TypeRocket v1 Pro users can now upgrade to TypeRocket v5 at their convenience.
JavaScript Hooks
( v1 )
- # HTTP
- # Example: Replacing flash with Sweet Alert
- # Repeater and Matrix
- # JavaScript Helpers
- # Site URL
- # Nonce
TypeRocket comes with two callbacks to help you extend the core JavaScript functionality: TypeRocket.httpCallbacks
and TypeRocket.repeaterCallbacks
.
HTTP
The HTTP callback lets you modify and respond to the REST API's JSON response.
TypeRocket.httpCallbacks.push(function(response) {
// do something
});
Example: Replacing flash with Sweet Alert
For example, you can tell the response that it shouldn't use the default flash message but use Sweet Alert instead.
TypeRocket.httpCallbacks.push(function(response) {
response.flash = false;
if (response.valid == true) {
type = 'success';
title = 'Success!';
} else {
type = 'error';
title = 'Error!'
}
swal(title, response.message, type);
});
If you are using the theme options plugin, you can see the core flash message when you save your changes.
Repeater and Matrix
The repeater callback is designed to allow you to do something when a repeater or matrix field is added. Although the callback has repeater in its name don't forget it applies to matrix fields as well.
$template
is a jQuery object of the field group being added.
TypeRocket.repeaterCallbacks.push(function($template) {
// do something
$template.find('.my-field').hide();
});
JavaScript Helpers
TypeRocket provides a helper object located at window.trHelpers
. If you need to access these helpers from the front-end be sure you have front-end mode enabled.
Site URL
let site_url = window.trHelpers.site_uri;
Nonce
let tr_nonce = window.trHelpers.nonce;
Found a typo? Something is wrong in this documentation? Fork and edit it!