Subversion Repositories wimsdev

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.    DynAPI Distribution
  3.    LoadPanel Class
  4.    
  5.    The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
  6.  
  7.    Requirements:
  8.         dynapi.api.Dynlayer
  9. */
  10.  
  11. function LoadPanel(url) {
  12.         this.DynLayer = DynLayer;
  13.         this.DynLayer();
  14.  
  15.         this._resizeH=true;
  16.         this._resizeW=false;
  17.         this._elmID = this.id+'_loadElm';
  18.         this._busy = true;
  19.         if (url) this._url = url;
  20.         this.setOverflow('hidden');
  21.  
  22.         this.marginWidth = 5;
  23.         this.marginHeight = 5;
  24.  
  25.         var lp = this;
  26.         this.historyIndex = -1;
  27.         this.history = [];
  28.         this.history.back = function() {
  29.                 if (!lp._busy && lp.historyIndex>0) {
  30.                         lp.historyIndex--;
  31.                         lp.reload();
  32.                 }
  33.         };
  34.         this.history.forward = function() {
  35.                 if (!lp._busy && lp.historyIndex<lp.history.length-1) {
  36.                         lp.historyIndex++;
  37.                         lp.reload();
  38.                 }
  39.         };
  40.  
  41.         this.onPreCreate(LoadPanel.PreCreateEvent);
  42.         this.onCreate(LoadPanel.CreateEvent);
  43. };
  44. LoadPanel.PreCreateEvent = function(e) {
  45.         if (dynapi.ua.ns4) this.html = '<layer left=0 top=0 width='+this.w+' height='+this.h+' name="'+this._elmID+'" visibility="inherit"></layer>';
  46.         else {
  47.                 var html = '<iframe name="'+this._elmID+'" style="width:0px; height:0px; visibility:hidden;"></iframe>';  //visibility: hidden; display: none;
  48.                 this._loadlyr = new DynLayer(html);
  49.                 this._loadlyr.setVisible(false);
  50.                 dynapi.document.addChild(this._loadlyr);
  51.         }
  52. };
  53. LoadPanel.CreateEvent = function(e) {
  54.         if(!dynapi.ua.opera) this._createElm();
  55.         else setTimeout(this+'._createElm();',10); // opera 7 needs this timeout
  56. };
  57.  
  58. var p = LoadPanel.prototype = new DynLayer;
  59. p._createElm = function(e) {
  60.         if (dynapi.ua.ns4) this._loadElm = this.doc.layers[0];
  61.         else this._loadElm = dynapi.frame.frames[this._elmID];
  62.         this._busy = false;
  63.         if (this._url) setTimeout(this+'.setURL("'+this._url+'")', 10);
  64. };
  65. p._DynLayer_setSize = DynLayer.prototype.setSize;
  66. p.setSize = function(w,h) {
  67.         var r = this._DynLayer_setSize(w,h);
  68.         //if (r && this._created && !this._isReloading && this.autoH && this.url) this.reload();
  69. };
  70. p.getURL=function() {
  71.         return this.history[this.historyIndex];
  72. };
  73. p.setURL = function(url, skipHistory) {
  74.         if (typeof(url)=='string') {
  75.                 if (!this._created || this._busy) this._url = url;
  76.                 else {
  77.                         if (skipHistory!=true) {
  78.                                 this.historyIndex++;
  79.                                 this.history[this.historyIndex] = url;
  80.                                 this.history.length = this.historyIndex+1;
  81.                         }
  82.                        
  83.                         var id = Math.random()+'';
  84.                         url += (url.indexOf('?')==-1)? '?' : '&';
  85.                         url += 'rand='+id.substring(2)+'&lpElementID='+this.id;
  86.                        
  87.                         this._busy = true;
  88.                         if (dynapi.ua.ns4) this._loadElm.src = url;
  89.                         else this._loadElm.document.location.href = url;
  90.                 }
  91.         }
  92. };
  93. p.reload = function() {
  94.         this.setURL(this.history[this.historyIndex], true);
  95. };
  96. p.clear = function() {
  97.         this._loadElm.document.write();
  98.         this._loadElm.document.close();
  99.         if (!dynapi.ua.ns4) this.setHTML('');
  100.         this.historyIndex = -1;
  101.         this.history = [];
  102. };
  103. p._notify = function() {
  104.         this._busy = false;
  105.         if (dynapi.ua.ns4) {
  106.                 var elm = this._loadElm;
  107.                 var h = elm.document.height;
  108.                 elm.clip.height = h;
  109.                 elm.clip.width = this.w;
  110.                 this.setHeight(h);
  111.                 setTimeout(this+'.invokeEvent("change")',1);
  112.         }
  113.         else {
  114.                 var html = this._loadElm.document.body.innerHTML;
  115.                 if (html) {
  116.                         this.setHTML(html);
  117.                         setTimeout(this+'._notify2()',10);  // ie/mac needs an extra ms to properly get content height
  118.                 }
  119.         }
  120. };
  121. p._notify2 = function() {
  122.         var h = this.getContentHeight();
  123.         if (!h) setTimeout(this+'._notify2()',200);
  124.         this.setHeight(h);
  125.         var bg = this._loadElm.document.bgColor;
  126.         if (bg) this.setBgColor(bg);
  127.         setTimeout(this+'.invokeEvent("change")',1);
  128. };
  129. LoadPanel.notify = function(elm) {
  130.         var url,id,obj;
  131.         if (dynapi.ua.ns4) url = elm.src;
  132.         else url = elm.document.location.href;
  133.        
  134.         var args = dynapi.functions.getURLArguments(url);
  135.         obj = DynObject.all[args["lpElementID"]];
  136.        
  137.         if (obj!=null) {
  138.                 elm.onload = function() {
  139.                         setTimeout(obj+'._notify("'+id+'","'+url+'")',100);
  140.                 };
  141.                 return obj; // returns loadpanel to the page
  142.         }
  143.         else {
  144.                 return false; // error
  145.         }
  146. };
  147.