From a04f33f30efb6187d6c6b4d83c446bfcdae35480 Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Mon, 11 Nov 2013 23:09:21 -0500 Subject: [PATCH] adding core.preloadImages() --- jspsych.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/jspsych.js b/jspsych.js index 8e702a4f..89184ec2 100755 --- a/jspsych.js +++ b/jspsych.js @@ -144,6 +144,33 @@ return exp_start_time; }; + // core.preloadImage will load images into the browser cache so that they appear quickly when + // used during a trial. + // images: array of paths to images + // callback_complete: a function with no arguments that calls when loading is complete + // callback_load: a function with a single argument that calls whenever an image is loaded + // argument is the number of images currently loaded. + + core.preloadImages = function(images, callback_complete, callback_load){ + var n_loaded = 0; + var loadfn = (typeof callback_load === 'undefined') ? function(){} : callback_load; + var finishfn = (typeof callback_complete === 'undefined') ? function(){} : callback_complete; + + for(var i=0;i