JavaScript events
The grid sends events when it starts and when its items change. They bubble, so one listener on document hears every grid on the page.
// Refresh a custom cursor after new items come in
document.addEventListener( 'forma:updated', ( event ) => {
myTheme.cursor.refresh( event.detail.items );
} );
// Don't load the next page while a popup is open
document.addEventListener( 'forma:before-load', ( event ) => {
if ( document.body.classList.contains( 'popup-open' ) ) {
event.preventDefault();
}
} );
Grid events
| Event | When |
|---|---|
forma:init | The grid is ready |
forma:before-load | A request starts; preventDefault() cancels it |
forma:updated | New items are in; detail.items lists them |
forma:filtered | After updated, when the filter changed |
forma:searched | After updated, when the search changed |
forma:sorted | After updated, when the order changed |
forma:paginated | After updated, for page numbers and Load More |
forma:error | The request failed |
Each detail has grid (the element), layout, layoutSettings, page, maxPages, term, search, sort, and for loads also action, append and items.
Lightbox events
| Event | Sent on | When |
|---|---|---|
forma:lightbox-slide | The element a slide comes from | Before the slide shows. detail.item is its data, which a listener can change |
forma:lightbox-open | document | Before the lightbox opens. detail.pswp is the PhotoSwipe instance, detail.trigger the element clicked |
Methods
window.formaGrid has two methods for your scripts:
// Start the grids in markup added after the page loaded, such as a popup
formaGrid.init( popupElement );
// Show page 3 of a grid, given the grid or one of its controls
formaGrid.page( gridElement, 3 );
Was this article helpful?
Thanks for your feedback!