github.js: use chrome code to show keyboard shortcuts
[conkeror.git] / modules / page-modes / github.js
blob09f4b342bbcd050c1e0bb2063b672d4e894b8ee8
1 /**
2  * (C) Copyright 2010 Desmond O. Chang <dochang@gmail.com>
3  *
4  * Use, modification, and distribution are subject to the terms specified in the
5  * COPYING file.
6 **/
8 in_module(null);
10 require("content-buffer.js");
12 define_keymap("github_keymap", $display_name = "github");
14 interactive("github-keyboard-shortcuts", null, function (I) {
15     var buf = I.buffer;
16     var elem = buf.document.querySelector("#main a.keyboard-shortcuts");
17     if (elem)
18         browser_object_follow(buf, FOLLOW_DEFAULT, elem);
19     else
20         I.minibuffer.message("No keyboard shortcuts help link found on this page");
21 });
23 interactive("github-focus-site-search", null, function (I) {
24     var buf = I.buffer;
25     var elem = buf.document.querySelector("#top_search_form input[name=q]");
26     if (elem)
27         browser_element_focus(buf, elem);
28     else
29         I.minibuffer.message("Site search box not found");
30 });
32 interactive("github-focus-issues-search", null, function (I) {
33     var buf = I.buffer;
34     var elem = buf.document.querySelector("#issues span.search input[name=q]");
35     if (elem)
36         browser_element_focus(buf, elem);
37     else
38         I.minibuffer.message("Issues search box not found");
39 });
41 [// Site-wide shortcuts
42  "s",                        // Focus site search
43  "?",                        // Bring up this help dialog
44  // Commit list
45  "j",                        // Move selected down
46  "k",                        // Move selected up
47  "t",                        // Open tree
48  "p",                        // Open parent
49  "c", "o", "return",         // Open commit
50  // Pull request list
51  "j",                        // Move selected down
52  "k",                        // Move selected up
53  "o", "return",              // Open issue
54  // Issues
55  "j",                        // Move selected down
56  "k",                        // Move selected up
57  "x",                        // Toggle select target
58  "o", "return",              // Open issue
59  "I",                        // Mark selected as read
60  "U",                        // Mark selected as unread
61  "e",                        // Close selected
62  "y",                        // Remove selected from view
63  "c",                        // Create issue
64  "l",                        // Create label
65  "i",                        // Back to inbox
66  "u",                        // Back to issues
67  "/",                        // Focus issues search
68  // Network Graph
69  "left", "h",                // Scroll left
70  "right", "l",               // Scroll right
71  "up", "k",                  // Scroll up
72  "down", "j",                // Scroll down
73  "t",                        // Toggle visibility of head labels
74  "S-left", "H",              // Scroll all the way left
75  "S-right", "L",             // Scroll all the way right
76  "S-up", "K",                // Scroll all the way up
77  "S-down", "J"]              // Scroll all the way down
78     .map(function (x) define_key(github_keymap, x, null, $fallthrough));
80 define_key(github_keymap, "?", "github-keyboard-shortcuts");
81 define_key(github_keymap, "s", "github-focus-site-search");
82 define_key(github_keymap, "/", "github-focus-issues-search");
85 var github_modality = {
86     normal: github_keymap
89 define_page_mode("github_mode",
90     $enable = function (buffer) {
91         buffer.content_modalities.push(github_modality);
92     },
93     $disable = function (buffer) {
94         var i = buffer.content_modalities.indexOf(github_modality);
95         if (i > -1)
96             buffer.content_modalities.splice(i, 1);
97     },
98     $display_name = "Github"
101 auto_mode_list.push([
102     build_url_regex($domain = "github", $allow_www = true),
103     github_mode
106 provide("github");