]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blob - wradmin/static/yui/dom/dom-debug.js
Rename public directory to static.
[philipp/winterrodeln/wradmin.git] / wradmin / static / yui / dom / dom-debug.js
1 /*
2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
5 version: 2.7.0
6 */
7 /**
8  * The dom module provides helper methods for manipulating Dom elements.
9  * @module dom
10  *
11  */
12
13 (function() {
14     YAHOO.env._id_counter = YAHOO.env._id_counter || 0;     // for use with generateId (global to save state if Dom is overwritten)
15
16         // internal shorthand
17     var Y = YAHOO.util,
18         lang = YAHOO.lang,
19         UA = YAHOO.env.ua,
20         trim = YAHOO.lang.trim,
21         propertyCache = {}, // for faster hyphen converts
22         reCache = {}, // cache className regexes
23         RE_TABLE = /^t(?:able|d|h)$/i, // for _calcBorders
24         RE_COLOR = /color$/i,
25
26         // DOM aliases 
27         document = window.document,     
28         documentElement = document.documentElement,
29
30         // string constants
31         OWNER_DOCUMENT = 'ownerDocument',
32         DEFAULT_VIEW = 'defaultView',
33         DOCUMENT_ELEMENT = 'documentElement',
34         COMPAT_MODE = 'compatMode',
35         OFFSET_LEFT = 'offsetLeft',
36         OFFSET_TOP = 'offsetTop',
37         OFFSET_PARENT = 'offsetParent',
38         PARENT_NODE = 'parentNode',
39         NODE_TYPE = 'nodeType',
40         TAG_NAME = 'tagName',
41         SCROLL_LEFT = 'scrollLeft',
42         SCROLL_TOP = 'scrollTop',
43         GET_BOUNDING_CLIENT_RECT = 'getBoundingClientRect',
44         GET_COMPUTED_STYLE = 'getComputedStyle',
45         CURRENT_STYLE = 'currentStyle',
46         CSS1_COMPAT = 'CSS1Compat',
47         _BACK_COMPAT = 'BackCompat',
48         _CLASS = 'class', // underscore due to reserved word
49         CLASS_NAME = 'className',
50         EMPTY = '',
51         SPACE = ' ',
52         C_START = '(?:^|\\s)',
53         C_END = '(?= |$)',
54         G = 'g',
55         POSITION = 'position',
56         FIXED = 'fixed',
57         RELATIVE = 'relative',
58         LEFT = 'left',
59         TOP = 'top',
60         MEDIUM = 'medium',
61         BORDER_LEFT_WIDTH = 'borderLeftWidth',
62         BORDER_TOP_WIDTH = 'borderTopWidth',
63     
64     // brower detection
65         isOpera = UA.opera,
66         isSafari = UA.webkit, 
67         isGecko = UA.gecko, 
68         isIE = UA.ie; 
69     
70     /**
71      * Provides helper methods for DOM elements.
72      * @namespace YAHOO.util
73      * @class Dom
74      * @requires yahoo, event
75      */
76     Y.Dom = {
77         CUSTOM_ATTRIBUTES: (!documentElement.hasAttribute) ? { // IE < 8
78             'for': 'htmlFor',
79             'class': CLASS_NAME
80         } : { // w3c
81             'htmlFor': 'for',
82             'className': _CLASS
83         },
84
85         /**
86          * Returns an HTMLElement reference.
87          * @method get
88          * @param {String | HTMLElement |Array} el Accepts a string to use as an ID for getting a DOM reference, an actual DOM reference, or an Array of IDs and/or HTMLElements.
89          * @return {HTMLElement | Array} A DOM reference to an HTML element or an array of HTMLElements.
90          */
91         get: function(el) {
92             var id, nodes, c, i, len;
93
94             if (el) {
95                 if (el[NODE_TYPE] || el.item) { // Node, or NodeList
96                     return el;
97                 }
98
99                 if (typeof el === 'string') { // id
100                     id = el;
101                     el = document.getElementById(el);
102                     if (el && el.id === id) { // IE: avoid false match on "name" attribute
103                     return el;
104                     } else if (el && document.all) { // filter by name
105                         el = null;
106                         nodes = document.all[id];
107                         for (i = 0, len = nodes.length; i < len; ++i) {
108                             if (nodes[i].id === id) {
109                                 return nodes[i];
110                             }
111                         }
112                     }
113                     return el;
114                 }
115                 
116                 if (el.DOM_EVENTS) { // YAHOO.util.Element
117                     el = el.get('element');
118                 }
119
120                 if ('length' in el) { // array-like 
121                     c = [];
122                     for (i = 0, len = el.length; i < len; ++i) {
123                         c[c.length] = Y.Dom.get(el[i]);
124                     }
125                     
126                     return c;
127                 }
128
129                 return el; // some other object, just pass it back
130             }
131
132             return null;
133         },
134     
135         getComputedStyle: function(el, property) {
136             if (window[GET_COMPUTED_STYLE]) {
137                 return el[OWNER_DOCUMENT][DEFAULT_VIEW][GET_COMPUTED_STYLE](el, null)[property];
138             } else if (el[CURRENT_STYLE]) {
139                 return Y.Dom.IE_ComputedStyle.get(el, property);
140             }
141         },
142
143         /**
144          * Normalizes currentStyle and ComputedStyle.
145          * @method getStyle
146          * @param {String | HTMLElement |Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements.
147          * @param {String} property The style property whose value is returned.
148          * @return {String | Array} The current value of the style property for the element(s).
149          */
150         getStyle: function(el, property) {
151             return Y.Dom.batch(el, Y.Dom._getStyle, property);
152         },
153
154         // branching at load instead of runtime
155         _getStyle: function() {
156             if (window[GET_COMPUTED_STYLE]) { // W3C DOM method
157                 return function(el, property) {
158                     property = (property === 'float') ? property = 'cssFloat' :
159                             Y.Dom._toCamel(property);
160
161                     var value = el.style[property],
162                         computed;
163                     
164                     if (!value) {
165                         computed = el[OWNER_DOCUMENT][DEFAULT_VIEW][GET_COMPUTED_STYLE](el, null);
166                         if (computed) { // test computed before touching for safari
167                             value = computed[property];
168                         }
169                     }
170                     
171                     return value;
172                 };
173             } else if (documentElement[CURRENT_STYLE]) {
174                 return function(el, property) {                         
175                     var value;
176
177                     switch(property) {
178                         case 'opacity' :// IE opacity uses filter
179                             value = 100;
180                             try { // will error if no DXImageTransform
181                                 value = el.filters['DXImageTransform.Microsoft.Alpha'].opacity;
182
183                             } catch(e) {
184                                 try { // make sure its in the document
185                                     value = el.filters('alpha').opacity;
186                                 } catch(err) {
187                                     YAHOO.log('getStyle: IE filter failed',
188                                             'error', 'Dom');
189                                 }
190                             }
191                             return value / 100;
192                         case 'float': // fix reserved word
193                             property = 'styleFloat'; // fall through
194                         default: 
195                             property = Y.Dom._toCamel(property);
196                             value = el[CURRENT_STYLE] ? el[CURRENT_STYLE][property] : null;
197                             return ( el.style[property] || value );
198                     }
199                 };
200             }
201         }(),
202     
203         /**
204          * Wrapper for setting style properties of HTMLElements.  Normalizes "opacity" across modern browsers.
205          * @method setStyle
206          * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements.
207          * @param {String} property The style property to be set.
208          * @param {String} val The value to apply to the given property.
209          */
210         setStyle: function(el, property, val) {
211             Y.Dom.batch(el, Y.Dom._setStyle, { prop: property, val: val });
212         },
213
214         _setStyle: function() {
215             if (isIE) {
216                 return function(el, args) {
217                     var property = Y.Dom._toCamel(args.prop),
218                         val = args.val;
219
220                     if (el) {
221                         switch (property) {
222                             case 'opacity':
223                                 if ( lang.isString(el.style.filter) ) { // in case not appended
224                                     el.style.filter = 'alpha(opacity=' + val * 100 + ')';
225                                     
226                                     if (!el[CURRENT_STYLE] || !el[CURRENT_STYLE].hasLayout) {
227                                         el.style.zoom = 1; // when no layout or cant tell
228                                     }
229                                 }
230                                 break;
231                             case 'float':
232                                 property = 'styleFloat';
233                             default:
234                             el.style[property] = val;
235                         }
236                     } else {
237                         YAHOO.log('element ' + el + ' is undefined', 'error', 'Dom');
238                     }
239                 };
240             } else {
241                 return function(el, args) {
242                     var property = Y.Dom._toCamel(args.prop),
243                         val = args.val;
244                     if (el) {
245                         if (property == 'float') {
246                             property = 'cssFloat';
247                         }
248                         el.style[property] = val;
249                     } else {
250                         YAHOO.log('element ' + el + ' is undefined', 'error', 'Dom');
251                     }
252                 };
253             }
254
255         }(),
256         
257         /**
258          * Gets the current position of an element based on page coordinates. 
259          * Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
260          * @method getXY
261          * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM
262          * reference, or an Array of IDs and/or HTMLElements
263          * @return {Array} The XY position of the element(s)
264          */
265         getXY: function(el) {
266             return Y.Dom.batch(el, Y.Dom._getXY);
267         },
268
269         _canPosition: function(el) {
270             return ( Y.Dom._getStyle(el, 'display') !== 'none' && Y.Dom._inDoc(el) );
271         },
272
273         _getXY: function() {
274             if (document[DOCUMENT_ELEMENT][GET_BOUNDING_CLIENT_RECT]) {
275                 return function(node) {
276                     var scrollLeft, scrollTop, box, doc,
277                         off1, off2, mode, bLeft, bTop,
278                         floor = Math.floor, // TODO: round?
279                         xy = false;
280
281                     if (Y.Dom._canPosition(node)) {
282                         box = node[GET_BOUNDING_CLIENT_RECT]();
283                         doc = node[OWNER_DOCUMENT];
284                         scrollLeft = Y.Dom.getDocumentScrollLeft(doc);
285                         scrollTop = Y.Dom.getDocumentScrollTop(doc);
286                         xy = [floor(box[LEFT]), floor(box[TOP])];
287
288                         if (isIE && UA.ie < 8) { // IE < 8: viewport off by 2
289                             off1 = 2;
290                             off2 = 2;
291                             mode = doc[COMPAT_MODE];
292                             bLeft = _getComputedStyle(doc[DOCUMENT_ELEMENT], BORDER_LEFT_WIDTH);
293                             bTop = _getComputedStyle(doc[DOCUMENT_ELEMENT], BORDER_TOP_WIDTH);
294
295                             if (UA.ie === 6) {
296                                 if (mode !== _BACK_COMPAT) {
297                                     off1 = 0;
298                                     off2 = 0;
299                                 }
300                             }
301                             
302                             if ((mode == _BACK_COMPAT)) {
303                                 if (bLeft !== MEDIUM) {
304                                     off1 = parseInt(bLeft, 10);
305                                 }
306                                 if (bTop !== MEDIUM) {
307                                     off2 = parseInt(bTop, 10);
308                                 }
309                             }
310                             
311                             xy[0] -= off1;
312                             xy[1] -= off2;
313
314                         }
315
316                         if ((scrollTop || scrollLeft)) {
317                             xy[0] += scrollLeft;
318                             xy[1] += scrollTop;
319                         }
320
321                         // gecko may return sub-pixel (non-int) values
322                         xy[0] = floor(xy[0]);
323                         xy[1] = floor(xy[1]);
324                     } else {
325                         YAHOO.log('getXY failed: element not positionable (either not in a document or not displayed)', 'error', 'Dom');
326                     }
327
328                     return xy;
329                 };
330             } else {
331                 return function(node) { // ff2, safari: manually calculate by crawling up offsetParents
332                     var docScrollLeft, docScrollTop,
333                         scrollTop, scrollLeft,
334                         bCheck,
335                         xy = false,
336                         parentNode = node;
337
338                     if  (Y.Dom._canPosition(node) ) {
339                         xy = [node[OFFSET_LEFT], node[OFFSET_TOP]];
340                         docScrollLeft = Y.Dom.getDocumentScrollLeft(node[OWNER_DOCUMENT]);
341                         docScrollTop = Y.Dom.getDocumentScrollTop(node[OWNER_DOCUMENT]);
342
343                         // TODO: refactor with !! or just falsey
344                         bCheck = ((isGecko || UA.webkit > 519) ? true : false);
345
346                         // TODO: worth refactoring for TOP/LEFT only?
347                         while ((parentNode = parentNode[OFFSET_PARENT])) {
348                             xy[0] += parentNode[OFFSET_LEFT];
349                             xy[1] += parentNode[OFFSET_TOP];
350                             if (bCheck) {
351                                 xy = Y.Dom._calcBorders(parentNode, xy);
352                             }
353                         }
354
355                         // account for any scrolled ancestors
356                         if (Y.Dom._getStyle(node, POSITION) !== FIXED) {
357                             parentNode = node;
358
359                             while ((parentNode = parentNode[PARENT_NODE]) && parentNode[TAG_NAME]) {
360                                 scrollTop = parentNode[SCROLL_TOP];
361                                 scrollLeft = parentNode[SCROLL_LEFT];
362
363                                 //Firefox does something funky with borders when overflow is not visible.
364                                 if (isGecko && (Y.Dom._getStyle(parentNode, 'overflow') !== 'visible')) {
365                                         xy = Y.Dom._calcBorders(parentNode, xy);
366                                 }
367
368                                 if (scrollTop || scrollLeft) {
369                                     xy[0] -= scrollLeft;
370                                     xy[1] -= scrollTop;
371                                 }
372                             }
373                             xy[0] += docScrollLeft;
374                             xy[1] += docScrollTop;
375
376                         } else {
377                             //Fix FIXED position -- add scrollbars
378                             if (isOpera) {
379                                 xy[0] -= docScrollLeft;
380                                 xy[1] -= docScrollTop;
381                             } else if (isSafari || isGecko) {
382                                 xy[0] += docScrollLeft;
383                                 xy[1] += docScrollTop;
384                             }
385                         }
386                         //Round the numbers so we get sane data back
387                         xy[0] = Math.floor(xy[0]);
388                         xy[1] = Math.floor(xy[1]);
389                     } else {
390                         YAHOO.log('getXY failed: element not positionable (either not in a document or not displayed)', 'error', 'Dom');
391                     }
392                     return xy;                
393                 };
394             }
395         }(), // NOTE: Executing for loadtime branching
396         
397         /**
398          * Gets the current X position of an element based on page coordinates.  The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
399          * @method getX
400          * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements
401          * @return {Number | Array} The X position of the element(s)
402          */
403         getX: function(el) {
404             var f = function(el) {
405                 return Y.Dom.getXY(el)[0];
406             };
407             
408             return Y.Dom.batch(el, f, Y.Dom, true);
409         },
410         
411         /**
412          * Gets the current Y position of an element based on page coordinates.  Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
413          * @method getY
414          * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements
415          * @return {Number | Array} The Y position of the element(s)
416          */
417         getY: function(el) {
418             var f = function(el) {
419                 return Y.Dom.getXY(el)[1];
420             };
421             
422             return Y.Dom.batch(el, f, Y.Dom, true);
423         },
424         
425         /**
426          * Set the position of an html element in page coordinates, regardless of how the element is positioned.
427          * The element(s) must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
428          * @method setXY
429          * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements
430          * @param {Array} pos Contains X & Y values for new position (coordinates are page-based)
431          * @param {Boolean} noRetry By default we try and set the position a second time if the first fails
432          */
433         setXY: function(el, pos, noRetry) {
434             Y.Dom.batch(el, Y.Dom._setXY, { pos: pos, noRetry: noRetry });
435         },
436
437         _setXY: function(node, args) {
438             var pos = Y.Dom._getStyle(node, POSITION),
439                 setStyle = Y.Dom.setStyle,
440                 xy = args.pos,
441                 noRetry = args.noRetry,
442
443                 delta = [ // assuming pixels; if not we will have to retry
444                     parseInt( Y.Dom.getComputedStyle(node, LEFT), 10 ),
445                     parseInt( Y.Dom.getComputedStyle(node, TOP), 10 )
446                 ],
447
448                 currentXY,
449                 newXY;
450         
451             if (pos == 'static') { // default to relative
452                 pos = RELATIVE;
453                 setStyle(node, POSITION, pos);
454             }
455
456             currentXY = Y.Dom._getXY(node);
457
458             if (!xy || currentXY === false) { // has to be part of doc to have xy
459                 YAHOO.log('xy failed: node not available', 'error', 'Node');
460                 return false; 
461             }
462             
463             if ( isNaN(delta[0]) ) {// in case of 'auto'
464                 delta[0] = (pos == RELATIVE) ? 0 : node[OFFSET_LEFT];
465             } 
466             if ( isNaN(delta[1]) ) { // in case of 'auto'
467                 delta[1] = (pos == RELATIVE) ? 0 : node[OFFSET_TOP];
468             } 
469
470             if (xy[0] !== null) { // from setX
471                 setStyle(node, LEFT, xy[0] - currentXY[0] + delta[0] + 'px');
472             }
473
474             if (xy[1] !== null) { // from setY
475                 setStyle(node, TOP, xy[1] - currentXY[1] + delta[1] + 'px');
476             }
477           
478             if (!noRetry) {
479                 newXY = Y.Dom._getXY(node);
480
481                 // if retry is true, try one more time if we miss 
482                if ( (xy[0] !== null && newXY[0] != xy[0]) || 
483                     (xy[1] !== null && newXY[1] != xy[1]) ) {
484                    Y.Dom._setXY(node, { pos: xy, noRetry: true });
485                }
486             }        
487
488             YAHOO.log('setXY setting position to ' + xy, 'info', 'Node');
489         },
490         
491         /**
492          * Set the X position of an html element in page coordinates, regardless of how the element is positioned.
493          * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
494          * @method setX
495          * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements.
496          * @param {Int} x The value to use as the X coordinate for the element(s).
497          */
498         setX: function(el, x) {
499             Y.Dom.setXY(el, [x, null]);
500         },
501         
502         /**
503          * Set the Y position of an html element in page coordinates, regardless of how the element is positioned.
504          * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
505          * @method setY
506          * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements.
507          * @param {Int} x To use as the Y coordinate for the element(s).
508          */
509         setY: function(el, y) {
510             Y.Dom.setXY(el, [null, y]);
511         },
512         
513         /**
514          * Returns the region position of the given element.
515          * The element must be part of the DOM tree to have a region (display:none or elements not appended return false).
516          * @method getRegion
517          * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements.
518          * @return {Region | Array} A Region or array of Region instances containing "top, left, bottom, right" member data.
519          */
520         getRegion: function(el) {
521             var f = function(el) {
522                 var region = false;
523                 if ( Y.Dom._canPosition(el) ) {
524                     region = Y.Region.getRegion(el);
525                     YAHOO.log('getRegion returning ' + region, 'info', 'Dom');
526                 } else {
527                     YAHOO.log('getRegion failed: element not positionable (either not in a document or not displayed)', 'error', 'Dom');
528                 }
529
530                 return region;
531             };
532             
533             return Y.Dom.batch(el, f, Y.Dom, true);
534         },
535         
536         /**
537          * Returns the width of the client (viewport).
538          * @method getClientWidth
539          * @deprecated Now using getViewportWidth.  This interface left intact for back compat.
540          * @return {Int} The width of the viewable area of the page.
541          */
542         getClientWidth: function() {
543             return Y.Dom.getViewportWidth();
544         },
545         
546         /**
547          * Returns the height of the client (viewport).
548          * @method getClientHeight
549          * @deprecated Now using getViewportHeight.  This interface left intact for back compat.
550          * @return {Int} The height of the viewable area of the page.
551          */
552         getClientHeight: function() {
553             return Y.Dom.getViewportHeight();
554         },
555
556         /**
557          * Returns a array of HTMLElements with the given class.
558          * For optimized performance, include a tag and/or root node when possible.
559          * Note: This method operates against a live collection, so modifying the 
560          * collection in the callback (removing/appending nodes, etc.) will have
561          * side effects.  Instead you should iterate the returned nodes array,
562          * as you would with the native "getElementsByTagName" method. 
563          * @method getElementsByClassName
564          * @param {String} className The class name to match against
565          * @param {String} tag (optional) The tag name of the elements being collected
566          * @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point 
567          * @param {Function} apply (optional) A function to apply to each element when found 
568          * @param {Any} o (optional) An optional arg that is passed to the supplied method
569          * @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o"
570          * @return {Array} An array of elements that have the given class name
571          */
572         getElementsByClassName: function(className, tag, root, apply, o, overrides) {
573             className = lang.trim(className);
574             tag = tag || '*';
575             root = (root) ? Y.Dom.get(root) : null || document; 
576             if (!root) {
577                 return [];
578             }
579
580             var nodes = [],
581                 elements = root.getElementsByTagName(tag),
582                 hasClass = Y.Dom.hasClass;
583
584             for (var i = 0, len = elements.length; i < len; ++i) {
585                 if ( hasClass(elements[i], className) ) {
586                     nodes[nodes.length] = elements[i];
587                 }
588             }
589             
590             if (apply) {
591                 Y.Dom.batch(nodes, apply, o, overrides);
592             }
593
594             return nodes;
595         },
596
597         /**
598          * Determines whether an HTMLElement has the given className.
599          * @method hasClass
600          * @param {String | HTMLElement | Array} el The element or collection to test
601          * @param {String} className the class name to search for
602          * @return {Boolean | Array} A boolean value or array of boolean values
603          */
604         hasClass: function(el, className) {
605             return Y.Dom.batch(el, Y.Dom._hasClass, className);
606         },
607
608         _hasClass: function(el, className) {
609             var ret = false,
610                 current;
611             
612             if (el && className) {
613                 current = Y.Dom.getAttribute(el, CLASS_NAME) || EMPTY;
614                 if (className.exec) {
615                     ret = className.test(current);
616                 } else {
617                     ret = className && (SPACE + current + SPACE).
618                         indexOf(SPACE + className + SPACE) > -1;
619                 }
620             } else {
621                 YAHOO.log('hasClass called with invalid arguments', 'warn', 'Dom');
622             }
623
624             return ret;
625         },
626     
627         /**
628          * Adds a class name to a given element or collection of elements.
629          * @method addClass         
630          * @param {String | HTMLElement | Array} el The element or collection to add the class to
631          * @param {String} className the class name to add to the class attribute
632          * @return {Boolean | Array} A pass/fail boolean or array of booleans
633          */
634         addClass: function(el, className) {
635             return Y.Dom.batch(el, Y.Dom._addClass, className);
636         },
637
638         _addClass: function(el, className) {
639             var ret = false,
640                 current;
641
642             if (el && className) {
643                 current = Y.Dom.getAttribute(el, CLASS_NAME) || EMPTY;
644                 if ( !Y.Dom._hasClass(el, className) ) {
645                     Y.Dom.setAttribute(el, CLASS_NAME, trim(current + SPACE + className));
646                     ret = true;
647                 }
648             } else {
649                 YAHOO.log('addClass called with invalid arguments', 'warn', 'Dom');
650             }
651
652             return ret;
653         },
654     
655         /**
656          * Removes a class name from a given element or collection of elements.
657          * @method removeClass         
658          * @param {String | HTMLElement | Array} el The element or collection to remove the class from
659          * @param {String} className the class name to remove from the class attribute
660          * @return {Boolean | Array} A pass/fail boolean or array of booleans
661          */
662         removeClass: function(el, className) {
663             return Y.Dom.batch(el, Y.Dom._removeClass, className);
664         },
665         
666         _removeClass: function(el, className) {
667             var ret = false,
668                 current,
669                 newClass,
670                 attr;
671
672             if (el && className) {
673                 current = Y.Dom.getAttribute(el, CLASS_NAME) || EMPTY;
674                 Y.Dom.setAttribute(el, CLASS_NAME, current.replace(Y.Dom._getClassRegex(className), EMPTY));
675
676                 newClass = Y.Dom.getAttribute(el, CLASS_NAME);
677                 if (current !== newClass) { // else nothing changed
678                     Y.Dom.setAttribute(el, CLASS_NAME, trim(newClass)); // trim after comparing to current class
679                     ret = true;
680
681                     if (Y.Dom.getAttribute(el, CLASS_NAME) === '') { // remove class attribute if empty
682                         attr = (el.hasAttribute && el.hasAttribute(_CLASS)) ? _CLASS : CLASS_NAME;
683                         YAHOO.log('removeClass removing empty class attribute', 'info', 'Dom');
684                         el.removeAttribute(attr);
685                     }
686                 }
687
688             } else {
689                 YAHOO.log('removeClass called with invalid arguments', 'warn', 'Dom');
690             }
691
692             return ret;
693         },
694         
695         /**
696          * Replace a class with another class for a given element or collection of elements.
697          * If no oldClassName is present, the newClassName is simply added.
698          * @method replaceClass  
699          * @param {String | HTMLElement | Array} el The element or collection to remove the class from
700          * @param {String} oldClassName the class name to be replaced
701          * @param {String} newClassName the class name that will be replacing the old class name
702          * @return {Boolean | Array} A pass/fail boolean or array of booleans
703          */
704         replaceClass: function(el, oldClassName, newClassName) {
705             return Y.Dom.batch(el, Y.Dom._replaceClass, { from: oldClassName, to: newClassName });
706         },
707
708         _replaceClass: function(el, classObj) {
709             var className,
710                 from,
711                 to,
712                 ret = false,
713                 current;
714
715             if (el && classObj) {
716                 from = classObj.from;
717                 to = classObj.to;
718
719                 if (!to) {
720                     ret = false;
721                 }  else if (!from) { // just add if no "from"
722                     ret = Y.Dom._addClass(el, classObj.to);
723                 } else if (from !== to) { // else nothing to replace
724                     // May need to lead with DBLSPACE?
725                     current = Y.Dom.getAttribute(el, CLASS_NAME) || EMPTY;
726                     className = (SPACE + current.replace(Y.Dom._getClassRegex(from), SPACE + to)).
727                                split(Y.Dom._getClassRegex(to));
728
729                     // insert to into what would have been the first occurrence slot
730                     className.splice(1, 0, SPACE + to);
731                     Y.Dom.setAttribute(el, CLASS_NAME, trim(className.join(EMPTY)));
732                     ret = true;
733                 }
734             } else {
735                 YAHOO.log('replaceClass called with invalid arguments', 'warn', 'Dom');
736             }
737
738             return ret;
739         },
740         
741         /**
742          * Returns an ID and applies it to the element "el", if provided.
743          * @method generateId  
744          * @param {String | HTMLElement | Array} el (optional) An optional element array of elements to add an ID to (no ID is added if one is already present).
745          * @param {String} prefix (optional) an optional prefix to use (defaults to "yui-gen").
746          * @return {String | Array} The generated ID, or array of generated IDs (or original ID if already present on an element)
747          */
748         generateId: function(el, prefix) {
749             prefix = prefix || 'yui-gen';
750
751             var f = function(el) {
752                 if (el && el.id) { // do not override existing ID
753                     YAHOO.log('generateId returning existing id ' + el.id, 'info', 'Dom');
754                     return el.id;
755                 }
756
757                 var id = prefix + YAHOO.env._id_counter++;
758                 YAHOO.log('generateId generating ' + id, 'info', 'Dom');
759
760                 if (el) {
761                     if (el[OWNER_DOCUMENT].getElementById(id)) { // in case one already exists
762                         // use failed id plus prefix to help ensure uniqueness
763                         return Y.Dom.generateId(el, id + prefix);
764                     }
765                     el.id = id;
766                 }
767                 
768                 return id;
769             };
770
771             // batch fails when no element, so just generate and return single ID
772             return Y.Dom.batch(el, f, Y.Dom, true) || f.apply(Y.Dom, arguments);
773         },
774         
775         /**
776          * Determines whether an HTMLElement is an ancestor of another HTML element in the DOM hierarchy.
777          * @method isAncestor
778          * @param {String | HTMLElement} haystack The possible ancestor
779          * @param {String | HTMLElement} needle The possible descendent
780          * @return {Boolean} Whether or not the haystack is an ancestor of needle
781          */
782         isAncestor: function(haystack, needle) {
783             haystack = Y.Dom.get(haystack);
784             needle = Y.Dom.get(needle);
785             
786             var ret = false;
787
788             if ( (haystack && needle) && (haystack[NODE_TYPE] && needle[NODE_TYPE]) ) {
789                 if (haystack.contains && haystack !== needle) { // contains returns true when equal
790                     ret = haystack.contains(needle);
791                 }
792                 else if (haystack.compareDocumentPosition) { // gecko
793                     ret = !!(haystack.compareDocumentPosition(needle) & 16);
794                 }
795             } else {
796                 YAHOO.log('isAncestor failed; invalid input: ' + haystack + ',' + needle, 'error', 'Dom');
797             }
798             YAHOO.log('isAncestor(' + haystack + ',' + needle + ' returning ' + ret, 'info', 'Dom');
799             return ret;
800         },
801         
802         /**
803          * Determines whether an HTMLElement is present in the current document.
804          * @method inDocument         
805          * @param {String | HTMLElement} el The element to search for
806          * @param {Object} doc An optional document to search, defaults to element's owner document 
807          * @return {Boolean} Whether or not the element is present in the current document
808          */
809         inDocument: function(el, doc) {
810             return Y.Dom._inDoc(Y.Dom.get(el), doc);
811         },
812
813         _inDoc: function(el, doc) {
814             var ret = false;
815             if (el && el[TAG_NAME]) {
816                 doc = doc || el[OWNER_DOCUMENT]; 
817                 ret = Y.Dom.isAncestor(doc[DOCUMENT_ELEMENT], el);
818             } else {
819                 YAHOO.log('inDocument failed: invalid input', 'error', 'Dom');
820             }
821             return ret;
822         },
823         
824         /**
825          * Returns a array of HTMLElements that pass the test applied by supplied boolean method.
826          * For optimized performance, include a tag and/or root node when possible.
827          * Note: This method operates against a live collection, so modifying the 
828          * collection in the callback (removing/appending nodes, etc.) will have
829          * side effects.  Instead you should iterate the returned nodes array,
830          * as you would with the native "getElementsByTagName" method. 
831          * @method getElementsBy
832          * @param {Function} method - A boolean method for testing elements which receives the element as its only argument.
833          * @param {String} tag (optional) The tag name of the elements being collected
834          * @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point 
835          * @param {Function} apply (optional) A function to apply to each element when found 
836          * @param {Any} o (optional) An optional arg that is passed to the supplied method
837          * @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o"
838          * @return {Array} Array of HTMLElements
839          */
840         getElementsBy: function(method, tag, root, apply, o, overrides, firstOnly) {
841             tag = tag || '*';
842             root = (root) ? Y.Dom.get(root) : null || document; 
843
844             if (!root) {
845                 return [];
846             }
847
848             var nodes = [],
849                 elements = root.getElementsByTagName(tag);
850             
851             for (var i = 0, len = elements.length; i < len; ++i) {
852                 if ( method(elements[i]) ) {
853                     if (firstOnly) {
854                         nodes = elements[i]; 
855                         break;
856                     } else {
857                         nodes[nodes.length] = elements[i];
858                     }
859                 }
860             }
861
862             if (apply) {
863                 Y.Dom.batch(nodes, apply, o, overrides);
864             }
865
866             YAHOO.log('getElementsBy returning ' + nodes, 'info', 'Dom');
867             
868             return nodes;
869         },
870         
871         /**
872          * Returns the first HTMLElement that passes the test applied by the supplied boolean method.
873          * @method getElementBy
874          * @param {Function} method - A boolean method for testing elements which receives the element as its only argument.
875          * @param {String} tag (optional) The tag name of the elements being collected
876          * @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point 
877          * @return {HTMLElement}
878          */
879         getElementBy: function(method, tag, root) {
880             return Y.Dom.getElementsBy(method, tag, root, null, null, null, true); 
881         },
882
883         /**
884          * Runs the supplied method against each item in the Collection/Array.
885          * The method is called with the element(s) as the first arg, and the optional param as the second ( method(el, o) ).
886          * @method batch
887          * @param {String | HTMLElement | Array} el (optional) An element or array of elements to apply the method to
888          * @param {Function} method The method to apply to the element(s)
889          * @param {Any} o (optional) An optional arg that is passed to the supplied method
890          * @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o"
891          * @return {Any | Array} The return value(s) from the supplied method
892          */
893         batch: function(el, method, o, overrides) {
894             var collection = [],
895                 scope = (overrides) ? o : window;
896                 
897             el = (el && (el[TAG_NAME] || el.item)) ? el : Y.Dom.get(el); // skip get() when possible
898             if (el && method) {
899                 if (el[TAG_NAME] || el.length === undefined) { // element or not array-like 
900                     return method.call(scope, el, o);
901                 } 
902
903                 for (var i = 0; i < el.length; ++i) {
904                     collection[collection.length] = method.call(scope, el[i], o);
905                 }
906             } else {
907                 YAHOO.log('batch called with invalid arguments', 'warn', 'Dom');
908                 return false;
909             } 
910             return collection;
911         },
912         
913         /**
914          * Returns the height of the document.
915          * @method getDocumentHeight
916          * @return {Int} The height of the actual document (which includes the body and its margin).
917          */
918         getDocumentHeight: function() {
919             var scrollHeight = (document[COMPAT_MODE] != CSS1_COMPAT || isSafari) ? document.body.scrollHeight : documentElement.scrollHeight,
920                 h = Math.max(scrollHeight, Y.Dom.getViewportHeight());
921
922             YAHOO.log('getDocumentHeight returning ' + h, 'info', 'Dom');
923             return h;
924         },
925         
926         /**
927          * Returns the width of the document.
928          * @method getDocumentWidth
929          * @return {Int} The width of the actual document (which includes the body and its margin).
930          */
931         getDocumentWidth: function() {
932             var scrollWidth = (document[COMPAT_MODE] != CSS1_COMPAT || isSafari) ? document.body.scrollWidth : documentElement.scrollWidth,
933                 w = Math.max(scrollWidth, Y.Dom.getViewportWidth());
934             YAHOO.log('getDocumentWidth returning ' + w, 'info', 'Dom');
935             return w;
936         },
937
938         /**
939          * Returns the current height of the viewport.
940          * @method getViewportHeight
941          * @return {Int} The height of the viewable area of the page (excludes scrollbars).
942          */
943         getViewportHeight: function() {
944             var height = self.innerHeight, // Safari, Opera
945                 mode = document[COMPAT_MODE];
946         
947             if ( (mode || isIE) && !isOpera ) { // IE, Gecko
948                 height = (mode == CSS1_COMPAT) ?
949                         documentElement.clientHeight : // Standards
950                         document.body.clientHeight; // Quirks
951             }
952         
953             YAHOO.log('getViewportHeight returning ' + height, 'info', 'Dom');
954             return height;
955         },
956         
957         /**
958          * Returns the current width of the viewport.
959          * @method getViewportWidth
960          * @return {Int} The width of the viewable area of the page (excludes scrollbars).
961          */
962         
963         getViewportWidth: function() {
964             var width = self.innerWidth,  // Safari
965                 mode = document[COMPAT_MODE];
966             
967             if (mode || isIE) { // IE, Gecko, Opera
968                 width = (mode == CSS1_COMPAT) ?
969                         documentElement.clientWidth : // Standards
970                         document.body.clientWidth; // Quirks
971             }
972             YAHOO.log('getViewportWidth returning ' + width, 'info', 'Dom');
973             return width;
974         },
975
976        /**
977          * Returns the nearest ancestor that passes the test applied by supplied boolean method.
978          * For performance reasons, IDs are not accepted and argument validation omitted.
979          * @method getAncestorBy
980          * @param {HTMLElement} node The HTMLElement to use as the starting point 
981          * @param {Function} method - A boolean method for testing elements which receives the element as its only argument.
982          * @return {Object} HTMLElement or null if not found
983          */
984         getAncestorBy: function(node, method) {
985             while ( (node = node[PARENT_NODE]) ) { // NOTE: assignment
986                 if ( Y.Dom._testElement(node, method) ) {
987                     YAHOO.log('getAncestorBy returning ' + node, 'info', 'Dom');
988                     return node;
989                 }
990             } 
991
992             YAHOO.log('getAncestorBy returning null (no ancestor passed test)', 'error', 'Dom');
993             return null;
994         },
995         
996         /**
997          * Returns the nearest ancestor with the given className.
998          * @method getAncestorByClassName
999          * @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point 
1000          * @param {String} className
1001          * @return {Object} HTMLElement
1002          */
1003         getAncestorByClassName: function(node, className) {
1004             node = Y.Dom.get(node);
1005             if (!node) {
1006                 YAHOO.log('getAncestorByClassName failed: invalid node argument', 'error', 'Dom');
1007                 return null;
1008             }
1009             var method = function(el) { return Y.Dom.hasClass(el, className); };
1010             return Y.Dom.getAncestorBy(node, method);
1011         },
1012
1013         /**
1014          * Returns the nearest ancestor with the given tagName.
1015          * @method getAncestorByTagName
1016          * @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point 
1017          * @param {String} tagName
1018          * @return {Object} HTMLElement
1019          */
1020         getAncestorByTagName: function(node, tagName) {
1021             node = Y.Dom.get(node);
1022             if (!node) {
1023                 YAHOO.log('getAncestorByTagName failed: invalid node argument', 'error', 'Dom');
1024                 return null;
1025             }
1026             var method = function(el) {
1027                  return el[TAG_NAME] && el[TAG_NAME].toUpperCase() == tagName.toUpperCase();
1028             };
1029
1030             return Y.Dom.getAncestorBy(node, method);
1031         },
1032
1033         /**
1034          * Returns the previous sibling that is an HTMLElement. 
1035          * For performance reasons, IDs are not accepted and argument validation omitted.
1036          * Returns the nearest HTMLElement sibling if no method provided.
1037          * @method getPreviousSiblingBy
1038          * @param {HTMLElement} node The HTMLElement to use as the starting point 
1039          * @param {Function} method A boolean function used to test siblings
1040          * that receives the sibling node being tested as its only argument
1041          * @return {Object} HTMLElement or null if not found
1042          */
1043         getPreviousSiblingBy: function(node, method) {
1044             while (node) {
1045                 node = node.previousSibling;
1046                 if ( Y.Dom._testElement(node, method) ) {
1047                     return node;
1048                 }
1049             }
1050             return null;
1051         }, 
1052
1053         /**
1054          * Returns the previous sibling that is an HTMLElement 
1055          * @method getPreviousSibling
1056          * @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point 
1057          * @return {Object} HTMLElement or null if not found
1058          */
1059         getPreviousSibling: function(node) {
1060             node = Y.Dom.get(node);
1061             if (!node) {
1062                 YAHOO.log('getPreviousSibling failed: invalid node argument', 'error', 'Dom');
1063                 return null;
1064             }
1065
1066             return Y.Dom.getPreviousSiblingBy(node);
1067         }, 
1068
1069         /**
1070          * Returns the next HTMLElement sibling that passes the boolean method. 
1071          * For performance reasons, IDs are not accepted and argument validation omitted.
1072          * Returns the nearest HTMLElement sibling if no method provided.
1073          * @method getNextSiblingBy
1074          * @param {HTMLElement} node The HTMLElement to use as the starting point 
1075          * @param {Function} method A boolean function used to test siblings
1076          * that receives the sibling node being tested as its only argument
1077          * @return {Object} HTMLElement or null if not found
1078          */
1079         getNextSiblingBy: function(node, method) {
1080             while (node) {
1081                 node = node.nextSibling;
1082                 if ( Y.Dom._testElement(node, method) ) {
1083                     return node;
1084                 }
1085             }
1086             return null;
1087         }, 
1088
1089         /**
1090          * Returns the next sibling that is an HTMLElement 
1091          * @method getNextSibling
1092          * @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point 
1093          * @return {Object} HTMLElement or null if not found
1094          */
1095         getNextSibling: function(node) {
1096             node = Y.Dom.get(node);
1097             if (!node) {
1098                 YAHOO.log('getNextSibling failed: invalid node argument', 'error', 'Dom');
1099                 return null;
1100             }
1101
1102             return Y.Dom.getNextSiblingBy(node);
1103         }, 
1104
1105         /**
1106          * Returns the first HTMLElement child that passes the test method. 
1107          * @method getFirstChildBy
1108          * @param {HTMLElement} node The HTMLElement to use as the starting point 
1109          * @param {Function} method A boolean function used to test children
1110          * that receives the node being tested as its only argument
1111          * @return {Object} HTMLElement or null if not found
1112          */
1113         getFirstChildBy: function(node, method) {
1114             var child = ( Y.Dom._testElement(node.firstChild, method) ) ? node.firstChild : null;
1115             return child || Y.Dom.getNextSiblingBy(node.firstChild, method);
1116         }, 
1117
1118         /**
1119          * Returns the first HTMLElement child. 
1120          * @method getFirstChild
1121          * @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point 
1122          * @return {Object} HTMLElement or null if not found
1123          */
1124         getFirstChild: function(node, method) {
1125             node = Y.Dom.get(node);
1126             if (!node) {
1127                 YAHOO.log('getFirstChild failed: invalid node argument', 'error', 'Dom');
1128                 return null;
1129             }
1130             return Y.Dom.getFirstChildBy(node);
1131         }, 
1132
1133         /**
1134          * Returns the last HTMLElement child that passes the test method. 
1135          * @method getLastChildBy
1136          * @param {HTMLElement} node The HTMLElement to use as the starting point 
1137          * @param {Function} method A boolean function used to test children
1138          * that receives the node being tested as its only argument
1139          * @return {Object} HTMLElement or null if not found
1140          */
1141         getLastChildBy: function(node, method) {
1142             if (!node) {
1143                 YAHOO.log('getLastChild failed: invalid node argument', 'error', 'Dom');
1144                 return null;
1145             }
1146             var child = ( Y.Dom._testElement(node.lastChild, method) ) ? node.lastChild : null;
1147             return child || Y.Dom.getPreviousSiblingBy(node.lastChild, method);
1148         }, 
1149
1150         /**
1151          * Returns the last HTMLElement child. 
1152          * @method getLastChild
1153          * @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point 
1154          * @return {Object} HTMLElement or null if not found
1155          */
1156         getLastChild: function(node) {
1157             node = Y.Dom.get(node);
1158             return Y.Dom.getLastChildBy(node);
1159         }, 
1160
1161         /**
1162          * Returns an array of HTMLElement childNodes that pass the test method. 
1163          * @method getChildrenBy
1164          * @param {HTMLElement} node The HTMLElement to start from
1165          * @param {Function} method A boolean function used to test children
1166          * that receives the node being tested as its only argument
1167          * @return {Array} A static array of HTMLElements
1168          */
1169         getChildrenBy: function(node, method) {
1170             var child = Y.Dom.getFirstChildBy(node, method),
1171                 children = child ? [child] : [];
1172
1173             Y.Dom.getNextSiblingBy(child, function(node) {
1174                 if ( !method || method(node) ) {
1175                     children[children.length] = node;
1176                 }
1177                 return false; // fail test to collect all children
1178             });
1179
1180             return children;
1181         },
1182  
1183         /**
1184          * Returns an array of HTMLElement childNodes. 
1185          * @method getChildren
1186          * @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point 
1187          * @return {Array} A static array of HTMLElements
1188          */
1189         getChildren: function(node) {
1190             node = Y.Dom.get(node);
1191             if (!node) {
1192                 YAHOO.log('getChildren failed: invalid node argument', 'error', 'Dom');
1193             }
1194
1195             return Y.Dom.getChildrenBy(node);
1196         },
1197
1198         /**
1199          * Returns the left scroll value of the document 
1200          * @method getDocumentScrollLeft
1201          * @param {HTMLDocument} document (optional) The document to get the scroll value of
1202          * @return {Int}  The amount that the document is scrolled to the left
1203          */
1204         getDocumentScrollLeft: function(doc) {
1205             doc = doc || document;
1206             return Math.max(doc[DOCUMENT_ELEMENT].scrollLeft, doc.body.scrollLeft);
1207         }, 
1208
1209         /**
1210          * Returns the top scroll value of the document 
1211          * @method getDocumentScrollTop
1212          * @param {HTMLDocument} document (optional) The document to get the scroll value of
1213          * @return {Int}  The amount that the document is scrolled to the top
1214          */
1215         getDocumentScrollTop: function(doc) {
1216             doc = doc || document;
1217             return Math.max(doc[DOCUMENT_ELEMENT].scrollTop, doc.body.scrollTop);
1218         },
1219
1220         /**
1221          * Inserts the new node as the previous sibling of the reference node 
1222          * @method insertBefore
1223          * @param {String | HTMLElement} newNode The node to be inserted
1224          * @param {String | HTMLElement} referenceNode The node to insert the new node before 
1225          * @return {HTMLElement} The node that was inserted (or null if insert fails) 
1226          */
1227         insertBefore: function(newNode, referenceNode) {
1228             newNode = Y.Dom.get(newNode); 
1229             referenceNode = Y.Dom.get(referenceNode); 
1230             
1231             if (!newNode || !referenceNode || !referenceNode[PARENT_NODE]) {
1232                 YAHOO.log('insertAfter failed: missing or invalid arg(s)', 'error', 'Dom');
1233                 return null;
1234             }       
1235
1236             return referenceNode[PARENT_NODE].insertBefore(newNode, referenceNode); 
1237         },
1238
1239         /**
1240          * Inserts the new node as the next sibling of the reference node 
1241          * @method insertAfter
1242          * @param {String | HTMLElement} newNode The node to be inserted
1243          * @param {String | HTMLElement} referenceNode The node to insert the new node after 
1244          * @return {HTMLElement} The node that was inserted (or null if insert fails) 
1245          */
1246         insertAfter: function(newNode, referenceNode) {
1247             newNode = Y.Dom.get(newNode); 
1248             referenceNode = Y.Dom.get(referenceNode); 
1249             
1250             if (!newNode || !referenceNode || !referenceNode[PARENT_NODE]) {
1251                 YAHOO.log('insertAfter failed: missing or invalid arg(s)', 'error', 'Dom');
1252                 return null;
1253             }       
1254
1255             if (referenceNode.nextSibling) {
1256                 return referenceNode[PARENT_NODE].insertBefore(newNode, referenceNode.nextSibling); 
1257             } else {
1258                 return referenceNode[PARENT_NODE].appendChild(newNode);
1259             }
1260         },
1261
1262         /**
1263          * Creates a Region based on the viewport relative to the document. 
1264          * @method getClientRegion
1265          * @return {Region} A Region object representing the viewport which accounts for document scroll
1266          */
1267         getClientRegion: function() {
1268             var t = Y.Dom.getDocumentScrollTop(),
1269                 l = Y.Dom.getDocumentScrollLeft(),
1270                 r = Y.Dom.getViewportWidth() + l,
1271                 b = Y.Dom.getViewportHeight() + t;
1272
1273             return new Y.Region(t, r, b, l);
1274         },
1275
1276         /**
1277          * Provides a normalized attribute interface. 
1278          * @method setAttibute
1279          * @param {String | HTMLElement} el The target element for the attribute.
1280          * @param {String} attr The attribute to set.
1281          * @param {String} val The value of the attribute.
1282          */
1283         setAttribute: function(el, attr, val) {
1284             attr = Y.Dom.CUSTOM_ATTRIBUTES[attr] || attr;
1285             el.setAttribute(attr, val);
1286         },
1287
1288
1289         /**
1290          * Provides a normalized attribute interface. 
1291          * @method getAttibute
1292          * @param {String | HTMLElement} el The target element for the attribute.
1293          * @param {String} attr The attribute to get.
1294          * @return {String} The current value of the attribute. 
1295          */
1296         getAttribute: function(el, attr) {
1297             attr = Y.Dom.CUSTOM_ATTRIBUTES[attr] || attr;
1298             return el.getAttribute(attr);
1299         },
1300
1301         _toCamel: function(property) {
1302             var c = propertyCache;
1303
1304             function tU(x,l) {
1305                 return l.toUpperCase();
1306             }
1307
1308             return c[property] || (c[property] = property.indexOf('-') === -1 ? 
1309                                     property :
1310                                     property.replace( /-([a-z])/gi, tU ));
1311         },
1312
1313         _getClassRegex: function(className) {
1314             var re;
1315             if (className !== undefined) { // allow empty string to pass
1316                 if (className.exec) { // already a RegExp
1317                     re = className;
1318                 } else {
1319                     re = reCache[className];
1320                     if (!re) {
1321                         // escape special chars (".", "[", etc.)
1322                         className = className.replace(Y.Dom._patterns.CLASS_RE_TOKENS, '\\$1');
1323                         re = reCache[className] = new RegExp(C_START + className + C_END, G);
1324                     }
1325                 }
1326             }
1327             return re;
1328         },
1329
1330         _patterns: {
1331             ROOT_TAG: /^body|html$/i, // body for quirks mode, html for standards,
1332             CLASS_RE_TOKENS: /([\.\(\)\^\$\*\+\?\|\[\]\{\}])/g
1333         },
1334
1335
1336         _testElement: function(node, method) {
1337             return node && node[NODE_TYPE] == 1 && ( !method || method(node) );
1338         },
1339
1340         _calcBorders: function(node, xy2) {
1341             var t = parseInt(Y.Dom[GET_COMPUTED_STYLE](node, BORDER_TOP_WIDTH), 10) || 0,
1342                 l = parseInt(Y.Dom[GET_COMPUTED_STYLE](node, BORDER_LEFT_WIDTH), 10) || 0;
1343             if (isGecko) {
1344                 if (RE_TABLE.test(node[TAG_NAME])) {
1345                     t = 0;
1346                     l = 0;
1347                 }
1348             }
1349             xy2[0] += l;
1350             xy2[1] += t;
1351             return xy2;
1352         }
1353     };
1354         
1355     var _getComputedStyle = Y.Dom[GET_COMPUTED_STYLE];
1356     // fix opera computedStyle default color unit (convert to rgb)
1357     if (UA.opera) {
1358         Y.Dom[GET_COMPUTED_STYLE] = function(node, att) {
1359             var val = _getComputedStyle(node, att);
1360             if (RE_COLOR.test(att)) {
1361                 val = Y.Dom.Color.toRGB(val);
1362             }
1363
1364             return val;
1365         };
1366
1367     }
1368
1369     // safari converts transparent to rgba(), others use "transparent"
1370     if (UA.webkit) {
1371         Y.Dom[GET_COMPUTED_STYLE] = function(node, att) {
1372             var val = _getComputedStyle(node, att);
1373
1374             if (val === 'rgba(0, 0, 0, 0)') {
1375                 val = 'transparent'; 
1376             }
1377
1378             return val;
1379         };
1380
1381     }
1382 })();
1383 /**
1384  * A region is a representation of an object on a grid.  It is defined
1385  * by the top, right, bottom, left extents, so is rectangular by default.  If 
1386  * other shapes are required, this class could be extended to support it.
1387  * @namespace YAHOO.util
1388  * @class Region
1389  * @param {Int} t the top extent
1390  * @param {Int} r the right extent
1391  * @param {Int} b the bottom extent
1392  * @param {Int} l the left extent
1393  * @constructor
1394  */
1395 YAHOO.util.Region = function(t, r, b, l) {
1396
1397     /**
1398      * The region's top extent
1399      * @property top
1400      * @type Int
1401      */
1402     this.top = t;
1403     
1404     /**
1405      * The region's top extent
1406      * @property y
1407      * @type Int
1408      */
1409     this.y = t;
1410     
1411     /**
1412      * The region's top extent as index, for symmetry with set/getXY
1413      * @property 1
1414      * @type Int
1415      */
1416     this[1] = t;
1417
1418     /**
1419      * The region's right extent
1420      * @property right
1421      * @type int
1422      */
1423     this.right = r;
1424
1425     /**
1426      * The region's bottom extent
1427      * @property bottom
1428      * @type Int
1429      */
1430     this.bottom = b;
1431
1432     /**
1433      * The region's left extent
1434      * @property left
1435      * @type Int
1436      */
1437     this.left = l;
1438     
1439     /**
1440      * The region's left extent
1441      * @property x
1442      * @type Int
1443      */
1444     this.x = l;
1445     
1446     /**
1447      * The region's left extent as index, for symmetry with set/getXY
1448      * @property 0
1449      * @type Int
1450      */
1451     this[0] = l;
1452
1453     /**
1454      * The region's total width 
1455      * @property width 
1456      * @type Int
1457      */
1458     this.width = this.right - this.left;
1459
1460     /**
1461      * The region's total height 
1462      * @property height 
1463      * @type Int
1464      */
1465     this.height = this.bottom - this.top;
1466 };
1467
1468 /**
1469  * Returns true if this region contains the region passed in
1470  * @method contains
1471  * @param  {Region}  region The region to evaluate
1472  * @return {Boolean}        True if the region is contained with this region, 
1473  *                          else false
1474  */
1475 YAHOO.util.Region.prototype.contains = function(region) {
1476     return ( region.left   >= this.left   && 
1477              region.right  <= this.right  && 
1478              region.top    >= this.top    && 
1479              region.bottom <= this.bottom    );
1480
1481     // this.logger.debug("does " + this + " contain " + region + " ... " + ret);
1482 };
1483
1484 /**
1485  * Returns the area of the region
1486  * @method getArea
1487  * @return {Int} the region's area
1488  */
1489 YAHOO.util.Region.prototype.getArea = function() {
1490     return ( (this.bottom - this.top) * (this.right - this.left) );
1491 };
1492
1493 /**
1494  * Returns the region where the passed in region overlaps with this one
1495  * @method intersect
1496  * @param  {Region} region The region that intersects
1497  * @return {Region}        The overlap region, or null if there is no overlap
1498  */
1499 YAHOO.util.Region.prototype.intersect = function(region) {
1500     var t = Math.max( this.top,    region.top    ),
1501         r = Math.min( this.right,  region.right  ),
1502         b = Math.min( this.bottom, region.bottom ),
1503         l = Math.max( this.left,   region.left   );
1504     
1505     if (b >= t && r >= l) {
1506         return new YAHOO.util.Region(t, r, b, l);
1507     } else {
1508         return null;
1509     }
1510 };
1511
1512 /**
1513  * Returns the region representing the smallest region that can contain both
1514  * the passed in region and this region.
1515  * @method union
1516  * @param  {Region} region The region that to create the union with
1517  * @return {Region}        The union region
1518  */
1519 YAHOO.util.Region.prototype.union = function(region) {
1520     var t = Math.min( this.top,    region.top    ),
1521         r = Math.max( this.right,  region.right  ),
1522         b = Math.max( this.bottom, region.bottom ),
1523         l = Math.min( this.left,   region.left   );
1524
1525     return new YAHOO.util.Region(t, r, b, l);
1526 };
1527
1528 /**
1529  * toString
1530  * @method toString
1531  * @return string the region properties
1532  */
1533 YAHOO.util.Region.prototype.toString = function() {
1534     return ( "Region {"    +
1535              "top: "       + this.top    + 
1536              ", right: "   + this.right  + 
1537              ", bottom: "  + this.bottom + 
1538              ", left: "    + this.left   + 
1539              ", height: "  + this.height + 
1540              ", width: "    + this.width   + 
1541              "}" );
1542 };
1543
1544 /**
1545  * Returns a region that is occupied by the DOM element
1546  * @method getRegion
1547  * @param  {HTMLElement} el The element
1548  * @return {Region}         The region that the element occupies
1549  * @static
1550  */
1551 YAHOO.util.Region.getRegion = function(el) {
1552     var p = YAHOO.util.Dom.getXY(el),
1553         t = p[1],
1554         r = p[0] + el.offsetWidth,
1555         b = p[1] + el.offsetHeight,
1556         l = p[0];
1557
1558     return new YAHOO.util.Region(t, r, b, l);
1559 };
1560
1561 /////////////////////////////////////////////////////////////////////////////
1562
1563
1564 /**
1565  * A point is a region that is special in that it represents a single point on 
1566  * the grid.
1567  * @namespace YAHOO.util
1568  * @class Point
1569  * @param {Int} x The X position of the point
1570  * @param {Int} y The Y position of the point
1571  * @constructor
1572  * @extends YAHOO.util.Region
1573  */
1574 YAHOO.util.Point = function(x, y) {
1575    if (YAHOO.lang.isArray(x)) { // accept input from Dom.getXY, Event.getXY, etc.
1576       y = x[1]; // dont blow away x yet
1577       x = x[0];
1578    }
1579  
1580     YAHOO.util.Point.superclass.constructor.call(this, y, x, y, x);
1581 };
1582
1583 YAHOO.extend(YAHOO.util.Point, YAHOO.util.Region);
1584
1585 (function() {
1586 /**
1587  * Add style management functionality to DOM.
1588  * @module dom
1589  * @for Dom
1590  */
1591
1592 var Y = YAHOO.util, 
1593     CLIENT_TOP = 'clientTop',
1594     CLIENT_LEFT = 'clientLeft',
1595     PARENT_NODE = 'parentNode',
1596     RIGHT = 'right',
1597     HAS_LAYOUT = 'hasLayout',
1598     PX = 'px',
1599     OPACITY = 'opacity',
1600     AUTO = 'auto',
1601     BORDER_LEFT_WIDTH = 'borderLeftWidth',
1602     BORDER_TOP_WIDTH = 'borderTopWidth',
1603     BORDER_RIGHT_WIDTH = 'borderRightWidth',
1604     BORDER_BOTTOM_WIDTH = 'borderBottomWidth',
1605     VISIBLE = 'visible',
1606     TRANSPARENT = 'transparent',
1607     HEIGHT = 'height',
1608     WIDTH = 'width',
1609     STYLE = 'style',
1610     CURRENT_STYLE = 'currentStyle',
1611
1612 // IE getComputedStyle
1613 // TODO: unit-less lineHeight (e.g. 1.22)
1614     re_size = /^width|height$/,
1615     re_unit = /^(\d[.\d]*)+(em|ex|px|gd|rem|vw|vh|vm|ch|mm|cm|in|pt|pc|deg|rad|ms|s|hz|khz|%){1}?/i,
1616
1617     ComputedStyle = {
1618         get: function(el, property) {
1619             var value = '',
1620                 current = el[CURRENT_STYLE][property];
1621
1622             if (property === OPACITY) {
1623                 value = Y.Dom.getStyle(el, OPACITY);        
1624             } else if (!current || (current.indexOf && current.indexOf(PX) > -1)) { // no need to convert
1625                 value = current;
1626             } else if (Y.Dom.IE_COMPUTED[property]) { // use compute function
1627                 value = Y.Dom.IE_COMPUTED[property](el, property);
1628             } else if (re_unit.test(current)) { // convert to pixel
1629                 value = Y.Dom.IE.ComputedStyle.getPixel(el, property);
1630             } else {
1631                 value = current;
1632             }
1633
1634             return value;
1635         },
1636
1637         getOffset: function(el, prop) {
1638             var current = el[CURRENT_STYLE][prop],                        // value of "width", "top", etc.
1639                 capped = prop.charAt(0).toUpperCase() + prop.substr(1), // "Width", "Top", etc.
1640                 offset = 'offset' + capped,                             // "offsetWidth", "offsetTop", etc.
1641                 pixel = 'pixel' + capped,                               // "pixelWidth", "pixelTop", etc.
1642                 value = '',
1643                 actual;
1644
1645             if (current == AUTO) {
1646                 actual = el[offset]; // offsetHeight/Top etc.
1647                 if (actual === undefined) { // likely "right" or "bottom"
1648                     value = 0;
1649                 }
1650
1651                 value = actual;
1652                 if (re_size.test(prop)) { // account for box model diff 
1653                     el[STYLE][prop] = actual; 
1654                     if (el[offset] > actual) {
1655                         // the difference is padding + border (works in Standards & Quirks modes)
1656                         value = actual - (el[offset] - actual);
1657                     }
1658                     el[STYLE][prop] = AUTO; // revert to auto
1659                 }
1660             } else { // convert units to px
1661                 if (!el[STYLE][pixel] && !el[STYLE][prop]) { // need to map style.width to currentStyle (no currentStyle.pixelWidth)
1662                     el[STYLE][prop] = current;              // no style.pixelWidth if no style.width
1663                 }
1664                 value = el[STYLE][pixel];
1665             }
1666             return value + PX;
1667         },
1668
1669         getBorderWidth: function(el, property) {
1670             // clientHeight/Width = paddingBox (e.g. offsetWidth - borderWidth)
1671             // clientTop/Left = borderWidth
1672             var value = null;
1673             if (!el[CURRENT_STYLE][HAS_LAYOUT]) { // TODO: unset layout?
1674                 el[STYLE].zoom = 1; // need layout to measure client
1675             }
1676
1677             switch(property) {
1678                 case BORDER_TOP_WIDTH:
1679                     value = el[CLIENT_TOP];
1680                     break;
1681                 case BORDER_BOTTOM_WIDTH:
1682                     value = el.offsetHeight - el.clientHeight - el[CLIENT_TOP];
1683                     break;
1684                 case BORDER_LEFT_WIDTH:
1685                     value = el[CLIENT_LEFT];
1686                     break;
1687                 case BORDER_RIGHT_WIDTH:
1688                     value = el.offsetWidth - el.clientWidth - el[CLIENT_LEFT];
1689                     break;
1690             }
1691             return value + PX;
1692         },
1693
1694         getPixel: function(node, att) {
1695             // use pixelRight to convert to px
1696             var val = null,
1697                 styleRight = node[CURRENT_STYLE][RIGHT],
1698                 current = node[CURRENT_STYLE][att];
1699
1700             node[STYLE][RIGHT] = current;
1701             val = node[STYLE].pixelRight;
1702             node[STYLE][RIGHT] = styleRight; // revert
1703
1704             return val + PX;
1705         },
1706
1707         getMargin: function(node, att) {
1708             var val;
1709             if (node[CURRENT_STYLE][att] == AUTO) {
1710                 val = 0 + PX;
1711             } else {
1712                 val = Y.Dom.IE.ComputedStyle.getPixel(node, att);
1713             }
1714             return val;
1715         },
1716
1717         getVisibility: function(node, att) {
1718             var current;
1719             while ( (current = node[CURRENT_STYLE]) && current[att] == 'inherit') { // NOTE: assignment in test
1720                 node = node[PARENT_NODE];
1721             }
1722             return (current) ? current[att] : VISIBLE;
1723         },
1724
1725         getColor: function(node, att) {
1726             return Y.Dom.Color.toRGB(node[CURRENT_STYLE][att]) || TRANSPARENT;
1727         },
1728
1729         getBorderColor: function(node, att) {
1730             var current = node[CURRENT_STYLE],
1731                 val = current[att] || current.color;
1732             return Y.Dom.Color.toRGB(Y.Dom.Color.toHex(val));
1733         }
1734
1735     },
1736
1737 //fontSize: getPixelFont,
1738     IEComputed = {};
1739
1740 IEComputed.top = IEComputed.right = IEComputed.bottom = IEComputed.left = 
1741         IEComputed[WIDTH] = IEComputed[HEIGHT] = ComputedStyle.getOffset;
1742
1743 IEComputed.color = ComputedStyle.getColor;
1744
1745 IEComputed[BORDER_TOP_WIDTH] = IEComputed[BORDER_RIGHT_WIDTH] =
1746         IEComputed[BORDER_BOTTOM_WIDTH] = IEComputed[BORDER_LEFT_WIDTH] =
1747         ComputedStyle.getBorderWidth;
1748
1749 IEComputed.marginTop = IEComputed.marginRight = IEComputed.marginBottom =
1750         IEComputed.marginLeft = ComputedStyle.getMargin;
1751
1752 IEComputed.visibility = ComputedStyle.getVisibility;
1753 IEComputed.borderColor = IEComputed.borderTopColor =
1754         IEComputed.borderRightColor = IEComputed.borderBottomColor =
1755         IEComputed.borderLeftColor = ComputedStyle.getBorderColor;
1756
1757 Y.Dom.IE_COMPUTED = IEComputed;
1758 Y.Dom.IE_ComputedStyle = ComputedStyle;
1759 })();
1760 (function() {
1761 /**
1762  * Add style management functionality to DOM.
1763  * @module dom
1764  * @for Dom
1765  */
1766
1767 var TO_STRING = 'toString',
1768     PARSE_INT = parseInt,
1769     RE = RegExp,
1770     Y = YAHOO.util;
1771
1772 Y.Dom.Color = {
1773     KEYWORDS: {
1774         black: '000',
1775         silver: 'c0c0c0',
1776         gray: '808080',
1777         white: 'fff',
1778         maroon: '800000',
1779         red: 'f00',
1780         purple: '800080',
1781         fuchsia: 'f0f',
1782         green: '008000',
1783         lime: '0f0',
1784         olive: '808000',
1785         yellow: 'ff0',
1786         navy: '000080',
1787         blue: '00f',
1788         teal: '008080',
1789         aqua: '0ff'
1790     },
1791
1792     re_RGB: /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i,
1793     re_hex: /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i,
1794     re_hex3: /([0-9A-F])/gi,
1795
1796     toRGB: function(val) {
1797         if (!Y.Dom.Color.re_RGB.test(val)) {
1798             val = Y.Dom.Color.toHex(val);
1799         }
1800
1801         if(Y.Dom.Color.re_hex.exec(val)) {
1802             val = 'rgb(' + [
1803                 PARSE_INT(RE.$1, 16),
1804                 PARSE_INT(RE.$2, 16),
1805                 PARSE_INT(RE.$3, 16)
1806             ].join(', ') + ')';
1807         }
1808         return val;
1809     },
1810
1811     toHex: function(val) {
1812         val = Y.Dom.Color.KEYWORDS[val] || val;
1813         if (Y.Dom.Color.re_RGB.exec(val)) {
1814             var r = (RE.$1.length === 1) ? '0' + RE.$1 : Number(RE.$1),
1815                 g = (RE.$2.length === 1) ? '0' + RE.$2 : Number(RE.$2),
1816                 b = (RE.$3.length === 1) ? '0' + RE.$3 : Number(RE.$3);
1817
1818             val = [
1819                 r[TO_STRING](16),
1820                 g[TO_STRING](16),
1821                 b[TO_STRING](16)
1822             ].join('');
1823         }
1824
1825         if (val.length < 6) {
1826             val = val.replace(Y.Dom.Color.re_hex3, '$1$1');
1827         }
1828
1829         if (val !== 'transparent' && val.indexOf('#') < 0) {
1830             val = '#' + val;
1831         }
1832
1833         return val.toLowerCase();
1834     }
1835 };
1836 }());
1837 YAHOO.register("dom", YAHOO.util.Dom, {version: "2.7.0", build: "1799"});