! function($, undefined) { $(function() { // Image Loading Effects // Function to handle image loading var fOnImagesLoad = function( oCallback ) { // Loop through every instagram image $(".insta-post img").each( function() { // If the image has loaded from cache if (this.complete | $(this).height() > 0) { // Call the callback oCallback.apply(this); } // When the image is loaded else { $(this).on('load', function() { // Call the callback oCallback.apply(this); }); } }); }; // On image loaded fOnImagesLoad( function() { // Make the image fade in (transition speed is set in css ) $(this).css( { opacity : 1 } ); }); // Stop close modal on inner element clicks $('.modal-content').on('click', '.image-container', function(e){ e.stopPropagation(); e.stopImmediatePropagation(); }); // Close modal $('.modal-container .modal-close, .modal-container, .modal-content').click(function(e) { // Fade out the modal $('.modal-container').fadeOut('fast', function() { // Remove the embed url $('.modal-container').html( "" ); }); // Reset the overflow $('html').css({ 'overflow-y': 'auto'}); }); // Clicking on the Load More link $('.load-more').click(function() { $.ajax( { cache: false, type: 'get', url: window.location.href+'?next_url='+encodeURIComponent($(this).data('url')), success: function(response) { var $res = $(response); // hide all image-container classes found in the response and append them to our instagram container (so we can fade it in below) var $filter = $res.find(".insta-row"); // Store the amount found (Get the last clearfix and the amount of items after it to work out the count) var nCount = $( ".insta-clear" ).last().nextAll().length; $filter.find('.insta-post').each(function(index) { // Increment the count nCount++; // Add to the insta row $('.insta-row').append($(this)); }); // On image loaded fOnImagesLoad( function() { // Make the image fade in (transition speed is set in css ) $(this).css( { opacity : 1 } ); }); // Only show Load More if there are more images to load if ( $res.find('.load-more').length ) { $('.load-more').data('url', $res.find('.load-more').data('url')); } else { $('.load-more').remove(); } } }); }); }); }(jQuery);