text: // Generated by CoffeeScript 2.2.2
  /* EventManager, v1.0.1
  *
  * Copyright (c) 2009, Howard Rauscher
  * Licensed under the MIT License
   */
  var EventManager;
  
  export default EventManager = (function() {
    var EventArg;
  
    //Based on the code https://gist.github.com/howardr/118668 - thanks!
    class EventManager {
      constructor() {
        this._listeners = [];
      }
  
      addListener(name, fn) {
        (this._listeners[name] = this._listeners[name] || []).push(fn);
        return this;
      }
  
      removeListener(name, fn) {
        var foundAt, i, j, len1, listener, listeners;
        if (arguments.length === 1) {
          this._listeners[name] = [];
        } else if (typeof fn === 'function') {
          listeners = this._listeners[name];
          if (listeners !== void 0) {
            foundAt = -1;
            for (i = j = 0, len1 = listeners.length; j < len1; i = ++j) {
              listener = listeners[i];
              if (listener === fn) {
                foundAt = i;
                break;
              }
            }
            if (foundAt >= 0) {
              listeners.splice(foundAt, 1);
            }
          }
        }
        return this;
      }
  
      fire(name, args) {
        var data, evt, i, j, len, len1, listener, listeners;
        listeners = this._listeners[name];
        args = args || [];
        if (listeners !== void 0) {
          data = {};
          evt = null;
          for (i = j = 0, len1 = listeners.length; j < len1; i = ++j) {
            listener = listeners[i];
            evt = new EventArg(name, data);
            listener.apply(window, args.concat(evt));
            data = evt.data;
            if (evt.removed) {
              listeners.splice(i, 1);
              len = listeners.length;
              --i;
            }
            if (evt.cancelled) {
              break;
            }
          }
        }
        return this;
      }
  
      hasListeners(name) {
        var ref;
        return ((ref = this._listeners[name] === void 0) != null ? ref : {
          0: this._listeners[name].length
        }) > 0;
      }
  
      static eventify(object, manager) {
        var func, j, len1, method, methods, results;
        methods = ['addListener', 'removeListener', 'fire'];
        manager = manager || new EventManager();
        func = function(method) {
          return object[method] = function() {
            return manager[method].apply(manager, arguments);
          };
        };
        results = [];
        for (j = 0, len1 = methods.length; j < len1; j++) {
          method = methods[j];
          results.push(func(method));
        }
        return results;
      }
  
    };
  
    EventArg = class EventArg {
      constructor(name1, data1) {
        this.name = name1;
        this.data = data1;
        this.cancelled = false;
        this.removed = false;
      }
  
      cancel() {
        return this.cancelled = true;
      }
  
      remove() {
        return this.removed = true;
      }
  
    };
  
    return EventManager;
  
  }).call(this);
  