@jspsych/plugin-survey-likert 2.0.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  var jsPsychSurveyLikert = (function (jspsych) {
2
2
  'use strict';
3
3
 
4
- var version = "2.0.1";
4
+ var version = "2.2.0";
5
5
 
6
6
  const info = {
7
7
  name: "survey-likert",
@@ -32,6 +32,11 @@ var jsPsychSurveyLikert = (function (jspsych) {
32
32
  name: {
33
33
  type: jspsych.ParameterType.STRING,
34
34
  default: ""
35
+ },
36
+ /** Default response value for this question (0-based index of labels array). */
37
+ default_response: {
38
+ type: jspsych.ParameterType.INT,
39
+ default: null
35
40
  }
36
41
  }
37
42
  },
@@ -75,6 +80,11 @@ var jsPsychSurveyLikert = (function (jspsych) {
75
80
  type: jspsych.ParameterType.INT,
76
81
  array: true
77
82
  }
83
+ },
84
+ // prettier-ignore
85
+ citations: {
86
+ "apa": "de Leeuw, J. R., Gilbert, R. A., & Luchterhandt, B. (2023). jsPsych: Enabling an Open-Source Collaborative Ecosystem of Behavioral Experiments. Journal of Open Source Software, 8(85), 5351. https://doi.org/10.21105/joss.05351 ",
87
+ "bibtex": '@article{Leeuw2023jsPsych, author = {de Leeuw, Joshua R. and Gilbert, Rebecca A. and Luchterhandt, Bj{\\" o}rn}, journal = {Journal of Open Source Software}, doi = {10.21105/joss.05351}, issn = {2475-9066}, number = {85}, year = {2023}, month = {may 11}, pages = {5351}, publisher = {Open Journals}, title = {jsPsych: Enabling an {Open}-{Source} {Collaborative} {Ecosystem} of {Behavioral} {Experiments}}, url = {https://joss.theoj.org/papers/10.21105/joss.05351}, volume = {8}, } '
78
88
  }
79
89
  };
80
90
  class SurveyLikertPlugin {
@@ -119,6 +129,9 @@ var jsPsychSurveyLikert = (function (jspsych) {
119
129
  if (question.required) {
120
130
  options_string += " required";
121
131
  }
132
+ if (question.default_response === j) {
133
+ options_string += " checked";
134
+ }
122
135
  options_string += ">" + question.labels[j] + "</label></li>";
123
136
  }
124
137
  options_string += "</ul>";
@@ -217,4 +230,4 @@ var jsPsychSurveyLikert = (function (jspsych) {
217
230
  return SurveyLikertPlugin;
218
231
 
219
232
  })(jsPsychModule);
220
- //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-likert@2.0.1/dist/index.browser.js.map
233
+ //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-likert@2.2.0/dist/index.browser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.browser.js","sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@jspsych/plugin-survey-likert\",\n \"version\": \"2.0.1\",\n \"description\": \"a jspsych plugin for measuring items on a likert scale\",\n \"type\": \"module\",\n \"main\": \"dist/index.cjs\",\n \"exports\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"typings\": \"dist/index.d.ts\",\n \"unpkg\": \"dist/index.browser.min.js\",\n \"files\": [\n \"src\",\n \"dist\"\n ],\n \"source\": \"src/index.ts\",\n \"scripts\": {\n \"test\": \"jest\",\n \"test:watch\": \"npm test -- --watch\",\n \"tsc\": \"tsc\",\n \"build\": \"rollup --config\",\n \"build:watch\": \"npm run build -- --watch\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/jspsych/jsPsych.git\",\n \"directory\": \"packages/plugin-survey-likert\"\n },\n \"author\": \"Josh de Leeuw\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/jspsych/jsPsych/issues\"\n },\n \"homepage\": \"https://www.jspsych.org/latest/plugins/survey-likert\",\n \"peerDependencies\": {\n \"jspsych\": \">=7.1.0\"\n },\n \"devDependencies\": {\n \"@jspsych/config\": \"^3.1.1\",\n \"@jspsych/test-utils\": \"^1.2.0\"\n }\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"survey-likert\",\n version: version,\n parameters: {\n /** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */\n questions: {\n type: ParameterType.COMPLEX,\n array: true,\n nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: undefined,\n },\n /** Array of likert labels to display for this question. */\n labels: {\n type: ParameterType.STRING,\n array: true,\n default: undefined,\n },\n /** Whether or not a response to this question must be given in order to continue. */\n required: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */\n name: {\n type: ParameterType.STRING,\n default: \"\",\n },\n },\n },\n /** If true, the order of the questions in the 'questions' array will be randomized. */\n randomize_question_order: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** HTML-formatted string to display at top of the page above all of the questions. */\n preamble: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** Width of the likert scales in pixels. */\n scale_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to submit responses. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n },\n /** Setting this to true will enable browser auto-complete or auto-fill for the form. */\n autocomplete: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\n /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n response: {\n type: ParameterType.OBJECT,\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */\n rt: {\n type: ParameterType.INT,\n },\n /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n question_order: {\n type: ParameterType.INT,\n array: true,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * The survey-likert plugin displays a set of questions with Likert scale responses. The participant responds\n * by selecting a radio button.\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/survey-likert/ survey-likert plugin documentation on jspsych.org}\n */\nclass SurveyLikertPlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n if (trial.scale_width !== null) {\n var w = trial.scale_width + \"px\";\n } else {\n var w = \"100%\";\n }\n\n var html = \"\";\n // inject CSS for trial\n html += '<style id=\"jspsych-survey-likert-css\">';\n html +=\n \".jspsych-survey-likert-statement { display:block; font-size: 16px; padding-top: 40px; margin-bottom:10px; }\" +\n \".jspsych-survey-likert-opts { list-style:none; width:\" +\n w +\n \"; margin:auto; padding:0 0 35px; display:block; font-size: 14px; line-height:1.1em; }\" +\n \".jspsych-survey-likert-opt-label { line-height: 1.1em; color: #444; }\" +\n \".jspsych-survey-likert-opts:before { content: ''; position:relative; top:11px; /*left:9.5%;*/ display:block; background-color:#efefef; height:4px; width:100%; }\" +\n \".jspsych-survey-likert-opts:last-of-type { border-bottom: 0; }\" +\n \".jspsych-survey-likert-opts li { display:inline-block; /*width:19%;*/ text-align:center; vertical-align: top; }\" +\n \".jspsych-survey-likert-opts li input[type=radio] { display:block; position:relative; top:0; left:50%; margin-left:-6px; }\";\n html += \"</style>\";\n\n // show preamble text\n if (trial.preamble !== null) {\n html +=\n '<div id=\"jspsych-survey-likert-preamble\" class=\"jspsych-survey-likert-preamble\">' +\n trial.preamble +\n \"</div>\";\n }\n\n if (trial.autocomplete) {\n html += '<form id=\"jspsych-survey-likert-form\">';\n } else {\n html += '<form id=\"jspsych-survey-likert-form\" autocomplete=\"off\">';\n }\n\n // add likert scale questions ///\n // generate question order. this is randomized here as opposed to randomizing the order of trial.questions\n // so that the data are always associated with the same question regardless of order\n var question_order = [];\n for (var i = 0; i < trial.questions.length; i++) {\n question_order.push(i);\n }\n if (trial.randomize_question_order) {\n question_order = this.jsPsych.randomization.shuffle(question_order);\n }\n\n for (var i = 0; i < trial.questions.length; i++) {\n var question = trial.questions[question_order[i]];\n // add question\n html += '<label class=\"jspsych-survey-likert-statement\">' + question.prompt + \"</label>\";\n // add options\n var width = 100 / question.labels.length;\n var options_string =\n '<ul class=\"jspsych-survey-likert-opts\" data-name=\"' +\n question.name +\n '\" data-radio-group=\"Q' +\n question_order[i] +\n '\">';\n for (var j = 0; j < question.labels.length; j++) {\n options_string +=\n '<li style=\"width:' +\n width +\n '%\"><label class=\"jspsych-survey-likert-opt-label\"><input type=\"radio\" name=\"Q' +\n question_order[i] +\n '\" value=\"' +\n j +\n '\"';\n if (question.required) {\n options_string += \" required\";\n }\n options_string += \">\" + question.labels[j] + \"</label></li>\";\n }\n options_string += \"</ul>\";\n html += options_string;\n }\n\n // add submit button\n html +=\n '<input type=\"submit\" id=\"jspsych-survey-likert-next\" class=\"jspsych-survey-likert jspsych-btn\" value=\"' +\n trial.button_label +\n '\"></input>';\n\n html += \"</form>\";\n\n display_element.innerHTML = html;\n\n display_element.querySelector(\"#jspsych-survey-likert-form\").addEventListener(\"submit\", (e) => {\n e.preventDefault();\n // measure response time\n var endTime = performance.now();\n var response_time = Math.round(endTime - startTime);\n\n // create object to hold responses\n var question_data = {};\n var matches = display_element.querySelectorAll<HTMLFormElement>(\n \"#jspsych-survey-likert-form .jspsych-survey-likert-opts\"\n );\n for (var index = 0; index < matches.length; index++) {\n var id = matches[index].dataset[\"radioGroup\"];\n var el = display_element.querySelector<HTMLInputElement>(\n 'input[name=\"' + id + '\"]:checked'\n );\n if (el === null) {\n var response: string | number = \"\";\n } else {\n var response: string | number = parseInt(el.value);\n }\n var obje = {};\n if (matches[index].attributes[\"data-name\"].value !== \"\") {\n var name = matches[index].attributes[\"data-name\"].value;\n } else {\n var name = id;\n }\n obje[name] = response;\n Object.assign(question_data, obje);\n }\n\n // save data\n var trial_data = {\n rt: response_time,\n response: question_data,\n question_order: question_order,\n };\n\n // next trial\n this.jsPsych.finishTrial(trial_data);\n });\n\n var startTime = performance.now();\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const question_data = {};\n let rt = 1000;\n\n for (const q of trial.questions) {\n const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;\n question_data[name] = this.jsPsych.randomization.randomInt(0, q.labels.length - 1);\n rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);\n }\n\n const default_data = {\n response: question_data,\n rt: rt,\n question_order: trial.randomize_question_order\n ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])\n : [...Array(trial.questions.length).keys()],\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n const answers = Object.entries(data.response);\n for (let i = 0; i < answers.length; i++) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\n `input[type=\"radio\"][name=\"${answers[i][0]}\"][value=\"${answers[i][1]}\"]`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\"#jspsych-survey-likert-next\"),\n data.rt\n );\n }\n}\n\nexport default S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A,MAAM,IAAO,GAAA,IAAA,CAAK,sBAAuB,CAAA,KAAA,EAAO,kBAAkB,CAAA,CAAA;EAElE,IAAM,MAAA,eAAA,GAAkB,IAAK,CAAA,OAAA,CAAQ,iBAAkB,EAAA,CAAA;EAEvD,IAAK,IAAA,CAAA,KAAA,CAAM,iBAAiB,KAAK,CAAA,CAAA;EACjC,IAAc,aAAA,EAAA,CAAA;EAEd,IAAA,MAAM,OAAU,GAAA,MAAA,CAAO,OAAQ,CAAA,IAAA,CAAK,QAAQ,CAAA,CAAA;EAC5C,IAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,OAAA,CAAQ,QAAQ,CAAK,EAAA,EAAA;EACvC,MAAA,IAAA,CAAK,QAAQ,SAAU,CAAA,WAAA;EAAA,QACrB,eAAgB,CAAA,aAAA;EAAA,UACd,CAAA,0BAAA,EAA6B,OAAQ,CAAA,CAAC,CAAE,CAAA,CAAC,CAAC,CAAA,UAAA,EAAa,OAAQ,CAAA,CAAC,CAAE,CAAA,CAAC,CAAC,CAAA,EAAA,CAAA;EAAA,SACtE;EAAA,QAAA,CACE,IAAK,CAAA,EAAA,GAAK,GAAQ,IAAA,OAAA,CAAQ,UAAW,CAAI,GAAA,CAAA,CAAA;EAAA,OAC7C,CAAA;EAAA,KACF;EAEA,IAAA,IAAA,CAAK,QAAQ,SAAU,CAAA,WAAA;EAAA,MACrB,eAAA,CAAgB,cAAc,6BAA6B,CAAA;EAAA,MAC3D,IAAK,CAAA,EAAA;EAAA,KACP,CAAA;EAAA,GACF;EACF;;;;;;;;"}
1
+ {"version":3,"file":"index.browser.js","sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@jspsych/plugin-survey-likert\",\n \"version\": \"2.2.0\",\n \"description\": \"a jspsych plugin for measuring items on a likert scale\",\n \"type\": \"module\",\n \"main\": \"dist/index.cjs\",\n \"exports\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"typings\": \"dist/index.d.ts\",\n \"unpkg\": \"dist/index.browser.min.js\",\n \"files\": [\n \"src\",\n \"dist\"\n ],\n \"source\": \"src/index.ts\",\n \"scripts\": {\n \"test\": \"jest\",\n \"test:watch\": \"npm test -- --watch\",\n \"tsc\": \"tsc\",\n \"build\": \"rollup --config\",\n \"build:watch\": \"npm run build -- --watch\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/jspsych/jsPsych.git\",\n \"directory\": \"packages/plugin-survey-likert\"\n },\n \"author\": \"Josh de Leeuw\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/jspsych/jsPsych/issues\"\n },\n \"homepage\": \"https://www.jspsych.org/latest/plugins/survey-likert\",\n \"peerDependencies\": {\n \"jspsych\": \">=7.1.0\"\n },\n \"devDependencies\": {\n \"@jspsych/config\": \"^3.2.0\",\n \"@jspsych/test-utils\": \"^1.2.0\"\n }\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"survey-likert\",\n version: version,\n parameters: {\n /** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */\n questions: {\n type: ParameterType.COMPLEX,\n array: true,\n nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: undefined,\n },\n /** Array of likert labels to display for this question. */\n labels: {\n type: ParameterType.STRING,\n array: true,\n default: undefined,\n },\n /** Whether or not a response to this question must be given in order to continue. */\n required: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */\n name: {\n type: ParameterType.STRING,\n default: \"\",\n },\n /** Default response value for this question (0-based index of labels array). */\n default_response: {\n type: ParameterType.INT,\n default: null,\n },\n },\n },\n /** If true, the order of the questions in the 'questions' array will be randomized. */\n randomize_question_order: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** HTML-formatted string to display at top of the page above all of the questions. */\n preamble: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** Width of the likert scales in pixels. */\n scale_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to submit responses. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n },\n /** Setting this to true will enable browser auto-complete or auto-fill for the form. */\n autocomplete: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\n /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n response: {\n type: ParameterType.OBJECT,\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */\n rt: {\n type: ParameterType.INT,\n },\n /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n question_order: {\n type: ParameterType.INT,\n array: true,\n },\n },\n // prettier-ignore\n citations: '__CITATIONS__',\n};\n\ntype Info = typeof info;\n\n/**\n * The survey-likert plugin displays a set of questions with Likert scale responses. The participant responds\n * by selecting a radio button.\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/survey-likert/ survey-likert plugin documentation on jspsych.org}\n */\nclass SurveyLikertPlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n if (trial.scale_width !== null) {\n var w = trial.scale_width + \"px\";\n } else {\n var w = \"100%\";\n }\n\n var html = \"\";\n // inject CSS for trial\n html += '<style id=\"jspsych-survey-likert-css\">';\n html +=\n \".jspsych-survey-likert-statement { display:block; font-size: 16px; padding-top: 40px; margin-bottom:10px; }\" +\n \".jspsych-survey-likert-opts { list-style:none; width:\" +\n w +\n \"; margin:auto; padding:0 0 35px; display:block; font-size: 14px; line-height:1.1em; }\" +\n \".jspsych-survey-likert-opt-label { line-height: 1.1em; color: #444; }\" +\n \".jspsych-survey-likert-opts:before { content: ''; position:relative; top:11px; /*left:9.5%;*/ display:block; background-color:#efefef; height:4px; width:100%; }\" +\n \".jspsych-survey-likert-opts:last-of-type { border-bottom: 0; }\" +\n \".jspsych-survey-likert-opts li { display:inline-block; /*width:19%;*/ text-align:center; vertical-align: top; }\" +\n \".jspsych-survey-likert-opts li input[type=radio] { display:block; position:relative; top:0; left:50%; margin-left:-6px; }\";\n html += \"</style>\";\n\n // show preamble text\n if (trial.preamble !== null) {\n html +=\n '<div id=\"jspsych-survey-likert-preamble\" class=\"jspsych-survey-likert-preamble\">' +\n trial.preamble +\n \"</div>\";\n }\n\n if (trial.autocomplete) {\n html += '<form id=\"jspsych-survey-likert-form\">';\n } else {\n html += '<form id=\"jspsych-survey-likert-form\" autocomplete=\"off\">';\n }\n\n // add likert scale questions ///\n // generate question order. this is randomized here as opposed to randomizing the order of trial.questions\n // so that the data are always associated with the same question regardless of order\n var question_order = [];\n for (var i = 0; i < trial.questions.length; i++) {\n question_order.push(i);\n }\n if (trial.randomize_question_order) {\n question_order = this.jsPsych.randomization.shuffle(question_order);\n }\n\n for (var i = 0; i < trial.questions.length; i++) {\n var question = trial.questions[question_order[i]];\n // add question\n html += '<label class=\"jspsych-survey-likert-statement\">' + question.prompt + \"</label>\";\n // add options\n var width = 100 / question.labels.length;\n var options_string =\n '<ul class=\"jspsych-survey-likert-opts\" data-name=\"' +\n question.name +\n '\" data-radio-group=\"Q' +\n question_order[i] +\n '\">';\n for (var j = 0; j < question.labels.length; j++) {\n options_string +=\n '<li style=\"width:' +\n width +\n '%\"><label class=\"jspsych-survey-likert-opt-label\"><input type=\"radio\" name=\"Q' +\n question_order[i] +\n '\" value=\"' +\n j +\n '\"';\n if (question.required) {\n options_string += \" required\";\n }\n if (question.default_response === j) {\n options_string += \" checked\";\n }\n options_string += \">\" + question.labels[j] + \"</label></li>\";\n }\n options_string += \"</ul>\";\n html += options_string;\n }\n\n // add submit button\n html +=\n '<input type=\"submit\" id=\"jspsych-survey-likert-next\" class=\"jspsych-survey-likert jspsych-btn\" value=\"' +\n trial.button_label +\n '\"></input>';\n\n html += \"</form>\";\n\n display_element.innerHTML = html;\n\n display_element.querySelector(\"#jspsych-survey-likert-form\").addEventListener(\"submit\", (e) => {\n e.preventDefault();\n // measure response time\n var endTime = performance.now();\n var response_time = Math.round(endTime - startTime);\n\n // create object to hold responses\n var question_data = {};\n var matches = display_element.querySelectorAll<HTMLFormElement>(\n \"#jspsych-survey-likert-form .jspsych-survey-likert-opts\"\n );\n for (var index = 0; index < matches.length; index++) {\n var id = matches[index].dataset[\"radioGroup\"];\n var el = display_element.querySelector<HTMLInputElement>(\n 'input[name=\"' + id + '\"]:checked'\n );\n if (el === null) {\n var response: string | number = \"\";\n } else {\n var response: string | number = parseInt(el.value);\n }\n var obje = {};\n if (matches[index].attributes[\"data-name\"].value !== \"\") {\n var name = matches[index].attributes[\"data-name\"].value;\n } else {\n var name = id;\n }\n obje[name] = response;\n Object.assign(question_data, obje);\n }\n\n // save data\n var trial_data = {\n rt: response_time,\n response: question_data,\n question_order: question_order,\n };\n\n // next trial\n this.jsPsych.finishTrial(trial_data);\n });\n\n var startTime = performance.now();\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const question_data = {};\n let rt = 1000;\n\n for (const q of trial.questions) {\n const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;\n question_data[name] = this.jsPsych.randomization.randomInt(0, q.labels.length - 1);\n rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);\n }\n\n const default_data = {\n response: question_data,\n rt: rt,\n question_order: trial.randomize_question_order\n ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])\n : [...Array(trial.questions.length).keys()],\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n const answers = Object.entries(data.response);\n for (let i = 0; i < answers.length; i++) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\n `input[type=\"radio\"][name=\"${answers[i][0]}\"][value=\"${answers[i][1]}\"]`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\"#jspsych-survey-likert-next\"),\n data.rt\n );\n }\n}\n\nexport default SurveyLikertPlugin;\n"],"names":[],"mappings":";;;EAEE,IAAW,OAAA,GAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ICiFA,SAAA,EAAA;EAAA;;KAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,2 +1,2 @@
1
- var jsPsychSurveyLikert=function(i){"use strict";var P="2.0.1";const g={name:"survey-likert",version:P,parameters:{questions:{type:i.ParameterType.COMPLEX,array:!0,nested:{prompt:{type:i.ParameterType.HTML_STRING,default:void 0},labels:{type:i.ParameterType.STRING,array:!0,default:void 0},required:{type:i.ParameterType.BOOL,default:!1},name:{type:i.ParameterType.STRING,default:""}}},randomize_question_order:{type:i.ParameterType.BOOL,default:!1},preamble:{type:i.ParameterType.HTML_STRING,default:null},scale_width:{type:i.ParameterType.INT,default:null},button_label:{type:i.ParameterType.STRING,default:"Continue"},autocomplete:{type:i.ParameterType.BOOL,default:!1}},data:{response:{type:i.ParameterType.OBJECT},rt:{type:i.ParameterType.INT},question_order:{type:i.ParameterType.INT,array:!0}}};class d{constructor(e){this.jsPsych=e}trial(e,r){if(r.scale_width!==null)var n=r.scale_width+"px";else var n="100%";var t="";t+='<style id="jspsych-survey-likert-css">',t+=".jspsych-survey-likert-statement { display:block; font-size: 16px; padding-top: 40px; margin-bottom:10px; }.jspsych-survey-likert-opts { list-style:none; width:"+n+"; margin:auto; padding:0 0 35px; display:block; font-size: 14px; line-height:1.1em; }.jspsych-survey-likert-opt-label { line-height: 1.1em; color: #444; }.jspsych-survey-likert-opts:before { content: ''; position:relative; top:11px; /*left:9.5%;*/ display:block; background-color:#efefef; height:4px; width:100%; }.jspsych-survey-likert-opts:last-of-type { border-bottom: 0; }.jspsych-survey-likert-opts li { display:inline-block; /*width:19%;*/ text-align:center; vertical-align: top; }.jspsych-survey-likert-opts li input[type=radio] { display:block; position:relative; top:0; left:50%; margin-left:-6px; }",t+="</style>",r.preamble!==null&&(t+='<div id="jspsych-survey-likert-preamble" class="jspsych-survey-likert-preamble">'+r.preamble+"</div>"),r.autocomplete?t+='<form id="jspsych-survey-likert-form">':t+='<form id="jspsych-survey-likert-form" autocomplete="off">';for(var l=[],a=0;a<r.questions.length;a++)l.push(a);r.randomize_question_order&&(l=this.jsPsych.randomization.shuffle(l));for(var a=0;a<r.questions.length;a++){var s=r.questions[l[a]];t+='<label class="jspsych-survey-likert-statement">'+s.prompt+"</label>";for(var c=100/s.labels.length,o='<ul class="jspsych-survey-likert-opts" data-name="'+s.name+'" data-radio-group="Q'+l[a]+'">',p=0;p<s.labels.length;p++)o+='<li style="width:'+c+'%"><label class="jspsych-survey-likert-opt-label"><input type="radio" name="Q'+l[a]+'" value="'+p+'"',s.required&&(o+=" required"),o+=">"+s.labels[p]+"</label></li>";o+="</ul>",t+=o}t+='<input type="submit" id="jspsych-survey-likert-next" class="jspsych-survey-likert jspsych-btn" value="'+r.button_label+'"></input>',t+="</form>",e.innerHTML=t,e.querySelector("#jspsych-survey-likert-form").addEventListener("submit",_=>{_.preventDefault();for(var j=performance.now(),q=Math.round(j-T),m={},y=e.querySelectorAll("#jspsych-survey-likert-form .jspsych-survey-likert-opts"),u=0;u<y.length;u++){var h=y[u].dataset.radioGroup,v=e.querySelector('input[name="'+h+'"]:checked');if(v===null)var f="";else var f=parseInt(v.value);var b={};if(y[u].attributes["data-name"].value!=="")var k=y[u].attributes["data-name"].value;else var k=h;b[k]=f,Object.assign(m,b)}var x={rt:q,response:m,question_order:l};this.jsPsych.finishTrial(x)});var T=performance.now()}simulate(e,r,n,t){r=="data-only"&&(t(),this.simulate_data_only(e,n)),r=="visual"&&this.simulate_visual(e,n,t)}create_simulation_data(e,r){const n={};let t=1e3;for(const s of e.questions){const c=s.name?s.name:`Q${e.questions.indexOf(s)}`;n[c]=this.jsPsych.randomization.randomInt(0,s.labels.length-1),t+=this.jsPsych.randomization.sampleExGaussian(1500,400,.005,!0)}const l={response:n,rt:t,question_order:e.randomize_question_order?this.jsPsych.randomization.shuffle([...Array(e.questions.length).keys()]):[...Array(e.questions.length).keys()]},a=this.jsPsych.pluginAPI.mergeSimulationData(l,r);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(e,a),a}simulate_data_only(e,r){const n=this.create_simulation_data(e,r);this.jsPsych.finishTrial(n)}simulate_visual(e,r,n){const t=this.create_simulation_data(e,r),l=this.jsPsych.getDisplayElement();this.trial(l,e),n();const a=Object.entries(t.response);for(let s=0;s<a.length;s++)this.jsPsych.pluginAPI.clickTarget(l.querySelector(`input[type="radio"][name="${a[s][0]}"][value="${a[s][1]}"]`),(t.rt-1e3)/a.length*(s+1));this.jsPsych.pluginAPI.clickTarget(l.querySelector("#jspsych-survey-likert-next"),t.rt)}}return d.info=g,d}(jsPsychModule);
2
- //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-likert@2.0.1/dist/index.browser.min.js.map
1
+ var jsPsychSurveyLikert=function(l){"use strict";var j="2.2.0";const P={name:"survey-likert",version:j,parameters:{questions:{type:l.ParameterType.COMPLEX,array:!0,nested:{prompt:{type:l.ParameterType.HTML_STRING,default:void 0},labels:{type:l.ParameterType.STRING,array:!0,default:void 0},required:{type:l.ParameterType.BOOL,default:!1},name:{type:l.ParameterType.STRING,default:""},default_response:{type:l.ParameterType.INT,default:null}}},randomize_question_order:{type:l.ParameterType.BOOL,default:!1},preamble:{type:l.ParameterType.HTML_STRING,default:null},scale_width:{type:l.ParameterType.INT,default:null},button_label:{type:l.ParameterType.STRING,default:"Continue"},autocomplete:{type:l.ParameterType.BOOL,default:!1}},data:{response:{type:l.ParameterType.OBJECT},rt:{type:l.ParameterType.INT},question_order:{type:l.ParameterType.INT,array:!0}},citations:{apa:"de Leeuw, J. R., Gilbert, R. A., & Luchterhandt, B. (2023). jsPsych: Enabling an Open-Source Collaborative Ecosystem of Behavioral Experiments. Journal of Open Source Software, 8(85), 5351. https://doi.org/10.21105/joss.05351 ",bibtex:'@article{Leeuw2023jsPsych, author = {de Leeuw, Joshua R. and Gilbert, Rebecca A. and Luchterhandt, Bj{\\" o}rn}, journal = {Journal of Open Source Software}, doi = {10.21105/joss.05351}, issn = {2475-9066}, number = {85}, year = {2023}, month = {may 11}, pages = {5351}, publisher = {Open Journals}, title = {jsPsych: Enabling an {Open}-{Source} {Collaborative} {Ecosystem} of {Behavioral} {Experiments}}, url = {https://joss.theoj.org/papers/10.21105/joss.05351}, volume = {8}, } '}};class d{constructor(e){this.jsPsych=e}trial(e,r){if(r.scale_width!==null)var o=r.scale_width+"px";else var o="100%";var t="";t+='<style id="jspsych-survey-likert-css">',t+=".jspsych-survey-likert-statement { display:block; font-size: 16px; padding-top: 40px; margin-bottom:10px; }.jspsych-survey-likert-opts { list-style:none; width:"+o+"; margin:auto; padding:0 0 35px; display:block; font-size: 14px; line-height:1.1em; }.jspsych-survey-likert-opt-label { line-height: 1.1em; color: #444; }.jspsych-survey-likert-opts:before { content: ''; position:relative; top:11px; /*left:9.5%;*/ display:block; background-color:#efefef; height:4px; width:100%; }.jspsych-survey-likert-opts:last-of-type { border-bottom: 0; }.jspsych-survey-likert-opts li { display:inline-block; /*width:19%;*/ text-align:center; vertical-align: top; }.jspsych-survey-likert-opts li input[type=radio] { display:block; position:relative; top:0; left:50%; margin-left:-6px; }",t+="</style>",r.preamble!==null&&(t+='<div id="jspsych-survey-likert-preamble" class="jspsych-survey-likert-preamble">'+r.preamble+"</div>"),r.autocomplete?t+='<form id="jspsych-survey-likert-form">':t+='<form id="jspsych-survey-likert-form" autocomplete="off">';for(var i=[],s=0;s<r.questions.length;s++)i.push(s);r.randomize_question_order&&(i=this.jsPsych.randomization.shuffle(i));for(var s=0;s<r.questions.length;s++){var a=r.questions[i[s]];t+='<label class="jspsych-survey-likert-statement">'+a.prompt+"</label>";for(var c=100/a.labels.length,n='<ul class="jspsych-survey-likert-opts" data-name="'+a.name+'" data-radio-group="Q'+i[s]+'">',u=0;u<a.labels.length;u++)n+='<li style="width:'+c+'%"><label class="jspsych-survey-likert-opt-label"><input type="radio" name="Q'+i[s]+'" value="'+u+'"',a.required&&(n+=" required"),a.default_response===u&&(n+=" checked"),n+=">"+a.labels[u]+"</label></li>";n+="</ul>",t+=n}t+='<input type="submit" id="jspsych-survey-likert-next" class="jspsych-survey-likert jspsych-btn" value="'+r.button_label+'"></input>',t+="</form>",e.innerHTML=t,e.querySelector("#jspsych-survey-likert-form").addEventListener("submit",T=>{T.preventDefault();for(var _=performance.now(),q=Math.round(_-k),h={},y=e.querySelectorAll("#jspsych-survey-likert-form .jspsych-survey-likert-opts"),p=0;p<y.length;p++){var m=y[p].dataset.radioGroup,v=e.querySelector('input[name="'+m+'"]:checked');if(v===null)var f="";else var f=parseInt(v.value);var b={};if(y[p].attributes["data-name"].value!=="")var g=y[p].attributes["data-name"].value;else var g=m;b[g]=f,Object.assign(h,b)}var S={rt:q,response:h,question_order:i};this.jsPsych.finishTrial(S)});var k=performance.now()}simulate(e,r,o,t){r=="data-only"&&(t(),this.simulate_data_only(e,o)),r=="visual"&&this.simulate_visual(e,o,t)}create_simulation_data(e,r){const o={};let t=1e3;for(const a of e.questions){const c=a.name?a.name:`Q${e.questions.indexOf(a)}`;o[c]=this.jsPsych.randomization.randomInt(0,a.labels.length-1),t+=this.jsPsych.randomization.sampleExGaussian(1500,400,.005,!0)}const i={response:o,rt:t,question_order:e.randomize_question_order?this.jsPsych.randomization.shuffle([...Array(e.questions.length).keys()]):[...Array(e.questions.length).keys()]},s=this.jsPsych.pluginAPI.mergeSimulationData(i,r);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(e,s),s}simulate_data_only(e,r){const o=this.create_simulation_data(e,r);this.jsPsych.finishTrial(o)}simulate_visual(e,r,o){const t=this.create_simulation_data(e,r),i=this.jsPsych.getDisplayElement();this.trial(i,e),o();const s=Object.entries(t.response);for(let a=0;a<s.length;a++)this.jsPsych.pluginAPI.clickTarget(i.querySelector(`input[type="radio"][name="${s[a][0]}"][value="${s[a][1]}"]`),(t.rt-1e3)/s.length*(a+1));this.jsPsych.pluginAPI.clickTarget(i.querySelector("#jspsych-survey-likert-next"),t.rt)}}return d.info=P,d}(jsPsychModule);
2
+ //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-likert@2.2.0/dist/index.browser.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.browser.min.js","sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@jspsych/plugin-survey-likert\",\n \"version\": \"2.0.1\",\n \"description\": \"a jspsych plugin for measuring items on a likert scale\",\n \"type\": \"module\",\n \"main\": \"dist/index.cjs\",\n \"exports\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"typings\": \"dist/index.d.ts\",\n \"unpkg\": \"dist/index.browser.min.js\",\n \"files\": [\n \"src\",\n \"dist\"\n ],\n \"source\": \"src/index.ts\",\n \"scripts\": {\n \"test\": \"jest\",\n \"test:watch\": \"npm test -- --watch\",\n \"tsc\": \"tsc\",\n \"build\": \"rollup --config\",\n \"build:watch\": \"npm run build -- --watch\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/jspsych/jsPsych.git\",\n \"directory\": \"packages/plugin-survey-likert\"\n },\n \"author\": \"Josh de Leeuw\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/jspsych/jsPsych/issues\"\n },\n \"homepage\": \"https://www.jspsych.org/latest/plugins/survey-likert\",\n \"peerDependencies\": {\n \"jspsych\": \">=7.1.0\"\n },\n \"devDependencies\": {\n \"@jspsych/config\": \"^3.1.1\",\n \"@jspsych/test-utils\": \"^1.2.0\"\n }\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"survey-likert\",\n version: version,\n parameters: {\n /** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */\n questions: {\n type: ParameterType.COMPLEX,\n array: true,\n nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: undefined,\n },\n /** Array of likert labels to display for this question. */\n labels: {\n type: ParameterType.STRING,\n array: true,\n default: undefined,\n },\n /** Whether or not a response to this question must be given in order to continue. */\n required: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */\n name: {\n type: ParameterType.STRING,\n default: \"\",\n },\n },\n },\n /** If true, the order of the questions in the 'questions' array will be randomized. */\n randomize_question_order: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** HTML-formatted string to display at top of the page above all of the questions. */\n preamble: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** Width of the likert scales in pixels. */\n scale_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to submit responses. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n },\n /** Setting this to true will enable browser auto-complete or auto-fill for the form. */\n autocomplete: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\n /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n response: {\n type: ParameterType.OBJECT,\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */\n rt: {\n type: ParameterType.INT,\n },\n /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n question_order: {\n type: ParameterType.INT,\n array: true,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * The survey-likert plugin displays a set of questions with Likert scale responses. The participant responds\n * by selecting a radio button.\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/survey-likert/ survey-likert plugin documentation on jspsych.org}\n */\nclass SurveyLikertPlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n if (trial.scale_width !== null) {\n var w = trial.scale_width + \"px\";\n } else {\n var w = \"100%\";\n }\n\n var html = \"\";\n // inject CSS for trial\n html += '<style id=\"jspsych-survey-likert-css\">';\n html +=\n \".jspsych-survey-likert-statement { display:block; font-size: 16px; padding-top: 40px; margin-bottom:10px; }\" +\n \".jspsych-survey-likert-opts { list-style:none; width:\" +\n w +\n \"; margin:auto; padding:0 0 35px; display:block; font-size: 14px; line-height:1.1em; }\" +\n \".jspsych-survey-likert-opt-label { line-height: 1.1em; color: #444; }\" +\n \".jspsych-survey-likert-opts:before { content: ''; position:relative; top:11px; /*left:9.5%;*/ display:block; background-color:#efefef; height:4px; width:100%; }\" +\n \".jspsych-survey-likert-opts:last-of-type { border-bottom: 0; }\" +\n \".jspsych-survey-likert-opts li { display:inline-block; /*width:19%;*/ text-align:center; vertical-align: top; }\" +\n \".jspsych-survey-likert-opts li input[type=radio] { display:block; position:relative; top:0; left:50%; margin-left:-6px; }\";\n html += \"</style>\";\n\n // show preamble text\n if (trial.preamble !== null) {\n html +=\n '<div id=\"jspsych-survey-likert-preamble\" class=\"jspsych-survey-likert-preamble\">' +\n trial.preamble +\n \"</div>\";\n }\n\n if (trial.autocomplete) {\n html += '<form id=\"jspsych-survey-likert-form\">';\n } else {\n html += '<form id=\"jspsych-survey-likert-form\" autocomplete=\"off\">';\n }\n\n // add likert scale questions ///\n // generate question order. this is randomized here as opposed to randomizing the order of trial.questions\n // so that the data are always associated with the same question regardless of order\n var question_order = [];\n for (var i = 0; i < trial.questions.length; i++) {\n question_order.push(i);\n }\n if (trial.randomize_question_order) {\n question_order = this.jsPsych.randomization.shuffle(question_order);\n }\n\n for (var i = 0; i < trial.questions.length; i++) {\n var question = trial.questions[question_order[i]];\n // add question\n html += '<label class=\"jspsych-survey-likert-statement\">' + question.prompt + \"</label>\";\n // add options\n var width = 100 / question.labels.length;\n var options_string =\n '<ul class=\"jspsych-survey-likert-opts\" data-name=\"' +\n question.name +\n '\" data-radio-group=\"Q' +\n question_order[i] +\n '\">';\n for (var j = 0; j < question.labels.length; j++) {\n options_string +=\n '<li style=\"width:' +\n width +\n '%\"><label class=\"jspsych-survey-likert-opt-label\"><input type=\"radio\" name=\"Q' +\n question_order[i] +\n '\" value=\"' +\n j +\n '\"';\n if (question.required) {\n options_string += \" required\";\n }\n options_string += \">\" + question.labels[j] + \"</label></li>\";\n }\n options_string += \"</ul>\";\n html += options_string;\n }\n\n // add submit button\n html +=\n '<input type=\"submit\" id=\"jspsych-survey-likert-next\" class=\"jspsych-survey-likert jspsych-btn\" value=\"' +\n trial.button_label +\n '\"></input>';\n\n html += \"</form>\";\n\n display_element.innerHTML = html;\n\n display_element.querySelector(\"#jspsych-survey-likert-form\").addEventListener(\"submit\", (e) => {\n e.preventDefault();\n // measure response time\n var endTime = performance.now();\n var response_time = Math.round(endTime - startTime);\n\n // create object to hold responses\n var question_data = {};\n var matches = display_element.querySelectorAll<HTMLFormElement>(\n \"#jspsych-survey-likert-form .jspsych-survey-likert-opts\"\n );\n for (var index = 0; index < matches.length; index++) {\n var id = matches[index].dataset[\"radioGroup\"];\n var el = display_element.querySelector<HTMLInputElement>(\n 'input[name=\"' + id + '\"]:checked'\n );\n if (el === null) {\n var response: string | number = \"\";\n } else {\n var response: string | number = parseInt(el.value);\n }\n var obje = {};\n if (matches[index].attributes[\"data-name\"].value !== \"\") {\n var name = matches[index].attributes[\"data-name\"].value;\n } else {\n var name = id;\n }\n obje[name] = response;\n Object.assign(question_data, obje);\n }\n\n // save data\n var trial_data = {\n rt: response_time,\n response: question_data,\n question_order: question_order,\n };\n\n // next trial\n this.jsPsych.finishTrial(trial_data);\n });\n\n var startTime = performance.now();\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const question_data = {};\n let rt = 1000;\n\n for (const q of trial.questions) {\n const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;\n question_data[name] = this.jsPsych.randomization.randomInt(0, q.labels.length - 1);\n rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);\n }\n\n const default_data = {\n response: question_data,\n rt: rt,\n question_order: trial.randomize_question_order\n ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])\n : [...Array(trial.questions.length).keys()],\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n const answers = Object.entries(data.response);\n for (let i = 0; i < answers.length; i++) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\n `input[type=\"radio\"][name=\"${answers[i][0]}\"][value=\"${answers[i][1]}\"]`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\"#jspsych-survey-likert-next\"),\n data.rt\n );\n }\n}\n\nexport default SurveyLikertPlugin;\n"],"names":["version","info","ParameterType","SurveyLikertPlugin","jsPsych","display_element","trial","w","html","question_order","i","question","width","options_string","j","e","endTime","response_time","startTime","question_data","matches","index","id","el","response","obje","name","trial_data","simulation_mode","simulation_options","load_callback","rt","q","default_data","data","answers"],"mappings":"iDAEEA,IAAAA,EAAW,QCEb,MAAMC,EAAc,CAClB,KAAM,gBACN,QAASD,EACT,WAAY,CAEV,UAAW,CACT,KAAME,gBAAc,QACpB,MAAO,GACP,OAAQ,CAEN,OAAQ,CACN,KAAMA,EAAAA,cAAc,YACpB,QAAS,MACX,EAEA,OAAQ,CACN,KAAMA,E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AClC,KAAK,QAAQ,UAAU,YACrBL,EAAgB,cACd,6BAA6B8B,EAAQzB,CAAC,EAAE,CAAC,CAAC,aAAayB,EAAQzB,CAAC,EAAE,CAAC,CAAC,IACtE,GACEwB,EAAK,GAAK,KAAQC,EAAQ,QAAWzB,EAAI,EAC7C,EAGF,KAAK,QAAQ,UAAU,YACrBL,EAAgB,cAAc,6BAA6B,EAC3D6B,EAAK,EACP,CACF,CACF,CA9MM/B,OAAAA,EACG,KAAOF"}
1
+ {"version":3,"file":"index.browser.min.js","sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@jspsych/plugin-survey-likert\",\n \"version\": \"2.2.0\",\n \"description\": \"a jspsych plugin for measuring items on a likert scale\",\n \"type\": \"module\",\n \"main\": \"dist/index.cjs\",\n \"exports\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"typings\": \"dist/index.d.ts\",\n \"unpkg\": \"dist/index.browser.min.js\",\n \"files\": [\n \"src\",\n \"dist\"\n ],\n \"source\": \"src/index.ts\",\n \"scripts\": {\n \"test\": \"jest\",\n \"test:watch\": \"npm test -- --watch\",\n \"tsc\": \"tsc\",\n \"build\": \"rollup --config\",\n \"build:watch\": \"npm run build -- --watch\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/jspsych/jsPsych.git\",\n \"directory\": \"packages/plugin-survey-likert\"\n },\n \"author\": \"Josh de Leeuw\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/jspsych/jsPsych/issues\"\n },\n \"homepage\": \"https://www.jspsych.org/latest/plugins/survey-likert\",\n \"peerDependencies\": {\n \"jspsych\": \">=7.1.0\"\n },\n \"devDependencies\": {\n \"@jspsych/config\": \"^3.2.0\",\n \"@jspsych/test-utils\": \"^1.2.0\"\n }\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"survey-likert\",\n version: version,\n parameters: {\n /** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */\n questions: {\n type: ParameterType.COMPLEX,\n array: true,\n nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: undefined,\n },\n /** Array of likert labels to display for this question. */\n labels: {\n type: ParameterType.STRING,\n array: true,\n default: undefined,\n },\n /** Whether or not a response to this question must be given in order to continue. */\n required: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */\n name: {\n type: ParameterType.STRING,\n default: \"\",\n },\n /** Default response value for this question (0-based index of labels array). */\n default_response: {\n type: ParameterType.INT,\n default: null,\n },\n },\n },\n /** If true, the order of the questions in the 'questions' array will be randomized. */\n randomize_question_order: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** HTML-formatted string to display at top of the page above all of the questions. */\n preamble: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** Width of the likert scales in pixels. */\n scale_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to submit responses. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n },\n /** Setting this to true will enable browser auto-complete or auto-fill for the form. */\n autocomplete: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\n /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n response: {\n type: ParameterType.OBJECT,\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */\n rt: {\n type: ParameterType.INT,\n },\n /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n question_order: {\n type: ParameterType.INT,\n array: true,\n },\n },\n // prettier-ignore\n citations: '__CITATIONS__',\n};\n\ntype Info = typeof info;\n\n/**\n * The survey-likert plugin displays a set of questions with Likert scale responses. The participant responds\n * by selecting a radio button.\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/survey-likert/ survey-likert plugin documentation on jspsych.org}\n */\nclass SurveyLikertPlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n if (trial.scale_width !== null) {\n var w = trial.scale_width + \"px\";\n } else {\n var w = \"100%\";\n }\n\n var html = \"\";\n // inject CSS for trial\n html += '<style id=\"jspsych-survey-likert-css\">';\n html +=\n \".jspsych-survey-likert-statement { display:block; font-size: 16px; padding-top: 40px; margin-bottom:10px; }\" +\n \".jspsych-survey-likert-opts { list-style:none; width:\" +\n w +\n \"; margin:auto; padding:0 0 35px; display:block; font-size: 14px; line-height:1.1em; }\" +\n \".jspsych-survey-likert-opt-label { line-height: 1.1em; color: #444; }\" +\n \".jspsych-survey-likert-opts:before { content: ''; position:relative; top:11px; /*left:9.5%;*/ display:block; background-color:#efefef; height:4px; width:100%; }\" +\n \".jspsych-survey-likert-opts:last-of-type { border-bottom: 0; }\" +\n \".jspsych-survey-likert-opts li { display:inline-block; /*width:19%;*/ text-align:center; vertical-align: top; }\" +\n \".jspsych-survey-likert-opts li input[type=radio] { display:block; position:relative; top:0; left:50%; margin-left:-6px; }\";\n html += \"</style>\";\n\n // show preamble text\n if (trial.preamble !== null) {\n html +=\n '<div id=\"jspsych-survey-likert-preamble\" class=\"jspsych-survey-likert-preamble\">' +\n trial.preamble +\n \"</div>\";\n }\n\n if (trial.autocomplete) {\n html += '<form id=\"jspsych-survey-likert-form\">';\n } else {\n html += '<form id=\"jspsych-survey-likert-form\" autocomplete=\"off\">';\n }\n\n // add likert scale questions ///\n // generate question order. this is randomized here as opposed to randomizing the order of trial.questions\n // so that the data are always associated with the same question regardless of order\n var question_order = [];\n for (var i = 0; i < trial.questions.length; i++) {\n question_order.push(i);\n }\n if (trial.randomize_question_order) {\n question_order = this.jsPsych.randomization.shuffle(question_order);\n }\n\n for (var i = 0; i < trial.questions.length; i++) {\n var question = trial.questions[question_order[i]];\n // add question\n html += '<label class=\"jspsych-survey-likert-statement\">' + question.prompt + \"</label>\";\n // add options\n var width = 100 / question.labels.length;\n var options_string =\n '<ul class=\"jspsych-survey-likert-opts\" data-name=\"' +\n question.name +\n '\" data-radio-group=\"Q' +\n question_order[i] +\n '\">';\n for (var j = 0; j < question.labels.length; j++) {\n options_string +=\n '<li style=\"width:' +\n width +\n '%\"><label class=\"jspsych-survey-likert-opt-label\"><input type=\"radio\" name=\"Q' +\n question_order[i] +\n '\" value=\"' +\n j +\n '\"';\n if (question.required) {\n options_string += \" required\";\n }\n if (question.default_response === j) {\n options_string += \" checked\";\n }\n options_string += \">\" + question.labels[j] + \"</label></li>\";\n }\n options_string += \"</ul>\";\n html += options_string;\n }\n\n // add submit button\n html +=\n '<input type=\"submit\" id=\"jspsych-survey-likert-next\" class=\"jspsych-survey-likert jspsych-btn\" value=\"' +\n trial.button_label +\n '\"></input>';\n\n html += \"</form>\";\n\n display_element.innerHTML = html;\n\n display_element.querySelector(\"#jspsych-survey-likert-form\").addEventListener(\"submit\", (e) => {\n e.preventDefault();\n // measure response time\n var endTime = performance.now();\n var response_time = Math.round(endTime - startTime);\n\n // create object to hold responses\n var question_data = {};\n var matches = display_element.querySelectorAll<HTMLFormElement>(\n \"#jspsych-survey-likert-form .jspsych-survey-likert-opts\"\n );\n for (var index = 0; index < matches.length; index++) {\n var id = matches[index].dataset[\"radioGroup\"];\n var el = display_element.querySelector<HTMLInputElement>(\n 'input[name=\"' + id + '\"]:checked'\n );\n if (el === null) {\n var response: string | number = \"\";\n } else {\n var response: string | number = parseInt(el.value);\n }\n var obje = {};\n if (matches[index].attributes[\"data-name\"].value !== \"\") {\n var name = matches[index].attributes[\"data-name\"].value;\n } else {\n var name = id;\n }\n obje[name] = response;\n Object.assign(question_data, obje);\n }\n\n // save data\n var trial_data = {\n rt: response_time,\n response: question_data,\n question_order: question_order,\n };\n\n // next trial\n this.jsPsych.finishTrial(trial_data);\n });\n\n var startTime = performance.now();\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const question_data = {};\n let rt = 1000;\n\n for (const q of trial.questions) {\n const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;\n question_data[name] = this.jsPsych.randomization.randomInt(0, q.labels.length - 1);\n rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);\n }\n\n const default_data = {\n response: question_data,\n rt: rt,\n question_order: trial.randomize_question_order\n ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])\n : [...Array(trial.questions.length).keys()],\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n const answers = Object.entries(data.response);\n for (let i = 0; i < answers.length; i++) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\n `input[type=\"radio\"][name=\"${answers[i][0]}\"][value=\"${answers[i][1]}\"]`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\"#jspsych-survey-likert-next\"),\n data.rt\n );\n }\n}\n\nexport default SurveyLikertPlugin;\n"],"names":["version"],"mappings":"iDAEEA,IAAAA,EAAW,myBCiFA,UAAA,iuBAAe"}
package/dist/index.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  var jspsych = require('jspsych');
4
4
 
5
- var version = "2.0.1";
5
+ var version = "2.2.0";
6
6
 
7
7
  const info = {
8
8
  name: "survey-likert",
@@ -33,6 +33,11 @@ const info = {
33
33
  name: {
34
34
  type: jspsych.ParameterType.STRING,
35
35
  default: ""
36
+ },
37
+ /** Default response value for this question (0-based index of labels array). */
38
+ default_response: {
39
+ type: jspsych.ParameterType.INT,
40
+ default: null
36
41
  }
37
42
  }
38
43
  },
@@ -76,6 +81,11 @@ const info = {
76
81
  type: jspsych.ParameterType.INT,
77
82
  array: true
78
83
  }
84
+ },
85
+ // prettier-ignore
86
+ citations: {
87
+ "apa": "de Leeuw, J. R., Gilbert, R. A., & Luchterhandt, B. (2023). jsPsych: Enabling an Open-Source Collaborative Ecosystem of Behavioral Experiments. Journal of Open Source Software, 8(85), 5351. https://doi.org/10.21105/joss.05351 ",
88
+ "bibtex": '@article{Leeuw2023jsPsych, author = {de Leeuw, Joshua R. and Gilbert, Rebecca A. and Luchterhandt, Bj{\\" o}rn}, journal = {Journal of Open Source Software}, doi = {10.21105/joss.05351}, issn = {2475-9066}, number = {85}, year = {2023}, month = {may 11}, pages = {5351}, publisher = {Open Journals}, title = {jsPsych: Enabling an {Open}-{Source} {Collaborative} {Ecosystem} of {Behavioral} {Experiments}}, url = {https://joss.theoj.org/papers/10.21105/joss.05351}, volume = {8}, } '
79
89
  }
80
90
  };
81
91
  class SurveyLikertPlugin {
@@ -120,6 +130,9 @@ class SurveyLikertPlugin {
120
130
  if (question.required) {
121
131
  options_string += " required";
122
132
  }
133
+ if (question.default_response === j) {
134
+ options_string += " checked";
135
+ }
123
136
  options_string += ">" + question.labels[j] + "</label></li>";
124
137
  }
125
138
  options_string += "</ul>";
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@jspsych/plugin-survey-likert\",\n \"version\": \"2.0.1\",\n \"description\": \"a jspsych plugin for measuring items on a likert scale\",\n \"type\": \"module\",\n \"main\": \"dist/index.cjs\",\n \"exports\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"typings\": \"dist/index.d.ts\",\n \"unpkg\": \"dist/index.browser.min.js\",\n \"files\": [\n \"src\",\n \"dist\"\n ],\n \"source\": \"src/index.ts\",\n \"scripts\": {\n \"test\": \"jest\",\n \"test:watch\": \"npm test -- --watch\",\n \"tsc\": \"tsc\",\n \"build\": \"rollup --config\",\n \"build:watch\": \"npm run build -- --watch\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/jspsych/jsPsych.git\",\n \"directory\": \"packages/plugin-survey-likert\"\n },\n \"author\": \"Josh de Leeuw\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/jspsych/jsPsych/issues\"\n },\n \"homepage\": \"https://www.jspsych.org/latest/plugins/survey-likert\",\n \"peerDependencies\": {\n \"jspsych\": \">=7.1.0\"\n },\n \"devDependencies\": {\n \"@jspsych/config\": \"^3.1.1\",\n \"@jspsych/test-utils\": \"^1.2.0\"\n }\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"survey-likert\",\n version: version,\n parameters: {\n /** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */\n questions: {\n type: ParameterType.COMPLEX,\n array: true,\n nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: undefined,\n },\n /** Array of likert labels to display for this question. */\n labels: {\n type: ParameterType.STRING,\n array: true,\n default: undefined,\n },\n /** Whether or not a response to this question must be given in order to continue. */\n required: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */\n name: {\n type: ParameterType.STRING,\n default: \"\",\n },\n },\n },\n /** If true, the order of the questions in the 'questions' array will be randomized. */\n randomize_question_order: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** HTML-formatted string to display at top of the page above all of the questions. */\n preamble: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** Width of the likert scales in pixels. */\n scale_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to submit responses. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n },\n /** Setting this to true will enable browser auto-complete or auto-fill for the form. */\n autocomplete: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\n /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n response: {\n type: ParameterType.OBJECT,\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */\n rt: {\n type: ParameterType.INT,\n },\n /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n question_order: {\n type: ParameterType.INT,\n array: true,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * The survey-likert plugin displays a set of questions with Likert scale responses. The participant responds\n * by selecting a radio button.\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/survey-likert/ survey-likert plugin documentation on jspsych.org}\n */\nclass SurveyLikertPlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n if (trial.scale_width !== null) {\n var w = trial.scale_width + \"px\";\n } else {\n var w = \"100%\";\n }\n\n var html = \"\";\n // inject CSS for trial\n html += '<style id=\"jspsych-survey-likert-css\">';\n html +=\n \".jspsych-survey-likert-statement { display:block; font-size: 16px; padding-top: 40px; margin-bottom:10px; }\" +\n \".jspsych-survey-likert-opts { list-style:none; width:\" +\n w +\n \"; margin:auto; padding:0 0 35px; display:block; font-size: 14px; line-height:1.1em; }\" +\n \".jspsych-survey-likert-opt-label { line-height: 1.1em; color: #444; }\" +\n \".jspsych-survey-likert-opts:before { content: ''; position:relative; top:11px; /*left:9.5%;*/ display:block; background-color:#efefef; height:4px; width:100%; }\" +\n \".jspsych-survey-likert-opts:last-of-type { border-bottom: 0; }\" +\n \".jspsych-survey-likert-opts li { display:inline-block; /*width:19%;*/ text-align:center; vertical-align: top; }\" +\n \".jspsych-survey-likert-opts li input[type=radio] { display:block; position:relative; top:0; left:50%; margin-left:-6px; }\";\n html += \"</style>\";\n\n // show preamble text\n if (trial.preamble !== null) {\n html +=\n '<div id=\"jspsych-survey-likert-preamble\" class=\"jspsych-survey-likert-preamble\">' +\n trial.preamble +\n \"</div>\";\n }\n\n if (trial.autocomplete) {\n html += '<form id=\"jspsych-survey-likert-form\">';\n } else {\n html += '<form id=\"jspsych-survey-likert-form\" autocomplete=\"off\">';\n }\n\n // add likert scale questions ///\n // generate question order. this is randomized here as opposed to randomizing the order of trial.questions\n // so that the data are always associated with the same question regardless of order\n var question_order = [];\n for (var i = 0; i < trial.questions.length; i++) {\n question_order.push(i);\n }\n if (trial.randomize_question_order) {\n question_order = this.jsPsych.randomization.shuffle(question_order);\n }\n\n for (var i = 0; i < trial.questions.length; i++) {\n var question = trial.questions[question_order[i]];\n // add question\n html += '<label class=\"jspsych-survey-likert-statement\">' + question.prompt + \"</label>\";\n // add options\n var width = 100 / question.labels.length;\n var options_string =\n '<ul class=\"jspsych-survey-likert-opts\" data-name=\"' +\n question.name +\n '\" data-radio-group=\"Q' +\n question_order[i] +\n '\">';\n for (var j = 0; j < question.labels.length; j++) {\n options_string +=\n '<li style=\"width:' +\n width +\n '%\"><label class=\"jspsych-survey-likert-opt-label\"><input type=\"radio\" name=\"Q' +\n question_order[i] +\n '\" value=\"' +\n j +\n '\"';\n if (question.required) {\n options_string += \" required\";\n }\n options_string += \">\" + question.labels[j] + \"</label></li>\";\n }\n options_string += \"</ul>\";\n html += options_string;\n }\n\n // add submit button\n html +=\n '<input type=\"submit\" id=\"jspsych-survey-likert-next\" class=\"jspsych-survey-likert jspsych-btn\" value=\"' +\n trial.button_label +\n '\"></input>';\n\n html += \"</form>\";\n\n display_element.innerHTML = html;\n\n display_element.querySelector(\"#jspsych-survey-likert-form\").addEventListener(\"submit\", (e) => {\n e.preventDefault();\n // measure response time\n var endTime = performance.now();\n var response_time = Math.round(endTime - startTime);\n\n // create object to hold responses\n var question_data = {};\n var matches = display_element.querySelectorAll<HTMLFormElement>(\n \"#jspsych-survey-likert-form .jspsych-survey-likert-opts\"\n );\n for (var index = 0; index < matches.length; index++) {\n var id = matches[index].dataset[\"radioGroup\"];\n var el = display_element.querySelector<HTMLInputElement>(\n 'input[name=\"' + id + '\"]:checked'\n );\n if (el === null) {\n var response: string | number = \"\";\n } else {\n var response: string | number = parseInt(el.value);\n }\n var obje = {};\n if (matches[index].attributes[\"data-name\"].value !== \"\") {\n var name = matches[index].attributes[\"data-name\"].value;\n } else {\n var name = id;\n }\n obje[name] = response;\n Object.assign(question_data, obje);\n }\n\n // save data\n var trial_data = {\n rt: response_time,\n response: question_data,\n question_order: question_order,\n };\n\n // next trial\n this.jsPsych.finishTrial(trial_data);\n });\n\n var startTime = performance.now();\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const question_data = {};\n let rt = 1000;\n\n for (const q of trial.questions) {\n const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;\n question_data[name] = this.jsPsych.randomization.randomInt(0, q.labels.length - 1);\n rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);\n }\n\n const default_data = {\n response: question_data,\n rt: rt,\n question_order: trial.randomize_question_order\n ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])\n : [...Array(trial.questions.length).keys()],\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n const answers = Object.entries(data.response);\n for (let i = 0; i < answers.length; i++) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\n `input[type=\"radio\"][name=\"${answers[i][0]}\"][value=\"${answers[i][1]}\"]`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\"#jspsych-survey-likert-next\"),\n data.rt\n );\n }\n}\n\nexport default SurveyLikertPlugin;\n"],"names":["ParameterType"],"mappings":";;;;AAEE,IAAW,OAAA,GAAA,OAAA;;ACEb,MAAM,IAAc,GAAA;AAAA,EAClB,IAAM,EAAA,eAAA;AAAA,EACN,OAAA;AAAA,EACA,UAAY,EAAA;AAAA;AAAA,IAEV,SAAW,EAAA;AAAA,MACT,M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CAAA,CAAA;AACjC,IAAc,aAAA,EAAA,CAAA;AAEd,IAAA,MAAM,OAAU,GAAA,MAAA,CAAO,OAAQ,CAAA,IAAA,CAAK,QAAQ,CAAA,CAAA;AAC5C,IAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,OAAA,CAAQ,QAAQ,CAAK,EAAA,EAAA;AACvC,MAAA,IAAA,CAAK,QAAQ,SAAU,CAAA,WAAA;AAAA,QACrB,eAAgB,CAAA,aAAA;AAAA,UACd,CAAA,0BAAA,EAA6B,OAAQ,CAAA,CAAC,CAAE,CAAA,CAAC,CAAC,CAAA,UAAA,EAAa,OAAQ,CAAA,CAAC,CAAE,CAAA,CAAC,CAAC,CAAA,EAAA,CAAA;AAAA,SACtE;AAAA,QAAA,CACE,IAAK,CAAA,EAAA,GAAK,GAAQ,IAAA,OAAA,CAAQ,UAAW,CAAI,GAAA,CAAA,CAAA;AAAA,OAC7C,CAAA;AAAA,KACF;AAEA,IAAA,IAAA,CAAK,QAAQ,SAAU,CAAA,WAAA;AAAA,MACrB,eAAA,CAAgB,cAAc,6BAA6B,CAAA;AAAA,MAC3D,IAAK,CAAA,EAAA;AAAA,KACP,CAAA;AAAA,GACF;AACF;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@jspsych/plugin-survey-likert\",\n \"version\": \"2.2.0\",\n \"description\": \"a jspsych plugin for measuring items on a likert scale\",\n \"type\": \"module\",\n \"main\": \"dist/index.cjs\",\n \"exports\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"typings\": \"dist/index.d.ts\",\n \"unpkg\": \"dist/index.browser.min.js\",\n \"files\": [\n \"src\",\n \"dist\"\n ],\n \"source\": \"src/index.ts\",\n \"scripts\": {\n \"test\": \"jest\",\n \"test:watch\": \"npm test -- --watch\",\n \"tsc\": \"tsc\",\n \"build\": \"rollup --config\",\n \"build:watch\": \"npm run build -- --watch\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/jspsych/jsPsych.git\",\n \"directory\": \"packages/plugin-survey-likert\"\n },\n \"author\": \"Josh de Leeuw\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/jspsych/jsPsych/issues\"\n },\n \"homepage\": \"https://www.jspsych.org/latest/plugins/survey-likert\",\n \"peerDependencies\": {\n \"jspsych\": \">=7.1.0\"\n },\n \"devDependencies\": {\n \"@jspsych/config\": \"^3.2.0\",\n \"@jspsych/test-utils\": \"^1.2.0\"\n }\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"survey-likert\",\n version: version,\n parameters: {\n /** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */\n questions: {\n type: ParameterType.COMPLEX,\n array: true,\n nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: undefined,\n },\n /** Array of likert labels to display for this question. */\n labels: {\n type: ParameterType.STRING,\n array: true,\n default: undefined,\n },\n /** Whether or not a response to this question must be given in order to continue. */\n required: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */\n name: {\n type: ParameterType.STRING,\n default: \"\",\n },\n /** Default response value for this question (0-based index of labels array). */\n default_response: {\n type: ParameterType.INT,\n default: null,\n },\n },\n },\n /** If true, the order of the questions in the 'questions' array will be randomized. */\n randomize_question_order: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** HTML-formatted string to display at top of the page above all of the questions. */\n preamble: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** Width of the likert scales in pixels. */\n scale_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to submit responses. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n },\n /** Setting this to true will enable browser auto-complete or auto-fill for the form. */\n autocomplete: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\n /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n response: {\n type: ParameterType.OBJECT,\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */\n rt: {\n type: ParameterType.INT,\n },\n /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n question_order: {\n type: ParameterType.INT,\n array: true,\n },\n },\n // prettier-ignore\n citations: '__CITATIONS__',\n};\n\ntype Info = typeof info;\n\n/**\n * The survey-likert plugin displays a set of questions with Likert scale responses. The participant responds\n * by selecting a radio button.\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/survey-likert/ survey-likert plugin documentation on jspsych.org}\n */\nclass SurveyLikertPlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n if (trial.scale_width !== null) {\n var w = trial.scale_width + \"px\";\n } else {\n var w = \"100%\";\n }\n\n var html = \"\";\n // inject CSS for trial\n html += '<style id=\"jspsych-survey-likert-css\">';\n html +=\n \".jspsych-survey-likert-statement { display:block; font-size: 16px; padding-top: 40px; margin-bottom:10px; }\" +\n \".jspsych-survey-likert-opts { list-style:none; width:\" +\n w +\n \"; margin:auto; padding:0 0 35px; display:block; font-size: 14px; line-height:1.1em; }\" +\n \".jspsych-survey-likert-opt-label { line-height: 1.1em; color: #444; }\" +\n \".jspsych-survey-likert-opts:before { content: ''; position:relative; top:11px; /*left:9.5%;*/ display:block; background-color:#efefef; height:4px; width:100%; }\" +\n \".jspsych-survey-likert-opts:last-of-type { border-bottom: 0; }\" +\n \".jspsych-survey-likert-opts li { display:inline-block; /*width:19%;*/ text-align:center; vertical-align: top; }\" +\n \".jspsych-survey-likert-opts li input[type=radio] { display:block; position:relative; top:0; left:50%; margin-left:-6px; }\";\n html += \"</style>\";\n\n // show preamble text\n if (trial.preamble !== null) {\n html +=\n '<div id=\"jspsych-survey-likert-preamble\" class=\"jspsych-survey-likert-preamble\">' +\n trial.preamble +\n \"</div>\";\n }\n\n if (trial.autocomplete) {\n html += '<form id=\"jspsych-survey-likert-form\">';\n } else {\n html += '<form id=\"jspsych-survey-likert-form\" autocomplete=\"off\">';\n }\n\n // add likert scale questions ///\n // generate question order. this is randomized here as opposed to randomizing the order of trial.questions\n // so that the data are always associated with the same question regardless of order\n var question_order = [];\n for (var i = 0; i < trial.questions.length; i++) {\n question_order.push(i);\n }\n if (trial.randomize_question_order) {\n question_order = this.jsPsych.randomization.shuffle(question_order);\n }\n\n for (var i = 0; i < trial.questions.length; i++) {\n var question = trial.questions[question_order[i]];\n // add question\n html += '<label class=\"jspsych-survey-likert-statement\">' + question.prompt + \"</label>\";\n // add options\n var width = 100 / question.labels.length;\n var options_string =\n '<ul class=\"jspsych-survey-likert-opts\" data-name=\"' +\n question.name +\n '\" data-radio-group=\"Q' +\n question_order[i] +\n '\">';\n for (var j = 0; j < question.labels.length; j++) {\n options_string +=\n '<li style=\"width:' +\n width +\n '%\"><label class=\"jspsych-survey-likert-opt-label\"><input type=\"radio\" name=\"Q' +\n question_order[i] +\n '\" value=\"' +\n j +\n '\"';\n if (question.required) {\n options_string += \" required\";\n }\n if (question.default_response === j) {\n options_string += \" checked\";\n }\n options_string += \">\" + question.labels[j] + \"</label></li>\";\n }\n options_string += \"</ul>\";\n html += options_string;\n }\n\n // add submit button\n html +=\n '<input type=\"submit\" id=\"jspsych-survey-likert-next\" class=\"jspsych-survey-likert jspsych-btn\" value=\"' +\n trial.button_label +\n '\"></input>';\n\n html += \"</form>\";\n\n display_element.innerHTML = html;\n\n display_element.querySelector(\"#jspsych-survey-likert-form\").addEventListener(\"submit\", (e) => {\n e.preventDefault();\n // measure response time\n var endTime = performance.now();\n var response_time = Math.round(endTime - startTime);\n\n // create object to hold responses\n var question_data = {};\n var matches = display_element.querySelectorAll<HTMLFormElement>(\n \"#jspsych-survey-likert-form .jspsych-survey-likert-opts\"\n );\n for (var index = 0; index < matches.length; index++) {\n var id = matches[index].dataset[\"radioGroup\"];\n var el = display_element.querySelector<HTMLInputElement>(\n 'input[name=\"' + id + '\"]:checked'\n );\n if (el === null) {\n var response: string | number = \"\";\n } else {\n var response: string | number = parseInt(el.value);\n }\n var obje = {};\n if (matches[index].attributes[\"data-name\"].value !== \"\") {\n var name = matches[index].attributes[\"data-name\"].value;\n } else {\n var name = id;\n }\n obje[name] = response;\n Object.assign(question_data, obje);\n }\n\n // save data\n var trial_data = {\n rt: response_time,\n response: question_data,\n question_order: question_order,\n };\n\n // next trial\n this.jsPsych.finishTrial(trial_data);\n });\n\n var startTime = performance.now();\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const question_data = {};\n let rt = 1000;\n\n for (const q of trial.questions) {\n const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;\n question_data[name] = this.jsPsych.randomization.randomInt(0, q.labels.length - 1);\n rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);\n }\n\n const default_data = {\n response: question_data,\n rt: rt,\n question_order: trial.randomize_question_order\n ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])\n : [...Array(trial.questions.length).keys()],\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n const answers = Object.entries(data.response);\n for (let i = 0; i < answers.length; i++) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\n `input[type=\"radio\"][name=\"${answers[i][0]}\"][value=\"${answers[i][1]}\"]`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\"#jspsych-survey-likert-next\"),\n data.rt\n );\n }\n}\n\nexport default SurveyLikertPlugin;\n"],"names":[],"mappings":";;;;AAEE,IAAW,OAAA,GAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ECiFA,SAAA,EAAA;AAAA;;GAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -30,6 +30,11 @@ declare const info: {
30
30
  readonly type: ParameterType.STRING;
