Class ClickTrigger

ClickTrigger allows you to run actions when a user clicks a target element (first time and every other time, i.e. odd number of click), and undo them when a user clicks the target element again (or every even number of clicks). It always acts as a toggle.


To use with auto-widgets (HTML API), see registerTrigger for the specification.

  • Arguments: none
  • Additional trigger options: none
    • target: A string element specification. See getReferenceElement.
    • prevent-default: A boolean.
    • prevent-select: A boolean.

Add classes active and toggled-on when the user clicks the element (first time and every other time, i.e. odd number of click), remove them when clicked again (or even number of click);

<div data-lisn-on-click="@add-class=active,toggled-on"></div>

As above, but using a CSS class instead of data attribute:

<div class="lisn-on-click--@add-class=active,toggled-on"></div>

Play the animations on the element 1000ms after the first time the user clicks it.

<div data-lisn-on-click="@animate +once +delay=1000"></div>

Add class visited the first time the user clicks the element, and play or reverse the animations on the element 1000ms each time the user clicks it.

<div data-lisn-on-click="@add-class=visited +once ;
@animate +delay=1000"
></div>

When the user clicks the next element with class box then add classes c1 and c2 to the element (that the trigger is defined on) and enable trigger my-trigger defined on this same element; undo all of that on even number of clicks on the reference box element.

<div data-lisn-on-click="@add-class=c1,c2 @enable=my-trigger +target=next.box"
data-lisn-on-run="@show +id=my-trigger"
></div>
<div class="box"></div>

As above, but using data-lisn-ref attribute instead of class selector.

<div data-lisn-on-click="@add-class=c1,c2 @enable=my-trigger +target=next-box"
data-lisn-on-run="@show +id=my-trigger"
></div>
<div data-lisn-ref="box"></div>

Hierarchy (View Summary)

Methods

Constructors

Properties

destroy: () => Promise<void>

Undoes all modifications to the element and returns it to its original state.

You will need to recreate it if you want to enable its functionality again.

disable: () => Promise<void>

Disables the functionality of the widget. What this means is specific to each widget.

enable: () => Promise<void>

Re-enables the functionality of the widget. What this means is specific to each widget.

getActions: () => Action[]

Returns the trigger's actions.

getConfig: () => PointerTriggerConfig

Returns the trigger config.

getElement: () => Element

Returns the element passed to the widget constructor.

isDestroyed: () => boolean

Returns true if the widget is destroyed.

isDisabled: () => boolean

Returns true if the widget is currently disabled.

onDestroy: (handler: WidgetHandler) => void

The given handler will be called when the widget is destroyed.

onDisable: (handler: WidgetHandler) => void

The given handler will be called when the widget is disabled.

onEnable: (handler: WidgetHandler) => void

The given handler will be called when the widget is enabled.

reverse: () => Promise<void>

"Undo"es all the Actions linked to the trigger.

run: () => Promise<void>

"Do"es all the Actions linked to the trigger.

toggle: () => Promise<void>

"Toggle"s all the Actions linked to the trigger.

toggleEnable: () => Promise<void>

Re-enables the widget if disabled, otherwise disables it.