12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- /**
- * https://github.com/mrdoob/eventdispatcher.js/
- */
- THREE.EventDispatcher = function () {
- var listeners = {};
- this.addEventListener = function ( type, listener ) {
- if ( listeners[ type ] === undefined ) {
- listeners[ type ] = [];
- }
- if ( listeners[ type ].indexOf( listener ) === - 1 ) {
- listeners[ type ].push( listener );
- }
- };
- this.removeEventListener = function ( type, listener ) {
- var index = listeners[ type ].indexOf( listener );
- if ( index !== - 1 ) {
- listeners[ type ].splice( index, 1 );
- }
- };
- this.dispatchEvent = function ( event ) {
- var listenerArray = listeners[ event.type ];
- if ( listenerArray !== undefined ) {
- event.target = this;
- for ( var i = 0, l = listenerArray.length; i < l; i ++ ) {
- listenerArray[ i ].call( this, event );
- }
- }
- };
- };
|