mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
1.5 KiB
1.5 KiB
Extensions
Extensions are jsPsych modules that can interface with any plugin to extend the functionality of the plugin. A canonical example of an extension is eye tracking. An eye tracking extension allows a plugin to gather gaze data and add it to the plugin's data object.
Using an Extension
To use an extension in an experiment, you'll load the extension file via a <script>
tag (just like adding a plugin) and then initialize the extension in the parameters of jsPsych.init()
.
<head>
<script src="jspsych/jspsych.js"></script>
<script src="jspsych/extensions/some-extension.js"></script>
</head>
jsPsych.init({
timeline: [...],
extensions: ['some-extension']
})
To enable an extension during a trial, add the extension name to the extensions
parameter list for the trial:
var trial = {
extensions: ['some-extension']
}
List of Extensions
Extension | Description |
---|---|
jspsych‑ext‑webgazer.js | Enables eye tracking using the WebGazer library. |
Writing an Extension
To create a new extension you must create an object that supports a few event callbacks. A barebones extension file might look like this:
jsPsych.extensions['new-extension'] = (function () {
var extension = {};
extension.initialize = function(params){
}
extension.on_start = function(){
}
extension.on_load = function(){
}
extension.on_finish = function(){
}
});