/** * jspsych-preload * documentation: docs.jspsych.org **/ jsPsych.plugins['preload'] = (function() { var plugin = {}; plugin.info = { name: 'preload', description: '', parameters: { auto_preload: { type: jsPsych.plugins.parameterType.BOOL, default: false }, trials: { type: jsPsych.plugins.parameterType.TIMELINE, default: [] }, images: { type: jsPsych.plugins.parameterType.STRING, default: [] }, audio: { type: jsPsych.plugins.parameterType.STRING, default: [] }, video: { type: jsPsych.plugins.parameterType.STRING, default: [] }, message: { type: jsPsych.plugins.parameterType.HTML_STRING, default: null }, show_progress_bar: { type: jsPsych.plugins.parameterType.BOOL, default: true, }, show_detailed_errors: { type: jsPsych.plugins.parameterType.BOOL, default: false }, max_load_time: { type: jsPsych.plugins.parameterType.INT, default: null } } } plugin.trial = function(display_element, trial) { // create list of media to preload //// var images = []; var audio = []; var video = []; if(trial.auto_preload){ var auto_preload = jsPsych.pluginAPI.getAutoPreloadList(); images = images.concat(auto_preload.images); audio = audio.concat(auto_preload.audio); video = video.concat(auto_preload.video); } if(trial.trials.length > 0){ var trial_preloads = jsPsych.pluginAPI.getAutoPreloadList(trial.trials); images = images.concat(trial_preloads.images); audio = audio.concat(trial_preloads.audio); video = video.concat(trial_preloads.video); } images = images.concat(trial.images); audio = audio.concat(trial.audio); video = video.concat(trial.video); images = jsPsych.utils.unique(jsPsych.utils.flatten(images)) audio = jsPsych.utils.unique(jsPsych.utils.flatten(audio)) video = jsPsych.utils.unique(jsPsych.utils.flatten(video)) // render display of message and progress bar var html = ''; if(trial.message !== null){ html += trial.message; } if(trial.show_progress_bar){ html += `