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

Version Path
riemann-dash-0.2.5 lib/riemann/dash/public/keys.js
riemann-dash-0.2.4 lib/riemann/dash/public/keys.js
riemann-dash-0.2.3 lib/riemann/dash/public/keys.js
mindreframer-riemann-dash-0.2.3 lib/riemann/dash/public/keys.js
mindreframer-reslike-dash-0.2.2 lib/riemann/dash/public/keys.js
riemann-dash-0.2.1 lib/riemann/dash/public/keys.js
riemann-dash-0.2.0 lib/riemann/dash/public/keys.js
riemann-dash-0.1.1 lib/riemann/dash/public/keys.js