(function ($) { 'use strict'; $(window).load(function(){ var magnifPopup = function () { $('.work-popup').magnificPopup({ type: 'image', removalDelay: 300, mainClass: 'mfp-with-zoom', gallery: { enabled: true }, zoom: { enabled: true, // By default it's false, so don't forget to enable it duration: 300, // duration of the effect, in milliseconds easing: 'ease-in-out', // CSS transition easing function // The "opener" function should return the element from which popup will be zoomed in // and to which popup will be scaled down // By defailt it looks for an image tag: opener: function (openerElement) { // openerElement is the element on which popup was initialized, in this case its tag // you don't need to add "opener" option if this code matches your needs, it's defailt one. return openerElement.is('img') ? openerElement : openerElement.find('img'); } } }); }; // Call the functions magnifPopup(); var $container = $('.gallery-work'); $container.isotope({ //Isotope options, 'item' matches the class in the PHP itemSelector : '.gitem', layoutMode : 'masonry' }); $('.gallery-menu a').click(function(){ $('.gallery-menu .current').removeClass('current'); $(this).addClass('current'); $('.loadmorebtn').css('margin-top',0); var selector = $(this).attr('data-filter'); $container.isotope({ filter: selector, animationOptions: { duration: 750, easing: 'linear', queue: false } }); return false; }); $( document ).on( 'click', '#loadposts', function() { var path = $(this).attr('data-path'), page = $(this).attr('data-page-next'), offset = $(this).attr('data-offset'), pagetotal = $(this).attr('data-page-total'); var nextpage = parseInt(page)+1; var nextoffset = parseInt(offset)+parseInt(offset); var margin = (parseInt(offset)/parseInt(pagetotal)) * 287; //alert(margin); if(nextpage>=pagetotal){ $('.load-more-button').remove(); } // alert(page); $.ajax({ url : templateUrl+'/infinite-posts.php', type : 'post', data : { path: path, page: page, offset : offset }, success : function( response ) { //alert(response); // var mediaItemContainer = $( '.gallery-work' ); $container.append( response ).isotope( 'reloadItems' ).isotope({ sortBy:'original-order' }); $('#loadposts').attr('data-page-next',nextpage); $('#loadposts').attr('data-offset',nextoffset); $('.loadmorebtn').css('margin-top',287); magnifPopup(); } }); }); }); })(jQuery);