OLD | NEW |
1 { | 1 { |
2 "version": 3, | 2 "version": 3, |
3 "file": "platform.concat.js", | 3 "file": "platform.concat.js", |
4 "sources": [ | 4 "sources": [ |
5 "../WeakMap/weakmap.js", | 5 "../WeakMap/weakmap.js", |
6 "../observe-js/src/observe.js", | 6 "../observe-js/src/observe.js", |
7 "build/if-poly.js", | 7 "build/if-poly.js", |
8 "../ShadowDOM/src/wrappers.js", | 8 "../ShadowDOM/src/wrappers.js", |
9 "../ShadowDOM/src/microtask.js", | 9 "../ShadowDOM/src/microtask.js", |
10 "../ShadowDOM/src/MutationObserver.js", | 10 "../ShadowDOM/src/MutationObserver.js", |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 "/*\n * Copyright 2013 The Polymer Authors. All rights reserved.\n * Use of
this source code is governed by a BSD-style\n * license that can be found in the
LICENSE file.\n */\n\n/*\n * Basic strategy: find the farthest apart points, us
e as diameter of circle\n * react to size change and rotation of the chord\n */\
n\n/**\n * @module PointerGestures\n * @submodule Events\n * @class pinch\n */\n
/**\n * Scale of the pinch zoom gesture\n * @property scale\n * @type Number\n *
/\n/**\n * Center X position of pointers causing pinch\n * @property centerX\n *
@type Number\n */\n/**\n * Center Y position of pointers causing pinch\n * @pro
perty centerY\n * @type Number\n */\n\n/**\n * @module PointerGestures\n * @subm
odule Events\n * @class rotate\n */\n/**\n * Angle (in degrees) of rotation. Mea
sured from starting positions of pointers.\n * @property angle\n * @type Number\
n */\n/**\n * Center X position of pointers causing rotation\n * @property cente
rX\n * @type Number\n */\n/**\n * Center Y position of pointers causing rotation
\n * @property centerY\n * @type Number\n */\n(function(scope) {\n var dispatch
er = scope.dispatcher;\n var pointermap = new scope.PointerMap();\n var RAD_TO
_DEG = 180 / Math.PI;\n var pinch = {\n events: [\n 'pointerdown',\n
'pointermove',\n 'pointerup',\n 'pointercancel'\n ],\n refere
nce: {},\n pointerdown: function(ev) {\n pointermap.set(ev.pointerId, ev
);\n if (pointermap.pointers() == 2) {\n var points = this.calcChord
();\n var angle = this.calcAngle(points);\n this.reference = {\n
angle: angle,\n diameter: points.diameter,\n target: s
cope.findLCA(points.a.target, points.b.target)\n };\n }\n },\n
pointerup: function(ev) {\n pointermap.delete(ev.pointerId);\n },\n
pointermove: function(ev) {\n if (pointermap.has(ev.pointerId)) {\n
pointermap.set(ev.pointerId, ev);\n if (pointermap.pointers() > 1) {\n
this.calcPinchRotate();\n }\n }\n },\n pointercancel: f
unction(ev) {\n this.pointerup(ev);\n },\n dispatchPinch: function(di
ameter, points) {\n var zoom = diameter / this.reference.diameter;\n v
ar ev = dispatcher.makeEvent('pinch', {\n scale: zoom,\n centerX:
points.center.x,\n centerY: points.center.y\n });\n dispatcher.
dispatchEvent(ev, this.reference.target);\n },\n dispatchRotate: function(
angle, points) {\n var diff = Math.round((angle - this.reference.angle) % 3
60);\n var ev = dispatcher.makeEvent('rotate', {\n angle: diff,\n
centerX: points.center.x,\n centerY: points.center.y\n });\n
dispatcher.dispatchEvent(ev, this.reference.target);\n },\n calcPinchRo
tate: function() {\n var points = this.calcChord();\n var diameter = p
oints.diameter;\n var angle = this.calcAngle(points);\n if (diameter !
= this.reference.diameter) {\n this.dispatchPinch(diameter, points);\n
}\n if (angle != this.reference.angle) {\n this.dispatchRotate(an
gle, points);\n }\n },\n calcChord: function() {\n var pointers
= [];\n pointermap.forEach(function(p) {\n pointers.push(p);\n
});\n var dist = 0;\n // start with at least two pointers\n var p
oints = {a: pointers[0], b: pointers[1]};\n var x, y, d;\n for (var i
= 0; i < pointers.length; i++) {\n var a = pointers[i];\n for (var
j = i + 1; j < pointers.length; j++) {\n var b = pointers[j];\n
x = Math.abs(a.clientX - b.clientX);\n y = Math.abs(a.clientY - b.cl
ientY);\n d = x + y;\n if (d > dist) {\n dist = d;\
n points = {a: a, b: b};\n }\n }\n }\n x =
Math.abs(points.a.clientX + points.b.clientX) / 2;\n y = Math.abs(points.a.
clientY + points.b.clientY) / 2;\n points.center = { x: x, y: y };\n p
oints.diameter = dist;\n return points;\n },\n calcAngle: function(po
ints) {\n var x = points.a.clientX - points.b.clientX;\n var y = point
s.a.clientY - points.b.clientY;\n return (360 + Math.atan2(y, x) * RAD_TO_D
EG) % 360;\n },\n };\n dispatcher.registerRecognizer('pinch', pinch);\n})(w
indow.PointerGestures);\n", | 201 "/*\n * Copyright 2013 The Polymer Authors. All rights reserved.\n * Use of
this source code is governed by a BSD-style\n * license that can be found in the
LICENSE file.\n */\n\n/*\n * Basic strategy: find the farthest apart points, us
e as diameter of circle\n * react to size change and rotation of the chord\n */\
n\n/**\n * @module PointerGestures\n * @submodule Events\n * @class pinch\n */\n
/**\n * Scale of the pinch zoom gesture\n * @property scale\n * @type Number\n *
/\n/**\n * Center X position of pointers causing pinch\n * @property centerX\n *
@type Number\n */\n/**\n * Center Y position of pointers causing pinch\n * @pro
perty centerY\n * @type Number\n */\n\n/**\n * @module PointerGestures\n * @subm
odule Events\n * @class rotate\n */\n/**\n * Angle (in degrees) of rotation. Mea
sured from starting positions of pointers.\n * @property angle\n * @type Number\
n */\n/**\n * Center X position of pointers causing rotation\n * @property cente
rX\n * @type Number\n */\n/**\n * Center Y position of pointers causing rotation
\n * @property centerY\n * @type Number\n */\n(function(scope) {\n var dispatch
er = scope.dispatcher;\n var pointermap = new scope.PointerMap();\n var RAD_TO
_DEG = 180 / Math.PI;\n var pinch = {\n events: [\n 'pointerdown',\n
'pointermove',\n 'pointerup',\n 'pointercancel'\n ],\n refere
nce: {},\n pointerdown: function(ev) {\n pointermap.set(ev.pointerId, ev
);\n if (pointermap.pointers() == 2) {\n var points = this.calcChord
();\n var angle = this.calcAngle(points);\n this.reference = {\n
angle: angle,\n diameter: points.diameter,\n target: s
cope.findLCA(points.a.target, points.b.target)\n };\n }\n },\n
pointerup: function(ev) {\n pointermap.delete(ev.pointerId);\n },\n
pointermove: function(ev) {\n if (pointermap.has(ev.pointerId)) {\n
pointermap.set(ev.pointerId, ev);\n if (pointermap.pointers() > 1) {\n
this.calcPinchRotate();\n }\n }\n },\n pointercancel: f
unction(ev) {\n this.pointerup(ev);\n },\n dispatchPinch: function(di
ameter, points) {\n var zoom = diameter / this.reference.diameter;\n v
ar ev = dispatcher.makeEvent('pinch', {\n scale: zoom,\n centerX:
points.center.x,\n centerY: points.center.y\n });\n dispatcher.
dispatchEvent(ev, this.reference.target);\n },\n dispatchRotate: function(
angle, points) {\n var diff = Math.round((angle - this.reference.angle) % 3
60);\n var ev = dispatcher.makeEvent('rotate', {\n angle: diff,\n
centerX: points.center.x,\n centerY: points.center.y\n });\n
dispatcher.dispatchEvent(ev, this.reference.target);\n },\n calcPinchRo
tate: function() {\n var points = this.calcChord();\n var diameter = p
oints.diameter;\n var angle = this.calcAngle(points);\n if (diameter !
= this.reference.diameter) {\n this.dispatchPinch(diameter, points);\n
}\n if (angle != this.reference.angle) {\n this.dispatchRotate(an
gle, points);\n }\n },\n calcChord: function() {\n var pointers
= [];\n pointermap.forEach(function(p) {\n pointers.push(p);\n
});\n var dist = 0;\n // start with at least two pointers\n var p
oints = {a: pointers[0], b: pointers[1]};\n var x, y, d;\n for (var i
= 0; i < pointers.length; i++) {\n var a = pointers[i];\n for (var
j = i + 1; j < pointers.length; j++) {\n var b = pointers[j];\n
x = Math.abs(a.clientX - b.clientX);\n y = Math.abs(a.clientY - b.cl
ientY);\n d = x + y;\n if (d > dist) {\n dist = d;\
n points = {a: a, b: b};\n }\n }\n }\n x =
Math.abs(points.a.clientX + points.b.clientX) / 2;\n y = Math.abs(points.a.
clientY + points.b.clientY) / 2;\n points.center = { x: x, y: y };\n p
oints.diameter = dist;\n return points;\n },\n calcAngle: function(po
ints) {\n var x = points.a.clientX - points.b.clientX;\n var y = point
s.a.clientY - points.b.clientY;\n return (360 + Math.atan2(y, x) * RAD_TO_D
EG) % 360;\n },\n };\n dispatcher.registerRecognizer('pinch', pinch);\n})(w
indow.PointerGestures);\n", |
202 "/*\n * Copyright 2013 The Polymer Authors. All rights reserved.\n * Use of
this source code is governed by a BSD-style\n * license that can be found in the
LICENSE file.\n */\n\n/**\n * This event is fired when a pointer quickly goes d
own and up, and is used to\n * denote activation.\n *\n * Any gesture event can
prevent the tap event from being created by calling\n * `event.preventTap`.\n *\
n * Any pointer event can prevent the tap by setting the `tapPrevented` property
\n * on itself.\n *\n * @module PointerGestures\n * @submodule Events\n * @class
tap\n */\n/**\n * X axis position of the tap.\n * @property x\n * @type Number\
n */\n/**\n * Y axis position of the tap.\n * @property y\n * @type Number\n */\
n/**\n * Type of the pointer that made the tap.\n * @property pointerType\n * @t
ype String\n */\n(function(scope) {\n var dispatcher = scope.dispatcher;\n var
pointermap = new scope.PointerMap();\n var tap = {\n events: [\n 'poin
terdown',\n 'pointermove',\n 'pointerup',\n 'pointercancel',\n
'keyup'\n ],\n pointerdown: function(inEvent) {\n if (inEvent.isPr
imary && !inEvent.tapPrevented) {\n pointermap.set(inEvent.pointerId, {\n
target: inEvent.target,\n buttons: inEvent.buttons,\n
x: inEvent.clientX,\n y: inEvent.clientY\n });\n }\n }
,\n pointermove: function(inEvent) {\n if (inEvent.isPrimary) {\n
var start = pointermap.get(inEvent.pointerId);\n if (start) {\n
if (inEvent.tapPrevented) {\n pointermap.delete(inEvent.pointerId);\
n }\n }\n }\n },\n shouldTap: function(e, downState)
{\n if (!e.tapPrevented) {\n if (e.pointerType === 'mouse') {\n
// only allow left click to tap for mouse\n return downState.butto
ns === 1;\n } else {\n return true;\n }\n }\n },\
n pointerup: function(inEvent) {\n var start = pointermap.get(inEvent.po
interId);\n if (start && this.shouldTap(inEvent, start)) {\n var t =
scope.findLCA(start.target, inEvent.target);\n if (t) {\n var e
= dispatcher.makeEvent('tap', {\n x: inEvent.clientX,\n y
: inEvent.clientY,\n detail: inEvent.detail,\n pointerType
: inEvent.pointerType\n });\n dispatcher.dispatchEvent(e, t);\
n }\n }\n pointermap.delete(inEvent.pointerId);\n },\n po
intercancel: function(inEvent) {\n pointermap.delete(inEvent.pointerId);\n
},\n keyup: function(inEvent) {\n var code = inEvent.keyCode;\n
// 32 == spacebar\n if (code === 32) {\n var t = inEvent.target;\n
if (!(t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement))
{\n dispatcher.dispatchEvent(dispatcher.makeEvent('tap', {\n
x: 0,\n y: 0,\n detail: 0,\n pointerType: 'una
vailable'\n }), t);\n }\n }\n },\n preventTap: functi
on(inPointerId) {\n pointermap.delete(inPointerId);\n }\n };\n dispatc
her.registerRecognizer('tap', tap);\n})(window.PointerGestures);\n", | 202 "/*\n * Copyright 2013 The Polymer Authors. All rights reserved.\n * Use of
this source code is governed by a BSD-style\n * license that can be found in the
LICENSE file.\n */\n\n/**\n * This event is fired when a pointer quickly goes d
own and up, and is used to\n * denote activation.\n *\n * Any gesture event can
prevent the tap event from being created by calling\n * `event.preventTap`.\n *\
n * Any pointer event can prevent the tap by setting the `tapPrevented` property
\n * on itself.\n *\n * @module PointerGestures\n * @submodule Events\n * @class
tap\n */\n/**\n * X axis position of the tap.\n * @property x\n * @type Number\
n */\n/**\n * Y axis position of the tap.\n * @property y\n * @type Number\n */\
n/**\n * Type of the pointer that made the tap.\n * @property pointerType\n * @t
ype String\n */\n(function(scope) {\n var dispatcher = scope.dispatcher;\n var
pointermap = new scope.PointerMap();\n var tap = {\n events: [\n 'poin
terdown',\n 'pointermove',\n 'pointerup',\n 'pointercancel',\n
'keyup'\n ],\n pointerdown: function(inEvent) {\n if (inEvent.isPr
imary && !inEvent.tapPrevented) {\n pointermap.set(inEvent.pointerId, {\n
target: inEvent.target,\n buttons: inEvent.buttons,\n
x: inEvent.clientX,\n y: inEvent.clientY\n });\n }\n }
,\n pointermove: function(inEvent) {\n if (inEvent.isPrimary) {\n
var start = pointermap.get(inEvent.pointerId);\n if (start) {\n
if (inEvent.tapPrevented) {\n pointermap.delete(inEvent.pointerId);\
n }\n }\n }\n },\n shouldTap: function(e, downState)
{\n if (!e.tapPrevented) {\n if (e.pointerType === 'mouse') {\n
// only allow left click to tap for mouse\n return downState.butto
ns === 1;\n } else {\n return true;\n }\n }\n },\
n pointerup: function(inEvent) {\n var start = pointermap.get(inEvent.po
interId);\n if (start && this.shouldTap(inEvent, start)) {\n var t =
scope.findLCA(start.target, inEvent.target);\n if (t) {\n var e
= dispatcher.makeEvent('tap', {\n x: inEvent.clientX,\n y
: inEvent.clientY,\n detail: inEvent.detail,\n pointerType
: inEvent.pointerType\n });\n dispatcher.dispatchEvent(e, t);\
n }\n }\n pointermap.delete(inEvent.pointerId);\n },\n po
intercancel: function(inEvent) {\n pointermap.delete(inEvent.pointerId);\n
},\n keyup: function(inEvent) {\n var code = inEvent.keyCode;\n
// 32 == spacebar\n if (code === 32) {\n var t = inEvent.target;\n
if (!(t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement))
{\n dispatcher.dispatchEvent(dispatcher.makeEvent('tap', {\n
x: 0,\n y: 0,\n detail: 0,\n pointerType: 'una
vailable'\n }), t);\n }\n }\n },\n preventTap: functi
on(inPointerId) {\n pointermap.delete(inPointerId);\n }\n };\n dispatc
her.registerRecognizer('tap', tap);\n})(window.PointerGestures);\n", |
203 "/*\n * Copyright 2014 The Polymer Authors. All rights reserved.\n * Use of
this source code is governed by a BSD-style\n * license that can be found in the
LICENSE file.\n */\n\n/**\n * Because recognizers are loaded after dispatcher,
we have to wait to register\n * scopes until after all the recognizers.\n */\n(f
unction(scope) {\n var dispatcher = scope.dispatcher;\n function registerScope
s() {\n dispatcher.immediateRegister = true;\n var rq = dispatcher.registe
rQueue;\n rq.forEach(scope.register);\n rq.length = 0;\n }\n if (documen
t.readyState === 'complete') {\n registerScopes();\n } else {\n // regist
er scopes after a steadystate is reached\n // less MutationObserver churn\n
document.addEventListener('readystatechange', function() {\n if (document
.readyState === 'complete') {\n registerScopes();\n }\n });\n }\
n})(window.PointerGestures);\n", | 203 "/*\n * Copyright 2014 The Polymer Authors. All rights reserved.\n * Use of
this source code is governed by a BSD-style\n * license that can be found in the
LICENSE file.\n */\n\n/**\n * Because recognizers are loaded after dispatcher,
we have to wait to register\n * scopes until after all the recognizers.\n */\n(f
unction(scope) {\n var dispatcher = scope.dispatcher;\n function registerScope
s() {\n dispatcher.immediateRegister = true;\n var rq = dispatcher.registe
rQueue;\n rq.forEach(scope.register);\n rq.length = 0;\n }\n if (documen
t.readyState === 'complete') {\n registerScopes();\n } else {\n // regist
er scopes after a steadystate is reached\n // less MutationObserver churn\n
document.addEventListener('readystatechange', function() {\n if (document
.readyState === 'complete') {\n registerScopes();\n }\n });\n }\
n})(window.PointerGestures);\n", |
204 "// Copyright (c) 2014 The Polymer Project Authors. All rights reserved.\n//
This code may only be used under the BSD style license found at http://polymer.
github.io/LICENSE.txt\n// The complete set of authors may be found at http://pol
ymer.github.io/AUTHORS.txt\n// The complete set of contributors may be found at
http://polymer.github.io/CONTRIBUTORS.txt\n// Code distributed by Google as part
of the polymer project is also\n// subject to an additional IP rights grant fou
nd at http://polymer.github.io/PATENTS.txt\n\n(function(global) {\n 'use strict
';\n\n var filter = Array.prototype.filter.call.bind(Array.prototype.filter);\n
\n function getTreeScope(node) {\n while (node.parentNode) {\n node = n
ode.parentNode;\n }\n\n return typeof node.getElementById === 'function' ?
node : null;\n }\n\n Node.prototype.bind = function(name, observable) {\n
console.error('Unhandled binding to Node: ', this, name, observable);\n };\n\n
function updateBindings(node, name, binding) {\n var bindings = node.binding
s_;\n if (!bindings)\n bindings = node.bindings_ = {};\n\n if (bindin
gs[name])\n binding[name].close();\n\n return bindings[name] = binding;\
n }\n\n function returnBinding(node, name, binding) {\n return binding;\n
}\n\n function sanitizeValue(value) {\n return value == null ? '' : value;\n
}\n\n function updateText(node, value) {\n node.data = sanitizeValue(value
);\n }\n\n function textBinding(node) {\n return function(value) {\n r
eturn updateText(node, value);\n };\n }\n\n var maybeUpdateBindings = retur
nBinding;\n\n Object.defineProperty(Platform, 'enableBindingsReflection', {\n
get: function() {\n return maybeUpdateBindings === updateBindings;\n }
,\n set: function(enable) {\n maybeUpdateBindings = enable ? updateBindi
ngs : returnBinding;\n return enable;\n },\n configurable: true\n })
;\n\n Text.prototype.bind = function(name, value, oneTime) {\n if (name !==
'textContent')\n return Node.prototype.bind.call(this, name, value, oneTime
);\n\n if (oneTime)\n return updateText(this, value);\n\n var observa
ble = value;\n updateText(this, observable.open(textBinding(this)));\n ret
urn maybeUpdateBindings(this, name, observable);\n }\n\n function updateAttrib
ute(el, name, conditional, value) {\n if (conditional) {\n if (value)\n
el.setAttribute(name, '');\n else\n el.removeAttribute(name);
\n return;\n }\n\n el.setAttribute(name, sanitizeValue(value));\n }\
n\n function attributeBinding(el, name, conditional) {\n return function(val
ue) {\n updateAttribute(el, name, conditional, value);\n };\n }\n\n El
ement.prototype.bind = function(name, value, oneTime) {\n var conditional = n
ame[name.length - 1] == '?';\n if (conditional) {\n this.removeAttribute
(name);\n name = name.slice(0, -1);\n }\n\n if (oneTime)\n retur
n updateAttribute(this, name, conditional, value);\n\n\n var observable = val
ue;\n updateAttribute(this, name, conditional,\n observable.open(attri
buteBinding(this, name, conditional)));\n\n return maybeUpdateBindings(this,
name, observable);\n };\n\n var checkboxEventType;\n (function() {\n // At
tempt to feature-detect which event (change or click) is fired first\n // for
checkboxes.\n var div = document.createElement('div');\n var checkbox = d
iv.appendChild(document.createElement('input'));\n checkbox.setAttribute('typ
e', 'checkbox');\n var first;\n var count = 0;\n checkbox.addEventListe
ner('click', function(e) {\n count++;\n first = first || 'click';\n
});\n checkbox.addEventListener('change', function() {\n count++;\n
first = first || 'change';\n });\n\n var event = document.createEvent('M
ouseEvent');\n event.initMouseEvent(\"click\", true, true, window, 0, 0, 0, 0
, 0, false,\n false, false, false, 0, null);\n checkbox.dispatchEvent(
event);\n // WebKit/Blink don't fire the change event if the element is outsi
de the\n // document, so assume 'change' for that case.\n checkboxEventTyp
e = count == 1 ? 'change' : first;\n })();\n\n function getEventForInputType(e
lement) {\n switch (element.type) {\n case 'checkbox':\n return c
heckboxEventType;\n case 'radio':\n case 'select-multiple':\n cas
e 'select-one':\n return 'change';\n case 'range':\n if (/Tri
dent|MSIE/.test(navigator.userAgent))\n return 'change';\n default
:\n return 'input';\n }\n }\n\n function updateInput(input, property
, value, santizeFn) {\n input[property] = (santizeFn || sanitizeValue)(value)
;\n }\n\n function inputBinding(input, property, santizeFn) {\n return func
tion(value) {\n return updateInput(input, property, value, santizeFn);\n
}\n }\n\n function noop() {}\n\n function bindInputEvent(input, property, ob
servable, postEventFn) {\n var eventType = getEventForInputType(input);\n\n
function eventHandler() {\n observable.setValue(input[property]);\n
observable.discardChanges();\n (postEventFn || noop)(input);\n Platfor
m.performMicrotaskCheckpoint();\n }\n input.addEventListener(eventType, ev
entHandler);\n\n return {\n close: function() {\n input.removeEve
ntListener(eventType, eventHandler);\n observable.close();\n },\n\n
observable_: observable\n }\n }\n\n function booleanSanitize(value) {\
n return Boolean(value);\n }\n\n // |element| is assumed to be an HTMLInput
Element with |type| == 'radio'.\n // Returns an array containing all radio butt
ons other than |element| that\n // have the same |name|, either in the form tha
t |element| belongs to or,\n // if no form, in the document tree to which |elem
ent| belongs.\n //\n // This implementation is based upon the HTML spec defini
tion of a\n // \"radio button group\":\n // http://www.whatwg.org/specs/web-
apps/current-work/multipage/number-state.html#radio-button-group\n //\n functi
on getAssociatedRadioButtons(element) {\n if (element.form) {\n return f
ilter(element.form.elements, function(el) {\n return el != element &&\n
el.tagName == 'INPUT' &&\n el.type == 'radio' &&\n
el.name == element.name;\n });\n } else {\n var treeScope = getT
reeScope(element);\n if (!treeScope)\n return [];\n var radios
= treeScope.querySelectorAll(\n 'input[type=\"radio\"][name=\"' + eleme
nt.name + '\"]');\n return filter(radios, function(el) {\n return el
!= element && !el.form;\n });\n }\n }\n\n function checkedPostEvent(i
nput) {\n // Only the radio button that is getting checked gets an event. We\
n // therefore find all the associated radio buttons and update their\n //
check binding manually.\n if (input.tagName === 'INPUT' &&\n input.ty
pe === 'radio') {\n getAssociatedRadioButtons(input).forEach(function(radio
) {\n var checkedBinding = radio.bindings_.checked;\n if (checkedB
inding) {\n // Set the value directly to avoid an infinite call stack.\
n checkedBinding.observable_.setValue(false);\n }\n });\n
}\n }\n\n HTMLInputElement.prototype.bind = function(name, value, oneTime) {
\n if (name !== 'value' && name !== 'checked')\n return HTMLElement.prot
otype.bind.call(this, name, value, oneTime);\n\n this.removeAttribute(name);\
n var sanitizeFn = name == 'checked' ? booleanSanitize : sanitizeValue;\n
var postEventFn = name == 'checked' ? checkedPostEvent : noop;\n\n if (oneTim
e)\n return updateInput(this, name, value, sanitizeFn);\n\n\n var observ
able = value;\n var binding = bindInputEvent(this, name, observable, postEven
tFn);\n updateInput(this, name,\n observable.open(inputBinding
(this, name, sanitizeFn)),\n sanitizeFn);\n\n // Checkboxes ma
y need to update bindings of other checkboxes.\n return updateBindings(this,
name, binding);\n }\n\n HTMLTextAreaElement.prototype.bind = function(name, va
lue, oneTime) {\n if (name !== 'value')\n return HTMLElement.prototype.b
ind.call(this, name, value, oneTime);\n\n this.removeAttribute('value');\n\n
if (oneTime)\n return updateInput(this, 'value', value);\n\n var obse
rvable = value;\n var binding = bindInputEvent(this, 'value', observable);\n
updateInput(this, 'value',\n observable.open(inputBinding(this
, 'value', sanitizeValue)));\n return maybeUpdateBindings(this, name, binding
);\n }\n\n function updateOption(option, value) {\n var parentNode = option
.parentNode;;\n var select;\n var selectBinding;\n var oldValue;\n i
f (parentNode instanceof HTMLSelectElement &&\n parentNode.bindings_ &&\n
parentNode.bindings_.value) {\n select = parentNode;\n selectB
inding = select.bindings_.value;\n oldValue = select.value;\n }\n\n o
ption.value = sanitizeValue(value);\n\n if (select && select.value != oldValu
e) {\n selectBinding.observable_.setValue(select.value);\n selectBindi
ng.observable_.discardChanges();\n Platform.performMicrotaskCheckpoint();\n
}\n }\n\n function optionBinding(option) {\n return function(value) {\n
updateOption(option, value);\n }\n }\n\n HTMLOptionElement.prototype.
bind = function(name, value, oneTime) {\n if (name !== 'value')\n return
HTMLElement.prototype.bind.call(this, name, value, oneTime);\n\n this.remove
Attribute('value');\n\n if (oneTime)\n return updateOption(this, value);
\n\n var observable = value;\n var binding = bindInputEvent(this, 'value',
observable);\n updateOption(this, observable.open(optionBinding(this)));\n
return maybeUpdateBindings(this, name, binding);\n }\n\n HTMLSelectElement.p
rototype.bind = function(name, value, oneTime) {\n if (name === 'selectedinde
x')\n name = 'selectedIndex';\n\n if (name !== 'selectedIndex' && name !
== 'value')\n return HTMLElement.prototype.bind.call(this, name, value, one
Time);\n\n this.removeAttribute(name);\n\n if (oneTime)\n return upda
teInput(this, name, value);\n\n var observable = value;\n var binding = bi
ndInputEvent(this, name, observable);\n updateInput(this, name,\n
observable.open(inputBinding(this, name)));\n\n // Option update events m
ay need to access select bindings.\n return updateBindings(this, name, bindin
g);\n }\n})(this);\n", | 204 "// Copyright (c) 2014 The Polymer Project Authors. All rights reserved.\n//
This code may only be used under the BSD style license found at http://polymer.
github.io/LICENSE.txt\n// The complete set of authors may be found at http://pol
ymer.github.io/AUTHORS.txt\n// The complete set of contributors may be found at
http://polymer.github.io/CONTRIBUTORS.txt\n// Code distributed by Google as part
of the polymer project is also\n// subject to an additional IP rights grant fou
nd at http://polymer.github.io/PATENTS.txt\n\n(function(global) {\n 'use strict
';\n\n var filter = Array.prototype.filter.call.bind(Array.prototype.filter);\n
\n function getTreeScope(node) {\n while (node.parentNode) {\n node = n
ode.parentNode;\n }\n\n return typeof node.getElementById === 'function' ?
node : null;\n }\n\n Node.prototype.bind = function(name, observable) {\n
console.error('Unhandled binding to Node: ', this, name, observable);\n };\n\n
function updateBindings(node, name, binding) {\n var bindings = node.binding
s_;\n if (!bindings)\n bindings = node.bindings_ = {};\n\n if (bindin
gs[name])\n binding[name].close();\n\n return bindings[name] = binding;\
n }\n\n function returnBinding(node, name, binding) {\n return binding;\n
}\n\n function sanitizeValue(value) {\n return value == null ? '' : value;\n
}\n\n function updateText(node, value) {\n node.data = sanitizeValue(value
);\n }\n\n function textBinding(node) {\n return function(value) {\n r
eturn updateText(node, value);\n };\n }\n\n var maybeUpdateBindings = retur
nBinding;\n\n Object.defineProperty(Platform, 'enableBindingsReflection', {\n
get: function() {\n return maybeUpdateBindings === updateBindings;\n }
,\n set: function(enable) {\n maybeUpdateBindings = enable ? updateBindi
ngs : returnBinding;\n return enable;\n },\n configurable: true\n })
;\n\n Text.prototype.bind = function(name, value, oneTime) {\n if (name !==
'textContent')\n return Node.prototype.bind.call(this, name, value, oneTime
);\n\n if (oneTime)\n return updateText(this, value);\n\n var observa
ble = value;\n updateText(this, observable.open(textBinding(this)));\n ret
urn maybeUpdateBindings(this, name, observable);\n }\n\n function updateAttrib
ute(el, name, conditional, value) {\n if (conditional) {\n if (value)\n
el.setAttribute(name, '');\n else\n el.removeAttribute(name);
\n return;\n }\n\n el.setAttribute(name, sanitizeValue(value));\n }\
n\n function attributeBinding(el, name, conditional) {\n return function(val
ue) {\n updateAttribute(el, name, conditional, value);\n };\n }\n\n El
ement.prototype.bind = function(name, value, oneTime) {\n var conditional = n
ame[name.length - 1] == '?';\n if (conditional) {\n this.removeAttribute
(name);\n name = name.slice(0, -1);\n }\n\n if (oneTime)\n retur
n updateAttribute(this, name, conditional, value);\n\n\n var observable = val
ue;\n updateAttribute(this, name, conditional,\n observable.open(attri
buteBinding(this, name, conditional)));\n\n return maybeUpdateBindings(this,
name, observable);\n };\n\n var checkboxEventType;\n (function() {\n // At
tempt to feature-detect which event (change or click) is fired first\n // for
checkboxes.\n var div = document.createElement('div');\n var checkbox = d
iv.appendChild(document.createElement('input'));\n checkbox.setAttribute('typ
e', 'checkbox');\n var first;\n var count = 0;\n checkbox.addEventListe
ner('click', function(e) {\n count++;\n first = first || 'click';\n
});\n checkbox.addEventListener('change', function() {\n count++;\n
first = first || 'change';\n });\n\n var event = document.createEvent('M
ouseEvent');\n event.initMouseEvent(\"click\", true, true, window, 0, 0, 0, 0
, 0, false,\n false, false, false, 0, null);\n checkbox.dispatchEvent(
event);\n // WebKit/Blink don't fire the change event if the element is outsi
de the\n // document, so assume 'change' for that case.\n checkboxEventTyp
e = count == 1 ? 'change' : first;\n })();\n\n function getEventForInputType(e
lement) {\n switch (element.type) {\n case 'checkbox':\n return c
heckboxEventType;\n case 'radio':\n case 'select-multiple':\n cas
e 'select-one':\n return 'change';\n case 'range':\n if (/Tri
dent|MSIE/.test(navigator.userAgent))\n return 'change';\n default
:\n return 'input';\n }\n }\n\n function updateInput(input, property
, value, santizeFn) {\n input[property] = (santizeFn || sanitizeValue)(value)
;\n }\n\n function inputBinding(input, property, santizeFn) {\n return func
tion(value) {\n return updateInput(input, property, value, santizeFn);\n
}\n }\n\n function noop() {}\n\n function bindInputEvent(input, property, ob
servable, postEventFn) {\n var eventType = getEventForInputType(input);\n\n
function eventHandler() {\n observable.setValue(input[property]);\n
observable.discardChanges();\n (postEventFn || noop)(input);\n Platfor
m.performMicrotaskCheckpoint();\n }\n input.addEventListener(eventType, ev
entHandler);\n\n return {\n close: function() {\n input.removeEve
ntListener(eventType, eventHandler);\n observable.close();\n },\n\n
observable_: observable\n }\n }\n\n function booleanSanitize(value) {\
n return Boolean(value);\n }\n\n // |element| is assumed to be an HTMLInput
Element with |type| == 'radio'.\n // Returns an array containing all radio butt
ons other than |element| that\n // have the same |name|, either in the form tha
t |element| belongs to or,\n // if no form, in the document tree to which |elem
ent| belongs.\n //\n // This implementation is based upon the HTML spec defini
tion of a\n // \"radio button group\":\n // http://www.whatwg.org/specs/web-
apps/current-work/multipage/number-state.html#radio-button-group\n //\n functi
on getAssociatedRadioButtons(element) {\n if (element.form) {\n return f
ilter(element.form.elements, function(el) {\n return el != element &&\n
el.tagName == 'INPUT' &&\n el.type == 'radio' &&\n
el.name == element.name;\n });\n } else {\n var treeScope = getT
reeScope(element);\n if (!treeScope)\n return [];\n var radios
= treeScope.querySelectorAll(\n 'input[type=\"radio\"][name=\"' + eleme
nt.name + '\"]');\n return filter(radios, function(el) {\n return el
!= element && !el.form;\n });\n }\n }\n\n function checkedPostEvent(i
nput) {\n // Only the radio button that is getting checked gets an event. We\
n // therefore find all the associated radio buttons and update their\n //
check binding manually.\n if (input.tagName === 'INPUT' &&\n input.ty
pe === 'radio') {\n getAssociatedRadioButtons(input).forEach(function(radio
) {\n var checkedBinding = radio.bindings_.checked;\n if (checkedB
inding) {\n // Set the value directly to avoid an infinite call stack.\
n checkedBinding.observable_.setValue(false);\n }\n });\n
}\n }\n\n HTMLInputElement.prototype.bind = function(name, value, oneTime) {
\n if (name !== 'value' && name !== 'checked')\n return HTMLElement.prot
otype.bind.call(this, name, value, oneTime);\n\n this.removeAttribute(name);\
n var sanitizeFn = name == 'checked' ? booleanSanitize : sanitizeValue;\n
var postEventFn = name == 'checked' ? checkedPostEvent : noop;\n\n if (oneTim
e)\n return updateInput(this, name, value, sanitizeFn);\n\n\n var observ
able = value;\n var binding = bindInputEvent(this, name, observable, postEven
tFn);\n updateInput(this, name,\n observable.open(inputBinding
(this, name, sanitizeFn)),\n sanitizeFn);\n\n // Checkboxes ma
y need to update bindings of other checkboxes.\n return updateBindings(this,
name, binding);\n }\n\n HTMLTextAreaElement.prototype.bind = function(name, va
lue, oneTime) {\n if (name !== 'value')\n return HTMLElement.prototype.b
ind.call(this, name, value, oneTime);\n\n this.removeAttribute('value');\n\n
if (oneTime)\n return updateInput(this, 'value', value);\n\n var obse
rvable = value;\n var binding = bindInputEvent(this, 'value', observable);\n
updateInput(this, 'value',\n observable.open(inputBinding(this
, 'value', sanitizeValue)));\n return maybeUpdateBindings(this, name, binding
);\n }\n\n function updateOption(option, value) {\n var parentNode = option
.parentNode;;\n var select;\n var selectBinding;\n var oldValue;\n i
f (parentNode instanceof HTMLSelectElement &&\n parentNode.bindings_ &&\n
parentNode.bindings_.value) {\n select = parentNode;\n selectB
inding = select.bindings_.value;\n oldValue = select.value;\n }\n\n o
ption.value = sanitizeValue(value);\n\n if (select && select.value != oldValu
e) {\n selectBinding.observable_.setValue(select.value);\n selectBindi
ng.observable_.discardChanges();\n Platform.performMicrotaskCheckpoint();\n
}\n }\n\n function optionBinding(option) {\n return function(value) {\n
updateOption(option, value);\n }\n }\n\n HTMLOptionElement.prototype.
bind = function(name, value, oneTime) {\n if (name !== 'value')\n return
HTMLElement.prototype.bind.call(this, name, value, oneTime);\n\n this.remove
Attribute('value');\n\n if (oneTime)\n return updateOption(this, value);
\n\n var observable = value;\n var binding = bindInputEvent(this, 'value',
observable);\n updateOption(this, observable.open(optionBinding(this)));\n
return maybeUpdateBindings(this, name, binding);\n }\n\n HTMLSelectElement.p
rototype.bind = function(name, value, oneTime) {\n if (name === 'selectedinde
x')\n name = 'selectedIndex';\n\n if (name !== 'selectedIndex' && name !
== 'value')\n return HTMLElement.prototype.bind.call(this, name, value, one
Time);\n\n this.removeAttribute(name);\n\n if (oneTime)\n return upda
teInput(this, name, value);\n\n var observable = value;\n var binding = bi
ndInputEvent(this, name, observable);\n updateInput(this, name,\n
observable.open(inputBinding(this, name)));\n\n // Option update events m
ay need to access select bindings.\n return updateBindings(this, name, bindin
g);\n }\n})(this);\n", |
205 "// Copyright (c) 2014 The Polymer Project Authors. All rights reserved.\n//
This code may only be used under the BSD style license found at http://polymer.
github.io/LICENSE.txt\n// The complete set of authors may be found at http://pol
ymer.github.io/AUTHORS.txt\n// The complete set of contributors may be found at
http://polymer.github.io/CONTRIBUTORS.txt\n// Code distributed by Google as part
of the polymer project is also\n// subject to an additional IP rights grant fou
nd at http://polymer.github.io/PATENTS.txt\n\n(function(global) {\n 'use strict
';\n\n function assert(v) {\n if (!v)\n throw new Error('Assertion fail
ed');\n }\n\n var forEach = Array.prototype.forEach.call.bind(Array.prototype.
forEach);\n\n function getFragmentRoot(node) {\n var p;\n while (p = node
.parentNode) {\n node = p;\n }\n\n return node;\n }\n\n function se
archRefId(node, id) {\n if (!id)\n return;\n\n var ref;\n var sele
ctor = '#' + id;\n while (!ref) {\n node = getFragmentRoot(node);\n\n
if (node.protoContent_)\n ref = node.protoContent_.querySelector(selec
tor);\n else if (node.getElementById)\n ref = node.getElementById(id
);\n\n if (ref || !node.templateCreator_)\n break\n\n node = no
de.templateCreator_;\n }\n\n return ref;\n }\n\n function getInstanceRoo
t(node) {\n while (node.parentNode) {\n node = node.parentNode;\n }\n
return node.templateCreator_ ? node : null;\n }\n\n var Map;\n if (global
.Map && typeof global.Map.prototype.forEach === 'function') {\n Map = global.
Map;\n } else {\n Map = function() {\n this.keys = [];\n this.valu
es = [];\n };\n\n Map.prototype = {\n set: function(key, value) {\n
var index = this.keys.indexOf(key);\n if (index < 0) {\n t
his.keys.push(key);\n this.values.push(value);\n } else {\n
this.values[index] = value;\n }\n },\n\n get: function(key
) {\n var index = this.keys.indexOf(key);\n if (index < 0)\n
return;\n\n return this.values[index];\n },\n\n delete: fun
ction(key, value) {\n var index = this.keys.indexOf(key);\n if (in
dex < 0)\n return false;\n\n this.keys.splice(index, 1);\n
this.values.splice(index, 1);\n return true;\n },\n\n forEach
: function(f, opt_this) {\n for (var i = 0; i < this.keys.length; i++)\n
f.call(opt_this || this, this.values[i], this.keys[i], this);\n }\
n };\n }\n\n // JScript does not have __proto__. We wrap all object literal
s with\n // createObject which uses Object.create, Object.defineProperty and\n
// Object.getOwnPropertyDescriptor to create a new object that does the exact\n
// same thing. The main downside to this solution is that we have to extract\n
// all those property descriptors for IE.\n var createObject = ('__proto__' i
n {}) ?\n function(obj) { return obj; } :\n function(obj) {\n v
ar proto = obj.__proto__;\n if (!proto)\n return obj;\n v
ar newObject = Object.create(proto);\n Object.getOwnPropertyNames(obj).fo
rEach(function(name) {\n Object.defineProperty(newObject, name,\n
Object.getOwnPropertyDescriptor(obj, name));\n }
);\n return newObject;\n };\n\n // IE does not support have Documen
t.prototype.contains.\n if (typeof document.contains != 'function') {\n Docu
ment.prototype.contains = function(node) {\n if (node === this || node.pare
ntNode === this)\n return true;\n return this.documentElement.contai
ns(node);\n }\n }\n\n var BIND = 'bind';\n var REPEAT = 'repeat';\n var I
F = 'if';\n\n var templateAttributeDirectives = {\n 'template': true,\n '
repeat': true,\n 'bind': true,\n 'ref': true\n };\n\n var semanticTempla
teElements = {\n 'THEAD': true,\n 'TBODY': true,\n 'TFOOT': true,\n
'TH': true,\n 'TR': true,\n 'TD': true,\n 'COLGROUP': true,\n 'COL':
true,\n 'CAPTION': true,\n 'OPTION': true,\n 'OPTGROUP': true\n };\n\
n var hasTemplateElement = typeof HTMLTemplateElement !== 'undefined';\n if (h
asTemplateElement) {\n // TODO(rafaelw): Remove when fix for\n // https://
codereview.chromium.org/164803002/\n // makes it to Chrome release.\n (fun
ction() {\n var t = document.createElement('template');\n var d = t.co
ntent.ownerDocument;\n var html = d.appendChild(d.createElement('html'));\n
var head = html.appendChild(d.createElement('head'));\n var base = d.
createElement('base');\n base.href = document.baseURI;\n head.appendCh
ild(base);\n })();\n }\n\n var allTemplatesSelectors = 'template, ' +\n
Object.keys(semanticTemplateElements).map(function(tagName) {\n return
tagName.toLowerCase() + '[template]';\n }).join(', ');\n\n function isSVGT
emplate(el) {\n return el.tagName == 'template' &&\n el.namespaceUR
I == 'http://www.w3.org/2000/svg';\n }\n\n function isHTMLTemplate(el) {\n
return el.tagName == 'TEMPLATE' &&\n el.namespaceURI == 'http://www.w3
.org/1999/xhtml';\n }\n\n function isAttributeTemplate(el) {\n return Boole
an(semanticTemplateElements[el.tagName] &&\n el.hasAttribute('
template'));\n }\n\n function isTemplate(el) {\n if (el.isTemplate_ === und
efined)\n el.isTemplate_ = el.tagName == 'TEMPLATE' || isAttributeTemplate(
el);\n\n return el.isTemplate_;\n }\n\n // FIXME: Observe templates being a
dded/removed from documents\n // FIXME: Expose imperative API to decorate and o
bserve templates in\n // \"disconnected tress\" (e.g. ShadowRoot)\n document.a
ddEventListener('DOMContentLoaded', function(e) {\n bootstrapTemplatesRecursi
velyFrom(document);\n // FIXME: Is this needed? Seems like it shouldn't be.\n
Platform.performMicrotaskCheckpoint();\n }, false);\n\n function forAllTem
platesFrom(node, fn) {\n var subTemplates = node.querySelectorAll(allTemplate
sSelectors);\n\n if (isTemplate(node))\n fn(node)\n forEach(subTempla
tes, fn);\n }\n\n function bootstrapTemplatesRecursivelyFrom(node) {\n func
tion bootstrap(template) {\n if (!HTMLTemplateElement.decorate(template))\n
bootstrapTemplatesRecursivelyFrom(template.content);\n }\n\n forAl
lTemplatesFrom(node, bootstrap);\n }\n\n if (!hasTemplateElement) {\n /**\n
* This represents a <template> element.\n * @constructor\n * @exten
ds {HTMLElement}\n */\n global.HTMLTemplateElement = function() {\n
throw TypeError('Illegal constructor');\n };\n }\n\n var hasProto = '__prot
o__' in {};\n\n function mixin(to, from) {\n Object.getOwnPropertyNames(from
).forEach(function(name) {\n Object.defineProperty(to, name,\n
Object.getOwnPropertyDescriptor(from, name));\n });\n }\n\n
// http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/templates/index.html#df
n-template-contents-owner\n function getOrCreateTemplateContentsOwner(template)
{\n var doc = template.ownerDocument\n if (!doc.defaultView)\n retur
n doc;\n var d = doc.templateContentsOwner_;\n if (!d) {\n // TODO(ar
v): This should either be a Document or HTMLDocument depending\n // on doc.
\n d = doc.implementation.createHTMLDocument('');\n while (d.lastChild
) {\n d.removeChild(d.lastChild);\n }\n doc.templateContentsOwn
er_ = d;\n }\n return d;\n }\n\n function getTemplateStagingDocument(tem
plate) {\n if (!template.stagingDocument_) {\n var owner = template.owne
rDocument;\n if (!owner.stagingDocument_) {\n owner.stagingDocument_
= owner.implementation.createHTMLDocument('');\n\n // TODO(rafaelw): Rem
ove when fix for\n // https://codereview.chromium.org/164803002/\n
// makes it to Chrome release.\n var base = owner.stagingDocument_.creat
eElement('base');\n base.href = document.baseURI;\n owner.stagingD
ocument_.head.appendChild(base);\n\n owner.stagingDocument_.stagingDocume
nt_ = owner.stagingDocument_;\n }\n\n template.stagingDocument_ = owne
r.stagingDocument_;\n }\n\n return template.stagingDocument_;\n }\n\n //
For non-template browsers, the parser will disallow <template> in certain\n //
locations, so we allow \"attribute templates\" which combine the template\n //
element with the top-level container node of the content, e.g.\n //\n // <t
r template repeat=\"{{ foo }}\"\" class=\"bar\"><td>Bar</td></tr>\n //\n // be
comes\n //\n // <template repeat=\"{{ foo }}\">\n // + #document-fragment
\n // + <tr class=\"bar\">\n // + <td>Bar</td>\n //\n function ext
ractTemplateFromAttributeTemplate(el) {\n var template = el.ownerDocument.cre
ateElement('template');\n el.parentNode.insertBefore(template, el);\n\n va
r attribs = el.attributes;\n var count = attribs.length;\n while (count--
> 0) {\n var attrib = attribs[count];\n if (templateAttributeDirective
s[attrib.name]) {\n if (attrib.name !== 'template')\n template.s
etAttribute(attrib.name, attrib.value);\n el.removeAttribute(attrib.name)
;\n }\n }\n\n return template;\n }\n\n function extractTemplateFrom
SVGTemplate(el) {\n var template = el.ownerDocument.createElement('template')
;\n el.parentNode.insertBefore(template, el);\n\n var attribs = el.attribu
tes;\n var count = attribs.length;\n while (count-- > 0) {\n var attr
ib = attribs[count];\n template.setAttribute(attrib.name, attrib.value);\n
el.removeAttribute(attrib.name);\n }\n\n el.parentNode.removeChild(el
);\n return template;\n }\n\n function liftNonNativeTemplateChildrenIntoCon
tent(template, el, useRoot) {\n var content = template.content;\n if (useR
oot) {\n content.appendChild(el);\n return;\n }\n\n var child;\n
while (child = el.firstChild) {\n content.appendChild(child);\n }\n
}\n\n var templateObserver;\n if (typeof MutationObserver == 'function') {\n
templateObserver = new MutationObserver(function(records) {\n for (var i
= 0; i < records.length; i++) {\n records[i].target.refChanged_();\n
}\n });\n }\n\n /**\n * Ensures proper API and content model for templa
te elements.\n * @param {HTMLTemplateElement} opt_instanceRef The template ele
ment which\n * |el| template element will return as the value of its ref()
, and whose\n * content will be used as source when createInstance() is in
voked.\n */\n HTMLTemplateElement.decorate = function(el, opt_instanceRef) {\
n if (el.templateIsDecorated_)\n return false;\n\n var templateElemen
t = el;\n templateElement.templateIsDecorated_ = true;\n\n var isNativeHTM
LTemplate = isHTMLTemplate(templateElement) &&\n h
asTemplateElement;\n var bootstrapContents = isNativeHTMLTemplate;\n var l
iftContents = !isNativeHTMLTemplate;\n var liftRoot = false;\n\n if (!isNa
tiveHTMLTemplate) {\n if (isAttributeTemplate(templateElement)) {\n
assert(!opt_instanceRef);\n templateElement = extractTemplateFromAttribut
eTemplate(el);\n templateElement.templateIsDecorated_ = true;\n is
NativeHTMLTemplate = hasTemplateElement;\n liftRoot = true;\n } else
if (isSVGTemplate(templateElement)) {\n templateElement = extractTemplat
eFromSVGTemplate(el);\n templateElement.templateIsDecorated_ = true;\n
isNativeHTMLTemplate = hasTemplateElement;\n }\n }\n\n if (!isNa
tiveHTMLTemplate) {\n fixTemplateElementPrototype(templateElement);\n
var doc = getOrCreateTemplateContentsOwner(templateElement);\n templateElem
ent.content_ = doc.createDocumentFragment();\n }\n\n if (opt_instanceRef)
{\n // template is contained within an instance, its direct content must be
\n // empty\n templateElement.instanceRef_ = opt_instanceRef;\n } e
lse if (liftContents) {\n liftNonNativeTemplateChildrenIntoContent(template
Element,\n el,\n
liftRoot);\n } else if (bootstrapContents) {\n
bootstrapTemplatesRecursivelyFrom(templateElement.content);\n }\n\n re
turn true;\n };\n\n // TODO(rafaelw): This used to decorate recursively all te
mplates from a given\n // node. This happens by default on 'DOMContentLoaded',
but may be needed\n // in subtrees not descendent from document (e.g. ShadowRoo
t).\n // Review whether this is the right public API.\n HTMLTemplateElement.bo
otstrap = bootstrapTemplatesRecursivelyFrom;\n\n var htmlElement = global.HTMLU
nknownElement || HTMLElement;\n\n var contentDescriptor = {\n get: function(
) {\n return this.content_;\n },\n enumerable: true,\n configurabl
e: true\n };\n\n if (!hasTemplateElement) {\n // Gecko is more picky with t
he prototype than WebKit. Make sure to use the\n // same prototype as created
in the constructor.\n HTMLTemplateElement.prototype = Object.create(htmlElem
ent.prototype);\n\n Object.defineProperty(HTMLTemplateElement.prototype, 'con
tent',\n contentDescriptor);\n }\n\n function fixTemp
lateElementPrototype(el) {\n if (hasProto)\n el.__proto__ = HTMLTemplate
Element.prototype;\n else\n mixin(el, HTMLTemplateElement.prototype);\n
}\n\n function ensureSetModelScheduled(template) {\n if (!template.setModel
Fn_) {\n template.setModelFn_ = function() {\n template.setModelFnSc
heduled_ = false;\n var map = getBindings(template,\n template
.delegate_ && template.delegate_.prepareBinding);\n processBindings(templ
ate, map, template.model_);\n };\n }\n\n if (!template.setModelFnSche
duled_) {\n template.setModelFnScheduled_ = true;\n Observer.runEOM_(t
emplate.setModelFn_);\n }\n }\n\n mixin(HTMLTemplateElement.prototype, {\n
bind: function(name, value, oneTime) {\n if (name != 'ref')\n ret
urn Element.prototype.bind.call(this, name, value, oneTime);\n\n var self =
this;\n var ref = oneTime ? value : value.open(function(ref) {\n se
lf.setAttribute('ref', ref);\n self.refChanged_();\n });\n\n th
is.setAttribute('ref', ref);\n this.refChanged_();\n if (oneTime)\n
return;\n\n if (!this.bindings_) {\n this.bindings_ = { ref: va
lue };\n } else {\n this.bindings_.ref = value;\n }\n\n re
turn value;\n },\n\n processBindingDirectives_: function(directives) {\n
if (this.iterator_)\n this.iterator_.closeDeps();\n\n if (!direc
tives.if && !directives.bind && !directives.repeat) {\n if (this.iterator
_) {\n this.iterator_.close();\n this.iterator_ = undefined;\n
}\n\n return;\n }\n\n if (!this.iterator_) {\n t
his.iterator_ = new TemplateIterator(this);\n }\n\n this.iterator_.upd
ateDependencies(directives, this.model_);\n\n if (templateObserver) {\n
templateObserver.observe(this, { attributes: true,\n
attributeFilter: ['ref'] });\n }\n\n return this.iter
ator_;\n },\n\n createInstance: function(model, bindingDelegate, delegate_
) {\n if (bindingDelegate)\n delegate_ = this.newDelegate_(bindingDe
legate);\n\n if (!this.refContent_)\n this.refContent_ = this.ref_.c
ontent;\n var content = this.refContent_;\n if (content.firstChild ===
null)\n return emptyInstance;\n\n var map = this.bindingMap_;\n
if (!map || map.content !== content) {\n // TODO(rafaelw): Setup a Muta
tionObserver on content to detect\n // when the instanceMap is invalid.\n
map = createInstanceBindingMap(content,\n delegate_ && delega
te_.prepareBinding) || [];\n map.content = content;\n this.binding
Map_ = map;\n }\n\n var stagingDocument = getTemplateStagingDocument(t
his);\n var instance = stagingDocument.createDocumentFragment();\n ins
tance.templateCreator_ = this;\n instance.protoContent_ = content;\n i
nstance.bindings_ = [];\n instance.terminator_ = null;\n var instanceR
ecord = instance.templateInstance_ = {\n firstNode: null,\n lastNo
de: null,\n model: model\n };\n\n var i = 0;\n var collect
Terminator = false;\n for (var child = content.firstChild; child; child = c
hild.nextSibling) {\n // The terminator of the instance is the clone of t
he last child of the\n // content. If the last child is an active templat
e, it may produce\n // instances as a result of production, so simply col
lecting the last\n // child of the instance after it has finished produci
ng may be wrong.\n if (child.nextSibling === null)\n collectTerm
inator = true;\n\n var clone = cloneAndBindInstance(child, instance, stag
ingDocument,\n map.children[i++],\n
model,\n
delegate_,\n instance.bindings_);\n
clone.templateInstance_ = instanceRecord;\n if (collectTerminator
)\n instance.terminator_ = clone;\n }\n\n instanceRecord.firs
tNode = instance.firstChild;\n instanceRecord.lastNode = instance.lastChild
;\n instance.templateCreator_ = undefined;\n instance.protoContent_ =
undefined;\n return instance;\n },\n\n get model() {\n return th
is.model_;\n },\n\n set model(model) {\n this.model_ = model;\n
ensureSetModelScheduled(this);\n },\n\n get bindingDelegate() {\n ret
urn this.delegate_ && this.delegate_.raw;\n },\n\n refChanged_: function()
{\n if (!this.iterator_ || this.refContent_ === this.ref_.content)\n
return;\n\n this.refContent_ = undefined;\n this.iterator_.valueChan
ged();\n this.iterator_.updateIteratedValue();\n },\n\n clear: functi
on() {\n this.model_ = undefined;\n this.delegate_ = undefined;\n
if (this.bindings_ && this.bindings_.ref)\n this.bindings_.ref.close()\n
this.refContent_ = undefined;\n if (!this.iterator_)\n return;
\n this.iterator_.valueChanged();\n this.iterator_.close()\n this
.iterator_ = undefined;\n },\n\n setDelegate_: function(delegate) {\n
this.delegate_ = delegate;\n this.bindingMap_ = undefined;\n if (this
.iterator_) {\n this.iterator_.instancePositionChangedFn_ = undefined;\n
this.iterator_.instanceModelFn_ = undefined;\n }\n },\n\n newD
elegate_: function(bindingDelegate) {\n if (!bindingDelegate)\n retu
rn {};\n\n function delegateFn(name) {\n var fn = bindingDelegate &&
bindingDelegate[name];\n if (typeof fn != 'function')\n return;
\n\n return function() {\n return fn.apply(bindingDelegate, argu
ments);\n };\n }\n\n return {\n raw: bindingDelegate,\n
prepareBinding: delegateFn('prepareBinding'),\n prepareInstanceMod
el: delegateFn('prepareInstanceModel'),\n prepareInstancePositionChanged:
\n delegateFn('prepareInstancePositionChanged')\n };\n },\n\n
// TODO(rafaelw): Assigning .bindingDelegate always succeeds. It may\n //
make sense to issue a warning or even throw if the template is already\n //
\"activated\", since this would be a strange thing to do.\n set bindingDelega
te(bindingDelegate) {\n if (this.delegate_) {\n throw Error('Templat
e must be cleared before a new bindingDelegate ' +\n 'can be
assigned');\n }\n\n this.setDelegate_(this.newDelegate_(bindingDelegat
e));\n },\n\n get ref_() {\n var ref = searchRefId(this, this.getAttr
ibute('ref'));\n if (!ref)\n ref = this.instanceRef_;\n\n if (!
ref)\n return this;\n\n var nextRef = ref.ref_;\n return nextRe
f ? nextRef : ref;\n }\n });\n\n // Returns\n // a) undefined if there a
re no mustaches.\n // b) [TEXT, (ONE_TIME?, PATH, DELEGATE_FN, TEXT)+] if the
re is at least one mustache.\n function parseMustaches(s, name, node, prepareBi
ndingFn) {\n if (!s || !s.length)\n return;\n\n var tokens;\n var
length = s.length;\n var startIndex = 0, lastIndex = 0, endIndex = 0;\n va
r onlyOneTime = true;\n while (lastIndex < length) {\n var startIndex =
s.indexOf('{{', lastIndex);\n var oneTimeStart = s.indexOf('[[', lastIndex)
;\n var oneTime = false;\n var terminator = '}}';\n\n if (oneTime
Start >= 0 &&\n (startIndex < 0 || oneTimeStart < startIndex)) {\n
startIndex = oneTimeStart;\n oneTime = true;\n terminator = ']]
';\n }\n\n endIndex = startIndex < 0 ? -1 : s.indexOf(terminator, star
tIndex + 2);\n\n if (endIndex < 0) {\n if (!tokens)\n retur
n;\n\n tokens.push(s.slice(lastIndex)); // TEXT\n break;\n }\
n\n tokens = tokens || [];\n tokens.push(s.slice(lastIndex, startIndex
)); // TEXT\n var pathString = s.slice(startIndex + 2, endIndex).trim();\n
tokens.push(oneTime); // ONE_TIME?\n onlyOneTime = onlyOneTime && oneT
ime;\n var delegateFn = prepareBindingFn &&\n prepare
BindingFn(pathString, name, node);\n // Don't try to parse the expression i
f there's a prepareBinding function\n if (delegateFn == null) {\n to
kens.push(Path.get(pathString)); // PATH\n } else {\n tokens.push(nu
ll);\n }\n tokens.push(delegateFn); // DELEGATE_FN\n lastIndex =
endIndex + 2;\n }\n\n if (lastIndex === length)\n tokens.push(''); //
TEXT\n\n tokens.hasOnePath = tokens.length === 5;\n tokens.isSimplePath =
tokens.hasOnePath &&\n tokens[0] == '' &&\n
tokens[4] == '';\n tokens.onlyOneTime = onlyOneTime;\n\n to
kens.combinator = function(values) {\n var newValue = tokens[0];\n\n f
or (var i = 1; i < tokens.length; i += 4) {\n var value = tokens.hasOnePa
th ? values : values[(i - 1) / 4];\n if (value !== undefined)\n
newValue += value;\n newValue += tokens[i + 3];\n }\n\n return
newValue;\n }\n\n return tokens;\n };\n\n function processOneTimeBinding
(name, tokens, node, model) {\n if (tokens.hasOnePath) {\n var delegateF
n = tokens[3];\n var value = delegateFn ? delegateFn(model, node, true) :\n
tokens[2].getValueFrom(model);\n return toke
ns.isSimplePath ? value : tokens.combinator(value);\n }\n\n var values = [
];\n for (var i = 1; i < tokens.length; i += 4) {\n var delegateFn = tok
ens[i + 2];\n values[(i - 1) / 4] = delegateFn ? delegateFn(model, node) :\
n tokens[i + 1].getValueFrom(model);\n }\n\n return tokens.combin
ator(values);\n }\n\n function processSinglePathBinding(name, tokens, node, mo
del) {\n var delegateFn = tokens[3];\n var observer = delegateFn ? delegat
eFn(model, node, false) :\n new PathObserver(model, tokens[2]);\n\n re
turn tokens.isSimplePath ? observer :\n new ObserverTransform(observer, t
okens.combinator);\n }\n\n function processBinding(name, tokens, node, model)
{\n if (tokens.onlyOneTime)\n return processOneTimeBinding(name, tokens,
node, model);\n\n if (tokens.hasOnePath)\n return processSinglePathBind
ing(name, tokens, node, model);\n\n var observer = new CompoundObserver();\n\
n for (var i = 1; i < tokens.length; i += 4) {\n var oneTime = tokens[i]
;\n var delegateFn = tokens[i + 2];\n\n if (delegateFn) {\n var
value = delegateFn(model, node, oneTime);\n if (oneTime)\n obse
rver.addPath(value)\n else\n observer.addObserver(value);\n
continue;\n }\n\n var path = tokens[i + 1];\n if (oneTime)\n
observer.addPath(path.getValueFrom(model))\n else\n observer.a
ddPath(model, path);\n }\n\n return new ObserverTransform(observer, tokens
.combinator);\n }\n\n function processBindings(node, bindings, model, instance
Bindings) {\n for (var i = 0; i < bindings.length; i += 2) {\n var name
= bindings[i]\n var tokens = bindings[i + 1];\n var value = processBin
ding(name, tokens, node, model);\n var binding = node.bind(name, value, tok
ens.onlyOneTime);\n if (binding && instanceBindings)\n instanceBindi
ngs.push(binding);\n }\n\n if (!bindings.isTemplate)\n return;\n\n
node.model_ = model;\n var iter = node.processBindingDirectives_(bindings);\
n if (instanceBindings && iter)\n instanceBindings.push(iter);\n }\n\n
function parseWithDefault(el, name, prepareBindingFn) {\n var v = el.getAttr
ibute(name);\n return parseMustaches(v == '' ? '{{}}' : v, name, el, prepareB
indingFn);\n }\n\n function parseAttributeBindings(element, prepareBindingFn)
{\n assert(element);\n\n var bindings = [];\n var ifFound = false;\n
var bindFound = false;\n\n for (var i = 0; i < element.attributes.length; i+
+) {\n var attr = element.attributes[i];\n var name = attr.name;\n
var value = attr.value;\n\n // Allow bindings expressed in attributes to
be prefixed with underbars.\n // We do this to allow correct semantics for
browsers that don't implement\n // <template> where certain attributes migh
t trigger side-effects -- and\n // for IE which sanitizes certain attribute
s, disallowing mustache\n // replacements in their text.\n while (name
[0] === '_') {\n name = name.substring(1);\n }\n\n if (isTempla
te(element) &&\n (name === IF || name === BIND || name === REPEAT)) {\n
continue;\n }\n\n var tokens = parseMustaches(value, name, ele
ment,\n prepareBindingFn);\n if (!tokens)\
n continue;\n\n bindings.push(name, tokens);\n }\n\n if (isTem
plate(element)) {\n bindings.isTemplate = true;\n bindings.if = parseW
ithDefault(element, IF, prepareBindingFn);\n bindings.bind = parseWithDefau
lt(element, BIND, prepareBindingFn);\n bindings.repeat = parseWithDefault(e
lement, REPEAT, prepareBindingFn);\n\n if (bindings.if && !bindings.bind &&
!bindings.repeat)\n bindings.bind = parseMustaches('{{}}', BIND, element
, prepareBindingFn);\n }\n\n return bindings;\n }\n\n function getBindin
gs(node, prepareBindingFn) {\n if (node.nodeType === Node.ELEMENT_NODE)\n
return parseAttributeBindings(node, prepareBindingFn);\n\n if (node.nodeTyp
e === Node.TEXT_NODE) {\n var tokens = parseMustaches(node.data, 'textConte
nt', node,\n prepareBindingFn);\n if (toke
ns)\n return ['textContent', tokens];\n }\n\n return [];\n }\n\n
function cloneAndBindInstance(node, parent, stagingDocument, bindings, model,\n
delegate,\n instan
ceBindings,\n instanceRecord) {\n var clone =
parent.appendChild(stagingDocument.importNode(node, false));\n\n var i = 0;\n
for (var child = node.firstChild; child; child = child.nextSibling) {\n
cloneAndBindInstance(child, clone, stagingDocument,\n
bindings.children[i++],\n model,\n
delegate,\n instanceBindings);\n }\n\n
if (bindings.isTemplate) {\n HTMLTemplateElement.decorate(clone, node);\
n if (delegate)\n clone.setDelegate_(delegate);\n }\n\n proces
sBindings(clone, bindings, model, instanceBindings);\n return clone;\n }\n\n
function createInstanceBindingMap(node, prepareBindingFn) {\n var map = get
Bindings(node, prepareBindingFn);\n map.children = {};\n var index = 0;\n
for (var child = node.firstChild; child; child = child.nextSibling) {\n
map.children[index++] = createInstanceBindingMap(child, prepareBindingFn);\n
}\n\n return map;\n }\n\n Object.defineProperty(Node.prototype, 'templateIn
stance', {\n get: function() {\n var instance = this.templateInstance_;\
n return instance ? instance :\n (this.parentNode ? this.parentNod
e.templateInstance : undefined);\n }\n });\n\n var emptyInstance = document
.createDocumentFragment();\n emptyInstance.bindings_ = [];\n emptyInstance.ter
minator_ = null;\n\n function TemplateIterator(templateElement) {\n this.clo
sed = false;\n this.templateElement_ = templateElement;\n this.instances =
[];\n this.deps = undefined;\n this.iteratedValue = [];\n this.present
Value = undefined;\n this.arrayObserver = undefined;\n }\n\n TemplateIterat
or.prototype = {\n closeDeps: function() {\n var deps = this.deps;\n
if (deps) {\n if (deps.ifOneTime === false)\n deps.ifValue.clo
se();\n if (deps.oneTime === false)\n deps.value.close();\n
}\n },\n\n updateDependencies: function(directives, model) {\n this.
closeDeps();\n\n var deps = this.deps = {};\n var template = this.temp
lateElement_;\n\n if (directives.if) {\n deps.hasIf = true;\n
deps.ifOneTime = directives.if.onlyOneTime;\n deps.ifValue = processBind
ing(IF, directives.if, template, model);\n\n // oneTime if & predicate is
false. nothing else to do.\n if (deps.ifOneTime && !deps.ifValue) {\n
this.updateIteratedValue();\n return;\n }\n\n if (
!deps.ifOneTime)\n deps.ifValue.open(this.updateIteratedValue, this);\n
}\n\n if (directives.repeat) {\n deps.repeat = true;\n
deps.oneTime = directives.repeat.onlyOneTime;\n deps.value = processBindi
ng(REPEAT, directives.repeat, template, model);\n } else {\n deps.re
peat = false;\n deps.oneTime = directives.bind.onlyOneTime;\n deps
.value = processBinding(BIND, directives.bind, template, model);\n }\n\n
if (!deps.oneTime)\n deps.value.open(this.updateIteratedValue, this);\
n\n this.updateIteratedValue();\n },\n\n updateIteratedValue: functio
n() {\n if (this.deps.hasIf) {\n var ifValue = this.deps.ifValue;\n
if (!this.deps.ifOneTime)\n ifValue = ifValue.discardChanges();\
n if (!ifValue) {\n this.valueChanged();\n return;\n
}\n }\n\n var value = this.deps.value;\n if (!this.deps.oneT
ime)\n value = value.discardChanges();\n if (!this.deps.repeat)\n
value = [value];\n var observe = this.deps.repeat &&\n
!this.deps.oneTime &&\n Array.isArray(value);\n this
.valueChanged(value, observe);\n },\n\n valueChanged: function(value, obse
rveValue) {\n if (!Array.isArray(value))\n value = [];\n\n if (
value === this.iteratedValue)\n return;\n\n this.unobserve();\n
this.presentValue = value;\n if (observeValue) {\n this.arrayObserv
er = new ArrayObserver(this.presentValue);\n this.arrayObserver.open(this
.handleSplices, this);\n }\n\n this.handleSplices(ArrayObserver.calcul
ateSplices(this.presentValue,\n
this.iteratedValue));\n },\n\n getLastInstanceNode: function(index)
{\n if (index == -1)\n return this.templateElement_;\n var ins
tance = this.instances[index];\n var terminator = instance.terminator_;\n
if (!terminator)\n return this.getLastInstanceNode(index - 1);\n\n
if (terminator.nodeType !== Node.ELEMENT_NODE ||\n this.templateElem
ent_ === terminator) {\n return terminator;\n }\n\n var subtemp
lateIterator = terminator.iterator_;\n if (!subtemplateIterator)\n r
eturn terminator;\n\n return subtemplateIterator.getLastTemplateNode();\n
},\n\n getLastTemplateNode: function() {\n return this.getLastInstance
Node(this.instances.length - 1);\n },\n\n insertInstanceAt: function(index
, fragment) {\n var previousInstanceLast = this.getLastInstanceNode(index -
1);\n var parent = this.templateElement_.parentNode;\n this.instances
.splice(index, 0, fragment);\n\n parent.insertBefore(fragment, previousInst
anceLast.nextSibling);\n },\n\n extractInstanceAt: function(index) {\n
var previousInstanceLast = this.getLastInstanceNode(index - 1);\n var las
tNode = this.getLastInstanceNode(index);\n var parent = this.templateElemen
t_.parentNode;\n var instance = this.instances.splice(index, 1)[0];\n\n
while (lastNode !== previousInstanceLast) {\n var node = previousInstan
ceLast.nextSibling;\n if (node == lastNode)\n lastNode = previou
sInstanceLast;\n\n instance.appendChild(parent.removeChild(node));\n
}\n\n return instance;\n },\n\n getDelegateFn: function(fn) {\n
fn = fn && fn(this.templateElement_);\n return typeof fn === 'function' ?
fn : null;\n },\n\n handleSplices: function(splices) {\n if (this.clo
sed || !splices.length)\n return;\n\n var template = this.templateEl
ement_;\n\n if (!template.parentNode) {\n this.close();\n ret
urn;\n }\n\n ArrayObserver.applySplices(this.iteratedValue, this.prese
ntValue,\n splices);\n\n var delegate = tem
plate.delegate_;\n if (this.instanceModelFn_ === undefined) {\n this
.instanceModelFn_ =\n this.getDelegateFn(delegate && delegate.prepare
InstanceModel);\n }\n\n if (this.instancePositionChangedFn_ === undefi
ned) {\n this.instancePositionChangedFn_ =\n this.getDelegateF
n(delegate &&\n delegate.prepareInstancePositionCh
anged);\n }\n\n // Instance Removals\n var instanceCache = new Ma
p;\n var removeDelta = 0;\n for (var i = 0; i < splices.length; i++) {
\n var splice = splices[i];\n var removed = splice.removed;\n
for (var j = 0; j < removed.length; j++) {\n var model = removed[j];
\n var instance = this.extractInstanceAt(splice.index + removeDelta);\n
if (instance !== emptyInstance) {\n instanceCache.set(model
, instance);\n }\n }\n\n removeDelta -= splice.addedCount
;\n }\n\n // Instance Insertions\n for (var i = 0; i < splices.le
ngth; i++) {\n var splice = splices[i];\n var addIndex = splice.in
dex;\n for (; addIndex < splice.index + splice.addedCount; addIndex++) {\
n var model = this.iteratedValue[addIndex];\n var instance = i
nstanceCache.get(model);\n if (instance) {\n instanceCache.d
elete(model);\n } else {\n if (this.instanceModelFn_) {\n
model = this.instanceModelFn_(model);\n }\n\n i
f (model === undefined) {\n instance = emptyInstance;\n
} else {\n instance = template.createInstance(model, undefined, del
egate);\n }\n }\n\n this.insertInstanceAt(addIndex,
instance);\n }\n }\n\n instanceCache.forEach(function(instance
) {\n this.closeInstanceBindings(instance);\n }, this);\n\n if
(this.instancePositionChangedFn_)\n this.reportInstancesMoved(splices);\n
},\n\n reportInstanceMoved: function(index) {\n var instance = this.
instances[index];\n if (instance === emptyInstance)\n return;\n\n
this.instancePositionChangedFn_(instance.templateInstance_, index);\n },\n
\n reportInstancesMoved: function(splices) {\n var index = 0;\n var
offset = 0;\n for (var i = 0; i < splices.length; i++) {\n var spli
ce = splices[i];\n if (offset != 0) {\n while (index < splice.in
dex) {\n this.reportInstanceMoved(index);\n index++;\n
}\n } else {\n index = splice.index;\n }\n\n
while (index < splice.index + splice.addedCount) {\n this.reportInstan
ceMoved(index);\n index++;\n }\n\n offset += splice.added
Count - splice.removed.length;\n }\n\n if (offset == 0)\n retur
n;\n\n var length = this.instances.length;\n while (index < length) {\
n this.reportInstanceMoved(index);\n index++;\n }\n },\n\n
closeInstanceBindings: function(instance) {\n var bindings = instance.b
indings_;\n for (var i = 0; i < bindings.length; i++) {\n bindings[i
].close();\n }\n },\n\n unobserve: function() {\n if (!this.arra
yObserver)\n return;\n\n this.arrayObserver.close();\n this.arr
ayObserver = undefined;\n },\n\n close: function() {\n if (this.close
d)\n return;\n this.unobserve();\n for (var i = 0; i < this.ins
tances.length; i++) {\n this.closeInstanceBindings(this.instances[i]);\n
}\n\n this.instances.length = 0;\n this.closeDeps();\n this.
templateElement_.iterator_ = undefined;\n this.closed = true;\n }\n };\
n\n // Polyfill-specific API.\n HTMLTemplateElement.forAllTemplatesFrom_ = for
AllTemplatesFrom;\n})(this);\n", | 205 "// Copyright (c) 2014 The Polymer Project Authors. All rights reserved.\n//
This code may only be used under the BSD style license found at http://polymer.
github.io/LICENSE.txt\n// The complete set of authors may be found at http://pol
ymer.github.io/AUTHORS.txt\n// The complete set of contributors may be found at
http://polymer.github.io/CONTRIBUTORS.txt\n// Code distributed by Google as part
of the polymer project is also\n// subject to an additional IP rights grant fou
nd at http://polymer.github.io/PATENTS.txt\n\n(function(global) {\n 'use strict
';\n\n function assert(v) {\n if (!v)\n throw new Error('Assertion fail
ed');\n }\n\n var forEach = Array.prototype.forEach.call.bind(Array.prototype.
forEach);\n\n function getFragmentRoot(node) {\n var p;\n while (p = node
.parentNode) {\n node = p;\n }\n\n return node;\n }\n\n function se
archRefId(node, id) {\n if (!id)\n return;\n\n var ref;\n var sele
ctor = '#' + id;\n while (!ref) {\n node = getFragmentRoot(node);\n\n
if (node.protoContent_)\n ref = node.protoContent_.querySelector(selec
tor);\n else if (node.getElementById)\n ref = node.getElementById(id
);\n\n if (ref || !node.templateCreator_)\n break\n\n node = no
de.templateCreator_;\n }\n\n return ref;\n }\n\n function getInstanceRoo
t(node) {\n while (node.parentNode) {\n node = node.parentNode;\n }\n
return node.templateCreator_ ? node : null;\n }\n\n var Map;\n if (global
.Map && typeof global.Map.prototype.forEach === 'function') {\n Map = global.
Map;\n } else {\n Map = function() {\n this.keys = [];\n this.valu
es = [];\n };\n\n Map.prototype = {\n set: function(key, value) {\n
var index = this.keys.indexOf(key);\n if (index < 0) {\n t
his.keys.push(key);\n this.values.push(value);\n } else {\n
this.values[index] = value;\n }\n },\n\n get: function(key
) {\n var index = this.keys.indexOf(key);\n if (index < 0)\n
return;\n\n return this.values[index];\n },\n\n delete: fun
ction(key, value) {\n var index = this.keys.indexOf(key);\n if (in
dex < 0)\n return false;\n\n this.keys.splice(index, 1);\n
this.values.splice(index, 1);\n return true;\n },\n\n forEach
: function(f, opt_this) {\n for (var i = 0; i < this.keys.length; i++)\n
f.call(opt_this || this, this.values[i], this.keys[i], this);\n }\
n };\n }\n\n // JScript does not have __proto__. We wrap all object literal
s with\n // createObject which uses Object.create, Object.defineProperty and\n
// Object.getOwnPropertyDescriptor to create a new object that does the exact\n
// same thing. The main downside to this solution is that we have to extract\n
// all those property descriptors for IE.\n var createObject = ('__proto__' i
n {}) ?\n function(obj) { return obj; } :\n function(obj) {\n v
ar proto = obj.__proto__;\n if (!proto)\n return obj;\n v
ar newObject = Object.create(proto);\n Object.getOwnPropertyNames(obj).fo
rEach(function(name) {\n Object.defineProperty(newObject, name,\n
Object.getOwnPropertyDescriptor(obj, name));\n }
);\n return newObject;\n };\n\n // IE does not support have Documen
t.prototype.contains.\n if (typeof document.contains != 'function') {\n Docu
ment.prototype.contains = function(node) {\n if (node === this || node.pare
ntNode === this)\n return true;\n return this.documentElement.contai
ns(node);\n }\n }\n\n var BIND = 'bind';\n var REPEAT = 'repeat';\n var I
F = 'if';\n\n var templateAttributeDirectives = {\n 'template': true,\n '
repeat': true,\n 'bind': true,\n 'ref': true\n };\n\n var semanticTempla
teElements = {\n 'THEAD': true,\n 'TBODY': true,\n 'TFOOT': true,\n
'TH': true,\n 'TR': true,\n 'TD': true,\n 'COLGROUP': true,\n 'COL':
true,\n 'CAPTION': true,\n 'OPTION': true,\n 'OPTGROUP': true\n };\n\
n var hasTemplateElement = typeof HTMLTemplateElement !== 'undefined';\n if (h
asTemplateElement) {\n // TODO(rafaelw): Remove when fix for\n // https://
codereview.chromium.org/164803002/\n // makes it to Chrome release.\n (fun
ction() {\n var t = document.createElement('template');\n var d = t.co
ntent.ownerDocument;\n var html = d.appendChild(d.createElement('html'));\n
var head = html.appendChild(d.createElement('head'));\n var base = d.
createElement('base');\n base.href = document.baseURI;\n head.appendCh
ild(base);\n })();\n }\n\n var allTemplatesSelectors = 'template, ' +\n
Object.keys(semanticTemplateElements).map(function(tagName) {\n return
tagName.toLowerCase() + '[template]';\n }).join(', ');\n\n function isSVGT
emplate(el) {\n return el.tagName == 'template' &&\n el.namespaceUR
I == 'http://www.w3.org/2000/svg';\n }\n\n function isHTMLTemplate(el) {\n
return el.tagName == 'TEMPLATE' &&\n el.namespaceURI == 'http://www.w3
.org/1999/xhtml';\n }\n\n function isAttributeTemplate(el) {\n return Boole
an(semanticTemplateElements[el.tagName] &&\n el.hasAttribute('
template'));\n }\n\n function isTemplate(el) {\n if (el.isTemplate_ === und
efined)\n el.isTemplate_ = el.tagName == 'TEMPLATE' || isAttributeTemplate(
el);\n\n return el.isTemplate_;\n }\n\n // FIXME: Observe templates being a
dded/removed from documents\n // FIXME: Expose imperative API to decorate and o
bserve templates in\n // \"disconnected tress\" (e.g. ShadowRoot)\n document.a
ddEventListener('DOMContentLoaded', function(e) {\n bootstrapTemplatesRecursi
velyFrom(document);\n // FIXME: Is this needed? Seems like it shouldn't be.\n
Platform.performMicrotaskCheckpoint();\n }, false);\n\n function forAllTem
platesFrom(node, fn) {\n var subTemplates = node.querySelectorAll(allTemplate
sSelectors);\n\n if (isTemplate(node))\n fn(node)\n forEach(subTempla
tes, fn);\n }\n\n function bootstrapTemplatesRecursivelyFrom(node) {\n func
tion bootstrap(template) {\n if (!HTMLTemplateElement.decorate(template))\n
bootstrapTemplatesRecursivelyFrom(template.content);\n }\n\n forAl
lTemplatesFrom(node, bootstrap);\n }\n\n if (!hasTemplateElement) {\n /**\n
* This represents a <template> element.\n * @constructor\n * @exten
ds {HTMLElement}\n */\n global.HTMLTemplateElement = function() {\n
throw TypeError('Illegal constructor');\n };\n }\n\n var hasProto = '__prot
o__' in {};\n\n function mixin(to, from) {\n Object.getOwnPropertyNames(from
).forEach(function(name) {\n Object.defineProperty(to, name,\n
Object.getOwnPropertyDescriptor(from, name));\n });\n }\n\n
// http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/templates/index.html#df
n-template-contents-owner\n function getOrCreateTemplateContentsOwner(template)
{\n var doc = template.ownerDocument\n if (!doc.defaultView)\n retur
n doc;\n var d = doc.templateContentsOwner_;\n if (!d) {\n // TODO(ar
v): This should either be a Document or HTMLDocument depending\n // on doc.
\n d = doc.implementation.createHTMLDocument('');\n while (d.lastChild
) {\n d.removeChild(d.lastChild);\n }\n doc.templateContentsOwn
er_ = d;\n }\n return d;\n }\n\n function getTemplateStagingDocument(tem
plate) {\n if (!template.stagingDocument_) {\n var owner = template.owne
rDocument;\n if (!owner.stagingDocument_) {\n owner.stagingDocument_
= owner.implementation.createHTMLDocument('');\n\n // TODO(rafaelw): Rem
ove when fix for\n // https://codereview.chromium.org/164803002/\n
// makes it to Chrome release.\n var base = owner.stagingDocument_.creat
eElement('base');\n base.href = document.baseURI;\n owner.stagingD
ocument_.head.appendChild(base);\n\n owner.stagingDocument_.stagingDocume
nt_ = owner.stagingDocument_;\n }\n\n template.stagingDocument_ = owne
r.stagingDocument_;\n }\n\n return template.stagingDocument_;\n }\n\n //
For non-template browsers, the parser will disallow <template> in certain\n //
locations, so we allow \"attribute templates\" which combine the template\n //
element with the top-level container node of the content, e.g.\n //\n // <t
r template repeat=\"{{ foo }}\"\" class=\"bar\"><td>Bar</td></tr>\n //\n // be
comes\n //\n // <template repeat=\"{{ foo }}\">\n // + #document-fragment
\n // + <tr class=\"bar\">\n // + <td>Bar</td>\n //\n function ext
ractTemplateFromAttributeTemplate(el) {\n var template = el.ownerDocument.cre
ateElement('template');\n el.parentNode.insertBefore(template, el);\n\n va
r attribs = el.attributes;\n var count = attribs.length;\n while (count--
> 0) {\n var attrib = attribs[count];\n if (templateAttributeDirective
s[attrib.name]) {\n if (attrib.name !== 'template')\n template.s
etAttribute(attrib.name, attrib.value);\n el.removeAttribute(attrib.name)
;\n }\n }\n\n return template;\n }\n\n function extractTemplateFrom
SVGTemplate(el) {\n var template = el.ownerDocument.createElement('template')
;\n el.parentNode.insertBefore(template, el);\n\n var attribs = el.attribu
tes;\n var count = attribs.length;\n while (count-- > 0) {\n var attr
ib = attribs[count];\n template.setAttribute(attrib.name, attrib.value);\n
el.removeAttribute(attrib.name);\n }\n\n el.parentNode.removeChild(el
);\n return template;\n }\n\n function liftNonNativeTemplateChildrenIntoCon
tent(template, el, useRoot) {\n var content = template.content;\n if (useR
oot) {\n content.appendChild(el);\n return;\n }\n\n var child;\n
while (child = el.firstChild) {\n content.appendChild(child);\n }\n
}\n\n var templateObserver;\n if (typeof MutationObserver == 'function') {\n
templateObserver = new MutationObserver(function(records) {\n for (var i
= 0; i < records.length; i++) {\n records[i].target.refChanged_();\n
}\n });\n }\n\n /**\n * Ensures proper API and content model for templa
te elements.\n * @param {HTMLTemplateElement} opt_instanceRef The template ele
ment which\n * |el| template element will return as the value of its ref()
, and whose\n * content will be used as source when createInstance() is in
voked.\n */\n HTMLTemplateElement.decorate = function(el, opt_instanceRef) {\
n if (el.templateIsDecorated_)\n return false;\n\n var templateElemen
t = el;\n templateElement.templateIsDecorated_ = true;\n\n var isNativeHTM
LTemplate = isHTMLTemplate(templateElement) &&\n h
asTemplateElement;\n var bootstrapContents = isNativeHTMLTemplate;\n var l
iftContents = !isNativeHTMLTemplate;\n var liftRoot = false;\n\n if (!isNa
tiveHTMLTemplate) {\n if (isAttributeTemplate(templateElement)) {\n
assert(!opt_instanceRef);\n templateElement = extractTemplateFromAttribut
eTemplate(el);\n templateElement.templateIsDecorated_ = true;\n is
NativeHTMLTemplate = hasTemplateElement;\n liftRoot = true;\n } else
if (isSVGTemplate(templateElement)) {\n templateElement = extractTemplat
eFromSVGTemplate(el);\n templateElement.templateIsDecorated_ = true;\n
isNativeHTMLTemplate = hasTemplateElement;\n }\n }\n\n if (!isNa
tiveHTMLTemplate) {\n fixTemplateElementPrototype(templateElement);\n
var doc = getOrCreateTemplateContentsOwner(templateElement);\n templateElem
ent.content_ = doc.createDocumentFragment();\n }\n\n if (opt_instanceRef)
{\n // template is contained within an instance, its direct content must be
\n // empty\n templateElement.instanceRef_ = opt_instanceRef;\n } e
lse if (liftContents) {\n liftNonNativeTemplateChildrenIntoContent(template
Element,\n el,\n
liftRoot);\n } else if (bootstrapContents) {\n
bootstrapTemplatesRecursivelyFrom(templateElement.content);\n }\n\n re
turn true;\n };\n\n // TODO(rafaelw): This used to decorate recursively all te
mplates from a given\n // node. This happens by default on 'DOMContentLoaded',
but may be needed\n // in subtrees not descendent from document (e.g. ShadowRoo
t).\n // Review whether this is the right public API.\n HTMLTemplateElement.bo
otstrap = bootstrapTemplatesRecursivelyFrom;\n\n var htmlElement = global.HTMLU
nknownElement || HTMLElement;\n\n var contentDescriptor = {\n get: function(
) {\n return this.content_;\n },\n enumerable: true,\n configurabl
e: true\n };\n\n if (!hasTemplateElement) {\n // Gecko is more picky with t
he prototype than WebKit. Make sure to use the\n // same prototype as created
in the constructor.\n HTMLTemplateElement.prototype = Object.create(htmlElem
ent.prototype);\n\n Object.defineProperty(HTMLTemplateElement.prototype, 'con
tent',\n contentDescriptor);\n }\n\n function fixTemp
lateElementPrototype(el) {\n if (hasProto)\n el.__proto__ = HTMLTemplate
Element.prototype;\n else\n mixin(el, HTMLTemplateElement.prototype);\n
}\n\n function ensureSetModelScheduled(template) {\n if (!template.setModel
Fn_) {\n template.setModelFn_ = function() {\n template.setModelFnSc
heduled_ = false;\n var map = getBindings(template,\n template
.delegate_ && template.delegate_.prepareBinding);\n processBindings(templ
ate, map, template.model_);\n };\n }\n\n if (!template.setModelFnSche
duled_) {\n template.setModelFnScheduled_ = true;\n Observer.runEOM_(t
emplate.setModelFn_);\n }\n }\n\n mixin(HTMLTemplateElement.prototype, {\n
bind: function(name, value, oneTime) {\n if (name != 'ref')\n ret
urn Element.prototype.bind.call(this, name, value, oneTime);\n\n var self =
this;\n var ref = oneTime ? value : value.open(function(ref) {\n se
lf.setAttribute('ref', ref);\n self.refChanged_();\n });\n\n th
is.setAttribute('ref', ref);\n this.refChanged_();\n if (oneTime)\n
return;\n\n if (!this.bindings_) {\n this.bindings_ = { ref: va
lue };\n } else {\n this.bindings_.ref = value;\n }\n\n re
turn value;\n },\n\n processBindingDirectives_: function(directives) {\n
if (this.iterator_)\n this.iterator_.closeDeps();\n\n if (!direc
tives.if && !directives.bind && !directives.repeat) {\n if (this.iterator
_) {\n this.iterator_.close();\n this.iterator_ = undefined;\n
}\n\n return;\n }\n\n if (!this.iterator_) {\n t
his.iterator_ = new TemplateIterator(this);\n }\n\n this.iterator_.upd
ateDependencies(directives, this.model_);\n\n if (templateObserver) {\n
templateObserver.observe(this, { attributes: true,\n
attributeFilter: ['ref'] });\n }\n\n return this.iter
ator_;\n },\n\n createInstance: function(model, bindingDelegate, delegate_
) {\n if (bindingDelegate)\n delegate_ = this.newDelegate_(bindingDe
legate);\n\n if (!this.refContent_)\n this.refContent_ = this.ref_.c
ontent;\n var content = this.refContent_;\n if (content.firstChild ===
null)\n return emptyInstance;\n\n var map = this.bindingMap_;\n
if (!map || map.content !== content) {\n // TODO(rafaelw): Setup a Muta
tionObserver on content to detect\n // when the instanceMap is invalid.\n
map = createInstanceBindingMap(content,\n delegate_ && delega
te_.prepareBinding) || [];\n map.content = content;\n this.binding
Map_ = map;\n }\n\n var stagingDocument = getTemplateStagingDocument(t
his);\n var instance = stagingDocument.createDocumentFragment();\n ins
tance.templateCreator_ = this;\n instance.protoContent_ = content;\n i
nstance.bindings_ = [];\n instance.terminator_ = null;\n var instanceR
ecord = instance.templateInstance_ = {\n firstNode: null,\n lastNo
de: null,\n model: model\n };\n\n var i = 0;\n var collect
Terminator = false;\n for (var child = content.firstChild; child; child = c
hild.nextSibling) {\n // The terminator of the instance is the clone of t
he last child of the\n // content. If the last child is an active templat
e, it may produce\n // instances as a result of production, so simply col
lecting the last\n // child of the instance after it has finished produci
ng may be wrong.\n if (child.nextSibling === null)\n collectTerm
inator = true;\n\n var clone = cloneAndBindInstance(child, instance, stag
ingDocument,\n map.children[i++],\n
model,\n
delegate_,\n instance.bindings_);\n
clone.templateInstance_ = instanceRecord;\n if (collectTerminator
)\n instance.terminator_ = clone;\n }\n\n instanceRecord.firs
tNode = instance.firstChild;\n instanceRecord.lastNode = instance.lastChild
;\n instance.templateCreator_ = undefined;\n instance.protoContent_ =
undefined;\n return instance;\n },\n\n get model() {\n return th
is.model_;\n },\n\n set model(model) {\n this.model_ = model;\n
ensureSetModelScheduled(this);\n },\n\n get bindingDelegate() {\n ret
urn this.delegate_ && this.delegate_.raw;\n },\n\n refChanged_: function()
{\n if (!this.iterator_ || this.refContent_ === this.ref_.content)\n
return;\n\n this.refContent_ = undefined;\n this.iterator_.valueChan
ged();\n this.iterator_.updateIteratedValue();\n },\n\n clear: functi
on() {\n this.model_ = undefined;\n this.delegate_ = undefined;\n
if (this.bindings_ && this.bindings_.ref)\n this.bindings_.ref.close()\n
this.refContent_ = undefined;\n if (!this.iterator_)\n return;
\n this.iterator_.valueChanged();\n this.iterator_.close()\n this
.iterator_ = undefined;\n },\n\n setDelegate_: function(delegate) {\n
this.delegate_ = delegate;\n this.bindingMap_ = undefined;\n if (this
.iterator_) {\n this.iterator_.instancePositionChangedFn_ = undefined;\n
this.iterator_.instanceModelFn_ = undefined;\n }\n },\n\n newD
elegate_: function(bindingDelegate) {\n if (!bindingDelegate)\n retu
rn {};\n\n function delegateFn(name) {\n var fn = bindingDelegate &&
bindingDelegate[name];\n if (typeof fn != 'function')\n return;
\n\n return function() {\n return fn.apply(bindingDelegate, argu
ments);\n };\n }\n\n return {\n raw: bindingDelegate,\n
prepareBinding: delegateFn('prepareBinding'),\n prepareInstanceMod
el: delegateFn('prepareInstanceModel'),\n prepareInstancePositionChanged:
\n delegateFn('prepareInstancePositionChanged')\n };\n },\n\n
// TODO(rafaelw): Assigning .bindingDelegate always succeeds. It may\n //
make sense to issue a warning or even throw if the template is already\n //
\"activated\", since this would be a strange thing to do.\n set bindingDelega
te(bindingDelegate) {\n if (this.delegate_) {\n throw Error('Templat
e must be cleared before a new bindingDelegate ' +\n 'can be
assigned');\n }\n\n this.setDelegate_(this.newDelegate_(bindingDelegat
e));\n },\n\n get ref_() {\n var ref = searchRefId(this, this.getAttr
ibute('ref'));\n if (!ref)\n ref = this.instanceRef_;\n\n if (!
ref)\n return this;\n\n var nextRef = ref.ref_;\n return nextRe
f ? nextRef : ref;\n }\n });\n\n // Returns\n // a) undefined if there a
re no mustaches.\n // b) [TEXT, (ONE_TIME?, PATH, DELEGATE_FN, TEXT)+] if the
re is at least one mustache.\n function parseMustaches(s, name, node, prepareBi
ndingFn) {\n if (!s || !s.length)\n return;\n\n var tokens;\n var
length = s.length;\n var startIndex = 0, lastIndex = 0, endIndex = 0;\n va
r onlyOneTime = true;\n while (lastIndex < length) {\n var startIndex =
s.indexOf('{{', lastIndex);\n var oneTimeStart = s.indexOf('[[', lastIndex)
;\n var oneTime = false;\n var terminator = '}}';\n\n if (oneTime
Start >= 0 &&\n (startIndex < 0 || oneTimeStart < startIndex)) {\n
startIndex = oneTimeStart;\n oneTime = true;\n terminator = ']]
';\n }\n\n endIndex = startIndex < 0 ? -1 : s.indexOf(terminator, star
tIndex + 2);\n\n if (endIndex < 0) {\n if (!tokens)\n retur
n;\n\n tokens.push(s.slice(lastIndex)); // TEXT\n break;\n }\
n\n tokens = tokens || [];\n tokens.push(s.slice(lastIndex, startIndex
)); // TEXT\n var pathString = s.slice(startIndex + 2, endIndex).trim();\n
tokens.push(oneTime); // ONE_TIME?\n onlyOneTime = onlyOneTime && oneT
ime;\n var delegateFn = prepareBindingFn &&\n prepare
BindingFn(pathString, name, node);\n // Don't try to parse the expression i
f there's a prepareBinding function\n if (delegateFn == null) {\n to
kens.push(Path.get(pathString)); // PATH\n } else {\n tokens.push(nu
ll);\n }\n tokens.push(delegateFn); // DELEGATE_FN\n lastIndex =
endIndex + 2;\n }\n\n if (lastIndex === length)\n tokens.push(''); //
TEXT\n\n tokens.hasOnePath = tokens.length === 5;\n tokens.isSimplePath =
tokens.hasOnePath &&\n tokens[0] == '' &&\n
tokens[4] == '';\n tokens.onlyOneTime = onlyOneTime;\n\n to
kens.combinator = function(values) {\n var newValue = tokens[0];\n\n f
or (var i = 1; i < tokens.length; i += 4) {\n var value = tokens.hasOnePa
th ? values : values[(i - 1) / 4];\n if (value !== undefined)\n
newValue += value;\n newValue += tokens[i + 3];\n }\n\n return
newValue;\n }\n\n return tokens;\n };\n\n function processOneTimeBinding
(name, tokens, node, model) {\n if (tokens.hasOnePath) {\n var delegateF
n = tokens[3];\n var value = delegateFn ? delegateFn(model, node, true) :\n
tokens[2].getValueFrom(model);\n return toke
ns.isSimplePath ? value : tokens.combinator(value);\n }\n\n var values = [
];\n for (var i = 1; i < tokens.length; i += 4) {\n var delegateFn = tok
ens[i + 2];\n values[(i - 1) / 4] = delegateFn ? delegateFn(model, node) :\
n tokens[i + 1].getValueFrom(model);\n }\n\n return tokens.combin
ator(values);\n }\n\n function processSinglePathBinding(name, tokens, node, mo
del) {\n var delegateFn = tokens[3];\n var observer = delegateFn ? delegat
eFn(model, node, false) :\n new PathObserver(model, tokens[2]);\n\n re
turn tokens.isSimplePath ? observer :\n new ObserverTransform(observer, t
okens.combinator);\n }\n\n function processBinding(name, tokens, node, model)
{\n if (tokens.onlyOneTime)\n return processOneTimeBinding(name, tokens,
node, model);\n\n if (tokens.hasOnePath)\n return processSinglePathBind
ing(name, tokens, node, model);\n\n var observer = new CompoundObserver();\n\
n for (var i = 1; i < tokens.length; i += 4) {\n var oneTime = tokens[i]
;\n var delegateFn = tokens[i + 2];\n\n if (delegateFn) {\n var
value = delegateFn(model, node, oneTime);\n if (oneTime)\n obse
rver.addPath(value)\n else\n observer.addObserver(value);\n
continue;\n }\n\n var path = tokens[i + 1];\n if (oneTime)\n
observer.addPath(path.getValueFrom(model))\n else\n observer.a
ddPath(model, path);\n }\n\n return new ObserverTransform(observer, tokens
.combinator);\n }\n\n function processBindings(node, bindings, model, instance
Bindings) {\n for (var i = 0; i < bindings.length; i += 2) {\n var name
= bindings[i]\n var tokens = bindings[i + 1];\n var value = processBin
ding(name, tokens, node, model);\n var binding = node.bind(name, value, tok
ens.onlyOneTime);\n if (binding && instanceBindings)\n instanceBindi
ngs.push(binding);\n }\n\n if (!bindings.isTemplate)\n return;\n\n
node.model_ = model;\n var iter = node.processBindingDirectives_(bindings);\
n if (instanceBindings && iter)\n instanceBindings.push(iter);\n }\n\n
function parseWithDefault(el, name, prepareBindingFn) {\n var v = el.getAttr
ibute(name);\n return parseMustaches(v == '' ? '{{}}' : v, name, el, prepareB
indingFn);\n }\n\n function parseAttributeBindings(element, prepareBindingFn)
{\n assert(element);\n\n var bindings = [];\n var ifFound = false;\n
var bindFound = false;\n\n for (var i = 0; i < element.attributes.length; i+
+) {\n var attr = element.attributes[i];\n var name = attr.name;\n
var value = attr.value;\n\n // Allow bindings expressed in attributes to
be prefixed with underbars.\n // We do this to allow correct semantics for
browsers that don't implement\n // <template> where certain attributes migh
t trigger side-effects -- and\n // for IE which sanitizes certain attribute
s, disallowing mustache\n // replacements in their text.\n while (name
[0] === '_') {\n name = name.substring(1);\n }\n\n if (isTempla
te(element) &&\n (name === IF || name === BIND || name === REPEAT)) {\n
continue;\n }\n\n var tokens = parseMustaches(value, name, ele
ment,\n prepareBindingFn);\n if (!tokens)\
n continue;\n\n bindings.push(name, tokens);\n }\n\n if (isTem
plate(element)) {\n bindings.isTemplate = true;\n bindings.if = parseW
ithDefault(element, IF, prepareBindingFn);\n bindings.bind = parseWithDefau
lt(element, BIND, prepareBindingFn);\n bindings.repeat = parseWithDefault(e
lement, REPEAT, prepareBindingFn);\n\n if (bindings.if && !bindings.bind &&
!bindings.repeat)\n bindings.bind = parseMustaches('{{}}', BIND, element
, prepareBindingFn);\n }\n\n return bindings;\n }\n\n function getBindin
gs(node, prepareBindingFn) {\n if (node.nodeType === Node.ELEMENT_NODE)\n
return parseAttributeBindings(node, prepareBindingFn);\n\n if (node.nodeTyp
e === Node.TEXT_NODE) {\n var tokens = parseMustaches(node.data, 'textConte
nt', node,\n prepareBindingFn);\n if (toke
ns)\n return ['textContent', tokens];\n }\n\n return [];\n }\n\n
function cloneAndBindInstance(node, parent, stagingDocument, bindings, model,\n
delegate,\n instan
ceBindings,\n instanceRecord) {\n var clone =
parent.appendChild(stagingDocument.importNode(node, false));\n\n var i = 0;\n
for (var child = node.firstChild; child; child = child.nextSibling) {\n
cloneAndBindInstance(child, clone, stagingDocument,\n
bindings.children[i++],\n model,\n
delegate,\n instanceBindings);\n }\n\n
if (bindings.isTemplate) {\n HTMLTemplateElement.decorate(clone, node);\
n if (delegate)\n clone.setDelegate_(delegate);\n }\n\n proces
sBindings(clone, bindings, model, instanceBindings);\n return clone;\n }\n\n
function createInstanceBindingMap(node, prepareBindingFn) {\n var map = get
Bindings(node, prepareBindingFn);\n map.children = {};\n var index = 0;\n
for (var child = node.firstChild; child; child = child.nextSibling) {\n
map.children[index++] = createInstanceBindingMap(child, prepareBindingFn);\n
}\n\n return map;\n }\n\n Object.defineProperty(Node.prototype, 'templateIn
stance', {\n get: function() {\n var instance = this.templateInstance_;\
n return instance ? instance :\n (this.parentNode ? this.parentNod
e.templateInstance : undefined);\n }\n });\n\n var emptyInstance = document
.createDocumentFragment();\n emptyInstance.bindings_ = [];\n emptyInstance.ter
minator_ = null;\n\n function TemplateIterator(templateElement) {\n this.clo
sed = false;\n this.templateElement_ = templateElement;\n this.instances =
[];\n this.deps = undefined;\n this.iteratedValue = [];\n this.present
Value = undefined;\n this.arrayObserver = undefined;\n }\n\n TemplateIterat
or.prototype = {\n closeDeps: function() {\n var deps = this.deps;\n
if (deps) {\n if (deps.ifOneTime === false)\n deps.ifValue.clo
se();\n if (deps.oneTime === false)\n deps.value.close();\n
}\n },\n\n updateDependencies: function(directives, model) {\n this.
closeDeps();\n\n var deps = this.deps = {};\n var template = this.temp
lateElement_;\n\n if (directives.if) {\n deps.hasIf = true;\n
deps.ifOneTime = directives.if.onlyOneTime;\n deps.ifValue = processBind
ing(IF, directives.if, template, model);\n\n // oneTime if & predicate is
false. nothing else to do.\n if (deps.ifOneTime && !deps.ifValue) {\n
this.updateIteratedValue();\n return;\n }\n\n if (
!deps.ifOneTime)\n deps.ifValue.open(this.updateIteratedValue, this);\n
}\n\n if (directives.repeat) {\n deps.repeat = true;\n
deps.oneTime = directives.repeat.onlyOneTime;\n deps.value = processBindi
ng(REPEAT, directives.repeat, template, model);\n } else {\n deps.re
peat = false;\n deps.oneTime = directives.bind.onlyOneTime;\n deps
.value = processBinding(BIND, directives.bind, template, model);\n }\n\n
if (!deps.oneTime)\n deps.value.open(this.updateIteratedValue, this);\
n\n this.updateIteratedValue();\n },\n\n updateIteratedValue: functio
n() {\n if (this.deps.hasIf) {\n var ifValue = this.deps.ifValue;\n
if (!this.deps.ifOneTime)\n ifValue = ifValue.discardChanges();\
n if (!ifValue) {\n this.valueChanged();\n return;\n
}\n }\n\n var value = this.deps.value;\n if (!this.deps.oneT
ime)\n value = value.discardChanges();\n if (!this.deps.repeat)\n
value = [value];\n var observe = this.deps.repeat &&\n
!this.deps.oneTime &&\n Array.isArray(value);\n this
.valueChanged(value, observe);\n },\n\n valueChanged: function(value, obse
rveValue) {\n if (!Array.isArray(value))\n value = [];\n\n if (
value === this.iteratedValue)\n return;\n\n this.unobserve();\n
this.presentValue = value;\n if (observeValue) {\n this.arrayObserv
er = new ArrayObserver(this.presentValue);\n this.arrayObserver.open(this
.handleSplices, this);\n }\n\n this.handleSplices(ArrayObserver.calcul
ateSplices(this.presentValue,\n
this.iteratedValue));\n },\n\n getLastInstanceNode: function(index)
{\n if (index == -1)\n return this.templateElement_;\n var ins
tance = this.instances[index];\n var terminator = instance.terminator_;\n
if (!terminator)\n return this.getLastInstanceNode(index - 1);\n\n
if (terminator.nodeType !== Node.ELEMENT_NODE ||\n this.templateElem
ent_ === terminator) {\n return terminator;\n }\n\n var subtemp
lateIterator = terminator.iterator_;\n if (!subtemplateIterator)\n r
eturn terminator;\n\n return subtemplateIterator.getLastTemplateNode();\n
},\n\n getLastTemplateNode: function() {\n return this.getLastInstance
Node(this.instances.length - 1);\n },\n\n insertInstanceAt: function(index
, fragment) {\n var previousInstanceLast = this.getLastInstanceNode(index -
1);\n var parent = this.templateElement_.parentNode;\n this.instances
.splice(index, 0, fragment);\n\n parent.insertBefore(fragment, previousInst
anceLast.nextSibling);\n },\n\n extractInstanceAt: function(index) {\n
var previousInstanceLast = this.getLastInstanceNode(index - 1);\n var las
tNode = this.getLastInstanceNode(index);\n var parent = this.templateElemen
t_.parentNode;\n var instance = this.instances.splice(index, 1)[0];\n\n
while (lastNode !== previousInstanceLast) {\n var node = previousInstan
ceLast.nextSibling;\n if (node == lastNode)\n lastNode = previou
sInstanceLast;\n\n instance.appendChild(parent.removeChild(node));\n
}\n\n return instance;\n },\n\n getDelegateFn: function(fn) {\n
fn = fn && fn(this.templateElement_);\n return typeof fn === 'function' ?
fn : null;\n },\n\n handleSplices: function(splices) {\n if (this.clo
sed || !splices.length)\n return;\n\n var template = this.templateEl
ement_;\n\n if (!template.parentNode) {\n this.close();\n ret
urn;\n }\n\n ArrayObserver.applySplices(this.iteratedValue, this.prese
ntValue,\n splices);\n\n var delegate = tem
plate.delegate_;\n if (this.instanceModelFn_ === undefined) {\n this
.instanceModelFn_ =\n this.getDelegateFn(delegate && delegate.prepare
InstanceModel);\n }\n\n if (this.instancePositionChangedFn_ === undefi
ned) {\n this.instancePositionChangedFn_ =\n this.getDelegateF
n(delegate &&\n delegate.prepareInstancePositionCh
anged);\n }\n\n // Instance Removals\n var instanceCache = new Ma
p;\n var removeDelta = 0;\n for (var i = 0; i < splices.length; i++) {
\n var splice = splices[i];\n var removed = splice.removed;\n
for (var j = 0; j < removed.length; j++) {\n var model = removed[j];
\n var instance = this.extractInstanceAt(splice.index + removeDelta);\n
if (instance !== emptyInstance) {\n instanceCache.set(model
, instance);\n }\n }\n\n removeDelta -= splice.addedCount
;\n }\n\n // Instance Insertions\n for (var i = 0; i < splices.le
ngth; i++) {\n var splice = splices[i];\n var addIndex = splice.in
dex;\n for (; addIndex < splice.index + splice.addedCount; addIndex++) {\
n var model = this.iteratedValue[addIndex];\n var instance = i
nstanceCache.get(model);\n if (instance) {\n instanceCache.d
elete(model);\n } else {\n if (this.instanceModelFn_) {\n
model = this.instanceModelFn_(model);\n }\n\n i
f (model === undefined) {\n instance = emptyInstance;\n
} else {\n instance = template.createInstance(model, undefined, del
egate);\n }\n }\n\n this.insertInstanceAt(addIndex,
instance);\n }\n }\n\n instanceCache.forEach(function(instance
) {\n this.closeInstanceBindings(instance);\n }, this);\n\n if
(this.instancePositionChangedFn_)\n this.reportInstancesMoved(splices);\n
},\n\n reportInstanceMoved: function(index) {\n var instance = this.
instances[index];\n if (instance === emptyInstance)\n return;\n\n
this.instancePositionChangedFn_(instance.templateInstance_, index);\n },\n
\n reportInstancesMoved: function(splices) {\n var index = 0;\n var
offset = 0;\n for (var i = 0; i < splices.length; i++) {\n var spli
ce = splices[i];\n if (offset != 0) {\n while (index < splice.in
dex) {\n this.reportInstanceMoved(index);\n index++;\n
}\n } else {\n index = splice.index;\n }\n\n
while (index < splice.index + splice.addedCount) {\n this.reportInstan
ceMoved(index);\n index++;\n }\n\n offset += splice.added
Count - splice.removed.length;\n }\n\n if (offset == 0)\n retur
n;\n\n var length = this.instances.length;\n while (index < length) {\
n this.reportInstanceMoved(index);\n index++;\n }\n },\n\n
closeInstanceBindings: function(instance) {\n var bindings = instance.b
indings_;\n for (var i = 0; i < bindings.length; i++) {\n bindings[i
].close();\n }\n },\n\n unobserve: function() {\n if (!this.arra
yObserver)\n return;\n\n this.arrayObserver.close();\n this.arr
ayObserver = undefined;\n },\n\n close: function() {\n if (this.close
d)\n return;\n this.unobserve();\n for (var i = 0; i < this.ins
tances.length; i++) {\n this.closeInstanceBindings(this.instances[i]);\n
}\n\n this.instances.length = 0;\n this.closeDeps();\n this.
templateElement_.iterator_ = undefined;\n this.closed = true;\n }\n };\
n\n // Polyfill-specific API.\n HTMLTemplateElement.forAllTemplatesFrom_ = for
AllTemplatesFrom;\n})(this);\n", |
206 "/*\n Copyright (C) 2013 Ariya Hidayat <ariya.hidayat@gmail.com>\n Copyrig
ht (C) 2013 Thaddee Tyl <thaddee.tyl@gmail.com>\n Copyright (C) 2012 Ariya Hida
yat <ariya.hidayat@gmail.com>\n Copyright (C) 2012 Mathias Bynens <mathias@qiwi
.be>\n Copyright (C) 2012 Joost-Wim Boekesteijn <joost-wim@boekesteijn.nl>\n C
opyright (C) 2012 Kris Kowal <kris.kowal@cixar.com>\n Copyright (C) 2012 Yusuke
Suzuki <utatane.tea@gmail.com>\n Copyright (C) 2012 Arpad Borsos <arpad.borsos
@googlemail.com>\n Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>\n
\n Redistribution and use in source and binary forms, with or without\n modifi
cation, are permitted provided that the following conditions are met:\n\n * R
edistributions of source code must retain the above copyright\n notice, thi
s list of conditions and the following disclaimer.\n * Redistributions in bin
ary form must reproduce the above copyright\n notice, this list of conditio
ns and the following disclaimer in the\n documentation and/or other materia
ls provided with the distribution.\n\n THIS SOFTWARE IS PROVIDED BY THE COPYRIG
HT HOLDERS AND CONTRIBUTORS \"AS IS\"\n AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE\n IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE\n ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT
HOLDER> BE LIABLE FOR ANY\n DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES\n (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBST
ITUTE GOODS OR SERVICES;\n LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPT
ION) HOWEVER CAUSED AND\n ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRI
CT LIABILITY, OR TORT\n (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF\n THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH D
AMAGE.\n*/\n\n(function (global) {\n 'use strict';\n\n var Token,\n
TokenName,\n Syntax,\n Messages,\n source,\n index,
\n length,\n delegate,\n lookahead,\n state;\n\n
Token = {\n BooleanLiteral: 1,\n EOF: 2,\n Identifier: 3,\n
Keyword: 4,\n NullLiteral: 5,\n NumericLiteral: 6,\n
Punctuator: 7,\n StringLiteral: 8\n };\n\n TokenName = {};\n T
okenName[Token.BooleanLiteral] = 'Boolean';\n TokenName[Token.EOF] = '<end>';
\n TokenName[Token.Identifier] = 'Identifier';\n TokenName[Token.Keyword]
= 'Keyword';\n TokenName[Token.NullLiteral] = 'Null';\n TokenName[Token.Nu
mericLiteral] = 'Numeric';\n TokenName[Token.Punctuator] = 'Punctuator';\n
TokenName[Token.StringLiteral] = 'String';\n\n Syntax = {\n ArrayExpr
ession: 'ArrayExpression',\n BinaryExpression: 'BinaryExpression',\n
CallExpression: 'CallExpression',\n ConditionalExpression: 'Conditiona
lExpression',\n EmptyStatement: 'EmptyStatement',\n ExpressionStat
ement: 'ExpressionStatement',\n Identifier: 'Identifier',\n Litera
l: 'Literal',\n LabeledStatement: 'LabeledStatement',\n LogicalExp
ression: 'LogicalExpression',\n MemberExpression: 'MemberExpression',\n
ObjectExpression: 'ObjectExpression',\n Program: 'Program',\n
Property: 'Property',\n ThisExpression: 'ThisExpression',\n Unar
yExpression: 'UnaryExpression'\n };\n\n // Error messages should be identi
cal to V8.\n Messages = {\n UnexpectedToken: 'Unexpected token %0',\n
UnknownLabel: 'Undefined label \\'%0\\'',\n Redeclaration: '%0 \\
'%1\\' has already been declared'\n };\n\n // Ensure the condition is true
, otherwise throw an error.\n // This is only to have a better contract seman
tic, i.e. another safety net\n // to catch a logic error. The condition shall
be fulfilled in normal case.\n // Do NOT use this to enforce a certain condi
tion on any user input.\n\n function assert(condition, message) {\n if
(!condition) {\n throw new Error('ASSERT: ' + message);\n }\n
}\n\n function isDecimalDigit(ch) {\n return (ch >= 48 && ch <= 57
); // 0..9\n }\n\n\n // 7.2 White Space\n\n function isWhiteSpace(ch)
{\n return (ch === 32) || // space\n (ch === 9) || // t
ab\n (ch === 0xB) ||\n (ch === 0xC) ||\n (ch ==
= 0xA0) ||\n (ch >= 0x1680 && '\\u1680\\u180E\\u2000\\u2001\\u2002\\u
2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200A\\u202F\\u205F\\u3000\\uFEF
F'.indexOf(String.fromCharCode(ch)) > 0);\n }\n\n // 7.3 Line Terminators\
n\n function isLineTerminator(ch) {\n return (ch === 10) || (ch === 13
) || (ch === 0x2028) || (ch === 0x2029);\n }\n\n // 7.6 Identifier Names a
nd Identifiers\n\n function isIdentifierStart(ch) {\n return (ch === 3
6) || (ch === 95) || // $ (dollar) and _ (underscore)\n (ch >= 65 &&
ch <= 90) || // A..Z\n (ch >= 97 && ch <= 122); //
a..z\n }\n\n function isIdentifierPart(ch) {\n return (ch === 36) |
| (ch === 95) || // $ (dollar) and _ (underscore)\n (ch >= 65 && ch
<= 90) || // A..Z\n (ch >= 97 && ch <= 122) || // a..z
\n (ch >= 48 && ch <= 57); // 0..9\n }\n\n // 7.6.1.1
Keywords\n\n function isKeyword(id) {\n return (id === 'this')\n }
\n\n // 7.4 Comments\n\n function skipWhitespace() {\n while (index
< length && isWhiteSpace(source.charCodeAt(index))) {\n ++index;\n
}\n }\n\n function getIdentifier() {\n var start, ch;\n\n
start = index++;\n while (index < length) {\n ch = source.c
harCodeAt(index);\n if (isIdentifierPart(ch)) {\n ++in
dex;\n } else {\n break;\n }\n }\n\n
return source.slice(start, index);\n }\n\n function scanIdentifier
() {\n var start, id, type;\n\n start = index;\n\n id = get
Identifier();\n\n // There is no keyword or literal with only one charact
er.\n // Thus, it must be an identifier.\n if (id.length === 1) {\
n type = Token.Identifier;\n } else if (isKeyword(id)) {\n
type = Token.Keyword;\n } else if (id === 'null') {\n
type = Token.NullLiteral;\n } else if (id === 'true' || id === 'false') {
\n type = Token.BooleanLiteral;\n } else {\n type =
Token.Identifier;\n }\n\n return {\n type: type,\n
value: id,\n range: [start, index]\n };\n }\n\n\n
// 7.7 Punctuators\n\n function scanPunctuator() {\n var start = ind
ex,\n code = source.charCodeAt(index),\n code2,\n
ch1 = source[index],\n ch2;\n\n switch (code) {\n\n
// Check for most common single-character punctuators.\n case 46: // .
dot\n case 40: // ( open bracket\n case 41: // ) close bracket
\n case 59: // ; semicolon\n case 44: // , comma\n case
123: // { open curly brace\n case 125: // } close curly brace\n
case 91: // [\n case 93: // ]\n case 58: // :\n case
63: // ?\n ++index;\n return {\n type: T
oken.Punctuator,\n value: String.fromCharCode(code),\n
range: [start, index]\n };\n\n default:\n code
2 = source.charCodeAt(index + 1);\n\n // '=' (char #61) marks an assi
gnment or comparison operator.\n if (code2 === 61) {\n
switch (code) {\n case 37: // %\n case 38: // &
\n case 42: // *:\n case 43: // +\n
case 45: // -\n case 47: // /\n case 60: //
<\n case 62: // >\n case 124: // |\n
index += 2;\n return {\n type:
Token.Punctuator,\n value: String.fromCharCode(code) + St
ring.fromCharCode(code2),\n range: [start, index]\n
};\n\n case 33: // !\n case 61: // =
\n index += 2;\n\n // !== and ===\n
if (source.charCodeAt(index) === 61) {\n ++i
ndex;\n }\n return {\n
type: Token.Punctuator,\n value: source.slice(start,
index),\n range: [start, index]\n };\n
default:\n break;\n }\n
}\n break;\n }\n\n // Peek more characters.\n\n
ch2 = source[index + 1];\n\n // Other 2-character punctuators: && ||
\n\n if (ch1 === ch2 && ('&|'.indexOf(ch1) >= 0)) {\n index +=
2;\n return {\n type: Token.Punctuator,\n
value: ch1 + ch2,\n range: [start, index]\n };\n
}\n\n if ('<>=!+-*%&|^/'.indexOf(ch1) >= 0) {\n ++index;
\n return {\n type: Token.Punctuator,\n
value: ch1,\n range: [start, index]\n };\n }\n
\n throwError({}, Messages.UnexpectedToken, 'ILLEGAL');\n }\n\n //
7.8.3 Numeric Literals\n function scanNumericLiteral() {\n var number,
start, ch;\n\n ch = source[index];\n assert(isDecimalDigit(ch.cha
rCodeAt(0)) || (ch === '.'),\n 'Numeric literal must start with a dec
imal digit or a decimal point');\n\n start = index;\n number = '';
\n if (ch !== '.') {\n number = source[index++];\n
ch = source[index];\n\n // Hex number starts with '0x'.\n
// Octal number starts with '0'.\n if (number === '0') {\n
// decimal number starts with '0' such as '09' is illegal.\n
if (ch && isDecimalDigit(ch.charCodeAt(0))) {\n throwError({
}, Messages.UnexpectedToken, 'ILLEGAL');\n }\n }\n\n
while (isDecimalDigit(source.charCodeAt(index))) {\n nu
mber += source[index++];\n }\n ch = source[index];\n
}\n\n if (ch === '.') {\n number += source[index++];\n
while (isDecimalDigit(source.charCodeAt(index))) {\n number
+= source[index++];\n }\n ch = source[index];\n }\
n\n if (ch === 'e' || ch === 'E') {\n number += source[index++
];\n\n ch = source[index];\n if (ch === '+' || ch === '-')
{\n number += source[index++];\n }\n if (i
sDecimalDigit(source.charCodeAt(index))) {\n while (isDecimalDigi
t(source.charCodeAt(index))) {\n number += source[index++];\n
}\n } else {\n throwError({}, Messages
.UnexpectedToken, 'ILLEGAL');\n }\n }\n\n if (isIdentif
ierStart(source.charCodeAt(index))) {\n throwError({}, Messages.Unexp
ectedToken, 'ILLEGAL');\n }\n\n return {\n type: Token.
NumericLiteral,\n value: parseFloat(number),\n range: [sta
rt, index]\n };\n }\n\n // 7.8.4 String Literals\n\n function sc
anStringLiteral() {\n var str = '', quote, start, ch, octal = false;\n\n
quote = source[index];\n assert((quote === '\\'' || quote === '\"'
),\n 'String literal must starts with a quote');\n\n start = i
ndex;\n ++index;\n\n while (index < length) {\n ch = so
urce[index++];\n\n if (ch === quote) {\n quote = '';\n
break;\n } else if (ch === '\\\\') {\n
ch = source[index++];\n if (!ch || !isLineTerminator(ch.charCode
At(0))) {\n switch (ch) {\n case 'n':\n
str += '\\n';\n break;\n
case 'r':\n str += '\\r';\n
break;\n case 't':\n str += '\\t';\n
break;\n case 'b':\n
str += '\\b';\n break;\n case '
f':\n str += '\\f';\n break;\n
case 'v':\n str += '\\x0B';\n
break;\n\n default:\n str
+= ch;\n break;\n }\n }
else {\n if (ch === '\\r' && source[index] === '\\n') {\n
++index;\n }\n }\n
} else if (isLineTerminator(ch.charCodeAt(0))) {\n break;\n
} else {\n str += ch;\n }\n }\n\n
if (quote !== '') {\n throwError({}, Messages.UnexpectedToken,
'ILLEGAL');\n }\n\n return {\n type: Token.StringLitera
l,\n value: str,\n octal: octal,\n range: [star
t, index]\n };\n }\n\n function isIdentifierName(token) {\n
return token.type === Token.Identifier ||\n token.type === Token.Keyw
ord ||\n token.type === Token.BooleanLiteral ||\n token.ty
pe === Token.NullLiteral;\n }\n\n function advance() {\n var ch;\n\
n skipWhitespace();\n\n if (index >= length) {\n return
{\n type: Token.EOF,\n range: [index, index]\n
};\n }\n\n ch = source.charCodeAt(index);\n\n // V
ery common: ( and ) and ;\n if (ch === 40 || ch === 41 || ch === 58) {\n
return scanPunctuator();\n }\n\n // String literal star
ts with single quote (#39) or double quote (#34).\n if (ch === 39 || ch =
== 34) {\n return scanStringLiteral();\n }\n\n if (isId
entifierStart(ch)) {\n return scanIdentifier();\n }\n\n
// Dot (.) char #46 can also start a floating-point number, hence the need\n
// to check the next character.\n if (ch === 46) {\n if (
isDecimalDigit(source.charCodeAt(index + 1))) {\n return scanNume
ricLiteral();\n }\n return scanPunctuator();\n }\n\
n if (isDecimalDigit(ch)) {\n return scanNumericLiteral();\n
}\n\n return scanPunctuator();\n }\n\n function lex() {\n
var token;\n\n token = lookahead;\n index = token.range[1];\n\
n lookahead = advance();\n\n index = token.range[1];\n\n re
turn token;\n }\n\n function peek() {\n var pos;\n\n pos = i
ndex;\n lookahead = advance();\n index = pos;\n }\n\n // Thr
ow an exception\n\n function throwError(token, messageFormat) {\n var
error,\n args = Array.prototype.slice.call(arguments, 2),\n
msg = messageFormat.replace(\n /%(\\d)/g,\n func
tion (whole, index) {\n assert(index < args.length, 'Message
reference must be in range');\n return args[index];\n
}\n );\n\n error = new Error(msg);\n error.inde
x = index;\n error.description = msg;\n throw error;\n }\n\n
// Throw an exception because of the token.\n\n function throwUnexpected(tok
en) {\n throwError(token, Messages.UnexpectedToken, token.value);\n }\
n\n // Expect the next token to match the specified punctuator.\n // If no
t, an exception will be thrown.\n\n function expect(value) {\n var tok
en = lex();\n if (token.type !== Token.Punctuator || token.value !== valu
e) {\n throwUnexpected(token);\n }\n }\n\n // Return tru
e if the next token matches the specified punctuator.\n\n function match(valu
e) {\n return lookahead.type === Token.Punctuator && lookahead.value ===
value;\n }\n\n // Return true if the next token matches the specified keyw
ord\n\n function matchKeyword(keyword) {\n return lookahead.type === T
oken.Keyword && lookahead.value === keyword;\n }\n\n function consumeSemic
olon() {\n // Catch the very common case first: immediately a semicolon (
char #59).\n if (source.charCodeAt(index) === 59) {\n lex();\n
return;\n }\n\n skipWhitespace();\n\n if (match
(';')) {\n lex();\n return;\n }\n\n if (look
ahead.type !== Token.EOF && !match('}')) {\n throwUnexpected(lookahea
d);\n }\n }\n\n // 11.1.4 Array Initialiser\n\n function parseAr
rayInitialiser() {\n var elements = [];\n\n expect('[');\n\n
while (!match(']')) {\n if (match(',')) {\n lex();\n
elements.push(null);\n } else {\n elem
ents.push(parseExpression());\n\n if (!match(']')) {\n
expect(',');\n }\n }\n }\n\n ex
pect(']');\n\n return delegate.createArrayExpression(elements);\n }\n\
n // 11.1.5 Object Initialiser\n\n function parseObjectPropertyKey() {\n
var token;\n\n skipWhitespace();\n token = lex();\n\n
// Note: This function is called only from parseObjectProperty(), where\n
// EOF and Punctuator tokens are already filtered out.\n if (token.type
=== Token.StringLiteral || token.type === Token.NumericLiteral) {\n
return delegate.createLiteral(token);\n }\n\n return delegate.crea
teIdentifier(token.value);\n }\n\n function parseObjectProperty() {\n
var token, key;\n\n token = lookahead;\n skipWhitespace();\n\n
if (token.type === Token.EOF || token.type === Token.Punctuator) {\n
throwUnexpected(token);\n }\n\n key = parseObjectPropertyKe
y();\n expect(':');\n return delegate.createProperty('init', key,
parseExpression());\n }\n\n function parseObjectInitialiser() {\n v
ar properties = [];\n\n expect('{');\n\n while (!match('}')) {\n
properties.push(parseObjectProperty());\n\n if (!match('}')
) {\n expect(',');\n }\n }\n\n expect('}
');\n\n return delegate.createObjectExpression(properties);\n }\n\n
// 11.1.6 The Grouping Operator\n\n function parseGroupExpression() {\n
var expr;\n\n expect('(');\n\n expr = parseExpression();\n\n
expect(')');\n\n return expr;\n }\n\n\n // 11.1 Primary Expres
sions\n\n function parsePrimaryExpression() {\n var type, token, expr;
\n\n if (match('(')) {\n return parseGroupExpression();\n
}\n\n type = lookahead.type;\n\n if (type === Token.Identifier)
{\n expr = delegate.createIdentifier(lex().value);\n } else i
f (type === Token.StringLiteral || type === Token.NumericLiteral) {\n
expr = delegate.createLiteral(lex());\n } else if (type === Token.Keywor
d) {\n if (matchKeyword('this')) {\n lex();\n
expr = delegate.createThisExpression();\n }\n } else if
(type === Token.BooleanLiteral) {\n token = lex();\n toke
n.value = (token.value === 'true');\n expr = delegate.createLiteral(t
oken);\n } else if (type === Token.NullLiteral) {\n token = le
x();\n token.value = null;\n expr = delegate.createLiteral
(token);\n } else if (match('[')) {\n expr = parseArrayInitial
iser();\n } else if (match('{')) {\n expr = parseObjectInitial
iser();\n }\n\n if (expr) {\n return expr;\n }\n
\n throwUnexpected(lex());\n }\n\n // 11.2 Left-Hand-Side Expressio
ns\n\n function parseArguments() {\n var args = [];\n\n expect(
'(');\n\n if (!match(')')) {\n while (index < length) {\n
args.push(parseExpression());\n if (match(')')) {\n
break;\n }\n expect(',');\n
}\n }\n\n expect(')');\n\n return args;\n }\n\n
function parseNonComputedProperty() {\n var token;\n\n token = le
x();\n\n if (!isIdentifierName(token)) {\n throwUnexpected(tok
en);\n }\n\n return delegate.createIdentifier(token.value);\n }
\n\n function parseNonComputedMember() {\n expect('.');\n\n ret
urn parseNonComputedProperty();\n }\n\n function parseComputedMember() {\n
var expr;\n\n expect('[');\n\n expr = parseExpression();\n
\n expect(']');\n\n return expr;\n }\n\n function parseLeftH
andSideExpression() {\n var expr, property;\n\n expr = parsePrimar
yExpression();\n\n while (match('.') || match('[')) {\n if (ma
tch('[')) {\n property = parseComputedMember();\n
expr = delegate.createMemberExpression('[', expr, property);\n } else
{\n property = parseNonComputedMember();\n expr =
delegate.createMemberExpression('.', expr, property);\n }\n }
\n\n return expr;\n }\n\n // 11.3 Postfix Expressions\n\n var pa
rsePostfixExpression = parseLeftHandSideExpression;\n\n // 11.4 Unary Operato
rs\n\n function parseUnaryExpression() {\n var token, expr;\n\n
if (lookahead.type !== Token.Punctuator && lookahead.type !== Token.Keyword) {\
n expr = parsePostfixExpression();\n } else if (match('+') ||
match('-') || match('!')) {\n token = lex();\n expr = pars
eUnaryExpression();\n expr = delegate.createUnaryExpression(token.val
ue, expr);\n } else if (matchKeyword('delete') || matchKeyword('void') ||
matchKeyword('typeof')) {\n throwError({}, Messages.UnexpectedToken)
;\n } else {\n expr = parsePostfixExpression();\n }\n\n
return expr;\n }\n\n function binaryPrecedence(token) {\n v
ar prec = 0;\n\n if (token.type !== Token.Punctuator && token.type !== To
ken.Keyword) {\n return 0;\n }\n\n switch (token.value)
{\n case '||':\n prec = 1;\n break;\n\n cas
e '&&':\n prec = 2;\n break;\n\n case '==':\n
case '!=':\n case '===':\n case '!==':\n prec = 6;\n
break;\n\n case '<':\n case '>':\n case '<=':\n
case '>=':\n case 'instanceof':\n prec = 7;\n
break;\n\n case 'in':\n prec = 7;\n break;\n\n
case '+':\n case '-':\n prec = 9;\n break;\n\n
case '*':\n case '/':\n case '%':\n prec = 11;\
n break;\n\n default:\n break;\n }\n\n
return prec;\n }\n\n // 11.5 Multiplicative Operators\n // 11.6 Addit
ive Operators\n // 11.7 Bitwise Shift Operators\n // 11.8 Relational Opera
tors\n // 11.9 Equality Operators\n // 11.10 Binary Bitwise Operators\n
// 11.11 Binary Logical Operators\n\n function parseBinaryExpression() {\n
var expr, token, prec, stack, right, operator, left, i;\n\n left =
parseUnaryExpression();\n\n token = lookahead;\n prec = binaryPrec
edence(token);\n if (prec === 0) {\n return left;\n }\n
token.prec = prec;\n lex();\n\n right = parseUnaryExpressi
on();\n\n stack = [left, token, right];\n\n while ((prec = binaryP
recedence(lookahead)) > 0) {\n\n // Reduce: make a binary expression
from the three topmost entries.\n while ((stack.length > 2) && (prec
<= stack[stack.length - 2].prec)) {\n right = stack.pop();\n
operator = stack.pop().value;\n left = stack.pop();\n
expr = delegate.createBinaryExpression(operator, left, right);\n
stack.push(expr);\n }\n\n // Shift.\n
token = lex();\n token.prec = prec;\n stack.push(tok
en);\n expr = parseUnaryExpression();\n stack.push(expr);\
n }\n\n // Final reduce to clean-up the stack.\n i = stack.
length - 1;\n expr = stack[i];\n while (i > 1) {\n expr
= delegate.createBinaryExpression(stack[i - 1].value, stack[i - 2], expr);\n
i -= 2;\n }\n\n return expr;\n }\n\n\n // 11.12 Con
ditional Operator\n\n function parseConditionalExpression() {\n var ex
pr, consequent, alternate;\n\n expr = parseBinaryExpression();\n\n
if (match('?')) {\n lex();\n consequent = parseConditiona
lExpression();\n expect(':');\n alternate = parseCondition
alExpression();\n\n expr = delegate.createConditionalExpression(expr,
consequent, alternate);\n }\n\n return expr;\n }\n\n // Sim
plification since we do not support AssignmentExpression.\n var parseExpressi
on = parseConditionalExpression;\n\n // Polymer Syntax extensions\n\n // F
ilter ::\n // Identifier\n // Identifier \"(\" \")\"\n // Identif
ier \"(\" FilterArguments \")\"\n\n function parseFilter() {\n var ide
ntifier, args;\n\n identifier = lex();\n\n if (identifier.type !==
Token.Identifier) {\n throwUnexpected(identifier);\n }\n\n
args = match('(') ? parseArguments() : [];\n\n return delegate.creat
eFilter(identifier.value, args);\n }\n\n // Filters ::\n // \"|\" Fil
ter\n // Filters \"|\" Filter\n\n function parseFilters() {\n whi
le (match('|')) {\n lex();\n parseFilter();\n }\n
}\n\n // TopLevel ::\n // LabelledExpressions\n // AsExpression\n
// InExpression\n // FilterExpression\n\n // AsExpression ::\n
// FilterExpression as Identifier\n\n // InExpression ::\n // Identifi
er, Identifier in FilterExpression\n // Identifier in FilterExpression\n\n
// FilterExpression ::\n // Expression\n // Expression Filters\n\n
function parseTopLevel() {\n skipWhitespace();\n peek();\n\n
var expr = parseExpression();\n if (expr) {\n if (lookahe
ad.value === ',' || lookahead.value == 'in' &&\n expr.type
=== Syntax.Identifier) {\n parseInExpression(expr);\n
} else {\n parseFilters();\n if (lookahead.value
=== 'as') {\n parseAsExpression(expr);\n } els
e {\n delegate.createTopLevel(expr);\n }\n
}\n }\n\n if (lookahead.type !== Token.EOF) {\n
throwUnexpected(lookahead);\n }\n }\n\n function parseAsExpression
(expr) {\n lex(); // as\n var identifier = lex().value;\n
delegate.createAsExpression(expr, identifier);\n }\n\n function parseInExp
ression(identifier) {\n var indexName;\n if (lookahead.value === '
,') {\n lex();\n if (lookahead.type !== Token.Identifier)\
n throwUnexpected(lookahead);\n indexName = lex().valu
e;\n }\n\n lex(); // in\n var expr = parseExpression();\n
parseFilters();\n delegate.createInExpression(identifier.name, ind
exName, expr);\n }\n\n function parse(code, inDelegate) {\n delegat
e = inDelegate;\n source = code;\n index = 0;\n length = so
urce.length;\n lookahead = null;\n state = {\n labelSet
: {}\n };\n\n return parseTopLevel();\n }\n\n global.esprima
= {\n parse: parse\n };\n})(this);\n", | 206 "/*\n Copyright (C) 2013 Ariya Hidayat <ariya.hidayat@gmail.com>\n Copyrig
ht (C) 2013 Thaddee Tyl <thaddee.tyl@gmail.com>\n Copyright (C) 2012 Ariya Hida
yat <ariya.hidayat@gmail.com>\n Copyright (C) 2012 Mathias Bynens <mathias@qiwi
.be>\n Copyright (C) 2012 Joost-Wim Boekesteijn <joost-wim@boekesteijn.nl>\n C
opyright (C) 2012 Kris Kowal <kris.kowal@cixar.com>\n Copyright (C) 2012 Yusuke
Suzuki <utatane.tea@gmail.com>\n Copyright (C) 2012 Arpad Borsos <arpad.borsos
@googlemail.com>\n Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>\n
\n Redistribution and use in source and binary forms, with or without\n modifi
cation, are permitted provided that the following conditions are met:\n\n * R
edistributions of source code must retain the above copyright\n notice, thi
s list of conditions and the following disclaimer.\n * Redistributions in bin
ary form must reproduce the above copyright\n notice, this list of conditio
ns and the following disclaimer in the\n documentation and/or other materia
ls provided with the distribution.\n\n THIS SOFTWARE IS PROVIDED BY THE COPYRIG
HT HOLDERS AND CONTRIBUTORS \"AS IS\"\n AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE\n IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE\n ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT
HOLDER> BE LIABLE FOR ANY\n DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES\n (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBST
ITUTE GOODS OR SERVICES;\n LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPT
ION) HOWEVER CAUSED AND\n ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRI
CT LIABILITY, OR TORT\n (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF\n THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH D
AMAGE.\n*/\n\n(function (global) {\n 'use strict';\n\n var Token,\n
TokenName,\n Syntax,\n Messages,\n source,\n index,
\n length,\n delegate,\n lookahead,\n state;\n\n
Token = {\n BooleanLiteral: 1,\n EOF: 2,\n Identifier: 3,\n
Keyword: 4,\n NullLiteral: 5,\n NumericLiteral: 6,\n
Punctuator: 7,\n StringLiteral: 8\n };\n\n TokenName = {};\n T
okenName[Token.BooleanLiteral] = 'Boolean';\n TokenName[Token.EOF] = '<end>';
\n TokenName[Token.Identifier] = 'Identifier';\n TokenName[Token.Keyword]
= 'Keyword';\n TokenName[Token.NullLiteral] = 'Null';\n TokenName[Token.Nu
mericLiteral] = 'Numeric';\n TokenName[Token.Punctuator] = 'Punctuator';\n
TokenName[Token.StringLiteral] = 'String';\n\n Syntax = {\n ArrayExpr
ession: 'ArrayExpression',\n BinaryExpression: 'BinaryExpression',\n
CallExpression: 'CallExpression',\n ConditionalExpression: 'Conditiona
lExpression',\n EmptyStatement: 'EmptyStatement',\n ExpressionStat
ement: 'ExpressionStatement',\n Identifier: 'Identifier',\n Litera
l: 'Literal',\n LabeledStatement: 'LabeledStatement',\n LogicalExp
ression: 'LogicalExpression',\n MemberExpression: 'MemberExpression',\n
ObjectExpression: 'ObjectExpression',\n Program: 'Program',\n
Property: 'Property',\n ThisExpression: 'ThisExpression',\n Unar
yExpression: 'UnaryExpression'\n };\n\n // Error messages should be identi
cal to V8.\n Messages = {\n UnexpectedToken: 'Unexpected token %0',\n
UnknownLabel: 'Undefined label \\'%0\\'',\n Redeclaration: '%0 \\
'%1\\' has already been declared'\n };\n\n // Ensure the condition is true
, otherwise throw an error.\n // This is only to have a better contract seman
tic, i.e. another safety net\n // to catch a logic error. The condition shall
be fulfilled in normal case.\n // Do NOT use this to enforce a certain condi
tion on any user input.\n\n function assert(condition, message) {\n if
(!condition) {\n throw new Error('ASSERT: ' + message);\n }\n
}\n\n function isDecimalDigit(ch) {\n return (ch >= 48 && ch <= 57
); // 0..9\n }\n\n\n // 7.2 White Space\n\n function isWhiteSpace(ch)
{\n return (ch === 32) || // space\n (ch === 9) || // t
ab\n (ch === 0xB) ||\n (ch === 0xC) ||\n (ch ==
= 0xA0) ||\n (ch >= 0x1680 && '\\u1680\\u180E\\u2000\\u2001\\u2002\\u
2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200A\\u202F\\u205F\\u3000\\uFEF
F'.indexOf(String.fromCharCode(ch)) > 0);\n }\n\n // 7.3 Line Terminators\
n\n function isLineTerminator(ch) {\n return (ch === 10) || (ch === 13
) || (ch === 0x2028) || (ch === 0x2029);\n }\n\n // 7.6 Identifier Names a
nd Identifiers\n\n function isIdentifierStart(ch) {\n return (ch === 3
6) || (ch === 95) || // $ (dollar) and _ (underscore)\n (ch >= 65 &&
ch <= 90) || // A..Z\n (ch >= 97 && ch <= 122); //
a..z\n }\n\n function isIdentifierPart(ch) {\n return (ch === 36) |
| (ch === 95) || // $ (dollar) and _ (underscore)\n (ch >= 65 && ch
<= 90) || // A..Z\n (ch >= 97 && ch <= 122) || // a..z
\n (ch >= 48 && ch <= 57); // 0..9\n }\n\n // 7.6.1.1
Keywords\n\n function isKeyword(id) {\n return (id === 'this')\n }
\n\n // 7.4 Comments\n\n function skipWhitespace() {\n while (index
< length && isWhiteSpace(source.charCodeAt(index))) {\n ++index;\n
}\n }\n\n function getIdentifier() {\n var start, ch;\n\n
start = index++;\n while (index < length) {\n ch = source.c
harCodeAt(index);\n if (isIdentifierPart(ch)) {\n ++in
dex;\n } else {\n break;\n }\n }\n\n
return source.slice(start, index);\n }\n\n function scanIdentifier
() {\n var start, id, type;\n\n start = index;\n\n id = get
Identifier();\n\n // There is no keyword or literal with only one charact
er.\n // Thus, it must be an identifier.\n if (id.length === 1) {\
n type = Token.Identifier;\n } else if (isKeyword(id)) {\n
type = Token.Keyword;\n } else if (id === 'null') {\n
type = Token.NullLiteral;\n } else if (id === 'true' || id === 'false') {
\n type = Token.BooleanLiteral;\n } else {\n type =
Token.Identifier;\n }\n\n return {\n type: type,\n
value: id,\n range: [start, index]\n };\n }\n\n\n
// 7.7 Punctuators\n\n function scanPunctuator() {\n var start = ind
ex,\n code = source.charCodeAt(index),\n code2,\n
ch1 = source[index],\n ch2;\n\n switch (code) {\n\n
// Check for most common single-character punctuators.\n case 46: // .
dot\n case 40: // ( open bracket\n case 41: // ) close bracket
\n case 59: // ; semicolon\n case 44: // , comma\n case
123: // { open curly brace\n case 125: // } close curly brace\n
case 91: // [\n case 93: // ]\n case 58: // :\n case
63: // ?\n ++index;\n return {\n type: T
oken.Punctuator,\n value: String.fromCharCode(code),\n
range: [start, index]\n };\n\n default:\n code
2 = source.charCodeAt(index + 1);\n\n // '=' (char #61) marks an assi
gnment or comparison operator.\n if (code2 === 61) {\n
switch (code) {\n case 37: // %\n case 38: // &
\n case 42: // *:\n case 43: // +\n
case 45: // -\n case 47: // /\n case 60: //
<\n case 62: // >\n case 124: // |\n
index += 2;\n return {\n type:
Token.Punctuator,\n value: String.fromCharCode(code) + St
ring.fromCharCode(code2),\n range: [start, index]\n
};\n\n case 33: // !\n case 61: // =
\n index += 2;\n\n // !== and ===\n
if (source.charCodeAt(index) === 61) {\n ++i
ndex;\n }\n return {\n
type: Token.Punctuator,\n value: source.slice(start,
index),\n range: [start, index]\n };\n
default:\n break;\n }\n
}\n break;\n }\n\n // Peek more characters.\n\n
ch2 = source[index + 1];\n\n // Other 2-character punctuators: && ||
\n\n if (ch1 === ch2 && ('&|'.indexOf(ch1) >= 0)) {\n index +=
2;\n return {\n type: Token.Punctuator,\n
value: ch1 + ch2,\n range: [start, index]\n };\n
}\n\n if ('<>=!+-*%&|^/'.indexOf(ch1) >= 0) {\n ++index;
\n return {\n type: Token.Punctuator,\n
value: ch1,\n range: [start, index]\n };\n }\n
\n throwError({}, Messages.UnexpectedToken, 'ILLEGAL');\n }\n\n //
7.8.3 Numeric Literals\n function scanNumericLiteral() {\n var number,
start, ch;\n\n ch = source[index];\n assert(isDecimalDigit(ch.cha
rCodeAt(0)) || (ch === '.'),\n 'Numeric literal must start with a dec
imal digit or a decimal point');\n\n start = index;\n number = '';
\n if (ch !== '.') {\n number = source[index++];\n
ch = source[index];\n\n // Hex number starts with '0x'.\n
// Octal number starts with '0'.\n if (number === '0') {\n
// decimal number starts with '0' such as '09' is illegal.\n
if (ch && isDecimalDigit(ch.charCodeAt(0))) {\n throwError({
}, Messages.UnexpectedToken, 'ILLEGAL');\n }\n }\n\n
while (isDecimalDigit(source.charCodeAt(index))) {\n nu
mber += source[index++];\n }\n ch = source[index];\n
}\n\n if (ch === '.') {\n number += source[index++];\n
while (isDecimalDigit(source.charCodeAt(index))) {\n number
+= source[index++];\n }\n ch = source[index];\n }\
n\n if (ch === 'e' || ch === 'E') {\n number += source[index++
];\n\n ch = source[index];\n if (ch === '+' || ch === '-')
{\n number += source[index++];\n }\n if (i
sDecimalDigit(source.charCodeAt(index))) {\n while (isDecimalDigi
t(source.charCodeAt(index))) {\n number += source[index++];\n
}\n } else {\n throwError({}, Messages
.UnexpectedToken, 'ILLEGAL');\n }\n }\n\n if (isIdentif
ierStart(source.charCodeAt(index))) {\n throwError({}, Messages.Unexp
ectedToken, 'ILLEGAL');\n }\n\n return {\n type: Token.
NumericLiteral,\n value: parseFloat(number),\n range: [sta
rt, index]\n };\n }\n\n // 7.8.4 String Literals\n\n function sc
anStringLiteral() {\n var str = '', quote, start, ch, octal = false;\n\n
quote = source[index];\n assert((quote === '\\'' || quote === '\"'
),\n 'String literal must starts with a quote');\n\n start = i
ndex;\n ++index;\n\n while (index < length) {\n ch = so
urce[index++];\n\n if (ch === quote) {\n quote = '';\n
break;\n } else if (ch === '\\\\') {\n
ch = source[index++];\n if (!ch || !isLineTerminator(ch.charCode
At(0))) {\n switch (ch) {\n case 'n':\n
str += '\\n';\n break;\n
case 'r':\n str += '\\r';\n
break;\n case 't':\n str += '\\t';\n
break;\n case 'b':\n
str += '\\b';\n break;\n case '
f':\n str += '\\f';\n break;\n
case 'v':\n str += '\\x0B';\n
break;\n\n default:\n str
+= ch;\n break;\n }\n }
else {\n if (ch === '\\r' && source[index] === '\\n') {\n
++index;\n }\n }\n
} else if (isLineTerminator(ch.charCodeAt(0))) {\n break;\n
} else {\n str += ch;\n }\n }\n\n
if (quote !== '') {\n throwError({}, Messages.UnexpectedToken,
'ILLEGAL');\n }\n\n return {\n type: Token.StringLitera
l,\n value: str,\n octal: octal,\n range: [star
t, index]\n };\n }\n\n function isIdentifierName(token) {\n
return token.type === Token.Identifier ||\n token.type === Token.Keyw
ord ||\n token.type === Token.BooleanLiteral ||\n token.ty
pe === Token.NullLiteral;\n }\n\n function advance() {\n var ch;\n\
n skipWhitespace();\n\n if (index >= length) {\n return
{\n type: Token.EOF,\n range: [index, index]\n
};\n }\n\n ch = source.charCodeAt(index);\n\n // V
ery common: ( and ) and ;\n if (ch === 40 || ch === 41 || ch === 58) {\n
return scanPunctuator();\n }\n\n // String literal star
ts with single quote (#39) or double quote (#34).\n if (ch === 39 || ch =
== 34) {\n return scanStringLiteral();\n }\n\n if (isId
entifierStart(ch)) {\n return scanIdentifier();\n }\n\n
// Dot (.) char #46 can also start a floating-point number, hence the need\n
// to check the next character.\n if (ch === 46) {\n if (
isDecimalDigit(source.charCodeAt(index + 1))) {\n return scanNume
ricLiteral();\n }\n return scanPunctuator();\n }\n\
n if (isDecimalDigit(ch)) {\n return scanNumericLiteral();\n
}\n\n return scanPunctuator();\n }\n\n function lex() {\n
var token;\n\n token = lookahead;\n index = token.range[1];\n\
n lookahead = advance();\n\n index = token.range[1];\n\n re
turn token;\n }\n\n function peek() {\n var pos;\n\n pos = i
ndex;\n lookahead = advance();\n index = pos;\n }\n\n // Thr
ow an exception\n\n function throwError(token, messageFormat) {\n var
error,\n args = Array.prototype.slice.call(arguments, 2),\n
msg = messageFormat.replace(\n /%(\\d)/g,\n func
tion (whole, index) {\n assert(index < args.length, 'Message
reference must be in range');\n return args[index];\n
}\n );\n\n error = new Error(msg);\n error.inde
x = index;\n error.description = msg;\n throw error;\n }\n\n
// Throw an exception because of the token.\n\n function throwUnexpected(tok
en) {\n throwError(token, Messages.UnexpectedToken, token.value);\n }\
n\n // Expect the next token to match the specified punctuator.\n // If no
t, an exception will be thrown.\n\n function expect(value) {\n var tok
en = lex();\n if (token.type !== Token.Punctuator || token.value !== valu
e) {\n throwUnexpected(token);\n }\n }\n\n // Return tru
e if the next token matches the specified punctuator.\n\n function match(valu
e) {\n return lookahead.type === Token.Punctuator && lookahead.value ===
value;\n }\n\n // Return true if the next token matches the specified keyw
ord\n\n function matchKeyword(keyword) {\n return lookahead.type === T
oken.Keyword && lookahead.value === keyword;\n }\n\n function consumeSemic
olon() {\n // Catch the very common case first: immediately a semicolon (
char #59).\n if (source.charCodeAt(index) === 59) {\n lex();\n
return;\n }\n\n skipWhitespace();\n\n if (match
(';')) {\n lex();\n return;\n }\n\n if (look
ahead.type !== Token.EOF && !match('}')) {\n throwUnexpected(lookahea
d);\n }\n }\n\n // 11.1.4 Array Initialiser\n\n function parseAr
rayInitialiser() {\n var elements = [];\n\n expect('[');\n\n
while (!match(']')) {\n if (match(',')) {\n lex();\n
elements.push(null);\n } else {\n elem
ents.push(parseExpression());\n\n if (!match(']')) {\n
expect(',');\n }\n }\n }\n\n ex
pect(']');\n\n return delegate.createArrayExpression(elements);\n }\n\
n // 11.1.5 Object Initialiser\n\n function parseObjectPropertyKey() {\n
var token;\n\n skipWhitespace();\n token = lex();\n\n
// Note: This function is called only from parseObjectProperty(), where\n
// EOF and Punctuator tokens are already filtered out.\n if (token.type
=== Token.StringLiteral || token.type === Token.NumericLiteral) {\n
return delegate.createLiteral(token);\n }\n\n return delegate.crea
teIdentifier(token.value);\n }\n\n function parseObjectProperty() {\n
var token, key;\n\n token = lookahead;\n skipWhitespace();\n\n
if (token.type === Token.EOF || token.type === Token.Punctuator) {\n
throwUnexpected(token);\n }\n\n key = parseObjectPropertyKe
y();\n expect(':');\n return delegate.createProperty('init', key,
parseExpression());\n }\n\n function parseObjectInitialiser() {\n v
ar properties = [];\n\n expect('{');\n\n while (!match('}')) {\n
properties.push(parseObjectProperty());\n\n if (!match('}')
) {\n expect(',');\n }\n }\n\n expect('}
');\n\n return delegate.createObjectExpression(properties);\n }\n\n
// 11.1.6 The Grouping Operator\n\n function parseGroupExpression() {\n
var expr;\n\n expect('(');\n\n expr = parseExpression();\n\n
expect(')');\n\n return expr;\n }\n\n\n // 11.1 Primary Expres
sions\n\n function parsePrimaryExpression() {\n var type, token, expr;
\n\n if (match('(')) {\n return parseGroupExpression();\n
}\n\n type = lookahead.type;\n\n if (type === Token.Identifier)
{\n expr = delegate.createIdentifier(lex().value);\n } else i
f (type === Token.StringLiteral || type === Token.NumericLiteral) {\n
expr = delegate.createLiteral(lex());\n } else if (type === Token.Keywor
d) {\n if (matchKeyword('this')) {\n lex();\n
expr = delegate.createThisExpression();\n }\n } else if
(type === Token.BooleanLiteral) {\n token = lex();\n toke
n.value = (token.value === 'true');\n expr = delegate.createLiteral(t
oken);\n } else if (type === Token.NullLiteral) {\n token = le
x();\n token.value = null;\n expr = delegate.createLiteral
(token);\n } else if (match('[')) {\n expr = parseArrayInitial
iser();\n } else if (match('{')) {\n expr = parseObjectInitial
iser();\n }\n\n if (expr) {\n return expr;\n }\n
\n throwUnexpected(lex());\n }\n\n // 11.2 Left-Hand-Side Expressio
ns\n\n function parseArguments() {\n var args = [];\n\n expect(
'(');\n\n if (!match(')')) {\n while (index < length) {\n
args.push(parseExpression());\n if (match(')')) {\n
break;\n }\n expect(',');\n
}\n }\n\n expect(')');\n\n return args;\n }\n\n
function parseNonComputedProperty() {\n var token;\n\n token = le
x();\n\n if (!isIdentifierName(token)) {\n throwUnexpected(tok
en);\n }\n\n return delegate.createIdentifier(token.value);\n }
\n\n function parseNonComputedMember() {\n expect('.');\n\n ret
urn parseNonComputedProperty();\n }\n\n function parseComputedMember() {\n
var expr;\n\n expect('[');\n\n expr = parseExpression();\n
\n expect(']');\n\n return expr;\n }\n\n function parseLeftH
andSideExpression() {\n var expr, property;\n\n expr = parsePrimar
yExpression();\n\n while (match('.') || match('[')) {\n if (ma
tch('[')) {\n property = parseComputedMember();\n
expr = delegate.createMemberExpression('[', expr, property);\n } else
{\n property = parseNonComputedMember();\n expr =
delegate.createMemberExpression('.', expr, property);\n }\n }
\n\n return expr;\n }\n\n // 11.3 Postfix Expressions\n\n var pa
rsePostfixExpression = parseLeftHandSideExpression;\n\n // 11.4 Unary Operato
rs\n\n function parseUnaryExpression() {\n var token, expr;\n\n
if (lookahead.type !== Token.Punctuator && lookahead.type !== Token.Keyword) {\
n expr = parsePostfixExpression();\n } else if (match('+') ||
match('-') || match('!')) {\n token = lex();\n expr = pars
eUnaryExpression();\n expr = delegate.createUnaryExpression(token.val
ue, expr);\n } else if (matchKeyword('delete') || matchKeyword('void') ||
matchKeyword('typeof')) {\n throwError({}, Messages.UnexpectedToken)
;\n } else {\n expr = parsePostfixExpression();\n }\n\n
return expr;\n }\n\n function binaryPrecedence(token) {\n v
ar prec = 0;\n\n if (token.type !== Token.Punctuator && token.type !== To
ken.Keyword) {\n return 0;\n }\n\n switch (token.value)
{\n case '||':\n prec = 1;\n break;\n\n cas
e '&&':\n prec = 2;\n break;\n\n case '==':\n
case '!=':\n case '===':\n case '!==':\n prec = 6;\n
break;\n\n case '<':\n case '>':\n case '<=':\n
case '>=':\n case 'instanceof':\n prec = 7;\n
break;\n\n case 'in':\n prec = 7;\n break;\n\n
case '+':\n case '-':\n prec = 9;\n break;\n\n
case '*':\n case '/':\n case '%':\n prec = 11;\
n break;\n\n default:\n break;\n }\n\n
return prec;\n }\n\n // 11.5 Multiplicative Operators\n // 11.6 Addit
ive Operators\n // 11.7 Bitwise Shift Operators\n // 11.8 Relational Opera
tors\n // 11.9 Equality Operators\n // 11.10 Binary Bitwise Operators\n
// 11.11 Binary Logical Operators\n\n function parseBinaryExpression() {\n
var expr, token, prec, stack, right, operator, left, i;\n\n left =
parseUnaryExpression();\n\n token = lookahead;\n prec = binaryPrec
edence(token);\n if (prec === 0) {\n return left;\n }\n
token.prec = prec;\n lex();\n\n right = parseUnaryExpressi
on();\n\n stack = [left, token, right];\n\n while ((prec = binaryP
recedence(lookahead)) > 0) {\n\n // Reduce: make a binary expression
from the three topmost entries.\n while ((stack.length > 2) && (prec
<= stack[stack.length - 2].prec)) {\n right = stack.pop();\n
operator = stack.pop().value;\n left = stack.pop();\n
expr = delegate.createBinaryExpression(operator, left, right);\n
stack.push(expr);\n }\n\n // Shift.\n
token = lex();\n token.prec = prec;\n stack.push(tok
en);\n expr = parseUnaryExpression();\n stack.push(expr);\
n }\n\n // Final reduce to clean-up the stack.\n i = stack.
length - 1;\n expr = stack[i];\n while (i > 1) {\n expr
= delegate.createBinaryExpression(stack[i - 1].value, stack[i - 2], expr);\n
i -= 2;\n }\n\n return expr;\n }\n\n\n // 11.12 Con
ditional Operator\n\n function parseConditionalExpression() {\n var ex
pr, consequent, alternate;\n\n expr = parseBinaryExpression();\n\n
if (match('?')) {\n lex();\n consequent = parseConditiona
lExpression();\n expect(':');\n alternate = parseCondition
alExpression();\n\n expr = delegate.createConditionalExpression(expr,
consequent, alternate);\n }\n\n return expr;\n }\n\n // Sim
plification since we do not support AssignmentExpression.\n var parseExpressi
on = parseConditionalExpression;\n\n // Polymer Syntax extensions\n\n // F
ilter ::\n // Identifier\n // Identifier \"(\" \")\"\n // Identif
ier \"(\" FilterArguments \")\"\n\n function parseFilter() {\n var ide
ntifier, args;\n\n identifier = lex();\n\n if (identifier.type !==
Token.Identifier) {\n throwUnexpected(identifier);\n }\n\n
args = match('(') ? parseArguments() : [];\n\n return delegate.creat
eFilter(identifier.value, args);\n }\n\n // Filters ::\n // \"|\" Fil
ter\n // Filters \"|\" Filter\n\n function parseFilters() {\n whi
le (match('|')) {\n lex();\n parseFilter();\n }\n
}\n\n // TopLevel ::\n // LabelledExpressions\n // AsExpression\n
// InExpression\n // FilterExpression\n\n // AsExpression ::\n
// FilterExpression as Identifier\n\n // InExpression ::\n // Identifi
er, Identifier in FilterExpression\n // Identifier in FilterExpression\n\n
// FilterExpression ::\n // Expression\n // Expression Filters\n\n
function parseTopLevel() {\n skipWhitespace();\n peek();\n\n
var expr = parseExpression();\n if (expr) {\n if (lookahe
ad.value === ',' || lookahead.value == 'in' &&\n expr.type
=== Syntax.Identifier) {\n parseInExpression(expr);\n
} else {\n parseFilters();\n if (lookahead.value
=== 'as') {\n parseAsExpression(expr);\n } els
e {\n delegate.createTopLevel(expr);\n }\n
}\n }\n\n if (lookahead.type !== Token.EOF) {\n
throwUnexpected(lookahead);\n }\n }\n\n function parseAsExpression
(expr) {\n lex(); // as\n var identifier = lex().value;\n
delegate.createAsExpression(expr, identifier);\n }\n\n function parseInExp
ression(identifier) {\n var indexName;\n if (lookahead.value === '
,') {\n lex();\n if (lookahead.type !== Token.Identifier)\
n throwUnexpected(lookahead);\n indexName = lex().valu
e;\n }\n\n lex(); // in\n var expr = parseExpression();\n
parseFilters();\n delegate.createInExpression(identifier.name, ind
exName, expr);\n }\n\n function parse(code, inDelegate) {\n delegat
e = inDelegate;\n source = code;\n index = 0;\n length = so
urce.length;\n lookahead = null;\n state = {\n labelSet
: {}\n };\n\n return parseTopLevel();\n }\n\n global.esprima
= {\n parse: parse\n };\n})(this);\n", |
207 "// Copyright (c) 2014 The Polymer Project Authors. All rights reserved.\n//
This code may only be used under the BSD style license found at http://polymer.
github.io/LICENSE.txt\n// The complete set of authors may be found at http://pol
ymer.github.io/AUTHORS.txt\n// The complete set of contributors may be found at
http://polymer.github.io/CONTRIBUTORS.txt\n// Code distributed by Google as part
of the polymer project is also\n// subject to an additional IP rights grant fou
nd at http://polymer.github.io/PATENTS.txt\n\n(function (global) {\n 'use stric
t';\n\n // JScript does not have __proto__. We wrap all object literals with\n
// createObject which uses Object.create, Object.defineProperty and\n // Objec
t.getOwnPropertyDescriptor to create a new object that does the exact\n // same
thing. The main downside to this solution is that we have to extract\n // all
those property descriptors for IE.\n var createObject = ('__proto__' in {}) ?\n
function(obj) { return obj; } :\n function(obj) {\n var proto
= obj.__proto__;\n if (!proto)\n return obj;\n var newObj
ect = Object.create(proto);\n Object.getOwnPropertyNames(obj).forEach(fun
ction(name) {\n Object.defineProperty(newObject, name,\n
Object.getOwnPropertyDescriptor(obj, name));\n });\n
return newObject;\n };\n\n function prepareBinding(expressionText, name
, node, filterRegistry) {\n var expression;\n try {\n expression = ge
tExpression(expressionText);\n if (expression.scopeIdent &&\n (nod
e.nodeType !== Node.ELEMENT_NODE ||\n node.tagName !== 'TEMPLATE' ||\n
(name !== 'bind' && name !== 'repeat'))) {\n throw Error('as a
nd in can only be used within <template bind/repeat>');\n }\n } catch (e
x) {\n console.error('Invalid expression syntax: ' + expressionText, ex);\n
return;\n }\n\n return function(model, node, oneTime) {\n var b
inding = expression.getBinding(model, filterRegistry, oneTime);\n if (expre
ssion.scopeIdent && binding) {\n node.polymerExpressionScopeIdent_ = expr
ession.scopeIdent;\n if (expression.indexIdent)\n node.polymerEx
pressionIndexIdent_ = expression.indexIdent;\n }\n\n return binding;\n
}\n }\n\n // TODO(rafaelw): Implement simple LRU.\n var expressionParseCa
che = Object.create(null);\n\n function getExpression(expressionText) {\n va
r expression = expressionParseCache[expressionText];\n if (!expression) {\n
var delegate = new ASTDelegate();\n esprima.parse(expressionText, deleg
ate);\n expression = new Expression(delegate);\n expressionParseCache[
expressionText] = expression;\n }\n return expression;\n }\n\n function
Literal(value) {\n this.value = value;\n this.valueFn_ = undefined;\n }\n
\n Literal.prototype = {\n valueFn: function() {\n if (!this.valueFn_)
{\n var value = this.value;\n this.valueFn_ = function() {\n
return value;\n }\n }\n\n return this.valueFn_;\n }\n }
\n\n function IdentPath(name) {\n this.name = name;\n this.path = Path.ge
t(name);\n }\n\n IdentPath.prototype = {\n valueFn: function() {\n if
(!this.valueFn_) {\n var name = this.name;\n var path = this.path;
\n this.valueFn_ = function(model, observer) {\n if (observer)\n
observer.addPath(model, path);\n\n return path.getValueFrom
(model);\n }\n }\n\n return this.valueFn_;\n },\n\n setVa
lue: function(model, newValue) {\n if (this.path.length == 1);\n mod
el = findScope(model, this.path[0]);\n\n return this.path.setValueFrom(mode
l, newValue);\n }\n };\n\n function MemberExpression(object, property, acce
ssor) {\n // convert literal computed property access where literal value is
a value\n // path to ident dot-access.\n if (accessor == '[' &&\n p
roperty instanceof Literal &&\n Path.get(property.value).valid) {\n
accessor = '.';\n property = new IdentPath(property.value);\n }\n\n t
his.dynamicDeps = typeof object == 'function' || object.dynamic;\n\n this.dyn
amic = typeof property == 'function' ||\n property.dynamic ||\
n accessor == '[';\n\n this.simplePath =\n !this.dyn
amic &&\n !this.dynamicDeps &&\n property instanceof IdentPath &&\
n (object instanceof MemberExpression || object instanceof IdentPath);\n\
n this.object = this.simplePath ? object : getFn(object);\n this.property
= accessor == '.' ? property : getFn(property);\n }\n\n MemberExpression.proto
type = {\n get fullPath() {\n if (!this.fullPath_) {\n var last =
this.object instanceof IdentPath ?\n this.object.name : this.object.
fullPath;\n this.fullPath_ = Path.get(last + '.' + this.property.name);\n
}\n\n return this.fullPath_;\n },\n\n valueFn: function() {\n
if (!this.valueFn_) {\n var object = this.object;\n\n if (this
.simplePath) {\n var path = this.fullPath;\n\n this.valueFn_ =
function(model, observer) {\n if (observer)\n observer.
addPath(model, path);\n\n return path.getValueFrom(model);\n
};\n } else if (this.property instanceof IdentPath) {\n var pat
h = Path.get(this.property.name);\n\n this.valueFn_ = function(model, o
bserver) {\n var context = object(model, observer);\n\n if
(observer)\n observer.addPath(context, path);\n\n retur
n path.getValueFrom(context);\n }\n } else {\n // Compu
ted property.\n var property = this.property;\n\n this.valueFn
_ = function(model, observer) {\n var context = object(model, observe
r);\n var propName = property(model, observer);\n if (obse
rver)\n observer.addPath(context, propName);\n\n return
context ? context[propName] : undefined;\n };\n }\n }\n
return this.valueFn_;\n },\n\n setValue: function(model, newValue) {\n
if (this.simplePath) {\n this.fullPath.setValueFrom(model, newValue);
\n return newValue;\n }\n\n var object = this.object(model);\n
var propName = this.property instanceof IdentPath ? this.property.name :\n
this.property(model);\n return object[propName] = newValue;\n }
\n };\n\n function Filter(name, args) {\n this.name = name;\n this.args
= [];\n for (var i = 0; i < args.length; i++) {\n this.args[i] = getFn(a
rgs[i]);\n }\n }\n\n Filter.prototype = {\n transform: function(value, t
oModelDirection, filterRegistry, model,\n observer) {\n
var fn = filterRegistry[this.name];\n var context = model;\n if (f
n) {\n context = undefined;\n } else {\n fn = context[this.na
me];\n if (!fn) {\n console.error('Cannot find filter: ' + this.
name);\n return;\n }\n }\n\n // If toModelDirection is
falsey, then the \"normal\" (dom-bound) direction\n // is used. Otherwise,
it looks for a 'toModel' property function on the\n // object.\n if (
toModelDirection) {\n fn = fn.toModel;\n } else if (typeof fn.toDOM
== 'function') {\n fn = fn.toDOM;\n }\n\n if (typeof fn != 'fun
ction') {\n console.error('No ' + (toModelDirection ? 'toModel' : 'toDOM'
) +\n ' found on' + this.name);\n return;\n }\n
\n var args = [value];\n for (var i = 0; i < this.args.length; i++) {\
n args[i + 1] = getFn(this.args[i])(model, observer);\n }\n\n r
eturn fn.apply(context, args);\n }\n };\n\n function notImplemented() { thr
ow Error('Not Implemented'); }\n\n var unaryOperators = {\n '+': function(v)
{ return +v; },\n '-': function(v) { return -v; },\n '!': function(v) { r
eturn !v; }\n };\n\n var binaryOperators = {\n '+': function(l, r) { return
l+r; },\n '-': function(l, r) { return l-r; },\n '*': function(l, r) { re
turn l*r; },\n '/': function(l, r) { return l/r; },\n '%': function(l, r)
{ return l%r; },\n '<': function(l, r) { return l<r; },\n '>': function(l,
r) { return l>r; },\n '<=': function(l, r) { return l<=r; },\n '>=': func
tion(l, r) { return l>=r; },\n '==': function(l, r) { return l==r; },\n '!
=': function(l, r) { return l!=r; },\n '===': function(l, r) { return l===r;
},\n '!==': function(l, r) { return l!==r; },\n '&&': function(l, r) { ret
urn l&&r; },\n '||': function(l, r) { return l||r; },\n };\n\n function get
Fn(arg) {\n return typeof arg == 'function' ? arg : arg.valueFn();\n }\n\n
function ASTDelegate() {\n this.expression = null;\n this.filters = [];\n
this.deps = {};\n this.currentPath = undefined;\n this.scopeIdent = und
efined;\n this.indexIdent = undefined;\n this.dynamicDeps = false;\n }\n\
n ASTDelegate.prototype = {\n createUnaryExpression: function(op, argument)
{\n if (!unaryOperators[op])\n throw Error('Disallowed operator: ' +
op);\n\n argument = getFn(argument);\n\n return function(model, obser
ver) {\n return unaryOperators[op](argument(model, observer));\n };\
n },\n\n createBinaryExpression: function(op, left, right) {\n if (!b
inaryOperators[op])\n throw Error('Disallowed operator: ' + op);\n\n
left = getFn(left);\n right = getFn(right);\n\n return function(model
, observer) {\n return binaryOperators[op](left(model, observer),\n
right(model, observer));\n };\n },\n\n c
reateConditionalExpression: function(test, consequent, alternate) {\n test
= getFn(test);\n consequent = getFn(consequent);\n alternate = getFn(a
lternate);\n\n return function(model, observer) {\n return test(mode
l, observer) ?\n consequent(model, observer) : alternate(model, obser
ver);\n }\n },\n\n createIdentifier: function(name) {\n var iden
t = new IdentPath(name);\n ident.type = 'Identifier';\n return ident;\
n },\n\n createMemberExpression: function(accessor, object, property) {\n
var ex = new MemberExpression(object, property, accessor);\n if (ex.dy
namicDeps)\n this.dynamicDeps = true;\n return ex;\n },\n\n cr
eateLiteral: function(token) {\n return new Literal(token.value);\n },\n
\n createArrayExpression: function(elements) {\n for (var i = 0; i < ele
ments.length; i++)\n elements[i] = getFn(elements[i]);\n\n return fu
nction(model, observer) {\n var arr = []\n for (var i = 0; i < ele
ments.length; i++)\n arr.push(elements[i](model, observer));\n r
eturn arr;\n }\n },\n\n createProperty: function(kind, key, value) {\
n return {\n key: key instanceof IdentPath ? key.name : key.value,\n
value: value\n };\n },\n\n createObjectExpression: function(p
roperties) {\n for (var i = 0; i < properties.length; i++)\n propert
ies[i].value = getFn(properties[i].value);\n\n return function(model, obser
ver) {\n var obj = {};\n for (var i = 0; i < properties.length; i+
+)\n obj[properties[i].key] = properties[i].value(model, observer);\n
return obj;\n }\n },\n\n createFilter: function(name, args) {\n
this.filters.push(new Filter(name, args));\n },\n\n createAsExpressi
on: function(expression, scopeIdent) {\n this.expression = expression;\n
this.scopeIdent = scopeIdent;\n },\n\n createInExpression: function(sco
peIdent, indexIdent, expression) {\n this.expression = expression;\n t
his.scopeIdent = scopeIdent;\n this.indexIdent = indexIdent;\n },\n\n
createTopLevel: function(expression) {\n this.expression = expression;\n
},\n\n createThisExpression: notImplemented\n }\n\n function ConstantObse
rvable(value) {\n this.value_ = value;\n }\n\n ConstantObservable.prototype
= {\n open: function() { return this.value_; },\n discardChanges: functio
n() { return this.value_; },\n deliver: function() {},\n close: function()
{},\n }\n\n function Expression(delegate) {\n this.scopeIdent = delegate.s
copeIdent;\n this.indexIdent = delegate.indexIdent;\n\n if (!delegate.expr
ession)\n throw Error('No expression found.');\n\n this.expression = del
egate.expression;\n getFn(this.expression); // forces enumeration of path dep
endencies\n\n this.filters = delegate.filters;\n this.dynamicDeps = delega
te.dynamicDeps;\n }\n\n Expression.prototype = {\n getBinding: function(mod
el, filterRegistry, oneTime) {\n if (oneTime)\n return this.getValue
(model, undefined, filterRegistry);\n\n var observer = new CompoundObserver
();\n // captures deps.\n var firstValue = this.getValue(model, observ
er, filterRegistry);\n var firstTime = true;\n var self = this;\n\n
function valueFn() {\n // deps cannot have changed on first value retr
ieval.\n if (firstTime) {\n firstTime = false;\n return
firstValue;\n }\n\n if (self.dynamicDeps)\n observer.sta
rtReset();\n\n var value = self.getValue(model,\n
self.dynamicDeps ? observer : undefined,\n
filterRegistry);\n if (self.dynamicDeps)\n observer.finish
Reset();\n\n return value;\n }\n\n function setValueFn(newValue
) {\n self.setValue(model, newValue, filterRegistry);\n return new
Value;\n }\n\n return new ObserverTransform(observer, valueFn, setValu
eFn, true);\n },\n\n getValue: function(model, observer, filterRegistry) {
\n var value = getFn(this.expression)(model, observer);\n for (var i =
0; i < this.filters.length; i++) {\n value = this.filters[i].transform(v
alue, false, filterRegistry, model,\n o
bserver);\n }\n\n return value;\n },\n\n setValue: function(mode
l, newValue, filterRegistry) {\n var count = this.filters ? this.filters.le
ngth : 0;\n while (count-- > 0) {\n newValue = this.filters[count].t
ransform(newValue, true, filterRegistry,\n
model);\n }\n\n if (this.expression.setValue)\n retu
rn this.expression.setValue(model, newValue);\n }\n }\n\n /**\n * Convert
s a style property name to a css property name. For example:\n * \"WebkitUserS
elect\" to \"-webkit-user-select\"\n */\n function convertStylePropertyName(n
ame) {\n return String(name).replace(/[A-Z]/g, function(c) {\n return '-
' + c.toLowerCase();\n });\n }\n\n function isEventHandler(name) {\n ret
urn name[0] === 'o' &&\n name[1] === 'n' &&\n name[2] === '-
';\n }\n\n var mixedCaseEventTypes = {};\n [\n 'webkitAnimationStart',\n
'webkitAnimationEnd',\n 'webkitTransitionEnd',\n 'DOMFocusOut',\n 'DO
MFocusIn',\n 'DOMMouseScroll'\n ].forEach(function(e) {\n mixedCaseEventT
ypes[e.toLowerCase()] = e;\n });\n\n var parentScopeName = '@' + Math.random()
.toString(36).slice(2);\n\n // Single ident paths must bind directly to the app
ropriate scope object.\n // I.e. Pushed values in two-bindings need to be assig
ned to the actual model\n // object.\n function findScope(model, prop) {\n
while (model[parentScopeName] &&\n !Object.prototype.hasOwnProperty.ca
ll(model, prop)) {\n model = model[parentScopeName];\n }\n\n return m
odel;\n }\n\n function resolveEventReceiver(model, path, node) {\n if (path
.length == 0)\n return undefined;\n\n if (path.length == 1)\n retur
n findScope(model, path[0]);\n\n for (var i = 0; model != null && i < path.le
ngth - 1; i++) {\n model = model[path[i]];\n }\n\n return model;\n }
\n\n function prepareEventBinding(path, name, polymerExpressions) {\n var ev
entType = name.substring(3);\n eventType = mixedCaseEventTypes[eventType] ||
eventType;\n\n return function(model, node, oneTime) {\n var fn, receive
r, handler;\n if (typeof polymerExpressions.resolveEventHandler == 'functio
n') {\n handler = function(e) {\n fn = fn || polymerExpressions.
resolveEventHandler(model, path, node);\n fn(e, e.detail, e.currentTarg
et);\n\n if (Platform && typeof Platform.flush == 'function')\n
Platform.flush();\n };\n } else {\n handler = function(e)
{\n fn = fn || path.getValueFrom(model);\n receiver = receive
r || resolveEventReceiver(model, path, node);\n\n fn.apply(receiver, [e
, e.detail, e.currentTarget]);\n\n if (Platform && typeof Platform.flus
h == 'function')\n Platform.flush();\n };\n }\n\n no
de.addEventListener(eventType, handler);\n\n if (oneTime)\n return;\
n\n function bindingValue() {\n return '{{ ' + path + ' }}';\n
}\n\n return {\n open: bindingValue,\n discardChanges: bindin
gValue,\n close: function() {\n node.removeEventListener(eventTy
pe, handler);\n }\n };\n }\n }\n\n function isLiteralExpression
(pathString) {\n switch (pathString) {\n case '':\n return false;
\n\n case 'false':\n case 'null':\n case 'true':\n return
true;\n }\n\n if (!isNaN(Number(pathString)))\n return true;\n\n r
eturn false;\n };\n\n function PolymerExpressions() {}\n\n PolymerExpressions
.prototype = {\n // \"built-in\" filters\n styleObject: function(value) {\
n var parts = [];\n for (var key in value) {\n parts.push(conve
rtStylePropertyName(key) + ': ' + value[key]);\n }\n return parts.join
('; ');\n },\n\n tokenList: function(value) {\n var tokens = [];\n
for (var key in value) {\n if (value[key])\n tokens.push(key)
;\n }\n return tokens.join(' ');\n },\n\n // binding delegate AP
I\n prepareInstancePositionChanged: function(template) {\n var indexIden
t = template.polymerExpressionIndexIdent_;\n if (!indexIdent)\n retu
rn;\n\n return function(templateInstance, index) {\n templateInstanc
e.model[indexIdent] = index;\n };\n },\n\n prepareBinding: function(p
athString, name, node) {\n var path = Path.get(pathString);\n if (isEv
entHandler(name)) {\n if (!path.valid) {\n console.error('on-* b
indings must be simple path expressions');\n return;\n }\n\n
return prepareEventBinding(path, name, this);\n }\n\n if (!isLiter
alExpression(pathString) && path.valid) {\n if (path.length == 1) {\n
return function(model, node, oneTime) {\n if (oneTime)\n
return path.getValueFrom(model);\n\n var scope = findScope(mod
el, path[0]);\n return new PathObserver(scope, path);\n };\n
}\n return; // bail out early if pathString is simple path.\n
}\n\n return prepareBinding(pathString, name, node, this);\n },\n\n
prepareInstanceModel: function(template) {\n var scopeName = template.poly
merExpressionScopeIdent_;\n if (!scopeName)\n return;\n\n var p
arentScope = template.templateInstance ?\n template.templateInstance.mo
del :\n template.model;\n\n var indexName = template.polymerExpres
sionIndexIdent_;\n\n return function(model) {\n var scope = Object.c
reate(parentScope);\n scope[scopeName] = model;\n scope[indexName]
= undefined;\n scope[parentScopeName] = parentScope;\n return sco
pe;\n };\n }\n };\n\n global.PolymerExpressions = PolymerExpressions;\
n if (global.exposeGetExpression)\n global.getExpression_ = getExpression;\n
\n global.PolymerExpressions.prepareEventBinding = prepareEventBinding;\n})(thi
s);\n", | 207 "// Copyright (c) 2014 The Polymer Project Authors. All rights reserved.\n//
This code may only be used under the BSD style license found at http://polymer.
github.io/LICENSE.txt\n// The complete set of authors may be found at http://pol
ymer.github.io/AUTHORS.txt\n// The complete set of contributors may be found at
http://polymer.github.io/CONTRIBUTORS.txt\n// Code distributed by Google as part
of the polymer project is also\n// subject to an additional IP rights grant fou
nd at http://polymer.github.io/PATENTS.txt\n\n(function (global) {\n 'use stric
t';\n\n // JScript does not have __proto__. We wrap all object literals with\n
// createObject which uses Object.create, Object.defineProperty and\n // Objec
t.getOwnPropertyDescriptor to create a new object that does the exact\n // same
thing. The main downside to this solution is that we have to extract\n // all
those property descriptors for IE.\n var createObject = ('__proto__' in {}) ?\n
function(obj) { return obj; } :\n function(obj) {\n var proto
= obj.__proto__;\n if (!proto)\n return obj;\n var newObj
ect = Object.create(proto);\n Object.getOwnPropertyNames(obj).forEach(fun
ction(name) {\n Object.defineProperty(newObject, name,\n
Object.getOwnPropertyDescriptor(obj, name));\n });\n
return newObject;\n };\n\n function prepareBinding(expressionText, name
, node, filterRegistry) {\n var expression;\n try {\n expression = ge
tExpression(expressionText);\n if (expression.scopeIdent &&\n (nod
e.nodeType !== Node.ELEMENT_NODE ||\n node.tagName !== 'TEMPLATE' ||\n
(name !== 'bind' && name !== 'repeat'))) {\n throw Error('as a
nd in can only be used within <template bind/repeat>');\n }\n } catch (e
x) {\n console.error('Invalid expression syntax: ' + expressionText, ex);\n
return;\n }\n\n return function(model, node, oneTime) {\n var b
inding = expression.getBinding(model, filterRegistry, oneTime);\n if (expre
ssion.scopeIdent && binding) {\n node.polymerExpressionScopeIdent_ = expr
ession.scopeIdent;\n if (expression.indexIdent)\n node.polymerEx
pressionIndexIdent_ = expression.indexIdent;\n }\n\n return binding;\n
}\n }\n\n // TODO(rafaelw): Implement simple LRU.\n var expressionParseCa
che = Object.create(null);\n\n function getExpression(expressionText) {\n va
r expression = expressionParseCache[expressionText];\n if (!expression) {\n
var delegate = new ASTDelegate();\n esprima.parse(expressionText, deleg
ate);\n expression = new Expression(delegate);\n expressionParseCache[
expressionText] = expression;\n }\n return expression;\n }\n\n function
Literal(value) {\n this.value = value;\n this.valueFn_ = undefined;\n }\n
\n Literal.prototype = {\n valueFn: function() {\n if (!this.valueFn_)
{\n var value = this.value;\n this.valueFn_ = function() {\n
return value;\n }\n }\n\n return this.valueFn_;\n }\n }
\n\n function IdentPath(name) {\n this.name = name;\n this.path = Path.ge
t(name);\n }\n\n IdentPath.prototype = {\n valueFn: function() {\n if
(!this.valueFn_) {\n var name = this.name;\n var path = this.path;
\n this.valueFn_ = function(model, observer) {\n if (observer)\n
observer.addPath(model, path);\n\n return path.getValueFrom
(model);\n }\n }\n\n return this.valueFn_;\n },\n\n setVa
lue: function(model, newValue) {\n if (this.path.length == 1);\n mod
el = findScope(model, this.path[0]);\n\n return this.path.setValueFrom(mode
l, newValue);\n }\n };\n\n function MemberExpression(object, property, acce
ssor) {\n // convert literal computed property access where literal value is
a value\n // path to ident dot-access.\n if (accessor == '[' &&\n p
roperty instanceof Literal &&\n Path.get(property.value).valid) {\n
accessor = '.';\n property = new IdentPath(property.value);\n }\n\n t
his.dynamicDeps = typeof object == 'function' || object.dynamic;\n\n this.dyn
amic = typeof property == 'function' ||\n property.dynamic ||\
n accessor == '[';\n\n this.simplePath =\n !this.dyn
amic &&\n !this.dynamicDeps &&\n property instanceof IdentPath &&\
n (object instanceof MemberExpression || object instanceof IdentPath);\n\
n this.object = this.simplePath ? object : getFn(object);\n this.property
= accessor == '.' ? property : getFn(property);\n }\n\n MemberExpression.proto
type = {\n get fullPath() {\n if (!this.fullPath_) {\n var last =
this.object instanceof IdentPath ?\n this.object.name : this.object.
fullPath;\n this.fullPath_ = Path.get(last + '.' + this.property.name);\n
}\n\n return this.fullPath_;\n },\n\n valueFn: function() {\n
if (!this.valueFn_) {\n var object = this.object;\n\n if (this
.simplePath) {\n var path = this.fullPath;\n\n this.valueFn_ =
function(model, observer) {\n if (observer)\n observer.
addPath(model, path);\n\n return path.getValueFrom(model);\n
};\n } else if (this.property instanceof IdentPath) {\n var pat
h = Path.get(this.property.name);\n\n this.valueFn_ = function(model, o
bserver) {\n var context = object(model, observer);\n\n if
(observer)\n observer.addPath(context, path);\n\n retur
n path.getValueFrom(context);\n }\n } else {\n // Compu
ted property.\n var property = this.property;\n\n this.valueFn
_ = function(model, observer) {\n var context = object(model, observe
r);\n var propName = property(model, observer);\n if (obse
rver)\n observer.addPath(context, propName);\n\n return
context ? context[propName] : undefined;\n };\n }\n }\n
return this.valueFn_;\n },\n\n setValue: function(model, newValue) {\n
if (this.simplePath) {\n this.fullPath.setValueFrom(model, newValue);
\n return newValue;\n }\n\n var object = this.object(model);\n
var propName = this.property instanceof IdentPath ? this.property.name :\n
this.property(model);\n return object[propName] = newValue;\n }
\n };\n\n function Filter(name, args) {\n this.name = name;\n this.args
= [];\n for (var i = 0; i < args.length; i++) {\n this.args[i] = getFn(a
rgs[i]);\n }\n }\n\n Filter.prototype = {\n transform: function(value, t
oModelDirection, filterRegistry, model,\n observer) {\n
var fn = filterRegistry[this.name];\n var context = model;\n if (f
n) {\n context = undefined;\n } else {\n fn = context[this.na
me];\n if (!fn) {\n console.error('Cannot find filter: ' + this.
name);\n return;\n }\n }\n\n // If toModelDirection is
falsey, then the \"normal\" (dom-bound) direction\n // is used. Otherwise,
it looks for a 'toModel' property function on the\n // object.\n if (
toModelDirection) {\n fn = fn.toModel;\n } else if (typeof fn.toDOM
== 'function') {\n fn = fn.toDOM;\n }\n\n if (typeof fn != 'fun
ction') {\n console.error('No ' + (toModelDirection ? 'toModel' : 'toDOM'
) +\n ' found on' + this.name);\n return;\n }\n
\n var args = [value];\n for (var i = 0; i < this.args.length; i++) {\
n args[i + 1] = getFn(this.args[i])(model, observer);\n }\n\n r
eturn fn.apply(context, args);\n }\n };\n\n function notImplemented() { thr
ow Error('Not Implemented'); }\n\n var unaryOperators = {\n '+': function(v)
{ return +v; },\n '-': function(v) { return -v; },\n '!': function(v) { r
eturn !v; }\n };\n\n var binaryOperators = {\n '+': function(l, r) { return
l+r; },\n '-': function(l, r) { return l-r; },\n '*': function(l, r) { re
turn l*r; },\n '/': function(l, r) { return l/r; },\n '%': function(l, r)
{ return l%r; },\n '<': function(l, r) { return l<r; },\n '>': function(l,
r) { return l>r; },\n '<=': function(l, r) { return l<=r; },\n '>=': func
tion(l, r) { return l>=r; },\n '==': function(l, r) { return l==r; },\n '!
=': function(l, r) { return l!=r; },\n '===': function(l, r) { return l===r;
},\n '!==': function(l, r) { return l!==r; },\n '&&': function(l, r) { ret
urn l&&r; },\n '||': function(l, r) { return l||r; },\n };\n\n function get
Fn(arg) {\n return typeof arg == 'function' ? arg : arg.valueFn();\n }\n\n
function ASTDelegate() {\n this.expression = null;\n this.filters = [];\n
this.deps = {};\n this.currentPath = undefined;\n this.scopeIdent = und
efined;\n this.indexIdent = undefined;\n this.dynamicDeps = false;\n }\n\
n ASTDelegate.prototype = {\n createUnaryExpression: function(op, argument)
{\n if (!unaryOperators[op])\n throw Error('Disallowed operator: ' +
op);\n\n argument = getFn(argument);\n\n return function(model, obser
ver) {\n return unaryOperators[op](argument(model, observer));\n };\
n },\n\n createBinaryExpression: function(op, left, right) {\n if (!b
inaryOperators[op])\n throw Error('Disallowed operator: ' + op);\n\n
left = getFn(left);\n right = getFn(right);\n\n return function(model
, observer) {\n return binaryOperators[op](left(model, observer),\n
right(model, observer));\n };\n },\n\n c
reateConditionalExpression: function(test, consequent, alternate) {\n test
= getFn(test);\n consequent = getFn(consequent);\n alternate = getFn(a
lternate);\n\n return function(model, observer) {\n return test(mode
l, observer) ?\n consequent(model, observer) : alternate(model, obser
ver);\n }\n },\n\n createIdentifier: function(name) {\n var iden
t = new IdentPath(name);\n ident.type = 'Identifier';\n return ident;\
n },\n\n createMemberExpression: function(accessor, object, property) {\n
var ex = new MemberExpression(object, property, accessor);\n if (ex.dy
namicDeps)\n this.dynamicDeps = true;\n return ex;\n },\n\n cr
eateLiteral: function(token) {\n return new Literal(token.value);\n },\n
\n createArrayExpression: function(elements) {\n for (var i = 0; i < ele
ments.length; i++)\n elements[i] = getFn(elements[i]);\n\n return fu
nction(model, observer) {\n var arr = []\n for (var i = 0; i < ele
ments.length; i++)\n arr.push(elements[i](model, observer));\n r
eturn arr;\n }\n },\n\n createProperty: function(kind, key, value) {\
n return {\n key: key instanceof IdentPath ? key.name : key.value,\n
value: value\n };\n },\n\n createObjectExpression: function(p
roperties) {\n for (var i = 0; i < properties.length; i++)\n propert
ies[i].value = getFn(properties[i].value);\n\n return function(model, obser
ver) {\n var obj = {};\n for (var i = 0; i < properties.length; i+
+)\n obj[properties[i].key] = properties[i].value(model, observer);\n
return obj;\n }\n },\n\n createFilter: function(name, args) {\n
this.filters.push(new Filter(name, args));\n },\n\n createAsExpressi
on: function(expression, scopeIdent) {\n this.expression = expression;\n
this.scopeIdent = scopeIdent;\n },\n\n createInExpression: function(sco
peIdent, indexIdent, expression) {\n this.expression = expression;\n t
his.scopeIdent = scopeIdent;\n this.indexIdent = indexIdent;\n },\n\n
createTopLevel: function(expression) {\n this.expression = expression;\n
},\n\n createThisExpression: notImplemented\n }\n\n function ConstantObse
rvable(value) {\n this.value_ = value;\n }\n\n ConstantObservable.prototype
= {\n open: function() { return this.value_; },\n discardChanges: functio
n() { return this.value_; },\n deliver: function() {},\n close: function()
{},\n }\n\n function Expression(delegate) {\n this.scopeIdent = delegate.s
copeIdent;\n this.indexIdent = delegate.indexIdent;\n\n if (!delegate.expr
ession)\n throw Error('No expression found.');\n\n this.expression = del
egate.expression;\n getFn(this.expression); // forces enumeration of path dep
endencies\n\n this.filters = delegate.filters;\n this.dynamicDeps = delega
te.dynamicDeps;\n }\n\n Expression.prototype = {\n getBinding: function(mod
el, filterRegistry, oneTime) {\n if (oneTime)\n return this.getValue
(model, undefined, filterRegistry);\n\n var observer = new CompoundObserver
();\n // captures deps.\n var firstValue = this.getValue(model, observ
er, filterRegistry);\n var firstTime = true;\n var self = this;\n\n
function valueFn() {\n // deps cannot have changed on first value retr
ieval.\n if (firstTime) {\n firstTime = false;\n return
firstValue;\n }\n\n if (self.dynamicDeps)\n observer.sta
rtReset();\n\n var value = self.getValue(model,\n
self.dynamicDeps ? observer : undefined,\n
filterRegistry);\n if (self.dynamicDeps)\n observer.finish
Reset();\n\n return value;\n }\n\n function setValueFn(newValue
) {\n self.setValue(model, newValue, filterRegistry);\n return new
Value;\n }\n\n return new ObserverTransform(observer, valueFn, setValu
eFn, true);\n },\n\n getValue: function(model, observer, filterRegistry) {
\n var value = getFn(this.expression)(model, observer);\n for (var i =
0; i < this.filters.length; i++) {\n value = this.filters[i].transform(v
alue, false, filterRegistry, model,\n o
bserver);\n }\n\n return value;\n },\n\n setValue: function(mode
l, newValue, filterRegistry) {\n var count = this.filters ? this.filters.le
ngth : 0;\n while (count-- > 0) {\n newValue = this.filters[count].t
ransform(newValue, true, filterRegistry,\n
model);\n }\n\n if (this.expression.setValue)\n retu
rn this.expression.setValue(model, newValue);\n }\n }\n\n /**\n * Convert
s a style property name to a css property name. For example:\n * \"WebkitUserS
elect\" to \"-webkit-user-select\"\n */\n function convertStylePropertyName(n
ame) {\n return String(name).replace(/[A-Z]/g, function(c) {\n return '-
' + c.toLowerCase();\n });\n }\n\n function isEventHandler(name) {\n ret
urn name[0] === 'o' &&\n name[1] === 'n' &&\n name[2] === '-
';\n }\n\n var mixedCaseEventTypes = {};\n [\n 'webkitAnimationStart',\n
'webkitAnimationEnd',\n 'webkitTransitionEnd',\n 'DOMFocusOut',\n 'DO
MFocusIn',\n 'DOMMouseScroll'\n ].forEach(function(e) {\n mixedCaseEventT
ypes[e.toLowerCase()] = e;\n });\n\n var parentScopeName = '@' + Math.random()
.toString(36).slice(2);\n\n // Single ident paths must bind directly to the app
ropriate scope object.\n // I.e. Pushed values in two-bindings need to be assig
ned to the actual model\n // object.\n function findScope(model, prop) {\n
while (model[parentScopeName] &&\n !Object.prototype.hasOwnProperty.ca
ll(model, prop)) {\n model = model[parentScopeName];\n }\n\n return m
odel;\n }\n\n function resolveEventReceiver(model, path, node) {\n if (path
.length == 0)\n return undefined;\n\n if (path.length == 1)\n retur
n findScope(model, path[0]);\n\n for (var i = 0; model != null && i < path.le
ngth - 1; i++) {\n model = model[path[i]];\n }\n\n return model;\n }
\n\n function prepareEventBinding(path, name, polymerExpressions) {\n var ev
entType = name.substring(3);\n eventType = mixedCaseEventTypes[eventType] ||
eventType;\n\n return function(model, node, oneTime) {\n var fn, receive
r, handler;\n if (typeof polymerExpressions.resolveEventHandler == 'functio
n') {\n handler = function(e) {\n fn = fn || polymerExpressions.
resolveEventHandler(model, path, node);\n fn(e, e.detail, e.currentTarg
et);\n\n if (Platform && typeof Platform.flush == 'function')\n
Platform.flush();\n };\n } else {\n handler = function(e)
{\n fn = fn || path.getValueFrom(model);\n receiver = receive
r || resolveEventReceiver(model, path, node);\n\n fn.apply(receiver, [e
, e.detail, e.currentTarget]);\n\n if (Platform && typeof Platform.flus
h == 'function')\n Platform.flush();\n };\n }\n\n no
de.addEventListener(eventType, handler);\n\n if (oneTime)\n return;\
n\n function bindingValue() {\n return '{{ ' + path + ' }}';\n
}\n\n return {\n open: bindingValue,\n discardChanges: bindin
gValue,\n close: function() {\n node.removeEventListener(eventTy
pe, handler);\n }\n };\n }\n }\n\n function isLiteralExpression
(pathString) {\n switch (pathString) {\n case '':\n return false;
\n\n case 'false':\n case 'null':\n case 'true':\n return
true;\n }\n\n if (!isNaN(Number(pathString)))\n return true;\n\n r
eturn false;\n };\n\n function PolymerExpressions() {}\n\n PolymerExpressions
.prototype = {\n // \"built-in\" filters\n styleObject: function(value) {\
n var parts = [];\n for (var key in value) {\n parts.push(conve
rtStylePropertyName(key) + ': ' + value[key]);\n }\n return parts.join
('; ');\n },\n\n tokenList: function(value) {\n var tokens = [];\n
for (var key in value) {\n if (value[key])\n tokens.push(key)
;\n }\n return tokens.join(' ');\n },\n\n // binding delegate AP
I\n prepareInstancePositionChanged: function(template) {\n var indexIden
t = template.polymerExpressionIndexIdent_;\n if (!indexIdent)\n retu
rn;\n\n return function(templateInstance, index) {\n templateInstanc
e.model[indexIdent] = index;\n };\n },\n\n prepareBinding: function(p
athString, name, node) {\n var path = Path.get(pathString);\n if (isEv
entHandler(name)) {\n if (!path.valid) {\n console.error('on-* b
indings must be simple path expressions');\n return;\n }\n\n
return prepareEventBinding(path, name, this);\n }\n\n if (!isLiter
alExpression(pathString) && path.valid) {\n if (path.length == 1) {\n
return function(model, node, oneTime) {\n if (oneTime)\n
return path.getValueFrom(model);\n\n var scope = findScope(mod
el, path[0]);\n return new PathObserver(scope, path);\n };\n
}\n return; // bail out early if pathString is simple path.\n
}\n\n return prepareBinding(pathString, name, node, this);\n },\n\n
prepareInstanceModel: function(template) {\n var scopeName = template.poly
merExpressionScopeIdent_;\n if (!scopeName)\n return;\n\n var p
arentScope = template.templateInstance ?\n template.templateInstance.mo
del :\n template.model;\n\n var indexName = template.polymerExpres
sionIndexIdent_;\n\n return function(model) {\n var scope = Object.c
reate(parentScope);\n scope[scopeName] = model;\n scope[indexName]
= undefined;\n scope[parentScopeName] = parentScope;\n return sco
pe;\n };\n }\n };\n\n global.PolymerExpressions = PolymerExpressions;\
n if (global.exposeGetExpression)\n global.getExpression_ = getExpression;\n
\n global.PolymerExpressions.prepareEventBinding = prepareEventBinding;\n})(thi
s);\n", |
208 "/*\n * Copyright 2013 The Polymer Authors. All rights reserved.\n * Use of
this source code is governed by a BSD-style\n * license that can be found in the
LICENSE file.\n */\n(function(scope) {\n\n// inject style sheet\nvar style = do
cument.createElement('style');\nstyle.textContent = 'template {display: none !im
portant;} /* injected by platform.js */';\nvar head = document.querySelector('he
ad');\nhead.insertBefore(style, head.firstChild);\n\n// flush (with logging)\nva
r flushing;\nfunction flush() {\n if (!flushing) {\n flushing = true;\n s
cope.endOfMicrotask(function() {\n flushing = false;\n logFlags.data &
& console.group('Platform.flush()');\n scope.performMicrotaskCheckpoint();\
n logFlags.data && console.groupEnd();\n });\n }\n};\n\n// polling dirt
y checker\n// flush periodically if platform does not have object observe.\nif (
!Observer.hasObjectObserve) {\n var FLUSH_POLL_INTERVAL = 125;\n window.addEve
ntListener('WebComponentsReady', function() {\n flush();\n scope.flushPoll
= setInterval(flush, FLUSH_POLL_INTERVAL);\n });\n} else {\n // make flush a
no-op when we have Object.observe\n flush = function() {};\n}\n\nif (window.Cus
tomElements && !CustomElements.useNative) {\n var originalImportNode = Document
.prototype.importNode;\n Document.prototype.importNode = function(node, deep) {
\n var imported = originalImportNode.call(this, node, deep);\n CustomEleme
nts.upgradeAll(imported);\n return imported;\n }\n}\n\n// exports\nscope.flu
sh = flush;\n\n})(window.Platform);\n\n" | 208 "/*\n * Copyright 2013 The Polymer Authors. All rights reserved.\n * Use of
this source code is governed by a BSD-style\n * license that can be found in the
LICENSE file.\n */\n(function(scope) {\n\n// inject style sheet\nvar style = do
cument.createElement('style');\nstyle.textContent = 'template {display: none !im
portant;} /* injected by platform.js */';\nvar head = document.querySelector('he
ad');\nhead.insertBefore(style, head.firstChild);\n\n// flush (with logging)\nva
r flushing;\nfunction flush() {\n if (!flushing) {\n flushing = true;\n s
cope.endOfMicrotask(function() {\n flushing = false;\n logFlags.data &
& console.group('Platform.flush()');\n scope.performMicrotaskCheckpoint();\
n logFlags.data && console.groupEnd();\n });\n }\n};\n\n// polling dirt
y checker\n// flush periodically if platform does not have object observe.\nif (
!Observer.hasObjectObserve) {\n var FLUSH_POLL_INTERVAL = 125;\n window.addEve
ntListener('WebComponentsReady', function() {\n flush();\n scope.flushPoll
= setInterval(flush, FLUSH_POLL_INTERVAL);\n });\n} else {\n // make flush a
no-op when we have Object.observe\n flush = function() {};\n}\n\nif (window.Cus
tomElements && !CustomElements.useNative) {\n var originalImportNode = Document
.prototype.importNode;\n Document.prototype.importNode = function(node, deep) {
\n var imported = originalImportNode.call(this, node, deep);\n CustomEleme
nts.upgradeAll(imported);\n return imported;\n }\n}\n\n// exports\nscope.flu
sh = flush;\n\n})(window.Platform);\n\n" |
209 ] | 209 ] |
210 } | 210 } |
OLD | NEW |