Merge pull request #365 from hugueslacroix/master

Follow up on issue #360 and pull request #362
This commit is contained in:
Josh de Leeuw 2017-04-04 11:26:48 -04:00 committed by GitHub
commit 5be7b122f3
9 changed files with 109 additions and 28 deletions

View File

@ -60,6 +60,12 @@ jsPsych.plugins['free-sort'] = (function() {
default: 'above', default: 'above',
no_function: false, no_function: false,
description: '' description: ''
},
button_label: {
type: [jsPsych.plugins.parameterType.STRING],
default: 'Done',
no_function: false,
description: ''
} }
} }
} }
@ -73,6 +79,7 @@ jsPsych.plugins['free-sort'] = (function() {
trial.prompt_location = trial.prompt_location || "above"; trial.prompt_location = trial.prompt_location || "above";
trial.sort_area_width = trial.sort_area_width || 800; trial.sort_area_width = trial.sort_area_width || 800;
trial.sort_area_height = trial.sort_area_height || 800; trial.sort_area_height = trial.sort_area_height || 800;
trial.button_label = typeof trial.button_label === 'undefined' ? 'Done' : trial.button_label;
// if any trial variables are functions // if any trial variables are functions
// this evaluates the function and replaces // this evaluates the function and replaces
@ -118,7 +125,7 @@ jsPsych.plugins['free-sort'] = (function() {
}); });
} }
display_element.innerHTML += '<button id="jspsych-free-sort-done-btn" class="jspsych-btn">Done</button>'; display_element.innerHTML += '<button id="jspsych-free-sort-done-btn" class="jspsych-btn">'+trial.button_label+'</button>';
var maxz = 1; var maxz = 1;

View File

