blob: ef3d76cc4b57eda49a5add7fd50a1a23b2b86aef [file] [log] [blame]
Simon Hunt0df1b1d2014-11-04 22:58:29 -08001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 Sample view to illustrate key bindings.
Simon Hunt0df1b1d2014-11-04 22:58:29 -080019 */
20
21(function (onos) {
22 'use strict';
23
Simon Hunt934c3ce2014-11-05 11:45:07 -080024 var keyDispatch = {
Simon Hunt0df1b1d2014-11-04 22:58:29 -080025 Z: keyUndo,
26 X: keyCut,
27 C: keyCopy,
28 V: keyPaste,
29 space: keySpace
30 };
31
32 function keyUndo(view) {
33 note(view, 'Z = UNDO');
34 }
35
36 function keyCut(view) {
37 note(view, 'X = CUT');
38 }
39
40 function keyCopy(view) {
41 note(view, 'C = COPY');
42 }
43
44 function keyPaste(view) {
45 note(view, 'V = PASTE');
46 }
47
48 function keySpace(view) {
49 note(view, 'The SpaceBar');
50 }
51
52 function note(view, msg) {
53 view.$div.append('p')
54 .text(msg)
55 .style({
56 'font-size': '10pt',
57 color: 'darkorange',
58 padding: '0 20px',
59 margin: 0
60 });
61 }
62
63 function keyCallback(view, key, keyCode, event) {
64 note(view, 'Key = ' + key + ' KeyCode = ' + keyCode);
65 }
66
Simon Hunt0df1b1d2014-11-04 22:58:29 -080067 function load(view, ctx) {
68 // this maps specific keys to specific functions (1)
69 view.setKeys(keyDispatch);
70 // whereas, this installs a general key handler function (2)
71 view.setKeys(keyCallback);
72
73 // Note that (1) takes precedence over (2)
74
75 view.$div.append('p')
76 .text('Press a key or two (try Z,X,C,V and others) ...')
77 .style('padding', '2px 8px');
78 }
79
80 // == register the view here, with links to lifecycle callbacks
81
82 onos.ui.addView('sampleKeys', {
83 reset: true, // empty the div on reset
84 load: load
85 });
86
87}(ONOS));