关闭前的Magnific Popup动作 [英] Magnific Popup action before close
问题描述
我已在我的解决方案中实施了Magnific Popup,我正在使用 Bootbox 来确认用户是否要关闭窗口而不保存更改,等等。
I have implemented Magnific Popup in my solutions and I am using Bootbox to get confirmation from the user that he wants to close the window without saving changes, etc.
我将自定义函数连接到关闭回调,但它无法按预期工作。
I hooked up my custom function to close callback but it doesn't work as expected.
$('#divThumbnails').magnificPopup({
delegate: 'a',
type: 'inline',
midClick: true,
callbacks: {
close: function () {
var confirm = bootbox.confirm('Are you sure?', function(result) {
});
if (confirm)
return true;
else
return false;
}
}
});
这只是一个快速的样本,而不是生产代码。 if-else语句在那里,因为否则Bootbox对话框无法显示(通常不需要检查返回的值,因为它作为参数传递,在本例中称为结果)。
This is just a fast sample, not production code. The if-else statement is there because otherwise Bootbox dialog fails to show (normally there is no need to check the returned value as it is passed as argument which in this example is called result ).
问题是,在我点击关闭按钮后,我的图像(这是弹出窗口的内容)消失了。我希望有机会取消关闭操作并实现我需要在关闭弹出窗口之前触发的事件。
The problem is that after I click the close button my image (which is the content of the popup) disappears. I would like to have an opportunity to cancel the close operation and to achieve that I need an event that will fire BEFORE closing the popup.
这是否可以通过Magnific实现Popup?
Is this possible to achieve with Magnific Popup ?
推荐答案
// 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);
};
http://codepen.io/dimsemenov/pen/edCgo
这篇关于关闭前的Magnific Popup动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!