-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhotkeys.min.js
1 lines (1 loc) · 1.64 KB
/
hotkeys.min.js
1
(function($){$.fn.hotKey=function(options,callback){var $self=this;var keys={"backspace":8,"tab":9,"return":13,"pause":19,"capslock":20,"esc":27,"space":32,"pageup":33,"pagedown":34,"end":35,"home":36,"left":37,"up":38,"right":39,"down":40,"insert":45,"del":46,"num0":96,"num1":97,"num2":98,"num3":99,"num4":100,"num5":101,"num6":102,"num7":103,"num8":104,"num9":105,"num*":106,"num+":107,"num-":109,"num.":110,"num/":111,"f1":112,"f2":113,"f3":114,"f4":115,"f5":116,"f6":117,"f7":118,"f8":119,"f9":120,"f10":121,"f11":122,"f12":123,"numlock":144,"scroll":145,";":186,"/":191,"\\":220,"'":222};var modifiers={'alt':'alt','ctrl':'ctrl','shift':'shift'};for(var i=65;i<91;i++){keys[String.fromCharCode(i).toLowerCase()]=i}return this.each(function(){var cb,hotKeyCode=0,modifier="",settings=$.extend({key:"",modifier:""},options);if((settings.key==="")||(typeof settings.key!=="string"))return;settings.key=settings.key.toLowerCase();if((settings.modifier!=="")&&(typeof settings.modifier==="string")){modifier=(modifiers[settings.modifier.toLowerCase()])?modifiers[settings.modifier.toLowerCase()]:0;if(!modifier)return}cb=callback;if(Object.prototype.toString.call(cb)!='[object Function]')return;hotKeyCode=(keys[settings.key])?keys[settings.key]:0;if(!hotKeyCode)return;$self.keydown(function(event){var keyCode=(event.which)?event.which:event.keyCode;if(((modifier=='alt')&&event.altKey)||((modifier=='ctrl')&&event.ctrlKey)||((modifier=='shift')&&event.shiftKey)||(modifier==="")){checkAndExecute(this)}function checkAndExecute(self){if(keyCode==hotKeyCode){cb.apply(self,arguments);event.preventDefault();event.stopPropagation();event.stopImmediatePropagation()}}})})}})(jQuery);