updated twitter.js

This commit is contained in:
Brandon Mathis 2011-09-29 20:04:18 -05:00
parent 3d6cd62100
commit 46cd9656c8

View File

@ -1,12 +1,11 @@
// JSON-P Twitter fetcher for Octopress // JSON-P Twitter fetcher for Octopress
// (c) Brandon Mathis // MIT Lisence // (c) Brandon Mathis // MIT License
/* Sky Slavin, Ludopoli. MIT license. * based on JavaScript Pretty Date * Copyright (c) 2008 John Resig (jquery.com) * Licensed under the MIT license. */ /* Sky Slavin, Ludopoli. MIT license. * based on JavaScript Pretty Date * Copyright (c) 2008 John Resig (jquery.com) * Licensed under the MIT license. */
function prettyDate(time) { function prettyDate(time) {
if (navigator.appName === 'Microsoft Internet Explorer') { if (navigator.appName === 'Microsoft Internet Explorer') {
return "<span>&infin;</span>"; // because IE date parsing isn't fun. return "<span>&infin;</span>"; // because IE date parsing isn't fun.
} }
var say = { var say = {
just_now: " now", just_now: " now",
minute_ago: "1m", minute_ago: "1m",
@ -15,6 +14,7 @@ function prettyDate(time) {
hours_ago: "h", hours_ago: "h",
yesterday: "1d", yesterday: "1d",
days_ago: "d", days_ago: "d",
last_week: "1w",
weeks_ago: "w" weeks_ago: "w"
}; };
@ -35,6 +35,7 @@ function prettyDate(time) {
diff < 86400 && Math.floor(diff / 3600) + say.hours_ago) || diff < 86400 && Math.floor(diff / 3600) + say.hours_ago) ||
day_diff === 1 && say.yesterday || day_diff === 1 && say.yesterday ||
day_diff < 7 && day_diff + say.days_ago || day_diff < 7 && day_diff + say.days_ago ||
day_diff === 7 && say.last_week ||
day_diff > 7 && Math.ceil(day_diff / 7) + say.weeks_ago; day_diff > 7 && Math.ceil(day_diff / 7) + say.weeks_ago;
} }
@ -47,8 +48,10 @@ function linkifyTweet(text, url) {
// Use twitter's api to replace t.co shortened urls with expanded ones. // Use twitter's api to replace t.co shortened urls with expanded ones.
for (var u in url) { for (var u in url) {
if(url[u].expanded_url != null){ if(url[u].expanded_url != null){
var shortUrl = new RegExp( url[u].url.replace(/https?:\/\//, ''), 'g'); var shortUrl = new RegExp(url[u].url, 'g');
text = text.replace(shortUrl, url[u].display_url); text = text.replace(shortUrl, url[u].expanded_url);
var shortUrl = new RegExp(">"+(url[u].url.replace(/https?:\/\//, '')), 'g');
text = text.replace(shortUrl, ">"+url[u].display_url);
} }
} }
return text return text