Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added twitterlib library for all things twitter api related

  • Loading branch information...
commit 2e452b82e449865097b5aa13705722885d03e3aa 1 parent 5dacfca
Remy Sharp authored July 04, 2011
22  ajax/libs/twitterlib/0.9.0/package.json
... ...
@@ -0,0 +1,22 @@
  1
+{
  2
+    "name": "twitterlib.js",
  3
+    "filename": "twitterlib.min.js",
  4
+    "version": "0.9.0",
  5
+    "description": "Library for doing all things Twitter API related, with added sauce for filtering, paging and paging",
  6
+    "homepage": "https://github.com/remy/twitterlib/",
  7
+    "keywords": [
  8
+       "twitter"
  9
+   ],
  10
+   "maintainers": [
  11
+       {
  12
+           "name": "Remy Sharp"
  13
+       } 
  14
+   ],
  15
+   "repositories": [
  16
+       {
  17
+           "type": "git",
  18
+           "url": "https://github.com/remy/twitterlib/" 
  19
+       } 
  20
+   ]
  21
+
  22
+}
5  ajax/libs/twitterlib/0.9.0/twitterlib.min.js
... ...
@@ -0,0 +1,5 @@
  1
+/**
  2
+ * twitterlib.js (c) 2011 Remy Sharp
  3
+ * Licensed under the terms of the MIT license.
  4
+ */
  5
+(function(a,b){function x(a,b,c){b&&k[a]==l&&(k[a]=b),this[a]==l&&(this[a]=function(b,c,d){typeof b=="function"?(d=b,b=""):b.toString()=="[Object object]"&&(d=c,c=b,b=""),c=u(c,d),v(a,b,c),c[a]=c.user=b,c.search=encodeURIComponent(b),c.callback&&s(t(a,c),c,c.callback);return this});return this[a]}function w(){var b=sessionStorage.length;while(b--)sessionStorage.key(b).substr(0,a.length)==a&&sessionStorage.removeItem(sessionStorage.key(b))}function v(b,c,d){g={method:b,arg:c,options:d,callback:d.callback,page:d.page||1};if(m){var e=JSON.parse(sessionStorage.getItem(a+".last_request")||"{}");if(g.method!=e.method||g.arg!=e.arg)w(),sessionStorage.setItem(a+".last_request",JSON.stringify(g))}}function u(a,b){typeof a=="function"&&(b=a,a={}),a===l&&(a={}),a.page=a.page||1,a.callback=b,a.limit===0&&delete a.limit;return a}function t(a,b){return k[a].replace(/(\b.*?)%(.*?)(\|.*?)?%/g,function(a,c,d,e){if(e&&e.substr(1)=="remove"&&b[d]==l)return"";return c+(b[d]===l?e.substr(1):b[d])})}function s(g,i,j){var k=e.createElement("script"),n=null;i==l&&(i={}),c++,h[a+c]=!0,d[a+c]=function(c,d){return function(e){var f=0,g=[];if(e.results){e=e.results,f=e.length;while(f--)e[f].user={id:e[f].from_user_id,screen_name:e[f].from_user,profile_image_url:e[f].profile_image_url},e[f].source=b[a].ify.entities(e[f].source),g=e[f].created_at.split(" "),e[f].created_at=[g[0],g[2],g[1],g[4],g[5],g[3]].join(" ").replace(/,/,"")}else if(e.length&&e[0].sender){f=e.length;while(f--)e[f].user=e[f].sender,e[f].originalText=e[f].text,e[f].text="@"+e[f].recipient_screen_name+" "+e[f].text}else if(d.rts==!0||d.rts=="t"||d.rts==1){f=e.length;while(f--)e[f].retweeted_status&&(e[f].retweeted_status.retweetedby=e[f].user,e[f]=e[f].retweeted_status)}d.originalTweets=e,d.filter&&(e=p.matchTweets(e,d.filter)),d.limit&&d.limit<e.length&&(e=e.splice(0,d.limit));if(m&&d.page>1)try{sessionStorage.setItem(a+".page"+d.page+".tweets",JSON.stringify(e)),sessionStorage.setItem(a+".page"+d.page+".originalTweets",JSON.stringify(d.originalTweets)),sessionStorage.setItem(a+".page"+d.page,"true")}catch(h){}d.cached=!1,j.call(b[a],e,d),r(c)}}(c,i),n=g.match(/callback=(.*)/),n!=null&&n.length>1?d[n[1]]=d[a+c]:g+="&callback="+a+c;if(!m||i.page<=1||m&&sessionStorage.getItem(a+".page"+i.page)==null)k.src=g,k.id=a+c,f.appendChild(k);else if(m){r(c),i.cached=!0,i.originalTweets=JSON.parse(sessionStorage.getItem(a+".page"+i.page+".originalTweets"));var o=JSON.parse(sessionStorage.getItem(a+".page"+i.page+".tweets")||"[]");i.filter&&(o=p.matchTweets(o,i.filter)),i.limit&&i.limit<o.length&&(o=o.splice(0,i.limit)),j.call(b[a],o,i)}}function r(b){var c=e.getElementById(a+b);c&&f.removeChild(e.getElementById(a+b)),delete h[a+b],d[a+b]=l;try{delete d[a+b]}catch(g){}}function q(c){var d='<li><div class="tweet">';d+='<div class="vcard"><a href="http://twitter.com/'+c.user.screen_name+'" class="url"><img style="height: 48px; width: 48px;" alt="'+c.user.name+'" class="photo fn" height="48" src="'+c.user.profile_image_url+'" width="48" /></a></div>',d+='<div class="hentry"><strong><a href="http://twitter.com/',d+=c.user.screen_name+'" ',d+='title="'+c.user.name+'">'+c.user.screen_name+"</a></strong> ",d+='<span class="entry-content">',d+=b[a].ify.clean(c.text),d+='</span> <span class="meta entry-meta"><a href="http://twitter.com/'+c.user.screen_name,d+="/status/"+c.id_str+'" class="entry-date" rel="bookmark"><span class="published" title="',d+=c.created_at+'">'+b[a].time.datetime(c.created_at)+"</span></a>",c.source&&(d+=" <span>from "+c.source+"</span>"),c.retweetedby&&(d+=" <span>retweeted by "+c.retweetedby.screen_name+"</span>"),d+="</span></div></div></li>";return d}var c=+(new Date),d=this,e=d.document,f=e.getElementsByTagName("head")[0],g={},h={},i={"&quot;":'"',"&lt;":"<","&gt;":">"},j={search:"http://search.twitter.com/search.json?q=%search%&page=%page|1%&rpp=%limit|100%&since_id=%since|remove%",timeline:"http://api.twitter.com/1/statuses/user_timeline.json?screen_name=%user%&count=%limit|200%&page=%page|1%&since_id=%since|remove%include_rts=%rts|false%",list:"http://api.twitter.com/1/%user%/lists/%list%/statuses.json?page=%page|1%&per_page=%limit|200%&since_id=%since|remove%",favs:"http://api.twitter.com/1/favorites/%user%.json?page=%page|1%"},k=j,l,m=!1,n=function(){return{entities:function(a){return a.replace(/(&[a-z0-9]+;)/g,function(a){return i[a]})},link:function(a){return a.replace(/[a-z]+:\/\/[a-z0-9-_]+\.[a-z0-9-_:~\+#%&\?\/.=]+[^:\.,\)\s*$]/ig,function(a){return'<a href="'+a+'">'+(a.length>25?a.substr(0,24)+"...":a)+"</a>"})},at:function(a){return a.replace(/(^|[^\w]+)\@([a-zA-Z0-9_]{1,15}(\/[a-zA-Z0-9-_]+)*)/g,function(a,b,c){return b+'@<a href="http://twitter.com/'+c+'">'+c+"</a>"})},hash:function(a){return a.replace(/(^|[^&\w'"]+)\#([a-zA-Z0-9_]+)/g,function(a,b,c){return b+'#<a href="http://search.twitter.com/search?q=%23'+c+'">'+c+"</a>"})},clean:function(a){return this.hash(this.at(this.link(a)))}}}(),o=function(){var a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];return{time:function(a){var b=a.getHours(),c=a.getMinutes()+"",d="AM";b==0?b=12:b==12?d="PM":b>12&&(b-=12,d="PM"),c.length==1&&(c="0"+c);return b+":"+c+" "+d},date:function(b){var c=b.toDateString().split(/ /),d=a[b.getMonth()],e=b.getDate()+"",f=~~e,g=b.getFullYear(),h=(new Date).getFullYear(),i="th";f%10==1&&e.substr(0,1)!="1"?i="st":f%10==2&&e.substr(0,1)!="1"?i="nd":f%10==3&&e.substr(0,1)!="1"&&(i="rd"),e.substr(0,1)=="0"&&(e=e.substr(1));return d+" "+e+i+(h!=g?", "+g:"")},datetime:function(a){var b=a.split(" "),c=new Date(Date.parse(b[1]+" "+b[2]+", "+b[5]+" "+b[3]));return this.time(c)+" "+this.date(c)},relative:function(a){var b=a.split(" "),c=Date.parse(b[1]+" "+b[2]+", "+b[5]+" "+b[3]),d=new Date(c),e=arguments.length>1?arguments[1]:new Date,f=~~((e.getTime()-c)/1e3),g="";f=f+e.getTimezoneOffset()*60,f<5?g="less than 5 seconds ago":f<30?g="half a minute ago":f<60?g="less than a minute ago":f<120?g="1 minute ago":f<2700?g=(~~(f/60)).toString()+" minutes ago":f<10800?g="about 1 hour ago":f<86400?g="about "+(~~(f/3600)).toString()+" hours ago":f<172800?g=this.time(d)+" yesterday":g=this.time(d)+" "+this.date(d);return g}}}(),p=function(){return{match:function(a,b,c){var d=0,e="",f=a.text.toLowerCase();typeof b=="string"&&(b=this.format(b));if(b.not.length){for(d=0;d<b.not.length;d++)if(f.indexOf(b.not[d])!==-1)return!1;if(!b.and.length&&!b.or.length)return!0}if(b.and.length)for(d=0;d<b.and.length;d++){e=b.and[d];if(e.substr(0,3)==="to:"){if(!RegExp("^@"+e.substr(3)).test(f))return!1}else if(e.substr(0,5)=="from:"){if(a.user.screen_name!==e.substr(5))return!1}else if(f.indexOf(e)===-1)return!1}if(b.or.length)for(d=0;d<b.or.length;d++){e=b.or[d];if(e.substr(0,3)==="to:"){if(RegExp("^@"+e.substr(3)).test(f))return!0}else if(e.substr(0,5)=="from:"){if(a.user.screen_name===e.substr(5))return!0}else if(f.indexOf(b.or[d])!==-1)return!0}else if(b.and.length)return!0;return!1},format:function(a,b){var c=[],d=[],e=[],f=0,g=[],h="",i="";a.replace(/(-?["'](.*?)["']|\S+)/g,function(a){var b=!1;a.substr(0,1)=="-"&&(b=!0),a=a.replace(/["']+|["']+$/g,""),b?g.push(a.substr(1).toLowerCase()):c.push(a)});for(f=0;f<c.length;f++)c[f]=="OR"&&c[f+1]?(d.push(c[f-1].toLowerCase()),d.push(c[f+1].toLowerCase()),f++,e.pop()):e.push(c[f].toLowerCase());return{or:d,and:e,not:g}},matchTweets:function(a,b,c){var d=[],e,f=0;typeof b=="string"&&(b=this.format(b));for(f=0;f<a.length;f++)this.match(a[f],b,c)&&d.push(a[f]);return d}}}();b[a]={custom:x,status:function(a,b,c){b=u(b,c),b.limit=1,v("status",a,b);return this.timeline(a,b,b.callback)},list:function(a,b,c){var d=a.split("/");b=u(b,c),v("list",a,b),b.user=d[0],b.list=d[1],b.callback&&s(t("list",b),b,b.callback);return this},next:function(){g.method&&(g.page++,g.options.page=g.page,this[g.method](g.arg,g.options,g.callback));return this},time:o,ify:n,filter:p,cancel:function(){for(var b in h)d[b]=function(){return function(a){r(a)}}(b.replace(a,""));h={};return this},reset:function(){k=j,g.method=""},render:q,debug:function(a){for(var b in a)k[b]=a[b];return this},cache:function(a){m=a==l?!0:a;if(!d.JSON||!d.sessionStorage)m=!1}},b[a].custom("search"),b[a].custom("timeline"),b[a].custom("favs")})("twitterlib",this)

0 notes on commit 2e452b8

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