[ 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/ -> dynapi.js (source)

   1  /*
   2      DynAPI Distribution
   3      DynObject, DynAPI Object, UserAgent, Library, Functions
   4  
   5      The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
   6  */
   7  
   8  function DynObject() {
   9      this.id = "DynObject"+DynObject._c++;
  10      DynObject.all[this.id] = this;
  11  };
  12  var p = DynObject.prototype;
  13  p.getClassName = function() {return this._className};
  14  p.getClass = function() {return dynapi.frame[this._className]};
  15  p.isClass = function(n) {return DynObject.isClass(this._className,n)};
  16  p.addMethod = function(n,fn) {this[n] = fn};
  17  p.removeMethod = function(n) {this[n] = null};
  18  p.setID = function(id,isInline,noImports) {
  19      if (this.id) delete DynObject.all[this.id];
  20      this.id = id;
  21      this.isInline=isInline;
  22      this._noInlineValues=noImports;
  23      DynObject.all[this.id] = this;
  24  };
  25  p.toString = function() {return "DynObject.all."+this.id};
  26  DynObject.all = {};
  27  DynObject._c = 0;
  28  DynObject.isClass = function(cn,n) {
  29      if (cn == n) return true;
  30      else {
  31          var c = dynapi.frame[cn];
  32          var p = c.prototype._pClassName;
  33          if (p) return DynObject.isClass(p,n);
  34          else return false;
  35      }
  36  };
  37  
  38  function _UserAgent() {
  39      var b = navigator.appName;
  40      var v = this.version = navigator.appVersion;
  41      var ua = navigator.userAgent.toLowerCase();    
  42      this.v = parseInt(v);
  43      this.safari = ua.indexOf("safari")>-1;    // always check for safari & opera 
  44      this.opera = ua.indexOf("opera")>-1;    // before ns or ie
  45      this.ns = !this.opera && !this.safari && (b=="Netscape");
  46      this.ie = !this.opera && (b=="Microsoft Internet Explorer");
  47      this.gecko = ua.indexOf('gecko')>-1; // check for gecko engine
  48      if (this.ns) {
  49          this.ns4 = (this.v==4);
  50          this.ns6 = (this.v>=5);
  51          this.b = "Netscape";
  52      }else if (this.ie) {
  53          this.ie4 = this.ie5 = this.ie55 = this.ie6 = false;
  54          if (v.indexOf('MSIE 4')>0) {this.ie4 = true; this.v = 4;}
  55          else if (v.indexOf('MSIE 5')>0) {this.ie5 = true; this.v = 5;}
  56          else if (v.indexOf('MSIE 5.5')>0) {this.ie55 = true; this.v = 5.5;}
  57          else if (v.indexOf('MSIE 6')>0) {this.ie6 = true; this.v = 6;}
  58          this.b = "MSIE";
  59      }else if (this.opera) {
  60          this.v=parseInt(ua.substr(ua.indexOf("opera")+6,1)); // set opera version
  61          this.opera6=(this.v>=6);
  62          this.opera7=(this.v>=7);
  63          this.b = "Opera";
  64      }else if (this.safari) {
  65          this.ns6 = (this.v>=5);    // ns6 compatible correct?
  66          this.b = "Safari";
  67      }
  68      this.dom = (document.createElement && document.appendChild && document.getElementsByTagName)? true : false;
  69      this.def = (this.ie||this.dom);
  70      this.win32 = ua.indexOf("win")>-1;
  71      this.mac = ua.indexOf("mac")>-1;
  72      this.other = (!this.win32 && !this.mac);
  73      this.supported = (this.def||this.ns4||this.ns6||this.opera)? true:false;
  74      this.broadband=false;
  75      this._bws=new Date; // bandwidth timer start 
  76  
  77      // Extended by Raphael Derosso Pereira
  78      this.ua = this.safari ? 'safari' : this.opera ? 'opera' : this.ie ? 'ie' : this.gecko ? 'gecko' : this.ns ? 'ns' : 'unknown';
  79  };
  80  
  81  function DynAPIObject() {
  82      this.DynObject = DynObject;
  83      this.DynObject();
  84  
  85      this.version = '3.0.0 Beta 1';
  86      this.loaded = false;
  87  
  88      this.ua = new _UserAgent();
  89  
  90      this._loadfn = [];
  91      this._unloadfn = [];
  92      var f = this.frame = window;
  93  
  94      var url = f.document.location.href;
  95      url = url.substring(0,url.lastIndexOf('/')+1);
  96      this.documentPath = url;
  97  
  98      var o = this;
  99  
 100      this.library = {};
 101      this.library.setPath = function(p) {o.library.path = p};
 102  
 103      f.onload = function() {
 104          o.loaded = true;
 105          if (!o.ua.supported) return alert('Unsupported Browser. Exiting.');
 106          if (o.library._create) o.library._create();  // calls dynapi._onLoad() after loading necessary files
 107          else setTimeout(o+'._onLoad()',1);
 108      };
 109      f.onunload = function() {
 110          for (var i=0;i<o._unloadfn.length;i++) o._unloadfn[i]();
 111          if (o.document) {
 112              o.document._destroy();
 113              o.document = null;
 114          }
 115      };
 116  };
 117  p = DynAPIObject.prototype = new DynObject;
 118  
 119  p.onLoad = function(f) {
 120      if (typeof(f)=="function") {
 121          if (!this.loaded) this._loadfn[this._loadfn.length] = f;
 122          else f();
 123      }
 124  };
 125  p._onLoad = function(f) {
 126      for (var i=0;i<this._loadfn.length;i++) this._loadfn[i]();
 127  };
 128  p.onUnload = function(f) {
 129      if (typeof(f)=="function") this._unloadfn[this._unloadfn.length] = f;
 130  };
 131  p.setPrototype = function(sC,sP) {
 132      var c = this.frame[sC];
 133      var p = this.frame[sP];
 134      if ((!c || !p) && this.ua.ns4 && this.library && this.library.elm) {
 135          if (!c) c = this.library.elm[sC];
 136          if (!p) p = this.library.elm[sP];
 137      }
 138      if (!c || !p) return alert('Prototype Error');
 139      c.prototype = new p();
 140      c.prototype._className = sC;
 141      c.prototype._pClassName = sP;
 142      c.toString = function() {return '['+sC+']'};
 143      return c.prototype;
 144  };
 145  
 146  var dynapi = new DynAPIObject();
 147  
 148  dynapi.ximages={'__xCnTer__':0}; // eXtensible Images
 149  p._imageGetHTML=function(){
 150      t= '<img src="'+this.src+'"'
 151      +((this.width)? ' width="'+this.width+'"':'')
 152      +((this.height)? ' height="'+this.height+'"':'')
 153      +' border="0">';
 154      return t;
 155  };
 156  
 157  dynapi.functions = {
 158      removeFromArray : function(array, index, id) {
 159          // This seems to be wrong!
 160          // Commented out by Raphael Derosso Pereira
 161          //var which=(typeof(index)=="object")?index:array[index];
 162          var which = index;
 163          if (id) delete array[which.id];
 164          else for (var i=0; i<array.length; i++) {
 165              if (array[i]==which) {
 166                  if(array.splice) array.splice(i,1);
 167                  else {    
 168                      for(var x=i; x<array.length-1; x++) array[x]=array[x+1];
 169                       array.length -= 1; 
 170                   }
 171                  break;
 172              }
 173          }
 174          return array;
 175      },
 176      removeFromObject : function(object, id) {
 177          if(!dynapi.ua.opera) delete object[id];
 178          else {
 179              var o={};
 180              for (var i in object) if(id!=i) o[i]=object[i];
 181              object=o;
 182          }
 183          return object;
 184      },
 185      True : function() {return true},
 186      False : function() {return false},
 187      Null : function() {},
 188      Zero : function() {return 0;},
 189      Allow : function() {
 190          event.cancelBubble = true;
 191          return true;
 192      },
 193      Deny : function() {
 194          event.cancelBubble = false;
 195          return false;
 196      },
 197      getImage : function(src,w,h) {
 198          img=(w!=null&&h!=null)? new Image(w,h) : new Image();
 199          img.src=src;
 200          img.getHTML=dynapi._imageGetHTML;
 201          return img;
 202      },
 203      getURLArguments : function(o) {  // pass a string or frame/layer object
 204          var url,l={};
 205          if (typeof(o)=="string") url = o;
 206          else if (dynapi.ua.ns4 && o.src) url = o.src;
 207          else if (o.document) url = o.document.location.href;
 208          else return l;
 209          var s = url.substring(url.indexOf('?')+1);
 210          var a = s.split('&');
 211          for (var i=0;i<a.length;i++) {
 212              var b = a[i].split('=');
 213              l[b[0]] = unescape(b[1]);
 214          }
 215          return l;
 216      },
 217      getAnchorLocation : function(a,lyr){
 218          var o,x=0,y=0;
 219          if(lyr && !lyr.doc) lyr=null;
 220          lyr=(lyr)? lyr:{doc:document,elm:document};
 221          if(typeof(a)=='string') {
 222              if(lyr.doc.all) a=lyr.doc.all[a];
 223              else if(lyr.doc.getElementById) a=lyr.doc.getElementById(a);
 224              else if(lyr.doc.layers) a=lyr.doc.anchors[a];
 225          }
 226          if(a) o=a;
 227          else return;
 228          if(lyr.doc.layers) { y+=o.y; x+=o.x;}
 229          else if(lyr.doc.getElementById || lyr.doc.all){
 230              while (o.offsetParent && lyr.elm!=o){
 231                  x+= o.offsetLeft;y+= o.offsetTop;
 232                  o = o.offsetParent;
 233              }
 234          }
 235          return {x:x,y:y,anchor:a};
 236      }
 237  };
 238  
 239  dynapi.documentArgs = dynapi.functions.getURLArguments(dynapi.frame);
 240  
 241  dynapi.debug = {};
 242  dynapi._debugBuffer = '';
 243  dPrint=function(s){var d=dynapi.debug; d.print(s)};
 244  dynapi.debug.print = function(s) {
 245      //@IF:DEBUG[
 246          if(s==null) s='';
 247          dynapi._debugBuffer += s + '\n';
 248      //]:DEBUG
 249  };
 250  
 251  // The DynAPI library system is optional, this can be removed if you want to include other scripts manually
 252  function DynAPILibrary() {
 253      this.DynObject = DynObject;
 254      this.DynObject();
 255  
 256      // list of js files: this.scripts['../src/api/dynlayer_ie.js'] = {dep, objects, pkg, fn};
 257      this.scripts = {};
 258  
 259      // list of package names: this.packages['dynapi.api'] = dynapi.api = {_objects,_path}
 260      this.packages = {};
 261  
 262      // list of object names: this.objects['DynLayer'] = this.scripts['../src/api/dynlayer_ie.js']
 263      this.objects = {};
 264  
 265      this._c = 0;
 266      this.loadList = [];
 267      this.loadIndex = -1;
 268      this.path = null;
 269      this.busy = true;
 270  };
 271  p = dynapi.setPrototype('DynAPILibrary','DynObject');
 272  
 273  // can return a path specific to a package, eg. dynapi.library.getPath('dynapi.api') returns '/src/dynapi/api/'
 274  p.getPath = function(pkg) {
 275      if (!pkg) pkg = 'dynapi';
 276      if (this.packages[pkg]) return this.packages[pkg]._path;
 277      return null;
 278  };
 279  
 280  // set dynapi path
 281  p.setPath = function(p,pkgFile) {
 282      this.path = p;
 283  
 284      // to-do: rearrange so add()'s can be done before setPath
 285      //        full paths will then be determined when queued
 286      //        need an extra argument on addPackage to specify whether the path is relative to this.path or not
 287      // OR:    add functionality so that these package definitions can be loaded/included on the fly
 288      
 289      // load pkgFile or 'ext/packages.js' file
 290      var s='<script type="text/javascript" language="JavaScript" src="'
 291      +((pkgFile)? pkgFile:p+'ext/packages.js')+'"><\/script>';
 292      document.write(s);
 293  };
 294  
 295  // adds package(s) to the library
 296  p.addPackage = function(pkg, path) {
 297      var ps;
 298      if (pkg.indexOf('.')) ps = pkg.split('.');
 299      else ps = [pkg];
 300  
 301      var p = dynapi.frame;
 302      for (var i=0;i<ps.length;i++) {  // returns the package object (eg. dynapi.api), or creates it if non-existant
 303          if (!p[ps[i]]) p[ps[i]] = {};
 304          p = p[ps[i]];
 305      }
 306      this.packages[pkg] = p;
 307      p._objects = [];
 308      p._path = path;
 309      return p;
 310  };
 311  
 312  // add object(s) to the library
 313  p.add = function(name, src, dep, relSource) {
 314      var objects = typeof(name)=="string"? [name] : name;
 315      dep = (!dep)? [] : typeof(dep)=="string"? [dep] : dep;
 316  
 317      var s,p,pkg;
 318      if (objects[0].indexOf('.')) {
 319          pkg = objects[0].substring(0,objects[0].lastIndexOf('.'));
 320          if (pkg && this.packages[pkg]) {
 321              p = this.packages[pkg];
 322              if (relSource!=false) src = p._path + src;
 323          }
 324      }
 325      if (!this.scripts[src]) s = this.scripts[src] = {};
 326      else s = this.scripts[src];
 327      s.objects = [];
 328      s.dep = dep;
 329      s.rdep = [];
 330      s.src = src;
 331      s.pkg = pkg;
 332      s.loaded = false;
 333      s.fn = null;
 334  
 335      var n;
 336      for (var i=0;i<objects.length;i++) {
 337          n = objects[i];
 338          if (pkg) n = n.substring(n.lastIndexOf('.')+1);
 339          this.objects[n] = s;
 340          s.objects[s.objects.length] = n;
 341          if (p) p._objects[p._objects.length] = n;
 342      }
 343  
 344      return s;
 345  };
 346  // adds a dependency, whenever object "n" is loaded it will load object "d" beforehand
 347  p.addBefore = function(n, d) {
 348      var s = this.objects[n];
 349      if (s && this.objects[d]) s.dep[s.dep.length] = d;
 350  };
 351  // adds a reverse dependency, whenever object "n" is loaded it will load object "r" afterword
 352  p.addAfter = function(n, r) {
 353      var s = this.objects[n];
 354      if (s && this.objects[r]) s.rdep[s.rdep.length] = r;
 355  };
 356  
 357  // returns a list of js source filenames to load
 358  p._queue = function(n, list, force) {
 359      var na=[], names=[],o;
 360      if (list==null) list = [];
 361      if (typeof(n)=="string") na = [n];
 362      else na = n;
 363  
 364      for (var i=0;i<na.length;i++) {
 365          o = na[i];
 366          if (typeof(o)=="string") {
 367              if (this.packages[o])
 368                  for (var j in this.packages[o]._objects)
 369                      names[names.length] = this.packages[o]._objects[j];
 370              else names[names.length] = o;
 371          }
 372          else if (typeof(o)=="object" && o.length) {
 373              list = this._queue(o, list, force);
 374          }
 375      }
 376  
 377      var s;
 378      for (var j=0;j<names.length;j++) {
 379          s = this._queueObject(names[j], force);
 380          if (s) {
 381              if (s.dep)
 382                  for (var i=0;i<s.dep.length;i++)
 383                      list = this._queue(s.dep[i], list, force);
 384              list[list.length] = s.src;
 385              // also include reverse deps
 386              if (s.rdep.length) list = this._queue(s.rdep, list, force);
 387          }
 388      }
 389      return list;
 390  };
 391  
 392  // determines whether to queue the script this object is in
 393  p._queueObject = function(n, f) {
 394      if (n.indexOf('.')) {
 395          var pkg = n.substring(0,n.lastIndexOf('.'));
 396          if (this.packages[pkg]) n = n.substring(n.lastIndexOf('.')+1);
 397      }
 398      var s = this.objects[n];
 399      if (s) {
 400          if (!s.queued) {
 401              if (f!=true && s.loaded) dynapi.debug.print('Library Warning: '+n+' is already loaded');
 402              else {
 403                  s.queued = true;
 404                  s.loaded = false;
 405                  return s;
 406              }
 407          }
 408      }
 409      else dynapi.debug.print('Library Error: no library map for '+n);
 410      return false;
 411  };
 412  
 413  // writes the <script> tag for the object
 414  p.include = function() { 
 415      var a = arguments;
 416      if (a[0]==true) a=a[1]; // arguments used ONLY by packages.js
 417      // buffer includes until packages(.js) are loaded
 418      if (!this._pakLoaded) { 
 419          if(!this._buffer) this._buffer=[];
 420          this._buffer[this._buffer.length]=a;
 421          return;
 422      }
 423      if (dynapi.loaded) this.load(a);
 424      else {
 425          var list = this._queue(a);
 426          var src;
 427          for (var i=0;i<list.length;i++) {
 428              src = list[i];
 429              this.scripts[src].loaded = true;
 430              dynapi.frame.document.write('<script type="text/javascript" language="JavaScript" src="'+src+'"><\/script>');
 431          }
 432      }
 433  };
 434  p.load = p.reload = p.loadScript = p.reloadScript = function(n) {
 435      dynapi.debug.print('Warning: dynapi.library load extensions not included');
 436  };
 437  dynapi.library = new DynAPILibrary();
 438  
 439  // deprecated
 440  var DynAPI = dynapi;


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