Subversion Repositories wimsdev

Rev

Rev 20 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
20 reyssat 1
/*
2
        DynAPI Distribution
3
        DynLayer NS4 Specific Functions
4
 
5
        The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
13573 obado 6
 
20 reyssat 7
        requires: dynapi.api.DynLayerBase
8
*/
9
 
10
p = DynLayer.prototype;
11
p._ns4IPad = '<img src="'+dynapi.library.path+'ext/images/pixel.gif" width="0" height="0">'; // used with blackboard
12
p._remove = function() {
13
        if (this.elm) {
14
                if (!this.parent.doc.recycled) this.parent.doc.recycled=[];
15
                this.parent.doc.recycled[this.parent.doc.recycled.length]=this.elm;
16
                this.elm.visibility="hide";
17
                this.elm = null;
18
                if (this.releaseMouseEvents) this.releaseMouseEvents();
19
                if (this.releaseKeyEvents) this.releaseKeyEvents();
20
        }
21
        /*this.frame = null;
22
        this.bgImage = null;
23
        this.bgColor = null;
24
        this.html = null;
25
        this.z = null;
26
        this.w = null;
27
        this.h = null;
28
        this.elm = null;
29
        this.doc = null;
30
        this.css = null;*/
31
};
32
p._create = function() {
33
        if (this.parent && !this.elm) {
34
                DynElement._flagPreCreate(this);
35
                var parentElement = this.parent.isClass('DynLayer')? this.parent.elm : this.parent.frame;
36
                var elm = new Layer(this.w||0, parentElement);
37
                if(this._noStyle) elm.className=this._className;
38
                else {
39
                        if (this.w) elm.clip.width = this.w;
40
                        if (this.h) elm.clip.height = this.h;
41
                        if (this.x && this.y) elm.moveTo(this.x,this.y);
42
                        else if (this.x) elm.left = this.x;
43
                        else if (this.y) elm.top = this.y;
44
                        if (this.bgColor!=null) elm.document.bgColor = this.bgColor;
45
                        if (this.clip) {
46
                                var c = elm.clip, cl = this.clip;
47
                                c.top=cl[0], c.right=cl[1], c.bottom=cl[2], c.left=cl[3];
48
                        }
49
                        if (this.z) elm.zIndex = this.z;
50
                        if (this.visible) elm.visibility = 'inherit';
51
                }
52
                if (this.children.length || (this.html!=null && this.html!='')) {
53
                        elm.document.write(this.getInnerHTML());
54
                        elm.document.close();
55
                }
56
                DynLayer._assignElement(this,elm);
57
                //if (this.updateLayout) this.updateLayout();
58
                DynElement._flagCreate(this);
59
        }
60
};
61
DynLayer._getLayerById = function(id,pElm){
62
        var i,lyrs,elm;
63
        pElm = (pElm)? pElm:document;
64
        lyrs = pElm.layers;
65
        for (i=0;i<lyrs.length;i++){
66
                elm=lyrs[i];
67
                if (elm.id==id) return elm;
68
                else if (elm.layers.length){
69
                        elm = this._getLayerById(id,elm);
70
                        if (elm) return elm;
13573 obado 71
                }
20 reyssat 72
        }
73
};
74
DynLayer._assignElement = function(dlyr,elm) {
75
        if (!elm) {
76
                elm = dlyr.parent.doc.layers[dlyr.id];
77
                if (!elm) elm=DynLayer._getLayerById(dlyr.id,dlyr.parent.elm);
78
                if (!elm) {dlyr._create();return}; // force create() for missing inline layer
79
        }
80
        dlyr.elm = elm;
81
        dlyr.css = elm;
82
        dlyr.doc = elm.document;
83
        if(dlyr._blkBoardElm) {
84
                dlyr._blkBoardElm = elm.document.layers[dlyr.id+'blkboard'];
85
                dlyr.doc = dlyr._blkBoardElm.document; // useful for <forms>, images, links, etc
86
        }
87
        dlyr.elm._dynobj = dlyr.doc._dynobj = dlyr; //demo
88
        dlyr._dyndoc = dlyr.parent._dyndoc;
89
 
90
        if (dlyr.html!=null && dlyr.html!='' && (dlyr.w==null || dlyr.h==null)) {
91
                var cw = (dlyr.w==null)? dlyr.getContentWidth() : null;
92
                var ch = (dlyr.h==null)? dlyr.getContentHeight() : null;
93
                //var cw = (dlyr.w==null)? dlyr.getElmWidth() : null;
94
                //var ch = (dlyr.h==null)? dlyr.getElmHeight() : null;
95
                dlyr.setSize(cw,ch);
96
        }
97
        if (dlyr.bgImage!=null) dlyr.setBgImage(dlyr.bgImage);
13573 obado 98
 
99
        var i,ch=dlyr.children;
20 reyssat 100
        for (i=0;i<ch.length;i++) DynLayer._assignElement(ch[i],null);
101
 
102
        if (dlyr._hasMouseEvents) dlyr.captureMouseEvents();
103
        if (dlyr._hasKeyEvents) dlyr.captureKeyEvents();
104
};
105
 
