mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-12 16:48:12 +00:00
clean formatting, remove redundant data
This commit is contained in:
parent
2c33d7603d
commit
2d9af8dfa9
@ -43,103 +43,99 @@
|
|||||||
|
|
||||||
plugin.trial = function(display_element, block, trial, part) {
|
plugin.trial = function(display_element, block, trial, part) {
|
||||||
|
|
||||||
// if any trial variables are functions
|
// if any trial variables are functions
|
||||||
// this evaluates the function and replaces
|
// this evaluates the function and replaces
|
||||||
// it with the output of the function
|
// it with the output of the function
|
||||||
trial = jsPsych.pluginAPI.normalizeTrialVariables(trial);
|
trial = jsPsych.pluginAPI.normalizeTrialVariables(trial);
|
||||||
|
|
||||||
// this array holds handlers from setTimeout calls
|
// this array holds handlers from setTimeout calls
|
||||||
// that need to be cleared if the trial ends early
|
// that need to be cleared if the trial ends early
|
||||||
var setTimeoutHandlers = [];
|
var setTimeoutHandlers = [];
|
||||||
|
|
||||||
// display stimulus
|
// display stimulus
|
||||||
if (!trial.is_html) {
|
if (!trial.is_html) {
|
||||||
display_element.append($('<img>', {
|
display_element.append($('<img>', {
|
||||||
src: trial.a_path,
|
src: trial.a_path,
|
||||||
id: 'jspsych-single-stim-stimulus'
|
id: 'jspsych-single-stim-stimulus'
|
||||||
}));
|
}));
|
||||||
}
|
} else {
|
||||||
else {
|
display_element.append($('<div>', {
|
||||||
display_element.append($('<div>', {
|
html: trial.a_path,
|
||||||
html: trial.a_path,
|
id: 'jspsych-single-stim-stimulus'
|
||||||
id: 'jspsych-single-stim-stimulus'
|
}));
|
||||||
}));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//show prompt if there is one
|
//show prompt if there is one
|
||||||
if (trial.prompt !== "") {
|
if (trial.prompt !== "") {
|
||||||
display_element.append(trial.prompt);
|
display_element.append(trial.prompt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// function to end trial when it is time
|
// function to end trial when it is time
|
||||||
var end_trial = function(info) {
|
var end_trial = function(info) {
|
||||||
|
|
||||||
// kill any remaining setTimeout handlers
|
// kill any remaining setTimeout handlers
|
||||||
for(var i = 0; i < setTimeoutHandlers.length; i++){
|
for(var i = 0; i < setTimeoutHandlers.length; i++){
|
||||||
clearTimeout(setTimeoutHandlers[i]);
|
clearTimeout(setTimeoutHandlers[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// kill keyboard listeners
|
// kill keyboard listeners
|
||||||
jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);
|
jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);
|
||||||
|
|
||||||
// gather the data to store for the trial
|
// gather the data to store for the trial
|
||||||
var trial_data = {
|
var trial_data = {
|
||||||
"trial_type": "single-stim",
|
"rt": info.rt,
|
||||||
"trial_index": block.trial_idx,
|
"stimulus": trial.a_path,
|
||||||
"rt": info.rt,
|
"key_press": info.key
|
||||||
"stimulus": trial.a_path,
|
};
|
||||||
"key_press": info.key
|
|
||||||
};
|
|
||||||
|
|
||||||
block.writeData($.extend({}, trial_data, trial.data));
|
block.writeData($.extend({}, trial_data, trial.data));
|
||||||
|
|
||||||
// clear the display
|
// clear the display
|
||||||
display_element.html('');
|
display_element.html('');
|
||||||
|
|
||||||
// move on to the next trial
|
// move on to the next trial
|
||||||
if (trial.timing_post_trial > 0) {
|
if (trial.timing_post_trial > 0) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
block.next();
|
block.next();
|
||||||
}, trial.timing_post_trial);
|
}, trial.timing_post_trial);
|
||||||
}
|
} else {
|
||||||
else {
|
block.next();
|
||||||
block.next();
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
|
||||||
// function to handle responses by the subject
|
// function to handle responses by the subject
|
||||||
var after_response = function(info) {
|
var after_response = function(info) {
|
||||||
|
|
||||||
// after a valid response, the stimulus will have the CSS class 'responded'
|
// after a valid response, the stimulus will have the CSS class 'responded'
|
||||||
// which can be used to provide visual feedback that a response was recorded
|
// which can be used to provide visual feedback that a response was recorded
|
||||||
$("#jspsych-single-stim-stimulus").addClass('responded');
|
$("#jspsych-single-stim-stimulus").addClass('responded');
|
||||||
|
|
||||||
if (trial.continue_after_response) {
|
if (trial.continue_after_response) {
|
||||||
// response triggers the next trial in this case.
|
// response triggers the next trial in this case.
|
||||||
// if hide_image_after_response is true, then next
|
// if hide_image_after_response is true, then next
|
||||||
// trial should be triggered by timeout function below.
|
// trial should be triggered by timeout function below.
|
||||||
end_trial(info);
|
end_trial(info);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// start the response listener
|
// start the response listener
|
||||||
var keyboardListener = jsPsych.pluginAPI.getKeyboardResponse(after_response, trial.choices);
|
var keyboardListener = jsPsych.pluginAPI.getKeyboardResponse(after_response, trial.choices);
|
||||||
|
|
||||||
// hide image if timing is set
|
// hide image if timing is set
|
||||||
if (trial.timing_stim > 0) {
|
if (trial.timing_stim > 0) {
|
||||||
var t1 = setTimeout(function() {
|
var t1 = setTimeout(function() {
|
||||||
$('#jspsych-single-stim-stimulus').css('visibility', 'hidden');
|
$('#jspsych-single-stim-stimulus').css('visibility', 'hidden');
|
||||||
}, trial.timing_stim);
|
}, trial.timing_stim);
|
||||||
setTimeoutHandlers.push(t1);
|
setTimeoutHandlers.push(t1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// end trial if time limit is set
|
// end trial if time limit is set
|
||||||
if (trial.timing_response > 0) {
|
if (trial.timing_response > 0) {
|
||||||
var t2 = setTimeout(function() {
|
var t2 = setTimeout(function() {
|
||||||
end_trial({rt: -1, key: -1});
|
end_trial({rt: -1, key: -1});
|
||||||
}, trial.timing_response);
|
}, trial.timing_response);
|
||||||
setTimeoutHandlers.push(t2);
|
setTimeoutHandlers.push(t2);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user