Skip to main content

Alert module scripting

This document details how to control Alert module using JavaScript.

Typically, you will be using an mwf library or you will define an mwf global variable to access a module object. This can vary based on the distribution library you are using. In either case, you will need to initialize the module object as described here. Once you have the name of the initialized module, you can interact with it through your code. For example, you can use the following sample code to detect a selection change to a alert module.

NOTE: To select a single module, make sure you have provided a unique selector for that module.

    var myAlertHtmlElement = document.querySelector('.c-alert');
    var mwfAlertComponent;
    mwf.ComponentFactory.create([ {
        c: mwf.Alert,
        elements: [ myAlertHtmlElement ],
        callback: function (results) {
            if (results && results.length) {
                 mwfAlertComponent= results[ 0 ];
        eventToBind: 'DOMContentLoaded'

The create method shown here will create a new module if the module is not already initialized or return back a module that is already initialized on the selector specified html element.

After creating the module object as described above, you can add a callback to the onAlertClosed event and subscribe to it. For example:

    if (mwfAlertmodule) {
        // subscribe to the mwfSliderComp instance defined above
            onAlertClosed: function () {
                // custom callback goes here
                console.log('alert closed');

When you run this example, the console log will record the following:

Console output

    alert closed

The first line in the log indicated that the value returned by the alert module is the string "true." The second line indicated that the module has been successfully user initiated.

The following events are available for subscription:

  • onAlertClosed — Data array: No data

More information about notifications can be found on the Event Notification page. While some DOM events are blocked by this control, the use of other DOM events is possible, but not recommended and developers who chose to do so are fully responsible for the functional consequences. The reasons for this are also discussed on the Event Notification page.

Last edited on 04-27-2017.