123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- var EventDispatcher = function () {};
- Object.assign( EventDispatcher.prototype, {
- addEventListener: function ( type, listener ) {
- if ( this._listeners === undefined ) this._listeners = {};
- var listeners = this._listeners;
- if ( listeners[ type ] === undefined ) {
- listeners[ type ] = [];
- }
- if ( listeners[ type ].indexOf( listener ) === - 1 ) {
- listeners[ type ].push( listener );
- }
- },
- hasEventListener: function ( type, listener ) {
- if ( this._listeners === undefined ) return false;
- var listeners = this._listeners;
- if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
- return true;
- }
- return false;
- },
- removeEventListener: function ( type, listener ) {
- if ( this._listeners === undefined ) return;
- var listeners = this._listeners;
- var listenerArray = listeners[ type ];
- if ( listenerArray !== undefined ) {
- var index = listenerArray.indexOf( listener );
- if ( index !== - 1 ) {
- listenerArray.splice( index, 1 );
- }
- }
- },
- dispatchEvent: function ( event ) {
- if ( this._listeners === undefined ) return;
- var listeners = this._listeners;
- var listenerArray = listeners[ event.type ];
- if ( listenerArray !== undefined ) {
- event.target = this;
- var array = [], i = 0;
- var length = listenerArray.length;
- for ( i = 0; i < length; i ++ ) {
- array[ i ] = listenerArray[ i ];
- }
- for ( i = 0; i < length; i ++ ) {
- array[ i ].call( this, event );
- }
- }
- }
- } );
|