/** * Require the given path. * * @param {String} path * @return {Object} exports * @api public */ function require(path, parent, orig) { var resolved = require.resolve(path); // lookup failed if (null == resolved) { orig = orig || path; parent = parent || 'root'; var err = new Error('Failed to require "' + orig + '" from "' + parent + '"'); err.path = orig; err.parent = parent; err.require = true; throw err; } var module = require.modules[resolved]; // perform real require() // by invoking the module's // registered function if (!module.exports) { module.exports = {}; module.client = module.component = true; module.call(this, module.exports, require.relative(resolved), module); } return module.exports; } /** * Registered modules. */ require.modules = {}; /** * Registered aliases. */ require.aliases = {}; /** * Resolve `path`. * * Lookup: * * - PATH/index.js * - PATH.js * - PATH * * @param {String} path * @return {String} path or null * @api private */ require.resolve = function(path) { if (path.charAt(0) === '/') path = path.slice(1); var paths = [ path, path + '.js', path + '.json', path + '/index.js', path + '/index.json' ]; for (var i = 0; i < paths.length; i++) { var path = paths[i]; if (require.modules.hasOwnProperty(path)) return path; if (require.aliases.hasOwnProperty(path)) return require.aliases[path]; } }; /** * Normalize `path` relative to the current path. * * @param {String} curr * @param {String} path * @return {String} * @api private */ require.normalize = function(curr, path) { var segs = []; if ('.' != path.charAt(0)) return path; curr = curr.split('/'); path = path.split('/'); for (var i = 0; i < path.length; ++i) { if ('..' == path[i]) { curr.pop(); } else if ('.' != path[i] && '' != path[i]) { segs.push(path[i]); } } return curr.concat(segs).join('/'); }; /** * Register module at `path` with callback `definition`. * * @param {String} path * @param {Function} definition * @api private */ require.register = function(path, definition) { require.modules[path] = definition; }; /** * Alias a module definition. * * @param {String} from * @param {String} to * @api private */ require.alias = function(from, to) { if (!require.modules.hasOwnProperty(from)) { throw new Error('Failed to alias "' + from + '", it does not exist'); } require.aliases[to] = from; }; /** * Return a require function relative to the `parent` path. * * @param {String} parent * @return {Function} * @api private */ require.relative = function(parent) { var p = require.normalize(parent, '..'); /** * lastIndexOf helper. */ function lastIndexOf(arr, obj) { var i = arr.length; while (i--) { if (arr[i] === obj) return i; } return -1; } /** * The relative require() itself. */ function localRequire(path) { var resolved = localRequire.resolve(path); return require(resolved, parent, path); } /** * Resolve relative to the parent. */ localRequire.resolve = function(path) { var c = path.charAt(0); if ('/' == c) return path.slice(1); if ('.' == c) return require.normalize(p, path); // resolve deps by returning // the dep in the nearest "deps" // directory var segs = parent.split('/'); var i = lastIndexOf(segs, 'deps') + 1; if (!i) i = 0; path = segs.slice(0, i + 1).join('/') + '/deps/' + path; return path; }; /** * Check if module is defined at `path`. */ localRequire.exists = function(path) { return require.modules.hasOwnProperty(localRequire.resolve(path)); }; return localRequire; }; require.register("mikeric-rivets/dist/rivets.js", function(exports, require, module){ // Rivets.js // version: 0.5.12 // author: Michael Richards // license: MIT (function() { var Rivets, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __slice = [].slice, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; Rivets = {}; if (!String.prototype.trim) { String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }; } Rivets.Binding = (function() { function Binding(view, el, type, key, keypath, options) { var identifier, regexp, value, _ref; this.view = view; this.el = el; this.type = type; this.key = key; this.keypath = keypath; this.options = options != null ? options : {}; this.update = __bind(this.update, this); this.unbind = __bind(this.unbind, this); this.bind = __bind(this.bind, this); this.publish = __bind(this.publish, this); this.sync = __bind(this.sync, this); this.set = __bind(this.set, this); this.eventHandler = __bind(this.eventHandler, this); this.formattedValue = __bind(this.formattedValue, this); if (!(this.binder = this.view.binders[type])) { _ref = this.view.binders; for (identifier in _ref) { value = _ref[identifier]; if (identifier !== '*' && identifier.indexOf('*') !== -1) { regexp = new RegExp("^" + (identifier.replace('*', '.+')) + "$"); if (regexp.test(type)) { this.binder = value; this.args = new RegExp("^" + (identifier.replace('*', '(.+)')) + "$").exec(type); this.args.shift(); } } } } this.binder || (this.binder = this.view.binders['*']); if (this.binder instanceof Function) { this.binder = { routine: this.binder }; } this.formatters = this.options.formatters || []; this.model = this.key ? this.view.models[this.key] : this.view.models; } Binding.prototype.formattedValue = function(value) { var args, formatter, id, _i, _len, _ref; _ref = this.formatters; for (_i = 0, _len = _ref.length; _i < _len; _i++) { formatter = _ref[_i]; args = formatter.split(/\s+/); id = args.shift(); formatter = this.model[id] instanceof Function ? this.model[id] : this.view.formatters[id]; if ((formatter != null ? formatter.read : void 0) instanceof Function) { value = formatter.read.apply(formatter, [value].concat(__slice.call(args))); } else if (formatter instanceof Function) { value = formatter.apply(null, [value].concat(__slice.call(args))); } } return value; }; Binding.prototype.eventHandler = function(fn) { var binding, handler; handler = (binding = this).view.config.handler; return function(ev) { return handler.call(fn, this, ev, binding); }; }; Binding.prototype.set = function(value) { var _ref; value = value instanceof Function && !this.binder["function"] ? this.formattedValue(value.call(this.model)) : this.formattedValue(value); return (_ref = this.binder.routine) != null ? _ref.call(this, this.el, value) : void 0; }; Binding.prototype.sync = function() { return this.set(this.options.bypass ? this.model[this.keypath] : this.view.config.adapter.read(this.model, this.keypath)); }; Binding.prototype.publish = function() { var args, formatter, id, value, _i, _len, _ref, _ref1, _ref2; value = Rivets.Util.getInputValue(this.el); _ref = this.formatters.slice(0).reverse(); for (_i = 0, _len = _ref.length; _i < _len; _i++) { formatter = _ref[_i]; args = formatter.split(/\s+/); id = args.shift(); if ((_ref1 = this.view.formatters[id]) != null ? _ref1.publish : void 0) { value = (_ref2 = this.view.formatters[id]).publish.apply(_ref2, [value].concat(__slice.call(args))); } } return this.view.config.adapter.publish(this.model, this.keypath, value); }; Binding.prototype.bind = function() { var dependency, keypath, model, _i, _len, _ref, _ref1, _ref2, _results; if ((_ref = this.binder.bind) != null) { _ref.call(this, this.el); } if (this.options.bypass) { this.sync(); } else { this.view.config.adapter.subscribe(this.model, this.keypath, this.sync); if (this.view.config.preloadData) { this.sync(); } } if ((_ref1 = this.options.dependencies) != null ? _ref1.length : void 0) { _ref2 = this.options.dependencies; _results = []; for (_i = 0, _len = _ref2.length; _i < _len; _i++) { dependency = _ref2[_i]; if (/^\./.test(dependency)) { model = this.model; keypath = dependency.substr(1); } else { dependency = dependency.split('.'); model = this.view.models[dependency.shift()]; keypath = dependency.join('.'); } _results.push(this.view.config.adapter.subscribe(model, keypath, this.sync)); } return _results; } }; Binding.prototype.unbind = function() { var dependency, keypath, model, _i, _len, _ref, _ref1, _ref2, _results; if ((_ref = this.binder.unbind) != null) { _ref.call(this, this.el); } if (!this.options.bypass) { this.view.config.adapter.unsubscribe(this.model, this.keypath, this.sync); } if ((_ref1 = this.options.dependencies) != null ? _ref1.length : void 0) { _ref2 = this.options.dependencies; _results = []; for (_i = 0, _len = _ref2.length; _i < _len; _i++) { dependency = _ref2[_i]; if (/^\./.test(dependency)) { model = this.model; keypath = dependency.substr(1); } else { dependency = dependency.split('.'); model = this.view.models[dependency.shift()]; keypath = dependency.join('.'); } _results.push(this.view.config.adapter.unsubscribe(model, keypath, this.sync)); } return _results; } }; Binding.prototype.update = function(models) { var _ref; if (models == null) { models = {}; } if (this.key) { if (models[this.key]) { if (!this.options.bypass) { this.view.config.adapter.unsubscribe(this.model, this.keypath, this.sync); } this.model = models[this.key]; if (this.options.bypass) { this.sync(); } else { this.view.config.adapter.subscribe(this.model, this.keypath, this.sync); if (this.view.config.preloadData) { this.sync(); } } } } else { this.sync(); } return (_ref = this.binder.update) != null ? _ref.call(this, models) : void 0; }; return Binding; })(); Rivets.ComponentBinding = (function(_super) { __extends(ComponentBinding, _super); function ComponentBinding(view, el, type) { var attribute, _i, _len, _ref, _ref1; this.view = view; this.el = el; this.type = type; this.unbind = __bind(this.unbind, this); this.bind = __bind(this.bind, this); this.update = __bind(this.update, this); this.locals = __bind(this.locals, this); this.component = Rivets.components[this.type]; this.attributes = {}; this.inflections = {}; _ref = this.el.attributes || []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { attribute = _ref[_i]; if (_ref1 = attribute.name, __indexOf.call(this.component.attributes, _ref1) >= 0) { this.attributes[attribute.name] = attribute.value; } else { this.inflections[attribute.name] = attribute.value; } } } ComponentBinding.prototype.sync = function() {}; ComponentBinding.prototype.locals = function(models) { var inverse, key, model, path, result, _i, _len, _ref, _ref1; if (models == null) { models = this.view.models; } result = {}; _ref = this.inflections; for (key in _ref) { inverse = _ref[key]; _ref1 = inverse.split('.'); for (_i = 0, _len = _ref1.length; _i < _len; _i++) { path = _ref1[_i]; result[key] = (result[key] || models)[path]; } } for (key in models) { model = models[key]; if (result[key] == null) { result[key] = model; } } return result; }; ComponentBinding.prototype.update = function(models) { var _ref; return (_ref = this.componentView) != null ? _ref.update(this.locals(models)) : void 0; }; ComponentBinding.prototype.bind = function() { var el, _ref; if (this.componentView != null) { return (_ref = this.componentView) != null ? _ref.bind() : void 0; } else { el = this.component.build.call(this.attributes); (this.componentView = new Rivets.View(el, this.locals(), this.view.options)).bind(); return this.el.parentNode.replaceChild(el, this.el); } }; ComponentBinding.prototype.unbind = function() { var _ref; return (_ref = this.componentView) != null ? _ref.unbind() : void 0; }; return ComponentBinding; })(Rivets.Binding); Rivets.TextBinding = (function(_super) { __extends(TextBinding, _super); function TextBinding(view, el, type, key, keypath, options) { this.view = view; this.el = el; this.type = type; this.key = key; this.keypath = keypath; this.options = options != null ? options : {}; this.sync = __bind(this.sync, this); this.formatters = this.options.formatters || []; this.model = this.key ? this.view.models[this.key] : this.view.models; } TextBinding.prototype.binder = { routine: function(node, value) { return node.data = value != null ? value : ''; } }; TextBinding.prototype.sync = function() { return TextBinding.__super__.sync.apply(this, arguments); }; return TextBinding; })(Rivets.Binding); Rivets.View = (function() { function View(els, models, options) { var k, option, v, _base, _i, _len, _ref, _ref1, _ref2; this.els = els; this.models = models; this.options = options != null ? options : {}; this.update = __bind(this.update, this); this.publish = __bind(this.publish, this); this.sync = __bind(this.sync, this); this.unbind = __bind(this.unbind, this); this.bind = __bind(this.bind, this); this.select = __bind(this.select, this); this.build = __bind(this.build, this); this.componentRegExp = __bind(this.componentRegExp, this); this.bindingRegExp = __bind(this.bindingRegExp, this); if (!(this.els.jquery || this.els instanceof Array)) { this.els = [this.els]; } _ref = ['config', 'binders', 'formatters']; for (_i = 0, _len = _ref.length; _i < _len; _i++) { option = _ref[_i]; this[option] = {}; if (this.options[option]) { _ref1 = this.options[option]; for (k in _ref1) { v = _ref1[k]; this[option][k] = v; } } _ref2 = Rivets[option]; for (k in _ref2) { v = _ref2[k]; if ((_base = this[option])[k] == null) { _base[k] = v; } } } this.build(); } View.prototype.bindingRegExp = function() { var prefix; prefix = this.config.prefix; if (prefix) { return new RegExp("^data-" + prefix + "-"); } else { return /^data-/; } }; View.prototype.componentRegExp = function() { var _ref, _ref1; return new RegExp("^" + ((_ref = (_ref1 = this.config.prefix) != null ? _ref1.toUpperCase() : void 0) != null ? _ref : 'RV') + "-"); }; View.prototype.build = function() { var bindingRegExp, buildBinding, componentRegExp, el, parse, skipNodes, _i, _len, _ref, _this = this; this.bindings = []; skipNodes = []; bindingRegExp = this.bindingRegExp(); componentRegExp = this.componentRegExp(); buildBinding = function(binding, node, type, declaration) { var context, ctx, dependencies, key, keypath, options, path, pipe, pipes, splitPath; options = {}; pipes = (function() { var _i, _len, _ref, _results; _ref = declaration.split('|'); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { pipe = _ref[_i]; _results.push(pipe.trim()); } return _results; })(); context = (function() { var _i, _len, _ref, _results; _ref = pipes.shift().split('<'); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { ctx = _ref[_i]; _results.push(ctx.trim()); } return _results; })(); path = context.shift(); splitPath = path.split(/\.|:/); options.formatters = pipes; options.bypass = path.indexOf(':') !== -1; if (splitPath[0]) { key = splitPath.shift(); } else { key = null; splitPath.shift(); } keypath = splitPath.join('.'); if (dependencies = context.shift()) { options.dependencies = dependencies.split(/\s+/); } return _this.bindings.push(new Rivets[binding](_this, node, type, key, keypath, options)); }; parse = function(node) { var attribute, attributes, binder, childNode, delimiters, identifier, n, parser, regexp, restTokens, startToken, text, token, tokens, type, value, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4, _results; if (__indexOf.call(skipNodes, node) < 0) { if (node.nodeType === Node.TEXT_NODE) { parser = Rivets.TextTemplateParser; if (delimiters = _this.config.templateDelimiters) { if ((tokens = parser.parse(node.data, delimiters)).length) { if (!(tokens.length === 1 && tokens[0].type === parser.types.text)) { startToken = tokens[0], restTokens = 2 <= tokens.length ? __slice.call(tokens, 1) : []; node.data = startToken.value; if (startToken.type === 0) { node.data = startToken.value; } else { buildBinding('TextBinding', node, null, startToken.value); } for (_i = 0, _len = restTokens.length; _i < _len; _i++) { token = restTokens[_i]; text = document.createTextNode(token.value); node.parentNode.appendChild(text); if (token.type === 1) { buildBinding('TextBinding', text, null, token.value); } } } } } } else if (componentRegExp.test(node.tagName)) { type = node.tagName.replace(componentRegExp, '').toLowerCase(); _this.bindings.push(new Rivets.ComponentBinding(_this, node, type)); } else if (node.attributes != null) { _ref = node.attributes; for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { attribute = _ref[_j]; if (bindingRegExp.test(attribute.name)) { type = attribute.name.replace(bindingRegExp, ''); if (!(binder = _this.binders[type])) { _ref1 = _this.binders; for (identifier in _ref1) { value = _ref1[identifier]; if (identifier !== '*' && identifier.indexOf('*') !== -1) { regexp = new RegExp("^" + (identifier.replace('*', '.+')) + "$"); if (regexp.test(type)) { binder = value; } } } } binder || (binder = _this.binders['*']); if (binder.block) { _ref2 = node.childNodes; for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { n = _ref2[_k]; skipNodes.push(n); } attributes = [attribute]; } } } _ref3 = attributes || node.attributes; for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) { attribute = _ref3[_l]; if (bindingRegExp.test(attribute.name)) { type = attribute.name.replace(bindingRegExp, ''); buildBinding('Binding', node, type, attribute.value); } } } _ref4 = node.childNodes; _results = []; for (_m = 0, _len4 = _ref4.length; _m < _len4; _m++) { childNode = _ref4[_m]; _results.push(parse(childNode)); } return _results; } }; _ref = this.els; for (_i = 0, _len = _ref.length; _i < _len; _i++) { el = _ref[_i]; parse(el); } }; View.prototype.select = function(fn) { var binding, _i, _len, _ref, _results; _ref = this.bindings; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { binding = _ref[_i]; if (fn(binding)) { _results.push(binding); } } return _results; }; View.prototype.bind = function() { var binding, _i, _len, _ref, _results; _ref = this.bindings; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { binding = _ref[_i]; _results.push(binding.bind()); } return _results; }; View.prototype.unbind = function() { var binding, _i, _len, _ref, _results; _ref = this.bindings; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { binding = _ref[_i]; _results.push(binding.unbind()); } return _results; }; View.prototype.sync = function() { var binding, _i, _len, _ref, _results; _ref = this.bindings; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { binding = _ref[_i]; _results.push(binding.sync()); } return _results; }; View.prototype.publish = function() { var binding, _i, _len, _ref, _results; _ref = this.select(function(b) { return b.binder.publishes; }); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { binding = _ref[_i]; _results.push(binding.publish()); } return _results; }; View.prototype.update = function(models) { var binding, key, model, _i, _len, _ref, _results; if (models == null) { models = {}; } for (key in models) { model = models[key]; this.models[key] = model; } _ref = this.bindings; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { binding = _ref[_i]; _results.push(binding.update(models)); } return _results; }; return View; })(); Rivets.TextTemplateParser = (function() { function TextTemplateParser() {} TextTemplateParser.types = { text: 0, binding: 1 }; TextTemplateParser.parse = function(template, delimiters) { var index, lastIndex, lastToken, length, substring, tokens, value; tokens = []; length = template.length; index = 0; lastIndex = 0; while (lastIndex < length) { index = template.indexOf(delimiters[0], lastIndex); if (index < 0) { tokens.push({ type: this.types.text, value: template.slice(lastIndex) }); break; } else { if (index > 0 && lastIndex < index) { tokens.push({ type: this.types.text, value: template.slice(lastIndex, index) }); } lastIndex = index + 2; index = template.indexOf(delimiters[1], lastIndex); if (index < 0) { substring = template.slice(lastIndex - 2); lastToken = tokens[tokens.length - 1]; if ((lastToken != null ? lastToken.type : void 0) === this.types.text) { lastToken.value += substring; } else { tokens.push({ type: this.types.text, value: substring }); } break; } value = template.slice(lastIndex, index).trim(); tokens.push({ type: this.types.binding, value: value }); lastIndex = index + 2; } } return tokens; }; return TextTemplateParser; })(); Rivets.Util = { bindEvent: function(el, event, handler) { if (window.jQuery != null) { el = jQuery(el); if (el.on != null) { return el.on(event, handler); } else { return el.bind(event, handler); } } else if (window.addEventListener != null) { return el.addEventListener(event, handler, false); } else { event = 'on' + event; return el.attachEvent(event, handler); } }, unbindEvent: function(el, event, handler) { if (window.jQuery != null) { el = jQuery(el); if (el.off != null) { return el.off(event, handler); } else { return el.unbind(event, handler); } } else if (window.removeEventListener != null) { return el.removeEventListener(event, handler, false); } else { event = 'on' + event; return el.detachEvent(event, handler); } }, getInputValue: function(el) { var o, _i, _len, _results; if (window.jQuery != null) { el = jQuery(el); switch (el[0].type) { case 'checkbox': return el.is(':checked'); default: return el.val(); } } else { switch (el.type) { case 'checkbox': return el.checked; case 'select-multiple': _results = []; for (_i = 0, _len = el.length; _i < _len; _i++) { o = el[_i]; if (o.selected) { _results.push(o.value); } } return _results; break; default: return el.value; } } } }; Rivets.binders = { enabled: function(el, value) { return el.disabled = !value; }, disabled: function(el, value) { return el.disabled = !!value; }, checked: { publishes: true, bind: function(el) { return Rivets.Util.bindEvent(el, 'change', this.publish); }, unbind: function(el) { return Rivets.Util.unbindEvent(el, 'change', this.publish); }, routine: function(el, value) { var _ref; if (el.type === 'radio') { return el.checked = ((_ref = el.value) != null ? _ref.toString() : void 0) === (value != null ? value.toString() : void 0); } else { return el.checked = !!value; } } }, unchecked: { publishes: true, bind: function(el) { return Rivets.Util.bindEvent(el, 'change', this.publish); }, unbind: function(el) { return Rivets.Util.unbindEvent(el, 'change', this.publish); }, routine: function(el, value) { var _ref; if (el.type === 'radio') { return el.checked = ((_ref = el.value) != null ? _ref.toString() : void 0) !== (value != null ? value.toString() : void 0); } else { return el.checked = !value; } } }, show: function(el, value) { return el.style.display = value ? '' : 'none'; }, hide: function(el, value) { return el.style.display = value ? 'none' : ''; }, html: function(el, value) { return el.innerHTML = value != null ? value : ''; }, value: { publishes: true, bind: function(el) { return Rivets.Util.bindEvent(el, 'change', this.publish); }, unbind: function(el) { return Rivets.Util.unbindEvent(el, 'change', this.publish); }, routine: function(el, value) { var o, _i, _len, _ref, _ref1, _ref2, _results; if (window.jQuery != null) { el = jQuery(el); if ((value != null ? value.toString() : void 0) !== ((_ref = el.val()) != null ? _ref.toString() : void 0)) { return el.val(value != null ? value : ''); } } else { if (el.type === 'select-multiple') { if (value != null) { _results = []; for (_i = 0, _len = el.length; _i < _len; _i++) { o = el[_i]; _results.push(o.selected = (_ref1 = o.value, __indexOf.call(value, _ref1) >= 0)); } return _results; } } else if ((value != null ? value.toString() : void 0) !== ((_ref2 = el.value) != null ? _ref2.toString() : void 0)) { return el.value = value != null ? value : ''; } } } }, text: function(el, value) { if (el.innerText != null) { return el.innerText = value != null ? value : ''; } else { return el.textContent = value != null ? value : ''; } }, "if": { block: true, bind: function(el) { var attr, declaration; if (this.marker == null) { attr = ['data', this.view.config.prefix, this.type].join('-').replace('--', '-'); declaration = el.getAttribute(attr); this.marker = document.createComment(" rivets: " + this.type + " " + declaration + " "); el.removeAttribute(attr); el.parentNode.insertBefore(this.marker, el); return el.parentNode.removeChild(el); } }, unbind: function() { var _ref; return (_ref = this.nested) != null ? _ref.unbind() : void 0; }, routine: function(el, value) { var key, model, models, options, _ref; if (!!value === (this.nested == null)) { if (value) { models = {}; _ref = this.view.models; for (key in _ref) { model = _ref[key]; models[key] = model; } options = { binders: this.view.options.binders, formatters: this.view.options.formatters, config: this.view.options.config }; (this.nested = new Rivets.View(el, models, options)).bind(); return this.marker.parentNode.insertBefore(el, this.marker.nextSibling); } else { el.parentNode.removeChild(el); this.nested.unbind(); return delete this.nested; } } }, update: function(models) { var _ref; return (_ref = this.nested) != null ? _ref.update(models) : void 0; } }, unless: { block: true, bind: function(el) { return Rivets.binders["if"].bind.call(this, el); }, unbind: function() { return Rivets.binders["if"].unbind.call(this); }, routine: function(el, value) { return Rivets.binders["if"].routine.call(this, el, !value); }, update: function(models) { return Rivets.binders["if"].update.call(this, models); } }, "on-*": { "function": true, unbind: function(el) { if (this.handler) { return Rivets.Util.unbindEvent(el, this.args[0], this.handler); } }, routine: function(el, value) { if (this.handler) { Rivets.Util.unbindEvent(el, this.args[0], this.handler); } return Rivets.Util.bindEvent(el, this.args[0], this.handler = this.eventHandler(value)); } }, "each-*": { block: true, bind: function(el) { var attr; if (this.marker == null) { attr = ['data', this.view.config.prefix, this.type].join('-').replace('--', '-'); this.marker = document.createComment(" rivets: " + this.type + " "); this.iterated = []; el.removeAttribute(attr); el.parentNode.insertBefore(this.marker, el); return el.parentNode.removeChild(el); } }, unbind: function(el) { var view, _i, _len, _ref, _results; if (this.iterated != null) { _ref = this.iterated; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { view = _ref[_i]; _results.push(view.unbind()); } return _results; } }, routine: function(el, collection) { var data, i, index, k, key, model, modelName, options, previous, template, v, view, _i, _j, _len, _len1, _ref, _ref1, _ref2, _results; modelName = this.args[0]; collection = collection || []; if (this.iterated.length > collection.length) { _ref = Array(this.iterated.length - collection.length); for (_i = 0, _len = _ref.length; _i < _len; _i++) { i = _ref[_i]; view = this.iterated.pop(); view.unbind(); this.marker.parentNode.removeChild(view.els[0]); } } _results = []; for (index = _j = 0, _len1 = collection.length; _j < _len1; index = ++_j) { model = collection[index]; data = {}; data[modelName] = model; if (this.iterated[index] == null) { _ref1 = this.view.models; for (key in _ref1) { model = _ref1[key]; if (data[key] == null) { data[key] = model; } } previous = this.iterated.length ? this.iterated[this.iterated.length - 1].els[0] : this.marker; options = { binders: this.view.options.binders, formatters: this.view.options.formatters, config: {} }; _ref2 = this.view.options.config; for (k in _ref2) { v = _ref2[k]; options.config[k] = v; } options.config.preloadData = true; template = el.cloneNode(true); view = new Rivets.View(template, data, options); view.bind(); this.iterated.push(view); _results.push(this.marker.parentNode.insertBefore(template, previous.nextSibling)); } else if (this.iterated[index].models[modelName] !== model) { _results.push(this.iterated[index].update(data)); } else { _results.push(void 0); } } return _results; }, update: function(models) { var data, key, model, view, _i, _len, _ref, _results; data = {}; for (key in models) { model = models[key]; if (key !== this.args[0]) { data[key] = model; } } _ref = this.iterated; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { view = _ref[_i]; _results.push(view.update(data)); } return _results; } }, "class-*": function(el, value) { var elClass; elClass = " " + el.className + " "; if (!value === (elClass.indexOf(" " + this.args[0] + " ") !== -1)) { return el.className = value ? "" + el.className + " " + this.args[0] : elClass.replace(" " + this.args[0] + " ", ' ').trim(); } }, "*": function(el, value) { if (value) { return el.setAttribute(this.type, value); } else { return el.removeAttribute(this.type); } } }; Rivets.components = {}; Rivets.config = { preloadData: true, handler: function(context, ev, binding) { return this.call(context, ev, binding.view.models); } }; Rivets.formatters = {}; Rivets.factory = function(exports) { exports._ = Rivets; exports.binders = Rivets.binders; exports.components = Rivets.components; exports.formatters = Rivets.formatters; exports.config = Rivets.config; exports.configure = function(options) { var property, value; if (options == null) { options = {}; } for (property in options) { value = options[property]; Rivets.config[property] = value; } }; return exports.bind = function(el, models, options) { var view; if (models == null) { models = {}; } if (options == null) { options = {}; } view = new Rivets.View(el, models, options); view.bind(); return view; }; }; if (typeof exports === 'object') { Rivets.factory(exports); } else if (typeof define === 'function' && define.amd) { define(['exports'], function(exports) { Rivets.factory(this.rivets = exports); return exports; }); } else { Rivets.factory(this.rivets = {}); } }).call(this); }); require.register("segmentio-extend/index.js", function(exports, require, module){ module.exports = function extend (object) { // Takes an unlimited number of extenders. var args = Array.prototype.slice.call(arguments, 1); // For each extender, copy their properties on our object. for (var i = 0, source; source = args[i]; i++) { if (!source) continue; for (var property in source) { object[property] = source[property]; } } return object; }; }); require.register("pluma-assimilate/dist/assimilate.js", function(exports, require, module){ /*! assimilate 0.3.0 Copyright (c) 2013 Alan Plum. MIT licensed. */ var slice = Array.prototype.slice; function bind(fn, self) { var args = slice.call(arguments, 2); if (typeof Function.prototype.bind === 'function') { return Function.prototype.bind.apply(fn, [self].concat(args)); } return function() { return fn.apply(self, args.concat(slice.call(arguments, 0))); }; } function simpleCopy(target, name, source) { target[name] = source[name]; } function properCopy(target, name, source) { var descriptor = Object.getOwnPropertyDescriptor(source, name); Object.defineProperty(target, name, descriptor); } function ownProperties(obj) { return Object.getOwnPropertyNames(obj); } function allKeys(obj) { var keys = []; for (var name in obj) { keys.push(name); } return keys; } function ownKeys(obj) { var keys = []; for (var name in obj) { if (obj.hasOwnProperty(name)) { keys.push(name); } } return keys; } function assimilateWithStrategy(target) { var strategy = this, sources = slice.call(arguments, 1), i, source, names, j, name; if (target === undefined || target === null) { target = {}; } for (i = 0; i < sources.length; i++) { source = sources[i]; names = strategy.keysFn(source); for (j = 0; j < names.length; j++) { name = names[j]; strategy.copyFn(target, name, source); } } return target; } var strategies = { DEFAULT: { keysFn: ownKeys, copyFn: simpleCopy }, PROPER: { keysFn: ownProperties, copyFn: properCopy }, INHERITED: { keysFn: allKeys, copyFn: simpleCopy }, DEEP: { keysFn: ownKeys, copyFn: function recursiveCopy(target, name, source) { var val = source[name]; var old = target[name]; if (typeof val === 'object' && typeof old === 'object') { assimilateWithStrategy.call(strategies.DEEP, old, val); } else { simpleCopy(target, name, source); } } }, STRICT: { keysFn: ownKeys, copyFn: function strictCopy(target, name, source) { if (source[name] !== undefined) { simpleCopy(target, name, source); } } }, FALLBACK: { keysFn: function fallbackCopy(target, name, source) { if (target[name] === undefined) { simpleCopy(target, name, source); } }, copyFn: simpleCopy } }; var assimilate = bind(assimilateWithStrategy, strategies.DEFAULT); assimilate.strategies = strategies; assimilate.withStrategy = function withStrategy(strategy) { if (typeof strategy === 'string') { strategy = strategies[strategy.toUpperCase()]; } if (!strategy) { throw new Error('Unknwon or invalid strategy:' + strategy); } if (typeof strategy.copyFn !== 'function') { throw new Error('Strategy missing copy function:' + strategy); } if (typeof strategy.keysFn !== 'function') { throw new Error('Strategy missing keys function:' + strategy); } return bind(assimilateWithStrategy, strategy); }; module.exports = assimilate; }); require.register("paulmillr-es6-shim/es6-shim.js", function(exports, require, module){ // ES6-shim 0.9.1 (c) 2013 Paul Miller (http://paulmillr.com) // ES6-shim may be freely distributed under the MIT license. // For more details and documentation: // https://github.com/paulmillr/es6-shim/ (function(undefined) { 'use strict'; var arePropertyDescriptorsSupported = function() { try { Object.defineProperty({}, 'x', {}); return true; } catch (e) { /* this is IE 8. */ return false; } }; var main = function() { var globals = (typeof global === 'undefined') ? window : global; var global_isFinite = globals.isFinite; var supportsDescriptors = !!Object.defineProperty && arePropertyDescriptorsSupported(); var _slice = Array.prototype.slice; var _indexOf = String.prototype.indexOf; var _toString = Object.prototype.toString; var _hasOwnProperty = Object.prototype.hasOwnProperty; // Define configurable, writable and non-enumerable props // if they don’t exist. var defineProperties = function(object, map) { Object.keys(map).forEach(function(name) { var method = map[name]; if (name in object) return; if (supportsDescriptors) { Object.defineProperty(object, name, { configurable: true, enumerable: false, writable: true, value: method }); } else { object[name] = method; } }); }; var ES = { ToInt32: function(x) { return x >> 0; }, ToUint32: function(x) { return x >>> 0; }, toInteger: function(value) { var number = +value; if (Number.isNaN(number)) return 0; if (number === 0 || !Number.isFinite(number)) return number; return Math.sign(number) * Math.floor(Math.abs(number)); } }; defineProperties(String, { fromCodePoint: function() { var points = _slice.call(arguments, 0); var result = []; var next; for (var i = 0, length = points.length; i < length; i++) { next = Number(points[i]); if (!Object.is(next, ES.toInteger(next)) || next < 0 || next > 0x10FFFF) { throw new RangeError('Invalid code point ' + next); } if (next < 0x10000) { result.push(String.fromCharCode(next)); } else { next -= 0x10000; result.push(String.fromCharCode((next >> 10) + 0xD800)); result.push(String.fromCharCode((next % 0x400) + 0xDC00)); } } return result.join(''); }, raw: function() { var callSite = arguments[0]; var substitutions = _slice.call(arguments, 1); var cooked = Object(callSite); var rawValue = cooked.raw; var raw = Object(rawValue); var len = Object.keys(raw).length; var literalsegments = ES.ToUint32(len); if (literalsegments === 0) { return ''; } var stringElements = []; var nextIndex = 0; var nextKey, next, nextSeg, nextSub; while (nextIndex < literalsegments) { nextKey = String(nextIndex); next = raw[nextKey]; nextSeg = String(next); stringElements.push(nextSeg); if (nextIndex + 1 >= literalsegments) { break; } next = substitutions[nextKey]; if (next === undefined) { break; } nextSub = String(next); stringElements.push(nextSub); nextIndex++; } return stringElements.join(''); } }); defineProperties(String.prototype, { // Fast repeat, uses the `Exponentiation by squaring` algorithm. // Perf: http://jsperf.com/string-repeat2/2 repeat: (function() { var repeat = function(s, times) { if (times < 1) return ''; if (times % 2) return repeat(s, times - 1) + s; var half = repeat(s, times / 2); return half + half; }; return function(times) { times = ES.toInteger(times); if (times < 0 || times === Infinity) { throw new RangeError(); } return repeat(String(this), times); }; })(), startsWith: function(searchStr) { if (this == null) throw new TypeError("Cannot call method 'startsWith' of " + this); var thisStr = String(this); searchStr = String(searchStr); var start = Math.max(ES.toInteger(arguments[1]), 0); return thisStr.substr(start, searchStr.length) === searchStr; }, endsWith: function(searchStr) { if (this == null) throw new TypeError("Cannot call method 'endsWith' of " + this); var thisStr = String(this); searchStr = String(searchStr); var thisLen = thisStr.length; var pos = (arguments[1] === undefined) ? thisLen : ES.toInteger(arguments[1]); var end = Math.min(pos, thisLen); return thisStr.slice(end - searchStr.length, end) === searchStr; }, contains: function(searchString) { var position = arguments[1]; // Somehow this trick makes method 100% compat with the spec. return _indexOf.call(this, searchString, position) !== -1; }, codePointAt: function(pos) { var s = String(this); var position = ES.toInteger(pos); var length = s.length; if (position < 0 || position >= length) return undefined; var first = s.charCodeAt(position); var isEnd = (position + 1 === length); if (first < 0xD800 || first > 0xDBFF || isEnd) return first; var second = s.charCodeAt(position + 1); if (second < 0xDC00 || second > 0xDFFF) return first; return ((first - 0xD800) * 1024) + (second - 0xDC00) + 0x10000; } }); defineProperties(Array, { from: function(iterable) { var mapFn = arguments[1]; var thisArg = arguments[2]; if (mapFn !== undefined && _toString.call(mapFn) !== '[object Function]') { throw new TypeError('when provided, the second argument must be a function'); } var list = Object(iterable); var length = ES.ToUint32(list.length); var result = typeof this === 'function' ? Object(new this(length)) : new Array(length); for (var i = 0; i < length; i++) { var value = list[i]; if (mapFn !== undefined) { result[i] = thisArg ? mapFn.call(thisArg, value) : mapFn(value); } else { result[i] = value; } } result.length = length; return result; }, of: function() { return Array.from(arguments); } }); defineProperties(globals, { ArrayIterator: function(array, kind) { this.i = 0; this.array = array; this.kind = kind; } }); defineProperties(ArrayIterator.prototype, { next: function() { var i = this.i; this.i = i + 1; var array = this.array; if (i >= array.length) { throw new Error(); } if (array.hasOwnProperty(i)) { var kind = this.kind; var retval; if (kind === "key") { retval = i; } if (kind === "value") { retval = array[i]; } if (kind === "entry") { retval = [i, array[i]]; } } else { retval = this.next(); } return retval; } }); defineProperties(Array.prototype, { copyWithin: function(target, start) { var o = Object(this); var len = Math.max(ES.toInteger(o.length), 0); var to = target < 0 ? Math.max(len + target, 0) : Math.min(target, len); var from = start < 0 ? Math.max(len + start, 0) : Math.min(start, len); var end = arguments.length > 2 ? arguments[2] : len; var final = end < 0 ? Math.max(len + end, 0) : Math.min(end, len); var count = Math.min(final - from, len - to); var direction = 1; if (from < to && to < (from + count)) { direction = -1; from += count - 1; to += count - 1; } while (count > 0) { if (_hasOwnProperty.call(o, from)) { o[to] = o[from]; } else { delete o[from]; } from += direction; to += direction; count -= 1; } return o; }, fill: function(value) { var len = this.length; var start = arguments.length > 1 ? ES.toInteger(arguments[1]) : 0; var end = arguments.length > 2 ? ES.toInteger(arguments[2]) : len; var relativeStart = start < 0 ? Math.max(len + start, 0) : Math.min(start, len); for (var i = relativeStart; i < len && i < end; ++i) { this[i] = value; } return this; }, find: function(predicate) { var list = Object(this); var length = ES.ToUint32(list.length); if (length === 0) return undefined; if (typeof predicate !== 'function') { throw new TypeError('Array#find: predicate must be a function'); } var thisArg = arguments[1]; for (var i = 0, value; i < length && i in list; i++) { value = list[i]; if (predicate.call(thisArg, value, i, list)) return value; } return undefined; }, findIndex: function(predicate) { var list = Object(this); var length = ES.ToUint32(list.length); if (length === 0) return -1; if (typeof predicate !== 'function') { throw new TypeError('Array#findIndex: predicate must be a function'); } var thisArg = arguments[1]; for (var i = 0, value; i < length && i in list; i++) { value = list[i]; if (predicate.call(thisArg, value, i, list)) return i; } return -1; }, keys: function() { return new ArrayIterator(this, "key"); }, values: function() { return new ArrayIterator(this, "value"); }, entries: function() { return new ArrayIterator(this, "entry"); } }); var maxSafeInteger = Math.pow(2, 53) - 1; defineProperties(Number, { MAX_SAFE_INTEGER: maxSafeInteger, MIN_SAFE_INTEGER: -maxSafeInteger, EPSILON: 2.220446049250313e-16, parseInt: globals.parseInt, parseFloat: globals.parseFloat, isFinite: function(value) { return typeof value === 'number' && global_isFinite(value); }, isSafeInteger: function(value) { return typeof value === 'number' && !Number.isNaN(value) && Number.isFinite(value) && parseInt(value, 10) === value && Math.abs(value) <= Number.MAX_SAFE_INTEGER; }, isNaN: function(value) { // NaN !== NaN, but they are identical. // NaNs are the only non-reflexive value, i.e., if x !== x, // then x is NaN. // isNaN is broken: it converts its argument to number, so // isNaN('foo') => true return value !== value; } }); defineProperties(Number.prototype, { clz: function() { var number = +this; if (!number || !Number.isFinite(number)) return 32; number = number < 0 ? Math.ceil(number) : Math.floor(number); number = number - Math.floor(number / 0x100000000) * 0x100000000; return 32 - (number).toString(2).length; } }); if (supportsDescriptors) { defineProperties(Object, { getOwnPropertyDescriptors: function(subject) { var descs = {}; Object.getOwnPropertyNames(subject).forEach(function(propName) { descs[propName] = Object.getOwnPropertyDescriptor(subject, propName); }); return descs; }, getPropertyDescriptor: function(subject, name) { var pd = Object.getOwnPropertyDescriptor(subject, name); var proto = Object.getPrototypeOf(subject); while (pd === undefined && proto !== null) { pd = Object.getOwnPropertyDescriptor(proto, name); proto = Object.getPrototypeOf(proto); } return pd; }, getPropertyNames: function(subject) { var result = Object.getOwnPropertyNames(subject); var proto = Object.getPrototypeOf(subject); var addProperty = function(property) { if (result.indexOf(property) === -1) { result.push(property); } }; while (proto !== null) { Object.getOwnPropertyNames(proto).forEach(addProperty); proto = Object.getPrototypeOf(proto); } return result; }, // 19.1.3.1 assign: function(target, source) { return Object.keys(source).reduce(function(target, key) { target[key] = source[key]; return target; }, target); }, // 19.1.3.15 mixin: function(target, source) { var props = Object.getOwnPropertyNames(source); return props.reduce(function(target, property) { var descriptor = Object.getOwnPropertyDescriptor(source, property); return Object.defineProperty(target, property, descriptor); }, target); } }); // 19.1.3.9 // shim from https://gist.github.com/WebReflection/5593554 defineProperties(Object, { setPrototypeOf: (function(Object, magic) { var set; var checkArgs = function(O, proto) { if (typeof O !== 'object' || O === null) { throw new TypeError('cannot set prototype on a non-object'); } if (typeof proto !== 'object') { throw new TypeError('can only set prototype to an object or null'); } }; var setPrototypeOf = function(O, proto) { checkArgs(O, proto); set.call(O, proto); return O; }; try { // this works already in Firefox and Safari set = Object.getOwnPropertyDescriptor(Object.prototype, magic).set; set.call({}, null); } catch (e) { if (Object.prototype !== {}[magic]) { // IE < 11 cannot be shimmed return; } // probably Chrome or some old Mobile stock browser set = function(proto) { this[magic] = proto; }; // please note that this will **not** work // in those browsers that do not inherit // __proto__ by mistake from Object.prototype // in these cases we should probably throw an error // or at least be informed about the issue setPrototypeOf.polyfill = setPrototypeOf( setPrototypeOf({}, null), Object.prototype ) instanceof Object; // setPrototypeOf.polyfill === true means it works as meant // setPrototypeOf.polyfill === false means it's not 100% reliable // setPrototypeOf.polyfill === undefined // or // setPrototypeOf.polyfill == null means it's not a polyfill // which means it works as expected // we can even delete Object.prototype.__proto__; } return setPrototypeOf; })(Object, '__proto__') }); } defineProperties(Object, { getOwnPropertyKeys: function(subject) { return Object.keys(subject); }, is: function(a, b) { if (a === b) { // 0 === -0, but they are not identical. if (a === 0) return 1 / a === 1 / b; return true; } return Number.isNaN(a) && Number.isNaN(b); } }); defineProperties(Math, { acosh: function(value) { value = Number(value); if (Number.isNaN(value) || value < 1) return NaN; if (value === 1) return 0; if (value === Infinity) return value; return Math.log(value + Math.sqrt(value * value - 1)); }, asinh: function(value) { value = Number(value); if (value === 0 || !global_isFinite(value)) { return value; } return Math.log(value + Math.sqrt(value * value + 1)); }, atanh: function(value) { value = Number(value); if (Number.isNaN(value) || value < -1 || value > 1) { return NaN; } if (value === -1) return -Infinity; if (value === 1) return Infinity; if (value === 0) return value; return 0.5 * Math.log((1 + value) / (1 - value)); }, cbrt: function(value) { value = Number(value); if (value === 0) return value; var negate = value < 0, result; if (negate) value = -value; result = Math.pow(value, 1/3); return negate ? -result : result; }, cosh: function(value) { value = Number(value); if (value === 0) return 1; // +0 or -0 if (!global_isFinite(value)) return value; if (value < 0) value = -value; if (value > 21) return Math.exp(value) / 2; return (Math.exp(value) + Math.exp(-value)) / 2; }, expm1: function(value) { value = Number(value); if (value === -Infinity) return -1; if (!global_isFinite(value) || value === 0) return value; var result = 0; var n = 50; for (var i = 1; i < n; i++) { for (var j = 2, factorial = 1; j <= i; j++) { factorial *= j; } result += Math.pow(value, i) / factorial; } return result; }, hypot: function(x, y) { var anyNaN = false; var allZero = true; var anyInfinity = false; var numbers = []; Array.prototype.every.call(arguments, function(arg) { var num = Number(arg); if (Number.isNaN(num)) anyNaN = true; else if (num === Infinity || num === -Infinity) anyInfinity = true; else if (num !== 0) allZero = false; if (anyInfinity) { return false; } else if (!anyNaN) { numbers.push(Math.abs(num)); } return true; }); if (anyInfinity) return Infinity; if (anyNaN) return NaN; if (allZero) return 0; numbers.sort(function (a, b) { return b - a; }); var largest = numbers[0]; var divided = numbers.map(function (number) { return number / largest; }); var sum = divided.reduce(function (sum, number) { return sum += number * number; }, 0); return largest * Math.sqrt(sum); }, log2: function(value) { return Math.log(value) * Math.LOG2E; }, log10: function(value) { return Math.log(value) * Math.LOG10E; }, log1p: function(value) { value = Number(value); if (value < -1 || Number.isNaN(value)) return NaN; if (value === 0 || value === Infinity) return value; if (value === -1) return -Infinity; var result = 0; var n = 50; if (value < 0 || value > 1) return Math.log(1 + value); for (var i = 1; i < n; i++) { if ((i % 2) === 0) { result -= Math.pow(value, i) / i; } else { result += Math.pow(value, i) / i; } } return result; }, sign: function(value) { var number = +value; if (number === 0) return number; if (Number.isNaN(number)) return number; return number < 0 ? -1 : 1; }, sinh: function(value) { value = Number(value); if (!global_isFinite(value) || value === 0) return value; return (Math.exp(value) - Math.exp(-value)) / 2; }, tanh: function(value) { value = Number(value); if (Number.isNaN(value) || value === 0) return value; if (value === Infinity) return 1; if (value === -Infinity) return -1; return (Math.exp(value) - Math.exp(-value)) / (Math.exp(value) + Math.exp(-value)); }, trunc: function(value) { var number = Number(value); return number < 0 ? -Math.floor(-number) : Math.floor(number); }, imul: function(x, y) { // taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul var ah = (x >>> 16) & 0xffff; var al = x & 0xffff; var bh = (y >>> 16) & 0xffff; var bl = y & 0xffff; // the shift by 0 fixes the sign on the high part // the final |0 converts the unsigned value into a signed value return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0)|0); } }); // Map and Set require a true ES5 environment if (supportsDescriptors) { var fastkey = function fastkey(key) { var type = typeof key; if (type === 'string') { return '$' + key; } else if (type === 'number' && !Object.is(key, -0)) { return key; } return null; }; var emptyObject = function emptyObject() { // accomodate some older not-quite-ES5 browsers return Object.create ? Object.create(null) : {}; }; var collectionShims = { Map: (function() { var empty = {}; function MapEntry(key, value) { this.key = key; this.value = value; this.next = null; this.prev = null; } MapEntry.prototype.isRemoved = function() { return this.key === empty; }; function MapIterator(map, kind) { this.head = map._head; this.i = this.head.next; this.kind = kind; } MapIterator.prototype = { next: function() { var i = this.i, kind = this.kind, head = this.head, result; while (i !== head) { this.i = i.next; if (!i.isRemoved()) { if (kind === "key") { result = i.key; } else if (kind === "value") { result = i.value; } else { result = [i.key, i.value]; } return { value: result, done: false }; } i = this.i; } return { value: undefined, done: true }; } }; function Map() { if (!(this instanceof Map)) throw new TypeError('Map must be called with "new"'); var head = new MapEntry(null, null); // circular doubly-linked list. head.next = head.prev = head; defineProperties(this, { '_head': head, '_storage': emptyObject(), '_size': 0 }); } Object.defineProperty(Map.prototype, 'size', { configurable: true, enumerable: false, get: function() { return this._size; } }); defineProperties(Map.prototype, { get: function(key) { var fkey = fastkey(key); if (fkey !== null) { // fast O(1) path var entry = this._storage[fkey]; return entry ? entry.value : undefined; } var head = this._head, i = head; while ((i = i.next) !== head) { if (Object.is(i.key, key)) { return i.value; } } return undefined; }, has: function(key) { var fkey = fastkey(key); if (fkey !== null) { // fast O(1) path return fkey in this._storage; } var head = this._head, i = head; while ((i = i.next) !== head) { if (Object.is(i.key, key)) { return true; } } return false; }, set: function(key, value) { var head = this._head, i = head, entry; var fkey = fastkey(key); if (fkey !== null) { // fast O(1) path if (fkey in this._storage) { this._storage[fkey].value = value; return; } else { entry = this._storage[fkey] = new MapEntry(key, value); i = head.prev; // fall through } } while ((i = i.next) !== head) { if (Object.is(i.key, key)) { i.value = value; return; } } entry = entry ? entry : new MapEntry(key, value); entry.next = this._head; entry.prev = this._head.prev; entry.prev.next = entry; entry.next.prev = entry; this._size += 1; }, 'delete': function(key) { var head = this._head, i = head; var fkey = fastkey(key); if (fkey !== null) { // fast O(1) path if (!(fkey in this._storage)) { return false; } i = this._storage[fkey].prev; delete this._storage[fkey]; // fall through } while ((i = i.next) !== head) { if (Object.is(i.key, key)) { i.key = i.value = empty; i.prev.next = i.next; i.next.prev = i.prev; this._size -= 1; return true; } } return false; }, clear: function() { this._size = 0; this._storage = emptyObject(); var head = this._head, i = head, p = i.next; while ((i = p) !== head) { i.key = i.value = empty; p = i.next; i.next = i.prev = head; } head.next = head.prev = head; }, keys: function() { return new MapIterator(this, "key"); }, values: function() { return new MapIterator(this, "value"); }, entries: function() { return new MapIterator(this, "key+value"); }, forEach: function(callback) { var context = arguments.length > 1 ? arguments[1] : null; var entireMap = this; var head = this._head, i = head; while ((i = i.next) !== head) { if (!i.isRemoved()) { callback.call(context, i.value, i.key, entireMap); } } } }); return Map; })(), Set: (function() { // Creating a Map is expensive. To speed up the common case of // Sets containing only string or numeric keys, we use an object // as backing storage and lazily create a full Map only when // required. var SetShim = function Set() { if (!(this instanceof SetShim)) throw new TypeError('Set must be called with "new"'); defineProperties(this, { '[[SetData]]': null, '_storage': emptyObject() }); }; // Switch from the object backing storage to a full Map. var ensureMap = function ensureMap(set) { if (!set['[[SetData]]']) { var m = set['[[SetData]]'] = new collectionShims.Map(); Object.keys(set._storage).forEach(function(k) { // fast check for leading '$' if (k.charCodeAt(0) === 36) { k = k.substring(1); } else { k = +k; } m.set(k, k); }); set._storage = null; // free old backing storage } }; Object.defineProperty(SetShim.prototype, 'size', { configurable: true, enumerable: false, get: function() { ensureMap(this); return this['[[SetData]]'].size; } }); defineProperties(SetShim.prototype, { has: function(key) { var fkey; if (this._storage && (fkey = fastkey(key)) !== null) { return !!this._storage[fkey]; } ensureMap(this); return this['[[SetData]]'].has(key); }, add: function(key) { var fkey; if (this._storage && (fkey = fastkey(key)) !== null) { this._storage[fkey]=true; return; } ensureMap(this); return this['[[SetData]]'].set(key, key); }, 'delete': function(key) { var fkey; if (this._storage && (fkey = fastkey(key)) !== null) { delete this._storage[fkey]; return; } ensureMap(this); return this['[[SetData]]']['delete'](key); }, clear: function() { if (this._storage) { this._storage = emptyObject(); return; } return this['[[SetData]]'].clear(); }, keys: function() { ensureMap(this); return this['[[SetData]]'].keys(); }, values: function() { ensureMap(this); return this['[[SetData]]'].values(); }, entries: function() { ensureMap(this); return this['[[SetData]]'].entries(); }, forEach: function(callback) { var context = arguments.length > 1 ? arguments[1] : null; var entireSet = this; ensureMap(this); this['[[SetData]]'].forEach(function(value, key) { callback.call(context, key, key, entireSet); }); } }); return SetShim; })() }; defineProperties(globals, collectionShims); if (globals.Map || globals.Set) { /* - In Firefox < 23, Map#size is a function. - In all current Firefox, Set#entries/keys/values & Map#clear do not exist - https://bugzilla.mozilla.org/show_bug.cgi?id=869996 - In Firefox 24, Map and Set do not implement forEach */ if ( typeof globals.Map.prototype.clear !== 'function' || new globals.Set().size !== 0 || new globals.Map().size !== 0 || typeof globals.Set.prototype.keys !== 'function' || typeof globals.Map.prototype.forEach !== 'function' || typeof globals.Set.prototype.forEach !== 'function' ) { globals.Map = collectionShims.Map; globals.Set = collectionShims.Set; } } } }; if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) { define(main); // RequireJS } else { main(); // CommonJS and