<commit_before>(function() {
  // Establish the root object, `window` in the browser, or `exports` on the server.
  var root = this;

  // Save the previous value of the `_r` variable.
  var previous_r = root._r;

  // Create quick reference variables for speed access to core prototypes.
  var slice = Array.prototype.slice;

  // Create a safe reference to the Underscore object for use below.
  var _r = function(obj) {
    if (obj instanceof _r) return obj;
    if (!(this instanceof _r)) return new _r(obj);
    this._wrapped = obj;
  };

  // Export the Underscore object for **Node.js**, with
  // backwards-compatibility for the old `require()` API. If we're in
  // the browser, add `_r` as a global object.
  if (typeof exports !== 'undefined') {
    if (typeof module !== 'undefined' && module.exports) {
      exports = module.exports = _r;
    }
    exports._r = _r;
  } else {
    root._r = _r;
  }

  // Current version.
  _r.VERSION = '0.0.1';

  // Reference to Underscore from browser
  var _ = root._;
  if (typeof _ === 'undefined' && typeof require !== 'undefined'){
    _ = require('underscore')._;
  }

  // Collection Functions
  // --------------------

  // Return the results of applying the iteratee to each element.
  _r.map = _r.collect = function(iteratee) {
    iteratee = _.iteratee(iteratee);
    return function(step){
      return function(result, input){
        return (result === void 0)  ? step()
          :    (input === void 0)   ? step(result)
          :    step(result, iteratee(input))
      }
    }
  };

  // Return the first value which passes a truth test. Aliased as `detect`.
  _r.find = _r.detect = function(predicate) {
    predicate = _.iteratee(predicate);
    return function(step){
      return function(result, input){
        return (result === void 0)  ? step()
          :    (input === void 0)   ? step(result)
          :    (predicate(input))   ? _r.reduced(step(result, input))
          :    result;
      }
    }
  };

  // Return all the elements that pass a truth test.
  // Aliased as `select`.
  _r.filter = _r.select = function(predicate) {
    predicate = _.iteratee(predicate);
    return function(step){
      return function(result, input){
        return (result === void 0)  ? step()
          :    (input === void 0)   ? step(result)
          :    (predicate(input))   ? step(result, input)
          :    result;
      }
    }
  };

  // Return all the elements for which a truth test fails.
  _r.reject = function(predicate) {
    return _r.filter(_.negate(_.iteratee(predicate)));
  };

  // Determine whether all of the elements match a truth test.
  // Aliased as `all`.
  _r.every = _r.all = function(predicate) {
    predicate = _.iteratee(predicate);
    return function(step){
      var found = false;
      return function(result, input){
        if(result === void 0) return step();

        if(input === void 0){
          if(!found){
            result = step(result, true);
          }
          return step(result);
        }

        if(!predicate(input)){
          found = true;
          return _r.reduced(step(result, false));
        }
        return result;
      }
    }
  };

  // Determine if at least one element in the object matches a truth test.
  // Aliased as `any`.
  _r.some = _r.any = function(predicate) {
    predicate = _.iteratee(predicate);
    return function(step){
      var found = false;
      return function(result, input){
        if(result === void 0) return step();

        if(input === void 0){
          if(!found){
            result = step(result, found);
          }
          return step(result);
        }

        if(predicate(input)){
          found = true;
          return _r.reduced(step(result, found));
        }
        return result;
      }
    }
  };

  // Determine if contains a given value (using `===`).
  // Aliased as `include`.
  _r.contains = _r.include = function(target) {
    return _r.some(function(x){return x === target});
  };

  // Invoke a method (with arguments) on every item in a collection.
  _r.invoke = function(method) {
    var args = slice.call(arguments, 2);
    var isFunc = _.isFunction(method);
    return _r.map(function(value) {
      return (isFunc ? method : value[method]).apply(value, args);
    });
  };

  // Convenience version of a common use case of `map`: fetching a property.
  _r.pluck = function(key) {
    return _r.map(_.property(key));
  };

  // Convenience version of a common use case of `filter`: selecting only objects
  // containing specific `key:value` pairs.
  _r.where = function(attrs) {
    return _r.filter(_.matches(attrs));
  };

  // Convenience version of a common use case of `find`: getting the first object
  // containing specific `key:value` pairs.
  _r.findWhere = function(attrs) {
    return _r.find(_.matches(attrs));
  };

  // Return the maximum element (or element-based computation).
  _r.max = function(iteratee) {
    iteratee = _.iteratee(iteratee);

    return function(step){
      var computedResult = -Infinity, lastComputed = -Infinity, computed;
      return function(result, input){
        if(result === void 0) return step();

        if(input === void 0){
          result = step(result, computedResult);
          return step(result);
        }

        computed = iteratee(input);
        if (computed > lastComputed || computed === -Infinity && computedResult === -Infinity) {
          computedResult = input;
          lastComputed = computed;
        }
        return result;
      }
    }
  };

  // Return the minimum element (or element-based computation).
  _r.min = function(obj, iteratee) {
    iteratee = _.iteratee(iteratee);

    return function(step){
      var computedResult = Infinity, lastComputed = Infinity, computed;
      return function(result, input){
        if(result === void 0) return step();

        if(input === void 0){
          result = step(result, computedResult);
          return step(result);
        }

        computed = iteratee(input);
        if (computed < lastComputed || computed === Infinity && computedResult === Infinity) {
          computedResult = input;
          lastComputed = computed;
        }
        return result;
      }
    }
  };

  // Array Functions
  // ---------------

  // Get the first element of an array. Passing **n** will return the first N
  // values in the array. Aliased as `head` and `take`.
  _r.first = _r.head = _r.take = function(n) {
    n = (n > 0) ? n : 1;
    return function(step){
      var count = n;
      return function(result, input){
        if(result === void 0) return step();
        if(input === void 0) return step(result);

        step(result, input);

        return (!--count) ?  _r.reduced(result) : result;
      }
    }
  };

  /* TODO
  // Returns everything but the last entry. Passing **n** will return all the values
  // excluding the last N.
  _.initial = function(array, n, guard) {
    return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n)));
  };

  // Get the last element. Passing **n** will return the last N  values.
  _.last = function(array, n, guard) {
    if (array == null) return void 0;
    if (n == null || guard) return array[array.length - 1];
    return _.rest(array, Math.max(0, array.length - n));
  };

  // Returns everything but the first entry. Aliased as `tail` and `drop`.
  // Passing an **n** will return the rest N values.
  _.rest = _.tail = _.drop = function(array, n, guard) {
    return slice.call(array, n == null || guard ? 1 : n);
  };
  */

  // Trim out all falsy values from an array.
  _r.compact = function() {
    return _r.filter(_.identity);
  };

  /* TODO
  // Produce a duplicate-free version of the array. If the array has already
  // been sorted, you have the option of using a faster algorithm.
  // Aliased as `unique`.
  _.uniq = _.unique = function(array, isSorted, iteratee) {
    if (array == null) return [];
    if (!_.isBoolean(isSorted)) {
      iteratee = isSorted;
      isSorted = false;
    }
    if (iteratee != null) iteratee = _.iteratee(iteratee);
    var result = [];
    var seen = [];
    for (var i = 0, length = array.length; i < length; i++) {
      var value = array[i];
      if (isSorted) {
        if (!i || seen !== value) result.push(value);
        seen = value;
      } else if (iteratee) {
        var computed = iteratee(value, i, array);
        if (_.indexOf(seen, computed) < 0) {
          seen.push(computed);
          result.push(value);
        }
      } else if (_.indexOf(result, value) < 0) {
        result.push(value);
      }
    }
    return result;
  };
  */

  // Invokes interceptor with each result and input, and then passes through input.
  // The primary purpose of this method is to "tap into" a method chain, in
  // order to perform operations on intermediate results within the chain.
  _r.tap = function(interceptor) {
    return function(step){
      return function(result, input){
        if(result === void 0) return step();
        if(input === void 0) return step(result);
        interceptor(result, input);
        return step(result, input);
      }
    }
  };

  // OOP
  // ---------------
  // If Underscore is called as a function, it returns a wrapped object that
  // can be used OO-style. This wrapper holds altered versions of all the
  // underscore functions. Wrapped objects may be chained.

  // Helper function to continue chaining intermediate results.
  var result = function(instance, obj) {
    return instance._chain ? _r.chain(obj) : obj;
  };

  // Add your own custom transducers to the Underscore.transducer object.
  _r.mixin = function(obj) {
    _.each(_.functions(obj), function(name) {
      var func = _r[name] = obj[name];
      _r.prototype[name] = function() {
        var method = func.apply(_r, arguments);
        if(_.isFunction(this._wrapped)){
          method = _.compose(this._wrapped, method);
        }
        return result(this, method);
      };
    });
  };

  // Add all of the Underscore functions to the wrapper object.
  _r.mixin(_r);

  _r.chain = function(obj) {
    var instance = _r(obj);
    instance._chain = true;
    return instance;
  };

  // Extracts the result from a wrapped and chained object.
  _r.prototype.value = function() {
    return this._wrapped;
  };

  // Run Underscore.js in *noConflict* mode, returning the `_` variable to its
  // previous owner. Returns a reference to the Underscore object.
  _r.noConflict = function() {
    root._r = previous_r;
    return this;
  };

  // Transducer Functions
  // --------------------

  // Wrapper to return from iteratee of reduce to terminate
  // _r.reduce early with the provided value
  function Reduced(value){this.value = value};
  _r.reduced = function(value){
    return new Reduced(value);
  }
  var reduceError = 'Reduce of empty array with no initial value',
      Symbol_iterator = (typeof Symbol !== 'undefined' && Symbol.iterator || '@@iterator');

  // **Reduce** builds up a single result from a list of values, aka `inject`,
  // or `foldl`.
  _r.reduce = _r.foldl = _r.inject = function(obj, iteratee, memo) {
    if (obj == null) obj = [];
    var keys = obj.length !== +obj.length && _.keys(obj),
        length = (keys || obj).length,
        index = 0, currentKey,
        iterator = (keys && (obj[Symbol_iterator] || obj));

    if(_.isFunction(iterator.next)){
      // Detected an iterator
      for(;;){
        currentKey = iterator.next();
        if(currentKey.done){
          return memo;
        }
        memo = iteratee(memo, currentKey.value, index++, obj);
        if(memo instanceof Reduced){
          return memo.value;
        }
      }
    }  else {
      // underscore behavior + Reduced if not iterator
      if (arguments.length < 3) {
        if (!length) throw new TypeError(reduceError);
        memo = obj[keys ? keys[index++] : index++];
      }
      for (; index < length; index++) {
        currentKey = keys ? keys[index] : index;
        memo = iteratee(memo, obj[currentKey], currentKey, obj);
        if(memo instanceof Reduced){
          return memo.value;
        }
      }
    }
    return memo;
  };

  // Takes a reducing step function of 2 args and returns a function suitable for
  // transduce by adding an arity-1 signature that calls complete
  // (default - identity) on the result argument.
  _r.completing = function(step, complete){
    complete = complete || _.identity;
    return function(result, input){
      return (result === void 0)  ? step()
        :    (input === void 0)   ? complete(result)
        :    step(result, input);
    }
  }

  // Appends (conjoins) the item to the collection, and returns collection
  _r.append = _r.conj = _r.conjoin = function(obj, item){
    if(obj === void 0){
      return [];
    }

    if(item === void 0){
      return obj;
    }

    // TODO objects
    obj.push(item);
    return obj;
  }

  // Reduce with a transformation of step (transform). If memo is not
  // supplied, step() will be called to produce it. step should be a reducing
  // step function that accepts both 1 and 2 arguments, if it accepts
  // only 2 you can add the arity-1 with _r.completing. Returns the result
  // of applying (the transformed) transform to memo and the first item in collection,
  // then applying transform to that result and the 2nd item, etc. If collection
  // contains no items, returns memo and step is not called. Note that
  // certain transforms may inject or skip items.
  _r.transduce = function(transform, obj, step, memo){
    if(step === void 0){
      step = _r.append;
    }

    if(memo === void 0){
      memo = step();
    }

    step = transform(step);
    return step(_r.reduce(obj, step, memo));
  }

  _r.prototype.transduce = function(obj, step, memo){
    return _r.transduce(this._wrapped, obj, step, memo);
  }

  // Returns a new coll consisting of to-coll with all of the items of
  // from-coll conjoined. A transducer (step function) may be supplied.
  _r.into = function(to, transform, from){
    var step = _r.append;

    if(from === void 0){
      from = transform
      return _r.reduce(from, step, to)
    }

    return _r.transduce(transform, from, step, to)
  }

  _r.prototype.into = function(to, from){
    return _r.into(to, this._wrapped, from);
  }

  // AMD registration happens at the end for compatibility with AMD loaders
  // that may not enforce next-turn semantics on modules. Even though general
  // practice for AMD registration is to be anonymous, underscore registers
  // as a named module because, like jQuery, it is a base library that is
  // popular enough to be bundled in a third party lib, but not be part of
  // an AMD load request. Those cases could generate an error when an
  // anonymous define() is called outside of a loader request.
  if (typeof define === 'function' && define.amd) {
    define('underscore.transducer', [], function() {
      return _r;
    });
  }
}.call(this));
<commit_msg>Add generate to allow (possibly infinite) callback based sequences<commit_after>(function() {
  // Establish the root object, `window` in the browser, or `exports` on the server.
  var root = this;

  // Save the previous value of the `_r` variable.
  var previous_r = root._r;

  // Create quick reference variables for speed access to core prototypes.
  var slice = Array.prototype.slice;

  // Create a safe reference to the Underscore object for use below.
  var _r = function(obj) {
    if (obj instanceof _r) return obj;
    if (!(this instanceof _r)) return new _r(obj);
    this._wrapped = obj;
  };

  // Export the Underscore object for **Node.js**, with
  // backwards-compatibility for the old `require()` API. If we're in
  // the browser, add `_r` as a global object.
  if (typeof exports !== 'undefined') {
    if (typeof module !== 'undefined' && module.exports) {
      exports = module.exports = _r;
    }
    exports._r = _r;
  } else {
    root._r = _r;
  }

  // Current version.
  _r.VERSION = '0.0.1';

  // Reference to Underscore from browser
  var _ = root._;
  if (typeof _ === 'undefined' && typeof require !== 'undefined'){
    _ = require('underscore')._;
  }

  // Collection Functions
  // --------------------

  // Return the results of applying the iteratee to each element.
  _r.map = _r.collect = function(iteratee) {
    iteratee = _.iteratee(iteratee);
    return function(step){
      return function(result, input){
        return (result === void 0)  ? step()
          :    (input === void 0)   ? step(result)
          :    step(result, iteratee(input))
      }
    }
  };

  // Return the first value which passes a truth test. Aliased as `detect`.
  _r.find = _r.detect = function(predicate) {
    predicate = _.iteratee(predicate);
    return function(step){
      return function(result, input){
        return (result === void 0)  ? step()
          :    (input === void 0)   ? step(result)
          :    (predicate(input))   ? _r.reduced(step(result, input))
          :    result;
      }
    }
  };

  // Return all the elements that pass a truth test.
  // Aliased as `select`.
  _r.filter = _r.select = function(predicate) {
    predicate = _.iteratee(predicate);
    return function(step){
      return function(result, input){
        return (result === void 0)  ? step()
          :    (input === void 0)   ? step(result)
          :    (predicate(input))   ? step(result, input)
          :    result;
      }
    }
  };

  // Return all the elements for which a truth test fails.
  _r.reject = function(predicate) {
    return _r.filter(_.negate(_.iteratee(predicate)));
  };

  // Determine whether all of the elements match a truth test.
  // Aliased as `all`.
  _r.every = _r.all = function(predicate) {
    predicate = _.iteratee(predicate);
    return function(step){
      var found = false;
      return function(result, input){
        if(result === void 0) return step();

        if(input === void 0){
          if(!found){
            result = step(result, true);
          }
          return step(result);
        }

        if(!predicate(input)){
          found = true;
          return _r.reduced(step(result, false));
        }
        return result;
      }
    }
  };

  // Determine if at least one element in the object matches a truth test.
  // Aliased as `any`.
  _r.some = _r.any = function(predicate) {
    predicate = _.iteratee(predicate);
    return function(step){
      var found = false;
      return function(result, input){
        if(result === void 0) return step();

        if(input === void 0){
          if(!found){
            result = step(result, found);
          }
          return step(result);
        }

        if(predicate(input)){
          found = true;
          return _r.reduced(step(result, found));
        }
        return result;
      }
    }
  };

  // Determine if contains a given value (using `===`).
  // Aliased as `include`.
  _r.contains = _r.include = function(target) {
    return _r.some(function(x){return x === target});
  };

  // Invoke a method (with arguments) on every item in a collection.
  _r.invoke = function(method) {
    var args = slice.call(arguments, 2);
    var isFunc = _.isFunction(method);
    return _r.map(function(value) {
      return (isFunc ? method : value[method]).apply(value, args);
    });
  };

  // Convenience version of a common use case of `map`: fetching a property.
  _r.pluck = function(key) {
    return _r.map(_.property(key));
  };

  // Convenience version of a common use case of `filter`: selecting only objects
  // containing specific `key:value` pairs.
  _r.where = function(attrs) {
    return _r.filter(_.matches(attrs));
  };

  // Convenience version of a common use case of `find`: getting the first object
  // containing specific `key:value` pairs.
  _r.findWhere = function(attrs) {
    return _r.find(_.matches(attrs));
  };

  // Return the maximum element (or element-based computation).
  _r.max = function(iteratee) {
    iteratee = _.iteratee(iteratee);

    return function(step){
      var computedResult = -Infinity, lastComputed = -Infinity, computed;
      return function(result, input){
        if(result === void 0) return step();

        if(input === void 0){
          result = step(result, computedResult);
          return step(result);
        }

        computed = iteratee(input);
        if (computed > lastComputed || computed === -Infinity && computedResult === -Infinity) {
          computedResult = input;
          lastComputed = computed;
        }
        return result;
      }
    }
  };

  // Return the minimum element (or element-based computation).
  _r.min = function(obj, iteratee) {
    iteratee = _.iteratee(iteratee);

    return function(step){
      var computedResult = Infinity, lastComputed = Infinity, computed;
      return function(result, input){
        if(result === void 0) return step();

        if(input === void 0){
          result = step(result, computedResult);
          return step(result);
        }

        computed = iteratee(input);
        if (computed < lastComputed || computed === Infinity && computedResult === Infinity) {
          computedResult = input;
          lastComputed = computed;
        }
        return result;
      }
    }
  };

  // Array Functions
  // ---------------

  // Get the first element of an array. Passing **n** will return the first N
  // values in the array. Aliased as `head` and `take`.
  _r.first = _r.head = _r.take = function(n) {
    n = (n > 0) ? n : 1;
    return function(step){
      var count = n;
      return function(result, input){
        if(result === void 0) return step();
        if(input === void 0) return step(result);

        step(result, input);

        return (!--count) ?  _r.reduced(result) : result;
      }
    }
  };

  /* TODO
  // Returns everything but the last entry. Passing **n** will return all the values
  // excluding the last N.
  _.initial = function(array, n, guard) {
    return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n)));
  };

  // Get the last element. Passing **n** will return the last N  values.
  _.last = function(array, n, guard) {
    if (array == null) return void 0;
    if (n == null || guard) return array[array.length - 1];
    return _.rest(array, Math.max(0, array.length - n));
  };

  // Returns everything but the first entry. Aliased as `tail` and `drop`.
  // Passing an **n** will return the rest N values.
  _.rest = _.tail = _.drop = function(array, n, guard) {
    return slice.call(array, n == null || guard ? 1 : n);
  };
  */

  // Trim out all falsy values from an array.
  _r.compact = function() {
    return _r.filter(_.identity);
  };

  /* TODO
  // Produce a duplicate-free version of the array. If the array has already
  // been sorted, you have the option of using a faster algorithm.
  // Aliased as `unique`.
  _.uniq = _.unique = function(array, isSorted, iteratee) {
    if (array == null) return [];
    if (!_.isBoolean(isSorted)) {
      iteratee = isSorted;
      isSorted = false;
    }
    if (iteratee != null) iteratee = _.iteratee(iteratee);
    var result = [];
    var seen = [];
    for (var i = 0, length = array.length; i < length; i++) {
      var value = array[i];
      if (isSorted) {
        if (!i || seen !== value) result.push(value);
        seen = value;
      } else if (iteratee) {
        var computed = iteratee(value, i, array);
        if (_.indexOf(seen, computed) < 0) {
          seen.push(computed);
          result.push(value);
        }
      } else if (_.indexOf(result, value) < 0) {
        result.push(value);
      }
    }
    return result;
  };
  */

  // Invokes interceptor with each result and input, and then passes through input.
  // The primary purpose of this method is to "tap into" a method chain, in
  // order to perform operations on intermediate results within the chain.
  _r.tap = function(interceptor) {
    return function(step){
      return function(result, input){
        if(result === void 0) return step();
        if(input === void 0) return step(result);
        interceptor(result, input);
        return step(result, input);
      }
    }
  };

  // OOP
  // ---------------
  // If Underscore is called as a function, it returns a wrapped object that
  // can be used OO-style. This wrapper holds altered versions of all the
  // underscore functions. Wrapped objects may be chained.

  // Helper function to continue chaining intermediate results.
  var result = function(instance, obj) {
    return instance._chain ? _r.chain(obj) : obj;
  };

  // Add your own custom transducers to the Underscore.transducer object.
  _r.mixin = function(obj) {
    _.each(_.functions(obj), function(name) {
      var func = _r[name] = obj[name];
      _r.prototype[name] = function() {
        var method = func.apply(_r, arguments);
        if(_.isFunction(this._wrapped)){
          method = _.compose(this._wrapped, method);
        }
        return result(this, method);
      };
    });
  };

  // Add all of the Underscore functions to the wrapper object.
  _r.mixin(_r);

  _r.chain = function(obj) {
    var instance = _r(obj);
    instance._chain = true;
    return instance;
  };

  // Extracts the result from a wrapped and chained object.
  _r.prototype.value = function() {
    return this._wrapped;
  };

  // Run Underscore.js in *noConflict* mode, returning the `_` variable to its
  // previous owner. Returns a reference to the Underscore object.
  _r.noConflict = function() {
    root._r = previous_r;
    return this;
  };

  // Transducer Functions
  // --------------------

  // Wrapper to return from iteratee of reduce to terminate
  // _r.reduce early with the provided value
  function Reduced(value){this.value = value};
  _r.reduced = function(value){
    return new Reduced(value);
  }
  var reduceError = 'Reduce of empty array with no initial value',
      Symbol_iterator = (typeof Symbol !== 'undefined' && Symbol.iterator || '@@iterator');

  // **Reduce** builds up a single result from a list of values, aka `inject`,
  // or `foldl`.  This implementation extends underscores implementation by
  // allowing early termination using _r.reduced and accepts iterators (ES6 or any object
  // that defines a next method)
  _r.reduce = _r.foldl = _r.inject = function(obj, iteratee, memo) {
    if (obj == null) obj = [];
    var keys = obj.length !== +obj.length && _.keys(obj),
        length = (keys || obj).length,
        index = 0, currentKey,
        iterator = (keys && (obj[Symbol_iterator] && obj[Symbol_iterator]() || obj));

    if(_.isFunction(iterator.next)){
      // Detected an iterator
      for(;;){
        currentKey = iterator.next();
        if(currentKey.done){
          return memo;
        }
        memo = iteratee(memo, currentKey.value, index++, obj);
        if(memo instanceof Reduced){
          return memo.value;
        }
      }
    }  else {
      // underscore behavior + Reduced if not iterator
      if (arguments.length < 3) {
        if (!length) throw new TypeError(reduceError);
        memo = obj[keys ? keys[index++] : index++];
      }
      for (; index < length; index++) {
        currentKey = keys ? keys[index] : index;
        memo = iteratee(memo, obj[currentKey], currentKey, obj);
        if(memo instanceof Reduced){
          return memo.value;
        }
      }
    }
    return memo;
  };

  // Takes a reducing step function of 2 args and returns a function suitable for
  // transduce by adding an arity-1 signature that calls complete
  // (default - identity) on the result argument.
  _r.completing = function(step, complete){
    complete = complete || _.identity;
    return function(result, input){
      return (result === void 0)  ? step()
        :    (input === void 0)   ? complete(result)
        :    step(result, input);
    }
  }

  // Appends (conjoins) the item to the collection, and returns collection
  _r.append = _r.conj = _r.conjoin = function(obj, item){
    if(obj === void 0){
      return [];
    }

    if(item === void 0){
      return obj;
    }

    // TODO objects
    obj.push(item);
    return obj;
  }

  // Reduce with a transformation of step (transform). If memo is not
  // supplied, step() will be called to produce it. step should be a reducing
  // step function that accepts both 1 and 2 arguments, if it accepts
  // only 2 you can add the arity-1 with _r.completing. Returns the result
  // of applying (the transformed) transform to memo and the first item in collection,
  // then applying transform to that result and the 2nd item, etc. If collection
  // contains no items, returns memo and step is not called. Note that
  // certain transforms may inject or skip items.
  _r.transduce = function(transform, obj, step, memo){
    if(step === void 0){
      step = _r.append;
    }

    if(memo === void 0){
      memo = step();
    }

    step = transform(step);
    return step(_r.reduce(obj, step, memo));
  }

  // Calls transduce using the chained transformation
  _r.prototype.transduce = function(obj, step, memo){
    return _r.transduce(this._wrapped, obj, step, memo);
  }

  // Returns a new coll consisting of to-coll with all of the items of
  // from-coll conjoined. A transducer (step function) may be supplied.
  _r.into = function(to, transform, from){
    var step = _r.append;

    if(from === void 0){
      from = transform
      return _r.reduce(from, step, to)
    }

    return _r.transduce(transform, from, step, to)
  }

  // Calls into using the chained transformation
  _r.prototype.into = function(to, from){
    return _r.into(to, this._wrapped, from);
  }

  // Creates an (duck typed) iterator that calls the provided next callback repeatedly
  // and uses the return value as the next value of the iterator.
  // Marks iterator as done if the next callback returns undefined (returns nothing)
  // Can be used to as a source obj to reduce, transduce etc
  _r.generate = function(next){
    return {
      next: function(){
        var value = next();
        return (value === void 0) ? {done: true} : {done: false, value: value};
      }
    }
  }

  // Transduces the current chained object by using the chained trasnformation
  // and an iterator created with the callback
  _r.prototype.generate = function(callback){
    return this.transduce(_r.generate(callback));
  }

  // AMD registration happens at the end for compatibility with AMD loaders
  // that may not enforce next-turn semantics on modules. Even though general
  // practice for AMD registration is to be anonymous, underscore registers
  // as a named module because, like jQuery, it is a base library that is
  // popular enough to be bundled in a third party lib, but not be part of
  // an AMD load request. Those cases could generate an error when an
  // anonymous define() is called outside of a loader request.
  if (typeof define === 'function' && define.amd) {
    define('underscore.transducer', [], function() {
      return _r;
    });
  }
}.call(this));
<|endoftext|>


<commit_before>// what do I want to do
// 1. Identify the area that will track mouse movement
// 2. Identify area that will constrain movement (eye)
// 3. identify the element that I want to move (pupil)
// 4. do some maths to link the top and left positions of the pupil to the mouse position
//$(document).on("ready", function(){

//(function(){

var mouseTrack = {
	init: function(){
		this.cacheDom();
		this.trackMouse();
		//this.eyePos();
	},
	cacheDom: function() {
		this.$container = $(".container");
		this.$eye = $(".eye");
		this.$pupil = $(".pupil")
		//console.log(this.$pupil);
	},
	trackMouse: function(){
		var pupil = this.$pupil;
		var width = this.$container.width();
		var height = this.$container.height();
		var pupilTop = this.$pupil.css("top");
		var pupilLeft = this.$pupil.css("left");
		//console.log(this.$container.width());
		this.$container.mousemove(function(event){
			//console.log(pupil);
			var x = event.clientX;
			var y = event.clientY;
			xPos = Math.min(Math.max(20, Math.round((x / width)*100)),80),
			yPos = Math.min(Math.max(20, Math.round((y / height)*100)),80);
			for (i = 0; i<pupil.length; i ++) {
				$(pupil[i]).css({"top": yPos + "%"});
				$(pupil[i]).css({"left": xPos + "%"});
			}

			//pupilLeft = xPos;

		});

	},
	eyePos: function() {
		var mousePosn = this.trackMouse();
		//console.log(mousePosn);
		var pupilTop = this.$pupil.top;

	}

};
console.log(mouseTrack);
mouseTrack.init();
//})();

