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) {
114 if (!t.open_window) {
122 t.open_window( "BaseTypes/Element.html", function( wnd ) {
123 t.delay_call(1, function() {
124 var elem = wnd.document.getElementById("elemID");
126 var dims = OpenLayers.Element.getDimensions(elem);
127 t.eq(dims.width, 50, "width correct when displayed");
128 t.eq(dims.height, 100, "height correct when displayed")
130 elem.style.display = "none";
131 dims = OpenLayers.Element.getDimensions(elem);
132 t.eq(dims.width, 50, "width correct when hidden");
133 t.eq(dims.height, 100, "height correct when hidden")
144 function test_hasClass(t) {
146 var has = OpenLayers.Element.hasClass;
148 var element = document.createElement("div");
149 element.className = "fe fi fo fum one.part two-part three:part four";
151 t.ok(has(element, "fe"), "has fe");
152 t.ok(has(element, "fi"), "has fi");
153 t.ok(has(element, "fo"), "has fo");
154 t.ok(!has(element, "f"), "hasn't f");
155 t.ok(!has(element, "o"), "hasn't o");
156 t.ok(!has(element, "fumb"), "hasn't fumb");
157 t.ok(!has(element, "one"), "hasn't one");
158 t.ok(has(element, "one.part"), "has one.part");
159 t.ok(!has(element, "two"), "hasn't two");
160 t.ok(has(element, "two-part"), "has two-part");
161 t.ok(!has(element, "three"), "hasn't three");
162 t.ok(has(element, "three:part"), "has three:part");
163 t.ok(has(element, "four"), "has four");
165 element.className = "";
166 t.ok(!has(element, "nada"), "hasn't nada");
169 function test_addClass(t) {
171 var add = OpenLayers.Element.addClass;
173 var element = document.createElement("div");
175 t.eq(element.className, "", "starts with no class name");
177 var mod = add(element, "first");
178 t.eq(mod.id, element.id, "returns the same element");
179 t.eq(element.className, "first", "properly adds first class name");
180 t.eq(add(element, "second").className, "first second",
181 "properly adds second class name");
182 t.eq(add(element, "second").className, "first second",
183 "doesn't do anything for duplicated names");
184 t.eq(add(element, "third").className, "first second third",
185 "properly adds third class name");
188 function test_removeClass(t) {
190 var remove = OpenLayers.Element.removeClass;
192 var element = document.createElement("div");
194 element.className = "first second middle fourth last";
196 var mod = remove(element, "last");
197 t.eq(mod.id, element.id, "returns the same element");
198 t.eq(element.className, "first second middle fourth",
199 "properly removes last class name");
200 t.eq(remove(element, "first").className, "second middle fourth",
201 "properly removes first class name");
202 t.eq(remove(element, "middle").className, "second fourth",
203 "properly removes middle class name");
204 t.eq(remove(element, "nada").className, "second fourth",
205 "doesn't do anything for bogus class name");
208 function test_toggleClass(t) {
210 var toggle = OpenLayers.Element.toggleClass;
212 var element = document.createElement("div");
215 var mod = toggle(element, "first");
216 t.eq(mod.id, element.id, "returns the same element");
217 t.eq(element.className, "first", "adds first new class name");
218 t.eq(toggle(element, "second").className, "first second",
219 "adds second new class name");
220 t.eq(toggle(element, "first").className, "second",
221 "removes first existing class name");
222 t.eq(toggle(element, "second").className, "",
223 "removes second existing class name");
226 function test_Element_getStyle(t) {
229 //tests for this function are not 100% complete... there is some funky
230 // business going on in there with
231 // * document.defaultView (moz/ff I believe)
232 // but I cant seem to find a good way to test them.
234 t.ok(OpenLayers.Element.getStyle(null, null) == null, "passing null values in to getStyle() doesnt bomb, returns null");
236 var elem = document.getElementById("elemID");
237 elem.style.chickenHead = {}
239 var style = "chickenHead";
240 t.ok(OpenLayers.Element.getStyle(elem, style) == elem.style.chickenHead, "get style on basic stylename returns correctly");
242 elem.style.chickenHead = "auto";
243 style = "chickenHead";
244 t.ok(OpenLayers.Element.getStyle(elem, style) == null, "get style on 'auto' style returns null");
246 if (OpenLayers.Util.getBrowserName() == "opera") {
247 elem.style.top = "15px";
250 elem.style.position = "static";
251 t.ok(OpenLayers.Element.getStyle(elem, style) == null, "in opera: get (top/left/right/bottom) style when position == 'static' returns null");
253 elem.style.position = "";
254 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");
257 t.ok(true, "browser is not opera.");
258 t.ok(true, "trust me. browser is not opera.");
266 <div id="elemID" style="width:50px; height:100px; background-color:red">test</div>