Bugzilla – Attachment 22415 Details for
Bug 11035
Replace shortcut plugin jquery.hotkeys.min.js
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11035 - Replace shortcut plugin jquery.hotkeys.min.js
Bug-11035---Replace-shortcut-plugin-jqueryhotkeysm.patch (text/plain), 18.10 KB, created by
Kyle M Hall (khall)
on 2013-10-25 15:39:07 UTC
(
hide
)
Description:
Bug 11035 - Replace shortcut plugin jquery.hotkeys.min.js
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2013-10-25 15:39:07 UTC
Size:
18.10 KB
patch
obsolete
>From 2447efc9ee8d0774e205ab8a29ce54680b2048bb Mon Sep 17 00:00:00 2001 >From: Blou <philippe.blouin@inlibro.com> >Date: Thu, 10 Oct 2013 13:44:27 -0400 >Subject: [PATCH] Bug 11035 - Replace shortcut plugin jquery.hotkeys.min.js > >To old plugin prevents the upgrade to the latest jquery. By replacing with openjs' shortcut.js, we have now one less hurdle in upgrading Koha to latest. > >Changes: >- removed jquery.hotkeys.min.js >- added shortcut.js >- modified the related includes (doc-head-close.inc and help-top.inc) >- modified the calls in staff-global.js > >Regression test: >1) apply the patch >2) in the intranet, test the shortcuts alt-q, alt-r, alt-u. > >These are the only affected functionalities. There is no new functionnality. > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > .../lib/jquery/plugins/jquery.hotkeys.min.js | 19 -- > .../intranet-tmpl/lib/jquery/plugins/shortcut.js | 223 ++++++++++++++++++++ > .../prog/en/includes/doc-head-close.inc | 2 +- > .../intranet-tmpl/prog/en/includes/help-top.inc | 2 +- > koha-tmpl/intranet-tmpl/prog/en/js/staff-global.js | 6 +- > 5 files changed, 228 insertions(+), 24 deletions(-) > delete mode 100644 koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.hotkeys.min.js > create mode 100644 koha-tmpl/intranet-tmpl/lib/jquery/plugins/shortcut.js > >diff --git a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.hotkeys.min.js b/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.hotkeys.min.js >deleted file mode 100644 >index 53e37cc..0000000 >--- a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.hotkeys.min.js >+++ /dev/null >@@ -1,19 +0,0 @@ >-(function(jQuery){jQuery.fn.__bind__=jQuery.fn.bind;jQuery.fn.__unbind__=jQuery.fn.unbind;jQuery.fn.__find__=jQuery.fn.find;var hotkeys={version:'0.7.9',override:/keypress|keydown|keyup/g,triggersMap:{},specialKeys:{27:'esc',9:'tab',32:'space',13:'return',8:'backspace',145:'scroll',20:'capslock',144:'numlock',19:'pause',45:'insert',36:'home',46:'del',35:'end',33:'pageup',34:'pagedown',37:'left',38:'up',39:'right',40:'down',109:'-',112:'f1',113:'f2',114:'f3',115:'f4',116:'f5',117:'f6',118:'f7',119:'f8',120:'f9',121:'f10',122:'f11',123:'f12',191:'/'},shiftNums:{"`":"~","1":"!","2":"@","3":"#","4":"$","5":"%","6":"^","7":"&","8":"*","9":"(","0":")","-":"_","=":"+",";":":","'":"\"",",":"<",".":">","/":"?","\\":"|"},newTrigger:function(type,combi,callback){var result={};result[type]={};result[type][combi]={cb:callback,disableInInput:false};return result;}};hotkeys.specialKeys=jQuery.extend(hotkeys.specialKeys,{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:'/'});jQuery.fn.find=function(selector){this.query=selector;return jQuery.fn.__find__.apply(this,arguments);};jQuery.fn.unbind=function(type,combi,fn){if(jQuery.isFunction(combi)){fn=combi;combi=null;} >-if(combi&&typeof combi==='string'){var selectorId=((this.prevObject&&this.prevObject.query)||(this[0].id&&this[0].id)||this[0]).toString();var hkTypes=type.split(' ');for(var x=0;x<hkTypes.length;x++){delete hotkeys.triggersMap[selectorId][hkTypes[x]][combi];}} >-return this.__unbind__(type,fn);};jQuery.fn.bind=function(type,data,fn){var handle=type.match(hotkeys.override);if(jQuery.isFunction(data)||!handle){return this.__bind__(type,data,fn);} >-else{var result=null,pass2jq=jQuery.trim(type.replace(hotkeys.override,''));if(pass2jq){result=this.__bind__(pass2jq,data,fn);} >-if(typeof data==="string"){data={'combi':data};} >-if(data.combi){for(var x=0;x<handle.length;x++){var eventType=handle[x];var combi=data.combi.toLowerCase(),trigger=hotkeys.newTrigger(eventType,combi,fn),selectorId=((this.prevObject&&this.prevObject.query)||(this[0].id&&this[0].id)||this[0]).toString();trigger[eventType][combi].disableInInput=data.disableInInput;if(!hotkeys.triggersMap[selectorId]){hotkeys.triggersMap[selectorId]=trigger;} >-else if(!hotkeys.triggersMap[selectorId][eventType]){hotkeys.triggersMap[selectorId][eventType]=trigger[eventType];} >-var mapPoint=hotkeys.triggersMap[selectorId][eventType][combi];if(!mapPoint){hotkeys.triggersMap[selectorId][eventType][combi]=[trigger[eventType][combi]];} >-else if(mapPoint.constructor!==Array){hotkeys.triggersMap[selectorId][eventType][combi]=[mapPoint];} >-else{hotkeys.triggersMap[selectorId][eventType][combi][mapPoint.length]=trigger[eventType][combi];} >-this.each(function(){var jqElem=jQuery(this);if(jqElem.attr('hkId')&&jqElem.attr('hkId')!==selectorId){selectorId=jqElem.attr('hkId')+";"+selectorId;} >-jqElem.attr('hkId',selectorId);});result=this.__bind__(handle.join(' '),data,hotkeys.handler)}} >-return result;}};hotkeys.findElement=function(elem){if(!jQuery(elem).attr('hkId')){if(jQuery.browser.opera||jQuery.browser.safari){while(!jQuery(elem).attr('hkId')&&elem.parentNode){elem=elem.parentNode;}}} >-return elem;};hotkeys.handler=function(event){var target=hotkeys.findElement(event.currentTarget),jTarget=jQuery(target),ids=jTarget.attr('hkId');if(ids){ids=ids.split(';');var code=event.which,type=event.type,special=hotkeys.specialKeys[code],character=!special&&String.fromCharCode(code).toLowerCase(),shift=event.shiftKey,ctrl=event.ctrlKey,alt=event.altKey||event.originalEvent.altKey,mapPoint=null;for(var x=0;x<ids.length;x++){if(hotkeys.triggersMap[ids[x]][type]){mapPoint=hotkeys.triggersMap[ids[x]][type];break;}} >-if(mapPoint){var trigger;if(!shift&&!ctrl&&!alt){trigger=mapPoint[special]||(character&&mapPoint[character]);} >-else{var modif='';if(alt)modif+='alt+';if(ctrl)modif+='ctrl+';if(shift)modif+='shift+';trigger=mapPoint[modif+special];if(!trigger){if(character){trigger=mapPoint[modif+character]||mapPoint[modif+hotkeys.shiftNums[character]]||(modif==='shift+'&&mapPoint[hotkeys.shiftNums[character]]);}}} >-if(trigger){var result=false;for(var x=0;x<trigger.length;x++){if(trigger[x].disableInInput){var elem=jQuery(event.target);if(jTarget.is("input")||jTarget.is("textarea")||jTarget.is("select")||elem.is("input")||elem.is("textarea")||elem.is("select")){return true;}} >-result=result||trigger[x].cb.apply(this,[event]);} >-return result;}}}};window.hotkeys=hotkeys;return jQuery;})(jQuery); >\ No newline at end of file >diff --git a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/shortcut.js b/koha-tmpl/intranet-tmpl/lib/jquery/plugins/shortcut.js >new file mode 100644 >index 0000000..c8694d7 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/lib/jquery/plugins/shortcut.js >@@ -0,0 +1,223 @@ >+/** >+ * http://www.openjs.com/scripts/events/keyboard_shortcuts/ >+ * Version : 2.01.B >+ * By Binny V A >+ * License : BSD >+ */ >+shortcut = { >+ 'all_shortcuts':{},//All the shortcuts are stored in this array >+ 'add': function(shortcut_combination,callback,opt) { >+ //Provide a set of default options >+ var default_options = { >+ 'type':'keydown', >+ 'propagate':false, >+ 'disable_in_input':false, >+ 'target':document, >+ 'keycode':false >+ } >+ if(!opt) opt = default_options; >+ else { >+ for(var dfo in default_options) { >+ if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo]; >+ } >+ } >+ >+ var ele = opt.target; >+ if(typeof opt.target == 'string') ele = document.getElementById(opt.target); >+ var ths = this; >+ shortcut_combination = shortcut_combination.toLowerCase(); >+ >+ //The function to be called at keypress >+ var func = function(e) { >+ e = e || window.event; >+ >+ if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields >+ var element; >+ if(e.target) element=e.target; >+ else if(e.srcElement) element=e.srcElement; >+ if(element.nodeType==3) element=element.parentNode; >+ >+ if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return; >+ } >+ >+ //Find Which key is pressed >+ if (e.keyCode) code = e.keyCode; >+ else if (e.which) code = e.which; >+ var character = String.fromCharCode(code).toLowerCase(); >+ >+ if(code == 188) character=","; //If the user presses , when the type is onkeydown >+ if(code == 190) character="."; //If the user presses , when the type is onkeydown >+ >+ var keys = shortcut_combination.split("+"); >+ //Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked >+ var kp = 0; >+ >+ //Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken >+ var shift_nums = { >+ "`":"~", >+ "1":"!", >+ "2":"@", >+ "3":"#", >+ "4":"$", >+ "5":"%", >+ "6":"^", >+ "7":"&", >+ "8":"*", >+ "9":"(", >+ "0":")", >+ "-":"_", >+ "=":"+", >+ ";":":", >+ "'":"\"", >+ ",":"<", >+ ".":">", >+ "/":"?", >+ "\\":"|" >+ } >+ //Special Keys - and their codes >+ var special_keys = { >+ 'esc':27, >+ 'escape':27, >+ 'tab':9, >+ 'space':32, >+ 'return':13, >+ 'enter':13, >+ 'backspace':8, >+ >+ 'scrolllock':145, >+ 'scroll_lock':145, >+ 'scroll':145, >+ 'capslock':20, >+ 'caps_lock':20, >+ 'caps':20, >+ 'numlock':144, >+ 'num_lock':144, >+ 'num':144, >+ >+ 'pause':19, >+ 'break':19, >+ >+ 'insert':45, >+ 'home':36, >+ 'delete':46, >+ 'end':35, >+ >+ 'pageup':33, >+ 'page_up':33, >+ 'pu':33, >+ >+ 'pagedown':34, >+ 'page_down':34, >+ 'pd':34, >+ >+ 'left':37, >+ 'up':38, >+ 'right':39, >+ 'down':40, >+ >+ 'f1':112, >+ 'f2':113, >+ 'f3':114, >+ 'f4':115, >+ 'f5':116, >+ 'f6':117, >+ 'f7':118, >+ 'f8':119, >+ 'f9':120, >+ 'f10':121, >+ 'f11':122, >+ 'f12':123 >+ } >+ >+ var modifiers = { >+ shift: { wanted:false, pressed:false}, >+ ctrl : { wanted:false, pressed:false}, >+ alt : { wanted:false, pressed:false}, >+ meta : { wanted:false, pressed:false} //Meta is Mac specific >+ }; >+ >+ if(e.ctrlKey) modifiers.ctrl.pressed = true; >+ if(e.shiftKey) modifiers.shift.pressed = true; >+ if(e.altKey) modifiers.alt.pressed = true; >+ if(e.metaKey) modifiers.meta.pressed = true; >+ >+ for(var i=0; k=keys[i],i<keys.length; i++) { >+ //Modifiers >+ if(k == 'ctrl' || k == 'control') { >+ kp++; >+ modifiers.ctrl.wanted = true; >+ >+ } else if(k == 'shift') { >+ kp++; >+ modifiers.shift.wanted = true; >+ >+ } else if(k == 'alt') { >+ kp++; >+ modifiers.alt.wanted = true; >+ } else if(k == 'meta') { >+ kp++; >+ modifiers.meta.wanted = true; >+ } else if(k.length > 1) { //If it is a special key >+ if(special_keys[k] == code) kp++; >+ >+ } else if(opt['keycode']) { >+ if(opt['keycode'] == code) kp++; >+ >+ } else { //The special keys did not match >+ if(character == k) kp++; >+ else { >+ if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase >+ character = shift_nums[character]; >+ if(character == k) kp++; >+ } >+ } >+ } >+ } >+ >+ if(kp == keys.length && >+ modifiers.ctrl.pressed == modifiers.ctrl.wanted && >+ modifiers.shift.pressed == modifiers.shift.wanted && >+ modifiers.alt.pressed == modifiers.alt.wanted && >+ modifiers.meta.pressed == modifiers.meta.wanted) { >+ callback(e); >+ >+ if(!opt['propagate']) { //Stop the event >+ //e.cancelBubble is supported by IE - this will kill the bubbling process. >+ e.cancelBubble = true; >+ e.returnValue = false; >+ >+ //e.stopPropagation works in Firefox. >+ if (e.stopPropagation) { >+ e.stopPropagation(); >+ e.preventDefault(); >+ } >+ return false; >+ } >+ } >+ } >+ this.all_shortcuts[shortcut_combination] = { >+ 'callback':func, >+ 'target':ele, >+ 'event': opt['type'] >+ }; >+ //Attach the function with the event >+ if(ele.addEventListener) ele.addEventListener(opt['type'], func, false); >+ else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func); >+ else ele['on'+opt['type']] = func; >+ }, >+ >+ //Remove the shortcut - just specify the shortcut and I will remove the binding >+ 'remove':function(shortcut_combination) { >+ shortcut_combination = shortcut_combination.toLowerCase(); >+ var binding = this.all_shortcuts[shortcut_combination]; >+ delete(this.all_shortcuts[shortcut_combination]) >+ if(!binding) return; >+ var type = binding['event']; >+ var ele = binding['target']; >+ var callback = binding['callback']; >+ >+ if(ele.detachEvent) ele.detachEvent('on'+type, callback); >+ else if(ele.removeEventListener) ele.removeEventListener(type, callback, false); >+ else ele['on'+type] = false; >+ } >+} >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc >index 5eabb6f..a0443d3 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc >@@ -10,7 +10,7 @@ > [% IF ( IntranetUserCSS ) %]<style type="text/css">[% IntranetUserCSS %]</style>[% END %] > <script type="text/javascript" src="[% interface %]/lib/jquery/jquery.js"></script> > <script type="text/javascript" src="[% interface %]/lib/jquery/jquery-ui.js"></script> >-<script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.hotkeys.min.js"></script> >+<script type="text/javascript" src="[% interface %]/lib/jquery/plugins/shortcut.js"></script> > <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.cookie.min.js"></script> > <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.highlight-3.js"></script> > <script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.qtip.js"></script> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/help-top.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/help-top.inc >index 54fe5a6..d386cfa 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/help-top.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/help-top.inc >@@ -10,7 +10,7 @@ > [% END %] > <script type="text/javascript" src="[% interface %]/lib/jquery/jquery.js"></script> > <script type="text/javascript" src="[% interface %]/lib/jquery/jquery-ui.js"></script> >-<script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.hotkeys.min.js"></script> >+<script type="text/javascript" src="[% interface %]/lib/jquery/plugins/shortcut.js"></script> > <!-- yui js --> > <script type="text/javascript" src="[% yuipath %]/utilities/utilities.js"></script> > <script type="text/javascript" src="[% yuipath %]/button/button-min.js"></script> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/en/js/staff-global.js >index 3d605e8..91da8e0 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/js/staff-global.js >+++ b/koha-tmpl/intranet-tmpl/prog/en/js/staff-global.js >@@ -8,9 +8,9 @@ function _(s) { return s; } // dummy function for gettext > > $(".close").click(function(){ window.close(); }); > >- if($("#header_search #checkin_search").length > 0){ $(document).bind('keydown','Alt+r',function (){ $("#header_search").tabs("select","#checkin_search"); $("#ret_barcode").focus(); }); } else { $(document).bind('keydown','Alt+r',function (){ location.href="/cgi-bin/koha/circ/returns.pl"; }); } >- if($("#header_search #circ_search").length > 0){ $(document).bind('keydown','Alt+u',function (){ $("#header_search").tabs("select","#circ_search"); $("#findborrower").focus(); }); } else { $(document).bind('keydown','Alt+u',function(){ location.href="/cgi-bin/koha/circ/circulation.pl"; }); } >- if($("#header_search #catalog_search").length > 0){ $(document).bind('keydown','Alt+q',function (){ $("#header_search").tabs("select","#catalog_search"); $("#search-form").focus(); }); } else { $(document).bind('keydown','Alt+q',function(){ location.href="/cgi-bin/koha/catalogue/search.pl"; }); } >+ if($("#header_search #checkin_search").length > 0){ shortcut.add('Alt+r',function (){ $("#header_search").tabs("select","#checkin_search"); $("#ret_barcode").focus(); }); } else { shortcut.add('Alt+r',function (){ location.href="/cgi-bin/koha/circ/returns.pl"; }); } >+ if($("#header_search #circ_search").length > 0){ shortcut.add('Alt+u',function (){ $("#header_search").tabs("select","#circ_search"); $("#findborrower").focus(); }); } else { shortcut.add('Alt+u',function(){ location.href="/cgi-bin/koha/circ/circulation.pl"; }); } >+ if($("#header_search #catalog_search").length > 0){ shortcut.add('Alt+q',function (){ $("#header_search").tabs("select","#catalog_search"); $("#search-form").focus(); }); } else { shortcut.add('Alt+q',function(){ location.href="/cgi-bin/koha/catalogue/search.pl"; }); } > > $(".focus").focus(); > $(".validated").validate(); >-- >1.7.2.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 11035
:
21952
|
22311
|
22415
|
22416
|
23259
|
23260