Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery(document).ready(function($){
- function find_page_number( element ) {
- element.find('span').remove();
- return parseInt( element.html() );
- }
- // //Trigger ajax at the end of page
- $(window).scroll(function(){
- var top = $('body.home').scrollTop();
- //console.log(top);
- var height = $(window).height();
- // console.log(height);
- var docheight = $(document).height();
- // console.log('docheight: '+ docheight);
- var screen = Number(docheight) - Number(height);
- // console.log('screen: ' + screen);
- // if( top >= height ){
- // $('a.showmore').click();
- // }
- });
- function yHandler() {
- var wrap = document.getElementById('primary');
- var contHeight = wrap.offsetHeight;//get page content height
- //get vertical scroll position
- var yOffset = window.pageYOffset;
- var y = yOffset + window.innerHeight;
- // console.log(y);
- if( y >= contHeight ){
- $('a.showmore').click();
- }
- }
- window.onscroll = yHandler;
- var page = 1;
- var count = 10;
- $('a.showmore').on('click', function( event ){
- event.preventDefault();
- //console.log('clicked');
- page++;
- if(request){
- request.abort();
- }
- var request = $.ajax({
- url: ajaxpagination.ajaxurl,
- type: 'post',
- data: {
- action: 'ajax_pagination',
- query_vars: ajaxpagination.query_vars,
- page: page,
- postType: $(this).data('type')
- },
- beforeSend: function(){
- },
- success: function( html ) {
- $('#loader').remove();
- $('#primary-grid:last').append( html );
- //console.log( html);
- $('.grid').ajaxComplete(function () {
- //console.log('done');
- var post = $('.grid > article');
- if(!$(post).hasClass('post-num-1')){
- $(post).removeClass('xlarge-66 large-66');
- $(post).addClass('all-33 small-100 tiny-100');
- }
- $(post).on('mouseover', function () {
- //console.log('hover ok');
- $(this).addClass('t5-effect');
- });
- $(post).on('mouseout', function () {
- $(this).removeClass('t5-effect');
- });
- });
- if(html == '' || null){
- //$('a.showmore').hide();
- $('a.showmore').remove();
- $('.grid:last').after( '<div class="no-more-posts sr-only" style="text-align:center;">No More Posts to Show</div>' );
- function remove_no_more_posts() {
- $('.no-more-posts').remove();
- }
- setTimeout(remove_no_more_posts, 150);
- $.ajaxStop
- }
- }
- // complete: $.ajaxStop
- })
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement