forked from DevExpress/devextreme-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
200 lines (175 loc) · 5.51 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="../../node_modules/devextreme/dist/css/dx.dark.css" />
<script src="../../node_modules/devextreme/dist/js/dx.all.js"></script>
<style>
body,
html {
margin: 0;
height: 100%;
}
</style>
</head>
<body class="dx-viewport">
<div id="toolbar"></div>
<div id="drawer" style="height: calc(100% - 56px)">
<div id="content" style="height: 100%">
<iframe id="frame" style="width: 100%; height: calc(100% - 56px); resize: both" src="JSDemos/Demos/DataGrid/Overview/jQuery/"></iframe>
<br />
<div>
<a id="demolink" target="_blank" href="">open in separate tab</a>
</div>
</div>
</div>
<script>
const ui = DevExpress.ui;
const themeCookieName = "dx-demo-theme";
let approach = null;
let theme = null;
let widget = null;
let name = null;
let treeList = null;
const processLink = () => {
if (window.location.hash === "") {
window.location.hash = "#JSDemos/Demos/DataGrid/Overview/jQuery/dx.light.css";
}
const pathParts = window.location.hash
.substring(1)
.split("/")
.filter((s) => s !== "");
const selectedData = treeList?.getSelectedRowsData("leavesOnly");
if (selectedData?.length) {
pathParts[2] = selectedData[0].Widget;
pathParts[3] = selectedData[0].Name;
}
approach = approach ?? pathParts[4];
theme = theme ?? pathParts[5];
widget = pathParts[2];
name = pathParts[3];
pathParts[4] = approach;
pathParts[5] = theme;
const link = pathParts.slice(0, -1).join("/");
window.location.hash = `#${link}/${theme}`;
return link + "/";
};
const setThemeCookie = () => {
const now = new Date();
// expires in a month
now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * 30);
document.cookie = `dx-demo-theme=${theme};path=/;expires=${now.toUTCString()}`;
};
const updateDemo = () => {
setThemeCookie();
document.getElementById("frame").src = document.getElementById("demolink").href = processLink();
};
const processDataSourceItem = (item) => {
if (!item.Widget) {
item.Title = item.Name;
}
if (item.Demos && item.Demos.length && !item.Groups) {
item.Groups = item.Demos;
}
if (item.Groups && item.Groups.length) {
item.Groups.forEach(processDataSourceItem);
}
item.key = (!item.Widget ? Math.random() : item.Widget) + item.Name;
return item;
};
const drawerTemplate = () => {
const treeListElement = document.createElement("div");
treeList = new ui.dxTreeList(treeListElement, {
dataStructure: "tree",
itemsExpr: "Groups",
keyExpr: "key",
width: 250,
height: "100%",
selection: {
mode: "single",
},
onSelectionChanged: updateDemo,
columns: [
{
dataField: "Title",
dataType: "string",
filterOperations: ["contains"],
},
],
showColumnHeaders: false,
filterMode: "fullBranch",
filterRow: {
visible: true,
},
});
DevExpress.utils.ajax
.sendRequest({
url: "JSDemos/menuMeta.json",
dataType: "json",
})
.then((data) => {
treeList.option("dataSource", data.map(processDataSourceItem));
treeList.selectRows([widget + name]);
treeList.option("focusedRowKey", widget + name);
});
return treeListElement;
};
document.addEventListener("DOMContentLoaded", function () {
updateDemo();
const drawerElement = document.getElementById("drawer");
const toolbarElement = document.getElementById("toolbar");
const drawer = new ui.dxDrawer(drawerElement, {
opened: true,
closeOnOutsideClick: false,
template: drawerTemplate,
});
new ui.dxToolbar(toolbarElement, {
items: [
{
location: "before",
widget: "dxButton",
options: {
icon: "menu",
onClick: () => drawer.toggle(),
},
},
{
location: "after",
widget: "dxSelectBox",
options: {
items: ["jQuery", "Angular", "Vue", "React"],
value: approach,
width: 100,
onValueChanged: (e) => {
approach = e.value;
updateDemo();
},
},
},
{
location: "after",
widget: "dxSelectBox",
options: {
dataSource: "/themes",
value: theme,
width: 250,
searchEnabled: true,
onValueChanged: (e) => {
theme = e.value;
updateDemo();
},
},
},
{
location: "after",
widget: "dxButton",
options: {
icon: "refresh",
onClick: () => updateDemo(),
},
},
],
});
});
</script>
</body>
</html>