| 1 |
define([ |
| 2 |
"dojo/_base/array", |
| 3 |
"dojo/dom-class", |
| 4 |
"dojo/dom-geometry", |
| 5 |
"dojo/dom-style", |
| 6 |
"dojo/_base/lang" |
| 7 |
], function(array, domClass, domGeometry, domStyle, lang){ |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
var layout = {}; |
| 15 |
|
| 16 |
|
| 17 |
layout.marginBox2contentBox = function( node, mb){ |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
var cs = domStyle.getComputedStyle(node); |
| 23 |
var me = domGeometry.getMarginExtents(node, cs); |
| 24 |
var pb = domGeometry.getPadBorderExtents(node, cs); |
| 25 |
return { |
| 26 |
l: domStyle.toPixelValue(node, cs.paddingLeft), |
| 27 |
t: domStyle.toPixelValue(node, cs.paddingTop), |
| 28 |
w: mb.w - (me.w + pb.w), |
| 29 |
h: mb.h - (me.h + pb.h) |
| 30 |
}; |
| 31 |
}; |
| 32 |
|
| 33 |
function capitalize(word){ |
| 34 |
return word.substring(0,1).toUpperCase() + word.substring(1); |
| 35 |
} |
| 36 |
|
| 37 |
function size(widget, dim){ |
| 38 |
|
| 39 |
var newSize = widget.resize ? widget.resize(dim) : domGeometry.setMarginBox(widget.domNode, dim); |
| 40 |
|
| 41 |
|
| 42 |
if(newSize){ |
| 43 |
|
| 44 |
lang.mixin(widget, newSize); |
| 45 |
}else{ |
| 46 |
|
| 47 |
|
| 48 |
lang.mixin(widget, domGeometry.getMarginBox(widget.domNode)); |
| 49 |
lang.mixin(widget, dim); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
layout.layoutChildren = function( container, dim, children, |
| 54 |
changedRegionId, changedRegionSize){ |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
dim = lang.mixin({}, dim); |
| 76 |
|
| 77 |
domClass.add(container, "dijitLayoutContainer"); |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
children = array.filter(children, function(item){ return item._constraint != "center" && item.layoutAlign != "client"; }) |
| 83 |
.concat(array.filter(children, function(item){ return item._constraint == "center" || item.layoutAlign == "client"; })); |
| 84 |
|
| 85 |
|
| 86 |
array.forEach(children, function(child){ |
| 87 |
var elm = child.domNode, |
| 88 |
pos = (child._constraint || child.layoutAlign); |
| 89 |
if(!pos){ |
| 90 |
throw new Error("No constraint setting for " + child.id) |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
var elmStyle = elm.style; |
| 95 |
elmStyle.left = dim.l+"px"; |
| 96 |
elmStyle.top = dim.t+"px"; |
| 97 |
elmStyle.position = "absolute"; |
| 98 |
|
| 99 |
domClass.add(elm, "dijitAlign" + capitalize(pos)); |
| 100 |
|
| 101 |
|
| 102 |
var sizeSetting = {}; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
if(changedRegionId && changedRegionId == child.id){ |
| 107 |
sizeSetting[child._constraint == "top" || child._constraint == "bottom" ? "h" : "w"] = changedRegionSize; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
if(pos == "top" || pos == "bottom"){ |
| 113 |
sizeSetting.w = dim.w; |
| 114 |
size(child, sizeSetting); |
| 115 |
dim.h -= child.h; |
| 116 |
if(pos == "top"){ |
| 117 |
dim.t += child.h; |
| 118 |
}else{ |
| 119 |
elmStyle.top = dim.t + dim.h + "px"; |
| 120 |
} |
| 121 |
}else if(pos == "left" || pos == "right"){ |
| 122 |
sizeSetting.h = dim.h; |
| 123 |
size(child, sizeSetting); |
| 124 |
dim.w -= child.w; |
| 125 |
if(pos == "left"){ |
| 126 |
dim.l += child.w; |
| 127 |
}else{ |
| 128 |
elmStyle.left = dim.l + dim.w + "px"; |
| 129 |
} |
| 130 |
}else if(pos == "client" || pos == "center"){ |
| 131 |
size(child, dim); |
| 132 |
} |
| 133 |
}); |
| 134 |
}; |
| 135 |
|
| 136 |
|
| 137 |
return { |
| 138 |
marginBox2contentBox: layout.marginBox2contentBox, |
| 139 |
layoutChildren: layout.layoutChildren |
| 140 |
}; |
| 141 |
}); |