Scalar 2 User's Guide

JavaScript events

Scalar 2 performs a fair amount of DOM manipulation when each page loads. Consequently, relying on the page ‘ready’ or ‘load’ events might produce unexpected results.

Instead, Scalar 2 includes a custom event, ‘pageLoadComplete’. This event will fire when Scalar 2 finishes manipulating the DOM.
$(document).ready(function() {
$('body').on('pageLoadComplete',function() {
// Do something to the DOM, such as change the "This page is tagged by" text
$('.has_tags').prev().text('This is the new text');
});
});

The ‘mediaElementComplete’ fires when media elements are created:
$(document).ready(function() {
$('body').on('mediaElementComplete',function(mediaElement) {
// Do something with the mediaElement
});
});

The ‘widgetElementLoaded’ fires when widgets are created:
$(document).ready(function() {
$('body').on('widgetElementLoaded',function() {
// Do something with the widget
});
});

This page has paths: