| 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.popup and BackgroundIFrame unit test</title> |
| 12 |
<style type="text/css"> |
| 13 |
@import "../../themes/claro/document.css"; |
| 14 |
@import "../../themes/dijit.css"; |
| 15 |
@import "../css/dijitTests.css"; |
| 16 |
|
| 17 |
body { |
| 18 |
height: 100%; |
| 19 |
padding: 0; |
| 20 |
margin: 0; |
| 21 |
} |
| 22 |
|
| 23 |
div { |
| 24 |
background: white; |
| 25 |
border: solid 1px gray; |
| 26 |
} |
| 27 |
|
| 28 |
/* the menu type test widgets */ |
| 29 |
.choice div { |
| 30 |
width: 200px; |
| 31 |
cursor: pointer; |
| 32 |
} |
| 33 |
.choice div:hover { |
| 34 |
background: #ccc; |
| 35 |
} |
| 36 |
</style> |
| 37 |
<script type="text/javascript" src="../../../dojo/dojo.js" |
| 38 |
data-dojo-config="isDebug: true, parseOnLoad: false"></script> |
| 39 |
<script type="text/javascript" src="../_testCommon.js"></script> |
| 40 |
|
| 41 |
<script type="text/javascript"> |
| 42 |
dojo.require("doh.runner"); |
| 43 |
dojo.require("dijit._base.popup"); |
| 44 |
dojo.require("dijit._Widget"); |
| 45 |
dojo.require("dijit._TemplatedMixin"); |
| 46 |
dojo.require("dijit.tests.helpers"); // functions to help test |
| 47 |
|
| 48 |
function log(str){ |
| 49 |
console.log(str); |
| 50 |
} |
| 51 |
|
| 52 |
dojo.ready(function(){ |
| 53 |
|
| 54 |
dojo.declare("SimpleDropDownButton", [dijit._Widget, dijit._TemplatedMixin], { |
| 55 |
// summary: |
| 56 |
// A button that shows a popup. |
| 57 |
// Supply popup as parameter when instantiating this widget. |
| 58 |
|
| 59 |
label: "show popup", |
| 60 |
orient: {'BL': 'TL', 'BR': 'TR'}, |
| 61 |
|
| 62 |
templateString: "<button data-dojo-attach-event='onclick: openPopup'>${label}</button>", |
| 63 |
|
| 64 |
openPopup: function(){ |
| 65 |
var self = this; |
| 66 |
|
| 67 |
dijit.popup.open({ |
| 68 |
popup: this.popup, |
| 69 |
parent: this, |
| 70 |
around: this.domNode, |
| 71 |
orient: this.orient, |
| 72 |
onCancel: function(){ |
| 73 |
log(self.id + ": cancel of child"); |
| 74 |
}, |
| 75 |
onExecute: function(){ |
| 76 |
log(self.id + ": execute of child"); |
| 77 |
dijit.popup.close(self.popup); |
| 78 |
self.open = false; |
| 79 |
} |
| 80 |
}); |
| 81 |
|
| 82 |
this.open = true; |
| 83 |
}, |
| 84 |
|
| 85 |
closePopup: function(){ |
| 86 |
if(this.open){ |
| 87 |
log(this.id + ": close popup due to blur"); |
| 88 |
dijit.popup.close(this.popup); |
| 89 |
this.open = false; |
| 90 |
} |
| 91 |
}, |
| 92 |
|
| 93 |
_onBlur: function(){ |
| 94 |
// summary: |
| 95 |
// This is called from focus manager and when we get the signal we |
| 96 |
// need to close the drop down |
| 97 |
this.closePopup(); |
| 98 |
} |
| 99 |
}); |
| 100 |
|
| 101 |
dojo.declare("SimplePopup", [dijit._Widget, dijit._TemplatedMixin], { |
| 102 |
// summary: |
| 103 |
// A trivial popup widget |
| 104 |
|
| 105 |
templateString: "<span>i'm a popup</span>" |
| 106 |
}); |
| 107 |
|
| 108 |
dojo.declare("SimpleChoiceWidget", [dijit._Widget, dijit._TemplatedMixin], { |
| 109 |
// summary: |
| 110 |
// A list of values; select a value by pressing an entry in the list. |
| 111 |
|
| 112 |
choice1: "1", |
| 113 |
choice2: "2", |
| 114 |
choice3: "3", |
| 115 |
|
| 116 |
templateString: |
| 117 |
"<div class='choice'>" + |
| 118 |
"<div data-dojo-attach-event='onclick: onClick'>${choice1}</div>" + |
| 119 |
"<div data-dojo-attach-event='onclick: onClick'>${choice2}</div>" + |
| 120 |
"<div data-dojo-attach-event='onclick: onClick'>${choice3}</div>" + |
| 121 |
"</div>", |
| 122 |
|
| 123 |
onClick: function(e){ |
| 124 |
this.onChange(e.target.innerHTML); |
| 125 |
}, |
| 126 |
|
| 127 |
onChange: function(val){ |
| 128 |
// summary: |
| 129 |
// When this widget is used as a popup, dijit.popup monitors calls |
| 130 |
// to onChange and then closes the popup |
| 131 |
log(this.id + ": selected " + val); |
| 132 |
} |
| 133 |
}); |
| 134 |
|
| 135 |
// Create a button that displays a simple drop down |
| 136 |
choiceDropDown = new SimpleChoiceWidget(); |
| 137 |
(choiceDropDownButton = new SimpleDropDownButton({ |
| 138 |
id: "choiceDropDownButton", |
| 139 |
label: "show choice drop down", |
| 140 |
popup: choiceDropDown |
| 141 |
})).placeAt(dojo.byId("widgets")); |
| 142 |
|
| 143 |
dojo.declare("DialogWithPopupWidget", [dijit._Widget, dijit._TemplatedMixin], { |
| 144 |
// summary: |
| 145 |
// This is a dialog that contains a button that spawns a drop down. |
| 146 |
// Supply popup as an argument to this widget. |
| 147 |
|
| 148 |
title: "I'm a dialog", |
| 149 |
label: "click me", |
| 150 |
|
| 151 |
templateString: |
| 152 |
"<div style='width: 300px'>" + |
| 153 |
"<div>${title}</div>" + |
| 154 |
"<input><br>" + |
| 155 |
"<button data-dojo-attach-point='button'>${label}</button><br>" + |
| 156 |
"<button data-dojo-attach-event='onclick: onExecute'>OK</button>" + |
| 157 |
"</div>", |
| 158 |
|
| 159 |
postCreate: function(){ |
| 160 |
// Convert the plain button into a SimpleDropDownButton widget. |
| 161 |
// Having it be a widget is important because that's how the popup |
| 162 |
// code knows where a stack of nested popups (typically menus) ends. |
| 163 |
// (In this case closing a stack of menus shouldn't close the dialog.) |
| 164 |
|
| 165 |
new SimpleDropDownButton({ |
| 166 |
id: this.id + "PopupButton", |
| 167 |
label: this.label, |
| 168 |
popup: this.popup, |
| 169 |
orient: {'BR': 'BL', 'TR': 'tL'} // so popup doesn't cover OK button |
| 170 |
}, this.button); |
| 171 |
}, |
| 172 |
|
| 173 |
onExecute: function(){ |
| 174 |
// summary: |
| 175 |
// Called when OK button is pressed. |
| 176 |
// If this is used as a popup this signals to the parent that |
| 177 |
// Dialog can be closed. |
| 178 |
console.log(this.id + ": executed"); |
| 179 |
} |
| 180 |
}); |
| 181 |
|
| 182 |
// Create a button that displays a dialog that displays a choice widget |
| 183 |
dialogDropDownButton = new SimpleDropDownButton({ |
| 184 |
id: "showSimpleDialogButton", |
| 185 |
label: "show dialog", |
| 186 |
popup: new DialogWithPopupWidget({ |
| 187 |
id: "simpleDialog", |
| 188 |
label: 'show simple choice drop down', |
| 189 |
popup: new SimpleChoiceWidget({ |
| 190 |
id: "choiceFromDialog" |
| 191 |
}) |
| 192 |
}) |
| 193 |
}).placeAt(dojo.byId("widgets")); |
| 194 |
|
| 195 |
dojo.declare("NestedPopupOpener", [dijit._Widget, dijit._TemplatedMixin], { |
| 196 |
// summary: |
| 197 |
// Clicking a value in this list will open a nested popup. |
| 198 |
// Specify popup1 and popup2 as parameters to this widget. |
| 199 |
|
| 200 |
templateString: |
| 201 |
"<div class='choice'>" + |
| 202 |
"<div data-dojo-attach-event='onclick: onClick'>popup1</div>" + |
| 203 |
"<div data-dojo-attach-event='onclick: onClick'>popup2</div>" + |
| 204 |
"</div>", |
| 205 |
|
| 206 |
onClick: function(e){ |
| 207 |
var id = this.id, |
| 208 |
popup = this[e.target.innerHTML]; |
| 209 |
log(id + ": opening popup " + popup.id); |
| 210 |
this.openPopup(popup); |
| 211 |
}, |
| 212 |
|
| 213 |
openPopup: function(popup){ |
| 214 |
dijit.popup.open({ |
| 215 |
popup: popup, |
| 216 |
parent: this, |
| 217 |
around: this.domNode, |
| 218 |
orient: {'TR': 'TL', 'TL': 'TR'}, |
| 219 |
onCancel: function(){ |
| 220 |
log(id + ": cancel of child " + popup.id); |
| 221 |
}, |
| 222 |
onExecute: function(){ |
| 223 |
log(id + ": execute of child " + popup.id); |
| 224 |
dijit.popup.close(popup); |
| 225 |
} |
| 226 |
}) |
| 227 |
}, |
| 228 |
|
| 229 |
closePopup: function(popup){ |
| 230 |
dijit.popup.close(popup); |
| 231 |
} |
| 232 |
}); |
| 233 |
|
| 234 |
// Create a button that displays a nested drop down. |
| 235 |
nestedOpener = new NestedPopupOpener({ |
| 236 |
id: 'nestedPopupOpener', |
| 237 |
popup1: (nestedChoice1 = new SimpleChoiceWidget({ |
| 238 |
id: "nestedChoice1" |
| 239 |
})), |
| 240 |
popup2: (nestedChoice2 = new SimpleChoiceWidget({ |
| 241 |
id: "nestedChoice2", |
| 242 |
choice1: "4", |
| 243 |
choice2: "5", |
| 244 |
choice3: "6" |
| 245 |
})) |
| 246 |
}); |
| 247 |
nestedDropDownButton = new SimpleDropDownButton({ |
| 248 |
id: "showNestedMenuButton", |
| 249 |
label: "show nested drop down", |
| 250 |
popup: nestedOpener |
| 251 |
}).placeAt(dojo.byId("widgets")); |
| 252 |
|
| 253 |
// Create a button that displays a dialog that displays a nested drop down |
| 254 |
dialogNestedChoice1 = new SimpleChoiceWidget({ |
| 255 |
id: "dialogNestedChoice1" |
| 256 |
}); |
| 257 |
dialogNestedChoice2 = new SimpleChoiceWidget({ |
| 258 |
id: "dialogNestedChoice2", |
| 259 |
choice1: "4", |
| 260 |
choice2: "5", |
| 261 |
choice3: "6" |
| 262 |
}); |
| 263 |
dialogNestedPopupOpener = new NestedPopupOpener({ |
| 264 |
id: "nestedPopupOpenerFromDialog", |
| 265 |
popup1: dialogNestedChoice1, |
| 266 |
popup2: dialogNestedChoice2 |
| 267 |
}); |
| 268 |
dialogWithNestedPopup = new DialogWithPopupWidget({ |
| 269 |
id: "buttonInComplexDialog", |
| 270 |
label: 'show nested menu', |
| 271 |
popup: dialogNestedPopupOpener |
| 272 |
}); |
| 273 |
dialogDropDownButton = new SimpleDropDownButton({ |
| 274 |
id: "showComplexDialogButton", |
| 275 |
label: "show dialog w/nested menu", |
| 276 |
popup: dialogWithNestedPopup |
| 277 |
}).placeAt(dojo.byId("widgets")); |
| 278 |
|
| 279 |
// For testing, create an unattached widget and unattached DOMNode |
| 280 |
new SimplePopup({id: "spw"}).placeAt(dojo.body()); |
| 281 |
dojo.place("<span id='sdn'>simple dom node</span>", dojo.body()); |
| 282 |
|
| 283 |
doh.register("API", [ |
| 284 |
function repeatMoveOffScreen(){ |
| 285 |
// Previously, calling moveOffScreen twice would cause an exception |
| 286 |
dijit.popup.moveOffScreen(dijit.byId("spw")); |
| 287 |
dijit.popup.moveOffScreen(dijit.byId("spw")); |
| 288 |
|
| 289 |
// Deprecated API where moveOffScreen() takes a DOMNode |
| 290 |
dijit.popup.moveOffScreen(dojo.byId("sdn")); |
| 291 |
dijit.popup.moveOffScreen(dojo.byId("sdn")); |
| 292 |
} |
| 293 |
]); |
| 294 |
|
| 295 |
doh.register("simple open and close", [ |
| 296 |
function initialConditions(t){ |
| 297 |
// If the popup code has cached any iframes, make sure they are hidden |
| 298 |
dojo.query("iframe").forEach(function(node){ |
| 299 |
console.log("found iframe", node); |
| 300 |
doh.is("none", node.style.display, "background iframe is hidden"); |
| 301 |
}); |
| 302 |
}, |
| 303 |
|
| 304 |
// Create popup on the edge of another widget |
| 305 |
function openAround(){ |
| 306 |
var d = new doh.Deferred(); |
| 307 |
|
| 308 |
var around = dojo.global.choiceDropDownButton, |
| 309 |
popup = dojo.global.choiceDropDown; |
| 310 |
|
| 311 |
around.openPopup(); |
| 312 |
|
| 313 |
setTimeout(d.getTestCallback(function(){ |
| 314 |
doh.t(isVisible(popup.domNode), "popup is visible"); |
| 315 |
|
| 316 |
if(dojo.isIE <= 6){ |
| 317 |
// Test the BackgroundIFrame |
| 318 |
var iframes = dojo.query("iframe"); |
| 319 |
doh.is(1, iframes.length, "one background iframe on IE6"); |
| 320 |
|
| 321 |
var popupCoords = dojo.position(popup.domNode), |
| 322 |
iframeCoords = dojo.position(iframes[0]); |
| 323 |
doh.is(popupCoords.x, iframeCoords.x, "x is same: " + popupCoords.x); |
| 324 |
doh.is(popupCoords.y, iframeCoords.y, "y is same: " + popupCoords.y); |
| 325 |
doh.is(popupCoords.w, iframeCoords.w, "w is same: " + popupCoords.w); |
| 326 |
doh.is(popupCoords.h, iframeCoords.h, "h is same: " + popupCoords.h); |
| 327 |
doh.is("", iframes[0].style.display, "not display:none"); |
| 328 |
} |
| 329 |
// TODO: test stack |
| 330 |
}), 500); |
| 331 |
|
| 332 |
return d; |
| 333 |
}, |
| 334 |
|
| 335 |
function closeAround(){ |
| 336 |
// Close the popup |
| 337 |
var around = dojo.global.choiceDropDownButton, |
| 338 |
popup = dojo.global.choiceDropDown; |
| 339 |
|
| 340 |
around.closePopup(); |
| 341 |
|
| 342 |
// Make sure the popup is hidden |
| 343 |
doh.is("none", popup.domNode.parentNode.style.display, "popup is hidden"); |
| 344 |
} |
| 345 |
]); |
| 346 |
|
| 347 |
doh.register("nested open and close", [ |
| 348 |
// Open first level |
| 349 |
function openAround(){ |
| 350 |
var d = new doh.Deferred(); |
| 351 |
|
| 352 |
var around = dojo.global.nestedDropDownButton, |
| 353 |
popup = dojo.global.nestedOpener, |
| 354 |
nestedPopup = dojo.global.nestedChoice1; |
| 355 |
|
| 356 |
around.openPopup(); |
| 357 |
|
| 358 |
setTimeout(d.getTestCallback(function(){ |
| 359 |
doh.t(isVisible(popup.domNode), "popup is visible"); |
| 360 |
|
| 361 |
if(dojo.isIE <= 6){ |
| 362 |
// Test the BackgroundIFrame |
| 363 |
var iframes = dojo.query("iframe", popup.domNode.parentNode); |
| 364 |
doh.is(1, iframes.length, "one background iframe on IE6"); |
| 365 |
|
| 366 |
var popupCoords = dojo.position(popup.domNode), |
| 367 |
iframeCoords = dojo.position(iframes[0]); |
| 368 |
doh.is(popupCoords.x, iframeCoords.x, "x is same: " + popupCoords.x); |
| 369 |
doh.is(popupCoords.y, iframeCoords.y, "y is same: " + popupCoords.y); |
| 370 |
doh.is(popupCoords.w, iframeCoords.w, "w is same: " + popupCoords.w); |
| 371 |
doh.is(popupCoords.h, iframeCoords.h, "h is same: " + popupCoords.h); |
| 372 |
doh.is("", iframes[0].style.display, "not display:none"); |
| 373 |
} |
| 374 |
// TODO: test stack |
| 375 |
}), 500); |
| 376 |
|
| 377 |
return d; |
| 378 |
}, |
| 379 |
|
| 380 |
function openNested(){ |
| 381 |
var d = new doh.Deferred(); |
| 382 |
|
| 383 |
var around = dojo.global.nestedDropDownButton, |
| 384 |
popup = dojo.global.nestedOpener, |
| 385 |
nestedPopup = dojo.global.nestedChoice1; |
| 386 |
|
| 387 |
popup.openPopup(nestedPopup); |
| 388 |
|
| 389 |
setTimeout(d.getTestCallback(function(){ |
| 390 |
doh.t(isVisible(nestedPopup.domNode), "nested popup is visible"); |
| 391 |
|
| 392 |
if(dojo.isIE <= 6){ |
| 393 |
// Test the BackgroundIFrame |
| 394 |
var iframes = dojo.query("iframe", popup.domNode.parentNode); |
| 395 |
doh.is(1, iframes.length, "one background iframe for popup"); |
| 396 |
|
| 397 |
iframes = dojo.query("iframe", nestedPopup.domNode.parentNode); |
| 398 |
doh.is(1, iframes.length, "another background iframe for nested popup"); |
| 399 |
|
| 400 |
var popupCoords = dojo.position(nestedPopup.domNode), |
| 401 |
iframeCoords = dojo.position(iframes[0]); |
| 402 |
doh.is(popupCoords.x, iframeCoords.x, "x is same: " + popupCoords.x); |
| 403 |
doh.is(popupCoords.y, iframeCoords.y, "y is same: " + popupCoords.y); |
| 404 |
doh.is(popupCoords.w, iframeCoords.w, "w is same: " + popupCoords.w); |
| 405 |
doh.is(popupCoords.h, iframeCoords.h, "h is same: " + popupCoords.h); |
| 406 |
doh.is("", iframes[0].style.display, "not display:none"); |
| 407 |
} |
| 408 |
// TODO: test stack |
| 409 |
}), 500); |
| 410 |
|
| 411 |
return d; |
| 412 |
}, |
| 413 |
|
| 414 |
function closeAround(){ |
| 415 |
// Close the layer of popups |
| 416 |
var around = dojo.global.nestedDropDownButton, |
| 417 |
popup = dojo.global.nestedOpener, |
| 418 |
nestedPopup = dojo.global.nestedChoice1; |
| 419 |
|
| 420 |
around.closePopup(); |
| 421 |
|
| 422 |
// Make sure the popups are both hidden |
| 423 |
// (in a future release this might change to display:none etc but currently it's visibility:hidden) |
| 424 |
doh.is("none", popup.domNode.parentNode.style.display, "popup is hidden"); |
| 425 |
doh.is("none", nestedPopup.domNode.parentNode.style.display, "nested popup is hidden"); |
| 426 |
} |
| 427 |
]); |
| 428 |
|
| 429 |
// Make sure there are no hidden tab stops when popups are closed. |
| 430 |
// This test doesn't work on safari (due to safari bugs) although there aren't any hidden tab stops. |
| 431 |
doh.register("no hidden tab stops", function hiddenTabStops(){ |
| 432 |
var tabbable = tabOrder(); |
| 433 |
doh.is("inputAtStart", tabbable[0].id, "first tabbable node"); |
| 434 |
doh.is("inputAtEnd", tabbable[tabbable.length - 1].id, "last tabbable node"); |
| 435 |
}); |
| 436 |
|
| 437 |
// TODO: test x/y placement |
| 438 |
|
| 439 |
// Test that onCancel goes back one level. |
| 440 |
// Call nestedChoice2.onCancel() and that should trigger nestedChoice2 to close |
| 441 |
// but nestedOpener stays open. |
| 442 |
// (TODO) |
| 443 |
|
| 444 |
// Test that onChange/onExecute goes back to top of popup chain. |
| 445 |
// Call dialogNestedChoice2.onChange() and that should trigger dialogNestedChoice2 |
| 446 |
// and dialogNestedPopupOpener to close, but not dialogWithNestedPopup. |
| 447 |
// (TODO) |
| 448 |
|
| 449 |
// --------------------- |
| 450 |
// a11y tests |
| 451 |
|
| 452 |
// Test that ESC key closes one level of a popup chain. |
| 453 |
// Focus nestedChoice2 and type ESC, and that should trigger nestedChoice2 to close |
| 454 |
// but nestedOpener stays open. |
| 455 |
// (TODO) |
| 456 |
|
| 457 |
// Test that TAB key cancels back to top of popup chain. |
| 458 |
// Focus nestedChoice2 and type TAB, and that should trigger dialogNestedChoice2 |
| 459 |
// and dialogNestedPopupOpener to close, but not dialogWithNestedPopup. |
| 460 |
// (TODO) |
| 461 |
|
| 462 |
doh.run(); |
| 463 |
}); |
| 464 |
</script> |
| 465 |
</head> |
| 466 |
<body> |
| 467 |
<h1>dijit.popup and BackgroundIFrame Unit Test</h1> |
| 468 |
<input id="inputAtStart"> |
| 469 |
<span id="widgets"></span> |
| 470 |
<input id="inputAtEnd"> |
| 471 |
</body> |
| 472 |
</html> |