diff --git a/js/macros/slider.js b/js/macros/slider.js index 620857c2d..65105e2ca 100644 --- a/js/macros/slider.js +++ b/js/macros/slider.js @@ -8,32 +8,39 @@ title: js/macros/slider.js "use strict"; var Renderer = require("../Renderer.js").Renderer, + Tiddler = require("../Tiddler.js").Tiddler, utils = require("../Utils.js"); exports.macro = { name: "slider", types: ["text/html","text/plain"], params: { - name: {byPos: 0, type: "text", optional: false}, + state: {byPos: 0, type: "text", optional: false}, targetTiddler: {byPos: 1, type: "tiddler", optional: false}, label: {byPos: 2, type: "text", optional: false}, tooltip: {byPos: 3, type: "text", optional: true} }, events: { click: function(event,macroNode) { - var el = event.currentTarget.firstChild.firstChild.nextSibling; - el.style.display = el.style.display === "block" ? "none" : "block"; + 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; } }, execute: function(macroNode,tiddler,store) { - var target = macroNode.params.targetTiddler, + var stateTiddler = macroNode.params.state ? store.getTiddler(macroNode.params.state) : {text: ""}, + isOpen = stateTiddler.text.trim() === "open", + target = macroNode.params.targetTiddler, dependencies = {include: {}}; dependencies.include[target] = 1; - var content = Renderer.SliderNode(macroNode.params.name, + var content = Renderer.SliderNode(macroNode.params.state, macroNode.params.label, macroNode.params.tooltip, + isOpen, [ Renderer.MacroNode("tiddler",{target: target},null,dependencies,store) ]);