UNPKG

mousetrap-global-bind

Version:

Mousetrap plugin for global bindings (works in input elements) with an additionnal unbindGlobal method.

16 lines (15 loc) 680 B
/** * adds a bindGlobal method to Mousetrap that allows you to * bind specific keyboard shortcuts that will still work * inside a text input field * * usage: * Mousetrap.bindGlobal('ctrl+s', _saveChanges); */ !function(t){var n={},o=t.prototype.stopCallback t.prototype.stopCallback=function(t,a,r,i){var e=this return!!e.paused||!n[r]&&!n[i]&&o.call(e,t,a,r)},t.prototype.bindGlobal=function(t,o,a){var r=this if(r.bind(t,o,a),t instanceof Array)for(var i=0;i<t.length;i++)n[t[i]]=!0 else n[t]=!0},t.prototype.unbindGlobal=function(t,o){var a=this if(a.unbind(t,o),t instanceof Array)for(var r=0;r<t.length;r++)n[t[r]]=!1 else n[t]=!1},t.init()}(Mousetrap)