Skip to content

Instantly share code, notes, and snippets.

@boazsender
Forked from iros/index.html
Last active September 30, 2015 15:08
Show Gist options
  • Save boazsender/1813727 to your computer and use it in GitHub Desktop.
Save boazsender/1813727 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Twitter Search Plugin</title>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="jquery.twitter.js"></script>
<style type="text/css">
body { padding: 10px; font-family: sans-serif; }
h2 { font-weight: normal; margin-top: 20px; clear: both; }
.twitter-posts li { margin-bottom: 10px; font-size: 12px; clear: both; list-style-type:none; }
.twitter-posts li img { float:left; width: 48px; margin:0px 10px 10px 0px;border:1px solid #c2c2c2; -moz-box-shadow: 0px 0px 4px #c2c2c2; -webkit-box-shadow: 0px 0px 4px #c2c2c2; box-shadow: 0px 0px 4px #c2c2c2; }
.twitter-posts li a { text-decoration:none; color: #009; }
</style>
<script type="text/javascript">
$(function(){
// This code runs our API tester
$('#runDemo').click(function(){
eval($('#thecode').text());
});
$('#demoList').twitter({from: 'bocoup', limit: 3});
// Call twitter search for tweets including the string 'bocoup loft'
$('#bocoup').twitter('bocoup loft');
// Call twitter search for tweets including the string 'omgomg'
// and limit to 5 results
// and don't show tweets with the word 'lol'
// and don't show tweets with an '_' or an 's' in them
// and don't show @replies
// and don't show retweets
// and only show results with links
$('#omg').twitter({
limit : 5, // Number of tweets to get <-- not in twitter api, maps to and supersedes rpp (results per page)
exclusions : '_ s', // Space delimited list of strings to exclude (eg: '_ s gr @b') <-- not in twitter api, done in plugin
replies : false, // Include mentions <-- not in twitter api, done in plugin
retweets : false, // Include mentions <-- not in twitter api, done in plugin
ors : 'omg', // Any of these words
nots : 'lol' // None of these words
});
// Call twitter search for tweets from boazsender
// and limit 5 results
// and set special text to display if none are found
// and don't show @replies
// and don't show retweets
// and list out all the possible options properties for learning!
$('#boazsender').twitter({
limit : 5, // Number of tweets to get <-- not in twitter api, maps to and supersedes rpp (results per page)
exclusions : '@ #', // Space delimited list of strings to exclude (eg: '_ s gr @b') <-- not in twitter api, done in plugin
notFoundText : 'No results found on twitter', // Text to display if no results are found <-- not in twitter api, done in plugin
replies : true, // Include replies? <-- not in twitter api, done in plugin
retweets : true, // Include replies? <-- not in twitter api, done in plugin
ands : '', // All of these words
phrase : '', // This exact phrase
ors : '', // Any of these words
nots : '', // None of these words
tag : '', // This hashtag
lang : '', // Written in language
from : 'boazsender', // From this person
to : '', // To this person
ref : '', // Referencing this person
near : '', // Near this place
within : '', // Within this distance
units : '', // Distance unit (miles or kilometers)
since : '', // Since this date
until : '', // Until this date
tude : '', // Attitude: '?' or ':)' or ':)'
filter : '', // Containing: 'links'
include : '', // Include retweet?: 'retweets'
rpp : 5, // Results per page
q : '', // Plain query
avatar : true //Add an avatar image of the user
});
// Call twitter search for tweets from rwaldron
// and limit 5 results
// and don't show @replies
// and don't show retweets
$('#rwaldron').twitter({
from : 'rwaldron', // From this person
limit : 5, // Number of tweets to get <-- not in twitter api, maps to and supersedes rpp (results per page)
replies : false, // Include replies? <-- not in twitter api, done in plugin
retweets : false // Include replies? <-- not in twitter api, done in plugin
});
// Call twitter search for tweets from asdasdhdajkhjfdasasd
// and limit 5 results
$('#asdasdhdajkhjfdasasd').twitter({
from : 'asdasdhdajkhjfdasasd', // From this person
limit : 0, // Number of tweets to get <-- not in twitter api, maps to and supersedes rpp (results per page)
notFoundText : 'this is special text to sho if no results are found.', // Text to display if no results are found <-- not in twitter api, done in plugin
});
});
</script>
<link href="twitterSearch.jQuery.css" media="screen" rel="stylesheet" type="text/css">
</head>
<body>
<code id="thecode" contenteditable="true">$('#demoList').twitter({from: 'cnn', replies: false, limit: 3})</code>
<a href="JavaScript:;" id="runDemo">&larr; Click to run this code</a>
<h2>Demo List (API tester):</h2>
<div id="demoList" class="twitter-posts prepend-6 span-12" style=""></div>
<h2>'bocoup loft':</h2>
<div id="bocoup" class="twitter-posts">
<h3>Loading Tweets From The Cloud With AJAX HTML5...</h3>
</div>
<h2>'omg':</h2>
<div id="omg" class="twitter-posts">
<h3>Loading Tweets From The Cloud With AJAX HTML5...</h3>
</div>
<h2>@BoazSender</h2>
<div id="boazsender" class="twitter-posts">
<h3>Loading Tweets From The Cloud With AJAX HTML5...</h3>
</div>
<h2>@rwaldron</h2>
<div id="rwaldron" class="twitter-posts">
<h3>Loading Tweets From The Cloud With AJAX HTML5...</h3>
</div>
<h2>@asdasdhdajkhjfdasasd</h2>
<div id="asdasdhdajkhjfdasasd" class="twitter-posts">
<h3>Loading Tweets From The Cloud With AJAX HTML5...</h3>
</div>
</body>
</html>
/*! jQuery Twitter Plugin - v0.3 - 2012-12-24
* https://github.com/boazsender/jQuery-Twitter-Plugin
* Copyright (c) 2012 Boaz Sender; Licensed MIT, GPL */
var linkify=linkify||function(){};(function(a,b){var c=function(a){return a.replace(/[@]+[a-z0\-9-_]+/ig,function(a){return a.link("http://twitter.com/"+a.replace("@",""))})},d=function(a){return a.replace(/[#]+[a-z0\-9-_]+/ig,function(a){return a.link("http://search.twitter.com/search?q="+a.replace("#","%23"))})},e={media:function(a,b){return e.urls(a,b)},urls:function(a,b){return"<a href='"+b.url+"' title='"+b.expanded_url+"'>"+b.display_url+"</a>"},user_mentions:function(a,b){return"<a href='http://twitter.com/"+b.screen_name+"' title='"+b.name+"'>@"+b.screen_name+"</a>"},hashtags:function(a,b){return"<a href='http://search.twitter.com/search?q=%23"+b.text+"'>#"+b.text+"</a>"}},f=function(b){var c=b.text,d=[];return a.each(b.entities,function(b,c){a.each(c,function(a,c){c.type=b}),d=d.concat(c)}),d.sort(function(a,b){return a.indices[0]<b.indices[0]}),a.each(d,function(a,b){e[b.type]&&(c=c.slice(0,b.indices[0])+e[b.type](c,b)+c.slice(b.indices[1]))}),c};a.twitter=function(b,c){if(!b)return!1;var d,e="",f=new RegExp(!1);typeof b=="string"?d=a.extend({},a.twitter.opts,{q:b}):(b.rpp=b.limit?b.limit:b.rpp,b.limit=b.limit?b.limit:b.rpp,e=b.exclusions?b.exclusions.replace(" ","|"):!1,f=e?new RegExp(e):!1,d=a.extend({},a.twitter.opts,b),d.rpp=d.exclusions||!d.replies||!d.retweets?d.rpp*10:d.rpp),a.getJSON("http://search.twitter.com/search.json?callback=?",d,function(a){c(a,d,f)})},a.fn.twitter=function(e,g){return e?this.each(function(){var h=a(this);a.twitter(e,function(e,i,j){var k=a("<ul>"),l=0,m;if(e.results&&e.results.length){for(m in e.results){var n=e.results[m],o=!i.replies&&n.to_user_id?!1:!0,p=!i.retweets&&n.text.slice(0,2)==="RT"?!1:!0;if(!o)continue;if(!p)continue;if(j&&j.test(n.text))continue;var q=a("<li/>",{"class":"tweet"});i.avatar===!0&&q.append(a("<a/>",{href:"http://twitter.com/"+n.from_user,html:"<img src='"+n.profile_image_url+"'/>"}));var r="<a href='http://twitter.com/"+n.from_user+"'>@"+n.from_user+"</a>: ";i.include_entities?r+=f(n):r+=c(d(b(n.text))),q.append(a("<span>",{"class":"content",html:r})).appendTo(k),l++;if(l===i.limit)break}h.html(k),g&&g(!0)}else h.html(a("<h3/>",{"class":"twitter-notFound",text:i.notFoundText})),g&&g(!1)})}):this},a.twitter.opts={limit:7,exclusions:"",notFoundText:"No results found on twitter",replies:!0,retweets:!0,ands:"",phrase:"",ors:"",nots:"",tag:"",lang:"",from:"",to:"",ref:"",near:"",within:"",units:"",since:"",until:"",tude:"",filter:"",include:"",rpp:5,q:"",avatar:!0,include_entities:!0}})(jQuery,linkify);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment