Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/javascript/controllers/player_controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Controller } from "@hotwired/stimulus";
import FakeAudio from "fake_audio";
import { useHotkeys } from "stimulus-use/hotkeys"

function secondsToDuration(num) {
let mins = Math.floor(num / 60);
Expand All @@ -20,6 +21,10 @@ export default class extends Controller {
this.handleTimeUpdate = this.handleTimeUpdate.bind(this);
this.handleEnded = this.handleEnded.bind(this);
this.playing = false;

useHotkeys(this, {
'space': [this.toggle],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Есть подозрение, что без отдельного обработчика события не обойтись, так как нам нужно блокировать поведение браузера по умолчанию (а это прокрутка), то есть, preventDefault().

})
}

trackValueChanged() {
Expand Down Expand Up @@ -59,6 +64,10 @@ export default class extends Controller {
}
}

toggle() {
this.playing ? this.pause() : this.play();
}

play() {
this.element.classList.add(this.playingClass);
this.audio.play();
Expand Down
2 changes: 2 additions & 0 deletions config/importmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
pin "@hotwired/stimulus", to: "https://ga.jspm.io/npm:@hotwired/stimulus@3.2.1/dist/stimulus.js"
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
pin_all_from "app/javascript/controllers", under: "controllers"
pin "stimulus-use/hotkeys", to: "https://ga.jspm.io/npm:stimulus-use@0.52.0/dist/hotkeys.js"
pin "hotkeys-js", to: "https://ga.jspm.io/npm:hotkeys-js@3.11.2/dist/hotkeys.esm.js"