Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /*** |
michael@0 | 2 | |
michael@0 | 3 | MochiKit.DOM 1.4 |
michael@0 | 4 | |
michael@0 | 5 | See <http://mochikit.com/> for documentation, downloads, license, etc. |
michael@0 | 6 | |
michael@0 | 7 | (c) 2005 Bob Ippolito. All rights Reserved. |
michael@0 | 8 | |
michael@0 | 9 | ***/ |
michael@0 | 10 | |
michael@0 | 11 | if (typeof(dojo) != 'undefined') { |
michael@0 | 12 | dojo.provide("MochiKit.DOM"); |
michael@0 | 13 | dojo.require("MochiKit.Base"); |
michael@0 | 14 | } |
michael@0 | 15 | if (typeof(JSAN) != 'undefined') { |
michael@0 | 16 | JSAN.use("MochiKit.Base", []); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | try { |
michael@0 | 20 | if (typeof(MochiKit.Base) == 'undefined') { |
michael@0 | 21 | throw ""; |
michael@0 | 22 | } |
michael@0 | 23 | } catch (e) { |
michael@0 | 24 | throw "MochiKit.DOM depends on MochiKit.Base!"; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | if (typeof(MochiKit.DOM) == 'undefined') { |
michael@0 | 28 | MochiKit.DOM = {}; |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | MochiKit.DOM.NAME = "MochiKit.DOM"; |
michael@0 | 32 | MochiKit.DOM.VERSION = "1.4"; |
michael@0 | 33 | MochiKit.DOM.__repr__ = function () { |
michael@0 | 34 | return "[" + this.NAME + " " + this.VERSION + "]"; |
michael@0 | 35 | }; |
michael@0 | 36 | MochiKit.DOM.toString = function () { |
michael@0 | 37 | return this.__repr__(); |
michael@0 | 38 | }; |
michael@0 | 39 | |
michael@0 | 40 | MochiKit.DOM.EXPORT = [ |
michael@0 | 41 | "removeEmptyTextNodes", |
michael@0 | 42 | "formContents", |
michael@0 | 43 | "currentWindow", |
michael@0 | 44 | "currentDocument", |
michael@0 | 45 | "withWindow", |
michael@0 | 46 | "withDocument", |
michael@0 | 47 | "registerDOMConverter", |
michael@0 | 48 | "coerceToDOM", |
michael@0 | 49 | "createDOM", |
michael@0 | 50 | "createDOMFunc", |
michael@0 | 51 | "isChildNode", |
michael@0 | 52 | "getNodeAttribute", |
michael@0 | 53 | "setNodeAttribute", |
michael@0 | 54 | "updateNodeAttributes", |
michael@0 | 55 | "appendChildNodes", |
michael@0 | 56 | "replaceChildNodes", |
michael@0 | 57 | "removeElement", |
michael@0 | 58 | "swapDOM", |
michael@0 | 59 | "BUTTON", |
michael@0 | 60 | "TT", |
michael@0 | 61 | "PRE", |
michael@0 | 62 | "H1", |
michael@0 | 63 | "H2", |
michael@0 | 64 | "H3", |
michael@0 | 65 | "BR", |
michael@0 | 66 | "CANVAS", |
michael@0 | 67 | "HR", |
michael@0 | 68 | "LABEL", |
michael@0 | 69 | "TEXTAREA", |
michael@0 | 70 | "FORM", |
michael@0 | 71 | "STRONG", |
michael@0 | 72 | "SELECT", |
michael@0 | 73 | "OPTION", |
michael@0 | 74 | "OPTGROUP", |
michael@0 | 75 | "LEGEND", |
michael@0 | 76 | "FIELDSET", |
michael@0 | 77 | "P", |
michael@0 | 78 | "UL", |
michael@0 | 79 | "OL", |
michael@0 | 80 | "LI", |
michael@0 | 81 | "TD", |
michael@0 | 82 | "TR", |
michael@0 | 83 | "THEAD", |
michael@0 | 84 | "TBODY", |
michael@0 | 85 | "TFOOT", |
michael@0 | 86 | "TABLE", |
michael@0 | 87 | "TH", |
michael@0 | 88 | "INPUT", |
michael@0 | 89 | "SPAN", |
michael@0 | 90 | "A", |
michael@0 | 91 | "DIV", |
michael@0 | 92 | "IMG", |
michael@0 | 93 | "getElement", |
michael@0 | 94 | "$", |
michael@0 | 95 | "getElementsByTagAndClassName", |
michael@0 | 96 | "addToCallStack", |
michael@0 | 97 | "addLoadEvent", |
michael@0 | 98 | "focusOnLoad", |
michael@0 | 99 | "setElementClass", |
michael@0 | 100 | "toggleElementClass", |
michael@0 | 101 | "addElementClass", |
michael@0 | 102 | "removeElementClass", |
michael@0 | 103 | "swapElementClass", |
michael@0 | 104 | "hasElementClass", |
michael@0 | 105 | "escapeHTML", |
michael@0 | 106 | "toHTML", |
michael@0 | 107 | "emitHTML", |
michael@0 | 108 | "scrapeText" |
michael@0 | 109 | ]; |
michael@0 | 110 | |
michael@0 | 111 | MochiKit.DOM.EXPORT_OK = [ |
michael@0 | 112 | "domConverters" |
michael@0 | 113 | ]; |
michael@0 | 114 | |
michael@0 | 115 | MochiKit.DOM.DEPRECATED = [ |
michael@0 | 116 | ['computedStyle', 'MochiKit.Style.computedStyle', '1.4'], |
michael@0 | 117 | /** @id MochiKit.DOM.elementDimensions */ |
michael@0 | 118 | ['elementDimensions', 'MochiKit.Style.getElementDimensions', '1.4'], |
michael@0 | 119 | /** @id MochiKit.DOM.elementPosition */ |
michael@0 | 120 | ['elementPosition', 'MochiKit.Style.getElementPosition', '1.4'], |
michael@0 | 121 | ['hideElement', 'MochiKit.Style.hideElement', '1.4'], |
michael@0 | 122 | /** @id MochiKit.DOM.setElementDimensions */ |
michael@0 | 123 | ['setElementDimensions', 'MochiKit.Style.setElementDimensions', '1.4'], |
michael@0 | 124 | /** @id MochiKit.DOM.setElementPosition */ |
michael@0 | 125 | ['setElementPosition', 'MochiKit.Style.setElementPosition', '1.4'], |
michael@0 | 126 | ['setDisplayForElement', 'MochiKit.Style.setDisplayForElement', '1.4'], |
michael@0 | 127 | /** @id MochiKit.DOM.setOpacity */ |
michael@0 | 128 | ['setOpacity', 'MochiKit.Style.setOpacity', '1.4'], |
michael@0 | 129 | ['showElement', 'MochiKit.Style.showElement', '1.4'], |
michael@0 | 130 | /** @id MochiKit.DOM.Coordinates */ |
michael@0 | 131 | ['Coordinates', 'MochiKit.Style.Coordinates', '1.4'], // FIXME: broken |
michael@0 | 132 | /** @id MochiKit.DOM.Dimensions */ |
michael@0 | 133 | ['Dimensions', 'MochiKit.Style.Dimensions', '1.4'] // FIXME: broken |
michael@0 | 134 | ]; |
michael@0 | 135 | |
michael@0 | 136 | /** @id MochiKit.DOM.getViewportDimensions */ |
michael@0 | 137 | MochiKit.DOM.getViewportDimensions = new Function('' + |
michael@0 | 138 | 'if (!MochiKit["Style"]) {' + |
michael@0 | 139 | ' throw new Error("This function has been deprecated and depends on MochiKit.Style.");' + |
michael@0 | 140 | '}' + |
michael@0 | 141 | 'return MochiKit.Style.getViewportDimensions.apply(this, arguments);'); |
michael@0 | 142 | |
michael@0 | 143 | MochiKit.Base.update(MochiKit.DOM, { |
michael@0 | 144 | |
michael@0 | 145 | /** @id MochiKit.DOM.currentWindow */ |
michael@0 | 146 | currentWindow: function () { |
michael@0 | 147 | return MochiKit.DOM._window; |
michael@0 | 148 | }, |
michael@0 | 149 | |
michael@0 | 150 | /** @id MochiKit.DOM.currentDocument */ |
michael@0 | 151 | currentDocument: function () { |
michael@0 | 152 | return MochiKit.DOM._document; |
michael@0 | 153 | }, |
michael@0 | 154 | |
michael@0 | 155 | /** @id MochiKit.DOM.withWindow */ |
michael@0 | 156 | withWindow: function (win, func) { |
michael@0 | 157 | var self = MochiKit.DOM; |
michael@0 | 158 | var oldDoc = self._document; |
michael@0 | 159 | var oldWin = self._win; |
michael@0 | 160 | var rval; |
michael@0 | 161 | try { |
michael@0 | 162 | self._window = win; |
michael@0 | 163 | self._document = win.document; |
michael@0 | 164 | rval = func(); |
michael@0 | 165 | } catch (e) { |
michael@0 | 166 | self._window = oldWin; |
michael@0 | 167 | self._document = oldDoc; |
michael@0 | 168 | throw e; |
michael@0 | 169 | } |
michael@0 | 170 | self._window = oldWin; |
michael@0 | 171 | self._document = oldDoc; |
michael@0 | 172 | return rval; |
michael@0 | 173 | }, |
michael@0 | 174 | |
michael@0 | 175 | /** @id MochiKit.DOM.formContents */ |
michael@0 | 176 | formContents: function (elem/* = document */) { |
michael@0 | 177 | var names = []; |
michael@0 | 178 | var values = []; |
michael@0 | 179 | var m = MochiKit.Base; |
michael@0 | 180 | var self = MochiKit.DOM; |
michael@0 | 181 | if (typeof(elem) == "undefined" || elem === null) { |
michael@0 | 182 | elem = self._document; |
michael@0 | 183 | } else { |
michael@0 | 184 | elem = self.getElement(elem); |
michael@0 | 185 | } |
michael@0 | 186 | m.nodeWalk(elem, function (elem) { |
michael@0 | 187 | var name = elem.name; |
michael@0 | 188 | if (m.isNotEmpty(name)) { |
michael@0 | 189 | var tagName = elem.tagName.toUpperCase(); |
michael@0 | 190 | if (tagName === "INPUT" |
michael@0 | 191 | && (elem.type == "radio" || elem.type == "checkbox") |
michael@0 | 192 | && !elem.checked |
michael@0 | 193 | ) { |
michael@0 | 194 | return null; |
michael@0 | 195 | } |
michael@0 | 196 | if (tagName === "SELECT") { |
michael@0 | 197 | if (elem.type == "select-one") { |
michael@0 | 198 | if (elem.selectedIndex >= 0) { |
michael@0 | 199 | var opt = elem.options[elem.selectedIndex]; |
michael@0 | 200 | names.push(name); |
michael@0 | 201 | values.push(opt.value); |
michael@0 | 202 | return null; |
michael@0 | 203 | } |
michael@0 | 204 | // no form elements? |
michael@0 | 205 | names.push(name); |
michael@0 | 206 | values.push(""); |
michael@0 | 207 | return null; |
michael@0 | 208 | } else { |
michael@0 | 209 | var opts = elem.options; |
michael@0 | 210 | if (!opts.length) { |
michael@0 | 211 | names.push(name); |
michael@0 | 212 | values.push(""); |
michael@0 | 213 | return null; |
michael@0 | 214 | } |
michael@0 | 215 | for (var i = 0; i < opts.length; i++) { |
michael@0 | 216 | var opt = opts[i]; |
michael@0 | 217 | if (!opt.selected) { |
michael@0 | 218 | continue; |
michael@0 | 219 | } |
michael@0 | 220 | names.push(name); |
michael@0 | 221 | values.push(opt.value); |
michael@0 | 222 | } |
michael@0 | 223 | return null; |
michael@0 | 224 | } |
michael@0 | 225 | } |
michael@0 | 226 | if (tagName === "FORM" || tagName === "P" || tagName === "SPAN" |
michael@0 | 227 | || tagName === "DIV" |
michael@0 | 228 | ) { |
michael@0 | 229 | return elem.childNodes; |
michael@0 | 230 | } |
michael@0 | 231 | names.push(name); |
michael@0 | 232 | values.push(elem.value || ''); |
michael@0 | 233 | return null; |
michael@0 | 234 | } |
michael@0 | 235 | return elem.childNodes; |
michael@0 | 236 | }); |
michael@0 | 237 | return [names, values]; |
michael@0 | 238 | }, |
michael@0 | 239 | |
michael@0 | 240 | /** @id MochiKit.DOM.withDocument */ |
michael@0 | 241 | withDocument: function (doc, func) { |
michael@0 | 242 | var self = MochiKit.DOM; |
michael@0 | 243 | var oldDoc = self._document; |
michael@0 | 244 | var rval; |
michael@0 | 245 | try { |
michael@0 | 246 | self._document = doc; |
michael@0 | 247 | rval = func(); |
michael@0 | 248 | } catch (e) { |
michael@0 | 249 | self._document = oldDoc; |
michael@0 | 250 | throw e; |
michael@0 | 251 | } |
michael@0 | 252 | self._document = oldDoc; |
michael@0 | 253 | return rval; |
michael@0 | 254 | }, |
michael@0 | 255 | |
michael@0 | 256 | /** @id MochiKit.DOM.registerDOMConverter */ |
michael@0 | 257 | registerDOMConverter: function (name, check, wrap, /* optional */override) { |
michael@0 | 258 | MochiKit.DOM.domConverters.register(name, check, wrap, override); |
michael@0 | 259 | }, |
michael@0 | 260 | |
michael@0 | 261 | /** @id MochiKit.DOM.coerceToDOM */ |
michael@0 | 262 | coerceToDOM: function (node, ctx) { |
michael@0 | 263 | var m = MochiKit.Base; |
michael@0 | 264 | var im = MochiKit.Iter; |
michael@0 | 265 | var self = MochiKit.DOM; |
michael@0 | 266 | if (im) { |
michael@0 | 267 | var iter = im.iter; |
michael@0 | 268 | var repeat = im.repeat; |
michael@0 | 269 | var map = m.map; |
michael@0 | 270 | } |
michael@0 | 271 | var domConverters = self.domConverters; |
michael@0 | 272 | var coerceToDOM = arguments.callee; |
michael@0 | 273 | var NotFound = m.NotFound; |
michael@0 | 274 | while (true) { |
michael@0 | 275 | if (typeof(node) == 'undefined' || node === null) { |
michael@0 | 276 | return null; |
michael@0 | 277 | } |
michael@0 | 278 | if (typeof(node.nodeType) != 'undefined' && node.nodeType > 0) { |
michael@0 | 279 | return node; |
michael@0 | 280 | } |
michael@0 | 281 | if (typeof(node) == 'number' || typeof(node) == 'boolean') { |
michael@0 | 282 | node = node.toString(); |
michael@0 | 283 | // FALL THROUGH |
michael@0 | 284 | } |
michael@0 | 285 | if (typeof(node) == 'string') { |
michael@0 | 286 | return self._document.createTextNode(node); |
michael@0 | 287 | } |
michael@0 | 288 | if (typeof(node.__dom__) == 'function') { |
michael@0 | 289 | node = node.__dom__(ctx); |
michael@0 | 290 | continue; |
michael@0 | 291 | } |
michael@0 | 292 | if (typeof(node.dom) == 'function') { |
michael@0 | 293 | node = node.dom(ctx); |
michael@0 | 294 | continue; |
michael@0 | 295 | } |
michael@0 | 296 | if (typeof(node) == 'function') { |
michael@0 | 297 | node = node.apply(ctx, [ctx]); |
michael@0 | 298 | continue; |
michael@0 | 299 | } |
michael@0 | 300 | |
michael@0 | 301 | if (im) { |
michael@0 | 302 | // iterable |
michael@0 | 303 | var iterNodes = null; |
michael@0 | 304 | try { |
michael@0 | 305 | iterNodes = iter(node); |
michael@0 | 306 | } catch (e) { |
michael@0 | 307 | // pass |
michael@0 | 308 | } |
michael@0 | 309 | if (iterNodes) { |
michael@0 | 310 | return map(coerceToDOM, iterNodes, repeat(ctx)); |
michael@0 | 311 | } |
michael@0 | 312 | } |
michael@0 | 313 | |
michael@0 | 314 | // adapter |
michael@0 | 315 | try { |
michael@0 | 316 | node = domConverters.match(node, ctx); |
michael@0 | 317 | continue; |
michael@0 | 318 | } catch (e) { |
michael@0 | 319 | if (e != NotFound) { |
michael@0 | 320 | throw e; |
michael@0 | 321 | } |
michael@0 | 322 | } |
michael@0 | 323 | |
michael@0 | 324 | // fallback |
michael@0 | 325 | return self._document.createTextNode(node.toString()); |
michael@0 | 326 | } |
michael@0 | 327 | // mozilla warnings aren't too bright |
michael@0 | 328 | return undefined; |
michael@0 | 329 | }, |
michael@0 | 330 | |
michael@0 | 331 | /** @id MochiKit.DOM.isChildNode */ |
michael@0 | 332 | isChildNode: function (node, maybeparent) { |
michael@0 | 333 | var self = MochiKit.DOM; |
michael@0 | 334 | if (typeof(node) == "string") { |
michael@0 | 335 | node = self.getElement(node); |
michael@0 | 336 | } |
michael@0 | 337 | if (typeof(maybeparent) == "string") { |
michael@0 | 338 | maybeparent = self.getElement(maybeparent); |
michael@0 | 339 | } |
michael@0 | 340 | if (node === maybeparent) { |
michael@0 | 341 | return true; |
michael@0 | 342 | } |
michael@0 | 343 | while (node && node.tagName.toUpperCase() != "BODY") { |
michael@0 | 344 | node = node.parentNode; |
michael@0 | 345 | if (node === maybeparent) { |
michael@0 | 346 | return true; |
michael@0 | 347 | } |
michael@0 | 348 | } |
michael@0 | 349 | return false; |
michael@0 | 350 | }, |
michael@0 | 351 | |
michael@0 | 352 | /** @id MochiKit.DOM.setNodeAttribute */ |
michael@0 | 353 | setNodeAttribute: function (node, attr, value) { |
michael@0 | 354 | var o = {}; |
michael@0 | 355 | o[attr] = value; |
michael@0 | 356 | try { |
michael@0 | 357 | return MochiKit.DOM.updateNodeAttributes(node, o); |
michael@0 | 358 | } catch (e) { |
michael@0 | 359 | // pass |
michael@0 | 360 | } |
michael@0 | 361 | return null; |
michael@0 | 362 | }, |
michael@0 | 363 | |
michael@0 | 364 | /** @id MochiKit.DOM.getNodeAttribute */ |
michael@0 | 365 | getNodeAttribute: function (node, attr) { |
michael@0 | 366 | var self = MochiKit.DOM; |
michael@0 | 367 | var rename = self.attributeArray.renames[attr]; |
michael@0 | 368 | node = self.getElement(node); |
michael@0 | 369 | try { |
michael@0 | 370 | if (rename) { |
michael@0 | 371 | return node[rename]; |
michael@0 | 372 | } |
michael@0 | 373 | return node.getAttribute(attr); |
michael@0 | 374 | } catch (e) { |
michael@0 | 375 | // pass |
michael@0 | 376 | } |
michael@0 | 377 | return null; |
michael@0 | 378 | }, |
michael@0 | 379 | |
michael@0 | 380 | /** @id MochiKit.DOM.updateNodeAttributes */ |
michael@0 | 381 | updateNodeAttributes: function (node, attrs) { |
michael@0 | 382 | var elem = node; |
michael@0 | 383 | var self = MochiKit.DOM; |
michael@0 | 384 | if (typeof(node) == 'string') { |
michael@0 | 385 | elem = self.getElement(node); |
michael@0 | 386 | } |
michael@0 | 387 | if (attrs) { |
michael@0 | 388 | var updatetree = MochiKit.Base.updatetree; |
michael@0 | 389 | if (self.attributeArray.compliant) { |
michael@0 | 390 | // not IE, good. |
michael@0 | 391 | for (var k in attrs) { |
michael@0 | 392 | var v = attrs[k]; |
michael@0 | 393 | if (typeof(v) == 'object' && typeof(elem[k]) == 'object') { |
michael@0 | 394 | updatetree(elem[k], v); |
michael@0 | 395 | } else if (k.substring(0, 2) == "on") { |
michael@0 | 396 | if (typeof(v) == "string") { |
michael@0 | 397 | v = new Function(v); |
michael@0 | 398 | } |
michael@0 | 399 | elem[k] = v; |
michael@0 | 400 | } else { |
michael@0 | 401 | elem.setAttribute(k, v); |
michael@0 | 402 | } |
michael@0 | 403 | } |
michael@0 | 404 | } else { |
michael@0 | 405 | // IE is insane in the membrane |
michael@0 | 406 | var renames = self.attributeArray.renames; |
michael@0 | 407 | for (k in attrs) { |
michael@0 | 408 | v = attrs[k]; |
michael@0 | 409 | var renamed = renames[k]; |
michael@0 | 410 | if (k == "style" && typeof(v) == "string") { |
michael@0 | 411 | elem.style.cssText = v; |
michael@0 | 412 | } else if (typeof(renamed) == "string") { |
michael@0 | 413 | elem[renamed] = v; |
michael@0 | 414 | } else if (typeof(elem[k]) == 'object' |
michael@0 | 415 | && typeof(v) == 'object') { |
michael@0 | 416 | updatetree(elem[k], v); |
michael@0 | 417 | } else if (k.substring(0, 2) == "on") { |
michael@0 | 418 | if (typeof(v) == "string") { |
michael@0 | 419 | v = new Function(v); |
michael@0 | 420 | } |
michael@0 | 421 | elem[k] = v; |
michael@0 | 422 | } else { |
michael@0 | 423 | elem.setAttribute(k, v); |
michael@0 | 424 | } |
michael@0 | 425 | } |
michael@0 | 426 | } |
michael@0 | 427 | } |
michael@0 | 428 | return elem; |
michael@0 | 429 | }, |
michael@0 | 430 | |
michael@0 | 431 | /** @id MochiKit.DOM.appendChildNodes */ |
michael@0 | 432 | appendChildNodes: function (node/*, nodes...*/) { |
michael@0 | 433 | var elem = node; |
michael@0 | 434 | var self = MochiKit.DOM; |
michael@0 | 435 | if (typeof(node) == 'string') { |
michael@0 | 436 | elem = self.getElement(node); |
michael@0 | 437 | } |
michael@0 | 438 | var nodeStack = [ |
michael@0 | 439 | self.coerceToDOM( |
michael@0 | 440 | MochiKit.Base.extend(null, arguments, 1), |
michael@0 | 441 | elem |
michael@0 | 442 | ) |
michael@0 | 443 | ]; |
michael@0 | 444 | var concat = MochiKit.Base.concat; |
michael@0 | 445 | while (nodeStack.length) { |
michael@0 | 446 | var n = nodeStack.shift(); |
michael@0 | 447 | if (typeof(n) == 'undefined' || n === null) { |
michael@0 | 448 | // pass |
michael@0 | 449 | } else if (typeof(n.nodeType) == 'number') { |
michael@0 | 450 | elem.appendChild(n); |
michael@0 | 451 | } else { |
michael@0 | 452 | nodeStack = concat(n, nodeStack); |
michael@0 | 453 | } |
michael@0 | 454 | } |
michael@0 | 455 | return elem; |
michael@0 | 456 | }, |
michael@0 | 457 | |
michael@0 | 458 | /** @id MochiKit.DOM.replaceChildNodes */ |
michael@0 | 459 | replaceChildNodes: function (node/*, nodes...*/) { |
michael@0 | 460 | var elem = node; |
michael@0 | 461 | var self = MochiKit.DOM; |
michael@0 | 462 | if (typeof(node) == 'string') { |
michael@0 | 463 | elem = self.getElement(node); |
michael@0 | 464 | arguments[0] = elem; |
michael@0 | 465 | } |
michael@0 | 466 | var child; |
michael@0 | 467 | while ((child = elem.firstChild)) { |
michael@0 | 468 | elem.removeChild(child); |
michael@0 | 469 | } |
michael@0 | 470 | if (arguments.length < 2) { |
michael@0 | 471 | return elem; |
michael@0 | 472 | } else { |
michael@0 | 473 | return self.appendChildNodes.apply(this, arguments); |
michael@0 | 474 | } |
michael@0 | 475 | }, |
michael@0 | 476 | |
michael@0 | 477 | /** @id MochiKit.DOM.createDOM */ |
michael@0 | 478 | createDOM: function (name, attrs/*, nodes... */) { |
michael@0 | 479 | var elem; |
michael@0 | 480 | var self = MochiKit.DOM; |
michael@0 | 481 | var m = MochiKit.Base; |
michael@0 | 482 | if (typeof(attrs) == "string" || typeof(attrs) == "number") { |
michael@0 | 483 | var args = m.extend([name, null], arguments, 1); |
michael@0 | 484 | return arguments.callee.apply(this, args); |
michael@0 | 485 | } |
michael@0 | 486 | if (typeof(name) == 'string') { |
michael@0 | 487 | // Internet Explorer is dumb |
michael@0 | 488 | var xhtml = self._xhtml; |
michael@0 | 489 | if (attrs && !self.attributeArray.compliant) { |
michael@0 | 490 | // http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/name_2.asp |
michael@0 | 491 | var contents = ""; |
michael@0 | 492 | if ('name' in attrs) { |
michael@0 | 493 | contents += ' name="' + self.escapeHTML(attrs.name) + '"'; |
michael@0 | 494 | } |
michael@0 | 495 | if (name == 'input' && 'type' in attrs) { |
michael@0 | 496 | contents += ' type="' + self.escapeHTML(attrs.type) + '"'; |
michael@0 | 497 | } |
michael@0 | 498 | if (contents) { |
michael@0 | 499 | name = "<" + name + contents + ">"; |
michael@0 | 500 | xhtml = false; |
michael@0 | 501 | } |
michael@0 | 502 | } |
michael@0 | 503 | var d = self._document; |
michael@0 | 504 | if (xhtml && d === document) { |
michael@0 | 505 | elem = d.createElementNS("http://www.w3.org/1999/xhtml", name); |
michael@0 | 506 | } else { |
michael@0 | 507 | elem = d.createElement(name); |
michael@0 | 508 | } |
michael@0 | 509 | } else { |
michael@0 | 510 | elem = name; |
michael@0 | 511 | } |
michael@0 | 512 | if (attrs) { |
michael@0 | 513 | self.updateNodeAttributes(elem, attrs); |
michael@0 | 514 | } |
michael@0 | 515 | if (arguments.length <= 2) { |
michael@0 | 516 | return elem; |
michael@0 | 517 | } else { |
michael@0 | 518 | var args = m.extend([elem], arguments, 2); |
michael@0 | 519 | return self.appendChildNodes.apply(this, args); |
michael@0 | 520 | } |
michael@0 | 521 | }, |
michael@0 | 522 | |
michael@0 | 523 | /** @id MochiKit.DOM.createDOMFunc */ |
michael@0 | 524 | createDOMFunc: function (/* tag, attrs, *nodes */) { |
michael@0 | 525 | var m = MochiKit.Base; |
michael@0 | 526 | return m.partial.apply( |
michael@0 | 527 | this, |
michael@0 | 528 | m.extend([MochiKit.DOM.createDOM], arguments) |
michael@0 | 529 | ); |
michael@0 | 530 | }, |
michael@0 | 531 | |
michael@0 | 532 | /** @id MochiKit.DOM.removeElement */ |
michael@0 | 533 | removeElement: function (elem) { |
michael@0 | 534 | var e = MochiKit.DOM.getElement(elem); |
michael@0 | 535 | e.parentNode.removeChild(e); |
michael@0 | 536 | return e; |
michael@0 | 537 | }, |
michael@0 | 538 | |
michael@0 | 539 | /** @id MochiKit.DOM.swapDOM */ |
michael@0 | 540 | swapDOM: function (dest, src) { |
michael@0 | 541 | var self = MochiKit.DOM; |
michael@0 | 542 | dest = self.getElement(dest); |
michael@0 | 543 | var parent = dest.parentNode; |
michael@0 | 544 | if (src) { |
michael@0 | 545 | src = self.getElement(src); |
michael@0 | 546 | parent.replaceChild(src, dest); |
michael@0 | 547 | } else { |
michael@0 | 548 | parent.removeChild(dest); |
michael@0 | 549 | } |
michael@0 | 550 | return src; |
michael@0 | 551 | }, |
michael@0 | 552 | |
michael@0 | 553 | /** @id MochiKit.DOM.getElement */ |
michael@0 | 554 | getElement: function (id) { |
michael@0 | 555 | var self = MochiKit.DOM; |
michael@0 | 556 | if (arguments.length == 1) { |
michael@0 | 557 | return ((typeof(id) == "string") ? |
michael@0 | 558 | self._document.getElementById(id) : id); |
michael@0 | 559 | } else { |
michael@0 | 560 | return MochiKit.Base.map(self.getElement, arguments); |
michael@0 | 561 | } |
michael@0 | 562 | }, |
michael@0 | 563 | |
michael@0 | 564 | /** @id MochiKit.DOM.getElementsByTagAndClassName */ |
michael@0 | 565 | getElementsByTagAndClassName: function (tagName, className, |
michael@0 | 566 | /* optional */parent) { |
michael@0 | 567 | var self = MochiKit.DOM; |
michael@0 | 568 | if (typeof(tagName) == 'undefined' || tagName === null) { |
michael@0 | 569 | tagName = '*'; |
michael@0 | 570 | } |
michael@0 | 571 | if (typeof(parent) == 'undefined' || parent === null) { |
michael@0 | 572 | parent = self._document; |
michael@0 | 573 | } |
michael@0 | 574 | parent = self.getElement(parent); |
michael@0 | 575 | var children = (parent.getElementsByTagName(tagName) |
michael@0 | 576 | || self._document.all); |
michael@0 | 577 | if (typeof(className) == 'undefined' || className === null) { |
michael@0 | 578 | return MochiKit.Base.extend(null, children); |
michael@0 | 579 | } |
michael@0 | 580 | |
michael@0 | 581 | var elements = []; |
michael@0 | 582 | for (var i = 0; i < children.length; i++) { |
michael@0 | 583 | var child = children[i]; |
michael@0 | 584 | var cls = child.className; |
michael@0 | 585 | if (!cls) { |
michael@0 | 586 | continue; |
michael@0 | 587 | } |
michael@0 | 588 | var classNames = cls.split(' '); |
michael@0 | 589 | for (var j = 0; j < classNames.length; j++) { |
michael@0 | 590 | if (classNames[j] == className) { |
michael@0 | 591 | elements.push(child); |
michael@0 | 592 | break; |
michael@0 | 593 | } |
michael@0 | 594 | } |
michael@0 | 595 | } |
michael@0 | 596 | |
michael@0 | 597 | return elements; |
michael@0 | 598 | }, |
michael@0 | 599 | |
michael@0 | 600 | _newCallStack: function (path, once) { |
michael@0 | 601 | var rval = function () { |
michael@0 | 602 | var callStack = arguments.callee.callStack; |
michael@0 | 603 | for (var i = 0; i < callStack.length; i++) { |
michael@0 | 604 | if (callStack[i].apply(this, arguments) === false) { |
michael@0 | 605 | break; |
michael@0 | 606 | } |
michael@0 | 607 | } |
michael@0 | 608 | if (once) { |
michael@0 | 609 | try { |
michael@0 | 610 | this[path] = null; |
michael@0 | 611 | } catch (e) { |
michael@0 | 612 | // pass |
michael@0 | 613 | } |
michael@0 | 614 | } |
michael@0 | 615 | }; |
michael@0 | 616 | rval.callStack = []; |
michael@0 | 617 | return rval; |
michael@0 | 618 | }, |
michael@0 | 619 | |
michael@0 | 620 | /** @id MochiKit.DOM.addToCallStack */ |
michael@0 | 621 | addToCallStack: function (target, path, func, once) { |
michael@0 | 622 | var self = MochiKit.DOM; |
michael@0 | 623 | var existing = target[path]; |
michael@0 | 624 | var regfunc = existing; |
michael@0 | 625 | if (!(typeof(existing) == 'function' |
michael@0 | 626 | && typeof(existing.callStack) == "object" |
michael@0 | 627 | && existing.callStack !== null)) { |
michael@0 | 628 | regfunc = self._newCallStack(path, once); |
michael@0 | 629 | if (typeof(existing) == 'function') { |
michael@0 | 630 | regfunc.callStack.push(existing); |
michael@0 | 631 | } |
michael@0 | 632 | target[path] = regfunc; |
michael@0 | 633 | } |
michael@0 | 634 | regfunc.callStack.push(func); |
michael@0 | 635 | }, |
michael@0 | 636 | |
michael@0 | 637 | /** @id MochiKit.DOM.addLoadEvent */ |
michael@0 | 638 | addLoadEvent: function (func) { |
michael@0 | 639 | var self = MochiKit.DOM; |
michael@0 | 640 | self.addToCallStack(self._window, "onload", func, true); |
michael@0 | 641 | |
michael@0 | 642 | }, |
michael@0 | 643 | |
michael@0 | 644 | /** @id MochiKit.DOM.focusOnLoad */ |
michael@0 | 645 | focusOnLoad: function (element) { |
michael@0 | 646 | var self = MochiKit.DOM; |
michael@0 | 647 | self.addLoadEvent(function () { |
michael@0 | 648 | element = self.getElement(element); |
michael@0 | 649 | if (element) { |
michael@0 | 650 | element.focus(); |
michael@0 | 651 | } |
michael@0 | 652 | }); |
michael@0 | 653 | }, |
michael@0 | 654 | |
michael@0 | 655 | /** @id MochiKit.DOM.setElementClass */ |
michael@0 | 656 | setElementClass: function (element, className) { |
michael@0 | 657 | var self = MochiKit.DOM; |
michael@0 | 658 | var obj = self.getElement(element); |
michael@0 | 659 | if (self.attributeArray.compliant) { |
michael@0 | 660 | obj.setAttribute("class", className); |
michael@0 | 661 | } else { |
michael@0 | 662 | obj.setAttribute("className", className); |
michael@0 | 663 | } |
michael@0 | 664 | }, |
michael@0 | 665 | |
michael@0 | 666 | /** @id MochiKit.DOM.toggleElementClass */ |
michael@0 | 667 | toggleElementClass: function (className/*, element... */) { |
michael@0 | 668 | var self = MochiKit.DOM; |
michael@0 | 669 | for (var i = 1; i < arguments.length; i++) { |
michael@0 | 670 | var obj = self.getElement(arguments[i]); |
michael@0 | 671 | if (!self.addElementClass(obj, className)) { |
michael@0 | 672 | self.removeElementClass(obj, className); |
michael@0 | 673 | } |
michael@0 | 674 | } |
michael@0 | 675 | }, |
michael@0 | 676 | |
michael@0 | 677 | /** @id MochiKit.DOM.addElementClass */ |
michael@0 | 678 | addElementClass: function (element, className) { |
michael@0 | 679 | var self = MochiKit.DOM; |
michael@0 | 680 | var obj = self.getElement(element); |
michael@0 | 681 | var cls = obj.className; |
michael@0 | 682 | // trivial case, no className yet |
michael@0 | 683 | if (cls == undefined || cls.length === 0) { |
michael@0 | 684 | self.setElementClass(obj, className); |
michael@0 | 685 | return true; |
michael@0 | 686 | } |
michael@0 | 687 | // the other trivial case, already set as the only class |
michael@0 | 688 | if (cls == className) { |
michael@0 | 689 | return false; |
michael@0 | 690 | } |
michael@0 | 691 | var classes = cls.split(" "); |
michael@0 | 692 | for (var i = 0; i < classes.length; i++) { |
michael@0 | 693 | // already present |
michael@0 | 694 | if (classes[i] == className) { |
michael@0 | 695 | return false; |
michael@0 | 696 | } |
michael@0 | 697 | } |
michael@0 | 698 | // append class |
michael@0 | 699 | self.setElementClass(obj, cls + " " + className); |
michael@0 | 700 | return true; |
michael@0 | 701 | }, |
michael@0 | 702 | |
michael@0 | 703 | /** @id MochiKit.DOM.removeElementClass */ |
michael@0 | 704 | removeElementClass: function (element, className) { |
michael@0 | 705 | var self = MochiKit.DOM; |
michael@0 | 706 | var obj = self.getElement(element); |
michael@0 | 707 | var cls = obj.className; |
michael@0 | 708 | // trivial case, no className yet |
michael@0 | 709 | if (cls == undefined || cls.length === 0) { |
michael@0 | 710 | return false; |
michael@0 | 711 | } |
michael@0 | 712 | // other trivial case, set only to className |
michael@0 | 713 | if (cls == className) { |
michael@0 | 714 | self.setElementClass(obj, ""); |
michael@0 | 715 | return true; |
michael@0 | 716 | } |
michael@0 | 717 | var classes = cls.split(" "); |
michael@0 | 718 | for (var i = 0; i < classes.length; i++) { |
michael@0 | 719 | // already present |
michael@0 | 720 | if (classes[i] == className) { |
michael@0 | 721 | // only check sane case where the class is used once |
michael@0 | 722 | classes.splice(i, 1); |
michael@0 | 723 | self.setElementClass(obj, classes.join(" ")); |
michael@0 | 724 | return true; |
michael@0 | 725 | } |
michael@0 | 726 | } |
michael@0 | 727 | // not found |
michael@0 | 728 | return false; |
michael@0 | 729 | }, |
michael@0 | 730 | |
michael@0 | 731 | /** @id MochiKit.DOM.swapElementClass */ |
michael@0 | 732 | swapElementClass: function (element, fromClass, toClass) { |
michael@0 | 733 | var obj = MochiKit.DOM.getElement(element); |
michael@0 | 734 | var res = MochiKit.DOM.removeElementClass(obj, fromClass); |
michael@0 | 735 | if (res) { |
michael@0 | 736 | MochiKit.DOM.addElementClass(obj, toClass); |
michael@0 | 737 | } |
michael@0 | 738 | return res; |
michael@0 | 739 | }, |
michael@0 | 740 | |
michael@0 | 741 | /** @id MochiKit.DOM.hasElementClass */ |
michael@0 | 742 | hasElementClass: function (element, className/*...*/) { |
michael@0 | 743 | var obj = MochiKit.DOM.getElement(element); |
michael@0 | 744 | var cls = obj.className; |
michael@0 | 745 | if (!cls) { |
michael@0 | 746 | return false; |
michael@0 | 747 | } |
michael@0 | 748 | var classes = cls.split(" "); |
michael@0 | 749 | for (var i = 1; i < arguments.length; i++) { |
michael@0 | 750 | var good = false; |
michael@0 | 751 | for (var j = 0; j < classes.length; j++) { |
michael@0 | 752 | if (classes[j] == arguments[i]) { |
michael@0 | 753 | good = true; |
michael@0 | 754 | break; |
michael@0 | 755 | } |
michael@0 | 756 | } |
michael@0 | 757 | if (!good) { |
michael@0 | 758 | return false; |
michael@0 | 759 | } |
michael@0 | 760 | } |
michael@0 | 761 | return true; |
michael@0 | 762 | }, |
michael@0 | 763 | |
michael@0 | 764 | /** @id MochiKit.DOM.escapeHTML */ |
michael@0 | 765 | escapeHTML: function (s) { |
michael@0 | 766 | return s.replace(/&/g, "&" |
michael@0 | 767 | ).replace(/"/g, """ |
michael@0 | 768 | ).replace(/</g, "<" |
michael@0 | 769 | ).replace(/>/g, ">"); |
michael@0 | 770 | }, |
michael@0 | 771 | |
michael@0 | 772 | /** @id MochiKit.DOM.toHTML */ |
michael@0 | 773 | toHTML: function (dom) { |
michael@0 | 774 | return MochiKit.DOM.emitHTML(dom).join(""); |
michael@0 | 775 | }, |
michael@0 | 776 | |
michael@0 | 777 | /** @id MochiKit.DOM.emitHTML */ |
michael@0 | 778 | emitHTML: function (dom, /* optional */lst) { |
michael@0 | 779 | if (typeof(lst) == 'undefined' || lst === null) { |
michael@0 | 780 | lst = []; |
michael@0 | 781 | } |
michael@0 | 782 | // queue is the call stack, we're doing this non-recursively |
michael@0 | 783 | var queue = [dom]; |
michael@0 | 784 | var self = MochiKit.DOM; |
michael@0 | 785 | var escapeHTML = self.escapeHTML; |
michael@0 | 786 | var attributeArray = self.attributeArray; |
michael@0 | 787 | while (queue.length) { |
michael@0 | 788 | dom = queue.pop(); |
michael@0 | 789 | if (typeof(dom) == 'string') { |
michael@0 | 790 | lst.push(dom); |
michael@0 | 791 | } else if (dom.nodeType == 1) { |
michael@0 | 792 | // we're not using higher order stuff here |
michael@0 | 793 | // because safari has heisenbugs.. argh. |
michael@0 | 794 | // |
michael@0 | 795 | // I think it might have something to do with |
michael@0 | 796 | // garbage collection and function calls. |
michael@0 | 797 | lst.push('<' + dom.tagName.toLowerCase()); |
michael@0 | 798 | var attributes = []; |
michael@0 | 799 | var domAttr = attributeArray(dom); |
michael@0 | 800 | for (var i = 0; i < domAttr.length; i++) { |
michael@0 | 801 | var a = domAttr[i]; |
michael@0 | 802 | attributes.push([ |
michael@0 | 803 | " ", |
michael@0 | 804 | a.name, |
michael@0 | 805 | '="', |
michael@0 | 806 | escapeHTML(a.value), |
michael@0 | 807 | '"' |
michael@0 | 808 | ]); |
michael@0 | 809 | } |
michael@0 | 810 | attributes.sort(); |
michael@0 | 811 | for (i = 0; i < attributes.length; i++) { |
michael@0 | 812 | var attrs = attributes[i]; |
michael@0 | 813 | for (var j = 0; j < attrs.length; j++) { |
michael@0 | 814 | lst.push(attrs[j]); |
michael@0 | 815 | } |
michael@0 | 816 | } |
michael@0 | 817 | if (dom.hasChildNodes()) { |
michael@0 | 818 | lst.push(">"); |
michael@0 | 819 | // queue is the FILO call stack, so we put the close tag |
michael@0 | 820 | // on first |
michael@0 | 821 | queue.push("</" + dom.tagName.toLowerCase() + ">"); |
michael@0 | 822 | var cnodes = dom.childNodes; |
michael@0 | 823 | for (i = cnodes.length - 1; i >= 0; i--) { |
michael@0 | 824 | queue.push(cnodes[i]); |
michael@0 | 825 | } |
michael@0 | 826 | } else { |
michael@0 | 827 | lst.push('/>'); |
michael@0 | 828 | } |
michael@0 | 829 | } else if (dom.nodeType == 3) { |
michael@0 | 830 | lst.push(escapeHTML(dom.nodeValue)); |
michael@0 | 831 | } |
michael@0 | 832 | } |
michael@0 | 833 | return lst; |
michael@0 | 834 | }, |
michael@0 | 835 | |
michael@0 | 836 | /** @id MochiKit.DOM.scrapeText */ |
michael@0 | 837 | scrapeText: function (node, /* optional */asArray) { |
michael@0 | 838 | var rval = []; |
michael@0 | 839 | (function (node) { |
michael@0 | 840 | var cn = node.childNodes; |
michael@0 | 841 | if (cn) { |
michael@0 | 842 | for (var i = 0; i < cn.length; i++) { |
michael@0 | 843 | arguments.callee.call(this, cn[i]); |
michael@0 | 844 | } |
michael@0 | 845 | } |
michael@0 | 846 | var nodeValue = node.nodeValue; |
michael@0 | 847 | if (typeof(nodeValue) == 'string') { |
michael@0 | 848 | rval.push(nodeValue); |
michael@0 | 849 | } |
michael@0 | 850 | })(MochiKit.DOM.getElement(node)); |
michael@0 | 851 | if (asArray) { |
michael@0 | 852 | return rval; |
michael@0 | 853 | } else { |
michael@0 | 854 | return rval.join(""); |
michael@0 | 855 | } |
michael@0 | 856 | }, |
michael@0 | 857 | |
michael@0 | 858 | /** @id MochiKit.DOM.removeEmptyTextNodes */ |
michael@0 | 859 | removeEmptyTextNodes: function (element) { |
michael@0 | 860 | element = MochiKit.DOM.getElement(element); |
michael@0 | 861 | for (var i = 0; i < element.childNodes.length; i++) { |
michael@0 | 862 | var node = element.childNodes[i]; |
michael@0 | 863 | if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) { |
michael@0 | 864 | node.parentNode.removeChild(node); |
michael@0 | 865 | } |
michael@0 | 866 | } |
michael@0 | 867 | }, |
michael@0 | 868 | |
michael@0 | 869 | __new__: function (win) { |
michael@0 | 870 | |
michael@0 | 871 | var m = MochiKit.Base; |
michael@0 | 872 | if (typeof(document) != "undefined") { |
michael@0 | 873 | this._document = document; |
michael@0 | 874 | this._xhtml = |
michael@0 | 875 | document.createElementNS && |
michael@0 | 876 | document.createElement("testname").localName == "testname"; |
michael@0 | 877 | } else if (MochiKit.MockDOM) { |
michael@0 | 878 | this._document = MochiKit.MockDOM.document; |
michael@0 | 879 | } |
michael@0 | 880 | this._window = win; |
michael@0 | 881 | |
michael@0 | 882 | this.domConverters = new m.AdapterRegistry(); |
michael@0 | 883 | |
michael@0 | 884 | var __tmpElement = this._document.createElement("span"); |
michael@0 | 885 | var attributeArray; |
michael@0 | 886 | if (__tmpElement && __tmpElement.attributes && |
michael@0 | 887 | __tmpElement.attributes.length > 0) { |
michael@0 | 888 | // for braindead browsers (IE) that insert extra junk |
michael@0 | 889 | var filter = m.filter; |
michael@0 | 890 | attributeArray = function (node) { |
michael@0 | 891 | return filter(attributeArray.ignoreAttrFilter, node.attributes); |
michael@0 | 892 | }; |
michael@0 | 893 | attributeArray.ignoreAttr = {}; |
michael@0 | 894 | var attrs = __tmpElement.attributes; |
michael@0 | 895 | var ignoreAttr = attributeArray.ignoreAttr; |
michael@0 | 896 | for (var i = 0; i < attrs.length; i++) { |
michael@0 | 897 | var a = attrs[i]; |
michael@0 | 898 | ignoreAttr[a.name] = a.value; |
michael@0 | 899 | } |
michael@0 | 900 | attributeArray.ignoreAttrFilter = function (a) { |
michael@0 | 901 | return (attributeArray.ignoreAttr[a.name] != a.value); |
michael@0 | 902 | }; |
michael@0 | 903 | attributeArray.compliant = false; |
michael@0 | 904 | attributeArray.renames = { |
michael@0 | 905 | "class": "className", |
michael@0 | 906 | "checked": "defaultChecked", |
michael@0 | 907 | "usemap": "useMap", |
michael@0 | 908 | "for": "htmlFor", |
michael@0 | 909 | "readonly": "readOnly", |
michael@0 | 910 | "colspan": "colSpan", |
michael@0 | 911 | "bgcolor": "bgColor" |
michael@0 | 912 | }; |
michael@0 | 913 | } else { |
michael@0 | 914 | attributeArray = function (node) { |
michael@0 | 915 | /*** |
michael@0 | 916 | |
michael@0 | 917 | Return an array of attributes for a given node, |
michael@0 | 918 | filtering out attributes that don't belong for |
michael@0 | 919 | that are inserted by "Certain Browsers". |
michael@0 | 920 | |
michael@0 | 921 | ***/ |
michael@0 | 922 | return node.attributes; |
michael@0 | 923 | }; |
michael@0 | 924 | attributeArray.compliant = true; |
michael@0 | 925 | attributeArray.renames = {}; |
michael@0 | 926 | } |
michael@0 | 927 | this.attributeArray = attributeArray; |
michael@0 | 928 | |
michael@0 | 929 | // FIXME: this really belongs in Base, and could probably be cleaner |
michael@0 | 930 | var _deprecated = function(fromModule, arr) { |
michael@0 | 931 | var modules = arr[1].split('.'); |
michael@0 | 932 | var str = ''; |
michael@0 | 933 | var obj = {}; |
michael@0 | 934 | |
michael@0 | 935 | str += 'if (!MochiKit.' + modules[1] + ') { throw new Error("'; |
michael@0 | 936 | str += 'This function has been deprecated and depends on MochiKit.'; |
michael@0 | 937 | str += modules[1] + '.");}'; |
michael@0 | 938 | str += 'return MochiKit.' + modules[1] + '.' + arr[0]; |
michael@0 | 939 | str += '.apply(this, arguments);'; |
michael@0 | 940 | |
michael@0 | 941 | obj[modules[2]] = new Function(str); |
michael@0 | 942 | MochiKit.Base.update(MochiKit[fromModule], obj); |
michael@0 | 943 | } |
michael@0 | 944 | for (var i; i < MochiKit.DOM.DEPRECATED.length; i++) { |
michael@0 | 945 | _deprecated('DOM', MochiKit.DOM.DEPRECATED[i]); |
michael@0 | 946 | } |
michael@0 | 947 | |
michael@0 | 948 | // shorthand for createDOM syntax |
michael@0 | 949 | var createDOMFunc = this.createDOMFunc; |
michael@0 | 950 | /** @id MochiKit.DOM.UL */ |
michael@0 | 951 | this.UL = createDOMFunc("ul"); |
michael@0 | 952 | /** @id MochiKit.DOM.OL */ |
michael@0 | 953 | this.OL = createDOMFunc("ol"); |
michael@0 | 954 | /** @id MochiKit.DOM.LI */ |
michael@0 | 955 | this.LI = createDOMFunc("li"); |
michael@0 | 956 | /** @id MochiKit.DOM.TD */ |
michael@0 | 957 | this.TD = createDOMFunc("td"); |
michael@0 | 958 | /** @id MochiKit.DOM.TR */ |
michael@0 | 959 | this.TR = createDOMFunc("tr"); |
michael@0 | 960 | /** @id MochiKit.DOM.TBODY */ |
michael@0 | 961 | this.TBODY = createDOMFunc("tbody"); |
michael@0 | 962 | /** @id MochiKit.DOM.THEAD */ |
michael@0 | 963 | this.THEAD = createDOMFunc("thead"); |
michael@0 | 964 | /** @id MochiKit.DOM.TFOOT */ |
michael@0 | 965 | this.TFOOT = createDOMFunc("tfoot"); |
michael@0 | 966 | /** @id MochiKit.DOM.TABLE */ |
michael@0 | 967 | this.TABLE = createDOMFunc("table"); |
michael@0 | 968 | /** @id MochiKit.DOM.TH */ |
michael@0 | 969 | this.TH = createDOMFunc("th"); |
michael@0 | 970 | /** @id MochiKit.DOM.INPUT */ |
michael@0 | 971 | this.INPUT = createDOMFunc("input"); |
michael@0 | 972 | /** @id MochiKit.DOM.SPAN */ |
michael@0 | 973 | this.SPAN = createDOMFunc("span"); |
michael@0 | 974 | /** @id MochiKit.DOM.A */ |
michael@0 | 975 | this.A = createDOMFunc("a"); |
michael@0 | 976 | /** @id MochiKit.DOM.DIV */ |
michael@0 | 977 | this.DIV = createDOMFunc("div"); |
michael@0 | 978 | /** @id MochiKit.DOM.IMG */ |
michael@0 | 979 | this.IMG = createDOMFunc("img"); |
michael@0 | 980 | /** @id MochiKit.DOM.BUTTON */ |
michael@0 | 981 | this.BUTTON = createDOMFunc("button"); |
michael@0 | 982 | /** @id MochiKit.DOM.TT */ |
michael@0 | 983 | this.TT = createDOMFunc("tt"); |
michael@0 | 984 | /** @id MochiKit.DOM.PRE */ |
michael@0 | 985 | this.PRE = createDOMFunc("pre"); |
michael@0 | 986 | /** @id MochiKit.DOM.H1 */ |
michael@0 | 987 | this.H1 = createDOMFunc("h1"); |
michael@0 | 988 | /** @id MochiKit.DOM.H2 */ |
michael@0 | 989 | this.H2 = createDOMFunc("h2"); |
michael@0 | 990 | /** @id MochiKit.DOM.H3 */ |
michael@0 | 991 | this.H3 = createDOMFunc("h3"); |
michael@0 | 992 | /** @id MochiKit.DOM.BR */ |
michael@0 | 993 | this.BR = createDOMFunc("br"); |
michael@0 | 994 | /** @id MochiKit.DOM.HR */ |
michael@0 | 995 | this.HR = createDOMFunc("hr"); |
michael@0 | 996 | /** @id MochiKit.DOM.LABEL */ |
michael@0 | 997 | this.LABEL = createDOMFunc("label"); |
michael@0 | 998 | /** @id MochiKit.DOM.TEXTAREA */ |
michael@0 | 999 | this.TEXTAREA = createDOMFunc("textarea"); |
michael@0 | 1000 | /** @id MochiKit.DOM.FORM */ |
michael@0 | 1001 | this.FORM = createDOMFunc("form"); |
michael@0 | 1002 | /** @id MochiKit.DOM.P */ |
michael@0 | 1003 | this.P = createDOMFunc("p"); |
michael@0 | 1004 | /** @id MochiKit.DOM.SELECT */ |
michael@0 | 1005 | this.SELECT = createDOMFunc("select"); |
michael@0 | 1006 | /** @id MochiKit.DOM.OPTION */ |
michael@0 | 1007 | this.OPTION = createDOMFunc("option"); |
michael@0 | 1008 | /** @id MochiKit.DOM.OPTGROUP */ |
michael@0 | 1009 | this.OPTGROUP = createDOMFunc("optgroup"); |
michael@0 | 1010 | /** @id MochiKit.DOM.LEGEND */ |
michael@0 | 1011 | this.LEGEND = createDOMFunc("legend"); |
michael@0 | 1012 | /** @id MochiKit.DOM.FIELDSET */ |
michael@0 | 1013 | this.FIELDSET = createDOMFunc("fieldset"); |
michael@0 | 1014 | /** @id MochiKit.DOM.STRONG */ |
michael@0 | 1015 | this.STRONG = createDOMFunc("strong"); |
michael@0 | 1016 | /** @id MochiKit.DOM.CANVAS */ |
michael@0 | 1017 | this.CANVAS = createDOMFunc("canvas"); |
michael@0 | 1018 | |
michael@0 | 1019 | /** @id MochiKit.DOM.$ */ |
michael@0 | 1020 | this.$ = this.getElement; |
michael@0 | 1021 | |
michael@0 | 1022 | this.EXPORT_TAGS = { |
michael@0 | 1023 | ":common": this.EXPORT, |
michael@0 | 1024 | ":all": m.concat(this.EXPORT, this.EXPORT_OK) |
michael@0 | 1025 | }; |
michael@0 | 1026 | |
michael@0 | 1027 | m.nameFunctions(this); |
michael@0 | 1028 | |
michael@0 | 1029 | } |
michael@0 | 1030 | }); |
michael@0 | 1031 | |
michael@0 | 1032 | |
michael@0 | 1033 | MochiKit.DOM.__new__(((typeof(window) == "undefined") ? this : window)); |
michael@0 | 1034 | |
michael@0 | 1035 | // |
michael@0 | 1036 | // XXX: Internet Explorer blows |
michael@0 | 1037 | // |
michael@0 | 1038 | if (MochiKit.__export__) { |
michael@0 | 1039 | withWindow = MochiKit.DOM.withWindow; |
michael@0 | 1040 | withDocument = MochiKit.DOM.withDocument; |
michael@0 | 1041 | } |
michael@0 | 1042 | |
michael@0 | 1043 | MochiKit.Base._exportSymbols(this, MochiKit.DOM); |