/* This software is licensed under a BSD license; see the LICENSE file for details. */ // - Version beta 0.2 // - Last Update: 2018, June 25 // - Major changes in beta 0.2: // + Replaced x.defaults with defaultX // + Added .settings.log to the html element // + Added .settings.once for the audio element // + Added .record, .stop and .play to the voiceRecorder element // + Added .wait and .settings.once to the voiceRecorder element // + Added .test.is to the function element, testing the return value // + Added .call to the function element (no longer run upon creation) // + Fixed video automatically starting when first to happen on first trial // + Made .wait actions uniform (i.e., they now all can take tests) // + Fixed a bug when passing an element to .before and .after // + Fixed selector.settings.once (and enable and disable) // KNOWN ISSUES // * Chrome requires a secure connection to record audio, which Ibex Farm does not provide yet // * defaultX affects all subsequent trials // * Crash when an element refers to a resource with no host and no zip were provided // - Major changes in beta 0.1: // + New syntax: // each element gets created by newX and retrieved by getX // commands come in 3 types: actions (.command), settings (.settings.command) and tests (.test.command) // 'instructions' are no longer a thing // defaultX can be used to define commands to be automatically executed upon creation of each element X // + Replaced all .record with settings.log // + Elements get printed on the screen only when .print is called (exception when part of canvas) // + Added .settings.left/right/center/color to each element // + Added .settings.before/after to each element // + Created a button element // + Created a textInput element // + Created a scale element (previously radio) // + Created a HTML element // + Created a voiceRecorder element // + Can retrieve table with PennController.GetTable and filter them using .filter // + Added a .logAppend command on PennController() to add values to each line for the trial in the results // - Major changes in alpha 0.4: // + Revised the preloading method // + Replaced all .save with .record // + Added the FeedItems command // - Major changes in alpha 0.3: // + Added the Canvas instruction // + Added the Instruction.id method !function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=134)}([function(e,t,n){"use strict";n.r(t),n.d(t,"Abort",function(){return r}),n.d(t,"Ctrlr",function(){return i}),n.d(t,"changeRunningOrder",function(){return s}),n.d(t,"getChangeRunningOrder",function(){return a}),n.d(t,"PennController",function(){return u});var r=new Object;window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver;var i={building:{},running:{},list:[]},o=[];function s(e){if(!(e instanceof Function))return console.log("ERROR: changeRunningOrder only takes functions as parameters");o.push(e)}function a(e){return o}var u=function(){let e=i.list.length,t=arguments;i.building.id=e,i.building.sequence=t,i.list.push(i.building),i.building={};let n={instructions:t,id:e,_toSave:[],save:function(e,t,r){return n._toSave.push([e,t,r]),n},_appendResultLine:[],logAppend:function(e,t){return void 0===t&&(t=e),n._appendResultLine.push([e,t]),n}};return n};u.Configure=function(e){for(let t in e)t.indexOf.Configure<0&&(u[t]=e[t])};let l={};u.GetURLParameter=function(e){if(!Object.keys(l).length){let e=window.location.search.replace("?","").split("&");for(let t in e)l[e[t].split("=")[0]]=e[t].split("=")[1]}if(l.hasOwnProperty(e))return l[e]},u.AddHost=function(){u.hasOwnProperty("hosts")||(u.hosts=[]);for(let e=0;e1;)try{return c.stringifyByChunk(e,r,n)}catch(e){n=Math.floor(n/2)}return c.stringifyByChar(e)}function f(e,t){for(var n=0;nn==t.options.preload[e])),i.push(n))}else i=[anyType];let o=function(e){let t,n=[],r={};for(let t in e){let i=e[t];if(i[0]instanceof Array){if(i[0].length>1){let e=i[0][1];r.hasOwnProperty(e)||(r[e]=[]),r[e].push(i)}}else n.push(i)}t="undefined"!=typeof counterOverride?counterOverride:__counter_value_from_server__;for(let e=0;e0&&"PennController"==i&&(u=!0)}}let s=$("
").append(h);t.element.append(s);for(let e in n){let r=n[e];r&&l.indexOf(r)>=0&&(t.toPreload||(t.toPreload=[]),t.toPreload.indexOf(r)<0&&(t.toPreload.push(r),r._setResource=r.extend("_setResource",function(){let e=t.toPreload.indexOf(r);e>=0&&t.toPreload.splice(e,1),t.toPreload.length<=0&&jQuery.contains(document,s[0])&&(s.remove(),t.finishedCallback())})))}return(!t.toPreload||t.toPreload.length<=0)&&jQuery.contains(document,s[0])?(s.remove(),t.finishedCallback()):setTimeout(function(){if(!jQuery.contains(document,s[0]))return r;s.remove(),t.finishedCallback()},t.options.timeout),r}i.CheckPreload=function(){u=!1;let e=arguments[Object.keys(arguments).length-1];return("number"!=typeof e||e<=0)&&(e=c),{custom:f,preload:arguments,timeout:e,countsForProgressBar:!1}},i.AutoPreload=function(e){"images"==e?(a=!1,o=!1,s=!0):"audio"==e?(o=!0,s=!1,a=!1):"video"==parameters?(a=!0,o=!1,s=!1):"object"==typeof e?(e.hasOwnProperty("images")&&(s=e.images),e.hasOwnProperty("audio")&&(o=e.audio),e.hasOwnProperty("videos")&&(a=e.videos)):(o=!0,s=!0,a=!0)}}).call(this,n(0).Ctrlr,n(0).Abort,n(0).PennController)},function(e,t,n){"use strict";n.r(t),function(e,r,i){n.d(t,"Instruction",function(){return l});var o=n(2),s=n(7);const a=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver;var u=[{}];class l{constructor(t,n,r){this.type=r,this.content=n,this.hasBeenRun=!1,this.isDone=!1,this.parentElement=null,this.element=null,this.origin=this,this.itvlWhen=null,this.resource=null,this.j={};let i=this;this.settings={},this.test={},this.testNot={};for(var o=this.constructor;o!=Object.getPrototypeOf(Function);){let e=o.prototype;for(let t in e.settings)!i.settings.hasOwnProperty(t)&&e.settings[t]instanceof Function&&(i.settings[t]=function(){return e.settings[t].apply(i,arguments)});for(let t in e.test)!i.test.hasOwnProperty(t)&&e.test[t]instanceof Function&&(i.test[t]=function(){return e.test[t].apply(i,arguments)},i.testNot[t]=function(){let n=e.test[t].apply(i,arguments),r=i.newMeta(function(){n.hasBeenRun=!1,n.isDone=!1,n.run()});return n.success=n.extend("success",function(e){e instanceof l||r.failure()}),n.failure=n.extend("failure",function(e){e instanceof l||r.success()}),r.success=function(e){return e instanceof l?(r._then=e,e.done=e.extend("done",function(){r.done()})):r._then instanceof l?r._then.run():r.done(),r},r.failure=function(e){return e instanceof l?(r._fail=e,e.done=e.extend("done",function(){r.done()})):r._fail instanceof l?r._fail.run():r.done(),r},r});o=Object.getPrototypeOf(o)}for(e.building.hasOwnProperty("instructions")||(e.building.instructions=[]),e.building.instructions.push(this);u.length").append(n)),i instanceof Function&&a){let e=new a(t=>{0!==t[0].addedNodes.length&&-1!==Array.prototype.indexOf.call(t[0].addedNodes,n[0])&&(e.disconnect(),i())});e.observe(t[0],{childList:!0})}if(this.origin._left){let e=$("").addClass("PennController-before");this.origin._left instanceof l?(this.origin._left.origin.parentElement=e,this.origin._left.hasBeenRun||this.origin._left.run(),this.origin._left.origin.print().run()):this.origin._left instanceof jQuery&&e.append(this.origin._left),n.prepend(e)}if(t.append(n),this.origin._right){let e=$("").addClass("PennController-after");this.origin._right instanceof l?(this.origin._right.origin.parentElement=e,this.origin._right.hasBeenRun||this.origin._right.run(),this.origin._right.origin.print().run()):this.origin._right instanceof jQuery&&e.append(this.origin._right),n.append(e)}}setElement(e){this.element=e;let t=this;for(let e in this.origin.element)"function"==typeof t.origin.element[e]?t.j[e]=function(){return t.origin.element[e].apply(t.origin.element,arguments),t.newMeta(function(){this.done()})}:t.j[e]=function(){return t.origin.element[e]}}_addToPreload(){if(this.origin.resource)return r;o.e.indexOf(this.origin)<0&&o.e.push(this.origin),e.building.hasOwnProperty("preloadingInstructions")||(e.building.preloadingInstructions=[]),e.building.preloadingInstructions.indexOf(this.origin)<0&&e.building.preloadingInstructions.push(this.origin)}_setResource(e){if(this.origin.resource)return console.log("Warning: trying to replace resource for "+this.origin.content+"; several host copies of the same file? Ignoring new resource."),r;let t=o.e.indexOf(this.origin);t>=0&&o.e.splice(t,1),this.origin.resource=e}fetchResource(e,t){let n,o,a=this;if(this.origin.resource)return r;if(s.d&&s.a.length>0&&!e.match(/^http/i))return void s.c.push(function(){a.fetchResource(e,t)});let u="load";if(s.b.hasOwnProperty(e))t=s.b[e].type,o=URL.createObjectURL(s.b[e].blob),t.match(/audio/)&&(u="canplay");else if(e.match(/^http/i)){let n=e.match(/\.([^.]+)$/);if(!t&&!n)return console.log("Error: extension of resource "+file+" not recognized"),r;n=n[1],"audio"==t||n.match(/mp3|ogg|wav/i)?(t="audio/"+n.toLowerCase().replace("mp3","mpeg").toLowerCase(),o=e,u="canplaythrough"):"image"==t||n.match(/gif|png|jpe?g/i)?(t="image/"+n.replace(/jpg/i,"jpeg").toLowerCase(),o=e):"video"==t||n.match(/mp4|ogg|webm/i)}else if(i.hosts.length)for(let n in i.hosts)"string"==typeof i.hosts[n]&&i.hosts[n].match(/^http/i)&&a.fetchResource(i.hosts[n]+e,t);t.match(/audio/)?(n=$("