|
1 | 1 | /*! |
2 | | - * angular-hotkeys v1.6.0 |
| 2 | + * angular-hotkeys v1.7.0 |
3 | 3 | * https://chieffancypants.github.io/angular-hotkeys |
4 | | - * Copyright (c) 2015 Wes Cruver |
| 4 | + * Copyright (c) 2016 Wes Cruver |
5 | 5 | * License: MIT |
6 | 6 | */ |
7 | 7 | /* |
8 | 8 | * angular-hotkeys |
9 | 9 | * |
10 | 10 | * Automatic keyboard shortcuts for your angular apps |
11 | 11 | * |
12 | | - * (c) 2014 Wes Cruver |
| 12 | + * (c) 2016 Wes Cruver |
13 | 13 | * License: MIT |
14 | 14 | */ |
15 | 15 |
|
|
62 | 62 | '</tr>' + |
63 | 63 | '</tbody></table>' + |
64 | 64 | '<div ng-bind-html="footer" ng-if="footer"></div>' + |
65 | | - '<div class="cfp-hotkeys-close" ng-click="toggleCheatSheet()">×</div>' + |
| 65 | + '<div class="cfp-hotkeys-close" ng-click="toggleCheatSheet()">×</div>' + |
66 | 66 | '</div></div>'; |
67 | 67 |
|
68 | 68 | /** |
|
79 | 79 |
|
80 | 80 | this.$get = ['$rootElement', '$rootScope', '$compile', '$window', '$document', function ($rootElement, $rootScope, $compile, $window, $document) { |
81 | 81 |
|
| 82 | + var mouseTrapEnabled = true; |
| 83 | + |
| 84 | + function pause() { |
| 85 | + mouseTrapEnabled = false; |
| 86 | + } |
| 87 | + |
| 88 | + function unpause() { |
| 89 | + mouseTrapEnabled = true; |
| 90 | + } |
| 91 | + |
82 | 92 | // monkeypatch Mousetrap's stopCallback() function |
83 | 93 | // this version doesn't return true when the element is an INPUT, SELECT, or TEXTAREA |
84 | 94 | // (instead we will perform this check per-key in the _add() method) |
85 | 95 | Mousetrap.prototype.stopCallback = function(event, element) { |
| 96 | + if (!mouseTrapEnabled) { |
| 97 | + return true; |
| 98 | + } |
| 99 | + |
86 | 100 | // if the element has the class "mousetrap" then no need to stop |
87 | 101 | if ((' ' + element.className + ' ').indexOf(' mousetrap ') > -1) { |
88 | 102 | return false; |
|
98 | 112 | */ |
99 | 113 | function symbolize (combo) { |
100 | 114 | var map = { |
101 | | - command : '⌘', |
102 | | - shift : '⇧', |
103 | | - left : '←', |
104 | | - right : '→', |
105 | | - up : '↑', |
106 | | - down : '↓', |
107 | | - 'return' : '↩', |
108 | | - backspace : '⌫' |
| 115 | + command : '\u2318', // ⌘ |
| 116 | + shift : '\u21E7', // ⇧ |
| 117 | + left : '\u2190', // ← |
| 118 | + right : '\u2192', // → |
| 119 | + up : '\u2191', // ↑ |
| 120 | + down : '\u2193', // ↓ |
| 121 | + 'return' : '\u23CE', // ⏎ |
| 122 | + backspace : '\u232B' // ⌫ |
109 | 123 | }; |
110 | 124 | combo = combo.split('+'); |
111 | 125 |
|
|
221 | 235 | * attached. This is useful to catch when the scopes are `$destroy`d and |
222 | 236 | * then automatically unbind the hotkey. |
223 | 237 | * |
224 | | - * @type {Array} |
| 238 | + * @type {Object} |
225 | 239 | */ |
226 | | - var boundScopes = []; |
| 240 | + var boundScopes = {}; |
227 | 241 |
|
228 | 242 | if (this.useNgRoute) { |
229 | 243 | $rootScope.$on('$routeChangeSuccess', function (event, route) { |
|
563 | 577 | }; |
564 | 578 | } |
565 | 579 |
|
566 | | - |
567 | 580 | var publicApi = { |
568 | 581 | add : _add, |
569 | 582 | del : _del, |
|
576 | 589 | cheatSheetDescription : this.cheatSheetDescription, |
577 | 590 | useNgRoute : this.useNgRoute, |
578 | 591 | purgeHotkeys : purgeHotkeys, |
579 | | - templateTitle : this.templateTitle |
| 592 | + templateTitle : this.templateTitle, |
| 593 | + pause : pause, |
| 594 | + unpause : unpause |
580 | 595 | }; |
581 | 596 |
|
582 | 597 | return publicApi; |
|
590 | 605 | return { |
591 | 606 | restrict: 'A', |
592 | 607 | link: function (scope, el, attrs) { |
593 | | - var key, allowIn; |
| 608 | + var keys = [], |
| 609 | + allowIn; |
594 | 610 |
|
595 | 611 | angular.forEach(scope.$eval(attrs.hotkey), function (func, hotkey) { |
596 | 612 | // split and trim the hotkeys string into array |
597 | 613 | allowIn = typeof attrs.hotkeyAllowIn === "string" ? attrs.hotkeyAllowIn.split(/[\s,]+/) : []; |
598 | 614 |
|
599 | | - key = hotkey; |
| 615 | + keys.push(hotkey); |
600 | 616 |
|
601 | 617 | hotkeys.add({ |
602 | 618 | combo: hotkey, |
|
609 | 625 |
|
610 | 626 | // remove the hotkey if the directive is destroyed: |
611 | 627 | el.bind('$destroy', function() { |
612 | | - hotkeys.del(key); |
| 628 | + angular.forEach(keys, hotkeys.del); |
613 | 629 | }); |
614 | 630 | } |
615 | 631 | }; |
|
0 commit comments