mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
more plugin refactoring #422
This commit is contained in:
parent
045560d2f5
commit
7f62f0b52b
48
examples/jspsych-image-slider-response.html
Normal file
48
examples/jspsych-image-slider-response.html
Normal file
@ -0,0 +1,48 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script src="../jspsych.js"></script>
|
||||
<script src="../plugins/jspsych-image-slider-response.js"></script>
|
||||
<link rel="stylesheet" href="../css/jspsych.css"></link>
|
||||
<style>
|
||||
img {
|
||||
width: 300px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body></body>
|
||||
<script>
|
||||
|
||||
var trial_1 = {
|
||||
type: 'image-slider-response',
|
||||
stimulus: 'img/happy_face_1.jpg',
|
||||
labels: ['1 (least happy)', '100 (most happy)'],
|
||||
prompt: '<p>How happy is this person on a scale of 1-100?</p>'
|
||||
}
|
||||
|
||||
var trial_2 = {
|
||||
type: 'image-slider-response',
|
||||
stimulus: 'img/happy_face_2.jpg',
|
||||
labels: ['1 (least happy)', '100 (most happy)'],
|
||||
prompt: '<p>How happy is this person on a scale of 1-100? (5s time limit)</p>',
|
||||
trial_duration: 5000
|
||||
}
|
||||
|
||||
var trial_3 = {
|
||||
type: 'image-slider-response',
|
||||
stimulus: 'img/happy_face_2.jpg',
|
||||
labels: ['1 (least happy)', '100 (most happy)'],
|
||||
prompt: '<p>How happy is this person on a scale of 1-100? (1s stimulus duration)</p>',
|
||||
stimulus_duration: 1000
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial_1, trial_2, trial_3],
|
||||
on_finish: function() {
|
||||
jsPsych.data.displayData();
|
||||
},
|
||||
default_iti: 250
|
||||
});
|
||||
</script>
|
||||
|
||||
</html>
|
@ -56,8 +56,8 @@ jsPsych.plugins['image-slider-response'] = (function() {
|
||||
// it with the output of the function
|
||||
trial = jsPsych.pluginAPI.evaluateFunctionParameters(trial);
|
||||
|
||||
var html = '<div id="jspsych-image-slider-response" class="jspsych-image-slider-response-question" style="margin: 100px 0px;">';
|
||||
html += '<div class="jspsych-image-slider-response-stimulus"><img src="' + trial.stimulus + '"></div>';
|
||||
var html = '<div id="jspsych-image-slider-response-wrapper" style="margin: 100px 0px;">';
|
||||
html += '<div id="jspsych-image-slider-response-stimulus"><img src="' + trial.stimulus + '"></div>';
|
||||
html += '<div class="jspsych-image-slider-response-container" style="position:relative;">';
|
||||
html += '<input type="range" min="'+trial.min+'" max="'+trial.max+'" step="'+trial.step+'" style="width: 100%;" id="jspsych-image-slider-response-response"></input>';
|
||||
html += '<div>'
|
||||
@ -90,7 +90,7 @@ jsPsych.plugins['image-slider-response'] = (function() {
|
||||
response.rt = endTime - startTime;
|
||||
response.response = display_element.querySelector('#jspsych-image-slider-response-response').value;
|
||||
|
||||
if(response_ends_trial){
|
||||
if(trial.response_ends_trial){
|
||||
end_trial();
|
||||
} else {
|
||||
display_element.querySelector('#jspsych-image-slider-response-next').disabled = true;
|
||||
@ -99,6 +99,9 @@ jsPsych.plugins['image-slider-response'] = (function() {
|
||||
});
|
||||
|
||||
function end_trial(){
|
||||
|
||||
jsPsych.pluginAPI.clearAllTimeouts();
|
||||
|
||||
// save data
|
||||
var trialdata = {
|
||||
"rt": response.rt,
|
||||
|
Loading…
Reference in New Issue
Block a user