1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-08-31 01:48:02 +00:00

Refactor things so that widgets can opt not to generate an element

They have to have a single child renderer instead
This commit is contained in:
Jeremy Ruston
2013-01-03 20:51:13 +00:00
parent 1c559660d9
commit 89d44e27df

View File

@@ -114,6 +114,8 @@ ElementRenderer.prototype.getAttribute = function(name,defaultValue) {
};
ElementRenderer.prototype.render = function(type) {
// Check if our widget is providing an element
if(this.widget.tag) {
var isHtml = type === "text/html",
output = [],attr,a,v;
if(isHtml) {
@@ -156,11 +158,19 @@ ElementRenderer.prototype.render = function(type) {
}
}
return output.join("");
} else {
// Just render our first child if we're not generating an element
return this.widget.children[0].render(type);
}
};
ElementRenderer.prototype.renderInDom = function() {
// Check if our widget is providing an element
if(this.widget.tag) {
// Create the element
this.domNode = document.createElement(this.widget.tag);
// Assign any specified event handlers
$tw.utils.addEventListeners(this.domNode,this.widget.events);
// Assign the attributes
this.assignAttributes();
// Render any child nodes
@@ -170,14 +180,16 @@ ElementRenderer.prototype.renderInDom = function() {
self.domNode.appendChild(node.renderInDom());
}
});
// Assign any specified event handlers
$tw.utils.addEventListeners(this.domNode,this.widget.events);
// Call postRenderInDom if the widget provides it
if(this.widget.postRenderInDom) {
this.widget.postRenderInDom();
}
// Return the dom node
return this.domNode;
} else {
// If we're not generating an element, just render our first child
return this.widget.children[0].renderInDom();
}
};
ElementRenderer.prototype.assignAttributes = function() {