elm-keyboard-shortcut
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "elm-keyboard-shortcut", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "companion package for elm-keyboard-shortcut", | ||
@@ -5,0 +5,0 @@ "main": "src/shortcut-element.js", |
# elm-keyboard-shortcut | ||
![GitHub Page example](https://github.com/leojpod/elm-keyboard-shortcut/workflows/GitHub%20Page%20example/badge.svg?branch=master) | ||
## Why? | ||
@@ -4,0 +6,0 @@ |
import '@webcomponents/custom-elements' | ||
import deburr from 'lodash.deburr' | ||
let preventDuplicateEvent = false | ||
/** | ||
* make sure the given fct is ran at most once every 10ms | ||
**/ | ||
function dedup (fct, event) { | ||
// if the lock it not in place | ||
if (!preventDuplicateEvent) { | ||
// then run the thing | ||
// but first put the lock in place | ||
preventDuplicateEvent = true | ||
setTimeout(() => { | ||
preventDuplicateEvent = false | ||
}, 10) | ||
return fct(event) | ||
} // else ignore it | ||
} | ||
/** | ||
* will process each incoming keydown event and try to match them to the list given in the shortcut attribute | ||
@@ -26,10 +9,6 @@ **/ | ||
connectedCallback () { | ||
console.log('hello', this) | ||
// when the element is created: add some listeners to the body | ||
// we'll take them out when it's all over | ||
this.listener = (evt) => { | ||
console.log('undedup evt -> ', evt, this.shortcuts) | ||
// dedup((event) => { | ||
const event = evt | ||
console.log("what we've got here is an event: ", event) | ||
this.shortcuts | ||
@@ -57,3 +36,2 @@ .filter( | ||
}) | ||
// }, evt) | ||
} | ||
@@ -60,0 +38,0 @@ document.body.addEventListener('keydown', this.listener, { capture: true }) |
37
5720
43