Skip to content

Instantly share code, notes, and snippets.

@imlucas
Created May 8, 2009 22:49
Show Gist options
  • Save imlucas/109040 to your computer and use it in GitHub Desktop.
Save imlucas/109040 to your computer and use it in GitHub Desktop.
$.hotness = function(options){
var wpFeedUrl = options.url;
var currentPage = 1;
var isLoading = false;
var debug = options.debug || false;
var loader;
function init(){
if($('#content-container-loader').length <1){
$(options.loader).insertAfter('.post:last');
$('#content-container-loader').hide();
}
loader = $('#content-container-loader');
$(window).scroll(handleScroll);
};
function debug(m){
(typeof console=='object') ? console.info(m) : '';
}
function fixItems(items){
var clean = [];
$.each(items, function(){
var i = this;
i.id = this.guid.content.match(/\d+/);
clean.push(i);
});
return clean;
}
function handleScroll(e){
if(($(window).scrollTop()+$(window).height())>=$('#content-container-loader').position().top){
if(!isLoading){
loader.show();
var getUrl = [wpFeedUrl, 'paged='+paged].join((wpFeedUrl.indexOf('?') < 0) ? '?':'&');
$.getJSON(
'http://pipes.yahoo.com/pipes/pipe.run',
{
'_render':'json',
'_callback':'?',
's': getUrl,
'_id':'eef101a0a8eb8cb109a60feb521a5012'
},
function(data){
isLoading = false;
currentPage++;
var items = fixItems(data.value.items);
// Track it on google analytics
// @todo(lucas) Tpl for url to track as?
pageTracker._trackPageview(getUrl);
$.each(items, function(){
$(loader).before($.template(options.postTemplate),this);
});
loader.hide();
if(jQuery.isFunction(options.callback)){
options.callback(items);
}
}
);
isLoading = true;
}
else{
debug('handle scroll called, but still loading previous');
}
};
}
/*
var loaderHtml = '<div id="content-container-loader" class="post"><p style="width: 265px; height: 200px; text-align: center; vertical-align: middle; display: table-cell;"><img width="32" height="32" src="http://preloaders.net/generator.php?image=71&amp;speed=2&amp;fore_color=B71818&amp;back_color=000000&amp;size=100x64&amp;transparency=0&amp;uncacher=94.50223290112753" style="height: 64px; width: 100px; margin-bottom: 16px;"/><br/>Loading more heavy shit...</p></div>';
$.hotness({
url: 'http://www.theheavyedition.com/feed',
debug: true,
loader: loaderHtml
});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment