Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "onBeforeClose" callback #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/jquery.simplemodal.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
* onOpen: (Function:null) The callback function used in place of SimpleModal's open
* onShow: (Function:null) The callback function used after the modal dialog has opened
* onClose: (Function:null) The callback function used in place of SimpleModal's close
* onBeforeClose: (Function:null)
*/
$.modal.defaults = {
appendTo: 'body',
Expand Down Expand Up @@ -213,7 +214,8 @@
modal: true,
onOpen: null,
onShow: null,
onClose: null
onClose: null,
onBeforeClose: null
};

/*
Expand Down Expand Up @@ -248,6 +250,7 @@

// set the onClose callback flag
s.occb = false;
s.obccb = false;

// determine how to handle the data based on its type
if (typeof data === 'object') {
Expand Down Expand Up @@ -671,6 +674,19 @@
return false;
}

if ($.isFunction(s.o.onBeforeClose) && !s.obccb )
{
var carryOn = s.o.onBeforeClose.apply(s, [s.d]);
if( carryOn === false )
{
return false;
}
else
{
s.obccb = true;
}
}

// remove the default events
s.unbindEvents();

Expand Down