aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/demos/keyboardshortcuts.html
blob: 2baec7b813b1a7273326230bb77ce2116ad6b6fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<html>
<!--
Copyright 2010 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
  <title>goog.ui.KeyboardShortcutHandler</title>
  <meta charset="utf-8">
  <script src="../base.js"></script>
  <script>
    goog.require('goog.dom');
    goog.require('goog.events.KeyCodes');
    goog.require('goog.ui.KeyboardShortcutHandler');
  </script>
  <link rel="stylesheet" href="css/demo.css">
</head>
<body>
  <h1>goog.ui.KeyboardShortcutHandler</h1>
  <div id="text"></div>
  <input type="text" />
  <input type="checkbox" />
  <input type="radio" />
  <button>button</button>
  <textarea></textarea>

  <pre>
    Shortcuts:
      A
      T E S T
      Shift+F12
      Shift+F11 C
      Ctrl+A
      G O O G
      B C
      B D
      Alt+Q A
      Alt+Q Shift+A
      Alt+Q Shift+B
      Space
      Home
      Enter
      G S
      S
      Meta+y
  </pre>

  <script>

    function showTriggered(event) {
      goog.dom.setTextContent(document.getElementById('text'),
          'Shortcut triggered: ' + event.identifier);
    }

    var shortcutHandler = new goog.ui.KeyboardShortcutHandler(document);

    var NONE = goog.ui.KeyboardShortcutHandler.Modifiers.NONE;
    var CTRL = goog.ui.KeyboardShortcutHandler.Modifiers.CTRL;
    var SHIFT = goog.ui.KeyboardShortcutHandler.Modifiers.SHIFT;
    var ALT = goog.ui.KeyboardShortcutHandler.Modifiers.ALT;
    var META = goog.ui.KeyboardShortcutHandler.Modifiers.META;

    shortcutHandler.registerShortcut('A', 'a');
    shortcutHandler.registerShortcut('T E S T', 't e s t');
    shortcutHandler.registerShortcut('SHIFT_F12', 'shift+f12');
    shortcutHandler.registerShortcut('SHIFT_F11 C', 'shift+f11 c');
    shortcutHandler.registerShortcut('META_Y', 'meta+y');
    shortcutHandler.registerShortcut('G S', 'g s');
    shortcutHandler.registerShortcut('S', 's');

    shortcutHandler.registerShortcut('GOOG',
        goog.events.KeyCodes.G, NONE,
        goog.events.KeyCodes.O, NONE,
        goog.events.KeyCodes.O, NONE,
        goog.events.KeyCodes.G);

    shortcutHandler.registerShortcut('CTRL_A',
        goog.events.KeyCodes.A, CTRL);

    shortcutHandler.registerShortcut('BC',
        goog.events.KeyCodes.B, NONE,
        goog.events.KeyCodes.C);

    shortcutHandler.registerShortcut('BD',
        goog.events.KeyCodes.B, NONE,
        goog.events.KeyCodes.D);

    shortcutHandler.registerShortcut('ALT_Q A',
        goog.events.KeyCodes.Q, ALT,
        goog.events.KeyCodes.A);

    shortcutHandler.registerShortcut('ALT_Q SHIFT_A',
        goog.events.KeyCodes.Q, ALT,
        goog.events.KeyCodes.A, SHIFT);

    shortcutHandler.registerShortcut('ALT_Q SHIFT_B', [
        goog.events.KeyCodes.Q, ALT,
        goog.events.KeyCodes.B, SHIFT]);

    shortcutHandler.registerShortcut('SPACE', goog.events.KeyCodes.SPACE);
    shortcutHandler.registerShortcut('HOME', goog.events.KeyCodes.HOME);
    shortcutHandler.registerShortcut('ENTER', goog.events.KeyCodes.ENTER);

    goog.events.listen(
        shortcutHandler,
        goog.ui.KeyboardShortcutHandler.EventType.SHORTCUT_TRIGGERED,
        showTriggered);
  </script>
</body>
</html>