Sha256: 62c4a04537271c8f13f4c355c38d313e288a126778872f4b3af3d80ac8f13ae7
Contents?: true
Size: 849 Bytes
Versions: 8
Compression:
Stored size: 849 Bytes
Contents
var keys = (function() { var active = true; var bindings = {}; // Disable bindings. var disable = function() { active = false; } // Enable bindings. var enable = function() { active = true; } // Bind a key. var bind = function(code, fn) { if (bindings[code] === undefined) { bindings[code] = []; } bindings[code].push(fn); } // React to key presses. $(document).bind('keydown', function(ev) { if (active === false) { return; } console.log(ev.which); var fns = bindings[ev.which]; if (fns !== undefined) { fns.forEach(function(fn) { fn(ev); }); // ev.preventDefault(); } }); return { active: function() { return active; }, bindings: function() { return bindings; }, bind: bind, enable: enable, disable: disable } })();
Version data entries
8 entries across 8 versions & 3 rubygems