mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-02 12:19:11 +00:00
Refactored handling of context tiddler
Now the title is passed around, rather than a reference to the tiddler. This lets the context be a missing tiddler, enabling us to correctly render missing tiddlers
This commit is contained in:
parent
cd0f8ebb52
commit
392e717497
@ -207,9 +207,13 @@ MacroNode.prototype.cloneChildren = function() {
|
||||
return childClones;
|
||||
};
|
||||
|
||||
MacroNode.prototype.execute = function(parents,tiddler) {
|
||||
MacroNode.prototype.execute = function(parents,tiddlerTitle) {
|
||||
// Evaluate macro parameters to get their values
|
||||
this.params = {};
|
||||
var tiddler = this.store.getTiddler(tiddlerTitle);
|
||||
if(!tiddler) {
|
||||
tiddler = {title: tiddlerTitle};
|
||||
}
|
||||
for(var p in this.srcParams) {
|
||||
if(typeof this.srcParams[p] === "function") {
|
||||
this.params[p] = this.srcParams[p](tiddler,this.store,utils);
|
||||
@ -218,7 +222,7 @@ MacroNode.prototype.execute = function(parents,tiddler) {
|
||||
}
|
||||
}
|
||||
// Save the context tiddler
|
||||
this.tiddlerTitle = tiddler ? tiddler.title : null;
|
||||
this.tiddlerTitle = tiddlerTitle;
|
||||
// Save a reference to the array of parents
|
||||
this.parents = parents || [];
|
||||
// Render the macro to get its content
|
||||
@ -261,8 +265,7 @@ MacroNode.prototype.refresh = function(changes) {
|
||||
// Check if any of the dependencies of this macro node have changed
|
||||
if(this.dependencies.hasChanged(changes)) {
|
||||
// Re-execute the macro if so
|
||||
var tiddler = this.store.getTiddler(this.tiddlerTitle);
|
||||
this.execute(this.parents,tiddler);
|
||||
this.execute(this.parents,this.tiddlerTitle);
|
||||
} else {
|
||||
// Refresh any children
|
||||
for(t=0; t<this.content.length; t++) {
|
||||
@ -277,7 +280,6 @@ MacroNode.prototype.refreshInDom = function(changes) {
|
||||
// Check if any of the dependencies of this macro node have changed
|
||||
if(this.dependencies.hasChanged(changes)) {
|
||||
// Ask the macro to rerender itself if it can
|
||||
var tiddler = this.store.getTiddler(this.tiddlerTitle);
|
||||
if(this.macro.refreshInDom) {
|
||||
this.macro.refreshInDom.call(this,changes);
|
||||
} else {
|
||||
@ -285,7 +287,7 @@ MacroNode.prototype.refreshInDom = function(changes) {
|
||||
while(this.domNode.hasChildNodes()) {
|
||||
this.domNode.removeChild(this.domNode.firstChild);
|
||||
}
|
||||
this.execute(this.parents,tiddler);
|
||||
this.execute(this.parents,this.tiddlerTitle);
|
||||
for(t=0; t<this.content.length; t++) {
|
||||
this.content[t].renderInDom(this.domNode);
|
||||
}
|
||||
@ -342,10 +344,10 @@ ElementNode.prototype.clone = function() {
|
||||
return new ElementNode(this.type,this.attributes,childClones);
|
||||
};
|
||||
|
||||
ElementNode.prototype.execute = function(parents,tiddler) {
|
||||
ElementNode.prototype.execute = function(parents,tiddlerTitle) {
|
||||
if(this.children) {
|
||||
for(var t=0; t<this.children.length; t++) {
|
||||
this.children[t].execute(parents,tiddler);
|
||||
this.children[t].execute(parents,tiddlerTitle);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -303,7 +303,7 @@ WikiStore.prototype.renderTiddler = function(targetType,tiddlerTitle,templateTit
|
||||
null,
|
||||
this);
|
||||
// Execute the macro
|
||||
macro.execute([],this.getTiddler(tiddlerTitle));
|
||||
macro.execute([],tiddlerTitle);
|
||||
// Render it
|
||||
return macro.render(targetType);
|
||||
};
|
||||
@ -314,7 +314,7 @@ WikiStore.prototype.installMacro = function(macro) {
|
||||
|
||||
WikiStore.prototype.renderMacro = function(macroName,params,children,tiddlerTitle) {
|
||||
var macro = Renderer.MacroNode(macroName,params,children,this);
|
||||
macro.execute([],this.getTiddler(tiddlerTitle));
|
||||
macro.execute([],tiddlerTitle);
|
||||
return macro;
|
||||
};
|
||||
|
||||
|
@ -24,7 +24,7 @@ function showChooser(macroNode) {
|
||||
]));
|
||||
});
|
||||
var wrapper = Renderer.ElementNode("ul",{},nodes);
|
||||
wrapper.execute(macroNode.parents,macroNode.store.getTiddler(macroNode.tiddlerTitle));
|
||||
wrapper.execute(macroNode.parents,macroNode.tiddlerTitle);
|
||||
macroNode.content = [wrapper];
|
||||
macroNode.content[0].renderInDom(macroNode.domNode);
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ exports.macro = {
|
||||
"class": classes
|
||||
},this.cloneChildren())];
|
||||
for(var t=0; t<content.length; t++) {
|
||||
content[t].execute(this.parents,this.store.getTiddler(this.tiddlerTitle));
|
||||
content[t].execute(this.parents,this.tiddlerTitle);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ exports.macro = {
|
||||
cloneTemplate.push(templateTree[c].clone());
|
||||
}
|
||||
var listNode = Renderer.ElementNode("li",null,cloneTemplate);
|
||||
listNode.execute(parents,this.store.getTiddler(tiddlers[t]));
|
||||
listNode.execute(parents,tiddlers[t]);
|
||||
content.push(listNode);
|
||||
}
|
||||
return [Renderer.ElementNode("ul",null,content)];
|
||||
|
@ -141,7 +141,7 @@ exports.macro = {
|
||||
)
|
||||
]
|
||||
);
|
||||
content.execute(this.parents,this.store.getTiddler(this.tiddlerTitle));
|
||||
content.execute(this.parents,this.tiddlerTitle);
|
||||
return [content];
|
||||
},
|
||||
refreshInDom: function(changes) {
|
||||
@ -156,7 +156,7 @@ exports.macro = {
|
||||
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));
|
||||
this.content[0].children[1].execute(this.parents,this.tiddlerTitle);
|
||||
this.content[0].children[1].renderInDom(this.content[0].domNode,null);
|
||||
needContentRefresh = false; // Don't refresh the children if we've just created them
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ exports.macro = {
|
||||
{target: story.tiddlers[t].title,template: story.tiddlers[t].template},
|
||||
null,
|
||||
this.store);
|
||||
m.execute(this.parents,this.store.getTiddler(this.tiddlerTitle));
|
||||
m.execute(this.parents,this.tiddlerTitle);
|
||||
content.push(m);
|
||||
}
|
||||
return content;
|
||||
@ -76,7 +76,7 @@ exports.macro = {
|
||||
{target: story.tiddlers[t].title,template: story.tiddlers[t].template},
|
||||
null,
|
||||
this.store);
|
||||
m.execute(this.parents,this.store.getTiddler(story.tiddlers[t].title));
|
||||
m.execute(this.parents,story.tiddlers[t].title);
|
||||
m.renderInDom(this.domNode,this.domNode.childNodes[t]);
|
||||
this.content.splice(t,0,m);
|
||||
} else {
|
||||
|
@ -95,7 +95,7 @@ exports.macro = {
|
||||
}
|
||||
// Execute macros within the content
|
||||
for(t=0; t<contentClone.length; t++) {
|
||||
contentClone[t].execute(parents,this.store.getTiddler(renderTitle));
|
||||
contentClone[t].execute(parents,renderTitle);
|
||||
}
|
||||
// Return the content
|
||||
return contentClone;
|
||||
|
@ -47,12 +47,17 @@ exports.macro = {
|
||||
}
|
||||
switch(this.params.format) {
|
||||
case "link":
|
||||
var link = Renderer.MacroNode("link",
|
||||
{target: value},
|
||||
[Renderer.TextNode(value)],
|
||||
this.store);
|
||||
link.execute(parents,tiddler);
|
||||
return [link];
|
||||
if(value === undefined) {
|
||||
return [];
|
||||
} else {
|
||||
var link = Renderer.MacroNode("link",
|
||||
{target: value},
|
||||
[Renderer.TextNode(value)],
|
||||
this.store);
|
||||
link.execute(parents,this.tiddlerTitle);
|
||||
return [link];
|
||||
}
|
||||
break;
|
||||
case "wikified":
|
||||
if(tiddler && this.params.field === "text") {
|
||||
if(parents.indexOf(tiddler.title) !== -1) {
|
||||
@ -69,7 +74,7 @@ exports.macro = {
|
||||
contentClone.push(content[t].clone());
|
||||
}
|
||||
for(t=0; t<contentClone.length; t++) {
|
||||
contentClone[t].execute(parents,tiddler);
|
||||
contentClone[t].execute(parents,this.tiddlerTitle);
|
||||
}
|
||||
return contentClone;
|
||||
case "date":
|
||||
@ -79,6 +84,7 @@ exports.macro = {
|
||||
} else {
|
||||
return [Renderer.TextNode(utils.formatDateString(value,template))];
|
||||
}
|
||||
break;
|
||||
default: // "text"
|
||||
return [Renderer.TextNode(value)];
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ function stopZoomer(macroNode) {
|
||||
macroNode.inZoomer = false;
|
||||
window.scrollTo(0,newScrollY);
|
||||
document.body.style.webkitTransform = "translateY(" + newScrollY * macroNode.xFactor + "px) " +
|
||||
"scale(" + macroNode.scale + ") " +
|
||||
"translateY(" + ((macroNode.windowHeight / macroNode.scale) - macroNode.bodyHeight) * macroNode.yFactor * macroNode.xFactor + "px)";
|
||||
"scale(" + macroNode.scale + ") " +
|
||||
"translateY(" + ((macroNode.windowHeight / macroNode.scale) - macroNode.bodyHeight) * macroNode.yFactor * macroNode.xFactor + "px)";
|
||||
utils.removeClass(document.body,"in-zoomer");
|
||||
document.body.style.webkitTransform = "translateY(0) scale(1) translateY(0)";
|
||||
}
|
||||
@ -68,8 +68,8 @@ function hoverZoomer(macroNode,x,y) {
|
||||
scale = macroNode.scale,
|
||||
postTranslateY = ((macroNode.windowHeight / macroNode.scale) - macroNode.bodyHeight) * macroNode.yFactor * macroNode.xFactor;
|
||||
var transform = "translateY(" + preTranslateY.toFixed(8) + "px) " +
|
||||
"scale(" + scale.toFixed(8) + ") " +
|
||||
"translateY(" + postTranslateY.toFixed(8) + "px)";
|
||||
"scale(" + scale.toFixed(8) + ") " +
|
||||
"translateY(" + postTranslateY.toFixed(8) + "px)";
|
||||
document.body.style.webkitTransform = transform;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user