2 Copyright (c) 2006, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
8 (function(){var Y
=YAHOO
.util
,getStyle
,setStyle
,id_counter
=0,propertyCache
={};var ua
=navigator
.userAgent
.toLowerCase(),isOpera
=(ua
.indexOf('opera')>-1),isSafari
=(ua
.indexOf('safari')>-1),isGecko
=(!isOpera
&&!isSafari
&&ua
.indexOf('gecko')>-1),isIE
=(!isOpera
&&ua
.indexOf('msie')>-1);var patterns
={HYPHEN
:/(-[a-z])/i};var toCamel=function(property
){if(!patterns
.HYPHEN
.test(property
)){return property
;}
9 if(propertyCache
[property
]){return propertyCache
[property
];}
10 while(patterns
.HYPHEN
.exec(property
)){property
=property
.replace(RegExp
.$1,RegExp
.$1.substr(1).toUpperCase());}
11 propertyCache
[property
]=property
;return property
;};if(document
.defaultView
&&document
.defaultView
.getComputedStyle
){getStyle=function(el
,property
){var value
=null;var computed
=document
.defaultView
.getComputedStyle(el
,'');if(computed
){value
=computed
[toCamel(property
)];}
12 return el
.style
[property
]||value
;};}else if(document
.documentElement
.currentStyle
&&isIE
){getStyle=function(el
,property
){switch(toCamel(property
)){case'opacity':var val
=100;try{val
=el
.filters
['DXImageTransform.Microsoft.Alpha'].opacity
;}catch(e
){try{val
=el
.filters('alpha').opacity
;}catch(e
){}}
13 return val
/100;break;default:var value
=el
.currentStyle
?el
.currentStyle
[property
]:null;return(el
.style
[property
]||value
);}};}else{getStyle=function(el
,property
){return el
.style
[property
];};}
14 if(isIE
){setStyle=function(el
,property
,val
){switch(property
){case'opacity':if(typeof el
.style
.filter
=='string'){el
.style
.filter
='alpha(opacity='+val
*100+')';if(!el
.currentStyle
||!el
.currentStyle
.hasLayout
){el
.style
.zoom
=1;}}
15 break;default:el
.style
[property
]=val
;}};}else{setStyle=function(el
,property
,val
){el
.style
[property
]=val
;};}
16 YAHOO
.util
.Dom
={get:function(el
){if(!el
){return null;}
17 if(typeof el
!='string'&&!(el
instanceof Array
)){return el
;}
18 if(typeof el
=='string'){return document
.getElementById(el
);}
19 else{var collection
=[];for(var i
=0,len
=el
.length
;i
<len
;++i
){collection
[collection
.length
]=Y
.Dom
.get(el
[i
]);}
21 return null;},getStyle:function(el
,property
){property
=toCamel(property
);var f=function(element
){return getStyle(element
,property
);};return Y
.Dom
.batch(el
,f
,Y
.Dom
,true);},setStyle:function(el
,property
,val
){property
=toCamel(property
);var f=function(element
){setStyle(element
,property
,val
);};Y
.Dom
.batch(el
,f
,Y
.Dom
,true);},getXY:function(el
){var f=function(el
){if(el
.parentNode
===null||el
.offsetParent
===null||this.getStyle(el
,'display')=='none'){return false;}
22 var parentNode
=null;var pos
=[];var box
;if(el
.getBoundingClientRect
){box
=el
.getBoundingClientRect();var doc
=document
;if(!this.inDocument(el
)&&parent
.document
!=document
){doc
=parent
.document
;if(!this.isAncestor(doc
.documentElement
,el
)){return false;}}
23 var scrollTop
=Math
.max(doc
.documentElement
.scrollTop
,doc
.body
.scrollTop
);var scrollLeft
=Math
.max(doc
.documentElement
.scrollLeft
,doc
.body
.scrollLeft
);return[box
.left
+scrollLeft
,box
.top
+scrollTop
];}
24 else{pos
=[el
.offsetLeft
,el
.offsetTop
];parentNode
=el
.offsetParent
;if(parentNode
!=el
){while(parentNode
){pos
[0]+=parentNode
.offsetLeft
;pos
[1]+=parentNode
.offsetTop
;parentNode
=parentNode
.offsetParent
;}}
25 if(isSafari
&&this.getStyle(el
,'position')=='absolute'){pos
[0]-=document
.body
.offsetLeft
;pos
[1]-=document
.body
.offsetTop
;}}
26 if(el
.parentNode
){parentNode
=el
.parentNode
;}
27 else{parentNode
=null;}
28 while(parentNode
&&parentNode
.tagName
.toUpperCase()!='BODY'&&parentNode
.tagName
.toUpperCase()!='HTML')
29 {if(Y
.Dom
.getStyle(parentNode
,'display')!='inline'){pos
[0]-=parentNode
.scrollLeft
;pos
[1]-=parentNode
.scrollTop
;}
30 if(parentNode
.parentNode
){parentNode
=parentNode
.parentNode
;}else{parentNode
=null;}}
31 return pos
;};return Y
.Dom
.batch(el
,f
,Y
.Dom
,true);},getX:function(el
){var f=function(el
){return Y
.Dom
.getXY(el
)[0];};return Y
.Dom
.batch(el
,f
,Y
.Dom
,true);},getY:function(el
){var f=function(el
){return Y
.Dom
.getXY(el
)[1];};return Y
.Dom
.batch(el
,f
,Y
.Dom
,true);},setXY:function(el
,pos
,noRetry
){var f=function(el
){var style_pos
=this.getStyle(el
,'position');if(style_pos
=='static'){this.setStyle(el
,'position','relative');style_pos
='relative';}
32 var pageXY
=this.getXY(el
);if(pageXY
===false){return false;}
33 var delta
=[parseInt(this.getStyle(el
,'left'),10),parseInt(this.getStyle(el
,'top'),10)];if(isNaN(delta
[0])){delta
[0]=(style_pos
=='relative')?0:el
.offsetLeft
;}
34 if(isNaN(delta
[1])){delta
[1]=(style_pos
=='relative')?0:el
.offsetTop
;}
35 if(pos
[0]!==null){el
.style
.left
=pos
[0]-pageXY
[0]+delta
[0]+'px';}
36 if(pos
[1]!==null){el
.style
.top
=pos
[1]-pageXY
[1]+delta
[1]+'px';}
37 if(!noRetry
){var newXY
=this.getXY(el
);if((pos
[0]!==null&&newXY
[0]!=pos
[0])||(pos
[1]!==null&&newXY
[1]!=pos
[1])){this.setXY(el
,pos
,true);}}};Y
.Dom
.batch(el
,f
,Y
.Dom
,true);},setX:function(el
,x
){Y
.Dom
.setXY(el
,[x
,null]);},setY:function(el
,y
){Y
.Dom
.setXY(el
,[null,y
]);},getRegion:function(el
){var f=function(el
){var region
=new Y
.Region
.getRegion(el
);return region
;};return Y
.Dom
.batch(el
,f
,Y
.Dom
,true);},getClientWidth:function(){return Y
.Dom
.getViewportWidth();},getClientHeight:function(){return Y
.Dom
.getViewportHeight();},getElementsByClassName:function(className
,tag
,root
){var method=function(el
){return Y
.Dom
.hasClass(el
,className
);};return Y
.Dom
.getElementsBy(method
,tag
,root
);},hasClass:function(el
,className
){var re
=new RegExp('(?:^|\\s+)'+className
+'(?:\\s+|$)');var f=function(el
){return re
.test(el
['className']);};return Y
.Dom
.batch(el
,f
,Y
.Dom
,true);},addClass:function(el
,className
){var f=function(el
){if(this.hasClass(el
,className
)){return;}
38 el
['className']=[el
['className'],className
].join(' ');};Y
.Dom
.batch(el
,f
,Y
.Dom
,true);},removeClass:function(el
,className
){var re
=new RegExp('(?:^|\\s+)'+className
+'(?:\\s+|$)','g');var f=function(el
){if(!this.hasClass(el
,className
)){return;}
39 var c
=el
['className'];el
['className']=c
.replace(re
,' ');if(this.hasClass(el
,className
)){this.removeClass(el
,className
);}};Y
.Dom
.batch(el
,f
,Y
.Dom
,true);},replaceClass:function(el
,oldClassName
,newClassName
){if(oldClassName
===newClassName
){return false;}
40 var re
=new RegExp('(?:^|\\s+)'+oldClassName
+'(?:\\s+|$)','g');var f=function(el
){if(!this.hasClass(el
,oldClassName
)){this.addClass(el
,newClassName
);return;}
41 el
['className']=el
['className'].replace(re
,' '+newClassName
+' ');if(this.hasClass(el
,oldClassName
)){this.replaceClass(el
,oldClassName
,newClassName
);}};Y
.Dom
.batch(el
,f
,Y
.Dom
,true);},generateId:function(el
,prefix
){prefix
=prefix
||'yui-gen';el
=el
||{};var f=function(el
){if(el
){el
=Y
.Dom
.get(el
);}else{el
={};}
42 if(!el
.id
){el
.id
=prefix
+id_counter
++;}
43 return el
.id
;};return Y
.Dom
.batch(el
,f
,Y
.Dom
,true);},isAncestor:function(haystack
,needle
){haystack
=Y
.Dom
.get(haystack
);if(!haystack
||!needle
){return false;}
44 var f=function(needle
){if(haystack
.contains
&&!isSafari
){return haystack
.contains(needle
);}
45 else if(haystack
.compareDocumentPosition
){return!!(haystack
.compareDocumentPosition(needle
)&16);}
46 else{var parent
=needle
.parentNode
;while(parent
){if(parent
==haystack
){return true;}
47 else if(!parent
.tagName
||parent
.tagName
.toUpperCase()=='HTML'){return false;}
48 parent
=parent
.parentNode
;}
49 return false;}};return Y
.Dom
.batch(needle
,f
,Y
.Dom
,true);},inDocument:function(el
){var f=function(el
){return this.isAncestor(document
.documentElement
,el
);};return Y
.Dom
.batch(el
,f
,Y
.Dom
,true);},getElementsBy:function(method
,tag
,root
){tag
=tag
||'*';var nodes
=[];if(root
){root
=Y
.Dom
.get(root
);if(!root
){return nodes
;}}else{root
=document
;}
50 var elements
=root
.getElementsByTagName(tag
);if(!elements
.length
&&(tag
=='*'&&root
.all
)){elements
=root
.all
;}
51 for(var i
=0,len
=elements
.length
;i
<len
;++i
){if(method(elements
[i
])){nodes
[nodes
.length
]=elements
[i
];}}
52 return nodes
;},batch:function(el
,method
,o
,override
){var id
=el
;el
=Y
.Dom
.get(el
);var scope
=(override
)?o
:window
;if(!el
||el
.tagName
||!el
.length
){if(!el
){return false;}
53 return method
.call(scope
,el
,o
);}
54 var collection
=[];for(var i
=0,len
=el
.length
;i
<len
;++i
){if(!el
[i
]){id
=el
[i
];}
55 collection
[collection
.length
]=method
.call(scope
,el
[i
],o
);}
56 return collection
;},getDocumentHeight:function(){var scrollHeight
=(document
.compatMode
!='CSS1Compat')?document
.body
.scrollHeight
:document
.documentElement
.scrollHeight
;var h
=Math
.max(scrollHeight
,Y
.Dom
.getViewportHeight());return h
;},getDocumentWidth:function(){var scrollWidth
=(document
.compatMode
!='CSS1Compat')?document
.body
.scrollWidth
:document
.documentElement
.scrollWidth
;var w
=Math
.max(scrollWidth
,Y
.Dom
.getViewportWidth());return w
;},getViewportHeight:function(){var height
=self
.innerHeight
;var mode
=document
.compatMode
;if((mode
||isIE
)&&!isOpera
){height
=(mode
=='CSS1Compat')?document
.documentElement
.clientHeight
:document
.body
.clientHeight
;}
57 return height
;},getViewportWidth:function(){var width
=self
.innerWidth
;var mode
=document
.compatMode
;if(mode
||isIE
){width
=(mode
=='CSS1Compat')?document
.documentElement
.clientWidth
:document
.body
.clientWidth
;}
58 return width
;}};})();YAHOO
.util
.Region=function(t
,r
,b
,l
){this.top
=t
;this[1]=t
;this.right
=r
;this.bottom
=b
;this.left
=l
;this[0]=l
;};YAHOO
.util
.Region
.prototype.contains=function(region
){return(region
.left
>=this.left
&®ion
.right
<=this.right
&®ion
.top
>=this.top
&®ion
.bottom
<=this.bottom
);};YAHOO
.util
.Region
.prototype.getArea=function(){return((this.bottom
-this.top
)*(this.right
-this.left
));};YAHOO
.util
.Region
.prototype.intersect=function(region
){var t
=Math
.max(this.top
,region
.top
);var r
=Math
.min(this.right
,region
.right
);var b
=Math
.min(this.bottom
,region
.bottom
);var l
=Math
.max(this.left
,region
.left
);if(b
>=t
&&r
>=l
){return new YAHOO
.util
.Region(t
,r
,b
,l
);}else{return null;}};YAHOO
.util
.Region
.prototype.union=function(region
){var t
=Math
.min(this.top
,region
.top
);var r
=Math
.max(this.right
,region
.right
);var b
=Math
.max(this.bottom
,region
.bottom
);var l
=Math
.min(this.left
,region
.left
);return new YAHOO
.util
.Region(t
,r
,b
,l
);};YAHOO
.util
.Region
.prototype.toString=function(){return("Region {"+"top: "+this.top
+", right: "+this.right
+", bottom: "+this.bottom
+", left: "+this.left
+"}");};YAHOO
.util
.Region
.getRegion=function(el
){var p
=YAHOO
.util
.Dom
.getXY(el
);var t
=p
[1];var r
=p
[0]+el
.offsetWidth
;var b
=p
[1]+el
.offsetHeight
;var l
=p
[0];return new YAHOO
.util
.Region(t
,r
,b
,l
);};YAHOO
.util
.Point=function(x
,y
){if(x
instanceof Array
){y
=x
[1];x
=x
[0];}
59 this.x
=this.right
=this.left
=this[0]=x
;this.y
=this.top
=this.bottom
=this[1]=y
;};YAHOO
.util
.Point
.prototype=new YAHOO
.util
.Region();