mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 19:20:55 +00:00
71 lines
2.0 KiB
HTML
71 lines
2.0 KiB
HTML
<!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-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 jsPsych = initJsPsych();
|
|
|
|
var start = {
|
|
type: jsPsychHtmlButtonResponse,
|
|
stimulus: '',
|
|
choices: ['Run demo']
|
|
};
|
|
|
|
var show_data = {
|
|
type: jsPsychHtmlButtonResponse,
|
|
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: jsPsychExternalHtml,
|
|
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.run([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>
|