1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-18 15:54:50 +00:00
TiddlyWiki5/tw2/source/tiddlywiki/js/Tabs.js
Jeremy Ruston a1c8ac624f Added first pass at support for building TiddlyWiki 2.6.x with TW5
There are still some whitespace and attribute ordering issues, but the
result runs correctly.
2012-05-29 22:02:38 +01:00

66 lines
1.9 KiB
JavaScript
Executable File

//--
//-- Tabs macro
//--
config.macros.tabs.handler = function(place,macroName,params)
{
var cookie = params[0];
var numTabs = (params.length-1)/3;
var wrapper = createTiddlyElement(null,"div",null,"tabsetWrapper " + cookie);
var tabset = createTiddlyElement(wrapper,"div",null,"tabset");
tabset.setAttribute("cookie",cookie);
var validTab = false;
var t;
for(t=0; t<numTabs; t++) {
var label = params[t*3+1];
var prompt = params[t*3+2];
var content = params[t*3+3];
var tab = createTiddlyButton(tabset,label,prompt,this.onClickTab,"tab tabUnselected");
createTiddlyElement(tab,"span",null,null," ",{style:"font-size:0pt;line-height:0px"});
tab.setAttribute("tab",label);
tab.setAttribute("content",content);
tab.title = prompt;
if(config.options[cookie] == label)
validTab = true;
}
if(!validTab)
config.options[cookie] = params[1];
place.appendChild(wrapper);
this.switchTab(tabset,config.options[cookie]);
};
config.macros.tabs.onClickTab = function(e)
{
config.macros.tabs.switchTab(this.parentNode,this.getAttribute("tab"));
return false;
};
config.macros.tabs.switchTab = function(tabset,tab)
{
var cookie = tabset.getAttribute("cookie");
var theTab = null;
var nodes = tabset.childNodes;
var t;
for(t=0; t<nodes.length; t++) {
if(nodes[t].getAttribute && nodes[t].getAttribute("tab") == tab) {
theTab = nodes[t];
theTab.className = "tab tabSelected";
} else {
nodes[t].className = "tab tabUnselected";
}
}
if(theTab) {
if(tabset.nextSibling && tabset.nextSibling.className == "tabContents")
jQuery(tabset.nextSibling).remove();
var tabContent = createTiddlyElement(null,"div",null,"tabContents");
tabset.parentNode.insertBefore(tabContent,tabset.nextSibling);
var contentTitle = theTab.getAttribute("content");
wikify(store.getTiddlerText(contentTitle),tabContent,null,store.getTiddler(contentTitle));
if(cookie) {
config.options[cookie] = tab;
saveOption(cookie);
}
}
};