Skip to content

Commit

Permalink
Merge pull request #20 from jodeleeuw/timing-zero-fix
Browse files Browse the repository at this point in the history
Timing zero fix
  • Loading branch information
jodeleeuw committed Jan 27, 2014
2 parents f906a7b + e76284a commit f68b475
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 47 deletions.
10 changes: 7 additions & 3 deletions plugins/jspsych-animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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);
}
}
};

Expand Down
10 changes: 7 additions & 3 deletions plugins/jspsych-categorize-animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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);
}
}
};

Expand Down
10 changes: 7 additions & 3 deletions plugins/jspsych-categorize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
};
Expand Down
11 changes: 8 additions & 3 deletions plugins/jspsych-free-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}
}));

Expand Down
4 changes: 2 additions & 2 deletions plugins/jspsych-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand All @@ -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() {
Expand Down
15 changes: 10 additions & 5 deletions plugins/jspsych-palmer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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($('<div id="jspsych-palmer-prompt">'));
$("#jspsych-palmer-prompt").html(trial.prompt);
Expand Down Expand Up @@ -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);
}

}

Expand Down
10 changes: 7 additions & 3 deletions plugins/jspsych-same-different.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 11 additions & 6 deletions plugins/jspsych-similarity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -100,7 +100,7 @@
}

$('#jspsych_sim_stim').css('visibility', 'visible');

if (trial.show_response == "SECOND_STIMULUS") {
show_response_slider(display_element, trial, block);
}
Expand Down Expand Up @@ -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);
}
});
}

Expand Down
11 changes: 8 additions & 3 deletions plugins/jspsych-single-stim.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
35 changes: 22 additions & 13 deletions plugins/jspsych-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -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];
}
Expand All @@ -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
Expand All @@ -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;
}
};
Expand All @@ -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'
Expand Down
10 changes: 7 additions & 3 deletions plugins/jspsych-xab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f68b475

Please sign in to comment.