Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UX Fixes for Enterprise #49

Merged
5 commits merged into from
Aug 19, 2017
Merged
Show file tree
Hide file tree
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
18 changes: 5 additions & 13 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@

var gh_enterprise;
const urls = ['github.com'];

function host(url) {
return url.trim().replace(/^(?:https?:\/\/)([^\/?#]+).*$/, '$1').toLowerCase();
return new URL(url).hostname;
}

chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
var urls = ['github.com'];
if (gh_enterprise) {
gh_enterprise = gh_enterprise.replace('https://', '');
gh_enterprise = gh_enterprise.replace('http://', '');
urls.push(gh_enterprise);
}

if (-1 !== urls.indexOf(host(tab.url))) {
if (urls.includes(host(tab.url))) {
chrome.pageAction.show(tabId);
if (tab.url.indexOf('github.com') < 0) {
if (!tab.url.includes('github.com')) {
chrome.tabs.insertCSS(null, {file: "pullrequest.css"});
chrome.tabs.executeScript(null, {file: "jquery-1.9.1.min.js"});
chrome.tabs.executeScript(null, {file: "enterprise.js"});
Expand All @@ -24,5 +16,5 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
});

chrome.storage.sync.get({url: ''}, function(items) {
gh_enterprise = items.url;
urls.push(host(items.url));
});
38 changes: 24 additions & 14 deletions enterprise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ var repositoryName;
var repositoryAuthor;
var autoCollapseExpressions;

function onFilesPage() {
return window.location.href.indexOf('files') !== -1;
}

function htmlIsInjected() {
return $('.pretty-pull-requests-inserted').length > 0;
}

function injectHtml() {
if (!onFilesPage()) return;
$('<span class="pretty-pull-requests collapse-lines">' +
'<label><input type="checkbox" class="js-collapse-additions" checked="yes">+</label>' +
'<label><input type="checkbox" class="js-collapse-deletions" checked="yes">-</label>' +
Expand Down Expand Up @@ -54,7 +59,7 @@ function getIds(path) {
}

function getId(path) {
var $span = $('span[title="' + path + '"]').closest('[id^=diff-]');
var $span = $('a[title="' + path + '"]').closest('[id^=diff-]');
var $a = $span.prev('a[name^=diff-]');
var id = $a.attr('name');

Expand Down Expand Up @@ -89,7 +94,7 @@ function toggleDiff(id, duration, display) {

if ($a) {
var $span = $a.next('div[id^=diff-]');
var $data = $span.children('.data, .image');
var $data = $span.children('.js-file-content');
var $bottom = $span.children('.bottom-collapse');

switch (display) {
Expand Down Expand Up @@ -147,16 +152,16 @@ function initDiffs() {
autoCollapse();
}

function clickTitle() {
function clickTitle(e) {
e.preventDefault();
var path = $(this).attr('title') || this.innerText;
var id = getId(path);
debugger;

return toggleDiff(id);
}

function clickCollapse() {
var $span = $(this).prevAll('.file-header');
var $span = $(this).closest('.js-file-content').prev('.file-header');
var path = $span.attr('data-path');
var id = getId(path);

Expand All @@ -170,23 +175,28 @@ function autoCollapse() {
}

chrome.storage.sync.get({url: '', saveCollapsedDiffs: true, tabSwitchingEnabled: false, autoCollapseExpressions: []}, function(items) {
if (items.url == window.location.origin ||
if (items.url === window.location.origin ||
"https://github.com" === window.location.origin) {

autoCollapseExpressions = items.autoCollapseExpressions;

var interval = null;
var injectHtmlIfNecessary = function () {
if (!htmlIsInjected()) {
collectUniquePageInfo();
injectHtml();
initDiffs();
$body.on('click', '.user-select-contain, .js-selectable-text, .file-info .link-gray-dark', clickTitle);
$body.on('click', '.bottom-collapse', clickCollapse);
$body.on('click', '.js-collapse-additions', collapseAdditions);
$body.on('click', '.js-collapse-deletions', collapseDeletions);
if (onFilesPage()) {
collectUniquePageInfo();
injectHtml();
initDiffs();
$body.on('click', '.user-select-contain, .js-selectable-text, .file-info .link-gray-dark', clickTitle);
$body.on('click', '.bottom-collapse', clickCollapse);
$body.on('click', '.js-collapse-additions', collapseAdditions);
$body.on('click', '.js-collapse-deletions', collapseDeletions);
}
} else {
clearInterval(interval);
}
setTimeout(injectHtmlIfNecessary, 1000);
};
interval = setInterval(injectHtmlIfNecessary, 1000);
var $body = $('body');
useLocalStorage = items.saveCollapsedDiffs;

Expand Down