forked from dojo/dojo1-dgrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
139 lines (131 loc) · 3.42 KB
/
index.html
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>dgrid Tests</title>
<style>
@import "../css/dgrid.css";
@import "../css/skins/slate.css";
html, body {
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
body {
font-family: Calibri, Verdana, Arial, Helvetica, sans-serif;
}
.toc {
border: none;
height: 100%;
}
.toc .header-title {
padding: 7px 20px;
}
.toc .dgrid-cell {
border: none;
}
.toc .dgrid-row {
background-color: #fff;
border-bottom: 1px solid #ccc;
cursor: pointer;
}
.toc .dgrid-row:hover {
background-color: #def;
}
.toc a {
/* Subdue default link styles, since entire row is clickable */
color: #000;
text-decoration: none;
}
.toc .field-name {
width: 20em;
}
</style>
</head>
<body class="slate">
<div id="grid"></div>
<script src="../../dojo/dojo.js" data-dojo-config="async: true"></script>
<script>
require([
"dojo/_base/xhr",
"dojo/on",
"dojo/json",
"dojo/store/Memory",
"dojo/cookie",
"dgrid/OnDemandGrid",
"dgrid/tree",
"put-selector/put",
"dojo/query",
"dojo/domReady!"
], function(xhr, on, json, Memory, cookie, OnDemandGrid, tree, put){
xhr.get({
url: "data/index.json",
handleAs: "json"
}).then(function(data){
var store = window.store = new Memory({
data: data,
idProperty: "url",
getChildren: function(parent, options){
return this.query({ parent: parent.url }, options);
},
mayHaveChildren: function(parent){
return !parent.title; // Items with title are html pages, leaves
}
});
var cookieName = "dgrid-test-index",
persistedInfo = cookie(cookieName);
persistedInfo = persistedInfo ?
json.parse(persistedInfo) : { expanded: {} };
function shouldExpand(row, level, previouslyExpanded) {
return previouslyExpanded || !!persistedInfo.expanded[row.id];
}
function renderLinkCell(object, value){
// Render a link for cells in rows representing pages
// (not parent directories)
return put(object.title ? "a[href=" + object.url + "]" : "div",
value || "");
}
var grid = new OnDemandGrid({
className: "toc",
columns: {
name: tree({
shouldExpand: shouldExpand,
renderCell: renderLinkCell,
expandOn: ".dgrid-row:click"
}),
title: { renderCell: renderLinkCell }
},
renderHeader: function(){
put(this.headerNode, "div.header-title", "dgrid Tests");
},
query: { parent: "" },
sort: "name",
store: store
}, "grid");
if(persistedInfo.scroll){
// Restore scroll position on initial refresh
on.once(grid, "dgrid-refresh-complete", function(){
grid.scrollTo({ y: persistedInfo.scroll });
});
}
grid.on(".dgrid-row:click", function(evt){
var item = grid.row(evt).data;
if(item.title){
// Persist state of expansion and scroll
cookie(cookieName, json.stringify({
expanded: grid._expanded,
scroll: grid.getScrollPosition().y
}));
// Navigate to test page, unless a link was clicked
// (in which case navigation will occur anyway)
if(evt.target.tagName !== "A"){
location.href = item.url;
}
}
});
});
});
</script>
</body>
</html>