| | 139 | function test_hasClass(t) { |
|---|
| | 140 | t.plan(14); |
|---|
| | 141 | var has = OpenLayers.Element.hasClass; |
|---|
| | 142 | |
|---|
| | 143 | var element = document.createElement("div"); |
|---|
| | 144 | element.className = "fe fi fo fum one.part two-part three:part four"; |
|---|
| | 145 | |
|---|
| | 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"); |
|---|
| | 159 | |
|---|
| | 160 | element.className = ""; |
|---|
| | 161 | t.ok(!has(element, "nada"), "hasn't nada"); |
|---|
| | 162 | } |
|---|
| | 163 | |
|---|
| | 164 | function test_addClass(t) { |
|---|
| | 165 | t.plan(6); |
|---|
| | 166 | var add = OpenLayers.Element.addClass; |
|---|
| | 167 | |
|---|
| | 168 | var element = document.createElement("div"); |
|---|
| | 169 | element.id = "foo"; |
|---|
| | 170 | t.eq(element.className, "", "starts with no class name"); |
|---|
| | 171 | |
|---|
| | 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"); |
|---|
| | 181 | } |
|---|
| | 182 | |
|---|
| | 183 | function test_removeClass(t) { |
|---|
| | 184 | t.plan(5); |
|---|
| | 185 | var remove = OpenLayers.Element.removeClass; |
|---|
| | 186 | |
|---|
| | 187 | var element = document.createElement("div"); |
|---|
| | 188 | element.id = "foo"; |
|---|
| | 189 | element.className = "first second middle fourth last"; |
|---|
| | 190 | |
|---|
| | 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"); |
|---|
| | 201 | } |
|---|
| | 202 | |
|---|
| | 203 | function test_toggleClass(t) { |
|---|
| | 204 | t.plan(5); |
|---|
| | 205 | var toggle = OpenLayers.Element.toggleClass; |
|---|
| | 206 | |
|---|
| | 207 | var element = document.createElement("div"); |
|---|
| | 208 | element.id = "foo"; |
|---|
| | 209 | |
|---|
| | 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"); |
|---|
| | 219 | } |
|---|
| | 220 | |
|---|