Skip to content

Commit

Permalink
Hotkeys (SpinaCMS#731)
Browse files Browse the repository at this point in the history
* Support for hotkeys in Spina
  • Loading branch information
Bramjetten authored Jun 30, 2021
1 parent 974a670 commit 9212900
Show file tree
Hide file tree
Showing 9 changed files with 632 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ The Tailwind purger was created by [@dhh](https://twitter.com/dhh) for [tailwind

Icons were designed by [@steveschoger](https://twitter.com/steveschoger) - [Heroicons](https://github.com/tailwindlabs/heroicons).

HotKeys support via [Hotkeys.js](https://wangchujiang.com/hotkeys/)

The font used in Spina's admin panel is called Metropolis and was created by Chris Simpson [Metropolis](https://github.com/chrismsimpson/Metropolis)

Copyright (c) 2015, Chris Simpson <[email protected]>.
Expand Down
21 changes: 21 additions & 0 deletions app/assets/javascripts/spina/controllers/hotkeys_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Controller } from "stimulus"
import hotkeys from "hotkeys"

export default class extends Controller {
static get targets() {
return [ "button" ]
}

connect() {
hotkeys(this.element.dataset.hotkeys, this.handleHotkeys.bind(this))
hotkeys.filter = (event) => true
}

handleHotkeys(event, handler) {
event.preventDefault()
if (this.hasButtonTarget) {
this.buttonTarget.click()
}
}

}
1 change: 1 addition & 0 deletions app/assets/javascripts/spina/libraries/hotkeys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//= require ./[email protected]
Loading

0 comments on commit 9212900

Please sign in to comment.