[tw5] Javascript to open tiddler

I’ve recently been experimenting with using Google Charts in TiddlyWiki. It’s going quite well (see my other thread), but I can’t work out how to open a tiddler in javascript (i.e. the Google Chart selection handler) without using window.location = ‘#’ + tiddlerNameHere;

That works, but sets the address bar and looks ugly. I’m sure there’s a better way.

Can anyone help?

from within a widget/macro use

this.caller.dispatchEvent({type: “tm-navigate”, navigateTo:tids[i]});

or maybe

this.dispatchEvent({type: “tm-navigate”, navigateTo:tids[i]});

Thanks for your suggestions. Unfortunately, I left out some important details in my OP and so I’m still trying things.

The Google Charts are generated in an iframe, which is where the selection handler is. It means the handler is not in the context of the widget/macro, so ‘this’ isn’t meaningful.

I can access ‘window.parent.$tw’ and I’ve seen code fragments that make it look like I should be able to do the following:

window.parent.$tw.rootWidget.dispatchEvent( { type:‘tm-navigate’, navigateTo: ‘Tiddler Name Here’ } );

Nothing happens.

I’ve tried a couple of other event properties too: setting ‘param’ the same as ‘navigateTo’, and setting ‘navigateFromTitle’ to the name of the tiddler hosting the macro call. Nothing for those either. Not even error messages in the console.

Thanks again for your help. Hoping you or anyone else might have some new ideas…

Assuming you want to open the tiddler in the default story river, try this:

let actions=’<$navigator story="$:/StoryList" history="$:/HistoryList">
<$action-navigate $to=“TiddlerNameHere”/>
</$navigator>

window.parent.$tw.rootWidget.invokeActionString(actions,this)

messages travel up the widget tree, and the navigation widget down from the rootwidget so it will not get the navigation message.

messages travel up the widget tree, and the navigation widget is down the tree from the rootwidget so it will not get the navigation message posted at the rootwidget.

That’s done the trick! Thanks.

Now in action (see “Selection Example”):

http://www.scss.com.au/family/andrew/tiddlywiki/GoogleCharts.html

1 Like