testing/mochitest/tests/MochiKit-1.4.2/MochiKit/MockDOM.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/testing/mochitest/tests/MochiKit-1.4.2/MochiKit/MockDOM.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,115 @@
     1.4 +/***
     1.5 +
     1.6 +MochiKit.MockDOM 1.4.2
     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.2";
    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, ownerDocument) {
    1.44 +    this.tagName = this.nodeName = name.toUpperCase();
    1.45 +    this.ownerDocument = ownerDocument || null;
    1.46 +    if (name == "DOCUMENT") {
    1.47 +        this.nodeType = 9;
    1.48 +        this.childNodes = [];
    1.49 +    } else if (typeof(data) == "string") {
    1.50 +        this.nodeValue = data;
    1.51 +        this.nodeType = 3;
    1.52 +    } else {
    1.53 +        this.nodeType = 1;
    1.54 +        this.childNodes = [];
    1.55 +    }
    1.56 +    if (name.substring(0, 1) == "<") {
    1.57 +        var nameattr = name.substring(
    1.58 +            name.indexOf('"') + 1, name.lastIndexOf('"'));
    1.59 +        name = name.substring(1, name.indexOf(" "));
    1.60 +        this.tagName = this.nodeName = name.toUpperCase();
    1.61 +        this.setAttribute("name", nameattr);
    1.62 +    }
    1.63 +};
    1.64 +
    1.65 +MochiKit.MockDOM.MockElement.prototype = {
    1.66 +    /** @id MochiKit.MockDOM.MockElement.prototype.createElement */
    1.67 +    createElement: function (tagName) {
    1.68 +        return new MochiKit.MockDOM.MockElement(tagName, null, this.nodeType == 9 ? this : this.ownerDocument);
    1.69 +    },
    1.70 +    /** @id MochiKit.MockDOM.MockElement.prototype.createTextNode */
    1.71 +    createTextNode: function (text) {
    1.72 +        return new MochiKit.MockDOM.MockElement("text", text, this.nodeType == 9 ? this : this.ownerDocument);
    1.73 +    },
    1.74 +    /** @id MochiKit.MockDOM.MockElement.prototype.setAttribute */
    1.75 +    setAttribute: function (name, value) {
    1.76 +        this[name] = value;
    1.77 +    },
    1.78 +    /** @id MochiKit.MockDOM.MockElement.prototype.getAttribute */
    1.79 +    getAttribute: function (name) {
    1.80 +        return this[name];
    1.81 +    },
    1.82 +    /** @id MochiKit.MockDOM.MockElement.prototype.appendChild */
    1.83 +    appendChild: function (child) {
    1.84 +        this.childNodes.push(child);
    1.85 +    },
    1.86 +    /** @id MochiKit.MockDOM.MockElement.prototype.toString */
    1.87 +    toString: function () {
    1.88 +        return "MockElement(" + this.tagName + ")";
    1.89 +    },
    1.90 +    /** @id MochiKit.MockDOM.MockElement.prototype.getElementsByTagName */
    1.91 +    getElementsByTagName: function (tagName) {
    1.92 +        var foundElements = [];
    1.93 +        MochiKit.Base.nodeWalk(this, function(node){
    1.94 +            if (tagName == '*' || tagName == node.tagName) {
    1.95 +                foundElements.push(node);
    1.96 +                return node.childNodes;
    1.97 +            }
    1.98 +        });
    1.99 +        return foundElements;
   1.100 +    }
   1.101 +};
   1.102 +
   1.103 +    /** @id MochiKit.MockDOM.EXPORT_OK */
   1.104 +MochiKit.MockDOM.EXPORT_OK = [
   1.105 +    "mockElement",
   1.106 +    "createDocument"
   1.107 +];
   1.108 +
   1.109 +    /** @id MochiKit.MockDOM.EXPORT */
   1.110 +MochiKit.MockDOM.EXPORT = [
   1.111 +    "document"
   1.112 +];
   1.113 +
   1.114 +MochiKit.MockDOM.__new__ = function () {
   1.115 +    this.document = this.createDocument();
   1.116 +};
   1.117 +
   1.118 +MochiKit.MockDOM.__new__();

mercurial