JavaScript events for developers

Our theme makes heavy use of JavaScript to speed up loading times and make features like quick view really, well, quick. At times you may want to hook into these events after they happen to run your own custom script or integrate a third-party app.

There is no jQuery dependency for these events even though our theme uses it extensively. All objects returned are vanilla JS objects and can be manipulated however you see fit.

Stylesheet has loaded and page is visible

Necessary because we only load some critical CSS inline — enough to show the page loader and some base styles — before lazyloading the rest of the stylesheet. Use this listener instead of document.onload or $(document).ready().

document.addEventListener('page:loaded', function() {
Cart updated

JavaScript updates the cart object after the quantity is changed. This event is triggered after the cart markup is updated and is free to customize.

Cart object returned.

document.addEventListener('cart:updated', function(evt) {
Product added to the ajax cart

Project object returned.

document.addEventListener('added:ajaxProduct', function(evt) {
Product failed to add to cart

The error message will let you know the problem. Most of the time it is quantity related.

document.addEventListener('error:ajaxProduct', function(evt) {
Quick view modal is opened

The first time the modal is opened some elements are lazyloaded, such as the add to cart form. Those elements are not available right away.

evt.detail.initialized will be true if the quick view modal is opened a second time and all elements are available immediately.

Only the product ID is returned along with the initialized state.

document.addEventListener('quickview:open', function(evt) {

  if (evt.detail.initialized) {
    console.log('quickview:open | already initialized')
    var $form = $('#AddToCartForm-' + evt.detail.productId);
    var $addToCart = $('#ProductSection-' + evt.detail.productId).find('.add-to-cart');
Quick view modal loaded

Only fires the first time the modal is opened.

Only the product ID is returned.

document.addEventListener('quickview:loaded', function(evt) {
  var $form = $('#AddToCartForm-' + evt.detail.productId);
Variant selection changed

Variant object returned.

document.addEventListener('variant:change', function(evt) {