mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-09-11 20:35:42 +00:00
Regular → Executable
+39
-3
@@ -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);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user