Rev 20 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
20 | reyssat | 1 | /* |
2 | DynAPI Distribution |
||
3 | BorderManager Class |
||
4 | |||
5 | The DynAPI Distribution is distributed under the terms of the GNU LGPL license. |
||
6 | |||
7 | requires: Highlighter |
||
8 | */ |
||
9 | |||
10 | BorderManager={}; |
||
11 | |||
12 | // usage: FocusManager.enableFocus('auto',true,'click',lyr1,lyr2,...lyrN); |
||
13 | BorderManager.enableFocus=function(b,c,type){ |
||
14 | var lyr,arg=arguments; |
||
15 | for (var i=3;i<arg.length;i++){ |
||
16 | lyr=arg[i]; |
||
17 | if(lyr) lyr.setBorder(b,c); |
||
18 | } |
||
19 | }; |
||
20 | |||
21 | /* |
||
22 | Outer Border uses Frame class with image support. |
||
23 | by: |
||
24 | Kevin Gargan (kevin[at]kegcl.demon.co.uk) |
||
25 | useage: |
||
26 | f=new Frame([widths],[sidecolors||sideimages],[cornerimages]) |
||
27 | and |
||
28 | f.setBorder([widths],[sidecolors||sideimages],[cornerimages]) |
||
29 | where |
||
30 | Parameter widths, sidecolors, sideimages and cornerimages may be scalar |
||
31 | or array defining top, right, bottom and left (defaulting like css). In |
||
32 | addition the corner images are defined as from top right, bottom right, |
||
33 | bottom left and top left. |
||
34 | e.g. |
||
35 | 1,'white' |
||
36 | 10,'tile.gif' |
||
37 | [1,2,3,4],['red','green','blue','yellow'] |
||
38 | 10,['t.gif','r.gif'] |
||
39 | 10,['t.gif','r.gif','b.gif','l.gif'],['tr.gif','br.gif','bl.gif','tl.gif'] |
||
40 | */ |
||
41 | function Frame(widths,sideimgs,cornerimgs) { |
||
42 | this.base=DynLayer; |
||
43 | this.base(); |
||
44 | this.setDefaults(widths,sideimgs,cornerimgs); |
||
45 | this.addChild(new Skin('n',this.sides[0]),'_fN'); |
||
46 | this.addChild(new Skin('e',this.sides[1]),'_fE'); |
||
47 | this.addChild(new Skin('s',this.sides[2]),'_fS'); |
||
48 | this.addChild(new Skin('w',this.sides[3]),'_fW'); |
||
49 | if(cornerimgs) { |
||
50 | this.addChild(new Skin('ne',this.corners[0]),'_fNE'); |
||
51 | this.addChild(new Skin('se',this.corners[1]),'_fSE'); |
||
52 | this.addChild(new Skin('sw',this.corners[2]),'_fSW'); |
||
53 | this.addChild(new Skin('nw',this.corners[3]),'_fNW'); |
||
54 | } |
||
55 | } |
||
56 | Frame._defaults=function(arry,def) { |
||
57 | var i=(arry==null)?[def]:(typeof(arry)!='object')?[arry]:arry, out=[]; |
||
58 | out[0]=i[0]; |
||
59 | out[1]=(i[1]!=null)?i[1]:out[0]; |
||
60 | out[2]=(i[2]!=null)?i[2]:out[0]; |
||
61 | out[3]=(i[3]!=null)?i[3]:out[1]; |
||
62 | return out; |
||
63 | }; |
||
64 | Frame._defaultCorners=function(haveCorners,ws,cimgs) { |
||
65 | var corners=[]; |
||
66 | corners[0]=[haveCorners?ws[1]:0,haveCorners?ws[0]:0,null,null,null,cimgs[0]]; |
||
67 | corners[1]=[haveCorners?ws[1]:0,haveCorners?ws[2]:0,null,null,null,cimgs[1]]; |
||
68 | corners[2]=[haveCorners?ws[3]:0,haveCorners?ws[2]:0,null,null,null,cimgs[2]]; |
||
69 | corners[3]=[haveCorners?ws[3]:0,haveCorners?ws[0]:0,null,null,null,cimgs[3]]; |
||
70 | return corners; |
||
71 | }; |
||
72 | Frame._defaultSides=function(ws,cs,simgs) { |
||
73 | var sides=[]; |
||
74 | var isCol=(simgs[0].indexOf('.')<0); // Color or image.gif file. |
||
75 | sides[0]=[null,ws[0],ws[1],cs[3][0],isCol?simgs[0]:null,isCol?null:simgs[0]]; |
||
76 | sides[1]=[ws[1],null,cs[0][1],ws[2],isCol?simgs[1]:null,isCol?null:simgs[1]]; |
||
77 | sides[2]=[null,ws[2],cs[1][0],ws[3],isCol?simgs[2]:null,isCol?null:simgs[2]]; |
||
78 | sides[3]=[ws[3],null,ws[0],cs[2][1],isCol?simgs[3]:null,isCol?null:simgs[3]]; |
||
79 | return sides; |
||
80 | }; |
||
81 | var p=Frame.prototype=new DynLayer(); |
||
82 | p.setDefaults=function(widths,sideimgs,cornerimgs) { |
||
83 | this.widths=Frame._defaults(widths,0); |
||
84 | this.sideimgs=Frame._defaults(sideimgs,'black'); |
||
85 | this.cornerimgs=Frame._defaults(cornerimgs,null); |
||
86 | this.corners=Frame._defaultCorners(cornerimgs,this.widths,this.cornerimgs); |
||
87 | this.sides=Frame._defaultSides(this.widths,this.corners,this.sideimgs); |
||
88 | }; |
||
89 | p.setBorder=function(widths,sideimgs,cornerimgs) { |
||
90 | var wso=this.widths; // Widths old. |
||
91 | var eo=wso[1], wo=wso[3], no=wso[0], so=wso[2]; |
||
92 | this.setDefaults(widths,sideimgs,cornerimgs); |
||
93 | this._fN.graft(this.sides[0]); |
||
94 | this._fE.graft(this.sides[1]); |
||
95 | this._fS.graft(this.sides[2]); |
||
96 | this._fW.graft(this.sides[3]); |
||
97 | if(cornerimgs) { |
||
98 | if(this._fNE==null) this.addChild(new Skin('ne',this.corners[0]),'_fNE'); |
||
99 | else this._fNE.graft(this.corners[0]); |
||
100 | if(this._fSE==null) this.addChild(new Skin('se',this.corners[1]),'_fSE'); |
||
101 | else this._fSE.graft(this.corners[1]); |
||
102 | if(this._fSW==null) this.addChild(new Skin('sw',this.corners[2]),'_fSW'); |
||
103 | else this._fSW.graft(this.corners[2]); |
||
104 | if(this._fNW==null) this.addChild(new Skin('nw',this.corners[3]),'_fNW'); |
||
105 | else this._fNW.graft(this.corners[3]); |
||
106 | } |
||
107 | else { |
||
108 | if(this._fNE) this._fNE.graft(this.corners[0]); |
||
109 | if(this._fSE) this._fSE.graft(this.corners[1]); |
||
110 | if(this._fSW) this._fSW.graft(this.corners[2]); |
||
111 | if(this._fNW) this._fNW.graft(this.corners[3]); |
||
112 | } |
||
113 | var ws=this.widths; // Widths new. |
||
114 | var de=ws[1]-eo, dw=ws[3]-wo, dn=ws[0]-no, ds=ws[2]-so; // Deltas. |
||
115 | this.setSize(this.w+de+dw,this.h+dn+ds); |
||
116 | var left=Math.ceil((ws[3]-ws[1])/2), top=Math.ceil((ws[0]-ws[2])/2); |
||
117 | this._fC.setAnchor({centerH:left,centerV:top}); |
||
118 | }; |
||
119 | p.addContent=function(c) { |
||
120 | if(c._fP) return; |
||
121 | else c._fP=this; |
||
122 | this.setLocation(c.x,c.y); |
||
123 | var ws=this.widths; |
||
124 | this.setSize(c.w+ws[1]+ws[3],c.h+ws[0]+ws[2]); |
||
125 | var left=Math.ceil((ws[3]-ws[1])/2), top=Math.ceil((ws[0]-ws[2])/2); |
||
126 | c.setAnchor({centerH:left,centerV:top}); |
||
127 | return this.addChild(c,'_fC'); |
||
128 | }; |
||
129 | function SquarePictureFrame(widths,sideimgs,cornerimgs,image,w,h,color) { |
||
130 | this.base=Frame; |
||
131 | this.base(widths,sideimgs,cornerimgs); |
||
132 | if(color) this.setBgColor(color); |
||
133 | this.addContent(new DynLayer(image.getHTML(),null,null,w,h)); |
||
134 | var longest=(w>h)?w:h, ws=this.widths; |
||
135 | this.setSize(longest+ws[1]+ws[3],longest+ws[0]+ws[2]); |
||
136 | }; |
||
137 | SquarePictureFrame.prototype=new Frame(); |
||
138 | |||
139 | /* |
||
140 | Inner Border - no Image/Frame support. |
||
141 | useage: setInnerBorder(N,'#000000') |
||
142 | setInnerBorder(N,{top:'white',bottom:'black'}); |
||
143 | setInnerBorder(N,{light:'white',dark:'silver'}); |
||
144 | */ |
||
145 | DynLayer.prototype._bor_tp={anchor:{top:0,left:0,right:0}}; |
||
146 | DynLayer.prototype._bor_rt={anchor:{top:0,right:0,bottom:0}}; |
||
147 | DynLayer.prototype._bor_bm={anchor:{bottom:0,left:0,right:0}}; |
||
148 | DynLayer.prototype._bor_lt={anchor:{top:0,left:0,bottom:0}}; |
||
149 | |||
150 | DynLayer.prototype.setInnerBorder = function(w,c){ |
||
151 | var tc,rc,bc,lc; |
||
152 | w = (w==null)? 0:w; |
||
153 | if (c==null) c='#000000'; |
||
154 | else if(c.constructor==Object) { |
||
155 | tc=c.top||c.light; |
||
156 | rc=c.right||c.dark; |
||
157 | bc=c.bottom||c.dark; |
||
158 | lc=c.left||c.light; |
||
159 | c=null; |
||
160 | }; |
||
161 | if(!this._borTp){ |
||
162 | // create border layers |
||
163 | this.addChild(new Highlighter(this._bor_tp),'_borTp');//top |
||
10534 | obado | 164 | this.addChild(new Highlighter(this._bor_rt),'_borRt');//right |
20 | reyssat | 165 | this.addChild(new Highlighter(this._bor_bm),'_borBm');//bottom |
166 | this.addChild(new Highlighter(this._bor_lt),'_borLt'); //left |
||
167 | } |
||
168 | // width |
||
169 | this._borTp.setHeight(w); |
||
170 | this._borRt.setWidth(w); |
||
171 | this._borBm.setHeight(w); |
||
172 | this._borLt.setWidth(w); |
||
173 | // color |
||
174 | this._borTp.setBgColor(tc||c); |
||
175 | this._borRt.setBgColor(rc||c); |
||
176 | this._borBm.setBgColor(bc||c); |
||
177 | this._borLt.setBgColor(lc||c); |
||
178 | // update anchors |
||
179 | if (this._updateAnchors) this._updateAnchors(); |
||
180 | }; |
||
181 |