| 1 |
define(["dojo/_base/kernel", "dojo/_base/array", "dojo/dom-geometry", "dojo/json"], function(dojo, array, geom, json){ |
| 2 |
|
| 3 |
function dijitById(id){ |
| 4 |
return dojo.global.require("dijit/registry").byId(id); |
| 5 |
} |
| 6 |
|
| 7 |
var exports = { |
| 8 |
checkInside: function( child, parent, comment){ |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
child = dijitById(child); |
| 13 |
parent = dijitById(parent); |
| 14 |
|
| 15 |
var cp = geom.position(child.domNode, true), |
| 16 |
pp = geom.position(parent.domNode, true); |
| 17 |
|
| 18 |
|
| 19 |
pp.w = Math.ceil(pp.w); |
| 20 |
|
| 21 |
doh.t( |
| 22 |
cp.y >= pp.y && cp.y+cp.h <= pp.y+pp.h && |
| 23 |
cp.x >= pp.x && cp.x+cp.w <= pp.x+pp.w, |
| 24 |
(comment ? comment + ": " : "") + child.region + " inside " + parent.id + json.stringify(cp) + json.stringify(pp) |
| 25 |
); |
| 26 |
}, |
| 27 |
|
| 28 |
checkAbove: function( comment, above, below){ |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
above = dijitById(above); |
| 33 |
below = dijitById(below); |
| 34 |
|
| 35 |
var ap = geom.position(above.domNode, true), |
| 36 |
bp = geom.position(below.domNode, true); |
| 37 |
|
| 38 |
doh.t(ap.y+ap.h < bp.y, |
| 39 |
comment + " " + above.region + " above " + below.region + json.stringify(ap) + json.stringify(bp) |
| 40 |
); |
| 41 |
}, |
| 42 |
|
| 43 |
checkLeft: function( comment, left, right){ |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
left = dijitById(left); |
| 48 |
right = dijitById(right); |
| 49 |
|
| 50 |
var lp = geom.position(left.domNode, true), |
| 51 |
rp = geom.position(right.domNode, true); |
| 52 |
|
| 53 |
doh.t(lp.x+lp.w < rp.x, |
| 54 |
comment + " " + left.region + " to left of " + right.region + json.stringify(lp) + json.stringify(rp) |
| 55 |
); |
| 56 |
}, |
| 57 |
|
| 58 |
checkBCpanes: function( bc, comment){ |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
var children = bc.getChildren(), |
| 64 |
regions = {}; |
| 65 |
|
| 66 |
|
| 67 |
array.forEach(children, function(child, comment){ |
| 68 |
exports.checkInside(child, bc, comment); |
| 69 |
regions[child.region] = child; |
| 70 |
}); |
| 71 |
|
| 72 |
|
| 73 |
array.forEach(children, function(child){ |
| 74 |
switch(child.region){ |
| 75 |
case "top": |
| 76 |
array.forEach(bc.design == "sidebar" ? ["center", "bottom"] : ["left", "center", "right", "bottom"], function(region){ |
| 77 |
if(regions[region]){ |
| 78 |
exports.checkAbove(bc.id, child, regions[region], comment); |
| 79 |
} |
| 80 |
}); |
| 81 |
break; |
| 82 |
case "bottom": |
| 83 |
array.forEach(bc.design == "sidebar" ? ["center", "top"] : ["left", "center", "right", "top"], function(region){ |
| 84 |
if(regions[region]){ |
| 85 |
exports.checkAbove(bc.id, regions[region], child, comment); |
| 86 |
} |
| 87 |
}); |
| 88 |
break; |
| 89 |
case "left": |
| 90 |
array.forEach(bc.design == "sidebar" ? ["top", "center", "bottom", "right"] : ["right"], function(region){ |
| 91 |
if(regions[region]){ |
| 92 |
exports.checkLeft(bc.id, child, regions[region], comment); |
| 93 |
} |
| 94 |
}); |
| 95 |
break; |
| 96 |
case "right": |
| 97 |
array.forEach(bc.design == "sidebar" ? ["top", "center", "bottom", "left"] : ["left"], function(region){ |
| 98 |
if(regions[region]){ |
| 99 |
exports.checkLeft(bc.id, regions[region], child, comment); |
| 100 |
} |
| 101 |
}); |
| 102 |
break; |
| 103 |
} |
| 104 |
}); |
| 105 |
}, |
| 106 |
|
| 107 |
within: function( a, b, range){ |
| 108 |
|
| 109 |
|
| 110 |
return Math.abs(a-b) <= range; |
| 111 |
} |
| 112 |
}; |
| 113 |
|
| 114 |
return exports; |
| 115 |
}); |