keyboard-bindings.js
137 lines
| 4.9 KiB
| application/javascript
|
JavascriptLexer
r1 | // Global keyboard bindings | |||
function setRCMouseBindings(repoName, repoLandingRev) { | ||||
r835 | ||||
/** custom callback for supressing mousetrap from firing */ | ||||
Mousetrap.stopCallback = function(e, element) { | ||||
// if the element has the class "mousetrap" then no need to stop | ||||
if ((' ' + element.className + ' ').indexOf(' mousetrap ') > -1) { | ||||
return false; | ||||
} | ||||
// stop for input, select, and textarea | ||||
return element.tagName == 'INPUT' || element.tagName == 'SELECT' || element.tagName == 'TEXTAREA' || element.isContentEditable; | ||||
}; | ||||
r1 | // general help "?" | |||
Mousetrap.bind(['?'], function(e) { | ||||
$('#help_kb').modal({}); | ||||
}); | ||||
// / open the quick filter | ||||
Mousetrap.bind(['/'], function(e) { | ||||
r2774 | $('#main_filter').get(0).focus(); | |||
r1 | ||||
// return false to prevent default browser behavior | ||||
// and stop event from bubbling | ||||
return false; | ||||
}); | ||||
// ctrl/command+b, show the the main bar | ||||
Mousetrap.bind(['command+b', 'ctrl+b'], function(e) { | ||||
var $headerInner = $('#header-inner'), | ||||
$content = $('#content'); | ||||
if ($headerInner.hasClass('hover') && $content.hasClass('hover')) { | ||||
$headerInner.removeClass('hover'); | ||||
$content.removeClass('hover'); | ||||
} else { | ||||
$headerInner.addClass('hover'); | ||||
$content.addClass('hover'); | ||||
} | ||||
return false; | ||||
}); | ||||
// general nav g + action | ||||
Mousetrap.bind(['g h'], function(e) { | ||||
window.location = pyroutes.url('home'); | ||||
}); | ||||
Mousetrap.bind(['g g'], function(e) { | ||||
r1891 | window.location = pyroutes.url('gists_show', {'private': 1}); | |||
r1 | }); | |||
Mousetrap.bind(['g G'], function(e) { | ||||
r1891 | window.location = pyroutes.url('gists_show', {'public': 1}); | |||
r1 | }); | |||
r3424 | ||||
Mousetrap.bind(['g 0'], function(e) { | ||||
window.location = pyroutes.url('my_account_goto_bookmark', {'bookmark_id': 0}); | ||||
}); | ||||
Mousetrap.bind(['g 1'], function(e) { | ||||
window.location = pyroutes.url('my_account_goto_bookmark', {'bookmark_id': 1}); | ||||
}); | ||||
Mousetrap.bind(['g 2'], function(e) { | ||||
window.location = pyroutes.url('my_account_goto_bookmark', {'bookmark_id': 2}); | ||||
}); | ||||
Mousetrap.bind(['g 3'], function(e) { | ||||
window.location = pyroutes.url('my_account_goto_bookmark', {'bookmark_id': 3}); | ||||
}); | ||||
Mousetrap.bind(['g 4'], function(e) { | ||||
window.location = pyroutes.url('my_account_goto_bookmark', {'bookmark_id': 4}); | ||||
}); | ||||
Mousetrap.bind(['g 5'], function(e) { | ||||
window.location = pyroutes.url('my_account_goto_bookmark', {'bookmark_id': 5}); | ||||
}); | ||||
Mousetrap.bind(['g 6'], function(e) { | ||||
window.location = pyroutes.url('my_account_goto_bookmark', {'bookmark_id': 6}); | ||||
}); | ||||
Mousetrap.bind(['g 7'], function(e) { | ||||
window.location = pyroutes.url('my_account_goto_bookmark', {'bookmark_id': 7}); | ||||
}); | ||||
Mousetrap.bind(['g 8'], function(e) { | ||||
window.location = pyroutes.url('my_account_goto_bookmark', {'bookmark_id': 8}); | ||||
}); | ||||
Mousetrap.bind(['g 9'], function(e) { | ||||
window.location = pyroutes.url('my_account_goto_bookmark', {'bookmark_id': 9}); | ||||
}); | ||||
r1 | Mousetrap.bind(['n g'], function(e) { | |||
r1891 | window.location = pyroutes.url('gists_new'); | |||
r1 | }); | |||
Mousetrap.bind(['n r'], function(e) { | ||||
r2014 | window.location = pyroutes.url('repo_new'); | |||
r1 | }); | |||
r3424 | if (repoName && repoName !== '') { | |||
r1 | // nav in repo context | |||
Mousetrap.bind(['g s'], function(e) { | ||||
window.location = pyroutes.url( | ||||
r1785 | 'repo_summary', {'repo_name': repoName}); | |||
r1 | }); | |||
Mousetrap.bind(['g c'], function(e) { | ||||
window.location = pyroutes.url( | ||||
r3742 | 'repo_commits', {'repo_name': repoName}); | |||
r1 | }); | |||
Mousetrap.bind(['g F'], function(e) { | ||||
window.location = pyroutes.url( | ||||
r1927 | 'repo_files', | |||
r1 | { | |||
'repo_name': repoName, | ||||
r1927 | 'commit_id': repoLandingRev, | |||
r1 | 'f_path': '', | |||
'search': '1' | ||||
}); | ||||
}); | ||||
Mousetrap.bind(['g f'], function(e) { | ||||
window.location = pyroutes.url( | ||||
r1927 | 'repo_files', | |||
r1 | { | |||
'repo_name': repoName, | ||||
r1927 | 'commit_id': repoLandingRev, | |||
r1 | 'f_path': '' | |||
}); | ||||
}); | ||||
r4084 | Mousetrap.bind(['g p'], function(e) { | |||
window.location = pyroutes.url( | ||||
'pullrequest_show_all', {'repo_name': repoName}); | ||||
}); | ||||
r1 | Mousetrap.bind(['g o'], function(e) { | |||
window.location = pyroutes.url( | ||||
'edit_repo', {'repo_name': repoName}); | ||||
}); | ||||
Mousetrap.bind(['g O'], function(e) { | ||||
window.location = pyroutes.url( | ||||
'edit_repo_perms', {'repo_name': repoName}); | ||||
}); | ||||
} | ||||
} | ||||
setRCMouseBindings(templateContext.repo_name, templateContext.repo_landing_commit); | ||||