From b82d69afc93ac195ebc28399461153056f00c5a2 Mon Sep 17 00:00:00 2001 From: Ben Styles Date: Wed, 10 Aug 2016 12:35:23 +0100 Subject: [PATCH] Build 0.9.2 --- bower.json | 2 +- component.json | 2 +- dist/rivets.bundled.js | 2314 ++++++++++++++++++++++++++++++++++++ dist/rivets.bundled.min.js | 6 +- dist/rivets.js | 62 +- dist/rivets.min.js | 4 +- package.json | 2 +- 7 files changed, 2359 insertions(+), 33 deletions(-) create mode 100644 dist/rivets.bundled.js diff --git a/bower.json b/bower.json index 7f960696a..4f5b965cd 100644 --- a/bower.json +++ b/bower.json @@ -2,7 +2,7 @@ "name": "rivets", "description": "Declarative data binding + templating solution.", "homepage": "http://rivetsjs.com", - "version": "0.9.1", + "version": "0.9.2", "main": "dist/rivets.js", "license": "MIT", "authors": [ diff --git a/component.json b/component.json index 781e42ca1..a97706a53 100644 --- a/component.json +++ b/component.json @@ -2,7 +2,7 @@ "name": "rivets", "description": "Declarative data binding + templating solution.", "repo": "mikeric/rivets", - "version": "0.9.1", + "version": "0.9.2", "keywords": [ "data binding", "templating" diff --git a/dist/rivets.bundled.js b/dist/rivets.bundled.js new file mode 100644 index 000000000..bedbac04f --- /dev/null +++ b/dist/rivets.bundled.js @@ -0,0 +1,2314 @@ +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(); + else if(typeof define === 'function' && define.amd) + define([], factory); + else if(typeof exports === 'object') + exports["rivets"] = factory(); + else + root["rivets"] = factory(); +})(this, function() { +return /******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; + +/******/ // The require function +/******/ function __webpack_require__(moduleId) { + +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; + +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; + +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); + +/******/ // Flag the module as loaded +/******/ module.loaded = true; + +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } + + +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; + +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; + +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; + +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { + if (true) { + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [module, exports, __webpack_require__(1), __webpack_require__(2), __webpack_require__(4), __webpack_require__(8), __webpack_require__(9)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('sightglass'), require('./rivets'), require('./view'), require('./adapter'), require('./binders')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.sightglass, global.rivets, global.view, global.adapter, global.binders); + global._export = mod.exports; + } + })(this, function (module, exports, _sightglass, _rivets, _view, _adapter, _binders) { + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + var _sightglass2 = _interopRequireDefault(_sightglass); + + var _rivets2 = _interopRequireDefault(_rivets); + + var _view2 = _interopRequireDefault(_view); + + var _adapter2 = _interopRequireDefault(_adapter); + + var _binders2 = _interopRequireDefault(_binders); + + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + + // Module factory. Integrates sightglass and public API methods. Returns the + // public interface. + var factory = function factory(sightglass) { + _rivets2.default.sightglass = sightglass; + _rivets2.default.binders = _binders2.default; + _rivets2.default.adapters['.'] = _adapter2.default; + + // Binds some data to a template / element. Retuddrns a Rivets.View instance. + _rivets2.default.bind = function (el) { + var models = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; + var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; + + var view = new _view2.default(el, models, options); + view.bind(); + return view; + }; + + // Initializes a new instance of a component on the specified element and + // returns a Rivets.View instance. + _rivets2.default.init = function (_component, el) { + var data = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; + + if (!el) { + el = document.createElement('div'); + } + + var component = _rivets2.default.components[_component]; + el.innerHTML = component.template.call(_rivets2.default, el); + var scope = component.initialize.call(_rivets2.default, el, data); + + var view = new _view2.default(el, scope); + view.bind(); + return view; + }; + + return _rivets2.default; + }; + + exports.default = factory(_sightglass2.default); + module.exports = exports['default']; + }); + +/***/ }, +/* 1 */ +/***/ function(module, exports, __webpack_require__) { + + var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { + if (true) { + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [module], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + } else if (typeof exports !== "undefined") { + factory(module); + } else { + var mod = { + exports: {} + }; + factory(mod); + global.index = mod.exports; + } + })(this, function (module) { + 'use strict'; + + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; + }; + + (function () { + // Public sightglass interface. + function sightglass(obj, keypath, callback, options) { + return new Observer(obj, keypath, callback, options); + } + + // Batteries not included. + sightglass.adapters = {}; + + // Constructs a new keypath observer and kicks things off. + function Observer(obj, keypath, callback, options) { + this.options = options || {}; + this.options.adapters = this.options.adapters || {}; + this.obj = obj; + this.keypath = keypath; + this.callback = callback; + this.objectPath = []; + this.update = this.update.bind(this); + this.parse(); + + if (isObject(this.target = this.realize())) { + this.set(true, this.key, this.target, this.callback); + } + } + + // Tokenizes the provided keypath string into interface + path tokens for the + // observer to work with. + Observer.tokenize = function (keypath, interfaces, root) { + var tokens = []; + var current = { i: root, path: '' }; + var index, chr; + + for (index = 0; index < keypath.length; index++) { + chr = keypath.charAt(index); + + if (!!~interfaces.indexOf(chr)) { + tokens.push(current); + current = { i: chr, path: '' }; + } else { + current.path += chr; + } + } + + tokens.push(current); + return tokens; + }; + + // Parses the keypath using the interfaces defined on the view. Sets variables + // for the tokenized keypath as well as the end key. + Observer.prototype.parse = function () { + var interfaces = this.interfaces(); + var root, path; + + if (!interfaces.length) { + error('Must define at least one adapter interface.'); + } + + if (!!~interfaces.indexOf(this.keypath[0])) { + root = this.keypath[0]; + path = this.keypath.substr(1); + } else { + if (typeof (root = this.options.root || sightglass.root) === 'undefined') { + error('Must define a default root adapter.'); + } + + path = this.keypath; + } + + this.tokens = Observer.tokenize(path, interfaces, root); + this.key = this.tokens.pop(); + }; + + // Realizes the full keypath, attaching observers for every key and correcting + // old observers to any changed objects in the keypath. + Observer.prototype.realize = function () { + var current = this.obj; + var unreached = false; + var prev; + + this.tokens.forEach(function (token, index) { + if (isObject(current)) { + if (typeof this.objectPath[index] !== 'undefined') { + if (current !== (prev = this.objectPath[index])) { + this.set(false, token, prev, this.update); + this.set(true, token, current, this.update); + this.objectPath[index] = current; + } + } else { + this.set(true, token, current, this.update); + this.objectPath[index] = current; + } + + current = this.get(token, current); + } else { + if (unreached === false) { + unreached = index; + } + + if (prev = this.objectPath[index]) { + this.set(false, token, prev, this.update); + } + } + }, this); + + if (unreached !== false) { + this.objectPath.splice(unreached); + } + + return current; + }; + + // Updates the keypath. This is called when any intermediary key is changed. + Observer.prototype.update = function () { + var next, oldValue; + + if ((next = this.realize()) !== this.target) { + if (isObject(this.target)) { + this.set(false, this.key, this.target, this.callback); + } + + if (isObject(next)) { + this.set(true, this.key, next, this.callback); + } + + oldValue = this.value(); + this.target = next; + + if (this.value() !== oldValue) this.callback(); + } + }; + + // Reads the current end value of the observed keypath. Returns undefined if + // the full keypath is unreachable. + Observer.prototype.value = function () { + if (isObject(this.target)) { + return this.get(this.key, this.target); + } + }; + + // Sets the current end value of the observed keypath. Calling setValue when + // the full keypath is unreachable is a no-op. + Observer.prototype.setValue = function (value) { + if (isObject(this.target)) { + this.adapter(this.key).set(this.target, this.key.path, value); + } + }; + + // Gets the provided key on an object. + Observer.prototype.get = function (key, obj) { + return this.adapter(key).get(obj, key.path); + }; + + // Observes or unobserves a callback on the object using the provided key. + Observer.prototype.set = function (active, key, obj, callback) { + var action = active ? 'observe' : 'unobserve'; + this.adapter(key)[action](obj, key.path, callback); + }; + + // Returns an array of all unique adapter interfaces available. + Observer.prototype.interfaces = function () { + var interfaces = Object.keys(this.options.adapters); + + Object.keys(sightglass.adapters).forEach(function (i) { + if (!~interfaces.indexOf(i)) { + interfaces.push(i); + } + }); + + return interfaces; + }; + + // Convenience function to grab the adapter for a specific key. + Observer.prototype.adapter = function (key) { + return this.options.adapters[key.i] || sightglass.adapters[key.i]; + }; + + // Unobserves the entire keypath. + Observer.prototype.unobserve = function () { + var obj; + + this.tokens.forEach(function (token, index) { + if (obj = this.objectPath[index]) { + this.set(false, token, obj, this.update); + } + }, this); + + if (isObject(this.target)) { + this.set(false, this.key, this.target, this.callback); + } + }; + + // Check if a value is an object than can be observed. + function isObject(obj) { + return (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && obj !== null; + } + + // Error thrower. + function error(message) { + throw new Error('[sightglass] ' + message); + } + + // Export module for Node and the browser. + if (typeof module !== 'undefined' && module.exports) { + module.exports = sightglass; + } else if (true) { + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function () { + return this.sightglass = sightglass; + }.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + } else { + this.sightglass = sightglass; + } + }).call(undefined); + }); + +/***/ }, +/* 2 */ +/***/ function(module, exports, __webpack_require__) { + + var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { + if (true) { + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [module, exports, __webpack_require__(3)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('./constants')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.constants); + global.rivets = mod.exports; + } + })(this, function (module, exports, _constants) { + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + + var rivets = { + // Global binders. + binders: {}, + + // Global components. + components: {}, + + // Global formatters. + formatters: {}, + + // Global sightglass adapters. + adapters: {}, + + // Default attribute prefix. + prefix: 'rv', + + // Default template delimiters. + templateDelimiters: ['{', '}'], + + // Default sightglass root interface. + rootInterface: '.', + + // Preload data by default. + preloadData: true, + + // Alias for index in rv-each binder + iterationAlias: function iterationAlias(modelName) { + return '%' + modelName + '%'; + }, + + // Default event handler. + handler: function handler(context, ev, binding) { + this.call(context, ev, binding.view.models); + }, + + // Merges an object literal into the corresponding global options. + configure: function configure() { + var _this = this; + + var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; + + Object.keys(options).forEach(function (option) { + var value = options[option]; + + if (_constants.EXTENSIONS.indexOf(option) > -1) { + Object.keys(value).forEach(function (key) { + _this[option][key] = value[key]; + }); + } else { + _this[option] = value; + } + }); + } + }; + + exports.default = rivets; + module.exports = exports['default']; + }); + +/***/ }, +/* 3 */ +/***/ function(module, exports, __webpack_require__) { + + var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { + if (true) { + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [exports], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + } else if (typeof exports !== "undefined") { + factory(exports); + } else { + var mod = { + exports: {} + }; + factory(mod.exports); + global.constants = mod.exports; + } + })(this, function (exports) { + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + var OPTIONS = exports.OPTIONS = ['prefix', 'templateDelimiters', 'rootInterface', 'preloadData', 'handler']; + + var EXTENSIONS = exports.EXTENSIONS = ['binders', 'formatters', 'components', 'adapters']; + }); + +/***/ }, +/* 4 */ +/***/ function(module, exports, __webpack_require__) { + + var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { + if (true) { + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [module, exports, __webpack_require__(2), __webpack_require__(3), __webpack_require__(5), __webpack_require__(6)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('./rivets'), require('./constants'), require('./bindings'), require('./parsers')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.rivets, global.constants, global.bindings, global.parsers); + global.view = mod.exports; + } + })(this, function (module, exports, _rivets, _constants, _bindings, _parsers) { + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + var _rivets2 = _interopRequireDefault(_rivets); + + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + var _createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); + + var defined = function defined(value) { + return value !== undefined && value !== null; + }; + + // A collection of bindings built from a set of parent nodes. + + var View = function () { + // The DOM elements and the model objects for binding are passed into the + // constructor along with any local options that should be used throughout the + // context of the view and it's bindings. + function View(els, models) { + var _this = this; + + var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; + + _classCallCheck(this, View); + + if (els.jquery || els instanceof Array) { + this.els = els; + } else { + this.els = [els]; + } + + this.models = models; + + _constants.EXTENSIONS.forEach(function (extensionType) { + _this[extensionType] = {}; + + if (options[extensionType]) { + Object.keys(options[extensionType]).forEach(function (key) { + _this[extensionType][key] = options[extensionType][key]; + }); + } + + Object.keys(_rivets2.default[extensionType]).forEach(function (key) { + if (!defined(_this[extensionType][key])) { + _this[extensionType][key] = _rivets2.default[extensionType][key]; + } + }); + }); + + _constants.OPTIONS.forEach(function (option) { + _this[option] = defined(options[option]) ? options[option] : _rivets2.default[option]; + }); + + this.build(); + } + + _createClass(View, [{ + key: 'options', + value: function options() { + var _this2 = this; + + var options = {}; + + _constants.EXTENSIONS.concat(_constants.OPTIONS).forEach(function (option) { + options[option] = _this2[option]; + }); + + return options; + } + }, { + key: 'bindingRegExp', + value: function bindingRegExp() { + return new RegExp('^' + this.prefix + '-'); + } + }, { + key: 'buildBinding', + value: function buildBinding(binding, node, type, declaration) { + var pipes = declaration.match(/((?:'[^']*')*(?:(?:[^\|']*(?:'[^']*')+[^\|']*)+|[^\|]+))|^$/g).map(function (pipe) { + return pipe.trim(); + }); + + var context = pipes.shift().split('<').map(function (ctx) { + return ctx.trim(); + }); + + var keypath = context.shift(); + var dependencies = context.shift(); + var options = { formatters: pipes }; + + if (dependencies) { + options.dependencies = dependencies.split(/\s+/); + } + + this.bindings.push(new binding(this, node, type, keypath, options)); + } + }, { + key: 'build', + value: function build() { + var _this3 = this; + + this.bindings = []; + + var parse = function parse(node) { + var block = false; + + if (node.nodeType === 3) { + var delimiters = _this3.templateDelimiters; + + if (delimiters) { + var tokens = (0, _parsers.parseTemplate)(node.data, delimiters); + + if (tokens.length) { + if (!(tokens.length === 1 && tokens[0].type === 0)) { + tokens.forEach(function (token) { + var text = document.createTextNode(token.value); + node.parentNode.insertBefore(text, node); + + if (token.type === 1) { + _this3.buildBinding(_bindings.TextBinding, text, null, token.value); + } + }); + + node.parentNode.removeChild(node); + } + } + } + } else if (node.nodeType === 1) { + block = _this3.traverse(node); + } + + if (!block) { + Array.prototype.slice.call(node.childNodes).forEach(parse); + } + }; + + var elements = this.els, + i = void 0, + len = void 0; + for (i = 0, len = elements.length; i < len; i++) { + parse(elements[i]); + } + + this.bindings.sort(function (a, b) { + var aPriority = defined(a.binder) ? a.binder.priority || 0 : 0; + var bPriority = defined(b.binder) ? b.binder.priority || 0 : 0; + return bPriority - aPriority; + }); + } + }, { + key: 'traverse', + value: function traverse(node) { + var _this4 = this; + + var bindingRegExp = this.bindingRegExp(); + var block = node.nodeName === 'SCRIPT' || node.nodeName === 'STYLE'; + var attributes = null; + + Array.prototype.slice.call(node.attributes).forEach(function (attribute) { + if (bindingRegExp.test(attribute.name)) { + (function () { + var type = attribute.name.replace(bindingRegExp, ''); + var binder = _this4.binders[type]; + + if (!binder) { + Object.keys(_this4.binders).forEach(function (identifier) { + var value = _this4.binders[identifier]; + + if (identifier !== '*' && identifier.indexOf('*') > -1) { + var regexp = new RegExp('^' + identifier.replace(/\*/g, '.+') + '$'); + + if (regexp.test(type)) { + binder = value; + } + } + }); + } + + if (!defined(binder)) { + binder = _this4.binders['*']; + } + + if (binder.block) { + block = true; + attributes = [attribute]; + } + })(); + } + }); + + attributes = attributes || Array.prototype.slice.call(node.attributes); + + attributes.forEach(function (attribute) { + if (bindingRegExp.test(attribute.name)) { + var type = attribute.name.replace(bindingRegExp, ''); + _this4.buildBinding(_bindings.Binding, node, type, attribute.value); + } + }); + + if (!block) { + var type = node.nodeName.toLowerCase(); + + if (this.components[type] && !node._bound) { + this.bindings.push(new _bindings.ComponentBinding(this, node, type)); + block = true; + } + } + + return block; + } + }, { + key: 'select', + value: function select(fn) { + return this.bindings.filter(fn); + } + }, { + key: 'bind', + value: function bind() { + this.bindings.forEach(function (binding) { + binding.bind(); + }); + } + }, { + key: 'unbind', + value: function unbind() { + this.bindings.forEach(function (binding) { + binding.unbind(); + }); + } + }, { + key: 'sync', + value: function sync() { + this.bindings.forEach(function (binding) { + binding.sync(); + }); + } + }, { + key: 'publish', + value: function publish() { + var publishes = this.select(function (binding) { + if (defined(binding.binder)) { + return binding.binder.publishes; + } + }); + + publishes.forEach(function (binding) { + binding.publish(); + }); + } + }, { + key: 'update', + value: function update() { + var _this5 = this; + + var models = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; + + Object.keys(models).forEach(function (key) { + _this5.models[key] = models[key]; + }); + + this.bindings.forEach(function (binding) { + if (defined(binding.update)) { + binding.update(models); + } + }); + } + }]); + + return View; + }(); + + exports.default = View; + module.exports = exports['default']; + }); + +/***/ }, +/* 5 */ +/***/ function(module, exports, __webpack_require__) { + + var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { + if (true) { + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [exports, __webpack_require__(2), __webpack_require__(6), __webpack_require__(7), __webpack_require__(3)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + } else if (typeof exports !== "undefined") { + factory(exports, require('./rivets'), require('./parsers'), require('./util'), require('./constants')); + } else { + var mod = { + exports: {} + }; + factory(mod.exports, global.rivets, global.parsers, global.util, global.constants); + global.bindings = mod.exports; + } + })(this, function (exports, _rivets, _parsers, _util, _constants) { + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.TextBinding = exports.ComponentBinding = exports.Binding = undefined; + + var _rivets2 = _interopRequireDefault(_rivets); + + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + + var _get = function get(object, property, receiver) { + if (object === null) object = Function.prototype; + var desc = Object.getOwnPropertyDescriptor(object, property); + + if (desc === undefined) { + var parent = Object.getPrototypeOf(object); + + if (parent === null) { + return undefined; + } else { + return get(parent, property, receiver); + } + } else if ("value" in desc) { + return desc.value; + } else { + var getter = desc.get; + + if (getter === undefined) { + return undefined; + } + + return getter.call(receiver); + } + }; + + function _possibleConstructorReturn(self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + + return call && (typeof call === "object" || typeof call === "function") ? call : self; + } + + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + }); + if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; + } + + function _toConsumableArray(arr) { + if (Array.isArray(arr)) { + for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { + arr2[i] = arr[i]; + } + + return arr2; + } else { + return Array.from(arr); + } + } + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + var _createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); + + var defined = function defined(value) { + return value !== undefined && value !== null; + }; + + // A single binding between a model attribute and a DOM element. + + var Binding = exports.Binding = function () { + // All information about the binding is passed into the constructor; the + // containing view, the DOM node, the type of binding, the model object and the + // keypath at which to listen for changes. + function Binding(view, el, type, keypath) { + var options = arguments.length <= 4 || arguments[4] === undefined ? {} : arguments[4]; + + _classCallCheck(this, Binding); + + this.view = view; + this.el = el; + this.type = type; + this.keypath = keypath; + this.options = options; + this.formatters = options.formatters || []; + this.dependencies = []; + this.formatterObservers = {}; + this.model = undefined; + this.setBinder(); + + this.bind = this.bind.bind(this); + this.unbind = this.unbind.bind(this); + this.sync = this.sync.bind(this); + this.publish = this.publish.bind(this); + } + + // Sets the binder to use when binding and syncing. + + + _createClass(Binding, [{ + key: 'setBinder', + value: function setBinder() { + var _this = this; + + this.binder = this.view.binders[this.type]; + + if (!this.binder) { + Object.keys(this.view.binders).forEach(function (identifier) { + var value = _this.view.binders[identifier]; + + if (identifier !== '*' && identifier.indexOf('*') > -1) { + var regexp = new RegExp('^' + identifier.replace(/\*/g, '.+') + '$'); + + if (regexp.test(_this.type)) { + _this.binder = value; + _this.args = new RegExp('^' + identifier.replace(/\*/g, '(.+)') + '$').exec(_this.type); + _this.args.shift(); + } + } + }); + } + + if (!defined(this.binder)) { + this.binder = this.view.binders['*']; + } + + if (this.binder instanceof Function) { + this.binder = { routine: this.binder }; + } + } + + // Observes the object keypath to run the provided callback. + + }, { + key: 'observe', + value: function observe(obj, keypath, callback) { + return _rivets2.default.sightglass(obj, keypath, callback, { + root: this.view.rootInterface, + adapters: this.view.adapters + }); + } + }, { + key: 'parseTarget', + value: function parseTarget() { + var token = (0, _parsers.parseType)(this.keypath); + + if (token.type === _parsers.PRIMITIVE) { + this.value = token.value; + } else { + this.observer = this.observe(this.view.models, this.keypath, this.sync); + this.model = this.observer.target; + } + } + }, { + key: 'parseFormatterArguments', + value: function parseFormatterArguments(args, formatterIndex) { + var _this2 = this; + + return args.map(_parsers.parseType).map(function (_ref, ai) { + var type = _ref.type; + var value = _ref.value; + + if (type === _parsers.PRIMITIVE) { + return value; + } else { + if (!defined(_this2.formatterObservers[formatterIndex])) { + _this2.formatterObservers[formatterIndex] = {}; + } + + var observer = _this2.formatterObservers[formatterIndex][ai]; + + if (!observer) { + observer = _this2.observe(_this2.view.models, value, _this2.sync); + _this2.formatterObservers[formatterIndex][ai] = observer; + } + + return observer.value(); + } + }); + } + + // Applies all the current formatters to the supplied value and returns the + // formatted value. + + }, { + key: 'formattedValue', + value: function formattedValue(value) { + var _this3 = this; + + this.formatters.forEach(function (formatterStr, fi) { + var args = formatterStr.match(/[^\s']+|'([^']|'[^\s])*'|"([^"]|"[^\s])*"/g); + var id = args.shift(); + var formatter = _this3.view.formatters[id]; + + var processedArgs = _this3.parseFormatterArguments(args, fi); + + if (formatter && formatter.read instanceof Function) { + value = formatter.read.apply(formatter, [value].concat(_toConsumableArray(processedArgs))); + } else if (formatter instanceof Function) { + value = formatter.apply(undefined, [value].concat(_toConsumableArray(processedArgs))); + } + }); + + return value; + } + + // Returns an event handler for the binding around the supplied function. + + }, { + key: 'eventHandler', + value: function eventHandler(fn) { + var binding = this; + var handler = binding.view.handler; + + return function (ev) { + handler.call(fn, this, ev, binding); + }; + } + + // Sets the value for the binding. This Basically just runs the binding routine + // with the suplied value formatted. + + }, { + key: 'set', + value: function set(value) { + if (value instanceof Function && !this.binder.function) { + value = this.formattedValue(value.call(this.model)); + } else { + value = this.formattedValue(value); + } + + if (this.binder.routine) { + this.binder.routine.call(this, this.el, value); + } + } + + // Syncs up the view binding with the model. + + }, { + key: 'sync', + value: function sync() { + var _this4 = this; + + if (this.observer) { + if (this.model !== this.observer.target) { + var deps = this.options.dependencies; + + this.dependencies.forEach(function (observer) { + observer.unobserve(); + }); + + this.dependencies = []; + this.model = this.observer.target; + + if (defined(this.model) && deps && deps.length) { + deps.forEach(function (dependency) { + var observer = _this4.observe(_this4.model, dependency, _this4.sync); + _this4.dependencies.push(observer); + }); + } + } + + this.set(this.observer.value()); + } else { + this.set(this.value); + } + } + + // Publishes the value currently set on the input element back to the model. + + }, { + key: 'publish', + value: function publish() { + var _this5 = this; + + if (this.observer) { + (function () { + var value = _this5.getValue(_this5.el); + var lastformatterIndex = _this5.formatters.length - 1; + + _this5.formatters.slice(0).reverse().forEach(function (formatter, fiReversed) { + var fi = lastformatterIndex - fiReversed; + var args = formatter.split(/\s+/); + var id = args.shift(); + var f = _this5.view.formatters[id]; + var processedArgs = _this5.parseFormatterArguments(args, fi); + + if (defined(f) && f.publish) { + value = f.publish.apply(f, [value].concat(_toConsumableArray(processedArgs))); + } + }); + + _this5.observer.setValue(value); + })(); + } + } + + // Subscribes to the model for changes at the specified keypath. Bi-directional + // routines will also listen for changes on the element to propagate them back + // to the model. + + }, { + key: 'bind', + value: function bind() { + var _this6 = this; + + this.parseTarget(); + + if (defined(this.binder.bind)) { + this.binder.bind.call(this, this.el); + } + + if (defined(this.model) && defined(this.options.dependencies)) { + this.options.dependencies.forEach(function (dependency) { + var observer = _this6.observe(_this6.model, dependency, _this6.sync); + _this6.dependencies.push(observer); + }); + } + + if (this.view.preloadData) { + this.sync(); + } + } + + // Unsubscribes from the model and the element. + + }, { + key: 'unbind', + value: function unbind() { + var _this7 = this; + + if (defined(this.binder.unbind)) { + this.binder.unbind.call(this, this.el); + } + + if (defined(this.observer)) { + this.observer.unobserve(); + } + + this.dependencies.forEach(function (observer) { + observer.unobserve(); + }); + + this.dependencies = []; + + Object.keys(this.formatterObservers).forEach(function (fi) { + var args = _this7.formatterObservers[fi]; + + Object.keys(args).forEach(function (ai) { + args[ai].unobserve(); + }); + }); + + this.formatterObservers = {}; + } + + // Updates the binding's model from what is currently set on the view. Unbinds + // the old model first and then re-binds with the new model. + + }, { + key: 'update', + value: function update() { + var models = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; + + if (defined(this.observer)) { + this.model = this.observer.target; + } + + if (defined(this.binder.update)) { + this.binder.update.call(this, models); + } + } + + // Returns elements value + + }, { + key: 'getValue', + value: function getValue(el) { + if (this.binder && defined(this.binder.getValue)) { + return this.binder.getValue.call(this, el); + } else { + return (0, _util.getInputValue)(el); + } + } + }]); + + return Binding; + }(); + + var ComponentBinding = exports.ComponentBinding = function (_Binding) { + _inherits(ComponentBinding, _Binding); + + // Initializes a component binding for the specified view. The raw component + // element is passed in along with the component type. Attributes and scope + // inflections are determined based on the components defined attributes. + function ComponentBinding(view, el, type) { + _classCallCheck(this, ComponentBinding); + + var _this8 = _possibleConstructorReturn(this, Object.getPrototypeOf(ComponentBinding).call(this, view, el, type)); + + _this8.component = _this8.view.components[_this8.type]; + _this8.static = {}; + _this8.observers = {}; + _this8.upstreamObservers = {}; + + var bindingRegExp = view.bindingRegExp(); + + if (_this8.el.attributes) { + _this8.el.attributes.forEach(function (attribute) { + if (!bindingRegExp.test(attribute.name)) { + var propertyName = _this8.camelCase(attribute.name); + var stat = _this8.component.static; + + if (stat && stat.indexOf(propertyName) > -1) { + _this8.static[propertyName] = attribute.value; + } else { + _this8.observers[propertyName] = attribute.value; + } + } + }); + } + return _this8; + } + + // Intercepts `Rivets.Binding::sync` since component bindings are not bound to + // a particular model to update it's value. + + + _createClass(ComponentBinding, [{ + key: 'sync', + value: function sync() {} + + // Intercepts `Rivets.Binding::update` since component bindings are not bound + // to a particular model to update it's value. + + }, { + key: 'update', + value: function update() {} + + // Intercepts `Rivets.Binding::publish` since component bindings are not bound + // to a particular model to update it's value. + + }, { + key: 'publish', + value: function publish() {} + + // Returns an object map using the component's scope inflections. + + }, { + key: 'locals', + value: function locals() { + var _this9 = this; + + var result = {}; + + Object.keys(this.static).forEach(function (key) { + result[key] = _this9.static[key]; + }); + + Object.keys(this.observers).forEach(function (key) { + result[key] = _this9.observers[key].value(); + }); + + return result; + } + + // Returns a camel-cased version of the string. Used when translating an + // element's attribute name into a property name for the component's scope. + + }, { + key: 'camelCase', + value: function camelCase(string) { + return string.replace(/-([a-z])/g, function (grouped) { + grouped[1].toUpperCase(); + }); + } + + // Intercepts `Rivets.Binding::bind` to build `@componentView` with a localized + // map of models from the root view. Bind `@componentView` on subsequent calls. + + }, { + key: 'bind', + value: function bind() { + var _this10 = this; + + if (!this.bound) { + Object.keys(this.observers).forEach(function (key) { + var keypath = _this10.observers[key]; + + _this10.observers[key] = _this10.observe(_this10.view.models, keypath, function (key) { + return function () { + _this10.componentView.models[key] = _this10.observers[key].value(); + }; + }.call(_this10, key)); + }); + + this.bound = true; + } + + if (defined(this.componentView)) { + this.componentView.bind(); + } else { + (function () { + _this10.el.innerHTML = _this10.component.template.call(_this10); + var scope = _this10.component.initialize.call(_this10, _this10.el, _this10.locals()); + _this10.el._bound = true; + + var options = {}; + + _constants.EXTENSIONS.forEach(function (extensionType) { + options[extensionType] = {}; + + if (_this10.component[extensionType]) { + Object.keys(_this10.component[extensionType]).forEach(function (key) { + options[extensionType][key] = _this10.component[extensionType][key]; + }); + } + + Object.keys(_this10.view[extensionType]).forEach(function (key) { + if (!defined(options[extensionType][key])) { + options[extensionType][key] = _this10.view[extensionType][key]; + } + }); + }); + + _constants.OPTIONS.forEach(function (option) { + if (defined(_this10.component[option])) { + options[option] = _this10.component[option]; + } else { + options[option] = _this10.view[option]; + } + }); + + _this10.componentView = new View(_this10.el, scope, options); + _this10.componentView.bind(); + + Object.keys(_this10.observers).forEach(function (key) { + var observer = _this10.observers[key]; + var models = _this10.componentView.models; + + var upstream = _this10.observe(models, key, function (key, observer) { + return function () { + observer.setValue(_this10.componentView.models[key]); + }; + }.call(_this10, key, observer)); + + _this10.upstreamObservers[key] = upstream; + }); + })(); + } + } + + // Intercept `Rivets.Binding::unbind` to be called on `@componentView`. + + }, { + key: 'unbind', + value: function unbind() { + var _this11 = this; + + Object.keys(this.upstreamObservers).forEach(function (key) { + _this11.upstreamObservers[key].unobserve(); + }); + + Object.keys(this.observers).forEach(function (key) { + _this11.observers[key].unobserve(); + }); + + if (defined(this.componentView)) { + this.componentView.unbind.call(this); + } + } + }]); + + return ComponentBinding; + }(Binding); + + var TextBinding = exports.TextBinding = function (_Binding2) { + _inherits(TextBinding, _Binding2); + + // Initializes a text binding for the specified view and text node. + function TextBinding(view, el, type, keypath) { + var options = arguments.length <= 4 || arguments[4] === undefined ? {} : arguments[4]; + + _classCallCheck(this, TextBinding); + + var _this12 = _possibleConstructorReturn(this, Object.getPrototypeOf(TextBinding).call(this, view, el, type)); + + _this12.keypath = keypath; + _this12.options = options; + _this12.formatters = _this12.options.formatters || []; + _this12.dependencies = []; + _this12.formatterObservers = {}; + + _this12.binder = { + routine: function routine(node, value) { + node.data = defined(value) ? value : ''; + } + }; + + _this12.sync = _this12.sync.bind(_this12); + return _this12; + } + + // Wrap the call to `sync` to avoid function context issues. + + + _createClass(TextBinding, [{ + key: 'sync', + value: function sync() { + _get(Object.getPrototypeOf(TextBinding.prototype), 'sync', this).call(this); + } + }]); + + return TextBinding; + }(Binding); + }); + +/***/ }, +/* 6 */ +/***/ function(module, exports, __webpack_require__) { + + var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { + if (true) { + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [exports], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + } else if (typeof exports !== "undefined") { + factory(exports); + } else { + var mod = { + exports: {} + }; + factory(mod.exports); + global.parsers = mod.exports; + } + })(this, function (exports) { + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.parseType = parseType; + exports.parseTemplate = parseTemplate; + var PRIMITIVE = exports.PRIMITIVE = 0; + var KEYPATH = 1; + var TEXT = 0; + var BINDING = 1; + + // Parser and tokenizer for getting the type and value from a string. + function parseType(string) { + var type = PRIMITIVE; + var value = string; + + if (/^'.*'$|^".*"$/.test(string)) { + value = string.slice(1, -1); + } else if (string === 'true') { + value = true; + } else if (string === 'false') { + value = false; + } else if (string === 'null') { + value = null; + } else if (string === 'undefined') { + value = undefined; + } else if (isNaN(Number(string)) === false) { + value = Number(string); + } else { + type = KEYPATH; + } + + return { type: type, value: value }; + } + + // Template parser and tokenizer for mustache-style text content bindings. + // Parses the template and returns a set of tokens, separating static portions + // of text from binding declarations. + function parseTemplate(template, delimiters) { + var tokens = []; + var length = template.length; + var index = 0; + var lastIndex = 0; + + while (lastIndex < length) { + index = template.indexOf(delimiters[0], lastIndex); + + if (index < 0) { + tokens.push({ + type: TEXT, + value: template.slice(lastIndex) + }); + + break; + } else { + if (index > 0 && lastIndex < index) { + tokens.push({ + type: TEXT, + value: template.slice(lastIndex, index) + }); + } + + lastIndex = index + delimiters[0].length; + index = template.indexOf(delimiters[1], lastIndex); + + if (index < 0) { + var substring = template.slice(lastIndex - delimiters[1].length); + var lastToken = tokens[tokens.length - 1]; + + if (lastToken && lastToken.type === TEXT) { + lastToken.value += substring; + } else { + tokens.push({ + type: TEXT, + value: substring + }); + } + + break; + } + + var value = template.slice(lastIndex, index).trim(); + + tokens.push({ + type: BINDING, + value: value + }); + + lastIndex = index + delimiters[1].length; + } + } + + return tokens; + } + }); + +/***/ }, +/* 7 */ +/***/ function(module, exports, __webpack_require__) { + + var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { + if (true) { + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [exports], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + } else if (typeof exports !== "undefined") { + factory(exports); + } else { + var mod = { + exports: {} + }; + factory(mod.exports); + global.util = mod.exports; + } + })(this, function (exports) { + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.bindEvent = bindEvent; + exports.unbindEvent = unbindEvent; + exports.getInputValue = getInputValue; + + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; + }; + + var $ = window.jQuery || window.$; + + function bindEvent(el, event, handler) { + if ($) { + $(el).on(event, handler); + } else { + el.addEventListener(event, handler, false); + } + } + + function unbindEvent(el, event, handler) { + if ($) { + $(el).off(event, handler); + } else { + el.removeEventListener(event, handler, false); + } + } + + function getInputValue(el) { + if ($) { + var $el = $(el); + + if ($el.attr('type') === 'checkbox') { + return $el.is(':checked'); + } else { + return $el.val(); + } + } else { + if (el.type === 'checkbox') { + return el.checked; + } else if (el.type === 'select-multiple') { + var _ret = function () { + var results = []; + + el.options.forEach(function (option) { + if (option.selected) { + results.push(option.value); + } + }); + + return { + v: results + }; + }(); + + if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; + } else { + return el.value; + } + } + } + }); + +/***/ }, +/* 8 */ +/***/ function(module, exports, __webpack_require__) { + + var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { + if (true) { + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [module, exports], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + } else if (typeof exports !== "undefined") { + factory(module, exports); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports); + global.adapter = mod.exports; + } + })(this, function (module, exports) { + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + // The default `.` adapter thats comes with Rivets.js. Allows subscribing to + // properties on plain objects, implemented in ES5 natives using + // `Object.defineProperty`. + + var defined = function defined(value) { + return value !== undefined && value !== null; + }; + + var ARRAY_METHODS = ['push', 'pop', 'shift', 'unshift', 'sort', 'reverse', 'splice']; + + var adapter = { + id: '_rv', + counter: 0, + weakmap: {}, + + weakReference: function weakReference(obj) { + if (!obj.hasOwnProperty(this.id)) { + var id = this.counter++; + + Object.defineProperty(obj, this.id, { + value: id + }); + } + + if (!this.weakmap[obj[this.id]]) { + this.weakmap[obj[this.id]] = { + callbacks: {} + }; + } + + return this.weakmap[obj[this.id]]; + }, + + cleanupWeakReference: function cleanupWeakReference(ref, id) { + if (!Object.keys(ref.callbacks).length) { + if (!(ref.pointers && Object.keys(ref.pointers).length)) { + delete this.weakmap[id]; + } + } + }, + + stubFunction: function stubFunction(obj, fn) { + var original = obj[fn]; + var map = this.weakReference(obj); + var weakmap = this.weakmap; + + obj[fn] = function () { + for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + var response = original.apply(obj, args); + + Object.keys(map.pointers).forEach(function (r) { + var k = map.pointers[r]; + + if (defined(weakmap[r])) { + if (weakmap[r].callbacks[k] instanceof Array) { + weakmap[r].callbacks[k].forEach(function (callback) { + callback(); + }); + } + } + }); + + return response; + }; + }, + + observeMutations: function observeMutations(obj, ref, keypath) { + var _this = this; + + if (obj instanceof Array) { + var map = this.weakReference(obj); + + if (!defined(map.pointers)) { + map.pointers = {}; + + ARRAY_METHODS.forEach(function (fn) { + _this.stubFunction(obj, fn); + }); + } + + if (!defined(map.pointers[ref])) { + map.pointers[ref] = []; + } + + if (map.pointers[ref].indexOf(keypath) === -1) { + map.pointers[ref].push(keypath); + } + } + }, + + unobserveMutations: function unobserveMutations(obj, ref, keypath) { + if (obj instanceof Array && defined(obj[this.id])) { + var map = this.weakmap[obj[this.id]]; + + if (map) { + var pointers = map.pointers[ref]; + + if (pointers) { + var idx = pointers.indexOf(keypath); + + if (idx > -1) { + pointers.splice(idx, 1); + } + + if (!pointers.length) { + delete map.pointers[ref]; + } + + this.cleanupWeakReference(map, obj[this.id]); + } + } + } + }, + + observe: function observe(obj, keypath, callback) { + var _this2 = this; + + var callbacks = this.weakReference(obj).callbacks; + + if (!defined(callbacks[keypath])) { + callbacks[keypath] = []; + var desc = Object.getOwnPropertyDescriptor(obj, keypath); + + if (!(desc && (desc.get || desc.set))) { + (function () { + var value = obj[keypath]; + + Object.defineProperty(obj, keypath, { + enumerable: true, + + get: function get() { + return value; + }, + + set: function set(newValue) { + if (newValue !== value) { + _this2.unobserveMutations(value, obj[_this2.id], keypath); + value = newValue; + var map = _this2.weakmap[obj[_this2.id]]; + + if (map) { + var _callbacks = map.callbacks; + + if (_callbacks[keypath]) { + _callbacks[keypath].forEach(function (cb) { + cb(); + }); + } + + _this2.observeMutations(newValue, obj[_this2.id], keypath); + } + } + } + }); + })(); + } + } + + if (callbacks[keypath].indexOf(callback) === -1) { + callbacks[keypath].push(callback); + } + + this.observeMutations(obj[keypath], obj[this.id], keypath); + }, + + unobserve: function unobserve(obj, keypath, callback) { + var map = this.weakmap[obj[this.id]]; + + if (map) { + var callbacks = map.callbacks[keypath]; + + if (callbacks) { + var idx = callbacks.indexOf(callback); + + if (idx > -1) { + callbacks.splice(idx, 1); + + if (!callbacks.length) { + delete map.callbacks[keypath]; + } + } + + this.unobserveMutations(obj[keypath], obj[this.id], keypath); + this.cleanupWeakReference(map, obj[this.id]); + } + } + }, + + get: function get(obj, keypath) { + return obj[keypath]; + }, + + set: function set(obj, keypath, value) { + obj[keypath] = value; + } + }; + + exports.default = adapter; + module.exports = exports['default']; + }); + +/***/ }, +/* 9 */ +/***/ function(module, exports, __webpack_require__) { + + var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { + if (true) { + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [module, exports, __webpack_require__(2), __webpack_require__(7)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('./rivets'), require('./util')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.rivets, global.util); + global.binders = mod.exports; + } + })(this, function (module, exports, _rivets, _util) { + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + var _rivets2 = _interopRequireDefault(_rivets); + + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + + var _templateObject = _taggedTemplateLiteral([' rivets: ', ' ', ' '], [' rivets: ', ' ', ' ']), + _templateObject2 = _taggedTemplateLiteral([' rivets: ', ' '], [' rivets: ', ' ']); + + function _taggedTemplateLiteral(strings, raw) { + return Object.freeze(Object.defineProperties(strings, { + raw: { + value: Object.freeze(raw) + } + })); + } + + var CHANGE_EVENT = 'change'; + + var defined = function defined(value) { + return value !== undefined && value !== null; + }; + + var getString = function getString(value) { + return defined(value) ? value.toString() : undefined; + }; + + var times = function times(n, cb) { + for (var i = 0; i < n; i++) { + cb(); + } + }; + + var binders = { + // Sets the element's text value. + text: function text(el, value) { + el.textContent = defined(value) ? value : ''; + }, + + // Sets the element's HTML content. + html: function html(el, value) { + el.innerHTML = defined(value) ? value : ''; + }, + + // Shows the element when value is true. + show: function show(el, value) { + el.style.display = value ? '' : 'none'; + }, + + // Hides the element when value is true (negated version of `show` binder). + hide: function hide(el, value) { + el.style.display = value ? 'none' : ''; + }, + + // Enables the element when value is true. + enabled: function enabled(el, value) { + el.disabled = !value; + }, + + // Disables the element when value is true (negated version of `enabled` binder). + disabled: function disabled(el, value) { + el.disabled = !!value; + }, + + // Checks a checkbox or radio input when the value is true. Also sets the model + // property when the input is checked or unchecked (two-way binder). + checked: { + publishes: true, + priority: 2000, + + bind: function bind(el) { + (0, _util.bindEvent)(el, CHANGE_EVENT, this.publish); + }, + + unbind: function unbind(el) { + (0, _util.unbindEvent)(el, CHANGE_EVENT, this.publish); + }, + + routine: function routine(el, value) { + if (el.type === 'radio') { + el.checked = getString(el.value) === getString(value); + } else { + el.checked = !!value; + } + } + }, + + // Unchecks a checkbox or radio input when the value is true (negated version of + // `checked` binder). Also sets the model property when the input is checked or + // unchecked (two-way binder). + unchecked: { + publishes: true, + priority: 2000, + + bind: function bind(el) { + (0, _util.bindEvent)(el, CHANGE_EVENT, this.publish); + }, + + unbind: function unbind(el) { + (0, _util.unbindEvent)(el, CHANGE_EVENT, this.publish); + }, + + routine: function routine(el, value) { + if (el.type === 'radio') { + el.checked = getString(el.value) !== getString(value); + } else { + el.checked = !value; + } + } + }, + + // Sets the element's value. Also sets the model property when the input changes + // (two-way binder). + value: { + publishes: true, + priority: 3000, + + bind: function bind(el) { + if (!(el.tagName === 'INPUT' && el.type === 'radio')) { + this.event = el.tagName === 'SELECT' ? 'change' : 'input'; + + (0, _util.bindEvent)(el, this.event, this.publish); + } + }, + + unbind: function unbind(el) { + if (!(el.tagName === 'INPUT' && el.type === 'radio')) { + (0, _util.unbindEvent)(el, this.event, this.publish); + } + }, + + routine: function routine(el, value) { + if (el.tagName === 'INPUT' && el.type === 'radio') { + el.setAttribute('value', value); + } else if (window.jQuery) { + el = jQuery(el); + + if (getString(value) !== getString(el.val())) { + el.val(defined(value) ? value : ''); + } + } else { + if (el.type === 'select-multiple') { + if (value instanceof Array) { + Array.from(el.options).forEach(function (option) { + option.selected = value.indexOf(option.value) > -1; + }); + } + } else if (getString(value) !== getString(el.value)) { + el.value = defined(value) ? value : ''; + } + } + } + }, + + // Inserts and binds the element and it's child nodes into the DOM when true. + if: { + block: true, + priority: 4000, + + bind: function bind(el) { + if (!defined(this.marker)) { + var attr = [this.view.prefix, this.type].join('-').replace('--', '-'); + var declaration = el.getAttribute(attr); + + this.marker = document.createComment(_templateObject, this.type, declaration); + this.bound = false; + + el.removeAttribute(attr); + el.parentNode.insertBefore(this.marker, el); + el.parentNode.removeChild(el); + } + }, + + unbind: function unbind() { + if (defined(this.nested)) { + this.nested.unbind(); + this.bound = false; + } + }, + + routine: function routine(el, value) { + var _this = this; + + if (!!value === !this.bound) { + if (value) { + (function () { + var models = {}; + + Object.keys(_this.view.models).forEach(function (key) { + models[key] = _this.view.models[key]; + }); + + if (defined(_this.nested)) { + _this.nested.bind(); + } else { + _this.nested = _rivets2.default.bind(el, models, _this.view.options()); + } + + _this.marker.parentNode.insertBefore(el, _this.marker.nextSibling); + _this.bound = true; + })(); + } else { + el.parentNode.removeChild(el); + this.nested.unbind(); + this.bound = false; + } + } + }, + + update: function update(models) { + if (defined(this.nested)) { + this.nested.update(models); + } + } + }, + + // Removes and unbinds the element and it's child nodes into the DOM when true + // (negated version of `if` binder). + unless: { + block: true, + priority: 4000, + + bind: function bind(el) { + _rivets2.default.binders.if.bind.call(this, el); + }, + + unbind: function unbind() { + _rivets2.default.binders.if.unbind.call(this); + }, + + routine: function routine(el, value) { + _rivets2.default.binders.if.routine.call(this, el, !value); + }, + + update: function update(models) { + _rivets2.default.binders.if.update.call(this, models); + } + }, + + // Binds an event handler on the element. + 'on-*': { + function: true, + priority: 1000, + + unbind: function unbind(el) { + if (defined(this.handler)) { + (0, _util.unbindEvent)(el, this.args[0], this.handler); + } + }, + + routine: function routine(el, value) { + if (defined(this.handler)) { + (0, _util.unbindEvent)(el, this.args[0], this.handler); + } + + this.handler = this.eventHandler(value); + (0, _util.bindEvent)(el, this.args[0], this.handler); + } + }, + + // Appends bound instances of the element in place for each item in the array. + 'each-*': { + block: true, + priority: 4000, + + bind: function bind(el) { + if (!defined(this.marker)) { + var attr = [this.view.prefix, this.type].join('-').replace('--', '-'); + this.marker = document.createComment(_templateObject2, this.type); + this.iterated = []; + + el.removeAttribute(attr); + el.parentNode.insertBefore(this.marker, el); + el.parentNode.removeChild(el); + } else { + this.iterated.forEach(function (view) { + view.bind(); + }); + } + }, + + unbind: function unbind(el) { + if (defined(this.iterated)) { + this.iterated.forEach(function (view) { + view.unbind(); + }); + } + }, + + routine: function routine(el, _collection) { + var _this2 = this; + + var modelName = this.args[0]; + var collection = _collection || []; + + if (this.iterated.length > collection.length) { + times(this.iterated.length - collection.length, function () { + var view = _this2.iterated.pop(); + view.unbind(); + _this2.marker.parentNode.removeChild(view.els[0]); + }); + } + + collection.forEach(function (model, index) { + var data = { index: index }; + data[_rivets2.default.iterationAlias(modelName)] = index; + data[modelName] = model; + + if (!defined(_this2.iterated[index])) { + Object.keys(_this2.view.models).forEach(function (key) { + if (!defined(data[key])) { + data[key] = _this2.view.models[key]; + } + }); + + var previous = _this2.marker; + + if (_this2.iterated.length) { + previous = _this2.iterated[_this2.iterated.length - 1].els[0]; + } + + var options = _this2.view.options(); + options.preloadData = true; + + var template = el.cloneNode(true); + var view = _rivets2.default.bind(template, data, options); + _this2.iterated.push(view); + _this2.marker.parentNode.insertBefore(template, previous.nextSibling); + } else if (_this2.iterated[index].models[modelName] !== model) { + _this2.iterated[index].update(data); + } + }); + + if (el.nodeName === 'OPTION') { + this.view.bindings.forEach(function (binding) { + if (binding.el === _this2.marker.parentNode && binding.type === 'value') { + binding.sync(); + } + }); + } + }, + + update: function update(models) { + var _this3 = this; + + var data = {}; + + Object.keys(models).forEach(function (key) { + if (key !== _this3.args[0]) { + data[key] = models[key]; + } + }); + + this.iterated.forEach(function (view) { + view.update(data); + }); + } + }, + + // Adds or removes the class from the element when value is true or false. + 'class-*': function _class(el, value) { + var elClass = ' ' + el.className + ' '; + + if (!value === elClass.indexOf(' ' + this.args[0] + ' ') > -1) { + if (value) { + el.className = el.className + ' ' + this.args[0]; + } else { + el.className = elClass.replace(' ' + this.args[0] + ' ', ' ').trim(); + } + } + }, + + // Sets the attribute on the element. If no binder above is matched it will fall + // back to using this binder. + '*': function _(el, value) { + if (defined(value)) { + el.setAttribute(this.type, value); + } else { + el.removeAttribute(this.type); + } + } + }; + + exports.default = binders; + module.exports = exports['default']; + }); + +/***/ } +/******/ ]) +}); +; \ No newline at end of file diff --git a/dist/rivets.bundled.min.js b/dist/rivets.bundled.min.js index cb15f022b..8a453fbf4 100755 --- a/dist/rivets.bundled.min.js +++ b/dist/rivets.bundled.min.js @@ -1,6 +1,6 @@ // Rivets.js + Sightglass.js -// version: 0.9.1 +// version: 0.9.2 // author: Michael Richards // license: MIT -(function(){function t(t,i,s,h){return new e(t,i,s,h)}function e(t,e,s,h){this.options=h||{},this.options.adapters=this.options.adapters||{},this.obj=t,this.keypath=e,this.callback=s,this.objectPath=[],this.parse(),i(this.target=this.realize())&&this.set(!0,this.key,this.target,this.callback)}function i(t){return"object"==typeof t&&null!==t}function s(t){throw new Error("[sightglass] "+t)}t.adapters={},e.tokenize=function(t,e,i){var s,h,a=[],o={i:i,path:""};for(s=0;se;e++)if(e in this&&this[e]===t)return e;return-1};t={options:["prefix","templateDelimiters","rootInterface","preloadData","handler","executeFunctions"],extensions:["binders","formatters","components","adapters"],"public":{binders:{},components:{},formatters:{},adapters:{},prefix:"rv",templateDelimiters:["{","}"],rootInterface:".",preloadData:!0,executeFunctions:!1,iterationAlias:function(t){return"%"+t+"%"},handler:function(t,e,i){return this.call(t,e,i.view.models)},configure:function(e){var i,n,s,r;null==e&&(e={});for(s in e)if(r=e[s],"binders"===s||"components"===s||"formatters"===s||"adapters"===s)for(n in r)i=r[n],t[s][n]=i;else t["public"][s]=r},bind:function(e,i,n){var s;return null==i&&(i={}),null==n&&(n={}),s=new t.View(e,i,n),s.bind(),s},init:function(e,i,n){var s,r,o;if(null==n&&(n={}),null==i&&(i=document.createElement("div")),e=t["public"].components[e],r=e.template.call(this,i),r instanceof HTMLElement){for(;i.firstChild;)i.removeChild(i.firstChild);i.appendChild(r)}else i.innerHTML=r;return s=e.initialize.call(this,i,n),o=new t.View(i,s),o.bind(),o}}},window.jQuery||window.$?(n="on"in jQuery.prototype?["on","off"]:["bind","unbind"],e=n[0],i=n[1],t.Util={bindEvent:function(t,i,n){return jQuery(t)[e](i,n)},unbindEvent:function(t,e,n){return jQuery(t)[i](e,n)},getInputValue:function(t){var e;return e=jQuery(t),"checkbox"===e.attr("type")?e.is(":checked"):e.val()}}):t.Util={bindEvent:function(){return"addEventListener"in window?function(t,e,i){return t.addEventListener(e,i,!1)}:function(t,e,i){return t.attachEvent("on"+e,i)}}(),unbindEvent:function(){return"removeEventListener"in window?function(t,e,i){return t.removeEventListener(e,i,!1)}:function(t,e,i){return t.detachEvent("on"+e,i)}}(),getInputValue:function(t){var e,i,n,s;if("checkbox"===t.type)return t.checked;if("select-multiple"===t.type){for(s=[],i=0,n=t.length;n>i;i++)e=t[i],e.selected&&s.push(e.value);return s}return t.value}},t.TypeParser=function(){function t(){}return t.types={primitive:0,keypath:1},t.parse=function(t){return/^'.*'$|^".*"$/.test(t)?{type:this.types.primitive,value:t.slice(1,-1)}:"true"===t?{type:this.types.primitive,value:!0}:"false"===t?{type:this.types.primitive,value:!1}:"null"===t?{type:this.types.primitive,value:null}:"undefined"===t?{type:this.types.primitive,value:void 0}:""===t?{type:this.types.primitive,value:void 0}:isNaN(Number(t))===!1?{type:this.types.primitive,value:Number(t)}:{type:this.types.keypath,value:t}},t}(),t.TextTemplateParser=function(){function t(){}return t.types={text:0,binding:1},t.parse=function(t,e){var i,n,s,r,o,u,l;for(u=[],r=t.length,i=0,n=0;r>n;){if(i=t.indexOf(e[0],n),0>i){u.push({type:this.types.text,value:t.slice(n)});break}if(i>0&&i>n&&u.push({type:this.types.text,value:t.slice(n,i)}),n=i+e[0].length,i=t.indexOf(e[1],n),0>i){o=t.slice(n-e[1].length),s=u[u.length-1],(null!=s?s.type:void 0)===this.types.text?s.value+=o:u.push({type:this.types.text,value:o});break}l=t.slice(n,i).trim(),u.push({type:this.types.binding,value:l}),n=i+e[1].length}return u},t}(),t.View=function(){function e(e,i,n){var r,o,u,l,h,a,p,d,c,f,b,v,y;for(this.els=e,this.models=i,null==n&&(n={}),this.update=s(this.update,this),this.publish=s(this.publish,this),this.sync=s(this.sync,this),this.unbind=s(this.unbind,this),this.bind=s(this.bind,this),this.select=s(this.select,this),this.traverse=s(this.traverse,this),this.build=s(this.build,this),this.buildBinding=s(this.buildBinding,this),this.bindingRegExp=s(this.bindingRegExp,this),this.options=s(this.options,this),this.els.jquery||this.els instanceof Array||(this.els=[this.els]),c=t.extensions,h=0,p=c.length;p>h;h++){if(o=c[h],this[o]={},n[o]){f=n[o];for(r in f)u=f[r],this[o][r]=u}b=t["public"][o];for(r in b)u=b[r],null==(l=this[o])[r]&&(l[r]=u)}for(v=t.options,a=0,d=v.length;d>a;a++)o=v[a],this[o]=null!=(y=n[o])?y:t["public"][o];this.build()}return e.prototype.options=function(){var e,i,n,s,r;for(i={},r=t.extensions.concat(t.options),n=0,s=r.length;s>n;n++)e=r[n],i[e]=this[e];return i},e.prototype.bindingRegExp=function(){return new RegExp("^"+this.prefix+"-")},e.prototype.buildBinding=function(e,i,n,s){var r,o,u,l,h,a,p;return h={},p=function(){var t,e,i,n;for(i=s.match(/((?:'[^']*')*(?:(?:[^\|']*(?:'[^']*')+[^\|']*)+|[^\|]+))|^$/g),n=[],t=0,e=i.length;e>t;t++)a=i[t],n.push(a.trim());return n}(),r=function(){var t,e,i,n;for(i=p.shift().split("<"),n=[],t=0,e=i.length;e>t;t++)o=i[t],n.push(o.trim());return n}(),l=r.shift(),h.formatters=p,(u=r.shift())&&(h.dependencies=u.split(/\s+/)),this.bindings.push(new t[e](this,i,n,l,h))},e.prototype.build=function(){var e,i,n,s,r;for(this.bindings=[],i=function(e){return function(n){var s,r,o,u,l,h,a,p,d,c,f,b,v;if(3===n.nodeType){if(l=t.TextTemplateParser,(o=e.templateDelimiters)&&(p=l.parse(n.data,o)).length&&(1!==p.length||p[0].type!==l.types.text)){for(d=0,f=p.length;f>d;d++)a=p[d],h=document.createTextNode(a.value),n.parentNode.insertBefore(h,n),1===a.type&&e.buildBinding("TextBinding",h,null,a.value);n.parentNode.removeChild(n)}}else 1===n.nodeType&&(s=e.traverse(n));if(!s)for(v=function(){var t,e,i,s;for(i=n.childNodes,s=[],t=0,e=i.length;e>t;t++)u=i[t],s.push(u);return s}(),c=0,b=v.length;b>c;c++)r=v[c],i(r)}}(this),r=this.els,n=0,s=r.length;s>n;n++)e=r[n],i(e);this.bindings.sort(function(t,e){var i,n;return((null!=(i=e.binder)?i.priority:void 0)||0)-((null!=(n=t.binder)?n.priority:void 0)||0)})},e.prototype.traverse=function(e){var i,n,s,r,o,u,l,h,a,p,d,c,f,b,v,y;for(r=this.bindingRegExp(),o="SCRIPT"===e.nodeName||"STYLE"===e.nodeName,b=e.attributes,p=0,c=b.length;c>p;p++)if(i=b[p],r.test(i.name)){if(h=i.name.replace(r,""),!(s=this.binders[h])){v=this.binders;for(u in v)a=v[u],"*"!==u&&-1!==u.indexOf("*")&&(l=new RegExp("^"+u.replace(/\*/g,".+")+"$"),l.test(h)&&(s=a))}s||(s=this.binders["*"]),s.block&&(o=!0,n=[i])}for(y=n||e.attributes,d=0,f=y.length;f>d;d++)i=y[d],r.test(i.name)&&(h=i.name.replace(r,""),this.buildBinding("Binding",e,h,i.value));return o||(h=e.nodeName.toLowerCase(),this.components[h]&&!e._bound&&(this.bindings.push(new t.ComponentBinding(this,e,h)),o=!0)),o},e.prototype.select=function(t){var e,i,n,s,r;for(s=this.bindings,r=[],i=0,n=s.length;n>i;i++)e=s[i],t(e)&&r.push(e);return r},e.prototype.bind=function(){var t,e,i,n;for(n=this.bindings,e=0,i=n.length;i>e;e++)t=n[e],t.bind()},e.prototype.unbind=function(){var t,e,i,n;for(n=this.bindings,e=0,i=n.length;i>e;e++)t=n[e],t.unbind()},e.prototype.sync=function(){var t,e,i,n;for(n=this.bindings,e=0,i=n.length;i>e;e++)t=n[e],"function"==typeof t.sync&&t.sync()},e.prototype.publish=function(){var t,e,i,n;for(n=this.select(function(t){var e;return null!=(e=t.binder)?e.publishes:void 0}),e=0,i=n.length;i>e;e++)t=n[e],t.publish()},e.prototype.update=function(t){var e,i,n,s,r,o;null==t&&(t={});for(i in t)n=t[i],this.models[i]=n;for(o=this.bindings,s=0,r=o.length;r>s;s++)e=o[s],"function"==typeof e.update&&e.update(t)},e}(),t.Binding=function(){function e(t,e,i,n,r){this.view=t,this.el=e,this.type=i,this.keypath=n,this.options=null!=r?r:{},this.getValue=s(this.getValue,this),this.update=s(this.update,this),this.unbind=s(this.unbind,this),this.bind=s(this.bind,this),this.publish=s(this.publish,this),this.sync=s(this.sync,this),this.set=s(this.set,this),this.eventHandler=s(this.eventHandler,this),this.formattedValue=s(this.formattedValue,this),this.parseTarget=s(this.parseTarget,this),this.observe=s(this.observe,this),this.setBinder=s(this.setBinder,this),this.formatters=this.options.formatters||[],this.dependencies=[],this.formatterObservers={},this.model=void 0,this.setBinder()}return e.prototype.setBinder=function(){var t,e,i,n;if(!(this.binder=this.view.binders[this.type])){n=this.view.binders;for(t in n)i=n[t],"*"!==t&&-1!==t.indexOf("*")&&(e=new RegExp("^"+t.replace(/\*/g,".+")+"$"),e.test(this.type)&&(this.binder=i,this.args=new RegExp("^"+t.replace(/\*/g,"(.+)")+"$").exec(this.type),this.args.shift()))}return this.binder||(this.binder=this.view.binders["*"]),this.binder instanceof Function?this.binder={routine:this.binder}:void 0},e.prototype.observe=function(e,i,n){return t.sightglass(e,i,n,{root:this.view.rootInterface,adapters:this.view.adapters})},e.prototype.parseTarget=function(){var e;return e=t.TypeParser.parse(this.keypath),0===e.type?this.value=e.value:(this.observer=this.observe(this.view.models,this.keypath,this.sync),this.model=this.observer.target)},e.prototype.formattedValue=function(e){var i,n,s,o,u,l,h,a,p,d,c,f,b,v,y;for(v=this.formatters,o=d=0,f=v.length;f>d;o=++d){for(u=v[o],s=u.match(/[^\s']+|'([^']|'[^\s])*'|"([^"]|"[^\s])*"/g),l=s.shift(),u=this.view.formatters[l],s=function(){var e,i,r;for(r=[],e=0,i=s.length;i>e;e++)n=s[e],r.push(t.TypeParser.parse(n));return r}(),a=[],i=c=0,b=s.length;b>c;i=++c)n=s[i],a.push(0===n.type?n.value:((p=this.formatterObservers)[o]||(p[o]={}),(h=this.formatterObservers[o][i])?void 0:(h=this.observe(this.view.models,n.value,this.sync),this.formatterObservers[o][i]=h),h.value()));(null!=u?u.read:void 0)instanceof Function?e=(y=u.read).call.apply(y,[this.model,e].concat(r.call(a))):u instanceof Function&&(e=u.call.apply(u,[this.model,e].concat(r.call(a))))}return e},e.prototype.eventHandler=function(t){var e,i;return i=(e=this).view.handler,function(n){return i.call(t,this,n,e)}},e.prototype.set=function(e){var i;return e=e instanceof Function&&!this.binder["function"]&&t["public"].executeFunctions?this.formattedValue(e.call(this.model)):this.formattedValue(e),null!=(i=this.binder.routine)?i.call(this,this.el,e):void 0},e.prototype.sync=function(){var t,e;return this.set(function(){var i,n,s,r,o,u,l;if(this.observer){if(this.model!==this.observer.target){for(o=this.dependencies,i=0,s=o.length;s>i;i++)e=o[i],e.unobserve();if(this.dependencies=[],null!=(this.model=this.observer.target)&&(null!=(u=this.options.dependencies)?u.length:void 0))for(l=this.options.dependencies,n=0,r=l.length;r>n;n++)t=l[n],e=this.observe(this.model,t,this.sync),this.dependencies.push(e)}return this.observer.value()}return this.value}.call(this))},e.prototype.publish=function(){var t,e,i,n,s,o,u,l,h;if(this.observer){for(n=this.getValue(this.el),u=this.formatters.slice(0).reverse(),s=0,o=u.length;o>s;s++)e=u[s],t=e.split(/\s+/),i=t.shift(),(null!=(l=this.view.formatters[i])?l.publish:void 0)&&(n=(h=this.view.formatters[i]).publish.apply(h,[n].concat(r.call(t))));return this.observer.setValue(n)}},e.prototype.bind=function(){var t,e,i,n,s,r,o;if(this.parseTarget(),null!=(s=this.binder.bind)&&s.call(this,this.el),null!=this.model&&(null!=(r=this.options.dependencies)?r.length:void 0))for(o=this.options.dependencies,i=0,n=o.length;n>i;i++)t=o[i],e=this.observe(this.model,t,this.sync),this.dependencies.push(e);return this.view.preloadData?this.sync():void 0},e.prototype.unbind=function(){var t,e,i,n,s,r,o,u,l,h;for(null!=(o=this.binder.unbind)&&o.call(this,this.el),null!=(u=this.observer)&&u.unobserve(),l=this.dependencies,s=0,r=l.length;r>s;s++)n=l[s],n.unobserve();this.dependencies=[],h=this.formatterObservers;for(i in h){e=h[i];for(t in e)n=e[t],n.unobserve()}return this.formatterObservers={}},e.prototype.update=function(t){var e,i;return null==t&&(t={}),this.model=null!=(e=this.observer)?e.target:void 0,null!=(i=this.binder.update)?i.call(this,t):void 0},e.prototype.getValue=function(e){return this.binder&&null!=this.binder.getValue?this.binder.getValue.call(this,e):t.Util.getInputValue(e)},e}(),t.ComponentBinding=function(e){function i(e,i,n){var r,o,u,h,a,p,d,c;for(this.view=e,this.el=i,this.type=n,this.unbind=s(this.unbind,this),this.bind=s(this.bind,this),this.locals=s(this.locals,this),this.component=this.view.components[this.type],this["static"]={},this.observers={},this.upstreamObservers={},o=e.bindingRegExp(),d=this.el.attributes||[],a=0,p=d.length;p>a;a++)r=d[a],o.test(r.name)||(u=this.camelCase(r.name),h=t.TypeParser.parse(r.value),l.call(null!=(c=this.component["static"])?c:[],u)>=0?this["static"][u]=r.value:0===h.type?this["static"][u]=h.value:this.observers[u]=r.value)}return u(i,e),i.prototype.sync=function(){},i.prototype.update=function(){},i.prototype.publish=function(){},i.prototype.locals=function(){var t,e,i,n,s,r;i={},s=this["static"];for(t in s)n=s[t],i[t]=n;r=this.observers;for(t in r)e=r[t],i[t]=e.value();return i},i.prototype.camelCase=function(t){return t.replace(/-([a-z])/g,function(t){return t[1].toUpperCase()})},i.prototype.bind=function(){var e,i,n,s,r,o,u,l,h,a,p,d,c,f,b,v,y,m,g,w;if(!this.bound){f=this.observers;for(i in f)n=f[i],this.observers[i]=this.observe(this.view.models,n,function(t){return function(e){return function(){return t.componentView.models[e]=t.observers[e].value()}}}(this).call(this,i));this.bound=!0}if(null!=this.componentView)this.componentView.bind();else{for(this.el.innerHTML=this.component.template.call(this),u=this.component.initialize.call(this,this.el,this.locals()),this.el._bound=!0,o={},b=t.extensions,a=0,d=b.length;d>a;a++){if(r=b[a],o[r]={},this.component[r]){v=this.component[r];for(e in v)l=v[e],o[r][e]=l}y=this.view[r];for(e in y)l=y[e],null==(h=o[r])[e]&&(h[e]=l)}for(m=t.options,p=0,c=m.length;c>p;p++)r=m[p],o[r]=null!=(g=this.component[r])?g:this.view[r];this.componentView=new t.View(Array.prototype.slice.call(this.el.childNodes),u,o),this.componentView.bind(),w=this.observers;for(i in w)s=w[i],this.upstreamObservers[i]=this.observe(this.componentView.models,i,function(t){return function(e,i){return function(){return i.setValue(t.componentView.models[e])}}}(this).call(this,i,s))}},i.prototype.unbind=function(){var t,e,i,n,s;i=this.upstreamObservers;for(t in i)e=i[t],e.unobserve();n=this.observers;for(t in n)e=n[t],e.unobserve();return null!=(s=this.componentView)?s.unbind.call(this):void 0},i}(t.Binding),t.TextBinding=function(t){function e(t,e,i,n,r){this.view=t,this.el=e,this.type=i,this.keypath=n,this.options=null!=r?r:{},this.sync=s(this.sync,this),this.formatters=this.options.formatters||[],this.dependencies=[],this.formatterObservers={}}return u(e,t),e.prototype.binder={routine:function(t,e){return t.data=null!=e?e:""}},e.prototype.sync=function(){return e.__super__.sync.apply(this,arguments)},e}(t.Binding),t["public"].binders.text=function(t,e){return null!=t.textContent?t.textContent=null!=e?e:"":t.innerText=null!=e?e:""},t["public"].binders.html=function(t,e){return t.innerHTML=null!=e?e:""},t["public"].binders.show=function(t,e){return t.style.display=e?"":"none"},t["public"].binders.hide=function(t,e){return t.style.display=e?"none":""},t["public"].binders.enabled=function(t,e){return t.disabled=!e},t["public"].binders.disabled=function(t,e){return t.disabled=!!e},t["public"].binders.checked={publishes:!0,priority:2e3,bind:function(e){return t.Util.bindEvent(e,"change",this.publish)},unbind:function(e){return t.Util.unbindEvent(e,"change",this.publish)},routine:function(t,e){var i;return t.checked="radio"===t.type?(null!=(i=t.value)?i.toString():void 0)===(null!=e?e.toString():void 0):!!e}},t["public"].binders.unchecked={publishes:!0,priority:2e3,bind:function(e){return t.Util.bindEvent(e,"change",this.publish)},unbind:function(e){return t.Util.unbindEvent(e,"change",this.publish)},routine:function(t,e){var i;return t.checked="radio"===t.type?(null!=(i=t.value)?i.toString():void 0)!==(null!=e?e.toString():void 0):!e}},t["public"].binders.value={publishes:!0,priority:3e3,bind:function(e){return"INPUT"!==e.tagName||"radio"!==e.type?(this.event="SELECT"===e.tagName?"change":"input",t.Util.bindEvent(e,this.event,this.publish)):void 0},unbind:function(e){return"INPUT"!==e.tagName||"radio"!==e.type?t.Util.unbindEvent(e,this.event,this.publish):void 0},routine:function(t,e){var i,n,s,r,o,u,h;if("INPUT"===t.tagName&&"radio"===t.type)return t.setAttribute("value",e);if(null!=window.jQuery){if(t=jQuery(t),(null!=e?e.toString():void 0)!==(null!=(r=t.val())?r.toString():void 0))return t.val(null!=e?e:"")}else if("select-multiple"===t.type){if(null!=e){for(h=[],n=0,s=t.length;s>n;n++)i=t[n],h.push(i.selected=(o=i.value,l.call(e,o)>=0));return h}}else if((null!=e?e.toString():void 0)!==(null!=(u=t.value)?u.toString():void 0))return t.value=null!=e?e:""}},t["public"].binders["if"]={block:!0,priority:4e3,bind:function(t){var e,i;return null==this.marker?(e=[this.view.prefix,this.type].join("-").replace("--","-"),i=t.getAttribute(e),this.marker=document.createComment(" rivets: "+this.type+" "+i+" "),this.bound=!1,t.removeAttribute(e),t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t)):void 0},unbind:function(){return this.nested?(this.nested.unbind(),this.bound=!1):void 0},routine:function(e,i){var n,s,r,o;if(!!i==!this.bound){if(i){r={},o=this.view.models;for(n in o)s=o[n],r[n]=s;return(this.nested||(this.nested=new t.View(e,r,this.view.options()))).bind(),this.marker.parentNode.insertBefore(e,this.marker.nextSibling),this.bound=!0}return e.parentNode.removeChild(e),this.nested.unbind(),this.bound=!1}},update:function(t){var e;return null!=(e=this.nested)?e.update(t):void 0}},t["public"].binders.unless={block:!0,priority:4e3,bind:function(e){return t["public"].binders["if"].bind.call(this,e)},unbind:function(){return t["public"].binders["if"].unbind.call(this)},routine:function(e,i){return t["public"].binders["if"].routine.call(this,e,!i)},update:function(e){return t["public"].binders["if"].update.call(this,e)}},t["public"].binders["on-*"]={"function":!0,priority:1e3,unbind:function(e){return this.handler?t.Util.unbindEvent(e,this.args[0],this.handler):void 0},routine:function(e,i){return this.handler&&t.Util.unbindEvent(e,this.args[0],this.handler),t.Util.bindEvent(e,this.args[0],this.handler=this.eventHandler(i))}},t["public"].binders["each-*"]={block:!0,priority:4e3,bind:function(t){var e,i,n,s,r;if(null==this.marker)e=[this.view.prefix,this.type].join("-").replace("--","-"),this.marker=document.createComment(" rivets: "+this.type+" "),this.iterated=[],t.removeAttribute(e),t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t);else for(r=this.iterated,n=0,s=r.length;s>n;n++)i=r[n],i.bind()},unbind:function(){var t,e,i,n;if(null!=this.iterated)for(n=this.iterated,e=0,i=n.length;i>e;e++)t=n[e],t.unbind()},routine:function(e,i){var n,s,r,o,u,l,h,a,p,d,c,f,b,v,y,m,g,w,k,x;if(h=this.args[0],i=i||[],this.iterated.length>i.length)for(w=Array(this.iterated.length-i.length),f=0,y=w.length;y>f;f++)r=w[f],c=this.iterated.pop(),c.unbind(),this.marker.parentNode.removeChild(c.els[0]);for(o=b=0,m=i.length;m>b;o=++b)if(l=i[o],s={index:o},s[t["public"].iterationAlias(h)]=o,s[h]=l,null==this.iterated[o]){k=this.view.models;for(u in k)l=k[u],null==s[u]&&(s[u]=l);p=this.iterated.length?this.iterated[this.iterated.length-1].els[0]:this.marker,a=this.view.options(),a.preloadData=!0,d=e.cloneNode(!0),c=new t.View(d,s,a),c.bind(),this.iterated.push(c),this.marker.parentNode.insertBefore(d,p.nextSibling)}else this.iterated[o].models[h]!==l&&this.iterated[o].update(s);if("OPTION"===e.nodeName)for(x=this.view.bindings,v=0,g=x.length;g>v;v++)n=x[v],n.el===this.marker.parentNode&&"value"===n.type&&n.sync()},update:function(t){var e,i,n,s,r,o,u;e={};for(i in t)n=t[i],i!==this.args[0]&&(e[i]=n);for(u=this.iterated,r=0,o=u.length;o>r;r++)s=u[r],s.update(e)}},t["public"].binders["class-*"]=function(t,e){var i;return i=" "+t.className+" ",!e==(-1!==i.indexOf(" "+this.args[0]+" "))?t.className=e?""+t.className+" "+this.args[0]:i.replace(" "+this.args[0]+" "," ").trim():void 0},t["public"].binders["*"]=function(t,e){return null!=e?t.setAttribute(this.type,e):t.removeAttribute(this.type)},t["public"].formatters.call=function(){var t,e;return e=arguments[0],t=2<=arguments.length?r.call(arguments,1):[],e.call.apply(e,[this].concat(r.call(t)))},t["public"].adapters["."]={id:"_rv",counter:0,weakmap:{},weakReference:function(t){var e,i,n;return t.hasOwnProperty(this.id)||(e=this.counter++,Object.defineProperty(t,this.id,{value:e})),(i=this.weakmap)[n=t[this.id]]||(i[n]={callbacks:{}})},cleanupWeakReference:function(t,e){return Object.keys(t.callbacks).length||t.pointers&&Object.keys(t.pointers).length?void 0:delete this.weakmap[e]},stubFunction:function(t,e){var i,n,s;return n=t[e],i=this.weakReference(t),s=this.weakmap,t[e]=function(){var e,r,o,u,l,h,a,p,d,c;u=n.apply(t,arguments),a=i.pointers;for(o in a)for(r=a[o],c=null!=(p=null!=(d=s[o])?d.callbacks[r]:void 0)?p:[],l=0,h=c.length;h>l;l++)e=c[l],e();return u}},observeMutations:function(t,e,i){var n,s,r,o,u,h;if(Array.isArray(t)){if(r=this.weakReference(t),null==r.pointers)for(r.pointers={},s=["push","pop","shift","unshift","sort","reverse","splice"],u=0,h=s.length;h>u;u++)n=s[u],this.stubFunction(t,n);if(null==(o=r.pointers)[e]&&(o[e]=[]),l.call(r.pointers[e],i)<0)return r.pointers[e].push(i)}},unobserveMutations:function(t,e,i){var n,s,r;return Array.isArray(t)&&null!=t[this.id]&&(s=this.weakmap[t[this.id]])&&(r=s.pointers[e])?((n=r.indexOf(i))>=0&&r.splice(n,1),r.length||delete s.pointers[e],this.cleanupWeakReference(s,t[this.id])):void 0},observe:function(t,e,i){var n,s,r;return n=this.weakReference(t).callbacks,null==n[e]&&(n[e]=[],s=Object.getOwnPropertyDescriptor(t,e),(null!=s?s.get:void 0)||(null!=s?s.set:void 0)||(r=t[e],Object.defineProperty(t,e,{enumerable:!0,get:function(){return r},set:function(i){return function(s){var o,u,l,h,a;if(s!==r&&(i.unobserveMutations(r,t[i.id],e),r=s,u=i.weakmap[t[i.id]])){if(n=u.callbacks,n[e])for(a=n[e],l=0,h=a.length;h>l;l++)o=a[l],o();return i.observeMutations(s,t[i.id],e)}}}(this)}))),l.call(n[e],i)<0&&n[e].push(i),this.observeMutations(t[e],t[this.id],e)},unobserve:function(t,e,i){var n,s,r;return(r=this.weakmap[t[this.id]])&&(n=r.callbacks[e])?((s=n.indexOf(i))>=0&&(n.splice(s,1),n.length||delete r.callbacks[e]),this.unobserveMutations(t[e],t[this.id],e),this.cleanupWeakReference(r,t[this.id])):void 0},get:function(t,e){return t[e]},set:function(t,e,i){return t[e]=i}},t.factory=function(e){return t.sightglass=e,t["public"]._=t,t["public"]},"object"==typeof("undefined"!=typeof module&&null!==module?module.exports:void 0)?module.exports=t.factory(require("sightglass")):"function"==typeof define&&define.amd?define(["sightglass"],function(e){return this.rivets=t.factory(e)}):this.rivets=t.factory(sightglass)}).call(this); \ No newline at end of file +(function(){function t(t,s,i,h){return new e(t,s,i,h)}function e(t,e,i,h){this.options=h||{},this.options.adapters=this.options.adapters||{},this.obj=t,this.keypath=e,this.callback=i,this.objectPath=[],this.update=this.update.bind(this),this.parse(),s(this.target=this.realize())&&this.set(!0,this.key,this.target,this.callback)}function s(t){return"object"==typeof t&&null!==t}function i(t){throw new Error("[sightglass] "+t)}t.adapters={},e.tokenize=function(t,e,s){var i,h,a=[],o={i:s,path:""};for(i=0;ie;e++)if(e in this&&this[e]===t)return e;return-1};t={options:["prefix","templateDelimiters","rootInterface","preloadData","handler","executeFunctions"],extensions:["binders","formatters","components","adapters"],"public":{binders:{},components:{},formatters:{},adapters:{},prefix:"rv",templateDelimiters:["{","}"],rootInterface:".",preloadData:!0,executeFunctions:!1,iterationAlias:function(t){return"%"+t+"%"},handler:function(t,e,i){return this.call(t,e,i.view.models)},configure:function(e){var i,n,r,s;null==e&&(e={});for(r in e)if(s=e[r],"binders"===r||"components"===r||"formatters"===r||"adapters"===r)for(n in s)i=s[n],t[r][n]=i;else t["public"][r]=s},bind:function(e,i,n){var r;return null==i&&(i={}),null==n&&(n={}),r=new t.View(e,i,n),r.bind(),r},init:function(e,i,n){var r,s,o;if(null==n&&(n={}),null==i&&(i=document.createElement("div")),e=t["public"].components[e],s=e.template.call(this,i),s instanceof HTMLElement){for(;i.firstChild;)i.removeChild(i.firstChild);i.appendChild(s)}else i.innerHTML=s;return r=e.initialize.call(this,i,n),o=new t.View(i,r),o.bind(),o}}},window.jQuery||window.$?(n="on"in jQuery.prototype?["on","off"]:["bind","unbind"],e=n[0],i=n[1],t.Util={bindEvent:function(t,i,n){return jQuery(t)[e](i,n)},unbindEvent:function(t,e,n){return jQuery(t)[i](e,n)},getInputValue:function(t){var e;return e=jQuery(t),"checkbox"===e.attr("type")?e.is(":checked"):e.val()}}):t.Util={bindEvent:function(){return"addEventListener"in window?function(t,e,i){return t.addEventListener(e,i,!1)}:function(t,e,i){return t.attachEvent("on"+e,i)}}(),unbindEvent:function(){return"removeEventListener"in window?function(t,e,i){return t.removeEventListener(e,i,!1)}:function(t,e,i){return t.detachEvent("on"+e,i)}}(),getInputValue:function(t){var e,i,n,r;if("checkbox"===t.type)return t.checked;if("select-multiple"===t.type){for(r=[],i=0,n=t.length;n>i;i++)e=t[i],e.selected&&r.push(e.value);return r}return t.value}},t.TypeParser=function(){function t(){}return t.types={primitive:0,keypath:1},t.parse=function(t){return/^'.*'$|^".*"$/.test(t)?{type:this.types.primitive,value:t.slice(1,-1)}:"true"===t?{type:this.types.primitive,value:!0}:"false"===t?{type:this.types.primitive,value:!1}:"null"===t?{type:this.types.primitive,value:null}:"undefined"===t?{type:this.types.primitive,value:void 0}:""===t?{type:this.types.primitive,value:void 0}:isNaN(Number(t))===!1?{type:this.types.primitive,value:Number(t)}:{type:this.types.keypath,value:t}},t}(),t.TextTemplateParser=function(){function t(){}return t.types={text:0,binding:1},t.parse=function(t,e){var i,n,r,s,o,u,l;for(u=[],s=t.length,i=0,n=0;s>n;){if(i=t.indexOf(e[0],n),0>i){u.push({type:this.types.text,value:t.slice(n)});break}if(i>0&&i>n&&u.push({type:this.types.text,value:t.slice(n,i)}),n=i+e[0].length,i=t.indexOf(e[1],n),0>i){o=t.slice(n-e[1].length),r=u[u.length-1],(null!=r?r.type:void 0)===this.types.text?r.value+=o:u.push({type:this.types.text,value:o});break}l=t.slice(n,i).trim(),u.push({type:this.types.binding,value:l}),n=i+e[1].length}return u},t}(),t.View=function(){function e(e,i,n){var s,o,u,l,h,a,p,d,c,f,b,v,m;for(this.els=e,this.models=i,null==n&&(n={}),this.update=r(this.update,this),this.publish=r(this.publish,this),this.sync=r(this.sync,this),this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.select=r(this.select,this),this.traverse=r(this.traverse,this),this.build=r(this.build,this),this.buildBinding=r(this.buildBinding,this),this.bindingRegExp=r(this.bindingRegExp,this),this.options=r(this.options,this),this.els.jquery||this.els instanceof Array||(this.els=[this.els]),c=t.extensions,h=0,p=c.length;p>h;h++){if(o=c[h],this[o]={},n[o]){f=n[o];for(s in f)u=f[s],this[o][s]=u}b=t["public"][o];for(s in b)u=b[s],null==(l=this[o])[s]&&(l[s]=u)}for(v=t.options,a=0,d=v.length;d>a;a++)o=v[a],this[o]=null!=(m=n[o])?m:t["public"][o];this.build()}return e.prototype.options=function(){var e,i,n,r,s;for(i={},s=t.extensions.concat(t.options),n=0,r=s.length;r>n;n++)e=s[n],i[e]=this[e];return i},e.prototype.bindingRegExp=function(){return new RegExp("^"+this.prefix+"-")},e.prototype.buildBinding=function(e,i,n,r){var s,o,u,l,h,a,p;return h={},p=function(){var t,e,i,n;for(i=r.match(/((?:'[^']*')*(?:(?:[^\|']*(?:'[^']*')+[^\|']*)+|[^\|]+))|^$/g),n=[],t=0,e=i.length;e>t;t++)a=i[t],n.push(a.trim());return n}(),s=function(){var t,e,i,n;for(i=p.shift().split("<"),n=[],t=0,e=i.length;e>t;t++)o=i[t],n.push(o.trim());return n}(),l=s.shift(),h.formatters=p,(u=s.shift())&&(h.dependencies=u.split(/\s+/)),this.bindings.push(new t[e](this,i,n,l,h))},e.prototype.build=function(){var e,i,n,r,s;for(this.bindings=[],i=function(e){return function(n){var r,s,o,u,l,h,a,p,d,c,f,b,v;if(3===n.nodeType){if(l=t.TextTemplateParser,(o=e.templateDelimiters)&&(p=l.parse(n.data,o)).length&&(1!==p.length||p[0].type!==l.types.text)){for(d=0,f=p.length;f>d;d++)a=p[d],h=document.createTextNode(a.value),n.parentNode.insertBefore(h,n),1===a.type&&e.buildBinding("TextBinding",h,null,a.value);n.parentNode.removeChild(n)}}else 1===n.nodeType&&(r=e.traverse(n));if(!r)for(v=function(){var t,e,i,r;for(i=n.childNodes,r=[],t=0,e=i.length;e>t;t++)u=i[t],r.push(u);return r}(),c=0,b=v.length;b>c;c++)s=v[c],i(s)}}(this),s=this.els,n=0,r=s.length;r>n;n++)e=s[n],i(e);this.bindings.sort(function(t,e){var i,n;return((null!=(i=e.binder)?i.priority:void 0)||0)-((null!=(n=t.binder)?n.priority:void 0)||0)})},e.prototype.traverse=function(e){var i,n,r,s,o,u,l,h,a,p,d,c,f,b,v,m;for(s=this.bindingRegExp(),o="SCRIPT"===e.nodeName||"STYLE"===e.nodeName,b=e.attributes,p=0,c=b.length;c>p;p++)if(i=b[p],s.test(i.name)){if(h=i.name.replace(s,""),!(r=this.binders[h])){v=this.binders;for(u in v)a=v[u],"*"!==u&&-1!==u.indexOf("*")&&(l=new RegExp("^"+u.replace(/\*/g,".+")+"$"),l.test(h)&&(r=a))}r||(r=this.binders["*"]),r.block&&(o=!0,n=[i])}for(m=n||e.attributes,d=0,f=m.length;f>d;d++)i=m[d],s.test(i.name)&&(h=i.name.replace(s,""),this.buildBinding("Binding",e,h,i.value));return o||(h=e.nodeName.toLowerCase(),this.components[h]&&!e._bound&&(this.bindings.push(new t.ComponentBinding(this,e,h)),o=!0)),o},e.prototype.select=function(t){var e,i,n,r,s;for(r=this.bindings,s=[],i=0,n=r.length;n>i;i++)e=r[i],t(e)&&s.push(e);return s},e.prototype.bind=function(){var t,e,i,n;for(n=this.bindings,e=0,i=n.length;i>e;e++)t=n[e],t.bind()},e.prototype.unbind=function(){var t,e,i,n;for(n=this.bindings,e=0,i=n.length;i>e;e++)t=n[e],t.unbind()},e.prototype.sync=function(){var t,e,i,n;for(n=this.bindings,e=0,i=n.length;i>e;e++)t=n[e],"function"==typeof t.sync&&t.sync()},e.prototype.publish=function(){var t,e,i,n;for(n=this.select(function(t){var e;return null!=(e=t.binder)?e.publishes:void 0}),e=0,i=n.length;i>e;e++)t=n[e],t.publish()},e.prototype.update=function(t){var e,i,n,r,s,o;null==t&&(t={});for(i in t)n=t[i],this.models[i]=n;for(o=this.bindings,r=0,s=o.length;s>r;r++)e=o[r],"function"==typeof e.update&&e.update(t)},e}(),t.Binding=function(){function e(t,e,i,n,s){this.view=t,this.el=e,this.type=i,this.keypath=n,this.options=null!=s?s:{},this.getValue=r(this.getValue,this),this.update=r(this.update,this),this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.publish=r(this.publish,this),this.sync=r(this.sync,this),this.set=r(this.set,this),this.eventHandler=r(this.eventHandler,this),this.formattedValue=r(this.formattedValue,this),this.parseFormatterArguments=r(this.parseFormatterArguments,this),this.parseTarget=r(this.parseTarget,this),this.observe=r(this.observe,this),this.setBinder=r(this.setBinder,this),this.formatters=this.options.formatters||[],this.dependencies=[],this.formatterObservers={},this.model=void 0,this.setBinder()}return e.prototype.setBinder=function(){var t,e,i,n;if(!(this.binder=this.view.binders[this.type])){n=this.view.binders;for(t in n)i=n[t],"*"!==t&&-1!==t.indexOf("*")&&(e=new RegExp("^"+t.replace(/\*/g,".+")+"$"),e.test(this.type)&&(this.binder=i,this.args=new RegExp("^"+t.replace(/\*/g,"(.+)")+"$").exec(this.type),this.args.shift()))}return this.binder||(this.binder=this.view.binders["*"]),this.binder instanceof Function?this.binder={routine:this.binder}:void 0},e.prototype.observe=function(e,i,n){return t.sightglass(e,i,n,{root:this.view.rootInterface,adapters:this.view.adapters})},e.prototype.parseTarget=function(){var e;return e=t.TypeParser.parse(this.keypath),e.type===t.TypeParser.types.primitive?this.value=e.value:(this.observer=this.observe(this.view.models,this.keypath,this.sync),this.model=this.observer.target)},e.prototype.parseFormatterArguments=function(e,i){var n,r,s,o,u,l,h;for(e=function(){var i,n,s;for(s=[],i=0,n=e.length;n>i;i++)r=e[i],s.push(t.TypeParser.parse(r));return s}(),o=[],n=l=0,h=e.length;h>l;n=++l)r=e[n],o.push(r.type===t.TypeParser.types.primitive?r.value:((u=this.formatterObservers)[i]||(u[i]={}),(s=this.formatterObservers[i][n])?void 0:(s=this.observe(this.view.models,r.value,this.sync),this.formatterObservers[i][n]=s),s.value()));return o},e.prototype.formattedValue=function(t){var e,i,n,r,o,u,l,h,a;for(h=this.formatters,i=u=0,l=h.length;l>u;i=++u)n=h[i],e=n.match(/[^\s']+|'([^']|'[^\s])*'|"([^"]|"[^\s])*"/g),r=e.shift(),n=this.view.formatters[r],o=this.parseFormatterArguments(e,i),(null!=n?n.read:void 0)instanceof Function?t=(a=n.read).call.apply(a,[this.model,t].concat(s.call(o))):n instanceof Function&&(t=n.call.apply(n,[this.model,t].concat(s.call(o))));return t},e.prototype.eventHandler=function(t){var e,i;return i=(e=this).view.handler,function(n){return i.call(t,this,n,e)}},e.prototype.set=function(e){var i;return e=e instanceof Function&&!this.binder["function"]&&t["public"].executeFunctions?this.formattedValue(e.call(this.model)):this.formattedValue(e),null!=(i=this.binder.routine)?i.call(this,this.el,e):void 0},e.prototype.sync=function(){var t,e;return this.set(function(){var i,n,r,s,o,u,l;if(this.observer){if(this.model!==this.observer.target){for(o=this.dependencies,i=0,r=o.length;r>i;i++)e=o[i],e.unobserve();if(this.dependencies=[],null!=(this.model=this.observer.target)&&(null!=(u=this.options.dependencies)?u.length:void 0))for(l=this.options.dependencies,n=0,s=l.length;s>n;n++)t=l[n],e=this.observe(this.model,t,this.sync),this.dependencies.push(e)}return this.observer.value()}return this.value}.call(this))},e.prototype.publish=function(){var t,e,i,n,r,o,u,l,h,a,p,d,c;if(this.observer){for(l=this.getValue(this.el),o=this.formatters.length-1,p=this.formatters.slice(0).reverse(),i=h=0,a=p.length;a>h;i=++h)n=p[i],e=o-i,t=n.split(/\s+/),r=t.shift(),u=this.parseFormatterArguments(t,e),(null!=(d=this.view.formatters[r])?d.publish:void 0)&&(l=(c=this.view.formatters[r]).publish.apply(c,[l].concat(s.call(u))));return this.observer.setValue(l)}},e.prototype.bind=function(){var t,e,i,n,r,s,o;if(this.parseTarget(),null!=(r=this.binder.bind)&&r.call(this,this.el),null!=this.model&&(null!=(s=this.options.dependencies)?s.length:void 0))for(o=this.options.dependencies,i=0,n=o.length;n>i;i++)t=o[i],e=this.observe(this.model,t,this.sync),this.dependencies.push(e);return this.view.preloadData?this.sync():void 0},e.prototype.unbind=function(){var t,e,i,n,r,s,o,u,l,h;for(null!=(o=this.binder.unbind)&&o.call(this,this.el),null!=(u=this.observer)&&u.unobserve(),l=this.dependencies,r=0,s=l.length;s>r;r++)n=l[r],n.unobserve();this.dependencies=[],h=this.formatterObservers;for(i in h){e=h[i];for(t in e)n=e[t],n.unobserve()}return this.formatterObservers={}},e.prototype.update=function(t){var e,i;return null==t&&(t={}),this.model=null!=(e=this.observer)?e.target:void 0,null!=(i=this.binder.update)?i.call(this,t):void 0},e.prototype.getValue=function(e){return this.binder&&null!=this.binder.getValue?this.binder.getValue.call(this,e):t.Util.getInputValue(e)},e}(),t.ComponentBinding=function(e){function i(e,i,n){var s,o,u,h,a,p,d,c;for(this.view=e,this.el=i,this.type=n,this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.locals=r(this.locals,this),this.component=this.view.components[this.type],this["static"]={},this.observers={},this.upstreamObservers={},o=e.bindingRegExp(),d=this.el.attributes||[],a=0,p=d.length;p>a;a++)s=d[a],o.test(s.name)||(u=this.camelCase(s.name),h=t.TypeParser.parse(s.value),l.call(null!=(c=this.component["static"])?c:[],u)>=0?this["static"][u]=s.value:h.type===t.TypeParser.types.primitive?this["static"][u]=h.value:this.observers[u]=s.value)}return u(i,e),i.prototype.sync=function(){},i.prototype.update=function(){},i.prototype.publish=function(){},i.prototype.locals=function(){var t,e,i,n,r,s;i={},r=this["static"];for(t in r)n=r[t],i[t]=n;s=this.observers;for(t in s)e=s[t],i[t]=e.value();return i},i.prototype.camelCase=function(t){return t.replace(/-([a-z])/g,function(t){return t[1].toUpperCase()})},i.prototype.bind=function(){var e,i,n,r,s,o,u,l,h,a,p,d,c,f,b,v,m,y,g,w;if(!this.bound){f=this.observers;for(i in f)n=f[i],this.observers[i]=this.observe(this.view.models,n,function(t){return function(e){return function(){return t.componentView.models[e]=t.observers[e].value()}}}(this).call(this,i));this.bound=!0}if(null!=this.componentView)this.componentView.bind();else{for(this.el.innerHTML=this.component.template.call(this),u=this.component.initialize.call(this,this.el,this.locals()),this.el._bound=!0,o={},b=t.extensions,a=0,d=b.length;d>a;a++){if(s=b[a],o[s]={},this.component[s]){v=this.component[s];for(e in v)l=v[e],o[s][e]=l}m=this.view[s];for(e in m)l=m[e],null==(h=o[s])[e]&&(h[e]=l)}for(y=t.options,p=0,c=y.length;c>p;p++)s=y[p],o[s]=null!=(g=this.component[s])?g:this.view[s];this.componentView=new t.View(Array.prototype.slice.call(this.el.childNodes),u,o),this.componentView.bind(),w=this.observers;for(i in w)r=w[i],this.upstreamObservers[i]=this.observe(this.componentView.models,i,function(t){return function(e,i){return function(){return i.setValue(t.componentView.models[e])}}}(this).call(this,i,r))}},i.prototype.unbind=function(){var t,e,i,n,r;i=this.upstreamObservers;for(t in i)e=i[t],e.unobserve();n=this.observers;for(t in n)e=n[t],e.unobserve();return null!=(r=this.componentView)?r.unbind.call(this):void 0},i}(t.Binding),t.TextBinding=function(t){function e(t,e,i,n,s){this.view=t,this.el=e,this.type=i,this.keypath=n,this.options=null!=s?s:{},this.sync=r(this.sync,this),this.formatters=this.options.formatters||[],this.dependencies=[],this.formatterObservers={}}return u(e,t),e.prototype.binder={routine:function(t,e){return t.data=null!=e?e:""}},e.prototype.sync=function(){return e.__super__.sync.apply(this,arguments)},e}(t.Binding),t["public"].binders.text=function(t,e){return null!=t.textContent?t.textContent=null!=e?e:"":t.innerText=null!=e?e:""},t["public"].binders.html=function(t,e){return t.innerHTML=null!=e?e:""},t["public"].binders.show=function(t,e){return t.style.display=e?"":"none"},t["public"].binders.hide=function(t,e){return t.style.display=e?"none":""},t["public"].binders.enabled=function(t,e){return t.disabled=!e},t["public"].binders.disabled=function(t,e){return t.disabled=!!e},t["public"].binders.checked={publishes:!0,priority:2e3,bind:function(e){return t.Util.bindEvent(e,"change",this.publish)},unbind:function(e){return t.Util.unbindEvent(e,"change",this.publish)},routine:function(t,e){var i;return t.checked="radio"===t.type?(null!=(i=t.value)?i.toString():void 0)===(null!=e?e.toString():void 0):!!e}},t["public"].binders.unchecked={publishes:!0,priority:2e3,bind:function(e){return t.Util.bindEvent(e,"change",this.publish)},unbind:function(e){return t.Util.unbindEvent(e,"change",this.publish)},routine:function(t,e){var i;return t.checked="radio"===t.type?(null!=(i=t.value)?i.toString():void 0)!==(null!=e?e.toString():void 0):!e}},t["public"].binders.value={publishes:!0,priority:3e3,bind:function(e){return"INPUT"!==e.tagName||"radio"!==e.type?(this.event="SELECT"===e.tagName?"change":"input",t.Util.bindEvent(e,this.event,this.publish)):void 0},unbind:function(e){return"INPUT"!==e.tagName||"radio"!==e.type?t.Util.unbindEvent(e,this.event,this.publish):void 0},routine:function(t,e){var i,n,r,s,o,u,h;if("INPUT"===t.tagName&&"radio"===t.type)return t.setAttribute("value",e);if(null!=window.jQuery){if(t=jQuery(t),(null!=e?e.toString():void 0)!==(null!=(s=t.val())?s.toString():void 0))return t.val(null!=e?e:"")}else if("select-multiple"===t.type){if(null!=e){for(h=[],n=0,r=t.length;r>n;n++)i=t[n],h.push(i.selected=(o=i.value,l.call(e,o)>=0));return h}}else if((null!=e?e.toString():void 0)!==(null!=(u=t.value)?u.toString():void 0))return t.value=null!=e?e:""}},t["public"].binders["if"]={block:!0,priority:4e3,bind:function(t){var e,i;return null==this.marker?(e=[this.view.prefix,this.type].join("-").replace("--","-"),i=t.getAttribute(e),this.marker=document.createComment(" rivets: "+this.type+" "+i+" "),this.bound=!1,t.removeAttribute(e),t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t)):void 0},unbind:function(){return this.nested?(this.nested.unbind(),this.bound=!1):void 0},routine:function(e,i){var n,r,s,o;if(!!i==!this.bound){if(i){s={},o=this.view.models;for(n in o)r=o[n],s[n]=r;return(this.nested||(this.nested=new t.View(e,s,this.view.options()))).bind(),this.marker.parentNode.insertBefore(e,this.marker.nextSibling),this.bound=!0}return e.parentNode.removeChild(e),this.nested.unbind(),this.bound=!1}},update:function(t){var e;return null!=(e=this.nested)?e.update(t):void 0}},t["public"].binders.unless={block:!0,priority:4e3,bind:function(e){return t["public"].binders["if"].bind.call(this,e)},unbind:function(){return t["public"].binders["if"].unbind.call(this)},routine:function(e,i){return t["public"].binders["if"].routine.call(this,e,!i)},update:function(e){return t["public"].binders["if"].update.call(this,e)}},t["public"].binders["on-*"]={"function":!0,priority:1e3,unbind:function(e){return this.handler?t.Util.unbindEvent(e,this.args[0],this.handler):void 0},routine:function(e,i){return this.handler&&t.Util.unbindEvent(e,this.args[0],this.handler),t.Util.bindEvent(e,this.args[0],this.handler=this.eventHandler(i))}},t["public"].binders["each-*"]={block:!0,priority:4e3,bind:function(t){var e,i,n,r,s;if(null==this.marker)e=[this.view.prefix,this.type].join("-").replace("--","-"),this.marker=document.createComment(" rivets: "+this.type+" "),this.iterated=[],t.removeAttribute(e),t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t);else for(s=this.iterated,n=0,r=s.length;r>n;n++)i=s[n],i.bind()},unbind:function(){var t,e,i,n;if(null!=this.iterated)for(n=this.iterated,e=0,i=n.length;i>e;e++)t=n[e],t.unbind()},routine:function(e,i){var n,r,s,o,u,l,h,a,p,d,c,f,b,v,m,y,g,w,k,x;if(h=this.args[0],i=i||[],this.iterated.length>i.length)for(w=Array(this.iterated.length-i.length),f=0,m=w.length;m>f;f++)s=w[f],c=this.iterated.pop(),c.unbind(),this.marker.parentNode.removeChild(c.els[0]);for(o=b=0,y=i.length;y>b;o=++b)if(l=i[o],r={index:o},r[t["public"].iterationAlias(h)]=o,r[h]=l,null==this.iterated[o]){k=this.view.models;for(u in k)l=k[u],null==r[u]&&(r[u]=l);p=this.iterated.length?this.iterated[this.iterated.length-1].els[0]:this.marker,a=this.view.options(),a.preloadData=!0,d=e.cloneNode(!0),c=new t.View(d,r,a),c.bind(),this.iterated.push(c),this.marker.parentNode.insertBefore(d,p.nextSibling)}else this.iterated[o].models[h]!==l&&this.iterated[o].update(r);if("OPTION"===e.nodeName)for(x=this.view.bindings,v=0,g=x.length;g>v;v++)n=x[v],n.el===this.marker.parentNode&&"value"===n.type&&n.sync()},update:function(t){var e,i,n,r,s,o,u;e={};for(i in t)n=t[i],i!==this.args[0]&&(e[i]=n);for(u=this.iterated,s=0,o=u.length;o>s;s++)r=u[s],r.update(e)}},t["public"].binders["class-*"]=function(t,e){var i;return i=" "+t.className+" ",!e==(-1!==i.indexOf(" "+this.args[0]+" "))?t.className=e?""+t.className+" "+this.args[0]:i.replace(" "+this.args[0]+" "," ").trim():void 0},t["public"].binders["*"]=function(t,e){return null!=e?t.setAttribute(this.type,e):t.removeAttribute(this.type)},t["public"].formatters.call=function(){var t,e;return e=arguments[0],t=2<=arguments.length?s.call(arguments,1):[],e.call.apply(e,[this].concat(s.call(t)))},t["public"].adapters["."]={id:"_rv",counter:0,weakmap:{},weakReference:function(t){var e,i,n;return t.hasOwnProperty(this.id)||(e=this.counter++,Object.defineProperty(t,this.id,{value:e})),(i=this.weakmap)[n=t[this.id]]||(i[n]={callbacks:{}})},cleanupWeakReference:function(t,e){return Object.keys(t.callbacks).length||t.pointers&&Object.keys(t.pointers).length?void 0:delete this.weakmap[e]},stubFunction:function(t,e){var i,n,r;return n=t[e],i=this.weakReference(t),r=this.weakmap,t[e]=function(){var e,s,o,u,l,h,a,p,d,c;u=n.apply(t,arguments),a=i.pointers;for(o in a)for(s=a[o],c=null!=(p=null!=(d=r[o])?d.callbacks[s]:void 0)?p:[],l=0,h=c.length;h>l;l++)e=c[l],e();return u}},observeMutations:function(t,e,i){var n,r,s,o,u,h;if(Array.isArray(t)){if(s=this.weakReference(t),null==s.pointers)for(s.pointers={},r=["push","pop","shift","unshift","sort","reverse","splice"],u=0,h=r.length;h>u;u++)n=r[u],this.stubFunction(t,n);if(null==(o=s.pointers)[e]&&(o[e]=[]),l.call(s.pointers[e],i)<0)return s.pointers[e].push(i)}},unobserveMutations:function(t,e,i){var n,r,s;return Array.isArray(t)&&null!=t[this.id]&&(r=this.weakmap[t[this.id]])&&(s=r.pointers[e])?((n=s.indexOf(i))>=0&&s.splice(n,1),s.length||delete r.pointers[e],this.cleanupWeakReference(r,t[this.id])):void 0},observe:function(t,e,i){var n,r,s;return n=this.weakReference(t).callbacks,null==n[e]&&(n[e]=[],r=Object.getOwnPropertyDescriptor(t,e),(null!=r?r.get:void 0)||(null!=r?r.set:void 0)||(s=t[e],Object.defineProperty(t,e,{enumerable:!0,get:function(){return s},set:function(i){return function(r){var o,u,h,a,p;if(r!==s&&(i.unobserveMutations(s,t[i.id],e),s=r,u=i.weakmap[t[i.id]])){if(n=u.callbacks,n[e])for(p=n[e].slice(),h=0,a=p.length;a>h;h++)o=p[h],l.call(n[e],o)>=0&&o();return i.observeMutations(r,t[i.id],e)}}}(this)}))),l.call(n[e],i)<0&&n[e].push(i),this.observeMutations(t[e],t[this.id],e)},unobserve:function(t,e,i){var n,r,s;return(s=this.weakmap[t[this.id]])&&(n=s.callbacks[e])?((r=n.indexOf(i))>=0&&(n.splice(r,1),n.length||(delete s.callbacks[e],this.unobserveMutations(t[e],t[this.id],e))),this.cleanupWeakReference(s,t[this.id])):void 0},get:function(t,e){return t[e]},set:function(t,e,i){return t[e]=i}},t.factory=function(e){return t.sightglass=e,t["public"]._=t,t["public"]},"object"==typeof("undefined"!=typeof module&&null!==module?module.exports:void 0)?module.exports=t.factory(require("sightglass")):"function"==typeof define&&define.amd?define(["sightglass"],function(e){return this.rivets=t.factory(e)}):this.rivets=t.factory(sightglass)}).call(this); \ No newline at end of file diff --git a/dist/rivets.js b/dist/rivets.js index 6316105b0..860d2c081 100755 --- a/dist/rivets.js +++ b/dist/rivets.js @@ -1,5 +1,5 @@ // Rivets.js -// version: 0.9.1 +// version: 0.9.2 // author: Michael Richards // license: MIT (function() { @@ -548,6 +548,7 @@ this.set = __bind(this.set, this); this.eventHandler = __bind(this.eventHandler, this); this.formattedValue = __bind(this.formattedValue, this); + this.parseFormatterArguments = __bind(this.parseFormatterArguments, this); this.parseTarget = __bind(this.parseTarget, this); this.observe = __bind(this.observe, this); this.setBinder = __bind(this.setBinder, this); @@ -592,7 +593,7 @@ Binding.prototype.parseTarget = function() { var token; token = Rivets.TypeParser.parse(this.keypath); - if (token.type === 0) { + if (token.type === Rivets.TypeParser.types.primitive) { return this.value = token.value; } else { this.observer = this.observe(this.view.models, this.keypath, this.sync); @@ -600,28 +601,34 @@ } }; + Binding.prototype.parseFormatterArguments = function(args, formatterIndex) { + var ai, arg, observer, processedArgs, _base, _i, _len; + args = (function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = args.length; _i < _len; _i++) { + arg = args[_i]; + _results.push(Rivets.TypeParser.parse(arg)); + } + return _results; + })(); + processedArgs = []; + for (ai = _i = 0, _len = args.length; _i < _len; ai = ++_i) { + arg = args[ai]; + processedArgs.push(arg.type === Rivets.TypeParser.types.primitive ? arg.value : ((_base = this.formatterObservers)[formatterIndex] || (_base[formatterIndex] = {}), !(observer = this.formatterObservers[formatterIndex][ai]) ? (observer = this.observe(this.view.models, arg.value, this.sync), this.formatterObservers[formatterIndex][ai] = observer) : void 0, observer.value())); + } + return processedArgs; + }; + Binding.prototype.formattedValue = function(value) { - var ai, arg, args, fi, formatter, id, observer, processedArgs, _base, _i, _j, _len, _len1, _ref1, _ref2; + var args, fi, formatter, id, processedArgs, _i, _len, _ref1, _ref2; _ref1 = this.formatters; for (fi = _i = 0, _len = _ref1.length; _i < _len; fi = ++_i) { formatter = _ref1[fi]; args = formatter.match(/[^\s']+|'([^']|'[^\s])*'|"([^"]|"[^\s])*"/g); id = args.shift(); formatter = this.view.formatters[id]; - args = (function() { - var _j, _len1, _results; - _results = []; - for (_j = 0, _len1 = args.length; _j < _len1; _j++) { - arg = args[_j]; - _results.push(Rivets.TypeParser.parse(arg)); - } - return _results; - })(); - processedArgs = []; - for (ai = _j = 0, _len1 = args.length; _j < _len1; ai = ++_j) { - arg = args[ai]; - processedArgs.push(arg.type === 0 ? arg.value : ((_base = this.formatterObservers)[fi] || (_base[fi] = {}), !(observer = this.formatterObservers[fi][ai]) ? (observer = this.observe(this.view.models, arg.value, this.sync), this.formatterObservers[fi][ai] = observer) : void 0, observer.value())); - } + processedArgs = this.parseFormatterArguments(args, fi); if ((formatter != null ? formatter.read : void 0) instanceof Function) { value = (_ref2 = formatter.read).call.apply(_ref2, [this.model, value].concat(__slice.call(processedArgs))); } else if (formatter instanceof Function) { @@ -674,16 +681,19 @@ }; Binding.prototype.publish = function() { - var args, formatter, id, value, _i, _len, _ref1, _ref2, _ref3; + var args, fi, fiReversed, formatter, id, lastformatterIndex, processedArgs, value, _i, _len, _ref1, _ref2, _ref3; if (this.observer) { value = this.getValue(this.el); + lastformatterIndex = this.formatters.length - 1; _ref1 = this.formatters.slice(0).reverse(); - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - formatter = _ref1[_i]; + for (fiReversed = _i = 0, _len = _ref1.length; _i < _len; fiReversed = ++_i) { + formatter = _ref1[fiReversed]; + fi = lastformatterIndex - fiReversed; args = formatter.split(/\s+/); id = args.shift(); + processedArgs = this.parseFormatterArguments(args, fi); if ((_ref2 = this.view.formatters[id]) != null ? _ref2.publish : void 0) { - value = (_ref3 = this.view.formatters[id]).publish.apply(_ref3, [value].concat(__slice.call(args))); + value = (_ref3 = this.view.formatters[id]).publish.apply(_ref3, [value].concat(__slice.call(processedArgs))); } } return this.observer.setValue(value); @@ -779,7 +789,7 @@ token = Rivets.TypeParser.parse(attribute.value); if (__indexOf.call((_ref2 = this.component["static"]) != null ? _ref2 : [], propertyName) >= 0) { this["static"][propertyName] = attribute.value; - } else if (token.type === 0) { + } else if (token.type === Rivets.TypeParser.types.primitive) { this["static"][propertyName] = token.value; } else { this.observers[propertyName] = attribute.value; @@ -1333,10 +1343,12 @@ if (map = _this.weakmap[obj[_this.id]]) { callbacks = map.callbacks; if (callbacks[keypath]) { - _ref1 = callbacks[keypath]; + _ref1 = callbacks[keypath].slice(); for (_i = 0, _len = _ref1.length; _i < _len; _i++) { cb = _ref1[_i]; - cb(); + if (__indexOf.call(callbacks[keypath], cb) >= 0) { + cb(); + } } } return _this.observeMutations(newValue, obj[_this.id], keypath); @@ -1360,9 +1372,9 @@ callbacks.splice(idx, 1); if (!callbacks.length) { delete map.callbacks[keypath]; + this.unobserveMutations(obj[keypath], obj[this.id], keypath); } } - this.unobserveMutations(obj[keypath], obj[this.id], keypath); return this.cleanupWeakReference(map, obj[this.id]); } } diff --git a/dist/rivets.min.js b/dist/rivets.min.js index 1ee8a9cb5..7e7a2dff1 100755 --- a/dist/rivets.min.js +++ b/dist/rivets.min.js @@ -1,5 +1,5 @@ // Rivets.js -// version: 0.9.1 +// version: 0.9.2 // author: Michael Richards // license: MIT -(function(){var t,e,i,n,s=function(t,e){return function(){return t.apply(e,arguments)}},r=[].slice,o={}.hasOwnProperty,u=function(t,e){function i(){this.constructor=t}for(var n in e)o.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},l=[].indexOf||function(t){for(var e=0,i=this.length;i>e;e++)if(e in this&&this[e]===t)return e;return-1};t={options:["prefix","templateDelimiters","rootInterface","preloadData","handler","executeFunctions"],extensions:["binders","formatters","components","adapters"],"public":{binders:{},components:{},formatters:{},adapters:{},prefix:"rv",templateDelimiters:["{","}"],rootInterface:".",preloadData:!0,executeFunctions:!1,iterationAlias:function(t){return"%"+t+"%"},handler:function(t,e,i){return this.call(t,e,i.view.models)},configure:function(e){var i,n,s,r;null==e&&(e={});for(s in e)if(r=e[s],"binders"===s||"components"===s||"formatters"===s||"adapters"===s)for(n in r)i=r[n],t[s][n]=i;else t["public"][s]=r},bind:function(e,i,n){var s;return null==i&&(i={}),null==n&&(n={}),s=new t.View(e,i,n),s.bind(),s},init:function(e,i,n){var s,r,o;if(null==n&&(n={}),null==i&&(i=document.createElement("div")),e=t["public"].components[e],r=e.template.call(this,i),r instanceof HTMLElement){for(;i.firstChild;)i.removeChild(i.firstChild);i.appendChild(r)}else i.innerHTML=r;return s=e.initialize.call(this,i,n),o=new t.View(i,s),o.bind(),o}}},window.jQuery||window.$?(n="on"in jQuery.prototype?["on","off"]:["bind","unbind"],e=n[0],i=n[1],t.Util={bindEvent:function(t,i,n){return jQuery(t)[e](i,n)},unbindEvent:function(t,e,n){return jQuery(t)[i](e,n)},getInputValue:function(t){var e;return e=jQuery(t),"checkbox"===e.attr("type")?e.is(":checked"):e.val()}}):t.Util={bindEvent:function(){return"addEventListener"in window?function(t,e,i){return t.addEventListener(e,i,!1)}:function(t,e,i){return t.attachEvent("on"+e,i)}}(),unbindEvent:function(){return"removeEventListener"in window?function(t,e,i){return t.removeEventListener(e,i,!1)}:function(t,e,i){return t.detachEvent("on"+e,i)}}(),getInputValue:function(t){var e,i,n,s;if("checkbox"===t.type)return t.checked;if("select-multiple"===t.type){for(s=[],i=0,n=t.length;n>i;i++)e=t[i],e.selected&&s.push(e.value);return s}return t.value}},t.TypeParser=function(){function t(){}return t.types={primitive:0,keypath:1},t.parse=function(t){return/^'.*'$|^".*"$/.test(t)?{type:this.types.primitive,value:t.slice(1,-1)}:"true"===t?{type:this.types.primitive,value:!0}:"false"===t?{type:this.types.primitive,value:!1}:"null"===t?{type:this.types.primitive,value:null}:"undefined"===t?{type:this.types.primitive,value:void 0}:""===t?{type:this.types.primitive,value:void 0}:isNaN(Number(t))===!1?{type:this.types.primitive,value:Number(t)}:{type:this.types.keypath,value:t}},t}(),t.TextTemplateParser=function(){function t(){}return t.types={text:0,binding:1},t.parse=function(t,e){var i,n,s,r,o,u,l;for(u=[],r=t.length,i=0,n=0;r>n;){if(i=t.indexOf(e[0],n),0>i){u.push({type:this.types.text,value:t.slice(n)});break}if(i>0&&i>n&&u.push({type:this.types.text,value:t.slice(n,i)}),n=i+e[0].length,i=t.indexOf(e[1],n),0>i){o=t.slice(n-e[1].length),s=u[u.length-1],(null!=s?s.type:void 0)===this.types.text?s.value+=o:u.push({type:this.types.text,value:o});break}l=t.slice(n,i).trim(),u.push({type:this.types.binding,value:l}),n=i+e[1].length}return u},t}(),t.View=function(){function e(e,i,n){var r,o,u,l,h,a,p,d,c,f,b,v,y;for(this.els=e,this.models=i,null==n&&(n={}),this.update=s(this.update,this),this.publish=s(this.publish,this),this.sync=s(this.sync,this),this.unbind=s(this.unbind,this),this.bind=s(this.bind,this),this.select=s(this.select,this),this.traverse=s(this.traverse,this),this.build=s(this.build,this),this.buildBinding=s(this.buildBinding,this),this.bindingRegExp=s(this.bindingRegExp,this),this.options=s(this.options,this),this.els.jquery||this.els instanceof Array||(this.els=[this.els]),c=t.extensions,h=0,p=c.length;p>h;h++){if(o=c[h],this[o]={},n[o]){f=n[o];for(r in f)u=f[r],this[o][r]=u}b=t["public"][o];for(r in b)u=b[r],null==(l=this[o])[r]&&(l[r]=u)}for(v=t.options,a=0,d=v.length;d>a;a++)o=v[a],this[o]=null!=(y=n[o])?y:t["public"][o];this.build()}return e.prototype.options=function(){var e,i,n,s,r;for(i={},r=t.extensions.concat(t.options),n=0,s=r.length;s>n;n++)e=r[n],i[e]=this[e];return i},e.prototype.bindingRegExp=function(){return new RegExp("^"+this.prefix+"-")},e.prototype.buildBinding=function(e,i,n,s){var r,o,u,l,h,a,p;return h={},p=function(){var t,e,i,n;for(i=s.match(/((?:'[^']*')*(?:(?:[^\|']*(?:'[^']*')+[^\|']*)+|[^\|]+))|^$/g),n=[],t=0,e=i.length;e>t;t++)a=i[t],n.push(a.trim());return n}(),r=function(){var t,e,i,n;for(i=p.shift().split("<"),n=[],t=0,e=i.length;e>t;t++)o=i[t],n.push(o.trim());return n}(),l=r.shift(),h.formatters=p,(u=r.shift())&&(h.dependencies=u.split(/\s+/)),this.bindings.push(new t[e](this,i,n,l,h))},e.prototype.build=function(){var e,i,n,s,r;for(this.bindings=[],i=function(e){return function(n){var s,r,o,u,l,h,a,p,d,c,f,b,v;if(3===n.nodeType){if(l=t.TextTemplateParser,(o=e.templateDelimiters)&&(p=l.parse(n.data,o)).length&&(1!==p.length||p[0].type!==l.types.text)){for(d=0,f=p.length;f>d;d++)a=p[d],h=document.createTextNode(a.value),n.parentNode.insertBefore(h,n),1===a.type&&e.buildBinding("TextBinding",h,null,a.value);n.parentNode.removeChild(n)}}else 1===n.nodeType&&(s=e.traverse(n));if(!s)for(v=function(){var t,e,i,s;for(i=n.childNodes,s=[],t=0,e=i.length;e>t;t++)u=i[t],s.push(u);return s}(),c=0,b=v.length;b>c;c++)r=v[c],i(r)}}(this),r=this.els,n=0,s=r.length;s>n;n++)e=r[n],i(e);this.bindings.sort(function(t,e){var i,n;return((null!=(i=e.binder)?i.priority:void 0)||0)-((null!=(n=t.binder)?n.priority:void 0)||0)})},e.prototype.traverse=function(e){var i,n,s,r,o,u,l,h,a,p,d,c,f,b,v,y;for(r=this.bindingRegExp(),o="SCRIPT"===e.nodeName||"STYLE"===e.nodeName,b=e.attributes,p=0,c=b.length;c>p;p++)if(i=b[p],r.test(i.name)){if(h=i.name.replace(r,""),!(s=this.binders[h])){v=this.binders;for(u in v)a=v[u],"*"!==u&&-1!==u.indexOf("*")&&(l=new RegExp("^"+u.replace(/\*/g,".+")+"$"),l.test(h)&&(s=a))}s||(s=this.binders["*"]),s.block&&(o=!0,n=[i])}for(y=n||e.attributes,d=0,f=y.length;f>d;d++)i=y[d],r.test(i.name)&&(h=i.name.replace(r,""),this.buildBinding("Binding",e,h,i.value));return o||(h=e.nodeName.toLowerCase(),this.components[h]&&!e._bound&&(this.bindings.push(new t.ComponentBinding(this,e,h)),o=!0)),o},e.prototype.select=function(t){var e,i,n,s,r;for(s=this.bindings,r=[],i=0,n=s.length;n>i;i++)e=s[i],t(e)&&r.push(e);return r},e.prototype.bind=function(){var t,e,i,n;for(n=this.bindings,e=0,i=n.length;i>e;e++)t=n[e],t.bind()},e.prototype.unbind=function(){var t,e,i,n;for(n=this.bindings,e=0,i=n.length;i>e;e++)t=n[e],t.unbind()},e.prototype.sync=function(){var t,e,i,n;for(n=this.bindings,e=0,i=n.length;i>e;e++)t=n[e],"function"==typeof t.sync&&t.sync()},e.prototype.publish=function(){var t,e,i,n;for(n=this.select(function(t){var e;return null!=(e=t.binder)?e.publishes:void 0}),e=0,i=n.length;i>e;e++)t=n[e],t.publish()},e.prototype.update=function(t){var e,i,n,s,r,o;null==t&&(t={});for(i in t)n=t[i],this.models[i]=n;for(o=this.bindings,s=0,r=o.length;r>s;s++)e=o[s],"function"==typeof e.update&&e.update(t)},e}(),t.Binding=function(){function e(t,e,i,n,r){this.view=t,this.el=e,this.type=i,this.keypath=n,this.options=null!=r?r:{},this.getValue=s(this.getValue,this),this.update=s(this.update,this),this.unbind=s(this.unbind,this),this.bind=s(this.bind,this),this.publish=s(this.publish,this),this.sync=s(this.sync,this),this.set=s(this.set,this),this.eventHandler=s(this.eventHandler,this),this.formattedValue=s(this.formattedValue,this),this.parseTarget=s(this.parseTarget,this),this.observe=s(this.observe,this),this.setBinder=s(this.setBinder,this),this.formatters=this.options.formatters||[],this.dependencies=[],this.formatterObservers={},this.model=void 0,this.setBinder()}return e.prototype.setBinder=function(){var t,e,i,n;if(!(this.binder=this.view.binders[this.type])){n=this.view.binders;for(t in n)i=n[t],"*"!==t&&-1!==t.indexOf("*")&&(e=new RegExp("^"+t.replace(/\*/g,".+")+"$"),e.test(this.type)&&(this.binder=i,this.args=new RegExp("^"+t.replace(/\*/g,"(.+)")+"$").exec(this.type),this.args.shift()))}return this.binder||(this.binder=this.view.binders["*"]),this.binder instanceof Function?this.binder={routine:this.binder}:void 0},e.prototype.observe=function(e,i,n){return t.sightglass(e,i,n,{root:this.view.rootInterface,adapters:this.view.adapters})},e.prototype.parseTarget=function(){var e;return e=t.TypeParser.parse(this.keypath),0===e.type?this.value=e.value:(this.observer=this.observe(this.view.models,this.keypath,this.sync),this.model=this.observer.target)},e.prototype.formattedValue=function(e){var i,n,s,o,u,l,h,a,p,d,c,f,b,v,y;for(v=this.formatters,o=d=0,f=v.length;f>d;o=++d){for(u=v[o],s=u.match(/[^\s']+|'([^']|'[^\s])*'|"([^"]|"[^\s])*"/g),l=s.shift(),u=this.view.formatters[l],s=function(){var e,i,r;for(r=[],e=0,i=s.length;i>e;e++)n=s[e],r.push(t.TypeParser.parse(n));return r}(),a=[],i=c=0,b=s.length;b>c;i=++c)n=s[i],a.push(0===n.type?n.value:((p=this.formatterObservers)[o]||(p[o]={}),(h=this.formatterObservers[o][i])?void 0:(h=this.observe(this.view.models,n.value,this.sync),this.formatterObservers[o][i]=h),h.value()));(null!=u?u.read:void 0)instanceof Function?e=(y=u.read).call.apply(y,[this.model,e].concat(r.call(a))):u instanceof Function&&(e=u.call.apply(u,[this.model,e].concat(r.call(a))))}return e},e.prototype.eventHandler=function(t){var e,i;return i=(e=this).view.handler,function(n){return i.call(t,this,n,e)}},e.prototype.set=function(e){var i;return e=e instanceof Function&&!this.binder["function"]&&t["public"].executeFunctions?this.formattedValue(e.call(this.model)):this.formattedValue(e),null!=(i=this.binder.routine)?i.call(this,this.el,e):void 0},e.prototype.sync=function(){var t,e;return this.set(function(){var i,n,s,r,o,u,l;if(this.observer){if(this.model!==this.observer.target){for(o=this.dependencies,i=0,s=o.length;s>i;i++)e=o[i],e.unobserve();if(this.dependencies=[],null!=(this.model=this.observer.target)&&(null!=(u=this.options.dependencies)?u.length:void 0))for(l=this.options.dependencies,n=0,r=l.length;r>n;n++)t=l[n],e=this.observe(this.model,t,this.sync),this.dependencies.push(e)}return this.observer.value()}return this.value}.call(this))},e.prototype.publish=function(){var t,e,i,n,s,o,u,l,h;if(this.observer){for(n=this.getValue(this.el),u=this.formatters.slice(0).reverse(),s=0,o=u.length;o>s;s++)e=u[s],t=e.split(/\s+/),i=t.shift(),(null!=(l=this.view.formatters[i])?l.publish:void 0)&&(n=(h=this.view.formatters[i]).publish.apply(h,[n].concat(r.call(t))));return this.observer.setValue(n)}},e.prototype.bind=function(){var t,e,i,n,s,r,o;if(this.parseTarget(),null!=(s=this.binder.bind)&&s.call(this,this.el),null!=this.model&&(null!=(r=this.options.dependencies)?r.length:void 0))for(o=this.options.dependencies,i=0,n=o.length;n>i;i++)t=o[i],e=this.observe(this.model,t,this.sync),this.dependencies.push(e);return this.view.preloadData?this.sync():void 0},e.prototype.unbind=function(){var t,e,i,n,s,r,o,u,l,h;for(null!=(o=this.binder.unbind)&&o.call(this,this.el),null!=(u=this.observer)&&u.unobserve(),l=this.dependencies,s=0,r=l.length;r>s;s++)n=l[s],n.unobserve();this.dependencies=[],h=this.formatterObservers;for(i in h){e=h[i];for(t in e)n=e[t],n.unobserve()}return this.formatterObservers={}},e.prototype.update=function(t){var e,i;return null==t&&(t={}),this.model=null!=(e=this.observer)?e.target:void 0,null!=(i=this.binder.update)?i.call(this,t):void 0},e.prototype.getValue=function(e){return this.binder&&null!=this.binder.getValue?this.binder.getValue.call(this,e):t.Util.getInputValue(e)},e}(),t.ComponentBinding=function(e){function i(e,i,n){var r,o,u,h,a,p,d,c;for(this.view=e,this.el=i,this.type=n,this.unbind=s(this.unbind,this),this.bind=s(this.bind,this),this.locals=s(this.locals,this),this.component=this.view.components[this.type],this["static"]={},this.observers={},this.upstreamObservers={},o=e.bindingRegExp(),d=this.el.attributes||[],a=0,p=d.length;p>a;a++)r=d[a],o.test(r.name)||(u=this.camelCase(r.name),h=t.TypeParser.parse(r.value),l.call(null!=(c=this.component["static"])?c:[],u)>=0?this["static"][u]=r.value:0===h.type?this["static"][u]=h.value:this.observers[u]=r.value)}return u(i,e),i.prototype.sync=function(){},i.prototype.update=function(){},i.prototype.publish=function(){},i.prototype.locals=function(){var t,e,i,n,s,r;i={},s=this["static"];for(t in s)n=s[t],i[t]=n;r=this.observers;for(t in r)e=r[t],i[t]=e.value();return i},i.prototype.camelCase=function(t){return t.replace(/-([a-z])/g,function(t){return t[1].toUpperCase()})},i.prototype.bind=function(){var e,i,n,s,r,o,u,l,h,a,p,d,c,f,b,v,y,m,g,w;if(!this.bound){f=this.observers;for(i in f)n=f[i],this.observers[i]=this.observe(this.view.models,n,function(t){return function(e){return function(){return t.componentView.models[e]=t.observers[e].value()}}}(this).call(this,i));this.bound=!0}if(null!=this.componentView)this.componentView.bind();else{for(this.el.innerHTML=this.component.template.call(this),u=this.component.initialize.call(this,this.el,this.locals()),this.el._bound=!0,o={},b=t.extensions,a=0,d=b.length;d>a;a++){if(r=b[a],o[r]={},this.component[r]){v=this.component[r];for(e in v)l=v[e],o[r][e]=l}y=this.view[r];for(e in y)l=y[e],null==(h=o[r])[e]&&(h[e]=l)}for(m=t.options,p=0,c=m.length;c>p;p++)r=m[p],o[r]=null!=(g=this.component[r])?g:this.view[r];this.componentView=new t.View(Array.prototype.slice.call(this.el.childNodes),u,o),this.componentView.bind(),w=this.observers;for(i in w)s=w[i],this.upstreamObservers[i]=this.observe(this.componentView.models,i,function(t){return function(e,i){return function(){return i.setValue(t.componentView.models[e])}}}(this).call(this,i,s))}},i.prototype.unbind=function(){var t,e,i,n,s;i=this.upstreamObservers;for(t in i)e=i[t],e.unobserve();n=this.observers;for(t in n)e=n[t],e.unobserve();return null!=(s=this.componentView)?s.unbind.call(this):void 0},i}(t.Binding),t.TextBinding=function(t){function e(t,e,i,n,r){this.view=t,this.el=e,this.type=i,this.keypath=n,this.options=null!=r?r:{},this.sync=s(this.sync,this),this.formatters=this.options.formatters||[],this.dependencies=[],this.formatterObservers={}}return u(e,t),e.prototype.binder={routine:function(t,e){return t.data=null!=e?e:""}},e.prototype.sync=function(){return e.__super__.sync.apply(this,arguments)},e}(t.Binding),t["public"].binders.text=function(t,e){return null!=t.textContent?t.textContent=null!=e?e:"":t.innerText=null!=e?e:""},t["public"].binders.html=function(t,e){return t.innerHTML=null!=e?e:""},t["public"].binders.show=function(t,e){return t.style.display=e?"":"none"},t["public"].binders.hide=function(t,e){return t.style.display=e?"none":""},t["public"].binders.enabled=function(t,e){return t.disabled=!e},t["public"].binders.disabled=function(t,e){return t.disabled=!!e},t["public"].binders.checked={publishes:!0,priority:2e3,bind:function(e){return t.Util.bindEvent(e,"change",this.publish)},unbind:function(e){return t.Util.unbindEvent(e,"change",this.publish)},routine:function(t,e){var i;return t.checked="radio"===t.type?(null!=(i=t.value)?i.toString():void 0)===(null!=e?e.toString():void 0):!!e}},t["public"].binders.unchecked={publishes:!0,priority:2e3,bind:function(e){return t.Util.bindEvent(e,"change",this.publish)},unbind:function(e){return t.Util.unbindEvent(e,"change",this.publish)},routine:function(t,e){var i;return t.checked="radio"===t.type?(null!=(i=t.value)?i.toString():void 0)!==(null!=e?e.toString():void 0):!e}},t["public"].binders.value={publishes:!0,priority:3e3,bind:function(e){return"INPUT"!==e.tagName||"radio"!==e.type?(this.event="SELECT"===e.tagName?"change":"input",t.Util.bindEvent(e,this.event,this.publish)):void 0},unbind:function(e){return"INPUT"!==e.tagName||"radio"!==e.type?t.Util.unbindEvent(e,this.event,this.publish):void 0},routine:function(t,e){var i,n,s,r,o,u,h;if("INPUT"===t.tagName&&"radio"===t.type)return t.setAttribute("value",e);if(null!=window.jQuery){if(t=jQuery(t),(null!=e?e.toString():void 0)!==(null!=(r=t.val())?r.toString():void 0))return t.val(null!=e?e:"")}else if("select-multiple"===t.type){if(null!=e){for(h=[],n=0,s=t.length;s>n;n++)i=t[n],h.push(i.selected=(o=i.value,l.call(e,o)>=0));return h}}else if((null!=e?e.toString():void 0)!==(null!=(u=t.value)?u.toString():void 0))return t.value=null!=e?e:""}},t["public"].binders["if"]={block:!0,priority:4e3,bind:function(t){var e,i;return null==this.marker?(e=[this.view.prefix,this.type].join("-").replace("--","-"),i=t.getAttribute(e),this.marker=document.createComment(" rivets: "+this.type+" "+i+" "),this.bound=!1,t.removeAttribute(e),t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t)):void 0},unbind:function(){return this.nested?(this.nested.unbind(),this.bound=!1):void 0},routine:function(e,i){var n,s,r,o;if(!!i==!this.bound){if(i){r={},o=this.view.models;for(n in o)s=o[n],r[n]=s;return(this.nested||(this.nested=new t.View(e,r,this.view.options()))).bind(),this.marker.parentNode.insertBefore(e,this.marker.nextSibling),this.bound=!0}return e.parentNode.removeChild(e),this.nested.unbind(),this.bound=!1}},update:function(t){var e;return null!=(e=this.nested)?e.update(t):void 0}},t["public"].binders.unless={block:!0,priority:4e3,bind:function(e){return t["public"].binders["if"].bind.call(this,e)},unbind:function(){return t["public"].binders["if"].unbind.call(this)},routine:function(e,i){return t["public"].binders["if"].routine.call(this,e,!i)},update:function(e){return t["public"].binders["if"].update.call(this,e)}},t["public"].binders["on-*"]={"function":!0,priority:1e3,unbind:function(e){return this.handler?t.Util.unbindEvent(e,this.args[0],this.handler):void 0},routine:function(e,i){return this.handler&&t.Util.unbindEvent(e,this.args[0],this.handler),t.Util.bindEvent(e,this.args[0],this.handler=this.eventHandler(i))}},t["public"].binders["each-*"]={block:!0,priority:4e3,bind:function(t){var e,i,n,s,r;if(null==this.marker)e=[this.view.prefix,this.type].join("-").replace("--","-"),this.marker=document.createComment(" rivets: "+this.type+" "),this.iterated=[],t.removeAttribute(e),t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t);else for(r=this.iterated,n=0,s=r.length;s>n;n++)i=r[n],i.bind()},unbind:function(){var t,e,i,n;if(null!=this.iterated)for(n=this.iterated,e=0,i=n.length;i>e;e++)t=n[e],t.unbind()},routine:function(e,i){var n,s,r,o,u,l,h,a,p,d,c,f,b,v,y,m,g,w,k,x;if(h=this.args[0],i=i||[],this.iterated.length>i.length)for(w=Array(this.iterated.length-i.length),f=0,y=w.length;y>f;f++)r=w[f],c=this.iterated.pop(),c.unbind(),this.marker.parentNode.removeChild(c.els[0]);for(o=b=0,m=i.length;m>b;o=++b)if(l=i[o],s={index:o},s[t["public"].iterationAlias(h)]=o,s[h]=l,null==this.iterated[o]){k=this.view.models;for(u in k)l=k[u],null==s[u]&&(s[u]=l);p=this.iterated.length?this.iterated[this.iterated.length-1].els[0]:this.marker,a=this.view.options(),a.preloadData=!0,d=e.cloneNode(!0),c=new t.View(d,s,a),c.bind(),this.iterated.push(c),this.marker.parentNode.insertBefore(d,p.nextSibling)}else this.iterated[o].models[h]!==l&&this.iterated[o].update(s);if("OPTION"===e.nodeName)for(x=this.view.bindings,v=0,g=x.length;g>v;v++)n=x[v],n.el===this.marker.parentNode&&"value"===n.type&&n.sync()},update:function(t){var e,i,n,s,r,o,u;e={};for(i in t)n=t[i],i!==this.args[0]&&(e[i]=n);for(u=this.iterated,r=0,o=u.length;o>r;r++)s=u[r],s.update(e)}},t["public"].binders["class-*"]=function(t,e){var i;return i=" "+t.className+" ",!e==(-1!==i.indexOf(" "+this.args[0]+" "))?t.className=e?""+t.className+" "+this.args[0]:i.replace(" "+this.args[0]+" "," ").trim():void 0},t["public"].binders["*"]=function(t,e){return null!=e?t.setAttribute(this.type,e):t.removeAttribute(this.type)},t["public"].formatters.call=function(){var t,e;return e=arguments[0],t=2<=arguments.length?r.call(arguments,1):[],e.call.apply(e,[this].concat(r.call(t)))},t["public"].adapters["."]={id:"_rv",counter:0,weakmap:{},weakReference:function(t){var e,i,n;return t.hasOwnProperty(this.id)||(e=this.counter++,Object.defineProperty(t,this.id,{value:e})),(i=this.weakmap)[n=t[this.id]]||(i[n]={callbacks:{}})},cleanupWeakReference:function(t,e){return Object.keys(t.callbacks).length||t.pointers&&Object.keys(t.pointers).length?void 0:delete this.weakmap[e]},stubFunction:function(t,e){var i,n,s;return n=t[e],i=this.weakReference(t),s=this.weakmap,t[e]=function(){var e,r,o,u,l,h,a,p,d,c;u=n.apply(t,arguments),a=i.pointers;for(o in a)for(r=a[o],c=null!=(p=null!=(d=s[o])?d.callbacks[r]:void 0)?p:[],l=0,h=c.length;h>l;l++)e=c[l],e();return u}},observeMutations:function(t,e,i){var n,s,r,o,u,h;if(Array.isArray(t)){if(r=this.weakReference(t),null==r.pointers)for(r.pointers={},s=["push","pop","shift","unshift","sort","reverse","splice"],u=0,h=s.length;h>u;u++)n=s[u],this.stubFunction(t,n);if(null==(o=r.pointers)[e]&&(o[e]=[]),l.call(r.pointers[e],i)<0)return r.pointers[e].push(i)}},unobserveMutations:function(t,e,i){var n,s,r;return Array.isArray(t)&&null!=t[this.id]&&(s=this.weakmap[t[this.id]])&&(r=s.pointers[e])?((n=r.indexOf(i))>=0&&r.splice(n,1),r.length||delete s.pointers[e],this.cleanupWeakReference(s,t[this.id])):void 0},observe:function(t,e,i){var n,s,r;return n=this.weakReference(t).callbacks,null==n[e]&&(n[e]=[],s=Object.getOwnPropertyDescriptor(t,e),(null!=s?s.get:void 0)||(null!=s?s.set:void 0)||(r=t[e],Object.defineProperty(t,e,{enumerable:!0,get:function(){return r},set:function(i){return function(s){var o,u,l,h,a;if(s!==r&&(i.unobserveMutations(r,t[i.id],e),r=s,u=i.weakmap[t[i.id]])){if(n=u.callbacks,n[e])for(a=n[e],l=0,h=a.length;h>l;l++)o=a[l],o();return i.observeMutations(s,t[i.id],e)}}}(this)}))),l.call(n[e],i)<0&&n[e].push(i),this.observeMutations(t[e],t[this.id],e)},unobserve:function(t,e,i){var n,s,r;return(r=this.weakmap[t[this.id]])&&(n=r.callbacks[e])?((s=n.indexOf(i))>=0&&(n.splice(s,1),n.length||delete r.callbacks[e]),this.unobserveMutations(t[e],t[this.id],e),this.cleanupWeakReference(r,t[this.id])):void 0},get:function(t,e){return t[e]},set:function(t,e,i){return t[e]=i}},t.factory=function(e){return t.sightglass=e,t["public"]._=t,t["public"]},"object"==typeof("undefined"!=typeof module&&null!==module?module.exports:void 0)?module.exports=t.factory(require("sightglass")):"function"==typeof define&&define.amd?define(["sightglass"],function(e){return this.rivets=t.factory(e)}):this.rivets=t.factory(sightglass)}).call(this); \ No newline at end of file +(function(){var t,e,i,n,r=function(t,e){return function(){return t.apply(e,arguments)}},s=[].slice,o={}.hasOwnProperty,u=function(t,e){function i(){this.constructor=t}for(var n in e)o.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},l=[].indexOf||function(t){for(var e=0,i=this.length;i>e;e++)if(e in this&&this[e]===t)return e;return-1};t={options:["prefix","templateDelimiters","rootInterface","preloadData","handler","executeFunctions"],extensions:["binders","formatters","components","adapters"],"public":{binders:{},components:{},formatters:{},adapters:{},prefix:"rv",templateDelimiters:["{","}"],rootInterface:".",preloadData:!0,executeFunctions:!1,iterationAlias:function(t){return"%"+t+"%"},handler:function(t,e,i){return this.call(t,e,i.view.models)},configure:function(e){var i,n,r,s;null==e&&(e={});for(r in e)if(s=e[r],"binders"===r||"components"===r||"formatters"===r||"adapters"===r)for(n in s)i=s[n],t[r][n]=i;else t["public"][r]=s},bind:function(e,i,n){var r;return null==i&&(i={}),null==n&&(n={}),r=new t.View(e,i,n),r.bind(),r},init:function(e,i,n){var r,s,o;if(null==n&&(n={}),null==i&&(i=document.createElement("div")),e=t["public"].components[e],s=e.template.call(this,i),s instanceof HTMLElement){for(;i.firstChild;)i.removeChild(i.firstChild);i.appendChild(s)}else i.innerHTML=s;return r=e.initialize.call(this,i,n),o=new t.View(i,r),o.bind(),o}}},window.jQuery||window.$?(n="on"in jQuery.prototype?["on","off"]:["bind","unbind"],e=n[0],i=n[1],t.Util={bindEvent:function(t,i,n){return jQuery(t)[e](i,n)},unbindEvent:function(t,e,n){return jQuery(t)[i](e,n)},getInputValue:function(t){var e;return e=jQuery(t),"checkbox"===e.attr("type")?e.is(":checked"):e.val()}}):t.Util={bindEvent:function(){return"addEventListener"in window?function(t,e,i){return t.addEventListener(e,i,!1)}:function(t,e,i){return t.attachEvent("on"+e,i)}}(),unbindEvent:function(){return"removeEventListener"in window?function(t,e,i){return t.removeEventListener(e,i,!1)}:function(t,e,i){return t.detachEvent("on"+e,i)}}(),getInputValue:function(t){var e,i,n,r;if("checkbox"===t.type)return t.checked;if("select-multiple"===t.type){for(r=[],i=0,n=t.length;n>i;i++)e=t[i],e.selected&&r.push(e.value);return r}return t.value}},t.TypeParser=function(){function t(){}return t.types={primitive:0,keypath:1},t.parse=function(t){return/^'.*'$|^".*"$/.test(t)?{type:this.types.primitive,value:t.slice(1,-1)}:"true"===t?{type:this.types.primitive,value:!0}:"false"===t?{type:this.types.primitive,value:!1}:"null"===t?{type:this.types.primitive,value:null}:"undefined"===t?{type:this.types.primitive,value:void 0}:""===t?{type:this.types.primitive,value:void 0}:isNaN(Number(t))===!1?{type:this.types.primitive,value:Number(t)}:{type:this.types.keypath,value:t}},t}(),t.TextTemplateParser=function(){function t(){}return t.types={text:0,binding:1},t.parse=function(t,e){var i,n,r,s,o,u,l;for(u=[],s=t.length,i=0,n=0;s>n;){if(i=t.indexOf(e[0],n),0>i){u.push({type:this.types.text,value:t.slice(n)});break}if(i>0&&i>n&&u.push({type:this.types.text,value:t.slice(n,i)}),n=i+e[0].length,i=t.indexOf(e[1],n),0>i){o=t.slice(n-e[1].length),r=u[u.length-1],(null!=r?r.type:void 0)===this.types.text?r.value+=o:u.push({type:this.types.text,value:o});break}l=t.slice(n,i).trim(),u.push({type:this.types.binding,value:l}),n=i+e[1].length}return u},t}(),t.View=function(){function e(e,i,n){var s,o,u,l,h,a,p,d,c,f,b,v,m;for(this.els=e,this.models=i,null==n&&(n={}),this.update=r(this.update,this),this.publish=r(this.publish,this),this.sync=r(this.sync,this),this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.select=r(this.select,this),this.traverse=r(this.traverse,this),this.build=r(this.build,this),this.buildBinding=r(this.buildBinding,this),this.bindingRegExp=r(this.bindingRegExp,this),this.options=r(this.options,this),this.els.jquery||this.els instanceof Array||(this.els=[this.els]),c=t.extensions,h=0,p=c.length;p>h;h++){if(o=c[h],this[o]={},n[o]){f=n[o];for(s in f)u=f[s],this[o][s]=u}b=t["public"][o];for(s in b)u=b[s],null==(l=this[o])[s]&&(l[s]=u)}for(v=t.options,a=0,d=v.length;d>a;a++)o=v[a],this[o]=null!=(m=n[o])?m:t["public"][o];this.build()}return e.prototype.options=function(){var e,i,n,r,s;for(i={},s=t.extensions.concat(t.options),n=0,r=s.length;r>n;n++)e=s[n],i[e]=this[e];return i},e.prototype.bindingRegExp=function(){return new RegExp("^"+this.prefix+"-")},e.prototype.buildBinding=function(e,i,n,r){var s,o,u,l,h,a,p;return h={},p=function(){var t,e,i,n;for(i=r.match(/((?:'[^']*')*(?:(?:[^\|']*(?:'[^']*')+[^\|']*)+|[^\|]+))|^$/g),n=[],t=0,e=i.length;e>t;t++)a=i[t],n.push(a.trim());return n}(),s=function(){var t,e,i,n;for(i=p.shift().split("<"),n=[],t=0,e=i.length;e>t;t++)o=i[t],n.push(o.trim());return n}(),l=s.shift(),h.formatters=p,(u=s.shift())&&(h.dependencies=u.split(/\s+/)),this.bindings.push(new t[e](this,i,n,l,h))},e.prototype.build=function(){var e,i,n,r,s;for(this.bindings=[],i=function(e){return function(n){var r,s,o,u,l,h,a,p,d,c,f,b,v;if(3===n.nodeType){if(l=t.TextTemplateParser,(o=e.templateDelimiters)&&(p=l.parse(n.data,o)).length&&(1!==p.length||p[0].type!==l.types.text)){for(d=0,f=p.length;f>d;d++)a=p[d],h=document.createTextNode(a.value),n.parentNode.insertBefore(h,n),1===a.type&&e.buildBinding("TextBinding",h,null,a.value);n.parentNode.removeChild(n)}}else 1===n.nodeType&&(r=e.traverse(n));if(!r)for(v=function(){var t,e,i,r;for(i=n.childNodes,r=[],t=0,e=i.length;e>t;t++)u=i[t],r.push(u);return r}(),c=0,b=v.length;b>c;c++)s=v[c],i(s)}}(this),s=this.els,n=0,r=s.length;r>n;n++)e=s[n],i(e);this.bindings.sort(function(t,e){var i,n;return((null!=(i=e.binder)?i.priority:void 0)||0)-((null!=(n=t.binder)?n.priority:void 0)||0)})},e.prototype.traverse=function(e){var i,n,r,s,o,u,l,h,a,p,d,c,f,b,v,m;for(s=this.bindingRegExp(),o="SCRIPT"===e.nodeName||"STYLE"===e.nodeName,b=e.attributes,p=0,c=b.length;c>p;p++)if(i=b[p],s.test(i.name)){if(h=i.name.replace(s,""),!(r=this.binders[h])){v=this.binders;for(u in v)a=v[u],"*"!==u&&-1!==u.indexOf("*")&&(l=new RegExp("^"+u.replace(/\*/g,".+")+"$"),l.test(h)&&(r=a))}r||(r=this.binders["*"]),r.block&&(o=!0,n=[i])}for(m=n||e.attributes,d=0,f=m.length;f>d;d++)i=m[d],s.test(i.name)&&(h=i.name.replace(s,""),this.buildBinding("Binding",e,h,i.value));return o||(h=e.nodeName.toLowerCase(),this.components[h]&&!e._bound&&(this.bindings.push(new t.ComponentBinding(this,e,h)),o=!0)),o},e.prototype.select=function(t){var e,i,n,r,s;for(r=this.bindings,s=[],i=0,n=r.length;n>i;i++)e=r[i],t(e)&&s.push(e);return s},e.prototype.bind=function(){var t,e,i,n;for(n=this.bindings,e=0,i=n.length;i>e;e++)t=n[e],t.bind()},e.prototype.unbind=function(){var t,e,i,n;for(n=this.bindings,e=0,i=n.length;i>e;e++)t=n[e],t.unbind()},e.prototype.sync=function(){var t,e,i,n;for(n=this.bindings,e=0,i=n.length;i>e;e++)t=n[e],"function"==typeof t.sync&&t.sync()},e.prototype.publish=function(){var t,e,i,n;for(n=this.select(function(t){var e;return null!=(e=t.binder)?e.publishes:void 0}),e=0,i=n.length;i>e;e++)t=n[e],t.publish()},e.prototype.update=function(t){var e,i,n,r,s,o;null==t&&(t={});for(i in t)n=t[i],this.models[i]=n;for(o=this.bindings,r=0,s=o.length;s>r;r++)e=o[r],"function"==typeof e.update&&e.update(t)},e}(),t.Binding=function(){function e(t,e,i,n,s){this.view=t,this.el=e,this.type=i,this.keypath=n,this.options=null!=s?s:{},this.getValue=r(this.getValue,this),this.update=r(this.update,this),this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.publish=r(this.publish,this),this.sync=r(this.sync,this),this.set=r(this.set,this),this.eventHandler=r(this.eventHandler,this),this.formattedValue=r(this.formattedValue,this),this.parseFormatterArguments=r(this.parseFormatterArguments,this),this.parseTarget=r(this.parseTarget,this),this.observe=r(this.observe,this),this.setBinder=r(this.setBinder,this),this.formatters=this.options.formatters||[],this.dependencies=[],this.formatterObservers={},this.model=void 0,this.setBinder()}return e.prototype.setBinder=function(){var t,e,i,n;if(!(this.binder=this.view.binders[this.type])){n=this.view.binders;for(t in n)i=n[t],"*"!==t&&-1!==t.indexOf("*")&&(e=new RegExp("^"+t.replace(/\*/g,".+")+"$"),e.test(this.type)&&(this.binder=i,this.args=new RegExp("^"+t.replace(/\*/g,"(.+)")+"$").exec(this.type),this.args.shift()))}return this.binder||(this.binder=this.view.binders["*"]),this.binder instanceof Function?this.binder={routine:this.binder}:void 0},e.prototype.observe=function(e,i,n){return t.sightglass(e,i,n,{root:this.view.rootInterface,adapters:this.view.adapters})},e.prototype.parseTarget=function(){var e;return e=t.TypeParser.parse(this.keypath),e.type===t.TypeParser.types.primitive?this.value=e.value:(this.observer=this.observe(this.view.models,this.keypath,this.sync),this.model=this.observer.target)},e.prototype.parseFormatterArguments=function(e,i){var n,r,s,o,u,l,h;for(e=function(){var i,n,s;for(s=[],i=0,n=e.length;n>i;i++)r=e[i],s.push(t.TypeParser.parse(r));return s}(),o=[],n=l=0,h=e.length;h>l;n=++l)r=e[n],o.push(r.type===t.TypeParser.types.primitive?r.value:((u=this.formatterObservers)[i]||(u[i]={}),(s=this.formatterObservers[i][n])?void 0:(s=this.observe(this.view.models,r.value,this.sync),this.formatterObservers[i][n]=s),s.value()));return o},e.prototype.formattedValue=function(t){var e,i,n,r,o,u,l,h,a;for(h=this.formatters,i=u=0,l=h.length;l>u;i=++u)n=h[i],e=n.match(/[^\s']+|'([^']|'[^\s])*'|"([^"]|"[^\s])*"/g),r=e.shift(),n=this.view.formatters[r],o=this.parseFormatterArguments(e,i),(null!=n?n.read:void 0)instanceof Function?t=(a=n.read).call.apply(a,[this.model,t].concat(s.call(o))):n instanceof Function&&(t=n.call.apply(n,[this.model,t].concat(s.call(o))));return t},e.prototype.eventHandler=function(t){var e,i;return i=(e=this).view.handler,function(n){return i.call(t,this,n,e)}},e.prototype.set=function(e){var i;return e=e instanceof Function&&!this.binder["function"]&&t["public"].executeFunctions?this.formattedValue(e.call(this.model)):this.formattedValue(e),null!=(i=this.binder.routine)?i.call(this,this.el,e):void 0},e.prototype.sync=function(){var t,e;return this.set(function(){var i,n,r,s,o,u,l;if(this.observer){if(this.model!==this.observer.target){for(o=this.dependencies,i=0,r=o.length;r>i;i++)e=o[i],e.unobserve();if(this.dependencies=[],null!=(this.model=this.observer.target)&&(null!=(u=this.options.dependencies)?u.length:void 0))for(l=this.options.dependencies,n=0,s=l.length;s>n;n++)t=l[n],e=this.observe(this.model,t,this.sync),this.dependencies.push(e)}return this.observer.value()}return this.value}.call(this))},e.prototype.publish=function(){var t,e,i,n,r,o,u,l,h,a,p,d,c;if(this.observer){for(l=this.getValue(this.el),o=this.formatters.length-1,p=this.formatters.slice(0).reverse(),i=h=0,a=p.length;a>h;i=++h)n=p[i],e=o-i,t=n.split(/\s+/),r=t.shift(),u=this.parseFormatterArguments(t,e),(null!=(d=this.view.formatters[r])?d.publish:void 0)&&(l=(c=this.view.formatters[r]).publish.apply(c,[l].concat(s.call(u))));return this.observer.setValue(l)}},e.prototype.bind=function(){var t,e,i,n,r,s,o;if(this.parseTarget(),null!=(r=this.binder.bind)&&r.call(this,this.el),null!=this.model&&(null!=(s=this.options.dependencies)?s.length:void 0))for(o=this.options.dependencies,i=0,n=o.length;n>i;i++)t=o[i],e=this.observe(this.model,t,this.sync),this.dependencies.push(e);return this.view.preloadData?this.sync():void 0},e.prototype.unbind=function(){var t,e,i,n,r,s,o,u,l,h;for(null!=(o=this.binder.unbind)&&o.call(this,this.el),null!=(u=this.observer)&&u.unobserve(),l=this.dependencies,r=0,s=l.length;s>r;r++)n=l[r],n.unobserve();this.dependencies=[],h=this.formatterObservers;for(i in h){e=h[i];for(t in e)n=e[t],n.unobserve()}return this.formatterObservers={}},e.prototype.update=function(t){var e,i;return null==t&&(t={}),this.model=null!=(e=this.observer)?e.target:void 0,null!=(i=this.binder.update)?i.call(this,t):void 0},e.prototype.getValue=function(e){return this.binder&&null!=this.binder.getValue?this.binder.getValue.call(this,e):t.Util.getInputValue(e)},e}(),t.ComponentBinding=function(e){function i(e,i,n){var s,o,u,h,a,p,d,c;for(this.view=e,this.el=i,this.type=n,this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.locals=r(this.locals,this),this.component=this.view.components[this.type],this["static"]={},this.observers={},this.upstreamObservers={},o=e.bindingRegExp(),d=this.el.attributes||[],a=0,p=d.length;p>a;a++)s=d[a],o.test(s.name)||(u=this.camelCase(s.name),h=t.TypeParser.parse(s.value),l.call(null!=(c=this.component["static"])?c:[],u)>=0?this["static"][u]=s.value:h.type===t.TypeParser.types.primitive?this["static"][u]=h.value:this.observers[u]=s.value)}return u(i,e),i.prototype.sync=function(){},i.prototype.update=function(){},i.prototype.publish=function(){},i.prototype.locals=function(){var t,e,i,n,r,s;i={},r=this["static"];for(t in r)n=r[t],i[t]=n;s=this.observers;for(t in s)e=s[t],i[t]=e.value();return i},i.prototype.camelCase=function(t){return t.replace(/-([a-z])/g,function(t){return t[1].toUpperCase()})},i.prototype.bind=function(){var e,i,n,r,s,o,u,l,h,a,p,d,c,f,b,v,m,y,g,w;if(!this.bound){f=this.observers;for(i in f)n=f[i],this.observers[i]=this.observe(this.view.models,n,function(t){return function(e){return function(){return t.componentView.models[e]=t.observers[e].value()}}}(this).call(this,i));this.bound=!0}if(null!=this.componentView)this.componentView.bind();else{for(this.el.innerHTML=this.component.template.call(this),u=this.component.initialize.call(this,this.el,this.locals()),this.el._bound=!0,o={},b=t.extensions,a=0,d=b.length;d>a;a++){if(s=b[a],o[s]={},this.component[s]){v=this.component[s];for(e in v)l=v[e],o[s][e]=l}m=this.view[s];for(e in m)l=m[e],null==(h=o[s])[e]&&(h[e]=l)}for(y=t.options,p=0,c=y.length;c>p;p++)s=y[p],o[s]=null!=(g=this.component[s])?g:this.view[s];this.componentView=new t.View(Array.prototype.slice.call(this.el.childNodes),u,o),this.componentView.bind(),w=this.observers;for(i in w)r=w[i],this.upstreamObservers[i]=this.observe(this.componentView.models,i,function(t){return function(e,i){return function(){return i.setValue(t.componentView.models[e])}}}(this).call(this,i,r))}},i.prototype.unbind=function(){var t,e,i,n,r;i=this.upstreamObservers;for(t in i)e=i[t],e.unobserve();n=this.observers;for(t in n)e=n[t],e.unobserve();return null!=(r=this.componentView)?r.unbind.call(this):void 0},i}(t.Binding),t.TextBinding=function(t){function e(t,e,i,n,s){this.view=t,this.el=e,this.type=i,this.keypath=n,this.options=null!=s?s:{},this.sync=r(this.sync,this),this.formatters=this.options.formatters||[],this.dependencies=[],this.formatterObservers={}}return u(e,t),e.prototype.binder={routine:function(t,e){return t.data=null!=e?e:""}},e.prototype.sync=function(){return e.__super__.sync.apply(this,arguments)},e}(t.Binding),t["public"].binders.text=function(t,e){return null!=t.textContent?t.textContent=null!=e?e:"":t.innerText=null!=e?e:""},t["public"].binders.html=function(t,e){return t.innerHTML=null!=e?e:""},t["public"].binders.show=function(t,e){return t.style.display=e?"":"none"},t["public"].binders.hide=function(t,e){return t.style.display=e?"none":""},t["public"].binders.enabled=function(t,e){return t.disabled=!e},t["public"].binders.disabled=function(t,e){return t.disabled=!!e},t["public"].binders.checked={publishes:!0,priority:2e3,bind:function(e){return t.Util.bindEvent(e,"change",this.publish)},unbind:function(e){return t.Util.unbindEvent(e,"change",this.publish)},routine:function(t,e){var i;return t.checked="radio"===t.type?(null!=(i=t.value)?i.toString():void 0)===(null!=e?e.toString():void 0):!!e}},t["public"].binders.unchecked={publishes:!0,priority:2e3,bind:function(e){return t.Util.bindEvent(e,"change",this.publish)},unbind:function(e){return t.Util.unbindEvent(e,"change",this.publish)},routine:function(t,e){var i;return t.checked="radio"===t.type?(null!=(i=t.value)?i.toString():void 0)!==(null!=e?e.toString():void 0):!e}},t["public"].binders.value={publishes:!0,priority:3e3,bind:function(e){return"INPUT"!==e.tagName||"radio"!==e.type?(this.event="SELECT"===e.tagName?"change":"input",t.Util.bindEvent(e,this.event,this.publish)):void 0},unbind:function(e){return"INPUT"!==e.tagName||"radio"!==e.type?t.Util.unbindEvent(e,this.event,this.publish):void 0},routine:function(t,e){var i,n,r,s,o,u,h;if("INPUT"===t.tagName&&"radio"===t.type)return t.setAttribute("value",e);if(null!=window.jQuery){if(t=jQuery(t),(null!=e?e.toString():void 0)!==(null!=(s=t.val())?s.toString():void 0))return t.val(null!=e?e:"")}else if("select-multiple"===t.type){if(null!=e){for(h=[],n=0,r=t.length;r>n;n++)i=t[n],h.push(i.selected=(o=i.value,l.call(e,o)>=0));return h}}else if((null!=e?e.toString():void 0)!==(null!=(u=t.value)?u.toString():void 0))return t.value=null!=e?e:""}},t["public"].binders["if"]={block:!0,priority:4e3,bind:function(t){var e,i;return null==this.marker?(e=[this.view.prefix,this.type].join("-").replace("--","-"),i=t.getAttribute(e),this.marker=document.createComment(" rivets: "+this.type+" "+i+" "),this.bound=!1,t.removeAttribute(e),t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t)):void 0},unbind:function(){return this.nested?(this.nested.unbind(),this.bound=!1):void 0},routine:function(e,i){var n,r,s,o;if(!!i==!this.bound){if(i){s={},o=this.view.models;for(n in o)r=o[n],s[n]=r;return(this.nested||(this.nested=new t.View(e,s,this.view.options()))).bind(),this.marker.parentNode.insertBefore(e,this.marker.nextSibling),this.bound=!0}return e.parentNode.removeChild(e),this.nested.unbind(),this.bound=!1}},update:function(t){var e;return null!=(e=this.nested)?e.update(t):void 0}},t["public"].binders.unless={block:!0,priority:4e3,bind:function(e){return t["public"].binders["if"].bind.call(this,e)},unbind:function(){return t["public"].binders["if"].unbind.call(this)},routine:function(e,i){return t["public"].binders["if"].routine.call(this,e,!i)},update:function(e){return t["public"].binders["if"].update.call(this,e)}},t["public"].binders["on-*"]={"function":!0,priority:1e3,unbind:function(e){return this.handler?t.Util.unbindEvent(e,this.args[0],this.handler):void 0},routine:function(e,i){return this.handler&&t.Util.unbindEvent(e,this.args[0],this.handler),t.Util.bindEvent(e,this.args[0],this.handler=this.eventHandler(i))}},t["public"].binders["each-*"]={block:!0,priority:4e3,bind:function(t){var e,i,n,r,s;if(null==this.marker)e=[this.view.prefix,this.type].join("-").replace("--","-"),this.marker=document.createComment(" rivets: "+this.type+" "),this.iterated=[],t.removeAttribute(e),t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t);else for(s=this.iterated,n=0,r=s.length;r>n;n++)i=s[n],i.bind()},unbind:function(){var t,e,i,n;if(null!=this.iterated)for(n=this.iterated,e=0,i=n.length;i>e;e++)t=n[e],t.unbind()},routine:function(e,i){var n,r,s,o,u,l,h,a,p,d,c,f,b,v,m,y,g,w,k,x;if(h=this.args[0],i=i||[],this.iterated.length>i.length)for(w=Array(this.iterated.length-i.length),f=0,m=w.length;m>f;f++)s=w[f],c=this.iterated.pop(),c.unbind(),this.marker.parentNode.removeChild(c.els[0]);for(o=b=0,y=i.length;y>b;o=++b)if(l=i[o],r={index:o},r[t["public"].iterationAlias(h)]=o,r[h]=l,null==this.iterated[o]){k=this.view.models;for(u in k)l=k[u],null==r[u]&&(r[u]=l);p=this.iterated.length?this.iterated[this.iterated.length-1].els[0]:this.marker,a=this.view.options(),a.preloadData=!0,d=e.cloneNode(!0),c=new t.View(d,r,a),c.bind(),this.iterated.push(c),this.marker.parentNode.insertBefore(d,p.nextSibling)}else this.iterated[o].models[h]!==l&&this.iterated[o].update(r);if("OPTION"===e.nodeName)for(x=this.view.bindings,v=0,g=x.length;g>v;v++)n=x[v],n.el===this.marker.parentNode&&"value"===n.type&&n.sync()},update:function(t){var e,i,n,r,s,o,u;e={};for(i in t)n=t[i],i!==this.args[0]&&(e[i]=n);for(u=this.iterated,s=0,o=u.length;o>s;s++)r=u[s],r.update(e)}},t["public"].binders["class-*"]=function(t,e){var i;return i=" "+t.className+" ",!e==(-1!==i.indexOf(" "+this.args[0]+" "))?t.className=e?""+t.className+" "+this.args[0]:i.replace(" "+this.args[0]+" "," ").trim():void 0},t["public"].binders["*"]=function(t,e){return null!=e?t.setAttribute(this.type,e):t.removeAttribute(this.type)},t["public"].formatters.call=function(){var t,e;return e=arguments[0],t=2<=arguments.length?s.call(arguments,1):[],e.call.apply(e,[this].concat(s.call(t)))},t["public"].adapters["."]={id:"_rv",counter:0,weakmap:{},weakReference:function(t){var e,i,n;return t.hasOwnProperty(this.id)||(e=this.counter++,Object.defineProperty(t,this.id,{value:e})),(i=this.weakmap)[n=t[this.id]]||(i[n]={callbacks:{}})},cleanupWeakReference:function(t,e){return Object.keys(t.callbacks).length||t.pointers&&Object.keys(t.pointers).length?void 0:delete this.weakmap[e]},stubFunction:function(t,e){var i,n,r;return n=t[e],i=this.weakReference(t),r=this.weakmap,t[e]=function(){var e,s,o,u,l,h,a,p,d,c;u=n.apply(t,arguments),a=i.pointers;for(o in a)for(s=a[o],c=null!=(p=null!=(d=r[o])?d.callbacks[s]:void 0)?p:[],l=0,h=c.length;h>l;l++)e=c[l],e();return u}},observeMutations:function(t,e,i){var n,r,s,o,u,h;if(Array.isArray(t)){if(s=this.weakReference(t),null==s.pointers)for(s.pointers={},r=["push","pop","shift","unshift","sort","reverse","splice"],u=0,h=r.length;h>u;u++)n=r[u],this.stubFunction(t,n);if(null==(o=s.pointers)[e]&&(o[e]=[]),l.call(s.pointers[e],i)<0)return s.pointers[e].push(i)}},unobserveMutations:function(t,e,i){var n,r,s;return Array.isArray(t)&&null!=t[this.id]&&(r=this.weakmap[t[this.id]])&&(s=r.pointers[e])?((n=s.indexOf(i))>=0&&s.splice(n,1),s.length||delete r.pointers[e],this.cleanupWeakReference(r,t[this.id])):void 0},observe:function(t,e,i){var n,r,s;return n=this.weakReference(t).callbacks,null==n[e]&&(n[e]=[],r=Object.getOwnPropertyDescriptor(t,e),(null!=r?r.get:void 0)||(null!=r?r.set:void 0)||(s=t[e],Object.defineProperty(t,e,{enumerable:!0,get:function(){return s},set:function(i){return function(r){var o,u,h,a,p;if(r!==s&&(i.unobserveMutations(s,t[i.id],e),s=r,u=i.weakmap[t[i.id]])){if(n=u.callbacks,n[e])for(p=n[e].slice(),h=0,a=p.length;a>h;h++)o=p[h],l.call(n[e],o)>=0&&o();return i.observeMutations(r,t[i.id],e)}}}(this)}))),l.call(n[e],i)<0&&n[e].push(i),this.observeMutations(t[e],t[this.id],e)},unobserve:function(t,e,i){var n,r,s;return(s=this.weakmap[t[this.id]])&&(n=s.callbacks[e])?((r=n.indexOf(i))>=0&&(n.splice(r,1),n.length||(delete s.callbacks[e],this.unobserveMutations(t[e],t[this.id],e))),this.cleanupWeakReference(s,t[this.id])):void 0},get:function(t,e){return t[e]},set:function(t,e,i){return t[e]=i}},t.factory=function(e){return t.sightglass=e,t["public"]._=t,t["public"]},"object"==typeof("undefined"!=typeof module&&null!==module?module.exports:void 0)?module.exports=t.factory(require("sightglass")):"function"==typeof define&&define.amd?define(["sightglass"],function(e){return this.rivets=t.factory(e)}):this.rivets=t.factory(sightglass)}).call(this); \ No newline at end of file diff --git a/package.json b/package.json index 2ed55e8e1..3d2a8b9db 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "rivets", "description": "Declarative data binding + templating solution.", - "version": "0.9.1", + "version": "0.9.2", "author": "Michael Richards", "url": "http://rivetsjs.com", "main": "./dist/rivets.js",