Changeset 15497 in webkit for trunk/JavaScriptCore/API/minidom.js
- Timestamp:
- Jul 17, 2006, 9:33:46 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/minidom.js
r15484 r15497 24 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 25 */ 26 27 // For browser-based testing28 if (typeof window != 'undefined') {29 /*30 The methods and constructors below approximate what that the native host should provide31 32 print(string);33 34 Node35 |-- TextNode36 |-- Element37 |-- RootElement38 |-- HeroElement39 |-- VillainElement40 |-- NameElement41 |-- WeaponElement42 |-- Document43 */44 45 function print(string, indentLevel)46 {47 document.getElementById('pre').appendChild(document.createTextNode(string));48 }49 50 Node = function()51 {52 this.__defineGetter__("childNodes", function() {53 if (!this._childNodes)54 this._childNodes = new Array();55 return this._childNodes;56 });57 this.__defineGetter__("firstChild", function () {58 return this.childNodes[0];59 });60 }61 62 Node.prototype.nodeType = "Node";63 64 Node.prototype.appendChild = function(child) {65 this.childNodes.push(child);66 }67 68 Node.prototype.serialize = function(numSpaces) {69 function printSpaces(n)70 {71 for (var i = 0; i < n; i++) // >72 print(" ");73 }74 75 printSpaces(numSpaces);76 print('<' + this.nodeType + '>' + '\n');77 78 var childNodesLength = this.childNodes.length;79 for (var i = 0; i < childNodesLength; i++) //>80 this.childNodes[i].serialize(numSpaces + 4);81 82 printSpaces(numSpaces);83 print('</' + this.nodeType + '>\n');84 }85 86 TextNode = function(text)87 {88 this.text = text;89 }90 91 TextNode.prototype = new Node();92 93 TextNode.prototype.nodeType = "Text";94 95 TextNode.prototype.serialize = function(numSpaces) {96 for (var i = 0; i < numSpaces; i++) // >97 print(" ");98 print(this.text + '\n');99 }100 101 Element = function()102 {103 }104 105 Element.prototype = new Node();106 107 Element.prototype.nodeType = "Element";108 109 RootElement = function()110 {111 }112 113 RootElement.prototype = new Element();114 115 RootElement.prototype.nodeType = "Root";116 117 HeroElement = function()118 {119 }120 121 HeroElement.prototype = new Element();122 123 HeroElement.prototype.nodeType = "Hero";124 125 VillainElement = function()126 {127 }128 129 VillainElement.prototype = new Element();130 131 VillainElement.prototype.nodeType = "Villain";132 133 NameElement = function()134 {135 }136 137 NameElement.prototype = new Element();138 139 NameElement.prototype.nodeType = "Name";140 141 WeaponElement = function()142 {143 }144 145 WeaponElement.prototype = new Element();146 147 WeaponElement.prototype.nodeType = "Weapon";148 149 Document = function()150 {151 }152 153 Document.prototype = new Node();154 155 Document.prototype.serialize = function() {156 this.firstChild.serialize(0);157 }158 159 Document.prototype.createElement = function(elementType) {160 return eval('new ' + elementType + 'Element()');161 }162 163 Document.prototype.createTextNode = function(text) {164 return new TextNode(text);165 }166 }167 26 168 27 function shouldBe(a, b) … … 248 107 249 108 print(Node); 250 251 /*252 var element, name, weapon;253 254 var document = new Document();255 document.appendChild(document.createElement('Root'));256 257 // Tank Girl258 element = document.createElement('Hero');259 260 name = document.createElement('Name');261 name.appendChild(document.createTextNode('Tank Girl'));262 element.appendChild(name);263 264 weapon = document.createElement('Weapon');265 weapon.appendChild(document.createTextNode('Tank'));266 element.appendChild(weapon);267 268 weapon = document.createElement('Weapon');269 weapon.appendChild(document.createTextNode('Attitude'));270 element.appendChild(weapon);271 272 weapon = document.createElement('Weapon');273 weapon.appendChild(document.createTextNode('Army of genetically engineered super-kangaroos'));274 element.appendChild(weapon);275 276 document.firstChild.appendChild(element);277 278 279 // Skeletor280 element = document.createElement('Villain');281 282 name = document.createElement('Name');283 name.appendChild(document.createTextNode('Skeletor'));284 element.appendChild(name);285 286 weapon = document.createElement('Weapon');287 weapon.appendChild(document.createTextNode('Havok Staff'));288 element.appendChild(weapon);289 290 weapon = document.createElement('Weapon');291 weapon.appendChild(document.createTextNode('Motley crew of henchmen'));292 element.appendChild(weapon);293 294 document.firstChild.appendChild(element);295 296 // Serialize297 document.serialize();298 */299 109 } 300 110
Note:
See TracChangeset
for help on using the changeset viewer.