mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-23 07:26:54 +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",
|
||||
types: ["text/html","text/plain"],
|
||||
params: {
|
||||
state: {byPos: 0, type: "text"},
|
||||
state: {byPos: 0, type: "tiddler"},
|
||||
targetTiddler: {byPos: 1, type: "tiddler"},
|
||||
label: {byPos: 2, type: "text"},
|
||||
tooltip: {byPos: 3, type: "text"}
|
||||
},
|
||||
events: {
|
||||
click: function(event,macroNode) {
|
||||
var el = event.currentTarget.firstChild.firstChild.nextSibling,
|
||||
stateTiddler = macroNode.params.state ? macroNode.store.getTiddler(macroNode.params.state) : {text: ""},
|
||||
isOpen = stateTiddler.text.trim() === "open";
|
||||
macroNode.store.addTiddler(new Tiddler(stateTiddler,{text: isOpen ? "closed" : "open"}));
|
||||
el.style.display = isOpen ? "none" : "block";
|
||||
event.preventDefault();
|
||||
return false;
|
||||
if(event.target === event.currentTarget.firstChild.firstChild) {
|
||||
var el = event.currentTarget.firstChild.firstChild.nextSibling,
|
||||
stateTiddler = macroNode.params.state ? macroNode.store.getTiddler(macroNode.params.state) : null;
|
||||
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"}));
|
||||
event.preventDefault();
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
},
|
||||
execute: function(macroNode,tiddler,store) {
|
||||
var stateTiddler = macroNode.params.state ? store.getTiddler(macroNode.params.state) : {text: ""},
|
||||
isOpen = stateTiddler.text.trim() === "open",
|
||||
var isOpen = macroNode.params.state ? store.getTiddlerText(macroNode.params.state,"").trim() === "open" : true,
|
||||
target = macroNode.params.targetTiddler,
|
||||
dependencies = new Dependencies();
|
||||
dependencies.addDependency(target,true);
|
||||
var content = Renderer.SliderNode(macroNode.params.state,
|
||||
macroNode.params.label,
|
||||
macroNode.params.label ? macroNode.params.label : target,
|
||||
macroNode.params.tooltip,
|
||||
isOpen,
|
||||
[
|
||||
Renderer.MacroNode("tiddler",{target: target},null,dependencies,store)
|
||||
]);
|
||||
content.execute(tiddler);
|
||||
content.execute(macroNode.parents,tiddler);
|
||||
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:
|
||||
<<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