(function(D){D.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":")","-":"_","=":"+",";":": ","'":'"',",":"<",".":">","/":"?","\\":"|"}};D.each(D.hotkeys.keypressKeys,function(E,F){D.hotkeys.shiftNums[F]=F});function A(E){this.num=0;this.timer=E>0?E:false}A.prototype.val=function(){return this.num};A.prototype.inc=function(){if(this.timer){clearTimeout(this.timeout);this.timeout=setTimeout(D.proxy(A.prototype.reset,this),this.timer)}this.num++};A.prototype.reset=function(){if(this.timer){clearTimeout(this.timeout)}this.num=0};function C(G){if(!(D.isPlainObject(G.data)||D.isArray(G.data)||typeof G.data==="string")){return }var F=G.handler,E={timer:700};(function(H){if(typeof H==="string"){E.combo=[H]}else{if(D.isArray(H)){E.combo=H}else{D.extend(E,H)}}E.combo=D.map(E.combo,function(I){return I.toLowerCase()})})(G.data);G.index=new A(E.timer);G.handler=function(M){if(this!==M.target&&(/textarea|select|input/i.test(M.target.nodeName))){return }var J=M.type!=="keypress"&&D.hotkeys.specialKeys[M.which],N=String.fromCharCode(M.which).toLowerCase(),K,L="",I={};if(M.altKey&&J!=="alt"){L+="alt+"}if(M.ctrlKey&&J!=="ctrl"){L+="ctrl+"}if(M.metaKey&&!M.ctrlKey&&J!=="meta"){L+="meta+"}if(M.shiftKey&&J!=="shift"){L+="shift+"}I[L+(J||N)]=true;if(/shift+/.test(L)){I[L.replace("shift+","")+D.hotkeys.shiftNums[(J||N)]]=true}var H=G.index,O=E.combo;if(B(O[H.val()],I)){if(H.val()===O.length-1){H.reset();return F.apply(this,arguments)}else{H.inc()}}else{H.reset();if(B(O[0],I)){H.inc()}}}}function B(H,F){var I=H.split(" ");for(var G=0,E=I.length;G<E;G++){if(F[I[G]]){return true}}return false}D.each(["keydown","keyup","keypress"],function(){D.event.special[this]={add:C}})})(jQuery);
jQuery(document).bind("iframeAppended",function(B,A){jQuery(A).contents().bind("keydown keypress keyup",function(C){jQuery.event.trigger(C,arguments,document,true)})});AJS.whenIType=function(H){H=jQuery.isArray(H)?H:[H];var D=AJS.I18n?AJS.I18n.getText("keyboard.shortcut.type"):AJS.params.keyType,A=AJS.I18n?AJS.I18n.getText("keyboard.shortcut.then"):AJS.params.keyThen,B=AJS.I18n?AJS.I18n.getText("keyboard.shortcut.or"):AJS.params.keyOr,C=navigator.platform.indexOf("Mac")!=-1;var F,E=function(J){var K=jQuery.grep(J,function(L){return/^[a-z0-9\?]$/i.test(L)}).length===J.length;jQuery(document).bind((K?"keypress":"keydown")+".whenitype",J,function(L){if(F&&!AJS.popup.current&&!AJS.dropDown.current&&!AJS.InlineDialog.current){F(L);L.preventDefault();L.stopImmediatePropagation()}});jQuery(document).bind("keyup.whenitype",J,function(L){L.preventDefault()})},I=function(J){var L=jQuery(J),M=L.attr("title")||"",K=H.slice(0);if(L.data("kbShortcutAppended")){G(L,K,M);return }if(C){K=jQuery.map(K,function(N){N=N.replace(/Meta/i,"\u2318");N=N.replace(/Shift/i,"\u21E7");return N})}M+=" ( "+D+" '"+K.shift()+"'";jQuery.each(K,function(){M+=" "+A+" '"+this+"'"});M+=" )";L.attr("title",M);L.data("kbShortcutAppended",true)},G=function(K,J,L){L=L.replace(/\)$/,B+" ");L+="'"+J.shift()+"'";jQuery.each(J,function(){L+=" "+A+" '"+this+"'"});L+=" )";K.attr("title",L)};E(H);return{moveToNextItem:function(J){F=function(){var L,N=true,K=jQuery(J),M=jQuery(J+".focused");if(!F.blurHandler){jQuery(document).one("keypress.whenitype",function(O){if(O.keyCode===27&&M){M.removeClass("focused")}})}if(M.length===0){N=false;M=jQuery(J).eq(0)}else{M.removeClass("focused");L=jQuery.inArray(M.get(0),K);if(L<K.length-1){L=L+1;M=K.eq(L)}else{M.removeClass("focused");M=jQuery(J).eq(0);N=false}}if(M&&M.length>0){M.addClass("focused");M.moveTo(N);M.find("a:first").focus()}}},moveToPrevItem:function(J){F=function(){var L,N=true,K=jQuery(J),M=jQuery(J+".focused");if(!F.blurHandler){jQuery(document).one("keypress.whenitype",function(O){if(O.keyCode===27&&M){M.removeClass("focused")}})}if(M.length===0){N=false;M=jQuery(J+":last")}else{M.removeClass("focused");L=jQuery.inArray(M.get(0),K);if(L>0){L=L-1;M=K.eq(L)}else{M.removeClass("focused");M=jQuery(J+":last");N=false}}if(M&&M.length>0){M.addClass("focused");M.moveTo(N);M.find("a:first").focus()}}},click:function(J){I(J);F=function(){var K=jQuery(J);if(K.length>0){K.click()}}},goTo:function(J){F=function(){window.location.href=contextPath+J}},evaluate:function(J){J.call(this)},followLink:function(J){I(J);F=function(){var K=jQuery(J);if(K.length>0&&(K.attr("nodeName").toLowerCase()==="a"||K.attr("nodeName").toLowerCase()==="link")){K.click();window.location.href=K.attr("href")}}},execute:function(K){var J=this;F=function(){K.call(J)}},moveToAndClick:function(J){I(J);F=function(){var K=jQuery(J);if(K.length>0){K.click();K.moveTo()}}},moveToAndFocus:function(J){I(J);F=function(L){var K=jQuery(J);if(K.length>0){K.focus();K.moveTo&&K.moveTo();if(K.is(":input")){L.preventDefault()}}}},or:function(J){E(J);return this}}};
AJS.bind("initialize.keyboardshortcuts",function(){var E=AJS.$,B=AJS.Data.get,D=B("context-path")+"/rest/shortcuts/latest/shortcuts/"+B("build-number")+"/"+B("keyboardshortcut-hash"),A=function(F){if(F.keyCode===27&&E(F.target).is(":input")){E(F.target).blur()}},C=navigator.platform.indexOf("Mac")!=-1;E.getJSON(D,function(H){var F=H.shortcuts;if(!F){throw new Error("Server returned no shortcuts.")}AJS.trigger("shortcuts-loaded.keyboardshortcuts",{shortcuts:F});var J={enableContext:function(K){var L;E.each(F,function(O,M){if(M.context!=K){return }var N=M.op,P=M.param;E.each(M.keys,function(){if(N==="execute"||N==="evaluate"){P=Function(P)}L=C?E.map(this,function(Q){return Q.replace(/Ctrl/i,"Meta")}):this;AJS.whenIType(L)[N](P)})})}};var G=function(){E(document).bind("keyup.whenitype",A);E(document).bind("iframeAppended.whenitype",function(L,K){E(K).load(function(){if(K.contentWindow&&K.contentWindow.jQuery){K.contentWindow.jQuery("body").bind("keyup.whenitype",A)}})});AJS.trigger("register-contexts.keyboardshortcuts",{shortcutRegistry:J})};G();AJS.bind("add-bindings.keyboardshortcuts",G);var I=function(){E(document).unbind(".whenitype");E("iframe").each(function(){if(this.contentWindow&&this.contentWindow.jQuery){this.contentWindow.jQuery("body").unbind(".keyboard-shortcuts.whenitype")}})};AJS.bind("remove-bindings.keyboardshortcuts",I)})});