@ -53,6 +53,18 @@ jsPsych.plugins.instructions = (function() {
default: false, default: false,
no_function: false, no_function: false,
description: '' description: ''
},
button_label_previous: {
type: [jsPsych.plugins.parameterType.STRING],
default: 'Previous',
no_function: false,
description: ''
},
button_label_next: {
type: [jsPsych.plugins.parameterType.STRING],
default: 'Next',
no_function: false,
description: ''
} }
} }
} }
@ -64,6 +76,8 @@ jsPsych.plugins.instructions = (function() {
trial.allow_backward = (typeof trial.allow_backward === 'undefined') ? true : trial.allow_backward; trial.allow_backward = (typeof trial.allow_backward === 'undefined') ? true : trial.allow_backward;
trial.allow_keys = (typeof trial.allow_keys === 'undefined') ? true : trial.allow_keys; trial.allow_keys = (typeof trial.allow_keys === 'undefined') ? true : trial.allow_keys;
trial.show_clickable_nav = (typeof trial.show_clickable_nav === 'undefined') ? false : trial.show_clickable_nav; trial.show_clickable_nav = (typeof trial.show_clickable_nav === 'undefined') ? false : trial.show_clickable_nav;
trial.button_label_previous = (typeof trial.button_label_previous === 'undefined') ? 'Previous' : trial.button_label_previous;
trial.button_label_next = (typeof trial.button_label_next === 'undefined') ? 'Next' : trial.button_label_next;
// if any trial variables are functions // if any trial variables are functions
// this evaluates the function and replaces // this evaluates the function and replaces
@ -77,7 +91,7 @@ jsPsych.plugins.instructions = (function() {
var start_time = (new Date()).getTime(); var start_time = (new Date()).getTime();
var last_page_update_time = start_time; var last_page_update_time = start_time;
function btnListener(evt){ function btnListener(evt){
evt.target.removeEventListener('click', btnListener); evt.target.removeEventListener('click', btnListener);
if(this.id === "jspsych-instructions-back"){ if(this.id === "jspsych-instructions-back"){
@ -87,7 +101,7 @@ jsPsych.plugins.instructions = (function() {
next(); next();
} }
} }
function show_current_page() { function show_current_page() {
display_element.innerHTML = trial.pages[current_page]; display_element.innerHTML = trial.pages[current_page];
@ -95,41 +109,41 @@ jsPsych.plugins.instructions = (function() {
var nav_html = "<div class='jspsych-instructions-nav'>"; var nav_html = "<div class='jspsych-instructions-nav'>";
if (current_page != 0 && trial.allow_backward) { if (current_page != 0 && trial.allow_backward) {
nav_html += "<button id='jspsych-instructions-back' class='jspsych-btn'>&lt; Previous</button>"; nav_html += "<button id='jspsych-instructions-back' class='jspsych-btn'>&lt; "+trial.button_label_previous+"</button>";
} }
nav_html += "<button id='jspsych-instructions-next' class='jspsych-btn'>Next &gt;</button></div>" nav_html += "<button id='jspsych-instructions-next' class='jspsych-btn'>"+trial.button_label_next+" &gt;</button></div>"
display_element.innerHTML += nav_html; display_element.innerHTML += nav_html;
if (current_page != 0 && trial.allow_backward) { if (current_page != 0 && trial.allow_backward) {
display_element.querySelector('#jspsych-instructions-back').addEventListener('click', btnListener); display_element.querySelector('#jspsych-instructions-back').addEventListener('click', btnListener);
} }
display_element.querySelector('#jspsych-instructions-next').addEventListener('click', btnListener); display_element.querySelector('#jspsych-instructions-next').addEventListener('click', btnListener);
} }
} }
function next() { function next() {
add_current_page_to_view_history() add_current_page_to_view_history()
current_page++; current_page++;
// if done, finish up... // if done, finish up...
if (current_page >= trial.pages.length) { if (current_page >= trial.pages.length) {
endTrial(); endTrial();
} else { } else {
show_current_page(); show_current_page();
} }
} }
function back() { function back() {
add_current_page_to_view_history() add_current_page_to_view_history()
current_page--; current_page--;
show_current_page(); show_current_page();
} }

View File

@ -66,6 +66,12 @@ jsPsych.plugins.palmer = (function() {
default: '', default: '',
no_function: false, no_function: false,
description: '' description: ''
},
button_label: {
type: [jsPsych.plugins.parameterType.STRING],
default: 'Done',
no_function: false,
description: ''
} }
} }
} }
@ -80,6 +86,7 @@ jsPsych.plugins.palmer = (function() {
trial.timing_item = trial.timing_item || 1000; trial.timing_item = trial.timing_item || 1000;
trial.timing_feedback = trial.timing_feedback || 1000; trial.timing_feedback = trial.timing_feedback || 1000;
trial.prompt = (typeof trial.prompt === 'undefined') ? "" : trial.prompt; trial.prompt = (typeof trial.prompt === 'undefined') ? "" : trial.prompt;
trial.button_label = typeof trial.button_label === 'undefined' ? 'Submit Answers' : trial.button_label;
// if any trial variables are functions // if any trial variables are functions
// this evaluates the function and replaces // this evaluates the function and replaces
@ -246,7 +253,7 @@ jsPsych.plugins.palmer = (function() {
// start recording the time // start recording the time
var startTime = (new Date()).getTime(); var startTime = (new Date()).getTime();
display_element.innerHTML += '<p><button id="jspsych-palmer-submitButton" class="jspsych-btn" type="button">Submit Answer</button></p>'; display_element.innerHTML += '<p><button id="jspsych-palmer-submitButton" class="jspsych-btn" type="button">'+trial.button_label+'</button></p>';
display_element.querySelector('#jspsych-palmer-submitButton').addEventListener('click', function() { display_element.querySelector('#jspsych-palmer-submitButton').addEventListener('click', function() {
save_data(); save_data();
}); });

View File

@ -47,6 +47,12 @@ jsPsych.plugins['reconstruction'] = (function() {
default: 'g', default: 'g',
no_function: false, no_function: false,
description: '' description: ''
},
button_label: {
type: [jsPsych.plugins.parameterType.STRING],
default: '',
no_function: false,
description: 'Submit Answers'
} }
} }
} }
@ -58,6 +64,7 @@ jsPsych.plugins['reconstruction'] = (function() {
trial.step_size = trial.step_size || 0.05; trial.step_size = trial.step_size || 0.05;
trial.key_increase = trial.key_increase || 'h'; trial.key_increase = trial.key_increase || 'h';
trial.key_decrease = trial.key_decrease || 'g'; trial.key_decrease = trial.key_decrease || 'g';
trial.button_label = typeof trial.button_label === 'undefined' ? 'Submit Answers' : trial.button_label;
// if any trial variables are functions // if any trial variables are functions
// this evaluates the function and replaces // this evaluates the function and replaces
@ -105,7 +112,7 @@ jsPsych.plugins['reconstruction'] = (function() {
display_element.innerHTML = '<div id="jspsych-reconstruction-stim-container">'+trial.stim_function(param)+'</div>'; display_element.innerHTML = '<div id="jspsych-reconstruction-stim-container">'+trial.stim_function(param)+'</div>';
// add submit button // add submit button
display_element.innerHTML += '<button id="jspsych-reconstruction-next" class="jspsych-btn jspsych-reconstruction">Submit Answers</button>'; display_element.innerHTML += '<button id="jspsych-reconstruction-next" class="jspsych-btn jspsych-reconstruction">'+trial.button_label+'</button>';
display_element.querySelector('#jspsych-reconstruction-next').addEventListener('click', endTrial); display_element.querySelector('#jspsych-reconstruction-next').addEventListener('click', endTrial);
} }

View File

@ -81,6 +81,12 @@ jsPsych.plugins.similarity = (function() {
default: '', default: '',
no_function: false, no_function: false,
description: '' description: ''
},
button_label: {
type: [jsPsych.plugins.parameterType.STRING],
default: '',
no_function: false,
description: 'Submit Answers'
} }
} }
} }
@ -100,6 +106,8 @@ jsPsych.plugins.similarity = (function() {
trial.is_html = (typeof trial.is_html === 'undefined') ? false : trial.is_html; trial.is_html = (typeof trial.is_html === 'undefined') ? false : trial.is_html;
trial.prompt = (typeof trial.prompt === 'undefined') ? '' : trial.prompt; trial.prompt = (typeof trial.prompt === 'undefined') ? '' : trial.prompt;
trial.button_label = typeof trial.button_label === 'undefined' ? 'Submit Answers' : trial.button_label;
// if any trial variables are functions // if any trial variables are functions
// this evaluates the function and replaces // this evaluates the function and replaces
@ -231,7 +239,7 @@ jsPsych.plugins.similarity = (function() {
display_element.append($('<button>', { display_element.append($('<button>', {
'id': 'next', 'id': 'next',
'class': 'sim', 'class': 'sim',
'html': 'Submit Answer' 'html': trial.button_label
})); }));
// if prompt is set, show prompt // if prompt is set, show prompt

View File

@ -29,6 +29,12 @@ jsPsych.plugins['survey-likert'] = (function() {
default: undefined, default: undefined,
no_function: false, no_function: false,
description: '' description: ''
},
button_label: {
type: [jsPsych.plugins.parameterType.STRING],
default: 'Submit Answers',
no_function: false,
description: ''
} }
} }
} }