//})

<commit_msg>update script<commit_after>// what do I want to do
// 1. Identify the area that will track mouse movement
// 2. Identify area that will constrain movement (eye)
// 3. identify the element that I want to move (pupil)
// 4. do some maths to link the top and left positions of the pupil to the mouse position
//$(document).on("ready", function(){

//(function(){

var mouseTrack = {
	init: function(){
		this.cacheDom();
		this.trackMouse();
	},
	cacheDom: function() {
		this.$container = $(".container");
		this.$eye = $(".eye");
		this.$pupil = $(".pupil")
	},
	trackMouse: function(){
		var pupil = this.$pupil;
		var width = this.$container.width();
		var height = this.$container.height();
		var pupilTop = this.$pupil.css("top");
		var pupilLeft = this.$pupil.css("left");
		this.$container.mousemove(function(event){
			var x = event.clientX;
			var y = event.clientY;
			xPos = Math.min(Math.max(20, Math.round((x / width)*100)),80),
			yPos = Math.min(Math.max(20, Math.round((y / height)*100)),80);
			for (i = 0; i<pupil.length; i ++) {
				$(pupil[i]).css({"top": yPos + "%"});
				$(pupil[i]).css({"left": xPos + "%"});
			}
		});

	},
};
mouseTrack.init();
//})();

//})

<|endoftext|>


<commit_before>// Basic Operations

function run() {
	var compute = ((13+2)*34-2);
	console.log(compute);

	var string = "IlovemyMacbookPro".length;
	console.log(string);

	var string1 = "Hello";
	var string2 = "World";
	console.log(string1+" "+string2+"!");

	var num = 10;
	console.log(num+=10);
	console.log(num-=10);
	console.log(num*=10);
	console.log(num/=10);

	var str1 = "asdas dasdsadasdasdsad";
	var str2 = "Adasdasdasdasd";

	console.log(str1==str2);

	console.log(str2[0]);

	console.log(str1.charAt(5));

	num = 12345;
	console.log(num);

	var value = 1;
	while(value <= 10) {
		console.log(value);
		value++;
	}

	for(value = 10; value >=1; value--) {
		console.log(value);
	}
}

run();

// Loops and Conditionals

