# Shoptet Developers Tools

URL: https://shoptet.dev/templates/shoptet-developers-tools

Shoptet Developers Tools are a set of JavaScript functions that make it easier for external developers to edit our templates. They are available in the 3rd generation templates: Techno, Tango, Waltz, Classic, Step, Disco and Samba.

The source code is public in the [templates-assets](https://github.com/shoptet/templates-assets) repository ( `shared/js/libs/dev.js` and `00/js/libs/scripts.js` ), see [Template assets](/templates/template-assets/) .

## Events monitoring

When you open the browser console (F12) on an e-shop, you see the following message:

```shell
Shoptet developers tools version 0.2.0
Events monitoring is disabled.
To enable events monitoring, run shoptet.dev.enableEventsMonitoring()
```

Run `shoptet.dev.enableEventsMonitoring()` to switch on the monitoring of **functions** and **events** . The function stores a cookie ( `monitorJSEvents` ) in your browser, so the monitoring applies only to you. It takes effect after the page is reloaded.

The function has two optional parameters:

- `reload` – `true` reloads the page right away; without it, the console asks you to reload the page yourself
- `expires` – how long the monitoring stays on; the default is one day. It is an object with any of the keys `years` , `months` , `days` , `hours` , `minutes` and `seconds` , merged with the default `{days: 1}` , so set `days: 0` when you want a shorter time.

```javascript
// Enable for one hour and reload the page
shoptet.dev.enableEventsMonitoring(true, {days: 0, hours: 1});
```

With the monitoring on, every monitored function that runs is written to the console with the arguments it was called with, and every Shoptet event that is dispatched is written there with the element it was dispatched on. This gives you an overview of what is happening "in the background", which functions run and how they relate to each other.

Switch the monitoring off with `shoptet.dev.disableEventsMonitoring()` , which removes the cookie and reloads the page.

warning
Functions and events monitoring must never be turned on globally for all visitors of an e-shop; it is of no use to customers.

## Modifying functionality

The most powerful part of Shoptet Developers Tools is the ability to react to template functions being called, to attach your own callbacks to them, and to respond to DOM changes.

### Monitored functions

Run `shoptet.scripts.monitoredFunctions` in the console to list the functions you can react to (we add more over time). Each of them has its full name, for example `shoptet.popups.showPopupWindow` or `shoptet.cartShared.addToCart` .

Every time one of these functions is called, an event with the same name is dispatched on `document` , right before the function runs. The functions in the `shoptet.MODULE_NAME` namespaces are considered stable, and we announce changes to them in advance in the [Frontend news](/news/frontend/) .

To react to every call of a function, for example `showPopupWindow` , listen to its event:

```javascript
document.addEventListener('shoptet.popups.showPopupWindow', function () {
    // code to be executed each time showPopupWindow is called
});
```

You can also register your own function as a callback of any monitored function. The callback runs after the function has finished and receives the arguments the function was called with. Each call to `setCustomCallback` adds a callback, so callbacks registered by different scripts do not overwrite each other.

```javascript
shoptet.scripts.setCustomCallback('shoptet.popups.showPopupWindow', function (args) {
    console.log('I am a callback of "shoptet.popups.showPopupWindow", called with the following arguments:');
    console.log(args);
});
```

note
`showPopupWindow` used to be in the `shoptet.global` namespace ( `shoptet.global.showPopupWindow` ), which the old version of this page used in its examples. It moved to `shoptet.popups` ; the old name now only logs a deprecation message and calls the new one, and its event and callbacks are no longer fired. Use `shoptet.popups.showPopupWindow` .

### Events fired when the DOM changes

Run `shoptet.scripts.availableDOMLoadEvents` to list the events fired when a new part of the DOM is loaded. The general event `ShoptetDOMContentLoaded` is fired each time a part of the DOM is loaded by AJAX, together with an event for the specific change, such as `ShoptetDOMCartContentLoaded` .

Other events you can respond to are listed in `shoptet.scripts.availableDOMUpdateEvents` (DOM updates, for example `ShoptetDOMCartCountUpdated` , together with the general `ShoptetDOMContentChanged` ) and `shoptet.scripts.availableCustomEvents` (for example cart changes, variant selection, filters and pagination, form validation). We keep adding events.

A practical example: after the cart content is reloaded, individual modifications are often needed. Instead of listening to the general jQuery `ajaxComplete` event, you can make targeted changes each time the cart content is reloaded:

```javascript
document.addEventListener('ShoptetDOMCartContentLoaded', function () {
    // code to be executed after the cart content is loaded
});
```

The events bubble, so you can listen to them on `document` even when they are dispatched on an element inside the page.

### Custom functions after form validation

You can hook your own script into the submission of forms validated by the template. This covers the order form as well as, for example, a discussion post, a newsletter subscription or a product question.

- `postSuccessfulValidation` is called after the form has been validated **successfully** , right before it is submitted. Return `false` to stop the submission – you then have to take care of submitting the form yourself. Any other return value lets the form be submitted.
- `postFailedValidation` is called after the validation has **failed** . It does not need to return anything.
Both functions receive the validated form as their first parameter, `form` .

Register them with `shoptet.scripts.setCustomFunction` , which adds your function to the ones already registered instead of replacing them, so several add-ons or customizations can use the hooks at the same time:

```javascript
/*
 * This function will be called after successful validation, right before form submit.
 * Argument "form" is the currently validated form.
 * Return false to stop the form from being submitted.
 */
shoptet.scripts.setCustomFunction('postSuccessfulValidation', function (form, args) {
    // Do your stuff here...
});

/*
 * This function will be called after unsuccessful validation, right before the form submitting is interrupted.
 * Argument "form" is the currently validated form.
 */
shoptet.scripts.setCustomFunction('postFailedValidation', function (form, args) {
    // Do your stuff here...
});
```

If you only need to be notified, you can also listen to the events `ShoptetSuccessfulValidation` and `ShoptetFailedValidation` , which are dispatched on the form just before these functions are called.

note
Assigning your own function directly to `shoptet.custom.postSuccessfulValidation` or `shoptet.custom.postFailedValidation` , as the old version of this page showed, still works, but it replaces whatever other scripts have registered. Use `setCustomFunction` instead, see [Multiple custom scripts after form validation](/news/frontend/multiple-custom-scripts-after-form-validation/) .

## Deprecation warnings

When we move or rename a template function, the old call keeps working for a while and writes a warning to the console with the new way to call it and the date after which the old one will be removed ( `shoptet.dev.deprecated` ). Once that date has passed, the warning becomes an error message. Remove deprecated calls from your code as soon as you see them, see [Frontend news from February 26, 2025](/news/frontend/frontend-news-from-february-26-2025/) .

## Missing a function or event?

If you work with JavaScript and miss a function or event that would help you, contact us at [partneri@shoptet.cz](mailto:partneri@shoptet.cz) . If it is possible and useful for our clients in general, we will do our best to add it.
