Catching system events

Is there a TW mechanism to catch system events and hook in some of my own action widgets?

For instance, I have a wiki for organizing a large collection of external links. I have a custom new button that launches an edit tiddler; the user fills out various metadata about the document in question, and saves. One of the fields is Author(s). When the user saves this link tiddler, I’d like to scan the Authors and automatically create tiddlers – with the tag Author – for each of them that doesn’t already exist. Ideally I’d like to launch them into the story river as well.

But I don’t know how to connect that simple action to TW’s save button. Is this something simple that I’ve missed? Is it tricky and hidden in a don’t-do-this-until-we-tell-you-you’re-ready section? Is it simply not supported?

Any suggestions?

At the wiki text level you would do this by creating a custom save button that saves the tiddler in question and performs additional actions.

At the JavaScript level you can use the th-saving-tiddler hook to invoke additional actions. I tend to have hooks that invoke actions from tiddlers with a specific tag using this mechanism. We do not yet have wikitext affordances for such hooks, partly since doing so consistently involves a rewrite of the navigation mechanism.

Oh, of course! I do plenty of alterations to the View interface, but outside a few field editors, I have treated the default Edit interface as sacrosanct. I will look into details of how to do this; it doesn’t sound too hard.

I do forget to look at that developer documentation, unless I’m looking to contribute back to the core. This method sounds like it might be a good fit for my skills. I’m very used to doing event-driven coding. A question that doesn’t seem to be answered by the existing documentation: where does a call to $tw.hooks.addHook(name, handler); go? Into a StartupAction? (Even then I don’t know how to get JS to run.) Into a tiddler with an specific module-type? Something else?

As I seem to say pretty often to you, thanks again for your help!

A module with type startup. Here is an example for a different hook:

1 Like