106
p.getOuterHTML = function() {
107
        var tag='layer',clip='';
108
        if(this._position=='relative') tag='ilayer';
109
        if(this._noStyle) return '\n<'+tag+' '+this._cssClass+' id="'+this.id+'">'+this.getInnerHTML()+'</'+tag+'>';
110
        else {
111
                if (this.clip) clip=' clip="'+this.clip[3]+','+this.clip[0]+','+this.clip[1]+','+this.clip[2]+'"';
112
                else clip=' clip="0,0,'+((this.w>=0)?this.w:0)+','+((this.h>=0)?this.h:0)+'"';
113
                return [
114
                        '\n<'+tag+' ',this._cssClass,' id="'+this.id+'"',
115
                        ' left=',(this.x!=null? this.x : 0),
116
                        ' top=',(this.y!=null? this.y : 0),
117
                        ((this.visible)? ' visibility="inherit"':' visibility="hide"'),
118
                        ((this.w!=null)? ' width='+this.w:''),
119
                        ((this.h!=null)? ' height='+this.h:''),
13573 obado 120
                        ((this.z)? ' zindex='+this.z:''),
20 reyssat 121
                        ((this.bgColor!=null)? ' bgcolor="'+this.bgColor+'"':''),
13573 obado 122
                        ((this.bgImage!=null)? ' background="'+this.bgImage+'"':''),
20 reyssat 123
                        clip,'>',this.getInnerHTML(),'</'+tag+'>'
124
                ].join('');
125
        }
126
};
127
p.getInnerHTML = function() {
128
        var i,s = '',ch=this.children;
129
        if (this.html!=null) {
130
                if (this.w==null) s += '<nobr>'+this.html+'</nobr>';
131
                else s+=this.html;
132
        }
13573 obado 133
        if (this._blkBoardElm) s='<layer id="'+this.id+'blkboard">'+this._ns4IPad+s+'</layer>';
134
        if(ch.length<50) for (i=0;i<ch.length;i++) s+=ch[i].getOuterHTML();
20 reyssat 135
        else if(ch.length){
136
                var ar=['']; // speed improvement for layers with nested children
137
                for (i=0;i<ch.length;i++) ar[i]=ch[i].getOuterHTML();
13573 obado 138
                s=s+ar.join('');
20 reyssat 139
        }
140
        return s;
141
};
142
p.enableBlackboard = function(){
143
        if (!this._created) this._blkBoardElm=true;
144
        else if(!this._blkBoardElm){
145
                var c,i,h='',elm = this.elm;
13573 obado 146
                if(this.html!=null) h=this.html;
20 reyssat 147
                var parentElement = this.parent.isClass('DynLayer')? this.parent.elm : this.parent.frame;
148
                var belm = this._blkBoardElm = new Layer(0, elm);
149
                this.doc = belm.document;
150
                this.doc.write(h); this.doc.close();
151
                belm.visibility = 'inherit';
152
                for (i=0;i<this.children.length;i++){
153
                        c=this.children[i];
154
                        c.css.zIndex=c.css.zIndex; // reset zindex
13573 obado 155
                }
20 reyssat 156
        }
157
};
158
p.setLocation = function(x,y) {
159
        var cx = (x!=null && x!=this.x);
160
        var cy = (y!=null && y!=this.y);
161
        if (cx) this.x = x||0;
162
        if (cy) this.y = y||0;
163
        if (this.css!=null) {
164
                if (cx && cy) this.elm.moveTo(this.x, this.y);
165
                else if (cx) this.css.left = this.x;
166
                else if (cy) this.css.top = this.y;
167
        }
13573 obado 168
        if(this._hasLocationEvents) this.invokeEvent('locationchange');
20 reyssat 169
        return (cx||cy);
170
};
171
p.setPageLocation = function(x,y) {
172
        if (this.css) {
173
                if (x!=null) {
174
                        this.css.pageX = x;
175
                        this.x = this.css.left;
176
                }
177
                if (y!=null) {
178
                        this.css.pageY = y;
179
                        this.y = this.css.top;
180
                }
181
                return true;
182
        }
183
        else {
184
                if (this.isChild) {
185
                        if (x!=null) x = x - this.parent.getPageX();
186
                        if (y!=null) y = y - this.parent.getPageY();
187
                }
188
                return this.setLocation(x,y);
189
        }
190
};
191
p.getPageX = function() {return this.css? this.css.pageX : null};
192
p.getPageY = function() {return this.css? this.css.pageY : null};
193
p.setVisible = function(b) {
194
        if (b!=this.visible) {
195
                this.visible = b;
196
                if (this.css) this.css.visibility = b? "inherit" : "hide";
197
        }
198
};
199
p.setSize = function(w,h) {
200
        if (this._useMinSize||this._useMaxSize){
201
                if (this._minW && w<this._minW) w=this._minW;
202
                if (this._minH && h<this._minH) h=this._minH;
203
                if (this._maxW && w>this._maxW) w=this._maxW;
204
                if (this._maxH && h>this._maxH) h=this._maxH;
205
        }
206
        var cw = (w!=null && w!=this.w);
207
        var ch = (h!=null && h!=this.h);
208
        if (cw) this.w = w<0? 0 : w;
209
        if (ch) this.h = h<0? 0 : h;
210
        if (cw||ch) {
211
                if (this._hasAnchor) this.updateAnchor(); // update this anchor
212
                if (this._hasChildAnchors) this._updateAnchors(); // update child anchors
213
                if (this.css) {
214
                        if (cw) this.css.clip.width = this.w || 0;
215
                        if (ch) this.css.clip.height = this.h || 0;
216
                        if (this.updateLayout) this.updateLayout();
217
                }
218
        }
219
        if(this._hasResizeEvents) this.invokeEvent('resize');
220
        return (cw||ch);
221
};
222
p.setHTML=function(html) {
223
        var ch = (html!=null && html!=this.html);
224
        if (ch) {
225
                this.html = html;
226
                if (this.css) {
227
                        var i, doc = this.doc;
228
                        var html=(!this._blkBoardElm)? this.html:this._ns4IPad+this.html; // don't ask why! See HTMLContainer
229
                        doc.open();     doc.write(html); doc.close();
230
                        for (i=0;i<doc.images.length;i++) doc.images[i]._dynobj = this;
231
                        for (i=0;i<doc.links.length;i++) doc.links[i]._dynobj = this;
232
                }
233
        }
234
        if(this._hasContentEvents) this.invokeEvent('contentchange');
235
};
236
p.setTextSelectable=function(b) {
237
        this._textSelectable = b;
238
        this.addEventListener({
239
                onmousemove : function(e) {
240
                        e.preventDefault();
241
                }
242
        });
243
        // && this.captureMouseEvents && !this._hasMouseEvents) this.captureMouseEvents();
244
};
245
p.getCursor = function() {return this._cursor};
246
p.setCursor = function(c) {
247
        if (!c) c = 'default';
13573 obado 248
        if (this._cursor!=c) this._cursor = c;
20 reyssat 249
        // Note: not supported in ns4
250
};
251
p.setBgColor=function(c) {
252
        this.bgColor = c;
253
        if (this.css) this.elm.document.bgColor = c;
254
};
255
p.setBgImage=function(path) {
256
        this.bgImage=path||'none';
257
        if (this.css) {
258
                //if (!path) this.setBgColor(this.getBgColor());
259
                setTimeout(this+'.elm.background.src="'+this.bgImage+'"',1);
260
        }
261
};
262
p.getContentWidth=function() {
263
        if (this.elm==null) return 0;
264
        else {
265
                return this.doc.width;
266
        };
267
};
268
p.getContentHeight=function() {
269
        if (this.elm==null) return 0;
270
        else {
271
                return this.doc.height;
272
        }
273
};
274
p.setClip=function(clip) {
275
        var cc=this.getClip();
276
        for (var i=0;i<clip.length;i++) if (clip[i]==null) clip[i]=cc[i];
277
        this.clip=clip;
278
        if (this.css==null) return;
279
        var c=this.css.clip;
280
        c.top=clip[0], c.right=clip[1], c.bottom=clip[2], c.left=clip[3];
281
};
282
p.getClip=function() {
283
        if (this.css==null || !this.css.clip) return [0,0,0,0];
284
        var c = this.css.clip;
285
        if (c) {
286
                return [c.top,c.right,c.bottom,c.left];
287
        }
288
};
289