API
Modal
Parameters
elementHTMLElement DOM element for component instantiation and scopeoptionsObject (optional, default{})options.toggleSelectorString Selector for the modal toggle (optional, default'')options.closeSelectorString Selector for closing the modal (optional, default'[data-ecl-modal-close]')options.attachClickListenerBoolean Whether or not to bind click events on toggle (optional, defaulttrue)options.attachKeyListenerBoolean Whether or not to bind keyboard events (optional, defaulttrue)options.scrollSelector(optional, default'[data-ecl-modal-scroll]')
init
Initialise component.
destroy
Destroy component.
checkScroll
Check if there is a scroll and display overflow.
handleClickOnToggle
Toggles between collapsed/expanded states.
Parameters
eEvent
openModal
Open the modal.
closeModal
Close the modal.
handleKeyboardGlobal
Handles global keyboard events, triggered outside of the modal.
Parameters
eEvent
autoInit
Parameters
rootHTMLElement DOM element for component instantiation and scope$1Object (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();
Retrieve an existing instance
If an existing instance needs to be updated, it can be retrieved this way:
var elt = document.querySelector('[data-ecl-modal]');
var instance = ECL.components.get(elt);
To update an existing instance, you can run destroy() and init() on this instance, like this:
instance.destroy();
instance.init();