| 1 |
define(["dojo/_base/declare", "dojo/_base/lang", "dojo/_base/array", "dojo/_base/window", |
| 2 |
"dojo/query", "dojo/dom-geometry", "dojo/dom-attr", "dojo/dom-style", "dijit/registry", |
| 3 |
"./LayoutBase", "../utils/layout", "../utils/constraints", "dojo/sniff"], |
| 4 |
function(declare, lang, array, win, query, domGeom, domAttr, domStyle, registry, LayoutBase, layout, constraints, has){ |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
return declare("dojox.app.controllers.Layout", LayoutBase, { |
| 11 |
|
| 12 |
constructor: function(app, events){ |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
}, |
| 21 |
|
| 22 |
onResize: function(){ |
| 23 |
this._doResize(this.app); |
| 24 |
|
| 25 |
|
| 26 |
this.resizeSelectedChildren(this.app); |
| 27 |
}, |
| 28 |
|
| 29 |
|
| 30 |
resizeSelectedChildren: function(w){ |
| 31 |
for(var hash in w.selectedChildren){ |
| 32 |
if(w.selectedChildren[hash] && w.selectedChildren[hash].domNode){ |
| 33 |
this.app.log("in Layout resizeSelectedChildren calling resizeSelectedChildren calling _doResize for w.selectedChildren[hash].id="+w.selectedChildren[hash].id); |
| 34 |
this._doResize(w.selectedChildren[hash]); |
| 35 |
|
| 36 |
array.forEach(w.selectedChildren[hash].domNode.children, function(child){ |
| 37 |
if(registry.byId(child.id) && registry.byId(child.id).resize){ |
| 38 |
registry.byId(child.id).resize(); |
| 39 |
} |
| 40 |
}); |
| 41 |
|
| 42 |
this.resizeSelectedChildren(w.selectedChildren[hash]); |
| 43 |
} |
| 44 |
} |
| 45 |
}, |
| 46 |
|
| 47 |
initLayout: function(event){ |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
this.app.log("in app/controllers/Layout.initLayout event=",event); |
| 58 |
this.app.log("in app/controllers/Layout.initLayout event.view.parent.name=[",event.view.parent.name,"]"); |
| 59 |
|
| 60 |
if (!event.view.domNode.parentNode || (has("ie") == 8 && !event.view.domNode.parentElement)) { |
| 61 |
if(this.app.useConfigOrder){ |
| 62 |
event.view.parent.domNode.appendChild(event.view.domNode); |
| 63 |
}else{ |
| 64 |
this.addViewToParentDomByConstraint(event); |
| 65 |
} |
| 66 |
} |
| 67 |
domAttr.set(event.view.domNode, "data-app-constraint", event.view.constraint); |
| 68 |
this.inherited(arguments); |
| 69 |
}, |
| 70 |
|
| 71 |
addViewToParentDomByConstraint: function(event){ |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
var newViewConstraint = event.view.constraint; |
| 80 |
if(newViewConstraint === "bottom"){ |
| 81 |
event.view.parent.domNode.appendChild(event.view.domNode); |
| 82 |
}else if(newViewConstraint === "top"){ |
| 83 |
event.view.parent.domNode.insertBefore(event.view.domNode, event.view.parent.domNode.firstChild); |
| 84 |
}else{ |
| 85 |
if(event.view.parent.domNode.children.length > 0){ |
| 86 |
|
| 87 |
for(var childIndex in event.view.parent.domNode.children){ |
| 88 |
var child = event.view.parent.domNode.children[childIndex]; |
| 89 |
var dir = domStyle.get(event.view.parent.domNode,"direction"); |
| 90 |
var isltr = (dir === "ltr"); |
| 91 |
var LEADING_VIEW = isltr ? "left" : "right"; |
| 92 |
var TRAILING_VIEW = isltr ? "right" : "left"; |
| 93 |
if(child.getAttribute && child.getAttribute("data-app-constraint")) { |
| 94 |
var previousViewConstraint = child.getAttribute("data-app-constraint"); |
| 95 |
|
| 96 |
|
| 97 |
if(previousViewConstraint === "bottom" || |
| 98 |
(previousViewConstraint === TRAILING_VIEW) || |
| 99 |
(previousViewConstraint !== "top" && |
| 100 |
(newViewConstraint === LEADING_VIEW))){ |
| 101 |
event.view.parent.domNode.insertBefore(event.view.domNode, child); |
| 102 |
break; |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
if (!event.view.domNode.parentNode || (has("ie") == 8 && !event.view.domNode.parentElement)) { |
| 110 |
event.view.parent.domNode.appendChild(event.view.domNode); |
| 111 |
} |
| 112 |
}, |
| 113 |
|
| 114 |
_doResize: function(view){ |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
var node = view.domNode; |
| 121 |
if(!node){ |
| 122 |
this.app.log("Warning - View has not been loaded, in Layout _doResize view.domNode is not set for view.id="+view.id+" view=",view); |
| 123 |
return; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
var mb = {}; |
| 130 |
if( !("h" in mb) || !("w" in mb) ){ |
| 131 |
mb = lang.mixin(domGeom.getMarginBox(node), mb); |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
if(view !== this.app){ |
| 137 |
var cs = domStyle.getComputedStyle(node); |
| 138 |
var me = domGeom.getMarginExtents(node, cs); |
| 139 |
var be = domGeom.getBorderExtents(node, cs); |
| 140 |
var bb = (view._borderBox = { |
| 141 |
w: mb.w - (me.w + be.w), |
| 142 |
h: mb.h - (me.h + be.h) |
| 143 |
}); |
| 144 |
var pe = domGeom.getPadExtents(node, cs); |
| 145 |
view._contentBox = { |
| 146 |
l: domStyle.toPixelValue(node, cs.paddingLeft), |
| 147 |
t: domStyle.toPixelValue(node, cs.paddingTop), |
| 148 |
w: bb.w - pe.w, |
| 149 |
h: bb.h - pe.h |
| 150 |
}; |
| 151 |
}else{ |
| 152 |
|
| 153 |
|
| 154 |
view._contentBox = { |
| 155 |
l: 0, |
| 156 |
t: 0, |
| 157 |
h: win.global.innerHeight || win.doc.documentElement.clientHeight, |
| 158 |
w: win.global.innerWidth || win.doc.documentElement.clientWidth |
| 159 |
}; |
| 160 |
} |
| 161 |
|
| 162 |
this.inherited(arguments); |
| 163 |
}, |
| 164 |
|
| 165 |
layoutView: function(event){ |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
if(event.view){ |
| 176 |
this.inherited(arguments); |
| 177 |
|
| 178 |
if(event.doResize){ |
| 179 |
this._doResize(event.parent || this.app); |
| 180 |
this._doResize(event.view); |
| 181 |
} |
| 182 |
} |
| 183 |
}, |
| 184 |
|
| 185 |
_doLayout: function(view){ |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
if(!view){ |
| 193 |
console.warn("layout empty view."); |
| 194 |
return; |
| 195 |
} |
| 196 |
this.app.log("in Layout _doLayout called for view.id="+view.id+" view=",view); |
| 197 |
|
| 198 |
var children; |
| 199 |
|
| 200 |
|
| 201 |
var selectedChild = constraints.getSelectedChild(view, view.constraint); |
| 202 |
if(selectedChild && selectedChild.isFullScreen){ |
| 203 |
console.warn("fullscreen sceen layout"); |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
}else{ |
| 214 |
children = query("> [data-app-constraint]", view.domNode).map(function(node){ |
| 215 |
var w = registry.getEnclosingWidget(node); |
| 216 |
if(w){ |
| 217 |
w._constraint = domAttr.get(node, "data-app-constraint"); |
| 218 |
return w; |
| 219 |
} |
| 220 |
|
| 221 |
return { |
| 222 |
domNode: node, |
| 223 |
_constraint: domAttr.get(node, "data-app-constraint") |
| 224 |
}; |
| 225 |
}); |
| 226 |
|
| 227 |
if(selectedChild){ |
| 228 |
children = array.filter(children, function(c){ |
| 229 |
|
| 230 |
return c.domNode && c._constraint; |
| 231 |
}, view); |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
if(view._contentBox){ |
| 236 |
layout.layoutChildren(view.domNode, view._contentBox, children); |
| 237 |
} |
| 238 |
} |
| 239 |
}); |
| 240 |
}); |