Merge pull request #2015 from kurokida/docs-demos

Create live demos for the categorize-html, categorize-image, and cloze plugins.
This commit is contained in:
Becky Gilbert 2021-07-28 12:08:49 -07:00 committed by GitHub
commit 6bd552d3cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 309 additions and 44 deletions

View File

@ -0,0 +1,61 @@
<!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-preload.js"></script>
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/plugins/jspsych-categorize-html.js"></script>
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/plugins/jspsych-html-button-response.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 categorization_trial = {
type: 'categorize-html',
stimulus: '<p>B</p>',
key_answer: 'p',
text_answer: 'letter',
choices: ['p', 'q'],
correct_text: "<p class='prompt'>Correct, this is a %ANS%.</p>",
incorrect_text: "<p class='prompt'>Incorrect, this is a %ANS%.</p>",
prompt: "<p>Press p for letter. Press q for number.</p>"
};
var trial_loop = {
timeline: [categorization_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>

View 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-preload.js"></script>
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/plugins/jspsych-categorize-image.js"></script>
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/plugins/jspsych-html-button-response.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 preload_trial = {
type: 'preload',
auto_preload: true
}
var categorization_trial = {
type: 'categorize-image',
stimulus: 'https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/examples/img/blue.png',
key_answer: 'b',
text_answer: 'Blue',
choices: ['r', 'g', 'b'],
correct_text: "<p class='prompt'>Correct! The color is %ANS%.</p>",
incorrect_text: "<p class='prompt'>Incorrect. The color is %ANS%.</p>",
prompt: "<p>Is the color of this circle (R)ed, (G)reen, or (B)lue?</p>"
};
var trial_loop = {
timeline: [categorization_trial, show_data],
loop_function: function() {
return true;
}
};
if (typeof jsPsych !== "undefined") {
jsPsych.init({
timeline: [preload_trial, 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>

View File

@ -0,0 +1,55 @@
<!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-preload.js"></script>
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/plugins/jspsych-cloze.js"></script>
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/plugins/jspsych-html-button-response.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 cloze_trial = {
type: 'cloze',
text: 'The %% is the largest terrestrial mammal. It lives in both %% and %%.'
};
var trial_loop = {
timeline: [cloze_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>

View File

@ -0,0 +1,58 @@
<!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-preload.js"></script>
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/plugins/jspsych-cloze.js"></script>
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/plugins/jspsych-html-button-response.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 cloze_trial = {
type: 'cloze',
text: 'A rectangle has % 4 % corners and a triangle has % 3 %.',
check_answers: true,
button_text: 'Next',
mistake_fn: function(){alert("Wrong answer. Please check again.")}
};
var trial_loop = {
timeline: [cloze_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>

View File

@ -36,18 +36,23 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
## Examples
#### Categorizing HTML content
```javascript
var categorization_trial = {
type: 'categorize',
stimulus: '<p>B</p>',
key_answer: 'p',
text_answer: 'letter',
choices: ['p', 'q'],
correct_text: "<p class='prompt'>Correct, this is a %ANS%.</p>",
incorrect_text: "<p class='prompt'>Incorrect, this is a %ANS%.</p>",
prompt: "<p>Press p for letter. Press q for number.</p>"
};
```
???+ example "Categorizing HTML content"
=== "Code"
```javascript
var categorization_trial = {
type: 'categorize-html',
stimulus: '<p>B</p>',
key_answer: 'p',
text_answer: 'letter',
choices: ['p', 'q'],
correct_text: "<p class='prompt'>Correct, this is a %ANS%.</p>",
incorrect_text: "<p class='prompt'>Incorrect, this is a %ANS%.</p>",
prompt: "<p>Press p for letter. Press q for number.</p>"
};
```
=== "Demo"
<div style="text-align:center;">
<iframe src="../plugins/demos/jspsych-categorize-html-demo1.html" width="90%;" height="600px;" frameBorder="0"></iframe>
</div>
<a target="_blank" rel="noopener noreferrer" href="../plugins/demos/jspsych-categorize-html-demo1.html">Open demo in new tab</a>

View File

@ -37,17 +37,23 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
## Examples
#### Categorizing an image
???+ example "Categorizing an image"
=== "Code"
```javascript
var categorization_trial = {
type: 'categorize-image',
stimulus: 'https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/examples/img/blue.png',
key_answer: 'b',
text_answer: 'Blue',
choices: ['r', 'g', 'b'],
correct_text: "<p class='prompt'>Correct! The color is %ANS%.</p>",
incorrect_text: "<p class='prompt'>Incorrect. The color is %ANS%.</p>",
prompt: "<p>Is the color of this circle (R)ed, (G)reen, or (B)lue?</p>"
};
```
=== "Demo"
<div style="text-align:center;">
<iframe src="../plugins/demos/jspsych-categorize-image-demo1.html" width="90%;" height="600px;" frameBorder="0"></iframe>
</div>
```javascript
var categorization_trial = {
type: 'categorize-image',
stimulus: 'img/harrypotter.png',
key_answer: 'g',
text_answer: 'Gryffindor',
choices: ['g', 'h', 'r', 's'],
correct_text: "<p class='prompt'>Correct! This person is a %ANS%.</p>",
incorrect_text: "<p class='prompt'>Incorrect. This person is a %ANS%.</p>",
prompt: "<p>Is this person a (G)ryffindor, (H)ufflepuff, (R)avenclaw, or (S)lytherin?</p>"
};
```
<a target="_blank" rel="noopener noreferrer" href="../plugins/demos/jspsych-categorize-image-demo1.html">Open demo in new tab</a>

View File

@ -23,23 +23,36 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
## Examples
#### Simple cloze using default settings (no check against correct solution, no custom button text)
???+ example "Simple cloze using default settings (no check against correct solution, no custom button text)"
=== "Code"
```javascript
var cloze_trial = {
type: 'cloze',
text: 'The %% is the largest terrestrial mammal. It lives in both %% and %%.'
};
```
=== "Demo"
<div style="text-align:center;">
<iframe src="../plugins/demos/jspsych-cloze-demo1.html" width="90%;" height="500px;" frameBorder="0"></iframe>
</div>
```javascript
var trial = {
type: 'cloze',
text: 'The %% is the largest terrestrial mammal. It lives in both %% and %%.'
};
```
<a target="_blank" rel="noopener noreferrer" href="../plugins/demos/jspsych-cloze-demo1.html">Open demo in new tab</a>
#### More elaborate example (with check against correct solution, custom error handling and modified button text)
```javascript
var trial = {
type: 'cloze',
text: 'A rectangle has % 4 % corners and a triangle has % 3 %.',
check_answers: true,
button_text: 'Next',
mistake_fn: function(){alert("Wrong answer. Please check again.")}
};
```
???+ example "More elaborate example (with check against correct solution, custom error handling and modified button text)"
=== "Code"
```javascript
var cloze_trial = {
type: 'cloze',
text: 'A rectangle has % 4 % corners and a triangle has % 3 %.',
check_answers: true,
button_text: 'Next',
mistake_fn: function(){alert("Wrong answer. Please check again.")}
};
```
=== "Demo"
<div style="text-align:center;">
<iframe src="../plugins/demos/jspsych-cloze-demo2.html" width="90%;" height="500px;" frameBorder="0"></iframe>
</div>
<a target="_blank" rel="noopener noreferrer" href="../plugins/demos/jspsych-cloze-demo2.html">Open demo in new tab</a>