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