/* This software is licensed under a BSD license; see the LICENSE file for details. */ define_ibex_controller({ name: "Maze", jqueryWidget: { _init: function() { this.cssPrefix = this.options._cssPrefix; this.utils = this.options._utils; this.finishedCallback = this.options._finishedCallback if (typeof(this.options.s) == "string") { // replace all linebreaks (and surrounding space) with 'space-return-space' var inputString = this.options.s.replace(/\s*[\r\n]\s*/g, " \r "); this.words = inputString.split(/[ \t]+/); } else { assert_is_arraylike(this.options.s, "Bad value for 's' option of Maze."); this.words = this.options.s; } if (typeof(this.options.a) == "string") { // replace all linebreaks (and surrounding space) with 'space-return-space' var inputString = this.options.a.replace(/\s*[\r\n]\s*/g, " \r "); this.alts = inputString.split(/[ \t]+/); } else { assert_is_arraylike(this.options.a, "Bad value for 'a' option of Maze."); this.alts = this.options.a; } assert(this.alts.length == this.words.length, "'a' and 's' must be the same length."); defaultOrder=[]; defaultOrder[0]=0; for (var i = 1; i < this.words.length; ++i){ defaultOrder[i] = Math.round(Math.random()); } //If no left-right order is provided, construct one randomly. this.order=dget(this.options, "order", defaultOrder); assert_is_arraylike(this.order, "Bad value for 'order' option of Maze."); assert(this.order.length == this.words.length, "'order' and 's' must be the same length."); for (i = 0; i < this.words.length; ++i){ assert(defaultOrder[i]==1||defaultOrder[i]==0, "elements of 'order' must be 0 or 1."); } this.redo=dget(this.options, "redo", false); assert(typeof(this.redo)===typeof(true), "Bad value for 'redo', must be true or false."); this.time=dget(this.options,"time",1000); assert(typeof(this.time)===typeof(5), "Bad value for 'time', must be int of at least 0."); //todo add assert on time this.emess=dget(this.options,"emess","Incorrect!") assert(typeof(this.emess)===typeof('ab'),"Bad value for 'emess', must be string.") this.rmess=dget(this.options,"rmess","Please try again.") assert(typeof(this.rmess)===typeof('ab'),"Bad value for 'rmess', must be string.") this.currentWord = 0; this.stoppingPoint = this.words.length; this.counter=$("