issue112, enhanced preload functions for photo-index
[phpfspot.git] / phpfspot.js
index 89eacbadfcda5c3672704a4262628fbe1e00c0c0..f9f970324bac324d8d24952cae1d2bccbf01a79a 100644 (file)
@@ -427,23 +427,32 @@ function WSR_getElementsByClassName(oElm, strTagName, oClassNames){
 }
 
 
-function preloadPhotos(lbImg) {
+function preloadPhotos(image_url) {
 
-   var d=document;
-   if(d.images)
-      if(!d.photos)
-         d.photos=new Array();
-
-   var i, j=d.photos.length;
+   var i;
+   var timeout = 1000;
+   var waiting = 100;
+   var counting;
 
    lbImg=WSR_getElementsByClassName(document,"img","thumb");
    for(i=0;i<lbImg.length;i++){
-      d.photos[j]=new Image;
-      d.photos[j].src=lbImg[i].src;
-      j++;
+      lbImg[i].src=image_url[i];
+      // to not bomb the server with requests, give the page some time
+      // to load the images one by one. if a image exceeds the timeout,
+      // the next image will be loaded.
+      if(lbImg[i].complete != undefined && lbImg[i].complete != true) {
+         counting = 0;
+         while(lbImg[i].complete != true && counting < timeout) {
+            window.setTimeout("noop()", waiting);
+            counting+=waiting;
+         }
+      }
    }
 }
 
+/* a function that does nothing */
+function noop() {}
+
 function startSlideShow()
 {
    if(!sliding) {