@jspsych/plugin-survey-likert 2.0.0 → 2.0.1
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.
- package/dist/index.browser.js +20 -55
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.min.js +2 -2
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.cjs +19 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -18
- package/dist/index.js +19 -54
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -14
package/dist/index.browser.js
CHANGED
|
@@ -1,113 +1,76 @@
|
|
|
1
1
|
var jsPsychSurveyLikert = (function (jspsych) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
name: "@jspsych/plugin-survey-likert",
|
|
6
|
-
version: "2.0.0",
|
|
7
|
-
description: "a jspsych plugin for measuring items on a likert scale",
|
|
8
|
-
type: "module",
|
|
9
|
-
main: "dist/index.cjs",
|
|
10
|
-
exports: {
|
|
11
|
-
import: "./dist/index.js",
|
|
12
|
-
require: "./dist/index.cjs"
|
|
13
|
-
},
|
|
14
|
-
typings: "dist/index.d.ts",
|
|
15
|
-
unpkg: "dist/index.browser.min.js",
|
|
16
|
-
files: [
|
|
17
|
-
"src",
|
|
18
|
-
"dist"
|
|
19
|
-
],
|
|
20
|
-
source: "src/index.ts",
|
|
21
|
-
scripts: {
|
|
22
|
-
test: "jest",
|
|
23
|
-
"test:watch": "npm test -- --watch",
|
|
24
|
-
tsc: "tsc",
|
|
25
|
-
build: "rollup --config",
|
|
26
|
-
"build:watch": "npm run build -- --watch"
|
|
27
|
-
},
|
|
28
|
-
repository: {
|
|
29
|
-
type: "git",
|
|
30
|
-
url: "git+https://github.com/jspsych/jsPsych.git",
|
|
31
|
-
directory: "packages/plugin-survey-likert"
|
|
32
|
-
},
|
|
33
|
-
author: "Josh de Leeuw",
|
|
34
|
-
license: "MIT",
|
|
35
|
-
bugs: {
|
|
36
|
-
url: "https://github.com/jspsych/jsPsych/issues"
|
|
37
|
-
},
|
|
38
|
-
homepage: "https://www.jspsych.org/latest/plugins/survey-likert",
|
|
39
|
-
peerDependencies: {
|
|
40
|
-
jspsych: ">=7.1.0"
|
|
41
|
-
},
|
|
42
|
-
devDependencies: {
|
|
43
|
-
"@jspsych/config": "^3.0.0",
|
|
44
|
-
"@jspsych/test-utils": "^1.2.0"
|
|
45
|
-
}
|
|
46
|
-
};
|
|
4
|
+
var version = "2.0.1";
|
|
47
5
|
|
|
48
6
|
const info = {
|
|
49
7
|
name: "survey-likert",
|
|
50
|
-
version
|
|
8
|
+
version,
|
|
51
9
|
parameters: {
|
|
10
|
+
/** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */
|
|
52
11
|
questions: {
|
|
53
12
|
type: jspsych.ParameterType.COMPLEX,
|
|
54
13
|
array: true,
|
|
55
14
|
nested: {
|
|
15
|
+
/** Question prompt. */
|
|
56
16
|
prompt: {
|
|
57
17
|
type: jspsych.ParameterType.HTML_STRING,
|
|
58
18
|
default: void 0
|
|
59
19
|
},
|
|
20
|
+
/** Array of likert labels to display for this question. */
|
|
60
21
|
labels: {
|
|
61
22
|
type: jspsych.ParameterType.STRING,
|
|
62
23
|
array: true,
|
|
63
24
|
default: void 0
|
|
64
25
|
},
|
|
26
|
+
/** Whether or not a response to this question must be given in order to continue. */
|
|
65
27
|
required: {
|
|
66
28
|
type: jspsych.ParameterType.BOOL,
|
|
67
29
|
default: false
|
|
68
30
|
},
|
|
31
|
+
/** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */
|
|
69
32
|
name: {
|
|
70
33
|
type: jspsych.ParameterType.STRING,
|
|
71
34
|
default: ""
|
|
72
35
|
}
|
|
73
36
|
}
|
|
74
37
|
},
|
|
38
|
+
/** If true, the order of the questions in the 'questions' array will be randomized. */
|
|
75
39
|
randomize_question_order: {
|
|
76
40
|
type: jspsych.ParameterType.BOOL,
|
|
77
41
|
default: false
|
|
78
42
|
},
|
|
43
|
+
/** HTML-formatted string to display at top of the page above all of the questions. */
|
|
79
44
|
preamble: {
|
|
80
45
|
type: jspsych.ParameterType.HTML_STRING,
|
|
81
46
|
default: null
|
|
82
47
|
},
|
|
48
|
+
/** Width of the likert scales in pixels. */
|
|
83
49
|
scale_width: {
|
|
84
50
|
type: jspsych.ParameterType.INT,
|
|
85
51
|
default: null
|
|
86
52
|
},
|
|
53
|
+
/** Label of the button to submit responses. */
|
|
87
54
|
button_label: {
|
|
88
55
|
type: jspsych.ParameterType.STRING,
|
|
89
56
|
default: "Continue"
|
|
90
57
|
},
|
|
58
|
+
/** Setting this to true will enable browser auto-complete or auto-fill for the form. */
|
|
91
59
|
autocomplete: {
|
|
92
60
|
type: jspsych.ParameterType.BOOL,
|
|
93
61
|
default: false
|
|
94
62
|
}
|
|
95
63
|
},
|
|
96
64
|
data: {
|
|
65
|
+
/** 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. */
|
|
97
66
|
response: {
|
|
98
|
-
type: jspsych.ParameterType.
|
|
99
|
-
nested: {
|
|
100
|
-
identifier: {
|
|
101
|
-
type: jspsych.ParameterType.STRING
|
|
102
|
-
},
|
|
103
|
-
response: {
|
|
104
|
-
type: jspsych.ParameterType.STRING | jspsych.ParameterType.INT | jspsych.ParameterType.FLOAT | jspsych.ParameterType.BOOL | jspsych.ParameterType.OBJECT
|
|
105
|
-
}
|
|
106
|
-
}
|
|
67
|
+
type: jspsych.ParameterType.OBJECT
|
|
107
68
|
},
|
|
69
|
+
/** 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. */
|
|
108
70
|
rt: {
|
|
109
71
|
type: jspsych.ParameterType.INT
|
|
110
72
|
},
|
|
73
|
+
/** 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. */
|
|
111
74
|
question_order: {
|
|
112
75
|
type: jspsych.ParameterType.INT,
|
|
113
76
|
array: true
|
|
@@ -118,7 +81,9 @@ var jsPsychSurveyLikert = (function (jspsych) {
|
|
|
118
81
|
constructor(jsPsych) {
|
|
119
82
|
this.jsPsych = jsPsych;
|
|
120
83
|
}
|
|
121
|
-
static
|
|
84
|
+
static {
|
|
85
|
+
this.info = info;
|
|
86
|
+
}
|
|
122
87
|
trial(display_element, trial) {
|
|
123
88
|
if (trial.scale_width !== null) {
|
|
124
89
|
var w = trial.scale_width + "px";
|
|
@@ -252,4 +217,4 @@ var jsPsychSurveyLikert = (function (jspsych) {
|
|
|
252
217
|
return SurveyLikertPlugin;
|
|
253
218
|
|
|
254
219
|
})(jsPsychModule);
|
|
255
|
-
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-likert@2.0.
|
|
220
|
+
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-likert@2.0.1/dist/index.browser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.js","sources":["../src/index.ts"],"sourcesContent":["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.COMPLEX,\n nested: {\n identifier: {\n type: ParameterType.STRING,\n },\n response: {\n type:\n ParameterType.STRING |\n ParameterType.INT |\n ParameterType.FLOAT |\n ParameterType.BOOL |\n ParameterType.OBJECT,\n },\n },\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","ParameterType"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIA,MAAM,IAAc,GAAA;EAAA,EAClB,IAAM,EAAA,eAAA;EAAA,WACNA,gBAA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B,EAAA,kBAAA,EAAoB,aAA2B,EAAA;EAC7F,IAAA,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,CAA6B,0BAAA,EAAA,OAAA,CAAQ,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,UAAA,EAAe,QAAQ,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA;EAAA,SACpE;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.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":";;;EAEE,IAAW,OAAA,GAAA,OAAA;;ECEb,MAAM,IAAc,GAAA;EAAA,EAClB,IAAM,EAAA,eAAA;EAAA,EACN,OAAA;EAAA,EACA,UAAY,EAAA;EAAA;EAAA,IAEV,SAAW,EAAA;EAAA,MACT,MAAMA,qBAAc,CAAA,OAAA;EAAA,MACpB,KAAO,EAAA,IAAA;EAAA,MACP,MAAQ,EAAA;EAAA;EAAA,QAEN,MAAQ,EAAA;EAAA,UACN,MAAMA,qBAAc,CAAA,WAAA;EAAA,UACpB,OAAS,EAAA,KAAA,CAAA;EAAA,SACX;EAAA;EAAA,QAEA,MAAQ,EAAA;EAAA,UACN,MAAMA,qBAAc,CAAA,MAAA;EAAA,UACpB,KAAO,EAAA,IAAA;EAAA,UAC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,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,2 +1,2 @@
|
|
|
1
|
-
var jsPsychSurveyLikert=function(
|
|
2
|
-
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-likert@2.0.
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.min.js","sources":["../src/index.ts"],"sourcesContent":["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.COMPLEX,\n nested: {\n identifier: {\n type: ParameterType.STRING,\n },\n response: {\n type:\n ParameterType.STRING |\n ParameterType.INT |\n ParameterType.FLOAT |\n ParameterType.BOOL |\n ParameterType.OBJECT,\n },\n },\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":["info","version","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":"g4BAIA,MAAMA,EAAc,CAClB,KAAM,gBACN,QAASC,EAAAA,QACT,WAAY,CAEV,UAAW,CACT,KAAMC,EAAAA,cAAc,QACpB,MAAO,GACP,OAAQ,CAEN,OAAQ,CACN,KAAMA,EAAAA,cAAc,YACpB,QAAS,MACX,EAEA,OAAQ,CACN,KAAMA,EAAAA,cAAc,OACpB,MAAO,GACP,QAAS,MACX,EAEA,SAAU,CACR,KAAMA,EAAAA,cAAc,KACpB,QAAS,EACX,EAEA,KAAM,CACJ,KAAMA,gBAAc,OACpB,QAAS,EACX,CACF,CACF,EAEA,yBAA0B,CACxB,KAAMA,EAAAA,cAAc,KACpB,QAAS,EACX,EAEA,SAAU,CACR,KAAMA,EAAc,cAAA,YACpB,QAAS,IACX,EAEA,YAAa,CACX,KAAMA,EAAc,cAAA,IACpB,QAAS,IACX,EAEA,aAAc,CACZ,KAAMA,EAAAA,cAAc,OACpB,QAAS,UACX,EAEA,aAAc,CACZ,KAAMA,EAAAA,cAAc,KACpB,QAAS,EACX,CACF,EACA,KAAM,CAEJ,SAAU,CACR,KAAMA,EAAc,cAAA,QACpB,OAAQ,CACN,WAAY,CACV,KAAMA,EAAAA,cAAc,MACtB,EACA,SAAU,CACR,KACEA,EAAc,cAAA,OACdA,EAAAA,cAAc,IACdA,EAAAA,cAAc,MACdA,EAAAA,cAAc,KACdA,EAAAA,cAAc,MAClB,CACF,CACF,EAEA,GAAI,CACF,KAAMA,EAAAA,cAAc,GACtB,EAEA,eAAgB,CACd,KAAMA,gBAAc,IACpB,MAAO,EACT,CACF,CACF,EAWA,MAAMC,CAAkD,CAGtD,YAAoBC,EAAkB,CAAlB,KAAAA,QA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O,KAAK,QAAQ,UAAU,oBAAoBD,EAAcJ,CAAkB,EAExF,OAAA,KAAK,QAAQ,UAAU,gCAAgCvB,EAAO4B,CAAI,EAE3DA,CACT,CAEQ,mBAAmB5B,EAAwBuB,EAAoB,CACrE,MAAMK,EAAO,KAAK,uBAAuB5B,EAAOuB,CAAkB,EAElE,KAAK,QAAQ,YAAYK,CAAI,CAC/B,CAEQ,gBAAgB5B,EAAwBuB,EAAoBC,EAA2B,CAC7F,MAAMI,EAAO,KAAK,uBAAuB5B,EAAOuB,CAAkB,EAE5DxB,EAAkB,KAAK,QAAQ,oBAErC,KAAK,MAAMA,EAAiBC,CAAK,EACjCwB,EAAAA,EAEA,MAAMK,EAAU,OAAO,QAAQD,EAAK,QAAQ,EAC5C,QAAS,EAAI,EAAG,EAAIC,EAAQ,OAAQ,IAClC,KAAK,QAAQ,UAAU,YACrB9B,EAAgB,cACd,6BAA6B8B,EAAQ,GAAG,eAAeA,EAAQ,GAAG,MACpE,GACED,EAAK,GAAK,KAAQC,EAAQ,QAAW,EAAI,EAC7C,EAGF,KAAK,QAAQ,UAAU,YACrB9B,EAAgB,cAAc,6BAA6B,EAC3D6B,EAAK,EACP,CACF,CACF,CA9MM/B,OAAAA,EACG,KAAOH"}
|
|
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,EAAAA,cAAc,OACpB,MAAO,GACP,QAAS,MACX,EAEA,SAAU,CACR,KAAMA,EAAAA,cAAc,KACpB,QAAS,EACX,EAEA,KAAM,CACJ,KAAMA,gBAAc,OACpB,QAAS,EACX,CACF,CACF,EAEA,yBAA0B,CACxB,KAAMA,gBAAc,KACpB,QAAS,EACX,EAEA,SAAU,CACR,KAAMA,EAAc,cAAA,YACpB,QAAS,IACX,EAEA,YAAa,CACX,KAAMA,EAAAA,cAAc,IACpB,QAAS,IACX,EAEA,aAAc,CACZ,KAAMA,gBAAc,OACpB,QAAS,UACX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|
|
|
3
3
|
var jspsych = require('jspsych');
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
name: "@jspsych/plugin-survey-likert",
|
|
7
|
-
version: "2.0.0",
|
|
8
|
-
description: "a jspsych plugin for measuring items on a likert scale",
|
|
9
|
-
type: "module",
|
|
10
|
-
main: "dist/index.cjs",
|
|
11
|
-
exports: {
|
|
12
|
-
import: "./dist/index.js",
|
|
13
|
-
require: "./dist/index.cjs"
|
|
14
|
-
},
|
|
15
|
-
typings: "dist/index.d.ts",
|
|
16
|
-
unpkg: "dist/index.browser.min.js",
|
|
17
|
-
files: [
|
|
18
|
-
"src",
|
|
19
|
-
"dist"
|
|
20
|
-
],
|
|
21
|
-
source: "src/index.ts",
|
|
22
|
-
scripts: {
|
|
23
|
-
test: "jest",
|
|
24
|
-
"test:watch": "npm test -- --watch",
|
|
25
|
-
tsc: "tsc",
|
|
26
|
-
build: "rollup --config",
|
|
27
|
-
"build:watch": "npm run build -- --watch"
|
|
28
|
-
},
|
|
29
|
-
repository: {
|
|
30
|
-
type: "git",
|
|
31
|
-
url: "git+https://github.com/jspsych/jsPsych.git",
|
|
32
|
-
directory: "packages/plugin-survey-likert"
|
|
33
|
-
},
|
|
34
|
-
author: "Josh de Leeuw",
|
|
35
|
-
license: "MIT",
|
|
36
|
-
bugs: {
|
|
37
|
-
url: "https://github.com/jspsych/jsPsych/issues"
|
|
38
|
-
},
|
|
39
|
-
homepage: "https://www.jspsych.org/latest/plugins/survey-likert",
|
|
40
|
-
peerDependencies: {
|
|
41
|
-
jspsych: ">=7.1.0"
|
|
42
|
-
},
|
|
43
|
-
devDependencies: {
|
|
44
|
-
"@jspsych/config": "^3.0.0",
|
|
45
|
-
"@jspsych/test-utils": "^1.2.0"
|
|
46
|
-
}
|
|
47
|
-
};
|
|
5
|
+
var version = "2.0.1";
|
|
48
6
|
|
|
49
7
|
const info = {
|
|
50
8
|
name: "survey-likert",
|
|
51
|
-
version
|
|
9
|
+
version,
|
|
52
10
|
parameters: {
|
|
11
|
+
/** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */
|
|
53
12
|
questions: {
|
|
54
13
|
type: jspsych.ParameterType.COMPLEX,
|
|
55
14
|
array: true,
|
|
56
15
|
nested: {
|
|
16
|
+
/** Question prompt. */
|
|
57
17
|
prompt: {
|
|
58
18
|
type: jspsych.ParameterType.HTML_STRING,
|
|
59
19
|
default: void 0
|
|
60
20
|
},
|
|
21
|
+
/** Array of likert labels to display for this question. */
|
|
61
22
|
labels: {
|
|
62
23
|
type: jspsych.ParameterType.STRING,
|
|
63
24
|
array: true,
|
|
64
25
|
default: void 0
|
|
65
26
|
},
|
|
27
|
+
/** Whether or not a response to this question must be given in order to continue. */
|
|
66
28
|
required: {
|
|
67
29
|
type: jspsych.ParameterType.BOOL,
|
|
68
30
|
default: false
|
|
69
31
|
},
|
|
32
|
+
/** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */
|
|
70
33
|
name: {
|
|
71
34
|
type: jspsych.ParameterType.STRING,
|
|
72
35
|
default: ""
|
|
73
36
|
}
|
|
74
37
|
}
|
|
75
38
|
},
|
|
39
|
+
/** If true, the order of the questions in the 'questions' array will be randomized. */
|
|
76
40
|
randomize_question_order: {
|
|
77
41
|
type: jspsych.ParameterType.BOOL,
|
|
78
42
|
default: false
|
|
79
43
|
},
|
|
44
|
+
/** HTML-formatted string to display at top of the page above all of the questions. */
|
|
80
45
|
preamble: {
|
|
81
46
|
type: jspsych.ParameterType.HTML_STRING,
|
|
82
47
|
default: null
|
|
83
48
|
},
|
|
49
|
+
/** Width of the likert scales in pixels. */
|
|
84
50
|
scale_width: {
|
|
85
51
|
type: jspsych.ParameterType.INT,
|
|
86
52
|
default: null
|
|
87
53
|
},
|
|
54
|
+
/** Label of the button to submit responses. */
|
|
88
55
|
button_label: {
|
|
89
56
|
type: jspsych.ParameterType.STRING,
|
|
90
57
|
default: "Continue"
|
|
91
58
|
},
|
|
59
|
+
/** Setting this to true will enable browser auto-complete or auto-fill for the form. */
|
|
92
60
|
autocomplete: {
|
|
93
61
|
type: jspsych.ParameterType.BOOL,
|
|
94
62
|
default: false
|
|
95
63
|
}
|
|
96
64
|
},
|
|
97
65
|
data: {
|
|
66
|
+
/** 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. */
|
|
98
67
|
response: {
|
|
99
|
-
type: jspsych.ParameterType.
|
|
100
|
-
nested: {
|
|
101
|
-
identifier: {
|
|
102
|
-
type: jspsych.ParameterType.STRING
|
|
103
|
-
},
|
|
104
|
-
response: {
|
|
105
|
-
type: jspsych.ParameterType.STRING | jspsych.ParameterType.INT | jspsych.ParameterType.FLOAT | jspsych.ParameterType.BOOL | jspsych.ParameterType.OBJECT
|
|
106
|
-
}
|
|
107
|
-
}
|
|
68
|
+
type: jspsych.ParameterType.OBJECT
|
|
108
69
|
},
|
|
70
|
+
/** 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. */
|
|
109
71
|
rt: {
|
|
110
72
|
type: jspsych.ParameterType.INT
|
|
111
73
|
},
|
|
74
|
+
/** 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. */
|
|
112
75
|
question_order: {
|
|
113
76
|
type: jspsych.ParameterType.INT,
|
|
114
77
|
array: true
|
|
@@ -119,6 +82,9 @@ class SurveyLikertPlugin {
|
|
|
119
82
|
constructor(jsPsych) {
|
|
120
83
|
this.jsPsych = jsPsych;
|
|
121
84
|
}
|
|
85
|
+
static {
|
|
86
|
+
this.info = info;
|
|
87
|
+
}
|
|
122
88
|
trial(display_element, trial) {
|
|
123
89
|
if (trial.scale_width !== null) {
|
|
124
90
|
var w = trial.scale_width + "px";
|
|
@@ -248,7 +214,6 @@ class SurveyLikertPlugin {
|
|
|
248
214
|
);
|
|
249
215
|
}
|
|
250
216
|
}
|
|
251
|
-
SurveyLikertPlugin.info = info;
|
|
252
217
|
|
|
253
218
|
module.exports = SurveyLikertPlugin;
|
|
254
219
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["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.COMPLEX,\n nested: {\n identifier: {\n type: ParameterType.STRING,\n },\n response: {\n type:\n ParameterType.STRING |\n ParameterType.INT |\n ParameterType.FLOAT |\n ParameterType.BOOL |\n ParameterType.OBJECT,\n },\n },\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","ParameterType"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAM,IAAc,GAAA;AAAA,EAClB,IAAM,EAAA,eAAA;AAAA,WACNA,gBAAA;AAAA,EACA,UAAY,EAAA;AAAA,IAEV,SAAW,EAAA;AAAA,MACT,MAAMC,qBAAc,CAAA,OAAA;AAAA,MACpB,KAAO,EAAA,IAAA;AAAA,MACP,MAAQ,EAAA;AAAA,QAEN,MAAQ,EAAA;AAAA,UACN,MAAMA,qBAAc,CAAA,WAAA;AAAA,UACpB,OAAS,EAAA,KAAA,CAAA;AAAA,SACX;AAAA,QAEA,MAAQ,EAAA;AAAA,UACN,MAAMA,qBAAc,CAAA,MAAA;AAAA,UACpB,KAAO,EAAA,IAAA;AAAA,UACP,OAAS,EAAA,KAAA,CAAA;AAAA,SACX;AAAA,QAEA,QAAU,EAAA;AAAA,UACR,MAAMA,qBAAc,CAAA,IAAA;AAAA,UACpB,OAAS,EAAA,KAAA;AAAA,SACX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A;AAAA,QACrB,eAAgB,CAAA,aAAA;AAAA,UACd,CAA6B,0BAAA,EAAA,OAAA,CAAQ,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,UAAA,EAAe,QAAQ,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA;AAAA,SACpE;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,CAAA;AA9MM,kBAAA,CACG,IAAO,GAAA,IAAA;;;;"}
|
|
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,MAAMA,qBAAc,CAAA,OAAA;AAAA,MACpB,KAAO,EAAA,IAAA;AAAA,MACP,MAAQ,EAAA;AAAA;AAAA,QAEN,MAAQ,EAAA;AAAA,UACN,MAAMA,qBAAc,CAAA,WAAA;AAAA,UACpB,OAAS,EAAA,KAAA,CAAA;AAAA,SACX;AAAA;AAAA,QAEA,MAAQ,EAAA;AAAA,UACN,MAAMA,qBAAc,CAAA,MAAA;AAAA,UACpB,KAAO,EAAA,IAAA;AAAA,UACP,OAAS,EAAA,KAAA,CAAA;AAAA,SACX;AAAA;AAAA,QAEA,QAAU,EAAA;AAAA,UACR,MAAMA,qBAAc,CAAA,IAAA;AAAA,UACpB,OAAS,EAAA,KAAA;AAAA,SACX;AAAA;AAAA,QAEA,IAAM,EAAA;AAAA,UACJ,MAAMA,qBAAc,CAAA,MAAA;AAAA,UACpB,OAAS,EAAA,EAAA;AAAA,SACX;AAAA,OACF;AAAA,KACF;AAAA;AAAA,IAEA,wBAA0B,EAAA;AAAA,MACxB,MAAMA,qBAAc,CAAA,IAAA;AAAA,MACpB,OAAS,EAAA,KAAA;AAAA,KACX;AAAA;AAAA,IAEA,QAAU,EAAA;AAAA,MACR,MAAMA,qBAAc,CAAA,WAAA;AAAA,MACpB,OAAS,EAAA,IAAA;AAAA,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
@@ -61,15 +61,7 @@ declare const info: {
|
|
|
61
61
|
readonly data: {
|
|
62
62
|
/** 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. */
|
|
63
63
|
readonly response: {
|
|
64
|
-
readonly type: ParameterType.
|
|
65
|
-
readonly nested: {
|
|
66
|
-
readonly identifier: {
|
|
67
|
-
readonly type: ParameterType.STRING;
|
|
68
|
-
};
|
|
69
|
-
readonly response: {
|
|
70
|
-
readonly type: number;
|
|
71
|
-
};
|
|
72
|
-
};
|
|
64
|
+
readonly type: ParameterType.OBJECT;
|
|
73
65
|
};
|
|
74
66
|
/** 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. */
|
|
75
67
|
readonly rt: {
|
|
@@ -153,15 +145,7 @@ declare class SurveyLikertPlugin implements JsPsychPlugin<Info> {
|
|
|
153
145
|
readonly data: {
|
|
154
146
|
/** 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. */
|
|
155
147
|
readonly response: {
|
|
156
|
-
readonly type: ParameterType.
|
|
157
|
-
readonly nested: {
|
|
158
|
-
readonly identifier: {
|
|
159
|
-
readonly type: ParameterType.STRING;
|
|
160
|
-
};
|
|
161
|
-
readonly response: {
|
|
162
|
-
readonly type: number;
|
|
163
|
-
};
|
|
164
|
-
};
|
|
148
|
+
readonly type: ParameterType.OBJECT;
|
|
165
149
|
};
|
|
166
150
|
/** 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. */
|
|
167
151
|
readonly rt: {
|
package/dist/index.js
CHANGED
|
@@ -1,112 +1,75 @@
|
|
|
1
1
|
import { ParameterType } from 'jspsych';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
name: "@jspsych/plugin-survey-likert",
|
|
5
|
-
version: "2.0.0",
|
|
6
|
-
description: "a jspsych plugin for measuring items on a likert scale",
|
|
7
|
-
type: "module",
|
|
8
|
-
main: "dist/index.cjs",
|
|
9
|
-
exports: {
|
|
10
|
-
import: "./dist/index.js",
|
|
11
|
-
require: "./dist/index.cjs"
|
|
12
|
-
},
|
|
13
|
-
typings: "dist/index.d.ts",
|
|
14
|
-
unpkg: "dist/index.browser.min.js",
|
|
15
|
-
files: [
|
|
16
|
-
"src",
|
|
17
|
-
"dist"
|
|
18
|
-
],
|
|
19
|
-
source: "src/index.ts",
|
|
20
|
-
scripts: {
|
|
21
|
-
test: "jest",
|
|
22
|
-
"test:watch": "npm test -- --watch",
|
|
23
|
-
tsc: "tsc",
|
|
24
|
-
build: "rollup --config",
|
|
25
|
-
"build:watch": "npm run build -- --watch"
|
|
26
|
-
},
|
|
27
|
-
repository: {
|
|
28
|
-
type: "git",
|
|
29
|
-
url: "git+https://github.com/jspsych/jsPsych.git",
|
|
30
|
-
directory: "packages/plugin-survey-likert"
|
|
31
|
-
},
|
|
32
|
-
author: "Josh de Leeuw",
|
|
33
|
-
license: "MIT",
|
|
34
|
-
bugs: {
|
|
35
|
-
url: "https://github.com/jspsych/jsPsych/issues"
|
|
36
|
-
},
|
|
37
|
-
homepage: "https://www.jspsych.org/latest/plugins/survey-likert",
|
|
38
|
-
peerDependencies: {
|
|
39
|
-
jspsych: ">=7.1.0"
|
|
40
|
-
},
|
|
41
|
-
devDependencies: {
|
|
42
|
-
"@jspsych/config": "^3.0.0",
|
|
43
|
-
"@jspsych/test-utils": "^1.2.0"
|
|
44
|
-
}
|
|
45
|
-
};
|
|
3
|
+
var version = "2.0.1";
|
|
46
4
|
|
|
47
5
|
const info = {
|
|
48
6
|
name: "survey-likert",
|
|
49
|
-
version
|
|
7
|
+
version,
|
|
50
8
|
parameters: {
|
|
9
|
+
/** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */
|
|
51
10
|
questions: {
|
|
52
11
|
type: ParameterType.COMPLEX,
|
|
53
12
|
array: true,
|
|
54
13
|
nested: {
|
|
14
|
+
/** Question prompt. */
|
|
55
15
|
prompt: {
|
|
56
16
|
type: ParameterType.HTML_STRING,
|
|
57
17
|
default: void 0
|
|
58
18
|
},
|
|
19
|
+
/** Array of likert labels to display for this question. */
|
|
59
20
|
labels: {
|
|
60
21
|
type: ParameterType.STRING,
|
|
61
22
|
array: true,
|
|
62
23
|
default: void 0
|
|
63
24
|
},
|
|
25
|
+
/** Whether or not a response to this question must be given in order to continue. */
|
|
64
26
|
required: {
|
|
65
27
|
type: ParameterType.BOOL,
|
|
66
28
|
default: false
|
|
67
29
|
},
|
|
30
|
+
/** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */
|
|
68
31
|
name: {
|
|
69
32
|
type: ParameterType.STRING,
|
|
70
33
|
default: ""
|
|
71
34
|
}
|
|
72
35
|
}
|
|
73
36
|
},
|
|
37
|
+
/** If true, the order of the questions in the 'questions' array will be randomized. */
|
|
74
38
|
randomize_question_order: {
|
|
75
39
|
type: ParameterType.BOOL,
|
|
76
40
|
default: false
|
|
77
41
|
},
|
|
42
|
+
/** HTML-formatted string to display at top of the page above all of the questions. */
|
|
78
43
|
preamble: {
|
|
79
44
|
type: ParameterType.HTML_STRING,
|
|
80
45
|
default: null
|
|
81
46
|
},
|
|
47
|
+
/** Width of the likert scales in pixels. */
|
|
82
48
|
scale_width: {
|
|
83
49
|
type: ParameterType.INT,
|
|
84
50
|
default: null
|
|
85
51
|
},
|
|
52
|
+
/** Label of the button to submit responses. */
|
|
86
53
|
button_label: {
|
|
87
54
|
type: ParameterType.STRING,
|
|
88
55
|
default: "Continue"
|
|
89
56
|
},
|
|
57
|
+
/** Setting this to true will enable browser auto-complete or auto-fill for the form. */
|
|
90
58
|
autocomplete: {
|
|
91
59
|
type: ParameterType.BOOL,
|
|
92
60
|
default: false
|
|
93
61
|
}
|
|
94
62
|
},
|
|
95
63
|
data: {
|
|
64
|
+
/** 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. */
|
|
96
65
|
response: {
|
|
97
|
-
type: ParameterType.
|
|
98
|
-
nested: {
|
|
99
|
-
identifier: {
|
|
100
|
-
type: ParameterType.STRING
|
|
101
|
-
},
|
|
102
|
-
response: {
|
|
103
|
-
type: ParameterType.STRING | ParameterType.INT | ParameterType.FLOAT | ParameterType.BOOL | ParameterType.OBJECT
|
|
104
|
-
}
|
|
105
|
-
}
|
|
66
|
+
type: ParameterType.OBJECT
|
|
106
67
|
},
|
|
68
|
+
/** 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. */
|
|
107
69
|
rt: {
|
|
108
70
|
type: ParameterType.INT
|
|
109
71
|
},
|
|
72
|
+
/** 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. */
|
|
110
73
|
question_order: {
|
|
111
74
|
type: ParameterType.INT,
|
|
112
75
|
array: true
|
|
@@ -117,6 +80,9 @@ class SurveyLikertPlugin {
|
|
|
117
80
|
constructor(jsPsych) {
|
|
118
81
|
this.jsPsych = jsPsych;
|
|
119
82
|
}
|
|
83
|
+
static {
|
|
84
|
+
this.info = info;
|
|
85
|
+
}
|
|
120
86
|
trial(display_element, trial) {
|
|
121
87
|
if (trial.scale_width !== null) {
|
|
122
88
|
var w = trial.scale_width + "px";
|
|
@@ -246,7 +212,6 @@ class SurveyLikertPlugin {
|
|
|
246
212
|
);
|
|
247
213
|
}
|
|
248
214
|
}
|
|
249
|
-
SurveyLikertPlugin.info = info;
|
|
250
215
|
|
|
251
216
|
export { SurveyLikertPlugin as default };
|
|
252
217
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["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.COMPLEX,\n nested: {\n identifier: {\n type: ParameterType.STRING,\n },\n response: {\n type:\n ParameterType.STRING |\n ParameterType.INT |\n ParameterType.FLOAT |\n ParameterType.BOOL |\n ParameterType.OBJECT,\n },\n },\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAM,IAAc,GAAA;AAAA,EAClB,IAAM,EAAA,eAAA;AAAA,WACNA,gBAAA;AAAA,EACA,UAAY,EAAA;AAAA,IAEV,SAAW,EAAA;AAAA,MACT,MAAM,aAAc,CAAA,OAAA;AAAA,MACpB,KAAO,EAAA,IAAA;AAAA,MACP,MAAQ,EAAA;AAAA,QAEN,MAAQ,EAAA;AAAA,UACN,MAAM,aAAc,CAAA,WAAA;AAAA,UACpB,OAAS,EAAA,KAAA,CAAA;AAAA,SACX;AAAA,QAEA,MAAQ,EAAA;AAAA,UACN,MAAM,aAAc,CAAA,MAAA;AAAA,UACpB,KAAO,EAAA,IAAA;AAAA,UACP,OAAS,EAAA,KAAA,CAAA;AAAA,SACX;AAAA,QAEA,QAAU,EAAA;AAAA,UACR,MAAM,aAAc,CAAA,IAAA;AAAA,UACpB,OAAS,EAAA,KAAA;AAAA,SACX;AAAA,QAEA,IAAM,EAAA;AAAA,UACJ,MAAM,aAAc,CAAA,MAAA;AAAA,UACpB,OAAS,EAAA,EAA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,QAAQ,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA;AAAA,SACpE;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,CAAA;AA9MM,kBAAA,CACG,IAAO,GAAA,IAAA;;;;"}
|
|
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,MACZ,M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A,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;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jspsych/plugin-survey-likert",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
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.
|
|
40
|
+
"@jspsych/config": "^3.1.1",
|
|
41
41
|
"@jspsych/test-utils": "^1.2.0"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/index.ts
CHANGED
|
@@ -63,20 +63,7 @@ const info = <const>{
|
|
|
63
63
|
data: {
|
|
64
64
|
/** 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. */
|
|
65
65
|
response: {
|
|
66
|
-
type: ParameterType.
|
|
67
|
-
nested: {
|
|
68
|
-
identifier: {
|
|
69
|
-
type: ParameterType.STRING,
|
|
70
|
-
},
|
|
71
|
-
response: {
|
|
72
|
-
type:
|
|
73
|
-
ParameterType.STRING |
|
|
74
|
-
ParameterType.INT |
|
|
75
|
-
ParameterType.FLOAT |
|
|
76
|
-
ParameterType.BOOL |
|
|
77
|
-
ParameterType.OBJECT,
|
|
78
|
-
},
|
|
79
|
-
},
|
|
66
|
+
type: ParameterType.OBJECT,
|
|
80
67
|
},
|
|
81
68
|
/** 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. */
|
|
82
69
|
rt: {
|