* default show_page_number to false for back-compatability
* added a line in the documentation describing page numbering
This commit is contained in:
mjaquiery 2018-02-09 16:22:21 +00:00
parent 9a655dc93b
commit a2d997841f
2 changed files with 22 additions and 8 deletions

View File

@ -13,7 +13,8 @@
pages: ['Welcome to the experiment. Click next to begin.',
'This is the second page of instructions.',
'This is the final page.'],
show_clickable_nav: true
show_clickable_nav: true,
show_page_number: true
}
jsPsych.init({

View File

@ -1,9 +1,12 @@
/* jspsych-text.js
/* jspsych-instructions.js
* Josh de Leeuw
*
* This plugin displays text (including HTML formatted strings) during the experiment.
* Use it to show instructions, provide performance feedback, etc...
*
* Page numbers can be displayed to help with navigation by setting show_page_number
* to true.
*
* documentation: docs.jspsych.org
*
*
@ -55,11 +58,11 @@ jsPsych.plugins.instructions = (function() {
description: 'If true, then a "Previous" and "Next" button will be displayed beneath the instructions.'
},
show_page_number: {
type: jsPsch.plugins.parameterType.BOOL,
type: jsPsych.plugins.parameterType.BOOL,
pretty_name: 'Show page number',
default: true,
default: false,
description: 'If true, and clickable navigation is enabled, then Page x/y will be shown between the nav buttons.'
}
},
button_label_previous: {
type: jsPsych.plugins.parameterType.STRING,
pretty_name: 'Button label previous',
@ -96,8 +99,11 @@ jsPsych.plugins.instructions = (function() {
}
function show_current_page() {
let pagenum_display = "";
if(trial.show_page_number) {
pagenum_display = "Page "+(current_page+1)+"/"+trial.pages.length;
}
display_element.innerHTML = trial.pages[current_page];
if (trial.show_clickable_nav) {
var nav_html = "<div class='jspsych-instructions-nav' style='padding: 10px 0px;'>";
@ -106,9 +112,12 @@ jsPsych.plugins.instructions = (function() {
nav_html += "<button id='jspsych-instructions-back' class='jspsych-btn' style='margin-right: 5px;' "+allowed+">&lt; "+trial.button_label_previous+"</button>";
}
if (trial.pages.length > 1 && trial.show_page_number) {
nav_html += "<span style='margin: 0 1em;'>Page "+(current_page+1)+"/"+trial.pages.length+"</span>";
nav_html += "<span style='margin: 0 1em;' class='"+
"jspsych-instructions-pagenum'>"+pagenum_display+"</span>";
}
nav_html += "<button id='jspsych-instructions-next' class='jspsych-btn' style='margin-left: 5px;'>"+trial.button_label_next+" &gt;</button></div>"
nav_html += "<button id='jspsych-instructions-next' class='jspsych-btn'"+
"style='margin-left: 5px;'>"+trial.button_label_next+
" &gt;</button></div>";
display_element.innerHTML += nav_html;
@ -117,6 +126,10 @@ jsPsych.plugins.instructions = (function() {
}
display_element.querySelector('#jspsych-instructions-next').addEventListener('click', btnListener);
} else if (trial.show_page_number && trial.pages.length > 1) {
// page numbers for non-mouse navigation
display_element.innerHTML += "<div class='jspsych-instructions-pagenum'>"+
pagenum_display+"</div>"
}
}