31
31
  readonly default: "";
32
32
  };
33
+ /** Default response value for this question (0-based index of labels array). */
34
+ readonly default_response: {
35
+ readonly type: ParameterType.INT;
36
+ readonly default: any;
37
+ };
33
38
  };
34
39
  };
35
40
  /** If true, the order of the questions in the 'questions' array will be randomized. */
@@ -73,6 +78,7 @@ declare const info: {
73
78
  readonly array: true;
74
79
  };
75
80
  };
81
+ readonly citations: "__CITATIONS__";
76
82
  };
77
83
  type Info = typeof info;
78
84
  /**
@@ -114,6 +120,11 @@ declare class SurveyLikertPlugin implements JsPsychPlugin<Info> {
114
120
  readonly type: ParameterType.STRING;
115
121
  readonly default: "";
116
122
  };
123
+ /** Default response value for this question (0-based index of labels array). */
124
+ readonly default_response: {
125
+ readonly type: ParameterType.INT;
126
+ readonly default: any;
127
+ };
117
128
  };
118
129
  };
119
130
  /** If true, the order of the questions in the 'questions' array will be randomized. */
@@ -157,6 +168,7 @@ declare class SurveyLikertPlugin implements JsPsychPlugin<Info> {
157
168
  readonly array: true;
158
169
  };
