If I have a tiddler with a link <a href="#Another">Another tiddler</a>, then clicking it will load the other tiddler. However, if I navigate normally (through wiki links) to another tiddler and back to the first, then clicking the link now doesn’t work. The problem is that the first click added the anchor to the navigation of the browser (I’m using the single file TW5), so now another click is a nop. (If I have another such anchor link it will navigate to the other tiddler).
My use case is that I use the viz (graphviz) plugin and I want the nodes to have links to tiddlers.
Is there a trick to fix this? Maybe something that listens to tiddler navigation events and then removes the anchor from the browser navigation?
As you discovered, <a href="#Another">Another tiddler</a> doesn’t fully replicate the behaviour of a normal tiddler link. The issue is that the browser doesn’t report the location hash as having changed if you click a link that points to the existing location hash.
You can work around it with the event catcher widget. We trap clicks on <a> tags that include an href attribute starting with #. The click handler uses the variable dom-href that is set by the eventcatcher to the value of the href attribute. It then navigates to the target of the link without the #.
Thank you. But, as I mentioned, I need to use this in graphviz. So whatever href I pass to it gets rendered as part of the SVG it produces and I cannot wrap it i event catchers. Is there another alternative?
If you are using the $:/plugins/chanilino/viz plugin you can try wrapping the eventcatcher widget around the entire $viz widget and the svg that it renders.
Hi @Ittayd perhaps try inserting a <$action-log/> widget inside click-actions so that you can inspect the variables that are being passed. In particular, you could verify that the link HREF ends up in the variable dom-hred.
Yes, the tiddler ‘bar’ opens, that was not the issue. The issue is that the ‘#bar’ remains in the address line and so navigating to another tiddler and then back to clicking the ellipsis will not navigate to ‘bar’ again.
Note that you don’t use ‘*|’ before href in the selector, so no event is caught and nothing happens.
Could it be a browser difference (I’m using Chrome)?
Do you see the anchor gets removed?
Maybe there’s a difference between a verbatim svg and one that is rendered by a widget?
Changing the selector to svg a triggers the crash on Chrome since nodes inside SVG elements don’t have the DOM properties that eventcatcher tries to read and assign as variables.
@jeremyruston I am away this week without a laptop so cannot debug systematically. I do get the error in TW 5.2.2 using your code but not in 5.2.3 pre-release.
Apologies for my ineptitude on the subject of discussion groups and use of tiddlywiki in general but I have this problem as well i.e Anchors can only be used once. My anchors look like this:
I would not know how to proceed correctly to wrap the svg in the event catcher but I have an idea how to, but I seem to have a different layout and would not be sure of the alteration to the code. I am new to tiddlywiki and do not yet understand the use of widgets yet.
Any help would be appreciated; I am delighted with the product which I am using to make a family history.
Peter