Monday, June 1, 2009

jQuery social bookmarking plugin

I was just working on trying to get a social bookmarking tool installed on one of my sites and came across two very good ones ShareThis and AddThis. Both seem to be very good but the AddThis tool operates on ssl sites. So, accordingly, I went with AddThis. The plugin code was a little too long for me, an example as follows:


Bookmark and Share



I decided to write a jQuery plugin to leverage simpler code. The following is the plugin jquery.addthis.js:

/*
* Addthis 1.0
* (c)2009 Brent Wong
*/
(function($){
$.addthis = function(code){

function init(){
try{
// determine whether to include the normal or SSL version
var addthisurl = (location.href.indexOf('https') == 0 ? 'https://' : 'http://') + 's7.addthis.com/js/250/addthis_widget.js?pub=' + code;

// include the script
$.getScript(addthisurl, function(){
$('a.addthis').append('<img src="http://s7.addthis.com/static/btn/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/>').attr('href', 'http://www.addthis.com/bookmark.php?v=250').mouseover(
function(){
return addthis_open(this, '', '[URL]', '[TITLE]');
}).mouseout(
function(){
addthis_close();
}).click(
function(){
return addthis_sendto();
});
});
} catch(err) {
// log any failure
console.log('Failed to load AddThis Script:' + err);
}
}

init();
}
})(jQuery);


Then all you have to do is create a link such as this:

<a class="addthis"></a>


And include the jQuery command in the header:

$(function(){
$.addthis('publishername');
});


And voila, you have AddThis links.

4 comments:

  1. Please Write review about this site:
    Check backlinks in 26 social bookmarking
    Social Scan

    ReplyDelete
  2. thanks for the information, I’ll be making the necessary changes thanks to your tips.i enjoyed the post, you have a nice site.



    communicate

    ReplyDelete