Subversion Repositories wimsdev

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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