簡體   English   中英

關閉前的Magnific Popup動作

[英]Magnific Popup action before close

我在我的解決方案中實現了Magnific Popup,我正在使用Bootbox來確認用戶是否要關閉窗口而不保存更改等。

我連接我的自定義函數來關閉回調但它沒有按預期工作。

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

問題是,在我單擊關閉按鈕后,我的圖像(這是彈出窗口的內容)消失了。 我想有機會取消關閉操作並實現我需要在關閉彈出窗口之前觸發的事件。

這是否可以通過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

此代碼僅覆蓋當前打開的彈出窗口! 如果你在關閉后打開相同的彈出窗口,這個回調將會消失!

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

  // your code here

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

};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM