Skip to content
Browse files

1.3.2: Option for profile image/username

  • Loading branch information...
1 parent d303bc2 commit 59584624b1932985967f8c492f1b209e010c5acc @elektronaut elektronaut committed Sep 16, 2009
Showing with 31 additions and 6 deletions.
  1. +8 −0 README.rdoc
  2. +22 −5 jquery.livetwitter.js
  3. +1 −1 jquery.livetwitter.min.js
View
8 README.rdoc
@@ -14,6 +14,10 @@ You can also show tweets from a user's timeline:
$("#twitterSearch").liveTwitter('elektronaut', {limit: 10, rate: 300000, mode: 'user_timeline'});
+Showing profile image and username is toggleable, and disabled by default in user_time mode. Use showAuthor to enable.
+
+ $("#twitterSearch").liveTwitter('elektronaut', {limit: 10, rate: 300000, mode: 'user_timeline', showAuthor: true});
+
Note: You might want to be careful with low refresh rates here to play nice with API rate limits.
Changing the query or options is pretty easy, just call liveTwitter again with the new parameters:
@@ -35,6 +39,10 @@ Stopping, starting and refreshing manually::
== Changelog
+=== 1.3.2
+
+* Profile image and username is toggleable, can also be shown on user_timeline.
+
=== 1.3.1
* Smarter timestamps
View
27 jquery.livetwitter.js
@@ -1,11 +1,11 @@
/*
- * jQuery LiveTwitter 1.3.1
+ * jQuery LiveTwitter 1.3.2
* - Live updating Twitter plugin for jQuery
*
* Copyright (c) 2009 Inge Jørgensen (elektronaut.no)
* Licensed under the MIT license (MIT-LICENSE.txt)
*
- * $Date: 2009/06/10 $
+ * $Date: 2009/09/16 $
*/
/*
@@ -40,6 +40,13 @@
limit: 10, // Limit number of results
refresh: true
}, options);
+ if(typeof settings.showAuthor == "undefined"){
+ if(settings.mode == 'search'){
+ settings.showAuthor = true;
+ } else {
+ settings.showAuthor = false;
+ }
+ }
window.twitter_callback = function(){return true;};
this.twitter = {
settings: settings,
@@ -94,14 +101,24 @@
results = json;
}
$(results).reverse().each(function(){
+ var screen_name = '';
+ var profile_image_url = '';
+ if(twitter.mode == 'search') {
+ screen_name = this.from_user;
+ profile_image_url = this.profile_image_url;
+ } else {
+ screen_name = this.user.screen_name;
+ profile_image_url = this.user.profile_image_url;
+ }
+ var userInfo = this.user;
var linkified_text = this.text.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) { return m.link(m); });
linkified_text = linkified_text.replace(/@[A-Za-z0-9_]+/, function(u){return u.link('http://twitter.com/'+u.replace(/^@/,''));});
if(Date.parse(this.created_at) > twitter.lastTimeStamp) {
var tweetHTML = '<div class="tweet tweet-'+this.id+'">';
- if(twitter.mode == 'search') {
+ if(twitter.settings.showAuthor) {
tweetHTML +=
- '<img width="24" height="24" src="'+this.profile_image_url+'" />' +
- '<p class="text"><span class="username"><a href="http://twitter.com/'+this.from_user+'">'+this.from_user+'</a>:</span> ';
+ '<img width="24" height="24" src="'+profile_image_url+'" />' +
+ '<p class="text"><span class="username"><a href="http://twitter.com/'+screen_name+'">'+screen_name+'</a>:</span> ';
} else {
tweetHTML +=
'<p class="text"> ';
View
2 jquery.livetwitter.min.js
@@ -1 +1 @@
-(function(a){if(!a.fn.reverse){a.fn.reverse=function(){return this.pushStack(this.get().reverse(),arguments)}}a.fn.liveTwitter=function(c,b){a(this).each(function(){var d={};if(this.twitter){d=jQuery.extend(this.twitter.settings,b);this.twitter.settings=d;if(c){this.twitter.query=c}this.twitter.limit=d.limit;this.twitter.mode=d.mode;if(this.twitter.interval){this.twitter.refresh()}}else{d=jQuery.extend({mode:"search",rate:15000,limit:10,refresh:true},b);window.twitter_callback=function(){return true};this.twitter={settings:d,query:c,limit:d.limit,mode:d.mode,interval:false,container:this,lastTimeStamp:0,relativeTime:function(g){var f=Date.parse(g);var i=(Date.parse(Date())-f)/1000;var h="";if(i<60){h=i+" seconds ago"}else{if(i<120){h="a minute ago"}else{if(i<(45*60)){h=(parseInt(i/60,10)).toString()+" minutes ago"}else{if(i<(90*60)){h="an hour ago"}else{if(i<(24*60*60)){h=""+(parseInt(i/3600,10)).toString()+" hours ago"}else{if(i<(48*60*60)){h="a day ago"}else{h=(parseInt(i/86400,10)).toString()+" days ago"}}}}}}return h},refreshTime:function(){var f=this;a(f.container).find("span.time").each(function(){a(this).html(f.relativeTime(this.timeStamp))})},refresh:function(f){var i=this;if(this.settings.refresh||f){var h=encodeURIComponent(this.query);var g="";if(i.mode=="search"){g="http://search.twitter.com/search.json?q="+h+"&callback=?"}else{if(i.mode=="user_timeline"){g="http://twitter.com/statuses/user_timeline/"+h+".json?count=5&callback=?"}}a.getJSON(g,function(k){var j=null;if(i.mode=="search"){j=k.results}else{j=k}a(j).reverse().each(function(){var m=this.text.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/,function(o){return o.link(o)});m=m.replace(/@[A-Za-z0-9_]+/,function(o){return o.link("http://twitter.com/"+o.replace(/^@/,""))});if(Date.parse(this.created_at)>i.lastTimeStamp){var n='<div class="tweet tweet-'+this.id+'">';if(i.mode=="search"){n+='<img width="24" height="24" src="'+this.profile_image_url+'" /><p class="text"><span class="username"><a href="http://twitter.com/'+this.from_user+'">'+this.from_user+"</a>:</span> "}else{n+='<p class="text"> '}n+=m+' <span class="time">'+i.relativeTime(this.created_at)+"</span></p></div>";a(i.container).prepend(n);var l=this.created_at;a(i.container).find("span.time:first").each(function(){this.timeStamp=l});if(!f){a(i.container).find(".tweet-"+this.id).hide().fadeIn()}i.lastTimeStamp=Date.parse(this.created_at)}});a(i.container).find("div.tweet:gt("+(i.limit-1)+")").remove()})}},start:function(){var f=this;if(!this.interval){this.interval=setInterval(function(){f.refresh()},f.settings.rate);this.refresh(true)}},stop:function(){if(this.interval){clearInterval(this.interval);this.interval=false}}};var e=this.twitter;this.timeInterval=setInterval(function(){e.refreshTime()},5000);this.twitter.start()}});return this}})(jQuery);
+(function(a){if(!a.fn.reverse){a.fn.reverse=function(){return this.pushStack(this.get().reverse(),arguments)}}a.fn.liveTwitter=function(c,b){a(this).each(function(){var d={};if(this.twitter){d=jQuery.extend(this.twitter.settings,b);this.twitter.settings=d;if(c){this.twitter.query=c}this.twitter.limit=d.limit;this.twitter.mode=d.mode;if(this.twitter.interval){this.twitter.refresh()}}else{d=jQuery.extend({mode:"search",rate:15000,limit:10,refresh:true},b);if(typeof d.showAuthor=="undefined"){if(d.mode=="search"){d.showAuthor=true}else{d.showAuthor=false}}window.twitter_callback=function(){return true};this.twitter={settings:d,query:c,limit:d.limit,mode:d.mode,interval:false,container:this,lastTimeStamp:0,relativeTime:function(g){var f=Date.parse(g);var i=(Date.parse(Date())-f)/1000;var h="";if(i<60){h=i+" seconds ago"}else{if(i<120){h="a minute ago"}else{if(i<(45*60)){h=(parseInt(i/60,10)).toString()+" minutes ago"}else{if(i<(90*60)){h="an hour ago"}else{if(i<(24*60*60)){h=""+(parseInt(i/3600,10)).toString()+" hours ago"}else{if(i<(48*60*60)){h="a day ago"}else{h=(parseInt(i/86400,10)).toString()+" days ago"}}}}}}return h},refreshTime:function(){var f=this;a(f.container).find("span.time").each(function(){a(this).html(f.relativeTime(this.timeStamp))})},refresh:function(f){var i=this;if(this.settings.refresh||f){var h=encodeURIComponent(this.query);var g="";if(i.mode=="search"){g="http://search.twitter.com/search.json?q="+h+"&callback=?"}else{if(i.mode=="user_timeline"){g="http://twitter.com/statuses/user_timeline/"+h+".json?count="+i.limit+"&callback=?"}}a.getJSON(g,function(k){var j=null;if(i.mode=="search"){j=k.results}else{j=k}a(j).reverse().each(function(){var p="";var n="";if(i.mode=="search"){p=this.from_user;n=this.profile_image_url}else{p=this.user.screen_name;n=this.user.profile_image_url}var l=this.user;var o=this.text.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/,function(r){return r.link(r)});o=o.replace(/@[A-Za-z0-9_]+/,function(r){return r.link("http://twitter.com/"+r.replace(/^@/,""))});if(Date.parse(this.created_at)>i.lastTimeStamp){var q='<div class="tweet tweet-'+this.id+'">';if(i.settings.showAuthor){q+='<img width="24" height="24" src="'+n+'" /><p class="text"><span class="username"><a href="http://twitter.com/'+p+'">'+p+"</a>:</span> "}else{q+='<p class="text"> '}q+=o+' <span class="time">'+i.relativeTime(this.created_at)+"</span></p></div>";a(i.container).prepend(q);var m=this.created_at;a(i.container).find("span.time:first").each(function(){this.timeStamp=m});if(!f){a(i.container).find(".tweet-"+this.id).hide().fadeIn()}i.lastTimeStamp=Date.parse(this.created_at)}});a(i.container).find("div.tweet:gt("+(i.limit-1)+")").remove()})}},start:function(){var f=this;if(!this.interval){this.interval=setInterval(function(){f.refresh()},f.settings.rate);this.refresh(true)}},stop:function(){if(this.interval){clearInterval(this.interval);this.interval=false}}};var e=this.twitter;this.timeInterval=setInterval(function(){e.refreshTime()},5000);this.twitter.start()}});return this}})(jQuery);

0 comments on commit 5958462

Please sign in to comment.
Something went wrong with that request. Please try again.