Mecha CMS

Mecha CMS blog and documentation.

DASHBOARD Hooks

Updated: Sunday, 07 August 2016

Function hooks for JavaScript.

Added since version 1.0.4.

You can add some function to the DASHBOARD variable if you want to make the function becomes customizable publicly. The example can be found in the composer function. Use it as simple as:

DASHBOARD.whatTheFunc = function(param) {
    return 'icon-' + param;
};

Then you can call the function anywhere after the declaration above. Example:

elem.className = DASHBOARD.whatTheFunc('home');

There are also support for function hook you can add with specific name if you want to add more function at once to a specific target so that it can be executed simultaneously at the same time.

Add a Function to Stacks

// Example 1
DASHBOARD.add('on_preview_complete', function(param) {
    alert('Echo: ' + param[0]);
}, 4);

// Example 2
DASHBOARD.add('on_preview_complete', function(param) {
    alert('Echo: ' + param.data_1);
}, 4);

Options:

DASHBOARD.add(name, fn, stack);
ParameterDescription
nameThe hook name.
fnThe function callback you want to execute.
stackThe function priority. The smaller the value, the earlier the function will be executed.

Call the Function Stacks

// Example 1
DASHBOARD.fire('on_preview_complete', ['item 1', 'item 2', 'item 3']);

// Example 2
DASHBOARD.fire('on_preview_complete', {
    data_1: 'item 1',
    data_2: 'item 2',
    data_3: 'item 3'
});

Delete the Function Stacks

DASHBOARD.eject('on_preview_complete');

Check for Function Stacks

if (DASHBOARD.exist('on_preview_update')) {
    alert('OK!');
}

console.log(DASHBOARD.exist()); // inspect!

Methods are similar with the Weapon class.

Donation and Email Subscription