1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-29 23:40:45 +00:00

Further refactorings to simplify macro development

This commit is contained in:
Jeremy Ruston 2012-03-05 13:36:53 +00:00
parent 8abf0049cf
commit cb97295fdb
2 changed files with 20 additions and 14 deletions

View File

@ -153,6 +153,10 @@ MacroNode.prototype.parseMacroParamString = function(paramString) {
return params;
};
MacroNode.prototype.hasParameter = function(name) {
return this.params.hasOwnProperty(name);
};
MacroNode.prototype.clone = function() {
return new MacroNode(this.macroName,this.srcParams,this.cloneChildren(),this.store,this.dependencies);
};
@ -348,6 +352,7 @@ ElementNode.prototype.renderInDom = function(domNode) {
}
}
domNode.appendChild(element);
this.domNode = element;
if(this.children) {
for(var t=0; t<this.children.length; t++) {
this.children[t].renderInDom(element);
@ -387,7 +392,8 @@ TextNode.prototype.render = function(type) {
};
TextNode.prototype.renderInDom = function(domNode) {
domNode.appendChild(document.createTextNode(this.text));
this.domNode = document.createTextNode(this.text);
domNode.appendChild(this.domNode);
};
var EntityNode = function(entity) {
@ -406,7 +412,8 @@ EntityNode.prototype.render = function(type) {
};
EntityNode.prototype.renderInDom = function(domNode) {
domNode.appendChild(document.createTextNode(utils.entityDecode(this.entity)));
this.domNode = document.createTextNode(utils.entityDecode(this.entity));
domNode.appendChild(this.domNode);
};
var RawNode = function(html) {
@ -425,9 +432,9 @@ RawNode.prototype.render = function(type) {
};
RawNode.prototype.renderInDom = function(domNode) {
var div = document.createElement("div");
div.innerHTML = this.html;
domNode.appendChild(div);
this.domNode = document.createElement("div");
this.domNode.innerHTML = this.html;
domNode.appendChild(this.domNode);
};
/*

View File

@ -112,13 +112,13 @@ exports.macro = {
var attributes = {
"class": ["tw-slider"]
};
if(this.params.hasOwnProperty("class")) {
if(this.hasParameter("class")) {
attributes["class"].push(this.params["class"]);
}
if(this.params.hasOwnProperty("state")) {
if(this.hasParameter("state")) {
attributes["data-tw-slider-type"] = this.params.state;
}
if(this.params.hasOwnProperty("tooltip")) {
if(this.hasParameter("tooltip")) {
attributes.alt = this.params.tooltip;
attributes.title = this.params.tooltip;
}
@ -147,22 +147,21 @@ exports.macro = {
refreshInDom: function(changes) {
var needContentRefresh = true; // Avoid refreshing the content nodes if we don't need to
// If the state tiddler has changed then reset the open state
if(this.params.hasOwnProperty("state") && changes.hasOwnProperty(this.params.state)) {
if(this.hasParameter("state") && changes.hasOwnProperty(this.params.state)) {
this.isOpen = getOpenState(this);
}
// Render the content if the slider is open and we don't have any content yet
if(this.isOpen && this.content[0].children[1].children.length === 0) {
// Remove the existing dom node for the body
this.content[0].domNode.removeChild(this.content[0].children[1].domNode);
// Get the slider content and execute it
this.content[0].children[1].children = getSliderContent(this);
this.content[0].children[1].execute(this.parents,this.store.getTiddler(this.tiddlerTitle));
// Replace the existing slider body DOM node
this.domNode.firstChild.removeChild(this.domNode.firstChild.firstChild.nextSibling);
this.content[0].children[1].renderInDom(this.domNode.firstChild,this.domNode.firstChild.firstChild.nextSibling);
this.content[0].children[1].renderInDom(this.content[0].domNode,null);
needContentRefresh = false; // Don't refresh the children if we've just created them
}
// Set the visibility of the slider content
var el = this.domNode.firstChild.firstChild.nextSibling;
el.style.display = this.isOpen ? "block" : "none";
this.content[0].children[1].domNode.style.display = this.isOpen ? "block" : "none";
// Refresh any children
if(needContentRefresh) {
for(var t=0; t<this.content.length; t++) {