diff --git a/src/pixi/loaders/AssetLoader.js b/src/pixi/loaders/AssetLoader.js index 013eadb..7bcb8df 100644 --- a/src/pixi/loaders/AssetLoader.js +++ b/src/pixi/loaders/AssetLoader.js @@ -20,8 +20,6 @@ */ PIXI.AssetLoader = function(assetURLs, crossorigin) { - PIXI.EventTarget.call(this); - /** * The array of asset URLs that are going to be loaded * @@ -57,6 +55,8 @@ }; }; +PIXI.EventTarget.mixin(PIXI.AssetLoader.prototype); + /** * Fired when an item has loaded * @event onProgress diff --git a/src/pixi/loaders/AssetLoader.js b/src/pixi/loaders/AssetLoader.js index 013eadb..7bcb8df 100644 --- a/src/pixi/loaders/AssetLoader.js +++ b/src/pixi/loaders/AssetLoader.js @@ -20,8 +20,6 @@ */ PIXI.AssetLoader = function(assetURLs, crossorigin) { - PIXI.EventTarget.call(this); - /** * The array of asset URLs that are going to be loaded * @@ -57,6 +55,8 @@ }; }; +PIXI.EventTarget.mixin(PIXI.AssetLoader.prototype); + /** * Fired when an item has loaded * @event onProgress diff --git a/src/pixi/loaders/AtlasLoader.js b/src/pixi/loaders/AtlasLoader.js index 5476da1..aa6c381 100644 --- a/src/pixi/loaders/AtlasLoader.js +++ b/src/pixi/loaders/AtlasLoader.js @@ -7,14 +7,13 @@ * When loaded this class will dispatch a 'loaded' event * If loading fails this class will dispatch an 'error' event * @class AtlasLoader - * @extends EventTarget + * @uses EventTarget * @constructor * @param {String} url the url of the JSON file * @param {Boolean} crossorigin */ PIXI.AtlasLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); this.url = url; this.baseUrl = url.replace(/[^\/]*$/, ''); this.crossorigin = crossorigin; @@ -25,6 +24,7 @@ // constructor PIXI.AtlasLoader.constructor = PIXI.AtlasLoader; +PIXI.EventTarget.mixin(PIXI.AtlasLoader.prototype); /** * Starts loading the JSON file diff --git a/src/pixi/loaders/AssetLoader.js b/src/pixi/loaders/AssetLoader.js index 013eadb..7bcb8df 100644 --- a/src/pixi/loaders/AssetLoader.js +++ b/src/pixi/loaders/AssetLoader.js @@ -20,8 +20,6 @@ */ PIXI.AssetLoader = function(assetURLs, crossorigin) { - PIXI.EventTarget.call(this); - /** * The array of asset URLs that are going to be loaded * @@ -57,6 +55,8 @@ }; }; +PIXI.EventTarget.mixin(PIXI.AssetLoader.prototype); + /** * Fired when an item has loaded * @event onProgress diff --git a/src/pixi/loaders/AtlasLoader.js b/src/pixi/loaders/AtlasLoader.js index 5476da1..aa6c381 100644 --- a/src/pixi/loaders/AtlasLoader.js +++ b/src/pixi/loaders/AtlasLoader.js @@ -7,14 +7,13 @@ * When loaded this class will dispatch a 'loaded' event * If loading fails this class will dispatch an 'error' event * @class AtlasLoader - * @extends EventTarget + * @uses EventTarget * @constructor * @param {String} url the url of the JSON file * @param {Boolean} crossorigin */ PIXI.AtlasLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); this.url = url; this.baseUrl = url.replace(/[^\/]*$/, ''); this.crossorigin = crossorigin; @@ -25,6 +24,7 @@ // constructor PIXI.AtlasLoader.constructor = PIXI.AtlasLoader; +PIXI.EventTarget.mixin(PIXI.AtlasLoader.prototype); /** * Starts loading the JSON file diff --git a/src/pixi/loaders/BitmapFontLoader.js b/src/pixi/loaders/BitmapFontLoader.js index 9082b33..cd67a37 100644 --- a/src/pixi/loaders/BitmapFontLoader.js +++ b/src/pixi/loaders/BitmapFontLoader.js @@ -21,7 +21,6 @@ * http://www.codeandweb.com/texturepacker * make sure to set the format as 'JSON' */ - PIXI.EventTarget.call(this); /** * The url of the bitmap font data @@ -60,6 +59,8 @@ // constructor PIXI.BitmapFontLoader.prototype.constructor = PIXI.BitmapFontLoader; +PIXI.EventTarget.mixin(PIXI.BitmapFontLoader.prototype); + /** * Loads the XML font data * diff --git a/src/pixi/loaders/AssetLoader.js b/src/pixi/loaders/AssetLoader.js index 013eadb..7bcb8df 100644 --- a/src/pixi/loaders/AssetLoader.js +++ b/src/pixi/loaders/AssetLoader.js @@ -20,8 +20,6 @@ */ PIXI.AssetLoader = function(assetURLs, crossorigin) { - PIXI.EventTarget.call(this); - /** * The array of asset URLs that are going to be loaded * @@ -57,6 +55,8 @@ }; }; +PIXI.EventTarget.mixin(PIXI.AssetLoader.prototype); + /** * Fired when an item has loaded * @event onProgress diff --git a/src/pixi/loaders/AtlasLoader.js b/src/pixi/loaders/AtlasLoader.js index 5476da1..aa6c381 100644 --- a/src/pixi/loaders/AtlasLoader.js +++ b/src/pixi/loaders/AtlasLoader.js @@ -7,14 +7,13 @@ * When loaded this class will dispatch a 'loaded' event * If loading fails this class will dispatch an 'error' event * @class AtlasLoader - * @extends EventTarget + * @uses EventTarget * @constructor * @param {String} url the url of the JSON file * @param {Boolean} crossorigin */ PIXI.AtlasLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); this.url = url; this.baseUrl = url.replace(/[^\/]*$/, ''); this.crossorigin = crossorigin; @@ -25,6 +24,7 @@ // constructor PIXI.AtlasLoader.constructor = PIXI.AtlasLoader; +PIXI.EventTarget.mixin(PIXI.AtlasLoader.prototype); /** * Starts loading the JSON file diff --git a/src/pixi/loaders/BitmapFontLoader.js b/src/pixi/loaders/BitmapFontLoader.js index 9082b33..cd67a37 100644 --- a/src/pixi/loaders/BitmapFontLoader.js +++ b/src/pixi/loaders/BitmapFontLoader.js @@ -21,7 +21,6 @@ * http://www.codeandweb.com/texturepacker * make sure to set the format as 'JSON' */ - PIXI.EventTarget.call(this); /** * The url of the bitmap font data @@ -60,6 +59,8 @@ // constructor PIXI.BitmapFontLoader.prototype.constructor = PIXI.BitmapFontLoader; +PIXI.EventTarget.mixin(PIXI.BitmapFontLoader.prototype); + /** * Loads the XML font data * diff --git a/src/pixi/loaders/ImageLoader.js b/src/pixi/loaders/ImageLoader.js index 568e76b..79d6765 100644 --- a/src/pixi/loaders/ImageLoader.js +++ b/src/pixi/loaders/ImageLoader.js @@ -15,8 +15,6 @@ */ PIXI.ImageLoader = function(url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The texture being loaded * @@ -36,6 +34,8 @@ // constructor PIXI.ImageLoader.prototype.constructor = PIXI.ImageLoader; +PIXI.EventTarget.mixin(PIXI.ImageLoader.prototype); + /** * Loads image or takes it from cache * diff --git a/src/pixi/loaders/AssetLoader.js b/src/pixi/loaders/AssetLoader.js index 013eadb..7bcb8df 100644 --- a/src/pixi/loaders/AssetLoader.js +++ b/src/pixi/loaders/AssetLoader.js @@ -20,8 +20,6 @@ */ PIXI.AssetLoader = function(assetURLs, crossorigin) { - PIXI.EventTarget.call(this); - /** * The array of asset URLs that are going to be loaded * @@ -57,6 +55,8 @@ }; }; +PIXI.EventTarget.mixin(PIXI.AssetLoader.prototype); + /** * Fired when an item has loaded * @event onProgress diff --git a/src/pixi/loaders/AtlasLoader.js b/src/pixi/loaders/AtlasLoader.js index 5476da1..aa6c381 100644 --- a/src/pixi/loaders/AtlasLoader.js +++ b/src/pixi/loaders/AtlasLoader.js @@ -7,14 +7,13 @@ * When loaded this class will dispatch a 'loaded' event * If loading fails this class will dispatch an 'error' event * @class AtlasLoader - * @extends EventTarget + * @uses EventTarget * @constructor * @param {String} url the url of the JSON file * @param {Boolean} crossorigin */ PIXI.AtlasLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); this.url = url; this.baseUrl = url.replace(/[^\/]*$/, ''); this.crossorigin = crossorigin; @@ -25,6 +24,7 @@ // constructor PIXI.AtlasLoader.constructor = PIXI.AtlasLoader; +PIXI.EventTarget.mixin(PIXI.AtlasLoader.prototype); /** * Starts loading the JSON file diff --git a/src/pixi/loaders/BitmapFontLoader.js b/src/pixi/loaders/BitmapFontLoader.js index 9082b33..cd67a37 100644 --- a/src/pixi/loaders/BitmapFontLoader.js +++ b/src/pixi/loaders/BitmapFontLoader.js @@ -21,7 +21,6 @@ * http://www.codeandweb.com/texturepacker * make sure to set the format as 'JSON' */ - PIXI.EventTarget.call(this); /** * The url of the bitmap font data @@ -60,6 +59,8 @@ // constructor PIXI.BitmapFontLoader.prototype.constructor = PIXI.BitmapFontLoader; +PIXI.EventTarget.mixin(PIXI.BitmapFontLoader.prototype); + /** * Loads the XML font data * diff --git a/src/pixi/loaders/ImageLoader.js b/src/pixi/loaders/ImageLoader.js index 568e76b..79d6765 100644 --- a/src/pixi/loaders/ImageLoader.js +++ b/src/pixi/loaders/ImageLoader.js @@ -15,8 +15,6 @@ */ PIXI.ImageLoader = function(url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The texture being loaded * @@ -36,6 +34,8 @@ // constructor PIXI.ImageLoader.prototype.constructor = PIXI.ImageLoader; +PIXI.EventTarget.mixin(PIXI.ImageLoader.prototype); + /** * Loads image or takes it from cache * diff --git a/src/pixi/loaders/JsonLoader.js b/src/pixi/loaders/JsonLoader.js index 5dc21ec..fea109f 100644 --- a/src/pixi/loaders/JsonLoader.js +++ b/src/pixi/loaders/JsonLoader.js @@ -14,8 +14,6 @@ * @param crossorigin {Boolean} Whether requests should be treated as crossorigin */ PIXI.JsonLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The url of the bitmap font data * @@ -55,6 +53,8 @@ // constructor PIXI.JsonLoader.prototype.constructor = PIXI.JsonLoader; +PIXI.EventTarget.mixin(PIXI.JsonLoader.prototype); + /** * Loads the JSON data * diff --git a/src/pixi/loaders/AssetLoader.js b/src/pixi/loaders/AssetLoader.js index 013eadb..7bcb8df 100644 --- a/src/pixi/loaders/AssetLoader.js +++ b/src/pixi/loaders/AssetLoader.js @@ -20,8 +20,6 @@ */ PIXI.AssetLoader = function(assetURLs, crossorigin) { - PIXI.EventTarget.call(this); - /** * The array of asset URLs that are going to be loaded * @@ -57,6 +55,8 @@ }; }; +PIXI.EventTarget.mixin(PIXI.AssetLoader.prototype); + /** * Fired when an item has loaded * @event onProgress diff --git a/src/pixi/loaders/AtlasLoader.js b/src/pixi/loaders/AtlasLoader.js index 5476da1..aa6c381 100644 --- a/src/pixi/loaders/AtlasLoader.js +++ b/src/pixi/loaders/AtlasLoader.js @@ -7,14 +7,13 @@ * When loaded this class will dispatch a 'loaded' event * If loading fails this class will dispatch an 'error' event * @class AtlasLoader - * @extends EventTarget + * @uses EventTarget * @constructor * @param {String} url the url of the JSON file * @param {Boolean} crossorigin */ PIXI.AtlasLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); this.url = url; this.baseUrl = url.replace(/[^\/]*$/, ''); this.crossorigin = crossorigin; @@ -25,6 +24,7 @@ // constructor PIXI.AtlasLoader.constructor = PIXI.AtlasLoader; +PIXI.EventTarget.mixin(PIXI.AtlasLoader.prototype); /** * Starts loading the JSON file diff --git a/src/pixi/loaders/BitmapFontLoader.js b/src/pixi/loaders/BitmapFontLoader.js index 9082b33..cd67a37 100644 --- a/src/pixi/loaders/BitmapFontLoader.js +++ b/src/pixi/loaders/BitmapFontLoader.js @@ -21,7 +21,6 @@ * http://www.codeandweb.com/texturepacker * make sure to set the format as 'JSON' */ - PIXI.EventTarget.call(this); /** * The url of the bitmap font data @@ -60,6 +59,8 @@ // constructor PIXI.BitmapFontLoader.prototype.constructor = PIXI.BitmapFontLoader; +PIXI.EventTarget.mixin(PIXI.BitmapFontLoader.prototype); + /** * Loads the XML font data * diff --git a/src/pixi/loaders/ImageLoader.js b/src/pixi/loaders/ImageLoader.js index 568e76b..79d6765 100644 --- a/src/pixi/loaders/ImageLoader.js +++ b/src/pixi/loaders/ImageLoader.js @@ -15,8 +15,6 @@ */ PIXI.ImageLoader = function(url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The texture being loaded * @@ -36,6 +34,8 @@ // constructor PIXI.ImageLoader.prototype.constructor = PIXI.ImageLoader; +PIXI.EventTarget.mixin(PIXI.ImageLoader.prototype); + /** * Loads image or takes it from cache * diff --git a/src/pixi/loaders/JsonLoader.js b/src/pixi/loaders/JsonLoader.js index 5dc21ec..fea109f 100644 --- a/src/pixi/loaders/JsonLoader.js +++ b/src/pixi/loaders/JsonLoader.js @@ -14,8 +14,6 @@ * @param crossorigin {Boolean} Whether requests should be treated as crossorigin */ PIXI.JsonLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The url of the bitmap font data * @@ -55,6 +53,8 @@ // constructor PIXI.JsonLoader.prototype.constructor = PIXI.JsonLoader; +PIXI.EventTarget.mixin(PIXI.JsonLoader.prototype); + /** * Loads the JSON data * diff --git a/src/pixi/loaders/SpineLoader.js b/src/pixi/loaders/SpineLoader.js index d4ade0e..027a980 100644 --- a/src/pixi/loaders/SpineLoader.js +++ b/src/pixi/loaders/SpineLoader.js @@ -23,8 +23,6 @@ */ PIXI.SpineLoader = function(url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The url of the bitmap font data * @@ -53,6 +51,8 @@ PIXI.SpineLoader.prototype.constructor = PIXI.SpineLoader; +PIXI.EventTarget.mixin(PIXI.SpineLoader.prototype); + /** * Loads the JSON data * diff --git a/src/pixi/loaders/AssetLoader.js b/src/pixi/loaders/AssetLoader.js index 013eadb..7bcb8df 100644 --- a/src/pixi/loaders/AssetLoader.js +++ b/src/pixi/loaders/AssetLoader.js @@ -20,8 +20,6 @@ */ PIXI.AssetLoader = function(assetURLs, crossorigin) { - PIXI.EventTarget.call(this); - /** * The array of asset URLs that are going to be loaded * @@ -57,6 +55,8 @@ }; }; +PIXI.EventTarget.mixin(PIXI.AssetLoader.prototype); + /** * Fired when an item has loaded * @event onProgress diff --git a/src/pixi/loaders/AtlasLoader.js b/src/pixi/loaders/AtlasLoader.js index 5476da1..aa6c381 100644 --- a/src/pixi/loaders/AtlasLoader.js +++ b/src/pixi/loaders/AtlasLoader.js @@ -7,14 +7,13 @@ * When loaded this class will dispatch a 'loaded' event * If loading fails this class will dispatch an 'error' event * @class AtlasLoader - * @extends EventTarget + * @uses EventTarget * @constructor * @param {String} url the url of the JSON file * @param {Boolean} crossorigin */ PIXI.AtlasLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); this.url = url; this.baseUrl = url.replace(/[^\/]*$/, ''); this.crossorigin = crossorigin; @@ -25,6 +24,7 @@ // constructor PIXI.AtlasLoader.constructor = PIXI.AtlasLoader; +PIXI.EventTarget.mixin(PIXI.AtlasLoader.prototype); /** * Starts loading the JSON file diff --git a/src/pixi/loaders/BitmapFontLoader.js b/src/pixi/loaders/BitmapFontLoader.js index 9082b33..cd67a37 100644 --- a/src/pixi/loaders/BitmapFontLoader.js +++ b/src/pixi/loaders/BitmapFontLoader.js @@ -21,7 +21,6 @@ * http://www.codeandweb.com/texturepacker * make sure to set the format as 'JSON' */ - PIXI.EventTarget.call(this); /** * The url of the bitmap font data @@ -60,6 +59,8 @@ // constructor PIXI.BitmapFontLoader.prototype.constructor = PIXI.BitmapFontLoader; +PIXI.EventTarget.mixin(PIXI.BitmapFontLoader.prototype); + /** * Loads the XML font data * diff --git a/src/pixi/loaders/ImageLoader.js b/src/pixi/loaders/ImageLoader.js index 568e76b..79d6765 100644 --- a/src/pixi/loaders/ImageLoader.js +++ b/src/pixi/loaders/ImageLoader.js @@ -15,8 +15,6 @@ */ PIXI.ImageLoader = function(url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The texture being loaded * @@ -36,6 +34,8 @@ // constructor PIXI.ImageLoader.prototype.constructor = PIXI.ImageLoader; +PIXI.EventTarget.mixin(PIXI.ImageLoader.prototype); + /** * Loads image or takes it from cache * diff --git a/src/pixi/loaders/JsonLoader.js b/src/pixi/loaders/JsonLoader.js index 5dc21ec..fea109f 100644 --- a/src/pixi/loaders/JsonLoader.js +++ b/src/pixi/loaders/JsonLoader.js @@ -14,8 +14,6 @@ * @param crossorigin {Boolean} Whether requests should be treated as crossorigin */ PIXI.JsonLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The url of the bitmap font data * @@ -55,6 +53,8 @@ // constructor PIXI.JsonLoader.prototype.constructor = PIXI.JsonLoader; +PIXI.EventTarget.mixin(PIXI.JsonLoader.prototype); + /** * Loads the JSON data * diff --git a/src/pixi/loaders/SpineLoader.js b/src/pixi/loaders/SpineLoader.js index d4ade0e..027a980 100644 --- a/src/pixi/loaders/SpineLoader.js +++ b/src/pixi/loaders/SpineLoader.js @@ -23,8 +23,6 @@ */ PIXI.SpineLoader = function(url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The url of the bitmap font data * @@ -53,6 +51,8 @@ PIXI.SpineLoader.prototype.constructor = PIXI.SpineLoader; +PIXI.EventTarget.mixin(PIXI.SpineLoader.prototype); + /** * Loads the JSON data * diff --git a/src/pixi/loaders/SpriteSheetLoader.js b/src/pixi/loaders/SpriteSheetLoader.js index 431c092..971724f 100644 --- a/src/pixi/loaders/SpriteSheetLoader.js +++ b/src/pixi/loaders/SpriteSheetLoader.js @@ -23,7 +23,6 @@ * http://www.codeandweb.com/texturepacker * make sure to set the format as 'JSON' */ - PIXI.EventTarget.call(this); /** * The url of the bitmap font data @@ -70,6 +69,8 @@ // constructor PIXI.SpriteSheetLoader.prototype.constructor = PIXI.SpriteSheetLoader; +PIXI.EventTarget.mixin(PIXI.SpriteSheetLoader.prototype); + /** * This will begin loading the JSON file * diff --git a/src/pixi/loaders/AssetLoader.js b/src/pixi/loaders/AssetLoader.js index 013eadb..7bcb8df 100644 --- a/src/pixi/loaders/AssetLoader.js +++ b/src/pixi/loaders/AssetLoader.js @@ -20,8 +20,6 @@ */ PIXI.AssetLoader = function(assetURLs, crossorigin) { - PIXI.EventTarget.call(this); - /** * The array of asset URLs that are going to be loaded * @@ -57,6 +55,8 @@ }; }; +PIXI.EventTarget.mixin(PIXI.AssetLoader.prototype); + /** * Fired when an item has loaded * @event onProgress diff --git a/src/pixi/loaders/AtlasLoader.js b/src/pixi/loaders/AtlasLoader.js index 5476da1..aa6c381 100644 --- a/src/pixi/loaders/AtlasLoader.js +++ b/src/pixi/loaders/AtlasLoader.js @@ -7,14 +7,13 @@ * When loaded this class will dispatch a 'loaded' event * If loading fails this class will dispatch an 'error' event * @class AtlasLoader - * @extends EventTarget + * @uses EventTarget * @constructor * @param {String} url the url of the JSON file * @param {Boolean} crossorigin */ PIXI.AtlasLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); this.url = url; this.baseUrl = url.replace(/[^\/]*$/, ''); this.crossorigin = crossorigin; @@ -25,6 +24,7 @@ // constructor PIXI.AtlasLoader.constructor = PIXI.AtlasLoader; +PIXI.EventTarget.mixin(PIXI.AtlasLoader.prototype); /** * Starts loading the JSON file diff --git a/src/pixi/loaders/BitmapFontLoader.js b/src/pixi/loaders/BitmapFontLoader.js index 9082b33..cd67a37 100644 --- a/src/pixi/loaders/BitmapFontLoader.js +++ b/src/pixi/loaders/BitmapFontLoader.js @@ -21,7 +21,6 @@ * http://www.codeandweb.com/texturepacker * make sure to set the format as 'JSON' */ - PIXI.EventTarget.call(this); /** * The url of the bitmap font data @@ -60,6 +59,8 @@ // constructor PIXI.BitmapFontLoader.prototype.constructor = PIXI.BitmapFontLoader; +PIXI.EventTarget.mixin(PIXI.BitmapFontLoader.prototype); + /** * Loads the XML font data * diff --git a/src/pixi/loaders/ImageLoader.js b/src/pixi/loaders/ImageLoader.js index 568e76b..79d6765 100644 --- a/src/pixi/loaders/ImageLoader.js +++ b/src/pixi/loaders/ImageLoader.js @@ -15,8 +15,6 @@ */ PIXI.ImageLoader = function(url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The texture being loaded * @@ -36,6 +34,8 @@ // constructor PIXI.ImageLoader.prototype.constructor = PIXI.ImageLoader; +PIXI.EventTarget.mixin(PIXI.ImageLoader.prototype); + /** * Loads image or takes it from cache * diff --git a/src/pixi/loaders/JsonLoader.js b/src/pixi/loaders/JsonLoader.js index 5dc21ec..fea109f 100644 --- a/src/pixi/loaders/JsonLoader.js +++ b/src/pixi/loaders/JsonLoader.js @@ -14,8 +14,6 @@ * @param crossorigin {Boolean} Whether requests should be treated as crossorigin */ PIXI.JsonLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The url of the bitmap font data * @@ -55,6 +53,8 @@ // constructor PIXI.JsonLoader.prototype.constructor = PIXI.JsonLoader; +PIXI.EventTarget.mixin(PIXI.JsonLoader.prototype); + /** * Loads the JSON data * diff --git a/src/pixi/loaders/SpineLoader.js b/src/pixi/loaders/SpineLoader.js index d4ade0e..027a980 100644 --- a/src/pixi/loaders/SpineLoader.js +++ b/src/pixi/loaders/SpineLoader.js @@ -23,8 +23,6 @@ */ PIXI.SpineLoader = function(url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The url of the bitmap font data * @@ -53,6 +51,8 @@ PIXI.SpineLoader.prototype.constructor = PIXI.SpineLoader; +PIXI.EventTarget.mixin(PIXI.SpineLoader.prototype); + /** * Loads the JSON data * diff --git a/src/pixi/loaders/SpriteSheetLoader.js b/src/pixi/loaders/SpriteSheetLoader.js index 431c092..971724f 100644 --- a/src/pixi/loaders/SpriteSheetLoader.js +++ b/src/pixi/loaders/SpriteSheetLoader.js @@ -23,7 +23,6 @@ * http://www.codeandweb.com/texturepacker * make sure to set the format as 'JSON' */ - PIXI.EventTarget.call(this); /** * The url of the bitmap font data @@ -70,6 +69,8 @@ // constructor PIXI.SpriteSheetLoader.prototype.constructor = PIXI.SpriteSheetLoader; +PIXI.EventTarget.mixin(PIXI.SpriteSheetLoader.prototype); + /** * This will begin loading the JSON file * diff --git a/src/pixi/textures/BaseTexture.js b/src/pixi/textures/BaseTexture.js index c13ed12..18fe8c2 100644 --- a/src/pixi/textures/BaseTexture.js +++ b/src/pixi/textures/BaseTexture.js @@ -19,8 +19,6 @@ */ PIXI.BaseTexture = function(source, scaleMode) { - PIXI.EventTarget.call( this ); - /** * [read-only] The width of the base texture set when the image has loaded * @@ -105,6 +103,8 @@ PIXI.BaseTexture.prototype.constructor = PIXI.BaseTexture; +PIXI.EventTarget.mixin(PIXI.BaseTexture.prototype); + /** * Destroys this base texture * diff --git a/src/pixi/loaders/AssetLoader.js b/src/pixi/loaders/AssetLoader.js index 013eadb..7bcb8df 100644 --- a/src/pixi/loaders/AssetLoader.js +++ b/src/pixi/loaders/AssetLoader.js @@ -20,8 +20,6 @@ */ PIXI.AssetLoader = function(assetURLs, crossorigin) { - PIXI.EventTarget.call(this); - /** * The array of asset URLs that are going to be loaded * @@ -57,6 +55,8 @@ }; }; +PIXI.EventTarget.mixin(PIXI.AssetLoader.prototype); + /** * Fired when an item has loaded * @event onProgress diff --git a/src/pixi/loaders/AtlasLoader.js b/src/pixi/loaders/AtlasLoader.js index 5476da1..aa6c381 100644 --- a/src/pixi/loaders/AtlasLoader.js +++ b/src/pixi/loaders/AtlasLoader.js @@ -7,14 +7,13 @@ * When loaded this class will dispatch a 'loaded' event * If loading fails this class will dispatch an 'error' event * @class AtlasLoader - * @extends EventTarget + * @uses EventTarget * @constructor * @param {String} url the url of the JSON file * @param {Boolean} crossorigin */ PIXI.AtlasLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); this.url = url; this.baseUrl = url.replace(/[^\/]*$/, ''); this.crossorigin = crossorigin; @@ -25,6 +24,7 @@ // constructor PIXI.AtlasLoader.constructor = PIXI.AtlasLoader; +PIXI.EventTarget.mixin(PIXI.AtlasLoader.prototype); /** * Starts loading the JSON file diff --git a/src/pixi/loaders/BitmapFontLoader.js b/src/pixi/loaders/BitmapFontLoader.js index 9082b33..cd67a37 100644 --- a/src/pixi/loaders/BitmapFontLoader.js +++ b/src/pixi/loaders/BitmapFontLoader.js @@ -21,7 +21,6 @@ * http://www.codeandweb.com/texturepacker * make sure to set the format as 'JSON' */ - PIXI.EventTarget.call(this); /** * The url of the bitmap font data @@ -60,6 +59,8 @@ // constructor PIXI.BitmapFontLoader.prototype.constructor = PIXI.BitmapFontLoader; +PIXI.EventTarget.mixin(PIXI.BitmapFontLoader.prototype); + /** * Loads the XML font data * diff --git a/src/pixi/loaders/ImageLoader.js b/src/pixi/loaders/ImageLoader.js index 568e76b..79d6765 100644 --- a/src/pixi/loaders/ImageLoader.js +++ b/src/pixi/loaders/ImageLoader.js @@ -15,8 +15,6 @@ */ PIXI.ImageLoader = function(url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The texture being loaded * @@ -36,6 +34,8 @@ // constructor PIXI.ImageLoader.prototype.constructor = PIXI.ImageLoader; +PIXI.EventTarget.mixin(PIXI.ImageLoader.prototype); + /** * Loads image or takes it from cache * diff --git a/src/pixi/loaders/JsonLoader.js b/src/pixi/loaders/JsonLoader.js index 5dc21ec..fea109f 100644 --- a/src/pixi/loaders/JsonLoader.js +++ b/src/pixi/loaders/JsonLoader.js @@ -14,8 +14,6 @@ * @param crossorigin {Boolean} Whether requests should be treated as crossorigin */ PIXI.JsonLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The url of the bitmap font data * @@ -55,6 +53,8 @@ // constructor PIXI.JsonLoader.prototype.constructor = PIXI.JsonLoader; +PIXI.EventTarget.mixin(PIXI.JsonLoader.prototype); + /** * Loads the JSON data * diff --git a/src/pixi/loaders/SpineLoader.js b/src/pixi/loaders/SpineLoader.js index d4ade0e..027a980 100644 --- a/src/pixi/loaders/SpineLoader.js +++ b/src/pixi/loaders/SpineLoader.js @@ -23,8 +23,6 @@ */ PIXI.SpineLoader = function(url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The url of the bitmap font data * @@ -53,6 +51,8 @@ PIXI.SpineLoader.prototype.constructor = PIXI.SpineLoader; +PIXI.EventTarget.mixin(PIXI.SpineLoader.prototype); + /** * Loads the JSON data * diff --git a/src/pixi/loaders/SpriteSheetLoader.js b/src/pixi/loaders/SpriteSheetLoader.js index 431c092..971724f 100644 --- a/src/pixi/loaders/SpriteSheetLoader.js +++ b/src/pixi/loaders/SpriteSheetLoader.js @@ -23,7 +23,6 @@ * http://www.codeandweb.com/texturepacker * make sure to set the format as 'JSON' */ - PIXI.EventTarget.call(this); /** * The url of the bitmap font data @@ -70,6 +69,8 @@ // constructor PIXI.SpriteSheetLoader.prototype.constructor = PIXI.SpriteSheetLoader; +PIXI.EventTarget.mixin(PIXI.SpriteSheetLoader.prototype); + /** * This will begin loading the JSON file * diff --git a/src/pixi/textures/BaseTexture.js b/src/pixi/textures/BaseTexture.js index c13ed12..18fe8c2 100644 --- a/src/pixi/textures/BaseTexture.js +++ b/src/pixi/textures/BaseTexture.js @@ -19,8 +19,6 @@ */ PIXI.BaseTexture = function(source, scaleMode) { - PIXI.EventTarget.call( this ); - /** * [read-only] The width of the base texture set when the image has loaded * @@ -105,6 +103,8 @@ PIXI.BaseTexture.prototype.constructor = PIXI.BaseTexture; +PIXI.EventTarget.mixin(PIXI.BaseTexture.prototype); + /** * Destroys this base texture * diff --git a/src/pixi/textures/RenderTexture.js b/src/pixi/textures/RenderTexture.js index cd73f65..db89052 100644 --- a/src/pixi/textures/RenderTexture.js +++ b/src/pixi/textures/RenderTexture.js @@ -26,14 +26,13 @@ * @class RenderTexture * @extends Texture + * @uses EventTarget * @constructor * @param width {Number} The width of the render texture * @param height {Number} The height of the render texture */ PIXI.RenderTexture = function(width, height, renderer) { - PIXI.EventTarget.call( this ); - /** * The with of the render texture * @@ -98,6 +97,8 @@ PIXI.RenderTexture.prototype = Object.create(PIXI.Texture.prototype); PIXI.RenderTexture.prototype.constructor = PIXI.RenderTexture; +PIXI.EventTarget.mixin(PIXI.RenderTexture.prototype); + PIXI.RenderTexture.prototype.resize = function(width, height) { this.width = width; diff --git a/src/pixi/loaders/AssetLoader.js b/src/pixi/loaders/AssetLoader.js index 013eadb..7bcb8df 100644 --- a/src/pixi/loaders/AssetLoader.js +++ b/src/pixi/loaders/AssetLoader.js @@ -20,8 +20,6 @@ */ PIXI.AssetLoader = function(assetURLs, crossorigin) { - PIXI.EventTarget.call(this); - /** * The array of asset URLs that are going to be loaded * @@ -57,6 +55,8 @@ }; }; +PIXI.EventTarget.mixin(PIXI.AssetLoader.prototype); + /** * Fired when an item has loaded * @event onProgress diff --git a/src/pixi/loaders/AtlasLoader.js b/src/pixi/loaders/AtlasLoader.js index 5476da1..aa6c381 100644 --- a/src/pixi/loaders/AtlasLoader.js +++ b/src/pixi/loaders/AtlasLoader.js @@ -7,14 +7,13 @@ * When loaded this class will dispatch a 'loaded' event * If loading fails this class will dispatch an 'error' event * @class AtlasLoader - * @extends EventTarget + * @uses EventTarget * @constructor * @param {String} url the url of the JSON file * @param {Boolean} crossorigin */ PIXI.AtlasLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); this.url = url; this.baseUrl = url.replace(/[^\/]*$/, ''); this.crossorigin = crossorigin; @@ -25,6 +24,7 @@ // constructor PIXI.AtlasLoader.constructor = PIXI.AtlasLoader; +PIXI.EventTarget.mixin(PIXI.AtlasLoader.prototype); /** * Starts loading the JSON file diff --git a/src/pixi/loaders/BitmapFontLoader.js b/src/pixi/loaders/BitmapFontLoader.js index 9082b33..cd67a37 100644 --- a/src/pixi/loaders/BitmapFontLoader.js +++ b/src/pixi/loaders/BitmapFontLoader.js @@ -21,7 +21,6 @@ * http://www.codeandweb.com/texturepacker * make sure to set the format as 'JSON' */ - PIXI.EventTarget.call(this); /** * The url of the bitmap font data @@ -60,6 +59,8 @@ // constructor PIXI.BitmapFontLoader.prototype.constructor = PIXI.BitmapFontLoader; +PIXI.EventTarget.mixin(PIXI.BitmapFontLoader.prototype); + /** * Loads the XML font data * diff --git a/src/pixi/loaders/ImageLoader.js b/src/pixi/loaders/ImageLoader.js index 568e76b..79d6765 100644 --- a/src/pixi/loaders/ImageLoader.js +++ b/src/pixi/loaders/ImageLoader.js @@ -15,8 +15,6 @@ */ PIXI.ImageLoader = function(url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The texture being loaded * @@ -36,6 +34,8 @@ // constructor PIXI.ImageLoader.prototype.constructor = PIXI.ImageLoader; +PIXI.EventTarget.mixin(PIXI.ImageLoader.prototype); + /** * Loads image or takes it from cache * diff --git a/src/pixi/loaders/JsonLoader.js b/src/pixi/loaders/JsonLoader.js index 5dc21ec..fea109f 100644 --- a/src/pixi/loaders/JsonLoader.js +++ b/src/pixi/loaders/JsonLoader.js @@ -14,8 +14,6 @@ * @param crossorigin {Boolean} Whether requests should be treated as crossorigin */ PIXI.JsonLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The url of the bitmap font data * @@ -55,6 +53,8 @@ // constructor PIXI.JsonLoader.prototype.constructor = PIXI.JsonLoader; +PIXI.EventTarget.mixin(PIXI.JsonLoader.prototype); + /** * Loads the JSON data * diff --git a/src/pixi/loaders/SpineLoader.js b/src/pixi/loaders/SpineLoader.js index d4ade0e..027a980 100644 --- a/src/pixi/loaders/SpineLoader.js +++ b/src/pixi/loaders/SpineLoader.js @@ -23,8 +23,6 @@ */ PIXI.SpineLoader = function(url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The url of the bitmap font data * @@ -53,6 +51,8 @@ PIXI.SpineLoader.prototype.constructor = PIXI.SpineLoader; +PIXI.EventTarget.mixin(PIXI.SpineLoader.prototype); + /** * Loads the JSON data * diff --git a/src/pixi/loaders/SpriteSheetLoader.js b/src/pixi/loaders/SpriteSheetLoader.js index 431c092..971724f 100644 --- a/src/pixi/loaders/SpriteSheetLoader.js +++ b/src/pixi/loaders/SpriteSheetLoader.js @@ -23,7 +23,6 @@ * http://www.codeandweb.com/texturepacker * make sure to set the format as 'JSON' */ - PIXI.EventTarget.call(this); /** * The url of the bitmap font data @@ -70,6 +69,8 @@ // constructor PIXI.SpriteSheetLoader.prototype.constructor = PIXI.SpriteSheetLoader; +PIXI.EventTarget.mixin(PIXI.SpriteSheetLoader.prototype); + /** * This will begin loading the JSON file * diff --git a/src/pixi/textures/BaseTexture.js b/src/pixi/textures/BaseTexture.js index c13ed12..18fe8c2 100644 --- a/src/pixi/textures/BaseTexture.js +++ b/src/pixi/textures/BaseTexture.js @@ -19,8 +19,6 @@ */ PIXI.BaseTexture = function(source, scaleMode) { - PIXI.EventTarget.call( this ); - /** * [read-only] The width of the base texture set when the image has loaded * @@ -105,6 +103,8 @@ PIXI.BaseTexture.prototype.constructor = PIXI.BaseTexture; +PIXI.EventTarget.mixin(PIXI.BaseTexture.prototype); + /** * Destroys this base texture * diff --git a/src/pixi/textures/RenderTexture.js b/src/pixi/textures/RenderTexture.js index cd73f65..db89052 100644 --- a/src/pixi/textures/RenderTexture.js +++ b/src/pixi/textures/RenderTexture.js @@ -26,14 +26,13 @@ * @class RenderTexture * @extends Texture + * @uses EventTarget * @constructor * @param width {Number} The width of the render texture * @param height {Number} The height of the render texture */ PIXI.RenderTexture = function(width, height, renderer) { - PIXI.EventTarget.call( this ); - /** * The with of the render texture * @@ -98,6 +97,8 @@ PIXI.RenderTexture.prototype = Object.create(PIXI.Texture.prototype); PIXI.RenderTexture.prototype.constructor = PIXI.RenderTexture; +PIXI.EventTarget.mixin(PIXI.RenderTexture.prototype); + PIXI.RenderTexture.prototype.resize = function(width, height) { this.width = width; diff --git a/src/pixi/textures/Texture.js b/src/pixi/textures/Texture.js index 9b04c11..de9aaa4 100644 --- a/src/pixi/textures/Texture.js +++ b/src/pixi/textures/Texture.js @@ -19,8 +19,6 @@ */ PIXI.Texture = function(baseTexture, frame) { - PIXI.EventTarget.call( this ); - if(!frame) { this.noFrame = true; @@ -73,6 +71,8 @@ PIXI.Texture.prototype.constructor = PIXI.Texture; +PIXI.EventTarget.mixin(PIXI.Texture.prototype); + /** * Called when the base texture is loaded * diff --git a/src/pixi/loaders/AssetLoader.js b/src/pixi/loaders/AssetLoader.js index 013eadb..7bcb8df 100644 --- a/src/pixi/loaders/AssetLoader.js +++ b/src/pixi/loaders/AssetLoader.js @@ -20,8 +20,6 @@ */ PIXI.AssetLoader = function(assetURLs, crossorigin) { - PIXI.EventTarget.call(this); - /** * The array of asset URLs that are going to be loaded * @@ -57,6 +55,8 @@ }; }; +PIXI.EventTarget.mixin(PIXI.AssetLoader.prototype); + /** * Fired when an item has loaded * @event onProgress diff --git a/src/pixi/loaders/AtlasLoader.js b/src/pixi/loaders/AtlasLoader.js index 5476da1..aa6c381 100644 --- a/src/pixi/loaders/AtlasLoader.js +++ b/src/pixi/loaders/AtlasLoader.js @@ -7,14 +7,13 @@ * When loaded this class will dispatch a 'loaded' event * If loading fails this class will dispatch an 'error' event * @class AtlasLoader - * @extends EventTarget + * @uses EventTarget * @constructor * @param {String} url the url of the JSON file * @param {Boolean} crossorigin */ PIXI.AtlasLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); this.url = url; this.baseUrl = url.replace(/[^\/]*$/, ''); this.crossorigin = crossorigin; @@ -25,6 +24,7 @@ // constructor PIXI.AtlasLoader.constructor = PIXI.AtlasLoader; +PIXI.EventTarget.mixin(PIXI.AtlasLoader.prototype); /** * Starts loading the JSON file diff --git a/src/pixi/loaders/BitmapFontLoader.js b/src/pixi/loaders/BitmapFontLoader.js index 9082b33..cd67a37 100644 --- a/src/pixi/loaders/BitmapFontLoader.js +++ b/src/pixi/loaders/BitmapFontLoader.js @@ -21,7 +21,6 @@ * http://www.codeandweb.com/texturepacker * make sure to set the format as 'JSON' */ - PIXI.EventTarget.call(this); /** * The url of the bitmap font data @@ -60,6 +59,8 @@ // constructor PIXI.BitmapFontLoader.prototype.constructor = PIXI.BitmapFontLoader; +PIXI.EventTarget.mixin(PIXI.BitmapFontLoader.prototype); + /** * Loads the XML font data * diff --git a/src/pixi/loaders/ImageLoader.js b/src/pixi/loaders/ImageLoader.js index 568e76b..79d6765 100644 --- a/src/pixi/loaders/ImageLoader.js +++ b/src/pixi/loaders/ImageLoader.js @@ -15,8 +15,6 @@ */ PIXI.ImageLoader = function(url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The texture being loaded * @@ -36,6 +34,8 @@ // constructor PIXI.ImageLoader.prototype.constructor = PIXI.ImageLoader; +PIXI.EventTarget.mixin(PIXI.ImageLoader.prototype); + /** * Loads image or takes it from cache * diff --git a/src/pixi/loaders/JsonLoader.js b/src/pixi/loaders/JsonLoader.js index 5dc21ec..fea109f 100644 --- a/src/pixi/loaders/JsonLoader.js +++ b/src/pixi/loaders/JsonLoader.js @@ -14,8 +14,6 @@ * @param crossorigin {Boolean} Whether requests should be treated as crossorigin */ PIXI.JsonLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The url of the bitmap font data * @@ -55,6 +53,8 @@ // constructor PIXI.JsonLoader.prototype.constructor = PIXI.JsonLoader; +PIXI.EventTarget.mixin(PIXI.JsonLoader.prototype); + /** * Loads the JSON data * diff --git a/src/pixi/loaders/SpineLoader.js b/src/pixi/loaders/SpineLoader.js index d4ade0e..027a980 100644 --- a/src/pixi/loaders/SpineLoader.js +++ b/src/pixi/loaders/SpineLoader.js @@ -23,8 +23,6 @@ */ PIXI.SpineLoader = function(url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The url of the bitmap font data * @@ -53,6 +51,8 @@ PIXI.SpineLoader.prototype.constructor = PIXI.SpineLoader; +PIXI.EventTarget.mixin(PIXI.SpineLoader.prototype); + /** * Loads the JSON data * diff --git a/src/pixi/loaders/SpriteSheetLoader.js b/src/pixi/loaders/SpriteSheetLoader.js index 431c092..971724f 100644 --- a/src/pixi/loaders/SpriteSheetLoader.js +++ b/src/pixi/loaders/SpriteSheetLoader.js @@ -23,7 +23,6 @@ * http://www.codeandweb.com/texturepacker * make sure to set the format as 'JSON' */ - PIXI.EventTarget.call(this); /** * The url of the bitmap font data @@ -70,6 +69,8 @@ // constructor PIXI.SpriteSheetLoader.prototype.constructor = PIXI.SpriteSheetLoader; +PIXI.EventTarget.mixin(PIXI.SpriteSheetLoader.prototype); + /** * This will begin loading the JSON file * diff --git a/src/pixi/textures/BaseTexture.js b/src/pixi/textures/BaseTexture.js index c13ed12..18fe8c2 100644 --- a/src/pixi/textures/BaseTexture.js +++ b/src/pixi/textures/BaseTexture.js @@ -19,8 +19,6 @@ */ PIXI.BaseTexture = function(source, scaleMode) { - PIXI.EventTarget.call( this ); - /** * [read-only] The width of the base texture set when the image has loaded * @@ -105,6 +103,8 @@ PIXI.BaseTexture.prototype.constructor = PIXI.BaseTexture; +PIXI.EventTarget.mixin(PIXI.BaseTexture.prototype); + /** * Destroys this base texture * diff --git a/src/pixi/textures/RenderTexture.js b/src/pixi/textures/RenderTexture.js index cd73f65..db89052 100644 --- a/src/pixi/textures/RenderTexture.js +++ b/src/pixi/textures/RenderTexture.js @@ -26,14 +26,13 @@ * @class RenderTexture * @extends Texture + * @uses EventTarget * @constructor * @param width {Number} The width of the render texture * @param height {Number} The height of the render texture */ PIXI.RenderTexture = function(width, height, renderer) { - PIXI.EventTarget.call( this ); - /** * The with of the render texture * @@ -98,6 +97,8 @@ PIXI.RenderTexture.prototype = Object.create(PIXI.Texture.prototype); PIXI.RenderTexture.prototype.constructor = PIXI.RenderTexture; +PIXI.EventTarget.mixin(PIXI.RenderTexture.prototype); + PIXI.RenderTexture.prototype.resize = function(width, height) { this.width = width; diff --git a/src/pixi/textures/Texture.js b/src/pixi/textures/Texture.js index 9b04c11..de9aaa4 100644 --- a/src/pixi/textures/Texture.js +++ b/src/pixi/textures/Texture.js @@ -19,8 +19,6 @@ */ PIXI.Texture = function(baseTexture, frame) { - PIXI.EventTarget.call( this ); - if(!frame) { this.noFrame = true; @@ -73,6 +71,8 @@ PIXI.Texture.prototype.constructor = PIXI.Texture; +PIXI.EventTarget.mixin(PIXI.Texture.prototype); + /** * Called when the base texture is loaded * diff --git a/src/pixi/utils/EventTarget.js b/src/pixi/utils/EventTarget.js index 71f9243..f261fc5 100644 --- a/src/pixi/utils/EventTarget.js +++ b/src/pixi/utils/EventTarget.js @@ -13,141 +13,165 @@ * * @class EventTarget * @example - * function MyEmitter() { - * PIXI.EventTarget.call(this); //mixes in event target stuff - * } + * function MyEmitter() {} + * + * PIXI.EventTarget.mixin(MyEmitter.prototype); * * var em = new MyEmitter(); * em.emit('eventName', 'some data', 'some moar data', {}, null, ...); */ -PIXI.EventTarget = function() { - /** - * Return a list of assigned event listeners. - * - * @param eventName {String} The events that should be listed. - * @returns {Array} - * @api public - */ - this.listeners = function listeners(eventName) { - return Array.apply(this, this._listeners[eventName] || []); - }; +function EventTarget() {} - /** - * Emit an event to all registered event listeners. - * - * @param eventName {String} The name of the event. - * @returns {Boolean} Indication if we've emitted an event. - * @api public - */ - this.emit = function emit(eventName, data) { - if(!data || data.__isEventObject !== true) - data = new PIXI.Event(this, eventName, data); +/** + * Mixes in the properties of the EventTarget prototype onto another object + * + * @method mixin + * @param object {Object} The obj to mix into + */ +EventTarget.prototype.mixin = function mixin(obj) { + obj.listeners = this.listeners; + obj.emit = this.emit; + obj.on = this.on; + obj.off = this.off; + obj.once = this.once; + obj.removeAllListeners = this.removeAllListeners; - if(this._listeners && this._listeners[eventName]) { - var listeners = this._listeners[eventName], - length = listeners.length, - fn = listeners[0], - i; + obj.addEventListener = this.addEventListener; + obj.removeEventListener = this.removeEventListener; + obj.dispatchEvent = this.dispatchEvent; +}; - for(i = 0; i < length; fn = listeners[++i]) { - //call the event listener - fn.call(this, data); +/** + * Return a list of assigned event listeners. + * + * @method listeners + * @param eventName {String} The events that should be listed. + * @returns {Array} An array of listener functions + */ +EventTarget.prototype.listeners = function listeners(eventName) { + return Array.apply(this, this._listeners[eventName] || []); +}; - //remove the listener if this is a "once" event - if(fn.__isOnce) - this.off(eventName, fn); +/** + * Emit an event to all registered event listeners. + * + * @method emit + * @alias dispatchEvent + * @param eventName {String} The name of the event. + * @returns {Boolean} Indication if we've emitted an event. + */ +EventTarget.prototype.emit = function emit(eventName, data) { + if(!data || data.__isEventObject !== true) + data = new PIXI.Event(this, eventName, data); - //if "stopImmediatePropagation" is called, stop calling all events - if(data.stoppedImmediate) - return; - } + if(this._listeners && this._listeners[eventName]) { + var listeners = this._listeners[eventName], + length = listeners.length, + fn = listeners[0], + i; - //if "stopPropagation" is called then don't bubble the event - if(data.stopped) + for(i = 0; i < length; fn = listeners[++i]) { + //call the event listener + fn.call(this, data); + + //remove the listener if this is a "once" event + if(fn.__isOnce) + this.off(eventName, fn); + + //if "stopImmediatePropagation" is called, stop calling all events + if(data.stoppedImmediate) return; } - if(this.parent && this.parent.emit) { - this.parent.emit.call(this.parent, eventName, data); - } + //if "stopPropagation" is called then don't bubble the event + if(data.stopped) + return; + } - return true; - }; + if(this.parent && this.parent.emit) { + this.parent.emit.call(this.parent, eventName, data); + } - /** - * Register a new EventListener for the given event. - * - * @param eventName {String} Name of the event. - * @param callback {Functon} fn Callback function. - * @api public - */ - this.on = function on(eventName, fn) { - if(!this._listeners) - this._listeners = {}; - - if(!this._listeners[eventName]) - this._listeners[eventName] = []; - - this._listeners[eventName].push(fn); - - return this; - }; - - /** - * Add an EventListener that's only called once. - * - * @param eventName {String} Name of the event. - * @param callback {Function} Callback function. - * @api public - */ - this.once = function once(eventName, fn) { - fn.__isOnce = true; - return this.on(eventName, fn); - }; - - /** - * Remove event listeners. - * - * @param eventName {String} The event we want to remove. - * @param callback {Function} The listener that we need to find. - * @api public - */ - this.off = function off(eventName, fn) { - if(!this._listeners[eventName]) - return this; - - var index = this._listeners[eventName].indexOf(fn); - - if(index !== -1) { - this._listeners[eventName].splice(index, 1); - } - - return this; - }; - - /** - * Remove all listeners or only the listeners for the specified event. - * - * @param eventName {String} The event want to remove all listeners for. - * @api public - */ - this.removeAllListeners = function removeAllListeners(eventName) { - if(!this._listeners[eventName]) - return this; - - this._listeners[eventName].length = 0; - - return this; - }; - - /** - * Alias methods names because people roll like that. - */ - this.removeEventListener = this.off; - this.addEventListener = this.on; - this.dispatchEvent = this.emit; + return true; }; +/** + * Register a new EventListener for the given event. + * + * @method on + * @alias addEventListener + * @param eventName {String} Name of the event. + * @param callback {Functon} fn Callback function. + */ +EventTarget.prototype.on = function on(eventName, fn) { + if(!this._listeners) + this._listeners = {}; + + if(!this._listeners[eventName]) + this._listeners[eventName] = []; + + this._listeners[eventName].push(fn); + + return this; +}; + +/** + * Add an EventListener that's only called once. + * + * @method once + * @param eventName {String} Name of the event. + * @param callback {Function} Callback function. + */ +EventTarget.prototype.once = function once(eventName, fn) { + fn.__isOnce = true; + return this.on(eventName, fn); +}; + +/** + * Remove event listeners. + * + * @method off + * @alias removeEventListener + * @param eventName {String} The event we want to remove. + * @param callback {Function} The listener that we need to find. + */ +EventTarget.prototype.off = function off(eventName, fn) { + if(!this._listeners[eventName]) + return this; + + var index = this._listeners[eventName].indexOf(fn); + + if(index !== -1) { + this._listeners[eventName].splice(index, 1); + } + + return this; +}; + +/** + * Remove all listeners or only the listeners for the specified event. + * + * @method removeAllListeners + * @param eventName {String} The event you want to remove all listeners for. + */ +EventTarget.prototype.removeAllListeners = function removeAllListeners(eventName) { + if(!this._listeners[eventName]) + return this; + + this._listeners[eventName].length = 0; + + return this; +}; + +/** + * Alias methods names because people roll like that. + */ +EventTarget.prototype.removeEventListener = EventTarget.prototype.off; +EventTarget.prototype.addEventListener = EventTarget.prototype.on; +EventTarget.prototype.dispatchEvent = EventTarget.prototype.emit; + +PIXI.EventTarget = new EventTarget(); + PIXI.Event = function(target, name, data) { this.__isEventObject = true; @@ -161,10 +185,10 @@ this.timeStamp = Date.now(); }; -PIXI.Event.prototype.stopPropagation = function() { +PIXI.Event.prototype.stopPropagation = function stopPropagation() { this.stopped = true; }; -PIXI.Event.prototype.stopImmediatePropagation = function() { +PIXI.Event.prototype.stopImmediatePropagation = function stopImmediatePropagation() { this.stoppedImmediate = true; }; diff --git a/src/pixi/loaders/AssetLoader.js b/src/pixi/loaders/AssetLoader.js index 013eadb..7bcb8df 100644 --- a/src/pixi/loaders/AssetLoader.js +++ b/src/pixi/loaders/AssetLoader.js @@ -20,8 +20,6 @@ */ PIXI.AssetLoader = function(assetURLs, crossorigin) { - PIXI.EventTarget.call(this); - /** * The array of asset URLs that are going to be loaded * @@ -57,6 +55,8 @@ }; }; +PIXI.EventTarget.mixin(PIXI.AssetLoader.prototype); + /** * Fired when an item has loaded * @event onProgress diff --git a/src/pixi/loaders/AtlasLoader.js b/src/pixi/loaders/AtlasLoader.js index 5476da1..aa6c381 100644 --- a/src/pixi/loaders/AtlasLoader.js +++ b/src/pixi/loaders/AtlasLoader.js @@ -7,14 +7,13 @@ * When loaded this class will dispatch a 'loaded' event * If loading fails this class will dispatch an 'error' event * @class AtlasLoader - * @extends EventTarget + * @uses EventTarget * @constructor * @param {String} url the url of the JSON file * @param {Boolean} crossorigin */ PIXI.AtlasLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); this.url = url; this.baseUrl = url.replace(/[^\/]*$/, ''); this.crossorigin = crossorigin; @@ -25,6 +24,7 @@ // constructor PIXI.AtlasLoader.constructor = PIXI.AtlasLoader; +PIXI.EventTarget.mixin(PIXI.AtlasLoader.prototype); /** * Starts loading the JSON file diff --git a/src/pixi/loaders/BitmapFontLoader.js b/src/pixi/loaders/BitmapFontLoader.js index 9082b33..cd67a37 100644 --- a/src/pixi/loaders/BitmapFontLoader.js +++ b/src/pixi/loaders/BitmapFontLoader.js @@ -21,7 +21,6 @@ * http://www.codeandweb.com/texturepacker * make sure to set the format as 'JSON' */ - PIXI.EventTarget.call(this); /** * The url of the bitmap font data @@ -60,6 +59,8 @@ // constructor PIXI.BitmapFontLoader.prototype.constructor = PIXI.BitmapFontLoader; +PIXI.EventTarget.mixin(PIXI.BitmapFontLoader.prototype); + /** * Loads the XML font data * diff --git a/src/pixi/loaders/ImageLoader.js b/src/pixi/loaders/ImageLoader.js index 568e76b..79d6765 100644 --- a/src/pixi/loaders/ImageLoader.js +++ b/src/pixi/loaders/ImageLoader.js @@ -15,8 +15,6 @@ */ PIXI.ImageLoader = function(url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The texture being loaded * @@ -36,6 +34,8 @@ // constructor PIXI.ImageLoader.prototype.constructor = PIXI.ImageLoader; +PIXI.EventTarget.mixin(PIXI.ImageLoader.prototype); + /** * Loads image or takes it from cache * diff --git a/src/pixi/loaders/JsonLoader.js b/src/pixi/loaders/JsonLoader.js index 5dc21ec..fea109f 100644 --- a/src/pixi/loaders/JsonLoader.js +++ b/src/pixi/loaders/JsonLoader.js @@ -14,8 +14,6 @@ * @param crossorigin {Boolean} Whether requests should be treated as crossorigin */ PIXI.JsonLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The url of the bitmap font data * @@ -55,6 +53,8 @@ // constructor PIXI.JsonLoader.prototype.constructor = PIXI.JsonLoader; +PIXI.EventTarget.mixin(PIXI.JsonLoader.prototype); + /** * Loads the JSON data * diff --git a/src/pixi/loaders/SpineLoader.js b/src/pixi/loaders/SpineLoader.js index d4ade0e..027a980 100644 --- a/src/pixi/loaders/SpineLoader.js +++ b/src/pixi/loaders/SpineLoader.js @@ -23,8 +23,6 @@ */ PIXI.SpineLoader = function(url, crossorigin) { - PIXI.EventTarget.call(this); - /** * The url of the bitmap font data * @@ -53,6 +51,8 @@ PIXI.SpineLoader.prototype.constructor = PIXI.SpineLoader; +PIXI.EventTarget.mixin(PIXI.SpineLoader.prototype); + /** * Loads the JSON data * diff --git a/src/pixi/loaders/SpriteSheetLoader.js b/src/pixi/loaders/SpriteSheetLoader.js index 431c092..971724f 100644 --- a/src/pixi/loaders/SpriteSheetLoader.js +++ b/src/pixi/loaders/SpriteSheetLoader.js @@ -23,7 +23,6 @@ * http://www.codeandweb.com/texturepacker * make sure to set the format as 'JSON' */ - PIXI.EventTarget.call(this); /** * The url of the bitmap font data @@ -70,6 +69,8 @@ // constructor PIXI.SpriteSheetLoader.prototype.constructor = PIXI.SpriteSheetLoader; +PIXI.EventTarget.mixin(PIXI.SpriteSheetLoader.prototype); + /** * This will begin loading the JSON file * diff --git a/src/pixi/textures/BaseTexture.js b/src/pixi/textures/BaseTexture.js index c13ed12..18fe8c2 100644 --- a/src/pixi/textures/BaseTexture.js +++ b/src/pixi/textures/BaseTexture.js @@ -19,8 +19,6 @@ */ PIXI.BaseTexture = function(source, scaleMode) { - PIXI.EventTarget.call( this ); - /** * [read-only] The width of the base texture set when the image has loaded * @@ -105,6 +103,8 @@ PIXI.BaseTexture.prototype.constructor = PIXI.BaseTexture; +PIXI.EventTarget.mixin(PIXI.BaseTexture.prototype); + /** * Destroys this base texture * diff --git a/src/pixi/textures/RenderTexture.js b/src/pixi/textures/RenderTexture.js index cd73f65..db89052 100644 --- a/src/pixi/textures/RenderTexture.js +++ b/src/pixi/textures/RenderTexture.js @@ -26,14 +26,13 @@ * @class RenderTexture * @extends Texture + * @uses EventTarget * @constructor * @param width {Number} The width of the render texture * @param height {Number} The height of the render texture */ PIXI.RenderTexture = function(width, height, renderer) { - PIXI.EventTarget.call( this ); - /** * The with of the render texture * @@ -98,6 +97,8 @@ PIXI.RenderTexture.prototype = Object.create(PIXI.Texture.prototype); PIXI.RenderTexture.prototype.constructor = PIXI.RenderTexture; +PIXI.EventTarget.mixin(PIXI.RenderTexture.prototype); + PIXI.RenderTexture.prototype.resize = function(width, height) { this.width = width; diff --git a/src/pixi/textures/Texture.js b/src/pixi/textures/Texture.js index 9b04c11..de9aaa4 100644 --- a/src/pixi/textures/Texture.js +++ b/src/pixi/textures/Texture.js @@ -19,8 +19,6 @@ */ PIXI.Texture = function(baseTexture, frame) { - PIXI.EventTarget.call( this ); - if(!frame) { this.noFrame = true; @@ -73,6 +71,8 @@ PIXI.Texture.prototype.constructor = PIXI.Texture; +PIXI.EventTarget.mixin(PIXI.Texture.prototype); + /** * Called when the base texture is loaded * diff --git a/src/pixi/utils/EventTarget.js b/src/pixi/utils/EventTarget.js index 71f9243..f261fc5 100644 --- a/src/pixi/utils/EventTarget.js +++ b/src/pixi/utils/EventTarget.js @@ -13,141 +13,165 @@ * * @class EventTarget * @example - * function MyEmitter() { - * PIXI.EventTarget.call(this); //mixes in event target stuff - * } + * function MyEmitter() {} + * + * PIXI.EventTarget.mixin(MyEmitter.prototype); * * var em = new MyEmitter(); * em.emit('eventName', 'some data', 'some moar data', {}, null, ...); */ -PIXI.EventTarget = function() { - /** - * Return a list of assigned event listeners. - * - * @param eventName {String} The events that should be listed. - * @returns {Array} - * @api public - */ - this.listeners = function listeners(eventName) { - return Array.apply(this, this._listeners[eventName] || []); - }; +function EventTarget() {} - /** - * Emit an event to all registered event listeners. - * - * @param eventName {String} The name of the event. - * @returns {Boolean} Indication if we've emitted an event. - * @api public - */ - this.emit = function emit(eventName, data) { - if(!data || data.__isEventObject !== true) - data = new PIXI.Event(this, eventName, data); +/** + * Mixes in the properties of the EventTarget prototype onto another object + * + * @method mixin + * @param object {Object} The obj to mix into + */ +EventTarget.prototype.mixin = function mixin(obj) { + obj.listeners = this.listeners; + obj.emit = this.emit; + obj.on = this.on; + obj.off = this.off; + obj.once = this.once; + obj.removeAllListeners = this.removeAllListeners; - if(this._listeners && this._listeners[eventName]) { - var listeners = this._listeners[eventName], - length = listeners.length, - fn = listeners[0], - i; + obj.addEventListener = this.addEventListener; + obj.removeEventListener = this.removeEventListener; + obj.dispatchEvent = this.dispatchEvent; +}; - for(i = 0; i < length; fn = listeners[++i]) { - //call the event listener - fn.call(this, data); +/** + * Return a list of assigned event listeners. + * + * @method listeners + * @param eventName {String} The events that should be listed. + * @returns {Array} An array of listener functions + */ +EventTarget.prototype.listeners = function listeners(eventName) { + return Array.apply(this, this._listeners[eventName] || []); +}; - //remove the listener if this is a "once" event - if(fn.__isOnce) - this.off(eventName, fn); +/** + * Emit an event to all registered event listeners. + * + * @method emit + * @alias dispatchEvent + * @param eventName {String} The name of the event. + * @returns {Boolean} Indication if we've emitted an event. + */ +EventTarget.prototype.emit = function emit(eventName, data) { + if(!data || data.__isEventObject !== true) + data = new PIXI.Event(this, eventName, data); - //if "stopImmediatePropagation" is called, stop calling all events - if(data.stoppedImmediate) - return; - } + if(this._listeners && this._listeners[eventName]) { + var listeners = this._listeners[eventName], + length = listeners.length, + fn = listeners[0], + i; - //if "stopPropagation" is called then don't bubble the event - if(data.stopped) + for(i = 0; i < length; fn = listeners[++i]) { + //call the event listener + fn.call(this, data); + + //remove the listener if this is a "once" event + if(fn.__isOnce) + this.off(eventName, fn); + + //if "stopImmediatePropagation" is called, stop calling all events + if(data.stoppedImmediate) return; } - if(this.parent && this.parent.emit) { - this.parent.emit.call(this.parent, eventName, data); - } + //if "stopPropagation" is called then don't bubble the event + if(data.stopped) + return; + } - return true; - }; + if(this.parent && this.parent.emit) { + this.parent.emit.call(this.parent, eventName, data); + } - /** - * Register a new EventListener for the given event. - * - * @param eventName {String} Name of the event. - * @param callback {Functon} fn Callback function. - * @api public - */ - this.on = function on(eventName, fn) { - if(!this._listeners) - this._listeners = {}; - - if(!this._listeners[eventName]) - this._listeners[eventName] = []; - - this._listeners[eventName].push(fn); - - return this; - }; - - /** - * Add an EventListener that's only called once. - * - * @param eventName {String} Name of the event. - * @param callback {Function} Callback function. - * @api public - */ - this.once = function once(eventName, fn) { - fn.__isOnce = true; - return this.on(eventName, fn); - }; - - /** - * Remove event listeners. - * - * @param eventName {String} The event we want to remove. - * @param callback {Function} The listener that we need to find. - * @api public - */ - this.off = function off(eventName, fn) { - if(!this._listeners[eventName]) - return this; - - var index = this._listeners[eventName].indexOf(fn); - - if(index !== -1) { - this._listeners[eventName].splice(index, 1); - } - - return this; - }; - - /** - * Remove all listeners or only the listeners for the specified event. - * - * @param eventName {String} The event want to remove all listeners for. - * @api public - */ - this.removeAllListeners = function removeAllListeners(eventName) { - if(!this._listeners[eventName]) - return this; - - this._listeners[eventName].length = 0; - - return this; - }; - - /** - * Alias methods names because people roll like that. - */ - this.removeEventListener = this.off; - this.addEventListener = this.on; - this.dispatchEvent = this.emit; + return true; }; +/** + * Register a new EventListener for the given event. + * + * @method on + * @alias addEventListener + * @param eventName {String} Name of the event. + * @param callback {Functon} fn Callback function. + */ +EventTarget.prototype.on = function on(eventName, fn) { + if(!this._listeners) + this._listeners = {}; + + if(!this._listeners[eventName]) + this._listeners[eventName] = []; + + this._listeners[eventName].push(fn); + + return this; +}; + +/** + * Add an EventListener that's only called once. + * + * @method once + * @param eventName {String} Name of the event. + * @param callback {Function} Callback function. + */ +EventTarget.prototype.once = function once(eventName, fn) { + fn.__isOnce = true; + return this.on(eventName, fn); +}; + +/** + * Remove event listeners. + * + * @method off + * @alias removeEventListener + * @param eventName {String} The event we want to remove. + * @param callback {Function} The listener that we need to find. + */ +EventTarget.prototype.off = function off(eventName, fn) { + if(!this._listeners[eventName]) + return this; + + var index = this._listeners[eventName].indexOf(fn); + + if(index !== -1) { + this._listeners[eventName].splice(index, 1); + } + + return this; +}; + +/** + * Remove all listeners or only the listeners for the specified event. + * + * @method removeAllListeners + * @param eventName {String} The event you want to remove all listeners for. + */ +EventTarget.prototype.removeAllListeners = function removeAllListeners(eventName) { + if(!this._listeners[eventName]) + return this; + + this._listeners[eventName].length = 0; + + return this; +}; + +/** + * Alias methods names because people roll like that. + */ +EventTarget.prototype.removeEventListener = EventTarget.prototype.off; +EventTarget.prototype.addEventListener = EventTarget.prototype.on; +EventTarget.prototype.dispatchEvent = EventTarget.prototype.emit; + +PIXI.EventTarget = new EventTarget(); + PIXI.Event = function(target, name, data) { this.__isEventObject = true; @@ -161,10 +185,10 @@ this.timeStamp = Date.now(); }; -PIXI.Event.prototype.stopPropagation = function() { +PIXI.Event.prototype.stopPropagation = function stopPropagation() { this.stopped = true; }; -PIXI.Event.prototype.stopImmediatePropagation = function() { +PIXI.Event.prototype.stopImmediatePropagation = function stopImmediatePropagation() { this.stoppedImmediate = true; }; diff --git a/test/unit/pixi/utils/EventTarget.js b/test/unit/pixi/utils/EventTarget.js index c958e19..feabba3 100644 --- a/test/unit/pixi/utils/EventTarget.js +++ b/test/unit/pixi/utils/EventTarget.js @@ -5,13 +5,13 @@ var EventTarget = PIXI.EventTarget; it('Module exists', function () { - expect(EventTarget).to.be.a('function'); + expect(EventTarget).to.be.an('object'); }); it('Confirm new instance', function () { var obj = {}; - EventTarget.call(obj); + EventTarget.mixin(obj); pixi_utils_EventTarget_like(obj); }); @@ -19,7 +19,7 @@ var myData = {}, obj = {}; - EventTarget.call(obj); + EventTarget.mixin(obj); obj.on('myevent', function (event) { expect(event).to.be.an.instanceOf(PIXI.Event); @@ -44,7 +44,7 @@ var called = 0, obj = {}; - EventTarget.call(obj); + EventTarget.mixin(obj); obj.once('myevent', function() { called++; }); @@ -60,7 +60,7 @@ it('simple off case works', function (done) { var obj = {}; - EventTarget.call(obj); + EventTarget.mixin(obj); function onMyEvent() { done(new Error('Event listener should not have been called')); @@ -78,8 +78,8 @@ pobj = {}, obj = { parent: pobj }; - EventTarget.call(pobj); - EventTarget.call(obj); + EventTarget.mixin(pobj); + EventTarget.mixin(obj); pobj.on('myevent', function () { done(); @@ -93,8 +93,8 @@ pobj = {}, obj = { parent: pobj }; - EventTarget.call(pobj); - EventTarget.call(obj); + EventTarget.mixin(pobj); + EventTarget.mixin(obj); pobj.on('myevent', function () { done(new Error('Event listener should not have been called on the parent element')); @@ -114,8 +114,8 @@ pobj = {}, obj = { parent: pobj }; - EventTarget.call(pobj); - EventTarget.call(obj); + EventTarget.mixin(pobj); + EventTarget.mixin(obj); pobj.on('myevent', function () { done(new Error('Event listener should not have been called on the parent')); @@ -138,7 +138,7 @@ var called = 0, obj = {}; - EventTarget.call(obj); + EventTarget.mixin(obj); function onMyEvent() { called++; @@ -156,7 +156,7 @@ var called = 0, obj = {}; - EventTarget.call(obj); + EventTarget.mixin(obj); function onMyEvent() { called++; @@ -175,7 +175,7 @@ var called = 0, obj = {}; - EventTarget.call(obj); + EventTarget.mixin(obj); function onMyEvent() { called++;