!function(){"use strict";angular.module("cfp.hotkeys",[]).provider("hotkeys",["$injector",function(e){this.includeCheatSheet=!0,this.useNgRoute=e.has("ngViewDirective"),this.templateTitle="Keyboard Shortcuts:",this.templateHeader=null,this.templateFooter=null,this.template='
{{ title }}
{{ key }} | {{ hotkey.description }} |
×
',this.cheatSheetHotkey="?",this.cheatSheetDescription="Show / hide this help menu",this.$get=["$rootElement","$rootScope","$compile","$window","$document",function(e,t,n,i,o){function r(e){var t={command:"⌘",shift:"⇧",left:"←",right:"→",up:"↑",down:"↓",return:"⏎",backspace:"⌫"};e=e.split("+");for(var n=0;n=0?e[n]="command":e[n]="ctrl"),e[n]=t[e[n]]||e[n];return e.join(" + ")}function a(e,t,n,i,o,r){this.combo=e instanceof Array?e:[e],this.description=t,this.callback=n,this.action=i,this.allowIn=o,this.persistent=r,this._formated=null}function s(){for(var e=d.hotkeys.length;e--;){var t=d.hotkeys[e];t&&!t.persistent&&h(t)}}function c(){d.helpVisible=!d.helpVisible,d.helpVisible?(g=u("esc"),h("esc"),l("esc",g.description,c,null,["INPUT","SELECT","TEXTAREA"])):(h("esc"),!1!==g&&l(g))}function l(e,t,n,i,o,r){var s,c=["INPUT","SELECT","TEXTAREA"];if("[object Object]"===Object.prototype.toString.call(e)&&(t=e.description,n=e.callback,i=e.action,r=e.persistent,o=e.allowIn,e=e.combo),h(e),t instanceof Function?(i=n,n=t,t="$$undefined$$"):angular.isUndefined(t)&&(t="$$undefined$$"),void 0===r&&(r=!0),"function"==typeof n){s=n,o instanceof Array||(o=[]);for(var l,u=0;u-1)t=!0;else for(var o=0;o-1&&(d.hotkeys[o].combo.length>1?d.hotkeys[o].combo.splice(d.hotkeys[o].combo.indexOf(t),1):(angular.forEach(y,function(e){var t=e.indexOf(d.hotkeys[o]);-1!==t&&e.splice(t,1)}),d.hotkeys.splice(o,1)),!0)}function u(e){if(!e)return d.hotkeys;for(var t,n=0;n-1)return t;return!1}function f(e){return function(n,i){if(e instanceof Array){var o=e[0],r=e[1];e=function(e){r.scope.$eval(o)}}t.$apply(function(){e(n,u(i))})}}var p=!0;Mousetrap.prototype.stopCallback=function(e,t){return!p||!((" "+t.className+" ").indexOf(" mousetrap ")>-1)&&(t.contentEditable&&"true"==t.contentEditable)},a.prototype.format=function(){if(null===this._formated){for(var e=this.combo[0].split(/[\s]/),t=0;t1?l.apply(this,arguments):l(t),y[e.$id].push(n),this}}},template:this.template,toggleCheatSheet:c,includeCheatSheet:this.includeCheatSheet,cheatSheetHotkey:this.cheatSheetHotkey,cheatSheetDescription:this.cheatSheetDescription,useNgRoute:this.useNgRoute,purgeHotkeys:s,templateTitle:this.templateTitle,pause:function(){p=!1},unpause:function(){p=!0}}}]}]).directive("hotkey",["hotkeys",function(e){return{restrict:"A",link:function(t,n,i){var o,r=[];angular.forEach(t.$eval(i.hotkey),function(t,n){o="string"==typeof i.hotkeyAllowIn?i.hotkeyAllowIn.split(/[\s,]+/):[],r.push(n),e.add({combo:n,description:i.hotkeyDescription,callback:t,action:i.hotkeyAction,allowIn:o})}),n.bind("$destroy",function(){angular.forEach(r,e.del)})}}}]).run(["hotkeys",function(e){}])}(),function(e,t,n){function i(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent("on"+t,n)}function o(e){if("keypress"==e.type){var t=String.fromCharCode(e.which);return e.shiftKey||(t=t.toLowerCase()),t}return m[e.which]?m[e.which]:v[e.which]?v[e.which]:String.fromCharCode(e.which).toLowerCase()}function r(e,t){return e.sort().join(",")===t.sort().join(",")}function a(e){var t=[];return e.shiftKey&&t.push("shift"),e.altKey&&t.push("alt"),e.ctrlKey&&t.push("ctrl"),e.metaKey&&t.push("meta"),t}function s(e){e.preventDefault?e.preventDefault():e.returnValue=!1}function c(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0}function l(e){return"shift"==e||"ctrl"==e||"alt"==e||"meta"==e}function h(){if(!k){k={};for(var e in m)e>95&&e<112||m.hasOwnProperty(e)&&(k[m[e]]=e)}return k}function u(e,t,n){return n||(n=h()[e]?"keydown":"keypress"),"keypress"==n&&t.length&&(n="keydown"),n}function f(e){return"+"===e?["+"]:(e=e.replace(/\+{2}/g,"+plus")).split("+")}function p(e,t){var n,i,o,r=[];for(n=f(e),o=0;o1?k(e,a,t,n):(r=p(e,n),v._callbacks[r.key]=v._callbacks[r.key]||[],h(r.key,r.modifiers,{type:r.action},i,e,o),v._callbacks[r.key][i?"unshift":"push"]({callback:t,modifiers:r.modifiers,action:r.action,seq:i,level:o,combo:e}))}var v=this;if(e=e||t,!(v instanceof y))return new y(e);v.target=e,v._callbacks={},v._directMap={};var g,b={},$=!1,w=!1,E=!1;v._handleKey=function(e,t,i){var o,r=h(e,t,i),a={},s=0,c=!1;for(o=0;o":".","?":"/","|":"\\"},b={option:"alt",command:"meta",return:"enter",escape:"esc",plus:"+",mod:/Mac|iPod|iPhone|iPad/.test(navigator.platform)?"meta":"ctrl"},$=1;$<20;++$)m[111+$]="f"+$;for($=0;$<=9;++$)m[$+96]=$;y.prototype.bind=function(e,t,n){var i=this;return e=e instanceof Array?e:[e],i._bindMultiple.call(i,e,t,n),i},y.prototype.unbind=function(e,t){var n=this;return n.bind.call(n,e,function(){},t)},y.prototype.trigger=function(e,t){var n=this;return n._directMap[e+":"+t]&&n._directMap[e+":"+t]({},e),n},y.prototype.reset=function(){var e=this;return e._callbacks={},e._directMap={},e},y.prototype.stopCallback=function(e,t){var n=this;return!((" "+t.className+" ").indexOf(" mousetrap ")>-1)&&(!d(t,n.target)&&("INPUT"==t.tagName||"SELECT"==t.tagName||"TEXTAREA"==t.tagName||t.isContentEditable))},y.prototype.handleKey=function(){var e=this;return e._handleKey.apply(e,arguments)},y.init=function(){var e=y(t);for(var n in e)"_"!==n.charAt(0)&&(y[n]=function(t){return function(){return e[t].apply(e,arguments)}}(n))},y.init(),e.Mousetrap=y,"undefined"!=typeof module&&module.exports&&(module.exports=y),"function"==typeof define&&define.amd&&define(function(){return y})}(window,document);