Skip to content

Commit

Permalink
Adding number key override to example.html
Browse files Browse the repository at this point in the history
  • Loading branch information
ctd1500 committed Nov 10, 2016
1 parent f56b355 commit 9e01d5f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ videojs('vidId').ready(function() {
customKeys: {
// Create custom hotkeys
ctrldKey: {
key: function(e) {
key: function(event) {
// Toggle something with CTRL + D Key
return (e.ctrlKey && e.which === 68);
return (event.ctrlKey && event.which === 68);
},
handler: function(player, options) {
handler: function(player, options, event) {
// Using mute as an example
if (options.enableMute) {
player.muted(!player.muted());
Expand Down
28 changes: 24 additions & 4 deletions example.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
seekStep: 5,
enableMute: true,
enableFullscreen: true,
enableNumbers: false,
enableVolumeScroll: true,

// Enhance existing simple hotkey with a complex hotkey
Expand All @@ -56,7 +57,7 @@
// Toggle something with S Key
return (e.which === 83);
},
handler: function(player, options) {
handler: function(player, options, e) {
// Example
if (player.paused()) {
player.play();
Expand All @@ -72,20 +73,39 @@
// Toggle something with CTRL + D Key
return (e.ctrlKey && e.which === 68);
},
handler: function(player, options) {
handler: function(player, options, event) {
// Example
if (options.enableMute) {
player.muted(!player.muted());
}
}
},

// Override number keys example from https://github.com/ctd1500/videojs-hotkeys/pull/36
numbersKey: {
key: function(event) {
// Override number keys
return ((event.which > 47 && event.which < 59) || (event.which > 95 && event.which < 106));
},
handler: function(player, options, event) {
// Do not handle if enableModifiersForNumbers set to false and keys are Ctrl, Cmd or Alt
if (options.enableModifiersForNumbers || !(event.metaKey || event.ctrlKey || event.altKey)) {
var sub = 48;
if (event.which > 95) {
sub = 96;
}
var number = event.which - sub;
player.currentTime(player.duration() * number * 0.1);
}
}
},

emptyHotkey: {
// Empty
},

withoutKey: {
handler: function(player, options) {
handler: function(player, options, event) {
console.log('withoutKey handler');
}
},
Expand All @@ -100,7 +120,7 @@
key: function() {
console.log('I have a malformed customKey. The Key function must return a boolean.');
},
handler: function(player, options) {
handler: function(player, options, event) {
//Empty
}
}
Expand Down

0 comments on commit 9e01d5f

Please sign in to comment.