(function ($) { var settings = $.extend({ pages: undefined, ajax_url: undefined, ajax_action: undefined }, anpip_settings); function open_popup() { var $this = $(this); var post_id = $this.data('post_id'); $.magnificPopup.open({ items: { src: settings.ajax_url }, type: 'ajax', ajax: { settings: { data: { action: settings.ajax_action, post_id: post_id } } }, callbacks: { beforeOpen: function() { $('body').addClass('body-mfp-open'); }, afterClose: function() { $('body').removeClass('body-mfp-open'); }, } }, 0); return false } $(document).ready(function () { for (var i in settings.pages) { if (!settings.pages.hasOwnProperty(i)) continue; $('a[href="' + settings.pages[i] + '"]') .data('post_id', i) .attr('href', '#') .on('click', open_popup); } }); })(jQuery);