Exemplo n.º 1
0
            add: function(fn){

                if( !Type.isFunction(fn) ) 
                    return;

                actions.on("done", fn);

            },
Exemplo n.º 2
0
      app.sandbox.on = function (name, listener, context) {
        if (!_.isFunction(listener) || !_.isString(name)) {
          throw new Error('Invalid arguments passed to sandbox.on');
        }
        context = context || this;
        var callback = function() {
          var args = Array.prototype.slice.call(arguments);
          try {
            listener.apply(context, args);
          } catch(e) {

          }
        };

        this._events = this._events || [];
        this._events.push({ name: name, listener: listener, callback: callback });

        mediator.on(name, callback);
      };
Exemplo n.º 3
0
      app.sandbox.on = function (name, listener) {
        this._events = this._events || [];
        this._events.push({ name: name, listener: listener});

        mediator.on(name, listener);
      };
Exemplo n.º 4
0
            initialize: function(app) {
                var EventEmitter = require('eventemitter'),
                    mediator;

                app.config.mediator = app.core.util.defaults(app.config.mediator || {}, defaults);
                mediator = new EventEmitter(app.config.mediator);
                app.core.mediator = mediator;


                /**
                 * @class Sandbox
                 */

                // extending the default sandbox

                /**
                 * @method on
                 * @param {String} name
                 * @param {Function} listener
                 */
                app.sandbox.on = attachListener('on');

                /**
                 * @method once
                 * @param {String} name
                 * @param {Function} listener
                 */
                app.sandbox.once = attachListener('once');

                /**
                 * @method off
                 * @param {String} name
                 * @param {Function} listener
                 */
                app.sandbox.off = function(name, listener) {

                    if (!this.events) {
                        return;
                    }

                    this.events = app.core.util.reject(this.events, function(event) {
                        var match = (event.name === name && event.listener === listener);

                        if (match) {
                            mediator.off(name, event.callback);
                        }

                        return match;
                    });
                };

                /**
                 * @method emit
                 * @param {String} name
                 * @param {Object} payload
                 */
                app.sandbox.emit = function() {

                    var debug = app.config.debug,
                        eventLogData;

                    if (debug === true || (!!debug.enable &&
                        (debug.components.length === 0 || debug.components.indexOf('husky:mediator') !== -1))) {
                        eventLogData = Array.prototype.slice.call(arguments);
                        eventLogData.unshift('Event emitted');
                        app.logger.log.apply(app.logger, eventLogData);
                    }

                    mediator.emit.apply(mediator, arguments);
                };

                /**
                 * @method stopListening
                 */
                app.sandbox.stopListening = function() {

                    if (!this.events) {
                        return;
                    }

                    app.core.util.each(this.events, function(event) {
                        mediator.off(event.name, event.callback);
                    });
                };

                // default event listener

                mediator.on(['husky', 'sandbox', 'stop'], function(sandbox) {
                    sandbox.stopListening();
                });

                mediator.on(['husky', 'sandbox', 'pause'], function(sandbox) {
                    // TODO Implement pause event listening
                    app.logger.warn('ATTENTION: Sandbox pause not implemented!', sandbox);
                });

                mediator.on(['husky', 'sandbox', 'continue'], function(sandbox) {
                    // TODO Implement continue event listening
                    app.logger.warn('ATTENTION: Sandbox continue not implemented!', sandbox);
                });
            }
Exemplo n.º 5
0
 onScroll: function(fn){
     events.on("scroll", fn);
 },
Exemplo n.º 6
0
 onResize: function(fn){
     events.on("resize", fn);
 },
Exemplo n.º 7
0
Scope.prototype.on = function(event, callback) {
    this.listeners.push([event, callback]);
    return bus.on(event, callback);
};