diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 69c0c8d..81cf8b3 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -606,18 +606,16 @@ /** * Destroys the container - * @param [options] {object} Options parameter + * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value * @param [options.children=false] {boolean} if set to true, all the children will have their destroy * method called as well. 'options' will be passed on to those calls. - * */ Container.prototype.destroy = function (options) { - options = options || {}; - DisplayObject.prototype.destroy.call(this); - if (options.children) + var destroyChildren = typeof options === 'boolean' ? options : options && options.children; + if (destroyChildren) { for (var i = 0, j = this.children.length; i < j; ++i) { diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 69c0c8d..81cf8b3 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -606,18 +606,16 @@ /** * Destroys the container - * @param [options] {object} Options parameter + * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value * @param [options.children=false] {boolean} if set to true, all the children will have their destroy * method called as well. 'options' will be passed on to those calls. - * */ Container.prototype.destroy = function (options) { - options = options || {}; - DisplayObject.prototype.destroy.call(this); - if (options.children) + var destroyChildren = typeof options === 'boolean' ? options : options && options.children; + if (destroyChildren) { for (var i = 0, j = this.children.length; i < j; ++i) { diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 5a04062..62296d9 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -409,7 +409,7 @@ /** * Destroys this sprite and optionally its texture and children * - * @param [options] {object} Options parameter + * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value * @param [options.children=false] {boolean} if set to true, all the children will have their destroy * method called as well. 'options' will be passed on to those calls. * @param [options.texture=false] {boolean} Should it destroy the current texture of the sprite as well @@ -417,15 +417,15 @@ */ Sprite.prototype.destroy = function (options) { - options = options || {}; - Container.prototype.destroy.call(this, options); this.anchor = null; - if (options.texture) + var destroyTexture = typeof options === 'boolean' ? options : options && options.texture; + if (destroyTexture) { - this._texture.destroy(!!options.baseTexture); + var destroyBaseTexture = typeof options === 'boolean' ? options : options && options.baseTexture; + this._texture.destroy(!!destroyBaseTexture); } this._texture = null; diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 69c0c8d..81cf8b3 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -606,18 +606,16 @@ /** * Destroys the container - * @param [options] {object} Options parameter + * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value * @param [options.children=false] {boolean} if set to true, all the children will have their destroy * method called as well. 'options' will be passed on to those calls. - * */ Container.prototype.destroy = function (options) { - options = options || {}; - DisplayObject.prototype.destroy.call(this); - if (options.children) + var destroyChildren = typeof options === 'boolean' ? options : options && options.children; + if (destroyChildren) { for (var i = 0, j = this.children.length; i < j; ++i) { diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 5a04062..62296d9 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -409,7 +409,7 @@ /** * Destroys this sprite and optionally its texture and children * - * @param [options] {object} Options parameter + * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value * @param [options.children=false] {boolean} if set to true, all the children will have their destroy * method called as well. 'options' will be passed on to those calls. * @param [options.texture=false] {boolean} Should it destroy the current texture of the sprite as well @@ -417,15 +417,15 @@ */ Sprite.prototype.destroy = function (options) { - options = options || {}; - Container.prototype.destroy.call(this, options); this.anchor = null; - if (options.texture) + var destroyTexture = typeof options === 'boolean' ? options : options && options.texture; + if (destroyTexture) { - this._texture.destroy(!!options.baseTexture); + var destroyBaseTexture = typeof options === 'boolean' ? options : options && options.baseTexture; + this._texture.destroy(!!destroyBaseTexture); } this._texture = null; diff --git a/src/core/text/Text.js b/src/core/text/Text.js index ec88fee..ad60a2e 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -639,7 +639,7 @@ /** * Destroys this text * - * @param [options] {object} Options parameter + * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value * @param [options.children=false] {boolean} if set to true, all the children will have their destroy * method called as well. 'options' will be passed on to those calls. * @param [options.texture=false] {boolean} Should it destroy the current texture of the sprite as well diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 69c0c8d..81cf8b3 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -606,18 +606,16 @@ /** * Destroys the container - * @param [options] {object} Options parameter + * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value * @param [options.children=false] {boolean} if set to true, all the children will have their destroy * method called as well. 'options' will be passed on to those calls. - * */ Container.prototype.destroy = function (options) { - options = options || {}; - DisplayObject.prototype.destroy.call(this); - if (options.children) + var destroyChildren = typeof options === 'boolean' ? options : options && options.children; + if (destroyChildren) { for (var i = 0, j = this.children.length; i < j; ++i) { diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 5a04062..62296d9 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -409,7 +409,7 @@ /** * Destroys this sprite and optionally its texture and children * - * @param [options] {object} Options parameter + * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value * @param [options.children=false] {boolean} if set to true, all the children will have their destroy * method called as well. 'options' will be passed on to those calls. * @param [options.texture=false] {boolean} Should it destroy the current texture of the sprite as well @@ -417,15 +417,15 @@ */ Sprite.prototype.destroy = function (options) { - options = options || {}; - Container.prototype.destroy.call(this, options); this.anchor = null; - if (options.texture) + var destroyTexture = typeof options === 'boolean' ? options : options && options.texture; + if (destroyTexture) { - this._texture.destroy(!!options.baseTexture); + var destroyBaseTexture = typeof options === 'boolean' ? options : options && options.baseTexture; + this._texture.destroy(!!destroyBaseTexture); } this._texture = null; diff --git a/src/core/text/Text.js b/src/core/text/Text.js index ec88fee..ad60a2e 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -639,7 +639,7 @@ /** * Destroys this text * - * @param [options] {object} Options parameter + * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value * @param [options.children=false] {boolean} if set to true, all the children will have their destroy * method called as well. 'options' will be passed on to those calls. * @param [options.texture=false] {boolean} Should it destroy the current texture of the sprite as well diff --git a/test/unit/core/display/Container.test.js b/test/unit/core/display/Container.test.js index db5c925..3534c05 100644 --- a/test/unit/core/display/Container.test.js +++ b/test/unit/core/display/Container.test.js @@ -90,5 +90,19 @@ container.destroy({children: true, texture: true}); expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); }); + + it('should accept boolean and pass it on to children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + container.addChild(child); + container.destroy(true); + expect(childDestroyOpts).to.deep.equal(true); + }); }); }); diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 69c0c8d..81cf8b3 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -606,18 +606,16 @@ /** * Destroys the container - * @param [options] {object} Options parameter + * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value * @param [options.children=false] {boolean} if set to true, all the children will have their destroy * method called as well. 'options' will be passed on to those calls. - * */ Container.prototype.destroy = function (options) { - options = options || {}; - DisplayObject.prototype.destroy.call(this); - if (options.children) + var destroyChildren = typeof options === 'boolean' ? options : options && options.children; + if (destroyChildren) { for (var i = 0, j = this.children.length; i < j; ++i) { diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 5a04062..62296d9 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -409,7 +409,7 @@ /** * Destroys this sprite and optionally its texture and children * - * @param [options] {object} Options parameter + * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value * @param [options.children=false] {boolean} if set to true, all the children will have their destroy * method called as well. 'options' will be passed on to those calls. * @param [options.texture=false] {boolean} Should it destroy the current texture of the sprite as well @@ -417,15 +417,15 @@ */ Sprite.prototype.destroy = function (options) { - options = options || {}; - Container.prototype.destroy.call(this, options); this.anchor = null; - if (options.texture) + var destroyTexture = typeof options === 'boolean' ? options : options && options.texture; + if (destroyTexture) { - this._texture.destroy(!!options.baseTexture); + var destroyBaseTexture = typeof options === 'boolean' ? options : options && options.baseTexture; + this._texture.destroy(!!destroyBaseTexture); } this._texture = null; diff --git a/src/core/text/Text.js b/src/core/text/Text.js index ec88fee..ad60a2e 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -639,7 +639,7 @@ /** * Destroys this text * - * @param [options] {object} Options parameter + * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value * @param [options.children=false] {boolean} if set to true, all the children will have their destroy * method called as well. 'options' will be passed on to those calls. * @param [options.texture=false] {boolean} Should it destroy the current texture of the sprite as well diff --git a/test/unit/core/display/Container.test.js b/test/unit/core/display/Container.test.js index db5c925..3534c05 100644 --- a/test/unit/core/display/Container.test.js +++ b/test/unit/core/display/Container.test.js @@ -90,5 +90,19 @@ container.destroy({children: true, texture: true}); expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); }); + + it('should accept boolean and pass it on to children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + container.addChild(child); + container.destroy(true); + expect(childDestroyOpts).to.deep.equal(true); + }); }); }); diff --git a/test/unit/core/sprites/Sprite.test.js b/test/unit/core/sprites/Sprite.test.js index 25393c4..fda975a 100644 --- a/test/unit/core/sprites/Sprite.test.js +++ b/test/unit/core/sprites/Sprite.test.js @@ -112,6 +112,16 @@ expect(textureDestroyArg).to.equal(true); }); + it('should correctly handle boolean', function () { + var sprite = new PIXI.Sprite(); + var textureDestroyArg; + + sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; + + sprite.destroy(true); + expect(textureDestroyArg).to.equal(true); + }); + it('should pass opts on to children if children flag is set', function () { var sprite = new PIXI.Sprite(), child = new PIXI.DisplayObject(), @@ -125,5 +135,19 @@ sprite.destroy({children: true, texture: true}); expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); }); + + it('should pass bool on to children', function () { + var sprite = new PIXI.Sprite(), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + sprite.addChild(child); + sprite.destroy(true); + expect(childDestroyOpts).to.deep.equal(true); + }); }); }); diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 69c0c8d..81cf8b3 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -606,18 +606,16 @@ /** * Destroys the container - * @param [options] {object} Options parameter + * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value * @param [options.children=false] {boolean} if set to true, all the children will have their destroy * method called as well. 'options' will be passed on to those calls. - * */ Container.prototype.destroy = function (options) { - options = options || {}; - DisplayObject.prototype.destroy.call(this); - if (options.children) + var destroyChildren = typeof options === 'boolean' ? options : options && options.children; + if (destroyChildren) { for (var i = 0, j = this.children.length; i < j; ++i) { diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 5a04062..62296d9 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -409,7 +409,7 @@ /** * Destroys this sprite and optionally its texture and children * - * @param [options] {object} Options parameter + * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value * @param [options.children=false] {boolean} if set to true, all the children will have their destroy * method called as well. 'options' will be passed on to those calls. * @param [options.texture=false] {boolean} Should it destroy the current texture of the sprite as well @@ -417,15 +417,15 @@ */ Sprite.prototype.destroy = function (options) { - options = options || {}; - Container.prototype.destroy.call(this, options); this.anchor = null; - if (options.texture) + var destroyTexture = typeof options === 'boolean' ? options : options && options.texture; + if (destroyTexture) { - this._texture.destroy(!!options.baseTexture); + var destroyBaseTexture = typeof options === 'boolean' ? options : options && options.baseTexture; + this._texture.destroy(!!destroyBaseTexture); } this._texture = null; diff --git a/src/core/text/Text.js b/src/core/text/Text.js index ec88fee..ad60a2e 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -639,7 +639,7 @@ /** * Destroys this text * - * @param [options] {object} Options parameter + * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value * @param [options.children=false] {boolean} if set to true, all the children will have their destroy * method called as well. 'options' will be passed on to those calls. * @param [options.texture=false] {boolean} Should it destroy the current texture of the sprite as well diff --git a/test/unit/core/display/Container.test.js b/test/unit/core/display/Container.test.js index db5c925..3534c05 100644 --- a/test/unit/core/display/Container.test.js +++ b/test/unit/core/display/Container.test.js @@ -90,5 +90,19 @@ container.destroy({children: true, texture: true}); expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); }); + + it('should accept boolean and pass it on to children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + container.addChild(child); + container.destroy(true); + expect(childDestroyOpts).to.deep.equal(true); + }); }); }); diff --git a/test/unit/core/sprites/Sprite.test.js b/test/unit/core/sprites/Sprite.test.js index 25393c4..fda975a 100644 --- a/test/unit/core/sprites/Sprite.test.js +++ b/test/unit/core/sprites/Sprite.test.js @@ -112,6 +112,16 @@ expect(textureDestroyArg).to.equal(true); }); + it('should correctly handle boolean', function () { + var sprite = new PIXI.Sprite(); + var textureDestroyArg; + + sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; + + sprite.destroy(true); + expect(textureDestroyArg).to.equal(true); + }); + it('should pass opts on to children if children flag is set', function () { var sprite = new PIXI.Sprite(), child = new PIXI.DisplayObject(), @@ -125,5 +135,19 @@ sprite.destroy({children: true, texture: true}); expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); }); + + it('should pass bool on to children', function () { + var sprite = new PIXI.Sprite(), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + sprite.addChild(child); + sprite.destroy(true); + expect(childDestroyOpts).to.deep.equal(true); + }); }); }); diff --git a/test/unit/core/text/Text.test.js b/test/unit/core/text/Text.test.js index 443ac80..eecf9a0 100644 --- a/test/unit/core/text/Text.test.js +++ b/test/unit/core/text/Text.test.js @@ -26,6 +26,16 @@ expect(child.position).to.equal(null); }); + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.position).to.equal(null); + expect(child.position).to.equal(null); + }); + it('should pass opts on to children if children flag is set', function () { var text = new PIXI.Text("foo"), child = new PIXI.DisplayObject(),