2013-10-16 154 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))) { 

它爲我解決了這個問題。