| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
|
| 5 |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 6 |
|
| 7 |
<title>Container</title> |
| 8 |
|
| 9 |
<script src="boilerplate.js"></script> |
| 10 |
|
| 11 |
<script type="text/javascript"> |
| 12 |
require([ |
| 13 |
"doh/runner", |
| 14 |
"dojo/_base/declare", "dojo/dom", "dojo/parser", |
| 15 |
"dijit/a11y", "dijit/focus", "dijit/registry", "dijit/_WidgetBase", "dijit/_Container", "dijit/_Contained", |
| 16 |
"dijit/tests/helpers", "dojo/domReady!" |
| 17 |
], function(doh, declare, dom, parser, a11y, focus, registry, _WidgetBase, _Container, _Contained, helpers){ |
| 18 |
|
| 19 |
declare("TestContainer", |
| 20 |
[_WidgetBase, _Container], { } |
| 21 |
); |
| 22 |
|
| 23 |
declare("TestContained", |
| 24 |
[_WidgetBase, _Contained], {} |
| 25 |
); |
| 26 |
|
| 27 |
doh.register("parse", function(){ |
| 28 |
parser.parse(); |
| 29 |
}); |
| 30 |
|
| 31 |
doh.register("basic tests", [ |
| 32 |
{ |
| 33 |
name: "getChildren", |
| 34 |
runTest: function(t){ |
| 35 |
var c = registry.byId("container"); |
| 36 |
var children = c.getChildren(); |
| 37 |
t.is(4, children.length); |
| 38 |
t.is("zero", children[0].id); |
| 39 |
t.is("one", children[1].id); |
| 40 |
t.is("two", children[2].id); |
| 41 |
t.is("three", children[3].id); |
| 42 |
} |
| 43 |
}, |
| 44 |
{ |
| 45 |
name: "_getSiblingOfChild", |
| 46 |
runTest: function(t){ |
| 47 |
var c = registry.byId("container"); |
| 48 |
var children = c.getChildren(); |
| 49 |
t.is("one", c._getSiblingOfChild(children[0], 1).id); |
| 50 |
t.is("two", c._getSiblingOfChild(children[1], 1).id); |
| 51 |
t.is("three", c._getSiblingOfChild(children[2], 1).id); |
| 52 |
t.is(null, c._getSiblingOfChild(children[3], 1)); |
| 53 |
t.is(null, c._getSiblingOfChild(children[0], -1)); |
| 54 |
t.is("zero", c._getSiblingOfChild(children[1], -1).id); |
| 55 |
t.is("one", c._getSiblingOfChild(children[2], -1).id); |
| 56 |
t.is("two", c._getSiblingOfChild(children[3], -1).id); |
| 57 |
} |
| 58 |
}, |
| 59 |
{ |
| 60 |
name: "getIndexOfChild", |
| 61 |
runTest: function(t){ |
| 62 |
var c = registry.byId("container"); |
| 63 |
t.is(0, c.getIndexOfChild(registry.byId("zero"))); |
| 64 |
t.is(1, c.getIndexOfChild(registry.byId("one"))); |
| 65 |
t.is(2, c.getIndexOfChild(registry.byId("two"))); |
| 66 |
t.is(3, c.getIndexOfChild(registry.byId("three"))); |
| 67 |
t.is(-1, c.getIndexOfChild(registry.byId("outside"))); |
| 68 |
t.is(-1, c.getIndexOfChild(registry.byId("outsideCont"))); |
| 69 |
} |
| 70 |
}, |
| 71 |
{ |
| 72 |
name: "getIndexInParent", |
| 73 |
runTest: function(t){ |
| 74 |
t.is(0, registry.byId("zero").getIndexInParent()); |
| 75 |
t.is(1, registry.byId("one").getIndexInParent()); |
| 76 |
t.is(2, registry.byId("two").getIndexInParent()); |
| 77 |
t.is(-1, registry.byId("outsideCont").getIndexInParent()); |
| 78 |
} |
| 79 |
}, |
| 80 |
{ |
| 81 |
name: "removeChild", |
| 82 |
runTest: function(t){ |
| 83 |
var c = registry.byId("container"); |
| 84 |
var children = c.getChildren(); |
| 85 |
t.is(4, children.length); |
| 86 |
c.removeChild(registry.byId("zero")); |
| 87 |
c.removeChild(1); // should remove "two" - because zero is already removed |
| 88 |
children = c.getChildren(); |
| 89 |
t.is(2, children.length); |
| 90 |
t.is("one", children[0].id); |
| 91 |
t.is("three", children[1].id); |
| 92 |
} |
| 93 |
}, |
| 94 |
{ |
| 95 |
name: "addChild", |
| 96 |
runTest: function(t){ |
| 97 |
var c = registry.byId("container"); |
| 98 |
|
| 99 |
// Add child at beginning |
| 100 |
c.addChild(registry.byId("zero"), 0); |
| 101 |
children = c.getChildren(); |
| 102 |
t.is(3, children.length); |
| 103 |
t.is("zero", children[0].id, "after addChild(zero), zero"); |
| 104 |
t.is("one", children[1].id, "after addChild(zero), one"); |
| 105 |
t.is("three", children[2].id, "after addChild(zero), three"); |
| 106 |
|
| 107 |
// Add child in middle |
| 108 |
c.addChild(registry.byId("two"), 2); |
| 109 |
children = c.getChildren(); |
| 110 |
t.is(4, children.length); |
| 111 |
t.is("zero", children[0].id, "after addChild(two), zero"); |
| 112 |
t.is("one", children[1].id, "after addChild(two), one"); |
| 113 |
t.is("two", children[2].id, "after addChild(two), two"); |
| 114 |
t.is("three", children[3].id, "after addChild(two), three"); |
| 115 |
|
| 116 |
// Add child at end |
| 117 |
c.addChild(new TestContained({id: "four"})); |
| 118 |
children = c.getChildren(); |
| 119 |
t.is(5, children.length); |
| 120 |
t.is("zero", children[0].id, "after addChild(four), zero"); |
| 121 |
t.is("one", children[1].id, "after addChild(four), one"); |
| 122 |
t.is("two", children[2].id, "after addChild(four), two"); |
| 123 |
t.is("three", children[3].id, "after addChild(four), three"); |
| 124 |
t.is("four", children[4].id, "after addChild(four), four"); |
| 125 |
|
| 126 |
// Add child at end with explicit position specified |
| 127 |
c.addChild(new TestContained({id: "five"}), 5); |
| 128 |
children = c.getChildren(); |
| 129 |
t.is(6, children.length); |
| 130 |
t.is("zero", children[0].id, "after addChild(five), zero"); |
| 131 |
t.is("one", children[1].id, "after addChild(five), one"); |
| 132 |
t.is("two", children[2].id, "after addChild(five), two"); |
| 133 |
t.is("three", children[3].id, "after addChild(five), three"); |
| 134 |
t.is("four", children[4].id, "after addChild(five), four"); |
| 135 |
t.is("five", children[5].id, "after addChild(five), five"); |
| 136 |
} |
| 137 |
} |
| 138 |
]); |
| 139 |
|
| 140 |
// Test for StackContainer etc. where each child is wrapped inside a <div> |
| 141 |
doh.register("wrapped children", [ |
| 142 |
{ |
| 143 |
name: "getChildren", |
| 144 |
runTest: function(t){ |
| 145 |
var c = registry.byId("wrappedContainer"); |
| 146 |
var children = c.getChildren(); |
| 147 |
t.is(3, children.length); |
| 148 |
t.is("wrappedOne", children[0].id); |
| 149 |
t.is("wrappedTwo", children[1].id); |
| 150 |
t.is("wrappedThree", children[2].id); |
| 151 |
} |
| 152 |
}, |
| 153 |
{ |
| 154 |
name: "getPreviousSibling / getNextSibling", |
| 155 |
runTest: function(t){ |
| 156 |
var c = registry.byId("wrappedTwo"); |
| 157 |
t.is("wrappedOne", c.getPreviousSibling().id); |
| 158 |
t.is("wrappedThree", c.getNextSibling().id); |
| 159 |
} |
| 160 |
} |
| 161 |
]); |
| 162 |
|
| 163 |
doh.run(); |
| 164 |
}); |
| 165 |
|
| 166 |
</script> |
| 167 |
</head> |
| 168 |
<body> |
| 169 |
|
| 170 |
<label for="input">before:</label><input id="input"/> |
| 171 |
<div id="container" data-dojo-type="TestContainer"> |
| 172 |
|
| 173 |
<div id="zero" data-dojo-type="TestContained"></div> |
| 174 |
<div id="one" data-dojo-type="TestContained"></div> |
| 175 |
<div id="two" data-dojo-type="TestContained"></div> |
| 176 |
<div id="three" data-dojo-type="dijit/_WidgetBase"></div> |
| 177 |
</div> |
| 178 |
<div id="outside" data-dojo-type="dijit/_WidgetBase"></div> |
| 179 |
<div id="outsideCont" data-dojo-type="TestContained"></div> |
| 180 |
|
| 181 |
|
| 182 |
<div id="wrappedContainer" data-dojo-type="TestContainer"> |
| 183 |
<div id="wrappedOne" data-dojo-type="TestContained"></div> |
| 184 |
<div id="wrappedTwo" data-dojo-type="TestContained"></div> |
| 185 |
<div id="wrappedThree" data-dojo-type="TestContained"></div> |
| 186 |
</div> |
| 187 |
|
| 188 |
</body> |
| 189 |
</html> |