159
170
  };
171
+ readonly citations: "__CITATIONS__";
160
172
  };
161
173
  constructor(jsPsych: JsPsych);
162
174
  trial(display_element: HTMLElement, trial: TrialType<Info>): void;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ParameterType } from 'jspsych';
2
2
 
3
- var version = "2.0.1";
3
+ var version = "2.2.0";
4
4
 
5
5
  const info = {
6
6
  name: "survey-likert",
@@ -31,6 +31,11 @@ const info = {
31
31
  name: {
32
32
  type: ParameterType.STRING,
33
33
  default: ""
34
+ },
35
+ /** Default response value for this question (0-based index of labels array). */
36
+ default_response: {
37
+ type: ParameterType.INT,
38
+ default: null
34
39
  }
35
40
  }
36
41
  },
@@ -74,6 +79,11 @@ const info = {
74
79
  type: ParameterType.INT,
75
80
  array: true
76
81
  }
82
+ },
83
+ // prettier-ignore
84
+ citations: {
85
+ "apa": "de Leeuw, J. R., Gilbert, R. A., & Luchterhandt, B. (2023). jsPsych: Enabling an Open-Source Collaborative Ecosystem of Behavioral Experiments. Journal of Open Source Software, 8(85), 5351. https://doi.org/10.21105/joss.05351 ",
86
+ "bibtex": '@article{Leeuw2023jsPsych, author = {de Leeuw, Joshua R. and Gilbert, Rebecca A. and Luchterhandt, Bj{\\" o}rn}, journal = {Journal of Open Source Software}, doi = {10.21105/joss.05351}, issn = {2475-9066}, number = {85}, year = {2023}, month = {may 11}, pages = {5351}, publisher = {Open Journals}, title = {jsPsych: Enabling an {Open}-{Source} {Collaborative} {Ecosystem} of {Behavioral} {Experiments}}, url = {https://joss.theoj.org/papers/10.21105/joss.05351}, volume = {8}, } '
77
87
  }
