Debian Codegraph @

dijit/tests/layout/robot/borderContainerTestFunctions.js

raw symbols SCIP
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(/*Widget*/ child, /*Widget*/ parent, /*String?*/ comment){
9 // summary:
10 // Test that child is fully inside of parent
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 // Adjust for IE10+ fractional values
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(/*String*/ comment, /*Widget*/ above, /*Widget*/ below){
29 // summary:
30 // Test that child is fully above parent
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(/*String*/ comment, /*Widget*/ left, /*Widget*/ right){
44 // summary:
45 // Test that child is fully left of parent
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(/*BorderContainer*/ bc, /*String*/ comment){
59 // summary:
60 // Check that all the panes in this BorderContainer are in sane
61 // positions relative to each other. Assumes at most one pane
62 // in each region.
63 var children = bc.getChildren(),
64 regions = {};
65
66 // Check all panes inside BorderContainer
67 array.forEach(children, function(child, comment){
68 exports.checkInside(child, bc, comment);
69 regions[child.region] = child;
70 });
71
72 // Check pane positions relative to each other
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(/*Number*/ a, /*Number*/ b, /*Number*/ range){
108 // summary:
109 // Returns true if a and b are within range
110 return Math.abs(a-b) <= range;
111 }
112 };
113
114 return exports;
115 });