-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.twitter.min.js
More file actions
11 lines (11 loc) · 2.52 KB
/
jquery.twitter.min.js
File metadata and controls
11 lines (11 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
/*
* Twitter Search Plugin jquery.twitter.js
* http://code.bocoup.com/jquery-twitter-plugin/
*
* Copyright (c) 2010 Bocoup, LLC
* Authors: Boaz Sender, Rick Waldron, Nick Cammarata
* Dual licensed under the MIT and GPL licenses.
* http://code.bocoup.com/license/
*
*/
;(function($){var mention=function(str){return str.replace(/[@]+[A-Za-z0-9-_]+/ig,function(username){return username.link('http://twitter.com/'+username.replace('@',''));});},hashtags=function(str){return str.replace(/[#]+[A-Za-z0-9-_]+/ig,function(tag){return tag.link('http://search.twitter.com/search?q='+tag.replace('#','%23'));});};$.twitter=function(options,callback){if(!options){return false;}var query,exclusionsExp=new RegExp(false);if(typeof options=='string'){query=$.extend({},$.twitter.opts,{q:options});}else{options.rpp=options.limit?options.limit:options.rpp;options.limit=options.limit?options.limit:options.rpp;exclusionsStr=options.exclusions?options.exclusions.replace(' ','|'):false;exclusionsExp=exclusionsStr?new RegExp(exclusionsStr):false;query=$.extend({},$.twitter.opts,options);query.rpp=query.exclusions||!query.replies||!query.retweets?(query.rpp*10):query.rpp;}$.getJSON('http://search.twitter.com/search.json?callback=?',query,function(tweets){callback(tweets,query,exclusionsExp)});};$.fn.twitter=function(options){if(!options){return this;}return this.each(function(){var $this=$(this);$.twitter(options,function(tweets,query,exclusionsExp){var $tweets=$('<ul>'),limitInt=0;if(tweets.results&&tweets.results.length){for(var i in tweets.results){var tweet=tweets.results[i],allowReply=!query.replies&&tweet.to_user_id?false:true,allowRetweet=!query.retweets&&tweet.text.slice(0,2)=='RT'?false:true;if(!allowReply){continue;}if(!allowRetweet){continue;}if(exclusionsExp&&exclusionsExp.test(tweet.text)){continue;}$('<li/>',{className:'tweet'}).append($('<a/>',{href:'http://twitter.com/'+tweet.from_user,html:'<img src="'+tweet.profile_image_url+'"/>'})).append($('<span>',{className:'content',html:'<a href="http://twitter.com/'+tweet.from_user+'">@'+tweet.from_user+'</a>: '+mention(hashtags(linkify(tweet.text)))})).appendTo($tweets);limitInt++;if(limitInt===query.limit){break;}}$this.html($tweets);}else{$this.html($('<p/>',{className:'twitter-notFound',text:query.notFoundText}));}});});};$.twitter.opts={limit:7,exclusions:'',notFoundText:'No results found on twitter',replies:true,retweets:true,ands:'',phrase:'',ors:'',nots:'',tag:'',lang:'',from:'',to:'',ref:'',near:'',within:'',units:'',since:'',until:'',tude:'',filter:'',include:'',rpp:5,q:''}})(jQuery);