|
1 IriSP.Widgets.Shortcuts = function(player, config) { |
|
2 IriSP.Widgets.Widget.call(this, player, config); |
|
3 }; |
|
4 |
|
5 /** |
|
6 * Keyboard shortcuts widget |
|
7 * This widgets add global shortcuts for common actions. |
|
8 * The default shortcuts are: |
|
9 * - Escape or Control-space for play/pause |
|
10 * - Control-left for rewind (+shift to go faster) |
|
11 * - Control-right for forward (+shift to go faster) |
|
12 */ |
|
13 IriSP.Widgets.Shortcuts.prototype = new IriSP.Widgets.Widget(); |
|
14 |
|
15 IriSP.Widgets.Shortcuts.prototype.defaults = { |
|
16 // Time increment, in ms, for backward/forward navigation |
|
17 time_increment: 2000 |
|
18 } |
|
19 |
|
20 IriSP.Widgets.Shortcuts.prototype.draw = function() { |
|
21 var _this = this; |
|
22 |
|
23 /* Standard shortcuts */ |
|
24 Mousetrap.bindGlobal(["esc", "ctrl+space"], function (e) { |
|
25 e.preventDefault(); |
|
26 if (! _this.media.getPaused()) { |
|
27 _this.media.pause(); |
|
28 } else { |
|
29 _this.media.play(); |
|
30 } |
|
31 return false; |
|
32 }); |
|
33 Mousetrap.bindGlobal("ctrl+left", function (e) { |
|
34 // Backward |
|
35 e.preventDefault(); |
|
36 _this.media.setCurrentTime(Math.max(0, _this.media.getCurrentTime() - _this.time_increment)); |
|
37 return false; |
|
38 }); |
|
39 Mousetrap.bindGlobal("ctrl+shift+left", function (e) { |
|
40 // Backward |
|
41 e.preventDefault(); |
|
42 _this.media.setCurrentTime(Math.max(0, _this.media.getCurrentTime() - 5 * _this.time_increment)); |
|
43 return false; |
|
44 }); |
|
45 Mousetrap.bindGlobal("ctrl+right", function (e) { |
|
46 // Forward |
|
47 e.preventDefault(); |
|
48 _this.media.setCurrentTime(Math.min(_this.media.duration, _this.media.getCurrentTime() + _this.time_increment)); |
|
49 return false; |
|
50 }); |
|
51 Mousetrap.bindGlobal("ctrl+shift+right", function (e) { |
|
52 // Forward |
|
53 e.preventDefault(); |
|
54 _this.media.setCurrentTime(Math.min(_this.media.duration, _this.media.getCurrentTime() + 5 * _this.time_increment)); |
|
55 return false; |
|
56 }); |
|
57 |
|
58 }; |