How do I make some Javascript code execute on load of any NyroModal dialog
I have some common Ja开发者_开发技巧vascript 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?
You have to set the afterShowCont inside a callbacks settingslike:
$.nmObj({
callbacks: {
afterShowCont: function(nm) {
alert('Handled!');
}
}
});
Or, you can define it in the custum filter like:
$.nmFilters({
custom: {
afterShowCont: function(nm) {
alert('Handled!');
}
}
});
Or you can define it when you're initiating the nyroModal elements:
$('.nyroModal').nyroModal({
callbacks: {
afterShowCont: function(nm) {
alert('Handled!');
}
}
});
NB : all of these solutions work with nyroModal V2.
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.
精彩评论