You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jd...@apache.org on 2009/04/09 15:31:55 UTC
svn commit: r763645 [4/8] - in
/wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui:
./ assets/skins/sam/ calendar/ calendar/assets/skins/sam/ dom/ event/
yahoo-dom-event/ yahoo/
Added: wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/dom/dom-min.js
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/dom/dom-min.js?rev=763645&view=auto
==============================================================================
--- wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/dom/dom-min.js (added)
+++ wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/dom/dom-min.js Thu Apr 9 13:31:54 2009
@@ -0,0 +1,9 @@
+/*
+Copyright (c) 2009, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 2.7.0
+*/
+(function(){YAHOO.env._id_counter=YAHOO.env._id_counter||0;var E=YAHOO.util,L=YAHOO.lang,m=YAHOO.env.ua,A=YAHOO.lang.trim,d={},h={},N=/^t(?:able|d|h)$/i,X=/color$/i,K=window.document,W=K.documentElement,e="ownerDocument",n="defaultView",v="documentElement",t="compatMode",b="offsetLeft",P="offsetTop",u="offsetParent",Z="parentNode",l="nodeType",C="tagName",O="scrollLeft",i="scrollTop",Q="getBoundingClientRect",w="getComputedStyle",a="currentStyle",M="CSS1Compat",c="BackCompat",g="class",F="className",J="",B=" ",s="(?:^|\\s)",k="(?= |$)",U="g",p="position",f="fixed",V="relative",j="left",o="top",r="medium",q="borderLeftWidth",R="borderTopWidth",D=m.opera,I=m.webkit,H=m.gecko,T=m.ie;E.Dom={CUSTOM_ATTRIBUTES:(!W.hasAttribute)?{"for":"htmlFor","class":F}:{"htmlFor":"for","className":g},get:function(y){var AA,Y,z,x,G;if(y){if(y[l]||y.item){return y;}if(typeof y==="string"){AA=y;y=K.getElementById(y);if(y&&y.id===AA){return y;}else{if(y&&K.all){y=null;Y=K.all[AA];for(x=0,G=Y.length
;x<G;++x){if(Y[x].id===AA){return Y[x];}}}}return y;}if(y.DOM_EVENTS){y=y.get("element");}if("length" in y){z=[];for(x=0,G=y.length;x<G;++x){z[z.length]=E.Dom.get(y[x]);}return z;}return y;}return null;},getComputedStyle:function(G,Y){if(window[w]){return G[e][n][w](G,null)[Y];}else{if(G[a]){return E.Dom.IE_ComputedStyle.get(G,Y);}}},getStyle:function(G,Y){return E.Dom.batch(G,E.Dom._getStyle,Y);},_getStyle:function(){if(window[w]){return function(G,y){y=(y==="float")?y="cssFloat":E.Dom._toCamel(y);var x=G.style[y],Y;if(!x){Y=G[e][n][w](G,null);if(Y){x=Y[y];}}return x;};}else{if(W[a]){return function(G,y){var x;switch(y){case"opacity":x=100;try{x=G.filters["DXImageTransform.Microsoft.Alpha"].opacity;}catch(z){try{x=G.filters("alpha").opacity;}catch(Y){}}return x/100;case"float":y="styleFloat";default:y=E.Dom._toCamel(y);x=G[a]?G[a][y]:null;return(G.style[y]||x);}};}}}(),setStyle:function(G,Y,x){E.Dom.batch(G,E.Dom._setStyle,{prop:Y,val:x});},_setStyle:function(){if(T){return
function(Y,G){var x=E.Dom._toCamel(G.prop),y=G.val;if(Y){switch(x){case"opacity":if(L.isString(Y.style.filter)){Y.style.filter="alpha(opacity="+y*100+")";if(!Y[a]||!Y[a].hasLayout){Y.style.zoom=1;}}break;case"float":x="styleFloat";default:Y.style[x]=y;}}else{}};}else{return function(Y,G){var x=E.Dom._toCamel(G.prop),y=G.val;if(Y){if(x=="float"){x="cssFloat";}Y.style[x]=y;}else{}};}}(),getXY:function(G){return E.Dom.batch(G,E.Dom._getXY);},_canPosition:function(G){return(E.Dom._getStyle(G,"display")!=="none"&&E.Dom._inDoc(G));},_getXY:function(){if(K[v][Q]){return function(y){var z,Y,AA,AF,AE,AD,AC,G,x,AB=Math.floor,AG=false;if(E.Dom._canPosition(y)){AA=y[Q]();AF=y[e];z=E.Dom.getDocumentScrollLeft(AF);Y=E.Dom.getDocumentScrollTop(AF);AG=[AB(AA[j]),AB(AA[o])];if(T&&m.ie<8){AE=2;AD=2;AC=AF[t];G=S(AF[v],q);x=S(AF[v],R);if(m.ie===6){if(AC!==c){AE=0;AD=0;}}if((AC==c)){if(G!==r){AE=parseInt(G,10);}if(x!==r){AD=parseInt(x,10);}}AG[0]-=AE;AG[1]-=AD;}if((Y||z)){AG[0]+=z;AG[1]+=Y;}AG[
0]=AB(AG[0]);AG[1]=AB(AG[1]);}else{}return AG;};}else{return function(y){var x,Y,AA,AB,AC,z=false,G=y;if(E.Dom._canPosition(y)){z=[y[b],y[P]];x=E.Dom.getDocumentScrollLeft(y[e]);Y=E.Dom.getDocumentScrollTop(y[e]);AC=((H||m.webkit>519)?true:false);while((G=G[u])){z[0]+=G[b];z[1]+=G[P];if(AC){z=E.Dom._calcBorders(G,z);}}if(E.Dom._getStyle(y,p)!==f){G=y;while((G=G[Z])&&G[C]){AA=G[i];AB=G[O];if(H&&(E.Dom._getStyle(G,"overflow")!=="visible")){z=E.Dom._calcBorders(G,z);}if(AA||AB){z[0]-=AB;z[1]-=AA;}}z[0]+=x;z[1]+=Y;}else{if(D){z[0]-=x;z[1]-=Y;}else{if(I||H){z[0]+=x;z[1]+=Y;}}}z[0]=Math.floor(z[0]);z[1]=Math.floor(z[1]);}else{}return z;};}}(),getX:function(G){var Y=function(x){return E.Dom.getXY(x)[0];};return E.Dom.batch(G,Y,E.Dom,true);},getY:function(G){var Y=function(x){return E.Dom.getXY(x)[1];};return E.Dom.batch(G,Y,E.Dom,true);},setXY:function(G,x,Y){E.Dom.batch(G,E.Dom._setXY,{pos:x,noRetry:Y});},_setXY:function(G,z){var AA=E.Dom._getStyle(G,p),y=E.Dom.setStyle,AD=z.pos,Y
=z.noRetry,AB=[parseInt(E.Dom.getComputedStyle(G,j),10),parseInt(E.Dom.getComputedStyle(G,o),10)],AC,x;if(AA=="static"){AA=V;y(G,p,AA);}AC=E.Dom._getXY(G);if(!AD||AC===false){return false;}if(isNaN(AB[0])){AB[0]=(AA==V)?0:G[b];}if(isNaN(AB[1])){AB[1]=(AA==V)?0:G[P];}if(AD[0]!==null){y(G,j,AD[0]-AC[0]+AB[0]+"px");}if(AD[1]!==null){y(G,o,AD[1]-AC[1]+AB[1]+"px");}if(!Y){x=E.Dom._getXY(G);if((AD[0]!==null&&x[0]!=AD[0])||(AD[1]!==null&&x[1]!=AD[1])){E.Dom._setXY(G,{pos:AD,noRetry:true});}}},setX:function(Y,G){E.Dom.setXY(Y,[G,null]);},setY:function(G,Y){E.Dom.setXY(G,[null,Y]);},getRegion:function(G){var Y=function(x){var y=false;if(E.Dom._canPosition(x)){y=E.Region.getRegion(x);}else{}return y;};return E.Dom.batch(G,Y,E.Dom,true);},getClientWidth:function(){return E.Dom.getViewportWidth();},getClientHeight:function(){return E.Dom.getViewportHeight();},getElementsByClassName:function(AB,AF,AC,AE,x,AD){AB=L.trim(AB);AF=AF||"*";AC=(AC)?E.Dom.get(AC):null||K;if(!AC){return[];}var Y=
[],G=AC.getElementsByTagName(AF),z=E.Dom.hasClass;for(var y=0,AA=G.length;y<AA;++y){if(z(G[y],AB)){Y[Y.length]=G[y];}}if(AE){E.Dom.batch(Y,AE,x,AD);}return Y;},hasClass:function(Y,G){return E.Dom.batch(Y,E.Dom._hasClass,G);},_hasClass:function(x,Y){var G=false,y;if(x&&Y){y=E.Dom.getAttribute(x,F)||J;if(Y.exec){G=Y.test(y);}else{G=Y&&(B+y+B).indexOf(B+Y+B)>-1;}}else{}return G;},addClass:function(Y,G){return E.Dom.batch(Y,E.Dom._addClass,G);},_addClass:function(x,Y){var G=false,y;if(x&&Y){y=E.Dom.getAttribute(x,F)||J;if(!E.Dom._hasClass(x,Y)){E.Dom.setAttribute(x,F,A(y+B+Y));G=true;}}else{}return G;},removeClass:function(Y,G){return E.Dom.batch(Y,E.Dom._removeClass,G);},_removeClass:function(y,x){var Y=false,AA,z,G;if(y&&x){AA=E.Dom.getAttribute(y,F)||J;E.Dom.setAttribute(y,F,AA.replace(E.Dom._getClassRegex(x),J));z=E.Dom.getAttribute(y,F);if(AA!==z){E.Dom.setAttribute(y,F,A(z));Y=true;if(E.Dom.getAttribute(y,F)===""){G=(y.hasAttribute&&y.hasAttribute(g))?g:F;y.removeAttribute
(G);}}}else{}return Y;},replaceClass:function(x,Y,G){return E.Dom.batch(x,E.Dom._replaceClass,{from:Y,to:G});
+},_replaceClass:function(y,x){var Y,AB,AA,G=false,z;if(y&&x){AB=x.from;AA=x.to;if(!AA){G=false;}else{if(!AB){G=E.Dom._addClass(y,x.to);}else{if(AB!==AA){z=E.Dom.getAttribute(y,F)||J;Y=(B+z.replace(E.Dom._getClassRegex(AB),B+AA)).split(E.Dom._getClassRegex(AA));Y.splice(1,0,B+AA);E.Dom.setAttribute(y,F,A(Y.join(J)));G=true;}}}}else{}return G;},generateId:function(G,x){x=x||"yui-gen";var Y=function(y){if(y&&y.id){return y.id;}var z=x+YAHOO.env._id_counter++;if(y){if(y[e].getElementById(z)){return E.Dom.generateId(y,z+x);}y.id=z;}return z;};return E.Dom.batch(G,Y,E.Dom,true)||Y.apply(E.Dom,arguments);},isAncestor:function(Y,x){Y=E.Dom.get(Y);x=E.Dom.get(x);var G=false;if((Y&&x)&&(Y[l]&&x[l])){if(Y.contains&&Y!==x){G=Y.contains(x);}else{if(Y.compareDocumentPosition){G=!!(Y.compareDocumentPosition(x)&16);}}}else{}return G;},inDocument:function(G,Y){return E.Dom._inDoc(E.Dom.get(G),Y);},_inDoc:function(Y,x){var G=false;if(Y&&Y[C]){x=x||Y[e];G=E.Dom.isAncestor(x[v],Y);}else{}return
G;},getElementsBy:function(Y,AF,AB,AD,y,AC,AE){AF=AF||"*";AB=(AB)?E.Dom.get(AB):null||K;if(!AB){return[];}var x=[],G=AB.getElementsByTagName(AF);for(var z=0,AA=G.length;z<AA;++z){if(Y(G[z])){if(AE){x=G[z];break;}else{x[x.length]=G[z];}}}if(AD){E.Dom.batch(x,AD,y,AC);}return x;},getElementBy:function(x,G,Y){return E.Dom.getElementsBy(x,G,Y,null,null,null,true);},batch:function(x,AB,AA,z){var y=[],Y=(z)?AA:window;x=(x&&(x[C]||x.item))?x:E.Dom.get(x);if(x&&AB){if(x[C]||x.length===undefined){return AB.call(Y,x,AA);}for(var G=0;G<x.length;++G){y[y.length]=AB.call(Y,x[G],AA);}}else{return false;}return y;},getDocumentHeight:function(){var Y=(K[t]!=M||I)?K.body.scrollHeight:W.scrollHeight,G=Math.max(Y,E.Dom.getViewportHeight());return G;},getDocumentWidth:function(){var Y=(K[t]!=M||I)?K.body.scrollWidth:W.scrollWidth,G=Math.max(Y,E.Dom.getViewportWidth());return G;},getViewportHeight:function(){var G=self.innerHeight,Y=K[t];if((Y||T)&&!D){G=(Y==M)?W.clientHeight:K.body.clientHeigh
t;}return G;},getViewportWidth:function(){var G=self.innerWidth,Y=K[t];if(Y||T){G=(Y==M)?W.clientWidth:K.body.clientWidth;}return G;},getAncestorBy:function(G,Y){while((G=G[Z])){if(E.Dom._testElement(G,Y)){return G;}}return null;},getAncestorByClassName:function(Y,G){Y=E.Dom.get(Y);if(!Y){return null;}var x=function(y){return E.Dom.hasClass(y,G);};return E.Dom.getAncestorBy(Y,x);},getAncestorByTagName:function(Y,G){Y=E.Dom.get(Y);if(!Y){return null;}var x=function(y){return y[C]&&y[C].toUpperCase()==G.toUpperCase();};return E.Dom.getAncestorBy(Y,x);},getPreviousSiblingBy:function(G,Y){while(G){G=G.previousSibling;if(E.Dom._testElement(G,Y)){return G;}}return null;},getPreviousSibling:function(G){G=E.Dom.get(G);if(!G){return null;}return E.Dom.getPreviousSiblingBy(G);},getNextSiblingBy:function(G,Y){while(G){G=G.nextSibling;if(E.Dom._testElement(G,Y)){return G;}}return null;},getNextSibling:function(G){G=E.Dom.get(G);if(!G){return null;}return E.Dom.getNextSiblingBy(G);},getF
irstChildBy:function(G,x){var Y=(E.Dom._testElement(G.firstChild,x))?G.firstChild:null;return Y||E.Dom.getNextSiblingBy(G.firstChild,x);},getFirstChild:function(G,Y){G=E.Dom.get(G);if(!G){return null;}return E.Dom.getFirstChildBy(G);},getLastChildBy:function(G,x){if(!G){return null;}var Y=(E.Dom._testElement(G.lastChild,x))?G.lastChild:null;return Y||E.Dom.getPreviousSiblingBy(G.lastChild,x);},getLastChild:function(G){G=E.Dom.get(G);return E.Dom.getLastChildBy(G);},getChildrenBy:function(Y,y){var x=E.Dom.getFirstChildBy(Y,y),G=x?[x]:[];E.Dom.getNextSiblingBy(x,function(z){if(!y||y(z)){G[G.length]=z;}return false;});return G;},getChildren:function(G){G=E.Dom.get(G);if(!G){}return E.Dom.getChildrenBy(G);},getDocumentScrollLeft:function(G){G=G||K;return Math.max(G[v].scrollLeft,G.body.scrollLeft);},getDocumentScrollTop:function(G){G=G||K;return Math.max(G[v].scrollTop,G.body.scrollTop);},insertBefore:function(Y,G){Y=E.Dom.get(Y);G=E.Dom.get(G);if(!Y||!G||!G[Z]){return null;}ret
urn G[Z].insertBefore(Y,G);},insertAfter:function(Y,G){Y=E.Dom.get(Y);G=E.Dom.get(G);if(!Y||!G||!G[Z]){return null;}if(G.nextSibling){return G[Z].insertBefore(Y,G.nextSibling);}else{return G[Z].appendChild(Y);}},getClientRegion:function(){var x=E.Dom.getDocumentScrollTop(),Y=E.Dom.getDocumentScrollLeft(),y=E.Dom.getViewportWidth()+Y,G=E.Dom.getViewportHeight()+x;return new E.Region(x,y,G,Y);},setAttribute:function(Y,G,x){G=E.Dom.CUSTOM_ATTRIBUTES[G]||G;Y.setAttribute(G,x);},getAttribute:function(Y,G){G=E.Dom.CUSTOM_ATTRIBUTES[G]||G;return Y.getAttribute(G);},_toCamel:function(Y){var x=d;function G(y,z){return z.toUpperCase();}return x[Y]||(x[Y]=Y.indexOf("-")===-1?Y:Y.replace(/-([a-z])/gi,G));},_getClassRegex:function(Y){var G;if(Y!==undefined){if(Y.exec){G=Y;}else{G=h[Y];if(!G){Y=Y.replace(E.Dom._patterns.CLASS_RE_TOKENS,"\\$1");G=h[Y]=new RegExp(s+Y+k,U);}}}return G;},_patterns:{ROOT_TAG:/^body|html$/i,CLASS_RE_TOKENS:/([\.\(\)\^\$\*\+\?\|\[\]\{\}])/g},_testElement:functio
n(G,Y){return G&&G[l]==1&&(!Y||Y(G));},_calcBorders:function(x,y){var Y=parseInt(E.Dom[w](x,R),10)||0,G=parseInt(E.Dom[w](x,q),10)||0;if(H){if(N.test(x[C])){Y=0;G=0;}}y[0]+=G;y[1]+=Y;return y;}};var S=E.Dom[w];if(m.opera){E.Dom[w]=function(Y,G){var x=S(Y,G);if(X.test(G)){x=E.Dom.Color.toRGB(x);}return x;};}if(m.webkit){E.Dom[w]=function(Y,G){var x=S(Y,G);if(x==="rgba(0, 0, 0, 0)"){x="transparent";}return x;};}})();YAHOO.util.Region=function(C,D,A,B){this.top=C;this.y=C;this[1]=C;this.right=D;this.bottom=A;this.left=B;this.x=B;this[0]=B;this.width=this.right-this.left;this.height=this.bottom-this.top;};YAHOO.util.Region.prototype.contains=function(A){return(A.left>=this.left&&A.right<=this.right&&A.top>=this.top&&A.bottom<=this.bottom);};YAHOO.util.Region.prototype.getArea=function(){return((this.bottom-this.top)*(this.right-this.left));};YAHOO.util.Region.prototype.intersect=function(E){var C=Math.max(this.top,E.top),D=Math.min(this.right,E.right),A=Math.min(this.bottom,E.bo
ttom),B=Math.max(this.left,E.left);if(A>=C&&D>=B){return new YAHOO.util.Region(C,D,A,B);
+}else{return null;}};YAHOO.util.Region.prototype.union=function(E){var C=Math.min(this.top,E.top),D=Math.max(this.right,E.right),A=Math.max(this.bottom,E.bottom),B=Math.min(this.left,E.left);return new YAHOO.util.Region(C,D,A,B);};YAHOO.util.Region.prototype.toString=function(){return("Region {"+"top: "+this.top+", right: "+this.right+", bottom: "+this.bottom+", left: "+this.left+", height: "+this.height+", width: "+this.width+"}");};YAHOO.util.Region.getRegion=function(D){var F=YAHOO.util.Dom.getXY(D),C=F[1],E=F[0]+D.offsetWidth,A=F[1]+D.offsetHeight,B=F[0];return new YAHOO.util.Region(C,E,A,B);};YAHOO.util.Point=function(A,B){if(YAHOO.lang.isArray(A)){B=A[1];A=A[0];}YAHOO.util.Point.superclass.constructor.call(this,B,A,B,A);};YAHOO.extend(YAHOO.util.Point,YAHOO.util.Region);(function(){var B=YAHOO.util,A="clientTop",F="clientLeft",J="parentNode",K="right",W="hasLayout",I="px",U="opacity",L="auto",D="borderLeftWidth",G="borderTopWidth",P="borderRightWidth",V="borderBottomWi
dth",S="visible",Q="transparent",N="height",E="width",H="style",T="currentStyle",R=/^width|height$/,O=/^(\d[.\d]*)+(em|ex|px|gd|rem|vw|vh|vm|ch|mm|cm|in|pt|pc|deg|rad|ms|s|hz|khz|%){1}?/i,M={get:function(X,Z){var Y="",a=X[T][Z];if(Z===U){Y=B.Dom.getStyle(X,U);}else{if(!a||(a.indexOf&&a.indexOf(I)>-1)){Y=a;}else{if(B.Dom.IE_COMPUTED[Z]){Y=B.Dom.IE_COMPUTED[Z](X,Z);}else{if(O.test(a)){Y=B.Dom.IE.ComputedStyle.getPixel(X,Z);}else{Y=a;}}}}return Y;},getOffset:function(Z,e){var b=Z[T][e],X=e.charAt(0).toUpperCase()+e.substr(1),c="offset"+X,Y="pixel"+X,a="",d;if(b==L){d=Z[c];if(d===undefined){a=0;}a=d;if(R.test(e)){Z[H][e]=d;if(Z[c]>d){a=d-(Z[c]-d);}Z[H][e]=L;}}else{if(!Z[H][Y]&&!Z[H][e]){Z[H][e]=b;}a=Z[H][Y];}return a+I;},getBorderWidth:function(X,Z){var Y=null;if(!X[T][W]){X[H].zoom=1;}switch(Z){case G:Y=X[A];break;case V:Y=X.offsetHeight-X.clientHeight-X[A];break;case D:Y=X[F];break;case P:Y=X.offsetWidth-X.clientWidth-X[F];break;}return Y+I;},getPixel:function(Y,X){var a=null,
b=Y[T][K],Z=Y[T][X];Y[H][K]=Z;a=Y[H].pixelRight;Y[H][K]=b;return a+I;},getMargin:function(Y,X){var Z;if(Y[T][X]==L){Z=0+I;}else{Z=B.Dom.IE.ComputedStyle.getPixel(Y,X);}return Z;},getVisibility:function(Y,X){var Z;while((Z=Y[T])&&Z[X]=="inherit"){Y=Y[J];}return(Z)?Z[X]:S;},getColor:function(Y,X){return B.Dom.Color.toRGB(Y[T][X])||Q;},getBorderColor:function(Y,X){var Z=Y[T],a=Z[X]||Z.color;return B.Dom.Color.toRGB(B.Dom.Color.toHex(a));}},C={};C.top=C.right=C.bottom=C.left=C[E]=C[N]=M.getOffset;C.color=M.getColor;C[G]=C[P]=C[V]=C[D]=M.getBorderWidth;C.marginTop=C.marginRight=C.marginBottom=C.marginLeft=M.getMargin;C.visibility=M.getVisibility;C.borderColor=C.borderTopColor=C.borderRightColor=C.borderBottomColor=C.borderLeftColor=M.getBorderColor;B.Dom.IE_COMPUTED=C;B.Dom.IE_ComputedStyle=M;})();(function(){var C="toString",A=parseInt,B=RegExp,D=YAHOO.util;D.Dom.Color={KEYWORDS:{black:"000",silver:"c0c0c0",gray:"808080",white:"fff",maroon:"800000",red:"f00",purple:"800080",fuch
sia:"f0f",green:"008000",lime:"0f0",olive:"808000",yellow:"ff0",navy:"000080",blue:"00f",teal:"008080",aqua:"0ff"},re_RGB:/^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i,re_hex:/^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i,re_hex3:/([0-9A-F])/gi,toRGB:function(E){if(!D.Dom.Color.re_RGB.test(E)){E=D.Dom.Color.toHex(E);}if(D.Dom.Color.re_hex.exec(E)){E="rgb("+[A(B.$1,16),A(B.$2,16),A(B.$3,16)].join(", ")+")";}return E;},toHex:function(H){H=D.Dom.Color.KEYWORDS[H]||H;if(D.Dom.Color.re_RGB.exec(H)){var G=(B.$1.length===1)?"0"+B.$1:Number(B.$1),F=(B.$2.length===1)?"0"+B.$2:Number(B.$2),E=(B.$3.length===1)?"0"+B.$3:Number(B.$3);H=[G[C](16),F[C](16),E[C](16)].join("");}if(H.length<6){H=H.replace(D.Dom.Color.re_hex3,"$1$1");}if(H!=="transparent"&&H.indexOf("#")<0){H="#"+H;}return H.toLowerCase();}};}());YAHOO.register("dom",YAHOO.util.Dom,{version:"2.7.0",build:"1799"});
\ No newline at end of file
Modified: wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/dom/dom.js
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/dom/dom.js?rev=763645&r1=763644&r2=763645&view=diff
==============================================================================
--- wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/dom/dom.js (original)
+++ wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/dom/dom.js Thu Apr 9 13:31:54 2009
@@ -1,8 +1,8 @@
/*
-Copyright (c) 2007, Yahoo! Inc. All rights reserved.
+Copyright (c) 2009, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
-version: 2.4.1
+version: 2.7.0
*/
/**
* The dom module provides helper methods for manipulating Dom elements.
@@ -11,136 +11,77 @@
*/
(function() {
- var Y = YAHOO.util, // internal shorthand
- getStyle, // for load time browser branching
- setStyle, // ditto
- id_counter = 0, // for use with generateId
+ YAHOO.env._id_counter = YAHOO.env._id_counter || 0; // for use with generateId (global to save state if Dom is overwritten)
+
+ // internal shorthand
+ var Y = YAHOO.util,
+ lang = YAHOO.lang,
+ UA = YAHOO.env.ua,
+ trim = YAHOO.lang.trim,
propertyCache = {}, // for faster hyphen converts
- reClassNameCache = {}, // cache regexes for className
- document = window.document; // cache for faster lookups
+ reCache = {}, // cache className regexes
+ RE_TABLE = /^t(?:able|d|h)$/i, // for _calcBorders
+ RE_COLOR = /color$/i,
+
+ // DOM aliases
+ document = window.document,
+ documentElement = document.documentElement,
+
+ // string constants
+ OWNER_DOCUMENT = 'ownerDocument',
+ DEFAULT_VIEW = 'defaultView',
+ DOCUMENT_ELEMENT = 'documentElement',
+ COMPAT_MODE = 'compatMode',
+ OFFSET_LEFT = 'offsetLeft',
+ OFFSET_TOP = 'offsetTop',
+ OFFSET_PARENT = 'offsetParent',
+ PARENT_NODE = 'parentNode',
+ NODE_TYPE = 'nodeType',
+ TAG_NAME = 'tagName',
+ SCROLL_LEFT = 'scrollLeft',
+ SCROLL_TOP = 'scrollTop',
+ GET_BOUNDING_CLIENT_RECT = 'getBoundingClientRect',
+ GET_COMPUTED_STYLE = 'getComputedStyle',
+ CURRENT_STYLE = 'currentStyle',
+ CSS1_COMPAT = 'CSS1Compat',
+ _BACK_COMPAT = 'BackCompat',
+ _CLASS = 'class', // underscore due to reserved word
+ CLASS_NAME = 'className',
+ EMPTY = '',
+ SPACE = ' ',
+ C_START = '(?:^|\\s)',
+ C_END = '(?= |$)',
+ G = 'g',
+ POSITION = 'position',
+ FIXED = 'fixed',
+ RELATIVE = 'relative',
+ LEFT = 'left',
+ TOP = 'top',
+ MEDIUM = 'medium',
+ BORDER_LEFT_WIDTH = 'borderLeftWidth',
+ BORDER_TOP_WIDTH = 'borderTopWidth',
// brower detection
- var isOpera = YAHOO.env.ua.opera,
- isSafari = YAHOO.env.ua.webkit,
- isGecko = YAHOO.env.ua.gecko,
- isIE = YAHOO.env.ua.ie;
-
- // regex cache
- var patterns = {
- HYPHEN: /(-[a-z])/i, // to normalize get/setStyle
- ROOT_TAG: /^body|html$/i // body for quirks mode, html for standards
- };
-
- var toCamel = function(property) {
- if ( !patterns.HYPHEN.test(property) ) {
- return property; // no hyphens
- }
-
- if (propertyCache[property]) { // already converted
- return propertyCache[property];
- }
-
- var converted = property;
-
- while( patterns.HYPHEN.exec(converted) ) {
- converted = converted.replace(RegExp.$1,
- RegExp.$1.substr(1).toUpperCase());
- }
-
- propertyCache[property] = converted;
- return converted;
- //return property.replace(/-([a-z])/gi, function(m0, m1) {return m1.toUpperCase()}) // cant use function as 2nd arg yet due to safari bug
- };
-
- var getClassRegEx = function(className) {
- var re = reClassNameCache[className];
- if (!re) {
- re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)');
- reClassNameCache[className] = re;
- }
- return re;
- };
-
- // branching at load instead of runtime
- if (document.defaultView && document.defaultView.getComputedStyle) { // W3C DOM method
- getStyle = function(el, property) {
- var value = null;
-
- if (property == 'float') { // fix reserved word
- property = 'cssFloat';
- }
-
- var computed = document.defaultView.getComputedStyle(el, '');
- if (computed) { // test computed before touching for safari
- value = computed[toCamel(property)];
- }
-
- return el.style[property] || value;
- };
- } else if (document.documentElement.currentStyle && isIE) { // IE method
- getStyle = function(el, property) {
- switch( toCamel(property) ) {
- case 'opacity' :// IE opacity uses filter
- var val = 100;
- try { // will error if no DXImageTransform
- val = el.filters['DXImageTransform.Microsoft.Alpha'].opacity;
-
- } catch(e) {
- try { // make sure its in the document
- val = el.filters('alpha').opacity;
- } catch(e) {
- }
- }
- return val / 100;
- case 'float': // fix reserved word
- property = 'styleFloat'; // fall through
- default:
- // test currentStyle before touching
- var value = el.currentStyle ? el.currentStyle[property] : null;
- return ( el.style[property] || value );
- }
- };
- } else { // default to inline only
- getStyle = function(el, property) { return el.style[property]; };
- }
+ isOpera = UA.opera,
+ isSafari = UA.webkit,
+ isGecko = UA.gecko,
+ isIE = UA.ie;
- if (isIE) {
- setStyle = function(el, property, val) {
- switch (property) {
- case 'opacity':
- if ( YAHOO.lang.isString(el.style.filter) ) { // in case not appended
- el.style.filter = 'alpha(opacity=' + val * 100 + ')';
-
- if (!el.currentStyle || !el.currentStyle.hasLayout) {
- el.style.zoom = 1; // when no layout or cant tell
- }
- }
- break;
- case 'float':
- property = 'styleFloat';
- default:
- el.style[property] = val;
- }
- };
- } else {
- setStyle = function(el, property, val) {
- if (property == 'float') {
- property = 'cssFloat';
- }
- el.style[property] = val;
- };
- }
-
- var testElement = function(node, method) {
- return node && node.nodeType == 1 && ( !method || method(node) );
- };
-
/**
* Provides helper methods for DOM elements.
* @namespace YAHOO.util
* @class Dom
+ * @requires yahoo, event
*/
- YAHOO.util.Dom = {
+ Y.Dom = {
+ CUSTOM_ATTRIBUTES: (!documentElement.hasAttribute) ? { // IE < 8
+ 'for': 'htmlFor',
+ 'class': CLASS_NAME
+ } : { // w3c
+ 'htmlFor': 'for',
+ 'className': _CLASS
+ },
+
/**
* Returns an HTMLElement reference.
* @method get
@@ -148,26 +89,57 @@
* @return {HTMLElement | Array} A DOM reference to an HTML element or an array of HTMLElements.
*/
get: function(el) {
- if (el && (el.tagName || el.item)) { // HTMLElement, or HTMLCollection
- return el;
- }
+ var id, nodes, c, i, len;
- if (YAHOO.lang.isString(el) || !el) { // HTMLElement or null
- return document.getElementById(el);
- }
-
- if (el.length !== undefined) { // array-like
- var c = [];
- for (var i = 0, len = el.length; i < len; ++i) {
- c[c.length] = Y.Dom.get(el[i]);
+ if (el) {
+ if (el[NODE_TYPE] || el.item) { // Node, or NodeList
+ return el;
+ }
+
+ if (typeof el === 'string') { // id
+ id = el;
+ el = document.getElementById(el);
+ if (el && el.id === id) { // IE: avoid false match on "name" attribute
+ return el;
+ } else if (el && document.all) { // filter by name
+ el = null;
+ nodes = document.all[id];
+ for (i = 0, len = nodes.length; i < len; ++i) {
+ if (nodes[i].id === id) {
+ return nodes[i];
+ }
+ }
+ }
+ return el;
}
- return c;
+ if (el.DOM_EVENTS) { // YAHOO.util.Element
+ el = el.get('element');
+ }
+
+ if ('length' in el) { // array-like
+ c = [];
+ for (i = 0, len = el.length; i < len; ++i) {
+ c[c.length] = Y.Dom.get(el[i]);
+ }
+
+ return c;
+ }
+
+ return el; // some other object, just pass it back
}
- return el; // some other object, just pass it back
+ return null;
},
+ getComputedStyle: function(el, property) {
+ if (window[GET_COMPUTED_STYLE]) {
+ return el[OWNER_DOCUMENT][DEFAULT_VIEW][GET_COMPUTED_STYLE](el, null)[property];
+ } else if (el[CURRENT_STYLE]) {
+ return Y.Dom.IE_ComputedStyle.get(el, property);
+ }
+ },
+
/**
* Normalizes currentStyle and ComputedStyle.
* @method getStyle
@@ -176,14 +148,55 @@
* @return {String | Array} The current value of the style property for the element(s).
*/
getStyle: function(el, property) {
- property = toCamel(property);
-
- var f = function(element) {
- return getStyle(element, property);
- };
-
- return Y.Dom.batch(el, f, Y.Dom, true);
+ return Y.Dom.batch(el, Y.Dom._getStyle, property);
},
+
+ // branching at load instead of runtime
+ _getStyle: function() {
+ if (window[GET_COMPUTED_STYLE]) { // W3C DOM method
+ return function(el, property) {
+ property = (property === 'float') ? property = 'cssFloat' :
+ Y.Dom._toCamel(property);
+
+ var value = el.style[property],
+ computed;
+
+ if (!value) {
+ computed = el[OWNER_DOCUMENT][DEFAULT_VIEW][GET_COMPUTED_STYLE](el, null);
+ if (computed) { // test computed before touching for safari
+ value = computed[property];
+ }
+ }
+
+ return value;
+ };
+ } else if (documentElement[CURRENT_STYLE]) {
+ return function(el, property) {
+ var value;
+
+ switch(property) {
+ case 'opacity' :// IE opacity uses filter
+ value = 100;
+ try { // will error if no DXImageTransform
+ value = el.filters['DXImageTransform.Microsoft.Alpha'].opacity;
+
+ } catch(e) {
+ try { // make sure its in the document
+ value = el.filters('alpha').opacity;
+ } catch(err) {
+ }
+ }
+ return value / 100;
+ case 'float': // fix reserved word
+ property = 'styleFloat'; // fall through
+ default:
+ property = Y.Dom._toCamel(property);
+ value = el[CURRENT_STYLE] ? el[CURRENT_STYLE][property] : null;
+ return ( el.style[property] || value );
+ }
+ };
+ }
+ }(),
/**
* Wrapper for setting style properties of HTMLElements. Normalizes "opacity" across modern browsers.
@@ -193,35 +206,187 @@
* @param {String} val The value to apply to the given property.
*/
setStyle: function(el, property, val) {
- property = toCamel(property);
-
- var f = function(element) {
- setStyle(element, property, val);
-
- };
-
- Y.Dom.batch(el, f, Y.Dom, true);
+ Y.Dom.batch(el, Y.Dom._setStyle, { prop: property, val: val });
},
+
+ _setStyle: function() {
+ if (isIE) {
+ return function(el, args) {
+ var property = Y.Dom._toCamel(args.prop),
+ val = args.val;
+
+ if (el) {
+ switch (property) {
+ case 'opacity':
+ if ( lang.isString(el.style.filter) ) { // in case not appended
+ el.style.filter = 'alpha(opacity=' + val * 100 + ')';
+
+ if (!el[CURRENT_STYLE] || !el[CURRENT_STYLE].hasLayout) {
+ el.style.zoom = 1; // when no layout or cant tell
+ }
+ }
+ break;
+ case 'float':
+ property = 'styleFloat';
+ default:
+ el.style[property] = val;
+ }
+ } else {
+ }
+ };
+ } else {
+ return function(el, args) {
+ var property = Y.Dom._toCamel(args.prop),
+ val = args.val;
+ if (el) {
+ if (property == 'float') {
+ property = 'cssFloat';
+ }
+ el.style[property] = val;
+ } else {
+ }
+ };
+ }
+
+ }(),
/**
- * Gets the current 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).
+ * Gets the current 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).
* @method getXY
- * @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
+ * @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
* @return {Array} The XY position of the element(s)
*/
getXY: function(el) {
- var f = function(el) {
- // has to be part of document to have pageXY
- if ( (el.parentNode === null || el.offsetParent === null ||
- this.getStyle(el, 'display') == 'none') && el != el.ownerDocument.body) {
- return false;
- }
-
- return getXY(el);
- };
-
- return Y.Dom.batch(el, f, Y.Dom, true);
+ return Y.Dom.batch(el, Y.Dom._getXY);
+ },
+
+ _canPosition: function(el) {
+ return ( Y.Dom._getStyle(el, 'display') !== 'none' && Y.Dom._inDoc(el) );
},
+
+ _getXY: function() {
+ if (document[DOCUMENT_ELEMENT][GET_BOUNDING_CLIENT_RECT]) {
+ return function(node) {
+ var scrollLeft, scrollTop, box, doc,
+ off1, off2, mode, bLeft, bTop,
+ floor = Math.floor, // TODO: round?
+ xy = false;
+
+ if (Y.Dom._canPosition(node)) {
+ box = node[GET_BOUNDING_CLIENT_RECT]();
+ doc = node[OWNER_DOCUMENT];
+ scrollLeft = Y.Dom.getDocumentScrollLeft(doc);
+ scrollTop = Y.Dom.getDocumentScrollTop(doc);
+ xy = [floor(box[LEFT]), floor(box[TOP])];
+
+ if (isIE && UA.ie < 8) { // IE < 8: viewport off by 2
+ off1 = 2;
+ off2 = 2;
+ mode = doc[COMPAT_MODE];
+ bLeft = _getComputedStyle(doc[DOCUMENT_ELEMENT], BORDER_LEFT_WIDTH);
+ bTop = _getComputedStyle(doc[DOCUMENT_ELEMENT], BORDER_TOP_WIDTH);
+
+ if (UA.ie === 6) {
+ if (mode !== _BACK_COMPAT) {
+ off1 = 0;
+ off2 = 0;
+ }
+ }
+
+ if ((mode == _BACK_COMPAT)) {
+ if (bLeft !== MEDIUM) {
+ off1 = parseInt(bLeft, 10);
+ }
+ if (bTop !== MEDIUM) {
+ off2 = parseInt(bTop, 10);
+ }
+ }
+
+ xy[0] -= off1;
+ xy[1] -= off2;
+
+ }
+
+ if ((scrollTop || scrollLeft)) {
+ xy[0] += scrollLeft;
+ xy[1] += scrollTop;
+ }
+
+ // gecko may return sub-pixel (non-int) values
+ xy[0] = floor(xy[0]);
+ xy[1] = floor(xy[1]);
+ } else {
+ }
+
+ return xy;
+ };
+ } else {
+ return function(node) { // ff2, safari: manually calculate by crawling up offsetParents
+ var docScrollLeft, docScrollTop,
+ scrollTop, scrollLeft,
+ bCheck,
+ xy = false,
+ parentNode = node;
+
+ if (Y.Dom._canPosition(node) ) {
+ xy = [node[OFFSET_LEFT], node[OFFSET_TOP]];
+ docScrollLeft = Y.Dom.getDocumentScrollLeft(node[OWNER_DOCUMENT]);
+ docScrollTop = Y.Dom.getDocumentScrollTop(node[OWNER_DOCUMENT]);
+
+ // TODO: refactor with !! or just falsey
+ bCheck = ((isGecko || UA.webkit > 519) ? true : false);
+
+ // TODO: worth refactoring for TOP/LEFT only?
+ while ((parentNode = parentNode[OFFSET_PARENT])) {
+ xy[0] += parentNode[OFFSET_LEFT];
+ xy[1] += parentNode[OFFSET_TOP];
+ if (bCheck) {
+ xy = Y.Dom._calcBorders(parentNode, xy);
+ }
+ }
+
+ // account for any scrolled ancestors
+ if (Y.Dom._getStyle(node, POSITION) !== FIXED) {
+ parentNode = node;
+
+ while ((parentNode = parentNode[PARENT_NODE]) && parentNode[TAG_NAME]) {
+ scrollTop = parentNode[SCROLL_TOP];
+ scrollLeft = parentNode[SCROLL_LEFT];
+
+ //Firefox does something funky with borders when overflow is not visible.
+ if (isGecko && (Y.Dom._getStyle(parentNode, 'overflow') !== 'visible')) {
+ xy = Y.Dom._calcBorders(parentNode, xy);
+ }
+
+ if (scrollTop || scrollLeft) {
+ xy[0] -= scrollLeft;
+ xy[1] -= scrollTop;
+ }
+ }
+ xy[0] += docScrollLeft;
+ xy[1] += docScrollTop;
+
+ } else {
+ //Fix FIXED position -- add scrollbars
+ if (isOpera) {
+ xy[0] -= docScrollLeft;
+ xy[1] -= docScrollTop;
+ } else if (isSafari || isGecko) {
+ xy[0] += docScrollLeft;
+ xy[1] += docScrollTop;
+ }
+ }
+ //Round the numbers so we get sane data back
+ xy[0] = Math.floor(xy[0]);
+ xy[1] = Math.floor(xy[1]);
+ } else {
+ }
+ return xy;
+ };
+ }
+ }(), // NOTE: Executing for loadtime branching
/**
* 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).
@@ -260,46 +425,59 @@
* @param {Boolean} noRetry By default we try and set the position a second time if the first fails
*/
setXY: function(el, pos, noRetry) {
- var f = function(el) {
- var style_pos = this.getStyle(el, 'position');
- if (style_pos == 'static') { // default to relative
- this.setStyle(el, 'position', 'relative');
- style_pos = 'relative';
- }
+ Y.Dom.batch(el, Y.Dom._setXY, { pos: pos, noRetry: noRetry });
+ },
- var pageXY = this.getXY(el);
- if (pageXY === false) { // has to be part of doc to have pageXY
- return false;
- }
-
- var delta = [ // assuming pixels; if not we will have to retry
- parseInt( this.getStyle(el, 'left'), 10 ),
- parseInt( this.getStyle(el, 'top'), 10 )
- ];
-
- if ( isNaN(delta[0]) ) {// in case of 'auto'
- delta[0] = (style_pos == 'relative') ? 0 : el.offsetLeft;
- }
- if ( isNaN(delta[1]) ) { // in case of 'auto'
- delta[1] = (style_pos == 'relative') ? 0 : el.offsetTop;
- }
-
- if (pos[0] !== null) { el.style.left = pos[0] - pageXY[0] + delta[0] + 'px'; }
- if (pos[1] !== null) { el.style.top = pos[1] - pageXY[1] + delta[1] + 'px'; }
-
- if (!noRetry) {
- var newXY = this.getXY(el);
-
- // if retry is true, try one more time if we miss
- if ( (pos[0] !== null && newXY[0] != pos[0]) ||
- (pos[1] !== null && newXY[1] != pos[1]) ) {
- this.setXY(el, pos, true);
- }
- }
+ _setXY: function(node, args) {
+ var pos = Y.Dom._getStyle(node, POSITION),
+ setStyle = Y.Dom.setStyle,
+ xy = args.pos,
+ noRetry = args.noRetry,
+
+ delta = [ // assuming pixels; if not we will have to retry
+ parseInt( Y.Dom.getComputedStyle(node, LEFT), 10 ),
+ parseInt( Y.Dom.getComputedStyle(node, TOP), 10 )
+ ],
+
+ currentXY,
+ newXY;
- };
+ if (pos == 'static') { // default to relative
+ pos = RELATIVE;
+ setStyle(node, POSITION, pos);
+ }
+
+ currentXY = Y.Dom._getXY(node);
+
+ if (!xy || currentXY === false) { // has to be part of doc to have xy
+ return false;
+ }
- Y.Dom.batch(el, f, Y.Dom, true);
+ if ( isNaN(delta[0]) ) {// in case of 'auto'
+ delta[0] = (pos == RELATIVE) ? 0 : node[OFFSET_LEFT];
+ }
+ if ( isNaN(delta[1]) ) { // in case of 'auto'
+ delta[1] = (pos == RELATIVE) ? 0 : node[OFFSET_TOP];
+ }
+
+ if (xy[0] !== null) { // from setX
+ setStyle(node, LEFT, xy[0] - currentXY[0] + delta[0] + 'px');
+ }
+
+ if (xy[1] !== null) { // from setY
+ setStyle(node, TOP, xy[1] - currentXY[1] + delta[1] + 'px');
+ }
+
+ if (!noRetry) {
+ newXY = Y.Dom._getXY(node);
+
+ // if retry is true, try one more time if we miss
+ if ( (xy[0] !== null && newXY[0] != xy[0]) ||
+ (xy[1] !== null && newXY[1] != xy[1]) ) {
+ Y.Dom._setXY(node, { pos: xy, noRetry: true });
+ }
+ }
+
},
/**
@@ -333,12 +511,12 @@
*/
getRegion: function(el) {
var f = function(el) {
- if ( (el.parentNode === null || el.offsetParent === null ||
- this.getStyle(el, 'display') == 'none') && el != document.body) {
- return false;
+ var region = false;
+ if ( Y.Dom._canPosition(el) ) {
+ region = Y.Region.getRegion(el);
+ } else {
}
- var region = Y.Region.getRegion(el);
return region;
};
@@ -368,14 +546,21 @@
/**
* Returns a array of HTMLElements with the given class.
* For optimized performance, include a tag and/or root node when possible.
+ * Note: This method operates against a live collection, so modifying the
+ * collection in the callback (removing/appending nodes, etc.) will have
+ * side effects. Instead you should iterate the returned nodes array,
+ * as you would with the native "getElementsByTagName" method.
* @method getElementsByClassName
* @param {String} className The class name to match against
* @param {String} tag (optional) The tag name of the elements being collected
* @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point
* @param {Function} apply (optional) A function to apply to each element when found
+ * @param {Any} o (optional) An optional arg that is passed to the supplied method
+ * @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o"
* @return {Array} An array of elements that have the given class name
*/
- getElementsByClassName: function(className, tag, root, apply) {
+ getElementsByClassName: function(className, tag, root, apply, o, overrides) {
+ className = lang.trim(className);
tag = tag || '*';
root = (root) ? Y.Dom.get(root) : null || document;
if (!root) {
@@ -384,17 +569,18 @@
var nodes = [],
elements = root.getElementsByTagName(tag),
- re = getClassRegEx(className);
+ hasClass = Y.Dom.hasClass;
for (var i = 0, len = elements.length; i < len; ++i) {
- if ( re.test(elements[i].className) ) {
+ if ( hasClass(elements[i], className) ) {
nodes[nodes.length] = elements[i];
- if (apply) {
- apply.call(elements[i], elements[i]);
- }
}
}
+ if (apply) {
+ Y.Dom.batch(nodes, apply, o, overrides);
+ }
+
return nodes;
},
@@ -406,13 +592,25 @@
* @return {Boolean | Array} A boolean value or array of boolean values
*/
hasClass: function(el, className) {
- var re = getClassRegEx(className);
+ return Y.Dom.batch(el, Y.Dom._hasClass, className);
+ },
- var f = function(el) {
- return re.test(el.className);
- };
-
- return Y.Dom.batch(el, f, Y.Dom, true);
+ _hasClass: function(el, className) {
+ var ret = false,
+ current;
+
+ if (el && className) {
+ current = Y.Dom.getAttribute(el, CLASS_NAME) || EMPTY;
+ if (className.exec) {
+ ret = className.test(current);
+ } else {
+ ret = className && (SPACE + current + SPACE).
+ indexOf(SPACE + className + SPACE) > -1;
+ }
+ } else {
+ }
+
+ return ret;
},
/**
@@ -423,17 +621,23 @@
* @return {Boolean | Array} A pass/fail boolean or array of booleans
*/
addClass: function(el, className) {
- var f = function(el) {
- if (this.hasClass(el, className)) {
- return false; // already present
+ return Y.Dom.batch(el, Y.Dom._addClass, className);
+ },
+
+ _addClass: function(el, className) {
+ var ret = false,
+ current;
+
+ if (el && className) {
+ current = Y.Dom.getAttribute(el, CLASS_NAME) || EMPTY;
+ if ( !Y.Dom._hasClass(el, className) ) {
+ Y.Dom.setAttribute(el, CLASS_NAME, trim(current + SPACE + className));
+ ret = true;
}
-
-
- el.className = YAHOO.lang.trim([el.className, className].join(' '));
- return true;
- };
-
- return Y.Dom.batch(el, f, Y.Dom, true);
+ } else {
+ }
+
+ return ret;
},
/**
@@ -444,25 +648,34 @@
* @return {Boolean | Array} A pass/fail boolean or array of booleans
*/
removeClass: function(el, className) {
- var re = getClassRegEx(className);
-
- var f = function(el) {
- if (!this.hasClass(el, className)) {
- return false; // not present
- }
-
-
- var c = el.className;
- el.className = c.replace(re, ' ');
- if ( this.hasClass(el, className) ) { // in case of multiple adjacent
- this.removeClass(el, className);
+ return Y.Dom.batch(el, Y.Dom._removeClass, className);
+ },
+
+ _removeClass: function(el, className) {
+ var ret = false,
+ current,
+ newClass,
+ attr;
+
+ if (el && className) {
+ current = Y.Dom.getAttribute(el, CLASS_NAME) || EMPTY;
+ Y.Dom.setAttribute(el, CLASS_NAME, current.replace(Y.Dom._getClassRegex(className), EMPTY));
+
+ newClass = Y.Dom.getAttribute(el, CLASS_NAME);
+ if (current !== newClass) { // else nothing changed
+ Y.Dom.setAttribute(el, CLASS_NAME, trim(newClass)); // trim after comparing to current class
+ ret = true;
+
+ if (Y.Dom.getAttribute(el, CLASS_NAME) === '') { // remove class attribute if empty
+ attr = (el.hasAttribute && el.hasAttribute(_CLASS)) ? _CLASS : CLASS_NAME;
+ el.removeAttribute(attr);
+ }
}
- el.className = YAHOO.lang.trim(el.className); // remove any trailing spaces
- return true;
- };
-
- return Y.Dom.batch(el, f, Y.Dom, true);
+ } else {
+ }
+
+ return ret;
},
/**
@@ -475,30 +688,39 @@
* @return {Boolean | Array} A pass/fail boolean or array of booleans
*/
replaceClass: function(el, oldClassName, newClassName) {
- if (!newClassName || oldClassName === newClassName) { // avoid infinite loop
- return false;
- }
-
- var re = getClassRegEx(oldClassName);
-
- var f = function(el) {
-
- if ( !this.hasClass(el, oldClassName) ) {
- this.addClass(el, newClassName); // just add it if nothing to replace
- return true; // NOTE: return
- }
-
- el.className = el.className.replace(re, ' ' + newClassName + ' ');
+ return Y.Dom.batch(el, Y.Dom._replaceClass, { from: oldClassName, to: newClassName });
+ },
- if ( this.hasClass(el, oldClassName) ) { // in case of multiple adjacent
- this.replaceClass(el, oldClassName, newClassName);
+ _replaceClass: function(el, classObj) {
+ var className,
+ from,
+ to,
+ ret = false,
+ current;
+
+ if (el && classObj) {
+ from = classObj.from;
+ to = classObj.to;
+
+ if (!to) {
+ ret = false;
+ } else if (!from) { // just add if no "from"
+ ret = Y.Dom._addClass(el, classObj.to);
+ } else if (from !== to) { // else nothing to replace
+ // May need to lead with DBLSPACE?
+ current = Y.Dom.getAttribute(el, CLASS_NAME) || EMPTY;
+ className = (SPACE + current.replace(Y.Dom._getClassRegex(from), SPACE + to)).
+ split(Y.Dom._getClassRegex(to));
+
+ // insert to into what would have been the first occurrence slot
+ className.splice(1, 0, SPACE + to);
+ Y.Dom.setAttribute(el, CLASS_NAME, trim(className.join(EMPTY)));
+ ret = true;
}
+ } else {
+ }
- el.className = YAHOO.lang.trim(el.className); // remove any trailing spaces
- return true;
- };
-
- return Y.Dom.batch(el, f, Y.Dom, true);
+ return ret;
},
/**
@@ -514,11 +736,15 @@
var f = function(el) {
if (el && el.id) { // do not override existing ID
return el.id;
- }
+ }
- var id = prefix + id_counter++;
+ var id = prefix + YAHOO.env._id_counter++;
if (el) {
+ if (el[OWNER_DOCUMENT].getElementById(id)) { // in case one already exists
+ // use failed id plus prefix to help ensure uniqueness
+ return Y.Dom.generateId(el, id + prefix);
+ }
el.id = id;
}
@@ -540,45 +766,58 @@
haystack = Y.Dom.get(haystack);
needle = Y.Dom.get(needle);
- if (!haystack || !needle) {
- return false;
- }
+ var ret = false;
- if (haystack.contains && needle.nodeType && !isSafari) { // safari contains is broken
- return haystack.contains(needle);
- }
- else if ( haystack.compareDocumentPosition && needle.nodeType ) {
- return !!(haystack.compareDocumentPosition(needle) & 16);
- } else if (needle.nodeType) {
- // fallback to crawling up (safari)
- return !!this.getAncestorBy(needle, function(el) {
- return el == haystack;
- });
+ if ( (haystack && needle) && (haystack[NODE_TYPE] && needle[NODE_TYPE]) ) {
+ if (haystack.contains && haystack !== needle) { // contains returns true when equal
+ ret = haystack.contains(needle);
+ }
+ else if (haystack.compareDocumentPosition) { // gecko
+ ret = !!(haystack.compareDocumentPosition(needle) & 16);
+ }
+ } else {
}
- return false;
+ return ret;
},
/**
* Determines whether an HTMLElement is present in the current document.
* @method inDocument
* @param {String | HTMLElement} el The element to search for
+ * @param {Object} doc An optional document to search, defaults to element's owner document
* @return {Boolean} Whether or not the element is present in the current document
*/
- inDocument: function(el) {
- return this.isAncestor(document.documentElement, el);
+ inDocument: function(el, doc) {
+ return Y.Dom._inDoc(Y.Dom.get(el), doc);
+ },
+
+ _inDoc: function(el, doc) {
+ var ret = false;
+ if (el && el[TAG_NAME]) {
+ doc = doc || el[OWNER_DOCUMENT];
+ ret = Y.Dom.isAncestor(doc[DOCUMENT_ELEMENT], el);
+ } else {
+ }
+ return ret;
},
/**
* Returns a array of HTMLElements that pass the test applied by supplied boolean method.
* For optimized performance, include a tag and/or root node when possible.
+ * Note: This method operates against a live collection, so modifying the
+ * collection in the callback (removing/appending nodes, etc.) will have
+ * side effects. Instead you should iterate the returned nodes array,
+ * as you would with the native "getElementsByTagName" method.
* @method getElementsBy
* @param {Function} method - A boolean method for testing elements which receives the element as its only argument.
* @param {String} tag (optional) The tag name of the elements being collected
* @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point
* @param {Function} apply (optional) A function to apply to each element when found
+ * @param {Any} o (optional) An optional arg that is passed to the supplied method
+ * @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o"
* @return {Array} Array of HTMLElements
*/
- getElementsBy: function(method, tag, root, apply) {
+ getElementsBy: function(method, tag, root, apply, o, overrides, firstOnly) {
tag = tag || '*';
root = (root) ? Y.Dom.get(root) : null || document;
@@ -591,45 +830,61 @@
for (var i = 0, len = elements.length; i < len; ++i) {
if ( method(elements[i]) ) {
- nodes[nodes.length] = elements[i];
- if (apply) {
- apply(elements[i]);
+ if (firstOnly) {
+ nodes = elements[i];
+ break;
+ } else {
+ nodes[nodes.length] = elements[i];
}
}
}
+ if (apply) {
+ Y.Dom.batch(nodes, apply, o, overrides);
+ }
+
return nodes;
},
/**
+ * Returns the first HTMLElement that passes the test applied by the supplied boolean method.
+ * @method getElementBy
+ * @param {Function} method - A boolean method for testing elements which receives the element as its only argument.
+ * @param {String} tag (optional) The tag name of the elements being collected
+ * @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point
+ * @return {HTMLElement}
+ */
+ getElementBy: function(method, tag, root) {
+ return Y.Dom.getElementsBy(method, tag, root, null, null, null, true);
+ },
+
+ /**
* Runs the supplied method against each item in the Collection/Array.
* The method is called with the element(s) as the first arg, and the optional param as the second ( method(el, o) ).
* @method batch
* @param {String | HTMLElement | Array} el (optional) An element or array of elements to apply the method to
* @param {Function} method The method to apply to the element(s)
* @param {Any} o (optional) An optional arg that is passed to the supplied method
- * @param {Boolean} override (optional) Whether or not to override the scope of "method" with "o"
+ * @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o"
* @return {Any | Array} The return value(s) from the supplied method
*/
- batch: function(el, method, o, override) {
- el = (el && (el.tagName || el.item)) ? el : Y.Dom.get(el); // skip get() when possible
+ batch: function(el, method, o, overrides) {
+ var collection = [],
+ scope = (overrides) ? o : window;
+
+ el = (el && (el[TAG_NAME] || el.item)) ? el : Y.Dom.get(el); // skip get() when possible
+ if (el && method) {
+ if (el[TAG_NAME] || el.length === undefined) { // element or not array-like
+ return method.call(scope, el, o);
+ }
- if (!el || !method) {
+ for (var i = 0; i < el.length; ++i) {
+ collection[collection.length] = method.call(scope, el[i], o);
+ }
+ } else {
return false;
}
- var scope = (override) ? o : window;
-
- if (el.tagName || el.length === undefined) { // element or not array-like
- return method.call(scope, el, o);
- }
-
- var collection = [];
-
- for (var i = 0, len = el.length; i < len; ++i) {
- collection[collection.length] = method.call(scope, el[i], o);
- }
-
return collection;
},
@@ -639,9 +894,9 @@
* @return {Int} The height of the actual document (which includes the body and its margin).
*/
getDocumentHeight: function() {
- var scrollHeight = (document.compatMode != 'CSS1Compat') ? document.body.scrollHeight : document.documentElement.scrollHeight;
+ var scrollHeight = (document[COMPAT_MODE] != CSS1_COMPAT || isSafari) ? document.body.scrollHeight : documentElement.scrollHeight,
+ h = Math.max(scrollHeight, Y.Dom.getViewportHeight());
- var h = Math.max(scrollHeight, Y.Dom.getViewportHeight());
return h;
},
@@ -651,8 +906,8 @@
* @return {Int} The width of the actual document (which includes the body and its margin).
*/
getDocumentWidth: function() {
- var scrollWidth = (document.compatMode != 'CSS1Compat') ? document.body.scrollWidth : document.documentElement.scrollWidth;
- var w = Math.max(scrollWidth, Y.Dom.getViewportWidth());
+ var scrollWidth = (document[COMPAT_MODE] != CSS1_COMPAT || isSafari) ? document.body.scrollWidth : documentElement.scrollWidth,
+ w = Math.max(scrollWidth, Y.Dom.getViewportWidth());
return w;
},
@@ -662,12 +917,12 @@
* @return {Int} The height of the viewable area of the page (excludes scrollbars).
*/
getViewportHeight: function() {
- var height = self.innerHeight; // Safari, Opera
- var mode = document.compatMode;
+ var height = self.innerHeight, // Safari, Opera
+ mode = document[COMPAT_MODE];
if ( (mode || isIE) && !isOpera ) { // IE, Gecko
- height = (mode == 'CSS1Compat') ?
- document.documentElement.clientHeight : // Standards
+ height = (mode == CSS1_COMPAT) ?
+ documentElement.clientHeight : // Standards
document.body.clientHeight; // Quirks
}
@@ -681,12 +936,12 @@
*/
getViewportWidth: function() {
- var width = self.innerWidth; // Safari
- var mode = document.compatMode;
+ var width = self.innerWidth, // Safari
+ mode = document[COMPAT_MODE];
if (mode || isIE) { // IE, Gecko, Opera
- width = (mode == 'CSS1Compat') ?
- document.documentElement.clientWidth : // Standards
+ width = (mode == CSS1_COMPAT) ?
+ documentElement.clientWidth : // Standards
document.body.clientWidth; // Quirks
}
return width;
@@ -701,8 +956,8 @@
* @return {Object} HTMLElement or null if not found
*/
getAncestorBy: function(node, method) {
- while (node = node.parentNode) { // NOTE: assignment
- if ( testElement(node, method) ) {
+ while ( (node = node[PARENT_NODE]) ) { // NOTE: assignment
+ if ( Y.Dom._testElement(node, method) ) {
return node;
}
}
@@ -739,7 +994,7 @@
return null;
}
var method = function(el) {
- return el.tagName && el.tagName.toUpperCase() == tagName.toUpperCase();
+ return el[TAG_NAME] && el[TAG_NAME].toUpperCase() == tagName.toUpperCase();
};
return Y.Dom.getAncestorBy(node, method);
@@ -758,7 +1013,7 @@
getPreviousSiblingBy: function(node, method) {
while (node) {
node = node.previousSibling;
- if ( testElement(node, method) ) {
+ if ( Y.Dom._testElement(node, method) ) {
return node;
}
}
@@ -793,7 +1048,7 @@
getNextSiblingBy: function(node, method) {
while (node) {
node = node.nextSibling;
- if ( testElement(node, method) ) {
+ if ( Y.Dom._testElement(node, method) ) {
return node;
}
}
@@ -824,7 +1079,7 @@
* @return {Object} HTMLElement or null if not found
*/
getFirstChildBy: function(node, method) {
- var child = ( testElement(node.firstChild, method) ) ? node.firstChild : null;
+ var child = ( Y.Dom._testElement(node.firstChild, method) ) ? node.firstChild : null;
return child || Y.Dom.getNextSiblingBy(node.firstChild, method);
},
@@ -854,7 +1109,7 @@
if (!node) {
return null;
}
- var child = ( testElement(node.lastChild, method) ) ? node.lastChild : null;
+ var child = ( Y.Dom._testElement(node.lastChild, method) ) ? node.lastChild : null;
return child || Y.Dom.getPreviousSiblingBy(node.lastChild, method);
},
@@ -878,8 +1133,8 @@
* @return {Array} A static array of HTMLElements
*/
getChildrenBy: function(node, method) {
- var child = Y.Dom.getFirstChildBy(node, method);
- var children = child ? [child] : [];
+ var child = Y.Dom.getFirstChildBy(node, method),
+ children = child ? [child] : [];
Y.Dom.getNextSiblingBy(child, function(node) {
if ( !method || method(node) ) {
@@ -904,7 +1159,7 @@
return Y.Dom.getChildrenBy(node);
},
-
+
/**
* Returns the left scroll value of the document
* @method getDocumentScrollLeft
@@ -913,7 +1168,7 @@
*/
getDocumentScrollLeft: function(doc) {
doc = doc || document;
- return Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft);
+ return Math.max(doc[DOCUMENT_ELEMENT].scrollLeft, doc.body.scrollLeft);
},
/**
@@ -924,7 +1179,7 @@
*/
getDocumentScrollTop: function(doc) {
doc = doc || document;
- return Math.max(doc.documentElement.scrollTop, doc.body.scrollTop);
+ return Math.max(doc[DOCUMENT_ELEMENT].scrollTop, doc.body.scrollTop);
},
/**
@@ -938,11 +1193,11 @@
newNode = Y.Dom.get(newNode);
referenceNode = Y.Dom.get(referenceNode);
- if (!newNode || !referenceNode || !referenceNode.parentNode) {
+ if (!newNode || !referenceNode || !referenceNode[PARENT_NODE]) {
return null;
}
- return referenceNode.parentNode.insertBefore(newNode, referenceNode);
+ return referenceNode[PARENT_NODE].insertBefore(newNode, referenceNode);
},
/**
@@ -956,14 +1211,14 @@
newNode = Y.Dom.get(newNode);
referenceNode = Y.Dom.get(referenceNode);
- if (!newNode || !referenceNode || !referenceNode.parentNode) {
+ if (!newNode || !referenceNode || !referenceNode[PARENT_NODE]) {
return null;
}
if (referenceNode.nextSibling) {
- return referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
+ return referenceNode[PARENT_NODE].insertBefore(newNode, referenceNode.nextSibling);
} else {
- return referenceNode.parentNode.appendChild(newNode);
+ return referenceNode[PARENT_NODE].appendChild(newNode);
}
},
@@ -979,62 +1234,114 @@
b = Y.Dom.getViewportHeight() + t;
return new Y.Region(t, r, b, l);
- }
- };
-
- var getXY = function() {
- if (document.documentElement.getBoundingClientRect) { // IE
- return function(el) {
- var box = el.getBoundingClientRect();
-
- var rootNode = el.ownerDocument;
- return [box.left + Y.Dom.getDocumentScrollLeft(rootNode), box.top +
- Y.Dom.getDocumentScrollTop(rootNode)];
- };
- } else {
- return function(el) { // manually calculate by crawling up offsetParents
- var pos = [el.offsetLeft, el.offsetTop];
- var parentNode = el.offsetParent;
-
- // safari: subtract body offsets if el is abs (or any offsetParent), unless body is offsetParent
- var accountForBody = (isSafari &&
- Y.Dom.getStyle(el, 'position') == 'absolute' &&
- el.offsetParent == el.ownerDocument.body);
-
- if (parentNode != el) {
- while (parentNode) {
- pos[0] += parentNode.offsetLeft;
- pos[1] += parentNode.offsetTop;
- if (!accountForBody && isSafari &&
- Y.Dom.getStyle(parentNode,'position') == 'absolute' ) {
- accountForBody = true;
- }
- parentNode = parentNode.offsetParent;
- }
- }
+ },
- if (accountForBody) { //safari doubles in this case
- pos[0] -= el.ownerDocument.body.offsetLeft;
- pos[1] -= el.ownerDocument.body.offsetTop;
- }
- parentNode = el.parentNode;
+ /**
+ * Provides a normalized attribute interface.
+ * @method setAttibute
+ * @param {String | HTMLElement} el The target element for the attribute.
+ * @param {String} attr The attribute to set.
+ * @param {String} val The value of the attribute.
+ */
+ setAttribute: function(el, attr, val) {
+ attr = Y.Dom.CUSTOM_ATTRIBUTES[attr] || attr;
+ el.setAttribute(attr, val);
+ },
- // account for any scrolled ancestors
- while ( parentNode.tagName && !patterns.ROOT_TAG.test(parentNode.tagName) )
- {
- // work around opera inline/table scrollLeft/Top bug
- if (Y.Dom.getStyle(parentNode, 'display').search(/^inline|table-row.*$/i)) {
- pos[0] -= parentNode.scrollLeft;
- pos[1] -= parentNode.scrollTop;
+
+ /**
+ * Provides a normalized attribute interface.
+ * @method getAttibute
+ * @param {String | HTMLElement} el The target element for the attribute.
+ * @param {String} attr The attribute to get.
+ * @return {String} The current value of the attribute.
+ */
+ getAttribute: function(el, attr) {
+ attr = Y.Dom.CUSTOM_ATTRIBUTES[attr] || attr;
+ return el.getAttribute(attr);
+ },
+
+ _toCamel: function(property) {
+ var c = propertyCache;
+
+ function tU(x,l) {
+ return l.toUpperCase();
+ }
+
+ return c[property] || (c[property] = property.indexOf('-') === -1 ?
+ property :
+ property.replace( /-([a-z])/gi, tU ));
+ },
+
+ _getClassRegex: function(className) {
+ var re;
+ if (className !== undefined) { // allow empty string to pass
+ if (className.exec) { // already a RegExp
+ re = className;
+ } else {
+ re = reCache[className];
+ if (!re) {
+ // escape special chars (".", "[", etc.)
+ className = className.replace(Y.Dom._patterns.CLASS_RE_TOKENS, '\\$1');
+ re = reCache[className] = new RegExp(C_START + className + C_END, G);
}
-
- parentNode = parentNode.parentNode;
}
+ }
+ return re;
+ },
- return pos;
- };
+ _patterns: {
+ ROOT_TAG: /^body|html$/i, // body for quirks mode, html for standards,
+ CLASS_RE_TOKENS: /([\.\(\)\^\$\*\+\?\|\[\]\{\}])/g
+ },
+
+
+ _testElement: function(node, method) {
+ return node && node[NODE_TYPE] == 1 && ( !method || method(node) );
+ },
+
+ _calcBorders: function(node, xy2) {
+ var t = parseInt(Y.Dom[GET_COMPUTED_STYLE](node, BORDER_TOP_WIDTH), 10) || 0,
+ l = parseInt(Y.Dom[GET_COMPUTED_STYLE](node, BORDER_LEFT_WIDTH), 10) || 0;
+ if (isGecko) {
+ if (RE_TABLE.test(node[TAG_NAME])) {
+ t = 0;
+ l = 0;
+ }
+ }
+ xy2[0] += l;
+ xy2[1] += t;
+ return xy2;
}
- }() // NOTE: Executing for loadtime branching
+ };
+
+ var _getComputedStyle = Y.Dom[GET_COMPUTED_STYLE];
+ // fix opera computedStyle default color unit (convert to rgb)
+ if (UA.opera) {
+ Y.Dom[GET_COMPUTED_STYLE] = function(node, att) {
+ var val = _getComputedStyle(node, att);
+ if (RE_COLOR.test(att)) {
+ val = Y.Dom.Color.toRGB(val);
+ }
+
+ return val;
+ };
+
+ }
+
+ // safari converts transparent to rgba(), others use "transparent"
+ if (UA.webkit) {
+ Y.Dom[GET_COMPUTED_STYLE] = function(node, att) {
+ var val = _getComputedStyle(node, att);
+
+ if (val === 'rgba(0, 0, 0, 0)') {
+ val = 'transparent';
+ }
+
+ return val;
+ };
+
+ }
})();
/**
* A region is a representation of an object on a grid. It is defined
@@ -1058,6 +1365,13 @@
this.top = t;
/**
+ * The region's top extent
+ * @property y
+ * @type Int
+ */
+ this.y = t;
+
+ /**
* The region's top extent as index, for symmetry with set/getXY
* @property 1
* @type Int
@@ -1086,11 +1400,32 @@
this.left = l;
/**
+ * The region's left extent
+ * @property x
+ * @type Int
+ */
+ this.x = l;
+
+ /**
* The region's left extent as index, for symmetry with set/getXY
* @property 0
* @type Int
*/
this[0] = l;
+
+ /**
+ * The region's total width
+ * @property width
+ * @type Int
+ */
+ this.width = this.right - this.left;
+
+ /**
+ * The region's total height
+ * @property height
+ * @type Int
+ */
+ this.height = this.bottom - this.top;
};
/**
@@ -1124,10 +1459,10 @@
* @return {Region} The overlap region, or null if there is no overlap
*/
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 );
+ var t = Math.max( this.top, region.top ),
+ r = Math.min( this.right, region.right ),
+ b = Math.min( this.bottom, region.bottom ),
+ l = Math.max( this.left, region.left );
if (b >= t && r >= l) {
return new YAHOO.util.Region(t, r, b, l);
@@ -1144,10 +1479,10 @@
* @return {Region} The union region
*/
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 );
+ var t = Math.min( this.top, region.top ),
+ r = Math.max( this.right, region.right ),
+ b = Math.max( this.bottom, region.bottom ),
+ l = Math.min( this.left, region.left );
return new YAHOO.util.Region(t, r, b, l);
};
@@ -1163,6 +1498,8 @@
", right: " + this.right +
", bottom: " + this.bottom +
", left: " + this.left +
+ ", height: " + this.height +
+ ", width: " + this.width +
"}" );
};
@@ -1174,12 +1511,11 @@
* @static
*/
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];
+ var p = YAHOO.util.Dom.getXY(el),
+ t = p[1],
+ r = p[0] + el.offsetWidth,
+ b = p[1] + el.offsetHeight,
+ l = p[0];
return new YAHOO.util.Region(t, r, b, l);
};
@@ -1202,23 +1538,262 @@
y = x[1]; // dont blow away x yet
x = x[0];
}
-
- /**
- * The X position of the point, which is also the right, left and index zero (for Dom.getXY symmetry)
- * @property x
- * @type Int
- */
-
- this.x = this.right = this.left = this[0] = x;
-
- /**
- * The Y position of the point, which is also the top, bottom and index one (for Dom.getXY symmetry)
- * @property y
- * @type Int
- */
- this.y = this.top = this.bottom = this[1] = y;
+
+ YAHOO.util.Point.superclass.constructor.call(this, y, x, y, x);
};
-YAHOO.util.Point.prototype = new YAHOO.util.Region();
+YAHOO.extend(YAHOO.util.Point, YAHOO.util.Region);
+
+(function() {
+/**
+ * Add style management functionality to DOM.
+ * @module dom
+ * @for Dom
+ */
+
+var Y = YAHOO.util,
+ CLIENT_TOP = 'clientTop',
+ CLIENT_LEFT = 'clientLeft',
+ PARENT_NODE = 'parentNode',
+ RIGHT = 'right',
+ HAS_LAYOUT = 'hasLayout',
+ PX = 'px',
+ OPACITY = 'opacity',
+ AUTO = 'auto',
+ BORDER_LEFT_WIDTH = 'borderLeftWidth',
+ BORDER_TOP_WIDTH = 'borderTopWidth',
+ BORDER_RIGHT_WIDTH = 'borderRightWidth',
+ BORDER_BOTTOM_WIDTH = 'borderBottomWidth',
+ VISIBLE = 'visible',
+ TRANSPARENT = 'transparent',
+ HEIGHT = 'height',
+ WIDTH = 'width',
+ STYLE = 'style',
+ CURRENT_STYLE = 'currentStyle',
+
+// IE getComputedStyle
+// TODO: unit-less lineHeight (e.g. 1.22)
+ re_size = /^width|height$/,
+ 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,
+
+ ComputedStyle = {
+ get: function(el, property) {
+ var value = '',
+ current = el[CURRENT_STYLE][property];
+
+ if (property === OPACITY) {
+ value = Y.Dom.getStyle(el, OPACITY);
+ } else if (!current || (current.indexOf && current.indexOf(PX) > -1)) { // no need to convert
+ value = current;
+ } else if (Y.Dom.IE_COMPUTED[property]) { // use compute function
+ value = Y.Dom.IE_COMPUTED[property](el, property);
+ } else if (re_unit.test(current)) { // convert to pixel
+ value = Y.Dom.IE.ComputedStyle.getPixel(el, property);
+ } else {
+ value = current;
+ }
+
+ return value;
+ },
+
+ getOffset: function(el, prop) {
+ var current = el[CURRENT_STYLE][prop], // value of "width", "top", etc.
+ capped = prop.charAt(0).toUpperCase() + prop.substr(1), // "Width", "Top", etc.
+ offset = 'offset' + capped, // "offsetWidth", "offsetTop", etc.
+ pixel = 'pixel' + capped, // "pixelWidth", "pixelTop", etc.
+ value = '',
+ actual;
+
+ if (current == AUTO) {
+ actual = el[offset]; // offsetHeight/Top etc.
+ if (actual === undefined) { // likely "right" or "bottom"
+ value = 0;
+ }
+
+ value = actual;
+ if (re_size.test(prop)) { // account for box model diff
+ el[STYLE][prop] = actual;
+ if (el[offset] > actual) {
+ // the difference is padding + border (works in Standards & Quirks modes)
+ value = actual - (el[offset] - actual);
+ }
+ el[STYLE][prop] = AUTO; // revert to auto
+ }
+ } else { // convert units to px
+ if (!el[STYLE][pixel] && !el[STYLE][prop]) { // need to map style.width to currentStyle (no currentStyle.pixelWidth)
+ el[STYLE][prop] = current; // no style.pixelWidth if no style.width
+ }
+ value = el[STYLE][pixel];
+ }
+ return value + PX;
+ },
+
+ getBorderWidth: function(el, property) {
+ // clientHeight/Width = paddingBox (e.g. offsetWidth - borderWidth)
+ // clientTop/Left = borderWidth
+ var value = null;
+ if (!el[CURRENT_STYLE][HAS_LAYOUT]) { // TODO: unset layout?
+ el[STYLE].zoom = 1; // need layout to measure client
+ }
+
+ switch(property) {
+ case BORDER_TOP_WIDTH:
+ value = el[CLIENT_TOP];
+ break;
+ case BORDER_BOTTOM_WIDTH:
+ value = el.offsetHeight - el.clientHeight - el[CLIENT_TOP];
+ break;
+ case BORDER_LEFT_WIDTH:
+ value = el[CLIENT_LEFT];
+ break;
+ case BORDER_RIGHT_WIDTH:
+ value = el.offsetWidth - el.clientWidth - el[CLIENT_LEFT];
+ break;
+ }
+ return value + PX;
+ },
+
+ getPixel: function(node, att) {
+ // use pixelRight to convert to px
+ var val = null,
+ styleRight = node[CURRENT_STYLE][RIGHT],
+ current = node[CURRENT_STYLE][att];
+
+ node[STYLE][RIGHT] = current;
+ val = node[STYLE].pixelRight;
+ node[STYLE][RIGHT] = styleRight; // revert
+
+ return val + PX;
+ },
+
+ getMargin: function(node, att) {
+ var val;
+ if (node[CURRENT_STYLE][att] == AUTO) {
+ val = 0 + PX;
+ } else {
+ val = Y.Dom.IE.ComputedStyle.getPixel(node, att);
+ }
+ return val;
+ },
+
+ getVisibility: function(node, att) {
+ var current;
+ while ( (current = node[CURRENT_STYLE]) && current[att] == 'inherit') { // NOTE: assignment in test
+ node = node[PARENT_NODE];
+ }
+ return (current) ? current[att] : VISIBLE;
+ },
+
+ getColor: function(node, att) {
+ return Y.Dom.Color.toRGB(node[CURRENT_STYLE][att]) || TRANSPARENT;
+ },
+
+ getBorderColor: function(node, att) {
+ var current = node[CURRENT_STYLE],
+ val = current[att] || current.color;
+ return Y.Dom.Color.toRGB(Y.Dom.Color.toHex(val));
+ }
+
+ },
+
+//fontSize: getPixelFont,
+ IEComputed = {};
+
+IEComputed.top = IEComputed.right = IEComputed.bottom = IEComputed.left =
+ IEComputed[WIDTH] = IEComputed[HEIGHT] = ComputedStyle.getOffset;
-YAHOO.register("dom", YAHOO.util.Dom, {version: "2.4.1", build: "742"});
+IEComputed.color = ComputedStyle.getColor;
+
+IEComputed[BORDER_TOP_WIDTH] = IEComputed[BORDER_RIGHT_WIDTH] =
+ IEComputed[BORDER_BOTTOM_WIDTH] = IEComputed[BORDER_LEFT_WIDTH] =
+ ComputedStyle.getBorderWidth;
+
+IEComputed.marginTop = IEComputed.marginRight = IEComputed.marginBottom =
+ IEComputed.marginLeft = ComputedStyle.getMargin;
+
+IEComputed.visibility = ComputedStyle.getVisibility;
+IEComputed.borderColor = IEComputed.borderTopColor =
+ IEComputed.borderRightColor = IEComputed.borderBottomColor =
+ IEComputed.borderLeftColor = ComputedStyle.getBorderColor;
+
+Y.Dom.IE_COMPUTED = IEComputed;
+Y.Dom.IE_ComputedStyle = ComputedStyle;
+})();
+(function() {
+/**
+ * Add style management functionality to DOM.
+ * @module dom
+ * @for Dom
+ */
+
+var TO_STRING = 'toString',
+ PARSE_INT = parseInt,
+ RE = RegExp,
+ Y = YAHOO.util;
+
+Y.Dom.Color = {
+ KEYWORDS: {
+ black: '000',
+ silver: 'c0c0c0',
+ gray: '808080',
+ white: 'fff',
+ maroon: '800000',
+ red: 'f00',
+ purple: '800080',
+ fuchsia: 'f0f',
+ green: '008000',
+ lime: '0f0',
+ olive: '808000',
+ yellow: 'ff0',
+ navy: '000080',
+ blue: '00f',
+ teal: '008080',
+ aqua: '0ff'
+ },
+
+ re_RGB: /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i,
+ re_hex: /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i,
+ re_hex3: /([0-9A-F])/gi,
+
+ toRGB: function(val) {
+ if (!Y.Dom.Color.re_RGB.test(val)) {
+ val = Y.Dom.Color.toHex(val);
+ }
+
+ if(Y.Dom.Color.re_hex.exec(val)) {
+ val = 'rgb(' + [
+ PARSE_INT(RE.$1, 16),
+ PARSE_INT(RE.$2, 16),
+ PARSE_INT(RE.$3, 16)
+ ].join(', ') + ')';
+ }
+ return val;
+ },
+
+ toHex: function(val) {
+ val = Y.Dom.Color.KEYWORDS[val] || val;
+ if (Y.Dom.Color.re_RGB.exec(val)) {
+ var r = (RE.$1.length === 1) ? '0' + RE.$1 : Number(RE.$1),
+ g = (RE.$2.length === 1) ? '0' + RE.$2 : Number(RE.$2),
+ b = (RE.$3.length === 1) ? '0' + RE.$3 : Number(RE.$3);
+
+ val = [
+ r[TO_STRING](16),
+ g[TO_STRING](16),
+ b[TO_STRING](16)
+ ].join('');
+ }
+
+ if (val.length < 6) {
+ val = val.replace(Y.Dom.Color.re_hex3, '$1$1');
+ }
+
+ if (val !== 'transparent' && val.indexOf('#') < 0) {
+ val = '#' + val;
+ }
+
+ return val.toLowerCase();
+ }
+};
+}());
+YAHOO.register("dom", YAHOO.util.Dom, {version: "2.7.0", build: "1799"});