Skip to content

Commit

Permalink
Allow tab switching to be optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Graham Holtslander committed Jun 10, 2015
1 parent 6a28f09 commit 2e706bc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
5 changes: 5 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ <h1>Options</h1>
</label>
<input id="url" type="url" class="form-control">
</div>
<div class="form-group">
<label>
Allow backtick to switch tabs on pull requests? <input id="tabSwitchingEnabled" type="checkbox">
</label>
</div>
<button class="btn btn-primary" id="save">Save</button>
</form>
<div id="status" class="bg-success"></div>
Expand Down
3 changes: 3 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
$(document).ready(function () {
loadItemsFromChromeStorage({
url: '',
tabSwitchingEnabled: false
// Add new items here to get them loaded and their values put in the form.
}, setFormValues);

Expand All @@ -44,9 +45,11 @@

var $form = $(e.currentTarget);
var url = $form.find('#url').val();
var tabSwitchingEnabled = $form.find('#tabSwitchingEnabled').prop('checked');

saveOptionsToChromeStorage({
'url': url,
'tabSwitchingEnabled': tabSwitchingEnabled,
}, function () {
var status = $('#status');
status.text('Options saved.');
Expand Down
36 changes: 19 additions & 17 deletions pullrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function moveToPreviousTab($pullRequestTabs, selectedTabIndex) {
$pullRequestTabs[selectedTabIndex].click();
}

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

Expand Down Expand Up @@ -93,22 +93,24 @@ chrome.storage.sync.get({url: ''}, function(items) {

$body.on('click', '.js-collapse-deletions', collapseDeletions);

$body.on('keydown', function (e) {
if (e.keyCode !== 192 || e.target.nodeName === 'TEXTAREA') {
return;
}

var $pullRequestTabs = $('.js-pull-request-tab');
var selectedTabIndex = $('.js-pull-request-tab.selected').index();

if (e.shiftKey) {
// Making this work like it would in other apps, where the shift
// key makes the cmd+tilde go backwards through the list.
moveToPreviousTab($pullRequestTabs, selectedTabIndex);
} else {
moveToNextTab($pullRequestTabs, selectedTabIndex);
}
});
if (items.tabSwitchingEnabled) {
$body.on('keydown', function (e) {
if (e.keyCode !== 192 || e.target.nodeName === 'TEXTAREA') {
return;
}

var $pullRequestTabs = $('.js-pull-request-tab');
var selectedTabIndex = $('.js-pull-request-tab.selected').index();

if (e.shiftKey) {
// Making this work like it would in other apps, where the shift
// key makes the cmd+tilde go backwards through the list.
moveToPreviousTab($pullRequestTabs, selectedTabIndex);
} else {
moveToNextTab($pullRequestTabs, selectedTabIndex);
}
});
}

// Actions per changed file
chrome.runtime.onConnect.addListener(function (port) {
Expand Down

0 comments on commit 2e706bc

Please sign in to comment.