From 866bf6db28111bea890c6da4cb4a9ef3660cd6f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Wed, 25 May 2016 12:15:36 +0800 Subject: [PATCH] IDOMElement: added clear, renamed lootChildren --- botanjs/src/Dandelion/IDOMElement.js | 28 +++++++++++++------- botanjs/src/externs/Dandelion.IDOMElement.js | 4 ++- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/botanjs/src/Dandelion/IDOMElement.js b/botanjs/src/Dandelion/IDOMElement.js index ccffbb7..8e9345f 100644 --- a/botanjs/src/Dandelion/IDOMElement.js +++ b/botanjs/src/Dandelion/IDOMElement.js @@ -10,23 +10,24 @@ var IDOMObject = ns[ NS_INVOKE ]( "IDOMObject" ); // IDOMElement, augmented element wrapper utilizing IKeys - var IDOMElement = function (element, sw) + var IDOMElement = function ( element, sw ) { - if (element instanceof IDOMElement) return element; + if ( element instanceof IDOMElement ) return element; - if (sw) + if ( sw ) { IDOMObject.call( this, element, true ); - this["getDAttribute"] = this.getDAttribute.bind(element); + this["getDAttribute"] = this.getDAttribute.bind( element ); - this["lootChildren"] = this.lootChildren.bind(element); + this["loot"] = this.loot.bind( element ); this["foreach"] = this.foreach.bind(element); - this["reverseChild"] = this.reverseChild.bind(element); - this["first"] = this.first.bind(element); - this["last"] = this.last.bind(element); - this["contains"] = this.contains.bind(element); + this["reverseChild"] = this.reverseChild.bind( element ); + this["clear"] = this.clear.bind( element ); + this["first"] = this.first.bind( element ); + this["last"] = this.last.bind( element ); + this["contains"] = this.contains.bind( element ); // Org values this["style"] = element.style; @@ -76,7 +77,7 @@ } }; - IDOMElement.prototype.lootChildren = function ( element ) + IDOMElement.prototype.loot = function ( element ) { var _nodes = element.childNodes; while(_nodes.length) @@ -85,6 +86,13 @@ } }; + IDOMElement.prototype.clear = function () + { + var _nodes = this.childNodes; + while( _nodes.length ) + this.removeChild( _nodes[0] ); + }; + IDOMElement.prototype.getDAttribute = function(name) { var i = this.getAttribute("data-" + name); diff --git a/botanjs/src/externs/Dandelion.IDOMElement.js b/botanjs/src/externs/Dandelion.IDOMElement.js index b00b4ec..6e23e35 100644 --- a/botanjs/src/externs/Dandelion.IDOMElement.js +++ b/botanjs/src/externs/Dandelion.IDOMElement.js @@ -6,7 +6,9 @@ Dandelion.IDOMElement.getDAttribute; /** @type {Function} */ Dandelion.IDOMElement.setAttribute; /** @type {Function} */ -Dandelion.IDOMElement.lootChildren; +Dandelion.IDOMElement.loot; +/** @type {Function} */ +Dandelion.IDOMElement.clear; /** @type {Function} */ Dandelion.IDOMElement.foreach; /** @type {Function} */