[483] | 1 | define([ |
---|
| 2 | "dojo/_base/kernel", |
---|
| 3 | "dojo/text!./resources/GridContainer.html", |
---|
| 4 | "dojo/_base/declare", // declare |
---|
| 5 | "dojo/query", |
---|
| 6 | "dojo/_base/sniff", |
---|
| 7 | "dojo/dom-class", |
---|
| 8 | "dojo/dom-style", |
---|
| 9 | "dojo/dom-geometry", |
---|
| 10 | "dojo/dom-construct", |
---|
| 11 | "dojo/dom-attr", // domAttr.get |
---|
| 12 | "dojo/_base/array", |
---|
| 13 | "dojo/_base/lang", |
---|
| 14 | "dojo/_base/event", |
---|
| 15 | "dojo/keys", // keys |
---|
| 16 | "dojo/topic", // topic.publish() |
---|
| 17 | "dijit/registry", |
---|
| 18 | "dijit/focus", |
---|
| 19 | "dijit/_base/focus", // dijit.getFocus() |
---|
| 20 | "dijit/_WidgetBase", |
---|
| 21 | "dijit/_TemplatedMixin", |
---|
| 22 | "dijit/layout/_LayoutWidget", |
---|
| 23 | "dojo/_base/NodeList", |
---|
| 24 | "dojox/mdnd/AreaManager", "dojox/mdnd/DropIndicator", |
---|
| 25 | "dojox/mdnd/dropMode/OverDropMode","dojox/mdnd/AutoScroll" |
---|
| 26 | ],function(dojo, template, declare, query, has, domClass, domStyle, geom, domConstruct, domAttr, array, lang, events, keys, topic, registry, focus, baseFocus, _WidgetBase, _TemplatedMixin, _LayoutWidget, NodeList){ |
---|
| 27 | |
---|
| 28 | var gcl = declare( |
---|
| 29 | "dojox.layout.GridContainerLite", |
---|
| 30 | [_LayoutWidget, _TemplatedMixin], |
---|
| 31 | { |
---|
| 32 | // summary: |
---|
| 33 | // The GridContainerLite is a container of child elements that are placed in a kind of grid. |
---|
| 34 | // |
---|
| 35 | // description: |
---|
| 36 | // GridContainerLite displays the child elements by column |
---|
| 37 | // (ie: the children widths are fixed by the column width of the grid but |
---|
| 38 | // the children heights are free). |
---|
| 39 | // Each child is movable by drag and drop inside the GridContainer. |
---|
| 40 | // The position of other children is automatically calculated when a child is moved. |
---|
| 41 | // |
---|
| 42 | // example: |
---|
| 43 | // | <div dojoType="dojox.layout.GridContainerLite" nbZones="3" isAutoOrganized="true"> |
---|
| 44 | // | <div dojoType="dijit.layout.ContentPane">Content Pane 1 : Drag Me !</div> |
---|
| 45 | // | <div dojoType="dijit.layout.ContentPane">Content Pane 2 : Drag Me !</div> |
---|
| 46 | // | <div dojoType="dijit.layout.ContentPane">Content Pane 3 : Drag Me !</div> |
---|
| 47 | // | </div> |
---|
| 48 | // |
---|
| 49 | // example: |
---|
| 50 | // | dojo.ready(function(){ |
---|
| 51 | // | var cpane1 = new dijit.layout.ContentPane({ |
---|
| 52 | // | title:"cpane1", content: "Content Pane 1 : Drag Me !" |
---|
| 53 | // | }), |
---|
| 54 | // | cpane2 = new dijit.layout.ContentPane({ |
---|
| 55 | // | title:"cpane2", |
---|
| 56 | // | content: "Content Pane 2 : Drag Me !" |
---|
| 57 | // | }), |
---|
| 58 | // | cpane3 = new dijit.layout.ContentPane({ |
---|
| 59 | // | title:"cpane3", |
---|
| 60 | // | content: "Content Pane 3 : Drag Me !" |
---|
| 61 | // | }); |
---|
| 62 | // | |
---|
| 63 | // | var widget = new dojox.layout.GridContainerLite({ |
---|
| 64 | // | nbZones: 3, |
---|
| 65 | // | isAutoOrganized: true |
---|
| 66 | // | }, dojo.byId("idNode")); |
---|
| 67 | // | widget.addChild(cpane1, 0, 0); |
---|
| 68 | // | widget.addChild(cpane2, 1, 0); |
---|
| 69 | // | widget.addChild(cpane3, 2, 1); |
---|
| 70 | // | widget.startup(); |
---|
| 71 | // | }); |
---|
| 72 | |
---|
| 73 | // autoRefresh: Boolean |
---|
| 74 | // Enable the refresh of registered areas on drag start. |
---|
| 75 | autoRefresh: true, |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | // templateString: String |
---|
| 79 | // template of gridContainer. |
---|
| 80 | templateString: template, |
---|
| 81 | |
---|
| 82 | // dragHandleClass: Array |
---|
| 83 | // CSS class enabling a drag handle on a child. |
---|
| 84 | dragHandleClass: "dojoxDragHandle", |
---|
| 85 | |
---|
| 86 | // nbZones: Integer |
---|
| 87 | // The number of dropped zones, by default 1. |
---|
| 88 | nbZones: 1, |
---|
| 89 | |
---|
| 90 | // doLayout: Boolean |
---|
| 91 | // If true, change the size of my currently displayed child to match my size. |
---|
| 92 | doLayout: true, |
---|
| 93 | |
---|
| 94 | // isAutoOrganized: Boolean |
---|
| 95 | // If true, widgets are organized automatically, |
---|
| 96 | // else the attribute colum of child will define the right column. |
---|
| 97 | isAutoOrganized: true, |
---|
| 98 | |
---|
| 99 | // acceptTypes: Array |
---|
| 100 | // The GridContainer will only accept the children that fit to the types. |
---|
| 101 | acceptTypes: [], |
---|
| 102 | |
---|
| 103 | // colWidths: String |
---|
| 104 | // A comma separated list of column widths. If the column widths do not add up |
---|
| 105 | // to 100, the remaining columns split the rest of the width evenly |
---|
| 106 | // between them. |
---|
| 107 | colWidths: "", |
---|
| 108 | |
---|
| 109 | constructor: function(/*Object*/props, /*DOMNode*/node){ |
---|
| 110 | this.acceptTypes = (props || {}).acceptTypes || ["text"]; |
---|
| 111 | this._disabled = true; |
---|
| 112 | }, |
---|
| 113 | |
---|
| 114 | postCreate: function(){ |
---|
| 115 | //console.log("dojox.layout.GridContainerLite ::: postCreate"); |
---|
| 116 | this.inherited(arguments); |
---|
| 117 | this._grid = []; |
---|
| 118 | |
---|
| 119 | this._createCells(); |
---|
| 120 | |
---|
| 121 | // need to resize dragged child when it's dropped. |
---|
| 122 | this.subscribe("/dojox/mdnd/drop", "resizeChildAfterDrop"); |
---|
| 123 | this.subscribe("/dojox/mdnd/drag/start", "resizeChildAfterDragStart"); |
---|
| 124 | |
---|
| 125 | this._dragManager = dojox.mdnd.areaManager(); |
---|
| 126 | // console.info("autorefresh ::: ", this.autoRefresh); |
---|
| 127 | this._dragManager.autoRefresh = this.autoRefresh; |
---|
| 128 | |
---|
| 129 | // Add specific dragHandleClass to the manager. |
---|
| 130 | this._dragManager.dragHandleClass = this.dragHandleClass; |
---|
| 131 | |
---|
| 132 | if(this.doLayout){ |
---|
| 133 | this._border = { |
---|
| 134 | h: has("ie") ? geom.getBorderExtents(this.gridContainerTable).h : 0, |
---|
| 135 | w: (has("ie") == 6) ? 1 : 0 |
---|
| 136 | }; |
---|
| 137 | }else{ |
---|
| 138 | domStyle.set(this.domNode, "overflowY", "hidden"); |
---|
| 139 | domStyle.set(this.gridContainerTable, "height", "auto"); |
---|
| 140 | } |
---|
| 141 | }, |
---|
| 142 | |
---|
| 143 | startup: function(){ |
---|
| 144 | //console.log("dojox.layout.GridContainerLite ::: startup"); |
---|
| 145 | if(this._started){ return; } |
---|
| 146 | |
---|
| 147 | if(this.isAutoOrganized){ |
---|
| 148 | this._organizeChildren(); |
---|
| 149 | } |
---|
| 150 | else{ |
---|
| 151 | this._organizeChildrenManually(); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | // Need to call getChildren because getChildren return null |
---|
| 155 | // The children are not direct children because of _organizeChildren method |
---|
| 156 | array.forEach(this.getChildren(), function(child){ |
---|
| 157 | child.startup(); |
---|
| 158 | }); |
---|
| 159 | |
---|
| 160 | // Need to enable the Drag And Drop only if the GridContainer is visible. |
---|
| 161 | if(this._isShown()){ |
---|
| 162 | this.enableDnd(); |
---|
| 163 | } |
---|
| 164 | this.inherited(arguments); |
---|
| 165 | }, |
---|
| 166 | |
---|
| 167 | resizeChildAfterDrop: function(/*Node*/node, /*Object*/targetArea, /*Integer*/indexChild){ |
---|
| 168 | // summary: |
---|
| 169 | // Resize the GridContainerLite inner table and the dropped widget. |
---|
| 170 | // description: |
---|
| 171 | // These components are resized only if the targetArea.node is a |
---|
| 172 | // child of this instance of gridContainerLite. |
---|
| 173 | // To be resized, the dropped node must have also a method resize. |
---|
| 174 | // node: |
---|
| 175 | // domNode of dropped widget. |
---|
| 176 | // targetArea: |
---|
| 177 | // AreaManager Object containing information of targetArea |
---|
| 178 | // indexChild: |
---|
| 179 | // Index where the dropped widget has been placed |
---|
| 180 | // returns: |
---|
| 181 | // True if resized. |
---|
| 182 | |
---|
| 183 | //console.log("dojox.layout.GridContainerLite ::: resizeChildAfterDrop"); |
---|
| 184 | if(this._disabled){ |
---|
| 185 | return false; |
---|
| 186 | } |
---|
| 187 | if(registry.getEnclosingWidget(targetArea.node) == this){ |
---|
| 188 | var widget = registry.byNode(node); |
---|
| 189 | if(widget.resize && lang.isFunction(widget.resize)){ |
---|
| 190 | widget.resize(); |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | // Update the column of the widget |
---|
| 194 | widget.set("column", node.parentNode.cellIndex); |
---|
| 195 | |
---|
| 196 | if(this.doLayout){ |
---|
| 197 | var domNodeHeight = this._contentBox.h, |
---|
| 198 | divHeight = geom.getContentBox(this.gridContainerDiv).h; |
---|
| 199 | if(divHeight >= domNodeHeight){ |
---|
| 200 | domStyle.set(this.gridContainerTable, "height", |
---|
| 201 | (domNodeHeight - this._border.h) + "px"); |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | return true; |
---|
| 205 | } |
---|
| 206 | return false; |
---|
| 207 | }, |
---|
| 208 | |
---|
| 209 | resizeChildAfterDragStart: function(/*Node*/node, /*Object*/sourceArea, /*Integer*/indexChild){ |
---|
| 210 | // summary: |
---|
| 211 | // Resize the GridContainerLite inner table only if the drag source |
---|
| 212 | // is a child of this gridContainer. |
---|
| 213 | // node: |
---|
| 214 | // domNode of dragged widget. |
---|
| 215 | // sourceArea: |
---|
| 216 | // AreaManager Object containing information of sourceArea |
---|
| 217 | // indexChild: |
---|
| 218 | // Index where the dragged widget has been placed |
---|
| 219 | |
---|
| 220 | //console.log("dojox.layout.GridContainerLite ::: resizeChildAfterDragStart"); |
---|
| 221 | if(this._disabled){ |
---|
| 222 | return false; |
---|
| 223 | } |
---|
| 224 | if(registry.getEnclosingWidget(sourceArea.node) == this){ |
---|
| 225 | this._draggedNode = node; |
---|
| 226 | if(this.doLayout){ |
---|
| 227 | geom.setMarginBox(this.gridContainerTable, { |
---|
| 228 | h: geom.getContentBox(this.gridContainerDiv).h - this._border.h |
---|
| 229 | }); |
---|
| 230 | } |
---|
| 231 | return true; |
---|
| 232 | } |
---|
| 233 | return false; |
---|
| 234 | }, |
---|
| 235 | |
---|
| 236 | getChildren: function(){ |
---|
| 237 | // summary: |
---|
| 238 | // A specific method which returns children after they were placed in zones. |
---|
| 239 | // returns: |
---|
| 240 | // A NodeList containing all children (widgets). |
---|
| 241 | // tags: |
---|
| 242 | // protected |
---|
| 243 | |
---|
| 244 | var children = new NodeList(); |
---|
| 245 | array.forEach(this._grid, function(dropZone){ |
---|
| 246 | query("> [widgetId]", dropZone.node).map(registry.byNode).forEach(function(item){ |
---|
| 247 | children.push(item); |
---|
| 248 | }); |
---|
| 249 | }); |
---|
| 250 | return children; // Array |
---|
| 251 | }, |
---|
| 252 | |
---|
| 253 | _isShown: function(){ |
---|
| 254 | // summary: |
---|
| 255 | // Check if the domNode is visible or not. |
---|
| 256 | // returns: |
---|
| 257 | // true if the content is currently shown |
---|
| 258 | // tags: |
---|
| 259 | // protected |
---|
| 260 | |
---|
| 261 | //console.log("dojox.layout.GridContainerLite ::: _isShown"); |
---|
| 262 | if("open" in this){ // for TitlePane, etc. |
---|
| 263 | return this.open; // Boolean |
---|
| 264 | } |
---|
| 265 | else{ |
---|
| 266 | var node = this.domNode; |
---|
| 267 | return (node.style.display != 'none') && (node.style.visibility != 'hidden') && !domClass.contains(node, "dijitHidden"); // Boolean |
---|
| 268 | } |
---|
| 269 | }, |
---|
| 270 | |
---|
| 271 | layout: function(){ |
---|
| 272 | // summary: |
---|
| 273 | // Resize of each child |
---|
| 274 | |
---|
| 275 | //console.log("dojox.layout.GridContainerLite ::: layout"); |
---|
| 276 | if(this.doLayout){ |
---|
| 277 | var contentBox = this._contentBox; |
---|
| 278 | geom.setMarginBox(this.gridContainerTable, { |
---|
| 279 | h: contentBox.h - this._border.h |
---|
| 280 | }); |
---|
| 281 | geom.setContentSize(this.domNode, { |
---|
| 282 | w: contentBox.w - this._border.w |
---|
| 283 | }); |
---|
| 284 | } |
---|
| 285 | array.forEach(this.getChildren(), function(widget){ |
---|
| 286 | if(widget.resize && lang.isFunction(widget.resize)){ |
---|
| 287 | widget.resize(); |
---|
| 288 | } |
---|
| 289 | }); |
---|
| 290 | }, |
---|
| 291 | |
---|
| 292 | onShow: function(){ |
---|
| 293 | // summary: |
---|
| 294 | // Enabled the Drag And Drop if it's necessary. |
---|
| 295 | |
---|
| 296 | //console.log("dojox.layout.GridContainerLite ::: onShow"); |
---|
| 297 | if(this._disabled){ |
---|
| 298 | this.enableDnd(); |
---|
| 299 | } |
---|
| 300 | }, |
---|
| 301 | |
---|
| 302 | onHide: function(){ |
---|
| 303 | // summary: |
---|
| 304 | // Disabled the Drag And Drop if it's necessary. |
---|
| 305 | |
---|
| 306 | //console.log("dojox.layout.GridContainerLite ::: onHide"); |
---|
| 307 | if(!this._disabled){ |
---|
| 308 | this.disableDnd(); |
---|
| 309 | } |
---|
| 310 | }, |
---|
| 311 | |
---|
| 312 | _createCells: function(){ |
---|
| 313 | // summary: |
---|
| 314 | // Create the columns of the GridContainer. |
---|
| 315 | // tags: |
---|
| 316 | // protected |
---|
| 317 | |
---|
| 318 | //console.log("dojox.layout.GridContainerLite ::: _createCells"); |
---|
| 319 | if(this.nbZones === 0){ this.nbZones = 1; } |
---|
| 320 | var accept = this.acceptTypes.join(","), |
---|
| 321 | i = 0; |
---|
| 322 | |
---|
| 323 | var widths = this._computeColWidth(); |
---|
| 324 | |
---|
| 325 | while(i < this.nbZones){ |
---|
| 326 | // Add the parameter accept in each zone used by AreaManager |
---|
| 327 | // (see method dojox.mdnd.AreaManager:registerByNode) |
---|
| 328 | this._grid.push({ |
---|
| 329 | node: domConstruct.create("td", { |
---|
| 330 | 'class': "gridContainerZone", |
---|
| 331 | accept: accept, |
---|
| 332 | id: this.id + "_dz" + i, |
---|
| 333 | style: { |
---|
| 334 | 'width': widths[i] + "%" |
---|
| 335 | } |
---|
| 336 | }, this.gridNode) |
---|
| 337 | }); |
---|
| 338 | i++; |
---|
| 339 | } |
---|
| 340 | }, |
---|
| 341 | |
---|
| 342 | _getZonesAttr: function(){ |
---|
| 343 | // summary: |
---|
| 344 | // return array of zone (domNode) |
---|
| 345 | return query(".gridContainerZone", this.containerNode); |
---|
| 346 | }, |
---|
| 347 | |
---|
| 348 | enableDnd: function(){ |
---|
| 349 | // summary: |
---|
| 350 | // Enable the Drag And Drop for children of GridContainer. |
---|
| 351 | |
---|
| 352 | //console.log("dojox.layout.GridContainerLite ::: enableDnd"); |
---|
| 353 | var m = this._dragManager; |
---|
| 354 | array.forEach(this._grid, function(dropZone){ |
---|
| 355 | m.registerByNode(dropZone.node); |
---|
| 356 | }); |
---|
| 357 | m._dropMode.updateAreas(m._areaList); |
---|
| 358 | this._disabled = false; |
---|
| 359 | }, |
---|
| 360 | |
---|
| 361 | disableDnd: function(){ |
---|
| 362 | // summary: |
---|
| 363 | // Disable the Drag And Drop for children of GridContainer. |
---|
| 364 | |
---|
| 365 | //console.log("dojox.layout.GridContainerLite ::: disableDnd"); |
---|
| 366 | var m = this._dragManager; |
---|
| 367 | array.forEach(this._grid, function(dropZone){ |
---|
| 368 | m.unregister(dropZone.node); |
---|
| 369 | }); |
---|
| 370 | m._dropMode.updateAreas(m._areaList); |
---|
| 371 | this._disabled = true; |
---|
| 372 | }, |
---|
| 373 | |
---|
| 374 | _organizeChildren: function(){ |
---|
| 375 | // summary: |
---|
| 376 | // List all zones and insert child into columns. |
---|
| 377 | |
---|
| 378 | //console.log("dojox.layout.GridContainerLite ::: _organizeChildren"); |
---|
| 379 | var children = dojox.layout.GridContainerLite.superclass.getChildren.call(this); |
---|
| 380 | var numZones = this.nbZones, |
---|
| 381 | numPerZone = Math.floor(children.length / numZones), |
---|
| 382 | mod = children.length % numZones, |
---|
| 383 | i = 0; |
---|
| 384 | // console.log('numPerZone', numPerZone, ':: mod', mod); |
---|
| 385 | for(var z = 0; z < numZones; z++){ |
---|
| 386 | for(var r = 0; r < numPerZone; r++){ |
---|
| 387 | this._insertChild(children[i], z); |
---|
| 388 | i++; |
---|
| 389 | } |
---|
| 390 | if(mod > 0){ |
---|
| 391 | try{ |
---|
| 392 | this._insertChild(children[i], z); |
---|
| 393 | i++; |
---|
| 394 | } |
---|
| 395 | catch(e){ |
---|
| 396 | console.error("Unable to insert child in GridContainer", e); |
---|
| 397 | } |
---|
| 398 | mod--; |
---|
| 399 | } |
---|
| 400 | else if(numPerZone === 0){ |
---|
| 401 | break; // Optimization |
---|
| 402 | } |
---|
| 403 | } |
---|
| 404 | }, |
---|
| 405 | |
---|
| 406 | _organizeChildrenManually: function (){ |
---|
| 407 | // summary: |
---|
| 408 | // Organize children by column property of widget. |
---|
| 409 | |
---|
| 410 | //console.log("dojox.layout.GridContainerLite ::: _organizeChildrenManually"); |
---|
| 411 | var children = dojox.layout.GridContainerLite.superclass.getChildren.call(this), |
---|
| 412 | length = children.length, |
---|
| 413 | child; |
---|
| 414 | for(var i = 0; i < length; i++){ |
---|
| 415 | child = children[i]; |
---|
| 416 | try{ |
---|
| 417 | this._insertChild(child, child.column - 1); |
---|
| 418 | } |
---|
| 419 | catch(e){ |
---|
| 420 | console.error("Unable to insert child in GridContainer", e); |
---|
| 421 | } |
---|
| 422 | } |
---|
| 423 | }, |
---|
| 424 | |
---|
| 425 | _insertChild: function(/*Widget*/child, /*Integer*/column, /*Integer?*/p){ |
---|
| 426 | // summary: |
---|
| 427 | // Insert a child in a specific column of the GridContainer widget. |
---|
| 428 | // column: |
---|
| 429 | // Column number |
---|
| 430 | // p: |
---|
| 431 | // Place in the zone (0 - first) |
---|
| 432 | // returns: |
---|
| 433 | // The widget inserted |
---|
| 434 | |
---|
| 435 | //console.log("dojox.layout.GridContainerLite ::: _insertChild", child, column, p); |
---|
| 436 | var zone = this._grid[column].node, |
---|
| 437 | length = zone.childNodes.length; |
---|
| 438 | if(typeof p === "undefined" || p > length){ |
---|
| 439 | p = length; |
---|
| 440 | } |
---|
| 441 | if(this._disabled){ |
---|
| 442 | domConstruct.place(child.domNode, zone, p); |
---|
| 443 | domAttr.set(child.domNode, "tabIndex", "0"); |
---|
| 444 | } |
---|
| 445 | else{ |
---|
| 446 | if(!child.dragRestriction){ |
---|
| 447 | this._dragManager.addDragItem(zone, child.domNode, p, true); |
---|
| 448 | } |
---|
| 449 | else{ |
---|
| 450 | domConstruct.place(child.domNode, zone, p); |
---|
| 451 | domAttr.set(child.domNode, "tabIndex", "0"); |
---|
| 452 | } |
---|
| 453 | } |
---|
| 454 | child.set("column", column); |
---|
| 455 | return child; // Widget |
---|
| 456 | }, |
---|
| 457 | |
---|
| 458 | removeChild: function(/*Widget*/ widget){ |
---|
| 459 | //console.log("dojox.layout.GridContainerLite ::: removeChild"); |
---|
| 460 | if(this._disabled){ |
---|
| 461 | this.inherited(arguments); |
---|
| 462 | } |
---|
| 463 | else{ |
---|
| 464 | this._dragManager.removeDragItem(widget.domNode.parentNode, widget.domNode); |
---|
| 465 | } |
---|
| 466 | }, |
---|
| 467 | |
---|
| 468 | addService: function(/*Object*/child, /*Integer?*/column, /*Integer?*/p){ |
---|
| 469 | //console.log("dojox.layout.GridContainerLite ::: addService"); |
---|
| 470 | kernel.deprecated("addService is deprecated.", "Please use instead.", "Future"); |
---|
| 471 | this.addChild(child, column, p); |
---|
| 472 | }, |
---|
| 473 | |
---|
| 474 | addChild: function(/*Object*/child, /*Integer?*/column, /*Integer?*/p){ |
---|
| 475 | // summary: |
---|
| 476 | // Add a child in a specific column of the GridContainer widget. |
---|
| 477 | // child: |
---|
| 478 | // widget to insert |
---|
| 479 | // column: |
---|
| 480 | // column number |
---|
| 481 | // p: |
---|
| 482 | // place in the zone (first = 0) |
---|
| 483 | // returns: |
---|
| 484 | // The widget inserted |
---|
| 485 | |
---|
| 486 | //console.log("dojox.layout.GridContainerLite ::: addChild"); |
---|
| 487 | child.domNode.id = child.id; |
---|
| 488 | dojox.layout.GridContainerLite.superclass.addChild.call(this, child, 0); |
---|
| 489 | if(column < 0 || column === undefined){ column = 0; } |
---|
| 490 | if(p <= 0){ p = 0; } |
---|
| 491 | try{ |
---|
| 492 | return this._insertChild(child, column, p); |
---|
| 493 | } |
---|
| 494 | catch(e){ |
---|
| 495 | console.error("Unable to insert child in GridContainer", e); |
---|
| 496 | } |
---|
| 497 | return null; // Widget |
---|
| 498 | }, |
---|
| 499 | |
---|
| 500 | _setColWidthsAttr: function(value){ |
---|
| 501 | this.colWidths = lang.isString(value) ? value.split(",") : (lang.isArray(value) ? value : [value]); |
---|
| 502 | |
---|
| 503 | if(this._started){ |
---|
| 504 | this._updateColumnsWidth(); |
---|
| 505 | } |
---|
| 506 | }, |
---|
| 507 | |
---|
| 508 | _updateColumnsWidth: function(/*Object*/ manager){ |
---|
| 509 | // summary: |
---|
| 510 | // Update the columns width. |
---|
| 511 | // manager: |
---|
| 512 | // dojox.mdnd.AreaManager singleton |
---|
| 513 | // tags: |
---|
| 514 | // private |
---|
| 515 | |
---|
| 516 | //console.log("dojox.layout.GridContainer ::: _updateColumnsWidth"); |
---|
| 517 | var length = this._grid.length; |
---|
| 518 | |
---|
| 519 | var widths = this._computeColWidth(); |
---|
| 520 | |
---|
| 521 | // Set the widths of each node |
---|
| 522 | for (var i = 0; i < length; i++){ |
---|
| 523 | this._grid[i].node.style.width = widths[i] + "%"; |
---|
| 524 | } |
---|
| 525 | }, |
---|
| 526 | |
---|
| 527 | _computeColWidth: function(){ |
---|
| 528 | var origWidths = this.colWidths || []; |
---|
| 529 | var widths = []; |
---|
| 530 | var colWidth; |
---|
| 531 | var widthSum = 0; |
---|
| 532 | var i; |
---|
| 533 | |
---|
| 534 | // Calculate the widths of each column. |
---|
| 535 | for(i = 0; i < this.nbZones; i++){ |
---|
| 536 | if(widths.length < origWidths.length){ |
---|
| 537 | widthSum += origWidths[i] * 1; |
---|
| 538 | widths.push(origWidths[i]); |
---|
| 539 | }else{ |
---|
| 540 | if(!colWidth){ |
---|
| 541 | colWidth = (100 - widthSum)/(this.nbZones - i); |
---|
| 542 | |
---|
| 543 | // If the numbers don't work out, make the remaining columns |
---|
| 544 | // an even width and let the code below average |
---|
| 545 | // out the differences. |
---|
| 546 | if(colWidth < 0){ |
---|
| 547 | colWidth = 100 / this.nbZones; |
---|
| 548 | } |
---|
| 549 | } |
---|
| 550 | widths.push(colWidth); |
---|
| 551 | widthSum += colWidth * 1; |
---|
| 552 | } |
---|
| 553 | } |
---|
| 554 | |
---|
| 555 | // If the numbers are wrong, divide them all so they add up to 100 |
---|
| 556 | if(widthSum > 100){ |
---|
| 557 | var divisor = 100 / widthSum; |
---|
| 558 | for(i = 0; i < widths.length; i++){ |
---|
| 559 | widths[i] *= divisor; |
---|
| 560 | } |
---|
| 561 | } |
---|
| 562 | return widths; |
---|
| 563 | }, |
---|
| 564 | |
---|
| 565 | _selectFocus: function(/*Event*/event){ |
---|
| 566 | // summary: |
---|
| 567 | // Enable keyboard accessibility into the GridContainer. |
---|
| 568 | // description: |
---|
| 569 | // Possibility to move focus into the GridContainer (TAB, LEFT ARROW, RIGHT ARROW, UP ARROW, DOWN ARROW). |
---|
| 570 | // Possibility to move GridContainer's children (Drag and Drop) with keyboard. (SHIFT + ARROW). |
---|
| 571 | // If the type of widget is not draggable, a popup is displayed. |
---|
| 572 | |
---|
| 573 | //console.log("dojox.layout.GridContainerLite ::: _selectFocus"); |
---|
| 574 | if(this._disabled){ return; } |
---|
| 575 | var key = event.keyCode, |
---|
| 576 | k = keys, |
---|
| 577 | zone = null, |
---|
| 578 | cFocus = baseFocus.getFocus(), |
---|
| 579 | focusNode = cFocus.node, |
---|
| 580 | m = this._dragManager, |
---|
| 581 | found, |
---|
| 582 | i, |
---|
| 583 | j, |
---|
| 584 | r, |
---|
| 585 | children, |
---|
| 586 | area, |
---|
| 587 | widget; |
---|
| 588 | if(focusNode == this.containerNode){ |
---|
| 589 | area = this.gridNode.childNodes; |
---|
| 590 | switch(key){ |
---|
| 591 | case k.DOWN_ARROW: |
---|
| 592 | case k.RIGHT_ARROW: |
---|
| 593 | found = false; |
---|
| 594 | for(i = 0; i < area.length; i++){ |
---|
| 595 | children = area[i].childNodes; |
---|
| 596 | for(j = 0; j < children.length; j++){ |
---|
| 597 | zone = children[j]; |
---|
| 598 | if(zone !== null && zone.style.display != "none"){ |
---|
| 599 | focus.focus(zone); |
---|
| 600 | events.stop(event); |
---|
| 601 | found = true; |
---|
| 602 | break; |
---|
| 603 | } |
---|
| 604 | } |
---|
| 605 | if(found){ break }; |
---|
| 606 | } |
---|
| 607 | break; |
---|
| 608 | case k.UP_ARROW: |
---|
| 609 | case k.LEFT_ARROW: |
---|
| 610 | area = this.gridNode.childNodes; |
---|
| 611 | found = false; |
---|
| 612 | for(i = area.length-1; i >= 0 ; i--){ |
---|
| 613 | children = area[i].childNodes; |
---|
| 614 | for(j = children.length; j >= 0; j--){ |
---|
| 615 | zone = children[j]; |
---|
| 616 | if(zone !== null && zone.style.display != "none"){ |
---|
| 617 | focus.focus(zone); |
---|
| 618 | events.stop(event); |
---|
| 619 | found = true; |
---|
| 620 | break; |
---|
| 621 | } |
---|
| 622 | } |
---|
| 623 | if(found){ break }; |
---|
| 624 | } |
---|
| 625 | break; |
---|
| 626 | } |
---|
| 627 | }else{ |
---|
| 628 | if(focusNode.parentNode.parentNode == this.gridNode){ |
---|
| 629 | var child = (key == k.UP_ARROW || key == k.LEFT_ARROW) ? "lastChild" : "firstChild"; |
---|
| 630 | var pos = (key == k.UP_ARROW || key == k.LEFT_ARROW) ? "previousSibling" : "nextSibling"; |
---|
| 631 | switch(key){ |
---|
| 632 | case k.UP_ARROW: |
---|
| 633 | case k.DOWN_ARROW: |
---|
| 634 | events.stop(event); |
---|
| 635 | found = false; |
---|
| 636 | var focusTemp = focusNode; |
---|
| 637 | while(!found){ |
---|
| 638 | children = focusTemp.parentNode.childNodes; |
---|
| 639 | var num = 0; |
---|
| 640 | for(i = 0; i < children.length; i++){ |
---|
| 641 | if(children[i].style.display != "none"){ num++; } |
---|
| 642 | if(num > 1){ break; } |
---|
| 643 | } |
---|
| 644 | if(num == 1){ return; } |
---|
| 645 | if(focusTemp[pos] === null){ |
---|
| 646 | zone = focusTemp.parentNode[child]; |
---|
| 647 | } |
---|
| 648 | else{ |
---|
| 649 | zone = focusTemp[pos]; |
---|
| 650 | } |
---|
| 651 | if(zone.style.display === "none"){ |
---|
| 652 | focusTemp = zone; |
---|
| 653 | } |
---|
| 654 | else{ |
---|
| 655 | found = true; |
---|
| 656 | } |
---|
| 657 | } |
---|
| 658 | if(event.shiftKey){ |
---|
| 659 | var parent = focusNode.parentNode; |
---|
| 660 | for(i = 0; i < this.gridNode.childNodes.length; i++){ |
---|
| 661 | if(parent == this.gridNode.childNodes[i]){ |
---|
| 662 | break; |
---|
| 663 | } |
---|
| 664 | } |
---|
| 665 | children = this.gridNode.childNodes[i].childNodes; |
---|
| 666 | for(j = 0; j < children.length; j++){ |
---|
| 667 | if(zone == children[j]){ |
---|
| 668 | break; |
---|
| 669 | } |
---|
| 670 | } |
---|
| 671 | if(has("mozilla") || has("webkit")){ i--; } |
---|
| 672 | |
---|
| 673 | widget = registry.byNode(focusNode); |
---|
| 674 | if(!widget.dragRestriction){ |
---|
| 675 | r = m.removeDragItem(parent, focusNode); |
---|
| 676 | this.addChild(widget, i, j); |
---|
| 677 | domAttr.set(focusNode, "tabIndex", "0"); |
---|
| 678 | focus.focus(focusNode); |
---|
| 679 | } |
---|
| 680 | else{ |
---|
| 681 | topic.publish("/dojox/layout/gridContainer/moveRestriction", this); |
---|
| 682 | } |
---|
| 683 | } |
---|
| 684 | else{ |
---|
| 685 | focus.focus(zone); |
---|
| 686 | } |
---|
| 687 | break; |
---|
| 688 | case k.RIGHT_ARROW: |
---|
| 689 | case k.LEFT_ARROW: |
---|
| 690 | events.stop(event); |
---|
| 691 | if(event.shiftKey){ |
---|
| 692 | var z = 0; |
---|
| 693 | if(focusNode.parentNode[pos] === null){ |
---|
| 694 | if(has("ie") && key == k.LEFT_ARROW){ |
---|
| 695 | z = this.gridNode.childNodes.length-1; |
---|
| 696 | } |
---|
| 697 | } |
---|
| 698 | else if(focusNode.parentNode[pos].nodeType == 3){ |
---|
| 699 | z = this.gridNode.childNodes.length - 2; |
---|
| 700 | } |
---|
| 701 | else{ |
---|
| 702 | for(i = 0; i < this.gridNode.childNodes.length; i++){ |
---|
| 703 | if(focusNode.parentNode[pos] == this.gridNode.childNodes[i]){ |
---|
| 704 | break; |
---|
| 705 | } |
---|
| 706 | z++; |
---|
| 707 | } |
---|
| 708 | if(has("mozilla") || has("webkit")){ z--; } |
---|
| 709 | } |
---|
| 710 | widget = registry.byNode(focusNode); |
---|
| 711 | var _dndType = focusNode.getAttribute("dndtype"); |
---|
| 712 | if(_dndType === null){ |
---|
| 713 | //check if it's a dijit object |
---|
| 714 | if(widget && widget.dndType){ |
---|
| 715 | _dndType = widget.dndType.split(/\s*,\s*/); |
---|
| 716 | } |
---|
| 717 | else{ |
---|
| 718 | _dndType = ["text"]; |
---|
| 719 | } |
---|
| 720 | } |
---|
| 721 | else{ |
---|
| 722 | _dndType = _dndType.split(/\s*,\s*/); |
---|
| 723 | } |
---|
| 724 | var accept = false; |
---|
| 725 | for(i = 0; i < this.acceptTypes.length; i++){ |
---|
| 726 | for(j = 0; j < _dndType.length; j++){ |
---|
| 727 | if(_dndType[j] == this.acceptTypes[i]){ |
---|
| 728 | accept = true; |
---|
| 729 | break; |
---|
| 730 | } |
---|
| 731 | } |
---|
| 732 | } |
---|
| 733 | if(accept && !widget.dragRestriction){ |
---|
| 734 | var parentSource = focusNode.parentNode, |
---|
| 735 | place = 0; |
---|
| 736 | if(k.LEFT_ARROW == key){ |
---|
| 737 | var t = z; |
---|
| 738 | if(has("mozilla") || has("webkit")){ t = z + 1; } |
---|
| 739 | place = this.gridNode.childNodes[t].childNodes.length; |
---|
| 740 | } |
---|
| 741 | // delete of manager : |
---|
| 742 | r = m.removeDragItem(parentSource, focusNode); |
---|
| 743 | this.addChild(widget, z, place); |
---|
| 744 | domAttr.set(r, "tabIndex", "0"); |
---|
| 745 | focus.focus(r); |
---|
| 746 | } |
---|
| 747 | else{ |
---|
| 748 | topic.publish("/dojox/layout/gridContainer/moveRestriction", this); |
---|
| 749 | } |
---|
| 750 | } |
---|
| 751 | else{ |
---|
| 752 | var node = focusNode.parentNode; |
---|
| 753 | while(zone === null){ |
---|
| 754 | if(node[pos] !== null && node[pos].nodeType !== 3){ |
---|
| 755 | node = node[pos]; |
---|
| 756 | } |
---|
| 757 | else{ |
---|
| 758 | if(pos === "previousSibling"){ |
---|
| 759 | node = node.parentNode.childNodes[node.parentNode.childNodes.length-1]; |
---|
| 760 | } |
---|
| 761 | else{ |
---|
| 762 | node = node.parentNode.childNodes[has("ie") ? 0 : 1]; |
---|
| 763 | } |
---|
| 764 | } |
---|
| 765 | zone = node[child]; |
---|
| 766 | if(zone && zone.style.display == "none"){ |
---|
| 767 | // check that all elements are not hidden |
---|
| 768 | children = zone.parentNode.childNodes; |
---|
| 769 | var childToSelect = null; |
---|
| 770 | if(pos == "previousSibling"){ |
---|
| 771 | for(i = children.length-1; i >= 0; i--){ |
---|
| 772 | if(children[i].style.display != "none"){ |
---|
| 773 | childToSelect = children[i]; |
---|
| 774 | break; |
---|
| 775 | } |
---|
| 776 | } |
---|
| 777 | } |
---|
| 778 | else{ |
---|
| 779 | for(i = 0; i < children.length; i++){ |
---|
| 780 | if(children[i].style.display != "none"){ |
---|
| 781 | childToSelect = children[i]; |
---|
| 782 | break; |
---|
| 783 | } |
---|
| 784 | } |
---|
| 785 | } |
---|
| 786 | if(!childToSelect){ |
---|
| 787 | focusNode = zone; |
---|
| 788 | node = focusNode.parentNode; |
---|
| 789 | zone = null; |
---|
| 790 | } |
---|
| 791 | else{ |
---|
| 792 | zone = childToSelect; |
---|
| 793 | } |
---|
| 794 | } |
---|
| 795 | } |
---|
| 796 | focus.focus(zone); |
---|
| 797 | } |
---|
| 798 | break; |
---|
| 799 | } |
---|
| 800 | } |
---|
| 801 | } |
---|
| 802 | }, |
---|
| 803 | |
---|
| 804 | destroy: function(){ |
---|
| 805 | //console.log("dojox.layout.GridContainerLite ::: destroy"); |
---|
| 806 | var m = this._dragManager; |
---|
| 807 | array.forEach(this._grid, function(dropZone){ |
---|
| 808 | m.unregister(dropZone.node); |
---|
| 809 | }); |
---|
| 810 | this.inherited(arguments); |
---|
| 811 | } |
---|
| 812 | }); |
---|
| 813 | |
---|
| 814 | gcl.ChildWidgetProperties = { |
---|
| 815 | // summary: |
---|
| 816 | // Properties set on children of a GridContainerLite |
---|
| 817 | |
---|
| 818 | // column: String |
---|
| 819 | // Column of the grid to place the widget. |
---|
| 820 | // Defined only if dojo.require("dojox.layout.GridContainerLite") is done. |
---|
| 821 | column: "1", |
---|
| 822 | |
---|
| 823 | // dragRestriction: Boolean |
---|
| 824 | // If true, the widget can not be draggable. |
---|
| 825 | // Defined only if dojo.require("dojox.layout.GridContainerLite") is done. |
---|
| 826 | dragRestriction: false |
---|
| 827 | }; |
---|
| 828 | |
---|
| 829 | // Add to widget base for benefit of parser. Remove for 2.0. Also, hide from doc viewer. |
---|
| 830 | lang.extend(_WidgetBase, /*===== {} || =====*/ gcl.ChildWidgetProperties); |
---|
| 831 | |
---|
| 832 | return gcl; |
---|
| 833 | }); |
---|