function trains(){
	var totalTrains = 12;
	var specialTrain1 = 10;
	var specialTrain2 = 12;
	var operationalTrains = 8;
	var dayOfWeek = "Wed";

	// var i = 1;
	// for(i = 1; i <= operationalTrains; i++) {
	// 	console.log("Train #"+i+" is operational");
	// }

	// for(i = operationalTrains+1; i <= totalTrains; i++) {
	// 	console.log("Train #"+i+" is not operational");
	// }

	//Optimising above approach

	for(i = 1; i <= totalTrains; i++) {
		if(i <= operationalTrains && i != 3) {
			console.log("Train #"+i+" is operational");
		}
		else if(i == specialTrain1 || i == specialTrain2){
			console.log("Train #"+i+" starts at noon");
		}
		else if(i == 3 && dayOfWeek == "Sun") {
			console.log("Train #"+i+" is operational");
		}
		else {
			console.log("Train #"+i+" is not operational");
		}
	}

}

trains();

// Built in Dialogs and Popups

function username() {
	var name;
	if(name = prompt("What is your name ?")) {
		if(confirm("Are you sure your name is "+name)) {
			alert("Sup "+name);
		}
		else {
			username();
		}
	}
	else {
		username();
	}
}

username();

<commit_msg>Updated script.js<commit_after>// Basic Operations

function run() {
	var compute = ((13+2)*34-2);
	console.log(compute);

	var string = "IlovemyMacbookPro".length;
	console.log(string);

	var string1 = "Hello";
	var string2 = "World";
	console.log(string1+" "+string2+"!");

	var num = 10;
	console.log(num+=10);
	console.log(num-=10);
	console.log(num*=10);
	console.log(num/=10);

	var str1 = "asdas dasdsadasdasdsad";
	var str2 = "Adasdasdasdasd";

	console.log(str1==str2);

	console.log(str2[0]);

	console.log(str1.charAt(5));

	num = 12345;
	console.log(num);

	var value = 1;
	while(value <= 10) {
		console.log(value);
		value++;
	}

	for(value = 10; value >=1; value--) {
		console.log(value);
	}
}

run();

// Loops and Conditionals

function trains(){
	var totalTrains = 12;
	var specialTrain1 = 10;
	var specialTrain2 = 12;
	var operationalTrains = 8;
	var dayOfWeek = "Wed";

	// var i = 1;
	// for(i = 1; i <= operationalTrains; i++) {
	// 	console.log("Train #"+i+" is operational");
	// }

	// for(i = operationalTrains+1; i <= totalTrains; i++) {
	// 	console.log("Train #"+i+" is not operational");
	// }

	//Optimising above approach

	for(i = 1; i <= totalTrains; i++) {
		if(i <= operationalTrains && i != 3) {
			console.log("Train #"+i+" is operational");
		}
		else if(i == specialTrain1 || i == specialTrain2){
			console.log("Train #"+i+" starts at noon");
		}
		else if(i == 3 && dayOfWeek == "Sun") {
			console.log("Train #"+i+" is operational");
		}
		else {
			console.log("Train #"+i+" is not operational");
		}
	}

}

trains();

// Built in Dialogs and Popups

function username() {
	var name;
	if(name = prompt("What is your name ?")) {
		if(confirm("Are you sure your name is "+name)) {
			alert("Sup "+name);
		}
		else {
			username();
		}
	}
	else {
		username();
	}
	console.log(name);
}

username();

<|endoftext|>


<commit_before>chrome.storage.local.get(null, function(items) {
  var aliases = items.aliases
  var aliasKey = items.aliasKey
  $('body').on('keydown', 'input, textarea', function(e) {
    var code = (e.keyCode ? e.keyCode : e.which);
    if(code == aliasKey) {
      var input = $(this).val().split(" ");
      for(var i = 0; i < input.length; i++) {
        if(replaceInput(input[i])) {
          e.preventDefault();
          input[i] = replaceInput(input[i])
        };
      };
      $(this).val(input.join(" "))
    };
  });

  function replaceInput(input) {
    if(input in aliases) {
      return aliases[input]
    } else {
      return false
    };
  };
});
<commit_msg>Add fix for reactjs shadowdom<commit_after>chrome.storage.local.get(null, function(items) {
  var aliases = items.aliases
  var aliasKey = items.aliasKey
  $('body').on('keydown', 'input, textarea', function(e) {
    var code = (e.keyCode ? e.keyCode : e.which);
    if(code == aliasKey) {
      var input = $(this).val().split(" ");
      for(var i = 0; i < input.length; i++) {
        if(replaceInput(input[i])) {
          e.preventDefault();
          input[i] = replaceInput(input[i])
        };
      };
      this.value = input.join(" ");
      var event = new Event('input', {bubbles: true});
      this.dispatchEvent(event);
    };
  });

  function replaceInput(input) {
    if(input in aliases) {
      return aliases[input]
    } else {
      return false
    };
  };
});

<|endoftext|>


<commit_before>/*
 * Created by marekfort on 13/04/16.
 */

$(document).ready(function(){
    // Setting summary to be centered to the iphone mockup
    $('.section-swipe .summary').css('margin-top', ($('.section-swipe img').height() / 2 - $('.section-swipe .summary').height() / 2 ));
    $('.section-supl .summary').css('margin-top', ($('.section-supl img').height() / 2 - $('.section-supl .summary').height() / 2 ));
});

lastScroll = 0;
shouldAnimate = tre;
lastColo = "#3C9BFF";
shouldSlide = true;
$(window).on('scroll', function(){
    scrollTop = $('body').scrollTop();
    scrollingUp = scrollTop < lastScroll;
    lastScroll = scrollTop;
    heightOfTransition = $('.section-supl').height();

    /*
     suplTop = (scrollTop - $('.section-supl').offset().top) / 14;
     $('.section-supl img').css('top', (suplTop));
     swipeTop = (scrollTop - $('.section-swipe').offset().top) / 14;
     $('.section-swipe img').css('top', (swipeTop));
     */

    if  ($('.section-supl').offset().top + heightOfTransition - heightOfTransition / 3 - scrollTop < 0 && lastColor != "#FF3D97" && scrollingUp == false && shouldAnimate ) {
        lastColor = "#FF3D97";
        shouldAnimate = false;
        jQuery(".content").animate({
            backgroundColor: "#FF3D97"
        }, 1500 );
        setTimeout(function(){
            shouldAnimate = true
        },1500);
    }
    else if ($('.section-supl').offset().top + heightOfTransition + heightOfTransition / 3 - scrollTop > 0 && lastColor != "#3C9BFF" && scrollingUp && shouldAnimate) {
        lastColor = "#3C9BFF";
        shouldAnimate = false;
        jQuery(".content").animate({
            backgroundColor: "#3C9BFF"
        }, 1500 );
        setTimeout(function(){
            shouldAnimate = true
        },1500);
    }

    if (scrollTop >= $('.section-me').offset().top - $('.section-me').height() && shouldSlide) {
        $('.slide').addClass('animated fadeInUp');
        shouldSlide = false;
    }

});

$('.portfolio-link').click(function() {
    body = $('body');
    scrollTop = body.scrollTop();
    body.animate({scrollTop : $('.section-supl').offset().top}, 600);
});

$('#about-link').click(function() {
    body = $('body');
    scrollTop = body.scrollTop();
    body.animate({scrollTop : $('.section-me').offset().top}, 600);
});

<commit_msg>Fixes<commit_after>/*
 * Created by marekfort on 13/04/16.
 */

$(document).ready(function(){
    // Setting summary to be centered to the iphone mockup
    $('.section-swipe .summary').css('margin-top', ($('.section-swipe img').height() / 2 - $('.section-swipe .summary').height() / 2 ));
    $('.section-supl .summary').css('margin-top', ($('.section-supl img').height() / 2 - $('.section-supl .summary').height() / 2 ));
});

lastScroll = 0;
shouldAnimate = true;
lastColor = "#3C9BFF";
shouldSlide = true;
$(window).on('scroll', function(){
    scrollTop = $('body').scrollTop();
    scrollingUp = scrollTop < lastScroll;
    lastScroll = scrollTop;
    heightOfTransition = $('.section-supl').height();

    /*
     suplTop = (scrollTop - $('.section-supl').offset().top) / 14;
     $('.section-supl img').css('top', (suplTop));
     swipeTop = (scrollTop - $('.section-swipe').offset().top) / 14;
     $('.section-swipe img').css('top', (swipeTop));
     */

    if  ($('.section-supl').offset().top + heightOfTransition - heightOfTransition / 3 - scrollTop < 0 && lastColor != "#FF3D97" && scrollingUp == false && shouldAnimate ) {
        lastColor = "#FF3D97";
        shouldAnimate = false;
        jQuery(".content").animate({
            backgroundColor: "#FF3D97"
        }, 1500 );
        setTimeout(function(){
            shouldAnimate = true
        },1500);
    }
    else if ($('.section-supl').offset().top + heightOfTransition + heightOfTransition / 3 - scrollTop > 0 && lastColor != "#3C9BFF" && scrollingUp && shouldAnimate) {
        lastColor = "#3C9BFF";
        shouldAnimate = false;
        jQuery(".content").animate({
            backgroundColor: "#3C9BFF"
        }, 1500 );
        setTimeout(function(){
            shouldAnimate = true
        },1500);
    }

    if (scrollTop >= $('.section-me').offset().top - $('.section-me').height() && shouldSlide) {
        $('.slide').addClass('animated fadeInUp');
        shouldSlide = false;
    }

});

$('.portfolio-link').click(function() {
    body = $('body');
    scrollTop = body.scrollTop();
    body.animate({scrollTop : $('.section-supl').offset().top}, 600);
});

$('#about-link').click(function() {
    body = $('body');
    scrollTop = body.scrollTop();
    body.animate({scrollTop : $('.section-me').offset().top}, 600);
});

<|endoftext|>


