Fluorescent
Stiletto
Stiletto
  • Stiletto Help Center
    • Start using Stiletto
      • Theme licenses
      • Migrate your theme
    • FAQs
    • Video tutorials
    • Changelog
  • General
    • Editing themes
      • Adding sections
      • Using templates
      • Accessibility
      • Customizing your site
      • SEO for Shopify themes
      • H1 heading tags
      • Online store speed
    • Image guide
      • Web ready photography
      • Image sizes
      • File formats
      • Theme image settings
    • Adapting theme content
      • Edit default theme content
      • Multiple languages
      • Dynamic content with metafields
      • Unique content for markets
    • Update your theme
  • Theme styles
    • Theme settings
    • Style presets
      • Demo layouts
    • Fonts
    • Colors
    • Animation
  • Pages
    • Templates
      • About page
      • Blog page
      • Blog posts
      • Collections list
      • Contact page
      • Customer accounts
      • FAQ page
      • Lookbook
      • Password page
      • Search page
      • Store locations
      • 404 page
      • Home page
    • Announcement bar
    • Header
      • Layout and style
      • Logo
      • Transparent header
      • Mega menus
      • Mobile menu
      • Quick search
      • Language and currency
      • Social media icons
      • Customer account icon
    • Footer
      • Links block
      • Newsletter block
      • Text and image block
      • Language and currency
      • Payment icons
      • Custom Liquid
  • Sections
    • Theme sections
      • Using sections
      • Content blocks
      • Blog posts
      • Collapsible row list
      • Collection list grid
      • Collection list slider
      • Complete the look
      • Contact form
      • Countdown banner
      • Countdown bar
      • Events
      • Featured collection grid
      • Featured collection slider
      • Featured product
      • Gallery carousel
      • Grid
      • Image compare
      • Image hero
      • Image hero split
      • Image with text
      • Image with text split
      • Multi column
      • Newsletter
      • Newsletter compact
      • Promotion banner
      • Promotion bar
      • Quotes
      • Recently viewed products
      • Rich text
      • Sales banner
      • Scrolling content
      • Shoppable image
      • Shoppable image editorial
      • Slideshow
      • Testimonials
      • Video
      • Video hero
      • Video with text
    • Popups
      • Sign up popup
      • Age verification
      • Countdown popup
      • Promotional popup
  • Products
    • Product listings
      • Product card style
    • Prices and discounts
    • Product badges
    • Quick shop
  • Product pages
    • Product template
      • Alternate templates
      • Pre-order template
      • Gift card
    • Layout and style
      • Product tabs
      • Media gallery
      • Sticky product details
      • Breadcrumbs
      • Navigation buttons
    • Overview blocks
      • Default blocks
        • Description
        • Product header
        • Variant selector
        • Quantity selector
        • Buy buttons
        • Local pickup banner
        • Share icons
        • Sticky add-to-cart bar
      • Collapsible rows block
      • Complementary products
      • Custom options
      • Image block
      • Information popup
      • Product labels
      • Secure payment
      • Stock level indicator
      • Text block
      • Text list with icons
      • App blocks
    • Variant options
      • Variant chips
      • Variant swatches
        • Enable swatches
        • Use default colors
        • Use custom colors
        • Use variant images
        • Use custom images
        • Change swatch styles
        • Show on product cards
        • Dynamic option availability
      • Media grouping
      • Sibling product swatches
    • Product page sections
      • Product reviews
      • Product recommendations
  • Collection pages
    • Collection template
      • Collection landing
      • Sale collection
      • Subcollections
      • Flash sale
    • Banner
    • Product grid
    • Filters and sorting
  • Cart
    • Cart page
    • Quick cart
      • Added to cart popup
      • Empty cart promotion
    • Free shipping bar
    • Low inventory warning
    • Cross sells
  • Support
    • Support policy
    • Shopify vs Theme issues
    • Store access requests
  • For developers
    • Custom CSS
    • Custom fonts
    • Custom Liquid
    • Custom JavaScript events
    • Edit Theme JavaScript
Powered by GitBook
On this page
  • Enable custom events
  • Add scripts to custom-events.js
  • Use exposed events
  • Item added to cart
  • Cart updated
  • Cart error
  • Quick cart opened
  • Quick cart closed
  • Product variant changed
  • Product quantity updated
  • Quick view loaded
  • Refresh quick cart and cart count

Was this helpful?

  1. For developers

Custom JavaScript events

Advanced

Last updated 3 months ago

Was this helpful?

We do not support code customizations. This guide offers a basic reference for developers. Always test code changes on unpublished theme copies. For assistance, we recommend reaching out to a .

For Stiletto, 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 Stiletto's JavaScript.

For intermediate developers, Stiletto also includes an unminified theme.js file that can be enabled to directly.

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.

STEPS
  1. Open the theme-globals.liquid file in the Snippets folder.

  2. Find the useCustomevents variable and set it to true.

    <div data-gb-custom-block data-tag="assign" data-useCustomEvents='false'></div>

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.

STEPS
  1. Open the custom-events.js in the Assets folder

  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");
});

Refresh quick cart and cart count


The following event can be used to refresh the quick cart and header cart count:

apps:product-added-to-cart

For example:

var event = new CustomEvent('apps:product-added-to-cart');
document.dispatchEvent(event);

How's Stiletto working for you?

We built Stiletto 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.

Related links

Please feel free to reach out with questions or introduce yourself by e-mailing us at

verified Fluorescent partner
edit the theme JavaScript
developers@fluorescent.co
Edit theme JavaScript
Custom Liquid
Custom CSS
Custom fonts