78
88
  };
79
89
  class SurveyLikertPlugin {
@@ -118,6 +128,9 @@ class SurveyLikertPlugin {
118
128
  if (question.required) {
119
129
  options_string += " required";
120
130
  }
131
+ if (question.default_response === j) {
132
+ options_string += " checked";
133
+ }
121
134
  options_string += ">" + question.labels[j] + "</label></li>";
122
135
  }
123
136
  options_string += "</ul>";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@jspsych/plugin-survey-likert\",\n \"version\": \"2.0.1\",\n \"description\": \"a jspsych plugin for measuring items on a likert scale\",\n \"type\": \"module\",\n \"main\": \"dist/index.cjs\",\n \"exports\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"typings\": \"dist/index.d.ts\",\n \"unpkg\": \"dist/index.browser.min.js\",\n \"files\": [\n \"src\",\n \"dist\"\n ],\n \"source\": \"src/index.ts\",\n \"scripts\": {\n \"test\": \"jest\",\n \"test:watch\": \"npm test -- --watch\",\n \"tsc\": \"tsc\",\n \"build\": \"rollup --config\",\n \"build:watch\": \"npm run build -- --watch\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/jspsych/jsPsych.git\",\n \"directory\": \"packages/plugin-survey-likert\"\n },\n \"author\": \"Josh de Leeuw\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/jspsych/jsPsych/issues\"\n },\n \"homepage\": \"https://www.jspsych.org/latest/plugins/survey-likert\",\n \"peerDependencies\": {\n \"jspsych\": \">=7.1.0\"\n },\n \"devDependencies\": {\n \"@jspsych/config\": \"^3.1.1\",\n \"@jspsych/test-utils\": \"^1.2.0\"\n }\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"survey-likert\",\n version: version,\n parameters: {\n /** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */\n questions: {\n type: ParameterType.COMPLEX,\n array: true,\n nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: undefined,\n },\n /** Array of likert labels to display for this question. */\n labels: {\n type: ParameterType.STRING,\n array: true,\n default: undefined,\n },\n /** Whether or not a response to this question must be given in order to continue. */\n required: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */\n name: {\n type: ParameterType.STRING,\n default: \"\",\n },\n },\n },\n /** If true, the order of the questions in the 'questions' array will be randomized. */\n randomize_question_order: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** HTML-formatted string to display at top of the page above all of the questions. */\n preamble: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** Width of the likert scales in pixels. */\n scale_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to submit responses. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n },\n /** Setting this to true will enable browser auto-complete or auto-fill for the form. */\n autocomplete: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\n /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n response: {\n type: ParameterType.OBJECT,\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */\n rt: {\n type: ParameterType.INT,\n },\n /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n question_order: {\n type: ParameterType.INT,\n array: true,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * The survey-likert plugin displays a set of questions with Likert scale responses. The participant responds\n * by selecting a radio button.\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/survey-likert/ survey-likert plugin documentation on jspsych.org}\n */\nclass SurveyLikertPlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n if (trial.scale_width !== null) {\n var w = trial.scale_width + \"px\";\n } else {\n var w = \"100%\";\n }\n\n var html = \"\";\n // inject CSS for trial\n html += '<style id=\"jspsych-survey-likert-css\">';\n html +=\n \".jspsych-survey-likert-statement { display:block; font-size: 16px; padding-top: 40px; margin-bottom:10px; }\" +\n \".jspsych-survey-likert-opts { list-style:none; width:\" +\n w +\n \"; margin:auto; padding:0 0 35px; display:block; font-size: 14px; line-height:1.1em; }\" +\n \".jspsych-survey-likert-opt-label { line-height: 1.1em; color: #444; }\" +\n \".jspsych-survey-likert-opts:before { content: ''; position:relative; top:11px; /*left:9.5%;*/ display:block; background-color:#efefef; height:4px; width:100%; }\" +\n \".jspsych-survey-likert-opts:last-of-type { border-bottom: 0; }\" +\n \".jspsych-survey-likert-opts li { display:inline-block; /*width:19%;*/ text-align:center; vertical-align: top; }\" +\n \".jspsych-survey-likert-opts li input[type=radio] { display:block; position:relative; top:0; left:50%; margin-left:-6px; }\";\n html += \"</style>\";\n\n // show preamble text\n if (trial.preamble !== null) {\n html +=\n '<div id=\"jspsych-survey-likert-preamble\" class=\"jspsych-survey-likert-preamble\">' +\n trial.preamble +\n \"</div>\";\n }\n\n if (trial.autocomplete) {\n html += '<form id=\"jspsych-survey-likert-form\">';\n } else {\n html += '<form id=\"jspsych-survey-likert-form\" autocomplete=\"off\">';\n }\n\n // add likert scale questions ///\n // generate question order. this is randomized here as opposed to randomizing the order of trial.questions\n // so that the data are always associated with the same question regardless of order\n var question_order = [];\n for (var i = 0; i < trial.questions.length; i++) {\n question_order.push(i);\n }\n if (trial.randomize_question_order) {\n question_order = this.jsPsych.randomization.shuffle(question_order);\n }\n\n for (var i = 0; i < trial.questions.length; i++) {\n var question = trial.questions[question_order[i]];\n // add question\n html += '<label class=\"jspsych-survey-likert-statement\">' + question.prompt + \"</label>\";\n // add options\n var width = 100 / question.labels.length;\n var options_string =\n '<ul class=\"jspsych-survey-likert-opts\" data-name=\"' +\n question.name +\n '\" data-radio-group=\"Q' +\n question_order[i] +\n '\">';\n for (var j = 0; j < question.labels.length; j++) {\n options_string +=\n '<li style=\"width:' +\n width +\n '%\"><label class=\"jspsych-survey-likert-opt-label\"><input type=\"radio\" name=\"Q' +\n question_order[i] +\n '\" value=\"' +\n j +\n '\"';\n if (question.required) {\n options_string += \" required\";\n }\n options_string += \">\" + question.labels[j] + \"</label></li>\";\n }\n options_string += \"</ul>\";\n html += options_string;\n }\n\n // add submit button\n html +=\n '<input type=\"submit\" id=\"jspsych-survey-likert-next\" class=\"jspsych-survey-likert jspsych-btn\" value=\"' +\n trial.button_label +\n '\"></input>';\n\n html += \"</form>\";\n\n display_element.innerHTML = html;\n\n display_element.querySelector(\"#jspsych-survey-likert-form\").addEventListener(\"submit\", (e) => {\n e.preventDefault();\n // measure response time\n var endTime = performance.now();\n var response_time = Math.round(endTime - startTime);\n\n // create object to hold responses\n var question_data = {};\n var matches = display_element.querySelectorAll<HTMLFormElement>(\n \"#jspsych-survey-likert-form .jspsych-survey-likert-opts\"\n );\n for (var index = 0; index < matches.length; index++) {\n var id = matches[index].dataset[\"radioGroup\"];\n var el = display_element.querySelector<HTMLInputElement>(\n 'input[name=\"' + id + '\"]:checked'\n );\n if (el === null) {\n var response: string | number = \"\";\n } else {\n var response: string | number = parseInt(el.value);\n }\n var obje = {};\n if (matches[index].attributes[\"data-name\"].value !== \"\") {\n var name = matches[index].attributes[\"data-name\"].value;\n } else {\n var name = id;\n }\n obje[name] = response;\n Object.assign(question_data, obje);\n }\n\n // save data\n var trial_data = {\n rt: response_time,\n response: question_data,\n question_order: question_order,\n };\n\n // next trial\n this.jsPsych.finishTrial(trial_data);\n });\n\n var startTime = performance.now();\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const question_data = {};\n let rt = 1000;\n\n for (const q of trial.questions) {\n const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;\n question_data[name] = this.jsPsych.randomization.randomInt(0, q.labels.length - 1);\n rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);\n }\n\n const default_data = {\n response: question_data,\n rt: rt,\n question_order: trial.randomize_question_order\n ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])\n : [...Array(trial.questions.length).keys()],\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n const answers = Object.entries(data.response);\n for (let i = 0; i < answers.length; i++) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\n `input[type=\"radio\"][name=\"${answers[i][0]}\"][value=\"${answers[i][1]}\"]`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\"#jspsych-survey-likert-next\"),\n data.rt\n );\n }\n}\n\nexport default SurveyLikertPlugin;\n"],"names":[],"mappings":";;AAEE,IAAW,OAAA,GAAA,OAAA;;ACEb,MAAM,IAAc,GAAA;AAAA,EAClB,IAAM,EAAA,eAAA;AAAA,EACN,OAAA;AAAA,EACA,UAAY,EAAA;AAAA;AAAA,IAEV,SAAW,EAAA;AAAA,MACT,MAAM,aAAc,CAAA,OAAA;AAAA,MACpB,KAAO,EAAA,IAAA;AAAA,MACP,MAAQ,EAAA;AAAA;AAAA,QAEN,MAAQ,EAAA;AAAA,UACN,MAAM,aAAc,CAAA,WAAA;AAAA,UACpB,OAAS,EAAA,KAAA,CAAA;AAAA,SACX;AAAA;AAAA,QAEA,MAAQ,EAAA;AAAA,UACN,MAAM,aAAc,CAAA,MAAA;AAAA,UACpB,KAAO,EAAA,IAAA;AAAA,UACP,OAAS,EAAA,KAAA,CAAA;AAAA,SACX;AAAA;AAAA,QAEA,QAAU,EAAA;AAAA,UACR,MAAM,aAAc,CAAA,IAAA;AAAA,UACpB,OAAS,EAAA,KAAA;AAAA,SACX;AAAA;AAAA,QAEA,IAAM,EAAA;AAAA,UACJ,MAAM,aAAc,CAAA,MAAA;AAAA,UACpB,OAAS,EAAA,EAAA;AAAA,SACX;AAAA,OACF;AAAA,KACF;AAAA;AAAA,IAEA,wBAA0B,EAAA;AAAA,MACxB,MAAM,aAAc,CAAA,IAAA;AAAA,MACpB,OAAS,EAAA,KAAA;AAAA,KACX;AAAA;AAAA,IAEA,QAAU,EAAA;AAAA,MACR,MAAM,aAAc,CAAA,WAAA;AAAA,MACpB,OAAS,EAAA,IAAA;AAAA,KACX;AAAA;AAAA,IAEA,WAAa,EAAA;AAAA,MACX,MAAM,aAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,IAAA;AAAA,KACX;AAAA;AAAA,IAEA,YAAc,EAAA;AAAA,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Q,eAAA,CAAgB,KAAwB,EAAA,kBAAA,EAAoB,aAA2B,EAAA;AAC7F,IAAA,MAAM,IAAO,GAAA,IAAA,CAAK,sBAAuB,CAAA,KAAA,EAAO,kBAAkB,CAAA,CAAA;AAElE,IAAM,MAAA,eAAA,GAAkB,IAAK,CAAA,OAAA,CAAQ,iBAAkB,EAAA,CAAA;AAEvD,IAAK,IAAA,CAAA,KAAA,CAAM,iBAAiB,KAAK,CAAA,CAAA;AACjC,IAAc,aAAA,EAAA,CAAA;AAEd,IAAA,MAAM,OAAU,GAAA,MAAA,CAAO,OAAQ,CAAA,IAAA,CAAK,QAAQ,CAAA,CAAA;AAC5C,IAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,OAAA,CAAQ,QAAQ,CAAK,EAAA,EAAA;AACvC,MAAA,IAAA,CAAK,QAAQ,SAAU,CAAA,WAAA;AAAA,QACrB,eAAgB,CAAA,aAAA;AAAA,UACd,CAAA,0BAAA,EAA6B,OAAQ,CAAA,CAAC,CAAE,CAAA,CAAC,CAAC,CAAA,UAAA,EAAa,OAAQ,CAAA,CAAC,CAAE,CAAA,CAAC,CAAC,CAAA,EAAA,CAAA;AAAA,SACtE;AAAA,QAAA,CACE,IAAK,CAAA,EAAA,GAAK,GAAQ,IAAA,OAAA,CAAQ,UAAW,CAAI,GAAA,CAAA,CAAA;AAAA,OAC7C,CAAA;AAAA,KACF;AAEA,IAAA,IAAA,CAAK,QAAQ,SAAU,CAAA,WAAA;AAAA,MACrB,eAAA,CAAgB,cAAc,6BAA6B,CAAA;AAAA,MAC3D,IAAK,CAAA,EAAA;AAAA,KACP,CAAA;AAAA,GACF;AACF;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@jspsych/plugin-survey-likert\",\n \"version\": \"2.2.0\",\n \"description\": \"a jspsych plugin for measuring items on a likert scale\",\n \"type\": \"module\",\n \"main\": \"dist/index.cjs\",\n \"exports\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"typings\": \"dist/index.d.ts\",\n \"unpkg\": \"dist/index.browser.min.js\",\n \"files\": [\n \"src\",\n \"dist\"\n ],\n \"source\": \"src/index.ts\",\n \"scripts\": {\n \"test\": \"jest\",\n \"test:watch\": \"npm test -- --watch\",\n \"tsc\": \"tsc\",\n \"build\": \"rollup --config\",\n \"build:watch\": \"npm run build -- --watch\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/jspsych/jsPsych.git\",\n \"directory\": \"packages/plugin-survey-likert\"\n },\n \"author\": \"Josh de Leeuw\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/jspsych/jsPsych/issues\"\n },\n \"homepage\": \"https://www.jspsych.org/latest/plugins/survey-likert\",\n \"peerDependencies\": {\n \"jspsych\": \">=7.1.0\"\n },\n \"devDependencies\": {\n \"@jspsych/config\": \"^3.2.0\",\n \"@jspsych/test-utils\": \"^1.2.0\"\n }\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"survey-likert\",\n version: version,\n parameters: {\n /** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */\n questions: {\n type: ParameterType.COMPLEX,\n array: true,\n nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: undefined,\n },\n /** Array of likert labels to display for this question. */\n labels: {\n type: ParameterType.STRING,\n array: true,\n default: undefined,\n },\n /** Whether or not a response to this question must be given in order to continue. */\n required: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */\n name: {\n type: ParameterType.STRING,\n default: \"\",\n },\n /** Default response value for this question (0-based index of labels array). */\n default_response: {\n type: ParameterType.INT,\n default: null,\n },\n },\n },\n /** If true, the order of the questions in the 'questions' array will be randomized. */\n randomize_question_order: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** HTML-formatted string to display at top of the page above all of the questions. */\n preamble: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** Width of the likert scales in pixels. */\n scale_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to submit responses. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n },\n /** Setting this to true will enable browser auto-complete or auto-fill for the form. */\n autocomplete: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\n /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n response: {\n type: ParameterType.OBJECT,\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */\n rt: {\n type: ParameterType.INT,\n },\n /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n question_order: {\n type: ParameterType.INT,\n array: true,\n },\n },\n // prettier-ignore\n citations: '__CITATIONS__',\n};\n\ntype Info = typeof info;\n\n/**\n * The survey-likert plugin displays a set of questions with Likert scale responses. The participant responds\n * by selecting a radio button.\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/survey-likert/ survey-likert plugin documentation on jspsych.org}\n */\nclass SurveyLikertPlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n if (trial.scale_width !== null) {\n var w = trial.scale_width + \"px\";\n } else {\n var w = \"100%\";\n }\n\n var html = \"\";\n // inject CSS for trial\n html += '<style id=\"jspsych-survey-likert-css\">';\n html +=\n \".jspsych-survey-likert-statement { display:block; font-size: 16px; padding-top: 40px; margin-bottom:10px; }\" +\n \".jspsych-survey-likert-opts { list-style:none; width:\" +\n w +\n \"; margin:auto; padding:0 0 35px; display:block; font-size: 14px; line-height:1.1em; }\" +\n \".jspsych-survey-likert-opt-label { line-height: 1.1em; color: #444; }\" +\n \".jspsych-survey-likert-opts:before { content: ''; position:relative; top:11px; /*left:9.5%;*/ display:block; background-color:#efefef; height:4px; width:100%; }\" +\n \".jspsych-survey-likert-opts:last-of-type { border-bottom: 0; }\" +\n \".jspsych-survey-likert-opts li { display:inline-block; /*width:19%;*/ text-align:center; vertical-align: top; }\" +\n \".jspsych-survey-likert-opts li input[type=radio] { display:block; position:relative; top:0; left:50%; margin-left:-6px; }\";\n html += \"</style>\";\n\n // show preamble text\n if (trial.preamble !== null) {\n html +=\n '<div id=\"jspsych-survey-likert-preamble\" class=\"jspsych-survey-likert-preamble\">' +\n trial.preamble +\n \"</div>\";\n }\n\n if (trial.autocomplete) {\n html += '<form id=\"jspsych-survey-likert-form\">';\n } else {\n html += '<form id=\"jspsych-survey-likert-form\" autocomplete=\"off\">';\n }\n\n // add likert scale questions ///\n // generate question order. this is randomized here as opposed to randomizing the order of trial.questions\n // so that the data are always associated with the same question regardless of order\n var question_order = [];\n for (var i = 0; i < trial.questions.length; i++) {\n question_order.push(i);\n }\n if (trial.randomize_question_order) {\n question_order = this.jsPsych.randomization.shuffle(question_order);\n }\n\n for (var i = 0; i < trial.questions.length; i++) {\n var question = trial.questions[question_order[i]];\n // add question\n html += '<label class=\"jspsych-survey-likert-statement\">' + question.prompt + \"</label>\";\n // add options\n var width = 100 / question.labels.length;\n var options_string =\n '<ul class=\"jspsych-survey-likert-opts\" data-name=\"' +\n question.name +\n '\" data-radio-group=\"Q' +\n question_order[i] +\n '\">';\n for (var j = 0; j < question.labels.length; j++) {\n options_string +=\n '<li style=\"width:' +\n width +\n '%\"><label class=\"jspsych-survey-likert-opt-label\"><input type=\"radio\" name=\"Q' +\n question_order[i] +\n '\" value=\"' +\n j +\n '\"';\n if (question.required) {\n options_string += \" required\";\n }\n if (question.default_response === j) {\n options_string += \" checked\";\n }\n options_string += \">\" + question.labels[j] + \"</label></li>\";\n }\n options_string += \"</ul>\";\n html += options_string;\n }\n\n // add submit button\n html +=\n '<input type=\"submit\" id=\"jspsych-survey-likert-next\" class=\"jspsych-survey-likert jspsych-btn\" value=\"' +\n trial.button_label +\n '\"></input>';\n\n html += \"</form>\";\n\n display_element.innerHTML = html;\n\n display_element.querySelector(\"#jspsych-survey-likert-form\").addEventListener(\"submit\", (e) => {\n e.preventDefault();\n // measure response time\n var endTime = performance.now();\n var response_time = Math.round(endTime - startTime);\n\n // create object to hold responses\n var question_data = {};\n var matches = display_element.querySelectorAll<HTMLFormElement>(\n \"#jspsych-survey-likert-form .jspsych-survey-likert-opts\"\n );\n for (var index = 0; index < matches.length; index++) {\n var id = matches[index].dataset[\"radioGroup\"];\n var el = display_element.querySelector<HTMLInputElement>(\n 'input[name=\"' + id + '\"]:checked'\n );\n if (el === null) {\n var response: string | number = \"\";\n } else {\n var response: string | number = parseInt(el.value);\n }\n var obje = {};\n if (matches[index].attributes[\"data-name\"].value !== \"\") {\n var name = matches[index].attributes[\"data-name\"].value;\n } else {\n var name = id;\n }\n obje[name] = response;\n Object.assign(question_data, obje);\n }\n\n // save data\n var trial_data = {\n rt: response_time,\n response: question_data,\n question_order: question_order,\n };\n\n // next trial\n this.jsPsych.finishTrial(trial_data);\n });\n\n var startTime = performance.now();\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const question_data = {};\n let rt = 1000;\n\n for (const q of trial.questions) {\n const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;\n question_data[name] = this.jsPsych.randomization.randomInt(0, q.labels.length - 1);\n rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);\n }\n\n const default_data = {\n response: question_data,\n rt: rt,\n question_order: trial.randomize_question_order\n ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])\n : [...Array(trial.questions.length).keys()],\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n const answers = Object.entries(data.response);\n for (let i = 0; i < answers.length; i++) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\n `input[type=\"radio\"][name=\"${answers[i][0]}\"][value=\"${answers[i][1]}\"]`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\"#jspsych-survey-likert-next\"),\n data.rt\n );\n }\n}\n\nexport default SurveyLikertPlugin;\n"],"names":[],"mappings":";;AAEE,IAAW,OAAA,GAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ECiFA,SAAA,EAAA;AAAA;;GAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jspsych/plugin-survey-likert",