<commit_before>var socket = io.connect();
var $dele = $('#dele');
var $button1 = $('#button1');var counter=0;var moves=0;var gamecount=1;var playersname;var iden;
var visited1=0;
var visited2=0;
var visited3=0;
var visited4=0;
var visited5=0;
var visited6=0;
var visited7=0;
var visited8=0;
var visited9=0;
var ismoved=0;
var $button2 = $('#button2');
var $available=$('#available');
var $reset=$('#reset');
var $joinarea=$('#joinarea');
var $gamearea=$('#gamearea');
var $users=$('#users');
var $spot1=$('#spot1');
var $spot2=$('#spot2');
var $spot3=$('#spot3');
var $spot4=$('#spot4');
var $spot5=$('#spot5');
var $spot6=$('#spot6');
var $spot7=$('#spot7');
var $spot8=$('#spot8');
var $spot9=$('#spot9');
socket.on('available',function(data){
var html2='';
for(var i=0;i<data.length;i++)
{
html2+='
Game id:  '+data[i].id+'
';
}
$available.html(html2);
});
$button1.click(function(e){
e.preventDefault();
mbox.prompt("Enter Your name",function(result){
    socket.emit('create',result);
});
socket.on('created',function(data){
  $joinarea.hide();
  $gamearea.show();
    iden=data.id;
  var html1='
Game id:  '+data.id+'
';var list=data.list; var html2='';
  for(i=0;i<list.length;i++)
  {
    html2+='
'+list[i]+'
';
  }
  html1+=html2;
  $users.html(html1);
});
});
$button2.click(function(e){
e.preventDefault();
mbox.prompt("enter the id of game you want to enter:",function(result){
    socket.emit('join',result);
    socket.on('player2name',function(data){
      mbox.prompt("enter your name:",function(result){
        if(result)
        {socket.emit('gamestart',result);}
      });
    });
});
});

socket.on('joined',function(data){
$joinarea.hide();
$gamearea.show();
    iden=data.id;
var html1='
Game id:  '+data.id+'
';var list=data.list; var html2='';
for(i=0;i<list.length;i++)
{
  html2+='
'+list[i]+'
';
}
html1+=html2;
$users.html(html1);
  socket.emit('namelist',gamecount);
});

$dele.click(function(e){
    socket.emit('disconnect',{id:iden});
    socket.disconnect();
    location.reload();

});
socket.on('display',function(data){
var html1='
Game id:  '+data.id+'
';var list=data.list; var html2='';
for(i=0;i<list.length;i++)
{
  html2+='
'+list[i]+'
';
}
html1+=html2;
$users.html(html1);
});
socket.on('firstmove',function(data){
mbox.alert(data[1]+" will make the first move",function(err,result){
  if (err) throw err;
});
});
$spot1.click(function(){
    if(visited1==0)
    {
  if(counter==0)
  {document.getElementById("spot1").innerHTML ="O";counter=counter+1;}
  else {
    document.getElementById("spot1").innerHTML = "X";counter=counter-1;
  }
   visited1=1;
  socket.emit('check',{id:iden,area:"spot1",counter:counter,moves:moves,visited:visited1});

    }

});
socket.on('checked',function(data){
   data.visited=1;
if(data.counter==0)
{document.getElementById(data.area).innerHTML="X";}
else {
  document.getElementById(data.area).innerHTML="O";
}
    document.getElementById(data.area).click(false);
counter=data.counter;moves=data.moves+1;
if(($spot1.text()=="X"&&$spot2.text()=="X"&&$spot3.text()=="X")||($spot4.text()=="X"&&$spot5.text()=="X"&&$spot6.text()=="X")||($spot7.text()=="X"&&$spot8.text()=="X"&&$spot9.text()=="X")||($spot1.text()=="X"&&$spot4.text()=="X"&&$spot7.text()=="X")
||($spot2.text()=="X"&&$spot5.text()=="X"&&$spot8.text()=="X")||($spot3.text()=="X"&&$spot6.text()=="X"&&$spot9.text()=="X")||($spot1.text()=="X"&&$spot5.text()=="X"&&$spot9.text()=="X")||($spot3.text()=="X"&&$spot5.text()=="X"&&$spot7.text()=="X"))
{
  console.log("chal jaa na yaar");
    moves=0;counter=0;
  mbox.alert(playersname[(data.gamecount+1)%2]+" won the game!!..Press Reset to start new game",function(err,result){
    if (err) throw err;
  });
}
else if(($spot1.text()=="O"&&$spot2.text()=="O"&&$spot3.text()=="O")||($spot4.text()=="O"&&$spot5.text()=="O"&&$spot6.text()=="O")||($spot7.text()=="O"&&$spot8.text()=="O"&&$spot9.text()=="O")||($spot1.text()=="O"&&$spot4.text()=="O"&&$spot7.text()=="O")
||($spot2.text()=="O"&&$spot5.text()=="O"&&$spot8.text()=="O")||($spot3.text()=="O"&&$spot6.text()=="O"&&$spot9.text()=="O")||($spot1.text()=="O"&&$spot5.text()=="O"&&$spot9.text()=="O")||($spot3.text()=="O"&&$spot5.text()=="O"&&$spot7.text()=="O"))
{
    console.log("chal jaa na yaar");
    moves=0;counter=0;
    mbox.alert(playersname[data.gamecount]+" won the game!!..Press Reset to start new game",function(err,result){
      if (err) throw err;
    });
}
else if(moves==9)
{
  console.log("chal jaa na yaar");
  socket.emit('draw',{id:iden,gamecount:gamecount});
  mbox.alert("the game resulted in draw",function(err,result){
    if (err) throw err;
    mbox.alert("Press Reset to start new game",function(err,result){
      if (err) throw err;
    });
  });
    socket.emit('namelist',{id:iden,gamecount:gamecount});
}
});
socket.on('newgame1',function(data){
moves=0;counter=0;
});
$reset.click(function(e){
e.preventDefault();
$spot1.empty();$spot2.empty();$spot3.empty();$spot4.empty();$spot5.empty();$spot6.empty();$spot7.empty();$spot8.empty();$spot9.empty();
gamecount=gamecount+1;gamecount=gamecount%2;
    visited1=0;visited2=0;visited3=0;visited4=0;visited5=0;visited6=0;visited7=0;visited8=0;visited9=0;
mbox.alert(playersname[gamecount]+" will make first move",function(err,result){
  if (err) throw err;
});
});
socket.on('gotnamelist',function(data){
  playersname=data.list;
});
$spot2.click(function(){
     if(visited2==0)
    {
  if(counter==0)
  {document.getElementById("spot2").innerHTML ="O";counter=counter+1;}
  else {
    document.getElementById("spot2").innerHTML = "X";counter=counter-1;
  }
      visited2=1;
  socket.emit('check',{id:iden,area:"spot2",counter:counter,moves:moves,visited:visited2});

    }
  });
$spot3.click(function(){
     if(visited3==0)
    {
  if(counter==0)
  {document.getElementById("spot3").innerHTML ="O";counter=counter+1;}
  else {
    document.getElementById("spot3").innerHTML = "X";counter=counter-1;
  }
     visited3=1;
  socket.emit('check',{id:iden,area:"spot3",counter:counter,moves:moves,visited:visited3});

    }

});
$spot4.click(function(){
     if(visited4==0)
    {
  if(counter==0)
  {document.getElementById("spot4").innerHTML ="O";counter=counter+1;}
  else {
    document.getElementById("spot4").innerHTML = "X";counter=counter-1;
  }
     visited4=1;
  socket.emit('check',{id:iden,area:"spot4",counter:counter,moves:moves,visited:visited4});

    }
});
$spot5.click(function(){
     if(visited5==0)
    {
  if(counter==0)
  {document.getElementById("spot5").innerHTML ="O";counter=counter+1;}
  else {
    document.getElementById("spot5").innerHTML = "X";counter=counter-1;
  }
      visited5=1;
  socket.emit('check',{id:iden,area:"spot5",counter:counter,moves:moves,visited:visited5});

    }
});
$spot6.click(function(){
     if(visited6==0)
    {
  if(counter==0)
  {document.getElementById("spot6").innerHTML ="O";counter=counter+1;}
  else {
    document.getElementById("spot6").innerHTML = "X";counter=counter-1;
  }
      visited6=1;
  socket.emit('check',{id:iden,area:"spot6",counter:counter,moves:moves,visited:visited6});

    }
});
$spot7.click(function(){
     if(visited7==0)
    {
  if(counter==0)
  {document.getElementById("spot7").innerHTML ="O";counter=counter+1;}
  else {
    document.getElementById("spot7").innerHTML = "X";counter=counter-1;
  }
       visited7=1;
  socket.emit('check',{id:iden,area:"spot7",counter:counter,moves:moves,visited:visited7});

    }
                });
$spot8.click(function(){
     if(visited8==0)
    {
  if(counter==0)
  {document.getElementById("spot8").innerHTML ="O";counter=counter+1;}
  else {
    document.getElementById("spot8").innerHTML = "X";counter=counter-1;
  }
     visited8=1;
  socket.emit('check',{id:iden,area:"spot8",counter:counter,moves:moves,visited:visited8});

    }
                });
$spot9.click(function(){
     if(visited9==0)
    {
  if(counter==0)
  {document.getElementById("spot9").innerHTML ="O";counter=counter+1;}
  else {
    document.getElementById("spot9").innerHTML = "X";counter=counter-1;
  }
    visited9=1;
  socket.emit('check',{id:iden,area:"spot9",counter:counter,moves:moves,visited:visited9});

    }

});
socket.on('reset',function(data){counter=0;moves=0;gamecount=1;
$spot1.empty();$spot2.empty();$spot3.empty();$spot4.empty();$spot5.empty();$spot6.empty();$spot7.empty();$spot8.empty();$spot9.empty();
visited1=0;visited2=0;visited3=0;visited4=0;visited5=0;visited6=0;visited7=0;visited8=0;visited9=0;
                                });
<commit_msg>kamlss<commit_after>var socket = io.connect();
var $dele = $('#dele');
var $button1 = $('#button1');var counter=0;var moves=0;var gamecount=1;var playersname;var iden;
var visited1=0;
var visited2=0;
var visited3=0;
var visited4=0;
var visited5=0;
var visited6=0;
var visited7=0;
var visited8=0;
var visited9=0;
var ismoved=0;
var $button2 = $('#button2');
var $available=$('#available');
var $reset=$('#reset');
var $joinarea=$('#joinarea');
var $gamearea=$('#gamearea');
var $users=$('#users');
var $spot1=$('#spot1');
var $spot2=$('#spot2');
var $spot3=$('#spot3');
var $spot4=$('#spot4');
var $spot5=$('#spot5');
var $spot6=$('#spot6');
var $spot7=$('#spot7');
var $spot8=$('#spot8');
var $spot9=$('#spot9');
socket.on('available',function(data){
var html2='';
for(var i=0;i<data.length;i++)
{
html2+='
Game id:  '+data[i].id+'
';
}
$available.html(html2);
});
$button1.click(function(e){
e.preventDefault();
mbox.prompt("Enter Your name",function(result){
    socket.emit('create',result);
});
socket.on('created',function(data){
  $joinarea.hide();
  $gamearea.show();
    iden=data.id;
  var html1='
Game id:  '+data.id+'
';var list=data.list; var html2='';
  for(i=0;i<list.length;i++)
  {
    html2+='
'+list[i]+'
';
  }
  html1+=html2;
  $users.html(html1);
});
});
$button2.click(function(e){
e.preventDefault();
mbox.prompt("enter the id of game you want to enter:",function(result){
    socket.emit('join',result);
    socket.on('player2name',function(data){
      mbox.prompt("enter your name:",function(result){
        if(result)
        {socket.emit('gamestart',result);}
      });
    });
});
});

socket.on('joined',function(data){
$joinarea.hide();
$gamearea.show();
    iden=data.id;
var html1='
Game id:  '+data.id+'
';var list=data.list; var html2='';
for(i=0;i<list.length;i++)
{
  html2+='
'+list[i]+'
';
}
html1+=html2;
$users.html(html1);
  socket.emit('namelist',gamecount);
});

$dele.click(function(e){
    socket.emit('disconnect',{id:iden});
    socket.disconnect();
    location.reload();

});
socket.on('display',function(data){
var html1='
Game id:  '+data.id+'
';var list=data.list; var html2='';
for(i=0;i<list.length;i++)
{
  html2+='
'+list[i]+'
';
}
html1+=html2;
$users.html(html1);
});
socket.on('firstmove',function(data){
mbox.alert(data[1]+" will make the first move",function(err,result){
  if (err) throw err;
});
});
$spot1.click(function(){
    if(visited1==0)
    {
  if(counter==0)
  {document.getElementById("spot1").innerHTML ="O";counter=counter+1;}
  else {
    document.getElementById("spot1").innerHTML = "X";counter=counter-1;
  }
   visited1=1;
  socket.emit('check',{id:iden,area:"spot1",counter:counter,moves:moves,visited:visited1});

    }

});
socket.on('checked',function(data){
   data.visited=1;
if(data.counter==0)
{document.getElementById(data.area).innerHTML="X";}
else {
  document.getElementById(data.area).innerHTML="O";
}
    document.getElementById(data.area).click(false);
counter=data.counter;moves=data.moves+1;
if(($spot1.text()=="X"&&$spot2.text()=="X"&&$spot3.text()=="X")||($spot4.text()=="X"&&$spot5.text()=="X"&&$spot6.text()=="X")||($spot7.text()=="X"&&$spot8.text()=="X"&&$spot9.text()=="X")||($spot1.text()=="X"&&$spot4.text()=="X"&&$spot7.text()=="X")
||($spot2.text()=="X"&&$spot5.text()=="X"&&$spot8.text()=="X")||($spot3.text()=="X"&&$spot6.text()=="X"&&$spot9.text()=="X")||($spot1.text()=="X"&&$spot5.text()=="X"&&$spot9.text()=="X")||($spot3.text()=="X"&&$spot5.text()=="X"&&$spot7.text()=="X"))
{
  console.log("chal jaa na yaar");
    moves=0;counter=0;
  mbox.alert(playersname[(gamecount+1)%2]+" won the game!!..Press Reset to start new game",function(err,result){
    if (err) throw err;
  });
}
else if(($spot1.text()=="O"&&$spot2.text()=="O"&&$spot3.text()=="O")||($spot4.text()=="O"&&$spot5.text()=="O"&&$spot6.text()=="O")||($spot7.text()=="O"&&$spot8.text()=="O"&&$spot9.text()=="O")||($spot1.text()=="O"&&$spot4.text()=="O"&&$spot7.text()=="O")
||($spot2.text()=="O"&&$spot5.text()=="O"&&$spot8.text()=="O")||($spot3.text()=="O"&&$spot6.text()=="O"&&$spot9.text()=="O")||($spot1.text()=="O"&&$spot5.text()=="O"&&$spot9.text()=="O")||($spot3.text()=="O"&&$spot5.text()=="O"&&$spot7.text()=="O"))
{
    console.log("chal jaa na yaar");
    moves=0;counter=0;
    mbox.alert(playersname[gamecount]+" won the game!!..Press Reset to start new game",function(err,result){
      if (err) throw err;
    });
}
else if(moves==9)
{
  console.log("chal jaa na yaar");
  socket.emit('draw',{id:iden,gamecount:gamecount});
  mbox.alert("the game resulted in draw",function(err,result){
    if (err) throw err;
    mbox.alert("Press Reset to start new game",function(err,result){
      if (err) throw err;
    });
  });
    socket.emit('namelist',{id:iden,gamecount:gamecount});
}
});
socket.on('newgame1',function(data){
moves=0;counter=0;
});
$reset.click(function(e){
e.preventDefault();
$spot1.empty();$spot2.empty();$spot3.empty();$spot4.empty();$spot5.empty();$spot6.empty();$spot7.empty();$spot8.empty();$spot9.empty();
data.gamecount=data.gamecount+1;data.gamecount=data.gamecount%2;
    visited1=0;visited2=0;visited3=0;visited4=0;visited5=0;visited6=0;visited7=0;visited8=0;visited9=0;
mbox.alert(playersname[data.gamecount]+" will make first move",function(err,result){
  if (err) throw err;
});
});
socket.on('gotnamelist',function(data){
  playersname=data.list;
});
$spot2.click(function(){
     if(visited2==0)
    {
  if(counter==0)
  {document.getElementById("spot2").innerHTML ="O";counter=counter+1;}
  else {
    document.getElementById("spot2").innerHTML = "X";counter=counter-1;
  }
      visited2=1;
  socket.emit('check',{id:iden,area:"spot2",counter:counter,moves:moves,visited:visited2});

    }
  });
$spot3.click(function(){
     if(visited3==0)
    {
  if(counter==0)
  {document.getElementById("spot3").innerHTML ="O";counter=counter+1;}
  else {
    document.getElementById("spot3").innerHTML = "X";counter=counter-1;
  }
     visited3=1;
  socket.emit('check',{id:iden,area:"spot3",counter:counter,moves:moves,visited:visited3});

    }

});
$spot4.click(function(){
     if(visited4==0)
    {
  if(counter==0)
  {document.getElementById("spot4").innerHTML ="O";counter=counter+1;}
  else {
    document.getElementById("spot4").innerHTML = "X";counter=counter-1;
  }
     visited4=1;
  socket.emit('check',{id:iden,area:"spot4",counter:counter,moves:moves,visited:visited4});

    }
});
$spot5.click(function(){
     if(visited5==0)
    {
  if(counter==0)
  {document.getElementById("spot5").innerHTML ="O";counter=counter+1;}
  else {
    document.getElementById("spot5").innerHTML = "X";counter=counter-1;
  }
      visited5=1;
  socket.emit('check',{id:iden,area:"spot5",counter:counter,moves:moves,visited:visited5});

    }
});
$spot6.click(function(){
     if(visited6==0)
    {
  if(counter==0)
  {document.getElementById("spot6").innerHTML ="O";counter=counter+1;}
  else {
    document.getElementById("spot6").innerHTML = "X";counter=counter-1;
  }
      visited6=1;
  socket.emit('check',{id:iden,area:"spot6",counter:counter,moves:moves,visited:visited6});

    }
});
$spot7.click(function(){
     if(visited7==0)
    {
  if(counter==0)
  {document.getElementById("spot7").innerHTML ="O";counter=counter+1;}
  else {
    document.getElementById("spot7").innerHTML = "X";counter=counter-1;
  }
       visited7=1;
  socket.emit('check',{id:iden,area:"spot7",counter:counter,moves:moves,visited:visited7});

    }
                });
$spot8.click(function(){
     if(visited8==0)
    {
  if(counter==0)
  {document.getElementById("spot8").innerHTML ="O";counter=counter+1;}
  else {
    document.getElementById("spot8").innerHTML = "X";counter=counter-1;
  }
     visited8=1;
  socket.emit('check',{id:iden,area:"spot8",counter:counter,moves:moves,visited:visited8});

    }
                });
$spot9.click(function(){
     if(visited9==0)
    {
  if(counter==0)
  {document.getElementById("spot9").innerHTML ="O";counter=counter+1;}
  else {
    document.getElementById("spot9").innerHTML = "X";counter=counter-1;
  }
    visited9=1;
  socket.emit('check',{id:iden,area:"spot9",counter:counter,moves:moves,visited:visited9});

    }

});
socket.on('reset',function(data){counter=0;moves=0;gamecount=1;
$spot1.empty();$spot2.empty();$spot3.empty();$spot4.empty();$spot5.empty();$spot6.empty();$spot7.empty();$spot8.empty();$spot9.empty();
visited1=0;visited2=0;visited3=0;visited4=0;visited5=0;visited6=0;visited7=0;visited8=0;visited9=0;
                                });
<|endoftext|>


<commit_before>/*
 * The main class of the Pedigree Editor, responsible for initializing all the basic elements of the app.
 * Contains wrapper methods for the most commonly used functions.
 * This class should be initialized only once.
 */
