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