Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Clearing tweets

  • Loading branch information...
commit 749b1da52ccec8e93e5e936b61ac11e21002063b 1 parent dafc907
@elektronaut elektronaut authored
View
10 README.rdoc
@@ -33,12 +33,16 @@ You disable automatic refreshing by passing refresh: false
$("#twitterSearch").liveTwitter('bacon', {limit: 10, refresh: false});
-Stopping, starting and refreshing manually::
+Stopping, starting and refreshing manually:
$("#twitterSearch").each(function(){ this.twitter.stop(); });
$("#twitterSearch").each(function(){ this.twitter.start(); });
$("#twitterSearch").each(function(){ this.twitter.refresh(); });
+If you want to clear the tweets on changing query, you can do this:
+
+ $("#twitterSearch").each(function(){ this.twitter.clear(); }).liveTwitter('my new query');
+
== Search options
@@ -77,6 +81,10 @@ If you want to apply behavior when new tweets are loaded, you can pass a callbac
== Changelog
+=== 1.5.1
+
+* You can now clear the tweets (thanks to Ryan!).
+
=== 1.5.0
* Following lists is now supported.
View
2  example.html
@@ -76,6 +76,8 @@
$('#searchLinks a').each(function(){
var query = $(this).text();
$(this).click(function(){
+ // Clear the tweets
+ $('#twitterSearch').each(function(){this.twitter.clear()});
// Update the search
$('#twitterSearch').liveTwitter(query);
// Update the header
View
8 jquery.livetwitter.js
@@ -1,11 +1,11 @@
/*
- * jQuery LiveTwitter 1.5.0
+ * jQuery LiveTwitter 1.5.1
* - Live updating Twitter plugin for jQuery
*
* Copyright (c) 2009-2010 Inge Jørgensen (elektronaut.no)
* Licensed under the MIT license (MIT-LICENSE.txt)
*
- * $Date: 2010/05/30$
+ * $Date: 2010/07/16$
*/
/*
@@ -218,6 +218,10 @@
clearInterval(this.interval);
this.interval = false;
}
+ },
+ clear: function(){
+ $(this.container).find('div.tweet').remove();
+ this.lastTimeStamp = null;
}
};
var twitter = this.twitter;
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(d,b,e){var c=this;a(this).each(function(){var f={};if(this.twitter){f=jQuery.extend(this.twitter.settings,b);this.twitter.settings=f;if(d){this.twitter.query=d}this.twitter.limit=f.limit;this.twitter.mode=f.mode;if(this.twitter.interval){this.twitter.refresh()}if(e){this.twitter.callback=e}}else{f=jQuery.extend({mode:"search",rate:15000,limit:10,refresh:true},b);if(typeof f.showAuthor=="undefined"){f.showAuthor=(f.mode=="user_timeline")?false:true}if(!window.twitter_callback){window.twitter_callback=function(){return true}}this.twitter={settings:f,query:d,limit:f.limit,mode:f.mode,interval:false,container:this,lastTimeStamp:0,callback:e,relativeTime:function(i){var h=Date.parse(i);var k=(Date.parse(Date())-h)/1000;var j="";if(k<60){j=k+" seconds ago"}else{if(k<120){j="a minute ago"}else{if(k<(45*60)){j=(parseInt(k/60,10)).toString()+" minutes ago"}else{if(k<(90*60)){j="an hour ago"}else{if(k<(24*60*60)){j=""+(parseInt(k/3600,10)).toString()+" hours ago"}else{if(k<(48*60*60)){j="a day ago"}else{j=(parseInt(k/86400,10)).toString()+" days ago"}}}}}}return j},refreshTime:function(){var h=this;a(h.container).find("span.time").each(function(){a(this).html(h.relativeTime(this.timeStamp))})},refresh:function(h){var k=this;if(this.settings.refresh||h){var i="";var n={};if(k.mode=="search"){n.q=this.query;if(this.settings.geocode){n.geocode=this.settings.geocode}if(this.settings.lang){n.lang=this.settings.lang}if(this.settings.rpp){n.rpp=this.settings.rpp}else{n.rpp=this.settings.limit}var l=[];for(var m in n){if(n.hasOwnProperty(m)){l[l.length]=m+"="+encodeURIComponent(n[m])}}l=l.join("&");i="http://search.twitter.com/search.json?"+l+"&callback=?"}else{if(k.mode=="user_timeline"){i="http://api.twitter.com/1/statuses/user_timeline/"+encodeURIComponent(this.query)+".json?count="+k.limit+"&callback=?"}else{if(k.mode=="list"){var o=encodeURIComponent(this.query.user);var j=encodeURIComponent(this.query.list);i="http://api.twitter.com/1/"+o+"/lists/"+j+"/statuses.json?per_page="+k.limit+"&callback=?"}}}a.getJSON(i,function(q){var p=null;if(k.mode=="search"){p=q.results}else{p=q}var r=0;a(p).reverse().each(function(){var w="";var u="";if(k.mode=="search"){w=this.from_user;u=this.profile_image_url;created_at_date=this.created_at}else{w=this.user.screen_name;u=this.user.profile_image_url;created_at_date=this.created_at.replace(/^(\w+)\s(\w+)\s(\d+)(.*)(\s\d+)$/,"$1, $3 $2$5$4")}var s=this.user;var v=this.text.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/,function(y){return y.link(y)});v=v.replace(/@[A-Za-z0-9_]+/g,function(y){return y.link("http://twitter.com/"+y.replace(/^@/,""))});v=v.replace(/#[A-Za-z0-9_\-]+/g,function(y){return y.link("http://search.twitter.com/search?q="+y.replace(/^#/,"%23"))});if(!k.settings.filter||k.settings.filter(this)){if(Date.parse(created_at_date)>k.lastTimeStamp){r+=1;var x='<div class="tweet tweet-'+this.id+'">';if(k.settings.showAuthor){x+='<img width="24" height="24" src="'+u+'" /><p class="text"><span class="username"><a href="http://twitter.com/'+w+'">'+w+"</a>:</span> "}else{x+='<p class="text"> '}x+=v+' <span class="time">'+k.relativeTime(created_at_date)+"</span></p></div>";a(k.container).prepend(x);var t=created_at_date;a(k.container).find("span.time:first").each(function(){this.timeStamp=t});if(!h){a(k.container).find(".tweet-"+this.id).hide().fadeIn()}k.lastTimeStamp=Date.parse(created_at_date)}}});if(r>0){a(k.container).find("div.tweet:gt("+(k.limit-1)+")").remove();if(k.callback){k.callback(c,r)}a(c).trigger("tweets")}})}},start:function(){var h=this;if(!this.interval){this.interval=setInterval(function(){h.refresh()},h.settings.rate);this.refresh(true)}},stop:function(){if(this.interval){clearInterval(this.interval);this.interval=false}}};var g=this.twitter;this.timeInterval=setInterval(function(){g.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(d,b,e){var c=this;a(this).each(function(){var f={};if(this.twitter){f=jQuery.extend(this.twitter.settings,b);this.twitter.settings=f;if(d){this.twitter.query=d}this.twitter.limit=f.limit;this.twitter.mode=f.mode;if(this.twitter.interval){this.twitter.refresh()}if(e){this.twitter.callback=e}}else{f=jQuery.extend({mode:"search",rate:15000,limit:10,refresh:true},b);if(typeof f.showAuthor=="undefined"){f.showAuthor=(f.mode=="user_timeline")?false:true}if(!window.twitter_callback){window.twitter_callback=function(){return true}}this.twitter={settings:f,query:d,limit:f.limit,mode:f.mode,interval:false,container:this,lastTimeStamp:0,callback:e,relativeTime:function(i){var h=Date.parse(i);var k=(Date.parse(Date())-h)/1000;var j="";if(k<60){j=k+" seconds ago"}else{if(k<120){j="a minute ago"}else{if(k<(45*60)){j=(parseInt(k/60,10)).toString()+" minutes ago"}else{if(k<(90*60)){j="an hour ago"}else{if(k<(24*60*60)){j=""+(parseInt(k/3600,10)).toString()+" hours ago"}else{if(k<(48*60*60)){j="a day ago"}else{j=(parseInt(k/86400,10)).toString()+" days ago"}}}}}}return j},refreshTime:function(){var h=this;a(h.container).find("span.time").each(function(){a(this).html(h.relativeTime(this.timeStamp))})},refresh:function(h){var k=this;if(this.settings.refresh||h){var i="";var n={};if(k.mode=="search"){n.q=this.query;if(this.settings.geocode){n.geocode=this.settings.geocode}if(this.settings.lang){n.lang=this.settings.lang}if(this.settings.rpp){n.rpp=this.settings.rpp}else{n.rpp=this.settings.limit}var l=[];for(var m in n){if(n.hasOwnProperty(m)){l[l.length]=m+"="+encodeURIComponent(n[m])}}l=l.join("&");i="http://search.twitter.com/search.json?"+l+"&callback=?"}else{if(k.mode=="user_timeline"){i="http://api.twitter.com/1/statuses/user_timeline/"+encodeURIComponent(this.query)+".json?count="+k.limit+"&callback=?"}else{if(k.mode=="list"){var o=encodeURIComponent(this.query.user);var j=encodeURIComponent(this.query.list);i="http://api.twitter.com/1/"+o+"/lists/"+j+"/statuses.json?per_page="+k.limit+"&callback=?"}}}a.getJSON(i,function(q){var p=null;if(k.mode=="search"){p=q.results}else{p=q}var r=0;a(p).reverse().each(function(){var w="";var u="";if(k.mode=="search"){w=this.from_user;u=this.profile_image_url;created_at_date=this.created_at}else{w=this.user.screen_name;u=this.user.profile_image_url;created_at_date=this.created_at.replace(/^(\w+)\s(\w+)\s(\d+)(.*)(\s\d+)$/,"$1, $3 $2$5$4")}var s=this.user;var v=this.text.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/,function(y){return y.link(y)});v=v.replace(/@[A-Za-z0-9_]+/g,function(y){return y.link("http://twitter.com/"+y.replace(/^@/,""))});v=v.replace(/#[A-Za-z0-9_\-]+/g,function(y){return y.link("http://search.twitter.com/search?q="+y.replace(/^#/,"%23"))});if(!k.settings.filter||k.settings.filter(this)){if(Date.parse(created_at_date)>k.lastTimeStamp){r+=1;var x='<div class="tweet tweet-'+this.id+'">';if(k.settings.showAuthor){x+='<img width="24" height="24" src="'+u+'" /><p class="text"><span class="username"><a href="http://twitter.com/'+w+'">'+w+"</a>:</span> "}else{x+='<p class="text"> '}x+=v+' <span class="time">'+k.relativeTime(created_at_date)+"</span></p></div>";a(k.container).prepend(x);var t=created_at_date;a(k.container).find("span.time:first").each(function(){this.timeStamp=t});if(!h){a(k.container).find(".tweet-"+this.id).hide().fadeIn()}k.lastTimeStamp=Date.parse(created_at_date)}}});if(r>0){a(k.container).find("div.tweet:gt("+(k.limit-1)+")").remove();if(k.callback){k.callback(c,r)}a(c).trigger("tweets")}})}},start:function(){var h=this;if(!this.interval){this.interval=setInterval(function(){h.refresh()},h.settings.rate);this.refresh(true)}},stop:function(){if(this.interval){clearInterval(this.interval);this.interval=false}},clear:function(){a(this.container).find("div.tweet").remove();this.lastTimeStamp=null}};var g=this.twitter;this.timeInterval=setInterval(function(){g.refreshTime()},5000);this.twitter.start()}});return this}})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.