var PedigreeEditor = Class.create({

//Graphical attributes for graphical elements in the editor
    attributes: {
        radius: 40,
        unbornShape: {'font-size': 50, 'font-family': 'Cambria'},
        nodeShape: {fill: "0-#ffffff:0-#B8B8B8:100", stroke: "#595959"},
        boxOnHover : {fill: "gray", stroke: "none",opacity: 1, "fill-opacity":.25},
        menuBtnIcon : {fill: "#1F1F1F", stroke: "none"},
        deleteBtnIcon : {fill: "#990000", stroke: "none"},
        btnMaskHoverOn : {opacity:.6, stroke: 'none'},
        btnMaskHoverOff : {opacity:0},
        btnMaskClick: {opacity:1},
        orbHue : .53,
        phShape: {fill: "white","fill-opacity": 0, "stroke": 'black', "stroke-dasharray": "- "},
        dragMeLabel: {'font-size': 14, 'font-family': 'Tahoma'},
        descendantGroupLabel: {'font-size': 20, 'font-family': 'Tahoma'},
        label: {'font-size': 18, 'font-family': 'Cambria'},
        disorderShapes: {},
        partnershipRadius: 6,
        partnershipLines : {"stroke-width": 2, stroke : '#2E2E56'}
    },

    /*
     * Initializes the workspace, menu, top menu-bar, child creation bubble, legend, layout and the Raphael elements.
     */
    initialize: function() {
        this.DEBUG_MODE = false;
        window.editor = this;

        this._workspace = new Workspace();
        this._nodeMenu = this.generateNodeMenu();
        this._partnershipMenu = this.generatePartnershipMenu();
        this._nodeTypeOptions = new NodeTypeOptions();
        this._legend = new Legend();
        this._nodeIndex = new NodeIndex();
        this._graph = new Graph();
        this._actionStack = new ActionStack();
        this._saveLoadEngine = new SaveLoadEngine();
        this._templateSelector = new TemplateSelector();

        var undoButton = $('action-undo');
        undoButton && undoButton.on("click", function(event) {
            editor.getActionStack().undo();
        });
        var redoButton = $('action-redo');
        redoButton && redoButton.on("click", function(event) {
            editor.getActionStack().redo();
        });

        var saveButton = $('action-save');
        saveButton && saveButton.on("click", function(event) {
            editor.getSaveLoadEngine().serialize();
        });

        var loadButton = $('action-load');
        loadButton && loadButton.on("click", function(event) {
            editor.getSaveLoadEngine().load();
        });

        var templatesButton = $('action-templates');
        templatesButton && templatesButton.on("click", function(event) {
            editor.getTemplateSelector().show();
        });
    },

    getNode: function(nodeID) {
        return editor.getGraph().getNodeMap()[nodeID];
    },

    /*
     * Returns the Graph object, responsible for managing nodes in the editor
     */
    getGraph: function() {
        return this._graph;
    },

    getActionStack: function() {
        return this._actionStack;
    },

    /*
     * Returns the menu object
     */
    getNodeMenu: function() {
        return this._nodeMenu;
    },

    /*
     * Returns the NodeTypeOptions object
     */
    getNodeTypeOptions: function() {
        return this._nodeTypeOptions;
    },

    /*
     * Returns the NodeIndex object responsible for the graphical layout of nodes
     */
    getNodeIndex: function() {
        return this._nodeIndex;
    },

    /*
     * Returns the Workspace object responsible managing the canvas
     */
    getWorkspace: function() {
        return this._workspace;
    },

    /*
     * Returns the Legend object responsible for managing and displaying the disorder legend
     */
    getLegend: function() {
        return this._legend;
    },

    /*
     * Returns the Raphael paper object
     */
    getPaper: function() {
        return this.getWorkspace().getPaper();
    },

    /**
     * Returns the engine for saving and loading
     *
     * @method getSaveLoadEngine
     * @return {SaveLoadEngine}
     */
    getSaveLoadEngine: function() {
        return this._saveLoadEngine;
    },

    /**
     * Returns the window for template selection
     *
     * @method getTemplateSelector
     * @return {TemplateSelector}
     */
    getTemplateSelector: function() {
        return this._templateSelector
    },

    /*
     * Creates and returns the menu for Person nodes
     */
    generateNodeMenu: function() {
        var _this = this;
        document.observe('mousedown', function(event) {
            if (_this.getNodeMenu() && _this.getNodeMenu().isActive()) {
                if (event.element().getAttribute('class') != 'menu-trigger' &&
                    (!event.element().up || !event.element().up('.menu-box, .calendar_date_select, .suggestItems') && event.element().up('body'))) {
                    _this.getNodeMenu().hide();
                }
            }
        });
        return new NodeMenu([
            {
                'name' : 'identifier',
                'label' : '',
                'type'  : 'hidden'
            },
            {
                'name' : 'gender',
                'label' : 'Gender',
                'type' : 'radio',
                'values' : [
                    { 'actual' : 'M', 'displayed' : 'Male' },
                    { 'actual' : 'F', 'displayed' : 'Female' },
                    { 'actual' : 'U', 'displayed' : 'Unknown' }
                ],
                'default' : 'U',
                'function' : 'setGenderAction'
            },
            {
                'name' : 'first_name',
                'label': 'First name',
                'type' : 'text',
                'function' : 'setFirstNameAction'
            },
            {
                'name' : 'last_name',
                'label': 'Last name',
                'type' : 'text',
                'function' : 'setLastNameAction'
            },
            {
                'name' : 'date_of_birth',
                'label' : 'Date of birth',
                'type' : 'date-picker',
                'format' : 'dd/MM/yyyy',
                'function' : 'setBirthDateAction'
            },
            {
                'name' : 'date_of_death',
                'label' : 'Date of death',
                'type' : 'date-picker',
                'format' : 'dd/MM/yyyy',
                'function' : 'setDeathDateAction'
            },
            {
                'name' : 'disorders',
                'label' : 'Known disorders of this individual',
                'type' : 'disease-picker',
                'function' : 'setDisordersAction'
            },
            {
                'name' : 'gestation_age',
                'label' : 'Gestation age',
                'type' : 'select',
                'range' : {'start': 0, 'end': 50, 'item' : ['week', 'weeks']},
                'nullValue' : true,
                'function' : 'setGestationAgeAction'
            },
            {
                'name' : 'state',
                'label' : 'Individual is',
                'type' : 'radio',
                'values' : [
                    { 'actual' : 'alive', 'displayed' : 'Alive' },
                    { 'actual' : 'deceased', 'displayed' : 'Deceased' },
                    { 'actual' : 'stillborn', 'displayed' : 'Stillborn' },
                    { 'actual' : 'aborted', 'displayed' : 'Aborted' },
                    { 'actual' : 'unborn', 'displayed' : 'Unborn' }
                ],
                'default' : 'alive',
                'function' : 'setLifeStatusAction'
            },
            {
                'label' : 'Heredity options',
                'name' : 'childlessSelect',
                'values' : [{'actual': 'none', displayed: 'None'},{'actual': 'childless', displayed: 'Childless'},{'actual': 'infertile', displayed: 'Infertile'}],
                'type' : 'select',
                'function' : 'setChildlessStatusAction'
            },
            {
                'name' : 'childlessText',
                'type' : 'text',
                'dependency' : 'childlessSelect != none',
                'tip' : 'Reason',
                'function' : 'setChildlessReasonAction'
            },
            {
                'name' : 'adopted',
                'label' : 'Adopted',
                'type' : 'checkbox',
                'function' : 'setAdoptedAction'
            }
        ]);
    },

    /*
     * Returns the menu of the partnership node
     */
    getPartnershipMenu: function() {
        return this._partnershipMenu;
    },

    /*
     * Creates and returns the menu for Partnership nodes
     */
    generatePartnershipMenu: function() {
        var _this = this;
        document.observe('mousedown', function(event) {
            if (_this.getPartnershipMenu() && _this.getPartnershipMenu().isActive()) {
                if (event.element().getAttribute('class') != 'menu-trigger' &&
                    (!event.element().up || !event.element().up('.menu-box, .calendar_date_select, .suggestItems') && event.element().up('body'))) {
                    _this.getPartnershipMenu().hide();
                }
            }
        });
        return new NodeMenu([
            {
                'label' : 'Heredity options',
                'name' : 'childlessSelect',
                'values' : [{'actual': 'none', displayed: 'None'},{'actual': 'childless', displayed: 'Childless'},{'actual': 'infertile', displayed: 'Infertile'}],
                'type' : 'select',
                'function' : 'setChildlessStatusAction'
            },
            {
                'name' : 'childlessText',
                'type' : 'text',
                'dependency' : 'childlessSelect != none',
                'tip' : 'Reason',
                'function' : 'setChildlessReasonAction'
            }
        ]);
    },

    initializeSave: function() {
        setInterval(function(){editor.getGraph().serialize()},30000);
    },

    // WRAPPERS FOR THE NODE INDEX & GRID FUNCITONS
    getGridUnitX : function () {
      return this.getNodeIndex().gridUnit.x;
    },

    getGridUnitY : function () {
      return this.getNodeIndex().gridUnit.y;
    },

    findPosition : function (relativeNodePosition, ids) {
      return this.getNodeIndex().findPosition(relativeNodePosition, ids);
    }
});

var editor;

document.observe("dom:loaded",function() {
    editor = new PedigreeEditor();
});
<commit_msg>added user-triggered template selector<commit_after>/*
 * The main class of the Pedigree Editor, responsible for initializing all the basic elements of the app.
 * Contains wrapper methods for the most commonly used functions.
 * This class should be initialized only once.
 */
