find open tab using tabs macro

12 views
Skip to first unread message

Jazz

unread,
Aug 24, 2010, 5:26:52 AM8/24/10
to TiddlyWiki
I have a tiddler that uses the core tabs macro.
I want to write a macro, running in the same tiddler, or running from
another tiddler, that retrieves the label, and content of the current
tab.
I don't know how it's done.

Cheers

PMario

unread,
Aug 25, 2010, 4:48:21 AM8/25/10
to TiddlyWiki
<<tabs txtMyTabs "Tab1" "helpTextTab1" Tab1 ...>>
txtMyTabs is a cookie and contains the actual label

<<option txtMyTabs>>
gets config.options.txtMyTabs and displays it.

A tricky tiddler transclusion can get the tiddler text

<<tiddler {{tiddler.title+"##code"}} with:
{{store.getTiddlerText(config.options.txtMyTabs)}}>>

and a code section reders it.
{{{
!code
$1
!end
}}}

All togehter can be seen at:
http://hoster.peermore.com/recipes/TeamWork/tiddlers.wiki#TabsTest
Tab1 Tab2

The problem is, that there is no autorefresh if you change the tab. I
think for this hijacking the tabs core click function is needed.
Teamwork is open for editing. so If someone has a good idea.

have fun!
-m

Jazz

unread,
Aug 27, 2010, 3:44:39 AM8/27/10
to TiddlyWiki
Thank you,

I have tried and that is great, I wish I could use the tab name (i.e.
the tiddler title) as opposed to the label. But at least that will get
me out of the woods for now.

so thank you thank you thank you

Jazz

unread,
Aug 31, 2010, 9:48:55 AM8/31/10
to TiddlyWiki
In the end, I have something like that:
which works only if I have one tiddler with tabs. As soon as I get
two, this fails... Any ideas?
It fails because
1) I don't know how best to catch values in the function that belongs
to the button. So if you press the button, the only way (I have) to
know which button this is coming from is through the ID of the button.
This is hard-wired as "buttonMagic" so, if another tiddler has a
button with ID buttonMagic, this fails.
2) I think there will be another problem because at the minute if two
tiddlers are using the tabs, I believe they will overwrite each
other's cookie.

[...]
config.macros.doSomething.handler = function
(place,macroName,params,wikifier,paramString,tiddler)
{
var par=
{
tiddler_title: tiddler.title
}

createTiddlyButton(place, this.label, this.prompt,
function ()
{
[...]
var _sug =
document.getElementById("buttonMagic").attributes;
var
query=store.getTiddlerText(tabNameFromTabLabel(_sug.getNamedItem("tiddler_title").value,
config.options.txtMyTabs));
[...]

}, "button", "buttonMagic", null, par);
}

// return the actual tiddler NAME not the LABEL on the tab
function tabNameFromTabLabel(title, label)
{
if(label == "My Label")
{
return title+"_mylabel";
}
[...]
}

Jazz

unread,
Aug 31, 2010, 11:43:27 AM8/31/10
to TiddlyWiki


Sort of solved the issue for now. There is now one cookie per tiddler
that has the tab (the name is built from a fixed prefix, and the
suffix is the title of the tiddler). This means that I can get the
open tab for the tiddler which had its button clicked. It does not
look very nice, but it works.

config.macros.doSomething.handler = function
(place,macroName,params,wikifier,paramString,tiddler)
{
var par=
{
tiddler_title: tiddler.title
}
createTiddlyButton(place, this.label, this.prompt,
function ()
{
[...]
var _sug =
document.getElementById("buttonMagic").attributes;
var tiddler_title =
_sug.getNamedItem("tiddler_title").value;
var open_tab="";

for(i in config.options)
{
if(i.match(tiddler_title+"$")==tiddler_title)
{
open_tab=config.options[i];
}
}
var
query=store.getTiddlerText(tabNameFromTabLabel(tiddler_title,
open_tab));
Reply all
Reply to author
Forward
0 new messages