Is there anyway to get confimation when user click or trying to close the Popup. This is my demo http://jsfiddle.net/K9Geq/
If user click cancel the Popup should remain as it is, Or if user click Ok, We need to close the Popup.
Possible with some JavaScript magic http://jsfiddle.net/K9Geq/1/
@dimsemenov man you saved my time... thanks.. :) can you explain what did you just did
I'm just overriding close method in MagnificPopup object that is created when open callback is fired:
// this part overrides "close" method in MagnificPopup object
$.magnificPopup.instance.close = function () {
if (!confirm("Are you sure?")) {
return;
}
// "proto" variable holds MagnificPopup class prototype
// The above change that we did to instance is not applied to the prototype,
// which allows us to call parent method:
$.magnificPopup.proto.close.call(this);
};
You can override any function in this manner...
Thanks. Now I understand how its working... :D
@dimsemenov This doesn't seem to work when calling the popup using the open method (or perhaps when using AJAX).
$.magnificPopup.open({
items: {
src: '/path/to/file',
type: 'ajax',
},
callbacks: {
open: function() {
$.magnificPopup.instance.close = function() {
console.log('close override is working');
$.magnificPopup.proto.close.call(this);
}
},
ajaxContentAdded: function() {
var m = this;
this.content.find('.closebutton').on('click', function(e) {
e.preventDefault();
m.close();
});
}
},
closeOnContentClick: false,
closeOnBgClick: false,
showCloseBtn: false,
enableEscapeKey: true
});
In this example, the console.log happens, but the window never closes. I've also tried moving the override of the close method out of the popup call completely, same result. What might I be doing wrong?
Most helpful comment
I'm just overriding
closemethod inMagnificPopupobject that is created whenopencallback is fired:You can override any function in this manner...