Initial Commit

Carried over from the abortive pull request #169
This commit is contained in:
Jeremy Ruston
2013-10-12 17:05:13 +01:00
parent 6ea264f3bc
commit ed35d91be6
25 changed files with 2403 additions and 15 deletions
Regular → Executable
+39 -3
View File
@@ -12,16 +12,27 @@ A barebones implementation of DOM interfaces needed by the rendering mechanism.
/*global $tw: false */
"use strict";
var TW_TextNode = function(text) {
this.textContent = text;
// Sequence number used to enable us to track objects for testing
var sequenceNumber = null;
var bumpSequenceNumber = function(object) {
if(sequenceNumber !== null) {
object.sequenceNumber = sequenceNumber++;
}
}
var TW_TextNode = function(text) {
bumpSequenceNumber(this);
this.textContent = text;
};
var TW_Element = function(tag) {
bumpSequenceNumber(this);
this.tag = tag;
this.attributes = {};
this.isRaw = false;
this.children = [];
}
};
TW_Element.prototype.setAttribute = function(name,value) {
if(this.isRaw) {
@@ -39,6 +50,19 @@ TW_Element.prototype.appendChild = function(node) {
node.parentNode = this;
};
TW_Element.prototype.insertBefore = function(node,nextSibling) {
if(nextSibling) {
var p = this.children.indexOf(nextSibling);
if(p !== -1) {
this.children.splice(p,0,node);
} else {
this.appendChild(node);
}
} else {
this.appendChild(node);
}
}
TW_Element.prototype.removeChild = function(node) {
var p = this.children.indexOf(node);
if(p !== -1) {
@@ -60,6 +84,15 @@ TW_Element.prototype.addEventListener = function(type,listener,useCapture) {
// Do nothing
};
Object.defineProperty(TW_Element.prototype, "className", {
get: function() {
return this.attributes["class"] || "";
},
set: function(value) {
this.attributes["class"] = value;
}
});
Object.defineProperty(TW_Element.prototype, "outerHTML", {
get: function() {
var output = [],attr,a,v;
@@ -123,6 +156,9 @@ Object.defineProperty(TW_Element.prototype, "textContent", {
});
var document = {
setSequenceNumber: function(value) {
sequenceNumber = value;
},
createElementNS: function(namespace,tag) {
return new TW_Element(tag);
},