Created
June 21, 2016 14:25
-
-
Save SaFrMo/b0c336d1c1a8581470201a65f1efd27d to your computer and use it in GitHub Desktop.
Infinite scroll on Teller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// if not currently loading AND page has teaser AND page is scrolled to teaser area | |
var teaserHeight = 250; | |
if ( !jt2016.loadingPost && jQuery('.teaser').length && (jQuery('.teaser').offset().top < jt2016.sTop + jQuery(window).height() - teaserHeight) ) { | |
// get url from teaser element | |
var url = jQuery('.teaser').data('url'); | |
// make new promise | |
jt2016.loadingPost = jQuery.ajax(url, {dataType: 'html'}).promise().done(function(data){ | |
// parse new page | |
var $html = jQuery(data); | |
// get and set up pieces of page | |
var $bookingLink = $html.find('#fixed-header .booking-link'); | |
var $entry = $html.find('#content .entry'); | |
var $teaser = $html.find('.teaser'); | |
// add entry to current page | |
jQuery('.teaser .meta').after($entry); | |
// turn teaser into incoming post, append new teaser | |
var $newPost = jQuery('.teaser') | |
.removeClass('teaser') | |
.attr('id', $html.find('#content .post').attr('id')) | |
.addClass('loaded-async') | |
.after($teaser); | |
// add horizontal bar after incoming post's Next Article divider | |
$newPost.find('.next-article').after('<div class="horizontal-line"></div>'); | |
// focus on that bar and add class to animate | |
$newPost.find('.horizontal-line').focus().addClass('loaded'); | |
// re-run some init functions | |
jt2016.onAjaxComplete(); | |
// get html of new booking link | |
var bookingLinkHTML = $bookingLink.html() || ''; | |
// push incoming state to cache | |
jt2016.blogPostCache.push({ | |
top: $newPost.offset().top, | |
url: url, | |
bookingLink: bookingLinkHTML, | |
title: $html.filter('title').text() | |
}); | |
// reset ajax promise | |
jt2016.loadingPost = false; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is what I ended up doing: