Components

Messages

API

Message

Parameters

  • element HTMLElement DOM element for component instantiation and scope

  • options Object (optional, default {})

    • options.closeSelector String Selector for closing the message (optional, default '[data-ecl-message-close]')
    • options.attachClickListener Boolean Whether or not to bind click events (optional, default true)

init

Initialise component.

destroy

Destroy component.

handleClickOnClose

Remove the message component.

autoInit

Parameters

  • root HTMLElement DOM element for component instantiation and scope

  • $1 Object (optional, default {})

    • $1.MESSAGE (optional, default {})

Returns Message An instance of Message.

Setup

There are 2 ways to initialise the component.

Automatic

Add data-ecl-auto-init="Message" attribute to component's markup:

<div
  role="alert"
  class="ecl-message ecl-message--info"
  data-ecl-message
  data-ecl-auto-init="Message"
>
  ...
</div>

Use the ECL library's autoInit() (ECL.autoInit()) when your page is ready or other custom event you want to hook onto.

Manual

Get target element, create an instance and invoke init().

Given you have 1 element with an attribute data-ecl-message on the page:

var elt = document.querySelector('[data-ecl-message]');
var message = new ECL.Message(elt);
message.init();