Open() method doesn't work for the dynamic popups
See original GitHub issue// Open popup immediately. If popup is already opened - it’ll just overwite the content (but old options will be kept). // - first parameter: options object // - second parameter (optional): index of item to open $.magnificPopup.open({ items: { src: ‘someimage.jpg’ }, type: ‘image’
// You may add options here, they’re exactly the same as for $.fn.magnificPopup call // Note that some settings that rely on click event (like disableOn or midClick) will not work here }, 0);
This doesn’t work for a dynamically created popups.
Here’s an example http://jsbin.com/esebEGa/1
Child static works well:
$('.toggle').each(function() {
var item = $(this);
var decor = item.data('mfp-decor');
item.magnificPopup({
type: 'inline',
midClick: true,
removalDelay: 400,
mainClass: function() {
var classname = 'mfp-fade';
if (decor && decor.length) {
classname = classname + ' ' + decor;
}
return classname;
}
});
});
Child dymanic doesn’t work:
$('.dynamic').on('click', function(event) {
event.preventDefault();
$.magnificPopup.open({
items: {
src: '<div class="popup popup-status">Dynamic</div>'
},
type: 'inline',
showCloseBtn: false,
removalDelay: 400,
mainClass: 'mfp-status'
});
});
If child dymanic link is clicked, both popups are closed.
I’ve also tried this solution https://github.com/dimsemenov/Magnific-Popup/issues/53#issuecomment-17804411 - same result, both popups are closed once you try to open a dynamically created popup.
Issue Analytics
- State:
- Created 10 years ago
- Comments:10 (1 by maintainers)
Top GitHub Comments
Thank you, I’ll look into it.
By the way, to fix this you may just add
event.stopImmediatePropagation();
on that.dynamic
click event handler, so the event won’t come to popup at all.Has there been any update on this?