3
- "version": "2.0.1",
3
+ "version": "2.2.0",
4
4
  "description": "a jspsych plugin for measuring items on a likert scale",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -37,7 +37,7 @@
37
37
  "jspsych": ">=7.1.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@jspsych/config": "^3.1.1",
40
+ "@jspsych/config": "^3.2.0",
41
41
  "@jspsych/test-utils": "^1.2.0"
42
42
  }
43
43
  }
package/src/index.spec.ts CHANGED
@@ -4,13 +4,13 @@ import surveyLikert from ".";
4
4
 
5
5
  jest.useFakeTimers();
6
6
 
7
- const selectInput = (name: string, value: string) =>
8
- document.querySelector(`input[name="${name}"][value="${value}"]`) as HTMLInputElement;
7
+ const selectInput = (name: string, value: string, displayElement: HTMLElement) =>
8
+ displayElement.querySelector(`input[name="${name}"][value="${value}"]`) as HTMLInputElement;
9
9
 
10
10
  describe("survey-likert plugin", () => {
11
11
  test("data are logged with the right question when randomize order is true", async () => {
12
12
  const scale = ["a", "b", "c", "d", "e"];
13
- const { getData, expectFinished } = await startTimeline([
13
+ const { getData, expectFinished, displayElement } = await startTimeline([
14
14
  {
15
15
  type: surveyLikert,
16
16
  questions: [
@@ -24,13 +24,13 @@ describe("survey-likert plugin", () => {
24
24
  },
25
25
  ]);
26
26
 
27
- selectInput("Q0", "0").checked = true;
28
- selectInput("Q1", "1").checked = true;
29
- selectInput("Q2", "2").checked = true;
30
- selectInput("Q3", "3").checked = true;
31
- selectInput("Q4", "4").checked = true;
27
+ selectInput("Q0", "0", displayElement).checked = true;
28
+ selectInput("Q1", "1", displayElement).checked = true;
29
+ selectInput("Q2", "2", displayElement).checked = true;
30
+ selectInput("Q3", "3", displayElement).checked = true;
31
+ selectInput("Q4", "4", displayElement).checked = true;
32
32
 
33
- await clickTarget(document.querySelector("#jspsych-survey-likert-next"));
33
+ await clickTarget(displayElement.querySelector("#jspsych-survey-likert-next"));
34
34
 
35
35
  await expectFinished();
36
36
 
@@ -41,6 +41,56 @@ describe("survey-likert plugin", () => {
41
41
  expect(surveyData.Q3).toEqual(3);
42
42
  expect(surveyData.Q4).toEqual(4);
43
43
  });
44
+
45
+ test("default_response options are pre-selected correctly", async () => {
46
+ const scale = ["a", "b", "c", "d", "e"];
47
+ const { displayElement } = await startTimeline([
48
+ {
49
+ type: surveyLikert,
50
+ questions: [
51
+ { prompt: "Q0", labels: scale, default_response: 2 },
52
+ { prompt: "Q1", labels: scale, default_response: 0 },
53
+ { prompt: "Q2", labels: scale, default_response: 4 },
54
+ { prompt: "Q3", labels: scale }, // No default
55
+ ],
56
+ randomize_question_order: false,
57
+ },
58
+ ]);
59
+
60
+ // Check correct radio buttons are pre-selected
61
+ expect(selectInput("Q0", "2", displayElement).checked).toBe(true);
62
+ expect(selectInput("Q1", "0", displayElement).checked).toBe(true);
63
+ expect(selectInput("Q2", "4", displayElement).checked).toBe(true);
64
+
65
+ // Check other options are NOT selected
66
+ expect(selectInput("Q0", "0", displayElement).checked).toBe(false);
67
+ expect(selectInput("Q0", "1", displayElement).checked).toBe(false);
68
+ expect(selectInput("Q1", "1", displayElement).checked).toBe(false);
69
+ expect(selectInput("Q2", "0", displayElement).checked).toBe(false);
70
+
71
+ // Check question without default has no selection
72
+ expect(selectInput("Q3", "0", displayElement).checked).toBe(false);
73
+ expect(selectInput("Q3", "1", displayElement).checked).toBe(false);
74
+ expect(selectInput("Q3", "2", displayElement).checked).toBe(false);
75
+ expect(selectInput("Q3", "3", displayElement).checked).toBe(false);
76
+ expect(selectInput("Q3", "4", displayElement).checked).toBe(false);
77
+ });
78
+
79
+ test("default_response null does not pre-select anything", async () => {
80
+ const scale = ["a", "b", "c"];
81
+ const { displayElement } = await startTimeline([
82
+ {
83
+ type: surveyLikert,
84
+ questions: [{ prompt: "Q0", labels: scale, default_response: null }],
85
+ randomize_question_order: false,
86
+ },
87
+ ]);
88
+
89
+ // Check that no options are pre-selected
90
+ expect(selectInput("Q0", "0", displayElement).checked).toBe(false);
91
+ expect(selectInput("Q0", "1", displayElement).checked).toBe(false);
92
+ expect(selectInput("Q0", "2", displayElement).checked).toBe(false);
93
+ });
44
94
  });
45
95
 
46
96
  describe("survey-likert plugin simulation", () => {
package/src/index.ts CHANGED
@@ -32,6 +32,11 @@ const info = <const>{
32
32
  type: ParameterType.STRING,
33
33
  default: "",
34
34
  },
35
+ /** Default response value for this question (0-based index of labels array). */
36
+ default_response: {
37
+ type: ParameterType.INT,
38
+ default: null,
39
+ },
35
40
  },
36
41
  },
37
42
  /** If true, the order of the questions in the 'questions' array will be randomized. */
@@ -75,6 +80,8 @@ const info = <const>{
75
80
  array: true,
76
81
  },
77
82
  },
83
+ // prettier-ignore
84
+ citations: '__CITATIONS__',
78
85
  };
79
86
 
80
87
  type Info = typeof info;
@@ -162,6 +169,9 @@ class SurveyLikertPlugin implements JsPsychPlugin<Info> {
162
169
  if (question.required) {
163
170
  options_string += " required";
164
171
  }
172
+ if (question.default_response === j) {
173
+ options_string += " checked";
174
+ }
165
175
  options_string += ">" + question.labels[j] + "</label></li>";
166
176
  }
167
177
  options_string += "</ul>";