summaryrefslogtreecommitdiff
path: root/includes/js/dijit/tests/layout/test_LayoutCode.html
blob: 9cec35e363b8f7cc65b0374a40103534ae41f6ea (plain)
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
	"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>Programmatic Layout Demo</title>

	<style type="text/css">
		@import "../../../dojo/resources/dojo.css";
		@import "css/dijitTests.css";

		html, body{	
			width: 100%;	/* make the body expand to fill the visible window */
			height: 100%;
			overflow: hidden;	/* erase window level scrollbars */
			padding: 0 0 0 0;
			margin: 0 0 0 0;
		}
		.dijitSplitPane{
			margin: 5px;
		}
		#rightPane {
			margin: 0;
		}
		#creator, #current {
			border: 3px solid blue;
			padding: 10px;
			margin: 10px;
		}
		#wrapper {
			border: 3px solid green;
			padding: 10px;
			margin: 10px;
		}
	</style>

	<script type="text/javascript" src="../../../dojo/dojo.js"
		djConfig="isDebug: true, parseOnLoad: true"></script>
	<script type="text/javascript" src="../_testCommon.js"></script>

	<script type="text/javascript">
		dojo.require("dijit.layout.LayoutContainer");
		dojo.require("dijit.layout.AccordionContainer");
		dojo.require("dijit.layout.ContentPane");
		dojo.require("dijit.layout.SplitContainer");
		dojo.require("dijit.layout.TabContainer");

		// Used in doc0.html
	 	dojo.require("dijit.form.ComboBox");
	 	dojo.require("dijit.form.Button");

		dojo.require("dojo.parser");	// scan page for widgets and instantiate them

		// Simple layout container layout
		var simpleLayout = {
			widgetType: "LayoutContainer",
			params: { id: "rootWidget" },
			style: "border: 3px solid grey; width: 95%; height: 400px;",
			children: [
				{
					widgetType: "ContentPane",
					params: {id: "left", layoutAlign: "left"},
					style: "width: 100px; background: #ffeeff;",
					innerHTML: "this is the left"
				},
				{
					widgetType: "ContentPane",
					params: {id: "right", layoutAlign: "right"},
					style: "width: 100px; background: #ffeeff;",
					innerHTML: "this is the right"
				},
				{
					widgetType: "ContentPane",
					params: {id: "top", layoutAlign: "top"},
					style: "height: 100px; background: #eeeeee;",
					innerHTML: "this is the top"
				},
				{
					widgetType: "ContentPane",
					params: {id: "bottom", layoutAlign: "bottom"},
					style: "height: 100px; background: #eeeeee;",
					innerHTML: "this is the bottom"
				},
				{
					widgetType: "ContentPane",
					params: {id: "client", layoutAlign: "client"},
					style: "height: 100px; background: #ffffee;",
					innerHTML: "this is the client"
				}
			]
		};

		// split container layout
		var splitLayout = {
			widgetType: "SplitContainer",
			params: {id: "rootWidget", orientation: "horizontal"},
			style: "border: 3px solid grey; width: 95%; height: 400px;",
			children: [
				{
					widgetType: "ContentPane",
					params: {id: "left"},
					style: "background: #ffeeff;",
					innerHTML: "left pane of split container"
				},
				{
					widgetType: "SplitContainer",
					params: {
						id: "nested", orientation: "vertical"},
					children: [
						{
							widgetType: "ContentPane",
							params: {id: "top"},
							style: "background: #eeffee;",
							innerHTML: "center-top pane of nested split container"
						},
						{
							widgetType: "ContentPane",
							params: {id: "bottom"},
							style: "background: #eeffee;",
							innerHTML: "center-bottom pane of nested split container"
						}
					]
				},
				{
					widgetType: "ContentPane",
					params: {id: "right"},
					style: "background: #ffeeff;",
					innerHTML: "right pane of split container"
				}
			]
		};

		// tab container layout
		var tabLayout = {
			widgetType: "TabContainer",
			params: {id: "rootWidget"},
			style: "width: 95%; height: 400px;",
			children: [
				{
					widgetType: "ContentPane",
					params: {id: "content", title: "Content tab", href: "doc0.html", executeScripts: true},
					style: "background: #ffeeff;"
				},
				{
					widgetType: "SplitContainer",
					params: {id: "nestedSplit", title: "Split pane tab", orientation: "vertical"},
					children: [
						{
							widgetType: "ContentPane",
							params: {id: "top"},
							style: "background: #eeffee;",
							innerHTML: "top pane of nested split container"
						},
						{
							widgetType: "ContentPane",
							params: {id: "bottom"},
							style: "background: #eeffee;",
							innerHTML: "bottom pane of nested split container"
						}
					]
				},
				{
					widgetType: "TabContainer",
					params: {id: "nestedTab", title: "Nested tabs"},
					children: [
						{
							widgetType: "ContentPane",
							params: {id: "left", title: "Nested Tab #1"},
							style: "background: #eeffee;",
							innerHTML: "tab 1 of nested tabs"
						},
						{
							widgetType: "ContentPane",
							params: {
								id: "right", title: "Nested Tab #2"},
							style: "background: #eeffee;",
							innerHTML: "tab 2 of nested tabs"
						}
					]
				}
			]
		};

