PHP and javascript snippets you can copy and paste.

Sunday, April 15, 2007

js_create_socialBookmarks(container,path_to_icons)

/**
* Creates links to social bookmarking sites.
*
* @param object container - div, span etc element to hold links.
* @param string path_to_icons - path to where the social bookmarking sites icons are.
*/

function js_create_socialBookmarks(container,path_to_icons){

var page = window.location;
var title = window.document.title;

links = new Array();

if(!path_to_icons || path_to_icons=='undefined'){
path_to_icons = './';
}

// Digg.
link = document.createElement('A');
link.href = "http://digg.com/submit?phase=2&url=" + escape(page) + "&title=" + escape(title);
link.setAttribute('title','Digg');
img = document.createElement('IMG');
img.setAttribute('src', path_to_icons + 'digg.png');
img.setAttribute('border','0');

img.setAttribute('alt','digg');
link.appendChild(img);
links[links.length] = link;

// Delicious.
link = document.createElement('A');
link.href = "http://del.icio.us/post?url=" + escape(page) + "&title=" + escape(title);
link.setAttribute('title','del.icio.us');
img = document.createElement('IMG');
img.setAttribute('src', path_to_icons + 'delicious.png');
img.setAttribute('border','0');
img.setAttribute('alt','del.icio.us');
link.appendChild(img);
links[links.length] = link;

// Stumbleupon.
link = document.createElement('A');
link.href = "http://www.stumbleupon.com/url/" + escape(page);

link.setAttribute('title','StumbleUpon');
img = document.createElement('IMG');
img.setAttribute('src', path_to_icons + 'stumbleupon.png');
img.setAttribute('border','0');
img.setAttribute('alt','StumbleUpon');
link.appendChild(img);
links[links.length] = link;

// Reddit.
link = document.createElement('A');
link.href = "http://reddit.com/submit?url=" + escape(page) + "&title=" + escape(title);
link.setAttribute('title','Reddit');
img = document.createElement('IMG');
img.setAttribute('src', path_to_icons + 'reddit.png');
img.setAttribute('border','0');
img.setAttribute('alt','Reddit');
link.appendChild(img);

links[links.length] = link;

// Technorati
link = document.createElement('A');
link.href = "http://technorati.com/faves?add=" + escape(page);
link.setAttribute('title','Technorati');
img = document.createElement('IMG');
img.setAttribute('src', path_to_icons + 'technorati.png');
img.setAttribute('border','0');
img.setAttribute('alt','Technorati');
link.appendChild(img);
links[links.length] = link;

// Furl.
link = document.createElement('A');
link.href = "http://www.furl.net/storeIt.jsp?u=" + escape(page) + "&t=" + escape(title);
link.setAttribute('title','Furl');
img = document.createElement('IMG');

img.setAttribute('src', path_to_icons + 'furl.png');
img.setAttribute('border','0');
img.setAttribute('alt','Furl');
link.appendChild(img);
links[links.length] = link;

// Slashdot.
link = document.createElement('A');
link.href = "http://slashdot.org/bookmark.pl?title=" + escape(title) + "&url=" + escape(page);
link.setAttribute('title','Slashdot');
img = document.createElement('IMG');
img.setAttribute('src', path_to_icons + 'slashdot.png');
img.setAttribute('border','0');
img.setAttribute('alt','Slashdot');
link.appendChild(img);

links[links.length] = link;

// Blinklist.
link = document.createElement('A');
link.href = "http://www.blinklist.com/index.php?Action=Blink/addblink.php&Url=" + escape(page) + "&Title=" + escape(page);
link.setAttribute('title','BlinkList');
img = document.createElement('IMG');
img.setAttribute('src', path_to_icons + 'blinklist.png');
img.setAttribute('border','0');
img.setAttribute('alt','BlinkList');
link.appendChild(img);
links[links.length] = link;

var max = links.length-1;

for(i=0;i<max;i++){

container.appendChild(links[i]);
}

}

1 comment:

admin said...

Tested 15 April 2007.