2013-06-21 88 views
6

我在解決方案已經實現了彈出Magnific酒店和我使用Bootbox擺脫他要關閉窗口而不保存更改用戶確認等彈出Magnific酒店行動前密切

我迷上了我的自定義功能到關閉回調,但它不能按預期工作。

$('#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對話框無法顯示(通常不需要檢查返回值,因爲它作爲參數傳遞,在本例中稱爲結果)。

問題是,我點擊關閉按鈕後,我的圖像(這是彈出的內容)消失。我希望有機會取消關閉操作並實現我需要的事件,然後才能關閉彈出窗口。

用Magnific Popup實現這個可能嗎?

回答

20
// 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

+0

謝謝您的回覆,我休息我的情況:) – Tobiasz

+0

嗨,我已經發布關於您的蕩氣迴腸彈出一個問題,我希望你能幫助http://stackoverflow.com/questions/26272970/image- gallery-with-multiple-title-on-right -side – Learning

+0

這也適用於在close.call行之後放置動作,在我的例子中刷新頁面容器 – Kiwizoom

0

此代碼只覆蓋當前打開彈出!如果您在關閉後打開相同的彈出窗口,則此回調將消失!

$.magnificPopup.instance.st.callbacks.close=function(){ 

    // your code here 

    // this actually close popup 
    $.magnificPopup.proto.close.call(this); 

}; 
相關問題