function Event() {
    var handlers = [];

    /***
     * Adds an event handler to be called when the event is fired.
     * <p>Event handler will receive two arguments - an <code>EventData</code> and the <code>data</code>
     * object the event was fired with.<p>
     * @method subscribe
     * @param fn {Function} Event handler.
     * @return {Function} the registered event handler `fn`.
     */
    this.subscribe = function (fn) {
      handlers.push(fn);
      return fn;
    };

    /***
     * Removes an event handler added with <code>subscribe(fn)</code>.
     * @method unsubscribe
     * @param fn {Function} Event handler to be removed. When undefined, all event handlers are unsubscribed.
     */
    this.unsubscribe = function (fn) {
      if (!fn) {
        handlers = [];
      } else {
        for (var i = handlers.length - 1; i >= 0; i--) {
          if (handlers[i] === fn) {
            handlers.splice(i, 1);
          }
        }
      }
    };

    /***
     * Returns the list of registered event handlers as an array.
     * @method handlers
     * @return the list of registered event handlers as an array. When no handlers are registered the array is empty.
     */
    this.handlers = function () {
      return handlers;
    };

    /***
     * Fires an event notifying all subscribers.
     * @method notify
     * @param args {Object} Additional data object to be passed to all handlers.
     * @param e {EventData}
     *      Optional.
     *      An <code>EventData</code> object to be passed to all handlers.
     *      For DOM events, an existing W3C/jQuery event object can be passed in.
     * @param scope {Object}
     *      Optional.
     *      The scope ("this") within which the handler will be executed.
     *      If not specified, the scope will be set to the <code>Event</code> instance.
     * @return {boolean} the return value produced by the event handlers; boolean TRUE by default.
     */
    this.notify = function (args, e, scope) {
      e = e || new EventData();
      scope = scope || this;

      var returnValue = true;
      for (var i = 0; i < handlers.length && !(e.isPropagationStopped() || e.isImmediatePropagationStopped()); i++) {
        returnValue = handlers[i].call(scope, e, args, returnValue);
      }

      return returnValue;
    };
  }
/***
   * A simple publisher-subscriber implementation.
   * @class Event
   * @constructor
   */
A simple publisher-subscriber implementation.
@class Event
@constructor
A simple publisher - subscriber implementation . @class Event @constructor
function Event() {
    var handlers = [];
    this.subscribe = function (fn) {
      handlers.push(fn);
      return fn;
    };
    this.unsubscribe = function (fn) {
      if (!fn) {
        handlers = [];
      } else {
        for (var i = handlers.length - 1; i >= 0; i--) {
          if (handlers[i] === fn) {
            handlers.splice(i, 1);
          }
        }
      }
    };
    this.handlers = function () {
      return handlers;
    };
    this.notify = function (args, e, scope) {
      e = e || new EventData();
      scope = scope || this;
      var returnValue = true;
      for (var i = 0; i < handlers.length && !(e.isPropagationStopped() || e.isImmediatePropagationStopped()); i++) {
        returnValue = handlers[i].call(scope, e, args, returnValue);
      }
      return returnValue;
    };
  }
function Event ( ) { var handlers = [ ] ; this . subscribe = function ( fn ) { handlers . push ( fn ) ; return fn ; } ; this . unsubscribe = function ( fn ) { if ( ! fn ) { handlers = [ ] ; } else { for ( var i = handlers . length - 1 ; i >= 0 ; i -- ) { if ( handlers [ i ] === fn ) { handlers . splice ( i , 1 ) ; } } } } ; this . handlers = function ( ) { return handlers ; } ; this . notify = function ( args , e , scope ) { e = e || new EventData ( ) ; scope = scope || this ; var returnValue = true ; for ( var i = 0 ; i < handlers . length && ! ( e . isPropagationStopped ( ) || e . isImmediatePropagationStopped ( ) ) ; i ++ ) { returnValue = handlers [ i ] . call ( scope , e , args , returnValue ) ; } return returnValue ; } ; }
A simple publisher-subscriber implementation.
A simple publisher - subscriber implementation .
/***
     * Adds an event handler to be called when the event is fired.
     * <p>Event handler will receive two arguments - an <code>EventData</code> and the <code>data</code>
     * object the event was fired with.<p>
     * @method subscribe
     * @param fn {Function} Event handler.
     * @return {Function} the registered event handler `fn`.
     */ /***
     * Removes an event handler added with <code>subscribe(fn)</code>.
     * @method unsubscribe
     * @param fn {Function} Event handler to be removed. When undefined, all event handlers are unsubscribed.
     */ /***
     * Returns the list of registered event handlers as an array.
     * @method handlers
     * @return the list of registered event handlers as an array. When no handlers are registered the array is empty.
     */ /***
     * Fires an event notifying all subscribers.
     * @method notify
     * @param args {Object} Additional data object to be passed to all handlers.
     * @param e {EventData}
     *      Optional.
     *      An <code>EventData</code> object to be passed to all handlers.
     *      For DOM events, an existing W3C/jQuery event object can be passed in.
     * @param scope {Object}
     *      Optional.
     *      The scope ("this") within which the handler will be executed.
     *      If not specified, the scope will be set to the <code>Event</code> instance.
     * @return {boolean} the return value produced by the event handlers; boolean TRUE by default.
     */