TW5 Equivalent of displayTiddler

169 views
Skip to first unread message

RunningUtes

unread,
Mar 3, 2014, 11:21:43 PM3/3/14
to tiddly...@googlegroups.com
I am looking for the TW5 equivalent to the javascript function "javascript:story.displayTiddler(null,'TiddlerName');" that is found in TWC

Any ideas? The goal is to open a specific tiddler using javascript.

Thanks,
Michael

Jeremy Ruston

unread,
Mar 4, 2014, 3:16:55 AM3/4/14
to TiddlyWikiDev
Hi Michael

> The goal is to open a specific tiddler using javascript.

There isn't a precise equivalent to the old TWC displayTiddler() function. What you need to do instead depends on the context:

* Within a widget you can use the tw-navigate message to open a tiddler
* Elsewhere, you can modify the $:/StoryList tiddler to add the new tiddler to the list, which will cause the on-screen story to automatically refresh to include the new tiddler

Can you explain a little more about the context?

Best wishes

Jeremy.




--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/groups/opt_out.



--
Jeremy Ruston
mailto:jeremy...@gmail.com

RunningUtes

unread,
Mar 4, 2014, 11:38:03 AM3/4/14
to tiddly...@googlegroups.com, jeremy...@gmail.com
Specifically, I am trying to create an ImageMap with locations that will use the TWC displayTiddler() function to open a tiddler.  I thought that I saw a function in the TW5 core to open a tiddler when I reviewed it in the past, but I can't find anything currently.

Any ideas of a workaround?
~Michael

Jeremy Ruston

unread,
Mar 5, 2014, 4:20:34 AM3/5/14
to RunningUtes, TiddlyWikiDev
Hi Michael

On Tue, Mar 4, 2014 at 4:38 PM, RunningUtes <Runni...@gmail.com> wrote:
Specifically, I am trying to create an ImageMap with locations that will use the TWC displayTiddler() function to open a tiddler.  I thought that I saw a function in the TW5 core to open a tiddler when I reviewed it in the past, but I can't find anything currently.

OK, a reasonable approach would be to create an <$imagemap> widget that displays the image map according to attributes that you provide (eg, an attribute to specify the image tiddler, and another attribute to specify the tiddler containing the map of clickable areas). Then your widget would trap click events on the image, and turn them into tw-navigate messages to actually do the navigation.

A good place to start is Chris Hunt's guide to writing widgets for TW5:


Best wishes

Jeremy.

Tobias Beer

unread,
Dec 2, 2014, 4:04:22 PM12/2/14
to tiddly...@googlegroups.com, jeremy...@gmail.com
> Elsewhere, you can modify the $:/StoryList tiddler to add the new tiddler to the list, which will cause the on-screen story to automatically refresh to include the new tiddler

Please, be so kind as to provide the required code to do this in js.

Best wishes, Tobias.

Jeremy Ruston

unread,
Dec 2, 2014, 7:14:10 PM12/2/14
to Tobias Beer, TiddlyWikiDev
Hi Tobias

You could use something like this:

// Get the existing story list
var storyTitle = "$:/StoryList",
newTiddlerTitle = "My newly displayed tiddler",
storyList = $tw.wiki.getTiddlerList(storyTitle);
// Add our tiddler if it's not already present
if(storyList.indexOf(newTiddlerTitle) === -1) {
storyList.unshift(newTiddlerTitle);
}
// Save the modified story list
$tw.wiki.addTiddler(new $tw.Tiddler(
{title: storyTitle},
$tw.wiki.getTiddler(storyTitle),
{list: storyList}
));

Best wishes

Jeremy.

Tobias Beer

unread,
Dec 2, 2014, 8:24:42 PM12/2/14
to tiddly...@googlegroups.com, beert...@gmail.com, jeremy...@gmail.com
Thanks, Jeremy!

Now, how do I turn this into a bookmarklet? :)

Tobias Beer

unread,
Dec 2, 2014, 8:26:07 PM12/2/14
to tiddly...@googlegroups.com, beert...@gmail.com, jeremy...@gmail.com
Would be cool if there was some $tw.utils.bookmarkify() :D

Best wishes, Tobias.

Danielo Rodríguez

unread,
Dec 3, 2014, 4:30:36 PM12/3/14
to tiddly...@googlegroups.com
Hello Tobias ,

You asked for the code to do this and then you asked that code to be turned into a bookmarket. Maybe it's a good exercise to try it yourself. I understand that you ask when you don't know how to do something,but this is on GitHub, on the navigator widget. Check it out, you will probably learn a lot.

Tobias Beer

unread,
Dec 3, 2014, 5:25:54 PM12/3/14
to tiddly...@googlegroups.com
Hi Danielo,
 
You asked for the code to do this and then you asked that code to be turned into a bookmarket.

Mhhh, I didn't want to turn a new displayTiddler function into a bookmarklet.
I simply wanted to use a function I used fairly often in TWc ...and now I have ...implemented it thanks to Jeremy in useful code that can be run as a bookmarklet.
 
Maybe it's a good exercise to try it yourself. I understand that you ask when you don't know how to do something,but this is on GitHub, on the navigator widget. Check it out, you will probably learn a lot.

As said, I was roaming the core for an hour or so to find out how what once was displayTiddler would be done in tw5, without much luck. So, the feedback from Jeremy was rather valuable. I'm not a fan of reverse engineering... I leave that to people who rejoice in that exercise. ^^

So, thanks to Stephan's input, the bookmarking know-how is now internalized ...learned a lot, i.e. that there's little need for any core bookmarkify(), afaics.


Best wishes, Tobias. 
Reply all
Reply to author
Forward
0 new messages