diff --git a/build/hotkeys.js b/build/hotkeys.js index 593e1e4..1dcd219 100644 --- a/build/hotkeys.js +++ b/build/hotkeys.js @@ -19,6 +19,17 @@ angular.module('cfp.hotkeys', []).provider('hotkeys', ['$injector', function($injector) { + var symbols = { + command : '⌘', + shift : '⇧', + left : '←', + right : '→', + up : '↑', + down : '↓', + 'return' : '↩', + backspace : '⌫' + }; + /** * Configurable setting to disable the cheatsheet entirely * @type {Boolean} @@ -38,6 +49,12 @@ this.templateTitle = 'Keyboard Shortcuts:'; + /** + * Configurable setting for keyboard labels + * @type {Object} + */ + this.symbols = symbols; + /** * Configurable settings for the cheat sheet header and footer. Both are HTML, and the header * overrides the normal title if specified. @@ -97,16 +114,6 @@ * @return {String} The key combination with symbols */ function symbolize (combo) { - var map = { - command : '⌘', - shift : '⇧', - left : '←', - right : '→', - up : '↑', - down : '↓', - 'return' : '↩', - backspace : '⌫' - }; combo = combo.split('+'); for (var i = 0; i < combo.length; i++) { @@ -119,7 +126,7 @@ } } - combo[i] = map[combo[i]] || combo[i]; + combo[i] = symbols[combo[i]] || combo[i]; } return combo.join(' + '); @@ -329,7 +336,7 @@ // these elements are prevented by the default Mousetrap.stopCallback(): var preventIn = ['INPUT', 'SELECT', 'TEXTAREA']; - // Determine if object format was given: + // Determine if object foxrmat was given: var objType = Object.prototype.toString.call(combo); if (objType === '[object Object]') { @@ -572,6 +579,7 @@ template : this.template, toggleCheatSheet : toggleCheatSheet, includeCheatSheet : this.includeCheatSheet, + symbols : symbols, cheatSheetHotkey : this.cheatSheetHotkey, cheatSheetDescription : this.cheatSheetDescription, useNgRoute : this.useNgRoute, @@ -1034,7 +1042,7 @@ } function _belongsTo(element, ancestor) { - if (element === document) { + if (element === null || element === document) { return false; } diff --git a/build/hotkeys.min.js b/build/hotkeys.min.js index 2f92ef3..e060209 100644 --- a/build/hotkeys.min.js +++ b/build/hotkeys.min.js @@ -4,4 +4,4 @@ * Copyright (c) 2015 Wes Cruver * License: MIT */ -!function(){"use strict";angular.module("cfp.hotkeys",[]).provider("hotkeys",["$injector",function(a){this.includeCheatSheet=!0,this.useNgRoute=a.has("ngViewDirective"),this.templateTitle="Keyboard Shortcuts:",this.templateHeader=null,this.templateFooter=null,this.template='',this.cheatSheetHotkey="?",this.cheatSheetDescription="Show / hide this help menu",this.$get=["$rootElement","$rootScope","$compile","$window","$document",function(a,b,c,d,e){function f(a){var b={command:"⌘",shift:"⇧",left:"←",right:"→",up:"↑",down:"↓","return":"↩",backspace:"⌫"};a=a.split("+");for(var c=0;c=0?a[c]="command":a[c]="ctrl"),a[c]=b[a[c]]||a[c];return a.join(" + ")}function g(a,b,c,d,e,f){this.combo=a instanceof Array?a:[a],this.description=b,this.callback=c,this.action=d,this.allowIn=e,this.persistent=f,this._formated=null}function h(){for(var a=o.hotkeys.length;a--;){var b=o.hotkeys[a];b&&!b.persistent&&k(b)}}function i(){o.helpVisible=!o.helpVisible,o.helpVisible?(t=l("esc"),k("esc"),j("esc",t.description,i,null,["INPUT","SELECT","TEXTAREA"])):(k("esc"),t!==!1&&j(t))}function j(a,b,c,d,e,f){var h,i=["INPUT","SELECT","TEXTAREA"],j=Object.prototype.toString.call(a);if("[object Object]"===j&&(b=a.description,c=a.callback,d=a.action,f=a.persistent,e=a.allowIn,a=a.combo),k(a),b instanceof Function?(d=c,c=b,b="$$undefined$$"):angular.isUndefined(b)&&(b="$$undefined$$"),void 0===f&&(f=!0),"function"==typeof c){h=c,e instanceof Array||(e=[]);for(var l,m=0;m-1)b=!0;else for(var e=0;e-1?(o.hotkeys[e].combo.length>1?o.hotkeys[e].combo.splice(o.hotkeys[e].combo.indexOf(b),1):(angular.forEach(p,function(a){var b=a.indexOf(o.hotkeys[e]);-1!==b&&a.splice(b,1)}),o.hotkeys.splice(e,1)),!0):!1}function l(a){if(!a)return o.hotkeys;for(var b,c=0;c-1)return b;return!1}function m(a){return a.$id in p||(p[a.$id]=[],a.$on("$destroy",function(){for(var b=p[a.$id].length;b--;)k(p[a.$id].pop())})),{add:function(b){var c;return c=arguments.length>1?j.apply(this,arguments):j(b),p[a.$id].push(c),this}}}function n(a){return function(c,d){if(a instanceof Array){var e=a[0],f=a[1];a=function(a){f.scope.$eval(e)}}b.$apply(function(){a(c,l(d))})}}Mousetrap.prototype.stopCallback=function(a,b){return(" "+b.className+" ").indexOf(" mousetrap ")>-1?!1:b.contentEditable&&"true"==b.contentEditable},g.prototype.format=function(){if(null===this._formated){for(var a=this.combo[0],b=a.split(/[\s]/),c=0;c95&&112>a||r.hasOwnProperty(a)&&(q[r[a]]=a)}return q}function l(a,b,c){return c||(c=k()[a]?"keydown":"keypress"),"keypress"==c&&b.length&&(c="keydown"),c}function m(a){return"+"===a?["+"]:(a=a.replace(/\+{2}/g,"+plus"),a.split("+"))}function n(a,b){var c,d,e,f=[];for(c=m(a),e=0;e1?void q(a,g,b,c):(f=n(a,c),s._callbacks[f.key]=s._callbacks[f.key]||[],k(f.key,f.modifiers,{type:f.action},d,a,e),void s._callbacks[f.key][d?"unshift":"push"]({callback:b,modifiers:f.modifiers,action:f.action,seq:d,level:e,combo:a}))}var s=this;if(a=a||b,!(s instanceof p))return new p(a);s.target=a,s._callbacks={},s._directMap={};var t,u={},v=!1,w=!1,x=!1;s._handleKey=function(a,b,d){var e,f=k(a,b,d),g={},h=0,i=!1;for(e=0;e":".","?":"/","|":"\\"},u={option:"alt",command:"meta","return":"enter",escape:"esc",plus:"+",mod:/Mac|iPod|iPhone|iPad/.test(navigator.platform)?"meta":"ctrl"},v=1;20>v;++v)r[111+v]="f"+v;for(v=0;9>=v;++v)r[v+96]=v;p.prototype.bind=function(a,b,c){var d=this;return a=a instanceof Array?a:[a],d._bindMultiple.call(d,a,b,c),d},p.prototype.unbind=function(a,b){var c=this;return c.bind.call(c,a,function(){},b)},p.prototype.trigger=function(a,b){var c=this;return c._directMap[a+":"+b]&&c._directMap[a+":"+b]({},a),c},p.prototype.reset=function(){var a=this;return a._callbacks={},a._directMap={},a},p.prototype.stopCallback=function(a,b){var c=this;return(" "+b.className+" ").indexOf(" mousetrap ")>-1?!1:o(b,c.target)?!1:"INPUT"==b.tagName||"SELECT"==b.tagName||"TEXTAREA"==b.tagName||b.isContentEditable},p.prototype.handleKey=function(){var a=this;return a._handleKey.apply(a,arguments)},p.init=function(){var a=p(b);for(var c in a)"_"!==c.charAt(0)&&(p[c]=function(b){return function(){return a[b].apply(a,arguments)}}(c))},p.init(),a.Mousetrap=p,"undefined"!=typeof module&&module.exports&&(module.exports=p),"function"==typeof define&&define.amd&&define(function(){return p})}(window,document); \ No newline at end of file +!function(){"use strict";angular.module("cfp.hotkeys",[]).provider("hotkeys",["$injector",function(a){var b={command:"⌘",shift:"⇧",left:"←",right:"→",up:"↑",down:"↓","return":"↩",backspace:"⌫"};this.includeCheatSheet=!0,this.useNgRoute=a.has("ngViewDirective"),this.templateTitle="Keyboard Shortcuts:",this.symbols=b,this.templateHeader=null,this.templateFooter=null,this.template='',this.cheatSheetHotkey="?",this.cheatSheetDescription="Show / hide this help menu",this.$get=["$rootElement","$rootScope","$compile","$window","$document",function(a,c,d,e,f){function g(a){a=a.split("+");for(var c=0;c=0?a[c]="command":a[c]="ctrl"),a[c]=b[a[c]]||a[c];return a.join(" + ")}function h(a,b,c,d,e,f){this.combo=a instanceof Array?a:[a],this.description=b,this.callback=c,this.action=d,this.allowIn=e,this.persistent=f,this._formated=null}function i(){for(var a=p.hotkeys.length;a--;){var b=p.hotkeys[a];b&&!b.persistent&&l(b)}}function j(){p.helpVisible=!p.helpVisible,p.helpVisible?(u=m("esc"),l("esc"),k("esc",u.description,j,null,["INPUT","SELECT","TEXTAREA"])):(l("esc"),u!==!1&&k(u))}function k(a,b,c,d,e,f){var g,i=["INPUT","SELECT","TEXTAREA"],j=Object.prototype.toString.call(a);if("[object Object]"===j&&(b=a.description,c=a.callback,d=a.action,f=a.persistent,e=a.allowIn,a=a.combo),l(a),b instanceof Function?(d=c,c=b,b="$$undefined$$"):angular.isUndefined(b)&&(b="$$undefined$$"),void 0===f&&(f=!0),"function"==typeof c){g=c,e instanceof Array||(e=[]);for(var k,m=0;m-1)b=!0;else for(var e=0;e-1?(p.hotkeys[e].combo.length>1?p.hotkeys[e].combo.splice(p.hotkeys[e].combo.indexOf(b),1):(angular.forEach(q,function(a){var b=a.indexOf(p.hotkeys[e]);-1!==b&&a.splice(b,1)}),p.hotkeys.splice(e,1)),!0):!1}function m(a){if(!a)return p.hotkeys;for(var b,c=0;c-1)return b;return!1}function n(a){return a.$id in q||(q[a.$id]=[],a.$on("$destroy",function(){for(var b=q[a.$id].length;b--;)l(q[a.$id].pop())})),{add:function(b){var c;return c=arguments.length>1?k.apply(this,arguments):k(b),q[a.$id].push(c),this}}}function o(a){return function(b,d){if(a instanceof Array){var e=a[0],f=a[1];a=function(a){f.scope.$eval(e)}}c.$apply(function(){a(b,m(d))})}}Mousetrap.prototype.stopCallback=function(a,b){return(" "+b.className+" ").indexOf(" mousetrap ")>-1?!1:b.contentEditable&&"true"==b.contentEditable},h.prototype.format=function(){if(null===this._formated){for(var a=this.combo[0],b=a.split(/[\s]/),c=0;c95&&112>a||r.hasOwnProperty(a)&&(q[r[a]]=a)}return q}function l(a,b,c){return c||(c=k()[a]?"keydown":"keypress"),"keypress"==c&&b.length&&(c="keydown"),c}function m(a){return"+"===a?["+"]:(a=a.replace(/\+{2}/g,"+plus"),a.split("+"))}function n(a,b){var c,d,e,f=[];for(c=m(a),e=0;e1?void q(a,g,b,c):(f=n(a,c),s._callbacks[f.key]=s._callbacks[f.key]||[],k(f.key,f.modifiers,{type:f.action},d,a,e),void s._callbacks[f.key][d?"unshift":"push"]({callback:b,modifiers:f.modifiers,action:f.action,seq:d,level:e,combo:a}))}var s=this;if(a=a||b,!(s instanceof p))return new p(a);s.target=a,s._callbacks={},s._directMap={};var t,u={},v=!1,w=!1,x=!1;s._handleKey=function(a,b,d){var e,f=k(a,b,d),g={},h=0,i=!1;for(e=0;e":".","?":"/","|":"\\"},u={option:"alt",command:"meta","return":"enter",escape:"esc",plus:"+",mod:/Mac|iPod|iPhone|iPad/.test(navigator.platform)?"meta":"ctrl"},v=1;20>v;++v)r[111+v]="f"+v;for(v=0;9>=v;++v)r[v+96]=v;p.prototype.bind=function(a,b,c){var d=this;return a=a instanceof Array?a:[a],d._bindMultiple.call(d,a,b,c),d},p.prototype.unbind=function(a,b){var c=this;return c.bind.call(c,a,function(){},b)},p.prototype.trigger=function(a,b){var c=this;return c._directMap[a+":"+b]&&c._directMap[a+":"+b]({},a),c},p.prototype.reset=function(){var a=this;return a._callbacks={},a._directMap={},a},p.prototype.stopCallback=function(a,b){var c=this;return(" "+b.className+" ").indexOf(" mousetrap ")>-1?!1:o(b,c.target)?!1:"INPUT"==b.tagName||"SELECT"==b.tagName||"TEXTAREA"==b.tagName||b.isContentEditable},p.prototype.handleKey=function(){var a=this;return a._handleKey.apply(a,arguments)},p.init=function(){var a=p(b);for(var c in a)"_"!==c.charAt(0)&&(p[c]=function(b){return function(){return a[b].apply(a,arguments)}}(c))},p.init(),a.Mousetrap=p,"undefined"!=typeof module&&module.exports&&(module.exports=p),"function"==typeof define&&define.amd&&define(function(){return p})}(window,document); \ No newline at end of file diff --git a/src/hotkeys.js b/src/hotkeys.js index d6ada81..8361090 100644 --- a/src/hotkeys.js +++ b/src/hotkeys.js @@ -13,6 +13,17 @@ angular.module('cfp.hotkeys', []).provider('hotkeys', function($injector) { + var symbols = { + command : '⌘', + shift : '⇧', + left : '←', + right : '→', + up : '↑', + down : '↓', + 'return' : '↩', + backspace : '⌫' + }; + /** * Configurable setting to disable the cheatsheet entirely * @type {Boolean} @@ -32,6 +43,12 @@ this.templateTitle = 'Keyboard Shortcuts:'; + /** + * Configurable setting for keyboard labels + * @type {Object} + */ + this.symbols = symbols; + /** * Configurable settings for the cheat sheet header and footer. Both are HTML, and the header * overrides the normal title if specified. @@ -91,16 +108,6 @@ * @return {String} The key combination with symbols */ function symbolize (combo) { - var map = { - command : '⌘', - shift : '⇧', - left : '←', - right : '→', - up : '↑', - down : '↓', - 'return' : '↩', - backspace : '⌫' - }; combo = combo.split('+'); for (var i = 0; i < combo.length; i++) { @@ -113,7 +120,7 @@ } } - combo[i] = map[combo[i]] || combo[i]; + combo[i] = symbols[combo[i]] || combo[i]; } return combo.join(' + '); @@ -566,6 +573,7 @@ template : this.template, toggleCheatSheet : toggleCheatSheet, includeCheatSheet : this.includeCheatSheet, + symbols : symbols, cheatSheetHotkey : this.cheatSheetHotkey, cheatSheetDescription : this.cheatSheetDescription, useNgRoute : this.useNgRoute,