Browse Source

Renamed EventTarget to EventDispatcher as discussed in fdb737d078e0e3d6eba9856cec77401082a42fe8.

Mr.doob 12 years ago
parent
commit
28aba0b81a

+ 3 - 3
docs/api/extras/core/EventTarget.html → docs/api/core/EventDispatcher.html

@@ -2,9 +2,9 @@
 <html lang="en">
 	<head>
 		<meta charset="utf-8">
-		<script src="../../../list.js"></script>
-		<script src="../../../page.js"></script>
-		<link type="text/css" rel="stylesheet" href="../../../page.css" />
+		<script src="../../list.js"></script>
+		<script src="../../page.js"></script>
+		<link type="text/css" rel="stylesheet" href="../../page.css" />
 	</head>
 	<body>
 		<h1>[name]</h1>

+ 1 - 1
docs/list.js

@@ -16,6 +16,7 @@ var list = {
 		"Core": [
 			[ "Clock", "api/core/Clock" ],
 			[ "Color", "api/core/Color" ],
+			[ "EventDispatcher", "api/core/EventDispatcher" ],
 			[ "Face3", "api/core/Face3" ],
 			[ "Face4", "api/core/Face4" ],
 			[ "Frustum", "api/core/Frustum" ],
@@ -139,7 +140,6 @@ var list = {
 			[ "BufferGeometry", "api/extras/core/BufferGeometry" ],
 			[ "Curve", "api/extras/core/Curve" ],
 			[ "CurvePath", "api/extras/core/CurvePath" ],
-			[ "EventTarget", "api/extras/core/EventTarget" ],
 			[ "Gyroscope", "api/extras/core/Gyroscope" ],
 			[ "Path", "api/extras/core/Path" ],
 			[ "Shape", "api/extras/core/Shape" ]

+ 1 - 1
examples/js/controls/OrbitControls.js

@@ -7,7 +7,7 @@
 
 THREE.OrbitControls = function ( object, domElement ) {
 
-	THREE.EventTarget.call( this );
+	THREE.EventDispatcher.call( this );
 
 	this.object = object;
 	this.domElement = ( domElement !== undefined ) ? domElement : document;

+ 1 - 1
examples/js/controls/TrackballControls.js

@@ -4,7 +4,7 @@
 
 THREE.TrackballControls = function ( object, domElement ) {
 
-	THREE.EventTarget.call( this );
+	THREE.EventDispatcher.call( this );
 
 	var _this = this;
 	var STATE = { NONE: -1, ROTATE: 0, ZOOM: 1, PAN: 2 };

+ 3 - 2
examples/js/loaders/MTLLoader.js

@@ -6,7 +6,8 @@
 
 THREE.MTLLoader = function( baseUrl, options ) {
 
-	THREE.EventTarget.call( this );
+	THREE.EventDispatcher.call( this );
+	
 	this.baseUrl = baseUrl;
 	this.options = options;
 
@@ -149,7 +150,7 @@ THREE.MTLLoader.prototype = {
 
 THREE.MTLLoader.MaterialCreator = function( baseUrl, options ) {
 
-	THREE.EventTarget.call( this );
+	THREE.EventDispatcher.call( this );
 
 	this.baseUrl = baseUrl;
 	this.options = options;

+ 1 - 1
examples/js/loaders/OBJLoader.js

@@ -4,7 +4,7 @@
 
 THREE.OBJLoader = function () {
 
-	THREE.EventTarget.call( this );
+	THREE.EventDispatcher.call( this );
 
 };
 

+ 1 - 1
examples/js/loaders/OBJMTLLoader.js

@@ -7,7 +7,7 @@
 
 THREE.OBJMTLLoader = function ( ) {
 
-	THREE.EventTarget.call( this );
+	THREE.EventDispatcher.call( this );
 
 };
 

+ 1 - 1
examples/js/loaders/STLLoader.js

@@ -20,7 +20,7 @@
 
 THREE.STLLoader = function () {
 
-	THREE.EventTarget.call( this );
+	THREE.EventDispatcher.call( this );
 
 };
 

+ 1 - 1
examples/js/loaders/VTKLoader.js

@@ -4,7 +4,7 @@
 
 THREE.VTKLoader = function () {
 
-	THREE.EventTarget.call( this );
+	THREE.EventDispatcher.call( this );
 
 };
 

+ 2 - 2
src/core/BufferGeometry.js

@@ -4,7 +4,7 @@
 
 THREE.BufferGeometry = function () {
 
-	THREE.EventTarget.call( this );
+	THREE.EventDispatcher.call( this );
 
 	this.id = THREE.GeometryIdCount ++;
 
@@ -546,7 +546,7 @@ THREE.BufferGeometry.prototype = {
 
 	deallocate: function () {
 
-		this.dispatchEvent( { type: 'deallocate', target: this } );
+		this.dispatchEvent( { type: 'deallocate' } );
 
 	}
 

+ 17 - 15
src/core/EventTarget.js → src/core/EventDispatcher.js

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

+ 2 - 2
src/core/Geometry.js

@@ -9,7 +9,7 @@
 
 THREE.Geometry = function () {
 
-	THREE.EventTarget.call( this );
+	THREE.EventDispatcher.call( this );
 
 	this.id = THREE.GeometryIdCount ++;
 
@@ -738,7 +738,7 @@ THREE.Geometry.prototype = {
 
 	deallocate: function () {
 
-		this.dispatchEvent( { type: 'deallocate', target: this } );
+		this.dispatchEvent( { type: 'deallocate' } );
 
 	}
 

+ 1 - 1
src/loaders/ImageLoader.js

@@ -4,7 +4,7 @@
 
 THREE.ImageLoader = function () {
 
-	THREE.EventTarget.call( this );
+	THREE.EventDispatcher.call( this );
 
 	this.crossOrigin = null;
 

+ 1 - 1
src/loaders/LoadingMonitor.js

@@ -4,7 +4,7 @@
 
 THREE.LoadingMonitor = function () {
 
-	THREE.EventTarget.call( this );
+	THREE.EventDispatcher.call( this );
 
 	var scope = this;
 

+ 1 - 1
src/loaders/SceneLoader.js

@@ -569,7 +569,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 			var result;
 
-			// loaders which use EventTarget
+			// loaders which use EventDispatcher
 
 			if ( event.content ) {
 

+ 1 - 1
src/loaders/TextureLoader.js

@@ -4,7 +4,7 @@
 
 THREE.TextureLoader = function () {
 
-	THREE.EventTarget.call( this );
+	THREE.EventDispatcher.call( this );
 
 	this.crossOrigin = null;
 

+ 2 - 2
src/materials/Material.js

@@ -5,7 +5,7 @@
 
 THREE.Material = function () {
 
-	THREE.EventTarget.call( this );
+	THREE.EventDispatcher.call( this );
 
 	this.id = THREE.MaterialIdCount ++;
 
@@ -118,7 +118,7 @@ THREE.Material.prototype.clone = function ( material ) {
 
 THREE.Material.prototype.deallocate = function () {
 
-	this.dispatchEvent( { type: 'deallocate', target: this } );
+	this.dispatchEvent( { type: 'deallocate' } );
 
 };
 

+ 2 - 2
src/renderers/WebGLRenderTarget.js

@@ -5,7 +5,7 @@
 
 THREE.WebGLRenderTarget = function ( width, height, options ) {
 
-	THREE.EventTarget.call( this );
+	THREE.EventDispatcher.call( this );
 
 	this.width = width;
 	this.height = height;
@@ -66,6 +66,6 @@ THREE.WebGLRenderTarget.prototype.clone = function() {
 
 THREE.WebGLRenderTarget.prototype.deallocate = function () {
 
-	this.dispatchEvent( { type: 'deallocate', target: this } );
+	this.dispatchEvent( { type: 'deallocate' } );
 
 };

+ 2 - 2
src/textures/Texture.js

@@ -6,7 +6,7 @@
 
 THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
 
-	THREE.EventTarget.call( this );
+	THREE.EventDispatcher.call( this );
 
 	this.id = THREE.TextureIdCount ++;
 
@@ -79,7 +79,7 @@ THREE.Texture.prototype = {
 
 	deallocate: function () {
 
-		this.dispatchEvent( { type: 'deallocate', target: this } );
+		this.dispatchEvent( { type: 'deallocate' } );
 
 	}
 

+ 1 - 1
utils/includes/canvas.json

@@ -16,7 +16,7 @@
 	"../src/math/Quaternion.js",
 	"../src/math/Vertex.js",
 	"../src/math/UV.js",
-	"../src/core/EventTarget.js",
+	"../src/core/EventDispatcher.js",
 	"../src/core/Raycaster.js",
 	"../src/core/Object3D.js",
 	"../src/core/Projector.js",

+ 1 - 1
utils/includes/common.json

@@ -19,7 +19,7 @@
 	"../src/math/Vertex.js",
 	"../src/math/UV.js",
 	"../src/core/Clock.js",
-	"../src/core/EventTarget.js",
+	"../src/core/EventDispatcher.js",
 	"../src/core/Raycaster.js",
 	"../src/core/Object3D.js",
 	"../src/core/Projector.js",

+ 1 - 1
utils/includes/css3d.json

@@ -12,7 +12,7 @@
 	"../src/math/Sphere.js",
 	"../src/math/Triangle.js",
 	"../src/math/Plane.js",
-	"../src/core/EventTarget.js",
+	"../src/core/EventDispatcher.js",
 	"../src/core/Raycaster.js",
 	"../src/core/Object3D.js",
 	"../src/core/Projector.js",

+ 1 - 1
utils/includes/webgl.json

@@ -18,7 +18,7 @@
 	"../src/math/Sphere.js",
 	"../src/math/Plane.js",
 	"../src/core/Clock.js",
-	"../src/core/EventTarget.js",
+	"../src/core/EventDispatcher.js",
 	"../src/core/Raycaster.js",
 	"../src/core/Object3D.js",
 	"../src/core/Projector.js",