root / trunk / web / dojo / dojox / drawing / ui / Button.js @ 12
History | View | Annotate | Download (4.42 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.drawing.ui.Button"]){ |
||
9 | dojo._hasResource["dojox.drawing.ui.Button"]=true; |
||
10 | dojo.provide("dojox.drawing.ui.Button");
|
||
11 | dojox.drawing.ui.Button=dojox.drawing.util.oo.declare(function(_1){
|
||
12 | _1.subShape=true;
|
||
13 | dojo.mixin(this,_1);
|
||
14 | this.width=_1.data.width||_1.data.rx*2; |
||
15 | this.height=_1.data.height||_1.data.ry*2; |
||
16 | this.y=_1.data.y||_1.data.cy-_1.data.ry;
|
||
17 | this.id=this.id||this.util.uid(this.type); |
||
18 | this.util.attr(this.container,"id",this.id); |
||
19 | if(this.callback){ |
||
20 | this.hitched=dojo.hitch(this.scope||window,this.callback,this); |
||
21 | } |
||
22 | _1.drawingType="ui";
|
||
23 | if(_1.data.width&&_1.data.height){
|
||
24 | this.shape=new dojox.drawing.stencil.Rect(_1); |
||
25 | }else{
|
||
26 | this.shape=new dojox.drawing.stencil.Ellipse(_1); |
||
27 | } |
||
28 | var _2=function(s,p,v){ |
||
29 | dojo.forEach(["norm","over","down","selected"],function(nm){ |
||
30 | s[nm].fill[p]=v; |
||
31 | }); |
||
32 | }; |
||
33 | _2(this.style.button,"y2",this.height+this.y); |
||
34 | _2(this.style.button,"y1",this.y); |
||
35 | if(_1.icon&&!_1.icon.text){
|
||
36 | var _3=this.drawing.getConstructor(_1.icon.type); |
||
37 | var o=this.makeOptions(_1.icon); |
||
38 | o.data=dojo.mixin(o.data,this.style.button.icon.norm);
|
||
39 | if(o.data&&o.data.borderWidth===0){ |
||
40 | o.data.fill=this.style.button.icon.norm.fill=o.data.color;
|
||
41 | }else{
|
||
42 | if(_1.icon.type=="line"||(_1.icon.type=="path"&&!_1.icon.closePath)){ |
||
43 | this.style.button.icon.selected.color=this.style.button.icon.selected.fill; |
||
44 | }else{
|
||
45 | } |
||
46 | } |
||
47 | this.icon=new _3(o); |
||
48 | }else{
|
||
49 | if(_1.text||(_1.icon&&_1.icon.text)){
|
||
50 | o=this.makeOptions(_1.text||_1.icon.text);
|
||
51 | o.data.color=this.style.button.icon.norm.color;
|
||
52 | this.style.button.icon.selected.color=this.style.button.icon.selected.fill; |
||
53 | this.icon=new dojox.drawing.stencil.Text(o); |
||
54 | this.icon.attr({height:this.icon._lineHeight,y:((this.height-this.icon._lineHeight)/2)+this.y}); |
||
55 | } |
||
56 | } |
||
57 | var c=this.drawing.getConstructor(this.toolType); |
||
58 | if(c){
|
||
59 | this.drawing.addUI("tooltip",{data:{text:c.setup.tooltip},button:this}); |
||
60 | } |
||
61 | this.onOut();
|
||
62 | },{callback:null,scope:null,hitched:null,toolType:"",onClick:function(_4){ |
||
63 | },makeOptions:function(d,s){ |
||
64 | s=s||1;
|
||
65 | d=dojo.clone(d); |
||
66 | var o={util:this.util,mouse:this.mouse,container:this.container,subShape:true}; |
||
67 | if(typeof (d)=="string"){ |
||
68 | o.data={x:this.data.x-5,y:this.data.y+2,width:this.data.width,height:this.data.height,text:d,makeFit:true}; |
||
69 | }else{
|
||
70 | if(d.points){
|
||
71 | dojo.forEach(d.points,function(pt){
|
||
72 | pt.x=pt.x*this.data.width*0.01*s+this.data.x; |
||
73 | pt.y=pt.y*this.data.height*0.01*s+this.data.y; |
||
74 | },this);
|
||
75 | o.data={}; |
||
76 | for(var n in d){ |
||
77 | if(n!="points"){ |
||
78 | o.data[n]=d[n]; |
||
79 | } |
||
80 | } |
||
81 | o.points=d.points; |
||
82 | }else{
|
||
83 | for(n in d){ |
||
84 | if(/x|width/.test(n)){ |
||
85 | d[n]=d[n]*this.data.width*0.01*s; |
||
86 | }else{
|
||
87 | if(/y|height/.test(n)){ |
||
88 | d[n]=d[n]*this.data.height*0.01*s; |
||
89 | } |
||
90 | } |
||
91 | if(/x/.test(n)&&!/r/.test(n)){ |
||
92 | d[n]+=this.data.x;
|
||
93 | }else{
|
||
94 | if(/y/.test(n)&&!/r/.test(n)){ |
||
95 | d[n]+=this.data.y;
|
||
96 | } |
||
97 | } |
||
98 | } |
||
99 | delete d.type;
|
||
100 | o.data=d; |
||
101 | } |
||
102 | } |
||
103 | o.drawingType="ui";
|
||
104 | return o;
|
||
105 | if(d.borderWidth!==undefined){ |
||
106 | o.data.borderWidth=d.borderWidth; |
||
107 | } |
||
108 | return o;
|
||
109 | },enabled:true,selected:false,type:"drawing.library.UI.Button",select:function(){ |
||
110 | this.selected=true; |
||
111 | if(this.icon){ |
||
112 | this.icon.attr(this.style.button.icon.selected); |
||
113 | } |
||
114 | this._change(this.style.button.selected); |
||
115 | this.shape.shadow&&this.shape.shadow.hide(); |
||
116 | },deselect:function(){ |
||
117 | this.selected=false; |
||
118 | if(this.icon){ |
||
119 | this.icon.attr(this.style.button.icon.norm); |
||
120 | } |
||
121 | this.shape.shadow&&this.shape.shadow.show(); |
||
122 | this._change(this.style.button.norm); |
||
123 | },disable:function(){ |
||
124 | if(!this.enabled){ |
||
125 | return;
|
||
126 | } |
||
127 | this.enabled=false; |
||
128 | this._change(this.style.button.disabled); |
||
129 | this.icon.attr({color:this.style.button.norm.color}); |
||
130 | },enable:function(){ |
||
131 | if(this.enabled){ |
||
132 | return;
|
||
133 | } |
||
134 | this.enabled=true; |
||
135 | this._change(this.style.button.norm); |
||
136 | this.icon.attr({color:this.style.button.icon.norm.color}); |
||
137 | },_change:function(_5){ |
||
138 | this.shape.attr(_5);
|
||
139 | this.shape.shadow&&this.shape.shadow.container.moveToBack(); |
||
140 | if(this.icon){ |
||
141 | this.icon.shape.moveToFront();
|
||
142 | } |
||
143 | },onOver:function(){ |
||
144 | if(this.selected||!this.enabled){ |
||
145 | return;
|
||
146 | } |
||
147 | this._change(this.style.button.over); |
||
148 | },onOut:function(){ |
||
149 | if(this.selected){ |
||
150 | return;
|
||
151 | } |
||
152 | this._change(this.style.button.norm); |
||
153 | },onDown:function(){ |
||
154 | if(this.selected||!this.enabled){ |
||
155 | return;
|
||
156 | } |
||
157 | this._change(this.style.button.selected); |
||
158 | },onUp:function(){ |
||
159 | if(!this.enabled){ |
||
160 | return;
|
||
161 | } |
||
162 | this._change(this.style.button.over); |
||
163 | if(this.hitched){ |
||
164 | this.hitched();
|
||
165 | } |
||
166 | this.onClick(this); |
||
167 | },attr:function(_6){ |
||
168 | if(this.icon){ |
||
169 | this.icon.attr(_6);
|
||
170 | } |
||
171 | }}); |
||
172 | dojox.drawing.register({name:"dojox.drawing.ui.Button"},"stencil"); |
||
173 | } |