less than a minute read • Updated 8 minutes ago
JavaScript naming and file structure reference
Naming conventions for Foxy JavaScript variables and events, the internal file structure, and the pageload order of execution.
JavaScript naming conventions
Similar to Google’s conventions, but using snake_case instead of camelCase for variable names.
Type | Convention | Example |
|---|---|---|
Function names | camelCase |
|
Variable names | snake_case |
|
Class names | PascalCase |
|
Enum names | PascalCase |
|
Method names | camelCase |
|
Constant values | UPPER_SNAKE_CASE |
|
Namespaced names | dot notation, camelCase |
|
File names | lowercase, no separator |
|
Event naming conventions
Present tense, like standard JavaScript events —
cart-coupon-add, notcart-coupon-added.Hyphens separate the parts of the event name.
Names follow this order: section (
cart,checkout,receipt), noun (coupon,email,address, etc.), modifier/attribute if applicable (e.g.cart-item-quantity, wherequantityis the attribute of the item), then verb (add,remove,update,change, etc.).The “after” event gets the
.donesuffix:client.on("cart-item-remove.done", handler).
What counts as an event
Anything in an init method.
Anything on
change,click,keyup/keydown,blur,focusin/focusout.Rendering.
Interactions with API JSON.
Selectors are not events — they return a string, not a triggerable action.
File structure
Internal source files used to compile Foxy’s external JavaScript. Source files are available at admin.foxycart.com/static/v/2.0.0/js/src/.
File | Purpose | Internal methods | Events |
|---|---|---|---|
| Methods that make requests to the |
| none |
| Methods that make requests to the | — |
|
| Checkout page initialization and methods. | — | not yet documented |
| Maintains and handles the | — |
|
| Defines the event model. | — | — |
| Shipping and billing country/state/province/region functionality. | — | none |
| Declares `var FC = FC | {};` | |
| Postal code → city + state/region lookup. | — | — |
| Sets the | — | — |
| Everything related to the Sidecart approach. | — | — |
| Twig.js-related methods, including custom Twig.js methods that mirror custom server-side methods. | — | — |
| Helper functions. |
| — |
External scripts
Script | Purpose |
|---|---|
| Namespace, session management, events, and utilities. |
| Base for custom integrations and the default Sidecart approach. |
| The cart in a Sidecart approach. |
Pageload events and order of execution
FC.client.init() is called on pageload for any CDN-loaded, store-specific JavaScript, triggering the following sequence:
FC.client.updateCart() makes an FC.client.request to get the cart JSON. On completion, FC.client.request triggers FC.client.updateJSON(), which in turn calls FC.client.updateMiniCart().
The ready event then triggers:
FC.cart.updateConfig()FC.cart.updatePaymentInfoRequired()
FC.cart.updateConfig() checks and sets localStorage, which triggers FC.client.requestConfig() — a call to FC.client._request that sets the config JSON with the updated data.