Delicious was founded by Joshua Schachter in 2003 and acquired by Yahoo in 2005. This website was formerly used to run in the domain http://del.icio.us hence known as del.icio.us. Now, this domain redirects to the domain http://delicious.com. This website got redesigned in July 2008 and the Delicious 2.0 went live with new domain, design and name.
Delicious is probably one of the largest social bookmarking website in the WWW world for discovering, sharing and storing the interesting and useful URL on the Internet. When saving the URL, user can enter tags for the URL which is quite useful when you’ve to search the particular URL from many bookmarks. The number of saves of a particular URL in Delicious is one of the measurements for checking popularity of that URL.
As the name specifies, Delicious Tagometer is a badge which displays the tags as well count of the users who have saved the particular URL.
Tagometer gets displayed in the web page which contains the code given below:
This is the new URL of the Tagometer badge from the Delicious. The URL for the Tagometer used to be different in the del.icio.us domain in past. For more information on future updates, you can check http://delicious.com/help.
The delicious Tagometer looks as shown:
As you can easily guess, the above Tagometer is placed on a web page whose URL has not yet been saved in Delicious.
Now let’s take a look at the Tagometer which is placed on a web page whose URL is saved by many users of Delicious.
In the above widget, the text “bookmark this on Delicious” is the hyperlink for saving the URL in delicious.
To save an URL in Delicious, you have to provide the URL and give a Title on the http://delicious.com/save page.
After clicking on the “bookmark this on Delicious” hyperlink on the Delicious Tagometer widget you can see the image of the web page on delicious.
And, the number is linked to the URL specific page on Delicious. For example, if you wish to view the users and their notes on the saves of the URL- http://digg.com, then the URL of delicious will be http://delicious.com/url/926a9b7a561a3f650ff41eef0c8ed45d
The last part “926a9b7a561a3f650ff41eef0c8ed45d” is the md5 hash of the URL http://digg.com.
The md5 is a one way hashing algorithm which converts a given string to a 32 character long string known as md5 digest. This hashed string can’t be reversed back into original string. The md5 function protects and ensures data integrity of Delicious Data Feeds.
Delicious data feeds are read-only web feeds containing bookmark information and other information which can be used third party websites. These feeds are available into two different format: RSS and JSON.
Among the various data feeds on the Delicious, let’s look at the details of the data feed which contains summary information of a URL. According to Delicious feed information page, these data feed for URL information can be retrieved via following call,
It clearly specifies summary of URL can be retrieved in the json format only from Delicious.
To get the summary about a URL, You can provide the actual URL in the url parameter of the above URL. Alternatively, you can provide md5() hash of the url in the hash parameter in the above URL.
Now, let’s look at feed URLs which can be used to access the summary of the http://digg.com from Delicious:
From the above URLs, it is clear that md5 hash of the string “http://digg.com” is 926a9b7a561a3f650ff41eef0c8ed45d
Now, let look at the JSON data which is returned from any of the above URL of Delicious feed.
As you can see clearly, the above JSON data contains hash of URL, the URL itself, total no of saves in Delicious in total_posts variable. Along with them, different tags including number of times that tag is used by different users of Delicious for saving the URL http://digg.com.
If the URL is not saved in Delicious then data returned from Delicious feed will be like this : displayTotalSaves()
Now, having understod the information returned above, let’s see how to create Delicious widget step by step.
Creating Delicious Tagometer Widget
Our Delicious Tagometer widget looks very similar to actual Delicious Tagometer widget but has different format and texts. In the Tagometer badge provided by delicious, there is no option for specifying a particular URL whose summary is to be displayed. It automatically displays the details of the URL of the web page containing the code. While in our custom widget, you can also specify the URL explicitly in the badge which is an optional parameter.
The above image is of the Delicious widget which we’re going to make and you can see clearly that the provided URL is not yet saved on Delicious.
Now, let’s look at the Custom Delicious Tagometer which we can see for a URL saved on the delicious.
The above badge of delicious is displayed for the URL: http://yahoo.com.
Writing Code for Delicious
As can be seen from the above code, if the variable delicious_widget_url is not defined already then the URL of the current document encoded with encodeURIComponent() function is assigned to this variable.
If delicious_widget_url variable is already defined then it is encoded with encodeURIComponent() function and assigned to the same variable.
Similarly, if the variable delicious_widget_title is not defined then document.title, which contains title of current web page, is encoded with encodeURIComponent() function and assigned to the delicious_widget_title variable .
Next, a variable del_rand_number is defined for handling multiple instances of the widget.
Math.floor(float_val) – converts to greatest integer less than or equal to float_val.
Math.ceil(float_val) – converts to smallest integer grater than or equal to float_val.
Math.round(float_val) – converts to nearest integer. If the decimal portion of float_val is greater than or equal to .5 then the resulting integer is the next whole number otherwise resulting number is rounded to the nearest integer less than float_val.
After that, now using above random number let’s define a variable which holds the “id” of the element in widget for displaying total no. of saves and tags.
Now, let’s look at the initWidget() function for initializing the widget.
//write the elements needed for widget
//now attach the stylesheet to the document
//now call the script of delicious
var delScript = document.createElement("script");
At the start of the above code, the function writeWidgetTexts(); is called for writing the content of widget.
The functions createElement() and setAttribute() are DOM manipulation function for creating a element and adding attribute to the element respectively. So, the next four statements of the above function create link element and sets various attributes for attaching CSS document to the page using widget.
Once link element is created and various attribute is assigned to it the next step is to append it to the document using widget, which is done with appendChild() function in the next line of above function.
getElementsByTagName() is a DOM function for accessing the document by the name of tag. Unlike getElementById() which access single element in the document, getElementsByTagName() can access multiple elements of DOM with the help of index. For example, document.getElementsByTagName(“div”) or document.getElementsByTagName(“div”).item(0) refers to the first division element of the document