jsToolboxMJK.page.addOnLoaded() - mkloubert/jsToolbox GitHub Wiki

jsToolboxMJK.page.addOnLoaded(action [, actionState [, opts]]) method

Adds a new function that is invoked when page has been completely loaded.

Syntax

$jsTB.page.addOnLoaded(action [, actionState [, opts]];

Parameters

Name Type Description
action Function The action to invoke.
actionState mixed [OPTIONAL] The additional object / value for the action to submit.
opts Object [OPTIONAL] Additional options.

Result

The page property value ($jsTB.page).

Remarks

Each action has the following structure:

function (sender, ctx) {
}

ctx

The ctx parameter has the following structure:

Methods

addVar(name, val [, opts])

Adds a new getter property to ctx.vars.

Parameters
Name Type Description
name String The name of the new property.
val mixed The value or function that returns it.
opts Object [OPTIONAL] Additional options.
Example
// first action to invoke
$jsTB.page.addOnLoaded(function(JSTB, ctx) {
    ctx.addVar('myVar1', 'TM')
       .addVar('myVar2', function() {
                             return 5979;
                         })
       .addVar('myVar3', function() {
                             return function(s) {
                                 return s.toLowerCase();
                             };
                         });
});

// the second one AFTER the first one
$jsTB.page.addOnLoaded(function(JSTB, ctx) {
    // 'TM'
    alert(ctx.vars.myVar1);

    // 5979
    alert(ctx.vars.myVar2);

    // 'mk'
    alert(ctx.vars.myVar3('MK'));
});
clearVars([opts])

Removes all variables.

Parameters
Name Type Description
opts Object [OPTIONAL] Additional options.

Properties

Name Type Description
continueOnError Boolean Gets or sets if the invokation of other functions should be continued if the current invokation fails. The value is TRUE by default.
index Number The zero-based index of the current function.
isFirst Boolean Gets if the function is the first one or not.
isLast Boolean Gets if the function is the last one or not.
lastErr Object Gets the last error if defined.
prevState mixed Gets the object that was submitted by the previous function.
nextState mixed Sets the object that shoulf be submitted to the next function.
state mixed The global object / value.
vars Object Global variables inside the invokation context.

Examples

// simple way
$jsTB.page.addOnLoaded(function() {
});

// with state
$jsTB.page.addOnLoaded(function(JSTB, ctx) {
    // 5979
    alert(ctx.state);
}, 5979);