summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpixel <pixel>2008-01-16 14:23:49 +0000
committerpixel <pixel>2008-01-16 14:23:49 +0000
commit0ea2b16f3199e1dc9f746f688d7530e6e3d94570 (patch)
tree105e30504f00fd7b26dff6c5a00b8d6e0eaf0bce
parent79331578d3b4bc73c74bc741d6bcaca2cf5cd650 (diff)
Adding the generic image preloading javascript to the htmllib.
-rw-r--r--lib/htmllib.lua64
1 files changed, 62 insertions, 2 deletions
diff --git a/lib/htmllib.lua b/lib/htmllib.lua
index 9603b4f..ab10530 100644
--- a/lib/htmllib.lua
+++ b/lib/htmllib.lua
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: htmllib.lua,v 1.1 2008-01-15 18:20:23 pixel Exp $ */
+/* $Id: htmllib.lua,v 1.2 2008-01-16 14:23:49 pixel Exp $ */
]]--
@@ -64,7 +64,6 @@ function removeAllOptions(selectbox)
}
}
-
function addOption(selectbox, value, text )
{
selectbox = getObjById(selectbox);
@@ -75,6 +74,67 @@ function addOption(selectbox, value, text )
selectbox.options.add(optn);
}
+//=============================================================================
+// Image Preloader
+function ImagePreloader(images, callback) {
+ // store the callback
+ this.callback = callback;
+
+ // initialize internal state.
+ this.nLoaded = 0;
+ this.nProcessed = 0;
+ this.aImages = new Array;
+
+ // record the number of images.
+ this.nImages = images.length;
+
+ // for each image, call preload()
+ for (var i = 0; i < images.length; i++)
+ this.preload(images[i]);
+}
+
+ImagePreloader.prototype.preload = function(image) {
+ // create new Image object and add to array
+ var oImage = new Image;
+ this.aImages.push(oImage);
+
+ // set up event handlers for the Image object
+ oImage.onload = ImagePreloader.prototype.onload;
+ oImage.onerror = ImagePreloader.prototype.onerror;
+ oImage.onabort = ImagePreloader.prototype.onabort;
+
+ // assign pointer back to this.
+ oImage.oImagePreloader = this;
+ oImage.bLoaded = false;
+ oImage.source = image;
+
+ // assign the .src property of the Image object
+ oImage.src = image;
+}
+
+ImagePreloader.prototype.onComplete = function() {
+ this.nProcessed++;
+ if (this.nProcessed == this.nImages)
+ this.callback(this.aImages);
+}
+
+ImagePreloader.prototype.onload = function() {
+ this.bLoaded = true;
+ this.oImagePreloader.nLoaded++;
+ this.oImagePreloader.onComplete();
+}
+
+ImagePreloader.prototype.onerror = function() {
+ this.bError = true;
+ this.oImagePreloader.onComplete();
+}
+
+ImagePreloader.prototype.onabort = function() {
+ this.bAbort = true;
+ this.oImagePreloader.onComplete();
+}
+//=============================================================================
+
/////////////////////////////////////////////////////////////////////
/*-------------------------------------------------------------------
AKX GetVariables