Code coverage report for src/pixi/utils/EventTarget.js

Statements: 85% (17 / 20)      Branches: 75% (9 / 12)      Functions: 80% (4 / 5)      Lines: 85% (17 / 20)     

All files » src/pixi/utils\ » EventTarget.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72                                  1   12   12     20   15       20   20         12   21   2       19   24           12   5   5   2           12            
/**
 * https://github.com/mrdoob/eventtarget.js/
 * THankS mr DOob!
 */
 
/**
 * Adds event emitter functionality to a class
 *
 * @class EventTarget
 * @example
 *      function MyEmitter() {
 *          PIXI.EventTarget.call(this); //mixes in event target stuff
 *      }
 *
 *      var em = new MyEmitter();
 *      em.emit({ type: 'eventName', data: 'some data' });
 */
PIXI.EventTarget = function () {
 
    var listeners = {};
 
    this.addEventListener = this.on = function ( type, listener ) {
 
 
        if ( listeners[ type ] === undefined ) {
 
            listeners[ type ] = [];
 
        }
 
        Eif ( listeners[ type ].indexOf( listener ) === - 1 ) {
 
            listeners[ type ].push( listener );
        }
 
    };
 
    this.dispatchEvent = this.emit = function ( event ) {
 
        if ( !listeners[ event.type ] || !listeners[ event.type ].length ) {
 
            return;
 
        }
 
        for(var i = 0, l = listeners[ event.type ].length; i < l; i++) {
 
            listeners[ event.type ][ i ]( event );
 
        }
 
    };
 
    this.removeEventListener = this.off = function ( type, listener ) {
 
        var index = listeners[ type ].indexOf( listener );
 
        if ( index !== - 1 ) {
 
            listeners[ type ].splice( index, 1 );
 
        }
 
    };
 
	this.removeAllEventListeners = function( type ) {
		var a = listeners[type];
		if (a)
			a.length = 0;
	};
};