/*! 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($, linkify) { var mention = function( str ) { return str.replace(/[@]+[a-z0\-9-_]+/ig, function( username ) { return username.link("http://twitter.com/"+ username.replace("@","") ); }); }, hashtags = function( str ) { return str.replace(/[#]+[a-z0\-9-_]+/ig, function( tag ) { return tag.link("http://search.twitter.com/search?q="+tag.replace("#","%23")); }); }, entityExpanders = { // Simply expand media entities as though they were hyperlinks media: function( text, mediaEntity ) { return entityExpanders.urls(text, mediaEntity); }, urls: function( text, urlEntity ) { return "" + urlEntity.display_url + ""; }, user_mentions: function( text, userEntity ) { return "@" + userEntity.screen_name + ""; }, hashtags: function( text, hashtagEntity ) { return "#" + hashtagEntity.text + ""; } }, expandEntities = function( tweet ) { var expanded = tweet.text; var allEnts = []; // To facilitate an in-place replacement, create a flat list of all // entities, sorted in descending order according to index in the tweet. $.each(tweet.entities, function(entityType, entities) { $.each(entities, function(_, entity) { entity.type = entityType; }); allEnts = allEnts.concat(entities); }); allEnts.sort(function(a, b) { return a.indices[0] < b.indices[0]; }); $.each(allEnts, function(_, entity) { // Check for expander first in order to prevent future entities from // breaking the plugin if (entityExpanders[entity.type]) { expanded = expanded.slice(0, entity.indices[0]) + entityExpanders[entity.type](expanded, entity) + expanded.slice(entity.indices[1]); } }); return expanded; }; $.twitter = function (options, callback) { // Fail if the options arg is not set if ( !options ) { return false; } // Set a temporary default query object var query, // Set up a string to be used later in the case that exclusions have been set exclusionsStr = "", // Set up a regex to be used later in the case that exclusions have been set exclusionsExp = new RegExp(false); // If options is a string use it as standalone query if ( typeof options === "string" ) { query = $.extend({}, $.twitter.opts, { q: options }); // Else prepare the options object to be serialized } else { // If a limit is set, add it to the query object options.rpp = options.limit ? options.limit : options.rpp; // If no limit is set, make the limit the rpp options.limit = options.limit ? options.limit : options.rpp; // If there are exlusions, turn them into a regex string exclusionsStr = options.exclusions ? options.exclusions.replace(" ", "|") : false; // If there are exlusions, turn the regex string we just made into a RegExp exclusionsExp = exclusionsStr ? new RegExp( exclusionsStr ) : false; // Make a new object that is a merger of the options passed in with the default $.twitter.opts object // and assign it to the query variable query = $.extend({}, $.twitter.opts, options); // If there are exclusions, or replies or retweets are set to false, multiply the results to ask for from twitter by ten // We need to do this so that we have some meat to work with if the exclusions are common query.rpp = query.exclusions || !query.replies || !query.retweets ? (query.rpp * 10) : query.rpp; } // Call Twitter JSONP $.getJSON("http://search.twitter.com/search.json?callback=?", query, function(tweets){ callback(tweets, query, exclusionsExp); }); }; $.fn.twitter = function( options, callback ) { // Fail gracefully if the options arg is not set // return the jQuery obj so that chaining does not break if ( !options ) { return this; } // Begin to iterate over the jQuery collection that the method was called on return this.each(function () { // Cache `this` var $this = $(this); $.twitter(options, function( tweets, query, exclusionsExp ) { //Create and cache a new UL var $tweets = $("