| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| 2 |
"http://www.w3.org/TR/html4/strict.dtd"> |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
<html> |
| 10 |
<head> |
| 11 |
<title>dijit/_base/place unit test</title> |
| 12 |
<style type="text/css"> |
| 13 |
@import "../../themes/claro/document.css"; |
| 14 |
@import "../css/dijitTests.css"; |
| 15 |
|
| 16 |
html { |
| 17 |
overflow: hidden; /* ie6 needs this */ |
| 18 |
} |
| 19 |
body { |
| 20 |
height: 100%; |
| 21 |
padding: 0; |
| 22 |
margin: 0; |
| 23 |
border: 0; |
| 24 |
} |
| 25 |
|
| 26 |
.aroundNode { |
| 27 |
position: absolute; |
| 28 |
width: 20px; |
| 29 |
height: 20px; |
| 30 |
background: yellow; |
| 31 |
} |
| 32 |
|
| 33 |
#popup { |
| 34 |
position: absolute; |
| 35 |
width: 75px; |
| 36 |
background: blue; |
| 37 |
color: white; |
| 38 |
} |
| 39 |
</style> |
| 40 |
<script type="text/javascript" src="../../../dojo/dojo.js" |
| 41 |
data-dojo-config="isDebug: true, parseOnLoad: false"></script> |
| 42 |
<script type="text/javascript" src="../_testCommon.js"></script> |
| 43 |
|
| 44 |
<script type="text/javascript"> |
| 45 |
dojo.require("doh.runner"); |
| 46 |
dojo.require("dojo.window"); |
| 47 |
dojo.require("dijit.dijit"); |
| 48 |
|
| 49 |
|
| 50 |
dojo.ready(function(){ |
| 51 |
|
| 52 |
// The around nodes |
| 53 |
var aroundTop = dojo.byId("aroundTop"), |
| 54 |
aroundBottom = dojo.byId("aroundBottom"), |
| 55 |
aroundLeft = dojo.byId("aroundLeft"), |
| 56 |
aroundRight = dojo.byId("aroundRight"); |
| 57 |
|
| 58 |
// The popup (aka dropdown) |
| 59 |
var popup = dojo.byId("popup"); |
| 60 |
|
| 61 |
doh.register("dijit/_base/place", |
| 62 |
[ |
| 63 |
function placeOnScreenTL(t){ |
| 64 |
// Place popup at (10,7)... dijit.placeOnScreen() should choose the top-left corner, because |
| 65 |
// any of the other corner would make the popup go partially off the screen |
| 66 |
var ret = dijit.placeOnScreen(popup, {x: 10, y:7}, ["TR", "BR", "BL", "TL"]); |
| 67 |
|
| 68 |
doh.is("TL", ret.corner, "top left corner chosen"); |
| 69 |
doh.is("10px", popup.style.left, "x coord"); |
| 70 |
doh.is("7px", popup.style.top, "y coord"); |
| 71 |
doh.is(75, ret.w, "it's 75px wide"); |
| 72 |
}, |
| 73 |
function placeOnScreenTR(t){ |
| 74 |
// Place popup at top right... dijit.placeOnScreen() should choose the top-right corner, because |
| 75 |
// any of the other corner would make the popup go partially off the screen |
| 76 |
var viewport = dojo.window.getBox(), |
| 77 |
ret = dijit.placeOnScreen(popup, {x: viewport.w-10, y:7}, ["TL", "BR", "TR", "BL"]), |
| 78 |
popupCoords = dojo.position(popup); |
| 79 |
|
| 80 |
doh.is("TR", ret.corner, "top left corner chosen"); |
| 81 |
doh.is(viewport.w-10, popupCoords.x + popupCoords.w, "x coord"); |
| 82 |
doh.is("7px", popup.style.top, "y coord"); |
| 83 |
doh.is(75, ret.w, "it's 75px wide"); |
| 84 |
}, |
| 85 |
function placeOnScreenAroundNodeT(t){ |
| 86 |
// Dropdown from "aroundTop" node. Should pick the second choice, since the first |
| 87 |
// goes offscreen. |
| 88 |
var ret = dijit.placeOnScreenAroundNode(popup, aroundTop, { |
| 89 |
"TL": "BL", // aroundTop's top-left corner with the popup's bottom-left corner (fails) |
| 90 |
"BL": "TL", // aroundTop's bottom-left corner with the popup's top-left corner (works) |
| 91 |
"BR": "TR" // aroundTop's bottom-right corner with the popup's top-right corner (works) |
| 92 |
}); |
| 93 |
|
| 94 |
doh.is("BL", ret.aroundCorner, "around corner"); |
| 95 |
doh.is("TL", ret.corner, "popup's corner"); |
| 96 |
doh.is("20px", popup.style.top, "underneath around node"); |
| 97 |
doh.is(Math.round(dojo.position(aroundTop).x), Math.round(popup.style.left.replace("px", "")), |
| 98 |
"left sides aligned"); |
| 99 |
}, |
| 100 |
function placeOnScreenAroundNodeTooltip(t){ |
| 101 |
// Same as above test except that shape of drop down changes depending on where it's positioned. |
| 102 |
// Simulates tooltip placement (tooltip shape changes b/c of the arrow). |
| 103 |
// Should pick the third choice this time |
| 104 |
|
| 105 |
function layoutNode(node, aroundCorner, nodeCorner){ |
| 106 |
node.style.width = (nodeCorner == "TL" ? "5000px" : "75px"); |
| 107 |
} |
| 108 |
var ret = dijit.placeOnScreenAroundNode(popup, aroundTop, { |
| 109 |
"TL": "BL", // aroundTop's top-left corner with the popup's bottom-left corner (fails) |
| 110 |
"BL": "TL", // aroundTop's bottom-left corner with the popup's top-left corner (works) |
| 111 |
"BR": "TR" // aroundTop's bottom-right corner with the popup's top-right corner (works) |
| 112 |
}, layoutNode); |
| 113 |
|
| 114 |
doh.is("BR", ret.aroundCorner, "around corner"); |
| 115 |
doh.is("TR", ret.corner, "popup's corner"); |
| 116 |
doh.is("20px", popup.style.top, "underneath around node"); |
| 117 |
doh.is(Math.round(dojo.position(aroundTop).x + dojo.position(aroundTop).w), |
| 118 |
Math.round(dojo.position(popup).x + dojo.position(popup).w), |
| 119 |
"right sides aligned"); |
| 120 |
}, |
| 121 |
function placeOnScreenAroundNodeB(t){ |
| 122 |
// Dropdown from "aroundBottom" node. Should go above aroundNode so that |
| 123 |
// popup doesn't go offscreen |
| 124 |
var ret = dijit.placeOnScreenAroundNode(popup, aroundBottom, { |
| 125 |
"BL": "TL", // aroundBottom's bottom-left corner with the popup's top-left corner (fails) |
| 126 |
"TL": "BL", // aroundBottom's top-left corner with the popup's bottom-left corner (works) |
| 127 |
"BR": "TR" // aroundBottom's bottom-right corner with the popup's top-right corner (fails) |
| 128 |
}); |
| 129 |
|
| 130 |
doh.is("TL", ret.aroundCorner, "around corner"); |
| 131 |
doh.is("BL", ret.corner, "popup's corner"); |
| 132 |
doh.is(Math.round(dojo.position(aroundBottom).y), |
| 133 |
Math.round(dojo.position(popup).y + dojo.position(popup).h), "above around node"); |
| 134 |
}, |
| 135 |
function placeOnScreenAroundNodeBM(t){ |
| 136 |
// bottom middle popup from "aroundBottom" node |
| 137 |
var ret = dijit.placeOnScreenAroundNode(popup, aroundBottom, { |
| 138 |
"TR": "TL", // aroundBottom's top-right corner with the popup's top-left corner (fails) |
| 139 |
"TM": "BM", // aroundBottom's top-middle with the popup's bottom-middle (works) |
| 140 |
"BM": "TM", // aroundBottom's bottom-middle with the popup's top-middle (fails) |
| 141 |
"TL": "TR" // aroundBottom's top-left corner with the popup's top-right corner (fails) |
| 142 |
}); |
| 143 |
|
| 144 |
doh.is("TM", ret.aroundCorner, "around middle"); |
| 145 |
doh.is("BM", ret.corner, "popup's middle"); |
| 146 |
var popupPos = dojo.position(popup); |
| 147 |
var aroundPos = dojo.position(aroundBottom); |
| 148 |
doh.is(Math.round(aroundPos.y), Math.round(popupPos.y + popupPos.h), "above around node"); |
| 149 |
doh.t(aroundPos.x > popupPos.x, "starts before around node"); |
| 150 |
doh.t(aroundPos.x < (popupPos.x + popupPos.w), "ends after around node"); |
| 151 |
}, |
| 152 |
function placeOnScreenAroundNodeTM(t){ |
| 153 |
// top middle popup from "aroundTop" node |
| 154 |
var ret = dijit.placeOnScreenAroundNode(popup, aroundTop, { |
| 155 |
"BL": "BR", // aroundTop's bottom-left corner with the popup's bottom-right corner (fails) |
| 156 |
"TM": "BM", // aroundTop's top-middle with the popup's bottom-middle (fails) |
| 157 |
"BM": "TM", // aroundTop's bottom-middle with the popup's top-middle (works) |
| 158 |
"BR": "BL" // aroundTop's bottom-right corner with the popup's bottom-left corner (fails) |
| 159 |
}); |
| 160 |
|
| 161 |
doh.is("BM", ret.aroundCorner, "around middle"); |
| 162 |
doh.is("TM", ret.corner, "popup's middle"); |
| 163 |
var popupPos = dojo.position(popup); |
| 164 |
var aroundPos = dojo.position(aroundTop); |
| 165 |
doh.is(Math.round(aroundPos.y + aroundPos.h), Math.round(popupPos.y), "below around node"); |
| 166 |
doh.t(aroundPos.x > popupPos.x, "starts before around node"); |
| 167 |
doh.t(aroundPos.x < (popupPos.x + popupPos.w), "ends after around node"); |
| 168 |
}, |
| 169 |
function placeOnScreenAroundNodeML(t){ |
| 170 |
// middle left popup from "aroundLeft" node |
| 171 |
var ret = dijit.placeOnScreenAroundNode(popup, aroundLeft, { |
| 172 |
"BR": "TR", // aroundLeft's bottom-right corner with the popup's top-right corner (fails) |
| 173 |
"MR": "ML", // aroundLeft's middle-right with the popup's middle-left (works) |
| 174 |
"ML": "MR", // aroundLeft's middle-left with the popup's middle-right (fails) |
| 175 |
"TR": "BR" // aroundLeft's top-right corner with the popup's bottom-right corner (fails) |
| 176 |
}); |
| 177 |
|
| 178 |
doh.is("MR", ret.aroundCorner, "around middle"); |
| 179 |
doh.is("ML", ret.corner, "popup's middle"); |
| 180 |
var popupPos = dojo.position(popup); |
| 181 |
var aroundPos = dojo.position(aroundLeft); |
| 182 |
doh.is(aroundPos.x + aroundPos.w, popupPos.x, "after around node"); |
| 183 |
doh.t(aroundPos.y > popupPos.y, "starts before around node"); |
| 184 |
doh.t(aroundPos.y < (popupPos.y + popupPos.h), "ends after around node"); |
| 185 |
}, |
| 186 |
function placeOnScreenAroundNodeMR(t){ |
| 187 |
// middle left popup from "aroundRight" node |
| 188 |
var ret = dijit.placeOnScreenAroundNode(popup, aroundRight, { |
| 189 |
"BL": "TL", // aroundRight's bottom-left corner with the popup's top-left corner (fails) |
| 190 |
"MR": "ML", // aroundRight's middle-right with the popup's middle-left (fails) |
| 191 |
"ML": "MR", // aroundRight's middle-left with the popup's middle-right (works) |
| 192 |
"TL": "BL" // aroundRight's top-left corner with the popup's bottom-left corner (fails) |
| 193 |
}); |
| 194 |
|
| 195 |
doh.is("ML", ret.aroundCorner, "around middle"); |
| 196 |
doh.is("MR", ret.corner, "popup's middle"); |
| 197 |
var popupPos = dojo.position(popup); |
| 198 |
var aroundPos = dojo.position(aroundRight); |
| 199 |
doh.is(Math.round(popupPos.x + popupPos.w), Math.round(aroundPos.x), "before around node"); |
| 200 |
doh.t(aroundPos.y > popupPos.y, "starts before around node"); |
| 201 |
doh.t(aroundPos.y < (popupPos.y + popupPos.h), "ends after around node"); |
| 202 |
}, |
| 203 |
function placeOnScreenAroundNodeMLB(t){ |
| 204 |
// bottom middle popup from "aroundLeft" node |
| 205 |
var ret = dijit.placeOnScreenAroundNode(popup, aroundLeft, { |
| 206 |
"BR": "TR", // aroundLeft's bottom-right corner with the popup's top-right corner (fails) |
| 207 |
"BM": "TM", // aroundLeft's bottom-middle with the popup's top-middle (works, sort of) |
| 208 |
"TR": "BR" // aroundLeft's top-right corner with the popup's bottom-right corner (fails) |
| 209 |
}); |
| 210 |
|
| 211 |
doh.is("BM", ret.aroundCorner, "around middle"); |
| 212 |
doh.is("TM", ret.corner, "popup's middle"); |
| 213 |
var popupPos = dojo.position(popup); |
| 214 |
var aroundPos = dojo.position(aroundLeft); |
| 215 |
doh.is(Math.round(aroundPos.y + aroundPos.h), Math.round(popupPos.y), "below around node"); |
| 216 |
doh.is(aroundPos.x, popupPos.x, "left aligned with around node"); |
| 217 |
}, |
| 218 |
function placeOnScreenAroundNodeMRT(t){ |
| 219 |
// top middle popup from "aroundRight" node |
| 220 |
var ret = dijit.placeOnScreenAroundNode(popup, aroundRight, { |
| 221 |
"BL": "TL", // aroundRight's bottom-left corner with the popup's top-left corner (fails) |
| 222 |
"TM": "BM", // aroundRight's top-middle with the popup's bottom-middle (works) |
| 223 |
"TL": "BL" // aroundRight's top-left corner with the popup's bottom-left corner (fails) |
| 224 |
}); |
| 225 |
|
| 226 |
doh.is("TM", ret.aroundCorner, "around middle"); |
| 227 |
doh.is("BM", ret.corner, "popup's middle"); |
| 228 |
var popupPos = dojo.position(popup); |
| 229 |
var aroundPos = dojo.position(aroundRight); |
| 230 |
doh.is(Math.round(popupPos.x + popupPos.w), |
| 231 |
Math.round(aroundPos.x + aroundPos.w + 1/*right:1px*/), "right aligned with around node"); |
| 232 |
doh.is(Math.round(popupPos.y + popupPos.h), Math.round(aroundPos.y), "above around node"); |
| 233 |
}, |
| 234 |
function placeOnScreenAroundNodeTML(t){ |
| 235 |
// middle left popup from "aroundTop" node |
| 236 |
var ret = dijit.placeOnScreenAroundNode(popup, aroundTop, { |
| 237 |
"BL": "BR", // aroundTop's bottom-left corner with the popup's bottom-right corner (fails) |
| 238 |
"ML": "MR", // aroundTop's middle-left with the popup's middle-right (works) |
| 239 |
"BR": "BL" // aroundTop's bottom-right corner with the popup's bottom-left corner (fails) |
| 240 |
}); |
| 241 |
|
| 242 |
doh.is("ML", ret.aroundCorner, "around middle"); |
| 243 |
doh.is("MR", ret.corner, "popup's middle"); |
| 244 |
var popupPos = dojo.position(popup); |
| 245 |
var aroundPos = dojo.position(aroundTop); |
| 246 |
doh.is(Math.round(aroundPos.x), Math.round(popupPos.x + popupPos.w), "before around node"); |
| 247 |
doh.is(aroundPos.y, popupPos.y, "top aligned with around node"); |
| 248 |
}, |
| 249 |
function placeOnScreenAroundNodeBMR(t){ |
| 250 |
// middle right popup from "aroundBottom" node |
| 251 |
var ret = dijit.placeOnScreenAroundNode(popup, aroundBottom, { |
| 252 |
"TL": "TR", // aroundBottom's top-left corner with the popup's top-right corner (fails) |
| 253 |
"MR": "ML", // aroundBottom's middle-right with the popup's middle-left (works) |
| 254 |
"TR": "TL" // aroundBottom's top-right corner with the popup's top-left corner (fails) |
| 255 |
}); |
| 256 |
|
| 257 |
doh.is("MR", ret.aroundCorner, "around middle"); |
| 258 |
doh.is("ML", ret.corner, "popup's middle"); |
| 259 |
var popupPos = dojo.position(popup); |
| 260 |
var aroundPos = dojo.position(aroundBottom); |
| 261 |
doh.is(Math.round(aroundPos.x + aroundPos.w), Math.round(popupPos.x), "after around node"); |
| 262 |
doh.is(Math.round(aroundPos.y + aroundPos.h + 5/*bottom:5px*/), |
| 263 |
Math.round(popupPos.y + popupPos.h), "bottom aligned with around node"); |
| 264 |
} |
| 265 |
] |
| 266 |
); |
| 267 |
doh.run(); |
| 268 |
}); |
| 269 |
|
| 270 |
</script> |
| 271 |
</head> |
| 272 |
<body> |
| 273 |
<h1>Dijit/_base/place Unit Test</h1> |
| 274 |
<div id="aroundTop" class="aroundNode" style="top: 0; left: 50%;">T</div> |
| 275 |
<div id="aroundLeft" class="aroundNode" style="bottom: 30%; left: 0;">L</div> |
| 276 |
<div id="aroundRight" class="aroundNode" style="bottom: 30%; right: 1px;">R</div> |
| 277 |
<div id="aroundBottom" class="aroundNode" style="bottom: 5px; left: 50%;">B</div> |
| 278 |
|
| 279 |
<div id="popup"> |
| 280 |
I'm a drop down, wider and taller than the around nodes I'm placed next to. |
| 281 |
</div> |
| 282 |
</body> |
| 283 |
</html> |