First of all, sorry about my english (spanish speaker) and about any other misunderstanding (first publication on GitHub). Next, Magnific-Popup it's a great script.
The issue: ajaxContentAdded callback is not firing on second term. I change the content of the popup firing magnificPopup from clicking an element of the previously opened popup.
Extended version: i have a header with login / register links. Both are shown as magnificPopup[ajax] and i want to make a few things after popup is shown. But in login popup i also have a link to register and when i click on it, the expected event is not fired.
assignRegisterPopup = function(selector) {
$(selector).magnificPopup({
type: 'ajax',
callbacks: {
ajaxContentAdded: function() {
if ($('.inner_header a.show_login').hassClass('active')) $('.inner_header a.show_login').removeClass('active'); //change style in header, if need
$( '.register_popup a.popup_cancel' ).on( 'click',function() {$.magnificPopup.close();}); //another close link included in design
$('.inner_header a.show_register').addClass('active'); //change style in header
},
afterClose: function() {
$('.inner_header a.show_register').removeClass('active'); //change style in header
},
}
});
};
assignRegisterPopup('.inner_header a.show_register');
$('.inner_header a.show_login').magnificPopup({
type: 'ajax',
callbacks: {
ajaxContentAdded: function() {
assignRegisterPopup('.login_popup a.show_register' ); //want to change the content
$( '.login_popup a.popup_cancel' ).on( 'click',function() {$.magnificPopup.close();}); //another close link included in design
$('.inner_header a.show_login').addClass('active'); //change style in header
},
afterClose: function() {
$('.inner_header a.show_login').removeClass('active'); //change style in header
},
}
});
I have the exact same issue, did you find a workaround?
Just debugged. Exact same issue for me. It's been one year since the last message from @hvaleanu... Did everyone find a workaround? If not, I'll have to edit the plugin myself.
Ok I found a workaround. It is to run $.magnificPopup.close() before running $.magnificPopup.open() again. The bug was due to the fact that if the popup is already open, MFP will run only an HTML update, without updating the internal option object. Closing the popup before opening it again is the quick and dirty workaround to this issue.
could you give sample code to a beginner to achieve this?
Most helpful comment
Ok I found a workaround. It is to run
$.magnificPopup.close()before running$.magnificPopup.open()again. The bug was due to the fact that if the popup is already open, MFP will run only an HTML update, without updating the internal option object. Closing the popup before opening it again is the quick and dirty workaround to this issue.