testing/mochitest/MochiKit/MockDOM.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:bb7820934e7d
1 /***
2
3 MochiKit.MockDOM 1.4
4
5 See <http://mochikit.com/> for documentation, downloads, license, etc.
6
7 (c) 2005 Bob Ippolito. All rights Reserved.
8
9 ***/
10
11 if (typeof(MochiKit) == "undefined") {
12 MochiKit = {};
13 }
14
15 if (typeof(MochiKit.MockDOM) == "undefined") {
16 MochiKit.MockDOM = {};
17 }
18
19 MochiKit.MockDOM.NAME = "MochiKit.MockDOM";
20 MochiKit.MockDOM.VERSION = "1.4";
21
22 MochiKit.MockDOM.__repr__ = function () {
23 return "[" + this.NAME + " " + this.VERSION + "]";
24 };
25
26 /** @id MochiKit.MockDOM.toString */
27 MochiKit.MockDOM.toString = function () {
28 return this.__repr__();
29 };
30
31 /** @id MochiKit.MockDOM.createDocument */
32 MochiKit.MockDOM.createDocument = function () {
33 var doc = new MochiKit.MockDOM.MockElement("DOCUMENT");
34 doc.body = doc.createElement("BODY");
35 doc.appendChild(doc.body);
36 return doc;
37 };
38
39 /** @id MochiKit.MockDOM.MockElement */
40 MochiKit.MockDOM.MockElement = function (name, data) {
41 this.tagName = this.nodeName = name.toUpperCase();
42 if (typeof(data) == "string") {
43 this.nodeValue = data;
44 this.nodeType = 3;
45 } else {
46 this.nodeType = 1;
47 this.childNodes = [];
48 }
49 if (name.substring(0, 1) == "<") {
50 var nameattr = name.substring(
51 name.indexOf('"') + 1, name.lastIndexOf('"'));
52 name = name.substring(1, name.indexOf(" "));
53 this.tagName = this.nodeName = name.toUpperCase();
54 this.setAttribute("name", nameattr);
55 }
56 };
57
58 MochiKit.MockDOM.MockElement.prototype = {
59 /** @id MochiKit.MockDOM.MockElement.prototype.createElement */
60 createElement: function (tagName) {
61 return new MochiKit.MockDOM.MockElement(tagName);
62 },
63 /** @id MochiKit.MockDOM.MockElement.prototype.createTextNode */
64 createTextNode: function (text) {
65 return new MochiKit.MockDOM.MockElement("text", text);
66 },
67 /** @id MochiKit.MockDOM.MockElement.prototype.setAttribute */
68 setAttribute: function (name, value) {
69 this[name] = value;
70 },
71 /** @id MochiKit.MockDOM.MockElement.prototype.getAttribute */
72 getAttribute: function (name) {
73 return this[name];
74 },
75 /** @id MochiKit.MockDOM.MockElement.prototype.appendChild */
76 appendChild: function (child) {
77 this.childNodes.push(child);
78 },
79 /** @id MochiKit.MockDOM.MockElement.prototype.toString */
80 toString: function () {
81 return "MockElement(" + this.tagName + ")";
82 }
83 };
84
85 /** @id MochiKit.MockDOM.EXPORT_OK */
86 MochiKit.MockDOM.EXPORT_OK = [
87 "mockElement",
88 "createDocument"
89 ];
90
91 /** @id MochiKit.MockDOM.EXPORT */
92 MochiKit.MockDOM.EXPORT = [
93 "document"
94 ];
95
96 MochiKit.MockDOM.__new__ = function () {
97 this.document = this.createDocument();
98 };
99
100 MochiKit.MockDOM.__new__();

mercurial