Navigation Menu

Skip to content

Commit

Permalink
Merge branch 'gh-issue-redirect'
Browse files Browse the repository at this point in the history
  • Loading branch information
haarg committed Nov 17, 2016
2 parents e751b95 + 0e23d18 commit 5c11f29
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions root/static/js/github.js
Expand Up @@ -10,6 +10,21 @@
this.href = this.item.attr('href');
}

// Callback to handle Github JSONP redirects

function getGithubApiJSONP_cb(success_cb) {
return function (res) {
if (res.meta.status >= 300 && res.meta.status < 400) {
var location = res.meta.Location;
var redirect_url = location.replace(/(callback=).*?(&)/, '$1?$2');
$.getJSON(redirect_url, success_cb);
}
else {
success_cb.apply(this, arguments);
}
};
}

GitHubUrl.match = function(a){
if ($(a).length == 0) return;

Expand All @@ -27,12 +42,12 @@
prepareData: function(data, cb) {
// we need additionally the repo info
var url = this.url.replace('/issues', '');
$.getJSON(url, function(repo) {
$.getJSON(url, getGithubApiJSONP_cb(function(repo) {
cb({
issues: data,
repo: repo.data
});
});
}));
},
render: function(data) {
if (data.issues.length === 0) {
Expand Down Expand Up @@ -146,15 +161,14 @@
}

var self = this;

this.item.qtip({
var qtip;
var tooltip = this.item.qtip({
content: {
ajax: {
dataType: 'json',
type: 'GET',
url: this.url,
success: function(res) {

success: getGithubApiJSONP_cb(function(res) {
var error;
try {
// If there was an error data will likely
Expand All @@ -164,11 +178,10 @@
}
} catch(ignore){ }
if( error ){
this.set('content.text', '<i>' + error + '</i>');
qtip.set('content.text', '<i>' + error + '</i>');
return;
}

var qtip = this;
self.prepareData(res.data, function(data) {
var html = self.render(data);
qtip.set('content.text', html);
Expand All @@ -179,7 +192,7 @@
}
});
});
}
})
},
text: '<i class="fa fa-spinner fa-spin"></i>',
title: 'Github Info'
Expand All @@ -196,6 +209,7 @@
classes: 'qtip-shadow qtip-rounded qtip-light qtip-github',
}
});
qtip = tooltip.qtip('api');
},

// This loops over the keys/values found in this.config and
Expand Down

0 comments on commit 5c11f29

Please sign in to comment.