1/* global infinite */ 2/* global console */ 3 4jQuery(document).ready(function($){ 5 6 /** 7 * Append button after all posts 8 */ 9 $('.blog-posts-wrap').append( '<div class="trigger"></div>' ); 10 var page = 2; 11 var lock = false; 12 13 14 $(window).scroll(function(){ 15 var postWrap = $('.blog-posts-wrap'); 16 var button = postWrap.find('.trigger'); 17 var processing = isElementInViewport(button); 18 19 if ( processing === true && lock === false ) { 20 if( page <= infinite.max_page ){ 21 postWrap.append( '<div class="loading text-center"><i class="fa fa-3x fa-spin fa-spinner" aria-hidden="true"></i></div>' ); 22 } 23 24 lock = true; 25 var data = { 26 action: 'infinite_scroll', 27 page: page, 28 nonce: infinite.nonce 29 }; 30 $.post(infinite.ajaxurl, data, function(res) { 31 if( res ) { 32 postWrap.find('.loading').remove(); 33 if( typeof infinite.masonry !== 'undefined' ){ 34 var html = $.parseHTML( res ); 35 var masonryGrid = $('.post-grid-display'); 36 37 $.each( html, function( i, el ){ 38 masonryGrid.append( el ); 39 masonryGrid.masonry( 'reloadItems' ); 40 masonryGrid.imagesLoaded().progress( function() { 41 masonryGrid.masonry('layout'); 42 }); 43 44 }); 45 } else { 46 button.prev().append( res ); 47 } 48 page++; 49 lock = false; 50 } else { 51 console.log(res); 52 } 53 }).fail(function(xhr) { 54 console.log(xhr.responseText); 55 }); 56 57 } 58 59 60 }); 61}); 62 63/** 64 * Detect if an element is in viewport or not 65 * 66 * @param el 67 * @returns {boolean} 68 */ 69function isElementInViewport (el) { 70 71 //special bonus for those using jQuery 72 if (typeof jQuery === 'function' && el instanceof jQuery) { 73 el = el[0]; 74 } 75 76 var rect = el.getBoundingClientRect(); 77 78 return ( 79 rect.top >= 0 && 80 rect.left >= 0 && 81 rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */ 82 rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */ 83 ); 84}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.