From da2e680a2828fb37229e1b45d9896846866eb733 Mon Sep 17 00:00:00 2001 From: Chris McKenzie Date: Thu, 5 Jan 2017 04:30:25 -0800 Subject: [PATCH] refactoring --- index.html | 2 +- js/deps/db.js | 1701 ------------------------------------- js/deps/db.min.js | 2 + js/deps/evda.js | 1450 ------------------------------- js/deps/evda.min.js | 2 + js/deps/underscore-min.js | 6 - 6 files changed, 5 insertions(+), 3158 deletions(-) delete mode 100644 js/deps/db.js create mode 100644 js/deps/db.min.js delete mode 100644 js/deps/evda.js create mode 100644 js/deps/evda.min.js delete mode 100644 js/deps/underscore-min.js diff --git a/index.html b/index.html index 8974ad2..aee4ebc 100644 --- a/index.html +++ b/index.html @@ -342,4 +342,4 @@

Search For a Video
- + diff --git a/js/deps/db.js b/js/deps/db.js deleted file mode 100644 index f797615..0000000 --- a/js/deps/db.js +++ /dev/null @@ -1,1701 +0,0 @@ -// -// db.js Javascript Database -// https://github.com/kristopolous/db.js -// -// Copyright 2011 - 2016, Chris McKenzie -// Dual licensed under the MIT or GPL Version 2 licenses. -// -// Looking under the hood are you? What a fun place to be. -// -// Let's break this down: -// -// 1. since there are no dependencies, I have to have nice -// underscore and jquery like things myself. -// -// 2. A few database specific tricks. -// -// 3. Trace and debug handlers -// -// 4. Now we get into the core top level functions. These -// run agnostic of a specific database and work -// holistically. They include things like find. -// -// 5. The database instance. -// -// 6. Finally a hook that exposes the internal functions -// outward, plus a few other inline ones that don't get -// used internally. -var module = module || {}, - DB = module.exports = (function(){ - 'use strict'; - var - // undefined - _u, - - // prototypes and short cuts - slice = Array.prototype.slice, - toString = Object.prototype.toString, - - // system caches - _orderCache = {}, - - _compProto = {}, - - // For computing set differences - _stainID = 0, - _stainKey = '_4ab92bf03191c585f182', - - // type checking system - _ = { - // from underscore.js { - isFun: function(obj) { return !!(obj && obj.constructor && obj.call && obj.apply) }, - isStr: function(obj) { return !!(obj === '' || (obj && obj.charCodeAt && obj.substr)) }, - isNum: function(obj) { return toString.call(obj) === '[object Number]' }, - isUndef: function(obj) { return isNaN(obj) || (obj === null) || (obj === _u) }, - isScalar: function(obj) { return _.isStr(obj) || _.isNum(obj) || _.isBool(obj) }, - isArr: [].isArray || function(obj) { return toString.call(obj) === '[object Array]' }, - isBool: function(obj){ - return obj === true || obj === false || toString.call(obj) === '[object Boolean]'; - }, - // } end underscore.js - // from jquery 1.5.2's type - isObj: function( obj ){ - if(_.isFun(obj) || _.isStr(obj) || _.isNum(obj) || _.isArr(obj)) { - return false; - } - return obj == null ? - String( obj ) === 'object' : - toString.call(obj) === '[object Object]' || true ; - } - }, - - proxy = function(what, caller) { - return function() { - caller.apply(what, slice.call(arguments)); - } - }, - - // functions that may have native shortcuts - indexOf = [].indexOf ? - function(array, item) { - return array.indexOf(item) - } : - - function(array, item) { - for(var i = array.length - 1; - (i !== -1) && (item !== array[i]); - i-- - ) {}; - - return i; - }, - - keys = Object.keys || function (obj) { - var ret = []; - - for(var key in obj) { - ret.push(key); - } - - return ret; - }, - - values = function (obj) { - var ret = []; - - for(var key in obj) { - ret.push(obj[key]); - } - - return ret; - }, - - obj = function(key, value) { - var ret = {}; - ret[key] = value; - return ret; - }, - - mapSoft = function(array, cb) { - var ret = []; - - for ( var i = 0, len = array.length; i < len; i++ ) { - ret.push(cb(array[i], i)); - } - - return ret; - }, - - map = [].map ? - function(array, cb) { - return array.map(cb) - } : mapSoft, - - _filterThrow = function(fun/*, thisArg*/) { - - var len = this.length; - for (var i = 0; i < len; i++) { - if (fun(this[i])) { - throw this[i]; - } - } - return []; - }, - - _filter = function(fun/*, thisArg*/) { - - var len = this.length, start = 0, res = []; - - for (var i = 0; i < len; i++) { - if (!fun(this[i])) { - if(start !== i) { - //res = res.concat(this.slice(start, i)); - res.splice.apply(res, [i,i].concat(this.slice(start, i))); - } - start = i + 1; - } - } - if(start !== i) { - res.splice.apply(res, [i,i].concat(this.slice(start, i))); - } - - return res; - }, - - // each is a complex one - each = [].forEach ? - function (obj, cb) { - // Try to return quickly if there's nothing to do. - if (_.isArr(obj)) { - if(obj.length === 0) { return; } - obj.forEach(cb); - } else if(_.isStr(obj) || _.isNum(obj) || _.isBool(obj)) { - cb(obj); - } else { - for( var key in obj ) { - cb(key, obj[key]); - } - } - } : - - function (obj, cb) { - // Try to return quickly if there's nothing to do. - if (obj.length === 0) { return; } - if (_.isArr(obj)) { - for ( var i = 0, len = obj.length; i < len; i++ ) { - cb(obj[i], i); - } - } else { - for( var key in obj ) { - cb(key, obj[key]); - } - } - }; - - // from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions - function escapeRegExp(string){ - return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); - } - - // This is from underscore. It's a <> object merge. - function extend(obj) { - each(slice.call(arguments, 1), function(source) { - if (source) { - for (var prop in source) { - obj[prop] = source[prop]; - } - } - }); - return obj; - } - - function kvarg(which){ - var ret = {}; - - if(which.length === 2) { - ret[which[0]] = which[1]; - return ret; - } - - if(which.length === 1) { - return which[0]; - } - } - - function hash(array) { - var ret = {}; - - each(array, function(index) { - ret[index] = true; - }); - - return ret; - } - - // We create basic comparator prototypes to avoid evals - each('< <= > >= == === != !=='.split(' '), function(which) { - _compProto[which] = Function( - 'rhs', - 'return function(x){return x' + which + 'rhs}' - ) - }); - - function trace(obj, cb) { - // if no parameters are provided, then trace all the - // databases from this point onward. - if(!obj || _.isBool(obj)) { - trace.active = (arguments.length === 0) ? !trace.active : obj; - if(cb) { - trace.cb = cb; - } - return trace.active; - } - // This prevents trace from being called on - // one object twice, which would lead to infinite - // recursion. - if(obj.__trace__) { - return; - } - - obj.__trace__ = {}; - var level = 0; - - each(obj, function(func, value) { - if(_.isFun(value)) { - obj.__trace__[func] = value; - - obj[func] = function() { - level ++; - - var - args = slice.call(arguments), - log = [func].concat(args); - - if(cb) { - cb({ - "this": this, - "args": args, - "func": func, - "level": level - }); - } else { - // trying to desperately make useful output - trace.l %= 500; - console.log(trace.l, log); - trace[trace.l++] = log; - } - - var res = obj.__trace__[func].apply(this, args); - - level --; - return res; - } - } - }); - } - trace.l = 0; - trace.active = false; - - function copy(obj) { - // we need to call slice for array-like objects, such as the dom - return 'length' in obj ? slice.call(obj) : values(obj); - } - - // These function accept index lists. - function setdiff(larger, subset) { - var ret = []; - - stain(subset); - - for(var ix = 0, len = larger.length; ix < len; ix++) { - if (isStained(larger[ix])) { - unstain(larger[ix]); - continue; - } - ret.push(larger[ix]); - } - - return ret; - } - - - // - // "Staining" is my own crackpot algorithm of comparing - // two unsorted lists of pointers that reference shared - // objects. We go through list one, affixing a unique - // constant value to each of the members. Then we go - // through list two and see if the value is there. - // - // This has to be done rather atomically as the value - // can easily be replaced by something else. It's an - // N + M cost... - // - function stain(list) { - _stainID++; - - each(list, function(el) { - el[_stainKey] = _stainID; - }); - } - - function unstain(obj) { - delete obj[_stainKey]; - } - - function isStained(obj) { - return obj[_stainKey] === _stainID; - } - - // The first parameter, if exists, is assumed to be the value in the database, - // which has a content of arrays, to search. - // The second parameter is the index to search - function has(param1, param2) { - var - len = arguments.length, - compare = len === 1 ? param1 : param2, - callback, - obj = {}; - - if(_.isArr(compare)) { - var len = compare.length; - - // This becomes O(N * M) - callback = function(key) { - for(var ix = 0; ix < len; ix++) { - if (indexOf(key, compare[ix]) > -1) { - return true; - } - } - return false; - } - } else { - // This is O(N) - callback = function(key) { - return indexOf(key, compare) > -1; - } - } - - if(len === 2) { - obj = {}; - obj[param1] = callback; - return obj; - } else { - return callback; - } - } - function val_comprehension(value) { - // this permits mongo-like invocation - if( _.isObj(value)) { - var - _key = keys(value)[0], - _fn = _key.slice(1); - - // see if the routine asked for exists - try { - value = DB[_fn](value[_key]); - } catch(ex) { - throw new Error(_fn + " is an unknown function"); - } - } else if( _.isArr(value)) { - // a convenience isin short-hand. - value = isin(value); - } - - return value; - } - - function find() { - var - filterList = slice.call(arguments), - filterComp_len, - filter, - filterIx, - filterComp, - - which, - val, - - // The dataset to compare against - set = (_.isArr(this) ? this : filterList.shift()); - - if( filterList.length === 2 && _.isStr( filterList[0] )) { - // This permits find(key, value) - which = {}; - which[filterList[0]] = filterList[1]; - filterList = [which]; - } - - for(filterIx = 0; filterIx < filterList.length; filterIx++) { - filter = filterList[filterIx]; - - // if we are looking at an array, then this acts as an OR, which means - // that we just recursively do this. - if(_.isArr(filter)) { - // If there are two arguments, and the first one isn't a function - // then it acts as a comparison of multiple keys, such as - // - // (['key1', 'key2', 'key3'], 'any of them can equal this') - // - if(_.isScalar(filter[0]) && filterList.length === 2) { - // remove it from the list so it doesn't get - // a further comprehension - var filterkey_compare = val_comprehension(filterList.pop()); - - filterComp = [function(row) { - for(var ix = 0; ix < filter.length; ix++) { - if(equal(row[filter[ix]], filterkey_compare)) { - return true; - } - } - }]; - } else { - filterComp = map(filter, expression()); - } - //self.fComp = filterComp; - - filterComp_len = filterComp.length; - set = _filter.call(set, function(row) { - // this satisfies the base case. - var ret = true; - for (var ix = 0; ix < filterComp_len; ix++) { - if(filterComp[ix](row)) { - return true; - } - ret = false; - } - return ret; - }); - } else if(_.isFun(filter)) { - set = _filter.call(set, filter); - } else { - each(filter, function(key, value) { - value = val_comprehension(value); - - if( _.isFun(value)) { - filterComp = function(which) { - // Check for existence - if( key in which ) { - val = which[key]; - - // Permit mutator events - if( _.isFun(val) ) { val = val(); } - - return value(val, which); - } - } - } else { - filterComp = function(which) { - val = which[key]; - - if( _.isFun(val) ) { val = val(); } - - // Check for existence - return (key in which && val === value ); - }; - } - set = _filter.call(set, filterComp); - }); - } - } - - return set; - } - - // - // missing - // - // Missing is to get records that have keys not defined - // - function missing(arg) { - var fieldList = hash(arg); - - return function(record) { - for(var field in fieldList) { - if(field in record) { - return false; - } - } - return true; - }; - } - - // - // isin - // - // This is like the SQL "in" operator, which is a reserved JS word. You can invoke it either - // with a static array or a callback - var isin = (function() { - - // todo: typecheck each element and then extract functions - return function (param1, param2) { - var - callback, - len = arguments.length, - compare = len === 1 ? param1 : (param2 || []), - dynamicList = [], - staticList = [], - obj = {}; - - // If the second argument is an array then we assume that we are looking - // to see if the value in the database is part of the user supplied funciton - if(!_.isArr(compare)) { - throw new TypeError("isin's argument is wrong. ", compare); - } - if(compare.length){ - each(compare, function(what) { - if(_.isFun(what)) { - dynamicList.push(what); - } else { - staticList.push(what); - } - }); - - callback = function(x) { - var res = indexOf(staticList, x) > -1; - for(var ix = 0; ix < dynamicList.length; ix++) { - if(res) { break; } - res = dynamicList[ix](x); - } - return res; - }; - } else if (_.isFun(compare)) { - callback = function(x) { return indexOf(compare(), x) > -1; }; - } else { - callback = compare; - } - - if(len === 2) { - obj = {}; - obj[param1] = callback; - return obj; - } else { - return callback; - } - } - })(); - - function equal(lhs, rhs) { - // If they are strictly equal or - return (lhs === rhs) || ( - // if it's a function and using the parameter of - // lhs makes the rhs function return true - (_.isFun(rhs) && rhs(lhs)) - // or if they are arrays and equal - || !_.isUndef(lhs) && ( - (lhs.join && rhs.join) && - (lhs.sort().toString() === rhs.sort().toString()) - ) - || (JSON.stringify(lhs) === JSON.stringify(rhs)) - ); - } - - function isArray(what) { - var asString = what.sort().join(''); - return function(param) { - return param.sort().join('') === asString; - } - } - - function like(param1, param2) { - var - compare, - len = arguments.length, - query, - queryRE, - obj = {}; - - if(len === 1) { - query = param1; - } else if(len === 2){ - query = param2; - } - - query = query.toString(); - - compare = function(x) { - if(x === null) { - return false; - } - - try { - queryRE = new RegExp(query, 'img'); - } catch (ex) { - queryRE = new RegExp(escapeRegExp(query), 'img'); - } - - return x.toString().search(queryRE) > -1; - } - - if(len === 2) { - obj = {}; - obj[param1] = compare; - return obj; - } else { - return compare; - } - } - - function update(arg0, arg1) { - var key, filter = this; - - // This permits update(key, value) on a chained find - if( arg1 !== _u ) { - - // Store the key string - key = arg0; - - // The constraint is actually the new value to be - // assigned. - arg0 = {}; - arg0[key] = arg1; - } - - if(_.isFun(arg0)) { - each(filter, arg0); - } else { - // {a: blah, b: blah} - each(arg0, function(key, value) { - // {a: function(){ return }} - if(_.isFun( value )) { - // take each item from the filter (filtered results) - // and then apply the value function to it, storing - // back the results - each(filter, function(which) { - if(_.isFun(which[key])) { - - which[key]( value(which) ); - } else { - which[key] = value(which); - } - }); - } else { - // otherwise, assign the static - each(filter, function(which) { - if(_.isFun(which[key])) { - which[key]( value ); - } else { - which[key] = value; - } - }); - } - }); - } - - return this; - } - - function not( lambda ) { - return function() { - return !lambda.apply(this, arguments); - } - } - - var _fCache = {}, _eCache = {}; - function ewrap(arg, str) { - var key = str + ":" + arg; - if(!(key in _eCache)) { - try { - _eCache[key] = eval('(function(' + arg +'){' + str + '})'); - } catch(ex) { - _eCache[key] = false; - } - } - return _eCache[key]; - } - - function fwrap(arg, str) { - var key = str + ":" + arg; - if(!(key in _fCache)) { - try { - _fCache[key] = new Function(arg, "try{return " + str + "}catch(e){}"); - } catch(ex) { - _fCache[key] = false; - } - } - return _fCache[key]; - } - - var expression = function () { - - return function(arg0, arg1) { - var ret, expr; - - if(_.isStr( arg0 )) { - expr = arg0; - - // - // There are TWO types of lambda function here (I'm not using the - // term 'closure' because that means something else) - // - // We can have one that is sensitive to a specific record member and - // one that is local to a record and not a specific member. - // - // As it turns out, we can derive the kind of function intended simply - // because they won't ever syntactically both be valid in real use cases. - // - // I mean sure, the empty string, space, semicolon etc is valid for both, - // alright sure, thanks smarty pants. But is that what you are using? really? - // - // No? ok, me either. This seems practical then. - // - // The invocation wrapping will also make this work magically, with proper - // expressive usage. - // - if(arguments.length === 2 && _.isStr(arg1)) { - expr = arg1; - ret = fwrap("x,rec", "x." + arg0 + expr); - - // if not, fall back on it - ret[arg0] = fwrap("x,rec", "x " + expr); - } else { - ret = fwrap("x,rec", "x " + expr); - - if(!ret) { - ret = fwrap("rec", arg0); - } - } - - return ret; - } else if (_.isObj( arg0 )) { - - var - cList = [], - fnList = [], - val; - - for(var key in arg0) { - val = arg0[key]; - if(_.isScalar(val)) { - if(_.isStr(val)) { - val = '"' + val + '"'; - } - cList.push("rec['" + key + "']===" + val); - } else if(_.isArr(val)) { - fnList.push(isin(key, val)); - } else { - cList.push("equal(rec['" + key + "'],arg0['" + key + "'])"); - } - }; - - if(cList.length) { - fnList.push(ewrap('rec,arg0', 'return ' + cList.join('&&'))); - } - - return function(rec,arg0) { - var val, key, fn; - - for(var ix = 0; ix < fnList.length; ix++) { - val = fnList[ix]; - - if(_.isObj(val)) { - key = keys(val)[0]; - fn = val[key]; - - if(_.isArr(fn)) { - if (indexOf(fn, rec[key]) === -1) { - return false; - } - } else if(!fn(rec[key])) { - return false; - } - } else if(!val(rec,arg0)) { - return false; - } - } - - return true; - } - } - } - } - - function eachRun(callback, arg1) { - var - context = 0, - ret = [], - filter; - - if(arguments.length === 2) { - filter = callback; - callback = arg1; - } else { - filter = _.isArr(this) ? this : this.find(); - } - - if(_.isArr(callback) && callback.length === 2) { - context = callback[0]; - callback = callback[1]; - } - - if(_.isArr(filter)) { - ret = mapSoft(filter, callback); - } else { - ret = {}; - - for(var key in filter) { - if(!_.isFun(filter[key])) { - ret[key] = callback.call(context, filter[key]); - } - } - } - - return ret; - } - - // The list of functions to chain - var chainList = hash([ - 'distinct', - 'each', - 'find', - 'findFirst', - 'first', - 'group', - 'has', - 'hasKey', - 'indexBy', - 'insert', - 'invert', - 'isin', - 'keyBy', - 'lazyView', - 'like', - 'missing', - 'order', - 'orderBy', - 'remove', - 'schema', - 'select', - 'slice', - 'sort', - 'unset', - 'update', - 'view', - 'where' - ]); - - // --- START OF AN INSTANCE ---- - // - // This is the start of a DB instance. - // All the instance local functions - // and variables ought to go here. Things - // that would have been considered "static" - // in a language such as Java or C++ should - // go above!!!! - // - function DB(arg0, arg1){ - var - constraints = {addIf:[]}, - constrainCache = {}, - syncList = [], - syncLock = false, - // - // This is our atomic counter that - // gets moved forward for different - // operations - // - _ix = {ins:0, del:0}, - _template = false, - ret = expression(), - - // globals with respect to this self. - _g = {}, - raw = []; - - function sync() { - if(!syncLock) { - syncLock = true; - each(syncList, function(which) { which.call(ret, raw); }); - syncLock = false; - } - } - - function chain(list) { - for(var func in chainList) { - list[func] = ret[func]; - } - - list.last = list[list.length - 1]; - - return list; - } - - function list2data(list) { - var ret = []; - - for(var ix = 0, len = list.length; ix < len; ix++) { - ret[ix] = raw[list[ix]]; - } - - return ret; - } - - extend(ret, { - - slice: function() { - var filter = _.isArr(this) ? this : ret.find() - - return(chain( slice.apply(filter, arguments) ) ); - }, - - transaction: { - start: function() { - syncLock = true; - }, - end: function(){ - // Have to turn the syncLock off prior to attempting it. - syncLock = false; - sync(); - } - }, - - // This isn't a true schema derivation ... it's a spot check - // over the data-set to try to show a general schema ... since - // this is essentially a schema-less document store there could - // be things missing. - // - schema: function() { - // rand() is slow on android (2013-01) and the entropy - // can have some issues so we don't try doing that. - // The interwebs claims that every 10th sampling is a good - // way to roll, so let's do that. - // - // Js perf says a trivial double for is the way to roll - // with a very slight edge for caching ... although this - // makes no sense whatsoever. - var - agg = {}, - list = _.isArr(this) ? this : ret.find(), - len = list.length, - skip = Math.ceil(Math.min(10, len / 3)), - entry; - - for(var i = 0; i < len; i += skip ) { - entry = list[i]; - - for(var key in entry) { - agg[key] = _u; - } - } - - return keys(agg); - }, - - // - // This is to constrain the database. Currently you can enforce a unique - // key value through something like `db.constrain('unique', 'somekey')`. - // You should probably run this early, as unlike in RDBMSs, it doesn't do - // a historical check nor does it create a optimized hash to index by - // this key ... it just does a lookup every time as of now. - // - constrain: function() { - extend(constraints, kvarg(arguments)); - }, - - // Adds if and only if a function matches a constraint - addIf: function( lambda ) { - if(lambda) { - constraints.addIf.push(lambda); - } - return constraints.addIf; - }, - - // beforeAdd allows you to mutate data prior to insertion. - // It's really an addIf that returns true - beforeAdd: function( lambda ) { - return ret.addIf( - lambda ? - function() { lambda.apply(0, arguments); return true; } - : false - ) - }, - - unset: function callee(key) { - if(_.isArr(key)) { - return each(key, callee) - } else { - var list = _.isArr(this) ? this : ret.find(); - each(list, function(what) { - if(key in what) { - delete what[key]; - } - }); - sync(); - return chain(list); - } - }, - - each: eachRun, - isFunction: _.isFun, - isString: _.isStr, - map: eachRun, - not: not, - - // This is a shorthand to find for when you are only expecting one result. - // A boolean false is returned if nothing is found - findFirst: function(){ - var - realFilter = _filter, - matched = false, - res; - _filter = _filterThrow; - try { - res = ret.find.apply(this, arguments); - } catch(ex) { - res = ex; - matched = true; - } - _filter = realFilter; - - // If we matched, then we did an assignment, - // otherwise we can assume that we got an array back. - return matched ? res : (res.length ? res[0] : false); - }, - - has: has, - - // hasKey is to get records that have keys defined - hasKey: function() { - var - outer = _.isArr(this) ? this : this.find(), - inner = outer.find(missing(slice.call(arguments))); - - return this.invert(inner, outer); - }, - - isin: isin, - like: like, - invert: function(list, second) { return chain(setdiff(second || raw, list || this)); }, - - // Missing is to get records that have keys not defined - missing: function() { - var base = missing(slice.call(arguments)); - return _.isArr(this) ? this.find(base) : base; - }, - - // The callbacks in this list are called - // every time the database changes with - // the raw value of the database. - // - // Note that this is different from the internal - // definition of the sync function, which does the - // actual synchronization - sync: function(callback) { - if(callback) { - syncList.push(callback); - } else { - sync(); - } - return ret; - }, - - template: function(opt) { - _template = opt; - return ret; - }, - - // Update allows you to set newvalue to all - // parameters matching constraint where constraint - // is either a set of K/V pairs or a result - // of find so that you can do something like - // - // Update also can take a callback. - // - // var result = db.find(constraint); - // result.update({a: b}); - // - update: function() { - var list = update.apply( _.isArr(this) ? this : ret.find(), arguments) ; - sync(); - return chain (list); - } - - }); - - extend(ret.template, { - create: ret.template, - update: function(opt) { extend(_template || {}, opt); return ret; }, - get: function() { return _template }, - destroy: function() { _template = false; return ret; } - }); - - ret.first = ret.findFirst; - - // - // group - // - // This is like SQLs groupby function. It will take results from any other function and then - // return them as a hash where the keys are the field values and the results are an array - // of the rows that match that value. - // - ret.group = function() { - var - args = slice.call(arguments || []), - field = args.shift(), - groupMap = {}, - filter = _.isArr(this) ? this : ret.find(); - - each(filter, function(which) { - // undefined is a valid thing. - var entry = (field in which) ? which[field] : [_u]; - each(entry, function(what) { - // if it's an array, then we do each one. - - if(! (what in groupMap) ) { - groupMap[what] = chain([]); - } - - groupMap[what].push(which); - }); - }); - - if(args.length) { - each(groupMap, function(key, value) { - groupMap[key] = ret.group.apply(value, args); - }); - } - - return groupMap; - } - - // - // keyBy - // - // This is like group above but it just maps as a K/V tuple, with - // the duplication policy of the first match being preferred. - // - ret.keyBy = function() { - var groupResult = ret.group.apply(this, arguments); - - each(groupResult, function(key, value) { - groupResult[key] = value[0]; - }); - - return groupResult; - } - - // - // distinct - // - // get an array of the distinct values for a particular key. - // - ret.distinct = function(field) { - return keys(ret.keyBy(field)); - } - - // - // indexBy is just a sort without a chaining of the args - // - ret.indexBy = function () { - // alias chain away - var _chain = chain; - - // make chain a dummy function - chain = function(m) { return m; } - - // set the order output to the raw - ret.__raw__ = raw = ret.order.apply(this, arguments); - - // and then re-assign chain back to the proper place - chain = _chain; - } - - // - // sort - // - // This is like SQLs orderby function. If you pass it just a field, then - // the results are returned in ascending order (x - y). - // - // You can also supply a second parameter of a case insensitive "asc" and "desc" like in SQL. - // - ret.order = ret.sort = ret.orderBy = function (arg0, arg1) { - var - key, - fnSort, - len = arguments.length, - order, - filter = _.isArr(this) ? this : ret.find(); - - if(_.isFun(arg0)) { - fnSort = arg0; - } else if(_.isStr(arg0)) { - key = arg0; - - if(len === 1) { - order = 'x-y'; - } else if(len === 2) { - - if(_.isStr(arg1)) { - order = { - asc: 'x-y', - desc: 'y-x' - }[arg1.toLowerCase()]; - } else { - order = arg1; - } - } - - if(_.isStr(order)) { - if(! _orderCache[order]) { - order = _orderCache[order] = new Function('x,y', 'return ' + order); - } else { - order = _orderCache[order]; - } - } - - eval('fnSort=function(a,b){return order(a.' + key + ', b.' + key + ')}'); - } - return chain(slice.call(filter).sort(fnSort)); - } - - ret.where = ret.find = function() { - var args = slice.call(arguments || []); - - // Addresses test 23 (Finding: Find all elements cascaded, 3 times) - if(!_.isArr(this)) { - args = [raw].concat(args); - } - - return chain( find.apply(this, args) ); - } - - // - // lazyView - // - // lazyViews are a variation of views that have to be explicitly rebuilt - // on demand with () - // - ret.lazyView = function(field, type) { - // keep track - var - myix = {del: _ix.del, ins: _ix.ins}, - res = {}, - keyer; - - if(field.search(/[()]/) === -1) { - if(field.charAt(0) !== '[' || field.charAt(0) !== '.') { - field = '.' + field; - } - - eval( "keyer=function(r,ref){try{ref[rX]=res[rX]=r;}catch(x){}}".replace(/X/g, field)); - } else { - eval( "keyer=function(r,ref){var val=r.X;try{ref[val]=res[val]=r;}catch(x){}}".replace(/X/g, field)); - } - - Object.defineProperty(res, 'update', { - enumerable: false, - configurable: false, - writable: false, - value: function(whence) { - if(whence) { - // if we only care about updating our views - // on a new delete, then we check our atomic - if(whence === 'del' && myix.del === _ix.del) { - return; - } else if(whence === 'ins' && myix.ins === _ix.ins) { - return; - } - } - myix = {del: _ix.del, ins: _ix.ins}; - - var ref = {}; - - each(raw, function(row) { - keyer(row, ref); - }); - - for(var key in res) { - if( ! (key in ref) && key != 'update') { - delete res[key]; - } - } - - Object.defineProperty(res, 'length', { - enumerable: false, - configurable: false, - writable: true, - value: Object.keys(res).length - }); - } - }); - - res.update(); - return res; - }, - - // - // view - // - // Views are an expensive synchronization macro that return - // an object that can be indexed in order to get into the data. - // - ret.view = function(field, type) { - var fn = ret.lazyView(field, type); - ret.sync(fn.update); - return fn; - } - - // - // select - // - // This will extract the values of a particular key from the filtered list - // and then return it as an array or an array of arrays, depending on - // which is relevant for the query. - // - // You can also do db.select(' * ') to retrieve all fields, although the - // key values of these fields aren't currently being returned. - // - ret.select = function(field) { - var - filter = _.isArr(this) ? this : ret.find(), - fieldCount, - resultList = {}; - - if(arguments.length > 1) { - field = slice.call(arguments); - } else if (_.isStr(field)) { - field = [field]; - } - - fieldCount = field.length; - - each(field, function(column, iy) { - if(column === '*') { - resultList = map(filter, values); - } else { - for(var ix = 0, len = filter.length; ix < len; ix++) { - var row = filter[ix]; - - if(column in row){ - if(fieldCount > 1) { - if(!resultList[ix]) { - resultList[ix] = []; - } - resultList[ix][iy] = row[column]; - } else { - resultList[ix] = row[column]; - } - } - } - } - }); - - return chain(values(resultList)); - } - - // - // insert - // - // This is to insert data into the database. You can either insert - // data as a list of arguments, as an array, or as a single object. - // - ret.insert = function(param) { - var - ix, - unique = constraints.unique, - existing = [], - toInsert = [], - ixList = []; - - // - // Parse the args put in. - // - // If it's a comma seperated list then make the - // list to insert all the args - if(arguments.length > 1) { - toInsert = slice.call(arguments); - - // if it was an array, then just assign it. - } else if (_.isArr(param)) { - toInsert = param; - - // otherwise it's one argument and - // we just insert that alone. - } else { - toInsert = [param]; - } - - each(toInsert, function(which) { - // We first check to make sure we *should* be adding this. - var doAdd = true; - - // If the unique field has been set then we do - // a hash search through the constraints to - // see if it's there. - if(unique && (unique in which)) { - - // If the user had opted for a certain field to be unique, - // then we find all the matches to that field and create - // a block list from them. - var key = 'c-' + unique, map_; - // We create a lazyView - if(!_g[key]) { - _g[key] = ret.lazyView(unique); - } else { - // Only update if a delete has happened - _g[key].update('del'); - } - - map_ = _g[key]; - - // This would mean that the candidate to be inserted - // should be rejected because it doesn't satisfy the - // unique constraint established. - if(which[unique] in map_){ - - // Create a reference list so we know what was existing - existing.push(map_[which[unique]]); - - // put on the existing value - ixList.push(map_[which[unique]]); - - // Toggle our doAdd over to false. - doAdd = false; - } else { - // Otherwise we assume it will be added and - // put it in our map for future reference. - map_[which[unique]] = which; - } - } - - each(constraints.addIf, function(test) { - // Make sure that our candidate passes all tests. - doAdd &= test(which); - }); - - if(!doAdd) { - return; - } - // if we got here then we can update - // our dynamic counter. - _ix.ins++; - - // If we get here, then the data is going in. - ix = raw.length; - - // insert from a template if available - if(_template) { - var instance = {}; - - // create a template instance that's capable - // of holding evaluations - each(_template, function(key, value) { - if(_.isFun(value)) { - instance[ key ] = value(); - } else { - instance[ key ] = value; - } - }); - - // map the values to be inserted upon - // the instance of this template - which = extend(instance, which); - } - - raw.push(which); - - ixList.push(ix); - }); - - sync(); - - return extend( - chain(list2data(ixList)), - {existing: existing} - ); - } - - // - // The quickest way to do an insert. - // This checks for absolutely nothing. - // - ret.flash = function(list) { - ret.__raw__ = raw = raw.concat(list); - } - - // trace self. - ret.trace = function(cb) { - DB.trace(ret, cb); - } - - // - // remove - // - // This will remove the entries from the database but also return them if - // you want to manipulate them. You can invoke this with a constraint. - // - ret.remove = function(arg0) { - var - isDirty = false, - end, start, - list, - save = []; - - if(_.isArr(this)) { list = this; } - else if(_.isArr(arg0)) { list = arg0; } - else if(arguments.length > 0){ - save = ret.find.apply(this, arguments); - if(save.length) { - ret.__raw__ = raw = ret.invert(save); - _ix.del++; - sync(); - } - return chain(save.reverse()); - } - - else { list = ret.find(); } - - stain(list); - - for(var ix = raw.length - 1, end = raw.length; ix >= 0; ix--) { - if (isStained(raw[ix])) { - unstain(raw[ix]); - save.push(raw[ix]); - continue; - } - if(end - (ix + 1)) { - start = ix + 1; - raw.splice(start, end - start); - isDirty = true; - } - end = ix; - } - - start = ix + 1; - if(end - start) { - raw.splice(start, end - start); - isDirty = true; - } - - if(isDirty) { - // If we've spliced, then we sync and update our - // atomic delete counter - _ix.del++; - sync(); - } - return chain(save.reverse()); - } - - // The ability to import a database from somewhere - if (arguments.length === 1) { - if(_.isArr(arg0)) { ret.insert(arg0) } - else if(_.isFun(arg0)) { ret.insert(arg0()) } - else if(_.isStr(arg0)) { return ret.apply(this, arguments) } - else if(_.isObj(arg0)) { - // This is so hokey... - var fails = false; - each(arg0, function(what, args) { - if(!ret[what]) { fails = true } - if(!fails) { - ret[what](args); - } - }); - if(fails) { - ret.insert(arg0); - } - } - } else if(arguments.length > 1) { - ret.insert(slice.call(arguments)); - } - - // Assign this after initialization - ret.__raw__ = raw; - - // we don't register this instance unless - // we are tracing. The reason is because it's - // convenient to use DB as a powerful filtering - // syntax. There shouldn't be a memory cost - // for that convenience. - if(trace.active) { - ret.trace(trace.cb); - } - - return ret; - } - - extend(DB, { - find: find, - expr: expression(), - diff: setdiff, - each: eachRun, - map: map, - not: not, - like: like, - trace: trace, - values: values, - isin: isin, - isArray: isArray, - isString: _.isStr, - isFunction: _.isFun, - - // like expr but for local functions - local: function(){ - return '(function(){ return ' + - DB.apply(this, arguments).toString() + - ';})()'; - }, - - // expensive basic full depth copying. - copy: function(data) { - return map(data, function(what) { - return extend({}, what); - }); - }, - - objectify: function(keyList, values) { - var obj = []; - - each(values, function(row) { - var objRow = {}; - each(keyList, function(key, index) { - objRow[key] = row[index]; - }); - - obj.push(objRow); - - }); - - return obj; - }, - - // This does a traditional left-reduction on a list - // as popular in list comprehension suites common in - // functional programming. - reduceLeft: function(memo, callback) { - if(arguments.length === 1) { - callback = memo; - memo = 0; - } - var lambda = _.isStr(callback) ? new Function("y,x", "return y " + callback) : callback; - - return function(list, opt) { - var reduced = memo; - - for(var ix = 0, len = list.length; ix < len; ix++) { - if(list[ix]) { - reduced = lambda(reduced, list[ix], opt); - } - } - - return reduced; - } - }, - - // This does a traditional right-reduction on a list - // as popular in list comprehension suites common in - // functional programming. - // - reduceRight: function(memo, callback) { - if(arguments.length === 1) { - callback = memo; - memo = 0; - } - callback = DB.reduceLeft(memo, callback); - - return function(list) { - return callback(list.reverse()); - } - } - }); - return DB; -})(); -DB.version='0.0.2.79-20160518'; diff --git a/js/deps/db.min.js b/js/deps/db.min.js new file mode 100644 index 0000000..c5ce95b --- /dev/null +++ b/js/deps/db.min.js @@ -0,0 +1,2 @@ +var module=module||{},DB=module.exports=function(){"use strict";function escapeRegExp(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function extend(r){return each(slice.call(arguments,1),function(n){if(n)for(var e in n)r[e]=n[e]}),r}function kvarg(r){var n={};return 2===r.length?(n[r[0]]=r[1],n):1===r.length?r[0]:void 0}function hash(r){var n={};return each(r,function(r){n[r]=!0}),n}function trace(r,n){if(!r||_.isBool(r))return trace.active=0===arguments.length?!trace.active:r,n&&(trace.cb=n),trace.active;if(!r.__trace__){r.__trace__={};var e=0;each(r,function(t,i){_.isFun(i)&&(r.__trace__[t]=i,r[t]=function(){e++;var i=slice.call(arguments),a=[t].concat(i);n?n({"this":this,args:i,func:t,level:e}):(trace.l%=500,console.log(trace.l,a),trace[trace.l++]=a);var s=r.__trace__[t].apply(this,i);return e--,s})})}}function copy(r){return"length"in r?slice.call(r):values(r)}function setdiff(r,n){var e=[];stain(n);for(var t=0,i=r.length;i>t;t++)isStained(r[t])?unstain(r[t]):e.push(r[t]);return e}function stain(r){_stainID++,each(r,function(r){r[_stainKey]=_stainID})}function unstain(r){delete r[_stainKey]}function isStained(r){return r[_stainKey]===_stainID}function has(r,n){var e,t=arguments.length,i=1===t?r:n,a={};if(_.isArr(i)){var t=i.length;e=function(r){for(var n=0;t>n;n++)if(indexOf(r,i[n])>-1)return!0;return!1}}else e=function(r){return indexOf(r,i)>-1};return 2===t?(a={},a[r]=e,a):e}function val_comprehension(r){if(_.isObj(r)){var n=keys(r)[0],e=n.slice(1);try{r=DB[e](r[n])}catch(t){throw new Error(e+" is an unknown function")}}else _.isArr(r)&&(r=isin(r));return r}function find(){var r,n,e,t,i,a,s=slice.call(arguments),c=_.isArr(this)?this:s.shift();for(2===s.length&&_.isStr(s[0])&&(i={},i[s[0]]=s[1],s=[i]),e=0;ei;i++){if(t[i](n))return!0;e=!1}return e})}else _.isFun(n)?c=_filter.call(c,n):each(n,function(r,n){n=val_comprehension(n),t=_.isFun(n)?function(e){return r in e?(a=e[r],_.isFun(a)&&(a=a()),n(a,e)):void 0}:function(e){return a=e[r],_.isFun(a)&&(a=a()),r in e&&a===n},c=_filter.call(c,t)});return c}function missing(r){var n=hash(r);return function(r){for(var e in n)if(e in r)return!1;return!0}}function equal(r,n){return r===n||_.isFun(n)&&n(r)||!_.isUndef(r)&&r.join&&n.join&&r.sort().toString()===n.sort().toString()||JSON.stringify(r)===JSON.stringify(n)}function isArray(r){var n=r.sort().join("");return function(r){return r.sort().join("")===n}}function like(r,n){var e,t,i,a=arguments.length,s={};if(1===a?t=r:2===a&&(t=n),_.isArr(t)){for(var c=0;c-1},2===a?(s={},s[r]=e,s):e}function update(r,n){var e,t=this;return n!==_u&&(e=r,r={},r[e]=n),_.isFun(r)?each(t,r):each(r,function(r,n){_.isFun(n)?each(t,function(e){_.isFun(e[r])?e[r](n(e)):e[r]=n(e)}):each(t,function(e){_.isFun(e[r])?e[r](n):e[r]=n})}),this}function not(r){return function(){return!r.apply(this,arguments)}}function ewrap(arg,str){var key=str+":"+arg;if(!(key in _eCache))try{_eCache[key]=eval("(function("+arg+"){"+str+"})")}catch(ex){_eCache[key]=!1}return _eCache[key]}function fwrap(r,n){var e=n+":"+r;if(!(e in _fCache))try{_fCache[e]=new Function(r,"try{return "+n+"}catch(e){}")}catch(t){_fCache[e]=!1}return _fCache[e]}function eachRun(r,n){var e,t=0,i=[];if(2===arguments.length?(e=r,r=n):e=_.isArr(this)?this:this.find(),_.isArr(r)&&2===r.length&&(t=r[0],r=r[1]),_.isArr(e))i=mapSoft(e,r);else{i={};for(var a in e)_.isFun(e[a])||(i[a]=r.call(t,e[a]))}return i}function DB(arg0,arg1){function sync(){syncLock||(syncLock=!0,each(syncList,function(r){r.call(ret,raw)}),syncLock=!1)}function chain(r){for(var n in chainList)r[n]=ret[n];return r.last=r[r.length-1],r}function list2data(r){for(var n=[],e=0,t=r.length;t>e;e++)n[e]=raw[r[e]];return n}var constraints={addIf:[]},constrainCache={},syncList=[],syncLock=!1,_ix={ins:0,del:0},_template=!1,ret=expression(),_g={},raw=[];if(extend(ret,{slice:function(){var r=_.isArr(this)?this:ret.find();return chain(slice.apply(r,arguments))},transaction:{start:function(){syncLock=!0},end:function(){syncLock=!1,sync()}},schema:function(){for(var r,n={},e=_.isArr(this)?this:ret.find(),t=e.length,i=Math.ceil(Math.min(10,t/3)),a=0;t>a;a+=i){r=e[a];for(var s in r)n[s]=_u}return keys(n)},constrain:function(){extend(constraints,kvarg(arguments))},addIf:function(r){return r&&constraints.addIf.push(r),constraints.addIf},beforeAdd:function(r){return ret.addIf(r?function(){return r.apply(0,arguments),!0}:!1)},unset:function r(n){if(_.isArr(n))return each(n,r);var e=_.isArr(this)?this:ret.find();return each(e,function(r){n in r&&delete r[n]}),sync(),chain(e)},each:eachRun,isFunction:_.isFun,isString:_.isStr,map:eachRun,not:not,findFirst:function(){var r,n=_filter,e=!1;_filter=_filterThrow;try{r=ret.find.apply(this,arguments)}catch(t){r=t,e=!0}return _filter=n,e?r:r.length?r[0]:!1},has:has,hasKey:function(){var r=_.isArr(this)?this:this.find(),n=r.find(missing(slice.call(arguments)));return this.invert(n,r)},isin:isin,like:like,invert:function(r,n){return chain(setdiff(n||raw,r||this))},missing:function(){var r=missing(slice.call(arguments));return _.isArr(this)?this.find(r):r},sync:function(r){return r?syncList.push(r):sync(),ret},template:function(r){return _template=r,ret},update:function(){var r=update.apply(_.isArr(this)?this:ret.find(),arguments);return sync(),chain(r)}}),extend(ret.template,{create:ret.template,update:function(r){return extend(_template||{},r),ret},get:function(){return _template},destroy:function(){return _template=!1,ret}}),ret.first=ret.findFirst,ret.group=function(){var r=slice.call(arguments||[]),n=r.shift(),e={},t=_.isArr(this)?this:ret.find();return each(t,function(r){var t=n in r?r[n]:[_u];each(t,function(n){n in e||(e[n]=chain([])),e[n].push(r)})}),r.length&&each(e,function(n,t){e[n]=ret.group.apply(t,r)}),e},ret.keyBy=function(){var r=ret.group.apply(this,arguments);return each(r,function(n,e){r[n]=e[0]}),r},ret.distinct=function(r){return keys(ret.keyBy(r))},ret.indexBy=function(){var r=chain;chain=function(r){return r},ret.__raw__=raw=ret.order.apply(this,arguments),chain=r},ret.order=ret.sort=ret.orderBy=function(arg0,arg1){var key,fnSort,len=arguments.length,order,filter=_.isArr(this)?this:ret.find(),list=slice.call(filter);if(_.isFun(arg0))fnSort=arg0;else if(_.isStr(arg0)){if(key=arg0,1===len?order="x-y":2===len&&(order=_.isStr(arg1)?{asc:"x-y",desc:"y-x"}[arg1.toLowerCase()]:arg1),_.isStr(list[0][key])){var _group=ret.group.call(list,key),_sorted=keys(_group).sort(),_args=map(_sorted,function(r){return _group[r]}),_res=Array.prototype.concat.apply([],_args);return"y-x"===order&&(_res=_res.reverse()),_res}_.isStr(order)&&(order=_orderCache[order]?_orderCache[order]:_orderCache[order]=new Function("x,y","return "+order)),eval("fnSort=function(a,b){return order(a."+key+", b."+key+")}")}return chain(list.sort(fnSort))},ret.where=ret.find=function(){var r=slice.call(arguments||[]);return _.isArr(this)||(r=[raw].concat(r)),chain(find.apply(this,r))},ret.lazyView=function(field,type){var myix={del:_ix.del,ins:_ix.ins},res={},keyer;return-1===field.search(/[()]/)?("["===field.charAt(0)&&"."===field.charAt(0)||(field="."+field),eval("keyer=function(r,ref){try{ref[rX]=res[rX]=r;}catch(x){}}".replace(/X/g,field))):eval("keyer=function(r,ref){var val=r.X;try{ref[val]=res[val]=r;}catch(x){}}".replace(/X/g,field)),Object.defineProperty(res,"update",{enumerable:!1,configurable:!1,writable:!1,value:function(r){if(r){if("del"===r&&myix.del===_ix.del)return;if("ins"===r&&myix.ins===_ix.ins)return}myix={del:_ix.del,ins:_ix.ins};var n={};each(raw,function(r){keyer(r,n)});for(var e in res)e in n||"update"==e||delete res[e];Object.defineProperty(res,"length",{enumerable:!1,configurable:!1,writable:!0,value:Object.keys(res).length})}}),res.update(),res},ret.view=function(r,n){var e=ret.lazyView(r,n);return ret.sync(e.update),e},ret.select=function(r){var n,e=_.isArr(this)?this:ret.find(),t={};return arguments.length>1?r=slice.call(arguments):_.isStr(r)&&(r=[r]),n=r.length,each(r,function(r,i){if("*"===r)t=map(e,values);else for(var a=0,s=e.length;s>a;a++){var c=e[a];r in c&&(n>1?(t[a]||(t[a]=[]),t[a][i]=c[r]):t[a]=c[r])}}),chain(values(t))},ret.insert=function(r){var n,e=constraints.unique,t=[],i=[],a=[];return i=arguments.length>1?slice.call(arguments):_.isArr(r)?r:[r],each(i,function(r){var i=!0;if(e&&e in r){var s,c="c-"+e;_g[c]?_g[c].update("del"):_g[c]=ret.lazyView(e),s=_g[c],r[e]in s?(t.push(s[r[e]]),a.push(s[r[e]]),i=!1):s[r[e]]=r}if(each(constraints.addIf,function(n){i&=n(r)}),i){if(_ix.ins++,n=raw.length,_template){var u={};each(_template,function(r,n){_.isFun(n)?u[r]=n():u[r]=n}),r=extend(u,r)}raw.push(r),a.push(n)}}),sync(),extend(chain(list2data(a)),{existing:t})},ret.flash=function(r){ret.__raw__=raw=raw.concat(r)},ret.trace=function(r){DB.trace(ret,r)},ret.remove=function(r){var n,e,t,i=!1,a=[];if(_.isArr(this))t=this;else if(_.isArr(r))t=r;else{if(arguments.length>0)return a=ret.find.apply(this,arguments),a.length&&(ret.__raw__=raw=ret.invert(a),_ix.del++,sync()),chain(a.reverse());t=ret.find()}stain(t);for(var s=raw.length-1,n=raw.length;s>=0;s--)isStained(raw[s])?(unstain(raw[s]),a.push(raw[s])):(n-(s+1)&&(e=s+1,raw.splice(e,n-e),i=!0),n=s);return e=s+1,n-e&&(raw.splice(e,n-e),i=!0),i&&(_ix.del++,sync()),chain(a.reverse())},1===arguments.length)if(_.isArr(arg0))ret.insert(arg0);else if(_.isFun(arg0))ret.insert(arg0());else{if(_.isStr(arg0))return ret.apply(this,arguments);if(_.isObj(arg0)){var fails=!1;each(arg0,function(r,n){ret[r]||(fails=!0),fails||ret[r](n)}),fails&&ret.insert(arg0)}}else arguments.length>1&&ret.insert(slice.call(arguments));return ret.__raw__=raw,trace.active&&ret.trace(trace.cb),ret}var _u,slice=Array.prototype.slice,toString=Object.prototype.toString,_orderCache={},_compProto={},_stainID=0,_stainKey="_4ab92bf03191c585f182",_={isFun:function(r){return!!(r&&r.constructor&&r.call&&r.apply)},isStr:function(r){return!!(""===r||r&&r.charCodeAt&&r.substr)},isNum:function(r){return"[object Number]"===toString.call(r)},isUndef:function(r){return isNaN(r)||null===r||r===_u},isScalar:function(r){return _.isStr(r)||_.isNum(r)||_.isBool(r)},isArr:[].isArray||function(r){return"[object Array]"===toString.call(r)},isBool:function(r){return r===!0||r===!1||"[object Boolean]"===toString.call(r)},isObj:function(r){return _.isFun(r)||_.isStr(r)||_.isNum(r)||_.isArr(r)?!1:null==r?"object"===String(r):"[object Object]"===toString.call(r)||!0}},proxy=function(r,n){return function(){n.apply(r,slice.call(arguments))}},indexOf=[].indexOf?function(r,n){return r.indexOf(n)}:function(r,n){for(var e=r.length-1;-1!==e&&n!==r[e];e--);return e},keys=Object.keys||function(r){var n=[];for(var e in r)n.push(e);return n},values=function(r){var n=[];for(var e in r)n.push(r[e]);return n},obj=function(r,n){var e={};return e[r]=n,e},mapArity=function(r,n){for(var e=[],t=0,i=r.length;i>t;t++)e.push(n.call(0,r[t]));return e},mapSoft=function(r,n,e){for(var t=[],i=0,a=r.length;a>i;i++)t.push(e?n(r[i]):n(r[i],i));return t},map=[].map?function(r,n){return r.map(n)}:mapSoft,_filterThrow=function(r){for(var n=this.length,e=0;n>e;e++)if(r(this[e]))throw this[e];return[]},_filter=function(r){for(var n=this.length,e=0,t=[],i=0;n>i;i++)r(this[i])||(e!==i&&t.splice.apply(t,[i,i].concat(this.slice(e,i))),e=i+1);return e!==i&&t.splice.apply(t,[i,i].concat(this.slice(e,i))),t},each=[].forEach?function(r,n){if(_.isArr(r)){if(0===r.length)return;r.forEach(n)}else if(_.isStr(r)||_.isNum(r)||_.isBool(r))n(r);else for(var e in r)n(e,r[e])}:function(r,n){if(0!==r.length)if(_.isArr(r))for(var e=0,t=r.length;t>e;e++)n(r[e],e);else for(var i in r)n(i,r[i])};each("< <= > >= == === != !==".split(" "),function(r){_compProto[r]=Function("rhs","return function(x){return x"+r+"rhs}")}),trace.l=0,trace.active=!1;var isin=function(){return function(r,n){var e,t=arguments.length,i=1===t?r:n||[],a=[],s=[],c={};if(!_.isArr(i))throw new TypeError("isin's argument is wrong. ",i);return i.length?(each(i,function(r){_.isFun(r)?a.push(r):s.push(r)}),e=function(r){for(var n=indexOf(s,r)>-1,e=0;e-1}:i,2===t?(c={},c[r]=e,c):e}}(),_fCache={},_eCache={},expression=function(){return function(r,n){var e,t;if(_.isStr(r))return t=r,2===arguments.length&&_.isStr(n)?(t=n,e=fwrap("x,rec","x."+r+t),e[r]=fwrap("x,rec","x "+t)):(e=fwrap("x,rec","x "+t),e||(e=fwrap("rec",r))),e;if(_.isObj(r)){var i,a=[],s=[];for(var c in r)i=r[c],_.isScalar(i)?(_.isStr(i)&&(i='"'+i+'"'),a.push("rec['"+c+"']==="+i)):_.isArr(i)?s.push(isin(c,i)):a.push("equal(rec['"+c+"'],arg0['"+c+"'])");return a.length&&s.push(ewrap("rec,arg0","return "+a.join("&&"))),function(r,n){for(var e,t,i,a=0;aa;a++)n[a]&&(i=e(i,n[a],t));return i}},reduceRight:function(r,n){return 1===arguments.length&&(n=r,r=0),n=DB.reduceLeft(r,n),function(r){return n(r.reverse())}}});var any=DB.reduceLeft(0,function(r,n){return r||n});return DB}();DB.version="0.0.2.92-20161021"; +//# sourceMappingURL=db.map.js diff --git a/js/deps/evda.js b/js/deps/evda.js deleted file mode 100644 index 0b14f4c..0000000 --- a/js/deps/evda.js +++ /dev/null @@ -1,1450 +0,0 @@ -// -// EvDa Events and Data -// See EvDa.version at the end for version info. -// -// https://github.com/kristopolous/EvDa -// -// Copyright 2008 - 2016 Chris McKenzie -// Dual licensed under the MIT or GPL Version 2 licenses. -// -var - module = module || {}, - EvDa = module.exports = (function (){ - 'use strict'; - - var - slice = Array.prototype.slice, - - // This is mostly underscore functions here. But they are included to make sure that - // they are supported here without requiring an additional library. - // - // underscore { - toString = Object.prototype.toString, - isArray = [].isArray || function (obj) { return toString.call(obj) === '[object Array]' }, - isFunction = function (obj) { return !!(obj && obj.constructor && obj.call && obj.apply) }, - isString = function (obj) { return !!(obj === '' || (obj && obj.charCodeAt && obj.substr)) }, - isNumber = function (obj) { return toString.call(obj) === '[object Number]' }, - isScalar = function (obj) { return isString(obj) || isNumber(obj) }, - isObject = function (obj) { - if ( isFunction(obj) || isString(obj) || isNumber(obj) || isArray(obj)) { - return false; - } - - return obj == null ? - String ( obj ) === 'object' : - toString.call(obj) === '[object Object]' || true ; - }, - - toArray = function (obj) { - return slice.call(obj); - }, - - each = [].forEach ? - function (obj, cb) { - if ( isScalar(obj)) { - return each([obj], cb); - } else if ( isArray(obj) || obj.length ) { - toArray(obj).forEach(cb); - } else { - for ( var key in obj ) { - cb(key, obj[key]); - } - } - } : - - function (obj, cb) { - if (isScalar(obj)) { - return each([obj], cb); - } else if (isArray(obj)) { - for ( var i = 0, len = obj.length; i < len; i++ ) { - cb(obj[i], i); - } - } else { - for ( var key in obj ) { - cb(key, obj[key]); - } - } - }, - - last = function (obj) { - return obj.length ? obj[obj.length - 1] : undefined; - }, - - values = function (obj) { - var ret = []; - - for (var key in obj) { - ret.push(obj[key]); - } - - return ret; - }, - - keys = ({}).keys || function (obj) { - if ( isArray(obj) ) { - return obj; - } - var ret = []; - - for ( var key in obj ) { - ret.push(key); - } - - return ret; - }, - - without = function (collection, item) { - var ret = []; - each(collection, function (which) { - if (which !== item) { - ret.push(which); - } - }); - return ret; - }, - - uniq = function (obj) { - var - old, - ret = []; - - each(keys(obj).sort(), function (which) { - if (which != old) { - old = which; - ret.push(which); - } - }); - return ret; - }, - - select = function (obj, test) { - var ret = []; - each(obj, function (which) { - if (test(which)) { ret.push (which); } - }); - return ret; - }, - - size = function (obj) { - return (obj && 'length' in obj) ? obj.length : 0; - }, - - map = [].map ? - function (array, cb) { - return array.map(cb) - } : - - function (array, cb) { - var ret = []; - - for ( var i = 0, len = array.length; i < len; i++ ) { - ret.push(cb(array[i], i)); - } - - return ret; - }, - - clone = function (obj) { - if (isArray(obj)) { return slice.call(obj); } - if (isObject(obj)) { return extend(obj, {}); } - return obj; - }, - - extend = function (obj) { - each(slice.call(arguments, 1), function (source) { - for (var prop in source) { - if (source[prop] !== void 0) { - - // This recursively assigns - /* - if ( isObject(source[prop]) && isObject(obj[prop]) ) { - extend(obj[prop], source[prop]); - } else { - */ obj[prop] = source[prop]; - //} - } - } - }); - return obj; - }, - - // } end of underscore style functions. - - isGlobbed = function (str) { - return str.match(/[?*]/); - }, - - // This looks to see if a key has a globbing parameter, such - // as ? or * and then return it - glob = function (key, context) { - if (isGlobbed(key)) { - return select(keys(context ? context : data), function (what) { - return what.match(key); - }); - } - return key; - }, - - // This uses the globbing feature and returns - // a "smart" map which is only one element if - // something matches, otherwise a map - smartMap = function (what, cback) { - var ret = {}; - if (isArray(what)) { - each(what, function (field) { - ret[field] = cback(field); - }); - return ret; - - } else { - return cback(what); - } - }, - - // Constants - FIRST = 'first', - ON = 'on', - AFTER = 'after', - TEST = 'test', - OR = 'or', - SET = "set", - stub = function(){ return true }, - typeList = [FIRST, ON, AFTER, TEST, OR], - - // The one time callback gets a property to - // the end of the object to notify our future-selfs - // that we ought to remove the function. - ONCE = {once: 1}; - - var e = function (imported) { - var - lockMap = {}, - testLockMap = {}, - - // Internals - data = {}, - data_ix = {}, - - // the backlog to execute if something is paused. - backlog = [], - globberMap = {}, - traceList = [], - // previous values - logSize = 10, - lastReturnMap = {}, - logMap = {}, - // last return - eventMap = {}, - removedMap = {}, - dbg = { - data: data, - events: eventMap, - removed: removedMap, - log: logMap, - lastReturn: lastReturnMap, - locks: lockMap, - testLocks: testLockMap, - trace: traceList, - globs: globberMap - }; - - // this will try to resolve what the user - // is asking for. - function resolve ( what ) { - if ( what in data ) { - return data[ what ]; - } - - // If the key isn't set then we try to resolve it - // through dot notation. - // ex: a.b.c - var - // [a,b,c] - parts = what.split('.'), - - // c - tail = parts.pop(), - - // a.b - head = parts.join('.'); - - if (head) { - // we try to resolve the head - var res = resolve( head ); - - if ( isObject(res) && tail in res ) { - return res[tail]; - } - } - } - - // This is the main invocation function. After - // you declare an instance and call that instance - // as a function, this is what gets run. - function pub ( scope, value, meta, opts ) { - var args = slice.call( arguments ); - - if ( scope === undefined ) { - throw "Undefined passed in as first argument."; - } - - // If there was one argument, then this is - // either a getter or the object style - // invocation. - if ( isArray(scope) ) { - // remove the scope argument. - args.shift(); - - return map(scope, function (which) { - return pub.apply(pub.context, [which].concat(args)); - }); - } - - // The object style invocation will return - // handles associated with all the keys that - // went in. There *could* be a mix and match - // of callbacks and setters, but that would - // be fine I guess... - if ( isObject(scope) ) { - if ( args.length === 1 && scope.constructor.toString().search(/{\s+\[native code\]\s+}/) === -1 ) { - pub.context = scope; - return; - } - - var ret = {}; - - // - // Object style should be executed as a transaction - // to avoid ordinals of the keys making a substantial - // difference in the existence of the values. - // - // Also under an object style assignment passing, the - // ordering of the arguments is naturally one off - - // excluding the value ... this means that we cascade - // down. - opts = meta || {}; - meta = value; - opts.noexec = 1; - - each( scope, function ( _key, _value ) { - ret[_key] = pub ( _key, _value, meta, opts ); - }); - - // After the callbacks has been bypassed, then we - // run all of them a second time, this time the - // dependency graphs from the object style transactional - // invocation should be satisfied - if (!opts.bypass) { - each( ret, function ( _key, _value ) { - if (isFunction(ret[_key]) && !isFunction(scope[_key])) { - scope[_key] = ret[_key](); - } - }); - } - - // TODO: fix this - bubble( keys(ret)[0] ); - - return scope; - } - - // This will return all the handlers associated with - // this event. - if ( args.length === 1 ) { - return smartMap(scope, resolve); - } - - // If there were two arguments and if one of them was a function, then - // this needs to be registered. Otherwise, we are setting a value. - // - // unless it's an array of functions - return pub [ - ( isFunction ( value ) || - ( isArray(value) && isFunction(value[0]) ) - ) ? ON : SET ].apply(this, args); - } - - function remove_reg(key, cb) { - if(!removedMap[key]) { - removedMap[key] = []; - } - removedMap[key].push(cb || eventMap[key]); - } - - function log(key, value, notes) { - if (!logMap[key]) { - logMap[key] = []; - } - - logMap[key].push([value, new Date(), notes]); - - if (logMap[key].length > logSize) { - logMap[key].shift(); - } - } - - // Register callbacks for - // test, on, after, and or. - each ( typeList, function ( stage ) { - - // register the function - pub[stage] = function ( key, callback, meta ) { - - // if it's an array, then we register each one - // individually. - if (isArray(callback)) { - // take everything after the first two arguments - var args = slice.call(arguments, 2); - - // go through the callback as an array, returning - // its list of cbs - return map(callback, function (cb) { - // call within the oo binding context, the key, the cb, - // and the remaining args. - return pub[stage].apply(pub.context, [key, cb].concat(args)); - }); - } - - var my_map = eventMap; - - if ( !callback ) { - return my_map[stage + key]; - } - - if ( !('ix' in callback) ) { - extend(callback, {ref: [], ix: 0, last: false, line: []}); - } - // This is the back-reference map to this callback - // so that we can unregister it in the future. - callback.ref.push( stage + key ); - - // For debugging purposes we register where this is being registered at. - callback.line.push ( (new Error).stack ); - - if ( isGlobbed(key) ) { - my_map = globberMap; - } - - (my_map[stage + key] || (my_map[stage + key] = [])).push ( callback ); - - // - // It would be nice to do something like - // ev('key', function ()).after(function (){}) - // - // But in order for this to happen you need to proxy the first argument - // magically over to a reference set. This isn't that hard actually - // and shouldn't be too expensive (lolz) anyway, a purely prototype-based - // approach would be awesome here but we need to do this functionally so - // it's a bit of superfluous code where we cross our fingers and hope nobody - // hates us. - // - each(typeList, function (stage) { - - if (!(stage in callback)) { - - callback[stage] = function (am_i_a_function) { - // the first argument MAY be our key from above - var args = slice.call(arguments); - - // If this is a function then we inherit our key - if (isFunction(am_i_a_function)) { - args = [key].concat(args); - } - // However, maybe someone didn't read the documentation closely and is - // trying to fuck with us, providing an entirely different set of keys here ... - // that bastard. It's ok, that's what the type-checking was all about. In this - // case we just blindly pass everything through - - // Also we want to be clever with the return of the callbacks, since we effectively - // shadow the previous system. As it turns out it doesn't matter how we chain these thing - // it just matters what temporal time we register them. So we make the final callback - // an array like structure. - if (! ('len' in callback) ) { - // self reference - callback[0] = callback; - // seed it one past the self-reference minus our incrementer - callback.len = 0; - } - callback.len++; - callback[callback.len] = pub[stage].apply(pub.context, args); - - return callback; - } - } - }); - - return extend(callback, meta); - } - }); - - function del ( handle ) { - each ( handle.ref, function ( stagekey ) { - var map = isGlobbed(stagekey) ? globberMap : eventMap; - map[ stagekey ] = without( map[ stagekey ], handle ); - remove_reg(stagekey, handle); - }); - } - - function isset ( key, callback, meta ) { - // This supports the style - // ev.isset(['key1', 'key2'], something). - // - // Since they all need to be set, then it doesn't really matter - // what order we trigger things in. We don't have to do any crazy - // accounting, just cascading should do fine. - if ( isArray(key) ) { - var myKey = key.pop(), next; - - return isset(glob(myKey), function (data, meta) { - next = (key.length === 1) ? key[0] : key; - return isset(next, callback, meta); - }, meta); - // ^^ this should recurse nicely. - // It uses the meta feature to - // aggregate the k/v pairs as it goes through them. - - } - - // This supports the style of - // ev.isset({ - // key1: something, - // key2: something - // }) - if ( isObject(key) ) { - - each ( key, function ( _key, _value ) { - if (isGlobbed(_key)) { - extend(_key, - smartMap(_key, function (_what){ - return isset(_key, _value, meta); - }) - ); - } else { - key[_key] = isset( _key, _value, meta ); - } - }); - - // Return the entire object as the result - return key; - - } - - var setKey = SET + key; - // If I know how to set this key but - // I just haven't done it yet, run through - // that function now. - if ( eventMap[setKey] ) { - // If someone explicitly sets the k/v in the setter - // that is fine, that means this function isn't run. - // - // NOTE: using the return value as the thing to be set is a bad idea - // because things can be done asynchronously. So there is no way to - // reliably check if the code explicitly set things after the function - // returns. - - // We only call this if we aren't set yet. - if (! (key in data) ) { - /* var ThisIsWorthless = */ eventMap[setKey](function (value) { - pub.set.call(pub.context, key, value, meta); - }); - } - - // register the setter if it existed. - remove_reg(setKey); - delete eventMap[setKey]; - } - - if ( callback ) { - // If it already exists, then just call the function - // that came in. - // - // Otherwise have it called once on a set. This means - // that the setter is inherently asynchronous since - // the execution of this function is continued to be - // blocked until the key is set. - meta = meta || {}; - return key in data ? - callback.call ( pub.context, data[key], meta ) : - pub[meta.first ? FIRST : ON ] ( key, callback, extend( meta , ONCE ) ); - } - - // Otherwise, if there is no callback, just return - // whether this key is defined or not. - return key in data; - }; - - function runCallback(callback, context, value, meta) { - if ( ! callback.norun) { - // our ingested meta was folded into our callback - meta.order++; - var res = callback.call ( - context, - value, - meta, - meta.meta - ); - - if ( callback.once ) { - del ( callback ); - } - - callback.ix++; - callback.last = new Date(); - - return res; - } - } - - function bubble(key) { - var - parts = key.split('.'), - parts_key = parts.pop(), - parts_obj = []; - - parts_obj[parts_key] = data[key]; - - // we then extend the value into the group. - pub.extend.apply( - pub.context, - [ - parts.join('.'), - parts_obj - ].concat( - slice.call(arguments, 1) - ) - ); - } - - // An internal wrapper function for the increment and decrement - // operations. - function mod( key, cb, arg, meta, initial ) { - initial = initial || 0; - - var res = map(isArray(key) ? key : [key], function (which) { - var val = isNumber(data[which]) ? data[which] : initial; - return pub.set ( which, cb(val, arg), meta ); - }); - return isArray(key) ? res : res[0]; - } - - mod.add = function (val, amount) { - return val + amount; - } - - function test(key, _meta, _pass, _fail, _coroutine) { - var - testList = eventMap[TEST + key] || [], - testIx = 0 - 1, - times = testList.length + 1, - failure, - cb = function() { - var - _times = times, - res = runCallback( - testList[ testIx ], - pub.context, - ('_value' in meta ? meta._value : meta.value), - meta - ); - // If the times value is the same then we didn't - // recurse into the tests and instead returned - // a truthy or falsey value, supposedly. - if(_times == times && !!res === res) { - meta(res); - } - }, - pass = function(key,meta) { - log(key, meta.value, ['test:pass', meta]); - return ( _pass || stub ) (key, meta); - }, - fail = function(meta) { - log(key, meta.value, ['test:fail', meta]); - return ( _fail || stub ) (meta); - }, - meta = function ( ok ) { - failure |= (ok === false); - times--; - - if (times < 0) { - return; - } else if ( times ) { - testIx++; - - if (_coroutine(meta, false)) { - cb(); - } else { - fail(meta); - } - } else if ( failure ) { - fail(meta); - } else { - pass(key, meta); - } - - return ok; - }; - - // we should be able to do things - // without these defined. - _coroutine = _coroutine || stub; - - extend(meta, _meta, { - done: meta, - result: meta, - }); - - return meta(true); - } - - extend(pub, { - // Exposing the internal variables so that - // extensions can be made. - _: {}, - context: this, - list: {}, - isPaused: false, - isok: function (key, value) { - var res; - - test( - key, - { - _value: value, - _isok: true - }, - function pass(){ res = true; }, - function fail(){ res = false; } - ); - - return res; - }, - - db: data, - debug: function (name, type) { - if(!name) { - return dbg; - } - - var res = { - lastReturn: lastReturnMap[name], - lock: lockMap[name], - log: logMap[name], - value: data[name] - }; - - if (type) { - res.events = eventMap[type + name]; - res.removed = removedMap[type + name]; - } else { - res.events = smartMap(typeList.concat([SET]), function (type) { - return eventMap[type + name]; - }); - res.removed = smartMap(typeList.concat([SET]), function (type) { - return removedMap[type + name]; - }); - } - - return res; - }, - del: del, - whenSet: isset, - isset: isset, - - pause: function () { - if (!pub.isPaused) { - pub.isPaused = true; - pub._.set = pub.set; - pub.set = function () { - backlog.push([SET, arguments]); - } - return true; - } - return false; - }, - - play: function () { - if (pub.isPaused) { - // first we take it off being paused - pub.isPaused = false; - - // now we make a mock evda - var mock = e(); - - // unswap out our dummy functions - pub.set = pub._.set; - - // And we run the backlog on it (with no events firing of course) - each(backlog, function (row) { - mock[row[0]].apply(mock, row[1]); - }); - // clear the backlog - backlog = []; - - // now we invoke the mock database over our own - pub(mock.db); - - return true; - } - return false; - }, - - // Unlike much of the reset of the code, - // setters have single functions. - setter: function ( key, callback ) { - eventMap[SET + key] = callback; - - // If I am setting a setter and - // a function is already waiting on it, - // then run it now. - if ( eventMap[ON + key] ) { - return isset ( key ); - } - }, - - when: function ( key, toTest, lambda ) { - // when multiple things are set in an object style. - if ( isObject(key) ) { - var - cbMap = {}, - flagMap = {}, - // flagTest only gets run when - flagReset = function (val, meta) { - flagMap[meta.key] = false; - meta(); - }, - flagTest = function (val, meta) { - // toggle the flag - flagMap[meta.key] = true; - - // see if there's any more false things - // and if there are not then we run this - if (values(flagMap).indexOf(false) === -1) { - toTest.apply(pub.context, slice.call(arguments)); - } - }; - - each ( key, function (_key, _val) { - // we first set up a test that will reset our flag. - cbMap[_key + "-test" ] = pub.test(_key, flagReset); - - // then the actual test - cbMap[_key] = pub.when(_key, _val, flagTest); - - // set the initial flagmap key - // value to false - this will - // be triggered if things succeed. - // This has to be initialized here. - flagMap[_key] = false; - }); - - return cbMap; - } - - // See if toTest makes sense as a block of code - // This may have some drastically unexpected side-effects. - if ( isString(toTest) ) { - try { - var attempt = new Function("x", "return x" + toTest); - - // If this doesn't throw an exception, - // we'll call it gold and then make the function - // our test case - attempt(); - - toTest = attempt; - } catch (ex) { } - } else if ( arguments.length === 2 ) { - return pub.isset ( key, toTest ); - } - - return pub(key, function (value) { - if ( - // Look for identical arrays by comparing their string values. - ( isArray(toTest) && toTest.sort().join('') === value.sort().join('') ) || - - // otherwise, Run a tester if that is defined - ( isFunction(toTest) && toTest(value) ) || - - // Otherwise, try a triple equals. - ( value === toTest ) - ) { - lambda.apply(pub.context, slice.call(arguments)); - } - }); - }, - - empty: function (key) { - // we want to maintain references to the object itself - if ( arguments.length === 0) { - for ( var key in data) { - delete data[key]; - } - } else { - each ( arguments, function (key) { - if ( key in data) { - if ( isArray(data[key])) { - pub.set(key, [], {}, {bypass:1, noexec:1}); - } else { - pub.set(key, null, {}, {bypass:1, noexec:1}); - } - } - }); - } - }, - - incr: function ( key, amount, meta ) { - var - cb = isString(amount) ? - new Function("val", "return val" + amount) : - mod.add; - // we can't use the same trick here because if we - // hit 0, it will auto-increment to amount - return mod ( key, cb, amount || 1, meta ); - }, - - decr: function ( key, amount, meta ) { - amount = amount || 1; - // if key isn't in data, it returns 0 and sets it - // if key is in data but isn't a number, it returns NaN and sets it - // if key is 1, then it gets reduced to 0, getting 0, - // if key is any other number, than it gets set - return mod ( key, mod.add, -(amount || 1), meta, 1 ); - }, - - // If we are pushing and popping a non-array then - // it's better that the browser tosses the error - // to the user than we try to be graceful and silent - // Therein, we don't try to handle input validation - // and just try it anyway - push: function ( key, value, meta ) { - return pub.set ( key, [].concat(data[key] || [], [value]), meta ); - }, - - pop: function ( key, meta ) { - return pub.set ( key, data[key].slice(0, -1), meta ); - }, - - group: function ( list ) { - var - opts = toArray(arguments), - list = opts.shift(), - ret = pub.apply(0, opts); - - ( pub.list[list] || (pub.list[list] = []) ); - - if ( isFunction(ret)) { - pub.list[list].push(ret); - } else { - each(ret, function (value, key) { - pub.list[list].push(value); - }); - } - return function () { - return pub.group.apply(0, [list].concat(toArray(arguments))); - } - }, - - extend: function (key, value) { - return pub.set.apply( - pub.context, [ - key, - extend({}, (data[key] || {}), value) - ].concat( - slice.call(arguments, 2) - ) - ); - }, - - count: function (key) { - if ( arguments.length === 0) { - return Math.max.apply(this, values(data_ix)); - } else { - return data_ix[key]; - } - }, - - setContext: function (what) { - pub.context = what; - }, - - set: function (key, value, _meta, _opts) { - _opts = _opts || {}; - - var - bypass = _opts.bypass, - coroutine = _opts.coroutine || stub, - hasvalue = ('value' in _opts), - noexec = _opts.noexec; - - // this is when we are calling a future setter - if ( arguments.length === 1) { - var ret = function () { - pub.set.apply(pub.context, [key].concat(slice.call(arguments))); - } - pub.set.call(pub.context, key, undefined); - return ret; - } - - // recursion prevention. - if ( lockMap[key] > 0) { - each ( traceList, function ( callback ) { - callback.call ( pub.context, extend({locked: key}, args) ); - }); - - return data[key]; - } - lockMap[key] = (lockMap[key] || 0) + 1; - - try { - var - result, - args = slice.call(arguments), - - // Tests are run sequentially, not - // in parallel. - doTest = (size(eventMap[ TEST + key ]) && !bypass), - - orHandler = function (_meta) { - if(_meta) { - meta = _meta; - } - // If the tests fail, then this is the alternate failure - // path that will be run - each ( eventMap[ OR + key ] || [], function ( callback ) { - runCallback ( - callback, - pub.context, - hasvalue ? _opts['value'] : meta.value, - meta - ); - }); - }, - successHandler = function(key, meta) { - // - // The actual setter gets the real value. - // - // If a "coroutine" is set then this will be - // called before the final setter goes through. - // - if (coroutine(meta, true)) { - - // - // Since the setter normally wraps the meta through a layer - // of indirection and we have done that already, we need - // to pass the meta this time as the wrapped version. - // - // Otherwise the calling convention of the data getting - // passed through would magically change if a test gets - // placed in the chain. - // - pub.set ( key, meta.value, meta.meta, {bypass: 1, order: meta.order} ); - } else { - orHandler(); - } - }, - // Invoke will also get done - // but it will have no semantic - // meaning, so it's fine. - meta = {}; - - meta.old = clone(data[key]); - - extend(meta, { - // During testing, the setter gets called on success. We should - // make sure that our order is continually accumulated if this - // is part of a re-ingestion. We make it -1 because we front-load - // how this is incremented. - order: ('order' in _opts) ? _opts.order : -1, - meta: _meta || {}, - key: key, - _value: hasvalue ? _opts['value'] : meta.value, - // the value to set ... or change. - value: value - }); - - if (doTest) { - // we permit a level of recursion for testing. - lockMap[key]--; - if (testLockMap[key] !== true) { - testLockMap[key] = true; - test(key, meta, successHandler, orHandler, coroutine); - testLockMap[key] = false; - } - - // - // Don't return the value... - // return the current value of that key. - // - // This is because keys can be denied - result = data[key]; - } else { - - // If there are tracing functions, then we - // call them one by one - each ( traceList, function ( callback ) { - callback.call ( pub.context, args ); - }); - - // If there's a coroutine then we call that - // here - if (coroutine(meta, true)) { - - value = meta.value; - - // - // Set the key to the new value. - // The old value is being passed in - // through the meta - // - // SETTER: This is the actual setting code - // - if (!(_opts.onlychange && value === data[key])) { - - if (!_opts.noset) { - log(key, value, 'set'); - data[key] = value; - - if (key != '') { - data_ix[key] = (data_ix[key] || 0) + 1; - } - } - - var myargs = arguments, cback = function (){ - each( - (eventMap[FIRST + key] || []).concat( - (eventMap[ON + key] || []) - ), - function (callback) { - meta.last = runCallback(callback, pub.context, value, meta); - }); - - // After this, we bubble up if relevant. - if (key.length > 0) { - // But we don't hit the coroutine - delete _opts.coroutine; - - bubble.apply(pub.context, [key].concat(slice.call(myargs, 2))); - } - - each(eventMap[AFTER + key] || [], - function (callback) { - meta.last = runCallback(callback, pub.context, value, meta); - }); - - lastReturnMap[key] = meta.last; - - return value; - } - - if (!noexec) { - result = cback.call(pub.context); - } else { - bubble.apply(pub.context, [key].concat(slice.call(myargs, 2))); - // if we are not executing this, then - // we return a set of functions that we - // would be executing. - result = cback; - } - } - } - } - - } catch(err) { - throw err; - - } finally { - lockMap[key] = 0; - } - - return result; - }, - - fire: function ( key, meta ) { - each(key, function (what) { - pub.set ( what, data[what], meta, {noset: true} ); - }); - }, - - once: function ( key, lambda, meta ) { - - // - // Permit once to take a bunch of callbacks and mark - // them all for one time. - // - // if we have a 'smart map' then we actually only care - // about the values of it. - // - if ( isObject(key) ) { - key = values(key); - } - if ( isArray(key) ) { - return map(key, function (what) { - pub.once.call(pub.context, what, lambda, meta); - }); - } - - // If this is a callback, then we can register it to be called once. - if (lambda) { - // Through some slight recursion. - return pub.once( - // First we register it as normal. - // Then we call the once with the - // handle, returning here - pub ( key, lambda, meta ) - - // And running the function below: - ); - } - // This will add the k/v pair to the handler - return extend( key, ONCE ); - }, - - enable: function ( listName ) { - each(pub.list[listName], function (callback) { - if ( callback.norun && callback.norun[listName] ) { - delete callback.norun[listName]; - } - - if ( size(callback.norun) === 0 ) { - delete callback.norun; - } - }); - return pub.list[listName]; - }, - - // This an M*N cost set-add that preserves list - // ordinality - osetadd: function ( key, value, meta ) { - var before = data[key] || []; - - // If we are successfully adding to the set - // then we run the events associated with it. - return pub ( key, value, meta, { - coroutine: function (meta, isFinal) { - var valArray = isArray(meta.value) ? meta.value : [meta.value]; - - meta.set = clone(before); - - each(valArray, function (what) { - if (meta.set.indexOf(what) === -1) { - meta.set.push(what); - } - }); - - if (isFinal) { - meta.value = meta.set; - } - meta.oper = {name:'osetadd', value:value}; - - return (before.length != meta.set.length); - } - }); - }, - - toggle: function ( key ) { - return pub(key, !data[key]); - }, - - // This is a sort + M complexity version that - // doesn't perserve ordinality. - setadd: function ( key, value, meta ) { - var before = data[key] || []; - - return pub( key, value, meta, { - // this is only called if the tests pass - coroutine: function (meta, isFinal) { - var valArray = isArray(meta.value) ? meta.value : [meta.value]; - meta.set = uniq( before.concat(valArray) ); - - if (isFinal) { - meta.value = meta.set; - } - meta.oper = {name:'setadd', value:value}; - - return (before.length != meta.set.length); - } - }); - }, - - settoggle: function ( key, value, meta ) { - var routine = ((data[key] || []).indexOf(value) === -1) ? 'add' : 'del'; - return pub[SET + routine](key, value, meta); - }, - - setdel: function ( key, value, meta ) { - var - before = data[key] || [], - after = without( before, value); - - if ( before.length != after.length) { - return pub ( key, after, meta, { - coroutine: function (meta, isFinal) { - if (isFinal) { - meta.oper = {name:'setdel', value:value}; - } - return true; - }, - value: value} ); - } - - return after; - }, - - disable: function ( listName ) { - each(pub.list[listName], function (callback) { - ( callback.norun || (callback.norun = {}) ) [ listName ] = true; - }); - - return pub.list[listName]; - }, - - unset: function () { - var bool = true; - each(arguments, function (which) { - bool &= (which in data); - - // This bubbling is totally slow but it works - var - parts = which.split('.'), - key = '', - len = parts.length, - last = parts[len - 1], - ix, iy, - ref; - - for (ix = 0; ix < len; ix++) { - key = parts.slice(0, ix).join('.'); - ref = data[key]; - if (ref) { - for (iy = ix; iy < (len - 1); iy++) { - ref = ref[parts[iy]]; - } - delete ref[last]; - } - } - - delete data[which]; - }); - - return bool; - }, - - find: function ( regex ) { - return select( keys(data), function (toTest) { - return toTest.match(regex); - }); - }, - - changed: function (key, callback) { - return pub.on(key, function (value, meta) { - var - newlen = size(value), - oldlen = size(meta.old); - - if (newlen - oldlen === 1) { - callback.call( pub.context, last(value) ); - } else if (newlen > oldlen) { - callback.call( pub.context, toArray(value).slice(oldlen) ); - } - }); - }, - - version: function() { - return EvDa.version; - }, - sniff: function () { - var - ignoreMap = {"":1}, - // Use a few levels of indirection to be - // able to toggle the sniffing on or off. - sniffConsole = function (args) { - // If we are to ignore this then we do nothing, - // otherwise we console.log when this occurs. - return ignoreMap[args[0]] || console.log(args); - }, - dummy = function () {}, - sniffProxy = sniffConsole; - - // sniffProxy either points to sniffConsole - // when it's on or dummy when it's off. - traceList.unshift(function (args){ - // That's why we can't call the proxy directly. - sniffProxy(args); - }); - - // neuter this function but don't populate - // the users keyspace. - pub.sniff = function () { - var - args = slice.call(arguments), - ret = []; - - each(args, function (key) { - if (isString(key)) { - if (ignoreMap[key]) { - delete ignoreMap[key]; - } else { - ignoreMap[key] = 1; - } - ret.push([key, ignoreMap[key]]); - - } else { - // If the key is true then we turn sniffing "on" - // by linking the proxy to the real sniff function. - // - // Otherwise, we link the proxy to a dummy function - sniffProxy = key ? sniffConsole : dummy; - ret.push(key); - } - }); - - return args.length ? ret : keys(ignoreMap); - } - - // After we've done the swapping to turn this thing on, - // now we call the internal function with the args set - return pub.sniff.apply(pub.context, arguments); - } - }); - - pub.setAdd = pub.setadd; - pub.setToggle = pub.settoggle; - pub.osetAdd = pub.osetadd; - pub.osetdel = pub.setdel; - pub.osetDel = pub.setdel; - pub.setDel = pub.setdel; - pub.isSet = pub.isset; - pub.whenset = pub.isset; - pub.mod = pub.incr; - - pub.get = pub; - pub.change = pub.on; - pub.add = pub.push; - pub.isOK = pub.isok; - - each(e._ext, function (key, cb) { - pub[key] = function () { - cb.apply(pub.context, [pub].concat(slice.call(arguments))); - } - }); - - // After all the mechanisms are set up, then and only then do - // we do the import - if (arguments.length > 0) { - pub(imported); - } - - return pub; - } - - e._ext = {}; - e.extend = function (name, cb) { - e._ext[name] = cb; - } - - // exposing some internals (mostly for the helper) - e.isArray = isArray; - - return e; -})(); -EvDa.version='0.2.40-20160422'; diff --git a/js/deps/evda.min.js b/js/deps/evda.min.js new file mode 100644 index 0000000..1e7117c --- /dev/null +++ b/js/deps/evda.min.js @@ -0,0 +1,2 @@ +var module=module||{},EvDa=module.exports=function(){"use strict";var n=Array.prototype.slice,t=Object.prototype.toString,e=[].isArray||function(n){return"[object Array]"===t.call(n)},r=function(n){return!!(n&&n.constructor&&n.call&&n.apply)},u=function(n){return!!(""===n||n&&n.charCodeAt&&n.substr)},o=function(n){return"[object Number]"===t.call(n)},c=function(n){return u(n)||o(n)},i=function(n){return r(n)||u(n)||o(n)||e(n)?!1:null==n?"object"===String(n):"[object Object]"===t.call(n)||!0},a=function(t){return n.call(t)},l=[].forEach?function(n,t){if(c(n))return l([n],t);if(e(n)||n.length)a(n).forEach(t);else for(var r in n)t(r,n[r])}:function(n,t){if(c(n))return l([n],t);if(e(n))for(var r=0,u=n.length;u>r;r++)t(n[r],r);else for(var o in n)t(o,n[o])},f=function(n){return n.length?n[n.length-1]:void 0},s=function(n){var t=[];for(var e in n)t.push(n[e]);return t},v={}.keys||function(n){if(e(n))return n;var t=[];for(var r in n)t.push(r);return t},d=function(n,t){var e=[];return l(n,function(n){n!==t&&e.push(n)}),e},p=function(n){var t,e=[];return l(v(n).sort(),function(n){n!=t&&(t=n,e.push(n))}),e},h=function(n,t){var e=[];return l(n,function(n){t(n)&&e.push(n)}),e},g=function(n){return n&&"length"in n?n.length:0},x=[].map?function(n,t){return n.map(t)}:function(n,t){for(var e=[],r=0,u=n.length;u>r;r++)e.push(t(n[r],r));return e},y=function(t){return e(t)?n.call(t):i(t)?m(t,{}):t},m=function(t){return l(n.call(arguments,1),function(n){for(var e in n)void 0!==n[e]&&(t[e]=n[e])}),t},b=function(n){return n.match(/[?*]/)},k=function(n,t){return b(n)?h(v(t?t:data),function(t){return t.match(n)}):n},j=function(n,t){var r={};return e(n)?(l(n,function(n){r[n]=t(n)}),r):t(n)},w="first",_="on",A="after",D="test",E="or",O="set",P=function(){return!0},S=[w,_,A,D,E],C={once:1},F=function(t){function c(n){if(n in H)return H[n];var t=n.split("."),e=t.pop(),r=t.join(".");if(r){var u=c(r);if(i(u)&&e in u)return u[e]}}function R(t,u,o,a){var f=n.call(arguments);if(void 0===t)throw"Undefined passed in as first argument.";if(e(t))return f.shift(),x(t,function(n){return R.apply(R.context,[n].concat(f))});if(i(t)){if(1===f.length&&-1===t.constructor.toString().search(/{\s+\[native code\]\s+}/))return void(R.context=t);var s={};return a=o||{},o=u,a.noexec=1,l(t,function(n,t){s[n]=R(n,t,o,a)}),a.bypass||l(s,function(n,e){r(s[n])&&!r(t[n])&&(t[n]=s[n]())}),U(v(s)[0]),t}return 1===f.length?j(t,c):R[r(u)||e(u)&&r(u[0])?_:O].apply(this,f)}function K(n,t){$[n]||($[n]=[]),$[n].push(t||Z[n])}function L(n,t,e){Y[n]||(Y[n]=[]),Y[n].push([t,new Date,e]),Y[n].length>W&&Y[n].shift()}function M(n){l(n.ref,function(t){var e=b(t)?Q:Z;e[t]=d(e[t],n),K(t,n)})}function N(n,t,r){if(e(n)){var u,o=n.pop();return N(k(o),function(e,r){return u=1===n.length?n[0]:n,N(u,t,r)},r)}if(i(n))return l(n,function(t,e){b(t)?m(t,j(t,function(n){return N(t,e,r)})):n[t]=N(t,e,r)}),n;var c=O+n;return Z[c]&&(n in H||Z[c](function(t){R.set.call(R.context,n,t,r)}),K(c),delete Z[c]),t?(r=r||{},n in H?t.call(R.context,H[n],r):R[r.first?w:_](n,t,m(r,C))):n in H}function T(n,t,e,r){if(!n.norun){r.order++;var u=n.call(t,e,r,r.meta);return n.once&&M(n),n.ix++,n.last=new Date,u}}function U(t){var e=t.split("."),r=e.pop(),u=[];u[r]=H[t],R.extend.apply(R.context,[e.join("."),u].concat(n.call(arguments,1)))}function q(n,t,r,u,c){c=c||0;var i=x(e(n)?n:[n],function(n){var e=o(H[n])?H[n]:c;return R.set(n,t(e,r),u)});return e(n)?i:i[0]}function z(n,t,e,r,u){var o,c=Z[D+n]||[],i=-1,a=c.length+1,l=function(){var n=a,t=T(c[i],R.context,"_value"in v?v._value:v.value,v);n==a&&!!t===t&&v(t)},f=function(n,t){return L(n,t.value,["test:pass",t]),(e||P)(n,t)},s=function(t){return L(n,t.value,["test:fail",t]),(r||P)(t)},v=function(t){return o|=t===!1,a--,0>a?void 0:(a?(i++,u(v,!1)?l():s(v)):o?s(v):f(n,v),t)};return u=u||P,m(v,t,{done:v,result:v}),v(!0)}var B={},G={},H={},I={},J=[],Q={},V=[],W=10,X={},Y={},Z={},$={},nn={data:H,events:Z,removed:$,log:Y,lastReturn:X,locks:B,testLocks:G,trace:V,globs:Q};return l(S,function(t){R[t]=function(u,o,c){if(e(o)){var i=n.call(arguments,2);return x(o,function(n){return R[t].apply(R.context,[u,n].concat(i))})}var a=Z;return o?("ix"in o||m(o,{ref:[],ix:0,last:!1,line:[]}),o.ref.push(t+u),o.line.push((new Error).stack),b(u)&&(a=Q),(a[t+u]||(a[t+u]=[])).push(o),l(S,function(t){t in o||(o[t]=function(e){var c=n.call(arguments);return r(e)&&(c=[u].concat(c)),"len"in o||(o[0]=o,o.len=0),o.len++,o[o.len]=R[t].apply(R.context,c),o})}),m(o,c)):a[t+u]}}),q.add=function(n,t){return n+t},m(R,{_:{},context:this,list:{},isPaused:!1,isok:function(n,t){var e;return z(n,{_value:t,_isok:!0},function(){e=!0},function(){e=!1}),e},db:H,debug:function(n,t){if(!n)return nn;var e={lastReturn:X[n],lock:B[n],log:Y[n],value:H[n]};return t?(e.events=Z[t+n],e.removed=$[t+n]):(e.events=j(S.concat([O]),function(t){return Z[t+n]}),e.removed=j(S.concat([O]),function(t){return $[t+n]})),e},del:M,whenSet:N,isset:N,pause:function(){return R.isPaused?!1:(R.isPaused=!0,R._.set=R.set,R.set=function(){J.push([O,arguments])},!0)},play:function(){if(R.isPaused){R.isPaused=!1;var n=F();return R.set=R._.set,l(J,function(t){n[t[0]].apply(n,t[1])}),J=[],R(n.db),!0}return!1},setter:function(n,t){return Z[O+n]=t,Z[_+n]?N(n):void 0},when:function(t,o,c){if(i(t)){var a={},f={},v=function(n,t){f[t.key]=!1,t()},d=function(t,e){f[e.key]=!0,-1===s(f).indexOf(!1)&&o.apply(R.context,n.call(arguments))};return l(t,function(n,t){a[n+"-test"]=R.test(n,v),a[n]=R.when(n,t,d),f[n]=!1}),a}if(u(o))try{var p=new Function("x","return x"+o);p(),o=p}catch(h){}else if(2===arguments.length)return R.isset(t,o);return R(t,function(t){(e(o)&&o.sort().join("")===t.sort().join("")||r(o)&&o(t)||t===o)&&c.apply(R.context,n.call(arguments))})},empty:function(n){if(0===arguments.length)for(var n in H)delete H[n];else l(arguments,function(n){n in H&&(e(H[n])?R.set(n,[],{},{bypass:1,noexec:1}):R.set(n,null,{},{bypass:1,noexec:1}))})},incr:function(n,t,e){var r=u(t)?new Function("val","return val"+t):q.add;return q(n,r,t||1,e)},decr:function(n,t,e){return t=t||1,q(n,q.add,-(t||1),e,1)},push:function(n,t,e){return R.set(n,[].concat(H[n]||[],[t]),e)},pop:function(n,t){return R.set(n,H[n].slice(0,-1),t)},group:function(n){var t=a(arguments),n=t.shift(),e=R.apply(0,t);return R.list[n]||(R.list[n]=[]),r(e)?R.list[n].push(e):l(e,function(t,e){R.list[n].push(t)}),function(){return R.group.apply(0,[n].concat(a(arguments)))}},extend:function(t,e){return R.set.apply(R.context,[t,m({},H[t]||{},e)].concat(n.call(arguments,2)))},count:function(n){return 0===arguments.length?Math.max.apply(this,s(I)):I[n]},setContext:function(n){R.context=n},set:function(t,e,r,u){u=u||{};var o=u.bypass,c=u.coroutine||P,i="value"in u,a=u.noexec;if(1===arguments.length){var f=function(){R.set.apply(R.context,[t].concat(n.call(arguments)))};return R.set.call(R.context,t,void 0),f}if(B[t]>0)return l(V,function(n){n.call(R.context,m({locked:t},v))}),H[t];B[t]=(B[t]||0)+1;try{var s,v=n.call(arguments),d=g(Z[D+t])&&!o,p=function(n){n&&(x=n),l(Z[E+t]||[],function(n){T(n,R.context,i?u.value:x.value,x)})},h=function(n,t){c(t,!0)?R.set(n,t.value,t.meta,{bypass:1,order:t.order}):p()},x={};if(x.old=y(H[t]),m(x,{order:"order"in u?u.order:-1,meta:r||{},key:t,_value:i?u.value:x.value,value:e}),d)B[t]--,G[t]!==!0&&(G[t]=!0,z(t,x,h,p,c),G[t]=!1),s=H[t];else if(l(V,function(n){n.call(R.context,v)}),c(x,!0)&&(e=x.value,!u.onlychange||e!==H[t])){u.noset||(L(t,e,"set"),H[t]=e,""!=t&&(I[t]=(I[t]||0)+1));var b=arguments,k=function(){return l((Z[w+t]||[]).concat(Z[_+t]||[]),function(n){x.last=T(n,R.context,e,x)}),t.length>0&&(delete u.coroutine,U.apply(R.context,[t].concat(n.call(b,2)))),l(Z[A+t]||[],function(n){x.last=T(n,R.context,e,x)}),X[t]=x.last,e};a?(U.apply(R.context,[t].concat(n.call(b,2))),s=k):s=k.call(R.context)}}catch(j){throw j}finally{B[t]=0}return s},fire:function(n,t){l(n,function(n){R.set(n,H[n],t,{noset:!0})})},once:function(n,t,r){return i(n)&&(n=s(n)),e(n)?x(n,function(n){R.once.call(R.context,n,t,r)}):t?R.once(R(n,t,r)):m(n,C)},enable:function(n){return l(R.list[n],function(t){t.norun&&t.norun[n]&&delete t.norun[n],0===g(t.norun)&&delete t.norun}),R.list[n]},osetadd:function(n,t,r){var u=H[n]||[];return R(n,t,r,{coroutine:function(n,r){var o=e(n.value)?n.value:[n.value];return n.set=y(u),l(o,function(t){-1===n.set.indexOf(t)&&n.set.push(t)}),r&&(n.value=n.set),n.oper={name:"osetadd",value:t},u.length!=n.set.length}})},toggle:function(n){return R(n,!H[n])},setadd:function(n,t,r){var u=H[n]||[];return R(n,t,r,{coroutine:function(n,r){var o=e(n.value)?n.value:[n.value];return n.set=p(u.concat(o)),r&&(n.value=n.set),n.oper={name:"setadd",value:t},u.length!=n.set.length}})},settoggle:function(n,t,e){var r=-1===(H[n]||[]).indexOf(t)?"add":"del";return R[O+r](n,t,e)},setdel:function(n,t,e){var r=H[n]||[],u=d(r,t);return r.length!=u.length?R(n,u,e,{coroutine:function(n,e){return e&&(n.oper={name:"setdel",value:t}),!0},value:t}):u},disable:function(n){return l(R.list[n],function(t){(t.norun||(t.norun={}))[n]=!0}),R.list[n]},unset:function(){var n=!0;return l(arguments,function(t){n&=t in H;var e,r,u,o=t.split("."),c="",i=o.length,a=o[i-1];for(e=0;i>e;e++)if(c=o.slice(0,e).join("."),u=H[c]){for(r=e;i-1>r;r++)u=u[o[r]];delete u[a]}delete H[t]}),n},find:function(n){return h(v(H),function(t){return t.match(n)})},changed:function(n,t){return R.on(n,function(n,e){var r=g(n),u=g(e.old);r-u===1?t.call(R.context,f(n)):r>u&&t.call(R.context,a(n).slice(u))})},version:function(){return EvDa.version},sniff:function(){var t={"":1},e=function(n){return t[n[0]]||console.log(n)},r=function(){},o=e;return V.unshift(function(n){o(n)}),R.sniff=function(){var c=n.call(arguments),i=[];return l(c,function(n){u(n)?(t[n]?delete t[n]:t[n]=1,i.push([n,t[n]])):(o=n?e:r,i.push(n))}),c.length?i:v(t)},R.sniff.apply(R.context,arguments)}}),R.setAdd=R.setadd,R.setToggle=R.settoggle,R.osetAdd=R.osetadd,R.osetdel=R.setdel,R.osetDel=R.setdel,R.setDel=R.setdel,R.isSet=R.isset,R.whenset=R.isset,R.mod=R.incr,R.get=R,R.change=R.on,R.add=R.push,R.isOK=R.isok,l(F._ext,function(t,e){R[t]=function(){e.apply(R.context,[R].concat(n.call(arguments)))}}),arguments.length>0&&R(t),R};return F._ext={},F.extend=function(n,t){F._ext[n]=t},F.isArray=e,F}();EvDa.version="0.2.40-20160422"; +//# sourceMappingURL=evda.map.js diff --git a/js/deps/underscore-min.js b/js/deps/underscore-min.js deleted file mode 100644 index f01025b..0000000 --- a/js/deps/underscore-min.js +++ /dev/null @@ -1,6 +0,0 @@ -// Underscore.js 1.8.3 -// http://underscorejs.org -// (c) 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors -// Underscore may be freely distributed under the MIT license. -(function(){function n(n){function t(t,r,e,u,i,o){for(;i>=0&&o>i;i+=n){var a=u?u[i]:i;e=r(e,t[a],a,t)}return e}return function(r,e,u,i){e=b(e,i,4);var o=!k(r)&&m.keys(r),a=(o||r).length,c=n>0?0:a-1;return arguments.length<3&&(u=r[o?o[c]:c],c+=n),t(r,e,u,o,c,a)}}function t(n){return function(t,r,e){r=x(r,e);for(var u=O(t),i=n>0?0:u-1;i>=0&&u>i;i+=n)if(r(t[i],i,t))return i;return-1}}function r(n,t,r){return function(e,u,i){var o=0,a=O(e);if("number"==typeof i)n>0?o=i>=0?i:Math.max(i+a,o):a=i>=0?Math.min(i+1,a):i+a+1;else if(r&&i&&a)return i=r(e,u),e[i]===u?i:-1;if(u!==u)return i=t(l.call(e,o,a),m.isNaN),i>=0?i+o:-1;for(i=n>0?o:a-1;i>=0&&a>i;i+=n)if(e[i]===u)return i;return-1}}function e(n,t){var r=I.length,e=n.constructor,u=m.isFunction(e)&&e.prototype||a,i="constructor";for(m.has(n,i)&&!m.contains(t,i)&&t.push(i);r--;)i=I[r],i in n&&n[i]!==u[i]&&!m.contains(t,i)&&t.push(i)}var u=this,i=u._,o=Array.prototype,a=Object.prototype,c=Function.prototype,f=o.push,l=o.slice,s=a.toString,p=a.hasOwnProperty,h=Array.isArray,v=Object.keys,g=c.bind,y=Object.create,d=function(){},m=function(n){return n instanceof m?n:this instanceof m?void(this._wrapped=n):new m(n)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=m),exports._=m):u._=m,m.VERSION="1.8.3";var b=function(n,t,r){if(t===void 0)return n;switch(null==r?3:r){case 1:return function(r){return n.call(t,r)};case 2:return function(r,e){return n.call(t,r,e)};case 3:return function(r,e,u){return n.call(t,r,e,u)};case 4:return function(r,e,u,i){return n.call(t,r,e,u,i)}}return function(){return n.apply(t,arguments)}},x=function(n,t,r){return null==n?m.identity:m.isFunction(n)?b(n,t,r):m.isObject(n)?m.matcher(n):m.property(n)};m.iteratee=function(n,t){return x(n,t,1/0)};var _=function(n,t){return function(r){var e=arguments.length;if(2>e||null==r)return r;for(var u=1;e>u;u++)for(var i=arguments[u],o=n(i),a=o.length,c=0;a>c;c++){var f=o[c];t&&r[f]!==void 0||(r[f]=i[f])}return r}},j=function(n){if(!m.isObject(n))return{};if(y)return y(n);d.prototype=n;var t=new d;return d.prototype=null,t},w=function(n){return function(t){return null==t?void 0:t[n]}},A=Math.pow(2,53)-1,O=w("length"),k=function(n){var t=O(n);return"number"==typeof t&&t>=0&&A>=t};m.each=m.forEach=function(n,t,r){t=b(t,r);var e,u;if(k(n))for(e=0,u=n.length;u>e;e++)t(n[e],e,n);else{var i=m.keys(n);for(e=0,u=i.length;u>e;e++)t(n[i[e]],i[e],n)}return n},m.map=m.collect=function(n,t,r){t=x(t,r);for(var e=!k(n)&&m.keys(n),u=(e||n).length,i=Array(u),o=0;u>o;o++){var a=e?e[o]:o;i[o]=t(n[a],a,n)}return i},m.reduce=m.foldl=m.inject=n(1),m.reduceRight=m.foldr=n(-1),m.find=m.detect=function(n,t,r){var e;return e=k(n)?m.findIndex(n,t,r):m.findKey(n,t,r),e!==void 0&&e!==-1?n[e]:void 0},m.filter=m.select=function(n,t,r){var e=[];return t=x(t,r),m.each(n,function(n,r,u){t(n,r,u)&&e.push(n)}),e},m.reject=function(n,t,r){return m.filter(n,m.negate(x(t)),r)},m.every=m.all=function(n,t,r){t=x(t,r);for(var e=!k(n)&&m.keys(n),u=(e||n).length,i=0;u>i;i++){var o=e?e[i]:i;if(!t(n[o],o,n))return!1}return!0},m.some=m.any=function(n,t,r){t=x(t,r);for(var e=!k(n)&&m.keys(n),u=(e||n).length,i=0;u>i;i++){var o=e?e[i]:i;if(t(n[o],o,n))return!0}return!1},m.contains=m.includes=m.include=function(n,t,r,e){return k(n)||(n=m.values(n)),("number"!=typeof r||e)&&(r=0),m.indexOf(n,t,r)>=0},m.invoke=function(n,t){var r=l.call(arguments,2),e=m.isFunction(t);return m.map(n,function(n){var u=e?t:n[t];return null==u?u:u.apply(n,r)})},m.pluck=function(n,t){return m.map(n,m.property(t))},m.where=function(n,t){return m.filter(n,m.matcher(t))},m.findWhere=function(n,t){return m.find(n,m.matcher(t))},m.max=function(n,t,r){var e,u,i=-1/0,o=-1/0;if(null==t&&null!=n){n=k(n)?n:m.values(n);for(var a=0,c=n.length;c>a;a++)e=n[a],e>i&&(i=e)}else t=x(t,r),m.each(n,function(n,r,e){u=t(n,r,e),(u>o||u===-1/0&&i===-1/0)&&(i=n,o=u)});return i},m.min=function(n,t,r){var e,u,i=1/0,o=1/0;if(null==t&&null!=n){n=k(n)?n:m.values(n);for(var a=0,c=n.length;c>a;a++)e=n[a],i>e&&(i=e)}else t=x(t,r),m.each(n,function(n,r,e){u=t(n,r,e),(o>u||1/0===u&&1/0===i)&&(i=n,o=u)});return i},m.shuffle=function(n){for(var t,r=k(n)?n:m.values(n),e=r.length,u=Array(e),i=0;e>i;i++)t=m.random(0,i),t!==i&&(u[i]=u[t]),u[t]=r[i];return u},m.sample=function(n,t,r){return null==t||r?(k(n)||(n=m.values(n)),n[m.random(n.length-1)]):m.shuffle(n).slice(0,Math.max(0,t))},m.sortBy=function(n,t,r){return t=x(t,r),m.pluck(m.map(n,function(n,r,e){return{value:n,index:r,criteria:t(n,r,e)}}).sort(function(n,t){var r=n.criteria,e=t.criteria;if(r!==e){if(r>e||r===void 0)return 1;if(e>r||e===void 0)return-1}return n.index-t.index}),"value")};var F=function(n){return function(t,r,e){var u={};return r=x(r,e),m.each(t,function(e,i){var o=r(e,i,t);n(u,e,o)}),u}};m.groupBy=F(function(n,t,r){m.has(n,r)?n[r].push(t):n[r]=[t]}),m.indexBy=F(function(n,t,r){n[r]=t}),m.countBy=F(function(n,t,r){m.has(n,r)?n[r]++:n[r]=1}),m.toArray=function(n){return n?m.isArray(n)?l.call(n):k(n)?m.map(n,m.identity):m.values(n):[]},m.size=function(n){return null==n?0:k(n)?n.length:m.keys(n).length},m.partition=function(n,t,r){t=x(t,r);var e=[],u=[];return m.each(n,function(n,r,i){(t(n,r,i)?e:u).push(n)}),[e,u]},m.first=m.head=m.take=function(n,t,r){return null==n?void 0:null==t||r?n[0]:m.initial(n,n.length-t)},m.initial=function(n,t,r){return l.call(n,0,Math.max(0,n.length-(null==t||r?1:t)))},m.last=function(n,t,r){return null==n?void 0:null==t||r?n[n.length-1]:m.rest(n,Math.max(0,n.length-t))},m.rest=m.tail=m.drop=function(n,t,r){return l.call(n,null==t||r?1:t)},m.compact=function(n){return m.filter(n,m.identity)};var S=function(n,t,r,e){for(var u=[],i=0,o=e||0,a=O(n);a>o;o++){var c=n[o];if(k(c)&&(m.isArray(c)||m.isArguments(c))){t||(c=S(c,t,r));var f=0,l=c.length;for(u.length+=l;l>f;)u[i++]=c[f++]}else r||(u[i++]=c)}return u};m.flatten=function(n,t){return S(n,t,!1)},m.without=function(n){return m.difference(n,l.call(arguments,1))},m.uniq=m.unique=function(n,t,r,e){m.isBoolean(t)||(e=r,r=t,t=!1),null!=r&&(r=x(r,e));for(var u=[],i=[],o=0,a=O(n);a>o;o++){var c=n[o],f=r?r(c,o,n):c;t?(o&&i===f||u.push(c),i=f):r?m.contains(i,f)||(i.push(f),u.push(c)):m.contains(u,c)||u.push(c)}return u},m.union=function(){return m.uniq(S(arguments,!0,!0))},m.intersection=function(n){for(var t=[],r=arguments.length,e=0,u=O(n);u>e;e++){var i=n[e];if(!m.contains(t,i)){for(var o=1;r>o&&m.contains(arguments[o],i);o++);o===r&&t.push(i)}}return t},m.difference=function(n){var t=S(arguments,!0,!0,1);return m.filter(n,function(n){return!m.contains(t,n)})},m.zip=function(){return m.unzip(arguments)},m.unzip=function(n){for(var t=n&&m.max(n,O).length||0,r=Array(t),e=0;t>e;e++)r[e]=m.pluck(n,e);return r},m.object=function(n,t){for(var r={},e=0,u=O(n);u>e;e++)t?r[n[e]]=t[e]:r[n[e][0]]=n[e][1];return r},m.findIndex=t(1),m.findLastIndex=t(-1),m.sortedIndex=function(n,t,r,e){r=x(r,e,1);for(var u=r(t),i=0,o=O(n);o>i;){var a=Math.floor((i+o)/2);r(n[a])i;i++,n+=r)u[i]=n;return u};var E=function(n,t,r,e,u){if(!(e instanceof t))return n.apply(r,u);var i=j(n.prototype),o=n.apply(i,u);return m.isObject(o)?o:i};m.bind=function(n,t){if(g&&n.bind===g)return g.apply(n,l.call(arguments,1));if(!m.isFunction(n))throw new TypeError("Bind must be called on a function");var r=l.call(arguments,2),e=function(){return E(n,e,t,this,r.concat(l.call(arguments)))};return e},m.partial=function(n){var t=l.call(arguments,1),r=function(){for(var e=0,u=t.length,i=Array(u),o=0;u>o;o++)i[o]=t[o]===m?arguments[e++]:t[o];for(;e=e)throw new Error("bindAll must be passed function names");for(t=1;e>t;t++)r=arguments[t],n[r]=m.bind(n[r],n);return n},m.memoize=function(n,t){var r=function(e){var u=r.cache,i=""+(t?t.apply(this,arguments):e);return m.has(u,i)||(u[i]=n.apply(this,arguments)),u[i]};return r.cache={},r},m.delay=function(n,t){var r=l.call(arguments,2);return setTimeout(function(){return n.apply(null,r)},t)},m.defer=m.partial(m.delay,m,1),m.throttle=function(n,t,r){var e,u,i,o=null,a=0;r||(r={});var c=function(){a=r.leading===!1?0:m.now(),o=null,i=n.apply(e,u),o||(e=u=null)};return function(){var f=m.now();a||r.leading!==!1||(a=f);var l=t-(f-a);return e=this,u=arguments,0>=l||l>t?(o&&(clearTimeout(o),o=null),a=f,i=n.apply(e,u),o||(e=u=null)):o||r.trailing===!1||(o=setTimeout(c,l)),i}},m.debounce=function(n,t,r){var e,u,i,o,a,c=function(){var f=m.now()-o;t>f&&f>=0?e=setTimeout(c,t-f):(e=null,r||(a=n.apply(i,u),e||(i=u=null)))};return function(){i=this,u=arguments,o=m.now();var f=r&&!e;return e||(e=setTimeout(c,t)),f&&(a=n.apply(i,u),i=u=null),a}},m.wrap=function(n,t){return m.partial(t,n)},m.negate=function(n){return function(){return!n.apply(this,arguments)}},m.compose=function(){var n=arguments,t=n.length-1;return function(){for(var r=t,e=n[t].apply(this,arguments);r--;)e=n[r].call(this,e);return e}},m.after=function(n,t){return function(){return--n<1?t.apply(this,arguments):void 0}},m.before=function(n,t){var r;return function(){return--n>0&&(r=t.apply(this,arguments)),1>=n&&(t=null),r}},m.once=m.partial(m.before,2);var M=!{toString:null}.propertyIsEnumerable("toString"),I=["valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"];m.keys=function(n){if(!m.isObject(n))return[];if(v)return v(n);var t=[];for(var r in n)m.has(n,r)&&t.push(r);return M&&e(n,t),t},m.allKeys=function(n){if(!m.isObject(n))return[];var t=[];for(var r in n)t.push(r);return M&&e(n,t),t},m.values=function(n){for(var t=m.keys(n),r=t.length,e=Array(r),u=0;r>u;u++)e[u]=n[t[u]];return e},m.mapObject=function(n,t,r){t=x(t,r);for(var e,u=m.keys(n),i=u.length,o={},a=0;i>a;a++)e=u[a],o[e]=t(n[e],e,n);return o},m.pairs=function(n){for(var t=m.keys(n),r=t.length,e=Array(r),u=0;r>u;u++)e[u]=[t[u],n[t[u]]];return e},m.invert=function(n){for(var t={},r=m.keys(n),e=0,u=r.length;u>e;e++)t[n[r[e]]]=r[e];return t},m.functions=m.methods=function(n){var t=[];for(var r in n)m.isFunction(n[r])&&t.push(r);return t.sort()},m.extend=_(m.allKeys),m.extendOwn=m.assign=_(m.keys),m.findKey=function(n,t,r){t=x(t,r);for(var e,u=m.keys(n),i=0,o=u.length;o>i;i++)if(e=u[i],t(n[e],e,n))return e},m.pick=function(n,t,r){var e,u,i={},o=n;if(null==o)return i;m.isFunction(t)?(u=m.allKeys(o),e=b(t,r)):(u=S(arguments,!1,!1,1),e=function(n,t,r){return t in r},o=Object(o));for(var a=0,c=u.length;c>a;a++){var f=u[a],l=o[f];e(l,f,o)&&(i[f]=l)}return i},m.omit=function(n,t,r){if(m.isFunction(t))t=m.negate(t);else{var e=m.map(S(arguments,!1,!1,1),String);t=function(n,t){return!m.contains(e,t)}}return m.pick(n,t,r)},m.defaults=_(m.allKeys,!0),m.create=function(n,t){var r=j(n);return t&&m.extendOwn(r,t),r},m.clone=function(n){return m.isObject(n)?m.isArray(n)?n.slice():m.extend({},n):n},m.tap=function(n,t){return t(n),n},m.isMatch=function(n,t){var r=m.keys(t),e=r.length;if(null==n)return!e;for(var u=Object(n),i=0;e>i;i++){var o=r[i];if(t[o]!==u[o]||!(o in u))return!1}return!0};var N=function(n,t,r,e){if(n===t)return 0!==n||1/n===1/t;if(null==n||null==t)return n===t;n instanceof m&&(n=n._wrapped),t instanceof m&&(t=t._wrapped);var u=s.call(n);if(u!==s.call(t))return!1;switch(u){case"[object RegExp]":case"[object String]":return""+n==""+t;case"[object Number]":return+n!==+n?+t!==+t:0===+n?1/+n===1/t:+n===+t;case"[object Date]":case"[object Boolean]":return+n===+t}var i="[object Array]"===u;if(!i){if("object"!=typeof n||"object"!=typeof t)return!1;var o=n.constructor,a=t.constructor;if(o!==a&&!(m.isFunction(o)&&o instanceof o&&m.isFunction(a)&&a instanceof a)&&"constructor"in n&&"constructor"in t)return!1}r=r||[],e=e||[];for(var c=r.length;c--;)if(r[c]===n)return e[c]===t;if(r.push(n),e.push(t),i){if(c=n.length,c!==t.length)return!1;for(;c--;)if(!N(n[c],t[c],r,e))return!1}else{var f,l=m.keys(n);if(c=l.length,m.keys(t).length!==c)return!1;for(;c--;)if(f=l[c],!m.has(t,f)||!N(n[f],t[f],r,e))return!1}return r.pop(),e.pop(),!0};m.isEqual=function(n,t){return N(n,t)},m.isEmpty=function(n){return null==n?!0:k(n)&&(m.isArray(n)||m.isString(n)||m.isArguments(n))?0===n.length:0===m.keys(n).length},m.isElement=function(n){return!(!n||1!==n.nodeType)},m.isArray=h||function(n){return"[object Array]"===s.call(n)},m.isObject=function(n){var t=typeof n;return"function"===t||"object"===t&&!!n},m.each(["Arguments","Function","String","Number","Date","RegExp","Error"],function(n){m["is"+n]=function(t){return s.call(t)==="[object "+n+"]"}}),m.isArguments(arguments)||(m.isArguments=function(n){return m.has(n,"callee")}),"function"!=typeof/./&&"object"!=typeof Int8Array&&(m.isFunction=function(n){return"function"==typeof n||!1}),m.isFinite=function(n){return isFinite(n)&&!isNaN(parseFloat(n))},m.isNaN=function(n){return m.isNumber(n)&&n!==+n},m.isBoolean=function(n){return n===!0||n===!1||"[object Boolean]"===s.call(n)},m.isNull=function(n){return null===n},m.isUndefined=function(n){return n===void 0},m.has=function(n,t){return null!=n&&p.call(n,t)},m.noConflict=function(){return u._=i,this},m.identity=function(n){return n},m.constant=function(n){return function(){return n}},m.noop=function(){},m.property=w,m.propertyOf=function(n){return null==n?function(){}:function(t){return n[t]}},m.matcher=m.matches=function(n){return n=m.extendOwn({},n),function(t){return m.isMatch(t,n)}},m.times=function(n,t,r){var e=Array(Math.max(0,n));t=b(t,r,1);for(var u=0;n>u;u++)e[u]=t(u);return e},m.random=function(n,t){return null==t&&(t=n,n=0),n+Math.floor(Math.random()*(t-n+1))},m.now=Date.now||function(){return(new Date).getTime()};var B={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},T=m.invert(B),R=function(n){var t=function(t){return n[t]},r="(?:"+m.keys(n).join("|")+")",e=RegExp(r),u=RegExp(r,"g");return function(n){return n=null==n?"":""+n,e.test(n)?n.replace(u,t):n}};m.escape=R(B),m.unescape=R(T),m.result=function(n,t,r){var e=null==n?void 0:n[t];return e===void 0&&(e=r),m.isFunction(e)?e.call(n):e};var q=0;m.uniqueId=function(n){var t=++q+"";return n?n+t:t},m.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var K=/(.)^/,z={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},D=/\\|'|\r|\n|\u2028|\u2029/g,L=function(n){return"\\"+z[n]};m.template=function(n,t,r){!t&&r&&(t=r),t=m.defaults({},t,m.templateSettings);var e=RegExp([(t.escape||K).source,(t.interpolate||K).source,(t.evaluate||K).source].join("|")+"|$","g"),u=0,i="__p+='";n.replace(e,function(t,r,e,o,a){return i+=n.slice(u,a).replace(D,L),u=a+t.length,r?i+="'+\n((__t=("+r+"))==null?'':_.escape(__t))+\n'":e?i+="'+\n((__t=("+e+"))==null?'':__t)+\n'":o&&(i+="';\n"+o+"\n__p+='"),t}),i+="';\n",t.variable||(i="with(obj||{}){\n"+i+"}\n"),i="var __t,__p='',__j=Array.prototype.join,"+"print=function(){__p+=__j.call(arguments,'');};\n"+i+"return __p;\n";try{var o=new Function(t.variable||"obj","_",i)}catch(a){throw a.source=i,a}var c=function(n){return o.call(this,n,m)},f=t.variable||"obj";return c.source="function("+f+"){\n"+i+"}",c},m.chain=function(n){var t=m(n);return t._chain=!0,t};var P=function(n,t){return n._chain?m(t).chain():t};m.mixin=function(n){m.each(m.functions(n),function(t){var r=m[t]=n[t];m.prototype[t]=function(){var n=[this._wrapped];return f.apply(n,arguments),P(this,r.apply(m,n))}})},m.mixin(m),m.each(["pop","push","reverse","shift","sort","splice","unshift"],function(n){var t=o[n];m.prototype[n]=function(){var r=this._wrapped;return t.apply(r,arguments),"shift"!==n&&"splice"!==n||0!==r.length||delete r[0],P(this,r)}}),m.each(["concat","join","slice"],function(n){var t=o[n];m.prototype[n]=function(){return P(this,t.apply(this._wrapped,arguments))}}),m.prototype.value=function(){return this._wrapped},m.prototype.valueOf=m.prototype.toJSON=m.prototype.value,m.prototype.toString=function(){return""+this._wrapped},"function"==typeof define&&define.amd&&define("underscore",[],function(){return m})}).call(this); -//# sourceMappingURL=underscore-min.map \ No newline at end of file