-
Notifications
You must be signed in to change notification settings - Fork 35
/
TestPage.js
327 lines (284 loc) · 10.2 KB
/
TestPage.js
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
eval(
Packages.Inject([
"Test",
"Class",
"Html.ResizeEvent",
"Html.Navigation",
"Html.Razor",
"Html.MVC",
"IO.Delay",
"IO.Resource",
"IO.Wildcard",
"GacUI.Types",
"GacUI.Elements.Interface",
"GacUI.Elements.Basic",
"GacUI.Elements.ColorizedText",
"GacUI.Elements.Document",
"GacUI.Layout.Basic",
"GacUI.Layout.Stack",
"GacUI.Layout.Table",
"GacUI.Layout.Misc"],
true)
);
/********************************************************************************
TabControl
********************************************************************************/
function BuildTabController(name) {
var Controller = Class("<TabController>::" + name, INavigationController, {
Id: Public(null),
Url: Public(null),
OnInstalled: Public.Override(function () {
var tabControl = window[this.Id];
for (var i = 0; i < tabControl.TabButtons.length; i++) {
var tabButton = tabControl.TabButtons[i];
if (tabButton.getAttribute("data-url") === this.Url) {
ShowTabPage(tabControl, tabButton.TabPage);
break;
}
}
}),
OnUninstalled: Public.Override(function () {
var tabControl = window[this.Id];
ShowTabPage(tabControl, null);
}),
});
return Controller;
}
var TabRootController = BuildTabController("Root");
function ShowTabPage(tabControl, tabPage) {
if (tabControl.CurrentTabPage !== null) {
tabControl.CurrentTabPage.classList.remove("Selected");
tabControl.CurrentTabPage.TabButton.classList.remove("Selected");
}
tabControl.CurrentTabPage = tabPage;
if (tabControl.CurrentTabPage !== null) {
tabControl.CurrentTabPage.classList.add("Selected");
tabControl.CurrentTabPage.TabButton.classList.add("Selected");
}
}
function CombineTabPage(tabControl, tabPage, tabButton) {
tabPage.TabControl = tabControl;
tabPage.TabButton = tabButton;
tabButton.TabPage = tabPage;
if (tabControl.TabControllerType) {
parentControllerType = undefined;
var current = tabButton;
while (current) {
if (current.TabControllerType && current !== tabControl) {
parentControllerType = current.TabControllerType;
break;
}
current = current.parentElement;
}
var url = tabButton.getAttribute("data-url");
RegisterNavigationPath(
url,
tabControl.TabControllerType,
{ Id: tabControl.id, Url: url },
parentControllerType
);
tabButton.addEventListener("click", function (event) {
var context = GetNavigationContextBefore(tabControl.TabControllerType);
context.push({ type: tabControl.TabControllerType, values: { Id: tabControl.id, Url: url } });
var path = BuildNavigationPath(context);
NavigateTo(path);
});
}
else {
tabButton.addEventListener("click", function (event) {
ShowTabPage(tabControl, event.currentTarget.TabPage);
});
}
}
function SetupTabControl(tabControl) {
function DirectChild(parent, className) {
var result = [];
var childNodes = parent.childNodes;
for (var i = 0; i < childNodes.length; i++) {
var childNode = childNodes[i];
if (childNode.className === className) {
result.push(childNode);
}
}
return result;
}
tabControl.CurrentTabPage = null;
if (tabControl.getAttribute("data-navigation") === "true") {
tabControl.TabControllerType = BuildTabController(tabControl.id);
}
else {
tabControl.TabControllerType = null;
}
tabControl.TabButtons = DirectChild(DirectChild(tabControl, "TabButtonContainer")[0], "TabButton");
tabControl.TabPages = DirectChild(DirectChild(tabControl, "TabPageContainer")[0], "TabPage");
for (var i = 0; i < tabControl.TabButtons.length; i++) {
CombineTabPage(tabControl, tabControl.TabPages[i], tabControl.TabButtons[i]);
}
if (!tabControl.TabControllerType) {
ShowTabPage(tabControl, tabControl.TabPages[0]);
}
}
/********************************************************************************
Draggable Handler
********************************************************************************/
function GetPx(px) {
return +px.substr(0, px.length - 2);
}
var bodyOnMouseMove = null;
var bodyOnMouseUp = null;
function TrackMouse(node) {
bodyOnMouseMove = node.data_onMouseMove;
bodyOnMouseUp = node.data_onMouseUp;
DetachMouseEvents(node, false);
}
function UnTrackMouse(node) {
AttachMouseEvents(node);
bodyOnMouseMove = null;
bodyOnMouseUp = null;
}
function AttachMouseEvents(node, onMouseDown, onMouseMove, onMouseUp) {
if (onMouseDown) node.data_onMouseDown = onMouseDown;
if (onMouseMove) node.data_onMouseMove = onMouseMove;
if (onMouseUp) node.data_onMouseUp = onMouseUp;
node.addEventListener("mousedown", node.data_onMouseDown, false);
node.addEventListener("mousemove", node.data_onMouseMove, false);
node.addEventListener("mouseup", node.data_onMouseUp, false);
}
function DetachMouseEvents(node, removeHandler) {
node.removeEventListener("mousedown", node.data_onMouseDown, false);
node.removeEventListener("mousemove", node.data_onMouseMove, false);
node.removeEventListener("mouseup", node.data_onMouseUp, false);
if (removeHandler) {
node.data_onMouseDown = undefined;
node.data_onMouseMove = undefined;
node.data_onMouseUp = undefined;
}
}
function InstallResizer(node, resizeCallback) {
var draggableHandle = document.createElement("div");
draggableHandle.setAttribute("class", "DraggableHandle");
draggableHandle.style.right = "1px";
draggableHandle.style.bottom = "1px";
draggableHandle.style.backgroundColor = "red";
node.appendChild(draggableHandle);
var dragging = false;
var x = 0.0;
var y = 0.0;
AttachMouseEvents(
draggableHandle,
function (event) {
if (draggableHandle.style.right !== "") {
draggableHandle.style.right = "";
draggableHandle.style.bottom = "";
draggableHandle.style.left = (node.offsetWidth - draggableHandle.offsetWidth - 3) + "px";
draggableHandle.style.top = (node.offsetHeight - draggableHandle.offsetHeight - 3) + "px";
}
dragging = true;
x = event.pageX;
y = event.pageY;
TrackMouse(draggableHandle);
},
function (event) {
if (dragging) {
var dx = event.pageX - x;
var dy = event.pageY - y;
var left = GetPx(draggableHandle.style.left);
var top = GetPx(draggableHandle.style.top);
var width = left + draggableHandle.offsetWidth + 1 + dx;
var height = top + draggableHandle.offsetHeight + 1 + dy;
if (width < 0 || height < 0) {
return;
}
node.style.minWidth = width + "px";
node.style.minHeight = height + "px";
draggableHandle.style.left = left + dx + "px";
draggableHandle.style.top = top + dy + "px";
resizeCallback(width, height);
x = event.pageX;
y = event.pageY;
}
},
function (event) {
dragging = false;
UnTrackMouse(draggableHandle);
}
);
}
function InstallMover(node) {
if (node.style.left === "" || node.style.top === "") {
return;
}
var draggableHandle = document.createElement("div");
draggableHandle.setAttribute("class", "DraggableHandle");
draggableHandle.style.left = "1px";
draggableHandle.style.top = "1px";
draggableHandle.style.backgroundColor = "blue";
node.appendChild(draggableHandle);
var dragging = false;
var x = 0.0;
var y = 0.0;
AttachMouseEvents(
draggableHandle,
function (event) {
dragging = true;
x = event.pageX;
y = event.pageY;
TrackMouse(draggableHandle);
},
function (event) {
if (dragging) {
var dx = event.pageX - x;
var dy = event.pageY - y;
node.style.left = GetPx(node.style.left) + dx + "px";
node.style.top = GetPx(node.style.top) + dy + "px";
x = event.pageX;
y = event.pageY;
}
},
function (event) {
dragging = false;
UnTrackMouse(draggableHandle);
}
);
}
function InstallDraggableHandlers(node, resizeCallback) {
InstallMover(node);
InstallResizer(node, resizeCallback);
}
window.addEventListener("mousemove", function (event) {
if (bodyOnMouseMove) {
bodyOnMouseMove(event);
}
}, false);
window.addEventListener("mouseup", function (event) {
if (bodyOnMouseUp) {
bodyOnMouseUp(event);
}
}, false);
/********************************************************************************
Layout Embedder
********************************************************************************/
function CreateLayoutEmbedder(layout, rows, columns) {
if (rows === undefined) rows = 1;
if (columns === undefined) columns = 1;
var div = document.createElement("div");
div.style.display = "block";
div.style.position = "relative";
div.style.border = "1px solid blue";
div.style.float = "left";
div.style.margin = "10px 10px 10px 10px";
var child = layout.BoundsHtmlElement;
if (child === undefined) {
child = layout;
}
child.style.position = "relative";
child.style.width = (columns * 100) + "px";
child.style.height = (rows * 100) + "px";
child.style.margin = "10px 10px 10px 10px";
div.appendChild(child);
InstallDraggableHandlers(div, function (width, height) {
child.style.width = (width - 20) + "px";
child.style.height = (height - 20) + "px";
});
return div;
}