[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/phpgwapi/js/dynapi/ext/ -> library.js (source)

   1  /*
   2      DynAPI Distribution
   3      Dynamic Loading extension to dynapi.library
   4  
   5      The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
   6  */
   7  
   8  // begin loading the object
   9  DynAPILibrary.prototype.load = function(n,fn) {
  10      var list = this._queue(n,null,arguments[2]);
  11      //return dynapi.debug.print('going to load: '+list);
  12      if (list.length) {
  13          var s,src;
  14          for (var i=0;i<list.length;i++) {
  15              src = list[i];
  16              s = this.scripts[list[i]];
  17              if (i==list.length-1 && fn!=null) s.fn = fn;
  18              this.loadList[this.loadList.length] = src;
  19          }
  20          this._load();
  21      }
  22      else if (fn) fn();
  23  };
  24  
  25  // reload the object
  26  DynAPILibrary.prototype.reload = function(n,fn,force) {
  27      var s = this.objects[n];
  28      if (s) {
  29          s.loaded = false;
  30          this.load(n,fn,force);
  31      }
  32  };
  33  
  34  // load a script that is not added to the library
  35  DynAPILibrary.prototype.loadScript = function(src,fn) {
  36      if (!this.scripts[src]) {
  37          var n = 'unnamed'+this._c++;
  38          s = this.add(n,src);  // generate a name for the script
  39          s.unnamed = true;
  40          s.fn = null;
  41          s.dep = [];
  42          this.load(n,fn);
  43      }
  44  };
  45  
  46  // reload a script 
  47  DynAPILibrary.prototype.reloadScript = function(src,fn,force) {
  48      var s=this.scripts[src];
  49      if(s) this.load(s.objects[0],fn,force);
  50  }
  51  
  52  // inserts the script element into the page
  53  DynAPILibrary.prototype._load = function() {
  54      if (this.busy) return; // dynapi.debug.print('Library Warning: busy');
  55      else {
  56          if (this.loadIndex<this.loadList.length-1) {
  57              this.busy = true;
  58              this.loadIndex++;
  59              var src = this.loadList[this.loadIndex];
  60              //if (!confirm('load: '+src+' ?')) return;
  61              var rsrc = src + '?'+Math.random();     // random ensures cached files are not loaded
  62              var s = this.scripts[src];
  63              if (dynapi.ua.ns4) {
  64                  // delete the constructors
  65                  for (var j=0;j<s.objects.length;j++) {
  66                      var n = s.objects[j];
  67                      if (dynapi.frame[n]) {
  68                          dynapi.frame[n] = null;
  69                          if (s.pkg) dynapi.frame[s.pkg+'.'+n] = null;
  70                      }
  71                  }
  72                  //NS4 does not like "/" inside the ?name=value
  73                  src=src.replace(/\//g,'+'); //substitute "/" for "+"
  74                  this.elm.src = dynapi._path+'ext/library.html?js='+src;
  75              }
  76              else if (dynapi.ua.ie && (dynapi.ua.v==4 || dynapi.ua.mac)) {
  77                  dynapi.frame.document.body.insertAdjacentHTML('beforeEnd','<script type="text/javascript" language="javascript" src="'+rsrc+'" defer><\/script>');
  78                  this._export(src);
  79              }
  80              else {
  81                  var elm = s.elm = dynapi.frame.document.createElement('script');
  82                  elm.src = rsrc;
  83                  elm.type = 'text/javascript';
  84                  elm.defer = true;
  85                  if (dynapi.ua.ie) {
  86                      elm.C = 0;
  87                      var o = this;
  88                      elm.onreadystatechange = function() {
  89                          elm.C++;
  90                          if (elm.C==2 || elm.readyState=="complete") {  // use 2nd statechange for onload
  91                              o._export(src);
  92                          }
  93                      }
  94                  }
  95                  dynapi.frame.document.getElementsByTagName('head')[0].appendChild(elm);
  96                  
  97                  // I could not find way to know when the script is complete in Moz v0.9.3
  98                  if (dynapi.ua.ns6) setTimeout(this+'._export("'+src+'")',100);
  99              }
 100          }
 101      }
 102  };
 103  
 104  // executed after a script is finished loading, run main() functions
 105  DynAPILibrary.prototype._export = function(src) {
 106      var src = this.loadList[this.loadIndex];
 107      var s = this.scripts[src];
 108      if (s) {
 109          this._register(s);
 110  
 111          // run elm.main)() before global main()
 112          if (dynapi.ua.ns4 && typeof(this.elm.main)=="function") {
 113              this.elm.main();
 114              this.elm.main = null;
 115          }
 116                  
 117          // run global main() if available
 118          if (typeof(main)=="function") {
 119              main();
 120              main = null;
 121          }
 122  
 123          // clear out all functions in the layer's scope
 124          if (dynapi.ua.ns4) {
 125              for (var i in this.elm) {
 126                  if (typeof(this.elm[i])=="function") delete this.elm[i];
 127              }
 128          }
 129          this.busy = false;
 130  
 131          // load next file
 132          this._load();
 133      }
 134      //else return alert('Library Error: unknown script '+src);
 135  };
 136  
 137  // registers the script as loaded, exports the objects
 138  DynAPILibrary.prototype._register = function(s) {
 139      //dynapi.debug.print('loaded "'+s.src+'"');
 140      s.loaded = true;
 141      s.queued = false;
 142      if (!s.unnamed) {
 143          var n,found;
 144          // loop through each object that the script contains
 145          for (var i=0;i<s.objects.length;i++) {
 146              found = false;
 147              n = s.objects[i];
 148                      
 149              // scope local objects in the layer to the DynAPI frame
 150              if (dynapi.ua.ns4 && this.elm && typeof(this.elm[n])!="undefined") {
 151                  dynapi.frame[n] = this.elm[n];
 152                  found = true;
 153              }
 154              else if (typeof(dynapi.frame[n])!="undefined") found = true;
 155              else if (n.indexOf('.')>0) {
 156                  var ns = n.split('.'), o = dynapi.frame, b = false;
 157                  for (var j=0;j<ns.length;j++) {
 158                      o = o[ns[j]];
 159                  }
 160                  if (typeof(o)!="undefined") found = true;
 161              }
 162              else if (typeof(dynapi[n])!="undefined") found = true;
 163              
 164              if (found) {
 165                  if (s.pkg) {
 166                      // make package link: dynapi.api.DynLayer = DynLayer
 167                      if (s.pkg!="dynapi") this.packages[s.pkg][n] = dynapi.frame[n];
 168                      n = s.pkg+'.'+n;
 169                  }
 170                  dynapi.debug.print('loaded ['+n+']');
 171              }
 172              else {
 173                  dynapi.debug.print('Library Error: could not find ['+n+']');
 174              }
 175          }
 176      }
 177      // run handler if available
 178      if (s.fn) {
 179          s.fn();
 180          delete s.fn;
 181      }
 182  };
 183  
 184  // called from /lib/dynapi/library.html to write the <script>, NS4 only
 185  DynAPILibrary.prototype._handleLoad = function(elm) {
 186      var args = dynapi.functions.getURLArguments(elm.src);
 187      var js = args["js"];
 188      if (js) {
 189          js=js.replace(/\+/g,'/'); // convert + to /
 190          if (js.indexOf('http')!=0) {
 191              var l = dynapi.frame.document.location;
 192              if (js.substr(0,1)=='/') js = l.port+'//'+host+src;
 193              else js = dynapi.documentPath+js;
 194          }
 195          elm.document.write('<script type="text/javascript" language="JavaScript" src="'+js+'?r'+Math.random()+'"><\/script>');
 196          elm.document.close();
 197          elm.onload = function() {
 198              dynapi.library._export(js);
 199          }
 200      }
 201  };
 202  
 203  // inserts the layer for NS4, register included scripts
 204  DynAPILibrary.prototype._create = function() {
 205      // ensure a previous main function is wiped out
 206      if (typeof(main)=="function") main = null;
 207          
 208      // register objects from scripts included by dynapi.library.include() or manually
 209      var s,n;
 210      for (var i in this.scripts) {
 211          s = this.scripts[i];
 212          n=s.objects[0];
 213          if(s.pkg=='dynapi.functions') { // used to avoid conflicts with intrinsic objects such as String, Image, Date and Math objects
 214              if(dynapi.functions[n]) this._register(s);
 215          }
 216          else if (s.loaded || (s.objects[0] && dynapi.frame[s.objects[0]])) this._register(s);
 217      }
 218      
 219      // create NS4 layer to load scripts into
 220      if (dynapi.ua.ns4) this.elm = new Layer(0, dynapi.frame);
 221      this.busy = false;
 222      
 223      // load any scripts before proceeding
 224      if (this.loadList.length) {
 225          var s = this.scripts[this.loadList[this.loadList.length-1]];
 226          s.fn = function() {
 227              setTimeout('dynapi._onLoad()',1);
 228          }
 229          this._load();
 230      }
 231      else setTimeout('dynapi._onLoad()',1);
 232  };


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7