a11yist/app/javascript/controllers/hotkey_controller.js

22 lines
603 B
JavaScript
Raw Normal View History

2024-11-09 03:54:25 +01:00
import { Controller } from "@hotwired/stimulus"
import { install } from '@github/hotkey'
// Connects to data-controller="hotkey"
export default class extends Controller {
connect() {
// Install all the hotkeys on the page
this.element.addEventListener("turbo:load", this.handleTurboLoad)
for (const el of this.element.parentNode.querySelectorAll('[data-hotkey]')) {
2024-11-11 05:00:51 +01:00
console.log(el.dataset)
2024-11-09 03:54:25 +01:00
install(el)
}
}
handleTurboLoad(event) {
for (const el of event.getTarget().querySelectorAll('[data-hotkey]')) {
2024-11-11 05:00:51 +01:00
console.log(el.dataset)
2024-11-09 03:54:25 +01:00
install(el)
}
}
}