Skip to content

Instantly share code, notes, and snippets.

@supasympa
Created December 5, 2011 14:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supasympa/1433849 to your computer and use it in GitHub Desktop.
Save supasympa/1433849 to your computer and use it in GitHub Desktop.
Some code to update ShareThis buttons with custom images - useful in SPAs or AJAX apps
function updateShareButtons(location, title, imgsrc) {
$('.share').hide();
$('.sharethis').html('');
var services = [
{type : 'facebook',
image : './css/img/social-facebook.png'},
{type : 'twitter',
image : './css/img/social-twitter.png'},
{type : 'email',
image : './css/img/social-email.png'},
{type : 'sharethis',
image : './css/img/social-more.png'}
];
var svc, elm;
for (var i = 0; i < services.length; i++) {
svc = services[i];
elm = $(['<span class="st_',svc.type,'_custom" st_url="',location,'" st_title="',title,'" st_image="',imgsrc,'"><img src="',svc.image,'"/></span>'].join(''));
$('.sharethis').append(elm);
}
stButtons.locateElements();
$('.share').show();
}
@supasympa
Copy link
Author

OK so it uses jQuery but it wouldn't be hard to change it to a pure Javascript version.
Obviously you'll need to change the services and their associated images.
The function is called with three properties:

location: the location url to share
title : the title to share
imgsrc : the image (icon) to share

@kmakarem
Copy link

kmakarem commented Dec 1, 2016

Simple and great code.

shareThis still did not implement an updateEntity fn so this is still effective.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment