mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-12 08:38:11 +00:00
add survey-likert demos
This commit is contained in:
parent
c8ba33d9ad
commit
629963f4d3
67
docs/plugins/demos/jspsych-survey-likert-demo1.html
Normal file
67
docs/plugins/demos/jspsych-survey-likert-demo1.html
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/jspsych.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/plugins/jspsych-html-button-response.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/plugins/jspsych-survey-likert.js"></script>
|
||||||
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/css/jspsych.css"
|
||||||
|
/>
|
||||||
|
<style>
|
||||||
|
.jspsych-btn {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body></body>
|
||||||
|
<script>
|
||||||
|
var start = {
|
||||||
|
type: 'html-button-response',
|
||||||
|
stimulus: '',
|
||||||
|
choices: ['Run demo']
|
||||||
|
};
|
||||||
|
|
||||||
|
var show_data = {
|
||||||
|
type: 'html-button-response',
|
||||||
|
stimulus: function() {
|
||||||
|
var trial_data = jsPsych.data.getLastTrialData().values();
|
||||||
|
var trial_json = JSON.stringify(trial_data, null, 2);
|
||||||
|
return `<p style="margin-bottom:0px;"><strong>Trial data:</strong></p>
|
||||||
|
<pre style="margin-top:0px;text-align:left;">${trial_json}</pre>`;
|
||||||
|
},
|
||||||
|
choices: ['Repeat demo']
|
||||||
|
};
|
||||||
|
|
||||||
|
var trial = {
|
||||||
|
type: 'survey-likert',
|
||||||
|
questions: [
|
||||||
|
{
|
||||||
|
prompt: "I like vegetables.",
|
||||||
|
labels: [
|
||||||
|
"Strongly Disagree",
|
||||||
|
"Disagree",
|
||||||
|
"Neutral",
|
||||||
|
"Agree",
|
||||||
|
"Strongly Agree"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
var trial_loop = {
|
||||||
|
timeline: [trial, show_data],
|
||||||
|
loop_function: function() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof jsPsych !== "undefined") {
|
||||||
|
jsPsych.init({
|
||||||
|
timeline: [start, trial_loop]
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
document.body.innerHTML = '<div style="text-align:center; margin-top:50%; transform:translate(0,-50%);">You must be online to view the plugin demo.</div>';
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</html>
|
69
docs/plugins/demos/jspsych-survey-likert-demo2.html
Normal file
69
docs/plugins/demos/jspsych-survey-likert-demo2.html
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/jspsych.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/plugins/jspsych-html-button-response.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/plugins/jspsych-survey-likert.js"></script>
|
||||||
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/css/jspsych.css"
|
||||||
|
/>
|
||||||
|
<style>
|
||||||
|
.jspsych-btn {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body></body>
|
||||||
|
<script>
|
||||||
|
var start = {
|
||||||
|
type: 'html-button-response',
|
||||||
|
stimulus: '',
|
||||||
|
choices: ['Run demo']
|
||||||
|
};
|
||||||
|
|
||||||
|
var show_data = {
|
||||||
|
type: 'html-button-response',
|
||||||
|
stimulus: function() {
|
||||||
|
var trial_data = jsPsych.data.getLastTrialData().values();
|
||||||
|
var trial_json = JSON.stringify(trial_data, null, 2);
|
||||||
|
return `<p style="margin-bottom:0px;"><strong>Trial data:</strong></p>
|
||||||
|
<pre style="margin-top:0px;text-align:left;">${trial_json}</pre>`;
|
||||||
|
},
|
||||||
|
choices: ['Repeat demo']
|
||||||
|
};
|
||||||
|
|
||||||
|
var likert_scale = [
|
||||||
|
"Strongly Disagree",
|
||||||
|
"Disagree",
|
||||||
|
"Neutral",
|
||||||
|
"Agree",
|
||||||
|
"Strongly Agree"
|
||||||
|
];
|
||||||
|
|
||||||
|
var trial = {
|
||||||
|
type: 'survey-likert',
|
||||||
|
questions: [
|
||||||
|
{prompt: "I like vegetables.", name: 'Vegetables', labels: likert_scale},
|
||||||
|
{prompt: "I like fruit.", name: 'Fruit', labels: likert_scale},
|
||||||
|
{prompt: "I like meat.", name: 'Meat', labels: likert_scale},
|
||||||
|
],
|
||||||
|
randomize_question_order: true
|
||||||
|
};
|
||||||
|
|
||||||
|
var trial_loop = {
|
||||||
|
timeline: [trial, show_data],
|
||||||
|
loop_function: function() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof jsPsych !== "undefined") {
|
||||||
|
jsPsych.init({
|
||||||
|
timeline: [start, trial_loop]
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
document.body.innerHTML = '<div style="text-align:center; margin-top:50%; transform:translate(0,-50%);">You must be online to view the plugin demo.</div>';
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</html>
|
@ -27,44 +27,60 @@ question_order | array | An array with the order of questions. For example `[2,0
|
|||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
#### Basic example
|
???+ example "Single Question"
|
||||||
|
=== "Code"
|
||||||
|
```javascript
|
||||||
|
var trial = {
|
||||||
|
type: 'survey-likert',
|
||||||
|
questions: [
|
||||||
|
{
|
||||||
|
prompt: "I like vegetables.",
|
||||||
|
labels: [
|
||||||
|
"Strongly Disagree",
|
||||||
|
"Disagree",
|
||||||
|
"Neutral",
|
||||||
|
"Agree",
|
||||||
|
"Strongly Agree"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
```javascript
|
=== "Demo"
|
||||||
var scale_1 = [
|
<div style="text-align:center;">
|
||||||
"Strongly Disagree",
|
<iframe src="../demos/jspsych-survey-likert-demo1.html" width="90%;" height="500px;" frameBorder="0"></iframe>
|
||||||
"Disagree",
|
</div>
|
||||||
"Neutral",
|
|
||||||
"Agree",
|
|
||||||
"Strongly Agree"
|
|
||||||
];
|
|
||||||
|
|
||||||
var likert_page = {
|
<a target="_blank" rel="noopener noreferrer" href="../demos/jspsych-survey-likert-demo1.html">Open demo in new tab</a>
|
||||||
type: 'survey-likert',
|
|
||||||
questions: [
|
|
||||||
{prompt: "I like vegetables.", labels: scale_1}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Multiple questions in a random order
|
???+ example "Multiple questions in a random order"
|
||||||
|
=== "Code"
|
||||||
|
```javascript
|
||||||
|
var likert_scale = [
|
||||||
|
"Strongly Disagree",
|
||||||
|
"Disagree",
|
||||||
|
"Neutral",
|
||||||
|
"Agree",
|
||||||
|
"Strongly Agree"
|
||||||
|
];
|
||||||
|
|
||||||
```javascript
|
var trial = {
|
||||||
var scale_1 = [
|
type: 'survey-likert',
|
||||||
"Strongly Disagree",
|
questions: [
|
||||||
"Disagree",
|
{prompt: "I like vegetables.", name: 'Vegetables', labels: likert_scale},
|
||||||
"Neutral",
|
{prompt: "I like fruit.", name: 'Fruit', labels: likert_scale},
|
||||||
"Agree",
|
{prompt: "I like meat.", name: 'Meat', labels: likert_scale},
|
||||||
"Strongly Agree"
|
],
|
||||||
];
|
randomize_question_order: true
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
var likert_page = {
|
=== "Demo"
|
||||||
type: 'survey-likert',
|
<div style="text-align:center;">
|
||||||
questions: [
|
<iframe src="../demos/jspsych-survey-likert-demo2.html" width="90%;" height="500px;" frameBorder="0"></iframe>
|
||||||
{prompt: "I like vegetables.", name: 'Vegetables', labels: scale_1},
|
</div>
|
||||||
{prompt: "I like fruit.", name: 'Fruit', labels: scale_1},
|
|
||||||
{prompt: "I like meat.", name: 'Meat', labels: scale_1},
|
<a target="_blank" rel="noopener noreferrer" href="../demos/jspsych-survey-likert-demo2.html">Open demo in new tab</a>
|
||||||
{prompt: "I like dairy.", name: 'Dairy', labels: scale_1}
|
|
||||||
],
|
|
||||||
randomize_question_order: true
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
Loading…
Reference in New Issue
Block a user