I'm trying to override the Magnific Popup close
method (as outlined in the documentation and answered here by the developer in another question). However, when using the open
method to create the popup (rather than attaching to an element in the DOM), the $.magnificPopup.proto
isn't accessible.
Here's my example of non-working code. As you can see, I'm trying to override the close
method once the popup opens. The console.log
fires when I try to close (either by my Close button or by hitting ESC) but the box does not close.
$.magnificPopup.open({
items: {
src: '/path/to/file',
type: 'ajax',
},
callbacks: {
open: function() {
$.magnificPopup.instance.close = function() {
console.log('close override is working');
$.magnificPopup.proto.close.call(this);
}
},
ajaxContentAdded: function() {
var m = this;
this.content.find('.redbutton').on('click', function(e) {
e.preventDefault();
m.close();
});
}
},
closeOnContentClick: false,
closeOnBgClick: false,
showCloseBtn: false,
enableEscapeKey: true
});
How can I close the box?