Deldo
Deldo is a Del.icio.us powered link browser. It can be dropped and integrated into your web site and allows users to browse your del.icio.us links using tags as if they were nested folders. Required: Mootools Library [
Download Compressed Deldo 1.0 ]
Full Source
/**
* Class: Deldo
* Del.icio.us powered link directory.
*
* Version:
* 1.0
*
* Author:
* Bryan Enlish <bryan at bluelinecity dot com>
*
* URL:
* http://bluelinecity.com/software/deldo
*
* Parameters:
* user - String, del.icio.us username to pull from.
* top_tags - Mixed, Optional, When array, will use array elements as top level tags, if integer, will
* get use most used tags up to that number as top level tags.
*
* Requires:
* mootools <mootools.net>
*
* Usage:
* var deldo = new Deldo('username');
*
* window.addEvent('domready',function(){
* // deldo.nofavicon = 1; //turn off favicon fetching
* deldo.make('deldo'); //insert into div element with id='deldo'
* });
*
* CSS Classes:
* <div class="deldo-path"></div>
* <div class="deldo-tags"></div>
* <div class="deldo-posts"></div>
*/
var Deldo = new Class({
Version: 1.0,
initialize: function( user, top_tags )
{
this.user = user;
this.scope = '';
this.tags = [];
this.path = location.pathname;
this.seperator = ' / ';
this.top_tags = (typeof(top_tags)=='object'?top_tags:null);
if ( location.search && (tmp = location.search.match(/?tags=(.*?)(&|$)/)) )
{
if ( tmp[1] )
{
this.scope = unescape(tmp[1]);
this.tags = tmp[1].split('+');
this.tags.forEach(function(e,i){
this[i] = unescape(e);
},this.tags);
}
}
this.include_dom("http://del.icio.us/feeds/json/"+ this.user + (this.scope==''?'':'/'+this.scope+'?count=100'));
this.include_dom("http://del.icio.us/feeds/json/tags/"+ this.user + (this.scope==''?'':'/'+this.scope)+(this.tags.length==0&&typeof(top_tags)=='number'?'?sort=count&count='+top_tags:''));
},
include_dom: function( script_filename )
{
document.write('<' + 'script');
document.write(' language="javascript"');
document.write(' type="text/javascript"');
document.write(' src="' + script_filename + '">');
document.write('</' + 'script' + '>');
},
makeBreadcrumb: function ( sep )
{
var crumbs = ['<a href="'+this.path+'?tags=">'+ this.user +'</a>'];
var trail = [];
this.tags.forEach(function(e){
trail.push(e);
crumbs.push('<a href="'+this.path+'?tags='+ trail.join('+') +'">'+ e.capitalize() +'</a>');
},this);
$('deldo-path-' + this.user).setHTML(crumbs.join(sep));
},
makeSubTags: function ()
{
var tags = (this.tags.length||!this.top_tags?Delicious.tags:this.top_tags);
$each(tags,function(e,i){
t = (this.tags.length||!this.top_tags?i:e);
if ( !this.tags.contains(t) )
{
new Element('a',{href:this.path+'?tags='+(this.scope==''?'':this.scope+'+')+t}).setHTML( t.capitalize() ).injectInside('deldo-tags-' + this.user );
$('deldo-tags-' + this.user ).appendText(' ');
}
},this);
},
makePosts: function ()
{
ul = new Element('ul');
Delicious.posts.forEach(function(post,i){
var li = new Element('li');
var a = new Element('a',{styles:(this.nofavicon?"":"margin-left:20px;"),href:post.u}).setHTML( post.d );
if ( !this.nofavicon )
{
var img = new Element('img',
{styles:'position:absolute;display:none;height:16;width:16;',
src:post.u.split('/').splice(0,3).join('/')+'/favicon.ico'
});
img.onload = function(){ img.style.display='inline'; };
img.injectInside(li);
}
a.injectInside(li);
if ( typeof(post.n) != 'undefined' )
{
li.appendText(' ' + post.n);
}
li.injectInside(ul);
},this);
ul.injectInside('deldo-posts-'+this.user);
},
make: function( el )
{
if ( el )
{
new Element('div',{'class':'deldo-path',id:'deldo-path-' + this.user }).injectInside(el);
new Element('div',{'class':'deldo-tags',id:'deldo-tags-' + this.user }).injectInside(el);
new Element('div',{'class':'deldo-posts',id:'deldo-posts-' + this.user }).injectInside(el);
this.makeBreadcrumb( this.seperator );
this.makeSubTags();
this.makePosts();
}
}
});


