1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mochitest/MochiKit/MockDOM.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 1.4 +/*** 1.5 + 1.6 +MochiKit.MockDOM 1.4 1.7 + 1.8 +See <http://mochikit.com/> for documentation, downloads, license, etc. 1.9 + 1.10 +(c) 2005 Bob Ippolito. All rights Reserved. 1.11 + 1.12 +***/ 1.13 + 1.14 +if (typeof(MochiKit) == "undefined") { 1.15 + MochiKit = {}; 1.16 +} 1.17 + 1.18 +if (typeof(MochiKit.MockDOM) == "undefined") { 1.19 + MochiKit.MockDOM = {}; 1.20 +} 1.21 + 1.22 +MochiKit.MockDOM.NAME = "MochiKit.MockDOM"; 1.23 +MochiKit.MockDOM.VERSION = "1.4"; 1.24 + 1.25 +MochiKit.MockDOM.__repr__ = function () { 1.26 + return "[" + this.NAME + " " + this.VERSION + "]"; 1.27 +}; 1.28 + 1.29 +/** @id MochiKit.MockDOM.toString */ 1.30 +MochiKit.MockDOM.toString = function () { 1.31 + return this.__repr__(); 1.32 +}; 1.33 + 1.34 +/** @id MochiKit.MockDOM.createDocument */ 1.35 +MochiKit.MockDOM.createDocument = function () { 1.36 + var doc = new MochiKit.MockDOM.MockElement("DOCUMENT"); 1.37 + doc.body = doc.createElement("BODY"); 1.38 + doc.appendChild(doc.body); 1.39 + return doc; 1.40 +}; 1.41 + 1.42 +/** @id MochiKit.MockDOM.MockElement */ 1.43 +MochiKit.MockDOM.MockElement = function (name, data) { 1.44 + this.tagName = this.nodeName = name.toUpperCase(); 1.45 + if (typeof(data) == "string") { 1.46 + this.nodeValue = data; 1.47 + this.nodeType = 3; 1.48 + } else { 1.49 + this.nodeType = 1; 1.50 + this.childNodes = []; 1.51 + } 1.52 + if (name.substring(0, 1) == "<") { 1.53 + var nameattr = name.substring( 1.54 + name.indexOf('"') + 1, name.lastIndexOf('"')); 1.55 + name = name.substring(1, name.indexOf(" ")); 1.56 + this.tagName = this.nodeName = name.toUpperCase(); 1.57 + this.setAttribute("name", nameattr); 1.58 + } 1.59 +}; 1.60 + 1.61 +MochiKit.MockDOM.MockElement.prototype = { 1.62 + /** @id MochiKit.MockDOM.MockElement.prototype.createElement */ 1.63 + createElement: function (tagName) { 1.64 + return new MochiKit.MockDOM.MockElement(tagName); 1.65 + }, 1.66 + /** @id MochiKit.MockDOM.MockElement.prototype.createTextNode */ 1.67 + createTextNode: function (text) { 1.68 + return new MochiKit.MockDOM.MockElement("text", text); 1.69 + }, 1.70 + /** @id MochiKit.MockDOM.MockElement.prototype.setAttribute */ 1.71 + setAttribute: function (name, value) { 1.72 + this[name] = value; 1.73 + }, 1.74 + /** @id MochiKit.MockDOM.MockElement.prototype.getAttribute */ 1.75 + getAttribute: function (name) { 1.76 + return this[name]; 1.77 + }, 1.78 + /** @id MochiKit.MockDOM.MockElement.prototype.appendChild */ 1.79 + appendChild: function (child) { 1.80 + this.childNodes.push(child); 1.81 + }, 1.82 + /** @id MochiKit.MockDOM.MockElement.prototype.toString */ 1.83 + toString: function () { 1.84 + return "MockElement(" + this.tagName + ")"; 1.85 + } 1.86 +}; 1.87 + 1.88 + /** @id MochiKit.MockDOM.EXPORT_OK */ 1.89 +MochiKit.MockDOM.EXPORT_OK = [ 1.90 + "mockElement", 1.91 + "createDocument" 1.92 +]; 1.93 + 1.94 + /** @id MochiKit.MockDOM.EXPORT */ 1.95 +MochiKit.MockDOM.EXPORT = [ 1.96 + "document" 1.97 +]; 1.98 + 1.99 +MochiKit.MockDOM.__new__ = function () { 1.100 + this.document = this.createDocument(); 1.101 +}; 1.102 + 1.103 +MochiKit.MockDOM.__new__();