diff --git a/index.html b/index.html
index def3dcb..39ea926 100644
--- a/index.html
+++ b/index.html
@@ -388,6 +388,11 @@
Callback events
+
+ confirmclose |
+ function |
+ Callback function which will execute when the popup is requested to close. The popup will only close if it returns true. |
+
beforeopen |
function |
diff --git a/jquery.popupoverlay.js b/jquery.popupoverlay.js
index eb0fe3d..ddd4471 100644
--- a/jquery.popupoverlay.js
+++ b/jquery.popupoverlay.js
@@ -441,14 +441,30 @@
return;
}
- if(opentimer) clearTimeout(opentimer);
-
var $body = $('body');
var $el = $(el);
var options = $el.data('popupoptions');
var $wrapper = $('#' + el.id + '_wrapper');
var $background = $('#' + el.id + '_background');
+ // Confirm close
+ if (options.confirmclose) {
+ if (!callback(el, lastclicked[el.id], options.confirmclose)) {
+ // Not confirmed
+ return;
+ }
+
+ // During callback execution, visibility of popup(s) could have changed,
+ // so we re-find this popup in visiblePopupsArray.
+ var popupIdIndex = $.inArray(el.id, visiblePopupsArray);
+ if (popupIdIndex === -1) {
+ // This popup was already hidden, nothing more to do.
+ return;
+ }
+ }
+
+ if(opentimer) clearTimeout(opentimer);
+
$el.data('popup-visible', false);
if (visiblePopupsArray.length === 1) {
@@ -679,7 +695,7 @@
openelement = options.openelement ? options.openelement : ('.' + el.id + opensuffix);
elementclicked = $(openelement + '[data-popup-ordinal="' + ordinal + '"]');
if (typeof func == 'function') {
- func.call($(el), el, elementclicked);
+ return func.call($(el), el, elementclicked);
}
};
@@ -839,6 +855,7 @@
closeelement: null,
transition: null,
tooltipanchor: null,
+ confirmclose: null,
beforeopen: null,
onclose: null,
onopen: null,