/*
		// tab container layout
		var tabNoLayout = {
			widgetType: "TabContainer",
			params: {id: "rootWidget", doLayout: false},
			children: [
				{
					widgetType: "ContentPane",
					params: {id: "doc0", title: "Doc 0", href: "doc0.html", executeScripts: true},
					style: "background: #ffeeff;"
				},
				{
					widgetType: "ContentPane",
					params: {id: "doc1", title: "Doc 1", href: "doc1.html", executeScripts: true},
					style: "background: #eeffee;"
				},
				{
					widgetType: "ContentPane",
					params: {id: "doc2", title: "Doc 2", href: "doc2.html", executeScripts: true},
					style: "background: #ffffee;"
				}
			]
		};
*/	

		// accordion container layout
		var accordionLayout = {
			widgetType: "AccordionContainer",
			params: {id: "rootWidget"},
			style: "border: 3px solid grey; width: 95%; height: 400px;",
			children: [
				{
					widgetType: "AccordionPane",
					params: {id: "one", title: "Pane #1"},
					style: "background: #ffeeff;",
					innerHTML: "first pane contents"
				},
				{
					widgetType: "AccordionPane",
					params: {id: "two", title: "Pane #2"},
					style: "background: #ffeeff;",
					innerHTML: "second pane contents"
				},
				{
					widgetType: "AccordionPane",
					params: {id: "three", title: "Pane #3"},
					style: "background: #ffeeff;",
					innerHTML: "third pane contents"
				}
			]
		};

		// Create a widget hierarchy from a JSON structure like
		// {widgetType: "LayoutContainer", params: { ... }, children: { ... } }
		function createWidgetHierarchy(widgetJson){
			// setup input node
			var node = document.createElement("div");
			document.body.appendChild(node);	// necessary for tab contianer ???
			if(widgetJson.style){
				node.style.cssText = widgetJson.style;
			}
			if(widgetJson.innerHTML){
				node.innerHTML=widgetJson.innerHTML;
			}

			// create the widget
			var widget = new dijit.layout[widgetJson.widgetType](widgetJson.params, node);

			// add its children (recursively)
			if(widgetJson.children){
				dojo.forEach(widgetJson.children,
					function(child){ widget.addChild(createWidgetHierarchy(child)); });
			}
			widget.startup(); //TODO: this is required now, right?

			return widget;
		}

		// create the widgets specified in layout and add them to widget "rootWidget"
		function create(layout){

			// erase old widget hierarchy (if it exists)
			var rootWidget = dijit.byId("rootWidget");
			if(rootWidget){
				rootWidget.destroyRecursive();
			}

			// create new widget
			rootWidget = createWidgetHierarchy(layout);

			// and display it
			var wrapper = dojo.byId("wrapper");
			wrapper.innerHTML="";	// just to erase the initial HTML message
			wrapper.appendChild(rootWidget.domNode);
	//		rootWidget.onResized();

			// make/update the menu of operations on each widget
			makeOperationTable();
		}

		// write out a menu of operations on each widget
		function makeOperationTable(){
			var html = "<table border=1>";
			dijit.registry.forEach(function(widget){
				html += "<tr><td>" + widget.id + "</td><td>";
				html += "<button onclick='removeFromParent(\"" + widget.id + "\");'> destroy </button> ";
				if(/Container/.test(widget.declaredClass)){
					html += "<button onclick='addChild(\"" + widget.id + "\");'> add a child </button> ";
				}
				html += "</td></tr>";
			});
			html += "</table>";
			dojo.byId("operations").innerHTML = html;
		}

		// remove a widget from it's parent and destroy it
		function removeFromParent(widget){
			widget = dijit.byId(widget);
			if(widget.parent){
				widget.parent.removeChild(widget);
			}
			widget.destroy();

			// reset the operation table so this widget is no longer shown
			makeOperationTable();
		}

		// add a child to given widget
		function addChild(widget){
			widget = dijit.byId(widget);

			// setup input node
			var node = document.createElement("div");
			node.style.cssText = "height: 70px; width: 150px; overflow: auto; background: #cccccc; border: dotted black 2px;";	// necessary if parent is LayoutContainer
			// create the widget
			var alignments = ["top","bottom","left","right"];
			var hrefs = ["doc0.html", "doc1.html", "doc2.html"];
			var child = new dijit.layout.ContentPane(
				{
					title: "Widget " + cnt,	// necessary if parent is tab
					layoutAlign: alignments[cnt%4],	// necessary if parent is LayoutContainer
					executeScripts: true,
					href: hrefs[cnt%3]
				},
				node);
			cnt++;

			if(/AccordionContainer/.test(widget.declaredClass)){
				var pane = new dijit.layout.AccordionPane({
					title: "AccordionWidget " + cnt
				});
				pane.setContent(child);
				child = pane;
			}
			// add it to the parent
			widget.addChild(child);

			// reset the operation table so the new widget is shown
			makeOperationTable();
		}
		var cnt=1;

		// show a widget
		function show(widget){
			widget = dijit.byId(widget);
			widget.show();
		}

		// hide a widget
		function hide(widget){
			widget = dijit.byId(widget);
			widget.hide();
		}
	</script>
</head>
<body>
	<h1>Test of layout code programmatic creation</h1>
	<table width="100%">
		<tr>
			<td id="creator" valign="top">
				<h4>Creator</h4>
				<p>Pressing a button will programatically add a hierarchy of widgets</p>
				<button onClick="create(simpleLayout);">Simple Layout</button>
				<button onClick="create(splitLayout);">Split Layout</button>
				<button onClick="create(tabLayout);">Tab Layout</button>
<!--				<button onClick="create(tabNoLayout);">Tab Non-Layout</button> -->
				<button onClick="create(accordionLayout);">Accordion Layout</button>
			</td>
			<td id="current">
				<h4>Current widgets</h4>
				This pane will let you try certain operations on each of the widgets.
				<div id="operations" style="height: 200px; overflow: auto;"></div>
			</td>
		</tr>
	</table>
	<hr>
	<div id="wrapper">
		When you press a button, this will be filled in with the generated widgets
	</div>
</body>
</html>