API
Gallery
Parameters
elementHTMLElement DOM element for component instantiation and scopeoptionsObject (optional, default{})options.galleryItemSelectorString Selector for gallery element (optional, default'[data-ecl-gallery-item]')options.descriptionSelectorString Selector for gallery description element (optional, default'[data-ecl-gallery-description]')options.metaSelectorString Selector for gallery meta info element (optional, default'[data-ecl-gallery-meta]')options.closeButtonSelectorString Selector for close button element (optional, default'[data-ecl-gallery-close]')options.overlaySelectorString Selector for gallery overlay element (optional, default'[data-ecl-gallery-overlay]')options.overlayHeaderSelectorString Selector for gallery overlay header element (optional, default'[data-ecl-gallery-overlay-header]')options.overlayFooterSelectorString Selector for gallery overlay footer element (optional, default'[data-ecl-gallery-overlay-footer]')options.overlayMediaSelectorString Selector for gallery overlay media element (optional, default'[data-ecl-gallery-overlay-media]')options.overlayCounterCurrentSelectorString Selector for gallery overlay current number element (optional, default'[data-ecl-gallery-overlay-counter-current]')options.overlayCounterMaxSelectorString Selector for display of number of elements in the gallery overlay (optional, default'[data-ecl-gallery-overlay-counter-max]')options.overlayDownloadSelectorString Selector for gallery overlay download element (optional, default'[data-ecl-gallery-overlay-download]')options.overlayShareSelectorString Selector for gallery overlay share element (optional, default'[data-ecl-gallery-overlay-share]')options.overlayDescriptionSelectorString Selector for gallery overlay description element (optional, default'[data-ecl-gallery-overlay-description]')options.overlayMetaSelectorString Selector for gallery overlay meta info element (optional, default'[data-ecl-gallery-overlay-meta]')options.overlayPreviousSelectorString Selector for gallery overlay previous link element (optional, default'[data-ecl-gallery-overlay-previous]')options.overlayNextSelectorString Selector for gallery overlay next link element (optional, default'[data-ecl-gallery-overlay-next]')options.attachClickListenerBoolean Whether or not to bind click events (optional, defaulttrue)options.attachKeyListenerBoolean Whether or not to bind keyup events (optional, defaulttrue)options.allButtonSelectorString Selector for view all button elementoptions.expandableSelector(optional, default'data-ecl-gallery-not-expandable')options.noOverlaySelector(optional, default'data-ecl-gallery-no-overlay')options.itemsLimitSelector(optional, default'data-ecl-gallery-visible-items')options.viewAllSelector(optional, default'[data-ecl-gallery-all]')options.viewAllLabelSelector(optional, default'data-ecl-gallery-collapsed-label')options.viewAllExpandedLabelSelector(optional, default'data-ecl-gallery-expanded-label')options.countSelector(optional, default'[data-ecl-gallery-count]')options.attachResizeListener(optional, defaulttrue)
init
Initialise component.
destroy
Destroy component.
checkScreen
Check if current display is desktop or mobile
hideItems
Parameters
plus(optional, default0)rows/itemInt numberHide several gallery items by default* 2 "lines" of items on desktop- only 3 items on mobile or the desired rows or items when using the view more button.
handleResize
Trigger events on resize Uses a debounce, for performance
updateOverlay
Parameters
selectedItemHTMLElement Media element
handleKeyboard
Handles keyboard events such as Escape and navigation.
Parameters
eEvent
handleClickOnCloseButton
Invoke listeners for close events.
handleKeyPressOnItem
Invoke listeners for on pressing the spacebar button.
Parameters
eEvent
handleClickOnViewAll
Invoke listeners for on click events on view all.
Parameters
eEvent
handleClickOnItem
Invoke listeners for on click events on the given gallery item.
Parameters
eEvent
preventClickOnItem
handle click event on gallery items when no overlay.
Parameters
eEvent
handleClickOnPreviousButton
Invoke listeners for on click events on previous navigation link.
handleClickOnNextButton
Invoke listeners for on click events on next navigation link.
autoInit
Parameters
rootHTMLElement DOM element for component instantiation and scope$1Object (optional, default{})$1.GALLERY(optional, default{})
Returns Gallery An instance of Gallery.
Setup
There are 2 ways to initialise the component.
Automatic
Add data-ecl-auto-init attribute to component's markup
<section class="ecl-gallery" data-ecl-gallery data-ecl-auto-init="Gallery">
...
</section>
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-gallery on the page:
var elt = document.querySelector('[data-ecl-gallery]');
var gallery = new ECL.Gallery(elt);
gallery.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-gallery]');
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();