Subversion Repositories wimsdev

Rev

Rev 20 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.  
  3.         DynAPI Distribution
  4.  
  5.         DynImage Class
  6.  
  7.         The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
  8.  
  9. */
  10.  
  11.  
  12.  
  13. function DynImage(img,id,alt) {
  14.         this.img = img;
  15.         this.id = id;
  16.         this.alt = alt;
  17. };
  18.  
  19. DynImage.prototype.toString = function() {
  20.  
  21.         return "<img src=\""+this.img.src+"\""+
  22.                 (this.id?" id=\""+this.id+"\"":"")+
  23.                 (this.img.width?" width=\""+this.img.width+"\"":"")+
  24.                 (this.img.height?" height=\""+this.img.height+"\"":"")+
  25.                 (this.alt?" alt=\""+this.alt+"\"":"")+">";
  26. };
  27.  
  28. DynImage.image = [];
  29.  
  30. DynImage.getImage = function(src,w,h) {
  31.  
  32.         for (var i=0;i<DynImage.image.length;i++) {
  33.                 if (DynImage.image[i].img.src==src) return DynImage.image[i].img;
  34.         }
  35.  
  36.         var index = DynImage.image.length;
  37.  
  38.         DynImage.image[index] = {};
  39.  
  40.         if (w&&h) {
  41.                 DynImage.image[index].img = new Image(w,h);
  42.                 DynImage.image[index].img.w = w;
  43.                 DynImage.image[index].img.h = h;
  44.         }
  45.  
  46.         else DynImage.image[index].img = new Image();
  47.  
  48.         DynImage.image[index].img.src = src;
  49.  
  50.         if (!DynImage.timerId) DynImage.timerId=setTimeout('DynImage.loadercheck()',50);
  51.  
  52.         return DynImage.image[index].img;
  53. };
  54.  
  55.  
  56. DynImage.loadercheck=function() {
  57.  
  58.         DynImage.ItemsDone=0;
  59.  
  60.         var max = DynImage.image.length;
  61.         var dimg = null;
  62.  
  63.         for (var i=0; i<max; i++) {
  64.  
  65.                 dimg = DynImage.image[i];
  66.  
  67.                 if (dimg.img.complete) {
  68.  
  69.                         DynImage.ItemsDone+=1;
  70.  
  71.                         if (dimg.img.w) dimg.img.width = dimg.img.w;
  72.                         if (dimg.img.h) dimg.img.height = dimg.img.h;
  73.  
  74.                 }
  75.  
  76.         }
  77.  
  78.         if (DynImage.ItemsDone<max) DynImage.timerId=setTimeout('DynImage.loadercheck()',25);
  79.         else DynImage.timerId=null;
  80.  
  81. };
  82.  
  83. dynapi.onLoad(DynImage.loaderStart);
  84.