diff --git a/.gitignore b/.gitignore index f66d9ef079..5dbaa70164 100755 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,11 @@ .DS_Store node_modules/ -sandbox/ -tmp/ \ No newline at end of file +sandbox/* +!sandbox/_base.html +!sandbox/_sandbox.css +!sandbox/require.js +!sandbox/sample/ +tmp/ +FIX.js +build/* +!build/README.md diff --git a/.travis.yml b/.travis.yml index b293a23c26..3822763338 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,14 @@ language: node_js -python: +node_js: - '0.10' before_script: -- npm install -g grunt-cli \ No newline at end of file +- npm install -g grunt-cli; chmod u+x scripts/deploy-edge-to-cdn.sh; grunt +script: ./scripts/deploy-edge-to-cdn.sh +env: + global: + - GH_REF: github.com/ractivejs/cdn.ractivejs.org.git + - secure: "dnPSiJmQuKhMh8skVLUjFegc+resP5wZV9scVxrSzkJNOzqLPE9Z8nm4c95gh6MzfHEz6YWz3gKfUfJeyHgpp1zfo+1EfOmit78GxZf+aj7GW1lBpPXFpobpTE1ZVTizu3/M6AojRXB7eIqSGJsUQvZAY8t1dldUDbocwveXqA0=" +branches: + only: + - master + - 0.4.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 90a5f970d5..5324220505 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,43 @@ Changelog --------- +* 0.4.0 + * BREAKING: Filenames are now lowercase. May affect you if you use Browserify etc. + * BREAKING: `set()`, `update()`, `teardown()`, `animate()`, `merge()`, `add()`, `subtract()`, and `toggle()` methods return a Promise that fulfils asynchronously when any resulting transitions have completed + * BREAKING: Elements are detached when *all* transitions are complete for a given instance, not just transitions on descendant nodes + * BREAKING: Default options are placed on `Ractive.defaults` (and `Component.defaults`, where `Component = Ractive.extend(...)`) + * BREAKING: The `adaptors` option is now `adapt`. It can be a string rather than an array if you're only using one adaptor + * Reactive computed properties + * Two-way binding works with 'keypath expressions' such as `{{foo[bar]}}` + * Support for single-file component imports via loader plugins such as http://ractivejs.github.io/ractive-load/ + * A global runloop handles change propagation and other batchable operations, resulting in performance improvements across the board + * Promises are used internally, and exposed as `Ractive.Promise` (Promises/A+ compliant, a la ES6 Promises) + * Components can have encapsulated styles, passed in as the `css` option (disable with `noCssTransform: true`) + * `ractive.reset()` method allows you to replace an instance's `data` object + * Decorators are updated when their arguments change (with specified `update()` method if possible, otherwise by tearing down and reinitialising) + * Inline components inherit surrounding data context, unless defined with `isolated: true` + * Transitions will use JavaScript timers if CSS transitions are unavailable + * A global variable (`window.Ractive`) is always exported, but `Ractive.noConflict()` is provided to prevent clobbering existing `Ractive` variable + * Inline component `init()` methods are only called once the component has entered the DOM + * Any section can be closed with `{{/...}}`, where `...` can be any string other than the closing delimiter + * Evaluators that throw exceptions will print an error to the console in debug mode + * `ractive.observe(callback)` - i.e. with no keypath - observes everything + * `ractive.observe('foo bar baz', callback)` will observe all three keypaths (passed to callback as third argument) + * Better whitespace preservation and indenting when using `ractive.toHTML()` + * Calling `ractive.off()` with no arguments removes all event listeners + * Triples work inside SVG elements + * `{{foo}}` works the same as `{{foo}}` + * More robust data/event propagation between components + * More robust magic mode + * Fixed a host of edge case bugs relating to array mutations + * Many minor fixes and tweaks: #349, #351, #353, #369, #370, #376, #377, #390, #391, #393, #398, #401, #406, #412, #425, #433, #434, #439, #441, #442, #446, #451, #460, #462, #464, #465, #467, #479, #480, #483, #486, #520, #530, #536, #553, #556 * 0.3.9 * `ractive.findComponent()` and `ractive.findAllComponents()` methods, for getting references to components * Expression results are wrapped if necessary (e.g. `{{getJSON(url)}}` wrapped by [@lluchs](https://github.com/lluchs)' [Promise adaptor](lluchs.github.io/Ractive-adaptors-Promise/)) * Mustaches referring to wrapped values render the facade, not the value * Directive arguments are parsed more reliably * Components inherit adaptors from their parents - * Adaptors can be set on subclasses defined with `Ractive.extend()` + * Adapto * Changes to [transitions API](http://docs.ractivejs.org/latest/transitions) * SVG support is detected and exposed as `Ractive.svg` * If subclass has data, it is used as prototype for instance data diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 47912e4128..db61050827 100755 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,13 +19,11 @@ Of course, if you've encountered a bug, then the best course of action is to rai Raising issues -------------- -Before submitting an issue, please make sure you're using the [latest released version](https://raw.github.com/RactiveJS/Ractive/master/Ractive.js). +Before submitting an issue, please make sure you're using the latest released version - http://cdn.ractivejs.org/latest/Ractive.js. -If the bug persists, it may have been fixed in the latest development version. New versions are developed in branches, named for the version number (e.g. at the time of writing, the development branch is [0.3.9](https://github.com/RactiveJS/Ractive/tree/0.3.9)). You can get the most recent builds from the `build` folder of this branch. +If the bug persists, it may have been fixed in the latest development version. You can always get the most recent successful build from http://cdn.ractivejs.org/edge/Ractive.js. -See the [branches page](https://github.com/RactiveJS/Ractive/branches) to find the newest development branch. - -The best issues contain a reproducible demonstration of the bug in the form of a [JSFiddle](http://jsfiddle.net/VGaLu/) or similar. A good tip when using these tools is to import Ractive via [rawgithub.com](https://rawgithub.com/), e.g. https://rawgithub.com/RactiveJS/Ractive/master/Ractive.js. +The best issues contain a reproducible demonstration of the bug in the form of a JSFiddle or similar. [This JSFiddle](http://jsfiddle.net/rich_harris/va6jU/) has a basic setup to get started with. Pull requests @@ -34,7 +32,7 @@ Pull requests **Pull requests against the master branch will not be merged!** -All pull requests are welcome. You should create a new branch, based on the newest development branch (see above), and submit the PR against the dev branch. +All pull requests are welcome. You should create a new branch, based on the newest development branch (currently [0.4.0](https://github.com/RactiveJS/Ractive/tree/0.4.0)), and submit the PR against that dev branch. *Caveat for what follows: If in doubt, submit the request - a PR that needs tweaking is infinitely more valuable than a request that wasn't made because you were worrying about meeting these requirements.* diff --git a/Gruntfile.js b/Gruntfile.js index 826130233b..d0174f0075 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,204 +1,35 @@ /*global module:false*/ -module.exports = function(grunt) { +module.exports = function ( grunt ) { - // Project configuration. - grunt.initConfig({ + 'use strict'; - pkg: grunt.file.readJSON( 'package.json' ), - - watch: { - js: { - files: [ 'src/**/*.js', 'wrapper/**/*.js' ], - tasks: [ 'clean:tmp', 'requirejs' ], - options: { - interrupt: true, - force: true - } - } - }, - - nodeunit: { - basic: [ 'test/node/basic.js' ], - parse: [ 'test/node/parse.js' ], - toHTML: [ 'test/node/toHTML.js' ] - }, - - qunit: { - parse: [ 'test/build/parse.html' ], - render: [ 'test/build/render.html' ], - mustache: [ 'test/build/mustache.html' ], - events: [ 'test/build/events.html' ], - misc: [ 'test/build/misc.html' ], - components: [ 'test/build/components.html' ], - merge: [ 'test/build/merge.html' ], - observe: [ 'test/build/observe.html' ], - options: { - timeout: 30000 - } - }, - - requirejs: { - full: { - options: { - baseUrl: 'src/', - name: 'Ractive', - out: 'tmp/Ractive.js', - optimize: 'none', - findNestedDependencies: true, - onBuildWrite: function( name, path, contents ) { - return require( 'amdclean' ).clean( contents ); - }, - - wrap: { - startFile: 'wrapper/intro.js', - endFile: 'wrapper/outro.js' - } - } - }, - runtime: { - options: { - baseUrl: 'src/', - name: 'Ractive', - out: 'tmp/Ractive.runtime.js', - optimize: 'none', - findNestedDependencies: true, - onBuildWrite: function( name, path, contents ) { - return require( 'amdclean' ).clean( contents ); - }, - - paths: { - 'parse/_parse': 'empty:' - }, - - wrap: { - startFile: 'wrapper/intro.js', - endFile: 'wrapper/outro.js' - } - } - } - }, + var config, dependency; - concat: { - options: { - banner: grunt.file.read( 'wrapper/banner.js' ), - process: { - data: { version: '<%= pkg.version %>' } - } - }, - full: { - src: [ 'tmp/Ractive.js' ], - dest: 'build/Ractive.js' - }, - runtime: { - src: [ 'tmp/Ractive.runtime.js' ], - dest: 'build/Ractive.runtime.js' - }, - full_legacy: { - src: [ 'src/legacy.js', 'tmp/Ractive.js' ], - dest: 'build/Ractive-legacy.js' - }, - runtime_legacy: { - src: [ 'src/legacy.js', 'tmp/Ractive.runtime.js' ], - dest: 'build/Ractive-legacy.runtime.js' - } - }, - - clean: { - tmp: [ 'tmp/' ], - build: [ 'build/' ] - }, - - jshint: { - files: [ 'src/**/*.js' ], - options: { - proto: true, - smarttabs: true, - boss: true, - evil: true, - laxbreak: true, - undef: true, - unused: true, - '-W018': true, - '-W041': false, - eqnull: true, - strict: true, - globals: { - define: true, - require: true, - Element: true, - window: true, - setTimeout: true, - setInterval: true, - clearInterval: true, - module: true, - document: true, - loadCircularDependency: true - } - } - }, - - uglify: { - runtime: { - src: ['<%= concat.runtime.dest %>'], - dest: 'build/Ractive.runtime.min.js' - }, - full: { - src: ['<%= concat.full.dest %>'], - dest: 'build/Ractive.min.js' - }, - runtime_legacy: { - src: ['<%= concat.runtime_legacy.dest %>'], - dest: 'build/Ractive-legacy.runtime.min.js' - }, - full_legacy: { - src: ['<%= concat.full_legacy.dest %>'], - dest: 'build/Ractive-legacy.min.js' - } - }, - - copy: { - release: { - files: [{ - expand: true, - cwd: 'build/', - src: [ '**/*' ], - dest: 'release/<%= pkg.version %>/' - }] - }, - link: { - files: { - 'Ractive.js': 'build/Ractive.js' - } - } - } + config = { + pkg: grunt.file.readJSON( 'package.json' ), + intro: grunt.file.read( 'wrapper/intro.js' ), + outro: grunt.file.read( 'wrapper/outro.js' ), + banner: grunt.file.read( 'wrapper/banner.js' ) + }; + + // Read config files from the `grunt/config/` folder + grunt.file.expand( 'grunt/config/*.js' ).forEach( function ( path ) { + var property = /grunt\/config\/(.+)\.js/.exec( path )[1], + module = require( './' + path ); + config[ property ] = typeof module === 'function' ? module( grunt ) : module; }); - grunt.loadNpmTasks( 'grunt-contrib-jshint' ); - grunt.loadNpmTasks( 'grunt-contrib-clean' ); - grunt.loadNpmTasks( 'grunt-contrib-nodeunit' ); - grunt.loadNpmTasks( 'grunt-contrib-qunit' ); - grunt.loadNpmTasks( 'grunt-contrib-concat' ); - grunt.loadNpmTasks( 'grunt-contrib-uglify' ); - grunt.loadNpmTasks( 'grunt-contrib-copy' ); - grunt.loadNpmTasks( 'grunt-contrib-watch' ); - grunt.loadNpmTasks( 'grunt-contrib-requirejs' ); + // Initialise grunt + grunt.initConfig( config ); - grunt.registerTask( 'default', [ - 'test', - 'clean:build', - 'concat', - 'uglify', - 'copy:link' - ]); - - grunt.registerTask( 'test', [ - 'clean:tmp', - 'jshint', - 'requirejs', - 'nodeunit', - 'qunit' - ]); + // Load development dependencies specified in package.json + for ( dependency in config.pkg.devDependencies ) { + if ( /^grunt-/.test( dependency) ) { + grunt.loadNpmTasks( dependency ); + } + } - grunt.registerTask( 'release', [ 'default', 'copy:release', 'copy:link' ] ); + // Load tasks from the `grunt-tasks/` folder + grunt.loadTasks( 'grunt/tasks' ); }; diff --git a/LICENSE.md b/LICENSE.md index beb3fbdbfa..e83ccb5444 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2014 Rich Harris and contributors +Copyright (c) 2013-14 Rich Harris and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/README.md b/README.md index 407698380a..e75c747475 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Ractive.js - Next-generation DOM manipulation *Got questions? Tag Stack Overflow questions with [ractivejs](http://stackoverflow.com/questions/tagged/ractivejs) or contact [@RactiveJS](http://twitter.com/RactiveJS) on Twitter* -*BETANAUTS! Help improve the next version of Ractive by trying out the [pre-release 0.4.0 builds](https://github.com/Rich-Harris/Ractive/tree/0.4.0/build) and [reporting any issues](https://github.com/Rich-Harris/Ractive/issues?state=open)!* +*BETANAUTS! Help improve the next version of Ractive by trying out the [pre-release 0.4.0 builds](https://github.com/ractivejs/ractive/tree/0.4.0/build) and [reporting any issues](https://github.com/ractivejs/ractive/issues?state=open)!* What is Ractive.js? ------------------- @@ -17,13 +17,13 @@ It's a JavaScript library for building reactive user interfaces in a way that do ...among many others. It takes a radically different approach to DOM manipulation - one that saves both you and the browser unnecessary work. -To get a feel for how it will make your life as a web developer easier, visit [ractivejs.org](http://ractivejs.org), follow the [interactive tutorials](http://learn.ractivejs.org), or try the [60 second setup](https://github.com/RactiveJS/Ractive/wiki/60-second-setup). +To get a feel for how it will make your life as a web developer easier, visit [ractivejs.org](http://ractivejs.org), follow the [interactive tutorials](http://learn.ractivejs.org), or try the [60 second setup](https://github.com/ractivejs/ractive/wiki/60-second-setup). Get help -------- -If you don't find what you're looking for in the [docs](https://github.com/rich-harris/Ractive/wiki), ask a question on Stack Overflow with the `ractivejs` tag, or send a tweet to [@RactiveJS](http://twitter.com/RactiveJS) or [@Rich_Harris](http://twitter.com/Rich_Harris). +If you don't find what you're looking for in the [docs](http://docs.ractivejs.org/latest), ask a question on Stack Overflow with the `ractive` tag, or send a tweet to [@RactiveJS](http://twitter.com/RactiveJS). Building @@ -69,7 +69,7 @@ $ grunt release Contributing ------------ -If you have feature suggestions or bug reports, please [raise an issue on GitHub](https://github.com/RactiveJS/Ractive/issues) after checking it's not a duplicate. +If you have feature suggestions or bug reports, please [raise an issue on GitHub](https://github.com/ractivejs/ractive/issues) after checking it's not a duplicate. Pull requests are always welcome! In lieu of a formal styleguide, please try to follow the existing conventions. diff --git a/Ractive.js b/Ractive.js deleted file mode 100644 index 462414585e..0000000000 --- a/Ractive.js +++ /dev/null @@ -1,9134 +0,0 @@ -/* - - Ractive - v0.3.9 - 2013-12-31 - ============================================================== - - Next-generation DOM manipulation - http://ractivejs.org - Follow @RactiveJS for updates - - -------------------------------------------------------------- - - Copyright 2013 2013 Rich Harris and contributors - - Permission is hereby granted, free of charge, to any person - obtaining a copy of this software and associated documentation - files (the "Software"), to deal in the Software without - restriction, including without limitation the rights to use, - copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following - conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - OTHER DEALINGS IN THE SOFTWARE. - -*/ - -(function ( global ) { - - - -var config_svg = function () { - - if (typeof document === 'undefined') { - return; - } - return document && document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#BasicStructure', '1.1'); - }(); -var utils_create = function () { - - var create; - try { - Object.create(null); - create = Object.create; - } catch (err) { - create = function () { - var F = function () { - }; - return function (proto, props) { - var obj; - if (proto === null) { - return {}; - } - F.prototype = proto; - obj = new F(); - if (props) { - Object.defineProperties(obj, props); - } - return obj; - }; - }(); - } - return create; - }(); -var config_namespaces = { - html: 'http://www.w3.org/1999/xhtml', - mathml: 'http://www.w3.org/1998/Math/MathML', - svg: 'http://www.w3.org/2000/svg', - xlink: 'http://www.w3.org/1999/xlink', - xml: 'http://www.w3.org/XML/1998/namespace', - xmlns: 'http://www.w3.org/2000/xmlns/' - }; -var utils_createElement = function (svg, namespaces) { - - if (!svg) { - return function (type, ns) { - if (ns && ns !== namespaces.html) { - throw 'This browser does not support namespaces other than http://www.w3.org/1999/xhtml. The most likely cause of this error is that you\'re trying to render SVG in an older browser. See https://github.com/RactiveJS/Ractive/wiki/SVG-and-older-browsers for more information'; - } - return document.createElement(type); - }; - } else { - return function (type, ns) { - if (!ns) { - return document.createElement(type); - } - return document.createElementNS(ns, type); - }; - } - }(config_svg, config_namespaces); -var config_isClient = function () { - - if (typeof document === 'object') { - return true; - } - return false; - }(); -var utils_defineProperty = function (isClient) { - - try { - Object.defineProperty({}, 'test', { value: 0 }); - if (isClient) { - Object.defineProperty(document.createElement('div'), 'test', { value: 0 }); - } - return Object.defineProperty; - } catch (err) { - return function (obj, prop, desc) { - obj[prop] = desc.value; - }; - } - }(config_isClient); -var utils_defineProperties = function (createElement, defineProperty, isClient) { - - try { - try { - Object.defineProperties({}, { test: { value: 0 } }); - } catch (err) { - throw err; - } - if (isClient) { - Object.defineProperties(createElement('div'), { test: { value: 0 } }); - } - return Object.defineProperties; - } catch (err) { - return function (obj, props) { - var prop; - for (prop in props) { - if (props.hasOwnProperty(prop)) { - defineProperty(obj, prop, props[prop]); - } - } - }; - } - }(utils_createElement, utils_defineProperty, config_isClient); -var utils_normaliseKeypath = function () { - - var regex = /\[\s*(\*|[0-9]|[1-9][0-9]+)\s*\]/g; - return function (keypath) { - return (keypath || '').replace(regex, '.$1'); - }; - }(); -var registries_adaptors = {}; -var config_types = { - TEXT: 1, - INTERPOLATOR: 2, - TRIPLE: 3, - SECTION: 4, - INVERTED: 5, - CLOSING: 6, - ELEMENT: 7, - PARTIAL: 8, - COMMENT: 9, - DELIMCHANGE: 10, - MUSTACHE: 11, - TAG: 12, - ATTRIBUTE: 13, - COMPONENT: 15, - NUMBER_LITERAL: 20, - STRING_LITERAL: 21, - ARRAY_LITERAL: 22, - OBJECT_LITERAL: 23, - BOOLEAN_LITERAL: 24, - GLOBAL: 26, - KEY_VALUE_PAIR: 27, - REFERENCE: 30, - REFINEMENT: 31, - MEMBER: 32, - PREFIX_OPERATOR: 33, - BRACKETED: 34, - CONDITIONAL: 35, - INFIX_OPERATOR: 36, - INVOCATION: 40 - }; -var utils_isArray = function () { - - var toString = Object.prototype.toString; - return function (thing) { - return toString.call(thing) === '[object Array]'; - }; - }(); -var shared_clearCache = function () { - - return function clearCache(ractive, keypath) { - var cacheMap, wrappedProperty; - if (wrappedProperty = ractive._wrapped[keypath]) { - if (wrappedProperty.teardown() !== false) { - ractive._wrapped[keypath] = null; - } - } - ractive._cache[keypath] = undefined; - if (cacheMap = ractive._cacheMap[keypath]) { - while (cacheMap.length) { - clearCache(ractive, cacheMap.pop()); - } - } - }; - }(); -var shared_getValueFromCheckboxes = function () { - - return function (ractive, keypath) { - var value, checkboxes, checkbox, len, i, rootEl; - value = []; - rootEl = ractive.rendered ? ractive.el : ractive.fragment.docFrag; - checkboxes = rootEl.querySelectorAll('input[type="checkbox"][name="{{' + keypath + '}}"]'); - len = checkboxes.length; - for (i = 0; i < len; i += 1) { - checkbox = checkboxes[i]; - if (checkbox.hasAttribute('checked') || checkbox.checked) { - value[value.length] = checkbox._ractive.value; - } - } - return value; - }; - }(); -var shared_preDomUpdate = function (getValueFromCheckboxes) { - - return function (ractive) { - var deferred, evaluator, selectValue, attribute, keypath, radio; - deferred = ractive._deferred; - while (evaluator = deferred.evals.pop()) { - evaluator.update().deferred = false; - } - while (selectValue = deferred.selectValues.pop()) { - selectValue.deferredUpdate(); - } - while (attribute = deferred.attrs.pop()) { - attribute.update().deferred = false; - } - while (keypath = deferred.checkboxes.pop()) { - ractive.set(keypath, getValueFromCheckboxes(ractive, keypath)); - } - while (radio = deferred.radios.pop()) { - radio.update(); - } - }; - }(shared_getValueFromCheckboxes); -var shared_postDomUpdate = function () { - - return function (ractive) { - var deferred, focusable, query, decorator, transition, observer; - deferred = ractive._deferred; - if (focusable = deferred.focusable) { - focusable.focus(); - deferred.focusable = null; - } - while (query = deferred.liveQueries.pop()) { - query._sort(); - } - while (decorator = deferred.decorators.pop()) { - decorator.init(); - } - while (transition = deferred.transitions.pop()) { - transition.init(); - } - while (observer = deferred.observers.pop()) { - observer.update(); - } - }; - }(); -var shared_makeTransitionManager = function () { - - var makeTransitionManager = function (root, callback) { - var transitionManager, elementsToDetach, detachNodes, nodeHasNoTransitioningChildren; - if (root._parent && root._parent._transitionManager) { - return root._parent._transitionManager; - } - elementsToDetach = []; - detachNodes = function () { - var i, element; - i = elementsToDetach.length; - while (i--) { - element = elementsToDetach[i]; - if (nodeHasNoTransitioningChildren(element.node)) { - element.detach(); - elementsToDetach.splice(i, 1); - } - } - }; - nodeHasNoTransitioningChildren = function (node) { - var i, candidate; - i = transitionManager.active.length; - while (i--) { - candidate = transitionManager.active[i]; - if (node.contains(candidate)) { - return false; - } - } - return true; - }; - transitionManager = { - active: [], - push: function (node) { - transitionManager.active[transitionManager.active.length] = node; - }, - pop: function (node) { - var index; - index = transitionManager.active.indexOf(node); - if (index === -1) { - return; - } - transitionManager.active.splice(index, 1); - detachNodes(); - if (!transitionManager.active.length && transitionManager._ready) { - transitionManager.complete(); - } - }, - complete: function () { - if (callback) { - callback.call(root); - } - }, - ready: function () { - detachNodes(); - transitionManager._ready = true; - if (!transitionManager.active.length) { - transitionManager.complete(); - } - }, - detachWhenReady: function (element) { - elementsToDetach[elementsToDetach.length] = element; - } - }; - return transitionManager; - }; - return makeTransitionManager; - }(); -var shared_notifyDependants = function () { - - var notifyDependants, lastKey, starMaps = {}; - lastKey = /[^\.]+$/; - notifyDependants = function (ractive, keypath, onlyDirect) { - var i; - if (ractive._patternObservers.length) { - notifyPatternObservers(ractive, keypath, keypath, onlyDirect, true); - } - for (i = 0; i < ractive._deps.length; i += 1) { - notifyDependantsAtPriority(ractive, keypath, i, onlyDirect); - } - }; - notifyDependants.multiple = function (ractive, keypaths, onlyDirect) { - var i, j, len; - len = keypaths.length; - if (ractive._patternObservers.length) { - i = len; - while (i--) { - notifyPatternObservers(ractive, keypaths[i], keypaths[i], onlyDirect, true); - } - } - for (i = 0; i < ractive._deps.length; i += 1) { - if (ractive._deps[i]) { - j = len; - while (j--) { - notifyDependantsAtPriority(ractive, keypaths[j], i, onlyDirect); - } - } - } - }; - return notifyDependants; - function notifyDependantsAtPriority(ractive, keypath, priority, onlyDirect) { - var depsByKeypath = ractive._deps[priority]; - if (!depsByKeypath) { - return; - } - updateAll(depsByKeypath[keypath]); - if (onlyDirect) { - return; - } - cascade(ractive._depsMap[keypath], ractive, priority); - } - function updateAll(deps) { - var i, len; - if (deps) { - len = deps.length; - for (i = 0; i < len; i += 1) { - deps[i].update(); - } - } - } - function cascade(childDeps, ractive, priority, onlyDirect) { - var i; - if (childDeps) { - i = childDeps.length; - while (i--) { - notifyDependantsAtPriority(ractive, childDeps[i], priority, onlyDirect); - } - } - } - function notifyPatternObservers(ractive, registeredKeypath, actualKeypath, isParentOfChangedKeypath, isTopLevelCall) { - var i, patternObserver, children, child, key, childActualKeypath, potentialWildcardMatches, cascade; - i = ractive._patternObservers.length; - while (i--) { - patternObserver = ractive._patternObservers[i]; - if (patternObserver.regex.test(actualKeypath)) { - patternObserver.update(actualKeypath); - } - } - if (isParentOfChangedKeypath) { - return; - } - cascade = function (keypath) { - if (children = ractive._depsMap[keypath]) { - i = children.length; - while (i--) { - child = children[i]; - key = lastKey.exec(child)[0]; - childActualKeypath = actualKeypath + '.' + key; - notifyPatternObservers(ractive, child, childActualKeypath); - } - } - }; - if (isTopLevelCall) { - potentialWildcardMatches = getPotentialWildcardMatches(actualKeypath); - potentialWildcardMatches.forEach(cascade); - } else { - cascade(registeredKeypath); - } - } - function getPotentialWildcardMatches(keypath) { - var keys, starMap, mapper, i, result, wildcardKeypath; - keys = keypath.split('.'); - starMap = getStarMap(keys.length); - result = []; - mapper = function (star, i) { - return star ? '*' : keys[i]; - }; - i = starMap.length; - while (i--) { - wildcardKeypath = starMap[i].map(mapper).join('.'); - if (!result[wildcardKeypath]) { - result[result.length] = wildcardKeypath; - result[wildcardKeypath] = true; - } - } - return result; - } - function getStarMap(num) { - var ones = '', max, binary, starMap, mapper, i; - if (!starMaps[num]) { - starMap = []; - while (ones.length < num) { - ones += 1; - } - max = parseInt(ones, 2); - mapper = function (digit) { - return digit === '1'; - }; - for (i = 0; i <= max; i += 1) { - binary = i.toString(2); - while (binary.length < num) { - binary = '0' + binary; - } - starMap[i] = Array.prototype.map.call(binary, mapper); - } - starMaps[num] = starMap; - } - return starMaps[num]; - } - }(); -var Ractive_prototype_get_arrayAdaptor = function (types, defineProperty, isArray, clearCache, preDomUpdate, postDomUpdate, makeTransitionManager, notifyDependants) { - - var arrayAdaptor, notifyArrayDependants, ArrayWrapper, patchArrayMethods, unpatchArrayMethods, patchedArrayProto, testObj, mutatorMethods, noop, errorMessage; - arrayAdaptor = { - filter: function (object) { - return isArray(object) && (!object._ractive || !object._ractive.setting); - }, - wrap: function (ractive, array, keypath) { - return new ArrayWrapper(ractive, array, keypath); - } - }; - ArrayWrapper = function (ractive, array, keypath) { - this.root = ractive; - this.value = array; - this.keypath = keypath; - if (!array._ractive) { - defineProperty(array, '_ractive', { - value: { - wrappers: [], - instances: [], - setting: false - }, - configurable: true - }); - patchArrayMethods(array); - } - if (!array._ractive.instances[ractive._guid]) { - array._ractive.instances[ractive._guid] = 0; - array._ractive.instances.push(ractive); - } - array._ractive.instances[ractive._guid] += 1; - array._ractive.wrappers.push(this); - }; - ArrayWrapper.prototype = { - get: function () { - return this.value; - }, - teardown: function () { - var array, storage, wrappers, instances, index; - array = this.value; - storage = array._ractive; - wrappers = storage.wrappers; - instances = storage.instances; - if (storage.setting) { - return false; - } - index = wrappers.indexOf(this); - if (index === -1) { - throw new Error(errorMessage); - } - wrappers.splice(index, 1); - if (!wrappers.length) { - delete array._ractive; - unpatchArrayMethods(this.value); - } else { - instances[this.root._guid] -= 1; - if (!instances[this.root._guid]) { - index = instances.indexOf(this.root); - if (index === -1) { - throw new Error(errorMessage); - } - instances.splice(index, 1); - } - } - } - }; - notifyArrayDependants = function (array, methodName, args) { - var notifyKeypathDependants, queueDependants, wrappers, wrapper, i; - notifyKeypathDependants = function (root, keypath) { - var depsByKeypath, deps, keys, upstreamQueue, smartUpdateQueue, dumbUpdateQueue, i, changed, start, end, childKeypath, lengthUnchanged; - if (methodName === 'sort' || methodName === 'reverse') { - root.set(keypath, array); - return; - } - clearCache(root, keypath); - smartUpdateQueue = []; - dumbUpdateQueue = []; - for (i = 0; i < root._deps.length; i += 1) { - depsByKeypath = root._deps[i]; - if (!depsByKeypath) { - continue; - } - deps = depsByKeypath[keypath]; - if (deps) { - queueDependants(keypath, deps, smartUpdateQueue, dumbUpdateQueue); - preDomUpdate(root); - while (smartUpdateQueue.length) { - smartUpdateQueue.pop().smartUpdate(methodName, args); - } - while (dumbUpdateQueue.length) { - dumbUpdateQueue.pop().update(); - } - } - } - if (methodName === 'splice' && args.length > 2 && args[1]) { - changed = Math.min(args[1], args.length - 2); - start = args[0]; - end = start + changed; - if (args[1] === args.length - 2) { - lengthUnchanged = true; - } - for (i = start; i < end; i += 1) { - childKeypath = keypath + '.' + i; - notifyDependants(root, childKeypath); - } - } - preDomUpdate(root); - upstreamQueue = []; - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - upstreamQueue[upstreamQueue.length] = keys.join('.'); - } - notifyDependants.multiple(root, upstreamQueue, true); - if (!lengthUnchanged) { - notifyDependants(root, keypath + '.length', true); - } - }; - queueDependants = function (keypath, deps, smartUpdateQueue, dumbUpdateQueue) { - var k, dependant; - k = deps.length; - while (k--) { - dependant = deps[k]; - if (dependant.type === types.REFERENCE) { - dependant.update(); - } else if (dependant.keypath === keypath && dependant.type === types.SECTION && !dependant.inverted && dependant.docFrag) { - smartUpdateQueue[smartUpdateQueue.length] = dependant; - } else { - dumbUpdateQueue[dumbUpdateQueue.length] = dependant; - } - } - }; - wrappers = array._ractive.wrappers; - i = wrappers.length; - while (i--) { - wrapper = wrappers[i]; - notifyKeypathDependants(wrapper.root, wrapper.keypath); - } - }; - patchedArrayProto = []; - mutatorMethods = [ - 'pop', - 'push', - 'reverse', - 'shift', - 'sort', - 'splice', - 'unshift' - ]; - noop = function () { - }; - mutatorMethods.forEach(function (methodName) { - var method = function () { - var result, instances, instance, i, previousTransitionManagers = {}, transitionManagers = {}; - result = Array.prototype[methodName].apply(this, arguments); - instances = this._ractive.instances; - i = instances.length; - while (i--) { - instance = instances[i]; - previousTransitionManagers[instance._guid] = instance._transitionManager; - instance._transitionManager = transitionManagers[instance._guid] = makeTransitionManager(instance, noop); - } - this._ractive.setting = true; - notifyArrayDependants(this, methodName, arguments); - this._ractive.setting = false; - i = instances.length; - while (i--) { - instance = instances[i]; - instance._transitionManager = previousTransitionManagers[instance._guid]; - transitionManagers[instance._guid].ready(); - preDomUpdate(instance); - postDomUpdate(instance); - } - return result; - }; - defineProperty(patchedArrayProto, methodName, { value: method }); - }); - testObj = {}; - if (testObj.__proto__) { - patchArrayMethods = function (array) { - array.__proto__ = patchedArrayProto; - }; - unpatchArrayMethods = function (array) { - array.__proto__ = Array.prototype; - }; - } else { - patchArrayMethods = function (array) { - var i, methodName; - i = mutatorMethods.length; - while (i--) { - methodName = mutatorMethods[i]; - defineProperty(array, methodName, { - value: patchedArrayProto[methodName], - configurable: true - }); - } - }; - unpatchArrayMethods = function (array) { - var i; - i = mutatorMethods.length; - while (i--) { - delete array[mutatorMethods[i]]; - } - }; - } - errorMessage = 'Something went wrong in a rather interesting way'; - return arrayAdaptor; - }(config_types, utils_defineProperty, utils_isArray, shared_clearCache, shared_preDomUpdate, shared_postDomUpdate, shared_makeTransitionManager, shared_notifyDependants); -var Ractive_prototype_get_magicAdaptor = function () { - - var magicAdaptor, MagicWrapper; - try { - Object.defineProperty({}, 'test', { value: 0 }); - } catch (err) { - return false; - } - magicAdaptor = { - filter: function (object, keypath) { - return !!keypath; - }, - wrap: function (ractive, object, keypath) { - return new MagicWrapper(ractive, object, keypath); - } - }; - MagicWrapper = function (ractive, object, keypath) { - var wrapper = this, keys, prop, objKeypath, descriptor, wrappers, oldGet, oldSet, get, set; - this.ractive = ractive; - this.keypath = keypath; - keys = keypath.split('.'); - this.prop = keys.pop(); - objKeypath = keys.join('.'); - this.obj = objKeypath ? ractive.get(objKeypath) : ractive.data; - descriptor = this.originalDescriptor = Object.getOwnPropertyDescriptor(this.obj, this.prop); - if (descriptor && descriptor.set && (wrappers = descriptor.set._ractiveWrappers)) { - if (wrappers.indexOf(this) === -1) { - wrappers.push(this); - } - return; - } - if (descriptor && !descriptor.configurable) { - throw new Error('Cannot use magic mode with property "' + prop + '" - object is not configurable'); - } - if (descriptor) { - this.value = descriptor.value; - oldGet = descriptor.get; - oldSet = descriptor.set; - } - get = oldGet || function () { - return wrapper.value; - }; - set = function (value) { - var wrappers, wrapper, i; - if (oldSet) { - oldSet(value); - } - wrappers = set._ractiveWrappers; - i = wrappers.length; - while (i--) { - wrapper = wrappers[i]; - if (!wrapper.resetting) { - wrapper.ractive.set(wrapper.keypath, value); - } - } - }; - set._ractiveWrappers = [this]; - Object.defineProperty(this.obj, this.prop, { - get: get, - set: set, - enumerable: true, - configurable: true - }); - }; - MagicWrapper.prototype = { - get: function () { - return this.value; - }, - reset: function (value) { - this.resetting = true; - this.value = value; - this.resetting = false; - }, - teardown: function () { - var descriptor, set, value, wrappers; - descriptor = Object.getOwnPropertyDescriptor(this.obj, this.prop); - set = descriptor.set; - wrappers = set._ractiveWrappers; - wrappers.splice(wrappers.indexOf(this), 1); - if (!wrappers.length) { - value = this.obj[this.prop]; - Object.defineProperty(this.obj, this.prop, this.originalDescriptor || { - writable: true, - enumerable: true, - configrable: true - }); - this.obj[this.prop] = value; - } - } - }; - return magicAdaptor; - }(); -var shared_adaptIfNecessary = function (adaptorRegistry, arrayAdaptor, magicAdaptor) { - - var prefixers = {}; - return function (ractive, keypath, value, isExpressionResult) { - var len, i, adaptor, wrapped; - len = ractive.adaptors.length; - for (i = 0; i < len; i += 1) { - adaptor = ractive.adaptors[i]; - if (typeof adaptor === 'string') { - if (!adaptorRegistry[adaptor]) { - throw new Error('Missing adaptor "' + adaptor + '"'); - } - adaptor = ractive.adaptors[i] = adaptorRegistry[adaptor]; - } - if (adaptor.filter(value, keypath, ractive)) { - wrapped = ractive._wrapped[keypath] = adaptor.wrap(ractive, value, keypath, getPrefixer(keypath)); - wrapped.value = value; - return; - } - } - if (!isExpressionResult) { - if (ractive.magic && magicAdaptor.filter(value, keypath, ractive)) { - ractive._wrapped[keypath] = magicAdaptor.wrap(ractive, value, keypath); - } else if (ractive.modifyArrays && arrayAdaptor.filter(value, keypath, ractive)) { - ractive._wrapped[keypath] = arrayAdaptor.wrap(ractive, value, keypath); - } - } - }; - function prefixKeypath(obj, prefix) { - var prefixed = {}, key; - if (!prefix) { - return obj; - } - prefix += '.'; - for (key in obj) { - if (obj.hasOwnProperty(key)) { - prefixed[prefix + key] = obj[key]; - } - } - return prefixed; - } - function getPrefixer(rootKeypath) { - var rootDot; - if (!prefixers[rootKeypath]) { - rootDot = rootKeypath ? rootKeypath + '.' : ''; - prefixers[rootKeypath] = function (relativeKeypath, value) { - var obj; - if (typeof relativeKeypath === 'string') { - obj = {}; - obj[rootDot + relativeKeypath] = value; - return obj; - } - if (typeof relativeKeypath === 'object') { - return rootDot ? prefixKeypath(relativeKeypath, rootKeypath) : relativeKeypath; - } - }; - } - return prefixers[rootKeypath]; - } - }(registries_adaptors, Ractive_prototype_get_arrayAdaptor, Ractive_prototype_get_magicAdaptor); -var Ractive_prototype_get__get = function (normaliseKeypath, adaptorRegistry, adaptIfNecessary) { - - var get, _get, retrieve; - get = function (keypath) { - if (this._captured && !this._captured[keypath]) { - this._captured.push(keypath); - this._captured[keypath] = true; - } - return _get(this, keypath); - }; - _get = function (ractive, keypath) { - var cache, cached, value, wrapped, evaluator; - keypath = normaliseKeypath(keypath); - cache = ractive._cache; - if ((cached = cache[keypath]) !== undefined) { - return cached; - } - if (wrapped = ractive._wrapped[keypath]) { - value = wrapped.value; - } else if (!keypath) { - adaptIfNecessary(ractive, '', ractive.data); - value = ractive.data; - } else if (evaluator = ractive._evaluators[keypath]) { - value = evaluator.value; - } else { - value = retrieve(ractive, keypath); - } - cache[keypath] = value; - return value; - }; - retrieve = function (ractive, keypath) { - var keys, key, parentKeypath, parentValue, cacheMap, value, wrapped; - keys = keypath.split('.'); - key = keys.pop(); - parentKeypath = keys.join('.'); - parentValue = _get(ractive, parentKeypath); - if (wrapped = ractive._wrapped[parentKeypath]) { - parentValue = wrapped.get(); - } - if (parentValue === null || parentValue === undefined) { - return; - } - if (!(cacheMap = ractive._cacheMap[parentKeypath])) { - ractive._cacheMap[parentKeypath] = [keypath]; - } else { - if (cacheMap.indexOf(keypath) === -1) { - cacheMap[cacheMap.length] = keypath; - } - } - value = parentValue[key]; - adaptIfNecessary(ractive, keypath, value); - ractive._cache[keypath] = value; - return value; - }; - return get; - }(utils_normaliseKeypath, registries_adaptors, shared_adaptIfNecessary); -var utils_isObject = function () { - - var toString = Object.prototype.toString; - return function (thing) { - return typeof thing === 'object' && toString.call(thing) === '[object Object]'; - }; - }(); -var utils_isEqual = function () { - - return function (a, b) { - if (a === null && b === null) { - return true; - } - if (typeof a === 'object' || typeof b === 'object') { - return false; - } - return a === b; - }; - }(); -var shared_resolveRef = function () { - - var resolveRef; - resolveRef = function (ractive, ref, contextStack) { - var keypath, keys, lastKey, contextKeys, innerMostContext, postfix, parentKeypath, parentValue, wrapped, context, ancestorErrorMessage; - ancestorErrorMessage = 'Could not resolve reference - too many "../" prefixes'; - if (ref === '.') { - if (!contextStack.length) { - return ''; - } - keypath = contextStack[contextStack.length - 1]; - } else if (ref.charAt(0) === '.') { - context = contextStack[contextStack.length - 1]; - contextKeys = context ? context.split('.') : []; - if (ref.substr(0, 3) === '../') { - while (ref.substr(0, 3) === '../') { - if (!contextKeys.length) { - throw new Error(ancestorErrorMessage); - } - contextKeys.pop(); - ref = ref.substring(3); - } - contextKeys.push(ref); - keypath = contextKeys.join('.'); - } else if (!context) { - keypath = ref.substring(1); - } else { - keypath = context + ref; - } - } else { - keys = ref.split('.'); - lastKey = keys.pop(); - postfix = keys.length ? '.' + keys.join('.') : ''; - contextStack = contextStack.concat(); - while (contextStack.length) { - innerMostContext = contextStack.pop(); - parentKeypath = innerMostContext + postfix; - parentValue = ractive.get(parentKeypath); - if (wrapped = ractive._wrapped[parentKeypath]) { - parentValue = wrapped.get(); - } - if (typeof parentValue === 'object' && parentValue !== null && parentValue.hasOwnProperty(lastKey)) { - keypath = innerMostContext + '.' + ref; - break; - } - } - if (!keypath && ractive.get(ref) !== undefined) { - keypath = ref; - } - } - return keypath ? keypath.replace(/^\./, '') : keypath; - }; - return resolveRef; - }(); -var shared_attemptKeypathResolution = function (resolveRef) { - - var push = Array.prototype.push; - return function (ractive) { - var unresolved, keypath, leftover; - while (unresolved = ractive._pendingResolution.pop()) { - keypath = resolveRef(ractive, unresolved.ref, unresolved.contextStack); - if (keypath !== undefined) { - unresolved.resolve(keypath); - } else { - (leftover || (leftover = [])).push(unresolved); - } - } - if (leftover) { - push.apply(ractive._pendingResolution, leftover); - } - }; - }(shared_resolveRef); -var shared_processDeferredUpdates = function (preDomUpdate, postDomUpdate) { - - return function (ractive) { - preDomUpdate(ractive); - postDomUpdate(ractive); - }; - }(shared_preDomUpdate, shared_postDomUpdate); -var Ractive_prototype_shared_replaceData = function () { - - return function (ractive, keypath, value) { - var keys, accumulated, wrapped, obj, key, currentKeypath, keypathToClear; - keys = keypath.split('.'); - accumulated = []; - if (wrapped = ractive._wrapped['']) { - if (wrapped.set) { - wrapped.set(keys.join('.'), value); - } - obj = wrapped.get(); - } else { - obj = ractive.data; - } - while (keys.length > 1) { - key = accumulated[accumulated.length] = keys.shift(); - currentKeypath = accumulated.join('.'); - if (wrapped = ractive._wrapped[currentKeypath]) { - if (wrapped.set) { - wrapped.set(keys.join('.'), value); - } - obj = wrapped.get(); - } else { - if (!obj.hasOwnProperty(key)) { - if (!keypathToClear) { - keypathToClear = currentKeypath; - } - obj[key] = /^\s*[0-9]+\s*$/.test(keys[0]) ? [] : {}; - } - obj = obj[key]; - } - } - key = keys[0]; - obj[key] = value; - return keypathToClear; - }; - }(); -var Ractive_prototype_set = function (isObject, isEqual, normaliseKeypath, clearCache, notifyDependants, attemptKeypathResolution, makeTransitionManager, processDeferredUpdates, replaceData) { - - var set, updateModel, getUpstreamChanges, resetWrapped; - set = function (keypath, value, complete) { - var map, changes, upstreamChanges, previousTransitionManager, transitionManager, i, changeHash; - changes = []; - if (isObject(keypath)) { - map = keypath; - complete = value; - } - if (map) { - for (keypath in map) { - if (map.hasOwnProperty(keypath)) { - value = map[keypath]; - keypath = normaliseKeypath(keypath); - updateModel(this, keypath, value, changes); - } - } - } else { - keypath = normaliseKeypath(keypath); - updateModel(this, keypath, value, changes); - } - if (!changes.length) { - return; - } - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - upstreamChanges = getUpstreamChanges(changes); - if (upstreamChanges.length) { - notifyDependants.multiple(this, upstreamChanges, true); - } - notifyDependants.multiple(this, changes); - if (this._pendingResolution.length) { - attemptKeypathResolution(this); - } - processDeferredUpdates(this); - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - if (!this.firingChangeEvent) { - this.firingChangeEvent = true; - changeHash = {}; - i = changes.length; - while (i--) { - changeHash[changes[i]] = this.get(changes[i]); - } - this.fire('change', changeHash); - this.firingChangeEvent = false; - } - return this; - }; - updateModel = function (ractive, keypath, value, changes) { - var cached, previous, wrapped, keypathToClear, evaluator; - if ((wrapped = ractive._wrapped[keypath]) && wrapped.reset) { - if (resetWrapped(ractive, keypath, value, wrapped, changes) !== false) { - return; - } - } - if (evaluator = ractive._evaluators[keypath]) { - evaluator.value = value; - } - cached = ractive._cache[keypath]; - previous = ractive.get(keypath); - if (previous !== value && !evaluator) { - keypathToClear = replaceData(ractive, keypath, value); - } else { - if (value === cached && typeof value !== 'object') { - return; - } - } - clearCache(ractive, keypathToClear || keypath); - changes[changes.length] = keypath; - }; - getUpstreamChanges = function (changes) { - var upstreamChanges = [''], i, keypath, keys, upstreamKeypath; - i = changes.length; - while (i--) { - keypath = changes[i]; - keys = keypath.split('.'); - while (keys.length > 1) { - keys.pop(); - upstreamKeypath = keys.join('.'); - if (!upstreamChanges[upstreamKeypath]) { - upstreamChanges[upstreamChanges.length] = upstreamKeypath; - upstreamChanges[upstreamKeypath] = true; - } - } - } - return upstreamChanges; - }; - resetWrapped = function (ractive, keypath, value, wrapped, changes) { - var previous, cached, cacheMap, i; - previous = wrapped.get(); - if (!isEqual(previous, value)) { - if (wrapped.reset(value) === false) { - return false; - } - } - value = wrapped.get(); - cached = ractive._cache[keypath]; - if (!isEqual(cached, value)) { - ractive._cache[keypath] = value; - cacheMap = ractive._cacheMap[keypath]; - if (cacheMap) { - i = cacheMap.length; - while (i--) { - clearCache(ractive, cacheMap[i]); - } - } - changes[changes.length] = keypath; - } - }; - return set; - }(utils_isObject, utils_isEqual, utils_normaliseKeypath, shared_clearCache, shared_notifyDependants, shared_attemptKeypathResolution, shared_makeTransitionManager, shared_processDeferredUpdates, Ractive_prototype_shared_replaceData); -var Ractive_prototype_update = function (makeTransitionManager, attemptKeypathResolution, clearCache, notifyDependants, processDeferredUpdates) { - - return function (keypath, complete) { - var transitionManager, previousTransitionManager; - if (typeof keypath === 'function') { - complete = keypath; - keypath = ''; - } - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - attemptKeypathResolution(this); - clearCache(this, keypath || ''); - notifyDependants(this, keypath || ''); - processDeferredUpdates(this); - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - if (typeof keypath === 'string') { - this.fire('update', keypath); - } else { - this.fire('update'); - } - return this; - }; - }(shared_makeTransitionManager, shared_attemptKeypathResolution, shared_clearCache, shared_notifyDependants, shared_processDeferredUpdates); -var utils_arrayContentsMatch = function (isArray) { - - return function (a, b) { - var i; - if (!isArray(a) || !isArray(b)) { - return false; - } - if (a.length !== b.length) { - return false; - } - i = a.length; - while (i--) { - if (a[i] !== b[i]) { - return false; - } - } - return true; - }; - }(utils_isArray); -var Ractive_prototype_updateModel = function (getValueFromCheckboxes, arrayContentsMatch, isEqual) { - - return function (keypath, cascade) { - var values, deferredCheckboxes, i; - if (typeof keypath !== 'string') { - keypath = ''; - cascade = true; - } - consolidateChangedValues(this, keypath, values = {}, deferredCheckboxes = [], cascade); - if (i = deferredCheckboxes.length) { - while (i--) { - keypath = deferredCheckboxes[i]; - values[keypath] = getValueFromCheckboxes(this, keypath); - } - } - this.set(values); - }; - function consolidateChangedValues(ractive, keypath, values, deferredCheckboxes, cascade) { - var bindings, childDeps, i, binding, oldValue, newValue; - bindings = ractive._twowayBindings[keypath]; - if (bindings) { - i = bindings.length; - while (i--) { - binding = bindings[i]; - if (binding.radioName && !binding.node.checked) { - continue; - } - if (binding.checkboxName) { - if (binding.changed() && !deferredCheckboxes[keypath]) { - deferredCheckboxes[keypath] = true; - deferredCheckboxes[deferredCheckboxes.length] = keypath; - } - continue; - } - oldValue = binding.attr.value; - newValue = binding.value(); - if (arrayContentsMatch(oldValue, newValue)) { - continue; - } - if (!isEqual(oldValue, newValue)) { - values[keypath] = newValue; - } - } - } - if (!cascade) { - return; - } - childDeps = ractive._depsMap[keypath]; - if (childDeps) { - i = childDeps.length; - while (i--) { - consolidateChangedValues(ractive, childDeps[i], values, deferredCheckboxes, cascade); - } - } - } - }(shared_getValueFromCheckboxes, utils_arrayContentsMatch, utils_isEqual); -var Ractive_prototype_animate_requestAnimationFrame = function () { - - if (typeof window === 'undefined') { - return; - } - (function (vendors, lastTime, window) { - var x, setTimeout; - if (window.requestAnimationFrame) { - return; - } - for (x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { - window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']; - } - if (!window.requestAnimationFrame) { - setTimeout = window.setTimeout; - window.requestAnimationFrame = function (callback) { - var currTime, timeToCall, id; - currTime = Date.now(); - timeToCall = Math.max(0, 16 - (currTime - lastTime)); - id = setTimeout(function () { - callback(currTime + timeToCall); - }, timeToCall); - lastTime = currTime + timeToCall; - return id; - }; - } - }([ - 'ms', - 'moz', - 'webkit', - 'o' - ], 0, window)); - return window.requestAnimationFrame; - }(); -var Ractive_prototype_animate_animations = function (rAF) { - - var queue = []; - var animations = { - tick: function () { - var i, animation; - for (i = 0; i < queue.length; i += 1) { - animation = queue[i]; - if (!animation.tick()) { - queue.splice(i--, 1); - } - } - if (queue.length) { - rAF(animations.tick); - } else { - animations.running = false; - } - }, - add: function (animation) { - queue[queue.length] = animation; - if (!animations.running) { - animations.running = true; - animations.tick(); - } - }, - abort: function (keypath, root) { - var i = queue.length, animation; - while (i--) { - animation = queue[i]; - if (animation.root === root && animation.keypath === keypath) { - animation.stop(); - } - } - } - }; - return animations; - }(Ractive_prototype_animate_requestAnimationFrame); -var utils_warn = function () { - - if (typeof console !== 'undefined' && typeof console.warn === 'function' && typeof console.warn.apply === 'function') { - return function () { - console.warn.apply(console, arguments); - }; - } - return function () { - }; - }(); -var utils_isNumeric = function () { - - return function (thing) { - return !isNaN(parseFloat(thing)) && isFinite(thing); - }; - }(); -var shared_interpolate = function (isArray, isObject, isNumeric) { - - var interpolate = function (from, to) { - if (isNumeric(from) && isNumeric(to)) { - return makeNumberInterpolator(+from, +to); - } - if (isArray(from) && isArray(to)) { - return makeArrayInterpolator(from, to); - } - if (isObject(from) && isObject(to)) { - return makeObjectInterpolator(from, to); - } - return function () { - return to; - }; - }; - return interpolate; - function makeNumberInterpolator(from, to) { - var delta = to - from; - if (!delta) { - return function () { - return from; - }; - } - return function (t) { - return from + t * delta; - }; - } - function makeArrayInterpolator(from, to) { - var intermediate, interpolators, len, i; - intermediate = []; - interpolators = []; - i = len = Math.min(from.length, to.length); - while (i--) { - interpolators[i] = interpolate(from[i], to[i]); - } - for (i = len; i < from.length; i += 1) { - intermediate[i] = from[i]; - } - for (i = len; i < to.length; i += 1) { - intermediate[i] = to[i]; - } - return function (t) { - var i = len; - while (i--) { - intermediate[i] = interpolators[i](t); - } - return intermediate; - }; - } - function makeObjectInterpolator(from, to) { - var properties = [], len, interpolators, intermediate, prop; - intermediate = {}; - interpolators = {}; - for (prop in from) { - if (from.hasOwnProperty(prop)) { - if (to.hasOwnProperty(prop)) { - properties[properties.length] = prop; - interpolators[prop] = interpolate(from[prop], to[prop]); - } else { - intermediate[prop] = from[prop]; - } - } - } - for (prop in to) { - if (to.hasOwnProperty(prop) && !from.hasOwnProperty(prop)) { - intermediate[prop] = to[prop]; - } - } - len = properties.length; - return function (t) { - var i = len, prop; - while (i--) { - prop = properties[i]; - intermediate[prop] = interpolators[prop](t); - } - return intermediate; - }; - } - }(utils_isArray, utils_isObject, utils_isNumeric); -var Ractive_prototype_animate_Animation = function (warn, interpolate) { - - var Animation = function (options) { - var key; - this.startTime = Date.now(); - for (key in options) { - if (options.hasOwnProperty(key)) { - this[key] = options[key]; - } - } - this.interpolator = interpolate(this.from, this.to); - this.running = true; - }; - Animation.prototype = { - tick: function () { - var elapsed, t, value, timeNow, index, keypath; - keypath = this.keypath; - if (this.running) { - timeNow = Date.now(); - elapsed = timeNow - this.startTime; - if (elapsed >= this.duration) { - if (keypath !== null) { - this.root.set(keypath, this.to); - } - if (this.step) { - this.step(1, this.to); - } - if (this.complete) { - this.complete(1, this.to); - } - index = this.root._animations.indexOf(this); - if (index === -1) { - warn('Animation was not found'); - } - this.root._animations.splice(index, 1); - this.running = false; - return false; - } - t = this.easing ? this.easing(elapsed / this.duration) : elapsed / this.duration; - if (keypath !== null) { - value = this.interpolator(t); - this.root.set(keypath, value); - } - if (this.step) { - this.step(t, value); - } - return true; - } - return false; - }, - stop: function () { - var index; - this.running = false; - index = this.root._animations.indexOf(this); - if (index === -1) { - warn('Animation was not found'); - } - this.root._animations.splice(index, 1); - } - }; - return Animation; - }(utils_warn, shared_interpolate); -var registries_easing = function () { - - return { - linear: function (pos) { - return pos; - }, - easeIn: function (pos) { - return Math.pow(pos, 3); - }, - easeOut: function (pos) { - return Math.pow(pos - 1, 3) + 1; - }, - easeInOut: function (pos) { - if ((pos /= 0.5) < 1) { - return 0.5 * Math.pow(pos, 3); - } - return 0.5 * (Math.pow(pos - 2, 3) + 2); - } - }; - }(); -var Ractive_prototype_animate__animate = function (isEqual, animations, Animation, easingRegistry) { - - var noAnimation = { - stop: function () { - } - }; - return function (keypath, to, options) { - var k, animation, animations, easing, duration, step, complete, makeValueCollector, currentValues, collectValue, dummy, dummyOptions; - if (typeof keypath === 'object') { - options = to || {}; - easing = options.easing; - duration = options.duration; - animations = []; - step = options.step; - complete = options.complete; - if (step || complete) { - currentValues = {}; - options.step = null; - options.complete = null; - makeValueCollector = function (keypath) { - return function (t, value) { - currentValues[keypath] = value; - }; - }; - } - for (k in keypath) { - if (keypath.hasOwnProperty(k)) { - if (step || complete) { - collectValue = makeValueCollector(k); - options = { - easing: easing, - duration: duration - }; - if (step) { - options.step = collectValue; - } - if (complete) { - options.complete = collectValue; - } - } - animations[animations.length] = animate(this, k, keypath[k], options); - } - } - if (step || complete) { - dummyOptions = { - easing: easing, - duration: duration - }; - if (step) { - dummyOptions.step = function (t) { - step(t, currentValues); - }; - } - if (complete) { - dummyOptions.complete = function (t) { - complete(t, currentValues); - }; - } - animations[animations.length] = dummy = animate(this, null, null, dummyOptions); - } - return { - stop: function () { - while (animations.length) { - animations.pop().stop(); - } - if (dummy) { - dummy.stop(); - } - } - }; - } - options = options || {}; - animation = animate(this, keypath, to, options); - return { - stop: function () { - animation.stop(); - } - }; - }; - function animate(root, keypath, to, options) { - var easing, duration, animation, from; - if (keypath !== null) { - from = root.get(keypath); - } - animations.abort(keypath, root); - if (isEqual(from, to)) { - if (options.complete) { - options.complete(1, options.to); - } - return noAnimation; - } - if (options.easing) { - if (typeof options.easing === 'function') { - easing = options.easing; - } else { - if (root.easing && root.easing[options.easing]) { - easing = root.easing[options.easing]; - } else { - easing = easingRegistry[options.easing]; - } - } - if (typeof easing !== 'function') { - easing = null; - } - } - duration = options.duration === undefined ? 400 : options.duration; - animation = new Animation({ - keypath: keypath, - from: from, - to: to, - root: root, - duration: duration, - easing: easing, - step: options.step, - complete: options.complete - }); - animations.add(animation); - root._animations[root._animations.length] = animation; - return animation; - } - }(utils_isEqual, Ractive_prototype_animate_animations, Ractive_prototype_animate_Animation, registries_easing); -var Ractive_prototype_on = function () { - - return function (eventName, callback) { - var self = this, listeners, n; - if (typeof eventName === 'object') { - listeners = []; - for (n in eventName) { - if (eventName.hasOwnProperty(n)) { - listeners[listeners.length] = this.on(n, eventName[n]); - } - } - return { - cancel: function () { - while (listeners.length) { - listeners.pop().cancel(); - } - } - }; - } - if (!this._subs[eventName]) { - this._subs[eventName] = [callback]; - } else { - this._subs[eventName].push(callback); - } - return { - cancel: function () { - self.off(eventName, callback); - } - }; - }; - }(); -var Ractive_prototype_off = function () { - - return function (eventName, callback) { - var subscribers, index; - if (!callback) { - if (!eventName) { - for (eventName in this._subs) { - delete this._subs[eventName]; - } - } else { - this._subs[eventName] = []; - } - } - subscribers = this._subs[eventName]; - if (subscribers) { - index = subscribers.indexOf(callback); - if (index !== -1) { - subscribers.splice(index, 1); - } - } - }; - }(); -var shared_registerDependant = function () { - - return function (dependant) { - var depsByKeypath, deps, keys, parentKeypath, map, ractive, keypath, priority; - ractive = dependant.root; - keypath = dependant.keypath; - priority = dependant.priority; - depsByKeypath = ractive._deps[priority] || (ractive._deps[priority] = {}); - deps = depsByKeypath[keypath] || (depsByKeypath[keypath] = []); - deps[deps.length] = dependant; - dependant.registered = true; - if (!keypath) { - return; - } - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - parentKeypath = keys.join('.'); - map = ractive._depsMap[parentKeypath] || (ractive._depsMap[parentKeypath] = []); - if (map[keypath] === undefined) { - map[keypath] = 0; - map[map.length] = keypath; - } - map[keypath] += 1; - keypath = parentKeypath; - } - }; - }(); -var shared_unregisterDependant = function () { - - return function (dependant) { - var deps, index, keys, parentKeypath, map, ractive, keypath, priority; - ractive = dependant.root; - keypath = dependant.keypath; - priority = dependant.priority; - deps = ractive._deps[priority][keypath]; - index = deps.indexOf(dependant); - if (index === -1 || !dependant.registered) { - throw new Error('Attempted to remove a dependant that was no longer registered! This should not happen. If you are seeing this bug in development please raise an issue at https://github.com/RactiveJS/Ractive/issues - thanks'); - } - deps.splice(index, 1); - dependant.registered = false; - if (!keypath) { - return; - } - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - parentKeypath = keys.join('.'); - map = ractive._depsMap[parentKeypath]; - map[keypath] -= 1; - if (!map[keypath]) { - map.splice(map.indexOf(keypath), 1); - map[keypath] = undefined; - } - keypath = parentKeypath; - } - }; - }(); -var Ractive_prototype_observe_Observer = function (isEqual) { - - var Observer = function (ractive, keypath, callback, options) { - var self = this; - this.root = ractive; - this.keypath = keypath; - this.callback = callback; - this.defer = options.defer; - this.debug = options.debug; - this.proxy = { - update: function () { - self.reallyUpdate(); - } - }; - this.priority = 0; - this.context = options && options.context ? options.context : ractive; - }; - Observer.prototype = { - init: function (immediate) { - if (immediate !== false) { - this.update(); - } else { - this.value = this.root.get(this.keypath); - } - }, - update: function () { - if (this.defer && this.ready) { - this.root._deferred.observers.push(this.proxy); - return; - } - this.reallyUpdate(); - }, - reallyUpdate: function () { - var oldValue, newValue; - oldValue = this.value; - newValue = this.root.get(this.keypath); - this.value = newValue; - if (this.updating) { - return; - } - this.updating = true; - if (!isEqual(newValue, oldValue) || !this.ready) { - try { - this.callback.call(this.context, newValue, oldValue, this.keypath); - } catch (err) { - if (this.debug || this.root.debug) { - throw err; - } - } - } - this.updating = false; - } - }; - return Observer; - }(utils_isEqual); -var Ractive_prototype_observe_getPattern = function () { - - return function (ractive, pattern) { - var keys, key, values, toGet, newToGet, expand, concatenate; - keys = pattern.split('.'); - toGet = []; - expand = function (keypath) { - var value, key; - value = ractive._wrapped[keypath] ? ractive._wrapped[keypath].get() : ractive.get(keypath); - for (key in value) { - newToGet.push(keypath + '.' + key); - } - }; - concatenate = function (keypath) { - return keypath + '.' + key; - }; - while (key = keys.shift()) { - if (key === '*') { - newToGet = []; - toGet.forEach(expand); - toGet = newToGet; - } else { - if (!toGet[0]) { - toGet[0] = key; - } else { - toGet = toGet.map(concatenate); - } - } - } - values = {}; - toGet.forEach(function (keypath) { - values[keypath] = ractive.get(keypath); - }); - return values; - }; - }(); -var Ractive_prototype_observe_PatternObserver = function (isEqual, getPattern) { - - var PatternObserver, wildcard = /\*/; - PatternObserver = function (ractive, keypath, callback, options) { - this.root = ractive; - this.callback = callback; - this.defer = options.defer; - this.debug = options.debug; - this.keypath = keypath; - this.regex = new RegExp('^' + keypath.replace(/\./g, '\\.').replace(/\*/g, '[^\\.]+') + '$'); - this.values = {}; - if (this.defer) { - this.proxies = []; - } - this.priority = 'pattern'; - this.context = options && options.context ? options.context : ractive; - }; - PatternObserver.prototype = { - init: function (immediate) { - var values, keypath; - values = getPattern(this.root, this.keypath); - if (immediate !== false) { - for (keypath in values) { - if (values.hasOwnProperty(keypath)) { - this.update(keypath); - } - } - } else { - this.values = values; - } - }, - update: function (keypath) { - var values; - if (wildcard.test(keypath)) { - values = getPattern(this.root, keypath); - for (keypath in values) { - if (values.hasOwnProperty(keypath)) { - this.update(keypath); - } - } - return; - } - if (this.defer && this.ready) { - this.root._deferred.observers.push(this.getProxy(keypath)); - return; - } - this.reallyUpdate(keypath); - }, - reallyUpdate: function (keypath) { - var value = this.root.get(keypath); - if (this.updating) { - this.values[keypath] = value; - return; - } - this.updating = true; - if (!isEqual(value, this.values[keypath]) || !this.ready) { - try { - this.callback.call(this.context, value, this.values[keypath], keypath); - } catch (err) { - if (this.debug || this.root.debug) { - throw err; - } - } - this.values[keypath] = value; - } - this.updating = false; - }, - getProxy: function (keypath) { - var self = this; - if (!this.proxies[keypath]) { - this.proxies[keypath] = { - update: function () { - self.reallyUpdate(keypath); - } - }; - } - return this.proxies[keypath]; - } - }; - return PatternObserver; - }(utils_isEqual, Ractive_prototype_observe_getPattern); -var Ractive_prototype_observe_getObserverFacade = function (normaliseKeypath, registerDependant, unregisterDependant, Observer, PatternObserver) { - - var wildcard = /\*/, emptyObject = {}; - return function getObserverFacade(ractive, keypath, callback, options) { - var observer, isPatternObserver; - keypath = normaliseKeypath(keypath); - options = options || emptyObject; - if (wildcard.test(keypath)) { - observer = new PatternObserver(ractive, keypath, callback, options); - ractive._patternObservers.push(observer); - isPatternObserver = true; - } else { - observer = new Observer(ractive, keypath, callback, options); - } - registerDependant(observer); - observer.init(options.init); - observer.ready = true; - return { - cancel: function () { - var index; - if (isPatternObserver) { - index = ractive._patternObservers.indexOf(observer); - if (index !== -1) { - ractive._patternObservers.splice(index, 1); - } - } - unregisterDependant(observer); - } - }; - }; - }(utils_normaliseKeypath, shared_registerDependant, shared_unregisterDependant, Ractive_prototype_observe_Observer, Ractive_prototype_observe_PatternObserver); -var Ractive_prototype_observe__observe = function (isObject, getObserverFacade) { - - return function observe(keypath, callback, options) { - var observers = [], k; - if (isObject(keypath)) { - options = callback; - for (k in keypath) { - if (keypath.hasOwnProperty(k)) { - callback = keypath[k]; - observers[observers.length] = getObserverFacade(this, k, callback, options); - } - } - return { - cancel: function () { - while (observers.length) { - observers.pop().cancel(); - } - } - }; - } - return getObserverFacade(this, keypath, callback, options); - }; - }(utils_isObject, Ractive_prototype_observe_getObserverFacade); -var Ractive_prototype_fire = function () { - - return function (eventName) { - var args, i, len, subscribers = this._subs[eventName]; - if (!subscribers) { - return; - } - args = Array.prototype.slice.call(arguments, 1); - for (i = 0, len = subscribers.length; i < len; i += 1) { - subscribers[i].apply(this, args); - } - }; - }(); -var Ractive_prototype_find = function () { - - return function (selector) { - if (!this.el) { - return null; - } - return this.fragment.find(selector); - }; - }(); -var utils_matches = function (isClient, createElement) { - - var div, methodNames, unprefixed, prefixed, vendors, i, j, makeFunction; - if (!isClient) { - return; - } - div = createElement('div'); - methodNames = [ - 'matches', - 'matchesSelector' - ]; - vendors = [ - 'o', - 'ms', - 'moz', - 'webkit' - ]; - makeFunction = function (methodName) { - return function (node, selector) { - return node[methodName](selector); - }; - }; - i = methodNames.length; - while (i--) { - unprefixed = methodNames[i]; - if (div[unprefixed]) { - return makeFunction(unprefixed); - } - j = vendors.length; - while (j--) { - prefixed = vendors[i] + unprefixed.substr(0, 1).toUpperCase() + unprefixed.substring(1); - if (div[prefixed]) { - return makeFunction(prefixed); - } - } - } - return function (node, selector) { - var nodes, i; - nodes = (node.parentNode || node.document).querySelectorAll(selector); - i = nodes.length; - while (i--) { - if (nodes[i] === node) { - return true; - } - } - return false; - }; - }(config_isClient, utils_createElement); -var Ractive_prototype_shared_makeQuery_test = function (matches) { - - return function (item, noDirty) { - var itemMatches = this._isComponentQuery ? !this.selector || item.name === this.selector : matches(item.node, this.selector); - if (itemMatches) { - this.push(item.node || item.instance); - if (!noDirty) { - this._makeDirty(); - } - return true; - } - }; - }(utils_matches); -var Ractive_prototype_shared_makeQuery_cancel = function () { - - return function () { - var liveQueries, selector, index; - liveQueries = this._root[this._isComponentQuery ? 'liveComponentQueries' : 'liveQueries']; - selector = this.selector; - index = liveQueries.indexOf(selector); - if (index !== -1) { - liveQueries.splice(index, 1); - liveQueries[selector] = null; - } - }; - }(); -var Ractive_prototype_shared_makeQuery_sortByItemPosition = function () { - - return function (a, b) { - var ancestryA, ancestryB, oldestA, oldestB, mutualAncestor, indexA, indexB, fragments, fragmentA, fragmentB; - ancestryA = getAncestry(a.component || a._ractive.proxy); - ancestryB = getAncestry(b.component || b._ractive.proxy); - oldestA = ancestryA[ancestryA.length - 1]; - oldestB = ancestryB[ancestryB.length - 1]; - while (oldestA && oldestA === oldestB) { - ancestryA.pop(); - ancestryB.pop(); - mutualAncestor = oldestA; - oldestA = ancestryA[ancestryA.length - 1]; - oldestB = ancestryB[ancestryB.length - 1]; - } - oldestA = oldestA.component || oldestA; - oldestB = oldestB.component || oldestB; - fragmentA = oldestA.parentFragment; - fragmentB = oldestB.parentFragment; - if (fragmentA === fragmentB) { - indexA = fragmentA.items.indexOf(oldestA); - indexB = fragmentB.items.indexOf(oldestB); - return indexA - indexB || ancestryA.length - ancestryB.length; - } - if (fragments = mutualAncestor.fragments) { - indexA = fragments.indexOf(fragmentA); - indexB = fragments.indexOf(fragmentB); - return indexA - indexB || ancestryA.length - ancestryB.length; - } - throw new Error('An unexpected condition was met while comparing the position of two components. Please file an issue at https://github.com/RactiveJS/Ractive/issues - thanks!'); - }; - function getParent(item) { - var parentFragment; - if (parentFragment = item.parentFragment) { - return parentFragment.owner; - } - if (item.component && (parentFragment = item.component.parentFragment)) { - return parentFragment.owner; - } - } - function getAncestry(item) { - var ancestry, ancestor; - ancestry = [item]; - ancestor = getParent(item); - while (ancestor) { - ancestry.push(ancestor); - ancestor = getParent(ancestor); - } - return ancestry; - } - }(); -var Ractive_prototype_shared_makeQuery_sortByDocumentPosition = function (sortByItemPosition) { - - return function (node, otherNode) { - var bitmask; - if (node.compareDocumentPosition) { - bitmask = node.compareDocumentPosition(otherNode); - return bitmask & 2 ? 1 : -1; - } - return sortByItemPosition(node, otherNode); - }; - }(Ractive_prototype_shared_makeQuery_sortByItemPosition); -var Ractive_prototype_shared_makeQuery_sort = function (sortByDocumentPosition, sortByItemPosition) { - - return function () { - this.sort(this._isComponentQuery ? sortByItemPosition : sortByDocumentPosition); - this._dirty = false; - }; - }(Ractive_prototype_shared_makeQuery_sortByDocumentPosition, Ractive_prototype_shared_makeQuery_sortByItemPosition); -var Ractive_prototype_shared_makeQuery_dirty = function () { - - return function () { - if (!this._dirty) { - this._root._deferred.liveQueries.push(this); - this._dirty = true; - } - }; - }(); -var Ractive_prototype_shared_makeQuery_remove = function () { - - return function (item) { - var index = this.indexOf(this._isComponentQuery ? item.instance : item.node); - if (index !== -1) { - this.splice(index, 1); - } - }; - }(); -var Ractive_prototype_shared_makeQuery__makeQuery = function (defineProperties, test, cancel, sort, dirty, remove) { - - return function (ractive, selector, live, isComponentQuery) { - var query; - query = []; - defineProperties(query, { - selector: { value: selector }, - live: { value: live }, - _isComponentQuery: { value: isComponentQuery }, - _test: { value: test } - }); - if (!live) { - return query; - } - defineProperties(query, { - cancel: { value: cancel }, - _root: { value: ractive }, - _sort: { value: sort }, - _makeDirty: { value: dirty }, - _remove: { value: remove }, - _dirty: { - value: false, - writable: true - } - }); - return query; - }; - }(utils_defineProperties, Ractive_prototype_shared_makeQuery_test, Ractive_prototype_shared_makeQuery_cancel, Ractive_prototype_shared_makeQuery_sort, Ractive_prototype_shared_makeQuery_dirty, Ractive_prototype_shared_makeQuery_remove); -var Ractive_prototype_findAll = function (warn, matches, defineProperties, makeQuery) { - - return function (selector, options) { - var liveQueries, query; - if (!this.el) { - return []; - } - options = options || {}; - liveQueries = this._liveQueries; - if (query = liveQueries[selector]) { - return options && options.live ? query : query.slice(); - } - query = makeQuery(this, selector, !!options.live, false); - if (query.live) { - liveQueries.push(selector); - liveQueries[selector] = query; - } - this.fragment.findAll(selector, query); - return query; - }; - }(utils_warn, utils_matches, utils_defineProperties, Ractive_prototype_shared_makeQuery__makeQuery); -var Ractive_prototype_findComponent = function () { - - return function (selector) { - return this.fragment.findComponent(selector); - }; - }(); -var Ractive_prototype_findAllComponents = function (warn, matches, defineProperties, makeQuery) { - - return function (selector, options) { - var liveQueries, query; - options = options || {}; - liveQueries = this._liveComponentQueries; - if (query = liveQueries[selector]) { - return options && options.live ? query : query.slice(); - } - query = makeQuery(this, selector, !!options.live, true); - if (query.live) { - liveQueries.push(selector); - liveQueries[selector] = query; - } - this.fragment.findAllComponents(selector, query); - return query; - }; - }(utils_warn, utils_matches, utils_defineProperties, Ractive_prototype_shared_makeQuery__makeQuery); -var utils_getElement = function () { - - return function (input) { - var output; - if (typeof window === 'undefined' || !document || !input) { - return null; - } - if (input.nodeType) { - return input; - } - if (typeof input === 'string') { - output = document.getElementById(input); - if (!output && document.querySelector) { - output = document.querySelector(input); - } - if (output && output.nodeType) { - return output; - } - } - if (input[0] && input[0].nodeType) { - return input[0]; - } - return null; - }; - }(); -var render_shared_initFragment = function (types, create) { - - return function (fragment, options) { - var numItems, i, parentFragment, parentRefs, ref; - fragment.owner = options.owner; - parentFragment = fragment.owner.parentFragment; - fragment.root = options.root; - fragment.pNode = options.pNode; - fragment.contextStack = options.contextStack || []; - if (fragment.owner.type === types.SECTION) { - fragment.index = options.index; - } - if (parentFragment) { - parentRefs = parentFragment.indexRefs; - if (parentRefs) { - fragment.indexRefs = create(null); - for (ref in parentRefs) { - fragment.indexRefs[ref] = parentRefs[ref]; - } - } - } - fragment.priority = parentFragment ? parentFragment.priority + 1 : 1; - if (options.indexRef) { - if (!fragment.indexRefs) { - fragment.indexRefs = {}; - } - fragment.indexRefs[options.indexRef] = options.index; - } - fragment.items = []; - numItems = options.descriptor ? options.descriptor.length : 0; - for (i = 0; i < numItems; i += 1) { - fragment.items[fragment.items.length] = fragment.createItem({ - parentFragment: fragment, - descriptor: options.descriptor[i], - index: i - }); - } - }; - }(config_types, utils_create); -var render_DomFragment_shared_insertHtml = function (createElement) { - - var elementCache = {}; - return function (html, tagName, docFrag) { - var container, nodes = []; - if (html) { - container = elementCache[tagName] || (elementCache[tagName] = createElement(tagName)); - container.innerHTML = html; - while (container.firstChild) { - nodes[nodes.length] = container.firstChild; - docFrag.appendChild(container.firstChild); - } - } - return nodes; - }; - }(utils_createElement); -var render_DomFragment_Text = function (types) { - - var DomText, lessThan, greaterThan; - lessThan = //g; - DomText = function (options, docFrag) { - this.type = types.TEXT; - this.descriptor = options.descriptor; - if (docFrag) { - this.node = document.createTextNode(options.descriptor); - docFrag.appendChild(this.node); - } - }; - DomText.prototype = { - detach: function () { - this.node.parentNode.removeChild(this.node); - return this.node; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - } - }, - firstNode: function () { - return this.node; - }, - toString: function () { - return ('' + this.descriptor).replace(lessThan, '<').replace(greaterThan, '>'); - } - }; - return DomText; - }(config_types); -var shared_teardown = function (unregisterDependant) { - - return function (thing) { - if (!thing.keypath) { - var index = thing.root._pendingResolution.indexOf(thing); - if (index !== -1) { - thing.root._pendingResolution.splice(index, 1); - } - } else { - unregisterDependant(thing); - } - }; - }(shared_unregisterDependant); -var render_shared_Evaluator_Reference = function (types, isEqual, defineProperty, registerDependant, unregisterDependant) { - - var Reference, thisPattern; - thisPattern = /this/; - Reference = function (root, keypath, evaluator, argNum, priority) { - var value; - this.evaluator = evaluator; - this.keypath = keypath; - this.root = root; - this.argNum = argNum; - this.type = types.REFERENCE; - this.priority = priority; - value = root.get(keypath); - if (typeof value === 'function') { - value = wrapFunction(value, root, evaluator); - } - this.value = evaluator.values[argNum] = value; - registerDependant(this); - }; - Reference.prototype = { - update: function () { - var value = this.root.get(this.keypath); - if (typeof value === 'function' && !value._nowrap) { - value = wrapFunction(value, this.root, this.evaluator); - } - if (!isEqual(value, this.value)) { - this.evaluator.values[this.argNum] = value; - this.evaluator.bubble(); - this.value = value; - } - }, - teardown: function () { - unregisterDependant(this); - } - }; - return Reference; - function wrapFunction(fn, ractive, evaluator) { - var prop, evaluators, index; - if (!thisPattern.test(fn.toString())) { - defineProperty(fn, '_nowrap', { value: true }); - return fn; - } - if (!fn['_' + ractive._guid]) { - defineProperty(fn, '_' + ractive._guid, { - value: function () { - var originalCaptured, result, i, evaluator; - originalCaptured = ractive._captured; - if (!originalCaptured) { - ractive._captured = []; - } - result = fn.apply(ractive, arguments); - if (ractive._captured.length) { - i = evaluators.length; - while (i--) { - evaluator = evaluators[i]; - evaluator.updateSoftDependencies(ractive._captured); - } - } - ractive._captured = originalCaptured; - return result; - }, - writable: true - }); - for (prop in fn) { - if (fn.hasOwnProperty(prop)) { - fn['_' + ractive._guid][prop] = fn[prop]; - } - } - fn['_' + ractive._guid + '_evaluators'] = []; - } - evaluators = fn['_' + ractive._guid + '_evaluators']; - index = evaluators.indexOf(evaluator); - if (index === -1) { - evaluators.push(evaluator); - } - return fn['_' + ractive._guid]; - } - }(config_types, utils_isEqual, utils_defineProperty, shared_registerDependant, shared_unregisterDependant); -var render_shared_Evaluator_SoftReference = function (isEqual, registerDependant, unregisterDependant) { - - var SoftReference = function (root, keypath, evaluator) { - this.root = root; - this.keypath = keypath; - this.priority = evaluator.priority; - this.evaluator = evaluator; - registerDependant(this); - }; - SoftReference.prototype = { - update: function () { - var value = this.root.get(this.keypath); - if (!isEqual(value, this.value)) { - this.evaluator.bubble(); - this.value = value; - } - }, - teardown: function () { - unregisterDependant(this); - } - }; - return SoftReference; - }(utils_isEqual, shared_registerDependant, shared_unregisterDependant); -var render_shared_Evaluator__Evaluator = function (isEqual, defineProperty, clearCache, notifyDependants, registerDependant, unregisterDependant, adaptIfNecessary, Reference, SoftReference) { - - var Evaluator, cache = {}; - Evaluator = function (root, keypath, functionStr, args, priority) { - var i, arg; - this.root = root; - this.keypath = keypath; - this.priority = priority; - this.fn = getFunctionFromString(functionStr, args.length); - this.values = []; - this.refs = []; - i = args.length; - while (i--) { - if (arg = args[i]) { - if (arg[0]) { - this.values[i] = arg[1]; - } else { - this.refs[this.refs.length] = new Reference(root, arg[1], this, i, priority); - } - } else { - this.values[i] = undefined; - } - } - this.selfUpdating = this.refs.length <= 1; - this.update(); - }; - Evaluator.prototype = { - bubble: function () { - if (this.selfUpdating) { - this.update(); - } else if (!this.deferred) { - this.root._deferred.evals.push(this); - this.deferred = true; - } - }, - update: function () { - var value; - if (this.evaluating) { - return this; - } - this.evaluating = true; - try { - value = this.fn.apply(null, this.values); - } catch (err) { - if (this.root.debug) { - throw err; - } else { - value = undefined; - } - } - if (!isEqual(value, this.value)) { - clearCache(this.root, this.keypath); - this.root._cache[this.keypath] = value; - adaptIfNecessary(this.root, this.keypath, value, true); - this.value = value; - notifyDependants(this.root, this.keypath); - } - this.evaluating = false; - return this; - }, - teardown: function () { - while (this.refs.length) { - this.refs.pop().teardown(); - } - clearCache(this.root, this.keypath); - this.root._evaluators[this.keypath] = null; - }, - refresh: function () { - if (!this.selfUpdating) { - this.deferred = true; - } - var i = this.refs.length; - while (i--) { - this.refs[i].update(); - } - if (this.deferred) { - this.update(); - this.deferred = false; - } - }, - updateSoftDependencies: function (softDeps) { - var i, keypath, ref; - if (!this.softRefs) { - this.softRefs = []; - } - i = this.softRefs.length; - while (i--) { - ref = this.softRefs[i]; - if (!softDeps[ref.keypath]) { - this.softRefs.splice(i, 1); - this.softRefs[ref.keypath] = false; - ref.teardown(); - } - } - i = softDeps.length; - while (i--) { - keypath = softDeps[i]; - if (!this.softRefs[keypath]) { - ref = new SoftReference(this.root, keypath, this); - this.softRefs[this.softRefs.length] = ref; - this.softRefs[keypath] = true; - } - } - this.selfUpdating = this.refs.length + this.softRefs.length <= 1; - } - }; - return Evaluator; - function getFunctionFromString(str, i) { - var fn, args; - str = str.replace(/\$\{([0-9]+)\}/g, '_$1'); - if (cache[str]) { - return cache[str]; - } - args = []; - while (i--) { - args[i] = '_' + i; - } - fn = new Function(args.join(','), 'return(' + str + ')'); - cache[str] = fn; - return fn; - } - }(utils_isEqual, utils_defineProperty, shared_clearCache, shared_notifyDependants, shared_registerDependant, shared_unregisterDependant, shared_adaptIfNecessary, render_shared_Evaluator_Reference, render_shared_Evaluator_SoftReference); -var render_shared_ExpressionResolver_ReferenceScout = function (resolveRef, teardown) { - - var ReferenceScout = function (resolver, ref, contextStack, argNum) { - var keypath, root; - root = this.root = resolver.root; - keypath = resolveRef(root, ref, contextStack); - if (keypath !== undefined) { - resolver.resolveRef(argNum, false, keypath); - } else { - this.ref = ref; - this.argNum = argNum; - this.resolver = resolver; - this.contextStack = contextStack; - root._pendingResolution[root._pendingResolution.length] = this; - } - }; - ReferenceScout.prototype = { - resolve: function (keypath) { - this.keypath = keypath; - this.resolver.resolveRef(this.argNum, false, keypath); - }, - teardown: function () { - if (!this.keypath) { - teardown(this); - } - } - }; - return ReferenceScout; - }(shared_resolveRef, shared_teardown); -var render_shared_ExpressionResolver_isRegularKeypath = function () { - - var keyPattern = /^(?:(?:[a-zA-Z$_][a-zA-Z$_0-9]*)|(?:[0-9]|[1-9][0-9]+))$/; - return function (keypath) { - var keys, key, i; - keys = keypath.split('.'); - i = keys.length; - while (i--) { - key = keys[i]; - if (key === 'undefined' || !keyPattern.test(key)) { - return false; - } - } - return true; - }; - }(); -var render_shared_ExpressionResolver_getKeypath = function (normaliseKeypath, isRegularKeypath) { - - return function (str, args) { - var unique, normalised; - unique = str.replace(/\$\{([0-9]+)\}/g, function (match, $1) { - return args[$1] ? args[$1][1] : 'undefined'; - }); - normalised = normaliseKeypath(unique); - if (isRegularKeypath(normalised)) { - return normalised; - } - return '${' + unique.replace(/[\.\[\]]/g, '-') + '}'; - }; - }(utils_normaliseKeypath, render_shared_ExpressionResolver_isRegularKeypath); -var render_shared_ExpressionResolver_reassignDependants = function (registerDependant, unregisterDependant) { - - return function (ractive, oldKeypath, newKeypath) { - var toReassign, i, dependant; - toReassign = []; - gatherDependants(ractive, oldKeypath, toReassign); - i = toReassign.length; - while (i--) { - dependant = toReassign[i]; - unregisterDependant(dependant); - dependant.keypath = dependant.keypath.replace(oldKeypath, newKeypath); - registerDependant(dependant); - dependant.update(); - } - }; - function cascade(ractive, oldKeypath, toReassign) { - var map, i; - map = ractive._depsMap[oldKeypath]; - if (!map) { - return; - } - i = map.length; - while (i--) { - gatherDependants(ractive, map[i], toReassign); - } - } - function gatherDependants(ractive, oldKeypath, toReassign) { - var priority, dependantsByKeypath, dependants, i; - priority = ractive._deps.length; - while (priority--) { - dependantsByKeypath = ractive._deps[priority]; - if (dependantsByKeypath) { - dependants = dependantsByKeypath[oldKeypath]; - if (dependants) { - i = dependants.length; - while (i--) { - toReassign.push(dependants[i]); - } - } - } - } - cascade(ractive, oldKeypath, toReassign); - } - }(shared_registerDependant, shared_unregisterDependant); -var render_shared_ExpressionResolver__ExpressionResolver = function (Evaluator, ReferenceScout, getKeypath, reassignDependants) { - - var ExpressionResolver = function (mustache) { - var expression, i, len, ref, indexRefs; - this.root = mustache.root; - this.mustache = mustache; - this.args = []; - this.scouts = []; - expression = mustache.descriptor.x; - indexRefs = mustache.parentFragment.indexRefs; - this.str = expression.s; - len = this.unresolved = this.args.length = expression.r ? expression.r.length : 0; - if (!len) { - this.resolved = this.ready = true; - this.bubble(); - return; - } - for (i = 0; i < len; i += 1) { - ref = expression.r[i]; - if (indexRefs && indexRefs[ref] !== undefined) { - this.resolveRef(i, true, indexRefs[ref]); - } else { - this.scouts[this.scouts.length] = new ReferenceScout(this, ref, mustache.contextStack, i); - } - } - this.ready = true; - this.bubble(); - }; - ExpressionResolver.prototype = { - bubble: function () { - var oldKeypath; - if (!this.ready) { - return; - } - oldKeypath = this.keypath; - this.keypath = getKeypath(this.str, this.args); - if (this.keypath.substr(0, 2) === '${') { - this.createEvaluator(); - } - if (oldKeypath) { - reassignDependants(this.root, oldKeypath, this.keypath); - } else { - this.mustache.resolve(this.keypath); - } - }, - teardown: function () { - while (this.scouts.length) { - this.scouts.pop().teardown(); - } - }, - resolveRef: function (argNum, isIndexRef, value) { - this.args[argNum] = [ - isIndexRef, - value - ]; - this.bubble(); - this.resolved = !--this.unresolved; - }, - createEvaluator: function () { - if (!this.root._evaluators[this.keypath]) { - this.root._evaluators[this.keypath] = new Evaluator(this.root, this.keypath, this.str, this.args, this.mustache.priority); - } else { - this.root._evaluators[this.keypath].refresh(); - } - } - }; - return ExpressionResolver; - }(render_shared_Evaluator__Evaluator, render_shared_ExpressionResolver_ReferenceScout, render_shared_ExpressionResolver_getKeypath, render_shared_ExpressionResolver_reassignDependants); -var render_shared_initMustache = function (resolveRef, ExpressionResolver) { - - return function (mustache, options) { - var keypath, indexRef, parentFragment; - parentFragment = mustache.parentFragment = options.parentFragment; - mustache.root = parentFragment.root; - mustache.contextStack = parentFragment.contextStack; - mustache.descriptor = options.descriptor; - mustache.index = options.index || 0; - mustache.priority = parentFragment.priority; - mustache.type = options.descriptor.t; - if (options.descriptor.r) { - if (parentFragment.indexRefs && parentFragment.indexRefs[options.descriptor.r] !== undefined) { - indexRef = parentFragment.indexRefs[options.descriptor.r]; - mustache.indexRef = options.descriptor.r; - mustache.value = indexRef; - mustache.render(mustache.value); - } else { - keypath = resolveRef(mustache.root, options.descriptor.r, mustache.contextStack); - if (keypath !== undefined) { - mustache.resolve(keypath); - } else { - mustache.ref = options.descriptor.r; - mustache.root._pendingResolution[mustache.root._pendingResolution.length] = mustache; - } - } - } - if (options.descriptor.x) { - mustache.expressionResolver = new ExpressionResolver(mustache); - } - if (mustache.descriptor.n && !mustache.hasOwnProperty('value')) { - mustache.render(undefined); - } - }; - }(shared_resolveRef, render_shared_ExpressionResolver__ExpressionResolver); -var render_shared_resolveMustache = function (types, registerDependant, unregisterDependant) { - - return function (keypath) { - if (keypath === this.keypath) { - return; - } - if (this.registered) { - unregisterDependant(this); - } - this.keypath = keypath; - registerDependant(this); - this.update(); - if (this.root.twoway && this.parentFragment.owner.type === types.ATTRIBUTE) { - this.parentFragment.owner.element.bind(); - } - if (this.expressionResolver && this.expressionResolver.resolved) { - this.expressionResolver = null; - } - }; - }(config_types, shared_registerDependant, shared_unregisterDependant); -var render_shared_updateMustache = function (isEqual) { - - return function () { - var wrapped, value; - value = this.root.get(this.keypath); - if (wrapped = this.root._wrapped[this.keypath]) { - value = wrapped.get(); - } - if (!isEqual(value, this.value)) { - this.render(value); - this.value = value; - } - }; - }(utils_isEqual); -var render_DomFragment_Interpolator = function (types, teardown, initMustache, resolveMustache, updateMustache) { - - var DomInterpolator, lessThan, greaterThan; - lessThan = //g; - DomInterpolator = function (options, docFrag) { - this.type = types.INTERPOLATOR; - if (docFrag) { - this.node = document.createTextNode(''); - docFrag.appendChild(this.node); - } - initMustache(this, options); - }; - DomInterpolator.prototype = { - update: updateMustache, - resolve: resolveMustache, - detach: function () { - this.node.parentNode.removeChild(this.node); - return this.node; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - } - teardown(this); - }, - render: function (value) { - if (this.node) { - this.node.data = value == undefined ? '' : value; - } - }, - firstNode: function () { - return this.node; - }, - toString: function () { - var value = this.value != undefined ? '' + this.value : ''; - return value.replace(lessThan, '<').replace(greaterThan, '>'); - } - }; - return DomInterpolator; - }(config_types, shared_teardown, render_shared_initMustache, render_shared_resolveMustache, render_shared_updateMustache); -var render_shared_updateSection = function (isArray, isObject, create) { - - return function (section, value) { - var fragmentOptions; - fragmentOptions = { - descriptor: section.descriptor.f, - root: section.root, - pNode: section.parentFragment.pNode, - owner: section - }; - if (section.descriptor.n) { - updateConditionalSection(section, value, true, fragmentOptions); - return; - } - if (isArray(value)) { - updateListSection(section, value, fragmentOptions); - } else if (isObject(value)) { - if (section.descriptor.i) { - updateListObjectSection(section, value, fragmentOptions); - } else { - updateContextSection(section, fragmentOptions); - } - } else { - updateConditionalSection(section, value, false, fragmentOptions); - } - }; - function updateListSection(section, value, fragmentOptions) { - var i, length, fragmentsToRemove; - length = value.length; - if (length < section.length) { - fragmentsToRemove = section.fragments.splice(length, section.length - length); - while (fragmentsToRemove.length) { - fragmentsToRemove.pop().teardown(true); - } - } else { - if (length > section.length) { - for (i = section.length; i < length; i += 1) { - fragmentOptions.contextStack = section.contextStack.concat(section.keypath + '.' + i); - fragmentOptions.index = i; - if (section.descriptor.i) { - fragmentOptions.indexRef = section.descriptor.i; - } - section.fragments[i] = section.createFragment(fragmentOptions); - } - } - } - section.length = length; - } - function updateListObjectSection(section, value, fragmentOptions) { - var id, fragmentsById; - fragmentsById = section.fragmentsById || (section.fragmentsById = create(null)); - for (id in fragmentsById) { - if (value[id] === undefined && fragmentsById[id]) { - fragmentsById[id].teardown(true); - fragmentsById[id] = null; - } - } - for (id in value) { - if (value[id] !== undefined && !fragmentsById[id]) { - fragmentOptions.contextStack = section.contextStack.concat(section.keypath + '.' + id); - fragmentOptions.index = id; - if (section.descriptor.i) { - fragmentOptions.indexRef = section.descriptor.i; - } - fragmentsById[id] = section.createFragment(fragmentOptions); - } - } - } - function updateContextSection(section, fragmentOptions) { - if (!section.length) { - fragmentOptions.contextStack = section.contextStack.concat(section.keypath); - fragmentOptions.index = 0; - section.fragments[0] = section.createFragment(fragmentOptions); - section.length = 1; - } - } - function updateConditionalSection(section, value, inverted, fragmentOptions) { - var doRender, emptyArray, fragmentsToRemove, fragment; - emptyArray = isArray(value) && value.length === 0; - if (inverted) { - doRender = emptyArray || !value; - } else { - doRender = value && !emptyArray; - } - if (doRender) { - if (!section.length) { - fragmentOptions.contextStack = section.contextStack; - fragmentOptions.index = 0; - section.fragments[0] = section.createFragment(fragmentOptions); - section.length = 1; - } - if (section.length > 1) { - fragmentsToRemove = section.fragments.splice(1); - while (fragment = fragmentsToRemove.pop()) { - fragment.teardown(true); - } - } - } else if (section.length) { - section.teardownFragments(true); - section.length = 0; - } - } - }(utils_isArray, utils_isObject, utils_create); -var render_DomFragment_Section_reassignFragment = function (types, unregisterDependant, ExpressionResolver) { - - return reassignFragment; - function reassignFragment(fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath) { - var i, item, context, query; - if (fragment.html) { - return; - } - if (fragment.indexRefs && fragment.indexRefs[indexRef] !== undefined) { - fragment.indexRefs[indexRef] = newIndex; - } - i = fragment.contextStack.length; - while (i--) { - context = fragment.contextStack[i]; - if (context.substr(0, oldKeypath.length) === oldKeypath) { - fragment.contextStack[i] = context.replace(oldKeypath, newKeypath); - } - } - i = fragment.items.length; - while (i--) { - item = fragment.items[i]; - switch (item.type) { - case types.ELEMENT: - reassignElement(item, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - break; - case types.PARTIAL: - reassignFragment(item.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - break; - case types.COMPONENT: - reassignFragment(item.instance.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - if (query = fragment.root._liveComponentQueries[item.name]) { - query._makeDirty(); - } - break; - case types.SECTION: - case types.INTERPOLATOR: - case types.TRIPLE: - reassignMustache(item, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - break; - } - } - } - function reassignElement(element, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath) { - var i, attribute, storage, masterEventName, proxies, proxy, binding, bindings, liveQueries, ractive; - i = element.attributes.length; - while (i--) { - attribute = element.attributes[i]; - if (attribute.fragment) { - reassignFragment(attribute.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - if (attribute.twoway) { - attribute.updateBindings(); - } - } - } - if (storage = element.node._ractive) { - if (storage.keypath.substr(0, oldKeypath.length) === oldKeypath) { - storage.keypath = storage.keypath.replace(oldKeypath, newKeypath); - } - if (indexRef !== undefined) { - storage.index[indexRef] = newIndex; - } - for (masterEventName in storage.events) { - proxies = storage.events[masterEventName].proxies; - i = proxies.length; - while (i--) { - proxy = proxies[i]; - if (typeof proxy.n === 'object') { - reassignFragment(proxy.a, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - if (proxy.d) { - reassignFragment(proxy.d, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - } - } - if (binding = storage.binding) { - if (binding.keypath.substr(0, oldKeypath.length) === oldKeypath) { - bindings = storage.root._twowayBindings[binding.keypath]; - bindings.splice(bindings.indexOf(binding), 1); - binding.keypath = binding.keypath.replace(oldKeypath, newKeypath); - bindings = storage.root._twowayBindings[binding.keypath] || (storage.root._twowayBindings[binding.keypath] = []); - bindings.push(binding); - } - } - } - if (element.fragment) { - reassignFragment(element.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - if (liveQueries = element.liveQueries) { - ractive = element.root; - i = liveQueries.length; - while (i--) { - ractive._liveQueries[liveQueries[i]]._makeDirty(); - } - } - } - function reassignMustache(mustache, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath) { - var i; - if (mustache.descriptor.x) { - if (mustache.expressionResolver) { - mustache.expressionResolver.teardown(); - } - mustache.expressionResolver = new ExpressionResolver(mustache); - } - if (mustache.keypath) { - if (mustache.keypath.substr(0, oldKeypath.length) === oldKeypath) { - mustache.resolve(mustache.keypath.replace(oldKeypath, newKeypath)); - } - } else if (mustache.indexRef === indexRef) { - mustache.value = newIndex; - mustache.render(newIndex); - } - if (mustache.fragments) { - i = mustache.fragments.length; - while (i--) { - reassignFragment(mustache.fragments[i], indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - } - } - }(config_types, shared_unregisterDependant, render_shared_ExpressionResolver__ExpressionResolver); -var render_DomFragment_Section_reassignFragments = function (types, reassignFragment, preDomUpdate) { - - return function (root, section, start, end, by) { - var i, fragment, indexRef, oldIndex, newIndex, oldKeypath, newKeypath; - indexRef = section.descriptor.i; - for (i = start; i < end; i += 1) { - fragment = section.fragments[i]; - oldIndex = i - by; - newIndex = i; - oldKeypath = section.keypath + '.' + (i - by); - newKeypath = section.keypath + '.' + i; - fragment.index += by; - reassignFragment(fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - preDomUpdate(root); - }; - }(config_types, render_DomFragment_Section_reassignFragment, shared_preDomUpdate); -var render_DomFragment_Section_prototype_merge = function (reassignFragment) { - - return function (newIndices) { - var section = this, parentFragment, firstChange, changed, i, newLength, newFragments, toTeardown, fragmentOptions, fragment, nextNode; - parentFragment = this.parentFragment; - newFragments = []; - newIndices.forEach(function (newIndex, oldIndex) { - var by, oldKeypath, newKeypath; - if (newIndex === oldIndex) { - newFragments[newIndex] = section.fragments[oldIndex]; - return; - } - if (firstChange === undefined) { - firstChange = oldIndex; - } - if (newIndex === -1) { - (toTeardown || (toTeardown = [])).push(section.fragments[oldIndex]); - return; - } - by = newIndex - oldIndex; - oldKeypath = section.keypath + '.' + oldIndex; - newKeypath = section.keypath + '.' + newIndex; - reassignFragment(section.fragments[oldIndex], section.descriptor.i, oldIndex, newIndex, by, oldKeypath, newKeypath); - newFragments[newIndex] = section.fragments[oldIndex]; - changed = true; - }); - if (toTeardown) { - while (fragment = toTeardown.pop()) { - fragment.teardown(true); - } - } - if (firstChange === undefined) { - firstChange = this.length; - } - newLength = this.root.get(this.keypath).length; - if (newLength === firstChange) { - return; - } - fragmentOptions = { - descriptor: this.descriptor.f, - root: this.root, - pNode: parentFragment.pNode, - owner: this - }; - if (this.descriptor.i) { - fragmentOptions.indexRef = this.descriptor.i; - } - for (i = firstChange; i < newLength; i += 1) { - if (fragment = newFragments[i]) { - this.docFrag.appendChild(fragment.detach(false)); - } else { - fragmentOptions.contextStack = this.contextStack.concat(this.keypath + '.' + i); - fragmentOptions.index = i; - fragment = this.createFragment(fragmentOptions); - } - this.fragments[i] = fragment; - } - nextNode = parentFragment.findNextNode(this); - parentFragment.pNode.insertBefore(this.docFrag, nextNode); - this.length = newLength; - }; - }(render_DomFragment_Section_reassignFragment); -var circular = function () { - - return []; - }(); -var render_DomFragment_Section__Section = function (types, isClient, initMustache, updateMustache, resolveMustache, updateSection, reassignFragment, reassignFragments, merge, teardown, circular) { - - var DomSection, DomFragment; - circular.push(function () { - DomFragment = circular.DomFragment; - }); - DomSection = function (options, docFrag) { - this.type = types.SECTION; - this.inverted = !!options.descriptor.n; - this.fragments = []; - this.length = 0; - if (docFrag) { - this.docFrag = document.createDocumentFragment(); - } - this.initialising = true; - initMustache(this, options); - if (docFrag) { - docFrag.appendChild(this.docFrag); - } - this.initialising = false; - }; - DomSection.prototype = { - update: updateMustache, - resolve: resolveMustache, - smartUpdate: function (methodName, args) { - var fragmentOptions; - if (methodName === 'push' || methodName === 'unshift' || methodName === 'splice') { - fragmentOptions = { - descriptor: this.descriptor.f, - root: this.root, - pNode: this.parentFragment.pNode, - owner: this - }; - if (this.descriptor.i) { - fragmentOptions.indexRef = this.descriptor.i; - } - } - if (this[methodName]) { - this.rendering = true; - this[methodName](fragmentOptions, args); - this.rendering = false; - } - }, - pop: function () { - if (this.length) { - this.fragments.pop().teardown(true); - this.length -= 1; - } - }, - push: function (fragmentOptions, args) { - var start, end, i; - start = this.length; - end = start + args.length; - for (i = start; i < end; i += 1) { - fragmentOptions.contextStack = this.contextStack.concat(this.keypath + '.' + i); - fragmentOptions.index = i; - this.fragments[i] = this.createFragment(fragmentOptions); - } - this.length += args.length; - this.parentFragment.pNode.insertBefore(this.docFrag, this.parentFragment.findNextNode(this)); - }, - shift: function () { - this.splice(null, [ - 0, - 1 - ]); - }, - unshift: function (fragmentOptions, args) { - this.splice(fragmentOptions, [ - 0, - 0 - ].concat(new Array(args.length))); - }, - splice: function (fragmentOptions, args) { - var insertionPoint, addedItems, removedItems, balance, i, start, end, spliceArgs, reassignStart; - if (!args.length) { - return; - } - start = +(args[0] < 0 ? this.length + args[0] : args[0]); - addedItems = Math.max(0, args.length - 2); - removedItems = args[1] !== undefined ? args[1] : this.length - start; - removedItems = Math.min(removedItems, this.length - start); - balance = addedItems - removedItems; - if (!balance) { - return; - } - if (balance < 0) { - end = start - balance; - for (i = start; i < end; i += 1) { - this.fragments[i].teardown(true); - } - this.fragments.splice(start, -balance); - } else { - end = start + balance; - insertionPoint = this.fragments[start] ? this.fragments[start].firstNode() : this.parentFragment.findNextNode(this); - spliceArgs = [ - start, - 0 - ].concat(new Array(balance)); - this.fragments.splice.apply(this.fragments, spliceArgs); - for (i = start; i < end; i += 1) { - fragmentOptions.contextStack = this.contextStack.concat(this.keypath + '.' + i); - fragmentOptions.index = i; - this.fragments[i] = this.createFragment(fragmentOptions); - } - this.parentFragment.pNode.insertBefore(this.docFrag, insertionPoint); - } - this.length += balance; - reassignStart = start + addedItems; - reassignFragments(this.root, this, reassignStart, this.length, balance); - }, - merge: merge, - detach: function () { - var i, len; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - this.docFrag.appendChild(this.fragments[i].detach()); - } - return this.docFrag; - }, - teardown: function (destroy) { - this.teardownFragments(destroy); - teardown(this); - }, - firstNode: function () { - if (this.fragments[0]) { - return this.fragments[0].firstNode(); - } - return this.parentFragment.findNextNode(this); - }, - findNextNode: function (fragment) { - if (this.fragments[fragment.index + 1]) { - return this.fragments[fragment.index + 1].firstNode(); - } - return this.parentFragment.findNextNode(this); - }, - teardownFragments: function (destroy) { - var id, fragment; - while (fragment = this.fragments.shift()) { - fragment.teardown(destroy); - } - if (this.fragmentsById) { - for (id in this.fragmentsById) { - if (this.fragments[id]) { - this.fragmentsById[id].teardown(destroy); - this.fragmentsById[id] = null; - } - } - } - }, - render: function (value) { - var nextNode, wrapped; - if (wrapped = this.root._wrapped[this.keypath]) { - value = wrapped.get(); - } - if (this.rendering) { - return; - } - this.rendering = true; - updateSection(this, value); - this.rendering = false; - if (this.docFrag && !this.docFrag.childNodes.length) { - return; - } - if (!this.initialising && isClient) { - nextNode = this.parentFragment.findNextNode(this); - if (nextNode && nextNode.parentNode === this.parentFragment.pNode) { - this.parentFragment.pNode.insertBefore(this.docFrag, nextNode); - } else { - this.parentFragment.pNode.appendChild(this.docFrag); - } - } - }, - createFragment: function (options) { - var fragment = new DomFragment(options); - if (this.docFrag) { - this.docFrag.appendChild(fragment.docFrag); - } - return fragment; - }, - toString: function () { - var str, i, id, len; - str = ''; - i = 0; - len = this.length; - for (i = 0; i < len; i += 1) { - str += this.fragments[i].toString(); - } - if (this.fragmentsById) { - for (id in this.fragmentsById) { - if (this.fragmentsById[id]) { - str += this.fragmentsById[id].toString(); - } - } - } - return str; - }, - find: function (selector) { - var i, len, queryResult; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - if (queryResult = this.fragments[i].find(selector)) { - return queryResult; - } - } - return null; - }, - findAll: function (selector, query) { - var i, len; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - this.fragments[i].findAll(selector, query); - } - }, - findComponent: function (selector) { - var i, len, queryResult; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - if (queryResult = this.fragments[i].findComponent(selector)) { - return queryResult; - } - } - return null; - }, - findAllComponents: function (selector, query) { - var i, len; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - this.fragments[i].findAllComponents(selector, query); - } - } - }; - return DomSection; - }(config_types, config_isClient, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache, render_shared_updateSection, render_DomFragment_Section_reassignFragment, render_DomFragment_Section_reassignFragments, render_DomFragment_Section_prototype_merge, shared_teardown, circular); -var render_DomFragment_Triple = function (types, matches, initMustache, updateMustache, resolveMustache, insertHtml, teardown) { - - var DomTriple = function (options, docFrag) { - this.type = types.TRIPLE; - if (docFrag) { - this.nodes = []; - this.docFrag = document.createDocumentFragment(); - } - this.initialising = true; - initMustache(this, options); - if (docFrag) { - docFrag.appendChild(this.docFrag); - } - this.initialising = false; - }; - DomTriple.prototype = { - update: updateMustache, - resolve: resolveMustache, - detach: function () { - var i = this.nodes.length; - while (i--) { - this.docFrag.appendChild(this.nodes[i]); - } - return this.docFrag; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - this.docFrag = this.nodes = null; - } - teardown(this); - }, - firstNode: function () { - if (this.nodes[0]) { - return this.nodes[0]; - } - return this.parentFragment.findNextNode(this); - }, - render: function (html) { - var node, pNode; - if (!this.nodes) { - return; - } - while (this.nodes.length) { - node = this.nodes.pop(); - node.parentNode.removeChild(node); - } - if (!html) { - this.nodes = []; - return; - } - pNode = this.parentFragment.pNode; - this.nodes = insertHtml(html, pNode.tagName, this.docFrag); - if (!this.initialising) { - pNode.insertBefore(this.docFrag, this.parentFragment.findNextNode(this)); - } - }, - toString: function () { - return this.value != undefined ? this.value : ''; - }, - find: function (selector) { - var i, len, node, queryResult; - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - return node; - } - if (queryResult = node.querySelector(selector)) { - return queryResult; - } - } - return null; - }, - findAll: function (selector, queryResult) { - var i, len, node, queryAllResult, numNodes, j; - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - queryResult.push(node); - } - if (queryAllResult = node.querySelectorAll(selector)) { - numNodes = queryAllResult.length; - for (j = 0; j < numNodes; j += 1) { - queryResult.push(queryAllResult[j]); - } - } - } - } - }; - return DomTriple; - }(config_types, utils_matches, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache, render_DomFragment_shared_insertHtml, shared_teardown); -var render_DomFragment_Element_initialise_getElementNamespace = function (namespaces) { - - return function (descriptor, parentNode) { - if (descriptor.a && descriptor.a.xmlns) { - return descriptor.a.xmlns; - } - return descriptor.e === 'svg' ? namespaces.svg : parentNode.namespaceURI || namespaces.html; - }; - }(config_namespaces); -var render_DomFragment_shared_enforceCase = function () { - - var svgCamelCaseElements, svgCamelCaseAttributes, createMap, map; - svgCamelCaseElements = 'altGlyph altGlyphDef altGlyphItem animateColor animateMotion animateTransform clipPath feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile feTurbulence foreignObject glyphRef linearGradient radialGradient textPath vkern'.split(' '); - svgCamelCaseAttributes = 'attributeName attributeType baseFrequency baseProfile calcMode clipPathUnits contentScriptType contentStyleType diffuseConstant edgeMode externalResourcesRequired filterRes filterUnits glyphRef gradientTransform gradientUnits kernelMatrix kernelUnitLength keyPoints keySplines keyTimes lengthAdjust limitingConeAngle markerHeight markerUnits markerWidth maskContentUnits maskUnits numOctaves pathLength patternContentUnits patternTransform patternUnits pointsAtX pointsAtY pointsAtZ preserveAlpha preserveAspectRatio primitiveUnits refX refY repeatCount repeatDur requiredExtensions requiredFeatures specularConstant specularExponent spreadMethod startOffset stdDeviation stitchTiles surfaceScale systemLanguage tableValues targetX targetY textLength viewBox viewTarget xChannelSelector yChannelSelector zoomAndPan'.split(' '); - createMap = function (items) { - var map = {}, i = items.length; - while (i--) { - map[items[i].toLowerCase()] = items[i]; - } - return map; - }; - map = createMap(svgCamelCaseElements.concat(svgCamelCaseAttributes)); - return function (elementName) { - var lowerCaseElementName = elementName.toLowerCase(); - return map[lowerCaseElementName] || lowerCaseElementName; - }; - }(); -var render_DomFragment_Attribute_helpers_determineNameAndNamespace = function (namespaces, enforceCase) { - - return function (attribute, name) { - var colonIndex, namespacePrefix; - colonIndex = name.indexOf(':'); - if (colonIndex !== -1) { - namespacePrefix = name.substr(0, colonIndex); - if (namespacePrefix !== 'xmlns') { - name = name.substring(colonIndex + 1); - attribute.name = enforceCase(name); - attribute.lcName = attribute.name.toLowerCase(); - attribute.namespace = namespaces[namespacePrefix.toLowerCase()]; - if (!attribute.namespace) { - throw 'Unknown namespace ("' + namespacePrefix + '")'; - } - return; - } - } - attribute.name = attribute.element.namespace !== namespaces.html ? enforceCase(name) : name; - attribute.lcName = attribute.name.toLowerCase(); - }; - }(config_namespaces, render_DomFragment_shared_enforceCase); -var render_DomFragment_Attribute_helpers_setStaticAttribute = function (namespaces) { - - return function (attribute, options) { - var node, value = options.value === null ? '' : options.value; - if (node = options.pNode) { - if (attribute.namespace) { - node.setAttributeNS(attribute.namespace, options.name, value); - } else { - if (options.name === 'style' && node.style.setAttribute) { - node.style.setAttribute('cssText', value); - } else if (options.name === 'class' && (!node.namespaceURI || node.namespaceURI === namespaces.html)) { - node.className = value; - } else { - node.setAttribute(options.name, value); - } - } - if (attribute.name === 'id') { - options.root.nodes[options.value] = node; - } - if (attribute.name === 'value') { - node._ractive.value = options.value; - } - } - attribute.value = options.value; - }; - }(config_namespaces); -var render_DomFragment_Attribute_helpers_determinePropertyName = function (namespaces) { - - var propertyNames = { - 'accept-charset': 'acceptCharset', - accesskey: 'accessKey', - bgcolor: 'bgColor', - 'class': 'className', - codebase: 'codeBase', - colspan: 'colSpan', - contenteditable: 'contentEditable', - datetime: 'dateTime', - dirname: 'dirName', - 'for': 'htmlFor', - 'http-equiv': 'httpEquiv', - ismap: 'isMap', - maxlength: 'maxLength', - novalidate: 'noValidate', - pubdate: 'pubDate', - readonly: 'readOnly', - rowspan: 'rowSpan', - tabindex: 'tabIndex', - usemap: 'useMap' - }; - return function (attribute, options) { - var propertyName; - if (attribute.pNode && !attribute.namespace && (!options.pNode.namespaceURI || options.pNode.namespaceURI === namespaces.html)) { - propertyName = propertyNames[attribute.name] || attribute.name; - if (options.pNode[propertyName] !== undefined) { - attribute.propertyName = propertyName; - } - if (typeof options.pNode[propertyName] === 'boolean' || propertyName === 'value') { - attribute.useProperty = true; - } - } - }; - }(config_namespaces); -var render_DomFragment_Attribute_prototype_bind = function (types, warn, arrayContentsMatch, getValueFromCheckboxes) { - - var bindAttribute, getInterpolator, updateModel, update, getBinding, inheritProperties, MultipleSelectBinding, SelectBinding, RadioNameBinding, CheckboxNameBinding, CheckedBinding, FileListBinding, ContentEditableBinding, GenericBinding; - bindAttribute = function () { - var node = this.pNode, interpolator, binding, bindings; - if (!this.fragment) { - return false; - } - interpolator = getInterpolator(this); - if (!interpolator) { - return false; - } - this.interpolator = interpolator; - this.keypath = interpolator.keypath || interpolator.descriptor.r; - binding = getBinding(this); - if (!binding) { - return false; - } - node._ractive.binding = this.element.binding = binding; - this.twoway = true; - bindings = this.root._twowayBindings[this.keypath] || (this.root._twowayBindings[this.keypath] = []); - bindings[bindings.length] = binding; - return true; - }; - updateModel = function () { - this._ractive.binding.update(); - }; - update = function () { - var value = this._ractive.root.get(this._ractive.binding.keypath); - this.value = value == undefined ? '' : value; - }; - getInterpolator = function (attribute) { - var item, errorMessage; - if (attribute.fragment.items.length !== 1) { - return null; - } - item = attribute.fragment.items[0]; - if (item.type !== types.INTERPOLATOR) { - return null; - } - if (!item.keypath && !item.ref) { - return null; - } - if (item.keypath && item.keypath.substr(0, 2) === '${') { - errorMessage = 'You cannot set up two-way binding against an expression ' + item.keypath; - if (attribute.root.debug) { - warn(errorMessage); - } - return null; - } - return item; - }; - getBinding = function (attribute) { - var node = attribute.pNode; - if (node.tagName === 'SELECT') { - return node.multiple ? new MultipleSelectBinding(attribute, node) : new SelectBinding(attribute, node); - } - if (node.type === 'checkbox' || node.type === 'radio') { - if (attribute.propertyName === 'name') { - if (node.type === 'checkbox') { - return new CheckboxNameBinding(attribute, node); - } - if (node.type === 'radio') { - return new RadioNameBinding(attribute, node); - } - } - if (attribute.propertyName === 'checked') { - return new CheckedBinding(attribute, node); - } - return null; - } - if (attribute.lcName !== 'value') { - warn('This is... odd'); - } - if (node.type === 'file') { - return new FileListBinding(attribute, node); - } - if (node.getAttribute('contenteditable')) { - return new ContentEditableBinding(attribute, node); - } - return new GenericBinding(attribute, node); - }; - MultipleSelectBinding = function (attribute, node) { - var valueFromModel; - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - valueFromModel = this.root.get(this.keypath); - if (valueFromModel === undefined) { - this.update(); - } - }; - MultipleSelectBinding.prototype = { - value: function () { - var value, options, i, len; - value = []; - options = this.node.options; - len = options.length; - for (i = 0; i < len; i += 1) { - if (options[i].selected) { - value[value.length] = options[i]._ractive.value; - } - } - return value; - }, - update: function () { - var attribute, previousValue, value; - attribute = this.attr; - previousValue = attribute.value; - value = this.value(); - if (previousValue === undefined || !arrayContentsMatch(value, previousValue)) { - attribute.receiving = true; - attribute.value = value; - this.root.set(this.keypath, value); - attribute.receiving = false; - } - return this; - }, - deferUpdate: function () { - if (this.deferred === true) { - return; - } - this.root._deferred.attrs.push(this); - this.deferred = true; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - } - }; - SelectBinding = function (attribute, node) { - var valueFromModel; - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - valueFromModel = this.root.get(this.keypath); - if (valueFromModel === undefined) { - this.update(); - } - }; - SelectBinding.prototype = { - value: function () { - var options, i, len; - options = this.node.options; - len = options.length; - for (i = 0; i < len; i += 1) { - if (options[i].selected) { - return options[i]._ractive.value; - } - } - }, - update: function () { - var value = this.value(); - this.attr.receiving = true; - this.attr.value = value; - this.root.set(this.keypath, value); - this.attr.receiving = false; - return this; - }, - deferUpdate: function () { - if (this.deferred === true) { - return; - } - this.root._deferred.attrs.push(this); - this.deferred = true; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - } - }; - RadioNameBinding = function (attribute, node) { - var valueFromModel; - this.radioName = true; - inheritProperties(this, attribute, node); - node.name = '{{' + attribute.keypath + '}}'; - node.addEventListener('change', updateModel, false); - if (node.attachEvent) { - node.addEventListener('click', updateModel, false); - } - valueFromModel = this.root.get(this.keypath); - if (valueFromModel !== undefined) { - node.checked = valueFromModel == node._ractive.value; - } else { - this.root._deferred.radios.push(this); - } - }; - RadioNameBinding.prototype = { - value: function () { - return this.node._ractive ? this.node._ractive.value : this.node.value; - }, - update: function () { - var node = this.node; - if (node.checked) { - this.attr.receiving = true; - this.root.set(this.keypath, this.value()); - this.attr.receiving = false; - } - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('click', updateModel, false); - } - }; - CheckboxNameBinding = function (attribute, node) { - var valueFromModel, checked; - this.checkboxName = true; - inheritProperties(this, attribute, node); - node.name = '{{' + this.keypath + '}}'; - node.addEventListener('change', updateModel, false); - if (node.attachEvent) { - node.addEventListener('click', updateModel, false); - } - valueFromModel = this.root.get(this.keypath); - if (valueFromModel !== undefined) { - checked = valueFromModel.indexOf(node._ractive.value) !== -1; - node.checked = checked; - } else { - if (this.root._deferred.checkboxes.indexOf(this.keypath) === -1) { - this.root._deferred.checkboxes.push(this.keypath); - } - } - }; - CheckboxNameBinding.prototype = { - changed: function () { - return this.node.checked !== !!this.checked; - }, - update: function () { - this.checked = this.node.checked; - this.attr.receiving = true; - this.root.set(this.keypath, getValueFromCheckboxes(this.root, this.keypath)); - this.attr.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('click', updateModel, false); - } - }; - CheckedBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - if (node.attachEvent) { - node.addEventListener('click', updateModel, false); - } - }; - CheckedBinding.prototype = { - value: function () { - return this.node.checked; - }, - update: function () { - this.attr.receiving = true; - this.root.set(this.keypath, this.value()); - this.attr.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('click', updateModel, false); - } - }; - FileListBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - }; - FileListBinding.prototype = { - value: function () { - return this.attr.pNode.files; - }, - update: function () { - this.attr.root.set(this.attr.keypath, this.value()); - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - } - }; - ContentEditableBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - if (!this.root.lazy) { - node.addEventListener('input', updateModel, false); - if (node.attachEvent) { - node.addEventListener('keyup', updateModel, false); - } - } - }; - ContentEditableBinding.prototype = { - update: function () { - this.attr.receiving = true; - this.root.set(this.keypath, this.node.innerHTML); - this.attr.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('input', updateModel, false); - this.node.removeEventListener('keyup', updateModel, false); - } - }; - GenericBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - if (!this.root.lazy) { - node.addEventListener('input', updateModel, false); - if (node.attachEvent) { - node.addEventListener('keyup', updateModel, false); - } - } - this.node.addEventListener('blur', update, false); - }; - GenericBinding.prototype = { - value: function () { - var value = this.attr.pNode.value; - if (+value + '' === value && value.indexOf('e') === -1) { - value = +value; - } - return value; - }, - update: function () { - var attribute = this.attr, value = this.value(); - attribute.receiving = true; - attribute.root.set(attribute.keypath, value); - attribute.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('input', updateModel, false); - this.node.removeEventListener('keyup', updateModel, false); - this.node.removeEventListener('blur', update, false); - } - }; - inheritProperties = function (binding, attribute, node) { - binding.attr = attribute; - binding.node = node; - binding.root = attribute.root; - binding.keypath = attribute.keypath; - }; - return bindAttribute; - }(config_types, utils_warn, utils_arrayContentsMatch, shared_getValueFromCheckboxes); -var render_DomFragment_Attribute_prototype_update = function (isArray, namespaces) { - - var updateAttribute, updateFileInputValue, deferSelect, initSelect, updateSelect, updateMultipleSelect, updateRadioName, updateCheckboxName, updateIEStyleAttribute, updateClassName, updateContentEditableValue, updateEverythingElse; - updateAttribute = function () { - var node; - if (!this.ready) { - return this; - } - node = this.pNode; - if (node.tagName === 'SELECT' && this.lcName === 'value') { - this.update = deferSelect; - this.deferredUpdate = initSelect; - return this.update(); - } - if (this.isFileInputValue) { - this.update = updateFileInputValue; - return this; - } - if (this.twoway && this.lcName === 'name') { - if (node.type === 'radio') { - this.update = updateRadioName; - return this.update(); - } - if (node.type === 'checkbox') { - this.update = updateCheckboxName; - return this.update(); - } - } - if (this.lcName === 'style' && node.style.setAttribute) { - this.update = updateIEStyleAttribute; - return this.update(); - } - if (this.lcName === 'class' && (!node.namespaceURI || node.namespaceURI === namespaces.html)) { - this.update = updateClassName; - return this.update(); - } - if (node.getAttribute('contenteditable') && this.lcName === 'value') { - this.update = updateContentEditableValue; - return this.update(); - } - this.update = updateEverythingElse; - return this.update(); - }; - updateFileInputValue = function () { - return this; - }; - initSelect = function () { - this.deferredUpdate = this.pNode.multiple ? updateMultipleSelect : updateSelect; - this.deferredUpdate(); - }; - deferSelect = function () { - this.root._deferred.selectValues.push(this); - return this; - }; - updateSelect = function () { - var value = this.fragment.getValue(), options, option, i; - this.value = this.pNode._ractive.value = value; - options = this.pNode.options; - i = options.length; - while (i--) { - option = options[i]; - if (option._ractive.value == value) { - option.selected = true; - return this; - } - } - return this; - }; - updateMultipleSelect = function () { - var value = this.fragment.getValue(), options, i; - if (!isArray(value)) { - value = [value]; - } - options = this.pNode.options; - i = options.length; - while (i--) { - options[i].selected = value.indexOf(options[i]._ractive.value) !== -1; - } - this.value = value; - return this; - }; - updateRadioName = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - node.checked = value == node._ractive.value; - return this; - }; - updateCheckboxName = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (!isArray(value)) { - node.checked = value == node._ractive.value; - return this; - } - node.checked = value.indexOf(node._ractive.value) !== -1; - return this; - }; - updateIEStyleAttribute = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - node.style.setAttribute('cssText', value); - this.value = value; - } - return this; - }; - updateClassName = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - node.className = value; - this.value = value; - } - return this; - }; - updateContentEditableValue = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - if (!this.receiving) { - node.innerHTML = value; - } - this.value = value; - } - return this; - }; - updateEverythingElse = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (this.isValueAttribute) { - node._ractive.value = value; - } - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - if (this.useProperty) { - if (!this.receiving) { - node[this.propertyName] = value; - } - this.value = value; - return this; - } - if (this.namespace) { - node.setAttributeNS(this.namespace, this.name, value); - this.value = value; - return this; - } - if (this.lcName === 'id') { - if (this.value !== undefined) { - this.root.nodes[this.value] = undefined; - } - this.root.nodes[value] = node; - } - node.setAttribute(this.name, value); - this.value = value; - } - return this; - }; - return updateAttribute; - }(utils_isArray, config_namespaces); -var parse_Tokenizer_utils_getStringMatch = function () { - - return function (string) { - var substr; - substr = this.str.substr(this.pos, string.length); - if (substr === string) { - this.pos += string.length; - return string; - } - return null; - }; - }(); -var parse_Tokenizer_utils_allowWhitespace = function () { - - var leadingWhitespace = /^\s+/; - return function () { - var match = leadingWhitespace.exec(this.remaining()); - if (!match) { - return null; - } - this.pos += match[0].length; - return match[0]; - }; - }(); -var parse_Tokenizer_utils_makeRegexMatcher = function () { - - return function (regex) { - return function (tokenizer) { - var match = regex.exec(tokenizer.str.substring(tokenizer.pos)); - if (!match) { - return null; - } - tokenizer.pos += match[0].length; - return match[1] || match[0]; - }; - }; - }(); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getEscapedChars = function () { - - return function (tokenizer) { - var chars = '', character; - character = getEscapedChar(tokenizer); - while (character) { - chars += character; - character = getEscapedChar(tokenizer); - } - return chars || null; - }; - function getEscapedChar(tokenizer) { - var character; - if (!tokenizer.getStringMatch('\\')) { - return null; - } - character = tokenizer.str.charAt(tokenizer.pos); - tokenizer.pos += 1; - return character; - } - }(); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getQuotedString = function (makeRegexMatcher, getEscapedChars) { - - var getUnescapedDoubleQuotedChars = makeRegexMatcher(/^[^\\"]+/), getUnescapedSingleQuotedChars = makeRegexMatcher(/^[^\\']+/); - return function getQuotedString(tokenizer, singleQuotes) { - var start, string, escaped, unescaped, next, matcher; - start = tokenizer.pos; - string = ''; - matcher = singleQuotes ? getUnescapedSingleQuotedChars : getUnescapedDoubleQuotedChars; - escaped = getEscapedChars(tokenizer); - if (escaped) { - string += escaped; - } - unescaped = matcher(tokenizer); - if (unescaped) { - string += unescaped; - } - if (!string) { - return ''; - } - next = getQuotedString(tokenizer, singleQuotes); - while (next !== '') { - string += next; - } - return string; - }; - }(parse_Tokenizer_utils_makeRegexMatcher, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getEscapedChars); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral = function (types, getQuotedString) { - - return function (tokenizer) { - var start, string; - start = tokenizer.pos; - if (tokenizer.getStringMatch('"')) { - string = getQuotedString(tokenizer, false); - if (!tokenizer.getStringMatch('"')) { - tokenizer.pos = start; - return null; - } - return { - t: types.STRING_LITERAL, - v: string - }; - } - if (tokenizer.getStringMatch('\'')) { - string = getQuotedString(tokenizer, true); - if (!tokenizer.getStringMatch('\'')) { - tokenizer.pos = start; - return null; - } - return { - t: types.STRING_LITERAL, - v: string - }; - } - return null; - }; - }(config_types, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getQuotedString); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getNumberLiteral = function (types, makeRegexMatcher) { - - var getNumber = makeRegexMatcher(/^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/); - return function (tokenizer) { - var result; - if (result = getNumber(tokenizer)) { - return { - t: types.NUMBER_LITERAL, - v: result - }; - } - return null; - }; - }(config_types, parse_Tokenizer_utils_makeRegexMatcher); -var parse_Tokenizer_getExpression_shared_getName = function (makeRegexMatcher) { - - return makeRegexMatcher(/^[a-zA-Z_$][a-zA-Z_$0-9]*/); - }(parse_Tokenizer_utils_makeRegexMatcher); -var parse_Tokenizer_getExpression_shared_getKey = function (getStringLiteral, getNumberLiteral, getName) { - - var identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/; - return function (tokenizer) { - var token; - if (token = getStringLiteral(tokenizer)) { - return identifier.test(token.v) ? token.v : '"' + token.v.replace(/"/g, '\\"') + '"'; - } - if (token = getNumberLiteral(tokenizer)) { - return token.v; - } - if (token = getName(tokenizer)) { - return token; - } - }; - }(parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getNumberLiteral, parse_Tokenizer_getExpression_shared_getName); -var utils_parseJSON = function (getStringMatch, allowWhitespace, getStringLiteral, getKey) { - - var Tokenizer, specials, specialsPattern, numberPattern, placeholderPattern, placeholderAtStartPattern; - specials = { - 'true': true, - 'false': false, - 'undefined': undefined, - 'null': null - }; - specialsPattern = new RegExp('^(?:' + Object.keys(specials).join('|') + ')'); - numberPattern = /^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/; - placeholderPattern = /\$\{([^\}]+)\}/g; - placeholderAtStartPattern = /^\$\{([^\}]+)\}/; - Tokenizer = function (str, values) { - this.str = str; - this.values = values; - this.pos = 0; - this.result = this.getToken(); - }; - Tokenizer.prototype = { - remaining: function () { - return this.str.substring(this.pos); - }, - getStringMatch: getStringMatch, - getToken: function () { - this.allowWhitespace(); - return this.getPlaceholder() || this.getSpecial() || this.getNumber() || this.getString() || this.getObject() || this.getArray(); - }, - getPlaceholder: function () { - var match; - if (!this.values) { - return null; - } - if ((match = placeholderAtStartPattern.exec(this.remaining())) && this.values.hasOwnProperty(match[1])) { - this.pos += match[0].length; - return { v: this.values[match[1]] }; - } - }, - getSpecial: function () { - var match; - if (match = specialsPattern.exec(this.remaining())) { - this.pos += match[0].length; - return { v: specials[match[0]] }; - } - }, - getNumber: function () { - var match; - if (match = numberPattern.exec(this.remaining())) { - this.pos += match[0].length; - return { v: +match[0] }; - } - }, - getString: function () { - var stringLiteral = getStringLiteral(this), values; - if (stringLiteral && (values = this.values)) { - return { - v: stringLiteral.v.replace(placeholderPattern, function (match, $1) { - return values[$1] || $1; - }) - }; - } - return stringLiteral; - }, - getObject: function () { - var result, pair; - if (!this.getStringMatch('{')) { - return null; - } - result = {}; - while (pair = getKeyValuePair(this)) { - result[pair.key] = pair.value; - this.allowWhitespace(); - if (this.getStringMatch('}')) { - return { v: result }; - } - if (!this.getStringMatch(',')) { - return null; - } - } - return null; - }, - getArray: function () { - var result, valueToken; - if (!this.getStringMatch('[')) { - return null; - } - result = []; - while (valueToken = this.getToken()) { - result.push(valueToken.v); - if (this.getStringMatch(']')) { - return { v: result }; - } - if (!this.getStringMatch(',')) { - return null; - } - } - return null; - }, - allowWhitespace: allowWhitespace - }; - function getKeyValuePair(tokenizer) { - var key, valueToken, pair; - tokenizer.allowWhitespace(); - key = getKey(tokenizer); - if (!key) { - return null; - } - pair = { key: key }; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(':')) { - return null; - } - tokenizer.allowWhitespace(); - valueToken = tokenizer.getToken(); - if (!valueToken) { - return null; - } - pair.value = valueToken.v; - return pair; - } - return function (str, values) { - var tokenizer = new Tokenizer(str, values); - if (tokenizer.result) { - return { - value: tokenizer.result.v, - remaining: tokenizer.remaining() - }; - } - return null; - }; - }(parse_Tokenizer_utils_getStringMatch, parse_Tokenizer_utils_allowWhitespace, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral, parse_Tokenizer_getExpression_shared_getKey); -var render_StringFragment_Interpolator = function (types, teardown, initMustache, updateMustache, resolveMustache) { - - var StringInterpolator = function (options) { - this.type = types.INTERPOLATOR; - initMustache(this, options); - }; - StringInterpolator.prototype = { - update: updateMustache, - resolve: resolveMustache, - render: function (value) { - this.value = value; - this.parentFragment.bubble(); - }, - teardown: function () { - teardown(this); - }, - toString: function () { - if (this.value == undefined) { - return ''; - } - return stringify(this.value); - } - }; - return StringInterpolator; - function stringify(value) { - if (typeof value === 'string') { - return value; - } - return JSON.stringify(value); - } - }(config_types, shared_teardown, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache); -var render_StringFragment_Section = function (types, initMustache, updateMustache, resolveMustache, updateSection, teardown, circular) { - - var StringSection, StringFragment; - circular.push(function () { - StringFragment = circular.StringFragment; - }); - StringSection = function (options) { - this.type = types.SECTION; - this.fragments = []; - this.length = 0; - initMustache(this, options); - }; - StringSection.prototype = { - update: updateMustache, - resolve: resolveMustache, - teardown: function () { - this.teardownFragments(); - teardown(this); - }, - teardownFragments: function () { - while (this.fragments.length) { - this.fragments.shift().teardown(); - } - this.length = 0; - }, - bubble: function () { - this.value = this.fragments.join(''); - this.parentFragment.bubble(); - }, - render: function (value) { - var wrapped; - if (wrapped = this.root._wrapped[this.keypath]) { - value = wrapped.get(); - } - updateSection(this, value); - this.parentFragment.bubble(); - }, - createFragment: function (options) { - return new StringFragment(options); - }, - toString: function () { - return this.fragments.join(''); - } - }; - return StringSection; - }(config_types, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache, render_shared_updateSection, shared_teardown, circular); -var render_StringFragment_Text = function (types) { - - var StringText = function (text) { - this.type = types.TEXT; - this.text = text; - }; - StringText.prototype = { - toString: function () { - return this.text; - }, - teardown: function () { - } - }; - return StringText; - }(config_types); -var render_StringFragment_prototype_toArgsList = function (warn, parseJSON) { - - return function () { - var values, counter, jsonesque, guid, errorMessage, parsed, processItems; - if (!this.argsList || this.dirty) { - values = {}; - counter = 0; - guid = this.root._guid; - processItems = function (items) { - return items.map(function (item) { - var placeholderId, wrapped, value; - if (item.text) { - return item.text; - } - if (item.fragments) { - return item.fragments.map(function (fragment) { - return processItems(fragment.items); - }).join(''); - } - placeholderId = guid + '-' + counter++; - if (wrapped = item.root._wrapped[item.keypath]) { - value = wrapped.value; - } else { - value = item.value; - } - values[placeholderId] = value; - return '${' + placeholderId + '}'; - }).join(''); - }; - jsonesque = processItems(this.items); - parsed = parseJSON('[' + jsonesque + ']', values); - if (!parsed) { - errorMessage = 'Could not parse directive arguments (' + this.toString() + '). If you think this is a bug, please file an issue at http://github.com/RactiveJS/Ractive/issues'; - if (this.root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - this.argsList = [jsonesque]; - } - } else { - this.argsList = parsed.value; - } - this.dirty = false; - } - return this.argsList; - }; - }(utils_warn, utils_parseJSON); -var render_StringFragment__StringFragment = function (types, parseJSON, initFragment, Interpolator, Section, Text, toArgsList, circular) { - - var StringFragment = function (options) { - initFragment(this, options); - }; - StringFragment.prototype = { - createItem: function (options) { - if (typeof options.descriptor === 'string') { - return new Text(options.descriptor); - } - switch (options.descriptor.t) { - case types.INTERPOLATOR: - return new Interpolator(options); - case types.TRIPLE: - return new Interpolator(options); - case types.SECTION: - return new Section(options); - default: - throw 'Something went wrong in a rather interesting way'; - } - }, - bubble: function () { - this.dirty = true; - this.owner.bubble(); - }, - teardown: function () { - var numItems, i; - numItems = this.items.length; - for (i = 0; i < numItems; i += 1) { - this.items[i].teardown(); - } - }, - getValue: function () { - var value; - if (this.items.length === 1 && this.items[0].type === types.INTERPOLATOR) { - value = this.items[0].value; - if (value !== undefined) { - return value; - } - } - return this.toString(); - }, - isSimple: function () { - var i, item, containsInterpolator; - if (this.simple !== undefined) { - return this.simple; - } - i = this.items.length; - while (i--) { - item = this.items[i]; - if (item.type === types.TEXT) { - continue; - } - if (item.type === types.INTERPOLATOR) { - if (containsInterpolator) { - return false; - } else { - containsInterpolator = true; - continue; - } - } - return this.simple = false; - } - return this.simple = true; - }, - toString: function () { - return this.items.join(''); - }, - toJSON: function () { - var value = this.getValue(), parsed; - if (typeof value === 'string') { - parsed = parseJSON(value); - value = parsed ? parsed.value : value; - } - return value; - }, - toArgsList: toArgsList - }; - circular.StringFragment = StringFragment; - return StringFragment; - }(config_types, utils_parseJSON, render_shared_initFragment, render_StringFragment_Interpolator, render_StringFragment_Section, render_StringFragment_Text, render_StringFragment_prototype_toArgsList, circular); -var render_DomFragment_Attribute__Attribute = function (types, determineNameAndNamespace, setStaticAttribute, determinePropertyName, bind, update, StringFragment) { - - var DomAttribute = function (options) { - this.type = types.ATTRIBUTE; - this.element = options.element; - determineNameAndNamespace(this, options.name); - if (options.value === null || typeof options.value === 'string') { - setStaticAttribute(this, options); - return; - } - this.root = options.root; - this.pNode = options.pNode; - this.parentFragment = this.element.parentFragment; - this.fragment = new StringFragment({ - descriptor: options.value, - root: this.root, - owner: this, - contextStack: options.contextStack - }); - if (!this.pNode) { - return; - } - if (this.name === 'value') { - this.isValueAttribute = true; - if (this.pNode.tagName === 'INPUT' && this.pNode.type === 'file') { - this.isFileInputValue = true; - } - } - determinePropertyName(this, options); - this.selfUpdating = this.fragment.isSimple(); - this.ready = true; - }; - DomAttribute.prototype = { - bind: bind, - update: update, - updateBindings: function () { - this.keypath = this.interpolator.keypath || this.interpolator.ref; - if (this.propertyName === 'name') { - this.pNode.name = '{{' + this.keypath + '}}'; - } - }, - teardown: function () { - var i; - if (this.boundEvents) { - i = this.boundEvents.length; - while (i--) { - this.pNode.removeEventListener(this.boundEvents[i], this.updateModel, false); - } - } - if (this.fragment) { - this.fragment.teardown(); - } - }, - bubble: function () { - if (this.selfUpdating) { - this.update(); - } else if (!this.deferred && this.ready) { - this.root._deferred.attrs.push(this); - this.deferred = true; - } - }, - toString: function () { - var str; - if (this.value === null) { - return this.name; - } - if (!this.fragment) { - return this.name + '=' + JSON.stringify(this.value); - } - str = this.fragment.toString(); - return this.name + '=' + JSON.stringify(str); - } - }; - return DomAttribute; - }(config_types, render_DomFragment_Attribute_helpers_determineNameAndNamespace, render_DomFragment_Attribute_helpers_setStaticAttribute, render_DomFragment_Attribute_helpers_determinePropertyName, render_DomFragment_Attribute_prototype_bind, render_DomFragment_Attribute_prototype_update, render_StringFragment__StringFragment); -var render_DomFragment_Element_initialise_createElementAttributes = function (DomAttribute) { - - return function (element, attributes) { - var attrName, attrValue, attr; - element.attributes = []; - for (attrName in attributes) { - if (attributes.hasOwnProperty(attrName)) { - attrValue = attributes[attrName]; - attr = new DomAttribute({ - element: element, - name: attrName, - value: attrValue, - root: element.root, - pNode: element.node, - contextStack: element.parentFragment.contextStack - }); - element.attributes[element.attributes.length] = element.attributes[attrName] = attr; - if (attrName !== 'name') { - attr.update(); - } - } - } - return element.attributes; - }; - }(render_DomFragment_Attribute__Attribute); -var render_DomFragment_Element_initialise_appendElementChildren = function (warn, namespaces, StringFragment, circular) { - - var DomFragment, updateCss, updateScript; - circular.push(function () { - DomFragment = circular.DomFragment; - }); - updateCss = function () { - var node = this.node, content = this.fragment.toString(); - if (node.styleSheet) { - node.styleSheet.cssText = content; - } - node.innerHTML = content; - }; - updateScript = function () { - if (!this.node.type || this.node.type === 'text/javascript') { - warn('Script tag was updated. This does not cause the code to be re-evaluated!'); - } - this.node.innerHTML = this.fragment.toString(); - }; - return function (element, node, descriptor, docFrag) { - var liveQueries, i, selector, queryAllResult, j; - if (element.lcName === 'script' || element.lcName === 'style') { - element.fragment = new StringFragment({ - descriptor: descriptor.f, - root: element.root, - contextStack: element.parentFragment.contextStack, - owner: element - }); - if (docFrag) { - if (element.lcName === 'script') { - element.bubble = updateScript; - element.node.innerHTML = element.fragment.toString(); - } else { - element.bubble = updateCss; - element.bubble(); - } - } - return; - } - if (typeof descriptor.f === 'string' && (!node || (!node.namespaceURI || node.namespaceURI === namespaces.html))) { - element.html = descriptor.f; - if (docFrag) { - node.innerHTML = element.html; - liveQueries = element.root._liveQueries; - i = liveQueries.length; - while (i--) { - selector = liveQueries[i]; - if ((queryAllResult = node.querySelectorAll(selector)) && (j = queryAllResult.length)) { - (element.liveQueries || (element.liveQueries = [])).push(selector); - element.liveQueries[selector] = []; - while (j--) { - element.liveQueries[selector][j] = queryAllResult[j]; - } - } - } - } - } else { - element.fragment = new DomFragment({ - descriptor: descriptor.f, - root: element.root, - pNode: node, - contextStack: element.parentFragment.contextStack, - owner: element - }); - if (docFrag) { - node.appendChild(element.fragment.docFrag); - } - } - }; - }(utils_warn, config_namespaces, render_StringFragment__StringFragment, circular); -var render_DomFragment_Element_initialise_decorate_Decorator = function (warn, StringFragment) { - - var Decorator = function (descriptor, root, owner, contextStack) { - var name, fragment, errorMessage; - this.root = root; - this.node = owner.node; - name = descriptor.n || descriptor; - if (typeof name !== 'string') { - fragment = new StringFragment({ - descriptor: name, - root: this.root, - owner: owner, - contextStack: contextStack - }); - name = fragment.toString(); - fragment.teardown(); - } - if (descriptor.a) { - this.params = descriptor.a; - } else if (descriptor.d) { - fragment = new StringFragment({ - descriptor: descriptor.d, - root: this.root, - owner: owner, - contextStack: contextStack - }); - this.params = fragment.toArgsList(); - fragment.teardown(); - } - this.fn = root.decorators[name]; - if (!this.fn) { - errorMessage = 'Missing "' + name + '" decorator. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#decorators'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - } - }; - Decorator.prototype = { - init: function () { - var result, args; - if (this.params) { - args = [this.node].concat(this.params); - result = this.fn.apply(this.root, args); - } else { - result = this.fn.call(this.root, this.node); - } - if (!result || !result.teardown) { - throw new Error('Decorator definition must return an object with a teardown method'); - } - this.teardown = result.teardown; - } - }; - return Decorator; - }(utils_warn, render_StringFragment__StringFragment); -var render_DomFragment_Element_initialise_decorate__decorate = function (Decorator) { - - return function (descriptor, root, owner, contextStack) { - owner.decorator = new Decorator(descriptor, root, owner, contextStack); - if (owner.decorator.fn) { - root._deferred.decorators.push(owner.decorator); - } - }; - }(render_DomFragment_Element_initialise_decorate_Decorator); -var render_DomFragment_Element_initialise_addEventProxies_addEventProxy = function (warn, StringFragment) { - - var addEventProxy, MasterEventHandler, ProxyEvent, firePlainEvent, fireEventWithArgs, fireEventWithDynamicArgs, customHandlers, genericHandler, getCustomHandler; - addEventProxy = function (element, triggerEventName, proxyDescriptor, contextStack, indexRefs) { - var events, master; - events = element.node._ractive.events; - master = events[triggerEventName] || (events[triggerEventName] = new MasterEventHandler(element, triggerEventName, contextStack, indexRefs)); - master.add(proxyDescriptor); - }; - MasterEventHandler = function (element, eventName, contextStack) { - var definition; - this.element = element; - this.root = element.root; - this.node = element.node; - this.name = eventName; - this.contextStack = contextStack; - this.proxies = []; - if (definition = this.root.events[eventName]) { - this.custom = definition(this.node, getCustomHandler(eventName)); - } else { - if (!('on' + eventName in this.node)) { - warn('Missing "' + this.name + '" event. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#events'); - } - this.node.addEventListener(eventName, genericHandler, false); - } - }; - MasterEventHandler.prototype = { - add: function (proxy) { - this.proxies[this.proxies.length] = new ProxyEvent(this.element, this.root, proxy, this.contextStack); - }, - teardown: function () { - var i; - if (this.custom) { - this.custom.teardown(); - } else { - this.node.removeEventListener(this.name, genericHandler, false); - } - i = this.proxies.length; - while (i--) { - this.proxies[i].teardown(); - } - }, - fire: function (event) { - var i = this.proxies.length; - while (i--) { - this.proxies[i].fire(event); - } - } - }; - ProxyEvent = function (element, ractive, descriptor, contextStack) { - var name; - this.root = ractive; - name = descriptor.n || descriptor; - if (typeof name === 'string') { - this.n = name; - } else { - this.n = new StringFragment({ - descriptor: descriptor.n, - root: this.root, - owner: element, - contextStack: contextStack - }); - } - if (descriptor.a) { - this.a = descriptor.a; - this.fire = fireEventWithArgs; - return; - } - if (descriptor.d) { - this.d = new StringFragment({ - descriptor: descriptor.d, - root: this.root, - owner: element, - contextStack: contextStack - }); - this.fire = fireEventWithDynamicArgs; - return; - } - this.fire = firePlainEvent; - }; - ProxyEvent.prototype = { - teardown: function () { - if (this.n.teardown) { - this.n.teardown(); - } - if (this.d) { - this.d.teardown(); - } - }, - bubble: function () { - } - }; - firePlainEvent = function (event) { - this.root.fire(this.n.toString(), event); - }; - fireEventWithArgs = function (event) { - this.root.fire.apply(this.root, [ - this.n.toString(), - event - ].concat(this.a)); - }; - fireEventWithDynamicArgs = function (event) { - var args = this.d.toArgsList(); - if (typeof args === 'string') { - args = args.substr(1, args.length - 2); - } - this.root.fire.apply(this.root, [ - this.n.toString(), - event - ].concat(args)); - }; - genericHandler = function (event) { - var storage = this._ractive; - storage.events[event.type].fire({ - node: this, - original: event, - index: storage.index, - keypath: storage.keypath, - context: storage.root.get(storage.keypath) - }); - }; - customHandlers = {}; - getCustomHandler = function (eventName) { - if (customHandlers[eventName]) { - return customHandlers[eventName]; - } - return customHandlers[eventName] = function (event) { - var storage = event.node._ractive; - event.index = storage.index; - event.keypath = storage.keypath; - event.context = storage.root.get(storage.keypath); - storage.events[eventName].fire(event); - }; - }; - return addEventProxy; - }(utils_warn, render_StringFragment__StringFragment); -var render_DomFragment_Element_initialise_addEventProxies__addEventProxies = function (addEventProxy) { - - return function (element, proxies) { - var i, eventName, eventNames; - for (eventName in proxies) { - if (proxies.hasOwnProperty(eventName)) { - eventNames = eventName.split('-'); - i = eventNames.length; - while (i--) { - addEventProxy(element, eventNames[i], proxies[eventName], element.parentFragment.contextStack); - } - } - } - }; - }(render_DomFragment_Element_initialise_addEventProxies_addEventProxy); -var render_DomFragment_Element_initialise_updateLiveQueries = function () { - - return function (element) { - var ractive, liveQueries, i, selector, query; - ractive = element.root; - liveQueries = ractive._liveQueries; - i = liveQueries.length; - while (i--) { - selector = liveQueries[i]; - query = liveQueries[selector]; - if (query._test(element)) { - (element.liveQueries || (element.liveQueries = [])).push(selector); - element.liveQueries[selector] = [element.node]; - } - } - }; - }(); -var utils_camelCase = function () { - - return function (hyphenatedStr) { - return hyphenatedStr.replace(/-([a-zA-Z])/g, function (match, $1) { - return $1.toUpperCase(); - }); - }; - }(); -var utils_fillGaps = function () { - - return function (target, source) { - var key; - for (key in source) { - if (source.hasOwnProperty(key) && !target.hasOwnProperty(key)) { - target[key] = source[key]; - } - } - return target; - }; - }(); -var render_DomFragment_Element_shared_executeTransition_Transition = function (isClient, createElement, warn, isNumeric, isArray, camelCase, fillGaps, StringFragment) { - - var Transition, testStyle, vendors, vendorPattern, unprefixPattern, prefixCache, CSS_TRANSITIONS_ENABLED, TRANSITION, TRANSITION_DURATION, TRANSITION_PROPERTY, TRANSITION_TIMING_FUNCTION, TRANSITIONEND; - if (!isClient) { - return; - } - testStyle = createElement('div').style; - (function () { - if (testStyle.transition !== undefined) { - TRANSITION = 'transition'; - TRANSITIONEND = 'transitionend'; - CSS_TRANSITIONS_ENABLED = true; - } else if (testStyle.webkitTransition !== undefined) { - TRANSITION = 'webkitTransition'; - TRANSITIONEND = 'webkitTransitionEnd'; - CSS_TRANSITIONS_ENABLED = true; - } else { - CSS_TRANSITIONS_ENABLED = false; - } - }()); - if (TRANSITION) { - TRANSITION_DURATION = TRANSITION + 'Duration'; - TRANSITION_PROPERTY = TRANSITION + 'Property'; - TRANSITION_TIMING_FUNCTION = TRANSITION + 'TimingFunction'; - } - Transition = function (descriptor, root, owner, contextStack, isIntro) { - var t = this, name, fragment, errorMessage; - this.root = root; - this.node = owner.node; - this.isIntro = isIntro; - this.originalStyle = this.node.getAttribute('style'); - this.complete = function (noReset) { - if (!noReset && t.isIntro) { - t.resetStyle(); - } - t._manager.pop(t.node); - t.node._ractive.transition = null; - }; - name = descriptor.n || descriptor; - if (typeof name !== 'string') { - fragment = new StringFragment({ - descriptor: name, - root: this.root, - owner: owner, - contextStack: contextStack - }); - name = fragment.toString(); - fragment.teardown(); - } - this.name = name; - if (descriptor.a) { - this.params = descriptor.a; - } else if (descriptor.d) { - fragment = new StringFragment({ - descriptor: descriptor.d, - root: this.root, - owner: owner, - contextStack: contextStack - }); - this.params = fragment.toArgsList(); - fragment.teardown(); - } - this._fn = root.transitions[name]; - if (!this._fn) { - errorMessage = 'Missing "' + name + '" transition. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#transitions'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - return; - } - }; - Transition.prototype = { - init: function () { - if (this._inited) { - throw new Error('Cannot initialize a transition more than once'); - } - this._inited = true; - this._fn.apply(this.root, [this].concat(this.params)); - }, - getStyle: function (props) { - var computedStyle, styles, i, prop, value; - computedStyle = window.getComputedStyle(this.node); - if (typeof props === 'string') { - value = computedStyle[prefix(props)]; - if (value === '0px') { - value = 0; - } - return value; - } - if (!isArray(props)) { - throw new Error('Transition#getStyle must be passed a string, or an array of strings representing CSS properties'); - } - styles = {}; - i = props.length; - while (i--) { - prop = props[i]; - value = computedStyle[prefix(prop)]; - if (value === '0px') { - value = 0; - } - styles[prop] = value; - } - return styles; - }, - setStyle: function (style, value) { - var prop; - if (typeof style === 'string') { - this.node.style[prefix(style)] = value; - } else { - for (prop in style) { - if (style.hasOwnProperty(prop)) { - this.node.style[prefix(prop)] = style[prop]; - } - } - } - return this; - }, - animateStyle: function (style, value, options, complete) { - var t = this, propertyNames, changedProperties, computedStyle, current, to, from, transitionEndHandler, i, prop; - if (typeof style === 'string') { - to = {}; - to[style] = value; - } else { - to = style; - complete = options; - options = value; - } - if (!options) { - warn('The "' + t.name + '" transition does not supply an options object to `t.animateStyle()`. This will break in a future version of Ractive. For more info see https://github.com/RactiveJS/Ractive/issues/340'); - options = t; - complete = t.complete; - } - if (!options.duration) { - t.setStyle(to); - if (complete) { - complete(); - } - } - propertyNames = Object.keys(to); - changedProperties = []; - computedStyle = window.getComputedStyle(t.node); - from = {}; - i = propertyNames.length; - while (i--) { - prop = propertyNames[i]; - current = computedStyle[prefix(prop)]; - if (current === '0px') { - current = 0; - } - if (current != to[prop]) { - changedProperties[changedProperties.length] = prop; - t.node.style[prefix(prop)] = current; - } - } - if (!changedProperties.length) { - if (complete) { - complete(); - } - return; - } - setTimeout(function () { - t.node.style[TRANSITION_PROPERTY] = propertyNames.map(prefix).map(hyphenate).join(','); - t.node.style[TRANSITION_TIMING_FUNCTION] = hyphenate(options.easing || 'linear'); - t.node.style[TRANSITION_DURATION] = options.duration / 1000 + 's'; - transitionEndHandler = function (event) { - var index; - index = changedProperties.indexOf(camelCase(unprefix(event.propertyName))); - if (index !== -1) { - changedProperties.splice(index, 1); - } - if (changedProperties.length) { - return; - } - t.root.fire(t.name + ':end'); - t.node.removeEventListener(TRANSITIONEND, transitionEndHandler, false); - if (complete) { - complete(); - } - }; - t.node.addEventListener(TRANSITIONEND, transitionEndHandler, false); - setTimeout(function () { - var i = changedProperties.length; - while (i--) { - prop = changedProperties[i]; - t.node.style[prefix(prop)] = to[prop]; - } - }, 0); - }, options.delay || 0); - }, - resetStyle: function () { - if (this.originalStyle) { - this.node.setAttribute('style', this.originalStyle); - } else { - this.node.getAttribute('style'); - this.node.removeAttribute('style'); - } - }, - processParams: function (params, defaults) { - if (typeof params === 'number') { - params = { duration: params }; - } else if (typeof params === 'string') { - if (params === 'slow') { - params = { duration: 600 }; - } else if (params === 'fast') { - params = { duration: 200 }; - } else { - params = { duration: 400 }; - } - } else if (!params) { - params = {}; - } - return fillGaps(params, defaults); - } - }; - vendors = [ - 'o', - 'ms', - 'moz', - 'webkit' - ]; - vendorPattern = new RegExp('^(?:' + vendors.join('|') + ')([A-Z])'); - unprefixPattern = new RegExp('^-(?:' + vendors.join('|') + ')-'); - prefixCache = {}; - function prefix(prop) { - var i, vendor, capped; - if (!prefixCache[prop]) { - if (testStyle[prop] !== undefined) { - prefixCache[prop] = prop; - } else { - capped = prop.charAt(0).toUpperCase() + prop.substring(1); - i = vendors.length; - while (i--) { - vendor = vendors[i]; - if (testStyle[vendor + capped] !== undefined) { - prefixCache[prop] = vendor + capped; - break; - } - } - } - } - return prefixCache[prop]; - } - function unprefix(prop) { - return prop.replace(unprefixPattern, ''); - } - function hyphenate(str) { - var hyphenated; - if (vendorPattern.test(str)) { - str = '-' + str; - } - hyphenated = str.replace(/[A-Z]/g, function (match) { - return '-' + match.toLowerCase(); - }); - return hyphenated; - } - return Transition; - }(config_isClient, utils_createElement, utils_warn, utils_isNumeric, utils_isArray, utils_camelCase, utils_fillGaps, render_StringFragment__StringFragment); -var render_DomFragment_Element_shared_executeTransition__executeTransition = function (warn, Transition) { - - return function (descriptor, root, owner, contextStack, isIntro) { - var transition, node, oldTransition; - if (!root.transitionsEnabled || root._parent && !root._parent.transitionsEnabled) { - return; - } - transition = new Transition(descriptor, root, owner, contextStack, isIntro); - if (transition._fn) { - node = transition.node; - transition._manager = root._transitionManager; - if (oldTransition = node._ractive.transition) { - oldTransition.complete(); - } - node._ractive.transition = transition; - transition._manager.push(node); - if (isIntro) { - root._deferred.transitions.push(transition); - } else { - transition.init(); - } - } - }; - }(utils_warn, render_DomFragment_Element_shared_executeTransition_Transition); -var render_DomFragment_Element_initialise__initialise = function (types, namespaces, create, defineProperty, matches, warn, createElement, getElementNamespace, createElementAttributes, appendElementChildren, decorate, addEventProxies, updateLiveQueries, executeTransition, enforceCase) { - - return function (element, options, docFrag) { - var parentFragment, pNode, contextStack, descriptor, namespace, name, attributes, width, height, loadHandler, root, selectBinding, errorMessage; - element.type = types.ELEMENT; - parentFragment = element.parentFragment = options.parentFragment; - pNode = parentFragment.pNode; - contextStack = parentFragment.contextStack; - descriptor = element.descriptor = options.descriptor; - element.root = root = parentFragment.root; - element.index = options.index; - element.lcName = descriptor.e.toLowerCase(); - element.eventListeners = []; - element.customEventListeners = []; - if (pNode) { - namespace = element.namespace = getElementNamespace(descriptor, pNode); - name = namespace !== namespaces.html ? enforceCase(descriptor.e) : descriptor.e; - element.node = createElement(name, namespace); - defineProperty(element.node, '_ractive', { - value: { - proxy: element, - keypath: contextStack.length ? contextStack[contextStack.length - 1] : '', - index: parentFragment.indexRefs, - events: create(null), - root: root - } - }); - } - attributes = createElementAttributes(element, descriptor.a); - if (descriptor.f) { - if (element.node && element.node.getAttribute('contenteditable')) { - if (element.node.innerHTML) { - errorMessage = 'A pre-populated contenteditable element should not have children'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - } - } - appendElementChildren(element, element.node, descriptor, docFrag); - } - if (docFrag && descriptor.v) { - addEventProxies(element, descriptor.v); - } - if (docFrag) { - if (root.twoway) { - element.bind(); - if (element.node.getAttribute('contenteditable') && element.node._ractive.binding) { - element.node._ractive.binding.update(); - } - } - if (attributes.name && !attributes.name.twoway) { - attributes.name.update(); - } - if (element.node.tagName === 'IMG' && ((width = element.attributes.width) || (height = element.attributes.height))) { - element.node.addEventListener('load', loadHandler = function () { - if (width) { - element.node.width = width.value; - } - if (height) { - element.node.height = height.value; - } - element.node.removeEventListener('load', loadHandler, false); - }, false); - } - docFrag.appendChild(element.node); - if (descriptor.o) { - decorate(descriptor.o, root, element, contextStack); - } - if (descriptor.t1) { - executeTransition(descriptor.t1, root, element, contextStack, true); - } - if (element.node.tagName === 'OPTION') { - if (pNode.tagName === 'SELECT' && (selectBinding = pNode._ractive.binding)) { - selectBinding.deferUpdate(); - } - if (element.node._ractive.value == pNode._ractive.value) { - element.node.selected = true; - } - } - if (element.node.autofocus) { - root._deferred.focusable = element.node; - } - } - updateLiveQueries(element); - }; - }(config_types, config_namespaces, utils_create, utils_defineProperty, utils_matches, utils_warn, utils_createElement, render_DomFragment_Element_initialise_getElementNamespace, render_DomFragment_Element_initialise_createElementAttributes, render_DomFragment_Element_initialise_appendElementChildren, render_DomFragment_Element_initialise_decorate__decorate, render_DomFragment_Element_initialise_addEventProxies__addEventProxies, render_DomFragment_Element_initialise_updateLiveQueries, render_DomFragment_Element_shared_executeTransition__executeTransition, render_DomFragment_shared_enforceCase); -var render_DomFragment_Element_prototype_teardown = function (executeTransition) { - - return function (destroy) { - var eventName, binding, bindings, i, liveQueries, selector, query, nodesToRemove, j; - if (this.fragment) { - this.fragment.teardown(false); - } - while (this.attributes.length) { - this.attributes.pop().teardown(); - } - if (this.node) { - for (eventName in this.node._ractive.events) { - this.node._ractive.events[eventName].teardown(); - } - if (binding = this.node._ractive.binding) { - binding.teardown(); - bindings = this.root._twowayBindings[binding.attr.keypath]; - bindings.splice(bindings.indexOf(binding), 1); - } - } - if (this.decorator) { - this.decorator.teardown(); - } - if (this.descriptor.t2) { - executeTransition(this.descriptor.t2, this.root, this, this.parentFragment.contextStack, false); - } - if (destroy) { - this.root._transitionManager.detachWhenReady(this); - } - if (liveQueries = this.liveQueries) { - i = liveQueries.length; - while (i--) { - selector = liveQueries[i]; - if (nodesToRemove = this.liveQueries[selector]) { - j = nodesToRemove.length; - query = this.root._liveQueries[selector]; - while (j--) { - query._remove(nodesToRemove[j]); - } - } - } - } - }; - }(render_DomFragment_Element_shared_executeTransition__executeTransition); -var config_voidElementNames = function () { - - return 'area base br col command doctype embed hr img input keygen link meta param source track wbr'.split(' '); - }(); -var render_DomFragment_Element_prototype_toString = function (voidElementNames) { - - return function () { - var str, i, len; - str = '<' + (this.descriptor.y ? '!doctype' : this.descriptor.e); - len = this.attributes.length; - for (i = 0; i < len; i += 1) { - str += ' ' + this.attributes[i].toString(); - } - str += '>'; - if (this.html) { - str += this.html; - } else if (this.fragment) { - str += this.fragment.toString(); - } - if (voidElementNames.indexOf(this.descriptor.e) === -1) { - str += '' + this.descriptor.e + '>'; - } - return str; - }; - }(config_voidElementNames); -var render_DomFragment_Element_prototype_find = function (matches) { - - return function (selector) { - var queryResult; - if (matches(this.node, selector)) { - return this.node; - } - if (this.html && (queryResult = this.node.querySelector(selector))) { - return queryResult; - } - if (this.fragment && this.fragment.find) { - return this.fragment.find(selector); - } - }; - }(utils_matches); -var render_DomFragment_Element_prototype_findAll = function () { - - return function (selector, query) { - var queryAllResult, i, numNodes, node, registeredNodes; - if (query._test(this, true) && query.live) { - (this.liveQueries || (this.liveQueries = [])).push(selector); - this.liveQueries[selector] = [this.node]; - } - if (this.html && (queryAllResult = this.node.querySelectorAll(selector)) && (numNodes = queryAllResult.length)) { - if (query.live) { - if (!this.liveQueries[selector]) { - (this.liveQueries || (this.liveQueries = [])).push(selector); - this.liveQueries[selector] = []; - } - registeredNodes = this.liveQueries[selector]; - } - for (i = 0; i < numNodes; i += 1) { - node = queryAllResult[i]; - query.push(node); - if (query.live) { - registeredNodes.push(node); - } - } - } - if (this.fragment) { - this.fragment.findAll(selector, query); - } - }; - }(); -var render_DomFragment_Element_prototype_findComponent = function () { - - return function (selector) { - if (this.fragment) { - return this.fragment.findComponent(selector); - } - }; - }(); -var render_DomFragment_Element_prototype_findAllComponents = function () { - - return function (selector, query) { - if (this.fragment) { - this.fragment.findAllComponents(selector, query); - } - }; - }(); -var render_DomFragment_Element_prototype_bind = function () { - - return function () { - var attributes = this.attributes; - if (!this.node) { - return; - } - if (this.binding) { - this.binding.teardown(); - this.binding = null; - } - if (this.node.getAttribute('contenteditable') && attributes.value && attributes.value.bind()) { - return; - } - switch (this.descriptor.e) { - case 'select': - case 'textarea': - if (attributes.value) { - attributes.value.bind(); - } - return; - case 'input': - if (this.node.type === 'radio' || this.node.type === 'checkbox') { - if (attributes.name && attributes.name.bind()) { - return; - } - if (attributes.checked && attributes.checked.bind()) { - return; - } - } - if (attributes.value && attributes.value.bind()) { - return; - } - } - }; - }(); -var render_DomFragment_Element__Element = function (initialise, teardown, toString, find, findAll, findComponent, findAllComponents, bind) { - - var DomElement = function (options, docFrag) { - initialise(this, options, docFrag); - }; - DomElement.prototype = { - detach: function () { - if (this.node) { - if (this.node.parentNode) { - this.node.parentNode.removeChild(this.node); - } - return this.node; - } - }, - teardown: teardown, - firstNode: function () { - return this.node; - }, - findNextNode: function () { - return null; - }, - bubble: function () { - }, - toString: toString, - find: find, - findAll: findAll, - findComponent: findComponent, - findAllComponents: findAllComponents, - bind: bind - }; - return DomElement; - }(render_DomFragment_Element_initialise__initialise, render_DomFragment_Element_prototype_teardown, render_DomFragment_Element_prototype_toString, render_DomFragment_Element_prototype_find, render_DomFragment_Element_prototype_findAll, render_DomFragment_Element_prototype_findComponent, render_DomFragment_Element_prototype_findAllComponents, render_DomFragment_Element_prototype_bind); -var config_errors = { missingParser: 'Missing Ractive.parse - cannot parse template. Either preparse or use the version that includes the parser' }; -var registries_partials = {}; -var parse_utils_stripHtmlComments = function () { - - return function (html) { - var commentStart, commentEnd, processed; - processed = ''; - while (html.length) { - commentStart = html.indexOf(''); - if (commentStart === -1 && commentEnd === -1) { - processed += html; - break; - } - if (commentStart !== -1 && commentEnd === -1) { - throw 'Illegal HTML - expected closing comment sequence (\'-->\')'; - } - if (commentEnd !== -1 && commentStart === -1 || commentEnd < commentStart) { - throw 'Illegal HTML - unexpected closing comment sequence (\'-->\')'; - } - processed += html.substr(0, commentStart); - html = html.substring(commentEnd + 3); - } - return processed; - }; - }(); -var parse_utils_stripStandalones = function (types) { - - return function (tokens) { - var i, current, backOne, backTwo, leadingLinebreak, trailingLinebreak; - leadingLinebreak = /^\s*\r?\n/; - trailingLinebreak = /\r?\n\s*$/; - for (i = 2; i < tokens.length; i += 1) { - current = tokens[i]; - backOne = tokens[i - 1]; - backTwo = tokens[i - 2]; - if (current.type === types.TEXT && backOne.type === types.MUSTACHE && backTwo.type === types.TEXT) { - if (trailingLinebreak.test(backTwo.value) && leadingLinebreak.test(current.value)) { - if (backOne.mustacheType !== types.INTERPOLATOR && backOne.mustacheType !== types.TRIPLE) { - backTwo.value = backTwo.value.replace(trailingLinebreak, '\n'); - } - current.value = current.value.replace(leadingLinebreak, ''); - if (current.value === '') { - tokens.splice(i--, 1); - } - } - } - } - return tokens; - }; - }(config_types); -var parse_utils_stripCommentTokens = function (types) { - - return function (tokens) { - var i, current, previous, next; - for (i = 0; i < tokens.length; i += 1) { - current = tokens[i]; - previous = tokens[i - 1]; - next = tokens[i + 1]; - if (current.mustacheType === types.COMMENT || current.mustacheType === types.DELIMCHANGE) { - tokens.splice(i, 1); - if (previous && next) { - if (previous.type === types.TEXT && next.type === types.TEXT) { - previous.value += next.value; - tokens.splice(i, 1); - } - } - i -= 1; - } - } - return tokens; - }; - }(config_types); -var parse_Tokenizer_getMustache_getDelimiterChange = function (makeRegexMatcher) { - - var getDelimiter = makeRegexMatcher(/^[^\s=]+/); - return function (tokenizer) { - var start, opening, closing; - if (!tokenizer.getStringMatch('=')) { - return null; - } - start = tokenizer.pos; - tokenizer.allowWhitespace(); - opening = getDelimiter(tokenizer); - if (!opening) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - closing = getDelimiter(tokenizer); - if (!closing) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch('=')) { - tokenizer.pos = start; - return null; - } - return [ - opening, - closing - ]; - }; - }(parse_Tokenizer_utils_makeRegexMatcher); -var parse_Tokenizer_getMustache_getMustacheType = function (types) { - - var mustacheTypes = { - '#': types.SECTION, - '^': types.INVERTED, - '/': types.CLOSING, - '>': types.PARTIAL, - '!': types.COMMENT, - '&': types.TRIPLE - }; - return function (tokenizer) { - var type = mustacheTypes[tokenizer.str.charAt(tokenizer.pos)]; - if (!type) { - return null; - } - tokenizer.pos += 1; - return type; - }; - }(config_types); -var parse_Tokenizer_getMustache_getMustacheContent = function (types, makeRegexMatcher, getMustacheType) { - - var getIndexRef = makeRegexMatcher(/^\s*:\s*([a-zA-Z_$][a-zA-Z_$0-9]*)/), arrayMember = /^[0-9][1-9]*$/; - return function (tokenizer, isTriple) { - var start, mustache, type, expr, i, remaining, index; - start = tokenizer.pos; - mustache = { type: isTriple ? types.TRIPLE : types.MUSTACHE }; - if (!isTriple) { - if (expr = tokenizer.getExpression()) { - mustache.mustacheType = types.INTERPOLATOR; - tokenizer.allowWhitespace(); - if (tokenizer.getStringMatch(tokenizer.delimiters[1])) { - tokenizer.pos -= tokenizer.delimiters[1].length; - } else { - tokenizer.pos = start; - expr = null; - } - } - if (!expr) { - type = getMustacheType(tokenizer); - if (type === types.TRIPLE) { - mustache = { type: types.TRIPLE }; - } else { - mustache.mustacheType = type || types.INTERPOLATOR; - } - if (type === types.COMMENT || type === types.CLOSING) { - remaining = tokenizer.remaining(); - index = remaining.indexOf(tokenizer.delimiters[1]); - if (index !== -1) { - mustache.ref = remaining.substr(0, index); - tokenizer.pos += index; - return mustache; - } - } - } - } - if (!expr) { - tokenizer.allowWhitespace(); - expr = tokenizer.getExpression(); - } - while (expr.t === types.BRACKETED && expr.x) { - expr = expr.x; - } - if (expr.t === types.REFERENCE) { - mustache.ref = expr.n; - } else if (expr.t === types.NUMBER_LITERAL && arrayMember.test(expr.v)) { - mustache.ref = expr.v; - } else { - mustache.expression = expr; - } - i = getIndexRef(tokenizer); - if (i !== null) { - mustache.indexRef = i; - } - return mustache; - }; - }(config_types, parse_Tokenizer_utils_makeRegexMatcher, parse_Tokenizer_getMustache_getMustacheType); -var parse_Tokenizer_getMustache__getMustache = function (types, getDelimiterChange, getMustacheContent) { - - return function () { - var seekTripleFirst = this.tripleDelimiters[0].length > this.delimiters[0].length; - return getMustache(this, seekTripleFirst) || getMustache(this, !seekTripleFirst); - }; - function getMustache(tokenizer, seekTriple) { - var start = tokenizer.pos, content, delimiters; - delimiters = seekTriple ? tokenizer.tripleDelimiters : tokenizer.delimiters; - if (!tokenizer.getStringMatch(delimiters[0])) { - return null; - } - content = getDelimiterChange(tokenizer); - if (content) { - if (!tokenizer.getStringMatch(delimiters[1])) { - tokenizer.pos = start; - return null; - } - tokenizer[seekTriple ? 'tripleDelimiters' : 'delimiters'] = content; - return { - type: types.MUSTACHE, - mustacheType: types.DELIMCHANGE - }; - } - tokenizer.allowWhitespace(); - content = getMustacheContent(tokenizer, seekTriple); - if (content === null) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(delimiters[1])) { - tokenizer.pos = start; - return null; - } - return content; - } - }(config_types, parse_Tokenizer_getMustache_getDelimiterChange, parse_Tokenizer_getMustache_getMustacheContent); -var parse_Tokenizer_getComment_getComment = function (types) { - - return function () { - var content, remaining, endIndex; - if (!this.getStringMatch(''); - if (endIndex === -1) { - throw new Error('Unexpected end of input (expected "-->" to close comment)'); - } - content = remaining.substr(0, endIndex); - this.pos += endIndex + 3; - return { - type: types.COMMENT, - content: content - }; - }; - }(config_types); -var parse_Tokenizer_utils_getLowestIndex = function () { - - return function (haystack, needles) { - var i, index, lowest; - i = needles.length; - while (i--) { - index = haystack.indexOf(needles[i]); - if (!index) { - return 0; - } - if (index === -1) { - continue; - } - if (!lowest || index < lowest) { - lowest = index; - } - } - return lowest || -1; - }; - }(); -var parse_Tokenizer_getTag__getTag = function (types, makeRegexMatcher, getLowestIndex) { - - var getTag, getOpeningTag, getClosingTag, getTagName, getAttributes, getAttribute, getAttributeName, getAttributeValue, getUnquotedAttributeValue, getUnquotedAttributeValueToken, getUnquotedAttributeValueText, getQuotedStringToken, getQuotedAttributeValue; - getTag = function () { - return getOpeningTag(this) || getClosingTag(this); - }; - getOpeningTag = function (tokenizer) { - var start, tag, attrs, lowerCaseName; - start = tokenizer.pos; - if (tokenizer.inside) { - return null; - } - if (!tokenizer.getStringMatch('<')) { - return null; - } - tag = { type: types.TAG }; - if (tokenizer.getStringMatch('!')) { - tag.doctype = true; - } - tag.name = getTagName(tokenizer); - if (!tag.name) { - tokenizer.pos = start; - return null; - } - attrs = getAttributes(tokenizer); - if (attrs) { - tag.attrs = attrs; - } - tokenizer.allowWhitespace(); - if (tokenizer.getStringMatch('/')) { - tag.selfClosing = true; - } - if (!tokenizer.getStringMatch('>')) { - tokenizer.pos = start; - return null; - } - lowerCaseName = tag.name.toLowerCase(); - if (lowerCaseName === 'script' || lowerCaseName === 'style') { - tokenizer.inside = lowerCaseName; - } - return tag; - }; - getClosingTag = function (tokenizer) { - var start, tag, expected; - start = tokenizer.pos; - expected = function (str) { - throw new Error('Unexpected character ' + tokenizer.remaining().charAt(0) + ' (expected ' + str + ')'); - }; - if (!tokenizer.getStringMatch('<')) { - return null; - } - tag = { - type: types.TAG, - closing: true - }; - if (!tokenizer.getStringMatch('/')) { - expected('"/"'); - } - tag.name = getTagName(tokenizer); - if (!tag.name) { - expected('tag name'); - } - if (!tokenizer.getStringMatch('>')) { - expected('">"'); - } - if (tokenizer.inside) { - if (tag.name.toLowerCase() !== tokenizer.inside) { - tokenizer.pos = start; - return null; - } - tokenizer.inside = null; - } - return tag; - }; - getTagName = makeRegexMatcher(/^[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/); - getAttributes = function (tokenizer) { - var start, attrs, attr; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - attr = getAttribute(tokenizer); - if (!attr) { - tokenizer.pos = start; - return null; - } - attrs = []; - while (attr !== null) { - attrs[attrs.length] = attr; - tokenizer.allowWhitespace(); - attr = getAttribute(tokenizer); - } - return attrs; - }; - getAttribute = function (tokenizer) { - var attr, name, value; - name = getAttributeName(tokenizer); - if (!name) { - return null; - } - attr = { name: name }; - value = getAttributeValue(tokenizer); - if (value) { - attr.value = value; - } - return attr; - }; - getAttributeName = makeRegexMatcher(/^[^\s"'>\/=]+/); - getAttributeValue = function (tokenizer) { - var start, value; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch('=')) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - value = getQuotedAttributeValue(tokenizer, '\'') || getQuotedAttributeValue(tokenizer, '"') || getUnquotedAttributeValue(tokenizer); - if (value === null) { - tokenizer.pos = start; - return null; - } - return value; - }; - getUnquotedAttributeValueText = makeRegexMatcher(/^[^\s"'=<>`]+/); - getUnquotedAttributeValueToken = function (tokenizer) { - var start, text, index; - start = tokenizer.pos; - text = getUnquotedAttributeValueText(tokenizer); - if (!text) { - return null; - } - if ((index = text.indexOf(tokenizer.delimiters[0])) !== -1) { - text = text.substr(0, index); - tokenizer.pos = start + text.length; - } - return { - type: types.TEXT, - value: text - }; - }; - getUnquotedAttributeValue = function (tokenizer) { - var tokens, token; - tokens = []; - token = tokenizer.getMustache() || getUnquotedAttributeValueToken(tokenizer); - while (token !== null) { - tokens[tokens.length] = token; - token = tokenizer.getMustache() || getUnquotedAttributeValueToken(tokenizer); - } - if (!tokens.length) { - return null; - } - return tokens; - }; - getQuotedAttributeValue = function (tokenizer, quoteMark) { - var start, tokens, token; - start = tokenizer.pos; - if (!tokenizer.getStringMatch(quoteMark)) { - return null; - } - tokens = []; - token = tokenizer.getMustache() || getQuotedStringToken(tokenizer, quoteMark); - while (token !== null) { - tokens[tokens.length] = token; - token = tokenizer.getMustache() || getQuotedStringToken(tokenizer, quoteMark); - } - if (!tokenizer.getStringMatch(quoteMark)) { - tokenizer.pos = start; - return null; - } - return tokens; - }; - getQuotedStringToken = function (tokenizer, quoteMark) { - var start, index, remaining; - start = tokenizer.pos; - remaining = tokenizer.remaining(); - index = getLowestIndex(remaining, [ - quoteMark, - tokenizer.delimiters[0], - tokenizer.delimiters[1] - ]); - if (index === -1) { - throw new Error('Quoted attribute value must have a closing quote'); - } - if (!index) { - return null; - } - tokenizer.pos += index; - return { - type: types.TEXT, - value: remaining.substr(0, index) - }; - }; - return getTag; - }(config_types, parse_Tokenizer_utils_makeRegexMatcher, parse_Tokenizer_utils_getLowestIndex); -var parse_Tokenizer_getText__getText = function (types, getLowestIndex) { - - return function () { - var index, remaining, barrier; - remaining = this.remaining(); - barrier = this.inside ? '' + this.inside : '<'; - index = getLowestIndex(remaining, [ - barrier, - this.delimiters[0], - this.tripleDelimiters[0] - ]); - if (!index) { - return null; - } - if (index === -1) { - index = remaining.length; - } - this.pos += index; - return { - type: types.TEXT, - value: remaining.substr(0, index) - }; - }; - }(config_types, parse_Tokenizer_utils_getLowestIndex); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getBooleanLiteral = function (types) { - - return function (tokenizer) { - var remaining = tokenizer.remaining(); - if (remaining.substr(0, 4) === 'true') { - tokenizer.pos += 4; - return { - t: types.BOOLEAN_LITERAL, - v: 'true' - }; - } - if (remaining.substr(0, 5) === 'false') { - tokenizer.pos += 5; - return { - t: types.BOOLEAN_LITERAL, - v: 'false' - }; - } - return null; - }; - }(config_types); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral_getKeyValuePair = function (types, getKey) { - - return function (tokenizer) { - var start, key, value; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - key = getKey(tokenizer); - if (key === null) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(':')) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - value = tokenizer.getExpression(); - if (value === null) { - tokenizer.pos = start; - return null; - } - return { - t: types.KEY_VALUE_PAIR, - k: key, - v: value - }; - }; - }(config_types, parse_Tokenizer_getExpression_shared_getKey); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral_getKeyValuePairs = function (getKeyValuePair) { - - return function getKeyValuePairs(tokenizer) { - var start, pairs, pair, keyValuePairs; - start = tokenizer.pos; - pair = getKeyValuePair(tokenizer); - if (pair === null) { - return null; - } - pairs = [pair]; - if (tokenizer.getStringMatch(',')) { - keyValuePairs = getKeyValuePairs(tokenizer); - if (!keyValuePairs) { - tokenizer.pos = start; - return null; - } - return pairs.concat(keyValuePairs); - } - return pairs; - }; - }(parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral_getKeyValuePair); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral__getObjectLiteral = function (types, getKeyValuePairs) { - - return function (tokenizer) { - var start, keyValuePairs; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch('{')) { - tokenizer.pos = start; - return null; - } - keyValuePairs = getKeyValuePairs(tokenizer); - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch('}')) { - tokenizer.pos = start; - return null; - } - return { - t: types.OBJECT_LITERAL, - m: keyValuePairs - }; - }; - }(config_types, parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral_getKeyValuePairs); -var parse_Tokenizer_getExpression_shared_getExpressionList = function () { - - return function getExpressionList(tokenizer) { - var start, expressions, expr, next; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - expr = tokenizer.getExpression(); - if (expr === null) { - return null; - } - expressions = [expr]; - tokenizer.allowWhitespace(); - if (tokenizer.getStringMatch(',')) { - next = getExpressionList(tokenizer); - if (next === null) { - tokenizer.pos = start; - return null; - } - expressions = expressions.concat(next); - } - return expressions; - }; - }(); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getArrayLiteral = function (types, getExpressionList) { - - return function (tokenizer) { - var start, expressionList; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch('[')) { - tokenizer.pos = start; - return null; - } - expressionList = getExpressionList(tokenizer); - if (!tokenizer.getStringMatch(']')) { - tokenizer.pos = start; - return null; - } - return { - t: types.ARRAY_LITERAL, - m: expressionList - }; - }; - }(config_types, parse_Tokenizer_getExpression_shared_getExpressionList); -var parse_Tokenizer_getExpression_getPrimary_getLiteral__getLiteral = function (getNumberLiteral, getBooleanLiteral, getStringLiteral, getObjectLiteral, getArrayLiteral) { - - return function (tokenizer) { - var literal = getNumberLiteral(tokenizer) || getBooleanLiteral(tokenizer) || getStringLiteral(tokenizer) || getObjectLiteral(tokenizer) || getArrayLiteral(tokenizer); - return literal; - }; - }(parse_Tokenizer_getExpression_getPrimary_getLiteral_getNumberLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getBooleanLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral__getObjectLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getArrayLiteral); -var parse_Tokenizer_getExpression_getPrimary_getReference = function (types, makeRegexMatcher, getName) { - - var getDotRefinement, getArrayRefinement, getArrayMember, globals; - getDotRefinement = makeRegexMatcher(/^\.[a-zA-Z_$0-9]+/); - getArrayRefinement = function (tokenizer) { - var num = getArrayMember(tokenizer); - if (num) { - return '.' + num; - } - return null; - }; - getArrayMember = makeRegexMatcher(/^\[(0|[1-9][0-9]*)\]/); - globals = /^(?:Array|Date|RegExp|decodeURIComponent|decodeURI|encodeURIComponent|encodeURI|isFinite|isNaN|parseFloat|parseInt|JSON|Math|NaN|undefined|null)$/; - return function (tokenizer) { - var startPos, ancestor, name, dot, combo, refinement, lastDotIndex; - startPos = tokenizer.pos; - ancestor = ''; - while (tokenizer.getStringMatch('../')) { - ancestor += '../'; - } - if (!ancestor) { - dot = tokenizer.getStringMatch('.') || ''; - } - name = getName(tokenizer) || ''; - if (!ancestor && !dot && globals.test(name)) { - return { - t: types.GLOBAL, - v: name - }; - } - if (name === 'this' && !ancestor && !dot) { - name = '.'; - startPos += 3; - } - combo = (ancestor || dot) + name; - if (!combo) { - return null; - } - while (refinement = getDotRefinement(tokenizer) || getArrayRefinement(tokenizer)) { - combo += refinement; - } - if (tokenizer.getStringMatch('(')) { - lastDotIndex = combo.lastIndexOf('.'); - if (lastDotIndex !== -1) { - combo = combo.substr(0, lastDotIndex); - tokenizer.pos = startPos + combo.length; - } else { - tokenizer.pos -= 1; - } - } - return { - t: types.REFERENCE, - n: combo - }; - }; - }(config_types, parse_Tokenizer_utils_makeRegexMatcher, parse_Tokenizer_getExpression_shared_getName); -var parse_Tokenizer_getExpression_getPrimary_getBracketedExpression = function (types) { - - return function (tokenizer) { - var start, expr; - start = tokenizer.pos; - if (!tokenizer.getStringMatch('(')) { - return null; - } - tokenizer.allowWhitespace(); - expr = tokenizer.getExpression(); - if (!expr) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(')')) { - tokenizer.pos = start; - return null; - } - return { - t: types.BRACKETED, - x: expr - }; - }; - }(config_types); -var parse_Tokenizer_getExpression_getPrimary__getPrimary = function (getLiteral, getReference, getBracketedExpression) { - - return function (tokenizer) { - return getLiteral(tokenizer) || getReference(tokenizer) || getBracketedExpression(tokenizer); - }; - }(parse_Tokenizer_getExpression_getPrimary_getLiteral__getLiteral, parse_Tokenizer_getExpression_getPrimary_getReference, parse_Tokenizer_getExpression_getPrimary_getBracketedExpression); -var parse_Tokenizer_getExpression_shared_getRefinement = function (types, getName) { - - return function getRefinement(tokenizer) { - var start, name, expr; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - if (tokenizer.getStringMatch('.')) { - tokenizer.allowWhitespace(); - if (name = getName(tokenizer)) { - return { - t: types.REFINEMENT, - n: name - }; - } - tokenizer.expected('a property name'); - } - if (tokenizer.getStringMatch('[')) { - tokenizer.allowWhitespace(); - expr = tokenizer.getExpression(); - if (!expr) { - tokenizer.expected('an expression'); - } - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(']')) { - tokenizer.expected('"]"'); - } - return { - t: types.REFINEMENT, - x: expr - }; - } - return null; - }; - }(config_types, parse_Tokenizer_getExpression_shared_getName); -var parse_Tokenizer_getExpression_getMemberOrInvocation = function (types, getPrimary, getExpressionList, getRefinement) { - - return function (tokenizer) { - var current, expression, refinement, expressionList; - expression = getPrimary(tokenizer); - if (!expression) { - return null; - } - while (expression) { - current = tokenizer.pos; - if (refinement = getRefinement(tokenizer)) { - expression = { - t: types.MEMBER, - x: expression, - r: refinement - }; - } else if (tokenizer.getStringMatch('(')) { - tokenizer.allowWhitespace(); - expressionList = getExpressionList(tokenizer); - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(')')) { - tokenizer.pos = current; - break; - } - expression = { - t: types.INVOCATION, - x: expression - }; - if (expressionList) { - expression.o = expressionList; - } - } else { - break; - } - } - return expression; - }; - }(config_types, parse_Tokenizer_getExpression_getPrimary__getPrimary, parse_Tokenizer_getExpression_shared_getExpressionList, parse_Tokenizer_getExpression_shared_getRefinement); -var parse_Tokenizer_getExpression_getTypeOf = function (types, getMemberOrInvocation) { - - var getTypeOf, makePrefixSequenceMatcher; - makePrefixSequenceMatcher = function (symbol, fallthrough) { - return function (tokenizer) { - var start, expression; - if (!tokenizer.getStringMatch(symbol)) { - return fallthrough(tokenizer); - } - start = tokenizer.pos; - tokenizer.allowWhitespace(); - expression = tokenizer.getExpression(); - if (!expression) { - tokenizer.expected('an expression'); - } - return { - s: symbol, - o: expression, - t: types.PREFIX_OPERATOR - }; - }; - }; - (function () { - var i, len, matcher, prefixOperators, fallthrough; - prefixOperators = '! ~ + - typeof'.split(' '); - fallthrough = getMemberOrInvocation; - for (i = 0, len = prefixOperators.length; i < len; i += 1) { - matcher = makePrefixSequenceMatcher(prefixOperators[i], fallthrough); - fallthrough = matcher; - } - getTypeOf = fallthrough; - }()); - return getTypeOf; - }(config_types, parse_Tokenizer_getExpression_getMemberOrInvocation); -var parse_Tokenizer_getExpression_getLogicalOr = function (types, getTypeOf) { - - var getLogicalOr, makeInfixSequenceMatcher; - makeInfixSequenceMatcher = function (symbol, fallthrough) { - return function (tokenizer) { - var start, left, right; - left = fallthrough(tokenizer); - if (!left) { - return null; - } - start = tokenizer.pos; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(symbol)) { - tokenizer.pos = start; - return left; - } - if (symbol === 'in' && /[a-zA-Z_$0-9]/.test(tokenizer.remaining().charAt(0))) { - tokenizer.pos = start; - return left; - } - tokenizer.allowWhitespace(); - right = tokenizer.getExpression(); - if (!right) { - tokenizer.pos = start; - return left; - } - return { - t: types.INFIX_OPERATOR, - s: symbol, - o: [ - left, - right - ] - }; - }; - }; - (function () { - var i, len, matcher, infixOperators, fallthrough; - infixOperators = '* / % + - << >> >>> < <= > >= in instanceof == != === !== & ^ | && ||'.split(' '); - fallthrough = getTypeOf; - for (i = 0, len = infixOperators.length; i < len; i += 1) { - matcher = makeInfixSequenceMatcher(infixOperators[i], fallthrough); - fallthrough = matcher; - } - getLogicalOr = fallthrough; - }()); - return getLogicalOr; - }(config_types, parse_Tokenizer_getExpression_getTypeOf); -var parse_Tokenizer_getExpression_getConditional = function (types, getLogicalOr) { - - return function (tokenizer) { - var start, expression, ifTrue, ifFalse; - expression = getLogicalOr(tokenizer); - if (!expression) { - return null; - } - start = tokenizer.pos; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch('?')) { - tokenizer.pos = start; - return expression; - } - tokenizer.allowWhitespace(); - ifTrue = tokenizer.getExpression(); - if (!ifTrue) { - tokenizer.pos = start; - return expression; - } - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(':')) { - tokenizer.pos = start; - return expression; - } - tokenizer.allowWhitespace(); - ifFalse = tokenizer.getExpression(); - if (!ifFalse) { - tokenizer.pos = start; - return expression; - } - return { - t: types.CONDITIONAL, - o: [ - expression, - ifTrue, - ifFalse - ] - }; - }; - }(config_types, parse_Tokenizer_getExpression_getLogicalOr); -var parse_Tokenizer_getExpression__getExpression = function (getConditional) { - - return function () { - return getConditional(this); - }; - }(parse_Tokenizer_getExpression_getConditional); -var parse_Tokenizer__Tokenizer = function (getMustache, getComment, getTag, getText, getExpression, allowWhitespace, getStringMatch) { - - var Tokenizer; - Tokenizer = function (str, options) { - var token; - this.str = str; - this.pos = 0; - this.delimiters = options.delimiters; - this.tripleDelimiters = options.tripleDelimiters; - this.tokens = []; - while (this.pos < this.str.length) { - token = this.getToken(); - if (token === null && this.remaining()) { - this.fail(); - } - this.tokens.push(token); - } - }; - Tokenizer.prototype = { - getToken: function () { - var token = this.getMustache() || this.getComment() || this.getTag() || this.getText(); - return token; - }, - getMustache: getMustache, - getComment: getComment, - getTag: getTag, - getText: getText, - getExpression: getExpression, - allowWhitespace: allowWhitespace, - getStringMatch: getStringMatch, - remaining: function () { - return this.str.substring(this.pos); - }, - fail: function () { - var last20, next20; - last20 = this.str.substr(0, this.pos).substr(-20); - if (last20.length === 20) { - last20 = '...' + last20; - } - next20 = this.remaining().substr(0, 20); - if (next20.length === 20) { - next20 = next20 + '...'; - } - throw new Error('Could not parse template: ' + (last20 ? last20 + '<- ' : '') + 'failed at character ' + this.pos + ' ->' + next20); - }, - expected: function (thing) { - var remaining = this.remaining().substr(0, 40); - if (remaining.length === 40) { - remaining += '...'; - } - throw new Error('Tokenizer failed: unexpected string "' + remaining + '" (expected ' + thing + ')'); - } - }; - return Tokenizer; - }(parse_Tokenizer_getMustache__getMustache, parse_Tokenizer_getComment_getComment, parse_Tokenizer_getTag__getTag, parse_Tokenizer_getText__getText, parse_Tokenizer_getExpression__getExpression, parse_Tokenizer_utils_allowWhitespace, parse_Tokenizer_utils_getStringMatch); -var parse_tokenize = function (stripHtmlComments, stripStandalones, stripCommentTokens, Tokenizer, circular) { - - var tokenize, Ractive; - circular.push(function () { - Ractive = circular.Ractive; - }); - tokenize = function (template, options) { - var tokenizer, tokens; - options = options || {}; - if (options.stripComments !== false) { - template = stripHtmlComments(template); - } - tokenizer = new Tokenizer(template, { - delimiters: options.delimiters || (Ractive ? Ractive.delimiters : [ - '{{', - '}}' - ]), - tripleDelimiters: options.tripleDelimiters || (Ractive ? Ractive.tripleDelimiters : [ - '{{{', - '}}}' - ]) - }); - tokens = tokenizer.tokens; - stripStandalones(tokens); - stripCommentTokens(tokens); - return tokens; - }; - return tokenize; - }(parse_utils_stripHtmlComments, parse_utils_stripStandalones, parse_utils_stripCommentTokens, parse_Tokenizer__Tokenizer, circular); -var parse_Parser_getText_TextStub__TextStub = function (types) { - - var TextStub, htmlEntities, controlCharacters, namedEntityPattern, hexEntityPattern, decimalEntityPattern, validateCode, decodeCharacterReferences, whitespace; - TextStub = function (token, preserveWhitespace) { - this.text = preserveWhitespace ? token.value : token.value.replace(whitespace, ' '); - }; - TextStub.prototype = { - type: types.TEXT, - toJSON: function () { - return this.decoded || (this.decoded = decodeCharacterReferences(this.text)); - }, - toString: function () { - return this.text; - } - }; - htmlEntities = { - quot: 34, - amp: 38, - apos: 39, - lt: 60, - gt: 62, - nbsp: 160, - iexcl: 161, - cent: 162, - pound: 163, - curren: 164, - yen: 165, - brvbar: 166, - sect: 167, - uml: 168, - copy: 169, - ordf: 170, - laquo: 171, - not: 172, - shy: 173, - reg: 174, - macr: 175, - deg: 176, - plusmn: 177, - sup2: 178, - sup3: 179, - acute: 180, - micro: 181, - para: 182, - middot: 183, - cedil: 184, - sup1: 185, - ordm: 186, - raquo: 187, - frac14: 188, - frac12: 189, - frac34: 190, - iquest: 191, - Agrave: 192, - Aacute: 193, - Acirc: 194, - Atilde: 195, - Auml: 196, - Aring: 197, - AElig: 198, - Ccedil: 199, - Egrave: 200, - Eacute: 201, - Ecirc: 202, - Euml: 203, - Igrave: 204, - Iacute: 205, - Icirc: 206, - Iuml: 207, - ETH: 208, - Ntilde: 209, - Ograve: 210, - Oacute: 211, - Ocirc: 212, - Otilde: 213, - Ouml: 214, - times: 215, - Oslash: 216, - Ugrave: 217, - Uacute: 218, - Ucirc: 219, - Uuml: 220, - Yacute: 221, - THORN: 222, - szlig: 223, - agrave: 224, - aacute: 225, - acirc: 226, - atilde: 227, - auml: 228, - aring: 229, - aelig: 230, - ccedil: 231, - egrave: 232, - eacute: 233, - ecirc: 234, - euml: 235, - igrave: 236, - iacute: 237, - icirc: 238, - iuml: 239, - eth: 240, - ntilde: 241, - ograve: 242, - oacute: 243, - ocirc: 244, - otilde: 245, - ouml: 246, - divide: 247, - oslash: 248, - ugrave: 249, - uacute: 250, - ucirc: 251, - uuml: 252, - yacute: 253, - thorn: 254, - yuml: 255, - OElig: 338, - oelig: 339, - Scaron: 352, - scaron: 353, - Yuml: 376, - fnof: 402, - circ: 710, - tilde: 732, - Alpha: 913, - Beta: 914, - Gamma: 915, - Delta: 916, - Epsilon: 917, - Zeta: 918, - Eta: 919, - Theta: 920, - Iota: 921, - Kappa: 922, - Lambda: 923, - Mu: 924, - Nu: 925, - Xi: 926, - Omicron: 927, - Pi: 928, - Rho: 929, - Sigma: 931, - Tau: 932, - Upsilon: 933, - Phi: 934, - Chi: 935, - Psi: 936, - Omega: 937, - alpha: 945, - beta: 946, - gamma: 947, - delta: 948, - epsilon: 949, - zeta: 950, - eta: 951, - theta: 952, - iota: 953, - kappa: 954, - lambda: 955, - mu: 956, - nu: 957, - xi: 958, - omicron: 959, - pi: 960, - rho: 961, - sigmaf: 962, - sigma: 963, - tau: 964, - upsilon: 965, - phi: 966, - chi: 967, - psi: 968, - omega: 969, - thetasym: 977, - upsih: 978, - piv: 982, - ensp: 8194, - emsp: 8195, - thinsp: 8201, - zwnj: 8204, - zwj: 8205, - lrm: 8206, - rlm: 8207, - ndash: 8211, - mdash: 8212, - lsquo: 8216, - rsquo: 8217, - sbquo: 8218, - ldquo: 8220, - rdquo: 8221, - bdquo: 8222, - dagger: 8224, - Dagger: 8225, - bull: 8226, - hellip: 8230, - permil: 8240, - prime: 8242, - Prime: 8243, - lsaquo: 8249, - rsaquo: 8250, - oline: 8254, - frasl: 8260, - euro: 8364, - image: 8465, - weierp: 8472, - real: 8476, - trade: 8482, - alefsym: 8501, - larr: 8592, - uarr: 8593, - rarr: 8594, - darr: 8595, - harr: 8596, - crarr: 8629, - lArr: 8656, - uArr: 8657, - rArr: 8658, - dArr: 8659, - hArr: 8660, - forall: 8704, - part: 8706, - exist: 8707, - empty: 8709, - nabla: 8711, - isin: 8712, - notin: 8713, - ni: 8715, - prod: 8719, - sum: 8721, - minus: 8722, - lowast: 8727, - radic: 8730, - prop: 8733, - infin: 8734, - ang: 8736, - and: 8743, - or: 8744, - cap: 8745, - cup: 8746, - 'int': 8747, - there4: 8756, - sim: 8764, - cong: 8773, - asymp: 8776, - ne: 8800, - equiv: 8801, - le: 8804, - ge: 8805, - sub: 8834, - sup: 8835, - nsub: 8836, - sube: 8838, - supe: 8839, - oplus: 8853, - otimes: 8855, - perp: 8869, - sdot: 8901, - lceil: 8968, - rceil: 8969, - lfloor: 8970, - rfloor: 8971, - lang: 9001, - rang: 9002, - loz: 9674, - spades: 9824, - clubs: 9827, - hearts: 9829, - diams: 9830 - }; - controlCharacters = [ - 8364, - 129, - 8218, - 402, - 8222, - 8230, - 8224, - 8225, - 710, - 8240, - 352, - 8249, - 338, - 141, - 381, - 143, - 144, - 8216, - 8217, - 8220, - 8221, - 8226, - 8211, - 8212, - 732, - 8482, - 353, - 8250, - 339, - 157, - 382, - 376 - ]; - namedEntityPattern = new RegExp('&(' + Object.keys(htmlEntities).join('|') + ');?', 'g'); - hexEntityPattern = /([0-9]+);?/g; - decimalEntityPattern = /([0-9]+);?/g; - validateCode = function (code) { - if (!code) { - return 65533; - } - if (code === 10) { - return 32; - } - if (code < 128) { - return code; - } - if (code <= 159) { - return controlCharacters[code - 128]; - } - if (code < 55296) { - return code; - } - if (code <= 57343) { - return 65533; - } - if (code <= 65535) { - return code; - } - return 65533; - }; - decodeCharacterReferences = function (html) { - var result; - result = html.replace(namedEntityPattern, function (match, name) { - if (htmlEntities[name]) { - return String.fromCharCode(htmlEntities[name]); - } - return match; - }); - result = result.replace(hexEntityPattern, function (match, hex) { - return String.fromCharCode(validateCode(parseInt(hex, 16))); - }); - result = result.replace(decimalEntityPattern, function (match, charCode) { - return String.fromCharCode(validateCode(charCode)); - }); - return result; - }; - whitespace = /\s+/g; - return TextStub; - }(config_types); -var parse_Parser_getText__getText = function (types, TextStub) { - - return function (token) { - if (token.type === types.TEXT) { - this.pos += 1; - return new TextStub(token, this.preserveWhitespace); - } - return null; - }; - }(config_types, parse_Parser_getText_TextStub__TextStub); -var parse_Parser_getComment_CommentStub__CommentStub = function (types) { - - var CommentStub; - CommentStub = function (token) { - this.content = token.content; - }; - CommentStub.prototype = { - toJSON: function () { - return { - t: types.COMMENT, - f: this.content - }; - }, - toString: function () { - return ''; - } - }; - return CommentStub; - }(config_types); -var parse_Parser_getComment__getComment = function (types, CommentStub) { - - return function (token) { - if (token.type === types.COMMENT) { - this.pos += 1; - return new CommentStub(token, this.preserveWhitespace); - } - return null; - }; - }(config_types, parse_Parser_getComment_CommentStub__CommentStub); -var parse_Parser_getMustache_ExpressionStub__ExpressionStub = function (types, isObject) { - - var ExpressionStub, getRefs, stringify; - ExpressionStub = function (token) { - this.refs = []; - getRefs(token, this.refs); - this.str = stringify(token, this.refs); - }; - ExpressionStub.prototype = { - toJSON: function () { - if (this.json) { - return this.json; - } - this.json = { - r: this.refs, - s: this.str - }; - return this.json; - } - }; - getRefs = function (token, refs) { - var i, list; - if (token.t === types.REFERENCE) { - if (refs.indexOf(token.n) === -1) { - refs.unshift(token.n); - } - } - list = token.o || token.m; - if (list) { - if (isObject(list)) { - getRefs(list, refs); - } else { - i = list.length; - while (i--) { - getRefs(list[i], refs); - } - } - } - if (token.x) { - getRefs(token.x, refs); - } - if (token.r) { - getRefs(token.r, refs); - } - if (token.v) { - getRefs(token.v, refs); - } - }; - stringify = function (token, refs) { - var map = function (item) { - return stringify(item, refs); - }; - switch (token.t) { - case types.BOOLEAN_LITERAL: - case types.GLOBAL: - case types.NUMBER_LITERAL: - return token.v; - case types.STRING_LITERAL: - return '\'' + token.v.replace(/'/g, '\\\'') + '\''; - case types.ARRAY_LITERAL: - return '[' + (token.m ? token.m.map(map).join(',') : '') + ']'; - case types.OBJECT_LITERAL: - return '{' + (token.m ? token.m.map(map).join(',') : '') + '}'; - case types.KEY_VALUE_PAIR: - return token.k + ':' + stringify(token.v, refs); - case types.PREFIX_OPERATOR: - return (token.s === 'typeof' ? 'typeof ' : token.s) + stringify(token.o, refs); - case types.INFIX_OPERATOR: - return stringify(token.o[0], refs) + (token.s.substr(0, 2) === 'in' ? ' ' + token.s + ' ' : token.s) + stringify(token.o[1], refs); - case types.INVOCATION: - return stringify(token.x, refs) + '(' + (token.o ? token.o.map(map).join(',') : '') + ')'; - case types.BRACKETED: - return '(' + stringify(token.x, refs) + ')'; - case types.MEMBER: - return stringify(token.x, refs) + stringify(token.r, refs); - case types.REFINEMENT: - return token.n ? '.' + token.n : '[' + stringify(token.x, refs) + ']'; - case types.CONDITIONAL: - return stringify(token.o[0], refs) + '?' + stringify(token.o[1], refs) + ':' + stringify(token.o[2], refs); - case types.REFERENCE: - return '${' + refs.indexOf(token.n) + '}'; - default: - throw new Error('Could not stringify expression token. This error is unexpected'); - } - }; - return ExpressionStub; - }(config_types, utils_isObject); -var parse_Parser_getMustache_MustacheStub__MustacheStub = function (types, ExpressionStub) { - - var MustacheStub = function (token, parser) { - this.type = token.type === types.TRIPLE ? types.TRIPLE : token.mustacheType; - if (token.ref) { - this.ref = token.ref; - } - if (token.expression) { - this.expr = new ExpressionStub(token.expression); - } - parser.pos += 1; - }; - MustacheStub.prototype = { - toJSON: function () { - var json; - if (this.json) { - return this.json; - } - json = { t: this.type }; - if (this.ref) { - json.r = this.ref; - } - if (this.expr) { - json.x = this.expr.toJSON(); - } - this.json = json; - return json; - }, - toString: function () { - return false; - } - }; - return MustacheStub; - }(config_types, parse_Parser_getMustache_ExpressionStub__ExpressionStub); -var parse_Parser_utils_stringifyStubs = function () { - - return function (items) { - var str = '', itemStr, i, len; - if (!items) { - return ''; - } - for (i = 0, len = items.length; i < len; i += 1) { - itemStr = items[i].toString(); - if (itemStr === false) { - return false; - } - str += itemStr; - } - return str; - }; - }(); -var parse_Parser_utils_jsonifyStubs = function (stringifyStubs) { - - return function (items, noStringify) { - var str, json; - if (!noStringify) { - str = stringifyStubs(items); - if (str !== false) { - return str; - } - } - json = items.map(function (item) { - return item.toJSON(noStringify); - }); - return json; - }; - }(parse_Parser_utils_stringifyStubs); -var parse_Parser_getMustache_SectionStub__SectionStub = function (types, jsonifyStubs, ExpressionStub) { - - var SectionStub = function (firstToken, parser) { - var next; - this.ref = firstToken.ref; - this.indexRef = firstToken.indexRef; - this.inverted = firstToken.mustacheType === types.INVERTED; - if (firstToken.expression) { - this.expr = new ExpressionStub(firstToken.expression); - } - parser.pos += 1; - this.items = []; - next = parser.next(); - while (next) { - if (next.mustacheType === types.CLOSING) { - if (next.ref.trim() === this.ref || this.expr) { - parser.pos += 1; - break; - } else { - throw new Error('Could not parse template: Illegal closing section'); - } - } - this.items[this.items.length] = parser.getStub(); - next = parser.next(); - } - }; - SectionStub.prototype = { - toJSON: function (noStringify) { - var json; - if (this.json) { - return this.json; - } - json = { t: types.SECTION }; - if (this.ref) { - json.r = this.ref; - } - if (this.indexRef) { - json.i = this.indexRef; - } - if (this.inverted) { - json.n = true; - } - if (this.expr) { - json.x = this.expr.toJSON(); - } - if (this.items.length) { - json.f = jsonifyStubs(this.items, noStringify); - } - this.json = json; - return json; - }, - toString: function () { - return false; - } - }; - return SectionStub; - }(config_types, parse_Parser_utils_jsonifyStubs, parse_Parser_getMustache_ExpressionStub__ExpressionStub); -var parse_Parser_getMustache__getMustache = function (types, MustacheStub, SectionStub) { - - return function (token) { - if (token.type === types.MUSTACHE || token.type === types.TRIPLE) { - if (token.mustacheType === types.SECTION || token.mustacheType === types.INVERTED) { - return new SectionStub(token, this); - } - return new MustacheStub(token, this); - } - }; - }(config_types, parse_Parser_getMustache_MustacheStub__MustacheStub, parse_Parser_getMustache_SectionStub__SectionStub); -var parse_Parser_getElement_ElementStub_utils_siblingsByTagName = function () { - - return { - li: ['li'], - dt: [ - 'dt', - 'dd' - ], - dd: [ - 'dt', - 'dd' - ], - p: 'address article aside blockquote dir div dl fieldset footer form h1 h2 h3 h4 h5 h6 header hgroup hr menu nav ol p pre section table ul'.split(' '), - rt: [ - 'rt', - 'rp' - ], - rp: [ - 'rp', - 'rt' - ], - optgroup: ['optgroup'], - option: [ - 'option', - 'optgroup' - ], - thead: [ - 'tbody', - 'tfoot' - ], - tbody: [ - 'tbody', - 'tfoot' - ], - tr: ['tr'], - td: [ - 'td', - 'th' - ], - th: [ - 'td', - 'th' - ] - }; - }(); -var parse_Parser_getElement_ElementStub_utils_filterAttributes = function (isArray) { - - return function (items) { - var attrs, proxies, filtered, i, len, item; - filtered = {}; - attrs = []; - proxies = []; - len = items.length; - for (i = 0; i < len; i += 1) { - item = items[i]; - if (item.name === 'intro') { - if (filtered.intro) { - throw new Error('An element can only have one intro transition'); - } - filtered.intro = item; - } else if (item.name === 'outro') { - if (filtered.outro) { - throw new Error('An element can only have one outro transition'); - } - filtered.outro = item; - } else if (item.name === 'intro-outro') { - if (filtered.intro || filtered.outro) { - throw new Error('An element can only have one intro and one outro transition'); - } - filtered.intro = item; - filtered.outro = deepClone(item); - } else if (item.name.substr(0, 6) === 'proxy-') { - item.name = item.name.substring(6); - proxies[proxies.length] = item; - } else if (item.name.substr(0, 3) === 'on-') { - item.name = item.name.substring(3); - proxies[proxies.length] = item; - } else if (item.name === 'decorator') { - filtered.decorator = item; - } else { - attrs[attrs.length] = item; - } - } - filtered.attrs = attrs; - filtered.proxies = proxies; - return filtered; - }; - function deepClone(obj) { - var result, key; - if (typeof obj !== 'object') { - return obj; - } - if (isArray(obj)) { - return obj.map(deepClone); - } - result = {}; - for (key in obj) { - if (obj.hasOwnProperty(key)) { - result[key] = deepClone(obj[key]); - } - } - return result; - } - }(utils_isArray); -var parse_Parser_getElement_ElementStub_utils_processDirective = function (types, parseJSON) { - - return function (directive) { - var processed, tokens, token, colonIndex, throwError, directiveName, directiveArgs, parsed; - throwError = function () { - throw new Error('Illegal directive'); - }; - if (!directive.name || !directive.value) { - throwError(); - } - processed = { directiveType: directive.name }; - tokens = directive.value; - directiveName = []; - directiveArgs = []; - while (tokens.length) { - token = tokens.shift(); - if (token.type === types.TEXT) { - colonIndex = token.value.indexOf(':'); - if (colonIndex === -1) { - directiveName[directiveName.length] = token; - } else { - if (colonIndex) { - directiveName[directiveName.length] = { - type: types.TEXT, - value: token.value.substr(0, colonIndex) - }; - } - if (token.value.length > colonIndex + 1) { - directiveArgs[0] = { - type: types.TEXT, - value: token.value.substring(colonIndex + 1) - }; - } - break; - } - } else { - directiveName[directiveName.length] = token; - } - } - directiveArgs = directiveArgs.concat(tokens); - if (directiveName.length === 1 && directiveName[0].type === types.TEXT) { - processed.name = directiveName[0].value; - } else { - processed.name = directiveName; - } - if (directiveArgs.length) { - if (directiveArgs.length === 1 && directiveArgs[0].type === types.TEXT) { - parsed = parseJSON('[' + directiveArgs[0].value + ']'); - processed.args = parsed ? parsed.value : directiveArgs[0].value; - } else { - processed.dynamicArgs = directiveArgs; - } - } - return processed; - }; - }(config_types, utils_parseJSON); -var parse_Parser_StringStub_StringParser = function (getText, getMustache) { - - var StringParser; - StringParser = function (tokens, options) { - var stub; - this.tokens = tokens || []; - this.pos = 0; - this.options = options; - this.result = []; - while (stub = this.getStub()) { - this.result.push(stub); - } - }; - StringParser.prototype = { - getStub: function () { - var token = this.next(); - if (!token) { - return null; - } - return this.getText(token) || this.getMustache(token); - }, - getText: getText, - getMustache: getMustache, - next: function () { - return this.tokens[this.pos]; - } - }; - return StringParser; - }(parse_Parser_getText__getText, parse_Parser_getMustache__getMustache); -var parse_Parser_StringStub__StringStub = function (StringParser, stringifyStubs, jsonifyStubs) { - - var StringStub; - StringStub = function (tokens) { - var parser = new StringParser(tokens); - this.stubs = parser.result; - }; - StringStub.prototype = { - toJSON: function (noStringify) { - var json; - if (this['json_' + noStringify]) { - return this['json_' + noStringify]; - } - json = this['json_' + noStringify] = jsonifyStubs(this.stubs, noStringify); - return json; - }, - toString: function () { - if (this.str !== undefined) { - return this.str; - } - this.str = stringifyStubs(this.stubs); - return this.str; - } - }; - return StringStub; - }(parse_Parser_StringStub_StringParser, parse_Parser_utils_stringifyStubs, parse_Parser_utils_jsonifyStubs); -var parse_Parser_getElement_ElementStub_utils_jsonifyDirective = function (StringStub) { - - return function (directive) { - var result, name; - if (typeof directive.name === 'string') { - if (!directive.args && !directive.dynamicArgs) { - return directive.name; - } - name = directive.name; - } else { - name = new StringStub(directive.name).toJSON(); - } - result = { n: name }; - if (directive.args) { - result.a = directive.args; - return result; - } - if (directive.dynamicArgs) { - result.d = new StringStub(directive.dynamicArgs).toJSON(); - } - return result; - }; - }(parse_Parser_StringStub__StringStub); -var parse_Parser_getElement_ElementStub_toJSON = function (types, jsonifyStubs, jsonifyDirective) { - - return function (noStringify) { - var json, name, value, proxy, i, len, attribute; - if (this['json_' + noStringify]) { - return this['json_' + noStringify]; - } - if (this.component) { - json = { - t: types.COMPONENT, - e: this.component - }; - } else { - json = { - t: types.ELEMENT, - e: this.tag - }; - } - if (this.doctype) { - json.y = 1; - } - if (this.attributes && this.attributes.length) { - json.a = {}; - len = this.attributes.length; - for (i = 0; i < len; i += 1) { - attribute = this.attributes[i]; - name = attribute.name; - if (json.a[name]) { - throw new Error('You cannot have multiple attributes with the same name'); - } - if (attribute.value === null) { - value = null; - } else { - value = attribute.value.toJSON(noStringify); - } - json.a[name] = value; - } - } - if (this.items && this.items.length) { - json.f = jsonifyStubs(this.items, noStringify); - } - if (this.proxies && this.proxies.length) { - json.v = {}; - len = this.proxies.length; - for (i = 0; i < len; i += 1) { - proxy = this.proxies[i]; - json.v[proxy.directiveType] = jsonifyDirective(proxy); - } - } - if (this.intro) { - json.t1 = jsonifyDirective(this.intro); - } - if (this.outro) { - json.t2 = jsonifyDirective(this.outro); - } - if (this.decorator) { - json.o = jsonifyDirective(this.decorator); - } - this['json_' + noStringify] = json; - return json; - }; - }(config_types, parse_Parser_utils_jsonifyStubs, parse_Parser_getElement_ElementStub_utils_jsonifyDirective); -var parse_Parser_getElement_ElementStub_toString = function (stringifyStubs, voidElementNames) { - - var htmlElements; - htmlElements = 'a abbr acronym address applet area b base basefont bdo big blockquote body br button caption center cite code col colgroup dd del dfn dir div dl dt em fieldset font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img input ins isindex kbd label legend li link map menu meta noframes noscript object ol p param pre q s samp script select small span strike strong style sub sup textarea title tt u ul var article aside audio bdi canvas command data datagrid datalist details embed eventsource figcaption figure footer header hgroup keygen mark meter nav output progress ruby rp rt section source summary time track video wbr'.split(' '); - return function () { - var str, i, len, attrStr, name, attrValueStr, fragStr, isVoid; - if (this.str !== undefined) { - return this.str; - } - if (this.component) { - return this.str = false; - } - if (htmlElements.indexOf(this.tag.toLowerCase()) === -1) { - return this.str = false; - } - if (this.proxies || this.intro || this.outro || this.decorator) { - return this.str = false; - } - fragStr = stringifyStubs(this.items); - if (fragStr === false) { - return this.str = false; - } - isVoid = voidElementNames.indexOf(this.tag.toLowerCase()) !== -1; - str = '<' + this.tag; - if (this.attributes) { - for (i = 0, len = this.attributes.length; i < len; i += 1) { - name = this.attributes[i].name; - if (name.indexOf(':') !== -1) { - return this.str = false; - } - if (name === 'id' || name === 'intro' || name === 'outro') { - return this.str = false; - } - attrStr = ' ' + name; - if (this.attributes[i].value !== null) { - attrValueStr = this.attributes[i].value.toString(); - if (attrValueStr === false) { - return this.str = false; - } - if (attrValueStr !== '') { - attrStr += '='; - if (/[\s"'=<>`]/.test(attrValueStr)) { - attrStr += '"' + attrValueStr.replace(/"/g, '"') + '"'; - } else { - attrStr += attrValueStr; - } - } - } - str += attrStr; - } - } - if (this.selfClosing && !isVoid) { - str += '/>'; - return this.str = str; - } - str += '>'; - if (isVoid) { - return this.str = str; - } - str += fragStr; - str += '' + this.tag + '>'; - return this.str = str; - }; - }(parse_Parser_utils_stringifyStubs, config_voidElementNames); -var parse_Parser_getElement_ElementStub__ElementStub = function (types, voidElementNames, warn, camelCase, stringifyStubs, siblingsByTagName, filterAttributes, processDirective, toJSON, toString, StringStub) { - - var ElementStub, allElementNames, closedByParentClose, onPattern, sanitize, leadingWhitespace = /^\s+/, trailingWhitespace = /\s+$/; - ElementStub = function (firstToken, parser, preserveWhitespace) { - var next, attrs, filtered, proxies, item, getFrag, lowerCaseTag; - parser.pos += 1; - getFrag = function (attr) { - return { - name: attr.name, - value: attr.value ? new StringStub(attr.value) : null - }; - }; - this.tag = firstToken.name; - lowerCaseTag = firstToken.name.toLowerCase(); - if (lowerCaseTag.substr(0, 3) === 'rv-') { - warn('The "rv-" prefix for components has been deprecated. Support will be removed in a future version'); - this.tag = this.tag.substring(3); - } - preserveWhitespace = preserveWhitespace || lowerCaseTag === 'pre'; - if (firstToken.attrs) { - filtered = filterAttributes(firstToken.attrs); - attrs = filtered.attrs; - proxies = filtered.proxies; - if (parser.options.sanitize && parser.options.sanitize.eventAttributes) { - attrs = attrs.filter(sanitize); - } - if (attrs.length) { - this.attributes = attrs.map(getFrag); - } - if (proxies.length) { - this.proxies = proxies.map(processDirective); - } - if (filtered.intro) { - this.intro = processDirective(filtered.intro); - } - if (filtered.outro) { - this.outro = processDirective(filtered.outro); - } - if (filtered.decorator) { - this.decorator = processDirective(filtered.decorator); - } - } - if (firstToken.doctype) { - this.doctype = true; - } - if (firstToken.selfClosing) { - this.selfClosing = true; - } - if (voidElementNames.indexOf(lowerCaseTag) !== -1) { - this.isVoid = true; - } - if (this.selfClosing || this.isVoid) { - return; - } - this.siblings = siblingsByTagName[lowerCaseTag]; - this.items = []; - next = parser.next(); - while (next) { - if (next.mustacheType === types.CLOSING) { - break; - } - if (next.type === types.TAG) { - if (next.closing) { - if (next.name.toLowerCase() === lowerCaseTag) { - parser.pos += 1; - } - break; - } else if (this.siblings && this.siblings.indexOf(next.name.toLowerCase()) !== -1) { - break; - } - } - this.items[this.items.length] = parser.getStub(); - next = parser.next(); - } - if (!preserveWhitespace) { - item = this.items[0]; - if (item && item.type === types.TEXT) { - item.text = item.text.replace(leadingWhitespace, ''); - if (!item.text) { - this.items.shift(); - } - } - item = this.items[this.items.length - 1]; - if (item && item.type === types.TEXT) { - item.text = item.text.replace(trailingWhitespace, ''); - if (!item.text) { - this.items.pop(); - } - } - } - }; - ElementStub.prototype = { - toJSON: toJSON, - toString: toString - }; - allElementNames = 'a abbr acronym address applet area b base basefont bdo big blockquote body br button caption center cite code col colgroup dd del dfn dir div dl dt em fieldset font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img input ins isindex kbd label legend li link map menu meta noframes noscript object ol p param pre q s samp script select small span strike strong style sub sup textarea title tt u ul var article aside audio bdi canvas command data datagrid datalist details embed eventsource figcaption figure footer header hgroup keygen mark meter nav output progress ruby rp rt section source summary time track video wbr'.split(' '); - closedByParentClose = 'li dd rt rp optgroup option tbody tfoot tr td th'.split(' '); - onPattern = /^on[a-zA-Z]/; - sanitize = function (attr) { - var valid = !onPattern.test(attr.name); - return valid; - }; - return ElementStub; - }(config_types, config_voidElementNames, utils_warn, utils_camelCase, parse_Parser_utils_stringifyStubs, parse_Parser_getElement_ElementStub_utils_siblingsByTagName, parse_Parser_getElement_ElementStub_utils_filterAttributes, parse_Parser_getElement_ElementStub_utils_processDirective, parse_Parser_getElement_ElementStub_toJSON, parse_Parser_getElement_ElementStub_toString, parse_Parser_StringStub__StringStub); -var parse_Parser_getElement__getElement = function (types, ElementStub) { - - return function (token) { - if (this.options.sanitize && this.options.sanitize.elements) { - if (this.options.sanitize.elements.indexOf(token.name.toLowerCase()) !== -1) { - return null; - } - } - return new ElementStub(token, this); - }; - }(config_types, parse_Parser_getElement_ElementStub__ElementStub); -var parse_Parser__Parser = function (getText, getComment, getMustache, getElement, jsonifyStubs) { - - var Parser; - Parser = function (tokens, options) { - var stub, stubs; - this.tokens = tokens || []; - this.pos = 0; - this.options = options; - this.preserveWhitespace = options.preserveWhitespace; - stubs = []; - while (stub = this.getStub()) { - stubs.push(stub); - } - this.result = jsonifyStubs(stubs); - }; - Parser.prototype = { - getStub: function () { - var token = this.next(); - if (!token) { - return null; - } - return this.getText(token) || this.getComment(token) || this.getMustache(token) || this.getElement(token); - }, - getText: getText, - getComment: getComment, - getMustache: getMustache, - getElement: getElement, - next: function () { - return this.tokens[this.pos]; - } - }; - return Parser; - }(parse_Parser_getText__getText, parse_Parser_getComment__getComment, parse_Parser_getMustache__getMustache, parse_Parser_getElement__getElement, parse_Parser_utils_jsonifyStubs); -var parse__parse = function (tokenize, types, Parser) { - - var parse, onlyWhitespace, inlinePartialStart, inlinePartialEnd, parseCompoundTemplate; - onlyWhitespace = /^\s*$/; - inlinePartialStart = //; - inlinePartialEnd = //; - parse = function (template, options) { - var tokens, json, token; - options = options || {}; - if (inlinePartialStart.test(template)) { - return parseCompoundTemplate(template, options); - } - if (options.sanitize === true) { - options.sanitize = { - elements: 'applet base basefont body frame frameset head html isindex link meta noframes noscript object param script style title'.split(' '), - eventAttributes: true - }; - } - tokens = tokenize(template, options); - if (!options.preserveWhitespace) { - token = tokens[0]; - if (token && token.type === types.TEXT && onlyWhitespace.test(token.value)) { - tokens.shift(); - } - token = tokens[tokens.length - 1]; - if (token && token.type === types.TEXT && onlyWhitespace.test(token.value)) { - tokens.pop(); - } - } - json = new Parser(tokens, options).result; - if (typeof json === 'string') { - return [json]; - } - return json; - }; - parseCompoundTemplate = function (template, options) { - var mainTemplate, remaining, partials, name, startMatch, endMatch; - partials = {}; - mainTemplate = ''; - remaining = template; - while (startMatch = inlinePartialStart.exec(remaining)) { - name = startMatch[1]; - mainTemplate += remaining.substr(0, startMatch.index); - remaining = remaining.substring(startMatch.index + startMatch[0].length); - endMatch = inlinePartialEnd.exec(remaining); - if (!endMatch || endMatch[1] !== name) { - throw new Error('Inline partials must have a closing delimiter, and cannot be nested'); - } - partials[name] = parse(remaining.substr(0, endMatch.index), options); - remaining = remaining.substring(endMatch.index + endMatch[0].length); - } - return { - main: parse(mainTemplate, options), - partials: partials - }; - }; - return parse; - }(parse_tokenize, config_types, parse_Parser__Parser); -var render_DomFragment_Partial_getPartialDescriptor = function (errors, isClient, warn, isObject, partials, parse) { - - var getPartialDescriptor, registerPartial, getPartialFromRegistry, unpack; - getPartialDescriptor = function (root, name) { - var el, partial, errorMessage; - if (partial = getPartialFromRegistry(root, name)) { - return partial; - } - if (isClient) { - el = document.getElementById(name); - if (el && el.tagName === 'SCRIPT') { - if (!parse) { - throw new Error(errors.missingParser); - } - registerPartial(parse(el.innerHTML), name, partials); - } - } - partial = partials[name]; - if (!partial) { - errorMessage = 'Could not find descriptor for partial "' + name + '"'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - return []; - } - return unpack(partial); - }; - getPartialFromRegistry = function (registryOwner, name) { - var partial; - if (registryOwner.partials[name]) { - if (typeof registryOwner.partials[name] === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - partial = parse(registryOwner.partials[name], registryOwner.parseOptions); - registerPartial(partial, name, registryOwner.partials); - } - return unpack(registryOwner.partials[name]); - } - }; - registerPartial = function (partial, name, registry) { - var key; - if (isObject(partial)) { - registry[name] = partial.main; - for (key in partial.partials) { - if (partial.partials.hasOwnProperty(key)) { - registry[key] = partial.partials[key]; - } - } - } else { - registry[name] = partial; - } - }; - unpack = function (partial) { - if (partial.length === 1 && typeof partial[0] === 'string') { - return partial[0]; - } - return partial; - }; - return getPartialDescriptor; - }(config_errors, config_isClient, utils_warn, utils_isObject, registries_partials, parse__parse); -var render_DomFragment_Partial__Partial = function (types, getPartialDescriptor, circular) { - - var DomPartial, DomFragment; - circular.push(function () { - DomFragment = circular.DomFragment; - }); - DomPartial = function (options, docFrag) { - var parentFragment = this.parentFragment = options.parentFragment, descriptor; - this.type = types.PARTIAL; - this.name = options.descriptor.r; - this.index = options.index; - if (!options.descriptor.r) { - throw new Error('Partials must have a static reference (no expressions). This may change in a future version of Ractive.'); - } - descriptor = getPartialDescriptor(parentFragment.root, options.descriptor.r); - this.fragment = new DomFragment({ - descriptor: descriptor, - root: parentFragment.root, - pNode: parentFragment.pNode, - contextStack: parentFragment.contextStack, - owner: this - }); - if (docFrag) { - docFrag.appendChild(this.fragment.docFrag); - } - }; - DomPartial.prototype = { - firstNode: function () { - return this.fragment.firstNode(); - }, - findNextNode: function () { - return this.parentFragment.findNextNode(this); - }, - detach: function () { - return this.fragment.detach(); - }, - teardown: function (destroy) { - this.fragment.teardown(destroy); - }, - toString: function () { - return this.fragment.toString(); - }, - find: function (selector) { - return this.fragment.find(selector); - }, - findAll: function (selector, query) { - return this.fragment.findAll(selector, query); - }, - findComponent: function (selector) { - return this.fragment.findComponent(selector); - }, - findAllComponents: function (selector, query) { - return this.fragment.findAllComponents(selector, query); - } - }; - return DomPartial; - }(config_types, render_DomFragment_Partial_getPartialDescriptor, circular); -var render_DomFragment_Component_initialise_createModel_ComponentParameter = function (StringFragment) { - - var ComponentParameter = function (component, key, value) { - this.parentFragment = component.parentFragment; - this.component = component; - this.key = key; - this.fragment = new StringFragment({ - descriptor: value, - root: component.root, - owner: this, - contextStack: component.parentFragment.contextStack - }); - this.selfUpdating = this.fragment.isSimple(); - this.value = this.fragment.getValue(); - }; - ComponentParameter.prototype = { - bubble: function () { - if (this.selfUpdating) { - this.update(); - } else if (!this.deferred && this.ready) { - this.root._deferred.attrs.push(this); - this.deferred = true; - } - }, - update: function () { - var value = this.fragment.getValue(); - this.component.instance.set(this.key, value); - this.value = value; - }, - teardown: function () { - this.fragment.teardown(); - } - }; - return ComponentParameter; - }(render_StringFragment__StringFragment); -var render_DomFragment_Component_initialise_createModel__createModel = function (types, parseJSON, resolveRef, ComponentParameter) { - - return function (component, attributes, toBind) { - var data, key, value; - data = {}; - component.complexParameters = []; - for (key in attributes) { - if (attributes.hasOwnProperty(key)) { - value = getValue(component, key, attributes[key], toBind); - if (value !== undefined) { - data[key] = value; - } - } - } - return data; - }; - function getValue(component, key, descriptor, toBind) { - var parameter, parsed, root, parentFragment, keypath; - root = component.root; - parentFragment = component.parentFragment; - if (typeof descriptor === 'string') { - parsed = parseJSON(descriptor); - return parsed ? parsed.value : descriptor; - } - if (descriptor === null) { - return true; - } - if (descriptor.length === 1 && descriptor[0].t === types.INTERPOLATOR && descriptor[0].r) { - if (parentFragment.indexRefs && parentFragment.indexRefs[descriptor[0].r] !== undefined) { - return parentFragment.indexRefs[descriptor[0].r]; - } - keypath = resolveRef(root, descriptor[0].r, parentFragment.contextStack) || descriptor[0].r; - toBind.push({ - childKeypath: key, - parentKeypath: keypath - }); - return root.get(keypath); - } - parameter = new ComponentParameter(component, key, descriptor); - component.complexParameters.push(parameter); - return parameter.value; - } - }(config_types, utils_parseJSON, shared_resolveRef, render_DomFragment_Component_initialise_createModel_ComponentParameter); -var render_DomFragment_Component_initialise_createInstance = function () { - - return function (component, Component, data, docFrag, contentDescriptor) { - var instance, parentFragment, partials, root; - parentFragment = component.parentFragment; - root = component.root; - partials = { content: contentDescriptor || [] }; - instance = new Component({ - el: parentFragment.pNode.cloneNode(false), - data: data, - partials: partials, - _parent: root, - adaptors: root.adaptors - }); - instance.component = component; - component.instance = instance; - instance.insert(docFrag); - instance.fragment.pNode = parentFragment.pNode; - return instance; - }; - }(); -var render_DomFragment_Component_initialise_createObservers = function () { - - var observeOptions = { - init: false, - debug: true - }; - return function (component, toBind) { - var pair, i; - component.observers = []; - i = toBind.length; - while (i--) { - pair = toBind[i]; - bind(component, pair.parentKeypath, pair.childKeypath); - } - }; - function bind(component, parentKeypath, childKeypath) { - var parentInstance, childInstance, settingParent, settingChild, observers, observer, value; - parentInstance = component.root; - childInstance = component.instance; - observers = component.observers; - observer = parentInstance.observe(parentKeypath, function (value) { - if (!settingParent && !parentInstance._wrapped[parentKeypath]) { - settingChild = true; - childInstance.set(childKeypath, value); - settingChild = false; - } - }, observeOptions); - observers.push(observer); - if (childInstance.twoway) { - observer = childInstance.observe(childKeypath, function (value) { - if (!settingChild) { - settingParent = true; - parentInstance.set(parentKeypath, value); - settingParent = false; - } - }, observeOptions); - observers.push(observer); - value = childInstance.get(childKeypath); - if (value !== undefined) { - parentInstance.set(parentKeypath, value); - } - } - } - }(); -var render_DomFragment_Component_initialise_propagateEvents = function (warn) { - - var errorMessage = 'Components currently only support simple events - you cannot include arguments. Sorry!'; - return function (component, eventsDescriptor) { - var eventName; - for (eventName in eventsDescriptor) { - if (eventsDescriptor.hasOwnProperty(eventName)) { - propagateEvent(component.instance, component.root, eventName, eventsDescriptor[eventName]); - } - } - }; - function propagateEvent(childInstance, parentInstance, eventName, proxyEventName) { - if (typeof proxyEventName !== 'string') { - if (parentInstance.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - return; - } - } - childInstance.on(eventName, function () { - var args = Array.prototype.slice.call(arguments); - args.unshift(proxyEventName); - parentInstance.fire.apply(parentInstance, args); - }); - } - }(utils_warn); -var render_DomFragment_Component_initialise_updateLiveQueries = function () { - - return function (component) { - var ancestor, query; - ancestor = component.root; - while (ancestor) { - if (query = ancestor._liveComponentQueries[component.name]) { - query.push(component.instance); - } - ancestor = ancestor._parent; - } - }; - }(); -var render_DomFragment_Component_initialise__initialise = function (types, warn, createModel, createInstance, createObservers, propagateEvents, updateLiveQueries) { - - return function (component, options, docFrag) { - var parentFragment, root, Component, data, toBind; - parentFragment = component.parentFragment = options.parentFragment; - root = parentFragment.root; - component.root = root; - component.type = types.COMPONENT; - component.name = options.descriptor.e; - component.index = options.index; - component.observers = []; - Component = root.components[options.descriptor.e]; - if (!Component) { - throw new Error('Component "' + options.descriptor.e + '" not found'); - } - toBind = []; - data = createModel(component, options.descriptor.a, toBind); - createInstance(component, Component, data, docFrag, options.descriptor.f); - createObservers(component, toBind); - propagateEvents(component, options.descriptor.v); - if (options.descriptor.t1 || options.descriptor.t2 || options.descriptor.o) { - warn('The "intro", "outro" and "decorator" directives have no effect on components'); - } - updateLiveQueries(component); - }; - }(config_types, utils_warn, render_DomFragment_Component_initialise_createModel__createModel, render_DomFragment_Component_initialise_createInstance, render_DomFragment_Component_initialise_createObservers, render_DomFragment_Component_initialise_propagateEvents, render_DomFragment_Component_initialise_updateLiveQueries); -var render_DomFragment_Component__Component = function (initialise) { - - var DomComponent = function (options, docFrag) { - initialise(this, options, docFrag); - }; - DomComponent.prototype = { - firstNode: function () { - return this.instance.fragment.firstNode(); - }, - findNextNode: function () { - return this.parentFragment.findNextNode(this); - }, - detach: function () { - return this.instance.fragment.detach(); - }, - teardown: function () { - var query; - while (this.complexParameters.length) { - this.complexParameters.pop().teardown(); - } - while (this.observers.length) { - this.observers.pop().cancel(); - } - if (query = this.root._liveComponentQueries[this.name]) { - query._remove(this); - } - this.instance.teardown(); - }, - toString: function () { - return this.instance.fragment.toString(); - }, - find: function (selector) { - return this.instance.fragment.find(selector); - }, - findAll: function (selector, query) { - return this.instance.fragment.findAll(selector, query); - }, - findComponent: function (selector) { - if (!selector || selector === this.name) { - return this.instance; - } - return null; - }, - findAllComponents: function (selector, query) { - query._test(this, true); - if (this.instance.fragment) { - this.instance.fragment.findAllComponents(selector, query); - } - } - }; - return DomComponent; - }(render_DomFragment_Component_initialise__initialise); -var render_DomFragment_Comment = function (types) { - - var DomComment = function (options, docFrag) { - this.type = types.COMMENT; - this.descriptor = options.descriptor; - if (docFrag) { - this.node = document.createComment(options.descriptor.f); - docFrag.appendChild(this.node); - } - }; - DomComment.prototype = { - detach: function () { - this.node.parentNode.removeChild(this.node); - return this.node; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - } - }, - firstNode: function () { - return this.node; - }, - toString: function () { - return ''; - } - }; - return DomComment; - }(config_types); -var render_DomFragment__DomFragment = function (types, matches, initFragment, insertHtml, Text, Interpolator, Section, Triple, Element, Partial, Component, Comment, circular) { - - var DomFragment = function (options) { - if (options.pNode) { - this.docFrag = document.createDocumentFragment(); - } - if (typeof options.descriptor === 'string') { - this.html = options.descriptor; - if (this.docFrag) { - this.nodes = insertHtml(this.html, options.pNode.tagName, this.docFrag); - } - } else { - initFragment(this, options); - } - }; - DomFragment.prototype = { - detach: function () { - var len, i; - if (this.nodes) { - i = this.nodes.length; - while (i--) { - this.docFrag.appendChild(this.nodes[i]); - } - } else if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - this.docFrag.appendChild(this.items[i].detach()); - } - } - return this.docFrag; - }, - createItem: function (options) { - if (typeof options.descriptor === 'string') { - return new Text(options, this.docFrag); - } - switch (options.descriptor.t) { - case types.INTERPOLATOR: - return new Interpolator(options, this.docFrag); - case types.SECTION: - return new Section(options, this.docFrag); - case types.TRIPLE: - return new Triple(options, this.docFrag); - case types.ELEMENT: - if (this.root.components[options.descriptor.e]) { - return new Component(options, this.docFrag); - } - return new Element(options, this.docFrag); - case types.PARTIAL: - return new Partial(options, this.docFrag); - case types.COMMENT: - return new Comment(options, this.docFrag); - default: - throw new Error('Something very strange happened. Please file an issue at https://github.com/RactiveJS/Ractive/issues. Thanks!'); - } - }, - teardown: function (destroy) { - var node; - if (this.nodes && destroy) { - while (node = this.nodes.pop()) { - node.parentNode.removeChild(node); - } - } else if (this.items) { - while (this.items.length) { - this.items.pop().teardown(destroy); - } - } - this.nodes = this.items = this.docFrag = null; - }, - firstNode: function () { - if (this.items && this.items[0]) { - return this.items[0].firstNode(); - } else if (this.nodes) { - return this.nodes[0] || null; - } - return null; - }, - findNextNode: function (item) { - var index = item.index; - if (this.items[index + 1]) { - return this.items[index + 1].firstNode(); - } - if (this.owner === this.root) { - if (!this.owner.component) { - return null; - } - return this.owner.component.findNextNode(); - } - return this.owner.findNextNode(this); - }, - toString: function () { - var html, i, len, item; - if (this.html) { - return this.html; - } - html = ''; - if (!this.items) { - return html; - } - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - html += item.toString(); - } - return html; - }, - find: function (selector) { - var i, len, item, node, queryResult; - if (this.nodes) { - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - return node; - } - if (queryResult = node.querySelector(selector)) { - return queryResult; - } - } - return null; - } - if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.find && (queryResult = item.find(selector))) { - return queryResult; - } - } - return null; - } - }, - findAll: function (selector, query) { - var i, len, item, node, queryAllResult, numNodes, j; - if (this.nodes) { - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - query.push(node); - } - if (queryAllResult = node.querySelectorAll(selector)) { - numNodes = queryAllResult.length; - for (j = 0; j < numNodes; j += 1) { - query.push(queryAllResult[j]); - } - } - } - } else if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.findAll) { - item.findAll(selector, query); - } - } - } - return query; - }, - findComponent: function (selector) { - var len, i, item, queryResult; - if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.findComponent && (queryResult = item.findComponent(selector))) { - return queryResult; - } - } - return null; - } - }, - findAllComponents: function (selector, query) { - var i, len, item; - if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.findAllComponents) { - item.findAllComponents(selector, query); - } - } - } - return query; - } - }; - circular.DomFragment = DomFragment; - return DomFragment; - }(config_types, utils_matches, render_shared_initFragment, render_DomFragment_shared_insertHtml, render_DomFragment_Text, render_DomFragment_Interpolator, render_DomFragment_Section__Section, render_DomFragment_Triple, render_DomFragment_Element__Element, render_DomFragment_Partial__Partial, render_DomFragment_Component__Component, render_DomFragment_Comment, circular); -var Ractive_prototype_render = function (getElement, makeTransitionManager, preDomUpdate, postDomUpdate, DomFragment) { - - return function (target, complete) { - var transitionManager; - if (!this._initing) { - throw new Error('You cannot call ractive.render() directly!'); - } - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - this.fragment = new DomFragment({ - descriptor: this.template, - root: this, - owner: this, - pNode: target - }); - preDomUpdate(this); - if (target) { - target.appendChild(this.fragment.docFrag); - } - postDomUpdate(this); - this._transitionManager = null; - transitionManager.ready(); - this.rendered = true; - }; - }(utils_getElement, shared_makeTransitionManager, shared_preDomUpdate, shared_postDomUpdate, render_DomFragment__DomFragment); -var Ractive_prototype_renderHTML = function (warn) { - - return function () { - warn('renderHTML() has been deprecated and will be removed in a future version. Please use toHTML() instead'); - return this.toHTML(); - }; - }(utils_warn); -var Ractive_prototype_toHTML = function () { - - return function () { - return this.fragment.toString(); - }; - }(); -var Ractive_prototype_teardown = function (makeTransitionManager, clearCache) { - - return function (complete) { - var keypath, transitionManager, previousTransitionManager; - this.fire('teardown'); - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - this.fragment.teardown(true); - while (this._animations[0]) { - this._animations[0].stop(); - } - for (keypath in this._cache) { - clearCache(this, keypath); - } - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - }; - }(shared_makeTransitionManager, shared_clearCache); -var Ractive_prototype_shared_add = function (isNumeric) { - - return function (root, keypath, d) { - var value; - if (typeof keypath !== 'string' || !isNumeric(d)) { - if (root.debug) { - throw new Error('Bad arguments'); - } - return; - } - value = root.get(keypath); - if (value === undefined) { - value = 0; - } - if (!isNumeric(value)) { - if (root.debug) { - throw new Error('Cannot add to a non-numeric value'); - } - return; - } - root.set(keypath, value + d); - }; - }(utils_isNumeric); -var Ractive_prototype_add = function (add) { - - return function (keypath, d) { - add(this, keypath, d === undefined ? 1 : d); - }; - }(Ractive_prototype_shared_add); -var Ractive_prototype_subtract = function (add) { - - return function (keypath, d) { - add(this, keypath, d === undefined ? -1 : -d); - }; - }(Ractive_prototype_shared_add); -var Ractive_prototype_toggle = function () { - - return function (keypath) { - var value; - if (typeof keypath !== 'string') { - if (this.debug) { - throw new Error('Bad arguments'); - } - return; - } - value = this.get(keypath); - this.set(keypath, !value); - }; - }(); -var Ractive_prototype_merge_mapOldToNewIndex = function () { - - return function (oldArray, newArray) { - var usedIndices, mapper, firstUnusedIndex, newIndices, changed; - usedIndices = {}; - firstUnusedIndex = 0; - mapper = function (item, i) { - var index, start, len; - start = firstUnusedIndex; - len = newArray.length; - do { - index = newArray.indexOf(item, start); - if (index === -1) { - changed = true; - return -1; - } - start = index + 1; - } while (usedIndices[index] && start < len); - if (index === firstUnusedIndex) { - firstUnusedIndex += 1; - } - if (index !== i) { - changed = true; - } - usedIndices[index] = true; - return index; - }; - newIndices = oldArray.map(mapper); - newIndices.unchanged = !changed; - return newIndices; - }; - }(); -var Ractive_prototype_merge_queueDependants = function (types) { - - return function queueDependants(keypath, deps, mergeQueue, updateQueue) { - var i, dependant; - i = deps.length; - while (i--) { - dependant = deps[i]; - if (dependant.type === types.REFERENCE) { - dependant.update(); - } else if (dependant.keypath === keypath && dependant.type === types.SECTION && !dependant.inverted && dependant.docFrag) { - mergeQueue[mergeQueue.length] = dependant; - } else { - updateQueue[updateQueue.length] = dependant; - } - } - }; - }(config_types); -var Ractive_prototype_merge__merge = function (warn, isArray, clearCache, preDomUpdate, processDeferredUpdates, makeTransitionManager, notifyDependants, replaceData, mapOldToNewIndex, queueDependants) { - - var identifiers = {}; - return function (keypath, array, options) { - var currentArray, oldArray, newArray, identifier, lengthUnchanged, i, newIndices, mergeQueue, updateQueue, depsByKeypath, deps, transitionManager, previousTransitionManager, upstreamQueue, keys; - currentArray = this.get(keypath); - if (!isArray(currentArray) || !isArray(array)) { - return this.set(keypath, array, options && options.complete); - } - lengthUnchanged = currentArray.length === array.length; - if (options && options.compare) { - if (options.compare === true) { - identifier = stringify; - } else if (typeof options.compare === 'string') { - identifier = getIdentifier(options.compare); - } else if (typeof options.compare == 'function') { - identifier = options.compare; - } else { - throw new Error('The `compare` option must be a function, or a string representing an identifying field (or `true` to use JSON.stringify)'); - } - try { - oldArray = currentArray.map(identifier); - newArray = array.map(identifier); - } catch (err) { - if (this.debug) { - throw err; - } else { - warn('Merge operation: comparison failed. Falling back to identity checking'); - } - oldArray = currentArray; - newArray = array; - } - } else { - oldArray = currentArray; - newArray = array; - } - newIndices = mapOldToNewIndex(oldArray, newArray); - clearCache(this, keypath); - replaceData(this, keypath, array); - if (newIndices.unchanged && lengthUnchanged) { - return; - } - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, options && options.complete); - mergeQueue = []; - updateQueue = []; - for (i = 0; i < this._deps.length; i += 1) { - depsByKeypath = this._deps[i]; - if (!depsByKeypath) { - continue; - } - deps = depsByKeypath[keypath]; - if (deps) { - queueDependants(keypath, deps, mergeQueue, updateQueue); - preDomUpdate(this); - while (mergeQueue.length) { - mergeQueue.pop().merge(newIndices); - } - while (updateQueue.length) { - updateQueue.pop().update(); - } - } - } - processDeferredUpdates(this); - upstreamQueue = []; - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - upstreamQueue[upstreamQueue.length] = keys.join('.'); - } - notifyDependants.multiple(this, upstreamQueue, true); - if (oldArray.length !== newArray.length) { - notifyDependants(this, keypath + '.length', true); - } - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - }; - function stringify(item) { - return JSON.stringify(item); - } - function getIdentifier(str) { - if (!identifiers[str]) { - identifiers[str] = function (item) { - return item[str]; - }; - } - return identifiers[str]; - } - }(utils_warn, utils_isArray, shared_clearCache, shared_preDomUpdate, shared_processDeferredUpdates, shared_makeTransitionManager, shared_notifyDependants, Ractive_prototype_shared_replaceData, Ractive_prototype_merge_mapOldToNewIndex, Ractive_prototype_merge_queueDependants); -var Ractive_prototype_detach = function () { - - return function () { - return this.fragment.detach(); - }; - }(); -var Ractive_prototype_insert = function (getElement) { - - return function (target, anchor) { - target = getElement(target); - anchor = getElement(anchor) || null; - if (!target) { - throw new Error('You must specify a valid target to insert into'); - } - target.insertBefore(this.detach(), anchor); - this.fragment.pNode = target; - }; - }(utils_getElement); -var Ractive_prototype__prototype = function (get, set, update, updateModel, animate, on, off, observe, fire, find, findAll, findComponent, findAllComponents, render, renderHTML, toHTML, teardown, add, subtract, toggle, merge, detach, insert) { - - return { - get: get, - set: set, - update: update, - updateModel: updateModel, - animate: animate, - on: on, - off: off, - observe: observe, - fire: fire, - find: find, - findAll: findAll, - findComponent: findComponent, - findAllComponents: findAllComponents, - renderHTML: renderHTML, - toHTML: toHTML, - render: render, - teardown: teardown, - add: add, - subtract: subtract, - toggle: toggle, - merge: merge, - detach: detach, - insert: insert - }; - }(Ractive_prototype_get__get, Ractive_prototype_set, Ractive_prototype_update, Ractive_prototype_updateModel, Ractive_prototype_animate__animate, Ractive_prototype_on, Ractive_prototype_off, Ractive_prototype_observe__observe, Ractive_prototype_fire, Ractive_prototype_find, Ractive_prototype_findAll, Ractive_prototype_findComponent, Ractive_prototype_findAllComponents, Ractive_prototype_render, Ractive_prototype_renderHTML, Ractive_prototype_toHTML, Ractive_prototype_teardown, Ractive_prototype_add, Ractive_prototype_subtract, Ractive_prototype_toggle, Ractive_prototype_merge__merge, Ractive_prototype_detach, Ractive_prototype_insert); -var extend_registries = function () { - - return [ - 'partials', - 'transitions', - 'events', - 'components', - 'decorators', - 'data' - ]; - }(); -var extend_initOptions = function () { - - return [ - 'el', - 'template', - 'complete', - 'modifyArrays', - 'magic', - 'twoway', - 'lazy', - 'append', - 'preserveWhitespace', - 'sanitize', - 'stripComments', - 'noIntro', - 'transitionsEnabled', - 'adaptors' - ]; - }(); -var extend_inheritFromParent = function (registries, initOptions, create) { - - return function (Child, Parent) { - registries.forEach(function (property) { - if (Parent[property]) { - Child[property] = create(Parent[property]); - } - }); - initOptions.forEach(function (property) { - Child[property] = Parent[property]; - }); - }; - }(extend_registries, extend_initOptions, utils_create); -var extend_wrapMethod = function () { - - return function (method, superMethod) { - if (/_super/.test(method)) { - return function () { - var _super = this._super, result; - this._super = superMethod; - result = method.apply(this, arguments); - this._super = _super; - return result; - }; - } else { - return method; - } - }; - }(); -var extend_utils_augment = function () { - - return function (target, source) { - var key; - for (key in source) { - if (source.hasOwnProperty(key)) { - target[key] = source[key]; - } - } - return target; - }; - }(); -var extend_inheritFromChildProps = function (registries, initOptions, wrapMethod, augment) { - - var blacklist, blacklisted; - blacklist = registries.concat(initOptions); - blacklisted = {}; - blacklist.forEach(function (property) { - blacklisted[property] = true; - }); - return function (Child, childProps) { - var key, member; - registries.forEach(function (property) { - var value = childProps[property]; - if (value) { - if (Child[property]) { - augment(Child[property], value); - } else { - Child[property] = value; - } - } - }); - initOptions.forEach(function (property) { - var value = childProps[property]; - if (value !== undefined) { - if (typeof value === 'function' && typeof Child[property] === 'function') { - Child[property] = wrapMethod(value, Child[property]); - } else { - Child[property] = childProps[property]; - } - } - }); - for (key in childProps) { - if (childProps.hasOwnProperty(key) && !blacklisted[key]) { - member = childProps[key]; - if (typeof member === 'function' && typeof Child.prototype[key] === 'function') { - Child.prototype[key] = wrapMethod(member, Child.prototype[key]); - } else { - Child.prototype[key] = member; - } - } - } - }; - }(extend_registries, extend_initOptions, extend_wrapMethod, extend_utils_augment); -var extend_extractInlinePartials = function (isObject, augment) { - - return function (Child, childProps) { - if (isObject(Child.template)) { - if (!Child.partials) { - Child.partials = {}; - } - augment(Child.partials, Child.template.partials); - if (childProps.partials) { - augment(Child.partials, childProps.partials); - } - Child.template = Child.template.main; - } - }; - }(utils_isObject, extend_utils_augment); -var extend_conditionallyParseTemplate = function (errors, isClient, parse) { - - return function (Child) { - var templateEl; - if (typeof Child.template === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - if (Child.template.charAt(0) === '#' && isClient) { - templateEl = document.getElementById(Child.template.substring(1)); - if (templateEl && templateEl.tagName === 'SCRIPT') { - Child.template = parse(templateEl.innerHTML, Child); - } else { - throw new Error('Could not find template element (' + Child.template + ')'); - } - } else { - Child.template = parse(Child.template, Child); - } - } - }; - }(config_errors, config_isClient, parse__parse); -var extend_conditionallyParsePartials = function (errors, parse) { - - return function (Child) { - var key; - if (Child.partials) { - for (key in Child.partials) { - if (Child.partials.hasOwnProperty(key) && typeof Child.partials[key] === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - Child.partials[key] = parse(Child.partials[key], Child); - } - } - } - }; - }(config_errors, parse__parse); -var extend_utils_clone = function () { - - return function (source) { - var target = {}, key; - for (key in source) { - if (source.hasOwnProperty(key)) { - target[key] = source[key]; - } - } - return target; - }; - }(); -var utils_extend = function () { - - return function (target) { - var prop, source, sources = Array.prototype.slice.call(arguments, 1); - while (source = sources.shift()) { - for (prop in source) { - if (source.hasOwnProperty(prop)) { - target[prop] = source[prop]; - } - } - } - return target; - }; - }(); -var Ractive_initialise = function (isClient, errors, warn, create, extend, defineProperty, defineProperties, getElement, isObject, magicAdaptor, parse) { - - var getObject, getArray, defaultOptions, registries; - getObject = function () { - return {}; - }; - getArray = function () { - return []; - }; - defaultOptions = create(null); - defineProperties(defaultOptions, { - preserveWhitespace: { - enumerable: true, - value: false - }, - append: { - enumerable: true, - value: false - }, - twoway: { - enumerable: true, - value: true - }, - modifyArrays: { - enumerable: true, - value: true - }, - data: { - enumerable: true, - value: getObject - }, - lazy: { - enumerable: true, - value: false - }, - debug: { - enumerable: true, - value: false - }, - transitions: { - enumerable: true, - value: getObject - }, - decorators: { - enumerable: true, - value: getObject - }, - events: { - enumerable: true, - value: getObject - }, - noIntro: { - enumerable: true, - value: false - }, - transitionsEnabled: { - enumerable: true, - value: true - }, - magic: { - enumerable: true, - value: false - }, - adaptors: { - enumerable: true, - value: getArray - } - }); - registries = [ - 'components', - 'decorators', - 'events', - 'partials', - 'transitions', - 'data' - ]; - return function (ractive, options) { - var key, template, templateEl, parsedTemplate; - for (key in defaultOptions) { - if (options[key] === undefined) { - options[key] = typeof defaultOptions[key] === 'function' ? defaultOptions[key]() : defaultOptions[key]; - } - } - defineProperties(ractive, { - _initing: { - value: true, - writable: true - }, - _guid: { - value: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { - var r, v; - r = Math.random() * 16 | 0; - v = c == 'x' ? r : r & 3 | 8; - return v.toString(16); - }) - }, - _subs: { - value: create(null), - configurable: true - }, - _cache: { value: {} }, - _cacheMap: { value: create(null) }, - _deps: { value: [] }, - _depsMap: { value: create(null) }, - _patternObservers: { value: [] }, - _pendingResolution: { value: [] }, - _deferred: { value: {} }, - _evaluators: { value: create(null) }, - _twowayBindings: { value: {} }, - _transitionManager: { - value: null, - writable: true - }, - _animations: { value: [] }, - nodes: { value: {} }, - _wrapped: { value: create(null) }, - _liveQueries: { value: [] }, - _liveComponentQueries: { value: [] } - }); - defineProperties(ractive._deferred, { - attrs: { value: [] }, - evals: { value: [] }, - selectValues: { value: [] }, - checkboxes: { value: [] }, - radios: { value: [] }, - observers: { value: [] }, - transitions: { value: [] }, - liveQueries: { value: [] }, - decorators: { value: [] }, - focusable: { - value: null, - writable: true - } - }); - ractive.adaptors = options.adaptors; - ractive.modifyArrays = options.modifyArrays; - ractive.magic = options.magic; - ractive.twoway = options.twoway; - ractive.lazy = options.lazy; - ractive.debug = options.debug; - if (ractive.magic && !magicAdaptor) { - throw new Error('Getters and setters (magic mode) are not supported in this browser'); - } - if (options._parent) { - defineProperty(ractive, '_parent', { value: options._parent }); - } - if (options.el) { - ractive.el = getElement(options.el); - if (!ractive.el && ractive.debug) { - throw new Error('Could not find container element'); - } - } - if (options.eventDefinitions) { - warn('ractive.eventDefinitions has been deprecated in favour of ractive.events. Support will be removed in future versions'); - options.events = options.eventDefinitions; - } - registries.forEach(function (registry) { - if (ractive.constructor[registry]) { - ractive[registry] = extend(create(ractive.constructor[registry] || {}), options[registry]); - } else if (options[registry]) { - ractive[registry] = options[registry]; - } - }); - template = options.template; - if (typeof template === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - if (template.charAt(0) === '#' && isClient) { - templateEl = document.getElementById(template.substring(1)); - if (templateEl) { - parsedTemplate = parse(templateEl.innerHTML, options); - } else { - throw new Error('Could not find template element (' + template + ')'); - } - } else { - parsedTemplate = parse(template, options); - } - } else { - parsedTemplate = template; - } - if (isObject(parsedTemplate)) { - extend(ractive.partials, parsedTemplate.partials); - parsedTemplate = parsedTemplate.main; - } - if (parsedTemplate && parsedTemplate.length === 1 && typeof parsedTemplate[0] === 'string') { - parsedTemplate = parsedTemplate[0]; - } - ractive.template = parsedTemplate; - extend(ractive.partials, options.partials); - ractive.parseOptions = { - preserveWhitespace: options.preserveWhitespace, - sanitize: options.sanitize, - stripComments: options.stripComments - }; - ractive.transitionsEnabled = options.noIntro ? false : options.transitionsEnabled; - if (isClient && !ractive.el) { - ractive.el = document.createDocumentFragment(); - } - if (ractive.el && !options.append) { - ractive.el.innerHTML = ''; - } - ractive.render(ractive.el, options.complete); - ractive.transitionsEnabled = options.transitionsEnabled; - ractive._initing = false; - }; - }(config_isClient, config_errors, utils_warn, utils_create, utils_extend, utils_defineProperty, utils_defineProperties, utils_getElement, utils_isObject, Ractive_prototype_get_magicAdaptor, parse__parse); -var extend_initChildInstance = function (fillGaps, initOptions, clone, wrapMethod, initialise) { - - return function (child, Child, options) { - initOptions.forEach(function (property) { - var value = options[property], defaultValue = Child[property]; - if (typeof value === 'function' && typeof defaultValue === 'function') { - options[property] = wrapMethod(value, defaultValue); - } else if (value === undefined && defaultValue !== undefined) { - options[property] = defaultValue; - } - }); - if (child.beforeInit) { - child.beforeInit(options); - } - initialise(child, options); - if (child.init) { - child.init(options); - } - }; - }(utils_fillGaps, extend_initOptions, extend_utils_clone, extend_wrapMethod, Ractive_initialise); -var extend__extend = function (create, inheritFromParent, inheritFromChildProps, extractInlinePartials, conditionallyParseTemplate, conditionallyParsePartials, initChildInstance, circular) { - - var Ractive; - circular.push(function () { - Ractive = circular.Ractive; - }); - return function (childProps) { - var Parent = this, Child; - Child = function (options) { - initChildInstance(this, Child, options || {}); - }; - Child.prototype = create(Parent.prototype); - Child.prototype.constructor = Child; - inheritFromParent(Child, Parent); - inheritFromChildProps(Child, childProps); - conditionallyParseTemplate(Child); - extractInlinePartials(Child, childProps); - conditionallyParsePartials(Child); - Child.extend = Parent.extend; - return Child; - }; - }(utils_create, extend_inheritFromParent, extend_inheritFromChildProps, extend_extractInlinePartials, extend_conditionallyParseTemplate, extend_conditionallyParsePartials, extend_initChildInstance, circular); -var Ractive__Ractive = function (svg, create, defineProperties, prototype, partialRegistry, adaptorRegistry, easingRegistry, Ractive_extend, parse, initialise, circular) { - - var Ractive = function (options) { - initialise(this, options); - }; - defineProperties(Ractive, { - prototype: { value: prototype }, - partials: { value: partialRegistry }, - adaptors: { value: adaptorRegistry }, - easing: { value: easingRegistry }, - transitions: { value: {} }, - events: { value: {} }, - components: { value: {} }, - decorators: { value: {} }, - svg: { value: svg }, - VERSION: { value: '0.3.9' } - }); - Ractive.eventDefinitions = Ractive.events; - Ractive.prototype.constructor = Ractive; - Ractive.delimiters = [ - '{{', - '}}' - ]; - Ractive.tripleDelimiters = [ - '{{{', - '}}}' - ]; - Ractive.extend = Ractive_extend; - Ractive.parse = parse; - circular.Ractive = Ractive; - return Ractive; - }(config_svg, utils_create, utils_defineProperties, Ractive_prototype__prototype, registries_partials, registries_adaptors, registries_easing, extend__extend, parse__parse, Ractive_initialise, circular); -var Ractive = function (Ractive, circular) { - - if (typeof window !== 'undefined' && window.Node && !window.Node.prototype.contains && window.HTMLElement && window.HTMLElement.prototype.contains) { - window.Node.prototype.contains = window.HTMLElement.prototype.contains; - } - while (circular.length) { - circular.pop()(); - } - return Ractive; - }(Ractive__Ractive, circular); -// export as Common JS module... -if ( typeof module !== "undefined" && module.exports ) { - module.exports = Ractive; -} - -// ... or as AMD module -else if ( typeof define === "function" && define.amd ) { - define( function () { - return Ractive; - }); -} - -// ... or as browser global -else { - global.Ractive = Ractive; -} - -}( typeof window !== 'undefined' ? window : this )); \ No newline at end of file diff --git a/bower.json b/bower.json index 5a959fad72..a6e4e411ba 100755 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "ractive", - "version": "0.3.9", - "main": "build/Ractive.js", + "version": "0.4.0", + "main": "ractive.js", "ignore": [ "**/.*", "node_modules", diff --git a/build/README.md b/build/README.md new file mode 100644 index 0000000000..d79bc18a96 --- /dev/null +++ b/build/README.md @@ -0,0 +1,22 @@ +Latest builds +============= + +The latest builds are available from http://cdn.ractivejs.org: + + +Compressed +---------- + +* http://cdn.ractivejs.org/edge/ractive.min.js +* http://cdn.ractivejs.org/edge/ractive-legacy.min.js (IE8 compatible version) +* http://cdn.ractivejs.org/edge/ractive.runtime.min.js (excludes `Ractive.parse`) +* http://cdn.ractivejs.org/edge/ractive-legacy.runtime.min.js + + +Uncompressed +------------ + +* http://cdn.ractivejs.org/edge/ractive.js +* http://cdn.ractivejs.org/edge/ractive-legacy.js (IE8 compatible version) +* http://cdn.ractivejs.org/edge/ractive.runtime.js (excludes `Ractive.parse`) +* http://cdn.ractivejs.org/edge/ractive-legacy.runtime.js diff --git a/build/Ractive-legacy.js b/build/Ractive-legacy.js deleted file mode 100644 index 94afc6476c..0000000000 --- a/build/Ractive-legacy.js +++ /dev/null @@ -1,9435 +0,0 @@ -/* - - Ractive - v0.3.9 - 2013-12-31 - ============================================================== - - Next-generation DOM manipulation - http://ractivejs.org - Follow @RactiveJS for updates - - -------------------------------------------------------------- - - Copyright 2013 2013 Rich Harris and contributors - - Permission is hereby granted, free of charge, to any person - obtaining a copy of this software and associated documentation - files (the "Software"), to deal in the Software without - restriction, including without limitation the rights to use, - copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following - conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - OTHER DEALINGS IN THE SOFTWARE. - -*/ - -(function ( win ) { - - 'use strict'; - - var doc = win.document; - - if ( !doc ) { - return; - } - - // Shims for older browsers - - if ( !Date.now ) { - Date.now = function () { return +new Date(); }; - } - - if ( !String.prototype.trim ) { - String.prototype.trim = function () { - return this.replace(/^\s+/, '').replace(/\s+$/, ''); - }; - } - - - // Polyfill for Object.keys - // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/keys - if ( !Object.keys ) { - Object.keys = (function () { - var hasOwnProperty = Object.prototype.hasOwnProperty, - hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'), - dontEnums = [ - 'toString', - 'toLocaleString', - 'valueOf', - 'hasOwnProperty', - 'isPrototypeOf', - 'propertyIsEnumerable', - 'constructor' - ], - dontEnumsLength = dontEnums.length; - - return function ( obj ) { - if ( typeof obj !== 'object' && typeof obj !== 'function' || obj === null ) { - throw new TypeError( 'Object.keys called on non-object' ); - } - - var result = []; - - for ( var prop in obj ) { - if ( hasOwnProperty.call( obj, prop ) ){ - result.push( prop ); - } - } - - if ( hasDontEnumBug ) { - for ( var i=0; i < dontEnumsLength; i++ ) { - if ( hasOwnProperty.call( obj, dontEnums[i] ) ){ - result.push( dontEnums[i] ); - } - } - } - return result; - }; - }()); - } - - - // Array extras - if ( !Array.prototype.indexOf ) { - Array.prototype.indexOf = function ( needle, i ) { - var len; - - if ( i === undefined ) { - i = 0; - } - - if ( i < 0 ) { - i+= this.length; - } - - if ( i < 0 ) { - i = 0; - } - - for ( len = this.length; i 2 && args[1]) { - changed = Math.min(args[1], args.length - 2); - start = args[0]; - end = start + changed; - if (args[1] === args.length - 2) { - lengthUnchanged = true; - } - for (i = start; i < end; i += 1) { - childKeypath = keypath + '.' + i; - notifyDependants(root, childKeypath); - } - } - preDomUpdate(root); - upstreamQueue = []; - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - upstreamQueue[upstreamQueue.length] = keys.join('.'); - } - notifyDependants.multiple(root, upstreamQueue, true); - if (!lengthUnchanged) { - notifyDependants(root, keypath + '.length', true); - } - }; - queueDependants = function (keypath, deps, smartUpdateQueue, dumbUpdateQueue) { - var k, dependant; - k = deps.length; - while (k--) { - dependant = deps[k]; - if (dependant.type === types.REFERENCE) { - dependant.update(); - } else if (dependant.keypath === keypath && dependant.type === types.SECTION && !dependant.inverted && dependant.docFrag) { - smartUpdateQueue[smartUpdateQueue.length] = dependant; - } else { - dumbUpdateQueue[dumbUpdateQueue.length] = dependant; - } - } - }; - wrappers = array._ractive.wrappers; - i = wrappers.length; - while (i--) { - wrapper = wrappers[i]; - notifyKeypathDependants(wrapper.root, wrapper.keypath); - } - }; - patchedArrayProto = []; - mutatorMethods = [ - 'pop', - 'push', - 'reverse', - 'shift', - 'sort', - 'splice', - 'unshift' - ]; - noop = function () { - }; - mutatorMethods.forEach(function (methodName) { - var method = function () { - var result, instances, instance, i, previousTransitionManagers = {}, transitionManagers = {}; - result = Array.prototype[methodName].apply(this, arguments); - instances = this._ractive.instances; - i = instances.length; - while (i--) { - instance = instances[i]; - previousTransitionManagers[instance._guid] = instance._transitionManager; - instance._transitionManager = transitionManagers[instance._guid] = makeTransitionManager(instance, noop); - } - this._ractive.setting = true; - notifyArrayDependants(this, methodName, arguments); - this._ractive.setting = false; - i = instances.length; - while (i--) { - instance = instances[i]; - instance._transitionManager = previousTransitionManagers[instance._guid]; - transitionManagers[instance._guid].ready(); - preDomUpdate(instance); - postDomUpdate(instance); - } - return result; - }; - defineProperty(patchedArrayProto, methodName, { value: method }); - }); - testObj = {}; - if (testObj.__proto__) { - patchArrayMethods = function (array) { - array.__proto__ = patchedArrayProto; - }; - unpatchArrayMethods = function (array) { - array.__proto__ = Array.prototype; - }; - } else { - patchArrayMethods = function (array) { - var i, methodName; - i = mutatorMethods.length; - while (i--) { - methodName = mutatorMethods[i]; - defineProperty(array, methodName, { - value: patchedArrayProto[methodName], - configurable: true - }); - } - }; - unpatchArrayMethods = function (array) { - var i; - i = mutatorMethods.length; - while (i--) { - delete array[mutatorMethods[i]]; - } - }; - } - errorMessage = 'Something went wrong in a rather interesting way'; - return arrayAdaptor; - }(config_types, utils_defineProperty, utils_isArray, shared_clearCache, shared_preDomUpdate, shared_postDomUpdate, shared_makeTransitionManager, shared_notifyDependants); -var Ractive_prototype_get_magicAdaptor = function () { - - var magicAdaptor, MagicWrapper; - try { - Object.defineProperty({}, 'test', { value: 0 }); - } catch (err) { - return false; - } - magicAdaptor = { - filter: function (object, keypath) { - return !!keypath; - }, - wrap: function (ractive, object, keypath) { - return new MagicWrapper(ractive, object, keypath); - } - }; - MagicWrapper = function (ractive, object, keypath) { - var wrapper = this, keys, prop, objKeypath, descriptor, wrappers, oldGet, oldSet, get, set; - this.ractive = ractive; - this.keypath = keypath; - keys = keypath.split('.'); - this.prop = keys.pop(); - objKeypath = keys.join('.'); - this.obj = objKeypath ? ractive.get(objKeypath) : ractive.data; - descriptor = this.originalDescriptor = Object.getOwnPropertyDescriptor(this.obj, this.prop); - if (descriptor && descriptor.set && (wrappers = descriptor.set._ractiveWrappers)) { - if (wrappers.indexOf(this) === -1) { - wrappers.push(this); - } - return; - } - if (descriptor && !descriptor.configurable) { - throw new Error('Cannot use magic mode with property "' + prop + '" - object is not configurable'); - } - if (descriptor) { - this.value = descriptor.value; - oldGet = descriptor.get; - oldSet = descriptor.set; - } - get = oldGet || function () { - return wrapper.value; - }; - set = function (value) { - var wrappers, wrapper, i; - if (oldSet) { - oldSet(value); - } - wrappers = set._ractiveWrappers; - i = wrappers.length; - while (i--) { - wrapper = wrappers[i]; - if (!wrapper.resetting) { - wrapper.ractive.set(wrapper.keypath, value); - } - } - }; - set._ractiveWrappers = [this]; - Object.defineProperty(this.obj, this.prop, { - get: get, - set: set, - enumerable: true, - configurable: true - }); - }; - MagicWrapper.prototype = { - get: function () { - return this.value; - }, - reset: function (value) { - this.resetting = true; - this.value = value; - this.resetting = false; - }, - teardown: function () { - var descriptor, set, value, wrappers; - descriptor = Object.getOwnPropertyDescriptor(this.obj, this.prop); - set = descriptor.set; - wrappers = set._ractiveWrappers; - wrappers.splice(wrappers.indexOf(this), 1); - if (!wrappers.length) { - value = this.obj[this.prop]; - Object.defineProperty(this.obj, this.prop, this.originalDescriptor || { - writable: true, - enumerable: true, - configrable: true - }); - this.obj[this.prop] = value; - } - } - }; - return magicAdaptor; - }(); -var shared_adaptIfNecessary = function (adaptorRegistry, arrayAdaptor, magicAdaptor) { - - var prefixers = {}; - return function (ractive, keypath, value, isExpressionResult) { - var len, i, adaptor, wrapped; - len = ractive.adaptors.length; - for (i = 0; i < len; i += 1) { - adaptor = ractive.adaptors[i]; - if (typeof adaptor === 'string') { - if (!adaptorRegistry[adaptor]) { - throw new Error('Missing adaptor "' + adaptor + '"'); - } - adaptor = ractive.adaptors[i] = adaptorRegistry[adaptor]; - } - if (adaptor.filter(value, keypath, ractive)) { - wrapped = ractive._wrapped[keypath] = adaptor.wrap(ractive, value, keypath, getPrefixer(keypath)); - wrapped.value = value; - return; - } - } - if (!isExpressionResult) { - if (ractive.magic && magicAdaptor.filter(value, keypath, ractive)) { - ractive._wrapped[keypath] = magicAdaptor.wrap(ractive, value, keypath); - } else if (ractive.modifyArrays && arrayAdaptor.filter(value, keypath, ractive)) { - ractive._wrapped[keypath] = arrayAdaptor.wrap(ractive, value, keypath); - } - } - }; - function prefixKeypath(obj, prefix) { - var prefixed = {}, key; - if (!prefix) { - return obj; - } - prefix += '.'; - for (key in obj) { - if (obj.hasOwnProperty(key)) { - prefixed[prefix + key] = obj[key]; - } - } - return prefixed; - } - function getPrefixer(rootKeypath) { - var rootDot; - if (!prefixers[rootKeypath]) { - rootDot = rootKeypath ? rootKeypath + '.' : ''; - prefixers[rootKeypath] = function (relativeKeypath, value) { - var obj; - if (typeof relativeKeypath === 'string') { - obj = {}; - obj[rootDot + relativeKeypath] = value; - return obj; - } - if (typeof relativeKeypath === 'object') { - return rootDot ? prefixKeypath(relativeKeypath, rootKeypath) : relativeKeypath; - } - }; - } - return prefixers[rootKeypath]; - } - }(registries_adaptors, Ractive_prototype_get_arrayAdaptor, Ractive_prototype_get_magicAdaptor); -var Ractive_prototype_get__get = function (normaliseKeypath, adaptorRegistry, adaptIfNecessary) { - - var get, _get, retrieve; - get = function (keypath) { - if (this._captured && !this._captured[keypath]) { - this._captured.push(keypath); - this._captured[keypath] = true; - } - return _get(this, keypath); - }; - _get = function (ractive, keypath) { - var cache, cached, value, wrapped, evaluator; - keypath = normaliseKeypath(keypath); - cache = ractive._cache; - if ((cached = cache[keypath]) !== undefined) { - return cached; - } - if (wrapped = ractive._wrapped[keypath]) { - value = wrapped.value; - } else if (!keypath) { - adaptIfNecessary(ractive, '', ractive.data); - value = ractive.data; - } else if (evaluator = ractive._evaluators[keypath]) { - value = evaluator.value; - } else { - value = retrieve(ractive, keypath); - } - cache[keypath] = value; - return value; - }; - retrieve = function (ractive, keypath) { - var keys, key, parentKeypath, parentValue, cacheMap, value, wrapped; - keys = keypath.split('.'); - key = keys.pop(); - parentKeypath = keys.join('.'); - parentValue = _get(ractive, parentKeypath); - if (wrapped = ractive._wrapped[parentKeypath]) { - parentValue = wrapped.get(); - } - if (parentValue === null || parentValue === undefined) { - return; - } - if (!(cacheMap = ractive._cacheMap[parentKeypath])) { - ractive._cacheMap[parentKeypath] = [keypath]; - } else { - if (cacheMap.indexOf(keypath) === -1) { - cacheMap[cacheMap.length] = keypath; - } - } - value = parentValue[key]; - adaptIfNecessary(ractive, keypath, value); - ractive._cache[keypath] = value; - return value; - }; - return get; - }(utils_normaliseKeypath, registries_adaptors, shared_adaptIfNecessary); -var utils_isObject = function () { - - var toString = Object.prototype.toString; - return function (thing) { - return typeof thing === 'object' && toString.call(thing) === '[object Object]'; - }; - }(); -var utils_isEqual = function () { - - return function (a, b) { - if (a === null && b === null) { - return true; - } - if (typeof a === 'object' || typeof b === 'object') { - return false; - } - return a === b; - }; - }(); -var shared_resolveRef = function () { - - var resolveRef; - resolveRef = function (ractive, ref, contextStack) { - var keypath, keys, lastKey, contextKeys, innerMostContext, postfix, parentKeypath, parentValue, wrapped, context, ancestorErrorMessage; - ancestorErrorMessage = 'Could not resolve reference - too many "../" prefixes'; - if (ref === '.') { - if (!contextStack.length) { - return ''; - } - keypath = contextStack[contextStack.length - 1]; - } else if (ref.charAt(0) === '.') { - context = contextStack[contextStack.length - 1]; - contextKeys = context ? context.split('.') : []; - if (ref.substr(0, 3) === '../') { - while (ref.substr(0, 3) === '../') { - if (!contextKeys.length) { - throw new Error(ancestorErrorMessage); - } - contextKeys.pop(); - ref = ref.substring(3); - } - contextKeys.push(ref); - keypath = contextKeys.join('.'); - } else if (!context) { - keypath = ref.substring(1); - } else { - keypath = context + ref; - } - } else { - keys = ref.split('.'); - lastKey = keys.pop(); - postfix = keys.length ? '.' + keys.join('.') : ''; - contextStack = contextStack.concat(); - while (contextStack.length) { - innerMostContext = contextStack.pop(); - parentKeypath = innerMostContext + postfix; - parentValue = ractive.get(parentKeypath); - if (wrapped = ractive._wrapped[parentKeypath]) { - parentValue = wrapped.get(); - } - if (typeof parentValue === 'object' && parentValue !== null && parentValue.hasOwnProperty(lastKey)) { - keypath = innerMostContext + '.' + ref; - break; - } - } - if (!keypath && ractive.get(ref) !== undefined) { - keypath = ref; - } - } - return keypath ? keypath.replace(/^\./, '') : keypath; - }; - return resolveRef; - }(); -var shared_attemptKeypathResolution = function (resolveRef) { - - var push = Array.prototype.push; - return function (ractive) { - var unresolved, keypath, leftover; - while (unresolved = ractive._pendingResolution.pop()) { - keypath = resolveRef(ractive, unresolved.ref, unresolved.contextStack); - if (keypath !== undefined) { - unresolved.resolve(keypath); - } else { - (leftover || (leftover = [])).push(unresolved); - } - } - if (leftover) { - push.apply(ractive._pendingResolution, leftover); - } - }; - }(shared_resolveRef); -var shared_processDeferredUpdates = function (preDomUpdate, postDomUpdate) { - - return function (ractive) { - preDomUpdate(ractive); - postDomUpdate(ractive); - }; - }(shared_preDomUpdate, shared_postDomUpdate); -var Ractive_prototype_shared_replaceData = function () { - - return function (ractive, keypath, value) { - var keys, accumulated, wrapped, obj, key, currentKeypath, keypathToClear; - keys = keypath.split('.'); - accumulated = []; - if (wrapped = ractive._wrapped['']) { - if (wrapped.set) { - wrapped.set(keys.join('.'), value); - } - obj = wrapped.get(); - } else { - obj = ractive.data; - } - while (keys.length > 1) { - key = accumulated[accumulated.length] = keys.shift(); - currentKeypath = accumulated.join('.'); - if (wrapped = ractive._wrapped[currentKeypath]) { - if (wrapped.set) { - wrapped.set(keys.join('.'), value); - } - obj = wrapped.get(); - } else { - if (!obj.hasOwnProperty(key)) { - if (!keypathToClear) { - keypathToClear = currentKeypath; - } - obj[key] = /^\s*[0-9]+\s*$/.test(keys[0]) ? [] : {}; - } - obj = obj[key]; - } - } - key = keys[0]; - obj[key] = value; - return keypathToClear; - }; - }(); -var Ractive_prototype_set = function (isObject, isEqual, normaliseKeypath, clearCache, notifyDependants, attemptKeypathResolution, makeTransitionManager, processDeferredUpdates, replaceData) { - - var set, updateModel, getUpstreamChanges, resetWrapped; - set = function (keypath, value, complete) { - var map, changes, upstreamChanges, previousTransitionManager, transitionManager, i, changeHash; - changes = []; - if (isObject(keypath)) { - map = keypath; - complete = value; - } - if (map) { - for (keypath in map) { - if (map.hasOwnProperty(keypath)) { - value = map[keypath]; - keypath = normaliseKeypath(keypath); - updateModel(this, keypath, value, changes); - } - } - } else { - keypath = normaliseKeypath(keypath); - updateModel(this, keypath, value, changes); - } - if (!changes.length) { - return; - } - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - upstreamChanges = getUpstreamChanges(changes); - if (upstreamChanges.length) { - notifyDependants.multiple(this, upstreamChanges, true); - } - notifyDependants.multiple(this, changes); - if (this._pendingResolution.length) { - attemptKeypathResolution(this); - } - processDeferredUpdates(this); - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - if (!this.firingChangeEvent) { - this.firingChangeEvent = true; - changeHash = {}; - i = changes.length; - while (i--) { - changeHash[changes[i]] = this.get(changes[i]); - } - this.fire('change', changeHash); - this.firingChangeEvent = false; - } - return this; - }; - updateModel = function (ractive, keypath, value, changes) { - var cached, previous, wrapped, keypathToClear, evaluator; - if ((wrapped = ractive._wrapped[keypath]) && wrapped.reset) { - if (resetWrapped(ractive, keypath, value, wrapped, changes) !== false) { - return; - } - } - if (evaluator = ractive._evaluators[keypath]) { - evaluator.value = value; - } - cached = ractive._cache[keypath]; - previous = ractive.get(keypath); - if (previous !== value && !evaluator) { - keypathToClear = replaceData(ractive, keypath, value); - } else { - if (value === cached && typeof value !== 'object') { - return; - } - } - clearCache(ractive, keypathToClear || keypath); - changes[changes.length] = keypath; - }; - getUpstreamChanges = function (changes) { - var upstreamChanges = [''], i, keypath, keys, upstreamKeypath; - i = changes.length; - while (i--) { - keypath = changes[i]; - keys = keypath.split('.'); - while (keys.length > 1) { - keys.pop(); - upstreamKeypath = keys.join('.'); - if (!upstreamChanges[upstreamKeypath]) { - upstreamChanges[upstreamChanges.length] = upstreamKeypath; - upstreamChanges[upstreamKeypath] = true; - } - } - } - return upstreamChanges; - }; - resetWrapped = function (ractive, keypath, value, wrapped, changes) { - var previous, cached, cacheMap, i; - previous = wrapped.get(); - if (!isEqual(previous, value)) { - if (wrapped.reset(value) === false) { - return false; - } - } - value = wrapped.get(); - cached = ractive._cache[keypath]; - if (!isEqual(cached, value)) { - ractive._cache[keypath] = value; - cacheMap = ractive._cacheMap[keypath]; - if (cacheMap) { - i = cacheMap.length; - while (i--) { - clearCache(ractive, cacheMap[i]); - } - } - changes[changes.length] = keypath; - } - }; - return set; - }(utils_isObject, utils_isEqual, utils_normaliseKeypath, shared_clearCache, shared_notifyDependants, shared_attemptKeypathResolution, shared_makeTransitionManager, shared_processDeferredUpdates, Ractive_prototype_shared_replaceData); -var Ractive_prototype_update = function (makeTransitionManager, attemptKeypathResolution, clearCache, notifyDependants, processDeferredUpdates) { - - return function (keypath, complete) { - var transitionManager, previousTransitionManager; - if (typeof keypath === 'function') { - complete = keypath; - keypath = ''; - } - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - attemptKeypathResolution(this); - clearCache(this, keypath || ''); - notifyDependants(this, keypath || ''); - processDeferredUpdates(this); - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - if (typeof keypath === 'string') { - this.fire('update', keypath); - } else { - this.fire('update'); - } - return this; - }; - }(shared_makeTransitionManager, shared_attemptKeypathResolution, shared_clearCache, shared_notifyDependants, shared_processDeferredUpdates); -var utils_arrayContentsMatch = function (isArray) { - - return function (a, b) { - var i; - if (!isArray(a) || !isArray(b)) { - return false; - } - if (a.length !== b.length) { - return false; - } - i = a.length; - while (i--) { - if (a[i] !== b[i]) { - return false; - } - } - return true; - }; - }(utils_isArray); -var Ractive_prototype_updateModel = function (getValueFromCheckboxes, arrayContentsMatch, isEqual) { - - return function (keypath, cascade) { - var values, deferredCheckboxes, i; - if (typeof keypath !== 'string') { - keypath = ''; - cascade = true; - } - consolidateChangedValues(this, keypath, values = {}, deferredCheckboxes = [], cascade); - if (i = deferredCheckboxes.length) { - while (i--) { - keypath = deferredCheckboxes[i]; - values[keypath] = getValueFromCheckboxes(this, keypath); - } - } - this.set(values); - }; - function consolidateChangedValues(ractive, keypath, values, deferredCheckboxes, cascade) { - var bindings, childDeps, i, binding, oldValue, newValue; - bindings = ractive._twowayBindings[keypath]; - if (bindings) { - i = bindings.length; - while (i--) { - binding = bindings[i]; - if (binding.radioName && !binding.node.checked) { - continue; - } - if (binding.checkboxName) { - if (binding.changed() && !deferredCheckboxes[keypath]) { - deferredCheckboxes[keypath] = true; - deferredCheckboxes[deferredCheckboxes.length] = keypath; - } - continue; - } - oldValue = binding.attr.value; - newValue = binding.value(); - if (arrayContentsMatch(oldValue, newValue)) { - continue; - } - if (!isEqual(oldValue, newValue)) { - values[keypath] = newValue; - } - } - } - if (!cascade) { - return; - } - childDeps = ractive._depsMap[keypath]; - if (childDeps) { - i = childDeps.length; - while (i--) { - consolidateChangedValues(ractive, childDeps[i], values, deferredCheckboxes, cascade); - } - } - } - }(shared_getValueFromCheckboxes, utils_arrayContentsMatch, utils_isEqual); -var Ractive_prototype_animate_requestAnimationFrame = function () { - - if (typeof window === 'undefined') { - return; - } - (function (vendors, lastTime, window) { - var x, setTimeout; - if (window.requestAnimationFrame) { - return; - } - for (x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { - window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']; - } - if (!window.requestAnimationFrame) { - setTimeout = window.setTimeout; - window.requestAnimationFrame = function (callback) { - var currTime, timeToCall, id; - currTime = Date.now(); - timeToCall = Math.max(0, 16 - (currTime - lastTime)); - id = setTimeout(function () { - callback(currTime + timeToCall); - }, timeToCall); - lastTime = currTime + timeToCall; - return id; - }; - } - }([ - 'ms', - 'moz', - 'webkit', - 'o' - ], 0, window)); - return window.requestAnimationFrame; - }(); -var Ractive_prototype_animate_animations = function (rAF) { - - var queue = []; - var animations = { - tick: function () { - var i, animation; - for (i = 0; i < queue.length; i += 1) { - animation = queue[i]; - if (!animation.tick()) { - queue.splice(i--, 1); - } - } - if (queue.length) { - rAF(animations.tick); - } else { - animations.running = false; - } - }, - add: function (animation) { - queue[queue.length] = animation; - if (!animations.running) { - animations.running = true; - animations.tick(); - } - }, - abort: function (keypath, root) { - var i = queue.length, animation; - while (i--) { - animation = queue[i]; - if (animation.root === root && animation.keypath === keypath) { - animation.stop(); - } - } - } - }; - return animations; - }(Ractive_prototype_animate_requestAnimationFrame); -var utils_warn = function () { - - if (typeof console !== 'undefined' && typeof console.warn === 'function' && typeof console.warn.apply === 'function') { - return function () { - console.warn.apply(console, arguments); - }; - } - return function () { - }; - }(); -var utils_isNumeric = function () { - - return function (thing) { - return !isNaN(parseFloat(thing)) && isFinite(thing); - }; - }(); -var shared_interpolate = function (isArray, isObject, isNumeric) { - - var interpolate = function (from, to) { - if (isNumeric(from) && isNumeric(to)) { - return makeNumberInterpolator(+from, +to); - } - if (isArray(from) && isArray(to)) { - return makeArrayInterpolator(from, to); - } - if (isObject(from) && isObject(to)) { - return makeObjectInterpolator(from, to); - } - return function () { - return to; - }; - }; - return interpolate; - function makeNumberInterpolator(from, to) { - var delta = to - from; - if (!delta) { - return function () { - return from; - }; - } - return function (t) { - return from + t * delta; - }; - } - function makeArrayInterpolator(from, to) { - var intermediate, interpolators, len, i; - intermediate = []; - interpolators = []; - i = len = Math.min(from.length, to.length); - while (i--) { - interpolators[i] = interpolate(from[i], to[i]); - } - for (i = len; i < from.length; i += 1) { - intermediate[i] = from[i]; - } - for (i = len; i < to.length; i += 1) { - intermediate[i] = to[i]; - } - return function (t) { - var i = len; - while (i--) { - intermediate[i] = interpolators[i](t); - } - return intermediate; - }; - } - function makeObjectInterpolator(from, to) { - var properties = [], len, interpolators, intermediate, prop; - intermediate = {}; - interpolators = {}; - for (prop in from) { - if (from.hasOwnProperty(prop)) { - if (to.hasOwnProperty(prop)) { - properties[properties.length] = prop; - interpolators[prop] = interpolate(from[prop], to[prop]); - } else { - intermediate[prop] = from[prop]; - } - } - } - for (prop in to) { - if (to.hasOwnProperty(prop) && !from.hasOwnProperty(prop)) { - intermediate[prop] = to[prop]; - } - } - len = properties.length; - return function (t) { - var i = len, prop; - while (i--) { - prop = properties[i]; - intermediate[prop] = interpolators[prop](t); - } - return intermediate; - }; - } - }(utils_isArray, utils_isObject, utils_isNumeric); -var Ractive_prototype_animate_Animation = function (warn, interpolate) { - - var Animation = function (options) { - var key; - this.startTime = Date.now(); - for (key in options) { - if (options.hasOwnProperty(key)) { - this[key] = options[key]; - } - } - this.interpolator = interpolate(this.from, this.to); - this.running = true; - }; - Animation.prototype = { - tick: function () { - var elapsed, t, value, timeNow, index, keypath; - keypath = this.keypath; - if (this.running) { - timeNow = Date.now(); - elapsed = timeNow - this.startTime; - if (elapsed >= this.duration) { - if (keypath !== null) { - this.root.set(keypath, this.to); - } - if (this.step) { - this.step(1, this.to); - } - if (this.complete) { - this.complete(1, this.to); - } - index = this.root._animations.indexOf(this); - if (index === -1) { - warn('Animation was not found'); - } - this.root._animations.splice(index, 1); - this.running = false; - return false; - } - t = this.easing ? this.easing(elapsed / this.duration) : elapsed / this.duration; - if (keypath !== null) { - value = this.interpolator(t); - this.root.set(keypath, value); - } - if (this.step) { - this.step(t, value); - } - return true; - } - return false; - }, - stop: function () { - var index; - this.running = false; - index = this.root._animations.indexOf(this); - if (index === -1) { - warn('Animation was not found'); - } - this.root._animations.splice(index, 1); - } - }; - return Animation; - }(utils_warn, shared_interpolate); -var registries_easing = function () { - - return { - linear: function (pos) { - return pos; - }, - easeIn: function (pos) { - return Math.pow(pos, 3); - }, - easeOut: function (pos) { - return Math.pow(pos - 1, 3) + 1; - }, - easeInOut: function (pos) { - if ((pos /= 0.5) < 1) { - return 0.5 * Math.pow(pos, 3); - } - return 0.5 * (Math.pow(pos - 2, 3) + 2); - } - }; - }(); -var Ractive_prototype_animate__animate = function (isEqual, animations, Animation, easingRegistry) { - - var noAnimation = { - stop: function () { - } - }; - return function (keypath, to, options) { - var k, animation, animations, easing, duration, step, complete, makeValueCollector, currentValues, collectValue, dummy, dummyOptions; - if (typeof keypath === 'object') { - options = to || {}; - easing = options.easing; - duration = options.duration; - animations = []; - step = options.step; - complete = options.complete; - if (step || complete) { - currentValues = {}; - options.step = null; - options.complete = null; - makeValueCollector = function (keypath) { - return function (t, value) { - currentValues[keypath] = value; - }; - }; - } - for (k in keypath) { - if (keypath.hasOwnProperty(k)) { - if (step || complete) { - collectValue = makeValueCollector(k); - options = { - easing: easing, - duration: duration - }; - if (step) { - options.step = collectValue; - } - if (complete) { - options.complete = collectValue; - } - } - animations[animations.length] = animate(this, k, keypath[k], options); - } - } - if (step || complete) { - dummyOptions = { - easing: easing, - duration: duration - }; - if (step) { - dummyOptions.step = function (t) { - step(t, currentValues); - }; - } - if (complete) { - dummyOptions.complete = function (t) { - complete(t, currentValues); - }; - } - animations[animations.length] = dummy = animate(this, null, null, dummyOptions); - } - return { - stop: function () { - while (animations.length) { - animations.pop().stop(); - } - if (dummy) { - dummy.stop(); - } - } - }; - } - options = options || {}; - animation = animate(this, keypath, to, options); - return { - stop: function () { - animation.stop(); - } - }; - }; - function animate(root, keypath, to, options) { - var easing, duration, animation, from; - if (keypath !== null) { - from = root.get(keypath); - } - animations.abort(keypath, root); - if (isEqual(from, to)) { - if (options.complete) { - options.complete(1, options.to); - } - return noAnimation; - } - if (options.easing) { - if (typeof options.easing === 'function') { - easing = options.easing; - } else { - if (root.easing && root.easing[options.easing]) { - easing = root.easing[options.easing]; - } else { - easing = easingRegistry[options.easing]; - } - } - if (typeof easing !== 'function') { - easing = null; - } - } - duration = options.duration === undefined ? 400 : options.duration; - animation = new Animation({ - keypath: keypath, - from: from, - to: to, - root: root, - duration: duration, - easing: easing, - step: options.step, - complete: options.complete - }); - animations.add(animation); - root._animations[root._animations.length] = animation; - return animation; - } - }(utils_isEqual, Ractive_prototype_animate_animations, Ractive_prototype_animate_Animation, registries_easing); -var Ractive_prototype_on = function () { - - return function (eventName, callback) { - var self = this, listeners, n; - if (typeof eventName === 'object') { - listeners = []; - for (n in eventName) { - if (eventName.hasOwnProperty(n)) { - listeners[listeners.length] = this.on(n, eventName[n]); - } - } - return { - cancel: function () { - while (listeners.length) { - listeners.pop().cancel(); - } - } - }; - } - if (!this._subs[eventName]) { - this._subs[eventName] = [callback]; - } else { - this._subs[eventName].push(callback); - } - return { - cancel: function () { - self.off(eventName, callback); - } - }; - }; - }(); -var Ractive_prototype_off = function () { - - return function (eventName, callback) { - var subscribers, index; - if (!callback) { - if (!eventName) { - for (eventName in this._subs) { - delete this._subs[eventName]; - } - } else { - this._subs[eventName] = []; - } - } - subscribers = this._subs[eventName]; - if (subscribers) { - index = subscribers.indexOf(callback); - if (index !== -1) { - subscribers.splice(index, 1); - } - } - }; - }(); -var shared_registerDependant = function () { - - return function (dependant) { - var depsByKeypath, deps, keys, parentKeypath, map, ractive, keypath, priority; - ractive = dependant.root; - keypath = dependant.keypath; - priority = dependant.priority; - depsByKeypath = ractive._deps[priority] || (ractive._deps[priority] = {}); - deps = depsByKeypath[keypath] || (depsByKeypath[keypath] = []); - deps[deps.length] = dependant; - dependant.registered = true; - if (!keypath) { - return; - } - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - parentKeypath = keys.join('.'); - map = ractive._depsMap[parentKeypath] || (ractive._depsMap[parentKeypath] = []); - if (map[keypath] === undefined) { - map[keypath] = 0; - map[map.length] = keypath; - } - map[keypath] += 1; - keypath = parentKeypath; - } - }; - }(); -var shared_unregisterDependant = function () { - - return function (dependant) { - var deps, index, keys, parentKeypath, map, ractive, keypath, priority; - ractive = dependant.root; - keypath = dependant.keypath; - priority = dependant.priority; - deps = ractive._deps[priority][keypath]; - index = deps.indexOf(dependant); - if (index === -1 || !dependant.registered) { - throw new Error('Attempted to remove a dependant that was no longer registered! This should not happen. If you are seeing this bug in development please raise an issue at https://github.com/RactiveJS/Ractive/issues - thanks'); - } - deps.splice(index, 1); - dependant.registered = false; - if (!keypath) { - return; - } - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - parentKeypath = keys.join('.'); - map = ractive._depsMap[parentKeypath]; - map[keypath] -= 1; - if (!map[keypath]) { - map.splice(map.indexOf(keypath), 1); - map[keypath] = undefined; - } - keypath = parentKeypath; - } - }; - }(); -var Ractive_prototype_observe_Observer = function (isEqual) { - - var Observer = function (ractive, keypath, callback, options) { - var self = this; - this.root = ractive; - this.keypath = keypath; - this.callback = callback; - this.defer = options.defer; - this.debug = options.debug; - this.proxy = { - update: function () { - self.reallyUpdate(); - } - }; - this.priority = 0; - this.context = options && options.context ? options.context : ractive; - }; - Observer.prototype = { - init: function (immediate) { - if (immediate !== false) { - this.update(); - } else { - this.value = this.root.get(this.keypath); - } - }, - update: function () { - if (this.defer && this.ready) { - this.root._deferred.observers.push(this.proxy); - return; - } - this.reallyUpdate(); - }, - reallyUpdate: function () { - var oldValue, newValue; - oldValue = this.value; - newValue = this.root.get(this.keypath); - this.value = newValue; - if (this.updating) { - return; - } - this.updating = true; - if (!isEqual(newValue, oldValue) || !this.ready) { - try { - this.callback.call(this.context, newValue, oldValue, this.keypath); - } catch (err) { - if (this.debug || this.root.debug) { - throw err; - } - } - } - this.updating = false; - } - }; - return Observer; - }(utils_isEqual); -var Ractive_prototype_observe_getPattern = function () { - - return function (ractive, pattern) { - var keys, key, values, toGet, newToGet, expand, concatenate; - keys = pattern.split('.'); - toGet = []; - expand = function (keypath) { - var value, key; - value = ractive._wrapped[keypath] ? ractive._wrapped[keypath].get() : ractive.get(keypath); - for (key in value) { - newToGet.push(keypath + '.' + key); - } - }; - concatenate = function (keypath) { - return keypath + '.' + key; - }; - while (key = keys.shift()) { - if (key === '*') { - newToGet = []; - toGet.forEach(expand); - toGet = newToGet; - } else { - if (!toGet[0]) { - toGet[0] = key; - } else { - toGet = toGet.map(concatenate); - } - } - } - values = {}; - toGet.forEach(function (keypath) { - values[keypath] = ractive.get(keypath); - }); - return values; - }; - }(); -var Ractive_prototype_observe_PatternObserver = function (isEqual, getPattern) { - - var PatternObserver, wildcard = /\*/; - PatternObserver = function (ractive, keypath, callback, options) { - this.root = ractive; - this.callback = callback; - this.defer = options.defer; - this.debug = options.debug; - this.keypath = keypath; - this.regex = new RegExp('^' + keypath.replace(/\./g, '\\.').replace(/\*/g, '[^\\.]+') + '$'); - this.values = {}; - if (this.defer) { - this.proxies = []; - } - this.priority = 'pattern'; - this.context = options && options.context ? options.context : ractive; - }; - PatternObserver.prototype = { - init: function (immediate) { - var values, keypath; - values = getPattern(this.root, this.keypath); - if (immediate !== false) { - for (keypath in values) { - if (values.hasOwnProperty(keypath)) { - this.update(keypath); - } - } - } else { - this.values = values; - } - }, - update: function (keypath) { - var values; - if (wildcard.test(keypath)) { - values = getPattern(this.root, keypath); - for (keypath in values) { - if (values.hasOwnProperty(keypath)) { - this.update(keypath); - } - } - return; - } - if (this.defer && this.ready) { - this.root._deferred.observers.push(this.getProxy(keypath)); - return; - } - this.reallyUpdate(keypath); - }, - reallyUpdate: function (keypath) { - var value = this.root.get(keypath); - if (this.updating) { - this.values[keypath] = value; - return; - } - this.updating = true; - if (!isEqual(value, this.values[keypath]) || !this.ready) { - try { - this.callback.call(this.context, value, this.values[keypath], keypath); - } catch (err) { - if (this.debug || this.root.debug) { - throw err; - } - } - this.values[keypath] = value; - } - this.updating = false; - }, - getProxy: function (keypath) { - var self = this; - if (!this.proxies[keypath]) { - this.proxies[keypath] = { - update: function () { - self.reallyUpdate(keypath); - } - }; - } - return this.proxies[keypath]; - } - }; - return PatternObserver; - }(utils_isEqual, Ractive_prototype_observe_getPattern); -var Ractive_prototype_observe_getObserverFacade = function (normaliseKeypath, registerDependant, unregisterDependant, Observer, PatternObserver) { - - var wildcard = /\*/, emptyObject = {}; - return function getObserverFacade(ractive, keypath, callback, options) { - var observer, isPatternObserver; - keypath = normaliseKeypath(keypath); - options = options || emptyObject; - if (wildcard.test(keypath)) { - observer = new PatternObserver(ractive, keypath, callback, options); - ractive._patternObservers.push(observer); - isPatternObserver = true; - } else { - observer = new Observer(ractive, keypath, callback, options); - } - registerDependant(observer); - observer.init(options.init); - observer.ready = true; - return { - cancel: function () { - var index; - if (isPatternObserver) { - index = ractive._patternObservers.indexOf(observer); - if (index !== -1) { - ractive._patternObservers.splice(index, 1); - } - } - unregisterDependant(observer); - } - }; - }; - }(utils_normaliseKeypath, shared_registerDependant, shared_unregisterDependant, Ractive_prototype_observe_Observer, Ractive_prototype_observe_PatternObserver); -var Ractive_prototype_observe__observe = function (isObject, getObserverFacade) { - - return function observe(keypath, callback, options) { - var observers = [], k; - if (isObject(keypath)) { - options = callback; - for (k in keypath) { - if (keypath.hasOwnProperty(k)) { - callback = keypath[k]; - observers[observers.length] = getObserverFacade(this, k, callback, options); - } - } - return { - cancel: function () { - while (observers.length) { - observers.pop().cancel(); - } - } - }; - } - return getObserverFacade(this, keypath, callback, options); - }; - }(utils_isObject, Ractive_prototype_observe_getObserverFacade); -var Ractive_prototype_fire = function () { - - return function (eventName) { - var args, i, len, subscribers = this._subs[eventName]; - if (!subscribers) { - return; - } - args = Array.prototype.slice.call(arguments, 1); - for (i = 0, len = subscribers.length; i < len; i += 1) { - subscribers[i].apply(this, args); - } - }; - }(); -var Ractive_prototype_find = function () { - - return function (selector) { - if (!this.el) { - return null; - } - return this.fragment.find(selector); - }; - }(); -var utils_matches = function (isClient, createElement) { - - var div, methodNames, unprefixed, prefixed, vendors, i, j, makeFunction; - if (!isClient) { - return; - } - div = createElement('div'); - methodNames = [ - 'matches', - 'matchesSelector' - ]; - vendors = [ - 'o', - 'ms', - 'moz', - 'webkit' - ]; - makeFunction = function (methodName) { - return function (node, selector) { - return node[methodName](selector); - }; - }; - i = methodNames.length; - while (i--) { - unprefixed = methodNames[i]; - if (div[unprefixed]) { - return makeFunction(unprefixed); - } - j = vendors.length; - while (j--) { - prefixed = vendors[i] + unprefixed.substr(0, 1).toUpperCase() + unprefixed.substring(1); - if (div[prefixed]) { - return makeFunction(prefixed); - } - } - } - return function (node, selector) { - var nodes, i; - nodes = (node.parentNode || node.document).querySelectorAll(selector); - i = nodes.length; - while (i--) { - if (nodes[i] === node) { - return true; - } - } - return false; - }; - }(config_isClient, utils_createElement); -var Ractive_prototype_shared_makeQuery_test = function (matches) { - - return function (item, noDirty) { - var itemMatches = this._isComponentQuery ? !this.selector || item.name === this.selector : matches(item.node, this.selector); - if (itemMatches) { - this.push(item.node || item.instance); - if (!noDirty) { - this._makeDirty(); - } - return true; - } - }; - }(utils_matches); -var Ractive_prototype_shared_makeQuery_cancel = function () { - - return function () { - var liveQueries, selector, index; - liveQueries = this._root[this._isComponentQuery ? 'liveComponentQueries' : 'liveQueries']; - selector = this.selector; - index = liveQueries.indexOf(selector); - if (index !== -1) { - liveQueries.splice(index, 1); - liveQueries[selector] = null; - } - }; - }(); -var Ractive_prototype_shared_makeQuery_sortByItemPosition = function () { - - return function (a, b) { - var ancestryA, ancestryB, oldestA, oldestB, mutualAncestor, indexA, indexB, fragments, fragmentA, fragmentB; - ancestryA = getAncestry(a.component || a._ractive.proxy); - ancestryB = getAncestry(b.component || b._ractive.proxy); - oldestA = ancestryA[ancestryA.length - 1]; - oldestB = ancestryB[ancestryB.length - 1]; - while (oldestA && oldestA === oldestB) { - ancestryA.pop(); - ancestryB.pop(); - mutualAncestor = oldestA; - oldestA = ancestryA[ancestryA.length - 1]; - oldestB = ancestryB[ancestryB.length - 1]; - } - oldestA = oldestA.component || oldestA; - oldestB = oldestB.component || oldestB; - fragmentA = oldestA.parentFragment; - fragmentB = oldestB.parentFragment; - if (fragmentA === fragmentB) { - indexA = fragmentA.items.indexOf(oldestA); - indexB = fragmentB.items.indexOf(oldestB); - return indexA - indexB || ancestryA.length - ancestryB.length; - } - if (fragments = mutualAncestor.fragments) { - indexA = fragments.indexOf(fragmentA); - indexB = fragments.indexOf(fragmentB); - return indexA - indexB || ancestryA.length - ancestryB.length; - } - throw new Error('An unexpected condition was met while comparing the position of two components. Please file an issue at https://github.com/RactiveJS/Ractive/issues - thanks!'); - }; - function getParent(item) { - var parentFragment; - if (parentFragment = item.parentFragment) { - return parentFragment.owner; - } - if (item.component && (parentFragment = item.component.parentFragment)) { - return parentFragment.owner; - } - } - function getAncestry(item) { - var ancestry, ancestor; - ancestry = [item]; - ancestor = getParent(item); - while (ancestor) { - ancestry.push(ancestor); - ancestor = getParent(ancestor); - } - return ancestry; - } - }(); -var Ractive_prototype_shared_makeQuery_sortByDocumentPosition = function (sortByItemPosition) { - - return function (node, otherNode) { - var bitmask; - if (node.compareDocumentPosition) { - bitmask = node.compareDocumentPosition(otherNode); - return bitmask & 2 ? 1 : -1; - } - return sortByItemPosition(node, otherNode); - }; - }(Ractive_prototype_shared_makeQuery_sortByItemPosition); -var Ractive_prototype_shared_makeQuery_sort = function (sortByDocumentPosition, sortByItemPosition) { - - return function () { - this.sort(this._isComponentQuery ? sortByItemPosition : sortByDocumentPosition); - this._dirty = false; - }; - }(Ractive_prototype_shared_makeQuery_sortByDocumentPosition, Ractive_prototype_shared_makeQuery_sortByItemPosition); -var Ractive_prototype_shared_makeQuery_dirty = function () { - - return function () { - if (!this._dirty) { - this._root._deferred.liveQueries.push(this); - this._dirty = true; - } - }; - }(); -var Ractive_prototype_shared_makeQuery_remove = function () { - - return function (item) { - var index = this.indexOf(this._isComponentQuery ? item.instance : item.node); - if (index !== -1) { - this.splice(index, 1); - } - }; - }(); -var Ractive_prototype_shared_makeQuery__makeQuery = function (defineProperties, test, cancel, sort, dirty, remove) { - - return function (ractive, selector, live, isComponentQuery) { - var query; - query = []; - defineProperties(query, { - selector: { value: selector }, - live: { value: live }, - _isComponentQuery: { value: isComponentQuery }, - _test: { value: test } - }); - if (!live) { - return query; - } - defineProperties(query, { - cancel: { value: cancel }, - _root: { value: ractive }, - _sort: { value: sort }, - _makeDirty: { value: dirty }, - _remove: { value: remove }, - _dirty: { - value: false, - writable: true - } - }); - return query; - }; - }(utils_defineProperties, Ractive_prototype_shared_makeQuery_test, Ractive_prototype_shared_makeQuery_cancel, Ractive_prototype_shared_makeQuery_sort, Ractive_prototype_shared_makeQuery_dirty, Ractive_prototype_shared_makeQuery_remove); -var Ractive_prototype_findAll = function (warn, matches, defineProperties, makeQuery) { - - return function (selector, options) { - var liveQueries, query; - if (!this.el) { - return []; - } - options = options || {}; - liveQueries = this._liveQueries; - if (query = liveQueries[selector]) { - return options && options.live ? query : query.slice(); - } - query = makeQuery(this, selector, !!options.live, false); - if (query.live) { - liveQueries.push(selector); - liveQueries[selector] = query; - } - this.fragment.findAll(selector, query); - return query; - }; - }(utils_warn, utils_matches, utils_defineProperties, Ractive_prototype_shared_makeQuery__makeQuery); -var Ractive_prototype_findComponent = function () { - - return function (selector) { - return this.fragment.findComponent(selector); - }; - }(); -var Ractive_prototype_findAllComponents = function (warn, matches, defineProperties, makeQuery) { - - return function (selector, options) { - var liveQueries, query; - options = options || {}; - liveQueries = this._liveComponentQueries; - if (query = liveQueries[selector]) { - return options && options.live ? query : query.slice(); - } - query = makeQuery(this, selector, !!options.live, true); - if (query.live) { - liveQueries.push(selector); - liveQueries[selector] = query; - } - this.fragment.findAllComponents(selector, query); - return query; - }; - }(utils_warn, utils_matches, utils_defineProperties, Ractive_prototype_shared_makeQuery__makeQuery); -var utils_getElement = function () { - - return function (input) { - var output; - if (typeof window === 'undefined' || !document || !input) { - return null; - } - if (input.nodeType) { - return input; - } - if (typeof input === 'string') { - output = document.getElementById(input); - if (!output && document.querySelector) { - output = document.querySelector(input); - } - if (output && output.nodeType) { - return output; - } - } - if (input[0] && input[0].nodeType) { - return input[0]; - } - return null; - }; - }(); -var render_shared_initFragment = function (types, create) { - - return function (fragment, options) { - var numItems, i, parentFragment, parentRefs, ref; - fragment.owner = options.owner; - parentFragment = fragment.owner.parentFragment; - fragment.root = options.root; - fragment.pNode = options.pNode; - fragment.contextStack = options.contextStack || []; - if (fragment.owner.type === types.SECTION) { - fragment.index = options.index; - } - if (parentFragment) { - parentRefs = parentFragment.indexRefs; - if (parentRefs) { - fragment.indexRefs = create(null); - for (ref in parentRefs) { - fragment.indexRefs[ref] = parentRefs[ref]; - } - } - } - fragment.priority = parentFragment ? parentFragment.priority + 1 : 1; - if (options.indexRef) { - if (!fragment.indexRefs) { - fragment.indexRefs = {}; - } - fragment.indexRefs[options.indexRef] = options.index; - } - fragment.items = []; - numItems = options.descriptor ? options.descriptor.length : 0; - for (i = 0; i < numItems; i += 1) { - fragment.items[fragment.items.length] = fragment.createItem({ - parentFragment: fragment, - descriptor: options.descriptor[i], - index: i - }); - } - }; - }(config_types, utils_create); -var render_DomFragment_shared_insertHtml = function (createElement) { - - var elementCache = {}; - return function (html, tagName, docFrag) { - var container, nodes = []; - if (html) { - container = elementCache[tagName] || (elementCache[tagName] = createElement(tagName)); - container.innerHTML = html; - while (container.firstChild) { - nodes[nodes.length] = container.firstChild; - docFrag.appendChild(container.firstChild); - } - } - return nodes; - }; - }(utils_createElement); -var render_DomFragment_Text = function (types) { - - var DomText, lessThan, greaterThan; - lessThan = //g; - DomText = function (options, docFrag) { - this.type = types.TEXT; - this.descriptor = options.descriptor; - if (docFrag) { - this.node = document.createTextNode(options.descriptor); - docFrag.appendChild(this.node); - } - }; - DomText.prototype = { - detach: function () { - this.node.parentNode.removeChild(this.node); - return this.node; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - } - }, - firstNode: function () { - return this.node; - }, - toString: function () { - return ('' + this.descriptor).replace(lessThan, '<').replace(greaterThan, '>'); - } - }; - return DomText; - }(config_types); -var shared_teardown = function (unregisterDependant) { - - return function (thing) { - if (!thing.keypath) { - var index = thing.root._pendingResolution.indexOf(thing); - if (index !== -1) { - thing.root._pendingResolution.splice(index, 1); - } - } else { - unregisterDependant(thing); - } - }; - }(shared_unregisterDependant); -var render_shared_Evaluator_Reference = function (types, isEqual, defineProperty, registerDependant, unregisterDependant) { - - var Reference, thisPattern; - thisPattern = /this/; - Reference = function (root, keypath, evaluator, argNum, priority) { - var value; - this.evaluator = evaluator; - this.keypath = keypath; - this.root = root; - this.argNum = argNum; - this.type = types.REFERENCE; - this.priority = priority; - value = root.get(keypath); - if (typeof value === 'function') { - value = wrapFunction(value, root, evaluator); - } - this.value = evaluator.values[argNum] = value; - registerDependant(this); - }; - Reference.prototype = { - update: function () { - var value = this.root.get(this.keypath); - if (typeof value === 'function' && !value._nowrap) { - value = wrapFunction(value, this.root, this.evaluator); - } - if (!isEqual(value, this.value)) { - this.evaluator.values[this.argNum] = value; - this.evaluator.bubble(); - this.value = value; - } - }, - teardown: function () { - unregisterDependant(this); - } - }; - return Reference; - function wrapFunction(fn, ractive, evaluator) { - var prop, evaluators, index; - if (!thisPattern.test(fn.toString())) { - defineProperty(fn, '_nowrap', { value: true }); - return fn; - } - if (!fn['_' + ractive._guid]) { - defineProperty(fn, '_' + ractive._guid, { - value: function () { - var originalCaptured, result, i, evaluator; - originalCaptured = ractive._captured; - if (!originalCaptured) { - ractive._captured = []; - } - result = fn.apply(ractive, arguments); - if (ractive._captured.length) { - i = evaluators.length; - while (i--) { - evaluator = evaluators[i]; - evaluator.updateSoftDependencies(ractive._captured); - } - } - ractive._captured = originalCaptured; - return result; - }, - writable: true - }); - for (prop in fn) { - if (fn.hasOwnProperty(prop)) { - fn['_' + ractive._guid][prop] = fn[prop]; - } - } - fn['_' + ractive._guid + '_evaluators'] = []; - } - evaluators = fn['_' + ractive._guid + '_evaluators']; - index = evaluators.indexOf(evaluator); - if (index === -1) { - evaluators.push(evaluator); - } - return fn['_' + ractive._guid]; - } - }(config_types, utils_isEqual, utils_defineProperty, shared_registerDependant, shared_unregisterDependant); -var render_shared_Evaluator_SoftReference = function (isEqual, registerDependant, unregisterDependant) { - - var SoftReference = function (root, keypath, evaluator) { - this.root = root; - this.keypath = keypath; - this.priority = evaluator.priority; - this.evaluator = evaluator; - registerDependant(this); - }; - SoftReference.prototype = { - update: function () { - var value = this.root.get(this.keypath); - if (!isEqual(value, this.value)) { - this.evaluator.bubble(); - this.value = value; - } - }, - teardown: function () { - unregisterDependant(this); - } - }; - return SoftReference; - }(utils_isEqual, shared_registerDependant, shared_unregisterDependant); -var render_shared_Evaluator__Evaluator = function (isEqual, defineProperty, clearCache, notifyDependants, registerDependant, unregisterDependant, adaptIfNecessary, Reference, SoftReference) { - - var Evaluator, cache = {}; - Evaluator = function (root, keypath, functionStr, args, priority) { - var i, arg; - this.root = root; - this.keypath = keypath; - this.priority = priority; - this.fn = getFunctionFromString(functionStr, args.length); - this.values = []; - this.refs = []; - i = args.length; - while (i--) { - if (arg = args[i]) { - if (arg[0]) { - this.values[i] = arg[1]; - } else { - this.refs[this.refs.length] = new Reference(root, arg[1], this, i, priority); - } - } else { - this.values[i] = undefined; - } - } - this.selfUpdating = this.refs.length <= 1; - this.update(); - }; - Evaluator.prototype = { - bubble: function () { - if (this.selfUpdating) { - this.update(); - } else if (!this.deferred) { - this.root._deferred.evals.push(this); - this.deferred = true; - } - }, - update: function () { - var value; - if (this.evaluating) { - return this; - } - this.evaluating = true; - try { - value = this.fn.apply(null, this.values); - } catch (err) { - if (this.root.debug) { - throw err; - } else { - value = undefined; - } - } - if (!isEqual(value, this.value)) { - clearCache(this.root, this.keypath); - this.root._cache[this.keypath] = value; - adaptIfNecessary(this.root, this.keypath, value, true); - this.value = value; - notifyDependants(this.root, this.keypath); - } - this.evaluating = false; - return this; - }, - teardown: function () { - while (this.refs.length) { - this.refs.pop().teardown(); - } - clearCache(this.root, this.keypath); - this.root._evaluators[this.keypath] = null; - }, - refresh: function () { - if (!this.selfUpdating) { - this.deferred = true; - } - var i = this.refs.length; - while (i--) { - this.refs[i].update(); - } - if (this.deferred) { - this.update(); - this.deferred = false; - } - }, - updateSoftDependencies: function (softDeps) { - var i, keypath, ref; - if (!this.softRefs) { - this.softRefs = []; - } - i = this.softRefs.length; - while (i--) { - ref = this.softRefs[i]; - if (!softDeps[ref.keypath]) { - this.softRefs.splice(i, 1); - this.softRefs[ref.keypath] = false; - ref.teardown(); - } - } - i = softDeps.length; - while (i--) { - keypath = softDeps[i]; - if (!this.softRefs[keypath]) { - ref = new SoftReference(this.root, keypath, this); - this.softRefs[this.softRefs.length] = ref; - this.softRefs[keypath] = true; - } - } - this.selfUpdating = this.refs.length + this.softRefs.length <= 1; - } - }; - return Evaluator; - function getFunctionFromString(str, i) { - var fn, args; - str = str.replace(/\$\{([0-9]+)\}/g, '_$1'); - if (cache[str]) { - return cache[str]; - } - args = []; - while (i--) { - args[i] = '_' + i; - } - fn = new Function(args.join(','), 'return(' + str + ')'); - cache[str] = fn; - return fn; - } - }(utils_isEqual, utils_defineProperty, shared_clearCache, shared_notifyDependants, shared_registerDependant, shared_unregisterDependant, shared_adaptIfNecessary, render_shared_Evaluator_Reference, render_shared_Evaluator_SoftReference); -var render_shared_ExpressionResolver_ReferenceScout = function (resolveRef, teardown) { - - var ReferenceScout = function (resolver, ref, contextStack, argNum) { - var keypath, root; - root = this.root = resolver.root; - keypath = resolveRef(root, ref, contextStack); - if (keypath !== undefined) { - resolver.resolveRef(argNum, false, keypath); - } else { - this.ref = ref; - this.argNum = argNum; - this.resolver = resolver; - this.contextStack = contextStack; - root._pendingResolution[root._pendingResolution.length] = this; - } - }; - ReferenceScout.prototype = { - resolve: function (keypath) { - this.keypath = keypath; - this.resolver.resolveRef(this.argNum, false, keypath); - }, - teardown: function () { - if (!this.keypath) { - teardown(this); - } - } - }; - return ReferenceScout; - }(shared_resolveRef, shared_teardown); -var render_shared_ExpressionResolver_isRegularKeypath = function () { - - var keyPattern = /^(?:(?:[a-zA-Z$_][a-zA-Z$_0-9]*)|(?:[0-9]|[1-9][0-9]+))$/; - return function (keypath) { - var keys, key, i; - keys = keypath.split('.'); - i = keys.length; - while (i--) { - key = keys[i]; - if (key === 'undefined' || !keyPattern.test(key)) { - return false; - } - } - return true; - }; - }(); -var render_shared_ExpressionResolver_getKeypath = function (normaliseKeypath, isRegularKeypath) { - - return function (str, args) { - var unique, normalised; - unique = str.replace(/\$\{([0-9]+)\}/g, function (match, $1) { - return args[$1] ? args[$1][1] : 'undefined'; - }); - normalised = normaliseKeypath(unique); - if (isRegularKeypath(normalised)) { - return normalised; - } - return '${' + unique.replace(/[\.\[\]]/g, '-') + '}'; - }; - }(utils_normaliseKeypath, render_shared_ExpressionResolver_isRegularKeypath); -var render_shared_ExpressionResolver_reassignDependants = function (registerDependant, unregisterDependant) { - - return function (ractive, oldKeypath, newKeypath) { - var toReassign, i, dependant; - toReassign = []; - gatherDependants(ractive, oldKeypath, toReassign); - i = toReassign.length; - while (i--) { - dependant = toReassign[i]; - unregisterDependant(dependant); - dependant.keypath = dependant.keypath.replace(oldKeypath, newKeypath); - registerDependant(dependant); - dependant.update(); - } - }; - function cascade(ractive, oldKeypath, toReassign) { - var map, i; - map = ractive._depsMap[oldKeypath]; - if (!map) { - return; - } - i = map.length; - while (i--) { - gatherDependants(ractive, map[i], toReassign); - } - } - function gatherDependants(ractive, oldKeypath, toReassign) { - var priority, dependantsByKeypath, dependants, i; - priority = ractive._deps.length; - while (priority--) { - dependantsByKeypath = ractive._deps[priority]; - if (dependantsByKeypath) { - dependants = dependantsByKeypath[oldKeypath]; - if (dependants) { - i = dependants.length; - while (i--) { - toReassign.push(dependants[i]); - } - } - } - } - cascade(ractive, oldKeypath, toReassign); - } - }(shared_registerDependant, shared_unregisterDependant); -var render_shared_ExpressionResolver__ExpressionResolver = function (Evaluator, ReferenceScout, getKeypath, reassignDependants) { - - var ExpressionResolver = function (mustache) { - var expression, i, len, ref, indexRefs; - this.root = mustache.root; - this.mustache = mustache; - this.args = []; - this.scouts = []; - expression = mustache.descriptor.x; - indexRefs = mustache.parentFragment.indexRefs; - this.str = expression.s; - len = this.unresolved = this.args.length = expression.r ? expression.r.length : 0; - if (!len) { - this.resolved = this.ready = true; - this.bubble(); - return; - } - for (i = 0; i < len; i += 1) { - ref = expression.r[i]; - if (indexRefs && indexRefs[ref] !== undefined) { - this.resolveRef(i, true, indexRefs[ref]); - } else { - this.scouts[this.scouts.length] = new ReferenceScout(this, ref, mustache.contextStack, i); - } - } - this.ready = true; - this.bubble(); - }; - ExpressionResolver.prototype = { - bubble: function () { - var oldKeypath; - if (!this.ready) { - return; - } - oldKeypath = this.keypath; - this.keypath = getKeypath(this.str, this.args); - if (this.keypath.substr(0, 2) === '${') { - this.createEvaluator(); - } - if (oldKeypath) { - reassignDependants(this.root, oldKeypath, this.keypath); - } else { - this.mustache.resolve(this.keypath); - } - }, - teardown: function () { - while (this.scouts.length) { - this.scouts.pop().teardown(); - } - }, - resolveRef: function (argNum, isIndexRef, value) { - this.args[argNum] = [ - isIndexRef, - value - ]; - this.bubble(); - this.resolved = !--this.unresolved; - }, - createEvaluator: function () { - if (!this.root._evaluators[this.keypath]) { - this.root._evaluators[this.keypath] = new Evaluator(this.root, this.keypath, this.str, this.args, this.mustache.priority); - } else { - this.root._evaluators[this.keypath].refresh(); - } - } - }; - return ExpressionResolver; - }(render_shared_Evaluator__Evaluator, render_shared_ExpressionResolver_ReferenceScout, render_shared_ExpressionResolver_getKeypath, render_shared_ExpressionResolver_reassignDependants); -var render_shared_initMustache = function (resolveRef, ExpressionResolver) { - - return function (mustache, options) { - var keypath, indexRef, parentFragment; - parentFragment = mustache.parentFragment = options.parentFragment; - mustache.root = parentFragment.root; - mustache.contextStack = parentFragment.contextStack; - mustache.descriptor = options.descriptor; - mustache.index = options.index || 0; - mustache.priority = parentFragment.priority; - mustache.type = options.descriptor.t; - if (options.descriptor.r) { - if (parentFragment.indexRefs && parentFragment.indexRefs[options.descriptor.r] !== undefined) { - indexRef = parentFragment.indexRefs[options.descriptor.r]; - mustache.indexRef = options.descriptor.r; - mustache.value = indexRef; - mustache.render(mustache.value); - } else { - keypath = resolveRef(mustache.root, options.descriptor.r, mustache.contextStack); - if (keypath !== undefined) { - mustache.resolve(keypath); - } else { - mustache.ref = options.descriptor.r; - mustache.root._pendingResolution[mustache.root._pendingResolution.length] = mustache; - } - } - } - if (options.descriptor.x) { - mustache.expressionResolver = new ExpressionResolver(mustache); - } - if (mustache.descriptor.n && !mustache.hasOwnProperty('value')) { - mustache.render(undefined); - } - }; - }(shared_resolveRef, render_shared_ExpressionResolver__ExpressionResolver); -var render_shared_resolveMustache = function (types, registerDependant, unregisterDependant) { - - return function (keypath) { - if (keypath === this.keypath) { - return; - } - if (this.registered) { - unregisterDependant(this); - } - this.keypath = keypath; - registerDependant(this); - this.update(); - if (this.root.twoway && this.parentFragment.owner.type === types.ATTRIBUTE) { - this.parentFragment.owner.element.bind(); - } - if (this.expressionResolver && this.expressionResolver.resolved) { - this.expressionResolver = null; - } - }; - }(config_types, shared_registerDependant, shared_unregisterDependant); -var render_shared_updateMustache = function (isEqual) { - - return function () { - var wrapped, value; - value = this.root.get(this.keypath); - if (wrapped = this.root._wrapped[this.keypath]) { - value = wrapped.get(); - } - if (!isEqual(value, this.value)) { - this.render(value); - this.value = value; - } - }; - }(utils_isEqual); -var render_DomFragment_Interpolator = function (types, teardown, initMustache, resolveMustache, updateMustache) { - - var DomInterpolator, lessThan, greaterThan; - lessThan = //g; - DomInterpolator = function (options, docFrag) { - this.type = types.INTERPOLATOR; - if (docFrag) { - this.node = document.createTextNode(''); - docFrag.appendChild(this.node); - } - initMustache(this, options); - }; - DomInterpolator.prototype = { - update: updateMustache, - resolve: resolveMustache, - detach: function () { - this.node.parentNode.removeChild(this.node); - return this.node; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - } - teardown(this); - }, - render: function (value) { - if (this.node) { - this.node.data = value == undefined ? '' : value; - } - }, - firstNode: function () { - return this.node; - }, - toString: function () { - var value = this.value != undefined ? '' + this.value : ''; - return value.replace(lessThan, '<').replace(greaterThan, '>'); - } - }; - return DomInterpolator; - }(config_types, shared_teardown, render_shared_initMustache, render_shared_resolveMustache, render_shared_updateMustache); -var render_shared_updateSection = function (isArray, isObject, create) { - - return function (section, value) { - var fragmentOptions; - fragmentOptions = { - descriptor: section.descriptor.f, - root: section.root, - pNode: section.parentFragment.pNode, - owner: section - }; - if (section.descriptor.n) { - updateConditionalSection(section, value, true, fragmentOptions); - return; - } - if (isArray(value)) { - updateListSection(section, value, fragmentOptions); - } else if (isObject(value)) { - if (section.descriptor.i) { - updateListObjectSection(section, value, fragmentOptions); - } else { - updateContextSection(section, fragmentOptions); - } - } else { - updateConditionalSection(section, value, false, fragmentOptions); - } - }; - function updateListSection(section, value, fragmentOptions) { - var i, length, fragmentsToRemove; - length = value.length; - if (length < section.length) { - fragmentsToRemove = section.fragments.splice(length, section.length - length); - while (fragmentsToRemove.length) { - fragmentsToRemove.pop().teardown(true); - } - } else { - if (length > section.length) { - for (i = section.length; i < length; i += 1) { - fragmentOptions.contextStack = section.contextStack.concat(section.keypath + '.' + i); - fragmentOptions.index = i; - if (section.descriptor.i) { - fragmentOptions.indexRef = section.descriptor.i; - } - section.fragments[i] = section.createFragment(fragmentOptions); - } - } - } - section.length = length; - } - function updateListObjectSection(section, value, fragmentOptions) { - var id, fragmentsById; - fragmentsById = section.fragmentsById || (section.fragmentsById = create(null)); - for (id in fragmentsById) { - if (value[id] === undefined && fragmentsById[id]) { - fragmentsById[id].teardown(true); - fragmentsById[id] = null; - } - } - for (id in value) { - if (value[id] !== undefined && !fragmentsById[id]) { - fragmentOptions.contextStack = section.contextStack.concat(section.keypath + '.' + id); - fragmentOptions.index = id; - if (section.descriptor.i) { - fragmentOptions.indexRef = section.descriptor.i; - } - fragmentsById[id] = section.createFragment(fragmentOptions); - } - } - } - function updateContextSection(section, fragmentOptions) { - if (!section.length) { - fragmentOptions.contextStack = section.contextStack.concat(section.keypath); - fragmentOptions.index = 0; - section.fragments[0] = section.createFragment(fragmentOptions); - section.length = 1; - } - } - function updateConditionalSection(section, value, inverted, fragmentOptions) { - var doRender, emptyArray, fragmentsToRemove, fragment; - emptyArray = isArray(value) && value.length === 0; - if (inverted) { - doRender = emptyArray || !value; - } else { - doRender = value && !emptyArray; - } - if (doRender) { - if (!section.length) { - fragmentOptions.contextStack = section.contextStack; - fragmentOptions.index = 0; - section.fragments[0] = section.createFragment(fragmentOptions); - section.length = 1; - } - if (section.length > 1) { - fragmentsToRemove = section.fragments.splice(1); - while (fragment = fragmentsToRemove.pop()) { - fragment.teardown(true); - } - } - } else if (section.length) { - section.teardownFragments(true); - section.length = 0; - } - } - }(utils_isArray, utils_isObject, utils_create); -var render_DomFragment_Section_reassignFragment = function (types, unregisterDependant, ExpressionResolver) { - - return reassignFragment; - function reassignFragment(fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath) { - var i, item, context, query; - if (fragment.html) { - return; - } - if (fragment.indexRefs && fragment.indexRefs[indexRef] !== undefined) { - fragment.indexRefs[indexRef] = newIndex; - } - i = fragment.contextStack.length; - while (i--) { - context = fragment.contextStack[i]; - if (context.substr(0, oldKeypath.length) === oldKeypath) { - fragment.contextStack[i] = context.replace(oldKeypath, newKeypath); - } - } - i = fragment.items.length; - while (i--) { - item = fragment.items[i]; - switch (item.type) { - case types.ELEMENT: - reassignElement(item, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - break; - case types.PARTIAL: - reassignFragment(item.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - break; - case types.COMPONENT: - reassignFragment(item.instance.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - if (query = fragment.root._liveComponentQueries[item.name]) { - query._makeDirty(); - } - break; - case types.SECTION: - case types.INTERPOLATOR: - case types.TRIPLE: - reassignMustache(item, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - break; - } - } - } - function reassignElement(element, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath) { - var i, attribute, storage, masterEventName, proxies, proxy, binding, bindings, liveQueries, ractive; - i = element.attributes.length; - while (i--) { - attribute = element.attributes[i]; - if (attribute.fragment) { - reassignFragment(attribute.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - if (attribute.twoway) { - attribute.updateBindings(); - } - } - } - if (storage = element.node._ractive) { - if (storage.keypath.substr(0, oldKeypath.length) === oldKeypath) { - storage.keypath = storage.keypath.replace(oldKeypath, newKeypath); - } - if (indexRef !== undefined) { - storage.index[indexRef] = newIndex; - } - for (masterEventName in storage.events) { - proxies = storage.events[masterEventName].proxies; - i = proxies.length; - while (i--) { - proxy = proxies[i]; - if (typeof proxy.n === 'object') { - reassignFragment(proxy.a, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - if (proxy.d) { - reassignFragment(proxy.d, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - } - } - if (binding = storage.binding) { - if (binding.keypath.substr(0, oldKeypath.length) === oldKeypath) { - bindings = storage.root._twowayBindings[binding.keypath]; - bindings.splice(bindings.indexOf(binding), 1); - binding.keypath = binding.keypath.replace(oldKeypath, newKeypath); - bindings = storage.root._twowayBindings[binding.keypath] || (storage.root._twowayBindings[binding.keypath] = []); - bindings.push(binding); - } - } - } - if (element.fragment) { - reassignFragment(element.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - if (liveQueries = element.liveQueries) { - ractive = element.root; - i = liveQueries.length; - while (i--) { - ractive._liveQueries[liveQueries[i]]._makeDirty(); - } - } - } - function reassignMustache(mustache, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath) { - var i; - if (mustache.descriptor.x) { - if (mustache.expressionResolver) { - mustache.expressionResolver.teardown(); - } - mustache.expressionResolver = new ExpressionResolver(mustache); - } - if (mustache.keypath) { - if (mustache.keypath.substr(0, oldKeypath.length) === oldKeypath) { - mustache.resolve(mustache.keypath.replace(oldKeypath, newKeypath)); - } - } else if (mustache.indexRef === indexRef) { - mustache.value = newIndex; - mustache.render(newIndex); - } - if (mustache.fragments) { - i = mustache.fragments.length; - while (i--) { - reassignFragment(mustache.fragments[i], indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - } - } - }(config_types, shared_unregisterDependant, render_shared_ExpressionResolver__ExpressionResolver); -var render_DomFragment_Section_reassignFragments = function (types, reassignFragment, preDomUpdate) { - - return function (root, section, start, end, by) { - var i, fragment, indexRef, oldIndex, newIndex, oldKeypath, newKeypath; - indexRef = section.descriptor.i; - for (i = start; i < end; i += 1) { - fragment = section.fragments[i]; - oldIndex = i - by; - newIndex = i; - oldKeypath = section.keypath + '.' + (i - by); - newKeypath = section.keypath + '.' + i; - fragment.index += by; - reassignFragment(fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - preDomUpdate(root); - }; - }(config_types, render_DomFragment_Section_reassignFragment, shared_preDomUpdate); -var render_DomFragment_Section_prototype_merge = function (reassignFragment) { - - return function (newIndices) { - var section = this, parentFragment, firstChange, changed, i, newLength, newFragments, toTeardown, fragmentOptions, fragment, nextNode; - parentFragment = this.parentFragment; - newFragments = []; - newIndices.forEach(function (newIndex, oldIndex) { - var by, oldKeypath, newKeypath; - if (newIndex === oldIndex) { - newFragments[newIndex] = section.fragments[oldIndex]; - return; - } - if (firstChange === undefined) { - firstChange = oldIndex; - } - if (newIndex === -1) { - (toTeardown || (toTeardown = [])).push(section.fragments[oldIndex]); - return; - } - by = newIndex - oldIndex; - oldKeypath = section.keypath + '.' + oldIndex; - newKeypath = section.keypath + '.' + newIndex; - reassignFragment(section.fragments[oldIndex], section.descriptor.i, oldIndex, newIndex, by, oldKeypath, newKeypath); - newFragments[newIndex] = section.fragments[oldIndex]; - changed = true; - }); - if (toTeardown) { - while (fragment = toTeardown.pop()) { - fragment.teardown(true); - } - } - if (firstChange === undefined) { - firstChange = this.length; - } - newLength = this.root.get(this.keypath).length; - if (newLength === firstChange) { - return; - } - fragmentOptions = { - descriptor: this.descriptor.f, - root: this.root, - pNode: parentFragment.pNode, - owner: this - }; - if (this.descriptor.i) { - fragmentOptions.indexRef = this.descriptor.i; - } - for (i = firstChange; i < newLength; i += 1) { - if (fragment = newFragments[i]) { - this.docFrag.appendChild(fragment.detach(false)); - } else { - fragmentOptions.contextStack = this.contextStack.concat(this.keypath + '.' + i); - fragmentOptions.index = i; - fragment = this.createFragment(fragmentOptions); - } - this.fragments[i] = fragment; - } - nextNode = parentFragment.findNextNode(this); - parentFragment.pNode.insertBefore(this.docFrag, nextNode); - this.length = newLength; - }; - }(render_DomFragment_Section_reassignFragment); -var circular = function () { - - return []; - }(); -var render_DomFragment_Section__Section = function (types, isClient, initMustache, updateMustache, resolveMustache, updateSection, reassignFragment, reassignFragments, merge, teardown, circular) { - - var DomSection, DomFragment; - circular.push(function () { - DomFragment = circular.DomFragment; - }); - DomSection = function (options, docFrag) { - this.type = types.SECTION; - this.inverted = !!options.descriptor.n; - this.fragments = []; - this.length = 0; - if (docFrag) { - this.docFrag = document.createDocumentFragment(); - } - this.initialising = true; - initMustache(this, options); - if (docFrag) { - docFrag.appendChild(this.docFrag); - } - this.initialising = false; - }; - DomSection.prototype = { - update: updateMustache, - resolve: resolveMustache, - smartUpdate: function (methodName, args) { - var fragmentOptions; - if (methodName === 'push' || methodName === 'unshift' || methodName === 'splice') { - fragmentOptions = { - descriptor: this.descriptor.f, - root: this.root, - pNode: this.parentFragment.pNode, - owner: this - }; - if (this.descriptor.i) { - fragmentOptions.indexRef = this.descriptor.i; - } - } - if (this[methodName]) { - this.rendering = true; - this[methodName](fragmentOptions, args); - this.rendering = false; - } - }, - pop: function () { - if (this.length) { - this.fragments.pop().teardown(true); - this.length -= 1; - } - }, - push: function (fragmentOptions, args) { - var start, end, i; - start = this.length; - end = start + args.length; - for (i = start; i < end; i += 1) { - fragmentOptions.contextStack = this.contextStack.concat(this.keypath + '.' + i); - fragmentOptions.index = i; - this.fragments[i] = this.createFragment(fragmentOptions); - } - this.length += args.length; - this.parentFragment.pNode.insertBefore(this.docFrag, this.parentFragment.findNextNode(this)); - }, - shift: function () { - this.splice(null, [ - 0, - 1 - ]); - }, - unshift: function (fragmentOptions, args) { - this.splice(fragmentOptions, [ - 0, - 0 - ].concat(new Array(args.length))); - }, - splice: function (fragmentOptions, args) { - var insertionPoint, addedItems, removedItems, balance, i, start, end, spliceArgs, reassignStart; - if (!args.length) { - return; - } - start = +(args[0] < 0 ? this.length + args[0] : args[0]); - addedItems = Math.max(0, args.length - 2); - removedItems = args[1] !== undefined ? args[1] : this.length - start; - removedItems = Math.min(removedItems, this.length - start); - balance = addedItems - removedItems; - if (!balance) { - return; - } - if (balance < 0) { - end = start - balance; - for (i = start; i < end; i += 1) { - this.fragments[i].teardown(true); - } - this.fragments.splice(start, -balance); - } else { - end = start + balance; - insertionPoint = this.fragments[start] ? this.fragments[start].firstNode() : this.parentFragment.findNextNode(this); - spliceArgs = [ - start, - 0 - ].concat(new Array(balance)); - this.fragments.splice.apply(this.fragments, spliceArgs); - for (i = start; i < end; i += 1) { - fragmentOptions.contextStack = this.contextStack.concat(this.keypath + '.' + i); - fragmentOptions.index = i; - this.fragments[i] = this.createFragment(fragmentOptions); - } - this.parentFragment.pNode.insertBefore(this.docFrag, insertionPoint); - } - this.length += balance; - reassignStart = start + addedItems; - reassignFragments(this.root, this, reassignStart, this.length, balance); - }, - merge: merge, - detach: function () { - var i, len; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - this.docFrag.appendChild(this.fragments[i].detach()); - } - return this.docFrag; - }, - teardown: function (destroy) { - this.teardownFragments(destroy); - teardown(this); - }, - firstNode: function () { - if (this.fragments[0]) { - return this.fragments[0].firstNode(); - } - return this.parentFragment.findNextNode(this); - }, - findNextNode: function (fragment) { - if (this.fragments[fragment.index + 1]) { - return this.fragments[fragment.index + 1].firstNode(); - } - return this.parentFragment.findNextNode(this); - }, - teardownFragments: function (destroy) { - var id, fragment; - while (fragment = this.fragments.shift()) { - fragment.teardown(destroy); - } - if (this.fragmentsById) { - for (id in this.fragmentsById) { - if (this.fragments[id]) { - this.fragmentsById[id].teardown(destroy); - this.fragmentsById[id] = null; - } - } - } - }, - render: function (value) { - var nextNode, wrapped; - if (wrapped = this.root._wrapped[this.keypath]) { - value = wrapped.get(); - } - if (this.rendering) { - return; - } - this.rendering = true; - updateSection(this, value); - this.rendering = false; - if (this.docFrag && !this.docFrag.childNodes.length) { - return; - } - if (!this.initialising && isClient) { - nextNode = this.parentFragment.findNextNode(this); - if (nextNode && nextNode.parentNode === this.parentFragment.pNode) { - this.parentFragment.pNode.insertBefore(this.docFrag, nextNode); - } else { - this.parentFragment.pNode.appendChild(this.docFrag); - } - } - }, - createFragment: function (options) { - var fragment = new DomFragment(options); - if (this.docFrag) { - this.docFrag.appendChild(fragment.docFrag); - } - return fragment; - }, - toString: function () { - var str, i, id, len; - str = ''; - i = 0; - len = this.length; - for (i = 0; i < len; i += 1) { - str += this.fragments[i].toString(); - } - if (this.fragmentsById) { - for (id in this.fragmentsById) { - if (this.fragmentsById[id]) { - str += this.fragmentsById[id].toString(); - } - } - } - return str; - }, - find: function (selector) { - var i, len, queryResult; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - if (queryResult = this.fragments[i].find(selector)) { - return queryResult; - } - } - return null; - }, - findAll: function (selector, query) { - var i, len; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - this.fragments[i].findAll(selector, query); - } - }, - findComponent: function (selector) { - var i, len, queryResult; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - if (queryResult = this.fragments[i].findComponent(selector)) { - return queryResult; - } - } - return null; - }, - findAllComponents: function (selector, query) { - var i, len; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - this.fragments[i].findAllComponents(selector, query); - } - } - }; - return DomSection; - }(config_types, config_isClient, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache, render_shared_updateSection, render_DomFragment_Section_reassignFragment, render_DomFragment_Section_reassignFragments, render_DomFragment_Section_prototype_merge, shared_teardown, circular); -var render_DomFragment_Triple = function (types, matches, initMustache, updateMustache, resolveMustache, insertHtml, teardown) { - - var DomTriple = function (options, docFrag) { - this.type = types.TRIPLE; - if (docFrag) { - this.nodes = []; - this.docFrag = document.createDocumentFragment(); - } - this.initialising = true; - initMustache(this, options); - if (docFrag) { - docFrag.appendChild(this.docFrag); - } - this.initialising = false; - }; - DomTriple.prototype = { - update: updateMustache, - resolve: resolveMustache, - detach: function () { - var i = this.nodes.length; - while (i--) { - this.docFrag.appendChild(this.nodes[i]); - } - return this.docFrag; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - this.docFrag = this.nodes = null; - } - teardown(this); - }, - firstNode: function () { - if (this.nodes[0]) { - return this.nodes[0]; - } - return this.parentFragment.findNextNode(this); - }, - render: function (html) { - var node, pNode; - if (!this.nodes) { - return; - } - while (this.nodes.length) { - node = this.nodes.pop(); - node.parentNode.removeChild(node); - } - if (!html) { - this.nodes = []; - return; - } - pNode = this.parentFragment.pNode; - this.nodes = insertHtml(html, pNode.tagName, this.docFrag); - if (!this.initialising) { - pNode.insertBefore(this.docFrag, this.parentFragment.findNextNode(this)); - } - }, - toString: function () { - return this.value != undefined ? this.value : ''; - }, - find: function (selector) { - var i, len, node, queryResult; - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - return node; - } - if (queryResult = node.querySelector(selector)) { - return queryResult; - } - } - return null; - }, - findAll: function (selector, queryResult) { - var i, len, node, queryAllResult, numNodes, j; - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - queryResult.push(node); - } - if (queryAllResult = node.querySelectorAll(selector)) { - numNodes = queryAllResult.length; - for (j = 0; j < numNodes; j += 1) { - queryResult.push(queryAllResult[j]); - } - } - } - } - }; - return DomTriple; - }(config_types, utils_matches, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache, render_DomFragment_shared_insertHtml, shared_teardown); -var render_DomFragment_Element_initialise_getElementNamespace = function (namespaces) { - - return function (descriptor, parentNode) { - if (descriptor.a && descriptor.a.xmlns) { - return descriptor.a.xmlns; - } - return descriptor.e === 'svg' ? namespaces.svg : parentNode.namespaceURI || namespaces.html; - }; - }(config_namespaces); -var render_DomFragment_shared_enforceCase = function () { - - var svgCamelCaseElements, svgCamelCaseAttributes, createMap, map; - svgCamelCaseElements = 'altGlyph altGlyphDef altGlyphItem animateColor animateMotion animateTransform clipPath feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile feTurbulence foreignObject glyphRef linearGradient radialGradient textPath vkern'.split(' '); - svgCamelCaseAttributes = 'attributeName attributeType baseFrequency baseProfile calcMode clipPathUnits contentScriptType contentStyleType diffuseConstant edgeMode externalResourcesRequired filterRes filterUnits glyphRef gradientTransform gradientUnits kernelMatrix kernelUnitLength keyPoints keySplines keyTimes lengthAdjust limitingConeAngle markerHeight markerUnits markerWidth maskContentUnits maskUnits numOctaves pathLength patternContentUnits patternTransform patternUnits pointsAtX pointsAtY pointsAtZ preserveAlpha preserveAspectRatio primitiveUnits refX refY repeatCount repeatDur requiredExtensions requiredFeatures specularConstant specularExponent spreadMethod startOffset stdDeviation stitchTiles surfaceScale systemLanguage tableValues targetX targetY textLength viewBox viewTarget xChannelSelector yChannelSelector zoomAndPan'.split(' '); - createMap = function (items) { - var map = {}, i = items.length; - while (i--) { - map[items[i].toLowerCase()] = items[i]; - } - return map; - }; - map = createMap(svgCamelCaseElements.concat(svgCamelCaseAttributes)); - return function (elementName) { - var lowerCaseElementName = elementName.toLowerCase(); - return map[lowerCaseElementName] || lowerCaseElementName; - }; - }(); -var render_DomFragment_Attribute_helpers_determineNameAndNamespace = function (namespaces, enforceCase) { - - return function (attribute, name) { - var colonIndex, namespacePrefix; - colonIndex = name.indexOf(':'); - if (colonIndex !== -1) { - namespacePrefix = name.substr(0, colonIndex); - if (namespacePrefix !== 'xmlns') { - name = name.substring(colonIndex + 1); - attribute.name = enforceCase(name); - attribute.lcName = attribute.name.toLowerCase(); - attribute.namespace = namespaces[namespacePrefix.toLowerCase()]; - if (!attribute.namespace) { - throw 'Unknown namespace ("' + namespacePrefix + '")'; - } - return; - } - } - attribute.name = attribute.element.namespace !== namespaces.html ? enforceCase(name) : name; - attribute.lcName = attribute.name.toLowerCase(); - }; - }(config_namespaces, render_DomFragment_shared_enforceCase); -var render_DomFragment_Attribute_helpers_setStaticAttribute = function (namespaces) { - - return function (attribute, options) { - var node, value = options.value === null ? '' : options.value; - if (node = options.pNode) { - if (attribute.namespace) { - node.setAttributeNS(attribute.namespace, options.name, value); - } else { - if (options.name === 'style' && node.style.setAttribute) { - node.style.setAttribute('cssText', value); - } else if (options.name === 'class' && (!node.namespaceURI || node.namespaceURI === namespaces.html)) { - node.className = value; - } else { - node.setAttribute(options.name, value); - } - } - if (attribute.name === 'id') { - options.root.nodes[options.value] = node; - } - if (attribute.name === 'value') { - node._ractive.value = options.value; - } - } - attribute.value = options.value; - }; - }(config_namespaces); -var render_DomFragment_Attribute_helpers_determinePropertyName = function (namespaces) { - - var propertyNames = { - 'accept-charset': 'acceptCharset', - accesskey: 'accessKey', - bgcolor: 'bgColor', - 'class': 'className', - codebase: 'codeBase', - colspan: 'colSpan', - contenteditable: 'contentEditable', - datetime: 'dateTime', - dirname: 'dirName', - 'for': 'htmlFor', - 'http-equiv': 'httpEquiv', - ismap: 'isMap', - maxlength: 'maxLength', - novalidate: 'noValidate', - pubdate: 'pubDate', - readonly: 'readOnly', - rowspan: 'rowSpan', - tabindex: 'tabIndex', - usemap: 'useMap' - }; - return function (attribute, options) { - var propertyName; - if (attribute.pNode && !attribute.namespace && (!options.pNode.namespaceURI || options.pNode.namespaceURI === namespaces.html)) { - propertyName = propertyNames[attribute.name] || attribute.name; - if (options.pNode[propertyName] !== undefined) { - attribute.propertyName = propertyName; - } - if (typeof options.pNode[propertyName] === 'boolean' || propertyName === 'value') { - attribute.useProperty = true; - } - } - }; - }(config_namespaces); -var render_DomFragment_Attribute_prototype_bind = function (types, warn, arrayContentsMatch, getValueFromCheckboxes) { - - var bindAttribute, getInterpolator, updateModel, update, getBinding, inheritProperties, MultipleSelectBinding, SelectBinding, RadioNameBinding, CheckboxNameBinding, CheckedBinding, FileListBinding, ContentEditableBinding, GenericBinding; - bindAttribute = function () { - var node = this.pNode, interpolator, binding, bindings; - if (!this.fragment) { - return false; - } - interpolator = getInterpolator(this); - if (!interpolator) { - return false; - } - this.interpolator = interpolator; - this.keypath = interpolator.keypath || interpolator.descriptor.r; - binding = getBinding(this); - if (!binding) { - return false; - } - node._ractive.binding = this.element.binding = binding; - this.twoway = true; - bindings = this.root._twowayBindings[this.keypath] || (this.root._twowayBindings[this.keypath] = []); - bindings[bindings.length] = binding; - return true; - }; - updateModel = function () { - this._ractive.binding.update(); - }; - update = function () { - var value = this._ractive.root.get(this._ractive.binding.keypath); - this.value = value == undefined ? '' : value; - }; - getInterpolator = function (attribute) { - var item, errorMessage; - if (attribute.fragment.items.length !== 1) { - return null; - } - item = attribute.fragment.items[0]; - if (item.type !== types.INTERPOLATOR) { - return null; - } - if (!item.keypath && !item.ref) { - return null; - } - if (item.keypath && item.keypath.substr(0, 2) === '${') { - errorMessage = 'You cannot set up two-way binding against an expression ' + item.keypath; - if (attribute.root.debug) { - warn(errorMessage); - } - return null; - } - return item; - }; - getBinding = function (attribute) { - var node = attribute.pNode; - if (node.tagName === 'SELECT') { - return node.multiple ? new MultipleSelectBinding(attribute, node) : new SelectBinding(attribute, node); - } - if (node.type === 'checkbox' || node.type === 'radio') { - if (attribute.propertyName === 'name') { - if (node.type === 'checkbox') { - return new CheckboxNameBinding(attribute, node); - } - if (node.type === 'radio') { - return new RadioNameBinding(attribute, node); - } - } - if (attribute.propertyName === 'checked') { - return new CheckedBinding(attribute, node); - } - return null; - } - if (attribute.lcName !== 'value') { - warn('This is... odd'); - } - if (node.type === 'file') { - return new FileListBinding(attribute, node); - } - if (node.getAttribute('contenteditable')) { - return new ContentEditableBinding(attribute, node); - } - return new GenericBinding(attribute, node); - }; - MultipleSelectBinding = function (attribute, node) { - var valueFromModel; - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - valueFromModel = this.root.get(this.keypath); - if (valueFromModel === undefined) { - this.update(); - } - }; - MultipleSelectBinding.prototype = { - value: function () { - var value, options, i, len; - value = []; - options = this.node.options; - len = options.length; - for (i = 0; i < len; i += 1) { - if (options[i].selected) { - value[value.length] = options[i]._ractive.value; - } - } - return value; - }, - update: function () { - var attribute, previousValue, value; - attribute = this.attr; - previousValue = attribute.value; - value = this.value(); - if (previousValue === undefined || !arrayContentsMatch(value, previousValue)) { - attribute.receiving = true; - attribute.value = value; - this.root.set(this.keypath, value); - attribute.receiving = false; - } - return this; - }, - deferUpdate: function () { - if (this.deferred === true) { - return; - } - this.root._deferred.attrs.push(this); - this.deferred = true; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - } - }; - SelectBinding = function (attribute, node) { - var valueFromModel; - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - valueFromModel = this.root.get(this.keypath); - if (valueFromModel === undefined) { - this.update(); - } - }; - SelectBinding.prototype = { - value: function () { - var options, i, len; - options = this.node.options; - len = options.length; - for (i = 0; i < len; i += 1) { - if (options[i].selected) { - return options[i]._ractive.value; - } - } - }, - update: function () { - var value = this.value(); - this.attr.receiving = true; - this.attr.value = value; - this.root.set(this.keypath, value); - this.attr.receiving = false; - return this; - }, - deferUpdate: function () { - if (this.deferred === true) { - return; - } - this.root._deferred.attrs.push(this); - this.deferred = true; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - } - }; - RadioNameBinding = function (attribute, node) { - var valueFromModel; - this.radioName = true; - inheritProperties(this, attribute, node); - node.name = '{{' + attribute.keypath + '}}'; - node.addEventListener('change', updateModel, false); - if (node.attachEvent) { - node.addEventListener('click', updateModel, false); - } - valueFromModel = this.root.get(this.keypath); - if (valueFromModel !== undefined) { - node.checked = valueFromModel == node._ractive.value; - } else { - this.root._deferred.radios.push(this); - } - }; - RadioNameBinding.prototype = { - value: function () { - return this.node._ractive ? this.node._ractive.value : this.node.value; - }, - update: function () { - var node = this.node; - if (node.checked) { - this.attr.receiving = true; - this.root.set(this.keypath, this.value()); - this.attr.receiving = false; - } - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('click', updateModel, false); - } - }; - CheckboxNameBinding = function (attribute, node) { - var valueFromModel, checked; - this.checkboxName = true; - inheritProperties(this, attribute, node); - node.name = '{{' + this.keypath + '}}'; - node.addEventListener('change', updateModel, false); - if (node.attachEvent) { - node.addEventListener('click', updateModel, false); - } - valueFromModel = this.root.get(this.keypath); - if (valueFromModel !== undefined) { - checked = valueFromModel.indexOf(node._ractive.value) !== -1; - node.checked = checked; - } else { - if (this.root._deferred.checkboxes.indexOf(this.keypath) === -1) { - this.root._deferred.checkboxes.push(this.keypath); - } - } - }; - CheckboxNameBinding.prototype = { - changed: function () { - return this.node.checked !== !!this.checked; - }, - update: function () { - this.checked = this.node.checked; - this.attr.receiving = true; - this.root.set(this.keypath, getValueFromCheckboxes(this.root, this.keypath)); - this.attr.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('click', updateModel, false); - } - }; - CheckedBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - if (node.attachEvent) { - node.addEventListener('click', updateModel, false); - } - }; - CheckedBinding.prototype = { - value: function () { - return this.node.checked; - }, - update: function () { - this.attr.receiving = true; - this.root.set(this.keypath, this.value()); - this.attr.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('click', updateModel, false); - } - }; - FileListBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - }; - FileListBinding.prototype = { - value: function () { - return this.attr.pNode.files; - }, - update: function () { - this.attr.root.set(this.attr.keypath, this.value()); - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - } - }; - ContentEditableBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - if (!this.root.lazy) { - node.addEventListener('input', updateModel, false); - if (node.attachEvent) { - node.addEventListener('keyup', updateModel, false); - } - } - }; - ContentEditableBinding.prototype = { - update: function () { - this.attr.receiving = true; - this.root.set(this.keypath, this.node.innerHTML); - this.attr.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('input', updateModel, false); - this.node.removeEventListener('keyup', updateModel, false); - } - }; - GenericBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - if (!this.root.lazy) { - node.addEventListener('input', updateModel, false); - if (node.attachEvent) { - node.addEventListener('keyup', updateModel, false); - } - } - this.node.addEventListener('blur', update, false); - }; - GenericBinding.prototype = { - value: function () { - var value = this.attr.pNode.value; - if (+value + '' === value && value.indexOf('e') === -1) { - value = +value; - } - return value; - }, - update: function () { - var attribute = this.attr, value = this.value(); - attribute.receiving = true; - attribute.root.set(attribute.keypath, value); - attribute.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('input', updateModel, false); - this.node.removeEventListener('keyup', updateModel, false); - this.node.removeEventListener('blur', update, false); - } - }; - inheritProperties = function (binding, attribute, node) { - binding.attr = attribute; - binding.node = node; - binding.root = attribute.root; - binding.keypath = attribute.keypath; - }; - return bindAttribute; - }(config_types, utils_warn, utils_arrayContentsMatch, shared_getValueFromCheckboxes); -var render_DomFragment_Attribute_prototype_update = function (isArray, namespaces) { - - var updateAttribute, updateFileInputValue, deferSelect, initSelect, updateSelect, updateMultipleSelect, updateRadioName, updateCheckboxName, updateIEStyleAttribute, updateClassName, updateContentEditableValue, updateEverythingElse; - updateAttribute = function () { - var node; - if (!this.ready) { - return this; - } - node = this.pNode; - if (node.tagName === 'SELECT' && this.lcName === 'value') { - this.update = deferSelect; - this.deferredUpdate = initSelect; - return this.update(); - } - if (this.isFileInputValue) { - this.update = updateFileInputValue; - return this; - } - if (this.twoway && this.lcName === 'name') { - if (node.type === 'radio') { - this.update = updateRadioName; - return this.update(); - } - if (node.type === 'checkbox') { - this.update = updateCheckboxName; - return this.update(); - } - } - if (this.lcName === 'style' && node.style.setAttribute) { - this.update = updateIEStyleAttribute; - return this.update(); - } - if (this.lcName === 'class' && (!node.namespaceURI || node.namespaceURI === namespaces.html)) { - this.update = updateClassName; - return this.update(); - } - if (node.getAttribute('contenteditable') && this.lcName === 'value') { - this.update = updateContentEditableValue; - return this.update(); - } - this.update = updateEverythingElse; - return this.update(); - }; - updateFileInputValue = function () { - return this; - }; - initSelect = function () { - this.deferredUpdate = this.pNode.multiple ? updateMultipleSelect : updateSelect; - this.deferredUpdate(); - }; - deferSelect = function () { - this.root._deferred.selectValues.push(this); - return this; - }; - updateSelect = function () { - var value = this.fragment.getValue(), options, option, i; - this.value = this.pNode._ractive.value = value; - options = this.pNode.options; - i = options.length; - while (i--) { - option = options[i]; - if (option._ractive.value == value) { - option.selected = true; - return this; - } - } - return this; - }; - updateMultipleSelect = function () { - var value = this.fragment.getValue(), options, i; - if (!isArray(value)) { - value = [value]; - } - options = this.pNode.options; - i = options.length; - while (i--) { - options[i].selected = value.indexOf(options[i]._ractive.value) !== -1; - } - this.value = value; - return this; - }; - updateRadioName = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - node.checked = value == node._ractive.value; - return this; - }; - updateCheckboxName = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (!isArray(value)) { - node.checked = value == node._ractive.value; - return this; - } - node.checked = value.indexOf(node._ractive.value) !== -1; - return this; - }; - updateIEStyleAttribute = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - node.style.setAttribute('cssText', value); - this.value = value; - } - return this; - }; - updateClassName = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - node.className = value; - this.value = value; - } - return this; - }; - updateContentEditableValue = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - if (!this.receiving) { - node.innerHTML = value; - } - this.value = value; - } - return this; - }; - updateEverythingElse = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (this.isValueAttribute) { - node._ractive.value = value; - } - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - if (this.useProperty) { - if (!this.receiving) { - node[this.propertyName] = value; - } - this.value = value; - return this; - } - if (this.namespace) { - node.setAttributeNS(this.namespace, this.name, value); - this.value = value; - return this; - } - if (this.lcName === 'id') { - if (this.value !== undefined) { - this.root.nodes[this.value] = undefined; - } - this.root.nodes[value] = node; - } - node.setAttribute(this.name, value); - this.value = value; - } - return this; - }; - return updateAttribute; - }(utils_isArray, config_namespaces); -var parse_Tokenizer_utils_getStringMatch = function () { - - return function (string) { - var substr; - substr = this.str.substr(this.pos, string.length); - if (substr === string) { - this.pos += string.length; - return string; - } - return null; - }; - }(); -var parse_Tokenizer_utils_allowWhitespace = function () { - - var leadingWhitespace = /^\s+/; - return function () { - var match = leadingWhitespace.exec(this.remaining()); - if (!match) { - return null; - } - this.pos += match[0].length; - return match[0]; - }; - }(); -var parse_Tokenizer_utils_makeRegexMatcher = function () { - - return function (regex) { - return function (tokenizer) { - var match = regex.exec(tokenizer.str.substring(tokenizer.pos)); - if (!match) { - return null; - } - tokenizer.pos += match[0].length; - return match[1] || match[0]; - }; - }; - }(); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getEscapedChars = function () { - - return function (tokenizer) { - var chars = '', character; - character = getEscapedChar(tokenizer); - while (character) { - chars += character; - character = getEscapedChar(tokenizer); - } - return chars || null; - }; - function getEscapedChar(tokenizer) { - var character; - if (!tokenizer.getStringMatch('\\')) { - return null; - } - character = tokenizer.str.charAt(tokenizer.pos); - tokenizer.pos += 1; - return character; - } - }(); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getQuotedString = function (makeRegexMatcher, getEscapedChars) { - - var getUnescapedDoubleQuotedChars = makeRegexMatcher(/^[^\\"]+/), getUnescapedSingleQuotedChars = makeRegexMatcher(/^[^\\']+/); - return function getQuotedString(tokenizer, singleQuotes) { - var start, string, escaped, unescaped, next, matcher; - start = tokenizer.pos; - string = ''; - matcher = singleQuotes ? getUnescapedSingleQuotedChars : getUnescapedDoubleQuotedChars; - escaped = getEscapedChars(tokenizer); - if (escaped) { - string += escaped; - } - unescaped = matcher(tokenizer); - if (unescaped) { - string += unescaped; - } - if (!string) { - return ''; - } - next = getQuotedString(tokenizer, singleQuotes); - while (next !== '') { - string += next; - } - return string; - }; - }(parse_Tokenizer_utils_makeRegexMatcher, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getEscapedChars); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral = function (types, getQuotedString) { - - return function (tokenizer) { - var start, string; - start = tokenizer.pos; - if (tokenizer.getStringMatch('"')) { - string = getQuotedString(tokenizer, false); - if (!tokenizer.getStringMatch('"')) { - tokenizer.pos = start; - return null; - } - return { - t: types.STRING_LITERAL, - v: string - }; - } - if (tokenizer.getStringMatch('\'')) { - string = getQuotedString(tokenizer, true); - if (!tokenizer.getStringMatch('\'')) { - tokenizer.pos = start; - return null; - } - return { - t: types.STRING_LITERAL, - v: string - }; - } - return null; - }; - }(config_types, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getQuotedString); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getNumberLiteral = function (types, makeRegexMatcher) { - - var getNumber = makeRegexMatcher(/^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/); - return function (tokenizer) { - var result; - if (result = getNumber(tokenizer)) { - return { - t: types.NUMBER_LITERAL, - v: result - }; - } - return null; - }; - }(config_types, parse_Tokenizer_utils_makeRegexMatcher); -var parse_Tokenizer_getExpression_shared_getName = function (makeRegexMatcher) { - - return makeRegexMatcher(/^[a-zA-Z_$][a-zA-Z_$0-9]*/); - }(parse_Tokenizer_utils_makeRegexMatcher); -var parse_Tokenizer_getExpression_shared_getKey = function (getStringLiteral, getNumberLiteral, getName) { - - var identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/; - return function (tokenizer) { - var token; - if (token = getStringLiteral(tokenizer)) { - return identifier.test(token.v) ? token.v : '"' + token.v.replace(/"/g, '\\"') + '"'; - } - if (token = getNumberLiteral(tokenizer)) { - return token.v; - } - if (token = getName(tokenizer)) { - return token; - } - }; - }(parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getNumberLiteral, parse_Tokenizer_getExpression_shared_getName); -var utils_parseJSON = function (getStringMatch, allowWhitespace, getStringLiteral, getKey) { - - var Tokenizer, specials, specialsPattern, numberPattern, placeholderPattern, placeholderAtStartPattern; - specials = { - 'true': true, - 'false': false, - 'undefined': undefined, - 'null': null - }; - specialsPattern = new RegExp('^(?:' + Object.keys(specials).join('|') + ')'); - numberPattern = /^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/; - placeholderPattern = /\$\{([^\}]+)\}/g; - placeholderAtStartPattern = /^\$\{([^\}]+)\}/; - Tokenizer = function (str, values) { - this.str = str; - this.values = values; - this.pos = 0; - this.result = this.getToken(); - }; - Tokenizer.prototype = { - remaining: function () { - return this.str.substring(this.pos); - }, - getStringMatch: getStringMatch, - getToken: function () { - this.allowWhitespace(); - return this.getPlaceholder() || this.getSpecial() || this.getNumber() || this.getString() || this.getObject() || this.getArray(); - }, - getPlaceholder: function () { - var match; - if (!this.values) { - return null; - } - if ((match = placeholderAtStartPattern.exec(this.remaining())) && this.values.hasOwnProperty(match[1])) { - this.pos += match[0].length; - return { v: this.values[match[1]] }; - } - }, - getSpecial: function () { - var match; - if (match = specialsPattern.exec(this.remaining())) { - this.pos += match[0].length; - return { v: specials[match[0]] }; - } - }, - getNumber: function () { - var match; - if (match = numberPattern.exec(this.remaining())) { - this.pos += match[0].length; - return { v: +match[0] }; - } - }, - getString: function () { - var stringLiteral = getStringLiteral(this), values; - if (stringLiteral && (values = this.values)) { - return { - v: stringLiteral.v.replace(placeholderPattern, function (match, $1) { - return values[$1] || $1; - }) - }; - } - return stringLiteral; - }, - getObject: function () { - var result, pair; - if (!this.getStringMatch('{')) { - return null; - } - result = {}; - while (pair = getKeyValuePair(this)) { - result[pair.key] = pair.value; - this.allowWhitespace(); - if (this.getStringMatch('}')) { - return { v: result }; - } - if (!this.getStringMatch(',')) { - return null; - } - } - return null; - }, - getArray: function () { - var result, valueToken; - if (!this.getStringMatch('[')) { - return null; - } - result = []; - while (valueToken = this.getToken()) { - result.push(valueToken.v); - if (this.getStringMatch(']')) { - return { v: result }; - } - if (!this.getStringMatch(',')) { - return null; - } - } - return null; - }, - allowWhitespace: allowWhitespace - }; - function getKeyValuePair(tokenizer) { - var key, valueToken, pair; - tokenizer.allowWhitespace(); - key = getKey(tokenizer); - if (!key) { - return null; - } - pair = { key: key }; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(':')) { - return null; - } - tokenizer.allowWhitespace(); - valueToken = tokenizer.getToken(); - if (!valueToken) { - return null; - } - pair.value = valueToken.v; - return pair; - } - return function (str, values) { - var tokenizer = new Tokenizer(str, values); - if (tokenizer.result) { - return { - value: tokenizer.result.v, - remaining: tokenizer.remaining() - }; - } - return null; - }; - }(parse_Tokenizer_utils_getStringMatch, parse_Tokenizer_utils_allowWhitespace, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral, parse_Tokenizer_getExpression_shared_getKey); -var render_StringFragment_Interpolator = function (types, teardown, initMustache, updateMustache, resolveMustache) { - - var StringInterpolator = function (options) { - this.type = types.INTERPOLATOR; - initMustache(this, options); - }; - StringInterpolator.prototype = { - update: updateMustache, - resolve: resolveMustache, - render: function (value) { - this.value = value; - this.parentFragment.bubble(); - }, - teardown: function () { - teardown(this); - }, - toString: function () { - if (this.value == undefined) { - return ''; - } - return stringify(this.value); - } - }; - return StringInterpolator; - function stringify(value) { - if (typeof value === 'string') { - return value; - } - return JSON.stringify(value); - } - }(config_types, shared_teardown, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache); -var render_StringFragment_Section = function (types, initMustache, updateMustache, resolveMustache, updateSection, teardown, circular) { - - var StringSection, StringFragment; - circular.push(function () { - StringFragment = circular.StringFragment; - }); - StringSection = function (options) { - this.type = types.SECTION; - this.fragments = []; - this.length = 0; - initMustache(this, options); - }; - StringSection.prototype = { - update: updateMustache, - resolve: resolveMustache, - teardown: function () { - this.teardownFragments(); - teardown(this); - }, - teardownFragments: function () { - while (this.fragments.length) { - this.fragments.shift().teardown(); - } - this.length = 0; - }, - bubble: function () { - this.value = this.fragments.join(''); - this.parentFragment.bubble(); - }, - render: function (value) { - var wrapped; - if (wrapped = this.root._wrapped[this.keypath]) { - value = wrapped.get(); - } - updateSection(this, value); - this.parentFragment.bubble(); - }, - createFragment: function (options) { - return new StringFragment(options); - }, - toString: function () { - return this.fragments.join(''); - } - }; - return StringSection; - }(config_types, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache, render_shared_updateSection, shared_teardown, circular); -var render_StringFragment_Text = function (types) { - - var StringText = function (text) { - this.type = types.TEXT; - this.text = text; - }; - StringText.prototype = { - toString: function () { - return this.text; - }, - teardown: function () { - } - }; - return StringText; - }(config_types); -var render_StringFragment_prototype_toArgsList = function (warn, parseJSON) { - - return function () { - var values, counter, jsonesque, guid, errorMessage, parsed, processItems; - if (!this.argsList || this.dirty) { - values = {}; - counter = 0; - guid = this.root._guid; - processItems = function (items) { - return items.map(function (item) { - var placeholderId, wrapped, value; - if (item.text) { - return item.text; - } - if (item.fragments) { - return item.fragments.map(function (fragment) { - return processItems(fragment.items); - }).join(''); - } - placeholderId = guid + '-' + counter++; - if (wrapped = item.root._wrapped[item.keypath]) { - value = wrapped.value; - } else { - value = item.value; - } - values[placeholderId] = value; - return '${' + placeholderId + '}'; - }).join(''); - }; - jsonesque = processItems(this.items); - parsed = parseJSON('[' + jsonesque + ']', values); - if (!parsed) { - errorMessage = 'Could not parse directive arguments (' + this.toString() + '). If you think this is a bug, please file an issue at http://github.com/RactiveJS/Ractive/issues'; - if (this.root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - this.argsList = [jsonesque]; - } - } else { - this.argsList = parsed.value; - } - this.dirty = false; - } - return this.argsList; - }; - }(utils_warn, utils_parseJSON); -var render_StringFragment__StringFragment = function (types, parseJSON, initFragment, Interpolator, Section, Text, toArgsList, circular) { - - var StringFragment = function (options) { - initFragment(this, options); - }; - StringFragment.prototype = { - createItem: function (options) { - if (typeof options.descriptor === 'string') { - return new Text(options.descriptor); - } - switch (options.descriptor.t) { - case types.INTERPOLATOR: - return new Interpolator(options); - case types.TRIPLE: - return new Interpolator(options); - case types.SECTION: - return new Section(options); - default: - throw 'Something went wrong in a rather interesting way'; - } - }, - bubble: function () { - this.dirty = true; - this.owner.bubble(); - }, - teardown: function () { - var numItems, i; - numItems = this.items.length; - for (i = 0; i < numItems; i += 1) { - this.items[i].teardown(); - } - }, - getValue: function () { - var value; - if (this.items.length === 1 && this.items[0].type === types.INTERPOLATOR) { - value = this.items[0].value; - if (value !== undefined) { - return value; - } - } - return this.toString(); - }, - isSimple: function () { - var i, item, containsInterpolator; - if (this.simple !== undefined) { - return this.simple; - } - i = this.items.length; - while (i--) { - item = this.items[i]; - if (item.type === types.TEXT) { - continue; - } - if (item.type === types.INTERPOLATOR) { - if (containsInterpolator) { - return false; - } else { - containsInterpolator = true; - continue; - } - } - return this.simple = false; - } - return this.simple = true; - }, - toString: function () { - return this.items.join(''); - }, - toJSON: function () { - var value = this.getValue(), parsed; - if (typeof value === 'string') { - parsed = parseJSON(value); - value = parsed ? parsed.value : value; - } - return value; - }, - toArgsList: toArgsList - }; - circular.StringFragment = StringFragment; - return StringFragment; - }(config_types, utils_parseJSON, render_shared_initFragment, render_StringFragment_Interpolator, render_StringFragment_Section, render_StringFragment_Text, render_StringFragment_prototype_toArgsList, circular); -var render_DomFragment_Attribute__Attribute = function (types, determineNameAndNamespace, setStaticAttribute, determinePropertyName, bind, update, StringFragment) { - - var DomAttribute = function (options) { - this.type = types.ATTRIBUTE; - this.element = options.element; - determineNameAndNamespace(this, options.name); - if (options.value === null || typeof options.value === 'string') { - setStaticAttribute(this, options); - return; - } - this.root = options.root; - this.pNode = options.pNode; - this.parentFragment = this.element.parentFragment; - this.fragment = new StringFragment({ - descriptor: options.value, - root: this.root, - owner: this, - contextStack: options.contextStack - }); - if (!this.pNode) { - return; - } - if (this.name === 'value') { - this.isValueAttribute = true; - if (this.pNode.tagName === 'INPUT' && this.pNode.type === 'file') { - this.isFileInputValue = true; - } - } - determinePropertyName(this, options); - this.selfUpdating = this.fragment.isSimple(); - this.ready = true; - }; - DomAttribute.prototype = { - bind: bind, - update: update, - updateBindings: function () { - this.keypath = this.interpolator.keypath || this.interpolator.ref; - if (this.propertyName === 'name') { - this.pNode.name = '{{' + this.keypath + '}}'; - } - }, - teardown: function () { - var i; - if (this.boundEvents) { - i = this.boundEvents.length; - while (i--) { - this.pNode.removeEventListener(this.boundEvents[i], this.updateModel, false); - } - } - if (this.fragment) { - this.fragment.teardown(); - } - }, - bubble: function () { - if (this.selfUpdating) { - this.update(); - } else if (!this.deferred && this.ready) { - this.root._deferred.attrs.push(this); - this.deferred = true; - } - }, - toString: function () { - var str; - if (this.value === null) { - return this.name; - } - if (!this.fragment) { - return this.name + '=' + JSON.stringify(this.value); - } - str = this.fragment.toString(); - return this.name + '=' + JSON.stringify(str); - } - }; - return DomAttribute; - }(config_types, render_DomFragment_Attribute_helpers_determineNameAndNamespace, render_DomFragment_Attribute_helpers_setStaticAttribute, render_DomFragment_Attribute_helpers_determinePropertyName, render_DomFragment_Attribute_prototype_bind, render_DomFragment_Attribute_prototype_update, render_StringFragment__StringFragment); -var render_DomFragment_Element_initialise_createElementAttributes = function (DomAttribute) { - - return function (element, attributes) { - var attrName, attrValue, attr; - element.attributes = []; - for (attrName in attributes) { - if (attributes.hasOwnProperty(attrName)) { - attrValue = attributes[attrName]; - attr = new DomAttribute({ - element: element, - name: attrName, - value: attrValue, - root: element.root, - pNode: element.node, - contextStack: element.parentFragment.contextStack - }); - element.attributes[element.attributes.length] = element.attributes[attrName] = attr; - if (attrName !== 'name') { - attr.update(); - } - } - } - return element.attributes; - }; - }(render_DomFragment_Attribute__Attribute); -var render_DomFragment_Element_initialise_appendElementChildren = function (warn, namespaces, StringFragment, circular) { - - var DomFragment, updateCss, updateScript; - circular.push(function () { - DomFragment = circular.DomFragment; - }); - updateCss = function () { - var node = this.node, content = this.fragment.toString(); - if (node.styleSheet) { - node.styleSheet.cssText = content; - } - node.innerHTML = content; - }; - updateScript = function () { - if (!this.node.type || this.node.type === 'text/javascript') { - warn('Script tag was updated. This does not cause the code to be re-evaluated!'); - } - this.node.innerHTML = this.fragment.toString(); - }; - return function (element, node, descriptor, docFrag) { - var liveQueries, i, selector, queryAllResult, j; - if (element.lcName === 'script' || element.lcName === 'style') { - element.fragment = new StringFragment({ - descriptor: descriptor.f, - root: element.root, - contextStack: element.parentFragment.contextStack, - owner: element - }); - if (docFrag) { - if (element.lcName === 'script') { - element.bubble = updateScript; - element.node.innerHTML = element.fragment.toString(); - } else { - element.bubble = updateCss; - element.bubble(); - } - } - return; - } - if (typeof descriptor.f === 'string' && (!node || (!node.namespaceURI || node.namespaceURI === namespaces.html))) { - element.html = descriptor.f; - if (docFrag) { - node.innerHTML = element.html; - liveQueries = element.root._liveQueries; - i = liveQueries.length; - while (i--) { - selector = liveQueries[i]; - if ((queryAllResult = node.querySelectorAll(selector)) && (j = queryAllResult.length)) { - (element.liveQueries || (element.liveQueries = [])).push(selector); - element.liveQueries[selector] = []; - while (j--) { - element.liveQueries[selector][j] = queryAllResult[j]; - } - } - } - } - } else { - element.fragment = new DomFragment({ - descriptor: descriptor.f, - root: element.root, - pNode: node, - contextStack: element.parentFragment.contextStack, - owner: element - }); - if (docFrag) { - node.appendChild(element.fragment.docFrag); - } - } - }; - }(utils_warn, config_namespaces, render_StringFragment__StringFragment, circular); -var render_DomFragment_Element_initialise_decorate_Decorator = function (warn, StringFragment) { - - var Decorator = function (descriptor, root, owner, contextStack) { - var name, fragment, errorMessage; - this.root = root; - this.node = owner.node; - name = descriptor.n || descriptor; - if (typeof name !== 'string') { - fragment = new StringFragment({ - descriptor: name, - root: this.root, - owner: owner, - contextStack: contextStack - }); - name = fragment.toString(); - fragment.teardown(); - } - if (descriptor.a) { - this.params = descriptor.a; - } else if (descriptor.d) { - fragment = new StringFragment({ - descriptor: descriptor.d, - root: this.root, - owner: owner, - contextStack: contextStack - }); - this.params = fragment.toArgsList(); - fragment.teardown(); - } - this.fn = root.decorators[name]; - if (!this.fn) { - errorMessage = 'Missing "' + name + '" decorator. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#decorators'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - } - }; - Decorator.prototype = { - init: function () { - var result, args; - if (this.params) { - args = [this.node].concat(this.params); - result = this.fn.apply(this.root, args); - } else { - result = this.fn.call(this.root, this.node); - } - if (!result || !result.teardown) { - throw new Error('Decorator definition must return an object with a teardown method'); - } - this.teardown = result.teardown; - } - }; - return Decorator; - }(utils_warn, render_StringFragment__StringFragment); -var render_DomFragment_Element_initialise_decorate__decorate = function (Decorator) { - - return function (descriptor, root, owner, contextStack) { - owner.decorator = new Decorator(descriptor, root, owner, contextStack); - if (owner.decorator.fn) { - root._deferred.decorators.push(owner.decorator); - } - }; - }(render_DomFragment_Element_initialise_decorate_Decorator); -var render_DomFragment_Element_initialise_addEventProxies_addEventProxy = function (warn, StringFragment) { - - var addEventProxy, MasterEventHandler, ProxyEvent, firePlainEvent, fireEventWithArgs, fireEventWithDynamicArgs, customHandlers, genericHandler, getCustomHandler; - addEventProxy = function (element, triggerEventName, proxyDescriptor, contextStack, indexRefs) { - var events, master; - events = element.node._ractive.events; - master = events[triggerEventName] || (events[triggerEventName] = new MasterEventHandler(element, triggerEventName, contextStack, indexRefs)); - master.add(proxyDescriptor); - }; - MasterEventHandler = function (element, eventName, contextStack) { - var definition; - this.element = element; - this.root = element.root; - this.node = element.node; - this.name = eventName; - this.contextStack = contextStack; - this.proxies = []; - if (definition = this.root.events[eventName]) { - this.custom = definition(this.node, getCustomHandler(eventName)); - } else { - if (!('on' + eventName in this.node)) { - warn('Missing "' + this.name + '" event. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#events'); - } - this.node.addEventListener(eventName, genericHandler, false); - } - }; - MasterEventHandler.prototype = { - add: function (proxy) { - this.proxies[this.proxies.length] = new ProxyEvent(this.element, this.root, proxy, this.contextStack); - }, - teardown: function () { - var i; - if (this.custom) { - this.custom.teardown(); - } else { - this.node.removeEventListener(this.name, genericHandler, false); - } - i = this.proxies.length; - while (i--) { - this.proxies[i].teardown(); - } - }, - fire: function (event) { - var i = this.proxies.length; - while (i--) { - this.proxies[i].fire(event); - } - } - }; - ProxyEvent = function (element, ractive, descriptor, contextStack) { - var name; - this.root = ractive; - name = descriptor.n || descriptor; - if (typeof name === 'string') { - this.n = name; - } else { - this.n = new StringFragment({ - descriptor: descriptor.n, - root: this.root, - owner: element, - contextStack: contextStack - }); - } - if (descriptor.a) { - this.a = descriptor.a; - this.fire = fireEventWithArgs; - return; - } - if (descriptor.d) { - this.d = new StringFragment({ - descriptor: descriptor.d, - root: this.root, - owner: element, - contextStack: contextStack - }); - this.fire = fireEventWithDynamicArgs; - return; - } - this.fire = firePlainEvent; - }; - ProxyEvent.prototype = { - teardown: function () { - if (this.n.teardown) { - this.n.teardown(); - } - if (this.d) { - this.d.teardown(); - } - }, - bubble: function () { - } - }; - firePlainEvent = function (event) { - this.root.fire(this.n.toString(), event); - }; - fireEventWithArgs = function (event) { - this.root.fire.apply(this.root, [ - this.n.toString(), - event - ].concat(this.a)); - }; - fireEventWithDynamicArgs = function (event) { - var args = this.d.toArgsList(); - if (typeof args === 'string') { - args = args.substr(1, args.length - 2); - } - this.root.fire.apply(this.root, [ - this.n.toString(), - event - ].concat(args)); - }; - genericHandler = function (event) { - var storage = this._ractive; - storage.events[event.type].fire({ - node: this, - original: event, - index: storage.index, - keypath: storage.keypath, - context: storage.root.get(storage.keypath) - }); - }; - customHandlers = {}; - getCustomHandler = function (eventName) { - if (customHandlers[eventName]) { - return customHandlers[eventName]; - } - return customHandlers[eventName] = function (event) { - var storage = event.node._ractive; - event.index = storage.index; - event.keypath = storage.keypath; - event.context = storage.root.get(storage.keypath); - storage.events[eventName].fire(event); - }; - }; - return addEventProxy; - }(utils_warn, render_StringFragment__StringFragment); -var render_DomFragment_Element_initialise_addEventProxies__addEventProxies = function (addEventProxy) { - - return function (element, proxies) { - var i, eventName, eventNames; - for (eventName in proxies) { - if (proxies.hasOwnProperty(eventName)) { - eventNames = eventName.split('-'); - i = eventNames.length; - while (i--) { - addEventProxy(element, eventNames[i], proxies[eventName], element.parentFragment.contextStack); - } - } - } - }; - }(render_DomFragment_Element_initialise_addEventProxies_addEventProxy); -var render_DomFragment_Element_initialise_updateLiveQueries = function () { - - return function (element) { - var ractive, liveQueries, i, selector, query; - ractive = element.root; - liveQueries = ractive._liveQueries; - i = liveQueries.length; - while (i--) { - selector = liveQueries[i]; - query = liveQueries[selector]; - if (query._test(element)) { - (element.liveQueries || (element.liveQueries = [])).push(selector); - element.liveQueries[selector] = [element.node]; - } - } - }; - }(); -var utils_camelCase = function () { - - return function (hyphenatedStr) { - return hyphenatedStr.replace(/-([a-zA-Z])/g, function (match, $1) { - return $1.toUpperCase(); - }); - }; - }(); -var utils_fillGaps = function () { - - return function (target, source) { - var key; - for (key in source) { - if (source.hasOwnProperty(key) && !target.hasOwnProperty(key)) { - target[key] = source[key]; - } - } - return target; - }; - }(); -var render_DomFragment_Element_shared_executeTransition_Transition = function (isClient, createElement, warn, isNumeric, isArray, camelCase, fillGaps, StringFragment) { - - var Transition, testStyle, vendors, vendorPattern, unprefixPattern, prefixCache, CSS_TRANSITIONS_ENABLED, TRANSITION, TRANSITION_DURATION, TRANSITION_PROPERTY, TRANSITION_TIMING_FUNCTION, TRANSITIONEND; - if (!isClient) { - return; - } - testStyle = createElement('div').style; - (function () { - if (testStyle.transition !== undefined) { - TRANSITION = 'transition'; - TRANSITIONEND = 'transitionend'; - CSS_TRANSITIONS_ENABLED = true; - } else if (testStyle.webkitTransition !== undefined) { - TRANSITION = 'webkitTransition'; - TRANSITIONEND = 'webkitTransitionEnd'; - CSS_TRANSITIONS_ENABLED = true; - } else { - CSS_TRANSITIONS_ENABLED = false; - } - }()); - if (TRANSITION) { - TRANSITION_DURATION = TRANSITION + 'Duration'; - TRANSITION_PROPERTY = TRANSITION + 'Property'; - TRANSITION_TIMING_FUNCTION = TRANSITION + 'TimingFunction'; - } - Transition = function (descriptor, root, owner, contextStack, isIntro) { - var t = this, name, fragment, errorMessage; - this.root = root; - this.node = owner.node; - this.isIntro = isIntro; - this.originalStyle = this.node.getAttribute('style'); - this.complete = function (noReset) { - if (!noReset && t.isIntro) { - t.resetStyle(); - } - t._manager.pop(t.node); - t.node._ractive.transition = null; - }; - name = descriptor.n || descriptor; - if (typeof name !== 'string') { - fragment = new StringFragment({ - descriptor: name, - root: this.root, - owner: owner, - contextStack: contextStack - }); - name = fragment.toString(); - fragment.teardown(); - } - this.name = name; - if (descriptor.a) { - this.params = descriptor.a; - } else if (descriptor.d) { - fragment = new StringFragment({ - descriptor: descriptor.d, - root: this.root, - owner: owner, - contextStack: contextStack - }); - this.params = fragment.toArgsList(); - fragment.teardown(); - } - this._fn = root.transitions[name]; - if (!this._fn) { - errorMessage = 'Missing "' + name + '" transition. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#transitions'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - return; - } - }; - Transition.prototype = { - init: function () { - if (this._inited) { - throw new Error('Cannot initialize a transition more than once'); - } - this._inited = true; - this._fn.apply(this.root, [this].concat(this.params)); - }, - getStyle: function (props) { - var computedStyle, styles, i, prop, value; - computedStyle = window.getComputedStyle(this.node); - if (typeof props === 'string') { - value = computedStyle[prefix(props)]; - if (value === '0px') { - value = 0; - } - return value; - } - if (!isArray(props)) { - throw new Error('Transition#getStyle must be passed a string, or an array of strings representing CSS properties'); - } - styles = {}; - i = props.length; - while (i--) { - prop = props[i]; - value = computedStyle[prefix(prop)]; - if (value === '0px') { - value = 0; - } - styles[prop] = value; - } - return styles; - }, - setStyle: function (style, value) { - var prop; - if (typeof style === 'string') { - this.node.style[prefix(style)] = value; - } else { - for (prop in style) { - if (style.hasOwnProperty(prop)) { - this.node.style[prefix(prop)] = style[prop]; - } - } - } - return this; - }, - animateStyle: function (style, value, options, complete) { - var t = this, propertyNames, changedProperties, computedStyle, current, to, from, transitionEndHandler, i, prop; - if (typeof style === 'string') { - to = {}; - to[style] = value; - } else { - to = style; - complete = options; - options = value; - } - if (!options) { - warn('The "' + t.name + '" transition does not supply an options object to `t.animateStyle()`. This will break in a future version of Ractive. For more info see https://github.com/RactiveJS/Ractive/issues/340'); - options = t; - complete = t.complete; - } - if (!options.duration) { - t.setStyle(to); - if (complete) { - complete(); - } - } - propertyNames = Object.keys(to); - changedProperties = []; - computedStyle = window.getComputedStyle(t.node); - from = {}; - i = propertyNames.length; - while (i--) { - prop = propertyNames[i]; - current = computedStyle[prefix(prop)]; - if (current === '0px') { - current = 0; - } - if (current != to[prop]) { - changedProperties[changedProperties.length] = prop; - t.node.style[prefix(prop)] = current; - } - } - if (!changedProperties.length) { - if (complete) { - complete(); - } - return; - } - setTimeout(function () { - t.node.style[TRANSITION_PROPERTY] = propertyNames.map(prefix).map(hyphenate).join(','); - t.node.style[TRANSITION_TIMING_FUNCTION] = hyphenate(options.easing || 'linear'); - t.node.style[TRANSITION_DURATION] = options.duration / 1000 + 's'; - transitionEndHandler = function (event) { - var index; - index = changedProperties.indexOf(camelCase(unprefix(event.propertyName))); - if (index !== -1) { - changedProperties.splice(index, 1); - } - if (changedProperties.length) { - return; - } - t.root.fire(t.name + ':end'); - t.node.removeEventListener(TRANSITIONEND, transitionEndHandler, false); - if (complete) { - complete(); - } - }; - t.node.addEventListener(TRANSITIONEND, transitionEndHandler, false); - setTimeout(function () { - var i = changedProperties.length; - while (i--) { - prop = changedProperties[i]; - t.node.style[prefix(prop)] = to[prop]; - } - }, 0); - }, options.delay || 0); - }, - resetStyle: function () { - if (this.originalStyle) { - this.node.setAttribute('style', this.originalStyle); - } else { - this.node.getAttribute('style'); - this.node.removeAttribute('style'); - } - }, - processParams: function (params, defaults) { - if (typeof params === 'number') { - params = { duration: params }; - } else if (typeof params === 'string') { - if (params === 'slow') { - params = { duration: 600 }; - } else if (params === 'fast') { - params = { duration: 200 }; - } else { - params = { duration: 400 }; - } - } else if (!params) { - params = {}; - } - return fillGaps(params, defaults); - } - }; - vendors = [ - 'o', - 'ms', - 'moz', - 'webkit' - ]; - vendorPattern = new RegExp('^(?:' + vendors.join('|') + ')([A-Z])'); - unprefixPattern = new RegExp('^-(?:' + vendors.join('|') + ')-'); - prefixCache = {}; - function prefix(prop) { - var i, vendor, capped; - if (!prefixCache[prop]) { - if (testStyle[prop] !== undefined) { - prefixCache[prop] = prop; - } else { - capped = prop.charAt(0).toUpperCase() + prop.substring(1); - i = vendors.length; - while (i--) { - vendor = vendors[i]; - if (testStyle[vendor + capped] !== undefined) { - prefixCache[prop] = vendor + capped; - break; - } - } - } - } - return prefixCache[prop]; - } - function unprefix(prop) { - return prop.replace(unprefixPattern, ''); - } - function hyphenate(str) { - var hyphenated; - if (vendorPattern.test(str)) { - str = '-' + str; - } - hyphenated = str.replace(/[A-Z]/g, function (match) { - return '-' + match.toLowerCase(); - }); - return hyphenated; - } - return Transition; - }(config_isClient, utils_createElement, utils_warn, utils_isNumeric, utils_isArray, utils_camelCase, utils_fillGaps, render_StringFragment__StringFragment); -var render_DomFragment_Element_shared_executeTransition__executeTransition = function (warn, Transition) { - - return function (descriptor, root, owner, contextStack, isIntro) { - var transition, node, oldTransition; - if (!root.transitionsEnabled || root._parent && !root._parent.transitionsEnabled) { - return; - } - transition = new Transition(descriptor, root, owner, contextStack, isIntro); - if (transition._fn) { - node = transition.node; - transition._manager = root._transitionManager; - if (oldTransition = node._ractive.transition) { - oldTransition.complete(); - } - node._ractive.transition = transition; - transition._manager.push(node); - if (isIntro) { - root._deferred.transitions.push(transition); - } else { - transition.init(); - } - } - }; - }(utils_warn, render_DomFragment_Element_shared_executeTransition_Transition); -var render_DomFragment_Element_initialise__initialise = function (types, namespaces, create, defineProperty, matches, warn, createElement, getElementNamespace, createElementAttributes, appendElementChildren, decorate, addEventProxies, updateLiveQueries, executeTransition, enforceCase) { - - return function (element, options, docFrag) { - var parentFragment, pNode, contextStack, descriptor, namespace, name, attributes, width, height, loadHandler, root, selectBinding, errorMessage; - element.type = types.ELEMENT; - parentFragment = element.parentFragment = options.parentFragment; - pNode = parentFragment.pNode; - contextStack = parentFragment.contextStack; - descriptor = element.descriptor = options.descriptor; - element.root = root = parentFragment.root; - element.index = options.index; - element.lcName = descriptor.e.toLowerCase(); - element.eventListeners = []; - element.customEventListeners = []; - if (pNode) { - namespace = element.namespace = getElementNamespace(descriptor, pNode); - name = namespace !== namespaces.html ? enforceCase(descriptor.e) : descriptor.e; - element.node = createElement(name, namespace); - defineProperty(element.node, '_ractive', { - value: { - proxy: element, - keypath: contextStack.length ? contextStack[contextStack.length - 1] : '', - index: parentFragment.indexRefs, - events: create(null), - root: root - } - }); - } - attributes = createElementAttributes(element, descriptor.a); - if (descriptor.f) { - if (element.node && element.node.getAttribute('contenteditable')) { - if (element.node.innerHTML) { - errorMessage = 'A pre-populated contenteditable element should not have children'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - } - } - appendElementChildren(element, element.node, descriptor, docFrag); - } - if (docFrag && descriptor.v) { - addEventProxies(element, descriptor.v); - } - if (docFrag) { - if (root.twoway) { - element.bind(); - if (element.node.getAttribute('contenteditable') && element.node._ractive.binding) { - element.node._ractive.binding.update(); - } - } - if (attributes.name && !attributes.name.twoway) { - attributes.name.update(); - } - if (element.node.tagName === 'IMG' && ((width = element.attributes.width) || (height = element.attributes.height))) { - element.node.addEventListener('load', loadHandler = function () { - if (width) { - element.node.width = width.value; - } - if (height) { - element.node.height = height.value; - } - element.node.removeEventListener('load', loadHandler, false); - }, false); - } - docFrag.appendChild(element.node); - if (descriptor.o) { - decorate(descriptor.o, root, element, contextStack); - } - if (descriptor.t1) { - executeTransition(descriptor.t1, root, element, contextStack, true); - } - if (element.node.tagName === 'OPTION') { - if (pNode.tagName === 'SELECT' && (selectBinding = pNode._ractive.binding)) { - selectBinding.deferUpdate(); - } - if (element.node._ractive.value == pNode._ractive.value) { - element.node.selected = true; - } - } - if (element.node.autofocus) { - root._deferred.focusable = element.node; - } - } - updateLiveQueries(element); - }; - }(config_types, config_namespaces, utils_create, utils_defineProperty, utils_matches, utils_warn, utils_createElement, render_DomFragment_Element_initialise_getElementNamespace, render_DomFragment_Element_initialise_createElementAttributes, render_DomFragment_Element_initialise_appendElementChildren, render_DomFragment_Element_initialise_decorate__decorate, render_DomFragment_Element_initialise_addEventProxies__addEventProxies, render_DomFragment_Element_initialise_updateLiveQueries, render_DomFragment_Element_shared_executeTransition__executeTransition, render_DomFragment_shared_enforceCase); -var render_DomFragment_Element_prototype_teardown = function (executeTransition) { - - return function (destroy) { - var eventName, binding, bindings, i, liveQueries, selector, query, nodesToRemove, j; - if (this.fragment) { - this.fragment.teardown(false); - } - while (this.attributes.length) { - this.attributes.pop().teardown(); - } - if (this.node) { - for (eventName in this.node._ractive.events) { - this.node._ractive.events[eventName].teardown(); - } - if (binding = this.node._ractive.binding) { - binding.teardown(); - bindings = this.root._twowayBindings[binding.attr.keypath]; - bindings.splice(bindings.indexOf(binding), 1); - } - } - if (this.decorator) { - this.decorator.teardown(); - } - if (this.descriptor.t2) { - executeTransition(this.descriptor.t2, this.root, this, this.parentFragment.contextStack, false); - } - if (destroy) { - this.root._transitionManager.detachWhenReady(this); - } - if (liveQueries = this.liveQueries) { - i = liveQueries.length; - while (i--) { - selector = liveQueries[i]; - if (nodesToRemove = this.liveQueries[selector]) { - j = nodesToRemove.length; - query = this.root._liveQueries[selector]; - while (j--) { - query._remove(nodesToRemove[j]); - } - } - } - } - }; - }(render_DomFragment_Element_shared_executeTransition__executeTransition); -var config_voidElementNames = function () { - - return 'area base br col command doctype embed hr img input keygen link meta param source track wbr'.split(' '); - }(); -var render_DomFragment_Element_prototype_toString = function (voidElementNames) { - - return function () { - var str, i, len; - str = '<' + (this.descriptor.y ? '!doctype' : this.descriptor.e); - len = this.attributes.length; - for (i = 0; i < len; i += 1) { - str += ' ' + this.attributes[i].toString(); - } - str += '>'; - if (this.html) { - str += this.html; - } else if (this.fragment) { - str += this.fragment.toString(); - } - if (voidElementNames.indexOf(this.descriptor.e) === -1) { - str += '' + this.descriptor.e + '>'; - } - return str; - }; - }(config_voidElementNames); -var render_DomFragment_Element_prototype_find = function (matches) { - - return function (selector) { - var queryResult; - if (matches(this.node, selector)) { - return this.node; - } - if (this.html && (queryResult = this.node.querySelector(selector))) { - return queryResult; - } - if (this.fragment && this.fragment.find) { - return this.fragment.find(selector); - } - }; - }(utils_matches); -var render_DomFragment_Element_prototype_findAll = function () { - - return function (selector, query) { - var queryAllResult, i, numNodes, node, registeredNodes; - if (query._test(this, true) && query.live) { - (this.liveQueries || (this.liveQueries = [])).push(selector); - this.liveQueries[selector] = [this.node]; - } - if (this.html && (queryAllResult = this.node.querySelectorAll(selector)) && (numNodes = queryAllResult.length)) { - if (query.live) { - if (!this.liveQueries[selector]) { - (this.liveQueries || (this.liveQueries = [])).push(selector); - this.liveQueries[selector] = []; - } - registeredNodes = this.liveQueries[selector]; - } - for (i = 0; i < numNodes; i += 1) { - node = queryAllResult[i]; - query.push(node); - if (query.live) { - registeredNodes.push(node); - } - } - } - if (this.fragment) { - this.fragment.findAll(selector, query); - } - }; - }(); -var render_DomFragment_Element_prototype_findComponent = function () { - - return function (selector) { - if (this.fragment) { - return this.fragment.findComponent(selector); - } - }; - }(); -var render_DomFragment_Element_prototype_findAllComponents = function () { - - return function (selector, query) { - if (this.fragment) { - this.fragment.findAllComponents(selector, query); - } - }; - }(); -var render_DomFragment_Element_prototype_bind = function () { - - return function () { - var attributes = this.attributes; - if (!this.node) { - return; - } - if (this.binding) { - this.binding.teardown(); - this.binding = null; - } - if (this.node.getAttribute('contenteditable') && attributes.value && attributes.value.bind()) { - return; - } - switch (this.descriptor.e) { - case 'select': - case 'textarea': - if (attributes.value) { - attributes.value.bind(); - } - return; - case 'input': - if (this.node.type === 'radio' || this.node.type === 'checkbox') { - if (attributes.name && attributes.name.bind()) { - return; - } - if (attributes.checked && attributes.checked.bind()) { - return; - } - } - if (attributes.value && attributes.value.bind()) { - return; - } - } - }; - }(); -var render_DomFragment_Element__Element = function (initialise, teardown, toString, find, findAll, findComponent, findAllComponents, bind) { - - var DomElement = function (options, docFrag) { - initialise(this, options, docFrag); - }; - DomElement.prototype = { - detach: function () { - if (this.node) { - if (this.node.parentNode) { - this.node.parentNode.removeChild(this.node); - } - return this.node; - } - }, - teardown: teardown, - firstNode: function () { - return this.node; - }, - findNextNode: function () { - return null; - }, - bubble: function () { - }, - toString: toString, - find: find, - findAll: findAll, - findComponent: findComponent, - findAllComponents: findAllComponents, - bind: bind - }; - return DomElement; - }(render_DomFragment_Element_initialise__initialise, render_DomFragment_Element_prototype_teardown, render_DomFragment_Element_prototype_toString, render_DomFragment_Element_prototype_find, render_DomFragment_Element_prototype_findAll, render_DomFragment_Element_prototype_findComponent, render_DomFragment_Element_prototype_findAllComponents, render_DomFragment_Element_prototype_bind); -var config_errors = { missingParser: 'Missing Ractive.parse - cannot parse template. Either preparse or use the version that includes the parser' }; -var registries_partials = {}; -var parse_utils_stripHtmlComments = function () { - - return function (html) { - var commentStart, commentEnd, processed; - processed = ''; - while (html.length) { - commentStart = html.indexOf(''); - if (commentStart === -1 && commentEnd === -1) { - processed += html; - break; - } - if (commentStart !== -1 && commentEnd === -1) { - throw 'Illegal HTML - expected closing comment sequence (\'-->\')'; - } - if (commentEnd !== -1 && commentStart === -1 || commentEnd < commentStart) { - throw 'Illegal HTML - unexpected closing comment sequence (\'-->\')'; - } - processed += html.substr(0, commentStart); - html = html.substring(commentEnd + 3); - } - return processed; - }; - }(); -var parse_utils_stripStandalones = function (types) { - - return function (tokens) { - var i, current, backOne, backTwo, leadingLinebreak, trailingLinebreak; - leadingLinebreak = /^\s*\r?\n/; - trailingLinebreak = /\r?\n\s*$/; - for (i = 2; i < tokens.length; i += 1) { - current = tokens[i]; - backOne = tokens[i - 1]; - backTwo = tokens[i - 2]; - if (current.type === types.TEXT && backOne.type === types.MUSTACHE && backTwo.type === types.TEXT) { - if (trailingLinebreak.test(backTwo.value) && leadingLinebreak.test(current.value)) { - if (backOne.mustacheType !== types.INTERPOLATOR && backOne.mustacheType !== types.TRIPLE) { - backTwo.value = backTwo.value.replace(trailingLinebreak, '\n'); - } - current.value = current.value.replace(leadingLinebreak, ''); - if (current.value === '') { - tokens.splice(i--, 1); - } - } - } - } - return tokens; - }; - }(config_types); -var parse_utils_stripCommentTokens = function (types) { - - return function (tokens) { - var i, current, previous, next; - for (i = 0; i < tokens.length; i += 1) { - current = tokens[i]; - previous = tokens[i - 1]; - next = tokens[i + 1]; - if (current.mustacheType === types.COMMENT || current.mustacheType === types.DELIMCHANGE) { - tokens.splice(i, 1); - if (previous && next) { - if (previous.type === types.TEXT && next.type === types.TEXT) { - previous.value += next.value; - tokens.splice(i, 1); - } - } - i -= 1; - } - } - return tokens; - }; - }(config_types); -var parse_Tokenizer_getMustache_getDelimiterChange = function (makeRegexMatcher) { - - var getDelimiter = makeRegexMatcher(/^[^\s=]+/); - return function (tokenizer) { - var start, opening, closing; - if (!tokenizer.getStringMatch('=')) { - return null; - } - start = tokenizer.pos; - tokenizer.allowWhitespace(); - opening = getDelimiter(tokenizer); - if (!opening) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - closing = getDelimiter(tokenizer); - if (!closing) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch('=')) { - tokenizer.pos = start; - return null; - } - return [ - opening, - closing - ]; - }; - }(parse_Tokenizer_utils_makeRegexMatcher); -var parse_Tokenizer_getMustache_getMustacheType = function (types) { - - var mustacheTypes = { - '#': types.SECTION, - '^': types.INVERTED, - '/': types.CLOSING, - '>': types.PARTIAL, - '!': types.COMMENT, - '&': types.TRIPLE - }; - return function (tokenizer) { - var type = mustacheTypes[tokenizer.str.charAt(tokenizer.pos)]; - if (!type) { - return null; - } - tokenizer.pos += 1; - return type; - }; - }(config_types); -var parse_Tokenizer_getMustache_getMustacheContent = function (types, makeRegexMatcher, getMustacheType) { - - var getIndexRef = makeRegexMatcher(/^\s*:\s*([a-zA-Z_$][a-zA-Z_$0-9]*)/), arrayMember = /^[0-9][1-9]*$/; - return function (tokenizer, isTriple) { - var start, mustache, type, expr, i, remaining, index; - start = tokenizer.pos; - mustache = { type: isTriple ? types.TRIPLE : types.MUSTACHE }; - if (!isTriple) { - if (expr = tokenizer.getExpression()) { - mustache.mustacheType = types.INTERPOLATOR; - tokenizer.allowWhitespace(); - if (tokenizer.getStringMatch(tokenizer.delimiters[1])) { - tokenizer.pos -= tokenizer.delimiters[1].length; - } else { - tokenizer.pos = start; - expr = null; - } - } - if (!expr) { - type = getMustacheType(tokenizer); - if (type === types.TRIPLE) { - mustache = { type: types.TRIPLE }; - } else { - mustache.mustacheType = type || types.INTERPOLATOR; - } - if (type === types.COMMENT || type === types.CLOSING) { - remaining = tokenizer.remaining(); - index = remaining.indexOf(tokenizer.delimiters[1]); - if (index !== -1) { - mustache.ref = remaining.substr(0, index); - tokenizer.pos += index; - return mustache; - } - } - } - } - if (!expr) { - tokenizer.allowWhitespace(); - expr = tokenizer.getExpression(); - } - while (expr.t === types.BRACKETED && expr.x) { - expr = expr.x; - } - if (expr.t === types.REFERENCE) { - mustache.ref = expr.n; - } else if (expr.t === types.NUMBER_LITERAL && arrayMember.test(expr.v)) { - mustache.ref = expr.v; - } else { - mustache.expression = expr; - } - i = getIndexRef(tokenizer); - if (i !== null) { - mustache.indexRef = i; - } - return mustache; - }; - }(config_types, parse_Tokenizer_utils_makeRegexMatcher, parse_Tokenizer_getMustache_getMustacheType); -var parse_Tokenizer_getMustache__getMustache = function (types, getDelimiterChange, getMustacheContent) { - - return function () { - var seekTripleFirst = this.tripleDelimiters[0].length > this.delimiters[0].length; - return getMustache(this, seekTripleFirst) || getMustache(this, !seekTripleFirst); - }; - function getMustache(tokenizer, seekTriple) { - var start = tokenizer.pos, content, delimiters; - delimiters = seekTriple ? tokenizer.tripleDelimiters : tokenizer.delimiters; - if (!tokenizer.getStringMatch(delimiters[0])) { - return null; - } - content = getDelimiterChange(tokenizer); - if (content) { - if (!tokenizer.getStringMatch(delimiters[1])) { - tokenizer.pos = start; - return null; - } - tokenizer[seekTriple ? 'tripleDelimiters' : 'delimiters'] = content; - return { - type: types.MUSTACHE, - mustacheType: types.DELIMCHANGE - }; - } - tokenizer.allowWhitespace(); - content = getMustacheContent(tokenizer, seekTriple); - if (content === null) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(delimiters[1])) { - tokenizer.pos = start; - return null; - } - return content; - } - }(config_types, parse_Tokenizer_getMustache_getDelimiterChange, parse_Tokenizer_getMustache_getMustacheContent); -var parse_Tokenizer_getComment_getComment = function (types) { - - return function () { - var content, remaining, endIndex; - if (!this.getStringMatch(''); - if (endIndex === -1) { - throw new Error('Unexpected end of input (expected "-->" to close comment)'); - } - content = remaining.substr(0, endIndex); - this.pos += endIndex + 3; - return { - type: types.COMMENT, - content: content - }; - }; - }(config_types); -var parse_Tokenizer_utils_getLowestIndex = function () { - - return function (haystack, needles) { - var i, index, lowest; - i = needles.length; - while (i--) { - index = haystack.indexOf(needles[i]); - if (!index) { - return 0; - } - if (index === -1) { - continue; - } - if (!lowest || index < lowest) { - lowest = index; - } - } - return lowest || -1; - }; - }(); -var parse_Tokenizer_getTag__getTag = function (types, makeRegexMatcher, getLowestIndex) { - - var getTag, getOpeningTag, getClosingTag, getTagName, getAttributes, getAttribute, getAttributeName, getAttributeValue, getUnquotedAttributeValue, getUnquotedAttributeValueToken, getUnquotedAttributeValueText, getQuotedStringToken, getQuotedAttributeValue; - getTag = function () { - return getOpeningTag(this) || getClosingTag(this); - }; - getOpeningTag = function (tokenizer) { - var start, tag, attrs, lowerCaseName; - start = tokenizer.pos; - if (tokenizer.inside) { - return null; - } - if (!tokenizer.getStringMatch('<')) { - return null; - } - tag = { type: types.TAG }; - if (tokenizer.getStringMatch('!')) { - tag.doctype = true; - } - tag.name = getTagName(tokenizer); - if (!tag.name) { - tokenizer.pos = start; - return null; - } - attrs = getAttributes(tokenizer); - if (attrs) { - tag.attrs = attrs; - } - tokenizer.allowWhitespace(); - if (tokenizer.getStringMatch('/')) { - tag.selfClosing = true; - } - if (!tokenizer.getStringMatch('>')) { - tokenizer.pos = start; - return null; - } - lowerCaseName = tag.name.toLowerCase(); - if (lowerCaseName === 'script' || lowerCaseName === 'style') { - tokenizer.inside = lowerCaseName; - } - return tag; - }; - getClosingTag = function (tokenizer) { - var start, tag, expected; - start = tokenizer.pos; - expected = function (str) { - throw new Error('Unexpected character ' + tokenizer.remaining().charAt(0) + ' (expected ' + str + ')'); - }; - if (!tokenizer.getStringMatch('<')) { - return null; - } - tag = { - type: types.TAG, - closing: true - }; - if (!tokenizer.getStringMatch('/')) { - expected('"/"'); - } - tag.name = getTagName(tokenizer); - if (!tag.name) { - expected('tag name'); - } - if (!tokenizer.getStringMatch('>')) { - expected('">"'); - } - if (tokenizer.inside) { - if (tag.name.toLowerCase() !== tokenizer.inside) { - tokenizer.pos = start; - return null; - } - tokenizer.inside = null; - } - return tag; - }; - getTagName = makeRegexMatcher(/^[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/); - getAttributes = function (tokenizer) { - var start, attrs, attr; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - attr = getAttribute(tokenizer); - if (!attr) { - tokenizer.pos = start; - return null; - } - attrs = []; - while (attr !== null) { - attrs[attrs.length] = attr; - tokenizer.allowWhitespace(); - attr = getAttribute(tokenizer); - } - return attrs; - }; - getAttribute = function (tokenizer) { - var attr, name, value; - name = getAttributeName(tokenizer); - if (!name) { - return null; - } - attr = { name: name }; - value = getAttributeValue(tokenizer); - if (value) { - attr.value = value; - } - return attr; - }; - getAttributeName = makeRegexMatcher(/^[^\s"'>\/=]+/); - getAttributeValue = function (tokenizer) { - var start, value; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch('=')) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - value = getQuotedAttributeValue(tokenizer, '\'') || getQuotedAttributeValue(tokenizer, '"') || getUnquotedAttributeValue(tokenizer); - if (value === null) { - tokenizer.pos = start; - return null; - } - return value; - }; - getUnquotedAttributeValueText = makeRegexMatcher(/^[^\s"'=<>`]+/); - getUnquotedAttributeValueToken = function (tokenizer) { - var start, text, index; - start = tokenizer.pos; - text = getUnquotedAttributeValueText(tokenizer); - if (!text) { - return null; - } - if ((index = text.indexOf(tokenizer.delimiters[0])) !== -1) { - text = text.substr(0, index); - tokenizer.pos = start + text.length; - } - return { - type: types.TEXT, - value: text - }; - }; - getUnquotedAttributeValue = function (tokenizer) { - var tokens, token; - tokens = []; - token = tokenizer.getMustache() || getUnquotedAttributeValueToken(tokenizer); - while (token !== null) { - tokens[tokens.length] = token; - token = tokenizer.getMustache() || getUnquotedAttributeValueToken(tokenizer); - } - if (!tokens.length) { - return null; - } - return tokens; - }; - getQuotedAttributeValue = function (tokenizer, quoteMark) { - var start, tokens, token; - start = tokenizer.pos; - if (!tokenizer.getStringMatch(quoteMark)) { - return null; - } - tokens = []; - token = tokenizer.getMustache() || getQuotedStringToken(tokenizer, quoteMark); - while (token !== null) { - tokens[tokens.length] = token; - token = tokenizer.getMustache() || getQuotedStringToken(tokenizer, quoteMark); - } - if (!tokenizer.getStringMatch(quoteMark)) { - tokenizer.pos = start; - return null; - } - return tokens; - }; - getQuotedStringToken = function (tokenizer, quoteMark) { - var start, index, remaining; - start = tokenizer.pos; - remaining = tokenizer.remaining(); - index = getLowestIndex(remaining, [ - quoteMark, - tokenizer.delimiters[0], - tokenizer.delimiters[1] - ]); - if (index === -1) { - throw new Error('Quoted attribute value must have a closing quote'); - } - if (!index) { - return null; - } - tokenizer.pos += index; - return { - type: types.TEXT, - value: remaining.substr(0, index) - }; - }; - return getTag; - }(config_types, parse_Tokenizer_utils_makeRegexMatcher, parse_Tokenizer_utils_getLowestIndex); -var parse_Tokenizer_getText__getText = function (types, getLowestIndex) { - - return function () { - var index, remaining, barrier; - remaining = this.remaining(); - barrier = this.inside ? '' + this.inside : '<'; - index = getLowestIndex(remaining, [ - barrier, - this.delimiters[0], - this.tripleDelimiters[0] - ]); - if (!index) { - return null; - } - if (index === -1) { - index = remaining.length; - } - this.pos += index; - return { - type: types.TEXT, - value: remaining.substr(0, index) - }; - }; - }(config_types, parse_Tokenizer_utils_getLowestIndex); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getBooleanLiteral = function (types) { - - return function (tokenizer) { - var remaining = tokenizer.remaining(); - if (remaining.substr(0, 4) === 'true') { - tokenizer.pos += 4; - return { - t: types.BOOLEAN_LITERAL, - v: 'true' - }; - } - if (remaining.substr(0, 5) === 'false') { - tokenizer.pos += 5; - return { - t: types.BOOLEAN_LITERAL, - v: 'false' - }; - } - return null; - }; - }(config_types); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral_getKeyValuePair = function (types, getKey) { - - return function (tokenizer) { - var start, key, value; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - key = getKey(tokenizer); - if (key === null) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(':')) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - value = tokenizer.getExpression(); - if (value === null) { - tokenizer.pos = start; - return null; - } - return { - t: types.KEY_VALUE_PAIR, - k: key, - v: value - }; - }; - }(config_types, parse_Tokenizer_getExpression_shared_getKey); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral_getKeyValuePairs = function (getKeyValuePair) { - - return function getKeyValuePairs(tokenizer) { - var start, pairs, pair, keyValuePairs; - start = tokenizer.pos; - pair = getKeyValuePair(tokenizer); - if (pair === null) { - return null; - } - pairs = [pair]; - if (tokenizer.getStringMatch(',')) { - keyValuePairs = getKeyValuePairs(tokenizer); - if (!keyValuePairs) { - tokenizer.pos = start; - return null; - } - return pairs.concat(keyValuePairs); - } - return pairs; - }; - }(parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral_getKeyValuePair); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral__getObjectLiteral = function (types, getKeyValuePairs) { - - return function (tokenizer) { - var start, keyValuePairs; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch('{')) { - tokenizer.pos = start; - return null; - } - keyValuePairs = getKeyValuePairs(tokenizer); - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch('}')) { - tokenizer.pos = start; - return null; - } - return { - t: types.OBJECT_LITERAL, - m: keyValuePairs - }; - }; - }(config_types, parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral_getKeyValuePairs); -var parse_Tokenizer_getExpression_shared_getExpressionList = function () { - - return function getExpressionList(tokenizer) { - var start, expressions, expr, next; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - expr = tokenizer.getExpression(); - if (expr === null) { - return null; - } - expressions = [expr]; - tokenizer.allowWhitespace(); - if (tokenizer.getStringMatch(',')) { - next = getExpressionList(tokenizer); - if (next === null) { - tokenizer.pos = start; - return null; - } - expressions = expressions.concat(next); - } - return expressions; - }; - }(); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getArrayLiteral = function (types, getExpressionList) { - - return function (tokenizer) { - var start, expressionList; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch('[')) { - tokenizer.pos = start; - return null; - } - expressionList = getExpressionList(tokenizer); - if (!tokenizer.getStringMatch(']')) { - tokenizer.pos = start; - return null; - } - return { - t: types.ARRAY_LITERAL, - m: expressionList - }; - }; - }(config_types, parse_Tokenizer_getExpression_shared_getExpressionList); -var parse_Tokenizer_getExpression_getPrimary_getLiteral__getLiteral = function (getNumberLiteral, getBooleanLiteral, getStringLiteral, getObjectLiteral, getArrayLiteral) { - - return function (tokenizer) { - var literal = getNumberLiteral(tokenizer) || getBooleanLiteral(tokenizer) || getStringLiteral(tokenizer) || getObjectLiteral(tokenizer) || getArrayLiteral(tokenizer); - return literal; - }; - }(parse_Tokenizer_getExpression_getPrimary_getLiteral_getNumberLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getBooleanLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral__getObjectLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getArrayLiteral); -var parse_Tokenizer_getExpression_getPrimary_getReference = function (types, makeRegexMatcher, getName) { - - var getDotRefinement, getArrayRefinement, getArrayMember, globals; - getDotRefinement = makeRegexMatcher(/^\.[a-zA-Z_$0-9]+/); - getArrayRefinement = function (tokenizer) { - var num = getArrayMember(tokenizer); - if (num) { - return '.' + num; - } - return null; - }; - getArrayMember = makeRegexMatcher(/^\[(0|[1-9][0-9]*)\]/); - globals = /^(?:Array|Date|RegExp|decodeURIComponent|decodeURI|encodeURIComponent|encodeURI|isFinite|isNaN|parseFloat|parseInt|JSON|Math|NaN|undefined|null)$/; - return function (tokenizer) { - var startPos, ancestor, name, dot, combo, refinement, lastDotIndex; - startPos = tokenizer.pos; - ancestor = ''; - while (tokenizer.getStringMatch('../')) { - ancestor += '../'; - } - if (!ancestor) { - dot = tokenizer.getStringMatch('.') || ''; - } - name = getName(tokenizer) || ''; - if (!ancestor && !dot && globals.test(name)) { - return { - t: types.GLOBAL, - v: name - }; - } - if (name === 'this' && !ancestor && !dot) { - name = '.'; - startPos += 3; - } - combo = (ancestor || dot) + name; - if (!combo) { - return null; - } - while (refinement = getDotRefinement(tokenizer) || getArrayRefinement(tokenizer)) { - combo += refinement; - } - if (tokenizer.getStringMatch('(')) { - lastDotIndex = combo.lastIndexOf('.'); - if (lastDotIndex !== -1) { - combo = combo.substr(0, lastDotIndex); - tokenizer.pos = startPos + combo.length; - } else { - tokenizer.pos -= 1; - } - } - return { - t: types.REFERENCE, - n: combo - }; - }; - }(config_types, parse_Tokenizer_utils_makeRegexMatcher, parse_Tokenizer_getExpression_shared_getName); -var parse_Tokenizer_getExpression_getPrimary_getBracketedExpression = function (types) { - - return function (tokenizer) { - var start, expr; - start = tokenizer.pos; - if (!tokenizer.getStringMatch('(')) { - return null; - } - tokenizer.allowWhitespace(); - expr = tokenizer.getExpression(); - if (!expr) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(')')) { - tokenizer.pos = start; - return null; - } - return { - t: types.BRACKETED, - x: expr - }; - }; - }(config_types); -var parse_Tokenizer_getExpression_getPrimary__getPrimary = function (getLiteral, getReference, getBracketedExpression) { - - return function (tokenizer) { - return getLiteral(tokenizer) || getReference(tokenizer) || getBracketedExpression(tokenizer); - }; - }(parse_Tokenizer_getExpression_getPrimary_getLiteral__getLiteral, parse_Tokenizer_getExpression_getPrimary_getReference, parse_Tokenizer_getExpression_getPrimary_getBracketedExpression); -var parse_Tokenizer_getExpression_shared_getRefinement = function (types, getName) { - - return function getRefinement(tokenizer) { - var start, name, expr; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - if (tokenizer.getStringMatch('.')) { - tokenizer.allowWhitespace(); - if (name = getName(tokenizer)) { - return { - t: types.REFINEMENT, - n: name - }; - } - tokenizer.expected('a property name'); - } - if (tokenizer.getStringMatch('[')) { - tokenizer.allowWhitespace(); - expr = tokenizer.getExpression(); - if (!expr) { - tokenizer.expected('an expression'); - } - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(']')) { - tokenizer.expected('"]"'); - } - return { - t: types.REFINEMENT, - x: expr - }; - } - return null; - }; - }(config_types, parse_Tokenizer_getExpression_shared_getName); -var parse_Tokenizer_getExpression_getMemberOrInvocation = function (types, getPrimary, getExpressionList, getRefinement) { - - return function (tokenizer) { - var current, expression, refinement, expressionList; - expression = getPrimary(tokenizer); - if (!expression) { - return null; - } - while (expression) { - current = tokenizer.pos; - if (refinement = getRefinement(tokenizer)) { - expression = { - t: types.MEMBER, - x: expression, - r: refinement - }; - } else if (tokenizer.getStringMatch('(')) { - tokenizer.allowWhitespace(); - expressionList = getExpressionList(tokenizer); - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(')')) { - tokenizer.pos = current; - break; - } - expression = { - t: types.INVOCATION, - x: expression - }; - if (expressionList) { - expression.o = expressionList; - } - } else { - break; - } - } - return expression; - }; - }(config_types, parse_Tokenizer_getExpression_getPrimary__getPrimary, parse_Tokenizer_getExpression_shared_getExpressionList, parse_Tokenizer_getExpression_shared_getRefinement); -var parse_Tokenizer_getExpression_getTypeOf = function (types, getMemberOrInvocation) { - - var getTypeOf, makePrefixSequenceMatcher; - makePrefixSequenceMatcher = function (symbol, fallthrough) { - return function (tokenizer) { - var start, expression; - if (!tokenizer.getStringMatch(symbol)) { - return fallthrough(tokenizer); - } - start = tokenizer.pos; - tokenizer.allowWhitespace(); - expression = tokenizer.getExpression(); - if (!expression) { - tokenizer.expected('an expression'); - } - return { - s: symbol, - o: expression, - t: types.PREFIX_OPERATOR - }; - }; - }; - (function () { - var i, len, matcher, prefixOperators, fallthrough; - prefixOperators = '! ~ + - typeof'.split(' '); - fallthrough = getMemberOrInvocation; - for (i = 0, len = prefixOperators.length; i < len; i += 1) { - matcher = makePrefixSequenceMatcher(prefixOperators[i], fallthrough); - fallthrough = matcher; - } - getTypeOf = fallthrough; - }()); - return getTypeOf; - }(config_types, parse_Tokenizer_getExpression_getMemberOrInvocation); -var parse_Tokenizer_getExpression_getLogicalOr = function (types, getTypeOf) { - - var getLogicalOr, makeInfixSequenceMatcher; - makeInfixSequenceMatcher = function (symbol, fallthrough) { - return function (tokenizer) { - var start, left, right; - left = fallthrough(tokenizer); - if (!left) { - return null; - } - start = tokenizer.pos; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(symbol)) { - tokenizer.pos = start; - return left; - } - if (symbol === 'in' && /[a-zA-Z_$0-9]/.test(tokenizer.remaining().charAt(0))) { - tokenizer.pos = start; - return left; - } - tokenizer.allowWhitespace(); - right = tokenizer.getExpression(); - if (!right) { - tokenizer.pos = start; - return left; - } - return { - t: types.INFIX_OPERATOR, - s: symbol, - o: [ - left, - right - ] - }; - }; - }; - (function () { - var i, len, matcher, infixOperators, fallthrough; - infixOperators = '* / % + - << >> >>> < <= > >= in instanceof == != === !== & ^ | && ||'.split(' '); - fallthrough = getTypeOf; - for (i = 0, len = infixOperators.length; i < len; i += 1) { - matcher = makeInfixSequenceMatcher(infixOperators[i], fallthrough); - fallthrough = matcher; - } - getLogicalOr = fallthrough; - }()); - return getLogicalOr; - }(config_types, parse_Tokenizer_getExpression_getTypeOf); -var parse_Tokenizer_getExpression_getConditional = function (types, getLogicalOr) { - - return function (tokenizer) { - var start, expression, ifTrue, ifFalse; - expression = getLogicalOr(tokenizer); - if (!expression) { - return null; - } - start = tokenizer.pos; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch('?')) { - tokenizer.pos = start; - return expression; - } - tokenizer.allowWhitespace(); - ifTrue = tokenizer.getExpression(); - if (!ifTrue) { - tokenizer.pos = start; - return expression; - } - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(':')) { - tokenizer.pos = start; - return expression; - } - tokenizer.allowWhitespace(); - ifFalse = tokenizer.getExpression(); - if (!ifFalse) { - tokenizer.pos = start; - return expression; - } - return { - t: types.CONDITIONAL, - o: [ - expression, - ifTrue, - ifFalse - ] - }; - }; - }(config_types, parse_Tokenizer_getExpression_getLogicalOr); -var parse_Tokenizer_getExpression__getExpression = function (getConditional) { - - return function () { - return getConditional(this); - }; - }(parse_Tokenizer_getExpression_getConditional); -var parse_Tokenizer__Tokenizer = function (getMustache, getComment, getTag, getText, getExpression, allowWhitespace, getStringMatch) { - - var Tokenizer; - Tokenizer = function (str, options) { - var token; - this.str = str; - this.pos = 0; - this.delimiters = options.delimiters; - this.tripleDelimiters = options.tripleDelimiters; - this.tokens = []; - while (this.pos < this.str.length) { - token = this.getToken(); - if (token === null && this.remaining()) { - this.fail(); - } - this.tokens.push(token); - } - }; - Tokenizer.prototype = { - getToken: function () { - var token = this.getMustache() || this.getComment() || this.getTag() || this.getText(); - return token; - }, - getMustache: getMustache, - getComment: getComment, - getTag: getTag, - getText: getText, - getExpression: getExpression, - allowWhitespace: allowWhitespace, - getStringMatch: getStringMatch, - remaining: function () { - return this.str.substring(this.pos); - }, - fail: function () { - var last20, next20; - last20 = this.str.substr(0, this.pos).substr(-20); - if (last20.length === 20) { - last20 = '...' + last20; - } - next20 = this.remaining().substr(0, 20); - if (next20.length === 20) { - next20 = next20 + '...'; - } - throw new Error('Could not parse template: ' + (last20 ? last20 + '<- ' : '') + 'failed at character ' + this.pos + ' ->' + next20); - }, - expected: function (thing) { - var remaining = this.remaining().substr(0, 40); - if (remaining.length === 40) { - remaining += '...'; - } - throw new Error('Tokenizer failed: unexpected string "' + remaining + '" (expected ' + thing + ')'); - } - }; - return Tokenizer; - }(parse_Tokenizer_getMustache__getMustache, parse_Tokenizer_getComment_getComment, parse_Tokenizer_getTag__getTag, parse_Tokenizer_getText__getText, parse_Tokenizer_getExpression__getExpression, parse_Tokenizer_utils_allowWhitespace, parse_Tokenizer_utils_getStringMatch); -var parse_tokenize = function (stripHtmlComments, stripStandalones, stripCommentTokens, Tokenizer, circular) { - - var tokenize, Ractive; - circular.push(function () { - Ractive = circular.Ractive; - }); - tokenize = function (template, options) { - var tokenizer, tokens; - options = options || {}; - if (options.stripComments !== false) { - template = stripHtmlComments(template); - } - tokenizer = new Tokenizer(template, { - delimiters: options.delimiters || (Ractive ? Ractive.delimiters : [ - '{{', - '}}' - ]), - tripleDelimiters: options.tripleDelimiters || (Ractive ? Ractive.tripleDelimiters : [ - '{{{', - '}}}' - ]) - }); - tokens = tokenizer.tokens; - stripStandalones(tokens); - stripCommentTokens(tokens); - return tokens; - }; - return tokenize; - }(parse_utils_stripHtmlComments, parse_utils_stripStandalones, parse_utils_stripCommentTokens, parse_Tokenizer__Tokenizer, circular); -var parse_Parser_getText_TextStub__TextStub = function (types) { - - var TextStub, htmlEntities, controlCharacters, namedEntityPattern, hexEntityPattern, decimalEntityPattern, validateCode, decodeCharacterReferences, whitespace; - TextStub = function (token, preserveWhitespace) { - this.text = preserveWhitespace ? token.value : token.value.replace(whitespace, ' '); - }; - TextStub.prototype = { - type: types.TEXT, - toJSON: function () { - return this.decoded || (this.decoded = decodeCharacterReferences(this.text)); - }, - toString: function () { - return this.text; - } - }; - htmlEntities = { - quot: 34, - amp: 38, - apos: 39, - lt: 60, - gt: 62, - nbsp: 160, - iexcl: 161, - cent: 162, - pound: 163, - curren: 164, - yen: 165, - brvbar: 166, - sect: 167, - uml: 168, - copy: 169, - ordf: 170, - laquo: 171, - not: 172, - shy: 173, - reg: 174, - macr: 175, - deg: 176, - plusmn: 177, - sup2: 178, - sup3: 179, - acute: 180, - micro: 181, - para: 182, - middot: 183, - cedil: 184, - sup1: 185, - ordm: 186, - raquo: 187, - frac14: 188, - frac12: 189, - frac34: 190, - iquest: 191, - Agrave: 192, - Aacute: 193, - Acirc: 194, - Atilde: 195, - Auml: 196, - Aring: 197, - AElig: 198, - Ccedil: 199, - Egrave: 200, - Eacute: 201, - Ecirc: 202, - Euml: 203, - Igrave: 204, - Iacute: 205, - Icirc: 206, - Iuml: 207, - ETH: 208, - Ntilde: 209, - Ograve: 210, - Oacute: 211, - Ocirc: 212, - Otilde: 213, - Ouml: 214, - times: 215, - Oslash: 216, - Ugrave: 217, - Uacute: 218, - Ucirc: 219, - Uuml: 220, - Yacute: 221, - THORN: 222, - szlig: 223, - agrave: 224, - aacute: 225, - acirc: 226, - atilde: 227, - auml: 228, - aring: 229, - aelig: 230, - ccedil: 231, - egrave: 232, - eacute: 233, - ecirc: 234, - euml: 235, - igrave: 236, - iacute: 237, - icirc: 238, - iuml: 239, - eth: 240, - ntilde: 241, - ograve: 242, - oacute: 243, - ocirc: 244, - otilde: 245, - ouml: 246, - divide: 247, - oslash: 248, - ugrave: 249, - uacute: 250, - ucirc: 251, - uuml: 252, - yacute: 253, - thorn: 254, - yuml: 255, - OElig: 338, - oelig: 339, - Scaron: 352, - scaron: 353, - Yuml: 376, - fnof: 402, - circ: 710, - tilde: 732, - Alpha: 913, - Beta: 914, - Gamma: 915, - Delta: 916, - Epsilon: 917, - Zeta: 918, - Eta: 919, - Theta: 920, - Iota: 921, - Kappa: 922, - Lambda: 923, - Mu: 924, - Nu: 925, - Xi: 926, - Omicron: 927, - Pi: 928, - Rho: 929, - Sigma: 931, - Tau: 932, - Upsilon: 933, - Phi: 934, - Chi: 935, - Psi: 936, - Omega: 937, - alpha: 945, - beta: 946, - gamma: 947, - delta: 948, - epsilon: 949, - zeta: 950, - eta: 951, - theta: 952, - iota: 953, - kappa: 954, - lambda: 955, - mu: 956, - nu: 957, - xi: 958, - omicron: 959, - pi: 960, - rho: 961, - sigmaf: 962, - sigma: 963, - tau: 964, - upsilon: 965, - phi: 966, - chi: 967, - psi: 968, - omega: 969, - thetasym: 977, - upsih: 978, - piv: 982, - ensp: 8194, - emsp: 8195, - thinsp: 8201, - zwnj: 8204, - zwj: 8205, - lrm: 8206, - rlm: 8207, - ndash: 8211, - mdash: 8212, - lsquo: 8216, - rsquo: 8217, - sbquo: 8218, - ldquo: 8220, - rdquo: 8221, - bdquo: 8222, - dagger: 8224, - Dagger: 8225, - bull: 8226, - hellip: 8230, - permil: 8240, - prime: 8242, - Prime: 8243, - lsaquo: 8249, - rsaquo: 8250, - oline: 8254, - frasl: 8260, - euro: 8364, - image: 8465, - weierp: 8472, - real: 8476, - trade: 8482, - alefsym: 8501, - larr: 8592, - uarr: 8593, - rarr: 8594, - darr: 8595, - harr: 8596, - crarr: 8629, - lArr: 8656, - uArr: 8657, - rArr: 8658, - dArr: 8659, - hArr: 8660, - forall: 8704, - part: 8706, - exist: 8707, - empty: 8709, - nabla: 8711, - isin: 8712, - notin: 8713, - ni: 8715, - prod: 8719, - sum: 8721, - minus: 8722, - lowast: 8727, - radic: 8730, - prop: 8733, - infin: 8734, - ang: 8736, - and: 8743, - or: 8744, - cap: 8745, - cup: 8746, - 'int': 8747, - there4: 8756, - sim: 8764, - cong: 8773, - asymp: 8776, - ne: 8800, - equiv: 8801, - le: 8804, - ge: 8805, - sub: 8834, - sup: 8835, - nsub: 8836, - sube: 8838, - supe: 8839, - oplus: 8853, - otimes: 8855, - perp: 8869, - sdot: 8901, - lceil: 8968, - rceil: 8969, - lfloor: 8970, - rfloor: 8971, - lang: 9001, - rang: 9002, - loz: 9674, - spades: 9824, - clubs: 9827, - hearts: 9829, - diams: 9830 - }; - controlCharacters = [ - 8364, - 129, - 8218, - 402, - 8222, - 8230, - 8224, - 8225, - 710, - 8240, - 352, - 8249, - 338, - 141, - 381, - 143, - 144, - 8216, - 8217, - 8220, - 8221, - 8226, - 8211, - 8212, - 732, - 8482, - 353, - 8250, - 339, - 157, - 382, - 376 - ]; - namedEntityPattern = new RegExp('&(' + Object.keys(htmlEntities).join('|') + ');?', 'g'); - hexEntityPattern = /([0-9]+);?/g; - decimalEntityPattern = /([0-9]+);?/g; - validateCode = function (code) { - if (!code) { - return 65533; - } - if (code === 10) { - return 32; - } - if (code < 128) { - return code; - } - if (code <= 159) { - return controlCharacters[code - 128]; - } - if (code < 55296) { - return code; - } - if (code <= 57343) { - return 65533; - } - if (code <= 65535) { - return code; - } - return 65533; - }; - decodeCharacterReferences = function (html) { - var result; - result = html.replace(namedEntityPattern, function (match, name) { - if (htmlEntities[name]) { - return String.fromCharCode(htmlEntities[name]); - } - return match; - }); - result = result.replace(hexEntityPattern, function (match, hex) { - return String.fromCharCode(validateCode(parseInt(hex, 16))); - }); - result = result.replace(decimalEntityPattern, function (match, charCode) { - return String.fromCharCode(validateCode(charCode)); - }); - return result; - }; - whitespace = /\s+/g; - return TextStub; - }(config_types); -var parse_Parser_getText__getText = function (types, TextStub) { - - return function (token) { - if (token.type === types.TEXT) { - this.pos += 1; - return new TextStub(token, this.preserveWhitespace); - } - return null; - }; - }(config_types, parse_Parser_getText_TextStub__TextStub); -var parse_Parser_getComment_CommentStub__CommentStub = function (types) { - - var CommentStub; - CommentStub = function (token) { - this.content = token.content; - }; - CommentStub.prototype = { - toJSON: function () { - return { - t: types.COMMENT, - f: this.content - }; - }, - toString: function () { - return ''; - } - }; - return CommentStub; - }(config_types); -var parse_Parser_getComment__getComment = function (types, CommentStub) { - - return function (token) { - if (token.type === types.COMMENT) { - this.pos += 1; - return new CommentStub(token, this.preserveWhitespace); - } - return null; - }; - }(config_types, parse_Parser_getComment_CommentStub__CommentStub); -var parse_Parser_getMustache_ExpressionStub__ExpressionStub = function (types, isObject) { - - var ExpressionStub, getRefs, stringify; - ExpressionStub = function (token) { - this.refs = []; - getRefs(token, this.refs); - this.str = stringify(token, this.refs); - }; - ExpressionStub.prototype = { - toJSON: function () { - if (this.json) { - return this.json; - } - this.json = { - r: this.refs, - s: this.str - }; - return this.json; - } - }; - getRefs = function (token, refs) { - var i, list; - if (token.t === types.REFERENCE) { - if (refs.indexOf(token.n) === -1) { - refs.unshift(token.n); - } - } - list = token.o || token.m; - if (list) { - if (isObject(list)) { - getRefs(list, refs); - } else { - i = list.length; - while (i--) { - getRefs(list[i], refs); - } - } - } - if (token.x) { - getRefs(token.x, refs); - } - if (token.r) { - getRefs(token.r, refs); - } - if (token.v) { - getRefs(token.v, refs); - } - }; - stringify = function (token, refs) { - var map = function (item) { - return stringify(item, refs); - }; - switch (token.t) { - case types.BOOLEAN_LITERAL: - case types.GLOBAL: - case types.NUMBER_LITERAL: - return token.v; - case types.STRING_LITERAL: - return '\'' + token.v.replace(/'/g, '\\\'') + '\''; - case types.ARRAY_LITERAL: - return '[' + (token.m ? token.m.map(map).join(',') : '') + ']'; - case types.OBJECT_LITERAL: - return '{' + (token.m ? token.m.map(map).join(',') : '') + '}'; - case types.KEY_VALUE_PAIR: - return token.k + ':' + stringify(token.v, refs); - case types.PREFIX_OPERATOR: - return (token.s === 'typeof' ? 'typeof ' : token.s) + stringify(token.o, refs); - case types.INFIX_OPERATOR: - return stringify(token.o[0], refs) + (token.s.substr(0, 2) === 'in' ? ' ' + token.s + ' ' : token.s) + stringify(token.o[1], refs); - case types.INVOCATION: - return stringify(token.x, refs) + '(' + (token.o ? token.o.map(map).join(',') : '') + ')'; - case types.BRACKETED: - return '(' + stringify(token.x, refs) + ')'; - case types.MEMBER: - return stringify(token.x, refs) + stringify(token.r, refs); - case types.REFINEMENT: - return token.n ? '.' + token.n : '[' + stringify(token.x, refs) + ']'; - case types.CONDITIONAL: - return stringify(token.o[0], refs) + '?' + stringify(token.o[1], refs) + ':' + stringify(token.o[2], refs); - case types.REFERENCE: - return '${' + refs.indexOf(token.n) + '}'; - default: - throw new Error('Could not stringify expression token. This error is unexpected'); - } - }; - return ExpressionStub; - }(config_types, utils_isObject); -var parse_Parser_getMustache_MustacheStub__MustacheStub = function (types, ExpressionStub) { - - var MustacheStub = function (token, parser) { - this.type = token.type === types.TRIPLE ? types.TRIPLE : token.mustacheType; - if (token.ref) { - this.ref = token.ref; - } - if (token.expression) { - this.expr = new ExpressionStub(token.expression); - } - parser.pos += 1; - }; - MustacheStub.prototype = { - toJSON: function () { - var json; - if (this.json) { - return this.json; - } - json = { t: this.type }; - if (this.ref) { - json.r = this.ref; - } - if (this.expr) { - json.x = this.expr.toJSON(); - } - this.json = json; - return json; - }, - toString: function () { - return false; - } - }; - return MustacheStub; - }(config_types, parse_Parser_getMustache_ExpressionStub__ExpressionStub); -var parse_Parser_utils_stringifyStubs = function () { - - return function (items) { - var str = '', itemStr, i, len; - if (!items) { - return ''; - } - for (i = 0, len = items.length; i < len; i += 1) { - itemStr = items[i].toString(); - if (itemStr === false) { - return false; - } - str += itemStr; - } - return str; - }; - }(); -var parse_Parser_utils_jsonifyStubs = function (stringifyStubs) { - - return function (items, noStringify) { - var str, json; - if (!noStringify) { - str = stringifyStubs(items); - if (str !== false) { - return str; - } - } - json = items.map(function (item) { - return item.toJSON(noStringify); - }); - return json; - }; - }(parse_Parser_utils_stringifyStubs); -var parse_Parser_getMustache_SectionStub__SectionStub = function (types, jsonifyStubs, ExpressionStub) { - - var SectionStub = function (firstToken, parser) { - var next; - this.ref = firstToken.ref; - this.indexRef = firstToken.indexRef; - this.inverted = firstToken.mustacheType === types.INVERTED; - if (firstToken.expression) { - this.expr = new ExpressionStub(firstToken.expression); - } - parser.pos += 1; - this.items = []; - next = parser.next(); - while (next) { - if (next.mustacheType === types.CLOSING) { - if (next.ref.trim() === this.ref || this.expr) { - parser.pos += 1; - break; - } else { - throw new Error('Could not parse template: Illegal closing section'); - } - } - this.items[this.items.length] = parser.getStub(); - next = parser.next(); - } - }; - SectionStub.prototype = { - toJSON: function (noStringify) { - var json; - if (this.json) { - return this.json; - } - json = { t: types.SECTION }; - if (this.ref) { - json.r = this.ref; - } - if (this.indexRef) { - json.i = this.indexRef; - } - if (this.inverted) { - json.n = true; - } - if (this.expr) { - json.x = this.expr.toJSON(); - } - if (this.items.length) { - json.f = jsonifyStubs(this.items, noStringify); - } - this.json = json; - return json; - }, - toString: function () { - return false; - } - }; - return SectionStub; - }(config_types, parse_Parser_utils_jsonifyStubs, parse_Parser_getMustache_ExpressionStub__ExpressionStub); -var parse_Parser_getMustache__getMustache = function (types, MustacheStub, SectionStub) { - - return function (token) { - if (token.type === types.MUSTACHE || token.type === types.TRIPLE) { - if (token.mustacheType === types.SECTION || token.mustacheType === types.INVERTED) { - return new SectionStub(token, this); - } - return new MustacheStub(token, this); - } - }; - }(config_types, parse_Parser_getMustache_MustacheStub__MustacheStub, parse_Parser_getMustache_SectionStub__SectionStub); -var parse_Parser_getElement_ElementStub_utils_siblingsByTagName = function () { - - return { - li: ['li'], - dt: [ - 'dt', - 'dd' - ], - dd: [ - 'dt', - 'dd' - ], - p: 'address article aside blockquote dir div dl fieldset footer form h1 h2 h3 h4 h5 h6 header hgroup hr menu nav ol p pre section table ul'.split(' '), - rt: [ - 'rt', - 'rp' - ], - rp: [ - 'rp', - 'rt' - ], - optgroup: ['optgroup'], - option: [ - 'option', - 'optgroup' - ], - thead: [ - 'tbody', - 'tfoot' - ], - tbody: [ - 'tbody', - 'tfoot' - ], - tr: ['tr'], - td: [ - 'td', - 'th' - ], - th: [ - 'td', - 'th' - ] - }; - }(); -var parse_Parser_getElement_ElementStub_utils_filterAttributes = function (isArray) { - - return function (items) { - var attrs, proxies, filtered, i, len, item; - filtered = {}; - attrs = []; - proxies = []; - len = items.length; - for (i = 0; i < len; i += 1) { - item = items[i]; - if (item.name === 'intro') { - if (filtered.intro) { - throw new Error('An element can only have one intro transition'); - } - filtered.intro = item; - } else if (item.name === 'outro') { - if (filtered.outro) { - throw new Error('An element can only have one outro transition'); - } - filtered.outro = item; - } else if (item.name === 'intro-outro') { - if (filtered.intro || filtered.outro) { - throw new Error('An element can only have one intro and one outro transition'); - } - filtered.intro = item; - filtered.outro = deepClone(item); - } else if (item.name.substr(0, 6) === 'proxy-') { - item.name = item.name.substring(6); - proxies[proxies.length] = item; - } else if (item.name.substr(0, 3) === 'on-') { - item.name = item.name.substring(3); - proxies[proxies.length] = item; - } else if (item.name === 'decorator') { - filtered.decorator = item; - } else { - attrs[attrs.length] = item; - } - } - filtered.attrs = attrs; - filtered.proxies = proxies; - return filtered; - }; - function deepClone(obj) { - var result, key; - if (typeof obj !== 'object') { - return obj; - } - if (isArray(obj)) { - return obj.map(deepClone); - } - result = {}; - for (key in obj) { - if (obj.hasOwnProperty(key)) { - result[key] = deepClone(obj[key]); - } - } - return result; - } - }(utils_isArray); -var parse_Parser_getElement_ElementStub_utils_processDirective = function (types, parseJSON) { - - return function (directive) { - var processed, tokens, token, colonIndex, throwError, directiveName, directiveArgs, parsed; - throwError = function () { - throw new Error('Illegal directive'); - }; - if (!directive.name || !directive.value) { - throwError(); - } - processed = { directiveType: directive.name }; - tokens = directive.value; - directiveName = []; - directiveArgs = []; - while (tokens.length) { - token = tokens.shift(); - if (token.type === types.TEXT) { - colonIndex = token.value.indexOf(':'); - if (colonIndex === -1) { - directiveName[directiveName.length] = token; - } else { - if (colonIndex) { - directiveName[directiveName.length] = { - type: types.TEXT, - value: token.value.substr(0, colonIndex) - }; - } - if (token.value.length > colonIndex + 1) { - directiveArgs[0] = { - type: types.TEXT, - value: token.value.substring(colonIndex + 1) - }; - } - break; - } - } else { - directiveName[directiveName.length] = token; - } - } - directiveArgs = directiveArgs.concat(tokens); - if (directiveName.length === 1 && directiveName[0].type === types.TEXT) { - processed.name = directiveName[0].value; - } else { - processed.name = directiveName; - } - if (directiveArgs.length) { - if (directiveArgs.length === 1 && directiveArgs[0].type === types.TEXT) { - parsed = parseJSON('[' + directiveArgs[0].value + ']'); - processed.args = parsed ? parsed.value : directiveArgs[0].value; - } else { - processed.dynamicArgs = directiveArgs; - } - } - return processed; - }; - }(config_types, utils_parseJSON); -var parse_Parser_StringStub_StringParser = function (getText, getMustache) { - - var StringParser; - StringParser = function (tokens, options) { - var stub; - this.tokens = tokens || []; - this.pos = 0; - this.options = options; - this.result = []; - while (stub = this.getStub()) { - this.result.push(stub); - } - }; - StringParser.prototype = { - getStub: function () { - var token = this.next(); - if (!token) { - return null; - } - return this.getText(token) || this.getMustache(token); - }, - getText: getText, - getMustache: getMustache, - next: function () { - return this.tokens[this.pos]; - } - }; - return StringParser; - }(parse_Parser_getText__getText, parse_Parser_getMustache__getMustache); -var parse_Parser_StringStub__StringStub = function (StringParser, stringifyStubs, jsonifyStubs) { - - var StringStub; - StringStub = function (tokens) { - var parser = new StringParser(tokens); - this.stubs = parser.result; - }; - StringStub.prototype = { - toJSON: function (noStringify) { - var json; - if (this['json_' + noStringify]) { - return this['json_' + noStringify]; - } - json = this['json_' + noStringify] = jsonifyStubs(this.stubs, noStringify); - return json; - }, - toString: function () { - if (this.str !== undefined) { - return this.str; - } - this.str = stringifyStubs(this.stubs); - return this.str; - } - }; - return StringStub; - }(parse_Parser_StringStub_StringParser, parse_Parser_utils_stringifyStubs, parse_Parser_utils_jsonifyStubs); -var parse_Parser_getElement_ElementStub_utils_jsonifyDirective = function (StringStub) { - - return function (directive) { - var result, name; - if (typeof directive.name === 'string') { - if (!directive.args && !directive.dynamicArgs) { - return directive.name; - } - name = directive.name; - } else { - name = new StringStub(directive.name).toJSON(); - } - result = { n: name }; - if (directive.args) { - result.a = directive.args; - return result; - } - if (directive.dynamicArgs) { - result.d = new StringStub(directive.dynamicArgs).toJSON(); - } - return result; - }; - }(parse_Parser_StringStub__StringStub); -var parse_Parser_getElement_ElementStub_toJSON = function (types, jsonifyStubs, jsonifyDirective) { - - return function (noStringify) { - var json, name, value, proxy, i, len, attribute; - if (this['json_' + noStringify]) { - return this['json_' + noStringify]; - } - if (this.component) { - json = { - t: types.COMPONENT, - e: this.component - }; - } else { - json = { - t: types.ELEMENT, - e: this.tag - }; - } - if (this.doctype) { - json.y = 1; - } - if (this.attributes && this.attributes.length) { - json.a = {}; - len = this.attributes.length; - for (i = 0; i < len; i += 1) { - attribute = this.attributes[i]; - name = attribute.name; - if (json.a[name]) { - throw new Error('You cannot have multiple attributes with the same name'); - } - if (attribute.value === null) { - value = null; - } else { - value = attribute.value.toJSON(noStringify); - } - json.a[name] = value; - } - } - if (this.items && this.items.length) { - json.f = jsonifyStubs(this.items, noStringify); - } - if (this.proxies && this.proxies.length) { - json.v = {}; - len = this.proxies.length; - for (i = 0; i < len; i += 1) { - proxy = this.proxies[i]; - json.v[proxy.directiveType] = jsonifyDirective(proxy); - } - } - if (this.intro) { - json.t1 = jsonifyDirective(this.intro); - } - if (this.outro) { - json.t2 = jsonifyDirective(this.outro); - } - if (this.decorator) { - json.o = jsonifyDirective(this.decorator); - } - this['json_' + noStringify] = json; - return json; - }; - }(config_types, parse_Parser_utils_jsonifyStubs, parse_Parser_getElement_ElementStub_utils_jsonifyDirective); -var parse_Parser_getElement_ElementStub_toString = function (stringifyStubs, voidElementNames) { - - var htmlElements; - htmlElements = 'a abbr acronym address applet area b base basefont bdo big blockquote body br button caption center cite code col colgroup dd del dfn dir div dl dt em fieldset font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img input ins isindex kbd label legend li link map menu meta noframes noscript object ol p param pre q s samp script select small span strike strong style sub sup textarea title tt u ul var article aside audio bdi canvas command data datagrid datalist details embed eventsource figcaption figure footer header hgroup keygen mark meter nav output progress ruby rp rt section source summary time track video wbr'.split(' '); - return function () { - var str, i, len, attrStr, name, attrValueStr, fragStr, isVoid; - if (this.str !== undefined) { - return this.str; - } - if (this.component) { - return this.str = false; - } - if (htmlElements.indexOf(this.tag.toLowerCase()) === -1) { - return this.str = false; - } - if (this.proxies || this.intro || this.outro || this.decorator) { - return this.str = false; - } - fragStr = stringifyStubs(this.items); - if (fragStr === false) { - return this.str = false; - } - isVoid = voidElementNames.indexOf(this.tag.toLowerCase()) !== -1; - str = '<' + this.tag; - if (this.attributes) { - for (i = 0, len = this.attributes.length; i < len; i += 1) { - name = this.attributes[i].name; - if (name.indexOf(':') !== -1) { - return this.str = false; - } - if (name === 'id' || name === 'intro' || name === 'outro') { - return this.str = false; - } - attrStr = ' ' + name; - if (this.attributes[i].value !== null) { - attrValueStr = this.attributes[i].value.toString(); - if (attrValueStr === false) { - return this.str = false; - } - if (attrValueStr !== '') { - attrStr += '='; - if (/[\s"'=<>`]/.test(attrValueStr)) { - attrStr += '"' + attrValueStr.replace(/"/g, '"') + '"'; - } else { - attrStr += attrValueStr; - } - } - } - str += attrStr; - } - } - if (this.selfClosing && !isVoid) { - str += '/>'; - return this.str = str; - } - str += '>'; - if (isVoid) { - return this.str = str; - } - str += fragStr; - str += '' + this.tag + '>'; - return this.str = str; - }; - }(parse_Parser_utils_stringifyStubs, config_voidElementNames); -var parse_Parser_getElement_ElementStub__ElementStub = function (types, voidElementNames, warn, camelCase, stringifyStubs, siblingsByTagName, filterAttributes, processDirective, toJSON, toString, StringStub) { - - var ElementStub, allElementNames, closedByParentClose, onPattern, sanitize, leadingWhitespace = /^\s+/, trailingWhitespace = /\s+$/; - ElementStub = function (firstToken, parser, preserveWhitespace) { - var next, attrs, filtered, proxies, item, getFrag, lowerCaseTag; - parser.pos += 1; - getFrag = function (attr) { - return { - name: attr.name, - value: attr.value ? new StringStub(attr.value) : null - }; - }; - this.tag = firstToken.name; - lowerCaseTag = firstToken.name.toLowerCase(); - if (lowerCaseTag.substr(0, 3) === 'rv-') { - warn('The "rv-" prefix for components has been deprecated. Support will be removed in a future version'); - this.tag = this.tag.substring(3); - } - preserveWhitespace = preserveWhitespace || lowerCaseTag === 'pre'; - if (firstToken.attrs) { - filtered = filterAttributes(firstToken.attrs); - attrs = filtered.attrs; - proxies = filtered.proxies; - if (parser.options.sanitize && parser.options.sanitize.eventAttributes) { - attrs = attrs.filter(sanitize); - } - if (attrs.length) { - this.attributes = attrs.map(getFrag); - } - if (proxies.length) { - this.proxies = proxies.map(processDirective); - } - if (filtered.intro) { - this.intro = processDirective(filtered.intro); - } - if (filtered.outro) { - this.outro = processDirective(filtered.outro); - } - if (filtered.decorator) { - this.decorator = processDirective(filtered.decorator); - } - } - if (firstToken.doctype) { - this.doctype = true; - } - if (firstToken.selfClosing) { - this.selfClosing = true; - } - if (voidElementNames.indexOf(lowerCaseTag) !== -1) { - this.isVoid = true; - } - if (this.selfClosing || this.isVoid) { - return; - } - this.siblings = siblingsByTagName[lowerCaseTag]; - this.items = []; - next = parser.next(); - while (next) { - if (next.mustacheType === types.CLOSING) { - break; - } - if (next.type === types.TAG) { - if (next.closing) { - if (next.name.toLowerCase() === lowerCaseTag) { - parser.pos += 1; - } - break; - } else if (this.siblings && this.siblings.indexOf(next.name.toLowerCase()) !== -1) { - break; - } - } - this.items[this.items.length] = parser.getStub(); - next = parser.next(); - } - if (!preserveWhitespace) { - item = this.items[0]; - if (item && item.type === types.TEXT) { - item.text = item.text.replace(leadingWhitespace, ''); - if (!item.text) { - this.items.shift(); - } - } - item = this.items[this.items.length - 1]; - if (item && item.type === types.TEXT) { - item.text = item.text.replace(trailingWhitespace, ''); - if (!item.text) { - this.items.pop(); - } - } - } - }; - ElementStub.prototype = { - toJSON: toJSON, - toString: toString - }; - allElementNames = 'a abbr acronym address applet area b base basefont bdo big blockquote body br button caption center cite code col colgroup dd del dfn dir div dl dt em fieldset font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img input ins isindex kbd label legend li link map menu meta noframes noscript object ol p param pre q s samp script select small span strike strong style sub sup textarea title tt u ul var article aside audio bdi canvas command data datagrid datalist details embed eventsource figcaption figure footer header hgroup keygen mark meter nav output progress ruby rp rt section source summary time track video wbr'.split(' '); - closedByParentClose = 'li dd rt rp optgroup option tbody tfoot tr td th'.split(' '); - onPattern = /^on[a-zA-Z]/; - sanitize = function (attr) { - var valid = !onPattern.test(attr.name); - return valid; - }; - return ElementStub; - }(config_types, config_voidElementNames, utils_warn, utils_camelCase, parse_Parser_utils_stringifyStubs, parse_Parser_getElement_ElementStub_utils_siblingsByTagName, parse_Parser_getElement_ElementStub_utils_filterAttributes, parse_Parser_getElement_ElementStub_utils_processDirective, parse_Parser_getElement_ElementStub_toJSON, parse_Parser_getElement_ElementStub_toString, parse_Parser_StringStub__StringStub); -var parse_Parser_getElement__getElement = function (types, ElementStub) { - - return function (token) { - if (this.options.sanitize && this.options.sanitize.elements) { - if (this.options.sanitize.elements.indexOf(token.name.toLowerCase()) !== -1) { - return null; - } - } - return new ElementStub(token, this); - }; - }(config_types, parse_Parser_getElement_ElementStub__ElementStub); -var parse_Parser__Parser = function (getText, getComment, getMustache, getElement, jsonifyStubs) { - - var Parser; - Parser = function (tokens, options) { - var stub, stubs; - this.tokens = tokens || []; - this.pos = 0; - this.options = options; - this.preserveWhitespace = options.preserveWhitespace; - stubs = []; - while (stub = this.getStub()) { - stubs.push(stub); - } - this.result = jsonifyStubs(stubs); - }; - Parser.prototype = { - getStub: function () { - var token = this.next(); - if (!token) { - return null; - } - return this.getText(token) || this.getComment(token) || this.getMustache(token) || this.getElement(token); - }, - getText: getText, - getComment: getComment, - getMustache: getMustache, - getElement: getElement, - next: function () { - return this.tokens[this.pos]; - } - }; - return Parser; - }(parse_Parser_getText__getText, parse_Parser_getComment__getComment, parse_Parser_getMustache__getMustache, parse_Parser_getElement__getElement, parse_Parser_utils_jsonifyStubs); -var parse__parse = function (tokenize, types, Parser) { - - var parse, onlyWhitespace, inlinePartialStart, inlinePartialEnd, parseCompoundTemplate; - onlyWhitespace = /^\s*$/; - inlinePartialStart = //; - inlinePartialEnd = //; - parse = function (template, options) { - var tokens, json, token; - options = options || {}; - if (inlinePartialStart.test(template)) { - return parseCompoundTemplate(template, options); - } - if (options.sanitize === true) { - options.sanitize = { - elements: 'applet base basefont body frame frameset head html isindex link meta noframes noscript object param script style title'.split(' '), - eventAttributes: true - }; - } - tokens = tokenize(template, options); - if (!options.preserveWhitespace) { - token = tokens[0]; - if (token && token.type === types.TEXT && onlyWhitespace.test(token.value)) { - tokens.shift(); - } - token = tokens[tokens.length - 1]; - if (token && token.type === types.TEXT && onlyWhitespace.test(token.value)) { - tokens.pop(); - } - } - json = new Parser(tokens, options).result; - if (typeof json === 'string') { - return [json]; - } - return json; - }; - parseCompoundTemplate = function (template, options) { - var mainTemplate, remaining, partials, name, startMatch, endMatch; - partials = {}; - mainTemplate = ''; - remaining = template; - while (startMatch = inlinePartialStart.exec(remaining)) { - name = startMatch[1]; - mainTemplate += remaining.substr(0, startMatch.index); - remaining = remaining.substring(startMatch.index + startMatch[0].length); - endMatch = inlinePartialEnd.exec(remaining); - if (!endMatch || endMatch[1] !== name) { - throw new Error('Inline partials must have a closing delimiter, and cannot be nested'); - } - partials[name] = parse(remaining.substr(0, endMatch.index), options); - remaining = remaining.substring(endMatch.index + endMatch[0].length); - } - return { - main: parse(mainTemplate, options), - partials: partials - }; - }; - return parse; - }(parse_tokenize, config_types, parse_Parser__Parser); -var render_DomFragment_Partial_getPartialDescriptor = function (errors, isClient, warn, isObject, partials, parse) { - - var getPartialDescriptor, registerPartial, getPartialFromRegistry, unpack; - getPartialDescriptor = function (root, name) { - var el, partial, errorMessage; - if (partial = getPartialFromRegistry(root, name)) { - return partial; - } - if (isClient) { - el = document.getElementById(name); - if (el && el.tagName === 'SCRIPT') { - if (!parse) { - throw new Error(errors.missingParser); - } - registerPartial(parse(el.innerHTML), name, partials); - } - } - partial = partials[name]; - if (!partial) { - errorMessage = 'Could not find descriptor for partial "' + name + '"'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - return []; - } - return unpack(partial); - }; - getPartialFromRegistry = function (registryOwner, name) { - var partial; - if (registryOwner.partials[name]) { - if (typeof registryOwner.partials[name] === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - partial = parse(registryOwner.partials[name], registryOwner.parseOptions); - registerPartial(partial, name, registryOwner.partials); - } - return unpack(registryOwner.partials[name]); - } - }; - registerPartial = function (partial, name, registry) { - var key; - if (isObject(partial)) { - registry[name] = partial.main; - for (key in partial.partials) { - if (partial.partials.hasOwnProperty(key)) { - registry[key] = partial.partials[key]; - } - } - } else { - registry[name] = partial; - } - }; - unpack = function (partial) { - if (partial.length === 1 && typeof partial[0] === 'string') { - return partial[0]; - } - return partial; - }; - return getPartialDescriptor; - }(config_errors, config_isClient, utils_warn, utils_isObject, registries_partials, parse__parse); -var render_DomFragment_Partial__Partial = function (types, getPartialDescriptor, circular) { - - var DomPartial, DomFragment; - circular.push(function () { - DomFragment = circular.DomFragment; - }); - DomPartial = function (options, docFrag) { - var parentFragment = this.parentFragment = options.parentFragment, descriptor; - this.type = types.PARTIAL; - this.name = options.descriptor.r; - this.index = options.index; - if (!options.descriptor.r) { - throw new Error('Partials must have a static reference (no expressions). This may change in a future version of Ractive.'); - } - descriptor = getPartialDescriptor(parentFragment.root, options.descriptor.r); - this.fragment = new DomFragment({ - descriptor: descriptor, - root: parentFragment.root, - pNode: parentFragment.pNode, - contextStack: parentFragment.contextStack, - owner: this - }); - if (docFrag) { - docFrag.appendChild(this.fragment.docFrag); - } - }; - DomPartial.prototype = { - firstNode: function () { - return this.fragment.firstNode(); - }, - findNextNode: function () { - return this.parentFragment.findNextNode(this); - }, - detach: function () { - return this.fragment.detach(); - }, - teardown: function (destroy) { - this.fragment.teardown(destroy); - }, - toString: function () { - return this.fragment.toString(); - }, - find: function (selector) { - return this.fragment.find(selector); - }, - findAll: function (selector, query) { - return this.fragment.findAll(selector, query); - }, - findComponent: function (selector) { - return this.fragment.findComponent(selector); - }, - findAllComponents: function (selector, query) { - return this.fragment.findAllComponents(selector, query); - } - }; - return DomPartial; - }(config_types, render_DomFragment_Partial_getPartialDescriptor, circular); -var render_DomFragment_Component_initialise_createModel_ComponentParameter = function (StringFragment) { - - var ComponentParameter = function (component, key, value) { - this.parentFragment = component.parentFragment; - this.component = component; - this.key = key; - this.fragment = new StringFragment({ - descriptor: value, - root: component.root, - owner: this, - contextStack: component.parentFragment.contextStack - }); - this.selfUpdating = this.fragment.isSimple(); - this.value = this.fragment.getValue(); - }; - ComponentParameter.prototype = { - bubble: function () { - if (this.selfUpdating) { - this.update(); - } else if (!this.deferred && this.ready) { - this.root._deferred.attrs.push(this); - this.deferred = true; - } - }, - update: function () { - var value = this.fragment.getValue(); - this.component.instance.set(this.key, value); - this.value = value; - }, - teardown: function () { - this.fragment.teardown(); - } - }; - return ComponentParameter; - }(render_StringFragment__StringFragment); -var render_DomFragment_Component_initialise_createModel__createModel = function (types, parseJSON, resolveRef, ComponentParameter) { - - return function (component, attributes, toBind) { - var data, key, value; - data = {}; - component.complexParameters = []; - for (key in attributes) { - if (attributes.hasOwnProperty(key)) { - value = getValue(component, key, attributes[key], toBind); - if (value !== undefined) { - data[key] = value; - } - } - } - return data; - }; - function getValue(component, key, descriptor, toBind) { - var parameter, parsed, root, parentFragment, keypath; - root = component.root; - parentFragment = component.parentFragment; - if (typeof descriptor === 'string') { - parsed = parseJSON(descriptor); - return parsed ? parsed.value : descriptor; - } - if (descriptor === null) { - return true; - } - if (descriptor.length === 1 && descriptor[0].t === types.INTERPOLATOR && descriptor[0].r) { - if (parentFragment.indexRefs && parentFragment.indexRefs[descriptor[0].r] !== undefined) { - return parentFragment.indexRefs[descriptor[0].r]; - } - keypath = resolveRef(root, descriptor[0].r, parentFragment.contextStack) || descriptor[0].r; - toBind.push({ - childKeypath: key, - parentKeypath: keypath - }); - return root.get(keypath); - } - parameter = new ComponentParameter(component, key, descriptor); - component.complexParameters.push(parameter); - return parameter.value; - } - }(config_types, utils_parseJSON, shared_resolveRef, render_DomFragment_Component_initialise_createModel_ComponentParameter); -var render_DomFragment_Component_initialise_createInstance = function () { - - return function (component, Component, data, docFrag, contentDescriptor) { - var instance, parentFragment, partials, root; - parentFragment = component.parentFragment; - root = component.root; - partials = { content: contentDescriptor || [] }; - instance = new Component({ - el: parentFragment.pNode.cloneNode(false), - data: data, - partials: partials, - _parent: root, - adaptors: root.adaptors - }); - instance.component = component; - component.instance = instance; - instance.insert(docFrag); - instance.fragment.pNode = parentFragment.pNode; - return instance; - }; - }(); -var render_DomFragment_Component_initialise_createObservers = function () { - - var observeOptions = { - init: false, - debug: true - }; - return function (component, toBind) { - var pair, i; - component.observers = []; - i = toBind.length; - while (i--) { - pair = toBind[i]; - bind(component, pair.parentKeypath, pair.childKeypath); - } - }; - function bind(component, parentKeypath, childKeypath) { - var parentInstance, childInstance, settingParent, settingChild, observers, observer, value; - parentInstance = component.root; - childInstance = component.instance; - observers = component.observers; - observer = parentInstance.observe(parentKeypath, function (value) { - if (!settingParent && !parentInstance._wrapped[parentKeypath]) { - settingChild = true; - childInstance.set(childKeypath, value); - settingChild = false; - } - }, observeOptions); - observers.push(observer); - if (childInstance.twoway) { - observer = childInstance.observe(childKeypath, function (value) { - if (!settingChild) { - settingParent = true; - parentInstance.set(parentKeypath, value); - settingParent = false; - } - }, observeOptions); - observers.push(observer); - value = childInstance.get(childKeypath); - if (value !== undefined) { - parentInstance.set(parentKeypath, value); - } - } - } - }(); -var render_DomFragment_Component_initialise_propagateEvents = function (warn) { - - var errorMessage = 'Components currently only support simple events - you cannot include arguments. Sorry!'; - return function (component, eventsDescriptor) { - var eventName; - for (eventName in eventsDescriptor) { - if (eventsDescriptor.hasOwnProperty(eventName)) { - propagateEvent(component.instance, component.root, eventName, eventsDescriptor[eventName]); - } - } - }; - function propagateEvent(childInstance, parentInstance, eventName, proxyEventName) { - if (typeof proxyEventName !== 'string') { - if (parentInstance.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - return; - } - } - childInstance.on(eventName, function () { - var args = Array.prototype.slice.call(arguments); - args.unshift(proxyEventName); - parentInstance.fire.apply(parentInstance, args); - }); - } - }(utils_warn); -var render_DomFragment_Component_initialise_updateLiveQueries = function () { - - return function (component) { - var ancestor, query; - ancestor = component.root; - while (ancestor) { - if (query = ancestor._liveComponentQueries[component.name]) { - query.push(component.instance); - } - ancestor = ancestor._parent; - } - }; - }(); -var render_DomFragment_Component_initialise__initialise = function (types, warn, createModel, createInstance, createObservers, propagateEvents, updateLiveQueries) { - - return function (component, options, docFrag) { - var parentFragment, root, Component, data, toBind; - parentFragment = component.parentFragment = options.parentFragment; - root = parentFragment.root; - component.root = root; - component.type = types.COMPONENT; - component.name = options.descriptor.e; - component.index = options.index; - component.observers = []; - Component = root.components[options.descriptor.e]; - if (!Component) { - throw new Error('Component "' + options.descriptor.e + '" not found'); - } - toBind = []; - data = createModel(component, options.descriptor.a, toBind); - createInstance(component, Component, data, docFrag, options.descriptor.f); - createObservers(component, toBind); - propagateEvents(component, options.descriptor.v); - if (options.descriptor.t1 || options.descriptor.t2 || options.descriptor.o) { - warn('The "intro", "outro" and "decorator" directives have no effect on components'); - } - updateLiveQueries(component); - }; - }(config_types, utils_warn, render_DomFragment_Component_initialise_createModel__createModel, render_DomFragment_Component_initialise_createInstance, render_DomFragment_Component_initialise_createObservers, render_DomFragment_Component_initialise_propagateEvents, render_DomFragment_Component_initialise_updateLiveQueries); -var render_DomFragment_Component__Component = function (initialise) { - - var DomComponent = function (options, docFrag) { - initialise(this, options, docFrag); - }; - DomComponent.prototype = { - firstNode: function () { - return this.instance.fragment.firstNode(); - }, - findNextNode: function () { - return this.parentFragment.findNextNode(this); - }, - detach: function () { - return this.instance.fragment.detach(); - }, - teardown: function () { - var query; - while (this.complexParameters.length) { - this.complexParameters.pop().teardown(); - } - while (this.observers.length) { - this.observers.pop().cancel(); - } - if (query = this.root._liveComponentQueries[this.name]) { - query._remove(this); - } - this.instance.teardown(); - }, - toString: function () { - return this.instance.fragment.toString(); - }, - find: function (selector) { - return this.instance.fragment.find(selector); - }, - findAll: function (selector, query) { - return this.instance.fragment.findAll(selector, query); - }, - findComponent: function (selector) { - if (!selector || selector === this.name) { - return this.instance; - } - return null; - }, - findAllComponents: function (selector, query) { - query._test(this, true); - if (this.instance.fragment) { - this.instance.fragment.findAllComponents(selector, query); - } - } - }; - return DomComponent; - }(render_DomFragment_Component_initialise__initialise); -var render_DomFragment_Comment = function (types) { - - var DomComment = function (options, docFrag) { - this.type = types.COMMENT; - this.descriptor = options.descriptor; - if (docFrag) { - this.node = document.createComment(options.descriptor.f); - docFrag.appendChild(this.node); - } - }; - DomComment.prototype = { - detach: function () { - this.node.parentNode.removeChild(this.node); - return this.node; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - } - }, - firstNode: function () { - return this.node; - }, - toString: function () { - return ''; - } - }; - return DomComment; - }(config_types); -var render_DomFragment__DomFragment = function (types, matches, initFragment, insertHtml, Text, Interpolator, Section, Triple, Element, Partial, Component, Comment, circular) { - - var DomFragment = function (options) { - if (options.pNode) { - this.docFrag = document.createDocumentFragment(); - } - if (typeof options.descriptor === 'string') { - this.html = options.descriptor; - if (this.docFrag) { - this.nodes = insertHtml(this.html, options.pNode.tagName, this.docFrag); - } - } else { - initFragment(this, options); - } - }; - DomFragment.prototype = { - detach: function () { - var len, i; - if (this.nodes) { - i = this.nodes.length; - while (i--) { - this.docFrag.appendChild(this.nodes[i]); - } - } else if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - this.docFrag.appendChild(this.items[i].detach()); - } - } - return this.docFrag; - }, - createItem: function (options) { - if (typeof options.descriptor === 'string') { - return new Text(options, this.docFrag); - } - switch (options.descriptor.t) { - case types.INTERPOLATOR: - return new Interpolator(options, this.docFrag); - case types.SECTION: - return new Section(options, this.docFrag); - case types.TRIPLE: - return new Triple(options, this.docFrag); - case types.ELEMENT: - if (this.root.components[options.descriptor.e]) { - return new Component(options, this.docFrag); - } - return new Element(options, this.docFrag); - case types.PARTIAL: - return new Partial(options, this.docFrag); - case types.COMMENT: - return new Comment(options, this.docFrag); - default: - throw new Error('Something very strange happened. Please file an issue at https://github.com/RactiveJS/Ractive/issues. Thanks!'); - } - }, - teardown: function (destroy) { - var node; - if (this.nodes && destroy) { - while (node = this.nodes.pop()) { - node.parentNode.removeChild(node); - } - } else if (this.items) { - while (this.items.length) { - this.items.pop().teardown(destroy); - } - } - this.nodes = this.items = this.docFrag = null; - }, - firstNode: function () { - if (this.items && this.items[0]) { - return this.items[0].firstNode(); - } else if (this.nodes) { - return this.nodes[0] || null; - } - return null; - }, - findNextNode: function (item) { - var index = item.index; - if (this.items[index + 1]) { - return this.items[index + 1].firstNode(); - } - if (this.owner === this.root) { - if (!this.owner.component) { - return null; - } - return this.owner.component.findNextNode(); - } - return this.owner.findNextNode(this); - }, - toString: function () { - var html, i, len, item; - if (this.html) { - return this.html; - } - html = ''; - if (!this.items) { - return html; - } - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - html += item.toString(); - } - return html; - }, - find: function (selector) { - var i, len, item, node, queryResult; - if (this.nodes) { - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - return node; - } - if (queryResult = node.querySelector(selector)) { - return queryResult; - } - } - return null; - } - if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.find && (queryResult = item.find(selector))) { - return queryResult; - } - } - return null; - } - }, - findAll: function (selector, query) { - var i, len, item, node, queryAllResult, numNodes, j; - if (this.nodes) { - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - query.push(node); - } - if (queryAllResult = node.querySelectorAll(selector)) { - numNodes = queryAllResult.length; - for (j = 0; j < numNodes; j += 1) { - query.push(queryAllResult[j]); - } - } - } - } else if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.findAll) { - item.findAll(selector, query); - } - } - } - return query; - }, - findComponent: function (selector) { - var len, i, item, queryResult; - if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.findComponent && (queryResult = item.findComponent(selector))) { - return queryResult; - } - } - return null; - } - }, - findAllComponents: function (selector, query) { - var i, len, item; - if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.findAllComponents) { - item.findAllComponents(selector, query); - } - } - } - return query; - } - }; - circular.DomFragment = DomFragment; - return DomFragment; - }(config_types, utils_matches, render_shared_initFragment, render_DomFragment_shared_insertHtml, render_DomFragment_Text, render_DomFragment_Interpolator, render_DomFragment_Section__Section, render_DomFragment_Triple, render_DomFragment_Element__Element, render_DomFragment_Partial__Partial, render_DomFragment_Component__Component, render_DomFragment_Comment, circular); -var Ractive_prototype_render = function (getElement, makeTransitionManager, preDomUpdate, postDomUpdate, DomFragment) { - - return function (target, complete) { - var transitionManager; - if (!this._initing) { - throw new Error('You cannot call ractive.render() directly!'); - } - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - this.fragment = new DomFragment({ - descriptor: this.template, - root: this, - owner: this, - pNode: target - }); - preDomUpdate(this); - if (target) { - target.appendChild(this.fragment.docFrag); - } - postDomUpdate(this); - this._transitionManager = null; - transitionManager.ready(); - this.rendered = true; - }; - }(utils_getElement, shared_makeTransitionManager, shared_preDomUpdate, shared_postDomUpdate, render_DomFragment__DomFragment); -var Ractive_prototype_renderHTML = function (warn) { - - return function () { - warn('renderHTML() has been deprecated and will be removed in a future version. Please use toHTML() instead'); - return this.toHTML(); - }; - }(utils_warn); -var Ractive_prototype_toHTML = function () { - - return function () { - return this.fragment.toString(); - }; - }(); -var Ractive_prototype_teardown = function (makeTransitionManager, clearCache) { - - return function (complete) { - var keypath, transitionManager, previousTransitionManager; - this.fire('teardown'); - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - this.fragment.teardown(true); - while (this._animations[0]) { - this._animations[0].stop(); - } - for (keypath in this._cache) { - clearCache(this, keypath); - } - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - }; - }(shared_makeTransitionManager, shared_clearCache); -var Ractive_prototype_shared_add = function (isNumeric) { - - return function (root, keypath, d) { - var value; - if (typeof keypath !== 'string' || !isNumeric(d)) { - if (root.debug) { - throw new Error('Bad arguments'); - } - return; - } - value = root.get(keypath); - if (value === undefined) { - value = 0; - } - if (!isNumeric(value)) { - if (root.debug) { - throw new Error('Cannot add to a non-numeric value'); - } - return; - } - root.set(keypath, value + d); - }; - }(utils_isNumeric); -var Ractive_prototype_add = function (add) { - - return function (keypath, d) { - add(this, keypath, d === undefined ? 1 : d); - }; - }(Ractive_prototype_shared_add); -var Ractive_prototype_subtract = function (add) { - - return function (keypath, d) { - add(this, keypath, d === undefined ? -1 : -d); - }; - }(Ractive_prototype_shared_add); -var Ractive_prototype_toggle = function () { - - return function (keypath) { - var value; - if (typeof keypath !== 'string') { - if (this.debug) { - throw new Error('Bad arguments'); - } - return; - } - value = this.get(keypath); - this.set(keypath, !value); - }; - }(); -var Ractive_prototype_merge_mapOldToNewIndex = function () { - - return function (oldArray, newArray) { - var usedIndices, mapper, firstUnusedIndex, newIndices, changed; - usedIndices = {}; - firstUnusedIndex = 0; - mapper = function (item, i) { - var index, start, len; - start = firstUnusedIndex; - len = newArray.length; - do { - index = newArray.indexOf(item, start); - if (index === -1) { - changed = true; - return -1; - } - start = index + 1; - } while (usedIndices[index] && start < len); - if (index === firstUnusedIndex) { - firstUnusedIndex += 1; - } - if (index !== i) { - changed = true; - } - usedIndices[index] = true; - return index; - }; - newIndices = oldArray.map(mapper); - newIndices.unchanged = !changed; - return newIndices; - }; - }(); -var Ractive_prototype_merge_queueDependants = function (types) { - - return function queueDependants(keypath, deps, mergeQueue, updateQueue) { - var i, dependant; - i = deps.length; - while (i--) { - dependant = deps[i]; - if (dependant.type === types.REFERENCE) { - dependant.update(); - } else if (dependant.keypath === keypath && dependant.type === types.SECTION && !dependant.inverted && dependant.docFrag) { - mergeQueue[mergeQueue.length] = dependant; - } else { - updateQueue[updateQueue.length] = dependant; - } - } - }; - }(config_types); -var Ractive_prototype_merge__merge = function (warn, isArray, clearCache, preDomUpdate, processDeferredUpdates, makeTransitionManager, notifyDependants, replaceData, mapOldToNewIndex, queueDependants) { - - var identifiers = {}; - return function (keypath, array, options) { - var currentArray, oldArray, newArray, identifier, lengthUnchanged, i, newIndices, mergeQueue, updateQueue, depsByKeypath, deps, transitionManager, previousTransitionManager, upstreamQueue, keys; - currentArray = this.get(keypath); - if (!isArray(currentArray) || !isArray(array)) { - return this.set(keypath, array, options && options.complete); - } - lengthUnchanged = currentArray.length === array.length; - if (options && options.compare) { - if (options.compare === true) { - identifier = stringify; - } else if (typeof options.compare === 'string') { - identifier = getIdentifier(options.compare); - } else if (typeof options.compare == 'function') { - identifier = options.compare; - } else { - throw new Error('The `compare` option must be a function, or a string representing an identifying field (or `true` to use JSON.stringify)'); - } - try { - oldArray = currentArray.map(identifier); - newArray = array.map(identifier); - } catch (err) { - if (this.debug) { - throw err; - } else { - warn('Merge operation: comparison failed. Falling back to identity checking'); - } - oldArray = currentArray; - newArray = array; - } - } else { - oldArray = currentArray; - newArray = array; - } - newIndices = mapOldToNewIndex(oldArray, newArray); - clearCache(this, keypath); - replaceData(this, keypath, array); - if (newIndices.unchanged && lengthUnchanged) { - return; - } - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, options && options.complete); - mergeQueue = []; - updateQueue = []; - for (i = 0; i < this._deps.length; i += 1) { - depsByKeypath = this._deps[i]; - if (!depsByKeypath) { - continue; - } - deps = depsByKeypath[keypath]; - if (deps) { - queueDependants(keypath, deps, mergeQueue, updateQueue); - preDomUpdate(this); - while (mergeQueue.length) { - mergeQueue.pop().merge(newIndices); - } - while (updateQueue.length) { - updateQueue.pop().update(); - } - } - } - processDeferredUpdates(this); - upstreamQueue = []; - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - upstreamQueue[upstreamQueue.length] = keys.join('.'); - } - notifyDependants.multiple(this, upstreamQueue, true); - if (oldArray.length !== newArray.length) { - notifyDependants(this, keypath + '.length', true); - } - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - }; - function stringify(item) { - return JSON.stringify(item); - } - function getIdentifier(str) { - if (!identifiers[str]) { - identifiers[str] = function (item) { - return item[str]; - }; - } - return identifiers[str]; - } - }(utils_warn, utils_isArray, shared_clearCache, shared_preDomUpdate, shared_processDeferredUpdates, shared_makeTransitionManager, shared_notifyDependants, Ractive_prototype_shared_replaceData, Ractive_prototype_merge_mapOldToNewIndex, Ractive_prototype_merge_queueDependants); -var Ractive_prototype_detach = function () { - - return function () { - return this.fragment.detach(); - }; - }(); -var Ractive_prototype_insert = function (getElement) { - - return function (target, anchor) { - target = getElement(target); - anchor = getElement(anchor) || null; - if (!target) { - throw new Error('You must specify a valid target to insert into'); - } - target.insertBefore(this.detach(), anchor); - this.fragment.pNode = target; - }; - }(utils_getElement); -var Ractive_prototype__prototype = function (get, set, update, updateModel, animate, on, off, observe, fire, find, findAll, findComponent, findAllComponents, render, renderHTML, toHTML, teardown, add, subtract, toggle, merge, detach, insert) { - - return { - get: get, - set: set, - update: update, - updateModel: updateModel, - animate: animate, - on: on, - off: off, - observe: observe, - fire: fire, - find: find, - findAll: findAll, - findComponent: findComponent, - findAllComponents: findAllComponents, - renderHTML: renderHTML, - toHTML: toHTML, - render: render, - teardown: teardown, - add: add, - subtract: subtract, - toggle: toggle, - merge: merge, - detach: detach, - insert: insert - }; - }(Ractive_prototype_get__get, Ractive_prototype_set, Ractive_prototype_update, Ractive_prototype_updateModel, Ractive_prototype_animate__animate, Ractive_prototype_on, Ractive_prototype_off, Ractive_prototype_observe__observe, Ractive_prototype_fire, Ractive_prototype_find, Ractive_prototype_findAll, Ractive_prototype_findComponent, Ractive_prototype_findAllComponents, Ractive_prototype_render, Ractive_prototype_renderHTML, Ractive_prototype_toHTML, Ractive_prototype_teardown, Ractive_prototype_add, Ractive_prototype_subtract, Ractive_prototype_toggle, Ractive_prototype_merge__merge, Ractive_prototype_detach, Ractive_prototype_insert); -var extend_registries = function () { - - return [ - 'partials', - 'transitions', - 'events', - 'components', - 'decorators', - 'data' - ]; - }(); -var extend_initOptions = function () { - - return [ - 'el', - 'template', - 'complete', - 'modifyArrays', - 'magic', - 'twoway', - 'lazy', - 'append', - 'preserveWhitespace', - 'sanitize', - 'stripComments', - 'noIntro', - 'transitionsEnabled', - 'adaptors' - ]; - }(); -var extend_inheritFromParent = function (registries, initOptions, create) { - - return function (Child, Parent) { - registries.forEach(function (property) { - if (Parent[property]) { - Child[property] = create(Parent[property]); - } - }); - initOptions.forEach(function (property) { - Child[property] = Parent[property]; - }); - }; - }(extend_registries, extend_initOptions, utils_create); -var extend_wrapMethod = function () { - - return function (method, superMethod) { - if (/_super/.test(method)) { - return function () { - var _super = this._super, result; - this._super = superMethod; - result = method.apply(this, arguments); - this._super = _super; - return result; - }; - } else { - return method; - } - }; - }(); -var extend_utils_augment = function () { - - return function (target, source) { - var key; - for (key in source) { - if (source.hasOwnProperty(key)) { - target[key] = source[key]; - } - } - return target; - }; - }(); -var extend_inheritFromChildProps = function (registries, initOptions, wrapMethod, augment) { - - var blacklist, blacklisted; - blacklist = registries.concat(initOptions); - blacklisted = {}; - blacklist.forEach(function (property) { - blacklisted[property] = true; - }); - return function (Child, childProps) { - var key, member; - registries.forEach(function (property) { - var value = childProps[property]; - if (value) { - if (Child[property]) { - augment(Child[property], value); - } else { - Child[property] = value; - } - } - }); - initOptions.forEach(function (property) { - var value = childProps[property]; - if (value !== undefined) { - if (typeof value === 'function' && typeof Child[property] === 'function') { - Child[property] = wrapMethod(value, Child[property]); - } else { - Child[property] = childProps[property]; - } - } - }); - for (key in childProps) { - if (childProps.hasOwnProperty(key) && !blacklisted[key]) { - member = childProps[key]; - if (typeof member === 'function' && typeof Child.prototype[key] === 'function') { - Child.prototype[key] = wrapMethod(member, Child.prototype[key]); - } else { - Child.prototype[key] = member; - } - } - } - }; - }(extend_registries, extend_initOptions, extend_wrapMethod, extend_utils_augment); -var extend_extractInlinePartials = function (isObject, augment) { - - return function (Child, childProps) { - if (isObject(Child.template)) { - if (!Child.partials) { - Child.partials = {}; - } - augment(Child.partials, Child.template.partials); - if (childProps.partials) { - augment(Child.partials, childProps.partials); - } - Child.template = Child.template.main; - } - }; - }(utils_isObject, extend_utils_augment); -var extend_conditionallyParseTemplate = function (errors, isClient, parse) { - - return function (Child) { - var templateEl; - if (typeof Child.template === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - if (Child.template.charAt(0) === '#' && isClient) { - templateEl = document.getElementById(Child.template.substring(1)); - if (templateEl && templateEl.tagName === 'SCRIPT') { - Child.template = parse(templateEl.innerHTML, Child); - } else { - throw new Error('Could not find template element (' + Child.template + ')'); - } - } else { - Child.template = parse(Child.template, Child); - } - } - }; - }(config_errors, config_isClient, parse__parse); -var extend_conditionallyParsePartials = function (errors, parse) { - - return function (Child) { - var key; - if (Child.partials) { - for (key in Child.partials) { - if (Child.partials.hasOwnProperty(key) && typeof Child.partials[key] === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - Child.partials[key] = parse(Child.partials[key], Child); - } - } - } - }; - }(config_errors, parse__parse); -var extend_utils_clone = function () { - - return function (source) { - var target = {}, key; - for (key in source) { - if (source.hasOwnProperty(key)) { - target[key] = source[key]; - } - } - return target; - }; - }(); -var utils_extend = function () { - - return function (target) { - var prop, source, sources = Array.prototype.slice.call(arguments, 1); - while (source = sources.shift()) { - for (prop in source) { - if (source.hasOwnProperty(prop)) { - target[prop] = source[prop]; - } - } - } - return target; - }; - }(); -var Ractive_initialise = function (isClient, errors, warn, create, extend, defineProperty, defineProperties, getElement, isObject, magicAdaptor, parse) { - - var getObject, getArray, defaultOptions, registries; - getObject = function () { - return {}; - }; - getArray = function () { - return []; - }; - defaultOptions = create(null); - defineProperties(defaultOptions, { - preserveWhitespace: { - enumerable: true, - value: false - }, - append: { - enumerable: true, - value: false - }, - twoway: { - enumerable: true, - value: true - }, - modifyArrays: { - enumerable: true, - value: true - }, - data: { - enumerable: true, - value: getObject - }, - lazy: { - enumerable: true, - value: false - }, - debug: { - enumerable: true, - value: false - }, - transitions: { - enumerable: true, - value: getObject - }, - decorators: { - enumerable: true, - value: getObject - }, - events: { - enumerable: true, - value: getObject - }, - noIntro: { - enumerable: true, - value: false - }, - transitionsEnabled: { - enumerable: true, - value: true - }, - magic: { - enumerable: true, - value: false - }, - adaptors: { - enumerable: true, - value: getArray - } - }); - registries = [ - 'components', - 'decorators', - 'events', - 'partials', - 'transitions', - 'data' - ]; - return function (ractive, options) { - var key, template, templateEl, parsedTemplate; - for (key in defaultOptions) { - if (options[key] === undefined) { - options[key] = typeof defaultOptions[key] === 'function' ? defaultOptions[key]() : defaultOptions[key]; - } - } - defineProperties(ractive, { - _initing: { - value: true, - writable: true - }, - _guid: { - value: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { - var r, v; - r = Math.random() * 16 | 0; - v = c == 'x' ? r : r & 3 | 8; - return v.toString(16); - }) - }, - _subs: { - value: create(null), - configurable: true - }, - _cache: { value: {} }, - _cacheMap: { value: create(null) }, - _deps: { value: [] }, - _depsMap: { value: create(null) }, - _patternObservers: { value: [] }, - _pendingResolution: { value: [] }, - _deferred: { value: {} }, - _evaluators: { value: create(null) }, - _twowayBindings: { value: {} }, - _transitionManager: { - value: null, - writable: true - }, - _animations: { value: [] }, - nodes: { value: {} }, - _wrapped: { value: create(null) }, - _liveQueries: { value: [] }, - _liveComponentQueries: { value: [] } - }); - defineProperties(ractive._deferred, { - attrs: { value: [] }, - evals: { value: [] }, - selectValues: { value: [] }, - checkboxes: { value: [] }, - radios: { value: [] }, - observers: { value: [] }, - transitions: { value: [] }, - liveQueries: { value: [] }, - decorators: { value: [] }, - focusable: { - value: null, - writable: true - } - }); - ractive.adaptors = options.adaptors; - ractive.modifyArrays = options.modifyArrays; - ractive.magic = options.magic; - ractive.twoway = options.twoway; - ractive.lazy = options.lazy; - ractive.debug = options.debug; - if (ractive.magic && !magicAdaptor) { - throw new Error('Getters and setters (magic mode) are not supported in this browser'); - } - if (options._parent) { - defineProperty(ractive, '_parent', { value: options._parent }); - } - if (options.el) { - ractive.el = getElement(options.el); - if (!ractive.el && ractive.debug) { - throw new Error('Could not find container element'); - } - } - if (options.eventDefinitions) { - warn('ractive.eventDefinitions has been deprecated in favour of ractive.events. Support will be removed in future versions'); - options.events = options.eventDefinitions; - } - registries.forEach(function (registry) { - if (ractive.constructor[registry]) { - ractive[registry] = extend(create(ractive.constructor[registry] || {}), options[registry]); - } else if (options[registry]) { - ractive[registry] = options[registry]; - } - }); - template = options.template; - if (typeof template === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - if (template.charAt(0) === '#' && isClient) { - templateEl = document.getElementById(template.substring(1)); - if (templateEl) { - parsedTemplate = parse(templateEl.innerHTML, options); - } else { - throw new Error('Could not find template element (' + template + ')'); - } - } else { - parsedTemplate = parse(template, options); - } - } else { - parsedTemplate = template; - } - if (isObject(parsedTemplate)) { - extend(ractive.partials, parsedTemplate.partials); - parsedTemplate = parsedTemplate.main; - } - if (parsedTemplate && parsedTemplate.length === 1 && typeof parsedTemplate[0] === 'string') { - parsedTemplate = parsedTemplate[0]; - } - ractive.template = parsedTemplate; - extend(ractive.partials, options.partials); - ractive.parseOptions = { - preserveWhitespace: options.preserveWhitespace, - sanitize: options.sanitize, - stripComments: options.stripComments - }; - ractive.transitionsEnabled = options.noIntro ? false : options.transitionsEnabled; - if (isClient && !ractive.el) { - ractive.el = document.createDocumentFragment(); - } - if (ractive.el && !options.append) { - ractive.el.innerHTML = ''; - } - ractive.render(ractive.el, options.complete); - ractive.transitionsEnabled = options.transitionsEnabled; - ractive._initing = false; - }; - }(config_isClient, config_errors, utils_warn, utils_create, utils_extend, utils_defineProperty, utils_defineProperties, utils_getElement, utils_isObject, Ractive_prototype_get_magicAdaptor, parse__parse); -var extend_initChildInstance = function (fillGaps, initOptions, clone, wrapMethod, initialise) { - - return function (child, Child, options) { - initOptions.forEach(function (property) { - var value = options[property], defaultValue = Child[property]; - if (typeof value === 'function' && typeof defaultValue === 'function') { - options[property] = wrapMethod(value, defaultValue); - } else if (value === undefined && defaultValue !== undefined) { - options[property] = defaultValue; - } - }); - if (child.beforeInit) { - child.beforeInit(options); - } - initialise(child, options); - if (child.init) { - child.init(options); - } - }; - }(utils_fillGaps, extend_initOptions, extend_utils_clone, extend_wrapMethod, Ractive_initialise); -var extend__extend = function (create, inheritFromParent, inheritFromChildProps, extractInlinePartials, conditionallyParseTemplate, conditionallyParsePartials, initChildInstance, circular) { - - var Ractive; - circular.push(function () { - Ractive = circular.Ractive; - }); - return function (childProps) { - var Parent = this, Child; - Child = function (options) { - initChildInstance(this, Child, options || {}); - }; - Child.prototype = create(Parent.prototype); - Child.prototype.constructor = Child; - inheritFromParent(Child, Parent); - inheritFromChildProps(Child, childProps); - conditionallyParseTemplate(Child); - extractInlinePartials(Child, childProps); - conditionallyParsePartials(Child); - Child.extend = Parent.extend; - return Child; - }; - }(utils_create, extend_inheritFromParent, extend_inheritFromChildProps, extend_extractInlinePartials, extend_conditionallyParseTemplate, extend_conditionallyParsePartials, extend_initChildInstance, circular); -var Ractive__Ractive = function (svg, create, defineProperties, prototype, partialRegistry, adaptorRegistry, easingRegistry, Ractive_extend, parse, initialise, circular) { - - var Ractive = function (options) { - initialise(this, options); - }; - defineProperties(Ractive, { - prototype: { value: prototype }, - partials: { value: partialRegistry }, - adaptors: { value: adaptorRegistry }, - easing: { value: easingRegistry }, - transitions: { value: {} }, - events: { value: {} }, - components: { value: {} }, - decorators: { value: {} }, - svg: { value: svg }, - VERSION: { value: '0.3.9' } - }); - Ractive.eventDefinitions = Ractive.events; - Ractive.prototype.constructor = Ractive; - Ractive.delimiters = [ - '{{', - '}}' - ]; - Ractive.tripleDelimiters = [ - '{{{', - '}}}' - ]; - Ractive.extend = Ractive_extend; - Ractive.parse = parse; - circular.Ractive = Ractive; - return Ractive; - }(config_svg, utils_create, utils_defineProperties, Ractive_prototype__prototype, registries_partials, registries_adaptors, registries_easing, extend__extend, parse__parse, Ractive_initialise, circular); -var Ractive = function (Ractive, circular) { - - if (typeof window !== 'undefined' && window.Node && !window.Node.prototype.contains && window.HTMLElement && window.HTMLElement.prototype.contains) { - window.Node.prototype.contains = window.HTMLElement.prototype.contains; - } - while (circular.length) { - circular.pop()(); - } - return Ractive; - }(Ractive__Ractive, circular); -// export as Common JS module... -if ( typeof module !== "undefined" && module.exports ) { - module.exports = Ractive; -} - -// ... or as AMD module -else if ( typeof define === "function" && define.amd ) { - define( function () { - return Ractive; - }); -} - -// ... or as browser global -else { - global.Ractive = Ractive; -} - -}( typeof window !== 'undefined' ? window : this )); \ No newline at end of file diff --git a/build/Ractive-legacy.min.js b/build/Ractive-legacy.min.js deleted file mode 100644 index 21bf494537..0000000000 --- a/build/Ractive-legacy.min.js +++ /dev/null @@ -1,4 +0,0 @@ -!function(a){"use strict";var b=a.document;b&&(Date.now||(Date.now=function(){return+new Date}),String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+/,"").replace(/\s+$/,"")}),Object.keys||(Object.keys=function(){var a=Object.prototype.hasOwnProperty,b=!{toString:null}.propertyIsEnumerable("toString"),c=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],d=c.length;return function(e){if("object"!=typeof e&&"function"!=typeof e||null===e)throw new TypeError("Object.keys called on non-object");var f=[];for(var g in e)a.call(e,g)&&f.push(g);if(b)for(var h=0;d>h;h++)a.call(e,c[h])&&f.push(c[h]);return f}}()),Array.prototype.indexOf||(Array.prototype.indexOf=function(a,b){var c;for(void 0===b&&(b=0),0>b&&(b+=this.length),0>b&&(b=0),c=this.length;c>b;b++)if(this.hasOwnProperty(b)&&this[b]===a)return b;return-1}),Array.prototype.forEach||(Array.prototype.forEach=function(a,b){var c,d;for(c=0,d=this.length;d>c;c+=1)this.hasOwnProperty(c)&&a.call(b,this[c],c,this)}),Array.prototype.map||(Array.prototype.map=function(a,b){var c,d,e=[];for(c=0,d=this.length;d>c;c+=1)this.hasOwnProperty(c)&&(e[c]=a.call(b,this[c],c,this));return e}),Array.prototype.filter||(Array.prototype.filter=function(a,b){var c,d,e=[];for(c=0,d=this.length;d>c;c+=1)this.hasOwnProperty(c)&&a.call(b,this[c],c,this)&&(e[e.length]=this[c]);return e}),a.addEventListener||!function(a,b){var c,d,e,f,g,h;c=function(a,b){var c,d=this;for(c in a)d[c]=a[c];d.currentTarget=b,d.target=a.srcElement||b,d.timeStamp=+new Date,d.preventDefault=function(){a.returnValue=!1},d.stopPropagation=function(){a.cancelBubble=!0}},d=function(a,b){var d,e,f=this;d=f.listeners||(f.listeners=[]),e=d.length,d[e]=[b,function(a){b.call(f,new c(a,f))}],f.attachEvent("on"+a,d[e][1])},e=function(a,b){var c,d,e=this;if(e.listeners)for(c=e.listeners,d=c.length;d--;)c[d][0]===b&&e.detachEvent("on"+a,c[d][1])},a.addEventListener=b.addEventListener=d,a.removeEventListener=b.removeEventListener=e,"Element"in a?(Element.prototype.addEventListener=d,Element.prototype.removeEventListener=e):(h=b.createElement,b.createElement=function(a){var b=h(a);return b.addEventListener=d,b.removeEventListener=e,b},f=b.getElementsByTagName("head")[0],g=b.createElement("style"),f.insertBefore(g,f.firstChild))}(a,b),a.getComputedStyle||(a.getComputedStyle=function(){function a(b,c,d,e){var f,g=c[d],h=parseFloat(g),i=g.split(/\d/)[0];return e=null!=e?e:/%|em/.test(i)&&b.parentElement?a(b.parentElement,b.parentElement.currentStyle,"fontSize",null):16,f="fontSize"==d?e:/width/i.test(d)?b.clientWidth:b.clientHeight,"em"==i?h*e:"in"==i?96*h:"pt"==i?96*h/72:"%"==i?h/100*f:h}function b(a,b){var c="border"==b?"Width":"",d=b+"Top"+c,e=b+"Right"+c,f=b+"Bottom"+c,g=b+"Left"+c;a[b]=(a[d]==a[e]==a[f]==a[g]?[a[d]]:a[d]==a[f]&&a[g]==a[e]?[a[d],a[e]]:a[g]==a[e]?[a[d],a[e],a[f]]:[a[d],a[e],a[f],a[g]]).join(" ")}function c(c){var d,e,f,g;d=c.currentStyle,e=this,f=a(c,d,"fontSize",null);for(g in d)/width|height|margin.|padding.|border.+W/.test(g)&&"auto"!==e[g]?e[g]=a(c,d,g,f)+"px":"styleFloat"===g?e.float=d[g]:e[g]=d[g];return b(e,"margin"),b(e,"padding"),b(e,"border"),e.fontSize=f+"px",e}function d(a){return new c(a)}return c.prototype={constructor:c,getPropertyPriority:function(){},getPropertyValue:function(a){return this[a]||""},item:function(){},removeProperty:function(){},setProperty:function(){},getPropertyCSSValue:function(){}},d}()))}("undefined"!=typeof window?window:this),function(a){var b=function(){return"undefined"!=typeof document?document&&document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure","1.1"):void 0}(),c=function(){var a;try{Object.create(null),a=Object.create}catch(b){a=function(){var a=function(){};return function(b,c){var d;return null===b?{}:(a.prototype=b,d=new a,c&&Object.defineProperties(d,c),d)}}()}return a}(),d={html:"http://www.w3.org/1999/xhtml",mathml:"http://www.w3.org/1998/Math/MathML",svg:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},e=function(a,b){return a?function(a,b){return b?document.createElementNS(b,a):document.createElement(a)}:function(a,c){if(c&&c!==b.html)throw"This browser does not support namespaces other than http://www.w3.org/1999/xhtml. The most likely cause of this error is that you're trying to render SVG in an older browser. See https://github.com/RactiveJS/Ractive/wiki/SVG-and-older-browsers for more information";return document.createElement(a)}}(b,d),f=function(){return"object"==typeof document?!0:!1}(),g=function(a){try{return Object.defineProperty({},"test",{value:0}),a&&Object.defineProperty(document.createElement("div"),"test",{value:0}),Object.defineProperty}catch(b){return function(a,b,c){a[b]=c.value}}}(f),h=function(a,b,c){try{try{Object.defineProperties({},{test:{value:0}})}catch(d){throw d}return c&&Object.defineProperties(a("div"),{test:{value:0}}),Object.defineProperties}catch(d){return function(a,c){var d;for(d in c)c.hasOwnProperty(d)&&b(a,d,c[d])}}}(e,g,f),i=function(){var a=/\[\s*(\*|[0-9]|[1-9][0-9]+)\s*\]/g;return function(b){return(b||"").replace(a,".$1")}}(),j={},k={TEXT:1,INTERPOLATOR:2,TRIPLE:3,SECTION:4,INVERTED:5,CLOSING:6,ELEMENT:7,PARTIAL:8,COMMENT:9,DELIMCHANGE:10,MUSTACHE:11,TAG:12,ATTRIBUTE:13,COMPONENT:15,NUMBER_LITERAL:20,STRING_LITERAL:21,ARRAY_LITERAL:22,OBJECT_LITERAL:23,BOOLEAN_LITERAL:24,GLOBAL:26,KEY_VALUE_PAIR:27,REFERENCE:30,REFINEMENT:31,MEMBER:32,PREFIX_OPERATOR:33,BRACKETED:34,CONDITIONAL:35,INFIX_OPERATOR:36,INVOCATION:40},l=function(){var a=Object.prototype.toString;return function(b){return"[object Array]"===a.call(b)}}(),m=function(){return function a(b,c){var d,e;if((e=b._wrapped[c])&&e.teardown()!==!1&&(b._wrapped[c]=null),b._cache[c]=void 0,d=b._cacheMap[c])for(;d.length;)a(b,d.pop())}}(),n=function(){return function(a,b){var c,d,e,f,g,h;for(c=[],h=a.rendered?a.el:a.fragment.docFrag,d=h.querySelectorAll('input[type="checkbox"][name="{{'+b+'}}"]'),f=d.length,g=0;f>g;g+=1)e=d[g],(e.hasAttribute("checked")||e.checked)&&(c[c.length]=e._ractive.value);return c}}(),o=function(a){return function(b){var c,d,e,f,g,h;for(c=b._deferred;d=c.evals.pop();)d.update().deferred=!1;for(;e=c.selectValues.pop();)e.deferredUpdate();for(;f=c.attrs.pop();)f.update().deferred=!1;for(;g=c.checkboxes.pop();)b.set(g,a(b,g));for(;h=c.radios.pop();)h.update()}}(n),p=function(){return function(a){var b,c,d,e,f,g;for(b=a._deferred,(c=b.focusable)&&(c.focus(),b.focusable=null);d=b.liveQueries.pop();)d._sort();for(;e=b.decorators.pop();)e.init();for(;f=b.transitions.pop();)f.init();for(;g=b.observers.pop();)g.update()}}(),q=function(){var a=function(a,b){var c,d,e,f;return a._parent&&a._parent._transitionManager?a._parent._transitionManager:(d=[],e=function(){var a,b;for(a=d.length;a--;)b=d[a],f(b.node)&&(b.detach(),d.splice(a,1))},f=function(a){var b,d;for(b=c.active.length;b--;)if(d=c.active[b],a.contains(d))return!1;return!0},c={active:[],push:function(a){c.active[c.active.length]=a},pop:function(a){var b;b=c.active.indexOf(a),-1!==b&&(c.active.splice(b,1),e(),!c.active.length&&c._ready&&c.complete())},complete:function(){b&&b.call(a)},ready:function(){e(),c._ready=!0,c.active.length||c.complete()},detachWhenReady:function(a){d[d.length]=a}})};return a}(),r=function(){function a(a,d,e,f){var g=a._deps[e];g&&(b(g[d]),f||c(a._depsMap[d],a,e))}function b(a){var b,c;if(a)for(c=a.length,b=0;c>b;b+=1)a[b].update()}function c(b,c,d,e){var f;if(b)for(f=b.length;f--;)a(c,b[f],d,e)}function d(a,b,c,f,g){var i,j,k,l,m,n,o,p;for(i=a._patternObservers.length;i--;)j=a._patternObservers[i],j.regex.test(c)&&j.update(c);f||(p=function(b){if(k=a._depsMap[b])for(i=k.length;i--;)l=k[i],m=h.exec(l)[0],n=c+"."+m,d(a,l,n)},g?(o=e(c),o.forEach(p)):p(b))}function e(a){var b,c,d,e,g,h;for(b=a.split("."),c=f(b.length),g=[],d=function(a,c){return a?"*":b[c]},e=c.length;e--;)h=c[e].map(d).join("."),g[h]||(g[g.length]=h,g[h]=!0);return g}function f(a){var b,c,d,e,f,g="";if(!i[a]){for(d=[];g.length=f;f+=1){for(c=f.toString(2);c.length2&&f[1])for(q=Math.min(f[1],f.length-2),r=f[0],s=r+q,f[1]===f.length-2&&(u=!0),p=r;s>p;p+=1)t=g+"."+p,h(a,t);for(e(a),m=[],l=g.split(".");l.length;)l.pop(),m[m.length]=l.join(".");h.multiple(a,m,!0),u||h(a,g+".length",!0)},i=function(b,c,d,e){var f,g;for(f=c.length;f--;)g=c[f],g.type===a.REFERENCE?g.update():g.keypath===b&&g.type===a.SECTION&&!g.inverted&&g.docFrag?d[d.length]=g:e[e.length]=g},j=b._ractive.wrappers,l=j.length;l--;)k=j[l],g(k.root,k.keypath)},n=[],p=["pop","push","reverse","shift","sort","splice","unshift"],q=function(){},p.forEach(function(a){var c=function(){var b,c,d,h,i={},k={};for(b=Array.prototype[a].apply(this,arguments),c=this._ractive.instances,h=c.length;h--;)d=c[h],i[d._guid]=d._transitionManager,d._transitionManager=k[d._guid]=g(d,q);for(this._ractive.setting=!0,j(this,a,arguments),this._ractive.setting=!1,h=c.length;h--;)d=c[h],d._transitionManager=i[d._guid],k[d._guid].ready(),e(d),f(d);return b};b(n,a,{value:c})}),o={},o.__proto__?(l=function(a){a.__proto__=n},m=function(a){a.__proto__=Array.prototype}):(l=function(a){var c,d;for(c=p.length;c--;)d=p[c],b(a,d,{value:n[d],configurable:!0})},m=function(a){var b;for(b=p.length;b--;)delete a[p[b]]}),r="Something went wrong in a rather interesting way",i}(k,g,l,m,o,p,q,r),t=function(){var a,b;try{Object.defineProperty({},"test",{value:0})}catch(c){return!1}return a={filter:function(a,b){return!!b},wrap:function(a,c,d){return new b(a,c,d)}},b=function(a,b,c){var d,e,f,g,h,i,j,k,l,m=this;if(this.ractive=a,this.keypath=c,d=c.split("."),this.prop=d.pop(),f=d.join("."),this.obj=f?a.get(f):a.data,g=this.originalDescriptor=Object.getOwnPropertyDescriptor(this.obj,this.prop),g&&g.set&&(h=g.set._ractiveWrappers))return-1===h.indexOf(this)&&h.push(this),void 0;if(g&&!g.configurable)throw new Error('Cannot use magic mode with property "'+e+'" - object is not configurable');g&&(this.value=g.value,i=g.get,j=g.set),k=i||function(){return m.value},l=function(a){var b,c,d;for(j&&j(a),b=l._ractiveWrappers,d=b.length;d--;)c=b[d],c.resetting||c.ractive.set(c.keypath,a)},l._ractiveWrappers=[this],Object.defineProperty(this.obj,this.prop,{get:k,set:l,enumerable:!0,configurable:!0})},b.prototype={get:function(){return this.value},reset:function(a){this.resetting=!0,this.value=a,this.resetting=!1},teardown:function(){var a,b,c,d;a=Object.getOwnPropertyDescriptor(this.obj,this.prop),b=a.set,d=b._ractiveWrappers,d.splice(d.indexOf(this),1),d.length||(c=this.obj[this.prop],Object.defineProperty(this.obj,this.prop,this.originalDescriptor||{writable:!0,enumerable:!0,configrable:!0}),this.obj[this.prop]=c)}},a}(),u=function(a,b,c){function d(a,b){var c,d={};if(!b)return a;b+=".";for(c in a)a.hasOwnProperty(c)&&(d[b+c]=a[c]);return d}function e(a){var b;return f[a]||(b=a?a+".":"",f[a]=function(c,e){var f;return"string"==typeof c?(f={},f[b+c]=e,f):"object"==typeof c?b?d(c,a):c:void 0}),f[a]}var f={};return function(d,f,g,h){var i,j,k,l;for(i=d.adaptors.length,j=0;i>j;j+=1){if(k=d.adaptors[j],"string"==typeof k){if(!a[k])throw new Error('Missing adaptor "'+k+'"');k=d.adaptors[j]=a[k]}if(k.filter(g,f,d))return l=d._wrapped[f]=k.wrap(d,g,f,e(f)),l.value=g,void 0}h||(d.magic&&c.filter(g,f,d)?d._wrapped[f]=c.wrap(d,g,f):d.modifyArrays&&b.filter(g,f,d)&&(d._wrapped[f]=b.wrap(d,g,f)))}}(j,s,t),v=function(a,b,c){var d,e,f;return d=function(a){return this._captured&&!this._captured[a]&&(this._captured.push(a),this._captured[a]=!0),e(this,a)},e=function(b,d){var e,g,h,i,j;return d=a(d),e=b._cache,void 0!==(g=e[d])?g:((i=b._wrapped[d])?h=i.value:d?h=(j=b._evaluators[d])?j.value:f(b,d):(c(b,"",b.data),h=b.data),e[d]=h,h)},f=function(a,b){var d,f,g,h,i,j,k;return d=b.split("."),f=d.pop(),g=d.join("."),h=e(a,g),(k=a._wrapped[g])&&(h=k.get()),null!==h&&void 0!==h?((i=a._cacheMap[g])?-1===i.indexOf(b)&&(i[i.length]=b):a._cacheMap[g]=[b],j=h[f],c(a,b,j),a._cache[b]=j,j):void 0},d}(i,j,u),w=function(){var a=Object.prototype.toString;return function(b){return"object"==typeof b&&"[object Object]"===a.call(b)}}(),x=function(){return function(a,b){return null===a&&null===b?!0:"object"==typeof a||"object"==typeof b?!1:a===b}}(),y=function(){var a;return a=function(a,b,c){var d,e,f,g,h,i,j,k,l,m,n;if(n='Could not resolve reference - too many "../" prefixes',"."===b){if(!c.length)return"";d=c[c.length-1]}else if("."===b.charAt(0))if(m=c[c.length-1],g=m?m.split("."):[],"../"===b.substr(0,3)){for(;"../"===b.substr(0,3);){if(!g.length)throw new Error(n);g.pop(),b=b.substring(3)}g.push(b),d=g.join(".")}else d=m?m+b:b.substring(1);else{for(e=b.split("."),f=e.pop(),i=e.length?"."+e.join("."):"",c=c.concat();c.length;)if(h=c.pop(),j=h+i,k=a.get(j),(l=a._wrapped[j])&&(k=l.get()),"object"==typeof k&&null!==k&&k.hasOwnProperty(f)){d=h+"."+b;break}d||void 0===a.get(b)||(d=b)}return d?d.replace(/^\./,""):d}}(),z=function(a){var b=Array.prototype.push;return function(c){for(var d,e,f;d=c._pendingResolution.pop();)e=a(c,d.ref,d.contextStack),void 0!==e?d.resolve(e):(f||(f=[])).push(d);f&&b.apply(c._pendingResolution,f)}}(y),A=function(a,b){return function(c){a(c),b(c)}}(o,p),B=function(){return function(a,b,c){var d,e,f,g,h,i,j;for(d=b.split("."),e=[],(f=a._wrapped[""])?(f.set&&f.set(d.join("."),c),g=f.get()):g=a.data;d.length>1;)h=e[e.length]=d.shift(),i=e.join("."),(f=a._wrapped[i])?(f.set&&f.set(d.join("."),c),g=f.get()):(g.hasOwnProperty(h)||(j||(j=i),g[h]=/^\s*[0-9]+\s*$/.test(d[0])?[]:{}),g=g[h]);return h=d[0],g[h]=c,j}}(),C=function(a,b,c,d,e,f,g,h,i){var j,k,l,m;return j=function(b,d,i){var j,m,n,o,p,q,r;if(m=[],a(b)&&(j=b,i=d),j)for(b in j)j.hasOwnProperty(b)&&(d=j[b],b=c(b),k(this,b,d,m));else b=c(b),k(this,b,d,m);if(m.length){if(o=this._transitionManager,this._transitionManager=p=g(this,i),n=l(m),n.length&&e.multiple(this,n,!0),e.multiple(this,m),this._pendingResolution.length&&f(this),h(this),this._transitionManager=o,p.ready(),!this.firingChangeEvent){for(this.firingChangeEvent=!0,r={},q=m.length;q--;)r[m[q]]=this.get(m[q]);this.fire("change",r),this.firingChangeEvent=!1}return this}},k=function(a,b,c,e){var f,g,h,j,k;if(!(h=a._wrapped[b])||!h.reset||m(a,b,c,h,e)===!1){if((k=a._evaluators[b])&&(k.value=c),f=a._cache[b],g=a.get(b),g===c||k){if(c===f&&"object"!=typeof c)return}else j=i(a,b,c);d(a,j||b),e[e.length]=b}},l=function(a){var b,c,d,e,f=[""];for(b=a.length;b--;)for(c=a[b],d=c.split(".");d.length>1;)d.pop(),e=d.join("."),f[e]||(f[f.length]=e,f[e]=!0);return f},m=function(a,c,e,f,g){var h,i,j,k;if(h=f.get(),!b(h,e)&&f.reset(e)===!1)return!1;if(e=f.get(),i=a._cache[c],!b(i,e)){if(a._cache[c]=e,j=a._cacheMap[c])for(k=j.length;k--;)d(a,j[k]);g[g.length]=c}},j}(w,x,i,m,r,z,q,A,B),D=function(a,b,c,d,e){return function(f,g){var h,i;return"function"==typeof f&&(g=f,f=""),i=this._transitionManager,this._transitionManager=h=a(this,g),b(this),c(this,f||""),d(this,f||""),e(this),this._transitionManager=i,h.ready(),"string"==typeof f?this.fire("update",f):this.fire("update"),this}}(q,z,m,r,A),E=function(a){return function(b,c){var d;if(!a(b)||!a(c))return!1;if(b.length!==c.length)return!1;for(d=b.length;d--;)if(b[d]!==c[d])return!1;return!0}}(l),F=function(a,b,c){function d(a,e,f,g,h){var i,j,k,l,m,n;if(i=a._twowayBindings[e])for(k=i.length;k--;)l=i[k],(!l.radioName||l.node.checked)&&(l.checkboxName?l.changed()&&!g[e]&&(g[e]=!0,g[g.length]=e):(m=l.attr.value,n=l.value(),b(m,n)||c(m,n)||(f[e]=n)));if(h&&(j=a._depsMap[e]))for(k=j.length;k--;)d(a,j[k],f,g,h)}return function(b,c){var e,f,g;if("string"!=typeof b&&(b="",c=!0),d(this,b,e={},f=[],c),g=f.length)for(;g--;)b=f[g],e[b]=a(this,b);this.set(e)}}(n,E,x),G=function(){return"undefined"!=typeof window?(function(a,b,c){var d,e;if(!c.requestAnimationFrame){for(d=0;d=this.duration?(null!==g&&this.root.set(g,this.to),this.step&&this.step(1,this.to),this.complete&&this.complete(1,this.to),f=this.root._animations.indexOf(this),-1===f&&a("Animation was not found"),this.root._animations.splice(f,1),this.running=!1,!1):(c=this.easing?this.easing(b/this.duration):b/this.duration,null!==g&&(d=this.interpolator(c),this.root.set(g,d)),this.step&&this.step(c,d),!0)):!1},stop:function(){var b;this.running=!1,b=this.root._animations.indexOf(this),-1===b&&a("Animation was not found"),this.root._animations.splice(b,1)}},c}(I,K),M=function(){return{linear:function(a){return a},easeIn:function(a){return Math.pow(a,3)},easeOut:function(a){return Math.pow(a-1,3)+1},easeInOut:function(a){return(a/=.5)<1?.5*Math.pow(a,3):.5*(Math.pow(a-2,3)+2)}}}(),N=function(a,b,c,d){function e(e,g,h,i){var j,k,l,m;return null!==g&&(m=e.get(g)),b.abort(g,e),a(m,h)?(i.complete&&i.complete(1,i.to),f):(i.easing&&(j="function"==typeof i.easing?i.easing:e.easing&&e.easing[i.easing]?e.easing[i.easing]:d[i.easing],"function"!=typeof j&&(j=null)),k=void 0===i.duration?400:i.duration,l=new c({keypath:g,from:m,to:h,root:e,duration:k,easing:j,step:i.step,complete:i.complete}),b.add(l),e._animations[e._animations.length]=l,l)}var f={stop:function(){}};return function(a,b,c){var d,f,g,h,i,j,k,l,m,n,o,p;if("object"==typeof a){c=b||{},h=c.easing,i=c.duration,g=[],j=c.step,k=c.complete,(j||k)&&(m={},c.step=null,c.complete=null,l=function(a){return function(b,c){m[a]=c}});for(d in a)a.hasOwnProperty(d)&&((j||k)&&(n=l(d),c={easing:h,duration:i},j&&(c.step=n),k&&(c.complete=n)),g[g.length]=e(this,d,a[d],c));return(j||k)&&(p={easing:h,duration:i},j&&(p.step=function(a){j(a,m)}),k&&(p.complete=function(a){k(a,m)}),g[g.length]=o=e(this,null,null,p)),{stop:function(){for(;g.length;)g.pop().stop();o&&o.stop()}}}return c=c||{},f=e(this,a,b,c),{stop:function(){f.stop()}}}}(x,H,L,M),O=function(){return function(a,b){var c,d,e=this;if("object"==typeof a){c=[];for(d in a)a.hasOwnProperty(d)&&(c[c.length]=this.on(d,a[d]));return{cancel:function(){for(;c.length;)c.pop().cancel()}}}return this._subs[a]?this._subs[a].push(b):this._subs[a]=[b],{cancel:function(){e.off(a,b)}}}}(),P=function(){return function(a,b){var c,d;if(!b)if(a)this._subs[a]=[];else for(a in this._subs)delete this._subs[a];c=this._subs[a],c&&(d=c.indexOf(b),-1!==d&&c.splice(d,1))}}(),Q=function(){return function(a){var b,c,d,e,f,g,h,i;if(g=a.root,h=a.keypath,i=a.priority,b=g._deps[i]||(g._deps[i]={}),c=b[h]||(b[h]=[]),c[c.length]=a,a.registered=!0,h)for(d=h.split(".");d.length;)d.pop(),e=d.join("."),f=g._depsMap[e]||(g._depsMap[e]=[]),void 0===f[h]&&(f[h]=0,f[f.length]=h),f[h]+=1,h=e}}(),R=function(){return function(a){var b,c,d,e,f,g,h,i;if(g=a.root,h=a.keypath,i=a.priority,b=g._deps[i][h],c=b.indexOf(a),-1===c||!a.registered)throw new Error("Attempted to remove a dependant that was no longer registered! This should not happen. If you are seeing this bug in development please raise an issue at https://github.com/RactiveJS/Ractive/issues - thanks");if(b.splice(c,1),a.registered=!1,h)for(d=h.split(".");d.length;)d.pop(),e=d.join("."),f=g._depsMap[e],f[h]-=1,f[h]||(f.splice(f.indexOf(h),1),f[h]=void 0),h=e}}(),S=function(a){var b=function(a,b,c,d){var e=this;this.root=a,this.keypath=b,this.callback=c,this.defer=d.defer,this.debug=d.debug,this.proxy={update:function(){e.reallyUpdate()}},this.priority=0,this.context=d&&d.context?d.context:a};return b.prototype={init:function(a){a!==!1?this.update():this.value=this.root.get(this.keypath)},update:function(){return this.defer&&this.ready?(this.root._deferred.observers.push(this.proxy),void 0):(this.reallyUpdate(),void 0)},reallyUpdate:function(){var b,c;if(b=this.value,c=this.root.get(this.keypath),this.value=c,!this.updating){if(this.updating=!0,!a(c,b)||!this.ready)try{this.callback.call(this.context,c,b,this.keypath)}catch(d){if(this.debug||this.root.debug)throw d}this.updating=!1}}},b}(x),T=function(){return function(a,b){var c,d,e,f,g,h,i;for(c=b.split("."),f=[],h=function(b){var c,d;c=a._wrapped[b]?a._wrapped[b].get():a.get(b);for(d in c)g.push(b+"."+d)},i=function(a){return a+"."+d};d=c.shift();)"*"===d?(g=[],f.forEach(h),f=g):f[0]?f=f.map(i):f[0]=d;return e={},f.forEach(function(b){e[b]=a.get(b)}),e}}(),U=function(a,b){var c,d=/\*/;return c=function(a,b,c,d){this.root=a,this.callback=c,this.defer=d.defer,this.debug=d.debug,this.keypath=b,this.regex=new RegExp("^"+b.replace(/\./g,"\\.").replace(/\*/g,"[^\\.]+")+"$"),this.values={},this.defer&&(this.proxies=[]),this.priority="pattern",this.context=d&&d.context?d.context:a},c.prototype={init:function(a){var c,d;if(c=b(this.root,this.keypath),a!==!1)for(d in c)c.hasOwnProperty(d)&&this.update(d);else this.values=c},update:function(a){var c;{if(!d.test(a))return this.defer&&this.ready?(this.root._deferred.observers.push(this.getProxy(a)),void 0):(this.reallyUpdate(a),void 0);c=b(this.root,a);for(a in c)c.hasOwnProperty(a)&&this.update(a)}},reallyUpdate:function(b){var c=this.root.get(b);if(this.updating)return this.values[b]=c,void 0;if(this.updating=!0,!a(c,this.values[b])||!this.ready){try{this.callback.call(this.context,c,this.values[b],b)}catch(d){if(this.debug||this.root.debug)throw d}this.values[b]=c}this.updating=!1},getProxy:function(a){var b=this;return this.proxies[a]||(this.proxies[a]={update:function(){b.reallyUpdate(a)}}),this.proxies[a]}},c}(x,T),V=function(a,b,c,d,e){var f=/\*/,g={};return function(h,i,j,k){var l,m;return i=a(i),k=k||g,f.test(i)?(l=new e(h,i,j,k),h._patternObservers.push(l),m=!0):l=new d(h,i,j,k),b(l),l.init(k.init),l.ready=!0,{cancel:function(){var a;m&&(a=h._patternObservers.indexOf(l),-1!==a&&h._patternObservers.splice(a,1)),c(l)}}}}(i,Q,R,S,U),W=function(a,b){return function(c,d,e){var f,g=[];if(a(c)){e=d;for(f in c)c.hasOwnProperty(f)&&(d=c[f],g[g.length]=b(this,f,d,e));return{cancel:function(){for(;g.length;)g.pop().cancel()}}}return b(this,c,d,e)}}(w,V),X=function(){return function(a){var b,c,d,e=this._subs[a];if(e)for(b=Array.prototype.slice.call(arguments,1),c=0,d=e.length;d>c;c+=1)e[c].apply(this,b)}}(),Y=function(){return function(a){return this.el?this.fragment.find(a):null}}(),Z=function(a,b){var c,d,e,f,g,h,i,j;if(a){for(c=b("div"),d=["matches","matchesSelector"],g=["o","ms","moz","webkit"],j=function(a){return function(b,c){return b[a](c)}},h=d.length;h--;){if(e=d[h],c[e])return j(e);for(i=g.length;i--;)if(f=g[h]+e.substr(0,1).toUpperCase()+e.substring(1),c[f])return j(f)}return function(a,b){var c,d;for(c=(a.parentNode||a.document).querySelectorAll(b),d=c.length;d--;)if(c[d]===a)return!0;return!1}}}(f,e),$=function(a){return function(b,c){var d=this._isComponentQuery?!this.selector||b.name===this.selector:a(b.node,this.selector);return d?(this.push(b.node||b.instance),c||this._makeDirty(),!0):void 0}}(Z),_=function(){return function(){var a,b,c;a=this._root[this._isComponentQuery?"liveComponentQueries":"liveQueries"],b=this.selector,c=a.indexOf(b),-1!==c&&(a.splice(c,1),a[b]=null)}}(),ab=function(){function a(a){var b;return(b=a.parentFragment)?b.owner:a.component&&(b=a.component.parentFragment)?b.owner:void 0}function b(b){var c,d;for(c=[b],d=a(b);d;)c.push(d),d=a(d);return c}return function(a,c){var d,e,f,g,h,i,j,k,l,m;for(d=b(a.component||a._ractive.proxy),e=b(c.component||c._ractive.proxy),f=d[d.length-1],g=e[e.length-1];f&&f===g;)d.pop(),e.pop(),h=f,f=d[d.length-1],g=e[e.length-1];if(f=f.component||f,g=g.component||g,l=f.parentFragment,m=g.parentFragment,l===m)return i=l.items.indexOf(f),j=m.items.indexOf(g),i-j||d.length-e.length;if(k=h.fragments)return i=k.indexOf(l),j=k.indexOf(m),i-j||d.length-e.length;throw new Error("An unexpected condition was met while comparing the position of two components. Please file an issue at https://github.com/RactiveJS/Ractive/issues - thanks!")}}(),bb=function(a){return function(b,c){var d;return b.compareDocumentPosition?(d=b.compareDocumentPosition(c),2&d?1:-1):a(b,c)}}(ab),cb=function(a,b){return function(){this.sort(this._isComponentQuery?b:a),this._dirty=!1}}(bb,ab),db=function(){return function(){this._dirty||(this._root._deferred.liveQueries.push(this),this._dirty=!0)}}(),eb=function(){return function(a){var b=this.indexOf(this._isComponentQuery?a.instance:a.node);-1!==b&&this.splice(b,1)}}(),fb=function(a,b,c,d,e,f){return function(g,h,i,j){var k;return k=[],a(k,{selector:{value:h},live:{value:i},_isComponentQuery:{value:j},_test:{value:b}}),i?(a(k,{cancel:{value:c},_root:{value:g},_sort:{value:d},_makeDirty:{value:e},_remove:{value:f},_dirty:{value:!1,writable:!0}}),k):k}}(h,$,_,cb,db,eb),gb=function(a,b,c,d){return function(a,b){var c,e;return this.el?(b=b||{},c=this._liveQueries,(e=c[a])?b&&b.live?e:e.slice():(e=d(this,a,!!b.live,!1),e.live&&(c.push(a),c[a]=e),this.fragment.findAll(a,e),e)):[]}}(I,Z,h,fb),hb=function(){return function(a){return this.fragment.findComponent(a)}}(),ib=function(a,b,c,d){return function(a,b){var c,e;return b=b||{},c=this._liveComponentQueries,(e=c[a])?b&&b.live?e:e.slice():(e=d(this,a,!!b.live,!0),e.live&&(c.push(a),c[a]=e),this.fragment.findAllComponents(a,e),e)}}(I,Z,h,fb),jb=function(){return function(a){var b;return"undefined"!=typeof window&&document&&a?a.nodeType?a:"string"==typeof a&&(b=document.getElementById(a),!b&&document.querySelector&&(b=document.querySelector(a)),b&&b.nodeType)?b:a[0]&&a[0].nodeType?a[0]:null:null}}(),kb=function(a,b){return function(c,d){var e,f,g,h,i;if(c.owner=d.owner,g=c.owner.parentFragment,c.root=d.root,c.pNode=d.pNode,c.contextStack=d.contextStack||[],c.owner.type===a.SECTION&&(c.index=d.index),g&&(h=g.indexRefs)){c.indexRefs=b(null);for(i in h)c.indexRefs[i]=h[i]}for(c.priority=g?g.priority+1:1,d.indexRef&&(c.indexRefs||(c.indexRefs={}),c.indexRefs[d.indexRef]=d.index),c.items=[],e=d.descriptor?d.descriptor.length:0,f=0;e>f;f+=1)c.items[c.items.length]=c.createItem({parentFragment:c,descriptor:d.descriptor[f],index:f})}}(k,c),lb=function(a){var b={};return function(c,d,e){var f,g=[];if(c)for(f=b[d]||(b[d]=a(d)),f.innerHTML=c;f.firstChild;)g[g.length]=f.firstChild,e.appendChild(f.firstChild);return g}}(e),mb=function(a){var b,c,d;return c=//g,b=function(b,c){this.type=a.TEXT,this.descriptor=b.descriptor,c&&(this.node=document.createTextNode(b.descriptor),c.appendChild(this.node))},b.prototype={detach:function(){return this.node.parentNode.removeChild(this.node),this.node},teardown:function(a){a&&this.detach()},firstNode:function(){return this.node},toString:function(){return(""+this.descriptor).replace(c,"<").replace(d,">")}},b}(k),nb=function(a){return function(b){if(b.keypath)a(b);else{var c=b.root._pendingResolution.indexOf(b);-1!==c&&b.root._pendingResolution.splice(c,1)}}}(R),ob=function(a,b,c,d,e){function f(a,b,d){var e,f,g;if(!h.test(a.toString()))return c(a,"_nowrap",{value:!0}),a;if(!a["_"+b._guid]){c(a,"_"+b._guid,{value:function(){var c,d,e,g;if(c=b._captured,c||(b._captured=[]),d=a.apply(b,arguments),b._captured.length)for(e=f.length;e--;)g=f[e],g.updateSoftDependencies(b._captured);return b._captured=c,d},writable:!0});for(e in a)a.hasOwnProperty(e)&&(a["_"+b._guid][e]=a[e]);a["_"+b._guid+"_evaluators"]=[]}return f=a["_"+b._guid+"_evaluators"],g=f.indexOf(d),-1===g&&f.push(d),a["_"+b._guid]}var g,h;return h=/this/,g=function(b,c,e,g,h){var i;this.evaluator=e,this.keypath=c,this.root=b,this.argNum=g,this.type=a.REFERENCE,this.priority=h,i=b.get(c),"function"==typeof i&&(i=f(i,b,e)),this.value=e.values[g]=i,d(this)},g.prototype={update:function(){var a=this.root.get(this.keypath);"function"!=typeof a||a._nowrap||(a=f(a,this.root,this.evaluator)),b(a,this.value)||(this.evaluator.values[this.argNum]=a,this.evaluator.bubble(),this.value=a)},teardown:function(){e(this)}},g}(k,x,g,Q,R),pb=function(a,b,c){var d=function(a,c,d){this.root=a,this.keypath=c,this.priority=d.priority,this.evaluator=d,b(this)};return d.prototype={update:function(){var b=this.root.get(this.keypath);a(b,this.value)||(this.evaluator.bubble(),this.value=b)},teardown:function(){c(this)}},d}(x,Q,R),qb=function(a,b,c,d,e,f,g,h,i){function j(a,b){var c,d;if(a=a.replace(/\$\{([0-9]+)\}/g,"_$1"),l[a])return l[a];for(d=[];b--;)d[b]="_"+b;return c=new Function(d.join(","),"return("+a+")"),l[a]=c,c}var k,l={};return k=function(a,b,c,d,e){var f,g;for(this.root=a,this.keypath=b,this.priority=e,this.fn=j(c,d.length),this.values=[],this.refs=[],f=d.length;f--;)(g=d[f])?g[0]?this.values[f]=g[1]:this.refs[this.refs.length]=new h(a,g[1],this,f,e):this.values[f]=void 0;this.selfUpdating=this.refs.length<=1,this.update()},k.prototype={bubble:function(){this.selfUpdating?this.update():this.deferred||(this.root._deferred.evals.push(this),this.deferred=!0) -},update:function(){var b;if(this.evaluating)return this;this.evaluating=!0;try{b=this.fn.apply(null,this.values)}catch(e){if(this.root.debug)throw e;b=void 0}return a(b,this.value)||(c(this.root,this.keypath),this.root._cache[this.keypath]=b,g(this.root,this.keypath,b,!0),this.value=b,d(this.root,this.keypath)),this.evaluating=!1,this},teardown:function(){for(;this.refs.length;)this.refs.pop().teardown();c(this.root,this.keypath),this.root._evaluators[this.keypath]=null},refresh:function(){this.selfUpdating||(this.deferred=!0);for(var a=this.refs.length;a--;)this.refs[a].update();this.deferred&&(this.update(),this.deferred=!1)},updateSoftDependencies:function(a){var b,c,d;for(this.softRefs||(this.softRefs=[]),b=this.softRefs.length;b--;)d=this.softRefs[b],a[d.keypath]||(this.softRefs.splice(b,1),this.softRefs[d.keypath]=!1,d.teardown());for(b=a.length;b--;)c=a[b],this.softRefs[c]||(d=new i(this.root,c,this),this.softRefs[this.softRefs.length]=d,this.softRefs[c]=!0);this.selfUpdating=this.refs.length+this.softRefs.length<=1}},k}(x,g,m,r,Q,R,u,ob,pb),rb=function(a,b){var c=function(b,c,d,e){var f,g;g=this.root=b.root,f=a(g,c,d),void 0!==f?b.resolveRef(e,!1,f):(this.ref=c,this.argNum=e,this.resolver=b,this.contextStack=d,g._pendingResolution[g._pendingResolution.length]=this)};return c.prototype={resolve:function(a){this.keypath=a,this.resolver.resolveRef(this.argNum,!1,a)},teardown:function(){this.keypath||b(this)}},c}(y,nb),sb=function(){var a=/^(?:(?:[a-zA-Z$_][a-zA-Z$_0-9]*)|(?:[0-9]|[1-9][0-9]+))$/;return function(b){var c,d,e;for(c=b.split("."),e=c.length;e--;)if(d=c[e],"undefined"===d||!a.test(d))return!1;return!0}}(),tb=function(a,b){return function(c,d){var e,f;return e=c.replace(/\$\{([0-9]+)\}/g,function(a,b){return d[b]?d[b][1]:"undefined"}),f=a(e),b(f)?f:"${"+e.replace(/[\.\[\]]/g,"-")+"}"}}(i,sb),ub=function(a,b){function c(a,b,c){var e,f;if(e=a._depsMap[b])for(f=e.length;f--;)d(a,e[f],c)}function d(a,b,d){var e,f,g,h;for(e=a._deps.length;e--;)if(f=a._deps[e],f&&(g=f[b]))for(h=g.length;h--;)d.push(g[h]);c(a,b,d)}return function(c,e,f){var g,h,i;for(g=[],d(c,e,g),h=g.length;h--;)i=g[h],b(i),i.keypath=i.keypath.replace(e,f),a(i),i.update()}}(Q,R),vb=function(a,b,c,d){var e=function(a){var c,d,e,f,g;if(this.root=a.root,this.mustache=a,this.args=[],this.scouts=[],c=a.descriptor.x,g=a.parentFragment.indexRefs,this.str=c.s,e=this.unresolved=this.args.length=c.r?c.r.length:0,!e)return this.resolved=this.ready=!0,this.bubble(),void 0;for(d=0;e>d;d+=1)f=c.r[d],g&&void 0!==g[f]?this.resolveRef(d,!0,g[f]):this.scouts[this.scouts.length]=new b(this,f,a.contextStack,d);this.ready=!0,this.bubble()};return e.prototype={bubble:function(){var a;this.ready&&(a=this.keypath,this.keypath=c(this.str,this.args),"${"===this.keypath.substr(0,2)&&this.createEvaluator(),a?d(this.root,a,this.keypath):this.mustache.resolve(this.keypath))},teardown:function(){for(;this.scouts.length;)this.scouts.pop().teardown()},resolveRef:function(a,b,c){this.args[a]=[b,c],this.bubble(),this.resolved=!--this.unresolved},createEvaluator:function(){this.root._evaluators[this.keypath]?this.root._evaluators[this.keypath].refresh():this.root._evaluators[this.keypath]=new a(this.root,this.keypath,this.str,this.args,this.mustache.priority)}},e}(qb,rb,tb,ub),wb=function(a,b){return function(c,d){var e,f,g;g=c.parentFragment=d.parentFragment,c.root=g.root,c.contextStack=g.contextStack,c.descriptor=d.descriptor,c.index=d.index||0,c.priority=g.priority,c.type=d.descriptor.t,d.descriptor.r&&(g.indexRefs&&void 0!==g.indexRefs[d.descriptor.r]?(f=g.indexRefs[d.descriptor.r],c.indexRef=d.descriptor.r,c.value=f,c.render(c.value)):(e=a(c.root,d.descriptor.r,c.contextStack),void 0!==e?c.resolve(e):(c.ref=d.descriptor.r,c.root._pendingResolution[c.root._pendingResolution.length]=c))),d.descriptor.x&&(c.expressionResolver=new b(c)),c.descriptor.n&&!c.hasOwnProperty("value")&&c.render(void 0)}}(y,vb),xb=function(a,b,c){return function(d){d!==this.keypath&&(this.registered&&c(this),this.keypath=d,b(this),this.update(),this.root.twoway&&this.parentFragment.owner.type===a.ATTRIBUTE&&this.parentFragment.owner.element.bind(),this.expressionResolver&&this.expressionResolver.resolved&&(this.expressionResolver=null))}}(k,Q,R),yb=function(a){return function(){var b,c;c=this.root.get(this.keypath),(b=this.root._wrapped[this.keypath])&&(c=b.get()),a(c,this.value)||(this.render(c),this.value=c)}}(x),zb=function(a,b,c,d,e){var f,g,h;return g=//g,f=function(b,d){this.type=a.INTERPOLATOR,d&&(this.node=document.createTextNode(""),d.appendChild(this.node)),c(this,b)},f.prototype={update:e,resolve:d,detach:function(){return this.node.parentNode.removeChild(this.node),this.node},teardown:function(a){a&&this.detach(),b(this)},render:function(a){this.node&&(this.node.data=void 0==a?"":a)},firstNode:function(){return this.node},toString:function(){var a=void 0!=this.value?""+this.value:"";return a.replace(g,"<").replace(h,">")}},f}(k,nb,wb,xb,yb),Ab=function(a,b,c){function d(a,b,c){var d,e,f;if(e=b.length,ea.length)for(d=a.length;e>d;d+=1)c.contextStack=a.contextStack.concat(a.keypath+"."+d),c.index=d,a.descriptor.i&&(c.indexRef=a.descriptor.i),a.fragments[d]=a.createFragment(c);a.length=e}function e(a,b,d){var e,f;f=a.fragmentsById||(a.fragmentsById=c(null));for(e in f)void 0===b[e]&&f[e]&&(f[e].teardown(!0),f[e]=null);for(e in b)void 0===b[e]||f[e]||(d.contextStack=a.contextStack.concat(a.keypath+"."+e),d.index=e,a.descriptor.i&&(d.indexRef=a.descriptor.i),f[e]=a.createFragment(d))}function f(a,b){a.length||(b.contextStack=a.contextStack.concat(a.keypath),b.index=0,a.fragments[0]=a.createFragment(b),a.length=1)}function g(b,c,d,e){var f,g,h,i;if(g=a(c)&&0===c.length,f=d?g||!c:c&&!g){if(b.length||(e.contextStack=b.contextStack,e.index=0,b.fragments[0]=b.createFragment(e),b.length=1),b.length>1)for(h=b.fragments.splice(1);i=h.pop();)i.teardown(!0)}else b.length&&(b.teardownFragments(!0),b.length=0)}return function(c,h){var i;return i={descriptor:c.descriptor.f,root:c.root,pNode:c.parentFragment.pNode,owner:c},c.descriptor.n?(g(c,h,!0,i),void 0):(a(h)?d(c,h,i):b(h)?c.descriptor.i?e(c,h,i):f(c,i):g(c,h,!1,i),void 0)}}(l,w,c),Bb=function(a,b,c){function d(b,c,g,h,i,j,k){var l,m,n,o;if(!b.html){for(b.indexRefs&&void 0!==b.indexRefs[c]&&(b.indexRefs[c]=h),l=b.contextStack.length;l--;)n=b.contextStack[l],n.substr(0,j.length)===j&&(b.contextStack[l]=n.replace(j,k));for(l=b.items.length;l--;)switch(m=b.items[l],m.type){case a.ELEMENT:e(m,c,g,h,i,j,k);break;case a.PARTIAL:d(m.fragment,c,g,h,i,j,k);break;case a.COMPONENT:d(m.instance.fragment,c,g,h,i,j,k),(o=b.root._liveComponentQueries[m.name])&&o._makeDirty();break;case a.SECTION:case a.INTERPOLATOR:case a.TRIPLE:f(m,c,g,h,i,j,k)}}}function e(a,b,c,e,f,g,h){var i,j,k,l,m,n,o,p,q,r;for(i=a.attributes.length;i--;)j=a.attributes[i],j.fragment&&(d(j.fragment,b,c,e,f,g,h),j.twoway&&j.updateBindings());if(k=a.node._ractive){k.keypath.substr(0,g.length)===g&&(k.keypath=k.keypath.replace(g,h)),void 0!==b&&(k.index[b]=e);for(l in k.events)for(m=k.events[l].proxies,i=m.length;i--;)n=m[i],"object"==typeof n.n&&d(n.a,b,c,e,f,g,h),n.d&&d(n.d,b,c,e,f,g,h);(o=k.binding)&&o.keypath.substr(0,g.length)===g&&(p=k.root._twowayBindings[o.keypath],p.splice(p.indexOf(o),1),o.keypath=o.keypath.replace(g,h),p=k.root._twowayBindings[o.keypath]||(k.root._twowayBindings[o.keypath]=[]),p.push(o))}if(a.fragment&&d(a.fragment,b,c,e,f,g,h),q=a.liveQueries)for(r=a.root,i=q.length;i--;)r._liveQueries[q[i]]._makeDirty()}function f(a,b,e,f,g,h,i){var j;if(a.descriptor.x&&(a.expressionResolver&&a.expressionResolver.teardown(),a.expressionResolver=new c(a)),a.keypath?a.keypath.substr(0,h.length)===h&&a.resolve(a.keypath.replace(h,i)):a.indexRef===b&&(a.value=f,a.render(f)),a.fragments)for(j=a.fragments.length;j--;)d(a.fragments[j],b,e,f,g,h,i)}return d}(k,R,vb),Cb=function(a,b,c){return function(a,d,e,f,g){var h,i,j,k,l,m,n;for(j=d.descriptor.i,h=e;f>h;h+=1)i=d.fragments[h],k=h-g,l=h,m=d.keypath+"."+(h-g),n=d.keypath+"."+h,i.index+=g,b(i,j,k,l,g,m,n);c(a)}}(k,Bb,o),Db=function(a){return function(b){var c,d,e,f,g,h,i,j,k,l,m=this;if(c=this.parentFragment,h=[],b.forEach(function(b,c){var f,g,j;return b===c?(h[b]=m.fragments[c],void 0):(void 0===d&&(d=c),-1===b?((i||(i=[])).push(m.fragments[c]),void 0):(f=b-c,g=m.keypath+"."+c,j=m.keypath+"."+b,a(m.fragments[c],m.descriptor.i,c,b,f,g,j),h[b]=m.fragments[c],e=!0,void 0))}),i)for(;k=i.pop();)k.teardown(!0);if(void 0===d&&(d=this.length),g=this.root.get(this.keypath).length,g!==d){for(j={descriptor:this.descriptor.f,root:this.root,pNode:c.pNode,owner:this},this.descriptor.i&&(j.indexRef=this.descriptor.i),f=d;g>f;f+=1)(k=h[f])?this.docFrag.appendChild(k.detach(!1)):(j.contextStack=this.contextStack.concat(this.keypath+"."+f),j.index=f,k=this.createFragment(j)),this.fragments[f]=k;l=c.findNextNode(this),c.pNode.insertBefore(this.docFrag,l),this.length=g}}}(Bb),Eb=function(){return[]}(),Fb=function(a,b,c,d,e,f,g,h,i,j,k){var l,m;return k.push(function(){m=k.DomFragment}),l=function(b,d){this.type=a.SECTION,this.inverted=!!b.descriptor.n,this.fragments=[],this.length=0,d&&(this.docFrag=document.createDocumentFragment()),this.initialising=!0,c(this,b),d&&d.appendChild(this.docFrag),this.initialising=!1},l.prototype={update:d,resolve:e,smartUpdate:function(a,b){var c;("push"===a||"unshift"===a||"splice"===a)&&(c={descriptor:this.descriptor.f,root:this.root,pNode:this.parentFragment.pNode,owner:this},this.descriptor.i&&(c.indexRef=this.descriptor.i)),this[a]&&(this.rendering=!0,this[a](c,b),this.rendering=!1)},pop:function(){this.length&&(this.fragments.pop().teardown(!0),this.length-=1)},push:function(a,b){var c,d,e;for(c=this.length,d=c+b.length,e=c;d>e;e+=1)a.contextStack=this.contextStack.concat(this.keypath+"."+e),a.index=e,this.fragments[e]=this.createFragment(a);this.length+=b.length,this.parentFragment.pNode.insertBefore(this.docFrag,this.parentFragment.findNextNode(this))},shift:function(){this.splice(null,[0,1])},unshift:function(a,b){this.splice(a,[0,0].concat(new Array(b.length)))},splice:function(a,b){var c,d,e,f,g,i,j,k,l;if(b.length&&(i=+(b[0]<0?this.length+b[0]:b[0]),d=Math.max(0,b.length-2),e=void 0!==b[1]?b[1]:this.length-i,e=Math.min(e,this.length-i),f=d-e)){if(0>f){for(j=i-f,g=i;j>g;g+=1)this.fragments[g].teardown(!0);this.fragments.splice(i,-f)}else{for(j=i+f,c=this.fragments[i]?this.fragments[i].firstNode():this.parentFragment.findNextNode(this),k=[i,0].concat(new Array(f)),this.fragments.splice.apply(this.fragments,k),g=i;j>g;g+=1)a.contextStack=this.contextStack.concat(this.keypath+"."+g),a.index=g,this.fragments[g]=this.createFragment(a);this.parentFragment.pNode.insertBefore(this.docFrag,c)}this.length+=f,l=i+d,h(this.root,this,l,this.length,f)}},merge:i,detach:function(){var a,b;for(b=this.fragments.length,a=0;b>a;a+=1)this.docFrag.appendChild(this.fragments[a].detach());return this.docFrag},teardown:function(a){this.teardownFragments(a),j(this)},firstNode:function(){return this.fragments[0]?this.fragments[0].firstNode():this.parentFragment.findNextNode(this)},findNextNode:function(a){return this.fragments[a.index+1]?this.fragments[a.index+1].firstNode():this.parentFragment.findNextNode(this)},teardownFragments:function(a){for(var b,c;c=this.fragments.shift();)c.teardown(a);if(this.fragmentsById)for(b in this.fragmentsById)this.fragments[b]&&(this.fragmentsById[b].teardown(a),this.fragmentsById[b]=null)},render:function(a){var c,d;(d=this.root._wrapped[this.keypath])&&(a=d.get()),this.rendering||(this.rendering=!0,f(this,a),this.rendering=!1,(!this.docFrag||this.docFrag.childNodes.length)&&!this.initialising&&b&&(c=this.parentFragment.findNextNode(this),c&&c.parentNode===this.parentFragment.pNode?this.parentFragment.pNode.insertBefore(this.docFrag,c):this.parentFragment.pNode.appendChild(this.docFrag)))},createFragment:function(a){var b=new m(a);return this.docFrag&&this.docFrag.appendChild(b.docFrag),b},toString:function(){var a,b,c,d;for(a="",b=0,d=this.length,b=0;d>b;b+=1)a+=this.fragments[b].toString();if(this.fragmentsById)for(c in this.fragmentsById)this.fragmentsById[c]&&(a+=this.fragmentsById[c].toString());return a},find:function(a){var b,c,d;for(c=this.fragments.length,b=0;c>b;b+=1)if(d=this.fragments[b].find(a))return d;return null},findAll:function(a,b){var c,d;for(d=this.fragments.length,c=0;d>c;c+=1)this.fragments[c].findAll(a,b)},findComponent:function(a){var b,c,d;for(c=this.fragments.length,b=0;c>b;b+=1)if(d=this.fragments[b].findComponent(a))return d;return null},findAllComponents:function(a,b){var c,d;for(d=this.fragments.length,c=0;d>c;c+=1)this.fragments[c].findAllComponents(a,b)}},l}(k,f,wb,yb,xb,Ab,Bb,Cb,Db,nb,Eb),Gb=function(a,b,c,d,e,f,g){var h=function(b,d){this.type=a.TRIPLE,d&&(this.nodes=[],this.docFrag=document.createDocumentFragment()),this.initialising=!0,c(this,b),d&&d.appendChild(this.docFrag),this.initialising=!1};return h.prototype={update:d,resolve:e,detach:function(){for(var a=this.nodes.length;a--;)this.docFrag.appendChild(this.nodes[a]);return this.docFrag},teardown:function(a){a&&(this.detach(),this.docFrag=this.nodes=null),g(this)},firstNode:function(){return this.nodes[0]?this.nodes[0]:this.parentFragment.findNextNode(this)},render:function(a){var b,c;if(this.nodes){for(;this.nodes.length;)b=this.nodes.pop(),b.parentNode.removeChild(b);if(!a)return this.nodes=[],void 0;c=this.parentFragment.pNode,this.nodes=f(a,c.tagName,this.docFrag),this.initialising||c.insertBefore(this.docFrag,this.parentFragment.findNextNode(this))}},toString:function(){return void 0!=this.value?this.value:""},find:function(a){var c,d,e,f;for(d=this.nodes.length,c=0;d>c;c+=1)if(e=this.nodes[c],1===e.nodeType){if(b(e,a))return e;if(f=e.querySelector(a))return f}return null},findAll:function(a,c){var d,e,f,g,h,i;for(e=this.nodes.length,d=0;e>d;d+=1)if(f=this.nodes[d],1===f.nodeType&&(b(f,a)&&c.push(f),g=f.querySelectorAll(a)))for(h=g.length,i=0;h>i;i+=1)c.push(g[i])}},h}(k,Z,wb,yb,xb,lb,nb),Hb=function(a){return function(b,c){return b.a&&b.a.xmlns?b.a.xmlns:"svg"===b.e?a.svg:c.namespaceURI||a.html}}(d),Ib=function(){var a,b,c,d;return a="altGlyph altGlyphDef altGlyphItem animateColor animateMotion animateTransform clipPath feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile feTurbulence foreignObject glyphRef linearGradient radialGradient textPath vkern".split(" "),b="attributeName attributeType baseFrequency baseProfile calcMode clipPathUnits contentScriptType contentStyleType diffuseConstant edgeMode externalResourcesRequired filterRes filterUnits glyphRef gradientTransform gradientUnits kernelMatrix kernelUnitLength keyPoints keySplines keyTimes lengthAdjust limitingConeAngle markerHeight markerUnits markerWidth maskContentUnits maskUnits numOctaves pathLength patternContentUnits patternTransform patternUnits pointsAtX pointsAtY pointsAtZ preserveAlpha preserveAspectRatio primitiveUnits refX refY repeatCount repeatDur requiredExtensions requiredFeatures specularConstant specularExponent spreadMethod startOffset stdDeviation stitchTiles surfaceScale systemLanguage tableValues targetX targetY textLength viewBox viewTarget xChannelSelector yChannelSelector zoomAndPan".split(" "),c=function(a){for(var b={},c=a.length;c--;)b[a[c].toLowerCase()]=a[c];return b},d=c(a.concat(b)),function(a){var b=a.toLowerCase();return d[b]||b}}(),Jb=function(a,b){return function(c,d){var e,f;if(e=d.indexOf(":"),-1===e||(f=d.substr(0,e),"xmlns"===f))c.name=c.element.namespace!==a.html?b(d):d,c.lcName=c.name.toLowerCase();else if(d=d.substring(e+1),c.name=b(d),c.lcName=c.name.toLowerCase(),c.namespace=a[f.toLowerCase()],!c.namespace)throw'Unknown namespace ("'+f+'")'}}(d,Ib),Kb=function(a){return function(b,c){var d,e=null===c.value?"":c.value;(d=c.pNode)&&(b.namespace?d.setAttributeNS(b.namespace,c.name,e):"style"===c.name&&d.style.setAttribute?d.style.setAttribute("cssText",e):"class"!==c.name||d.namespaceURI&&d.namespaceURI!==a.html?d.setAttribute(c.name,e):d.className=e,"id"===b.name&&(c.root.nodes[c.value]=d),"value"===b.name&&(d._ractive.value=c.value)),b.value=c.value}}(d),Lb=function(a){var b={"accept-charset":"acceptCharset",accesskey:"accessKey",bgcolor:"bgColor","class":"className",codebase:"codeBase",colspan:"colSpan",contenteditable:"contentEditable",datetime:"dateTime",dirname:"dirName","for":"htmlFor","http-equiv":"httpEquiv",ismap:"isMap",maxlength:"maxLength",novalidate:"noValidate",pubdate:"pubDate",readonly:"readOnly",rowspan:"rowSpan",tabindex:"tabIndex",usemap:"useMap"};return function(c,d){var e;!c.pNode||c.namespace||d.pNode.namespaceURI&&d.pNode.namespaceURI!==a.html||(e=b[c.name]||c.name,void 0!==d.pNode[e]&&(c.propertyName=e),("boolean"==typeof d.pNode[e]||"value"===e)&&(c.useProperty=!0))}}(d),Mb=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q,r;return e=function(){var a,b,c,d=this.pNode;return this.fragment?(a=f(this))?(this.interpolator=a,this.keypath=a.keypath||a.descriptor.r,(b=i(this))?(d._ractive.binding=this.element.binding=b,this.twoway=!0,c=this.root._twowayBindings[this.keypath]||(this.root._twowayBindings[this.keypath]=[]),c[c.length]=b,!0):!1):!1:!1},g=function(){this._ractive.binding.update()},h=function(){var a=this._ractive.root.get(this._ractive.binding.keypath);this.value=void 0==a?"":a},f=function(c){var d,e;return 1!==c.fragment.items.length?null:(d=c.fragment.items[0],d.type!==a.INTERPOLATOR?null:d.keypath||d.ref?d.keypath&&"${"===d.keypath.substr(0,2)?(e="You cannot set up two-way binding against an expression "+d.keypath,c.root.debug&&b(e),null):d:null)},i=function(a){var c=a.pNode;if("SELECT"===c.tagName)return c.multiple?new k(a,c):new l(a,c);if("checkbox"===c.type||"radio"===c.type){if("name"===a.propertyName){if("checkbox"===c.type)return new n(a,c);if("radio"===c.type)return new m(a,c)}return"checked"===a.propertyName?new o(a,c):null}return"value"!==a.lcName&&b("This is... odd"),"file"===c.type?new p(a,c):c.getAttribute("contenteditable")?new q(a,c):new r(a,c)},k=function(a,b){var c;j(this,a,b),b.addEventListener("change",g,!1),c=this.root.get(this.keypath),void 0===c&&this.update()},k.prototype={value:function(){var a,b,c,d;for(a=[],b=this.node.options,d=b.length,c=0;d>c;c+=1)b[c].selected&&(a[a.length]=b[c]._ractive.value);return a},update:function(){var a,b,d;return a=this.attr,b=a.value,d=this.value(),void 0!==b&&c(d,b)||(a.receiving=!0,a.value=d,this.root.set(this.keypath,d),a.receiving=!1),this},deferUpdate:function(){this.deferred!==!0&&(this.root._deferred.attrs.push(this),this.deferred=!0)},teardown:function(){this.node.removeEventListener("change",g,!1)}},l=function(a,b){var c;j(this,a,b),b.addEventListener("change",g,!1),c=this.root.get(this.keypath),void 0===c&&this.update()},l.prototype={value:function(){var a,b,c;for(a=this.node.options,c=a.length,b=0;c>b;b+=1)if(a[b].selected)return a[b]._ractive.value},update:function(){var a=this.value();return this.attr.receiving=!0,this.attr.value=a,this.root.set(this.keypath,a),this.attr.receiving=!1,this},deferUpdate:function(){this.deferred!==!0&&(this.root._deferred.attrs.push(this),this.deferred=!0)},teardown:function(){this.node.removeEventListener("change",g,!1)}},m=function(a,b){var c;this.radioName=!0,j(this,a,b),b.name="{{"+a.keypath+"}}",b.addEventListener("change",g,!1),b.attachEvent&&b.addEventListener("click",g,!1),c=this.root.get(this.keypath),void 0!==c?b.checked=c==b._ractive.value:this.root._deferred.radios.push(this)},m.prototype={value:function(){return this.node._ractive?this.node._ractive.value:this.node.value},update:function(){var a=this.node;a.checked&&(this.attr.receiving=!0,this.root.set(this.keypath,this.value()),this.attr.receiving=!1)},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("click",g,!1)}},n=function(a,b){var c,d;this.checkboxName=!0,j(this,a,b),b.name="{{"+this.keypath+"}}",b.addEventListener("change",g,!1),b.attachEvent&&b.addEventListener("click",g,!1),c=this.root.get(this.keypath),void 0!==c?(d=-1!==c.indexOf(b._ractive.value),b.checked=d):-1===this.root._deferred.checkboxes.indexOf(this.keypath)&&this.root._deferred.checkboxes.push(this.keypath)},n.prototype={changed:function(){return this.node.checked!==!!this.checked},update:function(){this.checked=this.node.checked,this.attr.receiving=!0,this.root.set(this.keypath,d(this.root,this.keypath)),this.attr.receiving=!1},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("click",g,!1)}},o=function(a,b){j(this,a,b),b.addEventListener("change",g,!1),b.attachEvent&&b.addEventListener("click",g,!1)},o.prototype={value:function(){return this.node.checked},update:function(){this.attr.receiving=!0,this.root.set(this.keypath,this.value()),this.attr.receiving=!1},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("click",g,!1)}},p=function(a,b){j(this,a,b),b.addEventListener("change",g,!1)},p.prototype={value:function(){return this.attr.pNode.files},update:function(){this.attr.root.set(this.attr.keypath,this.value())},teardown:function(){this.node.removeEventListener("change",g,!1)}},q=function(a,b){j(this,a,b),b.addEventListener("change",g,!1),this.root.lazy||(b.addEventListener("input",g,!1),b.attachEvent&&b.addEventListener("keyup",g,!1))},q.prototype={update:function(){this.attr.receiving=!0,this.root.set(this.keypath,this.node.innerHTML),this.attr.receiving=!1},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("input",g,!1),this.node.removeEventListener("keyup",g,!1)}},r=function(a,b){j(this,a,b),b.addEventListener("change",g,!1),this.root.lazy||(b.addEventListener("input",g,!1),b.attachEvent&&b.addEventListener("keyup",g,!1)),this.node.addEventListener("blur",h,!1)},r.prototype={value:function(){var a=this.attr.pNode.value;return+a+""===a&&-1===a.indexOf("e")&&(a=+a),a},update:function(){var a=this.attr,b=this.value();a.receiving=!0,a.root.set(a.keypath,b),a.receiving=!1},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("input",g,!1),this.node.removeEventListener("keyup",g,!1),this.node.removeEventListener("blur",h,!1)}},j=function(a,b,c){a.attr=b,a.node=c,a.root=b.root,a.keypath=b.keypath},e}(k,I,E,n),Nb=function(a,b){var c,d,e,f,g,h,i,j,k,l,m,n;return c=function(){var a;if(!this.ready)return this;if(a=this.pNode,"SELECT"===a.tagName&&"value"===this.lcName)return this.update=e,this.deferredUpdate=f,this.update();if(this.isFileInputValue)return this.update=d,this;if(this.twoway&&"name"===this.lcName){if("radio"===a.type)return this.update=i,this.update();if("checkbox"===a.type)return this.update=j,this.update()}return"style"===this.lcName&&a.style.setAttribute?(this.update=k,this.update()):"class"!==this.lcName||a.namespaceURI&&a.namespaceURI!==b.html?a.getAttribute("contenteditable")&&"value"===this.lcName?(this.update=m,this.update()):(this.update=n,this.update()):(this.update=l,this.update())},d=function(){return this},f=function(){this.deferredUpdate=this.pNode.multiple?h:g,this.deferredUpdate()},e=function(){return this.root._deferred.selectValues.push(this),this},g=function(){var a,b,c,d=this.fragment.getValue();for(this.value=this.pNode._ractive.value=d,a=this.pNode.options,c=a.length;c--;)if(b=a[c],b._ractive.value==d)return b.selected=!0,this;return this},h=function(){var b,c,d=this.fragment.getValue();for(a(d)||(d=[d]),b=this.pNode.options,c=b.length;c--;)b[c].selected=-1!==d.indexOf(b[c]._ractive.value);return this.value=d,this},i=function(){var a,b;return a=this.pNode,b=this.fragment.getValue(),a.checked=b==a._ractive.value,this},j=function(){var b,c;return b=this.pNode,c=this.fragment.getValue(),a(c)?(b.checked=-1!==c.indexOf(b._ractive.value),this):(b.checked=c==b._ractive.value,this)},k=function(){var a,b;return a=this.pNode,b=this.fragment.getValue(),void 0===b&&(b=""),b!==this.value&&(a.style.setAttribute("cssText",b),this.value=b),this},l=function(){var a,b;return a=this.pNode,b=this.fragment.getValue(),void 0===b&&(b=""),b!==this.value&&(a.className=b,this.value=b),this},m=function(){var a,b;return a=this.pNode,b=this.fragment.getValue(),void 0===b&&(b=""),b!==this.value&&(this.receiving||(a.innerHTML=b),this.value=b),this},n=function(){var a,b;if(a=this.pNode,b=this.fragment.getValue(),this.isValueAttribute&&(a._ractive.value=b),void 0===b&&(b=""),b!==this.value){if(this.useProperty)return this.receiving||(a[this.propertyName]=b),this.value=b,this;if(this.namespace)return a.setAttributeNS(this.namespace,this.name,b),this.value=b,this;"id"===this.lcName&&(void 0!==this.value&&(this.root.nodes[this.value]=void 0),this.root.nodes[b]=a),a.setAttribute(this.name,b),this.value=b}return this},c}(l,d),Ob=function(){return function(a){var b;return b=this.str.substr(this.pos,a.length),b===a?(this.pos+=a.length,a):null}}(),Pb=function(){var a=/^\s+/;return function(){var b=a.exec(this.remaining());return b?(this.pos+=b[0].length,b[0]):null}}(),Qb=function(){return function(a){return function(b){var c=a.exec(b.str.substring(b.pos));return c?(b.pos+=c[0].length,c[1]||c[0]):null}}}(),Rb=function(){function a(a){var b;return a.getStringMatch("\\")?(b=a.str.charAt(a.pos),a.pos+=1,b):null}return function(b){var c,d="";for(c=a(b);c;)d+=c,c=a(b);return d||null}}(),Sb=function(a,b){var c=a(/^[^\\"]+/),d=a(/^[^\\']+/);return function e(a,f){var g,h,i,j,k,l;if(g=a.pos,h="",l=f?d:c,i=b(a),i&&(h+=i),j=l(a),j&&(h+=j),!h)return"";for(k=e(a,f);""!==k;)h+=k;return h}}(Qb,Rb),Tb=function(a,b){return function(c){var d,e;return d=c.pos,c.getStringMatch('"')?(e=b(c,!1),c.getStringMatch('"')?{t:a.STRING_LITERAL,v:e}:(c.pos=d,null)):c.getStringMatch("'")?(e=b(c,!0),c.getStringMatch("'")?{t:a.STRING_LITERAL,v:e}:(c.pos=d,null)):null}}(k,Sb),Ub=function(a,b){var c=b(/^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/);return function(b){var d;return(d=c(b))?{t:a.NUMBER_LITERAL,v:d}:null}}(k,Qb),Vb=function(a){return a(/^[a-zA-Z_$][a-zA-Z_$0-9]*/)}(Qb),Wb=function(a,b,c){var d=/^[a-zA-Z_$][a-zA-Z_$0-9]*$/;return function(e){var f;return(f=a(e))?d.test(f.v)?f.v:'"'+f.v.replace(/"/g,'\\"')+'"':(f=b(e))?f.v:(f=c(e))?f:void 0}}(Tb,Ub,Vb),Xb=function(a,b,c,d){function e(a){var b,c,e;return a.allowWhitespace(),(b=d(a))?(e={key:b},a.allowWhitespace(),a.getStringMatch(":")?(a.allowWhitespace(),(c=a.getToken())?(e.value=c.v,e):null):null):null}var f,g,h,i,j,k;return g={"true":!0,"false":!1,undefined:void 0,"null":null},h=new RegExp("^(?:"+Object.keys(g).join("|")+")"),i=/^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/,j=/\$\{([^\}]+)\}/g,k=/^\$\{([^\}]+)\}/,f=function(a,b){this.str=a,this.values=b,this.pos=0,this.result=this.getToken()},f.prototype={remaining:function(){return this.str.substring(this.pos)},getStringMatch:a,getToken:function(){return this.allowWhitespace(),this.getPlaceholder()||this.getSpecial()||this.getNumber()||this.getString()||this.getObject()||this.getArray()},getPlaceholder:function(){var a;return this.values?(a=k.exec(this.remaining()))&&this.values.hasOwnProperty(a[1])?(this.pos+=a[0].length,{v:this.values[a[1]]}):void 0:null},getSpecial:function(){var a;return(a=h.exec(this.remaining()))?(this.pos+=a[0].length,{v:g[a[0]]}):void 0},getNumber:function(){var a;return(a=i.exec(this.remaining()))?(this.pos+=a[0].length,{v:+a[0]}):void 0},getString:function(){var a,b=c(this);return b&&(a=this.values)?{v:b.v.replace(j,function(b,c){return a[c]||c})}:b},getObject:function(){var a,b;if(!this.getStringMatch("{"))return null;for(a={};b=e(this);){if(a[b.key]=b.value,this.allowWhitespace(),this.getStringMatch("}"))return{v:a};if(!this.getStringMatch(","))return null}return null},getArray:function(){var a,b;if(!this.getStringMatch("["))return null;for(a=[];b=this.getToken();){if(a.push(b.v),this.getStringMatch("]"))return{v:a};if(!this.getStringMatch(","))return null}return null},allowWhitespace:b},function(a,b){var c=new f(a,b);return c.result?{value:c.result.v,remaining:c.remaining()}:null}}(Ob,Pb,Tb,Wb),Yb=function(a,b,c,d,e){function f(a){return"string"==typeof a?a:JSON.stringify(a)}var g=function(b){this.type=a.INTERPOLATOR,c(this,b)};return g.prototype={update:d,resolve:e,render:function(a){this.value=a,this.parentFragment.bubble()},teardown:function(){b(this)},toString:function(){return void 0==this.value?"":f(this.value)}},g}(k,nb,wb,yb,xb),Zb=function(a,b,c,d,e,f,g){var h,i;return g.push(function(){i=g.StringFragment}),h=function(c){this.type=a.SECTION,this.fragments=[],this.length=0,b(this,c)},h.prototype={update:c,resolve:d,teardown:function(){this.teardownFragments(),f(this)},teardownFragments:function(){for(;this.fragments.length;)this.fragments.shift().teardown();this.length=0},bubble:function(){this.value=this.fragments.join(""),this.parentFragment.bubble()},render:function(a){var b;(b=this.root._wrapped[this.keypath])&&(a=b.get()),e(this,a),this.parentFragment.bubble()},createFragment:function(a){return new i(a)},toString:function(){return this.fragments.join("")}},h}(k,wb,yb,xb,Ab,nb,Eb),$b=function(a){var b=function(b){this.type=a.TEXT,this.text=b};return b.prototype={toString:function(){return this.text},teardown:function(){}},b}(k),_b=function(a,b){return function(){var c,d,e,f,g,h,i;if(!this.argsList||this.dirty){if(c={},d=0,f=this.root._guid,i=function(a){return a.map(function(a){var b,e,g;return a.text?a.text:a.fragments?a.fragments.map(function(a){return i(a.items)}).join(""):(b=f+"-"+d++,g=(e=a.root._wrapped[a.keypath])?e.value:a.value,c[b]=g,"${"+b+"}")}).join("")},e=i(this.items),h=b("["+e+"]",c))this.argsList=h.value;else{if(g="Could not parse directive arguments ("+this.toString()+"). If you think this is a bug, please file an issue at http://github.com/RactiveJS/Ractive/issues",this.root.debug)throw new Error(g);a(g),this.argsList=[e]}this.dirty=!1}return this.argsList}}(I,Xb),ac=function(a,b,c,d,e,f,g,h){var i=function(a){c(this,a)};return i.prototype={createItem:function(b){if("string"==typeof b.descriptor)return new f(b.descriptor);switch(b.descriptor.t){case a.INTERPOLATOR:return new d(b);case a.TRIPLE:return new d(b);case a.SECTION:return new e(b);default:throw"Something went wrong in a rather interesting way"}},bubble:function(){this.dirty=!0,this.owner.bubble()},teardown:function(){var a,b;for(a=this.items.length,b=0;a>b;b+=1)this.items[b].teardown()},getValue:function(){var b;return 1===this.items.length&&this.items[0].type===a.INTERPOLATOR&&(b=this.items[0].value,void 0!==b)?b:this.toString()},isSimple:function(){var b,c,d;if(void 0!==this.simple)return this.simple;for(b=this.items.length;b--;)if(c=this.items[b],c.type!==a.TEXT){if(c.type!==a.INTERPOLATOR)return this.simple=!1;if(d)return!1;d=!0}return this.simple=!0},toString:function(){return this.items.join("")},toJSON:function(){var a,c=this.getValue();return"string"==typeof c&&(a=b(c),c=a?a.value:c),c},toArgsList:g},h.StringFragment=i,i}(k,Xb,kb,Yb,Zb,$b,_b,Eb),bc=function(a,b,c,d,e,f,g){var h=function(e){return this.type=a.ATTRIBUTE,this.element=e.element,b(this,e.name),null===e.value||"string"==typeof e.value?(c(this,e),void 0):(this.root=e.root,this.pNode=e.pNode,this.parentFragment=this.element.parentFragment,this.fragment=new g({descriptor:e.value,root:this.root,owner:this,contextStack:e.contextStack}),this.pNode&&("value"===this.name&&(this.isValueAttribute=!0,"INPUT"===this.pNode.tagName&&"file"===this.pNode.type&&(this.isFileInputValue=!0)),d(this,e),this.selfUpdating=this.fragment.isSimple(),this.ready=!0),void 0)};return h.prototype={bind:e,update:f,updateBindings:function(){this.keypath=this.interpolator.keypath||this.interpolator.ref,"name"===this.propertyName&&(this.pNode.name="{{"+this.keypath+"}}") -},teardown:function(){var a;if(this.boundEvents)for(a=this.boundEvents.length;a--;)this.pNode.removeEventListener(this.boundEvents[a],this.updateModel,!1);this.fragment&&this.fragment.teardown()},bubble:function(){this.selfUpdating?this.update():!this.deferred&&this.ready&&(this.root._deferred.attrs.push(this),this.deferred=!0)},toString:function(){var a;return null===this.value?this.name:this.fragment?(a=this.fragment.toString(),this.name+"="+JSON.stringify(a)):this.name+"="+JSON.stringify(this.value)}},h}(k,Jb,Kb,Lb,Mb,Nb,ac),cc=function(a){return function(b,c){var d,e,f;b.attributes=[];for(d in c)c.hasOwnProperty(d)&&(e=c[d],f=new a({element:b,name:d,value:e,root:b.root,pNode:b.node,contextStack:b.parentFragment.contextStack}),b.attributes[b.attributes.length]=b.attributes[d]=f,"name"!==d&&f.update());return b.attributes}}(bc),dc=function(a,b,c,d){var e,f,g;return d.push(function(){e=d.DomFragment}),f=function(){var a=this.node,b=this.fragment.toString();a.styleSheet&&(a.styleSheet.cssText=b),a.innerHTML=b},g=function(){this.node.type&&"text/javascript"!==this.node.type||a("Script tag was updated. This does not cause the code to be re-evaluated!"),this.node.innerHTML=this.fragment.toString()},function(a,d,h,i){var j,k,l,m,n;if("script"===a.lcName||"style"===a.lcName)return a.fragment=new c({descriptor:h.f,root:a.root,contextStack:a.parentFragment.contextStack,owner:a}),i&&("script"===a.lcName?(a.bubble=g,a.node.innerHTML=a.fragment.toString()):(a.bubble=f,a.bubble())),void 0;if("string"!=typeof h.f||d&&d.namespaceURI&&d.namespaceURI!==b.html)a.fragment=new e({descriptor:h.f,root:a.root,pNode:d,contextStack:a.parentFragment.contextStack,owner:a}),i&&d.appendChild(a.fragment.docFrag);else if(a.html=h.f,i)for(d.innerHTML=a.html,j=a.root._liveQueries,k=j.length;k--;)if(l=j[k],(m=d.querySelectorAll(l))&&(n=m.length))for((a.liveQueries||(a.liveQueries=[])).push(l),a.liveQueries[l]=[];n--;)a.liveQueries[l][n]=m[n]}}(I,d,ac,Eb),ec=function(a,b){var c=function(c,d,e,f){var g,h,i;if(this.root=d,this.node=e.node,g=c.n||c,"string"!=typeof g&&(h=new b({descriptor:g,root:this.root,owner:e,contextStack:f}),g=h.toString(),h.teardown()),c.a?this.params=c.a:c.d&&(h=new b({descriptor:c.d,root:this.root,owner:e,contextStack:f}),this.params=h.toArgsList(),h.teardown()),this.fn=d.decorators[g],!this.fn){if(i='Missing "'+g+'" decorator. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#decorators',d.debug)throw new Error(i);a(i)}};return c.prototype={init:function(){var a,b;if(this.params?(b=[this.node].concat(this.params),a=this.fn.apply(this.root,b)):a=this.fn.call(this.root,this.node),!a||!a.teardown)throw new Error("Decorator definition must return an object with a teardown method");this.teardown=a.teardown}},c}(I,ac),fc=function(a){return function(b,c,d,e){d.decorator=new a(b,c,d,e),d.decorator.fn&&c._deferred.decorators.push(d.decorator)}}(ec),gc=function(a,b){var c,d,e,f,g,h,i,j,k;return c=function(a,b,c,e,f){var g,h;g=a.node._ractive.events,h=g[b]||(g[b]=new d(a,b,e,f)),h.add(c)},d=function(b,c,d){var e;this.element=b,this.root=b.root,this.node=b.node,this.name=c,this.contextStack=d,this.proxies=[],(e=this.root.events[c])?this.custom=e(this.node,k(c)):("on"+c in this.node||a('Missing "'+this.name+'" event. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#events'),this.node.addEventListener(c,j,!1))},d.prototype={add:function(a){this.proxies[this.proxies.length]=new e(this.element,this.root,a,this.contextStack)},teardown:function(){var a;for(this.custom?this.custom.teardown():this.node.removeEventListener(this.name,j,!1),a=this.proxies.length;a--;)this.proxies[a].teardown()},fire:function(a){for(var b=this.proxies.length;b--;)this.proxies[b].fire(a)}},e=function(a,c,d,e){var i;return this.root=c,i=d.n||d,this.n="string"==typeof i?i:new b({descriptor:d.n,root:this.root,owner:a,contextStack:e}),d.a?(this.a=d.a,this.fire=g,void 0):d.d?(this.d=new b({descriptor:d.d,root:this.root,owner:a,contextStack:e}),this.fire=h,void 0):(this.fire=f,void 0)},e.prototype={teardown:function(){this.n.teardown&&this.n.teardown(),this.d&&this.d.teardown()},bubble:function(){}},f=function(a){this.root.fire(this.n.toString(),a)},g=function(a){this.root.fire.apply(this.root,[this.n.toString(),a].concat(this.a))},h=function(a){var b=this.d.toArgsList();"string"==typeof b&&(b=b.substr(1,b.length-2)),this.root.fire.apply(this.root,[this.n.toString(),a].concat(b))},j=function(a){var b=this._ractive;b.events[a.type].fire({node:this,original:a,index:b.index,keypath:b.keypath,context:b.root.get(b.keypath)})},i={},k=function(a){return i[a]?i[a]:i[a]=function(b){var c=b.node._ractive;b.index=c.index,b.keypath=c.keypath,b.context=c.root.get(c.keypath),c.events[a].fire(b)}},c}(I,ac),hc=function(a){return function(b,c){var d,e,f;for(e in c)if(c.hasOwnProperty(e))for(f=e.split("-"),d=f.length;d--;)a(b,f[d],c[e],b.parentFragment.contextStack)}}(gc),ic=function(){return function(a){var b,c,d,e,f;for(b=a.root,c=b._liveQueries,d=c.length;d--;)e=c[d],f=c[e],f._test(a)&&((a.liveQueries||(a.liveQueries=[])).push(e),a.liveQueries[e]=[a.node])}}(),jc=function(){return function(a){return a.replace(/-([a-zA-Z])/g,function(a,b){return b.toUpperCase()})}}(),kc=function(){return function(a,b){var c;for(c in b)b.hasOwnProperty(c)&&!a.hasOwnProperty(c)&&(a[c]=b[c]);return a}}(),lc=function(a,b,c,d,e,f,g,h){function i(a){var b,c,d;if(!q[a])if(void 0!==m[a])q[a]=a;else for(d=a.charAt(0).toUpperCase()+a.substring(1),b=n.length;b--;)if(c=n[b],void 0!==m[c+d]){q[a]=c+d;break}return q[a]}function j(a){return a.replace(p,"")}function k(a){var b;return o.test(a)&&(a="-"+a),b=a.replace(/[A-Z]/g,function(a){return"-"+a.toLowerCase()})}var l,m,n,o,p,q,r,s,t,u,v,w;if(a)return m=b("div").style,function(){void 0!==m.transition?(s="transition",w="transitionend",r=!0):void 0!==m.webkitTransition?(s="webkitTransition",w="webkitTransitionEnd",r=!0):r=!1}(),s&&(t=s+"Duration",u=s+"Property",v=s+"TimingFunction"),l=function(a,b,d,e,f){var g,i,j,k=this;if(this.root=b,this.node=d.node,this.isIntro=f,this.originalStyle=this.node.getAttribute("style"),this.complete=function(a){!a&&k.isIntro&&k.resetStyle(),k._manager.pop(k.node),k.node._ractive.transition=null},g=a.n||a,"string"!=typeof g&&(i=new h({descriptor:g,root:this.root,owner:d,contextStack:e}),g=i.toString(),i.teardown()),this.name=g,a.a?this.params=a.a:a.d&&(i=new h({descriptor:a.d,root:this.root,owner:d,contextStack:e}),this.params=i.toArgsList(),i.teardown()),this._fn=b.transitions[g],!this._fn){if(j='Missing "'+g+'" transition. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#transitions',b.debug)throw new Error(j);return c(j),void 0}},l.prototype={init:function(){if(this._inited)throw new Error("Cannot initialize a transition more than once");this._inited=!0,this._fn.apply(this.root,[this].concat(this.params))},getStyle:function(a){var b,c,d,f,g;if(b=window.getComputedStyle(this.node),"string"==typeof a)return g=b[i(a)],"0px"===g&&(g=0),g;if(!e(a))throw new Error("Transition#getStyle must be passed a string, or an array of strings representing CSS properties");for(c={},d=a.length;d--;)f=a[d],g=b[i(f)],"0px"===g&&(g=0),c[f]=g;return c},setStyle:function(a,b){var c;if("string"==typeof a)this.node.style[i(a)]=b;else for(c in a)a.hasOwnProperty(c)&&(this.node.style[i(c)]=a[c]);return this},animateStyle:function(a,b,d,e){var g,h,l,m,n,o,p,q,r,s=this;for("string"==typeof a?(n={},n[a]=b):(n=a,e=d,d=b),d||(c('The "'+s.name+'" transition does not supply an options object to `t.animateStyle()`. This will break in a future version of Ractive. For more info see https://github.com/RactiveJS/Ractive/issues/340'),d=s,e=s.complete),d.duration||(s.setStyle(n),e&&e()),g=Object.keys(n),h=[],l=window.getComputedStyle(s.node),o={},q=g.length;q--;)r=g[q],m=l[i(r)],"0px"===m&&(m=0),m!=n[r]&&(h[h.length]=r,s.node.style[i(r)]=m);return h.length?(setTimeout(function(){s.node.style[u]=g.map(i).map(k).join(","),s.node.style[v]=k(d.easing||"linear"),s.node.style[t]=d.duration/1e3+"s",p=function(a){var b;b=h.indexOf(f(j(a.propertyName))),-1!==b&&h.splice(b,1),h.length||(s.root.fire(s.name+":end"),s.node.removeEventListener(w,p,!1),e&&e())},s.node.addEventListener(w,p,!1),setTimeout(function(){for(var a=h.length;a--;)r=h[a],s.node.style[i(r)]=n[r]},0)},d.delay||0),void 0):(e&&e(),void 0)},resetStyle:function(){this.originalStyle?this.node.setAttribute("style",this.originalStyle):(this.node.getAttribute("style"),this.node.removeAttribute("style"))},processParams:function(a,b){return"number"==typeof a?a={duration:a}:"string"==typeof a?a="slow"===a?{duration:600}:"fast"===a?{duration:200}:{duration:400}:a||(a={}),g(a,b)}},n=["o","ms","moz","webkit"],o=new RegExp("^(?:"+n.join("|")+")([A-Z])"),p=new RegExp("^-(?:"+n.join("|")+")-"),q={},l}(f,e,I,J,l,jc,kc,ac),mc=function(a,b){return function(a,c,d,e,f){var g,h,i;!c.transitionsEnabled||c._parent&&!c._parent.transitionsEnabled||(g=new b(a,c,d,e,f),g._fn&&(h=g.node,g._manager=c._transitionManager,(i=h._ractive.transition)&&i.complete(),h._ractive.transition=g,g._manager.push(h),f?c._deferred.transitions.push(g):g.init()))}}(I,lc),nc=function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o){return function(e,p,q){var r,s,t,u,v,w,x,y,z,A,B,C,D;if(e.type=a.ELEMENT,r=e.parentFragment=p.parentFragment,s=r.pNode,t=r.contextStack,u=e.descriptor=p.descriptor,e.root=B=r.root,e.index=p.index,e.lcName=u.e.toLowerCase(),e.eventListeners=[],e.customEventListeners=[],s&&(v=e.namespace=h(u,s),w=v!==b.html?o(u.e):u.e,e.node=g(w,v),d(e.node,"_ractive",{value:{proxy:e,keypath:t.length?t[t.length-1]:"",index:r.indexRefs,events:c(null),root:B}})),x=i(e,u.a),u.f){if(e.node&&e.node.getAttribute("contenteditable")&&e.node.innerHTML){if(D="A pre-populated contenteditable element should not have children",B.debug)throw new Error(D);f(D)}j(e,e.node,u,q)}q&&u.v&&l(e,u.v),q&&(B.twoway&&(e.bind(),e.node.getAttribute("contenteditable")&&e.node._ractive.binding&&e.node._ractive.binding.update()),x.name&&!x.name.twoway&&x.name.update(),"IMG"===e.node.tagName&&((y=e.attributes.width)||(z=e.attributes.height))&&e.node.addEventListener("load",A=function(){y&&(e.node.width=y.value),z&&(e.node.height=z.value),e.node.removeEventListener("load",A,!1)},!1),q.appendChild(e.node),u.o&&k(u.o,B,e,t),u.t1&&n(u.t1,B,e,t,!0),"OPTION"===e.node.tagName&&("SELECT"===s.tagName&&(C=s._ractive.binding)&&C.deferUpdate(),e.node._ractive.value==s._ractive.value&&(e.node.selected=!0)),e.node.autofocus&&(B._deferred.focusable=e.node)),m(e)}}(k,d,c,g,Z,I,e,Hb,cc,dc,fc,hc,ic,mc,Ib),oc=function(a){return function(b){var c,d,e,f,g,h,i,j,k;for(this.fragment&&this.fragment.teardown(!1);this.attributes.length;)this.attributes.pop().teardown();if(this.node){for(c in this.node._ractive.events)this.node._ractive.events[c].teardown();(d=this.node._ractive.binding)&&(d.teardown(),e=this.root._twowayBindings[d.attr.keypath],e.splice(e.indexOf(d),1))}if(this.decorator&&this.decorator.teardown(),this.descriptor.t2&&a(this.descriptor.t2,this.root,this,this.parentFragment.contextStack,!1),b&&this.root._transitionManager.detachWhenReady(this),g=this.liveQueries)for(f=g.length;f--;)if(h=g[f],j=this.liveQueries[h])for(k=j.length,i=this.root._liveQueries[h];k--;)i._remove(j[k])}}(mc),pc=function(){return"area base br col command doctype embed hr img input keygen link meta param source track wbr".split(" ")}(),qc=function(a){return function(){var b,c,d;for(b="<"+(this.descriptor.y?"!doctype":this.descriptor.e),d=this.attributes.length,c=0;d>c;c+=1)b+=" "+this.attributes[c].toString();return b+=">",this.html?b+=this.html:this.fragment&&(b+=this.fragment.toString()),-1===a.indexOf(this.descriptor.e)&&(b+=""+this.descriptor.e+">"),b}}(pc),rc=function(a){return function(b){var c;return a(this.node,b)?this.node:this.html&&(c=this.node.querySelector(b))?c:this.fragment&&this.fragment.find?this.fragment.find(b):void 0}}(Z),sc=function(){return function(a,b){var c,d,e,f,g;if(b._test(this,!0)&&b.live&&((this.liveQueries||(this.liveQueries=[])).push(a),this.liveQueries[a]=[this.node]),this.html&&(c=this.node.querySelectorAll(a))&&(e=c.length))for(b.live&&(this.liveQueries[a]||((this.liveQueries||(this.liveQueries=[])).push(a),this.liveQueries[a]=[]),g=this.liveQueries[a]),d=0;e>d;d+=1)f=c[d],b.push(f),b.live&&g.push(f);this.fragment&&this.fragment.findAll(a,b)}}(),tc=function(){return function(a){return this.fragment?this.fragment.findComponent(a):void 0}}(),uc=function(){return function(a,b){this.fragment&&this.fragment.findAllComponents(a,b)}}(),vc=function(){return function(){var a=this.attributes;if(this.node&&(this.binding&&(this.binding.teardown(),this.binding=null),!(this.node.getAttribute("contenteditable")&&a.value&&a.value.bind())))switch(this.descriptor.e){case"select":case"textarea":return a.value&&a.value.bind(),void 0;case"input":if("radio"===this.node.type||"checkbox"===this.node.type){if(a.name&&a.name.bind())return;if(a.checked&&a.checked.bind())return}if(a.value&&a.value.bind())return}}}(),wc=function(a,b,c,d,e,f,g,h){var i=function(b,c){a(this,b,c)};return i.prototype={detach:function(){return this.node?(this.node.parentNode&&this.node.parentNode.removeChild(this.node),this.node):void 0},teardown:b,firstNode:function(){return this.node},findNextNode:function(){return null},bubble:function(){},toString:c,find:d,findAll:e,findComponent:f,findAllComponents:g,bind:h},i}(nc,oc,qc,rc,sc,tc,uc,vc),xc={missingParser:"Missing Ractive.parse - cannot parse template. Either preparse or use the version that includes the parser"},yc={},zc=function(){return function(a){var b,c,d;for(d="";a.length;){if(b=a.indexOf(""),-1===b&&-1===c){d+=a;break}if(-1!==b&&-1===c)throw"Illegal HTML - expected closing comment sequence ('-->')";if(-1!==c&&-1===b||b>c)throw"Illegal HTML - unexpected closing comment sequence ('-->')";d+=a.substr(0,b),a=a.substring(c+3)}return d}}(),Ac=function(a){return function(b){var c,d,e,f,g,h;for(g=/^\s*\r?\n/,h=/\r?\n\s*$/,c=2;c":a.PARTIAL,"!":a.COMMENT,"&":a.TRIPLE};return function(a){var c=b[a.str.charAt(a.pos)];return c?(a.pos+=1,c):null}}(k),Ec=function(a,b,c){var d=b(/^\s*:\s*([a-zA-Z_$][a-zA-Z_$0-9]*)/),e=/^[0-9][1-9]*$/;return function(b,f){var g,h,i,j,k,l,m;if(g=b.pos,h={type:f?a.TRIPLE:a.MUSTACHE},!(f||((j=b.getExpression())&&(h.mustacheType=a.INTERPOLATOR,b.allowWhitespace(),b.getStringMatch(b.delimiters[1])?b.pos-=b.delimiters[1].length:(b.pos=g,j=null)),j||(i=c(b),i===a.TRIPLE?h={type:a.TRIPLE}:h.mustacheType=i||a.INTERPOLATOR,i!==a.COMMENT&&i!==a.CLOSING||(l=b.remaining(),m=l.indexOf(b.delimiters[1]),-1===m)))))return h.ref=l.substr(0,m),b.pos+=m,h;for(j||(b.allowWhitespace(),j=b.getExpression());j.t===a.BRACKETED&&j.x;)j=j.x;return j.t===a.REFERENCE?h.ref=j.n:j.t===a.NUMBER_LITERAL&&e.test(j.v)?h.ref=j.v:h.expression=j,k=d(b),null!==k&&(h.indexRef=k),h}}(k,Qb,Dc),Fc=function(a,b,c){function d(d,e){var f,g,h=d.pos;return g=e?d.tripleDelimiters:d.delimiters,d.getStringMatch(g[0])?(f=b(d))?d.getStringMatch(g[1])?(d[e?"tripleDelimiters":"delimiters"]=f,{type:a.MUSTACHE,mustacheType:a.DELIMCHANGE}):(d.pos=h,null):(d.allowWhitespace(),f=c(d,e),null===f?(d.pos=h,null):(d.allowWhitespace(),d.getStringMatch(g[1])?f:(d.pos=h,null))):null}return function(){var a=this.tripleDelimiters[0].length>this.delimiters[0].length;return d(this,a)||d(this,!a)}}(k,Cc,Ec),Gc=function(a){return function(){var b,c,d;if(!this.getStringMatch(""),-1===d)throw new Error('Unexpected end of input (expected "-->" to close comment)');return b=c.substr(0,d),this.pos+=d+3,{type:a.COMMENT,content:b}}}(k),Hc=function(){return function(a,b){var c,d,e;for(c=b.length;c--;){if(d=a.indexOf(b[c]),!d)return 0;-1!==d&&(!e||e>d)&&(e=d)}return e||-1}}(),Ic=function(a,b,c){var d,e,f,g,h,i,j,k,l,m,n,o,p;return d=function(){return e(this)||f(this)},e=function(b){var c,d,e,f;return c=b.pos,b.inside?null:b.getStringMatch("<")?(d={type:a.TAG},b.getStringMatch("!")&&(d.doctype=!0),d.name=g(b),d.name?(e=h(b),e&&(d.attrs=e),b.allowWhitespace(),b.getStringMatch("/")&&(d.selfClosing=!0),b.getStringMatch(">")?(f=d.name.toLowerCase(),("script"===f||"style"===f)&&(b.inside=f),d):(b.pos=c,null)):(b.pos=c,null)):null},f=function(b){var c,d,e;if(c=b.pos,e=function(a){throw new Error("Unexpected character "+b.remaining().charAt(0)+" (expected "+a+")")},!b.getStringMatch("<"))return null;if(d={type:a.TAG,closing:!0},b.getStringMatch("/")||e('"/"'),d.name=g(b),d.name||e("tag name"),b.getStringMatch(">")||e('">"'),b.inside){if(d.name.toLowerCase()!==b.inside)return b.pos=c,null;b.inside=null}return d},g=b(/^[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/),h=function(a){var b,c,d;if(b=a.pos,a.allowWhitespace(),d=i(a),!d)return a.pos=b,null;for(c=[];null!==d;)c[c.length]=d,a.allowWhitespace(),d=i(a);return c},i=function(a){var b,c,d;return(c=j(a))?(b={name:c},d=k(a),d&&(b.value=d),b):null},j=b(/^[^\s"'>\/=]+/),k=function(a){var b,c;return b=a.pos,a.allowWhitespace(),a.getStringMatch("=")?(a.allowWhitespace(),c=p(a,"'")||p(a,'"')||l(a),null===c?(a.pos=b,null):c):(a.pos=b,null)},n=b(/^[^\s"'=<>`]+/),m=function(b){var c,d,e;return c=b.pos,(d=n(b))?(-1!==(e=d.indexOf(b.delimiters[0]))&&(d=d.substr(0,e),b.pos=c+d.length),{type:a.TEXT,value:d}):null},l=function(a){var b,c;for(b=[],c=a.getMustache()||m(a);null!==c;)b[b.length]=c,c=a.getMustache()||m(a);return b.length?b:null},p=function(a,b){var c,d,e;if(c=a.pos,!a.getStringMatch(b))return null;for(d=[],e=a.getMustache()||o(a,b);null!==e;)d[d.length]=e,e=a.getMustache()||o(a,b);return a.getStringMatch(b)?d:(a.pos=c,null)},o=function(b,d){var e,f,g;if(e=b.pos,g=b.remaining(),f=c(g,[d,b.delimiters[0],b.delimiters[1]]),-1===f)throw new Error("Quoted attribute value must have a closing quote");return f?(b.pos+=f,{type:a.TEXT,value:g.substr(0,f)}):null},d}(k,Qb,Hc),Jc=function(a,b){return function(){var c,d,e;return d=this.remaining(),e=this.inside?""+this.inside:"<",(c=b(d,[e,this.delimiters[0],this.tripleDelimiters[0]]))?(-1===c&&(c=d.length),this.pos+=c,{type:a.TEXT,value:d.substr(0,c)}):null}}(k,Hc),Kc=function(a){return function(b){var c=b.remaining();return"true"===c.substr(0,4)?(b.pos+=4,{t:a.BOOLEAN_LITERAL,v:"true"}):"false"===c.substr(0,5)?(b.pos+=5,{t:a.BOOLEAN_LITERAL,v:"false"}):null}}(k),Lc=function(a,b){return function(c){var d,e,f;return d=c.pos,c.allowWhitespace(),e=b(c),null===e?(c.pos=d,null):(c.allowWhitespace(),c.getStringMatch(":")?(c.allowWhitespace(),f=c.getExpression(),null===f?(c.pos=d,null):{t:a.KEY_VALUE_PAIR,k:e,v:f}):(c.pos=d,null))}}(k,Wb),Mc=function(a){return function b(c){var d,e,f,g;return d=c.pos,f=a(c),null===f?null:(e=[f],c.getStringMatch(",")?(g=b(c),g?e.concat(g):(c.pos=d,null)):e)}}(Lc),Nc=function(a,b){return function(c){var d,e;return d=c.pos,c.allowWhitespace(),c.getStringMatch("{")?(e=b(c),c.allowWhitespace(),c.getStringMatch("}")?{t:a.OBJECT_LITERAL,m:e}:(c.pos=d,null)):(c.pos=d,null)}}(k,Mc),Oc=function(){return function a(b){var c,d,e,f;if(c=b.pos,b.allowWhitespace(),e=b.getExpression(),null===e)return null;if(d=[e],b.allowWhitespace(),b.getStringMatch(",")){if(f=a(b),null===f)return b.pos=c,null;d=d.concat(f)}return d}}(),Pc=function(a,b){return function(c){var d,e;return d=c.pos,c.allowWhitespace(),c.getStringMatch("[")?(e=b(c),c.getStringMatch("]")?{t:a.ARRAY_LITERAL,m:e}:(c.pos=d,null)):(c.pos=d,null)}}(k,Oc),Qc=function(a,b,c,d,e){return function(f){var g=a(f)||b(f)||c(f)||d(f)||e(f);return g}}(Ub,Kc,Tb,Nc,Pc),Rc=function(a,b,c){var d,e,f,g;return d=b(/^\.[a-zA-Z_$0-9]+/),e=function(a){var b=f(a);return b?"."+b:null},f=b(/^\[(0|[1-9][0-9]*)\]/),g=/^(?:Array|Date|RegExp|decodeURIComponent|decodeURI|encodeURIComponent|encodeURI|isFinite|isNaN|parseFloat|parseInt|JSON|Math|NaN|undefined|null)$/,function(b){var f,h,i,j,k,l,m;for(f=b.pos,h="";b.getStringMatch("../");)h+="../";if(h||(j=b.getStringMatch(".")||""),i=c(b)||"",!h&&!j&&g.test(i))return{t:a.GLOBAL,v:i};if("this"!==i||h||j||(i=".",f+=3),k=(h||j)+i,!k)return null;for(;l=d(b)||e(b);)k+=l;return b.getStringMatch("(")&&(m=k.lastIndexOf("."),-1!==m?(k=k.substr(0,m),b.pos=f+k.length):b.pos-=1),{t:a.REFERENCE,n:k}}}(k,Qb,Vb),Sc=function(a){return function(b){var c,d;return c=b.pos,b.getStringMatch("(")?(b.allowWhitespace(),(d=b.getExpression())?(b.allowWhitespace(),b.getStringMatch(")")?{t:a.BRACKETED,x:d}:(b.pos=c,null)):(b.pos=c,null)):null}}(k),Tc=function(a,b,c){return function(d){return a(d)||b(d)||c(d)}}(Qc,Rc,Sc),Uc=function(a,b){return function(c){var d,e,f;if(d=c.pos,c.allowWhitespace(),c.getStringMatch(".")){if(c.allowWhitespace(),e=b(c))return{t:a.REFINEMENT,n:e};c.expected("a property name")}return c.getStringMatch("[")?(c.allowWhitespace(),f=c.getExpression(),f||c.expected("an expression"),c.allowWhitespace(),c.getStringMatch("]")||c.expected('"]"'),{t:a.REFINEMENT,x:f}):null}}(k,Vb),Vc=function(a,b,c,d){return function(e){var f,g,h,i;if(g=b(e),!g)return null;for(;g;)if(f=e.pos,h=d(e))g={t:a.MEMBER,x:g,r:h};else{if(!e.getStringMatch("("))break;if(e.allowWhitespace(),i=c(e),e.allowWhitespace(),!e.getStringMatch(")")){e.pos=f;break}g={t:a.INVOCATION,x:g},i&&(g.o=i)}return g}}(k,Tc,Oc,Uc),Wc=function(a,b){var c,d;return d=function(b,c){return function(d){var e,f;return d.getStringMatch(b)?(e=d.pos,d.allowWhitespace(),f=d.getExpression(),f||d.expected("an expression"),{s:b,o:f,t:a.PREFIX_OPERATOR}):c(d)}},function(){var a,e,f,g,h;for(g="! ~ + - typeof".split(" "),h=b,a=0,e=g.length;e>a;a+=1)f=d(g[a],h),h=f;c=h}(),c}(k,Vc),Xc=function(a,b){var c,d;return d=function(b,c){return function(d){var e,f,g;return(f=c(d))?(e=d.pos,d.allowWhitespace(),d.getStringMatch(b)?"in"===b&&/[a-zA-Z_$0-9]/.test(d.remaining().charAt(0))?(d.pos=e,f):(d.allowWhitespace(),g=d.getExpression(),g?{t:a.INFIX_OPERATOR,s:b,o:[f,g]}:(d.pos=e,f)):(d.pos=e,f)):null}},function(){var a,e,f,g,h;for(g="* / % + - << >> >>> < <= > >= in instanceof == != === !== & ^ | && ||".split(" "),h=b,a=0,e=g.length;e>a;a+=1)f=d(g[a],h),h=f;c=h}(),c}(k,Wc),Yc=function(a,b){return function(c){var d,e,f,g;return(e=b(c))?(d=c.pos,c.allowWhitespace(),c.getStringMatch("?")?(c.allowWhitespace(),(f=c.getExpression())?(c.allowWhitespace(),c.getStringMatch(":")?(c.allowWhitespace(),g=c.getExpression(),g?{t:a.CONDITIONAL,o:[e,f,g]}:(c.pos=d,e)):(c.pos=d,e)):(c.pos=d,e)):(c.pos=d,e)):null}}(k,Xc),Zc=function(a){return function(){return a(this)}}(Yc),$c=function(a,b,c,d,e,f,g){var h;return h=function(a,b){var c;for(this.str=a,this.pos=0,this.delimiters=b.delimiters,this.tripleDelimiters=b.tripleDelimiters,this.tokens=[];this.pos"+b)},expected:function(a){var b=this.remaining().substr(0,40);throw 40===b.length&&(b+="..."),new Error('Tokenizer failed: unexpected string "'+b+'" (expected '+a+")")}},h}(Fc,Gc,Ic,Jc,Zc,Pb,Ob),_c=function(a,b,c,d,e){var f,g;return e.push(function(){g=e.Ractive}),f=function(e,f){var h,i;return f=f||{},f.stripComments!==!1&&(e=a(e)),h=new d(e,{delimiters:f.delimiters||(g?g.delimiters:["{{","}}"]),tripleDelimiters:f.tripleDelimiters||(g?g.tripleDelimiters:["{{{","}}}"])}),i=h.tokens,b(i),c(i),i}}(zc,Ac,Bc,$c,Eb),ad=function(a){var b,c,d,e,f,g,h,i,j;return b=function(a,b){this.text=b?a.value:a.value.replace(j," ")},b.prototype={type:a.TEXT,toJSON:function(){return this.decoded||(this.decoded=i(this.text))},toString:function(){return this.text}},c={quot:34,amp:38,apos:39,lt:60,gt:62,nbsp:160,iexcl:161,cent:162,pound:163,curren:164,yen:165,brvbar:166,sect:167,uml:168,copy:169,ordf:170,laquo:171,not:172,shy:173,reg:174,macr:175,deg:176,plusmn:177,sup2:178,sup3:179,acute:180,micro:181,para:182,middot:183,cedil:184,sup1:185,ordm:186,raquo:187,frac14:188,frac12:189,frac34:190,iquest:191,Agrave:192,Aacute:193,Acirc:194,Atilde:195,Auml:196,Aring:197,AElig:198,Ccedil:199,Egrave:200,Eacute:201,Ecirc:202,Euml:203,Igrave:204,Iacute:205,Icirc:206,Iuml:207,ETH:208,Ntilde:209,Ograve:210,Oacute:211,Ocirc:212,Otilde:213,Ouml:214,times:215,Oslash:216,Ugrave:217,Uacute:218,Ucirc:219,Uuml:220,Yacute:221,THORN:222,szlig:223,agrave:224,aacute:225,acirc:226,atilde:227,auml:228,aring:229,aelig:230,ccedil:231,egrave:232,eacute:233,ecirc:234,euml:235,igrave:236,iacute:237,icirc:238,iuml:239,eth:240,ntilde:241,ograve:242,oacute:243,ocirc:244,otilde:245,ouml:246,divide:247,oslash:248,ugrave:249,uacute:250,ucirc:251,uuml:252,yacute:253,thorn:254,yuml:255,OElig:338,oelig:339,Scaron:352,scaron:353,Yuml:376,fnof:402,circ:710,tilde:732,Alpha:913,Beta:914,Gamma:915,Delta:916,Epsilon:917,Zeta:918,Eta:919,Theta:920,Iota:921,Kappa:922,Lambda:923,Mu:924,Nu:925,Xi:926,Omicron:927,Pi:928,Rho:929,Sigma:931,Tau:932,Upsilon:933,Phi:934,Chi:935,Psi:936,Omega:937,alpha:945,beta:946,gamma:947,delta:948,epsilon:949,zeta:950,eta:951,theta:952,iota:953,kappa:954,lambda:955,mu:956,nu:957,xi:958,omicron:959,pi:960,rho:961,sigmaf:962,sigma:963,tau:964,upsilon:965,phi:966,chi:967,psi:968,omega:969,thetasym:977,upsih:978,piv:982,ensp:8194,emsp:8195,thinsp:8201,zwnj:8204,zwj:8205,lrm:8206,rlm:8207,ndash:8211,mdash:8212,lsquo:8216,rsquo:8217,sbquo:8218,ldquo:8220,rdquo:8221,bdquo:8222,dagger:8224,Dagger:8225,bull:8226,hellip:8230,permil:8240,prime:8242,Prime:8243,lsaquo:8249,rsaquo:8250,oline:8254,frasl:8260,euro:8364,image:8465,weierp:8472,real:8476,trade:8482,alefsym:8501,larr:8592,uarr:8593,rarr:8594,darr:8595,harr:8596,crarr:8629,lArr:8656,uArr:8657,rArr:8658,dArr:8659,hArr:8660,forall:8704,part:8706,exist:8707,empty:8709,nabla:8711,isin:8712,notin:8713,ni:8715,prod:8719,sum:8721,minus:8722,lowast:8727,radic:8730,prop:8733,infin:8734,ang:8736,and:8743,or:8744,cap:8745,cup:8746,"int":8747,there4:8756,sim:8764,cong:8773,asymp:8776,ne:8800,equiv:8801,le:8804,ge:8805,sub:8834,sup:8835,nsub:8836,sube:8838,supe:8839,oplus:8853,otimes:8855,perp:8869,sdot:8901,lceil:8968,rceil:8969,lfloor:8970,rfloor:8971,lang:9001,rang:9002,loz:9674,spades:9824,clubs:9827,hearts:9829,diams:9830},d=[8364,129,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,141,381,143,144,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,157,382,376],e=new RegExp("&("+Object.keys(c).join("|")+");?","g"),f=/([0-9]+);?/g,g=/([0-9]+);?/g,h=function(a){return a?10===a?32:128>a?a:159>=a?d[a-128]:55296>a?a:57343>=a?65533:65535>=a?a:65533:65533},i=function(a){var b;return b=a.replace(e,function(a,b){return c[b]?String.fromCharCode(c[b]):a}),b=b.replace(f,function(a,b){return String.fromCharCode(h(parseInt(b,16)))}),b=b.replace(g,function(a,b){return String.fromCharCode(h(b))})},j=/\s+/g,b}(k),bd=function(a,b){return function(c){return c.type===a.TEXT?(this.pos+=1,new b(c,this.preserveWhitespace)):null}}(k,ad),cd=function(a){var b;return b=function(a){this.content=a.content},b.prototype={toJSON:function(){return{t:a.COMMENT,f:this.content}},toString:function(){return""}},b}(k),dd=function(a,b){return function(c){return c.type===a.COMMENT?(this.pos+=1,new b(c,this.preserveWhitespace)):null}}(k,cd),ed=function(a,b){var c,d,e;return c=function(a){this.refs=[],d(a,this.refs),this.str=e(a,this.refs)},c.prototype={toJSON:function(){return this.json?this.json:(this.json={r:this.refs,s:this.str},this.json)}},d=function(c,e){var f,g;if(c.t===a.REFERENCE&&-1===e.indexOf(c.n)&&e.unshift(c.n),g=c.o||c.m)if(b(g))d(g,e);else for(f=g.length;f--;)d(g[f],e);c.x&&d(c.x,e),c.r&&d(c.r,e),c.v&&d(c.v,e)},e=function(b,c){var d=function(a){return e(a,c)};switch(b.t){case a.BOOLEAN_LITERAL:case a.GLOBAL:case a.NUMBER_LITERAL:return b.v;case a.STRING_LITERAL:return"'"+b.v.replace(/'/g,"\\'")+"'";case a.ARRAY_LITERAL:return"["+(b.m?b.m.map(d).join(","):"")+"]";case a.OBJECT_LITERAL:return"{"+(b.m?b.m.map(d).join(","):"")+"}";case a.KEY_VALUE_PAIR:return b.k+":"+e(b.v,c);case a.PREFIX_OPERATOR:return("typeof"===b.s?"typeof ":b.s)+e(b.o,c);case a.INFIX_OPERATOR:return e(b.o[0],c)+("in"===b.s.substr(0,2)?" "+b.s+" ":b.s)+e(b.o[1],c);case a.INVOCATION:return e(b.x,c)+"("+(b.o?b.o.map(d).join(","):"")+")";case a.BRACKETED:return"("+e(b.x,c)+")";case a.MEMBER:return e(b.x,c)+e(b.r,c);case a.REFINEMENT:return b.n?"."+b.n:"["+e(b.x,c)+"]";case a.CONDITIONAL:return e(b.o[0],c)+"?"+e(b.o[1],c)+":"+e(b.o[2],c);case a.REFERENCE:return"${"+c.indexOf(b.n)+"}";default:throw new Error("Could not stringify expression token. This error is unexpected")}},c}(k,w),fd=function(a,b){var c=function(c,d){this.type=c.type===a.TRIPLE?a.TRIPLE:c.mustacheType,c.ref&&(this.ref=c.ref),c.expression&&(this.expr=new b(c.expression)),d.pos+=1};return c.prototype={toJSON:function(){var a;return this.json?this.json:(a={t:this.type},this.ref&&(a.r=this.ref),this.expr&&(a.x=this.expr.toJSON()),this.json=a,a)},toString:function(){return!1}},c}(k,ed),gd=function(){return function(a){var b,c,d,e="";if(!a)return"";for(c=0,d=a.length;d>c;c+=1){if(b=a[c].toString(),b===!1)return!1;e+=b}return e}}(),hd=function(a){return function(b,c){var d,e;return c||(d=a(b),d===!1)?e=b.map(function(a){return a.toJSON(c)}):d}}(gd),id=function(a,b,c){var d=function(b,d){var e;for(this.ref=b.ref,this.indexRef=b.indexRef,this.inverted=b.mustacheType===a.INVERTED,b.expression&&(this.expr=new c(b.expression)),d.pos+=1,this.items=[],e=d.next();e;){if(e.mustacheType===a.CLOSING){if(e.ref.trim()===this.ref||this.expr){d.pos+=1;break}throw new Error("Could not parse template: Illegal closing section")}this.items[this.items.length]=d.getStub(),e=d.next()}};return d.prototype={toJSON:function(c){var d;return this.json?this.json:(d={t:a.SECTION},this.ref&&(d.r=this.ref),this.indexRef&&(d.i=this.indexRef),this.inverted&&(d.n=!0),this.expr&&(d.x=this.expr.toJSON()),this.items.length&&(d.f=b(this.items,c)),this.json=d,d)},toString:function(){return!1}},d}(k,hd,ed),jd=function(a,b,c){return function(d){return d.type===a.MUSTACHE||d.type===a.TRIPLE?d.mustacheType===a.SECTION||d.mustacheType===a.INVERTED?new c(d,this):new b(d,this):void 0}}(k,fd,id),kd=function(){return{li:["li"],dt:["dt","dd"],dd:["dt","dd"],p:"address article aside blockquote dir div dl fieldset footer form h1 h2 h3 h4 h5 h6 header hgroup hr menu nav ol p pre section table ul".split(" "),rt:["rt","rp"],rp:["rp","rt"],optgroup:["optgroup"],option:["option","optgroup"],thead:["tbody","tfoot"],tbody:["tbody","tfoot"],tr:["tr"],td:["td","th"],th:["td","th"]}}(),ld=function(a){function b(c){var d,e;if("object"!=typeof c)return c;if(a(c))return c.map(b);d={};for(e in c)c.hasOwnProperty(e)&&(d[e]=b(c[e]));return d}return function(a){var c,d,e,f,g,h;for(e={},c=[],d=[],g=a.length,f=0;g>f;f+=1)if(h=a[f],"intro"===h.name){if(e.intro)throw new Error("An element can only have one intro transition"); -e.intro=h}else if("outro"===h.name){if(e.outro)throw new Error("An element can only have one outro transition");e.outro=h}else if("intro-outro"===h.name){if(e.intro||e.outro)throw new Error("An element can only have one intro and one outro transition");e.intro=h,e.outro=b(h)}else"proxy-"===h.name.substr(0,6)?(h.name=h.name.substring(6),d[d.length]=h):"on-"===h.name.substr(0,3)?(h.name=h.name.substring(3),d[d.length]=h):"decorator"===h.name?e.decorator=h:c[c.length]=h;return e.attrs=c,e.proxies=d,e}}(l),md=function(a,b){return function(c){var d,e,f,g,h,i,j,k;for(h=function(){throw new Error("Illegal directive")},c.name&&c.value||h(),d={directiveType:c.name},e=c.value,i=[],j=[];e.length;)if(f=e.shift(),f.type===a.TEXT){if(g=f.value.indexOf(":"),-1!==g){g&&(i[i.length]={type:a.TEXT,value:f.value.substr(0,g)}),f.value.length>g+1&&(j[0]={type:a.TEXT,value:f.value.substring(g+1)});break}i[i.length]=f}else i[i.length]=f;return j=j.concat(e),d.name=1===i.length&&i[0].type===a.TEXT?i[0].value:i,j.length&&(1===j.length&&j[0].type===a.TEXT?(k=b("["+j[0].value+"]"),d.args=k?k.value:j[0].value):d.dynamicArgs=j),d}}(k,Xb),nd=function(a,b){var c;return c=function(a,b){var c;for(this.tokens=a||[],this.pos=0,this.options=b,this.result=[];c=this.getStub();)this.result.push(c)},c.prototype={getStub:function(){var a=this.next();return a?this.getText(a)||this.getMustache(a):null},getText:a,getMustache:b,next:function(){return this.tokens[this.pos]}},c}(bd,jd),od=function(a,b,c){var d;return d=function(b){var c=new a(b);this.stubs=c.result},d.prototype={toJSON:function(a){var b;return this["json_"+a]?this["json_"+a]:b=this["json_"+a]=c(this.stubs,a)},toString:function(){return void 0!==this.str?this.str:(this.str=b(this.stubs),this.str)}},d}(nd,gd,hd),pd=function(a){return function(b){var c,d;if("string"==typeof b.name){if(!b.args&&!b.dynamicArgs)return b.name;d=b.name}else d=new a(b.name).toJSON();return c={n:d},b.args?(c.a=b.args,c):(b.dynamicArgs&&(c.d=new a(b.dynamicArgs).toJSON()),c)}}(od),qd=function(a,b,c){return function(d){var e,f,g,h,i,j,k;if(this["json_"+d])return this["json_"+d];if(e=this.component?{t:a.COMPONENT,e:this.component}:{t:a.ELEMENT,e:this.tag},this.doctype&&(e.y=1),this.attributes&&this.attributes.length)for(e.a={},j=this.attributes.length,i=0;j>i;i+=1){if(k=this.attributes[i],f=k.name,e.a[f])throw new Error("You cannot have multiple attributes with the same name");g=null===k.value?null:k.value.toJSON(d),e.a[f]=g}if(this.items&&this.items.length&&(e.f=b(this.items,d)),this.proxies&&this.proxies.length)for(e.v={},j=this.proxies.length,i=0;j>i;i+=1)h=this.proxies[i],e.v[h.directiveType]=c(h);return this.intro&&(e.t1=c(this.intro)),this.outro&&(e.t2=c(this.outro)),this.decorator&&(e.o=c(this.decorator)),this["json_"+d]=e,e}}(k,hd,pd),rd=function(a,b){var c;return c="a abbr acronym address applet area b base basefont bdo big blockquote body br button caption center cite code col colgroup dd del dfn dir div dl dt em fieldset font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img input ins isindex kbd label legend li link map menu meta noframes noscript object ol p param pre q s samp script select small span strike strong style sub sup textarea title tt u ul var article aside audio bdi canvas command data datagrid datalist details embed eventsource figcaption figure footer header hgroup keygen mark meter nav output progress ruby rp rt section source summary time track video wbr".split(" "),function(){var d,e,f,g,h,i,j,k;if(void 0!==this.str)return this.str;if(this.component)return this.str=!1;if(-1===c.indexOf(this.tag.toLowerCase()))return this.str=!1;if(this.proxies||this.intro||this.outro||this.decorator)return this.str=!1;if(j=a(this.items),j===!1)return this.str=!1;if(k=-1!==b.indexOf(this.tag.toLowerCase()),d="<"+this.tag,this.attributes)for(e=0,f=this.attributes.length;f>e;e+=1){if(h=this.attributes[e].name,-1!==h.indexOf(":"))return this.str=!1;if("id"===h||"intro"===h||"outro"===h)return this.str=!1;if(g=" "+h,null!==this.attributes[e].value){if(i=this.attributes[e].value.toString(),i===!1)return this.str=!1;""!==i&&(g+="=",g+=/[\s"'=<>`]/.test(i)?'"'+i.replace(/"/g,""")+'"':i)}d+=g}return this.selfClosing&&!k?(d+="/>",this.str=d):(d+=">",k?this.str=d:(d+=j,d+=""+this.tag+">",this.str=d))}}(gd,pc),sd=function(a,b,c,d,e,f,g,h,i,j,k){var l,m,n,o,p,q=/^\s+/,r=/\s+$/;return l=function(d,e,i){var j,l,m,n,o,s,t;if(e.pos+=1,s=function(a){return{name:a.name,value:a.value?new k(a.value):null}},this.tag=d.name,t=d.name.toLowerCase(),"rv-"===t.substr(0,3)&&(c('The "rv-" prefix for components has been deprecated. Support will be removed in a future version'),this.tag=this.tag.substring(3)),i=i||"pre"===t,d.attrs&&(m=g(d.attrs),l=m.attrs,n=m.proxies,e.options.sanitize&&e.options.sanitize.eventAttributes&&(l=l.filter(p)),l.length&&(this.attributes=l.map(s)),n.length&&(this.proxies=n.map(h)),m.intro&&(this.intro=h(m.intro)),m.outro&&(this.outro=h(m.outro)),m.decorator&&(this.decorator=h(m.decorator))),d.doctype&&(this.doctype=!0),d.selfClosing&&(this.selfClosing=!0),-1!==b.indexOf(t)&&(this.isVoid=!0),!this.selfClosing&&!this.isVoid){for(this.siblings=f[t],this.items=[],j=e.next();j&&j.mustacheType!==a.CLOSING;){if(j.type===a.TAG){if(j.closing){j.name.toLowerCase()===t&&(e.pos+=1);break}if(this.siblings&&-1!==this.siblings.indexOf(j.name.toLowerCase()))break}this.items[this.items.length]=e.getStub(),j=e.next()}i||(o=this.items[0],o&&o.type===a.TEXT&&(o.text=o.text.replace(q,""),o.text||this.items.shift()),o=this.items[this.items.length-1],o&&o.type===a.TEXT&&(o.text=o.text.replace(r,""),o.text||this.items.pop()))}},l.prototype={toJSON:i,toString:j},m="a abbr acronym address applet area b base basefont bdo big blockquote body br button caption center cite code col colgroup dd del dfn dir div dl dt em fieldset font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img input ins isindex kbd label legend li link map menu meta noframes noscript object ol p param pre q s samp script select small span strike strong style sub sup textarea title tt u ul var article aside audio bdi canvas command data datagrid datalist details embed eventsource figcaption figure footer header hgroup keygen mark meter nav output progress ruby rp rt section source summary time track video wbr".split(" "),n="li dd rt rp optgroup option tbody tfoot tr td th".split(" "),o=/^on[a-zA-Z]/,p=function(a){var b=!o.test(a.name);return b},l}(k,pc,I,jc,gd,kd,ld,md,qd,rd,od),td=function(a,b){return function(a){return this.options.sanitize&&this.options.sanitize.elements&&-1!==this.options.sanitize.elements.indexOf(a.name.toLowerCase())?null:new b(a,this)}}(k,sd),ud=function(a,b,c,d,e){var f;return f=function(a,b){var c,d;for(this.tokens=a||[],this.pos=0,this.options=b,this.preserveWhitespace=b.preserveWhitespace,d=[];c=this.getStub();)d.push(c);this.result=e(d)},f.prototype={getStub:function(){var a=this.next();return a?this.getText(a)||this.getComment(a)||this.getMustache(a)||this.getElement(a):null},getText:a,getComment:b,getMustache:c,getElement:d,next:function(){return this.tokens[this.pos]}},f}(bd,dd,jd,td,hd),vd=function(a,b,c){var d,e,f,g,h;return e=/^\s*$/,f=//,g=//,d=function(d,g){var i,j,k;return g=g||{},f.test(d)?h(d,g):(g.sanitize===!0&&(g.sanitize={elements:"applet base basefont body frame frameset head html isindex link meta noframes noscript object param script style title".split(" "),eventAttributes:!0}),i=a(d,g),g.preserveWhitespace||(k=i[0],k&&k.type===b.TEXT&&e.test(k.value)&&i.shift(),k=i[i.length-1],k&&k.type===b.TEXT&&e.test(k.value)&&i.pop()),j=new c(i,g).result,"string"==typeof j?[j]:j)},h=function(a,b){var c,e,h,i,j,k;for(h={},c="",e=a;j=f.exec(e);){if(i=j[1],c+=e.substr(0,j.index),e=e.substring(j.index+j[0].length),k=g.exec(e),!k||k[1]!==i)throw new Error("Inline partials must have a closing delimiter, and cannot be nested");h[i]=d(e.substr(0,k.index),b),e=e.substring(k.index+k[0].length)}return{main:d(c,b),partials:h}},d}(_c,k,ud),wd=function(a,b,c,d,e,f){var g,h,i,j;return g=function(d,g){var k,l,m;if(l=i(d,g))return l;if(b&&(k=document.getElementById(g),k&&"SCRIPT"===k.tagName)){if(!f)throw new Error(a.missingParser);h(f(k.innerHTML),g,e)}if(l=e[g],!l){if(m='Could not find descriptor for partial "'+g+'"',d.debug)throw new Error(m);return c(m),[]}return j(l)},i=function(b,c){var d;if(b.partials[c]){if("string"==typeof b.partials[c]){if(!f)throw new Error(a.missingParser);d=f(b.partials[c],b.parseOptions),h(d,c,b.partials)}return j(b.partials[c])}},h=function(a,b,c){var e;if(d(a)){c[b]=a.main;for(e in a.partials)a.partials.hasOwnProperty(e)&&(c[e]=a.partials[e])}else c[b]=a},j=function(a){return 1===a.length&&"string"==typeof a[0]?a[0]:a},g}(xc,f,I,w,yc,vd),xd=function(a,b,c){var d,e;return c.push(function(){e=c.DomFragment}),d=function(c,d){var f,g=this.parentFragment=c.parentFragment;if(this.type=a.PARTIAL,this.name=c.descriptor.r,this.index=c.index,!c.descriptor.r)throw new Error("Partials must have a static reference (no expressions). This may change in a future version of Ractive.");f=b(g.root,c.descriptor.r),this.fragment=new e({descriptor:f,root:g.root,pNode:g.pNode,contextStack:g.contextStack,owner:this}),d&&d.appendChild(this.fragment.docFrag)},d.prototype={firstNode:function(){return this.fragment.firstNode()},findNextNode:function(){return this.parentFragment.findNextNode(this)},detach:function(){return this.fragment.detach()},teardown:function(a){this.fragment.teardown(a)},toString:function(){return this.fragment.toString()},find:function(a){return this.fragment.find(a)},findAll:function(a,b){return this.fragment.findAll(a,b)},findComponent:function(a){return this.fragment.findComponent(a)},findAllComponents:function(a,b){return this.fragment.findAllComponents(a,b)}},d}(k,wd,Eb),yd=function(a){var b=function(b,c,d){this.parentFragment=b.parentFragment,this.component=b,this.key=c,this.fragment=new a({descriptor:d,root:b.root,owner:this,contextStack:b.parentFragment.contextStack}),this.selfUpdating=this.fragment.isSimple(),this.value=this.fragment.getValue()};return b.prototype={bubble:function(){this.selfUpdating?this.update():!this.deferred&&this.ready&&(this.root._deferred.attrs.push(this),this.deferred=!0)},update:function(){var a=this.fragment.getValue();this.component.instance.set(this.key,a),this.value=a},teardown:function(){this.fragment.teardown()}},b}(ac),zd=function(a,b,c,d){function e(e,f,g,h){var i,j,k,l,m;return k=e.root,l=e.parentFragment,"string"==typeof g?(j=b(g),j?j.value:g):null===g?!0:1===g.length&&g[0].t===a.INTERPOLATOR&&g[0].r?l.indexRefs&&void 0!==l.indexRefs[g[0].r]?l.indexRefs[g[0].r]:(m=c(k,g[0].r,l.contextStack)||g[0].r,h.push({childKeypath:f,parentKeypath:m}),k.get(m)):(i=new d(e,f,g),e.complexParameters.push(i),i.value)}return function(a,b,c){var d,f,g;d={},a.complexParameters=[];for(f in b)b.hasOwnProperty(f)&&(g=e(a,f,b[f],c),void 0!==g&&(d[f]=g));return d}}(k,Xb,y,yd),Ad=function(){return function(a,b,c,d,e){var f,g,h,i;return g=a.parentFragment,i=a.root,h={content:e||[]},f=new b({el:g.pNode.cloneNode(!1),data:c,partials:h,_parent:i,adaptors:i.adaptors}),f.component=a,a.instance=f,f.insert(d),f.fragment.pNode=g.pNode,f}}(),Bd=function(){function a(a,c,d){var e,f,g,h,i,j,k;e=a.root,f=a.instance,i=a.observers,j=e.observe(c,function(a){g||e._wrapped[c]||(h=!0,f.set(d,a),h=!1)},b),i.push(j),f.twoway&&(j=f.observe(d,function(a){h||(g=!0,e.set(c,a),g=!1)},b),i.push(j),k=f.get(d),void 0!==k&&e.set(c,k))}var b={init:!1,debug:!0};return function(b,c){var d,e;for(b.observers=[],e=c.length;e--;)d=c[e],a(b,d.parentKeypath,d.childKeypath)}}(),Cd=function(a){function b(b,d,e,f){if("string"!=typeof f){if(d.debug)throw new Error(c);return a(c),void 0}b.on(e,function(){var a=Array.prototype.slice.call(arguments);a.unshift(f),d.fire.apply(d,a)})}var c="Components currently only support simple events - you cannot include arguments. Sorry!";return function(a,c){var d;for(d in c)c.hasOwnProperty(d)&&b(a.instance,a.root,d,c[d])}}(I),Dd=function(){return function(a){var b,c;for(b=a.root;b;)(c=b._liveComponentQueries[a.name])&&c.push(a.instance),b=b._parent}}(),Ed=function(a,b,c,d,e,f,g){return function(h,i,j){var k,l,m,n,o;if(k=h.parentFragment=i.parentFragment,l=k.root,h.root=l,h.type=a.COMPONENT,h.name=i.descriptor.e,h.index=i.index,h.observers=[],m=l.components[i.descriptor.e],!m)throw new Error('Component "'+i.descriptor.e+'" not found');o=[],n=c(h,i.descriptor.a,o),d(h,m,n,j,i.descriptor.f),e(h,o),f(h,i.descriptor.v),(i.descriptor.t1||i.descriptor.t2||i.descriptor.o)&&b('The "intro", "outro" and "decorator" directives have no effect on components'),g(h)}}(k,I,zd,Ad,Bd,Cd,Dd),Fd=function(a){var b=function(b,c){a(this,b,c)};return b.prototype={firstNode:function(){return this.instance.fragment.firstNode()},findNextNode:function(){return this.parentFragment.findNextNode(this)},detach:function(){return this.instance.fragment.detach()},teardown:function(){for(var a;this.complexParameters.length;)this.complexParameters.pop().teardown();for(;this.observers.length;)this.observers.pop().cancel();(a=this.root._liveComponentQueries[this.name])&&a._remove(this),this.instance.teardown()},toString:function(){return this.instance.fragment.toString()},find:function(a){return this.instance.fragment.find(a)},findAll:function(a,b){return this.instance.fragment.findAll(a,b)},findComponent:function(a){return a&&a!==this.name?null:this.instance},findAllComponents:function(a,b){b._test(this,!0),this.instance.fragment&&this.instance.fragment.findAllComponents(a,b)}},b}(Ed),Gd=function(a){var b=function(b,c){this.type=a.COMMENT,this.descriptor=b.descriptor,c&&(this.node=document.createComment(b.descriptor.f),c.appendChild(this.node))};return b.prototype={detach:function(){return this.node.parentNode.removeChild(this.node),this.node},teardown:function(a){a&&this.detach()},firstNode:function(){return this.node},toString:function(){return""}},b}(k),Hd=function(a,b,c,d,e,f,g,h,i,j,k,l,m){var n=function(a){a.pNode&&(this.docFrag=document.createDocumentFragment()),"string"==typeof a.descriptor?(this.html=a.descriptor,this.docFrag&&(this.nodes=d(this.html,a.pNode.tagName,this.docFrag))):c(this,a)};return n.prototype={detach:function(){var a,b;if(this.nodes)for(b=this.nodes.length;b--;)this.docFrag.appendChild(this.nodes[b]);else if(this.items)for(a=this.items.length,b=0;a>b;b+=1)this.docFrag.appendChild(this.items[b].detach());return this.docFrag},createItem:function(b){if("string"==typeof b.descriptor)return new e(b,this.docFrag);switch(b.descriptor.t){case a.INTERPOLATOR:return new f(b,this.docFrag);case a.SECTION:return new g(b,this.docFrag);case a.TRIPLE:return new h(b,this.docFrag);case a.ELEMENT:return this.root.components[b.descriptor.e]?new k(b,this.docFrag):new i(b,this.docFrag);case a.PARTIAL:return new j(b,this.docFrag);case a.COMMENT:return new l(b,this.docFrag);default:throw new Error("Something very strange happened. Please file an issue at https://github.com/RactiveJS/Ractive/issues. Thanks!")}},teardown:function(a){var b;if(this.nodes&&a)for(;b=this.nodes.pop();)b.parentNode.removeChild(b);else if(this.items)for(;this.items.length;)this.items.pop().teardown(a);this.nodes=this.items=this.docFrag=null},firstNode:function(){return this.items&&this.items[0]?this.items[0].firstNode():this.nodes?this.nodes[0]||null:null},findNextNode:function(a){var b=a.index;return this.items[b+1]?this.items[b+1].firstNode():this.owner===this.root?this.owner.component?this.owner.component.findNextNode():null:this.owner.findNextNode(this)},toString:function(){var a,b,c,d;if(this.html)return this.html;if(a="",!this.items)return a;for(c=this.items.length,b=0;c>b;b+=1)d=this.items[b],a+=d.toString();return a},find:function(a){var c,d,e,f,g;if(this.nodes){for(d=this.nodes.length,c=0;d>c;c+=1)if(f=this.nodes[c],1===f.nodeType){if(b(f,a))return f;if(g=f.querySelector(a))return g}return null}if(this.items){for(d=this.items.length,c=0;d>c;c+=1)if(e=this.items[c],e.find&&(g=e.find(a)))return g;return null}},findAll:function(a,c){var d,e,f,g,h,i,j;if(this.nodes){for(e=this.nodes.length,d=0;e>d;d+=1)if(g=this.nodes[d],1===g.nodeType&&(b(g,a)&&c.push(g),h=g.querySelectorAll(a)))for(i=h.length,j=0;i>j;j+=1)c.push(h[j])}else if(this.items)for(e=this.items.length,d=0;e>d;d+=1)f=this.items[d],f.findAll&&f.findAll(a,c);return c},findComponent:function(a){var b,c,d,e;if(this.items){for(b=this.items.length,c=0;b>c;c+=1)if(d=this.items[c],d.findComponent&&(e=d.findComponent(a)))return e;return null}},findAllComponents:function(a,b){var c,d,e;if(this.items)for(d=this.items.length,c=0;d>c;c+=1)e=this.items[c],e.findAllComponents&&e.findAllComponents(a,b);return b}},m.DomFragment=n,n}(k,Z,kb,lb,mb,zb,Fb,Gb,wc,xd,Fd,Gd,Eb),Id=function(a,b,c,d,e){return function(a,f){var g;if(!this._initing)throw new Error("You cannot call ractive.render() directly!");this._transitionManager=g=b(this,f),this.fragment=new e({descriptor:this.template,root:this,owner:this,pNode:a}),c(this),a&&a.appendChild(this.fragment.docFrag),d(this),this._transitionManager=null,g.ready(),this.rendered=!0}}(jb,q,o,p,Hd),Jd=function(a){return function(){return a("renderHTML() has been deprecated and will be removed in a future version. Please use toHTML() instead"),this.toHTML()}}(I),Kd=function(){return function(){return this.fragment.toString()}}(),Ld=function(a,b){return function(c){var d,e,f;for(this.fire("teardown"),f=this._transitionManager,this._transitionManager=e=a(this,c),this.fragment.teardown(!0);this._animations[0];)this._animations[0].stop();for(d in this._cache)b(this,d);this._transitionManager=f,e.ready()}}(q,m),Md=function(a){return function(b,c,d){var e;if("string"==typeof c&&a(d)){if(e=b.get(c),void 0===e&&(e=0),a(e))b.set(c,e+d);else if(b.debug)throw new Error("Cannot add to a non-numeric value")}else if(b.debug)throw new Error("Bad arguments")}}(J),Nd=function(a){return function(b,c){a(this,b,void 0===c?1:c)}}(Md),Od=function(a){return function(b,c){a(this,b,void 0===c?-1:-c)}}(Md),Pd=function(){return function(a){var b;if("string"==typeof a)b=this.get(a),this.set(a,!b);else if(this.debug)throw new Error("Bad arguments")}}(),Qd=function(){return function(a,b){var c,d,e,f,g;return c={},e=0,d=function(a,d){var f,h,i;h=e,i=b.length;do{if(f=b.indexOf(a,h),-1===f)return g=!0,-1;h=f+1}while(c[f]&&i>h);return f===e&&(e+=1),f!==d&&(g=!0),c[f]=!0,f},f=a.map(d),f.unchanged=!g,f}}(),Rd=function(a){return function(b,c,d,e){var f,g;for(f=c.length;f--;)g=c[f],g.type===a.REFERENCE?g.update():g.keypath===b&&g.type===a.SECTION&&!g.inverted&&g.docFrag?d[d.length]=g:e[e.length]=g}}(k),Sd=function(a,b,c,d,e,f,g,h,i,j){function k(a){return JSON.stringify(a)}function l(a){return m[a]||(m[a]=function(b){return b[a]}),m[a]}var m={};return function(m,n,o){var p,q,r,s,t,u,v,w,x,y,z,A,B,C,D;if(p=this.get(m),!b(p)||!b(n))return this.set(m,n,o&&o.complete);if(t=p.length===n.length,o&&o.compare){if(o.compare===!0)s=k;else if("string"==typeof o.compare)s=l(o.compare);else{if("function"!=typeof o.compare)throw new Error("The `compare` option must be a function, or a string representing an identifying field (or `true` to use JSON.stringify)");s=o.compare}try{q=p.map(s),r=n.map(s)}catch(E){if(this.debug)throw E;a("Merge operation: comparison failed. Falling back to identity checking"),q=p,r=n}}else q=p,r=n;if(v=i(q,r),c(this,m),h(this,m,n),!v.unchanged||!t){for(B=this._transitionManager,this._transitionManager=A=f(this,o&&o.complete),w=[],x=[],u=0;u 2 && args[1]) { - changed = Math.min(args[1], args.length - 2); - start = args[0]; - end = start + changed; - if (args[1] === args.length - 2) { - lengthUnchanged = true; - } - for (i = start; i < end; i += 1) { - childKeypath = keypath + '.' + i; - notifyDependants(root, childKeypath); - } - } - preDomUpdate(root); - upstreamQueue = []; - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - upstreamQueue[upstreamQueue.length] = keys.join('.'); - } - notifyDependants.multiple(root, upstreamQueue, true); - if (!lengthUnchanged) { - notifyDependants(root, keypath + '.length', true); - } - }; - queueDependants = function (keypath, deps, smartUpdateQueue, dumbUpdateQueue) { - var k, dependant; - k = deps.length; - while (k--) { - dependant = deps[k]; - if (dependant.type === types.REFERENCE) { - dependant.update(); - } else if (dependant.keypath === keypath && dependant.type === types.SECTION && !dependant.inverted && dependant.docFrag) { - smartUpdateQueue[smartUpdateQueue.length] = dependant; - } else { - dumbUpdateQueue[dumbUpdateQueue.length] = dependant; - } - } - }; - wrappers = array._ractive.wrappers; - i = wrappers.length; - while (i--) { - wrapper = wrappers[i]; - notifyKeypathDependants(wrapper.root, wrapper.keypath); - } - }; - patchedArrayProto = []; - mutatorMethods = [ - 'pop', - 'push', - 'reverse', - 'shift', - 'sort', - 'splice', - 'unshift' - ]; - noop = function () { - }; - mutatorMethods.forEach(function (methodName) { - var method = function () { - var result, instances, instance, i, previousTransitionManagers = {}, transitionManagers = {}; - result = Array.prototype[methodName].apply(this, arguments); - instances = this._ractive.instances; - i = instances.length; - while (i--) { - instance = instances[i]; - previousTransitionManagers[instance._guid] = instance._transitionManager; - instance._transitionManager = transitionManagers[instance._guid] = makeTransitionManager(instance, noop); - } - this._ractive.setting = true; - notifyArrayDependants(this, methodName, arguments); - this._ractive.setting = false; - i = instances.length; - while (i--) { - instance = instances[i]; - instance._transitionManager = previousTransitionManagers[instance._guid]; - transitionManagers[instance._guid].ready(); - preDomUpdate(instance); - postDomUpdate(instance); - } - return result; - }; - defineProperty(patchedArrayProto, methodName, { value: method }); - }); - testObj = {}; - if (testObj.__proto__) { - patchArrayMethods = function (array) { - array.__proto__ = patchedArrayProto; - }; - unpatchArrayMethods = function (array) { - array.__proto__ = Array.prototype; - }; - } else { - patchArrayMethods = function (array) { - var i, methodName; - i = mutatorMethods.length; - while (i--) { - methodName = mutatorMethods[i]; - defineProperty(array, methodName, { - value: patchedArrayProto[methodName], - configurable: true - }); - } - }; - unpatchArrayMethods = function (array) { - var i; - i = mutatorMethods.length; - while (i--) { - delete array[mutatorMethods[i]]; - } - }; - } - errorMessage = 'Something went wrong in a rather interesting way'; - return arrayAdaptor; - }(config_types, utils_defineProperty, utils_isArray, shared_clearCache, shared_preDomUpdate, shared_postDomUpdate, shared_makeTransitionManager, shared_notifyDependants); -var Ractive_prototype_get_magicAdaptor = function () { - - var magicAdaptor, MagicWrapper; - try { - Object.defineProperty({}, 'test', { value: 0 }); - } catch (err) { - return false; - } - magicAdaptor = { - filter: function (object, keypath) { - return !!keypath; - }, - wrap: function (ractive, object, keypath) { - return new MagicWrapper(ractive, object, keypath); - } - }; - MagicWrapper = function (ractive, object, keypath) { - var wrapper = this, keys, prop, objKeypath, descriptor, wrappers, oldGet, oldSet, get, set; - this.ractive = ractive; - this.keypath = keypath; - keys = keypath.split('.'); - this.prop = keys.pop(); - objKeypath = keys.join('.'); - this.obj = objKeypath ? ractive.get(objKeypath) : ractive.data; - descriptor = this.originalDescriptor = Object.getOwnPropertyDescriptor(this.obj, this.prop); - if (descriptor && descriptor.set && (wrappers = descriptor.set._ractiveWrappers)) { - if (wrappers.indexOf(this) === -1) { - wrappers.push(this); - } - return; - } - if (descriptor && !descriptor.configurable) { - throw new Error('Cannot use magic mode with property "' + prop + '" - object is not configurable'); - } - if (descriptor) { - this.value = descriptor.value; - oldGet = descriptor.get; - oldSet = descriptor.set; - } - get = oldGet || function () { - return wrapper.value; - }; - set = function (value) { - var wrappers, wrapper, i; - if (oldSet) { - oldSet(value); - } - wrappers = set._ractiveWrappers; - i = wrappers.length; - while (i--) { - wrapper = wrappers[i]; - if (!wrapper.resetting) { - wrapper.ractive.set(wrapper.keypath, value); - } - } - }; - set._ractiveWrappers = [this]; - Object.defineProperty(this.obj, this.prop, { - get: get, - set: set, - enumerable: true, - configurable: true - }); - }; - MagicWrapper.prototype = { - get: function () { - return this.value; - }, - reset: function (value) { - this.resetting = true; - this.value = value; - this.resetting = false; - }, - teardown: function () { - var descriptor, set, value, wrappers; - descriptor = Object.getOwnPropertyDescriptor(this.obj, this.prop); - set = descriptor.set; - wrappers = set._ractiveWrappers; - wrappers.splice(wrappers.indexOf(this), 1); - if (!wrappers.length) { - value = this.obj[this.prop]; - Object.defineProperty(this.obj, this.prop, this.originalDescriptor || { - writable: true, - enumerable: true, - configrable: true - }); - this.obj[this.prop] = value; - } - } - }; - return magicAdaptor; - }(); -var shared_adaptIfNecessary = function (adaptorRegistry, arrayAdaptor, magicAdaptor) { - - var prefixers = {}; - return function (ractive, keypath, value, isExpressionResult) { - var len, i, adaptor, wrapped; - len = ractive.adaptors.length; - for (i = 0; i < len; i += 1) { - adaptor = ractive.adaptors[i]; - if (typeof adaptor === 'string') { - if (!adaptorRegistry[adaptor]) { - throw new Error('Missing adaptor "' + adaptor + '"'); - } - adaptor = ractive.adaptors[i] = adaptorRegistry[adaptor]; - } - if (adaptor.filter(value, keypath, ractive)) { - wrapped = ractive._wrapped[keypath] = adaptor.wrap(ractive, value, keypath, getPrefixer(keypath)); - wrapped.value = value; - return; - } - } - if (!isExpressionResult) { - if (ractive.magic && magicAdaptor.filter(value, keypath, ractive)) { - ractive._wrapped[keypath] = magicAdaptor.wrap(ractive, value, keypath); - } else if (ractive.modifyArrays && arrayAdaptor.filter(value, keypath, ractive)) { - ractive._wrapped[keypath] = arrayAdaptor.wrap(ractive, value, keypath); - } - } - }; - function prefixKeypath(obj, prefix) { - var prefixed = {}, key; - if (!prefix) { - return obj; - } - prefix += '.'; - for (key in obj) { - if (obj.hasOwnProperty(key)) { - prefixed[prefix + key] = obj[key]; - } - } - return prefixed; - } - function getPrefixer(rootKeypath) { - var rootDot; - if (!prefixers[rootKeypath]) { - rootDot = rootKeypath ? rootKeypath + '.' : ''; - prefixers[rootKeypath] = function (relativeKeypath, value) { - var obj; - if (typeof relativeKeypath === 'string') { - obj = {}; - obj[rootDot + relativeKeypath] = value; - return obj; - } - if (typeof relativeKeypath === 'object') { - return rootDot ? prefixKeypath(relativeKeypath, rootKeypath) : relativeKeypath; - } - }; - } - return prefixers[rootKeypath]; - } - }(registries_adaptors, Ractive_prototype_get_arrayAdaptor, Ractive_prototype_get_magicAdaptor); -var Ractive_prototype_get__get = function (normaliseKeypath, adaptorRegistry, adaptIfNecessary) { - - var get, _get, retrieve; - get = function (keypath) { - if (this._captured && !this._captured[keypath]) { - this._captured.push(keypath); - this._captured[keypath] = true; - } - return _get(this, keypath); - }; - _get = function (ractive, keypath) { - var cache, cached, value, wrapped, evaluator; - keypath = normaliseKeypath(keypath); - cache = ractive._cache; - if ((cached = cache[keypath]) !== undefined) { - return cached; - } - if (wrapped = ractive._wrapped[keypath]) { - value = wrapped.value; - } else if (!keypath) { - adaptIfNecessary(ractive, '', ractive.data); - value = ractive.data; - } else if (evaluator = ractive._evaluators[keypath]) { - value = evaluator.value; - } else { - value = retrieve(ractive, keypath); - } - cache[keypath] = value; - return value; - }; - retrieve = function (ractive, keypath) { - var keys, key, parentKeypath, parentValue, cacheMap, value, wrapped; - keys = keypath.split('.'); - key = keys.pop(); - parentKeypath = keys.join('.'); - parentValue = _get(ractive, parentKeypath); - if (wrapped = ractive._wrapped[parentKeypath]) { - parentValue = wrapped.get(); - } - if (parentValue === null || parentValue === undefined) { - return; - } - if (!(cacheMap = ractive._cacheMap[parentKeypath])) { - ractive._cacheMap[parentKeypath] = [keypath]; - } else { - if (cacheMap.indexOf(keypath) === -1) { - cacheMap[cacheMap.length] = keypath; - } - } - value = parentValue[key]; - adaptIfNecessary(ractive, keypath, value); - ractive._cache[keypath] = value; - return value; - }; - return get; - }(utils_normaliseKeypath, registries_adaptors, shared_adaptIfNecessary); -var utils_isObject = function () { - - var toString = Object.prototype.toString; - return function (thing) { - return typeof thing === 'object' && toString.call(thing) === '[object Object]'; - }; - }(); -var utils_isEqual = function () { - - return function (a, b) { - if (a === null && b === null) { - return true; - } - if (typeof a === 'object' || typeof b === 'object') { - return false; - } - return a === b; - }; - }(); -var shared_resolveRef = function () { - - var resolveRef; - resolveRef = function (ractive, ref, contextStack) { - var keypath, keys, lastKey, contextKeys, innerMostContext, postfix, parentKeypath, parentValue, wrapped, context, ancestorErrorMessage; - ancestorErrorMessage = 'Could not resolve reference - too many "../" prefixes'; - if (ref === '.') { - if (!contextStack.length) { - return ''; - } - keypath = contextStack[contextStack.length - 1]; - } else if (ref.charAt(0) === '.') { - context = contextStack[contextStack.length - 1]; - contextKeys = context ? context.split('.') : []; - if (ref.substr(0, 3) === '../') { - while (ref.substr(0, 3) === '../') { - if (!contextKeys.length) { - throw new Error(ancestorErrorMessage); - } - contextKeys.pop(); - ref = ref.substring(3); - } - contextKeys.push(ref); - keypath = contextKeys.join('.'); - } else if (!context) { - keypath = ref.substring(1); - } else { - keypath = context + ref; - } - } else { - keys = ref.split('.'); - lastKey = keys.pop(); - postfix = keys.length ? '.' + keys.join('.') : ''; - contextStack = contextStack.concat(); - while (contextStack.length) { - innerMostContext = contextStack.pop(); - parentKeypath = innerMostContext + postfix; - parentValue = ractive.get(parentKeypath); - if (wrapped = ractive._wrapped[parentKeypath]) { - parentValue = wrapped.get(); - } - if (typeof parentValue === 'object' && parentValue !== null && parentValue.hasOwnProperty(lastKey)) { - keypath = innerMostContext + '.' + ref; - break; - } - } - if (!keypath && ractive.get(ref) !== undefined) { - keypath = ref; - } - } - return keypath ? keypath.replace(/^\./, '') : keypath; - }; - return resolveRef; - }(); -var shared_attemptKeypathResolution = function (resolveRef) { - - var push = Array.prototype.push; - return function (ractive) { - var unresolved, keypath, leftover; - while (unresolved = ractive._pendingResolution.pop()) { - keypath = resolveRef(ractive, unresolved.ref, unresolved.contextStack); - if (keypath !== undefined) { - unresolved.resolve(keypath); - } else { - (leftover || (leftover = [])).push(unresolved); - } - } - if (leftover) { - push.apply(ractive._pendingResolution, leftover); - } - }; - }(shared_resolveRef); -var shared_processDeferredUpdates = function (preDomUpdate, postDomUpdate) { - - return function (ractive) { - preDomUpdate(ractive); - postDomUpdate(ractive); - }; - }(shared_preDomUpdate, shared_postDomUpdate); -var Ractive_prototype_shared_replaceData = function () { - - return function (ractive, keypath, value) { - var keys, accumulated, wrapped, obj, key, currentKeypath, keypathToClear; - keys = keypath.split('.'); - accumulated = []; - if (wrapped = ractive._wrapped['']) { - if (wrapped.set) { - wrapped.set(keys.join('.'), value); - } - obj = wrapped.get(); - } else { - obj = ractive.data; - } - while (keys.length > 1) { - key = accumulated[accumulated.length] = keys.shift(); - currentKeypath = accumulated.join('.'); - if (wrapped = ractive._wrapped[currentKeypath]) { - if (wrapped.set) { - wrapped.set(keys.join('.'), value); - } - obj = wrapped.get(); - } else { - if (!obj.hasOwnProperty(key)) { - if (!keypathToClear) { - keypathToClear = currentKeypath; - } - obj[key] = /^\s*[0-9]+\s*$/.test(keys[0]) ? [] : {}; - } - obj = obj[key]; - } - } - key = keys[0]; - obj[key] = value; - return keypathToClear; - }; - }(); -var Ractive_prototype_set = function (isObject, isEqual, normaliseKeypath, clearCache, notifyDependants, attemptKeypathResolution, makeTransitionManager, processDeferredUpdates, replaceData) { - - var set, updateModel, getUpstreamChanges, resetWrapped; - set = function (keypath, value, complete) { - var map, changes, upstreamChanges, previousTransitionManager, transitionManager, i, changeHash; - changes = []; - if (isObject(keypath)) { - map = keypath; - complete = value; - } - if (map) { - for (keypath in map) { - if (map.hasOwnProperty(keypath)) { - value = map[keypath]; - keypath = normaliseKeypath(keypath); - updateModel(this, keypath, value, changes); - } - } - } else { - keypath = normaliseKeypath(keypath); - updateModel(this, keypath, value, changes); - } - if (!changes.length) { - return; - } - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - upstreamChanges = getUpstreamChanges(changes); - if (upstreamChanges.length) { - notifyDependants.multiple(this, upstreamChanges, true); - } - notifyDependants.multiple(this, changes); - if (this._pendingResolution.length) { - attemptKeypathResolution(this); - } - processDeferredUpdates(this); - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - if (!this.firingChangeEvent) { - this.firingChangeEvent = true; - changeHash = {}; - i = changes.length; - while (i--) { - changeHash[changes[i]] = this.get(changes[i]); - } - this.fire('change', changeHash); - this.firingChangeEvent = false; - } - return this; - }; - updateModel = function (ractive, keypath, value, changes) { - var cached, previous, wrapped, keypathToClear, evaluator; - if ((wrapped = ractive._wrapped[keypath]) && wrapped.reset) { - if (resetWrapped(ractive, keypath, value, wrapped, changes) !== false) { - return; - } - } - if (evaluator = ractive._evaluators[keypath]) { - evaluator.value = value; - } - cached = ractive._cache[keypath]; - previous = ractive.get(keypath); - if (previous !== value && !evaluator) { - keypathToClear = replaceData(ractive, keypath, value); - } else { - if (value === cached && typeof value !== 'object') { - return; - } - } - clearCache(ractive, keypathToClear || keypath); - changes[changes.length] = keypath; - }; - getUpstreamChanges = function (changes) { - var upstreamChanges = [''], i, keypath, keys, upstreamKeypath; - i = changes.length; - while (i--) { - keypath = changes[i]; - keys = keypath.split('.'); - while (keys.length > 1) { - keys.pop(); - upstreamKeypath = keys.join('.'); - if (!upstreamChanges[upstreamKeypath]) { - upstreamChanges[upstreamChanges.length] = upstreamKeypath; - upstreamChanges[upstreamKeypath] = true; - } - } - } - return upstreamChanges; - }; - resetWrapped = function (ractive, keypath, value, wrapped, changes) { - var previous, cached, cacheMap, i; - previous = wrapped.get(); - if (!isEqual(previous, value)) { - if (wrapped.reset(value) === false) { - return false; - } - } - value = wrapped.get(); - cached = ractive._cache[keypath]; - if (!isEqual(cached, value)) { - ractive._cache[keypath] = value; - cacheMap = ractive._cacheMap[keypath]; - if (cacheMap) { - i = cacheMap.length; - while (i--) { - clearCache(ractive, cacheMap[i]); - } - } - changes[changes.length] = keypath; - } - }; - return set; - }(utils_isObject, utils_isEqual, utils_normaliseKeypath, shared_clearCache, shared_notifyDependants, shared_attemptKeypathResolution, shared_makeTransitionManager, shared_processDeferredUpdates, Ractive_prototype_shared_replaceData); -var Ractive_prototype_update = function (makeTransitionManager, attemptKeypathResolution, clearCache, notifyDependants, processDeferredUpdates) { - - return function (keypath, complete) { - var transitionManager, previousTransitionManager; - if (typeof keypath === 'function') { - complete = keypath; - keypath = ''; - } - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - attemptKeypathResolution(this); - clearCache(this, keypath || ''); - notifyDependants(this, keypath || ''); - processDeferredUpdates(this); - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - if (typeof keypath === 'string') { - this.fire('update', keypath); - } else { - this.fire('update'); - } - return this; - }; - }(shared_makeTransitionManager, shared_attemptKeypathResolution, shared_clearCache, shared_notifyDependants, shared_processDeferredUpdates); -var utils_arrayContentsMatch = function (isArray) { - - return function (a, b) { - var i; - if (!isArray(a) || !isArray(b)) { - return false; - } - if (a.length !== b.length) { - return false; - } - i = a.length; - while (i--) { - if (a[i] !== b[i]) { - return false; - } - } - return true; - }; - }(utils_isArray); -var Ractive_prototype_updateModel = function (getValueFromCheckboxes, arrayContentsMatch, isEqual) { - - return function (keypath, cascade) { - var values, deferredCheckboxes, i; - if (typeof keypath !== 'string') { - keypath = ''; - cascade = true; - } - consolidateChangedValues(this, keypath, values = {}, deferredCheckboxes = [], cascade); - if (i = deferredCheckboxes.length) { - while (i--) { - keypath = deferredCheckboxes[i]; - values[keypath] = getValueFromCheckboxes(this, keypath); - } - } - this.set(values); - }; - function consolidateChangedValues(ractive, keypath, values, deferredCheckboxes, cascade) { - var bindings, childDeps, i, binding, oldValue, newValue; - bindings = ractive._twowayBindings[keypath]; - if (bindings) { - i = bindings.length; - while (i--) { - binding = bindings[i]; - if (binding.radioName && !binding.node.checked) { - continue; - } - if (binding.checkboxName) { - if (binding.changed() && !deferredCheckboxes[keypath]) { - deferredCheckboxes[keypath] = true; - deferredCheckboxes[deferredCheckboxes.length] = keypath; - } - continue; - } - oldValue = binding.attr.value; - newValue = binding.value(); - if (arrayContentsMatch(oldValue, newValue)) { - continue; - } - if (!isEqual(oldValue, newValue)) { - values[keypath] = newValue; - } - } - } - if (!cascade) { - return; - } - childDeps = ractive._depsMap[keypath]; - if (childDeps) { - i = childDeps.length; - while (i--) { - consolidateChangedValues(ractive, childDeps[i], values, deferredCheckboxes, cascade); - } - } - } - }(shared_getValueFromCheckboxes, utils_arrayContentsMatch, utils_isEqual); -var Ractive_prototype_animate_requestAnimationFrame = function () { - - if (typeof window === 'undefined') { - return; - } - (function (vendors, lastTime, window) { - var x, setTimeout; - if (window.requestAnimationFrame) { - return; - } - for (x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { - window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']; - } - if (!window.requestAnimationFrame) { - setTimeout = window.setTimeout; - window.requestAnimationFrame = function (callback) { - var currTime, timeToCall, id; - currTime = Date.now(); - timeToCall = Math.max(0, 16 - (currTime - lastTime)); - id = setTimeout(function () { - callback(currTime + timeToCall); - }, timeToCall); - lastTime = currTime + timeToCall; - return id; - }; - } - }([ - 'ms', - 'moz', - 'webkit', - 'o' - ], 0, window)); - return window.requestAnimationFrame; - }(); -var Ractive_prototype_animate_animations = function (rAF) { - - var queue = []; - var animations = { - tick: function () { - var i, animation; - for (i = 0; i < queue.length; i += 1) { - animation = queue[i]; - if (!animation.tick()) { - queue.splice(i--, 1); - } - } - if (queue.length) { - rAF(animations.tick); - } else { - animations.running = false; - } - }, - add: function (animation) { - queue[queue.length] = animation; - if (!animations.running) { - animations.running = true; - animations.tick(); - } - }, - abort: function (keypath, root) { - var i = queue.length, animation; - while (i--) { - animation = queue[i]; - if (animation.root === root && animation.keypath === keypath) { - animation.stop(); - } - } - } - }; - return animations; - }(Ractive_prototype_animate_requestAnimationFrame); -var utils_warn = function () { - - if (typeof console !== 'undefined' && typeof console.warn === 'function' && typeof console.warn.apply === 'function') { - return function () { - console.warn.apply(console, arguments); - }; - } - return function () { - }; - }(); -var utils_isNumeric = function () { - - return function (thing) { - return !isNaN(parseFloat(thing)) && isFinite(thing); - }; - }(); -var shared_interpolate = function (isArray, isObject, isNumeric) { - - var interpolate = function (from, to) { - if (isNumeric(from) && isNumeric(to)) { - return makeNumberInterpolator(+from, +to); - } - if (isArray(from) && isArray(to)) { - return makeArrayInterpolator(from, to); - } - if (isObject(from) && isObject(to)) { - return makeObjectInterpolator(from, to); - } - return function () { - return to; - }; - }; - return interpolate; - function makeNumberInterpolator(from, to) { - var delta = to - from; - if (!delta) { - return function () { - return from; - }; - } - return function (t) { - return from + t * delta; - }; - } - function makeArrayInterpolator(from, to) { - var intermediate, interpolators, len, i; - intermediate = []; - interpolators = []; - i = len = Math.min(from.length, to.length); - while (i--) { - interpolators[i] = interpolate(from[i], to[i]); - } - for (i = len; i < from.length; i += 1) { - intermediate[i] = from[i]; - } - for (i = len; i < to.length; i += 1) { - intermediate[i] = to[i]; - } - return function (t) { - var i = len; - while (i--) { - intermediate[i] = interpolators[i](t); - } - return intermediate; - }; - } - function makeObjectInterpolator(from, to) { - var properties = [], len, interpolators, intermediate, prop; - intermediate = {}; - interpolators = {}; - for (prop in from) { - if (from.hasOwnProperty(prop)) { - if (to.hasOwnProperty(prop)) { - properties[properties.length] = prop; - interpolators[prop] = interpolate(from[prop], to[prop]); - } else { - intermediate[prop] = from[prop]; - } - } - } - for (prop in to) { - if (to.hasOwnProperty(prop) && !from.hasOwnProperty(prop)) { - intermediate[prop] = to[prop]; - } - } - len = properties.length; - return function (t) { - var i = len, prop; - while (i--) { - prop = properties[i]; - intermediate[prop] = interpolators[prop](t); - } - return intermediate; - }; - } - }(utils_isArray, utils_isObject, utils_isNumeric); -var Ractive_prototype_animate_Animation = function (warn, interpolate) { - - var Animation = function (options) { - var key; - this.startTime = Date.now(); - for (key in options) { - if (options.hasOwnProperty(key)) { - this[key] = options[key]; - } - } - this.interpolator = interpolate(this.from, this.to); - this.running = true; - }; - Animation.prototype = { - tick: function () { - var elapsed, t, value, timeNow, index, keypath; - keypath = this.keypath; - if (this.running) { - timeNow = Date.now(); - elapsed = timeNow - this.startTime; - if (elapsed >= this.duration) { - if (keypath !== null) { - this.root.set(keypath, this.to); - } - if (this.step) { - this.step(1, this.to); - } - if (this.complete) { - this.complete(1, this.to); - } - index = this.root._animations.indexOf(this); - if (index === -1) { - warn('Animation was not found'); - } - this.root._animations.splice(index, 1); - this.running = false; - return false; - } - t = this.easing ? this.easing(elapsed / this.duration) : elapsed / this.duration; - if (keypath !== null) { - value = this.interpolator(t); - this.root.set(keypath, value); - } - if (this.step) { - this.step(t, value); - } - return true; - } - return false; - }, - stop: function () { - var index; - this.running = false; - index = this.root._animations.indexOf(this); - if (index === -1) { - warn('Animation was not found'); - } - this.root._animations.splice(index, 1); - } - }; - return Animation; - }(utils_warn, shared_interpolate); -var registries_easing = function () { - - return { - linear: function (pos) { - return pos; - }, - easeIn: function (pos) { - return Math.pow(pos, 3); - }, - easeOut: function (pos) { - return Math.pow(pos - 1, 3) + 1; - }, - easeInOut: function (pos) { - if ((pos /= 0.5) < 1) { - return 0.5 * Math.pow(pos, 3); - } - return 0.5 * (Math.pow(pos - 2, 3) + 2); - } - }; - }(); -var Ractive_prototype_animate__animate = function (isEqual, animations, Animation, easingRegistry) { - - var noAnimation = { - stop: function () { - } - }; - return function (keypath, to, options) { - var k, animation, animations, easing, duration, step, complete, makeValueCollector, currentValues, collectValue, dummy, dummyOptions; - if (typeof keypath === 'object') { - options = to || {}; - easing = options.easing; - duration = options.duration; - animations = []; - step = options.step; - complete = options.complete; - if (step || complete) { - currentValues = {}; - options.step = null; - options.complete = null; - makeValueCollector = function (keypath) { - return function (t, value) { - currentValues[keypath] = value; - }; - }; - } - for (k in keypath) { - if (keypath.hasOwnProperty(k)) { - if (step || complete) { - collectValue = makeValueCollector(k); - options = { - easing: easing, - duration: duration - }; - if (step) { - options.step = collectValue; - } - if (complete) { - options.complete = collectValue; - } - } - animations[animations.length] = animate(this, k, keypath[k], options); - } - } - if (step || complete) { - dummyOptions = { - easing: easing, - duration: duration - }; - if (step) { - dummyOptions.step = function (t) { - step(t, currentValues); - }; - } - if (complete) { - dummyOptions.complete = function (t) { - complete(t, currentValues); - }; - } - animations[animations.length] = dummy = animate(this, null, null, dummyOptions); - } - return { - stop: function () { - while (animations.length) { - animations.pop().stop(); - } - if (dummy) { - dummy.stop(); - } - } - }; - } - options = options || {}; - animation = animate(this, keypath, to, options); - return { - stop: function () { - animation.stop(); - } - }; - }; - function animate(root, keypath, to, options) { - var easing, duration, animation, from; - if (keypath !== null) { - from = root.get(keypath); - } - animations.abort(keypath, root); - if (isEqual(from, to)) { - if (options.complete) { - options.complete(1, options.to); - } - return noAnimation; - } - if (options.easing) { - if (typeof options.easing === 'function') { - easing = options.easing; - } else { - if (root.easing && root.easing[options.easing]) { - easing = root.easing[options.easing]; - } else { - easing = easingRegistry[options.easing]; - } - } - if (typeof easing !== 'function') { - easing = null; - } - } - duration = options.duration === undefined ? 400 : options.duration; - animation = new Animation({ - keypath: keypath, - from: from, - to: to, - root: root, - duration: duration, - easing: easing, - step: options.step, - complete: options.complete - }); - animations.add(animation); - root._animations[root._animations.length] = animation; - return animation; - } - }(utils_isEqual, Ractive_prototype_animate_animations, Ractive_prototype_animate_Animation, registries_easing); -var Ractive_prototype_on = function () { - - return function (eventName, callback) { - var self = this, listeners, n; - if (typeof eventName === 'object') { - listeners = []; - for (n in eventName) { - if (eventName.hasOwnProperty(n)) { - listeners[listeners.length] = this.on(n, eventName[n]); - } - } - return { - cancel: function () { - while (listeners.length) { - listeners.pop().cancel(); - } - } - }; - } - if (!this._subs[eventName]) { - this._subs[eventName] = [callback]; - } else { - this._subs[eventName].push(callback); - } - return { - cancel: function () { - self.off(eventName, callback); - } - }; - }; - }(); -var Ractive_prototype_off = function () { - - return function (eventName, callback) { - var subscribers, index; - if (!callback) { - if (!eventName) { - for (eventName in this._subs) { - delete this._subs[eventName]; - } - } else { - this._subs[eventName] = []; - } - } - subscribers = this._subs[eventName]; - if (subscribers) { - index = subscribers.indexOf(callback); - if (index !== -1) { - subscribers.splice(index, 1); - } - } - }; - }(); -var shared_registerDependant = function () { - - return function (dependant) { - var depsByKeypath, deps, keys, parentKeypath, map, ractive, keypath, priority; - ractive = dependant.root; - keypath = dependant.keypath; - priority = dependant.priority; - depsByKeypath = ractive._deps[priority] || (ractive._deps[priority] = {}); - deps = depsByKeypath[keypath] || (depsByKeypath[keypath] = []); - deps[deps.length] = dependant; - dependant.registered = true; - if (!keypath) { - return; - } - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - parentKeypath = keys.join('.'); - map = ractive._depsMap[parentKeypath] || (ractive._depsMap[parentKeypath] = []); - if (map[keypath] === undefined) { - map[keypath] = 0; - map[map.length] = keypath; - } - map[keypath] += 1; - keypath = parentKeypath; - } - }; - }(); -var shared_unregisterDependant = function () { - - return function (dependant) { - var deps, index, keys, parentKeypath, map, ractive, keypath, priority; - ractive = dependant.root; - keypath = dependant.keypath; - priority = dependant.priority; - deps = ractive._deps[priority][keypath]; - index = deps.indexOf(dependant); - if (index === -1 || !dependant.registered) { - throw new Error('Attempted to remove a dependant that was no longer registered! This should not happen. If you are seeing this bug in development please raise an issue at https://github.com/RactiveJS/Ractive/issues - thanks'); - } - deps.splice(index, 1); - dependant.registered = false; - if (!keypath) { - return; - } - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - parentKeypath = keys.join('.'); - map = ractive._depsMap[parentKeypath]; - map[keypath] -= 1; - if (!map[keypath]) { - map.splice(map.indexOf(keypath), 1); - map[keypath] = undefined; - } - keypath = parentKeypath; - } - }; - }(); -var Ractive_prototype_observe_Observer = function (isEqual) { - - var Observer = function (ractive, keypath, callback, options) { - var self = this; - this.root = ractive; - this.keypath = keypath; - this.callback = callback; - this.defer = options.defer; - this.debug = options.debug; - this.proxy = { - update: function () { - self.reallyUpdate(); - } - }; - this.priority = 0; - this.context = options && options.context ? options.context : ractive; - }; - Observer.prototype = { - init: function (immediate) { - if (immediate !== false) { - this.update(); - } else { - this.value = this.root.get(this.keypath); - } - }, - update: function () { - if (this.defer && this.ready) { - this.root._deferred.observers.push(this.proxy); - return; - } - this.reallyUpdate(); - }, - reallyUpdate: function () { - var oldValue, newValue; - oldValue = this.value; - newValue = this.root.get(this.keypath); - this.value = newValue; - if (this.updating) { - return; - } - this.updating = true; - if (!isEqual(newValue, oldValue) || !this.ready) { - try { - this.callback.call(this.context, newValue, oldValue, this.keypath); - } catch (err) { - if (this.debug || this.root.debug) { - throw err; - } - } - } - this.updating = false; - } - }; - return Observer; - }(utils_isEqual); -var Ractive_prototype_observe_getPattern = function () { - - return function (ractive, pattern) { - var keys, key, values, toGet, newToGet, expand, concatenate; - keys = pattern.split('.'); - toGet = []; - expand = function (keypath) { - var value, key; - value = ractive._wrapped[keypath] ? ractive._wrapped[keypath].get() : ractive.get(keypath); - for (key in value) { - newToGet.push(keypath + '.' + key); - } - }; - concatenate = function (keypath) { - return keypath + '.' + key; - }; - while (key = keys.shift()) { - if (key === '*') { - newToGet = []; - toGet.forEach(expand); - toGet = newToGet; - } else { - if (!toGet[0]) { - toGet[0] = key; - } else { - toGet = toGet.map(concatenate); - } - } - } - values = {}; - toGet.forEach(function (keypath) { - values[keypath] = ractive.get(keypath); - }); - return values; - }; - }(); -var Ractive_prototype_observe_PatternObserver = function (isEqual, getPattern) { - - var PatternObserver, wildcard = /\*/; - PatternObserver = function (ractive, keypath, callback, options) { - this.root = ractive; - this.callback = callback; - this.defer = options.defer; - this.debug = options.debug; - this.keypath = keypath; - this.regex = new RegExp('^' + keypath.replace(/\./g, '\\.').replace(/\*/g, '[^\\.]+') + '$'); - this.values = {}; - if (this.defer) { - this.proxies = []; - } - this.priority = 'pattern'; - this.context = options && options.context ? options.context : ractive; - }; - PatternObserver.prototype = { - init: function (immediate) { - var values, keypath; - values = getPattern(this.root, this.keypath); - if (immediate !== false) { - for (keypath in values) { - if (values.hasOwnProperty(keypath)) { - this.update(keypath); - } - } - } else { - this.values = values; - } - }, - update: function (keypath) { - var values; - if (wildcard.test(keypath)) { - values = getPattern(this.root, keypath); - for (keypath in values) { - if (values.hasOwnProperty(keypath)) { - this.update(keypath); - } - } - return; - } - if (this.defer && this.ready) { - this.root._deferred.observers.push(this.getProxy(keypath)); - return; - } - this.reallyUpdate(keypath); - }, - reallyUpdate: function (keypath) { - var value = this.root.get(keypath); - if (this.updating) { - this.values[keypath] = value; - return; - } - this.updating = true; - if (!isEqual(value, this.values[keypath]) || !this.ready) { - try { - this.callback.call(this.context, value, this.values[keypath], keypath); - } catch (err) { - if (this.debug || this.root.debug) { - throw err; - } - } - this.values[keypath] = value; - } - this.updating = false; - }, - getProxy: function (keypath) { - var self = this; - if (!this.proxies[keypath]) { - this.proxies[keypath] = { - update: function () { - self.reallyUpdate(keypath); - } - }; - } - return this.proxies[keypath]; - } - }; - return PatternObserver; - }(utils_isEqual, Ractive_prototype_observe_getPattern); -var Ractive_prototype_observe_getObserverFacade = function (normaliseKeypath, registerDependant, unregisterDependant, Observer, PatternObserver) { - - var wildcard = /\*/, emptyObject = {}; - return function getObserverFacade(ractive, keypath, callback, options) { - var observer, isPatternObserver; - keypath = normaliseKeypath(keypath); - options = options || emptyObject; - if (wildcard.test(keypath)) { - observer = new PatternObserver(ractive, keypath, callback, options); - ractive._patternObservers.push(observer); - isPatternObserver = true; - } else { - observer = new Observer(ractive, keypath, callback, options); - } - registerDependant(observer); - observer.init(options.init); - observer.ready = true; - return { - cancel: function () { - var index; - if (isPatternObserver) { - index = ractive._patternObservers.indexOf(observer); - if (index !== -1) { - ractive._patternObservers.splice(index, 1); - } - } - unregisterDependant(observer); - } - }; - }; - }(utils_normaliseKeypath, shared_registerDependant, shared_unregisterDependant, Ractive_prototype_observe_Observer, Ractive_prototype_observe_PatternObserver); -var Ractive_prototype_observe__observe = function (isObject, getObserverFacade) { - - return function observe(keypath, callback, options) { - var observers = [], k; - if (isObject(keypath)) { - options = callback; - for (k in keypath) { - if (keypath.hasOwnProperty(k)) { - callback = keypath[k]; - observers[observers.length] = getObserverFacade(this, k, callback, options); - } - } - return { - cancel: function () { - while (observers.length) { - observers.pop().cancel(); - } - } - }; - } - return getObserverFacade(this, keypath, callback, options); - }; - }(utils_isObject, Ractive_prototype_observe_getObserverFacade); -var Ractive_prototype_fire = function () { - - return function (eventName) { - var args, i, len, subscribers = this._subs[eventName]; - if (!subscribers) { - return; - } - args = Array.prototype.slice.call(arguments, 1); - for (i = 0, len = subscribers.length; i < len; i += 1) { - subscribers[i].apply(this, args); - } - }; - }(); -var Ractive_prototype_find = function () { - - return function (selector) { - if (!this.el) { - return null; - } - return this.fragment.find(selector); - }; - }(); -var utils_matches = function (isClient, createElement) { - - var div, methodNames, unprefixed, prefixed, vendors, i, j, makeFunction; - if (!isClient) { - return; - } - div = createElement('div'); - methodNames = [ - 'matches', - 'matchesSelector' - ]; - vendors = [ - 'o', - 'ms', - 'moz', - 'webkit' - ]; - makeFunction = function (methodName) { - return function (node, selector) { - return node[methodName](selector); - }; - }; - i = methodNames.length; - while (i--) { - unprefixed = methodNames[i]; - if (div[unprefixed]) { - return makeFunction(unprefixed); - } - j = vendors.length; - while (j--) { - prefixed = vendors[i] + unprefixed.substr(0, 1).toUpperCase() + unprefixed.substring(1); - if (div[prefixed]) { - return makeFunction(prefixed); - } - } - } - return function (node, selector) { - var nodes, i; - nodes = (node.parentNode || node.document).querySelectorAll(selector); - i = nodes.length; - while (i--) { - if (nodes[i] === node) { - return true; - } - } - return false; - }; - }(config_isClient, utils_createElement); -var Ractive_prototype_shared_makeQuery_test = function (matches) { - - return function (item, noDirty) { - var itemMatches = this._isComponentQuery ? !this.selector || item.name === this.selector : matches(item.node, this.selector); - if (itemMatches) { - this.push(item.node || item.instance); - if (!noDirty) { - this._makeDirty(); - } - return true; - } - }; - }(utils_matches); -var Ractive_prototype_shared_makeQuery_cancel = function () { - - return function () { - var liveQueries, selector, index; - liveQueries = this._root[this._isComponentQuery ? 'liveComponentQueries' : 'liveQueries']; - selector = this.selector; - index = liveQueries.indexOf(selector); - if (index !== -1) { - liveQueries.splice(index, 1); - liveQueries[selector] = null; - } - }; - }(); -var Ractive_prototype_shared_makeQuery_sortByItemPosition = function () { - - return function (a, b) { - var ancestryA, ancestryB, oldestA, oldestB, mutualAncestor, indexA, indexB, fragments, fragmentA, fragmentB; - ancestryA = getAncestry(a.component || a._ractive.proxy); - ancestryB = getAncestry(b.component || b._ractive.proxy); - oldestA = ancestryA[ancestryA.length - 1]; - oldestB = ancestryB[ancestryB.length - 1]; - while (oldestA && oldestA === oldestB) { - ancestryA.pop(); - ancestryB.pop(); - mutualAncestor = oldestA; - oldestA = ancestryA[ancestryA.length - 1]; - oldestB = ancestryB[ancestryB.length - 1]; - } - oldestA = oldestA.component || oldestA; - oldestB = oldestB.component || oldestB; - fragmentA = oldestA.parentFragment; - fragmentB = oldestB.parentFragment; - if (fragmentA === fragmentB) { - indexA = fragmentA.items.indexOf(oldestA); - indexB = fragmentB.items.indexOf(oldestB); - return indexA - indexB || ancestryA.length - ancestryB.length; - } - if (fragments = mutualAncestor.fragments) { - indexA = fragments.indexOf(fragmentA); - indexB = fragments.indexOf(fragmentB); - return indexA - indexB || ancestryA.length - ancestryB.length; - } - throw new Error('An unexpected condition was met while comparing the position of two components. Please file an issue at https://github.com/RactiveJS/Ractive/issues - thanks!'); - }; - function getParent(item) { - var parentFragment; - if (parentFragment = item.parentFragment) { - return parentFragment.owner; - } - if (item.component && (parentFragment = item.component.parentFragment)) { - return parentFragment.owner; - } - } - function getAncestry(item) { - var ancestry, ancestor; - ancestry = [item]; - ancestor = getParent(item); - while (ancestor) { - ancestry.push(ancestor); - ancestor = getParent(ancestor); - } - return ancestry; - } - }(); -var Ractive_prototype_shared_makeQuery_sortByDocumentPosition = function (sortByItemPosition) { - - return function (node, otherNode) { - var bitmask; - if (node.compareDocumentPosition) { - bitmask = node.compareDocumentPosition(otherNode); - return bitmask & 2 ? 1 : -1; - } - return sortByItemPosition(node, otherNode); - }; - }(Ractive_prototype_shared_makeQuery_sortByItemPosition); -var Ractive_prototype_shared_makeQuery_sort = function (sortByDocumentPosition, sortByItemPosition) { - - return function () { - this.sort(this._isComponentQuery ? sortByItemPosition : sortByDocumentPosition); - this._dirty = false; - }; - }(Ractive_prototype_shared_makeQuery_sortByDocumentPosition, Ractive_prototype_shared_makeQuery_sortByItemPosition); -var Ractive_prototype_shared_makeQuery_dirty = function () { - - return function () { - if (!this._dirty) { - this._root._deferred.liveQueries.push(this); - this._dirty = true; - } - }; - }(); -var Ractive_prototype_shared_makeQuery_remove = function () { - - return function (item) { - var index = this.indexOf(this._isComponentQuery ? item.instance : item.node); - if (index !== -1) { - this.splice(index, 1); - } - }; - }(); -var Ractive_prototype_shared_makeQuery__makeQuery = function (defineProperties, test, cancel, sort, dirty, remove) { - - return function (ractive, selector, live, isComponentQuery) { - var query; - query = []; - defineProperties(query, { - selector: { value: selector }, - live: { value: live }, - _isComponentQuery: { value: isComponentQuery }, - _test: { value: test } - }); - if (!live) { - return query; - } - defineProperties(query, { - cancel: { value: cancel }, - _root: { value: ractive }, - _sort: { value: sort }, - _makeDirty: { value: dirty }, - _remove: { value: remove }, - _dirty: { - value: false, - writable: true - } - }); - return query; - }; - }(utils_defineProperties, Ractive_prototype_shared_makeQuery_test, Ractive_prototype_shared_makeQuery_cancel, Ractive_prototype_shared_makeQuery_sort, Ractive_prototype_shared_makeQuery_dirty, Ractive_prototype_shared_makeQuery_remove); -var Ractive_prototype_findAll = function (warn, matches, defineProperties, makeQuery) { - - return function (selector, options) { - var liveQueries, query; - if (!this.el) { - return []; - } - options = options || {}; - liveQueries = this._liveQueries; - if (query = liveQueries[selector]) { - return options && options.live ? query : query.slice(); - } - query = makeQuery(this, selector, !!options.live, false); - if (query.live) { - liveQueries.push(selector); - liveQueries[selector] = query; - } - this.fragment.findAll(selector, query); - return query; - }; - }(utils_warn, utils_matches, utils_defineProperties, Ractive_prototype_shared_makeQuery__makeQuery); -var Ractive_prototype_findComponent = function () { - - return function (selector) { - return this.fragment.findComponent(selector); - }; - }(); -var Ractive_prototype_findAllComponents = function (warn, matches, defineProperties, makeQuery) { - - return function (selector, options) { - var liveQueries, query; - options = options || {}; - liveQueries = this._liveComponentQueries; - if (query = liveQueries[selector]) { - return options && options.live ? query : query.slice(); - } - query = makeQuery(this, selector, !!options.live, true); - if (query.live) { - liveQueries.push(selector); - liveQueries[selector] = query; - } - this.fragment.findAllComponents(selector, query); - return query; - }; - }(utils_warn, utils_matches, utils_defineProperties, Ractive_prototype_shared_makeQuery__makeQuery); -var utils_getElement = function () { - - return function (input) { - var output; - if (typeof window === 'undefined' || !document || !input) { - return null; - } - if (input.nodeType) { - return input; - } - if (typeof input === 'string') { - output = document.getElementById(input); - if (!output && document.querySelector) { - output = document.querySelector(input); - } - if (output && output.nodeType) { - return output; - } - } - if (input[0] && input[0].nodeType) { - return input[0]; - } - return null; - }; - }(); -var render_shared_initFragment = function (types, create) { - - return function (fragment, options) { - var numItems, i, parentFragment, parentRefs, ref; - fragment.owner = options.owner; - parentFragment = fragment.owner.parentFragment; - fragment.root = options.root; - fragment.pNode = options.pNode; - fragment.contextStack = options.contextStack || []; - if (fragment.owner.type === types.SECTION) { - fragment.index = options.index; - } - if (parentFragment) { - parentRefs = parentFragment.indexRefs; - if (parentRefs) { - fragment.indexRefs = create(null); - for (ref in parentRefs) { - fragment.indexRefs[ref] = parentRefs[ref]; - } - } - } - fragment.priority = parentFragment ? parentFragment.priority + 1 : 1; - if (options.indexRef) { - if (!fragment.indexRefs) { - fragment.indexRefs = {}; - } - fragment.indexRefs[options.indexRef] = options.index; - } - fragment.items = []; - numItems = options.descriptor ? options.descriptor.length : 0; - for (i = 0; i < numItems; i += 1) { - fragment.items[fragment.items.length] = fragment.createItem({ - parentFragment: fragment, - descriptor: options.descriptor[i], - index: i - }); - } - }; - }(config_types, utils_create); -var render_DomFragment_shared_insertHtml = function (createElement) { - - var elementCache = {}; - return function (html, tagName, docFrag) { - var container, nodes = []; - if (html) { - container = elementCache[tagName] || (elementCache[tagName] = createElement(tagName)); - container.innerHTML = html; - while (container.firstChild) { - nodes[nodes.length] = container.firstChild; - docFrag.appendChild(container.firstChild); - } - } - return nodes; - }; - }(utils_createElement); -var render_DomFragment_Text = function (types) { - - var DomText, lessThan, greaterThan; - lessThan = //g; - DomText = function (options, docFrag) { - this.type = types.TEXT; - this.descriptor = options.descriptor; - if (docFrag) { - this.node = document.createTextNode(options.descriptor); - docFrag.appendChild(this.node); - } - }; - DomText.prototype = { - detach: function () { - this.node.parentNode.removeChild(this.node); - return this.node; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - } - }, - firstNode: function () { - return this.node; - }, - toString: function () { - return ('' + this.descriptor).replace(lessThan, '<').replace(greaterThan, '>'); - } - }; - return DomText; - }(config_types); -var shared_teardown = function (unregisterDependant) { - - return function (thing) { - if (!thing.keypath) { - var index = thing.root._pendingResolution.indexOf(thing); - if (index !== -1) { - thing.root._pendingResolution.splice(index, 1); - } - } else { - unregisterDependant(thing); - } - }; - }(shared_unregisterDependant); -var render_shared_Evaluator_Reference = function (types, isEqual, defineProperty, registerDependant, unregisterDependant) { - - var Reference, thisPattern; - thisPattern = /this/; - Reference = function (root, keypath, evaluator, argNum, priority) { - var value; - this.evaluator = evaluator; - this.keypath = keypath; - this.root = root; - this.argNum = argNum; - this.type = types.REFERENCE; - this.priority = priority; - value = root.get(keypath); - if (typeof value === 'function') { - value = wrapFunction(value, root, evaluator); - } - this.value = evaluator.values[argNum] = value; - registerDependant(this); - }; - Reference.prototype = { - update: function () { - var value = this.root.get(this.keypath); - if (typeof value === 'function' && !value._nowrap) { - value = wrapFunction(value, this.root, this.evaluator); - } - if (!isEqual(value, this.value)) { - this.evaluator.values[this.argNum] = value; - this.evaluator.bubble(); - this.value = value; - } - }, - teardown: function () { - unregisterDependant(this); - } - }; - return Reference; - function wrapFunction(fn, ractive, evaluator) { - var prop, evaluators, index; - if (!thisPattern.test(fn.toString())) { - defineProperty(fn, '_nowrap', { value: true }); - return fn; - } - if (!fn['_' + ractive._guid]) { - defineProperty(fn, '_' + ractive._guid, { - value: function () { - var originalCaptured, result, i, evaluator; - originalCaptured = ractive._captured; - if (!originalCaptured) { - ractive._captured = []; - } - result = fn.apply(ractive, arguments); - if (ractive._captured.length) { - i = evaluators.length; - while (i--) { - evaluator = evaluators[i]; - evaluator.updateSoftDependencies(ractive._captured); - } - } - ractive._captured = originalCaptured; - return result; - }, - writable: true - }); - for (prop in fn) { - if (fn.hasOwnProperty(prop)) { - fn['_' + ractive._guid][prop] = fn[prop]; - } - } - fn['_' + ractive._guid + '_evaluators'] = []; - } - evaluators = fn['_' + ractive._guid + '_evaluators']; - index = evaluators.indexOf(evaluator); - if (index === -1) { - evaluators.push(evaluator); - } - return fn['_' + ractive._guid]; - } - }(config_types, utils_isEqual, utils_defineProperty, shared_registerDependant, shared_unregisterDependant); -var render_shared_Evaluator_SoftReference = function (isEqual, registerDependant, unregisterDependant) { - - var SoftReference = function (root, keypath, evaluator) { - this.root = root; - this.keypath = keypath; - this.priority = evaluator.priority; - this.evaluator = evaluator; - registerDependant(this); - }; - SoftReference.prototype = { - update: function () { - var value = this.root.get(this.keypath); - if (!isEqual(value, this.value)) { - this.evaluator.bubble(); - this.value = value; - } - }, - teardown: function () { - unregisterDependant(this); - } - }; - return SoftReference; - }(utils_isEqual, shared_registerDependant, shared_unregisterDependant); -var render_shared_Evaluator__Evaluator = function (isEqual, defineProperty, clearCache, notifyDependants, registerDependant, unregisterDependant, adaptIfNecessary, Reference, SoftReference) { - - var Evaluator, cache = {}; - Evaluator = function (root, keypath, functionStr, args, priority) { - var i, arg; - this.root = root; - this.keypath = keypath; - this.priority = priority; - this.fn = getFunctionFromString(functionStr, args.length); - this.values = []; - this.refs = []; - i = args.length; - while (i--) { - if (arg = args[i]) { - if (arg[0]) { - this.values[i] = arg[1]; - } else { - this.refs[this.refs.length] = new Reference(root, arg[1], this, i, priority); - } - } else { - this.values[i] = undefined; - } - } - this.selfUpdating = this.refs.length <= 1; - this.update(); - }; - Evaluator.prototype = { - bubble: function () { - if (this.selfUpdating) { - this.update(); - } else if (!this.deferred) { - this.root._deferred.evals.push(this); - this.deferred = true; - } - }, - update: function () { - var value; - if (this.evaluating) { - return this; - } - this.evaluating = true; - try { - value = this.fn.apply(null, this.values); - } catch (err) { - if (this.root.debug) { - throw err; - } else { - value = undefined; - } - } - if (!isEqual(value, this.value)) { - clearCache(this.root, this.keypath); - this.root._cache[this.keypath] = value; - adaptIfNecessary(this.root, this.keypath, value, true); - this.value = value; - notifyDependants(this.root, this.keypath); - } - this.evaluating = false; - return this; - }, - teardown: function () { - while (this.refs.length) { - this.refs.pop().teardown(); - } - clearCache(this.root, this.keypath); - this.root._evaluators[this.keypath] = null; - }, - refresh: function () { - if (!this.selfUpdating) { - this.deferred = true; - } - var i = this.refs.length; - while (i--) { - this.refs[i].update(); - } - if (this.deferred) { - this.update(); - this.deferred = false; - } - }, - updateSoftDependencies: function (softDeps) { - var i, keypath, ref; - if (!this.softRefs) { - this.softRefs = []; - } - i = this.softRefs.length; - while (i--) { - ref = this.softRefs[i]; - if (!softDeps[ref.keypath]) { - this.softRefs.splice(i, 1); - this.softRefs[ref.keypath] = false; - ref.teardown(); - } - } - i = softDeps.length; - while (i--) { - keypath = softDeps[i]; - if (!this.softRefs[keypath]) { - ref = new SoftReference(this.root, keypath, this); - this.softRefs[this.softRefs.length] = ref; - this.softRefs[keypath] = true; - } - } - this.selfUpdating = this.refs.length + this.softRefs.length <= 1; - } - }; - return Evaluator; - function getFunctionFromString(str, i) { - var fn, args; - str = str.replace(/\$\{([0-9]+)\}/g, '_$1'); - if (cache[str]) { - return cache[str]; - } - args = []; - while (i--) { - args[i] = '_' + i; - } - fn = new Function(args.join(','), 'return(' + str + ')'); - cache[str] = fn; - return fn; - } - }(utils_isEqual, utils_defineProperty, shared_clearCache, shared_notifyDependants, shared_registerDependant, shared_unregisterDependant, shared_adaptIfNecessary, render_shared_Evaluator_Reference, render_shared_Evaluator_SoftReference); -var render_shared_ExpressionResolver_ReferenceScout = function (resolveRef, teardown) { - - var ReferenceScout = function (resolver, ref, contextStack, argNum) { - var keypath, root; - root = this.root = resolver.root; - keypath = resolveRef(root, ref, contextStack); - if (keypath !== undefined) { - resolver.resolveRef(argNum, false, keypath); - } else { - this.ref = ref; - this.argNum = argNum; - this.resolver = resolver; - this.contextStack = contextStack; - root._pendingResolution[root._pendingResolution.length] = this; - } - }; - ReferenceScout.prototype = { - resolve: function (keypath) { - this.keypath = keypath; - this.resolver.resolveRef(this.argNum, false, keypath); - }, - teardown: function () { - if (!this.keypath) { - teardown(this); - } - } - }; - return ReferenceScout; - }(shared_resolveRef, shared_teardown); -var render_shared_ExpressionResolver_isRegularKeypath = function () { - - var keyPattern = /^(?:(?:[a-zA-Z$_][a-zA-Z$_0-9]*)|(?:[0-9]|[1-9][0-9]+))$/; - return function (keypath) { - var keys, key, i; - keys = keypath.split('.'); - i = keys.length; - while (i--) { - key = keys[i]; - if (key === 'undefined' || !keyPattern.test(key)) { - return false; - } - } - return true; - }; - }(); -var render_shared_ExpressionResolver_getKeypath = function (normaliseKeypath, isRegularKeypath) { - - return function (str, args) { - var unique, normalised; - unique = str.replace(/\$\{([0-9]+)\}/g, function (match, $1) { - return args[$1] ? args[$1][1] : 'undefined'; - }); - normalised = normaliseKeypath(unique); - if (isRegularKeypath(normalised)) { - return normalised; - } - return '${' + unique.replace(/[\.\[\]]/g, '-') + '}'; - }; - }(utils_normaliseKeypath, render_shared_ExpressionResolver_isRegularKeypath); -var render_shared_ExpressionResolver_reassignDependants = function (registerDependant, unregisterDependant) { - - return function (ractive, oldKeypath, newKeypath) { - var toReassign, i, dependant; - toReassign = []; - gatherDependants(ractive, oldKeypath, toReassign); - i = toReassign.length; - while (i--) { - dependant = toReassign[i]; - unregisterDependant(dependant); - dependant.keypath = dependant.keypath.replace(oldKeypath, newKeypath); - registerDependant(dependant); - dependant.update(); - } - }; - function cascade(ractive, oldKeypath, toReassign) { - var map, i; - map = ractive._depsMap[oldKeypath]; - if (!map) { - return; - } - i = map.length; - while (i--) { - gatherDependants(ractive, map[i], toReassign); - } - } - function gatherDependants(ractive, oldKeypath, toReassign) { - var priority, dependantsByKeypath, dependants, i; - priority = ractive._deps.length; - while (priority--) { - dependantsByKeypath = ractive._deps[priority]; - if (dependantsByKeypath) { - dependants = dependantsByKeypath[oldKeypath]; - if (dependants) { - i = dependants.length; - while (i--) { - toReassign.push(dependants[i]); - } - } - } - } - cascade(ractive, oldKeypath, toReassign); - } - }(shared_registerDependant, shared_unregisterDependant); -var render_shared_ExpressionResolver__ExpressionResolver = function (Evaluator, ReferenceScout, getKeypath, reassignDependants) { - - var ExpressionResolver = function (mustache) { - var expression, i, len, ref, indexRefs; - this.root = mustache.root; - this.mustache = mustache; - this.args = []; - this.scouts = []; - expression = mustache.descriptor.x; - indexRefs = mustache.parentFragment.indexRefs; - this.str = expression.s; - len = this.unresolved = this.args.length = expression.r ? expression.r.length : 0; - if (!len) { - this.resolved = this.ready = true; - this.bubble(); - return; - } - for (i = 0; i < len; i += 1) { - ref = expression.r[i]; - if (indexRefs && indexRefs[ref] !== undefined) { - this.resolveRef(i, true, indexRefs[ref]); - } else { - this.scouts[this.scouts.length] = new ReferenceScout(this, ref, mustache.contextStack, i); - } - } - this.ready = true; - this.bubble(); - }; - ExpressionResolver.prototype = { - bubble: function () { - var oldKeypath; - if (!this.ready) { - return; - } - oldKeypath = this.keypath; - this.keypath = getKeypath(this.str, this.args); - if (this.keypath.substr(0, 2) === '${') { - this.createEvaluator(); - } - if (oldKeypath) { - reassignDependants(this.root, oldKeypath, this.keypath); - } else { - this.mustache.resolve(this.keypath); - } - }, - teardown: function () { - while (this.scouts.length) { - this.scouts.pop().teardown(); - } - }, - resolveRef: function (argNum, isIndexRef, value) { - this.args[argNum] = [ - isIndexRef, - value - ]; - this.bubble(); - this.resolved = !--this.unresolved; - }, - createEvaluator: function () { - if (!this.root._evaluators[this.keypath]) { - this.root._evaluators[this.keypath] = new Evaluator(this.root, this.keypath, this.str, this.args, this.mustache.priority); - } else { - this.root._evaluators[this.keypath].refresh(); - } - } - }; - return ExpressionResolver; - }(render_shared_Evaluator__Evaluator, render_shared_ExpressionResolver_ReferenceScout, render_shared_ExpressionResolver_getKeypath, render_shared_ExpressionResolver_reassignDependants); -var render_shared_initMustache = function (resolveRef, ExpressionResolver) { - - return function (mustache, options) { - var keypath, indexRef, parentFragment; - parentFragment = mustache.parentFragment = options.parentFragment; - mustache.root = parentFragment.root; - mustache.contextStack = parentFragment.contextStack; - mustache.descriptor = options.descriptor; - mustache.index = options.index || 0; - mustache.priority = parentFragment.priority; - mustache.type = options.descriptor.t; - if (options.descriptor.r) { - if (parentFragment.indexRefs && parentFragment.indexRefs[options.descriptor.r] !== undefined) { - indexRef = parentFragment.indexRefs[options.descriptor.r]; - mustache.indexRef = options.descriptor.r; - mustache.value = indexRef; - mustache.render(mustache.value); - } else { - keypath = resolveRef(mustache.root, options.descriptor.r, mustache.contextStack); - if (keypath !== undefined) { - mustache.resolve(keypath); - } else { - mustache.ref = options.descriptor.r; - mustache.root._pendingResolution[mustache.root._pendingResolution.length] = mustache; - } - } - } - if (options.descriptor.x) { - mustache.expressionResolver = new ExpressionResolver(mustache); - } - if (mustache.descriptor.n && !mustache.hasOwnProperty('value')) { - mustache.render(undefined); - } - }; - }(shared_resolveRef, render_shared_ExpressionResolver__ExpressionResolver); -var render_shared_resolveMustache = function (types, registerDependant, unregisterDependant) { - - return function (keypath) { - if (keypath === this.keypath) { - return; - } - if (this.registered) { - unregisterDependant(this); - } - this.keypath = keypath; - registerDependant(this); - this.update(); - if (this.root.twoway && this.parentFragment.owner.type === types.ATTRIBUTE) { - this.parentFragment.owner.element.bind(); - } - if (this.expressionResolver && this.expressionResolver.resolved) { - this.expressionResolver = null; - } - }; - }(config_types, shared_registerDependant, shared_unregisterDependant); -var render_shared_updateMustache = function (isEqual) { - - return function () { - var wrapped, value; - value = this.root.get(this.keypath); - if (wrapped = this.root._wrapped[this.keypath]) { - value = wrapped.get(); - } - if (!isEqual(value, this.value)) { - this.render(value); - this.value = value; - } - }; - }(utils_isEqual); -var render_DomFragment_Interpolator = function (types, teardown, initMustache, resolveMustache, updateMustache) { - - var DomInterpolator, lessThan, greaterThan; - lessThan = //g; - DomInterpolator = function (options, docFrag) { - this.type = types.INTERPOLATOR; - if (docFrag) { - this.node = document.createTextNode(''); - docFrag.appendChild(this.node); - } - initMustache(this, options); - }; - DomInterpolator.prototype = { - update: updateMustache, - resolve: resolveMustache, - detach: function () { - this.node.parentNode.removeChild(this.node); - return this.node; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - } - teardown(this); - }, - render: function (value) { - if (this.node) { - this.node.data = value == undefined ? '' : value; - } - }, - firstNode: function () { - return this.node; - }, - toString: function () { - var value = this.value != undefined ? '' + this.value : ''; - return value.replace(lessThan, '<').replace(greaterThan, '>'); - } - }; - return DomInterpolator; - }(config_types, shared_teardown, render_shared_initMustache, render_shared_resolveMustache, render_shared_updateMustache); -var render_shared_updateSection = function (isArray, isObject, create) { - - return function (section, value) { - var fragmentOptions; - fragmentOptions = { - descriptor: section.descriptor.f, - root: section.root, - pNode: section.parentFragment.pNode, - owner: section - }; - if (section.descriptor.n) { - updateConditionalSection(section, value, true, fragmentOptions); - return; - } - if (isArray(value)) { - updateListSection(section, value, fragmentOptions); - } else if (isObject(value)) { - if (section.descriptor.i) { - updateListObjectSection(section, value, fragmentOptions); - } else { - updateContextSection(section, fragmentOptions); - } - } else { - updateConditionalSection(section, value, false, fragmentOptions); - } - }; - function updateListSection(section, value, fragmentOptions) { - var i, length, fragmentsToRemove; - length = value.length; - if (length < section.length) { - fragmentsToRemove = section.fragments.splice(length, section.length - length); - while (fragmentsToRemove.length) { - fragmentsToRemove.pop().teardown(true); - } - } else { - if (length > section.length) { - for (i = section.length; i < length; i += 1) { - fragmentOptions.contextStack = section.contextStack.concat(section.keypath + '.' + i); - fragmentOptions.index = i; - if (section.descriptor.i) { - fragmentOptions.indexRef = section.descriptor.i; - } - section.fragments[i] = section.createFragment(fragmentOptions); - } - } - } - section.length = length; - } - function updateListObjectSection(section, value, fragmentOptions) { - var id, fragmentsById; - fragmentsById = section.fragmentsById || (section.fragmentsById = create(null)); - for (id in fragmentsById) { - if (value[id] === undefined && fragmentsById[id]) { - fragmentsById[id].teardown(true); - fragmentsById[id] = null; - } - } - for (id in value) { - if (value[id] !== undefined && !fragmentsById[id]) { - fragmentOptions.contextStack = section.contextStack.concat(section.keypath + '.' + id); - fragmentOptions.index = id; - if (section.descriptor.i) { - fragmentOptions.indexRef = section.descriptor.i; - } - fragmentsById[id] = section.createFragment(fragmentOptions); - } - } - } - function updateContextSection(section, fragmentOptions) { - if (!section.length) { - fragmentOptions.contextStack = section.contextStack.concat(section.keypath); - fragmentOptions.index = 0; - section.fragments[0] = section.createFragment(fragmentOptions); - section.length = 1; - } - } - function updateConditionalSection(section, value, inverted, fragmentOptions) { - var doRender, emptyArray, fragmentsToRemove, fragment; - emptyArray = isArray(value) && value.length === 0; - if (inverted) { - doRender = emptyArray || !value; - } else { - doRender = value && !emptyArray; - } - if (doRender) { - if (!section.length) { - fragmentOptions.contextStack = section.contextStack; - fragmentOptions.index = 0; - section.fragments[0] = section.createFragment(fragmentOptions); - section.length = 1; - } - if (section.length > 1) { - fragmentsToRemove = section.fragments.splice(1); - while (fragment = fragmentsToRemove.pop()) { - fragment.teardown(true); - } - } - } else if (section.length) { - section.teardownFragments(true); - section.length = 0; - } - } - }(utils_isArray, utils_isObject, utils_create); -var render_DomFragment_Section_reassignFragment = function (types, unregisterDependant, ExpressionResolver) { - - return reassignFragment; - function reassignFragment(fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath) { - var i, item, context, query; - if (fragment.html) { - return; - } - if (fragment.indexRefs && fragment.indexRefs[indexRef] !== undefined) { - fragment.indexRefs[indexRef] = newIndex; - } - i = fragment.contextStack.length; - while (i--) { - context = fragment.contextStack[i]; - if (context.substr(0, oldKeypath.length) === oldKeypath) { - fragment.contextStack[i] = context.replace(oldKeypath, newKeypath); - } - } - i = fragment.items.length; - while (i--) { - item = fragment.items[i]; - switch (item.type) { - case types.ELEMENT: - reassignElement(item, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - break; - case types.PARTIAL: - reassignFragment(item.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - break; - case types.COMPONENT: - reassignFragment(item.instance.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - if (query = fragment.root._liveComponentQueries[item.name]) { - query._makeDirty(); - } - break; - case types.SECTION: - case types.INTERPOLATOR: - case types.TRIPLE: - reassignMustache(item, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - break; - } - } - } - function reassignElement(element, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath) { - var i, attribute, storage, masterEventName, proxies, proxy, binding, bindings, liveQueries, ractive; - i = element.attributes.length; - while (i--) { - attribute = element.attributes[i]; - if (attribute.fragment) { - reassignFragment(attribute.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - if (attribute.twoway) { - attribute.updateBindings(); - } - } - } - if (storage = element.node._ractive) { - if (storage.keypath.substr(0, oldKeypath.length) === oldKeypath) { - storage.keypath = storage.keypath.replace(oldKeypath, newKeypath); - } - if (indexRef !== undefined) { - storage.index[indexRef] = newIndex; - } - for (masterEventName in storage.events) { - proxies = storage.events[masterEventName].proxies; - i = proxies.length; - while (i--) { - proxy = proxies[i]; - if (typeof proxy.n === 'object') { - reassignFragment(proxy.a, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - if (proxy.d) { - reassignFragment(proxy.d, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - } - } - if (binding = storage.binding) { - if (binding.keypath.substr(0, oldKeypath.length) === oldKeypath) { - bindings = storage.root._twowayBindings[binding.keypath]; - bindings.splice(bindings.indexOf(binding), 1); - binding.keypath = binding.keypath.replace(oldKeypath, newKeypath); - bindings = storage.root._twowayBindings[binding.keypath] || (storage.root._twowayBindings[binding.keypath] = []); - bindings.push(binding); - } - } - } - if (element.fragment) { - reassignFragment(element.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - if (liveQueries = element.liveQueries) { - ractive = element.root; - i = liveQueries.length; - while (i--) { - ractive._liveQueries[liveQueries[i]]._makeDirty(); - } - } - } - function reassignMustache(mustache, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath) { - var i; - if (mustache.descriptor.x) { - if (mustache.expressionResolver) { - mustache.expressionResolver.teardown(); - } - mustache.expressionResolver = new ExpressionResolver(mustache); - } - if (mustache.keypath) { - if (mustache.keypath.substr(0, oldKeypath.length) === oldKeypath) { - mustache.resolve(mustache.keypath.replace(oldKeypath, newKeypath)); - } - } else if (mustache.indexRef === indexRef) { - mustache.value = newIndex; - mustache.render(newIndex); - } - if (mustache.fragments) { - i = mustache.fragments.length; - while (i--) { - reassignFragment(mustache.fragments[i], indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - } - } - }(config_types, shared_unregisterDependant, render_shared_ExpressionResolver__ExpressionResolver); -var render_DomFragment_Section_reassignFragments = function (types, reassignFragment, preDomUpdate) { - - return function (root, section, start, end, by) { - var i, fragment, indexRef, oldIndex, newIndex, oldKeypath, newKeypath; - indexRef = section.descriptor.i; - for (i = start; i < end; i += 1) { - fragment = section.fragments[i]; - oldIndex = i - by; - newIndex = i; - oldKeypath = section.keypath + '.' + (i - by); - newKeypath = section.keypath + '.' + i; - fragment.index += by; - reassignFragment(fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - preDomUpdate(root); - }; - }(config_types, render_DomFragment_Section_reassignFragment, shared_preDomUpdate); -var render_DomFragment_Section_prototype_merge = function (reassignFragment) { - - return function (newIndices) { - var section = this, parentFragment, firstChange, changed, i, newLength, newFragments, toTeardown, fragmentOptions, fragment, nextNode; - parentFragment = this.parentFragment; - newFragments = []; - newIndices.forEach(function (newIndex, oldIndex) { - var by, oldKeypath, newKeypath; - if (newIndex === oldIndex) { - newFragments[newIndex] = section.fragments[oldIndex]; - return; - } - if (firstChange === undefined) { - firstChange = oldIndex; - } - if (newIndex === -1) { - (toTeardown || (toTeardown = [])).push(section.fragments[oldIndex]); - return; - } - by = newIndex - oldIndex; - oldKeypath = section.keypath + '.' + oldIndex; - newKeypath = section.keypath + '.' + newIndex; - reassignFragment(section.fragments[oldIndex], section.descriptor.i, oldIndex, newIndex, by, oldKeypath, newKeypath); - newFragments[newIndex] = section.fragments[oldIndex]; - changed = true; - }); - if (toTeardown) { - while (fragment = toTeardown.pop()) { - fragment.teardown(true); - } - } - if (firstChange === undefined) { - firstChange = this.length; - } - newLength = this.root.get(this.keypath).length; - if (newLength === firstChange) { - return; - } - fragmentOptions = { - descriptor: this.descriptor.f, - root: this.root, - pNode: parentFragment.pNode, - owner: this - }; - if (this.descriptor.i) { - fragmentOptions.indexRef = this.descriptor.i; - } - for (i = firstChange; i < newLength; i += 1) { - if (fragment = newFragments[i]) { - this.docFrag.appendChild(fragment.detach(false)); - } else { - fragmentOptions.contextStack = this.contextStack.concat(this.keypath + '.' + i); - fragmentOptions.index = i; - fragment = this.createFragment(fragmentOptions); - } - this.fragments[i] = fragment; - } - nextNode = parentFragment.findNextNode(this); - parentFragment.pNode.insertBefore(this.docFrag, nextNode); - this.length = newLength; - }; - }(render_DomFragment_Section_reassignFragment); -var circular = function () { - - return []; - }(); -var render_DomFragment_Section__Section = function (types, isClient, initMustache, updateMustache, resolveMustache, updateSection, reassignFragment, reassignFragments, merge, teardown, circular) { - - var DomSection, DomFragment; - circular.push(function () { - DomFragment = circular.DomFragment; - }); - DomSection = function (options, docFrag) { - this.type = types.SECTION; - this.inverted = !!options.descriptor.n; - this.fragments = []; - this.length = 0; - if (docFrag) { - this.docFrag = document.createDocumentFragment(); - } - this.initialising = true; - initMustache(this, options); - if (docFrag) { - docFrag.appendChild(this.docFrag); - } - this.initialising = false; - }; - DomSection.prototype = { - update: updateMustache, - resolve: resolveMustache, - smartUpdate: function (methodName, args) { - var fragmentOptions; - if (methodName === 'push' || methodName === 'unshift' || methodName === 'splice') { - fragmentOptions = { - descriptor: this.descriptor.f, - root: this.root, - pNode: this.parentFragment.pNode, - owner: this - }; - if (this.descriptor.i) { - fragmentOptions.indexRef = this.descriptor.i; - } - } - if (this[methodName]) { - this.rendering = true; - this[methodName](fragmentOptions, args); - this.rendering = false; - } - }, - pop: function () { - if (this.length) { - this.fragments.pop().teardown(true); - this.length -= 1; - } - }, - push: function (fragmentOptions, args) { - var start, end, i; - start = this.length; - end = start + args.length; - for (i = start; i < end; i += 1) { - fragmentOptions.contextStack = this.contextStack.concat(this.keypath + '.' + i); - fragmentOptions.index = i; - this.fragments[i] = this.createFragment(fragmentOptions); - } - this.length += args.length; - this.parentFragment.pNode.insertBefore(this.docFrag, this.parentFragment.findNextNode(this)); - }, - shift: function () { - this.splice(null, [ - 0, - 1 - ]); - }, - unshift: function (fragmentOptions, args) { - this.splice(fragmentOptions, [ - 0, - 0 - ].concat(new Array(args.length))); - }, - splice: function (fragmentOptions, args) { - var insertionPoint, addedItems, removedItems, balance, i, start, end, spliceArgs, reassignStart; - if (!args.length) { - return; - } - start = +(args[0] < 0 ? this.length + args[0] : args[0]); - addedItems = Math.max(0, args.length - 2); - removedItems = args[1] !== undefined ? args[1] : this.length - start; - removedItems = Math.min(removedItems, this.length - start); - balance = addedItems - removedItems; - if (!balance) { - return; - } - if (balance < 0) { - end = start - balance; - for (i = start; i < end; i += 1) { - this.fragments[i].teardown(true); - } - this.fragments.splice(start, -balance); - } else { - end = start + balance; - insertionPoint = this.fragments[start] ? this.fragments[start].firstNode() : this.parentFragment.findNextNode(this); - spliceArgs = [ - start, - 0 - ].concat(new Array(balance)); - this.fragments.splice.apply(this.fragments, spliceArgs); - for (i = start; i < end; i += 1) { - fragmentOptions.contextStack = this.contextStack.concat(this.keypath + '.' + i); - fragmentOptions.index = i; - this.fragments[i] = this.createFragment(fragmentOptions); - } - this.parentFragment.pNode.insertBefore(this.docFrag, insertionPoint); - } - this.length += balance; - reassignStart = start + addedItems; - reassignFragments(this.root, this, reassignStart, this.length, balance); - }, - merge: merge, - detach: function () { - var i, len; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - this.docFrag.appendChild(this.fragments[i].detach()); - } - return this.docFrag; - }, - teardown: function (destroy) { - this.teardownFragments(destroy); - teardown(this); - }, - firstNode: function () { - if (this.fragments[0]) { - return this.fragments[0].firstNode(); - } - return this.parentFragment.findNextNode(this); - }, - findNextNode: function (fragment) { - if (this.fragments[fragment.index + 1]) { - return this.fragments[fragment.index + 1].firstNode(); - } - return this.parentFragment.findNextNode(this); - }, - teardownFragments: function (destroy) { - var id, fragment; - while (fragment = this.fragments.shift()) { - fragment.teardown(destroy); - } - if (this.fragmentsById) { - for (id in this.fragmentsById) { - if (this.fragments[id]) { - this.fragmentsById[id].teardown(destroy); - this.fragmentsById[id] = null; - } - } - } - }, - render: function (value) { - var nextNode, wrapped; - if (wrapped = this.root._wrapped[this.keypath]) { - value = wrapped.get(); - } - if (this.rendering) { - return; - } - this.rendering = true; - updateSection(this, value); - this.rendering = false; - if (this.docFrag && !this.docFrag.childNodes.length) { - return; - } - if (!this.initialising && isClient) { - nextNode = this.parentFragment.findNextNode(this); - if (nextNode && nextNode.parentNode === this.parentFragment.pNode) { - this.parentFragment.pNode.insertBefore(this.docFrag, nextNode); - } else { - this.parentFragment.pNode.appendChild(this.docFrag); - } - } - }, - createFragment: function (options) { - var fragment = new DomFragment(options); - if (this.docFrag) { - this.docFrag.appendChild(fragment.docFrag); - } - return fragment; - }, - toString: function () { - var str, i, id, len; - str = ''; - i = 0; - len = this.length; - for (i = 0; i < len; i += 1) { - str += this.fragments[i].toString(); - } - if (this.fragmentsById) { - for (id in this.fragmentsById) { - if (this.fragmentsById[id]) { - str += this.fragmentsById[id].toString(); - } - } - } - return str; - }, - find: function (selector) { - var i, len, queryResult; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - if (queryResult = this.fragments[i].find(selector)) { - return queryResult; - } - } - return null; - }, - findAll: function (selector, query) { - var i, len; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - this.fragments[i].findAll(selector, query); - } - }, - findComponent: function (selector) { - var i, len, queryResult; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - if (queryResult = this.fragments[i].findComponent(selector)) { - return queryResult; - } - } - return null; - }, - findAllComponents: function (selector, query) { - var i, len; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - this.fragments[i].findAllComponents(selector, query); - } - } - }; - return DomSection; - }(config_types, config_isClient, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache, render_shared_updateSection, render_DomFragment_Section_reassignFragment, render_DomFragment_Section_reassignFragments, render_DomFragment_Section_prototype_merge, shared_teardown, circular); -var render_DomFragment_Triple = function (types, matches, initMustache, updateMustache, resolveMustache, insertHtml, teardown) { - - var DomTriple = function (options, docFrag) { - this.type = types.TRIPLE; - if (docFrag) { - this.nodes = []; - this.docFrag = document.createDocumentFragment(); - } - this.initialising = true; - initMustache(this, options); - if (docFrag) { - docFrag.appendChild(this.docFrag); - } - this.initialising = false; - }; - DomTriple.prototype = { - update: updateMustache, - resolve: resolveMustache, - detach: function () { - var i = this.nodes.length; - while (i--) { - this.docFrag.appendChild(this.nodes[i]); - } - return this.docFrag; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - this.docFrag = this.nodes = null; - } - teardown(this); - }, - firstNode: function () { - if (this.nodes[0]) { - return this.nodes[0]; - } - return this.parentFragment.findNextNode(this); - }, - render: function (html) { - var node, pNode; - if (!this.nodes) { - return; - } - while (this.nodes.length) { - node = this.nodes.pop(); - node.parentNode.removeChild(node); - } - if (!html) { - this.nodes = []; - return; - } - pNode = this.parentFragment.pNode; - this.nodes = insertHtml(html, pNode.tagName, this.docFrag); - if (!this.initialising) { - pNode.insertBefore(this.docFrag, this.parentFragment.findNextNode(this)); - } - }, - toString: function () { - return this.value != undefined ? this.value : ''; - }, - find: function (selector) { - var i, len, node, queryResult; - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - return node; - } - if (queryResult = node.querySelector(selector)) { - return queryResult; - } - } - return null; - }, - findAll: function (selector, queryResult) { - var i, len, node, queryAllResult, numNodes, j; - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - queryResult.push(node); - } - if (queryAllResult = node.querySelectorAll(selector)) { - numNodes = queryAllResult.length; - for (j = 0; j < numNodes; j += 1) { - queryResult.push(queryAllResult[j]); - } - } - } - } - }; - return DomTriple; - }(config_types, utils_matches, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache, render_DomFragment_shared_insertHtml, shared_teardown); -var render_DomFragment_Element_initialise_getElementNamespace = function (namespaces) { - - return function (descriptor, parentNode) { - if (descriptor.a && descriptor.a.xmlns) { - return descriptor.a.xmlns; - } - return descriptor.e === 'svg' ? namespaces.svg : parentNode.namespaceURI || namespaces.html; - }; - }(config_namespaces); -var render_DomFragment_shared_enforceCase = function () { - - var svgCamelCaseElements, svgCamelCaseAttributes, createMap, map; - svgCamelCaseElements = 'altGlyph altGlyphDef altGlyphItem animateColor animateMotion animateTransform clipPath feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile feTurbulence foreignObject glyphRef linearGradient radialGradient textPath vkern'.split(' '); - svgCamelCaseAttributes = 'attributeName attributeType baseFrequency baseProfile calcMode clipPathUnits contentScriptType contentStyleType diffuseConstant edgeMode externalResourcesRequired filterRes filterUnits glyphRef gradientTransform gradientUnits kernelMatrix kernelUnitLength keyPoints keySplines keyTimes lengthAdjust limitingConeAngle markerHeight markerUnits markerWidth maskContentUnits maskUnits numOctaves pathLength patternContentUnits patternTransform patternUnits pointsAtX pointsAtY pointsAtZ preserveAlpha preserveAspectRatio primitiveUnits refX refY repeatCount repeatDur requiredExtensions requiredFeatures specularConstant specularExponent spreadMethod startOffset stdDeviation stitchTiles surfaceScale systemLanguage tableValues targetX targetY textLength viewBox viewTarget xChannelSelector yChannelSelector zoomAndPan'.split(' '); - createMap = function (items) { - var map = {}, i = items.length; - while (i--) { - map[items[i].toLowerCase()] = items[i]; - } - return map; - }; - map = createMap(svgCamelCaseElements.concat(svgCamelCaseAttributes)); - return function (elementName) { - var lowerCaseElementName = elementName.toLowerCase(); - return map[lowerCaseElementName] || lowerCaseElementName; - }; - }(); -var render_DomFragment_Attribute_helpers_determineNameAndNamespace = function (namespaces, enforceCase) { - - return function (attribute, name) { - var colonIndex, namespacePrefix; - colonIndex = name.indexOf(':'); - if (colonIndex !== -1) { - namespacePrefix = name.substr(0, colonIndex); - if (namespacePrefix !== 'xmlns') { - name = name.substring(colonIndex + 1); - attribute.name = enforceCase(name); - attribute.lcName = attribute.name.toLowerCase(); - attribute.namespace = namespaces[namespacePrefix.toLowerCase()]; - if (!attribute.namespace) { - throw 'Unknown namespace ("' + namespacePrefix + '")'; - } - return; - } - } - attribute.name = attribute.element.namespace !== namespaces.html ? enforceCase(name) : name; - attribute.lcName = attribute.name.toLowerCase(); - }; - }(config_namespaces, render_DomFragment_shared_enforceCase); -var render_DomFragment_Attribute_helpers_setStaticAttribute = function (namespaces) { - - return function (attribute, options) { - var node, value = options.value === null ? '' : options.value; - if (node = options.pNode) { - if (attribute.namespace) { - node.setAttributeNS(attribute.namespace, options.name, value); - } else { - if (options.name === 'style' && node.style.setAttribute) { - node.style.setAttribute('cssText', value); - } else if (options.name === 'class' && (!node.namespaceURI || node.namespaceURI === namespaces.html)) { - node.className = value; - } else { - node.setAttribute(options.name, value); - } - } - if (attribute.name === 'id') { - options.root.nodes[options.value] = node; - } - if (attribute.name === 'value') { - node._ractive.value = options.value; - } - } - attribute.value = options.value; - }; - }(config_namespaces); -var render_DomFragment_Attribute_helpers_determinePropertyName = function (namespaces) { - - var propertyNames = { - 'accept-charset': 'acceptCharset', - accesskey: 'accessKey', - bgcolor: 'bgColor', - 'class': 'className', - codebase: 'codeBase', - colspan: 'colSpan', - contenteditable: 'contentEditable', - datetime: 'dateTime', - dirname: 'dirName', - 'for': 'htmlFor', - 'http-equiv': 'httpEquiv', - ismap: 'isMap', - maxlength: 'maxLength', - novalidate: 'noValidate', - pubdate: 'pubDate', - readonly: 'readOnly', - rowspan: 'rowSpan', - tabindex: 'tabIndex', - usemap: 'useMap' - }; - return function (attribute, options) { - var propertyName; - if (attribute.pNode && !attribute.namespace && (!options.pNode.namespaceURI || options.pNode.namespaceURI === namespaces.html)) { - propertyName = propertyNames[attribute.name] || attribute.name; - if (options.pNode[propertyName] !== undefined) { - attribute.propertyName = propertyName; - } - if (typeof options.pNode[propertyName] === 'boolean' || propertyName === 'value') { - attribute.useProperty = true; - } - } - }; - }(config_namespaces); -var render_DomFragment_Attribute_prototype_bind = function (types, warn, arrayContentsMatch, getValueFromCheckboxes) { - - var bindAttribute, getInterpolator, updateModel, update, getBinding, inheritProperties, MultipleSelectBinding, SelectBinding, RadioNameBinding, CheckboxNameBinding, CheckedBinding, FileListBinding, ContentEditableBinding, GenericBinding; - bindAttribute = function () { - var node = this.pNode, interpolator, binding, bindings; - if (!this.fragment) { - return false; - } - interpolator = getInterpolator(this); - if (!interpolator) { - return false; - } - this.interpolator = interpolator; - this.keypath = interpolator.keypath || interpolator.descriptor.r; - binding = getBinding(this); - if (!binding) { - return false; - } - node._ractive.binding = this.element.binding = binding; - this.twoway = true; - bindings = this.root._twowayBindings[this.keypath] || (this.root._twowayBindings[this.keypath] = []); - bindings[bindings.length] = binding; - return true; - }; - updateModel = function () { - this._ractive.binding.update(); - }; - update = function () { - var value = this._ractive.root.get(this._ractive.binding.keypath); - this.value = value == undefined ? '' : value; - }; - getInterpolator = function (attribute) { - var item, errorMessage; - if (attribute.fragment.items.length !== 1) { - return null; - } - item = attribute.fragment.items[0]; - if (item.type !== types.INTERPOLATOR) { - return null; - } - if (!item.keypath && !item.ref) { - return null; - } - if (item.keypath && item.keypath.substr(0, 2) === '${') { - errorMessage = 'You cannot set up two-way binding against an expression ' + item.keypath; - if (attribute.root.debug) { - warn(errorMessage); - } - return null; - } - return item; - }; - getBinding = function (attribute) { - var node = attribute.pNode; - if (node.tagName === 'SELECT') { - return node.multiple ? new MultipleSelectBinding(attribute, node) : new SelectBinding(attribute, node); - } - if (node.type === 'checkbox' || node.type === 'radio') { - if (attribute.propertyName === 'name') { - if (node.type === 'checkbox') { - return new CheckboxNameBinding(attribute, node); - } - if (node.type === 'radio') { - return new RadioNameBinding(attribute, node); - } - } - if (attribute.propertyName === 'checked') { - return new CheckedBinding(attribute, node); - } - return null; - } - if (attribute.lcName !== 'value') { - warn('This is... odd'); - } - if (node.type === 'file') { - return new FileListBinding(attribute, node); - } - if (node.getAttribute('contenteditable')) { - return new ContentEditableBinding(attribute, node); - } - return new GenericBinding(attribute, node); - }; - MultipleSelectBinding = function (attribute, node) { - var valueFromModel; - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - valueFromModel = this.root.get(this.keypath); - if (valueFromModel === undefined) { - this.update(); - } - }; - MultipleSelectBinding.prototype = { - value: function () { - var value, options, i, len; - value = []; - options = this.node.options; - len = options.length; - for (i = 0; i < len; i += 1) { - if (options[i].selected) { - value[value.length] = options[i]._ractive.value; - } - } - return value; - }, - update: function () { - var attribute, previousValue, value; - attribute = this.attr; - previousValue = attribute.value; - value = this.value(); - if (previousValue === undefined || !arrayContentsMatch(value, previousValue)) { - attribute.receiving = true; - attribute.value = value; - this.root.set(this.keypath, value); - attribute.receiving = false; - } - return this; - }, - deferUpdate: function () { - if (this.deferred === true) { - return; - } - this.root._deferred.attrs.push(this); - this.deferred = true; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - } - }; - SelectBinding = function (attribute, node) { - var valueFromModel; - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - valueFromModel = this.root.get(this.keypath); - if (valueFromModel === undefined) { - this.update(); - } - }; - SelectBinding.prototype = { - value: function () { - var options, i, len; - options = this.node.options; - len = options.length; - for (i = 0; i < len; i += 1) { - if (options[i].selected) { - return options[i]._ractive.value; - } - } - }, - update: function () { - var value = this.value(); - this.attr.receiving = true; - this.attr.value = value; - this.root.set(this.keypath, value); - this.attr.receiving = false; - return this; - }, - deferUpdate: function () { - if (this.deferred === true) { - return; - } - this.root._deferred.attrs.push(this); - this.deferred = true; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - } - }; - RadioNameBinding = function (attribute, node) { - var valueFromModel; - this.radioName = true; - inheritProperties(this, attribute, node); - node.name = '{{' + attribute.keypath + '}}'; - node.addEventListener('change', updateModel, false); - if (node.attachEvent) { - node.addEventListener('click', updateModel, false); - } - valueFromModel = this.root.get(this.keypath); - if (valueFromModel !== undefined) { - node.checked = valueFromModel == node._ractive.value; - } else { - this.root._deferred.radios.push(this); - } - }; - RadioNameBinding.prototype = { - value: function () { - return this.node._ractive ? this.node._ractive.value : this.node.value; - }, - update: function () { - var node = this.node; - if (node.checked) { - this.attr.receiving = true; - this.root.set(this.keypath, this.value()); - this.attr.receiving = false; - } - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('click', updateModel, false); - } - }; - CheckboxNameBinding = function (attribute, node) { - var valueFromModel, checked; - this.checkboxName = true; - inheritProperties(this, attribute, node); - node.name = '{{' + this.keypath + '}}'; - node.addEventListener('change', updateModel, false); - if (node.attachEvent) { - node.addEventListener('click', updateModel, false); - } - valueFromModel = this.root.get(this.keypath); - if (valueFromModel !== undefined) { - checked = valueFromModel.indexOf(node._ractive.value) !== -1; - node.checked = checked; - } else { - if (this.root._deferred.checkboxes.indexOf(this.keypath) === -1) { - this.root._deferred.checkboxes.push(this.keypath); - } - } - }; - CheckboxNameBinding.prototype = { - changed: function () { - return this.node.checked !== !!this.checked; - }, - update: function () { - this.checked = this.node.checked; - this.attr.receiving = true; - this.root.set(this.keypath, getValueFromCheckboxes(this.root, this.keypath)); - this.attr.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('click', updateModel, false); - } - }; - CheckedBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - if (node.attachEvent) { - node.addEventListener('click', updateModel, false); - } - }; - CheckedBinding.prototype = { - value: function () { - return this.node.checked; - }, - update: function () { - this.attr.receiving = true; - this.root.set(this.keypath, this.value()); - this.attr.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('click', updateModel, false); - } - }; - FileListBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - }; - FileListBinding.prototype = { - value: function () { - return this.attr.pNode.files; - }, - update: function () { - this.attr.root.set(this.attr.keypath, this.value()); - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - } - }; - ContentEditableBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - if (!this.root.lazy) { - node.addEventListener('input', updateModel, false); - if (node.attachEvent) { - node.addEventListener('keyup', updateModel, false); - } - } - }; - ContentEditableBinding.prototype = { - update: function () { - this.attr.receiving = true; - this.root.set(this.keypath, this.node.innerHTML); - this.attr.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('input', updateModel, false); - this.node.removeEventListener('keyup', updateModel, false); - } - }; - GenericBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - if (!this.root.lazy) { - node.addEventListener('input', updateModel, false); - if (node.attachEvent) { - node.addEventListener('keyup', updateModel, false); - } - } - this.node.addEventListener('blur', update, false); - }; - GenericBinding.prototype = { - value: function () { - var value = this.attr.pNode.value; - if (+value + '' === value && value.indexOf('e') === -1) { - value = +value; - } - return value; - }, - update: function () { - var attribute = this.attr, value = this.value(); - attribute.receiving = true; - attribute.root.set(attribute.keypath, value); - attribute.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('input', updateModel, false); - this.node.removeEventListener('keyup', updateModel, false); - this.node.removeEventListener('blur', update, false); - } - }; - inheritProperties = function (binding, attribute, node) { - binding.attr = attribute; - binding.node = node; - binding.root = attribute.root; - binding.keypath = attribute.keypath; - }; - return bindAttribute; - }(config_types, utils_warn, utils_arrayContentsMatch, shared_getValueFromCheckboxes); -var render_DomFragment_Attribute_prototype_update = function (isArray, namespaces) { - - var updateAttribute, updateFileInputValue, deferSelect, initSelect, updateSelect, updateMultipleSelect, updateRadioName, updateCheckboxName, updateIEStyleAttribute, updateClassName, updateContentEditableValue, updateEverythingElse; - updateAttribute = function () { - var node; - if (!this.ready) { - return this; - } - node = this.pNode; - if (node.tagName === 'SELECT' && this.lcName === 'value') { - this.update = deferSelect; - this.deferredUpdate = initSelect; - return this.update(); - } - if (this.isFileInputValue) { - this.update = updateFileInputValue; - return this; - } - if (this.twoway && this.lcName === 'name') { - if (node.type === 'radio') { - this.update = updateRadioName; - return this.update(); - } - if (node.type === 'checkbox') { - this.update = updateCheckboxName; - return this.update(); - } - } - if (this.lcName === 'style' && node.style.setAttribute) { - this.update = updateIEStyleAttribute; - return this.update(); - } - if (this.lcName === 'class' && (!node.namespaceURI || node.namespaceURI === namespaces.html)) { - this.update = updateClassName; - return this.update(); - } - if (node.getAttribute('contenteditable') && this.lcName === 'value') { - this.update = updateContentEditableValue; - return this.update(); - } - this.update = updateEverythingElse; - return this.update(); - }; - updateFileInputValue = function () { - return this; - }; - initSelect = function () { - this.deferredUpdate = this.pNode.multiple ? updateMultipleSelect : updateSelect; - this.deferredUpdate(); - }; - deferSelect = function () { - this.root._deferred.selectValues.push(this); - return this; - }; - updateSelect = function () { - var value = this.fragment.getValue(), options, option, i; - this.value = this.pNode._ractive.value = value; - options = this.pNode.options; - i = options.length; - while (i--) { - option = options[i]; - if (option._ractive.value == value) { - option.selected = true; - return this; - } - } - return this; - }; - updateMultipleSelect = function () { - var value = this.fragment.getValue(), options, i; - if (!isArray(value)) { - value = [value]; - } - options = this.pNode.options; - i = options.length; - while (i--) { - options[i].selected = value.indexOf(options[i]._ractive.value) !== -1; - } - this.value = value; - return this; - }; - updateRadioName = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - node.checked = value == node._ractive.value; - return this; - }; - updateCheckboxName = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (!isArray(value)) { - node.checked = value == node._ractive.value; - return this; - } - node.checked = value.indexOf(node._ractive.value) !== -1; - return this; - }; - updateIEStyleAttribute = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - node.style.setAttribute('cssText', value); - this.value = value; - } - return this; - }; - updateClassName = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - node.className = value; - this.value = value; - } - return this; - }; - updateContentEditableValue = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - if (!this.receiving) { - node.innerHTML = value; - } - this.value = value; - } - return this; - }; - updateEverythingElse = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (this.isValueAttribute) { - node._ractive.value = value; - } - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - if (this.useProperty) { - if (!this.receiving) { - node[this.propertyName] = value; - } - this.value = value; - return this; - } - if (this.namespace) { - node.setAttributeNS(this.namespace, this.name, value); - this.value = value; - return this; - } - if (this.lcName === 'id') { - if (this.value !== undefined) { - this.root.nodes[this.value] = undefined; - } - this.root.nodes[value] = node; - } - node.setAttribute(this.name, value); - this.value = value; - } - return this; - }; - return updateAttribute; - }(utils_isArray, config_namespaces); -var parse_Tokenizer_utils_getStringMatch = function () { - - return function (string) { - var substr; - substr = this.str.substr(this.pos, string.length); - if (substr === string) { - this.pos += string.length; - return string; - } - return null; - }; - }(); -var parse_Tokenizer_utils_allowWhitespace = function () { - - var leadingWhitespace = /^\s+/; - return function () { - var match = leadingWhitespace.exec(this.remaining()); - if (!match) { - return null; - } - this.pos += match[0].length; - return match[0]; - }; - }(); -var parse_Tokenizer_utils_makeRegexMatcher = function () { - - return function (regex) { - return function (tokenizer) { - var match = regex.exec(tokenizer.str.substring(tokenizer.pos)); - if (!match) { - return null; - } - tokenizer.pos += match[0].length; - return match[1] || match[0]; - }; - }; - }(); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getEscapedChars = function () { - - return function (tokenizer) { - var chars = '', character; - character = getEscapedChar(tokenizer); - while (character) { - chars += character; - character = getEscapedChar(tokenizer); - } - return chars || null; - }; - function getEscapedChar(tokenizer) { - var character; - if (!tokenizer.getStringMatch('\\')) { - return null; - } - character = tokenizer.str.charAt(tokenizer.pos); - tokenizer.pos += 1; - return character; - } - }(); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getQuotedString = function (makeRegexMatcher, getEscapedChars) { - - var getUnescapedDoubleQuotedChars = makeRegexMatcher(/^[^\\"]+/), getUnescapedSingleQuotedChars = makeRegexMatcher(/^[^\\']+/); - return function getQuotedString(tokenizer, singleQuotes) { - var start, string, escaped, unescaped, next, matcher; - start = tokenizer.pos; - string = ''; - matcher = singleQuotes ? getUnescapedSingleQuotedChars : getUnescapedDoubleQuotedChars; - escaped = getEscapedChars(tokenizer); - if (escaped) { - string += escaped; - } - unescaped = matcher(tokenizer); - if (unescaped) { - string += unescaped; - } - if (!string) { - return ''; - } - next = getQuotedString(tokenizer, singleQuotes); - while (next !== '') { - string += next; - } - return string; - }; - }(parse_Tokenizer_utils_makeRegexMatcher, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getEscapedChars); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral = function (types, getQuotedString) { - - return function (tokenizer) { - var start, string; - start = tokenizer.pos; - if (tokenizer.getStringMatch('"')) { - string = getQuotedString(tokenizer, false); - if (!tokenizer.getStringMatch('"')) { - tokenizer.pos = start; - return null; - } - return { - t: types.STRING_LITERAL, - v: string - }; - } - if (tokenizer.getStringMatch('\'')) { - string = getQuotedString(tokenizer, true); - if (!tokenizer.getStringMatch('\'')) { - tokenizer.pos = start; - return null; - } - return { - t: types.STRING_LITERAL, - v: string - }; - } - return null; - }; - }(config_types, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getQuotedString); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getNumberLiteral = function (types, makeRegexMatcher) { - - var getNumber = makeRegexMatcher(/^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/); - return function (tokenizer) { - var result; - if (result = getNumber(tokenizer)) { - return { - t: types.NUMBER_LITERAL, - v: result - }; - } - return null; - }; - }(config_types, parse_Tokenizer_utils_makeRegexMatcher); -var parse_Tokenizer_getExpression_shared_getName = function (makeRegexMatcher) { - - return makeRegexMatcher(/^[a-zA-Z_$][a-zA-Z_$0-9]*/); - }(parse_Tokenizer_utils_makeRegexMatcher); -var parse_Tokenizer_getExpression_shared_getKey = function (getStringLiteral, getNumberLiteral, getName) { - - var identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/; - return function (tokenizer) { - var token; - if (token = getStringLiteral(tokenizer)) { - return identifier.test(token.v) ? token.v : '"' + token.v.replace(/"/g, '\\"') + '"'; - } - if (token = getNumberLiteral(tokenizer)) { - return token.v; - } - if (token = getName(tokenizer)) { - return token; - } - }; - }(parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getNumberLiteral, parse_Tokenizer_getExpression_shared_getName); -var utils_parseJSON = function (getStringMatch, allowWhitespace, getStringLiteral, getKey) { - - var Tokenizer, specials, specialsPattern, numberPattern, placeholderPattern, placeholderAtStartPattern; - specials = { - 'true': true, - 'false': false, - 'undefined': undefined, - 'null': null - }; - specialsPattern = new RegExp('^(?:' + Object.keys(specials).join('|') + ')'); - numberPattern = /^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/; - placeholderPattern = /\$\{([^\}]+)\}/g; - placeholderAtStartPattern = /^\$\{([^\}]+)\}/; - Tokenizer = function (str, values) { - this.str = str; - this.values = values; - this.pos = 0; - this.result = this.getToken(); - }; - Tokenizer.prototype = { - remaining: function () { - return this.str.substring(this.pos); - }, - getStringMatch: getStringMatch, - getToken: function () { - this.allowWhitespace(); - return this.getPlaceholder() || this.getSpecial() || this.getNumber() || this.getString() || this.getObject() || this.getArray(); - }, - getPlaceholder: function () { - var match; - if (!this.values) { - return null; - } - if ((match = placeholderAtStartPattern.exec(this.remaining())) && this.values.hasOwnProperty(match[1])) { - this.pos += match[0].length; - return { v: this.values[match[1]] }; - } - }, - getSpecial: function () { - var match; - if (match = specialsPattern.exec(this.remaining())) { - this.pos += match[0].length; - return { v: specials[match[0]] }; - } - }, - getNumber: function () { - var match; - if (match = numberPattern.exec(this.remaining())) { - this.pos += match[0].length; - return { v: +match[0] }; - } - }, - getString: function () { - var stringLiteral = getStringLiteral(this), values; - if (stringLiteral && (values = this.values)) { - return { - v: stringLiteral.v.replace(placeholderPattern, function (match, $1) { - return values[$1] || $1; - }) - }; - } - return stringLiteral; - }, - getObject: function () { - var result, pair; - if (!this.getStringMatch('{')) { - return null; - } - result = {}; - while (pair = getKeyValuePair(this)) { - result[pair.key] = pair.value; - this.allowWhitespace(); - if (this.getStringMatch('}')) { - return { v: result }; - } - if (!this.getStringMatch(',')) { - return null; - } - } - return null; - }, - getArray: function () { - var result, valueToken; - if (!this.getStringMatch('[')) { - return null; - } - result = []; - while (valueToken = this.getToken()) { - result.push(valueToken.v); - if (this.getStringMatch(']')) { - return { v: result }; - } - if (!this.getStringMatch(',')) { - return null; - } - } - return null; - }, - allowWhitespace: allowWhitespace - }; - function getKeyValuePair(tokenizer) { - var key, valueToken, pair; - tokenizer.allowWhitespace(); - key = getKey(tokenizer); - if (!key) { - return null; - } - pair = { key: key }; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(':')) { - return null; - } - tokenizer.allowWhitespace(); - valueToken = tokenizer.getToken(); - if (!valueToken) { - return null; - } - pair.value = valueToken.v; - return pair; - } - return function (str, values) { - var tokenizer = new Tokenizer(str, values); - if (tokenizer.result) { - return { - value: tokenizer.result.v, - remaining: tokenizer.remaining() - }; - } - return null; - }; - }(parse_Tokenizer_utils_getStringMatch, parse_Tokenizer_utils_allowWhitespace, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral, parse_Tokenizer_getExpression_shared_getKey); -var render_StringFragment_Interpolator = function (types, teardown, initMustache, updateMustache, resolveMustache) { - - var StringInterpolator = function (options) { - this.type = types.INTERPOLATOR; - initMustache(this, options); - }; - StringInterpolator.prototype = { - update: updateMustache, - resolve: resolveMustache, - render: function (value) { - this.value = value; - this.parentFragment.bubble(); - }, - teardown: function () { - teardown(this); - }, - toString: function () { - if (this.value == undefined) { - return ''; - } - return stringify(this.value); - } - }; - return StringInterpolator; - function stringify(value) { - if (typeof value === 'string') { - return value; - } - return JSON.stringify(value); - } - }(config_types, shared_teardown, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache); -var render_StringFragment_Section = function (types, initMustache, updateMustache, resolveMustache, updateSection, teardown, circular) { - - var StringSection, StringFragment; - circular.push(function () { - StringFragment = circular.StringFragment; - }); - StringSection = function (options) { - this.type = types.SECTION; - this.fragments = []; - this.length = 0; - initMustache(this, options); - }; - StringSection.prototype = { - update: updateMustache, - resolve: resolveMustache, - teardown: function () { - this.teardownFragments(); - teardown(this); - }, - teardownFragments: function () { - while (this.fragments.length) { - this.fragments.shift().teardown(); - } - this.length = 0; - }, - bubble: function () { - this.value = this.fragments.join(''); - this.parentFragment.bubble(); - }, - render: function (value) { - var wrapped; - if (wrapped = this.root._wrapped[this.keypath]) { - value = wrapped.get(); - } - updateSection(this, value); - this.parentFragment.bubble(); - }, - createFragment: function (options) { - return new StringFragment(options); - }, - toString: function () { - return this.fragments.join(''); - } - }; - return StringSection; - }(config_types, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache, render_shared_updateSection, shared_teardown, circular); -var render_StringFragment_Text = function (types) { - - var StringText = function (text) { - this.type = types.TEXT; - this.text = text; - }; - StringText.prototype = { - toString: function () { - return this.text; - }, - teardown: function () { - } - }; - return StringText; - }(config_types); -var render_StringFragment_prototype_toArgsList = function (warn, parseJSON) { - - return function () { - var values, counter, jsonesque, guid, errorMessage, parsed, processItems; - if (!this.argsList || this.dirty) { - values = {}; - counter = 0; - guid = this.root._guid; - processItems = function (items) { - return items.map(function (item) { - var placeholderId, wrapped, value; - if (item.text) { - return item.text; - } - if (item.fragments) { - return item.fragments.map(function (fragment) { - return processItems(fragment.items); - }).join(''); - } - placeholderId = guid + '-' + counter++; - if (wrapped = item.root._wrapped[item.keypath]) { - value = wrapped.value; - } else { - value = item.value; - } - values[placeholderId] = value; - return '${' + placeholderId + '}'; - }).join(''); - }; - jsonesque = processItems(this.items); - parsed = parseJSON('[' + jsonesque + ']', values); - if (!parsed) { - errorMessage = 'Could not parse directive arguments (' + this.toString() + '). If you think this is a bug, please file an issue at http://github.com/RactiveJS/Ractive/issues'; - if (this.root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - this.argsList = [jsonesque]; - } - } else { - this.argsList = parsed.value; - } - this.dirty = false; - } - return this.argsList; - }; - }(utils_warn, utils_parseJSON); -var render_StringFragment__StringFragment = function (types, parseJSON, initFragment, Interpolator, Section, Text, toArgsList, circular) { - - var StringFragment = function (options) { - initFragment(this, options); - }; - StringFragment.prototype = { - createItem: function (options) { - if (typeof options.descriptor === 'string') { - return new Text(options.descriptor); - } - switch (options.descriptor.t) { - case types.INTERPOLATOR: - return new Interpolator(options); - case types.TRIPLE: - return new Interpolator(options); - case types.SECTION: - return new Section(options); - default: - throw 'Something went wrong in a rather interesting way'; - } - }, - bubble: function () { - this.dirty = true; - this.owner.bubble(); - }, - teardown: function () { - var numItems, i; - numItems = this.items.length; - for (i = 0; i < numItems; i += 1) { - this.items[i].teardown(); - } - }, - getValue: function () { - var value; - if (this.items.length === 1 && this.items[0].type === types.INTERPOLATOR) { - value = this.items[0].value; - if (value !== undefined) { - return value; - } - } - return this.toString(); - }, - isSimple: function () { - var i, item, containsInterpolator; - if (this.simple !== undefined) { - return this.simple; - } - i = this.items.length; - while (i--) { - item = this.items[i]; - if (item.type === types.TEXT) { - continue; - } - if (item.type === types.INTERPOLATOR) { - if (containsInterpolator) { - return false; - } else { - containsInterpolator = true; - continue; - } - } - return this.simple = false; - } - return this.simple = true; - }, - toString: function () { - return this.items.join(''); - }, - toJSON: function () { - var value = this.getValue(), parsed; - if (typeof value === 'string') { - parsed = parseJSON(value); - value = parsed ? parsed.value : value; - } - return value; - }, - toArgsList: toArgsList - }; - circular.StringFragment = StringFragment; - return StringFragment; - }(config_types, utils_parseJSON, render_shared_initFragment, render_StringFragment_Interpolator, render_StringFragment_Section, render_StringFragment_Text, render_StringFragment_prototype_toArgsList, circular); -var render_DomFragment_Attribute__Attribute = function (types, determineNameAndNamespace, setStaticAttribute, determinePropertyName, bind, update, StringFragment) { - - var DomAttribute = function (options) { - this.type = types.ATTRIBUTE; - this.element = options.element; - determineNameAndNamespace(this, options.name); - if (options.value === null || typeof options.value === 'string') { - setStaticAttribute(this, options); - return; - } - this.root = options.root; - this.pNode = options.pNode; - this.parentFragment = this.element.parentFragment; - this.fragment = new StringFragment({ - descriptor: options.value, - root: this.root, - owner: this, - contextStack: options.contextStack - }); - if (!this.pNode) { - return; - } - if (this.name === 'value') { - this.isValueAttribute = true; - if (this.pNode.tagName === 'INPUT' && this.pNode.type === 'file') { - this.isFileInputValue = true; - } - } - determinePropertyName(this, options); - this.selfUpdating = this.fragment.isSimple(); - this.ready = true; - }; - DomAttribute.prototype = { - bind: bind, - update: update, - updateBindings: function () { - this.keypath = this.interpolator.keypath || this.interpolator.ref; - if (this.propertyName === 'name') { - this.pNode.name = '{{' + this.keypath + '}}'; - } - }, - teardown: function () { - var i; - if (this.boundEvents) { - i = this.boundEvents.length; - while (i--) { - this.pNode.removeEventListener(this.boundEvents[i], this.updateModel, false); - } - } - if (this.fragment) { - this.fragment.teardown(); - } - }, - bubble: function () { - if (this.selfUpdating) { - this.update(); - } else if (!this.deferred && this.ready) { - this.root._deferred.attrs.push(this); - this.deferred = true; - } - }, - toString: function () { - var str; - if (this.value === null) { - return this.name; - } - if (!this.fragment) { - return this.name + '=' + JSON.stringify(this.value); - } - str = this.fragment.toString(); - return this.name + '=' + JSON.stringify(str); - } - }; - return DomAttribute; - }(config_types, render_DomFragment_Attribute_helpers_determineNameAndNamespace, render_DomFragment_Attribute_helpers_setStaticAttribute, render_DomFragment_Attribute_helpers_determinePropertyName, render_DomFragment_Attribute_prototype_bind, render_DomFragment_Attribute_prototype_update, render_StringFragment__StringFragment); -var render_DomFragment_Element_initialise_createElementAttributes = function (DomAttribute) { - - return function (element, attributes) { - var attrName, attrValue, attr; - element.attributes = []; - for (attrName in attributes) { - if (attributes.hasOwnProperty(attrName)) { - attrValue = attributes[attrName]; - attr = new DomAttribute({ - element: element, - name: attrName, - value: attrValue, - root: element.root, - pNode: element.node, - contextStack: element.parentFragment.contextStack - }); - element.attributes[element.attributes.length] = element.attributes[attrName] = attr; - if (attrName !== 'name') { - attr.update(); - } - } - } - return element.attributes; - }; - }(render_DomFragment_Attribute__Attribute); -var render_DomFragment_Element_initialise_appendElementChildren = function (warn, namespaces, StringFragment, circular) { - - var DomFragment, updateCss, updateScript; - circular.push(function () { - DomFragment = circular.DomFragment; - }); - updateCss = function () { - var node = this.node, content = this.fragment.toString(); - if (node.styleSheet) { - node.styleSheet.cssText = content; - } - node.innerHTML = content; - }; - updateScript = function () { - if (!this.node.type || this.node.type === 'text/javascript') { - warn('Script tag was updated. This does not cause the code to be re-evaluated!'); - } - this.node.innerHTML = this.fragment.toString(); - }; - return function (element, node, descriptor, docFrag) { - var liveQueries, i, selector, queryAllResult, j; - if (element.lcName === 'script' || element.lcName === 'style') { - element.fragment = new StringFragment({ - descriptor: descriptor.f, - root: element.root, - contextStack: element.parentFragment.contextStack, - owner: element - }); - if (docFrag) { - if (element.lcName === 'script') { - element.bubble = updateScript; - element.node.innerHTML = element.fragment.toString(); - } else { - element.bubble = updateCss; - element.bubble(); - } - } - return; - } - if (typeof descriptor.f === 'string' && (!node || (!node.namespaceURI || node.namespaceURI === namespaces.html))) { - element.html = descriptor.f; - if (docFrag) { - node.innerHTML = element.html; - liveQueries = element.root._liveQueries; - i = liveQueries.length; - while (i--) { - selector = liveQueries[i]; - if ((queryAllResult = node.querySelectorAll(selector)) && (j = queryAllResult.length)) { - (element.liveQueries || (element.liveQueries = [])).push(selector); - element.liveQueries[selector] = []; - while (j--) { - element.liveQueries[selector][j] = queryAllResult[j]; - } - } - } - } - } else { - element.fragment = new DomFragment({ - descriptor: descriptor.f, - root: element.root, - pNode: node, - contextStack: element.parentFragment.contextStack, - owner: element - }); - if (docFrag) { - node.appendChild(element.fragment.docFrag); - } - } - }; - }(utils_warn, config_namespaces, render_StringFragment__StringFragment, circular); -var render_DomFragment_Element_initialise_decorate_Decorator = function (warn, StringFragment) { - - var Decorator = function (descriptor, root, owner, contextStack) { - var name, fragment, errorMessage; - this.root = root; - this.node = owner.node; - name = descriptor.n || descriptor; - if (typeof name !== 'string') { - fragment = new StringFragment({ - descriptor: name, - root: this.root, - owner: owner, - contextStack: contextStack - }); - name = fragment.toString(); - fragment.teardown(); - } - if (descriptor.a) { - this.params = descriptor.a; - } else if (descriptor.d) { - fragment = new StringFragment({ - descriptor: descriptor.d, - root: this.root, - owner: owner, - contextStack: contextStack - }); - this.params = fragment.toArgsList(); - fragment.teardown(); - } - this.fn = root.decorators[name]; - if (!this.fn) { - errorMessage = 'Missing "' + name + '" decorator. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#decorators'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - } - }; - Decorator.prototype = { - init: function () { - var result, args; - if (this.params) { - args = [this.node].concat(this.params); - result = this.fn.apply(this.root, args); - } else { - result = this.fn.call(this.root, this.node); - } - if (!result || !result.teardown) { - throw new Error('Decorator definition must return an object with a teardown method'); - } - this.teardown = result.teardown; - } - }; - return Decorator; - }(utils_warn, render_StringFragment__StringFragment); -var render_DomFragment_Element_initialise_decorate__decorate = function (Decorator) { - - return function (descriptor, root, owner, contextStack) { - owner.decorator = new Decorator(descriptor, root, owner, contextStack); - if (owner.decorator.fn) { - root._deferred.decorators.push(owner.decorator); - } - }; - }(render_DomFragment_Element_initialise_decorate_Decorator); -var render_DomFragment_Element_initialise_addEventProxies_addEventProxy = function (warn, StringFragment) { - - var addEventProxy, MasterEventHandler, ProxyEvent, firePlainEvent, fireEventWithArgs, fireEventWithDynamicArgs, customHandlers, genericHandler, getCustomHandler; - addEventProxy = function (element, triggerEventName, proxyDescriptor, contextStack, indexRefs) { - var events, master; - events = element.node._ractive.events; - master = events[triggerEventName] || (events[triggerEventName] = new MasterEventHandler(element, triggerEventName, contextStack, indexRefs)); - master.add(proxyDescriptor); - }; - MasterEventHandler = function (element, eventName, contextStack) { - var definition; - this.element = element; - this.root = element.root; - this.node = element.node; - this.name = eventName; - this.contextStack = contextStack; - this.proxies = []; - if (definition = this.root.events[eventName]) { - this.custom = definition(this.node, getCustomHandler(eventName)); - } else { - if (!('on' + eventName in this.node)) { - warn('Missing "' + this.name + '" event. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#events'); - } - this.node.addEventListener(eventName, genericHandler, false); - } - }; - MasterEventHandler.prototype = { - add: function (proxy) { - this.proxies[this.proxies.length] = new ProxyEvent(this.element, this.root, proxy, this.contextStack); - }, - teardown: function () { - var i; - if (this.custom) { - this.custom.teardown(); - } else { - this.node.removeEventListener(this.name, genericHandler, false); - } - i = this.proxies.length; - while (i--) { - this.proxies[i].teardown(); - } - }, - fire: function (event) { - var i = this.proxies.length; - while (i--) { - this.proxies[i].fire(event); - } - } - }; - ProxyEvent = function (element, ractive, descriptor, contextStack) { - var name; - this.root = ractive; - name = descriptor.n || descriptor; - if (typeof name === 'string') { - this.n = name; - } else { - this.n = new StringFragment({ - descriptor: descriptor.n, - root: this.root, - owner: element, - contextStack: contextStack - }); - } - if (descriptor.a) { - this.a = descriptor.a; - this.fire = fireEventWithArgs; - return; - } - if (descriptor.d) { - this.d = new StringFragment({ - descriptor: descriptor.d, - root: this.root, - owner: element, - contextStack: contextStack - }); - this.fire = fireEventWithDynamicArgs; - return; - } - this.fire = firePlainEvent; - }; - ProxyEvent.prototype = { - teardown: function () { - if (this.n.teardown) { - this.n.teardown(); - } - if (this.d) { - this.d.teardown(); - } - }, - bubble: function () { - } - }; - firePlainEvent = function (event) { - this.root.fire(this.n.toString(), event); - }; - fireEventWithArgs = function (event) { - this.root.fire.apply(this.root, [ - this.n.toString(), - event - ].concat(this.a)); - }; - fireEventWithDynamicArgs = function (event) { - var args = this.d.toArgsList(); - if (typeof args === 'string') { - args = args.substr(1, args.length - 2); - } - this.root.fire.apply(this.root, [ - this.n.toString(), - event - ].concat(args)); - }; - genericHandler = function (event) { - var storage = this._ractive; - storage.events[event.type].fire({ - node: this, - original: event, - index: storage.index, - keypath: storage.keypath, - context: storage.root.get(storage.keypath) - }); - }; - customHandlers = {}; - getCustomHandler = function (eventName) { - if (customHandlers[eventName]) { - return customHandlers[eventName]; - } - return customHandlers[eventName] = function (event) { - var storage = event.node._ractive; - event.index = storage.index; - event.keypath = storage.keypath; - event.context = storage.root.get(storage.keypath); - storage.events[eventName].fire(event); - }; - }; - return addEventProxy; - }(utils_warn, render_StringFragment__StringFragment); -var render_DomFragment_Element_initialise_addEventProxies__addEventProxies = function (addEventProxy) { - - return function (element, proxies) { - var i, eventName, eventNames; - for (eventName in proxies) { - if (proxies.hasOwnProperty(eventName)) { - eventNames = eventName.split('-'); - i = eventNames.length; - while (i--) { - addEventProxy(element, eventNames[i], proxies[eventName], element.parentFragment.contextStack); - } - } - } - }; - }(render_DomFragment_Element_initialise_addEventProxies_addEventProxy); -var render_DomFragment_Element_initialise_updateLiveQueries = function () { - - return function (element) { - var ractive, liveQueries, i, selector, query; - ractive = element.root; - liveQueries = ractive._liveQueries; - i = liveQueries.length; - while (i--) { - selector = liveQueries[i]; - query = liveQueries[selector]; - if (query._test(element)) { - (element.liveQueries || (element.liveQueries = [])).push(selector); - element.liveQueries[selector] = [element.node]; - } - } - }; - }(); -var utils_camelCase = function () { - - return function (hyphenatedStr) { - return hyphenatedStr.replace(/-([a-zA-Z])/g, function (match, $1) { - return $1.toUpperCase(); - }); - }; - }(); -var utils_fillGaps = function () { - - return function (target, source) { - var key; - for (key in source) { - if (source.hasOwnProperty(key) && !target.hasOwnProperty(key)) { - target[key] = source[key]; - } - } - return target; - }; - }(); -var render_DomFragment_Element_shared_executeTransition_Transition = function (isClient, createElement, warn, isNumeric, isArray, camelCase, fillGaps, StringFragment) { - - var Transition, testStyle, vendors, vendorPattern, unprefixPattern, prefixCache, CSS_TRANSITIONS_ENABLED, TRANSITION, TRANSITION_DURATION, TRANSITION_PROPERTY, TRANSITION_TIMING_FUNCTION, TRANSITIONEND; - if (!isClient) { - return; - } - testStyle = createElement('div').style; - (function () { - if (testStyle.transition !== undefined) { - TRANSITION = 'transition'; - TRANSITIONEND = 'transitionend'; - CSS_TRANSITIONS_ENABLED = true; - } else if (testStyle.webkitTransition !== undefined) { - TRANSITION = 'webkitTransition'; - TRANSITIONEND = 'webkitTransitionEnd'; - CSS_TRANSITIONS_ENABLED = true; - } else { - CSS_TRANSITIONS_ENABLED = false; - } - }()); - if (TRANSITION) { - TRANSITION_DURATION = TRANSITION + 'Duration'; - TRANSITION_PROPERTY = TRANSITION + 'Property'; - TRANSITION_TIMING_FUNCTION = TRANSITION + 'TimingFunction'; - } - Transition = function (descriptor, root, owner, contextStack, isIntro) { - var t = this, name, fragment, errorMessage; - this.root = root; - this.node = owner.node; - this.isIntro = isIntro; - this.originalStyle = this.node.getAttribute('style'); - this.complete = function (noReset) { - if (!noReset && t.isIntro) { - t.resetStyle(); - } - t._manager.pop(t.node); - t.node._ractive.transition = null; - }; - name = descriptor.n || descriptor; - if (typeof name !== 'string') { - fragment = new StringFragment({ - descriptor: name, - root: this.root, - owner: owner, - contextStack: contextStack - }); - name = fragment.toString(); - fragment.teardown(); - } - this.name = name; - if (descriptor.a) { - this.params = descriptor.a; - } else if (descriptor.d) { - fragment = new StringFragment({ - descriptor: descriptor.d, - root: this.root, - owner: owner, - contextStack: contextStack - }); - this.params = fragment.toArgsList(); - fragment.teardown(); - } - this._fn = root.transitions[name]; - if (!this._fn) { - errorMessage = 'Missing "' + name + '" transition. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#transitions'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - return; - } - }; - Transition.prototype = { - init: function () { - if (this._inited) { - throw new Error('Cannot initialize a transition more than once'); - } - this._inited = true; - this._fn.apply(this.root, [this].concat(this.params)); - }, - getStyle: function (props) { - var computedStyle, styles, i, prop, value; - computedStyle = window.getComputedStyle(this.node); - if (typeof props === 'string') { - value = computedStyle[prefix(props)]; - if (value === '0px') { - value = 0; - } - return value; - } - if (!isArray(props)) { - throw new Error('Transition#getStyle must be passed a string, or an array of strings representing CSS properties'); - } - styles = {}; - i = props.length; - while (i--) { - prop = props[i]; - value = computedStyle[prefix(prop)]; - if (value === '0px') { - value = 0; - } - styles[prop] = value; - } - return styles; - }, - setStyle: function (style, value) { - var prop; - if (typeof style === 'string') { - this.node.style[prefix(style)] = value; - } else { - for (prop in style) { - if (style.hasOwnProperty(prop)) { - this.node.style[prefix(prop)] = style[prop]; - } - } - } - return this; - }, - animateStyle: function (style, value, options, complete) { - var t = this, propertyNames, changedProperties, computedStyle, current, to, from, transitionEndHandler, i, prop; - if (typeof style === 'string') { - to = {}; - to[style] = value; - } else { - to = style; - complete = options; - options = value; - } - if (!options) { - warn('The "' + t.name + '" transition does not supply an options object to `t.animateStyle()`. This will break in a future version of Ractive. For more info see https://github.com/RactiveJS/Ractive/issues/340'); - options = t; - complete = t.complete; - } - if (!options.duration) { - t.setStyle(to); - if (complete) { - complete(); - } - } - propertyNames = Object.keys(to); - changedProperties = []; - computedStyle = window.getComputedStyle(t.node); - from = {}; - i = propertyNames.length; - while (i--) { - prop = propertyNames[i]; - current = computedStyle[prefix(prop)]; - if (current === '0px') { - current = 0; - } - if (current != to[prop]) { - changedProperties[changedProperties.length] = prop; - t.node.style[prefix(prop)] = current; - } - } - if (!changedProperties.length) { - if (complete) { - complete(); - } - return; - } - setTimeout(function () { - t.node.style[TRANSITION_PROPERTY] = propertyNames.map(prefix).map(hyphenate).join(','); - t.node.style[TRANSITION_TIMING_FUNCTION] = hyphenate(options.easing || 'linear'); - t.node.style[TRANSITION_DURATION] = options.duration / 1000 + 's'; - transitionEndHandler = function (event) { - var index; - index = changedProperties.indexOf(camelCase(unprefix(event.propertyName))); - if (index !== -1) { - changedProperties.splice(index, 1); - } - if (changedProperties.length) { - return; - } - t.root.fire(t.name + ':end'); - t.node.removeEventListener(TRANSITIONEND, transitionEndHandler, false); - if (complete) { - complete(); - } - }; - t.node.addEventListener(TRANSITIONEND, transitionEndHandler, false); - setTimeout(function () { - var i = changedProperties.length; - while (i--) { - prop = changedProperties[i]; - t.node.style[prefix(prop)] = to[prop]; - } - }, 0); - }, options.delay || 0); - }, - resetStyle: function () { - if (this.originalStyle) { - this.node.setAttribute('style', this.originalStyle); - } else { - this.node.getAttribute('style'); - this.node.removeAttribute('style'); - } - }, - processParams: function (params, defaults) { - if (typeof params === 'number') { - params = { duration: params }; - } else if (typeof params === 'string') { - if (params === 'slow') { - params = { duration: 600 }; - } else if (params === 'fast') { - params = { duration: 200 }; - } else { - params = { duration: 400 }; - } - } else if (!params) { - params = {}; - } - return fillGaps(params, defaults); - } - }; - vendors = [ - 'o', - 'ms', - 'moz', - 'webkit' - ]; - vendorPattern = new RegExp('^(?:' + vendors.join('|') + ')([A-Z])'); - unprefixPattern = new RegExp('^-(?:' + vendors.join('|') + ')-'); - prefixCache = {}; - function prefix(prop) { - var i, vendor, capped; - if (!prefixCache[prop]) { - if (testStyle[prop] !== undefined) { - prefixCache[prop] = prop; - } else { - capped = prop.charAt(0).toUpperCase() + prop.substring(1); - i = vendors.length; - while (i--) { - vendor = vendors[i]; - if (testStyle[vendor + capped] !== undefined) { - prefixCache[prop] = vendor + capped; - break; - } - } - } - } - return prefixCache[prop]; - } - function unprefix(prop) { - return prop.replace(unprefixPattern, ''); - } - function hyphenate(str) { - var hyphenated; - if (vendorPattern.test(str)) { - str = '-' + str; - } - hyphenated = str.replace(/[A-Z]/g, function (match) { - return '-' + match.toLowerCase(); - }); - return hyphenated; - } - return Transition; - }(config_isClient, utils_createElement, utils_warn, utils_isNumeric, utils_isArray, utils_camelCase, utils_fillGaps, render_StringFragment__StringFragment); -var render_DomFragment_Element_shared_executeTransition__executeTransition = function (warn, Transition) { - - return function (descriptor, root, owner, contextStack, isIntro) { - var transition, node, oldTransition; - if (!root.transitionsEnabled || root._parent && !root._parent.transitionsEnabled) { - return; - } - transition = new Transition(descriptor, root, owner, contextStack, isIntro); - if (transition._fn) { - node = transition.node; - transition._manager = root._transitionManager; - if (oldTransition = node._ractive.transition) { - oldTransition.complete(); - } - node._ractive.transition = transition; - transition._manager.push(node); - if (isIntro) { - root._deferred.transitions.push(transition); - } else { - transition.init(); - } - } - }; - }(utils_warn, render_DomFragment_Element_shared_executeTransition_Transition); -var render_DomFragment_Element_initialise__initialise = function (types, namespaces, create, defineProperty, matches, warn, createElement, getElementNamespace, createElementAttributes, appendElementChildren, decorate, addEventProxies, updateLiveQueries, executeTransition, enforceCase) { - - return function (element, options, docFrag) { - var parentFragment, pNode, contextStack, descriptor, namespace, name, attributes, width, height, loadHandler, root, selectBinding, errorMessage; - element.type = types.ELEMENT; - parentFragment = element.parentFragment = options.parentFragment; - pNode = parentFragment.pNode; - contextStack = parentFragment.contextStack; - descriptor = element.descriptor = options.descriptor; - element.root = root = parentFragment.root; - element.index = options.index; - element.lcName = descriptor.e.toLowerCase(); - element.eventListeners = []; - element.customEventListeners = []; - if (pNode) { - namespace = element.namespace = getElementNamespace(descriptor, pNode); - name = namespace !== namespaces.html ? enforceCase(descriptor.e) : descriptor.e; - element.node = createElement(name, namespace); - defineProperty(element.node, '_ractive', { - value: { - proxy: element, - keypath: contextStack.length ? contextStack[contextStack.length - 1] : '', - index: parentFragment.indexRefs, - events: create(null), - root: root - } - }); - } - attributes = createElementAttributes(element, descriptor.a); - if (descriptor.f) { - if (element.node && element.node.getAttribute('contenteditable')) { - if (element.node.innerHTML) { - errorMessage = 'A pre-populated contenteditable element should not have children'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - } - } - appendElementChildren(element, element.node, descriptor, docFrag); - } - if (docFrag && descriptor.v) { - addEventProxies(element, descriptor.v); - } - if (docFrag) { - if (root.twoway) { - element.bind(); - if (element.node.getAttribute('contenteditable') && element.node._ractive.binding) { - element.node._ractive.binding.update(); - } - } - if (attributes.name && !attributes.name.twoway) { - attributes.name.update(); - } - if (element.node.tagName === 'IMG' && ((width = element.attributes.width) || (height = element.attributes.height))) { - element.node.addEventListener('load', loadHandler = function () { - if (width) { - element.node.width = width.value; - } - if (height) { - element.node.height = height.value; - } - element.node.removeEventListener('load', loadHandler, false); - }, false); - } - docFrag.appendChild(element.node); - if (descriptor.o) { - decorate(descriptor.o, root, element, contextStack); - } - if (descriptor.t1) { - executeTransition(descriptor.t1, root, element, contextStack, true); - } - if (element.node.tagName === 'OPTION') { - if (pNode.tagName === 'SELECT' && (selectBinding = pNode._ractive.binding)) { - selectBinding.deferUpdate(); - } - if (element.node._ractive.value == pNode._ractive.value) { - element.node.selected = true; - } - } - if (element.node.autofocus) { - root._deferred.focusable = element.node; - } - } - updateLiveQueries(element); - }; - }(config_types, config_namespaces, utils_create, utils_defineProperty, utils_matches, utils_warn, utils_createElement, render_DomFragment_Element_initialise_getElementNamespace, render_DomFragment_Element_initialise_createElementAttributes, render_DomFragment_Element_initialise_appendElementChildren, render_DomFragment_Element_initialise_decorate__decorate, render_DomFragment_Element_initialise_addEventProxies__addEventProxies, render_DomFragment_Element_initialise_updateLiveQueries, render_DomFragment_Element_shared_executeTransition__executeTransition, render_DomFragment_shared_enforceCase); -var render_DomFragment_Element_prototype_teardown = function (executeTransition) { - - return function (destroy) { - var eventName, binding, bindings, i, liveQueries, selector, query, nodesToRemove, j; - if (this.fragment) { - this.fragment.teardown(false); - } - while (this.attributes.length) { - this.attributes.pop().teardown(); - } - if (this.node) { - for (eventName in this.node._ractive.events) { - this.node._ractive.events[eventName].teardown(); - } - if (binding = this.node._ractive.binding) { - binding.teardown(); - bindings = this.root._twowayBindings[binding.attr.keypath]; - bindings.splice(bindings.indexOf(binding), 1); - } - } - if (this.decorator) { - this.decorator.teardown(); - } - if (this.descriptor.t2) { - executeTransition(this.descriptor.t2, this.root, this, this.parentFragment.contextStack, false); - } - if (destroy) { - this.root._transitionManager.detachWhenReady(this); - } - if (liveQueries = this.liveQueries) { - i = liveQueries.length; - while (i--) { - selector = liveQueries[i]; - if (nodesToRemove = this.liveQueries[selector]) { - j = nodesToRemove.length; - query = this.root._liveQueries[selector]; - while (j--) { - query._remove(nodesToRemove[j]); - } - } - } - } - }; - }(render_DomFragment_Element_shared_executeTransition__executeTransition); -var config_voidElementNames = function () { - - return 'area base br col command doctype embed hr img input keygen link meta param source track wbr'.split(' '); - }(); -var render_DomFragment_Element_prototype_toString = function (voidElementNames) { - - return function () { - var str, i, len; - str = '<' + (this.descriptor.y ? '!doctype' : this.descriptor.e); - len = this.attributes.length; - for (i = 0; i < len; i += 1) { - str += ' ' + this.attributes[i].toString(); - } - str += '>'; - if (this.html) { - str += this.html; - } else if (this.fragment) { - str += this.fragment.toString(); - } - if (voidElementNames.indexOf(this.descriptor.e) === -1) { - str += '' + this.descriptor.e + '>'; - } - return str; - }; - }(config_voidElementNames); -var render_DomFragment_Element_prototype_find = function (matches) { - - return function (selector) { - var queryResult; - if (matches(this.node, selector)) { - return this.node; - } - if (this.html && (queryResult = this.node.querySelector(selector))) { - return queryResult; - } - if (this.fragment && this.fragment.find) { - return this.fragment.find(selector); - } - }; - }(utils_matches); -var render_DomFragment_Element_prototype_findAll = function () { - - return function (selector, query) { - var queryAllResult, i, numNodes, node, registeredNodes; - if (query._test(this, true) && query.live) { - (this.liveQueries || (this.liveQueries = [])).push(selector); - this.liveQueries[selector] = [this.node]; - } - if (this.html && (queryAllResult = this.node.querySelectorAll(selector)) && (numNodes = queryAllResult.length)) { - if (query.live) { - if (!this.liveQueries[selector]) { - (this.liveQueries || (this.liveQueries = [])).push(selector); - this.liveQueries[selector] = []; - } - registeredNodes = this.liveQueries[selector]; - } - for (i = 0; i < numNodes; i += 1) { - node = queryAllResult[i]; - query.push(node); - if (query.live) { - registeredNodes.push(node); - } - } - } - if (this.fragment) { - this.fragment.findAll(selector, query); - } - }; - }(); -var render_DomFragment_Element_prototype_findComponent = function () { - - return function (selector) { - if (this.fragment) { - return this.fragment.findComponent(selector); - } - }; - }(); -var render_DomFragment_Element_prototype_findAllComponents = function () { - - return function (selector, query) { - if (this.fragment) { - this.fragment.findAllComponents(selector, query); - } - }; - }(); -var render_DomFragment_Element_prototype_bind = function () { - - return function () { - var attributes = this.attributes; - if (!this.node) { - return; - } - if (this.binding) { - this.binding.teardown(); - this.binding = null; - } - if (this.node.getAttribute('contenteditable') && attributes.value && attributes.value.bind()) { - return; - } - switch (this.descriptor.e) { - case 'select': - case 'textarea': - if (attributes.value) { - attributes.value.bind(); - } - return; - case 'input': - if (this.node.type === 'radio' || this.node.type === 'checkbox') { - if (attributes.name && attributes.name.bind()) { - return; - } - if (attributes.checked && attributes.checked.bind()) { - return; - } - } - if (attributes.value && attributes.value.bind()) { - return; - } - } - }; - }(); -var render_DomFragment_Element__Element = function (initialise, teardown, toString, find, findAll, findComponent, findAllComponents, bind) { - - var DomElement = function (options, docFrag) { - initialise(this, options, docFrag); - }; - DomElement.prototype = { - detach: function () { - if (this.node) { - if (this.node.parentNode) { - this.node.parentNode.removeChild(this.node); - } - return this.node; - } - }, - teardown: teardown, - firstNode: function () { - return this.node; - }, - findNextNode: function () { - return null; - }, - bubble: function () { - }, - toString: toString, - find: find, - findAll: findAll, - findComponent: findComponent, - findAllComponents: findAllComponents, - bind: bind - }; - return DomElement; - }(render_DomFragment_Element_initialise__initialise, render_DomFragment_Element_prototype_teardown, render_DomFragment_Element_prototype_toString, render_DomFragment_Element_prototype_find, render_DomFragment_Element_prototype_findAll, render_DomFragment_Element_prototype_findComponent, render_DomFragment_Element_prototype_findAllComponents, render_DomFragment_Element_prototype_bind); -var config_errors = { missingParser: 'Missing Ractive.parse - cannot parse template. Either preparse or use the version that includes the parser' }; -var registries_partials = {}; -var render_DomFragment_Partial_getPartialDescriptor = function (errors, isClient, warn, isObject, partials, parse) { - - var getPartialDescriptor, registerPartial, getPartialFromRegistry, unpack; - getPartialDescriptor = function (root, name) { - var el, partial, errorMessage; - if (partial = getPartialFromRegistry(root, name)) { - return partial; - } - if (isClient) { - el = document.getElementById(name); - if (el && el.tagName === 'SCRIPT') { - if (!parse) { - throw new Error(errors.missingParser); - } - registerPartial(parse(el.innerHTML), name, partials); - } - } - partial = partials[name]; - if (!partial) { - errorMessage = 'Could not find descriptor for partial "' + name + '"'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - return []; - } - return unpack(partial); - }; - getPartialFromRegistry = function (registryOwner, name) { - var partial; - if (registryOwner.partials[name]) { - if (typeof registryOwner.partials[name] === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - partial = parse(registryOwner.partials[name], registryOwner.parseOptions); - registerPartial(partial, name, registryOwner.partials); - } - return unpack(registryOwner.partials[name]); - } - }; - registerPartial = function (partial, name, registry) { - var key; - if (isObject(partial)) { - registry[name] = partial.main; - for (key in partial.partials) { - if (partial.partials.hasOwnProperty(key)) { - registry[key] = partial.partials[key]; - } - } - } else { - registry[name] = partial; - } - }; - unpack = function (partial) { - if (partial.length === 1 && typeof partial[0] === 'string') { - return partial[0]; - } - return partial; - }; - return getPartialDescriptor; - }(config_errors, config_isClient, utils_warn, utils_isObject, registries_partials, parse__parse); -var render_DomFragment_Partial__Partial = function (types, getPartialDescriptor, circular) { - - var DomPartial, DomFragment; - circular.push(function () { - DomFragment = circular.DomFragment; - }); - DomPartial = function (options, docFrag) { - var parentFragment = this.parentFragment = options.parentFragment, descriptor; - this.type = types.PARTIAL; - this.name = options.descriptor.r; - this.index = options.index; - if (!options.descriptor.r) { - throw new Error('Partials must have a static reference (no expressions). This may change in a future version of Ractive.'); - } - descriptor = getPartialDescriptor(parentFragment.root, options.descriptor.r); - this.fragment = new DomFragment({ - descriptor: descriptor, - root: parentFragment.root, - pNode: parentFragment.pNode, - contextStack: parentFragment.contextStack, - owner: this - }); - if (docFrag) { - docFrag.appendChild(this.fragment.docFrag); - } - }; - DomPartial.prototype = { - firstNode: function () { - return this.fragment.firstNode(); - }, - findNextNode: function () { - return this.parentFragment.findNextNode(this); - }, - detach: function () { - return this.fragment.detach(); - }, - teardown: function (destroy) { - this.fragment.teardown(destroy); - }, - toString: function () { - return this.fragment.toString(); - }, - find: function (selector) { - return this.fragment.find(selector); - }, - findAll: function (selector, query) { - return this.fragment.findAll(selector, query); - }, - findComponent: function (selector) { - return this.fragment.findComponent(selector); - }, - findAllComponents: function (selector, query) { - return this.fragment.findAllComponents(selector, query); - } - }; - return DomPartial; - }(config_types, render_DomFragment_Partial_getPartialDescriptor, circular); -var render_DomFragment_Component_initialise_createModel_ComponentParameter = function (StringFragment) { - - var ComponentParameter = function (component, key, value) { - this.parentFragment = component.parentFragment; - this.component = component; - this.key = key; - this.fragment = new StringFragment({ - descriptor: value, - root: component.root, - owner: this, - contextStack: component.parentFragment.contextStack - }); - this.selfUpdating = this.fragment.isSimple(); - this.value = this.fragment.getValue(); - }; - ComponentParameter.prototype = { - bubble: function () { - if (this.selfUpdating) { - this.update(); - } else if (!this.deferred && this.ready) { - this.root._deferred.attrs.push(this); - this.deferred = true; - } - }, - update: function () { - var value = this.fragment.getValue(); - this.component.instance.set(this.key, value); - this.value = value; - }, - teardown: function () { - this.fragment.teardown(); - } - }; - return ComponentParameter; - }(render_StringFragment__StringFragment); -var render_DomFragment_Component_initialise_createModel__createModel = function (types, parseJSON, resolveRef, ComponentParameter) { - - return function (component, attributes, toBind) { - var data, key, value; - data = {}; - component.complexParameters = []; - for (key in attributes) { - if (attributes.hasOwnProperty(key)) { - value = getValue(component, key, attributes[key], toBind); - if (value !== undefined) { - data[key] = value; - } - } - } - return data; - }; - function getValue(component, key, descriptor, toBind) { - var parameter, parsed, root, parentFragment, keypath; - root = component.root; - parentFragment = component.parentFragment; - if (typeof descriptor === 'string') { - parsed = parseJSON(descriptor); - return parsed ? parsed.value : descriptor; - } - if (descriptor === null) { - return true; - } - if (descriptor.length === 1 && descriptor[0].t === types.INTERPOLATOR && descriptor[0].r) { - if (parentFragment.indexRefs && parentFragment.indexRefs[descriptor[0].r] !== undefined) { - return parentFragment.indexRefs[descriptor[0].r]; - } - keypath = resolveRef(root, descriptor[0].r, parentFragment.contextStack) || descriptor[0].r; - toBind.push({ - childKeypath: key, - parentKeypath: keypath - }); - return root.get(keypath); - } - parameter = new ComponentParameter(component, key, descriptor); - component.complexParameters.push(parameter); - return parameter.value; - } - }(config_types, utils_parseJSON, shared_resolveRef, render_DomFragment_Component_initialise_createModel_ComponentParameter); -var render_DomFragment_Component_initialise_createInstance = function () { - - return function (component, Component, data, docFrag, contentDescriptor) { - var instance, parentFragment, partials, root; - parentFragment = component.parentFragment; - root = component.root; - partials = { content: contentDescriptor || [] }; - instance = new Component({ - el: parentFragment.pNode.cloneNode(false), - data: data, - partials: partials, - _parent: root, - adaptors: root.adaptors - }); - instance.component = component; - component.instance = instance; - instance.insert(docFrag); - instance.fragment.pNode = parentFragment.pNode; - return instance; - }; - }(); -var render_DomFragment_Component_initialise_createObservers = function () { - - var observeOptions = { - init: false, - debug: true - }; - return function (component, toBind) { - var pair, i; - component.observers = []; - i = toBind.length; - while (i--) { - pair = toBind[i]; - bind(component, pair.parentKeypath, pair.childKeypath); - } - }; - function bind(component, parentKeypath, childKeypath) { - var parentInstance, childInstance, settingParent, settingChild, observers, observer, value; - parentInstance = component.root; - childInstance = component.instance; - observers = component.observers; - observer = parentInstance.observe(parentKeypath, function (value) { - if (!settingParent && !parentInstance._wrapped[parentKeypath]) { - settingChild = true; - childInstance.set(childKeypath, value); - settingChild = false; - } - }, observeOptions); - observers.push(observer); - if (childInstance.twoway) { - observer = childInstance.observe(childKeypath, function (value) { - if (!settingChild) { - settingParent = true; - parentInstance.set(parentKeypath, value); - settingParent = false; - } - }, observeOptions); - observers.push(observer); - value = childInstance.get(childKeypath); - if (value !== undefined) { - parentInstance.set(parentKeypath, value); - } - } - } - }(); -var render_DomFragment_Component_initialise_propagateEvents = function (warn) { - - var errorMessage = 'Components currently only support simple events - you cannot include arguments. Sorry!'; - return function (component, eventsDescriptor) { - var eventName; - for (eventName in eventsDescriptor) { - if (eventsDescriptor.hasOwnProperty(eventName)) { - propagateEvent(component.instance, component.root, eventName, eventsDescriptor[eventName]); - } - } - }; - function propagateEvent(childInstance, parentInstance, eventName, proxyEventName) { - if (typeof proxyEventName !== 'string') { - if (parentInstance.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - return; - } - } - childInstance.on(eventName, function () { - var args = Array.prototype.slice.call(arguments); - args.unshift(proxyEventName); - parentInstance.fire.apply(parentInstance, args); - }); - } - }(utils_warn); -var render_DomFragment_Component_initialise_updateLiveQueries = function () { - - return function (component) { - var ancestor, query; - ancestor = component.root; - while (ancestor) { - if (query = ancestor._liveComponentQueries[component.name]) { - query.push(component.instance); - } - ancestor = ancestor._parent; - } - }; - }(); -var render_DomFragment_Component_initialise__initialise = function (types, warn, createModel, createInstance, createObservers, propagateEvents, updateLiveQueries) { - - return function (component, options, docFrag) { - var parentFragment, root, Component, data, toBind; - parentFragment = component.parentFragment = options.parentFragment; - root = parentFragment.root; - component.root = root; - component.type = types.COMPONENT; - component.name = options.descriptor.e; - component.index = options.index; - component.observers = []; - Component = root.components[options.descriptor.e]; - if (!Component) { - throw new Error('Component "' + options.descriptor.e + '" not found'); - } - toBind = []; - data = createModel(component, options.descriptor.a, toBind); - createInstance(component, Component, data, docFrag, options.descriptor.f); - createObservers(component, toBind); - propagateEvents(component, options.descriptor.v); - if (options.descriptor.t1 || options.descriptor.t2 || options.descriptor.o) { - warn('The "intro", "outro" and "decorator" directives have no effect on components'); - } - updateLiveQueries(component); - }; - }(config_types, utils_warn, render_DomFragment_Component_initialise_createModel__createModel, render_DomFragment_Component_initialise_createInstance, render_DomFragment_Component_initialise_createObservers, render_DomFragment_Component_initialise_propagateEvents, render_DomFragment_Component_initialise_updateLiveQueries); -var render_DomFragment_Component__Component = function (initialise) { - - var DomComponent = function (options, docFrag) { - initialise(this, options, docFrag); - }; - DomComponent.prototype = { - firstNode: function () { - return this.instance.fragment.firstNode(); - }, - findNextNode: function () { - return this.parentFragment.findNextNode(this); - }, - detach: function () { - return this.instance.fragment.detach(); - }, - teardown: function () { - var query; - while (this.complexParameters.length) { - this.complexParameters.pop().teardown(); - } - while (this.observers.length) { - this.observers.pop().cancel(); - } - if (query = this.root._liveComponentQueries[this.name]) { - query._remove(this); - } - this.instance.teardown(); - }, - toString: function () { - return this.instance.fragment.toString(); - }, - find: function (selector) { - return this.instance.fragment.find(selector); - }, - findAll: function (selector, query) { - return this.instance.fragment.findAll(selector, query); - }, - findComponent: function (selector) { - if (!selector || selector === this.name) { - return this.instance; - } - return null; - }, - findAllComponents: function (selector, query) { - query._test(this, true); - if (this.instance.fragment) { - this.instance.fragment.findAllComponents(selector, query); - } - } - }; - return DomComponent; - }(render_DomFragment_Component_initialise__initialise); -var render_DomFragment_Comment = function (types) { - - var DomComment = function (options, docFrag) { - this.type = types.COMMENT; - this.descriptor = options.descriptor; - if (docFrag) { - this.node = document.createComment(options.descriptor.f); - docFrag.appendChild(this.node); - } - }; - DomComment.prototype = { - detach: function () { - this.node.parentNode.removeChild(this.node); - return this.node; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - } - }, - firstNode: function () { - return this.node; - }, - toString: function () { - return ''; - } - }; - return DomComment; - }(config_types); -var render_DomFragment__DomFragment = function (types, matches, initFragment, insertHtml, Text, Interpolator, Section, Triple, Element, Partial, Component, Comment, circular) { - - var DomFragment = function (options) { - if (options.pNode) { - this.docFrag = document.createDocumentFragment(); - } - if (typeof options.descriptor === 'string') { - this.html = options.descriptor; - if (this.docFrag) { - this.nodes = insertHtml(this.html, options.pNode.tagName, this.docFrag); - } - } else { - initFragment(this, options); - } - }; - DomFragment.prototype = { - detach: function () { - var len, i; - if (this.nodes) { - i = this.nodes.length; - while (i--) { - this.docFrag.appendChild(this.nodes[i]); - } - } else if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - this.docFrag.appendChild(this.items[i].detach()); - } - } - return this.docFrag; - }, - createItem: function (options) { - if (typeof options.descriptor === 'string') { - return new Text(options, this.docFrag); - } - switch (options.descriptor.t) { - case types.INTERPOLATOR: - return new Interpolator(options, this.docFrag); - case types.SECTION: - return new Section(options, this.docFrag); - case types.TRIPLE: - return new Triple(options, this.docFrag); - case types.ELEMENT: - if (this.root.components[options.descriptor.e]) { - return new Component(options, this.docFrag); - } - return new Element(options, this.docFrag); - case types.PARTIAL: - return new Partial(options, this.docFrag); - case types.COMMENT: - return new Comment(options, this.docFrag); - default: - throw new Error('Something very strange happened. Please file an issue at https://github.com/RactiveJS/Ractive/issues. Thanks!'); - } - }, - teardown: function (destroy) { - var node; - if (this.nodes && destroy) { - while (node = this.nodes.pop()) { - node.parentNode.removeChild(node); - } - } else if (this.items) { - while (this.items.length) { - this.items.pop().teardown(destroy); - } - } - this.nodes = this.items = this.docFrag = null; - }, - firstNode: function () { - if (this.items && this.items[0]) { - return this.items[0].firstNode(); - } else if (this.nodes) { - return this.nodes[0] || null; - } - return null; - }, - findNextNode: function (item) { - var index = item.index; - if (this.items[index + 1]) { - return this.items[index + 1].firstNode(); - } - if (this.owner === this.root) { - if (!this.owner.component) { - return null; - } - return this.owner.component.findNextNode(); - } - return this.owner.findNextNode(this); - }, - toString: function () { - var html, i, len, item; - if (this.html) { - return this.html; - } - html = ''; - if (!this.items) { - return html; - } - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - html += item.toString(); - } - return html; - }, - find: function (selector) { - var i, len, item, node, queryResult; - if (this.nodes) { - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - return node; - } - if (queryResult = node.querySelector(selector)) { - return queryResult; - } - } - return null; - } - if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.find && (queryResult = item.find(selector))) { - return queryResult; - } - } - return null; - } - }, - findAll: function (selector, query) { - var i, len, item, node, queryAllResult, numNodes, j; - if (this.nodes) { - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - query.push(node); - } - if (queryAllResult = node.querySelectorAll(selector)) { - numNodes = queryAllResult.length; - for (j = 0; j < numNodes; j += 1) { - query.push(queryAllResult[j]); - } - } - } - } else if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.findAll) { - item.findAll(selector, query); - } - } - } - return query; - }, - findComponent: function (selector) { - var len, i, item, queryResult; - if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.findComponent && (queryResult = item.findComponent(selector))) { - return queryResult; - } - } - return null; - } - }, - findAllComponents: function (selector, query) { - var i, len, item; - if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.findAllComponents) { - item.findAllComponents(selector, query); - } - } - } - return query; - } - }; - circular.DomFragment = DomFragment; - return DomFragment; - }(config_types, utils_matches, render_shared_initFragment, render_DomFragment_shared_insertHtml, render_DomFragment_Text, render_DomFragment_Interpolator, render_DomFragment_Section__Section, render_DomFragment_Triple, render_DomFragment_Element__Element, render_DomFragment_Partial__Partial, render_DomFragment_Component__Component, render_DomFragment_Comment, circular); -var Ractive_prototype_render = function (getElement, makeTransitionManager, preDomUpdate, postDomUpdate, DomFragment) { - - return function (target, complete) { - var transitionManager; - if (!this._initing) { - throw new Error('You cannot call ractive.render() directly!'); - } - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - this.fragment = new DomFragment({ - descriptor: this.template, - root: this, - owner: this, - pNode: target - }); - preDomUpdate(this); - if (target) { - target.appendChild(this.fragment.docFrag); - } - postDomUpdate(this); - this._transitionManager = null; - transitionManager.ready(); - this.rendered = true; - }; - }(utils_getElement, shared_makeTransitionManager, shared_preDomUpdate, shared_postDomUpdate, render_DomFragment__DomFragment); -var Ractive_prototype_renderHTML = function (warn) { - - return function () { - warn('renderHTML() has been deprecated and will be removed in a future version. Please use toHTML() instead'); - return this.toHTML(); - }; - }(utils_warn); -var Ractive_prototype_toHTML = function () { - - return function () { - return this.fragment.toString(); - }; - }(); -var Ractive_prototype_teardown = function (makeTransitionManager, clearCache) { - - return function (complete) { - var keypath, transitionManager, previousTransitionManager; - this.fire('teardown'); - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - this.fragment.teardown(true); - while (this._animations[0]) { - this._animations[0].stop(); - } - for (keypath in this._cache) { - clearCache(this, keypath); - } - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - }; - }(shared_makeTransitionManager, shared_clearCache); -var Ractive_prototype_shared_add = function (isNumeric) { - - return function (root, keypath, d) { - var value; - if (typeof keypath !== 'string' || !isNumeric(d)) { - if (root.debug) { - throw new Error('Bad arguments'); - } - return; - } - value = root.get(keypath); - if (value === undefined) { - value = 0; - } - if (!isNumeric(value)) { - if (root.debug) { - throw new Error('Cannot add to a non-numeric value'); - } - return; - } - root.set(keypath, value + d); - }; - }(utils_isNumeric); -var Ractive_prototype_add = function (add) { - - return function (keypath, d) { - add(this, keypath, d === undefined ? 1 : d); - }; - }(Ractive_prototype_shared_add); -var Ractive_prototype_subtract = function (add) { - - return function (keypath, d) { - add(this, keypath, d === undefined ? -1 : -d); - }; - }(Ractive_prototype_shared_add); -var Ractive_prototype_toggle = function () { - - return function (keypath) { - var value; - if (typeof keypath !== 'string') { - if (this.debug) { - throw new Error('Bad arguments'); - } - return; - } - value = this.get(keypath); - this.set(keypath, !value); - }; - }(); -var Ractive_prototype_merge_mapOldToNewIndex = function () { - - return function (oldArray, newArray) { - var usedIndices, mapper, firstUnusedIndex, newIndices, changed; - usedIndices = {}; - firstUnusedIndex = 0; - mapper = function (item, i) { - var index, start, len; - start = firstUnusedIndex; - len = newArray.length; - do { - index = newArray.indexOf(item, start); - if (index === -1) { - changed = true; - return -1; - } - start = index + 1; - } while (usedIndices[index] && start < len); - if (index === firstUnusedIndex) { - firstUnusedIndex += 1; - } - if (index !== i) { - changed = true; - } - usedIndices[index] = true; - return index; - }; - newIndices = oldArray.map(mapper); - newIndices.unchanged = !changed; - return newIndices; - }; - }(); -var Ractive_prototype_merge_queueDependants = function (types) { - - return function queueDependants(keypath, deps, mergeQueue, updateQueue) { - var i, dependant; - i = deps.length; - while (i--) { - dependant = deps[i]; - if (dependant.type === types.REFERENCE) { - dependant.update(); - } else if (dependant.keypath === keypath && dependant.type === types.SECTION && !dependant.inverted && dependant.docFrag) { - mergeQueue[mergeQueue.length] = dependant; - } else { - updateQueue[updateQueue.length] = dependant; - } - } - }; - }(config_types); -var Ractive_prototype_merge__merge = function (warn, isArray, clearCache, preDomUpdate, processDeferredUpdates, makeTransitionManager, notifyDependants, replaceData, mapOldToNewIndex, queueDependants) { - - var identifiers = {}; - return function (keypath, array, options) { - var currentArray, oldArray, newArray, identifier, lengthUnchanged, i, newIndices, mergeQueue, updateQueue, depsByKeypath, deps, transitionManager, previousTransitionManager, upstreamQueue, keys; - currentArray = this.get(keypath); - if (!isArray(currentArray) || !isArray(array)) { - return this.set(keypath, array, options && options.complete); - } - lengthUnchanged = currentArray.length === array.length; - if (options && options.compare) { - if (options.compare === true) { - identifier = stringify; - } else if (typeof options.compare === 'string') { - identifier = getIdentifier(options.compare); - } else if (typeof options.compare == 'function') { - identifier = options.compare; - } else { - throw new Error('The `compare` option must be a function, or a string representing an identifying field (or `true` to use JSON.stringify)'); - } - try { - oldArray = currentArray.map(identifier); - newArray = array.map(identifier); - } catch (err) { - if (this.debug) { - throw err; - } else { - warn('Merge operation: comparison failed. Falling back to identity checking'); - } - oldArray = currentArray; - newArray = array; - } - } else { - oldArray = currentArray; - newArray = array; - } - newIndices = mapOldToNewIndex(oldArray, newArray); - clearCache(this, keypath); - replaceData(this, keypath, array); - if (newIndices.unchanged && lengthUnchanged) { - return; - } - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, options && options.complete); - mergeQueue = []; - updateQueue = []; - for (i = 0; i < this._deps.length; i += 1) { - depsByKeypath = this._deps[i]; - if (!depsByKeypath) { - continue; - } - deps = depsByKeypath[keypath]; - if (deps) { - queueDependants(keypath, deps, mergeQueue, updateQueue); - preDomUpdate(this); - while (mergeQueue.length) { - mergeQueue.pop().merge(newIndices); - } - while (updateQueue.length) { - updateQueue.pop().update(); - } - } - } - processDeferredUpdates(this); - upstreamQueue = []; - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - upstreamQueue[upstreamQueue.length] = keys.join('.'); - } - notifyDependants.multiple(this, upstreamQueue, true); - if (oldArray.length !== newArray.length) { - notifyDependants(this, keypath + '.length', true); - } - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - }; - function stringify(item) { - return JSON.stringify(item); - } - function getIdentifier(str) { - if (!identifiers[str]) { - identifiers[str] = function (item) { - return item[str]; - }; - } - return identifiers[str]; - } - }(utils_warn, utils_isArray, shared_clearCache, shared_preDomUpdate, shared_processDeferredUpdates, shared_makeTransitionManager, shared_notifyDependants, Ractive_prototype_shared_replaceData, Ractive_prototype_merge_mapOldToNewIndex, Ractive_prototype_merge_queueDependants); -var Ractive_prototype_detach = function () { - - return function () { - return this.fragment.detach(); - }; - }(); -var Ractive_prototype_insert = function (getElement) { - - return function (target, anchor) { - target = getElement(target); - anchor = getElement(anchor) || null; - if (!target) { - throw new Error('You must specify a valid target to insert into'); - } - target.insertBefore(this.detach(), anchor); - this.fragment.pNode = target; - }; - }(utils_getElement); -var Ractive_prototype__prototype = function (get, set, update, updateModel, animate, on, off, observe, fire, find, findAll, findComponent, findAllComponents, render, renderHTML, toHTML, teardown, add, subtract, toggle, merge, detach, insert) { - - return { - get: get, - set: set, - update: update, - updateModel: updateModel, - animate: animate, - on: on, - off: off, - observe: observe, - fire: fire, - find: find, - findAll: findAll, - findComponent: findComponent, - findAllComponents: findAllComponents, - renderHTML: renderHTML, - toHTML: toHTML, - render: render, - teardown: teardown, - add: add, - subtract: subtract, - toggle: toggle, - merge: merge, - detach: detach, - insert: insert - }; - }(Ractive_prototype_get__get, Ractive_prototype_set, Ractive_prototype_update, Ractive_prototype_updateModel, Ractive_prototype_animate__animate, Ractive_prototype_on, Ractive_prototype_off, Ractive_prototype_observe__observe, Ractive_prototype_fire, Ractive_prototype_find, Ractive_prototype_findAll, Ractive_prototype_findComponent, Ractive_prototype_findAllComponents, Ractive_prototype_render, Ractive_prototype_renderHTML, Ractive_prototype_toHTML, Ractive_prototype_teardown, Ractive_prototype_add, Ractive_prototype_subtract, Ractive_prototype_toggle, Ractive_prototype_merge__merge, Ractive_prototype_detach, Ractive_prototype_insert); -var extend_registries = function () { - - return [ - 'partials', - 'transitions', - 'events', - 'components', - 'decorators', - 'data' - ]; - }(); -var extend_initOptions = function () { - - return [ - 'el', - 'template', - 'complete', - 'modifyArrays', - 'magic', - 'twoway', - 'lazy', - 'append', - 'preserveWhitespace', - 'sanitize', - 'stripComments', - 'noIntro', - 'transitionsEnabled', - 'adaptors' - ]; - }(); -var extend_inheritFromParent = function (registries, initOptions, create) { - - return function (Child, Parent) { - registries.forEach(function (property) { - if (Parent[property]) { - Child[property] = create(Parent[property]); - } - }); - initOptions.forEach(function (property) { - Child[property] = Parent[property]; - }); - }; - }(extend_registries, extend_initOptions, utils_create); -var extend_wrapMethod = function () { - - return function (method, superMethod) { - if (/_super/.test(method)) { - return function () { - var _super = this._super, result; - this._super = superMethod; - result = method.apply(this, arguments); - this._super = _super; - return result; - }; - } else { - return method; - } - }; - }(); -var extend_utils_augment = function () { - - return function (target, source) { - var key; - for (key in source) { - if (source.hasOwnProperty(key)) { - target[key] = source[key]; - } - } - return target; - }; - }(); -var extend_inheritFromChildProps = function (registries, initOptions, wrapMethod, augment) { - - var blacklist, blacklisted; - blacklist = registries.concat(initOptions); - blacklisted = {}; - blacklist.forEach(function (property) { - blacklisted[property] = true; - }); - return function (Child, childProps) { - var key, member; - registries.forEach(function (property) { - var value = childProps[property]; - if (value) { - if (Child[property]) { - augment(Child[property], value); - } else { - Child[property] = value; - } - } - }); - initOptions.forEach(function (property) { - var value = childProps[property]; - if (value !== undefined) { - if (typeof value === 'function' && typeof Child[property] === 'function') { - Child[property] = wrapMethod(value, Child[property]); - } else { - Child[property] = childProps[property]; - } - } - }); - for (key in childProps) { - if (childProps.hasOwnProperty(key) && !blacklisted[key]) { - member = childProps[key]; - if (typeof member === 'function' && typeof Child.prototype[key] === 'function') { - Child.prototype[key] = wrapMethod(member, Child.prototype[key]); - } else { - Child.prototype[key] = member; - } - } - } - }; - }(extend_registries, extend_initOptions, extend_wrapMethod, extend_utils_augment); -var extend_extractInlinePartials = function (isObject, augment) { - - return function (Child, childProps) { - if (isObject(Child.template)) { - if (!Child.partials) { - Child.partials = {}; - } - augment(Child.partials, Child.template.partials); - if (childProps.partials) { - augment(Child.partials, childProps.partials); - } - Child.template = Child.template.main; - } - }; - }(utils_isObject, extend_utils_augment); -var extend_conditionallyParseTemplate = function (errors, isClient, parse) { - - return function (Child) { - var templateEl; - if (typeof Child.template === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - if (Child.template.charAt(0) === '#' && isClient) { - templateEl = document.getElementById(Child.template.substring(1)); - if (templateEl && templateEl.tagName === 'SCRIPT') { - Child.template = parse(templateEl.innerHTML, Child); - } else { - throw new Error('Could not find template element (' + Child.template + ')'); - } - } else { - Child.template = parse(Child.template, Child); - } - } - }; - }(config_errors, config_isClient, parse__parse); -var extend_conditionallyParsePartials = function (errors, parse) { - - return function (Child) { - var key; - if (Child.partials) { - for (key in Child.partials) { - if (Child.partials.hasOwnProperty(key) && typeof Child.partials[key] === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - Child.partials[key] = parse(Child.partials[key], Child); - } - } - } - }; - }(config_errors, parse__parse); -var extend_utils_clone = function () { - - return function (source) { - var target = {}, key; - for (key in source) { - if (source.hasOwnProperty(key)) { - target[key] = source[key]; - } - } - return target; - }; - }(); -var utils_extend = function () { - - return function (target) { - var prop, source, sources = Array.prototype.slice.call(arguments, 1); - while (source = sources.shift()) { - for (prop in source) { - if (source.hasOwnProperty(prop)) { - target[prop] = source[prop]; - } - } - } - return target; - }; - }(); -var Ractive_initialise = function (isClient, errors, warn, create, extend, defineProperty, defineProperties, getElement, isObject, magicAdaptor, parse) { - - var getObject, getArray, defaultOptions, registries; - getObject = function () { - return {}; - }; - getArray = function () { - return []; - }; - defaultOptions = create(null); - defineProperties(defaultOptions, { - preserveWhitespace: { - enumerable: true, - value: false - }, - append: { - enumerable: true, - value: false - }, - twoway: { - enumerable: true, - value: true - }, - modifyArrays: { - enumerable: true, - value: true - }, - data: { - enumerable: true, - value: getObject - }, - lazy: { - enumerable: true, - value: false - }, - debug: { - enumerable: true, - value: false - }, - transitions: { - enumerable: true, - value: getObject - }, - decorators: { - enumerable: true, - value: getObject - }, - events: { - enumerable: true, - value: getObject - }, - noIntro: { - enumerable: true, - value: false - }, - transitionsEnabled: { - enumerable: true, - value: true - }, - magic: { - enumerable: true, - value: false - }, - adaptors: { - enumerable: true, - value: getArray - } - }); - registries = [ - 'components', - 'decorators', - 'events', - 'partials', - 'transitions', - 'data' - ]; - return function (ractive, options) { - var key, template, templateEl, parsedTemplate; - for (key in defaultOptions) { - if (options[key] === undefined) { - options[key] = typeof defaultOptions[key] === 'function' ? defaultOptions[key]() : defaultOptions[key]; - } - } - defineProperties(ractive, { - _initing: { - value: true, - writable: true - }, - _guid: { - value: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { - var r, v; - r = Math.random() * 16 | 0; - v = c == 'x' ? r : r & 3 | 8; - return v.toString(16); - }) - }, - _subs: { - value: create(null), - configurable: true - }, - _cache: { value: {} }, - _cacheMap: { value: create(null) }, - _deps: { value: [] }, - _depsMap: { value: create(null) }, - _patternObservers: { value: [] }, - _pendingResolution: { value: [] }, - _deferred: { value: {} }, - _evaluators: { value: create(null) }, - _twowayBindings: { value: {} }, - _transitionManager: { - value: null, - writable: true - }, - _animations: { value: [] }, - nodes: { value: {} }, - _wrapped: { value: create(null) }, - _liveQueries: { value: [] }, - _liveComponentQueries: { value: [] } - }); - defineProperties(ractive._deferred, { - attrs: { value: [] }, - evals: { value: [] }, - selectValues: { value: [] }, - checkboxes: { value: [] }, - radios: { value: [] }, - observers: { value: [] }, - transitions: { value: [] }, - liveQueries: { value: [] }, - decorators: { value: [] }, - focusable: { - value: null, - writable: true - } - }); - ractive.adaptors = options.adaptors; - ractive.modifyArrays = options.modifyArrays; - ractive.magic = options.magic; - ractive.twoway = options.twoway; - ractive.lazy = options.lazy; - ractive.debug = options.debug; - if (ractive.magic && !magicAdaptor) { - throw new Error('Getters and setters (magic mode) are not supported in this browser'); - } - if (options._parent) { - defineProperty(ractive, '_parent', { value: options._parent }); - } - if (options.el) { - ractive.el = getElement(options.el); - if (!ractive.el && ractive.debug) { - throw new Error('Could not find container element'); - } - } - if (options.eventDefinitions) { - warn('ractive.eventDefinitions has been deprecated in favour of ractive.events. Support will be removed in future versions'); - options.events = options.eventDefinitions; - } - registries.forEach(function (registry) { - if (ractive.constructor[registry]) { - ractive[registry] = extend(create(ractive.constructor[registry] || {}), options[registry]); - } else if (options[registry]) { - ractive[registry] = options[registry]; - } - }); - template = options.template; - if (typeof template === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - if (template.charAt(0) === '#' && isClient) { - templateEl = document.getElementById(template.substring(1)); - if (templateEl) { - parsedTemplate = parse(templateEl.innerHTML, options); - } else { - throw new Error('Could not find template element (' + template + ')'); - } - } else { - parsedTemplate = parse(template, options); - } - } else { - parsedTemplate = template; - } - if (isObject(parsedTemplate)) { - extend(ractive.partials, parsedTemplate.partials); - parsedTemplate = parsedTemplate.main; - } - if (parsedTemplate && parsedTemplate.length === 1 && typeof parsedTemplate[0] === 'string') { - parsedTemplate = parsedTemplate[0]; - } - ractive.template = parsedTemplate; - extend(ractive.partials, options.partials); - ractive.parseOptions = { - preserveWhitespace: options.preserveWhitespace, - sanitize: options.sanitize, - stripComments: options.stripComments - }; - ractive.transitionsEnabled = options.noIntro ? false : options.transitionsEnabled; - if (isClient && !ractive.el) { - ractive.el = document.createDocumentFragment(); - } - if (ractive.el && !options.append) { - ractive.el.innerHTML = ''; - } - ractive.render(ractive.el, options.complete); - ractive.transitionsEnabled = options.transitionsEnabled; - ractive._initing = false; - }; - }(config_isClient, config_errors, utils_warn, utils_create, utils_extend, utils_defineProperty, utils_defineProperties, utils_getElement, utils_isObject, Ractive_prototype_get_magicAdaptor, parse__parse); -var extend_initChildInstance = function (fillGaps, initOptions, clone, wrapMethod, initialise) { - - return function (child, Child, options) { - initOptions.forEach(function (property) { - var value = options[property], defaultValue = Child[property]; - if (typeof value === 'function' && typeof defaultValue === 'function') { - options[property] = wrapMethod(value, defaultValue); - } else if (value === undefined && defaultValue !== undefined) { - options[property] = defaultValue; - } - }); - if (child.beforeInit) { - child.beforeInit(options); - } - initialise(child, options); - if (child.init) { - child.init(options); - } - }; - }(utils_fillGaps, extend_initOptions, extend_utils_clone, extend_wrapMethod, Ractive_initialise); -var extend__extend = function (create, inheritFromParent, inheritFromChildProps, extractInlinePartials, conditionallyParseTemplate, conditionallyParsePartials, initChildInstance, circular) { - - var Ractive; - circular.push(function () { - Ractive = circular.Ractive; - }); - return function (childProps) { - var Parent = this, Child; - Child = function (options) { - initChildInstance(this, Child, options || {}); - }; - Child.prototype = create(Parent.prototype); - Child.prototype.constructor = Child; - inheritFromParent(Child, Parent); - inheritFromChildProps(Child, childProps); - conditionallyParseTemplate(Child); - extractInlinePartials(Child, childProps); - conditionallyParsePartials(Child); - Child.extend = Parent.extend; - return Child; - }; - }(utils_create, extend_inheritFromParent, extend_inheritFromChildProps, extend_extractInlinePartials, extend_conditionallyParseTemplate, extend_conditionallyParsePartials, extend_initChildInstance, circular); -var Ractive__Ractive = function (svg, create, defineProperties, prototype, partialRegistry, adaptorRegistry, easingRegistry, Ractive_extend, parse, initialise, circular) { - - var Ractive = function (options) { - initialise(this, options); - }; - defineProperties(Ractive, { - prototype: { value: prototype }, - partials: { value: partialRegistry }, - adaptors: { value: adaptorRegistry }, - easing: { value: easingRegistry }, - transitions: { value: {} }, - events: { value: {} }, - components: { value: {} }, - decorators: { value: {} }, - svg: { value: svg }, - VERSION: { value: '0.3.9' } - }); - Ractive.eventDefinitions = Ractive.events; - Ractive.prototype.constructor = Ractive; - Ractive.delimiters = [ - '{{', - '}}' - ]; - Ractive.tripleDelimiters = [ - '{{{', - '}}}' - ]; - Ractive.extend = Ractive_extend; - Ractive.parse = parse; - circular.Ractive = Ractive; - return Ractive; - }(config_svg, utils_create, utils_defineProperties, Ractive_prototype__prototype, registries_partials, registries_adaptors, registries_easing, extend__extend, parse__parse, Ractive_initialise, circular); -var Ractive = function (Ractive, circular) { - - if (typeof window !== 'undefined' && window.Node && !window.Node.prototype.contains && window.HTMLElement && window.HTMLElement.prototype.contains) { - window.Node.prototype.contains = window.HTMLElement.prototype.contains; - } - while (circular.length) { - circular.pop()(); - } - return Ractive; - }(Ractive__Ractive, circular); -// export as Common JS module... -if ( typeof module !== "undefined" && module.exports ) { - module.exports = Ractive; -} - -// ... or as AMD module -else if ( typeof define === "function" && define.amd ) { - define( function () { - return Ractive; - }); -} - -// ... or as browser global -else { - global.Ractive = Ractive; -} - -}( typeof window !== 'undefined' ? window : this )); \ No newline at end of file diff --git a/build/Ractive-legacy.runtime.min.js b/build/Ractive-legacy.runtime.min.js deleted file mode 100644 index ac34c3f32f..0000000000 --- a/build/Ractive-legacy.runtime.min.js +++ /dev/null @@ -1,4 +0,0 @@ -!function(a){"use strict";var b=a.document;b&&(Date.now||(Date.now=function(){return+new Date}),String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+/,"").replace(/\s+$/,"")}),Object.keys||(Object.keys=function(){var a=Object.prototype.hasOwnProperty,b=!{toString:null}.propertyIsEnumerable("toString"),c=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],d=c.length;return function(e){if("object"!=typeof e&&"function"!=typeof e||null===e)throw new TypeError("Object.keys called on non-object");var f=[];for(var g in e)a.call(e,g)&&f.push(g);if(b)for(var h=0;d>h;h++)a.call(e,c[h])&&f.push(c[h]);return f}}()),Array.prototype.indexOf||(Array.prototype.indexOf=function(a,b){var c;for(void 0===b&&(b=0),0>b&&(b+=this.length),0>b&&(b=0),c=this.length;c>b;b++)if(this.hasOwnProperty(b)&&this[b]===a)return b;return-1}),Array.prototype.forEach||(Array.prototype.forEach=function(a,b){var c,d;for(c=0,d=this.length;d>c;c+=1)this.hasOwnProperty(c)&&a.call(b,this[c],c,this)}),Array.prototype.map||(Array.prototype.map=function(a,b){var c,d,e=[];for(c=0,d=this.length;d>c;c+=1)this.hasOwnProperty(c)&&(e[c]=a.call(b,this[c],c,this));return e}),Array.prototype.filter||(Array.prototype.filter=function(a,b){var c,d,e=[];for(c=0,d=this.length;d>c;c+=1)this.hasOwnProperty(c)&&a.call(b,this[c],c,this)&&(e[e.length]=this[c]);return e}),a.addEventListener||!function(a,b){var c,d,e,f,g,h;c=function(a,b){var c,d=this;for(c in a)d[c]=a[c];d.currentTarget=b,d.target=a.srcElement||b,d.timeStamp=+new Date,d.preventDefault=function(){a.returnValue=!1},d.stopPropagation=function(){a.cancelBubble=!0}},d=function(a,b){var d,e,f=this;d=f.listeners||(f.listeners=[]),e=d.length,d[e]=[b,function(a){b.call(f,new c(a,f))}],f.attachEvent("on"+a,d[e][1])},e=function(a,b){var c,d,e=this;if(e.listeners)for(c=e.listeners,d=c.length;d--;)c[d][0]===b&&e.detachEvent("on"+a,c[d][1])},a.addEventListener=b.addEventListener=d,a.removeEventListener=b.removeEventListener=e,"Element"in a?(Element.prototype.addEventListener=d,Element.prototype.removeEventListener=e):(h=b.createElement,b.createElement=function(a){var b=h(a);return b.addEventListener=d,b.removeEventListener=e,b},f=b.getElementsByTagName("head")[0],g=b.createElement("style"),f.insertBefore(g,f.firstChild))}(a,b),a.getComputedStyle||(a.getComputedStyle=function(){function a(b,c,d,e){var f,g=c[d],h=parseFloat(g),i=g.split(/\d/)[0];return e=null!=e?e:/%|em/.test(i)&&b.parentElement?a(b.parentElement,b.parentElement.currentStyle,"fontSize",null):16,f="fontSize"==d?e:/width/i.test(d)?b.clientWidth:b.clientHeight,"em"==i?h*e:"in"==i?96*h:"pt"==i?96*h/72:"%"==i?h/100*f:h}function b(a,b){var c="border"==b?"Width":"",d=b+"Top"+c,e=b+"Right"+c,f=b+"Bottom"+c,g=b+"Left"+c;a[b]=(a[d]==a[e]==a[f]==a[g]?[a[d]]:a[d]==a[f]&&a[g]==a[e]?[a[d],a[e]]:a[g]==a[e]?[a[d],a[e],a[f]]:[a[d],a[e],a[f],a[g]]).join(" ")}function c(c){var d,e,f,g;d=c.currentStyle,e=this,f=a(c,d,"fontSize",null);for(g in d)/width|height|margin.|padding.|border.+W/.test(g)&&"auto"!==e[g]?e[g]=a(c,d,g,f)+"px":"styleFloat"===g?e.float=d[g]:e[g]=d[g];return b(e,"margin"),b(e,"padding"),b(e,"border"),e.fontSize=f+"px",e}function d(a){return new c(a)}return c.prototype={constructor:c,getPropertyPriority:function(){},getPropertyValue:function(a){return this[a]||""},item:function(){},removeProperty:function(){},setProperty:function(){},getPropertyCSSValue:function(){}},d}()))}("undefined"!=typeof window?window:this),function(a){var b=function(){return"undefined"!=typeof document?document&&document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure","1.1"):void 0}(),c=function(){var a;try{Object.create(null),a=Object.create}catch(b){a=function(){var a=function(){};return function(b,c){var d;return null===b?{}:(a.prototype=b,d=new a,c&&Object.defineProperties(d,c),d)}}()}return a}(),d={html:"http://www.w3.org/1999/xhtml",mathml:"http://www.w3.org/1998/Math/MathML",svg:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},e=function(a,b){return a?function(a,b){return b?document.createElementNS(b,a):document.createElement(a)}:function(a,c){if(c&&c!==b.html)throw"This browser does not support namespaces other than http://www.w3.org/1999/xhtml. The most likely cause of this error is that you're trying to render SVG in an older browser. See https://github.com/RactiveJS/Ractive/wiki/SVG-and-older-browsers for more information";return document.createElement(a)}}(b,d),f=function(){return"object"==typeof document?!0:!1}(),g=function(a){try{return Object.defineProperty({},"test",{value:0}),a&&Object.defineProperty(document.createElement("div"),"test",{value:0}),Object.defineProperty}catch(b){return function(a,b,c){a[b]=c.value}}}(f),h=function(a,b,c){try{try{Object.defineProperties({},{test:{value:0}})}catch(d){throw d}return c&&Object.defineProperties(a("div"),{test:{value:0}}),Object.defineProperties}catch(d){return function(a,c){var d;for(d in c)c.hasOwnProperty(d)&&b(a,d,c[d])}}}(e,g,f),i=function(){var a=/\[\s*(\*|[0-9]|[1-9][0-9]+)\s*\]/g;return function(b){return(b||"").replace(a,".$1")}}(),j={},k={TEXT:1,INTERPOLATOR:2,TRIPLE:3,SECTION:4,INVERTED:5,CLOSING:6,ELEMENT:7,PARTIAL:8,COMMENT:9,DELIMCHANGE:10,MUSTACHE:11,TAG:12,ATTRIBUTE:13,COMPONENT:15,NUMBER_LITERAL:20,STRING_LITERAL:21,ARRAY_LITERAL:22,OBJECT_LITERAL:23,BOOLEAN_LITERAL:24,GLOBAL:26,KEY_VALUE_PAIR:27,REFERENCE:30,REFINEMENT:31,MEMBER:32,PREFIX_OPERATOR:33,BRACKETED:34,CONDITIONAL:35,INFIX_OPERATOR:36,INVOCATION:40},l=function(){var a=Object.prototype.toString;return function(b){return"[object Array]"===a.call(b)}}(),m=function(){return function a(b,c){var d,e;if((e=b._wrapped[c])&&e.teardown()!==!1&&(b._wrapped[c]=null),b._cache[c]=void 0,d=b._cacheMap[c])for(;d.length;)a(b,d.pop())}}(),n=function(){return function(a,b){var c,d,e,f,g,h;for(c=[],h=a.rendered?a.el:a.fragment.docFrag,d=h.querySelectorAll('input[type="checkbox"][name="{{'+b+'}}"]'),f=d.length,g=0;f>g;g+=1)e=d[g],(e.hasAttribute("checked")||e.checked)&&(c[c.length]=e._ractive.value);return c}}(),o=function(a){return function(b){var c,d,e,f,g,h;for(c=b._deferred;d=c.evals.pop();)d.update().deferred=!1;for(;e=c.selectValues.pop();)e.deferredUpdate();for(;f=c.attrs.pop();)f.update().deferred=!1;for(;g=c.checkboxes.pop();)b.set(g,a(b,g));for(;h=c.radios.pop();)h.update()}}(n),p=function(){return function(a){var b,c,d,e,f,g;for(b=a._deferred,(c=b.focusable)&&(c.focus(),b.focusable=null);d=b.liveQueries.pop();)d._sort();for(;e=b.decorators.pop();)e.init();for(;f=b.transitions.pop();)f.init();for(;g=b.observers.pop();)g.update()}}(),q=function(){var a=function(a,b){var c,d,e,f;return a._parent&&a._parent._transitionManager?a._parent._transitionManager:(d=[],e=function(){var a,b;for(a=d.length;a--;)b=d[a],f(b.node)&&(b.detach(),d.splice(a,1))},f=function(a){var b,d;for(b=c.active.length;b--;)if(d=c.active[b],a.contains(d))return!1;return!0},c={active:[],push:function(a){c.active[c.active.length]=a},pop:function(a){var b;b=c.active.indexOf(a),-1!==b&&(c.active.splice(b,1),e(),!c.active.length&&c._ready&&c.complete())},complete:function(){b&&b.call(a)},ready:function(){e(),c._ready=!0,c.active.length||c.complete()},detachWhenReady:function(a){d[d.length]=a}})};return a}(),r=function(){function a(a,d,e,f){var g=a._deps[e];g&&(b(g[d]),f||c(a._depsMap[d],a,e))}function b(a){var b,c;if(a)for(c=a.length,b=0;c>b;b+=1)a[b].update()}function c(b,c,d,e){var f;if(b)for(f=b.length;f--;)a(c,b[f],d,e)}function d(a,b,c,f,g){var i,j,k,l,m,n,o,p;for(i=a._patternObservers.length;i--;)j=a._patternObservers[i],j.regex.test(c)&&j.update(c);f||(p=function(b){if(k=a._depsMap[b])for(i=k.length;i--;)l=k[i],m=h.exec(l)[0],n=c+"."+m,d(a,l,n)},g?(o=e(c),o.forEach(p)):p(b))}function e(a){var b,c,d,e,g,h;for(b=a.split("."),c=f(b.length),g=[],d=function(a,c){return a?"*":b[c]},e=c.length;e--;)h=c[e].map(d).join("."),g[h]||(g[g.length]=h,g[h]=!0);return g}function f(a){var b,c,d,e,f,g="";if(!i[a]){for(d=[];g.length=f;f+=1){for(c=f.toString(2);c.length2&&f[1])for(q=Math.min(f[1],f.length-2),r=f[0],s=r+q,f[1]===f.length-2&&(u=!0),p=r;s>p;p+=1)t=g+"."+p,h(a,t);for(e(a),m=[],l=g.split(".");l.length;)l.pop(),m[m.length]=l.join(".");h.multiple(a,m,!0),u||h(a,g+".length",!0)},i=function(b,c,d,e){var f,g;for(f=c.length;f--;)g=c[f],g.type===a.REFERENCE?g.update():g.keypath===b&&g.type===a.SECTION&&!g.inverted&&g.docFrag?d[d.length]=g:e[e.length]=g},j=b._ractive.wrappers,l=j.length;l--;)k=j[l],g(k.root,k.keypath)},n=[],p=["pop","push","reverse","shift","sort","splice","unshift"],q=function(){},p.forEach(function(a){var c=function(){var b,c,d,h,i={},k={};for(b=Array.prototype[a].apply(this,arguments),c=this._ractive.instances,h=c.length;h--;)d=c[h],i[d._guid]=d._transitionManager,d._transitionManager=k[d._guid]=g(d,q);for(this._ractive.setting=!0,j(this,a,arguments),this._ractive.setting=!1,h=c.length;h--;)d=c[h],d._transitionManager=i[d._guid],k[d._guid].ready(),e(d),f(d);return b};b(n,a,{value:c})}),o={},o.__proto__?(l=function(a){a.__proto__=n},m=function(a){a.__proto__=Array.prototype}):(l=function(a){var c,d;for(c=p.length;c--;)d=p[c],b(a,d,{value:n[d],configurable:!0})},m=function(a){var b;for(b=p.length;b--;)delete a[p[b]]}),r="Something went wrong in a rather interesting way",i}(k,g,l,m,o,p,q,r),t=function(){var a,b;try{Object.defineProperty({},"test",{value:0})}catch(c){return!1}return a={filter:function(a,b){return!!b},wrap:function(a,c,d){return new b(a,c,d)}},b=function(a,b,c){var d,e,f,g,h,i,j,k,l,m=this;if(this.ractive=a,this.keypath=c,d=c.split("."),this.prop=d.pop(),f=d.join("."),this.obj=f?a.get(f):a.data,g=this.originalDescriptor=Object.getOwnPropertyDescriptor(this.obj,this.prop),g&&g.set&&(h=g.set._ractiveWrappers))return-1===h.indexOf(this)&&h.push(this),void 0;if(g&&!g.configurable)throw new Error('Cannot use magic mode with property "'+e+'" - object is not configurable');g&&(this.value=g.value,i=g.get,j=g.set),k=i||function(){return m.value},l=function(a){var b,c,d;for(j&&j(a),b=l._ractiveWrappers,d=b.length;d--;)c=b[d],c.resetting||c.ractive.set(c.keypath,a)},l._ractiveWrappers=[this],Object.defineProperty(this.obj,this.prop,{get:k,set:l,enumerable:!0,configurable:!0})},b.prototype={get:function(){return this.value},reset:function(a){this.resetting=!0,this.value=a,this.resetting=!1},teardown:function(){var a,b,c,d;a=Object.getOwnPropertyDescriptor(this.obj,this.prop),b=a.set,d=b._ractiveWrappers,d.splice(d.indexOf(this),1),d.length||(c=this.obj[this.prop],Object.defineProperty(this.obj,this.prop,this.originalDescriptor||{writable:!0,enumerable:!0,configrable:!0}),this.obj[this.prop]=c)}},a}(),u=function(a,b,c){function d(a,b){var c,d={};if(!b)return a;b+=".";for(c in a)a.hasOwnProperty(c)&&(d[b+c]=a[c]);return d}function e(a){var b;return f[a]||(b=a?a+".":"",f[a]=function(c,e){var f;return"string"==typeof c?(f={},f[b+c]=e,f):"object"==typeof c?b?d(c,a):c:void 0}),f[a]}var f={};return function(d,f,g,h){var i,j,k,l;for(i=d.adaptors.length,j=0;i>j;j+=1){if(k=d.adaptors[j],"string"==typeof k){if(!a[k])throw new Error('Missing adaptor "'+k+'"');k=d.adaptors[j]=a[k]}if(k.filter(g,f,d))return l=d._wrapped[f]=k.wrap(d,g,f,e(f)),l.value=g,void 0}h||(d.magic&&c.filter(g,f,d)?d._wrapped[f]=c.wrap(d,g,f):d.modifyArrays&&b.filter(g,f,d)&&(d._wrapped[f]=b.wrap(d,g,f)))}}(j,s,t),v=function(a,b,c){var d,e,f;return d=function(a){return this._captured&&!this._captured[a]&&(this._captured.push(a),this._captured[a]=!0),e(this,a)},e=function(b,d){var e,g,h,i,j;return d=a(d),e=b._cache,void 0!==(g=e[d])?g:((i=b._wrapped[d])?h=i.value:d?h=(j=b._evaluators[d])?j.value:f(b,d):(c(b,"",b.data),h=b.data),e[d]=h,h)},f=function(a,b){var d,f,g,h,i,j,k;return d=b.split("."),f=d.pop(),g=d.join("."),h=e(a,g),(k=a._wrapped[g])&&(h=k.get()),null!==h&&void 0!==h?((i=a._cacheMap[g])?-1===i.indexOf(b)&&(i[i.length]=b):a._cacheMap[g]=[b],j=h[f],c(a,b,j),a._cache[b]=j,j):void 0},d}(i,j,u),w=function(){var a=Object.prototype.toString;return function(b){return"object"==typeof b&&"[object Object]"===a.call(b)}}(),x=function(){return function(a,b){return null===a&&null===b?!0:"object"==typeof a||"object"==typeof b?!1:a===b}}(),y=function(){var a;return a=function(a,b,c){var d,e,f,g,h,i,j,k,l,m,n;if(n='Could not resolve reference - too many "../" prefixes',"."===b){if(!c.length)return"";d=c[c.length-1]}else if("."===b.charAt(0))if(m=c[c.length-1],g=m?m.split("."):[],"../"===b.substr(0,3)){for(;"../"===b.substr(0,3);){if(!g.length)throw new Error(n);g.pop(),b=b.substring(3)}g.push(b),d=g.join(".")}else d=m?m+b:b.substring(1);else{for(e=b.split("."),f=e.pop(),i=e.length?"."+e.join("."):"",c=c.concat();c.length;)if(h=c.pop(),j=h+i,k=a.get(j),(l=a._wrapped[j])&&(k=l.get()),"object"==typeof k&&null!==k&&k.hasOwnProperty(f)){d=h+"."+b;break}d||void 0===a.get(b)||(d=b)}return d?d.replace(/^\./,""):d}}(),z=function(a){var b=Array.prototype.push;return function(c){for(var d,e,f;d=c._pendingResolution.pop();)e=a(c,d.ref,d.contextStack),void 0!==e?d.resolve(e):(f||(f=[])).push(d);f&&b.apply(c._pendingResolution,f)}}(y),A=function(a,b){return function(c){a(c),b(c)}}(o,p),B=function(){return function(a,b,c){var d,e,f,g,h,i,j;for(d=b.split("."),e=[],(f=a._wrapped[""])?(f.set&&f.set(d.join("."),c),g=f.get()):g=a.data;d.length>1;)h=e[e.length]=d.shift(),i=e.join("."),(f=a._wrapped[i])?(f.set&&f.set(d.join("."),c),g=f.get()):(g.hasOwnProperty(h)||(j||(j=i),g[h]=/^\s*[0-9]+\s*$/.test(d[0])?[]:{}),g=g[h]);return h=d[0],g[h]=c,j}}(),C=function(a,b,c,d,e,f,g,h,i){var j,k,l,m;return j=function(b,d,i){var j,m,n,o,p,q,r;if(m=[],a(b)&&(j=b,i=d),j)for(b in j)j.hasOwnProperty(b)&&(d=j[b],b=c(b),k(this,b,d,m));else b=c(b),k(this,b,d,m);if(m.length){if(o=this._transitionManager,this._transitionManager=p=g(this,i),n=l(m),n.length&&e.multiple(this,n,!0),e.multiple(this,m),this._pendingResolution.length&&f(this),h(this),this._transitionManager=o,p.ready(),!this.firingChangeEvent){for(this.firingChangeEvent=!0,r={},q=m.length;q--;)r[m[q]]=this.get(m[q]);this.fire("change",r),this.firingChangeEvent=!1}return this}},k=function(a,b,c,e){var f,g,h,j,k;if(!(h=a._wrapped[b])||!h.reset||m(a,b,c,h,e)===!1){if((k=a._evaluators[b])&&(k.value=c),f=a._cache[b],g=a.get(b),g===c||k){if(c===f&&"object"!=typeof c)return}else j=i(a,b,c);d(a,j||b),e[e.length]=b}},l=function(a){var b,c,d,e,f=[""];for(b=a.length;b--;)for(c=a[b],d=c.split(".");d.length>1;)d.pop(),e=d.join("."),f[e]||(f[f.length]=e,f[e]=!0);return f},m=function(a,c,e,f,g){var h,i,j,k;if(h=f.get(),!b(h,e)&&f.reset(e)===!1)return!1;if(e=f.get(),i=a._cache[c],!b(i,e)){if(a._cache[c]=e,j=a._cacheMap[c])for(k=j.length;k--;)d(a,j[k]);g[g.length]=c}},j}(w,x,i,m,r,z,q,A,B),D=function(a,b,c,d,e){return function(f,g){var h,i;return"function"==typeof f&&(g=f,f=""),i=this._transitionManager,this._transitionManager=h=a(this,g),b(this),c(this,f||""),d(this,f||""),e(this),this._transitionManager=i,h.ready(),"string"==typeof f?this.fire("update",f):this.fire("update"),this}}(q,z,m,r,A),E=function(a){return function(b,c){var d;if(!a(b)||!a(c))return!1;if(b.length!==c.length)return!1;for(d=b.length;d--;)if(b[d]!==c[d])return!1;return!0}}(l),F=function(a,b,c){function d(a,e,f,g,h){var i,j,k,l,m,n;if(i=a._twowayBindings[e])for(k=i.length;k--;)l=i[k],(!l.radioName||l.node.checked)&&(l.checkboxName?l.changed()&&!g[e]&&(g[e]=!0,g[g.length]=e):(m=l.attr.value,n=l.value(),b(m,n)||c(m,n)||(f[e]=n)));if(h&&(j=a._depsMap[e]))for(k=j.length;k--;)d(a,j[k],f,g,h)}return function(b,c){var e,f,g;if("string"!=typeof b&&(b="",c=!0),d(this,b,e={},f=[],c),g=f.length)for(;g--;)b=f[g],e[b]=a(this,b);this.set(e)}}(n,E,x),G=function(){return"undefined"!=typeof window?(function(a,b,c){var d,e;if(!c.requestAnimationFrame){for(d=0;d=this.duration?(null!==g&&this.root.set(g,this.to),this.step&&this.step(1,this.to),this.complete&&this.complete(1,this.to),f=this.root._animations.indexOf(this),-1===f&&a("Animation was not found"),this.root._animations.splice(f,1),this.running=!1,!1):(c=this.easing?this.easing(b/this.duration):b/this.duration,null!==g&&(d=this.interpolator(c),this.root.set(g,d)),this.step&&this.step(c,d),!0)):!1},stop:function(){var b;this.running=!1,b=this.root._animations.indexOf(this),-1===b&&a("Animation was not found"),this.root._animations.splice(b,1)}},c}(I,K),M=function(){return{linear:function(a){return a},easeIn:function(a){return Math.pow(a,3)},easeOut:function(a){return Math.pow(a-1,3)+1},easeInOut:function(a){return(a/=.5)<1?.5*Math.pow(a,3):.5*(Math.pow(a-2,3)+2)}}}(),N=function(a,b,c,d){function e(e,g,h,i){var j,k,l,m;return null!==g&&(m=e.get(g)),b.abort(g,e),a(m,h)?(i.complete&&i.complete(1,i.to),f):(i.easing&&(j="function"==typeof i.easing?i.easing:e.easing&&e.easing[i.easing]?e.easing[i.easing]:d[i.easing],"function"!=typeof j&&(j=null)),k=void 0===i.duration?400:i.duration,l=new c({keypath:g,from:m,to:h,root:e,duration:k,easing:j,step:i.step,complete:i.complete}),b.add(l),e._animations[e._animations.length]=l,l)}var f={stop:function(){}};return function(a,b,c){var d,f,g,h,i,j,k,l,m,n,o,p;if("object"==typeof a){c=b||{},h=c.easing,i=c.duration,g=[],j=c.step,k=c.complete,(j||k)&&(m={},c.step=null,c.complete=null,l=function(a){return function(b,c){m[a]=c}});for(d in a)a.hasOwnProperty(d)&&((j||k)&&(n=l(d),c={easing:h,duration:i},j&&(c.step=n),k&&(c.complete=n)),g[g.length]=e(this,d,a[d],c));return(j||k)&&(p={easing:h,duration:i},j&&(p.step=function(a){j(a,m)}),k&&(p.complete=function(a){k(a,m)}),g[g.length]=o=e(this,null,null,p)),{stop:function(){for(;g.length;)g.pop().stop();o&&o.stop()}}}return c=c||{},f=e(this,a,b,c),{stop:function(){f.stop()}}}}(x,H,L,M),O=function(){return function(a,b){var c,d,e=this;if("object"==typeof a){c=[];for(d in a)a.hasOwnProperty(d)&&(c[c.length]=this.on(d,a[d]));return{cancel:function(){for(;c.length;)c.pop().cancel()}}}return this._subs[a]?this._subs[a].push(b):this._subs[a]=[b],{cancel:function(){e.off(a,b)}}}}(),P=function(){return function(a,b){var c,d;if(!b)if(a)this._subs[a]=[];else for(a in this._subs)delete this._subs[a];c=this._subs[a],c&&(d=c.indexOf(b),-1!==d&&c.splice(d,1))}}(),Q=function(){return function(a){var b,c,d,e,f,g,h,i;if(g=a.root,h=a.keypath,i=a.priority,b=g._deps[i]||(g._deps[i]={}),c=b[h]||(b[h]=[]),c[c.length]=a,a.registered=!0,h)for(d=h.split(".");d.length;)d.pop(),e=d.join("."),f=g._depsMap[e]||(g._depsMap[e]=[]),void 0===f[h]&&(f[h]=0,f[f.length]=h),f[h]+=1,h=e}}(),R=function(){return function(a){var b,c,d,e,f,g,h,i;if(g=a.root,h=a.keypath,i=a.priority,b=g._deps[i][h],c=b.indexOf(a),-1===c||!a.registered)throw new Error("Attempted to remove a dependant that was no longer registered! This should not happen. If you are seeing this bug in development please raise an issue at https://github.com/RactiveJS/Ractive/issues - thanks");if(b.splice(c,1),a.registered=!1,h)for(d=h.split(".");d.length;)d.pop(),e=d.join("."),f=g._depsMap[e],f[h]-=1,f[h]||(f.splice(f.indexOf(h),1),f[h]=void 0),h=e}}(),S=function(a){var b=function(a,b,c,d){var e=this;this.root=a,this.keypath=b,this.callback=c,this.defer=d.defer,this.debug=d.debug,this.proxy={update:function(){e.reallyUpdate()}},this.priority=0,this.context=d&&d.context?d.context:a};return b.prototype={init:function(a){a!==!1?this.update():this.value=this.root.get(this.keypath)},update:function(){return this.defer&&this.ready?(this.root._deferred.observers.push(this.proxy),void 0):(this.reallyUpdate(),void 0)},reallyUpdate:function(){var b,c;if(b=this.value,c=this.root.get(this.keypath),this.value=c,!this.updating){if(this.updating=!0,!a(c,b)||!this.ready)try{this.callback.call(this.context,c,b,this.keypath)}catch(d){if(this.debug||this.root.debug)throw d}this.updating=!1}}},b}(x),T=function(){return function(a,b){var c,d,e,f,g,h,i;for(c=b.split("."),f=[],h=function(b){var c,d;c=a._wrapped[b]?a._wrapped[b].get():a.get(b);for(d in c)g.push(b+"."+d)},i=function(a){return a+"."+d};d=c.shift();)"*"===d?(g=[],f.forEach(h),f=g):f[0]?f=f.map(i):f[0]=d;return e={},f.forEach(function(b){e[b]=a.get(b)}),e}}(),U=function(a,b){var c,d=/\*/;return c=function(a,b,c,d){this.root=a,this.callback=c,this.defer=d.defer,this.debug=d.debug,this.keypath=b,this.regex=new RegExp("^"+b.replace(/\./g,"\\.").replace(/\*/g,"[^\\.]+")+"$"),this.values={},this.defer&&(this.proxies=[]),this.priority="pattern",this.context=d&&d.context?d.context:a},c.prototype={init:function(a){var c,d;if(c=b(this.root,this.keypath),a!==!1)for(d in c)c.hasOwnProperty(d)&&this.update(d);else this.values=c},update:function(a){var c;{if(!d.test(a))return this.defer&&this.ready?(this.root._deferred.observers.push(this.getProxy(a)),void 0):(this.reallyUpdate(a),void 0);c=b(this.root,a);for(a in c)c.hasOwnProperty(a)&&this.update(a)}},reallyUpdate:function(b){var c=this.root.get(b);if(this.updating)return this.values[b]=c,void 0;if(this.updating=!0,!a(c,this.values[b])||!this.ready){try{this.callback.call(this.context,c,this.values[b],b)}catch(d){if(this.debug||this.root.debug)throw d}this.values[b]=c}this.updating=!1},getProxy:function(a){var b=this;return this.proxies[a]||(this.proxies[a]={update:function(){b.reallyUpdate(a)}}),this.proxies[a]}},c}(x,T),V=function(a,b,c,d,e){var f=/\*/,g={};return function(h,i,j,k){var l,m;return i=a(i),k=k||g,f.test(i)?(l=new e(h,i,j,k),h._patternObservers.push(l),m=!0):l=new d(h,i,j,k),b(l),l.init(k.init),l.ready=!0,{cancel:function(){var a;m&&(a=h._patternObservers.indexOf(l),-1!==a&&h._patternObservers.splice(a,1)),c(l)}}}}(i,Q,R,S,U),W=function(a,b){return function(c,d,e){var f,g=[];if(a(c)){e=d;for(f in c)c.hasOwnProperty(f)&&(d=c[f],g[g.length]=b(this,f,d,e));return{cancel:function(){for(;g.length;)g.pop().cancel()}}}return b(this,c,d,e)}}(w,V),X=function(){return function(a){var b,c,d,e=this._subs[a];if(e)for(b=Array.prototype.slice.call(arguments,1),c=0,d=e.length;d>c;c+=1)e[c].apply(this,b)}}(),Y=function(){return function(a){return this.el?this.fragment.find(a):null}}(),Z=function(a,b){var c,d,e,f,g,h,i,j;if(a){for(c=b("div"),d=["matches","matchesSelector"],g=["o","ms","moz","webkit"],j=function(a){return function(b,c){return b[a](c)}},h=d.length;h--;){if(e=d[h],c[e])return j(e);for(i=g.length;i--;)if(f=g[h]+e.substr(0,1).toUpperCase()+e.substring(1),c[f])return j(f)}return function(a,b){var c,d;for(c=(a.parentNode||a.document).querySelectorAll(b),d=c.length;d--;)if(c[d]===a)return!0;return!1}}}(f,e),$=function(a){return function(b,c){var d=this._isComponentQuery?!this.selector||b.name===this.selector:a(b.node,this.selector);return d?(this.push(b.node||b.instance),c||this._makeDirty(),!0):void 0}}(Z),_=function(){return function(){var a,b,c;a=this._root[this._isComponentQuery?"liveComponentQueries":"liveQueries"],b=this.selector,c=a.indexOf(b),-1!==c&&(a.splice(c,1),a[b]=null)}}(),ab=function(){function a(a){var b;return(b=a.parentFragment)?b.owner:a.component&&(b=a.component.parentFragment)?b.owner:void 0}function b(b){var c,d;for(c=[b],d=a(b);d;)c.push(d),d=a(d);return c}return function(a,c){var d,e,f,g,h,i,j,k,l,m;for(d=b(a.component||a._ractive.proxy),e=b(c.component||c._ractive.proxy),f=d[d.length-1],g=e[e.length-1];f&&f===g;)d.pop(),e.pop(),h=f,f=d[d.length-1],g=e[e.length-1];if(f=f.component||f,g=g.component||g,l=f.parentFragment,m=g.parentFragment,l===m)return i=l.items.indexOf(f),j=m.items.indexOf(g),i-j||d.length-e.length;if(k=h.fragments)return i=k.indexOf(l),j=k.indexOf(m),i-j||d.length-e.length;throw new Error("An unexpected condition was met while comparing the position of two components. Please file an issue at https://github.com/RactiveJS/Ractive/issues - thanks!")}}(),bb=function(a){return function(b,c){var d;return b.compareDocumentPosition?(d=b.compareDocumentPosition(c),2&d?1:-1):a(b,c)}}(ab),cb=function(a,b){return function(){this.sort(this._isComponentQuery?b:a),this._dirty=!1}}(bb,ab),db=function(){return function(){this._dirty||(this._root._deferred.liveQueries.push(this),this._dirty=!0)}}(),eb=function(){return function(a){var b=this.indexOf(this._isComponentQuery?a.instance:a.node);-1!==b&&this.splice(b,1)}}(),fb=function(a,b,c,d,e,f){return function(g,h,i,j){var k;return k=[],a(k,{selector:{value:h},live:{value:i},_isComponentQuery:{value:j},_test:{value:b}}),i?(a(k,{cancel:{value:c},_root:{value:g},_sort:{value:d},_makeDirty:{value:e},_remove:{value:f},_dirty:{value:!1,writable:!0}}),k):k}}(h,$,_,cb,db,eb),gb=function(a,b,c,d){return function(a,b){var c,e;return this.el?(b=b||{},c=this._liveQueries,(e=c[a])?b&&b.live?e:e.slice():(e=d(this,a,!!b.live,!1),e.live&&(c.push(a),c[a]=e),this.fragment.findAll(a,e),e)):[]}}(I,Z,h,fb),hb=function(){return function(a){return this.fragment.findComponent(a)}}(),ib=function(a,b,c,d){return function(a,b){var c,e;return b=b||{},c=this._liveComponentQueries,(e=c[a])?b&&b.live?e:e.slice():(e=d(this,a,!!b.live,!0),e.live&&(c.push(a),c[a]=e),this.fragment.findAllComponents(a,e),e)}}(I,Z,h,fb),jb=function(){return function(a){var b;return"undefined"!=typeof window&&document&&a?a.nodeType?a:"string"==typeof a&&(b=document.getElementById(a),!b&&document.querySelector&&(b=document.querySelector(a)),b&&b.nodeType)?b:a[0]&&a[0].nodeType?a[0]:null:null}}(),kb=function(a,b){return function(c,d){var e,f,g,h,i;if(c.owner=d.owner,g=c.owner.parentFragment,c.root=d.root,c.pNode=d.pNode,c.contextStack=d.contextStack||[],c.owner.type===a.SECTION&&(c.index=d.index),g&&(h=g.indexRefs)){c.indexRefs=b(null);for(i in h)c.indexRefs[i]=h[i]}for(c.priority=g?g.priority+1:1,d.indexRef&&(c.indexRefs||(c.indexRefs={}),c.indexRefs[d.indexRef]=d.index),c.items=[],e=d.descriptor?d.descriptor.length:0,f=0;e>f;f+=1)c.items[c.items.length]=c.createItem({parentFragment:c,descriptor:d.descriptor[f],index:f})}}(k,c),lb=function(a){var b={};return function(c,d,e){var f,g=[];if(c)for(f=b[d]||(b[d]=a(d)),f.innerHTML=c;f.firstChild;)g[g.length]=f.firstChild,e.appendChild(f.firstChild);return g}}(e),mb=function(a){var b,c,d;return c=//g,b=function(b,c){this.type=a.TEXT,this.descriptor=b.descriptor,c&&(this.node=document.createTextNode(b.descriptor),c.appendChild(this.node))},b.prototype={detach:function(){return this.node.parentNode.removeChild(this.node),this.node},teardown:function(a){a&&this.detach()},firstNode:function(){return this.node},toString:function(){return(""+this.descriptor).replace(c,"<").replace(d,">")}},b}(k),nb=function(a){return function(b){if(b.keypath)a(b);else{var c=b.root._pendingResolution.indexOf(b);-1!==c&&b.root._pendingResolution.splice(c,1)}}}(R),ob=function(a,b,c,d,e){function f(a,b,d){var e,f,g;if(!h.test(a.toString()))return c(a,"_nowrap",{value:!0}),a;if(!a["_"+b._guid]){c(a,"_"+b._guid,{value:function(){var c,d,e,g;if(c=b._captured,c||(b._captured=[]),d=a.apply(b,arguments),b._captured.length)for(e=f.length;e--;)g=f[e],g.updateSoftDependencies(b._captured);return b._captured=c,d},writable:!0});for(e in a)a.hasOwnProperty(e)&&(a["_"+b._guid][e]=a[e]);a["_"+b._guid+"_evaluators"]=[]}return f=a["_"+b._guid+"_evaluators"],g=f.indexOf(d),-1===g&&f.push(d),a["_"+b._guid]}var g,h;return h=/this/,g=function(b,c,e,g,h){var i;this.evaluator=e,this.keypath=c,this.root=b,this.argNum=g,this.type=a.REFERENCE,this.priority=h,i=b.get(c),"function"==typeof i&&(i=f(i,b,e)),this.value=e.values[g]=i,d(this)},g.prototype={update:function(){var a=this.root.get(this.keypath);"function"!=typeof a||a._nowrap||(a=f(a,this.root,this.evaluator)),b(a,this.value)||(this.evaluator.values[this.argNum]=a,this.evaluator.bubble(),this.value=a)},teardown:function(){e(this)}},g}(k,x,g,Q,R),pb=function(a,b,c){var d=function(a,c,d){this.root=a,this.keypath=c,this.priority=d.priority,this.evaluator=d,b(this)};return d.prototype={update:function(){var b=this.root.get(this.keypath);a(b,this.value)||(this.evaluator.bubble(),this.value=b)},teardown:function(){c(this)}},d}(x,Q,R),qb=function(a,b,c,d,e,f,g,h,i){function j(a,b){var c,d;if(a=a.replace(/\$\{([0-9]+)\}/g,"_$1"),l[a])return l[a];for(d=[];b--;)d[b]="_"+b;return c=new Function(d.join(","),"return("+a+")"),l[a]=c,c}var k,l={};return k=function(a,b,c,d,e){var f,g;for(this.root=a,this.keypath=b,this.priority=e,this.fn=j(c,d.length),this.values=[],this.refs=[],f=d.length;f--;)(g=d[f])?g[0]?this.values[f]=g[1]:this.refs[this.refs.length]=new h(a,g[1],this,f,e):this.values[f]=void 0;this.selfUpdating=this.refs.length<=1,this.update()},k.prototype={bubble:function(){this.selfUpdating?this.update():this.deferred||(this.root._deferred.evals.push(this),this.deferred=!0) -},update:function(){var b;if(this.evaluating)return this;this.evaluating=!0;try{b=this.fn.apply(null,this.values)}catch(e){if(this.root.debug)throw e;b=void 0}return a(b,this.value)||(c(this.root,this.keypath),this.root._cache[this.keypath]=b,g(this.root,this.keypath,b,!0),this.value=b,d(this.root,this.keypath)),this.evaluating=!1,this},teardown:function(){for(;this.refs.length;)this.refs.pop().teardown();c(this.root,this.keypath),this.root._evaluators[this.keypath]=null},refresh:function(){this.selfUpdating||(this.deferred=!0);for(var a=this.refs.length;a--;)this.refs[a].update();this.deferred&&(this.update(),this.deferred=!1)},updateSoftDependencies:function(a){var b,c,d;for(this.softRefs||(this.softRefs=[]),b=this.softRefs.length;b--;)d=this.softRefs[b],a[d.keypath]||(this.softRefs.splice(b,1),this.softRefs[d.keypath]=!1,d.teardown());for(b=a.length;b--;)c=a[b],this.softRefs[c]||(d=new i(this.root,c,this),this.softRefs[this.softRefs.length]=d,this.softRefs[c]=!0);this.selfUpdating=this.refs.length+this.softRefs.length<=1}},k}(x,g,m,r,Q,R,u,ob,pb),rb=function(a,b){var c=function(b,c,d,e){var f,g;g=this.root=b.root,f=a(g,c,d),void 0!==f?b.resolveRef(e,!1,f):(this.ref=c,this.argNum=e,this.resolver=b,this.contextStack=d,g._pendingResolution[g._pendingResolution.length]=this)};return c.prototype={resolve:function(a){this.keypath=a,this.resolver.resolveRef(this.argNum,!1,a)},teardown:function(){this.keypath||b(this)}},c}(y,nb),sb=function(){var a=/^(?:(?:[a-zA-Z$_][a-zA-Z$_0-9]*)|(?:[0-9]|[1-9][0-9]+))$/;return function(b){var c,d,e;for(c=b.split("."),e=c.length;e--;)if(d=c[e],"undefined"===d||!a.test(d))return!1;return!0}}(),tb=function(a,b){return function(c,d){var e,f;return e=c.replace(/\$\{([0-9]+)\}/g,function(a,b){return d[b]?d[b][1]:"undefined"}),f=a(e),b(f)?f:"${"+e.replace(/[\.\[\]]/g,"-")+"}"}}(i,sb),ub=function(a,b){function c(a,b,c){var e,f;if(e=a._depsMap[b])for(f=e.length;f--;)d(a,e[f],c)}function d(a,b,d){var e,f,g,h;for(e=a._deps.length;e--;)if(f=a._deps[e],f&&(g=f[b]))for(h=g.length;h--;)d.push(g[h]);c(a,b,d)}return function(c,e,f){var g,h,i;for(g=[],d(c,e,g),h=g.length;h--;)i=g[h],b(i),i.keypath=i.keypath.replace(e,f),a(i),i.update()}}(Q,R),vb=function(a,b,c,d){var e=function(a){var c,d,e,f,g;if(this.root=a.root,this.mustache=a,this.args=[],this.scouts=[],c=a.descriptor.x,g=a.parentFragment.indexRefs,this.str=c.s,e=this.unresolved=this.args.length=c.r?c.r.length:0,!e)return this.resolved=this.ready=!0,this.bubble(),void 0;for(d=0;e>d;d+=1)f=c.r[d],g&&void 0!==g[f]?this.resolveRef(d,!0,g[f]):this.scouts[this.scouts.length]=new b(this,f,a.contextStack,d);this.ready=!0,this.bubble()};return e.prototype={bubble:function(){var a;this.ready&&(a=this.keypath,this.keypath=c(this.str,this.args),"${"===this.keypath.substr(0,2)&&this.createEvaluator(),a?d(this.root,a,this.keypath):this.mustache.resolve(this.keypath))},teardown:function(){for(;this.scouts.length;)this.scouts.pop().teardown()},resolveRef:function(a,b,c){this.args[a]=[b,c],this.bubble(),this.resolved=!--this.unresolved},createEvaluator:function(){this.root._evaluators[this.keypath]?this.root._evaluators[this.keypath].refresh():this.root._evaluators[this.keypath]=new a(this.root,this.keypath,this.str,this.args,this.mustache.priority)}},e}(qb,rb,tb,ub),wb=function(a,b){return function(c,d){var e,f,g;g=c.parentFragment=d.parentFragment,c.root=g.root,c.contextStack=g.contextStack,c.descriptor=d.descriptor,c.index=d.index||0,c.priority=g.priority,c.type=d.descriptor.t,d.descriptor.r&&(g.indexRefs&&void 0!==g.indexRefs[d.descriptor.r]?(f=g.indexRefs[d.descriptor.r],c.indexRef=d.descriptor.r,c.value=f,c.render(c.value)):(e=a(c.root,d.descriptor.r,c.contextStack),void 0!==e?c.resolve(e):(c.ref=d.descriptor.r,c.root._pendingResolution[c.root._pendingResolution.length]=c))),d.descriptor.x&&(c.expressionResolver=new b(c)),c.descriptor.n&&!c.hasOwnProperty("value")&&c.render(void 0)}}(y,vb),xb=function(a,b,c){return function(d){d!==this.keypath&&(this.registered&&c(this),this.keypath=d,b(this),this.update(),this.root.twoway&&this.parentFragment.owner.type===a.ATTRIBUTE&&this.parentFragment.owner.element.bind(),this.expressionResolver&&this.expressionResolver.resolved&&(this.expressionResolver=null))}}(k,Q,R),yb=function(a){return function(){var b,c;c=this.root.get(this.keypath),(b=this.root._wrapped[this.keypath])&&(c=b.get()),a(c,this.value)||(this.render(c),this.value=c)}}(x),zb=function(a,b,c,d,e){var f,g,h;return g=//g,f=function(b,d){this.type=a.INTERPOLATOR,d&&(this.node=document.createTextNode(""),d.appendChild(this.node)),c(this,b)},f.prototype={update:e,resolve:d,detach:function(){return this.node.parentNode.removeChild(this.node),this.node},teardown:function(a){a&&this.detach(),b(this)},render:function(a){this.node&&(this.node.data=void 0==a?"":a)},firstNode:function(){return this.node},toString:function(){var a=void 0!=this.value?""+this.value:"";return a.replace(g,"<").replace(h,">")}},f}(k,nb,wb,xb,yb),Ab=function(a,b,c){function d(a,b,c){var d,e,f;if(e=b.length,ea.length)for(d=a.length;e>d;d+=1)c.contextStack=a.contextStack.concat(a.keypath+"."+d),c.index=d,a.descriptor.i&&(c.indexRef=a.descriptor.i),a.fragments[d]=a.createFragment(c);a.length=e}function e(a,b,d){var e,f;f=a.fragmentsById||(a.fragmentsById=c(null));for(e in f)void 0===b[e]&&f[e]&&(f[e].teardown(!0),f[e]=null);for(e in b)void 0===b[e]||f[e]||(d.contextStack=a.contextStack.concat(a.keypath+"."+e),d.index=e,a.descriptor.i&&(d.indexRef=a.descriptor.i),f[e]=a.createFragment(d))}function f(a,b){a.length||(b.contextStack=a.contextStack.concat(a.keypath),b.index=0,a.fragments[0]=a.createFragment(b),a.length=1)}function g(b,c,d,e){var f,g,h,i;if(g=a(c)&&0===c.length,f=d?g||!c:c&&!g){if(b.length||(e.contextStack=b.contextStack,e.index=0,b.fragments[0]=b.createFragment(e),b.length=1),b.length>1)for(h=b.fragments.splice(1);i=h.pop();)i.teardown(!0)}else b.length&&(b.teardownFragments(!0),b.length=0)}return function(c,h){var i;return i={descriptor:c.descriptor.f,root:c.root,pNode:c.parentFragment.pNode,owner:c},c.descriptor.n?(g(c,h,!0,i),void 0):(a(h)?d(c,h,i):b(h)?c.descriptor.i?e(c,h,i):f(c,i):g(c,h,!1,i),void 0)}}(l,w,c),Bb=function(a,b,c){function d(b,c,g,h,i,j,k){var l,m,n,o;if(!b.html){for(b.indexRefs&&void 0!==b.indexRefs[c]&&(b.indexRefs[c]=h),l=b.contextStack.length;l--;)n=b.contextStack[l],n.substr(0,j.length)===j&&(b.contextStack[l]=n.replace(j,k));for(l=b.items.length;l--;)switch(m=b.items[l],m.type){case a.ELEMENT:e(m,c,g,h,i,j,k);break;case a.PARTIAL:d(m.fragment,c,g,h,i,j,k);break;case a.COMPONENT:d(m.instance.fragment,c,g,h,i,j,k),(o=b.root._liveComponentQueries[m.name])&&o._makeDirty();break;case a.SECTION:case a.INTERPOLATOR:case a.TRIPLE:f(m,c,g,h,i,j,k)}}}function e(a,b,c,e,f,g,h){var i,j,k,l,m,n,o,p,q,r;for(i=a.attributes.length;i--;)j=a.attributes[i],j.fragment&&(d(j.fragment,b,c,e,f,g,h),j.twoway&&j.updateBindings());if(k=a.node._ractive){k.keypath.substr(0,g.length)===g&&(k.keypath=k.keypath.replace(g,h)),void 0!==b&&(k.index[b]=e);for(l in k.events)for(m=k.events[l].proxies,i=m.length;i--;)n=m[i],"object"==typeof n.n&&d(n.a,b,c,e,f,g,h),n.d&&d(n.d,b,c,e,f,g,h);(o=k.binding)&&o.keypath.substr(0,g.length)===g&&(p=k.root._twowayBindings[o.keypath],p.splice(p.indexOf(o),1),o.keypath=o.keypath.replace(g,h),p=k.root._twowayBindings[o.keypath]||(k.root._twowayBindings[o.keypath]=[]),p.push(o))}if(a.fragment&&d(a.fragment,b,c,e,f,g,h),q=a.liveQueries)for(r=a.root,i=q.length;i--;)r._liveQueries[q[i]]._makeDirty()}function f(a,b,e,f,g,h,i){var j;if(a.descriptor.x&&(a.expressionResolver&&a.expressionResolver.teardown(),a.expressionResolver=new c(a)),a.keypath?a.keypath.substr(0,h.length)===h&&a.resolve(a.keypath.replace(h,i)):a.indexRef===b&&(a.value=f,a.render(f)),a.fragments)for(j=a.fragments.length;j--;)d(a.fragments[j],b,e,f,g,h,i)}return d}(k,R,vb),Cb=function(a,b,c){return function(a,d,e,f,g){var h,i,j,k,l,m,n;for(j=d.descriptor.i,h=e;f>h;h+=1)i=d.fragments[h],k=h-g,l=h,m=d.keypath+"."+(h-g),n=d.keypath+"."+h,i.index+=g,b(i,j,k,l,g,m,n);c(a)}}(k,Bb,o),Db=function(a){return function(b){var c,d,e,f,g,h,i,j,k,l,m=this;if(c=this.parentFragment,h=[],b.forEach(function(b,c){var f,g,j;return b===c?(h[b]=m.fragments[c],void 0):(void 0===d&&(d=c),-1===b?((i||(i=[])).push(m.fragments[c]),void 0):(f=b-c,g=m.keypath+"."+c,j=m.keypath+"."+b,a(m.fragments[c],m.descriptor.i,c,b,f,g,j),h[b]=m.fragments[c],e=!0,void 0))}),i)for(;k=i.pop();)k.teardown(!0);if(void 0===d&&(d=this.length),g=this.root.get(this.keypath).length,g!==d){for(j={descriptor:this.descriptor.f,root:this.root,pNode:c.pNode,owner:this},this.descriptor.i&&(j.indexRef=this.descriptor.i),f=d;g>f;f+=1)(k=h[f])?this.docFrag.appendChild(k.detach(!1)):(j.contextStack=this.contextStack.concat(this.keypath+"."+f),j.index=f,k=this.createFragment(j)),this.fragments[f]=k;l=c.findNextNode(this),c.pNode.insertBefore(this.docFrag,l),this.length=g}}}(Bb),Eb=function(){return[]}(),Fb=function(a,b,c,d,e,f,g,h,i,j,k){var l,m;return k.push(function(){m=k.DomFragment}),l=function(b,d){this.type=a.SECTION,this.inverted=!!b.descriptor.n,this.fragments=[],this.length=0,d&&(this.docFrag=document.createDocumentFragment()),this.initialising=!0,c(this,b),d&&d.appendChild(this.docFrag),this.initialising=!1},l.prototype={update:d,resolve:e,smartUpdate:function(a,b){var c;("push"===a||"unshift"===a||"splice"===a)&&(c={descriptor:this.descriptor.f,root:this.root,pNode:this.parentFragment.pNode,owner:this},this.descriptor.i&&(c.indexRef=this.descriptor.i)),this[a]&&(this.rendering=!0,this[a](c,b),this.rendering=!1)},pop:function(){this.length&&(this.fragments.pop().teardown(!0),this.length-=1)},push:function(a,b){var c,d,e;for(c=this.length,d=c+b.length,e=c;d>e;e+=1)a.contextStack=this.contextStack.concat(this.keypath+"."+e),a.index=e,this.fragments[e]=this.createFragment(a);this.length+=b.length,this.parentFragment.pNode.insertBefore(this.docFrag,this.parentFragment.findNextNode(this))},shift:function(){this.splice(null,[0,1])},unshift:function(a,b){this.splice(a,[0,0].concat(new Array(b.length)))},splice:function(a,b){var c,d,e,f,g,i,j,k,l;if(b.length&&(i=+(b[0]<0?this.length+b[0]:b[0]),d=Math.max(0,b.length-2),e=void 0!==b[1]?b[1]:this.length-i,e=Math.min(e,this.length-i),f=d-e)){if(0>f){for(j=i-f,g=i;j>g;g+=1)this.fragments[g].teardown(!0);this.fragments.splice(i,-f)}else{for(j=i+f,c=this.fragments[i]?this.fragments[i].firstNode():this.parentFragment.findNextNode(this),k=[i,0].concat(new Array(f)),this.fragments.splice.apply(this.fragments,k),g=i;j>g;g+=1)a.contextStack=this.contextStack.concat(this.keypath+"."+g),a.index=g,this.fragments[g]=this.createFragment(a);this.parentFragment.pNode.insertBefore(this.docFrag,c)}this.length+=f,l=i+d,h(this.root,this,l,this.length,f)}},merge:i,detach:function(){var a,b;for(b=this.fragments.length,a=0;b>a;a+=1)this.docFrag.appendChild(this.fragments[a].detach());return this.docFrag},teardown:function(a){this.teardownFragments(a),j(this)},firstNode:function(){return this.fragments[0]?this.fragments[0].firstNode():this.parentFragment.findNextNode(this)},findNextNode:function(a){return this.fragments[a.index+1]?this.fragments[a.index+1].firstNode():this.parentFragment.findNextNode(this)},teardownFragments:function(a){for(var b,c;c=this.fragments.shift();)c.teardown(a);if(this.fragmentsById)for(b in this.fragmentsById)this.fragments[b]&&(this.fragmentsById[b].teardown(a),this.fragmentsById[b]=null)},render:function(a){var c,d;(d=this.root._wrapped[this.keypath])&&(a=d.get()),this.rendering||(this.rendering=!0,f(this,a),this.rendering=!1,(!this.docFrag||this.docFrag.childNodes.length)&&!this.initialising&&b&&(c=this.parentFragment.findNextNode(this),c&&c.parentNode===this.parentFragment.pNode?this.parentFragment.pNode.insertBefore(this.docFrag,c):this.parentFragment.pNode.appendChild(this.docFrag)))},createFragment:function(a){var b=new m(a);return this.docFrag&&this.docFrag.appendChild(b.docFrag),b},toString:function(){var a,b,c,d;for(a="",b=0,d=this.length,b=0;d>b;b+=1)a+=this.fragments[b].toString();if(this.fragmentsById)for(c in this.fragmentsById)this.fragmentsById[c]&&(a+=this.fragmentsById[c].toString());return a},find:function(a){var b,c,d;for(c=this.fragments.length,b=0;c>b;b+=1)if(d=this.fragments[b].find(a))return d;return null},findAll:function(a,b){var c,d;for(d=this.fragments.length,c=0;d>c;c+=1)this.fragments[c].findAll(a,b)},findComponent:function(a){var b,c,d;for(c=this.fragments.length,b=0;c>b;b+=1)if(d=this.fragments[b].findComponent(a))return d;return null},findAllComponents:function(a,b){var c,d;for(d=this.fragments.length,c=0;d>c;c+=1)this.fragments[c].findAllComponents(a,b)}},l}(k,f,wb,yb,xb,Ab,Bb,Cb,Db,nb,Eb),Gb=function(a,b,c,d,e,f,g){var h=function(b,d){this.type=a.TRIPLE,d&&(this.nodes=[],this.docFrag=document.createDocumentFragment()),this.initialising=!0,c(this,b),d&&d.appendChild(this.docFrag),this.initialising=!1};return h.prototype={update:d,resolve:e,detach:function(){for(var a=this.nodes.length;a--;)this.docFrag.appendChild(this.nodes[a]);return this.docFrag},teardown:function(a){a&&(this.detach(),this.docFrag=this.nodes=null),g(this)},firstNode:function(){return this.nodes[0]?this.nodes[0]:this.parentFragment.findNextNode(this)},render:function(a){var b,c;if(this.nodes){for(;this.nodes.length;)b=this.nodes.pop(),b.parentNode.removeChild(b);if(!a)return this.nodes=[],void 0;c=this.parentFragment.pNode,this.nodes=f(a,c.tagName,this.docFrag),this.initialising||c.insertBefore(this.docFrag,this.parentFragment.findNextNode(this))}},toString:function(){return void 0!=this.value?this.value:""},find:function(a){var c,d,e,f;for(d=this.nodes.length,c=0;d>c;c+=1)if(e=this.nodes[c],1===e.nodeType){if(b(e,a))return e;if(f=e.querySelector(a))return f}return null},findAll:function(a,c){var d,e,f,g,h,i;for(e=this.nodes.length,d=0;e>d;d+=1)if(f=this.nodes[d],1===f.nodeType&&(b(f,a)&&c.push(f),g=f.querySelectorAll(a)))for(h=g.length,i=0;h>i;i+=1)c.push(g[i])}},h}(k,Z,wb,yb,xb,lb,nb),Hb=function(a){return function(b,c){return b.a&&b.a.xmlns?b.a.xmlns:"svg"===b.e?a.svg:c.namespaceURI||a.html}}(d),Ib=function(){var a,b,c,d;return a="altGlyph altGlyphDef altGlyphItem animateColor animateMotion animateTransform clipPath feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile feTurbulence foreignObject glyphRef linearGradient radialGradient textPath vkern".split(" "),b="attributeName attributeType baseFrequency baseProfile calcMode clipPathUnits contentScriptType contentStyleType diffuseConstant edgeMode externalResourcesRequired filterRes filterUnits glyphRef gradientTransform gradientUnits kernelMatrix kernelUnitLength keyPoints keySplines keyTimes lengthAdjust limitingConeAngle markerHeight markerUnits markerWidth maskContentUnits maskUnits numOctaves pathLength patternContentUnits patternTransform patternUnits pointsAtX pointsAtY pointsAtZ preserveAlpha preserveAspectRatio primitiveUnits refX refY repeatCount repeatDur requiredExtensions requiredFeatures specularConstant specularExponent spreadMethod startOffset stdDeviation stitchTiles surfaceScale systemLanguage tableValues targetX targetY textLength viewBox viewTarget xChannelSelector yChannelSelector zoomAndPan".split(" "),c=function(a){for(var b={},c=a.length;c--;)b[a[c].toLowerCase()]=a[c];return b},d=c(a.concat(b)),function(a){var b=a.toLowerCase();return d[b]||b}}(),Jb=function(a,b){return function(c,d){var e,f;if(e=d.indexOf(":"),-1===e||(f=d.substr(0,e),"xmlns"===f))c.name=c.element.namespace!==a.html?b(d):d,c.lcName=c.name.toLowerCase();else if(d=d.substring(e+1),c.name=b(d),c.lcName=c.name.toLowerCase(),c.namespace=a[f.toLowerCase()],!c.namespace)throw'Unknown namespace ("'+f+'")'}}(d,Ib),Kb=function(a){return function(b,c){var d,e=null===c.value?"":c.value;(d=c.pNode)&&(b.namespace?d.setAttributeNS(b.namespace,c.name,e):"style"===c.name&&d.style.setAttribute?d.style.setAttribute("cssText",e):"class"!==c.name||d.namespaceURI&&d.namespaceURI!==a.html?d.setAttribute(c.name,e):d.className=e,"id"===b.name&&(c.root.nodes[c.value]=d),"value"===b.name&&(d._ractive.value=c.value)),b.value=c.value}}(d),Lb=function(a){var b={"accept-charset":"acceptCharset",accesskey:"accessKey",bgcolor:"bgColor","class":"className",codebase:"codeBase",colspan:"colSpan",contenteditable:"contentEditable",datetime:"dateTime",dirname:"dirName","for":"htmlFor","http-equiv":"httpEquiv",ismap:"isMap",maxlength:"maxLength",novalidate:"noValidate",pubdate:"pubDate",readonly:"readOnly",rowspan:"rowSpan",tabindex:"tabIndex",usemap:"useMap"};return function(c,d){var e;!c.pNode||c.namespace||d.pNode.namespaceURI&&d.pNode.namespaceURI!==a.html||(e=b[c.name]||c.name,void 0!==d.pNode[e]&&(c.propertyName=e),("boolean"==typeof d.pNode[e]||"value"===e)&&(c.useProperty=!0))}}(d),Mb=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q,r;return e=function(){var a,b,c,d=this.pNode;return this.fragment?(a=f(this))?(this.interpolator=a,this.keypath=a.keypath||a.descriptor.r,(b=i(this))?(d._ractive.binding=this.element.binding=b,this.twoway=!0,c=this.root._twowayBindings[this.keypath]||(this.root._twowayBindings[this.keypath]=[]),c[c.length]=b,!0):!1):!1:!1},g=function(){this._ractive.binding.update()},h=function(){var a=this._ractive.root.get(this._ractive.binding.keypath);this.value=void 0==a?"":a},f=function(c){var d,e;return 1!==c.fragment.items.length?null:(d=c.fragment.items[0],d.type!==a.INTERPOLATOR?null:d.keypath||d.ref?d.keypath&&"${"===d.keypath.substr(0,2)?(e="You cannot set up two-way binding against an expression "+d.keypath,c.root.debug&&b(e),null):d:null)},i=function(a){var c=a.pNode;if("SELECT"===c.tagName)return c.multiple?new k(a,c):new l(a,c);if("checkbox"===c.type||"radio"===c.type){if("name"===a.propertyName){if("checkbox"===c.type)return new n(a,c);if("radio"===c.type)return new m(a,c)}return"checked"===a.propertyName?new o(a,c):null}return"value"!==a.lcName&&b("This is... odd"),"file"===c.type?new p(a,c):c.getAttribute("contenteditable")?new q(a,c):new r(a,c)},k=function(a,b){var c;j(this,a,b),b.addEventListener("change",g,!1),c=this.root.get(this.keypath),void 0===c&&this.update()},k.prototype={value:function(){var a,b,c,d;for(a=[],b=this.node.options,d=b.length,c=0;d>c;c+=1)b[c].selected&&(a[a.length]=b[c]._ractive.value);return a},update:function(){var a,b,d;return a=this.attr,b=a.value,d=this.value(),void 0!==b&&c(d,b)||(a.receiving=!0,a.value=d,this.root.set(this.keypath,d),a.receiving=!1),this},deferUpdate:function(){this.deferred!==!0&&(this.root._deferred.attrs.push(this),this.deferred=!0)},teardown:function(){this.node.removeEventListener("change",g,!1)}},l=function(a,b){var c;j(this,a,b),b.addEventListener("change",g,!1),c=this.root.get(this.keypath),void 0===c&&this.update()},l.prototype={value:function(){var a,b,c;for(a=this.node.options,c=a.length,b=0;c>b;b+=1)if(a[b].selected)return a[b]._ractive.value},update:function(){var a=this.value();return this.attr.receiving=!0,this.attr.value=a,this.root.set(this.keypath,a),this.attr.receiving=!1,this},deferUpdate:function(){this.deferred!==!0&&(this.root._deferred.attrs.push(this),this.deferred=!0)},teardown:function(){this.node.removeEventListener("change",g,!1)}},m=function(a,b){var c;this.radioName=!0,j(this,a,b),b.name="{{"+a.keypath+"}}",b.addEventListener("change",g,!1),b.attachEvent&&b.addEventListener("click",g,!1),c=this.root.get(this.keypath),void 0!==c?b.checked=c==b._ractive.value:this.root._deferred.radios.push(this)},m.prototype={value:function(){return this.node._ractive?this.node._ractive.value:this.node.value},update:function(){var a=this.node;a.checked&&(this.attr.receiving=!0,this.root.set(this.keypath,this.value()),this.attr.receiving=!1)},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("click",g,!1)}},n=function(a,b){var c,d;this.checkboxName=!0,j(this,a,b),b.name="{{"+this.keypath+"}}",b.addEventListener("change",g,!1),b.attachEvent&&b.addEventListener("click",g,!1),c=this.root.get(this.keypath),void 0!==c?(d=-1!==c.indexOf(b._ractive.value),b.checked=d):-1===this.root._deferred.checkboxes.indexOf(this.keypath)&&this.root._deferred.checkboxes.push(this.keypath)},n.prototype={changed:function(){return this.node.checked!==!!this.checked},update:function(){this.checked=this.node.checked,this.attr.receiving=!0,this.root.set(this.keypath,d(this.root,this.keypath)),this.attr.receiving=!1},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("click",g,!1)}},o=function(a,b){j(this,a,b),b.addEventListener("change",g,!1),b.attachEvent&&b.addEventListener("click",g,!1)},o.prototype={value:function(){return this.node.checked},update:function(){this.attr.receiving=!0,this.root.set(this.keypath,this.value()),this.attr.receiving=!1},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("click",g,!1)}},p=function(a,b){j(this,a,b),b.addEventListener("change",g,!1)},p.prototype={value:function(){return this.attr.pNode.files},update:function(){this.attr.root.set(this.attr.keypath,this.value())},teardown:function(){this.node.removeEventListener("change",g,!1)}},q=function(a,b){j(this,a,b),b.addEventListener("change",g,!1),this.root.lazy||(b.addEventListener("input",g,!1),b.attachEvent&&b.addEventListener("keyup",g,!1))},q.prototype={update:function(){this.attr.receiving=!0,this.root.set(this.keypath,this.node.innerHTML),this.attr.receiving=!1},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("input",g,!1),this.node.removeEventListener("keyup",g,!1)}},r=function(a,b){j(this,a,b),b.addEventListener("change",g,!1),this.root.lazy||(b.addEventListener("input",g,!1),b.attachEvent&&b.addEventListener("keyup",g,!1)),this.node.addEventListener("blur",h,!1)},r.prototype={value:function(){var a=this.attr.pNode.value;return+a+""===a&&-1===a.indexOf("e")&&(a=+a),a},update:function(){var a=this.attr,b=this.value();a.receiving=!0,a.root.set(a.keypath,b),a.receiving=!1},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("input",g,!1),this.node.removeEventListener("keyup",g,!1),this.node.removeEventListener("blur",h,!1)}},j=function(a,b,c){a.attr=b,a.node=c,a.root=b.root,a.keypath=b.keypath},e}(k,I,E,n),Nb=function(a,b){var c,d,e,f,g,h,i,j,k,l,m,n;return c=function(){var a;if(!this.ready)return this;if(a=this.pNode,"SELECT"===a.tagName&&"value"===this.lcName)return this.update=e,this.deferredUpdate=f,this.update();if(this.isFileInputValue)return this.update=d,this;if(this.twoway&&"name"===this.lcName){if("radio"===a.type)return this.update=i,this.update();if("checkbox"===a.type)return this.update=j,this.update()}return"style"===this.lcName&&a.style.setAttribute?(this.update=k,this.update()):"class"!==this.lcName||a.namespaceURI&&a.namespaceURI!==b.html?a.getAttribute("contenteditable")&&"value"===this.lcName?(this.update=m,this.update()):(this.update=n,this.update()):(this.update=l,this.update())},d=function(){return this},f=function(){this.deferredUpdate=this.pNode.multiple?h:g,this.deferredUpdate()},e=function(){return this.root._deferred.selectValues.push(this),this},g=function(){var a,b,c,d=this.fragment.getValue();for(this.value=this.pNode._ractive.value=d,a=this.pNode.options,c=a.length;c--;)if(b=a[c],b._ractive.value==d)return b.selected=!0,this;return this},h=function(){var b,c,d=this.fragment.getValue();for(a(d)||(d=[d]),b=this.pNode.options,c=b.length;c--;)b[c].selected=-1!==d.indexOf(b[c]._ractive.value);return this.value=d,this},i=function(){var a,b;return a=this.pNode,b=this.fragment.getValue(),a.checked=b==a._ractive.value,this},j=function(){var b,c;return b=this.pNode,c=this.fragment.getValue(),a(c)?(b.checked=-1!==c.indexOf(b._ractive.value),this):(b.checked=c==b._ractive.value,this)},k=function(){var a,b;return a=this.pNode,b=this.fragment.getValue(),void 0===b&&(b=""),b!==this.value&&(a.style.setAttribute("cssText",b),this.value=b),this},l=function(){var a,b;return a=this.pNode,b=this.fragment.getValue(),void 0===b&&(b=""),b!==this.value&&(a.className=b,this.value=b),this},m=function(){var a,b;return a=this.pNode,b=this.fragment.getValue(),void 0===b&&(b=""),b!==this.value&&(this.receiving||(a.innerHTML=b),this.value=b),this},n=function(){var a,b;if(a=this.pNode,b=this.fragment.getValue(),this.isValueAttribute&&(a._ractive.value=b),void 0===b&&(b=""),b!==this.value){if(this.useProperty)return this.receiving||(a[this.propertyName]=b),this.value=b,this;if(this.namespace)return a.setAttributeNS(this.namespace,this.name,b),this.value=b,this;"id"===this.lcName&&(void 0!==this.value&&(this.root.nodes[this.value]=void 0),this.root.nodes[b]=a),a.setAttribute(this.name,b),this.value=b}return this},c}(l,d),Ob=function(){return function(a){var b;return b=this.str.substr(this.pos,a.length),b===a?(this.pos+=a.length,a):null}}(),Pb=function(){var a=/^\s+/;return function(){var b=a.exec(this.remaining());return b?(this.pos+=b[0].length,b[0]):null}}(),Qb=function(){return function(a){return function(b){var c=a.exec(b.str.substring(b.pos));return c?(b.pos+=c[0].length,c[1]||c[0]):null}}}(),Rb=function(){function a(a){var b;return a.getStringMatch("\\")?(b=a.str.charAt(a.pos),a.pos+=1,b):null}return function(b){var c,d="";for(c=a(b);c;)d+=c,c=a(b);return d||null}}(),Sb=function(a,b){var c=a(/^[^\\"]+/),d=a(/^[^\\']+/);return function e(a,f){var g,h,i,j,k,l;if(g=a.pos,h="",l=f?d:c,i=b(a),i&&(h+=i),j=l(a),j&&(h+=j),!h)return"";for(k=e(a,f);""!==k;)h+=k;return h}}(Qb,Rb),Tb=function(a,b){return function(c){var d,e;return d=c.pos,c.getStringMatch('"')?(e=b(c,!1),c.getStringMatch('"')?{t:a.STRING_LITERAL,v:e}:(c.pos=d,null)):c.getStringMatch("'")?(e=b(c,!0),c.getStringMatch("'")?{t:a.STRING_LITERAL,v:e}:(c.pos=d,null)):null}}(k,Sb),Ub=function(a,b){var c=b(/^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/);return function(b){var d;return(d=c(b))?{t:a.NUMBER_LITERAL,v:d}:null}}(k,Qb),Vb=function(a){return a(/^[a-zA-Z_$][a-zA-Z_$0-9]*/)}(Qb),Wb=function(a,b,c){var d=/^[a-zA-Z_$][a-zA-Z_$0-9]*$/;return function(e){var f;return(f=a(e))?d.test(f.v)?f.v:'"'+f.v.replace(/"/g,'\\"')+'"':(f=b(e))?f.v:(f=c(e))?f:void 0}}(Tb,Ub,Vb),Xb=function(a,b,c,d){function e(a){var b,c,e;return a.allowWhitespace(),(b=d(a))?(e={key:b},a.allowWhitespace(),a.getStringMatch(":")?(a.allowWhitespace(),(c=a.getToken())?(e.value=c.v,e):null):null):null}var f,g,h,i,j,k;return g={"true":!0,"false":!1,undefined:void 0,"null":null},h=new RegExp("^(?:"+Object.keys(g).join("|")+")"),i=/^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/,j=/\$\{([^\}]+)\}/g,k=/^\$\{([^\}]+)\}/,f=function(a,b){this.str=a,this.values=b,this.pos=0,this.result=this.getToken()},f.prototype={remaining:function(){return this.str.substring(this.pos)},getStringMatch:a,getToken:function(){return this.allowWhitespace(),this.getPlaceholder()||this.getSpecial()||this.getNumber()||this.getString()||this.getObject()||this.getArray()},getPlaceholder:function(){var a;return this.values?(a=k.exec(this.remaining()))&&this.values.hasOwnProperty(a[1])?(this.pos+=a[0].length,{v:this.values[a[1]]}):void 0:null},getSpecial:function(){var a;return(a=h.exec(this.remaining()))?(this.pos+=a[0].length,{v:g[a[0]]}):void 0},getNumber:function(){var a;return(a=i.exec(this.remaining()))?(this.pos+=a[0].length,{v:+a[0]}):void 0},getString:function(){var a,b=c(this);return b&&(a=this.values)?{v:b.v.replace(j,function(b,c){return a[c]||c})}:b},getObject:function(){var a,b;if(!this.getStringMatch("{"))return null;for(a={};b=e(this);){if(a[b.key]=b.value,this.allowWhitespace(),this.getStringMatch("}"))return{v:a};if(!this.getStringMatch(","))return null}return null},getArray:function(){var a,b;if(!this.getStringMatch("["))return null;for(a=[];b=this.getToken();){if(a.push(b.v),this.getStringMatch("]"))return{v:a};if(!this.getStringMatch(","))return null}return null},allowWhitespace:b},function(a,b){var c=new f(a,b);return c.result?{value:c.result.v,remaining:c.remaining()}:null}}(Ob,Pb,Tb,Wb),Yb=function(a,b,c,d,e){function f(a){return"string"==typeof a?a:JSON.stringify(a)}var g=function(b){this.type=a.INTERPOLATOR,c(this,b)};return g.prototype={update:d,resolve:e,render:function(a){this.value=a,this.parentFragment.bubble()},teardown:function(){b(this)},toString:function(){return void 0==this.value?"":f(this.value)}},g}(k,nb,wb,yb,xb),Zb=function(a,b,c,d,e,f,g){var h,i;return g.push(function(){i=g.StringFragment}),h=function(c){this.type=a.SECTION,this.fragments=[],this.length=0,b(this,c)},h.prototype={update:c,resolve:d,teardown:function(){this.teardownFragments(),f(this)},teardownFragments:function(){for(;this.fragments.length;)this.fragments.shift().teardown();this.length=0},bubble:function(){this.value=this.fragments.join(""),this.parentFragment.bubble()},render:function(a){var b;(b=this.root._wrapped[this.keypath])&&(a=b.get()),e(this,a),this.parentFragment.bubble()},createFragment:function(a){return new i(a)},toString:function(){return this.fragments.join("")}},h}(k,wb,yb,xb,Ab,nb,Eb),$b=function(a){var b=function(b){this.type=a.TEXT,this.text=b};return b.prototype={toString:function(){return this.text},teardown:function(){}},b}(k),_b=function(a,b){return function(){var c,d,e,f,g,h,i;if(!this.argsList||this.dirty){if(c={},d=0,f=this.root._guid,i=function(a){return a.map(function(a){var b,e,g;return a.text?a.text:a.fragments?a.fragments.map(function(a){return i(a.items)}).join(""):(b=f+"-"+d++,g=(e=a.root._wrapped[a.keypath])?e.value:a.value,c[b]=g,"${"+b+"}")}).join("")},e=i(this.items),h=b("["+e+"]",c))this.argsList=h.value;else{if(g="Could not parse directive arguments ("+this.toString()+"). If you think this is a bug, please file an issue at http://github.com/RactiveJS/Ractive/issues",this.root.debug)throw new Error(g);a(g),this.argsList=[e]}this.dirty=!1}return this.argsList}}(I,Xb),ac=function(a,b,c,d,e,f,g,h){var i=function(a){c(this,a)};return i.prototype={createItem:function(b){if("string"==typeof b.descriptor)return new f(b.descriptor);switch(b.descriptor.t){case a.INTERPOLATOR:return new d(b);case a.TRIPLE:return new d(b);case a.SECTION:return new e(b);default:throw"Something went wrong in a rather interesting way"}},bubble:function(){this.dirty=!0,this.owner.bubble()},teardown:function(){var a,b;for(a=this.items.length,b=0;a>b;b+=1)this.items[b].teardown()},getValue:function(){var b;return 1===this.items.length&&this.items[0].type===a.INTERPOLATOR&&(b=this.items[0].value,void 0!==b)?b:this.toString()},isSimple:function(){var b,c,d;if(void 0!==this.simple)return this.simple;for(b=this.items.length;b--;)if(c=this.items[b],c.type!==a.TEXT){if(c.type!==a.INTERPOLATOR)return this.simple=!1;if(d)return!1;d=!0}return this.simple=!0},toString:function(){return this.items.join("")},toJSON:function(){var a,c=this.getValue();return"string"==typeof c&&(a=b(c),c=a?a.value:c),c},toArgsList:g},h.StringFragment=i,i}(k,Xb,kb,Yb,Zb,$b,_b,Eb),bc=function(a,b,c,d,e,f,g){var h=function(e){return this.type=a.ATTRIBUTE,this.element=e.element,b(this,e.name),null===e.value||"string"==typeof e.value?(c(this,e),void 0):(this.root=e.root,this.pNode=e.pNode,this.parentFragment=this.element.parentFragment,this.fragment=new g({descriptor:e.value,root:this.root,owner:this,contextStack:e.contextStack}),this.pNode&&("value"===this.name&&(this.isValueAttribute=!0,"INPUT"===this.pNode.tagName&&"file"===this.pNode.type&&(this.isFileInputValue=!0)),d(this,e),this.selfUpdating=this.fragment.isSimple(),this.ready=!0),void 0)};return h.prototype={bind:e,update:f,updateBindings:function(){this.keypath=this.interpolator.keypath||this.interpolator.ref,"name"===this.propertyName&&(this.pNode.name="{{"+this.keypath+"}}") -},teardown:function(){var a;if(this.boundEvents)for(a=this.boundEvents.length;a--;)this.pNode.removeEventListener(this.boundEvents[a],this.updateModel,!1);this.fragment&&this.fragment.teardown()},bubble:function(){this.selfUpdating?this.update():!this.deferred&&this.ready&&(this.root._deferred.attrs.push(this),this.deferred=!0)},toString:function(){var a;return null===this.value?this.name:this.fragment?(a=this.fragment.toString(),this.name+"="+JSON.stringify(a)):this.name+"="+JSON.stringify(this.value)}},h}(k,Jb,Kb,Lb,Mb,Nb,ac),cc=function(a){return function(b,c){var d,e,f;b.attributes=[];for(d in c)c.hasOwnProperty(d)&&(e=c[d],f=new a({element:b,name:d,value:e,root:b.root,pNode:b.node,contextStack:b.parentFragment.contextStack}),b.attributes[b.attributes.length]=b.attributes[d]=f,"name"!==d&&f.update());return b.attributes}}(bc),dc=function(a,b,c,d){var e,f,g;return d.push(function(){e=d.DomFragment}),f=function(){var a=this.node,b=this.fragment.toString();a.styleSheet&&(a.styleSheet.cssText=b),a.innerHTML=b},g=function(){this.node.type&&"text/javascript"!==this.node.type||a("Script tag was updated. This does not cause the code to be re-evaluated!"),this.node.innerHTML=this.fragment.toString()},function(a,d,h,i){var j,k,l,m,n;if("script"===a.lcName||"style"===a.lcName)return a.fragment=new c({descriptor:h.f,root:a.root,contextStack:a.parentFragment.contextStack,owner:a}),i&&("script"===a.lcName?(a.bubble=g,a.node.innerHTML=a.fragment.toString()):(a.bubble=f,a.bubble())),void 0;if("string"!=typeof h.f||d&&d.namespaceURI&&d.namespaceURI!==b.html)a.fragment=new e({descriptor:h.f,root:a.root,pNode:d,contextStack:a.parentFragment.contextStack,owner:a}),i&&d.appendChild(a.fragment.docFrag);else if(a.html=h.f,i)for(d.innerHTML=a.html,j=a.root._liveQueries,k=j.length;k--;)if(l=j[k],(m=d.querySelectorAll(l))&&(n=m.length))for((a.liveQueries||(a.liveQueries=[])).push(l),a.liveQueries[l]=[];n--;)a.liveQueries[l][n]=m[n]}}(I,d,ac,Eb),ec=function(a,b){var c=function(c,d,e,f){var g,h,i;if(this.root=d,this.node=e.node,g=c.n||c,"string"!=typeof g&&(h=new b({descriptor:g,root:this.root,owner:e,contextStack:f}),g=h.toString(),h.teardown()),c.a?this.params=c.a:c.d&&(h=new b({descriptor:c.d,root:this.root,owner:e,contextStack:f}),this.params=h.toArgsList(),h.teardown()),this.fn=d.decorators[g],!this.fn){if(i='Missing "'+g+'" decorator. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#decorators',d.debug)throw new Error(i);a(i)}};return c.prototype={init:function(){var a,b;if(this.params?(b=[this.node].concat(this.params),a=this.fn.apply(this.root,b)):a=this.fn.call(this.root,this.node),!a||!a.teardown)throw new Error("Decorator definition must return an object with a teardown method");this.teardown=a.teardown}},c}(I,ac),fc=function(a){return function(b,c,d,e){d.decorator=new a(b,c,d,e),d.decorator.fn&&c._deferred.decorators.push(d.decorator)}}(ec),gc=function(a,b){var c,d,e,f,g,h,i,j,k;return c=function(a,b,c,e,f){var g,h;g=a.node._ractive.events,h=g[b]||(g[b]=new d(a,b,e,f)),h.add(c)},d=function(b,c,d){var e;this.element=b,this.root=b.root,this.node=b.node,this.name=c,this.contextStack=d,this.proxies=[],(e=this.root.events[c])?this.custom=e(this.node,k(c)):("on"+c in this.node||a('Missing "'+this.name+'" event. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#events'),this.node.addEventListener(c,j,!1))},d.prototype={add:function(a){this.proxies[this.proxies.length]=new e(this.element,this.root,a,this.contextStack)},teardown:function(){var a;for(this.custom?this.custom.teardown():this.node.removeEventListener(this.name,j,!1),a=this.proxies.length;a--;)this.proxies[a].teardown()},fire:function(a){for(var b=this.proxies.length;b--;)this.proxies[b].fire(a)}},e=function(a,c,d,e){var i;return this.root=c,i=d.n||d,this.n="string"==typeof i?i:new b({descriptor:d.n,root:this.root,owner:a,contextStack:e}),d.a?(this.a=d.a,this.fire=g,void 0):d.d?(this.d=new b({descriptor:d.d,root:this.root,owner:a,contextStack:e}),this.fire=h,void 0):(this.fire=f,void 0)},e.prototype={teardown:function(){this.n.teardown&&this.n.teardown(),this.d&&this.d.teardown()},bubble:function(){}},f=function(a){this.root.fire(this.n.toString(),a)},g=function(a){this.root.fire.apply(this.root,[this.n.toString(),a].concat(this.a))},h=function(a){var b=this.d.toArgsList();"string"==typeof b&&(b=b.substr(1,b.length-2)),this.root.fire.apply(this.root,[this.n.toString(),a].concat(b))},j=function(a){var b=this._ractive;b.events[a.type].fire({node:this,original:a,index:b.index,keypath:b.keypath,context:b.root.get(b.keypath)})},i={},k=function(a){return i[a]?i[a]:i[a]=function(b){var c=b.node._ractive;b.index=c.index,b.keypath=c.keypath,b.context=c.root.get(c.keypath),c.events[a].fire(b)}},c}(I,ac),hc=function(a){return function(b,c){var d,e,f;for(e in c)if(c.hasOwnProperty(e))for(f=e.split("-"),d=f.length;d--;)a(b,f[d],c[e],b.parentFragment.contextStack)}}(gc),ic=function(){return function(a){var b,c,d,e,f;for(b=a.root,c=b._liveQueries,d=c.length;d--;)e=c[d],f=c[e],f._test(a)&&((a.liveQueries||(a.liveQueries=[])).push(e),a.liveQueries[e]=[a.node])}}(),jc=function(){return function(a){return a.replace(/-([a-zA-Z])/g,function(a,b){return b.toUpperCase()})}}(),kc=function(){return function(a,b){var c;for(c in b)b.hasOwnProperty(c)&&!a.hasOwnProperty(c)&&(a[c]=b[c]);return a}}(),lc=function(a,b,c,d,e,f,g,h){function i(a){var b,c,d;if(!q[a])if(void 0!==m[a])q[a]=a;else for(d=a.charAt(0).toUpperCase()+a.substring(1),b=n.length;b--;)if(c=n[b],void 0!==m[c+d]){q[a]=c+d;break}return q[a]}function j(a){return a.replace(p,"")}function k(a){var b;return o.test(a)&&(a="-"+a),b=a.replace(/[A-Z]/g,function(a){return"-"+a.toLowerCase()})}var l,m,n,o,p,q,r,s,t,u,v,w;if(a)return m=b("div").style,function(){void 0!==m.transition?(s="transition",w="transitionend",r=!0):void 0!==m.webkitTransition?(s="webkitTransition",w="webkitTransitionEnd",r=!0):r=!1}(),s&&(t=s+"Duration",u=s+"Property",v=s+"TimingFunction"),l=function(a,b,d,e,f){var g,i,j,k=this;if(this.root=b,this.node=d.node,this.isIntro=f,this.originalStyle=this.node.getAttribute("style"),this.complete=function(a){!a&&k.isIntro&&k.resetStyle(),k._manager.pop(k.node),k.node._ractive.transition=null},g=a.n||a,"string"!=typeof g&&(i=new h({descriptor:g,root:this.root,owner:d,contextStack:e}),g=i.toString(),i.teardown()),this.name=g,a.a?this.params=a.a:a.d&&(i=new h({descriptor:a.d,root:this.root,owner:d,contextStack:e}),this.params=i.toArgsList(),i.teardown()),this._fn=b.transitions[g],!this._fn){if(j='Missing "'+g+'" transition. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#transitions',b.debug)throw new Error(j);return c(j),void 0}},l.prototype={init:function(){if(this._inited)throw new Error("Cannot initialize a transition more than once");this._inited=!0,this._fn.apply(this.root,[this].concat(this.params))},getStyle:function(a){var b,c,d,f,g;if(b=window.getComputedStyle(this.node),"string"==typeof a)return g=b[i(a)],"0px"===g&&(g=0),g;if(!e(a))throw new Error("Transition#getStyle must be passed a string, or an array of strings representing CSS properties");for(c={},d=a.length;d--;)f=a[d],g=b[i(f)],"0px"===g&&(g=0),c[f]=g;return c},setStyle:function(a,b){var c;if("string"==typeof a)this.node.style[i(a)]=b;else for(c in a)a.hasOwnProperty(c)&&(this.node.style[i(c)]=a[c]);return this},animateStyle:function(a,b,d,e){var g,h,l,m,n,o,p,q,r,s=this;for("string"==typeof a?(n={},n[a]=b):(n=a,e=d,d=b),d||(c('The "'+s.name+'" transition does not supply an options object to `t.animateStyle()`. This will break in a future version of Ractive. For more info see https://github.com/RactiveJS/Ractive/issues/340'),d=s,e=s.complete),d.duration||(s.setStyle(n),e&&e()),g=Object.keys(n),h=[],l=window.getComputedStyle(s.node),o={},q=g.length;q--;)r=g[q],m=l[i(r)],"0px"===m&&(m=0),m!=n[r]&&(h[h.length]=r,s.node.style[i(r)]=m);return h.length?(setTimeout(function(){s.node.style[u]=g.map(i).map(k).join(","),s.node.style[v]=k(d.easing||"linear"),s.node.style[t]=d.duration/1e3+"s",p=function(a){var b;b=h.indexOf(f(j(a.propertyName))),-1!==b&&h.splice(b,1),h.length||(s.root.fire(s.name+":end"),s.node.removeEventListener(w,p,!1),e&&e())},s.node.addEventListener(w,p,!1),setTimeout(function(){for(var a=h.length;a--;)r=h[a],s.node.style[i(r)]=n[r]},0)},d.delay||0),void 0):(e&&e(),void 0)},resetStyle:function(){this.originalStyle?this.node.setAttribute("style",this.originalStyle):(this.node.getAttribute("style"),this.node.removeAttribute("style"))},processParams:function(a,b){return"number"==typeof a?a={duration:a}:"string"==typeof a?a="slow"===a?{duration:600}:"fast"===a?{duration:200}:{duration:400}:a||(a={}),g(a,b)}},n=["o","ms","moz","webkit"],o=new RegExp("^(?:"+n.join("|")+")([A-Z])"),p=new RegExp("^-(?:"+n.join("|")+")-"),q={},l}(f,e,I,J,l,jc,kc,ac),mc=function(a,b){return function(a,c,d,e,f){var g,h,i;!c.transitionsEnabled||c._parent&&!c._parent.transitionsEnabled||(g=new b(a,c,d,e,f),g._fn&&(h=g.node,g._manager=c._transitionManager,(i=h._ractive.transition)&&i.complete(),h._ractive.transition=g,g._manager.push(h),f?c._deferred.transitions.push(g):g.init()))}}(I,lc),nc=function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o){return function(e,p,q){var r,s,t,u,v,w,x,y,z,A,B,C,D;if(e.type=a.ELEMENT,r=e.parentFragment=p.parentFragment,s=r.pNode,t=r.contextStack,u=e.descriptor=p.descriptor,e.root=B=r.root,e.index=p.index,e.lcName=u.e.toLowerCase(),e.eventListeners=[],e.customEventListeners=[],s&&(v=e.namespace=h(u,s),w=v!==b.html?o(u.e):u.e,e.node=g(w,v),d(e.node,"_ractive",{value:{proxy:e,keypath:t.length?t[t.length-1]:"",index:r.indexRefs,events:c(null),root:B}})),x=i(e,u.a),u.f){if(e.node&&e.node.getAttribute("contenteditable")&&e.node.innerHTML){if(D="A pre-populated contenteditable element should not have children",B.debug)throw new Error(D);f(D)}j(e,e.node,u,q)}q&&u.v&&l(e,u.v),q&&(B.twoway&&(e.bind(),e.node.getAttribute("contenteditable")&&e.node._ractive.binding&&e.node._ractive.binding.update()),x.name&&!x.name.twoway&&x.name.update(),"IMG"===e.node.tagName&&((y=e.attributes.width)||(z=e.attributes.height))&&e.node.addEventListener("load",A=function(){y&&(e.node.width=y.value),z&&(e.node.height=z.value),e.node.removeEventListener("load",A,!1)},!1),q.appendChild(e.node),u.o&&k(u.o,B,e,t),u.t1&&n(u.t1,B,e,t,!0),"OPTION"===e.node.tagName&&("SELECT"===s.tagName&&(C=s._ractive.binding)&&C.deferUpdate(),e.node._ractive.value==s._ractive.value&&(e.node.selected=!0)),e.node.autofocus&&(B._deferred.focusable=e.node)),m(e)}}(k,d,c,g,Z,I,e,Hb,cc,dc,fc,hc,ic,mc,Ib),oc=function(a){return function(b){var c,d,e,f,g,h,i,j,k;for(this.fragment&&this.fragment.teardown(!1);this.attributes.length;)this.attributes.pop().teardown();if(this.node){for(c in this.node._ractive.events)this.node._ractive.events[c].teardown();(d=this.node._ractive.binding)&&(d.teardown(),e=this.root._twowayBindings[d.attr.keypath],e.splice(e.indexOf(d),1))}if(this.decorator&&this.decorator.teardown(),this.descriptor.t2&&a(this.descriptor.t2,this.root,this,this.parentFragment.contextStack,!1),b&&this.root._transitionManager.detachWhenReady(this),g=this.liveQueries)for(f=g.length;f--;)if(h=g[f],j=this.liveQueries[h])for(k=j.length,i=this.root._liveQueries[h];k--;)i._remove(j[k])}}(mc),pc=function(){return"area base br col command doctype embed hr img input keygen link meta param source track wbr".split(" ")}(),qc=function(a){return function(){var b,c,d;for(b="<"+(this.descriptor.y?"!doctype":this.descriptor.e),d=this.attributes.length,c=0;d>c;c+=1)b+=" "+this.attributes[c].toString();return b+=">",this.html?b+=this.html:this.fragment&&(b+=this.fragment.toString()),-1===a.indexOf(this.descriptor.e)&&(b+=""+this.descriptor.e+">"),b}}(pc),rc=function(a){return function(b){var c;return a(this.node,b)?this.node:this.html&&(c=this.node.querySelector(b))?c:this.fragment&&this.fragment.find?this.fragment.find(b):void 0}}(Z),sc=function(){return function(a,b){var c,d,e,f,g;if(b._test(this,!0)&&b.live&&((this.liveQueries||(this.liveQueries=[])).push(a),this.liveQueries[a]=[this.node]),this.html&&(c=this.node.querySelectorAll(a))&&(e=c.length))for(b.live&&(this.liveQueries[a]||((this.liveQueries||(this.liveQueries=[])).push(a),this.liveQueries[a]=[]),g=this.liveQueries[a]),d=0;e>d;d+=1)f=c[d],b.push(f),b.live&&g.push(f);this.fragment&&this.fragment.findAll(a,b)}}(),tc=function(){return function(a){return this.fragment?this.fragment.findComponent(a):void 0}}(),uc=function(){return function(a,b){this.fragment&&this.fragment.findAllComponents(a,b)}}(),vc=function(){return function(){var a=this.attributes;if(this.node&&(this.binding&&(this.binding.teardown(),this.binding=null),!(this.node.getAttribute("contenteditable")&&a.value&&a.value.bind())))switch(this.descriptor.e){case"select":case"textarea":return a.value&&a.value.bind(),void 0;case"input":if("radio"===this.node.type||"checkbox"===this.node.type){if(a.name&&a.name.bind())return;if(a.checked&&a.checked.bind())return}if(a.value&&a.value.bind())return}}}(),wc=function(a,b,c,d,e,f,g,h){var i=function(b,c){a(this,b,c)};return i.prototype={detach:function(){return this.node?(this.node.parentNode&&this.node.parentNode.removeChild(this.node),this.node):void 0},teardown:b,firstNode:function(){return this.node},findNextNode:function(){return null},bubble:function(){},toString:c,find:d,findAll:e,findComponent:f,findAllComponents:g,bind:h},i}(nc,oc,qc,rc,sc,tc,uc,vc),xc={missingParser:"Missing Ractive.parse - cannot parse template. Either preparse or use the version that includes the parser"},yc={},zc=function(a,b,c,d,e,f){var g,h,i,j;return g=function(d,g){var k,l,m;if(l=i(d,g))return l;if(b&&(k=document.getElementById(g),k&&"SCRIPT"===k.tagName)){if(!f)throw new Error(a.missingParser);h(f(k.innerHTML),g,e)}if(l=e[g],!l){if(m='Could not find descriptor for partial "'+g+'"',d.debug)throw new Error(m);return c(m),[]}return j(l)},i=function(b,c){var d;if(b.partials[c]){if("string"==typeof b.partials[c]){if(!f)throw new Error(a.missingParser);d=f(b.partials[c],b.parseOptions),h(d,c,b.partials)}return j(b.partials[c])}},h=function(a,b,c){var e;if(d(a)){c[b]=a.main;for(e in a.partials)a.partials.hasOwnProperty(e)&&(c[e]=a.partials[e])}else c[b]=a},j=function(a){return 1===a.length&&"string"==typeof a[0]?a[0]:a},g}(xc,f,I,w,yc,parse__parse),Ac=function(a,b,c){var d,e;return c.push(function(){e=c.DomFragment}),d=function(c,d){var f,g=this.parentFragment=c.parentFragment;if(this.type=a.PARTIAL,this.name=c.descriptor.r,this.index=c.index,!c.descriptor.r)throw new Error("Partials must have a static reference (no expressions). This may change in a future version of Ractive.");f=b(g.root,c.descriptor.r),this.fragment=new e({descriptor:f,root:g.root,pNode:g.pNode,contextStack:g.contextStack,owner:this}),d&&d.appendChild(this.fragment.docFrag)},d.prototype={firstNode:function(){return this.fragment.firstNode()},findNextNode:function(){return this.parentFragment.findNextNode(this)},detach:function(){return this.fragment.detach()},teardown:function(a){this.fragment.teardown(a)},toString:function(){return this.fragment.toString()},find:function(a){return this.fragment.find(a)},findAll:function(a,b){return this.fragment.findAll(a,b)},findComponent:function(a){return this.fragment.findComponent(a)},findAllComponents:function(a,b){return this.fragment.findAllComponents(a,b)}},d}(k,zc,Eb),Bc=function(a){var b=function(b,c,d){this.parentFragment=b.parentFragment,this.component=b,this.key=c,this.fragment=new a({descriptor:d,root:b.root,owner:this,contextStack:b.parentFragment.contextStack}),this.selfUpdating=this.fragment.isSimple(),this.value=this.fragment.getValue()};return b.prototype={bubble:function(){this.selfUpdating?this.update():!this.deferred&&this.ready&&(this.root._deferred.attrs.push(this),this.deferred=!0)},update:function(){var a=this.fragment.getValue();this.component.instance.set(this.key,a),this.value=a},teardown:function(){this.fragment.teardown()}},b}(ac),Cc=function(a,b,c,d){function e(e,f,g,h){var i,j,k,l,m;return k=e.root,l=e.parentFragment,"string"==typeof g?(j=b(g),j?j.value:g):null===g?!0:1===g.length&&g[0].t===a.INTERPOLATOR&&g[0].r?l.indexRefs&&void 0!==l.indexRefs[g[0].r]?l.indexRefs[g[0].r]:(m=c(k,g[0].r,l.contextStack)||g[0].r,h.push({childKeypath:f,parentKeypath:m}),k.get(m)):(i=new d(e,f,g),e.complexParameters.push(i),i.value)}return function(a,b,c){var d,f,g;d={},a.complexParameters=[];for(f in b)b.hasOwnProperty(f)&&(g=e(a,f,b[f],c),void 0!==g&&(d[f]=g));return d}}(k,Xb,y,Bc),Dc=function(){return function(a,b,c,d,e){var f,g,h,i;return g=a.parentFragment,i=a.root,h={content:e||[]},f=new b({el:g.pNode.cloneNode(!1),data:c,partials:h,_parent:i,adaptors:i.adaptors}),f.component=a,a.instance=f,f.insert(d),f.fragment.pNode=g.pNode,f}}(),Ec=function(){function a(a,c,d){var e,f,g,h,i,j,k;e=a.root,f=a.instance,i=a.observers,j=e.observe(c,function(a){g||e._wrapped[c]||(h=!0,f.set(d,a),h=!1)},b),i.push(j),f.twoway&&(j=f.observe(d,function(a){h||(g=!0,e.set(c,a),g=!1)},b),i.push(j),k=f.get(d),void 0!==k&&e.set(c,k))}var b={init:!1,debug:!0};return function(b,c){var d,e;for(b.observers=[],e=c.length;e--;)d=c[e],a(b,d.parentKeypath,d.childKeypath)}}(),Fc=function(a){function b(b,d,e,f){if("string"!=typeof f){if(d.debug)throw new Error(c);return a(c),void 0}b.on(e,function(){var a=Array.prototype.slice.call(arguments);a.unshift(f),d.fire.apply(d,a)})}var c="Components currently only support simple events - you cannot include arguments. Sorry!";return function(a,c){var d;for(d in c)c.hasOwnProperty(d)&&b(a.instance,a.root,d,c[d])}}(I),Gc=function(){return function(a){var b,c;for(b=a.root;b;)(c=b._liveComponentQueries[a.name])&&c.push(a.instance),b=b._parent}}(),Hc=function(a,b,c,d,e,f,g){return function(h,i,j){var k,l,m,n,o;if(k=h.parentFragment=i.parentFragment,l=k.root,h.root=l,h.type=a.COMPONENT,h.name=i.descriptor.e,h.index=i.index,h.observers=[],m=l.components[i.descriptor.e],!m)throw new Error('Component "'+i.descriptor.e+'" not found');o=[],n=c(h,i.descriptor.a,o),d(h,m,n,j,i.descriptor.f),e(h,o),f(h,i.descriptor.v),(i.descriptor.t1||i.descriptor.t2||i.descriptor.o)&&b('The "intro", "outro" and "decorator" directives have no effect on components'),g(h)}}(k,I,Cc,Dc,Ec,Fc,Gc),Ic=function(a){var b=function(b,c){a(this,b,c)};return b.prototype={firstNode:function(){return this.instance.fragment.firstNode()},findNextNode:function(){return this.parentFragment.findNextNode(this)},detach:function(){return this.instance.fragment.detach()},teardown:function(){for(var a;this.complexParameters.length;)this.complexParameters.pop().teardown();for(;this.observers.length;)this.observers.pop().cancel();(a=this.root._liveComponentQueries[this.name])&&a._remove(this),this.instance.teardown()},toString:function(){return this.instance.fragment.toString()},find:function(a){return this.instance.fragment.find(a)},findAll:function(a,b){return this.instance.fragment.findAll(a,b)},findComponent:function(a){return a&&a!==this.name?null:this.instance},findAllComponents:function(a,b){b._test(this,!0),this.instance.fragment&&this.instance.fragment.findAllComponents(a,b)}},b}(Hc),Jc=function(a){var b=function(b,c){this.type=a.COMMENT,this.descriptor=b.descriptor,c&&(this.node=document.createComment(b.descriptor.f),c.appendChild(this.node))};return b.prototype={detach:function(){return this.node.parentNode.removeChild(this.node),this.node},teardown:function(a){a&&this.detach()},firstNode:function(){return this.node},toString:function(){return""}},b}(k),Kc=function(a,b,c,d,e,f,g,h,i,j,k,l,m){var n=function(a){a.pNode&&(this.docFrag=document.createDocumentFragment()),"string"==typeof a.descriptor?(this.html=a.descriptor,this.docFrag&&(this.nodes=d(this.html,a.pNode.tagName,this.docFrag))):c(this,a)};return n.prototype={detach:function(){var a,b;if(this.nodes)for(b=this.nodes.length;b--;)this.docFrag.appendChild(this.nodes[b]);else if(this.items)for(a=this.items.length,b=0;a>b;b+=1)this.docFrag.appendChild(this.items[b].detach());return this.docFrag},createItem:function(b){if("string"==typeof b.descriptor)return new e(b,this.docFrag);switch(b.descriptor.t){case a.INTERPOLATOR:return new f(b,this.docFrag);case a.SECTION:return new g(b,this.docFrag);case a.TRIPLE:return new h(b,this.docFrag);case a.ELEMENT:return this.root.components[b.descriptor.e]?new k(b,this.docFrag):new i(b,this.docFrag);case a.PARTIAL:return new j(b,this.docFrag);case a.COMMENT:return new l(b,this.docFrag);default:throw new Error("Something very strange happened. Please file an issue at https://github.com/RactiveJS/Ractive/issues. Thanks!")}},teardown:function(a){var b;if(this.nodes&&a)for(;b=this.nodes.pop();)b.parentNode.removeChild(b);else if(this.items)for(;this.items.length;)this.items.pop().teardown(a);this.nodes=this.items=this.docFrag=null},firstNode:function(){return this.items&&this.items[0]?this.items[0].firstNode():this.nodes?this.nodes[0]||null:null},findNextNode:function(a){var b=a.index;return this.items[b+1]?this.items[b+1].firstNode():this.owner===this.root?this.owner.component?this.owner.component.findNextNode():null:this.owner.findNextNode(this)},toString:function(){var a,b,c,d;if(this.html)return this.html;if(a="",!this.items)return a;for(c=this.items.length,b=0;c>b;b+=1)d=this.items[b],a+=d.toString();return a},find:function(a){var c,d,e,f,g;if(this.nodes){for(d=this.nodes.length,c=0;d>c;c+=1)if(f=this.nodes[c],1===f.nodeType){if(b(f,a))return f;if(g=f.querySelector(a))return g}return null}if(this.items){for(d=this.items.length,c=0;d>c;c+=1)if(e=this.items[c],e.find&&(g=e.find(a)))return g;return null}},findAll:function(a,c){var d,e,f,g,h,i,j;if(this.nodes){for(e=this.nodes.length,d=0;e>d;d+=1)if(g=this.nodes[d],1===g.nodeType&&(b(g,a)&&c.push(g),h=g.querySelectorAll(a)))for(i=h.length,j=0;i>j;j+=1)c.push(h[j])}else if(this.items)for(e=this.items.length,d=0;e>d;d+=1)f=this.items[d],f.findAll&&f.findAll(a,c);return c},findComponent:function(a){var b,c,d,e;if(this.items){for(b=this.items.length,c=0;b>c;c+=1)if(d=this.items[c],d.findComponent&&(e=d.findComponent(a)))return e;return null}},findAllComponents:function(a,b){var c,d,e;if(this.items)for(d=this.items.length,c=0;d>c;c+=1)e=this.items[c],e.findAllComponents&&e.findAllComponents(a,b);return b}},m.DomFragment=n,n}(k,Z,kb,lb,mb,zb,Fb,Gb,wc,Ac,Ic,Jc,Eb),Lc=function(a,b,c,d,e){return function(a,f){var g;if(!this._initing)throw new Error("You cannot call ractive.render() directly!");this._transitionManager=g=b(this,f),this.fragment=new e({descriptor:this.template,root:this,owner:this,pNode:a}),c(this),a&&a.appendChild(this.fragment.docFrag),d(this),this._transitionManager=null,g.ready(),this.rendered=!0}}(jb,q,o,p,Kc),Mc=function(a){return function(){return a("renderHTML() has been deprecated and will be removed in a future version. Please use toHTML() instead"),this.toHTML()}}(I),Nc=function(){return function(){return this.fragment.toString()}}(),Oc=function(a,b){return function(c){var d,e,f;for(this.fire("teardown"),f=this._transitionManager,this._transitionManager=e=a(this,c),this.fragment.teardown(!0);this._animations[0];)this._animations[0].stop();for(d in this._cache)b(this,d);this._transitionManager=f,e.ready()}}(q,m),Pc=function(a){return function(b,c,d){var e;if("string"==typeof c&&a(d)){if(e=b.get(c),void 0===e&&(e=0),a(e))b.set(c,e+d);else if(b.debug)throw new Error("Cannot add to a non-numeric value")}else if(b.debug)throw new Error("Bad arguments")}}(J),Qc=function(a){return function(b,c){a(this,b,void 0===c?1:c)}}(Pc),Rc=function(a){return function(b,c){a(this,b,void 0===c?-1:-c)}}(Pc),Sc=function(){return function(a){var b;if("string"==typeof a)b=this.get(a),this.set(a,!b);else if(this.debug)throw new Error("Bad arguments")}}(),Tc=function(){return function(a,b){var c,d,e,f,g;return c={},e=0,d=function(a,d){var f,h,i;h=e,i=b.length;do{if(f=b.indexOf(a,h),-1===f)return g=!0,-1;h=f+1}while(c[f]&&i>h);return f===e&&(e+=1),f!==d&&(g=!0),c[f]=!0,f},f=a.map(d),f.unchanged=!g,f}}(),Uc=function(a){return function(b,c,d,e){var f,g;for(f=c.length;f--;)g=c[f],g.type===a.REFERENCE?g.update():g.keypath===b&&g.type===a.SECTION&&!g.inverted&&g.docFrag?d[d.length]=g:e[e.length]=g}}(k),Vc=function(a,b,c,d,e,f,g,h,i,j){function k(a){return JSON.stringify(a)}function l(a){return m[a]||(m[a]=function(b){return b[a]}),m[a]}var m={};return function(m,n,o){var p,q,r,s,t,u,v,w,x,y,z,A,B,C,D;if(p=this.get(m),!b(p)||!b(n))return this.set(m,n,o&&o.complete);if(t=p.length===n.length,o&&o.compare){if(o.compare===!0)s=k;else if("string"==typeof o.compare)s=l(o.compare);else{if("function"!=typeof o.compare)throw new Error("The `compare` option must be a function, or a string representing an identifying field (or `true` to use JSON.stringify)");s=o.compare}try{q=p.map(s),r=n.map(s)}catch(E){if(this.debug)throw E;a("Merge operation: comparison failed. Falling back to identity checking"),q=p,r=n}}else q=p,r=n;if(v=i(q,r),c(this,m),h(this,m,n),!v.unchanged||!t){for(B=this._transitionManager,this._transitionManager=A=f(this,o&&o.complete),w=[],x=[],u=0;u 2 && args[1]) { - changed = Math.min(args[1], args.length - 2); - start = args[0]; - end = start + changed; - if (args[1] === args.length - 2) { - lengthUnchanged = true; - } - for (i = start; i < end; i += 1) { - childKeypath = keypath + '.' + i; - notifyDependants(root, childKeypath); - } - } - preDomUpdate(root); - upstreamQueue = []; - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - upstreamQueue[upstreamQueue.length] = keys.join('.'); - } - notifyDependants.multiple(root, upstreamQueue, true); - if (!lengthUnchanged) { - notifyDependants(root, keypath + '.length', true); - } - }; - queueDependants = function (keypath, deps, smartUpdateQueue, dumbUpdateQueue) { - var k, dependant; - k = deps.length; - while (k--) { - dependant = deps[k]; - if (dependant.type === types.REFERENCE) { - dependant.update(); - } else if (dependant.keypath === keypath && dependant.type === types.SECTION && !dependant.inverted && dependant.docFrag) { - smartUpdateQueue[smartUpdateQueue.length] = dependant; - } else { - dumbUpdateQueue[dumbUpdateQueue.length] = dependant; - } - } - }; - wrappers = array._ractive.wrappers; - i = wrappers.length; - while (i--) { - wrapper = wrappers[i]; - notifyKeypathDependants(wrapper.root, wrapper.keypath); - } - }; - patchedArrayProto = []; - mutatorMethods = [ - 'pop', - 'push', - 'reverse', - 'shift', - 'sort', - 'splice', - 'unshift' - ]; - noop = function () { - }; - mutatorMethods.forEach(function (methodName) { - var method = function () { - var result, instances, instance, i, previousTransitionManagers = {}, transitionManagers = {}; - result = Array.prototype[methodName].apply(this, arguments); - instances = this._ractive.instances; - i = instances.length; - while (i--) { - instance = instances[i]; - previousTransitionManagers[instance._guid] = instance._transitionManager; - instance._transitionManager = transitionManagers[instance._guid] = makeTransitionManager(instance, noop); - } - this._ractive.setting = true; - notifyArrayDependants(this, methodName, arguments); - this._ractive.setting = false; - i = instances.length; - while (i--) { - instance = instances[i]; - instance._transitionManager = previousTransitionManagers[instance._guid]; - transitionManagers[instance._guid].ready(); - preDomUpdate(instance); - postDomUpdate(instance); - } - return result; - }; - defineProperty(patchedArrayProto, methodName, { value: method }); - }); - testObj = {}; - if (testObj.__proto__) { - patchArrayMethods = function (array) { - array.__proto__ = patchedArrayProto; - }; - unpatchArrayMethods = function (array) { - array.__proto__ = Array.prototype; - }; - } else { - patchArrayMethods = function (array) { - var i, methodName; - i = mutatorMethods.length; - while (i--) { - methodName = mutatorMethods[i]; - defineProperty(array, methodName, { - value: patchedArrayProto[methodName], - configurable: true - }); - } - }; - unpatchArrayMethods = function (array) { - var i; - i = mutatorMethods.length; - while (i--) { - delete array[mutatorMethods[i]]; - } - }; - } - errorMessage = 'Something went wrong in a rather interesting way'; - return arrayAdaptor; - }(config_types, utils_defineProperty, utils_isArray, shared_clearCache, shared_preDomUpdate, shared_postDomUpdate, shared_makeTransitionManager, shared_notifyDependants); -var Ractive_prototype_get_magicAdaptor = function () { - - var magicAdaptor, MagicWrapper; - try { - Object.defineProperty({}, 'test', { value: 0 }); - } catch (err) { - return false; - } - magicAdaptor = { - filter: function (object, keypath) { - return !!keypath; - }, - wrap: function (ractive, object, keypath) { - return new MagicWrapper(ractive, object, keypath); - } - }; - MagicWrapper = function (ractive, object, keypath) { - var wrapper = this, keys, prop, objKeypath, descriptor, wrappers, oldGet, oldSet, get, set; - this.ractive = ractive; - this.keypath = keypath; - keys = keypath.split('.'); - this.prop = keys.pop(); - objKeypath = keys.join('.'); - this.obj = objKeypath ? ractive.get(objKeypath) : ractive.data; - descriptor = this.originalDescriptor = Object.getOwnPropertyDescriptor(this.obj, this.prop); - if (descriptor && descriptor.set && (wrappers = descriptor.set._ractiveWrappers)) { - if (wrappers.indexOf(this) === -1) { - wrappers.push(this); - } - return; - } - if (descriptor && !descriptor.configurable) { - throw new Error('Cannot use magic mode with property "' + prop + '" - object is not configurable'); - } - if (descriptor) { - this.value = descriptor.value; - oldGet = descriptor.get; - oldSet = descriptor.set; - } - get = oldGet || function () { - return wrapper.value; - }; - set = function (value) { - var wrappers, wrapper, i; - if (oldSet) { - oldSet(value); - } - wrappers = set._ractiveWrappers; - i = wrappers.length; - while (i--) { - wrapper = wrappers[i]; - if (!wrapper.resetting) { - wrapper.ractive.set(wrapper.keypath, value); - } - } - }; - set._ractiveWrappers = [this]; - Object.defineProperty(this.obj, this.prop, { - get: get, - set: set, - enumerable: true, - configurable: true - }); - }; - MagicWrapper.prototype = { - get: function () { - return this.value; - }, - reset: function (value) { - this.resetting = true; - this.value = value; - this.resetting = false; - }, - teardown: function () { - var descriptor, set, value, wrappers; - descriptor = Object.getOwnPropertyDescriptor(this.obj, this.prop); - set = descriptor.set; - wrappers = set._ractiveWrappers; - wrappers.splice(wrappers.indexOf(this), 1); - if (!wrappers.length) { - value = this.obj[this.prop]; - Object.defineProperty(this.obj, this.prop, this.originalDescriptor || { - writable: true, - enumerable: true, - configrable: true - }); - this.obj[this.prop] = value; - } - } - }; - return magicAdaptor; - }(); -var shared_adaptIfNecessary = function (adaptorRegistry, arrayAdaptor, magicAdaptor) { - - var prefixers = {}; - return function (ractive, keypath, value, isExpressionResult) { - var len, i, adaptor, wrapped; - len = ractive.adaptors.length; - for (i = 0; i < len; i += 1) { - adaptor = ractive.adaptors[i]; - if (typeof adaptor === 'string') { - if (!adaptorRegistry[adaptor]) { - throw new Error('Missing adaptor "' + adaptor + '"'); - } - adaptor = ractive.adaptors[i] = adaptorRegistry[adaptor]; - } - if (adaptor.filter(value, keypath, ractive)) { - wrapped = ractive._wrapped[keypath] = adaptor.wrap(ractive, value, keypath, getPrefixer(keypath)); - wrapped.value = value; - return; - } - } - if (!isExpressionResult) { - if (ractive.magic && magicAdaptor.filter(value, keypath, ractive)) { - ractive._wrapped[keypath] = magicAdaptor.wrap(ractive, value, keypath); - } else if (ractive.modifyArrays && arrayAdaptor.filter(value, keypath, ractive)) { - ractive._wrapped[keypath] = arrayAdaptor.wrap(ractive, value, keypath); - } - } - }; - function prefixKeypath(obj, prefix) { - var prefixed = {}, key; - if (!prefix) { - return obj; - } - prefix += '.'; - for (key in obj) { - if (obj.hasOwnProperty(key)) { - prefixed[prefix + key] = obj[key]; - } - } - return prefixed; - } - function getPrefixer(rootKeypath) { - var rootDot; - if (!prefixers[rootKeypath]) { - rootDot = rootKeypath ? rootKeypath + '.' : ''; - prefixers[rootKeypath] = function (relativeKeypath, value) { - var obj; - if (typeof relativeKeypath === 'string') { - obj = {}; - obj[rootDot + relativeKeypath] = value; - return obj; - } - if (typeof relativeKeypath === 'object') { - return rootDot ? prefixKeypath(relativeKeypath, rootKeypath) : relativeKeypath; - } - }; - } - return prefixers[rootKeypath]; - } - }(registries_adaptors, Ractive_prototype_get_arrayAdaptor, Ractive_prototype_get_magicAdaptor); -var Ractive_prototype_get__get = function (normaliseKeypath, adaptorRegistry, adaptIfNecessary) { - - var get, _get, retrieve; - get = function (keypath) { - if (this._captured && !this._captured[keypath]) { - this._captured.push(keypath); - this._captured[keypath] = true; - } - return _get(this, keypath); - }; - _get = function (ractive, keypath) { - var cache, cached, value, wrapped, evaluator; - keypath = normaliseKeypath(keypath); - cache = ractive._cache; - if ((cached = cache[keypath]) !== undefined) { - return cached; - } - if (wrapped = ractive._wrapped[keypath]) { - value = wrapped.value; - } else if (!keypath) { - adaptIfNecessary(ractive, '', ractive.data); - value = ractive.data; - } else if (evaluator = ractive._evaluators[keypath]) { - value = evaluator.value; - } else { - value = retrieve(ractive, keypath); - } - cache[keypath] = value; - return value; - }; - retrieve = function (ractive, keypath) { - var keys, key, parentKeypath, parentValue, cacheMap, value, wrapped; - keys = keypath.split('.'); - key = keys.pop(); - parentKeypath = keys.join('.'); - parentValue = _get(ractive, parentKeypath); - if (wrapped = ractive._wrapped[parentKeypath]) { - parentValue = wrapped.get(); - } - if (parentValue === null || parentValue === undefined) { - return; - } - if (!(cacheMap = ractive._cacheMap[parentKeypath])) { - ractive._cacheMap[parentKeypath] = [keypath]; - } else { - if (cacheMap.indexOf(keypath) === -1) { - cacheMap[cacheMap.length] = keypath; - } - } - value = parentValue[key]; - adaptIfNecessary(ractive, keypath, value); - ractive._cache[keypath] = value; - return value; - }; - return get; - }(utils_normaliseKeypath, registries_adaptors, shared_adaptIfNecessary); -var utils_isObject = function () { - - var toString = Object.prototype.toString; - return function (thing) { - return typeof thing === 'object' && toString.call(thing) === '[object Object]'; - }; - }(); -var utils_isEqual = function () { - - return function (a, b) { - if (a === null && b === null) { - return true; - } - if (typeof a === 'object' || typeof b === 'object') { - return false; - } - return a === b; - }; - }(); -var shared_resolveRef = function () { - - var resolveRef; - resolveRef = function (ractive, ref, contextStack) { - var keypath, keys, lastKey, contextKeys, innerMostContext, postfix, parentKeypath, parentValue, wrapped, context, ancestorErrorMessage; - ancestorErrorMessage = 'Could not resolve reference - too many "../" prefixes'; - if (ref === '.') { - if (!contextStack.length) { - return ''; - } - keypath = contextStack[contextStack.length - 1]; - } else if (ref.charAt(0) === '.') { - context = contextStack[contextStack.length - 1]; - contextKeys = context ? context.split('.') : []; - if (ref.substr(0, 3) === '../') { - while (ref.substr(0, 3) === '../') { - if (!contextKeys.length) { - throw new Error(ancestorErrorMessage); - } - contextKeys.pop(); - ref = ref.substring(3); - } - contextKeys.push(ref); - keypath = contextKeys.join('.'); - } else if (!context) { - keypath = ref.substring(1); - } else { - keypath = context + ref; - } - } else { - keys = ref.split('.'); - lastKey = keys.pop(); - postfix = keys.length ? '.' + keys.join('.') : ''; - contextStack = contextStack.concat(); - while (contextStack.length) { - innerMostContext = contextStack.pop(); - parentKeypath = innerMostContext + postfix; - parentValue = ractive.get(parentKeypath); - if (wrapped = ractive._wrapped[parentKeypath]) { - parentValue = wrapped.get(); - } - if (typeof parentValue === 'object' && parentValue !== null && parentValue.hasOwnProperty(lastKey)) { - keypath = innerMostContext + '.' + ref; - break; - } - } - if (!keypath && ractive.get(ref) !== undefined) { - keypath = ref; - } - } - return keypath ? keypath.replace(/^\./, '') : keypath; - }; - return resolveRef; - }(); -var shared_attemptKeypathResolution = function (resolveRef) { - - var push = Array.prototype.push; - return function (ractive) { - var unresolved, keypath, leftover; - while (unresolved = ractive._pendingResolution.pop()) { - keypath = resolveRef(ractive, unresolved.ref, unresolved.contextStack); - if (keypath !== undefined) { - unresolved.resolve(keypath); - } else { - (leftover || (leftover = [])).push(unresolved); - } - } - if (leftover) { - push.apply(ractive._pendingResolution, leftover); - } - }; - }(shared_resolveRef); -var shared_processDeferredUpdates = function (preDomUpdate, postDomUpdate) { - - return function (ractive) { - preDomUpdate(ractive); - postDomUpdate(ractive); - }; - }(shared_preDomUpdate, shared_postDomUpdate); -var Ractive_prototype_shared_replaceData = function () { - - return function (ractive, keypath, value) { - var keys, accumulated, wrapped, obj, key, currentKeypath, keypathToClear; - keys = keypath.split('.'); - accumulated = []; - if (wrapped = ractive._wrapped['']) { - if (wrapped.set) { - wrapped.set(keys.join('.'), value); - } - obj = wrapped.get(); - } else { - obj = ractive.data; - } - while (keys.length > 1) { - key = accumulated[accumulated.length] = keys.shift(); - currentKeypath = accumulated.join('.'); - if (wrapped = ractive._wrapped[currentKeypath]) { - if (wrapped.set) { - wrapped.set(keys.join('.'), value); - } - obj = wrapped.get(); - } else { - if (!obj.hasOwnProperty(key)) { - if (!keypathToClear) { - keypathToClear = currentKeypath; - } - obj[key] = /^\s*[0-9]+\s*$/.test(keys[0]) ? [] : {}; - } - obj = obj[key]; - } - } - key = keys[0]; - obj[key] = value; - return keypathToClear; - }; - }(); -var Ractive_prototype_set = function (isObject, isEqual, normaliseKeypath, clearCache, notifyDependants, attemptKeypathResolution, makeTransitionManager, processDeferredUpdates, replaceData) { - - var set, updateModel, getUpstreamChanges, resetWrapped; - set = function (keypath, value, complete) { - var map, changes, upstreamChanges, previousTransitionManager, transitionManager, i, changeHash; - changes = []; - if (isObject(keypath)) { - map = keypath; - complete = value; - } - if (map) { - for (keypath in map) { - if (map.hasOwnProperty(keypath)) { - value = map[keypath]; - keypath = normaliseKeypath(keypath); - updateModel(this, keypath, value, changes); - } - } - } else { - keypath = normaliseKeypath(keypath); - updateModel(this, keypath, value, changes); - } - if (!changes.length) { - return; - } - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - upstreamChanges = getUpstreamChanges(changes); - if (upstreamChanges.length) { - notifyDependants.multiple(this, upstreamChanges, true); - } - notifyDependants.multiple(this, changes); - if (this._pendingResolution.length) { - attemptKeypathResolution(this); - } - processDeferredUpdates(this); - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - if (!this.firingChangeEvent) { - this.firingChangeEvent = true; - changeHash = {}; - i = changes.length; - while (i--) { - changeHash[changes[i]] = this.get(changes[i]); - } - this.fire('change', changeHash); - this.firingChangeEvent = false; - } - return this; - }; - updateModel = function (ractive, keypath, value, changes) { - var cached, previous, wrapped, keypathToClear, evaluator; - if ((wrapped = ractive._wrapped[keypath]) && wrapped.reset) { - if (resetWrapped(ractive, keypath, value, wrapped, changes) !== false) { - return; - } - } - if (evaluator = ractive._evaluators[keypath]) { - evaluator.value = value; - } - cached = ractive._cache[keypath]; - previous = ractive.get(keypath); - if (previous !== value && !evaluator) { - keypathToClear = replaceData(ractive, keypath, value); - } else { - if (value === cached && typeof value !== 'object') { - return; - } - } - clearCache(ractive, keypathToClear || keypath); - changes[changes.length] = keypath; - }; - getUpstreamChanges = function (changes) { - var upstreamChanges = [''], i, keypath, keys, upstreamKeypath; - i = changes.length; - while (i--) { - keypath = changes[i]; - keys = keypath.split('.'); - while (keys.length > 1) { - keys.pop(); - upstreamKeypath = keys.join('.'); - if (!upstreamChanges[upstreamKeypath]) { - upstreamChanges[upstreamChanges.length] = upstreamKeypath; - upstreamChanges[upstreamKeypath] = true; - } - } - } - return upstreamChanges; - }; - resetWrapped = function (ractive, keypath, value, wrapped, changes) { - var previous, cached, cacheMap, i; - previous = wrapped.get(); - if (!isEqual(previous, value)) { - if (wrapped.reset(value) === false) { - return false; - } - } - value = wrapped.get(); - cached = ractive._cache[keypath]; - if (!isEqual(cached, value)) { - ractive._cache[keypath] = value; - cacheMap = ractive._cacheMap[keypath]; - if (cacheMap) { - i = cacheMap.length; - while (i--) { - clearCache(ractive, cacheMap[i]); - } - } - changes[changes.length] = keypath; - } - }; - return set; - }(utils_isObject, utils_isEqual, utils_normaliseKeypath, shared_clearCache, shared_notifyDependants, shared_attemptKeypathResolution, shared_makeTransitionManager, shared_processDeferredUpdates, Ractive_prototype_shared_replaceData); -var Ractive_prototype_update = function (makeTransitionManager, attemptKeypathResolution, clearCache, notifyDependants, processDeferredUpdates) { - - return function (keypath, complete) { - var transitionManager, previousTransitionManager; - if (typeof keypath === 'function') { - complete = keypath; - keypath = ''; - } - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - attemptKeypathResolution(this); - clearCache(this, keypath || ''); - notifyDependants(this, keypath || ''); - processDeferredUpdates(this); - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - if (typeof keypath === 'string') { - this.fire('update', keypath); - } else { - this.fire('update'); - } - return this; - }; - }(shared_makeTransitionManager, shared_attemptKeypathResolution, shared_clearCache, shared_notifyDependants, shared_processDeferredUpdates); -var utils_arrayContentsMatch = function (isArray) { - - return function (a, b) { - var i; - if (!isArray(a) || !isArray(b)) { - return false; - } - if (a.length !== b.length) { - return false; - } - i = a.length; - while (i--) { - if (a[i] !== b[i]) { - return false; - } - } - return true; - }; - }(utils_isArray); -var Ractive_prototype_updateModel = function (getValueFromCheckboxes, arrayContentsMatch, isEqual) { - - return function (keypath, cascade) { - var values, deferredCheckboxes, i; - if (typeof keypath !== 'string') { - keypath = ''; - cascade = true; - } - consolidateChangedValues(this, keypath, values = {}, deferredCheckboxes = [], cascade); - if (i = deferredCheckboxes.length) { - while (i--) { - keypath = deferredCheckboxes[i]; - values[keypath] = getValueFromCheckboxes(this, keypath); - } - } - this.set(values); - }; - function consolidateChangedValues(ractive, keypath, values, deferredCheckboxes, cascade) { - var bindings, childDeps, i, binding, oldValue, newValue; - bindings = ractive._twowayBindings[keypath]; - if (bindings) { - i = bindings.length; - while (i--) { - binding = bindings[i]; - if (binding.radioName && !binding.node.checked) { - continue; - } - if (binding.checkboxName) { - if (binding.changed() && !deferredCheckboxes[keypath]) { - deferredCheckboxes[keypath] = true; - deferredCheckboxes[deferredCheckboxes.length] = keypath; - } - continue; - } - oldValue = binding.attr.value; - newValue = binding.value(); - if (arrayContentsMatch(oldValue, newValue)) { - continue; - } - if (!isEqual(oldValue, newValue)) { - values[keypath] = newValue; - } - } - } - if (!cascade) { - return; - } - childDeps = ractive._depsMap[keypath]; - if (childDeps) { - i = childDeps.length; - while (i--) { - consolidateChangedValues(ractive, childDeps[i], values, deferredCheckboxes, cascade); - } - } - } - }(shared_getValueFromCheckboxes, utils_arrayContentsMatch, utils_isEqual); -var Ractive_prototype_animate_requestAnimationFrame = function () { - - if (typeof window === 'undefined') { - return; - } - (function (vendors, lastTime, window) { - var x, setTimeout; - if (window.requestAnimationFrame) { - return; - } - for (x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { - window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']; - } - if (!window.requestAnimationFrame) { - setTimeout = window.setTimeout; - window.requestAnimationFrame = function (callback) { - var currTime, timeToCall, id; - currTime = Date.now(); - timeToCall = Math.max(0, 16 - (currTime - lastTime)); - id = setTimeout(function () { - callback(currTime + timeToCall); - }, timeToCall); - lastTime = currTime + timeToCall; - return id; - }; - } - }([ - 'ms', - 'moz', - 'webkit', - 'o' - ], 0, window)); - return window.requestAnimationFrame; - }(); -var Ractive_prototype_animate_animations = function (rAF) { - - var queue = []; - var animations = { - tick: function () { - var i, animation; - for (i = 0; i < queue.length; i += 1) { - animation = queue[i]; - if (!animation.tick()) { - queue.splice(i--, 1); - } - } - if (queue.length) { - rAF(animations.tick); - } else { - animations.running = false; - } - }, - add: function (animation) { - queue[queue.length] = animation; - if (!animations.running) { - animations.running = true; - animations.tick(); - } - }, - abort: function (keypath, root) { - var i = queue.length, animation; - while (i--) { - animation = queue[i]; - if (animation.root === root && animation.keypath === keypath) { - animation.stop(); - } - } - } - }; - return animations; - }(Ractive_prototype_animate_requestAnimationFrame); -var utils_warn = function () { - - if (typeof console !== 'undefined' && typeof console.warn === 'function' && typeof console.warn.apply === 'function') { - return function () { - console.warn.apply(console, arguments); - }; - } - return function () { - }; - }(); -var utils_isNumeric = function () { - - return function (thing) { - return !isNaN(parseFloat(thing)) && isFinite(thing); - }; - }(); -var shared_interpolate = function (isArray, isObject, isNumeric) { - - var interpolate = function (from, to) { - if (isNumeric(from) && isNumeric(to)) { - return makeNumberInterpolator(+from, +to); - } - if (isArray(from) && isArray(to)) { - return makeArrayInterpolator(from, to); - } - if (isObject(from) && isObject(to)) { - return makeObjectInterpolator(from, to); - } - return function () { - return to; - }; - }; - return interpolate; - function makeNumberInterpolator(from, to) { - var delta = to - from; - if (!delta) { - return function () { - return from; - }; - } - return function (t) { - return from + t * delta; - }; - } - function makeArrayInterpolator(from, to) { - var intermediate, interpolators, len, i; - intermediate = []; - interpolators = []; - i = len = Math.min(from.length, to.length); - while (i--) { - interpolators[i] = interpolate(from[i], to[i]); - } - for (i = len; i < from.length; i += 1) { - intermediate[i] = from[i]; - } - for (i = len; i < to.length; i += 1) { - intermediate[i] = to[i]; - } - return function (t) { - var i = len; - while (i--) { - intermediate[i] = interpolators[i](t); - } - return intermediate; - }; - } - function makeObjectInterpolator(from, to) { - var properties = [], len, interpolators, intermediate, prop; - intermediate = {}; - interpolators = {}; - for (prop in from) { - if (from.hasOwnProperty(prop)) { - if (to.hasOwnProperty(prop)) { - properties[properties.length] = prop; - interpolators[prop] = interpolate(from[prop], to[prop]); - } else { - intermediate[prop] = from[prop]; - } - } - } - for (prop in to) { - if (to.hasOwnProperty(prop) && !from.hasOwnProperty(prop)) { - intermediate[prop] = to[prop]; - } - } - len = properties.length; - return function (t) { - var i = len, prop; - while (i--) { - prop = properties[i]; - intermediate[prop] = interpolators[prop](t); - } - return intermediate; - }; - } - }(utils_isArray, utils_isObject, utils_isNumeric); -var Ractive_prototype_animate_Animation = function (warn, interpolate) { - - var Animation = function (options) { - var key; - this.startTime = Date.now(); - for (key in options) { - if (options.hasOwnProperty(key)) { - this[key] = options[key]; - } - } - this.interpolator = interpolate(this.from, this.to); - this.running = true; - }; - Animation.prototype = { - tick: function () { - var elapsed, t, value, timeNow, index, keypath; - keypath = this.keypath; - if (this.running) { - timeNow = Date.now(); - elapsed = timeNow - this.startTime; - if (elapsed >= this.duration) { - if (keypath !== null) { - this.root.set(keypath, this.to); - } - if (this.step) { - this.step(1, this.to); - } - if (this.complete) { - this.complete(1, this.to); - } - index = this.root._animations.indexOf(this); - if (index === -1) { - warn('Animation was not found'); - } - this.root._animations.splice(index, 1); - this.running = false; - return false; - } - t = this.easing ? this.easing(elapsed / this.duration) : elapsed / this.duration; - if (keypath !== null) { - value = this.interpolator(t); - this.root.set(keypath, value); - } - if (this.step) { - this.step(t, value); - } - return true; - } - return false; - }, - stop: function () { - var index; - this.running = false; - index = this.root._animations.indexOf(this); - if (index === -1) { - warn('Animation was not found'); - } - this.root._animations.splice(index, 1); - } - }; - return Animation; - }(utils_warn, shared_interpolate); -var registries_easing = function () { - - return { - linear: function (pos) { - return pos; - }, - easeIn: function (pos) { - return Math.pow(pos, 3); - }, - easeOut: function (pos) { - return Math.pow(pos - 1, 3) + 1; - }, - easeInOut: function (pos) { - if ((pos /= 0.5) < 1) { - return 0.5 * Math.pow(pos, 3); - } - return 0.5 * (Math.pow(pos - 2, 3) + 2); - } - }; - }(); -var Ractive_prototype_animate__animate = function (isEqual, animations, Animation, easingRegistry) { - - var noAnimation = { - stop: function () { - } - }; - return function (keypath, to, options) { - var k, animation, animations, easing, duration, step, complete, makeValueCollector, currentValues, collectValue, dummy, dummyOptions; - if (typeof keypath === 'object') { - options = to || {}; - easing = options.easing; - duration = options.duration; - animations = []; - step = options.step; - complete = options.complete; - if (step || complete) { - currentValues = {}; - options.step = null; - options.complete = null; - makeValueCollector = function (keypath) { - return function (t, value) { - currentValues[keypath] = value; - }; - }; - } - for (k in keypath) { - if (keypath.hasOwnProperty(k)) { - if (step || complete) { - collectValue = makeValueCollector(k); - options = { - easing: easing, - duration: duration - }; - if (step) { - options.step = collectValue; - } - if (complete) { - options.complete = collectValue; - } - } - animations[animations.length] = animate(this, k, keypath[k], options); - } - } - if (step || complete) { - dummyOptions = { - easing: easing, - duration: duration - }; - if (step) { - dummyOptions.step = function (t) { - step(t, currentValues); - }; - } - if (complete) { - dummyOptions.complete = function (t) { - complete(t, currentValues); - }; - } - animations[animations.length] = dummy = animate(this, null, null, dummyOptions); - } - return { - stop: function () { - while (animations.length) { - animations.pop().stop(); - } - if (dummy) { - dummy.stop(); - } - } - }; - } - options = options || {}; - animation = animate(this, keypath, to, options); - return { - stop: function () { - animation.stop(); - } - }; - }; - function animate(root, keypath, to, options) { - var easing, duration, animation, from; - if (keypath !== null) { - from = root.get(keypath); - } - animations.abort(keypath, root); - if (isEqual(from, to)) { - if (options.complete) { - options.complete(1, options.to); - } - return noAnimation; - } - if (options.easing) { - if (typeof options.easing === 'function') { - easing = options.easing; - } else { - if (root.easing && root.easing[options.easing]) { - easing = root.easing[options.easing]; - } else { - easing = easingRegistry[options.easing]; - } - } - if (typeof easing !== 'function') { - easing = null; - } - } - duration = options.duration === undefined ? 400 : options.duration; - animation = new Animation({ - keypath: keypath, - from: from, - to: to, - root: root, - duration: duration, - easing: easing, - step: options.step, - complete: options.complete - }); - animations.add(animation); - root._animations[root._animations.length] = animation; - return animation; - } - }(utils_isEqual, Ractive_prototype_animate_animations, Ractive_prototype_animate_Animation, registries_easing); -var Ractive_prototype_on = function () { - - return function (eventName, callback) { - var self = this, listeners, n; - if (typeof eventName === 'object') { - listeners = []; - for (n in eventName) { - if (eventName.hasOwnProperty(n)) { - listeners[listeners.length] = this.on(n, eventName[n]); - } - } - return { - cancel: function () { - while (listeners.length) { - listeners.pop().cancel(); - } - } - }; - } - if (!this._subs[eventName]) { - this._subs[eventName] = [callback]; - } else { - this._subs[eventName].push(callback); - } - return { - cancel: function () { - self.off(eventName, callback); - } - }; - }; - }(); -var Ractive_prototype_off = function () { - - return function (eventName, callback) { - var subscribers, index; - if (!callback) { - if (!eventName) { - for (eventName in this._subs) { - delete this._subs[eventName]; - } - } else { - this._subs[eventName] = []; - } - } - subscribers = this._subs[eventName]; - if (subscribers) { - index = subscribers.indexOf(callback); - if (index !== -1) { - subscribers.splice(index, 1); - } - } - }; - }(); -var shared_registerDependant = function () { - - return function (dependant) { - var depsByKeypath, deps, keys, parentKeypath, map, ractive, keypath, priority; - ractive = dependant.root; - keypath = dependant.keypath; - priority = dependant.priority; - depsByKeypath = ractive._deps[priority] || (ractive._deps[priority] = {}); - deps = depsByKeypath[keypath] || (depsByKeypath[keypath] = []); - deps[deps.length] = dependant; - dependant.registered = true; - if (!keypath) { - return; - } - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - parentKeypath = keys.join('.'); - map = ractive._depsMap[parentKeypath] || (ractive._depsMap[parentKeypath] = []); - if (map[keypath] === undefined) { - map[keypath] = 0; - map[map.length] = keypath; - } - map[keypath] += 1; - keypath = parentKeypath; - } - }; - }(); -var shared_unregisterDependant = function () { - - return function (dependant) { - var deps, index, keys, parentKeypath, map, ractive, keypath, priority; - ractive = dependant.root; - keypath = dependant.keypath; - priority = dependant.priority; - deps = ractive._deps[priority][keypath]; - index = deps.indexOf(dependant); - if (index === -1 || !dependant.registered) { - throw new Error('Attempted to remove a dependant that was no longer registered! This should not happen. If you are seeing this bug in development please raise an issue at https://github.com/RactiveJS/Ractive/issues - thanks'); - } - deps.splice(index, 1); - dependant.registered = false; - if (!keypath) { - return; - } - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - parentKeypath = keys.join('.'); - map = ractive._depsMap[parentKeypath]; - map[keypath] -= 1; - if (!map[keypath]) { - map.splice(map.indexOf(keypath), 1); - map[keypath] = undefined; - } - keypath = parentKeypath; - } - }; - }(); -var Ractive_prototype_observe_Observer = function (isEqual) { - - var Observer = function (ractive, keypath, callback, options) { - var self = this; - this.root = ractive; - this.keypath = keypath; - this.callback = callback; - this.defer = options.defer; - this.debug = options.debug; - this.proxy = { - update: function () { - self.reallyUpdate(); - } - }; - this.priority = 0; - this.context = options && options.context ? options.context : ractive; - }; - Observer.prototype = { - init: function (immediate) { - if (immediate !== false) { - this.update(); - } else { - this.value = this.root.get(this.keypath); - } - }, - update: function () { - if (this.defer && this.ready) { - this.root._deferred.observers.push(this.proxy); - return; - } - this.reallyUpdate(); - }, - reallyUpdate: function () { - var oldValue, newValue; - oldValue = this.value; - newValue = this.root.get(this.keypath); - this.value = newValue; - if (this.updating) { - return; - } - this.updating = true; - if (!isEqual(newValue, oldValue) || !this.ready) { - try { - this.callback.call(this.context, newValue, oldValue, this.keypath); - } catch (err) { - if (this.debug || this.root.debug) { - throw err; - } - } - } - this.updating = false; - } - }; - return Observer; - }(utils_isEqual); -var Ractive_prototype_observe_getPattern = function () { - - return function (ractive, pattern) { - var keys, key, values, toGet, newToGet, expand, concatenate; - keys = pattern.split('.'); - toGet = []; - expand = function (keypath) { - var value, key; - value = ractive._wrapped[keypath] ? ractive._wrapped[keypath].get() : ractive.get(keypath); - for (key in value) { - newToGet.push(keypath + '.' + key); - } - }; - concatenate = function (keypath) { - return keypath + '.' + key; - }; - while (key = keys.shift()) { - if (key === '*') { - newToGet = []; - toGet.forEach(expand); - toGet = newToGet; - } else { - if (!toGet[0]) { - toGet[0] = key; - } else { - toGet = toGet.map(concatenate); - } - } - } - values = {}; - toGet.forEach(function (keypath) { - values[keypath] = ractive.get(keypath); - }); - return values; - }; - }(); -var Ractive_prototype_observe_PatternObserver = function (isEqual, getPattern) { - - var PatternObserver, wildcard = /\*/; - PatternObserver = function (ractive, keypath, callback, options) { - this.root = ractive; - this.callback = callback; - this.defer = options.defer; - this.debug = options.debug; - this.keypath = keypath; - this.regex = new RegExp('^' + keypath.replace(/\./g, '\\.').replace(/\*/g, '[^\\.]+') + '$'); - this.values = {}; - if (this.defer) { - this.proxies = []; - } - this.priority = 'pattern'; - this.context = options && options.context ? options.context : ractive; - }; - PatternObserver.prototype = { - init: function (immediate) { - var values, keypath; - values = getPattern(this.root, this.keypath); - if (immediate !== false) { - for (keypath in values) { - if (values.hasOwnProperty(keypath)) { - this.update(keypath); - } - } - } else { - this.values = values; - } - }, - update: function (keypath) { - var values; - if (wildcard.test(keypath)) { - values = getPattern(this.root, keypath); - for (keypath in values) { - if (values.hasOwnProperty(keypath)) { - this.update(keypath); - } - } - return; - } - if (this.defer && this.ready) { - this.root._deferred.observers.push(this.getProxy(keypath)); - return; - } - this.reallyUpdate(keypath); - }, - reallyUpdate: function (keypath) { - var value = this.root.get(keypath); - if (this.updating) { - this.values[keypath] = value; - return; - } - this.updating = true; - if (!isEqual(value, this.values[keypath]) || !this.ready) { - try { - this.callback.call(this.context, value, this.values[keypath], keypath); - } catch (err) { - if (this.debug || this.root.debug) { - throw err; - } - } - this.values[keypath] = value; - } - this.updating = false; - }, - getProxy: function (keypath) { - var self = this; - if (!this.proxies[keypath]) { - this.proxies[keypath] = { - update: function () { - self.reallyUpdate(keypath); - } - }; - } - return this.proxies[keypath]; - } - }; - return PatternObserver; - }(utils_isEqual, Ractive_prototype_observe_getPattern); -var Ractive_prototype_observe_getObserverFacade = function (normaliseKeypath, registerDependant, unregisterDependant, Observer, PatternObserver) { - - var wildcard = /\*/, emptyObject = {}; - return function getObserverFacade(ractive, keypath, callback, options) { - var observer, isPatternObserver; - keypath = normaliseKeypath(keypath); - options = options || emptyObject; - if (wildcard.test(keypath)) { - observer = new PatternObserver(ractive, keypath, callback, options); - ractive._patternObservers.push(observer); - isPatternObserver = true; - } else { - observer = new Observer(ractive, keypath, callback, options); - } - registerDependant(observer); - observer.init(options.init); - observer.ready = true; - return { - cancel: function () { - var index; - if (isPatternObserver) { - index = ractive._patternObservers.indexOf(observer); - if (index !== -1) { - ractive._patternObservers.splice(index, 1); - } - } - unregisterDependant(observer); - } - }; - }; - }(utils_normaliseKeypath, shared_registerDependant, shared_unregisterDependant, Ractive_prototype_observe_Observer, Ractive_prototype_observe_PatternObserver); -var Ractive_prototype_observe__observe = function (isObject, getObserverFacade) { - - return function observe(keypath, callback, options) { - var observers = [], k; - if (isObject(keypath)) { - options = callback; - for (k in keypath) { - if (keypath.hasOwnProperty(k)) { - callback = keypath[k]; - observers[observers.length] = getObserverFacade(this, k, callback, options); - } - } - return { - cancel: function () { - while (observers.length) { - observers.pop().cancel(); - } - } - }; - } - return getObserverFacade(this, keypath, callback, options); - }; - }(utils_isObject, Ractive_prototype_observe_getObserverFacade); -var Ractive_prototype_fire = function () { - - return function (eventName) { - var args, i, len, subscribers = this._subs[eventName]; - if (!subscribers) { - return; - } - args = Array.prototype.slice.call(arguments, 1); - for (i = 0, len = subscribers.length; i < len; i += 1) { - subscribers[i].apply(this, args); - } - }; - }(); -var Ractive_prototype_find = function () { - - return function (selector) { - if (!this.el) { - return null; - } - return this.fragment.find(selector); - }; - }(); -var utils_matches = function (isClient, createElement) { - - var div, methodNames, unprefixed, prefixed, vendors, i, j, makeFunction; - if (!isClient) { - return; - } - div = createElement('div'); - methodNames = [ - 'matches', - 'matchesSelector' - ]; - vendors = [ - 'o', - 'ms', - 'moz', - 'webkit' - ]; - makeFunction = function (methodName) { - return function (node, selector) { - return node[methodName](selector); - }; - }; - i = methodNames.length; - while (i--) { - unprefixed = methodNames[i]; - if (div[unprefixed]) { - return makeFunction(unprefixed); - } - j = vendors.length; - while (j--) { - prefixed = vendors[i] + unprefixed.substr(0, 1).toUpperCase() + unprefixed.substring(1); - if (div[prefixed]) { - return makeFunction(prefixed); - } - } - } - return function (node, selector) { - var nodes, i; - nodes = (node.parentNode || node.document).querySelectorAll(selector); - i = nodes.length; - while (i--) { - if (nodes[i] === node) { - return true; - } - } - return false; - }; - }(config_isClient, utils_createElement); -var Ractive_prototype_shared_makeQuery_test = function (matches) { - - return function (item, noDirty) { - var itemMatches = this._isComponentQuery ? !this.selector || item.name === this.selector : matches(item.node, this.selector); - if (itemMatches) { - this.push(item.node || item.instance); - if (!noDirty) { - this._makeDirty(); - } - return true; - } - }; - }(utils_matches); -var Ractive_prototype_shared_makeQuery_cancel = function () { - - return function () { - var liveQueries, selector, index; - liveQueries = this._root[this._isComponentQuery ? 'liveComponentQueries' : 'liveQueries']; - selector = this.selector; - index = liveQueries.indexOf(selector); - if (index !== -1) { - liveQueries.splice(index, 1); - liveQueries[selector] = null; - } - }; - }(); -var Ractive_prototype_shared_makeQuery_sortByItemPosition = function () { - - return function (a, b) { - var ancestryA, ancestryB, oldestA, oldestB, mutualAncestor, indexA, indexB, fragments, fragmentA, fragmentB; - ancestryA = getAncestry(a.component || a._ractive.proxy); - ancestryB = getAncestry(b.component || b._ractive.proxy); - oldestA = ancestryA[ancestryA.length - 1]; - oldestB = ancestryB[ancestryB.length - 1]; - while (oldestA && oldestA === oldestB) { - ancestryA.pop(); - ancestryB.pop(); - mutualAncestor = oldestA; - oldestA = ancestryA[ancestryA.length - 1]; - oldestB = ancestryB[ancestryB.length - 1]; - } - oldestA = oldestA.component || oldestA; - oldestB = oldestB.component || oldestB; - fragmentA = oldestA.parentFragment; - fragmentB = oldestB.parentFragment; - if (fragmentA === fragmentB) { - indexA = fragmentA.items.indexOf(oldestA); - indexB = fragmentB.items.indexOf(oldestB); - return indexA - indexB || ancestryA.length - ancestryB.length; - } - if (fragments = mutualAncestor.fragments) { - indexA = fragments.indexOf(fragmentA); - indexB = fragments.indexOf(fragmentB); - return indexA - indexB || ancestryA.length - ancestryB.length; - } - throw new Error('An unexpected condition was met while comparing the position of two components. Please file an issue at https://github.com/RactiveJS/Ractive/issues - thanks!'); - }; - function getParent(item) { - var parentFragment; - if (parentFragment = item.parentFragment) { - return parentFragment.owner; - } - if (item.component && (parentFragment = item.component.parentFragment)) { - return parentFragment.owner; - } - } - function getAncestry(item) { - var ancestry, ancestor; - ancestry = [item]; - ancestor = getParent(item); - while (ancestor) { - ancestry.push(ancestor); - ancestor = getParent(ancestor); - } - return ancestry; - } - }(); -var Ractive_prototype_shared_makeQuery_sortByDocumentPosition = function (sortByItemPosition) { - - return function (node, otherNode) { - var bitmask; - if (node.compareDocumentPosition) { - bitmask = node.compareDocumentPosition(otherNode); - return bitmask & 2 ? 1 : -1; - } - return sortByItemPosition(node, otherNode); - }; - }(Ractive_prototype_shared_makeQuery_sortByItemPosition); -var Ractive_prototype_shared_makeQuery_sort = function (sortByDocumentPosition, sortByItemPosition) { - - return function () { - this.sort(this._isComponentQuery ? sortByItemPosition : sortByDocumentPosition); - this._dirty = false; - }; - }(Ractive_prototype_shared_makeQuery_sortByDocumentPosition, Ractive_prototype_shared_makeQuery_sortByItemPosition); -var Ractive_prototype_shared_makeQuery_dirty = function () { - - return function () { - if (!this._dirty) { - this._root._deferred.liveQueries.push(this); - this._dirty = true; - } - }; - }(); -var Ractive_prototype_shared_makeQuery_remove = function () { - - return function (item) { - var index = this.indexOf(this._isComponentQuery ? item.instance : item.node); - if (index !== -1) { - this.splice(index, 1); - } - }; - }(); -var Ractive_prototype_shared_makeQuery__makeQuery = function (defineProperties, test, cancel, sort, dirty, remove) { - - return function (ractive, selector, live, isComponentQuery) { - var query; - query = []; - defineProperties(query, { - selector: { value: selector }, - live: { value: live }, - _isComponentQuery: { value: isComponentQuery }, - _test: { value: test } - }); - if (!live) { - return query; - } - defineProperties(query, { - cancel: { value: cancel }, - _root: { value: ractive }, - _sort: { value: sort }, - _makeDirty: { value: dirty }, - _remove: { value: remove }, - _dirty: { - value: false, - writable: true - } - }); - return query; - }; - }(utils_defineProperties, Ractive_prototype_shared_makeQuery_test, Ractive_prototype_shared_makeQuery_cancel, Ractive_prototype_shared_makeQuery_sort, Ractive_prototype_shared_makeQuery_dirty, Ractive_prototype_shared_makeQuery_remove); -var Ractive_prototype_findAll = function (warn, matches, defineProperties, makeQuery) { - - return function (selector, options) { - var liveQueries, query; - if (!this.el) { - return []; - } - options = options || {}; - liveQueries = this._liveQueries; - if (query = liveQueries[selector]) { - return options && options.live ? query : query.slice(); - } - query = makeQuery(this, selector, !!options.live, false); - if (query.live) { - liveQueries.push(selector); - liveQueries[selector] = query; - } - this.fragment.findAll(selector, query); - return query; - }; - }(utils_warn, utils_matches, utils_defineProperties, Ractive_prototype_shared_makeQuery__makeQuery); -var Ractive_prototype_findComponent = function () { - - return function (selector) { - return this.fragment.findComponent(selector); - }; - }(); -var Ractive_prototype_findAllComponents = function (warn, matches, defineProperties, makeQuery) { - - return function (selector, options) { - var liveQueries, query; - options = options || {}; - liveQueries = this._liveComponentQueries; - if (query = liveQueries[selector]) { - return options && options.live ? query : query.slice(); - } - query = makeQuery(this, selector, !!options.live, true); - if (query.live) { - liveQueries.push(selector); - liveQueries[selector] = query; - } - this.fragment.findAllComponents(selector, query); - return query; - }; - }(utils_warn, utils_matches, utils_defineProperties, Ractive_prototype_shared_makeQuery__makeQuery); -var utils_getElement = function () { - - return function (input) { - var output; - if (typeof window === 'undefined' || !document || !input) { - return null; - } - if (input.nodeType) { - return input; - } - if (typeof input === 'string') { - output = document.getElementById(input); - if (!output && document.querySelector) { - output = document.querySelector(input); - } - if (output && output.nodeType) { - return output; - } - } - if (input[0] && input[0].nodeType) { - return input[0]; - } - return null; - }; - }(); -var render_shared_initFragment = function (types, create) { - - return function (fragment, options) { - var numItems, i, parentFragment, parentRefs, ref; - fragment.owner = options.owner; - parentFragment = fragment.owner.parentFragment; - fragment.root = options.root; - fragment.pNode = options.pNode; - fragment.contextStack = options.contextStack || []; - if (fragment.owner.type === types.SECTION) { - fragment.index = options.index; - } - if (parentFragment) { - parentRefs = parentFragment.indexRefs; - if (parentRefs) { - fragment.indexRefs = create(null); - for (ref in parentRefs) { - fragment.indexRefs[ref] = parentRefs[ref]; - } - } - } - fragment.priority = parentFragment ? parentFragment.priority + 1 : 1; - if (options.indexRef) { - if (!fragment.indexRefs) { - fragment.indexRefs = {}; - } - fragment.indexRefs[options.indexRef] = options.index; - } - fragment.items = []; - numItems = options.descriptor ? options.descriptor.length : 0; - for (i = 0; i < numItems; i += 1) { - fragment.items[fragment.items.length] = fragment.createItem({ - parentFragment: fragment, - descriptor: options.descriptor[i], - index: i - }); - } - }; - }(config_types, utils_create); -var render_DomFragment_shared_insertHtml = function (createElement) { - - var elementCache = {}; - return function (html, tagName, docFrag) { - var container, nodes = []; - if (html) { - container = elementCache[tagName] || (elementCache[tagName] = createElement(tagName)); - container.innerHTML = html; - while (container.firstChild) { - nodes[nodes.length] = container.firstChild; - docFrag.appendChild(container.firstChild); - } - } - return nodes; - }; - }(utils_createElement); -var render_DomFragment_Text = function (types) { - - var DomText, lessThan, greaterThan; - lessThan = //g; - DomText = function (options, docFrag) { - this.type = types.TEXT; - this.descriptor = options.descriptor; - if (docFrag) { - this.node = document.createTextNode(options.descriptor); - docFrag.appendChild(this.node); - } - }; - DomText.prototype = { - detach: function () { - this.node.parentNode.removeChild(this.node); - return this.node; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - } - }, - firstNode: function () { - return this.node; - }, - toString: function () { - return ('' + this.descriptor).replace(lessThan, '<').replace(greaterThan, '>'); - } - }; - return DomText; - }(config_types); -var shared_teardown = function (unregisterDependant) { - - return function (thing) { - if (!thing.keypath) { - var index = thing.root._pendingResolution.indexOf(thing); - if (index !== -1) { - thing.root._pendingResolution.splice(index, 1); - } - } else { - unregisterDependant(thing); - } - }; - }(shared_unregisterDependant); -var render_shared_Evaluator_Reference = function (types, isEqual, defineProperty, registerDependant, unregisterDependant) { - - var Reference, thisPattern; - thisPattern = /this/; - Reference = function (root, keypath, evaluator, argNum, priority) { - var value; - this.evaluator = evaluator; - this.keypath = keypath; - this.root = root; - this.argNum = argNum; - this.type = types.REFERENCE; - this.priority = priority; - value = root.get(keypath); - if (typeof value === 'function') { - value = wrapFunction(value, root, evaluator); - } - this.value = evaluator.values[argNum] = value; - registerDependant(this); - }; - Reference.prototype = { - update: function () { - var value = this.root.get(this.keypath); - if (typeof value === 'function' && !value._nowrap) { - value = wrapFunction(value, this.root, this.evaluator); - } - if (!isEqual(value, this.value)) { - this.evaluator.values[this.argNum] = value; - this.evaluator.bubble(); - this.value = value; - } - }, - teardown: function () { - unregisterDependant(this); - } - }; - return Reference; - function wrapFunction(fn, ractive, evaluator) { - var prop, evaluators, index; - if (!thisPattern.test(fn.toString())) { - defineProperty(fn, '_nowrap', { value: true }); - return fn; - } - if (!fn['_' + ractive._guid]) { - defineProperty(fn, '_' + ractive._guid, { - value: function () { - var originalCaptured, result, i, evaluator; - originalCaptured = ractive._captured; - if (!originalCaptured) { - ractive._captured = []; - } - result = fn.apply(ractive, arguments); - if (ractive._captured.length) { - i = evaluators.length; - while (i--) { - evaluator = evaluators[i]; - evaluator.updateSoftDependencies(ractive._captured); - } - } - ractive._captured = originalCaptured; - return result; - }, - writable: true - }); - for (prop in fn) { - if (fn.hasOwnProperty(prop)) { - fn['_' + ractive._guid][prop] = fn[prop]; - } - } - fn['_' + ractive._guid + '_evaluators'] = []; - } - evaluators = fn['_' + ractive._guid + '_evaluators']; - index = evaluators.indexOf(evaluator); - if (index === -1) { - evaluators.push(evaluator); - } - return fn['_' + ractive._guid]; - } - }(config_types, utils_isEqual, utils_defineProperty, shared_registerDependant, shared_unregisterDependant); -var render_shared_Evaluator_SoftReference = function (isEqual, registerDependant, unregisterDependant) { - - var SoftReference = function (root, keypath, evaluator) { - this.root = root; - this.keypath = keypath; - this.priority = evaluator.priority; - this.evaluator = evaluator; - registerDependant(this); - }; - SoftReference.prototype = { - update: function () { - var value = this.root.get(this.keypath); - if (!isEqual(value, this.value)) { - this.evaluator.bubble(); - this.value = value; - } - }, - teardown: function () { - unregisterDependant(this); - } - }; - return SoftReference; - }(utils_isEqual, shared_registerDependant, shared_unregisterDependant); -var render_shared_Evaluator__Evaluator = function (isEqual, defineProperty, clearCache, notifyDependants, registerDependant, unregisterDependant, adaptIfNecessary, Reference, SoftReference) { - - var Evaluator, cache = {}; - Evaluator = function (root, keypath, functionStr, args, priority) { - var i, arg; - this.root = root; - this.keypath = keypath; - this.priority = priority; - this.fn = getFunctionFromString(functionStr, args.length); - this.values = []; - this.refs = []; - i = args.length; - while (i--) { - if (arg = args[i]) { - if (arg[0]) { - this.values[i] = arg[1]; - } else { - this.refs[this.refs.length] = new Reference(root, arg[1], this, i, priority); - } - } else { - this.values[i] = undefined; - } - } - this.selfUpdating = this.refs.length <= 1; - this.update(); - }; - Evaluator.prototype = { - bubble: function () { - if (this.selfUpdating) { - this.update(); - } else if (!this.deferred) { - this.root._deferred.evals.push(this); - this.deferred = true; - } - }, - update: function () { - var value; - if (this.evaluating) { - return this; - } - this.evaluating = true; - try { - value = this.fn.apply(null, this.values); - } catch (err) { - if (this.root.debug) { - throw err; - } else { - value = undefined; - } - } - if (!isEqual(value, this.value)) { - clearCache(this.root, this.keypath); - this.root._cache[this.keypath] = value; - adaptIfNecessary(this.root, this.keypath, value, true); - this.value = value; - notifyDependants(this.root, this.keypath); - } - this.evaluating = false; - return this; - }, - teardown: function () { - while (this.refs.length) { - this.refs.pop().teardown(); - } - clearCache(this.root, this.keypath); - this.root._evaluators[this.keypath] = null; - }, - refresh: function () { - if (!this.selfUpdating) { - this.deferred = true; - } - var i = this.refs.length; - while (i--) { - this.refs[i].update(); - } - if (this.deferred) { - this.update(); - this.deferred = false; - } - }, - updateSoftDependencies: function (softDeps) { - var i, keypath, ref; - if (!this.softRefs) { - this.softRefs = []; - } - i = this.softRefs.length; - while (i--) { - ref = this.softRefs[i]; - if (!softDeps[ref.keypath]) { - this.softRefs.splice(i, 1); - this.softRefs[ref.keypath] = false; - ref.teardown(); - } - } - i = softDeps.length; - while (i--) { - keypath = softDeps[i]; - if (!this.softRefs[keypath]) { - ref = new SoftReference(this.root, keypath, this); - this.softRefs[this.softRefs.length] = ref; - this.softRefs[keypath] = true; - } - } - this.selfUpdating = this.refs.length + this.softRefs.length <= 1; - } - }; - return Evaluator; - function getFunctionFromString(str, i) { - var fn, args; - str = str.replace(/\$\{([0-9]+)\}/g, '_$1'); - if (cache[str]) { - return cache[str]; - } - args = []; - while (i--) { - args[i] = '_' + i; - } - fn = new Function(args.join(','), 'return(' + str + ')'); - cache[str] = fn; - return fn; - } - }(utils_isEqual, utils_defineProperty, shared_clearCache, shared_notifyDependants, shared_registerDependant, shared_unregisterDependant, shared_adaptIfNecessary, render_shared_Evaluator_Reference, render_shared_Evaluator_SoftReference); -var render_shared_ExpressionResolver_ReferenceScout = function (resolveRef, teardown) { - - var ReferenceScout = function (resolver, ref, contextStack, argNum) { - var keypath, root; - root = this.root = resolver.root; - keypath = resolveRef(root, ref, contextStack); - if (keypath !== undefined) { - resolver.resolveRef(argNum, false, keypath); - } else { - this.ref = ref; - this.argNum = argNum; - this.resolver = resolver; - this.contextStack = contextStack; - root._pendingResolution[root._pendingResolution.length] = this; - } - }; - ReferenceScout.prototype = { - resolve: function (keypath) { - this.keypath = keypath; - this.resolver.resolveRef(this.argNum, false, keypath); - }, - teardown: function () { - if (!this.keypath) { - teardown(this); - } - } - }; - return ReferenceScout; - }(shared_resolveRef, shared_teardown); -var render_shared_ExpressionResolver_isRegularKeypath = function () { - - var keyPattern = /^(?:(?:[a-zA-Z$_][a-zA-Z$_0-9]*)|(?:[0-9]|[1-9][0-9]+))$/; - return function (keypath) { - var keys, key, i; - keys = keypath.split('.'); - i = keys.length; - while (i--) { - key = keys[i]; - if (key === 'undefined' || !keyPattern.test(key)) { - return false; - } - } - return true; - }; - }(); -var render_shared_ExpressionResolver_getKeypath = function (normaliseKeypath, isRegularKeypath) { - - return function (str, args) { - var unique, normalised; - unique = str.replace(/\$\{([0-9]+)\}/g, function (match, $1) { - return args[$1] ? args[$1][1] : 'undefined'; - }); - normalised = normaliseKeypath(unique); - if (isRegularKeypath(normalised)) { - return normalised; - } - return '${' + unique.replace(/[\.\[\]]/g, '-') + '}'; - }; - }(utils_normaliseKeypath, render_shared_ExpressionResolver_isRegularKeypath); -var render_shared_ExpressionResolver_reassignDependants = function (registerDependant, unregisterDependant) { - - return function (ractive, oldKeypath, newKeypath) { - var toReassign, i, dependant; - toReassign = []; - gatherDependants(ractive, oldKeypath, toReassign); - i = toReassign.length; - while (i--) { - dependant = toReassign[i]; - unregisterDependant(dependant); - dependant.keypath = dependant.keypath.replace(oldKeypath, newKeypath); - registerDependant(dependant); - dependant.update(); - } - }; - function cascade(ractive, oldKeypath, toReassign) { - var map, i; - map = ractive._depsMap[oldKeypath]; - if (!map) { - return; - } - i = map.length; - while (i--) { - gatherDependants(ractive, map[i], toReassign); - } - } - function gatherDependants(ractive, oldKeypath, toReassign) { - var priority, dependantsByKeypath, dependants, i; - priority = ractive._deps.length; - while (priority--) { - dependantsByKeypath = ractive._deps[priority]; - if (dependantsByKeypath) { - dependants = dependantsByKeypath[oldKeypath]; - if (dependants) { - i = dependants.length; - while (i--) { - toReassign.push(dependants[i]); - } - } - } - } - cascade(ractive, oldKeypath, toReassign); - } - }(shared_registerDependant, shared_unregisterDependant); -var render_shared_ExpressionResolver__ExpressionResolver = function (Evaluator, ReferenceScout, getKeypath, reassignDependants) { - - var ExpressionResolver = function (mustache) { - var expression, i, len, ref, indexRefs; - this.root = mustache.root; - this.mustache = mustache; - this.args = []; - this.scouts = []; - expression = mustache.descriptor.x; - indexRefs = mustache.parentFragment.indexRefs; - this.str = expression.s; - len = this.unresolved = this.args.length = expression.r ? expression.r.length : 0; - if (!len) { - this.resolved = this.ready = true; - this.bubble(); - return; - } - for (i = 0; i < len; i += 1) { - ref = expression.r[i]; - if (indexRefs && indexRefs[ref] !== undefined) { - this.resolveRef(i, true, indexRefs[ref]); - } else { - this.scouts[this.scouts.length] = new ReferenceScout(this, ref, mustache.contextStack, i); - } - } - this.ready = true; - this.bubble(); - }; - ExpressionResolver.prototype = { - bubble: function () { - var oldKeypath; - if (!this.ready) { - return; - } - oldKeypath = this.keypath; - this.keypath = getKeypath(this.str, this.args); - if (this.keypath.substr(0, 2) === '${') { - this.createEvaluator(); - } - if (oldKeypath) { - reassignDependants(this.root, oldKeypath, this.keypath); - } else { - this.mustache.resolve(this.keypath); - } - }, - teardown: function () { - while (this.scouts.length) { - this.scouts.pop().teardown(); - } - }, - resolveRef: function (argNum, isIndexRef, value) { - this.args[argNum] = [ - isIndexRef, - value - ]; - this.bubble(); - this.resolved = !--this.unresolved; - }, - createEvaluator: function () { - if (!this.root._evaluators[this.keypath]) { - this.root._evaluators[this.keypath] = new Evaluator(this.root, this.keypath, this.str, this.args, this.mustache.priority); - } else { - this.root._evaluators[this.keypath].refresh(); - } - } - }; - return ExpressionResolver; - }(render_shared_Evaluator__Evaluator, render_shared_ExpressionResolver_ReferenceScout, render_shared_ExpressionResolver_getKeypath, render_shared_ExpressionResolver_reassignDependants); -var render_shared_initMustache = function (resolveRef, ExpressionResolver) { - - return function (mustache, options) { - var keypath, indexRef, parentFragment; - parentFragment = mustache.parentFragment = options.parentFragment; - mustache.root = parentFragment.root; - mustache.contextStack = parentFragment.contextStack; - mustache.descriptor = options.descriptor; - mustache.index = options.index || 0; - mustache.priority = parentFragment.priority; - mustache.type = options.descriptor.t; - if (options.descriptor.r) { - if (parentFragment.indexRefs && parentFragment.indexRefs[options.descriptor.r] !== undefined) { - indexRef = parentFragment.indexRefs[options.descriptor.r]; - mustache.indexRef = options.descriptor.r; - mustache.value = indexRef; - mustache.render(mustache.value); - } else { - keypath = resolveRef(mustache.root, options.descriptor.r, mustache.contextStack); - if (keypath !== undefined) { - mustache.resolve(keypath); - } else { - mustache.ref = options.descriptor.r; - mustache.root._pendingResolution[mustache.root._pendingResolution.length] = mustache; - } - } - } - if (options.descriptor.x) { - mustache.expressionResolver = new ExpressionResolver(mustache); - } - if (mustache.descriptor.n && !mustache.hasOwnProperty('value')) { - mustache.render(undefined); - } - }; - }(shared_resolveRef, render_shared_ExpressionResolver__ExpressionResolver); -var render_shared_resolveMustache = function (types, registerDependant, unregisterDependant) { - - return function (keypath) { - if (keypath === this.keypath) { - return; - } - if (this.registered) { - unregisterDependant(this); - } - this.keypath = keypath; - registerDependant(this); - this.update(); - if (this.root.twoway && this.parentFragment.owner.type === types.ATTRIBUTE) { - this.parentFragment.owner.element.bind(); - } - if (this.expressionResolver && this.expressionResolver.resolved) { - this.expressionResolver = null; - } - }; - }(config_types, shared_registerDependant, shared_unregisterDependant); -var render_shared_updateMustache = function (isEqual) { - - return function () { - var wrapped, value; - value = this.root.get(this.keypath); - if (wrapped = this.root._wrapped[this.keypath]) { - value = wrapped.get(); - } - if (!isEqual(value, this.value)) { - this.render(value); - this.value = value; - } - }; - }(utils_isEqual); -var render_DomFragment_Interpolator = function (types, teardown, initMustache, resolveMustache, updateMustache) { - - var DomInterpolator, lessThan, greaterThan; - lessThan = //g; - DomInterpolator = function (options, docFrag) { - this.type = types.INTERPOLATOR; - if (docFrag) { - this.node = document.createTextNode(''); - docFrag.appendChild(this.node); - } - initMustache(this, options); - }; - DomInterpolator.prototype = { - update: updateMustache, - resolve: resolveMustache, - detach: function () { - this.node.parentNode.removeChild(this.node); - return this.node; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - } - teardown(this); - }, - render: function (value) { - if (this.node) { - this.node.data = value == undefined ? '' : value; - } - }, - firstNode: function () { - return this.node; - }, - toString: function () { - var value = this.value != undefined ? '' + this.value : ''; - return value.replace(lessThan, '<').replace(greaterThan, '>'); - } - }; - return DomInterpolator; - }(config_types, shared_teardown, render_shared_initMustache, render_shared_resolveMustache, render_shared_updateMustache); -var render_shared_updateSection = function (isArray, isObject, create) { - - return function (section, value) { - var fragmentOptions; - fragmentOptions = { - descriptor: section.descriptor.f, - root: section.root, - pNode: section.parentFragment.pNode, - owner: section - }; - if (section.descriptor.n) { - updateConditionalSection(section, value, true, fragmentOptions); - return; - } - if (isArray(value)) { - updateListSection(section, value, fragmentOptions); - } else if (isObject(value)) { - if (section.descriptor.i) { - updateListObjectSection(section, value, fragmentOptions); - } else { - updateContextSection(section, fragmentOptions); - } - } else { - updateConditionalSection(section, value, false, fragmentOptions); - } - }; - function updateListSection(section, value, fragmentOptions) { - var i, length, fragmentsToRemove; - length = value.length; - if (length < section.length) { - fragmentsToRemove = section.fragments.splice(length, section.length - length); - while (fragmentsToRemove.length) { - fragmentsToRemove.pop().teardown(true); - } - } else { - if (length > section.length) { - for (i = section.length; i < length; i += 1) { - fragmentOptions.contextStack = section.contextStack.concat(section.keypath + '.' + i); - fragmentOptions.index = i; - if (section.descriptor.i) { - fragmentOptions.indexRef = section.descriptor.i; - } - section.fragments[i] = section.createFragment(fragmentOptions); - } - } - } - section.length = length; - } - function updateListObjectSection(section, value, fragmentOptions) { - var id, fragmentsById; - fragmentsById = section.fragmentsById || (section.fragmentsById = create(null)); - for (id in fragmentsById) { - if (value[id] === undefined && fragmentsById[id]) { - fragmentsById[id].teardown(true); - fragmentsById[id] = null; - } - } - for (id in value) { - if (value[id] !== undefined && !fragmentsById[id]) { - fragmentOptions.contextStack = section.contextStack.concat(section.keypath + '.' + id); - fragmentOptions.index = id; - if (section.descriptor.i) { - fragmentOptions.indexRef = section.descriptor.i; - } - fragmentsById[id] = section.createFragment(fragmentOptions); - } - } - } - function updateContextSection(section, fragmentOptions) { - if (!section.length) { - fragmentOptions.contextStack = section.contextStack.concat(section.keypath); - fragmentOptions.index = 0; - section.fragments[0] = section.createFragment(fragmentOptions); - section.length = 1; - } - } - function updateConditionalSection(section, value, inverted, fragmentOptions) { - var doRender, emptyArray, fragmentsToRemove, fragment; - emptyArray = isArray(value) && value.length === 0; - if (inverted) { - doRender = emptyArray || !value; - } else { - doRender = value && !emptyArray; - } - if (doRender) { - if (!section.length) { - fragmentOptions.contextStack = section.contextStack; - fragmentOptions.index = 0; - section.fragments[0] = section.createFragment(fragmentOptions); - section.length = 1; - } - if (section.length > 1) { - fragmentsToRemove = section.fragments.splice(1); - while (fragment = fragmentsToRemove.pop()) { - fragment.teardown(true); - } - } - } else if (section.length) { - section.teardownFragments(true); - section.length = 0; - } - } - }(utils_isArray, utils_isObject, utils_create); -var render_DomFragment_Section_reassignFragment = function (types, unregisterDependant, ExpressionResolver) { - - return reassignFragment; - function reassignFragment(fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath) { - var i, item, context, query; - if (fragment.html) { - return; - } - if (fragment.indexRefs && fragment.indexRefs[indexRef] !== undefined) { - fragment.indexRefs[indexRef] = newIndex; - } - i = fragment.contextStack.length; - while (i--) { - context = fragment.contextStack[i]; - if (context.substr(0, oldKeypath.length) === oldKeypath) { - fragment.contextStack[i] = context.replace(oldKeypath, newKeypath); - } - } - i = fragment.items.length; - while (i--) { - item = fragment.items[i]; - switch (item.type) { - case types.ELEMENT: - reassignElement(item, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - break; - case types.PARTIAL: - reassignFragment(item.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - break; - case types.COMPONENT: - reassignFragment(item.instance.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - if (query = fragment.root._liveComponentQueries[item.name]) { - query._makeDirty(); - } - break; - case types.SECTION: - case types.INTERPOLATOR: - case types.TRIPLE: - reassignMustache(item, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - break; - } - } - } - function reassignElement(element, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath) { - var i, attribute, storage, masterEventName, proxies, proxy, binding, bindings, liveQueries, ractive; - i = element.attributes.length; - while (i--) { - attribute = element.attributes[i]; - if (attribute.fragment) { - reassignFragment(attribute.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - if (attribute.twoway) { - attribute.updateBindings(); - } - } - } - if (storage = element.node._ractive) { - if (storage.keypath.substr(0, oldKeypath.length) === oldKeypath) { - storage.keypath = storage.keypath.replace(oldKeypath, newKeypath); - } - if (indexRef !== undefined) { - storage.index[indexRef] = newIndex; - } - for (masterEventName in storage.events) { - proxies = storage.events[masterEventName].proxies; - i = proxies.length; - while (i--) { - proxy = proxies[i]; - if (typeof proxy.n === 'object') { - reassignFragment(proxy.a, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - if (proxy.d) { - reassignFragment(proxy.d, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - } - } - if (binding = storage.binding) { - if (binding.keypath.substr(0, oldKeypath.length) === oldKeypath) { - bindings = storage.root._twowayBindings[binding.keypath]; - bindings.splice(bindings.indexOf(binding), 1); - binding.keypath = binding.keypath.replace(oldKeypath, newKeypath); - bindings = storage.root._twowayBindings[binding.keypath] || (storage.root._twowayBindings[binding.keypath] = []); - bindings.push(binding); - } - } - } - if (element.fragment) { - reassignFragment(element.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - if (liveQueries = element.liveQueries) { - ractive = element.root; - i = liveQueries.length; - while (i--) { - ractive._liveQueries[liveQueries[i]]._makeDirty(); - } - } - } - function reassignMustache(mustache, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath) { - var i; - if (mustache.descriptor.x) { - if (mustache.expressionResolver) { - mustache.expressionResolver.teardown(); - } - mustache.expressionResolver = new ExpressionResolver(mustache); - } - if (mustache.keypath) { - if (mustache.keypath.substr(0, oldKeypath.length) === oldKeypath) { - mustache.resolve(mustache.keypath.replace(oldKeypath, newKeypath)); - } - } else if (mustache.indexRef === indexRef) { - mustache.value = newIndex; - mustache.render(newIndex); - } - if (mustache.fragments) { - i = mustache.fragments.length; - while (i--) { - reassignFragment(mustache.fragments[i], indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - } - } - }(config_types, shared_unregisterDependant, render_shared_ExpressionResolver__ExpressionResolver); -var render_DomFragment_Section_reassignFragments = function (types, reassignFragment, preDomUpdate) { - - return function (root, section, start, end, by) { - var i, fragment, indexRef, oldIndex, newIndex, oldKeypath, newKeypath; - indexRef = section.descriptor.i; - for (i = start; i < end; i += 1) { - fragment = section.fragments[i]; - oldIndex = i - by; - newIndex = i; - oldKeypath = section.keypath + '.' + (i - by); - newKeypath = section.keypath + '.' + i; - fragment.index += by; - reassignFragment(fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - preDomUpdate(root); - }; - }(config_types, render_DomFragment_Section_reassignFragment, shared_preDomUpdate); -var render_DomFragment_Section_prototype_merge = function (reassignFragment) { - - return function (newIndices) { - var section = this, parentFragment, firstChange, changed, i, newLength, newFragments, toTeardown, fragmentOptions, fragment, nextNode; - parentFragment = this.parentFragment; - newFragments = []; - newIndices.forEach(function (newIndex, oldIndex) { - var by, oldKeypath, newKeypath; - if (newIndex === oldIndex) { - newFragments[newIndex] = section.fragments[oldIndex]; - return; - } - if (firstChange === undefined) { - firstChange = oldIndex; - } - if (newIndex === -1) { - (toTeardown || (toTeardown = [])).push(section.fragments[oldIndex]); - return; - } - by = newIndex - oldIndex; - oldKeypath = section.keypath + '.' + oldIndex; - newKeypath = section.keypath + '.' + newIndex; - reassignFragment(section.fragments[oldIndex], section.descriptor.i, oldIndex, newIndex, by, oldKeypath, newKeypath); - newFragments[newIndex] = section.fragments[oldIndex]; - changed = true; - }); - if (toTeardown) { - while (fragment = toTeardown.pop()) { - fragment.teardown(true); - } - } - if (firstChange === undefined) { - firstChange = this.length; - } - newLength = this.root.get(this.keypath).length; - if (newLength === firstChange) { - return; - } - fragmentOptions = { - descriptor: this.descriptor.f, - root: this.root, - pNode: parentFragment.pNode, - owner: this - }; - if (this.descriptor.i) { - fragmentOptions.indexRef = this.descriptor.i; - } - for (i = firstChange; i < newLength; i += 1) { - if (fragment = newFragments[i]) { - this.docFrag.appendChild(fragment.detach(false)); - } else { - fragmentOptions.contextStack = this.contextStack.concat(this.keypath + '.' + i); - fragmentOptions.index = i; - fragment = this.createFragment(fragmentOptions); - } - this.fragments[i] = fragment; - } - nextNode = parentFragment.findNextNode(this); - parentFragment.pNode.insertBefore(this.docFrag, nextNode); - this.length = newLength; - }; - }(render_DomFragment_Section_reassignFragment); -var circular = function () { - - return []; - }(); -var render_DomFragment_Section__Section = function (types, isClient, initMustache, updateMustache, resolveMustache, updateSection, reassignFragment, reassignFragments, merge, teardown, circular) { - - var DomSection, DomFragment; - circular.push(function () { - DomFragment = circular.DomFragment; - }); - DomSection = function (options, docFrag) { - this.type = types.SECTION; - this.inverted = !!options.descriptor.n; - this.fragments = []; - this.length = 0; - if (docFrag) { - this.docFrag = document.createDocumentFragment(); - } - this.initialising = true; - initMustache(this, options); - if (docFrag) { - docFrag.appendChild(this.docFrag); - } - this.initialising = false; - }; - DomSection.prototype = { - update: updateMustache, - resolve: resolveMustache, - smartUpdate: function (methodName, args) { - var fragmentOptions; - if (methodName === 'push' || methodName === 'unshift' || methodName === 'splice') { - fragmentOptions = { - descriptor: this.descriptor.f, - root: this.root, - pNode: this.parentFragment.pNode, - owner: this - }; - if (this.descriptor.i) { - fragmentOptions.indexRef = this.descriptor.i; - } - } - if (this[methodName]) { - this.rendering = true; - this[methodName](fragmentOptions, args); - this.rendering = false; - } - }, - pop: function () { - if (this.length) { - this.fragments.pop().teardown(true); - this.length -= 1; - } - }, - push: function (fragmentOptions, args) { - var start, end, i; - start = this.length; - end = start + args.length; - for (i = start; i < end; i += 1) { - fragmentOptions.contextStack = this.contextStack.concat(this.keypath + '.' + i); - fragmentOptions.index = i; - this.fragments[i] = this.createFragment(fragmentOptions); - } - this.length += args.length; - this.parentFragment.pNode.insertBefore(this.docFrag, this.parentFragment.findNextNode(this)); - }, - shift: function () { - this.splice(null, [ - 0, - 1 - ]); - }, - unshift: function (fragmentOptions, args) { - this.splice(fragmentOptions, [ - 0, - 0 - ].concat(new Array(args.length))); - }, - splice: function (fragmentOptions, args) { - var insertionPoint, addedItems, removedItems, balance, i, start, end, spliceArgs, reassignStart; - if (!args.length) { - return; - } - start = +(args[0] < 0 ? this.length + args[0] : args[0]); - addedItems = Math.max(0, args.length - 2); - removedItems = args[1] !== undefined ? args[1] : this.length - start; - removedItems = Math.min(removedItems, this.length - start); - balance = addedItems - removedItems; - if (!balance) { - return; - } - if (balance < 0) { - end = start - balance; - for (i = start; i < end; i += 1) { - this.fragments[i].teardown(true); - } - this.fragments.splice(start, -balance); - } else { - end = start + balance; - insertionPoint = this.fragments[start] ? this.fragments[start].firstNode() : this.parentFragment.findNextNode(this); - spliceArgs = [ - start, - 0 - ].concat(new Array(balance)); - this.fragments.splice.apply(this.fragments, spliceArgs); - for (i = start; i < end; i += 1) { - fragmentOptions.contextStack = this.contextStack.concat(this.keypath + '.' + i); - fragmentOptions.index = i; - this.fragments[i] = this.createFragment(fragmentOptions); - } - this.parentFragment.pNode.insertBefore(this.docFrag, insertionPoint); - } - this.length += balance; - reassignStart = start + addedItems; - reassignFragments(this.root, this, reassignStart, this.length, balance); - }, - merge: merge, - detach: function () { - var i, len; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - this.docFrag.appendChild(this.fragments[i].detach()); - } - return this.docFrag; - }, - teardown: function (destroy) { - this.teardownFragments(destroy); - teardown(this); - }, - firstNode: function () { - if (this.fragments[0]) { - return this.fragments[0].firstNode(); - } - return this.parentFragment.findNextNode(this); - }, - findNextNode: function (fragment) { - if (this.fragments[fragment.index + 1]) { - return this.fragments[fragment.index + 1].firstNode(); - } - return this.parentFragment.findNextNode(this); - }, - teardownFragments: function (destroy) { - var id, fragment; - while (fragment = this.fragments.shift()) { - fragment.teardown(destroy); - } - if (this.fragmentsById) { - for (id in this.fragmentsById) { - if (this.fragments[id]) { - this.fragmentsById[id].teardown(destroy); - this.fragmentsById[id] = null; - } - } - } - }, - render: function (value) { - var nextNode, wrapped; - if (wrapped = this.root._wrapped[this.keypath]) { - value = wrapped.get(); - } - if (this.rendering) { - return; - } - this.rendering = true; - updateSection(this, value); - this.rendering = false; - if (this.docFrag && !this.docFrag.childNodes.length) { - return; - } - if (!this.initialising && isClient) { - nextNode = this.parentFragment.findNextNode(this); - if (nextNode && nextNode.parentNode === this.parentFragment.pNode) { - this.parentFragment.pNode.insertBefore(this.docFrag, nextNode); - } else { - this.parentFragment.pNode.appendChild(this.docFrag); - } - } - }, - createFragment: function (options) { - var fragment = new DomFragment(options); - if (this.docFrag) { - this.docFrag.appendChild(fragment.docFrag); - } - return fragment; - }, - toString: function () { - var str, i, id, len; - str = ''; - i = 0; - len = this.length; - for (i = 0; i < len; i += 1) { - str += this.fragments[i].toString(); - } - if (this.fragmentsById) { - for (id in this.fragmentsById) { - if (this.fragmentsById[id]) { - str += this.fragmentsById[id].toString(); - } - } - } - return str; - }, - find: function (selector) { - var i, len, queryResult; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - if (queryResult = this.fragments[i].find(selector)) { - return queryResult; - } - } - return null; - }, - findAll: function (selector, query) { - var i, len; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - this.fragments[i].findAll(selector, query); - } - }, - findComponent: function (selector) { - var i, len, queryResult; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - if (queryResult = this.fragments[i].findComponent(selector)) { - return queryResult; - } - } - return null; - }, - findAllComponents: function (selector, query) { - var i, len; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - this.fragments[i].findAllComponents(selector, query); - } - } - }; - return DomSection; - }(config_types, config_isClient, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache, render_shared_updateSection, render_DomFragment_Section_reassignFragment, render_DomFragment_Section_reassignFragments, render_DomFragment_Section_prototype_merge, shared_teardown, circular); -var render_DomFragment_Triple = function (types, matches, initMustache, updateMustache, resolveMustache, insertHtml, teardown) { - - var DomTriple = function (options, docFrag) { - this.type = types.TRIPLE; - if (docFrag) { - this.nodes = []; - this.docFrag = document.createDocumentFragment(); - } - this.initialising = true; - initMustache(this, options); - if (docFrag) { - docFrag.appendChild(this.docFrag); - } - this.initialising = false; - }; - DomTriple.prototype = { - update: updateMustache, - resolve: resolveMustache, - detach: function () { - var i = this.nodes.length; - while (i--) { - this.docFrag.appendChild(this.nodes[i]); - } - return this.docFrag; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - this.docFrag = this.nodes = null; - } - teardown(this); - }, - firstNode: function () { - if (this.nodes[0]) { - return this.nodes[0]; - } - return this.parentFragment.findNextNode(this); - }, - render: function (html) { - var node, pNode; - if (!this.nodes) { - return; - } - while (this.nodes.length) { - node = this.nodes.pop(); - node.parentNode.removeChild(node); - } - if (!html) { - this.nodes = []; - return; - } - pNode = this.parentFragment.pNode; - this.nodes = insertHtml(html, pNode.tagName, this.docFrag); - if (!this.initialising) { - pNode.insertBefore(this.docFrag, this.parentFragment.findNextNode(this)); - } - }, - toString: function () { - return this.value != undefined ? this.value : ''; - }, - find: function (selector) { - var i, len, node, queryResult; - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - return node; - } - if (queryResult = node.querySelector(selector)) { - return queryResult; - } - } - return null; - }, - findAll: function (selector, queryResult) { - var i, len, node, queryAllResult, numNodes, j; - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - queryResult.push(node); - } - if (queryAllResult = node.querySelectorAll(selector)) { - numNodes = queryAllResult.length; - for (j = 0; j < numNodes; j += 1) { - queryResult.push(queryAllResult[j]); - } - } - } - } - }; - return DomTriple; - }(config_types, utils_matches, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache, render_DomFragment_shared_insertHtml, shared_teardown); -var render_DomFragment_Element_initialise_getElementNamespace = function (namespaces) { - - return function (descriptor, parentNode) { - if (descriptor.a && descriptor.a.xmlns) { - return descriptor.a.xmlns; - } - return descriptor.e === 'svg' ? namespaces.svg : parentNode.namespaceURI || namespaces.html; - }; - }(config_namespaces); -var render_DomFragment_shared_enforceCase = function () { - - var svgCamelCaseElements, svgCamelCaseAttributes, createMap, map; - svgCamelCaseElements = 'altGlyph altGlyphDef altGlyphItem animateColor animateMotion animateTransform clipPath feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile feTurbulence foreignObject glyphRef linearGradient radialGradient textPath vkern'.split(' '); - svgCamelCaseAttributes = 'attributeName attributeType baseFrequency baseProfile calcMode clipPathUnits contentScriptType contentStyleType diffuseConstant edgeMode externalResourcesRequired filterRes filterUnits glyphRef gradientTransform gradientUnits kernelMatrix kernelUnitLength keyPoints keySplines keyTimes lengthAdjust limitingConeAngle markerHeight markerUnits markerWidth maskContentUnits maskUnits numOctaves pathLength patternContentUnits patternTransform patternUnits pointsAtX pointsAtY pointsAtZ preserveAlpha preserveAspectRatio primitiveUnits refX refY repeatCount repeatDur requiredExtensions requiredFeatures specularConstant specularExponent spreadMethod startOffset stdDeviation stitchTiles surfaceScale systemLanguage tableValues targetX targetY textLength viewBox viewTarget xChannelSelector yChannelSelector zoomAndPan'.split(' '); - createMap = function (items) { - var map = {}, i = items.length; - while (i--) { - map[items[i].toLowerCase()] = items[i]; - } - return map; - }; - map = createMap(svgCamelCaseElements.concat(svgCamelCaseAttributes)); - return function (elementName) { - var lowerCaseElementName = elementName.toLowerCase(); - return map[lowerCaseElementName] || lowerCaseElementName; - }; - }(); -var render_DomFragment_Attribute_helpers_determineNameAndNamespace = function (namespaces, enforceCase) { - - return function (attribute, name) { - var colonIndex, namespacePrefix; - colonIndex = name.indexOf(':'); - if (colonIndex !== -1) { - namespacePrefix = name.substr(0, colonIndex); - if (namespacePrefix !== 'xmlns') { - name = name.substring(colonIndex + 1); - attribute.name = enforceCase(name); - attribute.lcName = attribute.name.toLowerCase(); - attribute.namespace = namespaces[namespacePrefix.toLowerCase()]; - if (!attribute.namespace) { - throw 'Unknown namespace ("' + namespacePrefix + '")'; - } - return; - } - } - attribute.name = attribute.element.namespace !== namespaces.html ? enforceCase(name) : name; - attribute.lcName = attribute.name.toLowerCase(); - }; - }(config_namespaces, render_DomFragment_shared_enforceCase); -var render_DomFragment_Attribute_helpers_setStaticAttribute = function (namespaces) { - - return function (attribute, options) { - var node, value = options.value === null ? '' : options.value; - if (node = options.pNode) { - if (attribute.namespace) { - node.setAttributeNS(attribute.namespace, options.name, value); - } else { - if (options.name === 'style' && node.style.setAttribute) { - node.style.setAttribute('cssText', value); - } else if (options.name === 'class' && (!node.namespaceURI || node.namespaceURI === namespaces.html)) { - node.className = value; - } else { - node.setAttribute(options.name, value); - } - } - if (attribute.name === 'id') { - options.root.nodes[options.value] = node; - } - if (attribute.name === 'value') { - node._ractive.value = options.value; - } - } - attribute.value = options.value; - }; - }(config_namespaces); -var render_DomFragment_Attribute_helpers_determinePropertyName = function (namespaces) { - - var propertyNames = { - 'accept-charset': 'acceptCharset', - accesskey: 'accessKey', - bgcolor: 'bgColor', - 'class': 'className', - codebase: 'codeBase', - colspan: 'colSpan', - contenteditable: 'contentEditable', - datetime: 'dateTime', - dirname: 'dirName', - 'for': 'htmlFor', - 'http-equiv': 'httpEquiv', - ismap: 'isMap', - maxlength: 'maxLength', - novalidate: 'noValidate', - pubdate: 'pubDate', - readonly: 'readOnly', - rowspan: 'rowSpan', - tabindex: 'tabIndex', - usemap: 'useMap' - }; - return function (attribute, options) { - var propertyName; - if (attribute.pNode && !attribute.namespace && (!options.pNode.namespaceURI || options.pNode.namespaceURI === namespaces.html)) { - propertyName = propertyNames[attribute.name] || attribute.name; - if (options.pNode[propertyName] !== undefined) { - attribute.propertyName = propertyName; - } - if (typeof options.pNode[propertyName] === 'boolean' || propertyName === 'value') { - attribute.useProperty = true; - } - } - }; - }(config_namespaces); -var render_DomFragment_Attribute_prototype_bind = function (types, warn, arrayContentsMatch, getValueFromCheckboxes) { - - var bindAttribute, getInterpolator, updateModel, update, getBinding, inheritProperties, MultipleSelectBinding, SelectBinding, RadioNameBinding, CheckboxNameBinding, CheckedBinding, FileListBinding, ContentEditableBinding, GenericBinding; - bindAttribute = function () { - var node = this.pNode, interpolator, binding, bindings; - if (!this.fragment) { - return false; - } - interpolator = getInterpolator(this); - if (!interpolator) { - return false; - } - this.interpolator = interpolator; - this.keypath = interpolator.keypath || interpolator.descriptor.r; - binding = getBinding(this); - if (!binding) { - return false; - } - node._ractive.binding = this.element.binding = binding; - this.twoway = true; - bindings = this.root._twowayBindings[this.keypath] || (this.root._twowayBindings[this.keypath] = []); - bindings[bindings.length] = binding; - return true; - }; - updateModel = function () { - this._ractive.binding.update(); - }; - update = function () { - var value = this._ractive.root.get(this._ractive.binding.keypath); - this.value = value == undefined ? '' : value; - }; - getInterpolator = function (attribute) { - var item, errorMessage; - if (attribute.fragment.items.length !== 1) { - return null; - } - item = attribute.fragment.items[0]; - if (item.type !== types.INTERPOLATOR) { - return null; - } - if (!item.keypath && !item.ref) { - return null; - } - if (item.keypath && item.keypath.substr(0, 2) === '${') { - errorMessage = 'You cannot set up two-way binding against an expression ' + item.keypath; - if (attribute.root.debug) { - warn(errorMessage); - } - return null; - } - return item; - }; - getBinding = function (attribute) { - var node = attribute.pNode; - if (node.tagName === 'SELECT') { - return node.multiple ? new MultipleSelectBinding(attribute, node) : new SelectBinding(attribute, node); - } - if (node.type === 'checkbox' || node.type === 'radio') { - if (attribute.propertyName === 'name') { - if (node.type === 'checkbox') { - return new CheckboxNameBinding(attribute, node); - } - if (node.type === 'radio') { - return new RadioNameBinding(attribute, node); - } - } - if (attribute.propertyName === 'checked') { - return new CheckedBinding(attribute, node); - } - return null; - } - if (attribute.lcName !== 'value') { - warn('This is... odd'); - } - if (node.type === 'file') { - return new FileListBinding(attribute, node); - } - if (node.getAttribute('contenteditable')) { - return new ContentEditableBinding(attribute, node); - } - return new GenericBinding(attribute, node); - }; - MultipleSelectBinding = function (attribute, node) { - var valueFromModel; - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - valueFromModel = this.root.get(this.keypath); - if (valueFromModel === undefined) { - this.update(); - } - }; - MultipleSelectBinding.prototype = { - value: function () { - var value, options, i, len; - value = []; - options = this.node.options; - len = options.length; - for (i = 0; i < len; i += 1) { - if (options[i].selected) { - value[value.length] = options[i]._ractive.value; - } - } - return value; - }, - update: function () { - var attribute, previousValue, value; - attribute = this.attr; - previousValue = attribute.value; - value = this.value(); - if (previousValue === undefined || !arrayContentsMatch(value, previousValue)) { - attribute.receiving = true; - attribute.value = value; - this.root.set(this.keypath, value); - attribute.receiving = false; - } - return this; - }, - deferUpdate: function () { - if (this.deferred === true) { - return; - } - this.root._deferred.attrs.push(this); - this.deferred = true; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - } - }; - SelectBinding = function (attribute, node) { - var valueFromModel; - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - valueFromModel = this.root.get(this.keypath); - if (valueFromModel === undefined) { - this.update(); - } - }; - SelectBinding.prototype = { - value: function () { - var options, i, len; - options = this.node.options; - len = options.length; - for (i = 0; i < len; i += 1) { - if (options[i].selected) { - return options[i]._ractive.value; - } - } - }, - update: function () { - var value = this.value(); - this.attr.receiving = true; - this.attr.value = value; - this.root.set(this.keypath, value); - this.attr.receiving = false; - return this; - }, - deferUpdate: function () { - if (this.deferred === true) { - return; - } - this.root._deferred.attrs.push(this); - this.deferred = true; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - } - }; - RadioNameBinding = function (attribute, node) { - var valueFromModel; - this.radioName = true; - inheritProperties(this, attribute, node); - node.name = '{{' + attribute.keypath + '}}'; - node.addEventListener('change', updateModel, false); - if (node.attachEvent) { - node.addEventListener('click', updateModel, false); - } - valueFromModel = this.root.get(this.keypath); - if (valueFromModel !== undefined) { - node.checked = valueFromModel == node._ractive.value; - } else { - this.root._deferred.radios.push(this); - } - }; - RadioNameBinding.prototype = { - value: function () { - return this.node._ractive ? this.node._ractive.value : this.node.value; - }, - update: function () { - var node = this.node; - if (node.checked) { - this.attr.receiving = true; - this.root.set(this.keypath, this.value()); - this.attr.receiving = false; - } - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('click', updateModel, false); - } - }; - CheckboxNameBinding = function (attribute, node) { - var valueFromModel, checked; - this.checkboxName = true; - inheritProperties(this, attribute, node); - node.name = '{{' + this.keypath + '}}'; - node.addEventListener('change', updateModel, false); - if (node.attachEvent) { - node.addEventListener('click', updateModel, false); - } - valueFromModel = this.root.get(this.keypath); - if (valueFromModel !== undefined) { - checked = valueFromModel.indexOf(node._ractive.value) !== -1; - node.checked = checked; - } else { - if (this.root._deferred.checkboxes.indexOf(this.keypath) === -1) { - this.root._deferred.checkboxes.push(this.keypath); - } - } - }; - CheckboxNameBinding.prototype = { - changed: function () { - return this.node.checked !== !!this.checked; - }, - update: function () { - this.checked = this.node.checked; - this.attr.receiving = true; - this.root.set(this.keypath, getValueFromCheckboxes(this.root, this.keypath)); - this.attr.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('click', updateModel, false); - } - }; - CheckedBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - if (node.attachEvent) { - node.addEventListener('click', updateModel, false); - } - }; - CheckedBinding.prototype = { - value: function () { - return this.node.checked; - }, - update: function () { - this.attr.receiving = true; - this.root.set(this.keypath, this.value()); - this.attr.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('click', updateModel, false); - } - }; - FileListBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - }; - FileListBinding.prototype = { - value: function () { - return this.attr.pNode.files; - }, - update: function () { - this.attr.root.set(this.attr.keypath, this.value()); - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - } - }; - ContentEditableBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - if (!this.root.lazy) { - node.addEventListener('input', updateModel, false); - if (node.attachEvent) { - node.addEventListener('keyup', updateModel, false); - } - } - }; - ContentEditableBinding.prototype = { - update: function () { - this.attr.receiving = true; - this.root.set(this.keypath, this.node.innerHTML); - this.attr.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('input', updateModel, false); - this.node.removeEventListener('keyup', updateModel, false); - } - }; - GenericBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - if (!this.root.lazy) { - node.addEventListener('input', updateModel, false); - if (node.attachEvent) { - node.addEventListener('keyup', updateModel, false); - } - } - this.node.addEventListener('blur', update, false); - }; - GenericBinding.prototype = { - value: function () { - var value = this.attr.pNode.value; - if (+value + '' === value && value.indexOf('e') === -1) { - value = +value; - } - return value; - }, - update: function () { - var attribute = this.attr, value = this.value(); - attribute.receiving = true; - attribute.root.set(attribute.keypath, value); - attribute.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('input', updateModel, false); - this.node.removeEventListener('keyup', updateModel, false); - this.node.removeEventListener('blur', update, false); - } - }; - inheritProperties = function (binding, attribute, node) { - binding.attr = attribute; - binding.node = node; - binding.root = attribute.root; - binding.keypath = attribute.keypath; - }; - return bindAttribute; - }(config_types, utils_warn, utils_arrayContentsMatch, shared_getValueFromCheckboxes); -var render_DomFragment_Attribute_prototype_update = function (isArray, namespaces) { - - var updateAttribute, updateFileInputValue, deferSelect, initSelect, updateSelect, updateMultipleSelect, updateRadioName, updateCheckboxName, updateIEStyleAttribute, updateClassName, updateContentEditableValue, updateEverythingElse; - updateAttribute = function () { - var node; - if (!this.ready) { - return this; - } - node = this.pNode; - if (node.tagName === 'SELECT' && this.lcName === 'value') { - this.update = deferSelect; - this.deferredUpdate = initSelect; - return this.update(); - } - if (this.isFileInputValue) { - this.update = updateFileInputValue; - return this; - } - if (this.twoway && this.lcName === 'name') { - if (node.type === 'radio') { - this.update = updateRadioName; - return this.update(); - } - if (node.type === 'checkbox') { - this.update = updateCheckboxName; - return this.update(); - } - } - if (this.lcName === 'style' && node.style.setAttribute) { - this.update = updateIEStyleAttribute; - return this.update(); - } - if (this.lcName === 'class' && (!node.namespaceURI || node.namespaceURI === namespaces.html)) { - this.update = updateClassName; - return this.update(); - } - if (node.getAttribute('contenteditable') && this.lcName === 'value') { - this.update = updateContentEditableValue; - return this.update(); - } - this.update = updateEverythingElse; - return this.update(); - }; - updateFileInputValue = function () { - return this; - }; - initSelect = function () { - this.deferredUpdate = this.pNode.multiple ? updateMultipleSelect : updateSelect; - this.deferredUpdate(); - }; - deferSelect = function () { - this.root._deferred.selectValues.push(this); - return this; - }; - updateSelect = function () { - var value = this.fragment.getValue(), options, option, i; - this.value = this.pNode._ractive.value = value; - options = this.pNode.options; - i = options.length; - while (i--) { - option = options[i]; - if (option._ractive.value == value) { - option.selected = true; - return this; - } - } - return this; - }; - updateMultipleSelect = function () { - var value = this.fragment.getValue(), options, i; - if (!isArray(value)) { - value = [value]; - } - options = this.pNode.options; - i = options.length; - while (i--) { - options[i].selected = value.indexOf(options[i]._ractive.value) !== -1; - } - this.value = value; - return this; - }; - updateRadioName = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - node.checked = value == node._ractive.value; - return this; - }; - updateCheckboxName = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (!isArray(value)) { - node.checked = value == node._ractive.value; - return this; - } - node.checked = value.indexOf(node._ractive.value) !== -1; - return this; - }; - updateIEStyleAttribute = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - node.style.setAttribute('cssText', value); - this.value = value; - } - return this; - }; - updateClassName = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - node.className = value; - this.value = value; - } - return this; - }; - updateContentEditableValue = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - if (!this.receiving) { - node.innerHTML = value; - } - this.value = value; - } - return this; - }; - updateEverythingElse = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (this.isValueAttribute) { - node._ractive.value = value; - } - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - if (this.useProperty) { - if (!this.receiving) { - node[this.propertyName] = value; - } - this.value = value; - return this; - } - if (this.namespace) { - node.setAttributeNS(this.namespace, this.name, value); - this.value = value; - return this; - } - if (this.lcName === 'id') { - if (this.value !== undefined) { - this.root.nodes[this.value] = undefined; - } - this.root.nodes[value] = node; - } - node.setAttribute(this.name, value); - this.value = value; - } - return this; - }; - return updateAttribute; - }(utils_isArray, config_namespaces); -var parse_Tokenizer_utils_getStringMatch = function () { - - return function (string) { - var substr; - substr = this.str.substr(this.pos, string.length); - if (substr === string) { - this.pos += string.length; - return string; - } - return null; - }; - }(); -var parse_Tokenizer_utils_allowWhitespace = function () { - - var leadingWhitespace = /^\s+/; - return function () { - var match = leadingWhitespace.exec(this.remaining()); - if (!match) { - return null; - } - this.pos += match[0].length; - return match[0]; - }; - }(); -var parse_Tokenizer_utils_makeRegexMatcher = function () { - - return function (regex) { - return function (tokenizer) { - var match = regex.exec(tokenizer.str.substring(tokenizer.pos)); - if (!match) { - return null; - } - tokenizer.pos += match[0].length; - return match[1] || match[0]; - }; - }; - }(); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getEscapedChars = function () { - - return function (tokenizer) { - var chars = '', character; - character = getEscapedChar(tokenizer); - while (character) { - chars += character; - character = getEscapedChar(tokenizer); - } - return chars || null; - }; - function getEscapedChar(tokenizer) { - var character; - if (!tokenizer.getStringMatch('\\')) { - return null; - } - character = tokenizer.str.charAt(tokenizer.pos); - tokenizer.pos += 1; - return character; - } - }(); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getQuotedString = function (makeRegexMatcher, getEscapedChars) { - - var getUnescapedDoubleQuotedChars = makeRegexMatcher(/^[^\\"]+/), getUnescapedSingleQuotedChars = makeRegexMatcher(/^[^\\']+/); - return function getQuotedString(tokenizer, singleQuotes) { - var start, string, escaped, unescaped, next, matcher; - start = tokenizer.pos; - string = ''; - matcher = singleQuotes ? getUnescapedSingleQuotedChars : getUnescapedDoubleQuotedChars; - escaped = getEscapedChars(tokenizer); - if (escaped) { - string += escaped; - } - unescaped = matcher(tokenizer); - if (unescaped) { - string += unescaped; - } - if (!string) { - return ''; - } - next = getQuotedString(tokenizer, singleQuotes); - while (next !== '') { - string += next; - } - return string; - }; - }(parse_Tokenizer_utils_makeRegexMatcher, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getEscapedChars); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral = function (types, getQuotedString) { - - return function (tokenizer) { - var start, string; - start = tokenizer.pos; - if (tokenizer.getStringMatch('"')) { - string = getQuotedString(tokenizer, false); - if (!tokenizer.getStringMatch('"')) { - tokenizer.pos = start; - return null; - } - return { - t: types.STRING_LITERAL, - v: string - }; - } - if (tokenizer.getStringMatch('\'')) { - string = getQuotedString(tokenizer, true); - if (!tokenizer.getStringMatch('\'')) { - tokenizer.pos = start; - return null; - } - return { - t: types.STRING_LITERAL, - v: string - }; - } - return null; - }; - }(config_types, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getQuotedString); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getNumberLiteral = function (types, makeRegexMatcher) { - - var getNumber = makeRegexMatcher(/^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/); - return function (tokenizer) { - var result; - if (result = getNumber(tokenizer)) { - return { - t: types.NUMBER_LITERAL, - v: result - }; - } - return null; - }; - }(config_types, parse_Tokenizer_utils_makeRegexMatcher); -var parse_Tokenizer_getExpression_shared_getName = function (makeRegexMatcher) { - - return makeRegexMatcher(/^[a-zA-Z_$][a-zA-Z_$0-9]*/); - }(parse_Tokenizer_utils_makeRegexMatcher); -var parse_Tokenizer_getExpression_shared_getKey = function (getStringLiteral, getNumberLiteral, getName) { - - var identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/; - return function (tokenizer) { - var token; - if (token = getStringLiteral(tokenizer)) { - return identifier.test(token.v) ? token.v : '"' + token.v.replace(/"/g, '\\"') + '"'; - } - if (token = getNumberLiteral(tokenizer)) { - return token.v; - } - if (token = getName(tokenizer)) { - return token; - } - }; - }(parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getNumberLiteral, parse_Tokenizer_getExpression_shared_getName); -var utils_parseJSON = function (getStringMatch, allowWhitespace, getStringLiteral, getKey) { - - var Tokenizer, specials, specialsPattern, numberPattern, placeholderPattern, placeholderAtStartPattern; - specials = { - 'true': true, - 'false': false, - 'undefined': undefined, - 'null': null - }; - specialsPattern = new RegExp('^(?:' + Object.keys(specials).join('|') + ')'); - numberPattern = /^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/; - placeholderPattern = /\$\{([^\}]+)\}/g; - placeholderAtStartPattern = /^\$\{([^\}]+)\}/; - Tokenizer = function (str, values) { - this.str = str; - this.values = values; - this.pos = 0; - this.result = this.getToken(); - }; - Tokenizer.prototype = { - remaining: function () { - return this.str.substring(this.pos); - }, - getStringMatch: getStringMatch, - getToken: function () { - this.allowWhitespace(); - return this.getPlaceholder() || this.getSpecial() || this.getNumber() || this.getString() || this.getObject() || this.getArray(); - }, - getPlaceholder: function () { - var match; - if (!this.values) { - return null; - } - if ((match = placeholderAtStartPattern.exec(this.remaining())) && this.values.hasOwnProperty(match[1])) { - this.pos += match[0].length; - return { v: this.values[match[1]] }; - } - }, - getSpecial: function () { - var match; - if (match = specialsPattern.exec(this.remaining())) { - this.pos += match[0].length; - return { v: specials[match[0]] }; - } - }, - getNumber: function () { - var match; - if (match = numberPattern.exec(this.remaining())) { - this.pos += match[0].length; - return { v: +match[0] }; - } - }, - getString: function () { - var stringLiteral = getStringLiteral(this), values; - if (stringLiteral && (values = this.values)) { - return { - v: stringLiteral.v.replace(placeholderPattern, function (match, $1) { - return values[$1] || $1; - }) - }; - } - return stringLiteral; - }, - getObject: function () { - var result, pair; - if (!this.getStringMatch('{')) { - return null; - } - result = {}; - while (pair = getKeyValuePair(this)) { - result[pair.key] = pair.value; - this.allowWhitespace(); - if (this.getStringMatch('}')) { - return { v: result }; - } - if (!this.getStringMatch(',')) { - return null; - } - } - return null; - }, - getArray: function () { - var result, valueToken; - if (!this.getStringMatch('[')) { - return null; - } - result = []; - while (valueToken = this.getToken()) { - result.push(valueToken.v); - if (this.getStringMatch(']')) { - return { v: result }; - } - if (!this.getStringMatch(',')) { - return null; - } - } - return null; - }, - allowWhitespace: allowWhitespace - }; - function getKeyValuePair(tokenizer) { - var key, valueToken, pair; - tokenizer.allowWhitespace(); - key = getKey(tokenizer); - if (!key) { - return null; - } - pair = { key: key }; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(':')) { - return null; - } - tokenizer.allowWhitespace(); - valueToken = tokenizer.getToken(); - if (!valueToken) { - return null; - } - pair.value = valueToken.v; - return pair; - } - return function (str, values) { - var tokenizer = new Tokenizer(str, values); - if (tokenizer.result) { - return { - value: tokenizer.result.v, - remaining: tokenizer.remaining() - }; - } - return null; - }; - }(parse_Tokenizer_utils_getStringMatch, parse_Tokenizer_utils_allowWhitespace, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral, parse_Tokenizer_getExpression_shared_getKey); -var render_StringFragment_Interpolator = function (types, teardown, initMustache, updateMustache, resolveMustache) { - - var StringInterpolator = function (options) { - this.type = types.INTERPOLATOR; - initMustache(this, options); - }; - StringInterpolator.prototype = { - update: updateMustache, - resolve: resolveMustache, - render: function (value) { - this.value = value; - this.parentFragment.bubble(); - }, - teardown: function () { - teardown(this); - }, - toString: function () { - if (this.value == undefined) { - return ''; - } - return stringify(this.value); - } - }; - return StringInterpolator; - function stringify(value) { - if (typeof value === 'string') { - return value; - } - return JSON.stringify(value); - } - }(config_types, shared_teardown, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache); -var render_StringFragment_Section = function (types, initMustache, updateMustache, resolveMustache, updateSection, teardown, circular) { - - var StringSection, StringFragment; - circular.push(function () { - StringFragment = circular.StringFragment; - }); - StringSection = function (options) { - this.type = types.SECTION; - this.fragments = []; - this.length = 0; - initMustache(this, options); - }; - StringSection.prototype = { - update: updateMustache, - resolve: resolveMustache, - teardown: function () { - this.teardownFragments(); - teardown(this); - }, - teardownFragments: function () { - while (this.fragments.length) { - this.fragments.shift().teardown(); - } - this.length = 0; - }, - bubble: function () { - this.value = this.fragments.join(''); - this.parentFragment.bubble(); - }, - render: function (value) { - var wrapped; - if (wrapped = this.root._wrapped[this.keypath]) { - value = wrapped.get(); - } - updateSection(this, value); - this.parentFragment.bubble(); - }, - createFragment: function (options) { - return new StringFragment(options); - }, - toString: function () { - return this.fragments.join(''); - } - }; - return StringSection; - }(config_types, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache, render_shared_updateSection, shared_teardown, circular); -var render_StringFragment_Text = function (types) { - - var StringText = function (text) { - this.type = types.TEXT; - this.text = text; - }; - StringText.prototype = { - toString: function () { - return this.text; - }, - teardown: function () { - } - }; - return StringText; - }(config_types); -var render_StringFragment_prototype_toArgsList = function (warn, parseJSON) { - - return function () { - var values, counter, jsonesque, guid, errorMessage, parsed, processItems; - if (!this.argsList || this.dirty) { - values = {}; - counter = 0; - guid = this.root._guid; - processItems = function (items) { - return items.map(function (item) { - var placeholderId, wrapped, value; - if (item.text) { - return item.text; - } - if (item.fragments) { - return item.fragments.map(function (fragment) { - return processItems(fragment.items); - }).join(''); - } - placeholderId = guid + '-' + counter++; - if (wrapped = item.root._wrapped[item.keypath]) { - value = wrapped.value; - } else { - value = item.value; - } - values[placeholderId] = value; - return '${' + placeholderId + '}'; - }).join(''); - }; - jsonesque = processItems(this.items); - parsed = parseJSON('[' + jsonesque + ']', values); - if (!parsed) { - errorMessage = 'Could not parse directive arguments (' + this.toString() + '). If you think this is a bug, please file an issue at http://github.com/RactiveJS/Ractive/issues'; - if (this.root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - this.argsList = [jsonesque]; - } - } else { - this.argsList = parsed.value; - } - this.dirty = false; - } - return this.argsList; - }; - }(utils_warn, utils_parseJSON); -var render_StringFragment__StringFragment = function (types, parseJSON, initFragment, Interpolator, Section, Text, toArgsList, circular) { - - var StringFragment = function (options) { - initFragment(this, options); - }; - StringFragment.prototype = { - createItem: function (options) { - if (typeof options.descriptor === 'string') { - return new Text(options.descriptor); - } - switch (options.descriptor.t) { - case types.INTERPOLATOR: - return new Interpolator(options); - case types.TRIPLE: - return new Interpolator(options); - case types.SECTION: - return new Section(options); - default: - throw 'Something went wrong in a rather interesting way'; - } - }, - bubble: function () { - this.dirty = true; - this.owner.bubble(); - }, - teardown: function () { - var numItems, i; - numItems = this.items.length; - for (i = 0; i < numItems; i += 1) { - this.items[i].teardown(); - } - }, - getValue: function () { - var value; - if (this.items.length === 1 && this.items[0].type === types.INTERPOLATOR) { - value = this.items[0].value; - if (value !== undefined) { - return value; - } - } - return this.toString(); - }, - isSimple: function () { - var i, item, containsInterpolator; - if (this.simple !== undefined) { - return this.simple; - } - i = this.items.length; - while (i--) { - item = this.items[i]; - if (item.type === types.TEXT) { - continue; - } - if (item.type === types.INTERPOLATOR) { - if (containsInterpolator) { - return false; - } else { - containsInterpolator = true; - continue; - } - } - return this.simple = false; - } - return this.simple = true; - }, - toString: function () { - return this.items.join(''); - }, - toJSON: function () { - var value = this.getValue(), parsed; - if (typeof value === 'string') { - parsed = parseJSON(value); - value = parsed ? parsed.value : value; - } - return value; - }, - toArgsList: toArgsList - }; - circular.StringFragment = StringFragment; - return StringFragment; - }(config_types, utils_parseJSON, render_shared_initFragment, render_StringFragment_Interpolator, render_StringFragment_Section, render_StringFragment_Text, render_StringFragment_prototype_toArgsList, circular); -var render_DomFragment_Attribute__Attribute = function (types, determineNameAndNamespace, setStaticAttribute, determinePropertyName, bind, update, StringFragment) { - - var DomAttribute = function (options) { - this.type = types.ATTRIBUTE; - this.element = options.element; - determineNameAndNamespace(this, options.name); - if (options.value === null || typeof options.value === 'string') { - setStaticAttribute(this, options); - return; - } - this.root = options.root; - this.pNode = options.pNode; - this.parentFragment = this.element.parentFragment; - this.fragment = new StringFragment({ - descriptor: options.value, - root: this.root, - owner: this, - contextStack: options.contextStack - }); - if (!this.pNode) { - return; - } - if (this.name === 'value') { - this.isValueAttribute = true; - if (this.pNode.tagName === 'INPUT' && this.pNode.type === 'file') { - this.isFileInputValue = true; - } - } - determinePropertyName(this, options); - this.selfUpdating = this.fragment.isSimple(); - this.ready = true; - }; - DomAttribute.prototype = { - bind: bind, - update: update, - updateBindings: function () { - this.keypath = this.interpolator.keypath || this.interpolator.ref; - if (this.propertyName === 'name') { - this.pNode.name = '{{' + this.keypath + '}}'; - } - }, - teardown: function () { - var i; - if (this.boundEvents) { - i = this.boundEvents.length; - while (i--) { - this.pNode.removeEventListener(this.boundEvents[i], this.updateModel, false); - } - } - if (this.fragment) { - this.fragment.teardown(); - } - }, - bubble: function () { - if (this.selfUpdating) { - this.update(); - } else if (!this.deferred && this.ready) { - this.root._deferred.attrs.push(this); - this.deferred = true; - } - }, - toString: function () { - var str; - if (this.value === null) { - return this.name; - } - if (!this.fragment) { - return this.name + '=' + JSON.stringify(this.value); - } - str = this.fragment.toString(); - return this.name + '=' + JSON.stringify(str); - } - }; - return DomAttribute; - }(config_types, render_DomFragment_Attribute_helpers_determineNameAndNamespace, render_DomFragment_Attribute_helpers_setStaticAttribute, render_DomFragment_Attribute_helpers_determinePropertyName, render_DomFragment_Attribute_prototype_bind, render_DomFragment_Attribute_prototype_update, render_StringFragment__StringFragment); -var render_DomFragment_Element_initialise_createElementAttributes = function (DomAttribute) { - - return function (element, attributes) { - var attrName, attrValue, attr; - element.attributes = []; - for (attrName in attributes) { - if (attributes.hasOwnProperty(attrName)) { - attrValue = attributes[attrName]; - attr = new DomAttribute({ - element: element, - name: attrName, - value: attrValue, - root: element.root, - pNode: element.node, - contextStack: element.parentFragment.contextStack - }); - element.attributes[element.attributes.length] = element.attributes[attrName] = attr; - if (attrName !== 'name') { - attr.update(); - } - } - } - return element.attributes; - }; - }(render_DomFragment_Attribute__Attribute); -var render_DomFragment_Element_initialise_appendElementChildren = function (warn, namespaces, StringFragment, circular) { - - var DomFragment, updateCss, updateScript; - circular.push(function () { - DomFragment = circular.DomFragment; - }); - updateCss = function () { - var node = this.node, content = this.fragment.toString(); - if (node.styleSheet) { - node.styleSheet.cssText = content; - } - node.innerHTML = content; - }; - updateScript = function () { - if (!this.node.type || this.node.type === 'text/javascript') { - warn('Script tag was updated. This does not cause the code to be re-evaluated!'); - } - this.node.innerHTML = this.fragment.toString(); - }; - return function (element, node, descriptor, docFrag) { - var liveQueries, i, selector, queryAllResult, j; - if (element.lcName === 'script' || element.lcName === 'style') { - element.fragment = new StringFragment({ - descriptor: descriptor.f, - root: element.root, - contextStack: element.parentFragment.contextStack, - owner: element - }); - if (docFrag) { - if (element.lcName === 'script') { - element.bubble = updateScript; - element.node.innerHTML = element.fragment.toString(); - } else { - element.bubble = updateCss; - element.bubble(); - } - } - return; - } - if (typeof descriptor.f === 'string' && (!node || (!node.namespaceURI || node.namespaceURI === namespaces.html))) { - element.html = descriptor.f; - if (docFrag) { - node.innerHTML = element.html; - liveQueries = element.root._liveQueries; - i = liveQueries.length; - while (i--) { - selector = liveQueries[i]; - if ((queryAllResult = node.querySelectorAll(selector)) && (j = queryAllResult.length)) { - (element.liveQueries || (element.liveQueries = [])).push(selector); - element.liveQueries[selector] = []; - while (j--) { - element.liveQueries[selector][j] = queryAllResult[j]; - } - } - } - } - } else { - element.fragment = new DomFragment({ - descriptor: descriptor.f, - root: element.root, - pNode: node, - contextStack: element.parentFragment.contextStack, - owner: element - }); - if (docFrag) { - node.appendChild(element.fragment.docFrag); - } - } - }; - }(utils_warn, config_namespaces, render_StringFragment__StringFragment, circular); -var render_DomFragment_Element_initialise_decorate_Decorator = function (warn, StringFragment) { - - var Decorator = function (descriptor, root, owner, contextStack) { - var name, fragment, errorMessage; - this.root = root; - this.node = owner.node; - name = descriptor.n || descriptor; - if (typeof name !== 'string') { - fragment = new StringFragment({ - descriptor: name, - root: this.root, - owner: owner, - contextStack: contextStack - }); - name = fragment.toString(); - fragment.teardown(); - } - if (descriptor.a) { - this.params = descriptor.a; - } else if (descriptor.d) { - fragment = new StringFragment({ - descriptor: descriptor.d, - root: this.root, - owner: owner, - contextStack: contextStack - }); - this.params = fragment.toArgsList(); - fragment.teardown(); - } - this.fn = root.decorators[name]; - if (!this.fn) { - errorMessage = 'Missing "' + name + '" decorator. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#decorators'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - } - }; - Decorator.prototype = { - init: function () { - var result, args; - if (this.params) { - args = [this.node].concat(this.params); - result = this.fn.apply(this.root, args); - } else { - result = this.fn.call(this.root, this.node); - } - if (!result || !result.teardown) { - throw new Error('Decorator definition must return an object with a teardown method'); - } - this.teardown = result.teardown; - } - }; - return Decorator; - }(utils_warn, render_StringFragment__StringFragment); -var render_DomFragment_Element_initialise_decorate__decorate = function (Decorator) { - - return function (descriptor, root, owner, contextStack) { - owner.decorator = new Decorator(descriptor, root, owner, contextStack); - if (owner.decorator.fn) { - root._deferred.decorators.push(owner.decorator); - } - }; - }(render_DomFragment_Element_initialise_decorate_Decorator); -var render_DomFragment_Element_initialise_addEventProxies_addEventProxy = function (warn, StringFragment) { - - var addEventProxy, MasterEventHandler, ProxyEvent, firePlainEvent, fireEventWithArgs, fireEventWithDynamicArgs, customHandlers, genericHandler, getCustomHandler; - addEventProxy = function (element, triggerEventName, proxyDescriptor, contextStack, indexRefs) { - var events, master; - events = element.node._ractive.events; - master = events[triggerEventName] || (events[triggerEventName] = new MasterEventHandler(element, triggerEventName, contextStack, indexRefs)); - master.add(proxyDescriptor); - }; - MasterEventHandler = function (element, eventName, contextStack) { - var definition; - this.element = element; - this.root = element.root; - this.node = element.node; - this.name = eventName; - this.contextStack = contextStack; - this.proxies = []; - if (definition = this.root.events[eventName]) { - this.custom = definition(this.node, getCustomHandler(eventName)); - } else { - if (!('on' + eventName in this.node)) { - warn('Missing "' + this.name + '" event. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#events'); - } - this.node.addEventListener(eventName, genericHandler, false); - } - }; - MasterEventHandler.prototype = { - add: function (proxy) { - this.proxies[this.proxies.length] = new ProxyEvent(this.element, this.root, proxy, this.contextStack); - }, - teardown: function () { - var i; - if (this.custom) { - this.custom.teardown(); - } else { - this.node.removeEventListener(this.name, genericHandler, false); - } - i = this.proxies.length; - while (i--) { - this.proxies[i].teardown(); - } - }, - fire: function (event) { - var i = this.proxies.length; - while (i--) { - this.proxies[i].fire(event); - } - } - }; - ProxyEvent = function (element, ractive, descriptor, contextStack) { - var name; - this.root = ractive; - name = descriptor.n || descriptor; - if (typeof name === 'string') { - this.n = name; - } else { - this.n = new StringFragment({ - descriptor: descriptor.n, - root: this.root, - owner: element, - contextStack: contextStack - }); - } - if (descriptor.a) { - this.a = descriptor.a; - this.fire = fireEventWithArgs; - return; - } - if (descriptor.d) { - this.d = new StringFragment({ - descriptor: descriptor.d, - root: this.root, - owner: element, - contextStack: contextStack - }); - this.fire = fireEventWithDynamicArgs; - return; - } - this.fire = firePlainEvent; - }; - ProxyEvent.prototype = { - teardown: function () { - if (this.n.teardown) { - this.n.teardown(); - } - if (this.d) { - this.d.teardown(); - } - }, - bubble: function () { - } - }; - firePlainEvent = function (event) { - this.root.fire(this.n.toString(), event); - }; - fireEventWithArgs = function (event) { - this.root.fire.apply(this.root, [ - this.n.toString(), - event - ].concat(this.a)); - }; - fireEventWithDynamicArgs = function (event) { - var args = this.d.toArgsList(); - if (typeof args === 'string') { - args = args.substr(1, args.length - 2); - } - this.root.fire.apply(this.root, [ - this.n.toString(), - event - ].concat(args)); - }; - genericHandler = function (event) { - var storage = this._ractive; - storage.events[event.type].fire({ - node: this, - original: event, - index: storage.index, - keypath: storage.keypath, - context: storage.root.get(storage.keypath) - }); - }; - customHandlers = {}; - getCustomHandler = function (eventName) { - if (customHandlers[eventName]) { - return customHandlers[eventName]; - } - return customHandlers[eventName] = function (event) { - var storage = event.node._ractive; - event.index = storage.index; - event.keypath = storage.keypath; - event.context = storage.root.get(storage.keypath); - storage.events[eventName].fire(event); - }; - }; - return addEventProxy; - }(utils_warn, render_StringFragment__StringFragment); -var render_DomFragment_Element_initialise_addEventProxies__addEventProxies = function (addEventProxy) { - - return function (element, proxies) { - var i, eventName, eventNames; - for (eventName in proxies) { - if (proxies.hasOwnProperty(eventName)) { - eventNames = eventName.split('-'); - i = eventNames.length; - while (i--) { - addEventProxy(element, eventNames[i], proxies[eventName], element.parentFragment.contextStack); - } - } - } - }; - }(render_DomFragment_Element_initialise_addEventProxies_addEventProxy); -var render_DomFragment_Element_initialise_updateLiveQueries = function () { - - return function (element) { - var ractive, liveQueries, i, selector, query; - ractive = element.root; - liveQueries = ractive._liveQueries; - i = liveQueries.length; - while (i--) { - selector = liveQueries[i]; - query = liveQueries[selector]; - if (query._test(element)) { - (element.liveQueries || (element.liveQueries = [])).push(selector); - element.liveQueries[selector] = [element.node]; - } - } - }; - }(); -var utils_camelCase = function () { - - return function (hyphenatedStr) { - return hyphenatedStr.replace(/-([a-zA-Z])/g, function (match, $1) { - return $1.toUpperCase(); - }); - }; - }(); -var utils_fillGaps = function () { - - return function (target, source) { - var key; - for (key in source) { - if (source.hasOwnProperty(key) && !target.hasOwnProperty(key)) { - target[key] = source[key]; - } - } - return target; - }; - }(); -var render_DomFragment_Element_shared_executeTransition_Transition = function (isClient, createElement, warn, isNumeric, isArray, camelCase, fillGaps, StringFragment) { - - var Transition, testStyle, vendors, vendorPattern, unprefixPattern, prefixCache, CSS_TRANSITIONS_ENABLED, TRANSITION, TRANSITION_DURATION, TRANSITION_PROPERTY, TRANSITION_TIMING_FUNCTION, TRANSITIONEND; - if (!isClient) { - return; - } - testStyle = createElement('div').style; - (function () { - if (testStyle.transition !== undefined) { - TRANSITION = 'transition'; - TRANSITIONEND = 'transitionend'; - CSS_TRANSITIONS_ENABLED = true; - } else if (testStyle.webkitTransition !== undefined) { - TRANSITION = 'webkitTransition'; - TRANSITIONEND = 'webkitTransitionEnd'; - CSS_TRANSITIONS_ENABLED = true; - } else { - CSS_TRANSITIONS_ENABLED = false; - } - }()); - if (TRANSITION) { - TRANSITION_DURATION = TRANSITION + 'Duration'; - TRANSITION_PROPERTY = TRANSITION + 'Property'; - TRANSITION_TIMING_FUNCTION = TRANSITION + 'TimingFunction'; - } - Transition = function (descriptor, root, owner, contextStack, isIntro) { - var t = this, name, fragment, errorMessage; - this.root = root; - this.node = owner.node; - this.isIntro = isIntro; - this.originalStyle = this.node.getAttribute('style'); - this.complete = function (noReset) { - if (!noReset && t.isIntro) { - t.resetStyle(); - } - t._manager.pop(t.node); - t.node._ractive.transition = null; - }; - name = descriptor.n || descriptor; - if (typeof name !== 'string') { - fragment = new StringFragment({ - descriptor: name, - root: this.root, - owner: owner, - contextStack: contextStack - }); - name = fragment.toString(); - fragment.teardown(); - } - this.name = name; - if (descriptor.a) { - this.params = descriptor.a; - } else if (descriptor.d) { - fragment = new StringFragment({ - descriptor: descriptor.d, - root: this.root, - owner: owner, - contextStack: contextStack - }); - this.params = fragment.toArgsList(); - fragment.teardown(); - } - this._fn = root.transitions[name]; - if (!this._fn) { - errorMessage = 'Missing "' + name + '" transition. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#transitions'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - return; - } - }; - Transition.prototype = { - init: function () { - if (this._inited) { - throw new Error('Cannot initialize a transition more than once'); - } - this._inited = true; - this._fn.apply(this.root, [this].concat(this.params)); - }, - getStyle: function (props) { - var computedStyle, styles, i, prop, value; - computedStyle = window.getComputedStyle(this.node); - if (typeof props === 'string') { - value = computedStyle[prefix(props)]; - if (value === '0px') { - value = 0; - } - return value; - } - if (!isArray(props)) { - throw new Error('Transition#getStyle must be passed a string, or an array of strings representing CSS properties'); - } - styles = {}; - i = props.length; - while (i--) { - prop = props[i]; - value = computedStyle[prefix(prop)]; - if (value === '0px') { - value = 0; - } - styles[prop] = value; - } - return styles; - }, - setStyle: function (style, value) { - var prop; - if (typeof style === 'string') { - this.node.style[prefix(style)] = value; - } else { - for (prop in style) { - if (style.hasOwnProperty(prop)) { - this.node.style[prefix(prop)] = style[prop]; - } - } - } - return this; - }, - animateStyle: function (style, value, options, complete) { - var t = this, propertyNames, changedProperties, computedStyle, current, to, from, transitionEndHandler, i, prop; - if (typeof style === 'string') { - to = {}; - to[style] = value; - } else { - to = style; - complete = options; - options = value; - } - if (!options) { - warn('The "' + t.name + '" transition does not supply an options object to `t.animateStyle()`. This will break in a future version of Ractive. For more info see https://github.com/RactiveJS/Ractive/issues/340'); - options = t; - complete = t.complete; - } - if (!options.duration) { - t.setStyle(to); - if (complete) { - complete(); - } - } - propertyNames = Object.keys(to); - changedProperties = []; - computedStyle = window.getComputedStyle(t.node); - from = {}; - i = propertyNames.length; - while (i--) { - prop = propertyNames[i]; - current = computedStyle[prefix(prop)]; - if (current === '0px') { - current = 0; - } - if (current != to[prop]) { - changedProperties[changedProperties.length] = prop; - t.node.style[prefix(prop)] = current; - } - } - if (!changedProperties.length) { - if (complete) { - complete(); - } - return; - } - setTimeout(function () { - t.node.style[TRANSITION_PROPERTY] = propertyNames.map(prefix).map(hyphenate).join(','); - t.node.style[TRANSITION_TIMING_FUNCTION] = hyphenate(options.easing || 'linear'); - t.node.style[TRANSITION_DURATION] = options.duration / 1000 + 's'; - transitionEndHandler = function (event) { - var index; - index = changedProperties.indexOf(camelCase(unprefix(event.propertyName))); - if (index !== -1) { - changedProperties.splice(index, 1); - } - if (changedProperties.length) { - return; - } - t.root.fire(t.name + ':end'); - t.node.removeEventListener(TRANSITIONEND, transitionEndHandler, false); - if (complete) { - complete(); - } - }; - t.node.addEventListener(TRANSITIONEND, transitionEndHandler, false); - setTimeout(function () { - var i = changedProperties.length; - while (i--) { - prop = changedProperties[i]; - t.node.style[prefix(prop)] = to[prop]; - } - }, 0); - }, options.delay || 0); - }, - resetStyle: function () { - if (this.originalStyle) { - this.node.setAttribute('style', this.originalStyle); - } else { - this.node.getAttribute('style'); - this.node.removeAttribute('style'); - } - }, - processParams: function (params, defaults) { - if (typeof params === 'number') { - params = { duration: params }; - } else if (typeof params === 'string') { - if (params === 'slow') { - params = { duration: 600 }; - } else if (params === 'fast') { - params = { duration: 200 }; - } else { - params = { duration: 400 }; - } - } else if (!params) { - params = {}; - } - return fillGaps(params, defaults); - } - }; - vendors = [ - 'o', - 'ms', - 'moz', - 'webkit' - ]; - vendorPattern = new RegExp('^(?:' + vendors.join('|') + ')([A-Z])'); - unprefixPattern = new RegExp('^-(?:' + vendors.join('|') + ')-'); - prefixCache = {}; - function prefix(prop) { - var i, vendor, capped; - if (!prefixCache[prop]) { - if (testStyle[prop] !== undefined) { - prefixCache[prop] = prop; - } else { - capped = prop.charAt(0).toUpperCase() + prop.substring(1); - i = vendors.length; - while (i--) { - vendor = vendors[i]; - if (testStyle[vendor + capped] !== undefined) { - prefixCache[prop] = vendor + capped; - break; - } - } - } - } - return prefixCache[prop]; - } - function unprefix(prop) { - return prop.replace(unprefixPattern, ''); - } - function hyphenate(str) { - var hyphenated; - if (vendorPattern.test(str)) { - str = '-' + str; - } - hyphenated = str.replace(/[A-Z]/g, function (match) { - return '-' + match.toLowerCase(); - }); - return hyphenated; - } - return Transition; - }(config_isClient, utils_createElement, utils_warn, utils_isNumeric, utils_isArray, utils_camelCase, utils_fillGaps, render_StringFragment__StringFragment); -var render_DomFragment_Element_shared_executeTransition__executeTransition = function (warn, Transition) { - - return function (descriptor, root, owner, contextStack, isIntro) { - var transition, node, oldTransition; - if (!root.transitionsEnabled || root._parent && !root._parent.transitionsEnabled) { - return; - } - transition = new Transition(descriptor, root, owner, contextStack, isIntro); - if (transition._fn) { - node = transition.node; - transition._manager = root._transitionManager; - if (oldTransition = node._ractive.transition) { - oldTransition.complete(); - } - node._ractive.transition = transition; - transition._manager.push(node); - if (isIntro) { - root._deferred.transitions.push(transition); - } else { - transition.init(); - } - } - }; - }(utils_warn, render_DomFragment_Element_shared_executeTransition_Transition); -var render_DomFragment_Element_initialise__initialise = function (types, namespaces, create, defineProperty, matches, warn, createElement, getElementNamespace, createElementAttributes, appendElementChildren, decorate, addEventProxies, updateLiveQueries, executeTransition, enforceCase) { - - return function (element, options, docFrag) { - var parentFragment, pNode, contextStack, descriptor, namespace, name, attributes, width, height, loadHandler, root, selectBinding, errorMessage; - element.type = types.ELEMENT; - parentFragment = element.parentFragment = options.parentFragment; - pNode = parentFragment.pNode; - contextStack = parentFragment.contextStack; - descriptor = element.descriptor = options.descriptor; - element.root = root = parentFragment.root; - element.index = options.index; - element.lcName = descriptor.e.toLowerCase(); - element.eventListeners = []; - element.customEventListeners = []; - if (pNode) { - namespace = element.namespace = getElementNamespace(descriptor, pNode); - name = namespace !== namespaces.html ? enforceCase(descriptor.e) : descriptor.e; - element.node = createElement(name, namespace); - defineProperty(element.node, '_ractive', { - value: { - proxy: element, - keypath: contextStack.length ? contextStack[contextStack.length - 1] : '', - index: parentFragment.indexRefs, - events: create(null), - root: root - } - }); - } - attributes = createElementAttributes(element, descriptor.a); - if (descriptor.f) { - if (element.node && element.node.getAttribute('contenteditable')) { - if (element.node.innerHTML) { - errorMessage = 'A pre-populated contenteditable element should not have children'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - } - } - appendElementChildren(element, element.node, descriptor, docFrag); - } - if (docFrag && descriptor.v) { - addEventProxies(element, descriptor.v); - } - if (docFrag) { - if (root.twoway) { - element.bind(); - if (element.node.getAttribute('contenteditable') && element.node._ractive.binding) { - element.node._ractive.binding.update(); - } - } - if (attributes.name && !attributes.name.twoway) { - attributes.name.update(); - } - if (element.node.tagName === 'IMG' && ((width = element.attributes.width) || (height = element.attributes.height))) { - element.node.addEventListener('load', loadHandler = function () { - if (width) { - element.node.width = width.value; - } - if (height) { - element.node.height = height.value; - } - element.node.removeEventListener('load', loadHandler, false); - }, false); - } - docFrag.appendChild(element.node); - if (descriptor.o) { - decorate(descriptor.o, root, element, contextStack); - } - if (descriptor.t1) { - executeTransition(descriptor.t1, root, element, contextStack, true); - } - if (element.node.tagName === 'OPTION') { - if (pNode.tagName === 'SELECT' && (selectBinding = pNode._ractive.binding)) { - selectBinding.deferUpdate(); - } - if (element.node._ractive.value == pNode._ractive.value) { - element.node.selected = true; - } - } - if (element.node.autofocus) { - root._deferred.focusable = element.node; - } - } - updateLiveQueries(element); - }; - }(config_types, config_namespaces, utils_create, utils_defineProperty, utils_matches, utils_warn, utils_createElement, render_DomFragment_Element_initialise_getElementNamespace, render_DomFragment_Element_initialise_createElementAttributes, render_DomFragment_Element_initialise_appendElementChildren, render_DomFragment_Element_initialise_decorate__decorate, render_DomFragment_Element_initialise_addEventProxies__addEventProxies, render_DomFragment_Element_initialise_updateLiveQueries, render_DomFragment_Element_shared_executeTransition__executeTransition, render_DomFragment_shared_enforceCase); -var render_DomFragment_Element_prototype_teardown = function (executeTransition) { - - return function (destroy) { - var eventName, binding, bindings, i, liveQueries, selector, query, nodesToRemove, j; - if (this.fragment) { - this.fragment.teardown(false); - } - while (this.attributes.length) { - this.attributes.pop().teardown(); - } - if (this.node) { - for (eventName in this.node._ractive.events) { - this.node._ractive.events[eventName].teardown(); - } - if (binding = this.node._ractive.binding) { - binding.teardown(); - bindings = this.root._twowayBindings[binding.attr.keypath]; - bindings.splice(bindings.indexOf(binding), 1); - } - } - if (this.decorator) { - this.decorator.teardown(); - } - if (this.descriptor.t2) { - executeTransition(this.descriptor.t2, this.root, this, this.parentFragment.contextStack, false); - } - if (destroy) { - this.root._transitionManager.detachWhenReady(this); - } - if (liveQueries = this.liveQueries) { - i = liveQueries.length; - while (i--) { - selector = liveQueries[i]; - if (nodesToRemove = this.liveQueries[selector]) { - j = nodesToRemove.length; - query = this.root._liveQueries[selector]; - while (j--) { - query._remove(nodesToRemove[j]); - } - } - } - } - }; - }(render_DomFragment_Element_shared_executeTransition__executeTransition); -var config_voidElementNames = function () { - - return 'area base br col command doctype embed hr img input keygen link meta param source track wbr'.split(' '); - }(); -var render_DomFragment_Element_prototype_toString = function (voidElementNames) { - - return function () { - var str, i, len; - str = '<' + (this.descriptor.y ? '!doctype' : this.descriptor.e); - len = this.attributes.length; - for (i = 0; i < len; i += 1) { - str += ' ' + this.attributes[i].toString(); - } - str += '>'; - if (this.html) { - str += this.html; - } else if (this.fragment) { - str += this.fragment.toString(); - } - if (voidElementNames.indexOf(this.descriptor.e) === -1) { - str += '' + this.descriptor.e + '>'; - } - return str; - }; - }(config_voidElementNames); -var render_DomFragment_Element_prototype_find = function (matches) { - - return function (selector) { - var queryResult; - if (matches(this.node, selector)) { - return this.node; - } - if (this.html && (queryResult = this.node.querySelector(selector))) { - return queryResult; - } - if (this.fragment && this.fragment.find) { - return this.fragment.find(selector); - } - }; - }(utils_matches); -var render_DomFragment_Element_prototype_findAll = function () { - - return function (selector, query) { - var queryAllResult, i, numNodes, node, registeredNodes; - if (query._test(this, true) && query.live) { - (this.liveQueries || (this.liveQueries = [])).push(selector); - this.liveQueries[selector] = [this.node]; - } - if (this.html && (queryAllResult = this.node.querySelectorAll(selector)) && (numNodes = queryAllResult.length)) { - if (query.live) { - if (!this.liveQueries[selector]) { - (this.liveQueries || (this.liveQueries = [])).push(selector); - this.liveQueries[selector] = []; - } - registeredNodes = this.liveQueries[selector]; - } - for (i = 0; i < numNodes; i += 1) { - node = queryAllResult[i]; - query.push(node); - if (query.live) { - registeredNodes.push(node); - } - } - } - if (this.fragment) { - this.fragment.findAll(selector, query); - } - }; - }(); -var render_DomFragment_Element_prototype_findComponent = function () { - - return function (selector) { - if (this.fragment) { - return this.fragment.findComponent(selector); - } - }; - }(); -var render_DomFragment_Element_prototype_findAllComponents = function () { - - return function (selector, query) { - if (this.fragment) { - this.fragment.findAllComponents(selector, query); - } - }; - }(); -var render_DomFragment_Element_prototype_bind = function () { - - return function () { - var attributes = this.attributes; - if (!this.node) { - return; - } - if (this.binding) { - this.binding.teardown(); - this.binding = null; - } - if (this.node.getAttribute('contenteditable') && attributes.value && attributes.value.bind()) { - return; - } - switch (this.descriptor.e) { - case 'select': - case 'textarea': - if (attributes.value) { - attributes.value.bind(); - } - return; - case 'input': - if (this.node.type === 'radio' || this.node.type === 'checkbox') { - if (attributes.name && attributes.name.bind()) { - return; - } - if (attributes.checked && attributes.checked.bind()) { - return; - } - } - if (attributes.value && attributes.value.bind()) { - return; - } - } - }; - }(); -var render_DomFragment_Element__Element = function (initialise, teardown, toString, find, findAll, findComponent, findAllComponents, bind) { - - var DomElement = function (options, docFrag) { - initialise(this, options, docFrag); - }; - DomElement.prototype = { - detach: function () { - if (this.node) { - if (this.node.parentNode) { - this.node.parentNode.removeChild(this.node); - } - return this.node; - } - }, - teardown: teardown, - firstNode: function () { - return this.node; - }, - findNextNode: function () { - return null; - }, - bubble: function () { - }, - toString: toString, - find: find, - findAll: findAll, - findComponent: findComponent, - findAllComponents: findAllComponents, - bind: bind - }; - return DomElement; - }(render_DomFragment_Element_initialise__initialise, render_DomFragment_Element_prototype_teardown, render_DomFragment_Element_prototype_toString, render_DomFragment_Element_prototype_find, render_DomFragment_Element_prototype_findAll, render_DomFragment_Element_prototype_findComponent, render_DomFragment_Element_prototype_findAllComponents, render_DomFragment_Element_prototype_bind); -var config_errors = { missingParser: 'Missing Ractive.parse - cannot parse template. Either preparse or use the version that includes the parser' }; -var registries_partials = {}; -var parse_utils_stripHtmlComments = function () { - - return function (html) { - var commentStart, commentEnd, processed; - processed = ''; - while (html.length) { - commentStart = html.indexOf(''); - if (commentStart === -1 && commentEnd === -1) { - processed += html; - break; - } - if (commentStart !== -1 && commentEnd === -1) { - throw 'Illegal HTML - expected closing comment sequence (\'-->\')'; - } - if (commentEnd !== -1 && commentStart === -1 || commentEnd < commentStart) { - throw 'Illegal HTML - unexpected closing comment sequence (\'-->\')'; - } - processed += html.substr(0, commentStart); - html = html.substring(commentEnd + 3); - } - return processed; - }; - }(); -var parse_utils_stripStandalones = function (types) { - - return function (tokens) { - var i, current, backOne, backTwo, leadingLinebreak, trailingLinebreak; - leadingLinebreak = /^\s*\r?\n/; - trailingLinebreak = /\r?\n\s*$/; - for (i = 2; i < tokens.length; i += 1) { - current = tokens[i]; - backOne = tokens[i - 1]; - backTwo = tokens[i - 2]; - if (current.type === types.TEXT && backOne.type === types.MUSTACHE && backTwo.type === types.TEXT) { - if (trailingLinebreak.test(backTwo.value) && leadingLinebreak.test(current.value)) { - if (backOne.mustacheType !== types.INTERPOLATOR && backOne.mustacheType !== types.TRIPLE) { - backTwo.value = backTwo.value.replace(trailingLinebreak, '\n'); - } - current.value = current.value.replace(leadingLinebreak, ''); - if (current.value === '') { - tokens.splice(i--, 1); - } - } - } - } - return tokens; - }; - }(config_types); -var parse_utils_stripCommentTokens = function (types) { - - return function (tokens) { - var i, current, previous, next; - for (i = 0; i < tokens.length; i += 1) { - current = tokens[i]; - previous = tokens[i - 1]; - next = tokens[i + 1]; - if (current.mustacheType === types.COMMENT || current.mustacheType === types.DELIMCHANGE) { - tokens.splice(i, 1); - if (previous && next) { - if (previous.type === types.TEXT && next.type === types.TEXT) { - previous.value += next.value; - tokens.splice(i, 1); - } - } - i -= 1; - } - } - return tokens; - }; - }(config_types); -var parse_Tokenizer_getMustache_getDelimiterChange = function (makeRegexMatcher) { - - var getDelimiter = makeRegexMatcher(/^[^\s=]+/); - return function (tokenizer) { - var start, opening, closing; - if (!tokenizer.getStringMatch('=')) { - return null; - } - start = tokenizer.pos; - tokenizer.allowWhitespace(); - opening = getDelimiter(tokenizer); - if (!opening) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - closing = getDelimiter(tokenizer); - if (!closing) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch('=')) { - tokenizer.pos = start; - return null; - } - return [ - opening, - closing - ]; - }; - }(parse_Tokenizer_utils_makeRegexMatcher); -var parse_Tokenizer_getMustache_getMustacheType = function (types) { - - var mustacheTypes = { - '#': types.SECTION, - '^': types.INVERTED, - '/': types.CLOSING, - '>': types.PARTIAL, - '!': types.COMMENT, - '&': types.TRIPLE - }; - return function (tokenizer) { - var type = mustacheTypes[tokenizer.str.charAt(tokenizer.pos)]; - if (!type) { - return null; - } - tokenizer.pos += 1; - return type; - }; - }(config_types); -var parse_Tokenizer_getMustache_getMustacheContent = function (types, makeRegexMatcher, getMustacheType) { - - var getIndexRef = makeRegexMatcher(/^\s*:\s*([a-zA-Z_$][a-zA-Z_$0-9]*)/), arrayMember = /^[0-9][1-9]*$/; - return function (tokenizer, isTriple) { - var start, mustache, type, expr, i, remaining, index; - start = tokenizer.pos; - mustache = { type: isTriple ? types.TRIPLE : types.MUSTACHE }; - if (!isTriple) { - if (expr = tokenizer.getExpression()) { - mustache.mustacheType = types.INTERPOLATOR; - tokenizer.allowWhitespace(); - if (tokenizer.getStringMatch(tokenizer.delimiters[1])) { - tokenizer.pos -= tokenizer.delimiters[1].length; - } else { - tokenizer.pos = start; - expr = null; - } - } - if (!expr) { - type = getMustacheType(tokenizer); - if (type === types.TRIPLE) { - mustache = { type: types.TRIPLE }; - } else { - mustache.mustacheType = type || types.INTERPOLATOR; - } - if (type === types.COMMENT || type === types.CLOSING) { - remaining = tokenizer.remaining(); - index = remaining.indexOf(tokenizer.delimiters[1]); - if (index !== -1) { - mustache.ref = remaining.substr(0, index); - tokenizer.pos += index; - return mustache; - } - } - } - } - if (!expr) { - tokenizer.allowWhitespace(); - expr = tokenizer.getExpression(); - } - while (expr.t === types.BRACKETED && expr.x) { - expr = expr.x; - } - if (expr.t === types.REFERENCE) { - mustache.ref = expr.n; - } else if (expr.t === types.NUMBER_LITERAL && arrayMember.test(expr.v)) { - mustache.ref = expr.v; - } else { - mustache.expression = expr; - } - i = getIndexRef(tokenizer); - if (i !== null) { - mustache.indexRef = i; - } - return mustache; - }; - }(config_types, parse_Tokenizer_utils_makeRegexMatcher, parse_Tokenizer_getMustache_getMustacheType); -var parse_Tokenizer_getMustache__getMustache = function (types, getDelimiterChange, getMustacheContent) { - - return function () { - var seekTripleFirst = this.tripleDelimiters[0].length > this.delimiters[0].length; - return getMustache(this, seekTripleFirst) || getMustache(this, !seekTripleFirst); - }; - function getMustache(tokenizer, seekTriple) { - var start = tokenizer.pos, content, delimiters; - delimiters = seekTriple ? tokenizer.tripleDelimiters : tokenizer.delimiters; - if (!tokenizer.getStringMatch(delimiters[0])) { - return null; - } - content = getDelimiterChange(tokenizer); - if (content) { - if (!tokenizer.getStringMatch(delimiters[1])) { - tokenizer.pos = start; - return null; - } - tokenizer[seekTriple ? 'tripleDelimiters' : 'delimiters'] = content; - return { - type: types.MUSTACHE, - mustacheType: types.DELIMCHANGE - }; - } - tokenizer.allowWhitespace(); - content = getMustacheContent(tokenizer, seekTriple); - if (content === null) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(delimiters[1])) { - tokenizer.pos = start; - return null; - } - return content; - } - }(config_types, parse_Tokenizer_getMustache_getDelimiterChange, parse_Tokenizer_getMustache_getMustacheContent); -var parse_Tokenizer_getComment_getComment = function (types) { - - return function () { - var content, remaining, endIndex; - if (!this.getStringMatch(''); - if (endIndex === -1) { - throw new Error('Unexpected end of input (expected "-->" to close comment)'); - } - content = remaining.substr(0, endIndex); - this.pos += endIndex + 3; - return { - type: types.COMMENT, - content: content - }; - }; - }(config_types); -var parse_Tokenizer_utils_getLowestIndex = function () { - - return function (haystack, needles) { - var i, index, lowest; - i = needles.length; - while (i--) { - index = haystack.indexOf(needles[i]); - if (!index) { - return 0; - } - if (index === -1) { - continue; - } - if (!lowest || index < lowest) { - lowest = index; - } - } - return lowest || -1; - }; - }(); -var parse_Tokenizer_getTag__getTag = function (types, makeRegexMatcher, getLowestIndex) { - - var getTag, getOpeningTag, getClosingTag, getTagName, getAttributes, getAttribute, getAttributeName, getAttributeValue, getUnquotedAttributeValue, getUnquotedAttributeValueToken, getUnquotedAttributeValueText, getQuotedStringToken, getQuotedAttributeValue; - getTag = function () { - return getOpeningTag(this) || getClosingTag(this); - }; - getOpeningTag = function (tokenizer) { - var start, tag, attrs, lowerCaseName; - start = tokenizer.pos; - if (tokenizer.inside) { - return null; - } - if (!tokenizer.getStringMatch('<')) { - return null; - } - tag = { type: types.TAG }; - if (tokenizer.getStringMatch('!')) { - tag.doctype = true; - } - tag.name = getTagName(tokenizer); - if (!tag.name) { - tokenizer.pos = start; - return null; - } - attrs = getAttributes(tokenizer); - if (attrs) { - tag.attrs = attrs; - } - tokenizer.allowWhitespace(); - if (tokenizer.getStringMatch('/')) { - tag.selfClosing = true; - } - if (!tokenizer.getStringMatch('>')) { - tokenizer.pos = start; - return null; - } - lowerCaseName = tag.name.toLowerCase(); - if (lowerCaseName === 'script' || lowerCaseName === 'style') { - tokenizer.inside = lowerCaseName; - } - return tag; - }; - getClosingTag = function (tokenizer) { - var start, tag, expected; - start = tokenizer.pos; - expected = function (str) { - throw new Error('Unexpected character ' + tokenizer.remaining().charAt(0) + ' (expected ' + str + ')'); - }; - if (!tokenizer.getStringMatch('<')) { - return null; - } - tag = { - type: types.TAG, - closing: true - }; - if (!tokenizer.getStringMatch('/')) { - expected('"/"'); - } - tag.name = getTagName(tokenizer); - if (!tag.name) { - expected('tag name'); - } - if (!tokenizer.getStringMatch('>')) { - expected('">"'); - } - if (tokenizer.inside) { - if (tag.name.toLowerCase() !== tokenizer.inside) { - tokenizer.pos = start; - return null; - } - tokenizer.inside = null; - } - return tag; - }; - getTagName = makeRegexMatcher(/^[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/); - getAttributes = function (tokenizer) { - var start, attrs, attr; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - attr = getAttribute(tokenizer); - if (!attr) { - tokenizer.pos = start; - return null; - } - attrs = []; - while (attr !== null) { - attrs[attrs.length] = attr; - tokenizer.allowWhitespace(); - attr = getAttribute(tokenizer); - } - return attrs; - }; - getAttribute = function (tokenizer) { - var attr, name, value; - name = getAttributeName(tokenizer); - if (!name) { - return null; - } - attr = { name: name }; - value = getAttributeValue(tokenizer); - if (value) { - attr.value = value; - } - return attr; - }; - getAttributeName = makeRegexMatcher(/^[^\s"'>\/=]+/); - getAttributeValue = function (tokenizer) { - var start, value; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch('=')) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - value = getQuotedAttributeValue(tokenizer, '\'') || getQuotedAttributeValue(tokenizer, '"') || getUnquotedAttributeValue(tokenizer); - if (value === null) { - tokenizer.pos = start; - return null; - } - return value; - }; - getUnquotedAttributeValueText = makeRegexMatcher(/^[^\s"'=<>`]+/); - getUnquotedAttributeValueToken = function (tokenizer) { - var start, text, index; - start = tokenizer.pos; - text = getUnquotedAttributeValueText(tokenizer); - if (!text) { - return null; - } - if ((index = text.indexOf(tokenizer.delimiters[0])) !== -1) { - text = text.substr(0, index); - tokenizer.pos = start + text.length; - } - return { - type: types.TEXT, - value: text - }; - }; - getUnquotedAttributeValue = function (tokenizer) { - var tokens, token; - tokens = []; - token = tokenizer.getMustache() || getUnquotedAttributeValueToken(tokenizer); - while (token !== null) { - tokens[tokens.length] = token; - token = tokenizer.getMustache() || getUnquotedAttributeValueToken(tokenizer); - } - if (!tokens.length) { - return null; - } - return tokens; - }; - getQuotedAttributeValue = function (tokenizer, quoteMark) { - var start, tokens, token; - start = tokenizer.pos; - if (!tokenizer.getStringMatch(quoteMark)) { - return null; - } - tokens = []; - token = tokenizer.getMustache() || getQuotedStringToken(tokenizer, quoteMark); - while (token !== null) { - tokens[tokens.length] = token; - token = tokenizer.getMustache() || getQuotedStringToken(tokenizer, quoteMark); - } - if (!tokenizer.getStringMatch(quoteMark)) { - tokenizer.pos = start; - return null; - } - return tokens; - }; - getQuotedStringToken = function (tokenizer, quoteMark) { - var start, index, remaining; - start = tokenizer.pos; - remaining = tokenizer.remaining(); - index = getLowestIndex(remaining, [ - quoteMark, - tokenizer.delimiters[0], - tokenizer.delimiters[1] - ]); - if (index === -1) { - throw new Error('Quoted attribute value must have a closing quote'); - } - if (!index) { - return null; - } - tokenizer.pos += index; - return { - type: types.TEXT, - value: remaining.substr(0, index) - }; - }; - return getTag; - }(config_types, parse_Tokenizer_utils_makeRegexMatcher, parse_Tokenizer_utils_getLowestIndex); -var parse_Tokenizer_getText__getText = function (types, getLowestIndex) { - - return function () { - var index, remaining, barrier; - remaining = this.remaining(); - barrier = this.inside ? '' + this.inside : '<'; - index = getLowestIndex(remaining, [ - barrier, - this.delimiters[0], - this.tripleDelimiters[0] - ]); - if (!index) { - return null; - } - if (index === -1) { - index = remaining.length; - } - this.pos += index; - return { - type: types.TEXT, - value: remaining.substr(0, index) - }; - }; - }(config_types, parse_Tokenizer_utils_getLowestIndex); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getBooleanLiteral = function (types) { - - return function (tokenizer) { - var remaining = tokenizer.remaining(); - if (remaining.substr(0, 4) === 'true') { - tokenizer.pos += 4; - return { - t: types.BOOLEAN_LITERAL, - v: 'true' - }; - } - if (remaining.substr(0, 5) === 'false') { - tokenizer.pos += 5; - return { - t: types.BOOLEAN_LITERAL, - v: 'false' - }; - } - return null; - }; - }(config_types); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral_getKeyValuePair = function (types, getKey) { - - return function (tokenizer) { - var start, key, value; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - key = getKey(tokenizer); - if (key === null) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(':')) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - value = tokenizer.getExpression(); - if (value === null) { - tokenizer.pos = start; - return null; - } - return { - t: types.KEY_VALUE_PAIR, - k: key, - v: value - }; - }; - }(config_types, parse_Tokenizer_getExpression_shared_getKey); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral_getKeyValuePairs = function (getKeyValuePair) { - - return function getKeyValuePairs(tokenizer) { - var start, pairs, pair, keyValuePairs; - start = tokenizer.pos; - pair = getKeyValuePair(tokenizer); - if (pair === null) { - return null; - } - pairs = [pair]; - if (tokenizer.getStringMatch(',')) { - keyValuePairs = getKeyValuePairs(tokenizer); - if (!keyValuePairs) { - tokenizer.pos = start; - return null; - } - return pairs.concat(keyValuePairs); - } - return pairs; - }; - }(parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral_getKeyValuePair); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral__getObjectLiteral = function (types, getKeyValuePairs) { - - return function (tokenizer) { - var start, keyValuePairs; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch('{')) { - tokenizer.pos = start; - return null; - } - keyValuePairs = getKeyValuePairs(tokenizer); - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch('}')) { - tokenizer.pos = start; - return null; - } - return { - t: types.OBJECT_LITERAL, - m: keyValuePairs - }; - }; - }(config_types, parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral_getKeyValuePairs); -var parse_Tokenizer_getExpression_shared_getExpressionList = function () { - - return function getExpressionList(tokenizer) { - var start, expressions, expr, next; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - expr = tokenizer.getExpression(); - if (expr === null) { - return null; - } - expressions = [expr]; - tokenizer.allowWhitespace(); - if (tokenizer.getStringMatch(',')) { - next = getExpressionList(tokenizer); - if (next === null) { - tokenizer.pos = start; - return null; - } - expressions = expressions.concat(next); - } - return expressions; - }; - }(); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getArrayLiteral = function (types, getExpressionList) { - - return function (tokenizer) { - var start, expressionList; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch('[')) { - tokenizer.pos = start; - return null; - } - expressionList = getExpressionList(tokenizer); - if (!tokenizer.getStringMatch(']')) { - tokenizer.pos = start; - return null; - } - return { - t: types.ARRAY_LITERAL, - m: expressionList - }; - }; - }(config_types, parse_Tokenizer_getExpression_shared_getExpressionList); -var parse_Tokenizer_getExpression_getPrimary_getLiteral__getLiteral = function (getNumberLiteral, getBooleanLiteral, getStringLiteral, getObjectLiteral, getArrayLiteral) { - - return function (tokenizer) { - var literal = getNumberLiteral(tokenizer) || getBooleanLiteral(tokenizer) || getStringLiteral(tokenizer) || getObjectLiteral(tokenizer) || getArrayLiteral(tokenizer); - return literal; - }; - }(parse_Tokenizer_getExpression_getPrimary_getLiteral_getNumberLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getBooleanLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral__getObjectLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getArrayLiteral); -var parse_Tokenizer_getExpression_getPrimary_getReference = function (types, makeRegexMatcher, getName) { - - var getDotRefinement, getArrayRefinement, getArrayMember, globals; - getDotRefinement = makeRegexMatcher(/^\.[a-zA-Z_$0-9]+/); - getArrayRefinement = function (tokenizer) { - var num = getArrayMember(tokenizer); - if (num) { - return '.' + num; - } - return null; - }; - getArrayMember = makeRegexMatcher(/^\[(0|[1-9][0-9]*)\]/); - globals = /^(?:Array|Date|RegExp|decodeURIComponent|decodeURI|encodeURIComponent|encodeURI|isFinite|isNaN|parseFloat|parseInt|JSON|Math|NaN|undefined|null)$/; - return function (tokenizer) { - var startPos, ancestor, name, dot, combo, refinement, lastDotIndex; - startPos = tokenizer.pos; - ancestor = ''; - while (tokenizer.getStringMatch('../')) { - ancestor += '../'; - } - if (!ancestor) { - dot = tokenizer.getStringMatch('.') || ''; - } - name = getName(tokenizer) || ''; - if (!ancestor && !dot && globals.test(name)) { - return { - t: types.GLOBAL, - v: name - }; - } - if (name === 'this' && !ancestor && !dot) { - name = '.'; - startPos += 3; - } - combo = (ancestor || dot) + name; - if (!combo) { - return null; - } - while (refinement = getDotRefinement(tokenizer) || getArrayRefinement(tokenizer)) { - combo += refinement; - } - if (tokenizer.getStringMatch('(')) { - lastDotIndex = combo.lastIndexOf('.'); - if (lastDotIndex !== -1) { - combo = combo.substr(0, lastDotIndex); - tokenizer.pos = startPos + combo.length; - } else { - tokenizer.pos -= 1; - } - } - return { - t: types.REFERENCE, - n: combo - }; - }; - }(config_types, parse_Tokenizer_utils_makeRegexMatcher, parse_Tokenizer_getExpression_shared_getName); -var parse_Tokenizer_getExpression_getPrimary_getBracketedExpression = function (types) { - - return function (tokenizer) { - var start, expr; - start = tokenizer.pos; - if (!tokenizer.getStringMatch('(')) { - return null; - } - tokenizer.allowWhitespace(); - expr = tokenizer.getExpression(); - if (!expr) { - tokenizer.pos = start; - return null; - } - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(')')) { - tokenizer.pos = start; - return null; - } - return { - t: types.BRACKETED, - x: expr - }; - }; - }(config_types); -var parse_Tokenizer_getExpression_getPrimary__getPrimary = function (getLiteral, getReference, getBracketedExpression) { - - return function (tokenizer) { - return getLiteral(tokenizer) || getReference(tokenizer) || getBracketedExpression(tokenizer); - }; - }(parse_Tokenizer_getExpression_getPrimary_getLiteral__getLiteral, parse_Tokenizer_getExpression_getPrimary_getReference, parse_Tokenizer_getExpression_getPrimary_getBracketedExpression); -var parse_Tokenizer_getExpression_shared_getRefinement = function (types, getName) { - - return function getRefinement(tokenizer) { - var start, name, expr; - start = tokenizer.pos; - tokenizer.allowWhitespace(); - if (tokenizer.getStringMatch('.')) { - tokenizer.allowWhitespace(); - if (name = getName(tokenizer)) { - return { - t: types.REFINEMENT, - n: name - }; - } - tokenizer.expected('a property name'); - } - if (tokenizer.getStringMatch('[')) { - tokenizer.allowWhitespace(); - expr = tokenizer.getExpression(); - if (!expr) { - tokenizer.expected('an expression'); - } - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(']')) { - tokenizer.expected('"]"'); - } - return { - t: types.REFINEMENT, - x: expr - }; - } - return null; - }; - }(config_types, parse_Tokenizer_getExpression_shared_getName); -var parse_Tokenizer_getExpression_getMemberOrInvocation = function (types, getPrimary, getExpressionList, getRefinement) { - - return function (tokenizer) { - var current, expression, refinement, expressionList; - expression = getPrimary(tokenizer); - if (!expression) { - return null; - } - while (expression) { - current = tokenizer.pos; - if (refinement = getRefinement(tokenizer)) { - expression = { - t: types.MEMBER, - x: expression, - r: refinement - }; - } else if (tokenizer.getStringMatch('(')) { - tokenizer.allowWhitespace(); - expressionList = getExpressionList(tokenizer); - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(')')) { - tokenizer.pos = current; - break; - } - expression = { - t: types.INVOCATION, - x: expression - }; - if (expressionList) { - expression.o = expressionList; - } - } else { - break; - } - } - return expression; - }; - }(config_types, parse_Tokenizer_getExpression_getPrimary__getPrimary, parse_Tokenizer_getExpression_shared_getExpressionList, parse_Tokenizer_getExpression_shared_getRefinement); -var parse_Tokenizer_getExpression_getTypeOf = function (types, getMemberOrInvocation) { - - var getTypeOf, makePrefixSequenceMatcher; - makePrefixSequenceMatcher = function (symbol, fallthrough) { - return function (tokenizer) { - var start, expression; - if (!tokenizer.getStringMatch(symbol)) { - return fallthrough(tokenizer); - } - start = tokenizer.pos; - tokenizer.allowWhitespace(); - expression = tokenizer.getExpression(); - if (!expression) { - tokenizer.expected('an expression'); - } - return { - s: symbol, - o: expression, - t: types.PREFIX_OPERATOR - }; - }; - }; - (function () { - var i, len, matcher, prefixOperators, fallthrough; - prefixOperators = '! ~ + - typeof'.split(' '); - fallthrough = getMemberOrInvocation; - for (i = 0, len = prefixOperators.length; i < len; i += 1) { - matcher = makePrefixSequenceMatcher(prefixOperators[i], fallthrough); - fallthrough = matcher; - } - getTypeOf = fallthrough; - }()); - return getTypeOf; - }(config_types, parse_Tokenizer_getExpression_getMemberOrInvocation); -var parse_Tokenizer_getExpression_getLogicalOr = function (types, getTypeOf) { - - var getLogicalOr, makeInfixSequenceMatcher; - makeInfixSequenceMatcher = function (symbol, fallthrough) { - return function (tokenizer) { - var start, left, right; - left = fallthrough(tokenizer); - if (!left) { - return null; - } - start = tokenizer.pos; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(symbol)) { - tokenizer.pos = start; - return left; - } - if (symbol === 'in' && /[a-zA-Z_$0-9]/.test(tokenizer.remaining().charAt(0))) { - tokenizer.pos = start; - return left; - } - tokenizer.allowWhitespace(); - right = tokenizer.getExpression(); - if (!right) { - tokenizer.pos = start; - return left; - } - return { - t: types.INFIX_OPERATOR, - s: symbol, - o: [ - left, - right - ] - }; - }; - }; - (function () { - var i, len, matcher, infixOperators, fallthrough; - infixOperators = '* / % + - << >> >>> < <= > >= in instanceof == != === !== & ^ | && ||'.split(' '); - fallthrough = getTypeOf; - for (i = 0, len = infixOperators.length; i < len; i += 1) { - matcher = makeInfixSequenceMatcher(infixOperators[i], fallthrough); - fallthrough = matcher; - } - getLogicalOr = fallthrough; - }()); - return getLogicalOr; - }(config_types, parse_Tokenizer_getExpression_getTypeOf); -var parse_Tokenizer_getExpression_getConditional = function (types, getLogicalOr) { - - return function (tokenizer) { - var start, expression, ifTrue, ifFalse; - expression = getLogicalOr(tokenizer); - if (!expression) { - return null; - } - start = tokenizer.pos; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch('?')) { - tokenizer.pos = start; - return expression; - } - tokenizer.allowWhitespace(); - ifTrue = tokenizer.getExpression(); - if (!ifTrue) { - tokenizer.pos = start; - return expression; - } - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(':')) { - tokenizer.pos = start; - return expression; - } - tokenizer.allowWhitespace(); - ifFalse = tokenizer.getExpression(); - if (!ifFalse) { - tokenizer.pos = start; - return expression; - } - return { - t: types.CONDITIONAL, - o: [ - expression, - ifTrue, - ifFalse - ] - }; - }; - }(config_types, parse_Tokenizer_getExpression_getLogicalOr); -var parse_Tokenizer_getExpression__getExpression = function (getConditional) { - - return function () { - return getConditional(this); - }; - }(parse_Tokenizer_getExpression_getConditional); -var parse_Tokenizer__Tokenizer = function (getMustache, getComment, getTag, getText, getExpression, allowWhitespace, getStringMatch) { - - var Tokenizer; - Tokenizer = function (str, options) { - var token; - this.str = str; - this.pos = 0; - this.delimiters = options.delimiters; - this.tripleDelimiters = options.tripleDelimiters; - this.tokens = []; - while (this.pos < this.str.length) { - token = this.getToken(); - if (token === null && this.remaining()) { - this.fail(); - } - this.tokens.push(token); - } - }; - Tokenizer.prototype = { - getToken: function () { - var token = this.getMustache() || this.getComment() || this.getTag() || this.getText(); - return token; - }, - getMustache: getMustache, - getComment: getComment, - getTag: getTag, - getText: getText, - getExpression: getExpression, - allowWhitespace: allowWhitespace, - getStringMatch: getStringMatch, - remaining: function () { - return this.str.substring(this.pos); - }, - fail: function () { - var last20, next20; - last20 = this.str.substr(0, this.pos).substr(-20); - if (last20.length === 20) { - last20 = '...' + last20; - } - next20 = this.remaining().substr(0, 20); - if (next20.length === 20) { - next20 = next20 + '...'; - } - throw new Error('Could not parse template: ' + (last20 ? last20 + '<- ' : '') + 'failed at character ' + this.pos + ' ->' + next20); - }, - expected: function (thing) { - var remaining = this.remaining().substr(0, 40); - if (remaining.length === 40) { - remaining += '...'; - } - throw new Error('Tokenizer failed: unexpected string "' + remaining + '" (expected ' + thing + ')'); - } - }; - return Tokenizer; - }(parse_Tokenizer_getMustache__getMustache, parse_Tokenizer_getComment_getComment, parse_Tokenizer_getTag__getTag, parse_Tokenizer_getText__getText, parse_Tokenizer_getExpression__getExpression, parse_Tokenizer_utils_allowWhitespace, parse_Tokenizer_utils_getStringMatch); -var parse_tokenize = function (stripHtmlComments, stripStandalones, stripCommentTokens, Tokenizer, circular) { - - var tokenize, Ractive; - circular.push(function () { - Ractive = circular.Ractive; - }); - tokenize = function (template, options) { - var tokenizer, tokens; - options = options || {}; - if (options.stripComments !== false) { - template = stripHtmlComments(template); - } - tokenizer = new Tokenizer(template, { - delimiters: options.delimiters || (Ractive ? Ractive.delimiters : [ - '{{', - '}}' - ]), - tripleDelimiters: options.tripleDelimiters || (Ractive ? Ractive.tripleDelimiters : [ - '{{{', - '}}}' - ]) - }); - tokens = tokenizer.tokens; - stripStandalones(tokens); - stripCommentTokens(tokens); - return tokens; - }; - return tokenize; - }(parse_utils_stripHtmlComments, parse_utils_stripStandalones, parse_utils_stripCommentTokens, parse_Tokenizer__Tokenizer, circular); -var parse_Parser_getText_TextStub__TextStub = function (types) { - - var TextStub, htmlEntities, controlCharacters, namedEntityPattern, hexEntityPattern, decimalEntityPattern, validateCode, decodeCharacterReferences, whitespace; - TextStub = function (token, preserveWhitespace) { - this.text = preserveWhitespace ? token.value : token.value.replace(whitespace, ' '); - }; - TextStub.prototype = { - type: types.TEXT, - toJSON: function () { - return this.decoded || (this.decoded = decodeCharacterReferences(this.text)); - }, - toString: function () { - return this.text; - } - }; - htmlEntities = { - quot: 34, - amp: 38, - apos: 39, - lt: 60, - gt: 62, - nbsp: 160, - iexcl: 161, - cent: 162, - pound: 163, - curren: 164, - yen: 165, - brvbar: 166, - sect: 167, - uml: 168, - copy: 169, - ordf: 170, - laquo: 171, - not: 172, - shy: 173, - reg: 174, - macr: 175, - deg: 176, - plusmn: 177, - sup2: 178, - sup3: 179, - acute: 180, - micro: 181, - para: 182, - middot: 183, - cedil: 184, - sup1: 185, - ordm: 186, - raquo: 187, - frac14: 188, - frac12: 189, - frac34: 190, - iquest: 191, - Agrave: 192, - Aacute: 193, - Acirc: 194, - Atilde: 195, - Auml: 196, - Aring: 197, - AElig: 198, - Ccedil: 199, - Egrave: 200, - Eacute: 201, - Ecirc: 202, - Euml: 203, - Igrave: 204, - Iacute: 205, - Icirc: 206, - Iuml: 207, - ETH: 208, - Ntilde: 209, - Ograve: 210, - Oacute: 211, - Ocirc: 212, - Otilde: 213, - Ouml: 214, - times: 215, - Oslash: 216, - Ugrave: 217, - Uacute: 218, - Ucirc: 219, - Uuml: 220, - Yacute: 221, - THORN: 222, - szlig: 223, - agrave: 224, - aacute: 225, - acirc: 226, - atilde: 227, - auml: 228, - aring: 229, - aelig: 230, - ccedil: 231, - egrave: 232, - eacute: 233, - ecirc: 234, - euml: 235, - igrave: 236, - iacute: 237, - icirc: 238, - iuml: 239, - eth: 240, - ntilde: 241, - ograve: 242, - oacute: 243, - ocirc: 244, - otilde: 245, - ouml: 246, - divide: 247, - oslash: 248, - ugrave: 249, - uacute: 250, - ucirc: 251, - uuml: 252, - yacute: 253, - thorn: 254, - yuml: 255, - OElig: 338, - oelig: 339, - Scaron: 352, - scaron: 353, - Yuml: 376, - fnof: 402, - circ: 710, - tilde: 732, - Alpha: 913, - Beta: 914, - Gamma: 915, - Delta: 916, - Epsilon: 917, - Zeta: 918, - Eta: 919, - Theta: 920, - Iota: 921, - Kappa: 922, - Lambda: 923, - Mu: 924, - Nu: 925, - Xi: 926, - Omicron: 927, - Pi: 928, - Rho: 929, - Sigma: 931, - Tau: 932, - Upsilon: 933, - Phi: 934, - Chi: 935, - Psi: 936, - Omega: 937, - alpha: 945, - beta: 946, - gamma: 947, - delta: 948, - epsilon: 949, - zeta: 950, - eta: 951, - theta: 952, - iota: 953, - kappa: 954, - lambda: 955, - mu: 956, - nu: 957, - xi: 958, - omicron: 959, - pi: 960, - rho: 961, - sigmaf: 962, - sigma: 963, - tau: 964, - upsilon: 965, - phi: 966, - chi: 967, - psi: 968, - omega: 969, - thetasym: 977, - upsih: 978, - piv: 982, - ensp: 8194, - emsp: 8195, - thinsp: 8201, - zwnj: 8204, - zwj: 8205, - lrm: 8206, - rlm: 8207, - ndash: 8211, - mdash: 8212, - lsquo: 8216, - rsquo: 8217, - sbquo: 8218, - ldquo: 8220, - rdquo: 8221, - bdquo: 8222, - dagger: 8224, - Dagger: 8225, - bull: 8226, - hellip: 8230, - permil: 8240, - prime: 8242, - Prime: 8243, - lsaquo: 8249, - rsaquo: 8250, - oline: 8254, - frasl: 8260, - euro: 8364, - image: 8465, - weierp: 8472, - real: 8476, - trade: 8482, - alefsym: 8501, - larr: 8592, - uarr: 8593, - rarr: 8594, - darr: 8595, - harr: 8596, - crarr: 8629, - lArr: 8656, - uArr: 8657, - rArr: 8658, - dArr: 8659, - hArr: 8660, - forall: 8704, - part: 8706, - exist: 8707, - empty: 8709, - nabla: 8711, - isin: 8712, - notin: 8713, - ni: 8715, - prod: 8719, - sum: 8721, - minus: 8722, - lowast: 8727, - radic: 8730, - prop: 8733, - infin: 8734, - ang: 8736, - and: 8743, - or: 8744, - cap: 8745, - cup: 8746, - 'int': 8747, - there4: 8756, - sim: 8764, - cong: 8773, - asymp: 8776, - ne: 8800, - equiv: 8801, - le: 8804, - ge: 8805, - sub: 8834, - sup: 8835, - nsub: 8836, - sube: 8838, - supe: 8839, - oplus: 8853, - otimes: 8855, - perp: 8869, - sdot: 8901, - lceil: 8968, - rceil: 8969, - lfloor: 8970, - rfloor: 8971, - lang: 9001, - rang: 9002, - loz: 9674, - spades: 9824, - clubs: 9827, - hearts: 9829, - diams: 9830 - }; - controlCharacters = [ - 8364, - 129, - 8218, - 402, - 8222, - 8230, - 8224, - 8225, - 710, - 8240, - 352, - 8249, - 338, - 141, - 381, - 143, - 144, - 8216, - 8217, - 8220, - 8221, - 8226, - 8211, - 8212, - 732, - 8482, - 353, - 8250, - 339, - 157, - 382, - 376 - ]; - namedEntityPattern = new RegExp('&(' + Object.keys(htmlEntities).join('|') + ');?', 'g'); - hexEntityPattern = /([0-9]+);?/g; - decimalEntityPattern = /([0-9]+);?/g; - validateCode = function (code) { - if (!code) { - return 65533; - } - if (code === 10) { - return 32; - } - if (code < 128) { - return code; - } - if (code <= 159) { - return controlCharacters[code - 128]; - } - if (code < 55296) { - return code; - } - if (code <= 57343) { - return 65533; - } - if (code <= 65535) { - return code; - } - return 65533; - }; - decodeCharacterReferences = function (html) { - var result; - result = html.replace(namedEntityPattern, function (match, name) { - if (htmlEntities[name]) { - return String.fromCharCode(htmlEntities[name]); - } - return match; - }); - result = result.replace(hexEntityPattern, function (match, hex) { - return String.fromCharCode(validateCode(parseInt(hex, 16))); - }); - result = result.replace(decimalEntityPattern, function (match, charCode) { - return String.fromCharCode(validateCode(charCode)); - }); - return result; - }; - whitespace = /\s+/g; - return TextStub; - }(config_types); -var parse_Parser_getText__getText = function (types, TextStub) { - - return function (token) { - if (token.type === types.TEXT) { - this.pos += 1; - return new TextStub(token, this.preserveWhitespace); - } - return null; - }; - }(config_types, parse_Parser_getText_TextStub__TextStub); -var parse_Parser_getComment_CommentStub__CommentStub = function (types) { - - var CommentStub; - CommentStub = function (token) { - this.content = token.content; - }; - CommentStub.prototype = { - toJSON: function () { - return { - t: types.COMMENT, - f: this.content - }; - }, - toString: function () { - return ''; - } - }; - return CommentStub; - }(config_types); -var parse_Parser_getComment__getComment = function (types, CommentStub) { - - return function (token) { - if (token.type === types.COMMENT) { - this.pos += 1; - return new CommentStub(token, this.preserveWhitespace); - } - return null; - }; - }(config_types, parse_Parser_getComment_CommentStub__CommentStub); -var parse_Parser_getMustache_ExpressionStub__ExpressionStub = function (types, isObject) { - - var ExpressionStub, getRefs, stringify; - ExpressionStub = function (token) { - this.refs = []; - getRefs(token, this.refs); - this.str = stringify(token, this.refs); - }; - ExpressionStub.prototype = { - toJSON: function () { - if (this.json) { - return this.json; - } - this.json = { - r: this.refs, - s: this.str - }; - return this.json; - } - }; - getRefs = function (token, refs) { - var i, list; - if (token.t === types.REFERENCE) { - if (refs.indexOf(token.n) === -1) { - refs.unshift(token.n); - } - } - list = token.o || token.m; - if (list) { - if (isObject(list)) { - getRefs(list, refs); - } else { - i = list.length; - while (i--) { - getRefs(list[i], refs); - } - } - } - if (token.x) { - getRefs(token.x, refs); - } - if (token.r) { - getRefs(token.r, refs); - } - if (token.v) { - getRefs(token.v, refs); - } - }; - stringify = function (token, refs) { - var map = function (item) { - return stringify(item, refs); - }; - switch (token.t) { - case types.BOOLEAN_LITERAL: - case types.GLOBAL: - case types.NUMBER_LITERAL: - return token.v; - case types.STRING_LITERAL: - return '\'' + token.v.replace(/'/g, '\\\'') + '\''; - case types.ARRAY_LITERAL: - return '[' + (token.m ? token.m.map(map).join(',') : '') + ']'; - case types.OBJECT_LITERAL: - return '{' + (token.m ? token.m.map(map).join(',') : '') + '}'; - case types.KEY_VALUE_PAIR: - return token.k + ':' + stringify(token.v, refs); - case types.PREFIX_OPERATOR: - return (token.s === 'typeof' ? 'typeof ' : token.s) + stringify(token.o, refs); - case types.INFIX_OPERATOR: - return stringify(token.o[0], refs) + (token.s.substr(0, 2) === 'in' ? ' ' + token.s + ' ' : token.s) + stringify(token.o[1], refs); - case types.INVOCATION: - return stringify(token.x, refs) + '(' + (token.o ? token.o.map(map).join(',') : '') + ')'; - case types.BRACKETED: - return '(' + stringify(token.x, refs) + ')'; - case types.MEMBER: - return stringify(token.x, refs) + stringify(token.r, refs); - case types.REFINEMENT: - return token.n ? '.' + token.n : '[' + stringify(token.x, refs) + ']'; - case types.CONDITIONAL: - return stringify(token.o[0], refs) + '?' + stringify(token.o[1], refs) + ':' + stringify(token.o[2], refs); - case types.REFERENCE: - return '${' + refs.indexOf(token.n) + '}'; - default: - throw new Error('Could not stringify expression token. This error is unexpected'); - } - }; - return ExpressionStub; - }(config_types, utils_isObject); -var parse_Parser_getMustache_MustacheStub__MustacheStub = function (types, ExpressionStub) { - - var MustacheStub = function (token, parser) { - this.type = token.type === types.TRIPLE ? types.TRIPLE : token.mustacheType; - if (token.ref) { - this.ref = token.ref; - } - if (token.expression) { - this.expr = new ExpressionStub(token.expression); - } - parser.pos += 1; - }; - MustacheStub.prototype = { - toJSON: function () { - var json; - if (this.json) { - return this.json; - } - json = { t: this.type }; - if (this.ref) { - json.r = this.ref; - } - if (this.expr) { - json.x = this.expr.toJSON(); - } - this.json = json; - return json; - }, - toString: function () { - return false; - } - }; - return MustacheStub; - }(config_types, parse_Parser_getMustache_ExpressionStub__ExpressionStub); -var parse_Parser_utils_stringifyStubs = function () { - - return function (items) { - var str = '', itemStr, i, len; - if (!items) { - return ''; - } - for (i = 0, len = items.length; i < len; i += 1) { - itemStr = items[i].toString(); - if (itemStr === false) { - return false; - } - str += itemStr; - } - return str; - }; - }(); -var parse_Parser_utils_jsonifyStubs = function (stringifyStubs) { - - return function (items, noStringify) { - var str, json; - if (!noStringify) { - str = stringifyStubs(items); - if (str !== false) { - return str; - } - } - json = items.map(function (item) { - return item.toJSON(noStringify); - }); - return json; - }; - }(parse_Parser_utils_stringifyStubs); -var parse_Parser_getMustache_SectionStub__SectionStub = function (types, jsonifyStubs, ExpressionStub) { - - var SectionStub = function (firstToken, parser) { - var next; - this.ref = firstToken.ref; - this.indexRef = firstToken.indexRef; - this.inverted = firstToken.mustacheType === types.INVERTED; - if (firstToken.expression) { - this.expr = new ExpressionStub(firstToken.expression); - } - parser.pos += 1; - this.items = []; - next = parser.next(); - while (next) { - if (next.mustacheType === types.CLOSING) { - if (next.ref.trim() === this.ref || this.expr) { - parser.pos += 1; - break; - } else { - throw new Error('Could not parse template: Illegal closing section'); - } - } - this.items[this.items.length] = parser.getStub(); - next = parser.next(); - } - }; - SectionStub.prototype = { - toJSON: function (noStringify) { - var json; - if (this.json) { - return this.json; - } - json = { t: types.SECTION }; - if (this.ref) { - json.r = this.ref; - } - if (this.indexRef) { - json.i = this.indexRef; - } - if (this.inverted) { - json.n = true; - } - if (this.expr) { - json.x = this.expr.toJSON(); - } - if (this.items.length) { - json.f = jsonifyStubs(this.items, noStringify); - } - this.json = json; - return json; - }, - toString: function () { - return false; - } - }; - return SectionStub; - }(config_types, parse_Parser_utils_jsonifyStubs, parse_Parser_getMustache_ExpressionStub__ExpressionStub); -var parse_Parser_getMustache__getMustache = function (types, MustacheStub, SectionStub) { - - return function (token) { - if (token.type === types.MUSTACHE || token.type === types.TRIPLE) { - if (token.mustacheType === types.SECTION || token.mustacheType === types.INVERTED) { - return new SectionStub(token, this); - } - return new MustacheStub(token, this); - } - }; - }(config_types, parse_Parser_getMustache_MustacheStub__MustacheStub, parse_Parser_getMustache_SectionStub__SectionStub); -var parse_Parser_getElement_ElementStub_utils_siblingsByTagName = function () { - - return { - li: ['li'], - dt: [ - 'dt', - 'dd' - ], - dd: [ - 'dt', - 'dd' - ], - p: 'address article aside blockquote dir div dl fieldset footer form h1 h2 h3 h4 h5 h6 header hgroup hr menu nav ol p pre section table ul'.split(' '), - rt: [ - 'rt', - 'rp' - ], - rp: [ - 'rp', - 'rt' - ], - optgroup: ['optgroup'], - option: [ - 'option', - 'optgroup' - ], - thead: [ - 'tbody', - 'tfoot' - ], - tbody: [ - 'tbody', - 'tfoot' - ], - tr: ['tr'], - td: [ - 'td', - 'th' - ], - th: [ - 'td', - 'th' - ] - }; - }(); -var parse_Parser_getElement_ElementStub_utils_filterAttributes = function (isArray) { - - return function (items) { - var attrs, proxies, filtered, i, len, item; - filtered = {}; - attrs = []; - proxies = []; - len = items.length; - for (i = 0; i < len; i += 1) { - item = items[i]; - if (item.name === 'intro') { - if (filtered.intro) { - throw new Error('An element can only have one intro transition'); - } - filtered.intro = item; - } else if (item.name === 'outro') { - if (filtered.outro) { - throw new Error('An element can only have one outro transition'); - } - filtered.outro = item; - } else if (item.name === 'intro-outro') { - if (filtered.intro || filtered.outro) { - throw new Error('An element can only have one intro and one outro transition'); - } - filtered.intro = item; - filtered.outro = deepClone(item); - } else if (item.name.substr(0, 6) === 'proxy-') { - item.name = item.name.substring(6); - proxies[proxies.length] = item; - } else if (item.name.substr(0, 3) === 'on-') { - item.name = item.name.substring(3); - proxies[proxies.length] = item; - } else if (item.name === 'decorator') { - filtered.decorator = item; - } else { - attrs[attrs.length] = item; - } - } - filtered.attrs = attrs; - filtered.proxies = proxies; - return filtered; - }; - function deepClone(obj) { - var result, key; - if (typeof obj !== 'object') { - return obj; - } - if (isArray(obj)) { - return obj.map(deepClone); - } - result = {}; - for (key in obj) { - if (obj.hasOwnProperty(key)) { - result[key] = deepClone(obj[key]); - } - } - return result; - } - }(utils_isArray); -var parse_Parser_getElement_ElementStub_utils_processDirective = function (types, parseJSON) { - - return function (directive) { - var processed, tokens, token, colonIndex, throwError, directiveName, directiveArgs, parsed; - throwError = function () { - throw new Error('Illegal directive'); - }; - if (!directive.name || !directive.value) { - throwError(); - } - processed = { directiveType: directive.name }; - tokens = directive.value; - directiveName = []; - directiveArgs = []; - while (tokens.length) { - token = tokens.shift(); - if (token.type === types.TEXT) { - colonIndex = token.value.indexOf(':'); - if (colonIndex === -1) { - directiveName[directiveName.length] = token; - } else { - if (colonIndex) { - directiveName[directiveName.length] = { - type: types.TEXT, - value: token.value.substr(0, colonIndex) - }; - } - if (token.value.length > colonIndex + 1) { - directiveArgs[0] = { - type: types.TEXT, - value: token.value.substring(colonIndex + 1) - }; - } - break; - } - } else { - directiveName[directiveName.length] = token; - } - } - directiveArgs = directiveArgs.concat(tokens); - if (directiveName.length === 1 && directiveName[0].type === types.TEXT) { - processed.name = directiveName[0].value; - } else { - processed.name = directiveName; - } - if (directiveArgs.length) { - if (directiveArgs.length === 1 && directiveArgs[0].type === types.TEXT) { - parsed = parseJSON('[' + directiveArgs[0].value + ']'); - processed.args = parsed ? parsed.value : directiveArgs[0].value; - } else { - processed.dynamicArgs = directiveArgs; - } - } - return processed; - }; - }(config_types, utils_parseJSON); -var parse_Parser_StringStub_StringParser = function (getText, getMustache) { - - var StringParser; - StringParser = function (tokens, options) { - var stub; - this.tokens = tokens || []; - this.pos = 0; - this.options = options; - this.result = []; - while (stub = this.getStub()) { - this.result.push(stub); - } - }; - StringParser.prototype = { - getStub: function () { - var token = this.next(); - if (!token) { - return null; - } - return this.getText(token) || this.getMustache(token); - }, - getText: getText, - getMustache: getMustache, - next: function () { - return this.tokens[this.pos]; - } - }; - return StringParser; - }(parse_Parser_getText__getText, parse_Parser_getMustache__getMustache); -var parse_Parser_StringStub__StringStub = function (StringParser, stringifyStubs, jsonifyStubs) { - - var StringStub; - StringStub = function (tokens) { - var parser = new StringParser(tokens); - this.stubs = parser.result; - }; - StringStub.prototype = { - toJSON: function (noStringify) { - var json; - if (this['json_' + noStringify]) { - return this['json_' + noStringify]; - } - json = this['json_' + noStringify] = jsonifyStubs(this.stubs, noStringify); - return json; - }, - toString: function () { - if (this.str !== undefined) { - return this.str; - } - this.str = stringifyStubs(this.stubs); - return this.str; - } - }; - return StringStub; - }(parse_Parser_StringStub_StringParser, parse_Parser_utils_stringifyStubs, parse_Parser_utils_jsonifyStubs); -var parse_Parser_getElement_ElementStub_utils_jsonifyDirective = function (StringStub) { - - return function (directive) { - var result, name; - if (typeof directive.name === 'string') { - if (!directive.args && !directive.dynamicArgs) { - return directive.name; - } - name = directive.name; - } else { - name = new StringStub(directive.name).toJSON(); - } - result = { n: name }; - if (directive.args) { - result.a = directive.args; - return result; - } - if (directive.dynamicArgs) { - result.d = new StringStub(directive.dynamicArgs).toJSON(); - } - return result; - }; - }(parse_Parser_StringStub__StringStub); -var parse_Parser_getElement_ElementStub_toJSON = function (types, jsonifyStubs, jsonifyDirective) { - - return function (noStringify) { - var json, name, value, proxy, i, len, attribute; - if (this['json_' + noStringify]) { - return this['json_' + noStringify]; - } - if (this.component) { - json = { - t: types.COMPONENT, - e: this.component - }; - } else { - json = { - t: types.ELEMENT, - e: this.tag - }; - } - if (this.doctype) { - json.y = 1; - } - if (this.attributes && this.attributes.length) { - json.a = {}; - len = this.attributes.length; - for (i = 0; i < len; i += 1) { - attribute = this.attributes[i]; - name = attribute.name; - if (json.a[name]) { - throw new Error('You cannot have multiple attributes with the same name'); - } - if (attribute.value === null) { - value = null; - } else { - value = attribute.value.toJSON(noStringify); - } - json.a[name] = value; - } - } - if (this.items && this.items.length) { - json.f = jsonifyStubs(this.items, noStringify); - } - if (this.proxies && this.proxies.length) { - json.v = {}; - len = this.proxies.length; - for (i = 0; i < len; i += 1) { - proxy = this.proxies[i]; - json.v[proxy.directiveType] = jsonifyDirective(proxy); - } - } - if (this.intro) { - json.t1 = jsonifyDirective(this.intro); - } - if (this.outro) { - json.t2 = jsonifyDirective(this.outro); - } - if (this.decorator) { - json.o = jsonifyDirective(this.decorator); - } - this['json_' + noStringify] = json; - return json; - }; - }(config_types, parse_Parser_utils_jsonifyStubs, parse_Parser_getElement_ElementStub_utils_jsonifyDirective); -var parse_Parser_getElement_ElementStub_toString = function (stringifyStubs, voidElementNames) { - - var htmlElements; - htmlElements = 'a abbr acronym address applet area b base basefont bdo big blockquote body br button caption center cite code col colgroup dd del dfn dir div dl dt em fieldset font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img input ins isindex kbd label legend li link map menu meta noframes noscript object ol p param pre q s samp script select small span strike strong style sub sup textarea title tt u ul var article aside audio bdi canvas command data datagrid datalist details embed eventsource figcaption figure footer header hgroup keygen mark meter nav output progress ruby rp rt section source summary time track video wbr'.split(' '); - return function () { - var str, i, len, attrStr, name, attrValueStr, fragStr, isVoid; - if (this.str !== undefined) { - return this.str; - } - if (this.component) { - return this.str = false; - } - if (htmlElements.indexOf(this.tag.toLowerCase()) === -1) { - return this.str = false; - } - if (this.proxies || this.intro || this.outro || this.decorator) { - return this.str = false; - } - fragStr = stringifyStubs(this.items); - if (fragStr === false) { - return this.str = false; - } - isVoid = voidElementNames.indexOf(this.tag.toLowerCase()) !== -1; - str = '<' + this.tag; - if (this.attributes) { - for (i = 0, len = this.attributes.length; i < len; i += 1) { - name = this.attributes[i].name; - if (name.indexOf(':') !== -1) { - return this.str = false; - } - if (name === 'id' || name === 'intro' || name === 'outro') { - return this.str = false; - } - attrStr = ' ' + name; - if (this.attributes[i].value !== null) { - attrValueStr = this.attributes[i].value.toString(); - if (attrValueStr === false) { - return this.str = false; - } - if (attrValueStr !== '') { - attrStr += '='; - if (/[\s"'=<>`]/.test(attrValueStr)) { - attrStr += '"' + attrValueStr.replace(/"/g, '"') + '"'; - } else { - attrStr += attrValueStr; - } - } - } - str += attrStr; - } - } - if (this.selfClosing && !isVoid) { - str += '/>'; - return this.str = str; - } - str += '>'; - if (isVoid) { - return this.str = str; - } - str += fragStr; - str += '' + this.tag + '>'; - return this.str = str; - }; - }(parse_Parser_utils_stringifyStubs, config_voidElementNames); -var parse_Parser_getElement_ElementStub__ElementStub = function (types, voidElementNames, warn, camelCase, stringifyStubs, siblingsByTagName, filterAttributes, processDirective, toJSON, toString, StringStub) { - - var ElementStub, allElementNames, closedByParentClose, onPattern, sanitize, leadingWhitespace = /^\s+/, trailingWhitespace = /\s+$/; - ElementStub = function (firstToken, parser, preserveWhitespace) { - var next, attrs, filtered, proxies, item, getFrag, lowerCaseTag; - parser.pos += 1; - getFrag = function (attr) { - return { - name: attr.name, - value: attr.value ? new StringStub(attr.value) : null - }; - }; - this.tag = firstToken.name; - lowerCaseTag = firstToken.name.toLowerCase(); - if (lowerCaseTag.substr(0, 3) === 'rv-') { - warn('The "rv-" prefix for components has been deprecated. Support will be removed in a future version'); - this.tag = this.tag.substring(3); - } - preserveWhitespace = preserveWhitespace || lowerCaseTag === 'pre'; - if (firstToken.attrs) { - filtered = filterAttributes(firstToken.attrs); - attrs = filtered.attrs; - proxies = filtered.proxies; - if (parser.options.sanitize && parser.options.sanitize.eventAttributes) { - attrs = attrs.filter(sanitize); - } - if (attrs.length) { - this.attributes = attrs.map(getFrag); - } - if (proxies.length) { - this.proxies = proxies.map(processDirective); - } - if (filtered.intro) { - this.intro = processDirective(filtered.intro); - } - if (filtered.outro) { - this.outro = processDirective(filtered.outro); - } - if (filtered.decorator) { - this.decorator = processDirective(filtered.decorator); - } - } - if (firstToken.doctype) { - this.doctype = true; - } - if (firstToken.selfClosing) { - this.selfClosing = true; - } - if (voidElementNames.indexOf(lowerCaseTag) !== -1) { - this.isVoid = true; - } - if (this.selfClosing || this.isVoid) { - return; - } - this.siblings = siblingsByTagName[lowerCaseTag]; - this.items = []; - next = parser.next(); - while (next) { - if (next.mustacheType === types.CLOSING) { - break; - } - if (next.type === types.TAG) { - if (next.closing) { - if (next.name.toLowerCase() === lowerCaseTag) { - parser.pos += 1; - } - break; - } else if (this.siblings && this.siblings.indexOf(next.name.toLowerCase()) !== -1) { - break; - } - } - this.items[this.items.length] = parser.getStub(); - next = parser.next(); - } - if (!preserveWhitespace) { - item = this.items[0]; - if (item && item.type === types.TEXT) { - item.text = item.text.replace(leadingWhitespace, ''); - if (!item.text) { - this.items.shift(); - } - } - item = this.items[this.items.length - 1]; - if (item && item.type === types.TEXT) { - item.text = item.text.replace(trailingWhitespace, ''); - if (!item.text) { - this.items.pop(); - } - } - } - }; - ElementStub.prototype = { - toJSON: toJSON, - toString: toString - }; - allElementNames = 'a abbr acronym address applet area b base basefont bdo big blockquote body br button caption center cite code col colgroup dd del dfn dir div dl dt em fieldset font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img input ins isindex kbd label legend li link map menu meta noframes noscript object ol p param pre q s samp script select small span strike strong style sub sup textarea title tt u ul var article aside audio bdi canvas command data datagrid datalist details embed eventsource figcaption figure footer header hgroup keygen mark meter nav output progress ruby rp rt section source summary time track video wbr'.split(' '); - closedByParentClose = 'li dd rt rp optgroup option tbody tfoot tr td th'.split(' '); - onPattern = /^on[a-zA-Z]/; - sanitize = function (attr) { - var valid = !onPattern.test(attr.name); - return valid; - }; - return ElementStub; - }(config_types, config_voidElementNames, utils_warn, utils_camelCase, parse_Parser_utils_stringifyStubs, parse_Parser_getElement_ElementStub_utils_siblingsByTagName, parse_Parser_getElement_ElementStub_utils_filterAttributes, parse_Parser_getElement_ElementStub_utils_processDirective, parse_Parser_getElement_ElementStub_toJSON, parse_Parser_getElement_ElementStub_toString, parse_Parser_StringStub__StringStub); -var parse_Parser_getElement__getElement = function (types, ElementStub) { - - return function (token) { - if (this.options.sanitize && this.options.sanitize.elements) { - if (this.options.sanitize.elements.indexOf(token.name.toLowerCase()) !== -1) { - return null; - } - } - return new ElementStub(token, this); - }; - }(config_types, parse_Parser_getElement_ElementStub__ElementStub); -var parse_Parser__Parser = function (getText, getComment, getMustache, getElement, jsonifyStubs) { - - var Parser; - Parser = function (tokens, options) { - var stub, stubs; - this.tokens = tokens || []; - this.pos = 0; - this.options = options; - this.preserveWhitespace = options.preserveWhitespace; - stubs = []; - while (stub = this.getStub()) { - stubs.push(stub); - } - this.result = jsonifyStubs(stubs); - }; - Parser.prototype = { - getStub: function () { - var token = this.next(); - if (!token) { - return null; - } - return this.getText(token) || this.getComment(token) || this.getMustache(token) || this.getElement(token); - }, - getText: getText, - getComment: getComment, - getMustache: getMustache, - getElement: getElement, - next: function () { - return this.tokens[this.pos]; - } - }; - return Parser; - }(parse_Parser_getText__getText, parse_Parser_getComment__getComment, parse_Parser_getMustache__getMustache, parse_Parser_getElement__getElement, parse_Parser_utils_jsonifyStubs); -var parse__parse = function (tokenize, types, Parser) { - - var parse, onlyWhitespace, inlinePartialStart, inlinePartialEnd, parseCompoundTemplate; - onlyWhitespace = /^\s*$/; - inlinePartialStart = //; - inlinePartialEnd = //; - parse = function (template, options) { - var tokens, json, token; - options = options || {}; - if (inlinePartialStart.test(template)) { - return parseCompoundTemplate(template, options); - } - if (options.sanitize === true) { - options.sanitize = { - elements: 'applet base basefont body frame frameset head html isindex link meta noframes noscript object param script style title'.split(' '), - eventAttributes: true - }; - } - tokens = tokenize(template, options); - if (!options.preserveWhitespace) { - token = tokens[0]; - if (token && token.type === types.TEXT && onlyWhitespace.test(token.value)) { - tokens.shift(); - } - token = tokens[tokens.length - 1]; - if (token && token.type === types.TEXT && onlyWhitespace.test(token.value)) { - tokens.pop(); - } - } - json = new Parser(tokens, options).result; - if (typeof json === 'string') { - return [json]; - } - return json; - }; - parseCompoundTemplate = function (template, options) { - var mainTemplate, remaining, partials, name, startMatch, endMatch; - partials = {}; - mainTemplate = ''; - remaining = template; - while (startMatch = inlinePartialStart.exec(remaining)) { - name = startMatch[1]; - mainTemplate += remaining.substr(0, startMatch.index); - remaining = remaining.substring(startMatch.index + startMatch[0].length); - endMatch = inlinePartialEnd.exec(remaining); - if (!endMatch || endMatch[1] !== name) { - throw new Error('Inline partials must have a closing delimiter, and cannot be nested'); - } - partials[name] = parse(remaining.substr(0, endMatch.index), options); - remaining = remaining.substring(endMatch.index + endMatch[0].length); - } - return { - main: parse(mainTemplate, options), - partials: partials - }; - }; - return parse; - }(parse_tokenize, config_types, parse_Parser__Parser); -var render_DomFragment_Partial_getPartialDescriptor = function (errors, isClient, warn, isObject, partials, parse) { - - var getPartialDescriptor, registerPartial, getPartialFromRegistry, unpack; - getPartialDescriptor = function (root, name) { - var el, partial, errorMessage; - if (partial = getPartialFromRegistry(root, name)) { - return partial; - } - if (isClient) { - el = document.getElementById(name); - if (el && el.tagName === 'SCRIPT') { - if (!parse) { - throw new Error(errors.missingParser); - } - registerPartial(parse(el.innerHTML), name, partials); - } - } - partial = partials[name]; - if (!partial) { - errorMessage = 'Could not find descriptor for partial "' + name + '"'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - return []; - } - return unpack(partial); - }; - getPartialFromRegistry = function (registryOwner, name) { - var partial; - if (registryOwner.partials[name]) { - if (typeof registryOwner.partials[name] === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - partial = parse(registryOwner.partials[name], registryOwner.parseOptions); - registerPartial(partial, name, registryOwner.partials); - } - return unpack(registryOwner.partials[name]); - } - }; - registerPartial = function (partial, name, registry) { - var key; - if (isObject(partial)) { - registry[name] = partial.main; - for (key in partial.partials) { - if (partial.partials.hasOwnProperty(key)) { - registry[key] = partial.partials[key]; - } - } - } else { - registry[name] = partial; - } - }; - unpack = function (partial) { - if (partial.length === 1 && typeof partial[0] === 'string') { - return partial[0]; - } - return partial; - }; - return getPartialDescriptor; - }(config_errors, config_isClient, utils_warn, utils_isObject, registries_partials, parse__parse); -var render_DomFragment_Partial__Partial = function (types, getPartialDescriptor, circular) { - - var DomPartial, DomFragment; - circular.push(function () { - DomFragment = circular.DomFragment; - }); - DomPartial = function (options, docFrag) { - var parentFragment = this.parentFragment = options.parentFragment, descriptor; - this.type = types.PARTIAL; - this.name = options.descriptor.r; - this.index = options.index; - if (!options.descriptor.r) { - throw new Error('Partials must have a static reference (no expressions). This may change in a future version of Ractive.'); - } - descriptor = getPartialDescriptor(parentFragment.root, options.descriptor.r); - this.fragment = new DomFragment({ - descriptor: descriptor, - root: parentFragment.root, - pNode: parentFragment.pNode, - contextStack: parentFragment.contextStack, - owner: this - }); - if (docFrag) { - docFrag.appendChild(this.fragment.docFrag); - } - }; - DomPartial.prototype = { - firstNode: function () { - return this.fragment.firstNode(); - }, - findNextNode: function () { - return this.parentFragment.findNextNode(this); - }, - detach: function () { - return this.fragment.detach(); - }, - teardown: function (destroy) { - this.fragment.teardown(destroy); - }, - toString: function () { - return this.fragment.toString(); - }, - find: function (selector) { - return this.fragment.find(selector); - }, - findAll: function (selector, query) { - return this.fragment.findAll(selector, query); - }, - findComponent: function (selector) { - return this.fragment.findComponent(selector); - }, - findAllComponents: function (selector, query) { - return this.fragment.findAllComponents(selector, query); - } - }; - return DomPartial; - }(config_types, render_DomFragment_Partial_getPartialDescriptor, circular); -var render_DomFragment_Component_initialise_createModel_ComponentParameter = function (StringFragment) { - - var ComponentParameter = function (component, key, value) { - this.parentFragment = component.parentFragment; - this.component = component; - this.key = key; - this.fragment = new StringFragment({ - descriptor: value, - root: component.root, - owner: this, - contextStack: component.parentFragment.contextStack - }); - this.selfUpdating = this.fragment.isSimple(); - this.value = this.fragment.getValue(); - }; - ComponentParameter.prototype = { - bubble: function () { - if (this.selfUpdating) { - this.update(); - } else if (!this.deferred && this.ready) { - this.root._deferred.attrs.push(this); - this.deferred = true; - } - }, - update: function () { - var value = this.fragment.getValue(); - this.component.instance.set(this.key, value); - this.value = value; - }, - teardown: function () { - this.fragment.teardown(); - } - }; - return ComponentParameter; - }(render_StringFragment__StringFragment); -var render_DomFragment_Component_initialise_createModel__createModel = function (types, parseJSON, resolveRef, ComponentParameter) { - - return function (component, attributes, toBind) { - var data, key, value; - data = {}; - component.complexParameters = []; - for (key in attributes) { - if (attributes.hasOwnProperty(key)) { - value = getValue(component, key, attributes[key], toBind); - if (value !== undefined) { - data[key] = value; - } - } - } - return data; - }; - function getValue(component, key, descriptor, toBind) { - var parameter, parsed, root, parentFragment, keypath; - root = component.root; - parentFragment = component.parentFragment; - if (typeof descriptor === 'string') { - parsed = parseJSON(descriptor); - return parsed ? parsed.value : descriptor; - } - if (descriptor === null) { - return true; - } - if (descriptor.length === 1 && descriptor[0].t === types.INTERPOLATOR && descriptor[0].r) { - if (parentFragment.indexRefs && parentFragment.indexRefs[descriptor[0].r] !== undefined) { - return parentFragment.indexRefs[descriptor[0].r]; - } - keypath = resolveRef(root, descriptor[0].r, parentFragment.contextStack) || descriptor[0].r; - toBind.push({ - childKeypath: key, - parentKeypath: keypath - }); - return root.get(keypath); - } - parameter = new ComponentParameter(component, key, descriptor); - component.complexParameters.push(parameter); - return parameter.value; - } - }(config_types, utils_parseJSON, shared_resolveRef, render_DomFragment_Component_initialise_createModel_ComponentParameter); -var render_DomFragment_Component_initialise_createInstance = function () { - - return function (component, Component, data, docFrag, contentDescriptor) { - var instance, parentFragment, partials, root; - parentFragment = component.parentFragment; - root = component.root; - partials = { content: contentDescriptor || [] }; - instance = new Component({ - el: parentFragment.pNode.cloneNode(false), - data: data, - partials: partials, - _parent: root, - adaptors: root.adaptors - }); - instance.component = component; - component.instance = instance; - instance.insert(docFrag); - instance.fragment.pNode = parentFragment.pNode; - return instance; - }; - }(); -var render_DomFragment_Component_initialise_createObservers = function () { - - var observeOptions = { - init: false, - debug: true - }; - return function (component, toBind) { - var pair, i; - component.observers = []; - i = toBind.length; - while (i--) { - pair = toBind[i]; - bind(component, pair.parentKeypath, pair.childKeypath); - } - }; - function bind(component, parentKeypath, childKeypath) { - var parentInstance, childInstance, settingParent, settingChild, observers, observer, value; - parentInstance = component.root; - childInstance = component.instance; - observers = component.observers; - observer = parentInstance.observe(parentKeypath, function (value) { - if (!settingParent && !parentInstance._wrapped[parentKeypath]) { - settingChild = true; - childInstance.set(childKeypath, value); - settingChild = false; - } - }, observeOptions); - observers.push(observer); - if (childInstance.twoway) { - observer = childInstance.observe(childKeypath, function (value) { - if (!settingChild) { - settingParent = true; - parentInstance.set(parentKeypath, value); - settingParent = false; - } - }, observeOptions); - observers.push(observer); - value = childInstance.get(childKeypath); - if (value !== undefined) { - parentInstance.set(parentKeypath, value); - } - } - } - }(); -var render_DomFragment_Component_initialise_propagateEvents = function (warn) { - - var errorMessage = 'Components currently only support simple events - you cannot include arguments. Sorry!'; - return function (component, eventsDescriptor) { - var eventName; - for (eventName in eventsDescriptor) { - if (eventsDescriptor.hasOwnProperty(eventName)) { - propagateEvent(component.instance, component.root, eventName, eventsDescriptor[eventName]); - } - } - }; - function propagateEvent(childInstance, parentInstance, eventName, proxyEventName) { - if (typeof proxyEventName !== 'string') { - if (parentInstance.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - return; - } - } - childInstance.on(eventName, function () { - var args = Array.prototype.slice.call(arguments); - args.unshift(proxyEventName); - parentInstance.fire.apply(parentInstance, args); - }); - } - }(utils_warn); -var render_DomFragment_Component_initialise_updateLiveQueries = function () { - - return function (component) { - var ancestor, query; - ancestor = component.root; - while (ancestor) { - if (query = ancestor._liveComponentQueries[component.name]) { - query.push(component.instance); - } - ancestor = ancestor._parent; - } - }; - }(); -var render_DomFragment_Component_initialise__initialise = function (types, warn, createModel, createInstance, createObservers, propagateEvents, updateLiveQueries) { - - return function (component, options, docFrag) { - var parentFragment, root, Component, data, toBind; - parentFragment = component.parentFragment = options.parentFragment; - root = parentFragment.root; - component.root = root; - component.type = types.COMPONENT; - component.name = options.descriptor.e; - component.index = options.index; - component.observers = []; - Component = root.components[options.descriptor.e]; - if (!Component) { - throw new Error('Component "' + options.descriptor.e + '" not found'); - } - toBind = []; - data = createModel(component, options.descriptor.a, toBind); - createInstance(component, Component, data, docFrag, options.descriptor.f); - createObservers(component, toBind); - propagateEvents(component, options.descriptor.v); - if (options.descriptor.t1 || options.descriptor.t2 || options.descriptor.o) { - warn('The "intro", "outro" and "decorator" directives have no effect on components'); - } - updateLiveQueries(component); - }; - }(config_types, utils_warn, render_DomFragment_Component_initialise_createModel__createModel, render_DomFragment_Component_initialise_createInstance, render_DomFragment_Component_initialise_createObservers, render_DomFragment_Component_initialise_propagateEvents, render_DomFragment_Component_initialise_updateLiveQueries); -var render_DomFragment_Component__Component = function (initialise) { - - var DomComponent = function (options, docFrag) { - initialise(this, options, docFrag); - }; - DomComponent.prototype = { - firstNode: function () { - return this.instance.fragment.firstNode(); - }, - findNextNode: function () { - return this.parentFragment.findNextNode(this); - }, - detach: function () { - return this.instance.fragment.detach(); - }, - teardown: function () { - var query; - while (this.complexParameters.length) { - this.complexParameters.pop().teardown(); - } - while (this.observers.length) { - this.observers.pop().cancel(); - } - if (query = this.root._liveComponentQueries[this.name]) { - query._remove(this); - } - this.instance.teardown(); - }, - toString: function () { - return this.instance.fragment.toString(); - }, - find: function (selector) { - return this.instance.fragment.find(selector); - }, - findAll: function (selector, query) { - return this.instance.fragment.findAll(selector, query); - }, - findComponent: function (selector) { - if (!selector || selector === this.name) { - return this.instance; - } - return null; - }, - findAllComponents: function (selector, query) { - query._test(this, true); - if (this.instance.fragment) { - this.instance.fragment.findAllComponents(selector, query); - } - } - }; - return DomComponent; - }(render_DomFragment_Component_initialise__initialise); -var render_DomFragment_Comment = function (types) { - - var DomComment = function (options, docFrag) { - this.type = types.COMMENT; - this.descriptor = options.descriptor; - if (docFrag) { - this.node = document.createComment(options.descriptor.f); - docFrag.appendChild(this.node); - } - }; - DomComment.prototype = { - detach: function () { - this.node.parentNode.removeChild(this.node); - return this.node; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - } - }, - firstNode: function () { - return this.node; - }, - toString: function () { - return ''; - } - }; - return DomComment; - }(config_types); -var render_DomFragment__DomFragment = function (types, matches, initFragment, insertHtml, Text, Interpolator, Section, Triple, Element, Partial, Component, Comment, circular) { - - var DomFragment = function (options) { - if (options.pNode) { - this.docFrag = document.createDocumentFragment(); - } - if (typeof options.descriptor === 'string') { - this.html = options.descriptor; - if (this.docFrag) { - this.nodes = insertHtml(this.html, options.pNode.tagName, this.docFrag); - } - } else { - initFragment(this, options); - } - }; - DomFragment.prototype = { - detach: function () { - var len, i; - if (this.nodes) { - i = this.nodes.length; - while (i--) { - this.docFrag.appendChild(this.nodes[i]); - } - } else if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - this.docFrag.appendChild(this.items[i].detach()); - } - } - return this.docFrag; - }, - createItem: function (options) { - if (typeof options.descriptor === 'string') { - return new Text(options, this.docFrag); - } - switch (options.descriptor.t) { - case types.INTERPOLATOR: - return new Interpolator(options, this.docFrag); - case types.SECTION: - return new Section(options, this.docFrag); - case types.TRIPLE: - return new Triple(options, this.docFrag); - case types.ELEMENT: - if (this.root.components[options.descriptor.e]) { - return new Component(options, this.docFrag); - } - return new Element(options, this.docFrag); - case types.PARTIAL: - return new Partial(options, this.docFrag); - case types.COMMENT: - return new Comment(options, this.docFrag); - default: - throw new Error('Something very strange happened. Please file an issue at https://github.com/RactiveJS/Ractive/issues. Thanks!'); - } - }, - teardown: function (destroy) { - var node; - if (this.nodes && destroy) { - while (node = this.nodes.pop()) { - node.parentNode.removeChild(node); - } - } else if (this.items) { - while (this.items.length) { - this.items.pop().teardown(destroy); - } - } - this.nodes = this.items = this.docFrag = null; - }, - firstNode: function () { - if (this.items && this.items[0]) { - return this.items[0].firstNode(); - } else if (this.nodes) { - return this.nodes[0] || null; - } - return null; - }, - findNextNode: function (item) { - var index = item.index; - if (this.items[index + 1]) { - return this.items[index + 1].firstNode(); - } - if (this.owner === this.root) { - if (!this.owner.component) { - return null; - } - return this.owner.component.findNextNode(); - } - return this.owner.findNextNode(this); - }, - toString: function () { - var html, i, len, item; - if (this.html) { - return this.html; - } - html = ''; - if (!this.items) { - return html; - } - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - html += item.toString(); - } - return html; - }, - find: function (selector) { - var i, len, item, node, queryResult; - if (this.nodes) { - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - return node; - } - if (queryResult = node.querySelector(selector)) { - return queryResult; - } - } - return null; - } - if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.find && (queryResult = item.find(selector))) { - return queryResult; - } - } - return null; - } - }, - findAll: function (selector, query) { - var i, len, item, node, queryAllResult, numNodes, j; - if (this.nodes) { - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - query.push(node); - } - if (queryAllResult = node.querySelectorAll(selector)) { - numNodes = queryAllResult.length; - for (j = 0; j < numNodes; j += 1) { - query.push(queryAllResult[j]); - } - } - } - } else if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.findAll) { - item.findAll(selector, query); - } - } - } - return query; - }, - findComponent: function (selector) { - var len, i, item, queryResult; - if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.findComponent && (queryResult = item.findComponent(selector))) { - return queryResult; - } - } - return null; - } - }, - findAllComponents: function (selector, query) { - var i, len, item; - if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.findAllComponents) { - item.findAllComponents(selector, query); - } - } - } - return query; - } - }; - circular.DomFragment = DomFragment; - return DomFragment; - }(config_types, utils_matches, render_shared_initFragment, render_DomFragment_shared_insertHtml, render_DomFragment_Text, render_DomFragment_Interpolator, render_DomFragment_Section__Section, render_DomFragment_Triple, render_DomFragment_Element__Element, render_DomFragment_Partial__Partial, render_DomFragment_Component__Component, render_DomFragment_Comment, circular); -var Ractive_prototype_render = function (getElement, makeTransitionManager, preDomUpdate, postDomUpdate, DomFragment) { - - return function (target, complete) { - var transitionManager; - if (!this._initing) { - throw new Error('You cannot call ractive.render() directly!'); - } - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - this.fragment = new DomFragment({ - descriptor: this.template, - root: this, - owner: this, - pNode: target - }); - preDomUpdate(this); - if (target) { - target.appendChild(this.fragment.docFrag); - } - postDomUpdate(this); - this._transitionManager = null; - transitionManager.ready(); - this.rendered = true; - }; - }(utils_getElement, shared_makeTransitionManager, shared_preDomUpdate, shared_postDomUpdate, render_DomFragment__DomFragment); -var Ractive_prototype_renderHTML = function (warn) { - - return function () { - warn('renderHTML() has been deprecated and will be removed in a future version. Please use toHTML() instead'); - return this.toHTML(); - }; - }(utils_warn); -var Ractive_prototype_toHTML = function () { - - return function () { - return this.fragment.toString(); - }; - }(); -var Ractive_prototype_teardown = function (makeTransitionManager, clearCache) { - - return function (complete) { - var keypath, transitionManager, previousTransitionManager; - this.fire('teardown'); - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - this.fragment.teardown(true); - while (this._animations[0]) { - this._animations[0].stop(); - } - for (keypath in this._cache) { - clearCache(this, keypath); - } - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - }; - }(shared_makeTransitionManager, shared_clearCache); -var Ractive_prototype_shared_add = function (isNumeric) { - - return function (root, keypath, d) { - var value; - if (typeof keypath !== 'string' || !isNumeric(d)) { - if (root.debug) { - throw new Error('Bad arguments'); - } - return; - } - value = root.get(keypath); - if (value === undefined) { - value = 0; - } - if (!isNumeric(value)) { - if (root.debug) { - throw new Error('Cannot add to a non-numeric value'); - } - return; - } - root.set(keypath, value + d); - }; - }(utils_isNumeric); -var Ractive_prototype_add = function (add) { - - return function (keypath, d) { - add(this, keypath, d === undefined ? 1 : d); - }; - }(Ractive_prototype_shared_add); -var Ractive_prototype_subtract = function (add) { - - return function (keypath, d) { - add(this, keypath, d === undefined ? -1 : -d); - }; - }(Ractive_prototype_shared_add); -var Ractive_prototype_toggle = function () { - - return function (keypath) { - var value; - if (typeof keypath !== 'string') { - if (this.debug) { - throw new Error('Bad arguments'); - } - return; - } - value = this.get(keypath); - this.set(keypath, !value); - }; - }(); -var Ractive_prototype_merge_mapOldToNewIndex = function () { - - return function (oldArray, newArray) { - var usedIndices, mapper, firstUnusedIndex, newIndices, changed; - usedIndices = {}; - firstUnusedIndex = 0; - mapper = function (item, i) { - var index, start, len; - start = firstUnusedIndex; - len = newArray.length; - do { - index = newArray.indexOf(item, start); - if (index === -1) { - changed = true; - return -1; - } - start = index + 1; - } while (usedIndices[index] && start < len); - if (index === firstUnusedIndex) { - firstUnusedIndex += 1; - } - if (index !== i) { - changed = true; - } - usedIndices[index] = true; - return index; - }; - newIndices = oldArray.map(mapper); - newIndices.unchanged = !changed; - return newIndices; - }; - }(); -var Ractive_prototype_merge_queueDependants = function (types) { - - return function queueDependants(keypath, deps, mergeQueue, updateQueue) { - var i, dependant; - i = deps.length; - while (i--) { - dependant = deps[i]; - if (dependant.type === types.REFERENCE) { - dependant.update(); - } else if (dependant.keypath === keypath && dependant.type === types.SECTION && !dependant.inverted && dependant.docFrag) { - mergeQueue[mergeQueue.length] = dependant; - } else { - updateQueue[updateQueue.length] = dependant; - } - } - }; - }(config_types); -var Ractive_prototype_merge__merge = function (warn, isArray, clearCache, preDomUpdate, processDeferredUpdates, makeTransitionManager, notifyDependants, replaceData, mapOldToNewIndex, queueDependants) { - - var identifiers = {}; - return function (keypath, array, options) { - var currentArray, oldArray, newArray, identifier, lengthUnchanged, i, newIndices, mergeQueue, updateQueue, depsByKeypath, deps, transitionManager, previousTransitionManager, upstreamQueue, keys; - currentArray = this.get(keypath); - if (!isArray(currentArray) || !isArray(array)) { - return this.set(keypath, array, options && options.complete); - } - lengthUnchanged = currentArray.length === array.length; - if (options && options.compare) { - if (options.compare === true) { - identifier = stringify; - } else if (typeof options.compare === 'string') { - identifier = getIdentifier(options.compare); - } else if (typeof options.compare == 'function') { - identifier = options.compare; - } else { - throw new Error('The `compare` option must be a function, or a string representing an identifying field (or `true` to use JSON.stringify)'); - } - try { - oldArray = currentArray.map(identifier); - newArray = array.map(identifier); - } catch (err) { - if (this.debug) { - throw err; - } else { - warn('Merge operation: comparison failed. Falling back to identity checking'); - } - oldArray = currentArray; - newArray = array; - } - } else { - oldArray = currentArray; - newArray = array; - } - newIndices = mapOldToNewIndex(oldArray, newArray); - clearCache(this, keypath); - replaceData(this, keypath, array); - if (newIndices.unchanged && lengthUnchanged) { - return; - } - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, options && options.complete); - mergeQueue = []; - updateQueue = []; - for (i = 0; i < this._deps.length; i += 1) { - depsByKeypath = this._deps[i]; - if (!depsByKeypath) { - continue; - } - deps = depsByKeypath[keypath]; - if (deps) { - queueDependants(keypath, deps, mergeQueue, updateQueue); - preDomUpdate(this); - while (mergeQueue.length) { - mergeQueue.pop().merge(newIndices); - } - while (updateQueue.length) { - updateQueue.pop().update(); - } - } - } - processDeferredUpdates(this); - upstreamQueue = []; - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - upstreamQueue[upstreamQueue.length] = keys.join('.'); - } - notifyDependants.multiple(this, upstreamQueue, true); - if (oldArray.length !== newArray.length) { - notifyDependants(this, keypath + '.length', true); - } - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - }; - function stringify(item) { - return JSON.stringify(item); - } - function getIdentifier(str) { - if (!identifiers[str]) { - identifiers[str] = function (item) { - return item[str]; - }; - } - return identifiers[str]; - } - }(utils_warn, utils_isArray, shared_clearCache, shared_preDomUpdate, shared_processDeferredUpdates, shared_makeTransitionManager, shared_notifyDependants, Ractive_prototype_shared_replaceData, Ractive_prototype_merge_mapOldToNewIndex, Ractive_prototype_merge_queueDependants); -var Ractive_prototype_detach = function () { - - return function () { - return this.fragment.detach(); - }; - }(); -var Ractive_prototype_insert = function (getElement) { - - return function (target, anchor) { - target = getElement(target); - anchor = getElement(anchor) || null; - if (!target) { - throw new Error('You must specify a valid target to insert into'); - } - target.insertBefore(this.detach(), anchor); - this.fragment.pNode = target; - }; - }(utils_getElement); -var Ractive_prototype__prototype = function (get, set, update, updateModel, animate, on, off, observe, fire, find, findAll, findComponent, findAllComponents, render, renderHTML, toHTML, teardown, add, subtract, toggle, merge, detach, insert) { - - return { - get: get, - set: set, - update: update, - updateModel: updateModel, - animate: animate, - on: on, - off: off, - observe: observe, - fire: fire, - find: find, - findAll: findAll, - findComponent: findComponent, - findAllComponents: findAllComponents, - renderHTML: renderHTML, - toHTML: toHTML, - render: render, - teardown: teardown, - add: add, - subtract: subtract, - toggle: toggle, - merge: merge, - detach: detach, - insert: insert - }; - }(Ractive_prototype_get__get, Ractive_prototype_set, Ractive_prototype_update, Ractive_prototype_updateModel, Ractive_prototype_animate__animate, Ractive_prototype_on, Ractive_prototype_off, Ractive_prototype_observe__observe, Ractive_prototype_fire, Ractive_prototype_find, Ractive_prototype_findAll, Ractive_prototype_findComponent, Ractive_prototype_findAllComponents, Ractive_prototype_render, Ractive_prototype_renderHTML, Ractive_prototype_toHTML, Ractive_prototype_teardown, Ractive_prototype_add, Ractive_prototype_subtract, Ractive_prototype_toggle, Ractive_prototype_merge__merge, Ractive_prototype_detach, Ractive_prototype_insert); -var extend_registries = function () { - - return [ - 'partials', - 'transitions', - 'events', - 'components', - 'decorators', - 'data' - ]; - }(); -var extend_initOptions = function () { - - return [ - 'el', - 'template', - 'complete', - 'modifyArrays', - 'magic', - 'twoway', - 'lazy', - 'append', - 'preserveWhitespace', - 'sanitize', - 'stripComments', - 'noIntro', - 'transitionsEnabled', - 'adaptors' - ]; - }(); -var extend_inheritFromParent = function (registries, initOptions, create) { - - return function (Child, Parent) { - registries.forEach(function (property) { - if (Parent[property]) { - Child[property] = create(Parent[property]); - } - }); - initOptions.forEach(function (property) { - Child[property] = Parent[property]; - }); - }; - }(extend_registries, extend_initOptions, utils_create); -var extend_wrapMethod = function () { - - return function (method, superMethod) { - if (/_super/.test(method)) { - return function () { - var _super = this._super, result; - this._super = superMethod; - result = method.apply(this, arguments); - this._super = _super; - return result; - }; - } else { - return method; - } - }; - }(); -var extend_utils_augment = function () { - - return function (target, source) { - var key; - for (key in source) { - if (source.hasOwnProperty(key)) { - target[key] = source[key]; - } - } - return target; - }; - }(); -var extend_inheritFromChildProps = function (registries, initOptions, wrapMethod, augment) { - - var blacklist, blacklisted; - blacklist = registries.concat(initOptions); - blacklisted = {}; - blacklist.forEach(function (property) { - blacklisted[property] = true; - }); - return function (Child, childProps) { - var key, member; - registries.forEach(function (property) { - var value = childProps[property]; - if (value) { - if (Child[property]) { - augment(Child[property], value); - } else { - Child[property] = value; - } - } - }); - initOptions.forEach(function (property) { - var value = childProps[property]; - if (value !== undefined) { - if (typeof value === 'function' && typeof Child[property] === 'function') { - Child[property] = wrapMethod(value, Child[property]); - } else { - Child[property] = childProps[property]; - } - } - }); - for (key in childProps) { - if (childProps.hasOwnProperty(key) && !blacklisted[key]) { - member = childProps[key]; - if (typeof member === 'function' && typeof Child.prototype[key] === 'function') { - Child.prototype[key] = wrapMethod(member, Child.prototype[key]); - } else { - Child.prototype[key] = member; - } - } - } - }; - }(extend_registries, extend_initOptions, extend_wrapMethod, extend_utils_augment); -var extend_extractInlinePartials = function (isObject, augment) { - - return function (Child, childProps) { - if (isObject(Child.template)) { - if (!Child.partials) { - Child.partials = {}; - } - augment(Child.partials, Child.template.partials); - if (childProps.partials) { - augment(Child.partials, childProps.partials); - } - Child.template = Child.template.main; - } - }; - }(utils_isObject, extend_utils_augment); -var extend_conditionallyParseTemplate = function (errors, isClient, parse) { - - return function (Child) { - var templateEl; - if (typeof Child.template === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - if (Child.template.charAt(0) === '#' && isClient) { - templateEl = document.getElementById(Child.template.substring(1)); - if (templateEl && templateEl.tagName === 'SCRIPT') { - Child.template = parse(templateEl.innerHTML, Child); - } else { - throw new Error('Could not find template element (' + Child.template + ')'); - } - } else { - Child.template = parse(Child.template, Child); - } - } - }; - }(config_errors, config_isClient, parse__parse); -var extend_conditionallyParsePartials = function (errors, parse) { - - return function (Child) { - var key; - if (Child.partials) { - for (key in Child.partials) { - if (Child.partials.hasOwnProperty(key) && typeof Child.partials[key] === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - Child.partials[key] = parse(Child.partials[key], Child); - } - } - } - }; - }(config_errors, parse__parse); -var extend_utils_clone = function () { - - return function (source) { - var target = {}, key; - for (key in source) { - if (source.hasOwnProperty(key)) { - target[key] = source[key]; - } - } - return target; - }; - }(); -var utils_extend = function () { - - return function (target) { - var prop, source, sources = Array.prototype.slice.call(arguments, 1); - while (source = sources.shift()) { - for (prop in source) { - if (source.hasOwnProperty(prop)) { - target[prop] = source[prop]; - } - } - } - return target; - }; - }(); -var Ractive_initialise = function (isClient, errors, warn, create, extend, defineProperty, defineProperties, getElement, isObject, magicAdaptor, parse) { - - var getObject, getArray, defaultOptions, registries; - getObject = function () { - return {}; - }; - getArray = function () { - return []; - }; - defaultOptions = create(null); - defineProperties(defaultOptions, { - preserveWhitespace: { - enumerable: true, - value: false - }, - append: { - enumerable: true, - value: false - }, - twoway: { - enumerable: true, - value: true - }, - modifyArrays: { - enumerable: true, - value: true - }, - data: { - enumerable: true, - value: getObject - }, - lazy: { - enumerable: true, - value: false - }, - debug: { - enumerable: true, - value: false - }, - transitions: { - enumerable: true, - value: getObject - }, - decorators: { - enumerable: true, - value: getObject - }, - events: { - enumerable: true, - value: getObject - }, - noIntro: { - enumerable: true, - value: false - }, - transitionsEnabled: { - enumerable: true, - value: true - }, - magic: { - enumerable: true, - value: false - }, - adaptors: { - enumerable: true, - value: getArray - } - }); - registries = [ - 'components', - 'decorators', - 'events', - 'partials', - 'transitions', - 'data' - ]; - return function (ractive, options) { - var key, template, templateEl, parsedTemplate; - for (key in defaultOptions) { - if (options[key] === undefined) { - options[key] = typeof defaultOptions[key] === 'function' ? defaultOptions[key]() : defaultOptions[key]; - } - } - defineProperties(ractive, { - _initing: { - value: true, - writable: true - }, - _guid: { - value: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { - var r, v; - r = Math.random() * 16 | 0; - v = c == 'x' ? r : r & 3 | 8; - return v.toString(16); - }) - }, - _subs: { - value: create(null), - configurable: true - }, - _cache: { value: {} }, - _cacheMap: { value: create(null) }, - _deps: { value: [] }, - _depsMap: { value: create(null) }, - _patternObservers: { value: [] }, - _pendingResolution: { value: [] }, - _deferred: { value: {} }, - _evaluators: { value: create(null) }, - _twowayBindings: { value: {} }, - _transitionManager: { - value: null, - writable: true - }, - _animations: { value: [] }, - nodes: { value: {} }, - _wrapped: { value: create(null) }, - _liveQueries: { value: [] }, - _liveComponentQueries: { value: [] } - }); - defineProperties(ractive._deferred, { - attrs: { value: [] }, - evals: { value: [] }, - selectValues: { value: [] }, - checkboxes: { value: [] }, - radios: { value: [] }, - observers: { value: [] }, - transitions: { value: [] }, - liveQueries: { value: [] }, - decorators: { value: [] }, - focusable: { - value: null, - writable: true - } - }); - ractive.adaptors = options.adaptors; - ractive.modifyArrays = options.modifyArrays; - ractive.magic = options.magic; - ractive.twoway = options.twoway; - ractive.lazy = options.lazy; - ractive.debug = options.debug; - if (ractive.magic && !magicAdaptor) { - throw new Error('Getters and setters (magic mode) are not supported in this browser'); - } - if (options._parent) { - defineProperty(ractive, '_parent', { value: options._parent }); - } - if (options.el) { - ractive.el = getElement(options.el); - if (!ractive.el && ractive.debug) { - throw new Error('Could not find container element'); - } - } - if (options.eventDefinitions) { - warn('ractive.eventDefinitions has been deprecated in favour of ractive.events. Support will be removed in future versions'); - options.events = options.eventDefinitions; - } - registries.forEach(function (registry) { - if (ractive.constructor[registry]) { - ractive[registry] = extend(create(ractive.constructor[registry] || {}), options[registry]); - } else if (options[registry]) { - ractive[registry] = options[registry]; - } - }); - template = options.template; - if (typeof template === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - if (template.charAt(0) === '#' && isClient) { - templateEl = document.getElementById(template.substring(1)); - if (templateEl) { - parsedTemplate = parse(templateEl.innerHTML, options); - } else { - throw new Error('Could not find template element (' + template + ')'); - } - } else { - parsedTemplate = parse(template, options); - } - } else { - parsedTemplate = template; - } - if (isObject(parsedTemplate)) { - extend(ractive.partials, parsedTemplate.partials); - parsedTemplate = parsedTemplate.main; - } - if (parsedTemplate && parsedTemplate.length === 1 && typeof parsedTemplate[0] === 'string') { - parsedTemplate = parsedTemplate[0]; - } - ractive.template = parsedTemplate; - extend(ractive.partials, options.partials); - ractive.parseOptions = { - preserveWhitespace: options.preserveWhitespace, - sanitize: options.sanitize, - stripComments: options.stripComments - }; - ractive.transitionsEnabled = options.noIntro ? false : options.transitionsEnabled; - if (isClient && !ractive.el) { - ractive.el = document.createDocumentFragment(); - } - if (ractive.el && !options.append) { - ractive.el.innerHTML = ''; - } - ractive.render(ractive.el, options.complete); - ractive.transitionsEnabled = options.transitionsEnabled; - ractive._initing = false; - }; - }(config_isClient, config_errors, utils_warn, utils_create, utils_extend, utils_defineProperty, utils_defineProperties, utils_getElement, utils_isObject, Ractive_prototype_get_magicAdaptor, parse__parse); -var extend_initChildInstance = function (fillGaps, initOptions, clone, wrapMethod, initialise) { - - return function (child, Child, options) { - initOptions.forEach(function (property) { - var value = options[property], defaultValue = Child[property]; - if (typeof value === 'function' && typeof defaultValue === 'function') { - options[property] = wrapMethod(value, defaultValue); - } else if (value === undefined && defaultValue !== undefined) { - options[property] = defaultValue; - } - }); - if (child.beforeInit) { - child.beforeInit(options); - } - initialise(child, options); - if (child.init) { - child.init(options); - } - }; - }(utils_fillGaps, extend_initOptions, extend_utils_clone, extend_wrapMethod, Ractive_initialise); -var extend__extend = function (create, inheritFromParent, inheritFromChildProps, extractInlinePartials, conditionallyParseTemplate, conditionallyParsePartials, initChildInstance, circular) { - - var Ractive; - circular.push(function () { - Ractive = circular.Ractive; - }); - return function (childProps) { - var Parent = this, Child; - Child = function (options) { - initChildInstance(this, Child, options || {}); - }; - Child.prototype = create(Parent.prototype); - Child.prototype.constructor = Child; - inheritFromParent(Child, Parent); - inheritFromChildProps(Child, childProps); - conditionallyParseTemplate(Child); - extractInlinePartials(Child, childProps); - conditionallyParsePartials(Child); - Child.extend = Parent.extend; - return Child; - }; - }(utils_create, extend_inheritFromParent, extend_inheritFromChildProps, extend_extractInlinePartials, extend_conditionallyParseTemplate, extend_conditionallyParsePartials, extend_initChildInstance, circular); -var Ractive__Ractive = function (svg, create, defineProperties, prototype, partialRegistry, adaptorRegistry, easingRegistry, Ractive_extend, parse, initialise, circular) { - - var Ractive = function (options) { - initialise(this, options); - }; - defineProperties(Ractive, { - prototype: { value: prototype }, - partials: { value: partialRegistry }, - adaptors: { value: adaptorRegistry }, - easing: { value: easingRegistry }, - transitions: { value: {} }, - events: { value: {} }, - components: { value: {} }, - decorators: { value: {} }, - svg: { value: svg }, - VERSION: { value: '0.3.9' } - }); - Ractive.eventDefinitions = Ractive.events; - Ractive.prototype.constructor = Ractive; - Ractive.delimiters = [ - '{{', - '}}' - ]; - Ractive.tripleDelimiters = [ - '{{{', - '}}}' - ]; - Ractive.extend = Ractive_extend; - Ractive.parse = parse; - circular.Ractive = Ractive; - return Ractive; - }(config_svg, utils_create, utils_defineProperties, Ractive_prototype__prototype, registries_partials, registries_adaptors, registries_easing, extend__extend, parse__parse, Ractive_initialise, circular); -var Ractive = function (Ractive, circular) { - - if (typeof window !== 'undefined' && window.Node && !window.Node.prototype.contains && window.HTMLElement && window.HTMLElement.prototype.contains) { - window.Node.prototype.contains = window.HTMLElement.prototype.contains; - } - while (circular.length) { - circular.pop()(); - } - return Ractive; - }(Ractive__Ractive, circular); -// export as Common JS module... -if ( typeof module !== "undefined" && module.exports ) { - module.exports = Ractive; -} - -// ... or as AMD module -else if ( typeof define === "function" && define.amd ) { - define( function () { - return Ractive; - }); -} - -// ... or as browser global -else { - global.Ractive = Ractive; -} - -}( typeof window !== 'undefined' ? window : this )); \ No newline at end of file diff --git a/build/Ractive.min.js b/build/Ractive.min.js deleted file mode 100644 index 3b52eaafc5..0000000000 --- a/build/Ractive.min.js +++ /dev/null @@ -1,4 +0,0 @@ -!function(a){var b=function(){return"undefined"!=typeof document?document&&document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure","1.1"):void 0}(),c=function(){var a;try{Object.create(null),a=Object.create}catch(b){a=function(){var a=function(){};return function(b,c){var d;return null===b?{}:(a.prototype=b,d=new a,c&&Object.defineProperties(d,c),d)}}()}return a}(),d={html:"http://www.w3.org/1999/xhtml",mathml:"http://www.w3.org/1998/Math/MathML",svg:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},e=function(a,b){return a?function(a,b){return b?document.createElementNS(b,a):document.createElement(a)}:function(a,c){if(c&&c!==b.html)throw"This browser does not support namespaces other than http://www.w3.org/1999/xhtml. The most likely cause of this error is that you're trying to render SVG in an older browser. See https://github.com/RactiveJS/Ractive/wiki/SVG-and-older-browsers for more information";return document.createElement(a)}}(b,d),f=function(){return"object"==typeof document?!0:!1}(),g=function(a){try{return Object.defineProperty({},"test",{value:0}),a&&Object.defineProperty(document.createElement("div"),"test",{value:0}),Object.defineProperty}catch(b){return function(a,b,c){a[b]=c.value}}}(f),h=function(a,b,c){try{try{Object.defineProperties({},{test:{value:0}})}catch(d){throw d}return c&&Object.defineProperties(a("div"),{test:{value:0}}),Object.defineProperties}catch(d){return function(a,c){var d;for(d in c)c.hasOwnProperty(d)&&b(a,d,c[d])}}}(e,g,f),i=function(){var a=/\[\s*(\*|[0-9]|[1-9][0-9]+)\s*\]/g;return function(b){return(b||"").replace(a,".$1")}}(),j={},k={TEXT:1,INTERPOLATOR:2,TRIPLE:3,SECTION:4,INVERTED:5,CLOSING:6,ELEMENT:7,PARTIAL:8,COMMENT:9,DELIMCHANGE:10,MUSTACHE:11,TAG:12,ATTRIBUTE:13,COMPONENT:15,NUMBER_LITERAL:20,STRING_LITERAL:21,ARRAY_LITERAL:22,OBJECT_LITERAL:23,BOOLEAN_LITERAL:24,GLOBAL:26,KEY_VALUE_PAIR:27,REFERENCE:30,REFINEMENT:31,MEMBER:32,PREFIX_OPERATOR:33,BRACKETED:34,CONDITIONAL:35,INFIX_OPERATOR:36,INVOCATION:40},l=function(){var a=Object.prototype.toString;return function(b){return"[object Array]"===a.call(b)}}(),m=function(){return function a(b,c){var d,e;if((e=b._wrapped[c])&&e.teardown()!==!1&&(b._wrapped[c]=null),b._cache[c]=void 0,d=b._cacheMap[c])for(;d.length;)a(b,d.pop())}}(),n=function(){return function(a,b){var c,d,e,f,g,h;for(c=[],h=a.rendered?a.el:a.fragment.docFrag,d=h.querySelectorAll('input[type="checkbox"][name="{{'+b+'}}"]'),f=d.length,g=0;f>g;g+=1)e=d[g],(e.hasAttribute("checked")||e.checked)&&(c[c.length]=e._ractive.value);return c}}(),o=function(a){return function(b){var c,d,e,f,g,h;for(c=b._deferred;d=c.evals.pop();)d.update().deferred=!1;for(;e=c.selectValues.pop();)e.deferredUpdate();for(;f=c.attrs.pop();)f.update().deferred=!1;for(;g=c.checkboxes.pop();)b.set(g,a(b,g));for(;h=c.radios.pop();)h.update()}}(n),p=function(){return function(a){var b,c,d,e,f,g;for(b=a._deferred,(c=b.focusable)&&(c.focus(),b.focusable=null);d=b.liveQueries.pop();)d._sort();for(;e=b.decorators.pop();)e.init();for(;f=b.transitions.pop();)f.init();for(;g=b.observers.pop();)g.update()}}(),q=function(){var a=function(a,b){var c,d,e,f;return a._parent&&a._parent._transitionManager?a._parent._transitionManager:(d=[],e=function(){var a,b;for(a=d.length;a--;)b=d[a],f(b.node)&&(b.detach(),d.splice(a,1))},f=function(a){var b,d;for(b=c.active.length;b--;)if(d=c.active[b],a.contains(d))return!1;return!0},c={active:[],push:function(a){c.active[c.active.length]=a},pop:function(a){var b;b=c.active.indexOf(a),-1!==b&&(c.active.splice(b,1),e(),!c.active.length&&c._ready&&c.complete())},complete:function(){b&&b.call(a)},ready:function(){e(),c._ready=!0,c.active.length||c.complete()},detachWhenReady:function(a){d[d.length]=a}})};return a}(),r=function(){function a(a,d,e,f){var g=a._deps[e];g&&(b(g[d]),f||c(a._depsMap[d],a,e))}function b(a){var b,c;if(a)for(c=a.length,b=0;c>b;b+=1)a[b].update()}function c(b,c,d,e){var f;if(b)for(f=b.length;f--;)a(c,b[f],d,e)}function d(a,b,c,f,g){var i,j,k,l,m,n,o,p;for(i=a._patternObservers.length;i--;)j=a._patternObservers[i],j.regex.test(c)&&j.update(c);f||(p=function(b){if(k=a._depsMap[b])for(i=k.length;i--;)l=k[i],m=h.exec(l)[0],n=c+"."+m,d(a,l,n)},g?(o=e(c),o.forEach(p)):p(b))}function e(a){var b,c,d,e,g,h;for(b=a.split("."),c=f(b.length),g=[],d=function(a,c){return a?"*":b[c]},e=c.length;e--;)h=c[e].map(d).join("."),g[h]||(g[g.length]=h,g[h]=!0);return g}function f(a){var b,c,d,e,f,g="";if(!i[a]){for(d=[];g.length=f;f+=1){for(c=f.toString(2);c.length2&&f[1])for(q=Math.min(f[1],f.length-2),r=f[0],s=r+q,f[1]===f.length-2&&(u=!0),p=r;s>p;p+=1)t=g+"."+p,h(a,t);for(e(a),m=[],l=g.split(".");l.length;)l.pop(),m[m.length]=l.join(".");h.multiple(a,m,!0),u||h(a,g+".length",!0)},i=function(b,c,d,e){var f,g;for(f=c.length;f--;)g=c[f],g.type===a.REFERENCE?g.update():g.keypath===b&&g.type===a.SECTION&&!g.inverted&&g.docFrag?d[d.length]=g:e[e.length]=g},j=b._ractive.wrappers,l=j.length;l--;)k=j[l],g(k.root,k.keypath)},n=[],p=["pop","push","reverse","shift","sort","splice","unshift"],q=function(){},p.forEach(function(a){var c=function(){var b,c,d,h,i={},k={};for(b=Array.prototype[a].apply(this,arguments),c=this._ractive.instances,h=c.length;h--;)d=c[h],i[d._guid]=d._transitionManager,d._transitionManager=k[d._guid]=g(d,q);for(this._ractive.setting=!0,j(this,a,arguments),this._ractive.setting=!1,h=c.length;h--;)d=c[h],d._transitionManager=i[d._guid],k[d._guid].ready(),e(d),f(d);return b};b(n,a,{value:c})}),o={},o.__proto__?(l=function(a){a.__proto__=n},m=function(a){a.__proto__=Array.prototype}):(l=function(a){var c,d;for(c=p.length;c--;)d=p[c],b(a,d,{value:n[d],configurable:!0})},m=function(a){var b;for(b=p.length;b--;)delete a[p[b]]}),r="Something went wrong in a rather interesting way",i}(k,g,l,m,o,p,q,r),t=function(){var a,b;try{Object.defineProperty({},"test",{value:0})}catch(c){return!1}return a={filter:function(a,b){return!!b},wrap:function(a,c,d){return new b(a,c,d)}},b=function(a,b,c){var d,e,f,g,h,i,j,k,l,m=this;if(this.ractive=a,this.keypath=c,d=c.split("."),this.prop=d.pop(),f=d.join("."),this.obj=f?a.get(f):a.data,g=this.originalDescriptor=Object.getOwnPropertyDescriptor(this.obj,this.prop),g&&g.set&&(h=g.set._ractiveWrappers))return-1===h.indexOf(this)&&h.push(this),void 0;if(g&&!g.configurable)throw new Error('Cannot use magic mode with property "'+e+'" - object is not configurable');g&&(this.value=g.value,i=g.get,j=g.set),k=i||function(){return m.value},l=function(a){var b,c,d;for(j&&j(a),b=l._ractiveWrappers,d=b.length;d--;)c=b[d],c.resetting||c.ractive.set(c.keypath,a)},l._ractiveWrappers=[this],Object.defineProperty(this.obj,this.prop,{get:k,set:l,enumerable:!0,configurable:!0})},b.prototype={get:function(){return this.value},reset:function(a){this.resetting=!0,this.value=a,this.resetting=!1},teardown:function(){var a,b,c,d;a=Object.getOwnPropertyDescriptor(this.obj,this.prop),b=a.set,d=b._ractiveWrappers,d.splice(d.indexOf(this),1),d.length||(c=this.obj[this.prop],Object.defineProperty(this.obj,this.prop,this.originalDescriptor||{writable:!0,enumerable:!0,configrable:!0}),this.obj[this.prop]=c)}},a}(),u=function(a,b,c){function d(a,b){var c,d={};if(!b)return a;b+=".";for(c in a)a.hasOwnProperty(c)&&(d[b+c]=a[c]);return d}function e(a){var b;return f[a]||(b=a?a+".":"",f[a]=function(c,e){var f;return"string"==typeof c?(f={},f[b+c]=e,f):"object"==typeof c?b?d(c,a):c:void 0}),f[a]}var f={};return function(d,f,g,h){var i,j,k,l;for(i=d.adaptors.length,j=0;i>j;j+=1){if(k=d.adaptors[j],"string"==typeof k){if(!a[k])throw new Error('Missing adaptor "'+k+'"');k=d.adaptors[j]=a[k]}if(k.filter(g,f,d))return l=d._wrapped[f]=k.wrap(d,g,f,e(f)),l.value=g,void 0}h||(d.magic&&c.filter(g,f,d)?d._wrapped[f]=c.wrap(d,g,f):d.modifyArrays&&b.filter(g,f,d)&&(d._wrapped[f]=b.wrap(d,g,f)))}}(j,s,t),v=function(a,b,c){var d,e,f;return d=function(a){return this._captured&&!this._captured[a]&&(this._captured.push(a),this._captured[a]=!0),e(this,a)},e=function(b,d){var e,g,h,i,j;return d=a(d),e=b._cache,void 0!==(g=e[d])?g:((i=b._wrapped[d])?h=i.value:d?h=(j=b._evaluators[d])?j.value:f(b,d):(c(b,"",b.data),h=b.data),e[d]=h,h)},f=function(a,b){var d,f,g,h,i,j,k;return d=b.split("."),f=d.pop(),g=d.join("."),h=e(a,g),(k=a._wrapped[g])&&(h=k.get()),null!==h&&void 0!==h?((i=a._cacheMap[g])?-1===i.indexOf(b)&&(i[i.length]=b):a._cacheMap[g]=[b],j=h[f],c(a,b,j),a._cache[b]=j,j):void 0},d}(i,j,u),w=function(){var a=Object.prototype.toString;return function(b){return"object"==typeof b&&"[object Object]"===a.call(b)}}(),x=function(){return function(a,b){return null===a&&null===b?!0:"object"==typeof a||"object"==typeof b?!1:a===b}}(),y=function(){var a;return a=function(a,b,c){var d,e,f,g,h,i,j,k,l,m,n;if(n='Could not resolve reference - too many "../" prefixes',"."===b){if(!c.length)return"";d=c[c.length-1]}else if("."===b.charAt(0))if(m=c[c.length-1],g=m?m.split("."):[],"../"===b.substr(0,3)){for(;"../"===b.substr(0,3);){if(!g.length)throw new Error(n);g.pop(),b=b.substring(3)}g.push(b),d=g.join(".")}else d=m?m+b:b.substring(1);else{for(e=b.split("."),f=e.pop(),i=e.length?"."+e.join("."):"",c=c.concat();c.length;)if(h=c.pop(),j=h+i,k=a.get(j),(l=a._wrapped[j])&&(k=l.get()),"object"==typeof k&&null!==k&&k.hasOwnProperty(f)){d=h+"."+b;break}d||void 0===a.get(b)||(d=b)}return d?d.replace(/^\./,""):d}}(),z=function(a){var b=Array.prototype.push;return function(c){for(var d,e,f;d=c._pendingResolution.pop();)e=a(c,d.ref,d.contextStack),void 0!==e?d.resolve(e):(f||(f=[])).push(d);f&&b.apply(c._pendingResolution,f)}}(y),A=function(a,b){return function(c){a(c),b(c)}}(o,p),B=function(){return function(a,b,c){var d,e,f,g,h,i,j;for(d=b.split("."),e=[],(f=a._wrapped[""])?(f.set&&f.set(d.join("."),c),g=f.get()):g=a.data;d.length>1;)h=e[e.length]=d.shift(),i=e.join("."),(f=a._wrapped[i])?(f.set&&f.set(d.join("."),c),g=f.get()):(g.hasOwnProperty(h)||(j||(j=i),g[h]=/^\s*[0-9]+\s*$/.test(d[0])?[]:{}),g=g[h]);return h=d[0],g[h]=c,j}}(),C=function(a,b,c,d,e,f,g,h,i){var j,k,l,m;return j=function(b,d,i){var j,m,n,o,p,q,r;if(m=[],a(b)&&(j=b,i=d),j)for(b in j)j.hasOwnProperty(b)&&(d=j[b],b=c(b),k(this,b,d,m));else b=c(b),k(this,b,d,m);if(m.length){if(o=this._transitionManager,this._transitionManager=p=g(this,i),n=l(m),n.length&&e.multiple(this,n,!0),e.multiple(this,m),this._pendingResolution.length&&f(this),h(this),this._transitionManager=o,p.ready(),!this.firingChangeEvent){for(this.firingChangeEvent=!0,r={},q=m.length;q--;)r[m[q]]=this.get(m[q]);this.fire("change",r),this.firingChangeEvent=!1}return this}},k=function(a,b,c,e){var f,g,h,j,k;if(!(h=a._wrapped[b])||!h.reset||m(a,b,c,h,e)===!1){if((k=a._evaluators[b])&&(k.value=c),f=a._cache[b],g=a.get(b),g===c||k){if(c===f&&"object"!=typeof c)return}else j=i(a,b,c);d(a,j||b),e[e.length]=b}},l=function(a){var b,c,d,e,f=[""];for(b=a.length;b--;)for(c=a[b],d=c.split(".");d.length>1;)d.pop(),e=d.join("."),f[e]||(f[f.length]=e,f[e]=!0);return f},m=function(a,c,e,f,g){var h,i,j,k;if(h=f.get(),!b(h,e)&&f.reset(e)===!1)return!1;if(e=f.get(),i=a._cache[c],!b(i,e)){if(a._cache[c]=e,j=a._cacheMap[c])for(k=j.length;k--;)d(a,j[k]);g[g.length]=c}},j}(w,x,i,m,r,z,q,A,B),D=function(a,b,c,d,e){return function(f,g){var h,i;return"function"==typeof f&&(g=f,f=""),i=this._transitionManager,this._transitionManager=h=a(this,g),b(this),c(this,f||""),d(this,f||""),e(this),this._transitionManager=i,h.ready(),"string"==typeof f?this.fire("update",f):this.fire("update"),this}}(q,z,m,r,A),E=function(a){return function(b,c){var d;if(!a(b)||!a(c))return!1;if(b.length!==c.length)return!1;for(d=b.length;d--;)if(b[d]!==c[d])return!1;return!0}}(l),F=function(a,b,c){function d(a,e,f,g,h){var i,j,k,l,m,n;if(i=a._twowayBindings[e])for(k=i.length;k--;)l=i[k],(!l.radioName||l.node.checked)&&(l.checkboxName?l.changed()&&!g[e]&&(g[e]=!0,g[g.length]=e):(m=l.attr.value,n=l.value(),b(m,n)||c(m,n)||(f[e]=n)));if(h&&(j=a._depsMap[e]))for(k=j.length;k--;)d(a,j[k],f,g,h)}return function(b,c){var e,f,g;if("string"!=typeof b&&(b="",c=!0),d(this,b,e={},f=[],c),g=f.length)for(;g--;)b=f[g],e[b]=a(this,b);this.set(e)}}(n,E,x),G=function(){return"undefined"!=typeof window?(function(a,b,c){var d,e;if(!c.requestAnimationFrame){for(d=0;d=this.duration?(null!==g&&this.root.set(g,this.to),this.step&&this.step(1,this.to),this.complete&&this.complete(1,this.to),f=this.root._animations.indexOf(this),-1===f&&a("Animation was not found"),this.root._animations.splice(f,1),this.running=!1,!1):(c=this.easing?this.easing(b/this.duration):b/this.duration,null!==g&&(d=this.interpolator(c),this.root.set(g,d)),this.step&&this.step(c,d),!0)):!1},stop:function(){var b;this.running=!1,b=this.root._animations.indexOf(this),-1===b&&a("Animation was not found"),this.root._animations.splice(b,1)}},c}(I,K),M=function(){return{linear:function(a){return a},easeIn:function(a){return Math.pow(a,3)},easeOut:function(a){return Math.pow(a-1,3)+1},easeInOut:function(a){return(a/=.5)<1?.5*Math.pow(a,3):.5*(Math.pow(a-2,3)+2)}}}(),N=function(a,b,c,d){function e(e,g,h,i){var j,k,l,m;return null!==g&&(m=e.get(g)),b.abort(g,e),a(m,h)?(i.complete&&i.complete(1,i.to),f):(i.easing&&(j="function"==typeof i.easing?i.easing:e.easing&&e.easing[i.easing]?e.easing[i.easing]:d[i.easing],"function"!=typeof j&&(j=null)),k=void 0===i.duration?400:i.duration,l=new c({keypath:g,from:m,to:h,root:e,duration:k,easing:j,step:i.step,complete:i.complete}),b.add(l),e._animations[e._animations.length]=l,l)}var f={stop:function(){}};return function(a,b,c){var d,f,g,h,i,j,k,l,m,n,o,p;if("object"==typeof a){c=b||{},h=c.easing,i=c.duration,g=[],j=c.step,k=c.complete,(j||k)&&(m={},c.step=null,c.complete=null,l=function(a){return function(b,c){m[a]=c}});for(d in a)a.hasOwnProperty(d)&&((j||k)&&(n=l(d),c={easing:h,duration:i},j&&(c.step=n),k&&(c.complete=n)),g[g.length]=e(this,d,a[d],c));return(j||k)&&(p={easing:h,duration:i},j&&(p.step=function(a){j(a,m)}),k&&(p.complete=function(a){k(a,m)}),g[g.length]=o=e(this,null,null,p)),{stop:function(){for(;g.length;)g.pop().stop();o&&o.stop()}}}return c=c||{},f=e(this,a,b,c),{stop:function(){f.stop()}}}}(x,H,L,M),O=function(){return function(a,b){var c,d,e=this;if("object"==typeof a){c=[];for(d in a)a.hasOwnProperty(d)&&(c[c.length]=this.on(d,a[d]));return{cancel:function(){for(;c.length;)c.pop().cancel()}}}return this._subs[a]?this._subs[a].push(b):this._subs[a]=[b],{cancel:function(){e.off(a,b)}}}}(),P=function(){return function(a,b){var c,d;if(!b)if(a)this._subs[a]=[];else for(a in this._subs)delete this._subs[a];c=this._subs[a],c&&(d=c.indexOf(b),-1!==d&&c.splice(d,1))}}(),Q=function(){return function(a){var b,c,d,e,f,g,h,i;if(g=a.root,h=a.keypath,i=a.priority,b=g._deps[i]||(g._deps[i]={}),c=b[h]||(b[h]=[]),c[c.length]=a,a.registered=!0,h)for(d=h.split(".");d.length;)d.pop(),e=d.join("."),f=g._depsMap[e]||(g._depsMap[e]=[]),void 0===f[h]&&(f[h]=0,f[f.length]=h),f[h]+=1,h=e}}(),R=function(){return function(a){var b,c,d,e,f,g,h,i;if(g=a.root,h=a.keypath,i=a.priority,b=g._deps[i][h],c=b.indexOf(a),-1===c||!a.registered)throw new Error("Attempted to remove a dependant that was no longer registered! This should not happen. If you are seeing this bug in development please raise an issue at https://github.com/RactiveJS/Ractive/issues - thanks");if(b.splice(c,1),a.registered=!1,h)for(d=h.split(".");d.length;)d.pop(),e=d.join("."),f=g._depsMap[e],f[h]-=1,f[h]||(f.splice(f.indexOf(h),1),f[h]=void 0),h=e}}(),S=function(a){var b=function(a,b,c,d){var e=this;this.root=a,this.keypath=b,this.callback=c,this.defer=d.defer,this.debug=d.debug,this.proxy={update:function(){e.reallyUpdate()}},this.priority=0,this.context=d&&d.context?d.context:a};return b.prototype={init:function(a){a!==!1?this.update():this.value=this.root.get(this.keypath)},update:function(){return this.defer&&this.ready?(this.root._deferred.observers.push(this.proxy),void 0):(this.reallyUpdate(),void 0)},reallyUpdate:function(){var b,c;if(b=this.value,c=this.root.get(this.keypath),this.value=c,!this.updating){if(this.updating=!0,!a(c,b)||!this.ready)try{this.callback.call(this.context,c,b,this.keypath)}catch(d){if(this.debug||this.root.debug)throw d}this.updating=!1}}},b}(x),T=function(){return function(a,b){var c,d,e,f,g,h,i;for(c=b.split("."),f=[],h=function(b){var c,d;c=a._wrapped[b]?a._wrapped[b].get():a.get(b);for(d in c)g.push(b+"."+d)},i=function(a){return a+"."+d};d=c.shift();)"*"===d?(g=[],f.forEach(h),f=g):f[0]?f=f.map(i):f[0]=d;return e={},f.forEach(function(b){e[b]=a.get(b)}),e}}(),U=function(a,b){var c,d=/\*/;return c=function(a,b,c,d){this.root=a,this.callback=c,this.defer=d.defer,this.debug=d.debug,this.keypath=b,this.regex=new RegExp("^"+b.replace(/\./g,"\\.").replace(/\*/g,"[^\\.]+")+"$"),this.values={},this.defer&&(this.proxies=[]),this.priority="pattern",this.context=d&&d.context?d.context:a},c.prototype={init:function(a){var c,d;if(c=b(this.root,this.keypath),a!==!1)for(d in c)c.hasOwnProperty(d)&&this.update(d);else this.values=c},update:function(a){var c;{if(!d.test(a))return this.defer&&this.ready?(this.root._deferred.observers.push(this.getProxy(a)),void 0):(this.reallyUpdate(a),void 0);c=b(this.root,a);for(a in c)c.hasOwnProperty(a)&&this.update(a)}},reallyUpdate:function(b){var c=this.root.get(b);if(this.updating)return this.values[b]=c,void 0;if(this.updating=!0,!a(c,this.values[b])||!this.ready){try{this.callback.call(this.context,c,this.values[b],b)}catch(d){if(this.debug||this.root.debug)throw d}this.values[b]=c}this.updating=!1},getProxy:function(a){var b=this;return this.proxies[a]||(this.proxies[a]={update:function(){b.reallyUpdate(a)}}),this.proxies[a]}},c}(x,T),V=function(a,b,c,d,e){var f=/\*/,g={};return function(h,i,j,k){var l,m;return i=a(i),k=k||g,f.test(i)?(l=new e(h,i,j,k),h._patternObservers.push(l),m=!0):l=new d(h,i,j,k),b(l),l.init(k.init),l.ready=!0,{cancel:function(){var a;m&&(a=h._patternObservers.indexOf(l),-1!==a&&h._patternObservers.splice(a,1)),c(l)}}}}(i,Q,R,S,U),W=function(a,b){return function(c,d,e){var f,g=[];if(a(c)){e=d;for(f in c)c.hasOwnProperty(f)&&(d=c[f],g[g.length]=b(this,f,d,e));return{cancel:function(){for(;g.length;)g.pop().cancel()}}}return b(this,c,d,e)}}(w,V),X=function(){return function(a){var b,c,d,e=this._subs[a];if(e)for(b=Array.prototype.slice.call(arguments,1),c=0,d=e.length;d>c;c+=1)e[c].apply(this,b)}}(),Y=function(){return function(a){return this.el?this.fragment.find(a):null}}(),Z=function(a,b){var c,d,e,f,g,h,i,j;if(a){for(c=b("div"),d=["matches","matchesSelector"],g=["o","ms","moz","webkit"],j=function(a){return function(b,c){return b[a](c)}},h=d.length;h--;){if(e=d[h],c[e])return j(e);for(i=g.length;i--;)if(f=g[h]+e.substr(0,1).toUpperCase()+e.substring(1),c[f])return j(f)}return function(a,b){var c,d;for(c=(a.parentNode||a.document).querySelectorAll(b),d=c.length;d--;)if(c[d]===a)return!0;return!1}}}(f,e),$=function(a){return function(b,c){var d=this._isComponentQuery?!this.selector||b.name===this.selector:a(b.node,this.selector);return d?(this.push(b.node||b.instance),c||this._makeDirty(),!0):void 0}}(Z),_=function(){return function(){var a,b,c;a=this._root[this._isComponentQuery?"liveComponentQueries":"liveQueries"],b=this.selector,c=a.indexOf(b),-1!==c&&(a.splice(c,1),a[b]=null)}}(),ab=function(){function a(a){var b;return(b=a.parentFragment)?b.owner:a.component&&(b=a.component.parentFragment)?b.owner:void 0}function b(b){var c,d;for(c=[b],d=a(b);d;)c.push(d),d=a(d);return c}return function(a,c){var d,e,f,g,h,i,j,k,l,m;for(d=b(a.component||a._ractive.proxy),e=b(c.component||c._ractive.proxy),f=d[d.length-1],g=e[e.length-1];f&&f===g;)d.pop(),e.pop(),h=f,f=d[d.length-1],g=e[e.length-1];if(f=f.component||f,g=g.component||g,l=f.parentFragment,m=g.parentFragment,l===m)return i=l.items.indexOf(f),j=m.items.indexOf(g),i-j||d.length-e.length;if(k=h.fragments)return i=k.indexOf(l),j=k.indexOf(m),i-j||d.length-e.length;throw new Error("An unexpected condition was met while comparing the position of two components. Please file an issue at https://github.com/RactiveJS/Ractive/issues - thanks!")}}(),bb=function(a){return function(b,c){var d;return b.compareDocumentPosition?(d=b.compareDocumentPosition(c),2&d?1:-1):a(b,c)}}(ab),cb=function(a,b){return function(){this.sort(this._isComponentQuery?b:a),this._dirty=!1}}(bb,ab),db=function(){return function(){this._dirty||(this._root._deferred.liveQueries.push(this),this._dirty=!0)}}(),eb=function(){return function(a){var b=this.indexOf(this._isComponentQuery?a.instance:a.node);-1!==b&&this.splice(b,1)}}(),fb=function(a,b,c,d,e,f){return function(g,h,i,j){var k;return k=[],a(k,{selector:{value:h},live:{value:i},_isComponentQuery:{value:j},_test:{value:b}}),i?(a(k,{cancel:{value:c},_root:{value:g},_sort:{value:d},_makeDirty:{value:e},_remove:{value:f},_dirty:{value:!1,writable:!0}}),k):k}}(h,$,_,cb,db,eb),gb=function(a,b,c,d){return function(a,b){var c,e;return this.el?(b=b||{},c=this._liveQueries,(e=c[a])?b&&b.live?e:e.slice():(e=d(this,a,!!b.live,!1),e.live&&(c.push(a),c[a]=e),this.fragment.findAll(a,e),e)):[]}}(I,Z,h,fb),hb=function(){return function(a){return this.fragment.findComponent(a)}}(),ib=function(a,b,c,d){return function(a,b){var c,e;return b=b||{},c=this._liveComponentQueries,(e=c[a])?b&&b.live?e:e.slice():(e=d(this,a,!!b.live,!0),e.live&&(c.push(a),c[a]=e),this.fragment.findAllComponents(a,e),e)}}(I,Z,h,fb),jb=function(){return function(a){var b;return"undefined"!=typeof window&&document&&a?a.nodeType?a:"string"==typeof a&&(b=document.getElementById(a),!b&&document.querySelector&&(b=document.querySelector(a)),b&&b.nodeType)?b:a[0]&&a[0].nodeType?a[0]:null:null}}(),kb=function(a,b){return function(c,d){var e,f,g,h,i;if(c.owner=d.owner,g=c.owner.parentFragment,c.root=d.root,c.pNode=d.pNode,c.contextStack=d.contextStack||[],c.owner.type===a.SECTION&&(c.index=d.index),g&&(h=g.indexRefs)){c.indexRefs=b(null);for(i in h)c.indexRefs[i]=h[i]}for(c.priority=g?g.priority+1:1,d.indexRef&&(c.indexRefs||(c.indexRefs={}),c.indexRefs[d.indexRef]=d.index),c.items=[],e=d.descriptor?d.descriptor.length:0,f=0;e>f;f+=1)c.items[c.items.length]=c.createItem({parentFragment:c,descriptor:d.descriptor[f],index:f})}}(k,c),lb=function(a){var b={};return function(c,d,e){var f,g=[];if(c)for(f=b[d]||(b[d]=a(d)),f.innerHTML=c;f.firstChild;)g[g.length]=f.firstChild,e.appendChild(f.firstChild);return g}}(e),mb=function(a){var b,c,d;return c=//g,b=function(b,c){this.type=a.TEXT,this.descriptor=b.descriptor,c&&(this.node=document.createTextNode(b.descriptor),c.appendChild(this.node))},b.prototype={detach:function(){return this.node.parentNode.removeChild(this.node),this.node},teardown:function(a){a&&this.detach()},firstNode:function(){return this.node},toString:function(){return(""+this.descriptor).replace(c,"<").replace(d,">")}},b}(k),nb=function(a){return function(b){if(b.keypath)a(b);else{var c=b.root._pendingResolution.indexOf(b);-1!==c&&b.root._pendingResolution.splice(c,1)}}}(R),ob=function(a,b,c,d,e){function f(a,b,d){var e,f,g;if(!h.test(a.toString()))return c(a,"_nowrap",{value:!0}),a;if(!a["_"+b._guid]){c(a,"_"+b._guid,{value:function(){var c,d,e,g;if(c=b._captured,c||(b._captured=[]),d=a.apply(b,arguments),b._captured.length)for(e=f.length;e--;)g=f[e],g.updateSoftDependencies(b._captured);return b._captured=c,d},writable:!0});for(e in a)a.hasOwnProperty(e)&&(a["_"+b._guid][e]=a[e]);a["_"+b._guid+"_evaluators"]=[]}return f=a["_"+b._guid+"_evaluators"],g=f.indexOf(d),-1===g&&f.push(d),a["_"+b._guid]}var g,h;return h=/this/,g=function(b,c,e,g,h){var i;this.evaluator=e,this.keypath=c,this.root=b,this.argNum=g,this.type=a.REFERENCE,this.priority=h,i=b.get(c),"function"==typeof i&&(i=f(i,b,e)),this.value=e.values[g]=i,d(this)},g.prototype={update:function(){var a=this.root.get(this.keypath);"function"!=typeof a||a._nowrap||(a=f(a,this.root,this.evaluator)),b(a,this.value)||(this.evaluator.values[this.argNum]=a,this.evaluator.bubble(),this.value=a)},teardown:function(){e(this)}},g}(k,x,g,Q,R),pb=function(a,b,c){var d=function(a,c,d){this.root=a,this.keypath=c,this.priority=d.priority,this.evaluator=d,b(this)};return d.prototype={update:function(){var b=this.root.get(this.keypath);a(b,this.value)||(this.evaluator.bubble(),this.value=b)},teardown:function(){c(this)}},d}(x,Q,R),qb=function(a,b,c,d,e,f,g,h,i){function j(a,b){var c,d;if(a=a.replace(/\$\{([0-9]+)\}/g,"_$1"),l[a])return l[a];for(d=[];b--;)d[b]="_"+b;return c=new Function(d.join(","),"return("+a+")"),l[a]=c,c}var k,l={};return k=function(a,b,c,d,e){var f,g;for(this.root=a,this.keypath=b,this.priority=e,this.fn=j(c,d.length),this.values=[],this.refs=[],f=d.length;f--;)(g=d[f])?g[0]?this.values[f]=g[1]:this.refs[this.refs.length]=new h(a,g[1],this,f,e):this.values[f]=void 0;this.selfUpdating=this.refs.length<=1,this.update()},k.prototype={bubble:function(){this.selfUpdating?this.update():this.deferred||(this.root._deferred.evals.push(this),this.deferred=!0)},update:function(){var b;if(this.evaluating)return this;this.evaluating=!0;try{b=this.fn.apply(null,this.values)}catch(e){if(this.root.debug)throw e;b=void 0}return a(b,this.value)||(c(this.root,this.keypath),this.root._cache[this.keypath]=b,g(this.root,this.keypath,b,!0),this.value=b,d(this.root,this.keypath)),this.evaluating=!1,this},teardown:function(){for(;this.refs.length;)this.refs.pop().teardown();c(this.root,this.keypath),this.root._evaluators[this.keypath]=null},refresh:function(){this.selfUpdating||(this.deferred=!0);for(var a=this.refs.length;a--;)this.refs[a].update();this.deferred&&(this.update(),this.deferred=!1)},updateSoftDependencies:function(a){var b,c,d;for(this.softRefs||(this.softRefs=[]),b=this.softRefs.length;b--;)d=this.softRefs[b],a[d.keypath]||(this.softRefs.splice(b,1),this.softRefs[d.keypath]=!1,d.teardown());for(b=a.length;b--;)c=a[b],this.softRefs[c]||(d=new i(this.root,c,this),this.softRefs[this.softRefs.length]=d,this.softRefs[c]=!0);this.selfUpdating=this.refs.length+this.softRefs.length<=1}},k}(x,g,m,r,Q,R,u,ob,pb),rb=function(a,b){var c=function(b,c,d,e){var f,g;g=this.root=b.root,f=a(g,c,d),void 0!==f?b.resolveRef(e,!1,f):(this.ref=c,this.argNum=e,this.resolver=b,this.contextStack=d,g._pendingResolution[g._pendingResolution.length]=this)};return c.prototype={resolve:function(a){this.keypath=a,this.resolver.resolveRef(this.argNum,!1,a)},teardown:function(){this.keypath||b(this)}},c}(y,nb),sb=function(){var a=/^(?:(?:[a-zA-Z$_][a-zA-Z$_0-9]*)|(?:[0-9]|[1-9][0-9]+))$/;return function(b){var c,d,e;for(c=b.split("."),e=c.length;e--;)if(d=c[e],"undefined"===d||!a.test(d))return!1;return!0}}(),tb=function(a,b){return function(c,d){var e,f;return e=c.replace(/\$\{([0-9]+)\}/g,function(a,b){return d[b]?d[b][1]:"undefined"}),f=a(e),b(f)?f:"${"+e.replace(/[\.\[\]]/g,"-")+"}"}}(i,sb),ub=function(a,b){function c(a,b,c){var e,f;if(e=a._depsMap[b])for(f=e.length;f--;)d(a,e[f],c)}function d(a,b,d){var e,f,g,h;for(e=a._deps.length;e--;)if(f=a._deps[e],f&&(g=f[b]))for(h=g.length;h--;)d.push(g[h]);c(a,b,d)}return function(c,e,f){var g,h,i;for(g=[],d(c,e,g),h=g.length;h--;)i=g[h],b(i),i.keypath=i.keypath.replace(e,f),a(i),i.update()}}(Q,R),vb=function(a,b,c,d){var e=function(a){var c,d,e,f,g;if(this.root=a.root,this.mustache=a,this.args=[],this.scouts=[],c=a.descriptor.x,g=a.parentFragment.indexRefs,this.str=c.s,e=this.unresolved=this.args.length=c.r?c.r.length:0,!e)return this.resolved=this.ready=!0,this.bubble(),void 0;for(d=0;e>d;d+=1)f=c.r[d],g&&void 0!==g[f]?this.resolveRef(d,!0,g[f]):this.scouts[this.scouts.length]=new b(this,f,a.contextStack,d);this.ready=!0,this.bubble()};return e.prototype={bubble:function(){var a;this.ready&&(a=this.keypath,this.keypath=c(this.str,this.args),"${"===this.keypath.substr(0,2)&&this.createEvaluator(),a?d(this.root,a,this.keypath):this.mustache.resolve(this.keypath))},teardown:function(){for(;this.scouts.length;)this.scouts.pop().teardown()},resolveRef:function(a,b,c){this.args[a]=[b,c],this.bubble(),this.resolved=!--this.unresolved},createEvaluator:function(){this.root._evaluators[this.keypath]?this.root._evaluators[this.keypath].refresh():this.root._evaluators[this.keypath]=new a(this.root,this.keypath,this.str,this.args,this.mustache.priority)}},e}(qb,rb,tb,ub),wb=function(a,b){return function(c,d){var e,f,g;g=c.parentFragment=d.parentFragment,c.root=g.root,c.contextStack=g.contextStack,c.descriptor=d.descriptor,c.index=d.index||0,c.priority=g.priority,c.type=d.descriptor.t,d.descriptor.r&&(g.indexRefs&&void 0!==g.indexRefs[d.descriptor.r]?(f=g.indexRefs[d.descriptor.r],c.indexRef=d.descriptor.r,c.value=f,c.render(c.value)):(e=a(c.root,d.descriptor.r,c.contextStack),void 0!==e?c.resolve(e):(c.ref=d.descriptor.r,c.root._pendingResolution[c.root._pendingResolution.length]=c))),d.descriptor.x&&(c.expressionResolver=new b(c)),c.descriptor.n&&!c.hasOwnProperty("value")&&c.render(void 0) -}}(y,vb),xb=function(a,b,c){return function(d){d!==this.keypath&&(this.registered&&c(this),this.keypath=d,b(this),this.update(),this.root.twoway&&this.parentFragment.owner.type===a.ATTRIBUTE&&this.parentFragment.owner.element.bind(),this.expressionResolver&&this.expressionResolver.resolved&&(this.expressionResolver=null))}}(k,Q,R),yb=function(a){return function(){var b,c;c=this.root.get(this.keypath),(b=this.root._wrapped[this.keypath])&&(c=b.get()),a(c,this.value)||(this.render(c),this.value=c)}}(x),zb=function(a,b,c,d,e){var f,g,h;return g=//g,f=function(b,d){this.type=a.INTERPOLATOR,d&&(this.node=document.createTextNode(""),d.appendChild(this.node)),c(this,b)},f.prototype={update:e,resolve:d,detach:function(){return this.node.parentNode.removeChild(this.node),this.node},teardown:function(a){a&&this.detach(),b(this)},render:function(a){this.node&&(this.node.data=void 0==a?"":a)},firstNode:function(){return this.node},toString:function(){var a=void 0!=this.value?""+this.value:"";return a.replace(g,"<").replace(h,">")}},f}(k,nb,wb,xb,yb),Ab=function(a,b,c){function d(a,b,c){var d,e,f;if(e=b.length,ea.length)for(d=a.length;e>d;d+=1)c.contextStack=a.contextStack.concat(a.keypath+"."+d),c.index=d,a.descriptor.i&&(c.indexRef=a.descriptor.i),a.fragments[d]=a.createFragment(c);a.length=e}function e(a,b,d){var e,f;f=a.fragmentsById||(a.fragmentsById=c(null));for(e in f)void 0===b[e]&&f[e]&&(f[e].teardown(!0),f[e]=null);for(e in b)void 0===b[e]||f[e]||(d.contextStack=a.contextStack.concat(a.keypath+"."+e),d.index=e,a.descriptor.i&&(d.indexRef=a.descriptor.i),f[e]=a.createFragment(d))}function f(a,b){a.length||(b.contextStack=a.contextStack.concat(a.keypath),b.index=0,a.fragments[0]=a.createFragment(b),a.length=1)}function g(b,c,d,e){var f,g,h,i;if(g=a(c)&&0===c.length,f=d?g||!c:c&&!g){if(b.length||(e.contextStack=b.contextStack,e.index=0,b.fragments[0]=b.createFragment(e),b.length=1),b.length>1)for(h=b.fragments.splice(1);i=h.pop();)i.teardown(!0)}else b.length&&(b.teardownFragments(!0),b.length=0)}return function(c,h){var i;return i={descriptor:c.descriptor.f,root:c.root,pNode:c.parentFragment.pNode,owner:c},c.descriptor.n?(g(c,h,!0,i),void 0):(a(h)?d(c,h,i):b(h)?c.descriptor.i?e(c,h,i):f(c,i):g(c,h,!1,i),void 0)}}(l,w,c),Bb=function(a,b,c){function d(b,c,g,h,i,j,k){var l,m,n,o;if(!b.html){for(b.indexRefs&&void 0!==b.indexRefs[c]&&(b.indexRefs[c]=h),l=b.contextStack.length;l--;)n=b.contextStack[l],n.substr(0,j.length)===j&&(b.contextStack[l]=n.replace(j,k));for(l=b.items.length;l--;)switch(m=b.items[l],m.type){case a.ELEMENT:e(m,c,g,h,i,j,k);break;case a.PARTIAL:d(m.fragment,c,g,h,i,j,k);break;case a.COMPONENT:d(m.instance.fragment,c,g,h,i,j,k),(o=b.root._liveComponentQueries[m.name])&&o._makeDirty();break;case a.SECTION:case a.INTERPOLATOR:case a.TRIPLE:f(m,c,g,h,i,j,k)}}}function e(a,b,c,e,f,g,h){var i,j,k,l,m,n,o,p,q,r;for(i=a.attributes.length;i--;)j=a.attributes[i],j.fragment&&(d(j.fragment,b,c,e,f,g,h),j.twoway&&j.updateBindings());if(k=a.node._ractive){k.keypath.substr(0,g.length)===g&&(k.keypath=k.keypath.replace(g,h)),void 0!==b&&(k.index[b]=e);for(l in k.events)for(m=k.events[l].proxies,i=m.length;i--;)n=m[i],"object"==typeof n.n&&d(n.a,b,c,e,f,g,h),n.d&&d(n.d,b,c,e,f,g,h);(o=k.binding)&&o.keypath.substr(0,g.length)===g&&(p=k.root._twowayBindings[o.keypath],p.splice(p.indexOf(o),1),o.keypath=o.keypath.replace(g,h),p=k.root._twowayBindings[o.keypath]||(k.root._twowayBindings[o.keypath]=[]),p.push(o))}if(a.fragment&&d(a.fragment,b,c,e,f,g,h),q=a.liveQueries)for(r=a.root,i=q.length;i--;)r._liveQueries[q[i]]._makeDirty()}function f(a,b,e,f,g,h,i){var j;if(a.descriptor.x&&(a.expressionResolver&&a.expressionResolver.teardown(),a.expressionResolver=new c(a)),a.keypath?a.keypath.substr(0,h.length)===h&&a.resolve(a.keypath.replace(h,i)):a.indexRef===b&&(a.value=f,a.render(f)),a.fragments)for(j=a.fragments.length;j--;)d(a.fragments[j],b,e,f,g,h,i)}return d}(k,R,vb),Cb=function(a,b,c){return function(a,d,e,f,g){var h,i,j,k,l,m,n;for(j=d.descriptor.i,h=e;f>h;h+=1)i=d.fragments[h],k=h-g,l=h,m=d.keypath+"."+(h-g),n=d.keypath+"."+h,i.index+=g,b(i,j,k,l,g,m,n);c(a)}}(k,Bb,o),Db=function(a){return function(b){var c,d,e,f,g,h,i,j,k,l,m=this;if(c=this.parentFragment,h=[],b.forEach(function(b,c){var f,g,j;return b===c?(h[b]=m.fragments[c],void 0):(void 0===d&&(d=c),-1===b?((i||(i=[])).push(m.fragments[c]),void 0):(f=b-c,g=m.keypath+"."+c,j=m.keypath+"."+b,a(m.fragments[c],m.descriptor.i,c,b,f,g,j),h[b]=m.fragments[c],e=!0,void 0))}),i)for(;k=i.pop();)k.teardown(!0);if(void 0===d&&(d=this.length),g=this.root.get(this.keypath).length,g!==d){for(j={descriptor:this.descriptor.f,root:this.root,pNode:c.pNode,owner:this},this.descriptor.i&&(j.indexRef=this.descriptor.i),f=d;g>f;f+=1)(k=h[f])?this.docFrag.appendChild(k.detach(!1)):(j.contextStack=this.contextStack.concat(this.keypath+"."+f),j.index=f,k=this.createFragment(j)),this.fragments[f]=k;l=c.findNextNode(this),c.pNode.insertBefore(this.docFrag,l),this.length=g}}}(Bb),Eb=function(){return[]}(),Fb=function(a,b,c,d,e,f,g,h,i,j,k){var l,m;return k.push(function(){m=k.DomFragment}),l=function(b,d){this.type=a.SECTION,this.inverted=!!b.descriptor.n,this.fragments=[],this.length=0,d&&(this.docFrag=document.createDocumentFragment()),this.initialising=!0,c(this,b),d&&d.appendChild(this.docFrag),this.initialising=!1},l.prototype={update:d,resolve:e,smartUpdate:function(a,b){var c;("push"===a||"unshift"===a||"splice"===a)&&(c={descriptor:this.descriptor.f,root:this.root,pNode:this.parentFragment.pNode,owner:this},this.descriptor.i&&(c.indexRef=this.descriptor.i)),this[a]&&(this.rendering=!0,this[a](c,b),this.rendering=!1)},pop:function(){this.length&&(this.fragments.pop().teardown(!0),this.length-=1)},push:function(a,b){var c,d,e;for(c=this.length,d=c+b.length,e=c;d>e;e+=1)a.contextStack=this.contextStack.concat(this.keypath+"."+e),a.index=e,this.fragments[e]=this.createFragment(a);this.length+=b.length,this.parentFragment.pNode.insertBefore(this.docFrag,this.parentFragment.findNextNode(this))},shift:function(){this.splice(null,[0,1])},unshift:function(a,b){this.splice(a,[0,0].concat(new Array(b.length)))},splice:function(a,b){var c,d,e,f,g,i,j,k,l;if(b.length&&(i=+(b[0]<0?this.length+b[0]:b[0]),d=Math.max(0,b.length-2),e=void 0!==b[1]?b[1]:this.length-i,e=Math.min(e,this.length-i),f=d-e)){if(0>f){for(j=i-f,g=i;j>g;g+=1)this.fragments[g].teardown(!0);this.fragments.splice(i,-f)}else{for(j=i+f,c=this.fragments[i]?this.fragments[i].firstNode():this.parentFragment.findNextNode(this),k=[i,0].concat(new Array(f)),this.fragments.splice.apply(this.fragments,k),g=i;j>g;g+=1)a.contextStack=this.contextStack.concat(this.keypath+"."+g),a.index=g,this.fragments[g]=this.createFragment(a);this.parentFragment.pNode.insertBefore(this.docFrag,c)}this.length+=f,l=i+d,h(this.root,this,l,this.length,f)}},merge:i,detach:function(){var a,b;for(b=this.fragments.length,a=0;b>a;a+=1)this.docFrag.appendChild(this.fragments[a].detach());return this.docFrag},teardown:function(a){this.teardownFragments(a),j(this)},firstNode:function(){return this.fragments[0]?this.fragments[0].firstNode():this.parentFragment.findNextNode(this)},findNextNode:function(a){return this.fragments[a.index+1]?this.fragments[a.index+1].firstNode():this.parentFragment.findNextNode(this)},teardownFragments:function(a){for(var b,c;c=this.fragments.shift();)c.teardown(a);if(this.fragmentsById)for(b in this.fragmentsById)this.fragments[b]&&(this.fragmentsById[b].teardown(a),this.fragmentsById[b]=null)},render:function(a){var c,d;(d=this.root._wrapped[this.keypath])&&(a=d.get()),this.rendering||(this.rendering=!0,f(this,a),this.rendering=!1,(!this.docFrag||this.docFrag.childNodes.length)&&!this.initialising&&b&&(c=this.parentFragment.findNextNode(this),c&&c.parentNode===this.parentFragment.pNode?this.parentFragment.pNode.insertBefore(this.docFrag,c):this.parentFragment.pNode.appendChild(this.docFrag)))},createFragment:function(a){var b=new m(a);return this.docFrag&&this.docFrag.appendChild(b.docFrag),b},toString:function(){var a,b,c,d;for(a="",b=0,d=this.length,b=0;d>b;b+=1)a+=this.fragments[b].toString();if(this.fragmentsById)for(c in this.fragmentsById)this.fragmentsById[c]&&(a+=this.fragmentsById[c].toString());return a},find:function(a){var b,c,d;for(c=this.fragments.length,b=0;c>b;b+=1)if(d=this.fragments[b].find(a))return d;return null},findAll:function(a,b){var c,d;for(d=this.fragments.length,c=0;d>c;c+=1)this.fragments[c].findAll(a,b)},findComponent:function(a){var b,c,d;for(c=this.fragments.length,b=0;c>b;b+=1)if(d=this.fragments[b].findComponent(a))return d;return null},findAllComponents:function(a,b){var c,d;for(d=this.fragments.length,c=0;d>c;c+=1)this.fragments[c].findAllComponents(a,b)}},l}(k,f,wb,yb,xb,Ab,Bb,Cb,Db,nb,Eb),Gb=function(a,b,c,d,e,f,g){var h=function(b,d){this.type=a.TRIPLE,d&&(this.nodes=[],this.docFrag=document.createDocumentFragment()),this.initialising=!0,c(this,b),d&&d.appendChild(this.docFrag),this.initialising=!1};return h.prototype={update:d,resolve:e,detach:function(){for(var a=this.nodes.length;a--;)this.docFrag.appendChild(this.nodes[a]);return this.docFrag},teardown:function(a){a&&(this.detach(),this.docFrag=this.nodes=null),g(this)},firstNode:function(){return this.nodes[0]?this.nodes[0]:this.parentFragment.findNextNode(this)},render:function(a){var b,c;if(this.nodes){for(;this.nodes.length;)b=this.nodes.pop(),b.parentNode.removeChild(b);if(!a)return this.nodes=[],void 0;c=this.parentFragment.pNode,this.nodes=f(a,c.tagName,this.docFrag),this.initialising||c.insertBefore(this.docFrag,this.parentFragment.findNextNode(this))}},toString:function(){return void 0!=this.value?this.value:""},find:function(a){var c,d,e,f;for(d=this.nodes.length,c=0;d>c;c+=1)if(e=this.nodes[c],1===e.nodeType){if(b(e,a))return e;if(f=e.querySelector(a))return f}return null},findAll:function(a,c){var d,e,f,g,h,i;for(e=this.nodes.length,d=0;e>d;d+=1)if(f=this.nodes[d],1===f.nodeType&&(b(f,a)&&c.push(f),g=f.querySelectorAll(a)))for(h=g.length,i=0;h>i;i+=1)c.push(g[i])}},h}(k,Z,wb,yb,xb,lb,nb),Hb=function(a){return function(b,c){return b.a&&b.a.xmlns?b.a.xmlns:"svg"===b.e?a.svg:c.namespaceURI||a.html}}(d),Ib=function(){var a,b,c,d;return a="altGlyph altGlyphDef altGlyphItem animateColor animateMotion animateTransform clipPath feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile feTurbulence foreignObject glyphRef linearGradient radialGradient textPath vkern".split(" "),b="attributeName attributeType baseFrequency baseProfile calcMode clipPathUnits contentScriptType contentStyleType diffuseConstant edgeMode externalResourcesRequired filterRes filterUnits glyphRef gradientTransform gradientUnits kernelMatrix kernelUnitLength keyPoints keySplines keyTimes lengthAdjust limitingConeAngle markerHeight markerUnits markerWidth maskContentUnits maskUnits numOctaves pathLength patternContentUnits patternTransform patternUnits pointsAtX pointsAtY pointsAtZ preserveAlpha preserveAspectRatio primitiveUnits refX refY repeatCount repeatDur requiredExtensions requiredFeatures specularConstant specularExponent spreadMethod startOffset stdDeviation stitchTiles surfaceScale systemLanguage tableValues targetX targetY textLength viewBox viewTarget xChannelSelector yChannelSelector zoomAndPan".split(" "),c=function(a){for(var b={},c=a.length;c--;)b[a[c].toLowerCase()]=a[c];return b},d=c(a.concat(b)),function(a){var b=a.toLowerCase();return d[b]||b}}(),Jb=function(a,b){return function(c,d){var e,f;if(e=d.indexOf(":"),-1===e||(f=d.substr(0,e),"xmlns"===f))c.name=c.element.namespace!==a.html?b(d):d,c.lcName=c.name.toLowerCase();else if(d=d.substring(e+1),c.name=b(d),c.lcName=c.name.toLowerCase(),c.namespace=a[f.toLowerCase()],!c.namespace)throw'Unknown namespace ("'+f+'")'}}(d,Ib),Kb=function(a){return function(b,c){var d,e=null===c.value?"":c.value;(d=c.pNode)&&(b.namespace?d.setAttributeNS(b.namespace,c.name,e):"style"===c.name&&d.style.setAttribute?d.style.setAttribute("cssText",e):"class"!==c.name||d.namespaceURI&&d.namespaceURI!==a.html?d.setAttribute(c.name,e):d.className=e,"id"===b.name&&(c.root.nodes[c.value]=d),"value"===b.name&&(d._ractive.value=c.value)),b.value=c.value}}(d),Lb=function(a){var b={"accept-charset":"acceptCharset",accesskey:"accessKey",bgcolor:"bgColor","class":"className",codebase:"codeBase",colspan:"colSpan",contenteditable:"contentEditable",datetime:"dateTime",dirname:"dirName","for":"htmlFor","http-equiv":"httpEquiv",ismap:"isMap",maxlength:"maxLength",novalidate:"noValidate",pubdate:"pubDate",readonly:"readOnly",rowspan:"rowSpan",tabindex:"tabIndex",usemap:"useMap"};return function(c,d){var e;!c.pNode||c.namespace||d.pNode.namespaceURI&&d.pNode.namespaceURI!==a.html||(e=b[c.name]||c.name,void 0!==d.pNode[e]&&(c.propertyName=e),("boolean"==typeof d.pNode[e]||"value"===e)&&(c.useProperty=!0))}}(d),Mb=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q,r;return e=function(){var a,b,c,d=this.pNode;return this.fragment?(a=f(this))?(this.interpolator=a,this.keypath=a.keypath||a.descriptor.r,(b=i(this))?(d._ractive.binding=this.element.binding=b,this.twoway=!0,c=this.root._twowayBindings[this.keypath]||(this.root._twowayBindings[this.keypath]=[]),c[c.length]=b,!0):!1):!1:!1},g=function(){this._ractive.binding.update()},h=function(){var a=this._ractive.root.get(this._ractive.binding.keypath);this.value=void 0==a?"":a},f=function(c){var d,e;return 1!==c.fragment.items.length?null:(d=c.fragment.items[0],d.type!==a.INTERPOLATOR?null:d.keypath||d.ref?d.keypath&&"${"===d.keypath.substr(0,2)?(e="You cannot set up two-way binding against an expression "+d.keypath,c.root.debug&&b(e),null):d:null)},i=function(a){var c=a.pNode;if("SELECT"===c.tagName)return c.multiple?new k(a,c):new l(a,c);if("checkbox"===c.type||"radio"===c.type){if("name"===a.propertyName){if("checkbox"===c.type)return new n(a,c);if("radio"===c.type)return new m(a,c)}return"checked"===a.propertyName?new o(a,c):null}return"value"!==a.lcName&&b("This is... odd"),"file"===c.type?new p(a,c):c.getAttribute("contenteditable")?new q(a,c):new r(a,c)},k=function(a,b){var c;j(this,a,b),b.addEventListener("change",g,!1),c=this.root.get(this.keypath),void 0===c&&this.update()},k.prototype={value:function(){var a,b,c,d;for(a=[],b=this.node.options,d=b.length,c=0;d>c;c+=1)b[c].selected&&(a[a.length]=b[c]._ractive.value);return a},update:function(){var a,b,d;return a=this.attr,b=a.value,d=this.value(),void 0!==b&&c(d,b)||(a.receiving=!0,a.value=d,this.root.set(this.keypath,d),a.receiving=!1),this},deferUpdate:function(){this.deferred!==!0&&(this.root._deferred.attrs.push(this),this.deferred=!0)},teardown:function(){this.node.removeEventListener("change",g,!1)}},l=function(a,b){var c;j(this,a,b),b.addEventListener("change",g,!1),c=this.root.get(this.keypath),void 0===c&&this.update()},l.prototype={value:function(){var a,b,c;for(a=this.node.options,c=a.length,b=0;c>b;b+=1)if(a[b].selected)return a[b]._ractive.value},update:function(){var a=this.value();return this.attr.receiving=!0,this.attr.value=a,this.root.set(this.keypath,a),this.attr.receiving=!1,this},deferUpdate:function(){this.deferred!==!0&&(this.root._deferred.attrs.push(this),this.deferred=!0)},teardown:function(){this.node.removeEventListener("change",g,!1)}},m=function(a,b){var c;this.radioName=!0,j(this,a,b),b.name="{{"+a.keypath+"}}",b.addEventListener("change",g,!1),b.attachEvent&&b.addEventListener("click",g,!1),c=this.root.get(this.keypath),void 0!==c?b.checked=c==b._ractive.value:this.root._deferred.radios.push(this)},m.prototype={value:function(){return this.node._ractive?this.node._ractive.value:this.node.value},update:function(){var a=this.node;a.checked&&(this.attr.receiving=!0,this.root.set(this.keypath,this.value()),this.attr.receiving=!1)},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("click",g,!1)}},n=function(a,b){var c,d;this.checkboxName=!0,j(this,a,b),b.name="{{"+this.keypath+"}}",b.addEventListener("change",g,!1),b.attachEvent&&b.addEventListener("click",g,!1),c=this.root.get(this.keypath),void 0!==c?(d=-1!==c.indexOf(b._ractive.value),b.checked=d):-1===this.root._deferred.checkboxes.indexOf(this.keypath)&&this.root._deferred.checkboxes.push(this.keypath)},n.prototype={changed:function(){return this.node.checked!==!!this.checked},update:function(){this.checked=this.node.checked,this.attr.receiving=!0,this.root.set(this.keypath,d(this.root,this.keypath)),this.attr.receiving=!1},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("click",g,!1)}},o=function(a,b){j(this,a,b),b.addEventListener("change",g,!1),b.attachEvent&&b.addEventListener("click",g,!1)},o.prototype={value:function(){return this.node.checked},update:function(){this.attr.receiving=!0,this.root.set(this.keypath,this.value()),this.attr.receiving=!1},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("click",g,!1)}},p=function(a,b){j(this,a,b),b.addEventListener("change",g,!1)},p.prototype={value:function(){return this.attr.pNode.files},update:function(){this.attr.root.set(this.attr.keypath,this.value())},teardown:function(){this.node.removeEventListener("change",g,!1)}},q=function(a,b){j(this,a,b),b.addEventListener("change",g,!1),this.root.lazy||(b.addEventListener("input",g,!1),b.attachEvent&&b.addEventListener("keyup",g,!1))},q.prototype={update:function(){this.attr.receiving=!0,this.root.set(this.keypath,this.node.innerHTML),this.attr.receiving=!1},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("input",g,!1),this.node.removeEventListener("keyup",g,!1)}},r=function(a,b){j(this,a,b),b.addEventListener("change",g,!1),this.root.lazy||(b.addEventListener("input",g,!1),b.attachEvent&&b.addEventListener("keyup",g,!1)),this.node.addEventListener("blur",h,!1)},r.prototype={value:function(){var a=this.attr.pNode.value;return+a+""===a&&-1===a.indexOf("e")&&(a=+a),a},update:function(){var a=this.attr,b=this.value();a.receiving=!0,a.root.set(a.keypath,b),a.receiving=!1},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("input",g,!1),this.node.removeEventListener("keyup",g,!1),this.node.removeEventListener("blur",h,!1)}},j=function(a,b,c){a.attr=b,a.node=c,a.root=b.root,a.keypath=b.keypath},e}(k,I,E,n),Nb=function(a,b){var c,d,e,f,g,h,i,j,k,l,m,n;return c=function(){var a;if(!this.ready)return this;if(a=this.pNode,"SELECT"===a.tagName&&"value"===this.lcName)return this.update=e,this.deferredUpdate=f,this.update();if(this.isFileInputValue)return this.update=d,this;if(this.twoway&&"name"===this.lcName){if("radio"===a.type)return this.update=i,this.update();if("checkbox"===a.type)return this.update=j,this.update()}return"style"===this.lcName&&a.style.setAttribute?(this.update=k,this.update()):"class"!==this.lcName||a.namespaceURI&&a.namespaceURI!==b.html?a.getAttribute("contenteditable")&&"value"===this.lcName?(this.update=m,this.update()):(this.update=n,this.update()):(this.update=l,this.update())},d=function(){return this},f=function(){this.deferredUpdate=this.pNode.multiple?h:g,this.deferredUpdate()},e=function(){return this.root._deferred.selectValues.push(this),this},g=function(){var a,b,c,d=this.fragment.getValue();for(this.value=this.pNode._ractive.value=d,a=this.pNode.options,c=a.length;c--;)if(b=a[c],b._ractive.value==d)return b.selected=!0,this;return this},h=function(){var b,c,d=this.fragment.getValue();for(a(d)||(d=[d]),b=this.pNode.options,c=b.length;c--;)b[c].selected=-1!==d.indexOf(b[c]._ractive.value);return this.value=d,this},i=function(){var a,b;return a=this.pNode,b=this.fragment.getValue(),a.checked=b==a._ractive.value,this},j=function(){var b,c;return b=this.pNode,c=this.fragment.getValue(),a(c)?(b.checked=-1!==c.indexOf(b._ractive.value),this):(b.checked=c==b._ractive.value,this)},k=function(){var a,b;return a=this.pNode,b=this.fragment.getValue(),void 0===b&&(b=""),b!==this.value&&(a.style.setAttribute("cssText",b),this.value=b),this},l=function(){var a,b;return a=this.pNode,b=this.fragment.getValue(),void 0===b&&(b=""),b!==this.value&&(a.className=b,this.value=b),this},m=function(){var a,b;return a=this.pNode,b=this.fragment.getValue(),void 0===b&&(b=""),b!==this.value&&(this.receiving||(a.innerHTML=b),this.value=b),this},n=function(){var a,b;if(a=this.pNode,b=this.fragment.getValue(),this.isValueAttribute&&(a._ractive.value=b),void 0===b&&(b=""),b!==this.value){if(this.useProperty)return this.receiving||(a[this.propertyName]=b),this.value=b,this;if(this.namespace)return a.setAttributeNS(this.namespace,this.name,b),this.value=b,this;"id"===this.lcName&&(void 0!==this.value&&(this.root.nodes[this.value]=void 0),this.root.nodes[b]=a),a.setAttribute(this.name,b),this.value=b}return this},c}(l,d),Ob=function(){return function(a){var b;return b=this.str.substr(this.pos,a.length),b===a?(this.pos+=a.length,a):null}}(),Pb=function(){var a=/^\s+/;return function(){var b=a.exec(this.remaining());return b?(this.pos+=b[0].length,b[0]):null}}(),Qb=function(){return function(a){return function(b){var c=a.exec(b.str.substring(b.pos));return c?(b.pos+=c[0].length,c[1]||c[0]):null}}}(),Rb=function(){function a(a){var b;return a.getStringMatch("\\")?(b=a.str.charAt(a.pos),a.pos+=1,b):null}return function(b){var c,d="";for(c=a(b);c;)d+=c,c=a(b);return d||null}}(),Sb=function(a,b){var c=a(/^[^\\"]+/),d=a(/^[^\\']+/);return function e(a,f){var g,h,i,j,k,l;if(g=a.pos,h="",l=f?d:c,i=b(a),i&&(h+=i),j=l(a),j&&(h+=j),!h)return"";for(k=e(a,f);""!==k;)h+=k;return h}}(Qb,Rb),Tb=function(a,b){return function(c){var d,e;return d=c.pos,c.getStringMatch('"')?(e=b(c,!1),c.getStringMatch('"')?{t:a.STRING_LITERAL,v:e}:(c.pos=d,null)):c.getStringMatch("'")?(e=b(c,!0),c.getStringMatch("'")?{t:a.STRING_LITERAL,v:e}:(c.pos=d,null)):null}}(k,Sb),Ub=function(a,b){var c=b(/^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/);return function(b){var d;return(d=c(b))?{t:a.NUMBER_LITERAL,v:d}:null}}(k,Qb),Vb=function(a){return a(/^[a-zA-Z_$][a-zA-Z_$0-9]*/)}(Qb),Wb=function(a,b,c){var d=/^[a-zA-Z_$][a-zA-Z_$0-9]*$/;return function(e){var f;return(f=a(e))?d.test(f.v)?f.v:'"'+f.v.replace(/"/g,'\\"')+'"':(f=b(e))?f.v:(f=c(e))?f:void 0}}(Tb,Ub,Vb),Xb=function(a,b,c,d){function e(a){var b,c,e;return a.allowWhitespace(),(b=d(a))?(e={key:b},a.allowWhitespace(),a.getStringMatch(":")?(a.allowWhitespace(),(c=a.getToken())?(e.value=c.v,e):null):null):null}var f,g,h,i,j,k;return g={"true":!0,"false":!1,undefined:void 0,"null":null},h=new RegExp("^(?:"+Object.keys(g).join("|")+")"),i=/^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/,j=/\$\{([^\}]+)\}/g,k=/^\$\{([^\}]+)\}/,f=function(a,b){this.str=a,this.values=b,this.pos=0,this.result=this.getToken()},f.prototype={remaining:function(){return this.str.substring(this.pos)},getStringMatch:a,getToken:function(){return this.allowWhitespace(),this.getPlaceholder()||this.getSpecial()||this.getNumber()||this.getString()||this.getObject()||this.getArray()},getPlaceholder:function(){var a;return this.values?(a=k.exec(this.remaining()))&&this.values.hasOwnProperty(a[1])?(this.pos+=a[0].length,{v:this.values[a[1]]}):void 0:null},getSpecial:function(){var a;return(a=h.exec(this.remaining()))?(this.pos+=a[0].length,{v:g[a[0]]}):void 0},getNumber:function(){var a;return(a=i.exec(this.remaining()))?(this.pos+=a[0].length,{v:+a[0]}):void 0},getString:function(){var a,b=c(this);return b&&(a=this.values)?{v:b.v.replace(j,function(b,c){return a[c]||c})}:b},getObject:function(){var a,b;if(!this.getStringMatch("{"))return null;for(a={};b=e(this);){if(a[b.key]=b.value,this.allowWhitespace(),this.getStringMatch("}"))return{v:a};if(!this.getStringMatch(","))return null}return null},getArray:function(){var a,b;if(!this.getStringMatch("["))return null;for(a=[];b=this.getToken();){if(a.push(b.v),this.getStringMatch("]"))return{v:a};if(!this.getStringMatch(","))return null}return null},allowWhitespace:b},function(a,b){var c=new f(a,b);return c.result?{value:c.result.v,remaining:c.remaining()}:null}}(Ob,Pb,Tb,Wb),Yb=function(a,b,c,d,e){function f(a){return"string"==typeof a?a:JSON.stringify(a)}var g=function(b){this.type=a.INTERPOLATOR,c(this,b)};return g.prototype={update:d,resolve:e,render:function(a){this.value=a,this.parentFragment.bubble()},teardown:function(){b(this)},toString:function(){return void 0==this.value?"":f(this.value)}},g}(k,nb,wb,yb,xb),Zb=function(a,b,c,d,e,f,g){var h,i;return g.push(function(){i=g.StringFragment}),h=function(c){this.type=a.SECTION,this.fragments=[],this.length=0,b(this,c)},h.prototype={update:c,resolve:d,teardown:function(){this.teardownFragments(),f(this)},teardownFragments:function(){for(;this.fragments.length;)this.fragments.shift().teardown();this.length=0},bubble:function(){this.value=this.fragments.join(""),this.parentFragment.bubble()},render:function(a){var b;(b=this.root._wrapped[this.keypath])&&(a=b.get()),e(this,a),this.parentFragment.bubble()},createFragment:function(a){return new i(a)},toString:function(){return this.fragments.join("")}},h}(k,wb,yb,xb,Ab,nb,Eb),$b=function(a){var b=function(b){this.type=a.TEXT,this.text=b};return b.prototype={toString:function(){return this.text},teardown:function(){}},b}(k),_b=function(a,b){return function(){var c,d,e,f,g,h,i;if(!this.argsList||this.dirty){if(c={},d=0,f=this.root._guid,i=function(a){return a.map(function(a){var b,e,g;return a.text?a.text:a.fragments?a.fragments.map(function(a){return i(a.items)}).join(""):(b=f+"-"+d++,g=(e=a.root._wrapped[a.keypath])?e.value:a.value,c[b]=g,"${"+b+"}")}).join("")},e=i(this.items),h=b("["+e+"]",c))this.argsList=h.value;else{if(g="Could not parse directive arguments ("+this.toString()+"). If you think this is a bug, please file an issue at http://github.com/RactiveJS/Ractive/issues",this.root.debug)throw new Error(g);a(g),this.argsList=[e]}this.dirty=!1}return this.argsList}}(I,Xb),ac=function(a,b,c,d,e,f,g,h){var i=function(a){c(this,a)};return i.prototype={createItem:function(b){if("string"==typeof b.descriptor)return new f(b.descriptor);switch(b.descriptor.t){case a.INTERPOLATOR:return new d(b);case a.TRIPLE:return new d(b);case a.SECTION:return new e(b);default:throw"Something went wrong in a rather interesting way"}},bubble:function(){this.dirty=!0,this.owner.bubble()},teardown:function(){var a,b;for(a=this.items.length,b=0;a>b;b+=1)this.items[b].teardown()},getValue:function(){var b;return 1===this.items.length&&this.items[0].type===a.INTERPOLATOR&&(b=this.items[0].value,void 0!==b)?b:this.toString()},isSimple:function(){var b,c,d;if(void 0!==this.simple)return this.simple;for(b=this.items.length;b--;)if(c=this.items[b],c.type!==a.TEXT){if(c.type!==a.INTERPOLATOR)return this.simple=!1;if(d)return!1;d=!0}return this.simple=!0},toString:function(){return this.items.join("")},toJSON:function(){var a,c=this.getValue();return"string"==typeof c&&(a=b(c),c=a?a.value:c),c},toArgsList:g},h.StringFragment=i,i}(k,Xb,kb,Yb,Zb,$b,_b,Eb),bc=function(a,b,c,d,e,f,g){var h=function(e){return this.type=a.ATTRIBUTE,this.element=e.element,b(this,e.name),null===e.value||"string"==typeof e.value?(c(this,e),void 0):(this.root=e.root,this.pNode=e.pNode,this.parentFragment=this.element.parentFragment,this.fragment=new g({descriptor:e.value,root:this.root,owner:this,contextStack:e.contextStack}),this.pNode&&("value"===this.name&&(this.isValueAttribute=!0,"INPUT"===this.pNode.tagName&&"file"===this.pNode.type&&(this.isFileInputValue=!0)),d(this,e),this.selfUpdating=this.fragment.isSimple(),this.ready=!0),void 0)};return h.prototype={bind:e,update:f,updateBindings:function(){this.keypath=this.interpolator.keypath||this.interpolator.ref,"name"===this.propertyName&&(this.pNode.name="{{"+this.keypath+"}}")},teardown:function(){var a;if(this.boundEvents)for(a=this.boundEvents.length;a--;)this.pNode.removeEventListener(this.boundEvents[a],this.updateModel,!1);this.fragment&&this.fragment.teardown()},bubble:function(){this.selfUpdating?this.update():!this.deferred&&this.ready&&(this.root._deferred.attrs.push(this),this.deferred=!0)},toString:function(){var a;return null===this.value?this.name:this.fragment?(a=this.fragment.toString(),this.name+"="+JSON.stringify(a)):this.name+"="+JSON.stringify(this.value)}},h}(k,Jb,Kb,Lb,Mb,Nb,ac),cc=function(a){return function(b,c){var d,e,f;b.attributes=[];for(d in c)c.hasOwnProperty(d)&&(e=c[d],f=new a({element:b,name:d,value:e,root:b.root,pNode:b.node,contextStack:b.parentFragment.contextStack}),b.attributes[b.attributes.length]=b.attributes[d]=f,"name"!==d&&f.update());return b.attributes}}(bc),dc=function(a,b,c,d){var e,f,g;return d.push(function(){e=d.DomFragment}),f=function(){var a=this.node,b=this.fragment.toString();a.styleSheet&&(a.styleSheet.cssText=b),a.innerHTML=b},g=function(){this.node.type&&"text/javascript"!==this.node.type||a("Script tag was updated. This does not cause the code to be re-evaluated!"),this.node.innerHTML=this.fragment.toString()},function(a,d,h,i){var j,k,l,m,n;if("script"===a.lcName||"style"===a.lcName)return a.fragment=new c({descriptor:h.f,root:a.root,contextStack:a.parentFragment.contextStack,owner:a}),i&&("script"===a.lcName?(a.bubble=g,a.node.innerHTML=a.fragment.toString()):(a.bubble=f,a.bubble())),void 0;if("string"!=typeof h.f||d&&d.namespaceURI&&d.namespaceURI!==b.html)a.fragment=new e({descriptor:h.f,root:a.root,pNode:d,contextStack:a.parentFragment.contextStack,owner:a}),i&&d.appendChild(a.fragment.docFrag);else if(a.html=h.f,i)for(d.innerHTML=a.html,j=a.root._liveQueries,k=j.length;k--;)if(l=j[k],(m=d.querySelectorAll(l))&&(n=m.length))for((a.liveQueries||(a.liveQueries=[])).push(l),a.liveQueries[l]=[];n--;)a.liveQueries[l][n]=m[n]}}(I,d,ac,Eb),ec=function(a,b){var c=function(c,d,e,f){var g,h,i;if(this.root=d,this.node=e.node,g=c.n||c,"string"!=typeof g&&(h=new b({descriptor:g,root:this.root,owner:e,contextStack:f}),g=h.toString(),h.teardown()),c.a?this.params=c.a:c.d&&(h=new b({descriptor:c.d,root:this.root,owner:e,contextStack:f}),this.params=h.toArgsList(),h.teardown()),this.fn=d.decorators[g],!this.fn){if(i='Missing "'+g+'" decorator. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#decorators',d.debug)throw new Error(i);a(i)}};return c.prototype={init:function(){var a,b;if(this.params?(b=[this.node].concat(this.params),a=this.fn.apply(this.root,b)):a=this.fn.call(this.root,this.node),!a||!a.teardown)throw new Error("Decorator definition must return an object with a teardown method");this.teardown=a.teardown}},c}(I,ac),fc=function(a){return function(b,c,d,e){d.decorator=new a(b,c,d,e),d.decorator.fn&&c._deferred.decorators.push(d.decorator)}}(ec),gc=function(a,b){var c,d,e,f,g,h,i,j,k;return c=function(a,b,c,e,f){var g,h;g=a.node._ractive.events,h=g[b]||(g[b]=new d(a,b,e,f)),h.add(c)},d=function(b,c,d){var e;this.element=b,this.root=b.root,this.node=b.node,this.name=c,this.contextStack=d,this.proxies=[],(e=this.root.events[c])?this.custom=e(this.node,k(c)):("on"+c in this.node||a('Missing "'+this.name+'" event. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#events'),this.node.addEventListener(c,j,!1))},d.prototype={add:function(a){this.proxies[this.proxies.length]=new e(this.element,this.root,a,this.contextStack)},teardown:function(){var a;for(this.custom?this.custom.teardown():this.node.removeEventListener(this.name,j,!1),a=this.proxies.length;a--;)this.proxies[a].teardown()},fire:function(a){for(var b=this.proxies.length;b--;)this.proxies[b].fire(a)}},e=function(a,c,d,e){var i;return this.root=c,i=d.n||d,this.n="string"==typeof i?i:new b({descriptor:d.n,root:this.root,owner:a,contextStack:e}),d.a?(this.a=d.a,this.fire=g,void 0):d.d?(this.d=new b({descriptor:d.d,root:this.root,owner:a,contextStack:e}),this.fire=h,void 0):(this.fire=f,void 0) -},e.prototype={teardown:function(){this.n.teardown&&this.n.teardown(),this.d&&this.d.teardown()},bubble:function(){}},f=function(a){this.root.fire(this.n.toString(),a)},g=function(a){this.root.fire.apply(this.root,[this.n.toString(),a].concat(this.a))},h=function(a){var b=this.d.toArgsList();"string"==typeof b&&(b=b.substr(1,b.length-2)),this.root.fire.apply(this.root,[this.n.toString(),a].concat(b))},j=function(a){var b=this._ractive;b.events[a.type].fire({node:this,original:a,index:b.index,keypath:b.keypath,context:b.root.get(b.keypath)})},i={},k=function(a){return i[a]?i[a]:i[a]=function(b){var c=b.node._ractive;b.index=c.index,b.keypath=c.keypath,b.context=c.root.get(c.keypath),c.events[a].fire(b)}},c}(I,ac),hc=function(a){return function(b,c){var d,e,f;for(e in c)if(c.hasOwnProperty(e))for(f=e.split("-"),d=f.length;d--;)a(b,f[d],c[e],b.parentFragment.contextStack)}}(gc),ic=function(){return function(a){var b,c,d,e,f;for(b=a.root,c=b._liveQueries,d=c.length;d--;)e=c[d],f=c[e],f._test(a)&&((a.liveQueries||(a.liveQueries=[])).push(e),a.liveQueries[e]=[a.node])}}(),jc=function(){return function(a){return a.replace(/-([a-zA-Z])/g,function(a,b){return b.toUpperCase()})}}(),kc=function(){return function(a,b){var c;for(c in b)b.hasOwnProperty(c)&&!a.hasOwnProperty(c)&&(a[c]=b[c]);return a}}(),lc=function(a,b,c,d,e,f,g,h){function i(a){var b,c,d;if(!q[a])if(void 0!==m[a])q[a]=a;else for(d=a.charAt(0).toUpperCase()+a.substring(1),b=n.length;b--;)if(c=n[b],void 0!==m[c+d]){q[a]=c+d;break}return q[a]}function j(a){return a.replace(p,"")}function k(a){var b;return o.test(a)&&(a="-"+a),b=a.replace(/[A-Z]/g,function(a){return"-"+a.toLowerCase()})}var l,m,n,o,p,q,r,s,t,u,v,w;if(a)return m=b("div").style,function(){void 0!==m.transition?(s="transition",w="transitionend",r=!0):void 0!==m.webkitTransition?(s="webkitTransition",w="webkitTransitionEnd",r=!0):r=!1}(),s&&(t=s+"Duration",u=s+"Property",v=s+"TimingFunction"),l=function(a,b,d,e,f){var g,i,j,k=this;if(this.root=b,this.node=d.node,this.isIntro=f,this.originalStyle=this.node.getAttribute("style"),this.complete=function(a){!a&&k.isIntro&&k.resetStyle(),k._manager.pop(k.node),k.node._ractive.transition=null},g=a.n||a,"string"!=typeof g&&(i=new h({descriptor:g,root:this.root,owner:d,contextStack:e}),g=i.toString(),i.teardown()),this.name=g,a.a?this.params=a.a:a.d&&(i=new h({descriptor:a.d,root:this.root,owner:d,contextStack:e}),this.params=i.toArgsList(),i.teardown()),this._fn=b.transitions[g],!this._fn){if(j='Missing "'+g+'" transition. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#transitions',b.debug)throw new Error(j);return c(j),void 0}},l.prototype={init:function(){if(this._inited)throw new Error("Cannot initialize a transition more than once");this._inited=!0,this._fn.apply(this.root,[this].concat(this.params))},getStyle:function(a){var b,c,d,f,g;if(b=window.getComputedStyle(this.node),"string"==typeof a)return g=b[i(a)],"0px"===g&&(g=0),g;if(!e(a))throw new Error("Transition#getStyle must be passed a string, or an array of strings representing CSS properties");for(c={},d=a.length;d--;)f=a[d],g=b[i(f)],"0px"===g&&(g=0),c[f]=g;return c},setStyle:function(a,b){var c;if("string"==typeof a)this.node.style[i(a)]=b;else for(c in a)a.hasOwnProperty(c)&&(this.node.style[i(c)]=a[c]);return this},animateStyle:function(a,b,d,e){var g,h,l,m,n,o,p,q,r,s=this;for("string"==typeof a?(n={},n[a]=b):(n=a,e=d,d=b),d||(c('The "'+s.name+'" transition does not supply an options object to `t.animateStyle()`. This will break in a future version of Ractive. For more info see https://github.com/RactiveJS/Ractive/issues/340'),d=s,e=s.complete),d.duration||(s.setStyle(n),e&&e()),g=Object.keys(n),h=[],l=window.getComputedStyle(s.node),o={},q=g.length;q--;)r=g[q],m=l[i(r)],"0px"===m&&(m=0),m!=n[r]&&(h[h.length]=r,s.node.style[i(r)]=m);return h.length?(setTimeout(function(){s.node.style[u]=g.map(i).map(k).join(","),s.node.style[v]=k(d.easing||"linear"),s.node.style[t]=d.duration/1e3+"s",p=function(a){var b;b=h.indexOf(f(j(a.propertyName))),-1!==b&&h.splice(b,1),h.length||(s.root.fire(s.name+":end"),s.node.removeEventListener(w,p,!1),e&&e())},s.node.addEventListener(w,p,!1),setTimeout(function(){for(var a=h.length;a--;)r=h[a],s.node.style[i(r)]=n[r]},0)},d.delay||0),void 0):(e&&e(),void 0)},resetStyle:function(){this.originalStyle?this.node.setAttribute("style",this.originalStyle):(this.node.getAttribute("style"),this.node.removeAttribute("style"))},processParams:function(a,b){return"number"==typeof a?a={duration:a}:"string"==typeof a?a="slow"===a?{duration:600}:"fast"===a?{duration:200}:{duration:400}:a||(a={}),g(a,b)}},n=["o","ms","moz","webkit"],o=new RegExp("^(?:"+n.join("|")+")([A-Z])"),p=new RegExp("^-(?:"+n.join("|")+")-"),q={},l}(f,e,I,J,l,jc,kc,ac),mc=function(a,b){return function(a,c,d,e,f){var g,h,i;!c.transitionsEnabled||c._parent&&!c._parent.transitionsEnabled||(g=new b(a,c,d,e,f),g._fn&&(h=g.node,g._manager=c._transitionManager,(i=h._ractive.transition)&&i.complete(),h._ractive.transition=g,g._manager.push(h),f?c._deferred.transitions.push(g):g.init()))}}(I,lc),nc=function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o){return function(e,p,q){var r,s,t,u,v,w,x,y,z,A,B,C,D;if(e.type=a.ELEMENT,r=e.parentFragment=p.parentFragment,s=r.pNode,t=r.contextStack,u=e.descriptor=p.descriptor,e.root=B=r.root,e.index=p.index,e.lcName=u.e.toLowerCase(),e.eventListeners=[],e.customEventListeners=[],s&&(v=e.namespace=h(u,s),w=v!==b.html?o(u.e):u.e,e.node=g(w,v),d(e.node,"_ractive",{value:{proxy:e,keypath:t.length?t[t.length-1]:"",index:r.indexRefs,events:c(null),root:B}})),x=i(e,u.a),u.f){if(e.node&&e.node.getAttribute("contenteditable")&&e.node.innerHTML){if(D="A pre-populated contenteditable element should not have children",B.debug)throw new Error(D);f(D)}j(e,e.node,u,q)}q&&u.v&&l(e,u.v),q&&(B.twoway&&(e.bind(),e.node.getAttribute("contenteditable")&&e.node._ractive.binding&&e.node._ractive.binding.update()),x.name&&!x.name.twoway&&x.name.update(),"IMG"===e.node.tagName&&((y=e.attributes.width)||(z=e.attributes.height))&&e.node.addEventListener("load",A=function(){y&&(e.node.width=y.value),z&&(e.node.height=z.value),e.node.removeEventListener("load",A,!1)},!1),q.appendChild(e.node),u.o&&k(u.o,B,e,t),u.t1&&n(u.t1,B,e,t,!0),"OPTION"===e.node.tagName&&("SELECT"===s.tagName&&(C=s._ractive.binding)&&C.deferUpdate(),e.node._ractive.value==s._ractive.value&&(e.node.selected=!0)),e.node.autofocus&&(B._deferred.focusable=e.node)),m(e)}}(k,d,c,g,Z,I,e,Hb,cc,dc,fc,hc,ic,mc,Ib),oc=function(a){return function(b){var c,d,e,f,g,h,i,j,k;for(this.fragment&&this.fragment.teardown(!1);this.attributes.length;)this.attributes.pop().teardown();if(this.node){for(c in this.node._ractive.events)this.node._ractive.events[c].teardown();(d=this.node._ractive.binding)&&(d.teardown(),e=this.root._twowayBindings[d.attr.keypath],e.splice(e.indexOf(d),1))}if(this.decorator&&this.decorator.teardown(),this.descriptor.t2&&a(this.descriptor.t2,this.root,this,this.parentFragment.contextStack,!1),b&&this.root._transitionManager.detachWhenReady(this),g=this.liveQueries)for(f=g.length;f--;)if(h=g[f],j=this.liveQueries[h])for(k=j.length,i=this.root._liveQueries[h];k--;)i._remove(j[k])}}(mc),pc=function(){return"area base br col command doctype embed hr img input keygen link meta param source track wbr".split(" ")}(),qc=function(a){return function(){var b,c,d;for(b="<"+(this.descriptor.y?"!doctype":this.descriptor.e),d=this.attributes.length,c=0;d>c;c+=1)b+=" "+this.attributes[c].toString();return b+=">",this.html?b+=this.html:this.fragment&&(b+=this.fragment.toString()),-1===a.indexOf(this.descriptor.e)&&(b+=""+this.descriptor.e+">"),b}}(pc),rc=function(a){return function(b){var c;return a(this.node,b)?this.node:this.html&&(c=this.node.querySelector(b))?c:this.fragment&&this.fragment.find?this.fragment.find(b):void 0}}(Z),sc=function(){return function(a,b){var c,d,e,f,g;if(b._test(this,!0)&&b.live&&((this.liveQueries||(this.liveQueries=[])).push(a),this.liveQueries[a]=[this.node]),this.html&&(c=this.node.querySelectorAll(a))&&(e=c.length))for(b.live&&(this.liveQueries[a]||((this.liveQueries||(this.liveQueries=[])).push(a),this.liveQueries[a]=[]),g=this.liveQueries[a]),d=0;e>d;d+=1)f=c[d],b.push(f),b.live&&g.push(f);this.fragment&&this.fragment.findAll(a,b)}}(),tc=function(){return function(a){return this.fragment?this.fragment.findComponent(a):void 0}}(),uc=function(){return function(a,b){this.fragment&&this.fragment.findAllComponents(a,b)}}(),vc=function(){return function(){var a=this.attributes;if(this.node&&(this.binding&&(this.binding.teardown(),this.binding=null),!(this.node.getAttribute("contenteditable")&&a.value&&a.value.bind())))switch(this.descriptor.e){case"select":case"textarea":return a.value&&a.value.bind(),void 0;case"input":if("radio"===this.node.type||"checkbox"===this.node.type){if(a.name&&a.name.bind())return;if(a.checked&&a.checked.bind())return}if(a.value&&a.value.bind())return}}}(),wc=function(a,b,c,d,e,f,g,h){var i=function(b,c){a(this,b,c)};return i.prototype={detach:function(){return this.node?(this.node.parentNode&&this.node.parentNode.removeChild(this.node),this.node):void 0},teardown:b,firstNode:function(){return this.node},findNextNode:function(){return null},bubble:function(){},toString:c,find:d,findAll:e,findComponent:f,findAllComponents:g,bind:h},i}(nc,oc,qc,rc,sc,tc,uc,vc),xc={missingParser:"Missing Ractive.parse - cannot parse template. Either preparse or use the version that includes the parser"},yc={},zc=function(){return function(a){var b,c,d;for(d="";a.length;){if(b=a.indexOf(""),-1===b&&-1===c){d+=a;break}if(-1!==b&&-1===c)throw"Illegal HTML - expected closing comment sequence ('-->')";if(-1!==c&&-1===b||b>c)throw"Illegal HTML - unexpected closing comment sequence ('-->')";d+=a.substr(0,b),a=a.substring(c+3)}return d}}(),Ac=function(a){return function(b){var c,d,e,f,g,h;for(g=/^\s*\r?\n/,h=/\r?\n\s*$/,c=2;c":a.PARTIAL,"!":a.COMMENT,"&":a.TRIPLE};return function(a){var c=b[a.str.charAt(a.pos)];return c?(a.pos+=1,c):null}}(k),Ec=function(a,b,c){var d=b(/^\s*:\s*([a-zA-Z_$][a-zA-Z_$0-9]*)/),e=/^[0-9][1-9]*$/;return function(b,f){var g,h,i,j,k,l,m;if(g=b.pos,h={type:f?a.TRIPLE:a.MUSTACHE},!(f||((j=b.getExpression())&&(h.mustacheType=a.INTERPOLATOR,b.allowWhitespace(),b.getStringMatch(b.delimiters[1])?b.pos-=b.delimiters[1].length:(b.pos=g,j=null)),j||(i=c(b),i===a.TRIPLE?h={type:a.TRIPLE}:h.mustacheType=i||a.INTERPOLATOR,i!==a.COMMENT&&i!==a.CLOSING||(l=b.remaining(),m=l.indexOf(b.delimiters[1]),-1===m)))))return h.ref=l.substr(0,m),b.pos+=m,h;for(j||(b.allowWhitespace(),j=b.getExpression());j.t===a.BRACKETED&&j.x;)j=j.x;return j.t===a.REFERENCE?h.ref=j.n:j.t===a.NUMBER_LITERAL&&e.test(j.v)?h.ref=j.v:h.expression=j,k=d(b),null!==k&&(h.indexRef=k),h}}(k,Qb,Dc),Fc=function(a,b,c){function d(d,e){var f,g,h=d.pos;return g=e?d.tripleDelimiters:d.delimiters,d.getStringMatch(g[0])?(f=b(d))?d.getStringMatch(g[1])?(d[e?"tripleDelimiters":"delimiters"]=f,{type:a.MUSTACHE,mustacheType:a.DELIMCHANGE}):(d.pos=h,null):(d.allowWhitespace(),f=c(d,e),null===f?(d.pos=h,null):(d.allowWhitespace(),d.getStringMatch(g[1])?f:(d.pos=h,null))):null}return function(){var a=this.tripleDelimiters[0].length>this.delimiters[0].length;return d(this,a)||d(this,!a)}}(k,Cc,Ec),Gc=function(a){return function(){var b,c,d;if(!this.getStringMatch(""),-1===d)throw new Error('Unexpected end of input (expected "-->" to close comment)');return b=c.substr(0,d),this.pos+=d+3,{type:a.COMMENT,content:b}}}(k),Hc=function(){return function(a,b){var c,d,e;for(c=b.length;c--;){if(d=a.indexOf(b[c]),!d)return 0;-1!==d&&(!e||e>d)&&(e=d)}return e||-1}}(),Ic=function(a,b,c){var d,e,f,g,h,i,j,k,l,m,n,o,p;return d=function(){return e(this)||f(this)},e=function(b){var c,d,e,f;return c=b.pos,b.inside?null:b.getStringMatch("<")?(d={type:a.TAG},b.getStringMatch("!")&&(d.doctype=!0),d.name=g(b),d.name?(e=h(b),e&&(d.attrs=e),b.allowWhitespace(),b.getStringMatch("/")&&(d.selfClosing=!0),b.getStringMatch(">")?(f=d.name.toLowerCase(),("script"===f||"style"===f)&&(b.inside=f),d):(b.pos=c,null)):(b.pos=c,null)):null},f=function(b){var c,d,e;if(c=b.pos,e=function(a){throw new Error("Unexpected character "+b.remaining().charAt(0)+" (expected "+a+")")},!b.getStringMatch("<"))return null;if(d={type:a.TAG,closing:!0},b.getStringMatch("/")||e('"/"'),d.name=g(b),d.name||e("tag name"),b.getStringMatch(">")||e('">"'),b.inside){if(d.name.toLowerCase()!==b.inside)return b.pos=c,null;b.inside=null}return d},g=b(/^[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/),h=function(a){var b,c,d;if(b=a.pos,a.allowWhitespace(),d=i(a),!d)return a.pos=b,null;for(c=[];null!==d;)c[c.length]=d,a.allowWhitespace(),d=i(a);return c},i=function(a){var b,c,d;return(c=j(a))?(b={name:c},d=k(a),d&&(b.value=d),b):null},j=b(/^[^\s"'>\/=]+/),k=function(a){var b,c;return b=a.pos,a.allowWhitespace(),a.getStringMatch("=")?(a.allowWhitespace(),c=p(a,"'")||p(a,'"')||l(a),null===c?(a.pos=b,null):c):(a.pos=b,null)},n=b(/^[^\s"'=<>`]+/),m=function(b){var c,d,e;return c=b.pos,(d=n(b))?(-1!==(e=d.indexOf(b.delimiters[0]))&&(d=d.substr(0,e),b.pos=c+d.length),{type:a.TEXT,value:d}):null},l=function(a){var b,c;for(b=[],c=a.getMustache()||m(a);null!==c;)b[b.length]=c,c=a.getMustache()||m(a);return b.length?b:null},p=function(a,b){var c,d,e;if(c=a.pos,!a.getStringMatch(b))return null;for(d=[],e=a.getMustache()||o(a,b);null!==e;)d[d.length]=e,e=a.getMustache()||o(a,b);return a.getStringMatch(b)?d:(a.pos=c,null)},o=function(b,d){var e,f,g;if(e=b.pos,g=b.remaining(),f=c(g,[d,b.delimiters[0],b.delimiters[1]]),-1===f)throw new Error("Quoted attribute value must have a closing quote");return f?(b.pos+=f,{type:a.TEXT,value:g.substr(0,f)}):null},d}(k,Qb,Hc),Jc=function(a,b){return function(){var c,d,e;return d=this.remaining(),e=this.inside?""+this.inside:"<",(c=b(d,[e,this.delimiters[0],this.tripleDelimiters[0]]))?(-1===c&&(c=d.length),this.pos+=c,{type:a.TEXT,value:d.substr(0,c)}):null}}(k,Hc),Kc=function(a){return function(b){var c=b.remaining();return"true"===c.substr(0,4)?(b.pos+=4,{t:a.BOOLEAN_LITERAL,v:"true"}):"false"===c.substr(0,5)?(b.pos+=5,{t:a.BOOLEAN_LITERAL,v:"false"}):null}}(k),Lc=function(a,b){return function(c){var d,e,f;return d=c.pos,c.allowWhitespace(),e=b(c),null===e?(c.pos=d,null):(c.allowWhitespace(),c.getStringMatch(":")?(c.allowWhitespace(),f=c.getExpression(),null===f?(c.pos=d,null):{t:a.KEY_VALUE_PAIR,k:e,v:f}):(c.pos=d,null))}}(k,Wb),Mc=function(a){return function b(c){var d,e,f,g;return d=c.pos,f=a(c),null===f?null:(e=[f],c.getStringMatch(",")?(g=b(c),g?e.concat(g):(c.pos=d,null)):e)}}(Lc),Nc=function(a,b){return function(c){var d,e;return d=c.pos,c.allowWhitespace(),c.getStringMatch("{")?(e=b(c),c.allowWhitespace(),c.getStringMatch("}")?{t:a.OBJECT_LITERAL,m:e}:(c.pos=d,null)):(c.pos=d,null)}}(k,Mc),Oc=function(){return function a(b){var c,d,e,f;if(c=b.pos,b.allowWhitespace(),e=b.getExpression(),null===e)return null;if(d=[e],b.allowWhitespace(),b.getStringMatch(",")){if(f=a(b),null===f)return b.pos=c,null;d=d.concat(f)}return d}}(),Pc=function(a,b){return function(c){var d,e;return d=c.pos,c.allowWhitespace(),c.getStringMatch("[")?(e=b(c),c.getStringMatch("]")?{t:a.ARRAY_LITERAL,m:e}:(c.pos=d,null)):(c.pos=d,null)}}(k,Oc),Qc=function(a,b,c,d,e){return function(f){var g=a(f)||b(f)||c(f)||d(f)||e(f);return g}}(Ub,Kc,Tb,Nc,Pc),Rc=function(a,b,c){var d,e,f,g;return d=b(/^\.[a-zA-Z_$0-9]+/),e=function(a){var b=f(a);return b?"."+b:null},f=b(/^\[(0|[1-9][0-9]*)\]/),g=/^(?:Array|Date|RegExp|decodeURIComponent|decodeURI|encodeURIComponent|encodeURI|isFinite|isNaN|parseFloat|parseInt|JSON|Math|NaN|undefined|null)$/,function(b){var f,h,i,j,k,l,m;for(f=b.pos,h="";b.getStringMatch("../");)h+="../";if(h||(j=b.getStringMatch(".")||""),i=c(b)||"",!h&&!j&&g.test(i))return{t:a.GLOBAL,v:i};if("this"!==i||h||j||(i=".",f+=3),k=(h||j)+i,!k)return null;for(;l=d(b)||e(b);)k+=l;return b.getStringMatch("(")&&(m=k.lastIndexOf("."),-1!==m?(k=k.substr(0,m),b.pos=f+k.length):b.pos-=1),{t:a.REFERENCE,n:k}}}(k,Qb,Vb),Sc=function(a){return function(b){var c,d;return c=b.pos,b.getStringMatch("(")?(b.allowWhitespace(),(d=b.getExpression())?(b.allowWhitespace(),b.getStringMatch(")")?{t:a.BRACKETED,x:d}:(b.pos=c,null)):(b.pos=c,null)):null}}(k),Tc=function(a,b,c){return function(d){return a(d)||b(d)||c(d)}}(Qc,Rc,Sc),Uc=function(a,b){return function(c){var d,e,f;if(d=c.pos,c.allowWhitespace(),c.getStringMatch(".")){if(c.allowWhitespace(),e=b(c))return{t:a.REFINEMENT,n:e};c.expected("a property name")}return c.getStringMatch("[")?(c.allowWhitespace(),f=c.getExpression(),f||c.expected("an expression"),c.allowWhitespace(),c.getStringMatch("]")||c.expected('"]"'),{t:a.REFINEMENT,x:f}):null}}(k,Vb),Vc=function(a,b,c,d){return function(e){var f,g,h,i;if(g=b(e),!g)return null;for(;g;)if(f=e.pos,h=d(e))g={t:a.MEMBER,x:g,r:h};else{if(!e.getStringMatch("("))break;if(e.allowWhitespace(),i=c(e),e.allowWhitespace(),!e.getStringMatch(")")){e.pos=f;break}g={t:a.INVOCATION,x:g},i&&(g.o=i)}return g}}(k,Tc,Oc,Uc),Wc=function(a,b){var c,d;return d=function(b,c){return function(d){var e,f;return d.getStringMatch(b)?(e=d.pos,d.allowWhitespace(),f=d.getExpression(),f||d.expected("an expression"),{s:b,o:f,t:a.PREFIX_OPERATOR}):c(d)}},function(){var a,e,f,g,h;for(g="! ~ + - typeof".split(" "),h=b,a=0,e=g.length;e>a;a+=1)f=d(g[a],h),h=f;c=h}(),c}(k,Vc),Xc=function(a,b){var c,d;return d=function(b,c){return function(d){var e,f,g;return(f=c(d))?(e=d.pos,d.allowWhitespace(),d.getStringMatch(b)?"in"===b&&/[a-zA-Z_$0-9]/.test(d.remaining().charAt(0))?(d.pos=e,f):(d.allowWhitespace(),g=d.getExpression(),g?{t:a.INFIX_OPERATOR,s:b,o:[f,g]}:(d.pos=e,f)):(d.pos=e,f)):null}},function(){var a,e,f,g,h;for(g="* / % + - << >> >>> < <= > >= in instanceof == != === !== & ^ | && ||".split(" "),h=b,a=0,e=g.length;e>a;a+=1)f=d(g[a],h),h=f;c=h}(),c}(k,Wc),Yc=function(a,b){return function(c){var d,e,f,g;return(e=b(c))?(d=c.pos,c.allowWhitespace(),c.getStringMatch("?")?(c.allowWhitespace(),(f=c.getExpression())?(c.allowWhitespace(),c.getStringMatch(":")?(c.allowWhitespace(),g=c.getExpression(),g?{t:a.CONDITIONAL,o:[e,f,g]}:(c.pos=d,e)):(c.pos=d,e)):(c.pos=d,e)):(c.pos=d,e)):null}}(k,Xc),Zc=function(a){return function(){return a(this)}}(Yc),$c=function(a,b,c,d,e,f,g){var h;return h=function(a,b){var c;for(this.str=a,this.pos=0,this.delimiters=b.delimiters,this.tripleDelimiters=b.tripleDelimiters,this.tokens=[];this.pos"+b)},expected:function(a){var b=this.remaining().substr(0,40);throw 40===b.length&&(b+="..."),new Error('Tokenizer failed: unexpected string "'+b+'" (expected '+a+")")}},h}(Fc,Gc,Ic,Jc,Zc,Pb,Ob),_c=function(a,b,c,d,e){var f,g;return e.push(function(){g=e.Ractive}),f=function(e,f){var h,i;return f=f||{},f.stripComments!==!1&&(e=a(e)),h=new d(e,{delimiters:f.delimiters||(g?g.delimiters:["{{","}}"]),tripleDelimiters:f.tripleDelimiters||(g?g.tripleDelimiters:["{{{","}}}"])}),i=h.tokens,b(i),c(i),i}}(zc,Ac,Bc,$c,Eb),ad=function(a){var b,c,d,e,f,g,h,i,j;return b=function(a,b){this.text=b?a.value:a.value.replace(j," ")},b.prototype={type:a.TEXT,toJSON:function(){return this.decoded||(this.decoded=i(this.text))},toString:function(){return this.text}},c={quot:34,amp:38,apos:39,lt:60,gt:62,nbsp:160,iexcl:161,cent:162,pound:163,curren:164,yen:165,brvbar:166,sect:167,uml:168,copy:169,ordf:170,laquo:171,not:172,shy:173,reg:174,macr:175,deg:176,plusmn:177,sup2:178,sup3:179,acute:180,micro:181,para:182,middot:183,cedil:184,sup1:185,ordm:186,raquo:187,frac14:188,frac12:189,frac34:190,iquest:191,Agrave:192,Aacute:193,Acirc:194,Atilde:195,Auml:196,Aring:197,AElig:198,Ccedil:199,Egrave:200,Eacute:201,Ecirc:202,Euml:203,Igrave:204,Iacute:205,Icirc:206,Iuml:207,ETH:208,Ntilde:209,Ograve:210,Oacute:211,Ocirc:212,Otilde:213,Ouml:214,times:215,Oslash:216,Ugrave:217,Uacute:218,Ucirc:219,Uuml:220,Yacute:221,THORN:222,szlig:223,agrave:224,aacute:225,acirc:226,atilde:227,auml:228,aring:229,aelig:230,ccedil:231,egrave:232,eacute:233,ecirc:234,euml:235,igrave:236,iacute:237,icirc:238,iuml:239,eth:240,ntilde:241,ograve:242,oacute:243,ocirc:244,otilde:245,ouml:246,divide:247,oslash:248,ugrave:249,uacute:250,ucirc:251,uuml:252,yacute:253,thorn:254,yuml:255,OElig:338,oelig:339,Scaron:352,scaron:353,Yuml:376,fnof:402,circ:710,tilde:732,Alpha:913,Beta:914,Gamma:915,Delta:916,Epsilon:917,Zeta:918,Eta:919,Theta:920,Iota:921,Kappa:922,Lambda:923,Mu:924,Nu:925,Xi:926,Omicron:927,Pi:928,Rho:929,Sigma:931,Tau:932,Upsilon:933,Phi:934,Chi:935,Psi:936,Omega:937,alpha:945,beta:946,gamma:947,delta:948,epsilon:949,zeta:950,eta:951,theta:952,iota:953,kappa:954,lambda:955,mu:956,nu:957,xi:958,omicron:959,pi:960,rho:961,sigmaf:962,sigma:963,tau:964,upsilon:965,phi:966,chi:967,psi:968,omega:969,thetasym:977,upsih:978,piv:982,ensp:8194,emsp:8195,thinsp:8201,zwnj:8204,zwj:8205,lrm:8206,rlm:8207,ndash:8211,mdash:8212,lsquo:8216,rsquo:8217,sbquo:8218,ldquo:8220,rdquo:8221,bdquo:8222,dagger:8224,Dagger:8225,bull:8226,hellip:8230,permil:8240,prime:8242,Prime:8243,lsaquo:8249,rsaquo:8250,oline:8254,frasl:8260,euro:8364,image:8465,weierp:8472,real:8476,trade:8482,alefsym:8501,larr:8592,uarr:8593,rarr:8594,darr:8595,harr:8596,crarr:8629,lArr:8656,uArr:8657,rArr:8658,dArr:8659,hArr:8660,forall:8704,part:8706,exist:8707,empty:8709,nabla:8711,isin:8712,notin:8713,ni:8715,prod:8719,sum:8721,minus:8722,lowast:8727,radic:8730,prop:8733,infin:8734,ang:8736,and:8743,or:8744,cap:8745,cup:8746,"int":8747,there4:8756,sim:8764,cong:8773,asymp:8776,ne:8800,equiv:8801,le:8804,ge:8805,sub:8834,sup:8835,nsub:8836,sube:8838,supe:8839,oplus:8853,otimes:8855,perp:8869,sdot:8901,lceil:8968,rceil:8969,lfloor:8970,rfloor:8971,lang:9001,rang:9002,loz:9674,spades:9824,clubs:9827,hearts:9829,diams:9830},d=[8364,129,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,141,381,143,144,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,157,382,376],e=new RegExp("&("+Object.keys(c).join("|")+");?","g"),f=/([0-9]+);?/g,g=/([0-9]+);?/g,h=function(a){return a?10===a?32:128>a?a:159>=a?d[a-128]:55296>a?a:57343>=a?65533:65535>=a?a:65533:65533},i=function(a){var b;return b=a.replace(e,function(a,b){return c[b]?String.fromCharCode(c[b]):a}),b=b.replace(f,function(a,b){return String.fromCharCode(h(parseInt(b,16)))}),b=b.replace(g,function(a,b){return String.fromCharCode(h(b))})},j=/\s+/g,b}(k),bd=function(a,b){return function(c){return c.type===a.TEXT?(this.pos+=1,new b(c,this.preserveWhitespace)):null}}(k,ad),cd=function(a){var b;return b=function(a){this.content=a.content},b.prototype={toJSON:function(){return{t:a.COMMENT,f:this.content}},toString:function(){return""}},b}(k),dd=function(a,b){return function(c){return c.type===a.COMMENT?(this.pos+=1,new b(c,this.preserveWhitespace)):null}}(k,cd),ed=function(a,b){var c,d,e;return c=function(a){this.refs=[],d(a,this.refs),this.str=e(a,this.refs)},c.prototype={toJSON:function(){return this.json?this.json:(this.json={r:this.refs,s:this.str},this.json)}},d=function(c,e){var f,g;if(c.t===a.REFERENCE&&-1===e.indexOf(c.n)&&e.unshift(c.n),g=c.o||c.m)if(b(g))d(g,e);else for(f=g.length;f--;)d(g[f],e);c.x&&d(c.x,e),c.r&&d(c.r,e),c.v&&d(c.v,e)},e=function(b,c){var d=function(a){return e(a,c)};switch(b.t){case a.BOOLEAN_LITERAL:case a.GLOBAL:case a.NUMBER_LITERAL:return b.v;case a.STRING_LITERAL:return"'"+b.v.replace(/'/g,"\\'")+"'";case a.ARRAY_LITERAL:return"["+(b.m?b.m.map(d).join(","):"")+"]";case a.OBJECT_LITERAL:return"{"+(b.m?b.m.map(d).join(","):"")+"}";case a.KEY_VALUE_PAIR:return b.k+":"+e(b.v,c);case a.PREFIX_OPERATOR:return("typeof"===b.s?"typeof ":b.s)+e(b.o,c);case a.INFIX_OPERATOR:return e(b.o[0],c)+("in"===b.s.substr(0,2)?" "+b.s+" ":b.s)+e(b.o[1],c);case a.INVOCATION:return e(b.x,c)+"("+(b.o?b.o.map(d).join(","):"")+")";case a.BRACKETED:return"("+e(b.x,c)+")";case a.MEMBER:return e(b.x,c)+e(b.r,c);case a.REFINEMENT:return b.n?"."+b.n:"["+e(b.x,c)+"]";case a.CONDITIONAL:return e(b.o[0],c)+"?"+e(b.o[1],c)+":"+e(b.o[2],c);case a.REFERENCE:return"${"+c.indexOf(b.n)+"}";default:throw new Error("Could not stringify expression token. This error is unexpected")}},c}(k,w),fd=function(a,b){var c=function(c,d){this.type=c.type===a.TRIPLE?a.TRIPLE:c.mustacheType,c.ref&&(this.ref=c.ref),c.expression&&(this.expr=new b(c.expression)),d.pos+=1};return c.prototype={toJSON:function(){var a;return this.json?this.json:(a={t:this.type},this.ref&&(a.r=this.ref),this.expr&&(a.x=this.expr.toJSON()),this.json=a,a)},toString:function(){return!1}},c}(k,ed),gd=function(){return function(a){var b,c,d,e="";if(!a)return"";for(c=0,d=a.length;d>c;c+=1){if(b=a[c].toString(),b===!1)return!1;e+=b}return e}}(),hd=function(a){return function(b,c){var d,e;return c||(d=a(b),d===!1)?e=b.map(function(a){return a.toJSON(c)}):d}}(gd),id=function(a,b,c){var d=function(b,d){var e;for(this.ref=b.ref,this.indexRef=b.indexRef,this.inverted=b.mustacheType===a.INVERTED,b.expression&&(this.expr=new c(b.expression)),d.pos+=1,this.items=[],e=d.next();e;){if(e.mustacheType===a.CLOSING){if(e.ref.trim()===this.ref||this.expr){d.pos+=1;break}throw new Error("Could not parse template: Illegal closing section")}this.items[this.items.length]=d.getStub(),e=d.next()}};return d.prototype={toJSON:function(c){var d;return this.json?this.json:(d={t:a.SECTION},this.ref&&(d.r=this.ref),this.indexRef&&(d.i=this.indexRef),this.inverted&&(d.n=!0),this.expr&&(d.x=this.expr.toJSON()),this.items.length&&(d.f=b(this.items,c)),this.json=d,d)},toString:function(){return!1}},d}(k,hd,ed),jd=function(a,b,c){return function(d){return d.type===a.MUSTACHE||d.type===a.TRIPLE?d.mustacheType===a.SECTION||d.mustacheType===a.INVERTED?new c(d,this):new b(d,this):void 0}}(k,fd,id),kd=function(){return{li:["li"],dt:["dt","dd"],dd:["dt","dd"],p:"address article aside blockquote dir div dl fieldset footer form h1 h2 h3 h4 h5 h6 header hgroup hr menu nav ol p pre section table ul".split(" "),rt:["rt","rp"],rp:["rp","rt"],optgroup:["optgroup"],option:["option","optgroup"],thead:["tbody","tfoot"],tbody:["tbody","tfoot"],tr:["tr"],td:["td","th"],th:["td","th"]}}(),ld=function(a){function b(c){var d,e;if("object"!=typeof c)return c;if(a(c))return c.map(b);d={};for(e in c)c.hasOwnProperty(e)&&(d[e]=b(c[e]));return d}return function(a){var c,d,e,f,g,h;for(e={},c=[],d=[],g=a.length,f=0;g>f;f+=1)if(h=a[f],"intro"===h.name){if(e.intro)throw new Error("An element can only have one intro transition");e.intro=h}else if("outro"===h.name){if(e.outro)throw new Error("An element can only have one outro transition");e.outro=h}else if("intro-outro"===h.name){if(e.intro||e.outro)throw new Error("An element can only have one intro and one outro transition");e.intro=h,e.outro=b(h)}else"proxy-"===h.name.substr(0,6)?(h.name=h.name.substring(6),d[d.length]=h):"on-"===h.name.substr(0,3)?(h.name=h.name.substring(3),d[d.length]=h):"decorator"===h.name?e.decorator=h:c[c.length]=h;return e.attrs=c,e.proxies=d,e}}(l),md=function(a,b){return function(c){var d,e,f,g,h,i,j,k;for(h=function(){throw new Error("Illegal directive")},c.name&&c.value||h(),d={directiveType:c.name},e=c.value,i=[],j=[];e.length;)if(f=e.shift(),f.type===a.TEXT){if(g=f.value.indexOf(":"),-1!==g){g&&(i[i.length]={type:a.TEXT,value:f.value.substr(0,g)}),f.value.length>g+1&&(j[0]={type:a.TEXT,value:f.value.substring(g+1)});break}i[i.length]=f}else i[i.length]=f;return j=j.concat(e),d.name=1===i.length&&i[0].type===a.TEXT?i[0].value:i,j.length&&(1===j.length&&j[0].type===a.TEXT?(k=b("["+j[0].value+"]"),d.args=k?k.value:j[0].value):d.dynamicArgs=j),d}}(k,Xb),nd=function(a,b){var c;return c=function(a,b){var c;for(this.tokens=a||[],this.pos=0,this.options=b,this.result=[];c=this.getStub();)this.result.push(c)},c.prototype={getStub:function(){var a=this.next();return a?this.getText(a)||this.getMustache(a):null},getText:a,getMustache:b,next:function(){return this.tokens[this.pos]}},c}(bd,jd),od=function(a,b,c){var d;return d=function(b){var c=new a(b);this.stubs=c.result},d.prototype={toJSON:function(a){var b;return this["json_"+a]?this["json_"+a]:b=this["json_"+a]=c(this.stubs,a)},toString:function(){return void 0!==this.str?this.str:(this.str=b(this.stubs),this.str)}},d}(nd,gd,hd),pd=function(a){return function(b){var c,d;if("string"==typeof b.name){if(!b.args&&!b.dynamicArgs)return b.name;d=b.name}else d=new a(b.name).toJSON();return c={n:d},b.args?(c.a=b.args,c):(b.dynamicArgs&&(c.d=new a(b.dynamicArgs).toJSON()),c)}}(od),qd=function(a,b,c){return function(d){var e,f,g,h,i,j,k;if(this["json_"+d])return this["json_"+d];if(e=this.component?{t:a.COMPONENT,e:this.component}:{t:a.ELEMENT,e:this.tag},this.doctype&&(e.y=1),this.attributes&&this.attributes.length)for(e.a={},j=this.attributes.length,i=0;j>i;i+=1){if(k=this.attributes[i],f=k.name,e.a[f])throw new Error("You cannot have multiple attributes with the same name");g=null===k.value?null:k.value.toJSON(d),e.a[f]=g}if(this.items&&this.items.length&&(e.f=b(this.items,d)),this.proxies&&this.proxies.length)for(e.v={},j=this.proxies.length,i=0;j>i;i+=1)h=this.proxies[i],e.v[h.directiveType]=c(h);return this.intro&&(e.t1=c(this.intro)),this.outro&&(e.t2=c(this.outro)),this.decorator&&(e.o=c(this.decorator)),this["json_"+d]=e,e}}(k,hd,pd),rd=function(a,b){var c;return c="a abbr acronym address applet area b base basefont bdo big blockquote body br button caption center cite code col colgroup dd del dfn dir div dl dt em fieldset font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img input ins isindex kbd label legend li link map menu meta noframes noscript object ol p param pre q s samp script select small span strike strong style sub sup textarea title tt u ul var article aside audio bdi canvas command data datagrid datalist details embed eventsource figcaption figure footer header hgroup keygen mark meter nav output progress ruby rp rt section source summary time track video wbr".split(" "),function(){var d,e,f,g,h,i,j,k;if(void 0!==this.str)return this.str;if(this.component)return this.str=!1;if(-1===c.indexOf(this.tag.toLowerCase()))return this.str=!1;if(this.proxies||this.intro||this.outro||this.decorator)return this.str=!1;if(j=a(this.items),j===!1)return this.str=!1;if(k=-1!==b.indexOf(this.tag.toLowerCase()),d="<"+this.tag,this.attributes)for(e=0,f=this.attributes.length;f>e;e+=1){if(h=this.attributes[e].name,-1!==h.indexOf(":"))return this.str=!1;if("id"===h||"intro"===h||"outro"===h)return this.str=!1;if(g=" "+h,null!==this.attributes[e].value){if(i=this.attributes[e].value.toString(),i===!1)return this.str=!1; -""!==i&&(g+="=",g+=/[\s"'=<>`]/.test(i)?'"'+i.replace(/"/g,""")+'"':i)}d+=g}return this.selfClosing&&!k?(d+="/>",this.str=d):(d+=">",k?this.str=d:(d+=j,d+=""+this.tag+">",this.str=d))}}(gd,pc),sd=function(a,b,c,d,e,f,g,h,i,j,k){var l,m,n,o,p,q=/^\s+/,r=/\s+$/;return l=function(d,e,i){var j,l,m,n,o,s,t;if(e.pos+=1,s=function(a){return{name:a.name,value:a.value?new k(a.value):null}},this.tag=d.name,t=d.name.toLowerCase(),"rv-"===t.substr(0,3)&&(c('The "rv-" prefix for components has been deprecated. Support will be removed in a future version'),this.tag=this.tag.substring(3)),i=i||"pre"===t,d.attrs&&(m=g(d.attrs),l=m.attrs,n=m.proxies,e.options.sanitize&&e.options.sanitize.eventAttributes&&(l=l.filter(p)),l.length&&(this.attributes=l.map(s)),n.length&&(this.proxies=n.map(h)),m.intro&&(this.intro=h(m.intro)),m.outro&&(this.outro=h(m.outro)),m.decorator&&(this.decorator=h(m.decorator))),d.doctype&&(this.doctype=!0),d.selfClosing&&(this.selfClosing=!0),-1!==b.indexOf(t)&&(this.isVoid=!0),!this.selfClosing&&!this.isVoid){for(this.siblings=f[t],this.items=[],j=e.next();j&&j.mustacheType!==a.CLOSING;){if(j.type===a.TAG){if(j.closing){j.name.toLowerCase()===t&&(e.pos+=1);break}if(this.siblings&&-1!==this.siblings.indexOf(j.name.toLowerCase()))break}this.items[this.items.length]=e.getStub(),j=e.next()}i||(o=this.items[0],o&&o.type===a.TEXT&&(o.text=o.text.replace(q,""),o.text||this.items.shift()),o=this.items[this.items.length-1],o&&o.type===a.TEXT&&(o.text=o.text.replace(r,""),o.text||this.items.pop()))}},l.prototype={toJSON:i,toString:j},m="a abbr acronym address applet area b base basefont bdo big blockquote body br button caption center cite code col colgroup dd del dfn dir div dl dt em fieldset font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img input ins isindex kbd label legend li link map menu meta noframes noscript object ol p param pre q s samp script select small span strike strong style sub sup textarea title tt u ul var article aside audio bdi canvas command data datagrid datalist details embed eventsource figcaption figure footer header hgroup keygen mark meter nav output progress ruby rp rt section source summary time track video wbr".split(" "),n="li dd rt rp optgroup option tbody tfoot tr td th".split(" "),o=/^on[a-zA-Z]/,p=function(a){var b=!o.test(a.name);return b},l}(k,pc,I,jc,gd,kd,ld,md,qd,rd,od),td=function(a,b){return function(a){return this.options.sanitize&&this.options.sanitize.elements&&-1!==this.options.sanitize.elements.indexOf(a.name.toLowerCase())?null:new b(a,this)}}(k,sd),ud=function(a,b,c,d,e){var f;return f=function(a,b){var c,d;for(this.tokens=a||[],this.pos=0,this.options=b,this.preserveWhitespace=b.preserveWhitespace,d=[];c=this.getStub();)d.push(c);this.result=e(d)},f.prototype={getStub:function(){var a=this.next();return a?this.getText(a)||this.getComment(a)||this.getMustache(a)||this.getElement(a):null},getText:a,getComment:b,getMustache:c,getElement:d,next:function(){return this.tokens[this.pos]}},f}(bd,dd,jd,td,hd),vd=function(a,b,c){var d,e,f,g,h;return e=/^\s*$/,f=//,g=//,d=function(d,g){var i,j,k;return g=g||{},f.test(d)?h(d,g):(g.sanitize===!0&&(g.sanitize={elements:"applet base basefont body frame frameset head html isindex link meta noframes noscript object param script style title".split(" "),eventAttributes:!0}),i=a(d,g),g.preserveWhitespace||(k=i[0],k&&k.type===b.TEXT&&e.test(k.value)&&i.shift(),k=i[i.length-1],k&&k.type===b.TEXT&&e.test(k.value)&&i.pop()),j=new c(i,g).result,"string"==typeof j?[j]:j)},h=function(a,b){var c,e,h,i,j,k;for(h={},c="",e=a;j=f.exec(e);){if(i=j[1],c+=e.substr(0,j.index),e=e.substring(j.index+j[0].length),k=g.exec(e),!k||k[1]!==i)throw new Error("Inline partials must have a closing delimiter, and cannot be nested");h[i]=d(e.substr(0,k.index),b),e=e.substring(k.index+k[0].length)}return{main:d(c,b),partials:h}},d}(_c,k,ud),wd=function(a,b,c,d,e,f){var g,h,i,j;return g=function(d,g){var k,l,m;if(l=i(d,g))return l;if(b&&(k=document.getElementById(g),k&&"SCRIPT"===k.tagName)){if(!f)throw new Error(a.missingParser);h(f(k.innerHTML),g,e)}if(l=e[g],!l){if(m='Could not find descriptor for partial "'+g+'"',d.debug)throw new Error(m);return c(m),[]}return j(l)},i=function(b,c){var d;if(b.partials[c]){if("string"==typeof b.partials[c]){if(!f)throw new Error(a.missingParser);d=f(b.partials[c],b.parseOptions),h(d,c,b.partials)}return j(b.partials[c])}},h=function(a,b,c){var e;if(d(a)){c[b]=a.main;for(e in a.partials)a.partials.hasOwnProperty(e)&&(c[e]=a.partials[e])}else c[b]=a},j=function(a){return 1===a.length&&"string"==typeof a[0]?a[0]:a},g}(xc,f,I,w,yc,vd),xd=function(a,b,c){var d,e;return c.push(function(){e=c.DomFragment}),d=function(c,d){var f,g=this.parentFragment=c.parentFragment;if(this.type=a.PARTIAL,this.name=c.descriptor.r,this.index=c.index,!c.descriptor.r)throw new Error("Partials must have a static reference (no expressions). This may change in a future version of Ractive.");f=b(g.root,c.descriptor.r),this.fragment=new e({descriptor:f,root:g.root,pNode:g.pNode,contextStack:g.contextStack,owner:this}),d&&d.appendChild(this.fragment.docFrag)},d.prototype={firstNode:function(){return this.fragment.firstNode()},findNextNode:function(){return this.parentFragment.findNextNode(this)},detach:function(){return this.fragment.detach()},teardown:function(a){this.fragment.teardown(a)},toString:function(){return this.fragment.toString()},find:function(a){return this.fragment.find(a)},findAll:function(a,b){return this.fragment.findAll(a,b)},findComponent:function(a){return this.fragment.findComponent(a)},findAllComponents:function(a,b){return this.fragment.findAllComponents(a,b)}},d}(k,wd,Eb),yd=function(a){var b=function(b,c,d){this.parentFragment=b.parentFragment,this.component=b,this.key=c,this.fragment=new a({descriptor:d,root:b.root,owner:this,contextStack:b.parentFragment.contextStack}),this.selfUpdating=this.fragment.isSimple(),this.value=this.fragment.getValue()};return b.prototype={bubble:function(){this.selfUpdating?this.update():!this.deferred&&this.ready&&(this.root._deferred.attrs.push(this),this.deferred=!0)},update:function(){var a=this.fragment.getValue();this.component.instance.set(this.key,a),this.value=a},teardown:function(){this.fragment.teardown()}},b}(ac),zd=function(a,b,c,d){function e(e,f,g,h){var i,j,k,l,m;return k=e.root,l=e.parentFragment,"string"==typeof g?(j=b(g),j?j.value:g):null===g?!0:1===g.length&&g[0].t===a.INTERPOLATOR&&g[0].r?l.indexRefs&&void 0!==l.indexRefs[g[0].r]?l.indexRefs[g[0].r]:(m=c(k,g[0].r,l.contextStack)||g[0].r,h.push({childKeypath:f,parentKeypath:m}),k.get(m)):(i=new d(e,f,g),e.complexParameters.push(i),i.value)}return function(a,b,c){var d,f,g;d={},a.complexParameters=[];for(f in b)b.hasOwnProperty(f)&&(g=e(a,f,b[f],c),void 0!==g&&(d[f]=g));return d}}(k,Xb,y,yd),Ad=function(){return function(a,b,c,d,e){var f,g,h,i;return g=a.parentFragment,i=a.root,h={content:e||[]},f=new b({el:g.pNode.cloneNode(!1),data:c,partials:h,_parent:i,adaptors:i.adaptors}),f.component=a,a.instance=f,f.insert(d),f.fragment.pNode=g.pNode,f}}(),Bd=function(){function a(a,c,d){var e,f,g,h,i,j,k;e=a.root,f=a.instance,i=a.observers,j=e.observe(c,function(a){g||e._wrapped[c]||(h=!0,f.set(d,a),h=!1)},b),i.push(j),f.twoway&&(j=f.observe(d,function(a){h||(g=!0,e.set(c,a),g=!1)},b),i.push(j),k=f.get(d),void 0!==k&&e.set(c,k))}var b={init:!1,debug:!0};return function(b,c){var d,e;for(b.observers=[],e=c.length;e--;)d=c[e],a(b,d.parentKeypath,d.childKeypath)}}(),Cd=function(a){function b(b,d,e,f){if("string"!=typeof f){if(d.debug)throw new Error(c);return a(c),void 0}b.on(e,function(){var a=Array.prototype.slice.call(arguments);a.unshift(f),d.fire.apply(d,a)})}var c="Components currently only support simple events - you cannot include arguments. Sorry!";return function(a,c){var d;for(d in c)c.hasOwnProperty(d)&&b(a.instance,a.root,d,c[d])}}(I),Dd=function(){return function(a){var b,c;for(b=a.root;b;)(c=b._liveComponentQueries[a.name])&&c.push(a.instance),b=b._parent}}(),Ed=function(a,b,c,d,e,f,g){return function(h,i,j){var k,l,m,n,o;if(k=h.parentFragment=i.parentFragment,l=k.root,h.root=l,h.type=a.COMPONENT,h.name=i.descriptor.e,h.index=i.index,h.observers=[],m=l.components[i.descriptor.e],!m)throw new Error('Component "'+i.descriptor.e+'" not found');o=[],n=c(h,i.descriptor.a,o),d(h,m,n,j,i.descriptor.f),e(h,o),f(h,i.descriptor.v),(i.descriptor.t1||i.descriptor.t2||i.descriptor.o)&&b('The "intro", "outro" and "decorator" directives have no effect on components'),g(h)}}(k,I,zd,Ad,Bd,Cd,Dd),Fd=function(a){var b=function(b,c){a(this,b,c)};return b.prototype={firstNode:function(){return this.instance.fragment.firstNode()},findNextNode:function(){return this.parentFragment.findNextNode(this)},detach:function(){return this.instance.fragment.detach()},teardown:function(){for(var a;this.complexParameters.length;)this.complexParameters.pop().teardown();for(;this.observers.length;)this.observers.pop().cancel();(a=this.root._liveComponentQueries[this.name])&&a._remove(this),this.instance.teardown()},toString:function(){return this.instance.fragment.toString()},find:function(a){return this.instance.fragment.find(a)},findAll:function(a,b){return this.instance.fragment.findAll(a,b)},findComponent:function(a){return a&&a!==this.name?null:this.instance},findAllComponents:function(a,b){b._test(this,!0),this.instance.fragment&&this.instance.fragment.findAllComponents(a,b)}},b}(Ed),Gd=function(a){var b=function(b,c){this.type=a.COMMENT,this.descriptor=b.descriptor,c&&(this.node=document.createComment(b.descriptor.f),c.appendChild(this.node))};return b.prototype={detach:function(){return this.node.parentNode.removeChild(this.node),this.node},teardown:function(a){a&&this.detach()},firstNode:function(){return this.node},toString:function(){return""}},b}(k),Hd=function(a,b,c,d,e,f,g,h,i,j,k,l,m){var n=function(a){a.pNode&&(this.docFrag=document.createDocumentFragment()),"string"==typeof a.descriptor?(this.html=a.descriptor,this.docFrag&&(this.nodes=d(this.html,a.pNode.tagName,this.docFrag))):c(this,a)};return n.prototype={detach:function(){var a,b;if(this.nodes)for(b=this.nodes.length;b--;)this.docFrag.appendChild(this.nodes[b]);else if(this.items)for(a=this.items.length,b=0;a>b;b+=1)this.docFrag.appendChild(this.items[b].detach());return this.docFrag},createItem:function(b){if("string"==typeof b.descriptor)return new e(b,this.docFrag);switch(b.descriptor.t){case a.INTERPOLATOR:return new f(b,this.docFrag);case a.SECTION:return new g(b,this.docFrag);case a.TRIPLE:return new h(b,this.docFrag);case a.ELEMENT:return this.root.components[b.descriptor.e]?new k(b,this.docFrag):new i(b,this.docFrag);case a.PARTIAL:return new j(b,this.docFrag);case a.COMMENT:return new l(b,this.docFrag);default:throw new Error("Something very strange happened. Please file an issue at https://github.com/RactiveJS/Ractive/issues. Thanks!")}},teardown:function(a){var b;if(this.nodes&&a)for(;b=this.nodes.pop();)b.parentNode.removeChild(b);else if(this.items)for(;this.items.length;)this.items.pop().teardown(a);this.nodes=this.items=this.docFrag=null},firstNode:function(){return this.items&&this.items[0]?this.items[0].firstNode():this.nodes?this.nodes[0]||null:null},findNextNode:function(a){var b=a.index;return this.items[b+1]?this.items[b+1].firstNode():this.owner===this.root?this.owner.component?this.owner.component.findNextNode():null:this.owner.findNextNode(this)},toString:function(){var a,b,c,d;if(this.html)return this.html;if(a="",!this.items)return a;for(c=this.items.length,b=0;c>b;b+=1)d=this.items[b],a+=d.toString();return a},find:function(a){var c,d,e,f,g;if(this.nodes){for(d=this.nodes.length,c=0;d>c;c+=1)if(f=this.nodes[c],1===f.nodeType){if(b(f,a))return f;if(g=f.querySelector(a))return g}return null}if(this.items){for(d=this.items.length,c=0;d>c;c+=1)if(e=this.items[c],e.find&&(g=e.find(a)))return g;return null}},findAll:function(a,c){var d,e,f,g,h,i,j;if(this.nodes){for(e=this.nodes.length,d=0;e>d;d+=1)if(g=this.nodes[d],1===g.nodeType&&(b(g,a)&&c.push(g),h=g.querySelectorAll(a)))for(i=h.length,j=0;i>j;j+=1)c.push(h[j])}else if(this.items)for(e=this.items.length,d=0;e>d;d+=1)f=this.items[d],f.findAll&&f.findAll(a,c);return c},findComponent:function(a){var b,c,d,e;if(this.items){for(b=this.items.length,c=0;b>c;c+=1)if(d=this.items[c],d.findComponent&&(e=d.findComponent(a)))return e;return null}},findAllComponents:function(a,b){var c,d,e;if(this.items)for(d=this.items.length,c=0;d>c;c+=1)e=this.items[c],e.findAllComponents&&e.findAllComponents(a,b);return b}},m.DomFragment=n,n}(k,Z,kb,lb,mb,zb,Fb,Gb,wc,xd,Fd,Gd,Eb),Id=function(a,b,c,d,e){return function(a,f){var g;if(!this._initing)throw new Error("You cannot call ractive.render() directly!");this._transitionManager=g=b(this,f),this.fragment=new e({descriptor:this.template,root:this,owner:this,pNode:a}),c(this),a&&a.appendChild(this.fragment.docFrag),d(this),this._transitionManager=null,g.ready(),this.rendered=!0}}(jb,q,o,p,Hd),Jd=function(a){return function(){return a("renderHTML() has been deprecated and will be removed in a future version. Please use toHTML() instead"),this.toHTML()}}(I),Kd=function(){return function(){return this.fragment.toString()}}(),Ld=function(a,b){return function(c){var d,e,f;for(this.fire("teardown"),f=this._transitionManager,this._transitionManager=e=a(this,c),this.fragment.teardown(!0);this._animations[0];)this._animations[0].stop();for(d in this._cache)b(this,d);this._transitionManager=f,e.ready()}}(q,m),Md=function(a){return function(b,c,d){var e;if("string"==typeof c&&a(d)){if(e=b.get(c),void 0===e&&(e=0),a(e))b.set(c,e+d);else if(b.debug)throw new Error("Cannot add to a non-numeric value")}else if(b.debug)throw new Error("Bad arguments")}}(J),Nd=function(a){return function(b,c){a(this,b,void 0===c?1:c)}}(Md),Od=function(a){return function(b,c){a(this,b,void 0===c?-1:-c)}}(Md),Pd=function(){return function(a){var b;if("string"==typeof a)b=this.get(a),this.set(a,!b);else if(this.debug)throw new Error("Bad arguments")}}(),Qd=function(){return function(a,b){var c,d,e,f,g;return c={},e=0,d=function(a,d){var f,h,i;h=e,i=b.length;do{if(f=b.indexOf(a,h),-1===f)return g=!0,-1;h=f+1}while(c[f]&&i>h);return f===e&&(e+=1),f!==d&&(g=!0),c[f]=!0,f},f=a.map(d),f.unchanged=!g,f}}(),Rd=function(a){return function(b,c,d,e){var f,g;for(f=c.length;f--;)g=c[f],g.type===a.REFERENCE?g.update():g.keypath===b&&g.type===a.SECTION&&!g.inverted&&g.docFrag?d[d.length]=g:e[e.length]=g}}(k),Sd=function(a,b,c,d,e,f,g,h,i,j){function k(a){return JSON.stringify(a)}function l(a){return m[a]||(m[a]=function(b){return b[a]}),m[a]}var m={};return function(m,n,o){var p,q,r,s,t,u,v,w,x,y,z,A,B,C,D;if(p=this.get(m),!b(p)||!b(n))return this.set(m,n,o&&o.complete);if(t=p.length===n.length,o&&o.compare){if(o.compare===!0)s=k;else if("string"==typeof o.compare)s=l(o.compare);else{if("function"!=typeof o.compare)throw new Error("The `compare` option must be a function, or a string representing an identifying field (or `true` to use JSON.stringify)");s=o.compare}try{q=p.map(s),r=n.map(s)}catch(E){if(this.debug)throw E;a("Merge operation: comparison failed. Falling back to identity checking"),q=p,r=n}}else q=p,r=n;if(v=i(q,r),c(this,m),h(this,m,n),!v.unchanged||!t){for(B=this._transitionManager,this._transitionManager=A=f(this,o&&o.complete),w=[],x=[],u=0;u 2 && args[1]) { - changed = Math.min(args[1], args.length - 2); - start = args[0]; - end = start + changed; - if (args[1] === args.length - 2) { - lengthUnchanged = true; - } - for (i = start; i < end; i += 1) { - childKeypath = keypath + '.' + i; - notifyDependants(root, childKeypath); - } - } - preDomUpdate(root); - upstreamQueue = []; - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - upstreamQueue[upstreamQueue.length] = keys.join('.'); - } - notifyDependants.multiple(root, upstreamQueue, true); - if (!lengthUnchanged) { - notifyDependants(root, keypath + '.length', true); - } - }; - queueDependants = function (keypath, deps, smartUpdateQueue, dumbUpdateQueue) { - var k, dependant; - k = deps.length; - while (k--) { - dependant = deps[k]; - if (dependant.type === types.REFERENCE) { - dependant.update(); - } else if (dependant.keypath === keypath && dependant.type === types.SECTION && !dependant.inverted && dependant.docFrag) { - smartUpdateQueue[smartUpdateQueue.length] = dependant; - } else { - dumbUpdateQueue[dumbUpdateQueue.length] = dependant; - } - } - }; - wrappers = array._ractive.wrappers; - i = wrappers.length; - while (i--) { - wrapper = wrappers[i]; - notifyKeypathDependants(wrapper.root, wrapper.keypath); - } - }; - patchedArrayProto = []; - mutatorMethods = [ - 'pop', - 'push', - 'reverse', - 'shift', - 'sort', - 'splice', - 'unshift' - ]; - noop = function () { - }; - mutatorMethods.forEach(function (methodName) { - var method = function () { - var result, instances, instance, i, previousTransitionManagers = {}, transitionManagers = {}; - result = Array.prototype[methodName].apply(this, arguments); - instances = this._ractive.instances; - i = instances.length; - while (i--) { - instance = instances[i]; - previousTransitionManagers[instance._guid] = instance._transitionManager; - instance._transitionManager = transitionManagers[instance._guid] = makeTransitionManager(instance, noop); - } - this._ractive.setting = true; - notifyArrayDependants(this, methodName, arguments); - this._ractive.setting = false; - i = instances.length; - while (i--) { - instance = instances[i]; - instance._transitionManager = previousTransitionManagers[instance._guid]; - transitionManagers[instance._guid].ready(); - preDomUpdate(instance); - postDomUpdate(instance); - } - return result; - }; - defineProperty(patchedArrayProto, methodName, { value: method }); - }); - testObj = {}; - if (testObj.__proto__) { - patchArrayMethods = function (array) { - array.__proto__ = patchedArrayProto; - }; - unpatchArrayMethods = function (array) { - array.__proto__ = Array.prototype; - }; - } else { - patchArrayMethods = function (array) { - var i, methodName; - i = mutatorMethods.length; - while (i--) { - methodName = mutatorMethods[i]; - defineProperty(array, methodName, { - value: patchedArrayProto[methodName], - configurable: true - }); - } - }; - unpatchArrayMethods = function (array) { - var i; - i = mutatorMethods.length; - while (i--) { - delete array[mutatorMethods[i]]; - } - }; - } - errorMessage = 'Something went wrong in a rather interesting way'; - return arrayAdaptor; - }(config_types, utils_defineProperty, utils_isArray, shared_clearCache, shared_preDomUpdate, shared_postDomUpdate, shared_makeTransitionManager, shared_notifyDependants); -var Ractive_prototype_get_magicAdaptor = function () { - - var magicAdaptor, MagicWrapper; - try { - Object.defineProperty({}, 'test', { value: 0 }); - } catch (err) { - return false; - } - magicAdaptor = { - filter: function (object, keypath) { - return !!keypath; - }, - wrap: function (ractive, object, keypath) { - return new MagicWrapper(ractive, object, keypath); - } - }; - MagicWrapper = function (ractive, object, keypath) { - var wrapper = this, keys, prop, objKeypath, descriptor, wrappers, oldGet, oldSet, get, set; - this.ractive = ractive; - this.keypath = keypath; - keys = keypath.split('.'); - this.prop = keys.pop(); - objKeypath = keys.join('.'); - this.obj = objKeypath ? ractive.get(objKeypath) : ractive.data; - descriptor = this.originalDescriptor = Object.getOwnPropertyDescriptor(this.obj, this.prop); - if (descriptor && descriptor.set && (wrappers = descriptor.set._ractiveWrappers)) { - if (wrappers.indexOf(this) === -1) { - wrappers.push(this); - } - return; - } - if (descriptor && !descriptor.configurable) { - throw new Error('Cannot use magic mode with property "' + prop + '" - object is not configurable'); - } - if (descriptor) { - this.value = descriptor.value; - oldGet = descriptor.get; - oldSet = descriptor.set; - } - get = oldGet || function () { - return wrapper.value; - }; - set = function (value) { - var wrappers, wrapper, i; - if (oldSet) { - oldSet(value); - } - wrappers = set._ractiveWrappers; - i = wrappers.length; - while (i--) { - wrapper = wrappers[i]; - if (!wrapper.resetting) { - wrapper.ractive.set(wrapper.keypath, value); - } - } - }; - set._ractiveWrappers = [this]; - Object.defineProperty(this.obj, this.prop, { - get: get, - set: set, - enumerable: true, - configurable: true - }); - }; - MagicWrapper.prototype = { - get: function () { - return this.value; - }, - reset: function (value) { - this.resetting = true; - this.value = value; - this.resetting = false; - }, - teardown: function () { - var descriptor, set, value, wrappers; - descriptor = Object.getOwnPropertyDescriptor(this.obj, this.prop); - set = descriptor.set; - wrappers = set._ractiveWrappers; - wrappers.splice(wrappers.indexOf(this), 1); - if (!wrappers.length) { - value = this.obj[this.prop]; - Object.defineProperty(this.obj, this.prop, this.originalDescriptor || { - writable: true, - enumerable: true, - configrable: true - }); - this.obj[this.prop] = value; - } - } - }; - return magicAdaptor; - }(); -var shared_adaptIfNecessary = function (adaptorRegistry, arrayAdaptor, magicAdaptor) { - - var prefixers = {}; - return function (ractive, keypath, value, isExpressionResult) { - var len, i, adaptor, wrapped; - len = ractive.adaptors.length; - for (i = 0; i < len; i += 1) { - adaptor = ractive.adaptors[i]; - if (typeof adaptor === 'string') { - if (!adaptorRegistry[adaptor]) { - throw new Error('Missing adaptor "' + adaptor + '"'); - } - adaptor = ractive.adaptors[i] = adaptorRegistry[adaptor]; - } - if (adaptor.filter(value, keypath, ractive)) { - wrapped = ractive._wrapped[keypath] = adaptor.wrap(ractive, value, keypath, getPrefixer(keypath)); - wrapped.value = value; - return; - } - } - if (!isExpressionResult) { - if (ractive.magic && magicAdaptor.filter(value, keypath, ractive)) { - ractive._wrapped[keypath] = magicAdaptor.wrap(ractive, value, keypath); - } else if (ractive.modifyArrays && arrayAdaptor.filter(value, keypath, ractive)) { - ractive._wrapped[keypath] = arrayAdaptor.wrap(ractive, value, keypath); - } - } - }; - function prefixKeypath(obj, prefix) { - var prefixed = {}, key; - if (!prefix) { - return obj; - } - prefix += '.'; - for (key in obj) { - if (obj.hasOwnProperty(key)) { - prefixed[prefix + key] = obj[key]; - } - } - return prefixed; - } - function getPrefixer(rootKeypath) { - var rootDot; - if (!prefixers[rootKeypath]) { - rootDot = rootKeypath ? rootKeypath + '.' : ''; - prefixers[rootKeypath] = function (relativeKeypath, value) { - var obj; - if (typeof relativeKeypath === 'string') { - obj = {}; - obj[rootDot + relativeKeypath] = value; - return obj; - } - if (typeof relativeKeypath === 'object') { - return rootDot ? prefixKeypath(relativeKeypath, rootKeypath) : relativeKeypath; - } - }; - } - return prefixers[rootKeypath]; - } - }(registries_adaptors, Ractive_prototype_get_arrayAdaptor, Ractive_prototype_get_magicAdaptor); -var Ractive_prototype_get__get = function (normaliseKeypath, adaptorRegistry, adaptIfNecessary) { - - var get, _get, retrieve; - get = function (keypath) { - if (this._captured && !this._captured[keypath]) { - this._captured.push(keypath); - this._captured[keypath] = true; - } - return _get(this, keypath); - }; - _get = function (ractive, keypath) { - var cache, cached, value, wrapped, evaluator; - keypath = normaliseKeypath(keypath); - cache = ractive._cache; - if ((cached = cache[keypath]) !== undefined) { - return cached; - } - if (wrapped = ractive._wrapped[keypath]) { - value = wrapped.value; - } else if (!keypath) { - adaptIfNecessary(ractive, '', ractive.data); - value = ractive.data; - } else if (evaluator = ractive._evaluators[keypath]) { - value = evaluator.value; - } else { - value = retrieve(ractive, keypath); - } - cache[keypath] = value; - return value; - }; - retrieve = function (ractive, keypath) { - var keys, key, parentKeypath, parentValue, cacheMap, value, wrapped; - keys = keypath.split('.'); - key = keys.pop(); - parentKeypath = keys.join('.'); - parentValue = _get(ractive, parentKeypath); - if (wrapped = ractive._wrapped[parentKeypath]) { - parentValue = wrapped.get(); - } - if (parentValue === null || parentValue === undefined) { - return; - } - if (!(cacheMap = ractive._cacheMap[parentKeypath])) { - ractive._cacheMap[parentKeypath] = [keypath]; - } else { - if (cacheMap.indexOf(keypath) === -1) { - cacheMap[cacheMap.length] = keypath; - } - } - value = parentValue[key]; - adaptIfNecessary(ractive, keypath, value); - ractive._cache[keypath] = value; - return value; - }; - return get; - }(utils_normaliseKeypath, registries_adaptors, shared_adaptIfNecessary); -var utils_isObject = function () { - - var toString = Object.prototype.toString; - return function (thing) { - return typeof thing === 'object' && toString.call(thing) === '[object Object]'; - }; - }(); -var utils_isEqual = function () { - - return function (a, b) { - if (a === null && b === null) { - return true; - } - if (typeof a === 'object' || typeof b === 'object') { - return false; - } - return a === b; - }; - }(); -var shared_resolveRef = function () { - - var resolveRef; - resolveRef = function (ractive, ref, contextStack) { - var keypath, keys, lastKey, contextKeys, innerMostContext, postfix, parentKeypath, parentValue, wrapped, context, ancestorErrorMessage; - ancestorErrorMessage = 'Could not resolve reference - too many "../" prefixes'; - if (ref === '.') { - if (!contextStack.length) { - return ''; - } - keypath = contextStack[contextStack.length - 1]; - } else if (ref.charAt(0) === '.') { - context = contextStack[contextStack.length - 1]; - contextKeys = context ? context.split('.') : []; - if (ref.substr(0, 3) === '../') { - while (ref.substr(0, 3) === '../') { - if (!contextKeys.length) { - throw new Error(ancestorErrorMessage); - } - contextKeys.pop(); - ref = ref.substring(3); - } - contextKeys.push(ref); - keypath = contextKeys.join('.'); - } else if (!context) { - keypath = ref.substring(1); - } else { - keypath = context + ref; - } - } else { - keys = ref.split('.'); - lastKey = keys.pop(); - postfix = keys.length ? '.' + keys.join('.') : ''; - contextStack = contextStack.concat(); - while (contextStack.length) { - innerMostContext = contextStack.pop(); - parentKeypath = innerMostContext + postfix; - parentValue = ractive.get(parentKeypath); - if (wrapped = ractive._wrapped[parentKeypath]) { - parentValue = wrapped.get(); - } - if (typeof parentValue === 'object' && parentValue !== null && parentValue.hasOwnProperty(lastKey)) { - keypath = innerMostContext + '.' + ref; - break; - } - } - if (!keypath && ractive.get(ref) !== undefined) { - keypath = ref; - } - } - return keypath ? keypath.replace(/^\./, '') : keypath; - }; - return resolveRef; - }(); -var shared_attemptKeypathResolution = function (resolveRef) { - - var push = Array.prototype.push; - return function (ractive) { - var unresolved, keypath, leftover; - while (unresolved = ractive._pendingResolution.pop()) { - keypath = resolveRef(ractive, unresolved.ref, unresolved.contextStack); - if (keypath !== undefined) { - unresolved.resolve(keypath); - } else { - (leftover || (leftover = [])).push(unresolved); - } - } - if (leftover) { - push.apply(ractive._pendingResolution, leftover); - } - }; - }(shared_resolveRef); -var shared_processDeferredUpdates = function (preDomUpdate, postDomUpdate) { - - return function (ractive) { - preDomUpdate(ractive); - postDomUpdate(ractive); - }; - }(shared_preDomUpdate, shared_postDomUpdate); -var Ractive_prototype_shared_replaceData = function () { - - return function (ractive, keypath, value) { - var keys, accumulated, wrapped, obj, key, currentKeypath, keypathToClear; - keys = keypath.split('.'); - accumulated = []; - if (wrapped = ractive._wrapped['']) { - if (wrapped.set) { - wrapped.set(keys.join('.'), value); - } - obj = wrapped.get(); - } else { - obj = ractive.data; - } - while (keys.length > 1) { - key = accumulated[accumulated.length] = keys.shift(); - currentKeypath = accumulated.join('.'); - if (wrapped = ractive._wrapped[currentKeypath]) { - if (wrapped.set) { - wrapped.set(keys.join('.'), value); - } - obj = wrapped.get(); - } else { - if (!obj.hasOwnProperty(key)) { - if (!keypathToClear) { - keypathToClear = currentKeypath; - } - obj[key] = /^\s*[0-9]+\s*$/.test(keys[0]) ? [] : {}; - } - obj = obj[key]; - } - } - key = keys[0]; - obj[key] = value; - return keypathToClear; - }; - }(); -var Ractive_prototype_set = function (isObject, isEqual, normaliseKeypath, clearCache, notifyDependants, attemptKeypathResolution, makeTransitionManager, processDeferredUpdates, replaceData) { - - var set, updateModel, getUpstreamChanges, resetWrapped; - set = function (keypath, value, complete) { - var map, changes, upstreamChanges, previousTransitionManager, transitionManager, i, changeHash; - changes = []; - if (isObject(keypath)) { - map = keypath; - complete = value; - } - if (map) { - for (keypath in map) { - if (map.hasOwnProperty(keypath)) { - value = map[keypath]; - keypath = normaliseKeypath(keypath); - updateModel(this, keypath, value, changes); - } - } - } else { - keypath = normaliseKeypath(keypath); - updateModel(this, keypath, value, changes); - } - if (!changes.length) { - return; - } - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - upstreamChanges = getUpstreamChanges(changes); - if (upstreamChanges.length) { - notifyDependants.multiple(this, upstreamChanges, true); - } - notifyDependants.multiple(this, changes); - if (this._pendingResolution.length) { - attemptKeypathResolution(this); - } - processDeferredUpdates(this); - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - if (!this.firingChangeEvent) { - this.firingChangeEvent = true; - changeHash = {}; - i = changes.length; - while (i--) { - changeHash[changes[i]] = this.get(changes[i]); - } - this.fire('change', changeHash); - this.firingChangeEvent = false; - } - return this; - }; - updateModel = function (ractive, keypath, value, changes) { - var cached, previous, wrapped, keypathToClear, evaluator; - if ((wrapped = ractive._wrapped[keypath]) && wrapped.reset) { - if (resetWrapped(ractive, keypath, value, wrapped, changes) !== false) { - return; - } - } - if (evaluator = ractive._evaluators[keypath]) { - evaluator.value = value; - } - cached = ractive._cache[keypath]; - previous = ractive.get(keypath); - if (previous !== value && !evaluator) { - keypathToClear = replaceData(ractive, keypath, value); - } else { - if (value === cached && typeof value !== 'object') { - return; - } - } - clearCache(ractive, keypathToClear || keypath); - changes[changes.length] = keypath; - }; - getUpstreamChanges = function (changes) { - var upstreamChanges = [''], i, keypath, keys, upstreamKeypath; - i = changes.length; - while (i--) { - keypath = changes[i]; - keys = keypath.split('.'); - while (keys.length > 1) { - keys.pop(); - upstreamKeypath = keys.join('.'); - if (!upstreamChanges[upstreamKeypath]) { - upstreamChanges[upstreamChanges.length] = upstreamKeypath; - upstreamChanges[upstreamKeypath] = true; - } - } - } - return upstreamChanges; - }; - resetWrapped = function (ractive, keypath, value, wrapped, changes) { - var previous, cached, cacheMap, i; - previous = wrapped.get(); - if (!isEqual(previous, value)) { - if (wrapped.reset(value) === false) { - return false; - } - } - value = wrapped.get(); - cached = ractive._cache[keypath]; - if (!isEqual(cached, value)) { - ractive._cache[keypath] = value; - cacheMap = ractive._cacheMap[keypath]; - if (cacheMap) { - i = cacheMap.length; - while (i--) { - clearCache(ractive, cacheMap[i]); - } - } - changes[changes.length] = keypath; - } - }; - return set; - }(utils_isObject, utils_isEqual, utils_normaliseKeypath, shared_clearCache, shared_notifyDependants, shared_attemptKeypathResolution, shared_makeTransitionManager, shared_processDeferredUpdates, Ractive_prototype_shared_replaceData); -var Ractive_prototype_update = function (makeTransitionManager, attemptKeypathResolution, clearCache, notifyDependants, processDeferredUpdates) { - - return function (keypath, complete) { - var transitionManager, previousTransitionManager; - if (typeof keypath === 'function') { - complete = keypath; - keypath = ''; - } - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - attemptKeypathResolution(this); - clearCache(this, keypath || ''); - notifyDependants(this, keypath || ''); - processDeferredUpdates(this); - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - if (typeof keypath === 'string') { - this.fire('update', keypath); - } else { - this.fire('update'); - } - return this; - }; - }(shared_makeTransitionManager, shared_attemptKeypathResolution, shared_clearCache, shared_notifyDependants, shared_processDeferredUpdates); -var utils_arrayContentsMatch = function (isArray) { - - return function (a, b) { - var i; - if (!isArray(a) || !isArray(b)) { - return false; - } - if (a.length !== b.length) { - return false; - } - i = a.length; - while (i--) { - if (a[i] !== b[i]) { - return false; - } - } - return true; - }; - }(utils_isArray); -var Ractive_prototype_updateModel = function (getValueFromCheckboxes, arrayContentsMatch, isEqual) { - - return function (keypath, cascade) { - var values, deferredCheckboxes, i; - if (typeof keypath !== 'string') { - keypath = ''; - cascade = true; - } - consolidateChangedValues(this, keypath, values = {}, deferredCheckboxes = [], cascade); - if (i = deferredCheckboxes.length) { - while (i--) { - keypath = deferredCheckboxes[i]; - values[keypath] = getValueFromCheckboxes(this, keypath); - } - } - this.set(values); - }; - function consolidateChangedValues(ractive, keypath, values, deferredCheckboxes, cascade) { - var bindings, childDeps, i, binding, oldValue, newValue; - bindings = ractive._twowayBindings[keypath]; - if (bindings) { - i = bindings.length; - while (i--) { - binding = bindings[i]; - if (binding.radioName && !binding.node.checked) { - continue; - } - if (binding.checkboxName) { - if (binding.changed() && !deferredCheckboxes[keypath]) { - deferredCheckboxes[keypath] = true; - deferredCheckboxes[deferredCheckboxes.length] = keypath; - } - continue; - } - oldValue = binding.attr.value; - newValue = binding.value(); - if (arrayContentsMatch(oldValue, newValue)) { - continue; - } - if (!isEqual(oldValue, newValue)) { - values[keypath] = newValue; - } - } - } - if (!cascade) { - return; - } - childDeps = ractive._depsMap[keypath]; - if (childDeps) { - i = childDeps.length; - while (i--) { - consolidateChangedValues(ractive, childDeps[i], values, deferredCheckboxes, cascade); - } - } - } - }(shared_getValueFromCheckboxes, utils_arrayContentsMatch, utils_isEqual); -var Ractive_prototype_animate_requestAnimationFrame = function () { - - if (typeof window === 'undefined') { - return; - } - (function (vendors, lastTime, window) { - var x, setTimeout; - if (window.requestAnimationFrame) { - return; - } - for (x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { - window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']; - } - if (!window.requestAnimationFrame) { - setTimeout = window.setTimeout; - window.requestAnimationFrame = function (callback) { - var currTime, timeToCall, id; - currTime = Date.now(); - timeToCall = Math.max(0, 16 - (currTime - lastTime)); - id = setTimeout(function () { - callback(currTime + timeToCall); - }, timeToCall); - lastTime = currTime + timeToCall; - return id; - }; - } - }([ - 'ms', - 'moz', - 'webkit', - 'o' - ], 0, window)); - return window.requestAnimationFrame; - }(); -var Ractive_prototype_animate_animations = function (rAF) { - - var queue = []; - var animations = { - tick: function () { - var i, animation; - for (i = 0; i < queue.length; i += 1) { - animation = queue[i]; - if (!animation.tick()) { - queue.splice(i--, 1); - } - } - if (queue.length) { - rAF(animations.tick); - } else { - animations.running = false; - } - }, - add: function (animation) { - queue[queue.length] = animation; - if (!animations.running) { - animations.running = true; - animations.tick(); - } - }, - abort: function (keypath, root) { - var i = queue.length, animation; - while (i--) { - animation = queue[i]; - if (animation.root === root && animation.keypath === keypath) { - animation.stop(); - } - } - } - }; - return animations; - }(Ractive_prototype_animate_requestAnimationFrame); -var utils_warn = function () { - - if (typeof console !== 'undefined' && typeof console.warn === 'function' && typeof console.warn.apply === 'function') { - return function () { - console.warn.apply(console, arguments); - }; - } - return function () { - }; - }(); -var utils_isNumeric = function () { - - return function (thing) { - return !isNaN(parseFloat(thing)) && isFinite(thing); - }; - }(); -var shared_interpolate = function (isArray, isObject, isNumeric) { - - var interpolate = function (from, to) { - if (isNumeric(from) && isNumeric(to)) { - return makeNumberInterpolator(+from, +to); - } - if (isArray(from) && isArray(to)) { - return makeArrayInterpolator(from, to); - } - if (isObject(from) && isObject(to)) { - return makeObjectInterpolator(from, to); - } - return function () { - return to; - }; - }; - return interpolate; - function makeNumberInterpolator(from, to) { - var delta = to - from; - if (!delta) { - return function () { - return from; - }; - } - return function (t) { - return from + t * delta; - }; - } - function makeArrayInterpolator(from, to) { - var intermediate, interpolators, len, i; - intermediate = []; - interpolators = []; - i = len = Math.min(from.length, to.length); - while (i--) { - interpolators[i] = interpolate(from[i], to[i]); - } - for (i = len; i < from.length; i += 1) { - intermediate[i] = from[i]; - } - for (i = len; i < to.length; i += 1) { - intermediate[i] = to[i]; - } - return function (t) { - var i = len; - while (i--) { - intermediate[i] = interpolators[i](t); - } - return intermediate; - }; - } - function makeObjectInterpolator(from, to) { - var properties = [], len, interpolators, intermediate, prop; - intermediate = {}; - interpolators = {}; - for (prop in from) { - if (from.hasOwnProperty(prop)) { - if (to.hasOwnProperty(prop)) { - properties[properties.length] = prop; - interpolators[prop] = interpolate(from[prop], to[prop]); - } else { - intermediate[prop] = from[prop]; - } - } - } - for (prop in to) { - if (to.hasOwnProperty(prop) && !from.hasOwnProperty(prop)) { - intermediate[prop] = to[prop]; - } - } - len = properties.length; - return function (t) { - var i = len, prop; - while (i--) { - prop = properties[i]; - intermediate[prop] = interpolators[prop](t); - } - return intermediate; - }; - } - }(utils_isArray, utils_isObject, utils_isNumeric); -var Ractive_prototype_animate_Animation = function (warn, interpolate) { - - var Animation = function (options) { - var key; - this.startTime = Date.now(); - for (key in options) { - if (options.hasOwnProperty(key)) { - this[key] = options[key]; - } - } - this.interpolator = interpolate(this.from, this.to); - this.running = true; - }; - Animation.prototype = { - tick: function () { - var elapsed, t, value, timeNow, index, keypath; - keypath = this.keypath; - if (this.running) { - timeNow = Date.now(); - elapsed = timeNow - this.startTime; - if (elapsed >= this.duration) { - if (keypath !== null) { - this.root.set(keypath, this.to); - } - if (this.step) { - this.step(1, this.to); - } - if (this.complete) { - this.complete(1, this.to); - } - index = this.root._animations.indexOf(this); - if (index === -1) { - warn('Animation was not found'); - } - this.root._animations.splice(index, 1); - this.running = false; - return false; - } - t = this.easing ? this.easing(elapsed / this.duration) : elapsed / this.duration; - if (keypath !== null) { - value = this.interpolator(t); - this.root.set(keypath, value); - } - if (this.step) { - this.step(t, value); - } - return true; - } - return false; - }, - stop: function () { - var index; - this.running = false; - index = this.root._animations.indexOf(this); - if (index === -1) { - warn('Animation was not found'); - } - this.root._animations.splice(index, 1); - } - }; - return Animation; - }(utils_warn, shared_interpolate); -var registries_easing = function () { - - return { - linear: function (pos) { - return pos; - }, - easeIn: function (pos) { - return Math.pow(pos, 3); - }, - easeOut: function (pos) { - return Math.pow(pos - 1, 3) + 1; - }, - easeInOut: function (pos) { - if ((pos /= 0.5) < 1) { - return 0.5 * Math.pow(pos, 3); - } - return 0.5 * (Math.pow(pos - 2, 3) + 2); - } - }; - }(); -var Ractive_prototype_animate__animate = function (isEqual, animations, Animation, easingRegistry) { - - var noAnimation = { - stop: function () { - } - }; - return function (keypath, to, options) { - var k, animation, animations, easing, duration, step, complete, makeValueCollector, currentValues, collectValue, dummy, dummyOptions; - if (typeof keypath === 'object') { - options = to || {}; - easing = options.easing; - duration = options.duration; - animations = []; - step = options.step; - complete = options.complete; - if (step || complete) { - currentValues = {}; - options.step = null; - options.complete = null; - makeValueCollector = function (keypath) { - return function (t, value) { - currentValues[keypath] = value; - }; - }; - } - for (k in keypath) { - if (keypath.hasOwnProperty(k)) { - if (step || complete) { - collectValue = makeValueCollector(k); - options = { - easing: easing, - duration: duration - }; - if (step) { - options.step = collectValue; - } - if (complete) { - options.complete = collectValue; - } - } - animations[animations.length] = animate(this, k, keypath[k], options); - } - } - if (step || complete) { - dummyOptions = { - easing: easing, - duration: duration - }; - if (step) { - dummyOptions.step = function (t) { - step(t, currentValues); - }; - } - if (complete) { - dummyOptions.complete = function (t) { - complete(t, currentValues); - }; - } - animations[animations.length] = dummy = animate(this, null, null, dummyOptions); - } - return { - stop: function () { - while (animations.length) { - animations.pop().stop(); - } - if (dummy) { - dummy.stop(); - } - } - }; - } - options = options || {}; - animation = animate(this, keypath, to, options); - return { - stop: function () { - animation.stop(); - } - }; - }; - function animate(root, keypath, to, options) { - var easing, duration, animation, from; - if (keypath !== null) { - from = root.get(keypath); - } - animations.abort(keypath, root); - if (isEqual(from, to)) { - if (options.complete) { - options.complete(1, options.to); - } - return noAnimation; - } - if (options.easing) { - if (typeof options.easing === 'function') { - easing = options.easing; - } else { - if (root.easing && root.easing[options.easing]) { - easing = root.easing[options.easing]; - } else { - easing = easingRegistry[options.easing]; - } - } - if (typeof easing !== 'function') { - easing = null; - } - } - duration = options.duration === undefined ? 400 : options.duration; - animation = new Animation({ - keypath: keypath, - from: from, - to: to, - root: root, - duration: duration, - easing: easing, - step: options.step, - complete: options.complete - }); - animations.add(animation); - root._animations[root._animations.length] = animation; - return animation; - } - }(utils_isEqual, Ractive_prototype_animate_animations, Ractive_prototype_animate_Animation, registries_easing); -var Ractive_prototype_on = function () { - - return function (eventName, callback) { - var self = this, listeners, n; - if (typeof eventName === 'object') { - listeners = []; - for (n in eventName) { - if (eventName.hasOwnProperty(n)) { - listeners[listeners.length] = this.on(n, eventName[n]); - } - } - return { - cancel: function () { - while (listeners.length) { - listeners.pop().cancel(); - } - } - }; - } - if (!this._subs[eventName]) { - this._subs[eventName] = [callback]; - } else { - this._subs[eventName].push(callback); - } - return { - cancel: function () { - self.off(eventName, callback); - } - }; - }; - }(); -var Ractive_prototype_off = function () { - - return function (eventName, callback) { - var subscribers, index; - if (!callback) { - if (!eventName) { - for (eventName in this._subs) { - delete this._subs[eventName]; - } - } else { - this._subs[eventName] = []; - } - } - subscribers = this._subs[eventName]; - if (subscribers) { - index = subscribers.indexOf(callback); - if (index !== -1) { - subscribers.splice(index, 1); - } - } - }; - }(); -var shared_registerDependant = function () { - - return function (dependant) { - var depsByKeypath, deps, keys, parentKeypath, map, ractive, keypath, priority; - ractive = dependant.root; - keypath = dependant.keypath; - priority = dependant.priority; - depsByKeypath = ractive._deps[priority] || (ractive._deps[priority] = {}); - deps = depsByKeypath[keypath] || (depsByKeypath[keypath] = []); - deps[deps.length] = dependant; - dependant.registered = true; - if (!keypath) { - return; - } - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - parentKeypath = keys.join('.'); - map = ractive._depsMap[parentKeypath] || (ractive._depsMap[parentKeypath] = []); - if (map[keypath] === undefined) { - map[keypath] = 0; - map[map.length] = keypath; - } - map[keypath] += 1; - keypath = parentKeypath; - } - }; - }(); -var shared_unregisterDependant = function () { - - return function (dependant) { - var deps, index, keys, parentKeypath, map, ractive, keypath, priority; - ractive = dependant.root; - keypath = dependant.keypath; - priority = dependant.priority; - deps = ractive._deps[priority][keypath]; - index = deps.indexOf(dependant); - if (index === -1 || !dependant.registered) { - throw new Error('Attempted to remove a dependant that was no longer registered! This should not happen. If you are seeing this bug in development please raise an issue at https://github.com/RactiveJS/Ractive/issues - thanks'); - } - deps.splice(index, 1); - dependant.registered = false; - if (!keypath) { - return; - } - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - parentKeypath = keys.join('.'); - map = ractive._depsMap[parentKeypath]; - map[keypath] -= 1; - if (!map[keypath]) { - map.splice(map.indexOf(keypath), 1); - map[keypath] = undefined; - } - keypath = parentKeypath; - } - }; - }(); -var Ractive_prototype_observe_Observer = function (isEqual) { - - var Observer = function (ractive, keypath, callback, options) { - var self = this; - this.root = ractive; - this.keypath = keypath; - this.callback = callback; - this.defer = options.defer; - this.debug = options.debug; - this.proxy = { - update: function () { - self.reallyUpdate(); - } - }; - this.priority = 0; - this.context = options && options.context ? options.context : ractive; - }; - Observer.prototype = { - init: function (immediate) { - if (immediate !== false) { - this.update(); - } else { - this.value = this.root.get(this.keypath); - } - }, - update: function () { - if (this.defer && this.ready) { - this.root._deferred.observers.push(this.proxy); - return; - } - this.reallyUpdate(); - }, - reallyUpdate: function () { - var oldValue, newValue; - oldValue = this.value; - newValue = this.root.get(this.keypath); - this.value = newValue; - if (this.updating) { - return; - } - this.updating = true; - if (!isEqual(newValue, oldValue) || !this.ready) { - try { - this.callback.call(this.context, newValue, oldValue, this.keypath); - } catch (err) { - if (this.debug || this.root.debug) { - throw err; - } - } - } - this.updating = false; - } - }; - return Observer; - }(utils_isEqual); -var Ractive_prototype_observe_getPattern = function () { - - return function (ractive, pattern) { - var keys, key, values, toGet, newToGet, expand, concatenate; - keys = pattern.split('.'); - toGet = []; - expand = function (keypath) { - var value, key; - value = ractive._wrapped[keypath] ? ractive._wrapped[keypath].get() : ractive.get(keypath); - for (key in value) { - newToGet.push(keypath + '.' + key); - } - }; - concatenate = function (keypath) { - return keypath + '.' + key; - }; - while (key = keys.shift()) { - if (key === '*') { - newToGet = []; - toGet.forEach(expand); - toGet = newToGet; - } else { - if (!toGet[0]) { - toGet[0] = key; - } else { - toGet = toGet.map(concatenate); - } - } - } - values = {}; - toGet.forEach(function (keypath) { - values[keypath] = ractive.get(keypath); - }); - return values; - }; - }(); -var Ractive_prototype_observe_PatternObserver = function (isEqual, getPattern) { - - var PatternObserver, wildcard = /\*/; - PatternObserver = function (ractive, keypath, callback, options) { - this.root = ractive; - this.callback = callback; - this.defer = options.defer; - this.debug = options.debug; - this.keypath = keypath; - this.regex = new RegExp('^' + keypath.replace(/\./g, '\\.').replace(/\*/g, '[^\\.]+') + '$'); - this.values = {}; - if (this.defer) { - this.proxies = []; - } - this.priority = 'pattern'; - this.context = options && options.context ? options.context : ractive; - }; - PatternObserver.prototype = { - init: function (immediate) { - var values, keypath; - values = getPattern(this.root, this.keypath); - if (immediate !== false) { - for (keypath in values) { - if (values.hasOwnProperty(keypath)) { - this.update(keypath); - } - } - } else { - this.values = values; - } - }, - update: function (keypath) { - var values; - if (wildcard.test(keypath)) { - values = getPattern(this.root, keypath); - for (keypath in values) { - if (values.hasOwnProperty(keypath)) { - this.update(keypath); - } - } - return; - } - if (this.defer && this.ready) { - this.root._deferred.observers.push(this.getProxy(keypath)); - return; - } - this.reallyUpdate(keypath); - }, - reallyUpdate: function (keypath) { - var value = this.root.get(keypath); - if (this.updating) { - this.values[keypath] = value; - return; - } - this.updating = true; - if (!isEqual(value, this.values[keypath]) || !this.ready) { - try { - this.callback.call(this.context, value, this.values[keypath], keypath); - } catch (err) { - if (this.debug || this.root.debug) { - throw err; - } - } - this.values[keypath] = value; - } - this.updating = false; - }, - getProxy: function (keypath) { - var self = this; - if (!this.proxies[keypath]) { - this.proxies[keypath] = { - update: function () { - self.reallyUpdate(keypath); - } - }; - } - return this.proxies[keypath]; - } - }; - return PatternObserver; - }(utils_isEqual, Ractive_prototype_observe_getPattern); -var Ractive_prototype_observe_getObserverFacade = function (normaliseKeypath, registerDependant, unregisterDependant, Observer, PatternObserver) { - - var wildcard = /\*/, emptyObject = {}; - return function getObserverFacade(ractive, keypath, callback, options) { - var observer, isPatternObserver; - keypath = normaliseKeypath(keypath); - options = options || emptyObject; - if (wildcard.test(keypath)) { - observer = new PatternObserver(ractive, keypath, callback, options); - ractive._patternObservers.push(observer); - isPatternObserver = true; - } else { - observer = new Observer(ractive, keypath, callback, options); - } - registerDependant(observer); - observer.init(options.init); - observer.ready = true; - return { - cancel: function () { - var index; - if (isPatternObserver) { - index = ractive._patternObservers.indexOf(observer); - if (index !== -1) { - ractive._patternObservers.splice(index, 1); - } - } - unregisterDependant(observer); - } - }; - }; - }(utils_normaliseKeypath, shared_registerDependant, shared_unregisterDependant, Ractive_prototype_observe_Observer, Ractive_prototype_observe_PatternObserver); -var Ractive_prototype_observe__observe = function (isObject, getObserverFacade) { - - return function observe(keypath, callback, options) { - var observers = [], k; - if (isObject(keypath)) { - options = callback; - for (k in keypath) { - if (keypath.hasOwnProperty(k)) { - callback = keypath[k]; - observers[observers.length] = getObserverFacade(this, k, callback, options); - } - } - return { - cancel: function () { - while (observers.length) { - observers.pop().cancel(); - } - } - }; - } - return getObserverFacade(this, keypath, callback, options); - }; - }(utils_isObject, Ractive_prototype_observe_getObserverFacade); -var Ractive_prototype_fire = function () { - - return function (eventName) { - var args, i, len, subscribers = this._subs[eventName]; - if (!subscribers) { - return; - } - args = Array.prototype.slice.call(arguments, 1); - for (i = 0, len = subscribers.length; i < len; i += 1) { - subscribers[i].apply(this, args); - } - }; - }(); -var Ractive_prototype_find = function () { - - return function (selector) { - if (!this.el) { - return null; - } - return this.fragment.find(selector); - }; - }(); -var utils_matches = function (isClient, createElement) { - - var div, methodNames, unprefixed, prefixed, vendors, i, j, makeFunction; - if (!isClient) { - return; - } - div = createElement('div'); - methodNames = [ - 'matches', - 'matchesSelector' - ]; - vendors = [ - 'o', - 'ms', - 'moz', - 'webkit' - ]; - makeFunction = function (methodName) { - return function (node, selector) { - return node[methodName](selector); - }; - }; - i = methodNames.length; - while (i--) { - unprefixed = methodNames[i]; - if (div[unprefixed]) { - return makeFunction(unprefixed); - } - j = vendors.length; - while (j--) { - prefixed = vendors[i] + unprefixed.substr(0, 1).toUpperCase() + unprefixed.substring(1); - if (div[prefixed]) { - return makeFunction(prefixed); - } - } - } - return function (node, selector) { - var nodes, i; - nodes = (node.parentNode || node.document).querySelectorAll(selector); - i = nodes.length; - while (i--) { - if (nodes[i] === node) { - return true; - } - } - return false; - }; - }(config_isClient, utils_createElement); -var Ractive_prototype_shared_makeQuery_test = function (matches) { - - return function (item, noDirty) { - var itemMatches = this._isComponentQuery ? !this.selector || item.name === this.selector : matches(item.node, this.selector); - if (itemMatches) { - this.push(item.node || item.instance); - if (!noDirty) { - this._makeDirty(); - } - return true; - } - }; - }(utils_matches); -var Ractive_prototype_shared_makeQuery_cancel = function () { - - return function () { - var liveQueries, selector, index; - liveQueries = this._root[this._isComponentQuery ? 'liveComponentQueries' : 'liveQueries']; - selector = this.selector; - index = liveQueries.indexOf(selector); - if (index !== -1) { - liveQueries.splice(index, 1); - liveQueries[selector] = null; - } - }; - }(); -var Ractive_prototype_shared_makeQuery_sortByItemPosition = function () { - - return function (a, b) { - var ancestryA, ancestryB, oldestA, oldestB, mutualAncestor, indexA, indexB, fragments, fragmentA, fragmentB; - ancestryA = getAncestry(a.component || a._ractive.proxy); - ancestryB = getAncestry(b.component || b._ractive.proxy); - oldestA = ancestryA[ancestryA.length - 1]; - oldestB = ancestryB[ancestryB.length - 1]; - while (oldestA && oldestA === oldestB) { - ancestryA.pop(); - ancestryB.pop(); - mutualAncestor = oldestA; - oldestA = ancestryA[ancestryA.length - 1]; - oldestB = ancestryB[ancestryB.length - 1]; - } - oldestA = oldestA.component || oldestA; - oldestB = oldestB.component || oldestB; - fragmentA = oldestA.parentFragment; - fragmentB = oldestB.parentFragment; - if (fragmentA === fragmentB) { - indexA = fragmentA.items.indexOf(oldestA); - indexB = fragmentB.items.indexOf(oldestB); - return indexA - indexB || ancestryA.length - ancestryB.length; - } - if (fragments = mutualAncestor.fragments) { - indexA = fragments.indexOf(fragmentA); - indexB = fragments.indexOf(fragmentB); - return indexA - indexB || ancestryA.length - ancestryB.length; - } - throw new Error('An unexpected condition was met while comparing the position of two components. Please file an issue at https://github.com/RactiveJS/Ractive/issues - thanks!'); - }; - function getParent(item) { - var parentFragment; - if (parentFragment = item.parentFragment) { - return parentFragment.owner; - } - if (item.component && (parentFragment = item.component.parentFragment)) { - return parentFragment.owner; - } - } - function getAncestry(item) { - var ancestry, ancestor; - ancestry = [item]; - ancestor = getParent(item); - while (ancestor) { - ancestry.push(ancestor); - ancestor = getParent(ancestor); - } - return ancestry; - } - }(); -var Ractive_prototype_shared_makeQuery_sortByDocumentPosition = function (sortByItemPosition) { - - return function (node, otherNode) { - var bitmask; - if (node.compareDocumentPosition) { - bitmask = node.compareDocumentPosition(otherNode); - return bitmask & 2 ? 1 : -1; - } - return sortByItemPosition(node, otherNode); - }; - }(Ractive_prototype_shared_makeQuery_sortByItemPosition); -var Ractive_prototype_shared_makeQuery_sort = function (sortByDocumentPosition, sortByItemPosition) { - - return function () { - this.sort(this._isComponentQuery ? sortByItemPosition : sortByDocumentPosition); - this._dirty = false; - }; - }(Ractive_prototype_shared_makeQuery_sortByDocumentPosition, Ractive_prototype_shared_makeQuery_sortByItemPosition); -var Ractive_prototype_shared_makeQuery_dirty = function () { - - return function () { - if (!this._dirty) { - this._root._deferred.liveQueries.push(this); - this._dirty = true; - } - }; - }(); -var Ractive_prototype_shared_makeQuery_remove = function () { - - return function (item) { - var index = this.indexOf(this._isComponentQuery ? item.instance : item.node); - if (index !== -1) { - this.splice(index, 1); - } - }; - }(); -var Ractive_prototype_shared_makeQuery__makeQuery = function (defineProperties, test, cancel, sort, dirty, remove) { - - return function (ractive, selector, live, isComponentQuery) { - var query; - query = []; - defineProperties(query, { - selector: { value: selector }, - live: { value: live }, - _isComponentQuery: { value: isComponentQuery }, - _test: { value: test } - }); - if (!live) { - return query; - } - defineProperties(query, { - cancel: { value: cancel }, - _root: { value: ractive }, - _sort: { value: sort }, - _makeDirty: { value: dirty }, - _remove: { value: remove }, - _dirty: { - value: false, - writable: true - } - }); - return query; - }; - }(utils_defineProperties, Ractive_prototype_shared_makeQuery_test, Ractive_prototype_shared_makeQuery_cancel, Ractive_prototype_shared_makeQuery_sort, Ractive_prototype_shared_makeQuery_dirty, Ractive_prototype_shared_makeQuery_remove); -var Ractive_prototype_findAll = function (warn, matches, defineProperties, makeQuery) { - - return function (selector, options) { - var liveQueries, query; - if (!this.el) { - return []; - } - options = options || {}; - liveQueries = this._liveQueries; - if (query = liveQueries[selector]) { - return options && options.live ? query : query.slice(); - } - query = makeQuery(this, selector, !!options.live, false); - if (query.live) { - liveQueries.push(selector); - liveQueries[selector] = query; - } - this.fragment.findAll(selector, query); - return query; - }; - }(utils_warn, utils_matches, utils_defineProperties, Ractive_prototype_shared_makeQuery__makeQuery); -var Ractive_prototype_findComponent = function () { - - return function (selector) { - return this.fragment.findComponent(selector); - }; - }(); -var Ractive_prototype_findAllComponents = function (warn, matches, defineProperties, makeQuery) { - - return function (selector, options) { - var liveQueries, query; - options = options || {}; - liveQueries = this._liveComponentQueries; - if (query = liveQueries[selector]) { - return options && options.live ? query : query.slice(); - } - query = makeQuery(this, selector, !!options.live, true); - if (query.live) { - liveQueries.push(selector); - liveQueries[selector] = query; - } - this.fragment.findAllComponents(selector, query); - return query; - }; - }(utils_warn, utils_matches, utils_defineProperties, Ractive_prototype_shared_makeQuery__makeQuery); -var utils_getElement = function () { - - return function (input) { - var output; - if (typeof window === 'undefined' || !document || !input) { - return null; - } - if (input.nodeType) { - return input; - } - if (typeof input === 'string') { - output = document.getElementById(input); - if (!output && document.querySelector) { - output = document.querySelector(input); - } - if (output && output.nodeType) { - return output; - } - } - if (input[0] && input[0].nodeType) { - return input[0]; - } - return null; - }; - }(); -var render_shared_initFragment = function (types, create) { - - return function (fragment, options) { - var numItems, i, parentFragment, parentRefs, ref; - fragment.owner = options.owner; - parentFragment = fragment.owner.parentFragment; - fragment.root = options.root; - fragment.pNode = options.pNode; - fragment.contextStack = options.contextStack || []; - if (fragment.owner.type === types.SECTION) { - fragment.index = options.index; - } - if (parentFragment) { - parentRefs = parentFragment.indexRefs; - if (parentRefs) { - fragment.indexRefs = create(null); - for (ref in parentRefs) { - fragment.indexRefs[ref] = parentRefs[ref]; - } - } - } - fragment.priority = parentFragment ? parentFragment.priority + 1 : 1; - if (options.indexRef) { - if (!fragment.indexRefs) { - fragment.indexRefs = {}; - } - fragment.indexRefs[options.indexRef] = options.index; - } - fragment.items = []; - numItems = options.descriptor ? options.descriptor.length : 0; - for (i = 0; i < numItems; i += 1) { - fragment.items[fragment.items.length] = fragment.createItem({ - parentFragment: fragment, - descriptor: options.descriptor[i], - index: i - }); - } - }; - }(config_types, utils_create); -var render_DomFragment_shared_insertHtml = function (createElement) { - - var elementCache = {}; - return function (html, tagName, docFrag) { - var container, nodes = []; - if (html) { - container = elementCache[tagName] || (elementCache[tagName] = createElement(tagName)); - container.innerHTML = html; - while (container.firstChild) { - nodes[nodes.length] = container.firstChild; - docFrag.appendChild(container.firstChild); - } - } - return nodes; - }; - }(utils_createElement); -var render_DomFragment_Text = function (types) { - - var DomText, lessThan, greaterThan; - lessThan = //g; - DomText = function (options, docFrag) { - this.type = types.TEXT; - this.descriptor = options.descriptor; - if (docFrag) { - this.node = document.createTextNode(options.descriptor); - docFrag.appendChild(this.node); - } - }; - DomText.prototype = { - detach: function () { - this.node.parentNode.removeChild(this.node); - return this.node; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - } - }, - firstNode: function () { - return this.node; - }, - toString: function () { - return ('' + this.descriptor).replace(lessThan, '<').replace(greaterThan, '>'); - } - }; - return DomText; - }(config_types); -var shared_teardown = function (unregisterDependant) { - - return function (thing) { - if (!thing.keypath) { - var index = thing.root._pendingResolution.indexOf(thing); - if (index !== -1) { - thing.root._pendingResolution.splice(index, 1); - } - } else { - unregisterDependant(thing); - } - }; - }(shared_unregisterDependant); -var render_shared_Evaluator_Reference = function (types, isEqual, defineProperty, registerDependant, unregisterDependant) { - - var Reference, thisPattern; - thisPattern = /this/; - Reference = function (root, keypath, evaluator, argNum, priority) { - var value; - this.evaluator = evaluator; - this.keypath = keypath; - this.root = root; - this.argNum = argNum; - this.type = types.REFERENCE; - this.priority = priority; - value = root.get(keypath); - if (typeof value === 'function') { - value = wrapFunction(value, root, evaluator); - } - this.value = evaluator.values[argNum] = value; - registerDependant(this); - }; - Reference.prototype = { - update: function () { - var value = this.root.get(this.keypath); - if (typeof value === 'function' && !value._nowrap) { - value = wrapFunction(value, this.root, this.evaluator); - } - if (!isEqual(value, this.value)) { - this.evaluator.values[this.argNum] = value; - this.evaluator.bubble(); - this.value = value; - } - }, - teardown: function () { - unregisterDependant(this); - } - }; - return Reference; - function wrapFunction(fn, ractive, evaluator) { - var prop, evaluators, index; - if (!thisPattern.test(fn.toString())) { - defineProperty(fn, '_nowrap', { value: true }); - return fn; - } - if (!fn['_' + ractive._guid]) { - defineProperty(fn, '_' + ractive._guid, { - value: function () { - var originalCaptured, result, i, evaluator; - originalCaptured = ractive._captured; - if (!originalCaptured) { - ractive._captured = []; - } - result = fn.apply(ractive, arguments); - if (ractive._captured.length) { - i = evaluators.length; - while (i--) { - evaluator = evaluators[i]; - evaluator.updateSoftDependencies(ractive._captured); - } - } - ractive._captured = originalCaptured; - return result; - }, - writable: true - }); - for (prop in fn) { - if (fn.hasOwnProperty(prop)) { - fn['_' + ractive._guid][prop] = fn[prop]; - } - } - fn['_' + ractive._guid + '_evaluators'] = []; - } - evaluators = fn['_' + ractive._guid + '_evaluators']; - index = evaluators.indexOf(evaluator); - if (index === -1) { - evaluators.push(evaluator); - } - return fn['_' + ractive._guid]; - } - }(config_types, utils_isEqual, utils_defineProperty, shared_registerDependant, shared_unregisterDependant); -var render_shared_Evaluator_SoftReference = function (isEqual, registerDependant, unregisterDependant) { - - var SoftReference = function (root, keypath, evaluator) { - this.root = root; - this.keypath = keypath; - this.priority = evaluator.priority; - this.evaluator = evaluator; - registerDependant(this); - }; - SoftReference.prototype = { - update: function () { - var value = this.root.get(this.keypath); - if (!isEqual(value, this.value)) { - this.evaluator.bubble(); - this.value = value; - } - }, - teardown: function () { - unregisterDependant(this); - } - }; - return SoftReference; - }(utils_isEqual, shared_registerDependant, shared_unregisterDependant); -var render_shared_Evaluator__Evaluator = function (isEqual, defineProperty, clearCache, notifyDependants, registerDependant, unregisterDependant, adaptIfNecessary, Reference, SoftReference) { - - var Evaluator, cache = {}; - Evaluator = function (root, keypath, functionStr, args, priority) { - var i, arg; - this.root = root; - this.keypath = keypath; - this.priority = priority; - this.fn = getFunctionFromString(functionStr, args.length); - this.values = []; - this.refs = []; - i = args.length; - while (i--) { - if (arg = args[i]) { - if (arg[0]) { - this.values[i] = arg[1]; - } else { - this.refs[this.refs.length] = new Reference(root, arg[1], this, i, priority); - } - } else { - this.values[i] = undefined; - } - } - this.selfUpdating = this.refs.length <= 1; - this.update(); - }; - Evaluator.prototype = { - bubble: function () { - if (this.selfUpdating) { - this.update(); - } else if (!this.deferred) { - this.root._deferred.evals.push(this); - this.deferred = true; - } - }, - update: function () { - var value; - if (this.evaluating) { - return this; - } - this.evaluating = true; - try { - value = this.fn.apply(null, this.values); - } catch (err) { - if (this.root.debug) { - throw err; - } else { - value = undefined; - } - } - if (!isEqual(value, this.value)) { - clearCache(this.root, this.keypath); - this.root._cache[this.keypath] = value; - adaptIfNecessary(this.root, this.keypath, value, true); - this.value = value; - notifyDependants(this.root, this.keypath); - } - this.evaluating = false; - return this; - }, - teardown: function () { - while (this.refs.length) { - this.refs.pop().teardown(); - } - clearCache(this.root, this.keypath); - this.root._evaluators[this.keypath] = null; - }, - refresh: function () { - if (!this.selfUpdating) { - this.deferred = true; - } - var i = this.refs.length; - while (i--) { - this.refs[i].update(); - } - if (this.deferred) { - this.update(); - this.deferred = false; - } - }, - updateSoftDependencies: function (softDeps) { - var i, keypath, ref; - if (!this.softRefs) { - this.softRefs = []; - } - i = this.softRefs.length; - while (i--) { - ref = this.softRefs[i]; - if (!softDeps[ref.keypath]) { - this.softRefs.splice(i, 1); - this.softRefs[ref.keypath] = false; - ref.teardown(); - } - } - i = softDeps.length; - while (i--) { - keypath = softDeps[i]; - if (!this.softRefs[keypath]) { - ref = new SoftReference(this.root, keypath, this); - this.softRefs[this.softRefs.length] = ref; - this.softRefs[keypath] = true; - } - } - this.selfUpdating = this.refs.length + this.softRefs.length <= 1; - } - }; - return Evaluator; - function getFunctionFromString(str, i) { - var fn, args; - str = str.replace(/\$\{([0-9]+)\}/g, '_$1'); - if (cache[str]) { - return cache[str]; - } - args = []; - while (i--) { - args[i] = '_' + i; - } - fn = new Function(args.join(','), 'return(' + str + ')'); - cache[str] = fn; - return fn; - } - }(utils_isEqual, utils_defineProperty, shared_clearCache, shared_notifyDependants, shared_registerDependant, shared_unregisterDependant, shared_adaptIfNecessary, render_shared_Evaluator_Reference, render_shared_Evaluator_SoftReference); -var render_shared_ExpressionResolver_ReferenceScout = function (resolveRef, teardown) { - - var ReferenceScout = function (resolver, ref, contextStack, argNum) { - var keypath, root; - root = this.root = resolver.root; - keypath = resolveRef(root, ref, contextStack); - if (keypath !== undefined) { - resolver.resolveRef(argNum, false, keypath); - } else { - this.ref = ref; - this.argNum = argNum; - this.resolver = resolver; - this.contextStack = contextStack; - root._pendingResolution[root._pendingResolution.length] = this; - } - }; - ReferenceScout.prototype = { - resolve: function (keypath) { - this.keypath = keypath; - this.resolver.resolveRef(this.argNum, false, keypath); - }, - teardown: function () { - if (!this.keypath) { - teardown(this); - } - } - }; - return ReferenceScout; - }(shared_resolveRef, shared_teardown); -var render_shared_ExpressionResolver_isRegularKeypath = function () { - - var keyPattern = /^(?:(?:[a-zA-Z$_][a-zA-Z$_0-9]*)|(?:[0-9]|[1-9][0-9]+))$/; - return function (keypath) { - var keys, key, i; - keys = keypath.split('.'); - i = keys.length; - while (i--) { - key = keys[i]; - if (key === 'undefined' || !keyPattern.test(key)) { - return false; - } - } - return true; - }; - }(); -var render_shared_ExpressionResolver_getKeypath = function (normaliseKeypath, isRegularKeypath) { - - return function (str, args) { - var unique, normalised; - unique = str.replace(/\$\{([0-9]+)\}/g, function (match, $1) { - return args[$1] ? args[$1][1] : 'undefined'; - }); - normalised = normaliseKeypath(unique); - if (isRegularKeypath(normalised)) { - return normalised; - } - return '${' + unique.replace(/[\.\[\]]/g, '-') + '}'; - }; - }(utils_normaliseKeypath, render_shared_ExpressionResolver_isRegularKeypath); -var render_shared_ExpressionResolver_reassignDependants = function (registerDependant, unregisterDependant) { - - return function (ractive, oldKeypath, newKeypath) { - var toReassign, i, dependant; - toReassign = []; - gatherDependants(ractive, oldKeypath, toReassign); - i = toReassign.length; - while (i--) { - dependant = toReassign[i]; - unregisterDependant(dependant); - dependant.keypath = dependant.keypath.replace(oldKeypath, newKeypath); - registerDependant(dependant); - dependant.update(); - } - }; - function cascade(ractive, oldKeypath, toReassign) { - var map, i; - map = ractive._depsMap[oldKeypath]; - if (!map) { - return; - } - i = map.length; - while (i--) { - gatherDependants(ractive, map[i], toReassign); - } - } - function gatherDependants(ractive, oldKeypath, toReassign) { - var priority, dependantsByKeypath, dependants, i; - priority = ractive._deps.length; - while (priority--) { - dependantsByKeypath = ractive._deps[priority]; - if (dependantsByKeypath) { - dependants = dependantsByKeypath[oldKeypath]; - if (dependants) { - i = dependants.length; - while (i--) { - toReassign.push(dependants[i]); - } - } - } - } - cascade(ractive, oldKeypath, toReassign); - } - }(shared_registerDependant, shared_unregisterDependant); -var render_shared_ExpressionResolver__ExpressionResolver = function (Evaluator, ReferenceScout, getKeypath, reassignDependants) { - - var ExpressionResolver = function (mustache) { - var expression, i, len, ref, indexRefs; - this.root = mustache.root; - this.mustache = mustache; - this.args = []; - this.scouts = []; - expression = mustache.descriptor.x; - indexRefs = mustache.parentFragment.indexRefs; - this.str = expression.s; - len = this.unresolved = this.args.length = expression.r ? expression.r.length : 0; - if (!len) { - this.resolved = this.ready = true; - this.bubble(); - return; - } - for (i = 0; i < len; i += 1) { - ref = expression.r[i]; - if (indexRefs && indexRefs[ref] !== undefined) { - this.resolveRef(i, true, indexRefs[ref]); - } else { - this.scouts[this.scouts.length] = new ReferenceScout(this, ref, mustache.contextStack, i); - } - } - this.ready = true; - this.bubble(); - }; - ExpressionResolver.prototype = { - bubble: function () { - var oldKeypath; - if (!this.ready) { - return; - } - oldKeypath = this.keypath; - this.keypath = getKeypath(this.str, this.args); - if (this.keypath.substr(0, 2) === '${') { - this.createEvaluator(); - } - if (oldKeypath) { - reassignDependants(this.root, oldKeypath, this.keypath); - } else { - this.mustache.resolve(this.keypath); - } - }, - teardown: function () { - while (this.scouts.length) { - this.scouts.pop().teardown(); - } - }, - resolveRef: function (argNum, isIndexRef, value) { - this.args[argNum] = [ - isIndexRef, - value - ]; - this.bubble(); - this.resolved = !--this.unresolved; - }, - createEvaluator: function () { - if (!this.root._evaluators[this.keypath]) { - this.root._evaluators[this.keypath] = new Evaluator(this.root, this.keypath, this.str, this.args, this.mustache.priority); - } else { - this.root._evaluators[this.keypath].refresh(); - } - } - }; - return ExpressionResolver; - }(render_shared_Evaluator__Evaluator, render_shared_ExpressionResolver_ReferenceScout, render_shared_ExpressionResolver_getKeypath, render_shared_ExpressionResolver_reassignDependants); -var render_shared_initMustache = function (resolveRef, ExpressionResolver) { - - return function (mustache, options) { - var keypath, indexRef, parentFragment; - parentFragment = mustache.parentFragment = options.parentFragment; - mustache.root = parentFragment.root; - mustache.contextStack = parentFragment.contextStack; - mustache.descriptor = options.descriptor; - mustache.index = options.index || 0; - mustache.priority = parentFragment.priority; - mustache.type = options.descriptor.t; - if (options.descriptor.r) { - if (parentFragment.indexRefs && parentFragment.indexRefs[options.descriptor.r] !== undefined) { - indexRef = parentFragment.indexRefs[options.descriptor.r]; - mustache.indexRef = options.descriptor.r; - mustache.value = indexRef; - mustache.render(mustache.value); - } else { - keypath = resolveRef(mustache.root, options.descriptor.r, mustache.contextStack); - if (keypath !== undefined) { - mustache.resolve(keypath); - } else { - mustache.ref = options.descriptor.r; - mustache.root._pendingResolution[mustache.root._pendingResolution.length] = mustache; - } - } - } - if (options.descriptor.x) { - mustache.expressionResolver = new ExpressionResolver(mustache); - } - if (mustache.descriptor.n && !mustache.hasOwnProperty('value')) { - mustache.render(undefined); - } - }; - }(shared_resolveRef, render_shared_ExpressionResolver__ExpressionResolver); -var render_shared_resolveMustache = function (types, registerDependant, unregisterDependant) { - - return function (keypath) { - if (keypath === this.keypath) { - return; - } - if (this.registered) { - unregisterDependant(this); - } - this.keypath = keypath; - registerDependant(this); - this.update(); - if (this.root.twoway && this.parentFragment.owner.type === types.ATTRIBUTE) { - this.parentFragment.owner.element.bind(); - } - if (this.expressionResolver && this.expressionResolver.resolved) { - this.expressionResolver = null; - } - }; - }(config_types, shared_registerDependant, shared_unregisterDependant); -var render_shared_updateMustache = function (isEqual) { - - return function () { - var wrapped, value; - value = this.root.get(this.keypath); - if (wrapped = this.root._wrapped[this.keypath]) { - value = wrapped.get(); - } - if (!isEqual(value, this.value)) { - this.render(value); - this.value = value; - } - }; - }(utils_isEqual); -var render_DomFragment_Interpolator = function (types, teardown, initMustache, resolveMustache, updateMustache) { - - var DomInterpolator, lessThan, greaterThan; - lessThan = //g; - DomInterpolator = function (options, docFrag) { - this.type = types.INTERPOLATOR; - if (docFrag) { - this.node = document.createTextNode(''); - docFrag.appendChild(this.node); - } - initMustache(this, options); - }; - DomInterpolator.prototype = { - update: updateMustache, - resolve: resolveMustache, - detach: function () { - this.node.parentNode.removeChild(this.node); - return this.node; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - } - teardown(this); - }, - render: function (value) { - if (this.node) { - this.node.data = value == undefined ? '' : value; - } - }, - firstNode: function () { - return this.node; - }, - toString: function () { - var value = this.value != undefined ? '' + this.value : ''; - return value.replace(lessThan, '<').replace(greaterThan, '>'); - } - }; - return DomInterpolator; - }(config_types, shared_teardown, render_shared_initMustache, render_shared_resolveMustache, render_shared_updateMustache); -var render_shared_updateSection = function (isArray, isObject, create) { - - return function (section, value) { - var fragmentOptions; - fragmentOptions = { - descriptor: section.descriptor.f, - root: section.root, - pNode: section.parentFragment.pNode, - owner: section - }; - if (section.descriptor.n) { - updateConditionalSection(section, value, true, fragmentOptions); - return; - } - if (isArray(value)) { - updateListSection(section, value, fragmentOptions); - } else if (isObject(value)) { - if (section.descriptor.i) { - updateListObjectSection(section, value, fragmentOptions); - } else { - updateContextSection(section, fragmentOptions); - } - } else { - updateConditionalSection(section, value, false, fragmentOptions); - } - }; - function updateListSection(section, value, fragmentOptions) { - var i, length, fragmentsToRemove; - length = value.length; - if (length < section.length) { - fragmentsToRemove = section.fragments.splice(length, section.length - length); - while (fragmentsToRemove.length) { - fragmentsToRemove.pop().teardown(true); - } - } else { - if (length > section.length) { - for (i = section.length; i < length; i += 1) { - fragmentOptions.contextStack = section.contextStack.concat(section.keypath + '.' + i); - fragmentOptions.index = i; - if (section.descriptor.i) { - fragmentOptions.indexRef = section.descriptor.i; - } - section.fragments[i] = section.createFragment(fragmentOptions); - } - } - } - section.length = length; - } - function updateListObjectSection(section, value, fragmentOptions) { - var id, fragmentsById; - fragmentsById = section.fragmentsById || (section.fragmentsById = create(null)); - for (id in fragmentsById) { - if (value[id] === undefined && fragmentsById[id]) { - fragmentsById[id].teardown(true); - fragmentsById[id] = null; - } - } - for (id in value) { - if (value[id] !== undefined && !fragmentsById[id]) { - fragmentOptions.contextStack = section.contextStack.concat(section.keypath + '.' + id); - fragmentOptions.index = id; - if (section.descriptor.i) { - fragmentOptions.indexRef = section.descriptor.i; - } - fragmentsById[id] = section.createFragment(fragmentOptions); - } - } - } - function updateContextSection(section, fragmentOptions) { - if (!section.length) { - fragmentOptions.contextStack = section.contextStack.concat(section.keypath); - fragmentOptions.index = 0; - section.fragments[0] = section.createFragment(fragmentOptions); - section.length = 1; - } - } - function updateConditionalSection(section, value, inverted, fragmentOptions) { - var doRender, emptyArray, fragmentsToRemove, fragment; - emptyArray = isArray(value) && value.length === 0; - if (inverted) { - doRender = emptyArray || !value; - } else { - doRender = value && !emptyArray; - } - if (doRender) { - if (!section.length) { - fragmentOptions.contextStack = section.contextStack; - fragmentOptions.index = 0; - section.fragments[0] = section.createFragment(fragmentOptions); - section.length = 1; - } - if (section.length > 1) { - fragmentsToRemove = section.fragments.splice(1); - while (fragment = fragmentsToRemove.pop()) { - fragment.teardown(true); - } - } - } else if (section.length) { - section.teardownFragments(true); - section.length = 0; - } - } - }(utils_isArray, utils_isObject, utils_create); -var render_DomFragment_Section_reassignFragment = function (types, unregisterDependant, ExpressionResolver) { - - return reassignFragment; - function reassignFragment(fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath) { - var i, item, context, query; - if (fragment.html) { - return; - } - if (fragment.indexRefs && fragment.indexRefs[indexRef] !== undefined) { - fragment.indexRefs[indexRef] = newIndex; - } - i = fragment.contextStack.length; - while (i--) { - context = fragment.contextStack[i]; - if (context.substr(0, oldKeypath.length) === oldKeypath) { - fragment.contextStack[i] = context.replace(oldKeypath, newKeypath); - } - } - i = fragment.items.length; - while (i--) { - item = fragment.items[i]; - switch (item.type) { - case types.ELEMENT: - reassignElement(item, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - break; - case types.PARTIAL: - reassignFragment(item.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - break; - case types.COMPONENT: - reassignFragment(item.instance.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - if (query = fragment.root._liveComponentQueries[item.name]) { - query._makeDirty(); - } - break; - case types.SECTION: - case types.INTERPOLATOR: - case types.TRIPLE: - reassignMustache(item, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - break; - } - } - } - function reassignElement(element, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath) { - var i, attribute, storage, masterEventName, proxies, proxy, binding, bindings, liveQueries, ractive; - i = element.attributes.length; - while (i--) { - attribute = element.attributes[i]; - if (attribute.fragment) { - reassignFragment(attribute.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - if (attribute.twoway) { - attribute.updateBindings(); - } - } - } - if (storage = element.node._ractive) { - if (storage.keypath.substr(0, oldKeypath.length) === oldKeypath) { - storage.keypath = storage.keypath.replace(oldKeypath, newKeypath); - } - if (indexRef !== undefined) { - storage.index[indexRef] = newIndex; - } - for (masterEventName in storage.events) { - proxies = storage.events[masterEventName].proxies; - i = proxies.length; - while (i--) { - proxy = proxies[i]; - if (typeof proxy.n === 'object') { - reassignFragment(proxy.a, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - if (proxy.d) { - reassignFragment(proxy.d, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - } - } - if (binding = storage.binding) { - if (binding.keypath.substr(0, oldKeypath.length) === oldKeypath) { - bindings = storage.root._twowayBindings[binding.keypath]; - bindings.splice(bindings.indexOf(binding), 1); - binding.keypath = binding.keypath.replace(oldKeypath, newKeypath); - bindings = storage.root._twowayBindings[binding.keypath] || (storage.root._twowayBindings[binding.keypath] = []); - bindings.push(binding); - } - } - } - if (element.fragment) { - reassignFragment(element.fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - if (liveQueries = element.liveQueries) { - ractive = element.root; - i = liveQueries.length; - while (i--) { - ractive._liveQueries[liveQueries[i]]._makeDirty(); - } - } - } - function reassignMustache(mustache, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath) { - var i; - if (mustache.descriptor.x) { - if (mustache.expressionResolver) { - mustache.expressionResolver.teardown(); - } - mustache.expressionResolver = new ExpressionResolver(mustache); - } - if (mustache.keypath) { - if (mustache.keypath.substr(0, oldKeypath.length) === oldKeypath) { - mustache.resolve(mustache.keypath.replace(oldKeypath, newKeypath)); - } - } else if (mustache.indexRef === indexRef) { - mustache.value = newIndex; - mustache.render(newIndex); - } - if (mustache.fragments) { - i = mustache.fragments.length; - while (i--) { - reassignFragment(mustache.fragments[i], indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - } - } - }(config_types, shared_unregisterDependant, render_shared_ExpressionResolver__ExpressionResolver); -var render_DomFragment_Section_reassignFragments = function (types, reassignFragment, preDomUpdate) { - - return function (root, section, start, end, by) { - var i, fragment, indexRef, oldIndex, newIndex, oldKeypath, newKeypath; - indexRef = section.descriptor.i; - for (i = start; i < end; i += 1) { - fragment = section.fragments[i]; - oldIndex = i - by; - newIndex = i; - oldKeypath = section.keypath + '.' + (i - by); - newKeypath = section.keypath + '.' + i; - fragment.index += by; - reassignFragment(fragment, indexRef, oldIndex, newIndex, by, oldKeypath, newKeypath); - } - preDomUpdate(root); - }; - }(config_types, render_DomFragment_Section_reassignFragment, shared_preDomUpdate); -var render_DomFragment_Section_prototype_merge = function (reassignFragment) { - - return function (newIndices) { - var section = this, parentFragment, firstChange, changed, i, newLength, newFragments, toTeardown, fragmentOptions, fragment, nextNode; - parentFragment = this.parentFragment; - newFragments = []; - newIndices.forEach(function (newIndex, oldIndex) { - var by, oldKeypath, newKeypath; - if (newIndex === oldIndex) { - newFragments[newIndex] = section.fragments[oldIndex]; - return; - } - if (firstChange === undefined) { - firstChange = oldIndex; - } - if (newIndex === -1) { - (toTeardown || (toTeardown = [])).push(section.fragments[oldIndex]); - return; - } - by = newIndex - oldIndex; - oldKeypath = section.keypath + '.' + oldIndex; - newKeypath = section.keypath + '.' + newIndex; - reassignFragment(section.fragments[oldIndex], section.descriptor.i, oldIndex, newIndex, by, oldKeypath, newKeypath); - newFragments[newIndex] = section.fragments[oldIndex]; - changed = true; - }); - if (toTeardown) { - while (fragment = toTeardown.pop()) { - fragment.teardown(true); - } - } - if (firstChange === undefined) { - firstChange = this.length; - } - newLength = this.root.get(this.keypath).length; - if (newLength === firstChange) { - return; - } - fragmentOptions = { - descriptor: this.descriptor.f, - root: this.root, - pNode: parentFragment.pNode, - owner: this - }; - if (this.descriptor.i) { - fragmentOptions.indexRef = this.descriptor.i; - } - for (i = firstChange; i < newLength; i += 1) { - if (fragment = newFragments[i]) { - this.docFrag.appendChild(fragment.detach(false)); - } else { - fragmentOptions.contextStack = this.contextStack.concat(this.keypath + '.' + i); - fragmentOptions.index = i; - fragment = this.createFragment(fragmentOptions); - } - this.fragments[i] = fragment; - } - nextNode = parentFragment.findNextNode(this); - parentFragment.pNode.insertBefore(this.docFrag, nextNode); - this.length = newLength; - }; - }(render_DomFragment_Section_reassignFragment); -var circular = function () { - - return []; - }(); -var render_DomFragment_Section__Section = function (types, isClient, initMustache, updateMustache, resolveMustache, updateSection, reassignFragment, reassignFragments, merge, teardown, circular) { - - var DomSection, DomFragment; - circular.push(function () { - DomFragment = circular.DomFragment; - }); - DomSection = function (options, docFrag) { - this.type = types.SECTION; - this.inverted = !!options.descriptor.n; - this.fragments = []; - this.length = 0; - if (docFrag) { - this.docFrag = document.createDocumentFragment(); - } - this.initialising = true; - initMustache(this, options); - if (docFrag) { - docFrag.appendChild(this.docFrag); - } - this.initialising = false; - }; - DomSection.prototype = { - update: updateMustache, - resolve: resolveMustache, - smartUpdate: function (methodName, args) { - var fragmentOptions; - if (methodName === 'push' || methodName === 'unshift' || methodName === 'splice') { - fragmentOptions = { - descriptor: this.descriptor.f, - root: this.root, - pNode: this.parentFragment.pNode, - owner: this - }; - if (this.descriptor.i) { - fragmentOptions.indexRef = this.descriptor.i; - } - } - if (this[methodName]) { - this.rendering = true; - this[methodName](fragmentOptions, args); - this.rendering = false; - } - }, - pop: function () { - if (this.length) { - this.fragments.pop().teardown(true); - this.length -= 1; - } - }, - push: function (fragmentOptions, args) { - var start, end, i; - start = this.length; - end = start + args.length; - for (i = start; i < end; i += 1) { - fragmentOptions.contextStack = this.contextStack.concat(this.keypath + '.' + i); - fragmentOptions.index = i; - this.fragments[i] = this.createFragment(fragmentOptions); - } - this.length += args.length; - this.parentFragment.pNode.insertBefore(this.docFrag, this.parentFragment.findNextNode(this)); - }, - shift: function () { - this.splice(null, [ - 0, - 1 - ]); - }, - unshift: function (fragmentOptions, args) { - this.splice(fragmentOptions, [ - 0, - 0 - ].concat(new Array(args.length))); - }, - splice: function (fragmentOptions, args) { - var insertionPoint, addedItems, removedItems, balance, i, start, end, spliceArgs, reassignStart; - if (!args.length) { - return; - } - start = +(args[0] < 0 ? this.length + args[0] : args[0]); - addedItems = Math.max(0, args.length - 2); - removedItems = args[1] !== undefined ? args[1] : this.length - start; - removedItems = Math.min(removedItems, this.length - start); - balance = addedItems - removedItems; - if (!balance) { - return; - } - if (balance < 0) { - end = start - balance; - for (i = start; i < end; i += 1) { - this.fragments[i].teardown(true); - } - this.fragments.splice(start, -balance); - } else { - end = start + balance; - insertionPoint = this.fragments[start] ? this.fragments[start].firstNode() : this.parentFragment.findNextNode(this); - spliceArgs = [ - start, - 0 - ].concat(new Array(balance)); - this.fragments.splice.apply(this.fragments, spliceArgs); - for (i = start; i < end; i += 1) { - fragmentOptions.contextStack = this.contextStack.concat(this.keypath + '.' + i); - fragmentOptions.index = i; - this.fragments[i] = this.createFragment(fragmentOptions); - } - this.parentFragment.pNode.insertBefore(this.docFrag, insertionPoint); - } - this.length += balance; - reassignStart = start + addedItems; - reassignFragments(this.root, this, reassignStart, this.length, balance); - }, - merge: merge, - detach: function () { - var i, len; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - this.docFrag.appendChild(this.fragments[i].detach()); - } - return this.docFrag; - }, - teardown: function (destroy) { - this.teardownFragments(destroy); - teardown(this); - }, - firstNode: function () { - if (this.fragments[0]) { - return this.fragments[0].firstNode(); - } - return this.parentFragment.findNextNode(this); - }, - findNextNode: function (fragment) { - if (this.fragments[fragment.index + 1]) { - return this.fragments[fragment.index + 1].firstNode(); - } - return this.parentFragment.findNextNode(this); - }, - teardownFragments: function (destroy) { - var id, fragment; - while (fragment = this.fragments.shift()) { - fragment.teardown(destroy); - } - if (this.fragmentsById) { - for (id in this.fragmentsById) { - if (this.fragments[id]) { - this.fragmentsById[id].teardown(destroy); - this.fragmentsById[id] = null; - } - } - } - }, - render: function (value) { - var nextNode, wrapped; - if (wrapped = this.root._wrapped[this.keypath]) { - value = wrapped.get(); - } - if (this.rendering) { - return; - } - this.rendering = true; - updateSection(this, value); - this.rendering = false; - if (this.docFrag && !this.docFrag.childNodes.length) { - return; - } - if (!this.initialising && isClient) { - nextNode = this.parentFragment.findNextNode(this); - if (nextNode && nextNode.parentNode === this.parentFragment.pNode) { - this.parentFragment.pNode.insertBefore(this.docFrag, nextNode); - } else { - this.parentFragment.pNode.appendChild(this.docFrag); - } - } - }, - createFragment: function (options) { - var fragment = new DomFragment(options); - if (this.docFrag) { - this.docFrag.appendChild(fragment.docFrag); - } - return fragment; - }, - toString: function () { - var str, i, id, len; - str = ''; - i = 0; - len = this.length; - for (i = 0; i < len; i += 1) { - str += this.fragments[i].toString(); - } - if (this.fragmentsById) { - for (id in this.fragmentsById) { - if (this.fragmentsById[id]) { - str += this.fragmentsById[id].toString(); - } - } - } - return str; - }, - find: function (selector) { - var i, len, queryResult; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - if (queryResult = this.fragments[i].find(selector)) { - return queryResult; - } - } - return null; - }, - findAll: function (selector, query) { - var i, len; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - this.fragments[i].findAll(selector, query); - } - }, - findComponent: function (selector) { - var i, len, queryResult; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - if (queryResult = this.fragments[i].findComponent(selector)) { - return queryResult; - } - } - return null; - }, - findAllComponents: function (selector, query) { - var i, len; - len = this.fragments.length; - for (i = 0; i < len; i += 1) { - this.fragments[i].findAllComponents(selector, query); - } - } - }; - return DomSection; - }(config_types, config_isClient, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache, render_shared_updateSection, render_DomFragment_Section_reassignFragment, render_DomFragment_Section_reassignFragments, render_DomFragment_Section_prototype_merge, shared_teardown, circular); -var render_DomFragment_Triple = function (types, matches, initMustache, updateMustache, resolveMustache, insertHtml, teardown) { - - var DomTriple = function (options, docFrag) { - this.type = types.TRIPLE; - if (docFrag) { - this.nodes = []; - this.docFrag = document.createDocumentFragment(); - } - this.initialising = true; - initMustache(this, options); - if (docFrag) { - docFrag.appendChild(this.docFrag); - } - this.initialising = false; - }; - DomTriple.prototype = { - update: updateMustache, - resolve: resolveMustache, - detach: function () { - var i = this.nodes.length; - while (i--) { - this.docFrag.appendChild(this.nodes[i]); - } - return this.docFrag; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - this.docFrag = this.nodes = null; - } - teardown(this); - }, - firstNode: function () { - if (this.nodes[0]) { - return this.nodes[0]; - } - return this.parentFragment.findNextNode(this); - }, - render: function (html) { - var node, pNode; - if (!this.nodes) { - return; - } - while (this.nodes.length) { - node = this.nodes.pop(); - node.parentNode.removeChild(node); - } - if (!html) { - this.nodes = []; - return; - } - pNode = this.parentFragment.pNode; - this.nodes = insertHtml(html, pNode.tagName, this.docFrag); - if (!this.initialising) { - pNode.insertBefore(this.docFrag, this.parentFragment.findNextNode(this)); - } - }, - toString: function () { - return this.value != undefined ? this.value : ''; - }, - find: function (selector) { - var i, len, node, queryResult; - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - return node; - } - if (queryResult = node.querySelector(selector)) { - return queryResult; - } - } - return null; - }, - findAll: function (selector, queryResult) { - var i, len, node, queryAllResult, numNodes, j; - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - queryResult.push(node); - } - if (queryAllResult = node.querySelectorAll(selector)) { - numNodes = queryAllResult.length; - for (j = 0; j < numNodes; j += 1) { - queryResult.push(queryAllResult[j]); - } - } - } - } - }; - return DomTriple; - }(config_types, utils_matches, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache, render_DomFragment_shared_insertHtml, shared_teardown); -var render_DomFragment_Element_initialise_getElementNamespace = function (namespaces) { - - return function (descriptor, parentNode) { - if (descriptor.a && descriptor.a.xmlns) { - return descriptor.a.xmlns; - } - return descriptor.e === 'svg' ? namespaces.svg : parentNode.namespaceURI || namespaces.html; - }; - }(config_namespaces); -var render_DomFragment_shared_enforceCase = function () { - - var svgCamelCaseElements, svgCamelCaseAttributes, createMap, map; - svgCamelCaseElements = 'altGlyph altGlyphDef altGlyphItem animateColor animateMotion animateTransform clipPath feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile feTurbulence foreignObject glyphRef linearGradient radialGradient textPath vkern'.split(' '); - svgCamelCaseAttributes = 'attributeName attributeType baseFrequency baseProfile calcMode clipPathUnits contentScriptType contentStyleType diffuseConstant edgeMode externalResourcesRequired filterRes filterUnits glyphRef gradientTransform gradientUnits kernelMatrix kernelUnitLength keyPoints keySplines keyTimes lengthAdjust limitingConeAngle markerHeight markerUnits markerWidth maskContentUnits maskUnits numOctaves pathLength patternContentUnits patternTransform patternUnits pointsAtX pointsAtY pointsAtZ preserveAlpha preserveAspectRatio primitiveUnits refX refY repeatCount repeatDur requiredExtensions requiredFeatures specularConstant specularExponent spreadMethod startOffset stdDeviation stitchTiles surfaceScale systemLanguage tableValues targetX targetY textLength viewBox viewTarget xChannelSelector yChannelSelector zoomAndPan'.split(' '); - createMap = function (items) { - var map = {}, i = items.length; - while (i--) { - map[items[i].toLowerCase()] = items[i]; - } - return map; - }; - map = createMap(svgCamelCaseElements.concat(svgCamelCaseAttributes)); - return function (elementName) { - var lowerCaseElementName = elementName.toLowerCase(); - return map[lowerCaseElementName] || lowerCaseElementName; - }; - }(); -var render_DomFragment_Attribute_helpers_determineNameAndNamespace = function (namespaces, enforceCase) { - - return function (attribute, name) { - var colonIndex, namespacePrefix; - colonIndex = name.indexOf(':'); - if (colonIndex !== -1) { - namespacePrefix = name.substr(0, colonIndex); - if (namespacePrefix !== 'xmlns') { - name = name.substring(colonIndex + 1); - attribute.name = enforceCase(name); - attribute.lcName = attribute.name.toLowerCase(); - attribute.namespace = namespaces[namespacePrefix.toLowerCase()]; - if (!attribute.namespace) { - throw 'Unknown namespace ("' + namespacePrefix + '")'; - } - return; - } - } - attribute.name = attribute.element.namespace !== namespaces.html ? enforceCase(name) : name; - attribute.lcName = attribute.name.toLowerCase(); - }; - }(config_namespaces, render_DomFragment_shared_enforceCase); -var render_DomFragment_Attribute_helpers_setStaticAttribute = function (namespaces) { - - return function (attribute, options) { - var node, value = options.value === null ? '' : options.value; - if (node = options.pNode) { - if (attribute.namespace) { - node.setAttributeNS(attribute.namespace, options.name, value); - } else { - if (options.name === 'style' && node.style.setAttribute) { - node.style.setAttribute('cssText', value); - } else if (options.name === 'class' && (!node.namespaceURI || node.namespaceURI === namespaces.html)) { - node.className = value; - } else { - node.setAttribute(options.name, value); - } - } - if (attribute.name === 'id') { - options.root.nodes[options.value] = node; - } - if (attribute.name === 'value') { - node._ractive.value = options.value; - } - } - attribute.value = options.value; - }; - }(config_namespaces); -var render_DomFragment_Attribute_helpers_determinePropertyName = function (namespaces) { - - var propertyNames = { - 'accept-charset': 'acceptCharset', - accesskey: 'accessKey', - bgcolor: 'bgColor', - 'class': 'className', - codebase: 'codeBase', - colspan: 'colSpan', - contenteditable: 'contentEditable', - datetime: 'dateTime', - dirname: 'dirName', - 'for': 'htmlFor', - 'http-equiv': 'httpEquiv', - ismap: 'isMap', - maxlength: 'maxLength', - novalidate: 'noValidate', - pubdate: 'pubDate', - readonly: 'readOnly', - rowspan: 'rowSpan', - tabindex: 'tabIndex', - usemap: 'useMap' - }; - return function (attribute, options) { - var propertyName; - if (attribute.pNode && !attribute.namespace && (!options.pNode.namespaceURI || options.pNode.namespaceURI === namespaces.html)) { - propertyName = propertyNames[attribute.name] || attribute.name; - if (options.pNode[propertyName] !== undefined) { - attribute.propertyName = propertyName; - } - if (typeof options.pNode[propertyName] === 'boolean' || propertyName === 'value') { - attribute.useProperty = true; - } - } - }; - }(config_namespaces); -var render_DomFragment_Attribute_prototype_bind = function (types, warn, arrayContentsMatch, getValueFromCheckboxes) { - - var bindAttribute, getInterpolator, updateModel, update, getBinding, inheritProperties, MultipleSelectBinding, SelectBinding, RadioNameBinding, CheckboxNameBinding, CheckedBinding, FileListBinding, ContentEditableBinding, GenericBinding; - bindAttribute = function () { - var node = this.pNode, interpolator, binding, bindings; - if (!this.fragment) { - return false; - } - interpolator = getInterpolator(this); - if (!interpolator) { - return false; - } - this.interpolator = interpolator; - this.keypath = interpolator.keypath || interpolator.descriptor.r; - binding = getBinding(this); - if (!binding) { - return false; - } - node._ractive.binding = this.element.binding = binding; - this.twoway = true; - bindings = this.root._twowayBindings[this.keypath] || (this.root._twowayBindings[this.keypath] = []); - bindings[bindings.length] = binding; - return true; - }; - updateModel = function () { - this._ractive.binding.update(); - }; - update = function () { - var value = this._ractive.root.get(this._ractive.binding.keypath); - this.value = value == undefined ? '' : value; - }; - getInterpolator = function (attribute) { - var item, errorMessage; - if (attribute.fragment.items.length !== 1) { - return null; - } - item = attribute.fragment.items[0]; - if (item.type !== types.INTERPOLATOR) { - return null; - } - if (!item.keypath && !item.ref) { - return null; - } - if (item.keypath && item.keypath.substr(0, 2) === '${') { - errorMessage = 'You cannot set up two-way binding against an expression ' + item.keypath; - if (attribute.root.debug) { - warn(errorMessage); - } - return null; - } - return item; - }; - getBinding = function (attribute) { - var node = attribute.pNode; - if (node.tagName === 'SELECT') { - return node.multiple ? new MultipleSelectBinding(attribute, node) : new SelectBinding(attribute, node); - } - if (node.type === 'checkbox' || node.type === 'radio') { - if (attribute.propertyName === 'name') { - if (node.type === 'checkbox') { - return new CheckboxNameBinding(attribute, node); - } - if (node.type === 'radio') { - return new RadioNameBinding(attribute, node); - } - } - if (attribute.propertyName === 'checked') { - return new CheckedBinding(attribute, node); - } - return null; - } - if (attribute.lcName !== 'value') { - warn('This is... odd'); - } - if (node.type === 'file') { - return new FileListBinding(attribute, node); - } - if (node.getAttribute('contenteditable')) { - return new ContentEditableBinding(attribute, node); - } - return new GenericBinding(attribute, node); - }; - MultipleSelectBinding = function (attribute, node) { - var valueFromModel; - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - valueFromModel = this.root.get(this.keypath); - if (valueFromModel === undefined) { - this.update(); - } - }; - MultipleSelectBinding.prototype = { - value: function () { - var value, options, i, len; - value = []; - options = this.node.options; - len = options.length; - for (i = 0; i < len; i += 1) { - if (options[i].selected) { - value[value.length] = options[i]._ractive.value; - } - } - return value; - }, - update: function () { - var attribute, previousValue, value; - attribute = this.attr; - previousValue = attribute.value; - value = this.value(); - if (previousValue === undefined || !arrayContentsMatch(value, previousValue)) { - attribute.receiving = true; - attribute.value = value; - this.root.set(this.keypath, value); - attribute.receiving = false; - } - return this; - }, - deferUpdate: function () { - if (this.deferred === true) { - return; - } - this.root._deferred.attrs.push(this); - this.deferred = true; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - } - }; - SelectBinding = function (attribute, node) { - var valueFromModel; - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - valueFromModel = this.root.get(this.keypath); - if (valueFromModel === undefined) { - this.update(); - } - }; - SelectBinding.prototype = { - value: function () { - var options, i, len; - options = this.node.options; - len = options.length; - for (i = 0; i < len; i += 1) { - if (options[i].selected) { - return options[i]._ractive.value; - } - } - }, - update: function () { - var value = this.value(); - this.attr.receiving = true; - this.attr.value = value; - this.root.set(this.keypath, value); - this.attr.receiving = false; - return this; - }, - deferUpdate: function () { - if (this.deferred === true) { - return; - } - this.root._deferred.attrs.push(this); - this.deferred = true; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - } - }; - RadioNameBinding = function (attribute, node) { - var valueFromModel; - this.radioName = true; - inheritProperties(this, attribute, node); - node.name = '{{' + attribute.keypath + '}}'; - node.addEventListener('change', updateModel, false); - if (node.attachEvent) { - node.addEventListener('click', updateModel, false); - } - valueFromModel = this.root.get(this.keypath); - if (valueFromModel !== undefined) { - node.checked = valueFromModel == node._ractive.value; - } else { - this.root._deferred.radios.push(this); - } - }; - RadioNameBinding.prototype = { - value: function () { - return this.node._ractive ? this.node._ractive.value : this.node.value; - }, - update: function () { - var node = this.node; - if (node.checked) { - this.attr.receiving = true; - this.root.set(this.keypath, this.value()); - this.attr.receiving = false; - } - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('click', updateModel, false); - } - }; - CheckboxNameBinding = function (attribute, node) { - var valueFromModel, checked; - this.checkboxName = true; - inheritProperties(this, attribute, node); - node.name = '{{' + this.keypath + '}}'; - node.addEventListener('change', updateModel, false); - if (node.attachEvent) { - node.addEventListener('click', updateModel, false); - } - valueFromModel = this.root.get(this.keypath); - if (valueFromModel !== undefined) { - checked = valueFromModel.indexOf(node._ractive.value) !== -1; - node.checked = checked; - } else { - if (this.root._deferred.checkboxes.indexOf(this.keypath) === -1) { - this.root._deferred.checkboxes.push(this.keypath); - } - } - }; - CheckboxNameBinding.prototype = { - changed: function () { - return this.node.checked !== !!this.checked; - }, - update: function () { - this.checked = this.node.checked; - this.attr.receiving = true; - this.root.set(this.keypath, getValueFromCheckboxes(this.root, this.keypath)); - this.attr.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('click', updateModel, false); - } - }; - CheckedBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - if (node.attachEvent) { - node.addEventListener('click', updateModel, false); - } - }; - CheckedBinding.prototype = { - value: function () { - return this.node.checked; - }, - update: function () { - this.attr.receiving = true; - this.root.set(this.keypath, this.value()); - this.attr.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('click', updateModel, false); - } - }; - FileListBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - }; - FileListBinding.prototype = { - value: function () { - return this.attr.pNode.files; - }, - update: function () { - this.attr.root.set(this.attr.keypath, this.value()); - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - } - }; - ContentEditableBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - if (!this.root.lazy) { - node.addEventListener('input', updateModel, false); - if (node.attachEvent) { - node.addEventListener('keyup', updateModel, false); - } - } - }; - ContentEditableBinding.prototype = { - update: function () { - this.attr.receiving = true; - this.root.set(this.keypath, this.node.innerHTML); - this.attr.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('input', updateModel, false); - this.node.removeEventListener('keyup', updateModel, false); - } - }; - GenericBinding = function (attribute, node) { - inheritProperties(this, attribute, node); - node.addEventListener('change', updateModel, false); - if (!this.root.lazy) { - node.addEventListener('input', updateModel, false); - if (node.attachEvent) { - node.addEventListener('keyup', updateModel, false); - } - } - this.node.addEventListener('blur', update, false); - }; - GenericBinding.prototype = { - value: function () { - var value = this.attr.pNode.value; - if (+value + '' === value && value.indexOf('e') === -1) { - value = +value; - } - return value; - }, - update: function () { - var attribute = this.attr, value = this.value(); - attribute.receiving = true; - attribute.root.set(attribute.keypath, value); - attribute.receiving = false; - }, - teardown: function () { - this.node.removeEventListener('change', updateModel, false); - this.node.removeEventListener('input', updateModel, false); - this.node.removeEventListener('keyup', updateModel, false); - this.node.removeEventListener('blur', update, false); - } - }; - inheritProperties = function (binding, attribute, node) { - binding.attr = attribute; - binding.node = node; - binding.root = attribute.root; - binding.keypath = attribute.keypath; - }; - return bindAttribute; - }(config_types, utils_warn, utils_arrayContentsMatch, shared_getValueFromCheckboxes); -var render_DomFragment_Attribute_prototype_update = function (isArray, namespaces) { - - var updateAttribute, updateFileInputValue, deferSelect, initSelect, updateSelect, updateMultipleSelect, updateRadioName, updateCheckboxName, updateIEStyleAttribute, updateClassName, updateContentEditableValue, updateEverythingElse; - updateAttribute = function () { - var node; - if (!this.ready) { - return this; - } - node = this.pNode; - if (node.tagName === 'SELECT' && this.lcName === 'value') { - this.update = deferSelect; - this.deferredUpdate = initSelect; - return this.update(); - } - if (this.isFileInputValue) { - this.update = updateFileInputValue; - return this; - } - if (this.twoway && this.lcName === 'name') { - if (node.type === 'radio') { - this.update = updateRadioName; - return this.update(); - } - if (node.type === 'checkbox') { - this.update = updateCheckboxName; - return this.update(); - } - } - if (this.lcName === 'style' && node.style.setAttribute) { - this.update = updateIEStyleAttribute; - return this.update(); - } - if (this.lcName === 'class' && (!node.namespaceURI || node.namespaceURI === namespaces.html)) { - this.update = updateClassName; - return this.update(); - } - if (node.getAttribute('contenteditable') && this.lcName === 'value') { - this.update = updateContentEditableValue; - return this.update(); - } - this.update = updateEverythingElse; - return this.update(); - }; - updateFileInputValue = function () { - return this; - }; - initSelect = function () { - this.deferredUpdate = this.pNode.multiple ? updateMultipleSelect : updateSelect; - this.deferredUpdate(); - }; - deferSelect = function () { - this.root._deferred.selectValues.push(this); - return this; - }; - updateSelect = function () { - var value = this.fragment.getValue(), options, option, i; - this.value = this.pNode._ractive.value = value; - options = this.pNode.options; - i = options.length; - while (i--) { - option = options[i]; - if (option._ractive.value == value) { - option.selected = true; - return this; - } - } - return this; - }; - updateMultipleSelect = function () { - var value = this.fragment.getValue(), options, i; - if (!isArray(value)) { - value = [value]; - } - options = this.pNode.options; - i = options.length; - while (i--) { - options[i].selected = value.indexOf(options[i]._ractive.value) !== -1; - } - this.value = value; - return this; - }; - updateRadioName = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - node.checked = value == node._ractive.value; - return this; - }; - updateCheckboxName = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (!isArray(value)) { - node.checked = value == node._ractive.value; - return this; - } - node.checked = value.indexOf(node._ractive.value) !== -1; - return this; - }; - updateIEStyleAttribute = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - node.style.setAttribute('cssText', value); - this.value = value; - } - return this; - }; - updateClassName = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - node.className = value; - this.value = value; - } - return this; - }; - updateContentEditableValue = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - if (!this.receiving) { - node.innerHTML = value; - } - this.value = value; - } - return this; - }; - updateEverythingElse = function () { - var node, value; - node = this.pNode; - value = this.fragment.getValue(); - if (this.isValueAttribute) { - node._ractive.value = value; - } - if (value === undefined) { - value = ''; - } - if (value !== this.value) { - if (this.useProperty) { - if (!this.receiving) { - node[this.propertyName] = value; - } - this.value = value; - return this; - } - if (this.namespace) { - node.setAttributeNS(this.namespace, this.name, value); - this.value = value; - return this; - } - if (this.lcName === 'id') { - if (this.value !== undefined) { - this.root.nodes[this.value] = undefined; - } - this.root.nodes[value] = node; - } - node.setAttribute(this.name, value); - this.value = value; - } - return this; - }; - return updateAttribute; - }(utils_isArray, config_namespaces); -var parse_Tokenizer_utils_getStringMatch = function () { - - return function (string) { - var substr; - substr = this.str.substr(this.pos, string.length); - if (substr === string) { - this.pos += string.length; - return string; - } - return null; - }; - }(); -var parse_Tokenizer_utils_allowWhitespace = function () { - - var leadingWhitespace = /^\s+/; - return function () { - var match = leadingWhitespace.exec(this.remaining()); - if (!match) { - return null; - } - this.pos += match[0].length; - return match[0]; - }; - }(); -var parse_Tokenizer_utils_makeRegexMatcher = function () { - - return function (regex) { - return function (tokenizer) { - var match = regex.exec(tokenizer.str.substring(tokenizer.pos)); - if (!match) { - return null; - } - tokenizer.pos += match[0].length; - return match[1] || match[0]; - }; - }; - }(); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getEscapedChars = function () { - - return function (tokenizer) { - var chars = '', character; - character = getEscapedChar(tokenizer); - while (character) { - chars += character; - character = getEscapedChar(tokenizer); - } - return chars || null; - }; - function getEscapedChar(tokenizer) { - var character; - if (!tokenizer.getStringMatch('\\')) { - return null; - } - character = tokenizer.str.charAt(tokenizer.pos); - tokenizer.pos += 1; - return character; - } - }(); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getQuotedString = function (makeRegexMatcher, getEscapedChars) { - - var getUnescapedDoubleQuotedChars = makeRegexMatcher(/^[^\\"]+/), getUnescapedSingleQuotedChars = makeRegexMatcher(/^[^\\']+/); - return function getQuotedString(tokenizer, singleQuotes) { - var start, string, escaped, unescaped, next, matcher; - start = tokenizer.pos; - string = ''; - matcher = singleQuotes ? getUnescapedSingleQuotedChars : getUnescapedDoubleQuotedChars; - escaped = getEscapedChars(tokenizer); - if (escaped) { - string += escaped; - } - unescaped = matcher(tokenizer); - if (unescaped) { - string += unescaped; - } - if (!string) { - return ''; - } - next = getQuotedString(tokenizer, singleQuotes); - while (next !== '') { - string += next; - } - return string; - }; - }(parse_Tokenizer_utils_makeRegexMatcher, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getEscapedChars); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral = function (types, getQuotedString) { - - return function (tokenizer) { - var start, string; - start = tokenizer.pos; - if (tokenizer.getStringMatch('"')) { - string = getQuotedString(tokenizer, false); - if (!tokenizer.getStringMatch('"')) { - tokenizer.pos = start; - return null; - } - return { - t: types.STRING_LITERAL, - v: string - }; - } - if (tokenizer.getStringMatch('\'')) { - string = getQuotedString(tokenizer, true); - if (!tokenizer.getStringMatch('\'')) { - tokenizer.pos = start; - return null; - } - return { - t: types.STRING_LITERAL, - v: string - }; - } - return null; - }; - }(config_types, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getQuotedString); -var parse_Tokenizer_getExpression_getPrimary_getLiteral_getNumberLiteral = function (types, makeRegexMatcher) { - - var getNumber = makeRegexMatcher(/^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/); - return function (tokenizer) { - var result; - if (result = getNumber(tokenizer)) { - return { - t: types.NUMBER_LITERAL, - v: result - }; - } - return null; - }; - }(config_types, parse_Tokenizer_utils_makeRegexMatcher); -var parse_Tokenizer_getExpression_shared_getName = function (makeRegexMatcher) { - - return makeRegexMatcher(/^[a-zA-Z_$][a-zA-Z_$0-9]*/); - }(parse_Tokenizer_utils_makeRegexMatcher); -var parse_Tokenizer_getExpression_shared_getKey = function (getStringLiteral, getNumberLiteral, getName) { - - var identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/; - return function (tokenizer) { - var token; - if (token = getStringLiteral(tokenizer)) { - return identifier.test(token.v) ? token.v : '"' + token.v.replace(/"/g, '\\"') + '"'; - } - if (token = getNumberLiteral(tokenizer)) { - return token.v; - } - if (token = getName(tokenizer)) { - return token; - } - }; - }(parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getNumberLiteral, parse_Tokenizer_getExpression_shared_getName); -var utils_parseJSON = function (getStringMatch, allowWhitespace, getStringLiteral, getKey) { - - var Tokenizer, specials, specialsPattern, numberPattern, placeholderPattern, placeholderAtStartPattern; - specials = { - 'true': true, - 'false': false, - 'undefined': undefined, - 'null': null - }; - specialsPattern = new RegExp('^(?:' + Object.keys(specials).join('|') + ')'); - numberPattern = /^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/; - placeholderPattern = /\$\{([^\}]+)\}/g; - placeholderAtStartPattern = /^\$\{([^\}]+)\}/; - Tokenizer = function (str, values) { - this.str = str; - this.values = values; - this.pos = 0; - this.result = this.getToken(); - }; - Tokenizer.prototype = { - remaining: function () { - return this.str.substring(this.pos); - }, - getStringMatch: getStringMatch, - getToken: function () { - this.allowWhitespace(); - return this.getPlaceholder() || this.getSpecial() || this.getNumber() || this.getString() || this.getObject() || this.getArray(); - }, - getPlaceholder: function () { - var match; - if (!this.values) { - return null; - } - if ((match = placeholderAtStartPattern.exec(this.remaining())) && this.values.hasOwnProperty(match[1])) { - this.pos += match[0].length; - return { v: this.values[match[1]] }; - } - }, - getSpecial: function () { - var match; - if (match = specialsPattern.exec(this.remaining())) { - this.pos += match[0].length; - return { v: specials[match[0]] }; - } - }, - getNumber: function () { - var match; - if (match = numberPattern.exec(this.remaining())) { - this.pos += match[0].length; - return { v: +match[0] }; - } - }, - getString: function () { - var stringLiteral = getStringLiteral(this), values; - if (stringLiteral && (values = this.values)) { - return { - v: stringLiteral.v.replace(placeholderPattern, function (match, $1) { - return values[$1] || $1; - }) - }; - } - return stringLiteral; - }, - getObject: function () { - var result, pair; - if (!this.getStringMatch('{')) { - return null; - } - result = {}; - while (pair = getKeyValuePair(this)) { - result[pair.key] = pair.value; - this.allowWhitespace(); - if (this.getStringMatch('}')) { - return { v: result }; - } - if (!this.getStringMatch(',')) { - return null; - } - } - return null; - }, - getArray: function () { - var result, valueToken; - if (!this.getStringMatch('[')) { - return null; - } - result = []; - while (valueToken = this.getToken()) { - result.push(valueToken.v); - if (this.getStringMatch(']')) { - return { v: result }; - } - if (!this.getStringMatch(',')) { - return null; - } - } - return null; - }, - allowWhitespace: allowWhitespace - }; - function getKeyValuePair(tokenizer) { - var key, valueToken, pair; - tokenizer.allowWhitespace(); - key = getKey(tokenizer); - if (!key) { - return null; - } - pair = { key: key }; - tokenizer.allowWhitespace(); - if (!tokenizer.getStringMatch(':')) { - return null; - } - tokenizer.allowWhitespace(); - valueToken = tokenizer.getToken(); - if (!valueToken) { - return null; - } - pair.value = valueToken.v; - return pair; - } - return function (str, values) { - var tokenizer = new Tokenizer(str, values); - if (tokenizer.result) { - return { - value: tokenizer.result.v, - remaining: tokenizer.remaining() - }; - } - return null; - }; - }(parse_Tokenizer_utils_getStringMatch, parse_Tokenizer_utils_allowWhitespace, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral, parse_Tokenizer_getExpression_shared_getKey); -var render_StringFragment_Interpolator = function (types, teardown, initMustache, updateMustache, resolveMustache) { - - var StringInterpolator = function (options) { - this.type = types.INTERPOLATOR; - initMustache(this, options); - }; - StringInterpolator.prototype = { - update: updateMustache, - resolve: resolveMustache, - render: function (value) { - this.value = value; - this.parentFragment.bubble(); - }, - teardown: function () { - teardown(this); - }, - toString: function () { - if (this.value == undefined) { - return ''; - } - return stringify(this.value); - } - }; - return StringInterpolator; - function stringify(value) { - if (typeof value === 'string') { - return value; - } - return JSON.stringify(value); - } - }(config_types, shared_teardown, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache); -var render_StringFragment_Section = function (types, initMustache, updateMustache, resolveMustache, updateSection, teardown, circular) { - - var StringSection, StringFragment; - circular.push(function () { - StringFragment = circular.StringFragment; - }); - StringSection = function (options) { - this.type = types.SECTION; - this.fragments = []; - this.length = 0; - initMustache(this, options); - }; - StringSection.prototype = { - update: updateMustache, - resolve: resolveMustache, - teardown: function () { - this.teardownFragments(); - teardown(this); - }, - teardownFragments: function () { - while (this.fragments.length) { - this.fragments.shift().teardown(); - } - this.length = 0; - }, - bubble: function () { - this.value = this.fragments.join(''); - this.parentFragment.bubble(); - }, - render: function (value) { - var wrapped; - if (wrapped = this.root._wrapped[this.keypath]) { - value = wrapped.get(); - } - updateSection(this, value); - this.parentFragment.bubble(); - }, - createFragment: function (options) { - return new StringFragment(options); - }, - toString: function () { - return this.fragments.join(''); - } - }; - return StringSection; - }(config_types, render_shared_initMustache, render_shared_updateMustache, render_shared_resolveMustache, render_shared_updateSection, shared_teardown, circular); -var render_StringFragment_Text = function (types) { - - var StringText = function (text) { - this.type = types.TEXT; - this.text = text; - }; - StringText.prototype = { - toString: function () { - return this.text; - }, - teardown: function () { - } - }; - return StringText; - }(config_types); -var render_StringFragment_prototype_toArgsList = function (warn, parseJSON) { - - return function () { - var values, counter, jsonesque, guid, errorMessage, parsed, processItems; - if (!this.argsList || this.dirty) { - values = {}; - counter = 0; - guid = this.root._guid; - processItems = function (items) { - return items.map(function (item) { - var placeholderId, wrapped, value; - if (item.text) { - return item.text; - } - if (item.fragments) { - return item.fragments.map(function (fragment) { - return processItems(fragment.items); - }).join(''); - } - placeholderId = guid + '-' + counter++; - if (wrapped = item.root._wrapped[item.keypath]) { - value = wrapped.value; - } else { - value = item.value; - } - values[placeholderId] = value; - return '${' + placeholderId + '}'; - }).join(''); - }; - jsonesque = processItems(this.items); - parsed = parseJSON('[' + jsonesque + ']', values); - if (!parsed) { - errorMessage = 'Could not parse directive arguments (' + this.toString() + '). If you think this is a bug, please file an issue at http://github.com/RactiveJS/Ractive/issues'; - if (this.root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - this.argsList = [jsonesque]; - } - } else { - this.argsList = parsed.value; - } - this.dirty = false; - } - return this.argsList; - }; - }(utils_warn, utils_parseJSON); -var render_StringFragment__StringFragment = function (types, parseJSON, initFragment, Interpolator, Section, Text, toArgsList, circular) { - - var StringFragment = function (options) { - initFragment(this, options); - }; - StringFragment.prototype = { - createItem: function (options) { - if (typeof options.descriptor === 'string') { - return new Text(options.descriptor); - } - switch (options.descriptor.t) { - case types.INTERPOLATOR: - return new Interpolator(options); - case types.TRIPLE: - return new Interpolator(options); - case types.SECTION: - return new Section(options); - default: - throw 'Something went wrong in a rather interesting way'; - } - }, - bubble: function () { - this.dirty = true; - this.owner.bubble(); - }, - teardown: function () { - var numItems, i; - numItems = this.items.length; - for (i = 0; i < numItems; i += 1) { - this.items[i].teardown(); - } - }, - getValue: function () { - var value; - if (this.items.length === 1 && this.items[0].type === types.INTERPOLATOR) { - value = this.items[0].value; - if (value !== undefined) { - return value; - } - } - return this.toString(); - }, - isSimple: function () { - var i, item, containsInterpolator; - if (this.simple !== undefined) { - return this.simple; - } - i = this.items.length; - while (i--) { - item = this.items[i]; - if (item.type === types.TEXT) { - continue; - } - if (item.type === types.INTERPOLATOR) { - if (containsInterpolator) { - return false; - } else { - containsInterpolator = true; - continue; - } - } - return this.simple = false; - } - return this.simple = true; - }, - toString: function () { - return this.items.join(''); - }, - toJSON: function () { - var value = this.getValue(), parsed; - if (typeof value === 'string') { - parsed = parseJSON(value); - value = parsed ? parsed.value : value; - } - return value; - }, - toArgsList: toArgsList - }; - circular.StringFragment = StringFragment; - return StringFragment; - }(config_types, utils_parseJSON, render_shared_initFragment, render_StringFragment_Interpolator, render_StringFragment_Section, render_StringFragment_Text, render_StringFragment_prototype_toArgsList, circular); -var render_DomFragment_Attribute__Attribute = function (types, determineNameAndNamespace, setStaticAttribute, determinePropertyName, bind, update, StringFragment) { - - var DomAttribute = function (options) { - this.type = types.ATTRIBUTE; - this.element = options.element; - determineNameAndNamespace(this, options.name); - if (options.value === null || typeof options.value === 'string') { - setStaticAttribute(this, options); - return; - } - this.root = options.root; - this.pNode = options.pNode; - this.parentFragment = this.element.parentFragment; - this.fragment = new StringFragment({ - descriptor: options.value, - root: this.root, - owner: this, - contextStack: options.contextStack - }); - if (!this.pNode) { - return; - } - if (this.name === 'value') { - this.isValueAttribute = true; - if (this.pNode.tagName === 'INPUT' && this.pNode.type === 'file') { - this.isFileInputValue = true; - } - } - determinePropertyName(this, options); - this.selfUpdating = this.fragment.isSimple(); - this.ready = true; - }; - DomAttribute.prototype = { - bind: bind, - update: update, - updateBindings: function () { - this.keypath = this.interpolator.keypath || this.interpolator.ref; - if (this.propertyName === 'name') { - this.pNode.name = '{{' + this.keypath + '}}'; - } - }, - teardown: function () { - var i; - if (this.boundEvents) { - i = this.boundEvents.length; - while (i--) { - this.pNode.removeEventListener(this.boundEvents[i], this.updateModel, false); - } - } - if (this.fragment) { - this.fragment.teardown(); - } - }, - bubble: function () { - if (this.selfUpdating) { - this.update(); - } else if (!this.deferred && this.ready) { - this.root._deferred.attrs.push(this); - this.deferred = true; - } - }, - toString: function () { - var str; - if (this.value === null) { - return this.name; - } - if (!this.fragment) { - return this.name + '=' + JSON.stringify(this.value); - } - str = this.fragment.toString(); - return this.name + '=' + JSON.stringify(str); - } - }; - return DomAttribute; - }(config_types, render_DomFragment_Attribute_helpers_determineNameAndNamespace, render_DomFragment_Attribute_helpers_setStaticAttribute, render_DomFragment_Attribute_helpers_determinePropertyName, render_DomFragment_Attribute_prototype_bind, render_DomFragment_Attribute_prototype_update, render_StringFragment__StringFragment); -var render_DomFragment_Element_initialise_createElementAttributes = function (DomAttribute) { - - return function (element, attributes) { - var attrName, attrValue, attr; - element.attributes = []; - for (attrName in attributes) { - if (attributes.hasOwnProperty(attrName)) { - attrValue = attributes[attrName]; - attr = new DomAttribute({ - element: element, - name: attrName, - value: attrValue, - root: element.root, - pNode: element.node, - contextStack: element.parentFragment.contextStack - }); - element.attributes[element.attributes.length] = element.attributes[attrName] = attr; - if (attrName !== 'name') { - attr.update(); - } - } - } - return element.attributes; - }; - }(render_DomFragment_Attribute__Attribute); -var render_DomFragment_Element_initialise_appendElementChildren = function (warn, namespaces, StringFragment, circular) { - - var DomFragment, updateCss, updateScript; - circular.push(function () { - DomFragment = circular.DomFragment; - }); - updateCss = function () { - var node = this.node, content = this.fragment.toString(); - if (node.styleSheet) { - node.styleSheet.cssText = content; - } - node.innerHTML = content; - }; - updateScript = function () { - if (!this.node.type || this.node.type === 'text/javascript') { - warn('Script tag was updated. This does not cause the code to be re-evaluated!'); - } - this.node.innerHTML = this.fragment.toString(); - }; - return function (element, node, descriptor, docFrag) { - var liveQueries, i, selector, queryAllResult, j; - if (element.lcName === 'script' || element.lcName === 'style') { - element.fragment = new StringFragment({ - descriptor: descriptor.f, - root: element.root, - contextStack: element.parentFragment.contextStack, - owner: element - }); - if (docFrag) { - if (element.lcName === 'script') { - element.bubble = updateScript; - element.node.innerHTML = element.fragment.toString(); - } else { - element.bubble = updateCss; - element.bubble(); - } - } - return; - } - if (typeof descriptor.f === 'string' && (!node || (!node.namespaceURI || node.namespaceURI === namespaces.html))) { - element.html = descriptor.f; - if (docFrag) { - node.innerHTML = element.html; - liveQueries = element.root._liveQueries; - i = liveQueries.length; - while (i--) { - selector = liveQueries[i]; - if ((queryAllResult = node.querySelectorAll(selector)) && (j = queryAllResult.length)) { - (element.liveQueries || (element.liveQueries = [])).push(selector); - element.liveQueries[selector] = []; - while (j--) { - element.liveQueries[selector][j] = queryAllResult[j]; - } - } - } - } - } else { - element.fragment = new DomFragment({ - descriptor: descriptor.f, - root: element.root, - pNode: node, - contextStack: element.parentFragment.contextStack, - owner: element - }); - if (docFrag) { - node.appendChild(element.fragment.docFrag); - } - } - }; - }(utils_warn, config_namespaces, render_StringFragment__StringFragment, circular); -var render_DomFragment_Element_initialise_decorate_Decorator = function (warn, StringFragment) { - - var Decorator = function (descriptor, root, owner, contextStack) { - var name, fragment, errorMessage; - this.root = root; - this.node = owner.node; - name = descriptor.n || descriptor; - if (typeof name !== 'string') { - fragment = new StringFragment({ - descriptor: name, - root: this.root, - owner: owner, - contextStack: contextStack - }); - name = fragment.toString(); - fragment.teardown(); - } - if (descriptor.a) { - this.params = descriptor.a; - } else if (descriptor.d) { - fragment = new StringFragment({ - descriptor: descriptor.d, - root: this.root, - owner: owner, - contextStack: contextStack - }); - this.params = fragment.toArgsList(); - fragment.teardown(); - } - this.fn = root.decorators[name]; - if (!this.fn) { - errorMessage = 'Missing "' + name + '" decorator. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#decorators'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - } - }; - Decorator.prototype = { - init: function () { - var result, args; - if (this.params) { - args = [this.node].concat(this.params); - result = this.fn.apply(this.root, args); - } else { - result = this.fn.call(this.root, this.node); - } - if (!result || !result.teardown) { - throw new Error('Decorator definition must return an object with a teardown method'); - } - this.teardown = result.teardown; - } - }; - return Decorator; - }(utils_warn, render_StringFragment__StringFragment); -var render_DomFragment_Element_initialise_decorate__decorate = function (Decorator) { - - return function (descriptor, root, owner, contextStack) { - owner.decorator = new Decorator(descriptor, root, owner, contextStack); - if (owner.decorator.fn) { - root._deferred.decorators.push(owner.decorator); - } - }; - }(render_DomFragment_Element_initialise_decorate_Decorator); -var render_DomFragment_Element_initialise_addEventProxies_addEventProxy = function (warn, StringFragment) { - - var addEventProxy, MasterEventHandler, ProxyEvent, firePlainEvent, fireEventWithArgs, fireEventWithDynamicArgs, customHandlers, genericHandler, getCustomHandler; - addEventProxy = function (element, triggerEventName, proxyDescriptor, contextStack, indexRefs) { - var events, master; - events = element.node._ractive.events; - master = events[triggerEventName] || (events[triggerEventName] = new MasterEventHandler(element, triggerEventName, contextStack, indexRefs)); - master.add(proxyDescriptor); - }; - MasterEventHandler = function (element, eventName, contextStack) { - var definition; - this.element = element; - this.root = element.root; - this.node = element.node; - this.name = eventName; - this.contextStack = contextStack; - this.proxies = []; - if (definition = this.root.events[eventName]) { - this.custom = definition(this.node, getCustomHandler(eventName)); - } else { - if (!('on' + eventName in this.node)) { - warn('Missing "' + this.name + '" event. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#events'); - } - this.node.addEventListener(eventName, genericHandler, false); - } - }; - MasterEventHandler.prototype = { - add: function (proxy) { - this.proxies[this.proxies.length] = new ProxyEvent(this.element, this.root, proxy, this.contextStack); - }, - teardown: function () { - var i; - if (this.custom) { - this.custom.teardown(); - } else { - this.node.removeEventListener(this.name, genericHandler, false); - } - i = this.proxies.length; - while (i--) { - this.proxies[i].teardown(); - } - }, - fire: function (event) { - var i = this.proxies.length; - while (i--) { - this.proxies[i].fire(event); - } - } - }; - ProxyEvent = function (element, ractive, descriptor, contextStack) { - var name; - this.root = ractive; - name = descriptor.n || descriptor; - if (typeof name === 'string') { - this.n = name; - } else { - this.n = new StringFragment({ - descriptor: descriptor.n, - root: this.root, - owner: element, - contextStack: contextStack - }); - } - if (descriptor.a) { - this.a = descriptor.a; - this.fire = fireEventWithArgs; - return; - } - if (descriptor.d) { - this.d = new StringFragment({ - descriptor: descriptor.d, - root: this.root, - owner: element, - contextStack: contextStack - }); - this.fire = fireEventWithDynamicArgs; - return; - } - this.fire = firePlainEvent; - }; - ProxyEvent.prototype = { - teardown: function () { - if (this.n.teardown) { - this.n.teardown(); - } - if (this.d) { - this.d.teardown(); - } - }, - bubble: function () { - } - }; - firePlainEvent = function (event) { - this.root.fire(this.n.toString(), event); - }; - fireEventWithArgs = function (event) { - this.root.fire.apply(this.root, [ - this.n.toString(), - event - ].concat(this.a)); - }; - fireEventWithDynamicArgs = function (event) { - var args = this.d.toArgsList(); - if (typeof args === 'string') { - args = args.substr(1, args.length - 2); - } - this.root.fire.apply(this.root, [ - this.n.toString(), - event - ].concat(args)); - }; - genericHandler = function (event) { - var storage = this._ractive; - storage.events[event.type].fire({ - node: this, - original: event, - index: storage.index, - keypath: storage.keypath, - context: storage.root.get(storage.keypath) - }); - }; - customHandlers = {}; - getCustomHandler = function (eventName) { - if (customHandlers[eventName]) { - return customHandlers[eventName]; - } - return customHandlers[eventName] = function (event) { - var storage = event.node._ractive; - event.index = storage.index; - event.keypath = storage.keypath; - event.context = storage.root.get(storage.keypath); - storage.events[eventName].fire(event); - }; - }; - return addEventProxy; - }(utils_warn, render_StringFragment__StringFragment); -var render_DomFragment_Element_initialise_addEventProxies__addEventProxies = function (addEventProxy) { - - return function (element, proxies) { - var i, eventName, eventNames; - for (eventName in proxies) { - if (proxies.hasOwnProperty(eventName)) { - eventNames = eventName.split('-'); - i = eventNames.length; - while (i--) { - addEventProxy(element, eventNames[i], proxies[eventName], element.parentFragment.contextStack); - } - } - } - }; - }(render_DomFragment_Element_initialise_addEventProxies_addEventProxy); -var render_DomFragment_Element_initialise_updateLiveQueries = function () { - - return function (element) { - var ractive, liveQueries, i, selector, query; - ractive = element.root; - liveQueries = ractive._liveQueries; - i = liveQueries.length; - while (i--) { - selector = liveQueries[i]; - query = liveQueries[selector]; - if (query._test(element)) { - (element.liveQueries || (element.liveQueries = [])).push(selector); - element.liveQueries[selector] = [element.node]; - } - } - }; - }(); -var utils_camelCase = function () { - - return function (hyphenatedStr) { - return hyphenatedStr.replace(/-([a-zA-Z])/g, function (match, $1) { - return $1.toUpperCase(); - }); - }; - }(); -var utils_fillGaps = function () { - - return function (target, source) { - var key; - for (key in source) { - if (source.hasOwnProperty(key) && !target.hasOwnProperty(key)) { - target[key] = source[key]; - } - } - return target; - }; - }(); -var render_DomFragment_Element_shared_executeTransition_Transition = function (isClient, createElement, warn, isNumeric, isArray, camelCase, fillGaps, StringFragment) { - - var Transition, testStyle, vendors, vendorPattern, unprefixPattern, prefixCache, CSS_TRANSITIONS_ENABLED, TRANSITION, TRANSITION_DURATION, TRANSITION_PROPERTY, TRANSITION_TIMING_FUNCTION, TRANSITIONEND; - if (!isClient) { - return; - } - testStyle = createElement('div').style; - (function () { - if (testStyle.transition !== undefined) { - TRANSITION = 'transition'; - TRANSITIONEND = 'transitionend'; - CSS_TRANSITIONS_ENABLED = true; - } else if (testStyle.webkitTransition !== undefined) { - TRANSITION = 'webkitTransition'; - TRANSITIONEND = 'webkitTransitionEnd'; - CSS_TRANSITIONS_ENABLED = true; - } else { - CSS_TRANSITIONS_ENABLED = false; - } - }()); - if (TRANSITION) { - TRANSITION_DURATION = TRANSITION + 'Duration'; - TRANSITION_PROPERTY = TRANSITION + 'Property'; - TRANSITION_TIMING_FUNCTION = TRANSITION + 'TimingFunction'; - } - Transition = function (descriptor, root, owner, contextStack, isIntro) { - var t = this, name, fragment, errorMessage; - this.root = root; - this.node = owner.node; - this.isIntro = isIntro; - this.originalStyle = this.node.getAttribute('style'); - this.complete = function (noReset) { - if (!noReset && t.isIntro) { - t.resetStyle(); - } - t._manager.pop(t.node); - t.node._ractive.transition = null; - }; - name = descriptor.n || descriptor; - if (typeof name !== 'string') { - fragment = new StringFragment({ - descriptor: name, - root: this.root, - owner: owner, - contextStack: contextStack - }); - name = fragment.toString(); - fragment.teardown(); - } - this.name = name; - if (descriptor.a) { - this.params = descriptor.a; - } else if (descriptor.d) { - fragment = new StringFragment({ - descriptor: descriptor.d, - root: this.root, - owner: owner, - contextStack: contextStack - }); - this.params = fragment.toArgsList(); - fragment.teardown(); - } - this._fn = root.transitions[name]; - if (!this._fn) { - errorMessage = 'Missing "' + name + '" transition. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#transitions'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - return; - } - }; - Transition.prototype = { - init: function () { - if (this._inited) { - throw new Error('Cannot initialize a transition more than once'); - } - this._inited = true; - this._fn.apply(this.root, [this].concat(this.params)); - }, - getStyle: function (props) { - var computedStyle, styles, i, prop, value; - computedStyle = window.getComputedStyle(this.node); - if (typeof props === 'string') { - value = computedStyle[prefix(props)]; - if (value === '0px') { - value = 0; - } - return value; - } - if (!isArray(props)) { - throw new Error('Transition#getStyle must be passed a string, or an array of strings representing CSS properties'); - } - styles = {}; - i = props.length; - while (i--) { - prop = props[i]; - value = computedStyle[prefix(prop)]; - if (value === '0px') { - value = 0; - } - styles[prop] = value; - } - return styles; - }, - setStyle: function (style, value) { - var prop; - if (typeof style === 'string') { - this.node.style[prefix(style)] = value; - } else { - for (prop in style) { - if (style.hasOwnProperty(prop)) { - this.node.style[prefix(prop)] = style[prop]; - } - } - } - return this; - }, - animateStyle: function (style, value, options, complete) { - var t = this, propertyNames, changedProperties, computedStyle, current, to, from, transitionEndHandler, i, prop; - if (typeof style === 'string') { - to = {}; - to[style] = value; - } else { - to = style; - complete = options; - options = value; - } - if (!options) { - warn('The "' + t.name + '" transition does not supply an options object to `t.animateStyle()`. This will break in a future version of Ractive. For more info see https://github.com/RactiveJS/Ractive/issues/340'); - options = t; - complete = t.complete; - } - if (!options.duration) { - t.setStyle(to); - if (complete) { - complete(); - } - } - propertyNames = Object.keys(to); - changedProperties = []; - computedStyle = window.getComputedStyle(t.node); - from = {}; - i = propertyNames.length; - while (i--) { - prop = propertyNames[i]; - current = computedStyle[prefix(prop)]; - if (current === '0px') { - current = 0; - } - if (current != to[prop]) { - changedProperties[changedProperties.length] = prop; - t.node.style[prefix(prop)] = current; - } - } - if (!changedProperties.length) { - if (complete) { - complete(); - } - return; - } - setTimeout(function () { - t.node.style[TRANSITION_PROPERTY] = propertyNames.map(prefix).map(hyphenate).join(','); - t.node.style[TRANSITION_TIMING_FUNCTION] = hyphenate(options.easing || 'linear'); - t.node.style[TRANSITION_DURATION] = options.duration / 1000 + 's'; - transitionEndHandler = function (event) { - var index; - index = changedProperties.indexOf(camelCase(unprefix(event.propertyName))); - if (index !== -1) { - changedProperties.splice(index, 1); - } - if (changedProperties.length) { - return; - } - t.root.fire(t.name + ':end'); - t.node.removeEventListener(TRANSITIONEND, transitionEndHandler, false); - if (complete) { - complete(); - } - }; - t.node.addEventListener(TRANSITIONEND, transitionEndHandler, false); - setTimeout(function () { - var i = changedProperties.length; - while (i--) { - prop = changedProperties[i]; - t.node.style[prefix(prop)] = to[prop]; - } - }, 0); - }, options.delay || 0); - }, - resetStyle: function () { - if (this.originalStyle) { - this.node.setAttribute('style', this.originalStyle); - } else { - this.node.getAttribute('style'); - this.node.removeAttribute('style'); - } - }, - processParams: function (params, defaults) { - if (typeof params === 'number') { - params = { duration: params }; - } else if (typeof params === 'string') { - if (params === 'slow') { - params = { duration: 600 }; - } else if (params === 'fast') { - params = { duration: 200 }; - } else { - params = { duration: 400 }; - } - } else if (!params) { - params = {}; - } - return fillGaps(params, defaults); - } - }; - vendors = [ - 'o', - 'ms', - 'moz', - 'webkit' - ]; - vendorPattern = new RegExp('^(?:' + vendors.join('|') + ')([A-Z])'); - unprefixPattern = new RegExp('^-(?:' + vendors.join('|') + ')-'); - prefixCache = {}; - function prefix(prop) { - var i, vendor, capped; - if (!prefixCache[prop]) { - if (testStyle[prop] !== undefined) { - prefixCache[prop] = prop; - } else { - capped = prop.charAt(0).toUpperCase() + prop.substring(1); - i = vendors.length; - while (i--) { - vendor = vendors[i]; - if (testStyle[vendor + capped] !== undefined) { - prefixCache[prop] = vendor + capped; - break; - } - } - } - } - return prefixCache[prop]; - } - function unprefix(prop) { - return prop.replace(unprefixPattern, ''); - } - function hyphenate(str) { - var hyphenated; - if (vendorPattern.test(str)) { - str = '-' + str; - } - hyphenated = str.replace(/[A-Z]/g, function (match) { - return '-' + match.toLowerCase(); - }); - return hyphenated; - } - return Transition; - }(config_isClient, utils_createElement, utils_warn, utils_isNumeric, utils_isArray, utils_camelCase, utils_fillGaps, render_StringFragment__StringFragment); -var render_DomFragment_Element_shared_executeTransition__executeTransition = function (warn, Transition) { - - return function (descriptor, root, owner, contextStack, isIntro) { - var transition, node, oldTransition; - if (!root.transitionsEnabled || root._parent && !root._parent.transitionsEnabled) { - return; - } - transition = new Transition(descriptor, root, owner, contextStack, isIntro); - if (transition._fn) { - node = transition.node; - transition._manager = root._transitionManager; - if (oldTransition = node._ractive.transition) { - oldTransition.complete(); - } - node._ractive.transition = transition; - transition._manager.push(node); - if (isIntro) { - root._deferred.transitions.push(transition); - } else { - transition.init(); - } - } - }; - }(utils_warn, render_DomFragment_Element_shared_executeTransition_Transition); -var render_DomFragment_Element_initialise__initialise = function (types, namespaces, create, defineProperty, matches, warn, createElement, getElementNamespace, createElementAttributes, appendElementChildren, decorate, addEventProxies, updateLiveQueries, executeTransition, enforceCase) { - - return function (element, options, docFrag) { - var parentFragment, pNode, contextStack, descriptor, namespace, name, attributes, width, height, loadHandler, root, selectBinding, errorMessage; - element.type = types.ELEMENT; - parentFragment = element.parentFragment = options.parentFragment; - pNode = parentFragment.pNode; - contextStack = parentFragment.contextStack; - descriptor = element.descriptor = options.descriptor; - element.root = root = parentFragment.root; - element.index = options.index; - element.lcName = descriptor.e.toLowerCase(); - element.eventListeners = []; - element.customEventListeners = []; - if (pNode) { - namespace = element.namespace = getElementNamespace(descriptor, pNode); - name = namespace !== namespaces.html ? enforceCase(descriptor.e) : descriptor.e; - element.node = createElement(name, namespace); - defineProperty(element.node, '_ractive', { - value: { - proxy: element, - keypath: contextStack.length ? contextStack[contextStack.length - 1] : '', - index: parentFragment.indexRefs, - events: create(null), - root: root - } - }); - } - attributes = createElementAttributes(element, descriptor.a); - if (descriptor.f) { - if (element.node && element.node.getAttribute('contenteditable')) { - if (element.node.innerHTML) { - errorMessage = 'A pre-populated contenteditable element should not have children'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - } - } - appendElementChildren(element, element.node, descriptor, docFrag); - } - if (docFrag && descriptor.v) { - addEventProxies(element, descriptor.v); - } - if (docFrag) { - if (root.twoway) { - element.bind(); - if (element.node.getAttribute('contenteditable') && element.node._ractive.binding) { - element.node._ractive.binding.update(); - } - } - if (attributes.name && !attributes.name.twoway) { - attributes.name.update(); - } - if (element.node.tagName === 'IMG' && ((width = element.attributes.width) || (height = element.attributes.height))) { - element.node.addEventListener('load', loadHandler = function () { - if (width) { - element.node.width = width.value; - } - if (height) { - element.node.height = height.value; - } - element.node.removeEventListener('load', loadHandler, false); - }, false); - } - docFrag.appendChild(element.node); - if (descriptor.o) { - decorate(descriptor.o, root, element, contextStack); - } - if (descriptor.t1) { - executeTransition(descriptor.t1, root, element, contextStack, true); - } - if (element.node.tagName === 'OPTION') { - if (pNode.tagName === 'SELECT' && (selectBinding = pNode._ractive.binding)) { - selectBinding.deferUpdate(); - } - if (element.node._ractive.value == pNode._ractive.value) { - element.node.selected = true; - } - } - if (element.node.autofocus) { - root._deferred.focusable = element.node; - } - } - updateLiveQueries(element); - }; - }(config_types, config_namespaces, utils_create, utils_defineProperty, utils_matches, utils_warn, utils_createElement, render_DomFragment_Element_initialise_getElementNamespace, render_DomFragment_Element_initialise_createElementAttributes, render_DomFragment_Element_initialise_appendElementChildren, render_DomFragment_Element_initialise_decorate__decorate, render_DomFragment_Element_initialise_addEventProxies__addEventProxies, render_DomFragment_Element_initialise_updateLiveQueries, render_DomFragment_Element_shared_executeTransition__executeTransition, render_DomFragment_shared_enforceCase); -var render_DomFragment_Element_prototype_teardown = function (executeTransition) { - - return function (destroy) { - var eventName, binding, bindings, i, liveQueries, selector, query, nodesToRemove, j; - if (this.fragment) { - this.fragment.teardown(false); - } - while (this.attributes.length) { - this.attributes.pop().teardown(); - } - if (this.node) { - for (eventName in this.node._ractive.events) { - this.node._ractive.events[eventName].teardown(); - } - if (binding = this.node._ractive.binding) { - binding.teardown(); - bindings = this.root._twowayBindings[binding.attr.keypath]; - bindings.splice(bindings.indexOf(binding), 1); - } - } - if (this.decorator) { - this.decorator.teardown(); - } - if (this.descriptor.t2) { - executeTransition(this.descriptor.t2, this.root, this, this.parentFragment.contextStack, false); - } - if (destroy) { - this.root._transitionManager.detachWhenReady(this); - } - if (liveQueries = this.liveQueries) { - i = liveQueries.length; - while (i--) { - selector = liveQueries[i]; - if (nodesToRemove = this.liveQueries[selector]) { - j = nodesToRemove.length; - query = this.root._liveQueries[selector]; - while (j--) { - query._remove(nodesToRemove[j]); - } - } - } - } - }; - }(render_DomFragment_Element_shared_executeTransition__executeTransition); -var config_voidElementNames = function () { - - return 'area base br col command doctype embed hr img input keygen link meta param source track wbr'.split(' '); - }(); -var render_DomFragment_Element_prototype_toString = function (voidElementNames) { - - return function () { - var str, i, len; - str = '<' + (this.descriptor.y ? '!doctype' : this.descriptor.e); - len = this.attributes.length; - for (i = 0; i < len; i += 1) { - str += ' ' + this.attributes[i].toString(); - } - str += '>'; - if (this.html) { - str += this.html; - } else if (this.fragment) { - str += this.fragment.toString(); - } - if (voidElementNames.indexOf(this.descriptor.e) === -1) { - str += '' + this.descriptor.e + '>'; - } - return str; - }; - }(config_voidElementNames); -var render_DomFragment_Element_prototype_find = function (matches) { - - return function (selector) { - var queryResult; - if (matches(this.node, selector)) { - return this.node; - } - if (this.html && (queryResult = this.node.querySelector(selector))) { - return queryResult; - } - if (this.fragment && this.fragment.find) { - return this.fragment.find(selector); - } - }; - }(utils_matches); -var render_DomFragment_Element_prototype_findAll = function () { - - return function (selector, query) { - var queryAllResult, i, numNodes, node, registeredNodes; - if (query._test(this, true) && query.live) { - (this.liveQueries || (this.liveQueries = [])).push(selector); - this.liveQueries[selector] = [this.node]; - } - if (this.html && (queryAllResult = this.node.querySelectorAll(selector)) && (numNodes = queryAllResult.length)) { - if (query.live) { - if (!this.liveQueries[selector]) { - (this.liveQueries || (this.liveQueries = [])).push(selector); - this.liveQueries[selector] = []; - } - registeredNodes = this.liveQueries[selector]; - } - for (i = 0; i < numNodes; i += 1) { - node = queryAllResult[i]; - query.push(node); - if (query.live) { - registeredNodes.push(node); - } - } - } - if (this.fragment) { - this.fragment.findAll(selector, query); - } - }; - }(); -var render_DomFragment_Element_prototype_findComponent = function () { - - return function (selector) { - if (this.fragment) { - return this.fragment.findComponent(selector); - } - }; - }(); -var render_DomFragment_Element_prototype_findAllComponents = function () { - - return function (selector, query) { - if (this.fragment) { - this.fragment.findAllComponents(selector, query); - } - }; - }(); -var render_DomFragment_Element_prototype_bind = function () { - - return function () { - var attributes = this.attributes; - if (!this.node) { - return; - } - if (this.binding) { - this.binding.teardown(); - this.binding = null; - } - if (this.node.getAttribute('contenteditable') && attributes.value && attributes.value.bind()) { - return; - } - switch (this.descriptor.e) { - case 'select': - case 'textarea': - if (attributes.value) { - attributes.value.bind(); - } - return; - case 'input': - if (this.node.type === 'radio' || this.node.type === 'checkbox') { - if (attributes.name && attributes.name.bind()) { - return; - } - if (attributes.checked && attributes.checked.bind()) { - return; - } - } - if (attributes.value && attributes.value.bind()) { - return; - } - } - }; - }(); -var render_DomFragment_Element__Element = function (initialise, teardown, toString, find, findAll, findComponent, findAllComponents, bind) { - - var DomElement = function (options, docFrag) { - initialise(this, options, docFrag); - }; - DomElement.prototype = { - detach: function () { - if (this.node) { - if (this.node.parentNode) { - this.node.parentNode.removeChild(this.node); - } - return this.node; - } - }, - teardown: teardown, - firstNode: function () { - return this.node; - }, - findNextNode: function () { - return null; - }, - bubble: function () { - }, - toString: toString, - find: find, - findAll: findAll, - findComponent: findComponent, - findAllComponents: findAllComponents, - bind: bind - }; - return DomElement; - }(render_DomFragment_Element_initialise__initialise, render_DomFragment_Element_prototype_teardown, render_DomFragment_Element_prototype_toString, render_DomFragment_Element_prototype_find, render_DomFragment_Element_prototype_findAll, render_DomFragment_Element_prototype_findComponent, render_DomFragment_Element_prototype_findAllComponents, render_DomFragment_Element_prototype_bind); -var config_errors = { missingParser: 'Missing Ractive.parse - cannot parse template. Either preparse or use the version that includes the parser' }; -var registries_partials = {}; -var render_DomFragment_Partial_getPartialDescriptor = function (errors, isClient, warn, isObject, partials, parse) { - - var getPartialDescriptor, registerPartial, getPartialFromRegistry, unpack; - getPartialDescriptor = function (root, name) { - var el, partial, errorMessage; - if (partial = getPartialFromRegistry(root, name)) { - return partial; - } - if (isClient) { - el = document.getElementById(name); - if (el && el.tagName === 'SCRIPT') { - if (!parse) { - throw new Error(errors.missingParser); - } - registerPartial(parse(el.innerHTML), name, partials); - } - } - partial = partials[name]; - if (!partial) { - errorMessage = 'Could not find descriptor for partial "' + name + '"'; - if (root.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - } - return []; - } - return unpack(partial); - }; - getPartialFromRegistry = function (registryOwner, name) { - var partial; - if (registryOwner.partials[name]) { - if (typeof registryOwner.partials[name] === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - partial = parse(registryOwner.partials[name], registryOwner.parseOptions); - registerPartial(partial, name, registryOwner.partials); - } - return unpack(registryOwner.partials[name]); - } - }; - registerPartial = function (partial, name, registry) { - var key; - if (isObject(partial)) { - registry[name] = partial.main; - for (key in partial.partials) { - if (partial.partials.hasOwnProperty(key)) { - registry[key] = partial.partials[key]; - } - } - } else { - registry[name] = partial; - } - }; - unpack = function (partial) { - if (partial.length === 1 && typeof partial[0] === 'string') { - return partial[0]; - } - return partial; - }; - return getPartialDescriptor; - }(config_errors, config_isClient, utils_warn, utils_isObject, registries_partials, parse__parse); -var render_DomFragment_Partial__Partial = function (types, getPartialDescriptor, circular) { - - var DomPartial, DomFragment; - circular.push(function () { - DomFragment = circular.DomFragment; - }); - DomPartial = function (options, docFrag) { - var parentFragment = this.parentFragment = options.parentFragment, descriptor; - this.type = types.PARTIAL; - this.name = options.descriptor.r; - this.index = options.index; - if (!options.descriptor.r) { - throw new Error('Partials must have a static reference (no expressions). This may change in a future version of Ractive.'); - } - descriptor = getPartialDescriptor(parentFragment.root, options.descriptor.r); - this.fragment = new DomFragment({ - descriptor: descriptor, - root: parentFragment.root, - pNode: parentFragment.pNode, - contextStack: parentFragment.contextStack, - owner: this - }); - if (docFrag) { - docFrag.appendChild(this.fragment.docFrag); - } - }; - DomPartial.prototype = { - firstNode: function () { - return this.fragment.firstNode(); - }, - findNextNode: function () { - return this.parentFragment.findNextNode(this); - }, - detach: function () { - return this.fragment.detach(); - }, - teardown: function (destroy) { - this.fragment.teardown(destroy); - }, - toString: function () { - return this.fragment.toString(); - }, - find: function (selector) { - return this.fragment.find(selector); - }, - findAll: function (selector, query) { - return this.fragment.findAll(selector, query); - }, - findComponent: function (selector) { - return this.fragment.findComponent(selector); - }, - findAllComponents: function (selector, query) { - return this.fragment.findAllComponents(selector, query); - } - }; - return DomPartial; - }(config_types, render_DomFragment_Partial_getPartialDescriptor, circular); -var render_DomFragment_Component_initialise_createModel_ComponentParameter = function (StringFragment) { - - var ComponentParameter = function (component, key, value) { - this.parentFragment = component.parentFragment; - this.component = component; - this.key = key; - this.fragment = new StringFragment({ - descriptor: value, - root: component.root, - owner: this, - contextStack: component.parentFragment.contextStack - }); - this.selfUpdating = this.fragment.isSimple(); - this.value = this.fragment.getValue(); - }; - ComponentParameter.prototype = { - bubble: function () { - if (this.selfUpdating) { - this.update(); - } else if (!this.deferred && this.ready) { - this.root._deferred.attrs.push(this); - this.deferred = true; - } - }, - update: function () { - var value = this.fragment.getValue(); - this.component.instance.set(this.key, value); - this.value = value; - }, - teardown: function () { - this.fragment.teardown(); - } - }; - return ComponentParameter; - }(render_StringFragment__StringFragment); -var render_DomFragment_Component_initialise_createModel__createModel = function (types, parseJSON, resolveRef, ComponentParameter) { - - return function (component, attributes, toBind) { - var data, key, value; - data = {}; - component.complexParameters = []; - for (key in attributes) { - if (attributes.hasOwnProperty(key)) { - value = getValue(component, key, attributes[key], toBind); - if (value !== undefined) { - data[key] = value; - } - } - } - return data; - }; - function getValue(component, key, descriptor, toBind) { - var parameter, parsed, root, parentFragment, keypath; - root = component.root; - parentFragment = component.parentFragment; - if (typeof descriptor === 'string') { - parsed = parseJSON(descriptor); - return parsed ? parsed.value : descriptor; - } - if (descriptor === null) { - return true; - } - if (descriptor.length === 1 && descriptor[0].t === types.INTERPOLATOR && descriptor[0].r) { - if (parentFragment.indexRefs && parentFragment.indexRefs[descriptor[0].r] !== undefined) { - return parentFragment.indexRefs[descriptor[0].r]; - } - keypath = resolveRef(root, descriptor[0].r, parentFragment.contextStack) || descriptor[0].r; - toBind.push({ - childKeypath: key, - parentKeypath: keypath - }); - return root.get(keypath); - } - parameter = new ComponentParameter(component, key, descriptor); - component.complexParameters.push(parameter); - return parameter.value; - } - }(config_types, utils_parseJSON, shared_resolveRef, render_DomFragment_Component_initialise_createModel_ComponentParameter); -var render_DomFragment_Component_initialise_createInstance = function () { - - return function (component, Component, data, docFrag, contentDescriptor) { - var instance, parentFragment, partials, root; - parentFragment = component.parentFragment; - root = component.root; - partials = { content: contentDescriptor || [] }; - instance = new Component({ - el: parentFragment.pNode.cloneNode(false), - data: data, - partials: partials, - _parent: root, - adaptors: root.adaptors - }); - instance.component = component; - component.instance = instance; - instance.insert(docFrag); - instance.fragment.pNode = parentFragment.pNode; - return instance; - }; - }(); -var render_DomFragment_Component_initialise_createObservers = function () { - - var observeOptions = { - init: false, - debug: true - }; - return function (component, toBind) { - var pair, i; - component.observers = []; - i = toBind.length; - while (i--) { - pair = toBind[i]; - bind(component, pair.parentKeypath, pair.childKeypath); - } - }; - function bind(component, parentKeypath, childKeypath) { - var parentInstance, childInstance, settingParent, settingChild, observers, observer, value; - parentInstance = component.root; - childInstance = component.instance; - observers = component.observers; - observer = parentInstance.observe(parentKeypath, function (value) { - if (!settingParent && !parentInstance._wrapped[parentKeypath]) { - settingChild = true; - childInstance.set(childKeypath, value); - settingChild = false; - } - }, observeOptions); - observers.push(observer); - if (childInstance.twoway) { - observer = childInstance.observe(childKeypath, function (value) { - if (!settingChild) { - settingParent = true; - parentInstance.set(parentKeypath, value); - settingParent = false; - } - }, observeOptions); - observers.push(observer); - value = childInstance.get(childKeypath); - if (value !== undefined) { - parentInstance.set(parentKeypath, value); - } - } - } - }(); -var render_DomFragment_Component_initialise_propagateEvents = function (warn) { - - var errorMessage = 'Components currently only support simple events - you cannot include arguments. Sorry!'; - return function (component, eventsDescriptor) { - var eventName; - for (eventName in eventsDescriptor) { - if (eventsDescriptor.hasOwnProperty(eventName)) { - propagateEvent(component.instance, component.root, eventName, eventsDescriptor[eventName]); - } - } - }; - function propagateEvent(childInstance, parentInstance, eventName, proxyEventName) { - if (typeof proxyEventName !== 'string') { - if (parentInstance.debug) { - throw new Error(errorMessage); - } else { - warn(errorMessage); - return; - } - } - childInstance.on(eventName, function () { - var args = Array.prototype.slice.call(arguments); - args.unshift(proxyEventName); - parentInstance.fire.apply(parentInstance, args); - }); - } - }(utils_warn); -var render_DomFragment_Component_initialise_updateLiveQueries = function () { - - return function (component) { - var ancestor, query; - ancestor = component.root; - while (ancestor) { - if (query = ancestor._liveComponentQueries[component.name]) { - query.push(component.instance); - } - ancestor = ancestor._parent; - } - }; - }(); -var render_DomFragment_Component_initialise__initialise = function (types, warn, createModel, createInstance, createObservers, propagateEvents, updateLiveQueries) { - - return function (component, options, docFrag) { - var parentFragment, root, Component, data, toBind; - parentFragment = component.parentFragment = options.parentFragment; - root = parentFragment.root; - component.root = root; - component.type = types.COMPONENT; - component.name = options.descriptor.e; - component.index = options.index; - component.observers = []; - Component = root.components[options.descriptor.e]; - if (!Component) { - throw new Error('Component "' + options.descriptor.e + '" not found'); - } - toBind = []; - data = createModel(component, options.descriptor.a, toBind); - createInstance(component, Component, data, docFrag, options.descriptor.f); - createObservers(component, toBind); - propagateEvents(component, options.descriptor.v); - if (options.descriptor.t1 || options.descriptor.t2 || options.descriptor.o) { - warn('The "intro", "outro" and "decorator" directives have no effect on components'); - } - updateLiveQueries(component); - }; - }(config_types, utils_warn, render_DomFragment_Component_initialise_createModel__createModel, render_DomFragment_Component_initialise_createInstance, render_DomFragment_Component_initialise_createObservers, render_DomFragment_Component_initialise_propagateEvents, render_DomFragment_Component_initialise_updateLiveQueries); -var render_DomFragment_Component__Component = function (initialise) { - - var DomComponent = function (options, docFrag) { - initialise(this, options, docFrag); - }; - DomComponent.prototype = { - firstNode: function () { - return this.instance.fragment.firstNode(); - }, - findNextNode: function () { - return this.parentFragment.findNextNode(this); - }, - detach: function () { - return this.instance.fragment.detach(); - }, - teardown: function () { - var query; - while (this.complexParameters.length) { - this.complexParameters.pop().teardown(); - } - while (this.observers.length) { - this.observers.pop().cancel(); - } - if (query = this.root._liveComponentQueries[this.name]) { - query._remove(this); - } - this.instance.teardown(); - }, - toString: function () { - return this.instance.fragment.toString(); - }, - find: function (selector) { - return this.instance.fragment.find(selector); - }, - findAll: function (selector, query) { - return this.instance.fragment.findAll(selector, query); - }, - findComponent: function (selector) { - if (!selector || selector === this.name) { - return this.instance; - } - return null; - }, - findAllComponents: function (selector, query) { - query._test(this, true); - if (this.instance.fragment) { - this.instance.fragment.findAllComponents(selector, query); - } - } - }; - return DomComponent; - }(render_DomFragment_Component_initialise__initialise); -var render_DomFragment_Comment = function (types) { - - var DomComment = function (options, docFrag) { - this.type = types.COMMENT; - this.descriptor = options.descriptor; - if (docFrag) { - this.node = document.createComment(options.descriptor.f); - docFrag.appendChild(this.node); - } - }; - DomComment.prototype = { - detach: function () { - this.node.parentNode.removeChild(this.node); - return this.node; - }, - teardown: function (destroy) { - if (destroy) { - this.detach(); - } - }, - firstNode: function () { - return this.node; - }, - toString: function () { - return ''; - } - }; - return DomComment; - }(config_types); -var render_DomFragment__DomFragment = function (types, matches, initFragment, insertHtml, Text, Interpolator, Section, Triple, Element, Partial, Component, Comment, circular) { - - var DomFragment = function (options) { - if (options.pNode) { - this.docFrag = document.createDocumentFragment(); - } - if (typeof options.descriptor === 'string') { - this.html = options.descriptor; - if (this.docFrag) { - this.nodes = insertHtml(this.html, options.pNode.tagName, this.docFrag); - } - } else { - initFragment(this, options); - } - }; - DomFragment.prototype = { - detach: function () { - var len, i; - if (this.nodes) { - i = this.nodes.length; - while (i--) { - this.docFrag.appendChild(this.nodes[i]); - } - } else if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - this.docFrag.appendChild(this.items[i].detach()); - } - } - return this.docFrag; - }, - createItem: function (options) { - if (typeof options.descriptor === 'string') { - return new Text(options, this.docFrag); - } - switch (options.descriptor.t) { - case types.INTERPOLATOR: - return new Interpolator(options, this.docFrag); - case types.SECTION: - return new Section(options, this.docFrag); - case types.TRIPLE: - return new Triple(options, this.docFrag); - case types.ELEMENT: - if (this.root.components[options.descriptor.e]) { - return new Component(options, this.docFrag); - } - return new Element(options, this.docFrag); - case types.PARTIAL: - return new Partial(options, this.docFrag); - case types.COMMENT: - return new Comment(options, this.docFrag); - default: - throw new Error('Something very strange happened. Please file an issue at https://github.com/RactiveJS/Ractive/issues. Thanks!'); - } - }, - teardown: function (destroy) { - var node; - if (this.nodes && destroy) { - while (node = this.nodes.pop()) { - node.parentNode.removeChild(node); - } - } else if (this.items) { - while (this.items.length) { - this.items.pop().teardown(destroy); - } - } - this.nodes = this.items = this.docFrag = null; - }, - firstNode: function () { - if (this.items && this.items[0]) { - return this.items[0].firstNode(); - } else if (this.nodes) { - return this.nodes[0] || null; - } - return null; - }, - findNextNode: function (item) { - var index = item.index; - if (this.items[index + 1]) { - return this.items[index + 1].firstNode(); - } - if (this.owner === this.root) { - if (!this.owner.component) { - return null; - } - return this.owner.component.findNextNode(); - } - return this.owner.findNextNode(this); - }, - toString: function () { - var html, i, len, item; - if (this.html) { - return this.html; - } - html = ''; - if (!this.items) { - return html; - } - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - html += item.toString(); - } - return html; - }, - find: function (selector) { - var i, len, item, node, queryResult; - if (this.nodes) { - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - return node; - } - if (queryResult = node.querySelector(selector)) { - return queryResult; - } - } - return null; - } - if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.find && (queryResult = item.find(selector))) { - return queryResult; - } - } - return null; - } - }, - findAll: function (selector, query) { - var i, len, item, node, queryAllResult, numNodes, j; - if (this.nodes) { - len = this.nodes.length; - for (i = 0; i < len; i += 1) { - node = this.nodes[i]; - if (node.nodeType !== 1) { - continue; - } - if (matches(node, selector)) { - query.push(node); - } - if (queryAllResult = node.querySelectorAll(selector)) { - numNodes = queryAllResult.length; - for (j = 0; j < numNodes; j += 1) { - query.push(queryAllResult[j]); - } - } - } - } else if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.findAll) { - item.findAll(selector, query); - } - } - } - return query; - }, - findComponent: function (selector) { - var len, i, item, queryResult; - if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.findComponent && (queryResult = item.findComponent(selector))) { - return queryResult; - } - } - return null; - } - }, - findAllComponents: function (selector, query) { - var i, len, item; - if (this.items) { - len = this.items.length; - for (i = 0; i < len; i += 1) { - item = this.items[i]; - if (item.findAllComponents) { - item.findAllComponents(selector, query); - } - } - } - return query; - } - }; - circular.DomFragment = DomFragment; - return DomFragment; - }(config_types, utils_matches, render_shared_initFragment, render_DomFragment_shared_insertHtml, render_DomFragment_Text, render_DomFragment_Interpolator, render_DomFragment_Section__Section, render_DomFragment_Triple, render_DomFragment_Element__Element, render_DomFragment_Partial__Partial, render_DomFragment_Component__Component, render_DomFragment_Comment, circular); -var Ractive_prototype_render = function (getElement, makeTransitionManager, preDomUpdate, postDomUpdate, DomFragment) { - - return function (target, complete) { - var transitionManager; - if (!this._initing) { - throw new Error('You cannot call ractive.render() directly!'); - } - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - this.fragment = new DomFragment({ - descriptor: this.template, - root: this, - owner: this, - pNode: target - }); - preDomUpdate(this); - if (target) { - target.appendChild(this.fragment.docFrag); - } - postDomUpdate(this); - this._transitionManager = null; - transitionManager.ready(); - this.rendered = true; - }; - }(utils_getElement, shared_makeTransitionManager, shared_preDomUpdate, shared_postDomUpdate, render_DomFragment__DomFragment); -var Ractive_prototype_renderHTML = function (warn) { - - return function () { - warn('renderHTML() has been deprecated and will be removed in a future version. Please use toHTML() instead'); - return this.toHTML(); - }; - }(utils_warn); -var Ractive_prototype_toHTML = function () { - - return function () { - return this.fragment.toString(); - }; - }(); -var Ractive_prototype_teardown = function (makeTransitionManager, clearCache) { - - return function (complete) { - var keypath, transitionManager, previousTransitionManager; - this.fire('teardown'); - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, complete); - this.fragment.teardown(true); - while (this._animations[0]) { - this._animations[0].stop(); - } - for (keypath in this._cache) { - clearCache(this, keypath); - } - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - }; - }(shared_makeTransitionManager, shared_clearCache); -var Ractive_prototype_shared_add = function (isNumeric) { - - return function (root, keypath, d) { - var value; - if (typeof keypath !== 'string' || !isNumeric(d)) { - if (root.debug) { - throw new Error('Bad arguments'); - } - return; - } - value = root.get(keypath); - if (value === undefined) { - value = 0; - } - if (!isNumeric(value)) { - if (root.debug) { - throw new Error('Cannot add to a non-numeric value'); - } - return; - } - root.set(keypath, value + d); - }; - }(utils_isNumeric); -var Ractive_prototype_add = function (add) { - - return function (keypath, d) { - add(this, keypath, d === undefined ? 1 : d); - }; - }(Ractive_prototype_shared_add); -var Ractive_prototype_subtract = function (add) { - - return function (keypath, d) { - add(this, keypath, d === undefined ? -1 : -d); - }; - }(Ractive_prototype_shared_add); -var Ractive_prototype_toggle = function () { - - return function (keypath) { - var value; - if (typeof keypath !== 'string') { - if (this.debug) { - throw new Error('Bad arguments'); - } - return; - } - value = this.get(keypath); - this.set(keypath, !value); - }; - }(); -var Ractive_prototype_merge_mapOldToNewIndex = function () { - - return function (oldArray, newArray) { - var usedIndices, mapper, firstUnusedIndex, newIndices, changed; - usedIndices = {}; - firstUnusedIndex = 0; - mapper = function (item, i) { - var index, start, len; - start = firstUnusedIndex; - len = newArray.length; - do { - index = newArray.indexOf(item, start); - if (index === -1) { - changed = true; - return -1; - } - start = index + 1; - } while (usedIndices[index] && start < len); - if (index === firstUnusedIndex) { - firstUnusedIndex += 1; - } - if (index !== i) { - changed = true; - } - usedIndices[index] = true; - return index; - }; - newIndices = oldArray.map(mapper); - newIndices.unchanged = !changed; - return newIndices; - }; - }(); -var Ractive_prototype_merge_queueDependants = function (types) { - - return function queueDependants(keypath, deps, mergeQueue, updateQueue) { - var i, dependant; - i = deps.length; - while (i--) { - dependant = deps[i]; - if (dependant.type === types.REFERENCE) { - dependant.update(); - } else if (dependant.keypath === keypath && dependant.type === types.SECTION && !dependant.inverted && dependant.docFrag) { - mergeQueue[mergeQueue.length] = dependant; - } else { - updateQueue[updateQueue.length] = dependant; - } - } - }; - }(config_types); -var Ractive_prototype_merge__merge = function (warn, isArray, clearCache, preDomUpdate, processDeferredUpdates, makeTransitionManager, notifyDependants, replaceData, mapOldToNewIndex, queueDependants) { - - var identifiers = {}; - return function (keypath, array, options) { - var currentArray, oldArray, newArray, identifier, lengthUnchanged, i, newIndices, mergeQueue, updateQueue, depsByKeypath, deps, transitionManager, previousTransitionManager, upstreamQueue, keys; - currentArray = this.get(keypath); - if (!isArray(currentArray) || !isArray(array)) { - return this.set(keypath, array, options && options.complete); - } - lengthUnchanged = currentArray.length === array.length; - if (options && options.compare) { - if (options.compare === true) { - identifier = stringify; - } else if (typeof options.compare === 'string') { - identifier = getIdentifier(options.compare); - } else if (typeof options.compare == 'function') { - identifier = options.compare; - } else { - throw new Error('The `compare` option must be a function, or a string representing an identifying field (or `true` to use JSON.stringify)'); - } - try { - oldArray = currentArray.map(identifier); - newArray = array.map(identifier); - } catch (err) { - if (this.debug) { - throw err; - } else { - warn('Merge operation: comparison failed. Falling back to identity checking'); - } - oldArray = currentArray; - newArray = array; - } - } else { - oldArray = currentArray; - newArray = array; - } - newIndices = mapOldToNewIndex(oldArray, newArray); - clearCache(this, keypath); - replaceData(this, keypath, array); - if (newIndices.unchanged && lengthUnchanged) { - return; - } - previousTransitionManager = this._transitionManager; - this._transitionManager = transitionManager = makeTransitionManager(this, options && options.complete); - mergeQueue = []; - updateQueue = []; - for (i = 0; i < this._deps.length; i += 1) { - depsByKeypath = this._deps[i]; - if (!depsByKeypath) { - continue; - } - deps = depsByKeypath[keypath]; - if (deps) { - queueDependants(keypath, deps, mergeQueue, updateQueue); - preDomUpdate(this); - while (mergeQueue.length) { - mergeQueue.pop().merge(newIndices); - } - while (updateQueue.length) { - updateQueue.pop().update(); - } - } - } - processDeferredUpdates(this); - upstreamQueue = []; - keys = keypath.split('.'); - while (keys.length) { - keys.pop(); - upstreamQueue[upstreamQueue.length] = keys.join('.'); - } - notifyDependants.multiple(this, upstreamQueue, true); - if (oldArray.length !== newArray.length) { - notifyDependants(this, keypath + '.length', true); - } - this._transitionManager = previousTransitionManager; - transitionManager.ready(); - }; - function stringify(item) { - return JSON.stringify(item); - } - function getIdentifier(str) { - if (!identifiers[str]) { - identifiers[str] = function (item) { - return item[str]; - }; - } - return identifiers[str]; - } - }(utils_warn, utils_isArray, shared_clearCache, shared_preDomUpdate, shared_processDeferredUpdates, shared_makeTransitionManager, shared_notifyDependants, Ractive_prototype_shared_replaceData, Ractive_prototype_merge_mapOldToNewIndex, Ractive_prototype_merge_queueDependants); -var Ractive_prototype_detach = function () { - - return function () { - return this.fragment.detach(); - }; - }(); -var Ractive_prototype_insert = function (getElement) { - - return function (target, anchor) { - target = getElement(target); - anchor = getElement(anchor) || null; - if (!target) { - throw new Error('You must specify a valid target to insert into'); - } - target.insertBefore(this.detach(), anchor); - this.fragment.pNode = target; - }; - }(utils_getElement); -var Ractive_prototype__prototype = function (get, set, update, updateModel, animate, on, off, observe, fire, find, findAll, findComponent, findAllComponents, render, renderHTML, toHTML, teardown, add, subtract, toggle, merge, detach, insert) { - - return { - get: get, - set: set, - update: update, - updateModel: updateModel, - animate: animate, - on: on, - off: off, - observe: observe, - fire: fire, - find: find, - findAll: findAll, - findComponent: findComponent, - findAllComponents: findAllComponents, - renderHTML: renderHTML, - toHTML: toHTML, - render: render, - teardown: teardown, - add: add, - subtract: subtract, - toggle: toggle, - merge: merge, - detach: detach, - insert: insert - }; - }(Ractive_prototype_get__get, Ractive_prototype_set, Ractive_prototype_update, Ractive_prototype_updateModel, Ractive_prototype_animate__animate, Ractive_prototype_on, Ractive_prototype_off, Ractive_prototype_observe__observe, Ractive_prototype_fire, Ractive_prototype_find, Ractive_prototype_findAll, Ractive_prototype_findComponent, Ractive_prototype_findAllComponents, Ractive_prototype_render, Ractive_prototype_renderHTML, Ractive_prototype_toHTML, Ractive_prototype_teardown, Ractive_prototype_add, Ractive_prototype_subtract, Ractive_prototype_toggle, Ractive_prototype_merge__merge, Ractive_prototype_detach, Ractive_prototype_insert); -var extend_registries = function () { - - return [ - 'partials', - 'transitions', - 'events', - 'components', - 'decorators', - 'data' - ]; - }(); -var extend_initOptions = function () { - - return [ - 'el', - 'template', - 'complete', - 'modifyArrays', - 'magic', - 'twoway', - 'lazy', - 'append', - 'preserveWhitespace', - 'sanitize', - 'stripComments', - 'noIntro', - 'transitionsEnabled', - 'adaptors' - ]; - }(); -var extend_inheritFromParent = function (registries, initOptions, create) { - - return function (Child, Parent) { - registries.forEach(function (property) { - if (Parent[property]) { - Child[property] = create(Parent[property]); - } - }); - initOptions.forEach(function (property) { - Child[property] = Parent[property]; - }); - }; - }(extend_registries, extend_initOptions, utils_create); -var extend_wrapMethod = function () { - - return function (method, superMethod) { - if (/_super/.test(method)) { - return function () { - var _super = this._super, result; - this._super = superMethod; - result = method.apply(this, arguments); - this._super = _super; - return result; - }; - } else { - return method; - } - }; - }(); -var extend_utils_augment = function () { - - return function (target, source) { - var key; - for (key in source) { - if (source.hasOwnProperty(key)) { - target[key] = source[key]; - } - } - return target; - }; - }(); -var extend_inheritFromChildProps = function (registries, initOptions, wrapMethod, augment) { - - var blacklist, blacklisted; - blacklist = registries.concat(initOptions); - blacklisted = {}; - blacklist.forEach(function (property) { - blacklisted[property] = true; - }); - return function (Child, childProps) { - var key, member; - registries.forEach(function (property) { - var value = childProps[property]; - if (value) { - if (Child[property]) { - augment(Child[property], value); - } else { - Child[property] = value; - } - } - }); - initOptions.forEach(function (property) { - var value = childProps[property]; - if (value !== undefined) { - if (typeof value === 'function' && typeof Child[property] === 'function') { - Child[property] = wrapMethod(value, Child[property]); - } else { - Child[property] = childProps[property]; - } - } - }); - for (key in childProps) { - if (childProps.hasOwnProperty(key) && !blacklisted[key]) { - member = childProps[key]; - if (typeof member === 'function' && typeof Child.prototype[key] === 'function') { - Child.prototype[key] = wrapMethod(member, Child.prototype[key]); - } else { - Child.prototype[key] = member; - } - } - } - }; - }(extend_registries, extend_initOptions, extend_wrapMethod, extend_utils_augment); -var extend_extractInlinePartials = function (isObject, augment) { - - return function (Child, childProps) { - if (isObject(Child.template)) { - if (!Child.partials) { - Child.partials = {}; - } - augment(Child.partials, Child.template.partials); - if (childProps.partials) { - augment(Child.partials, childProps.partials); - } - Child.template = Child.template.main; - } - }; - }(utils_isObject, extend_utils_augment); -var extend_conditionallyParseTemplate = function (errors, isClient, parse) { - - return function (Child) { - var templateEl; - if (typeof Child.template === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - if (Child.template.charAt(0) === '#' && isClient) { - templateEl = document.getElementById(Child.template.substring(1)); - if (templateEl && templateEl.tagName === 'SCRIPT') { - Child.template = parse(templateEl.innerHTML, Child); - } else { - throw new Error('Could not find template element (' + Child.template + ')'); - } - } else { - Child.template = parse(Child.template, Child); - } - } - }; - }(config_errors, config_isClient, parse__parse); -var extend_conditionallyParsePartials = function (errors, parse) { - - return function (Child) { - var key; - if (Child.partials) { - for (key in Child.partials) { - if (Child.partials.hasOwnProperty(key) && typeof Child.partials[key] === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - Child.partials[key] = parse(Child.partials[key], Child); - } - } - } - }; - }(config_errors, parse__parse); -var extend_utils_clone = function () { - - return function (source) { - var target = {}, key; - for (key in source) { - if (source.hasOwnProperty(key)) { - target[key] = source[key]; - } - } - return target; - }; - }(); -var utils_extend = function () { - - return function (target) { - var prop, source, sources = Array.prototype.slice.call(arguments, 1); - while (source = sources.shift()) { - for (prop in source) { - if (source.hasOwnProperty(prop)) { - target[prop] = source[prop]; - } - } - } - return target; - }; - }(); -var Ractive_initialise = function (isClient, errors, warn, create, extend, defineProperty, defineProperties, getElement, isObject, magicAdaptor, parse) { - - var getObject, getArray, defaultOptions, registries; - getObject = function () { - return {}; - }; - getArray = function () { - return []; - }; - defaultOptions = create(null); - defineProperties(defaultOptions, { - preserveWhitespace: { - enumerable: true, - value: false - }, - append: { - enumerable: true, - value: false - }, - twoway: { - enumerable: true, - value: true - }, - modifyArrays: { - enumerable: true, - value: true - }, - data: { - enumerable: true, - value: getObject - }, - lazy: { - enumerable: true, - value: false - }, - debug: { - enumerable: true, - value: false - }, - transitions: { - enumerable: true, - value: getObject - }, - decorators: { - enumerable: true, - value: getObject - }, - events: { - enumerable: true, - value: getObject - }, - noIntro: { - enumerable: true, - value: false - }, - transitionsEnabled: { - enumerable: true, - value: true - }, - magic: { - enumerable: true, - value: false - }, - adaptors: { - enumerable: true, - value: getArray - } - }); - registries = [ - 'components', - 'decorators', - 'events', - 'partials', - 'transitions', - 'data' - ]; - return function (ractive, options) { - var key, template, templateEl, parsedTemplate; - for (key in defaultOptions) { - if (options[key] === undefined) { - options[key] = typeof defaultOptions[key] === 'function' ? defaultOptions[key]() : defaultOptions[key]; - } - } - defineProperties(ractive, { - _initing: { - value: true, - writable: true - }, - _guid: { - value: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { - var r, v; - r = Math.random() * 16 | 0; - v = c == 'x' ? r : r & 3 | 8; - return v.toString(16); - }) - }, - _subs: { - value: create(null), - configurable: true - }, - _cache: { value: {} }, - _cacheMap: { value: create(null) }, - _deps: { value: [] }, - _depsMap: { value: create(null) }, - _patternObservers: { value: [] }, - _pendingResolution: { value: [] }, - _deferred: { value: {} }, - _evaluators: { value: create(null) }, - _twowayBindings: { value: {} }, - _transitionManager: { - value: null, - writable: true - }, - _animations: { value: [] }, - nodes: { value: {} }, - _wrapped: { value: create(null) }, - _liveQueries: { value: [] }, - _liveComponentQueries: { value: [] } - }); - defineProperties(ractive._deferred, { - attrs: { value: [] }, - evals: { value: [] }, - selectValues: { value: [] }, - checkboxes: { value: [] }, - radios: { value: [] }, - observers: { value: [] }, - transitions: { value: [] }, - liveQueries: { value: [] }, - decorators: { value: [] }, - focusable: { - value: null, - writable: true - } - }); - ractive.adaptors = options.adaptors; - ractive.modifyArrays = options.modifyArrays; - ractive.magic = options.magic; - ractive.twoway = options.twoway; - ractive.lazy = options.lazy; - ractive.debug = options.debug; - if (ractive.magic && !magicAdaptor) { - throw new Error('Getters and setters (magic mode) are not supported in this browser'); - } - if (options._parent) { - defineProperty(ractive, '_parent', { value: options._parent }); - } - if (options.el) { - ractive.el = getElement(options.el); - if (!ractive.el && ractive.debug) { - throw new Error('Could not find container element'); - } - } - if (options.eventDefinitions) { - warn('ractive.eventDefinitions has been deprecated in favour of ractive.events. Support will be removed in future versions'); - options.events = options.eventDefinitions; - } - registries.forEach(function (registry) { - if (ractive.constructor[registry]) { - ractive[registry] = extend(create(ractive.constructor[registry] || {}), options[registry]); - } else if (options[registry]) { - ractive[registry] = options[registry]; - } - }); - template = options.template; - if (typeof template === 'string') { - if (!parse) { - throw new Error(errors.missingParser); - } - if (template.charAt(0) === '#' && isClient) { - templateEl = document.getElementById(template.substring(1)); - if (templateEl) { - parsedTemplate = parse(templateEl.innerHTML, options); - } else { - throw new Error('Could not find template element (' + template + ')'); - } - } else { - parsedTemplate = parse(template, options); - } - } else { - parsedTemplate = template; - } - if (isObject(parsedTemplate)) { - extend(ractive.partials, parsedTemplate.partials); - parsedTemplate = parsedTemplate.main; - } - if (parsedTemplate && parsedTemplate.length === 1 && typeof parsedTemplate[0] === 'string') { - parsedTemplate = parsedTemplate[0]; - } - ractive.template = parsedTemplate; - extend(ractive.partials, options.partials); - ractive.parseOptions = { - preserveWhitespace: options.preserveWhitespace, - sanitize: options.sanitize, - stripComments: options.stripComments - }; - ractive.transitionsEnabled = options.noIntro ? false : options.transitionsEnabled; - if (isClient && !ractive.el) { - ractive.el = document.createDocumentFragment(); - } - if (ractive.el && !options.append) { - ractive.el.innerHTML = ''; - } - ractive.render(ractive.el, options.complete); - ractive.transitionsEnabled = options.transitionsEnabled; - ractive._initing = false; - }; - }(config_isClient, config_errors, utils_warn, utils_create, utils_extend, utils_defineProperty, utils_defineProperties, utils_getElement, utils_isObject, Ractive_prototype_get_magicAdaptor, parse__parse); -var extend_initChildInstance = function (fillGaps, initOptions, clone, wrapMethod, initialise) { - - return function (child, Child, options) { - initOptions.forEach(function (property) { - var value = options[property], defaultValue = Child[property]; - if (typeof value === 'function' && typeof defaultValue === 'function') { - options[property] = wrapMethod(value, defaultValue); - } else if (value === undefined && defaultValue !== undefined) { - options[property] = defaultValue; - } - }); - if (child.beforeInit) { - child.beforeInit(options); - } - initialise(child, options); - if (child.init) { - child.init(options); - } - }; - }(utils_fillGaps, extend_initOptions, extend_utils_clone, extend_wrapMethod, Ractive_initialise); -var extend__extend = function (create, inheritFromParent, inheritFromChildProps, extractInlinePartials, conditionallyParseTemplate, conditionallyParsePartials, initChildInstance, circular) { - - var Ractive; - circular.push(function () { - Ractive = circular.Ractive; - }); - return function (childProps) { - var Parent = this, Child; - Child = function (options) { - initChildInstance(this, Child, options || {}); - }; - Child.prototype = create(Parent.prototype); - Child.prototype.constructor = Child; - inheritFromParent(Child, Parent); - inheritFromChildProps(Child, childProps); - conditionallyParseTemplate(Child); - extractInlinePartials(Child, childProps); - conditionallyParsePartials(Child); - Child.extend = Parent.extend; - return Child; - }; - }(utils_create, extend_inheritFromParent, extend_inheritFromChildProps, extend_extractInlinePartials, extend_conditionallyParseTemplate, extend_conditionallyParsePartials, extend_initChildInstance, circular); -var Ractive__Ractive = function (svg, create, defineProperties, prototype, partialRegistry, adaptorRegistry, easingRegistry, Ractive_extend, parse, initialise, circular) { - - var Ractive = function (options) { - initialise(this, options); - }; - defineProperties(Ractive, { - prototype: { value: prototype }, - partials: { value: partialRegistry }, - adaptors: { value: adaptorRegistry }, - easing: { value: easingRegistry }, - transitions: { value: {} }, - events: { value: {} }, - components: { value: {} }, - decorators: { value: {} }, - svg: { value: svg }, - VERSION: { value: '0.3.9' } - }); - Ractive.eventDefinitions = Ractive.events; - Ractive.prototype.constructor = Ractive; - Ractive.delimiters = [ - '{{', - '}}' - ]; - Ractive.tripleDelimiters = [ - '{{{', - '}}}' - ]; - Ractive.extend = Ractive_extend; - Ractive.parse = parse; - circular.Ractive = Ractive; - return Ractive; - }(config_svg, utils_create, utils_defineProperties, Ractive_prototype__prototype, registries_partials, registries_adaptors, registries_easing, extend__extend, parse__parse, Ractive_initialise, circular); -var Ractive = function (Ractive, circular) { - - if (typeof window !== 'undefined' && window.Node && !window.Node.prototype.contains && window.HTMLElement && window.HTMLElement.prototype.contains) { - window.Node.prototype.contains = window.HTMLElement.prototype.contains; - } - while (circular.length) { - circular.pop()(); - } - return Ractive; - }(Ractive__Ractive, circular); -// export as Common JS module... -if ( typeof module !== "undefined" && module.exports ) { - module.exports = Ractive; -} - -// ... or as AMD module -else if ( typeof define === "function" && define.amd ) { - define( function () { - return Ractive; - }); -} - -// ... or as browser global -else { - global.Ractive = Ractive; -} - -}( typeof window !== 'undefined' ? window : this )); \ No newline at end of file diff --git a/build/Ractive.runtime.min.js b/build/Ractive.runtime.min.js deleted file mode 100644 index e0fe1dbd4e..0000000000 --- a/build/Ractive.runtime.min.js +++ /dev/null @@ -1,3 +0,0 @@ -!function(a){var b=function(){return"undefined"!=typeof document?document&&document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure","1.1"):void 0}(),c=function(){var a;try{Object.create(null),a=Object.create}catch(b){a=function(){var a=function(){};return function(b,c){var d;return null===b?{}:(a.prototype=b,d=new a,c&&Object.defineProperties(d,c),d)}}()}return a}(),d={html:"http://www.w3.org/1999/xhtml",mathml:"http://www.w3.org/1998/Math/MathML",svg:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},e=function(a,b){return a?function(a,b){return b?document.createElementNS(b,a):document.createElement(a)}:function(a,c){if(c&&c!==b.html)throw"This browser does not support namespaces other than http://www.w3.org/1999/xhtml. The most likely cause of this error is that you're trying to render SVG in an older browser. See https://github.com/RactiveJS/Ractive/wiki/SVG-and-older-browsers for more information";return document.createElement(a)}}(b,d),f=function(){return"object"==typeof document?!0:!1}(),g=function(a){try{return Object.defineProperty({},"test",{value:0}),a&&Object.defineProperty(document.createElement("div"),"test",{value:0}),Object.defineProperty}catch(b){return function(a,b,c){a[b]=c.value}}}(f),h=function(a,b,c){try{try{Object.defineProperties({},{test:{value:0}})}catch(d){throw d}return c&&Object.defineProperties(a("div"),{test:{value:0}}),Object.defineProperties}catch(d){return function(a,c){var d;for(d in c)c.hasOwnProperty(d)&&b(a,d,c[d])}}}(e,g,f),i=function(){var a=/\[\s*(\*|[0-9]|[1-9][0-9]+)\s*\]/g;return function(b){return(b||"").replace(a,".$1")}}(),j={},k={TEXT:1,INTERPOLATOR:2,TRIPLE:3,SECTION:4,INVERTED:5,CLOSING:6,ELEMENT:7,PARTIAL:8,COMMENT:9,DELIMCHANGE:10,MUSTACHE:11,TAG:12,ATTRIBUTE:13,COMPONENT:15,NUMBER_LITERAL:20,STRING_LITERAL:21,ARRAY_LITERAL:22,OBJECT_LITERAL:23,BOOLEAN_LITERAL:24,GLOBAL:26,KEY_VALUE_PAIR:27,REFERENCE:30,REFINEMENT:31,MEMBER:32,PREFIX_OPERATOR:33,BRACKETED:34,CONDITIONAL:35,INFIX_OPERATOR:36,INVOCATION:40},l=function(){var a=Object.prototype.toString;return function(b){return"[object Array]"===a.call(b)}}(),m=function(){return function a(b,c){var d,e;if((e=b._wrapped[c])&&e.teardown()!==!1&&(b._wrapped[c]=null),b._cache[c]=void 0,d=b._cacheMap[c])for(;d.length;)a(b,d.pop())}}(),n=function(){return function(a,b){var c,d,e,f,g,h;for(c=[],h=a.rendered?a.el:a.fragment.docFrag,d=h.querySelectorAll('input[type="checkbox"][name="{{'+b+'}}"]'),f=d.length,g=0;f>g;g+=1)e=d[g],(e.hasAttribute("checked")||e.checked)&&(c[c.length]=e._ractive.value);return c}}(),o=function(a){return function(b){var c,d,e,f,g,h;for(c=b._deferred;d=c.evals.pop();)d.update().deferred=!1;for(;e=c.selectValues.pop();)e.deferredUpdate();for(;f=c.attrs.pop();)f.update().deferred=!1;for(;g=c.checkboxes.pop();)b.set(g,a(b,g));for(;h=c.radios.pop();)h.update()}}(n),p=function(){return function(a){var b,c,d,e,f,g;for(b=a._deferred,(c=b.focusable)&&(c.focus(),b.focusable=null);d=b.liveQueries.pop();)d._sort();for(;e=b.decorators.pop();)e.init();for(;f=b.transitions.pop();)f.init();for(;g=b.observers.pop();)g.update()}}(),q=function(){var a=function(a,b){var c,d,e,f;return a._parent&&a._parent._transitionManager?a._parent._transitionManager:(d=[],e=function(){var a,b;for(a=d.length;a--;)b=d[a],f(b.node)&&(b.detach(),d.splice(a,1))},f=function(a){var b,d;for(b=c.active.length;b--;)if(d=c.active[b],a.contains(d))return!1;return!0},c={active:[],push:function(a){c.active[c.active.length]=a},pop:function(a){var b;b=c.active.indexOf(a),-1!==b&&(c.active.splice(b,1),e(),!c.active.length&&c._ready&&c.complete())},complete:function(){b&&b.call(a)},ready:function(){e(),c._ready=!0,c.active.length||c.complete()},detachWhenReady:function(a){d[d.length]=a}})};return a}(),r=function(){function a(a,d,e,f){var g=a._deps[e];g&&(b(g[d]),f||c(a._depsMap[d],a,e))}function b(a){var b,c;if(a)for(c=a.length,b=0;c>b;b+=1)a[b].update()}function c(b,c,d,e){var f;if(b)for(f=b.length;f--;)a(c,b[f],d,e)}function d(a,b,c,f,g){var i,j,k,l,m,n,o,p;for(i=a._patternObservers.length;i--;)j=a._patternObservers[i],j.regex.test(c)&&j.update(c);f||(p=function(b){if(k=a._depsMap[b])for(i=k.length;i--;)l=k[i],m=h.exec(l)[0],n=c+"."+m,d(a,l,n)},g?(o=e(c),o.forEach(p)):p(b))}function e(a){var b,c,d,e,g,h;for(b=a.split("."),c=f(b.length),g=[],d=function(a,c){return a?"*":b[c]},e=c.length;e--;)h=c[e].map(d).join("."),g[h]||(g[g.length]=h,g[h]=!0);return g}function f(a){var b,c,d,e,f,g="";if(!i[a]){for(d=[];g.length=f;f+=1){for(c=f.toString(2);c.length2&&f[1])for(q=Math.min(f[1],f.length-2),r=f[0],s=r+q,f[1]===f.length-2&&(u=!0),p=r;s>p;p+=1)t=g+"."+p,h(a,t);for(e(a),m=[],l=g.split(".");l.length;)l.pop(),m[m.length]=l.join(".");h.multiple(a,m,!0),u||h(a,g+".length",!0)},i=function(b,c,d,e){var f,g;for(f=c.length;f--;)g=c[f],g.type===a.REFERENCE?g.update():g.keypath===b&&g.type===a.SECTION&&!g.inverted&&g.docFrag?d[d.length]=g:e[e.length]=g},j=b._ractive.wrappers,l=j.length;l--;)k=j[l],g(k.root,k.keypath)},n=[],p=["pop","push","reverse","shift","sort","splice","unshift"],q=function(){},p.forEach(function(a){var c=function(){var b,c,d,h,i={},k={};for(b=Array.prototype[a].apply(this,arguments),c=this._ractive.instances,h=c.length;h--;)d=c[h],i[d._guid]=d._transitionManager,d._transitionManager=k[d._guid]=g(d,q);for(this._ractive.setting=!0,j(this,a,arguments),this._ractive.setting=!1,h=c.length;h--;)d=c[h],d._transitionManager=i[d._guid],k[d._guid].ready(),e(d),f(d);return b};b(n,a,{value:c})}),o={},o.__proto__?(l=function(a){a.__proto__=n},m=function(a){a.__proto__=Array.prototype}):(l=function(a){var c,d;for(c=p.length;c--;)d=p[c],b(a,d,{value:n[d],configurable:!0})},m=function(a){var b;for(b=p.length;b--;)delete a[p[b]]}),r="Something went wrong in a rather interesting way",i}(k,g,l,m,o,p,q,r),t=function(){var a,b;try{Object.defineProperty({},"test",{value:0})}catch(c){return!1}return a={filter:function(a,b){return!!b},wrap:function(a,c,d){return new b(a,c,d)}},b=function(a,b,c){var d,e,f,g,h,i,j,k,l,m=this;if(this.ractive=a,this.keypath=c,d=c.split("."),this.prop=d.pop(),f=d.join("."),this.obj=f?a.get(f):a.data,g=this.originalDescriptor=Object.getOwnPropertyDescriptor(this.obj,this.prop),g&&g.set&&(h=g.set._ractiveWrappers))return-1===h.indexOf(this)&&h.push(this),void 0;if(g&&!g.configurable)throw new Error('Cannot use magic mode with property "'+e+'" - object is not configurable');g&&(this.value=g.value,i=g.get,j=g.set),k=i||function(){return m.value},l=function(a){var b,c,d;for(j&&j(a),b=l._ractiveWrappers,d=b.length;d--;)c=b[d],c.resetting||c.ractive.set(c.keypath,a)},l._ractiveWrappers=[this],Object.defineProperty(this.obj,this.prop,{get:k,set:l,enumerable:!0,configurable:!0})},b.prototype={get:function(){return this.value},reset:function(a){this.resetting=!0,this.value=a,this.resetting=!1},teardown:function(){var a,b,c,d;a=Object.getOwnPropertyDescriptor(this.obj,this.prop),b=a.set,d=b._ractiveWrappers,d.splice(d.indexOf(this),1),d.length||(c=this.obj[this.prop],Object.defineProperty(this.obj,this.prop,this.originalDescriptor||{writable:!0,enumerable:!0,configrable:!0}),this.obj[this.prop]=c)}},a}(),u=function(a,b,c){function d(a,b){var c,d={};if(!b)return a;b+=".";for(c in a)a.hasOwnProperty(c)&&(d[b+c]=a[c]);return d}function e(a){var b;return f[a]||(b=a?a+".":"",f[a]=function(c,e){var f;return"string"==typeof c?(f={},f[b+c]=e,f):"object"==typeof c?b?d(c,a):c:void 0}),f[a]}var f={};return function(d,f,g,h){var i,j,k,l;for(i=d.adaptors.length,j=0;i>j;j+=1){if(k=d.adaptors[j],"string"==typeof k){if(!a[k])throw new Error('Missing adaptor "'+k+'"');k=d.adaptors[j]=a[k]}if(k.filter(g,f,d))return l=d._wrapped[f]=k.wrap(d,g,f,e(f)),l.value=g,void 0}h||(d.magic&&c.filter(g,f,d)?d._wrapped[f]=c.wrap(d,g,f):d.modifyArrays&&b.filter(g,f,d)&&(d._wrapped[f]=b.wrap(d,g,f)))}}(j,s,t),v=function(a,b,c){var d,e,f;return d=function(a){return this._captured&&!this._captured[a]&&(this._captured.push(a),this._captured[a]=!0),e(this,a)},e=function(b,d){var e,g,h,i,j;return d=a(d),e=b._cache,void 0!==(g=e[d])?g:((i=b._wrapped[d])?h=i.value:d?h=(j=b._evaluators[d])?j.value:f(b,d):(c(b,"",b.data),h=b.data),e[d]=h,h)},f=function(a,b){var d,f,g,h,i,j,k;return d=b.split("."),f=d.pop(),g=d.join("."),h=e(a,g),(k=a._wrapped[g])&&(h=k.get()),null!==h&&void 0!==h?((i=a._cacheMap[g])?-1===i.indexOf(b)&&(i[i.length]=b):a._cacheMap[g]=[b],j=h[f],c(a,b,j),a._cache[b]=j,j):void 0},d}(i,j,u),w=function(){var a=Object.prototype.toString;return function(b){return"object"==typeof b&&"[object Object]"===a.call(b)}}(),x=function(){return function(a,b){return null===a&&null===b?!0:"object"==typeof a||"object"==typeof b?!1:a===b}}(),y=function(){var a;return a=function(a,b,c){var d,e,f,g,h,i,j,k,l,m,n;if(n='Could not resolve reference - too many "../" prefixes',"."===b){if(!c.length)return"";d=c[c.length-1]}else if("."===b.charAt(0))if(m=c[c.length-1],g=m?m.split("."):[],"../"===b.substr(0,3)){for(;"../"===b.substr(0,3);){if(!g.length)throw new Error(n);g.pop(),b=b.substring(3)}g.push(b),d=g.join(".")}else d=m?m+b:b.substring(1);else{for(e=b.split("."),f=e.pop(),i=e.length?"."+e.join("."):"",c=c.concat();c.length;)if(h=c.pop(),j=h+i,k=a.get(j),(l=a._wrapped[j])&&(k=l.get()),"object"==typeof k&&null!==k&&k.hasOwnProperty(f)){d=h+"."+b;break}d||void 0===a.get(b)||(d=b)}return d?d.replace(/^\./,""):d}}(),z=function(a){var b=Array.prototype.push;return function(c){for(var d,e,f;d=c._pendingResolution.pop();)e=a(c,d.ref,d.contextStack),void 0!==e?d.resolve(e):(f||(f=[])).push(d);f&&b.apply(c._pendingResolution,f)}}(y),A=function(a,b){return function(c){a(c),b(c)}}(o,p),B=function(){return function(a,b,c){var d,e,f,g,h,i,j;for(d=b.split("."),e=[],(f=a._wrapped[""])?(f.set&&f.set(d.join("."),c),g=f.get()):g=a.data;d.length>1;)h=e[e.length]=d.shift(),i=e.join("."),(f=a._wrapped[i])?(f.set&&f.set(d.join("."),c),g=f.get()):(g.hasOwnProperty(h)||(j||(j=i),g[h]=/^\s*[0-9]+\s*$/.test(d[0])?[]:{}),g=g[h]);return h=d[0],g[h]=c,j}}(),C=function(a,b,c,d,e,f,g,h,i){var j,k,l,m;return j=function(b,d,i){var j,m,n,o,p,q,r;if(m=[],a(b)&&(j=b,i=d),j)for(b in j)j.hasOwnProperty(b)&&(d=j[b],b=c(b),k(this,b,d,m));else b=c(b),k(this,b,d,m);if(m.length){if(o=this._transitionManager,this._transitionManager=p=g(this,i),n=l(m),n.length&&e.multiple(this,n,!0),e.multiple(this,m),this._pendingResolution.length&&f(this),h(this),this._transitionManager=o,p.ready(),!this.firingChangeEvent){for(this.firingChangeEvent=!0,r={},q=m.length;q--;)r[m[q]]=this.get(m[q]);this.fire("change",r),this.firingChangeEvent=!1}return this}},k=function(a,b,c,e){var f,g,h,j,k;if(!(h=a._wrapped[b])||!h.reset||m(a,b,c,h,e)===!1){if((k=a._evaluators[b])&&(k.value=c),f=a._cache[b],g=a.get(b),g===c||k){if(c===f&&"object"!=typeof c)return}else j=i(a,b,c);d(a,j||b),e[e.length]=b}},l=function(a){var b,c,d,e,f=[""];for(b=a.length;b--;)for(c=a[b],d=c.split(".");d.length>1;)d.pop(),e=d.join("."),f[e]||(f[f.length]=e,f[e]=!0);return f},m=function(a,c,e,f,g){var h,i,j,k;if(h=f.get(),!b(h,e)&&f.reset(e)===!1)return!1;if(e=f.get(),i=a._cache[c],!b(i,e)){if(a._cache[c]=e,j=a._cacheMap[c])for(k=j.length;k--;)d(a,j[k]);g[g.length]=c}},j}(w,x,i,m,r,z,q,A,B),D=function(a,b,c,d,e){return function(f,g){var h,i;return"function"==typeof f&&(g=f,f=""),i=this._transitionManager,this._transitionManager=h=a(this,g),b(this),c(this,f||""),d(this,f||""),e(this),this._transitionManager=i,h.ready(),"string"==typeof f?this.fire("update",f):this.fire("update"),this}}(q,z,m,r,A),E=function(a){return function(b,c){var d;if(!a(b)||!a(c))return!1;if(b.length!==c.length)return!1;for(d=b.length;d--;)if(b[d]!==c[d])return!1;return!0}}(l),F=function(a,b,c){function d(a,e,f,g,h){var i,j,k,l,m,n;if(i=a._twowayBindings[e])for(k=i.length;k--;)l=i[k],(!l.radioName||l.node.checked)&&(l.checkboxName?l.changed()&&!g[e]&&(g[e]=!0,g[g.length]=e):(m=l.attr.value,n=l.value(),b(m,n)||c(m,n)||(f[e]=n)));if(h&&(j=a._depsMap[e]))for(k=j.length;k--;)d(a,j[k],f,g,h)}return function(b,c){var e,f,g;if("string"!=typeof b&&(b="",c=!0),d(this,b,e={},f=[],c),g=f.length)for(;g--;)b=f[g],e[b]=a(this,b);this.set(e)}}(n,E,x),G=function(){return"undefined"!=typeof window?(function(a,b,c){var d,e;if(!c.requestAnimationFrame){for(d=0;d=this.duration?(null!==g&&this.root.set(g,this.to),this.step&&this.step(1,this.to),this.complete&&this.complete(1,this.to),f=this.root._animations.indexOf(this),-1===f&&a("Animation was not found"),this.root._animations.splice(f,1),this.running=!1,!1):(c=this.easing?this.easing(b/this.duration):b/this.duration,null!==g&&(d=this.interpolator(c),this.root.set(g,d)),this.step&&this.step(c,d),!0)):!1},stop:function(){var b;this.running=!1,b=this.root._animations.indexOf(this),-1===b&&a("Animation was not found"),this.root._animations.splice(b,1)}},c}(I,K),M=function(){return{linear:function(a){return a},easeIn:function(a){return Math.pow(a,3)},easeOut:function(a){return Math.pow(a-1,3)+1},easeInOut:function(a){return(a/=.5)<1?.5*Math.pow(a,3):.5*(Math.pow(a-2,3)+2)}}}(),N=function(a,b,c,d){function e(e,g,h,i){var j,k,l,m;return null!==g&&(m=e.get(g)),b.abort(g,e),a(m,h)?(i.complete&&i.complete(1,i.to),f):(i.easing&&(j="function"==typeof i.easing?i.easing:e.easing&&e.easing[i.easing]?e.easing[i.easing]:d[i.easing],"function"!=typeof j&&(j=null)),k=void 0===i.duration?400:i.duration,l=new c({keypath:g,from:m,to:h,root:e,duration:k,easing:j,step:i.step,complete:i.complete}),b.add(l),e._animations[e._animations.length]=l,l)}var f={stop:function(){}};return function(a,b,c){var d,f,g,h,i,j,k,l,m,n,o,p;if("object"==typeof a){c=b||{},h=c.easing,i=c.duration,g=[],j=c.step,k=c.complete,(j||k)&&(m={},c.step=null,c.complete=null,l=function(a){return function(b,c){m[a]=c}});for(d in a)a.hasOwnProperty(d)&&((j||k)&&(n=l(d),c={easing:h,duration:i},j&&(c.step=n),k&&(c.complete=n)),g[g.length]=e(this,d,a[d],c));return(j||k)&&(p={easing:h,duration:i},j&&(p.step=function(a){j(a,m)}),k&&(p.complete=function(a){k(a,m)}),g[g.length]=o=e(this,null,null,p)),{stop:function(){for(;g.length;)g.pop().stop();o&&o.stop()}}}return c=c||{},f=e(this,a,b,c),{stop:function(){f.stop()}}}}(x,H,L,M),O=function(){return function(a,b){var c,d,e=this;if("object"==typeof a){c=[];for(d in a)a.hasOwnProperty(d)&&(c[c.length]=this.on(d,a[d]));return{cancel:function(){for(;c.length;)c.pop().cancel()}}}return this._subs[a]?this._subs[a].push(b):this._subs[a]=[b],{cancel:function(){e.off(a,b)}}}}(),P=function(){return function(a,b){var c,d;if(!b)if(a)this._subs[a]=[];else for(a in this._subs)delete this._subs[a];c=this._subs[a],c&&(d=c.indexOf(b),-1!==d&&c.splice(d,1))}}(),Q=function(){return function(a){var b,c,d,e,f,g,h,i;if(g=a.root,h=a.keypath,i=a.priority,b=g._deps[i]||(g._deps[i]={}),c=b[h]||(b[h]=[]),c[c.length]=a,a.registered=!0,h)for(d=h.split(".");d.length;)d.pop(),e=d.join("."),f=g._depsMap[e]||(g._depsMap[e]=[]),void 0===f[h]&&(f[h]=0,f[f.length]=h),f[h]+=1,h=e}}(),R=function(){return function(a){var b,c,d,e,f,g,h,i;if(g=a.root,h=a.keypath,i=a.priority,b=g._deps[i][h],c=b.indexOf(a),-1===c||!a.registered)throw new Error("Attempted to remove a dependant that was no longer registered! This should not happen. If you are seeing this bug in development please raise an issue at https://github.com/RactiveJS/Ractive/issues - thanks");if(b.splice(c,1),a.registered=!1,h)for(d=h.split(".");d.length;)d.pop(),e=d.join("."),f=g._depsMap[e],f[h]-=1,f[h]||(f.splice(f.indexOf(h),1),f[h]=void 0),h=e}}(),S=function(a){var b=function(a,b,c,d){var e=this;this.root=a,this.keypath=b,this.callback=c,this.defer=d.defer,this.debug=d.debug,this.proxy={update:function(){e.reallyUpdate()}},this.priority=0,this.context=d&&d.context?d.context:a};return b.prototype={init:function(a){a!==!1?this.update():this.value=this.root.get(this.keypath)},update:function(){return this.defer&&this.ready?(this.root._deferred.observers.push(this.proxy),void 0):(this.reallyUpdate(),void 0)},reallyUpdate:function(){var b,c;if(b=this.value,c=this.root.get(this.keypath),this.value=c,!this.updating){if(this.updating=!0,!a(c,b)||!this.ready)try{this.callback.call(this.context,c,b,this.keypath)}catch(d){if(this.debug||this.root.debug)throw d}this.updating=!1}}},b}(x),T=function(){return function(a,b){var c,d,e,f,g,h,i;for(c=b.split("."),f=[],h=function(b){var c,d;c=a._wrapped[b]?a._wrapped[b].get():a.get(b);for(d in c)g.push(b+"."+d)},i=function(a){return a+"."+d};d=c.shift();)"*"===d?(g=[],f.forEach(h),f=g):f[0]?f=f.map(i):f[0]=d;return e={},f.forEach(function(b){e[b]=a.get(b)}),e}}(),U=function(a,b){var c,d=/\*/;return c=function(a,b,c,d){this.root=a,this.callback=c,this.defer=d.defer,this.debug=d.debug,this.keypath=b,this.regex=new RegExp("^"+b.replace(/\./g,"\\.").replace(/\*/g,"[^\\.]+")+"$"),this.values={},this.defer&&(this.proxies=[]),this.priority="pattern",this.context=d&&d.context?d.context:a},c.prototype={init:function(a){var c,d;if(c=b(this.root,this.keypath),a!==!1)for(d in c)c.hasOwnProperty(d)&&this.update(d);else this.values=c},update:function(a){var c;{if(!d.test(a))return this.defer&&this.ready?(this.root._deferred.observers.push(this.getProxy(a)),void 0):(this.reallyUpdate(a),void 0);c=b(this.root,a);for(a in c)c.hasOwnProperty(a)&&this.update(a)}},reallyUpdate:function(b){var c=this.root.get(b);if(this.updating)return this.values[b]=c,void 0;if(this.updating=!0,!a(c,this.values[b])||!this.ready){try{this.callback.call(this.context,c,this.values[b],b)}catch(d){if(this.debug||this.root.debug)throw d}this.values[b]=c}this.updating=!1},getProxy:function(a){var b=this;return this.proxies[a]||(this.proxies[a]={update:function(){b.reallyUpdate(a)}}),this.proxies[a]}},c}(x,T),V=function(a,b,c,d,e){var f=/\*/,g={};return function(h,i,j,k){var l,m;return i=a(i),k=k||g,f.test(i)?(l=new e(h,i,j,k),h._patternObservers.push(l),m=!0):l=new d(h,i,j,k),b(l),l.init(k.init),l.ready=!0,{cancel:function(){var a;m&&(a=h._patternObservers.indexOf(l),-1!==a&&h._patternObservers.splice(a,1)),c(l)}}}}(i,Q,R,S,U),W=function(a,b){return function(c,d,e){var f,g=[];if(a(c)){e=d;for(f in c)c.hasOwnProperty(f)&&(d=c[f],g[g.length]=b(this,f,d,e));return{cancel:function(){for(;g.length;)g.pop().cancel()}}}return b(this,c,d,e)}}(w,V),X=function(){return function(a){var b,c,d,e=this._subs[a];if(e)for(b=Array.prototype.slice.call(arguments,1),c=0,d=e.length;d>c;c+=1)e[c].apply(this,b)}}(),Y=function(){return function(a){return this.el?this.fragment.find(a):null}}(),Z=function(a,b){var c,d,e,f,g,h,i,j;if(a){for(c=b("div"),d=["matches","matchesSelector"],g=["o","ms","moz","webkit"],j=function(a){return function(b,c){return b[a](c)}},h=d.length;h--;){if(e=d[h],c[e])return j(e);for(i=g.length;i--;)if(f=g[h]+e.substr(0,1).toUpperCase()+e.substring(1),c[f])return j(f)}return function(a,b){var c,d;for(c=(a.parentNode||a.document).querySelectorAll(b),d=c.length;d--;)if(c[d]===a)return!0;return!1}}}(f,e),$=function(a){return function(b,c){var d=this._isComponentQuery?!this.selector||b.name===this.selector:a(b.node,this.selector);return d?(this.push(b.node||b.instance),c||this._makeDirty(),!0):void 0}}(Z),_=function(){return function(){var a,b,c;a=this._root[this._isComponentQuery?"liveComponentQueries":"liveQueries"],b=this.selector,c=a.indexOf(b),-1!==c&&(a.splice(c,1),a[b]=null)}}(),ab=function(){function a(a){var b;return(b=a.parentFragment)?b.owner:a.component&&(b=a.component.parentFragment)?b.owner:void 0}function b(b){var c,d;for(c=[b],d=a(b);d;)c.push(d),d=a(d);return c}return function(a,c){var d,e,f,g,h,i,j,k,l,m;for(d=b(a.component||a._ractive.proxy),e=b(c.component||c._ractive.proxy),f=d[d.length-1],g=e[e.length-1];f&&f===g;)d.pop(),e.pop(),h=f,f=d[d.length-1],g=e[e.length-1];if(f=f.component||f,g=g.component||g,l=f.parentFragment,m=g.parentFragment,l===m)return i=l.items.indexOf(f),j=m.items.indexOf(g),i-j||d.length-e.length;if(k=h.fragments)return i=k.indexOf(l),j=k.indexOf(m),i-j||d.length-e.length;throw new Error("An unexpected condition was met while comparing the position of two components. Please file an issue at https://github.com/RactiveJS/Ractive/issues - thanks!")}}(),bb=function(a){return function(b,c){var d;return b.compareDocumentPosition?(d=b.compareDocumentPosition(c),2&d?1:-1):a(b,c)}}(ab),cb=function(a,b){return function(){this.sort(this._isComponentQuery?b:a),this._dirty=!1}}(bb,ab),db=function(){return function(){this._dirty||(this._root._deferred.liveQueries.push(this),this._dirty=!0)}}(),eb=function(){return function(a){var b=this.indexOf(this._isComponentQuery?a.instance:a.node);-1!==b&&this.splice(b,1)}}(),fb=function(a,b,c,d,e,f){return function(g,h,i,j){var k;return k=[],a(k,{selector:{value:h},live:{value:i},_isComponentQuery:{value:j},_test:{value:b}}),i?(a(k,{cancel:{value:c},_root:{value:g},_sort:{value:d},_makeDirty:{value:e},_remove:{value:f},_dirty:{value:!1,writable:!0}}),k):k}}(h,$,_,cb,db,eb),gb=function(a,b,c,d){return function(a,b){var c,e;return this.el?(b=b||{},c=this._liveQueries,(e=c[a])?b&&b.live?e:e.slice():(e=d(this,a,!!b.live,!1),e.live&&(c.push(a),c[a]=e),this.fragment.findAll(a,e),e)):[]}}(I,Z,h,fb),hb=function(){return function(a){return this.fragment.findComponent(a)}}(),ib=function(a,b,c,d){return function(a,b){var c,e;return b=b||{},c=this._liveComponentQueries,(e=c[a])?b&&b.live?e:e.slice():(e=d(this,a,!!b.live,!0),e.live&&(c.push(a),c[a]=e),this.fragment.findAllComponents(a,e),e)}}(I,Z,h,fb),jb=function(){return function(a){var b;return"undefined"!=typeof window&&document&&a?a.nodeType?a:"string"==typeof a&&(b=document.getElementById(a),!b&&document.querySelector&&(b=document.querySelector(a)),b&&b.nodeType)?b:a[0]&&a[0].nodeType?a[0]:null:null}}(),kb=function(a,b){return function(c,d){var e,f,g,h,i;if(c.owner=d.owner,g=c.owner.parentFragment,c.root=d.root,c.pNode=d.pNode,c.contextStack=d.contextStack||[],c.owner.type===a.SECTION&&(c.index=d.index),g&&(h=g.indexRefs)){c.indexRefs=b(null);for(i in h)c.indexRefs[i]=h[i]}for(c.priority=g?g.priority+1:1,d.indexRef&&(c.indexRefs||(c.indexRefs={}),c.indexRefs[d.indexRef]=d.index),c.items=[],e=d.descriptor?d.descriptor.length:0,f=0;e>f;f+=1)c.items[c.items.length]=c.createItem({parentFragment:c,descriptor:d.descriptor[f],index:f})}}(k,c),lb=function(a){var b={};return function(c,d,e){var f,g=[];if(c)for(f=b[d]||(b[d]=a(d)),f.innerHTML=c;f.firstChild;)g[g.length]=f.firstChild,e.appendChild(f.firstChild);return g}}(e),mb=function(a){var b,c,d;return c=//g,b=function(b,c){this.type=a.TEXT,this.descriptor=b.descriptor,c&&(this.node=document.createTextNode(b.descriptor),c.appendChild(this.node))},b.prototype={detach:function(){return this.node.parentNode.removeChild(this.node),this.node},teardown:function(a){a&&this.detach()},firstNode:function(){return this.node},toString:function(){return(""+this.descriptor).replace(c,"<").replace(d,">")}},b}(k),nb=function(a){return function(b){if(b.keypath)a(b);else{var c=b.root._pendingResolution.indexOf(b);-1!==c&&b.root._pendingResolution.splice(c,1)}}}(R),ob=function(a,b,c,d,e){function f(a,b,d){var e,f,g;if(!h.test(a.toString()))return c(a,"_nowrap",{value:!0}),a;if(!a["_"+b._guid]){c(a,"_"+b._guid,{value:function(){var c,d,e,g;if(c=b._captured,c||(b._captured=[]),d=a.apply(b,arguments),b._captured.length)for(e=f.length;e--;)g=f[e],g.updateSoftDependencies(b._captured);return b._captured=c,d},writable:!0});for(e in a)a.hasOwnProperty(e)&&(a["_"+b._guid][e]=a[e]);a["_"+b._guid+"_evaluators"]=[]}return f=a["_"+b._guid+"_evaluators"],g=f.indexOf(d),-1===g&&f.push(d),a["_"+b._guid]}var g,h;return h=/this/,g=function(b,c,e,g,h){var i;this.evaluator=e,this.keypath=c,this.root=b,this.argNum=g,this.type=a.REFERENCE,this.priority=h,i=b.get(c),"function"==typeof i&&(i=f(i,b,e)),this.value=e.values[g]=i,d(this)},g.prototype={update:function(){var a=this.root.get(this.keypath);"function"!=typeof a||a._nowrap||(a=f(a,this.root,this.evaluator)),b(a,this.value)||(this.evaluator.values[this.argNum]=a,this.evaluator.bubble(),this.value=a)},teardown:function(){e(this)}},g}(k,x,g,Q,R),pb=function(a,b,c){var d=function(a,c,d){this.root=a,this.keypath=c,this.priority=d.priority,this.evaluator=d,b(this)};return d.prototype={update:function(){var b=this.root.get(this.keypath);a(b,this.value)||(this.evaluator.bubble(),this.value=b)},teardown:function(){c(this)}},d}(x,Q,R),qb=function(a,b,c,d,e,f,g,h,i){function j(a,b){var c,d;if(a=a.replace(/\$\{([0-9]+)\}/g,"_$1"),l[a])return l[a];for(d=[];b--;)d[b]="_"+b;return c=new Function(d.join(","),"return("+a+")"),l[a]=c,c}var k,l={};return k=function(a,b,c,d,e){var f,g;for(this.root=a,this.keypath=b,this.priority=e,this.fn=j(c,d.length),this.values=[],this.refs=[],f=d.length;f--;)(g=d[f])?g[0]?this.values[f]=g[1]:this.refs[this.refs.length]=new h(a,g[1],this,f,e):this.values[f]=void 0;this.selfUpdating=this.refs.length<=1,this.update()},k.prototype={bubble:function(){this.selfUpdating?this.update():this.deferred||(this.root._deferred.evals.push(this),this.deferred=!0)},update:function(){var b;if(this.evaluating)return this;this.evaluating=!0;try{b=this.fn.apply(null,this.values)}catch(e){if(this.root.debug)throw e;b=void 0}return a(b,this.value)||(c(this.root,this.keypath),this.root._cache[this.keypath]=b,g(this.root,this.keypath,b,!0),this.value=b,d(this.root,this.keypath)),this.evaluating=!1,this},teardown:function(){for(;this.refs.length;)this.refs.pop().teardown();c(this.root,this.keypath),this.root._evaluators[this.keypath]=null},refresh:function(){this.selfUpdating||(this.deferred=!0);for(var a=this.refs.length;a--;)this.refs[a].update();this.deferred&&(this.update(),this.deferred=!1)},updateSoftDependencies:function(a){var b,c,d;for(this.softRefs||(this.softRefs=[]),b=this.softRefs.length;b--;)d=this.softRefs[b],a[d.keypath]||(this.softRefs.splice(b,1),this.softRefs[d.keypath]=!1,d.teardown());for(b=a.length;b--;)c=a[b],this.softRefs[c]||(d=new i(this.root,c,this),this.softRefs[this.softRefs.length]=d,this.softRefs[c]=!0);this.selfUpdating=this.refs.length+this.softRefs.length<=1}},k}(x,g,m,r,Q,R,u,ob,pb),rb=function(a,b){var c=function(b,c,d,e){var f,g;g=this.root=b.root,f=a(g,c,d),void 0!==f?b.resolveRef(e,!1,f):(this.ref=c,this.argNum=e,this.resolver=b,this.contextStack=d,g._pendingResolution[g._pendingResolution.length]=this)};return c.prototype={resolve:function(a){this.keypath=a,this.resolver.resolveRef(this.argNum,!1,a)},teardown:function(){this.keypath||b(this)}},c}(y,nb),sb=function(){var a=/^(?:(?:[a-zA-Z$_][a-zA-Z$_0-9]*)|(?:[0-9]|[1-9][0-9]+))$/;return function(b){var c,d,e;for(c=b.split("."),e=c.length;e--;)if(d=c[e],"undefined"===d||!a.test(d))return!1;return!0}}(),tb=function(a,b){return function(c,d){var e,f;return e=c.replace(/\$\{([0-9]+)\}/g,function(a,b){return d[b]?d[b][1]:"undefined"}),f=a(e),b(f)?f:"${"+e.replace(/[\.\[\]]/g,"-")+"}"}}(i,sb),ub=function(a,b){function c(a,b,c){var e,f;if(e=a._depsMap[b])for(f=e.length;f--;)d(a,e[f],c)}function d(a,b,d){var e,f,g,h;for(e=a._deps.length;e--;)if(f=a._deps[e],f&&(g=f[b]))for(h=g.length;h--;)d.push(g[h]);c(a,b,d)}return function(c,e,f){var g,h,i;for(g=[],d(c,e,g),h=g.length;h--;)i=g[h],b(i),i.keypath=i.keypath.replace(e,f),a(i),i.update()}}(Q,R),vb=function(a,b,c,d){var e=function(a){var c,d,e,f,g;if(this.root=a.root,this.mustache=a,this.args=[],this.scouts=[],c=a.descriptor.x,g=a.parentFragment.indexRefs,this.str=c.s,e=this.unresolved=this.args.length=c.r?c.r.length:0,!e)return this.resolved=this.ready=!0,this.bubble(),void 0;for(d=0;e>d;d+=1)f=c.r[d],g&&void 0!==g[f]?this.resolveRef(d,!0,g[f]):this.scouts[this.scouts.length]=new b(this,f,a.contextStack,d);this.ready=!0,this.bubble()};return e.prototype={bubble:function(){var a;this.ready&&(a=this.keypath,this.keypath=c(this.str,this.args),"${"===this.keypath.substr(0,2)&&this.createEvaluator(),a?d(this.root,a,this.keypath):this.mustache.resolve(this.keypath))},teardown:function(){for(;this.scouts.length;)this.scouts.pop().teardown()},resolveRef:function(a,b,c){this.args[a]=[b,c],this.bubble(),this.resolved=!--this.unresolved},createEvaluator:function(){this.root._evaluators[this.keypath]?this.root._evaluators[this.keypath].refresh():this.root._evaluators[this.keypath]=new a(this.root,this.keypath,this.str,this.args,this.mustache.priority)}},e}(qb,rb,tb,ub),wb=function(a,b){return function(c,d){var e,f,g;g=c.parentFragment=d.parentFragment,c.root=g.root,c.contextStack=g.contextStack,c.descriptor=d.descriptor,c.index=d.index||0,c.priority=g.priority,c.type=d.descriptor.t,d.descriptor.r&&(g.indexRefs&&void 0!==g.indexRefs[d.descriptor.r]?(f=g.indexRefs[d.descriptor.r],c.indexRef=d.descriptor.r,c.value=f,c.render(c.value)):(e=a(c.root,d.descriptor.r,c.contextStack),void 0!==e?c.resolve(e):(c.ref=d.descriptor.r,c.root._pendingResolution[c.root._pendingResolution.length]=c))),d.descriptor.x&&(c.expressionResolver=new b(c)),c.descriptor.n&&!c.hasOwnProperty("value")&&c.render(void 0) -}}(y,vb),xb=function(a,b,c){return function(d){d!==this.keypath&&(this.registered&&c(this),this.keypath=d,b(this),this.update(),this.root.twoway&&this.parentFragment.owner.type===a.ATTRIBUTE&&this.parentFragment.owner.element.bind(),this.expressionResolver&&this.expressionResolver.resolved&&(this.expressionResolver=null))}}(k,Q,R),yb=function(a){return function(){var b,c;c=this.root.get(this.keypath),(b=this.root._wrapped[this.keypath])&&(c=b.get()),a(c,this.value)||(this.render(c),this.value=c)}}(x),zb=function(a,b,c,d,e){var f,g,h;return g=//g,f=function(b,d){this.type=a.INTERPOLATOR,d&&(this.node=document.createTextNode(""),d.appendChild(this.node)),c(this,b)},f.prototype={update:e,resolve:d,detach:function(){return this.node.parentNode.removeChild(this.node),this.node},teardown:function(a){a&&this.detach(),b(this)},render:function(a){this.node&&(this.node.data=void 0==a?"":a)},firstNode:function(){return this.node},toString:function(){var a=void 0!=this.value?""+this.value:"";return a.replace(g,"<").replace(h,">")}},f}(k,nb,wb,xb,yb),Ab=function(a,b,c){function d(a,b,c){var d,e,f;if(e=b.length,ea.length)for(d=a.length;e>d;d+=1)c.contextStack=a.contextStack.concat(a.keypath+"."+d),c.index=d,a.descriptor.i&&(c.indexRef=a.descriptor.i),a.fragments[d]=a.createFragment(c);a.length=e}function e(a,b,d){var e,f;f=a.fragmentsById||(a.fragmentsById=c(null));for(e in f)void 0===b[e]&&f[e]&&(f[e].teardown(!0),f[e]=null);for(e in b)void 0===b[e]||f[e]||(d.contextStack=a.contextStack.concat(a.keypath+"."+e),d.index=e,a.descriptor.i&&(d.indexRef=a.descriptor.i),f[e]=a.createFragment(d))}function f(a,b){a.length||(b.contextStack=a.contextStack.concat(a.keypath),b.index=0,a.fragments[0]=a.createFragment(b),a.length=1)}function g(b,c,d,e){var f,g,h,i;if(g=a(c)&&0===c.length,f=d?g||!c:c&&!g){if(b.length||(e.contextStack=b.contextStack,e.index=0,b.fragments[0]=b.createFragment(e),b.length=1),b.length>1)for(h=b.fragments.splice(1);i=h.pop();)i.teardown(!0)}else b.length&&(b.teardownFragments(!0),b.length=0)}return function(c,h){var i;return i={descriptor:c.descriptor.f,root:c.root,pNode:c.parentFragment.pNode,owner:c},c.descriptor.n?(g(c,h,!0,i),void 0):(a(h)?d(c,h,i):b(h)?c.descriptor.i?e(c,h,i):f(c,i):g(c,h,!1,i),void 0)}}(l,w,c),Bb=function(a,b,c){function d(b,c,g,h,i,j,k){var l,m,n,o;if(!b.html){for(b.indexRefs&&void 0!==b.indexRefs[c]&&(b.indexRefs[c]=h),l=b.contextStack.length;l--;)n=b.contextStack[l],n.substr(0,j.length)===j&&(b.contextStack[l]=n.replace(j,k));for(l=b.items.length;l--;)switch(m=b.items[l],m.type){case a.ELEMENT:e(m,c,g,h,i,j,k);break;case a.PARTIAL:d(m.fragment,c,g,h,i,j,k);break;case a.COMPONENT:d(m.instance.fragment,c,g,h,i,j,k),(o=b.root._liveComponentQueries[m.name])&&o._makeDirty();break;case a.SECTION:case a.INTERPOLATOR:case a.TRIPLE:f(m,c,g,h,i,j,k)}}}function e(a,b,c,e,f,g,h){var i,j,k,l,m,n,o,p,q,r;for(i=a.attributes.length;i--;)j=a.attributes[i],j.fragment&&(d(j.fragment,b,c,e,f,g,h),j.twoway&&j.updateBindings());if(k=a.node._ractive){k.keypath.substr(0,g.length)===g&&(k.keypath=k.keypath.replace(g,h)),void 0!==b&&(k.index[b]=e);for(l in k.events)for(m=k.events[l].proxies,i=m.length;i--;)n=m[i],"object"==typeof n.n&&d(n.a,b,c,e,f,g,h),n.d&&d(n.d,b,c,e,f,g,h);(o=k.binding)&&o.keypath.substr(0,g.length)===g&&(p=k.root._twowayBindings[o.keypath],p.splice(p.indexOf(o),1),o.keypath=o.keypath.replace(g,h),p=k.root._twowayBindings[o.keypath]||(k.root._twowayBindings[o.keypath]=[]),p.push(o))}if(a.fragment&&d(a.fragment,b,c,e,f,g,h),q=a.liveQueries)for(r=a.root,i=q.length;i--;)r._liveQueries[q[i]]._makeDirty()}function f(a,b,e,f,g,h,i){var j;if(a.descriptor.x&&(a.expressionResolver&&a.expressionResolver.teardown(),a.expressionResolver=new c(a)),a.keypath?a.keypath.substr(0,h.length)===h&&a.resolve(a.keypath.replace(h,i)):a.indexRef===b&&(a.value=f,a.render(f)),a.fragments)for(j=a.fragments.length;j--;)d(a.fragments[j],b,e,f,g,h,i)}return d}(k,R,vb),Cb=function(a,b,c){return function(a,d,e,f,g){var h,i,j,k,l,m,n;for(j=d.descriptor.i,h=e;f>h;h+=1)i=d.fragments[h],k=h-g,l=h,m=d.keypath+"."+(h-g),n=d.keypath+"."+h,i.index+=g,b(i,j,k,l,g,m,n);c(a)}}(k,Bb,o),Db=function(a){return function(b){var c,d,e,f,g,h,i,j,k,l,m=this;if(c=this.parentFragment,h=[],b.forEach(function(b,c){var f,g,j;return b===c?(h[b]=m.fragments[c],void 0):(void 0===d&&(d=c),-1===b?((i||(i=[])).push(m.fragments[c]),void 0):(f=b-c,g=m.keypath+"."+c,j=m.keypath+"."+b,a(m.fragments[c],m.descriptor.i,c,b,f,g,j),h[b]=m.fragments[c],e=!0,void 0))}),i)for(;k=i.pop();)k.teardown(!0);if(void 0===d&&(d=this.length),g=this.root.get(this.keypath).length,g!==d){for(j={descriptor:this.descriptor.f,root:this.root,pNode:c.pNode,owner:this},this.descriptor.i&&(j.indexRef=this.descriptor.i),f=d;g>f;f+=1)(k=h[f])?this.docFrag.appendChild(k.detach(!1)):(j.contextStack=this.contextStack.concat(this.keypath+"."+f),j.index=f,k=this.createFragment(j)),this.fragments[f]=k;l=c.findNextNode(this),c.pNode.insertBefore(this.docFrag,l),this.length=g}}}(Bb),Eb=function(){return[]}(),Fb=function(a,b,c,d,e,f,g,h,i,j,k){var l,m;return k.push(function(){m=k.DomFragment}),l=function(b,d){this.type=a.SECTION,this.inverted=!!b.descriptor.n,this.fragments=[],this.length=0,d&&(this.docFrag=document.createDocumentFragment()),this.initialising=!0,c(this,b),d&&d.appendChild(this.docFrag),this.initialising=!1},l.prototype={update:d,resolve:e,smartUpdate:function(a,b){var c;("push"===a||"unshift"===a||"splice"===a)&&(c={descriptor:this.descriptor.f,root:this.root,pNode:this.parentFragment.pNode,owner:this},this.descriptor.i&&(c.indexRef=this.descriptor.i)),this[a]&&(this.rendering=!0,this[a](c,b),this.rendering=!1)},pop:function(){this.length&&(this.fragments.pop().teardown(!0),this.length-=1)},push:function(a,b){var c,d,e;for(c=this.length,d=c+b.length,e=c;d>e;e+=1)a.contextStack=this.contextStack.concat(this.keypath+"."+e),a.index=e,this.fragments[e]=this.createFragment(a);this.length+=b.length,this.parentFragment.pNode.insertBefore(this.docFrag,this.parentFragment.findNextNode(this))},shift:function(){this.splice(null,[0,1])},unshift:function(a,b){this.splice(a,[0,0].concat(new Array(b.length)))},splice:function(a,b){var c,d,e,f,g,i,j,k,l;if(b.length&&(i=+(b[0]<0?this.length+b[0]:b[0]),d=Math.max(0,b.length-2),e=void 0!==b[1]?b[1]:this.length-i,e=Math.min(e,this.length-i),f=d-e)){if(0>f){for(j=i-f,g=i;j>g;g+=1)this.fragments[g].teardown(!0);this.fragments.splice(i,-f)}else{for(j=i+f,c=this.fragments[i]?this.fragments[i].firstNode():this.parentFragment.findNextNode(this),k=[i,0].concat(new Array(f)),this.fragments.splice.apply(this.fragments,k),g=i;j>g;g+=1)a.contextStack=this.contextStack.concat(this.keypath+"."+g),a.index=g,this.fragments[g]=this.createFragment(a);this.parentFragment.pNode.insertBefore(this.docFrag,c)}this.length+=f,l=i+d,h(this.root,this,l,this.length,f)}},merge:i,detach:function(){var a,b;for(b=this.fragments.length,a=0;b>a;a+=1)this.docFrag.appendChild(this.fragments[a].detach());return this.docFrag},teardown:function(a){this.teardownFragments(a),j(this)},firstNode:function(){return this.fragments[0]?this.fragments[0].firstNode():this.parentFragment.findNextNode(this)},findNextNode:function(a){return this.fragments[a.index+1]?this.fragments[a.index+1].firstNode():this.parentFragment.findNextNode(this)},teardownFragments:function(a){for(var b,c;c=this.fragments.shift();)c.teardown(a);if(this.fragmentsById)for(b in this.fragmentsById)this.fragments[b]&&(this.fragmentsById[b].teardown(a),this.fragmentsById[b]=null)},render:function(a){var c,d;(d=this.root._wrapped[this.keypath])&&(a=d.get()),this.rendering||(this.rendering=!0,f(this,a),this.rendering=!1,(!this.docFrag||this.docFrag.childNodes.length)&&!this.initialising&&b&&(c=this.parentFragment.findNextNode(this),c&&c.parentNode===this.parentFragment.pNode?this.parentFragment.pNode.insertBefore(this.docFrag,c):this.parentFragment.pNode.appendChild(this.docFrag)))},createFragment:function(a){var b=new m(a);return this.docFrag&&this.docFrag.appendChild(b.docFrag),b},toString:function(){var a,b,c,d;for(a="",b=0,d=this.length,b=0;d>b;b+=1)a+=this.fragments[b].toString();if(this.fragmentsById)for(c in this.fragmentsById)this.fragmentsById[c]&&(a+=this.fragmentsById[c].toString());return a},find:function(a){var b,c,d;for(c=this.fragments.length,b=0;c>b;b+=1)if(d=this.fragments[b].find(a))return d;return null},findAll:function(a,b){var c,d;for(d=this.fragments.length,c=0;d>c;c+=1)this.fragments[c].findAll(a,b)},findComponent:function(a){var b,c,d;for(c=this.fragments.length,b=0;c>b;b+=1)if(d=this.fragments[b].findComponent(a))return d;return null},findAllComponents:function(a,b){var c,d;for(d=this.fragments.length,c=0;d>c;c+=1)this.fragments[c].findAllComponents(a,b)}},l}(k,f,wb,yb,xb,Ab,Bb,Cb,Db,nb,Eb),Gb=function(a,b,c,d,e,f,g){var h=function(b,d){this.type=a.TRIPLE,d&&(this.nodes=[],this.docFrag=document.createDocumentFragment()),this.initialising=!0,c(this,b),d&&d.appendChild(this.docFrag),this.initialising=!1};return h.prototype={update:d,resolve:e,detach:function(){for(var a=this.nodes.length;a--;)this.docFrag.appendChild(this.nodes[a]);return this.docFrag},teardown:function(a){a&&(this.detach(),this.docFrag=this.nodes=null),g(this)},firstNode:function(){return this.nodes[0]?this.nodes[0]:this.parentFragment.findNextNode(this)},render:function(a){var b,c;if(this.nodes){for(;this.nodes.length;)b=this.nodes.pop(),b.parentNode.removeChild(b);if(!a)return this.nodes=[],void 0;c=this.parentFragment.pNode,this.nodes=f(a,c.tagName,this.docFrag),this.initialising||c.insertBefore(this.docFrag,this.parentFragment.findNextNode(this))}},toString:function(){return void 0!=this.value?this.value:""},find:function(a){var c,d,e,f;for(d=this.nodes.length,c=0;d>c;c+=1)if(e=this.nodes[c],1===e.nodeType){if(b(e,a))return e;if(f=e.querySelector(a))return f}return null},findAll:function(a,c){var d,e,f,g,h,i;for(e=this.nodes.length,d=0;e>d;d+=1)if(f=this.nodes[d],1===f.nodeType&&(b(f,a)&&c.push(f),g=f.querySelectorAll(a)))for(h=g.length,i=0;h>i;i+=1)c.push(g[i])}},h}(k,Z,wb,yb,xb,lb,nb),Hb=function(a){return function(b,c){return b.a&&b.a.xmlns?b.a.xmlns:"svg"===b.e?a.svg:c.namespaceURI||a.html}}(d),Ib=function(){var a,b,c,d;return a="altGlyph altGlyphDef altGlyphItem animateColor animateMotion animateTransform clipPath feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile feTurbulence foreignObject glyphRef linearGradient radialGradient textPath vkern".split(" "),b="attributeName attributeType baseFrequency baseProfile calcMode clipPathUnits contentScriptType contentStyleType diffuseConstant edgeMode externalResourcesRequired filterRes filterUnits glyphRef gradientTransform gradientUnits kernelMatrix kernelUnitLength keyPoints keySplines keyTimes lengthAdjust limitingConeAngle markerHeight markerUnits markerWidth maskContentUnits maskUnits numOctaves pathLength patternContentUnits patternTransform patternUnits pointsAtX pointsAtY pointsAtZ preserveAlpha preserveAspectRatio primitiveUnits refX refY repeatCount repeatDur requiredExtensions requiredFeatures specularConstant specularExponent spreadMethod startOffset stdDeviation stitchTiles surfaceScale systemLanguage tableValues targetX targetY textLength viewBox viewTarget xChannelSelector yChannelSelector zoomAndPan".split(" "),c=function(a){for(var b={},c=a.length;c--;)b[a[c].toLowerCase()]=a[c];return b},d=c(a.concat(b)),function(a){var b=a.toLowerCase();return d[b]||b}}(),Jb=function(a,b){return function(c,d){var e,f;if(e=d.indexOf(":"),-1===e||(f=d.substr(0,e),"xmlns"===f))c.name=c.element.namespace!==a.html?b(d):d,c.lcName=c.name.toLowerCase();else if(d=d.substring(e+1),c.name=b(d),c.lcName=c.name.toLowerCase(),c.namespace=a[f.toLowerCase()],!c.namespace)throw'Unknown namespace ("'+f+'")'}}(d,Ib),Kb=function(a){return function(b,c){var d,e=null===c.value?"":c.value;(d=c.pNode)&&(b.namespace?d.setAttributeNS(b.namespace,c.name,e):"style"===c.name&&d.style.setAttribute?d.style.setAttribute("cssText",e):"class"!==c.name||d.namespaceURI&&d.namespaceURI!==a.html?d.setAttribute(c.name,e):d.className=e,"id"===b.name&&(c.root.nodes[c.value]=d),"value"===b.name&&(d._ractive.value=c.value)),b.value=c.value}}(d),Lb=function(a){var b={"accept-charset":"acceptCharset",accesskey:"accessKey",bgcolor:"bgColor","class":"className",codebase:"codeBase",colspan:"colSpan",contenteditable:"contentEditable",datetime:"dateTime",dirname:"dirName","for":"htmlFor","http-equiv":"httpEquiv",ismap:"isMap",maxlength:"maxLength",novalidate:"noValidate",pubdate:"pubDate",readonly:"readOnly",rowspan:"rowSpan",tabindex:"tabIndex",usemap:"useMap"};return function(c,d){var e;!c.pNode||c.namespace||d.pNode.namespaceURI&&d.pNode.namespaceURI!==a.html||(e=b[c.name]||c.name,void 0!==d.pNode[e]&&(c.propertyName=e),("boolean"==typeof d.pNode[e]||"value"===e)&&(c.useProperty=!0))}}(d),Mb=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q,r;return e=function(){var a,b,c,d=this.pNode;return this.fragment?(a=f(this))?(this.interpolator=a,this.keypath=a.keypath||a.descriptor.r,(b=i(this))?(d._ractive.binding=this.element.binding=b,this.twoway=!0,c=this.root._twowayBindings[this.keypath]||(this.root._twowayBindings[this.keypath]=[]),c[c.length]=b,!0):!1):!1:!1},g=function(){this._ractive.binding.update()},h=function(){var a=this._ractive.root.get(this._ractive.binding.keypath);this.value=void 0==a?"":a},f=function(c){var d,e;return 1!==c.fragment.items.length?null:(d=c.fragment.items[0],d.type!==a.INTERPOLATOR?null:d.keypath||d.ref?d.keypath&&"${"===d.keypath.substr(0,2)?(e="You cannot set up two-way binding against an expression "+d.keypath,c.root.debug&&b(e),null):d:null)},i=function(a){var c=a.pNode;if("SELECT"===c.tagName)return c.multiple?new k(a,c):new l(a,c);if("checkbox"===c.type||"radio"===c.type){if("name"===a.propertyName){if("checkbox"===c.type)return new n(a,c);if("radio"===c.type)return new m(a,c)}return"checked"===a.propertyName?new o(a,c):null}return"value"!==a.lcName&&b("This is... odd"),"file"===c.type?new p(a,c):c.getAttribute("contenteditable")?new q(a,c):new r(a,c)},k=function(a,b){var c;j(this,a,b),b.addEventListener("change",g,!1),c=this.root.get(this.keypath),void 0===c&&this.update()},k.prototype={value:function(){var a,b,c,d;for(a=[],b=this.node.options,d=b.length,c=0;d>c;c+=1)b[c].selected&&(a[a.length]=b[c]._ractive.value);return a},update:function(){var a,b,d;return a=this.attr,b=a.value,d=this.value(),void 0!==b&&c(d,b)||(a.receiving=!0,a.value=d,this.root.set(this.keypath,d),a.receiving=!1),this},deferUpdate:function(){this.deferred!==!0&&(this.root._deferred.attrs.push(this),this.deferred=!0)},teardown:function(){this.node.removeEventListener("change",g,!1)}},l=function(a,b){var c;j(this,a,b),b.addEventListener("change",g,!1),c=this.root.get(this.keypath),void 0===c&&this.update()},l.prototype={value:function(){var a,b,c;for(a=this.node.options,c=a.length,b=0;c>b;b+=1)if(a[b].selected)return a[b]._ractive.value},update:function(){var a=this.value();return this.attr.receiving=!0,this.attr.value=a,this.root.set(this.keypath,a),this.attr.receiving=!1,this},deferUpdate:function(){this.deferred!==!0&&(this.root._deferred.attrs.push(this),this.deferred=!0)},teardown:function(){this.node.removeEventListener("change",g,!1)}},m=function(a,b){var c;this.radioName=!0,j(this,a,b),b.name="{{"+a.keypath+"}}",b.addEventListener("change",g,!1),b.attachEvent&&b.addEventListener("click",g,!1),c=this.root.get(this.keypath),void 0!==c?b.checked=c==b._ractive.value:this.root._deferred.radios.push(this)},m.prototype={value:function(){return this.node._ractive?this.node._ractive.value:this.node.value},update:function(){var a=this.node;a.checked&&(this.attr.receiving=!0,this.root.set(this.keypath,this.value()),this.attr.receiving=!1)},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("click",g,!1)}},n=function(a,b){var c,d;this.checkboxName=!0,j(this,a,b),b.name="{{"+this.keypath+"}}",b.addEventListener("change",g,!1),b.attachEvent&&b.addEventListener("click",g,!1),c=this.root.get(this.keypath),void 0!==c?(d=-1!==c.indexOf(b._ractive.value),b.checked=d):-1===this.root._deferred.checkboxes.indexOf(this.keypath)&&this.root._deferred.checkboxes.push(this.keypath)},n.prototype={changed:function(){return this.node.checked!==!!this.checked},update:function(){this.checked=this.node.checked,this.attr.receiving=!0,this.root.set(this.keypath,d(this.root,this.keypath)),this.attr.receiving=!1},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("click",g,!1)}},o=function(a,b){j(this,a,b),b.addEventListener("change",g,!1),b.attachEvent&&b.addEventListener("click",g,!1)},o.prototype={value:function(){return this.node.checked},update:function(){this.attr.receiving=!0,this.root.set(this.keypath,this.value()),this.attr.receiving=!1},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("click",g,!1)}},p=function(a,b){j(this,a,b),b.addEventListener("change",g,!1)},p.prototype={value:function(){return this.attr.pNode.files},update:function(){this.attr.root.set(this.attr.keypath,this.value())},teardown:function(){this.node.removeEventListener("change",g,!1)}},q=function(a,b){j(this,a,b),b.addEventListener("change",g,!1),this.root.lazy||(b.addEventListener("input",g,!1),b.attachEvent&&b.addEventListener("keyup",g,!1))},q.prototype={update:function(){this.attr.receiving=!0,this.root.set(this.keypath,this.node.innerHTML),this.attr.receiving=!1},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("input",g,!1),this.node.removeEventListener("keyup",g,!1)}},r=function(a,b){j(this,a,b),b.addEventListener("change",g,!1),this.root.lazy||(b.addEventListener("input",g,!1),b.attachEvent&&b.addEventListener("keyup",g,!1)),this.node.addEventListener("blur",h,!1)},r.prototype={value:function(){var a=this.attr.pNode.value;return+a+""===a&&-1===a.indexOf("e")&&(a=+a),a},update:function(){var a=this.attr,b=this.value();a.receiving=!0,a.root.set(a.keypath,b),a.receiving=!1},teardown:function(){this.node.removeEventListener("change",g,!1),this.node.removeEventListener("input",g,!1),this.node.removeEventListener("keyup",g,!1),this.node.removeEventListener("blur",h,!1)}},j=function(a,b,c){a.attr=b,a.node=c,a.root=b.root,a.keypath=b.keypath},e}(k,I,E,n),Nb=function(a,b){var c,d,e,f,g,h,i,j,k,l,m,n;return c=function(){var a;if(!this.ready)return this;if(a=this.pNode,"SELECT"===a.tagName&&"value"===this.lcName)return this.update=e,this.deferredUpdate=f,this.update();if(this.isFileInputValue)return this.update=d,this;if(this.twoway&&"name"===this.lcName){if("radio"===a.type)return this.update=i,this.update();if("checkbox"===a.type)return this.update=j,this.update()}return"style"===this.lcName&&a.style.setAttribute?(this.update=k,this.update()):"class"!==this.lcName||a.namespaceURI&&a.namespaceURI!==b.html?a.getAttribute("contenteditable")&&"value"===this.lcName?(this.update=m,this.update()):(this.update=n,this.update()):(this.update=l,this.update())},d=function(){return this},f=function(){this.deferredUpdate=this.pNode.multiple?h:g,this.deferredUpdate()},e=function(){return this.root._deferred.selectValues.push(this),this},g=function(){var a,b,c,d=this.fragment.getValue();for(this.value=this.pNode._ractive.value=d,a=this.pNode.options,c=a.length;c--;)if(b=a[c],b._ractive.value==d)return b.selected=!0,this;return this},h=function(){var b,c,d=this.fragment.getValue();for(a(d)||(d=[d]),b=this.pNode.options,c=b.length;c--;)b[c].selected=-1!==d.indexOf(b[c]._ractive.value);return this.value=d,this},i=function(){var a,b;return a=this.pNode,b=this.fragment.getValue(),a.checked=b==a._ractive.value,this},j=function(){var b,c;return b=this.pNode,c=this.fragment.getValue(),a(c)?(b.checked=-1!==c.indexOf(b._ractive.value),this):(b.checked=c==b._ractive.value,this)},k=function(){var a,b;return a=this.pNode,b=this.fragment.getValue(),void 0===b&&(b=""),b!==this.value&&(a.style.setAttribute("cssText",b),this.value=b),this},l=function(){var a,b;return a=this.pNode,b=this.fragment.getValue(),void 0===b&&(b=""),b!==this.value&&(a.className=b,this.value=b),this},m=function(){var a,b;return a=this.pNode,b=this.fragment.getValue(),void 0===b&&(b=""),b!==this.value&&(this.receiving||(a.innerHTML=b),this.value=b),this},n=function(){var a,b;if(a=this.pNode,b=this.fragment.getValue(),this.isValueAttribute&&(a._ractive.value=b),void 0===b&&(b=""),b!==this.value){if(this.useProperty)return this.receiving||(a[this.propertyName]=b),this.value=b,this;if(this.namespace)return a.setAttributeNS(this.namespace,this.name,b),this.value=b,this;"id"===this.lcName&&(void 0!==this.value&&(this.root.nodes[this.value]=void 0),this.root.nodes[b]=a),a.setAttribute(this.name,b),this.value=b}return this},c}(l,d),Ob=function(){return function(a){var b;return b=this.str.substr(this.pos,a.length),b===a?(this.pos+=a.length,a):null}}(),Pb=function(){var a=/^\s+/;return function(){var b=a.exec(this.remaining());return b?(this.pos+=b[0].length,b[0]):null}}(),Qb=function(){return function(a){return function(b){var c=a.exec(b.str.substring(b.pos));return c?(b.pos+=c[0].length,c[1]||c[0]):null}}}(),Rb=function(){function a(a){var b;return a.getStringMatch("\\")?(b=a.str.charAt(a.pos),a.pos+=1,b):null}return function(b){var c,d="";for(c=a(b);c;)d+=c,c=a(b);return d||null}}(),Sb=function(a,b){var c=a(/^[^\\"]+/),d=a(/^[^\\']+/);return function e(a,f){var g,h,i,j,k,l;if(g=a.pos,h="",l=f?d:c,i=b(a),i&&(h+=i),j=l(a),j&&(h+=j),!h)return"";for(k=e(a,f);""!==k;)h+=k;return h}}(Qb,Rb),Tb=function(a,b){return function(c){var d,e;return d=c.pos,c.getStringMatch('"')?(e=b(c,!1),c.getStringMatch('"')?{t:a.STRING_LITERAL,v:e}:(c.pos=d,null)):c.getStringMatch("'")?(e=b(c,!0),c.getStringMatch("'")?{t:a.STRING_LITERAL,v:e}:(c.pos=d,null)):null}}(k,Sb),Ub=function(a,b){var c=b(/^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/);return function(b){var d;return(d=c(b))?{t:a.NUMBER_LITERAL,v:d}:null}}(k,Qb),Vb=function(a){return a(/^[a-zA-Z_$][a-zA-Z_$0-9]*/)}(Qb),Wb=function(a,b,c){var d=/^[a-zA-Z_$][a-zA-Z_$0-9]*$/;return function(e){var f;return(f=a(e))?d.test(f.v)?f.v:'"'+f.v.replace(/"/g,'\\"')+'"':(f=b(e))?f.v:(f=c(e))?f:void 0}}(Tb,Ub,Vb),Xb=function(a,b,c,d){function e(a){var b,c,e;return a.allowWhitespace(),(b=d(a))?(e={key:b},a.allowWhitespace(),a.getStringMatch(":")?(a.allowWhitespace(),(c=a.getToken())?(e.value=c.v,e):null):null):null}var f,g,h,i,j,k;return g={"true":!0,"false":!1,undefined:void 0,"null":null},h=new RegExp("^(?:"+Object.keys(g).join("|")+")"),i=/^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/,j=/\$\{([^\}]+)\}/g,k=/^\$\{([^\}]+)\}/,f=function(a,b){this.str=a,this.values=b,this.pos=0,this.result=this.getToken()},f.prototype={remaining:function(){return this.str.substring(this.pos)},getStringMatch:a,getToken:function(){return this.allowWhitespace(),this.getPlaceholder()||this.getSpecial()||this.getNumber()||this.getString()||this.getObject()||this.getArray()},getPlaceholder:function(){var a;return this.values?(a=k.exec(this.remaining()))&&this.values.hasOwnProperty(a[1])?(this.pos+=a[0].length,{v:this.values[a[1]]}):void 0:null},getSpecial:function(){var a;return(a=h.exec(this.remaining()))?(this.pos+=a[0].length,{v:g[a[0]]}):void 0},getNumber:function(){var a;return(a=i.exec(this.remaining()))?(this.pos+=a[0].length,{v:+a[0]}):void 0},getString:function(){var a,b=c(this);return b&&(a=this.values)?{v:b.v.replace(j,function(b,c){return a[c]||c})}:b},getObject:function(){var a,b;if(!this.getStringMatch("{"))return null;for(a={};b=e(this);){if(a[b.key]=b.value,this.allowWhitespace(),this.getStringMatch("}"))return{v:a};if(!this.getStringMatch(","))return null}return null},getArray:function(){var a,b;if(!this.getStringMatch("["))return null;for(a=[];b=this.getToken();){if(a.push(b.v),this.getStringMatch("]"))return{v:a};if(!this.getStringMatch(","))return null}return null},allowWhitespace:b},function(a,b){var c=new f(a,b);return c.result?{value:c.result.v,remaining:c.remaining()}:null}}(Ob,Pb,Tb,Wb),Yb=function(a,b,c,d,e){function f(a){return"string"==typeof a?a:JSON.stringify(a)}var g=function(b){this.type=a.INTERPOLATOR,c(this,b)};return g.prototype={update:d,resolve:e,render:function(a){this.value=a,this.parentFragment.bubble()},teardown:function(){b(this)},toString:function(){return void 0==this.value?"":f(this.value)}},g}(k,nb,wb,yb,xb),Zb=function(a,b,c,d,e,f,g){var h,i;return g.push(function(){i=g.StringFragment}),h=function(c){this.type=a.SECTION,this.fragments=[],this.length=0,b(this,c)},h.prototype={update:c,resolve:d,teardown:function(){this.teardownFragments(),f(this)},teardownFragments:function(){for(;this.fragments.length;)this.fragments.shift().teardown();this.length=0},bubble:function(){this.value=this.fragments.join(""),this.parentFragment.bubble()},render:function(a){var b;(b=this.root._wrapped[this.keypath])&&(a=b.get()),e(this,a),this.parentFragment.bubble()},createFragment:function(a){return new i(a)},toString:function(){return this.fragments.join("")}},h}(k,wb,yb,xb,Ab,nb,Eb),$b=function(a){var b=function(b){this.type=a.TEXT,this.text=b};return b.prototype={toString:function(){return this.text},teardown:function(){}},b}(k),_b=function(a,b){return function(){var c,d,e,f,g,h,i;if(!this.argsList||this.dirty){if(c={},d=0,f=this.root._guid,i=function(a){return a.map(function(a){var b,e,g;return a.text?a.text:a.fragments?a.fragments.map(function(a){return i(a.items)}).join(""):(b=f+"-"+d++,g=(e=a.root._wrapped[a.keypath])?e.value:a.value,c[b]=g,"${"+b+"}")}).join("")},e=i(this.items),h=b("["+e+"]",c))this.argsList=h.value;else{if(g="Could not parse directive arguments ("+this.toString()+"). If you think this is a bug, please file an issue at http://github.com/RactiveJS/Ractive/issues",this.root.debug)throw new Error(g);a(g),this.argsList=[e]}this.dirty=!1}return this.argsList}}(I,Xb),ac=function(a,b,c,d,e,f,g,h){var i=function(a){c(this,a)};return i.prototype={createItem:function(b){if("string"==typeof b.descriptor)return new f(b.descriptor);switch(b.descriptor.t){case a.INTERPOLATOR:return new d(b);case a.TRIPLE:return new d(b);case a.SECTION:return new e(b);default:throw"Something went wrong in a rather interesting way"}},bubble:function(){this.dirty=!0,this.owner.bubble()},teardown:function(){var a,b;for(a=this.items.length,b=0;a>b;b+=1)this.items[b].teardown()},getValue:function(){var b;return 1===this.items.length&&this.items[0].type===a.INTERPOLATOR&&(b=this.items[0].value,void 0!==b)?b:this.toString()},isSimple:function(){var b,c,d;if(void 0!==this.simple)return this.simple;for(b=this.items.length;b--;)if(c=this.items[b],c.type!==a.TEXT){if(c.type!==a.INTERPOLATOR)return this.simple=!1;if(d)return!1;d=!0}return this.simple=!0},toString:function(){return this.items.join("")},toJSON:function(){var a,c=this.getValue();return"string"==typeof c&&(a=b(c),c=a?a.value:c),c},toArgsList:g},h.StringFragment=i,i}(k,Xb,kb,Yb,Zb,$b,_b,Eb),bc=function(a,b,c,d,e,f,g){var h=function(e){return this.type=a.ATTRIBUTE,this.element=e.element,b(this,e.name),null===e.value||"string"==typeof e.value?(c(this,e),void 0):(this.root=e.root,this.pNode=e.pNode,this.parentFragment=this.element.parentFragment,this.fragment=new g({descriptor:e.value,root:this.root,owner:this,contextStack:e.contextStack}),this.pNode&&("value"===this.name&&(this.isValueAttribute=!0,"INPUT"===this.pNode.tagName&&"file"===this.pNode.type&&(this.isFileInputValue=!0)),d(this,e),this.selfUpdating=this.fragment.isSimple(),this.ready=!0),void 0)};return h.prototype={bind:e,update:f,updateBindings:function(){this.keypath=this.interpolator.keypath||this.interpolator.ref,"name"===this.propertyName&&(this.pNode.name="{{"+this.keypath+"}}")},teardown:function(){var a;if(this.boundEvents)for(a=this.boundEvents.length;a--;)this.pNode.removeEventListener(this.boundEvents[a],this.updateModel,!1);this.fragment&&this.fragment.teardown()},bubble:function(){this.selfUpdating?this.update():!this.deferred&&this.ready&&(this.root._deferred.attrs.push(this),this.deferred=!0)},toString:function(){var a;return null===this.value?this.name:this.fragment?(a=this.fragment.toString(),this.name+"="+JSON.stringify(a)):this.name+"="+JSON.stringify(this.value)}},h}(k,Jb,Kb,Lb,Mb,Nb,ac),cc=function(a){return function(b,c){var d,e,f;b.attributes=[];for(d in c)c.hasOwnProperty(d)&&(e=c[d],f=new a({element:b,name:d,value:e,root:b.root,pNode:b.node,contextStack:b.parentFragment.contextStack}),b.attributes[b.attributes.length]=b.attributes[d]=f,"name"!==d&&f.update());return b.attributes}}(bc),dc=function(a,b,c,d){var e,f,g;return d.push(function(){e=d.DomFragment}),f=function(){var a=this.node,b=this.fragment.toString();a.styleSheet&&(a.styleSheet.cssText=b),a.innerHTML=b},g=function(){this.node.type&&"text/javascript"!==this.node.type||a("Script tag was updated. This does not cause the code to be re-evaluated!"),this.node.innerHTML=this.fragment.toString()},function(a,d,h,i){var j,k,l,m,n;if("script"===a.lcName||"style"===a.lcName)return a.fragment=new c({descriptor:h.f,root:a.root,contextStack:a.parentFragment.contextStack,owner:a}),i&&("script"===a.lcName?(a.bubble=g,a.node.innerHTML=a.fragment.toString()):(a.bubble=f,a.bubble())),void 0;if("string"!=typeof h.f||d&&d.namespaceURI&&d.namespaceURI!==b.html)a.fragment=new e({descriptor:h.f,root:a.root,pNode:d,contextStack:a.parentFragment.contextStack,owner:a}),i&&d.appendChild(a.fragment.docFrag);else if(a.html=h.f,i)for(d.innerHTML=a.html,j=a.root._liveQueries,k=j.length;k--;)if(l=j[k],(m=d.querySelectorAll(l))&&(n=m.length))for((a.liveQueries||(a.liveQueries=[])).push(l),a.liveQueries[l]=[];n--;)a.liveQueries[l][n]=m[n]}}(I,d,ac,Eb),ec=function(a,b){var c=function(c,d,e,f){var g,h,i;if(this.root=d,this.node=e.node,g=c.n||c,"string"!=typeof g&&(h=new b({descriptor:g,root:this.root,owner:e,contextStack:f}),g=h.toString(),h.teardown()),c.a?this.params=c.a:c.d&&(h=new b({descriptor:c.d,root:this.root,owner:e,contextStack:f}),this.params=h.toArgsList(),h.teardown()),this.fn=d.decorators[g],!this.fn){if(i='Missing "'+g+'" decorator. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#decorators',d.debug)throw new Error(i);a(i)}};return c.prototype={init:function(){var a,b;if(this.params?(b=[this.node].concat(this.params),a=this.fn.apply(this.root,b)):a=this.fn.call(this.root,this.node),!a||!a.teardown)throw new Error("Decorator definition must return an object with a teardown method");this.teardown=a.teardown}},c}(I,ac),fc=function(a){return function(b,c,d,e){d.decorator=new a(b,c,d,e),d.decorator.fn&&c._deferred.decorators.push(d.decorator)}}(ec),gc=function(a,b){var c,d,e,f,g,h,i,j,k;return c=function(a,b,c,e,f){var g,h;g=a.node._ractive.events,h=g[b]||(g[b]=new d(a,b,e,f)),h.add(c)},d=function(b,c,d){var e;this.element=b,this.root=b.root,this.node=b.node,this.name=c,this.contextStack=d,this.proxies=[],(e=this.root.events[c])?this.custom=e(this.node,k(c)):("on"+c in this.node||a('Missing "'+this.name+'" event. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#events'),this.node.addEventListener(c,j,!1))},d.prototype={add:function(a){this.proxies[this.proxies.length]=new e(this.element,this.root,a,this.contextStack)},teardown:function(){var a;for(this.custom?this.custom.teardown():this.node.removeEventListener(this.name,j,!1),a=this.proxies.length;a--;)this.proxies[a].teardown()},fire:function(a){for(var b=this.proxies.length;b--;)this.proxies[b].fire(a)}},e=function(a,c,d,e){var i;return this.root=c,i=d.n||d,this.n="string"==typeof i?i:new b({descriptor:d.n,root:this.root,owner:a,contextStack:e}),d.a?(this.a=d.a,this.fire=g,void 0):d.d?(this.d=new b({descriptor:d.d,root:this.root,owner:a,contextStack:e}),this.fire=h,void 0):(this.fire=f,void 0) -},e.prototype={teardown:function(){this.n.teardown&&this.n.teardown(),this.d&&this.d.teardown()},bubble:function(){}},f=function(a){this.root.fire(this.n.toString(),a)},g=function(a){this.root.fire.apply(this.root,[this.n.toString(),a].concat(this.a))},h=function(a){var b=this.d.toArgsList();"string"==typeof b&&(b=b.substr(1,b.length-2)),this.root.fire.apply(this.root,[this.n.toString(),a].concat(b))},j=function(a){var b=this._ractive;b.events[a.type].fire({node:this,original:a,index:b.index,keypath:b.keypath,context:b.root.get(b.keypath)})},i={},k=function(a){return i[a]?i[a]:i[a]=function(b){var c=b.node._ractive;b.index=c.index,b.keypath=c.keypath,b.context=c.root.get(c.keypath),c.events[a].fire(b)}},c}(I,ac),hc=function(a){return function(b,c){var d,e,f;for(e in c)if(c.hasOwnProperty(e))for(f=e.split("-"),d=f.length;d--;)a(b,f[d],c[e],b.parentFragment.contextStack)}}(gc),ic=function(){return function(a){var b,c,d,e,f;for(b=a.root,c=b._liveQueries,d=c.length;d--;)e=c[d],f=c[e],f._test(a)&&((a.liveQueries||(a.liveQueries=[])).push(e),a.liveQueries[e]=[a.node])}}(),jc=function(){return function(a){return a.replace(/-([a-zA-Z])/g,function(a,b){return b.toUpperCase()})}}(),kc=function(){return function(a,b){var c;for(c in b)b.hasOwnProperty(c)&&!a.hasOwnProperty(c)&&(a[c]=b[c]);return a}}(),lc=function(a,b,c,d,e,f,g,h){function i(a){var b,c,d;if(!q[a])if(void 0!==m[a])q[a]=a;else for(d=a.charAt(0).toUpperCase()+a.substring(1),b=n.length;b--;)if(c=n[b],void 0!==m[c+d]){q[a]=c+d;break}return q[a]}function j(a){return a.replace(p,"")}function k(a){var b;return o.test(a)&&(a="-"+a),b=a.replace(/[A-Z]/g,function(a){return"-"+a.toLowerCase()})}var l,m,n,o,p,q,r,s,t,u,v,w;if(a)return m=b("div").style,function(){void 0!==m.transition?(s="transition",w="transitionend",r=!0):void 0!==m.webkitTransition?(s="webkitTransition",w="webkitTransitionEnd",r=!0):r=!1}(),s&&(t=s+"Duration",u=s+"Property",v=s+"TimingFunction"),l=function(a,b,d,e,f){var g,i,j,k=this;if(this.root=b,this.node=d.node,this.isIntro=f,this.originalStyle=this.node.getAttribute("style"),this.complete=function(a){!a&&k.isIntro&&k.resetStyle(),k._manager.pop(k.node),k.node._ractive.transition=null},g=a.n||a,"string"!=typeof g&&(i=new h({descriptor:g,root:this.root,owner:d,contextStack:e}),g=i.toString(),i.teardown()),this.name=g,a.a?this.params=a.a:a.d&&(i=new h({descriptor:a.d,root:this.root,owner:d,contextStack:e}),this.params=i.toArgsList(),i.teardown()),this._fn=b.transitions[g],!this._fn){if(j='Missing "'+g+'" transition. You may need to download a plugin via https://github.com/RactiveJS/Ractive/wiki/Plugins#transitions',b.debug)throw new Error(j);return c(j),void 0}},l.prototype={init:function(){if(this._inited)throw new Error("Cannot initialize a transition more than once");this._inited=!0,this._fn.apply(this.root,[this].concat(this.params))},getStyle:function(a){var b,c,d,f,g;if(b=window.getComputedStyle(this.node),"string"==typeof a)return g=b[i(a)],"0px"===g&&(g=0),g;if(!e(a))throw new Error("Transition#getStyle must be passed a string, or an array of strings representing CSS properties");for(c={},d=a.length;d--;)f=a[d],g=b[i(f)],"0px"===g&&(g=0),c[f]=g;return c},setStyle:function(a,b){var c;if("string"==typeof a)this.node.style[i(a)]=b;else for(c in a)a.hasOwnProperty(c)&&(this.node.style[i(c)]=a[c]);return this},animateStyle:function(a,b,d,e){var g,h,l,m,n,o,p,q,r,s=this;for("string"==typeof a?(n={},n[a]=b):(n=a,e=d,d=b),d||(c('The "'+s.name+'" transition does not supply an options object to `t.animateStyle()`. This will break in a future version of Ractive. For more info see https://github.com/RactiveJS/Ractive/issues/340'),d=s,e=s.complete),d.duration||(s.setStyle(n),e&&e()),g=Object.keys(n),h=[],l=window.getComputedStyle(s.node),o={},q=g.length;q--;)r=g[q],m=l[i(r)],"0px"===m&&(m=0),m!=n[r]&&(h[h.length]=r,s.node.style[i(r)]=m);return h.length?(setTimeout(function(){s.node.style[u]=g.map(i).map(k).join(","),s.node.style[v]=k(d.easing||"linear"),s.node.style[t]=d.duration/1e3+"s",p=function(a){var b;b=h.indexOf(f(j(a.propertyName))),-1!==b&&h.splice(b,1),h.length||(s.root.fire(s.name+":end"),s.node.removeEventListener(w,p,!1),e&&e())},s.node.addEventListener(w,p,!1),setTimeout(function(){for(var a=h.length;a--;)r=h[a],s.node.style[i(r)]=n[r]},0)},d.delay||0),void 0):(e&&e(),void 0)},resetStyle:function(){this.originalStyle?this.node.setAttribute("style",this.originalStyle):(this.node.getAttribute("style"),this.node.removeAttribute("style"))},processParams:function(a,b){return"number"==typeof a?a={duration:a}:"string"==typeof a?a="slow"===a?{duration:600}:"fast"===a?{duration:200}:{duration:400}:a||(a={}),g(a,b)}},n=["o","ms","moz","webkit"],o=new RegExp("^(?:"+n.join("|")+")([A-Z])"),p=new RegExp("^-(?:"+n.join("|")+")-"),q={},l}(f,e,I,J,l,jc,kc,ac),mc=function(a,b){return function(a,c,d,e,f){var g,h,i;!c.transitionsEnabled||c._parent&&!c._parent.transitionsEnabled||(g=new b(a,c,d,e,f),g._fn&&(h=g.node,g._manager=c._transitionManager,(i=h._ractive.transition)&&i.complete(),h._ractive.transition=g,g._manager.push(h),f?c._deferred.transitions.push(g):g.init()))}}(I,lc),nc=function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o){return function(e,p,q){var r,s,t,u,v,w,x,y,z,A,B,C,D;if(e.type=a.ELEMENT,r=e.parentFragment=p.parentFragment,s=r.pNode,t=r.contextStack,u=e.descriptor=p.descriptor,e.root=B=r.root,e.index=p.index,e.lcName=u.e.toLowerCase(),e.eventListeners=[],e.customEventListeners=[],s&&(v=e.namespace=h(u,s),w=v!==b.html?o(u.e):u.e,e.node=g(w,v),d(e.node,"_ractive",{value:{proxy:e,keypath:t.length?t[t.length-1]:"",index:r.indexRefs,events:c(null),root:B}})),x=i(e,u.a),u.f){if(e.node&&e.node.getAttribute("contenteditable")&&e.node.innerHTML){if(D="A pre-populated contenteditable element should not have children",B.debug)throw new Error(D);f(D)}j(e,e.node,u,q)}q&&u.v&&l(e,u.v),q&&(B.twoway&&(e.bind(),e.node.getAttribute("contenteditable")&&e.node._ractive.binding&&e.node._ractive.binding.update()),x.name&&!x.name.twoway&&x.name.update(),"IMG"===e.node.tagName&&((y=e.attributes.width)||(z=e.attributes.height))&&e.node.addEventListener("load",A=function(){y&&(e.node.width=y.value),z&&(e.node.height=z.value),e.node.removeEventListener("load",A,!1)},!1),q.appendChild(e.node),u.o&&k(u.o,B,e,t),u.t1&&n(u.t1,B,e,t,!0),"OPTION"===e.node.tagName&&("SELECT"===s.tagName&&(C=s._ractive.binding)&&C.deferUpdate(),e.node._ractive.value==s._ractive.value&&(e.node.selected=!0)),e.node.autofocus&&(B._deferred.focusable=e.node)),m(e)}}(k,d,c,g,Z,I,e,Hb,cc,dc,fc,hc,ic,mc,Ib),oc=function(a){return function(b){var c,d,e,f,g,h,i,j,k;for(this.fragment&&this.fragment.teardown(!1);this.attributes.length;)this.attributes.pop().teardown();if(this.node){for(c in this.node._ractive.events)this.node._ractive.events[c].teardown();(d=this.node._ractive.binding)&&(d.teardown(),e=this.root._twowayBindings[d.attr.keypath],e.splice(e.indexOf(d),1))}if(this.decorator&&this.decorator.teardown(),this.descriptor.t2&&a(this.descriptor.t2,this.root,this,this.parentFragment.contextStack,!1),b&&this.root._transitionManager.detachWhenReady(this),g=this.liveQueries)for(f=g.length;f--;)if(h=g[f],j=this.liveQueries[h])for(k=j.length,i=this.root._liveQueries[h];k--;)i._remove(j[k])}}(mc),pc=function(){return"area base br col command doctype embed hr img input keygen link meta param source track wbr".split(" ")}(),qc=function(a){return function(){var b,c,d;for(b="<"+(this.descriptor.y?"!doctype":this.descriptor.e),d=this.attributes.length,c=0;d>c;c+=1)b+=" "+this.attributes[c].toString();return b+=">",this.html?b+=this.html:this.fragment&&(b+=this.fragment.toString()),-1===a.indexOf(this.descriptor.e)&&(b+=""+this.descriptor.e+">"),b}}(pc),rc=function(a){return function(b){var c;return a(this.node,b)?this.node:this.html&&(c=this.node.querySelector(b))?c:this.fragment&&this.fragment.find?this.fragment.find(b):void 0}}(Z),sc=function(){return function(a,b){var c,d,e,f,g;if(b._test(this,!0)&&b.live&&((this.liveQueries||(this.liveQueries=[])).push(a),this.liveQueries[a]=[this.node]),this.html&&(c=this.node.querySelectorAll(a))&&(e=c.length))for(b.live&&(this.liveQueries[a]||((this.liveQueries||(this.liveQueries=[])).push(a),this.liveQueries[a]=[]),g=this.liveQueries[a]),d=0;e>d;d+=1)f=c[d],b.push(f),b.live&&g.push(f);this.fragment&&this.fragment.findAll(a,b)}}(),tc=function(){return function(a){return this.fragment?this.fragment.findComponent(a):void 0}}(),uc=function(){return function(a,b){this.fragment&&this.fragment.findAllComponents(a,b)}}(),vc=function(){return function(){var a=this.attributes;if(this.node&&(this.binding&&(this.binding.teardown(),this.binding=null),!(this.node.getAttribute("contenteditable")&&a.value&&a.value.bind())))switch(this.descriptor.e){case"select":case"textarea":return a.value&&a.value.bind(),void 0;case"input":if("radio"===this.node.type||"checkbox"===this.node.type){if(a.name&&a.name.bind())return;if(a.checked&&a.checked.bind())return}if(a.value&&a.value.bind())return}}}(),wc=function(a,b,c,d,e,f,g,h){var i=function(b,c){a(this,b,c)};return i.prototype={detach:function(){return this.node?(this.node.parentNode&&this.node.parentNode.removeChild(this.node),this.node):void 0},teardown:b,firstNode:function(){return this.node},findNextNode:function(){return null},bubble:function(){},toString:c,find:d,findAll:e,findComponent:f,findAllComponents:g,bind:h},i}(nc,oc,qc,rc,sc,tc,uc,vc),xc={missingParser:"Missing Ractive.parse - cannot parse template. Either preparse or use the version that includes the parser"},yc={},zc=function(a,b,c,d,e,f){var g,h,i,j;return g=function(d,g){var k,l,m;if(l=i(d,g))return l;if(b&&(k=document.getElementById(g),k&&"SCRIPT"===k.tagName)){if(!f)throw new Error(a.missingParser);h(f(k.innerHTML),g,e)}if(l=e[g],!l){if(m='Could not find descriptor for partial "'+g+'"',d.debug)throw new Error(m);return c(m),[]}return j(l)},i=function(b,c){var d;if(b.partials[c]){if("string"==typeof b.partials[c]){if(!f)throw new Error(a.missingParser);d=f(b.partials[c],b.parseOptions),h(d,c,b.partials)}return j(b.partials[c])}},h=function(a,b,c){var e;if(d(a)){c[b]=a.main;for(e in a.partials)a.partials.hasOwnProperty(e)&&(c[e]=a.partials[e])}else c[b]=a},j=function(a){return 1===a.length&&"string"==typeof a[0]?a[0]:a},g}(xc,f,I,w,yc,parse__parse),Ac=function(a,b,c){var d,e;return c.push(function(){e=c.DomFragment}),d=function(c,d){var f,g=this.parentFragment=c.parentFragment;if(this.type=a.PARTIAL,this.name=c.descriptor.r,this.index=c.index,!c.descriptor.r)throw new Error("Partials must have a static reference (no expressions). This may change in a future version of Ractive.");f=b(g.root,c.descriptor.r),this.fragment=new e({descriptor:f,root:g.root,pNode:g.pNode,contextStack:g.contextStack,owner:this}),d&&d.appendChild(this.fragment.docFrag)},d.prototype={firstNode:function(){return this.fragment.firstNode()},findNextNode:function(){return this.parentFragment.findNextNode(this)},detach:function(){return this.fragment.detach()},teardown:function(a){this.fragment.teardown(a)},toString:function(){return this.fragment.toString()},find:function(a){return this.fragment.find(a)},findAll:function(a,b){return this.fragment.findAll(a,b)},findComponent:function(a){return this.fragment.findComponent(a)},findAllComponents:function(a,b){return this.fragment.findAllComponents(a,b)}},d}(k,zc,Eb),Bc=function(a){var b=function(b,c,d){this.parentFragment=b.parentFragment,this.component=b,this.key=c,this.fragment=new a({descriptor:d,root:b.root,owner:this,contextStack:b.parentFragment.contextStack}),this.selfUpdating=this.fragment.isSimple(),this.value=this.fragment.getValue()};return b.prototype={bubble:function(){this.selfUpdating?this.update():!this.deferred&&this.ready&&(this.root._deferred.attrs.push(this),this.deferred=!0)},update:function(){var a=this.fragment.getValue();this.component.instance.set(this.key,a),this.value=a},teardown:function(){this.fragment.teardown()}},b}(ac),Cc=function(a,b,c,d){function e(e,f,g,h){var i,j,k,l,m;return k=e.root,l=e.parentFragment,"string"==typeof g?(j=b(g),j?j.value:g):null===g?!0:1===g.length&&g[0].t===a.INTERPOLATOR&&g[0].r?l.indexRefs&&void 0!==l.indexRefs[g[0].r]?l.indexRefs[g[0].r]:(m=c(k,g[0].r,l.contextStack)||g[0].r,h.push({childKeypath:f,parentKeypath:m}),k.get(m)):(i=new d(e,f,g),e.complexParameters.push(i),i.value)}return function(a,b,c){var d,f,g;d={},a.complexParameters=[];for(f in b)b.hasOwnProperty(f)&&(g=e(a,f,b[f],c),void 0!==g&&(d[f]=g));return d}}(k,Xb,y,Bc),Dc=function(){return function(a,b,c,d,e){var f,g,h,i;return g=a.parentFragment,i=a.root,h={content:e||[]},f=new b({el:g.pNode.cloneNode(!1),data:c,partials:h,_parent:i,adaptors:i.adaptors}),f.component=a,a.instance=f,f.insert(d),f.fragment.pNode=g.pNode,f}}(),Ec=function(){function a(a,c,d){var e,f,g,h,i,j,k;e=a.root,f=a.instance,i=a.observers,j=e.observe(c,function(a){g||e._wrapped[c]||(h=!0,f.set(d,a),h=!1)},b),i.push(j),f.twoway&&(j=f.observe(d,function(a){h||(g=!0,e.set(c,a),g=!1)},b),i.push(j),k=f.get(d),void 0!==k&&e.set(c,k))}var b={init:!1,debug:!0};return function(b,c){var d,e;for(b.observers=[],e=c.length;e--;)d=c[e],a(b,d.parentKeypath,d.childKeypath)}}(),Fc=function(a){function b(b,d,e,f){if("string"!=typeof f){if(d.debug)throw new Error(c);return a(c),void 0}b.on(e,function(){var a=Array.prototype.slice.call(arguments);a.unshift(f),d.fire.apply(d,a)})}var c="Components currently only support simple events - you cannot include arguments. Sorry!";return function(a,c){var d;for(d in c)c.hasOwnProperty(d)&&b(a.instance,a.root,d,c[d])}}(I),Gc=function(){return function(a){var b,c;for(b=a.root;b;)(c=b._liveComponentQueries[a.name])&&c.push(a.instance),b=b._parent}}(),Hc=function(a,b,c,d,e,f,g){return function(h,i,j){var k,l,m,n,o;if(k=h.parentFragment=i.parentFragment,l=k.root,h.root=l,h.type=a.COMPONENT,h.name=i.descriptor.e,h.index=i.index,h.observers=[],m=l.components[i.descriptor.e],!m)throw new Error('Component "'+i.descriptor.e+'" not found');o=[],n=c(h,i.descriptor.a,o),d(h,m,n,j,i.descriptor.f),e(h,o),f(h,i.descriptor.v),(i.descriptor.t1||i.descriptor.t2||i.descriptor.o)&&b('The "intro", "outro" and "decorator" directives have no effect on components'),g(h)}}(k,I,Cc,Dc,Ec,Fc,Gc),Ic=function(a){var b=function(b,c){a(this,b,c)};return b.prototype={firstNode:function(){return this.instance.fragment.firstNode()},findNextNode:function(){return this.parentFragment.findNextNode(this)},detach:function(){return this.instance.fragment.detach()},teardown:function(){for(var a;this.complexParameters.length;)this.complexParameters.pop().teardown();for(;this.observers.length;)this.observers.pop().cancel();(a=this.root._liveComponentQueries[this.name])&&a._remove(this),this.instance.teardown()},toString:function(){return this.instance.fragment.toString()},find:function(a){return this.instance.fragment.find(a)},findAll:function(a,b){return this.instance.fragment.findAll(a,b)},findComponent:function(a){return a&&a!==this.name?null:this.instance},findAllComponents:function(a,b){b._test(this,!0),this.instance.fragment&&this.instance.fragment.findAllComponents(a,b)}},b}(Hc),Jc=function(a){var b=function(b,c){this.type=a.COMMENT,this.descriptor=b.descriptor,c&&(this.node=document.createComment(b.descriptor.f),c.appendChild(this.node))};return b.prototype={detach:function(){return this.node.parentNode.removeChild(this.node),this.node},teardown:function(a){a&&this.detach()},firstNode:function(){return this.node},toString:function(){return""}},b}(k),Kc=function(a,b,c,d,e,f,g,h,i,j,k,l,m){var n=function(a){a.pNode&&(this.docFrag=document.createDocumentFragment()),"string"==typeof a.descriptor?(this.html=a.descriptor,this.docFrag&&(this.nodes=d(this.html,a.pNode.tagName,this.docFrag))):c(this,a)};return n.prototype={detach:function(){var a,b;if(this.nodes)for(b=this.nodes.length;b--;)this.docFrag.appendChild(this.nodes[b]);else if(this.items)for(a=this.items.length,b=0;a>b;b+=1)this.docFrag.appendChild(this.items[b].detach());return this.docFrag},createItem:function(b){if("string"==typeof b.descriptor)return new e(b,this.docFrag);switch(b.descriptor.t){case a.INTERPOLATOR:return new f(b,this.docFrag);case a.SECTION:return new g(b,this.docFrag);case a.TRIPLE:return new h(b,this.docFrag);case a.ELEMENT:return this.root.components[b.descriptor.e]?new k(b,this.docFrag):new i(b,this.docFrag);case a.PARTIAL:return new j(b,this.docFrag);case a.COMMENT:return new l(b,this.docFrag);default:throw new Error("Something very strange happened. Please file an issue at https://github.com/RactiveJS/Ractive/issues. Thanks!")}},teardown:function(a){var b;if(this.nodes&&a)for(;b=this.nodes.pop();)b.parentNode.removeChild(b);else if(this.items)for(;this.items.length;)this.items.pop().teardown(a);this.nodes=this.items=this.docFrag=null},firstNode:function(){return this.items&&this.items[0]?this.items[0].firstNode():this.nodes?this.nodes[0]||null:null},findNextNode:function(a){var b=a.index;return this.items[b+1]?this.items[b+1].firstNode():this.owner===this.root?this.owner.component?this.owner.component.findNextNode():null:this.owner.findNextNode(this)},toString:function(){var a,b,c,d;if(this.html)return this.html;if(a="",!this.items)return a;for(c=this.items.length,b=0;c>b;b+=1)d=this.items[b],a+=d.toString();return a},find:function(a){var c,d,e,f,g;if(this.nodes){for(d=this.nodes.length,c=0;d>c;c+=1)if(f=this.nodes[c],1===f.nodeType){if(b(f,a))return f;if(g=f.querySelector(a))return g}return null}if(this.items){for(d=this.items.length,c=0;d>c;c+=1)if(e=this.items[c],e.find&&(g=e.find(a)))return g;return null}},findAll:function(a,c){var d,e,f,g,h,i,j;if(this.nodes){for(e=this.nodes.length,d=0;e>d;d+=1)if(g=this.nodes[d],1===g.nodeType&&(b(g,a)&&c.push(g),h=g.querySelectorAll(a)))for(i=h.length,j=0;i>j;j+=1)c.push(h[j])}else if(this.items)for(e=this.items.length,d=0;e>d;d+=1)f=this.items[d],f.findAll&&f.findAll(a,c);return c},findComponent:function(a){var b,c,d,e;if(this.items){for(b=this.items.length,c=0;b>c;c+=1)if(d=this.items[c],d.findComponent&&(e=d.findComponent(a)))return e;return null}},findAllComponents:function(a,b){var c,d,e;if(this.items)for(d=this.items.length,c=0;d>c;c+=1)e=this.items[c],e.findAllComponents&&e.findAllComponents(a,b);return b}},m.DomFragment=n,n}(k,Z,kb,lb,mb,zb,Fb,Gb,wc,Ac,Ic,Jc,Eb),Lc=function(a,b,c,d,e){return function(a,f){var g;if(!this._initing)throw new Error("You cannot call ractive.render() directly!");this._transitionManager=g=b(this,f),this.fragment=new e({descriptor:this.template,root:this,owner:this,pNode:a}),c(this),a&&a.appendChild(this.fragment.docFrag),d(this),this._transitionManager=null,g.ready(),this.rendered=!0}}(jb,q,o,p,Kc),Mc=function(a){return function(){return a("renderHTML() has been deprecated and will be removed in a future version. Please use toHTML() instead"),this.toHTML()}}(I),Nc=function(){return function(){return this.fragment.toString()}}(),Oc=function(a,b){return function(c){var d,e,f;for(this.fire("teardown"),f=this._transitionManager,this._transitionManager=e=a(this,c),this.fragment.teardown(!0);this._animations[0];)this._animations[0].stop();for(d in this._cache)b(this,d);this._transitionManager=f,e.ready()}}(q,m),Pc=function(a){return function(b,c,d){var e;if("string"==typeof c&&a(d)){if(e=b.get(c),void 0===e&&(e=0),a(e))b.set(c,e+d);else if(b.debug)throw new Error("Cannot add to a non-numeric value")}else if(b.debug)throw new Error("Bad arguments")}}(J),Qc=function(a){return function(b,c){a(this,b,void 0===c?1:c)}}(Pc),Rc=function(a){return function(b,c){a(this,b,void 0===c?-1:-c)}}(Pc),Sc=function(){return function(a){var b;if("string"==typeof a)b=this.get(a),this.set(a,!b);else if(this.debug)throw new Error("Bad arguments")}}(),Tc=function(){return function(a,b){var c,d,e,f,g;return c={},e=0,d=function(a,d){var f,h,i;h=e,i=b.length;do{if(f=b.indexOf(a,h),-1===f)return g=!0,-1;h=f+1}while(c[f]&&i>h);return f===e&&(e+=1),f!==d&&(g=!0),c[f]=!0,f},f=a.map(d),f.unchanged=!g,f}}(),Uc=function(a){return function(b,c,d,e){var f,g;for(f=c.length;f--;)g=c[f],g.type===a.REFERENCE?g.update():g.keypath===b&&g.type===a.SECTION&&!g.inverted&&g.docFrag?d[d.length]=g:e[e.length]=g}}(k),Vc=function(a,b,c,d,e,f,g,h,i,j){function k(a){return JSON.stringify(a)}function l(a){return m[a]||(m[a]=function(b){return b[a]}),m[a]}var m={};return function(m,n,o){var p,q,r,s,t,u,v,w,x,y,z,A,B,C,D;if(p=this.get(m),!b(p)||!b(n))return this.set(m,n,o&&o.complete);if(t=p.length===n.length,o&&o.compare){if(o.compare===!0)s=k;else if("string"==typeof o.compare)s=l(o.compare);else{if("function"!=typeof o.compare)throw new Error("The `compare` option must be a function, or a string representing an identifying field (or `true` to use JSON.stringify)");s=o.compare}try{q=p.map(s),r=n.map(s)}catch(E){if(this.debug)throw E;a("Merge operation: comparison failed. Falling back to identity checking"),q=p,r=n}}else q=p,r=n;if(v=i(q,r),c(this,m),h(this,m,n),!v.unchanged||!t){for(B=this._transitionManager,this._transitionManager=A=f(this,o&&o.complete),w=[],x=[],u=0;u', + footer: '<%= outro %>' + } + }, + banner: { + files: [{ + expand: true, + cwd: 'tmp/', + src: '*.js', + dest: 'build/' + }], + options: { + process: true, + banner: '<%= banner %>' + } + } +}; diff --git a/grunt/config/copy.js b/grunt/config/copy.js new file mode 100644 index 0000000000..370e542a65 --- /dev/null +++ b/grunt/config/copy.js @@ -0,0 +1,14 @@ +module.exports = { + release: { + files: [{ + expand: true, + cwd: 'build/', + src: [ '**/*' ], + dest: 'release/<%= pkg.version %>/' + }] + }, + link: { + src: 'build/ractive.js', + dest: 'ractive.js' + } +}; diff --git a/grunt/config/jsbeautifier.js b/grunt/config/jsbeautifier.js new file mode 100644 index 0000000000..066a28ac8f --- /dev/null +++ b/grunt/config/jsbeautifier.js @@ -0,0 +1,10 @@ +module.exports = { + files: 'tmp/**/*.js', + options: { + js: { + indentWithTabs: true, + spaceBeforeConditional: true, + spaceInParen: true + } + } +}; diff --git a/grunt/config/jshint.js b/grunt/config/jshint.js new file mode 100644 index 0000000000..8cb0486e00 --- /dev/null +++ b/grunt/config/jshint.js @@ -0,0 +1,27 @@ +module.exports = { + files: [ 'src/**/*.js' ], + options: { + boss: true, + eqnull: true, + evil: true, + laxbreak: true, + proto: true, + smarttabs: true, + strict: true, + undef: true, + unused: true, + '-W018': true, + '-W041': false, + globals: { + clearInterval: true, + define: true, + document: true, + Element: true, + module: true, + require: true, + setInterval: true, + setTimeout: true, + window: true + } + } +}; diff --git a/grunt/config/nodeunit.js b/grunt/config/nodeunit.js new file mode 100644 index 0000000000..60528a64cd --- /dev/null +++ b/grunt/config/nodeunit.js @@ -0,0 +1,15 @@ +module.exports = function ( grunt ) { + + 'use strict'; + + var nodeunitConfig = {}; + + grunt.file.expand( 'test/node/*.js' ).forEach( function ( path ) { + var testName = /test\/node\/(.+)\.js/.exec( path )[1]; + + nodeunitConfig[ testName ] = path; + }); + + return nodeunitConfig; + +}; diff --git a/grunt/config/qunit.js b/grunt/config/qunit.js new file mode 100644 index 0000000000..e185010168 --- /dev/null +++ b/grunt/config/qunit.js @@ -0,0 +1,19 @@ +module.exports = function ( grunt ) { + + 'use strict'; + + var qunitConfig = {}; + + grunt.file.expand( 'test/tests/*.html' ).forEach( function ( path ) { + var testName = /test\/tests\/(.+)\.html/.exec( path )[1]; + + if ( testName === 'index' ) { + testName = 'all'; + } + + qunitConfig[ testName ] = path; + }); + + return qunitConfig; + +}; \ No newline at end of file diff --git a/grunt/config/requirejs.js b/grunt/config/requirejs.js new file mode 100644 index 0000000000..b1bf1c8e10 --- /dev/null +++ b/grunt/config/requirejs.js @@ -0,0 +1,45 @@ +module.exports = { + full: { + options: { + out: 'tmp/ractive.js', + paths: { + 'legacy': 'empty/legacy' + } + } + }, + legacy: { + options: { + out: 'tmp/ractive-legacy.js' + } + }, + runtime: { + options: { + out: 'tmp/ractive.runtime.js', + paths: { + 'parse/_parse': 'empty/parse', + 'legacy': 'empty/legacy' + } + } + }, + runtime_legacy: { + options: { + out: 'tmp/ractive-legacy.runtime.js', + paths: { + 'parse/_parse': 'empty/parse' + } + } + }, + options: { + baseUrl: 'src/', + name: 'Ractive', + optimize: 'none', + logLevel: 2, + onBuildWrite: function( name, path, contents ) { + var moduleNames = {}; + + return require( 'amdclean' ).clean({ + code: contents + }) + '\n'; + } + } +}; diff --git a/grunt/config/uglify.js b/grunt/config/uglify.js new file mode 100644 index 0000000000..9aa4a5335c --- /dev/null +++ b/grunt/config/uglify.js @@ -0,0 +1,6 @@ +module.exports = { + 'tmp/ractive.min.js': 'tmp/ractive.js', + 'tmp/ractive-legacy.min.js': 'tmp/ractive-legacy.js', + 'tmp/ractive.runtime.min.js': 'tmp/ractive.runtime.js', + 'tmp/ractive-legacy.runtime.min.js': 'tmp/ractive-legacy.runtime.js' +}; diff --git a/grunt/config/watch.js b/grunt/config/watch.js new file mode 100644 index 0000000000..09451932e9 --- /dev/null +++ b/grunt/config/watch.js @@ -0,0 +1,10 @@ +module.exports = { + js: { + files: [ 'src/**/*.js', 'wrapper/**/*.js' ], + tasks: [ 'clean:tmp', 'requirejs' ], + options: { + interrupt: true, + force: true + } + } +}; \ No newline at end of file diff --git a/grunt/tasks/build.js b/grunt/tasks/build.js new file mode 100644 index 0000000000..c068dbe95c --- /dev/null +++ b/grunt/tasks/build.js @@ -0,0 +1,14 @@ +module.exports = function ( grunt ) { + + 'use strict'; + + grunt.registerTask( 'build', [ + 'jshint', + 'clean:tmp', + 'requirejs', + 'concat:closure', + 'revision', + 'jsbeautifier' + ]); + +}; diff --git a/grunt/tasks/default.js b/grunt/tasks/default.js new file mode 100644 index 0000000000..30054a2faf --- /dev/null +++ b/grunt/tasks/default.js @@ -0,0 +1,12 @@ +module.exports = function ( grunt ) { + + 'use strict'; + + grunt.registerTask( 'default', [ + 'build', + 'test', + 'uglify', + 'concat:banner' + ]); + +}; diff --git a/grunt/tasks/promises-aplus-tests.js b/grunt/tasks/promises-aplus-tests.js new file mode 100644 index 0000000000..598f158262 --- /dev/null +++ b/grunt/tasks/promises-aplus-tests.js @@ -0,0 +1,16 @@ +module.exports = function ( grunt ) { + + 'use strict'; + + grunt.registerTask( 'promises-aplus-tests', 'Run the Promises/A+ test suite.', function () { + var promisesAplusTests, adaptor, done; + + promisesAplusTests = require( 'promises-aplus-tests' ); + adaptor = require( '../../test/promises-aplus-adaptor' ); + + done = this.async(); + + promisesAplusTests( adaptor, { reporter: 'dot' }, done ); + }); + +}; \ No newline at end of file diff --git a/grunt/tasks/release.js b/grunt/tasks/release.js new file mode 100644 index 0000000000..15e6c571ed --- /dev/null +++ b/grunt/tasks/release.js @@ -0,0 +1,7 @@ +module.exports = function ( grunt ) { + + 'use strict'; + + grunt.registerTask( 'release', [ 'default', 'copy:release', 'copy:link' ] ); + +}; \ No newline at end of file diff --git a/grunt/tasks/revision.js b/grunt/tasks/revision.js new file mode 100644 index 0000000000..2522483515 --- /dev/null +++ b/grunt/tasks/revision.js @@ -0,0 +1,19 @@ +module.exports = function ( grunt ) { + + 'use strict'; + + grunt.registerTask( 'revision', 'Set revision to grunt config pkg.version', function () { + var done = this.async(); + + require( 'child_process' ).exec( 'git rev-parse HEAD', function ( err, commitHash ) { + if ( err ) { + done( err ); + return; + } + + grunt.config( 'commitHash', commitHash ); + done(); + }); + }); + +}; diff --git a/grunt/tasks/test.js b/grunt/tasks/test.js new file mode 100644 index 0000000000..944acc50ef --- /dev/null +++ b/grunt/tasks/test.js @@ -0,0 +1,10 @@ +module.exports = function ( grunt ) { + + 'use strict'; + + grunt.registerTask( 'test', [ + 'nodeunit', + 'qunit:all' + ]); + +}; diff --git a/package.json b/package.json index 95fbb6adb7..edc33570b2 100755 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "ractive", "description": "Next-generation DOM manipulation", - "version": "0.3.9", + "version": "0.4.0", "homepage": "http://ractivejs.org", - "main": "build/Ractive.js", + "main": "ractive.js", "keywords": [ "template", "templating", @@ -21,18 +21,18 @@ } ], "jam": { - "name": "Ractive", - "main": "Ractive.js", + "name": "ractive", + "main": "ractive.js", "include": [ - "Ractive.js", - "build/Ractive.js", - "build/Ractive.runtime.js", - "build/Ractive.min.js", - "build/Ractive.runtime.min.js", - "build/Ractive-legacy.js", - "build/Ractive-legacy.runtime.js", - "build/Ractive-legacy.min.js", - "build/Ractive-legacy.runtime.min.js", + "ractive.js", + "build/ractive.js", + "build/ractive.runtime.js", + "build/ractive.min.js", + "build/ractive.runtime.min.js", + "build/ractive-legacy.js", + "build/ractive-legacy.runtime.js", + "build/ractive-legacy.min.js", + "build/ractive-legacy.runtime.min.js", "README.md" ] }, @@ -41,7 +41,7 @@ "Templating" ], "bugs": { - "url": "https://github.com/RactiveJS/Ractive/issues" + "url": "https://github.com/ractivejs/ractive/issues" }, "contributors": [ { @@ -59,22 +59,24 @@ ], "repository": { "type": "git", - "url": "https://github.com/RactiveJS/Ractive.git" + "url": "https://github.com/ractivejs/ractive.git" }, - "github": "https://github.com/RactiveJS/Ractive", + "github": "https://github.com/ractivejs/ractive", "devDependencies": { - "grunt": "~0.4.1", - "grunt-contrib-jshint": "~0.8.0", + "grunt": "~0.4.4", + "grunt-contrib-jshint": "~0.10.0", "grunt-contrib-clean": "~0.5.0", - "grunt-contrib-qunit": "~0.3.0", - "grunt-contrib-nodeunit": "~0.2.2", - "grunt-contrib-concat": "~0.3.0", - "grunt-contrib-uglify": "~0.2.7", + "grunt-contrib-qunit": "~0.4.0", + "grunt-contrib-nodeunit": "~0.3.3", + "grunt-contrib-concat": "~0.4.0", + "grunt-contrib-uglify": "~0.4.0", "grunt-contrib-copy": "~0.5.0", - "grunt-contrib-watch": "~0.5.3", - "grunt-contrib-requirejs": "~0.4.1", - "amdclean": "~0.3.2", - "cheerio": "~0.13.0" + "grunt-contrib-watch": "~0.6.1", + "amdclean": "~1.5.0", + "cheerio": "~0.15.0", + "promises-aplus-tests": "*", + "grunt-jsbeautifier": "~0.2.7", + "grunt-contrib-requirejs": "~0.4.3" }, "testling": { "html": "test/testling.html", @@ -93,8 +95,5 @@ "ipad/6.0", "android-browser/4.2" ] - }, - "scripts": { - "test": "grunt test" } } diff --git a/ractive.js b/ractive.js new file mode 100644 index 0000000000..789cbf9429 --- /dev/null +++ b/ractive.js @@ -0,0 +1,12026 @@ +/* + Ractive.js v0.4.0 + 2014-04-08 - commit 276c0e2b + + http://ractivejs.org + http://twitter.com/RactiveJS + + Released under the MIT License. +*/ + +( function( global ) { + + 'use strict'; + + var noConflict = global.Ractive; + + var legacy = undefined; + + var config_initOptions = function() { + + var defaults, initOptions; + defaults = { + el: null, + template: '', + complete: null, + preserveWhitespace: false, + append: false, + twoway: true, + modifyArrays: true, + lazy: false, + debug: false, + noIntro: false, + transitionsEnabled: true, + magic: false, + noCssTransform: false, + adapt: [], + sanitize: false, + stripComments: true, + isolated: false, + delimiters: [ + '{{', + '}}' + ], + tripleDelimiters: [ + '{{{', + '}}}' + ], + computed: null + }; + initOptions = { + keys: Object.keys( defaults ), + defaults: defaults + }; + return initOptions; + }( legacy ); + + var config_svg = function() { + + if ( typeof document === 'undefined' ) { + return; + } + return document && document.implementation.hasFeature( 'http://www.w3.org/TR/SVG11/feature#BasicStructure', '1.1' ); + }(); + + var config_namespaces = { + html: 'http://www.w3.org/1999/xhtml', + mathml: 'http://www.w3.org/1998/Math/MathML', + svg: 'http://www.w3.org/2000/svg', + xlink: 'http://www.w3.org/1999/xlink', + xml: 'http://www.w3.org/XML/1998/namespace', + xmlns: 'http://www.w3.org/2000/xmlns/' + }; + + var utils_createElement = function( svg, namespaces ) { + + // Test for SVG support + if ( !svg ) { + return function( type, ns ) { + if ( ns && ns !== namespaces.html ) { + throw 'This browser does not support namespaces other than http://www.w3.org/1999/xhtml. The most likely cause of this error is that you\'re trying to render SVG in an older browser. See http://docs.ractivejs.org/latest/svg-and-older-browsers for more information'; + } + return document.createElement( type ); + }; + } else { + return function( type, ns ) { + if ( !ns || ns === namespaces.html ) { + return document.createElement( type ); + } + return document.createElementNS( ns, type ); + }; + } + }( config_svg, config_namespaces ); + + var config_isClient = typeof document === 'object'; + + var utils_defineProperty = function( isClient ) { + + try { + Object.defineProperty( {}, 'test', { + value: 0 + } ); + if ( isClient ) { + Object.defineProperty( document.createElement( 'div' ), 'test', { + value: 0 + } ); + } + return Object.defineProperty; + } catch ( err ) { + // Object.defineProperty doesn't exist, or we're in IE8 where you can + // only use it with DOM objects (what the fuck were you smoking, MSFT?) + return function( obj, prop, desc ) { + obj[ prop ] = desc.value; + }; + } + }( config_isClient ); + + var utils_defineProperties = function( createElement, defineProperty, isClient ) { + + try { + try { + Object.defineProperties( {}, { + test: { + value: 0 + } + } ); + } catch ( err ) { + // TODO how do we account for this? noMagic = true; + throw err; + } + if ( isClient ) { + Object.defineProperties( createElement( 'div' ), { + test: { + value: 0 + } + } ); + } + return Object.defineProperties; + } catch ( err ) { + return function( obj, props ) { + var prop; + for ( prop in props ) { + if ( props.hasOwnProperty( prop ) ) { + defineProperty( obj, prop, props[ prop ] ); + } + } + }; + } + }( utils_createElement, utils_defineProperty, config_isClient ); + + var utils_isNumeric = function( thing ) { + return !isNaN( parseFloat( thing ) ) && isFinite( thing ); + }; + + var Ractive_prototype_shared_add = function( isNumeric ) { + + return function( root, keypath, d ) { + var value; + if ( typeof keypath !== 'string' || !isNumeric( d ) ) { + throw new Error( 'Bad arguments' ); + } + value = +root.get( keypath ) || 0; + if ( !isNumeric( value ) ) { + throw new Error( 'Cannot add to a non-numeric value' ); + } + return root.set( keypath, value + d ); + }; + }( utils_isNumeric ); + + var Ractive_prototype_add = function( add ) { + + return function( keypath, d ) { + return add( this, keypath, d === undefined ? 1 : +d ); + }; + }( Ractive_prototype_shared_add ); + + var utils_isEqual = function( a, b ) { + if ( a === null && b === null ) { + return true; + } + if ( typeof a === 'object' || typeof b === 'object' ) { + return false; + } + return a === b; + }; + + var utils_Promise = function() { + + var Promise, PENDING = {}, FULFILLED = {}, REJECTED = {}; + Promise = function( callback ) { + var fulfilledHandlers = [], + rejectedHandlers = [], + state = PENDING, + result, dispatchHandlers, makeResolver, fulfil, reject, promise; + makeResolver = function( newState ) { + return function( value ) { + if ( state !== PENDING ) { + return; + } + result = value; + state = newState; + dispatchHandlers = makeDispatcher( state === FULFILLED ? fulfilledHandlers : rejectedHandlers, result ); + // dispatch onFulfilled and onRejected handlers asynchronously + wait( dispatchHandlers ); + }; + }; + fulfil = makeResolver( FULFILLED ); + reject = makeResolver( REJECTED ); + callback( fulfil, reject ); + promise = { + // `then()` returns a Promise - 2.2.7 + then: function( onFulfilled, onRejected ) { + var promise2 = new Promise( function( fulfil, reject ) { + var processResolutionHandler = function( handler, handlers, forward ) { + // 2.2.1.1 + if ( typeof handler === 'function' ) { + handlers.push( function( p1result ) { + var x; + try { + x = handler( p1result ); + resolve( promise2, x, fulfil, reject ); + } catch ( err ) { + reject( err ); + } + } ); + } else { + // Forward the result of promise1 to promise2, if resolution handlers + // are not given + handlers.push( forward ); + } + }; + // 2.2 + processResolutionHandler( onFulfilled, fulfilledHandlers, fulfil ); + processResolutionHandler( onRejected, rejectedHandlers, reject ); + if ( state !== PENDING ) { + // If the promise has resolved already, dispatch the appropriate handlers asynchronously + wait( dispatchHandlers ); + } + } ); + return promise2; + } + }; + promise[ 'catch' ] = function( onRejected ) { + return this.then( null, onRejected ); + }; + return promise; + }; + Promise.all = function( promises ) { + return new Promise( function( fulfil, reject ) { + var result = [], + pending, i, processPromise; + if ( !promises.length ) { + fulfil( result ); + return; + } + processPromise = function( i ) { + promises[ i ].then( function( value ) { + result[ i ] = value; + if ( !--pending ) { + fulfil( result ); + } + }, reject ); + }; + pending = i = promises.length; + while ( i-- ) { + processPromise( i ); + } + } ); + }; + Promise.resolve = function( value ) { + return new Promise( function( fulfil ) { + fulfil( value ); + } ); + }; + Promise.reject = function( reason ) { + return new Promise( function( fulfil, reject ) { + reject( reason ); + } ); + }; + return Promise; + // TODO use MutationObservers or something to simulate setImmediate + function wait( callback ) { + setTimeout( callback, 0 ); + } + + function makeDispatcher( handlers, result ) { + return function() { + var handler; + while ( handler = handlers.shift() ) { + handler( result ); + } + }; + } + + function resolve( promise, x, fulfil, reject ) { + // Promise Resolution Procedure + var then; + // 2.3.1 + if ( x === promise ) { + throw new TypeError( 'A promise\'s fulfillment handler cannot return the same promise' ); + } + // 2.3.2 + if ( x instanceof Promise ) { + x.then( fulfil, reject ); + } else if ( x && ( typeof x === 'object' || typeof x === 'function' ) ) { + try { + then = x.then; + } catch ( e ) { + reject( e ); + // 2.3.3.2 + return; + } + // 2.3.3.3 + if ( typeof then === 'function' ) { + var called, resolvePromise, rejectPromise; + resolvePromise = function( y ) { + if ( called ) { + return; + } + called = true; + resolve( promise, y, fulfil, reject ); + }; + rejectPromise = function( r ) { + if ( called ) { + return; + } + called = true; + reject( r ); + }; + try { + then.call( x, resolvePromise, rejectPromise ); + } catch ( e ) { + if ( !called ) { + // 2.3.3.3.4.1 + reject( e ); + // 2.3.3.3.4.2 + called = true; + return; + } + } + } else { + fulfil( x ); + } + } else { + fulfil( x ); + } + } + }(); + + var utils_normaliseKeypath = function() { + + var regex = /\[\s*(\*|[0-9]|[1-9][0-9]+)\s*\]/g; + return function normaliseKeypath( keypath ) { + return ( keypath || '' ).replace( regex, '.$1' ); + }; + }(); + + var config_vendors = [ + 'o', + 'ms', + 'moz', + 'webkit' + ]; + + var utils_requestAnimationFrame = function( vendors ) { + + // If window doesn't exist, we don't need requestAnimationFrame + if ( typeof window === 'undefined' ) { + return; + } + // https://gist.github.com/paulirish/1579671 + ( function( vendors, lastTime, window ) { + var x, setTimeout; + if ( window.requestAnimationFrame ) { + return; + } + for ( x = 0; x < vendors.length && !window.requestAnimationFrame; ++x ) { + window.requestAnimationFrame = window[ vendors[ x ] + 'RequestAnimationFrame' ]; + } + if ( !window.requestAnimationFrame ) { + setTimeout = window.setTimeout; + window.requestAnimationFrame = function( callback ) { + var currTime, timeToCall, id; + currTime = Date.now(); + timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) ); + id = setTimeout( function() { + callback( currTime + timeToCall ); + }, timeToCall ); + lastTime = currTime + timeToCall; + return id; + }; + } + }( vendors, 0, window ) ); + return window.requestAnimationFrame; + }( config_vendors ); + + var utils_getTime = function() { + + if ( typeof window !== 'undefined' && window.performance && typeof window.performance.now === 'function' ) { + return function() { + return window.performance.now(); + }; + } else { + return function() { + return Date.now(); + }; + } + }(); + + // This module provides a place to store a) circular dependencies and + // b) the callback functions that require those circular dependencies + var circular = []; + + var utils_removeFromArray = function( array, member ) { + var index = array.indexOf( member ); + if ( index !== -1 ) { + array.splice( index, 1 ); + } + }; + + var global_css = function( circular, isClient, removeFromArray ) { + + var runloop, styleElement, head, styleSheet, inDom, prefix = '/* Ractive.js component styles */\n', + componentsInPage = {}, styles = []; + if ( !isClient ) { + return; + } + circular.push( function() { + runloop = circular.runloop; + } ); + styleElement = document.createElement( 'style' ); + styleElement.type = 'text/css'; + head = document.getElementsByTagName( 'head' )[ 0 ]; + inDom = false; + // Internet Exploder won't let you use styleSheet.innerHTML - we have to + // use styleSheet.cssText instead + styleSheet = styleElement.styleSheet; + return { + add: function( Component ) { + if ( !Component.css ) { + return; + } + if ( !componentsInPage[ Component._guid ] ) { + // we create this counter so that we can in/decrement it as + // instances are added and removed. When all components are + // removed, the style is too + componentsInPage[ Component._guid ] = 0; + styles.push( Component.css ); + runloop.scheduleCssUpdate(); + } + componentsInPage[ Component._guid ] += 1; + }, + remove: function( Component ) { + if ( !Component.css ) { + return; + } + componentsInPage[ Component._guid ] -= 1; + if ( !componentsInPage[ Component._guid ] ) { + removeFromArray( styles, Component.css ); + runloop.scheduleCssUpdate(); + } + }, + update: function() { + var css; + if ( styles.length ) { + css = prefix + styles.join( ' ' ); + if ( styleSheet ) { + styleSheet.cssText = css; + } else { + styleElement.innerHTML = css; + } + if ( !inDom ) { + head.appendChild( styleElement ); + } + } else if ( inDom ) { + head.removeChild( styleElement ); + } + } + }; + }( circular, config_isClient, utils_removeFromArray ); + + var shared_getValueFromCheckboxes = function( ractive, keypath ) { + var value, checkboxes, checkbox, len, i, rootEl; + value = []; + // TODO in edge cases involving components with inputs bound to the same keypath, this + // could get messy + // if we're still in the initial render, we need to find the inputs from the as-yet off-DOM + // document fragment. otherwise, the root element + rootEl = ractive._rendering ? ractive.fragment.docFrag : ractive.el; + checkboxes = rootEl.querySelectorAll( 'input[type="checkbox"][name="{{' + keypath + '}}"]' ); + len = checkboxes.length; + for ( i = 0; i < len; i += 1 ) { + checkbox = checkboxes[ i ]; + if ( checkbox.hasAttribute( 'checked' ) || checkbox.checked ) { + value.push( checkbox._ractive.value ); + } + } + return value; + }; + + var utils_hasOwnProperty = Object.prototype.hasOwnProperty; + + var shared_getInnerContext = function( fragment ) { + do { + if ( fragment.context ) { + return fragment.context; + } + } while ( fragment = fragment.parent ); + return ''; + }; + + var shared_resolveRef = function( circular, normaliseKeypath, hasOwnProperty, getInnerContext ) { + + var get, ancestorErrorMessage = 'Could not resolve reference - too many "../" prefixes'; + circular.push( function() { + get = circular.get; + } ); + return function resolveRef( ractive, ref, fragment ) { + var context, contextKeys, keys, lastKey, postfix, parentKeypath, parentValue, wrapped, hasContextChain; + ref = normaliseKeypath( ref ); + // Implicit iterators - i.e. {{.}} - are a special case + if ( ref === '.' ) { + return getInnerContext( fragment ); + } + // If a reference begins with '.', it's either a restricted reference or + // an ancestor reference... + if ( ref.charAt( 0 ) === '.' ) { + // ...either way we need to get the innermost context + context = getInnerContext( fragment ); + contextKeys = context ? context.split( '.' ) : []; + // ancestor references (starting "../") go up the tree + if ( ref.substr( 0, 3 ) === '../' ) { + while ( ref.substr( 0, 3 ) === '../' ) { + if ( !contextKeys.length ) { + throw new Error( ancestorErrorMessage ); + } + contextKeys.pop(); + ref = ref.substring( 3 ); + } + contextKeys.push( ref ); + return contextKeys.join( '.' ); + } + // not an ancestor reference - must be a restricted reference (prepended with ".") + if ( !context ) { + return ref.substring( 1 ); + } + return context + ref; + } + // Now we need to try and resolve the reference against any + // contexts set by parent list/object sections + keys = ref.split( '.' ); + lastKey = keys.pop(); + postfix = keys.length ? '.' + keys.join( '.' ) : ''; + do { + context = fragment.context; + if ( !context ) { + continue; + } + hasContextChain = true; + parentKeypath = context + postfix; + parentValue = get( ractive, parentKeypath ); + if ( wrapped = ractive._wrapped[ parentKeypath ] ) { + parentValue = wrapped.get(); + } + if ( parentValue && ( typeof parentValue === 'object' || typeof parentValue === 'function' ) && lastKey in parentValue ) { + return context + '.' + ref; + } + } while ( fragment = fragment.parent ); + // Still no keypath? + // If there's no context chain, and the instance is either a) isolated or + // b) an orphan, then we know that the keypath is identical to the reference + if ( !hasContextChain && ( !ractive._parent || ractive.isolated ) ) { + return ref; + } + // We need both of these - the first enables components to treat data contexts + // like lexical scopes in JavaScript functions... + if ( hasOwnProperty.call( ractive.data, ref ) ) { + return ref; + } else if ( get( ractive, ref ) !== undefined ) { + return ref; + } + }; + }( circular, utils_normaliseKeypath, utils_hasOwnProperty, shared_getInnerContext ); + + var shared_getUpstreamChanges = function getUpstreamChanges( changes ) { + var upstreamChanges = [ '' ], + i, keypath, keys, upstreamKeypath; + i = changes.length; + while ( i-- ) { + keypath = changes[ i ]; + keys = keypath.split( '.' ); + while ( keys.length > 1 ) { + keys.pop(); + upstreamKeypath = keys.join( '.' ); + if ( upstreamChanges[ upstreamKeypath ] !== true ) { + upstreamChanges.push( upstreamKeypath ); + upstreamChanges[ upstreamKeypath ] = true; + } + } + } + return upstreamChanges; + }; + + var shared_notifyDependants = function() { + + var lastKey, starMaps = {}; + lastKey = /[^\.]+$/; + + function notifyDependants( ractive, keypath, onlyDirect ) { + var i; + // Notify any pattern observers + if ( ractive._patternObservers.length ) { + notifyPatternObservers( ractive, keypath, keypath, onlyDirect, true ); + } + for ( i = 0; i < ractive._deps.length; i += 1 ) { + // can't cache ractive._deps.length, it may change + notifyDependantsAtPriority( ractive, keypath, i, onlyDirect ); + } + } + notifyDependants.multiple = function notifyMultipleDependants( ractive, keypaths, onlyDirect ) { + var i, j, len; + len = keypaths.length; + // Notify any pattern observers + if ( ractive._patternObservers.length ) { + i = len; + while ( i-- ) { + notifyPatternObservers( ractive, keypaths[ i ], keypaths[ i ], onlyDirect, true ); + } + } + for ( i = 0; i < ractive._deps.length; i += 1 ) { + if ( ractive._deps[ i ] ) { + j = len; + while ( j-- ) { + notifyDependantsAtPriority( ractive, keypaths[ j ], i, onlyDirect ); + } + } + } + }; + return notifyDependants; + + function notifyDependantsAtPriority( ractive, keypath, priority, onlyDirect ) { + var depsByKeypath = ractive._deps[ priority ]; + if ( !depsByKeypath ) { + return; + } + // update dependants of this keypath + updateAll( depsByKeypath[ keypath ] ); + // If we're only notifying direct dependants, not dependants + // of downstream keypaths, then YOU SHALL NOT PASS + if ( onlyDirect ) { + return; + } + // otherwise, cascade + cascade( ractive._depsMap[ keypath ], ractive, priority ); + } + + function updateAll( deps ) { + var i, len; + if ( deps ) { + len = deps.length; + for ( i = 0; i < len; i += 1 ) { + deps[ i ].update(); + } + } + } + + function cascade( childDeps, ractive, priority, onlyDirect ) { + var i; + if ( childDeps ) { + i = childDeps.length; + while ( i-- ) { + notifyDependantsAtPriority( ractive, childDeps[ i ], priority, onlyDirect ); + } + } + } + // TODO split into two functions? i.e. one for the top-level call, one for the cascade + function notifyPatternObservers( ractive, registeredKeypath, actualKeypath, isParentOfChangedKeypath, isTopLevelCall ) { + var i, patternObserver, children, child, key, childActualKeypath, potentialWildcardMatches, cascade; + // First, observers that match patterns at the same level + // or higher in the tree + i = ractive._patternObservers.length; + while ( i-- ) { + patternObserver = ractive._patternObservers[ i ]; + if ( patternObserver.regex.test( actualKeypath ) ) { + patternObserver.update( actualKeypath ); + } + } + if ( isParentOfChangedKeypath ) { + return; + } + // If the changed keypath is 'foo.bar', we need to see if there are + // any pattern observer dependants of keypaths below any of + // 'foo.bar', 'foo.*', '*.bar' or '*.*' (e.g. 'foo.bar.*' or 'foo.*.baz' ) + cascade = function( keypath ) { + if ( children = ractive._depsMap[ keypath ] ) { + i = children.length; + while ( i-- ) { + child = children[ i ]; + // foo.*.baz + key = lastKey.exec( child )[ 0 ]; + // 'baz' + childActualKeypath = actualKeypath ? actualKeypath + '.' + key : key; + // 'foo.bar.baz' + notifyPatternObservers( ractive, child, childActualKeypath ); + } + } + }; + if ( isTopLevelCall ) { + potentialWildcardMatches = getPotentialWildcardMatches( actualKeypath ); + potentialWildcardMatches.forEach( cascade ); + } else { + cascade( registeredKeypath ); + } + } + // This function takes a keypath such as 'foo.bar.baz', and returns + // all the variants of that keypath that include a wildcard in place + // of a key, such as 'foo.bar.*', 'foo.*.baz', 'foo.*.*' and so on. + // These are then checked against the dependants map (ractive._depsMap) + // to see if any pattern observers are downstream of one or more of + // these wildcard keypaths (e.g. 'foo.bar.*.status') + function getPotentialWildcardMatches( keypath ) { + var keys, starMap, mapper, i, result, wildcardKeypath; + keys = keypath.split( '.' ); + starMap = getStarMap( keys.length ); + result = []; + mapper = function( star, i ) { + return star ? '*' : keys[ i ]; + }; + i = starMap.length; + while ( i-- ) { + wildcardKeypath = starMap[ i ].map( mapper ).join( '.' ); + if ( !result[ wildcardKeypath ] ) { + result.push( wildcardKeypath ); + result[ wildcardKeypath ] = true; + } + } + return result; + } + // This function returns all the possible true/false combinations for + // a given number - e.g. for two, the possible combinations are + // [ true, true ], [ true, false ], [ false, true ], [ false, false ]. + // It does so by getting all the binary values between 0 and e.g. 11 + function getStarMap( num ) { + var ones = '', + max, binary, starMap, mapper, i; + if ( !starMaps[ num ] ) { + starMap = []; + while ( ones.length < num ) { + ones += 1; + } + max = parseInt( ones, 2 ); + mapper = function( digit ) { + return digit === '1'; + }; + for ( i = 0; i <= max; i += 1 ) { + binary = i.toString( 2 ); + while ( binary.length < num ) { + binary = '0' + binary; + } + starMap[ i ] = Array.prototype.map.call( binary, mapper ); + } + starMaps[ num ] = starMap; + } + return starMaps[ num ]; + } + }(); + + var shared_makeTransitionManager = function( removeFromArray ) { + + var makeTransitionManager, checkComplete, remove, init; + makeTransitionManager = function( callback, previous ) { + var transitionManager = []; + transitionManager.detachQueue = []; + transitionManager.remove = remove; + transitionManager.init = init; + transitionManager._check = checkComplete; + transitionManager._callback = callback; + transitionManager._previous = previous; + if ( previous ) { + previous.push( transitionManager ); + } + return transitionManager; + }; + checkComplete = function() { + var element; + if ( this._ready && !this.length ) { + while ( element = this.detachQueue.pop() ) { + element.detach(); + } + if ( typeof this._callback === 'function' ) { + this._callback(); + } + if ( this._previous ) { + this._previous.remove( this ); + } + } + }; + remove = function( transition ) { + removeFromArray( this, transition ); + this._check(); + }; + init = function() { + this._ready = true; + this._check(); + }; + return makeTransitionManager; + }( utils_removeFromArray ); + + var global_runloop = function( circular, css, removeFromArray, getValueFromCheckboxes, resolveRef, getUpstreamChanges, notifyDependants, makeTransitionManager ) { + + circular.push( function() { + get = circular.get; + set = circular.set; + } ); + var runloop, get, set, dirty = false, + flushing = false, + pendingCssChanges, inFlight = 0, + toFocus = null, + liveQueries = [], + decorators = [], + transitions = [], + observers = [], + attributes = [], + activeBindings = [], + evaluators = [], + computations = [], + selectValues = [], + checkboxKeypaths = {}, checkboxes = [], + radios = [], + unresolved = [], + instances = [], + transitionManager; + runloop = { + start: function( instance, callback ) { + this.addInstance( instance ); + if ( !flushing ) { + inFlight += 1; + // create a new transition manager + transitionManager = makeTransitionManager( callback, transitionManager ); + } + }, + end: function() { + if ( flushing ) { + attemptKeypathResolution(); + return; + } + if ( !--inFlight ) { + flushing = true; + flushChanges(); + flushing = false; + land(); + } + transitionManager.init(); + transitionManager = transitionManager._previous; + }, + trigger: function() { + if ( inFlight || flushing ) { + attemptKeypathResolution(); + return; + } + flushing = true; + flushChanges(); + flushing = false; + land(); + }, + focus: function( node ) { + toFocus = node; + }, + addInstance: function( instance ) { + if ( instance && !instances[ instance._guid ] ) { + instances.push( instance ); + instances[ instances._guid ] = true; + } + }, + addLiveQuery: function( query ) { + liveQueries.push( query ); + }, + addDecorator: function( decorator ) { + decorators.push( decorator ); + }, + addTransition: function( transition ) { + transition._manager = transitionManager; + transitionManager.push( transition ); + transitions.push( transition ); + }, + addObserver: function( observer ) { + observers.push( observer ); + }, + addAttribute: function( attribute ) { + attributes.push( attribute ); + }, + addBinding: function( binding ) { + binding.active = true; + activeBindings.push( binding ); + }, + scheduleCssUpdate: function() { + // if runloop isn't currently active, we need to trigger change immediately + if ( !inFlight && !flushing ) { + // TODO does this ever happen? + css.update(); + } else { + pendingCssChanges = true; + } + }, + // changes that may cause additional changes... + addEvaluator: function( evaluator ) { + dirty = true; + evaluators.push( evaluator ); + }, + addComputation: function( thing ) { + dirty = true; + computations.push( thing ); + }, + addSelectValue: function( selectValue ) { + dirty = true; + selectValues.push( selectValue ); + }, + addCheckbox: function( checkbox ) { + if ( !checkboxKeypaths[ checkbox.keypath ] ) { + dirty = true; + checkboxes.push( checkbox ); + } + }, + addRadio: function( radio ) { + dirty = true; + radios.push( radio ); + }, + addUnresolved: function( thing ) { + dirty = true; + unresolved.push( thing ); + }, + removeUnresolved: function( thing ) { + removeFromArray( unresolved, thing ); + }, + // synchronise node detachments with transition ends + detachWhenReady: function( thing ) { + transitionManager.detachQueue.push( thing ); + } + }; + circular.runloop = runloop; + return runloop; + + function land() { + var thing, changedKeypath, changeHash; + if ( toFocus ) { + toFocus.focus(); + toFocus = null; + } + while ( thing = attributes.pop() ) { + thing.update().deferred = false; + } + while ( thing = liveQueries.pop() ) { + thing._sort(); + } + while ( thing = decorators.pop() ) { + thing.init(); + } + while ( thing = transitions.pop() ) { + thing.init(); + } + while ( thing = observers.pop() ) { + thing.update(); + } + while ( thing = activeBindings.pop() ) { + thing.active = false; + } + // Change events are fired last + while ( thing = instances.pop() ) { + instances[ thing._guid ] = false; + if ( thing._changes.length ) { + changeHash = {}; + while ( changedKeypath = thing._changes.pop() ) { + changeHash[ changedKeypath ] = get( thing, changedKeypath ); + } + thing.fire( 'change', changeHash ); + } + } + if ( pendingCssChanges ) { + css.update(); + pendingCssChanges = false; + } + } + + function flushChanges() { + var thing, upstreamChanges, i; + i = instances.length; + while ( i-- ) { + thing = instances[ i ]; + if ( thing._changes.length ) { + upstreamChanges = getUpstreamChanges( thing._changes ); + notifyDependants.multiple( thing, upstreamChanges, true ); + } + } + attemptKeypathResolution(); + while ( dirty ) { + dirty = false; + while ( thing = computations.pop() ) { + thing.update(); + } + while ( thing = evaluators.pop() ) { + thing.update().deferred = false; + } + while ( thing = selectValues.pop() ) { + thing.deferredUpdate(); + } + while ( thing = checkboxes.pop() ) { + set( thing.root, thing.keypath, getValueFromCheckboxes( thing.root, thing.keypath ) ); + } + while ( thing = radios.pop() ) { + thing.update(); + } + } + } + + function attemptKeypathResolution() { + var array, thing, keypath; + if ( !unresolved.length ) { + return; + } + // see if we can resolve any unresolved references + array = unresolved.splice( 0, unresolved.length ); + while ( thing = array.pop() ) { + if ( thing.keypath ) { + continue; + } + keypath = resolveRef( thing.root, thing.ref, thing.parentFragment ); + if ( keypath !== undefined ) { + // If we've resolved the keypath, we can initialise this item + thing.resolve( keypath ); + } else { + // If we can't resolve the reference, try again next time + unresolved.push( thing ); + } + } + } + }( circular, global_css, utils_removeFromArray, shared_getValueFromCheckboxes, shared_resolveRef, shared_getUpstreamChanges, shared_notifyDependants, shared_makeTransitionManager ); + + var shared_animations = function( rAF, getTime, runloop ) { + + var queue = []; + var animations = { + tick: function() { + var i, animation, now; + now = getTime(); + runloop.start(); + for ( i = 0; i < queue.length; i += 1 ) { + animation = queue[ i ]; + if ( !animation.tick( now ) ) { + // animation is complete, remove it from the stack, and decrement i so we don't miss one + queue.splice( i--, 1 ); + } + } + runloop.end(); + if ( queue.length ) { + rAF( animations.tick ); + } else { + animations.running = false; + } + }, + add: function( animation ) { + queue.push( animation ); + if ( !animations.running ) { + animations.running = true; + rAF( animations.tick ); + } + }, + // TODO optimise this + abort: function( keypath, root ) { + var i = queue.length, + animation; + while ( i-- ) { + animation = queue[ i ]; + if ( animation.root === root && animation.keypath === keypath ) { + animation.stop(); + } + } + } + }; + return animations; + }( utils_requestAnimationFrame, utils_getTime, global_runloop ); + + var utils_isArray = function() { + + var toString = Object.prototype.toString; + // thanks, http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/ + return function( thing ) { + return toString.call( thing ) === '[object Array]'; + }; + }(); + + var utils_clone = function( isArray ) { + + return function( source ) { + var target, key; + if ( !source || typeof source !== 'object' ) { + return source; + } + if ( isArray( source ) ) { + return source.slice(); + } + target = {}; + for ( key in source ) { + if ( source.hasOwnProperty( key ) ) { + target[ key ] = source[ key ]; + } + } + return target; + }; + }( utils_isArray ); + + var registries_adaptors = {}; + + var shared_get_arrayAdaptor_getSpliceEquivalent = function( array, methodName, args ) { + switch ( methodName ) { + case 'splice': + return args; + case 'sort': + case 'reverse': + return null; + case 'pop': + if ( array.length ) { + return [ -1 ]; + } + return null; + case 'push': + return [ + array.length, + 0 + ].concat( args ); + case 'shift': + return [ + 0, + 1 + ]; + case 'unshift': + return [ + 0, + 0 + ].concat( args ); + } + }; + + var shared_get_arrayAdaptor_summariseSpliceOperation = function( array, args ) { + var start, addedItems, removedItems, balance; + if ( !args ) { + return null; + } + // figure out where the changes started... + start = +( args[ 0 ] < 0 ? array.length + args[ 0 ] : args[ 0 ] ); + // ...and how many items were added to or removed from the array + addedItems = Math.max( 0, args.length - 2 ); + removedItems = args[ 1 ] !== undefined ? args[ 1 ] : array.length - start; + // It's possible to do e.g. [ 1, 2, 3 ].splice( 2, 2 ) - i.e. the second argument + // means removing more items from the end of the array than there are. In these + // cases we need to curb JavaScript's enthusiasm or we'll get out of sync + removedItems = Math.min( removedItems, array.length - start ); + balance = addedItems - removedItems; + return { + start: start, + balance: balance, + added: addedItems, + removed: removedItems + }; + }; + + var config_types = { + TEXT: 1, + INTERPOLATOR: 2, + TRIPLE: 3, + SECTION: 4, + INVERTED: 5, + CLOSING: 6, + ELEMENT: 7, + PARTIAL: 8, + COMMENT: 9, + DELIMCHANGE: 10, + MUSTACHE: 11, + TAG: 12, + ATTRIBUTE: 13, + COMPONENT: 15, + NUMBER_LITERAL: 20, + STRING_LITERAL: 21, + ARRAY_LITERAL: 22, + OBJECT_LITERAL: 23, + BOOLEAN_LITERAL: 24, + GLOBAL: 26, + KEY_VALUE_PAIR: 27, + REFERENCE: 30, + REFINEMENT: 31, + MEMBER: 32, + PREFIX_OPERATOR: 33, + BRACKETED: 34, + CONDITIONAL: 35, + INFIX_OPERATOR: 36, + INVOCATION: 40 + }; + + var shared_clearCache = function clearCache( ractive, keypath, dontTeardownWrapper ) { + var cacheMap, wrappedProperty; + if ( !dontTeardownWrapper ) { + // Is there a wrapped property at this keypath? + if ( wrappedProperty = ractive._wrapped[ keypath ] ) { + // Did we unwrap it? + if ( wrappedProperty.teardown() !== false ) { + ractive._wrapped[ keypath ] = null; + } + } + } + ractive._cache[ keypath ] = undefined; + if ( cacheMap = ractive._cacheMap[ keypath ] ) { + while ( cacheMap.length ) { + clearCache( ractive, cacheMap.pop() ); + } + } + }; + + var utils_createBranch = function() { + + var numeric = /^\s*[0-9]+\s*$/; + return function( key ) { + return numeric.test( key ) ? [] : {}; + }; + }(); + + var shared_set = function( circular, isEqual, createBranch, clearCache, notifyDependants ) { + + var get; + circular.push( function() { + get = circular.get; + } ); + + function set( ractive, keypath, value, silent ) { + var keys, lastKey, parentKeypath, parentValue, computation, wrapper, evaluator, dontTeardownWrapper; + if ( isEqual( ractive._cache[ keypath ], value ) ) { + return; + } + computation = ractive._computations[ keypath ]; + wrapper = ractive._wrapped[ keypath ]; + evaluator = ractive._evaluators[ keypath ]; + if ( computation && !computation.setting ) { + computation.set( value ); + } + // If we have a wrapper with a `reset()` method, we try and use it. If the + // `reset()` method returns false, the wrapper should be torn down, and + // (most likely) a new one should be created later + if ( wrapper && wrapper.reset ) { + dontTeardownWrapper = wrapper.reset( value ) !== false; + if ( dontTeardownWrapper ) { + value = wrapper.get(); + } + } + // Update evaluator value. This may be from the evaluator itself, or + // it may be from the wrapper that wraps an evaluator's result - it + // doesn't matter + if ( evaluator ) { + evaluator.value = value; + } + if ( !computation && !evaluator && !dontTeardownWrapper ) { + keys = keypath.split( '.' ); + lastKey = keys.pop(); + parentKeypath = keys.join( '.' ); + wrapper = ractive._wrapped[ parentKeypath ]; + if ( wrapper && wrapper.set ) { + wrapper.set( lastKey, value ); + } else { + parentValue = wrapper ? wrapper.get() : get( ractive, parentKeypath ); + if ( !parentValue ) { + parentValue = createBranch( lastKey ); + set( ractive, parentKeypath, parentValue, true ); + } + parentValue[ lastKey ] = value; + } + } + clearCache( ractive, keypath, dontTeardownWrapper ); + if ( !silent ) { + ractive._changes.push( keypath ); + notifyDependants( ractive, keypath ); + } + } + circular.set = set; + return set; + }( circular, utils_isEqual, utils_createBranch, shared_clearCache, shared_notifyDependants ); + + var shared_get_arrayAdaptor_processWrapper = function( types, clearCache, notifyDependants, set ) { + + return function( wrapper, array, methodName, spliceSummary ) { + var root, keypath, clearEnd, updateDependant, i, changed, start, end, childKeypath, lengthUnchanged; + root = wrapper.root; + keypath = wrapper.keypath; + root._changes.push( keypath ); + // If this is a sort or reverse, we just do root.set()... + // TODO use merge logic? + if ( methodName === 'sort' || methodName === 'reverse' ) { + set( root, keypath, array ); + return; + } + if ( !spliceSummary ) { + // (presumably we tried to pop from an array of zero length. + // in which case there's nothing to do) + return; + } + // ...otherwise we do a smart update whereby elements are added/removed + // in the right place. But we do need to clear the cache downstream + clearEnd = !spliceSummary.balance ? spliceSummary.added : array.length - Math.min( spliceSummary.balance, 0 ); + for ( i = spliceSummary.start; i < clearEnd; i += 1 ) { + clearCache( root, keypath + '.' + i ); + } + // Propagate changes + updateDependant = function( dependant ) { + // is this a DOM section? + if ( dependant.keypath === keypath && dependant.type === types.SECTION && !dependant.inverted && dependant.docFrag ) { + dependant.splice( spliceSummary ); + } else { + dependant.update(); + } + }; + // Go through all dependant priority levels, finding smart update targets + root._deps.forEach( function( depsByKeypath ) { + var dependants = depsByKeypath[ keypath ]; + if ( dependants ) { + dependants.forEach( updateDependant ); + } + } ); + // if we're removing old items and adding new ones, simultaneously, we need to force an update + if ( spliceSummary.added && spliceSummary.removed ) { + changed = Math.max( spliceSummary.added, spliceSummary.removed ); + start = spliceSummary.start; + end = start + changed; + lengthUnchanged = spliceSummary.added === spliceSummary.removed; + for ( i = start; i < end; i += 1 ) { + childKeypath = keypath + '.' + i; + notifyDependants( root, childKeypath ); + } + } + // length property has changed - notify dependants + // TODO in some cases (e.g. todo list example, when marking all as complete, then + // adding a new item (which should deactivate the 'all complete' checkbox + // but doesn't) this needs to happen before other updates. But doing so causes + // other mental problems. not sure what's going on... + if ( !lengthUnchanged ) { + clearCache( root, keypath + '.length' ); + notifyDependants( root, keypath + '.length', true ); + } + }; + }( config_types, shared_clearCache, shared_notifyDependants, shared_set ); + + var shared_get_arrayAdaptor_patch = function( runloop, defineProperty, getSpliceEquivalent, summariseSpliceOperation, processWrapper ) { + + var patchedArrayProto = [], + mutatorMethods = [ + 'pop', + 'push', + 'reverse', + 'shift', + 'sort', + 'splice', + 'unshift' + ], + testObj, patchArrayMethods, unpatchArrayMethods; + mutatorMethods.forEach( function( methodName ) { + var method = function() { + var spliceEquivalent, spliceSummary, result, wrapper, i; + // push, pop, shift and unshift can all be represented as a splice operation. + // this makes life easier later + spliceEquivalent = getSpliceEquivalent( this, methodName, Array.prototype.slice.call( arguments ) ); + spliceSummary = summariseSpliceOperation( this, spliceEquivalent ); + // apply the underlying method + result = Array.prototype[ methodName ].apply( this, arguments ); + // trigger changes + this._ractive.setting = true; + i = this._ractive.wrappers.length; + while ( i-- ) { + wrapper = this._ractive.wrappers[ i ]; + runloop.start( wrapper.root ); + processWrapper( wrapper, this, methodName, spliceSummary ); + runloop.end(); + } + this._ractive.setting = false; + return result; + }; + defineProperty( patchedArrayProto, methodName, { + value: method + } ); + } ); + // can we use prototype chain injection? + // http://perfectionkills.com/how-ecmascript-5-still-does-not-allow-to-subclass-an-array/#wrappers_prototype_chain_injection + testObj = {}; + if ( testObj.__proto__ ) { + // yes, we can + patchArrayMethods = function( array ) { + array.__proto__ = patchedArrayProto; + }; + unpatchArrayMethods = function( array ) { + array.__proto__ = Array.prototype; + }; + } else { + // no, we can't + patchArrayMethods = function( array ) { + var i, methodName; + i = mutatorMethods.length; + while ( i-- ) { + methodName = mutatorMethods[ i ]; + defineProperty( array, methodName, { + value: patchedArrayProto[ methodName ], + configurable: true + } ); + } + }; + unpatchArrayMethods = function( array ) { + var i; + i = mutatorMethods.length; + while ( i-- ) { + delete array[ mutatorMethods[ i ] ]; + } + }; + } + patchArrayMethods.unpatch = unpatchArrayMethods; + return patchArrayMethods; + }( global_runloop, utils_defineProperty, shared_get_arrayAdaptor_getSpliceEquivalent, shared_get_arrayAdaptor_summariseSpliceOperation, shared_get_arrayAdaptor_processWrapper ); + + var shared_get_arrayAdaptor__arrayAdaptor = function( defineProperty, isArray, patch ) { + + var arrayAdaptor, + // helpers + ArrayWrapper, errorMessage; + arrayAdaptor = { + filter: function( object ) { + // wrap the array if a) b) it's an array, and b) either it hasn't been wrapped already, + // or the array didn't trigger the get() itself + return isArray( object ) && ( !object._ractive || !object._ractive.setting ); + }, + wrap: function( ractive, array, keypath ) { + return new ArrayWrapper( ractive, array, keypath ); + } + }; + ArrayWrapper = function( ractive, array, keypath ) { + this.root = ractive; + this.value = array; + this.keypath = keypath; + // if this array hasn't already been ractified, ractify it + if ( !array._ractive ) { + // define a non-enumerable _ractive property to store the wrappers + defineProperty( array, '_ractive', { + value: { + wrappers: [], + instances: [], + setting: false + }, + configurable: true + } ); + patch( array ); + } + // store the ractive instance, so we can handle transitions later + if ( !array._ractive.instances[ ractive._guid ] ) { + array._ractive.instances[ ractive._guid ] = 0; + array._ractive.instances.push( ractive ); + } + array._ractive.instances[ ractive._guid ] += 1; + array._ractive.wrappers.push( this ); + }; + ArrayWrapper.prototype = { + get: function() { + return this.value; + }, + teardown: function() { + var array, storage, wrappers, instances, index; + array = this.value; + storage = array._ractive; + wrappers = storage.wrappers; + instances = storage.instances; + // if teardown() was invoked because we're clearing the cache as a result of + // a change that the array itself triggered, we can save ourselves the teardown + // and immediate setup + if ( storage.setting ) { + return false; + } + index = wrappers.indexOf( this ); + if ( index === -1 ) { + throw new Error( errorMessage ); + } + wrappers.splice( index, 1 ); + // if nothing else depends on this array, we can revert it to its + // natural state + if ( !wrappers.length ) { + delete array._ractive; + patch.unpatch( this.value ); + } else { + // remove ractive instance if possible + instances[ this.root._guid ] -= 1; + if ( !instances[ this.root._guid ] ) { + index = instances.indexOf( this.root ); + if ( index === -1 ) { + throw new Error( errorMessage ); + } + instances.splice( index, 1 ); + } + } + } + }; + errorMessage = 'Something went wrong in a rather interesting way'; + return arrayAdaptor; + }( utils_defineProperty, utils_isArray, shared_get_arrayAdaptor_patch ); + + var shared_get_magicAdaptor = function( runloop, createBranch, isArray, clearCache, notifyDependants ) { + + var magicAdaptor, MagicWrapper; + try { + Object.defineProperty( {}, 'test', { + value: 0 + } ); + } catch ( err ) { + return false; + } + magicAdaptor = { + filter: function( object, keypath, ractive ) { + var keys, key, parentKeypath, parentWrapper, parentValue; + if ( !keypath ) { + return false; + } + keys = keypath.split( '.' ); + key = keys.pop(); + parentKeypath = keys.join( '.' ); + // If the parent value is a wrapper, other than a magic wrapper, + // we shouldn't wrap this property + if ( ( parentWrapper = ractive._wrapped[ parentKeypath ] ) && !parentWrapper.magic ) { + return false; + } + parentValue = ractive.get( parentKeypath ); + // if parentValue is an array that doesn't include this member, + // we should return false otherwise lengths will get messed up + if ( isArray( parentValue ) && /^[0-9]+$/.test( key ) ) { + return false; + } + return parentValue && ( typeof parentValue === 'object' || typeof parentValue === 'function' ); + }, + wrap: function( ractive, property, keypath ) { + return new MagicWrapper( ractive, property, keypath ); + } + }; + MagicWrapper = function( ractive, value, keypath ) { + var keys, objKeypath, descriptor, siblings; + this.magic = true; + this.ractive = ractive; + this.keypath = keypath; + this.value = value; + keys = keypath.split( '.' ); + this.prop = keys.pop(); + objKeypath = keys.join( '.' ); + this.obj = objKeypath ? ractive.get( objKeypath ) : ractive.data; + descriptor = this.originalDescriptor = Object.getOwnPropertyDescriptor( this.obj, this.prop ); + // Has this property already been wrapped? + if ( descriptor && descriptor.set && ( siblings = descriptor.set._ractiveWrappers ) ) { + // Yes. Register this wrapper to this property, if it hasn't been already + if ( siblings.indexOf( this ) === -1 ) { + siblings.push( this ); + } + return; + } + // No, it hasn't been wrapped + createAccessors( this, value, descriptor ); + }; + MagicWrapper.prototype = { + get: function() { + return this.value; + }, + reset: function( value ) { + if ( this.updating ) { + return; + } + this.updating = true; + this.obj[ this.prop ] = value; + // trigger set() accessor + clearCache( this.ractive, this.keypath ); + this.updating = false; + }, + set: function( key, value ) { + if ( this.updating ) { + return; + } + if ( !this.obj[ this.prop ] ) { + this.updating = true; + this.obj[ this.prop ] = createBranch( key ); + this.updating = false; + } + this.obj[ this.prop ][ key ] = value; + }, + teardown: function() { + var descriptor, set, value, wrappers, index; + // If this method was called because the cache was being cleared as a + // result of a set()/update() call made by this wrapper, we return false + // so that it doesn't get torn down + if ( this.updating ) { + return false; + } + descriptor = Object.getOwnPropertyDescriptor( this.obj, this.prop ); + set = descriptor && descriptor.set; + if ( !set ) { + // most likely, this was an array member that was spliced out + return; + } + wrappers = set._ractiveWrappers; + index = wrappers.indexOf( this ); + if ( index !== -1 ) { + wrappers.splice( index, 1 ); + } + // Last one out, turn off the lights + if ( !wrappers.length ) { + value = this.obj[ this.prop ]; + Object.defineProperty( this.obj, this.prop, this.originalDescriptor || { + writable: true, + enumerable: true, + configurable: true + } ); + this.obj[ this.prop ] = value; + } + } + }; + + function createAccessors( originalWrapper, value, descriptor ) { + var object, property, oldGet, oldSet, get, set; + object = originalWrapper.obj; + property = originalWrapper.prop; + // Is this descriptor configurable? + if ( descriptor && !descriptor.configurable ) { + // Special case - array length + if ( property === 'length' ) { + return; + } + throw new Error( 'Cannot use magic mode with property "' + property + '" - object is not configurable' ); + } + // Time to wrap this property + if ( descriptor ) { + oldGet = descriptor.get; + oldSet = descriptor.set; + } + get = oldGet || function() { + return value; + }; + set = function( v ) { + if ( oldSet ) { + oldSet( v ); + } + value = oldGet ? oldGet() : v; + set._ractiveWrappers.forEach( updateWrapper ); + }; + + function updateWrapper( wrapper ) { + var keypath, ractive; + wrapper.value = value; + if ( wrapper.updating ) { + return; + } + ractive = wrapper.ractive; + keypath = wrapper.keypath; + wrapper.updating = true; + runloop.start( ractive ); + ractive._changes.push( keypath ); + clearCache( ractive, keypath ); + notifyDependants( ractive, keypath ); + runloop.end(); + wrapper.updating = false; + } + // Create an array of wrappers, in case other keypaths/ractives depend on this property. + // Handily, we can store them as a property of the set function. Yay JavaScript. + set._ractiveWrappers = [ originalWrapper ]; + Object.defineProperty( object, property, { + get: get, + set: set, + enumerable: true, + configurable: true + } ); + } + return magicAdaptor; + }( global_runloop, utils_createBranch, utils_isArray, shared_clearCache, shared_notifyDependants ); + + var shared_get_magicArrayAdaptor = function( magicAdaptor, arrayAdaptor ) { + + if ( !magicAdaptor ) { + return false; + } + var magicArrayAdaptor, MagicArrayWrapper; + magicArrayAdaptor = { + filter: function( object, keypath, ractive ) { + return magicAdaptor.filter( object, keypath, ractive ) && arrayAdaptor.filter( object ); + }, + wrap: function( ractive, array, keypath ) { + return new MagicArrayWrapper( ractive, array, keypath ); + } + }; + MagicArrayWrapper = function( ractive, array, keypath ) { + this.value = array; + this.magic = true; + this.magicWrapper = magicAdaptor.wrap( ractive, array, keypath ); + this.arrayWrapper = arrayAdaptor.wrap( ractive, array, keypath ); + }; + MagicArrayWrapper.prototype = { + get: function() { + return this.value; + }, + teardown: function() { + this.arrayWrapper.teardown(); + this.magicWrapper.teardown(); + }, + reset: function( value ) { + return this.magicWrapper.reset( value ); + } + }; + return magicArrayAdaptor; + }( shared_get_magicAdaptor, shared_get_arrayAdaptor__arrayAdaptor ); + + var shared_adaptIfNecessary = function( adaptorRegistry, arrayAdaptor, magicAdaptor, magicArrayAdaptor ) { + + var prefixers = {}; + return function adaptIfNecessary( ractive, keypath, value, isExpressionResult ) { + var len, i, adaptor, wrapped; + // Do we have an adaptor for this value? + len = ractive.adapt.length; + for ( i = 0; i < len; i += 1 ) { + adaptor = ractive.adapt[ i ]; + // Adaptors can be specified as e.g. [ 'Backbone.Model', 'Backbone.Collection' ] - + // we need to get the actual adaptor if that's the case + if ( typeof adaptor === 'string' ) { + if ( !adaptorRegistry[ adaptor ] ) { + throw new Error( 'Missing adaptor "' + adaptor + '"' ); + } + adaptor = ractive.adapt[ i ] = adaptorRegistry[ adaptor ]; + } + if ( adaptor.filter( value, keypath, ractive ) ) { + wrapped = ractive._wrapped[ keypath ] = adaptor.wrap( ractive, value, keypath, getPrefixer( keypath ) ); + wrapped.value = value; + return value; + } + } + if ( !isExpressionResult ) { + if ( ractive.magic ) { + if ( magicArrayAdaptor.filter( value, keypath, ractive ) ) { + ractive._wrapped[ keypath ] = magicArrayAdaptor.wrap( ractive, value, keypath ); + } else if ( magicAdaptor.filter( value, keypath, ractive ) ) { + ractive._wrapped[ keypath ] = magicAdaptor.wrap( ractive, value, keypath ); + } + } else if ( ractive.modifyArrays && arrayAdaptor.filter( value, keypath, ractive ) ) { + ractive._wrapped[ keypath ] = arrayAdaptor.wrap( ractive, value, keypath ); + } + } + return value; + }; + + function prefixKeypath( obj, prefix ) { + var prefixed = {}, key; + if ( !prefix ) { + return obj; + } + prefix += '.'; + for ( key in obj ) { + if ( obj.hasOwnProperty( key ) ) { + prefixed[ prefix + key ] = obj[ key ]; + } + } + return prefixed; + } + + function getPrefixer( rootKeypath ) { + var rootDot; + if ( !prefixers[ rootKeypath ] ) { + rootDot = rootKeypath ? rootKeypath + '.' : ''; + prefixers[ rootKeypath ] = function( relativeKeypath, value ) { + var obj; + if ( typeof relativeKeypath === 'string' ) { + obj = {}; + obj[ rootDot + relativeKeypath ] = value; + return obj; + } + if ( typeof relativeKeypath === 'object' ) { + // 'relativeKeypath' is in fact a hash, not a keypath + return rootDot ? prefixKeypath( relativeKeypath, rootKeypath ) : relativeKeypath; + } + }; + } + return prefixers[ rootKeypath ]; + } + }( registries_adaptors, shared_get_arrayAdaptor__arrayAdaptor, shared_get_magicAdaptor, shared_get_magicArrayAdaptor ); + + var shared_registerDependant = function() { + + return function registerDependant( dependant ) { + var depsByKeypath, deps, ractive, keypath, priority; + ractive = dependant.root; + keypath = dependant.keypath; + priority = dependant.priority; + depsByKeypath = ractive._deps[ priority ] || ( ractive._deps[ priority ] = {} ); + deps = depsByKeypath[ keypath ] || ( depsByKeypath[ keypath ] = [] ); + deps.push( dependant ); + dependant.registered = true; + if ( !keypath ) { + return; + } + updateDependantsMap( ractive, keypath ); + }; + + function updateDependantsMap( ractive, keypath ) { + var keys, parentKeypath, map; + // update dependants map + keys = keypath.split( '.' ); + while ( keys.length ) { + keys.pop(); + parentKeypath = keys.join( '.' ); + map = ractive._depsMap[ parentKeypath ] || ( ractive._depsMap[ parentKeypath ] = [] ); + if ( map[ keypath ] === undefined ) { + map[ keypath ] = 0; + map[ map.length ] = keypath; + } + map[ keypath ] += 1; + keypath = parentKeypath; + } + } + }(); + + var shared_unregisterDependant = function() { + + return function unregisterDependant( dependant ) { + var deps, index, ractive, keypath, priority; + ractive = dependant.root; + keypath = dependant.keypath; + priority = dependant.priority; + deps = ractive._deps[ priority ][ keypath ]; + index = deps.indexOf( dependant ); + if ( index === -1 || !dependant.registered ) { + throw new Error( 'Attempted to remove a dependant that was no longer registered! This should not happen. If you are seeing this bug in development please raise an issue at https://github.com/RactiveJS/Ractive/issues - thanks' ); + } + deps.splice( index, 1 ); + dependant.registered = false; + if ( !keypath ) { + return; + } + updateDependantsMap( ractive, keypath ); + }; + + function updateDependantsMap( ractive, keypath ) { + var keys, parentKeypath, map; + // update dependants map + keys = keypath.split( '.' ); + while ( keys.length ) { + keys.pop(); + parentKeypath = keys.join( '.' ); + map = ractive._depsMap[ parentKeypath ]; + map[ keypath ] -= 1; + if ( !map[ keypath ] ) { + // remove from parent deps map + map.splice( map.indexOf( keypath ), 1 ); + map[ keypath ] = undefined; + } + keypath = parentKeypath; + } + } + }(); + + var shared_createComponentBinding = function( circular, runloop, isArray, isEqual, registerDependant, unregisterDependant ) { + + var get, set; + circular.push( function() { + get = circular.get; + set = circular.set; + } ); + var Binding = function( ractive, keypath, otherInstance, otherKeypath, priority ) { + this.root = ractive; + this.keypath = keypath; + this.priority = priority; + this.otherInstance = otherInstance; + this.otherKeypath = otherKeypath; + registerDependant( this ); + this.value = get( this.root, this.keypath ); + }; + Binding.prototype = { + update: function() { + var value; + // Only *you* can prevent infinite loops + if ( this.updating || this.counterpart && this.counterpart.updating ) { + return; + } + value = get( this.root, this.keypath ); + // Is this a smart array update? If so, it'll update on its + // own, we shouldn't do anything + if ( isArray( value ) && value._ractive && value._ractive.setting ) { + return; + } + if ( !isEqual( value, this.value ) ) { + this.updating = true; + // TODO maybe the case that `value === this.value` - should that result + // in an update rather than a set? + runloop.addInstance( this.otherInstance ); + set( this.otherInstance, this.otherKeypath, value ); + this.value = value; + // TODO will the counterpart update after this line, during + // the runloop end cycle? may be a problem... + this.updating = false; + } + }, + reassign: function( newKeypath ) { + unregisterDependant( this ); + unregisterDependant( this.counterpart ); + this.keypath = newKeypath; + this.counterpart.otherKeypath = newKeypath; + registerDependant( this ); + registerDependant( this.counterpart ); + }, + teardown: function() { + unregisterDependant( this ); + } + }; + return function createComponentBinding( component, parentInstance, parentKeypath, childKeypath ) { + var hash, childInstance, bindings, priority, parentToChildBinding, childToParentBinding; + hash = parentKeypath + '=' + childKeypath; + bindings = component.bindings; + if ( bindings[ hash ] ) { + // TODO does this ever happen? + return; + } + bindings[ hash ] = true; + childInstance = component.instance; + priority = component.parentFragment.priority; + parentToChildBinding = new Binding( parentInstance, parentKeypath, childInstance, childKeypath, priority ); + bindings.push( parentToChildBinding ); + if ( childInstance.twoway ) { + childToParentBinding = new Binding( childInstance, childKeypath, parentInstance, parentKeypath, 1 ); + bindings.push( childToParentBinding ); + parentToChildBinding.counterpart = childToParentBinding; + childToParentBinding.counterpart = parentToChildBinding; + } + }; + }( circular, global_runloop, utils_isArray, utils_isEqual, shared_registerDependant, shared_unregisterDependant ); + + var shared_get_getFromParent = function( circular, createComponentBinding, set ) { + + var get; + circular.push( function() { + get = circular.get; + } ); + return function getFromParent( child, keypath ) { + var parent, fragment, keypathToTest, value, index; + parent = child._parent; + fragment = child.component.parentFragment; + // Special case - index refs + if ( fragment.indexRefs && ( index = fragment.indexRefs[ keypath ] ) !== undefined ) { + // create an index ref binding, so that it can be reassigned letter if necessary + child.component.indexRefBindings[ keypath ] = keypath; + return index; + } + do { + if ( !fragment.context ) { + continue; + } + keypathToTest = fragment.context + '.' + keypath; + value = get( parent, keypathToTest ); + if ( value !== undefined ) { + createLateComponentBinding( parent, child, keypathToTest, keypath, value ); + return value; + } + } while ( fragment = fragment.parent ); + value = get( parent, keypath ); + if ( value !== undefined ) { + createLateComponentBinding( parent, child, keypath, keypath, value ); + return value; + } + }; + + function createLateComponentBinding( parent, child, parentKeypath, childKeypath, value ) { + set( child, childKeypath, value, true ); + createComponentBinding( child.component, parent, parentKeypath, childKeypath ); + } + }( circular, shared_createComponentBinding, shared_set ); + + var shared_get_FAILED_LOOKUP = { + FAILED_LOOKUP: true + }; + + var shared_get__get = function( circular, hasOwnProperty, clone, adaptIfNecessary, getFromParent, FAILED_LOOKUP ) { + + function get( ractive, keypath, options ) { + var cache = ractive._cache, + value, computation, wrapped, evaluator; + if ( cache[ keypath ] === undefined ) { + // Is this a computed property? + if ( computation = ractive._computations[ keypath ] ) { + value = computation.value; + } else if ( wrapped = ractive._wrapped[ keypath ] ) { + value = wrapped.value; + } else if ( !keypath ) { + adaptIfNecessary( ractive, '', ractive.data ); + value = ractive.data; + } else if ( evaluator = ractive._evaluators[ keypath ] ) { + value = evaluator.value; + } else { + value = retrieve( ractive, keypath ); + } + cache[ keypath ] = value; + } else { + value = cache[ keypath ]; + } + // If the property doesn't exist on this viewmodel, we + // can try going up a scope. This will create bindings + // between parent and child if possible + if ( value === FAILED_LOOKUP ) { + if ( ractive._parent && !ractive.isolated ) { + value = getFromParent( ractive, keypath, options ); + } else { + value = undefined; + } + } + if ( options && options.evaluateWrapped && ( wrapped = ractive._wrapped[ keypath ] ) ) { + value = wrapped.get(); + } + return value; + } + circular.get = get; + return get; + + function retrieve( ractive, keypath ) { + var keys, key, parentKeypath, parentValue, cacheMap, value, wrapped, shouldClone; + keys = keypath.split( '.' ); + key = keys.pop(); + parentKeypath = keys.join( '.' ); + parentValue = get( ractive, parentKeypath ); + if ( wrapped = ractive._wrapped[ parentKeypath ] ) { + parentValue = wrapped.get(); + } + if ( parentValue === null || parentValue === undefined ) { + return; + } + // update cache map + if ( !( cacheMap = ractive._cacheMap[ parentKeypath ] ) ) { + ractive._cacheMap[ parentKeypath ] = [ keypath ]; + } else { + if ( cacheMap.indexOf( keypath ) === -1 ) { + cacheMap.push( keypath ); + } + } + // If this property doesn't exist, we return a sentinel value + // so that we know to query parent scope (if such there be) + if ( typeof parentValue === 'object' && !( key in parentValue ) ) { + return ractive._cache[ keypath ] = FAILED_LOOKUP; + } + // If this value actually lives on the prototype of this + // instance's `data`, and not as an own property, we need to + // clone it. Otherwise the instance could end up manipulating + // data that doesn't belong to it + shouldClone = !hasOwnProperty.call( parentValue, key ); + value = shouldClone ? clone( parentValue[ key ] ) : parentValue[ key ]; + // Do we have an adaptor for this value? + value = adaptIfNecessary( ractive, keypath, value, false ); + // Update cache + ractive._cache[ keypath ] = value; + return value; + } + }( circular, utils_hasOwnProperty, utils_clone, shared_adaptIfNecessary, shared_get_getFromParent, shared_get_FAILED_LOOKUP ); + + /* global console */ + var utils_warn = function() { + + if ( typeof console !== 'undefined' && typeof console.warn === 'function' && typeof console.warn.apply === 'function' ) { + return function() { + console.warn.apply( console, arguments ); + }; + } + return function() {}; + }(); + + var utils_isObject = function() { + + var toString = Object.prototype.toString; + return function( thing ) { + return typeof thing === 'object' && toString.call( thing ) === '[object Object]'; + }; + }(); + + var registries_interpolators = function( circular, hasOwnProperty, isArray, isObject, isNumeric ) { + + var interpolators, interpolate, cssLengthPattern; + circular.push( function() { + interpolate = circular.interpolate; + } ); + cssLengthPattern = /^([+-]?[0-9]+\.?(?:[0-9]+)?)(px|em|ex|%|in|cm|mm|pt|pc)$/; + interpolators = { + number: function( from, to ) { + var delta; + if ( !isNumeric( from ) || !isNumeric( to ) ) { + return null; + } + from = +from; + to = +to; + delta = to - from; + if ( !delta ) { + return function() { + return from; + }; + } + return function( t ) { + return from + t * delta; + }; + }, + array: function( from, to ) { + var intermediate, interpolators, len, i; + if ( !isArray( from ) || !isArray( to ) ) { + return null; + } + intermediate = []; + interpolators = []; + i = len = Math.min( from.length, to.length ); + while ( i-- ) { + interpolators[ i ] = interpolate( from[ i ], to[ i ] ); + } + // surplus values - don't interpolate, but don't exclude them either + for ( i = len; i < from.length; i += 1 ) { + intermediate[ i ] = from[ i ]; + } + for ( i = len; i < to.length; i += 1 ) { + intermediate[ i ] = to[ i ]; + } + return function( t ) { + var i = len; + while ( i-- ) { + intermediate[ i ] = interpolators[ i ]( t ); + } + return intermediate; + }; + }, + object: function( from, to ) { + var properties, len, interpolators, intermediate, prop; + if ( !isObject( from ) || !isObject( to ) ) { + return null; + } + properties = []; + intermediate = {}; + interpolators = {}; + for ( prop in from ) { + if ( hasOwnProperty.call( from, prop ) ) { + if ( hasOwnProperty.call( to, prop ) ) { + properties.push( prop ); + interpolators[ prop ] = interpolate( from[ prop ], to[ prop ] ); + } else { + intermediate[ prop ] = from[ prop ]; + } + } + } + for ( prop in to ) { + if ( hasOwnProperty.call( to, prop ) && !hasOwnProperty.call( from, prop ) ) { + intermediate[ prop ] = to[ prop ]; + } + } + len = properties.length; + return function( t ) { + var i = len, + prop; + while ( i-- ) { + prop = properties[ i ]; + intermediate[ prop ] = interpolators[ prop ]( t ); + } + return intermediate; + }; + }, + cssLength: function( from, to ) { + var fromMatch, toMatch, fromUnit, toUnit, fromValue, toValue, unit, delta; + if ( from !== 0 && typeof from !== 'string' || to !== 0 && typeof to !== 'string' ) { + return null; + } + fromMatch = cssLengthPattern.exec( from ); + toMatch = cssLengthPattern.exec( to ); + fromUnit = fromMatch ? fromMatch[ 2 ] : ''; + toUnit = toMatch ? toMatch[ 2 ] : ''; + if ( fromUnit && toUnit && fromUnit !== toUnit ) { + return null; + } + unit = fromUnit || toUnit; + fromValue = fromMatch ? +fromMatch[ 1 ] : 0; + toValue = toMatch ? +toMatch[ 1 ] : 0; + delta = toValue - fromValue; + if ( !delta ) { + return function() { + return fromValue + unit; + }; + } + return function( t ) { + return fromValue + t * delta + unit; + }; + } + }; + return interpolators; + }( circular, utils_hasOwnProperty, utils_isArray, utils_isObject, utils_isNumeric ); + + var shared_interpolate = function( circular, warn, interpolators ) { + + var interpolate = function( from, to, ractive, type ) { + if ( from === to ) { + return snap( to ); + } + if ( type ) { + if ( ractive.interpolators[ type ] ) { + return ractive.interpolators[ type ]( from, to ) || snap( to ); + } + warn( 'Missing "' + type + '" interpolator. You may need to download a plugin from [TODO]' ); + } + return interpolators.number( from, to ) || interpolators.array( from, to ) || interpolators.object( from, to ) || interpolators.cssLength( from, to ) || snap( to ); + }; + circular.interpolate = interpolate; + return interpolate; + + function snap( to ) { + return function() { + return to; + }; + } + }( circular, utils_warn, registries_interpolators ); + + var Ractive_prototype_animate_Animation = function( warn, runloop, interpolate, set ) { + + var Animation = function( options ) { + var key; + this.startTime = Date.now(); + // from and to + for ( key in options ) { + if ( options.hasOwnProperty( key ) ) { + this[ key ] = options[ key ]; + } + } + this.interpolator = interpolate( this.from, this.to, this.root, this.interpolator ); + this.running = true; + }; + Animation.prototype = { + tick: function() { + var elapsed, t, value, timeNow, index, keypath; + keypath = this.keypath; + if ( this.running ) { + timeNow = Date.now(); + elapsed = timeNow - this.startTime; + if ( elapsed >= this.duration ) { + if ( keypath !== null ) { + runloop.start( this.root ); + set( this.root, keypath, this.to ); + runloop.end(); + } + if ( this.step ) { + this.step( 1, this.to ); + } + this.complete( this.to ); + index = this.root._animations.indexOf( this ); + // TODO investigate why this happens + if ( index === -1 ) { + warn( 'Animation was not found' ); + } + this.root._animations.splice( index, 1 ); + this.running = false; + return false; + } + t = this.easing ? this.easing( elapsed / this.duration ) : elapsed / this.duration; + if ( keypath !== null ) { + value = this.interpolator( t ); + runloop.start( this.root ); + set( this.root, keypath, value ); + runloop.end(); + } + if ( this.step ) { + this.step( t, value ); + } + return true; + } + return false; + }, + stop: function() { + var index; + this.running = false; + index = this.root._animations.indexOf( this ); + // TODO investigate why this happens + if ( index === -1 ) { + warn( 'Animation was not found' ); + } + this.root._animations.splice( index, 1 ); + } + }; + return Animation; + }( utils_warn, global_runloop, shared_interpolate, shared_set ); + + var Ractive_prototype_animate__animate = function( isEqual, Promise, normaliseKeypath, animations, get, Animation ) { + + var noop = function() {}, noAnimation = { + stop: noop + }; + return function( keypath, to, options ) { + var promise, fulfilPromise, k, animation, animations, easing, duration, step, complete, makeValueCollector, currentValues, collectValue, dummy, dummyOptions; + promise = new Promise( function( fulfil ) { + fulfilPromise = fulfil; + } ); + // animate multiple keypaths + if ( typeof keypath === 'object' ) { + options = to || {}; + easing = options.easing; + duration = options.duration; + animations = []; + // we don't want to pass the `step` and `complete` handlers, as they will + // run for each animation! So instead we'll store the handlers and create + // our own... + step = options.step; + complete = options.complete; + if ( step || complete ) { + currentValues = {}; + options.step = null; + options.complete = null; + makeValueCollector = function( keypath ) { + return function( t, value ) { + currentValues[ keypath ] = value; + }; + }; + } + for ( k in keypath ) { + if ( keypath.hasOwnProperty( k ) ) { + if ( step || complete ) { + collectValue = makeValueCollector( k ); + options = { + easing: easing, + duration: duration + }; + if ( step ) { + options.step = collectValue; + } + } + options.complete = complete ? collectValue : noop; + animations.push( animate( this, k, keypath[ k ], options ) ); + } + } + if ( step || complete ) { + dummyOptions = { + easing: easing, + duration: duration + }; + if ( step ) { + dummyOptions.step = function( t ) { + step( t, currentValues ); + }; + } + if ( complete ) { + promise.then( function( t ) { + complete( t, currentValues ); + } ); + } + dummyOptions.complete = fulfilPromise; + dummy = animate( this, null, null, dummyOptions ); + animations.push( dummy ); + } + return { + stop: function() { + var animation; + while ( animation = animations.pop() ) { + animation.stop(); + } + if ( dummy ) { + dummy.stop(); + } + } + }; + } + // animate a single keypath + options = options || {}; + if ( options.complete ) { + promise.then( options.complete ); + } + options.complete = fulfilPromise; + animation = animate( this, keypath, to, options ); + promise.stop = function() { + animation.stop(); + }; + return promise; + }; + + function animate( root, keypath, to, options ) { + var easing, duration, animation, from; + if ( keypath ) { + keypath = normaliseKeypath( keypath ); + } + if ( keypath !== null ) { + from = get( root, keypath ); + } + // cancel any existing animation + // TODO what about upstream/downstream keypaths? + animations.abort( keypath, root ); + // don't bother animating values that stay the same + if ( isEqual( from, to ) ) { + if ( options.complete ) { + options.complete( options.to ); + } + return noAnimation; + } + // easing function + if ( options.easing ) { + if ( typeof options.easing === 'function' ) { + easing = options.easing; + } else { + easing = root.easing[ options.easing ]; + } + if ( typeof easing !== 'function' ) { + easing = null; + } + } + // duration + duration = options.duration === undefined ? 400 : options.duration; + // TODO store keys, use an internal set method + animation = new Animation( { + keypath: keypath, + from: from, + to: to, + root: root, + duration: duration, + easing: easing, + interpolator: options.interpolator, + // TODO wrap callbacks if necessary, to use instance as context + step: options.step, + complete: options.complete + } ); + animations.add( animation ); + root._animations.push( animation ); + return animation; + } + }( utils_isEqual, utils_Promise, utils_normaliseKeypath, shared_animations, shared_get__get, Ractive_prototype_animate_Animation ); + + var Ractive_prototype_detach = function() { + return this.fragment.detach(); + }; + + var Ractive_prototype_find = function( selector ) { + if ( !this.el ) { + return null; + } + return this.fragment.find( selector ); + }; + + var utils_matches = function( isClient, vendors, createElement ) { + + var div, methodNames, unprefixed, prefixed, i, j, makeFunction; + if ( !isClient ) { + return; + } + div = createElement( 'div' ); + methodNames = [ + 'matches', + 'matchesSelector' + ]; + makeFunction = function( methodName ) { + return function( node, selector ) { + return node[ methodName ]( selector ); + }; + }; + i = methodNames.length; + while ( i-- ) { + unprefixed = methodNames[ i ]; + if ( div[ unprefixed ] ) { + return makeFunction( unprefixed ); + } + j = vendors.length; + while ( j-- ) { + prefixed = vendors[ i ] + unprefixed.substr( 0, 1 ).toUpperCase() + unprefixed.substring( 1 ); + if ( div[ prefixed ] ) { + return makeFunction( prefixed ); + } + } + } + // IE8... + return function( node, selector ) { + var nodes, i; + nodes = ( node.parentNode || node.document ).querySelectorAll( selector ); + i = nodes.length; + while ( i-- ) { + if ( nodes[ i ] === node ) { + return true; + } + } + return false; + }; + }( config_isClient, config_vendors, utils_createElement ); + + var Ractive_prototype_shared_makeQuery_test = function( matches ) { + + return function( item, noDirty ) { + var itemMatches = this._isComponentQuery ? !this.selector || item.name === this.selector : matches( item.node, this.selector ); + if ( itemMatches ) { + this.push( item.node || item.instance ); + if ( !noDirty ) { + this._makeDirty(); + } + return true; + } + }; + }( utils_matches ); + + var Ractive_prototype_shared_makeQuery_cancel = function() { + var liveQueries, selector, index; + liveQueries = this._root[ this._isComponentQuery ? 'liveComponentQueries' : 'liveQueries' ]; + selector = this.selector; + index = liveQueries.indexOf( selector ); + if ( index !== -1 ) { + liveQueries.splice( index, 1 ); + liveQueries[ selector ] = null; + } + }; + + var Ractive_prototype_shared_makeQuery_sortByItemPosition = function() { + + return function( a, b ) { + var ancestryA, ancestryB, oldestA, oldestB, mutualAncestor, indexA, indexB, fragments, fragmentA, fragmentB; + ancestryA = getAncestry( a.component || a._ractive.proxy ); + ancestryB = getAncestry( b.component || b._ractive.proxy ); + oldestA = ancestryA[ ancestryA.length - 1 ]; + oldestB = ancestryB[ ancestryB.length - 1 ]; + // remove items from the end of both ancestries as long as they are identical + // - the final one removed is the closest mutual ancestor + while ( oldestA && oldestA === oldestB ) { + ancestryA.pop(); + ancestryB.pop(); + mutualAncestor = oldestA; + oldestA = ancestryA[ ancestryA.length - 1 ]; + oldestB = ancestryB[ ancestryB.length - 1 ]; + } + // now that we have the mutual ancestor, we can find which is earliest + oldestA = oldestA.component || oldestA; + oldestB = oldestB.component || oldestB; + fragmentA = oldestA.parentFragment; + fragmentB = oldestB.parentFragment; + // if both items share a parent fragment, our job is easy + if ( fragmentA === fragmentB ) { + indexA = fragmentA.items.indexOf( oldestA ); + indexB = fragmentB.items.indexOf( oldestB ); + // if it's the same index, it means one contains the other, + // so we see which has the longest ancestry + return indexA - indexB || ancestryA.length - ancestryB.length; + } + // if mutual ancestor is a section, we first test to see which section + // fragment comes first + if ( fragments = mutualAncestor.fragments ) { + indexA = fragments.indexOf( fragmentA ); + indexB = fragments.indexOf( fragmentB ); + return indexA - indexB || ancestryA.length - ancestryB.length; + } + throw new Error( 'An unexpected condition was met while comparing the position of two components. Please file an issue at https://github.com/RactiveJS/Ractive/issues - thanks!' ); + }; + + function getParent( item ) { + var parentFragment; + if ( parentFragment = item.parentFragment ) { + return parentFragment.owner; + } + if ( item.component && ( parentFragment = item.component.parentFragment ) ) { + return parentFragment.owner; + } + } + + function getAncestry( item ) { + var ancestry, ancestor; + ancestry = [ item ]; + ancestor = getParent( item ); + while ( ancestor ) { + ancestry.push( ancestor ); + ancestor = getParent( ancestor ); + } + return ancestry; + } + }(); + + var Ractive_prototype_shared_makeQuery_sortByDocumentPosition = function( sortByItemPosition ) { + + return function( node, otherNode ) { + var bitmask; + if ( node.compareDocumentPosition ) { + bitmask = node.compareDocumentPosition( otherNode ); + return bitmask & 2 ? 1 : -1; + } + // In old IE, we can piggy back on the mechanism for + // comparing component positions + return sortByItemPosition( node, otherNode ); + }; + }( Ractive_prototype_shared_makeQuery_sortByItemPosition ); + + var Ractive_prototype_shared_makeQuery_sort = function( sortByDocumentPosition, sortByItemPosition ) { + + return function() { + this.sort( this._isComponentQuery ? sortByItemPosition : sortByDocumentPosition ); + this._dirty = false; + }; + }( Ractive_prototype_shared_makeQuery_sortByDocumentPosition, Ractive_prototype_shared_makeQuery_sortByItemPosition ); + + var Ractive_prototype_shared_makeQuery_dirty = function( runloop ) { + + return function() { + if ( !this._dirty ) { + runloop.addLiveQuery( this ); + this._dirty = true; + } + }; + }( global_runloop ); + + var Ractive_prototype_shared_makeQuery_remove = function( nodeOrComponent ) { + var index = this.indexOf( this._isComponentQuery ? nodeOrComponent.instance : nodeOrComponent ); + if ( index !== -1 ) { + this.splice( index, 1 ); + } + }; + + var Ractive_prototype_shared_makeQuery__makeQuery = function( defineProperties, test, cancel, sort, dirty, remove ) { + + return function( ractive, selector, live, isComponentQuery ) { + var query = []; + defineProperties( query, { + selector: { + value: selector + }, + live: { + value: live + }, + _isComponentQuery: { + value: isComponentQuery + }, + _test: { + value: test + } + } ); + if ( !live ) { + return query; + } + defineProperties( query, { + cancel: { + value: cancel + }, + _root: { + value: ractive + }, + _sort: { + value: sort + }, + _makeDirty: { + value: dirty + }, + _remove: { + value: remove + }, + _dirty: { + value: false, + writable: true + } + } ); + return query; + }; + }( utils_defineProperties, Ractive_prototype_shared_makeQuery_test, Ractive_prototype_shared_makeQuery_cancel, Ractive_prototype_shared_makeQuery_sort, Ractive_prototype_shared_makeQuery_dirty, Ractive_prototype_shared_makeQuery_remove ); + + var Ractive_prototype_findAll = function( makeQuery ) { + + return function( selector, options ) { + var liveQueries, query; + if ( !this.el ) { + return []; + } + options = options || {}; + liveQueries = this._liveQueries; + // Shortcut: if we're maintaining a live query with this + // selector, we don't need to traverse the parallel DOM + if ( query = liveQueries[ selector ] ) { + // Either return the exact same query, or (if not live) a snapshot + return options && options.live ? query : query.slice(); + } + query = makeQuery( this, selector, !! options.live, false ); + // Add this to the list of live queries Ractive needs to maintain, + // if applicable + if ( query.live ) { + liveQueries.push( selector ); + liveQueries[ selector ] = query; + } + this.fragment.findAll( selector, query ); + return query; + }; + }( Ractive_prototype_shared_makeQuery__makeQuery ); + + var Ractive_prototype_findAllComponents = function( makeQuery ) { + + return function( selector, options ) { + var liveQueries, query; + options = options || {}; + liveQueries = this._liveComponentQueries; + // Shortcut: if we're maintaining a live query with this + // selector, we don't need to traverse the parallel DOM + if ( query = liveQueries[ selector ] ) { + // Either return the exact same query, or (if not live) a snapshot + return options && options.live ? query : query.slice(); + } + query = makeQuery( this, selector, !! options.live, true ); + // Add this to the list of live queries Ractive needs to maintain, + // if applicable + if ( query.live ) { + liveQueries.push( selector ); + liveQueries[ selector ] = query; + } + this.fragment.findAllComponents( selector, query ); + return query; + }; + }( Ractive_prototype_shared_makeQuery__makeQuery ); + + var Ractive_prototype_findComponent = function( selector ) { + return this.fragment.findComponent( selector ); + }; + + var Ractive_prototype_fire = function( eventName ) { + var args, i, len, subscribers = this._subs[ eventName ]; + if ( !subscribers ) { + return; + } + args = Array.prototype.slice.call( arguments, 1 ); + for ( i = 0, len = subscribers.length; i < len; i += 1 ) { + subscribers[ i ].apply( this, args ); + } + }; + + var shared_get_UnresolvedImplicitDependency = function( circular, removeFromArray, runloop, notifyDependants ) { + + var get, empty = {}; + circular.push( function() { + get = circular.get; + } ); + var UnresolvedImplicitDependency = function( ractive, keypath ) { + this.root = ractive; + this.ref = keypath; + this.parentFragment = empty; + ractive._unresolvedImplicitDependencies[ keypath ] = true; + ractive._unresolvedImplicitDependencies.push( this ); + runloop.addUnresolved( this ); + }; + UnresolvedImplicitDependency.prototype = { + resolve: function() { + var ractive = this.root; + notifyDependants( ractive, this.ref ); + ractive._unresolvedImplicitDependencies[ this.ref ] = false; + removeFromArray( ractive._unresolvedImplicitDependencies, this ); + }, + teardown: function() { + runloop.removeUnresolved( this ); + } + }; + return UnresolvedImplicitDependency; + }( circular, utils_removeFromArray, global_runloop, shared_notifyDependants ); + + var Ractive_prototype_get = function( normaliseKeypath, get, UnresolvedImplicitDependency ) { + + var options = { + isTopLevel: true + }; + return function Ractive_prototype_get( keypath ) { + var value; + keypath = normaliseKeypath( keypath ); + value = get( this, keypath, options ); + // capture the dependency, if we're inside an evaluator + if ( this._captured && this._captured[ keypath ] !== true ) { + this._captured.push( keypath ); + this._captured[ keypath ] = true; + // if we couldn't resolve the keypath, we need to make it as a failed + // lookup, so that the evaluator updates correctly once we CAN + // resolve the keypath + if ( value === undefined && this._unresolvedImplicitDependencies[ keypath ] !== true ) { + new UnresolvedImplicitDependency( this, keypath ); + } + } + return value; + }; + }( utils_normaliseKeypath, shared_get__get, shared_get_UnresolvedImplicitDependency ); + + var utils_getElement = function( input ) { + var output; + if ( typeof window === 'undefined' || !document || !input ) { + return null; + } + // We already have a DOM node - no work to do. (Duck typing alert!) + if ( input.nodeType ) { + return input; + } + // Get node from string + if ( typeof input === 'string' ) { + // try ID first + output = document.getElementById( input ); + // then as selector, if possible + if ( !output && document.querySelector ) { + output = document.querySelector( input ); + } + // did it work? + if ( output && output.nodeType ) { + return output; + } + } + // If we've been given a collection (jQuery, Zepto etc), extract the first item + if ( input[ 0 ] && input[ 0 ].nodeType ) { + return input[ 0 ]; + } + return null; + }; + + var Ractive_prototype_insert = function( getElement ) { + + return function( target, anchor ) { + target = getElement( target ); + anchor = getElement( anchor ) || null; + if ( !target ) { + throw new Error( 'You must specify a valid target to insert into' ); + } + target.insertBefore( this.detach(), anchor ); + this.fragment.pNode = this.el = target; + }; + }( utils_getElement ); + + var Ractive_prototype_merge_mapOldToNewIndex = function( oldArray, newArray ) { + var usedIndices, firstUnusedIndex, newIndices, changed; + usedIndices = {}; + firstUnusedIndex = 0; + newIndices = oldArray.map( function( item, i ) { + var index, start, len; + start = firstUnusedIndex; + len = newArray.length; + do { + index = newArray.indexOf( item, start ); + if ( index === -1 ) { + changed = true; + return -1; + } + start = index + 1; + } while ( usedIndices[ index ] && start < len ); + // keep track of the first unused index, so we don't search + // the whole of newArray for each item in oldArray unnecessarily + if ( index === firstUnusedIndex ) { + firstUnusedIndex += 1; + } + if ( index !== i ) { + changed = true; + } + usedIndices[ index ] = true; + return index; + } ); + newIndices.unchanged = !changed; + return newIndices; + }; + + var Ractive_prototype_merge_propagateChanges = function( types, notifyDependants ) { + + return function( ractive, keypath, newIndices, lengthUnchanged ) { + var updateDependant; + ractive._changes.push( keypath ); + updateDependant = function( dependant ) { + // references need to get processed before mustaches + if ( dependant.type === types.REFERENCE ) { + dependant.update(); + } else if ( dependant.keypath === keypath && dependant.type === types.SECTION && !dependant.inverted && dependant.docFrag ) { + dependant.merge( newIndices ); + } else { + dependant.update(); + } + }; + // Go through all dependant priority levels, finding merge targets + ractive._deps.forEach( function( depsByKeypath ) { + var dependants = depsByKeypath[ keypath ]; + if ( dependants ) { + dependants.forEach( updateDependant ); + } + } ); + // length property has changed - notify dependants + // TODO in some cases (e.g. todo list example, when marking all as complete, then + // adding a new item (which should deactivate the 'all complete' checkbox + // but doesn't) this needs to happen before other updates. But doing so causes + // other mental problems. not sure what's going on... + if ( !lengthUnchanged ) { + notifyDependants( ractive, keypath + '.length', true ); + } + }; + }( config_types, shared_notifyDependants ); + + var Ractive_prototype_merge__merge = function( runloop, warn, isArray, Promise, set, mapOldToNewIndex, propagateChanges ) { + + var comparators = {}; + return function merge( keypath, array, options ) { + var currentArray, oldArray, newArray, comparator, lengthUnchanged, newIndices, promise, fulfilPromise; + currentArray = this.get( keypath ); + // If either the existing value or the new value isn't an + // array, just do a regular set + if ( !isArray( currentArray ) || !isArray( array ) ) { + return this.set( keypath, array, options && options.complete ); + } + lengthUnchanged = currentArray.length === array.length; + if ( options && options.compare ) { + comparator = getComparatorFunction( options.compare ); + try { + oldArray = currentArray.map( comparator ); + newArray = array.map( comparator ); + } catch ( err ) { + // fallback to an identity check - worst case scenario we have + // to do more DOM manipulation than we thought... + // ...unless we're in debug mode of course + if ( this.debug ) { + throw err; + } else { + warn( 'Merge operation: comparison failed. Falling back to identity checking' ); + } + oldArray = currentArray; + newArray = array; + } + } else { + oldArray = currentArray; + newArray = array; + } + // find new indices for members of oldArray + newIndices = mapOldToNewIndex( oldArray, newArray ); + // Manage transitions + promise = new Promise( function( fulfil ) { + fulfilPromise = fulfil; + } ); + runloop.start( this, fulfilPromise ); + // Update the model + // TODO allow existing array to be updated in place, rather than replaced? + set( this, keypath, array, true ); + propagateChanges( this, keypath, newIndices, lengthUnchanged ); + runloop.end(); + // attach callback as fulfilment handler, if specified + if ( options && options.complete ) { + promise.then( options.complete ); + } + return promise; + }; + + function stringify( item ) { + return JSON.stringify( item ); + } + + function getComparatorFunction( comparator ) { + // If `compare` is `true`, we use JSON.stringify to compare + // objects that are the same shape, but non-identical - i.e. + // { foo: 'bar' } !== { foo: 'bar' } + if ( comparator === true ) { + return stringify; + } + if ( typeof comparator === 'string' ) { + if ( !comparators[ comparator ] ) { + comparators[ comparator ] = function( item ) { + return item[ comparator ]; + }; + } + return comparators[ comparator ]; + } + if ( typeof comparator === 'function' ) { + return comparator; + } + throw new Error( 'The `compare` option must be a function, or a string representing an identifying field (or `true` to use JSON.stringify)' ); + } + }( global_runloop, utils_warn, utils_isArray, utils_Promise, shared_set, Ractive_prototype_merge_mapOldToNewIndex, Ractive_prototype_merge_propagateChanges ); + + var Ractive_prototype_observe_Observer = function( runloop, isEqual, get ) { + + var Observer = function( ractive, keypath, callback, options ) { + var self = this; + this.root = ractive; + this.keypath = keypath; + this.callback = callback; + this.defer = options.defer; + this.debug = options.debug; + this.proxy = { + update: function() { + self.reallyUpdate(); + } + }; + // Observers are notified before any DOM changes take place (though + // they can defer execution until afterwards) + this.priority = 0; + // default to root as context, but allow it to be overridden + this.context = options && options.context ? options.context : ractive; + }; + Observer.prototype = { + init: function( immediate ) { + if ( immediate !== false ) { + this.update(); + } else { + this.value = get( this.root, this.keypath ); + } + }, + update: function() { + if ( this.defer && this.ready ) { + runloop.addObserver( this.proxy ); + return; + } + this.reallyUpdate(); + }, + reallyUpdate: function() { + var oldValue, newValue; + oldValue = this.value; + newValue = get( this.root, this.keypath ); + this.value = newValue; + // Prevent infinite loops + if ( this.updating ) { + return; + } + this.updating = true; + if ( !isEqual( newValue, oldValue ) || !this.ready ) { + // wrap the callback in a try-catch block, and only throw error in + // debug mode + try { + this.callback.call( this.context, newValue, oldValue, this.keypath ); + } catch ( err ) { + if ( this.debug || this.root.debug ) { + throw err; + } + } + } + this.updating = false; + } + }; + return Observer; + }( global_runloop, utils_isEqual, shared_get__get ); + + var Ractive_prototype_observe_getPattern = function( isArray ) { + + return function( ractive, pattern ) { + var keys, key, values, toGet, newToGet, expand, concatenate; + keys = pattern.split( '.' ); + toGet = []; + expand = function( keypath ) { + var value, key; + value = ractive._wrapped[ keypath ] ? ractive._wrapped[ keypath ].get() : ractive.get( keypath ); + for ( key in value ) { + if ( value.hasOwnProperty( key ) && ( key !== '_ractive' || !isArray( value ) ) ) { + // for benefit of IE8 + newToGet.push( keypath + '.' + key ); + } + } + }; + concatenate = function( keypath ) { + return keypath + '.' + key; + }; + while ( key = keys.shift() ) { + if ( key === '*' ) { + newToGet = []; + toGet.forEach( expand ); + toGet = newToGet; + } else { + if ( !toGet[ 0 ] ) { + toGet[ 0 ] = key; + } else { + toGet = toGet.map( concatenate ); + } + } + } + values = {}; + toGet.forEach( function( keypath ) { + values[ keypath ] = ractive.get( keypath ); + } ); + return values; + }; + }( utils_isArray ); + + var Ractive_prototype_observe_PatternObserver = function( runloop, isEqual, get, getPattern ) { + + var PatternObserver, wildcard = /\*/; + PatternObserver = function( ractive, keypath, callback, options ) { + this.root = ractive; + this.callback = callback; + this.defer = options.defer; + this.debug = options.debug; + this.keypath = keypath; + this.regex = new RegExp( '^' + keypath.replace( /\./g, '\\.' ).replace( /\*/g, '[^\\.]+' ) + '$' ); + this.values = {}; + if ( this.defer ) { + this.proxies = []; + } + // Observers are notified before any DOM changes take place (though + // they can defer execution until afterwards) + this.priority = 'pattern'; + // default to root as context, but allow it to be overridden + this.context = options && options.context ? options.context : ractive; + }; + PatternObserver.prototype = { + init: function( immediate ) { + var values, keypath; + values = getPattern( this.root, this.keypath ); + if ( immediate !== false ) { + for ( keypath in values ) { + if ( values.hasOwnProperty( keypath ) ) { + this.update( keypath ); + } + } + } else { + this.values = values; + } + }, + update: function( keypath ) { + var values; + if ( wildcard.test( keypath ) ) { + values = getPattern( this.root, keypath ); + for ( keypath in values ) { + if ( values.hasOwnProperty( keypath ) ) { + this.update( keypath ); + } + } + return; + } + if ( this.defer && this.ready ) { + runloop.addObserver( this.getProxy( keypath ) ); + return; + } + this.reallyUpdate( keypath ); + }, + reallyUpdate: function( keypath ) { + var value = get( this.root, keypath ); + // Prevent infinite loops + if ( this.updating ) { + this.values[ keypath ] = value; + return; + } + this.updating = true; + if ( !isEqual( value, this.values[ keypath ] ) || !this.ready ) { + // wrap the callback in a try-catch block, and only throw error in + // debug mode + try { + this.callback.call( this.context, value, this.values[ keypath ], keypath ); + } catch ( err ) { + if ( this.debug || this.root.debug ) { + throw err; + } + } + this.values[ keypath ] = value; + } + this.updating = false; + }, + getProxy: function( keypath ) { + var self = this; + if ( !this.proxies[ keypath ] ) { + this.proxies[ keypath ] = { + update: function() { + self.reallyUpdate( keypath ); + } + }; + } + return this.proxies[ keypath ]; + } + }; + return PatternObserver; + }( global_runloop, utils_isEqual, shared_get__get, Ractive_prototype_observe_getPattern ); + + var Ractive_prototype_observe_getObserverFacade = function( normaliseKeypath, registerDependant, unregisterDependant, Observer, PatternObserver ) { + + var wildcard = /\*/, + emptyObject = {}; + return function getObserverFacade( ractive, keypath, callback, options ) { + var observer, isPatternObserver; + keypath = normaliseKeypath( keypath ); + options = options || emptyObject; + // pattern observers are treated differently + if ( wildcard.test( keypath ) ) { + observer = new PatternObserver( ractive, keypath, callback, options ); + ractive._patternObservers.push( observer ); + isPatternObserver = true; + } else { + observer = new Observer( ractive, keypath, callback, options ); + } + registerDependant( observer ); + observer.init( options.init ); + // This flag allows observers to initialise even with undefined values + observer.ready = true; + return { + cancel: function() { + var index; + if ( isPatternObserver ) { + index = ractive._patternObservers.indexOf( observer ); + if ( index !== -1 ) { + ractive._patternObservers.splice( index, 1 ); + } + } + unregisterDependant( observer ); + } + }; + }; + }( utils_normaliseKeypath, shared_registerDependant, shared_unregisterDependant, Ractive_prototype_observe_Observer, Ractive_prototype_observe_PatternObserver ); + + var Ractive_prototype_observe__observe = function( isObject, getObserverFacade ) { + + return function observe( keypath, callback, options ) { + var observers, map, keypaths, i; + // Allow a map of keypaths to handlers + if ( isObject( keypath ) ) { + options = callback; + map = keypath; + observers = []; + for ( keypath in map ) { + if ( map.hasOwnProperty( keypath ) ) { + callback = map[ keypath ]; + observers.push( this.observe( keypath, callback, options ) ); + } + } + return { + cancel: function() { + while ( observers.length ) { + observers.pop().cancel(); + } + } + }; + } + // Allow `ractive.observe( callback )` - i.e. observe entire model + if ( typeof keypath === 'function' ) { + options = callback; + callback = keypath; + keypath = ''; + return getObserverFacade( this, keypath, callback, options ); + } + keypaths = keypath.split( ' ' ); + // Single keypath + if ( keypaths.length === 1 ) { + return getObserverFacade( this, keypath, callback, options ); + } + // Multiple space-separated keypaths + observers = []; + i = keypaths.length; + while ( i-- ) { + keypath = keypaths[ i ]; + if ( keypath ) { + observers.push( getObserverFacade( this, keypath, callback, options ) ); + } + } + return { + cancel: function() { + while ( observers.length ) { + observers.pop().cancel(); + } + } + }; + }; + }( utils_isObject, Ractive_prototype_observe_getObserverFacade ); + + var Ractive_prototype_off = function( eventName, callback ) { + var subscribers, index; + // if no callback specified, remove all callbacks + if ( !callback ) { + // if no event name specified, remove all callbacks for all events + if ( !eventName ) { + // TODO use this code instead, once the following issue has been resolved + // in PhantomJS (tests are unpassable otherwise!) + // https://github.com/ariya/phantomjs/issues/11856 + // defineProperty( this, '_subs', { value: create( null ), configurable: true }); + for ( eventName in this._subs ) { + delete this._subs[ eventName ]; + } + } else { + this._subs[ eventName ] = []; + } + } + subscribers = this._subs[ eventName ]; + if ( subscribers ) { + index = subscribers.indexOf( callback ); + if ( index !== -1 ) { + subscribers.splice( index, 1 ); + } + } + }; + + var Ractive_prototype_on = function( eventName, callback ) { + var self = this, + listeners, n; + // allow mutliple listeners to be bound in one go + if ( typeof eventName === 'object' ) { + listeners = []; + for ( n in eventName ) { + if ( eventName.hasOwnProperty( n ) ) { + listeners.push( this.on( n, eventName[ n ] ) ); + } + } + return { + cancel: function() { + var listener; + while ( listener = listeners.pop() ) { + listener.cancel(); + } + } + }; + } + if ( !this._subs[ eventName ] ) { + this._subs[ eventName ] = [ callback ]; + } else { + this._subs[ eventName ].push( callback ); + } + return { + cancel: function() { + self.off( eventName, callback ); + } + }; + }; + + var utils_create = function() { + + var create; + try { + Object.create( null ); + create = Object.create; + } catch ( err ) { + // sigh + create = function() { + var F = function() {}; + return function( proto, props ) { + var obj; + if ( proto === null ) { + return {}; + } + F.prototype = proto; + obj = new F(); + if ( props ) { + Object.defineProperties( obj, props ); + } + return obj; + }; + }(); + } + return create; + }(); + + var render_shared_Fragment_initialise = function( types, create ) { + + return function initFragment( fragment, options ) { + var numItems, i, parentFragment, parentRefs, ref; + // The item that owns this fragment - an element, section, partial, or attribute + fragment.owner = options.owner; + parentFragment = fragment.parent = fragment.owner.parentFragment; + // inherited properties + fragment.root = options.root; + fragment.pNode = options.pNode; + fragment.pElement = options.pElement; + fragment.context = options.context; + // If parent item is a section, this may not be the only fragment + // that belongs to it - we need to make a note of the index + if ( fragment.owner.type === types.SECTION ) { + fragment.index = options.index; + } + // index references (the 'i' in {{#section:i}}{{/section}}) need to cascade + // down the tree + if ( parentFragment ) { + parentRefs = parentFragment.indexRefs; + if ( parentRefs ) { + fragment.indexRefs = create( null ); + // avoids need for hasOwnProperty + for ( ref in parentRefs ) { + fragment.indexRefs[ ref ] = parentRefs[ ref ]; + } + } + } + // inherit priority + fragment.priority = parentFragment ? parentFragment.priority + 1 : 1; + if ( options.indexRef ) { + if ( !fragment.indexRefs ) { + fragment.indexRefs = {}; + } + fragment.indexRefs[ options.indexRef ] = options.index; + } + // Time to create this fragment's child items; + fragment.items = []; + numItems = options.descriptor ? options.descriptor.length : 0; + for ( i = 0; i < numItems; i += 1 ) { + fragment.items[ fragment.items.length ] = fragment.createItem( { + parentFragment: fragment, + pElement: options.pElement, + descriptor: options.descriptor[ i ], + index: i + } ); + } + }; + }( config_types, utils_create ); + + var render_shared_utils_startsWithKeypath = function startsWithKeypath( target, keypath ) { + return target.substr( 0, keypath.length + 1 ) === keypath + '.'; + }; + + var render_shared_utils_startsWith = function( startsWithKeypath ) { + + return function startsWith( target, keypath ) { + return target === keypath || startsWithKeypath( target, keypath ); + }; + }( render_shared_utils_startsWithKeypath ); + + var render_shared_utils_getNewKeypath = function( startsWithKeypath ) { + + return function getNewKeypath( targetKeypath, oldKeypath, newKeypath ) { + //exact match + if ( targetKeypath === oldKeypath ) { + return newKeypath; + } + //partial match based on leading keypath segments + if ( startsWithKeypath( targetKeypath, oldKeypath ) ) { + return targetKeypath.replace( oldKeypath + '.', newKeypath + '.' ); + } + }; + }( render_shared_utils_startsWithKeypath ); + + var render_shared_utils_assignNewKeypath = function( startsWith, getNewKeypath ) { + + return function assignNewKeypath( target, property, oldKeypath, newKeypath ) { + if ( !target[ property ] || startsWith( target[ property ], newKeypath ) ) { + return; + } + target[ property ] = getNewKeypath( target[ property ], oldKeypath, newKeypath ); + }; + }( render_shared_utils_startsWith, render_shared_utils_getNewKeypath ); + + var render_shared_Fragment_reassign = function( assignNewKeypath ) { + + return function reassignFragment( indexRef, newIndex, oldKeypath, newKeypath ) { + // If this fragment was rendered with innerHTML, we have nothing to do + // TODO a less hacky way of determining this + if ( this.html !== undefined ) { + return; + } + // assign new context keypath if needed + assignNewKeypath( this, 'context', oldKeypath, newKeypath ); + if ( this.indexRefs && this.indexRefs[ indexRef ] !== undefined && this.indexRefs[ indexRef ] !== newIndex ) { + this.indexRefs[ indexRef ] = newIndex; + } + this.items.forEach( function( item ) { + item.reassign( indexRef, newIndex, oldKeypath, newKeypath ); + } ); + }; + }( render_shared_utils_assignNewKeypath ); + + var render_shared_Fragment__Fragment = function( init, reassign ) { + + return { + init: init, + reassign: reassign + }; + }( render_shared_Fragment_initialise, render_shared_Fragment_reassign ); + + var render_DomFragment_shared_insertHtml = function( namespaces, createElement ) { + + var elementCache = {}, ieBug, ieBlacklist; + try { + createElement( 'table' ).innerHTML = 'foo'; + } catch ( err ) { + ieBug = true; + ieBlacklist = { + TABLE: [ + '', + '' + ], + THEAD: [ + '', + '' + ], + TBODY: [ + '', + '' + ], + TR: [ + '', + '' + ], + SELECT: [ + '', + '' + ] + }; + } + return function( html, tagName, namespace, docFrag ) { + var container, nodes = [], + wrapper; + if ( html ) { + if ( ieBug && ( wrapper = ieBlacklist[ tagName ] ) ) { + container = element( 'DIV' ); + container.innerHTML = wrapper[ 0 ] + html + wrapper[ 1 ]; + container = container.querySelector( '.x' ); + } else if ( namespace === namespaces.svg ) { + container = element( 'DIV' ); + container.innerHTML = '' + html + ''; + container = container.querySelector( '.x' ); + } else { + container = element( tagName ); + container.innerHTML = html; + } + while ( container.firstChild ) { + nodes.push( container.firstChild ); + docFrag.appendChild( container.firstChild ); + } + } + return nodes; + }; + + function element( tagName ) { + return elementCache[ tagName ] || ( elementCache[ tagName ] = createElement( tagName ) ); + } + }( config_namespaces, utils_createElement ); + + var render_DomFragment_shared_detach = function() { + var node = this.node, + parentNode; + if ( node && ( parentNode = node.parentNode ) ) { + parentNode.removeChild( node ); + return node; + } + }; + + var render_DomFragment_Text = function( types, detach ) { + + var DomText, lessThan, greaterThan; + lessThan = //g; + DomText = function( options, docFrag ) { + this.type = types.TEXT; + this.descriptor = options.descriptor; + if ( docFrag ) { + this.node = document.createTextNode( options.descriptor ); + docFrag.appendChild( this.node ); + } + }; + DomText.prototype = { + detach: detach, + reassign: function() {}, + //no-op + teardown: function( destroy ) { + if ( destroy ) { + this.detach(); + } + }, + firstNode: function() { + return this.node; + }, + toString: function() { + return ( '' + this.descriptor ).replace( lessThan, '<' ).replace( greaterThan, '>' ); + } + }; + return DomText; + }( config_types, render_DomFragment_shared_detach ); + + var shared_teardown = function( runloop, unregisterDependant ) { + + return function( thing ) { + if ( !thing.keypath ) { + // this was on the 'unresolved' list, we need to remove it + runloop.removeUnresolved( thing ); + } else { + // this was registered as a dependant + unregisterDependant( thing ); + } + }; + }( global_runloop, shared_unregisterDependant ); + + var shared_Unresolved = function( runloop ) { + + var Unresolved = function( ractive, ref, parentFragment, callback ) { + this.root = ractive; + this.ref = ref; + this.parentFragment = parentFragment; + this.resolve = callback; + runloop.addUnresolved( this ); + }; + Unresolved.prototype = { + teardown: function() { + runloop.removeUnresolved( this ); + } + }; + return Unresolved; + }( global_runloop ); + + var render_shared_Evaluator_Reference = function( types, isEqual, defineProperty, registerDependant, unregisterDependant ) { + + var Reference, thisPattern; + thisPattern = /this/; + Reference = function( root, keypath, evaluator, argNum, priority ) { + var value; + this.evaluator = evaluator; + this.keypath = keypath; + this.root = root; + this.argNum = argNum; + this.type = types.REFERENCE; + this.priority = priority; + value = root.get( keypath ); + if ( typeof value === 'function' ) { + value = wrapFunction( value, root, evaluator ); + } + this.value = evaluator.values[ argNum ] = value; + registerDependant( this ); + }; + Reference.prototype = { + update: function() { + var value = this.root.get( this.keypath ); + if ( typeof value === 'function' && !value._nowrap ) { + value = wrapFunction( value, this.root, this.evaluator ); + } + if ( !isEqual( value, this.value ) ) { + this.evaluator.values[ this.argNum ] = value; + this.evaluator.bubble(); + this.value = value; + } + }, + teardown: function() { + unregisterDependant( this ); + } + }; + return Reference; + + function wrapFunction( fn, ractive, evaluator ) { + var prop, evaluators, index; + // If the function doesn't refer to `this`, we don't need + // to set the context, because we're not doing `this.get()` + // (which is how dependencies are tracked) + if ( !thisPattern.test( fn.toString() ) ) { + defineProperty( fn, '_nowrap', { + // no point doing this every time + value: true + } ); + return fn; + } + // If this function is being wrapped for the first time... + if ( !fn[ '_' + ractive._guid ] ) { + // ...we need to do some work + defineProperty( fn, '_' + ractive._guid, { + value: function() { + var originalCaptured, result, i, evaluator; + originalCaptured = ractive._captured; + if ( !originalCaptured ) { + ractive._captured = []; + } + result = fn.apply( ractive, arguments ); + if ( ractive._captured.length ) { + i = evaluators.length; + while ( i-- ) { + evaluator = evaluators[ i ]; + evaluator.updateSoftDependencies( ractive._captured ); + } + } + // reset + ractive._captured = originalCaptured; + return result; + }, + writable: true + } ); + for ( prop in fn ) { + if ( fn.hasOwnProperty( prop ) ) { + fn[ '_' + ractive._guid ][ prop ] = fn[ prop ]; + } + } + fn[ '_' + ractive._guid + '_evaluators' ] = []; + } + // We need to make a note of which evaluators are using this function, + // so that they can all be notified of changes + evaluators = fn[ '_' + ractive._guid + '_evaluators' ]; + index = evaluators.indexOf( evaluator ); + if ( index === -1 ) { + evaluators.push( evaluator ); + } + // Return the wrapped function + return fn[ '_' + ractive._guid ]; + } + }( config_types, utils_isEqual, utils_defineProperty, shared_registerDependant, shared_unregisterDependant ); + + var render_shared_Evaluator_SoftReference = function( isEqual, registerDependant, unregisterDependant ) { + + var SoftReference = function( root, keypath, evaluator ) { + this.root = root; + this.keypath = keypath; + this.priority = evaluator.priority; + this.evaluator = evaluator; + registerDependant( this ); + }; + SoftReference.prototype = { + update: function() { + var value = this.root.get( this.keypath ); + if ( !isEqual( value, this.value ) ) { + this.evaluator.bubble(); + this.value = value; + } + }, + teardown: function() { + unregisterDependant( this ); + } + }; + return SoftReference; + }( utils_isEqual, shared_registerDependant, shared_unregisterDependant ); + + var render_shared_Evaluator__Evaluator = function( runloop, warn, isEqual, clearCache, notifyDependants, adaptIfNecessary, Reference, SoftReference ) { + + var Evaluator, cache = {}; + Evaluator = function( root, keypath, uniqueString, functionStr, args, priority ) { + var evaluator = this; + evaluator.root = root; + evaluator.uniqueString = uniqueString; + evaluator.keypath = keypath; + evaluator.priority = priority; + evaluator.fn = getFunctionFromString( functionStr, args.length ); + evaluator.values = []; + evaluator.refs = []; + args.forEach( function( arg, i ) { + if ( !arg ) { + return; + } + if ( arg.indexRef ) { + // this is an index ref... we don't need to register a dependant + evaluator.values[ i ] = arg.value; + } else { + evaluator.refs.push( new Reference( root, arg.keypath, evaluator, i, priority ) ); + } + } ); + evaluator.selfUpdating = evaluator.refs.length <= 1; + }; + Evaluator.prototype = { + bubble: function() { + // If we only have one reference, we can update immediately... + if ( this.selfUpdating ) { + this.update(); + } else if ( !this.deferred ) { + runloop.addEvaluator( this ); + this.deferred = true; + } + }, + update: function() { + var value; + // prevent infinite loops + if ( this.evaluating ) { + return this; + } + this.evaluating = true; + try { + value = this.fn.apply( null, this.values ); + } catch ( err ) { + if ( this.root.debug ) { + warn( 'Error evaluating "' + this.uniqueString + '": ' + err.message || err ); + } + value = undefined; + } + if ( !isEqual( value, this.value ) ) { + this.value = value; + clearCache( this.root, this.keypath ); + adaptIfNecessary( this.root, this.keypath, value, true ); + notifyDependants( this.root, this.keypath ); + } + this.evaluating = false; + return this; + }, + // TODO should evaluators ever get torn down? At present, they don't... + teardown: function() { + while ( this.refs.length ) { + this.refs.pop().teardown(); + } + clearCache( this.root, this.keypath ); + this.root._evaluators[ this.keypath ] = null; + }, + // This method forces the evaluator to sync with the current model + // in the case of a smart update + refresh: function() { + if ( !this.selfUpdating ) { + this.deferred = true; + } + var i = this.refs.length; + while ( i-- ) { + this.refs[ i ].update(); + } + if ( this.deferred ) { + this.update(); + this.deferred = false; + } + }, + updateSoftDependencies: function( softDeps ) { + var i, keypath, ref; + if ( !this.softRefs ) { + this.softRefs = []; + } + // teardown any references that are no longer relevant + i = this.softRefs.length; + while ( i-- ) { + ref = this.softRefs[ i ]; + if ( !softDeps[ ref.keypath ] ) { + this.softRefs.splice( i, 1 ); + this.softRefs[ ref.keypath ] = false; + ref.teardown(); + } + } + // add references for any new soft dependencies + i = softDeps.length; + while ( i-- ) { + keypath = softDeps[ i ]; + if ( !this.softRefs[ keypath ] ) { + ref = new SoftReference( this.root, keypath, this ); + this.softRefs.push( ref ); + this.softRefs[ keypath ] = true; + } + } + this.selfUpdating = this.refs.length + this.softRefs.length <= 1; + } + }; + return Evaluator; + + function getFunctionFromString( str, i ) { + var fn, args; + str = str.replace( /\$\{([0-9]+)\}/g, '_$1' ); + if ( cache[ str ] ) { + return cache[ str ]; + } + args = []; + while ( i-- ) { + args[ i ] = '_' + i; + } + fn = new Function( args.join( ',' ), 'return(' + str + ')' ); + cache[ str ] = fn; + return fn; + } + }( global_runloop, utils_warn, utils_isEqual, shared_clearCache, shared_notifyDependants, shared_adaptIfNecessary, render_shared_Evaluator_Reference, render_shared_Evaluator_SoftReference ); + + var render_shared_Resolvers_ExpressionResolver = function( removeFromArray, resolveRef, Unresolved, Evaluator, getNewKeypath ) { + + var ExpressionResolver = function( owner, parentFragment, expression, callback ) { + var expressionResolver = this, + ractive, indexRefs, args; + ractive = owner.root; + this.root = ractive; + this.callback = callback; + this.owner = owner; + this.str = expression.s; + this.args = args = []; + this.unresolved = []; + this.pending = 0; + indexRefs = parentFragment.indexRefs; + // some expressions don't have references. edge case, but, yeah. + if ( !expression.r || !expression.r.length ) { + this.resolved = this.ready = true; + this.bubble(); + return; + } + // Create resolvers for each reference + expression.r.forEach( function( reference, i ) { + var index, keypath, unresolved; + // Is this an index reference? + if ( indexRefs && ( index = indexRefs[ reference ] ) !== undefined ) { + args[ i ] = { + indexRef: reference, + value: index + }; + return; + } + // Can we resolve it immediately? + if ( keypath = resolveRef( ractive, reference, parentFragment ) ) { + args[ i ] = { + keypath: keypath + }; + return; + } + // Couldn't resolve yet + args[ i ] = undefined; + expressionResolver.pending += 1; + unresolved = new Unresolved( ractive, reference, parentFragment, function( keypath ) { + expressionResolver.resolve( i, keypath ); + removeFromArray( expressionResolver.unresolved, unresolved ); + } ); + expressionResolver.unresolved.push( unresolved ); + } ); + this.ready = true; + this.bubble(); + }; + ExpressionResolver.prototype = { + bubble: function() { + if ( !this.ready ) { + return; + } + this.uniqueString = getUniqueString( this.str, this.args ); + this.keypath = getKeypath( this.uniqueString ); + this.createEvaluator(); + this.callback( this.keypath ); + }, + teardown: function() { + var unresolved; + while ( unresolved = this.unresolved.pop() ) { + unresolved.teardown(); + } + }, + resolve: function( index, keypath ) { + this.args[ index ] = { + keypath: keypath + }; + this.bubble(); + // when all references have been resolved, we can flag the entire expression + // as having been resolved + this.resolved = !--this.pending; + }, + createEvaluator: function() { + var evaluator; + // only if it doesn't exist yet! + if ( !this.root._evaluators[ this.keypath ] ) { + evaluator = new Evaluator( this.root, this.keypath, this.uniqueString, this.str, this.args, this.owner.priority ); + this.root._evaluators[ this.keypath ] = evaluator; + evaluator.update(); + } else { + // we need to trigger a refresh of the evaluator, since it + // will have become de-synced from the model if we're in a + // reassignment cycle + this.root._evaluators[ this.keypath ].refresh(); + } + }, + reassign: function( indexRef, newIndex, oldKeypath, newKeypath ) { + var changed; + this.args.forEach( function( arg ) { + var changedKeypath; + if ( arg.keypath && ( changedKeypath = getNewKeypath( arg.keypath, oldKeypath, newKeypath ) ) ) { + arg.keypath = changedKeypath; + changed = true; + } else if ( arg.indexRef === indexRef ) { + arg.value = newIndex; + changed = true; + } + } ); + if ( changed ) { + this.bubble(); + } + } + }; + return ExpressionResolver; + + function getUniqueString( str, args ) { + // get string that is unique to this expression + return str.replace( /\$\{([0-9]+)\}/g, function( match, $1 ) { + return args[ $1 ] ? args[ $1 ].value || args[ $1 ].keypath : 'undefined'; + } ); + } + + function getKeypath( uniqueString ) { + // Sanitize by removing any periods or square brackets. Otherwise + // we can't split the keypath into keys! + return '${' + uniqueString.replace( /[\.\[\]]/g, '-' ) + '}'; + } + }( utils_removeFromArray, shared_resolveRef, shared_Unresolved, render_shared_Evaluator__Evaluator, render_shared_utils_getNewKeypath ); + + var render_shared_Resolvers_KeypathExpressionResolver = function( types, removeFromArray, resolveRef, Unresolved, registerDependant, unregisterDependant, ExpressionResolver ) { + + var KeypathExpressionResolver = function( mustache, descriptor, callback ) { + var resolver = this, + ractive, parentFragment, keypath, dynamic, members; + ractive = mustache.root; + parentFragment = mustache.parentFragment; + this.ref = descriptor.r; + this.root = mustache.root; + this.mustache = mustache; + this.callback = callback; + this.pending = 0; + this.unresolved = []; + members = this.members = []; + this.indexRefMembers = []; + this.keypathObservers = []; + this.expressionResolvers = []; + descriptor.m.forEach( function( member, i ) { + var ref, indexRefs, index, createKeypathObserver, unresolved, expressionResolver; + if ( typeof member === 'string' ) { + resolver.members[ i ] = member; + return; + } + // simple reference? + if ( member.t === types.REFERENCE ) { + ref = member.n; + indexRefs = parentFragment.indexRefs; + if ( indexRefs && ( index = indexRefs[ ref ] ) !== undefined ) { + members[ i ] = index; + // make a note of it, in case of reassignments + resolver.indexRefMembers.push( { + ref: ref, + index: i + } ); + return; + } + dynamic = true; + createKeypathObserver = function( keypath ) { + var keypathObserver = new KeypathObserver( ractive, keypath, mustache.priority, resolver, i ); + resolver.keypathObservers.push( keypathObserver ); + }; + // Can we resolve the reference immediately? + if ( keypath = resolveRef( ractive, ref, parentFragment ) ) { + createKeypathObserver( keypath ); + return; + } + // Couldn't resolve yet + members[ i ] = undefined; + resolver.pending += 1; + unresolved = new Unresolved( ractive, ref, parentFragment, function( keypath ) { + resolver.resolve( i, keypath ); + removeFromArray( resolver.unresolved, unresolved ); + } ); + resolver.unresolved.push( unresolved ); + return null; + } + // Otherwise we have an expression in its own right + dynamic = true; + resolver.pending += 1; + expressionResolver = new ExpressionResolver( resolver, parentFragment, member, function( keypath ) { + resolver.resolve( i, keypath ); + removeFromArray( resolver.unresolved, expressionResolver ); + } ); + resolver.unresolved.push( expressionResolver ); + } ); + // Some keypath expressions (e.g. foo["bar"], or foo[i] where `i` is an + // index reference) won't change. So we don't need to register any watchers + if ( !dynamic ) { + keypath = this.getKeypath(); + callback( keypath ); + return; + } + this.ready = true; + this.bubble(); + }; + KeypathExpressionResolver.prototype = { + getKeypath: function() { + return this.ref + '.' + this.members.join( '.' ); + }, + bubble: function() { + if ( !this.ready || this.pending ) { + return; + } + this.callback( this.getKeypath() ); + }, + resolve: function( index, value ) { + var keypathObserver = new KeypathObserver( this.root, value, this.mustache.priority, this, index ); + keypathObserver.update(); + this.keypathObservers.push( keypathObserver ); + // when all references have been resolved, we can flag the entire expression + // as having been resolved + this.resolved = !--this.pending; + this.bubble(); + }, + teardown: function() { + var unresolved; + while ( unresolved = this.unresolved.pop() ) { + unresolved.teardown(); + } + }, + reassign: function( indexRef, newIndex ) { + var changed, i, member; + i = this.indexRefMembers.length; + while ( i-- ) { + member = this.indexRefMembers[ i ]; + if ( member.ref === indexRef ) { + changed = true; + this.members[ member.index ] = newIndex; + } + } + if ( changed ) { + this.bubble(); + } + } + }; + var KeypathObserver = function( ractive, keypath, priority, resolver, index ) { + this.root = ractive; + this.keypath = keypath; + this.priority = priority; + this.resolver = resolver; + this.index = index; + registerDependant( this ); + this.update(); + }; + KeypathObserver.prototype = { + update: function() { + var resolver = this.resolver; + resolver.members[ this.index ] = this.root.get( this.keypath ); + resolver.bubble(); + }, + teardown: function() { + unregisterDependant( this ); + } + }; + return KeypathExpressionResolver; + }( config_types, utils_removeFromArray, shared_resolveRef, shared_Unresolved, shared_registerDependant, shared_unregisterDependant, render_shared_Resolvers_ExpressionResolver ); + + var render_shared_Mustache_initialise = function( runloop, resolveRef, KeypathExpressionResolver, ExpressionResolver ) { + + return function initMustache( mustache, options ) { + var ref, keypath, indexRefs, index, parentFragment, descriptor, resolve; + parentFragment = options.parentFragment; + descriptor = options.descriptor; + mustache.root = parentFragment.root; + mustache.parentFragment = parentFragment; + mustache.descriptor = options.descriptor; + mustache.index = options.index || 0; + mustache.priority = parentFragment.priority; + mustache.type = options.descriptor.t; + resolve = function( keypath ) { + mustache.resolve( keypath ); + }; + // if this is a simple mustache, with a reference, we just need to resolve + // the reference to a keypath + if ( ref = descriptor.r ) { + indexRefs = parentFragment.indexRefs; + if ( indexRefs && ( index = indexRefs[ ref ] ) !== undefined ) { + mustache.indexRef = ref; + mustache.value = index; + mustache.render( mustache.value ); + } else { + keypath = resolveRef( mustache.root, ref, mustache.parentFragment ); + if ( keypath !== undefined ) { + resolve( keypath ); + } else { + mustache.ref = ref; + runloop.addUnresolved( mustache ); + } + } + } + // if it's an expression, we have a bit more work to do + if ( options.descriptor.x ) { + mustache.resolver = new ExpressionResolver( mustache, parentFragment, options.descriptor.x, resolve ); + } + if ( options.descriptor.kx ) { + mustache.resolver = new KeypathExpressionResolver( mustache, options.descriptor.kx, resolve ); + } + // Special case - inverted sections + if ( mustache.descriptor.n && !mustache.hasOwnProperty( 'value' ) ) { + mustache.render( undefined ); + } + }; + }( global_runloop, shared_resolveRef, render_shared_Resolvers_KeypathExpressionResolver, render_shared_Resolvers_ExpressionResolver ); + + var render_shared_Mustache_update = function( isEqual, get ) { + + var options = { + evaluateWrapped: true + }; + return function updateMustache() { + var value = get( this.root, this.keypath, options ); + if ( !isEqual( value, this.value ) ) { + this.render( value ); + this.value = value; + } + }; + }( utils_isEqual, shared_get__get ); + + var render_shared_Mustache_resolve = function( types, registerDependant, unregisterDependant ) { + + return function resolveMustache( keypath ) { + var i; + // In some cases, we may resolve to the same keypath (if this is + // an expression mustache that was reassigned due to an ancestor's + // keypath) - in which case, this is a no-op + if ( keypath === this.keypath ) { + return; + } + // if we resolved previously, we need to unregister + if ( this.registered ) { + unregisterDependant( this ); + // is this a section? if so, we may have children that need + // to be reassigned + // TODO only DOM sections? + if ( this.type === types.SECTION ) { + i = this.fragments.length; + while ( i-- ) { + this.fragments[ i ].reassign( null, null, this.keypath, keypath ); + } + } + } + this.keypath = keypath; + registerDependant( this ); + this.update(); + }; + }( config_types, shared_registerDependant, shared_unregisterDependant ); + + var render_shared_Mustache_reassign = function( getNewKeypath ) { + + return function reassignMustache( indexRef, newIndex, oldKeypath, newKeypath ) { + var updated, i; + // expression mustache? + if ( this.resolver ) { + this.resolver.reassign( indexRef, newIndex, oldKeypath, newKeypath ); + } else if ( this.keypath ) { + updated = getNewKeypath( this.keypath, oldKeypath, newKeypath ); + // was a new keypath created? + if ( updated ) { + // resolve it + this.resolve( updated ); + } + } else if ( indexRef !== undefined && this.indexRef === indexRef ) { + this.value = newIndex; + this.render( newIndex ); + } + // otherwise, it's an unresolved reference. the context stack has been updated + // so it will take care of itself + // if it's a section mustache, we need to go through any children + if ( this.fragments ) { + i = this.fragments.length; + while ( i-- ) { + this.fragments[ i ].reassign( indexRef, newIndex, oldKeypath, newKeypath ); + } + } + }; + }( render_shared_utils_getNewKeypath ); + + var render_shared_Mustache__Mustache = function( init, update, resolve, reassign ) { + + return { + init: init, + update: update, + resolve: resolve, + reassign: reassign + }; + }( render_shared_Mustache_initialise, render_shared_Mustache_update, render_shared_Mustache_resolve, render_shared_Mustache_reassign ); + + var render_DomFragment_Interpolator = function( types, teardown, Mustache, detach ) { + + var DomInterpolator, lessThan, greaterThan; + lessThan = //g; + DomInterpolator = function( options, docFrag ) { + this.type = types.INTERPOLATOR; + if ( docFrag ) { + this.node = document.createTextNode( '' ); + docFrag.appendChild( this.node ); + } + // extend Mustache + Mustache.init( this, options ); + }; + DomInterpolator.prototype = { + update: Mustache.update, + resolve: Mustache.resolve, + reassign: Mustache.reassign, + detach: detach, + teardown: function( destroy ) { + if ( destroy ) { + this.detach(); + } + teardown( this ); + }, + render: function( value ) { + if ( this.node ) { + this.node.data = value == undefined ? '' : value; + } + }, + firstNode: function() { + return this.node; + }, + toString: function() { + var value = this.value != undefined ? '' + this.value : ''; + return value.replace( lessThan, '<' ).replace( greaterThan, '>' ); + } + }; + return DomInterpolator; + }( config_types, shared_teardown, render_shared_Mustache__Mustache, render_DomFragment_shared_detach ); + + var render_DomFragment_Section_prototype_merge = function() { + + var toTeardown = []; + return function sectionMerge( newIndices ) { + var section = this, + parentFragment, firstChange, i, newLength, reassignedFragments, fragmentOptions, fragment, nextNode; + parentFragment = this.parentFragment; + reassignedFragments = []; + // first, reassign existing fragments + newIndices.forEach( function reassignIfNecessary( newIndex, oldIndex ) { + var fragment, by, oldKeypath, newKeypath; + if ( newIndex === oldIndex ) { + reassignedFragments[ newIndex ] = section.fragments[ oldIndex ]; + return; + } + if ( firstChange === undefined ) { + firstChange = oldIndex; + } + // does this fragment need to be torn down? + if ( newIndex === -1 ) { + toTeardown.push( section.fragments[ oldIndex ] ); + return; + } + // Otherwise, it needs to be reassigned to a new index + fragment = section.fragments[ oldIndex ]; + by = newIndex - oldIndex; + oldKeypath = section.keypath + '.' + oldIndex; + newKeypath = section.keypath + '.' + newIndex; + fragment.reassign( section.descriptor.i, oldIndex, newIndex, by, oldKeypath, newKeypath ); + reassignedFragments[ newIndex ] = fragment; + } ); + while ( fragment = toTeardown.pop() ) { + fragment.teardown( true ); + } + // If nothing changed with the existing fragments, then we start adding + // new fragments at the end... + if ( firstChange === undefined ) { + firstChange = this.length; + } + this.length = newLength = this.root.get( this.keypath ).length; + if ( newLength === firstChange ) { + // ...unless there are no new fragments to add + return; + } + // Prepare new fragment options + fragmentOptions = { + descriptor: this.descriptor.f, + root: this.root, + pNode: parentFragment.pNode, + owner: this + }; + if ( this.descriptor.i ) { + fragmentOptions.indexRef = this.descriptor.i; + } + // Add as many new fragments as we need to, or add back existing + // (detached) fragments + for ( i = firstChange; i < newLength; i += 1 ) { + // is this an existing fragment? + if ( fragment = reassignedFragments[ i ] ) { + this.docFrag.appendChild( fragment.detach( false ) ); + } else { + fragmentOptions.context = this.keypath + '.' + i; + fragmentOptions.index = i; + fragment = this.createFragment( fragmentOptions ); + } + this.fragments[ i ] = fragment; + } + // reinsert fragment + nextNode = parentFragment.findNextNode( this ); + parentFragment.pNode.insertBefore( this.docFrag, nextNode ); + }; + }(); + + var render_shared_updateSection = function( isArray, isObject ) { + + return function updateSection( section, value ) { + var fragmentOptions = { + descriptor: section.descriptor.f, + root: section.root, + pNode: section.parentFragment.pNode, + pElement: section.parentFragment.pElement, + owner: section + }; + // if section is inverted, only check for truthiness/falsiness + if ( section.descriptor.n ) { + updateConditionalSection( section, value, true, fragmentOptions ); + return; + } + // otherwise we need to work out what sort of section we're dealing with + // if value is an array, or an object with an index reference, iterate through + if ( isArray( value ) ) { + updateListSection( section, value, fragmentOptions ); + } else if ( isObject( value ) || typeof value === 'function' ) { + if ( section.descriptor.i ) { + updateListObjectSection( section, value, fragmentOptions ); + } else { + updateContextSection( section, fragmentOptions ); + } + } else { + updateConditionalSection( section, value, false, fragmentOptions ); + } + }; + + function updateListSection( section, value, fragmentOptions ) { + var i, length, fragmentsToRemove; + length = value.length; + // if the array is shorter than it was previously, remove items + if ( length < section.length ) { + fragmentsToRemove = section.fragments.splice( length, section.length - length ); + while ( fragmentsToRemove.length ) { + fragmentsToRemove.pop().teardown( true ); + } + } else { + if ( length > section.length ) { + // add any new ones + for ( i = section.length; i < length; i += 1 ) { + // append list item to context stack + fragmentOptions.context = section.keypath + '.' + i; + fragmentOptions.index = i; + if ( section.descriptor.i ) { + fragmentOptions.indexRef = section.descriptor.i; + } + section.fragments[ i ] = section.createFragment( fragmentOptions ); + } + } + } + section.length = length; + } + + function updateListObjectSection( section, value, fragmentOptions ) { + var id, i, hasKey, fragment; + hasKey = section.hasKey || ( section.hasKey = {} ); + // remove any fragments that should no longer exist + i = section.fragments.length; + while ( i-- ) { + fragment = section.fragments[ i ]; + if ( !( fragment.index in value ) ) { + section.fragments[ i ].teardown( true ); + section.fragments.splice( i, 1 ); + hasKey[ fragment.index ] = false; + } + } + // add any that haven't been created yet + for ( id in value ) { + if ( !hasKey[ id ] ) { + fragmentOptions.context = section.keypath + '.' + id; + fragmentOptions.index = id; + if ( section.descriptor.i ) { + fragmentOptions.indexRef = section.descriptor.i; + } + section.fragments.push( section.createFragment( fragmentOptions ) ); + hasKey[ id ] = true; + } + } + section.length = section.fragments.length; + } + + function updateContextSection( section, fragmentOptions ) { + // ...then if it isn't rendered, render it, adding section.keypath to the context stack + // (if it is already rendered, then any children dependent on the context stack + // will update themselves without any prompting) + if ( !section.length ) { + // append this section to the context stack + fragmentOptions.context = section.keypath; + fragmentOptions.index = 0; + section.fragments[ 0 ] = section.createFragment( fragmentOptions ); + section.length = 1; + } + } + + function updateConditionalSection( section, value, inverted, fragmentOptions ) { + var doRender, emptyArray, fragmentsToRemove, fragment; + emptyArray = isArray( value ) && value.length === 0; + if ( inverted ) { + doRender = emptyArray || !value; + } else { + doRender = value && !emptyArray; + } + if ( doRender ) { + if ( !section.length ) { + // no change to context stack + fragmentOptions.index = 0; + section.fragments[ 0 ] = section.createFragment( fragmentOptions ); + section.length = 1; + } + if ( section.length > 1 ) { + fragmentsToRemove = section.fragments.splice( 1 ); + while ( fragment = fragmentsToRemove.pop() ) { + fragment.teardown( true ); + } + } + } else if ( section.length ) { + section.teardownFragments( true ); + section.length = 0; + } + } + }( utils_isArray, utils_isObject ); + + var render_DomFragment_Section_prototype_render = function( isClient, updateSection ) { + + return function DomSection_prototype_render( value ) { + var nextNode, wrapped; + // with sections, we need to get the fake value if we have a wrapped object + if ( wrapped = this.root._wrapped[ this.keypath ] ) { + value = wrapped.get(); + } + // prevent sections from rendering multiple times (happens if + // evaluators evaluate while update is happening) + if ( this.rendering ) { + return; + } + this.rendering = true; + updateSection( this, value ); + this.rendering = false; + // if we have no new nodes to insert (i.e. the section length stayed the + // same, or shrank), we don't need to go any further + if ( this.docFrag && !this.docFrag.childNodes.length ) { + return; + } + // if this isn't the initial render, we need to insert any new nodes in + // the right place + if ( !this.initialising && isClient ) { + // Normally this is just a case of finding the next node, and inserting + // items before it... + nextNode = this.parentFragment.findNextNode( this ); + if ( nextNode && nextNode.parentNode === this.parentFragment.pNode ) { + this.parentFragment.pNode.insertBefore( this.docFrag, nextNode ); + } else { + // TODO could there be a situation in which later nodes could have + // been attached to the parent node, i.e. we need to find a sibling + // to insert before? + this.parentFragment.pNode.appendChild( this.docFrag ); + } + } + }; + }( config_isClient, render_shared_updateSection ); + + var render_DomFragment_Section_reassignFragments = function( section, start, end, by ) { + var i, fragment, indexRef, oldKeypath, newKeypath; + indexRef = section.descriptor.i; + for ( i = start; i < end; i += 1 ) { + fragment = section.fragments[ i ]; + oldKeypath = section.keypath + '.' + ( i - by ); + newKeypath = section.keypath + '.' + i; + // change the fragment index + fragment.index = i; + fragment.reassign( indexRef, i, oldKeypath, newKeypath ); + } + }; + + var render_DomFragment_Section_prototype_splice = function( reassignFragments ) { + + return function( spliceSummary ) { + var section = this, + balance, start, insertStart, insertEnd, spliceArgs; + balance = spliceSummary.balance; + if ( !balance ) { + // The array length hasn't changed - we don't need to add or remove anything + return; + } + start = spliceSummary.start; + section.length += balance; + // If more items were removed from the array than added, we tear down + // the excess fragments and remove them... + if ( balance < 0 ) { + section.fragments.splice( start, -balance ).forEach( teardown ); + // Reassign fragments after the ones we've just removed + reassignFragments( section, start, section.length, balance ); + // Nothing more to do + return; + } + // ...otherwise we need to add some things to the DOM. + insertStart = start + spliceSummary.removed; + insertEnd = start + spliceSummary.added; + // Make room for the new fragments by doing a splice that simulates + // what happened to the data array + spliceArgs = [ + insertStart, + 0 + ]; + spliceArgs.length += balance; + section.fragments.splice.apply( section.fragments, spliceArgs ); + // Reassign existing fragments at the end of the array + reassignFragments( section, insertEnd, section.length, balance ); + // Create the new ones + renderNewFragments( section, insertStart, insertEnd ); + }; + + function teardown( fragment ) { + fragment.teardown( true ); + } + + function renderNewFragments( section, start, end ) { + var fragmentOptions, i, insertionPoint; + section.rendering = true; + fragmentOptions = { + descriptor: section.descriptor.f, + root: section.root, + pNode: section.parentFragment.pNode, + owner: section, + indexRef: section.descriptor.i + }; + for ( i = start; i < end; i += 1 ) { + fragmentOptions.context = section.keypath + '.' + i; + fragmentOptions.index = i; + section.fragments[ i ] = section.createFragment( fragmentOptions ); + } + // Figure out where these new nodes need to be inserted + insertionPoint = section.fragments[ end ] ? section.fragments[ end ].firstNode() : section.parentFragment.findNextNode( section ); + // Append docfrag in front of insertion point + section.parentFragment.pNode.insertBefore( section.docFrag, insertionPoint ); + section.rendering = false; + } + }( render_DomFragment_Section_reassignFragments ); + + var render_DomFragment_Section__Section = function( types, Mustache, merge, render, splice, teardown, circular ) { + + var DomSection, DomFragment; + circular.push( function() { + DomFragment = circular.DomFragment; + } ); + // Section + DomSection = function( options, docFrag ) { + this.type = types.SECTION; + this.inverted = !! options.descriptor.n; + this.fragments = []; + this.length = 0; + // number of times this section is rendered + if ( docFrag ) { + this.docFrag = document.createDocumentFragment(); + } + this.initialising = true; + Mustache.init( this, options ); + if ( docFrag ) { + docFrag.appendChild( this.docFrag ); + } + this.initialising = false; + }; + DomSection.prototype = { + update: Mustache.update, + resolve: Mustache.resolve, + reassign: Mustache.reassign, + splice: splice, + merge: merge, + detach: function() { + var i, len; + if ( this.docFrag ) { + len = this.fragments.length; + for ( i = 0; i < len; i += 1 ) { + this.docFrag.appendChild( this.fragments[ i ].detach() ); + } + return this.docFrag; + } + }, + teardown: function( destroy ) { + this.teardownFragments( destroy ); + teardown( this ); + }, + firstNode: function() { + if ( this.fragments[ 0 ] ) { + return this.fragments[ 0 ].firstNode(); + } + return this.parentFragment.findNextNode( this ); + }, + findNextNode: function( fragment ) { + if ( this.fragments[ fragment.index + 1 ] ) { + return this.fragments[ fragment.index + 1 ].firstNode(); + } + return this.parentFragment.findNextNode( this ); + }, + teardownFragments: function( destroy ) { + var fragment; + while ( fragment = this.fragments.shift() ) { + fragment.teardown( destroy ); + } + }, + render: render, + createFragment: function( options ) { + var fragment = new DomFragment( options ); + if ( this.docFrag ) { + this.docFrag.appendChild( fragment.docFrag ); + } + return fragment; + }, + toString: function() { + var str, i, len; + str = ''; + i = 0; + len = this.length; + for ( i = 0; i < len; i += 1 ) { + str += this.fragments[ i ].toString(); + } + return str; + }, + find: function( selector ) { + var i, len, queryResult; + len = this.fragments.length; + for ( i = 0; i < len; i += 1 ) { + if ( queryResult = this.fragments[ i ].find( selector ) ) { + return queryResult; + } + } + return null; + }, + findAll: function( selector, query ) { + var i, len; + len = this.fragments.length; + for ( i = 0; i < len; i += 1 ) { + this.fragments[ i ].findAll( selector, query ); + } + }, + findComponent: function( selector ) { + var i, len, queryResult; + len = this.fragments.length; + for ( i = 0; i < len; i += 1 ) { + if ( queryResult = this.fragments[ i ].findComponent( selector ) ) { + return queryResult; + } + } + return null; + }, + findAllComponents: function( selector, query ) { + var i, len; + len = this.fragments.length; + for ( i = 0; i < len; i += 1 ) { + this.fragments[ i ].findAllComponents( selector, query ); + } + } + }; + return DomSection; + }( config_types, render_shared_Mustache__Mustache, render_DomFragment_Section_prototype_merge, render_DomFragment_Section_prototype_render, render_DomFragment_Section_prototype_splice, shared_teardown, circular ); + + var render_DomFragment_Triple = function( types, matches, Mustache, insertHtml, teardown ) { + + var DomTriple = function( options, docFrag ) { + this.type = types.TRIPLE; + if ( docFrag ) { + this.nodes = []; + this.docFrag = document.createDocumentFragment(); + } + this.initialising = true; + Mustache.init( this, options ); + if ( docFrag ) { + docFrag.appendChild( this.docFrag ); + } + this.initialising = false; + }; + DomTriple.prototype = { + update: Mustache.update, + resolve: Mustache.resolve, + reassign: Mustache.reassign, + detach: function() { + var len, i; + if ( this.docFrag ) { + len = this.nodes.length; + for ( i = 0; i < len; i += 1 ) { + this.docFrag.appendChild( this.nodes[ i ] ); + } + return this.docFrag; + } + }, + teardown: function( destroy ) { + if ( destroy ) { + this.detach(); + this.docFrag = this.nodes = null; + } + teardown( this ); + }, + firstNode: function() { + if ( this.nodes[ 0 ] ) { + return this.nodes[ 0 ]; + } + return this.parentFragment.findNextNode( this ); + }, + render: function( html ) { + var node, pNode; + if ( !this.nodes ) { + // looks like we're in a server environment... + // nothing to see here, move along + return; + } + // remove existing nodes + while ( this.nodes.length ) { + node = this.nodes.pop(); + node.parentNode.removeChild( node ); + } + if ( !html ) { + this.nodes = []; + return; + } + // get new nodes + pNode = this.parentFragment.pNode; + this.nodes = insertHtml( html, pNode.tagName, pNode.namespaceURI, this.docFrag ); + if ( !this.initialising ) { + pNode.insertBefore( this.docFrag, this.parentFragment.findNextNode( this ) ); + } + // Special case - we're inserting the contents of a + if ( pNode.tagName === 'SELECT' && pNode._ractive && pNode._ractive.binding ) { + pNode._ractive.binding.update(); + } + }, + toString: function() { + return this.value != undefined ? this.value : ''; + }, + find: function( selector ) { + var i, len, node, queryResult; + len = this.nodes.length; + for ( i = 0; i < len; i += 1 ) { + node = this.nodes[ i ]; + if ( node.nodeType !== 1 ) { + continue; + } + if ( matches( node, selector ) ) { + return node; + } + if ( queryResult = node.querySelector( selector ) ) { + return queryResult; + } + } + return null; + }, + findAll: function( selector, queryResult ) { + var i, len, node, queryAllResult, numNodes, j; + len = this.nodes.length; + for ( i = 0; i < len; i += 1 ) { + node = this.nodes[ i ]; + if ( node.nodeType !== 1 ) { + continue; + } + if ( matches( node, selector ) ) { + queryResult.push( node ); + } + if ( queryAllResult = node.querySelectorAll( selector ) ) { + numNodes = queryAllResult.length; + for ( j = 0; j < numNodes; j += 1 ) { + queryResult.push( queryAllResult[ j ] ); + } + } + } + } + }; + return DomTriple; + }( config_types, utils_matches, render_shared_Mustache__Mustache, render_DomFragment_shared_insertHtml, shared_teardown ); + + var render_DomFragment_Element_initialise_getElementNamespace = function( namespaces ) { + + return function( descriptor, parentNode ) { + // if the element has an xmlns attribute, use that + if ( descriptor.a && descriptor.a.xmlns ) { + return descriptor.a.xmlns; + } + // otherwise, use the svg namespace if this is an svg element, or inherit namespace from parent + return descriptor.e === 'svg' ? namespaces.svg : parentNode.namespaceURI || namespaces.html; + }; + }( config_namespaces ); + + var render_DomFragment_shared_enforceCase = function() { + + var svgCamelCaseElements, svgCamelCaseAttributes, createMap, map; + svgCamelCaseElements = 'altGlyph altGlyphDef altGlyphItem animateColor animateMotion animateTransform clipPath feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile feTurbulence foreignObject glyphRef linearGradient radialGradient textPath vkern'.split( ' ' ); + svgCamelCaseAttributes = 'attributeName attributeType baseFrequency baseProfile calcMode clipPathUnits contentScriptType contentStyleType diffuseConstant edgeMode externalResourcesRequired filterRes filterUnits glyphRef gradientTransform gradientUnits kernelMatrix kernelUnitLength keyPoints keySplines keyTimes lengthAdjust limitingConeAngle markerHeight markerUnits markerWidth maskContentUnits maskUnits numOctaves pathLength patternContentUnits patternTransform patternUnits pointsAtX pointsAtY pointsAtZ preserveAlpha preserveAspectRatio primitiveUnits refX refY repeatCount repeatDur requiredExtensions requiredFeatures specularConstant specularExponent spreadMethod startOffset stdDeviation stitchTiles surfaceScale systemLanguage tableValues targetX targetY textLength viewBox viewTarget xChannelSelector yChannelSelector zoomAndPan'.split( ' ' ); + createMap = function( items ) { + var map = {}, i = items.length; + while ( i-- ) { + map[ items[ i ].toLowerCase() ] = items[ i ]; + } + return map; + }; + map = createMap( svgCamelCaseElements.concat( svgCamelCaseAttributes ) ); + return function( elementName ) { + var lowerCaseElementName = elementName.toLowerCase(); + return map[ lowerCaseElementName ] || lowerCaseElementName; + }; + }(); + + var render_DomFragment_Attribute_helpers_determineNameAndNamespace = function( namespaces, enforceCase ) { + + return function( attribute, name ) { + var colonIndex, namespacePrefix; + // are we dealing with a namespaced attribute, e.g. xlink:href? + colonIndex = name.indexOf( ':' ); + if ( colonIndex !== -1 ) { + // looks like we are, yes... + namespacePrefix = name.substr( 0, colonIndex ); + // ...unless it's a namespace *declaration*, which we ignore (on the assumption + // that only valid namespaces will be used) + if ( namespacePrefix !== 'xmlns' ) { + name = name.substring( colonIndex + 1 ); + attribute.name = enforceCase( name ); + attribute.lcName = attribute.name.toLowerCase(); + attribute.namespace = namespaces[ namespacePrefix.toLowerCase() ]; + if ( !attribute.namespace ) { + throw 'Unknown namespace ("' + namespacePrefix + '")'; + } + return; + } + } + // SVG attribute names are case sensitive + attribute.name = attribute.element.namespace !== namespaces.html ? enforceCase( name ) : name; + attribute.lcName = attribute.name.toLowerCase(); + }; + }( config_namespaces, render_DomFragment_shared_enforceCase ); + + var render_DomFragment_Attribute_helpers_setStaticAttribute = function( namespaces ) { + + return function setStaticAttribute( attribute, options ) { + var node, value = options.value === null ? '' : options.value; + if ( node = options.pNode ) { + if ( attribute.namespace ) { + node.setAttributeNS( attribute.namespace, options.name, value ); + } else { + // is it a style attribute? and are we in a broken POS browser? + if ( options.name === 'style' && node.style.setAttribute ) { + node.style.setAttribute( 'cssText', value ); + } else if ( options.name === 'class' && ( !node.namespaceURI || node.namespaceURI === namespaces.html ) ) { + node.className = value; + } else { + node.setAttribute( options.name, value ); + } + } + if ( attribute.name === 'id' ) { + options.root.nodes[ options.value ] = node; + } + if ( attribute.name === 'value' ) { + node._ractive.value = options.value; + } + } + attribute.value = options.value; + }; + }( config_namespaces ); + + var render_DomFragment_Attribute_helpers_determinePropertyName = function( namespaces ) { + + // the property name equivalents for element attributes, where they differ + // from the lowercased attribute name + var propertyNames = { + 'accept-charset': 'acceptCharset', + accesskey: 'accessKey', + bgcolor: 'bgColor', + 'class': 'className', + codebase: 'codeBase', + colspan: 'colSpan', + contenteditable: 'contentEditable', + datetime: 'dateTime', + dirname: 'dirName', + 'for': 'htmlFor', + 'http-equiv': 'httpEquiv', + ismap: 'isMap', + maxlength: 'maxLength', + novalidate: 'noValidate', + pubdate: 'pubDate', + readonly: 'readOnly', + rowspan: 'rowSpan', + tabindex: 'tabIndex', + usemap: 'useMap' + }; + return function( attribute, options ) { + var propertyName; + if ( attribute.pNode && !attribute.namespace && ( !options.pNode.namespaceURI || options.pNode.namespaceURI === namespaces.html ) ) { + propertyName = propertyNames[ attribute.name ] || attribute.name; + if ( options.pNode[ propertyName ] !== undefined ) { + attribute.propertyName = propertyName; + } + // is attribute a boolean attribute or 'value'? If so we're better off doing e.g. + // node.selected = true rather than node.setAttribute( 'selected', '' ) + if ( typeof options.pNode[ propertyName ] === 'boolean' || propertyName === 'value' ) { + attribute.useProperty = true; + } + } + }; + }( config_namespaces ); + + var render_DomFragment_Attribute_helpers_getInterpolator = function( types ) { + + return function getInterpolator( attribute ) { + var items, item; + items = attribute.fragment.items; + if ( items.length !== 1 ) { + return; + } + item = items[ 0 ]; + if ( item.type !== types.INTERPOLATOR || !item.keypath && !item.ref ) { + return; + } + return item; + }; + }( config_types ); + + var utils_arrayContentsMatch = function( isArray ) { + + return function( a, b ) { + var i; + if ( !isArray( a ) || !isArray( b ) ) { + return false; + } + if ( a.length !== b.length ) { + return false; + } + i = a.length; + while ( i-- ) { + if ( a[ i ] !== b[ i ] ) { + return false; + } + } + return true; + }; + }( utils_isArray ); + + var render_DomFragment_Attribute_prototype_bind = function( runloop, warn, arrayContentsMatch, getValueFromCheckboxes, get, set ) { + + var singleMustacheError = 'For two-way binding to work, attribute value must be a single interpolator (e.g. value="{{foo}}")', + expressionError = 'You cannot set up two-way binding against an expression ', + bindAttribute, updateModel, getOptions, update, getBinding, inheritProperties, MultipleSelectBinding, SelectBinding, RadioNameBinding, CheckboxNameBinding, CheckedBinding, FileListBinding, ContentEditableBinding, GenericBinding; + bindAttribute = function() { + var node = this.pNode, + interpolator, binding, bindings; + interpolator = this.interpolator; + if ( !interpolator ) { + warn( singleMustacheError ); + return false; + } + if ( interpolator.keypath && interpolator.keypath.substr === '${' ) { + warn( expressionError + interpolator.keypath ); + return false; + } + // Hmmm. Not sure if this is the best way to handle this ambiguity... + // + // Let's say we were given `value="{{bar}}"`. If the context stack was + // context stack was `["foo"]`, and `foo.bar` *wasn't* `undefined`, the + // keypath would be `foo.bar`. Then, any user input would result in + // `foo.bar` being updated. + // + // If, however, `foo.bar` *was* undefined, and so was `bar`, we would be + // left with an unresolved partial keypath - so we are forced to make an + // assumption. That assumption is that the input in question should + // be forced to resolve to `bar`, and any user input would affect `bar` + // and not `foo.bar`. + // + // Did that make any sense? No? Oh. Sorry. Well the moral of the story is + // be explicit when using two-way data-binding about what keypath you're + // updating. Using it in lists is probably a recipe for confusion... + if ( !interpolator.keypath ) { + interpolator.resolve( interpolator.descriptor.r ); + } + this.keypath = interpolator.keypath; + binding = getBinding( this ); + if ( !binding ) { + return false; + } + node._ractive.binding = this.element.binding = binding; + this.twoway = true; + // register this with the root, so that we can force an update later + bindings = this.root._twowayBindings[ this.keypath ] || ( this.root._twowayBindings[ this.keypath ] = [] ); + bindings.push( binding ); + return true; + }; + // This is the handler for DOM events that would lead to a change in the model + // (i.e. change, sometimes, input, and occasionally click and keyup) + updateModel = function() { + runloop.start( this._ractive.root ); + this._ractive.binding.update(); + runloop.end(); + }; + getOptions = { + evaluateWrapped: true + }; + update = function() { + var value = get( this._ractive.root, this._ractive.binding.keypath, getOptions ); + this.value = value == undefined ? '' : value; + }; + getBinding = function( attribute ) { + var node = attribute.pNode; + if ( node.tagName === 'SELECT' ) { + return node.multiple ? new MultipleSelectBinding( attribute, node ) : new SelectBinding( attribute, node ); + } + if ( node.type === 'checkbox' || node.type === 'radio' ) { + if ( attribute.propertyName === 'name' ) { + if ( node.type === 'checkbox' ) { + return new CheckboxNameBinding( attribute, node ); + } + if ( node.type === 'radio' ) { + return new RadioNameBinding( attribute, node ); + } + } + if ( attribute.propertyName === 'checked' ) { + return new CheckedBinding( attribute, node ); + } + return null; + } + if ( attribute.lcName !== 'value' ) { + throw new Error( 'Attempted to set up an illegal two-way binding. This error is unexpected - if you can, please file an issue at https://github.com/RactiveJS/Ractive, or contact @RactiveJS on Twitter. Thanks!' ); + } + if ( node.type === 'file' ) { + return new FileListBinding( attribute, node ); + } + if ( node.getAttribute( 'contenteditable' ) ) { + return new ContentEditableBinding( attribute, node ); + } + return new GenericBinding( attribute, node ); + }; + MultipleSelectBinding = function( attribute, node ) { + var valueFromModel; + inheritProperties( this, attribute, node ); + node.addEventListener( 'change', updateModel, false ); + valueFromModel = get( this.root, this.keypath ); + if ( valueFromModel === undefined ) { + // get value from DOM, if possible + this.update(); + } + }; + MultipleSelectBinding.prototype = { + value: function() { + var selectedValues, options, i, len, option, optionValue; + selectedValues = []; + options = this.node.options; + len = options.length; + for ( i = 0; i < len; i += 1 ) { + option = options[ i ]; + if ( option.selected ) { + optionValue = option._ractive ? option._ractive.value : option.value; + selectedValues.push( optionValue ); + } + } + return selectedValues; + }, + update: function() { + var attribute, previousValue, value; + attribute = this.attr; + previousValue = attribute.value; + value = this.value(); + if ( previousValue === undefined || !arrayContentsMatch( value, previousValue ) ) { + // either length or contents have changed, so we update the model + runloop.addBinding( attribute ); + attribute.value = value; + set( this.root, this.keypath, value ); + runloop.trigger(); + } + return this; + }, + deferUpdate: function() { + if ( this.deferred === true ) { + return; + } + // TODO we're hijacking an existing bit of functionality here... + // the whole deferred updates thing could use a spring clean + runloop.addAttribute( this ); + this.deferred = true; + }, + teardown: function() { + this.node.removeEventListener( 'change', updateModel, false ); + } + }; + SelectBinding = function( attribute, node ) { + var valueFromModel; + inheritProperties( this, attribute, node ); + node.addEventListener( 'change', updateModel, false ); + valueFromModel = get( this.root, this.keypath ); + if ( valueFromModel === undefined ) { + // get value from DOM, if possible + this.update(); + } + }; + SelectBinding.prototype = { + value: function() { + var options, i, len, option, optionValue; + options = this.node.options; + len = options.length; + for ( i = 0; i < len; i += 1 ) { + option = options[ i ]; + if ( options[ i ].selected ) { + optionValue = option._ractive ? option._ractive.value : option.value; + return optionValue; + } + } + }, + update: function() { + var value = this.value(); + runloop.addBinding( this.attr ); + this.attr.value = value; + set( this.root, this.keypath, value ); + runloop.trigger(); + return this; + }, + deferUpdate: function() { + if ( this.deferred === true ) { + return; + } + // TODO we're hijacking an existing bit of functionality here... + // the whole deferred updates thing could use a spring clean + runloop.addAttribute( this ); + this.deferred = true; + }, + teardown: function() { + this.node.removeEventListener( 'change', updateModel, false ); + } + }; + RadioNameBinding = function( attribute, node ) { + var valueFromModel; + this.radioName = true; + // so that updateModel knows what to do with this + inheritProperties( this, attribute, node ); + node.name = '{{' + attribute.keypath + '}}'; + node.addEventListener( 'change', updateModel, false ); + if ( node.attachEvent ) { + node.addEventListener( 'click', updateModel, false ); + } + valueFromModel = get( this.root, this.keypath ); + if ( valueFromModel !== undefined ) { + node.checked = valueFromModel == node._ractive.value; + } else { + runloop.addRadio( this ); + } + }; + RadioNameBinding.prototype = { + value: function() { + return this.node._ractive ? this.node._ractive.value : this.node.value; + }, + update: function() { + var node = this.node; + if ( node.checked ) { + runloop.addBinding( this.attr ); + set( this.root, this.keypath, this.value() ); + runloop.trigger(); + } + }, + teardown: function() { + this.node.removeEventListener( 'change', updateModel, false ); + this.node.removeEventListener( 'click', updateModel, false ); + } + }; + CheckboxNameBinding = function( attribute, node ) { + var valueFromModel, checked; + this.checkboxName = true; + // so that updateModel knows what to do with this + inheritProperties( this, attribute, node ); + node.name = '{{' + this.keypath + '}}'; + node.addEventListener( 'change', updateModel, false ); + // in case of IE emergency, bind to click event as well + if ( node.attachEvent ) { + node.addEventListener( 'click', updateModel, false ); + } + valueFromModel = get( this.root, this.keypath ); + // if the model already specifies this value, check/uncheck accordingly + if ( valueFromModel !== undefined ) { + checked = valueFromModel.indexOf( node._ractive.value ) !== -1; + node.checked = checked; + } else { + runloop.addCheckbox( this ); + } + }; + CheckboxNameBinding.prototype = { + changed: function() { + return this.node.checked !== !! this.checked; + }, + update: function() { + this.checked = this.node.checked; + runloop.addBinding( this.attr ); + set( this.root, this.keypath, getValueFromCheckboxes( this.root, this.keypath ) ); + runloop.trigger(); + }, + teardown: function() { + this.node.removeEventListener( 'change', updateModel, false ); + this.node.removeEventListener( 'click', updateModel, false ); + } + }; + CheckedBinding = function( attribute, node ) { + inheritProperties( this, attribute, node ); + node.addEventListener( 'change', updateModel, false ); + if ( node.attachEvent ) { + node.addEventListener( 'click', updateModel, false ); + } + }; + CheckedBinding.prototype = { + value: function() { + return this.node.checked; + }, + update: function() { + runloop.addBinding( this.attr ); + set( this.root, this.keypath, this.value() ); + runloop.trigger(); + }, + teardown: function() { + this.node.removeEventListener( 'change', updateModel, false ); + this.node.removeEventListener( 'click', updateModel, false ); + } + }; + FileListBinding = function( attribute, node ) { + inheritProperties( this, attribute, node ); + node.addEventListener( 'change', updateModel, false ); + }; + FileListBinding.prototype = { + value: function() { + return this.attr.pNode.files; + }, + update: function() { + set( this.attr.root, this.attr.keypath, this.value() ); + runloop.trigger(); + }, + teardown: function() { + this.node.removeEventListener( 'change', updateModel, false ); + } + }; + ContentEditableBinding = function( attribute, node ) { + inheritProperties( this, attribute, node ); + node.addEventListener( 'change', updateModel, false ); + if ( !this.root.lazy ) { + node.addEventListener( 'input', updateModel, false ); + if ( node.attachEvent ) { + node.addEventListener( 'keyup', updateModel, false ); + } + } + }; + ContentEditableBinding.prototype = { + update: function() { + runloop.addBinding( this.attr ); + set( this.root, this.keypath, this.node.innerHTML ); + runloop.trigger(); + }, + teardown: function() { + this.node.removeEventListener( 'change', updateModel, false ); + this.node.removeEventListener( 'input', updateModel, false ); + this.node.removeEventListener( 'keyup', updateModel, false ); + } + }; + GenericBinding = function( attribute, node ) { + inheritProperties( this, attribute, node ); + node.addEventListener( 'change', updateModel, false ); + if ( !this.root.lazy ) { + node.addEventListener( 'input', updateModel, false ); + if ( node.attachEvent ) { + node.addEventListener( 'keyup', updateModel, false ); + } + } + this.node.addEventListener( 'blur', update, false ); + }; + GenericBinding.prototype = { + value: function() { + var value = this.attr.pNode.value; + // if the value is numeric, treat it as a number. otherwise don't + if ( +value + '' === value && value.indexOf( 'e' ) === -1 ) { + value = +value; + } + return value; + }, + update: function() { + var attribute = this.attr, + value = this.value(); + runloop.addBinding( attribute ); + set( attribute.root, attribute.keypath, value ); + runloop.trigger(); + }, + teardown: function() { + this.node.removeEventListener( 'change', updateModel, false ); + this.node.removeEventListener( 'input', updateModel, false ); + this.node.removeEventListener( 'keyup', updateModel, false ); + this.node.removeEventListener( 'blur', update, false ); + } + }; + inheritProperties = function( binding, attribute, node ) { + binding.attr = attribute; + binding.node = node; + binding.root = attribute.root; + binding.keypath = attribute.keypath; + }; + return bindAttribute; + }( global_runloop, utils_warn, utils_arrayContentsMatch, shared_getValueFromCheckboxes, shared_get__get, shared_set ); + + var render_DomFragment_Attribute_prototype_update = function( runloop, namespaces, isArray ) { + + var updateAttribute, updateFileInputValue, deferSelect, initSelect, updateSelect, updateMultipleSelect, updateRadioName, updateCheckboxName, updateIEStyleAttribute, updateClassName, updateContentEditableValue, updateEverythingElse; + // There are a few special cases when it comes to updating attributes. For this reason, + // the prototype .update() method points to updateAttribute, which waits until the + // attribute has finished initialising, then replaces the prototype method with a more + // suitable one. That way, we save ourselves doing a bunch of tests on each call + updateAttribute = function() { + var node; + if ( !this.ready ) { + return this; + } + node = this.pNode; + // special case - selects + if ( node.tagName === 'SELECT' && this.lcName === 'value' ) { + this.update = deferSelect; + this.deferredUpdate = initSelect; + // we don't know yet if it's a select-one or select-multiple + return this.update(); + } + // special case - + if ( this.isFileInputValue ) { + this.update = updateFileInputValue; + // save ourselves the trouble next time + return this; + } + // special case - + if ( this.twoway && this.lcName === 'name' ) { + if ( node.type === 'radio' ) { + this.update = updateRadioName; + return this.update(); + } + if ( node.type === 'checkbox' ) { + this.update = updateCheckboxName; + return this.update(); + } + } + // special case - style attributes in Internet Exploder + if ( this.lcName === 'style' && node.style.setAttribute ) { + this.update = updateIEStyleAttribute; + return this.update(); + } + // special case - class names. IE fucks things up, again + if ( this.lcName === 'class' && ( !node.namespaceURI || node.namespaceURI === namespaces.html ) ) { + this.update = updateClassName; + return this.update(); + } + // special case - contenteditable + if ( node.getAttribute( 'contenteditable' ) && this.lcName === 'value' ) { + this.update = updateContentEditableValue; + return this.update(); + } + this.update = updateEverythingElse; + return this.update(); + }; + updateFileInputValue = function() { + return this; + }; + initSelect = function() { + // we're now in a position to decide whether this is a select-one or select-multiple + this.deferredUpdate = this.pNode.multiple ? updateMultipleSelect : updateSelect; + this.deferredUpdate(); + }; + deferSelect = function() { + // because select values depend partly on the values of their children, and their + // children may be entering and leaving the DOM, we wait until updates are + // complete before updating + runloop.addSelectValue( this ); + return this; + }; + updateSelect = function() { + var value = this.fragment.getValue(), + options, option, optionValue, i; + this.value = this.pNode._ractive.value = value; + options = this.pNode.options; + i = options.length; + while ( i-- ) { + option = options[ i ]; + optionValue = option._ractive ? option._ractive.value : option.value; + // options inserted via a triple don't have _ractive + if ( optionValue == value ) { + // double equals as we may be comparing numbers with strings + option.selected = true; + return this; + } + } + // if we're still here, it means the new value didn't match any of the options... + // TODO figure out what to do in this situation + return this; + }; + updateMultipleSelect = function() { + var value = this.fragment.getValue(), + options, i, option, optionValue; + if ( !isArray( value ) ) { + value = [ value ]; + } + options = this.pNode.options; + i = options.length; + while ( i-- ) { + option = options[ i ]; + optionValue = option._ractive ? option._ractive.value : option.value; + // options inserted via a triple don't have _ractive + option.selected = value.indexOf( optionValue ) !== -1; + } + this.value = value; + return this; + }; + updateRadioName = function() { + var node, value; + node = this.pNode; + value = this.fragment.getValue(); + node.checked = value == node._ractive.value; + return this; + }; + updateCheckboxName = function() { + var node, value; + node = this.pNode; + value = this.fragment.getValue(); + if ( !isArray( value ) ) { + node.checked = value == node._ractive.value; + return this; + } + node.checked = value.indexOf( node._ractive.value ) !== -1; + return this; + }; + updateIEStyleAttribute = function() { + var node, value; + node = this.pNode; + value = this.fragment.getValue(); + if ( value === undefined ) { + value = ''; + } + if ( value !== this.value ) { + node.style.setAttribute( 'cssText', value ); + this.value = value; + } + return this; + }; + updateClassName = function() { + var node, value; + node = this.pNode; + value = this.fragment.getValue(); + if ( value === undefined ) { + value = ''; + } + if ( value !== this.value ) { + node.className = value; + this.value = value; + } + return this; + }; + updateContentEditableValue = function() { + var node, value; + node = this.pNode; + value = this.fragment.getValue(); + if ( value === undefined ) { + value = ''; + } + if ( value !== this.value ) { + if ( !this.active ) { + node.innerHTML = value; + } + this.value = value; + } + return this; + }; + updateEverythingElse = function() { + var node, value, binding; + node = this.pNode; + value = this.fragment.getValue(); + // store actual value, so it doesn't get coerced to a string + if ( this.isValueAttribute ) { + node._ractive.value = value; + } + if ( value == undefined ) { + value = ''; + } + if ( value !== this.value ) { + if ( this.useProperty ) { + // with two-way binding, only update if the change wasn't initiated by the user + // otherwise the cursor will often be sent to the wrong place + if ( !this.active ) { + node[ this.propertyName ] = value; + } + // special case - a selected option whose select element has two-way binding + if ( node.tagName === 'OPTION' && node.selected && ( binding = this.element.select.binding ) ) { + binding.update(); + } + this.value = value; + return this; + } + if ( this.namespace ) { + node.setAttributeNS( this.namespace, this.name, value ); + this.value = value; + return this; + } + if ( this.lcName === 'id' ) { + if ( this.value !== undefined ) { + this.root.nodes[ this.value ] = undefined; + } + this.root.nodes[ value ] = node; + } + node.setAttribute( this.name, value ); + this.value = value; + } + return this; + }; + return updateAttribute; + }( global_runloop, config_namespaces, utils_isArray ); + + var parse_Tokenizer_utils_getStringMatch = function( string ) { + var substr; + substr = this.str.substr( this.pos, string.length ); + if ( substr === string ) { + this.pos += string.length; + return string; + } + return null; + }; + + var parse_Tokenizer_utils_allowWhitespace = function() { + + var leadingWhitespace = /^\s+/; + return function() { + var match = leadingWhitespace.exec( this.remaining() ); + if ( !match ) { + return null; + } + this.pos += match[ 0 ].length; + return match[ 0 ]; + }; + }(); + + var parse_Tokenizer_utils_makeRegexMatcher = function( regex ) { + return function( tokenizer ) { + var match = regex.exec( tokenizer.str.substring( tokenizer.pos ) ); + if ( !match ) { + return null; + } + tokenizer.pos += match[ 0 ].length; + return match[ 1 ] || match[ 0 ]; + }; + }; + + var parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_makeQuotedStringMatcher = function( makeRegexMatcher ) { + + var getStringMiddle, getEscapeSequence, getLineContinuation; + // Match one or more characters until: ", ', \, or EOL/EOF. + // EOL/EOF is written as (?!.) (meaning there's no non-newline char next). + getStringMiddle = makeRegexMatcher( /^(?=.)[^"'\\]+?(?:(?!.)|(?=["'\\]))/ ); + // Match one escape sequence, including the backslash. + getEscapeSequence = makeRegexMatcher( /^\\(?:['"\\bfnrt]|0(?![0-9])|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|(?=.)[^ux0-9])/ ); + // Match one ES5 line continuation (backslash + line terminator). + getLineContinuation = makeRegexMatcher( /^\\(?:\r\n|[\u000A\u000D\u2028\u2029])/ ); + // Helper for defining getDoubleQuotedString and getSingleQuotedString. + return function( okQuote ) { + return function( tokenizer ) { + var start, literal, done, next; + start = tokenizer.pos; + literal = '"'; + done = false; + while ( !done ) { + next = getStringMiddle( tokenizer ) || getEscapeSequence( tokenizer ) || tokenizer.getStringMatch( okQuote ); + if ( next ) { + if ( next === '"' ) { + literal += '\\"'; + } else if ( next === '\\\'' ) { + literal += '\''; + } else { + literal += next; + } + } else { + next = getLineContinuation( tokenizer ); + if ( next ) { + // convert \(newline-like) into a \u escape, which is allowed in JSON + literal += '\\u' + ( '000' + next.charCodeAt( 1 ).toString( 16 ) ).slice( -4 ); + } else { + done = true; + } + } + } + literal += '"'; + // use JSON.parse to interpret escapes + return JSON.parse( literal ); + }; + }; + }( parse_Tokenizer_utils_makeRegexMatcher ); + + var parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getSingleQuotedString = function( makeQuotedStringMatcher ) { + + return makeQuotedStringMatcher( '"' ); + }( parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_makeQuotedStringMatcher ); + + var parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getDoubleQuotedString = function( makeQuotedStringMatcher ) { + + return makeQuotedStringMatcher( '\'' ); + }( parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_makeQuotedStringMatcher ); + + var parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral = function( types, getSingleQuotedString, getDoubleQuotedString ) { + + return function( tokenizer ) { + var start, string; + start = tokenizer.pos; + if ( tokenizer.getStringMatch( '"' ) ) { + string = getDoubleQuotedString( tokenizer ); + if ( !tokenizer.getStringMatch( '"' ) ) { + tokenizer.pos = start; + return null; + } + return { + t: types.STRING_LITERAL, + v: string + }; + } + if ( tokenizer.getStringMatch( '\'' ) ) { + string = getSingleQuotedString( tokenizer ); + if ( !tokenizer.getStringMatch( '\'' ) ) { + tokenizer.pos = start; + return null; + } + return { + t: types.STRING_LITERAL, + v: string + }; + } + return null; + }; + }( config_types, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getSingleQuotedString, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral_getDoubleQuotedString ); + + var parse_Tokenizer_getExpression_getPrimary_getLiteral_getNumberLiteral = function( types, makeRegexMatcher ) { + + // bulletproof number regex from https://gist.github.com/Rich-Harris/7544330 + var getNumber = makeRegexMatcher( /^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/ ); + return function( tokenizer ) { + var result; + if ( result = getNumber( tokenizer ) ) { + return { + t: types.NUMBER_LITERAL, + v: result + }; + } + return null; + }; + }( config_types, parse_Tokenizer_utils_makeRegexMatcher ); + + var parse_Tokenizer_getExpression_shared_getName = function( makeRegexMatcher ) { + + return makeRegexMatcher( /^[a-zA-Z_$][a-zA-Z_$0-9]*/ ); + }( parse_Tokenizer_utils_makeRegexMatcher ); + + var parse_Tokenizer_getExpression_shared_getKey = function( getStringLiteral, getNumberLiteral, getName ) { + + var identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/; + // http://mathiasbynens.be/notes/javascript-properties + // can be any name, string literal, or number literal + return function( tokenizer ) { + var token; + if ( token = getStringLiteral( tokenizer ) ) { + return identifier.test( token.v ) ? token.v : '"' + token.v.replace( /"/g, '\\"' ) + '"'; + } + if ( token = getNumberLiteral( tokenizer ) ) { + return token.v; + } + if ( token = getName( tokenizer ) ) { + return token; + } + }; + }( parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getNumberLiteral, parse_Tokenizer_getExpression_shared_getName ); + + var utils_parseJSON = function( getStringMatch, allowWhitespace, getStringLiteral, getKey ) { + + // simple JSON parser, without the restrictions of JSON parse + // (i.e. having to double-quote keys). + // + // This re-uses logic from the main template parser, albeit + // messily. Could probably use a cleanup at some point. + // + // If passed a hash of values as the second argument, ${placeholders} + // will be replaced with those values + var Tokenizer, specials, specialsPattern, numberPattern, placeholderPattern, placeholderAtStartPattern; + specials = { + 'true': true, + 'false': false, + 'undefined': undefined, + 'null': null + }; + specialsPattern = new RegExp( '^(?:' + Object.keys( specials ).join( '|' ) + ')' ); + numberPattern = /^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/; + placeholderPattern = /\$\{([^\}]+)\}/g; + placeholderAtStartPattern = /^\$\{([^\}]+)\}/; + Tokenizer = function( str, values ) { + this.str = str; + this.values = values; + this.pos = 0; + this.result = this.getToken(); + }; + Tokenizer.prototype = { + remaining: function() { + return this.str.substring( this.pos ); + }, + getStringMatch: getStringMatch, + getToken: function() { + this.allowWhitespace(); + return this.getPlaceholder() || this.getSpecial() || this.getNumber() || this.getString() || this.getObject() || this.getArray(); + }, + getPlaceholder: function() { + var match; + if ( !this.values ) { + return null; + } + if ( ( match = placeholderAtStartPattern.exec( this.remaining() ) ) && this.values.hasOwnProperty( match[ 1 ] ) ) { + this.pos += match[ 0 ].length; + return { + v: this.values[ match[ 1 ] ] + }; + } + }, + getSpecial: function() { + var match; + if ( match = specialsPattern.exec( this.remaining() ) ) { + this.pos += match[ 0 ].length; + return { + v: specials[ match[ 0 ] ] + }; + } + }, + getNumber: function() { + var match; + if ( match = numberPattern.exec( this.remaining() ) ) { + this.pos += match[ 0 ].length; + return { + v: +match[ 0 ] + }; + } + }, + getString: function() { + var stringLiteral = getStringLiteral( this ), + values; + if ( stringLiteral && ( values = this.values ) ) { + return { + v: stringLiteral.v.replace( placeholderPattern, function( match, $1 ) { + return values[ $1 ] || $1; + } ) + }; + } + return stringLiteral; + }, + getObject: function() { + var result, pair; + if ( !this.getStringMatch( '{' ) ) { + return null; + } + result = {}; + while ( pair = getKeyValuePair( this ) ) { + result[ pair.key ] = pair.value; + this.allowWhitespace(); + if ( this.getStringMatch( '}' ) ) { + return { + v: result + }; + } + if ( !this.getStringMatch( ',' ) ) { + return null; + } + } + return null; + }, + getArray: function() { + var result, valueToken; + if ( !this.getStringMatch( '[' ) ) { + return null; + } + result = []; + while ( valueToken = this.getToken() ) { + result.push( valueToken.v ); + if ( this.getStringMatch( ']' ) ) { + return { + v: result + }; + } + if ( !this.getStringMatch( ',' ) ) { + return null; + } + } + return null; + }, + allowWhitespace: allowWhitespace + }; + + function getKeyValuePair( tokenizer ) { + var key, valueToken, pair; + tokenizer.allowWhitespace(); + key = getKey( tokenizer ); + if ( !key ) { + return null; + } + pair = { + key: key + }; + tokenizer.allowWhitespace(); + if ( !tokenizer.getStringMatch( ':' ) ) { + return null; + } + tokenizer.allowWhitespace(); + valueToken = tokenizer.getToken(); + if ( !valueToken ) { + return null; + } + pair.value = valueToken.v; + return pair; + } + return function( str, values ) { + var tokenizer = new Tokenizer( str, values ); + if ( tokenizer.result ) { + return { + value: tokenizer.result.v, + remaining: tokenizer.remaining() + }; + } + return null; + }; + }( parse_Tokenizer_utils_getStringMatch, parse_Tokenizer_utils_allowWhitespace, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral, parse_Tokenizer_getExpression_shared_getKey ); + + var render_StringFragment_Interpolator = function( types, teardown, Mustache ) { + + var StringInterpolator = function( options ) { + this.type = types.INTERPOLATOR; + Mustache.init( this, options ); + }; + StringInterpolator.prototype = { + update: Mustache.update, + resolve: Mustache.resolve, + reassign: Mustache.reassign, + render: function( value ) { + this.value = value; + this.parentFragment.bubble(); + }, + teardown: function() { + teardown( this ); + }, + toString: function() { + if ( this.value == undefined ) { + return ''; + } + return stringify( this.value ); + } + }; + return StringInterpolator; + + function stringify( value ) { + if ( typeof value === 'string' ) { + return value; + } + return JSON.stringify( value ); + } + }( config_types, shared_teardown, render_shared_Mustache__Mustache ); + + var render_StringFragment_Section = function( types, Mustache, updateSection, teardown, circular ) { + + var StringSection, StringFragment; + circular.push( function() { + StringFragment = circular.StringFragment; + } ); + StringSection = function( options ) { + this.type = types.SECTION; + this.fragments = []; + this.length = 0; + Mustache.init( this, options ); + }; + StringSection.prototype = { + update: Mustache.update, + resolve: Mustache.resolve, + reassign: Mustache.reassign, + teardown: function() { + this.teardownFragments(); + teardown( this ); + }, + teardownFragments: function() { + while ( this.fragments.length ) { + this.fragments.shift().teardown(); + } + this.length = 0; + }, + bubble: function() { + this.value = this.fragments.join( '' ); + this.parentFragment.bubble(); + }, + render: function( value ) { + var wrapped; + // with sections, we need to get the fake value if we have a wrapped object + if ( wrapped = this.root._wrapped[ this.keypath ] ) { + value = wrapped.get(); + } + updateSection( this, value ); + this.parentFragment.bubble(); + }, + createFragment: function( options ) { + return new StringFragment( options ); + }, + toString: function() { + return this.fragments.join( '' ); + } + }; + return StringSection; + }( config_types, render_shared_Mustache__Mustache, render_shared_updateSection, shared_teardown, circular ); + + var render_StringFragment_Text = function( types ) { + + var StringText = function( text ) { + this.type = types.TEXT; + this.text = text; + }; + StringText.prototype = { + toString: function() { + return this.text; + }, + reassign: function() {}, + //no-op + teardown: function() {} + }; + return StringText; + }( config_types ); + + var render_StringFragment_prototype_toArgsList = function( warn, parseJSON ) { + + return function() { + var values, counter, jsonesque, guid, errorMessage, parsed, processItems; + if ( !this.argsList || this.dirty ) { + values = {}; + counter = 0; + guid = this.root._guid; + processItems = function( items ) { + return items.map( function( item ) { + var placeholderId, wrapped, value; + if ( item.text ) { + return item.text; + } + if ( item.fragments ) { + return item.fragments.map( function( fragment ) { + return processItems( fragment.items ); + } ).join( '' ); + } + placeholderId = guid + '-' + counter++; + if ( wrapped = item.root._wrapped[ item.keypath ] ) { + value = wrapped.value; + } else { + value = item.value; + } + values[ placeholderId ] = value; + return '${' + placeholderId + '}'; + } ).join( '' ); + }; + jsonesque = processItems( this.items ); + parsed = parseJSON( '[' + jsonesque + ']', values ); + if ( !parsed ) { + errorMessage = 'Could not parse directive arguments (' + this.toString() + '). If you think this is a bug, please file an issue at http://github.com/RactiveJS/Ractive/issues'; + if ( this.root.debug ) { + throw new Error( errorMessage ); + } else { + warn( errorMessage ); + this.argsList = [ jsonesque ]; + } + } else { + this.argsList = parsed.value; + } + this.dirty = false; + } + return this.argsList; + }; + }( utils_warn, utils_parseJSON ); + + var render_StringFragment__StringFragment = function( types, parseJSON, Fragment, Interpolator, Section, Text, toArgsList, circular ) { + + var StringFragment = function( options ) { + Fragment.init( this, options ); + }; + StringFragment.prototype = { + reassign: Fragment.reassign, + createItem: function( options ) { + if ( typeof options.descriptor === 'string' ) { + return new Text( options.descriptor ); + } + switch ( options.descriptor.t ) { + case types.INTERPOLATOR: + return new Interpolator( options ); + case types.TRIPLE: + return new Interpolator( options ); + case types.SECTION: + return new Section( options ); + default: + throw 'Something went wrong in a rather interesting way'; + } + }, + bubble: function() { + this.dirty = true; + this.owner.bubble(); + }, + teardown: function() { + var numItems, i; + numItems = this.items.length; + for ( i = 0; i < numItems; i += 1 ) { + this.items[ i ].teardown(); + } + }, + getValue: function() { + var value; + // Accommodate boolean attributes + if ( this.items.length === 1 && this.items[ 0 ].type === types.INTERPOLATOR ) { + value = this.items[ 0 ].value; + if ( value !== undefined ) { + return value; + } + } + return this.toString(); + }, + isSimple: function() { + var i, item, containsInterpolator; + if ( this.simple !== undefined ) { + return this.simple; + } + i = this.items.length; + while ( i-- ) { + item = this.items[ i ]; + if ( item.type === types.TEXT ) { + continue; + } + // we can only have one interpolator and still be self-updating + if ( item.type === types.INTERPOLATOR ) { + if ( containsInterpolator ) { + return false; + } else { + containsInterpolator = true; + continue; + } + } + // anything that isn't text or an interpolator (i.e. a section) + // and we can't self-update + return this.simple = false; + } + return this.simple = true; + }, + toString: function() { + return this.items.join( '' ); + }, + toJSON: function() { + var value = this.getValue(), + parsed; + if ( typeof value === 'string' ) { + parsed = parseJSON( value ); + value = parsed ? parsed.value : value; + } + return value; + }, + toArgsList: toArgsList + }; + circular.StringFragment = StringFragment; + return StringFragment; + }( config_types, utils_parseJSON, render_shared_Fragment__Fragment, render_StringFragment_Interpolator, render_StringFragment_Section, render_StringFragment_Text, render_StringFragment_prototype_toArgsList, circular ); + + var render_DomFragment_Attribute__Attribute = function( runloop, types, determineNameAndNamespace, setStaticAttribute, determinePropertyName, getInterpolator, bind, update, StringFragment ) { + + var DomAttribute = function( options ) { + this.type = types.ATTRIBUTE; + this.element = options.element; + determineNameAndNamespace( this, options.name ); + // if it's an empty attribute, or just a straight key-value pair, with no + // mustache shenanigans, set the attribute accordingly and go home + if ( options.value === null || typeof options.value === 'string' ) { + setStaticAttribute( this, options ); + return; + } + // otherwise we need to do some work + this.root = options.root; + this.pNode = options.pNode; + // share parentFragment with parent element + this.parentFragment = this.element.parentFragment; + this.fragment = new StringFragment( { + descriptor: options.value, + root: this.root, + owner: this + } ); + // Store a reference to this attribute's interpolator, if its fragment + // takes the form `{{foo}}`. This is necessary for two-way binding and + // for correctly rendering HTML later + this.interpolator = getInterpolator( this ); + // if we're not rendering (i.e. we're just stringifying), we can stop here + if ( !this.pNode ) { + return; + } + // special cases + if ( this.name === 'value' ) { + this.isValueAttribute = true; + // TODO need to wait until afterwards to determine type, in case we + // haven't initialised that attribute yet + // + if ( this.pNode.tagName === 'INPUT' && this.pNode.type === 'file' ) { + this.isFileInputValue = true; + } + } + // can we establish this attribute's property name equivalent? + determinePropertyName( this, options ); + // determine whether this attribute can be marked as self-updating + this.selfUpdating = this.fragment.isSimple(); + // mark as ready + this.ready = true; + }; + DomAttribute.prototype = { + bind: bind, + update: update, + updateBindings: function() { + // if the fragment this attribute belongs to gets reassigned (as a result of + // as section being updated via an array shift, unshift or splice), this + // attribute needs to recognise that its keypath has changed + this.keypath = this.interpolator.keypath || this.interpolator.ref; + // if we encounter the special case described above, update the name attribute + if ( this.propertyName === 'name' ) { + // replace actual name attribute + this.pNode.name = '{{' + this.keypath + '}}'; + } + }, + reassign: function( indexRef, newIndex, oldKeypath, newKeypath ) { + if ( this.fragment ) { + this.fragment.reassign( indexRef, newIndex, oldKeypath, newKeypath ); + if ( this.twoway ) { + this.updateBindings(); + } + } + }, + teardown: function() { + var i; + if ( this.boundEvents ) { + i = this.boundEvents.length; + while ( i-- ) { + this.pNode.removeEventListener( this.boundEvents[ i ], this.updateModel, false ); + } + } + // ignore non-dynamic attributes + if ( this.fragment ) { + this.fragment.teardown(); + } + }, + bubble: function() { + // If an attribute's text fragment contains a single item, we can + // update the DOM immediately... + if ( this.selfUpdating ) { + this.update(); + } else if ( !this.deferred && this.ready ) { + runloop.addAttribute( this ); + this.deferred = true; + } + }, + toString: function() { + var str, interpolator; + if ( this.value === null ) { + return this.name; + } + // Special case - select values (should not be stringified) + if ( this.name === 'value' && this.element.lcName === 'select' ) { + return; + } + // Special case - radio names + if ( this.name === 'name' && this.element.lcName === 'input' && ( interpolator = this.interpolator ) ) { + return 'name={{' + ( interpolator.keypath || interpolator.ref ) + '}}'; + } + // TODO don't use JSON.stringify? + if ( !this.fragment ) { + return this.name + '=' + JSON.stringify( this.value ); + } + // TODO deal with boolean attributes correctly + str = this.fragment.toString(); + return this.name + '=' + JSON.stringify( str ); + } + }; + return DomAttribute; + }( global_runloop, config_types, render_DomFragment_Attribute_helpers_determineNameAndNamespace, render_DomFragment_Attribute_helpers_setStaticAttribute, render_DomFragment_Attribute_helpers_determinePropertyName, render_DomFragment_Attribute_helpers_getInterpolator, render_DomFragment_Attribute_prototype_bind, render_DomFragment_Attribute_prototype_update, render_StringFragment__StringFragment ); + + var render_DomFragment_Element_initialise_createElementAttribute = function( Attribute ) { + + return function createElementAttribute( element, name, fragment ) { + var attr = new Attribute( { + element: element, + name: name, + value: fragment, + root: element.root, + pNode: element.node + } ); + // store against both index and name, for fast iteration and lookup + element.attributes.push( element.attributes[ name ] = attr ); + // The name attribute is a special case - it is the only two-way attribute that updates + // the viewmodel based on the value of another attribute. For that reason it must wait + // until the node has been initialised, and the viewmodel has had its first two-way + // update, before updating itself (otherwise it may disable a checkbox or radio that + // was enabled in the template) + if ( name !== 'name' ) { + attr.update(); + } + }; + }( render_DomFragment_Attribute__Attribute ); + + var render_DomFragment_Element_initialise_createElementAttributes = function( createElementAttribute ) { + + return function( element, attributes ) { + var attrName; + element.attributes = []; + for ( attrName in attributes ) { + if ( attributes.hasOwnProperty( attrName ) ) { + createElementAttribute( element, attrName, attributes[ attrName ] ); + } + } + return element.attributes; + }; + }( render_DomFragment_Element_initialise_createElementAttribute ); + + var utils_toArray = function toArray( arrayLike ) { + var array = [], + i = arrayLike.length; + while ( i-- ) { + array[ i ] = arrayLike[ i ]; + } + return array; + }; + + var render_DomFragment_Element_shared_getMatchingStaticNodes = function( toArray ) { + + return function getMatchingStaticNodes( element, selector ) { + if ( !element.matchingStaticNodes[ selector ] ) { + element.matchingStaticNodes[ selector ] = toArray( element.node.querySelectorAll( selector ) ); + } + return element.matchingStaticNodes[ selector ]; + }; + }( utils_toArray ); + + var render_DomFragment_Element_initialise_appendElementChildren = function( warn, namespaces, StringFragment, getMatchingStaticNodes, circular ) { + + var DomFragment, updateCss, updateScript; + circular.push( function() { + DomFragment = circular.DomFragment; + } ); + updateCss = function() { + var node = this.node, + content = this.fragment.toString(); + if ( node.styleSheet ) { + node.styleSheet.cssText = content; + } else { + node.innerHTML = content; + } + }; + updateScript = function() { + if ( !this.node.type || this.node.type === 'text/javascript' ) { + warn( 'Script tag was updated. This does not cause the code to be re-evaluated!' ); + } + this.node.text = this.fragment.toString(); + }; + return function appendElementChildren( element, node, descriptor, docFrag ) { + // Special case - script and style tags + if ( element.lcName === 'script' || element.lcName === 'style' ) { + element.fragment = new StringFragment( { + descriptor: descriptor.f, + root: element.root, + owner: element + } ); + if ( docFrag ) { + if ( element.lcName === 'script' ) { + element.bubble = updateScript; + element.node.text = element.fragment.toString(); + } else { + element.bubble = updateCss; + element.bubble(); + } + } + return; + } + if ( typeof descriptor.f === 'string' && ( !node || ( !node.namespaceURI || node.namespaceURI === namespaces.html ) ) ) { + // great! we can use innerHTML + element.html = descriptor.f; + if ( docFrag ) { + node.innerHTML = element.html; + // Update live queries, if applicable + element.matchingStaticNodes = {}; + // so we can remove matches made with querySelectorAll at teardown time + updateLiveQueries( element ); + } + } else { + element.fragment = new DomFragment( { + descriptor: descriptor.f, + root: element.root, + pNode: node, + owner: element, + pElement: element + } ); + if ( docFrag ) { + node.appendChild( element.fragment.docFrag ); + } + } + }; + + function updateLiveQueries( element ) { + var instance, liveQueries, node, selector, query, matchingStaticNodes, i; + node = element.node; + instance = element.root; + do { + liveQueries = instance._liveQueries; + i = liveQueries.length; + while ( i-- ) { + selector = liveQueries[ i ]; + query = liveQueries[ selector ]; + matchingStaticNodes = getMatchingStaticNodes( element, selector ); + query.push.apply( query, matchingStaticNodes ); + } + } while ( instance = instance._parent ); + } + }( utils_warn, config_namespaces, render_StringFragment__StringFragment, render_DomFragment_Element_shared_getMatchingStaticNodes, circular ); + + var render_DomFragment_Element_initialise_decorate_Decorator = function( warn, StringFragment ) { + + var Decorator = function( descriptor, ractive, owner ) { + var decorator = this, + name, fragment, errorMessage; + decorator.root = ractive; + decorator.node = owner.node; + name = descriptor.n || descriptor; + if ( typeof name !== 'string' ) { + fragment = new StringFragment( { + descriptor: name, + root: ractive, + owner: owner + } ); + name = fragment.toString(); + fragment.teardown(); + } + if ( descriptor.a ) { + decorator.params = descriptor.a; + } else if ( descriptor.d ) { + decorator.fragment = new StringFragment( { + descriptor: descriptor.d, + root: ractive, + owner: owner + } ); + decorator.params = decorator.fragment.toArgsList(); + decorator.fragment.bubble = function() { + this.dirty = true; + decorator.params = this.toArgsList(); + if ( decorator.ready ) { + decorator.update(); + } + }; + } + decorator.fn = ractive.decorators[ name ]; + if ( !decorator.fn ) { + errorMessage = 'Missing "' + name + '" decorator. You may need to download a plugin via http://docs.ractivejs.org/latest/plugins#decorators'; + if ( ractive.debug ) { + throw new Error( errorMessage ); + } else { + warn( errorMessage ); + } + } + }; + Decorator.prototype = { + init: function() { + var result, args; + if ( this.params ) { + args = [ this.node ].concat( this.params ); + result = this.fn.apply( this.root, args ); + } else { + result = this.fn.call( this.root, this.node ); + } + if ( !result || !result.teardown ) { + throw new Error( 'Decorator definition must return an object with a teardown method' ); + } + // TODO does this make sense? + this.actual = result; + this.ready = true; + }, + update: function() { + if ( this.actual.update ) { + this.actual.update.apply( this.root, this.params ); + } else { + this.actual.teardown( true ); + this.init(); + } + }, + teardown: function( updating ) { + this.actual.teardown(); + if ( !updating && this.fragment ) { + this.fragment.teardown(); + } + } + }; + return Decorator; + }( utils_warn, render_StringFragment__StringFragment ); + + var render_DomFragment_Element_initialise_decorate__decorate = function( runloop, Decorator ) { + + return function( descriptor, root, owner ) { + var decorator = new Decorator( descriptor, root, owner ); + if ( decorator.fn ) { + owner.decorator = decorator; + runloop.addDecorator( owner.decorator ); + } + }; + }( global_runloop, render_DomFragment_Element_initialise_decorate_Decorator ); + + var render_DomFragment_Element_initialise_addEventProxies_addEventProxy = function( warn, StringFragment ) { + + var addEventProxy, + // helpers + MasterEventHandler, ProxyEvent, firePlainEvent, fireEventWithArgs, fireEventWithDynamicArgs, customHandlers, genericHandler, getCustomHandler; + addEventProxy = function( element, triggerEventName, proxyDescriptor, indexRefs ) { + var events, master; + events = element.node._ractive.events; + master = events[ triggerEventName ] || ( events[ triggerEventName ] = new MasterEventHandler( element, triggerEventName, indexRefs ) ); + master.add( proxyDescriptor ); + }; + MasterEventHandler = function( element, eventName ) { + var definition; + this.element = element; + this.root = element.root; + this.node = element.node; + this.name = eventName; + this.proxies = []; + if ( definition = this.root.events[ eventName ] ) { + this.custom = definition( this.node, getCustomHandler( eventName ) ); + } else { + // Looks like we're dealing with a standard DOM event... but let's check + if ( !( 'on' + eventName in this.node ) ) { + warn( 'Missing "' + this.name + '" event. You may need to download a plugin via http://docs.ractivejs.org/latest/plugins#events' ); + } + this.node.addEventListener( eventName, genericHandler, false ); + } + }; + MasterEventHandler.prototype = { + add: function( proxy ) { + this.proxies.push( new ProxyEvent( this.element, this.root, proxy ) ); + }, + // TODO teardown when element torn down + teardown: function() { + var i; + if ( this.custom ) { + this.custom.teardown(); + } else { + this.node.removeEventListener( this.name, genericHandler, false ); + } + i = this.proxies.length; + while ( i-- ) { + this.proxies[ i ].teardown(); + } + }, + fire: function( event ) { + var i = this.proxies.length; + while ( i-- ) { + this.proxies[ i ].fire( event ); + } + } + }; + ProxyEvent = function( element, ractive, descriptor ) { + var name; + this.root = ractive; + name = descriptor.n || descriptor; + if ( typeof name === 'string' ) { + this.n = name; + } else { + this.n = new StringFragment( { + descriptor: descriptor.n, + root: this.root, + owner: element + } ); + } + if ( descriptor.a ) { + this.a = descriptor.a; + this.fire = fireEventWithArgs; + return; + } + if ( descriptor.d ) { + this.d = new StringFragment( { + descriptor: descriptor.d, + root: this.root, + owner: element + } ); + this.fire = fireEventWithDynamicArgs; + return; + } + this.fire = firePlainEvent; + }; + ProxyEvent.prototype = { + teardown: function() { + if ( this.n.teardown ) { + this.n.teardown(); + } + if ( this.d ) { + this.d.teardown(); + } + }, + bubble: function() {} + }; + // the ProxyEvent instance fire method could be any of these + firePlainEvent = function( event ) { + this.root.fire( this.n.toString(), event ); + }; + fireEventWithArgs = function( event ) { + this.root.fire.apply( this.root, [ + this.n.toString(), + event + ].concat( this.a ) ); + }; + fireEventWithDynamicArgs = function( event ) { + var args = this.d.toArgsList(); + // need to strip [] from ends if a string! + if ( typeof args === 'string' ) { + args = args.substr( 1, args.length - 2 ); + } + this.root.fire.apply( this.root, [ + this.n.toString(), + event + ].concat( args ) ); + }; + // all native DOM events dealt with by Ractive share a single handler + genericHandler = function( event ) { + var storage = this._ractive; + storage.events[ event.type ].fire( { + node: this, + original: event, + index: storage.index, + keypath: storage.keypath, + context: storage.root.get( storage.keypath ) + } ); + }; + customHandlers = {}; + getCustomHandler = function( eventName ) { + if ( customHandlers[ eventName ] ) { + return customHandlers[ eventName ]; + } + return customHandlers[ eventName ] = function( event ) { + var storage = event.node._ractive; + event.index = storage.index; + event.keypath = storage.keypath; + event.context = storage.root.get( storage.keypath ); + storage.events[ eventName ].fire( event ); + }; + }; + return addEventProxy; + }( utils_warn, render_StringFragment__StringFragment ); + + var render_DomFragment_Element_initialise_addEventProxies__addEventProxies = function( addEventProxy ) { + + return function( element, proxies ) { + var i, eventName, eventNames; + for ( eventName in proxies ) { + if ( proxies.hasOwnProperty( eventName ) ) { + eventNames = eventName.split( '-' ); + i = eventNames.length; + while ( i-- ) { + addEventProxy( element, eventNames[ i ], proxies[ eventName ] ); + } + } + } + }; + }( render_DomFragment_Element_initialise_addEventProxies_addEventProxy ); + + var render_DomFragment_Element_initialise_updateLiveQueries = function( element ) { + var instance, liveQueries, i, selector, query; + // Does this need to be added to any live queries? + instance = element.root; + do { + liveQueries = instance._liveQueries; + i = liveQueries.length; + while ( i-- ) { + selector = liveQueries[ i ]; + query = liveQueries[ selector ]; + if ( query._test( element ) ) { + // keep register of applicable selectors, for when we teardown + ( element.liveQueries || ( element.liveQueries = [] ) ).push( query ); + } + } + } while ( instance = instance._parent ); + }; + + var render_DomFragment_Element_shared_executeTransition_Transition_prototype_init = function() { + if ( this._inited ) { + throw new Error( 'Cannot initialize a transition more than once' ); + } + this._inited = true; + this._fn.apply( this.root, [ this ].concat( this.params ) ); + }; + + var render_DomFragment_Element_shared_executeTransition_Transition_helpers_prefix = function( isClient, vendors, createElement ) { + + var prefixCache, testStyle; + if ( !isClient ) { + return; + } + prefixCache = {}; + testStyle = createElement( 'div' ).style; + return function( prop ) { + var i, vendor, capped; + if ( !prefixCache[ prop ] ) { + if ( testStyle[ prop ] !== undefined ) { + prefixCache[ prop ] = prop; + } else { + // test vendors... + capped = prop.charAt( 0 ).toUpperCase() + prop.substring( 1 ); + i = vendors.length; + while ( i-- ) { + vendor = vendors[ i ]; + if ( testStyle[ vendor + capped ] !== undefined ) { + prefixCache[ prop ] = vendor + capped; + break; + } + } + } + } + return prefixCache[ prop ]; + }; + }( config_isClient, config_vendors, utils_createElement ); + + var render_DomFragment_Element_shared_executeTransition_Transition_prototype_getStyle = function( legacy, isClient, isArray, prefix ) { + + var getComputedStyle; + if ( !isClient ) { + return; + } + getComputedStyle = window.getComputedStyle || legacy.getComputedStyle; + return function( props ) { + var computedStyle, styles, i, prop, value; + computedStyle = window.getComputedStyle( this.node ); + if ( typeof props === 'string' ) { + value = computedStyle[ prefix( props ) ]; + if ( value === '0px' ) { + value = 0; + } + return value; + } + if ( !isArray( props ) ) { + throw new Error( 'Transition#getStyle must be passed a string, or an array of strings representing CSS properties' ); + } + styles = {}; + i = props.length; + while ( i-- ) { + prop = props[ i ]; + value = computedStyle[ prefix( prop ) ]; + if ( value === '0px' ) { + value = 0; + } + styles[ prop ] = value; + } + return styles; + }; + }( legacy, config_isClient, utils_isArray, render_DomFragment_Element_shared_executeTransition_Transition_helpers_prefix ); + + var render_DomFragment_Element_shared_executeTransition_Transition_prototype_setStyle = function( prefix ) { + + return function( style, value ) { + var prop; + if ( typeof style === 'string' ) { + this.node.style[ prefix( style ) ] = value; + } else { + for ( prop in style ) { + if ( style.hasOwnProperty( prop ) ) { + this.node.style[ prefix( prop ) ] = style[ prop ]; + } + } + } + return this; + }; + }( render_DomFragment_Element_shared_executeTransition_Transition_helpers_prefix ); + + var utils_camelCase = function( hyphenatedStr ) { + return hyphenatedStr.replace( /-([a-zA-Z])/g, function( match, $1 ) { + return $1.toUpperCase(); + } ); + }; + + var shared_Ticker = function( warn, getTime, animations ) { + + // TODO what happens if a transition is aborted? + // TODO use this with Animation to dedupe some code? + var Ticker = function( options ) { + var easing; + this.duration = options.duration; + this.step = options.step; + this.complete = options.complete; + // easing + if ( typeof options.easing === 'string' ) { + easing = options.root.easing[ options.easing ]; + if ( !easing ) { + warn( 'Missing easing function ("' + options.easing + '"). You may need to download a plugin from [TODO]' ); + easing = linear; + } + } else if ( typeof options.easing === 'function' ) { + easing = options.easing; + } else { + easing = linear; + } + this.easing = easing; + this.start = getTime(); + this.end = this.start + this.duration; + this.running = true; + animations.add( this ); + }; + Ticker.prototype = { + tick: function( now ) { + var elapsed, eased; + if ( !this.running ) { + return false; + } + if ( now > this.end ) { + if ( this.step ) { + this.step( 1 ); + } + if ( this.complete ) { + this.complete( 1 ); + } + return false; + } + elapsed = now - this.start; + eased = this.easing( elapsed / this.duration ); + if ( this.step ) { + this.step( eased ); + } + return true; + }, + stop: function() { + if ( this.abort ) { + this.abort(); + } + this.running = false; + } + }; + return Ticker; + + function linear( t ) { + return t; + } + }( utils_warn, utils_getTime, shared_animations ); + + var render_DomFragment_Element_shared_executeTransition_Transition_helpers_unprefix = function( vendors ) { + + var unprefixPattern = new RegExp( '^-(?:' + vendors.join( '|' ) + ')-' ); + return function( prop ) { + return prop.replace( unprefixPattern, '' ); + }; + }( config_vendors ); + + var render_DomFragment_Element_shared_executeTransition_Transition_helpers_hyphenate = function( vendors ) { + + var vendorPattern = new RegExp( '^(?:' + vendors.join( '|' ) + ')([A-Z])' ); + return function( str ) { + var hyphenated; + if ( !str ) { + return ''; + } + if ( vendorPattern.test( str ) ) { + str = '-' + str; + } + hyphenated = str.replace( /[A-Z]/g, function( match ) { + return '-' + match.toLowerCase(); + } ); + return hyphenated; + }; + }( config_vendors ); + + var render_DomFragment_Element_shared_executeTransition_Transition_prototype_animateStyle_createTransitions = function( isClient, warn, createElement, camelCase, interpolate, Ticker, prefix, unprefix, hyphenate ) { + + var testStyle, TRANSITION, TRANSITIONEND, CSS_TRANSITIONS_ENABLED, TRANSITION_DURATION, TRANSITION_PROPERTY, TRANSITION_TIMING_FUNCTION, canUseCssTransitions = {}, cannotUseCssTransitions = {}; + if ( !isClient ) { + return; + } + testStyle = createElement( 'div' ).style; + // determine some facts about our environment + ( function() { + if ( testStyle.transition !== undefined ) { + TRANSITION = 'transition'; + TRANSITIONEND = 'transitionend'; + CSS_TRANSITIONS_ENABLED = true; + } else if ( testStyle.webkitTransition !== undefined ) { + TRANSITION = 'webkitTransition'; + TRANSITIONEND = 'webkitTransitionEnd'; + CSS_TRANSITIONS_ENABLED = true; + } else { + CSS_TRANSITIONS_ENABLED = false; + } + }() ); + if ( TRANSITION ) { + TRANSITION_DURATION = TRANSITION + 'Duration'; + TRANSITION_PROPERTY = TRANSITION + 'Property'; + TRANSITION_TIMING_FUNCTION = TRANSITION + 'TimingFunction'; + } + return function( t, to, options, changedProperties, transitionEndHandler, resolve ) { + // Wait a beat (otherwise the target styles will be applied immediately) + // TODO use a fastdom-style mechanism? + setTimeout( function() { + var hashPrefix, jsTransitionsComplete, cssTransitionsComplete, checkComplete; + checkComplete = function() { + if ( jsTransitionsComplete && cssTransitionsComplete ) { + resolve(); + } + }; + // this is used to keep track of which elements can use CSS to animate + // which properties + hashPrefix = t.node.namespaceURI + t.node.tagName; + t.node.style[ TRANSITION_PROPERTY ] = changedProperties.map( prefix ).map( hyphenate ).join( ',' ); + t.node.style[ TRANSITION_TIMING_FUNCTION ] = hyphenate( options.easing || 'linear' ); + t.node.style[ TRANSITION_DURATION ] = options.duration / 1000 + 's'; + transitionEndHandler = function( event ) { + var index; + index = changedProperties.indexOf( camelCase( unprefix( event.propertyName ) ) ); + if ( index !== -1 ) { + changedProperties.splice( index, 1 ); + } + if ( changedProperties.length ) { + // still transitioning... + return; + } + t.root.fire( t.name + ':end' ); + t.node.removeEventListener( TRANSITIONEND, transitionEndHandler, false ); + cssTransitionsComplete = true; + checkComplete(); + }; + t.node.addEventListener( TRANSITIONEND, transitionEndHandler, false ); + setTimeout( function() { + var i = changedProperties.length, + hash, originalValue, index, propertiesToTransitionInJs = [], + prop; + while ( i-- ) { + prop = changedProperties[ i ]; + hash = hashPrefix + prop; + if ( canUseCssTransitions[ hash ] ) { + // We can definitely use CSS transitions, because + // we've already tried it and it worked + t.node.style[ prefix( prop ) ] = to[ prop ]; + } else { + // one way or another, we'll need this + originalValue = t.getStyle( prop ); + } + if ( canUseCssTransitions[ hash ] === undefined ) { + // We're not yet sure if we can use CSS transitions - + // let's find out + t.node.style[ prefix( prop ) ] = to[ prop ]; + // if this property is transitionable in this browser, + // the current style will be different from the target style + canUseCssTransitions[ hash ] = t.getStyle( prop ) != to[ prop ]; + cannotUseCssTransitions[ hash ] = !canUseCssTransitions[ hash ]; + } + if ( cannotUseCssTransitions[ hash ] ) { + // we need to fall back to timer-based stuff + // need to remove this from changedProperties, otherwise transitionEndHandler + // will get confused + index = changedProperties.indexOf( prop ); + if ( index === -1 ) { + warn( 'Something very strange happened with transitions. If you see this message, please let @RactiveJS know. Thanks!' ); + } else { + changedProperties.splice( index, 1 ); + } + // TODO Determine whether this property is animatable at all + // for now assume it is. First, we need to set the value to what it was... + t.node.style[ prefix( prop ) ] = originalValue; + // ...then kick off a timer-based transition + propertiesToTransitionInJs.push( { + name: prefix( prop ), + interpolator: interpolate( originalValue, to[ prop ] ) + } ); + } + } + // javascript transitions + if ( propertiesToTransitionInJs.length ) { + new Ticker( { + root: t.root, + duration: options.duration, + easing: camelCase( options.easing ), + step: function( pos ) { + var prop, i; + i = propertiesToTransitionInJs.length; + while ( i-- ) { + prop = propertiesToTransitionInJs[ i ]; + t.node.style[ prop.name ] = prop.interpolator( pos ); + } + }, + complete: function() { + jsTransitionsComplete = true; + checkComplete(); + } + } ); + } else { + jsTransitionsComplete = true; + } + if ( !changedProperties.length ) { + // We need to cancel the transitionEndHandler, and deal with + // the fact that it will never fire + t.node.removeEventListener( TRANSITIONEND, transitionEndHandler, false ); + cssTransitionsComplete = true; + checkComplete(); + } + }, 0 ); + }, options.delay || 0 ); + }; + }( config_isClient, utils_warn, utils_createElement, utils_camelCase, shared_interpolate, shared_Ticker, render_DomFragment_Element_shared_executeTransition_Transition_helpers_prefix, render_DomFragment_Element_shared_executeTransition_Transition_helpers_unprefix, render_DomFragment_Element_shared_executeTransition_Transition_helpers_hyphenate ); + + var render_DomFragment_Element_shared_executeTransition_Transition_prototype_animateStyle__animateStyle = function( legacy, isClient, warn, Promise, prefix, createTransitions ) { + + var getComputedStyle; + if ( !isClient ) { + return; + } + getComputedStyle = window.getComputedStyle || legacy.getComputedStyle; + return function( style, value, options, complete ) { + var t = this, + to; + if ( typeof style === 'string' ) { + to = {}; + to[ style ] = value; + } else { + to = style; + // shuffle arguments + complete = options; + options = value; + } + // As of 0.3.9, transition authors should supply an `option` object with + // `duration` and `easing` properties (and optional `delay`), plus a + // callback function that gets called after the animation completes + // TODO remove this check in a future version + if ( !options ) { + warn( 'The "' + t.name + '" transition does not supply an options object to `t.animateStyle()`. This will break in a future version of Ractive. For more info see https://github.com/RactiveJS/Ractive/issues/340' ); + options = t; + complete = t.complete; + } + var promise = new Promise( function( resolve ) { + var propertyNames, changedProperties, computedStyle, current, from, transitionEndHandler, i, prop; + // Edge case - if duration is zero, set style synchronously and complete + if ( !options.duration ) { + t.setStyle( to ); + resolve(); + return; + } + // Get a list of the properties we're animating + propertyNames = Object.keys( to ); + changedProperties = []; + // Store the current styles + computedStyle = window.getComputedStyle( t.node ); + from = {}; + i = propertyNames.length; + while ( i-- ) { + prop = propertyNames[ i ]; + current = computedStyle[ prefix( prop ) ]; + if ( current === '0px' ) { + current = 0; + } + // we need to know if we're actually changing anything + if ( current != to[ prop ] ) { + // use != instead of !==, so we can compare strings with numbers + changedProperties.push( prop ); + // make the computed style explicit, so we can animate where + // e.g. height='auto' + t.node.style[ prefix( prop ) ] = current; + } + } + // If we're not actually changing anything, the transitionend event + // will never fire! So we complete early + if ( !changedProperties.length ) { + resolve(); + return; + } + createTransitions( t, to, options, changedProperties, transitionEndHandler, resolve ); + } ); + // If a callback was supplied, do the honours + // TODO remove this check in future + if ( complete ) { + warn( 't.animateStyle returns a Promise as of 0.4.0. Transition authors should do t.animateStyle(...).then(callback)' ); + promise.then( complete ); + } + return promise; + }; + }( legacy, config_isClient, utils_warn, utils_Promise, render_DomFragment_Element_shared_executeTransition_Transition_helpers_prefix, render_DomFragment_Element_shared_executeTransition_Transition_prototype_animateStyle_createTransitions ); + + var utils_fillGaps = function( target, source ) { + var key; + for ( key in source ) { + if ( source.hasOwnProperty( key ) && !( key in target ) ) { + target[ key ] = source[ key ]; + } + } + return target; + }; + + var render_DomFragment_Element_shared_executeTransition_Transition_prototype_processParams = function( fillGaps ) { + + return function( params, defaults ) { + if ( typeof params === 'number' ) { + params = { + duration: params + }; + } else if ( typeof params === 'string' ) { + if ( params === 'slow' ) { + params = { + duration: 600 + }; + } else if ( params === 'fast' ) { + params = { + duration: 200 + }; + } else { + params = { + duration: 400 + }; + } + } else if ( !params ) { + params = {}; + } + return fillGaps( params, defaults ); + }; + }( utils_fillGaps ); + + var render_DomFragment_Element_shared_executeTransition_Transition_prototype_resetStyle = function() { + if ( this.originalStyle ) { + this.node.setAttribute( 'style', this.originalStyle ); + } else { + // Next line is necessary, to remove empty style attribute! + // See http://stackoverflow.com/a/7167553 + this.node.getAttribute( 'style' ); + this.node.removeAttribute( 'style' ); + } + }; + + var render_DomFragment_Element_shared_executeTransition_Transition__Transition = function( warn, StringFragment, init, getStyle, setStyle, animateStyle, processParams, resetStyle ) { + + var Transition; + Transition = function( descriptor, root, owner, isIntro ) { + var t = this, + name, fragment, errorMessage; + this.root = root; + this.node = owner.node; + this.isIntro = isIntro; + // store original style attribute + this.originalStyle = this.node.getAttribute( 'style' ); + // create t.complete() - we don't want this on the prototype, + // because we don't want `this` silliness when passing it as + // an argument + t.complete = function( noReset ) { + if ( !noReset && t.isIntro ) { + t.resetStyle(); + } + t.node._ractive.transition = null; + t._manager.remove( t ); + }; + name = descriptor.n || descriptor; + if ( typeof name !== 'string' ) { + fragment = new StringFragment( { + descriptor: name, + root: this.root, + owner: owner + } ); + name = fragment.toString(); + fragment.teardown(); + } + this.name = name; + if ( descriptor.a ) { + this.params = descriptor.a; + } else if ( descriptor.d ) { + // TODO is there a way to interpret dynamic arguments without all the + // 'dependency thrashing'? + fragment = new StringFragment( { + descriptor: descriptor.d, + root: this.root, + owner: owner + } ); + this.params = fragment.toArgsList(); + fragment.teardown(); + } + this._fn = root.transitions[ name ]; + if ( !this._fn ) { + errorMessage = 'Missing "' + name + '" transition. You may need to download a plugin via http://docs.ractivejs.org/latest/plugins#transitions'; + if ( root.debug ) { + throw new Error( errorMessage ); + } else { + warn( errorMessage ); + } + return; + } + }; + Transition.prototype = { + init: init, + getStyle: getStyle, + setStyle: setStyle, + animateStyle: animateStyle, + processParams: processParams, + resetStyle: resetStyle + }; + return Transition; + }( utils_warn, render_StringFragment__StringFragment, render_DomFragment_Element_shared_executeTransition_Transition_prototype_init, render_DomFragment_Element_shared_executeTransition_Transition_prototype_getStyle, render_DomFragment_Element_shared_executeTransition_Transition_prototype_setStyle, render_DomFragment_Element_shared_executeTransition_Transition_prototype_animateStyle__animateStyle, render_DomFragment_Element_shared_executeTransition_Transition_prototype_processParams, render_DomFragment_Element_shared_executeTransition_Transition_prototype_resetStyle ); + + var render_DomFragment_Element_shared_executeTransition__executeTransition = function( runloop, Transition ) { + + return function( descriptor, ractive, owner, isIntro ) { + var transition, node, oldTransition; + // TODO this can't be right! + if ( !ractive.transitionsEnabled || ractive._parent && !ractive._parent.transitionsEnabled ) { + return; + } + // get transition name, args and function + transition = new Transition( descriptor, ractive, owner, isIntro ); + if ( transition._fn ) { + node = transition.node; + // Existing transition (i.e. we're outroing before intro is complete)? + // End it prematurely + if ( oldTransition = node._ractive.transition ) { + oldTransition.complete(); + } + node._ractive.transition = transition; + runloop.addTransition( transition ); + } + }; + }( global_runloop, render_DomFragment_Element_shared_executeTransition_Transition__Transition ); + + var render_DomFragment_Element_initialise__initialise = function( runloop, types, namespaces, create, defineProperty, warn, createElement, getInnerContext, getElementNamespace, createElementAttribute, createElementAttributes, appendElementChildren, decorate, addEventProxies, updateLiveQueries, executeTransition, enforceCase ) { + + return function initialiseElement( element, options, docFrag ) { + var parentFragment, pNode, descriptor, namespace, name, attributes, width, height, loadHandler, root, selectBinding, errorMessage; + element.type = types.ELEMENT; + // stuff we'll need later + parentFragment = element.parentFragment = options.parentFragment; + pNode = parentFragment.pNode; + descriptor = element.descriptor = options.descriptor; + element.parent = options.pElement; + element.root = root = parentFragment.root; + element.index = options.index; + element.lcName = descriptor.e.toLowerCase(); + element.eventListeners = []; + element.customEventListeners = []; + element.cssDetachQueue = []; + // get namespace, if we're actually rendering (not server-side stringifying) + if ( pNode ) { + namespace = element.namespace = getElementNamespace( descriptor, pNode ); + // non-HTML elements (i.e. SVG) are case-sensitive + name = namespace !== namespaces.html ? enforceCase( descriptor.e ) : descriptor.e; + // create the DOM node + element.node = createElement( name, namespace ); + // Is this a top-level node of a component? If so, we may need to add + // a data-rvcguid attribute, for CSS encapsulation + if ( root.css && pNode === root.el ) { + element.node.setAttribute( 'data-rvcguid', root.constructor._guid || root._guid ); + } + // Add _ractive property to the node - we use this object to store stuff + // related to proxy events, two-way bindings etc + defineProperty( element.node, '_ractive', { + value: { + proxy: element, + keypath: getInnerContext( parentFragment ), + index: parentFragment.indexRefs, + events: create( null ), + root: root + } + } ); + } + // set attributes + attributes = createElementAttributes( element, descriptor.a ); + // append children, if there are any + if ( descriptor.f ) { + // Special case - contenteditable + if ( element.node && element.node.getAttribute( 'contenteditable' ) ) { + if ( element.node.innerHTML ) { + // This is illegal. You can't have content inside a contenteditable + // element that's already populated + errorMessage = 'A pre-populated contenteditable element should not have children'; + if ( root.debug ) { + throw new Error( errorMessage ); + } else { + warn( errorMessage ); + } + } + } + appendElementChildren( element, element.node, descriptor, docFrag ); + } + // create event proxies + if ( docFrag && descriptor.v ) { + addEventProxies( element, descriptor.v ); + } + // if we're actually rendering (i.e. not server-side stringifying), proceed + if ( docFrag ) { + // deal with two-way bindings + if ( root.twoway ) { + element.bind(); + // Special case - contenteditable + if ( element.node.getAttribute( 'contenteditable' ) && element.node._ractive.binding ) { + // We need to update the model + element.node._ractive.binding.update(); + } + } + // name attributes are deferred, because they're a special case - if two-way + // binding is involved they need to update later. But if it turns out they're + // not two-way we can update them now + if ( attributes.name && !attributes.name.twoway ) { + attributes.name.update(); + } + // if this is an , and we're in a crap browser, we may need to prevent it + // from overriding width and height when it loads the src + if ( element.node.tagName === 'IMG' && ( ( width = element.attributes.width ) || ( height = element.attributes.height ) ) ) { + element.node.addEventListener( 'load', loadHandler = function() { + if ( width ) { + element.node.width = width.value; + } + if ( height ) { + element.node.height = height.value; + } + element.node.removeEventListener( 'load', loadHandler, false ); + }, false ); + } + docFrag.appendChild( element.node ); + // apply decorator(s) + if ( descriptor.o ) { + decorate( descriptor.o, root, element ); + } + // trigger intro transition + if ( descriptor.t1 ) { + executeTransition( descriptor.t1, root, element, true ); + } + if ( element.node.tagName === 'OPTION' ) { + // Special case... if this option's parent select was previously + // empty, it's possible that it should initialise to the value of + // this option. + if ( pNode.tagName === 'SELECT' && ( selectBinding = pNode._ractive.binding ) ) { + // it should be! + selectBinding.deferUpdate(); + } + // If a value attribute was not given, we need to create one based on + // the content of the node, so that `foo` behaves the + // same as `foo` with two-way binding + if ( !attributes.value ) { + createElementAttribute( element, 'value', descriptor.f ); + } + // Special case... a select may have had its value set before a matching + // option was rendered. This might be that option element + if ( element.node._ractive.value == pNode._ractive.value ) { + element.node.selected = true; + } + } + if ( element.node.autofocus ) { + // Special case. Some browsers (*cough* Firefix *cough*) have a problem + // with dynamically-generated elements having autofocus, and they won't + // allow you to programmatically focus the element until it's in the DOM + runloop.focus( element.node ); + } + } + // If this is an option element, we need to store a reference to its select + if ( element.lcName === 'option' ) { + element.select = findParentSelect( element.parent ); + } + updateLiveQueries( element ); + }; + + function findParentSelect( element ) { + do { + if ( element.lcName === 'select' ) { + return element; + } + } while ( element = element.parent ); + } + }( global_runloop, config_types, config_namespaces, utils_create, utils_defineProperty, utils_warn, utils_createElement, shared_getInnerContext, render_DomFragment_Element_initialise_getElementNamespace, render_DomFragment_Element_initialise_createElementAttribute, render_DomFragment_Element_initialise_createElementAttributes, render_DomFragment_Element_initialise_appendElementChildren, render_DomFragment_Element_initialise_decorate__decorate, render_DomFragment_Element_initialise_addEventProxies__addEventProxies, render_DomFragment_Element_initialise_updateLiveQueries, render_DomFragment_Element_shared_executeTransition__executeTransition, render_DomFragment_shared_enforceCase ); + + var render_DomFragment_Element_prototype_teardown = function( runloop, executeTransition ) { + + return function Element_prototype_teardown( destroy ) { + var eventName, binding, bindings; + // Detach as soon as we can + if ( destroy ) { + this.willDetach = true; + runloop.detachWhenReady( this ); + } + // Children first. that way, any transitions on child elements will be + // handled by the current transitionManager + if ( this.fragment ) { + this.fragment.teardown( false ); + } + while ( this.attributes.length ) { + this.attributes.pop().teardown(); + } + if ( this.node ) { + for ( eventName in this.node._ractive.events ) { + this.node._ractive.events[ eventName ].teardown(); + } + // tear down two-way binding, if such there be + if ( binding = this.node._ractive.binding ) { + binding.teardown(); + bindings = this.root._twowayBindings[ binding.attr.keypath ]; + bindings.splice( bindings.indexOf( binding ), 1 ); + } + } + if ( this.decorator ) { + this.decorator.teardown(); + } + // Outro, if necessary + if ( this.descriptor.t2 ) { + executeTransition( this.descriptor.t2, this.root, this, false ); + } + // Remove this node from any live queries + if ( this.liveQueries ) { + removeFromLiveQueries( this ); + } + }; + + function removeFromLiveQueries( element ) { + var query, selector, matchingStaticNodes, i, j; + i = element.liveQueries.length; + while ( i-- ) { + query = element.liveQueries[ i ]; + selector = query.selector; + query._remove( element.node ); + if ( element.matchingStaticNodes && ( matchingStaticNodes = element.matchingStaticNodes[ selector ] ) ) { + j = matchingStaticNodes.length; + while ( j-- ) { + query.remove( matchingStaticNodes[ j ] ); + } + } + } + } + }( global_runloop, render_DomFragment_Element_shared_executeTransition__executeTransition ); + + var render_DomFragment_Element_prototype_reassign = function( assignNewKeypath ) { + + return function reassignElement( indexRef, newIndex, oldKeypath, newKeypath ) { + var i, storage, masterEventName, proxies, proxy, binding, bindings, liveQueries, ractive; + i = this.attributes.length; + while ( i-- ) { + this.attributes[ i ].reassign( indexRef, newIndex, oldKeypath, newKeypath ); + } + if ( storage = this.node._ractive ) { + //adjust keypath if needed + assignNewKeypath( storage, 'keypath', oldKeypath, newKeypath ); + if ( indexRef != undefined ) { + storage.index[ indexRef ] = newIndex; + } + for ( masterEventName in storage.events ) { + proxies = storage.events[ masterEventName ].proxies; + i = proxies.length; + while ( i-- ) { + proxy = proxies[ i ]; + if ( typeof proxy.n === 'object' ) { + proxy.a.reassign( indexRef, newIndex, oldKeypath, newKeypath ); + } + if ( proxy.d ) { + proxy.d.reassign( indexRef, newIndex, oldKeypath, newKeypath ); + } + } + } + if ( binding = storage.binding ) { + if ( binding.keypath.substr( 0, oldKeypath.length ) === oldKeypath ) { + bindings = storage.root._twowayBindings[ binding.keypath ]; + // remove binding reference for old keypath + bindings.splice( bindings.indexOf( binding ), 1 ); + // update keypath + binding.keypath = binding.keypath.replace( oldKeypath, newKeypath ); + // add binding reference for new keypath + bindings = storage.root._twowayBindings[ binding.keypath ] || ( storage.root._twowayBindings[ binding.keypath ] = [] ); + bindings.push( binding ); + } + } + } + // reassign children + if ( this.fragment ) { + this.fragment.reassign( indexRef, newIndex, oldKeypath, newKeypath ); + } + // Update live queries, if necessary + if ( liveQueries = this.liveQueries ) { + ractive = this.root; + i = liveQueries.length; + while ( i-- ) { + liveQueries[ i ]._makeDirty(); + } + } + }; + }( render_shared_utils_assignNewKeypath ); + + var config_voidElementNames = 'area base br col command doctype embed hr img input keygen link meta param source track wbr'.split( ' ' ); + + var render_DomFragment_Element_prototype_toString = function( voidElementNames, isArray ) { + + return function() { + var str, i, len, attrStr; + str = '<' + ( this.descriptor.y ? '!doctype' : this.descriptor.e ); + len = this.attributes.length; + for ( i = 0; i < len; i += 1 ) { + if ( attrStr = this.attributes[ i ].toString() ) { + str += ' ' + attrStr; + } + } + // Special case - selected options + if ( this.lcName === 'option' && optionIsSelected( this ) ) { + str += ' selected'; + } + // Special case - two-way radio name bindings + if ( this.lcName === 'input' && inputIsCheckedRadio( this ) ) { + str += ' checked'; + } + str += '>'; + if ( this.html ) { + str += this.html; + } else if ( this.fragment ) { + str += this.fragment.toString(); + } + // add a closing tag if this isn't a void element + if ( voidElementNames.indexOf( this.descriptor.e ) === -1 ) { + str += '' + this.descriptor.e + '>'; + } + this.stringifying = false; + return str; + }; + + function optionIsSelected( element ) { + var optionValue, selectValueAttribute, selectValueInterpolator, selectValue, i; + optionValue = element.attributes.value.value; + selectValueAttribute = element.select.attributes.value; + selectValueInterpolator = selectValueAttribute.interpolator; + if ( !selectValueInterpolator ) { + return; + } + selectValue = element.root.get( selectValueInterpolator.keypath || selectValueInterpolator.ref ); + if ( selectValue == optionValue ) { + return true; + } + if ( element.select.attributes.multiple && isArray( selectValue ) ) { + i = selectValue.length; + while ( i-- ) { + if ( selectValue[ i ] == optionValue ) { + return true; + } + } + } + } + + function inputIsCheckedRadio( element ) { + var attributes, typeAttribute, valueAttribute, nameAttribute; + attributes = element.attributes; + typeAttribute = attributes.type; + valueAttribute = attributes.value; + nameAttribute = attributes.name; + if ( !typeAttribute || typeAttribute.value !== 'radio' || !valueAttribute || !nameAttribute.interpolator ) { + return; + } + if ( valueAttribute.value === nameAttribute.interpolator.value ) { + return true; + } + } + }( config_voidElementNames, utils_isArray ); + + var render_DomFragment_Element_prototype_find = function( matches ) { + + return function( selector ) { + var queryResult; + if ( matches( this.node, selector ) ) { + return this.node; + } + if ( this.html && ( queryResult = this.node.querySelector( selector ) ) ) { + return queryResult; + } + if ( this.fragment && this.fragment.find ) { + return this.fragment.find( selector ); + } + }; + }( utils_matches ); + + var render_DomFragment_Element_prototype_findAll = function( getMatchingStaticNodes ) { + + return function( selector, query ) { + var matchingStaticNodes, matchedSelf; + // Add this node to the query, if applicable, and register the + // query on this element + if ( query._test( this, true ) && query.live ) { + ( this.liveQueries || ( this.liveQueries = [] ) ).push( query ); + } + if ( this.html ) { + matchingStaticNodes = getMatchingStaticNodes( this, selector ); + query.push.apply( query, matchingStaticNodes ); + if ( query.live && !matchedSelf ) { + ( this.liveQueries || ( this.liveQueries = [] ) ).push( query ); + } + } + if ( this.fragment ) { + this.fragment.findAll( selector, query ); + } + }; + }( render_DomFragment_Element_shared_getMatchingStaticNodes ); + + var render_DomFragment_Element_prototype_findComponent = function( selector ) { + if ( this.fragment ) { + return this.fragment.findComponent( selector ); + } + }; + + var render_DomFragment_Element_prototype_findAllComponents = function( selector, query ) { + if ( this.fragment ) { + this.fragment.findAllComponents( selector, query ); + } + }; + + var render_DomFragment_Element_prototype_bind = function() { + var attributes = this.attributes; + if ( !this.node ) { + // we're not in a browser! + return; + } + // if this is a late binding, and there's already one, it + // needs to be torn down + if ( this.binding ) { + this.binding.teardown(); + this.binding = null; + } + // contenteditable + if ( this.node.getAttribute( 'contenteditable' ) && attributes.value && attributes.value.bind() ) { + return; + } + // an element can only have one two-way attribute + switch ( this.descriptor.e ) { + case 'select': + case 'textarea': + if ( attributes.value ) { + attributes.value.bind(); + } + return; + case 'input': + if ( this.node.type === 'radio' || this.node.type === 'checkbox' ) { + // we can either bind the name attribute, or the checked attribute - not both + if ( attributes.name && attributes.name.bind() ) { + return; + } + if ( attributes.checked && attributes.checked.bind() ) { + return; + } + } + if ( attributes.value && attributes.value.bind() ) { + return; + } + } + }; + + var render_DomFragment_Element__Element = function( runloop, css, initialise, teardown, reassign, toString, find, findAll, findComponent, findAllComponents, bind ) { + + var DomElement = function( options, docFrag ) { + initialise( this, options, docFrag ); + }; + DomElement.prototype = { + detach: function() { + var Component; + if ( this.node ) { + // need to check for parent node - DOM may have been altered + // by something other than Ractive! e.g. jQuery UI... + if ( this.node.parentNode ) { + this.node.parentNode.removeChild( this.node ); + } + return this.node; + } + // If this element has child components with their own CSS, that CSS needs to + // be removed now + // TODO optimise this + if ( this.cssDetachQueue.length ) { + runloop.start(); + while ( Component === this.cssDetachQueue.pop() ) { + css.remove( Component ); + } + runloop.end(); + } + }, + teardown: teardown, + reassign: reassign, + firstNode: function() { + return this.node; + }, + findNextNode: function() { + return null; + }, + // TODO can we get rid of this? + bubble: function() {}, + // just so event proxy and transition fragments have something to call! + toString: toString, + find: find, + findAll: findAll, + findComponent: findComponent, + findAllComponents: findAllComponents, + bind: bind + }; + return DomElement; + }( global_runloop, global_css, render_DomFragment_Element_initialise__initialise, render_DomFragment_Element_prototype_teardown, render_DomFragment_Element_prototype_reassign, render_DomFragment_Element_prototype_toString, render_DomFragment_Element_prototype_find, render_DomFragment_Element_prototype_findAll, render_DomFragment_Element_prototype_findComponent, render_DomFragment_Element_prototype_findAllComponents, render_DomFragment_Element_prototype_bind ); + + var config_errors = { + missingParser: 'Missing Ractive.parse - cannot parse template. Either preparse or use the version that includes the parser' + }; + + var registries_partials = {}; + + var parse_utils_stripHtmlComments = function( html ) { + var commentStart, commentEnd, processed; + processed = ''; + while ( html.length ) { + commentStart = html.indexOf( '' ); + // no comments? great + if ( commentStart === -1 && commentEnd === -1 ) { + processed += html; + break; + } + // comment start but no comment end + if ( commentStart !== -1 && commentEnd === -1 ) { + throw 'Illegal HTML - expected closing comment sequence (\'-->\')'; + } + // comment end but no comment start, or comment end before comment start + if ( commentEnd !== -1 && commentStart === -1 || commentEnd < commentStart ) { + throw 'Illegal HTML - unexpected closing comment sequence (\'-->\')'; + } + processed += html.substr( 0, commentStart ); + html = html.substring( commentEnd + 3 ); + } + return processed; + }; + + var parse_utils_stripStandalones = function( types ) { + + return function( tokens ) { + var i, current, backOne, backTwo, leadingLinebreak, trailingLinebreak; + leadingLinebreak = /^\s*\r?\n/; + trailingLinebreak = /\r?\n\s*$/; + for ( i = 2; i < tokens.length; i += 1 ) { + current = tokens[ i ]; + backOne = tokens[ i - 1 ]; + backTwo = tokens[ i - 2 ]; + // if we're at the end of a [text][mustache][text] sequence, where [mustache] isn't a partial... + if ( current.type === types.TEXT && ( backOne.type === types.MUSTACHE && backOne.mustacheType !== types.PARTIAL ) && backTwo.type === types.TEXT ) { + // ... and the mustache is a standalone (i.e. line breaks either side)... + if ( trailingLinebreak.test( backTwo.value ) && leadingLinebreak.test( current.value ) ) { + // ... then we want to remove the whitespace after the first line break + // if the mustache wasn't a triple or interpolator or partial + if ( backOne.mustacheType !== types.INTERPOLATOR && backOne.mustacheType !== types.TRIPLE ) { + backTwo.value = backTwo.value.replace( trailingLinebreak, '\n' ); + } + // and the leading line break of the second text token + current.value = current.value.replace( leadingLinebreak, '' ); + // if that means the current token is now empty, we should remove it + if ( current.value === '' ) { + tokens.splice( i--, 1 ); + } + } + } + } + return tokens; + }; + }( config_types ); + + var parse_utils_stripCommentTokens = function( types ) { + + return function( tokens ) { + var i, current, previous, next; + for ( i = 0; i < tokens.length; i += 1 ) { + current = tokens[ i ]; + previous = tokens[ i - 1 ]; + next = tokens[ i + 1 ]; + // if the current token is a comment or a delimiter change, remove it... + if ( current.mustacheType === types.COMMENT || current.mustacheType === types.DELIMCHANGE ) { + tokens.splice( i, 1 ); + // remove comment token + // ... and see if it has text nodes either side, in which case + // they can be concatenated + if ( previous && next ) { + if ( previous.type === types.TEXT && next.type === types.TEXT ) { + previous.value += next.value; + tokens.splice( i, 1 ); + } + } + i -= 1; + } + } + return tokens; + }; + }( config_types ); + + var parse_Tokenizer_getMustache_getDelimiterChange = function( makeRegexMatcher ) { + + var getDelimiter = makeRegexMatcher( /^[^\s=]+/ ); + return function( tokenizer ) { + var start, opening, closing; + if ( !tokenizer.getStringMatch( '=' ) ) { + return null; + } + start = tokenizer.pos; + // allow whitespace before new opening delimiter + tokenizer.allowWhitespace(); + opening = getDelimiter( tokenizer ); + if ( !opening ) { + tokenizer.pos = start; + return null; + } + // allow whitespace (in fact, it's necessary...) + tokenizer.allowWhitespace(); + closing = getDelimiter( tokenizer ); + if ( !closing ) { + tokenizer.pos = start; + return null; + } + // allow whitespace before closing '=' + tokenizer.allowWhitespace(); + if ( !tokenizer.getStringMatch( '=' ) ) { + tokenizer.pos = start; + return null; + } + return [ + opening, + closing + ]; + }; + }( parse_Tokenizer_utils_makeRegexMatcher ); + + var parse_Tokenizer_getMustache_getMustacheType = function( types ) { + + var mustacheTypes = { + '#': types.SECTION, + '^': types.INVERTED, + '/': types.CLOSING, + '>': types.PARTIAL, + '!': types.COMMENT, + '&': types.TRIPLE + }; + return function( tokenizer ) { + var type = mustacheTypes[ tokenizer.str.charAt( tokenizer.pos ) ]; + if ( !type ) { + return null; + } + tokenizer.pos += 1; + return type; + }; + }( config_types ); + + var parse_Tokenizer_getMustache_getMustacheContent = function( types, makeRegexMatcher, getMustacheType ) { + + var getIndexRef = makeRegexMatcher( /^\s*:\s*([a-zA-Z_$][a-zA-Z_$0-9]*)/ ), + arrayMember = /^[0-9][1-9]*$/; + return function( tokenizer, isTriple ) { + var start, mustache, type, expr, i, remaining, index, delimiter, keypathExpression; + start = tokenizer.pos; + mustache = { + type: isTriple ? types.TRIPLE : types.MUSTACHE + }; + // Determine mustache type + if ( !isTriple ) { + // We need to test for expressions before we test for mustache type, because + // an expression that begins '!' looks a lot like a comment + if ( expr = tokenizer.getExpression() ) { + mustache.mustacheType = types.INTERPOLATOR; + // Was it actually an expression, or a comment block in disguise? + tokenizer.allowWhitespace(); + if ( tokenizer.getStringMatch( tokenizer.delimiters[ 1 ] ) ) { + // expression + tokenizer.pos -= tokenizer.delimiters[ 1 ].length; + } else { + // comment block + tokenizer.pos = start; + expr = null; + } + } + if ( !expr ) { + type = getMustacheType( tokenizer ); + // Special case - ampersand mustaches + if ( type === types.TRIPLE ) { + mustache = { + type: types.TRIPLE + }; + } else { + mustache.mustacheType = type || types.INTERPOLATOR; + } + // if it's a comment or a section closer, allow any contents except '}}' + if ( type === types.COMMENT || type === types.CLOSING ) { + remaining = tokenizer.remaining(); + index = remaining.indexOf( tokenizer.delimiters[ 1 ] ); + if ( index !== -1 ) { + mustache.ref = remaining.substr( 0, index ); + tokenizer.pos += index; + return mustache; + } + } + } + } + if ( !expr ) { + // allow whitespace + tokenizer.allowWhitespace(); + // get expression + expr = tokenizer.getExpression(); + // With certain valid references that aren't valid expressions, + // e.g. {{1.foo}}, we have a problem: it looks like we've got an + // expression, but the expression didn't consume the entire + // reference. So we need to check that the mustache delimiters + // appear next, unless there's an index reference (i.e. a colon) + remaining = tokenizer.remaining(); + delimiter = isTriple ? tokenizer.tripleDelimiters[ 1 ] : tokenizer.delimiters[ 1 ]; + if ( remaining.substr( 0, delimiter.length ) !== delimiter && remaining.charAt( 0 ) !== ':' ) { + tokenizer.pos = start; + remaining = tokenizer.remaining(); + index = remaining.indexOf( tokenizer.delimiters[ 1 ] ); + if ( index !== -1 ) { + mustache.ref = remaining.substr( 0, index ).trim(); + tokenizer.pos += index; + return mustache; + } + } + } + while ( expr.t === types.BRACKETED && expr.x ) { + expr = expr.x; + } + // special case - integers should be treated as array members references, + // rather than as expressions in their own right + if ( expr.t === types.REFERENCE ) { + mustache.ref = expr.n; + } else if ( expr.t === types.NUMBER_LITERAL && arrayMember.test( expr.v ) ) { + mustache.ref = expr.v; + } else if ( keypathExpression = getKeypathExpression( expr ) ) { + mustache.keypathExpression = keypathExpression; + } else { + mustache.expression = expr; + } + // optional index reference + i = getIndexRef( tokenizer ); + if ( i !== null ) { + mustache.indexRef = i; + } + return mustache; + }; + + function getKeypathExpression( expr ) { + var members = []; + while ( expr.t === types.MEMBER && expr.r.t === types.REFINEMENT ) { + members.unshift( expr.r ); + expr = expr.x; + } + if ( expr.t !== types.REFERENCE ) { + return null; + } + return { + r: expr.n, + m: members + }; + } + }( config_types, parse_Tokenizer_utils_makeRegexMatcher, parse_Tokenizer_getMustache_getMustacheType ); + + var parse_Tokenizer_getMustache__getMustache = function( types, getDelimiterChange, getMustacheContent ) { + + return function() { + // if the triple delimiter (e.g. '{{{') is longer than the regular mustache + // delimiter (e.g. '{{') then we need to try and find a triple first. Otherwise + // we will get a false positive if the mustache delimiter is a substring of the + // triple delimiter, as in the default case + var seekTripleFirst = this.tripleDelimiters[ 0 ].length > this.delimiters[ 0 ].length; + return getMustache( this, seekTripleFirst ) || getMustache( this, !seekTripleFirst ); + }; + + function getMustache( tokenizer, seekTriple ) { + var start = tokenizer.pos, + content, delimiters; + delimiters = seekTriple ? tokenizer.tripleDelimiters : tokenizer.delimiters; + if ( !tokenizer.getStringMatch( delimiters[ 0 ] ) ) { + return null; + } + // delimiter change? + content = getDelimiterChange( tokenizer ); + if ( content ) { + // find closing delimiter or abort... + if ( !tokenizer.getStringMatch( delimiters[ 1 ] ) ) { + tokenizer.pos = start; + return null; + } + // ...then make the switch + tokenizer[ seekTriple ? 'tripleDelimiters' : 'delimiters' ] = content; + return { + type: types.MUSTACHE, + mustacheType: types.DELIMCHANGE + }; + } + tokenizer.allowWhitespace(); + content = getMustacheContent( tokenizer, seekTriple ); + if ( content === null ) { + tokenizer.pos = start; + return null; + } + // allow whitespace before closing delimiter + tokenizer.allowWhitespace(); + if ( !tokenizer.getStringMatch( delimiters[ 1 ] ) ) { + tokenizer.pos = start; + return null; + } + return content; + } + }( config_types, parse_Tokenizer_getMustache_getDelimiterChange, parse_Tokenizer_getMustache_getMustacheContent ); + + var parse_Tokenizer_getComment_getComment = function( types ) { + + return function() { + var content, remaining, endIndex; + if ( !this.getStringMatch( '' ); + if ( endIndex === -1 ) { + throw new Error( 'Unexpected end of input (expected "-->" to close comment)' ); + } + content = remaining.substr( 0, endIndex ); + this.pos += endIndex + 3; + return { + type: types.COMMENT, + content: content + }; + }; + }( config_types ); + + var parse_Tokenizer_utils_getLowestIndex = function( haystack, needles ) { + var i, index, lowest; + i = needles.length; + while ( i-- ) { + index = haystack.indexOf( needles[ i ] ); + // short circuit + if ( !index ) { + return 0; + } + if ( index === -1 ) { + continue; + } + if ( !lowest || index < lowest ) { + lowest = index; + } + } + return lowest || -1; + }; + + var parse_Tokenizer_getTag__getTag = function( types, makeRegexMatcher, getLowestIndex ) { + + var getTag, getOpeningTag, getClosingTag, getTagName, getAttributes, getAttribute, getAttributeName, getAttributeValue, getUnquotedAttributeValue, getUnquotedAttributeValueToken, getUnquotedAttributeValueText, getQuotedStringToken, getQuotedAttributeValue; + getTag = function() { + return getOpeningTag( this ) || getClosingTag( this ); + }; + getOpeningTag = function( tokenizer ) { + var start, tag, attrs, lowerCaseName; + start = tokenizer.pos; + if ( tokenizer.inside ) { + return null; + } + if ( !tokenizer.getStringMatch( '<' ) ) { + return null; + } + tag = { + type: types.TAG + }; + if ( tokenizer.getStringMatch( '!' ) ) { + tag.doctype = true; + } + // tag name + tag.name = getTagName( tokenizer ); + if ( !tag.name ) { + tokenizer.pos = start; + return null; + } + // attributes + attrs = getAttributes( tokenizer ); + if ( attrs ) { + tag.attrs = attrs; + } + // allow whitespace before closing solidus + tokenizer.allowWhitespace(); + // self-closing solidus? + if ( tokenizer.getStringMatch( '/' ) ) { + tag.selfClosing = true; + } + // closing angle bracket + if ( !tokenizer.getStringMatch( '>' ) ) { + tokenizer.pos = start; + return null; + } + // Special case - if we open a script tag, further tags should + // be ignored unless they're a closing script tag + lowerCaseName = tag.name.toLowerCase(); + if ( lowerCaseName === 'script' || lowerCaseName === 'style' ) { + tokenizer.inside = lowerCaseName; + } + return tag; + }; + getClosingTag = function( tokenizer ) { + var start, tag, expected; + start = tokenizer.pos; + expected = function( str ) { + throw new Error( 'Unexpected character ' + tokenizer.remaining().charAt( 0 ) + ' (expected ' + str + ')' ); + }; + if ( !tokenizer.getStringMatch( '<' ) ) { + return null; + } + tag = { + type: types.TAG, + closing: true + }; + // closing solidus + if ( !tokenizer.getStringMatch( '/' ) ) { + expected( '"/"' ); + } + // tag name + tag.name = getTagName( tokenizer ); + if ( !tag.name ) { + expected( 'tag name' ); + } + // closing angle bracket + if ( !tokenizer.getStringMatch( '>' ) ) { + expected( '">"' ); + } + if ( tokenizer.inside ) { + if ( tag.name.toLowerCase() !== tokenizer.inside ) { + tokenizer.pos = start; + return null; + } + tokenizer.inside = null; + } + return tag; + }; + getTagName = makeRegexMatcher( /^[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/ ); + getAttributes = function( tokenizer ) { + var start, attrs, attr; + start = tokenizer.pos; + // if the next character isn't whitespace, there are no attributes... + if ( !tokenizer.getStringMatch( ' ' ) && !tokenizer.getStringMatch( '\n' ) ) { + return null; + } + // ...but allow arbitrary amounts of whitespace + tokenizer.allowWhitespace(); + attr = getAttribute( tokenizer ); + if ( !attr ) { + tokenizer.pos = start; + return null; + } + attrs = []; + while ( attr !== null ) { + attrs.push( attr ); + tokenizer.allowWhitespace(); + attr = getAttribute( tokenizer ); + } + return attrs; + }; + getAttribute = function( tokenizer ) { + var attr, name, value; + name = getAttributeName( tokenizer ); + if ( !name ) { + return null; + } + attr = { + name: name + }; + value = getAttributeValue( tokenizer ); + if ( value ) { + attr.value = value; + } + return attr; + }; + getAttributeName = makeRegexMatcher( /^[^\s"'>\/=]+/ ); + getAttributeValue = function( tokenizer ) { + var start, value; + start = tokenizer.pos; + tokenizer.allowWhitespace(); + if ( !tokenizer.getStringMatch( '=' ) ) { + tokenizer.pos = start; + return null; + } + tokenizer.allowWhitespace(); + value = getQuotedAttributeValue( tokenizer, '\'' ) || getQuotedAttributeValue( tokenizer, '"' ) || getUnquotedAttributeValue( tokenizer ); + if ( value === null ) { + tokenizer.pos = start; + return null; + } + return value; + }; + getUnquotedAttributeValueText = makeRegexMatcher( /^[^\s"'=<>`]+/ ); + getUnquotedAttributeValueToken = function( tokenizer ) { + var start, text, index; + start = tokenizer.pos; + text = getUnquotedAttributeValueText( tokenizer ); + if ( !text ) { + return null; + } + if ( ( index = text.indexOf( tokenizer.delimiters[ 0 ] ) ) !== -1 ) { + text = text.substr( 0, index ); + tokenizer.pos = start + text.length; + } + return { + type: types.TEXT, + value: text + }; + }; + getUnquotedAttributeValue = function( tokenizer ) { + var tokens, token; + tokens = []; + token = tokenizer.getMustache() || getUnquotedAttributeValueToken( tokenizer ); + while ( token !== null ) { + tokens.push( token ); + token = tokenizer.getMustache() || getUnquotedAttributeValueToken( tokenizer ); + } + if ( !tokens.length ) { + return null; + } + return tokens; + }; + getQuotedAttributeValue = function( tokenizer, quoteMark ) { + var start, tokens, token; + start = tokenizer.pos; + if ( !tokenizer.getStringMatch( quoteMark ) ) { + return null; + } + tokens = []; + token = tokenizer.getMustache() || getQuotedStringToken( tokenizer, quoteMark ); + while ( token !== null ) { + tokens.push( token ); + token = tokenizer.getMustache() || getQuotedStringToken( tokenizer, quoteMark ); + } + if ( !tokenizer.getStringMatch( quoteMark ) ) { + tokenizer.pos = start; + return null; + } + return tokens; + }; + getQuotedStringToken = function( tokenizer, quoteMark ) { + var start, index, remaining; + start = tokenizer.pos; + remaining = tokenizer.remaining(); + index = getLowestIndex( remaining, [ + quoteMark, + tokenizer.delimiters[ 0 ], + tokenizer.delimiters[ 1 ] + ] ); + if ( index === -1 ) { + throw new Error( 'Quoted attribute value must have a closing quote' ); + } + if ( !index ) { + return null; + } + tokenizer.pos += index; + return { + type: types.TEXT, + value: remaining.substr( 0, index ) + }; + }; + return getTag; + }( config_types, parse_Tokenizer_utils_makeRegexMatcher, parse_Tokenizer_utils_getLowestIndex ); + + var parse_Tokenizer_getText__getText = function( types, getLowestIndex ) { + + return function() { + var index, remaining, barrier; + remaining = this.remaining(); + barrier = this.inside ? '' + this.inside : '<'; + if ( this.inside && !this.interpolate[ this.inside ] ) { + index = remaining.indexOf( barrier ); + } else { + index = getLowestIndex( remaining, [ + barrier, + this.delimiters[ 0 ], + this.tripleDelimiters[ 0 ] + ] ); + } + if ( !index ) { + return null; + } + if ( index === -1 ) { + index = remaining.length; + } + this.pos += index; + return { + type: types.TEXT, + value: remaining.substr( 0, index ) + }; + }; + }( config_types, parse_Tokenizer_utils_getLowestIndex ); + + var parse_Tokenizer_getExpression_getPrimary_getLiteral_getBooleanLiteral = function( types ) { + + return function( tokenizer ) { + var remaining = tokenizer.remaining(); + if ( remaining.substr( 0, 4 ) === 'true' ) { + tokenizer.pos += 4; + return { + t: types.BOOLEAN_LITERAL, + v: 'true' + }; + } + if ( remaining.substr( 0, 5 ) === 'false' ) { + tokenizer.pos += 5; + return { + t: types.BOOLEAN_LITERAL, + v: 'false' + }; + } + return null; + }; + }( config_types ); + + var parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral_getKeyValuePair = function( types, getKey ) { + + return function( tokenizer ) { + var start, key, value; + start = tokenizer.pos; + // allow whitespace between '{' and key + tokenizer.allowWhitespace(); + key = getKey( tokenizer ); + if ( key === null ) { + tokenizer.pos = start; + return null; + } + // allow whitespace between key and ':' + tokenizer.allowWhitespace(); + // next character must be ':' + if ( !tokenizer.getStringMatch( ':' ) ) { + tokenizer.pos = start; + return null; + } + // allow whitespace between ':' and value + tokenizer.allowWhitespace(); + // next expression must be a, well... expression + value = tokenizer.getExpression(); + if ( value === null ) { + tokenizer.pos = start; + return null; + } + return { + t: types.KEY_VALUE_PAIR, + k: key, + v: value + }; + }; + }( config_types, parse_Tokenizer_getExpression_shared_getKey ); + + var parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral_getKeyValuePairs = function( getKeyValuePair ) { + + return function getKeyValuePairs( tokenizer ) { + var start, pairs, pair, keyValuePairs; + start = tokenizer.pos; + pair = getKeyValuePair( tokenizer ); + if ( pair === null ) { + return null; + } + pairs = [ pair ]; + if ( tokenizer.getStringMatch( ',' ) ) { + keyValuePairs = getKeyValuePairs( tokenizer ); + if ( !keyValuePairs ) { + tokenizer.pos = start; + return null; + } + return pairs.concat( keyValuePairs ); + } + return pairs; + }; + }( parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral_getKeyValuePair ); + + var parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral__getObjectLiteral = function( types, getKeyValuePairs ) { + + return function( tokenizer ) { + var start, keyValuePairs; + start = tokenizer.pos; + // allow whitespace + tokenizer.allowWhitespace(); + if ( !tokenizer.getStringMatch( '{' ) ) { + tokenizer.pos = start; + return null; + } + keyValuePairs = getKeyValuePairs( tokenizer ); + // allow whitespace between final value and '}' + tokenizer.allowWhitespace(); + if ( !tokenizer.getStringMatch( '}' ) ) { + tokenizer.pos = start; + return null; + } + return { + t: types.OBJECT_LITERAL, + m: keyValuePairs + }; + }; + }( config_types, parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral_getKeyValuePairs ); + + var parse_Tokenizer_getExpression_shared_getExpressionList = function getExpressionList( tokenizer ) { + var start, expressions, expr, next; + start = tokenizer.pos; + tokenizer.allowWhitespace(); + expr = tokenizer.getExpression(); + if ( expr === null ) { + return null; + } + expressions = [ expr ]; + // allow whitespace between expression and ',' + tokenizer.allowWhitespace(); + if ( tokenizer.getStringMatch( ',' ) ) { + next = getExpressionList( tokenizer ); + if ( next === null ) { + tokenizer.pos = start; + return null; + } + expressions = expressions.concat( next ); + } + return expressions; + }; + + var parse_Tokenizer_getExpression_getPrimary_getLiteral_getArrayLiteral = function( types, getExpressionList ) { + + return function( tokenizer ) { + var start, expressionList; + start = tokenizer.pos; + // allow whitespace before '[' + tokenizer.allowWhitespace(); + if ( !tokenizer.getStringMatch( '[' ) ) { + tokenizer.pos = start; + return null; + } + expressionList = getExpressionList( tokenizer ); + if ( !tokenizer.getStringMatch( ']' ) ) { + tokenizer.pos = start; + return null; + } + return { + t: types.ARRAY_LITERAL, + m: expressionList + }; + }; + }( config_types, parse_Tokenizer_getExpression_shared_getExpressionList ); + + var parse_Tokenizer_getExpression_getPrimary_getLiteral__getLiteral = function( getNumberLiteral, getBooleanLiteral, getStringLiteral, getObjectLiteral, getArrayLiteral ) { + + return function( tokenizer ) { + var literal = getNumberLiteral( tokenizer ) || getBooleanLiteral( tokenizer ) || getStringLiteral( tokenizer ) || getObjectLiteral( tokenizer ) || getArrayLiteral( tokenizer ); + return literal; + }; + }( parse_Tokenizer_getExpression_getPrimary_getLiteral_getNumberLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getBooleanLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getStringLiteral__getStringLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getObjectLiteral__getObjectLiteral, parse_Tokenizer_getExpression_getPrimary_getLiteral_getArrayLiteral ); + + var parse_Tokenizer_getExpression_getPrimary_getReference = function( types, makeRegexMatcher, getName ) { + + var getDotRefinement, getArrayRefinement, getArrayMember, globals; + getDotRefinement = makeRegexMatcher( /^\.[a-zA-Z_$0-9]+/ ); + getArrayRefinement = function( tokenizer ) { + var num = getArrayMember( tokenizer ); + if ( num ) { + return '.' + num; + } + return null; + }; + getArrayMember = makeRegexMatcher( /^\[(0|[1-9][0-9]*)\]/ ); + // if a reference is a browser global, we don't deference it later, so it needs special treatment + globals = /^(?:Array|Date|RegExp|decodeURIComponent|decodeURI|encodeURIComponent|encodeURI|isFinite|isNaN|parseFloat|parseInt|JSON|Math|NaN|undefined|null)$/; + return function( tokenizer ) { + var startPos, ancestor, name, dot, combo, refinement, lastDotIndex; + startPos = tokenizer.pos; + // we might have ancestor refs... + ancestor = ''; + while ( tokenizer.getStringMatch( '../' ) ) { + ancestor += '../'; + } + if ( !ancestor ) { + // we might have an implicit iterator or a restricted reference + dot = tokenizer.getStringMatch( '.' ) || ''; + } + name = getName( tokenizer ) || ''; + // if this is a browser global, stop here + if ( !ancestor && !dot && globals.test( name ) ) { + return { + t: types.GLOBAL, + v: name + }; + } + // allow the use of `this` + if ( name === 'this' && !ancestor && !dot ) { + name = '.'; + startPos += 3; + } + combo = ( ancestor || dot ) + name; + if ( !combo ) { + return null; + } + while ( refinement = getDotRefinement( tokenizer ) || getArrayRefinement( tokenizer ) ) { + combo += refinement; + } + if ( tokenizer.getStringMatch( '(' ) ) { + // if this is a method invocation (as opposed to a function) we need + // to strip the method name from the reference combo, else the context + // will be wrong + lastDotIndex = combo.lastIndexOf( '.' ); + if ( lastDotIndex !== -1 ) { + combo = combo.substr( 0, lastDotIndex ); + tokenizer.pos = startPos + combo.length; + } else { + tokenizer.pos -= 1; + } + } + return { + t: types.REFERENCE, + n: combo + }; + }; + }( config_types, parse_Tokenizer_utils_makeRegexMatcher, parse_Tokenizer_getExpression_shared_getName ); + + var parse_Tokenizer_getExpression_getPrimary_getBracketedExpression = function( types ) { + + return function( tokenizer ) { + var start, expr; + start = tokenizer.pos; + if ( !tokenizer.getStringMatch( '(' ) ) { + return null; + } + tokenizer.allowWhitespace(); + expr = tokenizer.getExpression(); + if ( !expr ) { + tokenizer.pos = start; + return null; + } + tokenizer.allowWhitespace(); + if ( !tokenizer.getStringMatch( ')' ) ) { + tokenizer.pos = start; + return null; + } + return { + t: types.BRACKETED, + x: expr + }; + }; + }( config_types ); + + var parse_Tokenizer_getExpression_getPrimary__getPrimary = function( getLiteral, getReference, getBracketedExpression ) { + + return function( tokenizer ) { + return getLiteral( tokenizer ) || getReference( tokenizer ) || getBracketedExpression( tokenizer ); + }; + }( parse_Tokenizer_getExpression_getPrimary_getLiteral__getLiteral, parse_Tokenizer_getExpression_getPrimary_getReference, parse_Tokenizer_getExpression_getPrimary_getBracketedExpression ); + + var parse_Tokenizer_getExpression_shared_getRefinement = function( types, getName ) { + + return function getRefinement( tokenizer ) { + var start, name, expr; + start = tokenizer.pos; + tokenizer.allowWhitespace(); + // "." name + if ( tokenizer.getStringMatch( '.' ) ) { + tokenizer.allowWhitespace(); + if ( name = getName( tokenizer ) ) { + return { + t: types.REFINEMENT, + n: name + }; + } + tokenizer.expected( 'a property name' ); + } + // "[" expression "]" + if ( tokenizer.getStringMatch( '[' ) ) { + tokenizer.allowWhitespace(); + expr = tokenizer.getExpression(); + if ( !expr ) { + tokenizer.expected( 'an expression' ); + } + tokenizer.allowWhitespace(); + if ( !tokenizer.getStringMatch( ']' ) ) { + tokenizer.expected( '"]"' ); + } + return { + t: types.REFINEMENT, + x: expr + }; + } + return null; + }; + }( config_types, parse_Tokenizer_getExpression_shared_getName ); + + var parse_Tokenizer_getExpression_getMemberOrInvocation = function( types, getPrimary, getExpressionList, getRefinement ) { + + return function( tokenizer ) { + var current, expression, refinement, expressionList; + expression = getPrimary( tokenizer ); + if ( !expression ) { + return null; + } + while ( expression ) { + current = tokenizer.pos; + if ( refinement = getRefinement( tokenizer ) ) { + expression = { + t: types.MEMBER, + x: expression, + r: refinement + }; + } else if ( tokenizer.getStringMatch( '(' ) ) { + tokenizer.allowWhitespace(); + expressionList = getExpressionList( tokenizer ); + tokenizer.allowWhitespace(); + if ( !tokenizer.getStringMatch( ')' ) ) { + tokenizer.pos = current; + break; + } + expression = { + t: types.INVOCATION, + x: expression + }; + if ( expressionList ) { + expression.o = expressionList; + } + } else { + break; + } + } + return expression; + }; + }( config_types, parse_Tokenizer_getExpression_getPrimary__getPrimary, parse_Tokenizer_getExpression_shared_getExpressionList, parse_Tokenizer_getExpression_shared_getRefinement ); + + var parse_Tokenizer_getExpression_getTypeOf = function( types, getMemberOrInvocation ) { + + var getTypeOf, makePrefixSequenceMatcher; + makePrefixSequenceMatcher = function( symbol, fallthrough ) { + return function( tokenizer ) { + var start, expression; + if ( !tokenizer.getStringMatch( symbol ) ) { + return fallthrough( tokenizer ); + } + start = tokenizer.pos; + tokenizer.allowWhitespace(); + expression = tokenizer.getExpression(); + if ( !expression ) { + tokenizer.expected( 'an expression' ); + } + return { + s: symbol, + o: expression, + t: types.PREFIX_OPERATOR + }; + }; + }; + // create all prefix sequence matchers, return getTypeOf + ( function() { + var i, len, matcher, prefixOperators, fallthrough; + prefixOperators = '! ~ + - typeof'.split( ' ' ); + fallthrough = getMemberOrInvocation; + for ( i = 0, len = prefixOperators.length; i < len; i += 1 ) { + matcher = makePrefixSequenceMatcher( prefixOperators[ i ], fallthrough ); + fallthrough = matcher; + } + // typeof operator is higher precedence than multiplication, so provides the + // fallthrough for the multiplication sequence matcher we're about to create + // (we're skipping void and delete) + getTypeOf = fallthrough; + }() ); + return getTypeOf; + }( config_types, parse_Tokenizer_getExpression_getMemberOrInvocation ); + + var parse_Tokenizer_getExpression_getLogicalOr = function( types, getTypeOf ) { + + var getLogicalOr, makeInfixSequenceMatcher; + makeInfixSequenceMatcher = function( symbol, fallthrough ) { + return function( tokenizer ) { + var start, left, right; + left = fallthrough( tokenizer ); + if ( !left ) { + return null; + } + // Loop to handle left-recursion in a case like `a * b * c` and produce + // left association, i.e. `(a * b) * c`. The matcher can't call itself + // to parse `left` because that would be infinite regress. + while ( true ) { + start = tokenizer.pos; + tokenizer.allowWhitespace(); + if ( !tokenizer.getStringMatch( symbol ) ) { + tokenizer.pos = start; + return left; + } + // special case - in operator must not be followed by [a-zA-Z_$0-9] + if ( symbol === 'in' && /[a-zA-Z_$0-9]/.test( tokenizer.remaining().charAt( 0 ) ) ) { + tokenizer.pos = start; + return left; + } + tokenizer.allowWhitespace(); + // right operand must also consist of only higher-precedence operators + right = fallthrough( tokenizer ); + if ( !right ) { + tokenizer.pos = start; + return left; + } + left = { + t: types.INFIX_OPERATOR, + s: symbol, + o: [ + left, + right + ] + }; + } + }; + }; + // create all infix sequence matchers, and return getLogicalOr + ( function() { + var i, len, matcher, infixOperators, fallthrough; + // All the infix operators on order of precedence (source: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Operator_Precedence) + // Each sequence matcher will initially fall through to its higher precedence + // neighbour, and only attempt to match if one of the higher precedence operators + // (or, ultimately, a literal, reference, or bracketed expression) already matched + infixOperators = '* / % + - << >> >>> < <= > >= in instanceof == != === !== & ^ | && ||'.split( ' ' ); + // A typeof operator is higher precedence than multiplication + fallthrough = getTypeOf; + for ( i = 0, len = infixOperators.length; i < len; i += 1 ) { + matcher = makeInfixSequenceMatcher( infixOperators[ i ], fallthrough ); + fallthrough = matcher; + } + // Logical OR is the fallthrough for the conditional matcher + getLogicalOr = fallthrough; + }() ); + return getLogicalOr; + }( config_types, parse_Tokenizer_getExpression_getTypeOf ); + + var parse_Tokenizer_getExpression_getConditional = function( types, getLogicalOr ) { + + // The conditional operator is the lowest precedence operator, so we start here + return function( tokenizer ) { + var start, expression, ifTrue, ifFalse; + expression = getLogicalOr( tokenizer ); + if ( !expression ) { + return null; + } + start = tokenizer.pos; + tokenizer.allowWhitespace(); + if ( !tokenizer.getStringMatch( '?' ) ) { + tokenizer.pos = start; + return expression; + } + tokenizer.allowWhitespace(); + ifTrue = tokenizer.getExpression(); + if ( !ifTrue ) { + tokenizer.pos = start; + return expression; + } + tokenizer.allowWhitespace(); + if ( !tokenizer.getStringMatch( ':' ) ) { + tokenizer.pos = start; + return expression; + } + tokenizer.allowWhitespace(); + ifFalse = tokenizer.getExpression(); + if ( !ifFalse ) { + tokenizer.pos = start; + return expression; + } + return { + t: types.CONDITIONAL, + o: [ + expression, + ifTrue, + ifFalse + ] + }; + }; + }( config_types, parse_Tokenizer_getExpression_getLogicalOr ); + + var parse_Tokenizer_getExpression__getExpression = function( getConditional ) { + + // The conditional operator is the lowest precedence operator (except yield, + // assignment operators, and commas, none of which are supported), so we + // start there. If it doesn't match, it 'falls through' to progressively + // higher precedence operators, until it eventually matches (or fails to + // match) a 'primary' - a literal or a reference. This way, the abstract syntax + // tree has everything in its proper place, i.e. 2 + 3 * 4 === 14, not 20. + return function() { + return getConditional( this ); + }; + }( parse_Tokenizer_getExpression_getConditional ); + + var parse_Tokenizer__Tokenizer = function( getMustache, getComment, getTag, getText, getExpression, allowWhitespace, getStringMatch ) { + + var Tokenizer; + Tokenizer = function( str, options ) { + var token; + this.str = str; + this.pos = 0; + this.delimiters = options.delimiters; + this.tripleDelimiters = options.tripleDelimiters; + this.interpolate = options.interpolate; + this.tokens = []; + while ( this.pos < this.str.length ) { + token = this.getToken(); + if ( token === null && this.remaining() ) { + this.fail(); + } + this.tokens.push( token ); + } + }; + Tokenizer.prototype = { + getToken: function() { + var token = this.getMustache() || this.getComment() || this.getTag() || this.getText(); + return token; + }, + getMustache: getMustache, + getComment: getComment, + getTag: getTag, + getText: getText, + getExpression: getExpression, + // utils + allowWhitespace: allowWhitespace, + getStringMatch: getStringMatch, + remaining: function() { + return this.str.substring( this.pos ); + }, + fail: function() { + var last20, next20; + last20 = this.str.substr( 0, this.pos ).substr( -20 ); + if ( last20.length === 20 ) { + last20 = '...' + last20; + } + next20 = this.remaining().substr( 0, 20 ); + if ( next20.length === 20 ) { + next20 = next20 + '...'; + } + throw new Error( 'Could not parse template: ' + ( last20 ? last20 + '<- ' : '' ) + 'failed at character ' + this.pos + ' ->' + next20 ); + }, + expected: function( thing ) { + var remaining = this.remaining().substr( 0, 40 ); + if ( remaining.length === 40 ) { + remaining += '...'; + } + throw new Error( 'Tokenizer failed: unexpected string "' + remaining + '" (expected ' + thing + ')' ); + } + }; + return Tokenizer; + }( parse_Tokenizer_getMustache__getMustache, parse_Tokenizer_getComment_getComment, parse_Tokenizer_getTag__getTag, parse_Tokenizer_getText__getText, parse_Tokenizer_getExpression__getExpression, parse_Tokenizer_utils_allowWhitespace, parse_Tokenizer_utils_getStringMatch ); + + var parse_tokenize = function( initOptions, stripHtmlComments, stripStandalones, stripCommentTokens, Tokenizer ) { + + return function( template, options ) { + var tokenizer, tokens; + options = options || {}; + if ( options.stripComments !== false ) { + template = stripHtmlComments( template ); + } + // TODO handle delimiters differently + tokenizer = new Tokenizer( template, { + delimiters: options.delimiters || initOptions.defaults.delimiters, + tripleDelimiters: options.tripleDelimiters || initOptions.defaults.tripleDelimiters, + interpolate: { + script: options.interpolateScripts !== false ? true : false, + style: options.interpolateStyles !== false ? true : false + } + } ); + // TODO and this... + tokens = tokenizer.tokens; + stripStandalones( tokens ); + stripCommentTokens( tokens ); + return tokens; + }; + }( config_initOptions, parse_utils_stripHtmlComments, parse_utils_stripStandalones, parse_utils_stripCommentTokens, parse_Tokenizer__Tokenizer ); + + var parse_Parser_getText_TextStub__TextStub = function( types ) { + + var TextStub, + // helpers + htmlEntities, controlCharacters, namedEntityPattern, hexEntityPattern, decimalEntityPattern, validateCode, decodeCharacterReferences, whitespace; + TextStub = function( token, preserveWhitespace ) { + this.text = preserveWhitespace ? token.value : token.value.replace( whitespace, ' ' ); + }; + TextStub.prototype = { + type: types.TEXT, + toJSON: function() { + // this will be used within HTML, so we need to decode things like & + return this.decoded || ( this.decoded = decodeCharacterReferences( this.text ) ); + }, + toString: function() { + // this will be used as straight text + return this.text; + } + }; + htmlEntities = { + quot: 34, + amp: 38, + apos: 39, + lt: 60, + gt: 62, + nbsp: 160, + iexcl: 161, + cent: 162, + pound: 163, + curren: 164, + yen: 165, + brvbar: 166, + sect: 167, + uml: 168, + copy: 169, + ordf: 170, + laquo: 171, + not: 172, + shy: 173, + reg: 174, + macr: 175, + deg: 176, + plusmn: 177, + sup2: 178, + sup3: 179, + acute: 180, + micro: 181, + para: 182, + middot: 183, + cedil: 184, + sup1: 185, + ordm: 186, + raquo: 187, + frac14: 188, + frac12: 189, + frac34: 190, + iquest: 191, + Agrave: 192, + Aacute: 193, + Acirc: 194, + Atilde: 195, + Auml: 196, + Aring: 197, + AElig: 198, + Ccedil: 199, + Egrave: 200, + Eacute: 201, + Ecirc: 202, + Euml: 203, + Igrave: 204, + Iacute: 205, + Icirc: 206, + Iuml: 207, + ETH: 208, + Ntilde: 209, + Ograve: 210, + Oacute: 211, + Ocirc: 212, + Otilde: 213, + Ouml: 214, + times: 215, + Oslash: 216, + Ugrave: 217, + Uacute: 218, + Ucirc: 219, + Uuml: 220, + Yacute: 221, + THORN: 222, + szlig: 223, + agrave: 224, + aacute: 225, + acirc: 226, + atilde: 227, + auml: 228, + aring: 229, + aelig: 230, + ccedil: 231, + egrave: 232, + eacute: 233, + ecirc: 234, + euml: 235, + igrave: 236, + iacute: 237, + icirc: 238, + iuml: 239, + eth: 240, + ntilde: 241, + ograve: 242, + oacute: 243, + ocirc: 244, + otilde: 245, + ouml: 246, + divide: 247, + oslash: 248, + ugrave: 249, + uacute: 250, + ucirc: 251, + uuml: 252, + yacute: 253, + thorn: 254, + yuml: 255, + OElig: 338, + oelig: 339, + Scaron: 352, + scaron: 353, + Yuml: 376, + fnof: 402, + circ: 710, + tilde: 732, + Alpha: 913, + Beta: 914, + Gamma: 915, + Delta: 916, + Epsilon: 917, + Zeta: 918, + Eta: 919, + Theta: 920, + Iota: 921, + Kappa: 922, + Lambda: 923, + Mu: 924, + Nu: 925, + Xi: 926, + Omicron: 927, + Pi: 928, + Rho: 929, + Sigma: 931, + Tau: 932, + Upsilon: 933, + Phi: 934, + Chi: 935, + Psi: 936, + Omega: 937, + alpha: 945, + beta: 946, + gamma: 947, + delta: 948, + epsilon: 949, + zeta: 950, + eta: 951, + theta: 952, + iota: 953, + kappa: 954, + lambda: 955, + mu: 956, + nu: 957, + xi: 958, + omicron: 959, + pi: 960, + rho: 961, + sigmaf: 962, + sigma: 963, + tau: 964, + upsilon: 965, + phi: 966, + chi: 967, + psi: 968, + omega: 969, + thetasym: 977, + upsih: 978, + piv: 982, + ensp: 8194, + emsp: 8195, + thinsp: 8201, + zwnj: 8204, + zwj: 8205, + lrm: 8206, + rlm: 8207, + ndash: 8211, + mdash: 8212, + lsquo: 8216, + rsquo: 8217, + sbquo: 8218, + ldquo: 8220, + rdquo: 8221, + bdquo: 8222, + dagger: 8224, + Dagger: 8225, + bull: 8226, + hellip: 8230, + permil: 8240, + prime: 8242, + Prime: 8243, + lsaquo: 8249, + rsaquo: 8250, + oline: 8254, + frasl: 8260, + euro: 8364, + image: 8465, + weierp: 8472, + real: 8476, + trade: 8482, + alefsym: 8501, + larr: 8592, + uarr: 8593, + rarr: 8594, + darr: 8595, + harr: 8596, + crarr: 8629, + lArr: 8656, + uArr: 8657, + rArr: 8658, + dArr: 8659, + hArr: 8660, + forall: 8704, + part: 8706, + exist: 8707, + empty: 8709, + nabla: 8711, + isin: 8712, + notin: 8713, + ni: 8715, + prod: 8719, + sum: 8721, + minus: 8722, + lowast: 8727, + radic: 8730, + prop: 8733, + infin: 8734, + ang: 8736, + and: 8743, + or: 8744, + cap: 8745, + cup: 8746, + 'int': 8747, + there4: 8756, + sim: 8764, + cong: 8773, + asymp: 8776, + ne: 8800, + equiv: 8801, + le: 8804, + ge: 8805, + sub: 8834, + sup: 8835, + nsub: 8836, + sube: 8838, + supe: 8839, + oplus: 8853, + otimes: 8855, + perp: 8869, + sdot: 8901, + lceil: 8968, + rceil: 8969, + lfloor: 8970, + rfloor: 8971, + lang: 9001, + rang: 9002, + loz: 9674, + spades: 9824, + clubs: 9827, + hearts: 9829, + diams: 9830 + }; + controlCharacters = [ + 8364, + 129, + 8218, + 402, + 8222, + 8230, + 8224, + 8225, + 710, + 8240, + 352, + 8249, + 338, + 141, + 381, + 143, + 144, + 8216, + 8217, + 8220, + 8221, + 8226, + 8211, + 8212, + 732, + 8482, + 353, + 8250, + 339, + 157, + 382, + 376 + ]; + namedEntityPattern = new RegExp( '&(' + Object.keys( htmlEntities ).join( '|' ) + ');?', 'g' ); + hexEntityPattern = /([0-9]+);?/g; + decimalEntityPattern = /([0-9]+);?/g; + // some code points are verboten. If we were inserting HTML, the browser would replace the illegal + // code points with alternatives in some cases - since we're bypassing that mechanism, we need + // to replace them ourselves + // + // Source: http://en.wikipedia.org/wiki/Character_encodings_in_HTML#Illegal_characters + validateCode = function( code ) { + if ( !code ) { + return 65533; + } + // line feed becomes generic whitespace + if ( code === 10 ) { + return 32; + } + // ASCII range. (Why someone would use HTML entities for ASCII characters I don't know, but...) + if ( code < 128 ) { + return code; + } + // code points 128-159 are dealt with leniently by browsers, but they're incorrect. We need + // to correct the mistake or we'll end up with missing € signs and so on + if ( code <= 159 ) { + return controlCharacters[ code - 128 ]; + } + // basic multilingual plane + if ( code < 55296 ) { + return code; + } + // UTF-16 surrogate halves + if ( code <= 57343 ) { + return 65533; + } + // rest of the basic multilingual plane + if ( code <= 65535 ) { + return code; + } + // TODO it's... not exactly clear what should happen with code points over this value. The + // following seems to work. But I can't guarantee it works in China! + return 65533; + }; + decodeCharacterReferences = function( html ) { + var result; + // named entities + result = html.replace( namedEntityPattern, function( match, name ) { + if ( htmlEntities[ name ] ) { + return String.fromCharCode( htmlEntities[ name ] ); + } + return match; + } ); + // hex references + result = result.replace( hexEntityPattern, function( match, hex ) { + return String.fromCharCode( validateCode( parseInt( hex, 16 ) ) ); + } ); + // decimal references + result = result.replace( decimalEntityPattern, function( match, charCode ) { + return String.fromCharCode( validateCode( charCode ) ); + } ); + return result; + }; + whitespace = /\s+/g; + return TextStub; + }( config_types ); + + var parse_Parser_getText__getText = function( types, TextStub ) { + + return function( token, preserveWhitespace ) { + if ( token.type === types.TEXT ) { + this.pos += 1; + return new TextStub( token, preserveWhitespace ); + } + return null; + }; + }( config_types, parse_Parser_getText_TextStub__TextStub ); + + var parse_Parser_getComment_CommentStub__CommentStub = function( types ) { + + var CommentStub; + CommentStub = function( token ) { + this.content = token.content; + }; + CommentStub.prototype = { + toJSON: function() { + return { + t: types.COMMENT, + f: this.content + }; + }, + toString: function() { + return ''; + } + }; + return CommentStub; + }( config_types ); + + var parse_Parser_getComment__getComment = function( types, CommentStub ) { + + return function( token ) { + if ( token.type === types.COMMENT ) { + this.pos += 1; + return new CommentStub( token, this.preserveWhitespace ); + } + return null; + }; + }( config_types, parse_Parser_getComment_CommentStub__CommentStub ); + + var parse_Parser_getMustache_ExpressionStub = function( types, isObject ) { + + var ExpressionStub = function( token ) { + this.refs = []; + getRefs( token, this.refs ); + this.str = stringify( token, this.refs ); + }; + ExpressionStub.prototype = { + toJSON: function() { + if ( !this.json ) { + this.json = { + r: this.refs, + s: this.str + }; + } + return this.json; + } + }; + return ExpressionStub; + + function quoteStringLiteral( str ) { + return JSON.stringify( String( str ) ); + } + // TODO maybe refactor this? + function getRefs( token, refs ) { + var i, list; + if ( token.t === types.REFERENCE ) { + if ( refs.indexOf( token.n ) === -1 ) { + refs.unshift( token.n ); + } + } + list = token.o || token.m; + if ( list ) { + if ( isObject( list ) ) { + getRefs( list, refs ); + } else { + i = list.length; + while ( i-- ) { + getRefs( list[ i ], refs ); + } + } + } + if ( token.x ) { + getRefs( token.x, refs ); + } + if ( token.r ) { + getRefs( token.r, refs ); + } + if ( token.v ) { + getRefs( token.v, refs ); + } + } + + function stringify( token, refs ) { + var map = function( item ) { + return stringify( item, refs ); + }; + switch ( token.t ) { + case types.BOOLEAN_LITERAL: + case types.GLOBAL: + case types.NUMBER_LITERAL: + return token.v; + case types.STRING_LITERAL: + return quoteStringLiteral( token.v ); + case types.ARRAY_LITERAL: + return '[' + ( token.m ? token.m.map( map ).join( ',' ) : '' ) + ']'; + case types.OBJECT_LITERAL: + return '{' + ( token.m ? token.m.map( map ).join( ',' ) : '' ) + '}'; + case types.KEY_VALUE_PAIR: + return token.k + ':' + stringify( token.v, refs ); + case types.PREFIX_OPERATOR: + return ( token.s === 'typeof' ? 'typeof ' : token.s ) + stringify( token.o, refs ); + case types.INFIX_OPERATOR: + return stringify( token.o[ 0 ], refs ) + ( token.s.substr( 0, 2 ) === 'in' ? ' ' + token.s + ' ' : token.s ) + stringify( token.o[ 1 ], refs ); + case types.INVOCATION: + return stringify( token.x, refs ) + '(' + ( token.o ? token.o.map( map ).join( ',' ) : '' ) + ')'; + case types.BRACKETED: + return '(' + stringify( token.x, refs ) + ')'; + case types.MEMBER: + return stringify( token.x, refs ) + stringify( token.r, refs ); + case types.REFINEMENT: + return token.n ? '.' + token.n : '[' + stringify( token.x, refs ) + ']'; + case types.CONDITIONAL: + return stringify( token.o[ 0 ], refs ) + '?' + stringify( token.o[ 1 ], refs ) + ':' + stringify( token.o[ 2 ], refs ); + case types.REFERENCE: + return '${' + refs.indexOf( token.n ) + '}'; + default: + throw new Error( 'Could not stringify expression token. This error is unexpected' ); + } + } + }( config_types, utils_isObject ); + + var parse_Parser_getMustache_KeypathExpressionStub = function( types, ExpressionStub ) { + + var KeypathExpressionStub; + KeypathExpressionStub = function( token ) { + this.json = { + r: token.r, + m: token.m.map( jsonify ) + }; + }; + KeypathExpressionStub.prototype = { + toJSON: function() { + return this.json; + } + }; + return KeypathExpressionStub; + + function jsonify( member ) { + // Straightforward property, e.g. `foo.bar`? + if ( member.n ) { + return member.n; + } + // String or number literal, e.g. `foo["bar"]` or `foo[1]`? + if ( member.x.t === types.STRING_LITERAL || member.x.t === types.NUMBER_LITERAL ) { + return member.x.v; + } + // Straightforward reference, e.g. `foo[bar]`? + if ( member.x.t === types.REFERENCE ) { + return member.x; + } + // If none of the above, we need to process the AST + return new ExpressionStub( member.x ).toJSON(); + } + }( config_types, parse_Parser_getMustache_ExpressionStub ); + + var parse_Parser_getMustache_MustacheStub = function( types, KeypathExpressionStub, ExpressionStub ) { + + var MustacheStub = function( token, parser ) { + this.type = token.type === types.TRIPLE ? types.TRIPLE : token.mustacheType; + if ( token.ref ) { + this.ref = token.ref; + } + if ( token.keypathExpression ) { + this.keypathExpr = new KeypathExpressionStub( token.keypathExpression ); + } + if ( token.expression ) { + this.expr = new ExpressionStub( token.expression ); + } + parser.pos += 1; + }; + MustacheStub.prototype = { + toJSON: function() { + var json; + if ( this.json ) { + return this.json; + } + json = { + t: this.type + }; + if ( this.ref ) { + json.r = this.ref; + } + if ( this.keypathExpr ) { + json.kx = this.keypathExpr.toJSON(); + } + if ( this.expr ) { + json.x = this.expr.toJSON(); + } + this.json = json; + return json; + }, + toString: function() { + // mustaches cannot be stringified + return false; + } + }; + return MustacheStub; + }( config_types, parse_Parser_getMustache_KeypathExpressionStub, parse_Parser_getMustache_ExpressionStub ); + + var parse_Parser_utils_stringifyStubs = function( items ) { + var str = '', + itemStr, i, len; + if ( !items ) { + return ''; + } + for ( i = 0, len = items.length; i < len; i += 1 ) { + itemStr = items[ i ].toString(); + if ( itemStr === false ) { + return false; + } + str += itemStr; + } + return str; + }; + + var parse_Parser_utils_jsonifyStubs = function( stringifyStubs ) { + + return function( items, noStringify, topLevel ) { + var str, json; + if ( !topLevel && !noStringify ) { + str = stringifyStubs( items ); + if ( str !== false ) { + return str; + } + } + json = items.map( function( item ) { + return item.toJSON( noStringify ); + } ); + return json; + }; + }( parse_Parser_utils_stringifyStubs ); + + var parse_Parser_getMustache_SectionStub = function( types, normaliseKeypath, jsonifyStubs, KeypathExpressionStub, ExpressionStub ) { + + var SectionStub = function( firstToken, parser ) { + var next; + this.ref = firstToken.ref; + this.indexRef = firstToken.indexRef; + this.inverted = firstToken.mustacheType === types.INVERTED; + if ( firstToken.keypathExpression ) { + this.keypathExpr = new KeypathExpressionStub( firstToken.keypathExpression ); + } + if ( firstToken.expression ) { + this.expr = new ExpressionStub( firstToken.expression ); + } + parser.pos += 1; + this.items = []; + next = parser.next(); + while ( next ) { + if ( next.mustacheType === types.CLOSING ) { + validateClosing( this, next ); + parser.pos += 1; + break; + } + this.items.push( parser.getStub() ); + next = parser.next(); + } + }; + + function validateClosing( stub, token ) { + var opening = stub.ref, + closing = normaliseKeypath( token.ref.trim() ); + if ( !opening || !closing ) { + return; + } + if ( stub.indexRef ) { + opening += ':' + stub.indexRef; + } + if ( opening.substr( 0, closing.length ) !== closing ) { + throw new Error( 'Could not parse template: Illegal closing section {{/' + closing + '}}. Expected {{/' + stub.ref + '}}.' ); + } + } + SectionStub.prototype = { + toJSON: function( noStringify ) { + var json; + if ( this.json ) { + return this.json; + } + json = { + t: types.SECTION + }; + if ( this.ref ) { + json.r = this.ref; + } + if ( this.indexRef ) { + json.i = this.indexRef; + } + if ( this.inverted ) { + json.n = true; + } + if ( this.expr ) { + json.x = this.expr.toJSON(); + } + if ( this.keypathExpr ) { + json.kx = this.keypathExpr.toJSON(); + } + if ( this.items.length ) { + json.f = jsonifyStubs( this.items, noStringify ); + } + this.json = json; + return json; + }, + toString: function() { + // sections cannot be stringified + return false; + } + }; + return SectionStub; + }( config_types, utils_normaliseKeypath, parse_Parser_utils_jsonifyStubs, parse_Parser_getMustache_KeypathExpressionStub, parse_Parser_getMustache_ExpressionStub ); + + var parse_Parser_getMustache__getMustache = function( types, MustacheStub, SectionStub ) { + + return function( token ) { + if ( token.type === types.MUSTACHE || token.type === types.TRIPLE ) { + if ( token.mustacheType === types.SECTION || token.mustacheType === types.INVERTED ) { + return new SectionStub( token, this ); + } + return new MustacheStub( token, this ); + } + }; + }( config_types, parse_Parser_getMustache_MustacheStub, parse_Parser_getMustache_SectionStub ); + + var parse_Parser_getElement_ElementStub_utils_siblingsByTagName = { + li: [ 'li' ], + dt: [ + 'dt', + 'dd' + ], + dd: [ + 'dt', + 'dd' + ], + p: 'address article aside blockquote dir div dl fieldset footer form h1 h2 h3 h4 h5 h6 header hgroup hr menu nav ol p pre section table ul'.split( ' ' ), + rt: [ + 'rt', + 'rp' + ], + rp: [ + 'rp', + 'rt' + ], + optgroup: [ 'optgroup' ], + option: [ + 'option', + 'optgroup' + ], + thead: [ + 'tbody', + 'tfoot' + ], + tbody: [ + 'tbody', + 'tfoot' + ], + tr: [ 'tr' ], + td: [ + 'td', + 'th' + ], + th: [ + 'td', + 'th' + ] + }; + + var parse_Parser_getElement_ElementStub_utils_filterAttributes = function( isArray ) { + + return function( items ) { + var attrs, proxies, filtered, i, len, item; + filtered = {}; + attrs = []; + proxies = []; + len = items.length; + for ( i = 0; i < len; i += 1 ) { + item = items[ i ]; + // Transition? + if ( item.name === 'intro' ) { + if ( filtered.intro ) { + throw new Error( 'An element can only have one intro transition' ); + } + filtered.intro = item; + } else if ( item.name === 'outro' ) { + if ( filtered.outro ) { + throw new Error( 'An element can only have one outro transition' ); + } + filtered.outro = item; + } else if ( item.name === 'intro-outro' ) { + if ( filtered.intro || filtered.outro ) { + throw new Error( 'An element can only have one intro and one outro transition' ); + } + filtered.intro = item; + filtered.outro = deepClone( item ); + } else if ( item.name.substr( 0, 6 ) === 'proxy-' ) { + item.name = item.name.substring( 6 ); + proxies.push( item ); + } else if ( item.name.substr( 0, 3 ) === 'on-' ) { + item.name = item.name.substring( 3 ); + proxies.push( item ); + } else if ( item.name === 'decorator' ) { + filtered.decorator = item; + } else { + attrs.push( item ); + } + } + filtered.attrs = attrs; + filtered.proxies = proxies; + return filtered; + }; + + function deepClone( obj ) { + var result, key; + if ( typeof obj !== 'object' ) { + return obj; + } + if ( isArray( obj ) ) { + return obj.map( deepClone ); + } + result = {}; + for ( key in obj ) { + if ( obj.hasOwnProperty( key ) ) { + result[ key ] = deepClone( obj[ key ] ); + } + } + return result; + } + }( utils_isArray ); + + var parse_Parser_getElement_ElementStub_utils_processDirective = function( types, parseJSON ) { + + return function( directive ) { + var processed, tokens, token, colonIndex, throwError, directiveName, directiveArgs, parsed; + throwError = function() { + throw new Error( 'Illegal directive' ); + }; + if ( !directive.name || !directive.value ) { + throwError(); + } + processed = { + directiveType: directive.name + }; + tokens = directive.value; + directiveName = []; + directiveArgs = []; + while ( tokens.length ) { + token = tokens.shift(); + if ( token.type === types.TEXT ) { + colonIndex = token.value.indexOf( ':' ); + if ( colonIndex === -1 ) { + directiveName.push( token ); + } else { + // is the colon the first character? + if ( colonIndex ) { + // no + directiveName.push( { + type: types.TEXT, + value: token.value.substr( 0, colonIndex ) + } ); + } + // if there is anything after the colon in this token, treat + // it as the first token of the directiveArgs fragment + if ( token.value.length > colonIndex + 1 ) { + directiveArgs[ 0 ] = { + type: types.TEXT, + value: token.value.substring( colonIndex + 1 ) + }; + } + break; + } + } else { + directiveName.push( token ); + } + } + directiveArgs = directiveArgs.concat( tokens ); + if ( directiveName.length === 1 && directiveName[ 0 ].type === types.TEXT ) { + processed.name = directiveName[ 0 ].value; + } else { + processed.name = directiveName; + } + if ( directiveArgs.length ) { + if ( directiveArgs.length === 1 && directiveArgs[ 0 ].type === types.TEXT ) { + parsed = parseJSON( '[' + directiveArgs[ 0 ].value + ']' ); + processed.args = parsed ? parsed.value : directiveArgs[ 0 ].value; + } else { + processed.dynamicArgs = directiveArgs; + } + } + return processed; + }; + }( config_types, utils_parseJSON ); + + var parse_Parser_StringStub_StringParser = function( getText, getMustache ) { + + var StringParser; + StringParser = function( tokens, options ) { + // TODO what are the options? + var stub; + this.tokens = tokens || []; + this.pos = 0; + this.options = options; + this.result = []; + while ( stub = this.getStub() ) { + this.result.push( stub ); + } + }; + StringParser.prototype = { + getStub: function() { + var token = this.next(); + if ( !token ) { + return null; + } + return this.getText( token ) || this.getMustache( token ); + }, + getText: getText, + getMustache: getMustache, + next: function() { + return this.tokens[ this.pos ]; + } + }; + return StringParser; + }( parse_Parser_getText__getText, parse_Parser_getMustache__getMustache ); + + var parse_Parser_StringStub__StringStub = function( StringParser, stringifyStubs, jsonifyStubs ) { + + var StringStub; + StringStub = function( tokens ) { + var parser = new StringParser( tokens ); + this.stubs = parser.result; + }; + StringStub.prototype = { + toJSON: function( noStringify ) { + var json; + if ( this[ 'json_' + noStringify ] ) { + return this[ 'json_' + noStringify ]; + } + json = this[ 'json_' + noStringify ] = jsonifyStubs( this.stubs, noStringify ); + return json; + }, + toString: function() { + if ( this.str !== undefined ) { + return this.str; + } + this.str = stringifyStubs( this.stubs ); + return this.str; + } + }; + return StringStub; + }( parse_Parser_StringStub_StringParser, parse_Parser_utils_stringifyStubs, parse_Parser_utils_jsonifyStubs ); + + var parse_Parser_getElement_ElementStub_utils_jsonifyDirective = function( StringStub ) { + + return function( directive ) { + var result, name; + if ( typeof directive.name === 'string' ) { + if ( !directive.args && !directive.dynamicArgs ) { + return directive.name; + } + name = directive.name; + } else { + name = new StringStub( directive.name ).toJSON(); + } + result = { + n: name + }; + if ( directive.args ) { + result.a = directive.args; + return result; + } + if ( directive.dynamicArgs ) { + result.d = new StringStub( directive.dynamicArgs ).toJSON(); + } + return result; + }; + }( parse_Parser_StringStub__StringStub ); + + var parse_Parser_getElement_ElementStub_toJSON = function( types, jsonifyStubs, jsonifyDirective ) { + + return function( noStringify ) { + var json, name, value, proxy, i, len, attribute; + if ( this[ 'json_' + noStringify ] ) { + return this[ 'json_' + noStringify ]; + } + json = { + t: types.ELEMENT, + e: this.tag + }; + if ( this.doctype ) { + json.y = 1; + } + if ( this.attributes && this.attributes.length ) { + json.a = {}; + len = this.attributes.length; + for ( i = 0; i < len; i += 1 ) { + attribute = this.attributes[ i ]; + name = attribute.name; + if ( json.a[ name ] ) { + throw new Error( 'You cannot have multiple attributes with the same name' ); + } + // empty attributes (e.g. autoplay, checked) + if ( attribute.value === null ) { + value = null; + } else { + //value = jsonifyStubs( attribute.value, noStringify ); + value = attribute.value.toJSON( noStringify ); + } + json.a[ name ] = value; + } + } + if ( this.items && this.items.length ) { + json.f = jsonifyStubs( this.items, noStringify ); + } + if ( this.proxies && this.proxies.length ) { + json.v = {}; + len = this.proxies.length; + for ( i = 0; i < len; i += 1 ) { + proxy = this.proxies[ i ]; + json.v[ proxy.directiveType ] = jsonifyDirective( proxy ); + } + } + if ( this.intro ) { + json.t1 = jsonifyDirective( this.intro ); + } + if ( this.outro ) { + json.t2 = jsonifyDirective( this.outro ); + } + if ( this.decorator ) { + json.o = jsonifyDirective( this.decorator ); + } + this[ 'json_' + noStringify ] = json; + return json; + }; + }( config_types, parse_Parser_utils_jsonifyStubs, parse_Parser_getElement_ElementStub_utils_jsonifyDirective ); + + var parse_Parser_getElement_ElementStub_toString = function( stringifyStubs, voidElementNames ) { + + var htmlElements; + htmlElements = 'a abbr acronym address applet area b base basefont bdo big blockquote body br button caption center cite code col colgroup dd del dfn dir div dl dt em fieldset font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img input ins isindex kbd label legend li link map menu meta noframes noscript object ol p param pre q s samp script select small span strike strong style sub sup textarea title tt u ul var article aside audio bdi canvas command data datagrid datalist details embed eventsource figcaption figure footer header hgroup keygen mark meter nav output progress ruby rp rt section source summary time track video wbr'.split( ' ' ); + return function() { + var str, i, len, attrStr, name, attrValueStr, fragStr, isVoid; + if ( this.str !== undefined ) { + return this.str; + } + // if this isn't an HTML element, it can't be stringified (since the only reason to stringify an + // element is to use with innerHTML, and SVG doesn't support that method. + // Note: table elements and select children are excluded from this, because IE (of course) + // fucks up when you use innerHTML with them + if ( htmlElements.indexOf( this.tag.toLowerCase() ) === -1 ) { + return this.str = false; + } + // do we have proxies or transitions or a decorator? if so we can't use innerHTML + if ( this.proxies || this.intro || this.outro || this.decorator ) { + return this.str = false; + } + // see if children can be stringified (i.e. don't contain mustaches) + fragStr = stringifyStubs( this.items ); + if ( fragStr === false ) { + return this.str = false; + } + // is this a void element? + isVoid = voidElementNames.indexOf( this.tag.toLowerCase() ) !== -1; + str = '<' + this.tag; + if ( this.attributes ) { + for ( i = 0, len = this.attributes.length; i < len; i += 1 ) { + name = this.attributes[ i ].name; + // does this look like a namespaced attribute? if so we can't stringify it + if ( name.indexOf( ':' ) !== -1 ) { + return this.str = false; + } + // if this element has an id attribute, it can't be stringified (since references are stored + // in ractive.nodes). Similarly, intro and outro transitions + if ( name === 'id' || name === 'intro' || name === 'outro' ) { + return this.str = false; + } + attrStr = ' ' + name; + // empty attributes + if ( this.attributes[ i ].value !== null ) { + attrValueStr = this.attributes[ i ].value.toString(); + if ( attrValueStr === false ) { + return this.str = false; + } + if ( attrValueStr !== '' ) { + attrStr += '='; + // does it need to be quoted? + if ( /[\s"'=<>`]/.test( attrValueStr ) ) { + attrStr += '"' + attrValueStr.replace( /"/g, '"' ) + '"'; + } else { + attrStr += attrValueStr; + } + } + } + str += attrStr; + } + } + // if this isn't a void tag, but is self-closing, add a solidus. Aaaaand, we're done + if ( this.selfClosing && !isVoid ) { + str += '/>'; + return this.str = str; + } + str += '>'; + // void element? we're done + if ( isVoid ) { + return this.str = str; + } + // if this has children, add them + str += fragStr; + str += '' + this.tag + '>'; + return this.str = str; + }; + }( parse_Parser_utils_stringifyStubs, config_voidElementNames ); + + var parse_Parser_getElement_ElementStub__ElementStub = function( types, voidElementNames, warn, siblingsByTagName, filterAttributes, processDirective, toJSON, toString, StringStub ) { + + var ElementStub, + // helpers + allElementNames, closedByParentClose, onPattern, sanitize, leadingWhitespace = /^\s+/, + trailingWhitespace = /\s+$/; + ElementStub = function( firstToken, parser, preserveWhitespace ) { + var next, attrs, filtered, proxies, item, getFrag, lowerCaseTag; + parser.pos += 1; + getFrag = function( attr ) { + return { + name: attr.name, + value: attr.value ? new StringStub( attr.value ) : null + }; + }; + // enforce lower case tag names by default. HTML doesn't care. SVG does, so if we see an SVG tag + // that should be camelcased, camelcase it + this.tag = firstToken.name; + lowerCaseTag = firstToken.name.toLowerCase(); + if ( lowerCaseTag.substr( 0, 3 ) === 'rv-' ) { + warn( 'The "rv-" prefix for components has been deprecated. Support will be removed in a future version' ); + this.tag = this.tag.substring( 3 ); + } + // if this is a element, preserve whitespace within + preserveWhitespace = preserveWhitespace || lowerCaseTag === 'pre' || lowerCaseTag === 'style' || lowerCaseTag === 'script'; + if ( firstToken.attrs ) { + filtered = filterAttributes( firstToken.attrs ); + attrs = filtered.attrs; + proxies = filtered.proxies; + // remove event attributes (e.g. onclick='doSomething()') if we're sanitizing + if ( parser.options.sanitize && parser.options.sanitize.eventAttributes ) { + attrs = attrs.filter( sanitize ); + } + if ( attrs.length ) { + this.attributes = attrs.map( getFrag ); + } + // Process directives (proxy events, transitions, and decorators) + if ( proxies.length ) { + this.proxies = proxies.map( processDirective ); + } + if ( filtered.intro ) { + this.intro = processDirective( filtered.intro ); + } + if ( filtered.outro ) { + this.outro = processDirective( filtered.outro ); + } + if ( filtered.decorator ) { + this.decorator = processDirective( filtered.decorator ); + } + } + if ( firstToken.doctype ) { + this.doctype = true; + } + if ( firstToken.selfClosing ) { + this.selfClosing = true; + } + if ( voidElementNames.indexOf( lowerCaseTag ) !== -1 ) { + this.isVoid = true; + } + // if self-closing or a void element, close + if ( this.selfClosing || this.isVoid ) { + return; + } + this.siblings = siblingsByTagName[ lowerCaseTag ]; + this.items = []; + next = parser.next(); + while ( next ) { + // section closing mustache should also close this element, e.g. + // {{#items}}{{content}}{{/items}} + if ( next.mustacheType === types.CLOSING ) { + break; + } + if ( next.type === types.TAG ) { + // closing tag + if ( next.closing ) { + // it's a closing tag, which means this element is closed... + if ( next.name.toLowerCase() === lowerCaseTag ) { + parser.pos += 1; + } + break; + } else if ( this.siblings && this.siblings.indexOf( next.name.toLowerCase() ) !== -1 ) { + break; + } + } + this.items.push( parser.getStub( preserveWhitespace ) ); + next = parser.next(); + } + // if we're not preserving whitespace, we can eliminate inner leading and trailing whitespace + if ( !preserveWhitespace ) { + item = this.items[ 0 ]; + if ( item && item.type === types.TEXT ) { + item.text = item.text.replace( leadingWhitespace, '' ); + if ( !item.text ) { + this.items.shift(); + } + } + item = this.items[ this.items.length - 1 ]; + if ( item && item.type === types.TEXT ) { + item.text = item.text.replace( trailingWhitespace, '' ); + if ( !item.text ) { + this.items.pop(); + } + } + } + }; + ElementStub.prototype = { + toJSON: toJSON, + toString: toString + }; + allElementNames = 'a abbr acronym address applet area b base basefont bdo big blockquote body br button caption center cite code col colgroup dd del dfn dir div dl dt em fieldset font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img input ins isindex kbd label legend li link map menu meta noframes noscript object ol p param pre q s samp script select small span strike strong style sub sup textarea title tt u ul var article aside audio bdi canvas command data datagrid datalist details embed eventsource figcaption figure footer header hgroup keygen mark meter nav output progress ruby rp rt section source summary time track video wbr'.split( ' ' ); + closedByParentClose = 'li dd rt rp optgroup option tbody tfoot tr td th'.split( ' ' ); + onPattern = /^on[a-zA-Z]/; + sanitize = function( attr ) { + var valid = !onPattern.test( attr.name ); + return valid; + }; + return ElementStub; + }( config_types, config_voidElementNames, utils_warn, parse_Parser_getElement_ElementStub_utils_siblingsByTagName, parse_Parser_getElement_ElementStub_utils_filterAttributes, parse_Parser_getElement_ElementStub_utils_processDirective, parse_Parser_getElement_ElementStub_toJSON, parse_Parser_getElement_ElementStub_toString, parse_Parser_StringStub__StringStub ); + + var parse_Parser_getElement__getElement = function( ElementStub ) { + + return function( token ) { + // sanitize + if ( this.options.sanitize && this.options.sanitize.elements ) { + if ( this.options.sanitize.elements.indexOf( token.name.toLowerCase() ) !== -1 ) { + return null; + } + } + return new ElementStub( token, this, this.preserveWhitespace ); + }; + }( parse_Parser_getElement_ElementStub__ElementStub ); + + var parse_Parser__Parser = function( getText, getComment, getMustache, getElement, jsonifyStubs ) { + + var Parser; + Parser = function( tokens, options ) { + var stub, stubs; + this.tokens = tokens || []; + this.pos = 0; + this.options = options; + this.preserveWhitespace = options.preserveWhitespace; + stubs = []; + while ( stub = this.getStub() ) { + stubs.push( stub ); + } + this.result = jsonifyStubs( stubs, options.noStringify, true ); + }; + Parser.prototype = { + getStub: function( preserveWhitespace ) { + var token = this.next(); + if ( !token ) { + return null; + } + return this.getText( token, this.preserveWhitespace || preserveWhitespace ) || this.getComment( token ) || this.getMustache( token ) || this.getElement( token ); + }, + getText: getText, + getComment: getComment, + getMustache: getMustache, + getElement: getElement, + next: function() { + return this.tokens[ this.pos ]; + } + }; + return Parser; + }( parse_Parser_getText__getText, parse_Parser_getComment__getComment, parse_Parser_getMustache__getMustache, parse_Parser_getElement__getElement, parse_Parser_utils_jsonifyStubs ); + + // Ractive.parse + // =============== + // + // Takes in a string, and returns an object representing the parsed template. + // A parsed template is an array of 1 or more 'descriptors', which in some + // cases have children. + // + // The format is optimised for size, not readability, however for reference the + // keys for each descriptor are as follows: + // + // * r - Reference, e.g. 'mustache' in {{mustache}} + // * t - Type code (e.g. 1 is text, 2 is interpolator...) + // * f - Fragment. Contains a descriptor's children + // * e - Element name + // * a - map of element Attributes, or proxy event/transition Arguments + // * d - Dynamic proxy event/transition arguments + // * n - indicates an iNverted section + // * i - Index reference, e.g. 'num' in {{#section:num}}content{{/section}} + // * v - eVent proxies (i.e. when user e.g. clicks on a node, fire proxy event) + // * x - eXpressions + // * s - String representation of an expression function + // * t1 - intro Transition + // * t2 - outro Transition + // * o - decOrator + // * y - is doctYpe + var parse__parse = function( tokenize, types, Parser ) { + + var parse, onlyWhitespace, inlinePartialStart, inlinePartialEnd, parseCompoundTemplate; + onlyWhitespace = /^\s*$/; + inlinePartialStart = //; + inlinePartialEnd = //; + parse = function( template, options ) { + var tokens, json, token; + options = options || {}; + // does this template include inline partials? + if ( inlinePartialStart.test( template ) ) { + return parseCompoundTemplate( template, options ); + } + if ( options.sanitize === true ) { + options.sanitize = { + // blacklist from https://code.google.com/p/google-caja/source/browse/trunk/src/com/google/caja/lang/html/html4-elements-whitelist.json + elements: 'applet base basefont body frame frameset head html isindex link meta noframes noscript object param script style title'.split( ' ' ), + eventAttributes: true + }; + } + tokens = tokenize( template, options ); + if ( !options.preserveWhitespace ) { + // remove first token if it only contains whitespace + token = tokens[ 0 ]; + if ( token && token.type === types.TEXT && onlyWhitespace.test( token.value ) ) { + tokens.shift(); + } + // ditto last token + token = tokens[ tokens.length - 1 ]; + if ( token && token.type === types.TEXT && onlyWhitespace.test( token.value ) ) { + tokens.pop(); + } + } + json = new Parser( tokens, options ).result; + if ( typeof json === 'string' ) { + // If we return it as a string, Ractive will attempt to reparse it! + // Instead we wrap it in an array. Ractive knows what to do then + return [ json ]; + } + return json; + }; + parseCompoundTemplate = function( template, options ) { + var mainTemplate, remaining, partials, name, startMatch, endMatch; + partials = {}; + mainTemplate = ''; + remaining = template; + while ( startMatch = inlinePartialStart.exec( remaining ) ) { + name = startMatch[ 1 ]; + mainTemplate += remaining.substr( 0, startMatch.index ); + remaining = remaining.substring( startMatch.index + startMatch[ 0 ].length ); + endMatch = inlinePartialEnd.exec( remaining ); + if ( !endMatch || endMatch[ 1 ] !== name ) { + throw new Error( 'Inline partials must have a closing delimiter, and cannot be nested' ); + } + partials[ name ] = parse( remaining.substr( 0, endMatch.index ), options ); + remaining = remaining.substring( endMatch.index + endMatch[ 0 ].length ); + } + return { + main: parse( mainTemplate, options ), + partials: partials + }; + }; + return parse; + }( parse_tokenize, config_types, parse_Parser__Parser ); + + var render_DomFragment_Partial_deIndent = function() { + + var empty = /^\s*$/, + leadingWhitespace = /^\s*/; + return function( str ) { + var lines, firstLine, lastLine, minIndent; + lines = str.split( '\n' ); + // remove first and last line, if they only contain whitespace + firstLine = lines[ 0 ]; + if ( firstLine !== undefined && empty.test( firstLine ) ) { + lines.shift(); + } + lastLine = lines[ lines.length - 1 ]; + if ( lastLine !== undefined && empty.test( lastLine ) ) { + lines.pop(); + } + minIndent = lines.reduce( reducer, null ); + if ( minIndent ) { + str = lines.map( function( line ) { + return line.replace( minIndent, '' ); + } ).join( '\n' ); + } + return str; + }; + + function reducer( previous, line ) { + var lineIndent = leadingWhitespace.exec( line )[ 0 ]; + if ( previous === null || lineIndent.length < previous.length ) { + return lineIndent; + } + return previous; + } + }(); + + var render_DomFragment_Partial_getPartialDescriptor = function( errors, isClient, warn, isObject, partials, parse, deIndent ) { + + var getPartialDescriptor, registerPartial, getPartialFromRegistry, unpack; + getPartialDescriptor = function( root, name ) { + var el, partial, errorMessage; + // If the partial was specified on this instance, great + if ( partial = getPartialFromRegistry( root, name ) ) { + return partial; + } + // Does it exist on the page as a script tag? + if ( isClient ) { + el = document.getElementById( name ); + if ( el && el.tagName === 'SCRIPT' ) { + if ( !parse ) { + throw new Error( errors.missingParser ); + } + registerPartial( parse( deIndent( el.text ), root.parseOptions ), name, partials ); + } + } + partial = partials[ name ]; + // No match? Return an empty array + if ( !partial ) { + errorMessage = 'Could not find descriptor for partial "' + name + '"'; + if ( root.debug ) { + throw new Error( errorMessage ); + } else { + warn( errorMessage ); + } + return []; + } + return unpack( partial ); + }; + getPartialFromRegistry = function( ractive, name ) { + var partial; + if ( ractive.partials[ name ] ) { + // If this was added manually to the registry, but hasn't been parsed, + // parse it now + if ( typeof ractive.partials[ name ] === 'string' ) { + if ( !parse ) { + throw new Error( errors.missingParser ); + } + partial = parse( ractive.partials[ name ], ractive.parseOptions ); + registerPartial( partial, name, ractive.partials ); + } + return unpack( ractive.partials[ name ] ); + } + }; + registerPartial = function( partial, name, registry ) { + var key; + if ( isObject( partial ) ) { + registry[ name ] = partial.main; + for ( key in partial.partials ) { + if ( partial.partials.hasOwnProperty( key ) ) { + registry[ key ] = partial.partials[ key ]; + } + } + } else { + registry[ name ] = partial; + } + }; + unpack = function( partial ) { + // Unpack string, if necessary + if ( partial.length === 1 && typeof partial[ 0 ] === 'string' ) { + return partial[ 0 ]; + } + return partial; + }; + return getPartialDescriptor; + }( config_errors, config_isClient, utils_warn, utils_isObject, registries_partials, parse__parse, render_DomFragment_Partial_deIndent ); + + var render_DomFragment_Partial_applyIndent = function( string, indent ) { + var indented; + if ( !indent ) { + return string; + } + indented = string.split( '\n' ).map( function( line, notFirstLine ) { + return notFirstLine ? indent + line : line; + } ).join( '\n' ); + return indented; + }; + + var render_DomFragment_Partial__Partial = function( types, getPartialDescriptor, applyIndent, circular ) { + + var DomPartial, DomFragment; + circular.push( function() { + DomFragment = circular.DomFragment; + } ); + DomPartial = function( options, docFrag ) { + var parentFragment = this.parentFragment = options.parentFragment, + descriptor; + this.type = types.PARTIAL; + this.name = options.descriptor.r; + this.index = options.index; + if ( !options.descriptor.r ) { + // TODO support dynamic partial switching + throw new Error( 'Partials must have a static reference (no expressions). This may change in a future version of Ractive.' ); + } + descriptor = getPartialDescriptor( parentFragment.root, options.descriptor.r ); + this.fragment = new DomFragment( { + descriptor: descriptor, + root: parentFragment.root, + pNode: parentFragment.pNode, + owner: this + } ); + if ( docFrag ) { + docFrag.appendChild( this.fragment.docFrag ); + } + }; + DomPartial.prototype = { + firstNode: function() { + return this.fragment.firstNode(); + }, + findNextNode: function() { + return this.parentFragment.findNextNode( this ); + }, + detach: function() { + return this.fragment.detach(); + }, + reassign: function( indexRef, newIndex, oldKeypath, newKeypath ) { + return this.fragment.reassign( indexRef, newIndex, oldKeypath, newKeypath ); + }, + teardown: function( destroy ) { + this.fragment.teardown( destroy ); + }, + toString: function() { + var string, previousItem, lastLine, match; + string = this.fragment.toString(); + previousItem = this.parentFragment.items[ this.index - 1 ]; + if ( !previousItem || previousItem.type !== types.TEXT ) { + return string; + } + lastLine = previousItem.descriptor.split( '\n' ).pop(); + if ( match = /^\s+$/.exec( lastLine ) ) { + return applyIndent( string, match[ 0 ] ); + } + return string; + }, + find: function( selector ) { + return this.fragment.find( selector ); + }, + findAll: function( selector, query ) { + return this.fragment.findAll( selector, query ); + }, + findComponent: function( selector ) { + return this.fragment.findComponent( selector ); + }, + findAllComponents: function( selector, query ) { + return this.fragment.findAllComponents( selector, query ); + } + }; + return DomPartial; + }( config_types, render_DomFragment_Partial_getPartialDescriptor, render_DomFragment_Partial_applyIndent, circular ); + + var render_DomFragment_Component_initialise_createModel_ComponentParameter = function( runloop, StringFragment ) { + + var ComponentParameter = function( component, key, value ) { + this.parentFragment = component.parentFragment; + this.component = component; + this.key = key; + this.fragment = new StringFragment( { + descriptor: value, + root: component.root, + owner: this + } ); + this.selfUpdating = this.fragment.isSimple(); + this.value = this.fragment.getValue(); + }; + ComponentParameter.prototype = { + bubble: function() { + // If there's a single item, we can update the component immediately... + if ( this.selfUpdating ) { + this.update(); + } else if ( !this.deferred && this.ready ) { + runloop.addAttribute( this ); + this.deferred = true; + } + }, + update: function() { + var value = this.fragment.getValue(); + this.component.instance.set( this.key, value ); + this.value = value; + }, + teardown: function() { + this.fragment.teardown(); + } + }; + return ComponentParameter; + }( global_runloop, render_StringFragment__StringFragment ); + + var render_DomFragment_Component_initialise_createModel__createModel = function( types, parseJSON, resolveRef, get, ComponentParameter ) { + + return function( component, defaultData, attributes, toBind ) { + var data, key, value; + data = {}; + // some parameters, e.g. foo="The value is {{bar}}", are 'complex' - in + // other words, we need to construct a string fragment to watch + // when they change. We store these so they can be torn down later + component.complexParameters = []; + for ( key in attributes ) { + if ( attributes.hasOwnProperty( key ) ) { + value = getValue( component, key, attributes[ key ], toBind ); + if ( value !== undefined || defaultData[ key ] === undefined ) { + data[ key ] = value; + } + } + } + return data; + }; + + function getValue( component, key, descriptor, toBind ) { + var parameter, parsed, parentInstance, parentFragment, keypath, indexRef; + parentInstance = component.root; + parentFragment = component.parentFragment; + // If this is a static value, great + if ( typeof descriptor === 'string' ) { + parsed = parseJSON( descriptor ); + return parsed ? parsed.value : descriptor; + } + // If null, we treat it as a boolean attribute (i.e. true) + if ( descriptor === null ) { + return true; + } + // If a regular interpolator, we bind to it + if ( descriptor.length === 1 && descriptor[ 0 ].t === types.INTERPOLATOR && descriptor[ 0 ].r ) { + // Is it an index reference? + if ( parentFragment.indexRefs && parentFragment.indexRefs[ indexRef = descriptor[ 0 ].r ] !== undefined ) { + component.indexRefBindings[ indexRef ] = key; + return parentFragment.indexRefs[ indexRef ]; + } + // TODO what about references that resolve late? Should these be considered? + keypath = resolveRef( parentInstance, descriptor[ 0 ].r, parentFragment ) || descriptor[ 0 ].r; + // We need to set up bindings between parent and child, but + // we can't do it yet because the child instance doesn't exist + // yet - so we make a note instead + toBind.push( { + childKeypath: key, + parentKeypath: keypath + } ); + return get( parentInstance, keypath ); + } + // We have a 'complex parameter' - we need to create a full-blown string + // fragment in order to evaluate and observe its value + parameter = new ComponentParameter( component, key, descriptor ); + component.complexParameters.push( parameter ); + return parameter.value; + } + }( config_types, utils_parseJSON, shared_resolveRef, shared_get__get, render_DomFragment_Component_initialise_createModel_ComponentParameter ); + + var render_DomFragment_Component_initialise_createInstance = function() { + + return function( component, Component, data, docFrag, contentDescriptor ) { + var instance, parentFragment, partials, root, adapt; + parentFragment = component.parentFragment; + root = component.root; + // Make contents available as a {{>content}} partial + partials = { + content: contentDescriptor || [] + }; + // Use component default adaptors AND inherit parent adaptors. + adapt = combineAdaptors( root, Component.defaults.adapt, Component.adaptors ); + instance = new Component( { + el: parentFragment.pNode, + append: true, + data: data, + partials: partials, + magic: root.magic || Component.defaults.magic, + modifyArrays: root.modifyArrays, + _parent: root, + _component: component, + adapt: adapt + } ); + if ( docFrag ) { + // The component may be in the wrong place! This is because we + // are still populating the document fragment that will be appended + // to its parent node. So even though the component is *already* + // a child of the parent node, we need to detach it, then insert + // it into said document fragment, so that order is maintained + // (both figuratively and literally). + instance.insert( docFrag ); + // (After inserting, we need to reset the node reference) + instance.fragment.pNode = instance.el = parentFragment.pNode; + } + return instance; + }; + + function combineAdaptors( root, defaultAdapt ) { + var adapt, len, i; + // Parent adaptors should take precedence, so they go first + if ( root.adapt.length ) { + adapt = root.adapt.map( function( stringOrObject ) { + if ( typeof stringOrObject === 'object' ) { + return stringOrObject; + } + return root.adaptors[ stringOrObject ] || stringOrObject; + } ); + } else { + adapt = []; + } + // If the component has any adaptors that aren't already included, + // include them now + if ( len = defaultAdapt.length ) { + for ( i = 0; i < len; i += 1 ) { + if ( adapt.indexOf( defaultAdapt[ i ] ) === -1 ) { + adapt.push( defaultAdapt[ i ] ); + } + } + } + return adapt; + } + }(); + + var render_DomFragment_Component_initialise_createBindings = function( createComponentBinding, get, set ) { + + return function createInitialComponentBindings( component, toBind ) { + toBind.forEach( function createInitialComponentBinding( pair ) { + var childValue, parentValue; + createComponentBinding( component, component.root, pair.parentKeypath, pair.childKeypath ); + childValue = get( component.instance, pair.childKeypath ); + parentValue = get( component.root, pair.parentKeypath ); + if ( childValue !== undefined && parentValue === undefined ) { + set( component.root, pair.parentKeypath, childValue ); + } + } ); + }; + }( shared_createComponentBinding, shared_get__get, shared_set ); + + var render_DomFragment_Component_initialise_propagateEvents = function( warn ) { + + // TODO how should event arguments be handled? e.g. + // + // The event 'bar' will be fired on the parent instance + // when 'foo' fires on the child, but the 1,2,3 arguments + // will be lost + var errorMessage = 'Components currently only support simple events - you cannot include arguments. Sorry!'; + return function( component, eventsDescriptor ) { + var eventName; + for ( eventName in eventsDescriptor ) { + if ( eventsDescriptor.hasOwnProperty( eventName ) ) { + propagateEvent( component.instance, component.root, eventName, eventsDescriptor[ eventName ] ); + } + } + }; + + function propagateEvent( childInstance, parentInstance, eventName, proxyEventName ) { + if ( typeof proxyEventName !== 'string' ) { + if ( parentInstance.debug ) { + throw new Error( errorMessage ); + } else { + warn( errorMessage ); + return; + } + } + childInstance.on( eventName, function() { + var args = Array.prototype.slice.call( arguments ); + args.unshift( proxyEventName ); + parentInstance.fire.apply( parentInstance, args ); + } ); + } + }( utils_warn ); + + var render_DomFragment_Component_initialise_updateLiveQueries = function( component ) { + var ancestor, query; + // If there's a live query for this component type, add it + ancestor = component.root; + while ( ancestor ) { + if ( query = ancestor._liveComponentQueries[ component.name ] ) { + query.push( component.instance ); + } + ancestor = ancestor._parent; + } + }; + + var render_DomFragment_Component_initialise__initialise = function( types, warn, createModel, createInstance, createBindings, propagateEvents, updateLiveQueries ) { + + return function initialiseComponent( component, options, docFrag ) { + var parentFragment, root, Component, data, toBind; + parentFragment = component.parentFragment = options.parentFragment; + root = parentFragment.root; + component.root = root; + component.type = types.COMPONENT; + component.name = options.descriptor.e; + component.index = options.index; + component.indexRefBindings = {}; + component.bindings = []; + // get the component constructor + Component = root.components[ options.descriptor.e ]; + if ( !Component ) { + throw new Error( 'Component "' + options.descriptor.e + '" not found' ); + } + // First, we need to create a model for the component - e.g. if we + // encounter then we need to create a widget + // with `data: { foo: 'bar' }`. + // + // This may involve setting up some bindings, but we can't do it + // yet so we take some notes instead + toBind = []; + data = createModel( component, Component.data || {}, options.descriptor.a, toBind ); + createInstance( component, Component, data, docFrag, options.descriptor.f ); + createBindings( component, toBind ); + propagateEvents( component, options.descriptor.v ); + // intro, outro and decorator directives have no effect + if ( options.descriptor.t1 || options.descriptor.t2 || options.descriptor.o ) { + warn( 'The "intro", "outro" and "decorator" directives have no effect on components' ); + } + updateLiveQueries( component ); + }; + }( config_types, utils_warn, render_DomFragment_Component_initialise_createModel__createModel, render_DomFragment_Component_initialise_createInstance, render_DomFragment_Component_initialise_createBindings, render_DomFragment_Component_initialise_propagateEvents, render_DomFragment_Component_initialise_updateLiveQueries ); + + var render_DomFragment_Component__Component = function( initialise, getNewKeypath ) { + + var DomComponent = function( options, docFrag ) { + initialise( this, options, docFrag ); + }; + DomComponent.prototype = { + firstNode: function() { + return this.instance.fragment.firstNode(); + }, + findNextNode: function() { + return this.parentFragment.findNextNode( this ); + }, + detach: function() { + return this.instance.fragment.detach(); + }, + teardown: function( destroy ) { + while ( this.complexParameters.length ) { + this.complexParameters.pop().teardown(); + } + while ( this.bindings.length ) { + this.bindings.pop().teardown(); + } + removeFromLiveComponentQueries( this ); + // Add this flag so that we don't unnecessarily destroy the component's nodes + this.shouldDestroy = destroy; + this.instance.teardown(); + }, + reassign: function( indexRef, newIndex, oldKeypath, newKeypath ) { + var childInstance = this.instance, + parentInstance = childInstance._parent, + indexRefAlias, query; + this.bindings.forEach( function( binding ) { + var updated; + if ( binding.root !== parentInstance ) { + return; + } + if ( binding.keypath === indexRef ) { + childInstance.set( binding.otherKeypath, newIndex ); + } + if ( updated = getNewKeypath( binding.keypath, oldKeypath, newKeypath ) ) { + binding.reassign( updated ); + } + } ); + if ( indexRefAlias = this.indexRefBindings[ indexRef ] ) { + childInstance.set( indexRefAlias, newIndex ); + } + if ( query = this.root._liveComponentQueries[ this.name ] ) { + query._makeDirty(); + } + }, + toString: function() { + return this.instance.fragment.toString(); + }, + find: function( selector ) { + return this.instance.fragment.find( selector ); + }, + findAll: function( selector, query ) { + return this.instance.fragment.findAll( selector, query ); + }, + findComponent: function( selector ) { + if ( !selector || selector === this.name ) { + return this.instance; + } + if ( this.instance.fragment ) { + return this.instance.fragment.findComponent( selector ); + } + return null; + }, + findAllComponents: function( selector, query ) { + query._test( this, true ); + if ( this.instance.fragment ) { + this.instance.fragment.findAllComponents( selector, query ); + } + } + }; + return DomComponent; + + function removeFromLiveComponentQueries( component ) { + var instance, query; + instance = component.root; + do { + if ( query = instance._liveComponentQueries[ component.name ] ) { + query._remove( component ); + } + } while ( instance = instance._parent ); + } + }( render_DomFragment_Component_initialise__initialise, render_shared_utils_getNewKeypath ); + + var render_DomFragment_Comment = function( types, detach ) { + + var DomComment = function( options, docFrag ) { + this.type = types.COMMENT; + this.descriptor = options.descriptor; + if ( docFrag ) { + this.node = document.createComment( options.descriptor.f ); + docFrag.appendChild( this.node ); + } + }; + DomComment.prototype = { + detach: detach, + teardown: function( destroy ) { + if ( destroy ) { + this.detach(); + } + }, + firstNode: function() { + return this.node; + }, + toString: function() { + return ''; + } + }; + return DomComment; + }( config_types, render_DomFragment_shared_detach ); + + var render_DomFragment__DomFragment = function( types, matches, Fragment, insertHtml, Text, Interpolator, Section, Triple, Element, Partial, Component, Comment, circular ) { + + var DomFragment = function( options ) { + if ( options.pNode ) { + this.docFrag = document.createDocumentFragment(); + } + // if we have an HTML string, our job is easy. + if ( typeof options.descriptor === 'string' ) { + this.html = options.descriptor; + if ( this.docFrag ) { + this.nodes = insertHtml( this.html, options.pNode.tagName, options.pNode.namespaceURI, this.docFrag ); + } + } else { + // otherwise we need to make a proper fragment + Fragment.init( this, options ); + } + }; + DomFragment.prototype = { + reassign: Fragment.reassign, + detach: function() { + var len, i; + if ( this.docFrag ) { + // if this was built from HTML, we just need to remove the nodes + if ( this.nodes ) { + len = this.nodes.length; + for ( i = 0; i < len; i += 1 ) { + this.docFrag.appendChild( this.nodes[ i ] ); + } + } else if ( this.items ) { + len = this.items.length; + for ( i = 0; i < len; i += 1 ) { + this.docFrag.appendChild( this.items[ i ].detach() ); + } + } + return this.docFrag; + } + }, + createItem: function( options ) { + if ( typeof options.descriptor === 'string' ) { + return new Text( options, this.docFrag ); + } + switch ( options.descriptor.t ) { + case types.INTERPOLATOR: + return new Interpolator( options, this.docFrag ); + case types.SECTION: + return new Section( options, this.docFrag ); + case types.TRIPLE: + return new Triple( options, this.docFrag ); + case types.ELEMENT: + if ( this.root.components[ options.descriptor.e ] ) { + return new Component( options, this.docFrag ); + } + return new Element( options, this.docFrag ); + case types.PARTIAL: + return new Partial( options, this.docFrag ); + case types.COMMENT: + return new Comment( options, this.docFrag ); + default: + throw new Error( 'Something very strange happened. Please file an issue at https://github.com/RactiveJS/Ractive/issues. Thanks!' ); + } + }, + teardown: function( destroy ) { + var node; + // if this was built from HTML, we just need to remove the nodes + if ( this.nodes && destroy ) { + while ( node = this.nodes.pop() ) { + node.parentNode.removeChild( node ); + } + } else if ( this.items ) { + while ( this.items.length ) { + this.items.pop().teardown( destroy ); + } + } + this.nodes = this.items = this.docFrag = null; + }, + firstNode: function() { + if ( this.items && this.items[ 0 ] ) { + return this.items[ 0 ].firstNode(); + } else if ( this.nodes ) { + return this.nodes[ 0 ] || null; + } + return null; + }, + findNextNode: function( item ) { + var index = item.index; + if ( this.items[ index + 1 ] ) { + return this.items[ index + 1 ].firstNode(); + } + // if this is the root fragment, and there are no more items, + // it means we're at the end... + if ( this.owner === this.root ) { + if ( !this.owner.component ) { + return null; + } + // ...unless this is a component + return this.owner.component.findNextNode(); + } + return this.owner.findNextNode( this ); + }, + toString: function() { + var html, i, len, item; + if ( this.html ) { + return this.html; + } + html = ''; + if ( !this.items ) { + return html; + } + len = this.items.length; + for ( i = 0; i < len; i += 1 ) { + item = this.items[ i ]; + html += item.toString(); + } + return html; + }, + find: function( selector ) { + var i, len, item, node, queryResult; + if ( this.nodes ) { + len = this.nodes.length; + for ( i = 0; i < len; i += 1 ) { + node = this.nodes[ i ]; + // we only care about elements + if ( node.nodeType !== 1 ) { + continue; + } + if ( matches( node, selector ) ) { + return node; + } + if ( queryResult = node.querySelector( selector ) ) { + return queryResult; + } + } + return null; + } + if ( this.items ) { + len = this.items.length; + for ( i = 0; i < len; i += 1 ) { + item = this.items[ i ]; + if ( item.find && ( queryResult = item.find( selector ) ) ) { + return queryResult; + } + } + return null; + } + }, + findAll: function( selector, query ) { + var i, len, item, node, queryAllResult, numNodes, j; + if ( this.nodes ) { + len = this.nodes.length; + for ( i = 0; i < len; i += 1 ) { + node = this.nodes[ i ]; + // we only care about elements + if ( node.nodeType !== 1 ) { + continue; + } + if ( matches( node, selector ) ) { + query.push( node ); + } + if ( queryAllResult = node.querySelectorAll( selector ) ) { + numNodes = queryAllResult.length; + for ( j = 0; j < numNodes; j += 1 ) { + query.push( queryAllResult[ j ] ); + } + } + } + } else if ( this.items ) { + len = this.items.length; + for ( i = 0; i < len; i += 1 ) { + item = this.items[ i ]; + if ( item.findAll ) { + item.findAll( selector, query ); + } + } + } + return query; + }, + findComponent: function( selector ) { + var len, i, item, queryResult; + if ( this.items ) { + len = this.items.length; + for ( i = 0; i < len; i += 1 ) { + item = this.items[ i ]; + if ( item.findComponent && ( queryResult = item.findComponent( selector ) ) ) { + return queryResult; + } + } + return null; + } + }, + findAllComponents: function( selector, query ) { + var i, len, item; + if ( this.items ) { + len = this.items.length; + for ( i = 0; i < len; i += 1 ) { + item = this.items[ i ]; + if ( item.findAllComponents ) { + item.findAllComponents( selector, query ); + } + } + } + return query; + } + }; + circular.DomFragment = DomFragment; + return DomFragment; + }( config_types, utils_matches, render_shared_Fragment__Fragment, render_DomFragment_shared_insertHtml, render_DomFragment_Text, render_DomFragment_Interpolator, render_DomFragment_Section__Section, render_DomFragment_Triple, render_DomFragment_Element__Element, render_DomFragment_Partial__Partial, render_DomFragment_Component__Component, render_DomFragment_Comment, circular ); + + var Ractive_prototype_render = function( runloop, css, DomFragment ) { + + return function Ractive_prototype_render( target, callback ) { + this._rendering = true; + runloop.start( this, callback ); + // This method is part of the API for one reason only - so that it can be + // overwritten by components that don't want to use the templating system + // (e.g. canvas-based components). It shouldn't be called outside of the + // initialisation sequence! + if ( !this._initing ) { + throw new Error( 'You cannot call ractive.render() directly!' ); + } + // Add CSS, if applicable + if ( this.constructor.css ) { + css.add( this.constructor ); + } + // Render our *root fragment* + this.fragment = new DomFragment( { + descriptor: this.template, + root: this, + owner: this, + // saves doing `if ( this.parent ) { /*...*/ }` later on + pNode: target + } ); + if ( target ) { + target.appendChild( this.fragment.docFrag ); + } + // If this is *isn't* a child of a component that's in the process of rendering, + // it should call any `init()` methods at this point + if ( !this._parent || !this._parent._rendering ) { + initChildren( this ); + } + delete this._rendering; + runloop.end(); + }; + + function initChildren( instance ) { + var child; + while ( child = instance._childInitQueue.pop() ) { + if ( child.instance.init ) { + child.instance.init( child.options ); + } + // now do the same for grandchildren, etc + initChildren( child.instance ); + } + } + }( global_runloop, global_css, render_DomFragment__DomFragment ); + + var Ractive_prototype_renderHTML = function( warn ) { + + return function() { + // TODO remove this method in a future version! + warn( 'renderHTML() has been deprecated and will be removed in a future version. Please use toHTML() instead' ); + return this.toHTML(); + }; + }( utils_warn ); + + var Ractive_prototype_reset = function( Promise, runloop, clearCache, notifyDependants ) { + + return function( data, callback ) { + var promise, fulfilPromise, wrapper; + if ( typeof data === 'function' ) { + callback = data; + data = {}; + } else { + data = data || {}; + } + if ( typeof data !== 'object' ) { + throw new Error( 'The reset method takes either no arguments, or an object containing new data' ); + } + promise = new Promise( function( fulfil ) { + fulfilPromise = fulfil; + } ); + if ( callback ) { + promise.then( callback ); + } + runloop.start( this, fulfilPromise ); + // If the root object is wrapped, try and use the wrapper's reset value + if ( ( wrapper = this._wrapped[ '' ] ) && wrapper.reset ) { + if ( wrapper.reset( data ) === false ) { + // reset was rejected, we need to replace the object + this.data = data; + } + } else { + this.data = data; + } + clearCache( this, '' ); + notifyDependants( this, '' ); + runloop.end(); + this.fire( 'reset', data ); + return promise; + }; + }( utils_Promise, global_runloop, shared_clearCache, shared_notifyDependants ); + + var Ractive_prototype_set = function( runloop, isObject, normaliseKeypath, Promise, set ) { + + return function Ractive_prototype_set( keypath, value, callback ) { + var map, promise, fulfilPromise; + promise = new Promise( function( fulfil ) { + fulfilPromise = fulfil; + } ); + runloop.start( this, fulfilPromise ); + // Set multiple keypaths in one go + if ( isObject( keypath ) ) { + map = keypath; + callback = value; + for ( keypath in map ) { + if ( map.hasOwnProperty( keypath ) ) { + value = map[ keypath ]; + keypath = normaliseKeypath( keypath ); + set( this, keypath, value ); + } + } + } else { + keypath = normaliseKeypath( keypath ); + set( this, keypath, value ); + } + runloop.end(); + if ( callback ) { + promise.then( callback.bind( this ) ); + } + return promise; + }; + }( global_runloop, utils_isObject, utils_normaliseKeypath, utils_Promise, shared_set ); + + var Ractive_prototype_subtract = function( add ) { + + return function( keypath, d ) { + return add( this, keypath, d === undefined ? -1 : -d ); + }; + }( Ractive_prototype_shared_add ); + + // Teardown. This goes through the root fragment and all its children, removing observers + // and generally cleaning up after itself + var Ractive_prototype_teardown = function( types, css, runloop, Promise, clearCache ) { + + return function( callback ) { + var keypath, promise, fulfilPromise, shouldDestroy, originalCallback, fragment, nearestDetachingElement, unresolvedImplicitDependency; + this.fire( 'teardown' ); + // If this is a component, and the component isn't marked for destruction, + // don't detach nodes from the DOM unnecessarily + shouldDestroy = !this.component || this.component.shouldDestroy; + if ( this.constructor.css ) { + // We need to find the nearest detaching element. When it gets removed + // from the DOM, it's safe to remove our CSS + if ( shouldDestroy ) { + originalCallback = callback; + callback = function() { + if ( originalCallback ) { + originalCallback.call( this ); + } + css.remove( this.constructor ); + }; + } else { + fragment = this.component.parentFragment; + do { + if ( fragment.owner.type !== types.ELEMENT ) { + continue; + } + if ( fragment.owner.willDetach ) { + nearestDetachingElement = fragment.owner; + } + } while ( !nearestDetachingElement && ( fragment = fragment.parent ) ); + if ( !nearestDetachingElement ) { + throw new Error( 'A component is being torn down but doesn\'t have a nearest detaching element... this shouldn\'t happen!' ); + } + nearestDetachingElement.cssDetachQueue.push( this.constructor ); + } + } + promise = new Promise( function( fulfil ) { + fulfilPromise = fulfil; + } ); + runloop.start( this, fulfilPromise ); + this.fragment.teardown( shouldDestroy ); + // Cancel any animations in progress + while ( this._animations[ 0 ] ) { + this._animations[ 0 ].stop(); + } + // Clear cache - this has the side-effect of unregistering keypaths from modified arrays. + for ( keypath in this._cache ) { + clearCache( this, keypath ); + } + // Teardown any failed lookups - we don't need them to resolve any more + while ( unresolvedImplicitDependency = this._unresolvedImplicitDependencies.pop() ) { + unresolvedImplicitDependency.teardown(); + } + runloop.end(); + if ( callback ) { + promise.then( callback.bind( this ) ); + } + return promise; + }; + }( config_types, global_css, global_runloop, utils_Promise, shared_clearCache ); + + var Ractive_prototype_toHTML = function() { + return this.fragment.toString(); + }; + + var Ractive_prototype_toggle = function( keypath, callback ) { + var value; + if ( typeof keypath !== 'string' ) { + if ( this.debug ) { + throw new Error( 'Bad arguments' ); + } + return; + } + value = this.get( keypath ); + return this.set( keypath, !value, callback ); + }; + + var Ractive_prototype_update = function( runloop, Promise, clearCache, notifyDependants ) { + + return function( keypath, callback ) { + var promise, fulfilPromise; + if ( typeof keypath === 'function' ) { + callback = keypath; + keypath = ''; + } else { + keypath = keypath || ''; + } + promise = new Promise( function( fulfil ) { + fulfilPromise = fulfil; + } ); + runloop.start( this, fulfilPromise ); + clearCache( this, keypath ); + notifyDependants( this, keypath ); + runloop.end(); + this.fire( 'update', keypath ); + if ( callback ) { + promise.then( callback.bind( this ) ); + } + return promise; + }; + }( global_runloop, utils_Promise, shared_clearCache, shared_notifyDependants ); + + var Ractive_prototype_updateModel = function( getValueFromCheckboxes, arrayContentsMatch, isEqual ) { + + return function Ractive_prototype_updateModel( keypath, cascade ) { + var values, deferredCheckboxes, i; + if ( typeof keypath !== 'string' ) { + keypath = ''; + cascade = true; + } + consolidateChangedValues( this, keypath, values = {}, deferredCheckboxes = [], cascade ); + if ( i = deferredCheckboxes.length ) { + while ( i-- ) { + keypath = deferredCheckboxes[ i ]; + values[ keypath ] = getValueFromCheckboxes( this, keypath ); + } + } + this.set( values ); + }; + + function consolidateChangedValues( ractive, keypath, values, deferredCheckboxes, cascade ) { + var bindings, childDeps, i, binding, oldValue, newValue; + bindings = ractive._twowayBindings[ keypath ]; + if ( bindings ) { + i = bindings.length; + while ( i-- ) { + binding = bindings[ i ]; + // special case - radio name bindings + if ( binding.radioName && !binding.node.checked ) { + continue; + } + // special case - checkbox name bindings + if ( binding.checkboxName ) { + if ( binding.changed() && deferredCheckboxes[ keypath ] !== true ) { + // we will need to see which checkboxes with the same name are checked, + // but we only want to do so once + deferredCheckboxes[ keypath ] = true; + // for quick lookup without indexOf + deferredCheckboxes.push( keypath ); + } + continue; + } + oldValue = binding.attr.value; + newValue = binding.value(); + if ( arrayContentsMatch( oldValue, newValue ) ) { + continue; + } + if ( !isEqual( oldValue, newValue ) ) { + values[ keypath ] = newValue; + } + } + } + if ( !cascade ) { + return; + } + // cascade + childDeps = ractive._depsMap[ keypath ]; + if ( childDeps ) { + i = childDeps.length; + while ( i-- ) { + consolidateChangedValues( ractive, childDeps[ i ], values, deferredCheckboxes, cascade ); + } + } + } + }( shared_getValueFromCheckboxes, utils_arrayContentsMatch, utils_isEqual ); + + var Ractive_prototype__prototype = function( add, animate, detach, find, findAll, findAllComponents, findComponent, fire, get, insert, merge, observe, off, on, render, renderHTML, reset, set, subtract, teardown, toHTML, toggle, update, updateModel ) { + + return { + add: add, + animate: animate, + detach: detach, + find: find, + findAll: findAll, + findAllComponents: findAllComponents, + findComponent: findComponent, + fire: fire, + get: get, + insert: insert, + merge: merge, + observe: observe, + off: off, + on: on, + render: render, + renderHTML: renderHTML, + reset: reset, + set: set, + subtract: subtract, + teardown: teardown, + toHTML: toHTML, + toggle: toggle, + update: update, + updateModel: updateModel + }; + }( Ractive_prototype_add, Ractive_prototype_animate__animate, Ractive_prototype_detach, Ractive_prototype_find, Ractive_prototype_findAll, Ractive_prototype_findAllComponents, Ractive_prototype_findComponent, Ractive_prototype_fire, Ractive_prototype_get, Ractive_prototype_insert, Ractive_prototype_merge__merge, Ractive_prototype_observe__observe, Ractive_prototype_off, Ractive_prototype_on, Ractive_prototype_render, Ractive_prototype_renderHTML, Ractive_prototype_reset, Ractive_prototype_set, Ractive_prototype_subtract, Ractive_prototype_teardown, Ractive_prototype_toHTML, Ractive_prototype_toggle, Ractive_prototype_update, Ractive_prototype_updateModel ); + + var registries_components = {}; + + // These are a subset of the easing equations found at + // https://raw.github.com/danro/easing-js - license info + // follows: + // -------------------------------------------------- + // easing.js v0.5.4 + // Generic set of easing functions with AMD support + // https://github.com/danro/easing-js + // This code may be freely distributed under the MIT license + // http://danro.mit-license.org/ + // -------------------------------------------------- + // All functions adapted from Thomas Fuchs & Jeremy Kahn + // Easing Equations (c) 2003 Robert Penner, BSD license + // https://raw.github.com/danro/easing-js/master/LICENSE + // -------------------------------------------------- + // In that library, the functions named easeIn, easeOut, and + // easeInOut below are named easeInCubic, easeOutCubic, and + // (you guessed it) easeInOutCubic. + // + // You can add additional easing functions to this list, and they + // will be globally available. + var registries_easing = { + linear: function( pos ) { + return pos; + }, + easeIn: function( pos ) { + return Math.pow( pos, 3 ); + }, + easeOut: function( pos ) { + return Math.pow( pos - 1, 3 ) + 1; + }, + easeInOut: function( pos ) { + if ( ( pos /= 0.5 ) < 1 ) { + return 0.5 * Math.pow( pos, 3 ); + } + return 0.5 * ( Math.pow( pos - 2, 3 ) + 2 ); + } + }; + + var utils_getGuid = function() { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace( /[xy]/g, function( c ) { + var r, v; + r = Math.random() * 16 | 0; + v = c == 'x' ? r : r & 3 | 8; + return v.toString( 16 ); + } ); + }; + + var utils_extend = function( target ) { + var prop, source, sources = Array.prototype.slice.call( arguments, 1 ); + while ( source = sources.shift() ) { + for ( prop in source ) { + if ( source.hasOwnProperty( prop ) ) { + target[ prop ] = source[ prop ]; + } + } + } + return target; + }; + + var config_registries = [ + 'adaptors', + 'components', + 'decorators', + 'easing', + 'events', + 'interpolators', + 'partials', + 'transitions', + 'data' + ]; + + var extend_utils_transformCss = function() { + + var selectorsPattern = /(?:^|\})?\s*([^\{\}]+)\s*\{/g, + commentsPattern = /\/\*.*?\*\//g, + selectorUnitPattern = /((?:(?:\[[^\]+]\])|(?:[^\s\+\>\~:]))+)((?::[^\s\+\>\~]+)?\s*[\s\+\>\~]?)\s*/g; + return function transformCss( css, guid ) { + var transformed, addGuid; + addGuid = function( selector ) { + var selectorUnits, match, unit, dataAttr, base, prepended, appended, i, transformed = []; + selectorUnits = []; + while ( match = selectorUnitPattern.exec( selector ) ) { + selectorUnits.push( { + str: match[ 0 ], + base: match[ 1 ], + modifiers: match[ 2 ] + } ); + } + // For each simple selector within the selector, we need to create a version + // that a) combines with the guid, and b) is inside the guid + dataAttr = '[data-rvcguid="' + guid + '"]'; + base = selectorUnits.map( extractString ); + i = selectorUnits.length; + while ( i-- ) { + appended = base.slice(); + // Pseudo-selectors should go after the attribute selector + unit = selectorUnits[ i ]; + appended[ i ] = unit.base + dataAttr + unit.modifiers || ''; + prepended = base.slice(); + prepended[ i ] = dataAttr + ' ' + prepended[ i ]; + transformed.push( appended.join( ' ' ), prepended.join( ' ' ) ); + } + return transformed.join( ', ' ); + }; + transformed = css.replace( commentsPattern, '' ).replace( selectorsPattern, function( match, $1 ) { + var selectors, transformed; + selectors = $1.split( ',' ).map( trim ); + transformed = selectors.map( addGuid ).join( ', ' ) + ' '; + return match.replace( $1, transformed ); + } ); + return transformed; + }; + + function trim( str ) { + if ( str.trim ) { + return str.trim(); + } + return str.replace( /^\s+/, '' ).replace( /\s+$/, '' ); + } + + function extractString( unit ) { + return unit.str; + } + }(); + + var extend_inheritFromParent = function( registries, create, defineProperty, transformCss ) { + + // This is where we inherit class-level options, such as `modifyArrays` + // or `append` or `twoway`, and registries such as `partials` + return function( Child, Parent ) { + registries.forEach( function( property ) { + if ( Parent[ property ] ) { + Child[ property ] = create( Parent[ property ] ); + } + } ); + defineProperty( Child, 'defaults', { + value: create( Parent.defaults ) + } ); + // Special case - CSS + if ( Parent.css ) { + defineProperty( Child, 'css', { + value: Parent.defaults.noCssTransform ? Parent.css : transformCss( Parent.css, Child._guid ) + } ); + } + }; + }( config_registries, utils_create, utils_defineProperty, extend_utils_transformCss ); + + var extend_wrapMethod = function( method, superMethod ) { + if ( /_super/.test( method ) ) { + return function() { + var _super = this._super, + result; + this._super = superMethod; + result = method.apply( this, arguments ); + this._super = _super; + return result; + }; + } else { + return method; + } + }; + + var extend_utils_augment = function( target, source ) { + var key; + for ( key in source ) { + if ( source.hasOwnProperty( key ) ) { + target[ key ] = source[ key ]; + } + } + return target; + }; + + var extend_inheritFromChildProps = function( initOptions, registries, defineProperty, wrapMethod, augment, transformCss ) { + + var blacklisted = {}; + registries.concat( initOptions.keys ).forEach( function( property ) { + blacklisted[ property ] = true; + } ); + // This is where we augment the class-level options (inherited from + // Parent) with the values passed to Parent.extend() + return function( Child, childProps ) { + var key, member; + registries.forEach( function( property ) { + var value = childProps[ property ]; + if ( value ) { + if ( Child[ property ] ) { + augment( Child[ property ], value ); + } else { + Child[ property ] = value; + } + } + } ); + initOptions.keys.forEach( function( key ) { + var value = childProps[ key ]; + if ( value !== undefined ) { + // we may need to wrap a function (e.g. the `complete` option) + if ( typeof value === 'function' && typeof Child[ key ] === 'function' ) { + Child.defaults[ key ] = wrapMethod( value, Child[ key ] ); + } else { + Child.defaults[ key ] = childProps[ key ]; + } + } + } ); + for ( key in childProps ) { + if ( !blacklisted[ key ] && childProps.hasOwnProperty( key ) ) { + member = childProps[ key ]; + // if this is a method that overwrites a prototype method, we may need + // to wrap it + if ( typeof member === 'function' && typeof Child.prototype[ key ] === 'function' ) { + Child.prototype[ key ] = wrapMethod( member, Child.prototype[ key ] ); + } else { + Child.prototype[ key ] = member; + } + } + } + // Special case - CSS + if ( childProps.css ) { + defineProperty( Child, 'css', { + value: Child.defaults.noCssTransform ? childProps.css : transformCss( childProps.css, Child._guid ) + } ); + } + }; + }( config_initOptions, config_registries, utils_defineProperty, extend_wrapMethod, extend_utils_augment, extend_utils_transformCss ); + + var extend_extractInlinePartials = function( isObject, augment ) { + + return function( Child, childProps ) { + // does our template contain inline partials? + if ( isObject( Child.defaults.template ) ) { + if ( !Child.partials ) { + Child.partials = {}; + } + // get those inline partials + augment( Child.partials, Child.defaults.template.partials ); + // but we also need to ensure that any explicit partials override inline ones + if ( childProps.partials ) { + augment( Child.partials, childProps.partials ); + } + // move template to where it belongs + Child.defaults.template = Child.defaults.template.main; + } + }; + }( utils_isObject, extend_utils_augment ); + + var extend_conditionallyParseTemplate = function( errors, isClient, parse ) { + + return function( Child ) { + var templateEl; + if ( typeof Child.defaults.template === 'string' ) { + if ( !parse ) { + throw new Error( errors.missingParser ); + } + if ( Child.defaults.template.charAt( 0 ) === '#' && isClient ) { + templateEl = document.getElementById( Child.defaults.template.substring( 1 ) ); + if ( templateEl && templateEl.tagName === 'SCRIPT' ) { + Child.defaults.template = parse( templateEl.innerHTML, Child ); + } else { + throw new Error( 'Could not find template element (' + Child.defaults.template + ')' ); + } + } else { + Child.defaults.template = parse( Child.defaults.template, Child.defaults ); + } + } + }; + }( config_errors, config_isClient, parse__parse ); + + var extend_conditionallyParsePartials = function( errors, parse ) { + + return function( Child ) { + var key; + // Parse partials, if necessary + if ( Child.partials ) { + for ( key in Child.partials ) { + if ( Child.partials.hasOwnProperty( key ) && typeof Child.partials[ key ] === 'string' ) { + if ( !parse ) { + throw new Error( errors.missingParser ); + } + Child.partials[ key ] = parse( Child.partials[ key ], Child ); + } + } + } + }; + }( config_errors, parse__parse ); + + var Ractive_initialise_computations_getComputationSignature = function() { + + var pattern = /\$\{([^\}]+)\}/g; + return function( signature ) { + if ( typeof signature === 'function' ) { + return { + get: signature + }; + } + if ( typeof signature === 'string' ) { + return { + get: createFunctionFromString( signature ) + }; + } + if ( typeof signature === 'object' && typeof signature.get === 'string' ) { + signature = { + get: createFunctionFromString( signature.get ), + set: signature.set + }; + } + return signature; + }; + + function createFunctionFromString( signature ) { + var functionBody = 'var __ractive=this;return(' + signature.replace( pattern, function( match, keypath ) { + return '__ractive.get("' + keypath + '")'; + } ) + ')'; + return new Function( functionBody ); + } + }(); + + var Ractive_initialise_computations_Watcher = function( isEqual, registerDependant, unregisterDependant ) { + + var Watcher = function( computation, keypath ) { + this.root = computation.ractive; + this.keypath = keypath; + this.priority = 0; + this.computation = computation; + registerDependant( this ); + }; + Watcher.prototype = { + update: function() { + var value; + value = this.root.get( this.keypath ); + if ( !isEqual( value, this.value ) ) { + this.computation.bubble(); + } + }, + teardown: function() { + unregisterDependant( this ); + } + }; + return Watcher; + }( utils_isEqual, shared_registerDependant, shared_unregisterDependant ); + + var Ractive_initialise_computations_Computation = function( warn, runloop, set, Watcher ) { + + var Computation = function( ractive, key, signature ) { + this.ractive = ractive; + this.key = key; + this.getter = signature.get; + this.setter = signature.set; + this.watchers = []; + this.update(); + }; + Computation.prototype = { + set: function( value ) { + if ( this.setting ) { + this.value = value; + return; + } + if ( !this.setter ) { + throw new Error( 'Computed properties without setters are read-only in the current version' ); + } + this.setter.call( this.ractive, value ); + }, + update: function() { + var ractive, originalCaptured, result, errored; + ractive = this.ractive; + originalCaptured = ractive._captured; + if ( !originalCaptured ) { + ractive._captured = []; + } + try { + result = this.getter.call( ractive ); + } catch ( err ) { + if ( ractive.debug ) { + warn( 'Failed to compute "' + this.key + '": ' + err.message || err ); + } + errored = true; + } + diff( this, this.watchers, ractive._captured ); + // reset + ractive._captured = originalCaptured; + if ( !errored ) { + this.setting = true; + this.value = result; + set( ractive, this.key, result ); + this.setting = false; + } + this.deferred = false; + }, + bubble: function() { + if ( this.watchers.length <= 1 ) { + this.update(); + } else if ( !this.deferred ) { + runloop.addComputation( this ); + this.deferred = true; + } + } + }; + + function diff( computation, watchers, newDependencies ) { + var i, watcher, keypath; + // remove dependencies that are no longer used + i = watchers.length; + while ( i-- ) { + watcher = watchers[ i ]; + if ( !newDependencies[ watcher.keypath ] ) { + watchers.splice( i, 1 ); + watchers[ watcher.keypath ] = null; + watcher.teardown(); + } + } + // create references for any new dependencies + i = newDependencies.length; + while ( i-- ) { + keypath = newDependencies[ i ]; + if ( !watchers[ keypath ] ) { + watcher = new Watcher( computation, keypath ); + watchers.push( watchers[ keypath ] = watcher ); + } + } + } + return Computation; + }( utils_warn, global_runloop, shared_set, Ractive_initialise_computations_Watcher ); + + var Ractive_initialise_computations_createComputations = function( getComputationSignature, Computation ) { + + return function createComputations( ractive, computed ) { + var key, signature; + for ( key in computed ) { + signature = getComputationSignature( computed[ key ] ); + ractive._computations[ key ] = new Computation( ractive, key, signature ); + } + }; + }( Ractive_initialise_computations_getComputationSignature, Ractive_initialise_computations_Computation ); + + var Ractive_initialise = function( isClient, errors, initOptions, registries, warn, create, extend, fillGaps, defineProperties, getElement, isObject, isArray, getGuid, Promise, magicAdaptor, parse, createComputations ) { + + var flags = [ + 'adapt', + 'modifyArrays', + 'magic', + 'twoway', + 'lazy', + 'debug', + 'isolated' + ]; + return function initialiseRactiveInstance( ractive, options ) { + var defaults, template, templateEl, parsedTemplate, promise, fulfilPromise, computed; + if ( isArray( options.adaptors ) ) { + warn( 'The `adaptors` option, to indicate which adaptors should be used with a given Ractive instance, has been deprecated in favour of `adapt`. See [TODO] for more information' ); + options.adapt = options.adaptors; + delete options.adaptors; + } + // Options + // ------- + defaults = ractive.constructor.defaults; + initOptions.keys.forEach( function( key ) { + if ( options[ key ] === undefined ) { + options[ key ] = defaults[ key ]; + } + } ); + // options + flags.forEach( function( flag ) { + ractive[ flag ] = options[ flag ]; + } ); + // special cases + if ( typeof ractive.adapt === 'string' ) { + ractive.adapt = [ ractive.adapt ]; + } + if ( ractive.magic && !magicAdaptor ) { + throw new Error( 'Getters and setters (magic mode) are not supported in this browser' ); + } + // Initialisation + // -------------- + // We use Object.defineProperties (where possible) as these should be read-only + defineProperties( ractive, { + _initing: { + value: true, + writable: true + }, + // Generate a unique identifier, for places where you'd use a weak map if it + // existed + _guid: { + value: getGuid() + }, + // events + _subs: { + value: create( null ), + configurable: true + }, + // cache + _cache: { + value: {} + }, + // we need to be able to use hasOwnProperty, so can't inherit from null + _cacheMap: { + value: create( null ) + }, + // dependency graph + _deps: { + value: [] + }, + _depsMap: { + value: create( null ) + }, + _patternObservers: { + value: [] + }, + // Keep a list of used evaluators, so we don't duplicate them + _evaluators: { + value: create( null ) + }, + // Computed properties + _computations: { + value: create( null ) + }, + // two-way bindings + _twowayBindings: { + value: {} + }, + // animations (so we can stop any in progress at teardown) + _animations: { + value: [] + }, + // nodes registry + nodes: { + value: {} + }, + // property wrappers + _wrapped: { + value: create( null ) + }, + // live queries + _liveQueries: { + value: [] + }, + _liveComponentQueries: { + value: [] + }, + // components to init at the end of a mutation + _childInitQueue: { + value: [] + }, + // data changes + _changes: { + value: [] + }, + // failed lookups, when we try to access data from ancestor scopes + _unresolvedImplicitDependencies: { + value: [] + } + } ); + // If this is a component, store a reference to the parent + if ( options._parent && options._component ) { + defineProperties( ractive, { + _parent: { + value: options._parent + }, + component: { + value: options._component + } + } ); + // And store a reference to the instance on the component + options._component.instance = ractive; + } + if ( options.el ) { + ractive.el = getElement( options.el ); + if ( !ractive.el && ractive.debug ) { + throw new Error( 'Could not find container element' ); + } + } + // Create local registry objects, with the global registries as prototypes + if ( options.eventDefinitions ) { + // TODO remove support + warn( 'ractive.eventDefinitions has been deprecated in favour of ractive.events. Support will be removed in future versions' ); + options.events = options.eventDefinitions; + } + registries.forEach( function( registry ) { + if ( ractive.constructor[ registry ] ) { + ractive[ registry ] = extend( create( ractive.constructor[ registry ] ), options[ registry ] ); + } else if ( options[ registry ] ) { + ractive[ registry ] = options[ registry ]; + } + } ); + // Special case + if ( !ractive.data ) { + ractive.data = {}; + } + // Set up any computed values + computed = defaults.computed ? extend( create( defaults.computed ), options.computed ) : options.computed; + if ( computed ) { + createComputations( ractive, computed ); + } + // Parse template, if necessary + template = options.template; + if ( typeof template === 'string' ) { + if ( !parse ) { + throw new Error( errors.missingParser ); + } + if ( template.charAt( 0 ) === '#' && isClient ) { + // assume this is an ID of a + + + + + + « NAME_HERE + + + + loading individual Ractive.js source files... please wait + + + + + + + + + + +
element, preserve whitespace within + preserveWhitespace = preserveWhitespace || lowerCaseTag === 'pre' || lowerCaseTag === 'style' || lowerCaseTag === 'script'; + if ( firstToken.attrs ) { + filtered = filterAttributes( firstToken.attrs ); + attrs = filtered.attrs; + proxies = filtered.proxies; + // remove event attributes (e.g. onclick='doSomething()') if we're sanitizing + if ( parser.options.sanitize && parser.options.sanitize.eventAttributes ) { + attrs = attrs.filter( sanitize ); + } + if ( attrs.length ) { + this.attributes = attrs.map( getFrag ); + } + // Process directives (proxy events, transitions, and decorators) + if ( proxies.length ) { + this.proxies = proxies.map( processDirective ); + } + if ( filtered.intro ) { + this.intro = processDirective( filtered.intro ); + } + if ( filtered.outro ) { + this.outro = processDirective( filtered.outro ); + } + if ( filtered.decorator ) { + this.decorator = processDirective( filtered.decorator ); + } + } + if ( firstToken.doctype ) { + this.doctype = true; + } + if ( firstToken.selfClosing ) { + this.selfClosing = true; + } + if ( voidElementNames.indexOf( lowerCaseTag ) !== -1 ) { + this.isVoid = true; + } + // if self-closing or a void element, close + if ( this.selfClosing || this.isVoid ) { + return; + } + this.siblings = siblingsByTagName[ lowerCaseTag ]; + this.items = []; + next = parser.next(); + while ( next ) { + // section closing mustache should also close this element, e.g. + //
loading individual Ractive.js source files... please wait