Configures the given element as an AutoHide widget.

The AutoHide widget automatically hides (and optionally removes) the given element, or children of it that match a given selector, after a certain delay.

It executes these actions every time the matching element(s) have a change of attribute or appear (are inserted) into the DOM.

To use with auto-widgets (HTML API) (see settings.autoWidgets), the following CSS classes or data attributes are recognized:

  • lisn-auto-hide class or data-lisn-auto-hide attribute
  • lisn-auto-remove class or data-lisn-auto-remove attribute (enables AutoHideConfig.remove)

NOTE: This widget supports multiple instances per element, you can specify multiple widget configurations, separated with ";".

See below examples for what values you can use set for the data attributes in order to modify the configuration of the automatically created widget.

This will automatically hide (with class lisn-hide) the element 3 seconds (default delay) after it is inserted into the DOM or after it gets any attributes changed on it (for example that might show it again).

<div class="lisn-auto-hide">
Automatically hidden in 3s.
</div>

This will automatically hide and then remove the element 3 seconds (default delay) after it is inserted into the DOM.

<div class="lisn-auto-remove">
Automatically hidden and removed in 3s.
</div>

This will automatically

  • hide p elements with class message 2 seconds after they are inserted or changed
  • hide p elements with class warning 5 seconds after they are inserted or changed; and it will save that particular AutoHide widget with ID myID so that it can be looked up using AutoHide.get
  • remove p elements with class disposable 3 seconds (default delay) after they are inserted or changed
<div data-lisn-auto-hide="selector=p.message delay=2000 ;
selector=p.warning delay=5000 id=myID"
data-lisn-auto-remove="selector=p.disposable">
<p>Some text, this will stay.</p>
<p class="message">
Automatically hidden in 2s.
</p>
<p class="warning">
Automatically hidden in 5s.
</p>
<p class="disposable">
Automatically hidden and removed in 3s.
</p>
</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.

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.

toggleEnable: () => Promise<void>

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