Sep 7
Author
derschreckliche

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

Posted by derschreckliche

Vote for articles fresher than 90 days!
Derzeitige Beurteilung: 3.50 of 5, 6 Stimme(n) 1504 hits
Select language: German, German

2 Comments

Display comments as(Linear | Threaded)
  1. Margaret says:

    MargaretI recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

    Margaret

    http://businesseshome.net

    Comment (1)

  2. Free SMS says:

    Free SMShii.. very nice blog. :-)

    mfg alex

    Comment (1)

Add Comment


Pavatar/Gravatar/Favatar/MyBlogLog/Monster ID author images supported.
Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA


Dieser Blog wird von 1on.de zur Verfügung gestellt; einem kostenlosen Dienst der IDEE GmbH
http://www.flickr.com/photos/zen/ / http://www.flickr.com/photos/zen/196614536/ / CC BY-NC-SA 2.0