2013-10-16 155 views
2

我在弹出窗口中有一些窗体控件,并且想阻止用户在窗体无效时关闭它。如何防止关闭

我想这只是一个测试,但当用户点击关闭按钮弹出仍然关闭,等

$.magnificPopup.open({ 
      items: { 
       src: '#topic' 
      }, 
      type: 'inline', 
      removalDelay: 500, //delay removal by X to allow out-animation 
      mainClass: 'mfp-3d-unfold', 
      closeMarkup: '<button title="Close (Esc)" type="button" class="mfp-close"></button>', 
      midClick: true, // Allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source in href. 
      callbacks: { 
       beforeClose: function() { 
        // Callback available since v0.9.0 
        return false; 
       }, 
       close: function() { 
        // Will fire when popup is closed 
        return false; 
       } 
      } 
     }); 

回答

2

根据该文件,如果添加closeOnContentClick: false作为一个选项,窗口不该不结束。

magnificPopup.open({ 
      items: { 
       src: '#topic' 
      }, 
      type: 'inline', 
      closeOnContentClick: false, 
      removalDelay: 500, //delay removal by X to allow out-animation 
      mainClass: 'mfp-3d-unfold', 
      closeMarkup: '<button title="Close (Esc)" type="button" class="mfp-close"></button>', 
      midClick: true 
     }); 

不过,我一直在试图让一个Ajax窗口时,里面有它(的形式)和加入这个选项在所有不工作(很可能为其工作,点击不关闭内联)。到目前为止,我能够实现它的唯一方法是向弹出窗口中的所有子节点添加一个mfp-prevent-close类(例如所有表单输入字段,周围字段集等)。

希望这有助于反正:)

+1

我刚刚发现这个答案 - http://stackoverflow.com/questions/18215477/why-magnific-popup-ajax-box-closes-if-clicked-on-content - 看起来像你可以尝试添加模态:true而不是closeOnContentClick:false – BellamyStudio

0

我终于找到了GitHub

您需要更换代码

// if click is outside the content 
if((target !== mfp.content[0] && !$.contains(mfp.content[0], target))) { 

的下面一行的解决方案

// if click is outside the content 
if((target !== mfp.content[0] && !$.contains(mfp.content[0].parentElement, target))) { 

它为我解决了这个问题。