| 1 | <!DOCTYPE html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 5 | <title>BorderContainer Experiments | The Dojo Toolkit</title> |
| 6 | |
| 7 | <script src="../boilerplate.js"></script> |
| 8 | |
| 9 | <style type="text/css"> |
| 10 | #pane1 { background-color:red; |
| 11 | } |
| 12 | #pane2{ |
| 13 | background-color:green; |
| 14 | } |
| 15 | #pane3 { |
| 16 | background-color:blue; |
| 17 | } |
| 18 | #pane0 { |
| 19 | background-color:#ededed; |
| 20 | } |
| 21 | .wrapper { padding:25px; } |
| 22 | .bc { margin:10px; border:2px solid #ededed; } |
| 23 | </style> |
| 24 | |
| 25 | <script type="text/javascript"> |
| 26 | require([ |
| 27 | "dojo/_base/array", |
| 28 | "dojo/_base/declare", |
| 29 | "dojo/dom", |
| 30 | "dojo/dom-construct", |
| 31 | "dojo/dom-style", |
| 32 | "dojo/parser", |
| 33 | "dojo/query", |
| 34 | "dijit/registry", |
| 35 | "dijit/layout/BorderContainer", |
| 36 | "dijit/form/Button", |
| 37 | "dijit/layout/ContentPane", |
| 38 | "dojo/domReady!" |
| 39 | ], function(array, declare, dom, domConstruct, domStyle, parser, query, |
| 40 | registry, BorderContainer, Button, ContentPane){ |
| 41 | |
| 42 | var open = false; |
| 43 | |
| 44 | |
| 45 | declare("my.BorderContainer", BorderContainer,{ |
| 46 | |
| 47 | opts: { |
| 48 | // single pane view |
| 49 | "a":{ |
| 50 | panes: [ |
| 51 | { id: "pane0", sizeable:false, region:"center", style: { width:"100%", height:"100%" } }, |
| 52 | { id: "pane1", hidden:true }, |
| 53 | { id: "pane2", hidden:true }, |
| 54 | { id: "pane3", hidden:true } |
| 55 | ] |
| 56 | }, |
| 57 | // top / bottom view |
| 58 | "ah":{ |
| 59 | panes: [ |
| 60 | { id: "pane0", sizeable:false, region:"center", style: { width:"100%", height:"50%" } }, |
| 61 | { id: "pane1", sizeable:true, region:"bottom", style: { width:"100%", height:"50%" } }, |
| 62 | { id: "pane2", hidden:true }, |
| 63 | { id: "pane3", hidden:true } |
| 64 | ] |
| 65 | }, |
| 66 | // left / right view |
| 67 | "av":{ |
| 68 | panes: [ |
| 69 | { id: "pane0", sizeable:true, region:"left", style: { width:"50%", height:"100%" } }, |
| 70 | { id: "pane1", sizeable:false, region:"center", style: { width:"50%", height:"100%" } }, |
| 71 | { id: "pane2", hidden:true }, |
| 72 | { id: "pane3", hidden:true } |
| 73 | ] |
| 74 | } |
| 75 | |
| 76 | }, |
| 77 | |
| 78 | _clearSplitters: function(){ |
| 79 | // cleanup all splitters on the page |
| 80 | query(".dijitSplitter",this.domNode).forEach(function(n){ |
| 81 | registry.byNode(n).destroy(); |
| 82 | }); |
| 83 | query(".dijitSplitterCover").forEach(domConstruct.destroy); |
| 84 | delete this._splitters; |
| 85 | this._splitters = {}; |
| 86 | }, |
| 87 | |
| 88 | setLayoutENUM: function(lay){ |
| 89 | // set the layout to a predefined setup |
| 90 | if(this._layoutSetting != lay){ |
| 91 | |
| 92 | this._layoutSetting = lay; |
| 93 | var struct = this.opts[lay] || false; |
| 94 | this._clearSplitters(); |
| 95 | |
| 96 | array.forEach(struct.panes,function(pane,i){ |
| 97 | // setup each pane |
| 98 | var d = registry.byId(pane.id); |
| 99 | d.region = pane.region || "center"; |
| 100 | d.splitter = pane.sizeable; |
| 101 | if(pane.minSize){ d.minSize = pane.minSize; } |
| 102 | if(pane.maxSize){ d.maxSize = pane.maxSize; } |
| 103 | if(pane.hidden){ |
| 104 | // reset this widget to our hidden holder node |
| 105 | this.extractChild(d,dom.byId("holder")); |
| 106 | d.splitter = null; |
| 107 | d.region = null; |
| 108 | d.maxSize = null; |
| 109 | d.minSize = null; |
| 110 | }else{ |
| 111 | if(pane.style){ |
| 112 | // object setter via style only in trunk: |
| 113 | domStyle.set(d.domNode, pane.style); |
| 114 | } |
| 115 | this.addChild(d,i); |
| 116 | } |
| 117 | },this); |
| 118 | } |
| 119 | this.layout(); |
| 120 | }, |
| 121 | |
| 122 | extractChild: function(/*dijit/_WidgetBase*/ child, /*DomNode*/ node){ |
| 123 | // a non-destructive cleanup for the bordercontainer. |
| 124 | // cleanup a widget, and append it's domNode to some |
| 125 | // other node in the dom |
| 126 | var region = child.region; |
| 127 | var splitter = this._splitters[region]; |
| 128 | if(splitter){ |
| 129 | registry.byNode(splitter).destroy(); |
| 130 | delete this._splitters[region]; |
| 131 | } |
| 132 | delete this["_"+region]; |
| 133 | node.appendChild(child.domNode); |
| 134 | if(this._started){ |
| 135 | this._layoutChildren(); |
| 136 | } |
| 137 | return child.domNode; |
| 138 | } |
| 139 | }); |
| 140 | |
| 141 | parser.parse(); |
| 142 | |
| 143 | // make buttons |
| 144 | array.forEach(["a","av","ah"],function(n){ |
| 145 | |
| 146 | var but = new Button({ |
| 147 | label: "Set "+n, |
| 148 | onClick: function(){ |
| 149 | console.log(n); |
| 150 | layout.setLayoutENUM(n); |
| 151 | } |
| 152 | }); |
| 153 | dom.byId("buttons").appendChild(but.domNode); |
| 154 | but.startup(); |
| 155 | }) |
| 156 | |
| 157 | }); |
| 158 | </script> |
| 159 | |
| 160 | </head> |
| 161 | <body class="claro" role="main"> |
| 162 | |
| 163 | <script type="dojo/require"> |
| 164 | fx: "dojo/_base/fx", |
| 165 | registry: "dijit/registry" |
| 166 | </script> |
| 167 | |
| 168 | <h1>This is a test</h1> |
| 169 | <p>This is only a test. An experiment in dynamically altering a BorderContainer's layout |
| 170 | (a seemingly unsupported feature just yet). It Demonstrates how to programatically alter/animate |
| 171 | the size of non-center regions though, and several simple layout configurations |
| 172 | </p> |
| 173 | |
| 174 | <div> |
| 175 | <h3>Layouts:</h3> |
| 176 | <div id="buttons"></div> |
| 177 | </div> |
| 178 | |
| 179 | <div id="container" data-dojo-id="layout" data-dojo-type="my.BorderContainer" data-dojo-props='style:"width:600px; height:300px; border:3px solid #333;"'> |
| 180 | <div id="pane0" data-dojo-type="dijit/layout/ContentPane" data-dojo-props='region:"center" '> |
| 181 | pane0 |
| 182 | </div> |
| 183 | </div> |
| 184 | |
| 185 | <div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props='"class":"bc", style:"height:200px"'> |
| 186 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='region:"center"'> |
| 187 | Sinlge pane - l1 |
| 188 | </div> |
| 189 | </div> |
| 190 | |
| 191 | <div class="wrapper"> |
| 192 | <h3>two panes, vertical split:</h3> |
| 193 | |
| 194 | |
| 195 | <div id="animBC" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props='"class":"bc", style:"height:200px"'> |
| 196 | <div id="sizing1" data-dojo-type="dijit/layout/ContentPane" data-dojo-props='style:"background-color:red", region:"left", splitter:true'> |
| 197 | Sinlge pane - left |
| 198 | </div> |
| 199 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='region:"center"'> |
| 200 | Sinlge pane - center |
| 201 | <button data-dojo-type="dijit/form/Button"> |
| 202 | Size Me |
| 203 | <script type="dojo/method" data-dojo-event="onClick"> |
| 204 | var n = registry.byId("sizing1").domNode; |
| 205 | fx.animateProperty({ |
| 206 | node:n, |
| 207 | duration:1000, |
| 208 | properties: { width: { end: (open ? "100" : "400"), units:"px" } }, |
| 209 | onEnd: function(){ |
| 210 | open = !open; |
| 211 | registry.byId("animBC").layout(); |
| 212 | } |
| 213 | }).play(1); |
| 214 | </script> |
| 215 | </button> |
| 216 | </div> |
| 217 | </div> |
| 218 | |
| 219 | <div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props='"class":"bc", style:"height:200px"'> |
| 220 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='region:"center", splitter:true'> |
| 221 | Single pane - center (splitter) (this is unsupported, and does not work) |
| 222 | </div> |
| 223 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='region:"right"'> |
| 224 | Single pane - right (no splitter) |
| 225 | </div> |
| 226 | </div> |
| 227 | |
| 228 | <div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props='"class":"bc", style:"height:200px"'> |
| 229 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='region:"center"'> |
| 230 | Single pane - center (no splitter) |
| 231 | </div> |
| 232 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='region:"right", splitter:true'> |
| 233 | Single pane - right (splitter) |
| 234 | </div> |
| 235 | </div> |
| 236 | </div> |
| 237 | |
| 238 | <div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props='"class":"bc", style:"width:200px; height:400px;"'> |
| 239 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='region:"top", splitter:true'> |
| 240 | Single pane - top (splitter) |
| 241 | |
| 242 | </div> |
| 243 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='region:"center"'> |
| 244 | Single pane - center |
| 245 | </div> |
| 246 | </div> |
| 247 | |
| 248 | <div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props='"class":"bc", style:"width:200px; height:400px;"'> |
| 249 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='region:"center"'> |
| 250 | Single pane - center |
| 251 | </div> |
| 252 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='region:"bottom", splitter:true'> |
| 253 | Single Pane Bottom (splitter) |
| 254 | </div> |
| 255 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='region:"top", splitter:true'> |
| 256 | Single Pane Top (splitter) |
| 257 | </div> |
| 258 | </div> |
| 259 | |
| 260 | <div id="holder" style="visibility:hidden"> |
| 261 | <div id="pane1" data-dojo-type="dijit/layout/ContentPane" >pane 1</div> |
| 262 | <div id="pane2" data-dojo-type="dijit/layout/ContentPane" >pane 2</div> |
| 263 | <div id="pane3" data-dojo-type="dijit/layout/ContentPane" >pane 3</div> |
| 264 | </div> |
| 265 | |
| 266 | </body> |
| 267 | </html> |