Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magnific Popup Callback when closing

I am using Magnific Popup for uploading images. When the user clicks or presses the close button, I'd like to get confirmation from the user whether to close on not.

This is my Javascript:

$('#upload').magnificPopup({
    type:'inline',
    callbacks: {
        close: function(){
            if( confirm("Are you sure you want to close?") ) {
              return true;
            }
              return false;
            }
          }
      }
});

But it is not working.

like image 277
KKK Avatar asked Jun 14 '13 05:06

KKK


2 Answers

You can override the close method. By modifying the instance, you will only change the functionality of this specific popup. Then simply call the original close method to finish the job.

$('#upload').magnificPopup({
  type:'inline',
  callbacks: {
    open: function() {
      $.magnificPopup.instance.close = function() {
        // Do whatever else you need to do here
        var confirmed = confirm("Are you sure you want to close?");
        if(!confirmed) {
          return;
        }

        // Call the original close method to close the popup
        $.magnificPopup.proto.close.call(this);
      };
    }
  }
});
like image 165
Michael Irigoyen Avatar answered Oct 04 '22 02:10

Michael Irigoyen


You could try:

( '#upload' ).magnificPopup({
    type: 'inline',
    callbacks: {
      close: function(){
         var didConfirm = confirm( "Are you sure?" );
         if( didConfirm == false ){
            return false;
         }
      }
    }
});
like image 39
CodeHunter Avatar answered Oct 04 '22 04:10

CodeHunter