Sha256: 2787414ecd8d4e8d3b50404cd4aa6f78f696a46c4661e1a47869ebc418db3bda
Contents?: true
Size: 1.04 KB
Versions: 28
Compression:
Stored size: 1.04 KB
Contents
/** * adds a bindScoped method to Mousetrap that allows you to * bind specific keyboard shortcuts that will work only within * certain context * inside a text input field * * usage: * Mousetrap.bindScoped('.some-class', 'ctrl+s', _saveChanges); */ Mousetrap = (function(Mousetrap) { var _scopedCallbacks = {}, _originalStopCallback = Mousetrap.stopCallback; Mousetrap.stopCallback = function(e, element, combo, sequence) { var selector = _scopedCallbacks[combo] || _scopedCallbacks[sequence]; if (selector) { return !$(element).is(selector); } return _originalStopCallback(e, element, combo); }; Mousetrap.bindScoped = function(selector, keys, callback, action) { Mousetrap.bind(keys, callback, action); if (keys instanceof Array) { for (var i = 0; i < keys.length; i++) { _scopedCallbacks[keys[i]] = selector; } return; } _scopedCallbacks[keys] = selector; }; return Mousetrap; }) (Mousetrap);
Version data entries
28 entries across 28 versions & 1 rubygems