0c1c747d9ce1241c34c516935071badf29ed2e9a.svn-base 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2. "http://www.w3.org/TR/html4/strict.dtd">
  3. <html>
  4. <head>
  5. <title>Layout Demo</title>
  6. <script type="text/javascript" src="../../../dojo/dojo.js"
  7. djConfig="isDebug: true, parseOnLoad: true"></script>
  8. <script type="text/javascript" src="../_testCommon.js"></script>
  9. <script type="text/javascript">
  10. dojo.require("dijit.layout.LayoutContainer");
  11. dojo.require("dijit.layout.AccordionContainer");
  12. dojo.require("dijit.layout.ContentPane");
  13. dojo.require("dijit.layout.SplitContainer");
  14. dojo.require("dijit.layout.TabContainer");
  15. // Used in doc0.html
  16. dojo.require("dijit.form.ComboBox");
  17. dojo.require("dijit.form.Button");
  18. dojo.require("dojo.parser"); // scan page for widgets and instantiate them
  19. // Simple layout container layout
  20. var simpleLayout = {
  21. widgetType: "LayoutContainer",
  22. params: { id: "rootWidget" },
  23. style: "border: 3px solid grey; width: 95%; height: 400px;",
  24. children: [
  25. {
  26. widgetType: "ContentPane",
  27. params: {id: "left", layoutAlign: "left"},
  28. style: "width: 100px; background: #ffeeff;",
  29. innerHTML: "this is the left"
  30. },
  31. {
  32. widgetType: "ContentPane",
  33. params: {id: "right", layoutAlign: "right"},
  34. style: "width: 100px; background: #ffeeff;",
  35. innerHTML: "this is the right"
  36. },
  37. {
  38. widgetType: "ContentPane",
  39. params: {id: "top", layoutAlign: "top"},
  40. style: "height: 100px; background: #eeeeee;",
  41. innerHTML: "this is the top"
  42. },
  43. {
  44. widgetType: "ContentPane",
  45. params: {id: "bottom", layoutAlign: "bottom"},
  46. style: "height: 100px; background: #eeeeee;",
  47. innerHTML: "this is the bottom"
  48. },
  49. {
  50. widgetType: "ContentPane",
  51. params: {id: "client", layoutAlign: "client"},
  52. style: "height: 100px; background: #ffffee;",
  53. innerHTML: "this is the client"
  54. }
  55. ]
  56. };
  57. // split container layout
  58. var splitLayout = {
  59. widgetType: "SplitContainer",
  60. params: {id: "rootWidget", orientation: "horizontal"},
  61. style: "border: 3px solid grey; width: 95%; height: 400px;",
  62. children: [
  63. {
  64. widgetType: "ContentPane",
  65. params: {id: "left"},
  66. style: "background: #ffeeff;",
  67. innerHTML: "left pane of split container"
  68. },
  69. {
  70. widgetType: "SplitContainer",
  71. params: {
  72. id: "nested", orientation: "vertical"},
  73. children: [
  74. {
  75. widgetType: "ContentPane",
  76. params: {id: "top"},
  77. style: "background: #eeffee;",
  78. innerHTML: "center-top pane of nested split container"
  79. },
  80. {
  81. widgetType: "ContentPane",
  82. params: {id: "bottom"},
  83. style: "background: #eeffee;",
  84. innerHTML: "center-bottom pane of nested split container"
  85. }
  86. ]
  87. },
  88. {
  89. widgetType: "ContentPane",
  90. params: {id: "right"},
  91. style: "background: #ffeeff;",
  92. innerHTML: "right pane of split container"
  93. }
  94. ]
  95. };
  96. // tab container layout
  97. var tabLayout = {
  98. widgetType: "TabContainer",
  99. params: {id: "rootWidget"},
  100. style: "width: 95%; height: 400px;",
  101. children: [
  102. {
  103. widgetType: "ContentPane",
  104. params: {id: "content", title: "Content tab", href: "doc0.html", executeScripts: true},
  105. style: "background: #ffeeff;"
  106. },
  107. {
  108. widgetType: "SplitContainer",
  109. params: {id: "nestedSplit", title: "Split pane tab", orientation: "vertical"},
  110. children: [
  111. {
  112. widgetType: "ContentPane",
  113. params: {id: "top"},
  114. style: "background: #eeffee;",
  115. innerHTML: "top pane of nested split container"
  116. },
  117. {
  118. widgetType: "ContentPane",
  119. params: {id: "bottom"},
  120. style: "background: #eeffee;",
  121. innerHTML: "bottom pane of nested split container"
  122. }
  123. ]
  124. },
  125. {
  126. widgetType: "TabContainer",
  127. params: {id: "nestedTab", title: "Nested tabs"},
  128. children: [
  129. {
  130. widgetType: "ContentPane",
  131. params: {id: "left", title: "Nested Tab #1"},
  132. style: "background: #eeffee;",
  133. innerHTML: "tab 1 of nested tabs"
  134. },
  135. {
  136. widgetType: "ContentPane",
  137. params: {
  138. id: "right", title: "Nested Tab #2"},
  139. style: "background: #eeffee;",
  140. innerHTML: "tab 2 of nested tabs"
  141. }
  142. ]
  143. }
  144. ]
  145. };
  146. /*
  147. // tab container layout
  148. var tabNoLayout = {
  149. widgetType: "TabContainer",
  150. params: {id: "rootWidget", doLayout: false},
  151. children: [
  152. {
  153. widgetType: "ContentPane",
  154. params: {id: "doc0", title: "Doc 0", href: "doc0.html", executeScripts: true},
  155. style: "background: #ffeeff;"
  156. },
  157. {
  158. widgetType: "ContentPane",
  159. params: {id: "doc1", title: "Doc 1", href: "doc1.html", executeScripts: true},
  160. style: "background: #eeffee;"
  161. },
  162. {
  163. widgetType: "ContentPane",
  164. params: {id: "doc2", title: "Doc 2", href: "doc2.html", executeScripts: true},
  165. style: "background: #ffffee;"
  166. }
  167. ]
  168. };
  169. */
  170. // accordion container layout
  171. var accordionLayout = {
  172. widgetType: "AccordionContainer",
  173. params: {id: "rootWidget"},
  174. style: "border: 3px solid grey; width: 95%; height: 400px;",
  175. children: [
  176. {
  177. widgetType: "AccordionPane",
  178. params: {id: "one", title: "Pane #1"},
  179. style: "background: #ffeeff;",
  180. innerHTML: "first pane contents"
  181. },
  182. {
  183. widgetType: "AccordionPane",
  184. params: {id: "two", title: "Pane #2"},
  185. style: "background: #ffeeff;",
  186. innerHTML: "second pane contents"
  187. },
  188. {
  189. widgetType: "AccordionPane",
  190. params: {id: "three", title: "Pane #3"},
  191. style: "background: #ffeeff;",
  192. innerHTML: "third pane contents"
  193. }
  194. ]
  195. };
  196. // Create a widget hierarchy from a JSON structure like
  197. // {widgetType: "LayoutContainer", params: { ... }, children: { ... } }
  198. function createWidgetHierarchy(widgetJson){
  199. // setup input node
  200. var node = document.createElement("div");
  201. document.body.appendChild(node); // necessary for tab contianer ???
  202. if(widgetJson.style){
  203. node.style.cssText = widgetJson.style;
  204. }
  205. if(widgetJson.innerHTML){
  206. node.innerHTML=widgetJson.innerHTML;
  207. }
  208. // create the widget
  209. var widget = new dijit.layout[widgetJson.widgetType](widgetJson.params, node);
  210. // add its children (recursively)
  211. if(widgetJson.children){
  212. dojo.forEach(widgetJson.children,
  213. function(child){ widget.addChild(createWidgetHierarchy(child)); });
  214. }
  215. widget.startup(); //TODO: this is required now, right?
  216. return widget;
  217. }
  218. // create the widgets specified in layout and add them to widget "rootWidget"
  219. function create(layout){
  220. // erase old widget hierarchy (if it exists)
  221. var rootWidget = dijit.byId("rootWidget");
  222. if(rootWidget){
  223. rootWidget.destroyRecursive();
  224. }
  225. // create new widget
  226. rootWidget = createWidgetHierarchy(layout);
  227. // and display it
  228. var wrapper = dojo.byId("wrapper");
  229. wrapper.innerHTML=""; // just to erase the initial HTML message
  230. wrapper.appendChild(rootWidget.domNode);
  231. // rootWidget.onResized();
  232. // make/update the menu of operations on each widget
  233. makeOperationTable();
  234. }
  235. // write out a menu of operations on each widget
  236. function makeOperationTable(){
  237. var html = "<table border=1>";
  238. dijit.registry.forEach(function(widget){
  239. html += "<tr><td>" + widget.id + "</td><td>";
  240. html += "<button onclick='removeFromParent(\"" + widget.id + "\");'> destroy </button> ";
  241. if(/Container/.test(widget.declaredClass)){
  242. html += "<button onclick='addChild(\"" + widget.id + "\");'> add a child </button> ";
  243. }
  244. html += "</td></tr>";
  245. });
  246. html += "</table>";
  247. dojo.byId("operations").innerHTML = html;
  248. }
  249. // remove a widget from it's parent and destroy it
  250. function removeFromParent(widget){
  251. widget = dijit.byId(widget);
  252. if(widget.parent){
  253. widget.parent.removeChild(widget);
  254. }
  255. widget.destroy();
  256. // reset the operation table so this widget is no longer shown
  257. makeOperationTable();
  258. }
  259. // add a child to given widget
  260. function addChild(widget){
  261. widget = dijit.byId(widget);
  262. // setup input node
  263. var node = document.createElement("div");
  264. node.style.cssText = "height: 70px; width: 150px; overflow: auto; background: #cccccc; border: dotted black 2px;"; // necessary if parent is LayoutContainer
  265. // create the widget
  266. var alignments = ["top","bottom","left","right"];
  267. var hrefs = ["doc0.html", "doc1.html", "doc2.html"];
  268. var child = new dijit.layout.ContentPane(
  269. {
  270. title: "Widget " + cnt, // necessary if parent is tab
  271. layoutAlign: alignments[cnt%4], // necessary if parent is LayoutContainer
  272. executeScripts: true,
  273. href: hrefs[cnt%3]
  274. },
  275. node);
  276. cnt++;
  277. if(/AccordionContainer/.test(widget.declaredClass)){
  278. var pane = new dijit.layout.AccordionPane({
  279. title: "AccordionWidget " + cnt
  280. });
  281. pane.setContent(child);
  282. child = pane;
  283. }
  284. // add it to the parent
  285. widget.addChild(child);
  286. // reset the operation table so the new widget is shown
  287. makeOperationTable();
  288. }
  289. var cnt=1;
  290. // show a widget
  291. function show(widget){
  292. widget = dijit.byId(widget);
  293. widget.show();
  294. }
  295. // hide a widget
  296. function hide(widget){
  297. widget = dijit.byId(widget);
  298. widget.hide();
  299. }
  300. </script>
  301. <style type="text/css">
  302. @import "../../../dojo/resources/dojo.css";
  303. @import "css/dijitTests.css";
  304. html, body{
  305. width: 100%; /* make the body expand to fill the visible window */
  306. height: 100%;
  307. overflow: hidden; /* erase window level scrollbars */
  308. padding: 0 0 0 0;
  309. margin: 0 0 0 0;
  310. }
  311. .dijitSplitPane{
  312. margin: 5px;
  313. }
  314. #rightPane {
  315. margin: 0;
  316. }
  317. #creator, #current {
  318. border: 3px solid blue;
  319. padding: 10px;
  320. margin: 10px;
  321. }
  322. #wrapper {
  323. border: 3px solid green;
  324. padding: 10px;
  325. margin: 10px;
  326. }
  327. </style>
  328. </head>
  329. <body>
  330. <h1>Test of layout code programmatic creation</h1>
  331. <table width="100%">
  332. <tr>
  333. <td id="creator" valign="top">
  334. <h4>Creator</h4>
  335. <p>Pressing a button will programatically add a hierarchy of widgets</p>
  336. <button onClick="create(simpleLayout);">Simple Layout</button>
  337. <button onClick="create(splitLayout);">Split Layout</button>
  338. <button onClick="create(tabLayout);">Tab Layout</button>
  339. <!-- <button onClick="create(tabNoLayout);">Tab Non-Layout</button> -->
  340. <button onClick="create(accordionLayout);">Accordion Layout</button>
  341. </td>
  342. <td id="current">
  343. <h4>Current widgets</h4>
  344. This pane will let you try certain operations on each of the widgets.
  345. <div id="operations" style="height: 200px; overflow: auto;"></div>
  346. </td>
  347. </tr>
  348. </table>
  349. <hr>
  350. <div id="wrapper">
  351. When you press a button, this will be filled in with the generated widgets
  352. </div>
  353. </body>
  354. </html>