remove editable option

Closes #72
This commit is contained in:
Josh de Leeuw 2014-09-29 14:02:04 -04:00
parent 940c5580f8
commit 9b617435e8

View File

@ -22,13 +22,10 @@
plugin.create = function(params) { plugin.create = function(params) {
params = jsPsych.pluginAPI.enforceArray(params, ['data']);
var trials = []; var trials = [];
for (var i = 0; i < params.configurations.length; i++) { for (var i = 0; i < params.configurations.length; i++) {
var trial = { var trial = {
configurations: params.configurations[i], configurations: params.configurations[i],
editable: (typeof params.editable === 'undefined') ? false : params.editable,
show_feedback: (typeof params.show_feedback === 'undefined') ? false : params.show_feedback, show_feedback: (typeof params.show_feedback === 'undefined') ? false : params.show_feedback,
grid_spacing: params.grid_spacing || 75, grid_spacing: params.grid_spacing || 75,
square_size: params.square_size || 3, square_size: params.square_size || 3,
@ -74,7 +71,7 @@
var circle = paper.circle(trial.grid_spacing * j, trial.grid_spacing * i, trial.circle_radius); var circle = paper.circle(trial.grid_spacing * j, trial.grid_spacing * i, trial.circle_radius);
circle.attr("fill", "#000").attr("stroke-width", "0").attr("stroke", "#000").data("node", node_idx); circle.attr("fill", "#000").attr("stroke-width", "0").attr("stroke", "#000").data("node", node_idx);
if (trial.editable) {
circle.hover( circle.hover(
function() { function() {
@ -92,13 +89,12 @@
line_started = true; line_started = true;
start_circle = this.data("node"); start_circle = this.data("node");
this.attr("fill", "#777").attr("stroke", "#777"); this.attr("fill", "#777").attr("stroke", "#777");
} } else {
else {
end_circle = this.data("node"); end_circle = this.data("node");
draw_connection(start_circle, end_circle); draw_connection(start_circle, end_circle);
} }
}); });
}
node_idx++; node_idx++;
circles.push(circle); circles.push(circle);
} }
@ -163,6 +159,7 @@
// define some helper functions to toggle lines on and off // define some helper functions to toggle lines on and off
// this function gets the index of a line based on the two circles it connects // this function gets the index of a line based on the two circles it connects
function getLineIndex(start_circle, end_circle) { function getLineIndex(start_circle, end_circle) {
var the_line = -1; var the_line = -1;
for (var i = 0; i < lines.length; i++) { for (var i = 0; i < lines.length; i++) {
@ -175,14 +172,14 @@
} }
// this function turns a line on/off based on the index (the_line) // this function turns a line on/off based on the index (the_line)
function toggle_line(the_line) { function toggle_line(the_line) {
if (the_line > -1) { if (the_line > -1) {
if (lineIsVisible[the_line] === 0) { if (lineIsVisible[the_line] === 0) {
lineElements[the_line].show(); lineElements[the_line].show();
lineElements[the_line].toBack(); lineElements[the_line].toBack();
lineIsVisible[the_line] = 1; lineIsVisible[the_line] = 1;
} } else {
else {
lineElements[the_line].hide(); lineElements[the_line].hide();
lineElements[the_line].toBack(); lineElements[the_line].toBack();
lineIsVisible[the_line] = 0; lineIsVisible[the_line] = 0;
@ -192,6 +189,7 @@
// this function takes an array of length = num lines, and displays the line whereever there // this function takes an array of length = num lines, and displays the line whereever there
// is a 1 in the array. // is a 1 in the array.
function showConfiguration(configuration) { function showConfiguration(configuration) {
for (var i = 0; i < configuration.length; i++) { for (var i = 0; i < configuration.length; i++) {
if (configuration[i] != lineIsVisible[i]) { if (configuration[i] != lineIsVisible[i]) {
@ -201,6 +199,7 @@
} }
// highlight a line // highlight a line
function highlightLine(line) { function highlightLine(line) {
lineElements[line].attr("stroke", "#f00"); lineElements[line].attr("stroke", "#f00");
} }
@ -208,27 +207,10 @@
// start recording the time // start recording the time
var startTime = (new Date()).getTime(); var startTime = (new Date()).getTime();
// what kind of trial are we doing?
// if trial.editable is true, then we will let the user interact with the stimulus to create
// something, e.g. for a reconstruction probe.
// need a way for the user to submit when they are done in that case...
if (trial.editable) {
display_element.append($('<button id="jspsych-palmer-submitButton" type="button">Submit Answer</button>')); display_element.append($('<button id="jspsych-palmer-submitButton" type="button">Submit Answer</button>'));
$('#jspsych-palmer-submitButton').click(function() { $('#jspsych-palmer-submitButton').click(function() {
save_data(); save_data();
}); });
}
// if trial.editable is false, then we are just showing a pre-determined configuration.
// for now, the only option will be to display for a fixed amount of time.
// 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 !== "") { if (trial.prompt !== "") {
display_element.append($('<div id="jspsych-palmer-prompt">')); display_element.append($('<div id="jspsych-palmer-prompt">'));
@ -246,6 +228,7 @@
} }
// save data // save data
function save_data() { function save_data() {
// measure RT // measure RT
@ -265,7 +248,7 @@
"num_wrong": n_diff, "num_wrong": n_diff,
}, trial.data)); }, trial.data));
if (trial.editable && trial.show_feedback) { if (trial.show_feedback) {
// hide the button // hide the button
$('#jspsych-palmer-submitButton').hide(); $('#jspsych-palmer-submitButton').hide();
$('#jspsych-palmer-prompt').hide(); $('#jspsych-palmer-prompt').hide();
@ -274,12 +257,10 @@
var feedback = ""; var feedback = "";
if (correct) { if (correct) {
feedback = "Correct!"; feedback = "Correct!";
} } else {
else {
if (n_diff > 1) { if (n_diff > 1) {
feedback = "You missed " + n_diff + " lines. The correct symbol is shown above."; feedback = "You missed " + n_diff + " lines. The correct symbol is shown above.";
} } else {
else {
feedback = "You missed 1 line. The correct symbol is shown above."; feedback = "You missed 1 line. The correct symbol is shown above.";
} }
} }
@ -289,8 +270,7 @@
next_trial(); next_trial();
}, trial.timing_feedback); }, trial.timing_feedback);
} } else {
else {
next_trial(); next_trial();
} }
} }
@ -304,8 +284,7 @@
setTimeout(function() { setTimeout(function() {
jsPsych.finishTrial(); jsPsych.finishTrial();
}, trial.timing_post_trial); }, trial.timing_post_trial);
} } else {
else {
jsPsych.finishTrial(); jsPsych.finishTrial();
} }
@ -384,14 +363,14 @@
// define some helper functions to toggle lines on and off // define some helper functions to toggle lines on and off
// this function turns a line on/off based on the index (the_line) // this function turns a line on/off based on the index (the_line)
function toggle_line(the_line) { function toggle_line(the_line) {
if (the_line > -1) { if (the_line > -1) {
if (lineIsVisible[the_line] === 0) { if (lineIsVisible[the_line] === 0) {
lineElements[the_line].show(); lineElements[the_line].show();
lineElements[the_line].toBack(); lineElements[the_line].toBack();
lineIsVisible[the_line] = 1; lineIsVisible[the_line] = 1;
} } else {
else {
lineElements[the_line].hide(); lineElements[the_line].hide();
lineElements[the_line].toBack(); lineElements[the_line].toBack();
lineIsVisible[the_line] = 0; lineIsVisible[the_line] = 0;