5 See <http://mochikit.com/> for documentation, downloads, license, etc.
7 (c) 2005 Bob Ippolito. All rights Reserved.
11 if (typeof(MochiKit
) == "undefined") {
15 if (typeof(MochiKit
.MockDOM
) == "undefined") {
16 MochiKit
.MockDOM
= {};
19 MochiKit
.MockDOM
.NAME
= "MochiKit.MockDOM";
20 MochiKit
.MockDOM
.VERSION
= "1.4";
22 MochiKit
.MockDOM
.__repr__
= function () {
23 return "[" + this.NAME
+ " " + this.VERSION
+ "]";
26 /** @id MochiKit.MockDOM.toString */
27 MochiKit
.MockDOM
.toString
= function () {
28 return this.__repr__();
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
);
39 /** @id MochiKit.MockDOM.MockElement */
40 MochiKit
.MockDOM
.MockElement
= function (name
, data
, ownerDocument
) {
41 this.tagName
= this.nodeName
= name
.toUpperCase();
42 this.ownerDocument
= ownerDocument
|| null;
43 if (name
== "DOCUMENT") {
46 } else if (typeof(data
) == "string") {
47 this.nodeValue
= data
;
53 if (name
.substring(0, 1) == "<") {
54 var nameattr
= name
.substring(
55 name
.indexOf('"') + 1, name
.lastIndexOf('"'));
56 name
= name
.substring(1, name
.indexOf(" "));
57 this.tagName
= this.nodeName
= name
.toUpperCase();
58 this.setAttribute("name", nameattr
);
62 MochiKit
.MockDOM
.MockElement
.prototype = {
63 /** @id MochiKit.MockDOM.MockElement.prototype.createElement */
64 createElement
: function (tagName
) {
65 return new MochiKit
.MockDOM
.MockElement(tagName
, null, this.nodeType
== 9 ? this : this.ownerDocument
);
67 /** @id MochiKit.MockDOM.MockElement.prototype.createTextNode */
68 createTextNode
: function (text
) {
69 return new MochiKit
.MockDOM
.MockElement("text", text
, this.nodeType
== 9 ? this : this.ownerDocument
);
71 /** @id MochiKit.MockDOM.MockElement.prototype.setAttribute */
72 setAttribute
: function (name
, value
) {
75 /** @id MochiKit.MockDOM.MockElement.prototype.getAttribute */
76 getAttribute
: function (name
) {
79 /** @id MochiKit.MockDOM.MockElement.prototype.appendChild */
80 appendChild
: function (child
) {
81 this.childNodes
.push(child
);
83 /** @id MochiKit.MockDOM.MockElement.prototype.toString */
84 toString
: function () {
85 return "MockElement(" + this.tagName
+ ")";
87 /** @id MochiKit.MockDOM.MockElement.prototype.getElementsByTagName */
88 getElementsByTagName
: function (tagName
) {
89 var foundElements
= [];
90 MochiKit
.Base
.nodeWalk(this, function(node
){
91 if (tagName
== '*' || tagName
== node
.tagName
) {
92 foundElements
.push(node
);
93 return node
.childNodes
;
100 /** @id MochiKit.MockDOM.EXPORT_OK */
101 MochiKit
.MockDOM
.EXPORT_OK
= [
106 /** @id MochiKit.MockDOM.EXPORT */
107 MochiKit
.MockDOM
.EXPORT
= [
111 MochiKit
.MockDOM
.__new__
= function () {
112 this.document
= this.createDocument();
115 MochiKit
.MockDOM
.__new__();