Skip to content

Instantly share code, notes, and snippets.

@iwasrobbed
Created April 6, 2011 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save iwasrobbed/906235 to your computer and use it in GitHub Desktop.
Save iwasrobbed/906235 to your computer and use it in GitHub Desktop.
Infinite scrolling modified for ajax
function kickOffAjax(){
// we dont want to fire the ajax multiple times
opts.isDuringAjax = true;
// show the loading message quickly
// then hide the previous/next links after we're
// sure the loading message was visible
props.loadingMsg.appendTo( opts.loadMsgSelector ).show(opts.loadingMsgRevealSpeed, function(){
$( opts.navSelector ).hide();
// increment the URL bit. e.g. /page/3/
opts.currPage++;
debug('heading into ajax',path);
if ($.isFunction(opts.pathParse)){
// if we got a custom path parsing function, pass in our path guess and page iteration
desturl = opts.pathParse(path.join('2'), opts.currPage);
} else {
desturl = path.join( opts.currPage );
}
$.ajax({
url: desturl,
type: 'GET',
dataType: 'html',
success: function (data) {
if (data.trim().length == 0) {
showDoneMsg();
return false;
} else {
// append the ajax data to the end
$(opts.contentSelector).append(data);
// fadeout currently makes the <em>'d text ugly in IE6
props.loadingMsg.fadeOut('normal' );
// smooth scroll to ease in the new content
if (opts.animate){
var scrollTo = $(window).scrollTop() + $('#infscr-loading').height() + opts.extraScrollPx + 'px';
$('html,body').animate({scrollTop: scrollTo}, 800,function(){ opts.isDuringAjax = false; });
}
callback.call( $(opts.contentSelector) );
if (!opts.animate) opts.isDuringAjax = false; // once the call is done, we can allow it again.
}
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment