Using protocol relative URLs for Twitter, GitHub and Pinboard feeds

This commit is contained in:
Brandon Mathis 2012-09-29 22:48:11 -05:00
parent 3f842465bd
commit 9f7425a953
2 changed files with 8 additions and 8 deletions

View File

@ -165,9 +165,9 @@ var octopress = (function(){
function linkifyTweet(text, url) { function linkifyTweet(text, url) {
// Linkify urls, usernames, hashtags // Linkify urls, usernames, hashtags
text = text.replace(/(https?:\/\/)([\w\-:;?&=+.%#\/]+)/gi, '<a href="$1$2">$2</a>') text = text.replace(/(https?:)(\/\/)([\w\-:;?&=+.%#\/]+)/gi, '<a href="$2$3">$3</a>')
.replace(/(^|\W)@(\w+)/g, '$1<a href="http://twitter.com/$2">@$2</a>') .replace(/(^|\W)@(\w+)/g, '$1<a href="//twitter.com/$2">@$2</a>')
.replace(/(^|\W)#(\w+)/g, '$1<a href="http://search.twitter.com/search?q=%23$2">#$2</a>'); .replace(/(^|\W)#(\w+)/g, '$1<a href="//search.twitter.com/search?q=%23$2">#$2</a>');
// 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) {
@ -186,7 +186,7 @@ var octopress = (function(){
content = ''; content = '';
for (var t in tweets) { for (var t in tweets) {
content += '<li>'+'<p>'+'<a href="http://twitter.com/'+twitter_user+'/status/'+tweets[t].id_str+'">'+octopress.prettyDate(tweets[t].created_at)+'</a>'+linkifyTweet(tweets[t].text.replace(/\n/g, '<br>'), tweets[t].entities.urls)+'</p>'+'</li>'; content += '<li>'+'<p>'+'<a href="//twitter.com/'+twitter_user+'/status/'+tweets[t].id_str+'">'+octopress.prettyDate(tweets[t].created_at)+'</a>'+linkifyTweet(tweets[t].text.replace(/\n/g, '<br>'), tweets[t].entities.urls)+'</p>'+'</li>';
} }
timeline.innerHTML = content; timeline.innerHTML = content;
} }
@ -199,7 +199,7 @@ var octopress = (function(){
var count = parseInt(target.attr('data-count'), 10); var count = parseInt(target.attr('data-count'), 10);
var replies = target.attr('data-replies') == 'true'; var replies = target.attr('data-replies') == 'true';
$.ajax({ $.ajax({
url: "http://api.twitter.com/1/statuses/user_timeline/" + user + ".json?trim_user=true&count=" + (count + 20) + "&include_entities=1&exclude_replies=" + (replies ? "0" : "1") + "&callback=?" url: "//api.twitter.com/1/statuses/user_timeline/" + user + ".json?trim_user=true&count=" + (count + 20) + "&include_entities=1&exclude_replies=" + (replies ? "0" : "1") + "&callback=?"
, dataType: 'jsonp' , dataType: 'jsonp'
, error: function (err) { $('#tweets li.loading').addClass('error').text("Twitter's busted"); } , error: function (err) { $('#tweets li.loading').addClass('error').text("Twitter's busted"); }
, success: function(data) { render(data.slice(0, count), user); } , success: function(data) { render(data.slice(0, count), user); }
@ -235,7 +235,7 @@ var octopress = (function(){
var count = parseInt(target.attr('data-count')) var count = parseInt(target.attr('data-count'))
var skip_forks = target.attr('data-skip') == 'true'; var skip_forks = target.attr('data-skip') == 'true';
$.ajax({ $.ajax({
url: "https://api.github.com/users/"+user+"/repos?callback=?" url: "//api.github.com/users/"+user+"/repos?callback=?"
, dataType: 'jsonp' , dataType: 'jsonp'
, error: function (err) { target.find('.loading').addClass('error').text("Error loading feed"); } , error: function (err) { target.find('.loading').addClass('error').text("Error loading feed"); }
, success: function(data) { , success: function(data) {

View File

@ -39,7 +39,7 @@ var pinboard = (function(){
if (it.t.length > 0) { if (it.t.length > 0) {
for (var i = 0; i < it.t.length; i++) { for (var i = 0; i < it.t.length; i++) {
var tag = it.t[i]; var tag = it.t[i];
str += " <a class=\"pin-tag\" href=\"http://pinboard.in/u:"+ this.cook(it.a) + "/t:" + this.cook(tag) + "\">" + this.cook(tag).replace(/^\s+|\s+$/g, '') + "</a> "; str += " <a class=\"pin-tag\" href=\"//pinboard.in/u:"+ this.cook(it.a) + "/t:" + this.cook(tag) + "\">" + this.cook(tag).replace(/^\s+|\s+$/g, '') + "</a> ";
} }
} }
str += "</p></li>\n"; str += "</p></li>\n";
@ -50,7 +50,7 @@ var pinboard = (function(){
return { return {
getFeed: function(options) { getFeed: function(options) {
this.element = options.target; this.element = options.target;
fetch("http://feeds.pinboard.in/json/v1/u:"+options.user+"/?cb=pinboard.render\&count="+options.count); fetch("//feeds.pinboard.in/json/v1/u:"+options.user+"/?cb=pinboard.render\&count="+options.count);
}, },
render: function(data) { render: function(data) {