Skip to content

Instantly share code, notes, and snippets.

@paulirish
Created October 29, 2009 16:48
Show Gist options
  • Save paulirish/221589 to your computer and use it in GitHub Desktop.
Save paulirish/221589 to your computer and use it in GitHub Desktop.
// sharethis plugin by paul irish
// usage:
// $('a.sharethistrigger').shareThis();
// for ShareThis
$.fn.shareThis = function(){
if (!$(this).length) return this; // quit if theres nothing.
// this path should come out of the configurator
var mycustom = document.location.protocol + '//w.sharethis.com/widget/?tabs=email%2Cweb&charset=utf-8&services=reddit%2Cdigg%2Cfacebook%2Cmyspace%2Cdelicious%2Cstumbleupon%2Ctechnorati%2Cgoogle_bmarks%2Cyahoo_bmarks%2Cyahoo_myweb%2Cwindows_live%2Cfriendfeed%2Cnewsvine%2Cxanga%2Cmixx%2Cmagnolia&style=default&publisher=ed1f9543-f910-4aa8-a989-3f5385932fb0&headerbg=%23000000&inactivebg=%23272727&inactivefg=%23b3b3b3&linkfg=%23FF6702';
// this needs to be in the query string.
mycustom = mycustom.replace('&button=false','')+'&button=false';
var elems = this;
setTimeout(function(){
if (typeof SHARETHIS != 'undefined') attachButtons();
else $.getScript(mycustom,attachButtons);
},700); // 700 ms delay.
function attachButtons(){
if (typeof SHARETHIS == 'undefined') debug('SHARETHIS is undefined after scriptgrab',arguments);
$(elems).filter(':visible').each(function(){
var left = $(this).offset().left + $(this).width() - 354; // 354 is the hardcoded width of .stwrapper, the sharethis box.
SHARETHIS.addEntry({ title: document.title}, { button: false, offsetLeft: left }).attachButton(this);
});
SHARETHIS.onReady();
}
return $(this).click(function(e){ e.preventDefault(); });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment