5
5
See <http://mochikit.com/> for documentation, downloads, license, etc.
7
7
(c) 2005 Bob Ippolito. All rights Reserved.
10
11
if (typeof(MochiKit) == "undefined") {
14
15
if (typeof(MochiKit.MockDOM) == "undefined") {
18
19
MochiKit.MockDOM.NAME = "MochiKit.MockDOM";
19
MochiKit.MockDOM.VERSION = "1.3.1";
20
MochiKit.MockDOM.VERSION = "1.4.2";
21
22
MochiKit.MockDOM.__repr__ = function () {
22
23
return "[" + this.NAME + " " + this.VERSION + "]";
26
/** @id MochiKit.MockDOM.toString */
25
27
MochiKit.MockDOM.toString = function () {
26
28
return this.__repr__();
31
/** @id MochiKit.MockDOM.createDocument */
29
32
MochiKit.MockDOM.createDocument = function () {
30
33
var doc = new MochiKit.MockDOM.MockElement("DOCUMENT");
31
34
doc.body = doc.createElement("BODY");
36
MochiKit.MockDOM.MockElement = function (name, data) {
37
this.nodeName = name.toUpperCase();
38
if (typeof(data) == "string") {
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") {
39
47
this.nodeValue = data;
46
54
var nameattr = name.substring(
47
55
name.indexOf('"') + 1, name.lastIndexOf('"'));
48
56
name = name.substring(1, name.indexOf(" "));
49
this.nodeName = name.toUpperCase();
57
this.tagName = this.nodeName = name.toUpperCase();
50
58
this.setAttribute("name", nameattr);
54
62
MochiKit.MockDOM.MockElement.prototype = {
55
createElement: function (nodeName) {
56
return new MochiKit.MockDOM.MockElement(nodeName);
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 */
58
68
createTextNode: function (text) {
59
return new MochiKit.MockDOM.MockElement("text", text);
69
return new MochiKit.MockDOM.MockElement("text", text, this.nodeType == 9 ? this : this.ownerDocument);
71
/** @id MochiKit.MockDOM.MockElement.prototype.setAttribute */
61
72
setAttribute: function (name, value) {
62
73
this[name] = value;
75
/** @id MochiKit.MockDOM.MockElement.prototype.getAttribute */
64
76
getAttribute: function (name) {
79
/** @id MochiKit.MockDOM.MockElement.prototype.appendChild */
67
80
appendChild: function (child) {
68
81
this.childNodes.push(child);
83
/** @id MochiKit.MockDOM.MockElement.prototype.toString */
70
84
toString: function () {
71
return "MockElement(" + this.nodeName + ")";
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__();