Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions root/static/js/github.js
Original file line number Diff line number Diff line change
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