Custom JavaScript events

Custom JavaScript events

Start your free trial
Start your free trial

General

Online store speed
Online store speed
Accessibility
Accessibility
Theme updates
Theme updates

Theme styles

Style presets
Style presets
Colors
Colors
Fonts
Fonts
Animation
Animation
Social media
Social media

Header

Announcement bar
Announcement bar
Mobile menu
Mobile menu
Search bar
Search bar

Sections

Products

Product listings
Product listings
Product badges
Product badges
Quick view
Quick view
Quick add
Quick add

Product page

Product template
Product template
Variant chips
Variant chips
Sticky add-to-cart bar
Sticky add-to-cart bar
Sibling product swatches
Sibling product swatches
Product recommendations
Product recommendations

Collection page

Collections template
Collections template
Banner
Banner
Product grid
Product grid
Filters and sorting
Filters and sorting

Cart

Quick cart
Quick cart
Cart page
Cart page
Added-to-cart popup
Added-to-cart popup
Cross sells
Cross sells
Free shipping bar
Free shipping bar
Low inventory warning
Low inventory warning

Pages

Templates
Templates
Home page
Home page
About page
About page
Blogs page
Blogs page
Blog post
Blog post
Collections list
Collections list
Contact page
Contact page
Password page
Password page
Search page
Search page
404 page
404 page

Support

Support policy
Support policy
Shopify vs Theme issues
Shopify vs Theme issues
Store access requests
Store access requests

Custom JavaScript events

Note | For intermediate developers, Cornerstone also includes an unminified theme.js file that can be enabled to edit the theme JavaScript directly.

For Cornerstone, we've introduced custom events so developers can easily add their own functionality to the theme without needing to edit the theme's JavaScript files.

Use the custom-events.js file included in the theme to add all your custom scripts in one place and effortlessly hook into Cornerstone's JavaScript.

Enable custom events

To enable custom events, you need to update the theme-globals.liquid to import the custom-events.js file that you'll be using for your scripts.

icon
STEPS
  1. In the Snippets folder, open the theme-globals.liquid.
  2. Find the useCustomevents variable and set it to true.
  3. {% assign useCustomEvents = false %}

Add scripts to custom-events.js

Once you've enabled custom events, you can start adding your custom scripts to the custom-events.js file.

icon
STEPS
  1. In the Assets folder, open the custom-events.js.
  2. Add your scripts using the available exposed events or start from scratch and use this file to create something new.

Use exposed events

We've listed all exposed events within the custom-events.js file so you can easily use and edit them there.

The following exposed events are available to use as a blueprint to get started:

Item added to cart

This event fires when an item is added to the cart. The AJAX cart must be enabled for this event to be exposed. The product object is passed within the detail object.

document.addEventListener("cart:item-added", function (evt) {
  console.log("Item added to the cart");
  console.log(evt.detail.product);
});

Cart updated

This event fires when the cart has been updated. The AJAX cart must be enabled for the event to be exposed. The cart object is passed within the detail object.

document.addEventListener("cart:updated", function (evt) {
  console.log("Cart updated");
  console.log(evt.detail.cart);
});

Cart error

This event fires when an error occurs with adding an item to the cart. This error typically occurs when a product is unavailable due to insufficient stock. The error message is passed within the detail object.

document.addEventListener("cart:error", function (evt) {
  console.log("Cart error");
  console.log(evt.detail.errorMessage);
});

Quick cart opened

This event fires when the quick cart is opened. The AJAX cart must be enabled for the event to be exposed. The cart object is passed within the detail object.

document.addEventListener("quick-cart:open", function (evt) {
  console.log("Quick cart opened");
  console.log(evt.detail.cart);
});

Quick cart closed

This event fires when the quick cart is closed. The AJAX cart must be enabled for the event to be exposed.

document.addEventListener("quick-cart:close", function () {
  console.log("Quick cart closed");
});

Product variant changed

This event fires when an a variant product is selected. A Variant selector block must be enabled on the product template or featured product section for the event to be exposed. The selected variant object is passed within the detail object.

document.addEventListener("product:variant-change", function (evt) {
  console.log("Product variant changed");
  console.log(evt.detail.variant);
});

Product quantity updated

This event fires when the product quantity is updated. A Quantity selector block must be enabled on the product template or featured product section for the event to be exposed. The quantity and selected variant objects are passed within the detail object.

document.addEventListener("product:quantity-update", function (evt) {
  console.log("Product quantity updated");
  console.log(evt.detail.quantity, evt.detail.variant);
});

Quick view loaded

This event fires when a quick view modal is opened. The Enable quick view setting must be enabled.

document.addEventListener("quick-view:loaded", function () {
  console.log("Quick view loaded");
});
How's Cornerstone working for you?

We built Cornerstone with developers in mind. We're looking to create relationships with third-party developers using our themes and want to hear from you about what you're building. Please feel free to reach out with questions or introduce yourself by e-mailing us at developers@fluorescent.co