mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 20:10:03 +00:00
Further refactorings to simplify macro development
This commit is contained in:
parent
8abf0049cf
commit
cb97295fdb
@ -153,6 +153,10 @@ MacroNode.prototype.parseMacroParamString = function(paramString) {
|
|||||||
return params;
|
return params;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MacroNode.prototype.hasParameter = function(name) {
|
||||||
|
return this.params.hasOwnProperty(name);
|
||||||
|
};
|
||||||
|
|
||||||
MacroNode.prototype.clone = function() {
|
MacroNode.prototype.clone = function() {
|
||||||
return new MacroNode(this.macroName,this.srcParams,this.cloneChildren(),this.store,this.dependencies);
|
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);
|
domNode.appendChild(element);
|
||||||
|
this.domNode = element;
|
||||||
if(this.children) {
|
if(this.children) {
|
||||||
for(var t=0; t<this.children.length; t++) {
|
for(var t=0; t<this.children.length; t++) {
|
||||||
this.children[t].renderInDom(element);
|
this.children[t].renderInDom(element);
|
||||||
@ -387,7 +392,8 @@ TextNode.prototype.render = function(type) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TextNode.prototype.renderInDom = function(domNode) {
|
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) {
|
var EntityNode = function(entity) {
|
||||||
@ -406,7 +412,8 @@ EntityNode.prototype.render = function(type) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
EntityNode.prototype.renderInDom = function(domNode) {
|
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) {
|
var RawNode = function(html) {
|
||||||
@ -425,9 +432,9 @@ RawNode.prototype.render = function(type) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
RawNode.prototype.renderInDom = function(domNode) {
|
RawNode.prototype.renderInDom = function(domNode) {
|
||||||
var div = document.createElement("div");
|
this.domNode = document.createElement("div");
|
||||||
div.innerHTML = this.html;
|
this.domNode.innerHTML = this.html;
|
||||||
domNode.appendChild(div);
|
domNode.appendChild(this.domNode);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -112,13 +112,13 @@ exports.macro = {
|
|||||||
var attributes = {
|
var attributes = {
|
||||||
"class": ["tw-slider"]
|
"class": ["tw-slider"]
|
||||||
};
|
};
|
||||||
if(this.params.hasOwnProperty("class")) {
|
if(this.hasParameter("class")) {
|
||||||
attributes["class"].push(this.params["class"]);
|
attributes["class"].push(this.params["class"]);
|
||||||
}
|
}
|
||||||
if(this.params.hasOwnProperty("state")) {
|
if(this.hasParameter("state")) {
|
||||||
attributes["data-tw-slider-type"] = this.params.state;
|
attributes["data-tw-slider-type"] = this.params.state;
|
||||||
}
|
}
|
||||||
if(this.params.hasOwnProperty("tooltip")) {
|
if(this.hasParameter("tooltip")) {
|
||||||
attributes.alt = this.params.tooltip;
|
attributes.alt = this.params.tooltip;
|
||||||
attributes.title = this.params.tooltip;
|
attributes.title = this.params.tooltip;
|
||||||
}
|
}
|
||||||
@ -147,22 +147,21 @@ exports.macro = {
|
|||||||
refreshInDom: function(changes) {
|
refreshInDom: function(changes) {
|
||||||
var needContentRefresh = true; // Avoid refreshing the content nodes if we don't need to
|
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 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);
|
this.isOpen = getOpenState(this);
|
||||||
}
|
}
|
||||||
// Render the content if the slider is open and we don't have any content yet
|
// 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) {
|
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
|
// Get the slider content and execute it
|
||||||
this.content[0].children[1].children = getSliderContent(this);
|
this.content[0].children[1].children = getSliderContent(this);
|
||||||
this.content[0].children[1].execute(this.parents,this.store.getTiddler(this.tiddlerTitle));
|
this.content[0].children[1].execute(this.parents,this.store.getTiddler(this.tiddlerTitle));
|
||||||
// Replace the existing slider body DOM node
|
this.content[0].children[1].renderInDom(this.content[0].domNode,null);
|
||||||
this.domNode.firstChild.removeChild(this.domNode.firstChild.firstChild.nextSibling);
|
|
||||||
this.content[0].children[1].renderInDom(this.domNode.firstChild,this.domNode.firstChild.firstChild.nextSibling);
|
|
||||||
needContentRefresh = false; // Don't refresh the children if we've just created them
|
needContentRefresh = false; // Don't refresh the children if we've just created them
|
||||||
}
|
}
|
||||||
// Set the visibility of the slider content
|
// Set the visibility of the slider content
|
||||||
var el = this.domNode.firstChild.firstChild.nextSibling;
|
this.content[0].children[1].domNode.style.display = this.isOpen ? "block" : "none";
|
||||||
el.style.display = this.isOpen ? "block" : "none";
|
|
||||||
// Refresh any children
|
// Refresh any children
|
||||||
if(needContentRefresh) {
|
if(needContentRefresh) {
|
||||||
for(var t=0; t<this.content.length; t++) {
|
for(var t=0; t<this.content.length; t++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user