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