var jsPsychInstructions = (function (jspsych) {
'use strict';
const info = {
name: "instructions",
parameters: {
/** Each element of the array is the HTML-formatted content for a single page. */
pages: {
type: jspsych.ParameterType.HTML_STRING,
pretty_name: "Pages",
default: undefined,
array: true,
},
/** The key the subject can press in order to advance to the next page. */
key_forward: {
type: jspsych.ParameterType.KEY,
pretty_name: "Key forward",
default: "ArrowRight",
},
/** The key that the subject can press to return to the previous page. */
key_backward: {
type: jspsych.ParameterType.KEY,
pretty_name: "Key backward",
default: "ArrowLeft",
},
/** If true, the subject can return to the previous page of the instructions. */
allow_backward: {
type: jspsych.ParameterType.BOOL,
pretty_name: "Allow backward",
default: true,
},
/** If true, the subject can use keyboard keys to navigate the pages. */
allow_keys: {
type: jspsych.ParameterType.BOOL,
pretty_name: "Allow keys",
default: true,
},
/** If true, then a "Previous" and "Next" button will be displayed beneath the instructions. */
show_clickable_nav: {
type: jspsych.ParameterType.BOOL,
pretty_name: "Show clickable nav",
default: false,
},
/** If true, and clickable navigation is enabled, then Page x/y will be shown between the nav buttons. */
show_page_number: {
type: jspsych.ParameterType.BOOL,
pretty_name: "Show page number",
default: false,
},
/** The text that appears before x/y (current/total) pages displayed with show_page_number. */
page_label: {
type: jspsych.ParameterType.STRING,
pretty_name: "Page label",
default: "Page",
},
/** The text that appears on the button to go backwards. */
button_label_previous: {
type: jspsych.ParameterType.STRING,
pretty_name: "Button label previous",
default: "Previous",
},
/** The text that appears on the button to go forwards. */
button_label_next: {
type: jspsych.ParameterType.STRING,
pretty_name: "Button label next",
default: "Next",
},
},
};
/**
* **instructions**
*
* jsPsych plugin to display text (including HTML-formatted strings) during the experiment.
* Use it to show a set of pages that participants can move forward/backward through.
* Page numbers can be displayed to help with navigation by setting show_page_number to true.
*
* @author Josh de Leeuw
* @see {@link https://www.jspsych.org/plugins/jspsych-instructions/ instructions plugin documentation on jspsych.org}
*/
class InstructionsPlugin {
constructor(jsPsych) {
this.jsPsych = jsPsych;
}
trial(display_element, trial) {
var current_page = 0;
var view_history = [];
var start_time = performance.now();
var last_page_update_time = start_time;
function btnListener(evt) {
evt.target.removeEventListener("click", btnListener);
if (this.id === "jspsych-instructions-back") {
back();
}
else if (this.id === "jspsych-instructions-next") {
next();
}
}
function show_current_page() {
var html = trial.pages[current_page];
var pagenum_display = "";
if (trial.show_page_number) {
pagenum_display =
"" +
trial.page_label +
" " +
(current_page + 1) +
"/" +
trial.pages.length +
"";
}
if (trial.show_clickable_nav) {
var nav_html = "