Just finished my little Identi.ca widget for easy integration into websites. It also works with twitter! I made this, because the official Identi.ca Badge was kind of too heavy for me and not integrating within the style of my website well.
First i found this: An Identi.ca widget made with YUI-Framework. It works very well, but the problem i had with it was that i use the mootools js-framework for some effects on my site and they both frameworks don't really like each other. So i just had to do it myself.
Here it is (first at all you will need to get mootools here and include it in the head):
The HTML:
<div id="identica_widget">
<ul id="identica_list">
<li>keine Updates</li>
</ul>
</div>-------------------------------------------------
The Mootools Javascript:
-------------------------------------------------
window.addEvent('domready', function(){
//what will show behind "Follow me on "...
var service_name = "Identi.ca";
// a statusNet / laconica / twitter server, no tailing "/"!
// (don't forget to set twitter_mode for http://twitter.com)
var server = "http://identi.ca"
// for using with twitter set this to 1 and
var twitter_mode = "0";
// how much messages to show
var msg_count = "3";
//your username
var user_name = "derschreckliche";
//set to "friends_timeline" for your and your friends posts
var timeline = "user_timeline";
//set to "1" for friends_timeline avatars on each post.
//on user_timeline "top" will show your avatar on top
var show_avatars = "top";
//avatar image size in pixels
//(class="micro-avatar" if you want to style it with css)
var avatar_size_px = "30";
//--------------- the code -------------------
if(twitter_mode == "1"){
api_server = server;
} else {
api_server = server+'/api';
}
TwAPIReq = new Request.JSONP({
url: api_server+"/statuses/"+timeline+".json?screen_name="
+user_name+"&count="+msg_count,
onComplete: function(data){
$$('#identica_list li').dispose();
linked_image = new Element('a', {
'href': server+'/'+user_name,
'id': 'follow-me-link',
'html': ' Follow me on '+service_name
});
if(show_avatars == "top") {
av_image = new Element('img', {
'src': data[0].user.profile_image_url,
'width': avatar_size_px,
'height': avatar_size_px,
'class': 'micro-avatar'
});
av_image.inject(linked_image, 'top');
}
linked_image.inject('identica_widget', 'top');
data.each(function(status){
if(twitter_mode == 1){
var html_to_inject = status.text.tweetify();
} else {
var html_to_inject = status.text.dentify(server);
}
if(show_avatars == 1) {
linked_image = '<a href="'+server+'/'+user_name+
'"><img src="'+status.user.profile_image_url+
'" width="'+avatar_size_px+'" height="'+
avatar_size_px+' class="micro-avatar" /></a>';
html_to_inject = linked_image + html_to_inject;
}
var li_elem = new Element('li', {
'html': html_to_inject
});
li_elem.inject('identica_list');
});
}
});
TwAPIReq.send();
//for linking hashtags, usernames, and urls
//thanks to david walsh (http://davidwalsh.name/tweetify) for this
String.implement({
tweetify: function() {
return this.replace(/(https?:\/\/\S+)/gi,'<a href="$1">$1</a>'
).replace(/(^|\s)@(\w+)/g,
'$1<a href="http://twitter.com/$2">@$2</a>'
).replace(/(^|\s)#(\w+)/g,
'$1<a href="http://search.twitter.com/search?q=%23$2">#$2</a>');
},
dentify: function(server) {
return this.replace(/(https?:\/\/\S+)/gi,'<a href="$1">$1</a>'
).replace(/(^|\s)@(\w+)/g,
'$1<a href="'+server+'/$2">@$2</a>'
).replace(/(^|\s)#(\w+)/g,
'$1<a href="'+server+
'/search/notice?q=%23$2&search=Search">#$2</a>'
).replace(/(^|\s)!(\w+)/g,
'$1<a href="'+server+
'/search/group?q=$2&search=Search">!$2</a>');
}
});
});
-------------------------------------------------
The list of dents/tweets/posts will fully integrate into your website, as no styles are used.
As i use it on this website, you can see how it work on the right.
Big thanks to david walsh for the tweetify function that i modified for using with identi.ca and other laconica or statusNet servers and i added some groups support.
Feel free to give me ideas for extending or improving it, maybe i really will do it ;-P



09/09/09 03:06:14
PingBack
Comment (1)