
(function($){var defaults={disableInInput:false,propagate:false,target:$('html').get(0)};var specialKeys={8:'backspace',9:'tab',13:'enter',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',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:'scrolllock'};$.hotkeys={add:function(keys,options,callback){if($.isFunction(options)){callback=options;options={};}
if(!$.isFunction(callback))return;options=options||{};keys=keys.toLowerCase();options=$.extend(defaults,options);options.target=$(options.target).get(0);if(options.target.document)options.target=options.target.document;if(options.target.nodeName.toLowerCase()=='body')options.target=options.target.ownerDocument;if(options.target.body)options.target=$('html',options.target);var target=$(options.target);var hotkeys=target.data('hotkeys');if(!hotkeys){target.keydown(checkEvent);hotkeys={};target.data('hotkeys',hotkeys);}
hotkeys[keys]={callback:callback,options:options};},remove:function(options){var keys=options.keys?options.keys.toLowerCase():null;var target=options.target?$(options.target).get(0):document;$(target).each(function(){var hotkeys=$(this).data('hotkeys');delete hotkeys[keys];});}};var checkEvent=function(e){var target=e.target;if(target.nodeType==3)target=target.parentNode;var originalTarget=target;var hotkeys=$(target).data('hotkeys');while(!hotkeys&&target.tagName.toLowerCase()!='html'){target=target.parentNode;var hotkeys=$(target).data('hotkeys');}
keys='';if(e.altKey)keys+='alt+';if(e.ctrlKey)keys+='ctrl+';if(!e.ctrlKey&&e.metaKey)keys+='cmd+';if(e.shiftKey)keys+='shift+';keys+=specialKeys[e.which]||String.fromCharCode(e.which).toLowerCase();if(keys.charAt(keys.length-1)=='+')keys=keys.substr(0,keys.length-1);if(!hotkeys[keys])return;if(hotkeys[keys].options.disableInInput&&$(originalTarget).is('input, textarea'))return;hotkeys[keys].callback();if(hotkeys[keys].options.propagate)return;e.preventDefault();e.stopPropagation();return false;};})(jQuery);