Diffstat (limited to 'frontend/gamma/js/MochiKit/DOM.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/MochiKit/DOM.js | 165 |
1 files changed, 100 insertions, 65 deletions
diff --git a/frontend/gamma/js/MochiKit/DOM.js b/frontend/gamma/js/MochiKit/DOM.js index af5d46f..944ab78 100644 --- a/frontend/gamma/js/MochiKit/DOM.js +++ b/frontend/gamma/js/MochiKit/DOM.js | |||
@@ -1,546 +1,546 @@ | |||
1 | /*** | 1 | /*** |
2 | 2 | ||
3 | MochiKit.DOM 1.5 | 3 | MochiKit.DOM 1.5 |
4 | 4 | ||
5 | See <http://mochikit.com/> for documentation, downloads, license, etc. | 5 | See <http://mochikit.com/> for documentation, downloads, license, etc. |
6 | 6 | ||
7 | (c) 2005 Bob Ippolito. All rights Reserved. | 7 | (c) 2005 Bob Ippolito. All rights Reserved. |
8 | 8 | ||
9 | ***/ | 9 | ***/ |
10 | 10 | ||
11 | MochiKit.Base._module('DOM', '1.5', ['Base']); | 11 | MochiKit.Base.module(MochiKit, 'DOM', '1.5', ['Base']); |
12 | 12 | ||
13 | MochiKit.Base.update(MochiKit.DOM, { | 13 | MochiKit.Base.update(MochiKit.DOM, { |
14 | 14 | ||
15 | /** @id MochiKit.DOM.currentWindow */ | 15 | /** @id MochiKit.DOM.currentWindow */ |
16 | currentWindow: function () { | 16 | currentWindow: function () { |
17 | return MochiKit.DOM._window; | 17 | return MochiKit.DOM._window; |
18 | }, | 18 | }, |
19 | 19 | ||
20 | /** @id MochiKit.DOM.currentDocument */ | 20 | /** @id MochiKit.DOM.currentDocument */ |
21 | currentDocument: function () { | 21 | currentDocument: function () { |
22 | return MochiKit.DOM._document; | 22 | return MochiKit.DOM._document; |
23 | }, | 23 | }, |
24 | 24 | ||
25 | /** @id MochiKit.DOM.withWindow */ | 25 | /** @id MochiKit.DOM.withWindow */ |
26 | withWindow: function (win, func) { | 26 | withWindow: function (win, func) { |
27 | var self = MochiKit.DOM; | 27 | var self = MochiKit.DOM; |
28 | var oldDoc = self._document; | 28 | var oldDoc = self._document; |
29 | var oldWin = self._window; | 29 | var oldWin = self._window; |
30 | var rval; | 30 | var rval; |
31 | try { | 31 | try { |
32 | self._window = win; | 32 | self._window = win; |
33 | self._document = win.document; | 33 | self._document = win.document; |
34 | rval = func(); | 34 | rval = func(); |
35 | } catch (e) { | 35 | } catch (e) { |
36 | self._window = oldWin; | 36 | self._window = oldWin; |
37 | self._document = oldDoc; | 37 | self._document = oldDoc; |
38 | throw e; | 38 | throw e; |
39 | } | 39 | } |
40 | self._window = oldWin; | 40 | self._window = oldWin; |
41 | self._document = oldDoc; | 41 | self._document = oldDoc; |
42 | return rval; | 42 | return rval; |
43 | }, | 43 | }, |
44 | 44 | ||
45 | /** @id MochiKit.DOM.formContents */ | 45 | /** @id MochiKit.DOM.formContents */ |
46 | formContents: function (elem/* = document.body */) { | 46 | formContents: function (elem/* = document.body */) { |
47 | var names = []; | 47 | var names = []; |
48 | var values = []; | 48 | var values = []; |
49 | var m = MochiKit.Base; | 49 | var m = MochiKit.Base; |
50 | var self = MochiKit.DOM; | 50 | var self = MochiKit.DOM; |
51 | if (typeof(elem) == "undefined" || elem === null) { | 51 | if (typeof(elem) == "undefined" || elem === null) { |
52 | elem = self._document.body; | 52 | elem = self._document.body; |
53 | } else { | 53 | } else { |
54 | elem = self.getElement(elem); | 54 | elem = self.getElement(elem); |
55 | } | 55 | } |
56 | m.nodeWalk(elem, function (elem) { | 56 | m.nodeWalk(elem, function (elem) { |
57 | var name = elem.name; | 57 | var name = elem.name; |
58 | if (m.isNotEmpty(name)) { | 58 | if (m.isNotEmpty(name)) { |
59 | var tagName = elem.tagName.toUpperCase(); | 59 | var tagName = elem.tagName.toUpperCase(); |
60 | if (tagName === "INPUT" | 60 | if (tagName === "INPUT" |
61 | && (elem.type == "radio" || elem.type == "checkbox") | 61 | && (elem.type == "radio" || elem.type == "checkbox") |
62 | && !elem.checked | 62 | && !elem.checked |
63 | ) { | 63 | ) { |
64 | return null; | 64 | return null; |
65 | } | 65 | } |
66 | if (tagName === "SELECT") { | 66 | if (tagName === "SELECT") { |
67 | if (elem.type == "select-one") { | 67 | if (elem.type == "select-one") { |
68 | if (elem.selectedIndex >= 0) { | 68 | if (elem.selectedIndex >= 0) { |
69 | var opt = elem.options[elem.selectedIndex]; | 69 | var opt = elem.options[elem.selectedIndex]; |
70 | var v = opt.value; | 70 | var v = opt.value; |
71 | if (!v) { | 71 | if (!v) { |
72 | var h = opt.outerHTML; | 72 | var h = opt.outerHTML; |
73 | // internet explorer sure does suck. | 73 | // internet explorer sure does suck. |
74 | if (h && !h.match(/^[^>]+\svalue\s*=/i)) { | 74 | if (h && !h.match(/^[^>]+\svalue\s*=/i)) { |
75 | v = opt.text; | 75 | v = opt.text; |
76 | } | 76 | } |
77 | } | 77 | } |
78 | names.push(name); | 78 | names.push(name); |
79 | values.push(v); | 79 | values.push(v); |
80 | return null; | 80 | return null; |
81 | } | 81 | } |
82 | // no form elements? | 82 | // no form elements? |
83 | names.push(name); | 83 | names.push(name); |
84 | values.push(""); | 84 | values.push(""); |
85 | return null; | 85 | return null; |
86 | } else { | 86 | } else { |
87 | var opts = elem.options; | 87 | var opts = elem.options; |
88 | if (!opts.length) { | 88 | if (!opts.length) { |
89 | names.push(name); | 89 | names.push(name); |
90 | values.push(""); | 90 | values.push(""); |
91 | return null; | 91 | return null; |
92 | } | 92 | } |
93 | for (var i = 0; i < opts.length; i++) { | 93 | for (var i = 0; i < opts.length; i++) { |
94 | var opt = opts[i]; | 94 | var opt = opts[i]; |
95 | if (!opt.selected) { | 95 | if (!opt.selected) { |
96 | continue; | 96 | continue; |
97 | } | 97 | } |
98 | var v = opt.value; | 98 | var v = opt.value; |
99 | if (!v) { | 99 | if (!v) { |
100 | var h = opt.outerHTML; | 100 | var h = opt.outerHTML; |
101 | // internet explorer sure does suck. | 101 | // internet explorer sure does suck. |
102 | if (h && !h.match(/^[^>]+\svalue\s*=/i)) { | 102 | if (h && !h.match(/^[^>]+\svalue\s*=/i)) { |
103 | v = opt.text; | 103 | v = opt.text; |
104 | } | 104 | } |
105 | } | 105 | } |
106 | names.push(name); | 106 | names.push(name); |
107 | values.push(v); | 107 | values.push(v); |
108 | } | 108 | } |
109 | return null; | 109 | return null; |
110 | } | 110 | } |
111 | } | 111 | } |
112 | if (tagName === "FORM" || tagName === "P" || tagName === "SPAN" | 112 | if (tagName === "FORM" || tagName === "P" || tagName === "SPAN" |
113 | || tagName === "DIV" | 113 | || tagName === "DIV" |
114 | ) { | 114 | ) { |
115 | return elem.childNodes; | 115 | return elem.childNodes; |
116 | } | 116 | } |
117 | names.push(name); | 117 | names.push(name); |
118 | values.push(elem.value || ''); | 118 | values.push(elem.value || ''); |
119 | return null; | 119 | return null; |
120 | } | 120 | } |
121 | return elem.childNodes; | 121 | return elem.childNodes; |
122 | }); | 122 | }); |
123 | return [names, values]; | 123 | return [names, values]; |
124 | }, | 124 | }, |
125 | 125 | ||
126 | /** @id MochiKit.DOM.withDocument */ | 126 | /** @id MochiKit.DOM.withDocument */ |
127 | withDocument: function (doc, func) { | 127 | withDocument: function (doc, func) { |
128 | var self = MochiKit.DOM; | 128 | var self = MochiKit.DOM; |
129 | var oldDoc = self._document; | 129 | var oldDoc = self._document; |
130 | var rval; | 130 | var rval; |
131 | try { | 131 | try { |
132 | self._document = doc; | 132 | self._document = doc; |
133 | rval = func(); | 133 | rval = func(); |
134 | } catch (e) { | 134 | } catch (e) { |
135 | self._document = oldDoc; | 135 | self._document = oldDoc; |
136 | throw e; | 136 | throw e; |
137 | } | 137 | } |
138 | self._document = oldDoc; | 138 | self._document = oldDoc; |
139 | return rval; | 139 | return rval; |
140 | }, | 140 | }, |
141 | 141 | ||
142 | /** @id MochiKit.DOM.registerDOMConverter */ | 142 | /** @id MochiKit.DOM.registerDOMConverter */ |
143 | registerDOMConverter: function (name, check, wrap, /* optional */override) { | 143 | registerDOMConverter: function (name, check, wrap, /* optional */override) { |
144 | MochiKit.DOM.domConverters.register(name, check, wrap, override); | 144 | MochiKit.DOM.domConverters.register(name, check, wrap, override); |
145 | }, | 145 | }, |
146 | 146 | ||
147 | /** @id MochiKit.DOM.coerceToDOM */ | 147 | /** @id MochiKit.DOM.coerceToDOM */ |
148 | coerceToDOM: function (node, ctx) { | 148 | coerceToDOM: function (node, ctx) { |
149 | var m = MochiKit.Base; | 149 | var m = MochiKit.Base; |
150 | var im = MochiKit.Iter; | 150 | var im = MochiKit.Iter; |
151 | var self = MochiKit.DOM; | 151 | var self = MochiKit.DOM; |
152 | if (im) { | 152 | if (im) { |
153 | var iter = im.iter; | 153 | var iter = im.iter; |
154 | var repeat = im.repeat; | 154 | var repeat = im.repeat; |
155 | } | 155 | } |
156 | var map = m.map; | 156 | var map = m.map; |
157 | var domConverters = self.domConverters; | 157 | var domConverters = self.domConverters; |
158 | var coerceToDOM = arguments.callee; | 158 | var coerceToDOM = arguments.callee; |
159 | var NotFound = m.NotFound; | 159 | var NotFound = m.NotFound; |
160 | while (true) { | 160 | while (true) { |
161 | if (typeof(node) == 'undefined' || node === null) { | 161 | if (typeof(node) == 'undefined' || node === null) { |
162 | return null; | 162 | return null; |
163 | } | 163 | } |
164 | // this is a safari childNodes object, avoiding crashes w/ attr | 164 | // this is a safari childNodes object, avoiding crashes w/ attr |
165 | // lookup | 165 | // lookup |
166 | if (typeof(node) == "function" && | 166 | if (typeof(node) == "function" && |
167 | typeof(node.length) == "number" && | 167 | typeof(node.length) == "number" && |
168 | !(node instanceof Function)) { | 168 | !(node instanceof Function)) { |
169 | node = im ? im.list(node) : m.extend(null, node); | 169 | node = im ? im.list(node) : m.extend(null, node); |
170 | } | 170 | } |
171 | if (typeof(node.nodeType) != 'undefined' && node.nodeType > 0) { | 171 | if (typeof(node.nodeType) != 'undefined' && node.nodeType > 0) { |
172 | return node; | 172 | return node; |
173 | } | 173 | } |
174 | if (typeof(node) == 'number' || typeof(node) == 'boolean') { | 174 | if (typeof(node) == 'number' || typeof(node) == 'boolean') { |
175 | node = node.toString(); | 175 | node = node.toString(); |
176 | // FALL THROUGH | 176 | // FALL THROUGH |
177 | } | 177 | } |
178 | if (typeof(node) == 'string') { | 178 | if (typeof(node) == 'string') { |
179 | return self._document.createTextNode(node); | 179 | return self._document.createTextNode(node); |
180 | } | 180 | } |
181 | if (typeof(node.__dom__) == 'function') { | 181 | if (typeof(node.__dom__) == 'function') { |
182 | node = node.__dom__(ctx); | 182 | node = node.__dom__(ctx); |
183 | continue; | 183 | continue; |
184 | } | 184 | } |
185 | if (typeof(node.dom) == 'function') { | 185 | if (typeof(node.dom) == 'function') { |
186 | node = node.dom(ctx); | 186 | node = node.dom(ctx); |
187 | continue; | 187 | continue; |
188 | } | 188 | } |
189 | if (typeof(node) == 'function') { | 189 | if (typeof(node) == 'function') { |
190 | node = node.apply(ctx, [ctx]); | 190 | node = node.apply(ctx, [ctx]); |
191 | continue; | 191 | continue; |
192 | } | 192 | } |
193 | 193 | ||
194 | if (im) { | 194 | if (im) { |
195 | // iterable | 195 | // iterable |
196 | var iterNodes = null; | 196 | var iterNodes = null; |
197 | try { | 197 | try { |
198 | iterNodes = iter(node); | 198 | iterNodes = iter(node); |
199 | } catch (e) { | 199 | } catch (e) { |
200 | // pass | 200 | // pass |
201 | } | 201 | } |
202 | if (iterNodes) { | 202 | if (iterNodes) { |
203 | return map(coerceToDOM, iterNodes, repeat(ctx)); | 203 | return map(coerceToDOM, iterNodes, repeat(ctx)); |
204 | } | 204 | } |
205 | } else if (m.isArrayLike(node)) { | 205 | } else if (m.isArrayLike(node)) { |
206 | var func = function (n) { return coerceToDOM(n, ctx); }; | 206 | var func = function (n) { return coerceToDOM(n, ctx); }; |
207 | return map(func, node); | 207 | return map(func, node); |
208 | } | 208 | } |
209 | 209 | ||
210 | // adapter | 210 | // adapter |
211 | try { | 211 | try { |
212 | node = domConverters.match(node, ctx); | 212 | node = domConverters.match(node, ctx); |
213 | continue; | 213 | continue; |
214 | } catch (e) { | 214 | } catch (e) { |
215 | if (e != NotFound) { | 215 | if (e != NotFound) { |
216 | throw e; | 216 | throw e; |
217 | } | 217 | } |
218 | } | 218 | } |
219 | 219 | ||
220 | // fallback | 220 | // fallback |
221 | return self._document.createTextNode(node.toString()); | 221 | return self._document.createTextNode(node.toString()); |
222 | } | 222 | } |
223 | // mozilla warnings aren't too bright | 223 | // mozilla warnings aren't too bright |
224 | return undefined; | 224 | return undefined; |
225 | }, | 225 | }, |
226 | 226 | ||
227 | /** @id MochiKit.DOM.isChildNode */ | 227 | /** @id MochiKit.DOM.isChildNode */ |
228 | isChildNode: function (node, maybeparent) { | 228 | isChildNode: function (node, maybeparent) { |
229 | var self = MochiKit.DOM; | 229 | var self = MochiKit.DOM; |
230 | if (typeof(node) == "string") { | 230 | if (typeof(node) == "string") { |
231 | node = self.getElement(node); | 231 | node = self.getElement(node); |
232 | } | 232 | } |
233 | if (typeof(maybeparent) == "string") { | 233 | if (typeof(maybeparent) == "string") { |
234 | maybeparent = self.getElement(maybeparent); | 234 | maybeparent = self.getElement(maybeparent); |
235 | } | 235 | } |
236 | if (typeof(node) == 'undefined' || node === null) { | 236 | if (typeof(node) == 'undefined' || node === null) { |
237 | return false; | 237 | return false; |
238 | } | 238 | } |
239 | while (node != null && node !== self._document) { | 239 | while (node != null && node !== self._document) { |
240 | if (node === maybeparent) { | 240 | if (node === maybeparent) { |
241 | return true; | 241 | return true; |
242 | } | 242 | } |
243 | node = node.parentNode; | 243 | node = node.parentNode; |
244 | } | 244 | } |
245 | return false; | 245 | return false; |
246 | }, | 246 | }, |
247 | 247 | ||
248 | /** @id MochiKit.DOM.setNodeAttribute */ | 248 | /** @id MochiKit.DOM.setNodeAttribute */ |
249 | setNodeAttribute: function (node, attr, value) { | 249 | setNodeAttribute: function (node, attr, value) { |
250 | var o = {}; | 250 | var o = {}; |
251 | o[attr] = value; | 251 | o[attr] = value; |
252 | try { | 252 | try { |
253 | return MochiKit.DOM.updateNodeAttributes(node, o); | 253 | return MochiKit.DOM.updateNodeAttributes(node, o); |
254 | } catch (e) { | 254 | } catch (e) { |
255 | // pass | 255 | // pass |
256 | } | 256 | } |
257 | return null; | 257 | return null; |
258 | }, | 258 | }, |
259 | 259 | ||
260 | /** @id MochiKit.DOM.getNodeAttribute */ | 260 | /** @id MochiKit.DOM.getNodeAttribute */ |
261 | getNodeAttribute: function (node, attr) { | 261 | getNodeAttribute: function (node, attr) { |
262 | var self = MochiKit.DOM; | 262 | var self = MochiKit.DOM; |
263 | var rename = self.attributeArray.renames[attr]; | 263 | var rename = self.attributeArray.renames[attr]; |
264 | var ignoreValue = self.attributeArray.ignoreAttr[attr]; | 264 | var ignoreValue = self.attributeArray.ignoreAttr[attr]; |
265 | node = self.getElement(node); | 265 | node = self.getElement(node); |
266 | try { | 266 | try { |
267 | if (rename) { | 267 | if (rename) { |
268 | return node[rename]; | 268 | return node[rename]; |
269 | } | 269 | } |
270 | var value = node.getAttribute(attr); | 270 | var value = node.getAttribute(attr); |
271 | if (value != ignoreValue) { | 271 | if (value != ignoreValue) { |
272 | return value; | 272 | return value; |
273 | } | 273 | } |
274 | } catch (e) { | 274 | } catch (e) { |
275 | // pass | 275 | // pass |
276 | } | 276 | } |
277 | return null; | 277 | return null; |
278 | }, | 278 | }, |
279 | 279 | ||
280 | /** @id MochiKit.DOM.removeNodeAttribute */ | 280 | /** @id MochiKit.DOM.removeNodeAttribute */ |
281 | removeNodeAttribute: function (node, attr) { | 281 | removeNodeAttribute: function (node, attr) { |
282 | var self = MochiKit.DOM; | 282 | var self = MochiKit.DOM; |
283 | var rename = self.attributeArray.renames[attr]; | 283 | var rename = self.attributeArray.renames[attr]; |
284 | node = self.getElement(node); | 284 | node = self.getElement(node); |
285 | try { | 285 | try { |
286 | if (rename) { | 286 | if (rename) { |
287 | return node[rename]; | 287 | return node[rename]; |
288 | } | 288 | } |
289 | return node.removeAttribute(attr); | 289 | return node.removeAttribute(attr); |
290 | } catch (e) { | 290 | } catch (e) { |
291 | // pass | 291 | // pass |
292 | } | 292 | } |
293 | return null; | 293 | return null; |
294 | }, | 294 | }, |
295 | 295 | ||
296 | /** @id MochiKit.DOM.updateNodeAttributes */ | 296 | /** @id MochiKit.DOM.updateNodeAttributes */ |
297 | updateNodeAttributes: function (node, attrs) { | 297 | updateNodeAttributes: function (node, attrs) { |
298 | var elem = node; | 298 | var elem = node; |
299 | var self = MochiKit.DOM; | 299 | var self = MochiKit.DOM; |
300 | var base = MochiKit.Base; | ||
300 | if (typeof(node) == 'string') { | 301 | if (typeof(node) == 'string') { |
301 | elem = self.getElement(node); | 302 | elem = self.getElement(node); |
302 | } | 303 | } |
303 | if (attrs) { | 304 | if (attrs) { |
304 | var updatetree = MochiKit.Base.updatetree; | ||
305 | if (self.attributeArray.compliant) { | 305 | if (self.attributeArray.compliant) { |
306 | // not IE, good. | 306 | // not IE, good. |
307 | for (var k in attrs) { | 307 | for (var k in attrs) { |
308 | var v = attrs[k]; | 308 | var v = attrs[k]; |
309 | if (typeof(v) == 'object' && typeof(elem[k]) == 'object') { | 309 | if (typeof(v) == 'object' && typeof(elem[k]) == 'object') { |
310 | if (k == "style" && MochiKit.Style) { | 310 | if (k == "style" && MochiKit.Style) { |
311 | MochiKit.Style.setStyle(elem, v); | 311 | MochiKit.Style.setStyle(elem, v); |
312 | } else { | 312 | } else { |
313 | updatetree(elem[k], v); | 313 | base.updatetree(elem[k], v); |
314 | } | 314 | } |
315 | } else if (k.substring(0, 2) == "on") { | 315 | } else if (k.substring(0, 2) == "on") { |
316 | if (typeof(v) == "string") { | 316 | if (typeof(v) == "string") { |
317 | v = new Function(v); | 317 | v = new Function(v); |
318 | } | 318 | } |
319 | elem[k] = v; | 319 | elem[k] = v; |
320 | } else { | 320 | } else { |
321 | elem.setAttribute(k, v); | 321 | elem.setAttribute(k, v); |
322 | } | 322 | } |
323 | if (typeof(elem[k]) == "string" && elem[k] != v) { | 323 | if (base.isValue(elem[k]) && elem[k] != v) { |
324 | // Also set property for weird attributes (see #302) | 324 | // Also set property for weird attributes (see #302 & #335) |
325 | elem[k] = v; | 325 | elem[k] = v; |
326 | } | 326 | } |
327 | } | 327 | } |
328 | } else { | 328 | } else { |
329 | // IE is insane in the membrane | 329 | // IE is insane in the membrane |
330 | var renames = self.attributeArray.renames; | 330 | var renames = self.attributeArray.renames; |
331 | for (var k in attrs) { | 331 | for (var k in attrs) { |
332 | v = attrs[k]; | 332 | v = attrs[k]; |
333 | var renamed = renames[k]; | 333 | var renamed = renames[k]; |
334 | if (k == "style" && typeof(v) == "string") { | 334 | if (k == "style" && typeof(v) == "string") { |
335 | elem.style.cssText = v; | 335 | elem.style.cssText = v; |
336 | } else if (typeof(renamed) == "string") { | 336 | } else if (typeof(renamed) == "string") { |
337 | elem[renamed] = v; | 337 | elem[renamed] = v; |
338 | } else if (typeof(elem[k]) == 'object' | 338 | } else if (typeof(elem[k]) == 'object' |
339 | && typeof(v) == 'object') { | 339 | && typeof(v) == 'object') { |
340 | if (k == "style" && MochiKit.Style) { | 340 | if (k == "style" && MochiKit.Style) { |
341 | MochiKit.Style.setStyle(elem, v); | 341 | MochiKit.Style.setStyle(elem, v); |
342 | } else { | 342 | } else { |
343 | updatetree(elem[k], v); | 343 | base.updatetree(elem[k], v); |
344 | } | 344 | } |
345 | } else if (k.substring(0, 2) == "on") { | 345 | } else if (k.substring(0, 2) == "on") { |
346 | if (typeof(v) == "string") { | 346 | if (typeof(v) == "string") { |
347 | v = new Function(v); | 347 | v = new Function(v); |
348 | } | 348 | } |
349 | elem[k] = v; | 349 | elem[k] = v; |
350 | } else { | 350 | } else { |
351 | elem.setAttribute(k, v); | 351 | elem.setAttribute(k, v); |
352 | } | 352 | } |
353 | if (typeof(elem[k]) == "string" && elem[k] != v) { | 353 | if (base.isValue(elem[k]) && elem[k] != v) { |
354 | // Also set property for weird attributes (see #302) | 354 | // Also set property for weird attributes (see #302 & #335) |
355 | elem[k] = v; | 355 | elem[k] = v; |
356 | } | 356 | } |
357 | } | 357 | } |
358 | } | 358 | } |
359 | } | 359 | } |
360 | return elem; | 360 | return elem; |
361 | }, | 361 | }, |
362 | 362 | ||
363 | /** @id MochiKit.DOM.appendChildNodes */ | 363 | /** @id MochiKit.DOM.appendChildNodes */ |
364 | appendChildNodes: function (node/*, nodes...*/) { | 364 | appendChildNodes: function (node/*, nodes...*/) { |
365 | var elem = node; | 365 | var elem = node; |
366 | var self = MochiKit.DOM; | 366 | var self = MochiKit.DOM; |
367 | if (typeof(node) == 'string') { | 367 | if (typeof(node) == 'string') { |
368 | elem = self.getElement(node); | 368 | elem = self.getElement(node); |
369 | } | 369 | } |
370 | var nodeStack = [ | 370 | var nodeStack = [ |
371 | self.coerceToDOM( | 371 | self.coerceToDOM( |
372 | MochiKit.Base.extend(null, arguments, 1), | 372 | MochiKit.Base.extend(null, arguments, 1), |
373 | elem | 373 | elem |
374 | ) | 374 | ) |
375 | ]; | 375 | ]; |
376 | var concat = MochiKit.Base.concat; | 376 | var concat = MochiKit.Base.concat; |
377 | while (nodeStack.length) { | 377 | while (nodeStack.length) { |
378 | var n = nodeStack.shift(); | 378 | var n = nodeStack.shift(); |
379 | if (typeof(n) == 'undefined' || n === null) { | 379 | if (typeof(n) == 'undefined' || n === null) { |
380 | // pass | 380 | // pass |
381 | } else if (typeof(n.nodeType) == 'number') { | 381 | } else if (typeof(n.nodeType) == 'number') { |
382 | elem.appendChild(n); | 382 | elem.appendChild(n); |
383 | } else { | 383 | } else { |
384 | nodeStack = concat(n, nodeStack); | 384 | nodeStack = concat(n, nodeStack); |
385 | } | 385 | } |
386 | } | 386 | } |
387 | return elem; | 387 | return elem; |
388 | }, | 388 | }, |
389 | 389 | ||
390 | 390 | ||
391 | /** @id MochiKit.DOM.insertSiblingNodesBefore */ | 391 | /** @id MochiKit.DOM.insertSiblingNodesBefore */ |
392 | insertSiblingNodesBefore: function (node/*, nodes...*/) { | 392 | insertSiblingNodesBefore: function (node/*, nodes...*/) { |
393 | var elem = node; | 393 | var elem = node; |
394 | var self = MochiKit.DOM; | 394 | var self = MochiKit.DOM; |
395 | if (typeof(node) == 'string') { | 395 | if (typeof(node) == 'string') { |
396 | elem = self.getElement(node); | 396 | elem = self.getElement(node); |
397 | } | 397 | } |
398 | var nodeStack = [ | 398 | var nodeStack = [ |
399 | self.coerceToDOM( | 399 | self.coerceToDOM( |
400 | MochiKit.Base.extend(null, arguments, 1), | 400 | MochiKit.Base.extend(null, arguments, 1), |
401 | elem | 401 | elem |
402 | ) | 402 | ) |
403 | ]; | 403 | ]; |
404 | var parentnode = elem.parentNode; | 404 | var parentnode = elem.parentNode; |
405 | var concat = MochiKit.Base.concat; | 405 | var concat = MochiKit.Base.concat; |
406 | while (nodeStack.length) { | 406 | while (nodeStack.length) { |
407 | var n = nodeStack.shift(); | 407 | var n = nodeStack.shift(); |
408 | if (typeof(n) == 'undefined' || n === null) { | 408 | if (typeof(n) == 'undefined' || n === null) { |
409 | // pass | 409 | // pass |
410 | } else if (typeof(n.nodeType) == 'number') { | 410 | } else if (typeof(n.nodeType) == 'number') { |
411 | parentnode.insertBefore(n, elem); | 411 | parentnode.insertBefore(n, elem); |
412 | } else { | 412 | } else { |
413 | nodeStack = concat(n, nodeStack); | 413 | nodeStack = concat(n, nodeStack); |
414 | } | 414 | } |
415 | } | 415 | } |
416 | return parentnode; | 416 | return parentnode; |
417 | }, | 417 | }, |
418 | 418 | ||
419 | /** @id MochiKit.DOM.insertSiblingNodesAfter */ | 419 | /** @id MochiKit.DOM.insertSiblingNodesAfter */ |
420 | insertSiblingNodesAfter: function (node/*, nodes...*/) { | 420 | insertSiblingNodesAfter: function (node/*, nodes...*/) { |
421 | var elem = node; | 421 | var elem = node; |
422 | var self = MochiKit.DOM; | 422 | var self = MochiKit.DOM; |
423 | 423 | ||
424 | if (typeof(node) == 'string') { | 424 | if (typeof(node) == 'string') { |
425 | elem = self.getElement(node); | 425 | elem = self.getElement(node); |
426 | } | 426 | } |
427 | var nodeStack = [ | 427 | var nodeStack = [ |
428 | self.coerceToDOM( | 428 | self.coerceToDOM( |
429 | MochiKit.Base.extend(null, arguments, 1), | 429 | MochiKit.Base.extend(null, arguments, 1), |
430 | elem | 430 | elem |
431 | ) | 431 | ) |
432 | ]; | 432 | ]; |
433 | 433 | ||
434 | if (elem.nextSibling) { | 434 | if (elem.nextSibling) { |
435 | return self.insertSiblingNodesBefore(elem.nextSibling, nodeStack); | 435 | return self.insertSiblingNodesBefore(elem.nextSibling, nodeStack); |
436 | } | 436 | } |
437 | else { | 437 | else { |
438 | return self.appendChildNodes(elem.parentNode, nodeStack); | 438 | return self.appendChildNodes(elem.parentNode, nodeStack); |
439 | } | 439 | } |
440 | }, | 440 | }, |
441 | 441 | ||
442 | /** @id MochiKit.DOM.replaceChildNodes */ | 442 | /** @id MochiKit.DOM.replaceChildNodes */ |
443 | replaceChildNodes: function (node/*, nodes...*/) { | 443 | replaceChildNodes: function (node/*, nodes...*/) { |
444 | var elem = node; | 444 | var elem = node; |
445 | var self = MochiKit.DOM; | 445 | var self = MochiKit.DOM; |
446 | if (typeof(node) == 'string') { | 446 | if (typeof(node) == 'string') { |
447 | elem = self.getElement(node); | 447 | elem = self.getElement(node); |
448 | arguments[0] = elem; | 448 | arguments[0] = elem; |
449 | } | 449 | } |
450 | var child; | 450 | var child; |
451 | while ((child = elem.firstChild)) { | 451 | while ((child = elem.firstChild)) { |
452 | elem.removeChild(child); | 452 | elem.removeChild(child); |
453 | } | 453 | } |
454 | if (arguments.length < 2) { | 454 | if (arguments.length < 2) { |
455 | return elem; | 455 | return elem; |
456 | } else { | 456 | } else { |
457 | return self.appendChildNodes.apply(this, arguments); | 457 | return self.appendChildNodes.apply(this, arguments); |
458 | } | 458 | } |
459 | }, | 459 | }, |
460 | 460 | ||
461 | /** @id MochiKit.DOM.createDOM */ | 461 | /** @id MochiKit.DOM.createDOM */ |
462 | createDOM: function (name, attrs/*, nodes... */) { | 462 | createDOM: function (name, attrs/*, nodes... */) { |
463 | var elem; | 463 | var elem; |
464 | var self = MochiKit.DOM; | 464 | var self = MochiKit.DOM; |
465 | var m = MochiKit.Base; | 465 | var m = MochiKit.Base; |
466 | if (typeof(attrs) == "string" || typeof(attrs) == "number") { | 466 | if (typeof(attrs) == "string" || typeof(attrs) == "number") { |
467 | var args = m.extend([name, null], arguments, 1); | 467 | var args = m.extend([name, null], arguments, 1); |
468 | return arguments.callee.apply(this, args); | 468 | return arguments.callee.apply(this, args); |
469 | } | 469 | } |
470 | if (typeof(name) == 'string') { | 470 | if (typeof(name) == 'string') { |
471 | // Internet Explorer is dumb | 471 | // Internet Explorer is dumb |
472 | var xhtml = self._xhtml; | 472 | var xhtml = self._xhtml; |
473 | if (attrs && !self.attributeArray.compliant) { | 473 | if (attrs && !self.attributeArray.compliant) { |
474 | // http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/name_2.asp | 474 | // http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/name_2.asp |
475 | var contents = ""; | 475 | var contents = ""; |
476 | if ('name' in attrs) { | 476 | if ('name' in attrs) { |
477 | contents += ' name="' + self.escapeHTML(attrs.name) + '"'; | 477 | contents += ' name="' + self.escapeHTML(attrs.name) + '"'; |
478 | } | 478 | } |
479 | if (name == 'input' && 'type' in attrs) { | 479 | if (name == 'input' && 'type' in attrs) { |
480 | contents += ' type="' + self.escapeHTML(attrs.type) + '"'; | 480 | contents += ' type="' + self.escapeHTML(attrs.type) + '"'; |
481 | } | 481 | } |
482 | if (contents) { | 482 | if (contents) { |
483 | name = "<" + name + contents + ">"; | 483 | name = "<" + name + contents + ">"; |
484 | xhtml = false; | 484 | xhtml = false; |
485 | } | 485 | } |
486 | } | 486 | } |
487 | var d = self._document; | 487 | var d = self._document; |
488 | if (xhtml && d === document) { | 488 | if (xhtml && d === document) { |
489 | elem = d.createElementNS("http://www.w3.org/1999/xhtml", name); | 489 | elem = d.createElementNS("http://www.w3.org/1999/xhtml", name); |
490 | } else { | 490 | } else { |
491 | elem = d.createElement(name); | 491 | elem = d.createElement(name); |
492 | } | 492 | } |
493 | } else { | 493 | } else { |
494 | elem = name; | 494 | elem = name; |
495 | } | 495 | } |
496 | if (attrs) { | 496 | if (attrs) { |
497 | self.updateNodeAttributes(elem, attrs); | 497 | self.updateNodeAttributes(elem, attrs); |
498 | } | 498 | } |
499 | if (arguments.length <= 2) { | 499 | if (arguments.length <= 2) { |
500 | return elem; | 500 | return elem; |
501 | } else { | 501 | } else { |
502 | var args = m.extend([elem], arguments, 2); | 502 | var args = m.extend([elem], arguments, 2); |
503 | return self.appendChildNodes.apply(this, args); | 503 | return self.appendChildNodes.apply(this, args); |
504 | } | 504 | } |
505 | }, | 505 | }, |
506 | 506 | ||
507 | /** @id MochiKit.DOM.createDOMFunc */ | 507 | /** @id MochiKit.DOM.createDOMFunc */ |
508 | createDOMFunc: function (/* tag, attrs, *nodes */) { | 508 | createDOMFunc: function (/* tag, attrs, *nodes */) { |
509 | var m = MochiKit.Base; | 509 | var m = MochiKit.Base; |
510 | return m.partial.apply( | 510 | return m.partial.apply( |
511 | this, | 511 | this, |
512 | m.extend([MochiKit.DOM.createDOM], arguments) | 512 | m.extend([MochiKit.DOM.createDOM], arguments) |
513 | ); | 513 | ); |
514 | }, | 514 | }, |
515 | 515 | ||
516 | /** @id MochiKit.DOM.removeElement */ | 516 | /** @id MochiKit.DOM.removeElement */ |
517 | removeElement: function (elem) { | 517 | removeElement: function (elem) { |
518 | var self = MochiKit.DOM; | 518 | var self = MochiKit.DOM; |
519 | if (typeof(elem) == "string") { | 519 | if (typeof(elem) == "string") { |
520 | elem = self.getElement(elem); | 520 | elem = self.getElement(elem); |
521 | } | 521 | } |
522 | var e = self.coerceToDOM(elem); | 522 | var e = self.coerceToDOM(elem); |
523 | e.parentNode.removeChild(e); | 523 | e.parentNode.removeChild(e); |
524 | return e; | 524 | return e; |
525 | }, | 525 | }, |
526 | 526 | ||
527 | /** @id MochiKit.DOM.swapDOM */ | 527 | /** @id MochiKit.DOM.swapDOM */ |
528 | swapDOM: function (dest, src) { | 528 | swapDOM: function (dest, src) { |
529 | var self = MochiKit.DOM; | 529 | var self = MochiKit.DOM; |
530 | dest = self.getElement(dest); | 530 | dest = self.getElement(dest); |
531 | var parent = dest.parentNode; | 531 | var parent = dest.parentNode; |
532 | if (src) { | 532 | if (src) { |
533 | if (typeof(src) == "string") { | 533 | if (typeof(src) == "string") { |
534 | src = self.getElement(src); | 534 | src = self.getElement(src); |
535 | } | 535 | } |
536 | src = self.coerceToDOM(src, parent); | 536 | src = self.coerceToDOM(src, parent); |
537 | parent.replaceChild(src, dest); | 537 | parent.replaceChild(src, dest); |
538 | } else { | 538 | } else { |
539 | parent.removeChild(dest); | 539 | parent.removeChild(dest); |
540 | } | 540 | } |
541 | return src; | 541 | return src; |
542 | }, | 542 | }, |
543 | 543 | ||
544 | /** @id MochiKit.DOM.getElement */ | 544 | /** @id MochiKit.DOM.getElement */ |
545 | getElement: function (id) { | 545 | getElement: function (id) { |
546 | var self = MochiKit.DOM; | 546 | var self = MochiKit.DOM; |
@@ -801,344 +801,379 @@ MochiKit.Base.update(MochiKit.DOM, { | |||
801 | // because safari has heisenbugs.. argh. | 801 | // because safari has heisenbugs.. argh. |
802 | // | 802 | // |
803 | // I think it might have something to do with | 803 | // I think it might have something to do with |
804 | // garbage collection and function calls. | 804 | // garbage collection and function calls. |
805 | lst.push('<' + dom.tagName.toLowerCase()); | 805 | lst.push('<' + dom.tagName.toLowerCase()); |
806 | var attributes = []; | 806 | var attributes = []; |
807 | var domAttr = attributeArray(dom); | 807 | var domAttr = attributeArray(dom); |
808 | for (var i = 0; i < domAttr.length; i++) { | 808 | for (var i = 0; i < domAttr.length; i++) { |
809 | var a = domAttr[i]; | 809 | var a = domAttr[i]; |
810 | attributes.push([ | 810 | attributes.push([ |
811 | " ", | 811 | " ", |
812 | a.name, | 812 | a.name, |
813 | '="', | 813 | '="', |
814 | escapeHTML(a.value), | 814 | escapeHTML(a.value), |
815 | '"' | 815 | '"' |
816 | ]); | 816 | ]); |
817 | } | 817 | } |
818 | attributes.sort(); | 818 | attributes.sort(); |
819 | for (i = 0; i < attributes.length; i++) { | 819 | for (i = 0; i < attributes.length; i++) { |
820 | var attrs = attributes[i]; | 820 | var attrs = attributes[i]; |
821 | for (var j = 0; j < attrs.length; j++) { | 821 | for (var j = 0; j < attrs.length; j++) { |
822 | lst.push(attrs[j]); | 822 | lst.push(attrs[j]); |
823 | } | 823 | } |
824 | } | 824 | } |
825 | if (dom.hasChildNodes()) { | 825 | if (dom.hasChildNodes()) { |
826 | lst.push(">"); | 826 | lst.push(">"); |
827 | // queue is the FILO call stack, so we put the close tag | 827 | // queue is the FILO call stack, so we put the close tag |
828 | // on first | 828 | // on first |
829 | queue.push("</" + dom.tagName.toLowerCase() + ">"); | 829 | queue.push("</" + dom.tagName.toLowerCase() + ">"); |
830 | var cnodes = dom.childNodes; | 830 | var cnodes = dom.childNodes; |
831 | for (i = cnodes.length - 1; i >= 0; i--) { | 831 | for (i = cnodes.length - 1; i >= 0; i--) { |
832 | queue.push(cnodes[i]); | 832 | queue.push(cnodes[i]); |
833 | } | 833 | } |
834 | } else { | 834 | } else { |
835 | lst.push('/>'); | 835 | lst.push('/>'); |
836 | } | 836 | } |
837 | } else if (dom.nodeType == 3) { | 837 | } else if (dom.nodeType == 3) { |
838 | lst.push(escapeHTML(dom.nodeValue)); | 838 | lst.push(escapeHTML(dom.nodeValue)); |
839 | } | 839 | } |
840 | } | 840 | } |
841 | return lst; | 841 | return lst; |
842 | }, | 842 | }, |
843 | 843 | ||
844 | /** @id MochiKit.DOM.scrapeText */ | 844 | /** @id MochiKit.DOM.scrapeText */ |
845 | scrapeText: function (node, /* optional */asArray) { | 845 | scrapeText: function (node, /* optional */asArray) { |
846 | var rval = []; | 846 | var rval = []; |
847 | (function (node) { | 847 | (function (node) { |
848 | var cn = node.childNodes; | 848 | var cn = node.childNodes; |
849 | if (cn) { | 849 | if (cn) { |
850 | for (var i = 0; i < cn.length; i++) { | 850 | for (var i = 0; i < cn.length; i++) { |
851 | arguments.callee.call(this, cn[i]); | 851 | arguments.callee.call(this, cn[i]); |
852 | } | 852 | } |
853 | } | 853 | } |
854 | var nodeValue = node.nodeValue; | 854 | var nodeValue = node.nodeValue; |
855 | if (typeof(nodeValue) == 'string') { | 855 | if (typeof(nodeValue) == 'string') { |
856 | rval.push(nodeValue); | 856 | rval.push(nodeValue); |
857 | } | 857 | } |
858 | })(MochiKit.DOM.getElement(node)); | 858 | })(MochiKit.DOM.getElement(node)); |
859 | if (asArray) { | 859 | if (asArray) { |
860 | return rval; | 860 | return rval; |
861 | } else { | 861 | } else { |
862 | return rval.join(""); | 862 | return rval.join(""); |
863 | } | 863 | } |
864 | }, | 864 | }, |
865 | 865 | ||
866 | /** @id MochiKit.DOM.removeEmptyTextNodes */ | 866 | /** @id MochiKit.DOM.removeEmptyTextNodes */ |
867 | removeEmptyTextNodes: function (element) { | 867 | removeEmptyTextNodes: function (element) { |
868 | element = MochiKit.DOM.getElement(element); | 868 | element = MochiKit.DOM.getElement(element); |
869 | for (var i = 0; i < element.childNodes.length; i++) { | 869 | for (var i = 0; i < element.childNodes.length; i++) { |
870 | var node = element.childNodes[i]; | 870 | var node = element.childNodes[i]; |
871 | if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) { | 871 | if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) { |
872 | node.parentNode.removeChild(node); | 872 | node.parentNode.removeChild(node); |
873 | } | 873 | } |
874 | } | 874 | } |
875 | }, | 875 | }, |
876 | 876 | ||
877 | /** @id MochiKit.DOM.getFirstElementByTagAndClassName */ | 877 | /** @id MochiKit.DOM.getFirstElementByTagAndClassName */ |
878 | getFirstElementByTagAndClassName: function (tagName, className, | 878 | getFirstElementByTagAndClassName: function (tagName, className, |
879 | /* optional */parent) { | 879 | /* optional */parent) { |
880 | var self = MochiKit.DOM; | 880 | var self = MochiKit.DOM; |
881 | if (typeof(tagName) == 'undefined' || tagName === null) { | 881 | if (typeof(tagName) == 'undefined' || tagName === null) { |
882 | tagName = '*'; | 882 | tagName = '*'; |
883 | } | 883 | } |
884 | if (typeof(parent) == 'undefined' || parent === null) { | 884 | if (typeof(parent) == 'undefined' || parent === null) { |
885 | parent = self._document; | 885 | parent = self._document; |
886 | } | 886 | } |
887 | parent = self.getElement(parent); | 887 | parent = self.getElement(parent); |
888 | if (parent == null) { | 888 | if (parent == null) { |
889 | return null; | 889 | return null; |
890 | } | 890 | } |
891 | var children = (parent.getElementsByTagName(tagName) | 891 | var children = (parent.getElementsByTagName(tagName) |
892 | || self._document.all); | 892 | || self._document.all); |
893 | if (children.length <= 0) { | 893 | if (children.length <= 0) { |
894 | return null; | 894 | return null; |
895 | } else if (typeof(className) == 'undefined' || className === null) { | 895 | } else if (typeof(className) == 'undefined' || className === null) { |
896 | return children[0]; | 896 | return children[0]; |
897 | } | 897 | } |
898 | 898 | ||
899 | for (var i = 0; i < children.length; i++) { | 899 | for (var i = 0; i < children.length; i++) { |
900 | var child = children[i]; | 900 | var child = children[i]; |
901 | var cls = child.className; | 901 | var cls = child.className; |
902 | if (typeof(cls) != "string") { | 902 | if (typeof(cls) != "string") { |
903 | cls = child.getAttribute("class"); | 903 | cls = child.getAttribute("class"); |
904 | } | 904 | } |
905 | if (typeof(cls) == "string") { | 905 | if (typeof(cls) == "string") { |
906 | var classNames = cls.split(' '); | 906 | var classNames = cls.split(' '); |
907 | for (var j = 0; j < classNames.length; j++) { | 907 | for (var j = 0; j < classNames.length; j++) { |
908 | if (classNames[j] == className) { | 908 | if (classNames[j] == className) { |
909 | return child; | 909 | return child; |
910 | } | 910 | } |
911 | } | 911 | } |
912 | } | 912 | } |
913 | } | 913 | } |
914 | return null; | 914 | return null; |
915 | }, | 915 | }, |
916 | 916 | ||
917 | /** @id MochiKit.DOM.getFirstParentByTagAndClassName */ | 917 | /** @id MochiKit.DOM.getFirstParentByTagAndClassName */ |
918 | getFirstParentByTagAndClassName: function (elem, tagName, className) { | 918 | getFirstParentByTagAndClassName: function (elem, tagName, className) { |
919 | var self = MochiKit.DOM; | 919 | var self = MochiKit.DOM; |
920 | elem = self.getElement(elem); | 920 | elem = self.getElement(elem); |
921 | if (typeof(tagName) == 'undefined' || tagName === null) { | 921 | if (typeof(tagName) == 'undefined' || tagName === null) { |
922 | tagName = '*'; | 922 | tagName = '*'; |
923 | } else { | 923 | } else { |
924 | tagName = tagName.toUpperCase(); | 924 | tagName = tagName.toUpperCase(); |
925 | } | 925 | } |
926 | if (typeof(className) == 'undefined' || className === null) { | 926 | if (typeof(className) == 'undefined' || className === null) { |
927 | className = null; | 927 | className = null; |
928 | } | 928 | } |
929 | if (elem) { | 929 | if (elem) { |
930 | elem = elem.parentNode; | 930 | elem = elem.parentNode; |
931 | } | 931 | } |
932 | while (elem && elem.tagName) { | 932 | while (elem && elem.tagName) { |
933 | var curTagName = elem.tagName.toUpperCase(); | 933 | var curTagName = elem.tagName.toUpperCase(); |
934 | if ((tagName === '*' || tagName == curTagName) && | 934 | if ((tagName === '*' || tagName == curTagName) && |
935 | (className === null || self.hasElementClass(elem, className))) { | 935 | (className === null || self.hasElementClass(elem, className))) { |
936 | return elem; | 936 | return elem; |
937 | } | 937 | } |
938 | elem = elem.parentNode; | 938 | elem = elem.parentNode; |
939 | } | 939 | } |
940 | return null; | 940 | return null; |
941 | }, | 941 | }, |
942 | 942 | ||
943 | __new__: function (win) { | 943 | __new__: function (win) { |
944 | 944 | ||
945 | var m = MochiKit.Base; | 945 | var m = MochiKit.Base; |
946 | if (typeof(document) != "undefined") { | 946 | if (typeof(document) != "undefined") { |
947 | this._document = document; | 947 | this._document = document; |
948 | var kXULNSURI = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; | 948 | var kXULNSURI = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; |
949 | this._xhtml = (document.documentElement && | 949 | this._xhtml = (document.documentElement && |
950 | document.createElementNS && | 950 | document.createElementNS && |
951 | document.documentElement.namespaceURI === kXULNSURI); | 951 | document.documentElement.namespaceURI === kXULNSURI); |
952 | } else if (MochiKit.MockDOM) { | 952 | } else if (MochiKit.MockDOM) { |
953 | this._document = MochiKit.MockDOM.document; | 953 | this._document = MochiKit.MockDOM.document; |
954 | } | 954 | } |
955 | this._window = win; | 955 | this._window = win; |
956 | 956 | ||
957 | this.domConverters = new m.AdapterRegistry(); | 957 | this.domConverters = new m.AdapterRegistry(); |
958 | 958 | ||
959 | var __tmpElement = this._document.createElement("span"); | 959 | var __tmpElement = this._document.createElement("span"); |
960 | var attributeArray; | 960 | var attributeArray; |
961 | if (__tmpElement && __tmpElement.attributes && | 961 | if (__tmpElement && __tmpElement.attributes && |
962 | __tmpElement.attributes.length > 0) { | 962 | __tmpElement.attributes.length > 0) { |
963 | // for braindead browsers (IE) that insert extra junk | 963 | // for braindead browsers (IE) that insert extra junk |
964 | var filter = m.filter; | 964 | var filter = m.filter; |
965 | attributeArray = function (node) { | 965 | attributeArray = function (node) { |
966 | /*** | 966 | /*** |
967 | 967 | ||
968 | Return an array of attributes for a given node, | 968 | Return an array of attributes for a given node, |
969 | filtering out attributes that don't belong for | 969 | filtering out attributes that don't belong for |
970 | that are inserted by "Certain Browsers". | 970 | that are inserted by "Certain Browsers". |
971 | 971 | ||
972 | ***/ | 972 | ***/ |
973 | return filter(attributeArray.ignoreAttrFilter, node.attributes); | 973 | return filter(attributeArray.ignoreAttrFilter, node.attributes); |
974 | }; | 974 | }; |
975 | attributeArray.ignoreAttr = {}; | 975 | attributeArray.ignoreAttr = {}; |
976 | var attrs = __tmpElement.attributes; | 976 | var attrs = __tmpElement.attributes; |
977 | var ignoreAttr = attributeArray.ignoreAttr; | 977 | var ignoreAttr = attributeArray.ignoreAttr; |
978 | for (var i = 0; i < attrs.length; i++) { | 978 | for (var i = 0; i < attrs.length; i++) { |
979 | var a = attrs[i]; | 979 | var a = attrs[i]; |
980 | ignoreAttr[a.name] = a.value; | 980 | ignoreAttr[a.name] = a.value; |
981 | } | 981 | } |
982 | attributeArray.ignoreAttrFilter = function (a) { | 982 | attributeArray.ignoreAttrFilter = function (a) { |
983 | return (attributeArray.ignoreAttr[a.name] != a.value); | 983 | return (attributeArray.ignoreAttr[a.name] != a.value); |
984 | }; | 984 | }; |
985 | attributeArray.compliant = false; | 985 | attributeArray.compliant = false; |
986 | attributeArray.renames = { | 986 | attributeArray.renames = { |
987 | "class": "className", | 987 | "class": "className", |
988 | "checked": "defaultChecked", | 988 | "checked": "defaultChecked", |
989 | "usemap": "useMap", | 989 | "usemap": "useMap", |
990 | "for": "htmlFor", | 990 | "for": "htmlFor", |
991 | "readonly": "readOnly", | 991 | "readonly": "readOnly", |
992 | "colspan": "colSpan", | 992 | "colspan": "colSpan", |
993 | "rowspan": "rowSpan", | ||
993 | "bgcolor": "bgColor", | 994 | "bgcolor": "bgColor", |
994 | "cellspacing": "cellSpacing", | 995 | "cellspacing": "cellSpacing", |
995 | "cellpadding": "cellPadding" | 996 | "cellpadding": "cellPadding" |
996 | }; | 997 | }; |
997 | } else { | 998 | } else { |
998 | attributeArray = function (node) { | 999 | attributeArray = function (node) { |
999 | return node.attributes; | 1000 | return node.attributes; |
1000 | }; | 1001 | }; |
1001 | attributeArray.compliant = true; | 1002 | attributeArray.compliant = true; |
1002 | attributeArray.ignoreAttr = {}; | 1003 | attributeArray.ignoreAttr = {}; |
1003 | attributeArray.renames = {}; | 1004 | attributeArray.renames = {}; |
1004 | } | 1005 | } |
1005 | attributeArray.__export__ = false; | 1006 | attributeArray.__export__ = false; |
1006 | this.attributeArray = attributeArray; | 1007 | this.attributeArray = attributeArray; |
1007 | 1008 | ||
1008 | // Backwards compatibility aliases | 1009 | // Backwards compatibility aliases |
1009 | /** @id MochiKit.DOM.computedStyle */ | 1010 | /** @id MochiKit.DOM.computedStyle */ |
1010 | m._deprecated(this, 'computedStyle', 'MochiKit.Style.getStyle', '1.4'); | 1011 | m._deprecated(this, 'computedStyle', 'MochiKit.Style.getStyle', '1.4', true); |
1011 | /** @id MochiKit.DOM.elementDimensions */ | 1012 | /** @id MochiKit.DOM.elementDimensions */ |
1012 | m._deprecated(this, 'elementDimensions', 'MochiKit.Style.getElementDimensions', '1.4'); | 1013 | m._deprecated(this, 'elementDimensions', 'MochiKit.Style.getElementDimensions', '1.4'); |
1013 | /** @id MochiKit.DOM.elementPosition */ | 1014 | /** @id MochiKit.DOM.elementPosition */ |
1014 | m._deprecated(this, 'elementPosition', 'MochiKit.Style.getElementPosition', '1.4'); | 1015 | m._deprecated(this, 'elementPosition', 'MochiKit.Style.getElementPosition', '1.4'); |
1015 | /** @id MochiKit.DOM.getViewportDimensions */ | 1016 | /** @id MochiKit.DOM.getViewportDimensions */ |
1016 | m._deprecated(this, 'getViewportDimensions', 'MochiKit.Style.getViewportDimensions', '1.4'); | 1017 | m._deprecated(this, 'getViewportDimensions', 'MochiKit.Style.getViewportDimensions', '1.4'); |
1017 | /** @id MochiKit.DOM.hideElement */ | 1018 | /** @id MochiKit.DOM.hideElement */ |
1018 | m._deprecated(this, 'hideElement', 'MochiKit.Style.hideElement', '1.4'); | 1019 | m._deprecated(this, 'hideElement', 'MochiKit.Style.hideElement', '1.4'); |
1019 | /** @id MochiKit.DOM.makeClipping */ | 1020 | /** @id MochiKit.DOM.makeClipping */ |
1020 | m._deprecated(this, 'makeClipping', 'MochiKit.Style.makeClipping', '1.4.1'); | 1021 | m._deprecated(this, 'makeClipping', 'MochiKit.Style.makeClipping', '1.4.1'); |
1021 | /** @id MochiKit.DOM.makePositioned */ | 1022 | /** @id MochiKit.DOM.makePositioned */ |
1022 | m._deprecated(this, 'makePositioned', 'MochiKit.Style.makePositioned', '1.4.1'); | 1023 | m._deprecated(this, 'makePositioned', 'MochiKit.Style.makePositioned', '1.4.1'); |
1023 | /** @id MochiKit.DOM.setElementDimensions */ | 1024 | /** @id MochiKit.DOM.setElementDimensions */ |
1024 | m._deprecated(this, 'setElementDimensions', 'MochiKit.Style.setElementDimensions', '1.4'); | 1025 | m._deprecated(this, 'setElementDimensions', 'MochiKit.Style.setElementDimensions', '1.4'); |
1025 | /** @id MochiKit.DOM.setElementPosition */ | 1026 | /** @id MochiKit.DOM.setElementPosition */ |
1026 | m._deprecated(this, 'setElementPosition', 'MochiKit.Style.setElementPosition', '1.4'); | 1027 | m._deprecated(this, 'setElementPosition', 'MochiKit.Style.setElementPosition', '1.4'); |
1027 | /** @id MochiKit.DOM.setDisplayForElement */ | 1028 | /** @id MochiKit.DOM.setDisplayForElement */ |
1028 | m._deprecated(this, 'setDisplayForElement', 'MochiKit.Style.setDisplayForElement', '1.4'); | 1029 | m._deprecated(this, 'setDisplayForElement', 'MochiKit.Style.setDisplayForElement', '1.4'); |
1029 | /** @id MochiKit.DOM.setOpacity */ | 1030 | /** @id MochiKit.DOM.setOpacity */ |
1030 | m._deprecated(this, 'setOpacity', 'MochiKit.Style.setOpacity', '1.4'); | 1031 | m._deprecated(this, 'setOpacity', 'MochiKit.Style.setOpacity', '1.4'); |
1031 | /** @id MochiKit.DOM.showElement */ | 1032 | /** @id MochiKit.DOM.showElement */ |
1032 | m._deprecated(this, 'showElement', 'MochiKit.Style.showElement', '1.4'); | 1033 | m._deprecated(this, 'showElement', 'MochiKit.Style.showElement', '1.4'); |
1033 | /** @id MochiKit.DOM.undoClipping */ | 1034 | /** @id MochiKit.DOM.undoClipping */ |
1034 | m._deprecated(this, 'undoClipping', 'MochiKit.Style.undoClipping', '1.4.1'); | 1035 | m._deprecated(this, 'undoClipping', 'MochiKit.Style.undoClipping', '1.4.1'); |
1035 | /** @id MochiKit.DOM.undoPositioned */ | 1036 | /** @id MochiKit.DOM.undoPositioned */ |
1036 | m._deprecated(this, 'undoPositioned', 'MochiKit.Style.undoPositioned', '1.4.1'); | 1037 | m._deprecated(this, 'undoPositioned', 'MochiKit.Style.undoPositioned', '1.4.1'); |
1037 | /** @id MochiKit.DOM.Coordinates */ | 1038 | /** @id MochiKit.DOM.Coordinates */ |
1038 | m._deprecated(this, 'Coordinates', 'MochiKit.Style.Coordinates', '1.4'); | 1039 | m._deprecated(this, 'Coordinates', 'MochiKit.Style.Coordinates', '1.4'); |
1039 | /** @id MochiKit.DOM.Dimensions */ | 1040 | /** @id MochiKit.DOM.Dimensions */ |
1040 | m._deprecated(this, 'Dimensions', 'MochiKit.Style.Dimensions', '1.4'); | 1041 | m._deprecated(this, 'Dimensions', 'MochiKit.Style.Dimensions', '1.4'); |
1041 | 1042 | ||
1042 | // shorthand for createDOM syntax | 1043 | // shorthand for createDOM syntax |
1043 | var createDOMFunc = this.createDOMFunc; | 1044 | var createDOMFunc = this.createDOMFunc; |
1044 | /** @id MochiKit.DOM.UL */ | ||
1045 | this.UL = createDOMFunc("ul"); | ||
1046 | /** @id MochiKit.DOM.OL */ | ||
1047 | this.OL = createDOMFunc("ol"); | ||
1048 | /** @id MochiKit.DOM.LI */ | ||
1049 | this.LI = createDOMFunc("li"); | ||
1050 | /** @id MochiKit.DOM.DL */ | ||
1051 | this.DL = createDOMFunc("dl"); | ||
1052 | /** @id MochiKit.DOM.DT */ | ||
1053 | this.DT = createDOMFunc("dt"); | ||
1054 | /** @id MochiKit.DOM.DD */ | ||
1055 | this.DD = createDOMFunc("dd"); | ||
1056 | /** @id MochiKit.DOM.TD */ | ||
1057 | this.TD = createDOMFunc("td"); | ||
1058 | /** @id MochiKit.DOM.TR */ | ||
1059 | this.TR = createDOMFunc("tr"); | ||
1060 | /** @id MochiKit.DOM.TBODY */ | ||
1061 | this.TBODY = createDOMFunc("tbody"); | ||
1062 | /** @id MochiKit.DOM.THEAD */ | ||
1063 | this.THEAD = createDOMFunc("thead"); | ||
1064 | /** @id MochiKit.DOM.TFOOT */ | ||
1065 | this.TFOOT = createDOMFunc("tfoot"); | ||
1066 | /** @id MochiKit.DOM.TABLE */ | ||
1067 | this.TABLE = createDOMFunc("table"); | ||
1068 | /** @id MochiKit.DOM.TH */ | ||
1069 | this.TH = createDOMFunc("th"); | ||
1070 | /** @id MochiKit.DOM.INPUT */ | ||
1071 | this.INPUT = createDOMFunc("input"); | ||
1072 | /** @id MochiKit.DOM.SPAN */ | ||
1073 | this.SPAN = createDOMFunc("span"); | ||
1074 | /** @id MochiKit.DOM.A */ | 1045 | /** @id MochiKit.DOM.A */ |
1075 | this.A = createDOMFunc("a"); | 1046 | this.A = createDOMFunc("a"); |
1076 | /** @id MochiKit.DOM.DIV */ | 1047 | /** @id MochiKit.DOM.ARTICLE */ |
1077 | this.DIV = createDOMFunc("div"); | 1048 | this.ARTICLE = createDOMFunc("article"); |
1078 | /** @id MochiKit.DOM.IMG */ | 1049 | /** @id MochiKit.DOM.ASIDE */ |
1079 | this.IMG = createDOMFunc("img"); | 1050 | this.ASIDE = createDOMFunc("aside"); |
1051 | /** @id MochiKit.DOM.BR */ | ||
1052 | this.BR = createDOMFunc("br"); | ||
1080 | /** @id MochiKit.DOM.BUTTON */ | 1053 | /** @id MochiKit.DOM.BUTTON */ |
1081 | this.BUTTON = createDOMFunc("button"); | 1054 | this.BUTTON = createDOMFunc("button"); |
1082 | /** @id MochiKit.DOM.TT */ | 1055 | /** @id MochiKit.DOM.CANVAS */ |
1083 | this.TT = createDOMFunc("tt"); | 1056 | this.CANVAS = createDOMFunc("canvas"); |
1084 | /** @id MochiKit.DOM.PRE */ | 1057 | /** @id MochiKit.DOM.CAPTION */ |
1085 | this.PRE = createDOMFunc("pre"); | 1058 | this.CAPTION = createDOMFunc("caption"); |
1059 | /** @id MochiKit.DOM.DD */ | ||
1060 | this.DD = createDOMFunc("dd"); | ||
1061 | /** @id MochiKit.DOM.DIV */ | ||
1062 | this.DIV = createDOMFunc("div"); | ||
1063 | /** @id MochiKit.DOM.DL */ | ||
1064 | this.DL = createDOMFunc("dl"); | ||
1065 | /** @id MochiKit.DOM.DT */ | ||
1066 | this.DT = createDOMFunc("dt"); | ||
1067 | /** @id MochiKit.DOM.FIELDSET */ | ||
1068 | this.FIELDSET = createDOMFunc("fieldset"); | ||
1069 | /** @id MochiKit.DOM.FIGURE */ | ||
1070 | this.FIGURE = createDOMFunc("figure"); | ||
1071 | /** @id MochiKit.DOM.FIGCAPTION */ | ||
1072 | this.FIGCAPTION = createDOMFunc("figcaption"); | ||
1073 | /** @id MochiKit.DOM.FOOTER */ | ||
1074 | this.FOOTER = createDOMFunc("footer"); | ||
1075 | /** @id MochiKit.DOM.FORM */ | ||
1076 | this.FORM = createDOMFunc("form"); | ||
1086 | /** @id MochiKit.DOM.H1 */ | 1077 | /** @id MochiKit.DOM.H1 */ |
1087 | this.H1 = createDOMFunc("h1"); | 1078 | this.H1 = createDOMFunc("h1"); |
1088 | /** @id MochiKit.DOM.H2 */ | 1079 | /** @id MochiKit.DOM.H2 */ |
1089 | this.H2 = createDOMFunc("h2"); | 1080 | this.H2 = createDOMFunc("h2"); |
1090 | /** @id MochiKit.DOM.H3 */ | 1081 | /** @id MochiKit.DOM.H3 */ |
1091 | this.H3 = createDOMFunc("h3"); | 1082 | this.H3 = createDOMFunc("h3"); |
1092 | /** @id MochiKit.DOM.H4 */ | 1083 | /** @id MochiKit.DOM.H4 */ |
1093 | this.H4 = createDOMFunc("h4"); | 1084 | this.H4 = createDOMFunc("h4"); |
1094 | /** @id MochiKit.DOM.H5 */ | 1085 | /** @id MochiKit.DOM.H5 */ |
1095 | this.H5 = createDOMFunc("h5"); | 1086 | this.H5 = createDOMFunc("h5"); |
1096 | /** @id MochiKit.DOM.H6 */ | 1087 | /** @id MochiKit.DOM.H6 */ |
1097 | this.H6 = createDOMFunc("h6"); | 1088 | this.H6 = createDOMFunc("h6"); |
1098 | /** @id MochiKit.DOM.BR */ | 1089 | /** @id MochiKit.DOM.HEADER */ |
1099 | this.BR = createDOMFunc("br"); | 1090 | this.HEADER = createDOMFunc("header"); |
1091 | /** @id MochiKit.DOM.HGROUP */ | ||
1092 | this.HGROUP = createDOMFunc("hgroup"); | ||
1100 | /** @id MochiKit.DOM.HR */ | 1093 | /** @id MochiKit.DOM.HR */ |
1101 | this.HR = createDOMFunc("hr"); | 1094 | this.HR = createDOMFunc("hr"); |
1095 | /** @id MochiKit.DOM.IFRAME */ | ||
1096 | this.IFRAME = createDOMFunc("iframe"); | ||
1097 | /** @id MochiKit.DOM.IMG */ | ||
1098 | this.IMG = createDOMFunc("img"); | ||
1099 | /** @id MochiKit.DOM.INPUT */ | ||
1100 | this.INPUT = createDOMFunc("input"); | ||
1102 | /** @id MochiKit.DOM.LABEL */ | 1101 | /** @id MochiKit.DOM.LABEL */ |
1103 | this.LABEL = createDOMFunc("label"); | 1102 | this.LABEL = createDOMFunc("label"); |
1104 | /** @id MochiKit.DOM.TEXTAREA */ | 1103 | /** @id MochiKit.DOM.LEGEND */ |
1105 | this.TEXTAREA = createDOMFunc("textarea"); | 1104 | this.LEGEND = createDOMFunc("legend"); |
1106 | /** @id MochiKit.DOM.FORM */ | 1105 | /** @id MochiKit.DOM.LI */ |
1107 | this.FORM = createDOMFunc("form"); | 1106 | this.LI = createDOMFunc("li"); |
1107 | /** @id MochiKit.DOM.LINK */ | ||
1108 | this.LINK = createDOMFunc("link"); | ||
1109 | /** @id MochiKit.DOM.MARK */ | ||
1110 | this.MARK = createDOMFunc("mark"); | ||
1111 | /** @id MochiKit.DOM.METER */ | ||
1112 | this.METER = createDOMFunc("meter"); | ||
1113 | /** @id MochiKit.DOM.NAV */ | ||
1114 | this.NAV = createDOMFunc("nav"); | ||
1115 | /** @id MochiKit.DOM.OL */ | ||
1116 | this.OL = createDOMFunc("ol"); | ||
1117 | /** @id MochiKit.DOM.OPTGROUP */ | ||
1118 | this.OPTGROUP = createDOMFunc("optgroup"); | ||
1119 | /** @id MochiKit.DOM.OPTION */ | ||
1120 | this.OPTION = createDOMFunc("option"); | ||
1108 | /** @id MochiKit.DOM.P */ | 1121 | /** @id MochiKit.DOM.P */ |
1109 | this.P = createDOMFunc("p"); | 1122 | this.P = createDOMFunc("p"); |
1123 | /** @id MochiKit.DOM.PRE */ | ||
1124 | this.PRE = createDOMFunc("pre"); | ||
1125 | /** @id MochiKit.DOM.PROGRESS */ | ||
1126 | this.PROGRESS = createDOMFunc("progress"); | ||
1127 | /** @id MochiKit.DOM.SCRIPT */ | ||
1128 | this.SCRIPT = createDOMFunc("script"); | ||
1129 | /** @id MochiKit.DOM.SECTION */ | ||
1130 | this.SECTION = createDOMFunc("section"); | ||
1110 | /** @id MochiKit.DOM.SELECT */ | 1131 | /** @id MochiKit.DOM.SELECT */ |
1111 | this.SELECT = createDOMFunc("select"); | 1132 | this.SELECT = createDOMFunc("select"); |
1112 | /** @id MochiKit.DOM.OPTION */ | 1133 | /** @id MochiKit.DOM.SPAN */ |
1113 | this.OPTION = createDOMFunc("option"); | 1134 | this.SPAN = createDOMFunc("span"); |
1114 | /** @id MochiKit.DOM.OPTGROUP */ | ||
1115 | this.OPTGROUP = createDOMFunc("optgroup"); | ||
1116 | /** @id MochiKit.DOM.LEGEND */ | ||
1117 | this.LEGEND = createDOMFunc("legend"); | ||
1118 | /** @id MochiKit.DOM.FIELDSET */ | ||
1119 | this.FIELDSET = createDOMFunc("fieldset"); | ||
1120 | /** @id MochiKit.DOM.STRONG */ | 1135 | /** @id MochiKit.DOM.STRONG */ |
1121 | this.STRONG = createDOMFunc("strong"); | 1136 | this.STRONG = createDOMFunc("strong"); |
1122 | /** @id MochiKit.DOM.CANVAS */ | 1137 | /** @id MochiKit.DOM.STYLE */ |
1123 | this.CANVAS = createDOMFunc("canvas"); | 1138 | this.STYLE = createDOMFunc("style"); |
1124 | 1139 | /** @id MochiKit.DOM.TABLE */ | |
1140 | this.TABLE = createDOMFunc("table"); | ||
1141 | /** @id MochiKit.DOM.TBODY */ | ||
1142 | this.TBODY = createDOMFunc("tbody"); | ||
1143 | /** @id MochiKit.DOM.TD */ | ||
1144 | this.TD = createDOMFunc("td"); | ||
1145 | /** @id MochiKit.DOM.TEXTAREA */ | ||
1146 | this.TEXTAREA = createDOMFunc("textarea"); | ||
1147 | /** @id MochiKit.DOM.TFOOT */ | ||
1148 | this.TFOOT = createDOMFunc("tfoot"); | ||
1149 | /** @id MochiKit.DOM.TH */ | ||
1150 | this.TH = createDOMFunc("th"); | ||
1151 | /** @id MochiKit.DOM.THEAD */ | ||
1152 | this.THEAD = createDOMFunc("thead"); | ||
1153 | /** @id MochiKit.DOM.TR */ | ||
1154 | this.TR = createDOMFunc("tr"); | ||
1155 | /** @id MochiKit.DOM.TT */ | ||
1156 | this.TT = createDOMFunc("tt"); | ||
1157 | /** @id MochiKit.DOM.UL */ | ||
1158 | this.UL = createDOMFunc("ul"); | ||
1159 | /** @id MochiKit.DOM.NBSP */ | ||
1160 | this.NBSP = "\u00a0"; | ||
1125 | /** @id MochiKit.DOM.$ */ | 1161 | /** @id MochiKit.DOM.$ */ |
1126 | this.$ = this.getElement; | 1162 | this.$ = this.getElement; |
1127 | 1163 | ||
1128 | m.nameFunctions(this); | 1164 | m.nameFunctions(this); |
1129 | |||
1130 | } | 1165 | } |
1131 | }); | 1166 | }); |
1132 | 1167 | ||
1133 | 1168 | ||
1134 | MochiKit.DOM.__new__(((typeof(window) == "undefined") ? this : window)); | 1169 | MochiKit.DOM.__new__(((typeof(window) == "undefined") ? this : window)); |
1135 | 1170 | ||
1136 | // | 1171 | // |
1137 | // XXX: Internet Explorer blows | 1172 | // XXX: Internet Explorer blows |
1138 | // | 1173 | // |
1139 | if (MochiKit.__export__) { | 1174 | if (MochiKit.__export__) { |
1140 | withWindow = MochiKit.DOM.withWindow; | 1175 | withWindow = MochiKit.DOM.withWindow; |
1141 | withDocument = MochiKit.DOM.withDocument; | 1176 | withDocument = MochiKit.DOM.withDocument; |
1142 | } | 1177 | } |
1143 | 1178 | ||
1144 | MochiKit.Base._exportSymbols(this, MochiKit.DOM); | 1179 | MochiKit.Base._exportSymbols(this, MochiKit.DOM); |