supasympa
12/5/2011 - 2:54 PM

Some code to update ShareThis buttons with custom images - useful in SPAs or AJAX apps

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();
  }