Subversion Repositories wimsdev

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.         DynAPI Distribution
  3.         DynLayer DOM Specific Functions
  4.  
  5.         The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
  6.        
  7.         requires: dynapi.api.DynLayerBase
  8. */
  9.  
  10. p = DynLayer.prototype;
  11. p._create = function() {
  12.         if (this.parent && !this.elm) {
  13.                 DynElement._flagPreCreate(this);
  14.                 var elm, parentElement;
  15.                 parentElement = this.parent.elm;
  16.                
  17.                 // this method seems faster for most dom browsers
  18.                 var r = parentElement.ownerDocument.createRange();
  19.                 r.setStartBefore(parentElement);
  20.                 var ptxt = r.createContextualFragment(this.getOuterHTML());
  21.                 parentElement.appendChild(ptxt);
  22.                 elm = parentElement.lastChild;
  23.  
  24.                 DynLayer._assignElement(this,elm);
  25.                 DynElement._flagCreate(this);
  26.         }
  27. };
  28. DynLayer._assignElement = function(dlyr,elm,divs) {
  29.         if (!elm ) {
  30.                 elm = (divs)? divs[dlyr.id] : dlyr.parent.doc.getElementById(dlyr.id);
  31.                 if (!elm) {dlyr._create();return}; // force create() for missing inline layer
  32.         }
  33.         dlyr.elm = elm;
  34.         dlyr.css = elm.style;
  35.         dlyr.doc = dlyr.parent.doc;
  36.         dlyr.elm._dynobj = dlyr;
  37.         dlyr._dyndoc = dlyr.parent._dyndoc;
  38.         if(dlyr._blkBoardElm) dlyr._blkBoardElm = (divs)? divs[dlyr.id+'_blkboard'] : dlyr.parent.doc.getElementById(dlyr.id+'_blkboard');
  39.  
  40.         if (dlyr.z) dlyr.css.zIndex = dlyr.z;
  41.  
  42.         if (dlyr.html!=null && dlyr.html!='' && (dlyr.w==null || dlyr.h==null)) {
  43.                 var cw = (dlyr.w==null)? dlyr.getContentWidth() : null;
  44.                 var ch = (dlyr.h==null)? dlyr.getContentHeight() : null;
  45.                 //var cw = (dlyr.w==null)? dlyr.getElmWidth() : null;
  46.                 //var ch = (dlyr.h==null)? dlyr.getElmHeight() : null;
  47.                 dlyr.setSize(cw,ch);
  48.         }
  49.  
  50.         var i,ch=dlyr.children;
  51.         for (i=0;i<ch.length;i++) DynLayer._assignElement(ch[i],null,divs);
  52.  
  53.         if (dlyr._hasMouseEvents) dlyr.captureMouseEvents();
  54.         if (dlyr._hasKeyEvents) dlyr.captureKeyEvents();
  55.  
  56. };
  57. p.enableBlackboard = function(){
  58.         if (!this._created) this._blkBoardElm=true;
  59.         else if(!this._blkBoardElm){
  60.                 var r,ptxt;
  61.                 var h='',elm = this.elm;
  62.                 if(this.html!=null) h=this.html;
  63.                 r = elm.ownerDocument.createRange();
  64.                 r.setStartBefore(elm);
  65.                 ptxt = r.createContextualFragment('<div id="'+this.id+'_blkboard">'+h+'</div>');
  66.                 elm.appendChild(ptxt);
  67.                 this._blkBoardElm = elm.lastChild;             
  68.         }
  69. };
  70. p.setLocation=function(x,y) {
  71.         var cx = (x!=null && x!=this.x);
  72.         var cy = (y!=null && y!=this.y);
  73.         if (cx) this.x = x||0;
  74.         if (cy) this.y = y||0;
  75.         if (this.css!=null) {
  76.                 if (cx) this.css.left = this.x+"px";
  77.                 if (cy) this.css.top = this.y+"px";
  78.         }
  79.         if(this._hasLocationEvents) this.invokeEvent('locationchange');
  80.         return (cx||cy);
  81. };
  82. p.setPageLocation = function(x,y) {
  83.         if (this.isChild) {
  84.                 if (x!=null) x = x - this.parent.getPageX();
  85.                 if (y!=null) y = y - this.parent.getPageY();
  86.         }
  87.         return this.setLocation(x,y);
  88. };
  89. p.setHTML = function(html) {
  90.         if (html!=this.html) {
  91.                 this.html = html;
  92.                 if (this.css) {
  93.                         var elm = (this._blkBoardElm)? this._blkBoardElm:this.elm;
  94.                         elm.innerHTML = html;          
  95.                         var sTmp=(this.w==null)?'<NOBR>'+this.html+'</NOBR>':this.html;
  96.                         while (elm.hasChildNodes()) elm.removeChild(elm.firstChild);
  97.                         var r=elm.ownerDocument.createRange();
  98.                         r.selectNodeContents(elm);
  99.                         r.collapse(true);
  100.                         var df=r.createContextualFragment(sTmp);
  101.                         elm.appendChild(df);
  102.                 }
  103.         }
  104.         if(this._hasContentEvents) this.invokeEvent('contentchange');  
  105. };
  106. p.setTextSelectable=function(b) {
  107.         this._textSelectable = b;
  108.         if(!this._hasMouseEvents) this.captureMouseEvents();
  109.         if (!b) this.setCursor('default');
  110. };
  111. p.getCursor = function() {return (this._cursor=='pointer')? 'hand':this._cursor};
  112. p.setCursor = function(c) {
  113.         if (!c) c = 'default';
  114.         else c=(c+'').toLowerCase();
  115.         if (c=='hand') c='pointer';
  116.         if (this._cursor!=c) {
  117.                 this._cursor = c;
  118.                 if (this.css) this.css.cursor = c;
  119.         }              
  120. };
  121. p.getContentWidth=function() {
  122.         if (this.elm==null) return 0;
  123.         else {
  124.                 var tw = this.elm.style.width;
  125.                 this.elm.style.width = "auto";
  126.                 var w = this.elm.offsetWidth;
  127.                 this.elm.style.width = tw;
  128.                 return w;
  129.         };
  130. };
  131. p.getContentHeight=function() {
  132.         if (this.elm==null) return 0;
  133.         else {
  134.                 var th = this.elm.style.height;
  135.                 this.elm.style.height = "auto";
  136.                 var h = this.elm.offsetHeight;
  137.                 this.elm.style.height = th;
  138.                 return h;
  139.         }
  140. };
  141.