Subversion Repositories wimsdev

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.         DynAPI Distribution
  3.         HTMLContainer Class
  4.  
  5.         The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
  6.        
  7.         Requires: HTMLComponent
  8. */
  9.  
  10. function HTMLContainer(css,html,w,h){
  11.         this.HTMLComponent = HTMLComponent;
  12.         this.HTMLComponent(css);       
  13.        
  14.         this.w=w; this.h=h;
  15.         this.html=html||'';
  16. };
  17. var p = dynapi.setPrototype('HTMLContainer','HTMLComponent');
  18. p._ns4IPad='<img src="'+dynapi.library.path+'ext/images/pixel.gif" width="0" height="0">';
  19. p._assignElm = function(elm){
  20.         if(!this.parent) return;
  21.         else if(!this.parent._created) return;
  22.         var id=this.id+'HTC';
  23.         var doc=this.parent.doc;
  24.         if(elm) elm;   
  25.         else if(dynapi.ua.ie) elm=doc.all[id];
  26.         else if(dynapi.ua.dom) elm=doc.getElementById(id);
  27.         else if(dynapi.ua.ns4) {
  28.                 this._ns4ielm=doc.layers[id];
  29.                 elm =this._ns4ielm.document.layers[id+'L'];
  30.                 this._ns4ielm.clip.width=elm.document.width;
  31.                 this._ns4ielm.clip.height=elm.document.height;
  32.         }
  33.         if(!elm) return;
  34.         this.elm = elm;
  35.         this.css = (dynapi.ua.ns4)? elm:elm.style;
  36.         this.doc = elm.document;
  37. };
  38. p.getInnerHTML = function(){
  39.         var h,html = this.html;
  40.         if(dynapi.ua.ns4) {
  41.                 if(this.w==null) html='<nobr>'+html+'</nobr>';
  42.                 h='\n<ilayer visibility="inherit" id="'+this.id+'HTC" '
  43.                 +((this.w)? ' width="'+this.w+'"':'')
  44.                 +((this.h)? ' height="'+this.h+'"':'')
  45.                 +'><layer id="'+this.id+'HTCL">'+this._ns4IPad+html+'</layer></ilayer>';
  46.                 /* NS4 iLayer seems to be having a problem when you're trying to update the content of the layer
  47.                 so a layer was used to support document.write() method after page load.
  48.                 I've also noticed that at times <layer> will not display a <table> it's nested inside another table.
  49.                 for example <table><tr><td><ilayer><layer><table><tr><td>Content</td></tr></table></layer></ilayer></td></tr></table>
  50.                 the _ns4IPad will keep things in tact. *sigh* - NS4!!!! */
  51.         }
  52.         else {
  53.                 h='<div class="'+this._class+'" id="'+this.id+'HTC" style="'
  54.                 +((this.w)? ' width:'+this.w+'px;':'')
  55.                 +((this.h)? ' height:'+this.h+'px;':'')
  56.                 +'">'+html+'</div>';           
  57.         }
  58.         return h;
  59. };
  60. p.setHTML = function(html){
  61.         if(this.html==html) return;
  62.         this.html=html
  63.         if(this.getElm()){
  64.                 if(dynapi.ua.ie) this.elm.innerHTML=html; // ok?
  65.                 else if(dynapi.ua.dom) {
  66.                         var elm = this.elm;
  67.                         elm.innerHTML = html;          
  68.                         var sTmp=(this.w==null)? '<nobr>'+this.html+'</nobr>':this.html;
  69.                         while (elm.hasChildNodes()) elm.removeChild(elm.firstChild);
  70.                         var r=elm.ownerDocument.createRange();
  71.                         r.selectNodeContents(elm);
  72.                         r.collapse(true);
  73.                         var df=r.createContextualFragment(sTmp);
  74.                         elm.appendChild(df);
  75.                 }else {
  76.                         var doc=this.doc;
  77.                         if(this.w==null) html='<nobr>'+html+'</nobr>';
  78.                         doc.open(); doc.write(this._ns4IPad+html); doc.close();
  79.                         this._ns4ielm.clip.width=doc.width;
  80.                         this._ns4ielm.clip.height=doc.height;
  81.                 }
  82.         }
  83. };