2012-01-23 18:31:17 +00:00
|
|
|
/*\
|
|
|
|
title: js/macros/slider.js
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true */
|
|
|
|
"use strict";
|
|
|
|
|
2012-02-16 20:38:10 +00:00
|
|
|
var Renderer = require("../Renderer.js").Renderer,
|
2012-02-17 14:11:25 +00:00
|
|
|
Dependencies = require("../Dependencies.js").Dependencies,
|
2012-02-17 12:36:39 +00:00
|
|
|
Tiddler = require("../Tiddler.js").Tiddler,
|
2012-02-06 11:31:23 +00:00
|
|
|
utils = require("../Utils.js");
|
2012-01-23 18:31:17 +00:00
|
|
|
|
|
|
|
exports.macro = {
|
|
|
|
name: "slider",
|
|
|
|
types: ["text/html","text/plain"],
|
|
|
|
params: {
|
2012-02-17 12:36:39 +00:00
|
|
|
state: {byPos: 0, type: "text", optional: false},
|
2012-01-23 18:31:17 +00:00
|
|
|
targetTiddler: {byPos: 1, type: "tiddler", optional: false},
|
|
|
|
label: {byPos: 2, type: "text", optional: false},
|
|
|
|
tooltip: {byPos: 3, type: "text", optional: true}
|
|
|
|
},
|
2012-02-02 17:48:09 +00:00
|
|
|
events: {
|
2012-02-16 20:38:10 +00:00
|
|
|
click: function(event,macroNode) {
|
2012-02-17 12:36:39 +00:00
|
|
|
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";
|
2012-02-02 17:48:09 +00:00
|
|
|
event.preventDefault();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
2012-02-16 20:38:10 +00:00
|
|
|
execute: function(macroNode,tiddler,store) {
|
2012-02-17 12:36:39 +00:00
|
|
|
var stateTiddler = macroNode.params.state ? store.getTiddler(macroNode.params.state) : {text: ""},
|
|
|
|
isOpen = stateTiddler.text.trim() === "open",
|
|
|
|
target = macroNode.params.targetTiddler,
|
2012-02-17 14:11:25 +00:00
|
|
|
dependencies = new Dependencies();
|
|
|
|
dependencies.addDependency(target,true);
|
2012-02-17 12:36:39 +00:00
|
|
|
var content = Renderer.SliderNode(macroNode.params.state,
|
2012-02-16 20:38:10 +00:00
|
|
|
macroNode.params.label,
|
|
|
|
macroNode.params.tooltip,
|
2012-02-17 12:36:39 +00:00
|
|
|
isOpen,
|
2012-02-16 20:38:10 +00:00
|
|
|
[
|
|
|
|
Renderer.MacroNode("tiddler",{target: target},null,dependencies,store)
|
|
|
|
]);
|
|
|
|
content.execute(tiddler);
|
|
|
|
return [content];
|
2012-01-23 18:31:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|
|
|
|
|