Created
August 24, 2016 22:09
-
-
Save hk0i/e726becbf5e3792340d74d8f50ae73dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Allows numbers 1-3 to switch tabs in a pull request on bitbucket.org | |
*/ | |
var TabNumbers = (function($) { | |
var ids = { | |
'overview': '#pr-menu-diff', | |
'commits': '#pr-menu-commits', | |
'activity': '#pr-menu-activity' | |
}; | |
var self = {}; | |
self.switchTo = function(tabName) { | |
if (tabName in ids) { | |
$(ids[tabName]).click(); | |
} | |
}; | |
self.init = function(keyboard) { | |
console.log('init'); | |
keyboard.reset(); | |
keyboard.bind('1', function(event) { | |
event.preventDefault(); | |
self.switchTo('overview'); | |
}); | |
keyboard.bind('2', function(event) { | |
event.preventDefault(); | |
self.switchTo('commits'); | |
}); | |
keyboard.bind('3', function(event) { | |
event.preventDefault(); | |
self.switchTo('activity'); | |
}); | |
}; | |
return self; | |
})(jQuery); | |
jQuery('ready', function() { | |
if (typeof Mousetrap === 'undefined') { | |
$.getScript('https://cdnjs.cloudflare.com/ajax/libs/mousetrap/1.4.6/mousetrap.min.js', function() { | |
TabNumbers.init(Mousetrap); | |
}); | |
} | |
else { | |
TabNumbers.init(Mousetrap); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment