// Generated by CoffeeScript 1.4.0
(function() {

  (function($) {
    return $.keyStroke = function(requiredKeys, callback, options) {
      var $document, activeKeys, checkKeystroke, executeCallback;
      if (options == null) {
        options = {};
      }
      options = $.extend({
        context: this,
        args: [],
        preventDefault: true,
        modKeys: []
      }, options);
      $document = $(document);
      activeKeys = [];
      $document.keydown(function(event) {
        activeKeys.push(event.keyCode);
        activeKeys = activeKeys.filter(function(item, index, array) {
          return index === $.inArray(item, array);
        });
        if (checkKeystroke(event)) {
          return executeCallback(event);
        }
      });
      $document.keyup(function(event) {
        var index;
        index = $.inArray(event.keyCode, activeKeys);
        if (index > -1) {
          return activeKeys.splice(index, 1);
        }
      });
      executeCallback = function(event) {
        if (options.preventDefault) {
          event.preventDefault();
        }
        return callback.apply(options.context, [event].concat(options.args));
      };
      return checkKeystroke = function(event) {
        var modifier, _i, _len, _ref, _ref1;
        if ('array' === $.type(requiredKeys)) {
          return (0 === (_ref = $(activeKeys).not(requiredKeys).length) && _ref === $(requiredKeys).not(activeKeys).length);
        } else {
          if (1 + options.modKeys.length !== activeKeys.length) {
            return false;
          }
          if (!($.inArray(requiredKeys, activeKeys) > -1)) {
            return false;
          }
          _ref1 = options.modKeys;
          for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
            modifier = _ref1[_i];
            if (!event[modifier]) {
              return false;
            }
          }
          return true;
        }
      };
    };
  })(jQuery);

}).call(this);
