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-19 17:24:01 +00:00
|
|
|
state: {byPos: 0, type: "tiddler"},
|
2012-02-17 17:32:32 +00:00
|
|
|
targetTiddler: {byPos: 1, type: "tiddler"},
|
|
|
|
label: {byPos: 2, type: "text"},
|
|
|
|
tooltip: {byPos: 3, type: "text"}
|
2012-01-23 18:31:17 +00:00
|
|
|
},
|
2012-02-02 17:48:09 +00:00
|
|
|
events: {
|
2012-02-16 20:38:10 +00:00
|
|
|
click: function(event,macroNode) {
|
2012-02-19 17:24:01 +00:00
|
|
|
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;
|
|
|
|
}
|
2012-02-02 17:48:09 +00:00
|
|
|
}
|
|
|
|
},
|
2012-02-16 20:38:10 +00:00
|
|
|
execute: function(macroNode,tiddler,store) {
|
2012-02-19 17:24:01 +00:00
|
|
|
var isOpen = macroNode.params.state ? store.getTiddlerText(macroNode.params.state,"").trim() === "open" : true,
|
2012-02-20 18:05:10 +00:00
|
|
|
target = macroNode.params.targetTiddler;
|
2012-02-17 12:36:39 +00:00
|
|
|
var content = Renderer.SliderNode(macroNode.params.state,
|
2012-02-19 17:24:01 +00:00
|
|
|
macroNode.params.label ? macroNode.params.label : target,
|
2012-02-16 20:38:10 +00:00
|
|
|
macroNode.params.tooltip,
|
2012-02-17 12:36:39 +00:00
|
|
|
isOpen,
|
2012-02-16 20:38:10 +00:00
|
|
|
[
|
2012-02-20 18:05:10 +00:00
|
|
|
Renderer.MacroNode(
|
|
|
|
"tiddler",
|
|
|
|
{target: target},
|
|
|
|
null,
|
|
|
|
store)
|
2012-02-16 20:38:10 +00:00
|
|
|
]);
|
2012-02-19 17:24:01 +00:00
|
|
|
content.execute(macroNode.parents,tiddler);
|
2012-02-16 20:38:10 +00:00
|
|
|
return [content];
|
2012-02-19 17:24:01 +00:00
|
|
|
},
|
|
|
|
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";
|
|
|
|
}
|
2012-01-23 18:31:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|
|
|
|
|