mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-02 14:32:53 +00:00
Updated slider macro to have a refresh method
This commit is contained in:
parent
a0524c2144
commit
e4dd63d089
@ -16,37 +16,50 @@ exports.macro = {
|
|||||||
name: "slider",
|
name: "slider",
|
||||||
types: ["text/html","text/plain"],
|
types: ["text/html","text/plain"],
|
||||||
params: {
|
params: {
|
||||||
state: {byPos: 0, type: "text"},
|
state: {byPos: 0, type: "tiddler"},
|
||||||
targetTiddler: {byPos: 1, type: "tiddler"},
|
targetTiddler: {byPos: 1, type: "tiddler"},
|
||||||
label: {byPos: 2, type: "text"},
|
label: {byPos: 2, type: "text"},
|
||||||
tooltip: {byPos: 3, type: "text"}
|
tooltip: {byPos: 3, type: "text"}
|
||||||
},
|
},
|
||||||
events: {
|
events: {
|
||||||
click: function(event,macroNode) {
|
click: function(event,macroNode) {
|
||||||
|
if(event.target === event.currentTarget.firstChild.firstChild) {
|
||||||
var el = event.currentTarget.firstChild.firstChild.nextSibling,
|
var el = event.currentTarget.firstChild.firstChild.nextSibling,
|
||||||
stateTiddler = macroNode.params.state ? macroNode.store.getTiddler(macroNode.params.state) : {text: ""},
|
stateTiddler = macroNode.params.state ? macroNode.store.getTiddler(macroNode.params.state) : null;
|
||||||
isOpen = stateTiddler.text.trim() === "open";
|
stateTiddler = stateTiddler || new Tiddler({title: macroNode.params.state, text: ""});
|
||||||
|
var isOpen = stateTiddler.text.trim() === "open";
|
||||||
macroNode.store.addTiddler(new Tiddler(stateTiddler,{text: isOpen ? "closed" : "open"}));
|
macroNode.store.addTiddler(new Tiddler(stateTiddler,{text: isOpen ? "closed" : "open"}));
|
||||||
el.style.display = isOpen ? "none" : "block";
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return false;
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
execute: function(macroNode,tiddler,store) {
|
execute: function(macroNode,tiddler,store) {
|
||||||
var stateTiddler = macroNode.params.state ? store.getTiddler(macroNode.params.state) : {text: ""},
|
var isOpen = macroNode.params.state ? store.getTiddlerText(macroNode.params.state,"").trim() === "open" : true,
|
||||||
isOpen = stateTiddler.text.trim() === "open",
|
|
||||||
target = macroNode.params.targetTiddler,
|
target = macroNode.params.targetTiddler,
|
||||||
dependencies = new Dependencies();
|
dependencies = new Dependencies();
|
||||||
dependencies.addDependency(target,true);
|
dependencies.addDependency(target,true);
|
||||||
var content = Renderer.SliderNode(macroNode.params.state,
|
var content = Renderer.SliderNode(macroNode.params.state,
|
||||||
macroNode.params.label,
|
macroNode.params.label ? macroNode.params.label : target,
|
||||||
macroNode.params.tooltip,
|
macroNode.params.tooltip,
|
||||||
isOpen,
|
isOpen,
|
||||||
[
|
[
|
||||||
Renderer.MacroNode("tiddler",{target: target},null,dependencies,store)
|
Renderer.MacroNode("tiddler",{target: target},null,dependencies,store)
|
||||||
]);
|
]);
|
||||||
content.execute(tiddler);
|
content.execute(macroNode.parents,tiddler);
|
||||||
return [content];
|
return [content];
|
||||||
|
},
|
||||||
|
refresh: function(changes,macroNode,tiddler,store) {
|
||||||
|
if(macroNode.params.target && changes.hasOwnProperty(macroNode.params.target) !== -1) {
|
||||||
|
// If the target has changed, re-render the macro
|
||||||
|
} else if (macroNode.params.state && changes.hasOwnProperty(macroNode.params.state) !== -1) {
|
||||||
|
// If it was just the state tiddler that's changed, set the display appropriately
|
||||||
|
var el = macroNode.domNode.firstChild.firstChild.nextSibling,
|
||||||
|
isOpen = macroNode.store.getTiddlerText(macroNode.params.state,"").trim() === "open";
|
||||||
|
el.style.display = isOpen ? "block" : "none";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,3 +3,7 @@ title: SliderTests
|
|||||||
The status of this slider is stored in the tiddler JackSlider:
|
The status of this slider is stored in the tiddler JackSlider:
|
||||||
<<slider JackSlider "Motovun Jack.jpg" "TiddlyWiki Kitten" "See the kitten">>
|
<<slider JackSlider "Motovun Jack.jpg" "TiddlyWiki Kitten" "See the kitten">>
|
||||||
|
|
||||||
|
And here's another slider that is also keyed to JackSlider (<<slider JackSlider "HelloThere">>), this time inline.
|
||||||
|
|
||||||
|
And here's another slider that contains a video:
|
||||||
|
<<slider VideoSlider "VideoTests">>
|
||||||
|
Loading…
Reference in New Issue
Block a user