JAVASCRIPT   33
faultless disagreement js
Guest on 6th February 2023 01:47:51 PM


  1.  
  2.  
  3.  
  4.  
  5. function make_slides(f) {
  6.   var   slides = {};
  7.  
  8.   slides.i0 = slide({
  9.      name : "i0",
  10.      start: function() {
  11.       exp.startT = Date.now();
  12.      }
  13.   });
  14.  
  15.   slides.instructions1 = slide({
  16.     name : "instructions1",
  17.     start: function() {
  18.       $(".instruction_condition").html("Between subject intruction manipulation: "+ exp.instruction);
  19.     },
  20.     button : function() {
  21.       exp.go(); //use exp.go() if and only if there is no "present" data.
  22.     }
  23.   });
  24.  
  25.   slides.multi_slider = slide({
  26.     name : "multi_slider",
  27.     present : stimuli,
  28.     present_handle : function(stim) {
  29.       $(".err").hide();
  30.       this.init_sliders();      
  31.       exp.sliderPost = null;
  32.       // $('input[name="sense"]:checked').attr('checked',false);
  33.       this.stim = stim; //FRED: allows you to access stim in helpers
  34.       //var noun_data = _.sample(corpus.Noun)
  35.       //this.noun_data = noun_data;
  36.       //var noun = noun_data.noun;
  37.       //var animacy = noun_data.animacy;
  38.  
  39. //      this.verbs = _.shuffle(["is","is not"])
  40.  
  41. //      var names_list = _.shuffle(names);
  42.  
  43. //      var man1 = names_list[0];
  44. //      var man2 = names_list[1];
  45.  
  46. //      $(".man1").html(man1);
  47.  
  48. //      $(".man2").html(man2);
  49.  
  50.       $(".predicate").html(stim.Predicate);
  51.  
  52.       //$(".woman1").html(woman1);
  53.  
  54.       //$(".woman2").html(man2);
  55.  
  56. //      $(".utterance1").html("\"That "+ stim.Noun + " " + this.verbs[0] + " " + stim.Predicate + ".\"");
  57.  
  58. //      $(".utterance2").html("\"You're wrong. That "+ stim.Noun + " " + this.verbs[1] + " "  + stim.Predicate + ".\"");
  59.  
  60. //      this.sentence_types = _.shuffle(["yes","no"]);
  61. //      this.sentence_types = ["no","yes"];
  62. //      var sentences = {
  63. //        "yes": "Yes, it's a matter of opinion.",
  64. //        "no": "No, somebody must be wrong.",
  65. //      };
  66.  
  67. //      this.n_sliders = this.sentence_types.length;
  68.                 this.n_sliders = 1;
  69. //      $(".slider_row").remove();
  70. //      for (var i=0; i<this.n_sliders; i++) {
  71. //        var sentence_type_left = this.sentence_types[0];
  72. //        var sentence_type_left = this.sentence_types[1];        
  73. //        var sentence_left = sentences[sentence_type_left];
  74. //        var sentence_right = sentences[sentence_type_right];        
  75. //        $("#multi_slider_table").append('<tr class="slider_row"><td class="slider_target" id="sentence0">' + "<font size='4'>" + sentence_left + "</font>" + '</td><td colspan="2"><div id="slider0" class="slider">-------[ ]--------</div></td><td class="slider_target" id="sentence1">' + "<font size='4'>" + sentence_right + "</font>" + '</td></tr>');
  76. //        utils.match_row_height("#multi_slider_table", ".slider_target");
  77. //      }
  78.  
  79.     },
  80.  
  81.     button : function() {
  82.         console.log(exp.sliderPost);
  83.       if (exp.sliderPost != null) {
  84.         this.log_responses();
  85.         _stream.apply(this); //use exp.go() if and only if there is no "present" data.
  86.       } else {
  87.         $(".err").show();
  88.       }
  89.     },
  90.  
  91.     init_sliders : function() {
  92.       utils.make_slider("#slider0", function(event, ui) {
  93.         exp.sliderPost = ui.value;
  94.       });
  95.     },
  96. //    make_slider_callback : function(i) {
  97. //      return function(event, ui) {
  98. //        exp.sliderPost[i] = ui.value;
  99. //      };
  100. //    },
  101.     log_responses : function() {
  102.         exp.data_trials.push({
  103.           "response" : exp.sliderPost,
  104.           "predicate" : this.stim.Predicate,
  105. //          "predicate" : this.stim.Predicate,
  106.               "predicateclass" : this.stim.PredicateClass,
  107. //          "class" : this.stim.Class,
  108. //          "firstutterance" : this.verbs[0],
  109.           // "sense" : $('input[name="sense"]:checked').val(),        
  110.           "slide_number" : exp.phase
  111.         });
  112.     },
  113.   });
  114.  
  115.   slides.subj_info =  slide({
  116.     name : "subj_info",
  117.     submit : function(e){
  118.       //if (e.preventDefault) e.preventDefault(); // I don't know what this means.
  119.       exp.subj_data = {
  120.         language : $("#language").val(),
  121.         enjoyment : $("#enjoyment").val(),
  122.         asses : $('input[name="assess"]:checked').val(),
  123.         age : $("#age").val(),
  124.         gender : $("#gender").val(),
  125.         education : $("#education").val(),
  126.         comments : $("#comments").val(),
  127.       };
  128.       exp.go(); //use exp.go() if and only if there is no "present" data.
  129.     }
  130.   });
  131.  
  132.   slides.thanks = slide({
  133.     name : "thanks",
  134.     start : function() {
  135.       exp.data= {
  136.           "trials" : exp.data_trials,
  137.           "catch_trials" : exp.catch_trials,
  138.           "system" : exp.system,
  139.           //"condition" : exp.condition,
  140.           "subject_information" : exp.subj_data,
  141.           "time_in_minutes" : (Date.now() - exp.startT)/60000
  142.       };
  143.       setTimeout(function() {turk.submit(exp.data);}, 1000);
  144.     }
  145.   });
  146.  
  147.   return slides;
  148. }
  149.  
  150. /// init ///
  151. function init() {
  152.   exp.trials = [];
  153.   exp.catch_trials = [];
  154.   exp.instruction = _.sample(["instruction1","instruction2"]);
  155.   exp.system = {
  156.       Browser : BrowserDetect.browser,
  157.       OS : BrowserDetect.OS,
  158.       screenH: screen.height,
  159.       screenUH: exp.height,
  160.       screenW: screen.width,
  161.       screenUW: exp.width
  162.     };
  163.   //blocks of the experiment:
  164.   exp.structure=["i0", "instructions1",'multi_slider', 'subj_info', 'thanks'];
  165.  
  166.   exp.data_trials = [];
  167.   //make corresponding slides:
  168.   exp.slides = make_slides(exp);
  169.  
  170.   exp.nQs = utils.get_exp_length(); //this does not work if there are stacks of stims (but does work for an experiment with this structure)
  171.                     //relies on structure and slides being defined
  172.  
  173.   $('.slide').hide(); //hide everything
  174.  
  175.   //make sure turkers have accepted HIT (or you're not in mturk)
  176.   $("#start_button").click(function() {
  177.     if (turk.previewMode) {
  178.       $("#mustaccept").show();
  179.     } else {
  180.       $("#start_button").click(function() {$("#mustaccept").show();});
  181.       exp.go();
  182.     }
  183.   });
  184.  
  185.   exp.go(); //show first slide
  186. }

Raw Paste

Login or Register to edit or fork this paste. It's free.