mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-11 16:18:11 +00:00
started work on freepick touch plugin
do not use. still in development.
This commit is contained in:
parent
ca38b559f1
commit
4c7463273b
87
jspsych-touch-freepick.js
Normal file
87
jspsych-touch-freepick.js
Normal file
@ -0,0 +1,87 @@
|
||||
(function( $ ) {
|
||||
jsPsych.touch_freepick = (function(){
|
||||
|
||||
var plugin = {};
|
||||
|
||||
plugin.create = function(params) {
|
||||
stims = params["stimuli"];
|
||||
trials = new Array(stims.length);
|
||||
for(var i = 0; i < trials.length; i++)
|
||||
{
|
||||
trials[i] = {};
|
||||
trials[i]["type"] = "touch_freepick";
|
||||
trials[i]["stims"] = stims[i];
|
||||
trials[i]["answers"] = params["answers"][i];
|
||||
trials[i]["timing"] = params["timing"];
|
||||
if(params["data"]!=undefined){
|
||||
trials[i]["data"] = params["data"][i];
|
||||
}
|
||||
}
|
||||
return trials;
|
||||
}
|
||||
|
||||
plugin.trial = function($this, block, trial, part)
|
||||
{
|
||||
switch(part){
|
||||
case 1:
|
||||
p1_time = (new Date()).getTime();
|
||||
|
||||
// add images
|
||||
for(var i=0;trial.stims.length;i++){
|
||||
$this.append($('<img>', {
|
||||
"src": trial.stims[i],
|
||||
"class": 'freepick',
|
||||
"id":'fp'+i
|
||||
}));
|
||||
}
|
||||
|
||||
var click_count = 0;
|
||||
var click_locations = [];
|
||||
var click_times = [];
|
||||
|
||||
var touchfunction = function(e) {
|
||||
|
||||
e.originalEvent.preventDefault();
|
||||
|
||||
var rt = (new Date()).getTime() - p1_time;
|
||||
var x = e.originalEvent.touches[0].pageX;
|
||||
var y = e.originalEvent.touches[0].pageY;
|
||||
|
||||
click_count = click_count + 1;
|
||||
|
||||
console.log("click event "+x+" "+y+". click count "+click_count+". click num "+trial.click_num);
|
||||
|
||||
//save location
|
||||
click_locations.push([x,y]);
|
||||
click_times.push(rt);
|
||||
|
||||
//save response time
|
||||
if(click_count == trial.click_num)
|
||||
{
|
||||
var click_loc_data = {"click_locations": click_locations};
|
||||
var click_time_data = {"click_times": click_times};
|
||||
var img = {"img": trial.a_path };
|
||||
// save data
|
||||
block.data[block.trial_idx] = $.extend({}, img, click_loc_data, click_time_data, trial.data);
|
||||
|
||||
plugin.trial($this, block, trial, part + 1);
|
||||
}
|
||||
};
|
||||
|
||||
$('.storybook').click(function(){ void(0); })
|
||||
|
||||
//$('.storybook').mousedown(function(e){ touchfunction(e);});
|
||||
$('.storybook').bind("touchstart", function(e){touchfunction(e);});
|
||||
|
||||
break;
|
||||
case 2:
|
||||
$('.storybook').remove();
|
||||
|
||||
setTimeout(function(){block.next();}, trial.timing[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return plugin;
|
||||
})();
|
||||
})(jQuery);
|
Loading…
Reference in New Issue
Block a user