diff --git a/plugins/jspsych-animation.js b/plugins/jspsych-animation.js index a6e7bd2112..ae47f49778 100644 --- a/plugins/jspsych-animation.js +++ b/plugins/jspsych-animation.js @@ -38,7 +38,7 @@ trials[i].frame_isi = params.frame_isi || 0; trials[i].repetitions = params.repetitions || 1; trials[i].choices = params.choices || []; - trials[i].timing_post_trial = params.timing_post_trial || 1000; + trials[i].timing_post_trial = (typeof params.timing_post_trial === 'undefined') ? 1000 : params.timing_post_trial; trials[i].prompt = (typeof params.prompt === 'undefined') ? "" : params.prompt; trials[i].data = (typeof params.data === 'undefined') ? {} : params.data[i]; } @@ -142,9 +142,13 @@ "responses": JSON.stringify(responses) }, trial.data)); - setTimeout(function() { + if(trial.timing_post_trial > 0){ + setTimeout(function() { + block.next(); + }, trial.timing_post_trial); + } else { block.next(); - }, trial.timing_post_trial); + } } }; diff --git a/plugins/jspsych-categorize-animation.js b/plugins/jspsych-categorize-animation.js index 108d358679..4bdb43db17 100644 --- a/plugins/jspsych-categorize-animation.js +++ b/plugins/jspsych-categorize-animation.js @@ -44,7 +44,7 @@ trials[i].allow_response_before_complete = params.allow_response_before_complete || false; trials[i].frame_time = params.frame_time || 500; trials[i].timing_feedback_duration = params.timing_feedback_duration || 2000; - trials[i].timing_post_trial = params.timing_post_trial || 1000; + trials[i].timing_post_trial = (typeof params.timing_post_trial === 'undefined') ? 1000 : params.timing_post_trial; trials[i].prompt = (typeof params.prompt === 'undefined') ? '' : params.prompt; trials[i].data = (typeof params.data === 'undefined') ? {} : params.data[i]; } @@ -172,9 +172,13 @@ function endTrial() { clearInterval(animate_interval); // stop animation! display_element.html(''); // clear everything - setTimeout(function() { + if(trial.timing_post_trial > 0){ + setTimeout(function() { + block.next(); + }, trial.timing_post_trial); + } else { block.next(); - }, trial.timing_post_trial); + } } }; diff --git a/plugins/jspsych-categorize.js b/plugins/jspsych-categorize.js index 3eefd6c10a..e7498e23eb 100644 --- a/plugins/jspsych-categorize.js +++ b/plugins/jspsych-categorize.js @@ -43,7 +43,7 @@ // timing params trials[i].timing_stim = params.timing_stim || -1; // default is to show image until response trials[i].timing_feedback_duration = params.timing_feedback_duration || 2000; - trials[i].timing_post_trial = params.timing_post_trial || 1000; + trials[i].timing_post_trial = (typeof params.timing_post_trial === 'undefined') ? 1000 : params.timing_post_trial; // optional params trials[i].show_stim_with_feedback = (typeof params.show_stim_with_feedback === 'undefined') ? true : params.show_stim_with_feedback; trials[i].is_html = (typeof params.is_html === 'undefined') ? false : params.is_html; @@ -194,9 +194,13 @@ break; case 3: display_element.html(""); - setTimeout(function() { + if(trial.timing_post_trial > 0){ + setTimeout(function() { + block.next(); + }, trial.timing_post_trial); + } else { block.next(); - }, trial.timing_post_trial); + } break; } }; diff --git a/plugins/jspsych-free-sort.js b/plugins/jspsych-free-sort.js index d1361ada47..f6c3797b56 100644 --- a/plugins/jspsych-free-sort.js +++ b/plugins/jspsych-free-sort.js @@ -33,7 +33,7 @@ "images": params.stimuli[i], // array of images to display "stim_height": params.stim_height || 100, "stim_width": params.stim_width || 100, - "timing_post_trial": params.timing_post_trial || 1000, + "timing_post_trial": (typeof params.timing_post_trial === 'undefined') ? 1000 : params.timing_post_trial, "prompt": (typeof params.prompt === 'undefined') ? '' : params.prompt, "prompt_location": params.prompt_location || "above", "sort_area_width": params.sort_area_width || 800, @@ -133,9 +133,14 @@ // advance to next part display_element.html(""); - setTimeout(function() { + if (trial.timing_post_trial > 0) { + setTimeout(function() { + block.next(); + }, trial.timing_post_trial); + } + else { block.next(); - }, trial.timing_post_trial); + } } })); diff --git a/plugins/jspsych-html.js b/plugins/jspsych-html.js index 2966935dd1..2b080d36c4 100644 --- a/plugins/jspsych-html.js +++ b/plugins/jspsych-html.js @@ -43,7 +43,7 @@ Example Usage: url: params.pages[i].url, cont_key: params.pages[i].cont_key || params.cont_key, cont_btn: params.pages[i].cont_btn || params.cont_btn, - timing_post_trial: params.pages[i].timing_post_trial || params.timing_post_trial || 1000, + timing_post_trial: params.pages[i].timing_post_trial || (typeof params.timing_post_trial === 'undefined') ? 1000 : params.timing_post_trial, check_fn: params.pages[i].check_fn, force_refresh: (typeof params.force_refresh === 'undefined') ? false : params.force_refresh }); @@ -69,7 +69,7 @@ Example Usage: rt: (new Date()).getTime() - t0, url: trial.url }); - if (trial.timing) { + if (trial.timing_post_trial > 0) { // hide display_element, since it could have a border and we want a blank screen during timing display_element.hide(); setTimeout(function() { diff --git a/plugins/jspsych-palmer.js b/plugins/jspsych-palmer.js index de54e054c6..727359ac01 100644 --- a/plugins/jspsych-palmer.js +++ b/plugins/jspsych-palmer.js @@ -45,7 +45,7 @@ square_size: params.square_size || 3, circle_radius: params.circle_radius || 20, timing_item: params.timing_item || 1000, - timing_post_trial: params.timing_post_trial || 1000, + timing_post_trial: (typeof params.timing_post_trial === 'undefined') ? 1000 : params.timing_post_trial, timing_feedback: params.timing_feedback || 1000, prompt: (typeof params.prompt === 'undefined') ? "" : params.prompt, data: (typeof params.data === 'undefined') ? {} : params.data[i] @@ -232,12 +232,12 @@ // future ideas: allow for key response, to enable things like n-back, same/different, etc.. if (!trial.editable) { showConfiguration(trial.configurations); - + setTimeout(function() { save_data(); }, trial.timing_item); } - + if (trial.prompt !== "") { display_element.append($('
')); $("#jspsych-palmer-prompt").html(trial.prompt); @@ -310,9 +310,14 @@ display_element.html(''); // next trial - setTimeout(function() { + if (trial.timing_post_trial > 0) { + setTimeout(function() { + block.next(); + }, trial.timing_post_trial); + } + else { block.next(); - }, trial.timing_post_trial); + } } diff --git a/plugins/jspsych-same-different.js b/plugins/jspsych-same-different.js index 890af9f0f3..6183d3c421 100644 --- a/plugins/jspsych-same-different.js +++ b/plugins/jspsych-same-different.js @@ -39,7 +39,7 @@ trials[i].timing_first_stim = params.timing_first_stim || 1000; trials[i].timing_second_stim = params.timing_second_stim || 1000; // if -1, then second stim is shown until response. trials[i].timing_gap = params.timing_gap || 500; - trials[i].timing_post_trial = params.timing_post_trial || 1000; + trials[i].timing_post_trial = (typeof params.timing_post_trial === 'undefined') ? 1000 : params.timing_post_trial; // optional parameters trials[i].is_html = (typeof params.is_html === 'undefined') ? false : true; trials[i].prompt = (typeof params.prompt === 'undefined') ? "" : params.prompt; @@ -140,9 +140,13 @@ $(document).unbind('keyup', resp_func); display_element.html(''); - setTimeout(function() { + if(trial.timing_post_trial > 0) { + setTimeout(function() { + block.next(); + }, trial.timing_post_trial); + } else { block.next(); - }, trial.timing_post_trial); + } } }; $(document).keyup(resp_func); diff --git a/plugins/jspsych-similarity.js b/plugins/jspsych-similarity.js index 52c582794a..98bc1b6c4e 100644 --- a/plugins/jspsych-similarity.js +++ b/plugins/jspsych-similarity.js @@ -43,7 +43,7 @@ trials[i].timing_first_stim = params.timing_first_stim || 1000; // default 1000ms trials[i].timing_second_stim = params.timing_second_stim || -1; // -1 = inf time; positive numbers = msec to display second image. trials[i].timing_image_gap = params.timing_image_gap || 1000; // default 1000ms - trials[i].timing_post_trial = params.timing_post_trial || 1000; // default 1000ms + trials[i].timing_post_trial = (typeof params.timing_post_trial === 'undefined') ? 1000 : params.timing_post_trial; // default 1000ms trials[i].is_html = (typeof params.is_html === 'undefined') ? false : params.is_html; trials[i].prompt = (typeof params.prompt === 'undefined') ? '' : params.prompt; @@ -89,9 +89,9 @@ plugin.trial(display_element, block, trial, part + 1); }, trial.timing_image_gap); break; - + case 3: - + if (!trial.is_html) { $('#jspsych_sim_stim').attr('src', trial.b_path); } @@ -100,7 +100,7 @@ } $('#jspsych_sim_stim').css('visibility', 'visible'); - + if (trial.show_response == "SECOND_STIMULUS") { show_response_slider(display_element, trial, block); } @@ -218,9 +218,14 @@ }, trial.data)); // goto next trial in block display_element.html(''); - setTimeout(function() { + if (trial.timing_post_trial > 0) { + setTimeout(function() { + block.next(); + }, trial.timing_post_trial); + } + else { block.next(); - }, trial.timing_post_trial); + } }); } diff --git a/plugins/jspsych-single-stim.js b/plugins/jspsych-single-stim.js index b8269ffee1..59ccea59ba 100644 --- a/plugins/jspsych-single-stim.js +++ b/plugins/jspsych-single-stim.js @@ -40,7 +40,7 @@ // timing parameters trials[i].timing_stim = params.timing_stim || -1; // if -1, then show indefinitely trials[i].timing_response = params.timing_response || -1; // if -1, then wait for response forever - trials[i].timing_post_trial = params.timing_post_trial || 1000; + trials[i].timing_post_trial = (typeof params.timing_post_trial === 'undefined') ? 1000 : params.timing_post_trial; // optional parameters trials[i].is_html = (typeof params.is_html === 'undefined') ? false : params.is_html; trials[i].prompt = (typeof params.prompt === 'undefined') ? "" : params.prompt; @@ -96,9 +96,14 @@ block.writeData($.extend({}, trial_data, trial.data)); $(document).unbind('keyup', resp_func); display_element.html(''); - setTimeout(function() { + if (trial.timing_post_trial > 0) { + setTimeout(function() { + block.next(); + }, trial.timing_post_trial); + } + else { block.next(); - }, trial.timing_post_trial); + } }; var resp_func = function(e) { diff --git a/plugins/jspsych-text.js b/plugins/jspsych-text.js index 448684313e..31e5c18457 100644 --- a/plugins/jspsych-text.js +++ b/plugins/jspsych-text.js @@ -35,9 +35,9 @@ * When the above parameters are loaded into the text plugin, the first screen would show * "hello, hello." and the second screen would show "I don't know why you say goodbye, I say hello." * - */ - - (function($) { + */ + +(function($) { jsPsych.text = (function() { var plugin = {}; @@ -49,7 +49,7 @@ trials[i].type = "text"; // must match plugin name trials[i].text = params.text[i]; // text of all trials trials[i].cont_key = params.cont_key || '13'; // keycode to press to advance screen, default is ENTER. - trials[i].timing_post_trial = params.timing_post_trial || 0; // how long to delay between screens, default is no delay. + trials[i].timing_post_trial = (typeof params.timing_post_trial === 'undefined') ? 0 : params.timing_post_trial; trials[i].variables = (typeof params.variables === 'undefined') ? undefined : params.variables[i]; trials[i].data = (typeof params.data === 'undefined') ? {} : params.data[i]; } @@ -74,7 +74,7 @@ display_element.html(replaced_text); var startTime = (new Date()).getTime(); - + // it's possible that if the user is holding down the cont_key when // they arrive on the page that they will advance as soon as the // key is released. this prevents that from happening by requiring a @@ -89,15 +89,19 @@ $(document).unbind('keyup', key_listener); // remove the response function, so that it doesn't get triggered again. $(document).unbind('keydown', key_down_listener); display_element.html(''); // clear the display - setTimeout(function() { + if (trial.timing_post_trial > 0) { + setTimeout(function() { + block.next(); + }, trial.timing_post_trial); + } + else { block.next(); - }, trial.timing_post_trial); // call block.next() to advance the experiment after a delay. + } // call block.next() to advance the experiment after a delay. } }; - - var key_down_listener = function(e){ - if(e.which == trial.cont_key) - { + + var key_down_listener = function(e) { + if (e.which == trial.cont_key) { cont_key_down = true; } }; @@ -106,9 +110,14 @@ save_data(); display_element.unbind('click', mouse_listener); // remove the response function, so that it doesn't get triggered again. display_element.html(''); // clear the display - setTimeout(function() { + if (trial.timing_post_trial > 0) { + setTimeout(function() { + block.next(); + }, trial.timing_post_trial); + } + else { block.next(); - }, trial.timing_post_trial); // call block.next() to advance the experiment after a delay. + } // call block.next() to advance the experiment after a delay. }; // check if key is 'mouse' diff --git a/plugins/jspsych-xab.js b/plugins/jspsych-xab.js index 7f313adfe5..68be173829 100644 --- a/plugins/jspsych-xab.js +++ b/plugins/jspsych-xab.js @@ -55,7 +55,7 @@ trials[i].timing_x = params.timing_x || 1000; // defaults to 1000msec. trials[i].timing_xab_gap = params.timing_xab_gap || 1000; // defaults to 1000msec. trials[i].timing_ab = params.timing_ab || -1; // defaults to -1, meaning infinite time on AB. If a positive number is used, then AB will only be displayed for that length. - trials[i].timing_post_trial = params.timing_post_trial || 1000; // defaults to 1000msec. + trials[i].timing_post_trial = (typeof params.timing_post_trial === 'undefined') ? 1000 : params.timing_post_trial; // defaults to 1000msec. // optional parameters trials[i].is_html = (typeof params.is_html === 'undefined') ? false : params.is_html; trials[i].prompt = (typeof params.prompt === 'undefined') ? "" : params.prompt; @@ -192,9 +192,13 @@ display_element.html(''); // remove all xab_trial_complete = true; // move on to the next trial after timing_post_trial milliseconds - setTimeout(function() { + if(trial.timing_post_trial > 0) { + setTimeout(function() { + block.next(); + }, trial.timing_post_trial); + } else { block.next(); - }, trial.timing_post_trial); + } } }; $(document).keyup(resp_func);