mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-12 16:48:12 +00:00
Merge pull request #2018 from kurokida/docs-demos
Create live demos for the external-html and free-sort plugins.
This commit is contained in:
commit
11a5378865
12
docs/plugins/demos/external_page.html
Normal file
12
docs/plugins/demos/external_page.html
Normal file
@ -0,0 +1,12 @@
|
||||
<div id="consent">
|
||||
<p>
|
||||
This is a demo experiment, with this minimal consent form being loaded
|
||||
as an external html document. To continue, click the checkbox below
|
||||
and hit "Start Experiment".
|
||||
</p>
|
||||
<p>
|
||||
<input type="checkbox" id="consent_checkbox" />
|
||||
I agree to take part in this study.
|
||||
</p>
|
||||
<button type="button" id="start">Start Experiment</button>
|
||||
</div>
|
71
docs/plugins/demos/jspsych-external-html-demo1.html
Normal file
71
docs/plugins/demos/jspsych-external-html-demo1.html
Normal file
@ -0,0 +1,71 @@
|
||||
<!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-external-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']
|
||||
};
|
||||
|
||||
// sample function that might be used to check if a subject has given
|
||||
// consent to participate.
|
||||
var check_consent = function(elem) {
|
||||
if (document.getElementById('consent_checkbox').checked) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
alert("If you wish to participate, you must check the box next to the statement 'I agree to participate in this study.'");
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// declare the block.
|
||||
var trial = {
|
||||
type:'external-html',
|
||||
url: "external_page.html",
|
||||
cont_btn: "start",
|
||||
check_fn: check_consent
|
||||
};
|
||||
|
||||
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>
|
73
docs/plugins/demos/jspsych-free-sort-demo1.html
Normal file
73
docs/plugins/demos/jspsych-free-sort-demo1.html
Normal file
@ -0,0 +1,73 @@
|
||||
<!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-free-sort.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 sorting_stimuli = [
|
||||
'https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/examples/img/happy_face_1.jpg',
|
||||
'https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/examples/img/happy_face_2.jpg',
|
||||
'https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/examples/img/happy_face_3.jpg',
|
||||
'https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/examples/img/happy_face_4.jpg'
|
||||
]
|
||||
|
||||
var preload_trial = {
|
||||
type: 'preload',
|
||||
images: sorting_stimuli
|
||||
}
|
||||
|
||||
var sort_trial = {
|
||||
type: 'free-sort',
|
||||
stimuli: sorting_stimuli,
|
||||
stim_width: 80,
|
||||
stim_height: 60,
|
||||
sort_area_width: 500,
|
||||
sort_area_height: 500,
|
||||
stim_starts_inside: true,
|
||||
prompt: "<p>Click and drag the images below to sort them so that similar items are close together.</p>"
|
||||
};
|
||||
|
||||
var trial_loop = {
|
||||
timeline: [sort_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>
|
@ -44,7 +44,8 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
</div>
|
||||
```
|
||||
|
||||
##### jsPsych code to load above page.
|
||||
???+ example "jsPsych code to load above page."
|
||||
=== "Code"
|
||||
```javascript
|
||||
// sample function that might be used to check if a subject has given
|
||||
// consent to participate.
|
||||
@ -59,7 +60,6 @@ var check_consent = function(elem) {
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
// declare the block.
|
||||
var trial = {
|
||||
type:'external-html',
|
||||
@ -68,3 +68,9 @@ var trial = {
|
||||
check_fn: check_consent
|
||||
};
|
||||
```
|
||||
=== "Demo"
|
||||
<div style="text-align:center;">
|
||||
<iframe src="../plugins/demos/jspsych-external-html-demo1.html" width="90%;" height="500px;" frameBorder="0"></iframe>
|
||||
</div>
|
||||
|
||||
<a target="_blank" rel="noopener noreferrer" href="../plugins/demos/jspsych-external-html-demo1.html">Open demo in new tab</a>
|
||||
|
@ -40,17 +40,23 @@ rt | numeric | The response time in milliseconds for the participant to finish a
|
||||
|
||||
## Examples
|
||||
|
||||
#### Basic example
|
||||
|
||||
???+ example "Basic example"
|
||||
=== "Code"
|
||||
```javascript
|
||||
var sorting_stimuli = [];
|
||||
for (var i = 1; i <= 12; i++) {
|
||||
sorting_stimuli.push("img/cell_img_" + i + ".jpg");
|
||||
}
|
||||
|
||||
var sort_trial = {
|
||||
type: 'free-sort',
|
||||
stimuli: sorting_stimuli,
|
||||
stim_width: 80,
|
||||
stim_height: 60,
|
||||
sort_area_width: 500,
|
||||
sort_area_height: 500,
|
||||
prompt: "<p>Click and drag the images below to sort them so that similar items are close together.</p>"
|
||||
};
|
||||
```
|
||||
=== "Demo"
|
||||
<div style="text-align:center;">
|
||||
<iframe src="../plugins/demos/jspsych-free-sort-demo1.html" width="90%;" height="700px;" frameBorder="0"></iframe>
|
||||
</div>
|
||||
|
||||
<a target="_blank" rel="noopener noreferrer" href="../plugins/demos/jspsych-free-sort-demo1.html">Open demo in new tab</a>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user