liuyg
2021-07-02 25ce610f6ecca7325e7a743dc032c4a76559c63d
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
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Test Keyboard Mixin</title>
        <meta name="viewport" content="width=570">
        <style>
            @import "../../dojo/resources/dojo.css";
            @import "../css/dgrid.css";
            @import "../css/skins/claro.css";
            /* add styles to size this grid appropriately */
            .dgrid {
                height: 15em;
                float: left;
                width: 40%;
                margin: 1em 0.5%;
            }
            .field-order {
                width: 3em;
            }
            .field-name {
                width: 8em;
            }
            #list {
                width: 15%;
            }
 
            .clear {
                clear: both;
            }
        </style>
        <script src="../../dojo/dojo.js"
            data-dojo-config="async: true"></script>
        <script>
            var getFirstTarget; // function, defined within require callback
 
            require(["dgrid/OnDemandList", "dgrid/OnDemandGrid", "dgrid/Keyboard", "dojo/_base/declare", "dojo/on", "dojo/query", "dgrid/test/data/testStore", "dojo/domReady!"],
            function(OnDemandList, OnDemandGrid, Keyboard, declare, on, query, testStore){
                var columns = {
                        col1: "Column 1",
                        col3: "Column 3",
                        col5: "Column 5"
                    },
                    KeyboardList = declare([OnDemandList, Keyboard]),
                    KeyboardGrid = declare([OnDemandGrid, Keyboard]),
                    list = window.list = new KeyboardList({
                        collection: testStore,
                        renderRow: function (item) {
                            var div = document.createElement('div');
                            div.appendChild(document.createTextNode(item.col5));
                            return div;
                        }
                    }, "list"),
                    grid = window.grid = new KeyboardGrid({
                        collection: testStore,
                        columns: columns
                    }, "grid"),
                    rowGrid = window.rowGrid = new KeyboardGrid({
                        collection: testStore,
                        columns: columns,
                        cellNavigation: false
                    }, "rowGrid");
 
                getFirstTarget = function(grid){
                    return query(".dgrid-content .dgrid-cell", grid.domNode)[0] ||
                        query(".dgrid-content .dgrid-row", grid.domNode)[0];
                };
 
                on(document.body, "dgrid-cellfocusin,dgrid-cellfocusout",
                    function(event){
                        var msg = "focus " + (event.type == "dgrid-cellfocusin" ? "gained" : "lost");
                        console.log(event.grid.id + ": " + msg +
                            (event.parentType ? " (via " + event.parentType + "): " : ": "),
                            event.cell || event.row
                        );
                    }
                );
            });
        </script>
    </head>
    <body class="claro">
        <h2>Keyboard/focus-enabled List and Grids</h2>
        <div id="list"></div>
        <div id="grid"></div>
        <div id="rowGrid"></div>
        <div class="clear">
            <h3>Buttons to test programmatic focus</h3>
            <div>Focus, no argument:
                <button onclick="list.focus();">List</button>
                <button onclick="grid.focus();">Cell-navigation Grid</button>
                <button onclick="rowGrid.focus();">Row-navigation Grid</button>
            </div>
            <div>Focus first row/cell:
                <button onclick="list.focus(getFirstTarget(list));">List</button>
                <button onclick="grid.focus(getFirstTarget(grid));">Cell-navigation Grid</button>
                <button onclick="rowGrid.focus(getFirstTarget(rowGrid));">Row-navigation Grid</button>
            </div>
            <div>Focus header (no argument):
                <button onclick="grid.focusHeader();">Cell-navigation Grid</button>
                <button onclick="grid.set('columns', grid.columns); grid.focusHeader();">
                    Reset columns, then focus</button>
            </div>
        </div>
    </body>
</html>