(function(){var NONCHARACTER_KEYS={8:"Backspace",9:"Tab",13:"Return",16:"Shift",17:"Control",18:"Alt",27:"Esc",32:"Spacebar",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"Left",38:"Up",39:"Right",40:"Down",46:"Del"};var MODIFIER_KEYS={16:"Shift",17:"Control",18:"Alt"};var lastModifierKey=0;pipe("keydown",function(event){if(event.which in MODIFIER_KEYS){if(event.which===lastModifierKey){return null}lastModifierKey=event.which}else{lastModifierKey=0}return NONCHARACTER_KEYS[event.which]||null},"aui:keydown");pipe("keypress",function(event){lastModifierKey=0;switch(event.which){case 0:case 8:case 9:case 27:break;default:if(!event.ctrlKey&&!event.altKey&&!event.metaKey){return String.fromCharCode(event.which)}}return null},"aui:keypress");pipe("keyup",function(event){if(event.which===lastModifierKey){lastModifierKey=0}return NONCHARACTER_KEYS[event.which]||null},"aui:keyup");function pipe(inType,getKey,outType){var listenerCount=0;jQuery.event.special[outType]={setup:function(){if(listenerCount===0){jQuery(document).bind(inType,dispatchKeyEvent)}listenerCount++},teardown:function(){listenerCount--;if(listenerCount===0){jQuery(document).unbind(inType,dispatchKeyEvent)}}};function dispatchKeyEvent(event){var key=getKey(event);if(key){var $event=new jQuery.Event(outType);$event.key=key;if(outType!=="aui:keypress"){$event.shiftKey=event.shiftKey;$event.ctrlKey=event.ctrlKey;$event.altKey=event.altKey}var target=event.target;var ownerDocument=(target.nodeType===9)?target:target.ownerDocument;if(ownerDocument!==document){$event.target=target;arguments[0]=$event;jQuery.event.trigger($event,arguments,document,true)}else{jQuery(target).trigger($event)}if($event.isDefaultPrevented()){event.preventDefault()}}}}jQuery(document).bind("iframeAppended",function(event){jQuery(event.target).contents().bind("keydown keypress keyup",function(event){jQuery.event.trigger(event,arguments,document,true)})})})();
(function(){var SHORTCUTS={};var KEY_STREAM=[];var MAX_LENGTH=0;var resetTimerId=0;var nonCharacterKeyPressed=false;var $document=jQuery(document);jQuery.event.special.shortcut={setup:function(){$document.bind("keydown",keydown);$document.bind("aui:keypress",keypress);$document.bind("keyup",keyup)},teardown:function(){$document.unbind("keydown",keydown);$document.unbind("aui:keypress",keypress);$document.unbind("keyup",keyup)},add:function(config){if(this!==document){throw new TypeError('"shortcut" event handlers must be bound at the document')}if(config.data===undefined){throw new Error('No data argument supplied in call to jQuery.fn.bind("shortcut", '+(config.handler.name||"function")+")")}if(typeof config.data!=="string"){throw new TypeError("Object "+config.data+" is not a string")}if(config.data.length===0){throw new Error("Shortcut sequence must not be empty")}for(var shortcut in SHORTCUTS){if(hasConflict(shortcut,config.data)){throw new Error('Cannot bind new shortcut "'+config.data+'" due to conflict with existing shortcut "'+shortcut+'"')}}if(config.data.length>MAX_LENGTH){MAX_LENGTH=config.data.length}SHORTCUTS[config.data]=config.handler},remove:function(config){if(this!==document){throw new TypeError('"shortcut" event handlers must be bound at the document')}delete SHORTCUTS[config.data]}};function keydown(event){if(nonCharacterKeyPressed){resetKeyStream()}nonCharacterKeyPressed=(event.which!==16)}function keypress(event){if(jQuery(event.target).is(":input")){resetKeyStream();return }KEY_STREAM.push(event.key);clearTimeout(resetTimerId);resetTimerId=setTimeout(resetKeyStream,2000);if(KEY_STREAM.length>MAX_LENGTH){KEY_STREAM.shift()}var keyStream=KEY_STREAM.join("");for(var i=0;i<keyStream.length;i++){var shortcut=keyStream.slice(i);if(shortcut in SHORTCUTS){event.preventDefault();event=new jQuery.Event("shortcut");event.data=shortcut;SHORTCUTS[shortcut].call(document,event);KEY_STREAM.length=0;break}}nonCharacterKeyPressed=false}function keyup(){if(nonCharacterKeyPressed){resetKeyStream()}}function resetKeyStream(){KEY_STREAM.length=0}function hasConflict(shortcut1,shortcut2){var len1=shortcut1.length;var len2=shortcut2.length;if(len1===len2){return shortcut1===shortcut2}var i,d;if(len1<len2){i=shortcut2.indexOf(shortcut1);d=len2-len1}else{i=shortcut1.indexOf(shortcut2);d=len1-len2}return i>=0&&i<d}})();
AJS.whenIType=function(shortcut){return new AJS.KeyboardShortcut(shortcut)};AJS.KeyboardShortcut=function(shortcut){this._executer=null;this.shortcuts=[shortcut];this._bindShortcut(shortcut)};AJS.KeyboardShortcut.prototype._bindShortcut=function(shortcut){if(typeof shortcut!=="string"){throw new TypeError("AJS.KeyboardShortcut expects string; received "+typeof shortcut)}if(/^(?:ctrl|alt|shift|meta)+/i.test(shortcut)){throw new SyntaxError('AJS.KeyboardShortcut cannot bind the shortcut "'+shortcut+'" because it uses a modifier')}var self=this;jQuery(document).bind("shortcut",shortcut,function(event){if(self._executer&&!AJS.popup.current&&!AJS.dropDown.current&&!JIRA.Dialog.current){if(AJS.InlineDialog.current){AJS.InlineDialog.current.hide()}self._executer(event);event.preventDefault()}})};AJS.KeyboardShortcut.prototype._addShortcutTitle=function(selector){var elem=jQuery(selector);var title=elem.attr("title")||"";var typeStr="Type";var thenStr="then";var orStr="OR";var shortcuts=jQuery.map(this.shortcuts,function(shortcut){return" '"+shortcut.split("").join("' "+thenStr+" '")+"'"});title+=" ( "+typeStr+shortcuts.join(" "+orStr+" ")+" )";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(shortcut){this.shortcuts.push(shortcut);this._bindShortcut(shortcut);return this};
AJS.whenIType.fromJSON=function(json){if(json){jQuery(document).bind("aui:keyup",function(event){var $target=jQuery(event.target);if(event.key==="Esc"&&$target.is(":input")){$target.blur()}});jQuery.each(json,function(){var keys=Function.prototype.call.apply(Array.prototype.concat,this.keys);var shortcut=keys.join("");if(keys.length<shortcut.length){throw new Error("Shortcut sequence ["+keys.join(",")+"] contains invalid keys")}AJS.whenIType(shortcut)[this.op](this.param)})}};jQuery(function(){if(AJS.keys){AJS.whenIType.fromJSON(AJS.keys.shortcuts)}});