var PedigreeEditor = Class.create({

//Graphical attributes for graphical elements in the editor
    attributes: {
        radius: 40,
        unbornShape: {'font-size': 50, 'font-family': 'Cambria'},
        nodeShape: {fill: "0-#ffffff:0-#B8B8B8:100", stroke: "#595959"},
        boxOnHover : {fill: "gray", stroke: "none",opacity: 1, "fill-opacity":.25},
        menuBtnIcon : {fill: "#1F1F1F", stroke: "none"},
        deleteBtnIcon : {fill: "#990000", stroke: "none"},
        btnMaskHoverOn : {opacity:.6, stroke: 'none'},
        btnMaskHoverOff : {opacity:0},
        btnMaskClick: {opacity:1},
        orbHue : .53,
        phShape: {fill: "white","fill-opacity": 0, "stroke": 'black', "stroke-dasharray": "- "},
        dragMeLabel: {'font-size': 14, 'font-family': 'Tahoma'},
        descendantGroupLabel: {'font-size': 20, 'font-family': 'Tahoma'},
        label: {'font-size': 18, 'font-family': 'Cambria'},
        disorderShapes: {},
        partnershipRadius: 6,
        partnershipLines : {"stroke-width": 2, stroke : '#2E2E56'}
    },

    /*
     * Initializes the workspace, menu, top menu-bar, child creation bubble, legend, layout and the Raphael elements.
     */
    initialize: function() {
        this.DEBUG_MODE = false;
        window.editor = this;

        this._workspace = new Workspace();
        this._nodeMenu = this.generateNodeMenu();
        this._partnershipMenu = this.generatePartnershipMenu();
        this._nodeTypeOptions = new NodeTypeOptions();
        this._legend = new Legend();
        this._nodeIndex = new NodeIndex();
        this._graph = new Graph();
        this._actionStack = new ActionStack();
        this._saveLoadEngine = new SaveLoadEngine();
        this._startupTemplateSelector = new TemplateSelector(true);
        this._templateSelector = new TemplateSelector();

        var undoButton = $('action-undo');
        undoButton && undoButton.on("click", function(event) {
            editor.getActionStack().undo();
        });
        var redoButton = $('action-redo');
        redoButton && redoButton.on("click", function(event) {
            editor.getActionStack().redo();
        });

        var saveButton = $('action-save');
        saveButton && saveButton.on("click", function(event) {
            editor.getSaveLoadEngine().serialize();
        });

        var loadButton = $('action-load');
        loadButton && loadButton.on("click", function(event) {
            editor.getSaveLoadEngine().load();
        });

        var templatesButton = $('action-templates');
        templatesButton && templatesButton.on("click", function(event) {
            editor.getTemplateSelector().show();
        });
    },

    getNode: function(nodeID) {
        return editor.getGraph().getNodeMap()[nodeID];
    },

    /*
     * Returns the Graph object, responsible for managing nodes in the editor
     */
    getGraph: function() {
        return this._graph;
    },

    getActionStack: function() {
        return this._actionStack;
    },

    /*
     * Returns the menu object
     */
    getNodeMenu: function() {
        return this._nodeMenu;
    },

    /*
     * Returns the NodeTypeOptions object
     */
    getNodeTypeOptions: function() {
        return this._nodeTypeOptions;
    },

    /*
     * Returns the NodeIndex object responsible for the graphical layout of nodes
     */
    getNodeIndex: function() {
        return this._nodeIndex;
    },

    /*
     * Returns the Workspace object responsible managing the canvas
     */
    getWorkspace: function() {
        return this._workspace;
    },

    /*
     * Returns the Legend object responsible for managing and displaying the disorder legend
     */
    getLegend: function() {
        return this._legend;
    },

    /*
     * Returns the Raphael paper object
     */
    getPaper: function() {
        return this.getWorkspace().getPaper();
    },

    /**
     * Returns the engine for saving and loading
     *
     * @method getSaveLoadEngine
     * @return {SaveLoadEngine}
     */
    getSaveLoadEngine: function() {
        return this._saveLoadEngine;
    },

    /**
     * Returns the template selector which appears on startup
     *
     * @method getStartupTemplateSelector
     * @return {TemplateSelector}
     */
    getStartupTemplateSelector: function() {
        return this._startupTemplateSelector
    },

    /**
     * Returns the user triggered template selector
     *
     * @method getTemplateSelector
     * @return {TemplateSelector}
     */
    getTemplateSelector: function() {
        return this._templateSelector
    },

    /*
     * Creates and returns the menu for Person nodes
     */
    generateNodeMenu: function() {
        var _this = this;
        document.observe('mousedown', function(event) {
            if (_this.getNodeMenu() && _this.getNodeMenu().isActive()) {
                if (event.element().getAttribute('class') != 'menu-trigger' &&
                    (!event.element().up || !event.element().up('.menu-box, .calendar_date_select, .suggestItems') && event.element().up('body'))) {
                    _this.getNodeMenu().hide();
                }
            }
        });
        return new NodeMenu([
            {
                'name' : 'identifier',
                'label' : '',
                'type'  : 'hidden'
            },
            {
                'name' : 'gender',
                'label' : 'Gender',
                'type' : 'radio',
                'values' : [
                    { 'actual' : 'M', 'displayed' : 'Male' },
                    { 'actual' : 'F', 'displayed' : 'Female' },
                    { 'actual' : 'U', 'displayed' : 'Unknown' }
                ],
                'default' : 'U',
                'function' : 'setGenderAction'
            },
            {
                'name' : 'first_name',
                'label': 'First name',
                'type' : 'text',
                'function' : 'setFirstNameAction'
            },
            {
                'name' : 'last_name',
                'label': 'Last name',
                'type' : 'text',
                'function' : 'setLastNameAction'
            },
            {
                'name' : 'date_of_birth',
                'label' : 'Date of birth',
                'type' : 'date-picker',
                'format' : 'dd/MM/yyyy',
                'function' : 'setBirthDateAction'
            },
            {
                'name' : 'date_of_death',
                'label' : 'Date of death',
                'type' : 'date-picker',
                'format' : 'dd/MM/yyyy',
                'function' : 'setDeathDateAction'
            },
            {
                'name' : 'disorders',
                'label' : 'Known disorders of this individual',
                'type' : 'disease-picker',
                'function' : 'setDisordersAction'
            },
            {
                'name' : 'gestation_age',
                'label' : 'Gestation age',
                'type' : 'select',
                'range' : {'start': 0, 'end': 50, 'item' : ['week', 'weeks']},
                'nullValue' : true,
                'function' : 'setGestationAgeAction'
            },
            {
                'name' : 'state',
                'label' : 'Individual is',
                'type' : 'radio',
                'values' : [
                    { 'actual' : 'alive', 'displayed' : 'Alive' },
                    { 'actual' : 'deceased', 'displayed' : 'Deceased' },
                    { 'actual' : 'stillborn', 'displayed' : 'Stillborn' },
                    { 'actual' : 'aborted', 'displayed' : 'Aborted' },
                    { 'actual' : 'unborn', 'displayed' : 'Unborn' }
                ],
                'default' : 'alive',
                'function' : 'setLifeStatusAction'
            },
            {
                'label' : 'Heredity options',
                'name' : 'childlessSelect',
                'values' : [{'actual': 'none', displayed: 'None'},{'actual': 'childless', displayed: 'Childless'},{'actual': 'infertile', displayed: 'Infertile'}],
                'type' : 'select',
                'function' : 'setChildlessStatusAction'
            },
            {
                'name' : 'childlessText',
                'type' : 'text',
                'dependency' : 'childlessSelect != none',
                'tip' : 'Reason',
                'function' : 'setChildlessReasonAction'
            },
            {
                'name' : 'adopted',
                'label' : 'Adopted',
                'type' : 'checkbox',
                'function' : 'setAdoptedAction'
            }
        ]);
    },

    /*
     * Returns the menu of the partnership node
     */
    getPartnershipMenu: function() {
        return this._partnershipMenu;
    },

    /*
     * Creates and returns the menu for Partnership nodes
     */
    generatePartnershipMenu: function() {
        var _this = this;
        document.observe('mousedown', function(event) {
            if (_this.getPartnershipMenu() && _this.getPartnershipMenu().isActive()) {
                if (event.element().getAttribute('class') != 'menu-trigger' &&
                    (!event.element().up || !event.element().up('.menu-box, .calendar_date_select, .suggestItems') && event.element().up('body'))) {
                    _this.getPartnershipMenu().hide();
                }
            }
        });
        return new NodeMenu([
            {
                'label' : 'Heredity options',
                'name' : 'childlessSelect',
                'values' : [{'actual': 'none', displayed: 'None'},{'actual': 'childless', displayed: 'Childless'},{'actual': 'infertile', displayed: 'Infertile'}],
                'type' : 'select',
                'function' : 'setChildlessStatusAction'
            },
            {
                'name' : 'childlessText',
                'type' : 'text',
                'dependency' : 'childlessSelect != none',
                'tip' : 'Reason',
                'function' : 'setChildlessReasonAction'
            }
        ]);
    },

    initializeSave: function() {
        setInterval(function(){editor.getGraph().serialize()},30000);
    },

    // WRAPPERS FOR THE NODE INDEX & GRID FUNCITONS
    getGridUnitX : function () {
      return this.getNodeIndex().gridUnit.x;
    },

    getGridUnitY : function () {
      return this.getNodeIndex().gridUnit.y;
    },

    findPosition : function (relativeNodePosition, ids) {
      return this.getNodeIndex().findPosition(relativeNodePosition, ids);
    }
});

var editor;

document.observe("dom:loaded",function() {
    editor = new PedigreeEditor();
});
<|endoftext|>


<commit_before>$( document ).ready(function() {
    Parse.initialize("A74VDEFq9sVeu9RaOLs0C2B4QxSEnlqQLsrtesZc", "4LrgyWjfgo9ujUUVkUQpVJZo2YiqzbVRc4b7ue26");

    var country;

	$("#upload").click(function(){

		var validCountries = ["America", "Mexico", "China", "India", "Japan", "Britain", "France", "Russia", "Greece", "Australlia" ];
		var validCols = ["food", "manners", "recreation", "beliefs", "appearance"];

		var countryName = $("#country").val();
		var col = $("#col").val().toLowerCase();
		var linkVal = $("#link").val();
		var descriptionVal = $("#description").val();

		var isValidCountry = false;
		var isValidCols = true;

		for(var i = 0; i < validCountries.length; i++){
			if(validCountries[i] == countryName)
				isValidCountry = true;
		}
		for(var i = 0; i < validCols.length; i++){
			if(validCols[i] == col){
				isValidCols = true;
			}
		}

		if(isValidCols && isValidCountry){
			var Extension = Parse.Object.extend(countryName);
			country = new Extension();

			country.save({foo: col}).then(function(object) {
			});
			country.save({link: linkVal}).then(function(object) {
			});
			country.save({description: descriptionVal}).then(function(object) {
			});
		} else {
			alert("Nope. Check country and col");
		}
	});

});<commit_msg>Revert b108dd5..2f7a1eb<commit_after>$( document ).ready(function() {
    Parse.initialize("A74VDEFq9sVeu9RaOLs0C2B4QxSEnlqQLsrtesZc", "4LrgyWjfgo9ujUUVkUQpVJZo2YiqzbVRc4b7ue26");

    var country;

	$("#upload").click(function(){

		var validCountries = ["America", "Mexico", "China", "India", "Japan", "Britain", "France", "Russia", "Greece", "Australlia" ];
		var validCols = ["food", "manners", "recreation", "beliefs", "appearance"];

		var countryName = $("#country").val();
		var col = $("#col").val().toLowerCase();
		var link = $("#link").val();
		var description = $("#description").val();

		var isValidCountry = false;
		var isValidCols = true;

		for(var i = 0; i < validCountries.length; i++){
			if(validCountries[i] == countryName)
				isValidCountry = true;
		}
		for(var i = 0; i < validCols.length; i++){
			if(validCols[i] == col){
				isValidCols = true;
			}
		}

		if(isValidCols && isValidCountry){
			var Extension = Parse.Object.extend(countryName);
			country = new Extension();

			country.save({foo: col}).then(function(object) {
			});
			country.save({link: link}).then(function(object) {
			});
			country.save({description: description}).then(function(object) {
			});
		} else {
			alert("Nope. Check country and col");
		}
	});

});<|endoftext|>