API
Modal
Parameters
element
HTMLElement DOM element for component instantiation and scopeoptions
Object (optional, default{}
)options.toggleSelector
String Selector for the modal toggle (optional, default''
)options.closeSelector
String Selector for closing the modal (optional, default'[data-ecl-modal-close]'
)options.attachClickListener
Boolean Whether or not to bind click events on toggle (optional, defaulttrue
)options.attachKeyListener
Boolean Whether or not to bind keyboard events (optional, defaulttrue
)
init
Initialise component.
destroy
Destroy component.
handleClickOnToggle
Toggles between collapsed/expanded states.
Parameters
e
Event
openModal
Open the modal.
closeModal
Close the modal.
handleKeyboardGlobal
Handles global keyboard events, triggered outside of the modal.
Parameters
e
Event
autoInit
Parameters
root
HTMLElement DOM element for component instantiation and scope$1
Object (optional, default{}
)$1.MODAL
(optional, default{}
)
Returns Modal An instance of Modal.
Setup
There are 2 ways to initialise the component.
Automatic
Add data-ecl-auto-init="Modal"
attribute to component's markup:
<div class="ecl-modal" data-ecl-modal data-ecl-auto-init="Modal">...</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-modal
on the page:
var elt = document.querySelector('[data-ecl-modal]');
var modal = new ECL.Modal(elt);
modal.init();