[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 /* 2 DynAPI Distribution 3 DynDocument Class 4 5 The DynAPI Distribution is distributed under the terms of the GNU LGPL license. 6 7 requires: dynapi.api.DynElement 8 */ 9 10 function DynDocument(frame) { 11 this.DynElement = DynElement; 12 this.DynElement(); 13 this.frame = frame; 14 this.doc = this.frame.document; 15 this._dyndoc = this; 16 this.x = 0; 17 this.y = 0; 18 this.w = 0; 19 this.h = 0; 20 this._topZIndex = 10000; 21 var o = this; 22 this.frame.onresize = function() {o._handleResize()}; 23 this.onResizeNS4 = "reload"; // or "redraw" 24 this._created = false; 25 }; 26 var p = dynapi.setPrototype('DynDocument','DynElement'); 27 p._remove = function() { 28 this.elm=null; 29 this.doc=null; 30 this.frame=null; 31 }; 32 p.getBgColor = function() { 33 return this.bgColor; 34 }; 35 p.getX = p.getY = p.getPageX = p.getPageY = dynapi.functions.Zero; 36 p.getWidth = function() { 37 if (!this.w) this.findDimensions(); 38 return this.w; 39 }; 40 p.getHeight = function() { 41 if (!this.h) this.findDimensions(); 42 return this.h; 43 }; 44 p.getXScroll = function () 45 { 46 return (dynapi.ua.ns)? this.frame.pageXOffset : this.elm.scrollLeft; 47 } 48 p.getYScroll = function () 49 { 50 return (dynapi.ua.ns)? this.frame.pageYOffset : this.elm.scrollTop; 51 } 52 p.findDimensions = function() { 53 this.w=(dynapi.ua.ns||dynapi.ua.opera)? this.frame.innerWidth : (dynapi.ua.ie6) ? 54 this.doc.documentElement.clientWidth : this.elm.clientWidth; 55 this.h=(dynapi.ua.ns||dynapi.ua.opera)? this.frame.innerHeight : (dynapi.ua.ie6) ? 56 this.doc.documentElement.clientHeight : this.elm.clientHeight; 57 }; 58 p.setBgColor = function(color) { 59 if (color == null) color=''; 60 if (dynapi.ua.ns4 && color == '') color = '#ffffff'; 61 this.bgColor = color; 62 this.doc.bgColor = color; 63 }; 64 p.setFgColor = function(color) { 65 if (color == null) color=''; 66 if (dynapi.ua.ns4 && color == '') color='#ffffff'; 67 this.fgColor = color; 68 this.doc.fgColor = color; 69 }; 70 p.insertChild = function(c,pos,usebp) { // Blueprint Enabled 71 if (c && !c.isInline && c.parent == this) { 72 if(pos) c.setPosition(pos); 73 DynElement._flagPreCreate(c); 74 if(usebp) 75 c.isInline=c._noInlineValues=true; 76 else { 77 this.doc.write(c.getOuterHTML()); 78 c._inserted = true; 79 } 80 } 81 }; 82 p.insertAllChildren = function(usebp,bpSrc) { // Blueprint Enabled 83 var i,c,str =['']; 84 var ch=this.children; 85 for(i=0;i<ch.length;i++) { 86 c = ch[i]; 87 if(!c.isInline && !c._inserted){ 88 DynElement._flagPreCreate(c); 89 if(usebp) 90 c.isInline=c._noInlineValues=true; 91 else { 92 str[i]=c.getOuterHTML(); 93 c._inserted = true; 94 } 95 } 96 } 97 if(this._hBuffer.length) this.doc.write(this._hBuffer.join('')); // used by addHTML() 98 if(usebp){ 99 if(bpSrc) dynapi.frame.document.write('<script type="text/javascript" language="JavaScript" src="'+bpSrc+'"><\/script>'); 100 } 101 else { 102 this.doc.write(str.join('\n')); 103 this.doc.close(); 104 } 105 }; 106 107 p._create = function() { 108 var ua=dynapi.ua; 109 this._created = true; 110 if (ua.ns4) { 111 this.css = this.doc; 112 this.elm = this.doc; 113 } 114 else { 115 this.elm = this.frame.document.body; 116 this.css = this.frame.document.body.style; 117 if (ua.ie) { 118 this._overflow = this.css.overflow || ''; 119 } 120 if (this._cursor) this.css.cursor = this._cursor; 121 } 122 this.elm._dynobj = this; 123 this.doc._dynobj = this; // DynKeyEvent needs this! 124 this.findDimensions(); 125 126 this.fgColor = this.doc.fgColor||''; 127 this.bgColor = this.doc.bgColor||''; 128 129 var divs; 130 // create divs object - speeds up DOM browsers on Win32. Linux & Mac? 131 if (ua.ie||ua.dom) { 132 divs={}; 133 var dv,all=(ua.ie||ua.opera)? document.all.tags('div') : document.getElementsByTagName('div'); 134 var i=0,l=all.length; // very important! 135 while (i<l){ 136 dv=all[i]; 137 divs[dv.id]=dv; 138 i++; 139 } 140 } 141 142 var c,ch=this.children; 143 for(i=0;i<ch.length;i++){ 144 c=ch[i]; 145 if (c._inserted) c._createInserted(divs); 146 else if(c.isInline) c._createInline(divs); 147 else c._create(); 148 }; 149 this._updateAnchors(); 150 151 if(ua.ie && this._textSelectable==false) this.doc.onselectstart = dynapi.functions.Deny; 152 153 if (this.captureMouseEvents) this.captureMouseEvents(); 154 if (this.captureKeyEvents) this.captureKeyEvents(); 155 this.invokeEvent('load'); 156 }; 157 p.destroyAllChildren = function() { 158 for (var i=0;i<this.children.length;i++) { 159 this.children[i]._destroy(); 160 delete this.children[i]; 161 } 162 this.children = []; 163 }; 164 p._destroy = function() { 165 this.destroyAllChildren(); 166 delete DynObject.all; 167 this.elm = null; 168 this.css = null; 169 this.frame = null; 170 }; 171 172 p._handleResize = function() { 173 var w = this.w; 174 var h = this.h; 175 this.findDimensions(); 176 if (this.w!=w || this.h!=h) { 177 if (dynapi.ua.ns4) { 178 if (this.onResizeNS4=="redraw") { 179 for (var i=0;i<this.children.length;i++) { 180 this.children[i].elm = null; 181 if (this.children[i]._created) { 182 this.children[i]._created = false; 183 this.children[i]._create(); 184 } 185 } 186 this.invokeEvent('resize'); 187 } 188 else if (this.onResizeNS4=="reload") { 189 this.doc.location.href = this.doc.location.href; 190 } 191 } 192 else { 193 this.invokeEvent('resize'); 194 this._updateAnchors(); 195 } 196 } 197 }; 198 p.getCursor = function() {return (this._cursor=='pointer')? 'hand':this._cursor}; 199 p.setCursor = function(c) { 200 if (!c) c = 'default'; 201 else c=(c+'').toLowerCase(); 202 if (!dynapi.ua.ie && c=='hand') c='pointer'; 203 if (this._cursor!=c) { 204 this._cursor = c; 205 if (this.css) this.css.cursor = c; 206 } 207 }; 208 p.setTextSelectable = function(b){ 209 this._textSelectable = b; 210 if(!dynapi.ua.ie) this.captureMouseEvents(); 211 else{ 212 if (this.doc) this.doc.onselectstart = b? dynapi.functions.Allow : dynapi.functions.Deny; 213 } 214 if (!b) this.setCursor('default'); 215 }; 216 p.showScrollBars = function(b){ 217 if(b==this._showScroll) return; 218 else this._showScroll=b; 219 if(dynapi.ua.ie){ 220 window.setTimeout('document.body.scroll="'+((b)? 'yes':'no')+'"',100); 221 }else if(dynapi.ua.ns||dynapi.ua.opera){ 222 if(b){ 223 this._docSize=[document.width,document.height]; 224 document.width = this.frame.innerWidth; 225 document.height = this.frame.innerHeight; 226 }else if(this._docSize){ 227 document.width = this._docSize[0]; 228 document.height = this._docSize[1]; 229 } 230 } 231 }; 232 p.writeStyle = function(s){ 233 // note: don't ever add \n to the end of the following strings or ns4 will choke! 234 if(!s) return; 235 var css ='<style><!-- '; 236 for(var i in s) css +='.'+i+' {'+s[i]+';} '; 237 css += ' --></style>'; 238 document.write(css); 239 }; 240 241 p._hBuffer = []; 242 p.addHTML = function(html){ 243 var elm,ua = dynapi.ua; 244 var hbuf=this._hBuffer; 245 var cnt=(this._hblc)? this._hblc++:(this._hblc=1); 246 if (ua.ns4) { 247 html='<nobr>'+html+'<nobr>'; 248 if(!this._created) hbuf[cnt]=html; 249 else { 250 elm=new Layer(0,this.frame); 251 elm.left=elm.top=0; 252 var doc=elm.document; 253 elm.clip.width=dynapi.document.w; 254 elm.clip.height=dynapi.document.h; 255 doc.open();doc.write(html);doc.close(); 256 elm.visibility = 'inherit'; 257 } 258 } 259 else { 260 var pelm=this.elm; 261 if(!this._created) hbuf[cnt]=html; 262 else { 263 if(ua.ie){ 264 pelm.insertAdjacentHTML("beforeEnd",html); 265 elm = pelm.children[pelm.children.length-1]; 266 } 267 else{ 268 var r = pelm.ownerDocument.createRange(); 269 r.setStartBefore(pelm); 270 var ptxt = r.createContextualFragment(html); 271 pelm.appendChild(ptxt); 272 elm = pelm.lastChild; 273 } 274 } 275 } 276 }; 277 278 function main() { 279 if (dynapi.document==null) { 280 dynapi.document = new DynDocument(dynapi.frame); 281 if (dynapi.loaded) dynapi.document._create(); 282 else dynapi.onLoad(function() { 283 dynapi.document._create(); 284 }); 285 } 286 }; 287 if (!dynapi.loaded) main(); 288
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |