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 demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
Hit the keys <kbd>↑</kbd> <kbd>↑</kbd> <kbd>↓</kbd> <kbd>↓</kbd> <kbd>←</kbd> <kbd>→</kbd> <kbd>←</kbd> <kbd>→</kbd> <kbd>B</kbd> <kbd>A</kbd> in sequence, to trigger the konami code.
<hot-key shortcut="up up down down left right left right b a" trigger="konami" if="{{active}}"></hot-key>
</p>

<p>
Hit <kbd>Ctrl</kbd> + <kbd>S</kbd> to demo trapping default browser shortcuts.
<hot-key trap shortcut="['ctrl+s', 'command+s']" trigger="trap" if="{{active}}"></hot-key>
</p>



Expand All @@ -107,6 +112,10 @@
this.addEventListener('konami', function(e){
this.log += 'Konami event detected\n';
}.bind(this));

this.addEventListener('trap', function(e){
this.log += 'Trap event detected\n';
}.bind(this));
}
});
</script>
Expand Down
13 changes: 12 additions & 1 deletion hot-key.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@status alpha
@homepage https://github.com/FWeinb/hot-key
-->
<polymer-element name="hot-key" attributes="shortcut trigger if">
<polymer-element name="hot-key" attributes="shortcut trigger if trap">
<script>
Polymer('hot-key', {

Expand Down Expand Up @@ -46,6 +46,14 @@
* @type string
*/
trigger : null,

/**
* Trap the event to prevent propagation and default browser behavior.
* @attribute trap
* @default false
* @type boolean
*/
trap : false,

/**
* A boolean to indicate if this hot-key is active.
Expand Down Expand Up @@ -91,6 +99,9 @@
if ( this.if ) {
funcToTrigger.bind(this)();
}
if (this.trap) {
return false;
}
}.bind(this);
}
});
Expand Down