Commits

derschreckliche committed a41ac52

Initial commit: Added file IdenticaWidget.js

Comments (0)

Files changed (1)

IdenticaWidget.js

+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>');
+	}
+});
+
+var IdenticaWidget = new Class({
+	Implements: [Options, Events],
+	options: {
+	    follow_text: "Follow me on identi.ca",
+	    server: "http://identi.ca",
+	    api_path: "api/",
+	    msg_count: "3",
+	    user_name: "derschreckliche",
+	    timeline: "user_timeline",
+	    avatar: "top",
+	    avatar_size: "50",
+	    container: $("identica_widget"),
+	    twitter_mode: "0"
+	},
+	initialize: function(options){
+	    this.setOptions(options);
+	    TwAPIReq = new Request.JSONP({
+	        url: this.options.server+'/'+this.options.api_path+"/statuses/"+this.options.timeline+".json?screen_name="+this.options.user_name+"&count="+this.options.msg_count,
+	        onComplete: function(data){
+	            this.options.container.getChildren().dispose();
+	            link = new Element('a', {
+	                'href': this.options.server+'/'+this.options.user_name,
+	                'id': 'follow-me-link',
+	                'html': this.options.follow_text+'<br/>'
+	            });
+	            if(this.options.avatar == "top") {
+	                 av_image = new Element('img', {
+	                     'src': data[0].user.profile_image_url,
+	                     'width': this.options.avatar_size,
+	                     'height': this.options.avatar_size,
+	                     'class': 'micro-avatar',
+	                     'style': 'float:left'
+	                 });
+	                 av_image.inject(link, 'top');
+	            }
+	            link.inject(this.options.container, 'top');
+	            data.each(function(status){
+	                if(this.options.twitter_mode == 1){
+	                    html_to_inject = status.text.tweetify();
+	                } else {
+	                    html_to_inject = status.text.dentify(this.options.server);
+	                }
+	                if(this.options.avatar == 1) {
+	                    link = '<a href="'+this.options.server+'/'+status.user.user_name+'"><img src="'+status.user.profile_image_url
+								+'" width="'+this.options.avatar_size+'" height="'+this.options.avatar_size+' class="micro-avatar" /></a>';
+	                    html_to_inject = link + html_to_inject;
+	                }
+	                var li_elem = new Element('li', {
+	                    'html': html_to_inject
+	                });
+	                li_elem.inject(this.options.container);
+	      	 	}.bind(this));
+	    	}.bind(this)
+		});
+
+		TwAPIReq.send();
+	}
+});