View File

@ -48,6 +48,12 @@ jsPsych.plugins['survey-multi-choice'] = (function() {
default: '', default: '',
no_function: false, no_function: false,
description: '' description: ''
},
button_label: {
type: [jsPsych.plugins.parameterType.STRING],
default: '',
no_function: false,
description: ''
} }
} }
} }
@ -63,6 +69,8 @@ jsPsych.plugins['survey-multi-choice'] = (function() {
trial.preamble = typeof trial.preamble == 'undefined' ? "" : trial.preamble; trial.preamble = typeof trial.preamble == 'undefined' ? "" : trial.preamble;
trial.required = typeof trial.required == 'undefined' ? null : trial.required; trial.required = typeof trial.required == 'undefined' ? null : trial.required;
trial.horizontal = typeof trial.required == 'undefined' ? false : trial.horizontal; trial.horizontal = typeof trial.required == 'undefined' ? false : trial.horizontal;
//If button_label is empty, the browser's language will be used to determine the button label.
trial.button_label = typeof trial.button_label === 'undefined' ? '' : trial.button_label;
// if any trial variables are functions // if any trial variables are functions
// this evaluates the function and replaces // this evaluates the function and replaces
@ -113,16 +121,18 @@ jsPsych.plugins['survey-multi-choice'] = (function() {
// add label and question text // add label and question text
var form = document.getElementById(option_id_name) var form = document.getElementById(option_id_name)
var input_id_name = _join(plugin_id_name, 'response', i); var input_name = _join(plugin_id_name, 'response', i);
var input_id = _join(plugin_id_name, 'response', i, j);
var label = document.createElement('label'); var label = document.createElement('label');
label.setAttribute('class', plugin_id_name+'-text'); label.setAttribute('class', plugin_id_name+'-text');
label.innerHTML = trial.options[i][j]; label.innerHTML = trial.options[i][j];
label.setAttribute('for', input_id_name) label.setAttribute('for', input_id)
// create radio button // create radio button
var input = document.createElement('input'); var input = document.createElement('input');
input.setAttribute('type', "radio"); input.setAttribute('type', "radio");
input.setAttribute('name', input_id_name); input.setAttribute('name', input_name);
input.setAttribute('id', input_id);
input.setAttribute('value', trial.options[i][j]); input.setAttribute('value', trial.options[i][j]);
form.appendChild(label); form.appendChild(label);
form.insertBefore(input, label); form.insertBefore(input, label);
@ -137,8 +147,7 @@ jsPsych.plugins['survey-multi-choice'] = (function() {
} }
} }
// add submit button // add submit button
trial_form.innerHTML += '<input type="submit" id="'+plugin_id_name+'-next" class="'+plugin_id_name+' jspsych-btn"></input>'; trial_form.innerHTML += '<input type="submit" id="'+plugin_id_name+'-next" class="'+plugin_id_name+' jspsych-btn"' + (trial.button_label ? ' value="'+trial.button_label + '"': '') + '></input>';
trial_form.addEventListener('submit', function(event) { trial_form.addEventListener('submit', function(event) {
event.preventDefault(); event.preventDefault();
var matches = display_element.querySelectorAll("div." + plugin_id_name + "-question"); var matches = display_element.querySelectorAll("div." + plugin_id_name + "-question");

View File

@ -46,6 +46,12 @@ jsPsych.plugins['survey-multi-select'] = (function() {
default: '', default: '',
no_function: false, no_function: false,
description: '' description: ''
},
button_label: {
type: [jsPsych.plugins.parameterType.STRING],
default: '',
no_function: false,
description: ''
} }
} }
} }
@ -62,6 +68,8 @@ jsPsych.plugins['survey-multi-select'] = (function() {
trial.required = typeof trial.required == 'undefined' ? true : trial.required; trial.required = typeof trial.required == 'undefined' ? true : trial.required;
trial.required_msg = trial.required_msg || '*please select at least one option!'; trial.required_msg = trial.required_msg || '*please select at least one option!';
trial.horizontal = typeof trial.horizontal == 'undefined' ? false : trial.horizontal; trial.horizontal = typeof trial.horizontal == 'undefined' ? false : trial.horizontal;
//If button_label is empty, the browser's language will be used to determine the button label.
trial.button_label = typeof trial.button_label === 'undefined' ? '' : trial.button_label;
// if any trial variables are functions // if any trial variables are functions
// this evaluates the function and replaces // this evaluates the function and replaces
@ -112,16 +120,18 @@ jsPsych.plugins['survey-multi-select'] = (function() {
// add label and question text // add label and question text
var form = document.getElementById(option_id_name) var form = document.getElementById(option_id_name)
var input_id_name = _join(plugin_id_name, 'response', i); var input_name = _join(plugin_id_name, 'response', i);
var input_id = _join(plugin_id_name, 'response', i, j);
var label = document.createElement('label'); var label = document.createElement('label');
label.setAttribute('class', plugin_id_name+'-text'); label.setAttribute('class', plugin_id_name+'-text');
label.innerHTML = trial.options[i][j]; label.innerHTML = trial.options[i][j];
label.setAttribute('for', input_id_name) label.setAttribute('for', input_id)
// create checkboxes // create checkboxes
var input = document.createElement('input'); var input = document.createElement('input');
input.setAttribute('type', "checkbox"); input.setAttribute('type', "checkbox");
input.setAttribute('name', input_id_name); input.setAttribute('name', input_name);
input.setAttribute('id', input_id);
input.setAttribute('value', trial.options[i][j]) input.setAttribute('value', trial.options[i][j])
form.appendChild(label) form.appendChild(label)
form.insertBefore(input, label) form.insertBefore(input, label)
@ -129,7 +139,7 @@ jsPsych.plugins['survey-multi-select'] = (function() {
} }
// add submit button // add submit button
trial_form.innerHTML +='<div class="fail-message"></div>' trial_form.innerHTML +='<div class="fail-message"></div>'
trial_form.innerHTML += '<input type="submit" id="'+plugin_id_name+'-next" class="'+plugin_id_name+' jspsych-btn"></input>'; trial_form.innerHTML += '<input type="submit" id="'+plugin_id_name+'-next" class="'+plugin_id_name+' jspsych-btn"' + (trial.button_label ? ' value="'+trial.button_label +'"': '') + '></input>';
trial_form.addEventListener('submit', function(event) { trial_form.addEventListener('submit', function(event) {
event.preventDefault(); event.preventDefault();

View File

@ -24,7 +24,7 @@ jsPsych.plugins['survey-text'] = (function() {
no_function: false, no_function: false,
description: '' description: ''
}, },
premable: { preamble: {
type: [jsPsych.plugins.parameterType.STRING], type: [jsPsych.plugins.parameterType.STRING],
default: '', default: '',
no_function: false, no_function: false,
@ -43,6 +43,19 @@ jsPsych.plugins['survey-text'] = (function() {
default: 40, default: 40,
no_function: false, no_function: false,
description: '' description: ''
},
values: {
type: [jsPsych.plugins.parameterType.STRING],
array: true,
default: '',
no_function: false,
description: ''
},
button_label: {
type: [jsPsych.plugins.parameterType.STRING],
default: '',
no_function: false,
description: 'Submit Answers'
} }
} }
} }