【问题标题】:determining how a simplemodal window was closed via an iframe or closeHTML, escClose or overlayClose确定如何通过 iframe 关闭 simplemodal 窗口并关闭 HTML、enClose 或覆盖 Close
【发布时间】:2012-05-08 23:42:18
【问题描述】:
我正在使用 simplemodal 通过 iframe 显示表单。 form 可以关闭 modal,onClose 回调可以刷新主屏幕,更新屏幕上的信息。但如果 iframe 表单没有关闭模式,我不想刷新主屏幕。换句话说,我不想在 closeHTML、escClose 或 overlayClose 的简单关闭时刷新屏幕。
如果关闭是通过closeHTML、escClose 或overlayClose 调用的,onClose 回调中是否有办法确定关闭模式的内容?
【问题讨论】:
标签:
jquery
jquery-plugins
simplemodal
【解决方案1】:
我确信有更好的方法来做到这一点,但这可能会让你走上正轨。
- 编辑插件为每种关闭类型设置数据属性值
- 使用 onClose 回调获取数据属性
插件代码
// bind the close event to any element with the closeClass class
$('.' + s.o.closeClass).bind('click.simplemodal', function (e) {
e.preventDefault();
// set 'closeType' data attr
$('body').data('closetype', 'closeClass');
s.close();
});
// bind the overlay click to the close function, if enabled
if (s.o.modal && s.o.close && s.o.overlayClose) {
s.d.overlay.bind('click.simplemodal', function (e) {
e.preventDefault();
// set 'closeType' data attr
$('body').data('closetype', 'overlayClose');
s.close();
});
}
// bind keydown events
doc.bind('keydown.simplemodal', function (e) {
if (s.o.modal && e.keyCode === 9) { // TAB
s.watchTab(e);
}
else if ((s.o.close && s.o.escClose) && e.keyCode === 27) { // ESC
e.preventDefault();
// set 'closeType' data attr
$('body').data('closetype', 'escClose');
s.close();
}
});
插件初始化
// Load dialog on click
$('#basic-modal .basic').click(function (e) {
$('#basic-modal-content').modal({
overlayClose: true,
onClose: function() {
console.log($('body').data('closetype'));
$.modal.close();
}
});
return false;
});