root / trunk / web / dojo / dojox / html / ext-dojo / style.js @ 10
History | View | Annotate | Download (8.31 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.html.ext-dojo.style"]){ |
||
9 | dojo._hasResource["dojox.html.ext-dojo.style"]=true; |
||
10 | dojo.provide("dojox.html.ext-dojo.style");
|
||
11 | dojo.experimental("dojox.html.ext-dojo.style");
|
||
12 | dojo.mixin(dojox.html["ext-dojo"].style,{supportsTransform:true,_toPx:function(_1){ |
||
13 | var ds=dojo.style,_2=this._conversion; |
||
14 | if(typeof _1==="number"){ |
||
15 | return _1+"px"; |
||
16 | }else{
|
||
17 | if(_1.toLowerCase().indexOf("px")!=-1){ |
||
18 | return _1;
|
||
19 | } |
||
20 | } |
||
21 | !_2.parentNode&&dojo.place(_2,dojo.body()); |
||
22 | ds(_2,"margin",_1);
|
||
23 | return ds(_2,"margin"); |
||
24 | },init:function(){ |
||
25 | var ds=dojo.style,_3=dojo.doc.documentElement.style,_4=dojox.html["ext-dojo"].style; |
||
26 | dojo.style=function(_5,_6,_7){ |
||
27 | var n=dojo.byId(_5),tr=(_6=="transform"),to=(_6=="transformOrigin"),_8=arguments.length; |
||
28 | if(_8==3){ |
||
29 | if(tr){
|
||
30 | _4.setTransform(n,_7,true);
|
||
31 | }else{
|
||
32 | if(to){
|
||
33 | _4.setTransformOrigin(n,_7); |
||
34 | }else{
|
||
35 | ds(_5,_6,_7); |
||
36 | } |
||
37 | } |
||
38 | } |
||
39 | if(_8==2){ |
||
40 | if(tr){
|
||
41 | return _4.getTransform(_5);
|
||
42 | }else{
|
||
43 | if(to){
|
||
44 | return _4.getTransformOrigin(_5);
|
||
45 | }else{
|
||
46 | return ds(_5,_6);
|
||
47 | } |
||
48 | } |
||
49 | } |
||
50 | }; |
||
51 | for(var i=0,_9=["WebkitT","MozT","OT","t"];i<_9.length;i++){ |
||
52 | if(typeof _3[_9[i]+"ransform"]!=="undefined"){ |
||
53 | this.tPropertyName=_9[i]+"ransform"; |
||
54 | } |
||
55 | if(typeof _3[_9[i]+"ransformOrigin"]!=="undefined"){ |
||
56 | this.toPropertyName=_9[i]+"ransformOrigin"; |
||
57 | } |
||
58 | } |
||
59 | if(this.tPropertyName){ |
||
60 | this.setTransform=function(_a,_b){ |
||
61 | return dojo.style(_a,this.tPropertyName,_b); |
||
62 | }; |
||
63 | this.getTransform=function(_c){ |
||
64 | return dojo.style(_c,this.tPropertyName); |
||
65 | }; |
||
66 | }else{
|
||
67 | if(dojo.isIE){
|
||
68 | this.setTransform=this._setTransformFilter; |
||
69 | this.getTransform=this._getTransformFilter; |
||
70 | } |
||
71 | } |
||
72 | if(this.toPropertyName){ |
||
73 | this.setTransformOrigin=function(_d,_e){ |
||
74 | return dojo.style(_d,this.toPropertyName,_e); |
||
75 | }; |
||
76 | this.getTransformOrigin=function(_f){ |
||
77 | return dojo.style(_f,this.toPropertyName); |
||
78 | }; |
||
79 | }else{
|
||
80 | if(dojo.isIE){
|
||
81 | this.setTransformOrigin=this._setTransformOriginFilter; |
||
82 | this.getTransformOrigin=this._getTransformOriginFilter; |
||
83 | }else{
|
||
84 | this.supportsTransform=false; |
||
85 | } |
||
86 | } |
||
87 | this._conversion=dojo.create("div",{style:{position:"absolute",top:"-100px",left:"-100px",fontSize:0,width:"0",backgroundPosition:"50% 50%"}}); |
||
88 | },_notSupported:function(){ |
||
89 | console.warn("Sorry, this browser doesn't support transform and transform-origin");
|
||
90 | },_setTransformOriginFilter:function(_10,_11){ |
||
91 | var to=dojo.trim(_11).replace(" top"," 0").replace("left ","0 ").replace(" center","50%").replace("center ","50% ").replace(" bottom"," 100%").replace("right ","100% ").replace(/\s+/," "),_12=to.split(" "),n=dojo.byId(_10),t=this.getTransform(n),_13=true; |
||
92 | for(var i=0;i<_12.length;i++){ |
||
93 | _13=_13&&/^0|(\d+(%|px|pt|in|pc|mm|cm))$/.test(_12[i]);
|
||
94 | if(_12[i].indexOf("%")==-1){ |
||
95 | _12[i]=this._toPx(_12[i]);
|
||
96 | } |
||
97 | } |
||
98 | if(!_13){
|
||
99 | return;
|
||
100 | } |
||
101 | if(!_12.length||_12.length>2){ |
||
102 | return;
|
||
103 | } |
||
104 | dojo.attr(n,"dojo-transform-origin",_12.join(" ")); |
||
105 | t&&this.setTransform(_10,t);
|
||
106 | },_getTransformOriginFilter:function(_14){ |
||
107 | return dojo.attr(_14,"dojo-transform-origin")||"50% 50%"; |
||
108 | },_setTransformFilter:function(_15,_16){ |
||
109 | var t=_16.replace(/\s/g,""),n=dojo.byId(_15),_17=t.split(")"),_18=1,_19=1,_1a="DXImageTransform.Microsoft.Matrix",_1b=dojo.hasAttr,_1c=dojo.attr,PI=Math.PI,cos=Math.cos,sin=Math.sin,tan=Math.tan,max=Math.max,min=Math.min,abs=Math.abs,_1d=PI/180,_1e=PI/200,ct="",_1f="",_20=[],x0=0,y0=0,dx=0,dy=0,xc=0,yc=0,a=0,m11=1,m12=0,m21=0,m22=1,tx=0,ty=0,_21=[m11,m12,m21,m22,tx,ty],_22=false,ds=dojo.style,_23=ds(n,"position")=="absolute"?"absolute":"relative",w=ds(n,"width")+ds(n,"paddingLeft")+ds(n,"paddingRight"),h=ds(n,"height")+ds(n,"paddingTop")+ds(n,"paddingBottom"),_24=this._toPx; |
||
110 | !_1b(n,"dojo-transform-origin")&&this.setTransformOrigin(n,"50% 50%"); |
||
111 | for(var i=0,l=_17.length;i<l;i++){ |
||
112 | _20=_17[i].match(/matrix|rotate|scaleX|scaleY|scale|skewX|skewY|skew|translateX|translateY|translate/);
|
||
113 | _1f=_20?_20[0]:""; |
||
114 | switch(_1f){
|
||
115 | case "matrix": |
||
116 | ct=_17[i].replace(/matrix\(|\)/g,""); |
||
117 | var _25=ct.split(","); |
||
118 | m11=_21[0]*_25[0]+_21[1]*_25[2]; |
||
119 | m12=_21[0]*_25[1]+_21[1]*_25[3]; |
||
120 | m21=_21[2]*_25[0]+_21[3]*_25[2]; |
||
121 | m22=_21[2]*_25[1]+_21[3]*_25[3]; |
||
122 | tx=_21[4]+_25[4]; |
||
123 | ty=_21[5]+_25[5]; |
||
124 | break;
|
||
125 | case "rotate": |
||
126 | ct=_17[i].replace(/rotate\(|\)/g,""); |
||
127 | _18=ct.indexOf("deg")!=-1?_1d:ct.indexOf("grad")!=-1?_1e:1; |
||
128 | a=parseFloat(ct)*_18; |
||
129 | var s=sin(a),c=cos(a);
|
||
130 | m11=_21[0]*c+_21[1]*s; |
||
131 | m12=-_21[0]*s+_21[1]*c; |
||
132 | m21=_21[2]*c+_21[3]*s; |
||
133 | m22=-_21[2]*s+_21[3]*c; |
||
134 | break;
|
||
135 | case "skewX": |
||
136 | ct=_17[i].replace(/skewX\(|\)/g,""); |
||
137 | _18=ct.indexOf("deg")!=-1?_1d:ct.indexOf("grad")!=-1?_1e:1; |
||
138 | var ta=tan(parseFloat(ct)*_18);
|
||
139 | m11=_21[0];
|
||
140 | m12=_21[0]*ta+_21[1]; |
||
141 | m21=_21[2];
|
||
142 | m22=_21[2]*ta+_21[3]; |
||
143 | break;
|
||
144 | case "skewY": |
||
145 | ct=_17[i].replace(/skewY\(|\)/g,""); |
||
146 | _18=ct.indexOf("deg")!=-1?_1d:ct.indexOf("grad")!=-1?_1e:1; |
||
147 | ta=tan(parseFloat(ct)*_18); |
||
148 | m11=_21[0]+_21[1]*ta; |
||
149 | m12=_21[1];
|
||
150 | m21=_21[2]+_21[3]*ta; |
||
151 | m22=_21[3];
|
||
152 | break;
|
||
153 | case "skew": |
||
154 | ct=_17[i].replace(/skew\(|\)/g,""); |
||
155 | var _26=ct.split(","); |
||
156 | _26[1]=_26[1]||"0"; |
||
157 | _18=_26[0].indexOf("deg")!=-1?_1d:_26[0].indexOf("grad")!=-1?_1e:1; |
||
158 | _19=_26[1].indexOf("deg")!=-1?_1d:_26[1].indexOf("grad")!=-1?_1e:1; |
||
159 | var a0=tan(parseFloat(_26[0])*_18),a1=tan(parseFloat(_26[1])*_19); |
||
160 | m11=_21[0]+_21[1]*a1; |
||
161 | m12=_21[0]*a0+_21[1]; |
||
162 | m21=_21[2]+_21[3]*a1; |
||
163 | m22=_21[2]*a0+_21[3]; |
||
164 | break;
|
||
165 | case "scaleX": |
||
166 | ct=parseFloat(_17[i].replace(/scaleX\(|\)/g,""))||1; |
||
167 | m11=_21[0]*ct;
|
||
168 | m12=_21[1];
|
||
169 | m21=_21[2]*ct;
|
||
170 | m22=_21[3];
|
||
171 | break;
|
||
172 | case "scaleY": |
||
173 | ct=parseFloat(_17[i].replace(/scaleY\(|\)/g,""))||1; |
||
174 | m11=_21[0];
|
||
175 | m12=_21[1]*ct;
|
||
176 | m21=_21[2];
|
||
177 | m22=_21[3]*ct;
|
||
178 | break;
|
||
179 | case "scale": |
||
180 | ct=_17[i].replace(/scale\(|\)/g,""); |
||
181 | var _27=ct.split(","); |
||
182 | _27[1]=_27[1]||_27[0]; |
||
183 | m11=_21[0]*_27[0]; |
||
184 | m12=_21[1]*_27[1]; |
||
185 | m21=_21[2]*_27[0]; |
||
186 | m22=_21[3]*_27[1]; |
||
187 | break;
|
||
188 | case "translateX": |
||
189 | ct=parseInt(_17[i].replace(/translateX\(|\)/g,""))||1; |
||
190 | m11=_21[0];
|
||
191 | m12=_21[1];
|
||
192 | m21=_21[2];
|
||
193 | m22=_21[3];
|
||
194 | tx=_24(ct); |
||
195 | tx&&_1c(n,"dojo-transform-matrix-tx",tx);
|
||
196 | break;
|
||
197 | case "translateY": |
||
198 | ct=parseInt(_17[i].replace(/translateY\(|\)/g,""))||1; |
||
199 | m11=_21[0];
|
||
200 | m12=_21[1];
|
||
201 | m21=_21[2];
|
||
202 | m22=_21[3];
|
||
203 | ty=_24(ct); |
||
204 | ty&&_1c(n,"dojo-transform-matrix-ty",ty);
|
||
205 | break;
|
||
206 | case "translate": |
||
207 | ct=_17[i].replace(/translate\(|\)/g,""); |
||
208 | m11=_21[0];
|
||
209 | m12=_21[1];
|
||
210 | m21=_21[2];
|
||
211 | m22=_21[3];
|
||
212 | var _28=ct.split(","); |
||
213 | _28[0]=parseInt(_24(_28[0]))||0; |
||
214 | _28[1]=parseInt(_24(_28[1]))||0; |
||
215 | tx=_28[0];
|
||
216 | ty=_28[1];
|
||
217 | tx&&_1c(n,"dojo-transform-matrix-tx",tx);
|
||
218 | ty&&_1c(n,"dojo-transform-matrix-ty",ty);
|
||
219 | break;
|
||
220 | } |
||
221 | _21=[m11,m12,m21,m22,tx,ty]; |
||
222 | } |
||
223 | var Bx=min(w*m11+h*m12,min(min(w*m11,h*m12),0)),By=min(w*m21+h*m22,min(min(w*m21,h*m22),0)); |
||
224 | dx=-Bx; |
||
225 | dy=-By; |
||
226 | if(dojo.isIE<8){ |
||
227 | n.style.zoom="1";
|
||
228 | if(_23!="absolute"){ |
||
229 | var _29=ds(_15.parentNode,"width"),tw=abs(w*m11),th=abs(h*m12),_2a=max(tw+th,max(max(th,tw),0)); |
||
230 | dx-=(_2a-w)/2-(_29>_2a?0:(_2a-_29)/2); |
||
231 | } |
||
232 | }else{
|
||
233 | if(dojo.isIE==8){ |
||
234 | ds(n,"zIndex")=="auto"&&(n.style.zIndex="0"); |
||
235 | } |
||
236 | } |
||
237 | try{
|
||
238 | _22=!!n.filters.item(_1a); |
||
239 | } |
||
240 | catch(e){
|
||
241 | _22=false;
|
||
242 | } |
||
243 | if(_22){
|
||
244 | n.filters.item(_1a).M11=m11; |
||
245 | n.filters.item(_1a).M12=m12; |
||
246 | n.filters.item(_1a).M21=m21; |
||
247 | n.filters.item(_1a).M22=m22; |
||
248 | n.filters.item(_1a).filterType="bilinear";
|
||
249 | n.filters.item(_1a).Dx=0;
|
||
250 | n.filters.item(_1a).Dy=0;
|
||
251 | n.filters.item(_1a).sizingMethod="auto expand";
|
||
252 | }else{
|
||
253 | n.style.filter+=" progid:"+_1a+"(M11="+m11+",M12="+m12+",M21="+m21+",M22="+m22+",FilterType='bilinear',Dx=0,Dy=0,sizingMethod='auto expand')"; |
||
254 | } |
||
255 | tx=parseInt(_1c(n,"dojo-transform-matrix-tx")||"0"); |
||
256 | ty=parseInt(_1c(n,"dojo-transform-matrix-ty")||"0"); |
||
257 | var _2b=_1c(n,"dojo-transform-origin").split(" "); |
||
258 | for(i=0;i<2;i++){ |
||
259 | _2b[i]=_2b[i]||"50%";
|
||
260 | } |
||
261 | xc=(_2b[0].toString().indexOf("%")!=-1)?w*parseInt(_2b[0])*0.01:_2b[0]; |
||
262 | yc=(_2b[1].toString().indexOf("%")!=-1)?h*parseInt(_2b[1])*0.01:_2b[1]; |
||
263 | if(_1b(n,"dojo-startX")){ |
||
264 | x0=parseInt(_1c(n,"dojo-startX"));
|
||
265 | }else{
|
||
266 | x0=parseInt(ds(n,"left"));
|
||
267 | _1c(n,"dojo-startX",_23=="absolute"?x0:"0"); |
||
268 | } |
||
269 | if(_1b(n,"dojo-startY")){ |
||
270 | y0=parseInt(_1c(n,"dojo-startY"));
|
||
271 | }else{
|
||
272 | y0=parseInt(ds(n,"top"));
|
||
273 | _1c(n,"dojo-startY",_23=="absolute"?y0:"0"); |
||
274 | } |
||
275 | ds(n,{position:_23,left:x0-parseInt(dx)+parseInt(xc)-((parseInt(xc)-tx)*m11+(parseInt(yc)-ty)*m12)+"px",top:y0-parseInt(dy)+parseInt(yc)-((parseInt(xc)-tx)*m21+(parseInt(yc)-ty)*m22)+"px"}); |
||
276 | },_getTransformFilter:function(_2c){ |
||
277 | try{
|
||
278 | var n=dojo.byId(_2c),_2d=n.filters.item(0); |
||
279 | return "matrix("+_2d.M11+", "+_2d.M12+", "+_2d.M21+", "+_2d.M22+", "+(dojo.attr(_2c,"dojo-transform-tx")||"0")+", "+(dojo.attr(_2c,"dojo-transform-ty")||"0")+")"; |
||
280 | } |
||
281 | catch(e){
|
||
282 | return "matrix(1, 0, 0, 1, 0, 0)"; |
||
283 | } |
||
284 | },setTransform:function(){ |
||
285 | this._notSupported();
|
||
286 | },setTransformOrigin:function(){ |
||
287 | this._notSupported();
|
||
288 | }}); |
||
289 | dojox.html["ext-dojo"].style.init();
|
||
290 | } |