Search code examples
javascripteventspopuponloadnyromodal

How do I make some Javascript code execute on load of any NyroModal dialog


I have some common Javascript which I would like to execute on the event of any NyroModal dialog being opened.

How do I assign an event handler for, say, the 'on load' (or whatever) event of the NyroModal component?


Solution

  • All of the NyroModal's event handlers can be set in its 'options' object, which you can set using the '$.nmObj' function (by passing an object containing the keys/values you want to set).

    To handle the on-load of a popup, you probably want the 'afterShowCont' handler:

    $.nmObj({
        callbacks: {
            afterShowCont: function(nm) {
                alert('Handled!');
            }
        }
    });
    

    See a full list of events here: http://nyromodal.nyrodev.com/#filters

    Note: The 'nm' parameter will contain an instance of the NyroModal object, which allows you to alter the content, manipulate the NyroModal, etc.