Replacing button action with condition

Hi,

I’m using Saq’s Spotlight for an image gallery and this is activated by a button.

\define spotlight-actions()
<$action-spotlight
	$images=" "

	$start=""
	$labels=" "
	autoslide="true"
	class="fancycustomclass"
/>
\end

<$button actions=<<spotlight-actions>> >open lightbox</$button> 

Instead of a button, I’d like to open the gallery when a condition is met e.g.

<% if [<now DDD>match[Wednesday]]%>

<% endif %>

Is this possible?

Thanks
Jon

I don’t the spotlight action widget. However, maybe this might help:

https://tiddlywiki.com/#ActionNavigateWidget

Thanks, I did have a look at that but it seems to be based on a button click and that’s the action I want to replace.

That’s right. Just call it in your spotlight-actions() code (with your conditional, of course).

I am not sure if StartupActions may be what you want. But action-widgets can only be activated with user interaction.


I do have an experimental trigger-actions plugin, where the action is activated, whenever it is rendered.

Warning: It is possible to create endless loops if done wrong. – So Backup – Backup – Backup

\procedure test()
<!-- do something -->
\end

<$trigger actions=<<test>>/>

Just to clarify what I’m trying to do.

If I use Saq’s Swifty slider, I can put that in a tiddler called ‘Gallery autoplay’ and then I have a series of conditions, which once met from my data input during the week, will automatically open the tiddler and using $:/tags/AboveStory, the gallery will pop up above everything else.

<% if [<now DDD>match[Wednesday]]%>
...
...
...

{{Gallery autoplay}}

<% endif %>

So, this works fine but the Spotlight option would give a better result. It’s just the button activation is the problem.

At first glance, your plugin might be a bit advanced for me, but I’ll have a go and failing that, I can stick to the Swifty Slider option and work with that.

Thanks
Jon

Very basic user here :woozy_face:

Yea. This should probably do it. But I did not test it. As I wrote. Backup first.

<% if [<now DDD>match[Wednesday]]%>
  <$trigger actions=<<spotlight-actions>>/>
<% endif %>

That does work - thanks!

From your description, it sounds like your widget could be Kryptonite to wikis!

If I just use it for this use case without any further changes - will I be safe? :cold_sweat:

If it works – your code should be safe. But you should still give it a proper test. Make a backup and try to break it – Just for testing. If you can not break it, it should be safe.

If you can break it, you have learned what you should avoid :wink:

It’s a disclaimer, because the trigger-widget can cause problems with endless loops. Which in turn can make the browser unresponsive and can lead to data loss. That’s why I need to make it clear.

Especially while developing, when variables are undefined because of a typo and so on – hickups can happen.

You should avoid eg:

  • In tiddler A you trigger “open tiddler B”
  • In tiddler B you trigger an action that modifies tiddler A
  • Modifying tiddler A will re-render it
  • Rendering tiddler A will trigger the widget → :boom:

That’s why action-widgets by default need to be manually triggered with buttons.

hope that makes sense

OK, will do.

(Phew! I’ll take off the safety specs)

Many thanks
Jon

Will it trigger multiple times when tiddler refresh by typing in other edit mode tiddler or state tiddler change?

I think a safer approach is listen on th-xxx, if there is a hook for opening tiddler.

The trigger widget needs the “context” of the widget-tree, where it lives in. Eg: If trigger is inside a $let-widget it needs to have access to the variables defined by let. So if one of those variables are changed, the widget will trigger. – That’s intended.

The trigger widget was created, to run automated UI tests in the browser, without user interaction.