1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-09-06 12:58:03 +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) { ElementRenderer.prototype.render = function(type) {
// Check if our widget is providing an element
if(this.widget.tag) {
var isHtml = type === "text/html", var isHtml = type === "text/html",
output = [],attr,a,v; output = [],attr,a,v;
if(isHtml) { if(isHtml) {
@@ -156,11 +158,19 @@ ElementRenderer.prototype.render = function(type) {
} }
} }
return output.join(""); 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() { ElementRenderer.prototype.renderInDom = function() {
// Check if our widget is providing an element
if(this.widget.tag) {
// Create the element // Create the element
this.domNode = document.createElement(this.widget.tag); this.domNode = document.createElement(this.widget.tag);
// Assign any specified event handlers
$tw.utils.addEventListeners(this.domNode,this.widget.events);
// Assign the attributes // Assign the attributes
this.assignAttributes(); this.assignAttributes();
// Render any child nodes // Render any child nodes
@@ -170,14 +180,16 @@ ElementRenderer.prototype.renderInDom = function() {
self.domNode.appendChild(node.renderInDom()); 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 // Call postRenderInDom if the widget provides it
if(this.widget.postRenderInDom) { if(this.widget.postRenderInDom) {
this.widget.postRenderInDom(); this.widget.postRenderInDom();
} }
// Return the dom node // Return the dom node
return this.domNode; 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() { ElementRenderer.prototype.assignAttributes = function() {