4
<script src="../../lib/OpenLayers.js"></script>
6
<script type="text/javascript">
8
function test_Element_visible(t) {
17
elem.style.display = "";
18
t.ok(OpenLayers.Element.visible(elem), "element with style.display == '' is visible");
20
elem.style.display = "block";
21
t.ok(OpenLayers.Element.visible(elem), "element with style.display == block is visible");
23
elem.style.display = "none";
24
t.ok(!OpenLayers.Element.visible(elem), "element with style.display == none is not visible");
27
function test_Element_toggle(t) {
42
OpenLayers.Element.toggle(elem1, elem2);
44
t.eq(elem1.style.display, "", "hidden element toggled to display");
45
t.eq(elem2.style.display, "none", "shown element toggled to hidden");
48
function test_Element_hide(t) {
63
OpenLayers.Element.hide(elem1, elem2);
65
t.eq(elem1.style.display, "none", "hidden element stays hidden");
66
t.eq(elem2.style.display, "none", "shown element hidden");
69
function test_Element_show(t) {
84
OpenLayers.Element.show(elem1, elem2);
86
t.eq(elem1.style.display, "", "hidden element shown");
87
t.eq(elem2.style.display, "", "shown element stays shown");
90
function test_Element_remove(t) {
95
'removeChild': function(elem) {
96
t.ok(true, "removeChild called");
100
OpenLayers.Element.remove(elem);
103
function test_Element_getHeight(t) {
110
t.ok(OpenLayers.Element.getHeight(elem) == elem.offsetHeight, "offsetHeight returned");
113
function test_Element_getDimensions(t) {
117
t.open_window( "BaseTypes/Element.html", function( wnd ) {
118
t.delay_call( 0.5, function() {
119
var elem = wnd.document.getElementById("elemID");
121
var dims = OpenLayers.Element.getDimensions(elem);
122
t.eq(dims.width, 50, "width correct when displayed");
123
t.eq(dims.height, 100, "height correct when displayed")
125
elem.style.display = "none";
126
dims = OpenLayers.Element.getDimensions(elem);
127
t.eq(dims.width, 50, "width correct when hidden");
128
t.eq(dims.height, 100, "height correct when hidden")
139
function test_hasClass(t) {
141
var has = OpenLayers.Element.hasClass;
143
var element = document.createElement("div");
144
element.className = "fe fi fo fum one.part two-part three:part four";
146
t.ok(has(element, "fe"), "has fe");
147
t.ok(has(element, "fi"), "has fi");
148
t.ok(has(element, "fo"), "has fo");
149
t.ok(!has(element, "f"), "hasn't f");
150
t.ok(!has(element, "o"), "hasn't o");
151
t.ok(!has(element, "fumb"), "hasn't fumb");
152
t.ok(!has(element, "one"), "hasn't one");
153
t.ok(has(element, "one.part"), "has one.part");
154
t.ok(!has(element, "two"), "hasn't two");
155
t.ok(has(element, "two-part"), "has two-part");
156
t.ok(!has(element, "three"), "hasn't three");
157
t.ok(has(element, "three:part"), "has three:part");
158
t.ok(has(element, "four"), "has four");
160
element.className = "";
161
t.ok(!has(element, "nada"), "hasn't nada");
164
function test_addClass(t) {
166
var add = OpenLayers.Element.addClass;
168
var element = document.createElement("div");
170
t.eq(element.className, "", "starts with no class name");
172
var mod = add(element, "first");
173
t.eq(mod.id, element.id, "returns the same element");
174
t.eq(element.className, "first", "properly adds first class name");
175
t.eq(add(element, "second").className, "first second",
176
"properly adds second class name");
177
t.eq(add(element, "second").className, "first second",
178
"doesn't do anything for duplicated names");
179
t.eq(add(element, "third").className, "first second third",
180
"properly adds third class name");
183
function test_removeClass(t) {
185
var remove = OpenLayers.Element.removeClass;
187
var element = document.createElement("div");
189
element.className = "first second middle fourth last";
191
var mod = remove(element, "last");
192
t.eq(mod.id, element.id, "returns the same element");
193
t.eq(element.className, "first second middle fourth",
194
"properly removes last class name");
195
t.eq(remove(element, "first").className, "second middle fourth",
196
"properly removes first class name");
197
t.eq(remove(element, "middle").className, "second fourth",
198
"properly removes middle class name");
199
t.eq(remove(element, "nada").className, "second fourth",
200
"doesn't do anything for bogus class name");
203
function test_toggleClass(t) {
205
var toggle = OpenLayers.Element.toggleClass;
207
var element = document.createElement("div");
210
var mod = toggle(element, "first");
211
t.eq(mod.id, element.id, "returns the same element");
212
t.eq(element.className, "first", "adds first new class name");
213
t.eq(toggle(element, "second").className, "first second",
214
"adds second new class name");
215
t.eq(toggle(element, "first").className, "second",
216
"removes first existing class name");
217
t.eq(toggle(element, "second").className, "",
218
"removes second existing class name");
221
function test_Element_getStyle(t) {
224
//tests for this function are not 100% complete... there is some funky
225
// business going on in there with
226
// * document.defaultView (moz/ff I believe)
227
// but I cant seem to find a good way to test them.
229
t.ok(OpenLayers.Element.getStyle(null, null) == null, "passing null values in to getStyle() doesnt bomb, returns null");
231
var elem = document.getElementById("elemID");
232
elem.style.chickenHead = {}
234
var style = "chickenHead";
235
t.ok(OpenLayers.Element.getStyle(elem, style) == elem.style.chickenHead, "get style on basic stylename returns correctly");
237
elem.style.chickenHead = "auto";
238
style = "chickenHead";
239
t.ok(OpenLayers.Element.getStyle(elem, style) == null, "get style on 'auto' style returns null");
241
if (OpenLayers.Util.getBrowserName() == "opera") {
242
elem.style.top = "15px";
245
elem.style.position = "static";
246
t.ok(OpenLayers.Element.getStyle(elem, style) == null, "in opera: get (top/left/right/bottom) style when position == 'static' returns null");
248
elem.style.position = "";
249
t.ok(OpenLayers.Element.getStyle(elem, style) == null, "in opera: get (top/left/right/bottom) style when position != 'static', gets computedStyle as static and returns null");
252
t.ok(true, "browser is not opera.");
253
t.ok(true, "trust me. browser is not opera.");
261
<div id="elemID" style="width:50px; height:100px; background-color:red">test</div>