Skip to content

Instantly share code, notes, and snippets.

@tmort
Created January 29, 2013 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmort/4666399 to your computer and use it in GitHub Desktop.
Save tmort/4666399 to your computer and use it in GitHub Desktop.
WPSocialite.js Modified to load the scrolling icons 100 px before window shows them.
jQuery(function($) {
Socialite.process(); //processing each instance before we take any action. Makes sure pinterest loads individually and not all together.
if ( $("body").hasClass("wpsocialite-scroll") ) { //If set to 'scroll'
var articles = $('.social-buttons'), socialised = { }, win = $(window), updateArticles, onUpdate, updateTimeout;
updateArticles = function()
{
// viewport bounds
var wT = win.scrollTop(),
wL = win.scrollLeft(),
wR = wL + win.width() + 100 ,
wB = wT + win.height() + 100;
// check which articles are visible and socialise!
for (var i = 0; i < articles.length; i++) {
if (socialised[i]) {
continue;
}
// article bounds
var art = $(articles[i]),
aT = art.offset().top,
aL = art.offset().left,
aR = aL + art.width(),
aB = aT + art.height();
// vertial point inside viewport
if ((aT >= wT && aT <= wB) || (aB >= wT && aB <= wB)) {
// horizontal point inside viewport
if ((aL >= wL && aL <= wR) || (aR >= wL && aR <= wR)) {
socialised[i] = true;
Socialite.load(articles[i]);
}
}
}
};
onUpdate = function()
{
if (updateTimeout) {
clearTimeout(updateTimeout);
}
updateTimeout = setTimeout(updateArticles, 100);
};
win.on('resize', onUpdate).on('scroll', onUpdate);
setTimeout(updateArticles, 100);
} else { //If not set to 'scroll', default to hover
$('.social-buttons').parent().one('mouseenter', function(){
Socialite.load($(this)[0]);
});
}
});//theend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment