Show More
@@ -1,89 +1,101 b'' | |||
|
1 | 1 | // Global keyboard bindings |
|
2 | 2 | |
|
3 | 3 | function setRCMouseBindings(repoName, repoLandingRev) { |
|
4 | ||
|
5 | /** custom callback for supressing mousetrap from firing */ | |
|
6 | Mousetrap.stopCallback = function(e, element) { | |
|
7 | // if the element has the class "mousetrap" then no need to stop | |
|
8 | if ((' ' + element.className + ' ').indexOf(' mousetrap ') > -1) { | |
|
9 | return false; | |
|
10 | } | |
|
11 | ||
|
12 | // stop for input, select, and textarea | |
|
13 | return element.tagName == 'INPUT' || element.tagName == 'SELECT' || element.tagName == 'TEXTAREA' || element.isContentEditable; | |
|
14 | }; | |
|
15 | ||
|
4 | 16 | // general help "?" |
|
5 | 17 | Mousetrap.bind(['?'], function(e) { |
|
6 | 18 | $('#help_kb').modal({}); |
|
7 | 19 | }); |
|
8 | 20 | |
|
9 | 21 | // / open the quick filter |
|
10 | 22 | Mousetrap.bind(['/'], function(e) { |
|
11 | 23 | $('#repo_switcher').select2('open'); |
|
12 | 24 | |
|
13 | 25 | // return false to prevent default browser behavior |
|
14 | 26 | // and stop event from bubbling |
|
15 | 27 | return false; |
|
16 | 28 | }); |
|
17 | 29 | |
|
18 | 30 | // ctrl/command+b, show the the main bar |
|
19 | 31 | Mousetrap.bind(['command+b', 'ctrl+b'], function(e) { |
|
20 | 32 | var $headerInner = $('#header-inner'), |
|
21 | 33 | $content = $('#content'); |
|
22 | 34 | if ($headerInner.hasClass('hover') && $content.hasClass('hover')) { |
|
23 | 35 | $headerInner.removeClass('hover'); |
|
24 | 36 | $content.removeClass('hover'); |
|
25 | 37 | } else { |
|
26 | 38 | $headerInner.addClass('hover'); |
|
27 | 39 | $content.addClass('hover'); |
|
28 | 40 | } |
|
29 | 41 | return false; |
|
30 | 42 | }); |
|
31 | 43 | |
|
32 | 44 | // general nav g + action |
|
33 | 45 | Mousetrap.bind(['g h'], function(e) { |
|
34 | 46 | window.location = pyroutes.url('home'); |
|
35 | 47 | }); |
|
36 | 48 | Mousetrap.bind(['g g'], function(e) { |
|
37 | 49 | window.location = pyroutes.url('gists', {'private': 1}); |
|
38 | 50 | }); |
|
39 | 51 | Mousetrap.bind(['g G'], function(e) { |
|
40 | 52 | window.location = pyroutes.url('gists', {'public': 1}); |
|
41 | 53 | }); |
|
42 | 54 | Mousetrap.bind(['n g'], function(e) { |
|
43 | 55 | window.location = pyroutes.url('new_gist'); |
|
44 | 56 | }); |
|
45 | 57 | Mousetrap.bind(['n r'], function(e) { |
|
46 | 58 | window.location = pyroutes.url('new_repo'); |
|
47 | 59 | }); |
|
48 | 60 | |
|
49 | 61 | if (repoName !== '' && repoLandingRev !== '') { |
|
50 | 62 | // nav in repo context |
|
51 | 63 | Mousetrap.bind(['g s'], function(e) { |
|
52 | 64 | window.location = pyroutes.url( |
|
53 | 65 | 'summary_home', {'repo_name': repoName}); |
|
54 | 66 | }); |
|
55 | 67 | Mousetrap.bind(['g c'], function(e) { |
|
56 | 68 | window.location = pyroutes.url( |
|
57 | 69 | 'changelog_home', {'repo_name': repoName}); |
|
58 | 70 | }); |
|
59 | 71 | Mousetrap.bind(['g F'], function(e) { |
|
60 | 72 | window.location = pyroutes.url( |
|
61 | 73 | 'files_home', |
|
62 | 74 | { |
|
63 | 75 | 'repo_name': repoName, |
|
64 | 76 | 'revision': repoLandingRev, |
|
65 | 77 | 'f_path': '', |
|
66 | 78 | 'search': '1' |
|
67 | 79 | }); |
|
68 | 80 | }); |
|
69 | 81 | Mousetrap.bind(['g f'], function(e) { |
|
70 | 82 | window.location = pyroutes.url( |
|
71 | 83 | 'files_home', |
|
72 | 84 | { |
|
73 | 85 | 'repo_name': repoName, |
|
74 | 86 | 'revision': repoLandingRev, |
|
75 | 87 | 'f_path': '' |
|
76 | 88 | }); |
|
77 | 89 | }); |
|
78 | 90 | Mousetrap.bind(['g o'], function(e) { |
|
79 | 91 | window.location = pyroutes.url( |
|
80 | 92 | 'edit_repo', {'repo_name': repoName}); |
|
81 | 93 | }); |
|
82 | 94 | Mousetrap.bind(['g O'], function(e) { |
|
83 | 95 | window.location = pyroutes.url( |
|
84 | 96 | 'edit_repo_perms', {'repo_name': repoName}); |
|
85 | 97 | }); |
|
86 | 98 | } |
|
87 | 99 | } |
|
88 | 100 | |
|
89 | 101 | setRCMouseBindings(templateContext.repo_name, templateContext.repo_landing_commit); |
General Comments 0
You need to be logged in to leave comments.
Login now