(function(jQuery){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",224:"meta"}};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)}}})(handleObj.data);handleObj.combo=options.combo;handleObj.index=0;handleObj.handler=function(event){if(event.target!==this&&jQuery(event.target).is(":input")){return }var keyIsCharacterInput=(event.type==="keypress"&&event.which>0);var key=(keyIsCharacterInput)?String.fromCharCode(event.which):jQuery.hotkeys.specialKeys[event.which||event.keyCode];var modifier="";var result=true;if(!key){return }if(event.ctrlKey&&key!=="ctrl"){modifier+="ctrl+"}if(event.altKey&&key!=="alt"){modifier+="alt+"}if(event.metaKey&&!event.ctrlKey&&key!=="meta"){modifier+="meta+"}if(!keyIsCharacterInput&&event.shiftKey&&key!=="shift"){modifier+="shift+"}if(handleObj.index>=comboIndex&&comboIndex<options.combo.length&&options.combo[comboIndex]===modifier+key){if(comboIndex+1<options.combo.length){handleObj.index++;activeCombo=true}else{if(!activeCombo){handleObj.index=0;activeHandler=origHandler}}}else{handleObj.index=0}if(handleObj===lastHandleObj){clearTimeout(timerId);if(activeCombo){comboIndex++;timerId=setTimeout(resetComboState,750)}else{if(activeHandler){result=activeHandler.apply(this,arguments);activeHandler=null}comboIndex=0}activeCombo=false}return result};lastHandleObj=handleObj}jQuery.each(["keydown","keyup","keypress"],function(){jQuery.event.special[this]={add:keyHandler}})})(jQuery);
AJS.KeyboardShortcut=function(keys){this._executer=null;this._keys=jQuery.isArray(keys)?keys:[keys];this._bindKeys(this._keys)};AJS.KeyboardShortcut.prototype._bindKeys=function(keys){var that=this;jQuery(document).bind("keydown keypress",keys,function(e){if(that._executer&&!AJS.popup.current&&!AJS.dropDown.current&&!JIRA.Dialog.current){if(AJS.InlineDialog.current){AJS.InlineDialog.current.hide()}that._executer(e);e.preventDefault()}})};AJS.KeyboardShortcut.prototype._addShortcutTitle=function(selector){var elem=jQuery(selector),title=elem.attr("title")||"",keyArr=this._keys.slice(0);if(elem.data("kbShortcutAppended")){this._appendShortcutTitle(elem,keyArr,title);return }title+=" ( "+AJS.params.keyType+" '"+keyArr.shift()+"'";jQuery.each(keyArr,function(){title+=" "+AJS.params.keyThen+" '"+this+"'"});title+=" )";elem.attr("title",title);elem.data("kbShortcutAppended",true)};AJS.KeyboardShortcut.prototype._appendShortcutTitle=function(elem,keyArr,title){title=title.replace(/\)$/," OR ");title+="'"+keyArr.shift()+"'";jQuery.each(keyArr,function(){title+=" "+AJS.params.keyThen+" '"+this+"'"});title+=" )";elem.attr("title",title)};AJS.KeyboardShortcut.prototype.moveToNextItem=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).eq(0)}else{focusedElem.removeClass("focused");index=jQuery.inArray(focusedElem.get(0),items);if(index<items.length-1){index=index+1;focusedElem=items.eq(index)}else{focusedElem.removeClass("focused");focusedElem=jQuery(selector).eq(0)}}if(focusedElem&&focusedElem.length>0){focusedElem.addClass("focused");focusedElem.scrollIntoView();focusedElem.find("a:first").focus()}}};AJS.KeyboardShortcut.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()}}};AJS.KeyboardShortcut.prototype.click=function(selector){this._addShortcutTitle(selector);this._executer=function(){jQuery(selector).click()}};AJS.KeyboardShortcut.prototype.goTo=function(location){this._executer=function(){window.location.href=contextPath+location}};AJS.KeyboardShortcut.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")}}};AJS.KeyboardShortcut.prototype.moveToAndClick=function(selector){this._addShortcutTitle(selector);this._executer=function(){var elem=jQuery(selector);if(elem.length>0){elem.click();elem.scrollIntoView()}}};AJS.KeyboardShortcut.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()}}}};AJS.KeyboardShortcut.prototype.evaluate=function(command){if(typeof command!=="function"){command=new Function(command)}command.call(this)};AJS.KeyboardShortcut.prototype.execute=function(func){var self=this;this._executer=function(){if(typeof func!=="function"){func=new Function(func)}func.call(self)}};AJS.KeyboardShortcut.prototype.or=function(keys){this._bindKeys(keys);return this};AJS.whenIType=function(keys){return new AJS.KeyboardShortcut(keys)};if(jQuery.browser.webkit){jQuery(document).bind("iframeAppended",function(e,iframe){jQuery(iframe).load(function(){jQuery(iframe).contents().bind("keyup keydown keypress",function(event){if(!jQuery(event.target).is(":input")){jQuery(document).trigger(event)}})})})};
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)}});

