Last active
December 18, 2015 14:59
-
-
Save peterwilsoncc/5801185 to your computer and use it in GitHub Desktop.
Rapid Twitter Widget for WordPress filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(typeof(RapidTwitter)=='undefined'){RapidTwitter={};} | |
RapidTwitter.generate_html = function(screen_name, tweets){ | |
var the_html = ''; | |
for (var i=0, l=tweets.length; i<l; i++) { | |
var use_tweet = tweets[i], | |
rt_html = '', | |
classes = ['tweet']; | |
if (typeof use_tweet.user.screen_name == 'undefined') { | |
use_tweet.user.screen_name = screen_name; | |
} | |
if (typeof use_tweet.retweeted_status != 'undefined') { | |
use_tweet = use_tweet.retweeted_status; | |
classes.push('tweet--retweet'); | |
if (typeof use_tweet.user.screen_name == 'undefined') { | |
var mentions = tweets[i].entities.user_mentions, | |
mentions_length = mentions.length, | |
mention_position = 256; //any number over 140 works | |
for (var j=0; j<mentions_length; j++) { | |
if (mentions[j].indices[0] < mention_position) { | |
mention_position = mentions[j].indices[0]; | |
use_tweet.user.screen_name = mentions[j].screen_name; | |
} | |
} | |
} | |
rt_html += 'RT '; | |
rt_html += '<a href="'; | |
rt_html += 'https://twitter.com/'; | |
rt_html += use_tweet.user.screen_name; | |
rt_html += '" class="tweet__mention tweet__mention--retweet">'; | |
rt_html += '<span>@</span>'; | |
rt_html += use_tweet.user.screen_name; | |
rt_html += '</a>'; | |
rt_html += ': '; | |
} | |
if (use_tweet.in_reply_to_screen_name != null) { | |
classes.push('tweet--reply'); | |
} | |
the_html += '<li class="'; | |
the_html += classes.join(' '); | |
the_html += '">'; | |
the_html += rt_html; | |
the_html += RapidTwitter.process_entities(use_tweet); | |
the_html += ' '; | |
the_html += '<a class="tweet__datestamp timesince" href="'; | |
the_html += 'https://twitter.com/'; | |
the_html += use_tweet.user.screen_name; | |
the_html += '/status/'; | |
the_html += use_tweet.id_str; | |
the_html += '">'; | |
the_html += RapidTwitter.relative_time(use_tweet.created_at); | |
the_html += '</a>'; | |
the_html += '</li>'; | |
} | |
return the_html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment