updated added reqwest to ender.js, fixed twitter.js url expansion bug
This commit is contained in:
parent
04586299b1
commit
347c954894
File diff suppressed because one or more lines are too long
@ -1,11 +1,6 @@
|
||||
// JSON-P Twitter fetcher for Octopress
|
||||
// (c) Brandon Mathis // MIT Lisence
|
||||
|
||||
// jXHR.js (JSON-P XHR) | v0.1 (c) Kyle Simpson | MIT License | http://mulletxhr.com/
|
||||
// uncompressed version available in source/javascripts/libs/jXHR.js
|
||||
(function(c){var b=c.setTimeout,d=c.document,a=0;c.jXHR=function(){var e,g,n,h,m=null;function l(){try{h.parentNode.removeChild(h)}catch(o){}}function k(){g=false;e="";l();h=null;i(0)}function f(p){try{m.onerror.call(m,p,e)}catch(o){throw new Error(p)}}function j(){if((this.readyState&&this.readyState!=="complete"&&this.readyState!=="loaded")||g){return}this.onload=this.onreadystatechange=null;g=true;if(m.readyState!==4){f("Script failed to load ["+e+"].")}l()}function i(o,p){p=p||[];m.readyState=o;if(typeof m.onreadystatechange==="function"){m.onreadystatechange.apply(m,p)}}m={onerror:null,onreadystatechange:null,readyState:0,open:function(p,o){k();internal_callback="cb"+(a++);(function(q){c.jXHR[q]=function(){try{i.call(m,4,arguments)}catch(r){m.readyState=-1;f("Script failed to run ["+e+"].")}c.jXHR[q]=null}})(internal_callback);e=o.replace(/=\?/,"=jXHR."+internal_callback);i(1)},send:function(){b(function(){h=d.createElement("script");h.setAttribute("type","text/javascript");h.onload=h.onreadystatechange=function(){j.call(h)};h.setAttribute("src",e);d.getElementsByTagName("head")[0].appendChild(h)},0);i(2)},setRequestHeader:function(){},getResponseHeader:function(){return""},getAllResponseHeaders:function(){return[]}};k();return m}})(window);
|
||||
|
||||
|
||||
/* 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) {
|
||||
if (navigator.appName === 'Microsoft Internet Explorer') {
|
||||
@ -44,12 +39,20 @@ function prettyDate(time) {
|
||||
}
|
||||
|
||||
function linkifyTweet(text, url) {
|
||||
for (var u in url) {
|
||||
var shortUrl = new RegExp(url[u].url, 'g');
|
||||
text = text.replace(shortUrl, '<a href="' + url[u].expanded_url + '">' + url[u].expanded_url.replace(/https?:\/\//, '') + '</a>');
|
||||
}
|
||||
return text.replace(/(^|\W)@(\w+)/g, '$1<a href="http://twitter.com/$2">@$2</a>')
|
||||
// Linkify urls, usernames, hashtags
|
||||
text = text.replace(/(https?:\/\/)([\w\-:;?&=+.%#\/]+)/gi, '<a href="$1$2">$2</a>')
|
||||
.replace(/(^|\W)@(\w+)/g, '$1<a href="http://twitter.com/$2">@$2</a>')
|
||||
.replace(/(^|\W)#(\w+)/g, '$1<a href="http://search.twitter.com/search?q=%23$2">#$2</a>');
|
||||
|
||||
// Use twitter's api to replace t.co shortened urls with expanded ones.
|
||||
for (var u in url) {
|
||||
if(url[u].expanded_url != null){
|
||||
var shortUrl = new RegExp( url[u].url.replace(/https?:\/\//, ''), 'g');
|
||||
text = text.replace(shortUrl, url[u].display_url);
|
||||
console.log(text);
|
||||
}
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
function showTwitterFeed(tweets, twitter_user) {
|
||||
@ -63,15 +66,11 @@ function showTwitterFeed(tweets, twitter_user) {
|
||||
}
|
||||
|
||||
function getTwitterFeed(user, count, replies) {
|
||||
var feed = new jXHR();
|
||||
feed.onerror = function (msg,url) {
|
||||
$('#tweets li.loading').addClass('error').text("Twitter's busted");
|
||||
};
|
||||
feed.onreadystatechange = function(data){
|
||||
if (feed.readyState === 4) { showTwitterFeed(data, user); }
|
||||
};
|
||||
$.ajax({
|
||||
url: "http://api.twitter.com/1/statuses/user_timeline/" + user + ".json?trim_user=true&count=" + (parseInt(count, 10)) + "&include_entities=1&exclude_replies=" + (replies ? "0" : "1") + "&callback=?"
|
||||
, type: 'jsonp'
|
||||
, error: function (err) { $('#tweets li.loading').addClass('error').text("Twitter's busted"); }
|
||||
, success: function(data) { showTwitterFeed(data, user); }
|
||||
})
|
||||
}
|
||||
|
||||
// Documentation: https://dev.twitter.com/docs/api/1/get/statuses/user_timeline
|
||||
feed.open("GET","http://api.twitter.com/1/statuses/user_timeline/" + user + ".json?trim_user=true&count=" + (parseInt(count, 10)) + "&include_entities=1&exclude_replies=" + (replies ? "0" : "1") + "&callback=?");
|
||||
feed.send();
|
||||
}
|
Loading…
Reference in New Issue
Block a user