| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/> |
| 5 |
<title>WidgetsInTemplateMixin.js</title> |
| 6 |
|
| 7 |
<style type="text/css"> |
| 8 |
/* Make our tests stand out as easily identifiable content */ |
| 9 |
.testcontainer { |
| 10 |
border: 10px yellow; |
| 11 |
border-style: dashed; |
| 12 |
padding: 1em; |
| 13 |
margin: 1em; |
| 14 |
} |
| 15 |
.testcontainer > p { |
| 16 |
padding: 0 1em; |
| 17 |
font-weight: bold; |
| 18 |
} |
| 19 |
</style> |
| 20 |
|
| 21 |
<script type="text/javascript" src="boilerplate.js"></script> |
| 22 |
<script type="text/javascript"> |
| 23 |
require([ |
| 24 |
"doh", "dojo/_base/array", "dojo/_base/declare", "dojo/_base/window", "dojo/dom", "dojo/dom-geometry", |
| 25 |
"dojo/html", "dojo/on", "dojo/query", "dojo/parser", |
| 26 |
"dijit/registry", "dijit/_WidgetBase", "dijit/_Widget", |
| 27 |
"dijit/_AttachMixin", "dijit/_TemplatedMixin", "dijit/_WidgetsInTemplateMixin", |
| 28 |
"dijit/form/Button", "dijit/form/CheckBox", "dijit/form/TextBox", |
| 29 |
"dijit/ProgressBar", "dijit/_Container", "dijit/_Contained", |
| 30 |
"dijit/layout/ContentPane", "dijit/layout/_LayoutWidget", "dijit/layout/LayoutContainer", |
| 31 |
"dijit/tests/resources/TestContextRequireWidget", |
| 32 |
"dojo/domReady!" |
| 33 |
], function(doh, array, declare, win, dom, domGeom, html, on, query, parser, |
| 34 |
registry, _WidgetBase, _Widget, _AttachMixin, _TemplatedMixin, _WidgetsInTemplateMixin, |
| 35 |
Button, CheckBox, TextBox, ProgressBar, _Container, _Contained, _LayoutWidget, LayoutContainer){ |
| 36 |
|
| 37 |
declare('Test1Widget', [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], { |
| 38 |
templateString: dom.byId('Test1Template').value, |
| 39 |
onClick: function(e){ |
| 40 |
if(e.target){ |
| 41 |
alert('onClick widgetId='+e.target.id); |
| 42 |
}else{ |
| 43 |
if(e._counter == undefined){ |
| 44 |
e._counter = 1; |
| 45 |
}else{ |
| 46 |
e._counter++; |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
}); |
| 51 |
|
| 52 |
declare('Test3Widget', [_Widget, _TemplatedMixin, _WidgetsInTemplateMixin], { |
| 53 |
templateString: dom.byId('Test3Template').value |
| 54 |
}); |
| 55 |
|
| 56 |
declare('TestLayoutWidget', _LayoutWidget, { |
| 57 |
startup: function(){ |
| 58 |
if(this._started){ |
| 59 |
this._doubleStarted = true; |
| 60 |
} |
| 61 |
this.inherited(arguments); |
| 62 |
}, |
| 63 |
destroy: function(){ |
| 64 |
if(this._destroyed){ |
| 65 |
this._doubleDestroyed = true; |
| 66 |
} |
| 67 |
this.inherited(arguments); |
| 68 |
this._destroyed = true; |
| 69 |
} |
| 70 |
}); |
| 71 |
|
| 72 |
declare('TestCtnrWidget', [_WidgetBase, _Container], { |
| 73 |
startup: function(){ |
| 74 |
if(this._started){ |
| 75 |
this._doubleStarted = true; |
| 76 |
} |
| 77 |
this.inherited(arguments); |
| 78 |
}, |
| 79 |
destroy: function(){ |
| 80 |
if(this._destroyed){ |
| 81 |
this._doubleDestroyed = true; |
| 82 |
} |
| 83 |
this.inherited(arguments); |
| 84 |
this._destroyed = true; |
| 85 |
} |
| 86 |
}); |
| 87 |
|
| 88 |
declare('TestCtndWidget', [_WidgetBase, _Contained], { |
| 89 |
startup: function(){ |
| 90 |
if(this._started){ |
| 91 |
this._doubleStarted = true; |
| 92 |
} |
| 93 |
this.inherited(arguments); |
| 94 |
}, |
| 95 |
destroy: function(){ |
| 96 |
if(this._destroyed){ |
| 97 |
this._doubleDestroyed = true; |
| 98 |
} |
| 99 |
this.inherited(arguments); |
| 100 |
this._destroyed = true; |
| 101 |
} |
| 102 |
}); |
| 103 |
|
| 104 |
declare('TestNonCtnrWidget', [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], { |
| 105 |
templateString: "<div data-dojo-attach-point=containerNode></div>", |
| 106 |
startup: function(){ |
| 107 |
if(this._started){ |
| 108 |
this._doubleStarted = true; |
| 109 |
} |
| 110 |
this.inherited(arguments); |
| 111 |
}, |
| 112 |
destroy: function(){ |
| 113 |
if(this._destroyed){ |
| 114 |
this._doubleDestroyed = true; |
| 115 |
} |
| 116 |
this.inherited(arguments); |
| 117 |
this._destroyed = true; |
| 118 |
} |
| 119 |
}); |
| 120 |
|
| 121 |
declare('TestStubWidget', _WidgetBase, { |
| 122 |
startup: function(){ |
| 123 |
if(this._started){ |
| 124 |
this._doubleStarted = true; |
| 125 |
} |
| 126 |
this.inherited(arguments); |
| 127 |
}, |
| 128 |
destroy: function(){ |
| 129 |
if(this._destroyed){ |
| 130 |
this._doubleDestroyed = true; |
| 131 |
} |
| 132 |
this.inherited(arguments); |
| 133 |
this._destroyed = true; |
| 134 |
} |
| 135 |
}); |
| 136 |
|
| 137 |
declare('Test5Widget', |
| 138 |
[_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], |
| 139 |
{ |
| 140 |
templateString: dom.byId('Test5Template').value, |
| 141 |
startup: function(){ |
| 142 |
if(this._started){ |
| 143 |
this._doubleStarted = true; |
| 144 |
} |
| 145 |
this.inherited(arguments); |
| 146 |
}, |
| 147 |
destroy: function(){ |
| 148 |
if(this._destroyed){ |
| 149 |
this._doubleDestroyed = true; |
| 150 |
} |
| 151 |
this.inherited(arguments); |
| 152 |
this._destroyed = true; |
| 153 |
} |
| 154 |
}); |
| 155 |
|
| 156 |
declare('Test6Widget', [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], { |
| 157 |
templateString: dom.byId('Test6Template').value, |
| 158 |
clickCount: 0, |
| 159 |
handleClick: function(){ |
| 160 |
this.clickCount++; |
| 161 |
} |
| 162 |
}); |
| 163 |
|
| 164 |
declare("Missing", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], { |
| 165 |
templateString: '<div>' + |
| 166 |
'<div data-dojo-type="dijit/layout/ContentPane">' + |
| 167 |
'<div data-dojo-type="dijit/form/Button" data-dojo-props="id: \'missingButtonId\'" ' + |
| 168 |
'data-dojo-attach-point="missingButton">Missing...</div>' + |
| 169 |
'</div>' + |
| 170 |
'</div>' |
| 171 |
}); |
| 172 |
|
| 173 |
function getTest5WidgetsInTemplate(testW){ |
| 174 |
// summary: |
| 175 |
// Returns all the widgets in the template for a Test5Widget |
| 176 |
return [ |
| 177 |
testW, |
| 178 |
testW.layout, |
| 179 |
testW.layChild1, |
| 180 |
testW.layChild2, |
| 181 |
testW.container, |
| 182 |
testW.contained1, |
| 183 |
testW.contained2, |
| 184 |
testW.nonContainer, |
| 185 |
testW.nonContained1, |
| 186 |
testW.nonContained2, |
| 187 |
testW.threeLevel, |
| 188 |
testW.secondLevel, |
| 189 |
testW.bottomLevel, |
| 190 |
testW.anotherThree, |
| 191 |
testW.anotherSecond, |
| 192 |
testW.anotherBottom, |
| 193 |
testW.stub1 |
| 194 |
]; |
| 195 |
} |
| 196 |
|
| 197 |
function validateTest5Widget(/*Test5Widget*/ testW, /*Boolean*/ started){ |
| 198 |
// Check that testW widget, and all the widgets in it's template, got started, but not double-started |
| 199 |
array.forEach(getTest5WidgetsInTemplate(testW), function(w){ |
| 200 |
if(started){ |
| 201 |
doh.t(w._started, w + " should be started"); |
| 202 |
}else{ |
| 203 |
doh.f(w._started, w + " should not be started"); |
| 204 |
} |
| 205 |
doh.is(undefined, w._doubleStarted, "w._doubleStarted: " + w); |
| 206 |
}); |
| 207 |
} |
| 208 |
|
| 209 |
function validateTest5WidgetDestroy(t, testW){ |
| 210 |
var savedWidgets = getTest5WidgetsInTemplate(testW); |
| 211 |
testW.destroy(); |
| 212 |
array.forEach(savedWidgets, function(w, idx){ |
| 213 |
doh.t(w._destroyed, "w._destroyed: " + w); |
| 214 |
doh.is(undefined, w._doubleDestroyed, "w._doubleDestroyed: " + w); |
| 215 |
}); |
| 216 |
} |
| 217 |
|
| 218 |
doh.register("_AttachMixin-widgetInTemplate", [ |
| 219 |
function createAttachWidgetsCombo() { |
| 220 |
/*** TEST _AttachMixin combined with _WidgetsInTemplateMixin ***/ |
| 221 |
var AttachWidgetsCombo = declare([ _WidgetBase, _AttachMixin, _WidgetsInTemplateMixin ], { |
| 222 |
|
| 223 |
postCreate: function() { |
| 224 |
html.set(this.heading, "Amazing things will happen if you click this button!!!"); |
| 225 |
}, |
| 226 |
_buttonClicked: function(e) { |
| 227 |
html.set(this.heading, "Well that was boring. " + |
| 228 |
"My attach point button thinks it is a " + (this.mybutton.isInstanceOf(Button) ? 'dijit/form/Button':'Gruffalo')); |
| 229 |
} |
| 230 |
}); |
| 231 |
|
| 232 |
var myawc = new AttachWidgetsCombo({}, dom.byId('attachMeThree')); |
| 233 |
|
| 234 |
doh.t(myawc.heading, "heading"); |
| 235 |
doh.t(myawc.mybutton, "mybutton"); |
| 236 |
doh.is("Amazing things will happen if you click this button!!!", myawc.heading.innerHTML, "Initial value"); |
| 237 |
|
| 238 |
// Simulate clicking the button. Don't use click() because it's not supported on a <span> |
| 239 |
// in Android < 4.4. |
| 240 |
on.emit(myawc.mybutton.focusNode, "click", { |
| 241 |
bubbles: true, |
| 242 |
cancelable: true |
| 243 |
}); |
| 244 |
|
| 245 |
doh.is("Well that was boring. My attach point button thinks it is a dijit/form/Button", myawc.heading.innerHTML, "Post-op value"); |
| 246 |
}, |
| 247 |
|
| 248 |
function containerNode(){ |
| 249 |
// Test that widgets inside of containerNode aren't parsed by _WidgetsInTemplateMixin |
| 250 |
|
| 251 |
declare("OuterWidget", [ _WidgetBase, _AttachMixin, _WidgetsInTemplateMixin ], { |
| 252 |
// Prevent the main parser call from hitting my supporting widgets. |
| 253 |
// But this also stops the parser from hitting anything inside my containerNode, so I need |
| 254 |
// to do a recursive parse() like ContentPane does (or just extend ContentPane) |
| 255 |
stopParser: true, |
| 256 |
|
| 257 |
postCreate: function(){ |
| 258 |
doh.is(0, this.getChildren().length, "contained widget not created yet"); |
| 259 |
parser.parse(this.containerNode); |
| 260 |
} |
| 261 |
}); |
| 262 |
declare("SupportingWidget", _WidgetBase); |
| 263 |
declare("ContainedWidget", _WidgetBase); |
| 264 |
parser.parse(dom.byId("containerNode")); |
| 265 |
|
| 266 |
doh.t("outerWidget" in window, "outer widget created"); |
| 267 |
doh.t(outerWidget.supportingWidget, "supporting widget instantiated"); |
| 268 |
doh.f(outerWidget.containedWidget, "contained widget not instantiated by _WidgetsInTemplateMixin parse call"); |
| 269 |
|
| 270 |
doh.is(1, outerWidget.getChildren().length, "contained widget created too"); |
| 271 |
} |
| 272 |
]); |
| 273 |
|
| 274 |
doh.register("_Templated-widgetsInTemplate", [ |
| 275 |
function parse(){ |
| 276 |
parser.parse("templateTests"); |
| 277 |
}, |
| 278 |
{ |
| 279 |
name: "data-dojo-attach-point", |
| 280 |
runTest: function(t){ |
| 281 |
var testW = registry.byId("test1Widget"); |
| 282 |
doh.t(testW, "test1Widget was instantiated"); |
| 283 |
doh.t(testW.normalNode, "normalNode"); |
| 284 |
doh.f(isNaN(testW.normalNode.nodeType), "normalNode.nodeType"); |
| 285 |
doh.t(testW.buttonWidget instanceof Button, "buttonWidget is Button"); |
| 286 |
doh.t(testW.checkboxWidget instanceof CheckBox, "checkboxWidget is CheckBox"); |
| 287 |
doh.t(testW.progressBarWidget instanceof ProgressBar, "progressBarWidget is ProgressBar"); |
| 288 |
} |
| 289 |
}, |
| 290 |
{ |
| 291 |
name: "data-dojo-attach-event", |
| 292 |
runTest: function(t){ |
| 293 |
var testW = registry.byId("test1Widget"); |
| 294 |
testW.buttonWidget._counter=0; |
| 295 |
testW.buttonWidget.onClick(testW.buttonWidget); |
| 296 |
testW.checkboxWidget._counter=0; |
| 297 |
testW.checkboxWidget.onClick(testW.checkboxWidget); |
| 298 |
testW.progressBarWidget._counter=0; |
| 299 |
testW.progressBarWidget.onChange(testW.progressBarWidget); |
| 300 |
doh.is(1,testW.buttonWidget._counter, "buttonWidget._counter"); |
| 301 |
doh.is(1,testW.checkboxWidget._counter, "checkboxWidget._counter"); |
| 302 |
doh.is(1,testW.progressBarWidget._counter, "progressBarWidget._counter"); |
| 303 |
} |
| 304 |
}, |
| 305 |
{ |
| 306 |
name: "data-dojo-attach-event strange name", |
| 307 |
runTest: function(t){ |
| 308 |
// This is for testing data-dojo-attach-event to attach to a method in the widget, |
| 309 |
// rather than using _WidgetBase.on(...). Remove for 2.0. |
| 310 |
var SubWidget = declare("SubWidget", _WidgetBase, { |
| 311 |
f: function(){ |
| 312 |
// just for attaching to |
| 313 |
} |
| 314 |
}); |
| 315 |
var MainWidget = declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], { |
| 316 |
templateString: |
| 317 |
'<div>' + |
| 318 |
'<div data-dojo-type="SubWidget" data-dojo-attach-point="sw" ' + |
| 319 |
' data-dojo-attach-event="f: g">' + |
| 320 |
'</div>', |
| 321 |
g: function(){ |
| 322 |
this.gWasCalled = true; |
| 323 |
} |
| 324 |
}); |
| 325 |
var mw = new MainWidget(); |
| 326 |
doh.t(mw.sw, "attach-point exists"); |
| 327 |
mw.sw.f(); |
| 328 |
doh.t(mw.gWasCalled, "attach-event worked"); |
| 329 |
} |
| 330 |
}, |
| 331 |
{ |
| 332 |
// Test that getDescendants () |
| 333 |
// finds direct descendants but skips widgetsInTemplates |
| 334 |
// and also nested widgets (if direct==true) |
| 335 |
name: "getChildren", |
| 336 |
runTest: function(t){ |
| 337 |
var testW = registry.byId("test3Widget"); |
| 338 |
|
| 339 |
/*** performance tests |
| 340 |
var start = new Date(); |
| 341 |
for(var i=0; i<1000; i++) |
| 342 |
testW.getChildren(); |
| 343 |
console.log("*** time for getChildren(): " + (new Date()-start)); |
| 344 |
var start = new Date(); |
| 345 |
for(var i=0; i<1000; i++) |
| 346 |
testW.getDescendants(); |
| 347 |
console.log("*** time for getDescendants(false): " + (new Date()-start)); |
| 348 |
***/ |
| 349 |
var chil = testW.getChildren(); |
| 350 |
doh.is(5, chil.length, "number of direct descendants"); |
| 351 |
doh.is(chil[0].id, "3.1"); |
| 352 |
doh.is(chil[1].id, "3.2"); |
| 353 |
doh.is(chil[2].id, "3.3"); |
| 354 |
doh.is(chil[3].id, "3.4"); |
| 355 |
doh.is(chil[4].id, "3.5"); |
| 356 |
|
| 357 |
// remove this test for 2.0 |
| 358 |
var desc = testW.getDescendants(); |
| 359 |
doh.is(7, desc.length, "number of descendants (including nested ones)"); |
| 360 |
doh.is(desc[0].id, "3.1"); |
| 361 |
doh.is(desc[1].id, "3.2"); |
| 362 |
doh.is(desc[2].id, "3.3"); |
| 363 |
doh.is(desc[3].id, "3.nested"); |
| 364 |
doh.is(desc[4].id, "3.nested2"); |
| 365 |
doh.is(desc[5].id, "3.4"); |
| 366 |
doh.is(desc[6].id, "3.5"); |
| 367 |
} |
| 368 |
}, |
| 369 |
{ |
| 370 |
// Check that declarative widget with other widgets in template is correctly started |
| 371 |
name: "declarative widget with many child widgets", |
| 372 |
runTest: function(t){ |
| 373 |
validateTest5Widget(registry.byId("test5Widget"), true); |
| 374 |
} |
| 375 |
}, |
| 376 |
{ |
| 377 |
// Check that programmatic widget with other widgets in template is correctly started |
| 378 |
name: "programmatic widget with many child widgets", |
| 379 |
runTest: function(t){ |
| 380 |
// Create widget. Widgets in template should not be started yet. |
| 381 |
test5WidgetProgrammatic = new Test5Widget(); |
| 382 |
validateTest5Widget(test5WidgetProgrammatic, false); |
| 383 |
|
| 384 |
// Place widget in DOM and startup. Widgets in template should now be started. |
| 385 |
test5WidgetProgrammatic.placeAt("test5Widget", "after"); |
| 386 |
test5WidgetProgrammatic.startup(); |
| 387 |
validateTest5Widget(test5WidgetProgrammatic, true); |
| 388 |
} |
| 389 |
}, |
| 390 |
{ |
| 391 |
// Check that destroying our declarative widget works correctly |
| 392 |
name: "declarative widget destruction", |
| 393 |
runTest: function(t){ |
| 394 |
validateTest5WidgetDestroy(t, registry.byId("test5Widget")); |
| 395 |
} |
| 396 |
}, |
| 397 |
{ |
| 398 |
// Check that destroying our programmatic widget works correctly |
| 399 |
name: "programmatic widget destruction", |
| 400 |
runTest: function(t){ |
| 401 |
validateTest5WidgetDestroy(t, test5WidgetProgrammatic); |
| 402 |
} |
| 403 |
}, |
| 404 |
{ |
| 405 |
// Test that data-dojo-attach-point inside of a ContentPane (inside of a template) works |
| 406 |
name: "ContentPane", |
| 407 |
runTest: function(){ |
| 408 |
var testW = registry.byId("missing"); |
| 409 |
doh.t(testW, "widget was created"); |
| 410 |
doh.t(testW.missingButton, "data-dojo-attach-point created"); |
| 411 |
doh.is("dijit.form.Button", testW.missingButton.declaredClass, "and it's to a widget"); |
| 412 |
doh.t(registry.byId("missingButtonId"), "nested widget also registered by id"); |
| 413 |
} |
| 414 |
}, |
| 415 |
{ |
| 416 |
// Test that data-dojo-attach-event bindings work with widgets in template, when |
| 417 |
// binding to dijit/_Widget methods |
| 418 |
name: "_Widget Deferred Connect methods", |
| 419 |
runTest: function(){ |
| 420 |
var test6Widget = registry.byId("test6Widget"); |
| 421 |
doh.t(test6Widget.clickCount === 0, "click count was initially zero"); |
| 422 |
// Issue a 'click' event directly on the interior input of the TextBox |
| 423 |
test6Widget.textbox.textbox.click(); |
| 424 |
doh.t(test6Widget.clickCount === 1, "click count incremented properly"); |
| 425 |
} |
| 426 |
}, |
| 427 |
|
| 428 |
function widgetsInTemplateLifecycle(t){ |
| 429 |
|
| 430 |
var result = [], expected = [1, 1, 0, 2, 2, 3]; |
| 431 |
|
| 432 |
// widgetsInTemplateLifecycle |
| 433 |
declare("SubThing", _WidgetBase, { |
| 434 |
postCreate: function(){ |
| 435 |
this.inherited(arguments); |
| 436 |
result.push(1); |
| 437 |
}, |
| 438 |
startup: function(){ |
| 439 |
this.inherited(arguments); |
| 440 |
result.push(2); |
| 441 |
} |
| 442 |
}); |
| 443 |
|
| 444 |
declare("ParentThing", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], { |
| 445 |
templateString: "<div>" + |
| 446 |
"<span data-dojo-type='SubThing'>a</span>" + |
| 447 |
"<div data-dojo-type='dijit/layout/LayoutContainer'>" + |
| 448 |
"<span data-dojo-type='SubThing' data-dojo-props='region: \"center\"'>b</span>" + |
| 449 |
"</div>" + |
| 450 |
"</div>", |
| 451 |
postCreate: function(){ |
| 452 |
// children postcreate (x2) called before this postCreate |
| 453 |
this.inherited(arguments); |
| 454 |
result.push(0); |
| 455 |
}, |
| 456 |
startup: function(){ |
| 457 |
// then children startup (x2) then our startup |
| 458 |
// (we can call inherited after push(), and change the order) |
| 459 |
this.inherited(arguments); |
| 460 |
result.push(3); |
| 461 |
} |
| 462 |
}); |
| 463 |
|
| 464 |
new ParentThing().startup(); |
| 465 |
|
| 466 |
t.is(expected.length, result.length); |
| 467 |
array.forEach(expected, function(r){ |
| 468 |
t.is(r, result.shift()); |
| 469 |
}); |
| 470 |
|
| 471 |
} |
| 472 |
]); |
| 473 |
|
| 474 |
// Test that "this" referenced from data-dojo-props can refer to the hosting widget |
| 475 |
doh.register("data-dojo-props this", function(){ |
| 476 |
var host = declare([dijit._WidgetBase, dijit._TemplatedMixin, dijit._WidgetsInTemplateMixin], { |
| 477 |
obj: {hello: "world"}, |
| 478 |
templateString: |
| 479 |
"<div>" + |
| 480 |
"<div data-dojo-type='dijit/_WidgetBase' data-dojo-props='hostObj: this.obj'" + |
| 481 |
" data-dojo-attach-point='subWidget'></div>" + |
| 482 |
"</div>" |
| 483 |
}); |
| 484 |
|
| 485 |
var hostWidget = new host(), |
| 486 |
subWidget = hostWidget && hostWidget.subWidget; |
| 487 |
doh.isNot(undefined, hostWidget, "created host widget"); |
| 488 |
doh.isNot(undefined, subWidget, "created sub widget"); |
| 489 |
doh.isNot(undefined, subWidget.hostObj, "sub widget got hostObj defined"); |
| 490 |
doh.is("world", subWidget.hostObj.hello, "object is correct") |
| 491 |
}); |
| 492 |
|
| 493 |
// Test that a context require can be passed to the parser |
| 494 |
doh.register("context require", function(){ |
| 495 |
var cw = registry.byId("testContextWidget"); |
| 496 |
doh.is(typeof cw.fooNode, "object", "button created"); |
| 497 |
doh.is(cw.fooNode.fooNode.innerHTML, "TestWidget", "sub widget contains right properties"); |
| 498 |
}); |
| 499 |
|
| 500 |
doh.run(); |
| 501 |
}); |
| 502 |
</script> |
| 503 |
</head> |
| 504 |
<body> |
| 505 |
<h1>WidgetsInTemplateMixin</h1> |
| 506 |
|
| 507 |
|
| 508 |
<div class="testcontainer"> |
| 509 |
<p>This test shows that a _AttachMixin dijit with _WidgetsInTemplate properly attaches widgets from the template.<br> |
| 510 |
<div id="attachMeThree"> |
| 511 |
<h2 data-dojo-attach-point='heading'></h2> |
| 512 |
<button data-dojo-type='dijit/form/Button' |
| 513 |
data-dojo-attach-point='mybutton' |
| 514 |
data-dojo-attach-event='click: _buttonClicked'>A button</button> |
| 515 |
</div> |
| 516 |
</div> |
| 517 |
|
| 518 |
|
| 519 |
<div id="containerNode" class="testcontainer"> |
| 520 |
<p>This tests that nodes inside of data-dojo-attach-point="containerNode" are ignored<br> |
| 521 |
<div data-dojo-id="outerWidget" data-dojo-type="OuterWidget"> |
| 522 |
<h2 data-dojo-attach-point="heading">heading</h2> |
| 523 |
<div data-dojo-type="SupportingWidget" data-dojo-attach-point="supportingWidget">supporting widget</div> |
| 524 |
<div data-dojo-attach-point="containerNode"> |
| 525 |
<span data-dojo-type="ContainedWidget" data-dojo-attach-point="containedWidget">contained widget</span> |
| 526 |
</div> |
| 527 |
</div> |
| 528 |
</div> |
| 529 |
|
| 530 |
|
| 531 |
<div id="templateTests"> |
| 532 |
<textarea id="Test1Template" style="display:none;"> |
| 533 |
<div> |
| 534 |
<div data-dojo-attach-point="normalNode">normal node</div> |
| 535 |
<button data-dojo-attach-point="buttonWidget" data-dojo-attach-event="click:onClick" data-dojo-type="dijit/form/Button">button #1</button> |
| 536 |
<div data-dojo-attach-point="checkboxWidget" data-dojo-attach-event="click:onClick" data-dojo-type="dijit/form/CheckBox"></div> checkbox #1 |
| 537 |
<div data-dojo-attach-point="progressBarWidget" data-dojo-attach-event="change:onClick" |
| 538 |
data-dojo-type="dijit/ProgressBar" data-dojo-props='value: 20, maximum: 200, style: "width:400px;"'></div> |
| 539 |
</div> |
| 540 |
</textarea> |
| 541 |
|
| 542 |
<div data-dojo-type="Test1Widget" data-dojo-props="id: 'test1Widget'"></div> |
| 543 |
|
| 544 |
|
| 545 |
<textarea id="Test3Template" style="display:none;"> |
| 546 |
<div> |
| 547 |
<div data-dojo-attach-point="checkboxWidget" data-dojo-type="dijit/form/CheckBox"></div> checkbox #3 |
| 548 |
<div data-dojo-attach-point="containerNode"></div> |
| 549 |
</div> |
| 550 |
</textarea> |
| 551 |
|
| 552 |
<div data-dojo-type="Test3Widget" data-dojo-props="id: 'test3Widget'"> |
| 553 |
<span>hello world</span> |
| 554 |
<b style="border: 1px solid blue;">this is my |
| 555 |
<button data-dojo-type="dijit/form/Button" data-dojo-props="id: '3.1'">first button</button> |
| 556 |
</b> |
| 557 |
<button data-dojo-type="dijit/form/Button" data-dojo-props="id: '3.2'">another button</button> |
| 558 |
<i>and some more</i> |
| 559 |
<div style="border: 1px solid red;"> |
| 560 |
<div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="style: {border: '1px solid gray'}, id: '3.3'"> |
| 561 |
<button data-dojo-type="dijit/form/Button" data-dojo-props="id: '3.nested'">a nested button</button> |
| 562 |
<button data-dojo-type="dijit/form/Button" data-dojo-props="id: '3.nested2'">another nested button</button> |
| 563 |
</div> |
| 564 |
<button data-dojo-type="dijit/form/Button" data-dojo-props="id: '3.4'">yet another button</button> |
| 565 |
<button data-dojo-type="dijit/form/Button" data-dojo-props="id: '3.5'">yet yet another button</button> |
| 566 |
</div> |
| 567 |
</div> |
| 568 |
|
| 569 |
|
| 570 |
<textarea id="Test5Template" style="display:none;"> |
| 571 |
<div> |
| 572 |
<div data-dojo-type="TestLayoutWidget" data-dojo-attach-point="layout"> |
| 573 |
<div data-dojo-type="TestCtndWidget" data-dojo-attach-point="layChild1"></div> |
| 574 |
<div data-dojo-type="TestCtndWidget" data-dojo-attach-point="layChild2"></div> |
| 575 |
</div> |
| 576 |
<div data-dojo-type="TestCtnrWidget" data-dojo-attach-point="container"> |
| 577 |
<div data-dojo-type="TestCtndWidget" data-dojo-attach-point="contained1"></div> |
| 578 |
<div data-dojo-type="TestCtndWidget" data-dojo-attach-point="contained2"></div> |
| 579 |
</div> |
| 580 |
<div data-dojo-type="TestStubWidget" data-dojo-attach-point="stub1"></div> |
| 581 |
<div data-dojo-type="TestNonCtnrWidget" data-dojo-attach-point="nonContainer"> |
| 582 |
<div data-dojo-type="TestStubWidget" data-dojo-attach-point="nonContained1"></div> |
| 583 |
<div data-dojo-type="TestStubWidget" data-dojo-attach-point="nonContained2"></div> |
| 584 |
</div> |
| 585 |
<div data-dojo-type="TestCtnrWidget" data-dojo-attach-point="threeLevel"> |
| 586 |
<div data-dojo-type="TestNonCtnrWidget" data-dojo-attach-point="secondLevel"> |
| 587 |
<div data-dojo-type="TestStubWidget" data-dojo-attach-point="bottomLevel"></div> |
| 588 |
</div> |
| 589 |
</div> |
| 590 |
<div data-dojo-type="TestNonCtnrWidget" data-dojo-attach-point="anotherThree"> |
| 591 |
<div data-dojo-type="TestCtnrWidget" data-dojo-attach-point="anotherSecond"> |
| 592 |
<div data-dojo-type="TestCtndWidget" data-dojo-attach-point="anotherBottom"></div> |
| 593 |
</div> |
| 594 |
</div> |
| 595 |
</div> |
| 596 |
</textarea> |
| 597 |
|
| 598 |
<div data-dojo-type="Test5Widget" data-dojo-props="id: 'test5Widget'"></div> |
| 599 |
|
| 600 |
<div data-dojo-type="Missing" data-dojo-props="id: 'missing'"></div> |
| 601 |
|
| 602 |
|
| 603 |
<div data-dojo-type="dijit/tests/resources/TestContextRequireWidget" data-dojo-props="id: 'testContextWidget'"></div> |
| 604 |
|
| 605 |
|
| 606 |
<textarea id="Test6Template" style="display:none;"> |
| 607 |
<div> |
| 608 |
<div data-dojo-type="dijit/form/TextBox" data-dojo-attach-point="textbox" data-dojo-attach-event="onClick: handleClick"></div> |
| 609 |
</div> |
| 610 |
</textarea> |
| 611 |
|
| 612 |
<div data-dojo-type="Test6Widget" data-dojo-props="id: 'test6Widget'"></div> |
| 613 |
|
| 614 |
</div> |
| 615 |
|
| 616 |
</body> |
| 617 |
</html> |