support firefox,Redundant code
parent
a36b8eaa73
commit
948a08a31a
@ -1 +1 @@
|
||||
/*! hotkeys-js v1.0.6 | (c) 2016 | https://github.com/jaywcjlove/hotkeys.git */!function(root,factory){"function"==typeof define&&define.amd?define([],factory):"object"==typeof exports?module.exports=factory():root.hotkeys=factory()}(this,function(){function setScope(scope){_scope=scope||"all"}function getScope(){return _scope||"all"}function addEvent(object,event,method){object.addEventListener?object.addEventListener(event,method,!1):object.attachEvent&&object.attachEvent("on"+event,function(){method(window.event)})}function isPressed(keyCode){return"string"==typeof keyCode&&(keyCode=code(keyCode)),_downKeys.indexOf(keyCode)!==-1}function getPressedKeyCodes(argument){return _downKeys.slice(0)}function dispatch(event){var scope,key=event.keyCode,asterisk=_handlers["*"];if(_downKeys.indexOf(key)===-1&&_downKeys.push(key),93!==key&&224!==key||(key=91),key in _mods){_mods[key]=!0;for(var k in _modifier)_modifier[k]===key&&(hotkeys[k]=!0);if(!asterisk)return}for(var e in _mods)_mods[e]=event[modifierMap[e]];if(hotkeys.filter.call(this,event)){if(scope=getScope(),asterisk)for(i=0;i<asterisk.length;i++)asterisk[i].scope===scope&&eventHandler(event,asterisk[i],scope);if(key in _handlers)for(i=0;i<_handlers[key].length;i++)eventHandler(event,_handlers[key][i],scope)}}function eventHandler(event,handler,scope){var modifiersMatch;if(handler.scope===scope||"all"===handler.scope){modifiersMatch=handler.mods.length>0;for(var y in _mods)(!_mods[y]&&handler.mods.indexOf(+y)>-1||_mods[y]&&handler.mods.indexOf(+y)===-1)&&(modifiersMatch=!1);(0!==handler.mods.length||_mods[16]||_mods[18]||_mods[17]||_mods[91])&&!modifiersMatch&&"*"!==handler.shortcut||handler.method(event,handler)===!1&&(event.preventDefault?event.preventDefault():event.returnValue=!1,event.stopPropagation&&event.stopPropagation(),event.cancelBubble&&(event.cancelBubble=!0))}}function unbind(key,scope){for(var keys,obj,multipleKeys=getKeys(key),mods=[],i=0;i<multipleKeys.length;i++){if(keys=multipleKeys[i].split("+"),keys.length>1&&(mods=getMods(keys)),key=keys[keys.length-1],key=code(key),void 0===scope&&(scope=getScope()),!_handlers[key])return;for(var r=0;r<_handlers[key].length;r++)obj=_handlers[key][r],obj.scope===scope&&compareArray(obj.mods,mods)&&(_handlers[key][r]={})}}function deleteScope(scope){var key,handlers,i;for(key in _handlers)for(handlers=_handlers[key],i=0;i<handlers.length;)handlers[i].scope===scope?handlers.splice(i,1):i++}function compareArray(a1,a2){if(a1.length!==a2.length)return!1;for(var i=0;i<a1.length;i++)if(a1[i]!==a2[i])return!1;return!0}function filter(event){var tagName=(event.target||event.srcElement).tagName;return!("INPUT"===tagName||"SELECT"===tagName||"TEXTAREA"===tagName)}function getMods(key){for(var mods=key.slice(0,key.length-1),i=0;i<mods.length;i++)mods[i]=_modifier[mods[i]];return mods}function getKeys(key){var keys;return key=key.replace(/\s/g,""),keys=key.split(","),""===keys[keys.length-1]&&(keys[keys.length-2]+=","),keys}function clearModifier(event){var key=event.keyCode,i=_downKeys.indexOf(key);if(i>=0&&_downKeys.splice(i,1),93!==key&&224!==key||(key=91),key in _mods){_mods[key]=!1;for(var k in _modifier)_modifier[k]===key&&(hotkeys[k]=!1)}}function hotkeys(key,scope,method){var keys=getKeys(key),mods=[],i=0;for(void 0===method&&(method=scope,scope="all");i<keys.length;i++)key=keys[i].split("+"),mods=[],key.length>1&&(mods=getMods(key),key=[key[key.length-1]]),key=key[0],key="*"===key?"*":code(key),key in _handlers||(_handlers[key]=[]),_handlers[key].push({shortcut:keys[i],scope:scope,method:method,key:keys[i],mods:mods})}Array.prototype.indexOf||(Array.prototype.indexOf=function(obj){for(var i=0;i<this.length;i++)if(this[i]===obj)return i;return-1});var _api,isff=navigator.userAgent.toLowerCase().indexOf("firefox")>0,_keyMap={backspace:8,tab:9,clear:12,enter:13,"return":13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,"delete":46,home:36,end:35,pageup:33,pagedown:34,",":188,".":190,"/":191,"`":192,"-":isff?173:189,"=":isff?61:187,";":isff?59:186,"'":222,"[":219,"]":221,"\\":220},_scope="all",_modifier={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":isff?224:91,command:isff?224:91},_downKeys=[],modifierMap={16:"shiftKey",18:"altKey",17:"ctrlKey"},_mods={16:!1,18:!1,17:!1,91:!1},code=function(x){return _keyMap[x]||x.toUpperCase().charCodeAt(0)},_handlers={};for(k=1;k<20;k++)_keyMap["f"+k]=111+k;modifierMap[isff?224:91]="metaKey",_mods[isff?224:91]=!1,addEvent(document,"keydown",function(event){dispatch(event)}),addEvent(document,"keyup",function(event){clearModifier(event)}),_api={setScope:setScope,getScope:getScope,deleteScope:deleteScope,getPressedKeyCodes:getPressedKeyCodes,isPressed:isPressed,filter:filter,unbind:unbind};for(var a in _api)hotkeys[a]=_api[a];var _hotkeys=window.hotkeys;return hotkeys.noConflict=function(deep){return deep&&window.hotkeys===hotkeys&&(window.hotkeys=_hotkeys),hotkeys},window.hotkeys=hotkeys,hotkeys});
|
||||
/*! hotkeys-js v1.0.7 | (c) 2016 | https://github.com/jaywcjlove/hotkeys.git */!function(root,factory){"function"==typeof define&&define.amd?define([],factory):"object"==typeof exports?module.exports=factory():root.hotkeys=factory()}(this,function(){function setScope(scope){_scope=scope||"all"}function getScope(){return _scope||"all"}function addEvent(object,event,method){object.addEventListener?object.addEventListener(event,method,!1):object.attachEvent&&object.attachEvent("on"+event,function(){method(window.event)})}function isPressed(keyCode){return"string"==typeof keyCode&&(keyCode=code(keyCode)),_downKeys.indexOf(keyCode)!==-1}function getPressedKeyCodes(argument){return _downKeys.slice(0)}function dispatch(event){var scope,key=event.keyCode,asterisk=_handlers["*"];if(_downKeys.indexOf(key)===-1&&_downKeys.push(key),93!==key&&224!==key||(key=91),key in _mods){_mods[key]=!0;for(var k in _modifier)_modifier[k]===key&&(hotkeys[k]=!0);if(!asterisk)return}for(var e in _mods)_mods[e]=event[modifierMap[e]];if(hotkeys.filter.call(this,event)){if(scope=getScope(),asterisk)for(i=0;i<asterisk.length;i++)asterisk[i].scope===scope&&eventHandler(event,asterisk[i],scope);if(key in _handlers)for(i=0;i<_handlers[key].length;i++)eventHandler(event,_handlers[key][i],scope)}}function eventHandler(event,handler,scope){var modifiersMatch;if(handler.scope===scope||"all"===handler.scope){modifiersMatch=handler.mods.length>0;for(var y in _mods)(!_mods[y]&&handler.mods.indexOf(+y)>-1||_mods[y]&&handler.mods.indexOf(+y)===-1)&&(modifiersMatch=!1);(0!==handler.mods.length||_mods[16]||_mods[18]||_mods[17]||_mods[91])&&!modifiersMatch&&"*"!==handler.shortcut||handler.method(event,handler)===!1&&(event.preventDefault?event.preventDefault():event.returnValue=!1,event.stopPropagation&&event.stopPropagation(),event.cancelBubble&&(event.cancelBubble=!0))}}function unbind(key,scope){for(var keys,obj,multipleKeys=getKeys(key),mods=[],i=0;i<multipleKeys.length;i++){if(keys=multipleKeys[i].split("+"),keys.length>1&&(mods=getMods(keys)),key=keys[keys.length-1],key=code(key),void 0===scope&&(scope=getScope()),!_handlers[key])return;for(var r=0;r<_handlers[key].length;r++)obj=_handlers[key][r],obj.scope===scope&&compareArray(obj.mods,mods)&&(_handlers[key][r]={})}}function deleteScope(scope){var key,handlers,i;for(key in _handlers)for(handlers=_handlers[key],i=0;i<handlers.length;)handlers[i].scope===scope?handlers.splice(i,1):i++}function compareArray(a1,a2){if(a1.length!==a2.length)return!1;for(var i=0;i<a1.length;i++)if(a1[i]!==a2[i])return!1;return!0}function filter(event){var tagName=(event.target||event.srcElement).tagName;return!("INPUT"===tagName||"SELECT"===tagName||"TEXTAREA"===tagName)}function getMods(key){for(var mods=key.slice(0,key.length-1),i=0;i<mods.length;i++)mods[i]=_modifier[mods[i]];return mods}function getKeys(key){var keys;return key=key.replace(/\s/g,""),keys=key.split(","),""===keys[keys.length-1]&&(keys[keys.length-2]+=","),keys}function clearModifier(event){var key=event.keyCode,i=_downKeys.indexOf(key);if(i>=0&&_downKeys.splice(i,1),93!==key&&224!==key||(key=91),key in _mods){_mods[key]=!1;for(var k in _modifier)_modifier[k]===key&&(hotkeys[k]=!1)}}function hotkeys(key,scope,method){var keys=getKeys(key),mods=[],i=0;for(void 0===method&&(method=scope,scope="all");i<keys.length;i++)key=keys[i].split("+"),mods=[],key.length>1&&(mods=getMods(key),key=[key[key.length-1]]),key=key[0],key="*"===key?"*":code(key),key in _handlers||(_handlers[key]=[]),_handlers[key].push({shortcut:keys[i],scope:scope,method:method,key:keys[i],mods:mods})}Array.prototype.indexOf||(Array.prototype.indexOf=function(obj){for(var i=0;i<this.length;i++)if(this[i]===obj)return i;return-1});var _api,isff=navigator.userAgent.toLowerCase().indexOf("firefox")>0,_keyMap={backspace:8,tab:9,clear:12,enter:13,"return":13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,"delete":46,home:36,end:35,pageup:33,pagedown:34,",":188,".":190,"/":191,"`":192,"-":isff?173:189,"=":isff?61:187,";":isff?59:186,"'":222,"[":219,"]":221,"\\":220},_scope="all",_modifier={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":isff?224:91,command:isff?224:91},_downKeys=[],modifierMap={16:"shiftKey",18:"altKey",17:"ctrlKey"},_mods={16:!1,18:!1,17:!1,91:!1},code=function(x){return _keyMap[x]||x.toUpperCase().charCodeAt(0)},_handlers={};for(k=1;k<20;k++)_keyMap["f"+k]=111+k;modifierMap[isff?224:91]="metaKey",_mods[isff?224:91]=!1,addEvent(document,"keydown",function(event){dispatch(event)}),addEvent(document,"keyup",function(event){clearModifier(event)}),_api={setScope:setScope,getScope:getScope,deleteScope:deleteScope,getPressedKeyCodes:getPressedKeyCodes,isPressed:isPressed,filter:filter,unbind:unbind};for(var a in _api)hotkeys[a]=_api[a];var _hotkeys=window.hotkeys;return hotkeys.noConflict=function(deep){return deep&&window.hotkeys===hotkeys&&(window.hotkeys=_hotkeys),hotkeys},window.hotkeys=hotkeys,hotkeys});
|
Loading…
Reference in New Issue