Rev 11521 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
20 | reyssat | 1 | /* |
2 | DynAPI Distribution |
||
3 | DynLayer Base/Common Class |
||
4 | |||
5 | The DynAPI Distribution is distributed under the terms of the GNU LGPL license. |
||
11521 | obado | 6 | |
20 | reyssat | 7 | requires: dynapi.api.DynDocument |
8 | */ |
||
9 | |||
10 | var DynLayerBase = {}; // used by library |
||
11 | function DynLayer(html,x,y,w,h,color,image) { |
||
12 | this.DynElement = DynElement; |
||
13 | this.DynElement(); |
||
14 | |||
15 | if (html && html.constructor==Object){ |
||
16 | var args=html; // dictionary input |
||
17 | html=args.html; |
||
18 | x = args.x; |
||
19 | y = args.y; |
||
20 | w = args.w; |
||
21 | h = args.h; |
||
22 | color = args.color; |
||
23 | image = args.image; |
||
24 | this.z = (args.zIndex||1); |
||
25 | this._saveAnchor = args.anchor; |
||
26 | this.visible = (args.visible==false)?false:true; |
||
27 | this._textSelectable = (args.textSelectable==false)?false:true; |
||
28 | if (args.id) this.setID(args.id,true); |
||
29 | } |
||
30 | else { |
||
31 | this.visible = true; |
||
32 | this.z = 1; |
||
33 | this._saveAnchor = false; |
||
34 | this._textSelectable = true; |
||
35 | } |
||
11521 | obado | 36 | |
20 | reyssat | 37 | this.x = x; |
38 | this.y = y; |
||
39 | this.w = w; |
||
40 | this.h = h; |
||
41 | this.bgColor = color; |
||
42 | this.bgImage = image; |
||
43 | this.html = (html!=null)? html+'':null; // convert html to string |
||
44 | this.elm = null; |
||
45 | this.doc = null; |
||
11521 | obado | 46 | this.css = null; |
20 | reyssat | 47 | }; |
11521 | obado | 48 | var protoElement = dynapi.setPrototype('DynLayer','DynElement'); |
49 | protoElement._destroy = function() { |
||
20 | reyssat | 50 | this._destroyAllChildren(); |
51 | this.removeAllEventListeners(); |
||
52 | if (this.elm) this._remove(); |
||
53 | DynObject.all[this.id] = null; |
||
54 | this.children = null; |
||
55 | this.frame = null; |
||
11521 | obado | 56 | |
20 | reyssat | 57 | this.bgImage = null; |
58 | this.bgColor = null; |
||
59 | this.html = null; |
||
60 | this.x = null; |
||
61 | this.y = null; |
||
62 | this.w = null; |
||
63 | this.h = null; |
||
64 | this.z = null; |
||
65 | this.doc = null; |
||
66 | this.css = null; |
||
67 | this._dyndoc = null; |
||
68 | this.parent = null; |
||
69 | }; |
||
11521 | obado | 70 | protoElement._destroyAllChildren = function() { |
20 | reyssat | 71 | for (var i=0;i<this.children.length;i++) { |
72 | this.children[i]._destroy(); |
||
73 | delete this.children[i]; |
||
74 | } |
||
75 | this.children = []; |
||
76 | }; |
||
11521 | obado | 77 | protoElement._remove = function() { //! Overwritten by NS4 |
20 | reyssat | 78 | var p=this.parent; |
79 | if (this.elm) { |
||
80 | //this.elm.style.visibility = "hidden"; |
||
81 | //this.elm.innerHTML = ""; |
||
82 | //this.elm.outerHTML = ""; |
||
83 | var pref=p.elm; |
||
84 | if(document.getElementById && document.childNodes){ |
||
85 | if(this.elm.parentNode) pref = this.elm.parentNode; |
||
86 | pref.removeChild(this.elm); |
||
87 | } else if (pref && pref.children){ |
||
88 | this.elm.outerHTML=''; |
||
89 | } |
||
90 | this.elm = null; |
||
91 | |||
92 | if (this.releaseMouseEvents) this.releaseMouseEvents(); |
||
93 | if (this.releaseKeyEvents) this.releaseKeyEvents(); |
||
94 | } |
||
95 | /*this.frame = null; |
||
96 | this.bgImage = null; |
||
97 | this.bgColor = null; |
||
98 | this.html = null; |
||
99 | this.z = null; |
||
100 | this.w = null; |
||
101 | this.h = null; |
||
102 | this.elm = null; |
||
103 | this.doc = null; |
||
104 | this.css = null;*/ |
||
105 | }; |
||
11521 | obado | 106 | protoElement._createInserted = function(divs){ |
20 | reyssat | 107 | DynLayer._assignElement(this,null,divs); //! NS4 will ignore divs |
108 | DynElement._flagCreate(this); |
||
109 | }; |
||
11521 | obado | 110 | protoElement.getOuterHTML=function() { //! Overwritten by NS4 |
20 | reyssat | 111 | if(this._noStyle) return '<div '+this._cssClass+' id="'+this.id+'">'+this.getInnerHTML()+'</div>'; |
112 | else { |
||
113 | var s,clip='',bgimage=' background-image:none;'; |
||
114 | if(this.bgImage!=null) bgimage=' background-image:url('+this.bgImage+');'; |
||
115 | //else if (this.bgImage==null && this.html==null) bgimage=' background-image:none;'; |
||
116 | if (this.clip) clip=' clip:rect('+this.clip[0]+'px '+this.clip[1]+'px '+this.clip[2]+'px '+this.clip[3]+'px);'; |
||
117 | else if (this.w!=null && this.h!=null) clip=' clip:rect(0px '+this.w+'px '+this.h+'px 0px);'; |
||
118 | return [ |
||
119 | '\n<div '+this._cssClass+' id="'+this.id+'" style="', |
||
120 | ' left:',(this.x!=null? this.x : 0),'px;', |
||
11521 | obado | 121 | ' top:',(this.y!=null? this.y : 0),'px;', |
20 | reyssat | 122 | ((this.w!=null)? ' width:'+this.w+'px;':''), |
123 | ((this.h!=null)? ' height:'+this.h+'px;':''), |
||
124 | ((this.z)? ' z-index:'+this.z+';':''), |
||
125 | ((this._cursor!=null)? ' cursor:'+this._cursor+';':''), |
||
126 | ((this.bgColor!=null)? ' background-color:'+this.bgColor+';':''), |
||
127 | ((this.visible==false)? ' visibility:hidden;':' visibility:inherit;'), |
||
128 | bgimage, |
||
129 | clip, |
||
130 | this._cssOverflow, |
||
131 | this._cssPosition, |
||
132 | ';">', |
||
133 | this.getInnerHTML(), |
||
134 | '</div>' |
||
11521 | obado | 135 | ].join(''); |
20 | reyssat | 136 | } |
137 | }; |
||
11521 | obado | 138 | protoElement.getInnerHTML=function() { //! Overwritten by NS4 |
20 | reyssat | 139 | var s = ''; |
140 | var i,ch=this.children; |
||
141 | if (this.html!=null) s+=this.html; |
||
11521 | obado | 142 | if (this._blkBoardElm) s=('<div id="'+this.id+'_blkboard">'+s+'</div>'); |
143 | if(ch.length<50) for (i=0;i<ch.length;i++) s+=ch[i].getOuterHTML(); |
||
20 | reyssat | 144 | else if(ch.length){ |
145 | var ar=['']; // speed improvement for layers with nested children |
||
146 | for (i=0;i<ch.length;i++) ar[i]=ch[i].getOuterHTML(); |
||
11521 | obado | 147 | s=s+ar.join(''); |
20 | reyssat | 148 | } |
149 | return s; |
||
150 | }; |
||
151 | |||
11521 | obado | 152 | protoElement.getPageX = function() {return (this.isChild)? this.parent.getPageX()+(this.x||0) : this.x||0}; //! Overwritten by NS4 |
153 | protoElement.getPageY = function() {return (this.isChild)? this.parent.getPageY()+(this.y||0) : this.y||0}; //! Overwritten by NS4 |
||
20 | reyssat | 154 | |
11521 | obado | 155 | protoElement._cssClass = ''; |
156 | protoElement.setClass = function(c,noInlineStyle){ |
||
20 | reyssat | 157 | this._className=c; |
11521 | obado | 158 | if(this.css) this.css.className=c; |
20 | reyssat | 159 | else { |
160 | this._cssClass=(c)? 'class="'+c+'"':''; |
||
161 | this._noStyle=noInlineStyle; |
||
162 | } |
||
163 | }; |
||
11522 | obado | 164 | protoElement.setCssClass = function(classes){ |
165 | this._cssClass = 'class="'+classes+'"'; |
||
166 | }; |
||
20 | reyssat | 167 | |
11521 | obado | 168 | protoElement.setVisible = function(b) { //! Overwritten by NS4 |
20 | reyssat | 169 | //if (b!=this.visible) { |
170 | this.visible = b; |
||
171 | if (this.css) this.css.visibility = b? "inherit" : "hidden"; |
||
172 | //} |
||
173 | }; |
||
11521 | obado | 174 | protoElement.setSize = function(w,h) { //! Overwritten by NS4 |
20 | reyssat | 175 | if (this._useMinSize||this._useMaxSize){ |
176 | if (this._minW && w<this._minW) w=this._minW; |
||
177 | if (this._minH && h<this._minH) h=this._minH; |
||
178 | if (this._maxW && w>this._maxW) w=this._maxW; |
||
179 | if (this._maxH && h>this._maxH) h=this._maxH; |
||
180 | } |
||
181 | var cw = (w!=null && w!=this.w); |
||
182 | var ch = (h!=null && h!=this.h); |
||
183 | if (cw) this.w = w<0? 0 : w; |
||
184 | if (ch) this.h = h<0? 0 : h; |
||
185 | if (cw||ch) { |
||
186 | if (this._hasAnchor) this.updateAnchor(); // update this anchor |
||
187 | if (this._hasChildAnchors) this._updateAnchors(); // update child anchors |
||
188 | if (this.css) { |
||
189 | if (cw) this.css.width = this.w||0; |
||
190 | if (ch) this.css.height = this.h||0; |
||
191 | if (cw || ch) this.css.clip = 'rect(0px '+(this.w||0)+'px '+(this.h||0)+'px 0px)'; |
||
192 | if (this.updateLayout) this.updateLayout(); |
||
193 | } |
||
194 | } |
||
195 | if(this._hasResizeEvents) this.invokeEvent('resize'); |
||
196 | return (cw||ch); |
||
197 | }; |
||
11521 | obado | 198 | protoElement.setMaximumSize = function(w,h){ |
20 | reyssat | 199 | this._maxW=w; this._maxH=h; |
200 | this._useMaxSize=(w!=h!=null); |
||
201 | w=(this.w>w)?w:this.w; |
||
202 | h=(this.h>h)? h:this.h; |
||
203 | this.setSize(this.w,this.h); |
||
204 | }; |
||
11521 | obado | 205 | protoElement.setMinimumSize = function(w,h){ |
20 | reyssat | 206 | this._minW=w; this._minH=h; |
207 | this._useMinSize=(w!=h!=null); |
||
208 | this.setSize(this.w,this.h); |
||
209 | }; |
||
210 | |||
11521 | obado | 211 | protoElement._position = 'absolute'; |
212 | protoElement._cssPosition = ' position:absolute'; |
||
213 | protoElement.setPosition = function(p){ |
||
20 | reyssat | 214 | if(p!='relative' && p!='fixed' && p!='absolute') p='absolute'; |
215 | this._position=p; |
||
216 | if (this.css) this.css.position=p; |
||
217 | else this._cssPosition = ' position:'+p; |
||
218 | }; |
||
219 | |||
11521 | obado | 220 | protoElement._overflow='hidden'; |
221 | protoElement._cssOverflow =' overflow:hidden;'; |
||
222 | protoElement.getOverflow = function(){return this._overflow}; |
||
223 | protoElement.setOverflow = function(s){ |
||
20 | reyssat | 224 | if(!s) s='default'; |
225 | this._overflow=s; |
||
226 | if(this.css) this.css.overflow=s; |
||
227 | else this._cssOverflow=' overflow:'+s+';'; |
||
228 | }; |
||
229 | |||
11521 | obado | 230 | protoElement.getAnchor = function(){ |
20 | reyssat | 231 | if(!this.parent) return this._saveAnchors; |
232 | else if (this.parent._childAnchors) { |
||
233 | return this.parent._childAnchors[this.id]; |
||
234 | } |
||
235 | }; |
||
11521 | obado | 236 | protoElement.setAnchor = function(anchor) { |
237 | //console.log("[dynapi3x] dynlayer_base.js // setAnchor(" + anchor + ")"); |
||
238 | |||
20 | reyssat | 239 | if (anchor == null) { |
240 | delete this._saveAnchor; |
||
11521 | obado | 241 | if (this.parent && this.parent._childAnchors && this.parent._childAnchors[this.id]){ |
242 | //console.log("[dynapi3x] dynlayer_base.js // setAnchor -- deleting _childAnchors["+this.id+"]"); |
||
243 | delete this.parent._childAnchors[this.id]; |
||
244 | } |
||
20 | reyssat | 245 | this._hasAnchor = false; |
246 | } |
||
247 | else if (this.parent) { |
||
248 | if (!this.parent._childAnchors) this.parent._childAnchors = {}; |
||
11521 | obado | 249 | var parent_anchors = this.parent._childAnchors; |
250 | parent_anchors[this.id] = anchor; |
||
20 | reyssat | 251 | this.parent._updateAnchor(this.id); |
252 | this._hasAnchor = this.parent._hasChildAnchors = true; |
||
253 | } |
||
254 | else this._saveAnchor = anchor; |
||
255 | }; |
||
11521 | obado | 256 | protoElement.setX=function(x) {this.setLocation(x,null)}; |
257 | protoElement.setY=function(y) {this.setLocation(null,y)}; |
||
258 | protoElement.getX=function() {return this.x||0}; |
||
259 | protoElement.getY=function() {return this.y||0}; |
||
260 | protoElement.setPageX = function(x) {this.setPageLocation(x,null)}; |
||
261 | protoElement.setPageY = function(y) {this.setPageLocation(null,y)}; |
||
262 | protoElement.getVisible=function() {return this.visible}; |
||
263 | protoElement.getZIndex=function() {return this.z}; |
||
264 | protoElement.setZIndex=function(z) { |
||
20 | reyssat | 265 | if (typeof(z)=="object") { |
266 | if (z.above) this.z = z.above.z + 1; |
||
267 | else if (z.below) this.z = z.below.z - 1; |
||
268 | else if (z.topmost && this.parent) { |
||
269 | var topZ=10000,ch=this.parent.children; |
||
270 | for(var i=0;i<ch.length;i++) if (ch[i].z>topZ) topZ=ch[i].z; |
||
271 | this.parent._topZ = topZ+2; |
||
272 | this.z = this.parent._topZ; |
||
273 | } |
||
274 | } |
||
275 | else this.z = z; |
||
276 | if (this.css) this.css.zIndex = this.z; |
||
277 | }; |
||
11521 | obado | 278 | protoElement.getHTML = function() {return this.html}; |
279 | protoElement.setWidth=function(w) {this.setSize(w,null)}; |
||
280 | protoElement.setHeight=function(h) {this.setSize(null,h)}; |
||
281 | protoElement.getWidth=function() {return this.w||0}; |
||
282 | protoElement.getHeight=function() {return this.h||0}; |
||
283 | protoElement.getBgImage=function() {return this.bgImage}; |
||
284 | protoElement.getBgColor=function() {return this.bgColor}; |
||
285 | protoElement.setBgColor=function(c) { //! Overwritten by NS4 |
||
20 | reyssat | 286 | if (c==null) c = 'transparent'; |
287 | this.bgColor = c; |
||
288 | if (this.css) this.css.backgroundColor = c; |
||
289 | }; |
||
11521 | obado | 290 | protoElement.setBgImage=function(path) { //! Overwritten by NS4 |
20 | reyssat | 291 | this.bgImage=path; |
292 | if (this.css) this.css.backgroundImage='url('+path+')'; |
||
293 | }; |
||
11521 | obado | 294 | protoElement.setClip=function(clip) { //! Overwritten by NS4 |
20 | reyssat | 295 | var cc=this.getClip(); |
296 | for (var i=0;i<clip.length;i++) if (clip[i]==null) clip[i]=cc[i]; |
||
297 | this.clip=clip; |
||
298 | if (this.css==null) return; |
||
299 | var c=this.css.clip; |
||
300 | this.css.clip="rect("+clip[0]+"px "+clip[1]+"px "+clip[2]+"px "+clip[3]+"px)"; |
||
301 | }; |
||
11521 | obado | 302 | protoElement.getClip=function() { //! Overwritten by NS4 |
20 | reyssat | 303 | if (this.css==null || !this.css.clip) return [0,0,0,0]; |
304 | var c = this.css.clip; |
||
305 | if (c) { |
||
306 | if (c.indexOf("rect(")>-1) { |
||
307 | c=c.split("rect(")[1].split(")")[0].split("px"); |
||
308 | for (var i=0;i<c.length;i++) c[i]=parseInt(c[i]); |
||
309 | return [c[0],c[1],c[2],c[3]]; |
||
310 | } |
||
311 | else return [0,this.w,this.h,0]; |
||
312 | } |
||
313 | }; |
||
314 | /* |
||
11521 | obado | 315 | protoElement.getElmWidth = function(){ |
20 | reyssat | 316 | var w = parseInt(this.css.width); |
317 | if(isNaN(w)) w=this.getContentWidth(); |
||
318 | return w; |
||
319 | }; |
||
11521 | obado | 320 | protoElement.getElmHeight = function(){ |
20 | reyssat | 321 | var h = parseInt(this.css.height); |
322 | alert(this.css.height) |
||
11521 | obado | 323 | if(isNaN(h)) h=this.getContentWidth(); |
20 | reyssat | 324 | return h; |
325 | }; |
||
326 | */ |
||
11521 | obado | 327 | protoElement.slideTo = function(endx,endy,inc,speed) { |
20 | reyssat | 328 | if (!this._slideActive) { |
329 | var x = this.x||0; |
||
330 | var y = this.y||0; |
||
331 | if (endx==null) endx = x; |
||
332 | if (endy==null) endy = y; |
||
333 | var distx = endx-x; |
||
334 | var disty = endy-y; |
||
335 | if (x==endx && y==endy) return; |
||
336 | var num = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2))/(inc||10)-1; |
||
337 | var dx = distx/num; |
||
338 | var dy = disty/num; |
||
339 | this._slideActive = true; |
||
340 | this._slide(dx,dy,endx,endy,num,this.x,this.y,1,(speed||20)); |
||
341 | } |
||
342 | }; |
||
11521 | obado | 343 | protoElement.slideStop = function() { |
20 | reyssat | 344 | this._slideActive = false; |
345 | //this.invokeEvent('pathcancel'); |
||
346 | }; |
||
11521 | obado | 347 | protoElement._slide = function(dx,dy,endx,endy,num,x,y,i,speed) { |
20 | reyssat | 348 | if (!this._slideActive) this.slideStop(); |
349 | else if (i++ < num) { |
||
350 | this.invokeEvent('pathrun'); |
||
351 | if (this._slideActive) { |
||
352 | x += dx; |
||
353 | y += dy; |
||
354 | this.setLocation(Math.round(x),Math.round(y)); |
||
355 | setTimeout(this+'._slide('+dx+','+dy+','+endx+','+endy+','+num+','+x+','+y+','+i+','+speed+')',speed); |
||
356 | } |
||
357 | //else this.slideStop(); |
||
358 | } |
||
359 | else { |
||
360 | this._slideActive = false; |
||
361 | this.invokeEvent('pathrun'); |
||
362 | this.setLocation(endx,endy); |
||
363 | this.invokeEvent('pathfinish'); |
||
364 | } |
||
11521 | obado | 365 | }; |