@jspsych/plugin-survey-likert 1.1.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.js +230 -226
- 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 +228 -224
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +55 -26
- package/dist/index.js +228 -224
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.spec.ts +1 -1
- package/src/index.ts +34 -16
package/dist/index.browser.js
CHANGED
|
@@ -1,251 +1,255 @@
|
|
|
1
1
|
var jsPsychSurveyLikert = (function (jspsych) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
var _package = {
|
|
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
|
+
};
|
|
47
|
+
|
|
4
48
|
const info = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type: jspsych.ParameterType.HTML_STRING,
|
|
16
|
-
pretty_name: "Prompt",
|
|
17
|
-
default: undefined,
|
|
18
|
-
},
|
|
19
|
-
/** Array of likert labels to display for this question. */
|
|
20
|
-
labels: {
|
|
21
|
-
type: jspsych.ParameterType.STRING,
|
|
22
|
-
array: true,
|
|
23
|
-
pretty_name: "Labels",
|
|
24
|
-
default: undefined,
|
|
25
|
-
},
|
|
26
|
-
/** Whether or not a response to this question must be given in order to continue. */
|
|
27
|
-
required: {
|
|
28
|
-
type: jspsych.ParameterType.BOOL,
|
|
29
|
-
pretty_name: "Required",
|
|
30
|
-
default: false,
|
|
31
|
-
},
|
|
32
|
-
/** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */
|
|
33
|
-
name: {
|
|
34
|
-
type: jspsych.ParameterType.STRING,
|
|
35
|
-
pretty_name: "Question Name",
|
|
36
|
-
default: "",
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
/** If true, the order of the questions in the 'questions' array will be randomized. */
|
|
41
|
-
randomize_question_order: {
|
|
42
|
-
type: jspsych.ParameterType.BOOL,
|
|
43
|
-
pretty_name: "Randomize Question Order",
|
|
44
|
-
default: false,
|
|
45
|
-
},
|
|
46
|
-
/** HTML-formatted string to display at top of the page above all of the questions. */
|
|
47
|
-
preamble: {
|
|
48
|
-
type: jspsych.ParameterType.HTML_STRING,
|
|
49
|
-
pretty_name: "Preamble",
|
|
50
|
-
default: null,
|
|
49
|
+
name: "survey-likert",
|
|
50
|
+
version: _package.version,
|
|
51
|
+
parameters: {
|
|
52
|
+
questions: {
|
|
53
|
+
type: jspsych.ParameterType.COMPLEX,
|
|
54
|
+
array: true,
|
|
55
|
+
nested: {
|
|
56
|
+
prompt: {
|
|
57
|
+
type: jspsych.ParameterType.HTML_STRING,
|
|
58
|
+
default: void 0
|
|
51
59
|
},
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
default: null,
|
|
60
|
+
labels: {
|
|
61
|
+
type: jspsych.ParameterType.STRING,
|
|
62
|
+
array: true,
|
|
63
|
+
default: void 0
|
|
57
64
|
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
pretty_name: "Button label",
|
|
62
|
-
default: "Continue",
|
|
65
|
+
required: {
|
|
66
|
+
type: jspsych.ParameterType.BOOL,
|
|
67
|
+
default: false
|
|
63
68
|
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
name: {
|
|
70
|
+
type: jspsych.ParameterType.STRING,
|
|
71
|
+
default: ""
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
randomize_question_order: {
|
|
76
|
+
type: jspsych.ParameterType.BOOL,
|
|
77
|
+
default: false
|
|
78
|
+
},
|
|
79
|
+
preamble: {
|
|
80
|
+
type: jspsych.ParameterType.HTML_STRING,
|
|
81
|
+
default: null
|
|
82
|
+
},
|
|
83
|
+
scale_width: {
|
|
84
|
+
type: jspsych.ParameterType.INT,
|
|
85
|
+
default: null
|
|
86
|
+
},
|
|
87
|
+
button_label: {
|
|
88
|
+
type: jspsych.ParameterType.STRING,
|
|
89
|
+
default: "Continue"
|
|
90
|
+
},
|
|
91
|
+
autocomplete: {
|
|
92
|
+
type: jspsych.ParameterType.BOOL,
|
|
93
|
+
default: false
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
data: {
|
|
97
|
+
response: {
|
|
98
|
+
type: jspsych.ParameterType.COMPLEX,
|
|
99
|
+
nested: {
|
|
100
|
+
identifier: {
|
|
101
|
+
type: jspsych.ParameterType.STRING
|
|
69
102
|
},
|
|
103
|
+
response: {
|
|
104
|
+
type: jspsych.ParameterType.STRING | jspsych.ParameterType.INT | jspsych.ParameterType.FLOAT | jspsych.ParameterType.BOOL | jspsych.ParameterType.OBJECT
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
rt: {
|
|
109
|
+
type: jspsych.ParameterType.INT
|
|
70
110
|
},
|
|
111
|
+
question_order: {
|
|
112
|
+
type: jspsych.ParameterType.INT,
|
|
113
|
+
array: true
|
|
114
|
+
}
|
|
115
|
+
}
|
|
71
116
|
};
|
|
72
|
-
/**
|
|
73
|
-
* **survey-likert**
|
|
74
|
-
*
|
|
75
|
-
* jsPsych plugin for gathering responses to questions on a likert scale
|
|
76
|
-
*
|
|
77
|
-
* @author Josh de Leeuw
|
|
78
|
-
* @see {@link https://www.jspsych.org/plugins/jspsych-survey-likert/ survey-likert plugin documentation on jspsych.org}
|
|
79
|
-
*/
|
|
80
117
|
class SurveyLikertPlugin {
|
|
81
|
-
|
|
82
|
-
|
|
118
|
+
constructor(jsPsych) {
|
|
119
|
+
this.jsPsych = jsPsych;
|
|
120
|
+
}
|
|
121
|
+
static info = info;
|
|
122
|
+
trial(display_element, trial) {
|
|
123
|
+
if (trial.scale_width !== null) {
|
|
124
|
+
var w = trial.scale_width + "px";
|
|
125
|
+
} else {
|
|
126
|
+
var w = "100%";
|
|
83
127
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (trial.autocomplete) {
|
|
113
|
-
html += '<form id="jspsych-survey-likert-form">';
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
html += '<form id="jspsych-survey-likert-form" autocomplete="off">';
|
|
117
|
-
}
|
|
118
|
-
// add likert scale questions ///
|
|
119
|
-
// generate question order. this is randomized here as opposed to randomizing the order of trial.questions
|
|
120
|
-
// so that the data are always associated with the same question regardless of order
|
|
121
|
-
var question_order = [];
|
|
122
|
-
for (var i = 0; i < trial.questions.length; i++) {
|
|
123
|
-
question_order.push(i);
|
|
124
|
-
}
|
|
125
|
-
if (trial.randomize_question_order) {
|
|
126
|
-
question_order = this.jsPsych.randomization.shuffle(question_order);
|
|
127
|
-
}
|
|
128
|
-
for (var i = 0; i < trial.questions.length; i++) {
|
|
129
|
-
var question = trial.questions[question_order[i]];
|
|
130
|
-
// add question
|
|
131
|
-
html += '<label class="jspsych-survey-likert-statement">' + question.prompt + "</label>";
|
|
132
|
-
// add options
|
|
133
|
-
var width = 100 / question.labels.length;
|
|
134
|
-
var options_string = '<ul class="jspsych-survey-likert-opts" data-name="' +
|
|
135
|
-
question.name +
|
|
136
|
-
'" data-radio-group="Q' +
|
|
137
|
-
question_order[i] +
|
|
138
|
-
'">';
|
|
139
|
-
for (var j = 0; j < question.labels.length; j++) {
|
|
140
|
-
options_string +=
|
|
141
|
-
'<li style="width:' +
|
|
142
|
-
width +
|
|
143
|
-
'%"><label class="jspsych-survey-likert-opt-label"><input type="radio" name="Q' +
|
|
144
|
-
question_order[i] +
|
|
145
|
-
'" value="' +
|
|
146
|
-
j +
|
|
147
|
-
'"';
|
|
148
|
-
if (question.required) {
|
|
149
|
-
options_string += " required";
|
|
150
|
-
}
|
|
151
|
-
options_string += ">" + question.labels[j] + "</label></li>";
|
|
152
|
-
}
|
|
153
|
-
options_string += "</ul>";
|
|
154
|
-
html += options_string;
|
|
128
|
+
var html = "";
|
|
129
|
+
html += '<style id="jspsych-survey-likert-css">';
|
|
130
|
+
html += ".jspsych-survey-likert-statement { display:block; font-size: 16px; padding-top: 40px; margin-bottom:10px; }.jspsych-survey-likert-opts { list-style:none; width:" + w + "; 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; }";
|
|
131
|
+
html += "</style>";
|
|
132
|
+
if (trial.preamble !== null) {
|
|
133
|
+
html += '<div id="jspsych-survey-likert-preamble" class="jspsych-survey-likert-preamble">' + trial.preamble + "</div>";
|
|
134
|
+
}
|
|
135
|
+
if (trial.autocomplete) {
|
|
136
|
+
html += '<form id="jspsych-survey-likert-form">';
|
|
137
|
+
} else {
|
|
138
|
+
html += '<form id="jspsych-survey-likert-form" autocomplete="off">';
|
|
139
|
+
}
|
|
140
|
+
var question_order = [];
|
|
141
|
+
for (var i = 0; i < trial.questions.length; i++) {
|
|
142
|
+
question_order.push(i);
|
|
143
|
+
}
|
|
144
|
+
if (trial.randomize_question_order) {
|
|
145
|
+
question_order = this.jsPsych.randomization.shuffle(question_order);
|
|
146
|
+
}
|
|
147
|
+
for (var i = 0; i < trial.questions.length; i++) {
|
|
148
|
+
var question = trial.questions[question_order[i]];
|
|
149
|
+
html += '<label class="jspsych-survey-likert-statement">' + question.prompt + "</label>";
|
|
150
|
+
var width = 100 / question.labels.length;
|
|
151
|
+
var options_string = '<ul class="jspsych-survey-likert-opts" data-name="' + question.name + '" data-radio-group="Q' + question_order[i] + '">';
|
|
152
|
+
for (var j = 0; j < question.labels.length; j++) {
|
|
153
|
+
options_string += '<li style="width:' + width + '%"><label class="jspsych-survey-likert-opt-label"><input type="radio" name="Q' + question_order[i] + '" value="' + j + '"';
|
|
154
|
+
if (question.required) {
|
|
155
|
+
options_string += " required";
|
|
155
156
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
'"></input>';
|
|
161
|
-
html += "</form>";
|
|
162
|
-
display_element.innerHTML = html;
|
|
163
|
-
display_element.querySelector("#jspsych-survey-likert-form").addEventListener("submit", (e) => {
|
|
164
|
-
e.preventDefault();
|
|
165
|
-
// measure response time
|
|
166
|
-
var endTime = performance.now();
|
|
167
|
-
var response_time = Math.round(endTime - startTime);
|
|
168
|
-
// create object to hold responses
|
|
169
|
-
var question_data = {};
|
|
170
|
-
var matches = display_element.querySelectorAll("#jspsych-survey-likert-form .jspsych-survey-likert-opts");
|
|
171
|
-
for (var index = 0; index < matches.length; index++) {
|
|
172
|
-
var id = matches[index].dataset["radioGroup"];
|
|
173
|
-
var el = display_element.querySelector('input[name="' + id + '"]:checked');
|
|
174
|
-
if (el === null) {
|
|
175
|
-
var response = "";
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
var response = parseInt(el.value);
|
|
179
|
-
}
|
|
180
|
-
var obje = {};
|
|
181
|
-
if (matches[index].attributes["data-name"].value !== "") {
|
|
182
|
-
var name = matches[index].attributes["data-name"].value;
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
var name = id;
|
|
186
|
-
}
|
|
187
|
-
obje[name] = response;
|
|
188
|
-
Object.assign(question_data, obje);
|
|
189
|
-
}
|
|
190
|
-
// save data
|
|
191
|
-
var trial_data = {
|
|
192
|
-
rt: response_time,
|
|
193
|
-
response: question_data,
|
|
194
|
-
question_order: question_order,
|
|
195
|
-
};
|
|
196
|
-
display_element.innerHTML = "";
|
|
197
|
-
// next trial
|
|
198
|
-
this.jsPsych.finishTrial(trial_data);
|
|
199
|
-
});
|
|
200
|
-
var startTime = performance.now();
|
|
157
|
+
options_string += ">" + question.labels[j] + "</label></li>";
|
|
158
|
+
}
|
|
159
|
+
options_string += "</ul>";
|
|
160
|
+
html += options_string;
|
|
201
161
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
162
|
+
html += '<input type="submit" id="jspsych-survey-likert-next" class="jspsych-survey-likert jspsych-btn" value="' + trial.button_label + '"></input>';
|
|
163
|
+
html += "</form>";
|
|
164
|
+
display_element.innerHTML = html;
|
|
165
|
+
display_element.querySelector("#jspsych-survey-likert-form").addEventListener("submit", (e) => {
|
|
166
|
+
e.preventDefault();
|
|
167
|
+
var endTime = performance.now();
|
|
168
|
+
var response_time = Math.round(endTime - startTime);
|
|
169
|
+
var question_data = {};
|
|
170
|
+
var matches = display_element.querySelectorAll(
|
|
171
|
+
"#jspsych-survey-likert-form .jspsych-survey-likert-opts"
|
|
172
|
+
);
|
|
173
|
+
for (var index = 0; index < matches.length; index++) {
|
|
174
|
+
var id = matches[index].dataset["radioGroup"];
|
|
175
|
+
var el = display_element.querySelector(
|
|
176
|
+
'input[name="' + id + '"]:checked'
|
|
177
|
+
);
|
|
178
|
+
if (el === null) {
|
|
179
|
+
var response = "";
|
|
180
|
+
} else {
|
|
181
|
+
var response = parseInt(el.value);
|
|
206
182
|
}
|
|
207
|
-
|
|
208
|
-
|
|
183
|
+
var obje = {};
|
|
184
|
+
if (matches[index].attributes["data-name"].value !== "") {
|
|
185
|
+
var name = matches[index].attributes["data-name"].value;
|
|
186
|
+
} else {
|
|
187
|
+
var name = id;
|
|
209
188
|
}
|
|
189
|
+
obje[name] = response;
|
|
190
|
+
Object.assign(question_data, obje);
|
|
191
|
+
}
|
|
192
|
+
var trial_data = {
|
|
193
|
+
rt: response_time,
|
|
194
|
+
response: question_data,
|
|
195
|
+
question_order
|
|
196
|
+
};
|
|
197
|
+
this.jsPsych.finishTrial(trial_data);
|
|
198
|
+
});
|
|
199
|
+
var startTime = performance.now();
|
|
200
|
+
}
|
|
201
|
+
simulate(trial, simulation_mode, simulation_options, load_callback) {
|
|
202
|
+
if (simulation_mode == "data-only") {
|
|
203
|
+
load_callback();
|
|
204
|
+
this.simulate_data_only(trial, simulation_options);
|
|
210
205
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
let rt = 1000;
|
|
214
|
-
for (const q of trial.questions) {
|
|
215
|
-
const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;
|
|
216
|
-
question_data[name] = this.jsPsych.randomization.randomInt(0, q.labels.length - 1);
|
|
217
|
-
rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);
|
|
218
|
-
}
|
|
219
|
-
const default_data = {
|
|
220
|
-
response: question_data,
|
|
221
|
-
rt: rt,
|
|
222
|
-
question_order: trial.randomize_question_order
|
|
223
|
-
? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])
|
|
224
|
-
: [...Array(trial.questions.length).keys()],
|
|
225
|
-
};
|
|
226
|
-
const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
|
|
227
|
-
this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
|
|
228
|
-
return data;
|
|
206
|
+
if (simulation_mode == "visual") {
|
|
207
|
+
this.simulate_visual(trial, simulation_options, load_callback);
|
|
229
208
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
209
|
+
}
|
|
210
|
+
create_simulation_data(trial, simulation_options) {
|
|
211
|
+
const question_data = {};
|
|
212
|
+
let rt = 1e3;
|
|
213
|
+
for (const q of trial.questions) {
|
|
214
|
+
const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;
|
|
215
|
+
question_data[name] = this.jsPsych.randomization.randomInt(0, q.labels.length - 1);
|
|
216
|
+
rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);
|
|
233
217
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
218
|
+
const default_data = {
|
|
219
|
+
response: question_data,
|
|
220
|
+
rt,
|
|
221
|
+
question_order: trial.randomize_question_order ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()]) : [...Array(trial.questions.length).keys()]
|
|
222
|
+
};
|
|
223
|
+
const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
|
|
224
|
+
this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
|
|
225
|
+
return data;
|
|
226
|
+
}
|
|
227
|
+
simulate_data_only(trial, simulation_options) {
|
|
228
|
+
const data = this.create_simulation_data(trial, simulation_options);
|
|
229
|
+
this.jsPsych.finishTrial(data);
|
|
230
|
+
}
|
|
231
|
+
simulate_visual(trial, simulation_options, load_callback) {
|
|
232
|
+
const data = this.create_simulation_data(trial, simulation_options);
|
|
233
|
+
const display_element = this.jsPsych.getDisplayElement();
|
|
234
|
+
this.trial(display_element, trial);
|
|
235
|
+
load_callback();
|
|
236
|
+
const answers = Object.entries(data.response);
|
|
237
|
+
for (let i = 0; i < answers.length; i++) {
|
|
238
|
+
this.jsPsych.pluginAPI.clickTarget(
|
|
239
|
+
display_element.querySelector(
|
|
240
|
+
`input[type="radio"][name="${answers[i][0]}"][value="${answers[i][1]}"]`
|
|
241
|
+
),
|
|
242
|
+
(data.rt - 1e3) / answers.length * (i + 1)
|
|
243
|
+
);
|
|
244
244
|
}
|
|
245
|
+
this.jsPsych.pluginAPI.clickTarget(
|
|
246
|
+
display_element.querySelector("#jspsych-survey-likert-next"),
|
|
247
|
+
data.rt
|
|
248
|
+
);
|
|
249
|
+
}
|
|
245
250
|
}
|
|
246
|
-
SurveyLikertPlugin.info = info;
|
|
247
251
|
|
|
248
252
|
return SurveyLikertPlugin;
|
|
249
253
|
|
|
250
254
|
})(jsPsychModule);
|
|
251
|
-
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-likert@
|
|
255
|
+
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-likert@2.0.0/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\nconst info = <const>{\n name: \"survey-likert\",\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 pretty_name: \"Questions\",\n nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n pretty_name: \"Prompt\",\n default: undefined,\n },\n /** Array of likert labels to display for this question. */\n labels: {\n type: ParameterType.STRING,\n array: true,\n pretty_name: \"Labels\",\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 pretty_name: \"Required\",\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 pretty_name: \"Question Name\",\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 pretty_name: \"Randomize Question Order\",\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 pretty_name: \"Preamble\",\n default: null,\n },\n /** Width of the likert scales in pixels. */\n scale_width: {\n type: ParameterType.INT,\n pretty_name: \"Scale width\",\n default: null,\n },\n /** Label of the button to submit responses. */\n button_label: {\n type: ParameterType.STRING,\n pretty_name: \"Button label\",\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 pretty_name: \"Allow autocomplete\",\n default: false,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * **survey-likert**\n *\n * jsPsych plugin for gathering responses to questions on a likert scale\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/plugins/jspsych-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 display_element.innerHTML = \"\";\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":";;;EAEA,MAAM,IAAI,GAAU;EAClB,IAAA,IAAI,EAAE,eAAe;EACrB,IAAA,UAAU,EAAE;;EAEV,QAAA,SAAS,EAAE;cACT,IAAI,EAAEA,qBAAa,CAAC,OAAO;EAC3B,YAAA,KAAK,EAAE,IAAI;EACX,YAAA,WAAW,EAAE,WAAW;EACxB,YAAA,MAAM,EAAE;;EAEN,gBAAA,MAAM,EAAE;sBACN,IAAI,EAAEA,qBAAa,CAAC,WAAW;EAC/B,oBAAA,WAAW,EAAE,QAAQ;EACrB,oBAAA,OAAO,EAAE,SAAS;EACnB,iBAAA;;EAED,gBAAA,MAAM,EAAE;sBACN,IAAI,EAAEA,qBAAa,CAAC,MAAM;EAC1B,oBAAA,KAAK,EAAE,IAAI;EACX,oBAAA,WAAW,EAAE,QAAQ;EACrB,oBAAA,OAAO,EAAE,SAAS;EACnB,iBAAA;;EAED,gBAAA,QAAQ,EAAE;sBACR,IAAI,EAAEA,qBAAa,CAAC,IAAI;EACxB,oBAAA,WAAW,EAAE,UAAU;EACvB,oBAAA,OAAO,EAAE,KAAK;EACf,iBAAA;;EAED,gBAAA,IAAI,EAAE;sBACJ,IAAI,EAAEA,qBAAa,CAAC,MAAM;EAC1B,oBAAA,WAAW,EAAE,eAAe;EAC5B,oBAAA,OAAO,EAAE,EAAE;EACZ,iBAAA;EACF,aAAA;EACF,SAAA;;EAED,QAAA,wBAAwB,EAAE;cACxB,IAAI,EAAEA,qBAAa,CAAC,IAAI;EACxB,YAAA,WAAW,EAAE,0BAA0B;EACvC,YAAA,OAAO,EAAE,KAAK;EACf,SAAA;;EAED,QAAA,QAAQ,EAAE;cACR,IAAI,EAAEA,qBAAa,CAAC,WAAW;EAC/B,YAAA,W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AAA,IAAA,GAAG,IAAI;;;;;;;;"}
|
|
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,gBAAA;EAAA,EACA,UAAY,EAAA;EAAA,IAEV,SAAW,EAAA;EAAA,MACT,MAAMC,qBAAc,CAAA,OAAA;EAAA,MACpB,KAAO,EAAA,IAAA;EAAA,MACP,MAAQ,EAAA;EAAA,QAEN,MAAQ,EAAA;EAAA,UACN,MAAMA,qBAAc,CAAA,WAAA;EAAA,UACpB,OAAS,EAAA,KAAA,CAAA;EAAA,SACX;EAAA,QAEA,MAAQ,EAAA;EAAA,UACN,MAAMA,qBAAc,CAAA,MAAA;EAAA,UACpB,KAAO,EAAA,IAAA;EAAA,UACP,OAAS,EAAA,KAAA,CAAA;EAAA,SACX;EAAA,QAEA,QAAU,EAAA;EAAA,UACR,MAAMA,qBAAc,CAAA,IAAA;EAAA,UACpB,OAAS,EAAA,KAAA;EAAA,SACX;EAAA,QAEA,IAAM,EAAA;EAAA,UACJ,MAAMA,qBAAc,CAAA,MAAA;EAAA,UACpB,OAAS,EAAA,EAAA;EAAA,SACX;EAAA,OACF;EAAA,KACF;EAAA,IAEA,wBAA0B,EAAA;EAAA,MACxB,MAAMA,qBAAc,CAAA,IAAA;EAAA,MACpB,OAAS,EAAA,KAAA;EAAA,KACX;EAAA,IAEA,QAAU,EAAA;EA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AAA,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@
|
|
1
|
+
var jsPsychSurveyLikert=function(s){"use strict";var P={name:"@jspsych/plugin-survey-likert",version:"2.0.0",description:"a jspsych plugin for measuring items on a likert scale",type:"module",main:"dist/index.cjs",exports:{import:"./dist/index.js",require:"./dist/index.cjs"},typings:"dist/index.d.ts",unpkg:"dist/index.browser.min.js",files:["src","dist"],source:"src/index.ts",scripts:{test:"jest","test:watch":"npm test -- --watch",tsc:"tsc",build:"rollup --config","build:watch":"npm run build -- --watch"},repository:{type:"git",url:"git+https://github.com/jspsych/jsPsych.git",directory:"packages/plugin-survey-likert"},author:"Josh de Leeuw",license:"MIT",bugs:{url:"https://github.com/jspsych/jsPsych/issues"},homepage:"https://www.jspsych.org/latest/plugins/survey-likert",peerDependencies:{jspsych:">=7.1.0"},devDependencies:{"@jspsych/config":"^3.0.0","@jspsych/test-utils":"^1.2.0"}};const k={name:"survey-likert",version:P.version,parameters:{questions:{type:s.ParameterType.COMPLEX,array:!0,nested:{prompt:{type:s.ParameterType.HTML_STRING,default:void 0},labels:{type:s.ParameterType.STRING,array:!0,default:void 0},required:{type:s.ParameterType.BOOL,default:!1},name:{type:s.ParameterType.STRING,default:""}}},randomize_question_order:{type:s.ParameterType.BOOL,default:!1},preamble:{type:s.ParameterType.HTML_STRING,default:null},scale_width:{type:s.ParameterType.INT,default:null},button_label:{type:s.ParameterType.STRING,default:"Continue"},autocomplete:{type:s.ParameterType.BOOL,default:!1}},data:{response:{type:s.ParameterType.COMPLEX,nested:{identifier:{type:s.ParameterType.STRING},response:{type:s.ParameterType.STRING|s.ParameterType.INT|s.ParameterType.FLOAT|s.ParameterType.BOOL|s.ParameterType.OBJECT}}},rt:{type:s.ParameterType.INT},question_order:{type:s.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 i=r.questions[l[a]];t+='<label class="jspsych-survey-likert-statement">'+i.prompt+"</label>";for(var c=100/i.labels.length,o='<ul class="jspsych-survey-likert-opts" data-name="'+i.name+'" data-radio-group="Q'+l[a]+'">',u=0;u<i.labels.length;u++)o+='<li style="width:'+c+'%"><label class="jspsych-survey-likert-opt-label"><input type="radio" name="Q'+l[a]+'" value="'+u+'"',i.required&&(o+=" required"),o+=">"+i.labels[u]+"</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",j=>{j.preventDefault();for(var _=performance.now(),q=Math.round(_-T),m={},y=e.querySelectorAll("#jspsych-survey-likert-form .jspsych-survey-likert-opts"),p=0;p<y.length;p++){var h=y[p].dataset.radioGroup,v=e.querySelector('input[name="'+h+'"]:checked');if(v===null)var f="";else var f=parseInt(v.value);var g={};if(y[p].attributes["data-name"].value!=="")var b=y[p].attributes["data-name"].value;else var b=h;g[b]=f,Object.assign(m,g)}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 i of e.questions){const c=i.name?i.name:`Q${e.questions.indexOf(i)}`;n[c]=this.jsPsych.randomization.randomInt(0,i.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 i=0;i<a.length;i++)this.jsPsych.pluginAPI.clickTarget(l.querySelector(`input[type="radio"][name="${a[i][0]}"][value="${a[i][1]}"]`),(t.rt-1e3)/a.length*(i+1));this.jsPsych.pluginAPI.clickTarget(l.querySelector("#jspsych-survey-likert-next"),t.rt)}}return d.info=k,d}(jsPsychModule);
|
|
2
|
+
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-likert@2.0.0/dist/index.browser.min.js.map
|