From e82cf9c5a79af3f775efec22f57e508d62a62737 Mon Sep 17 00:00:00 2001 From: yakudza Date: Mon, 10 Oct 2016 09:35:31 +0300 Subject: [PATCH 1/2] [WIP] issue 1650 --- root/static/js/github.js | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/root/static/js/github.js b/root/static/js/github.js index 331551cd6c..156ae68994 100644 --- a/root/static/js/github.js +++ b/root/static/js/github.js @@ -7,7 +7,23 @@ function GithubUrl(item) { this.item = $(item); - this.href = this.item.attr('href'); + var href = this.item.attr('href').replace('Perl-Email-Project', 'rjbs'); + this.href = 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){ @@ -27,12 +43,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) { @@ -146,15 +162,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 @@ -164,11 +179,10 @@ } } catch(ignore){ } if( error ){ - this.set('content.text', '' + error + ''); + qtip.set('content.text', '' + error + ''); return; } - var qtip = this; self.prepareData(res.data, function(data) { var html = self.render(data); qtip.set('content.text', html); @@ -179,7 +193,7 @@ } }); }); - } + }) }, text: '', title: 'Github Info' @@ -196,6 +210,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 From 73dbfbdda6bee4fe89c0bcdd6433d45d499ff09c Mon Sep 17 00:00:00 2001 From: yakudza Date: Mon, 10 Oct 2016 22:35:34 +0300 Subject: [PATCH 2/2] clean up --- root/static/js/github.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/root/static/js/github.js b/root/static/js/github.js index 156ae68994..fe412ec20a 100644 --- a/root/static/js/github.js +++ b/root/static/js/github.js @@ -7,8 +7,7 @@ function GithubUrl(item) { this.item = $(item); - var href = this.item.attr('href').replace('Perl-Email-Project', 'rjbs'); - this.href = href; //this.item.attr('href'); + this.href = this.item.attr('href'); } // Callback to handle Github JSONP redirects