js.key-commands.js Maven / Gradle / Ivy
(function(jQuery){var handlers=[];jQuery.hotkeys={version:"0.8",specialKeys:{8:"backspace",9:"tab",13:"return",16:"shift",17:"ctrl",18:"alt",19:"pause",20:"capslock",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"del",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"numlock",145:"scroll",188:",",190:".",191:"/",224:"meta",219:"[",221:"]"},keypressKeys:["<",">","?"],shiftNums:{"`":"~","1":"!","2":"@","3":"#","4":"$","5":"%","6":"^","7":"&","8":"*","9":"(","0":")","-":"_","=":"+",";":": ","'":'"',",":"<",".":">","/":"?","\\":"|"}};jQuery.each(jQuery.hotkeys.keypressKeys,function(_,key){jQuery.hotkeys.shiftNums[key]=key});var comboIndex=0;var timerId=0;var lastHandleObj=null;var activeHandler=null;var activeCombo=false;function resetComboState(){comboIndex=0;activeCombo=false}function keyHandler(handleObj){if(!(typeof handleObj.data==="string"||jQuery.isArray(handleObj.data)||(handleObj.data&&handleObj.data.combo))){return}var origHandler=handleObj.handler,options={timer:700};(function(data){if(typeof data==="string"){options.combo=[data]}else{if(jQuery.isArray(data)){options.combo=data}else{jQuery.extend(options,data)}}options.combo=jQuery.map(options.combo,function(key){return key.toLowerCase()})})(handleObj.data);handleObj.combo=options.combo;handleObj.index=0;handleObj.handler=function(event){if(event.target!==this&&jQuery(event.target).is(":input")){return}var special=jQuery.hotkeys.specialKeys[event.which];var key=(event.type!=="keypress")&&special||String.fromCharCode(event.which).toLowerCase();var modif="";var possible={};var result=true;if(event.altKey&&special!=="alt"){modif+="alt+"}if(event.ctrlKey&&special!=="ctrl"){modif+="ctrl+"}if(event.metaKey&&!event.ctrlKey&&special!=="meta"){modif+="meta+"}if(event.shiftKey&&special!=="shift"){modif+="shift+"}possible[modif+key]=true;if(/shift\+/.test(modif)){possible[modif.replace("shift+","")+jQuery.hotkeys.shiftNums[key]]=true}if(handleObj.index===comboIndex&&comboIndex0){focusedElem.addClass("focused");focusedElem.scrollIntoView();focusedElem.find("a:first").focus()}}};ActionController.prototype.moveToPrevItem=function(selector){this._executer=function(){var index,items=jQuery(selector),focusedElem=jQuery(selector+".focused");if(!this._executer.blurHandler){jQuery(document).one("keypress",function(e){if(e.keyCode===27&&focusedElem){focusedElem.removeClass("focused")}})}if(focusedElem.length===0){focusedElem=jQuery(selector+":last")}else{focusedElem.removeClass("focused");index=jQuery.inArray(focusedElem.get(0),items);if(index>0){index=index-1;focusedElem=items.eq(index)}else{focusedElem.removeClass("focused");focusedElem=jQuery(selector+":last")}}if(focusedElem&&focusedElem.length>0){focusedElem.addClass("focused");focusedElem.scrollIntoView();focusedElem.find("a:first").focus()}}};ActionController.prototype.click=function(selector){this._addShortcutTitle(selector);this._executer=function(){jQuery(selector).click()}};ActionController.prototype.goTo=function(location){this._executer=function(){window.location.href=contextPath+location}};ActionController.prototype.followLink=function(selector){this._addShortcutTitle(selector);this._executer=function(){var elem=jQuery(selector);if(elem.length>0&&(elem.attr("nodeName").toLowerCase()==="a"||elem.attr("nodeName").toLowerCase()==="link")){elem.click();window.location.href=elem.attr("href")}}};ActionController.prototype.moveToAndClick=function(selector){this._addShortcutTitle(selector);this._executer=function(){var elem=jQuery(selector);if(elem.length>0){elem.click();elem.scrollIntoView()}}};ActionController.prototype.moveToAndFocus=function(selector){this._addShortcutTitle(selector);this._executer=function(e){var $elem=jQuery(selector);if($elem.length>0){$elem.focus();$elem.scrollIntoView();if($elem.is(":input")){e.preventDefault()}}}};ActionController.prototype.evaluate=function(command){if(typeof command!=="function"){command=new Function(command)}command.call(this)};ActionController.prototype.execute=function(func){var self=this;this._executer=function(){if(typeof func!=="function"){func=new Function(func)}func.call(self)}};ActionController.prototype.or=function(keys){this._bindKeys(keys);return this}})();
AJS.whenIType.fromJSON=function(json){function blurTargetField(e){if(e.keyCode===27&&jQuery(e.target).is(":input")){jQuery(e.target).blur()}}if(json){jQuery(document).keyup(blurTargetField);jQuery(document).bind("iframeAppended",function(e,iframe){jQuery(iframe).load(function(){var jQuery;if(iframe.contentWindow&&iframe.contentWindow.jQuery){jQuery=iframe.contentWindow.jQuery;jQuery("body").keyup(blurTargetField)}})});jQuery.each(json,function(){var allKeys=Function.prototype.call.apply(Array.prototype.concat,this.keys);AJS.whenIType(allKeys)[this.op](this.param)})}};jQuery(function(){if(AJS.keys){AJS.whenIType.fromJSON(AJS.keys.shortcuts)}});
© 2015 - 2025 Weber Informatics LLC | Privacy Policy