Javascript to open tiddler

33 views
Skip to first unread message

andrewg_oz

unread,
Jul 9, 2022, 3:30:01 AMJul 9
to TiddlyWiki
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?

BJ

unread,
Jul 9, 2022, 10:12:28 AMJul 9
to TiddlyWiki
from within a widget/macro use

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

BJ

unread,
Jul 9, 2022, 2:13:06 PMJul 9
to TiddlyWiki
or maybe
this.dispatchEvent({type: "tm-navigate", navigateTo:tids[i]});

andrewg_oz

unread,
Jul 10, 2022, 9:29:53 AMJul 10
to TiddlyWiki
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...

Saq Imtiaz

unread,
Jul 10, 2022, 10:01:50 AMJul 10
to TiddlyWiki
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)
Message has been deleted

BJ

unread,
Jul 10, 2022, 2:26:30 PMJul 10
to TiddlyWiki
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.

andrewg_oz

unread,
Jul 11, 2022, 12:35:54 AMJul 11
to TiddlyWiki
That's done the trick! Thanks.

Now in action (see "Selection Example"):

Reply all
Reply to author
Forward
0 new messages