OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 if (typeof Polymer == 'undefined') | |
6 Polymer = {dom: 'shadow'}; | |
7 else | |
8 console.error('Polymer is already defined.'); | |
9 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
10 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
11 // found in the LICENSE file. | 3 // found in the LICENSE file. |
12 | 4 |
13 /** | 5 /** |
14 * The global object. | 6 * The global object. |
15 * @type {!Object} | 7 * @type {!Object} |
16 * @const | 8 * @const |
17 */ | 9 */ |
18 var global = this; | 10 var global = this; |
(...skipping 1773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1792 removeAttribute: function(attr) { | 1784 removeAttribute: function(attr) { |
1793 if (attr.toLowerCase() == 'disabled') | 1785 if (attr.toLowerCase() == 'disabled') |
1794 this.disabled = false; | 1786 this.disabled = false; |
1795 else | 1787 else |
1796 HTMLAnchorElement.prototype.removeAttribute.apply(this, arguments); | 1788 HTMLAnchorElement.prototype.removeAttribute.apply(this, arguments); |
1797 }, | 1789 }, |
1798 }, | 1790 }, |
1799 | 1791 |
1800 extends: 'a', | 1792 extends: 'a', |
1801 }); | 1793 }); |
1802 // Copyright 2014 Google Inc. All rights reserved. | |
1803 // | |
1804 // Licensed under the Apache License, Version 2.0 (the "License"); | |
1805 // you may not use this file except in compliance with the License. | |
1806 // You may obtain a copy of the License at | |
1807 // | |
1808 // http://www.apache.org/licenses/LICENSE-2.0 | |
1809 // | |
1810 // Unless required by applicable law or agreed to in writing, software | |
1811 // distributed under the License is distributed on an "AS IS" BASIS, | |
1812 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
1813 // See the License for the specific language governing permissions and | |
1814 // limitations under the License. | |
1815 | |
1816 !function(a,b){b["true"]=a;var c={},d={},e={},f=null;!function(a){function b(a){
if("number"==typeof a)return a;var b={};for(var c in a)b[c]=a[c];return b}functi
on c(){this._delay=0,this._endDelay=0,this._fill="none",this._iterationStart=0,t
his._iterations=1,this._duration=0,this._playbackRate=1,this._direction="normal"
,this._easing="linear"}function d(b,d){var e=new c;return d&&(e.fill="both",e.du
ration="auto"),"number"!=typeof b||isNaN(b)?void 0!==b&&Object.getOwnPropertyNam
es(b).forEach(function(c){if("auto"!=b[c]){if(("number"==typeof e[c]||"duration"
==c)&&("number"!=typeof b[c]||isNaN(b[c])))return;if("fill"==c&&-1==s.indexOf(b[
c]))return;if("direction"==c&&-1==t.indexOf(b[c]))return;if("playbackRate"==c&&1
!==b[c]&&a.isDeprecated("AnimationEffectTiming.playbackRate","2014-11-28","Use A
nimation.playbackRate instead."))return;e[c]=b[c]}}):e.duration=b,e}function e(a
){return"number"==typeof a&&(a=isNaN(a)?{duration:0}:{duration:a}),a}function f(
b,c){b=a.numericTimingToObject(b);var e=d(b,c);return e._easing=i(e.easing),e}fu
nction g(a,b,c,d){return 0>a||a>1||0>c||c>1?B:function(e){function f(a,b,c){retu
rn 3*a*(1-c)*(1-c)*c+3*b*(1-c)*c*c+c*c*c}if(0==e||1==e)return e;for(var g=0,h=1;
;){var i=(g+h)/2,j=f(a,c,i);if(Math.abs(e-j)<.001)return f(b,d,i);e>j?g=i:h=i}}}
function h(a,b){return function(c){if(c>=1)return 1;var d=1/a;return c+=b*d,c-c%
d}}function i(a){var b=z.exec(a);if(b)return g.apply(this,b.slice(1).map(Number)
);var c=A.exec(a);if(c)return h(Number(c[1]),{start:u,middle:v,end:w}[c[2]]);var
d=x[a];return d?d:B}function j(a){return Math.abs(k(a)/a.playbackRate)}function
k(a){return a.duration*a.iterations}function l(a,b,c){return null==b?C:b<c.dela
y?D:b>=c.delay+a?E:F}function m(a,b,c,d,e){switch(d){case D:return"backwards"==b
||"both"==b?0:null;case F:return c-e;case E:return"forwards"==b||"both"==b?a:nul
l;case C:return null}}function n(a,b,c,d){return(d.playbackRate<0?b-a:b)*d.playb
ackRate+c}function o(a,b,c,d,e){return 1/0===c||c===-1/0||c-d==b&&e.iterations&&
(e.iterations+e.iterationStart)%1==0?a:c%a}function p(a,b,c,d){return 0===c?0:b=
=a?d.iterationStart+d.iterations-1:Math.floor(c/a)}function q(a,b,c,d){var e=a%2
>=1,f="normal"==d.direction||d.direction==(e?"alternate-reverse":"alternate"),g=
f?c:b-c,h=g/b;return b*d.easing(h)}function r(a,b,c){var d=l(a,b,c),e=m(a,c.fill
,b,d,c.delay);if(null===e)return null;if(0===a)return d===D?0:1;var f=c.iteratio
nStart*c.duration,g=n(a,e,f,c),h=o(c.duration,k(c),g,f,c),i=p(c.duration,h,g,c);
return q(i,c.duration,h,c)/c.duration}var s="backwards|forwards|both|none".split
("|"),t="reverse|alternate|alternate-reverse".split("|");c.prototype={_setMember
:function(b,c){this["_"+b]=c,this._effect&&(this._effect._timingInput[b]=c,this.
_effect._timing=a.normalizeTimingInput(a.normalizeTimingInput(this._effect._timi
ngInput)),this._effect.activeDuration=a.calculateActiveDuration(this._effect._ti
ming),this._effect._animation&&this._effect._animation._rebuildUnderlyingAnimati
on())},get playbackRate(){return this._playbackRate},set delay(a){this._setMembe
r("delay",a)},get delay(){return this._delay},set endDelay(a){this._setMember("e
ndDelay",a)},get endDelay(){return this._endDelay},set fill(a){this._setMember("
fill",a)},get fill(){return this._fill},set iterationStart(a){this._setMember("i
terationStart",a)},get iterationStart(){return this._iterationStart},set duratio
n(a){this._setMember("duration",a)},get duration(){return this._duration},set di
rection(a){this._setMember("direction",a)},get direction(){return this._directio
n},set easing(a){this._setMember("easing",a)},get easing(){return this._easing},
set iterations(a){this._setMember("iterations",a)},get iterations(){return this.
_iterations}};var u=1,v=.5,w=0,x={ease:g(.25,.1,.25,1),"ease-in":g(.42,0,1,1),"e
ase-out":g(0,0,.58,1),"ease-in-out":g(.42,0,.58,1),"step-start":h(1,u),"step-mid
dle":h(1,v),"step-end":h(1,w)},y="\\s*(-?\\d+\\.?\\d*|-?\\.\\d+)\\s*",z=new RegE
xp("cubic-bezier\\("+y+","+y+","+y+","+y+"\\)"),A=/steps\(\s*(\d+)\s*,\s*(start|
middle|end)\s*\)/,B=function(a){return a},C=0,D=1,E=2,F=3;a.cloneTimingInput=b,a
.makeTiming=d,a.numericTimingToObject=e,a.normalizeTimingInput=f,a.calculateActi
veDuration=j,a.calculateTimeFraction=r,a.calculatePhase=l,a.toTimingFunction=i}(
c,f),function(a){function b(a,b){return a in h?h[a][b]||b:b}function c(a,c,d){va
r g=e[a];if(g){f.style[a]=c;for(var h in g){var i=g[h],j=f.style[i];d[i]=b(i,j)}
}else d[a]=b(a,c)}function d(b){function d(){var a=e.length;null==e[a-1].offset&
&(e[a-1].offset=1),a>1&&null==e[0].offset&&(e[0].offset=0);for(var b=0,c=e[0].of
fset,d=1;a>d;d++){var f=e[d].offset;if(null!=f){for(var g=1;d-b>g;g++)e[b+g].off
set=c+(f-c)*g/(d-b);b=d,c=f}}}if(!Array.isArray(b)&&null!==b)throw new TypeError
("Keyframes must be null or an array of keyframes");if(null==b)return[];for(var
e=b.map(function(b){var d={};for(var e in b){var f=b[e];if("offset"==e){if(null!
=f&&(f=Number(f),!isFinite(f)))throw new TypeError("keyframe offsets must be num
bers.")}else{if("composite"==e)throw{type:DOMException.NOT_SUPPORTED_ERR,name:"N
otSupportedError",message:"add compositing is not supported"};f="easing"==e?a.to
TimingFunction(f):""+f}c(e,f,d)}return void 0==d.offset&&(d.offset=null),void 0=
=d.easing&&(d.easing=a.toTimingFunction("linear")),d}),f=!0,g=-1/0,h=0;h<e.lengt
h;h++){var i=e[h].offset;if(null!=i){if(g>i)throw{code:DOMException.INVALID_MODI
FICATION_ERR,name:"InvalidModificationError",message:"Keyframes are not loosely
sorted by offset. Sort or specify offsets."};g=i}else f=!1}return e=e.filter(fun
ction(a){return a.offset>=0&&a.offset<=1}),f||d(),e}var e={background:["backgrou
ndImage","backgroundPosition","backgroundSize","backgroundRepeat","backgroundAtt
achment","backgroundOrigin","backgroundClip","backgroundColor"],border:["borderT
opColor","borderTopStyle","borderTopWidth","borderRightColor","borderRightStyle"
,"borderRightWidth","borderBottomColor","borderBottomStyle","borderBottomWidth",
"borderLeftColor","borderLeftStyle","borderLeftWidth"],borderBottom:["borderBott
omWidth","borderBottomStyle","borderBottomColor"],borderColor:["borderTopColor",
"borderRightColor","borderBottomColor","borderLeftColor"],borderLeft:["borderLef
tWidth","borderLeftStyle","borderLeftColor"],borderRadius:["borderTopLeftRadius"
,"borderTopRightRadius","borderBottomRightRadius","borderBottomLeftRadius"],bord
erRight:["borderRightWidth","borderRightStyle","borderRightColor"],borderTop:["b
orderTopWidth","borderTopStyle","borderTopColor"],borderWidth:["borderTopWidth",
"borderRightWidth","borderBottomWidth","borderLeftWidth"],flex:["flexGrow","flex
Shrink","flexBasis"],font:["fontFamily","fontSize","fontStyle","fontVariant","fo
ntWeight","lineHeight"],margin:["marginTop","marginRight","marginBottom","margin
Left"],outline:["outlineColor","outlineStyle","outlineWidth"],padding:["paddingT
op","paddingRight","paddingBottom","paddingLeft"]},f=document.createElementNS("h
ttp://www.w3.org/1999/xhtml","div"),g={thin:"1px",medium:"3px",thick:"5px"},h={b
orderBottomWidth:g,borderLeftWidth:g,borderRightWidth:g,borderTopWidth:g,fontSiz
e:{"xx-small":"60%","x-small":"75%",small:"89%",medium:"100%",large:"120%","x-la
rge":"150%","xx-large":"200%"},fontWeight:{normal:"400",bold:"700"},outlineWidth
:g,textShadow:{none:"0px 0px 0px transparent"},boxShadow:{none:"0px 0px 0px 0px
transparent"}};a.normalizeKeyframes=d}(c,f),function(a){var b={};a.isDeprecated=
function(a,c,d,e){var f=e?"are":"is",g=new Date,h=new Date(c);return h.setMonth(
h.getMonth()+3),h>g?(a in b||console.warn("Web Animations: "+a+" "+f+" deprecate
d and will stop working on "+h.toDateString()+". "+d),b[a]=!0,!1):!0},a.deprecat
ed=function(b,c,d,e){var f=e?"are":"is";if(a.isDeprecated(b,c,d,e))throw new Err
or(b+" "+f+" no longer supported. "+d)}}(c),function(){if(document.documentEleme
nt.animate){var a=document.documentElement.animate([],0),b=!0;if(a&&(b=!1,"play|
currentTime|pause|reverse|playbackRate|cancel|finish|startTime|playState".split(
"|").forEach(function(c){void 0===a[c]&&(b=!0)})),!b)return}!function(a,b){funct
ion c(a){for(var b={},c=0;c<a.length;c++)for(var d in a[c])if("offset"!=d&&"easi
ng"!=d&&"composite"!=d){var e={offset:a[c].offset,easing:a[c].easing,value:a[c][
d]};b[d]=b[d]||[],b[d].push(e)}for(var f in b){var g=b[f];if(0!=g[0].offset||1!=
g[g.length-1].offset)throw{type:DOMException.NOT_SUPPORTED_ERR,name:"NotSupporte
dError",message:"Partial keyframes are not supported"}}return b}function d(a){va
r c=[];for(var d in a)for(var e=a[d],f=0;f<e.length-1;f++){var g=e[f].offset,h=e
[f+1].offset,i=e[f].value,j=e[f+1].value;g==h&&(1==h?i=j:j=i),c.push({startTime:
g,endTime:h,easing:e[f].easing,property:d,interpolation:b.propertyInterpolation(
d,i,j)})}return c.sort(function(a,b){return a.startTime-b.startTime}),c}b.conver
tEffectInput=function(e){var f=a.normalizeKeyframes(e),g=c(f),h=d(g);return func
tion(a,c){if(null!=c)h.filter(function(a){return 0>=c&&0==a.startTime||c>=1&&1==
a.endTime||c>=a.startTime&&c<=a.endTime}).forEach(function(d){var e=c-d.startTim
e,f=d.endTime-d.startTime,g=0==f?0:d.easing(e/f);b.apply(a,d.property,d.interpol
ation(g))});else for(var d in g)"offset"!=d&&"easing"!=d&&"composite"!=d&&b.clea
r(a,d)}}}(c,d,f),function(a){function b(a,b,c){e[c]=e[c]||[],e[c].push([a,b])}fu
nction c(a,c,d){for(var e=0;e<d.length;e++){var f=d[e];b(a,c,f),/-/.test(f)&&b(a
,c,f.replace(/-(.)/g,function(a,b){return b.toUpperCase()}))}}function d(b,c,d){
if("initial"==c||"initial"==d){var g=b.replace(/-(.)/g,function(a,b){return b.to
UpperCase()});"initial"==c&&(c=f[g]),"initial"==d&&(d=f[g])}for(var h=c==d?[]:e[
b],i=0;h&&i<h.length;i++){var j=h[i][0](c),k=h[i][0](d);if(void 0!==j&&void 0!==
k){var l=h[i][1](j,k);if(l){var m=a.Interpolation.apply(null,l);return function(
a){return 0==a?c:1==a?d:m(a)}}}}return a.Interpolation(!1,!0,function(a){return
a?d:c})}var e={};a.addPropertiesHandler=c;var f={backgroundColor:"transparent",b
ackgroundPosition:"0% 0%",borderBottomColor:"currentColor",borderBottomLeftRadiu
s:"0px",borderBottomRightRadius:"0px",borderBottomWidth:"3px",borderLeftColor:"c
urrentColor",borderLeftWidth:"3px",borderRightColor:"currentColor",borderRightWi
dth:"3px",borderSpacing:"2px",borderTopColor:"currentColor",borderTopLeftRadius:
"0px",borderTopRightRadius:"0px",borderTopWidth:"3px",bottom:"auto",clip:"rect(0
px, 0px, 0px, 0px)",color:"black",fontSize:"100%",fontWeight:"400",height:"auto"
,left:"auto",letterSpacing:"normal",lineHeight:"120%",marginBottom:"0px",marginL
eft:"0px",marginRight:"0px",marginTop:"0px",maxHeight:"none",maxWidth:"none",min
Height:"0px",minWidth:"0px",opacity:"1.0",outlineColor:"invert",outlineOffset:"0
px",outlineWidth:"3px",paddingBottom:"0px",paddingLeft:"0px",paddingRight:"0px",
paddingTop:"0px",right:"auto",textIndent:"0px",textShadow:"0px 0px 0px transpare
nt",top:"auto",transform:"",verticalAlign:"0px",visibility:"visible",width:"auto
",wordSpacing:"normal",zIndex:"auto"};a.propertyInterpolation=d}(d,f),function(a
,b){function c(b){var c=a.calculateActiveDuration(b),d=function(d){return a.calc
ulateTimeFraction(c,d,b)};return d._totalDuration=b.delay+c+b.endDelay,d._isCurr
ent=function(d){var e=a.calculatePhase(c,d,b);return e===PhaseActive||e===PhaseB
efore},d}b.KeyframeEffect=function(d,e,f){var g,h=c(a.normalizeTimingInput(f)),i
=b.convertEffectInput(e),j=function(){i(d,g)};return j._update=function(a){retur
n g=h(a),null!==g},j._clear=function(){i(d,null)},j._hasSameTarget=function(a){r
eturn d===a},j._isCurrent=h._isCurrent,j._totalDuration=h._totalDuration,j},b.Nu
llEffect=function(a){var b=function(){a&&(a(),a=null)};return b._update=function
(){return null},b._totalDuration=0,b._isCurrent=function(){return!1},b._hasSameT
arget=function(){return!1},b}}(c,d,f),function(a){a.apply=function(b,c,d){b.styl
e[a.propertyName(c)]=d},a.clear=function(b,c){b.style[a.propertyName(c)]=""}}(d,
f),function(a){window.Element.prototype.animate=function(b,c){return a.timeline.
_play(a.KeyframeEffect(this,b,c))}}(d),function(a){function b(a,c,d){if("number"
==typeof a&&"number"==typeof c)return a*(1-d)+c*d;if("boolean"==typeof a&&"boole
an"==typeof c)return.5>d?a:c;if(a.length==c.length){for(var e=[],f=0;f<a.length;
f++)e.push(b(a[f],c[f],d));return e}throw"Mismatched interpolation arguments "+a
+":"+c}a.Interpolation=function(a,c,d){return function(e){return d(b(a,c,e))}}}(
d,f),function(a,b){a.sequenceNumber=0;var c=function(a,b,c){this.target=a,this.c
urrentTime=b,this.timelineTime=c,this.type="finish",this.bubbles=!1,this.cancela
ble=!1,this.currentTarget=a,this.defaultPrevented=!1,this.eventPhase=Event.AT_TA
RGET,this.timeStamp=Date.now()};b.Animation=function(b){this._sequenceNumber=a.s
equenceNumber++,this._currentTime=0,this._startTime=null,this._paused=!1,this._p
laybackRate=1,this._inTimeline=!0,this._finishedFlag=!1,this.onfinish=null,this.
_finishHandlers=[],this._effect=b,this._inEffect=this._effect._update(0),this._i
dle=!0,this._currentTimePending=!1},b.Animation.prototype={_ensureAlive:function
(){this._inEffect=this._effect._update(this.playbackRate<0&&0===this.currentTime
?-1:this.currentTime),this._inTimeline||!this._inEffect&&this._finishedFlag||(th
is._inTimeline=!0,b.timeline._animations.push(this))},_tickCurrentTime:function(
a,b){a!=this._currentTime&&(this._currentTime=a,this._isFinished&&!b&&(this._cur
rentTime=this._playbackRate>0?this._totalDuration:0),this._ensureAlive())},get c
urrentTime(){return this._idle||this._currentTimePending?null:this._currentTime}
,set currentTime(a){a=+a,isNaN(a)||(b.restart(),this._paused||null==this._startT
ime||(this._startTime=this._timeline.currentTime-a/this._playbackRate),this._cur
rentTimePending=!1,this._currentTime!=a&&(this._tickCurrentTime(a,!0),b.invalida
teEffects()))},get startTime(){return this._startTime},set startTime(a){a=+a,isN
aN(a)||this._paused||this._idle||(this._startTime=a,this._tickCurrentTime((this.
_timeline.currentTime-this._startTime)*this.playbackRate),b.invalidateEffects())
},get playbackRate(){return this._playbackRate},set playbackRate(a){if(a!=this._
playbackRate){var b=this.currentTime;this._playbackRate=a,this._startTime=null,"
paused"!=this.playState&&"idle"!=this.playState&&this.play(),null!=b&&(this.curr
entTime=b)}},get _isFinished(){return!this._idle&&(this._playbackRate>0&&this._c
urrentTime>=this._totalDuration||this._playbackRate<0&&this._currentTime<=0)},ge
t _totalDuration(){return this._effect._totalDuration},get playState(){return th
is._idle?"idle":null==this._startTime&&!this._paused&&0!=this.playbackRate||this
._currentTimePending?"pending":this._paused?"paused":this._isFinished?"finished"
:"running"},play:function(){this._paused=!1,(this._isFinished||this._idle)&&(thi
s._currentTime=this._playbackRate>0?0:this._totalDuration,this._startTime=null,b
.invalidateEffects()),this._finishedFlag=!1,b.restart(),this._idle=!1,this._ensu
reAlive()},pause:function(){this._isFinished||this._paused||this._idle||(this._c
urrentTimePending=!0),this._startTime=null,this._paused=!0},finish:function(){th
is._idle||(this.currentTime=this._playbackRate>0?this._totalDuration:0,this._sta
rtTime=this._totalDuration-this.currentTime,this._currentTimePending=!1)},cancel
:function(){this._inEffect&&(this._inEffect=!1,this._idle=!0,this.currentTime=0,
this._startTime=null,this._effect._update(null),b.invalidateEffects(),b.restart(
))},reverse:function(){this.playbackRate*=-1,this.play()},addEventListener:funct
ion(a,b){"function"==typeof b&&"finish"==a&&this._finishHandlers.push(b)},remove
EventListener:function(a,b){if("finish"==a){var c=this._finishHandlers.indexOf(b
);c>=0&&this._finishHandlers.splice(c,1)}},_fireEvents:function(a){var b=this._i
sFinished;if((b||this._idle)&&!this._finishedFlag){var d=new c(this,this._curren
tTime,a),e=this._finishHandlers.concat(this.onfinish?[this.onfinish]:[]);setTime
out(function(){e.forEach(function(a){a.call(d.target,d)})},0)}this._finishedFlag
=b},_tick:function(a){return this._idle||this._paused||(null==this._startTime?th
is.startTime=a-this._currentTime/this.playbackRate:this._isFinished||this._tickC
urrentTime((a-this._startTime)*this.playbackRate)),this._currentTimePending=!1,t
his._fireEvents(a),!this._idle&&(this._inEffect||!this._finishedFlag)}}}(c,d,f),
function(a,b){function c(a){var b=i;i=[],a<s.currentTime&&(a=s.currentTime),g(a)
,b.forEach(function(b){b[1](a)}),o&&g(a),f(),l=void 0}function d(a,b){return a._
sequenceNumber-b._sequenceNumber}function e(){this._animations=[],this.currentTi
me=window.performance&&performance.now?performance.now():0}function f(){p.forEac
h(function(a){a()}),p.length=0}function g(a){n=!1;var c=b.timeline;c.currentTime
=a,c._animations.sort(d),m=!1;var e=c._animations;c._animations=[];var f=[],g=[]
;e=e.filter(function(b){return b._inTimeline=b._tick(a),b._inEffect?g.push(b._ef
fect):f.push(b._effect),b._isFinished||b._paused||b._idle||(m=!0),b._inTimeline}
),p.push.apply(p,f),p.push.apply(p,g),c._animations.push.apply(c._animations,e),
o=!1,m&&requestAnimationFrame(function(){})}var h=window.requestAnimationFrame,i
=[],j=0;window.requestAnimationFrame=function(a){var b=j++;return 0==i.length&&h
(c),i.push([b,a]),b},window.cancelAnimationFrame=function(a){i.forEach(function(
b){b[0]==a&&(b[1]=function(){})})},e.prototype={_play:function(c){c._timing=a.no
rmalizeTimingInput(c.timing);var d=new b.Animation(c);return d._idle=!1,d._timel
ine=this,this._animations.push(d),b.restart(),b.invalidateEffects(),d}};var k,l=
void 0,k=function(){return void 0==l&&(l=performance.now()),l},m=!1,n=!1;b.resta
rt=function(){return m||(m=!0,requestAnimationFrame(function(){}),n=!0),n};var o
=!1;b.invalidateEffects=function(){o=!0};var p=[],q=1e3/60,r=window.getComputedS
tyle;Object.defineProperty(window,"getComputedStyle",{configurable:!0,enumerable
:!0,value:function(){if(o){var a=k();a-s.currentTime>0&&(s.currentTime+=q*(Math.
floor((a-s.currentTime)/q)+1)),g(s.currentTime)}return f(),r.apply(this,argument
s)}});var s=new e;b.timeline=s}(c,d,f),function(a){function b(a,b){var c=a.exec(
b);return c?(c=a.ignoreCase?c[0].toLowerCase():c[0],[c,b.substr(c.length)]):void
0}function c(a,b){b=b.replace(/^\s*/,"");var c=a(b);return c?[c[0],c[1].replace
(/^\s*/,"")]:void 0}function d(a,d,e){a=c.bind(null,a);for(var f=[];;){var g=a(e
);if(!g)return[f,e];if(f.push(g[0]),e=g[1],g=b(d,e),!g||""==g[1])return[f,e];e=g
[1]}}function e(a,b){for(var c=0,d=0;d<b.length&&(!/\s|,/.test(b[d])||0!=c);d++)
if("("==b[d])c++;else if(")"==b[d]&&(c--,0==c&&d++,0>=c))break;var e=a(b.substr(
0,d));return void 0==e?void 0:[e,b.substr(d)]}function f(a,b){for(var c=a,d=b;c&
&d;)c>d?c%=d:d%=c;return c=a*b/(c+d)}function g(a){return function(b){var c=a(b)
;return c&&(c[0]=void 0),c}}function h(a,b){return function(c){var d=a(c);return
d?d:[b,c]}}function i(b,c){for(var d=[],e=0;e<b.length;e++){var f=a.consumeTrim
med(b[e],c);if(!f||""==f[0])return;void 0!==f[0]&&d.push(f[0]),c=f[1]}return""==
c?d:void 0}function j(a,b,c,d,e){for(var g=[],h=[],i=[],j=f(d.length,e.length),k
=0;j>k;k++){var l=b(d[k%d.length],e[k%e.length]);if(!l)return;g.push(l[0]),h.pus
h(l[1]),i.push(l[2])}return[g,h,function(b){var d=b.map(function(a,b){return i[b
](a)}).join(c);return a?a(d):d}]}function k(a,b,c){for(var d=[],e=[],f=[],g=0,h=
0;h<c.length;h++)if("function"==typeof c[h]){var i=c[h](a[g],b[g++]);d.push(i[0]
),e.push(i[1]),f.push(i[2])}else!function(a){d.push(!1),e.push(!1),f.push(functi
on(){return c[a]})}(h);return[d,e,function(a){for(var b="",c=0;c<a.length;c++)b+
=f[c](a[c]);return b}]}a.consumeToken=b,a.consumeTrimmed=c,a.consumeRepeated=d,a
.consumeParenthesised=e,a.ignore=g,a.optional=h,a.consumeList=i,a.mergeNestedRep
eated=j.bind(null,null),a.mergeWrappedNestedRepeated=j,a.mergeList=k}(d),functio
n(a){function b(b){function c(b){var c=a.consumeToken(/^inset/i,b);if(c)return d
.inset=!0,c;var c=a.consumeLengthOrPercent(b);if(c)return d.lengths.push(c[0]),c
;var c=a.consumeColor(b);return c?(d.color=c[0],c):void 0}var d={inset:!1,length
s:[],color:null},e=a.consumeRepeated(c,/^/,b);return e&&e[0].length?[d,e[1]]:voi
d 0}function c(c){var d=a.consumeRepeated(b,/^,/,c);return d&&""==d[1]?d[0]:void
0}function d(b,c){for(;b.lengths.length<Math.max(b.lengths.length,c.lengths.len
gth);)b.lengths.push({px:0});for(;c.lengths.length<Math.max(b.lengths.length,c.l
engths.length);)c.lengths.push({px:0});if(b.inset==c.inset&&!!b.color==!!c.color
){for(var d,e=[],f=[[],0],g=[[],0],h=0;h<b.lengths.length;h++){var i=a.mergeDime
nsions(b.lengths[h],c.lengths[h],2==h);f[0].push(i[0]),g[0].push(i[1]),e.push(i[
2])}if(b.color&&c.color){var j=a.mergeColors(b.color,c.color);f[1]=j[0],g[1]=j[1
],d=j[2]}return[f,g,function(a){for(var c=b.inset?"inset ":" ",f=0;f<e.length;f+
+)c+=e[f](a[0][f])+" ";return d&&(c+=d(a[1])),c}]}}function e(b,c,d,e){function
f(a){return{inset:a,color:[0,0,0,0],lengths:[{px:0},{px:0},{px:0},{px:0}]}}for(v
ar g=[],h=[],i=0;i<d.length||i<e.length;i++){var j=d[i]||f(e[i].inset),k=e[i]||f
(d[i].inset);g.push(j),h.push(k)}return a.mergeNestedRepeated(b,c,g,h)}var f=e.b
ind(null,d,", ");a.addPropertiesHandler(c,f,["box-shadow","text-shadow"])}(d),fu
nction(a){function b(a){return a.toFixed(3).replace(".000","")}function c(a,b,c)
{return Math.min(b,Math.max(a,c))}function d(a){return/^\s*[-+]?(\d*\.)?\d+\s*$/
.test(a)?Number(a):void 0}function e(a,c){return[a,c,b]}function f(a,b){return 0
!=a?h(0,1/0)(a,b):void 0}function g(a,b){return[a,b,function(a){return Math.roun
d(c(1,1/0,a))}]}function h(a,d){return function(e,f){return[e,f,function(e){retu
rn b(c(a,d,e))}]}}function i(a,b){return[a,b,Math.round]}a.clamp=c,a.addProperti
esHandler(d,h(0,1/0),["border-image-width","line-height"]),a.addPropertiesHandle
r(d,h(0,1),["opacity","shape-image-threshold"]),a.addPropertiesHandler(d,f,["fle
x-grow","flex-shrink"]),a.addPropertiesHandler(d,g,["orphans","widows"]),a.addPr
opertiesHandler(d,i,["z-index"]),a.parseNumber=d,a.mergeNumbers=e,a.numberToStri
ng=b}(d,f),function(a){function b(a,b){return"visible"==a||"visible"==b?[0,1,fun
ction(c){return 0>=c?a:c>=1?b:"visible"}]:void 0}a.addPropertiesHandler(String,b
,["visibility"])}(d),function(a){function b(a){a=a.trim(),e.fillStyle="#000",e.f
illStyle=a;var b=e.fillStyle;if(e.fillStyle="#fff",e.fillStyle=a,b==e.fillStyle)
{e.fillRect(0,0,1,1);var c=e.getImageData(0,0,1,1).data;e.clearRect(0,0,1,1);var
d=c[3]/255;return[c[0]*d,c[1]*d,c[2]*d,d]}}function c(b,c){return[b,c,function(
b){function c(a){return Math.max(0,Math.min(255,a))}if(b[3])for(var d=0;3>d;d++)
b[d]=Math.round(c(b[d]/b[3]));return b[3]=a.numberToString(a.clamp(0,1,b[3])),"r
gba("+b.join(",")+")"}]}var d=document.createElementNS("http://www.w3.org/1999/x
html","canvas");d.width=d.height=1;var e=d.getContext("2d");a.addPropertiesHandl
er(b,c,["background-color","border-bottom-color","border-left-color","border-rig
ht-color","border-top-color","color","outline-color","text-decoration-color"]),a
.consumeColor=a.consumeParenthesised.bind(null,b),a.mergeColors=c}(d,f),function
(a,b){function c(a,b){if(b=b.trim().toLowerCase(),"0"==b&&"px".search(a)>=0)retu
rn{px:0};if(/^[^(]*$|^calc/.test(b)){b=b.replace(/calc\(/g,"(");var c={};b=b.rep
lace(a,function(a){return c[a]=null,"U"+a});for(var d="U("+a.source+")",e=b.repl
ace(/[-+]?(\d*\.)?\d+/g,"N").replace(new RegExp("N"+d,"g"),"D").replace(/\s[+-]\
s/g,"O").replace(/\s/g,""),f=[/N\*(D)/g,/(N|D)[*/]N/g,/(N|D)O\1/g,/\((N|D)\)/g],
g=0;g<f.length;)f[g].test(e)?(e=e.replace(f[g],"$1"),g=0):g++;if("D"==e){for(var
h in c){var i=eval(b.replace(new RegExp("U"+h,"g"),"").replace(new RegExp(d,"g"
),"*0"));if(!isFinite(i))return;c[h]=i}return c}}}function d(a,b){return e(a,b,!
0)}function e(b,c,d){var e,f=[];for(e in b)f.push(e);for(e in c)f.indexOf(e)<0&&
f.push(e);return b=f.map(function(a){return b[a]||0}),c=f.map(function(a){return
c[a]||0}),[b,c,function(b){var c=b.map(function(c,e){return 1==b.length&&d&&(c=
Math.max(c,0)),a.numberToString(c)+f[e]}).join(" + ");return b.length>1?"calc("+
c+")":c}]}var f="px|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc",g=c.bind(null,n
ew RegExp(f,"g")),h=c.bind(null,new RegExp(f+"|%","g")),i=c.bind(null,/deg|rad|g
rad|turn/g);a.parseLength=g,a.parseLengthOrPercent=h,a.consumeLengthOrPercent=a.
consumeParenthesised.bind(null,h),a.parseAngle=i,a.mergeDimensions=e;var j=a.con
sumeParenthesised.bind(null,g),k=a.consumeRepeated.bind(void 0,j,/^/),l=a.consum
eRepeated.bind(void 0,k,/^,/);a.consumeSizePairList=l;var m=function(a){var b=l(
a);return b&&""==b[1]?b[0]:void 0},n=a.mergeNestedRepeated.bind(void 0,d," "),o=
a.mergeNestedRepeated.bind(void 0,n,",");a.mergeNonNegativeSizePair=n,a.addPrope
rtiesHandler(m,o,["background-size"]),a.addPropertiesHandler(h,d,["border-bottom
-width","border-image-width","border-left-width","border-right-width","border-to
p-width","flex-basis","font-size","height","line-height","max-height","max-width
","outline-width","width"]),a.addPropertiesHandler(h,e,["border-bottom-left-radi
us","border-bottom-right-radius","border-top-left-radius","border-top-right-radi
us","bottom","left","letter-spacing","margin-bottom","margin-left","margin-right
","margin-top","min-height","min-width","outline-offset","padding-bottom","paddi
ng-left","padding-right","padding-top","perspective","right","shape-margin","tex
t-indent","top","vertical-align","word-spacing"])}(d,f),function(a){function b(b
){return a.consumeLengthOrPercent(b)||a.consumeToken(/^auto/,b)}function c(c){va
r d=a.consumeList([a.ignore(a.consumeToken.bind(null,/^rect/)),a.ignore(a.consum
eToken.bind(null,/^\(/)),a.consumeRepeated.bind(null,b,/^,/),a.ignore(a.consumeT
oken.bind(null,/^\)/))],c);return d&&4==d[0].length?d[0]:void 0}function d(b,c){
return"auto"==b||"auto"==c?[!0,!1,function(d){var e=d?b:c;if("auto"==e)return"au
to";var f=a.mergeDimensions(e,e);return f[2](f[0])}]:a.mergeDimensions(b,c)}func
tion e(a){return"rect("+a+")"}var f=a.mergeWrappedNestedRepeated.bind(null,e,d,"
, ");a.parseBox=c,a.mergeBoxes=f,a.addPropertiesHandler(c,f,["clip"])}(d,f),func
tion(a){function b(a){return function(b){var c=0;return a.map(function(a){return
a===j?b[c++]:a})}}function c(a){return a}function d(b){if(b=b.toLowerCase().tri
m(),"none"==b)return[];for(var c,d=/\s*(\w+)\(([^)]*)\)/g,e=[],f=0;c=d.exec(b);)
{if(c.index!=f)return;f=c.index+c[0].length;var g=c[1],h=m[g];if(!h)return;var i
=c[2].split(","),j=h[0];if(j.length<i.length)return;for(var n=[],o=0;o<j.length;
o++){var p,q=i[o],r=j[o];if(p=q?{A:function(b){return"0"==b.trim()?l:a.parseAngl
e(b)},N:a.parseNumber,T:a.parseLengthOrPercent,L:a.parseLength}[r.toUpperCase()]
(q):{a:l,n:n[0],t:k}[r],void 0===p)return;n.push(p)}if(e.push({t:g,d:n}),d.lastI
ndex==b.length)return e}}function e(a){return a.toFixed(6).replace(".000000","")
}function f(b,c){if(b.decompositionPair!==c){b.decompositionPair=c;var d=a.makeM
atrixDecomposition(b)}if(c.decompositionPair!==b){c.decompositionPair=b;var f=a.
makeMatrixDecomposition(c)}return null==d[0]||null==f[0]?[[!1],[!0],function(a){
return a?c[0].d:b[0].d}]:(d[0].push(0),f[0].push(1),[d,f,function(b){var c=a.qua
t(d[0][3],f[0][3],b[5]),g=a.composeMatrix(b[0],b[1],b[2],c,b[4]),h=g.map(e).join
(",");return h}])}function g(a){return a.replace(/[xy]/,"")}function h(a){return
a.replace(/(x|y|z|3d)?$/,"3d")}function i(b,c){var d=a.makeMatrixDecomposition&
&!0,e=!1;if(!b.length||!c.length){b.length||(e=!0,b=c,c=[]);for(var i=0;i<b.leng
th;i++){var j=b[i].t,k=b[i].d,l="scale"==j.substr(0,5)?1:0;c.push({t:j,d:k.map(f
unction(a){if("number"==typeof a)return l;var b={};for(var c in a)b[c]=l;return
b})})}}var n=function(a,b){return"perspective"==a&&"perspective"==b||("matrix"==
a||"matrix3d"==a)&&("matrix"==b||"matrix3d"==b)},o=[],p=[],q=[];if(b.length!=c.l
ength){if(!d)return;var r=f(b,c);o=[r[0]],p=[r[1]],q=[["matrix",[r[2]]]]}else fo
r(var i=0;i<b.length;i++){var j,s=b[i].t,t=c[i].t,u=b[i].d,v=c[i].d,w=m[s],x=m[t
];if(n(s,t)){if(!d)return;var r=f([b[i]],[c[i]]);o.push(r[0]),p.push(r[1]),q.pus
h(["matrix",[r[2]]])}else{if(s==t)j=s;else if(w[2]&&x[2]&&g(s)==g(t))j=g(s),u=w[
2](u),v=x[2](v);else{if(!w[1]||!x[1]||h(s)!=h(t)){if(!d)return;var r=f(b,c);o=[r
[0]],p=[r[1]],q=[["matrix",[r[2]]]];break}j=h(s),u=w[1](u),v=x[1](v)}for(var y=[
],z=[],A=[],B=0;B<u.length;B++){var C="number"==typeof u[B]?a.mergeNumbers:a.mer
geDimensions,r=C(u[B],v[B]);y[B]=r[0],z[B]=r[1],A.push(r[2])}o.push(y),p.push(z)
,q.push([j,A])}}if(e){var D=o;o=p,p=D}return[o,p,function(a){return a.map(functi
on(a,b){var c=a.map(function(a,c){return q[b][1][c](a)}).join(",");return"matrix
"==q[b][0]&&16==c.split(",").length&&(q[b][0]="matrix3d"),q[b][0]+"("+c+")"}).jo
in(" ")}]}var j=null,k={px:0},l={deg:0},m={matrix:["NNNNNN",[j,j,0,0,j,j,0,0,0,0
,1,0,j,j,0,1],c],matrix3d:["NNNNNNNNNNNNNNNN",c],rotate:["A"],rotatex:["A"],rota
tey:["A"],rotatez:["A"],rotate3d:["NNNA"],perspective:["L"],scale:["Nn",b([j,j,1
]),c],scalex:["N",b([j,1,1]),b([j,1])],scaley:["N",b([1,j,1]),b([1,j])],scalez:[
"N",b([1,1,j])],scale3d:["NNN",c],skew:["Aa",null,c],skewx:["A",null,b([j,l])],s
kewy:["A",null,b([l,j])],translate:["Tt",b([j,j,k]),c],translatex:["T",b([j,k,k]
),b([j,k])],translatey:["T",b([k,j,k]),b([k,j])],translatez:["L",b([k,k,j])],tra
nslate3d:["TTL",c]};a.addPropertiesHandler(d,i,["transform"])}(d,f),function(a){
function b(a,b){b.concat([a]).forEach(function(b){b in document.documentElement.
style&&(c[a]=b)})}var c={};b("transform",["webkitTransform","msTransform"]),b("t
ransformOrigin",["webkitTransformOrigin"]),b("perspective",["webkitPerspective"]
),b("perspectiveOrigin",["webkitPerspectiveOrigin"]),a.propertyName=function(a){
return c[a]||a}}(d,f)}(),!function(a,b){function c(a){var b=window.document.time
line;b.currentTime=a,b._discardAnimations(),0==b._animations.length?e=!1:request
AnimationFrame(c)}var d=window.requestAnimationFrame;window.requestAnimationFram
e=function(a){return d(function(b){window.document.timeline._updateAnimationsPro
mises(),a(b),window.document.timeline._updateAnimationsPromises()})},b.Animation
Timeline=function(){this._animations=[],this.currentTime=void 0},b.AnimationTime
line.prototype={getAnimations:function(){return this._discardAnimations(),this._
animations.slice()},_updateAnimationsPromises:function(){b.animationsWithPromise
s=b.animationsWithPromises.filter(function(a){return a._updatePromises()})},_dis
cardAnimations:function(){this._updateAnimationsPromises(),this._animations=this
._animations.filter(function(a){return"finished"!=a.playState&&"idle"!=a.playSta
te})},_play:function(a){var c=new b.Animation(a,this);return this._animations.pu
sh(c),b.restartWebAnimationsNextTick(),c._updatePromises(),c._animation.play(),c
._updatePromises(),c},play:function(a){return a&&a.remove(),this._play(a)}};var
e=!1;b.restartWebAnimationsNextTick=function(){e||(e=!0,requestAnimationFrame(c)
)};var f=new b.AnimationTimeline;b.timeline=f;try{Object.defineProperty(window.d
ocument,"timeline",{configurable:!0,get:function(){return f}})}catch(g){}try{win
dow.document.timeline=f}catch(g){}}(c,e,f),function(a,b){b.animationsWithPromise
s=[],b.Animation=function(b,c){if(this.effect=b,b&&(b._animation=this),!c)throw
new Error("Animation with null timeline is not supported");this._timeline=c,this
._sequenceNumber=a.sequenceNumber++,this._holdTime=0,this._paused=!1,this._isGro
up=!1,this._animation=null,this._childAnimations=[],this._callback=null,this._ol
dPlayState="idle",this._rebuildUnderlyingAnimation(),this._animation.cancel(),th
is._updatePromises()},b.Animation.prototype={_updatePromises:function(){var a=th
is._oldPlayState,b=this.playState;return this._readyPromise&&b!==a&&("idle"==b?(
this._rejectReadyPromise(),this._readyPromise=void 0):"pending"==a?this._resolve
ReadyPromise():"pending"==b&&(this._readyPromise=void 0)),this._finishedPromise&
&b!==a&&("idle"==b?(this._rejectFinishedPromise(),this._finishedPromise=void 0):
"finished"==b?this._resolveFinishedPromise():"finished"==a&&(this._finishedPromi
se=void 0)),this._oldPlayState=this.playState,this._readyPromise||this._finished
Promise},_rebuildUnderlyingAnimation:function(){this._updatePromises();var a,c,d
,e,f=this._animation?!0:!1;f&&(a=this.playbackRate,c=this._paused,d=this.startTi
me,e=this.currentTime,this._animation.cancel(),this._animation._wrapper=null,thi
s._animation=null),(!this.effect||this.effect instanceof window.KeyframeEffect)&
&(this._animation=b.newUnderlyingAnimationForKeyframeEffect(this.effect),b.bindA
nimationForKeyframeEffect(this)),(this.effect instanceof window.SequenceEffect||
this.effect instanceof window.GroupEffect)&&(this._animation=b.newUnderlyingAnim
ationForGroup(this.effect),b.bindAnimationForGroup(this)),this.effect&&this.effe
ct._onsample&&b.bindAnimationForCustomEffect(this),f&&(1!=a&&(this.playbackRate=
a),null!==d?this.startTime=d:null!==e?this.currentTime=e:null!==this._holdTime&&
(this.currentTime=this._holdTime),c&&this.pause()),this._updatePromises() | |
1817 },_updateChildren:function(){if(this.effect&&"idle"!=this.playState){var a=this.
effect._timing.delay;this._childAnimations.forEach(function(c){this._arrangeChil
dren(c,a),this.effect instanceof window.SequenceEffect&&(a+=b.groupChildDuration
(c.effect))}.bind(this))}},_setExternalAnimation:function(a){if(this.effect&&thi
s._isGroup)for(var b=0;b<this.effect.children.length;b++)this.effect.children[b]
._animation=a,this._childAnimations[b]._setExternalAnimation(a)},_constructChild
Animations:function(){if(this.effect&&this._isGroup){var a=this.effect._timing.d
elay;this._removeChildAnimations(),this.effect.children.forEach(function(c){var
d=window.document.timeline._play(c);this._childAnimations.push(d),d.playbackRate
=this.playbackRate,this._paused&&d.pause(),c._animation=this.effect._animation,t
his._arrangeChildren(d,a),this.effect instanceof window.SequenceEffect&&(a+=b.gr
oupChildDuration(c))}.bind(this))}},_arrangeChildren:function(a,b){null===this.s
tartTime?a.currentTime=this.currentTime-b/this.playbackRate:a.startTime!==this.s
tartTime+b/this.playbackRate&&(a.startTime=this.startTime+b/this.playbackRate)},
get timeline(){return this._timeline},get playState(){return this._animation?thi
s._animation.playState:"idle"},get finished(){return window.Promise?(this._finis
hedPromise||(-1==b.animationsWithPromises.indexOf(this)&&b.animationsWithPromise
s.push(this),this._finishedPromise=new Promise(function(a,b){this._resolveFinish
edPromise=function(){a(this)},this._rejectFinishedPromise=function(){b({type:DOM
Exception.ABORT_ERR,name:"AbortError"})}}.bind(this)),"finished"==this.playState
&&this._resolveFinishedPromise()),this._finishedPromise):(console.warn("Animatio
n Promises require JavaScript Promise constructor"),null)},get ready(){return wi
ndow.Promise?(this._readyPromise||(-1==b.animationsWithPromises.indexOf(this)&&b
.animationsWithPromises.push(this),this._readyPromise=new Promise(function(a,b){
this._resolveReadyPromise=function(){a(this)},this._rejectReadyPromise=function(
){b({type:DOMException.ABORT_ERR,name:"AbortError"})}}.bind(this)),"pending"!==t
his.playState&&this._resolveReadyPromise()),this._readyPromise):(console.warn("A
nimation Promises require JavaScript Promise constructor"),null)},get onfinish()
{return this._onfinish},set onfinish(a){"function"==typeof a?(this._onfinish=a,t
his._animation.onfinish=function(b){b.target=this,a.call(this,b)}.bind(this)):(t
his._animation.onfinish=a,this.onfinish=this._animation.onfinish)},get currentTi
me(){this._updatePromises();var a=this._animation.currentTime;return this._updat
ePromises(),a},set currentTime(a){this._updatePromises(),this._animation.current
Time=isFinite(a)?a:Math.sign(a)*Number.MAX_VALUE,this._register(),this._forEachC
hild(function(b,c){b.currentTime=a-c}),this._updatePromises()},get startTime(){r
eturn this._animation.startTime},set startTime(a){this._updatePromises(),this._a
nimation.startTime=isFinite(a)?a:Math.sign(a)*Number.MAX_VALUE,this._register(),
this._forEachChild(function(b,c){b.startTime=a+c}),this._updatePromises()},get p
laybackRate(){return this._animation.playbackRate},set playbackRate(a){this._upd
atePromises();var b=this.currentTime;this._animation.playbackRate=a,this._forEac
hChild(function(b){b.playbackRate=a}),"paused"!=this.playState&&"idle"!=this.pla
yState&&this.play(),null!==b&&(this.currentTime=b),this._updatePromises()},play:
function(){this._updatePromises(),this._paused=!1,this._animation.play(),-1==thi
s._timeline._animations.indexOf(this)&&this._timeline._animations.push(this),thi
s._register(),b.awaitStartTime(this),this._forEachChild(function(a){var b=a.curr
entTime;a.play(),a.currentTime=b}),this._updatePromises()},pause:function(){this
._updatePromises(),this.currentTime&&(this._holdTime=this.currentTime),this._ani
mation.pause(),this._register(),this._forEachChild(function(a){a.pause()}),this.
_paused=!0,this._updatePromises()},finish:function(){this._updatePromises(),this
._animation.finish(),this._register(),this._updatePromises()},cancel:function(){
this._updatePromises(),this._animation.cancel(),this._register(),this._removeChi
ldAnimations(),this._updatePromises()},reverse:function(){this._updatePromises()
;var a=this.currentTime;this._animation.reverse(),this._forEachChild(function(a)
{a.reverse()}),null!==a&&(this.currentTime=a),this._updatePromises()},addEventLi
stener:function(a,b){var c=b;"function"==typeof b&&(c=function(a){a.target=this,
b.call(this,a)}.bind(this),b._wrapper=c),this._animation.addEventListener(a,c)},
removeEventListener:function(a,b){this._animation.removeEventListener(a,b&&b._wr
apper||b)},_removeChildAnimations:function(){for(;this._childAnimations.length;)
this._childAnimations.pop().cancel()},_forEachChild:function(b){var c=0;if(this.
effect.children&&this._childAnimations.length<this.effect.children.length&&this.
_constructChildAnimations(),this._childAnimations.forEach(function(a){b.call(thi
s,a,c),this.effect instanceof window.SequenceEffect&&(c+=a.effect.activeDuration
)}.bind(this)),"pending"!=this.playState){var d=this.effect._timing,e=this.curre
ntTime;null!==e&&(e=a.calculateTimeFraction(a.calculateActiveDuration(d),e,d)),(
null==e||isNaN(e))&&this._removeChildAnimations()}}},window.Animation=b.Animatio
n}(c,e,f),function(a,b){function c(b){this._frames=a.normalizeKeyframes(b)}funct
ion d(){for(var a=!1;h.length;){var b=h.shift();b._updateChildren(),a=!0}return
a}var e=function(a){if(a._animation=void 0,a instanceof window.SequenceEffect||a
instanceof window.GroupEffect)for(var b=0;b<a.children.length;b++)e(a.children[
b])};b.removeMulti=function(a){for(var b=[],c=0;c<a.length;c++){var d=a[c];d._pa
rent?(-1==b.indexOf(d._parent)&&b.push(d._parent),d._parent.children.splice(d._p
arent.children.indexOf(d),1),d._parent=null,e(d)):d._animation&&d._animation.eff
ect==d&&(d._animation.cancel(),d._animation.effect=new KeyframeEffect(null,[]),d
._animation._callback&&(d._animation._callback._animation=null),d._animation._re
buildUnderlyingAnimation(),e(d))}for(c=0;c<b.length;c++)b[c]._rebuild()},b.Keyfr
ameEffect=function(b,d,e){return this.target=b,this._parent=null,e=a.numericTimi
ngToObject(e),this._timingInput=a.cloneTimingInput(e),this._timing=a.normalizeTi
mingInput(e),this.timing=a.makeTiming(e,!1,this),this.timing._effect=this,"funct
ion"==typeof d?(a.deprecated("Custom KeyframeEffect","2015-06-22","Use KeyframeE
ffect.onsample instead."),this._normalizedKeyframes=d):this._normalizedKeyframes
=new c(d),this._keyframes=d,this.activeDuration=a.calculateActiveDuration(this._
timing),this},b.KeyframeEffect.prototype={getFrames:function(){return"function"=
=typeof this._normalizedKeyframes?this._normalizedKeyframes:this._normalizedKeyf
rames._frames},set onsample(a){if("function"==typeof this.getFrames())throw new
Error("Setting onsample on custom effect KeyframeEffect is not supported.");this
._onsample=a,this._animation&&this._animation._rebuildUnderlyingAnimation()},get
parent(){return this._parent},clone:function(){if("function"==typeof this.getFr
ames())throw new Error("Cloning custom effects is not supported.");var b=new Key
frameEffect(this.target,[],a.cloneTimingInput(this._timingInput));return b._norm
alizedKeyframes=this._normalizedKeyframes,b._keyframes=this._keyframes,b},remove
:function(){b.removeMulti([this])}};var f=Element.prototype.animate;Element.prot
otype.animate=function(a,c){return b.timeline._play(new b.KeyframeEffect(this,a,
c))};var g=document.createElementNS("http://www.w3.org/1999/xhtml","div");b.newU
nderlyingAnimationForKeyframeEffect=function(a){if(a){var b=a.target||g,c=a._key
frames;"function"==typeof c&&(c=[]);var d=a._timingInput}else var b=g,c=[],d=0;r
eturn f.apply(b,[c,d])},b.bindAnimationForKeyframeEffect=function(a){a.effect&&"
function"==typeof a.effect._normalizedKeyframes&&b.bindAnimationForCustomEffect(
a)};var h=[];b.awaitStartTime=function(a){null===a.startTime&&a._isGroup&&(0==h.
length&&requestAnimationFrame(d),h.push(a))};var i=window.getComputedStyle;Objec
t.defineProperty(window,"getComputedStyle",{configurable:!0,enumerable:!0,value:
function(){window.document.timeline._updateAnimationsPromises();var a=i.apply(th
is,arguments);return d()&&(a=i.apply(this,arguments)),window.document.timeline._
updateAnimationsPromises(),a}}),window.KeyframeEffect=b.KeyframeEffect,window.El
ement.prototype.getAnimations=function(){return document.timeline.getAnimations(
).filter(function(a){return null!==a.effect&&a.effect.target==this}.bind(this))}
}(c,e,f),function(a,b){function c(a){a._registered||(a._registered=!0,f.push(a),
g||(g=!0,requestAnimationFrame(d)))}function d(){var a=f;f=[],a.sort(function(a,
b){return a._sequenceNumber-b._sequenceNumber}),a=a.filter(function(a){a();var b
=a._animation?a._animation.playState:"idle";return"running"!=b&&"pending"!=b&&(a
._registered=!1),a._registered}),f.push.apply(f,a),f.length?(g=!0,requestAnimati
onFrame(d)):g=!1}var e=(document.createElementNS("http://www.w3.org/1999/xhtml",
"div"),0);b.bindAnimationForCustomEffect=function(b){var d,f=b.effect.target,g="
function"==typeof b.effect.getFrames();d=g?b.effect.getFrames():b.effect._onsamp
le;var h=b.effect.timing,i=null;h=a.normalizeTimingInput(h);var j=function(){var
c=j._animation?j._animation.currentTime:null;null!==c&&(c=a.calculateTimeFracti
on(a.calculateActiveDuration(h),c,h),isNaN(c)&&(c=null)),c!==i&&(g?d(c,f,b.effec
t):d(c,b.effect,b.effect._animation)),i=c};j._animation=b,j._registered=!1,j._se
quenceNumber=e++,b._callback=j,c(j)};var f=[],g=!1;b.Animation.prototype._regist
er=function(){this._callback&&c(this._callback)}}(c,e,f),function(a,b){function
c(a){return a._timing.delay+a.activeDuration+a._timing.endDelay}function d(b,c){
this._parent=null,this.children=b||[],this._reparent(this.children),c=a.numericT
imingToObject(c),this._timingInput=a.cloneTimingInput(c),this._timing=a.normaliz
eTimingInput(c,!0),this.timing=a.makeTiming(c,!0,this),this.timing._effect=this,
"auto"===this._timing.duration&&(this._timing.duration=this.activeDuration)}wind
ow.SequenceEffect=function(){d.apply(this,arguments)},window.GroupEffect=functio
n(){d.apply(this,arguments)},d.prototype={_isAncestor:function(a){for(var b=this
;null!==b;){if(b==a)return!0;b=b._parent}return!1},_rebuild:function(){for(var a
=this;a;)"auto"===a.timing.duration&&(a._timing.duration=a.activeDuration),a=a._
parent;this._animation&&this._animation._rebuildUnderlyingAnimation()},_reparent
:function(a){b.removeMulti(a);for(var c=0;c<a.length;c++)a[c]._parent=this},_put
Child:function(a,b){for(var c=b?"Cannot append an ancestor or self":"Cannot prep
end an ancestor or self",d=0;d<a.length;d++)if(this._isAncestor(a[d]))throw{type
:DOMException.HIERARCHY_REQUEST_ERR,name:"HierarchyRequestError",message:c};for(
var d=0;d<a.length;d++)b?this.children.push(a[d]):this.children.unshift(a[d]);th
is._reparent(a),this._rebuild()},append:function(){this._putChild(arguments,!0)}
,prepend:function(){this._putChild(arguments,!1)},get parent(){return this._pare
nt},get firstChild(){return this.children.length?this.children[0]:null},get last
Child(){return this.children.length?this.children[this.children.length-1]:null},
clone:function(){for(var b=a.cloneTimingInput(this._timingInput),c=[],d=0;d<this
.children.length;d++)c.push(this.children[d].clone());return this instanceof Gro
upEffect?new GroupEffect(c,b):new SequenceEffect(c,b)},remove:function(){b.remov
eMulti([this])}},window.SequenceEffect.prototype=Object.create(d.prototype),Obje
ct.defineProperty(window.SequenceEffect.prototype,"activeDuration",{get:function
(){var a=0;return this.children.forEach(function(b){a+=c(b)}),Math.max(a,0)}}),w
indow.GroupEffect.prototype=Object.create(d.prototype),Object.defineProperty(win
dow.GroupEffect.prototype,"activeDuration",{get:function(){var a=0;return this.c
hildren.forEach(function(b){a=Math.max(a,c(b))}),a}}),b.newUnderlyingAnimationFo
rGroup=function(c){var d,e=null,f=function(b){var c=d._wrapper;return c&&"pendin
g"!=c.playState&&c.effect?null==b?void c._removeChildAnimations():0==b&&c.playba
ckRate<0&&(e||(e=a.normalizeTimingInput(c.effect.timing)),b=a.calculateTimeFract
ion(a.calculateActiveDuration(e),-1,e),isNaN(b)||null==b)?(c._forEachChild(funct
ion(a){a.currentTime=-1}),void c._removeChildAnimations()):void 0:void 0},g=new
KeyframeEffect(null,[],c._timing);return g.onsample=f,d=b.timeline._play(g)},b.b
indAnimationForGroup=function(a){a._animation._wrapper=a,a._isGroup=!0,b.awaitSt
artTime(a),a._constructChildAnimations(),a._setExternalAnimation(a)},b.groupChil
dDuration=c}(c,e,f)}({},function(){return this}()); | |
1818 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1794 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
1819 // Use of this source code is governed by a BSD-style license that can be | 1795 // Use of this source code is governed by a BSD-style license that can be |
1820 // found in the LICENSE file. | 1796 // found in the LICENSE file. |
1821 | 1797 |
1822 // <include src="../../../../ui/webui/resources/js/i18n_template_no_process.js"> | 1798 // <include src="../../../../ui/webui/resources/js/i18n_template_no_process.js"> |
1823 | 1799 |
1824 i18nTemplate.process(document, loadTimeData); | 1800 i18nTemplate.process(document, loadTimeData); |
1825 (function () { | |
1826 function resolve() { | |
1827 document.body.removeAttribute('unresolved'); | |
1828 } | |
1829 if (window.WebComponents) { | |
1830 addEventListener('WebComponentsReady', resolve); | |
1831 } else { | |
1832 if (document.readyState === 'interactive' || document.readyState === 'complete')
{ | |
1833 resolve(); | |
1834 } else { | |
1835 addEventListener('DOMContentLoaded', resolve); | |
1836 } | |
1837 } | |
1838 }()); | |
1839 window.Polymer = { | |
1840 Settings: function () { | |
1841 var user = window.Polymer || {}; | |
1842 var parts = location.search.slice(1).split('&'); | |
1843 for (var i = 0, o; i < parts.length && (o = parts[i]); i++) { | |
1844 o = o.split('='); | |
1845 o[0] && (user[o[0]] = o[1] || true); | |
1846 } | |
1847 var wantShadow = user.dom === 'shadow'; | |
1848 var hasShadow = Boolean(Element.prototype.createShadowRoot); | |
1849 var nativeShadow = hasShadow && !window.ShadowDOMPolyfill; | |
1850 var useShadow = wantShadow && hasShadow; | |
1851 var hasNativeImports = Boolean('import' in document.createElement('link')); | |
1852 var useNativeImports = hasNativeImports; | |
1853 var useNativeCustomElements = !window.CustomElements || window.CustomElements.us
eNative; | |
1854 return { | |
1855 wantShadow: wantShadow, | |
1856 hasShadow: hasShadow, | |
1857 nativeShadow: nativeShadow, | |
1858 useShadow: useShadow, | |
1859 useNativeShadow: useShadow && nativeShadow, | |
1860 useNativeImports: useNativeImports, | |
1861 useNativeCustomElements: useNativeCustomElements | |
1862 }; | |
1863 }() | |
1864 }; | |
1865 (function () { | |
1866 var userPolymer = window.Polymer; | |
1867 window.Polymer = function (prototype) { | |
1868 if (typeof prototype === 'function') { | |
1869 prototype = prototype.prototype; | |
1870 } | |
1871 if (!prototype) { | |
1872 prototype = {}; | |
1873 } | |
1874 var factory = desugar(prototype); | |
1875 prototype = factory.prototype; | |
1876 var options = { prototype: prototype }; | |
1877 if (prototype.extends) { | |
1878 options.extends = prototype.extends; | |
1879 } | |
1880 Polymer.telemetry._registrate(prototype); | |
1881 document.registerElement(prototype.is, options); | |
1882 return factory; | |
1883 }; | |
1884 var desugar = function (prototype) { | |
1885 var base = Polymer.Base; | |
1886 if (prototype.extends) { | |
1887 base = Polymer.Base._getExtendedPrototype(prototype.extends); | |
1888 } | |
1889 prototype = Polymer.Base.chainObject(prototype, base); | |
1890 prototype.registerCallback(); | |
1891 return prototype.constructor; | |
1892 }; | |
1893 window.Polymer = Polymer; | |
1894 if (userPolymer) { | |
1895 for (var i in userPolymer) { | |
1896 Polymer[i] = userPolymer[i]; | |
1897 } | |
1898 } | |
1899 Polymer.Class = desugar; | |
1900 }()); | |
1901 Polymer.telemetry = { | |
1902 registrations: [], | |
1903 _regLog: function (prototype) { | |
1904 console.log('[' + prototype.is + ']: registered'); | |
1905 }, | |
1906 _registrate: function (prototype) { | |
1907 this.registrations.push(prototype); | |
1908 Polymer.log && this._regLog(prototype); | |
1909 }, | |
1910 dumpRegistrations: function () { | |
1911 this.registrations.forEach(this._regLog); | |
1912 } | |
1913 }; | |
1914 Object.defineProperty(window, 'currentImport', { | |
1915 enumerable: true, | |
1916 configurable: true, | |
1917 get: function () { | |
1918 return (document._currentScript || document.currentScript).ownerDocument; | |
1919 } | |
1920 }); | |
1921 Polymer.RenderStatus = { | |
1922 _ready: false, | |
1923 _callbacks: [], | |
1924 whenReady: function (cb) { | |
1925 if (this._ready) { | |
1926 cb(); | |
1927 } else { | |
1928 this._callbacks.push(cb); | |
1929 } | |
1930 }, | |
1931 _makeReady: function () { | |
1932 this._ready = true; | |
1933 for (var i = 0; i < this._callbacks.length; i++) { | |
1934 this._callbacks[i](); | |
1935 } | |
1936 this._callbacks = []; | |
1937 }, | |
1938 _catchFirstRender: function () { | |
1939 requestAnimationFrame(function () { | |
1940 Polymer.RenderStatus._makeReady(); | |
1941 }); | |
1942 }, | |
1943 _afterNextRenderQueue: [], | |
1944 _waitingNextRender: false, | |
1945 afterNextRender: function (element, fn, args) { | |
1946 this._watchNextRender(); | |
1947 this._afterNextRenderQueue.push([ | |
1948 element, | |
1949 fn, | |
1950 args | |
1951 ]); | |
1952 }, | |
1953 _watchNextRender: function () { | |
1954 if (!this._waitingNextRender) { | |
1955 this._waitingNextRender = true; | |
1956 var fn = function () { | |
1957 Polymer.RenderStatus._flushNextRender(); | |
1958 }; | |
1959 if (!this._ready) { | |
1960 this.whenReady(fn); | |
1961 } else { | |
1962 requestAnimationFrame(fn); | |
1963 } | |
1964 } | |
1965 }, | |
1966 _flushNextRender: function () { | |
1967 var self = this; | |
1968 setTimeout(function () { | |
1969 self._flushRenderCallbacks(self._afterNextRenderQueue); | |
1970 self._afterNextRenderQueue = []; | |
1971 self._waitingNextRender = false; | |
1972 }); | |
1973 }, | |
1974 _flushRenderCallbacks: function (callbacks) { | |
1975 for (var i = 0, h; i < callbacks.length; i++) { | |
1976 h = callbacks[i]; | |
1977 h[1].apply(h[0], h[2] || Polymer.nar); | |
1978 } | |
1979 ; | |
1980 } | |
1981 }; | |
1982 if (window.HTMLImports) { | |
1983 HTMLImports.whenReady(function () { | |
1984 Polymer.RenderStatus._catchFirstRender(); | |
1985 }); | |
1986 } else { | |
1987 Polymer.RenderStatus._catchFirstRender(); | |
1988 } | |
1989 Polymer.ImportStatus = Polymer.RenderStatus; | |
1990 Polymer.ImportStatus.whenLoaded = Polymer.ImportStatus.whenReady; | |
1991 Polymer.Base = { | |
1992 __isPolymerInstance__: true, | |
1993 _addFeature: function (feature) { | |
1994 this.extend(this, feature); | |
1995 }, | |
1996 registerCallback: function () { | |
1997 this._desugarBehaviors(); | |
1998 this._doBehavior('beforeRegister'); | |
1999 this._registerFeatures(); | |
2000 this._doBehavior('registered'); | |
2001 }, | |
2002 createdCallback: function () { | |
2003 Polymer.telemetry.instanceCount++; | |
2004 this.root = this; | |
2005 this._doBehavior('created'); | |
2006 this._initFeatures(); | |
2007 }, | |
2008 attachedCallback: function () { | |
2009 var self = this; | |
2010 Polymer.RenderStatus.whenReady(function () { | |
2011 self.isAttached = true; | |
2012 self._doBehavior('attached'); | |
2013 }); | |
2014 }, | |
2015 detachedCallback: function () { | |
2016 this.isAttached = false; | |
2017 this._doBehavior('detached'); | |
2018 }, | |
2019 attributeChangedCallback: function (name, oldValue, newValue) { | |
2020 this._attributeChangedImpl(name); | |
2021 this._doBehavior('attributeChanged', [ | |
2022 name, | |
2023 oldValue, | |
2024 newValue | |
2025 ]); | |
2026 }, | |
2027 _attributeChangedImpl: function (name) { | |
2028 this._setAttributeToProperty(this, name); | |
2029 }, | |
2030 extend: function (prototype, api) { | |
2031 if (prototype && api) { | |
2032 var n$ = Object.getOwnPropertyNames(api); | |
2033 for (var i = 0, n; i < n$.length && (n = n$[i]); i++) { | |
2034 this.copyOwnProperty(n, api, prototype); | |
2035 } | |
2036 } | |
2037 return prototype || api; | |
2038 }, | |
2039 mixin: function (target, source) { | |
2040 for (var i in source) { | |
2041 target[i] = source[i]; | |
2042 } | |
2043 return target; | |
2044 }, | |
2045 copyOwnProperty: function (name, source, target) { | |
2046 var pd = Object.getOwnPropertyDescriptor(source, name); | |
2047 if (pd) { | |
2048 Object.defineProperty(target, name, pd); | |
2049 } | |
2050 }, | |
2051 _log: console.log.apply.bind(console.log, console), | |
2052 _warn: console.warn.apply.bind(console.warn, console), | |
2053 _error: console.error.apply.bind(console.error, console), | |
2054 _logf: function () { | |
2055 return this._logPrefix.concat([this.is]).concat(Array.prototype.slice.call(argum
ents, 0)); | |
2056 } | |
2057 }; | |
2058 Polymer.Base._logPrefix = function () { | |
2059 var color = window.chrome || /firefox/i.test(navigator.userAgent); | |
2060 return color ? [ | |
2061 '%c[%s::%s]:', | |
2062 'font-weight: bold; background-color:#EEEE00;' | |
2063 ] : ['[%s::%s]:']; | |
2064 }(); | |
2065 Polymer.Base.chainObject = function (object, inherited) { | |
2066 if (object && inherited && object !== inherited) { | |
2067 if (!Object.__proto__) { | |
2068 object = Polymer.Base.extend(Object.create(inherited), object); | |
2069 } | |
2070 object.__proto__ = inherited; | |
2071 } | |
2072 return object; | |
2073 }; | |
2074 Polymer.Base = Polymer.Base.chainObject(Polymer.Base, HTMLElement.prototype); | |
2075 if (window.CustomElements) { | |
2076 Polymer.instanceof = CustomElements.instanceof; | |
2077 } else { | |
2078 Polymer.instanceof = function (obj, ctor) { | |
2079 return obj instanceof ctor; | |
2080 }; | |
2081 } | |
2082 Polymer.isInstance = function (obj) { | |
2083 return Boolean(obj && obj.__isPolymerInstance__); | |
2084 }; | |
2085 Polymer.telemetry.instanceCount = 0; | |
2086 (function () { | |
2087 var modules = {}; | |
2088 var lcModules = {}; | |
2089 var findModule = function (id) { | |
2090 return modules[id] || lcModules[id.toLowerCase()]; | |
2091 }; | |
2092 var DomModule = function () { | |
2093 return document.createElement('dom-module'); | |
2094 }; | |
2095 DomModule.prototype = Object.create(HTMLElement.prototype); | |
2096 Polymer.Base.extend(DomModule.prototype, { | |
2097 constructor: DomModule, | |
2098 createdCallback: function () { | |
2099 this.register(); | |
2100 }, | |
2101 register: function (id) { | |
2102 var id = id || this.id || this.getAttribute('name') || this.getAttribute('is'); | |
2103 if (id) { | |
2104 this.id = id; | |
2105 modules[id] = this; | |
2106 lcModules[id.toLowerCase()] = this; | |
2107 } | |
2108 }, | |
2109 import: function (id, selector) { | |
2110 if (id) { | |
2111 var m = findModule(id); | |
2112 if (!m) { | |
2113 forceDomModulesUpgrade(); | |
2114 m = findModule(id); | |
2115 } | |
2116 if (m && selector) { | |
2117 m = m.querySelector(selector); | |
2118 } | |
2119 return m; | |
2120 } | |
2121 } | |
2122 }); | |
2123 var cePolyfill = window.CustomElements && !CustomElements.useNative; | |
2124 document.registerElement('dom-module', DomModule); | |
2125 function forceDomModulesUpgrade() { | |
2126 if (cePolyfill) { | |
2127 var script = document._currentScript || document.currentScript; | |
2128 var doc = script && script.ownerDocument || document; | |
2129 var modules = doc.querySelectorAll('dom-module'); | |
2130 for (var i = modules.length - 1, m; i >= 0 && (m = modules[i]); i--) { | |
2131 if (m.__upgraded__) { | |
2132 return; | |
2133 } else { | |
2134 CustomElements.upgrade(m); | |
2135 } | |
2136 } | |
2137 } | |
2138 } | |
2139 }()); | |
2140 Polymer.Base._addFeature({ | |
2141 _prepIs: function () { | |
2142 if (!this.is) { | |
2143 var module = (document._currentScript || document.currentScript).parentNode; | |
2144 if (module.localName === 'dom-module') { | |
2145 var id = module.id || module.getAttribute('name') || module.getAttribute('is'); | |
2146 this.is = id; | |
2147 } | |
2148 } | |
2149 if (this.is) { | |
2150 this.is = this.is.toLowerCase(); | |
2151 } | |
2152 } | |
2153 }); | |
2154 Polymer.Base._addFeature({ | |
2155 behaviors: [], | |
2156 _desugarBehaviors: function () { | |
2157 if (this.behaviors.length) { | |
2158 this.behaviors = this._desugarSomeBehaviors(this.behaviors); | |
2159 } | |
2160 }, | |
2161 _desugarSomeBehaviors: function (behaviors) { | |
2162 behaviors = this._flattenBehaviorsList(behaviors); | |
2163 for (var i = behaviors.length - 1; i >= 0; i--) { | |
2164 this._mixinBehavior(behaviors[i]); | |
2165 } | |
2166 return behaviors; | |
2167 }, | |
2168 _flattenBehaviorsList: function (behaviors) { | |
2169 var flat = []; | |
2170 for (var i = 0; i < behaviors.length; i++) { | |
2171 var b = behaviors[i]; | |
2172 if (b instanceof Array) { | |
2173 flat = flat.concat(this._flattenBehaviorsList(b)); | |
2174 } else if (b) { | |
2175 flat.push(b); | |
2176 } else { | |
2177 this._warn(this._logf('_flattenBehaviorsList', 'behavior is null, check for miss
ing or 404 import')); | |
2178 } | |
2179 } | |
2180 return flat; | |
2181 }, | |
2182 _mixinBehavior: function (b) { | |
2183 var n$ = Object.getOwnPropertyNames(b); | |
2184 for (var i = 0, n; i < n$.length && (n = n$[i]); i++) { | |
2185 if (!Polymer.Base._behaviorProperties[n] && !this.hasOwnProperty(n)) { | |
2186 this.copyOwnProperty(n, b, this); | |
2187 } | |
2188 } | |
2189 }, | |
2190 _prepBehaviors: function () { | |
2191 this._prepFlattenedBehaviors(this.behaviors); | |
2192 }, | |
2193 _prepFlattenedBehaviors: function (behaviors) { | |
2194 for (var i = 0, l = behaviors.length; i < l; i++) { | |
2195 this._prepBehavior(behaviors[i]); | |
2196 } | |
2197 this._prepBehavior(this); | |
2198 }, | |
2199 _doBehavior: function (name, args) { | |
2200 for (var i = 0; i < this.behaviors.length; i++) { | |
2201 this._invokeBehavior(this.behaviors[i], name, args); | |
2202 } | |
2203 this._invokeBehavior(this, name, args); | |
2204 }, | |
2205 _invokeBehavior: function (b, name, args) { | |
2206 var fn = b[name]; | |
2207 if (fn) { | |
2208 fn.apply(this, args || Polymer.nar); | |
2209 } | |
2210 }, | |
2211 _marshalBehaviors: function () { | |
2212 for (var i = 0; i < this.behaviors.length; i++) { | |
2213 this._marshalBehavior(this.behaviors[i]); | |
2214 } | |
2215 this._marshalBehavior(this); | |
2216 } | |
2217 }); | |
2218 Polymer.Base._behaviorProperties = { | |
2219 hostAttributes: true, | |
2220 registered: true, | |
2221 properties: true, | |
2222 observers: true, | |
2223 listeners: true, | |
2224 created: true, | |
2225 attached: true, | |
2226 detached: true, | |
2227 attributeChanged: true, | |
2228 ready: true | |
2229 }; | |
2230 Polymer.Base._addFeature({ | |
2231 _getExtendedPrototype: function (tag) { | |
2232 return this._getExtendedNativePrototype(tag); | |
2233 }, | |
2234 _nativePrototypes: {}, | |
2235 _getExtendedNativePrototype: function (tag) { | |
2236 var p = this._nativePrototypes[tag]; | |
2237 if (!p) { | |
2238 var np = this.getNativePrototype(tag); | |
2239 p = this.extend(Object.create(np), Polymer.Base); | |
2240 this._nativePrototypes[tag] = p; | |
2241 } | |
2242 return p; | |
2243 }, | |
2244 getNativePrototype: function (tag) { | |
2245 return Object.getPrototypeOf(document.createElement(tag)); | |
2246 } | |
2247 }); | |
2248 Polymer.Base._addFeature({ | |
2249 _prepConstructor: function () { | |
2250 this._factoryArgs = this.extends ? [ | |
2251 this.extends, | |
2252 this.is | |
2253 ] : [this.is]; | |
2254 var ctor = function () { | |
2255 return this._factory(arguments); | |
2256 }; | |
2257 if (this.hasOwnProperty('extends')) { | |
2258 ctor.extends = this.extends; | |
2259 } | |
2260 Object.defineProperty(this, 'constructor', { | |
2261 value: ctor, | |
2262 writable: true, | |
2263 configurable: true | |
2264 }); | |
2265 ctor.prototype = this; | |
2266 }, | |
2267 _factory: function (args) { | |
2268 var elt = document.createElement.apply(document, this._factoryArgs); | |
2269 if (this.factoryImpl) { | |
2270 this.factoryImpl.apply(elt, args); | |
2271 } | |
2272 return elt; | |
2273 } | |
2274 }); | |
2275 Polymer.nob = Object.create(null); | |
2276 Polymer.Base._addFeature({ | |
2277 properties: {}, | |
2278 getPropertyInfo: function (property) { | |
2279 var info = this._getPropertyInfo(property, this.properties); | |
2280 if (!info) { | |
2281 for (var i = 0; i < this.behaviors.length; i++) { | |
2282 info = this._getPropertyInfo(property, this.behaviors[i].properties); | |
2283 if (info) { | |
2284 return info; | |
2285 } | |
2286 } | |
2287 ; | |
2288 } | |
2289 return info || Polymer.nob; | |
2290 }, | |
2291 _getPropertyInfo: function (property, properties) { | |
2292 var p = properties && properties[property]; | |
2293 if (typeof p === 'function') { | |
2294 p = properties[property] = { type: p }; | |
2295 } | |
2296 if (p) { | |
2297 p.defined = true; | |
2298 } | |
2299 return p; | |
2300 }, | |
2301 _prepPropertyInfo: function () { | |
2302 this._propertyInfo = {}; | |
2303 for (var i = 0, p; i < this.behaviors.length; i++) { | |
2304 this._addPropertyInfo(this._propertyInfo, this.behaviors[i].properties); | |
2305 } | |
2306 this._addPropertyInfo(this._propertyInfo, this.properties); | |
2307 this._addPropertyInfo(this._propertyInfo, this._propertyEffects); | |
2308 }, | |
2309 _addPropertyInfo: function (target, source) { | |
2310 if (source) { | |
2311 var t, s; | |
2312 for (var i in source) { | |
2313 t = target[i]; | |
2314 s = source[i]; | |
2315 if (i[0] === '_' && !s.readOnly) { | |
2316 continue; | |
2317 } | |
2318 if (!target[i]) { | |
2319 target[i] = { | |
2320 type: typeof s === 'function' ? s : s.type, | |
2321 readOnly: s.readOnly, | |
2322 attribute: Polymer.CaseMap.camelToDashCase(i) | |
2323 }; | |
2324 } else { | |
2325 if (!t.type) { | |
2326 t.type = s.type; | |
2327 } | |
2328 if (!t.readOnly) { | |
2329 t.readOnly = s.readOnly; | |
2330 } | |
2331 } | |
2332 } | |
2333 } | |
2334 } | |
2335 }); | |
2336 Polymer.CaseMap = { | |
2337 _caseMap: {}, | |
2338 dashToCamelCase: function (dash) { | |
2339 var mapped = Polymer.CaseMap._caseMap[dash]; | |
2340 if (mapped) { | |
2341 return mapped; | |
2342 } | |
2343 if (dash.indexOf('-') < 0) { | |
2344 return Polymer.CaseMap._caseMap[dash] = dash; | |
2345 } | |
2346 return Polymer.CaseMap._caseMap[dash] = dash.replace(/-([a-z])/g, function (m) { | |
2347 return m[1].toUpperCase(); | |
2348 }); | |
2349 }, | |
2350 camelToDashCase: function (camel) { | |
2351 var mapped = Polymer.CaseMap._caseMap[camel]; | |
2352 if (mapped) { | |
2353 return mapped; | |
2354 } | |
2355 return Polymer.CaseMap._caseMap[camel] = camel.replace(/([a-z][A-Z])/g, function
(g) { | |
2356 return g[0] + '-' + g[1].toLowerCase(); | |
2357 }); | |
2358 } | |
2359 }; | |
2360 Polymer.Base._addFeature({ | |
2361 _addHostAttributes: function (attributes) { | |
2362 if (!this._aggregatedAttributes) { | |
2363 this._aggregatedAttributes = {}; | |
2364 } | |
2365 if (attributes) { | |
2366 this.mixin(this._aggregatedAttributes, attributes); | |
2367 } | |
2368 }, | |
2369 _marshalHostAttributes: function () { | |
2370 if (this._aggregatedAttributes) { | |
2371 this._applyAttributes(this, this._aggregatedAttributes); | |
2372 } | |
2373 }, | |
2374 _applyAttributes: function (node, attr$) { | |
2375 for (var n in attr$) { | |
2376 if (!this.hasAttribute(n) && n !== 'class') { | |
2377 var v = attr$[n]; | |
2378 this.serializeValueToAttribute(v, n, this); | |
2379 } | |
2380 } | |
2381 }, | |
2382 _marshalAttributes: function () { | |
2383 this._takeAttributesToModel(this); | |
2384 }, | |
2385 _takeAttributesToModel: function (model) { | |
2386 if (this.hasAttributes()) { | |
2387 for (var i in this._propertyInfo) { | |
2388 var info = this._propertyInfo[i]; | |
2389 if (this.hasAttribute(info.attribute)) { | |
2390 this._setAttributeToProperty(model, info.attribute, i, info); | |
2391 } | |
2392 } | |
2393 } | |
2394 }, | |
2395 _setAttributeToProperty: function (model, attribute, property, info) { | |
2396 if (!this._serializing) { | |
2397 var property = property || Polymer.CaseMap.dashToCamelCase(attribute); | |
2398 info = info || this._propertyInfo && this._propertyInfo[property]; | |
2399 if (info && !info.readOnly) { | |
2400 var v = this.getAttribute(attribute); | |
2401 model[property] = this.deserialize(v, info.type); | |
2402 } | |
2403 } | |
2404 }, | |
2405 _serializing: false, | |
2406 reflectPropertyToAttribute: function (property, attribute, value) { | |
2407 this._serializing = true; | |
2408 value = value === undefined ? this[property] : value; | |
2409 this.serializeValueToAttribute(value, attribute || Polymer.CaseMap.camelToDashCa
se(property)); | |
2410 this._serializing = false; | |
2411 }, | |
2412 serializeValueToAttribute: function (value, attribute, node) { | |
2413 var str = this.serialize(value); | |
2414 node = node || this; | |
2415 if (str === undefined) { | |
2416 node.removeAttribute(attribute); | |
2417 } else { | |
2418 node.setAttribute(attribute, str); | |
2419 } | |
2420 }, | |
2421 deserialize: function (value, type) { | |
2422 switch (type) { | |
2423 case Number: | |
2424 value = Number(value); | |
2425 break; | |
2426 case Boolean: | |
2427 value = value !== null; | |
2428 break; | |
2429 case Object: | |
2430 try { | |
2431 value = JSON.parse(value); | |
2432 } catch (x) { | |
2433 } | |
2434 break; | |
2435 case Array: | |
2436 try { | |
2437 value = JSON.parse(value); | |
2438 } catch (x) { | |
2439 value = null; | |
2440 console.warn('Polymer::Attributes: couldn`t decode Array as JSON'); | |
2441 } | |
2442 break; | |
2443 case Date: | |
2444 value = new Date(value); | |
2445 break; | |
2446 case String: | |
2447 default: | |
2448 break; | |
2449 } | |
2450 return value; | |
2451 }, | |
2452 serialize: function (value) { | |
2453 switch (typeof value) { | |
2454 case 'boolean': | |
2455 return value ? '' : undefined; | |
2456 case 'object': | |
2457 if (value instanceof Date) { | |
2458 return value; | |
2459 } else if (value) { | |
2460 try { | |
2461 return JSON.stringify(value); | |
2462 } catch (x) { | |
2463 return ''; | |
2464 } | |
2465 } | |
2466 default: | |
2467 return value != null ? value : undefined; | |
2468 } | |
2469 } | |
2470 }); | |
2471 Polymer.Base._addFeature({ | |
2472 _setupDebouncers: function () { | |
2473 this._debouncers = {}; | |
2474 }, | |
2475 debounce: function (jobName, callback, wait) { | |
2476 return this._debouncers[jobName] = Polymer.Debounce.call(this, this._debouncers[
jobName], callback, wait); | |
2477 }, | |
2478 isDebouncerActive: function (jobName) { | |
2479 var debouncer = this._debouncers[jobName]; | |
2480 return debouncer && debouncer.finish; | |
2481 }, | |
2482 flushDebouncer: function (jobName) { | |
2483 var debouncer = this._debouncers[jobName]; | |
2484 if (debouncer) { | |
2485 debouncer.complete(); | |
2486 } | |
2487 }, | |
2488 cancelDebouncer: function (jobName) { | |
2489 var debouncer = this._debouncers[jobName]; | |
2490 if (debouncer) { | |
2491 debouncer.stop(); | |
2492 } | |
2493 } | |
2494 }); | |
2495 Polymer.version = '1.2.3'; | |
2496 Polymer.Base._addFeature({ | |
2497 _registerFeatures: function () { | |
2498 this._prepIs(); | |
2499 this._prepBehaviors(); | |
2500 this._prepConstructor(); | |
2501 this._prepPropertyInfo(); | |
2502 }, | |
2503 _prepBehavior: function (b) { | |
2504 this._addHostAttributes(b.hostAttributes); | |
2505 }, | |
2506 _marshalBehavior: function (b) { | |
2507 }, | |
2508 _initFeatures: function () { | |
2509 this._marshalHostAttributes(); | |
2510 this._setupDebouncers(); | |
2511 this._marshalBehaviors(); | |
2512 } | |
2513 }); | |
2514 Polymer.Base._addFeature({ | |
2515 _prepTemplate: function () { | |
2516 if (this._template === undefined) { | |
2517 this._template = Polymer.DomModule.import(this.is, 'template'); | |
2518 } | |
2519 if (this._template && this._template.hasAttribute('is')) { | |
2520 this._warn(this._logf('_prepTemplate', 'top-level Polymer template ' + 'must not
be a type-extension, found', this._template, 'Move inside simple <template>.'))
; | |
2521 } | |
2522 if (this._template && !this._template.content && window.HTMLTemplateElement && H
TMLTemplateElement.decorate) { | |
2523 HTMLTemplateElement.decorate(this._template); | |
2524 } | |
2525 }, | |
2526 _stampTemplate: function () { | |
2527 if (this._template) { | |
2528 this.root = this.instanceTemplate(this._template); | |
2529 } | |
2530 }, | |
2531 instanceTemplate: function (template) { | |
2532 var dom = document.importNode(template._content || template.content, true); | |
2533 return dom; | |
2534 } | |
2535 }); | |
2536 (function () { | |
2537 var baseAttachedCallback = Polymer.Base.attachedCallback; | |
2538 Polymer.Base._addFeature({ | |
2539 _hostStack: [], | |
2540 ready: function () { | |
2541 }, | |
2542 _registerHost: function (host) { | |
2543 this.dataHost = host = host || Polymer.Base._hostStack[Polymer.Base._hostStack.l
ength - 1]; | |
2544 if (host && host._clients) { | |
2545 host._clients.push(this); | |
2546 } | |
2547 }, | |
2548 _beginHosting: function () { | |
2549 Polymer.Base._hostStack.push(this); | |
2550 if (!this._clients) { | |
2551 this._clients = []; | |
2552 } | |
2553 }, | |
2554 _endHosting: function () { | |
2555 Polymer.Base._hostStack.pop(); | |
2556 }, | |
2557 _tryReady: function () { | |
2558 if (this._canReady()) { | |
2559 this._ready(); | |
2560 } | |
2561 }, | |
2562 _canReady: function () { | |
2563 return !this.dataHost || this.dataHost._clientsReadied; | |
2564 }, | |
2565 _ready: function () { | |
2566 this._beforeClientsReady(); | |
2567 if (this._template) { | |
2568 this._setupRoot(); | |
2569 this._readyClients(); | |
2570 } | |
2571 this._clientsReadied = true; | |
2572 this._clients = null; | |
2573 this._afterClientsReady(); | |
2574 this._readySelf(); | |
2575 }, | |
2576 _readyClients: function () { | |
2577 this._beginDistribute(); | |
2578 var c$ = this._clients; | |
2579 if (c$) { | |
2580 for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { | |
2581 c._ready(); | |
2582 } | |
2583 } | |
2584 this._finishDistribute(); | |
2585 }, | |
2586 _readySelf: function () { | |
2587 this._doBehavior('ready'); | |
2588 this._readied = true; | |
2589 if (this._attachedPending) { | |
2590 this._attachedPending = false; | |
2591 this.attachedCallback(); | |
2592 } | |
2593 }, | |
2594 _beforeClientsReady: function () { | |
2595 }, | |
2596 _afterClientsReady: function () { | |
2597 }, | |
2598 _beforeAttached: function () { | |
2599 }, | |
2600 attachedCallback: function () { | |
2601 if (this._readied) { | |
2602 this._beforeAttached(); | |
2603 baseAttachedCallback.call(this); | |
2604 } else { | |
2605 this._attachedPending = true; | |
2606 } | |
2607 } | |
2608 }); | |
2609 }()); | |
2610 Polymer.ArraySplice = function () { | |
2611 function newSplice(index, removed, addedCount) { | |
2612 return { | |
2613 index: index, | |
2614 removed: removed, | |
2615 addedCount: addedCount | |
2616 }; | |
2617 } | |
2618 var EDIT_LEAVE = 0; | |
2619 var EDIT_UPDATE = 1; | |
2620 var EDIT_ADD = 2; | |
2621 var EDIT_DELETE = 3; | |
2622 function ArraySplice() { | |
2623 } | |
2624 ArraySplice.prototype = { | |
2625 calcEditDistances: function (current, currentStart, currentEnd, old, oldStart, o
ldEnd) { | |
2626 var rowCount = oldEnd - oldStart + 1; | |
2627 var columnCount = currentEnd - currentStart + 1; | |
2628 var distances = new Array(rowCount); | |
2629 for (var i = 0; i < rowCount; i++) { | |
2630 distances[i] = new Array(columnCount); | |
2631 distances[i][0] = i; | |
2632 } | |
2633 for (var j = 0; j < columnCount; j++) | |
2634 distances[0][j] = j; | |
2635 for (var i = 1; i < rowCount; i++) { | |
2636 for (var j = 1; j < columnCount; j++) { | |
2637 if (this.equals(current[currentStart + j - 1], old[oldStart + i - 1])) | |
2638 distances[i][j] = distances[i - 1][j - 1]; | |
2639 else { | |
2640 var north = distances[i - 1][j] + 1; | |
2641 var west = distances[i][j - 1] + 1; | |
2642 distances[i][j] = north < west ? north : west; | |
2643 } | |
2644 } | |
2645 } | |
2646 return distances; | |
2647 }, | |
2648 spliceOperationsFromEditDistances: function (distances) { | |
2649 var i = distances.length - 1; | |
2650 var j = distances[0].length - 1; | |
2651 var current = distances[i][j]; | |
2652 var edits = []; | |
2653 while (i > 0 || j > 0) { | |
2654 if (i == 0) { | |
2655 edits.push(EDIT_ADD); | |
2656 j--; | |
2657 continue; | |
2658 } | |
2659 if (j == 0) { | |
2660 edits.push(EDIT_DELETE); | |
2661 i--; | |
2662 continue; | |
2663 } | |
2664 var northWest = distances[i - 1][j - 1]; | |
2665 var west = distances[i - 1][j]; | |
2666 var north = distances[i][j - 1]; | |
2667 var min; | |
2668 if (west < north) | |
2669 min = west < northWest ? west : northWest; | |
2670 else | |
2671 min = north < northWest ? north : northWest; | |
2672 if (min == northWest) { | |
2673 if (northWest == current) { | |
2674 edits.push(EDIT_LEAVE); | |
2675 } else { | |
2676 edits.push(EDIT_UPDATE); | |
2677 current = northWest; | |
2678 } | |
2679 i--; | |
2680 j--; | |
2681 } else if (min == west) { | |
2682 edits.push(EDIT_DELETE); | |
2683 i--; | |
2684 current = west; | |
2685 } else { | |
2686 edits.push(EDIT_ADD); | |
2687 j--; | |
2688 current = north; | |
2689 } | |
2690 } | |
2691 edits.reverse(); | |
2692 return edits; | |
2693 }, | |
2694 calcSplices: function (current, currentStart, currentEnd, old, oldStart, oldEnd)
{ | |
2695 var prefixCount = 0; | |
2696 var suffixCount = 0; | |
2697 var minLength = Math.min(currentEnd - currentStart, oldEnd - oldStart); | |
2698 if (currentStart == 0 && oldStart == 0) | |
2699 prefixCount = this.sharedPrefix(current, old, minLength); | |
2700 if (currentEnd == current.length && oldEnd == old.length) | |
2701 suffixCount = this.sharedSuffix(current, old, minLength - prefixCount); | |
2702 currentStart += prefixCount; | |
2703 oldStart += prefixCount; | |
2704 currentEnd -= suffixCount; | |
2705 oldEnd -= suffixCount; | |
2706 if (currentEnd - currentStart == 0 && oldEnd - oldStart == 0) | |
2707 return []; | |
2708 if (currentStart == currentEnd) { | |
2709 var splice = newSplice(currentStart, [], 0); | |
2710 while (oldStart < oldEnd) | |
2711 splice.removed.push(old[oldStart++]); | |
2712 return [splice]; | |
2713 } else if (oldStart == oldEnd) | |
2714 return [newSplice(currentStart, [], currentEnd - currentStart)]; | |
2715 var ops = this.spliceOperationsFromEditDistances(this.calcEditDistances(current,
currentStart, currentEnd, old, oldStart, oldEnd)); | |
2716 var splice = undefined; | |
2717 var splices = []; | |
2718 var index = currentStart; | |
2719 var oldIndex = oldStart; | |
2720 for (var i = 0; i < ops.length; i++) { | |
2721 switch (ops[i]) { | |
2722 case EDIT_LEAVE: | |
2723 if (splice) { | |
2724 splices.push(splice); | |
2725 splice = undefined; | |
2726 } | |
2727 index++; | |
2728 oldIndex++; | |
2729 break; | |
2730 case EDIT_UPDATE: | |
2731 if (!splice) | |
2732 splice = newSplice(index, [], 0); | |
2733 splice.addedCount++; | |
2734 index++; | |
2735 splice.removed.push(old[oldIndex]); | |
2736 oldIndex++; | |
2737 break; | |
2738 case EDIT_ADD: | |
2739 if (!splice) | |
2740 splice = newSplice(index, [], 0); | |
2741 splice.addedCount++; | |
2742 index++; | |
2743 break; | |
2744 case EDIT_DELETE: | |
2745 if (!splice) | |
2746 splice = newSplice(index, [], 0); | |
2747 splice.removed.push(old[oldIndex]); | |
2748 oldIndex++; | |
2749 break; | |
2750 } | |
2751 } | |
2752 if (splice) { | |
2753 splices.push(splice); | |
2754 } | |
2755 return splices; | |
2756 }, | |
2757 sharedPrefix: function (current, old, searchLength) { | |
2758 for (var i = 0; i < searchLength; i++) | |
2759 if (!this.equals(current[i], old[i])) | |
2760 return i; | |
2761 return searchLength; | |
2762 }, | |
2763 sharedSuffix: function (current, old, searchLength) { | |
2764 var index1 = current.length; | |
2765 var index2 = old.length; | |
2766 var count = 0; | |
2767 while (count < searchLength && this.equals(current[--index1], old[--index2])) | |
2768 count++; | |
2769 return count; | |
2770 }, | |
2771 calculateSplices: function (current, previous) { | |
2772 return this.calcSplices(current, 0, current.length, previous, 0, previous.length
); | |
2773 }, | |
2774 equals: function (currentValue, previousValue) { | |
2775 return currentValue === previousValue; | |
2776 } | |
2777 }; | |
2778 return new ArraySplice(); | |
2779 }(); | |
2780 Polymer.domInnerHTML = function () { | |
2781 var escapeAttrRegExp = /[&\u00A0"]/g; | |
2782 var escapeDataRegExp = /[&\u00A0<>]/g; | |
2783 function escapeReplace(c) { | |
2784 switch (c) { | |
2785 case '&': | |
2786 return '&'; | |
2787 case '<': | |
2788 return '<'; | |
2789 case '>': | |
2790 return '>'; | |
2791 case '"': | |
2792 return '"'; | |
2793 case '\xA0': | |
2794 return ' '; | |
2795 } | |
2796 } | |
2797 function escapeAttr(s) { | |
2798 return s.replace(escapeAttrRegExp, escapeReplace); | |
2799 } | |
2800 function escapeData(s) { | |
2801 return s.replace(escapeDataRegExp, escapeReplace); | |
2802 } | |
2803 function makeSet(arr) { | |
2804 var set = {}; | |
2805 for (var i = 0; i < arr.length; i++) { | |
2806 set[arr[i]] = true; | |
2807 } | |
2808 return set; | |
2809 } | |
2810 var voidElements = makeSet([ | |
2811 'area', | |
2812 'base', | |
2813 'br', | |
2814 'col', | |
2815 'command', | |
2816 'embed', | |
2817 'hr', | |
2818 'img', | |
2819 'input', | |
2820 'keygen', | |
2821 'link', | |
2822 'meta', | |
2823 'param', | |
2824 'source', | |
2825 'track', | |
2826 'wbr' | |
2827 ]); | |
2828 var plaintextParents = makeSet([ | |
2829 'style', | |
2830 'script', | |
2831 'xmp', | |
2832 'iframe', | |
2833 'noembed', | |
2834 'noframes', | |
2835 'plaintext', | |
2836 'noscript' | |
2837 ]); | |
2838 function getOuterHTML(node, parentNode, composed) { | |
2839 switch (node.nodeType) { | |
2840 case Node.ELEMENT_NODE: | |
2841 var tagName = node.localName; | |
2842 var s = '<' + tagName; | |
2843 var attrs = node.attributes; | |
2844 for (var i = 0, attr; attr = attrs[i]; i++) { | |
2845 s += ' ' + attr.name + '="' + escapeAttr(attr.value) + '"'; | |
2846 } | |
2847 s += '>'; | |
2848 if (voidElements[tagName]) { | |
2849 return s; | |
2850 } | |
2851 return s + getInnerHTML(node, composed) + '</' + tagName + '>'; | |
2852 case Node.TEXT_NODE: | |
2853 var data = node.data; | |
2854 if (parentNode && plaintextParents[parentNode.localName]) { | |
2855 return data; | |
2856 } | |
2857 return escapeData(data); | |
2858 case Node.COMMENT_NODE: | |
2859 return '<!--' + node.data + '-->'; | |
2860 default: | |
2861 console.error(node); | |
2862 throw new Error('not implemented'); | |
2863 } | |
2864 } | |
2865 function getInnerHTML(node, composed) { | |
2866 if (node instanceof HTMLTemplateElement) | |
2867 node = node.content; | |
2868 var s = ''; | |
2869 var c$ = Polymer.dom(node).childNodes; | |
2870 c$ = composed ? node._composedChildren : c$; | |
2871 for (var i = 0, l = c$.length, child; i < l && (child = c$[i]); i++) { | |
2872 s += getOuterHTML(child, node, composed); | |
2873 } | |
2874 return s; | |
2875 } | |
2876 return { getInnerHTML: getInnerHTML }; | |
2877 }(); | |
2878 Polymer.DomApi = function () { | |
2879 'use strict'; | |
2880 var Settings = Polymer.Settings; | |
2881 var getInnerHTML = Polymer.domInnerHTML.getInnerHTML; | |
2882 var nativeInsertBefore = Element.prototype.insertBefore; | |
2883 var nativeRemoveChild = Element.prototype.removeChild; | |
2884 var nativeAppendChild = Element.prototype.appendChild; | |
2885 var nativeCloneNode = Element.prototype.cloneNode; | |
2886 var nativeImportNode = Document.prototype.importNode; | |
2887 var needsToWrap = Settings.hasShadow && !Settings.nativeShadow; | |
2888 var wrap = window.wrap ? window.wrap : function (node) { | |
2889 return node; | |
2890 }; | |
2891 var DomApi = function (node) { | |
2892 this.node = needsToWrap ? wrap(node) : node; | |
2893 if (this.patch) { | |
2894 this.patch(); | |
2895 } | |
2896 }; | |
2897 DomApi.prototype = { | |
2898 flush: function () { | |
2899 Polymer.dom.flush(); | |
2900 }, | |
2901 deepContains: function (node) { | |
2902 if (this.node.contains(node)) { | |
2903 return true; | |
2904 } | |
2905 var n = node; | |
2906 var wrappedDocument = wrap(document); | |
2907 while (n && n !== wrappedDocument && n !== this.node) { | |
2908 n = Polymer.dom(n).parentNode || n.host; | |
2909 } | |
2910 return n === this.node; | |
2911 }, | |
2912 _lazyDistribute: function (host) { | |
2913 if (host.shadyRoot && host.shadyRoot._distributionClean) { | |
2914 host.shadyRoot._distributionClean = false; | |
2915 Polymer.dom.addDebouncer(host.debounce('_distribute', host._distributeContent)); | |
2916 } | |
2917 }, | |
2918 appendChild: function (node) { | |
2919 return this._addNode(node); | |
2920 }, | |
2921 insertBefore: function (node, ref_node) { | |
2922 return this._addNode(node, ref_node); | |
2923 }, | |
2924 _addNode: function (node, ref_node) { | |
2925 this._removeNodeFromParent(node); | |
2926 var addedInsertionPoint; | |
2927 var root = this.getOwnerRoot(); | |
2928 if (root) { | |
2929 addedInsertionPoint = this._maybeAddInsertionPoint(node, this.node); | |
2930 } | |
2931 if (this._nodeHasLogicalChildren(this.node)) { | |
2932 if (ref_node) { | |
2933 var children = this.childNodes; | |
2934 var index = children.indexOf(ref_node); | |
2935 if (index < 0) { | |
2936 throw Error('The ref_node to be inserted before is not a child ' + 'of this node
'); | |
2937 } | |
2938 } | |
2939 this._addLogicalInfo(node, this.node, index); | |
2940 } | |
2941 this._addNodeToHost(node); | |
2942 if (!this._maybeDistribute(node, this.node) && !this._tryRemoveUndistributedNode
(node)) { | |
2943 if (ref_node) { | |
2944 ref_node = ref_node.localName === CONTENT ? this._firstComposedNode(ref_node) :
ref_node; | |
2945 } | |
2946 var container = this.node._isShadyRoot ? this.node.host : this.node; | |
2947 addToComposedParent(container, node, ref_node); | |
2948 if (ref_node) { | |
2949 nativeInsertBefore.call(container, node, ref_node); | |
2950 } else { | |
2951 nativeAppendChild.call(container, node); | |
2952 } | |
2953 } | |
2954 if (addedInsertionPoint) { | |
2955 this._updateInsertionPoints(root.host); | |
2956 } | |
2957 this.notifyObserver(); | |
2958 return node; | |
2959 }, | |
2960 removeChild: function (node) { | |
2961 if (factory(node).parentNode !== this.node) { | |
2962 console.warn('The node to be removed is not a child of this node', node); | |
2963 } | |
2964 this._removeNodeFromHost(node); | |
2965 if (!this._maybeDistribute(node, this.node)) { | |
2966 var container = this.node._isShadyRoot ? this.node.host : this.node; | |
2967 if (container === node.parentNode) { | |
2968 removeFromComposedParent(container, node); | |
2969 nativeRemoveChild.call(container, node); | |
2970 } | |
2971 } | |
2972 this.notifyObserver(); | |
2973 return node; | |
2974 }, | |
2975 replaceChild: function (node, ref_node) { | |
2976 this.insertBefore(node, ref_node); | |
2977 this.removeChild(ref_node); | |
2978 return node; | |
2979 }, | |
2980 _hasCachedOwnerRoot: function (node) { | |
2981 return Boolean(node._ownerShadyRoot !== undefined); | |
2982 }, | |
2983 getOwnerRoot: function () { | |
2984 return this._ownerShadyRootForNode(this.node); | |
2985 }, | |
2986 _ownerShadyRootForNode: function (node) { | |
2987 if (!node) { | |
2988 return; | |
2989 } | |
2990 if (node._ownerShadyRoot === undefined) { | |
2991 var root; | |
2992 if (node._isShadyRoot) { | |
2993 root = node; | |
2994 } else { | |
2995 var parent = Polymer.dom(node).parentNode; | |
2996 if (parent) { | |
2997 root = parent._isShadyRoot ? parent : this._ownerShadyRootForNode(parent); | |
2998 } else { | |
2999 root = null; | |
3000 } | |
3001 } | |
3002 node._ownerShadyRoot = root; | |
3003 } | |
3004 return node._ownerShadyRoot; | |
3005 }, | |
3006 _maybeDistribute: function (node, parent) { | |
3007 var fragContent = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && !node.__noCon
tent && Polymer.dom(node).querySelector(CONTENT); | |
3008 var wrappedContent = fragContent && Polymer.dom(fragContent).parentNode.nodeType
!== Node.DOCUMENT_FRAGMENT_NODE; | |
3009 var hasContent = fragContent || node.localName === CONTENT; | |
3010 if (hasContent) { | |
3011 var root = this._ownerShadyRootForNode(parent); | |
3012 if (root) { | |
3013 var host = root.host; | |
3014 this._lazyDistribute(host); | |
3015 } | |
3016 } | |
3017 var parentNeedsDist = this._parentNeedsDistribution(parent); | |
3018 if (parentNeedsDist) { | |
3019 this._lazyDistribute(parent); | |
3020 } | |
3021 return parentNeedsDist || hasContent && !wrappedContent; | |
3022 }, | |
3023 _maybeAddInsertionPoint: function (node, parent) { | |
3024 var added; | |
3025 if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && !node.__noContent) { | |
3026 var c$ = factory(node).querySelectorAll(CONTENT); | |
3027 for (var i = 0, n, np, na; i < c$.length && (n = c$[i]); i++) { | |
3028 np = factory(n).parentNode; | |
3029 if (np === node) { | |
3030 np = parent; | |
3031 } | |
3032 na = this._maybeAddInsertionPoint(n, np); | |
3033 added = added || na; | |
3034 } | |
3035 } else if (node.localName === CONTENT) { | |
3036 saveLightChildrenIfNeeded(parent); | |
3037 saveLightChildrenIfNeeded(node); | |
3038 added = true; | |
3039 } | |
3040 return added; | |
3041 }, | |
3042 _tryRemoveUndistributedNode: function (node) { | |
3043 if (this.node.shadyRoot) { | |
3044 var parent = getComposedParent(node); | |
3045 if (parent) { | |
3046 nativeRemoveChild.call(parent, node); | |
3047 } | |
3048 return true; | |
3049 } | |
3050 }, | |
3051 _updateInsertionPoints: function (host) { | |
3052 var i$ = host.shadyRoot._insertionPoints = factory(host.shadyRoot).querySelector
All(CONTENT); | |
3053 for (var i = 0, c; i < i$.length; i++) { | |
3054 c = i$[i]; | |
3055 saveLightChildrenIfNeeded(c); | |
3056 saveLightChildrenIfNeeded(factory(c).parentNode); | |
3057 } | |
3058 }, | |
3059 _nodeHasLogicalChildren: function (node) { | |
3060 return Boolean(node._lightChildren !== undefined); | |
3061 }, | |
3062 _parentNeedsDistribution: function (parent) { | |
3063 return parent && parent.shadyRoot && hasInsertionPoint(parent.shadyRoot); | |
3064 }, | |
3065 _removeNodeFromParent: function (node) { | |
3066 var parent = node._lightParent || node.parentNode; | |
3067 if (parent && hasDomApi(parent)) { | |
3068 factory(parent).notifyObserver(); | |
3069 } | |
3070 this._removeNodeFromHost(node, true); | |
3071 }, | |
3072 _removeNodeFromHost: function (node, ensureComposedRemoval) { | |
3073 var hostNeedsDist; | |
3074 var root; | |
3075 var parent = node._lightParent; | |
3076 if (parent) { | |
3077 factory(node)._distributeParent(); | |
3078 root = this._ownerShadyRootForNode(node); | |
3079 if (root) { | |
3080 root.host._elementRemove(node); | |
3081 hostNeedsDist = this._removeDistributedChildren(root, node); | |
3082 } | |
3083 this._removeLogicalInfo(node, parent); | |
3084 } | |
3085 this._removeOwnerShadyRoot(node); | |
3086 if (root && hostNeedsDist) { | |
3087 this._updateInsertionPoints(root.host); | |
3088 this._lazyDistribute(root.host); | |
3089 } else if (ensureComposedRemoval) { | |
3090 removeFromComposedParent(getComposedParent(node), node); | |
3091 } | |
3092 }, | |
3093 _removeDistributedChildren: function (root, container) { | |
3094 var hostNeedsDist; | |
3095 var ip$ = root._insertionPoints; | |
3096 for (var i = 0; i < ip$.length; i++) { | |
3097 var content = ip$[i]; | |
3098 if (this._contains(container, content)) { | |
3099 var dc$ = factory(content).getDistributedNodes(); | |
3100 for (var j = 0; j < dc$.length; j++) { | |
3101 hostNeedsDist = true; | |
3102 var node = dc$[j]; | |
3103 var parent = node.parentNode; | |
3104 if (parent) { | |
3105 removeFromComposedParent(parent, node); | |
3106 nativeRemoveChild.call(parent, node); | |
3107 } | |
3108 } | |
3109 } | |
3110 } | |
3111 return hostNeedsDist; | |
3112 }, | |
3113 _contains: function (container, node) { | |
3114 while (node) { | |
3115 if (node == container) { | |
3116 return true; | |
3117 } | |
3118 node = factory(node).parentNode; | |
3119 } | |
3120 }, | |
3121 _addNodeToHost: function (node) { | |
3122 var root = this.getOwnerRoot(); | |
3123 if (root) { | |
3124 root.host._elementAdd(node); | |
3125 } | |
3126 }, | |
3127 _addLogicalInfo: function (node, container, index) { | |
3128 var children = factory(container).childNodes; | |
3129 index = index === undefined ? children.length : index; | |
3130 if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { | |
3131 var c$ = arrayCopyChildNodes(node); | |
3132 for (var i = 0, n; i < c$.length && (n = c$[i]); i++) { | |
3133 children.splice(index++, 0, n); | |
3134 n._lightParent = container; | |
3135 } | |
3136 } else { | |
3137 children.splice(index, 0, node); | |
3138 node._lightParent = container; | |
3139 } | |
3140 }, | |
3141 _removeLogicalInfo: function (node, container) { | |
3142 var children = factory(container).childNodes; | |
3143 var index = children.indexOf(node); | |
3144 if (index < 0 || container !== node._lightParent) { | |
3145 throw Error('The node to be removed is not a child of this node'); | |
3146 } | |
3147 children.splice(index, 1); | |
3148 node._lightParent = null; | |
3149 }, | |
3150 _removeOwnerShadyRoot: function (node) { | |
3151 if (this._hasCachedOwnerRoot(node)) { | |
3152 var c$ = factory(node).childNodes; | |
3153 for (var i = 0, l = c$.length, n; i < l && (n = c$[i]); i++) { | |
3154 this._removeOwnerShadyRoot(n); | |
3155 } | |
3156 } | |
3157 node._ownerShadyRoot = undefined; | |
3158 }, | |
3159 _firstComposedNode: function (content) { | |
3160 var n$ = factory(content).getDistributedNodes(); | |
3161 for (var i = 0, l = n$.length, n, p$; i < l && (n = n$[i]); i++) { | |
3162 p$ = factory(n).getDestinationInsertionPoints(); | |
3163 if (p$[p$.length - 1] === content) { | |
3164 return n; | |
3165 } | |
3166 } | |
3167 }, | |
3168 querySelector: function (selector) { | |
3169 return this.querySelectorAll(selector)[0]; | |
3170 }, | |
3171 querySelectorAll: function (selector) { | |
3172 return this._query(function (n) { | |
3173 return matchesSelector.call(n, selector); | |
3174 }, this.node); | |
3175 }, | |
3176 _query: function (matcher, node) { | |
3177 node = node || this.node; | |
3178 var list = []; | |
3179 this._queryElements(factory(node).childNodes, matcher, list); | |
3180 return list; | |
3181 }, | |
3182 _queryElements: function (elements, matcher, list) { | |
3183 for (var i = 0, l = elements.length, c; i < l && (c = elements[i]); i++) { | |
3184 if (c.nodeType === Node.ELEMENT_NODE) { | |
3185 this._queryElement(c, matcher, list); | |
3186 } | |
3187 } | |
3188 }, | |
3189 _queryElement: function (node, matcher, list) { | |
3190 if (matcher(node)) { | |
3191 list.push(node); | |
3192 } | |
3193 this._queryElements(factory(node).childNodes, matcher, list); | |
3194 }, | |
3195 getDestinationInsertionPoints: function () { | |
3196 return this.node._destinationInsertionPoints || []; | |
3197 }, | |
3198 getDistributedNodes: function () { | |
3199 return this.node._distributedNodes || []; | |
3200 }, | |
3201 queryDistributedElements: function (selector) { | |
3202 var c$ = this.getEffectiveChildNodes(); | |
3203 var list = []; | |
3204 for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { | |
3205 if (c.nodeType === Node.ELEMENT_NODE && matchesSelector.call(c, selector)) { | |
3206 list.push(c); | |
3207 } | |
3208 } | |
3209 return list; | |
3210 }, | |
3211 getEffectiveChildNodes: function () { | |
3212 var list = []; | |
3213 var c$ = this.childNodes; | |
3214 for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { | |
3215 if (c.localName === CONTENT) { | |
3216 var d$ = factory(c).getDistributedNodes(); | |
3217 for (var j = 0; j < d$.length; j++) { | |
3218 list.push(d$[j]); | |
3219 } | |
3220 } else { | |
3221 list.push(c); | |
3222 } | |
3223 } | |
3224 return list; | |
3225 }, | |
3226 _clear: function () { | |
3227 while (this.childNodes.length) { | |
3228 this.removeChild(this.childNodes[0]); | |
3229 } | |
3230 }, | |
3231 setAttribute: function (name, value) { | |
3232 this.node.setAttribute(name, value); | |
3233 this._distributeParent(); | |
3234 }, | |
3235 removeAttribute: function (name) { | |
3236 this.node.removeAttribute(name); | |
3237 this._distributeParent(); | |
3238 }, | |
3239 _distributeParent: function () { | |
3240 if (this._parentNeedsDistribution(this.parentNode)) { | |
3241 this._lazyDistribute(this.parentNode); | |
3242 } | |
3243 }, | |
3244 cloneNode: function (deep) { | |
3245 var n = nativeCloneNode.call(this.node, false); | |
3246 if (deep) { | |
3247 var c$ = this.childNodes; | |
3248 var d = factory(n); | |
3249 for (var i = 0, nc; i < c$.length; i++) { | |
3250 nc = factory(c$[i]).cloneNode(true); | |
3251 d.appendChild(nc); | |
3252 } | |
3253 } | |
3254 return n; | |
3255 }, | |
3256 importNode: function (externalNode, deep) { | |
3257 var doc = this.node instanceof Document ? this.node : this.node.ownerDocument; | |
3258 var n = nativeImportNode.call(doc, externalNode, false); | |
3259 if (deep) { | |
3260 var c$ = factory(externalNode).childNodes; | |
3261 var d = factory(n); | |
3262 for (var i = 0, nc; i < c$.length; i++) { | |
3263 nc = factory(doc).importNode(c$[i], true); | |
3264 d.appendChild(nc); | |
3265 } | |
3266 } | |
3267 return n; | |
3268 }, | |
3269 observeNodes: function (callback) { | |
3270 if (callback) { | |
3271 if (!this.observer) { | |
3272 this.observer = this.node.localName === CONTENT ? new DomApi.DistributedNodesObs
erver(this) : new DomApi.EffectiveNodesObserver(this); | |
3273 } | |
3274 return this.observer.addListener(callback); | |
3275 } | |
3276 }, | |
3277 unobserveNodes: function (handle) { | |
3278 if (this.observer) { | |
3279 this.observer.removeListener(handle); | |
3280 } | |
3281 }, | |
3282 notifyObserver: function () { | |
3283 if (this.observer) { | |
3284 this.observer.notify(); | |
3285 } | |
3286 } | |
3287 }; | |
3288 if (!Settings.useShadow) { | |
3289 Object.defineProperties(DomApi.prototype, { | |
3290 childNodes: { | |
3291 get: function () { | |
3292 var c$ = getLightChildren(this.node); | |
3293 return Array.isArray(c$) ? c$ : arrayCopyChildNodes(this.node); | |
3294 }, | |
3295 configurable: true | |
3296 }, | |
3297 children: { | |
3298 get: function () { | |
3299 return Array.prototype.filter.call(this.childNodes, function (n) { | |
3300 return n.nodeType === Node.ELEMENT_NODE; | |
3301 }); | |
3302 }, | |
3303 configurable: true | |
3304 }, | |
3305 parentNode: { | |
3306 get: function () { | |
3307 return this.node._lightParent || getComposedParent(this.node); | |
3308 }, | |
3309 configurable: true | |
3310 }, | |
3311 firstChild: { | |
3312 get: function () { | |
3313 return this.childNodes[0]; | |
3314 }, | |
3315 configurable: true | |
3316 }, | |
3317 lastChild: { | |
3318 get: function () { | |
3319 var c$ = this.childNodes; | |
3320 return c$[c$.length - 1]; | |
3321 }, | |
3322 configurable: true | |
3323 }, | |
3324 nextSibling: { | |
3325 get: function () { | |
3326 var c$ = this.parentNode && factory(this.parentNode).childNodes; | |
3327 if (c$) { | |
3328 return c$[Array.prototype.indexOf.call(c$, this.node) + 1]; | |
3329 } | |
3330 }, | |
3331 configurable: true | |
3332 }, | |
3333 previousSibling: { | |
3334 get: function () { | |
3335 var c$ = this.parentNode && factory(this.parentNode).childNodes; | |
3336 if (c$) { | |
3337 return c$[Array.prototype.indexOf.call(c$, this.node) - 1]; | |
3338 } | |
3339 }, | |
3340 configurable: true | |
3341 }, | |
3342 firstElementChild: { | |
3343 get: function () { | |
3344 return this.children[0]; | |
3345 }, | |
3346 configurable: true | |
3347 }, | |
3348 lastElementChild: { | |
3349 get: function () { | |
3350 var c$ = this.children; | |
3351 return c$[c$.length - 1]; | |
3352 }, | |
3353 configurable: true | |
3354 }, | |
3355 nextElementSibling: { | |
3356 get: function () { | |
3357 var c$ = this.parentNode && factory(this.parentNode).children; | |
3358 if (c$) { | |
3359 return c$[Array.prototype.indexOf.call(c$, this.node) + 1]; | |
3360 } | |
3361 }, | |
3362 configurable: true | |
3363 }, | |
3364 previousElementSibling: { | |
3365 get: function () { | |
3366 var c$ = this.parentNode && factory(this.parentNode).children; | |
3367 if (c$) { | |
3368 return c$[Array.prototype.indexOf.call(c$, this.node) - 1]; | |
3369 } | |
3370 }, | |
3371 configurable: true | |
3372 }, | |
3373 textContent: { | |
3374 get: function () { | |
3375 var nt = this.node.nodeType; | |
3376 if (nt === Node.TEXT_NODE || nt === Node.COMMENT_NODE) { | |
3377 return this.node.textContent; | |
3378 } else { | |
3379 var tc = []; | |
3380 for (var i = 0, cn = this.childNodes, c; c = cn[i]; i++) { | |
3381 if (c.nodeType !== Node.COMMENT_NODE) { | |
3382 tc.push(c.textContent); | |
3383 } | |
3384 } | |
3385 return tc.join(''); | |
3386 } | |
3387 }, | |
3388 set: function (text) { | |
3389 var nt = this.node.nodeType; | |
3390 if (nt === Node.TEXT_NODE || nt === Node.COMMENT_NODE) { | |
3391 this.node.textContent = text; | |
3392 } else { | |
3393 this._clear(); | |
3394 if (text) { | |
3395 this.appendChild(document.createTextNode(text)); | |
3396 } | |
3397 } | |
3398 }, | |
3399 configurable: true | |
3400 }, | |
3401 innerHTML: { | |
3402 get: function () { | |
3403 var nt = this.node.nodeType; | |
3404 if (nt === Node.TEXT_NODE || nt === Node.COMMENT_NODE) { | |
3405 return null; | |
3406 } else { | |
3407 return getInnerHTML(this.node); | |
3408 } | |
3409 }, | |
3410 set: function (text) { | |
3411 var nt = this.node.nodeType; | |
3412 if (nt !== Node.TEXT_NODE || nt !== Node.COMMENT_NODE) { | |
3413 this._clear(); | |
3414 var d = document.createElement('div'); | |
3415 d.innerHTML = text; | |
3416 var c$ = arrayCopyChildNodes(d); | |
3417 for (var i = 0; i < c$.length; i++) { | |
3418 this.appendChild(c$[i]); | |
3419 } | |
3420 } | |
3421 }, | |
3422 configurable: true | |
3423 } | |
3424 }); | |
3425 DomApi.prototype._getComposedInnerHTML = function () { | |
3426 return getInnerHTML(this.node, true); | |
3427 }; | |
3428 } else { | |
3429 var forwardMethods = function (m$) { | |
3430 for (var i = 0; i < m$.length; i++) { | |
3431 forwardMethod(m$[i]); | |
3432 } | |
3433 }; | |
3434 var forwardMethod = function (method) { | |
3435 DomApi.prototype[method] = function () { | |
3436 return this.node[method].apply(this.node, arguments); | |
3437 }; | |
3438 }; | |
3439 forwardMethods([ | |
3440 'cloneNode', | |
3441 'appendChild', | |
3442 'insertBefore', | |
3443 'removeChild', | |
3444 'replaceChild' | |
3445 ]); | |
3446 DomApi.prototype.querySelectorAll = function (selector) { | |
3447 return arrayCopy(this.node.querySelectorAll(selector)); | |
3448 }; | |
3449 DomApi.prototype.getOwnerRoot = function () { | |
3450 var n = this.node; | |
3451 while (n) { | |
3452 if (n.nodeType === Node.DOCUMENT_FRAGMENT_NODE && n.host) { | |
3453 return n; | |
3454 } | |
3455 n = n.parentNode; | |
3456 } | |
3457 }; | |
3458 DomApi.prototype.importNode = function (externalNode, deep) { | |
3459 var doc = this.node instanceof Document ? this.node : this.node.ownerDocument; | |
3460 return doc.importNode(externalNode, deep); | |
3461 }; | |
3462 DomApi.prototype.getDestinationInsertionPoints = function () { | |
3463 var n$ = this.node.getDestinationInsertionPoints && this.node.getDestinationInse
rtionPoints(); | |
3464 return n$ ? arrayCopy(n$) : []; | |
3465 }; | |
3466 DomApi.prototype.getDistributedNodes = function () { | |
3467 var n$ = this.node.getDistributedNodes && this.node.getDistributedNodes(); | |
3468 return n$ ? arrayCopy(n$) : []; | |
3469 }; | |
3470 DomApi.prototype._distributeParent = function () { | |
3471 }; | |
3472 Object.defineProperties(DomApi.prototype, { | |
3473 childNodes: { | |
3474 get: function () { | |
3475 return arrayCopyChildNodes(this.node); | |
3476 }, | |
3477 configurable: true | |
3478 }, | |
3479 children: { | |
3480 get: function () { | |
3481 return arrayCopyChildren(this.node); | |
3482 }, | |
3483 configurable: true | |
3484 }, | |
3485 textContent: { | |
3486 get: function () { | |
3487 return this.node.textContent; | |
3488 }, | |
3489 set: function (value) { | |
3490 return this.node.textContent = value; | |
3491 }, | |
3492 configurable: true | |
3493 }, | |
3494 innerHTML: { | |
3495 get: function () { | |
3496 return this.node.innerHTML; | |
3497 }, | |
3498 set: function (value) { | |
3499 return this.node.innerHTML = value; | |
3500 }, | |
3501 configurable: true | |
3502 } | |
3503 }); | |
3504 var forwardProperties = function (f$) { | |
3505 for (var i = 0; i < f$.length; i++) { | |
3506 forwardProperty(f$[i]); | |
3507 } | |
3508 }; | |
3509 var forwardProperty = function (name) { | |
3510 Object.defineProperty(DomApi.prototype, name, { | |
3511 get: function () { | |
3512 return this.node[name]; | |
3513 }, | |
3514 configurable: true | |
3515 }); | |
3516 }; | |
3517 forwardProperties([ | |
3518 'parentNode', | |
3519 'firstChild', | |
3520 'lastChild', | |
3521 'nextSibling', | |
3522 'previousSibling', | |
3523 'firstElementChild', | |
3524 'lastElementChild', | |
3525 'nextElementSibling', | |
3526 'previousElementSibling' | |
3527 ]); | |
3528 } | |
3529 var CONTENT = 'content'; | |
3530 function factory(node, patch) { | |
3531 node = node || document; | |
3532 if (!node.__domApi) { | |
3533 node.__domApi = new DomApi(node, patch); | |
3534 } | |
3535 return node.__domApi; | |
3536 } | |
3537 ; | |
3538 function hasDomApi(node) { | |
3539 return Boolean(node.__domApi); | |
3540 } | |
3541 ; | |
3542 Polymer.dom = function (obj, patch) { | |
3543 if (obj instanceof Event) { | |
3544 return Polymer.EventApi.factory(obj); | |
3545 } else { | |
3546 return factory(obj, patch); | |
3547 } | |
3548 }; | |
3549 function getLightChildren(node) { | |
3550 var children = node._lightChildren; | |
3551 return children ? children : node.childNodes; | |
3552 } | |
3553 function getComposedChildren(node) { | |
3554 if (!node._composedChildren) { | |
3555 node._composedChildren = arrayCopyChildNodes(node); | |
3556 } | |
3557 return node._composedChildren; | |
3558 } | |
3559 function addToComposedParent(parent, node, ref_node) { | |
3560 var children = getComposedChildren(parent); | |
3561 var i = ref_node ? children.indexOf(ref_node) : -1; | |
3562 if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { | |
3563 var fragChildren = getComposedChildren(node); | |
3564 for (var j = 0; j < fragChildren.length; j++) { | |
3565 addNodeToComposedChildren(fragChildren[j], parent, children, i + j); | |
3566 } | |
3567 node._composedChildren = null; | |
3568 } else { | |
3569 addNodeToComposedChildren(node, parent, children, i); | |
3570 } | |
3571 } | |
3572 function getComposedParent(node) { | |
3573 return node.__patched ? node._composedParent : node.parentNode; | |
3574 } | |
3575 function addNodeToComposedChildren(node, parent, children, i) { | |
3576 node._composedParent = parent; | |
3577 children.splice(i >= 0 ? i : children.length, 0, node); | |
3578 } | |
3579 function removeFromComposedParent(parent, node) { | |
3580 node._composedParent = null; | |
3581 if (parent) { | |
3582 var children = getComposedChildren(parent); | |
3583 var i = children.indexOf(node); | |
3584 if (i >= 0) { | |
3585 children.splice(i, 1); | |
3586 } | |
3587 } | |
3588 } | |
3589 function saveLightChildrenIfNeeded(node) { | |
3590 if (!node._lightChildren) { | |
3591 var c$ = arrayCopyChildNodes(node); | |
3592 for (var i = 0, l = c$.length, child; i < l && (child = c$[i]); i++) { | |
3593 child._lightParent = child._lightParent || node; | |
3594 } | |
3595 node._lightChildren = c$; | |
3596 } | |
3597 } | |
3598 function arrayCopyChildNodes(parent) { | |
3599 var copy = [], i = 0; | |
3600 for (var n = parent.firstChild; n; n = n.nextSibling) { | |
3601 copy[i++] = n; | |
3602 } | |
3603 return copy; | |
3604 } | |
3605 function arrayCopyChildren(parent) { | |
3606 var copy = [], i = 0; | |
3607 for (var n = parent.firstElementChild; n; n = n.nextElementSibling) { | |
3608 copy[i++] = n; | |
3609 } | |
3610 return copy; | |
3611 } | |
3612 function arrayCopy(a$) { | |
3613 var l = a$.length; | |
3614 var copy = new Array(l); | |
3615 for (var i = 0; i < l; i++) { | |
3616 copy[i] = a$[i]; | |
3617 } | |
3618 return copy; | |
3619 } | |
3620 function hasInsertionPoint(root) { | |
3621 return Boolean(root && root._insertionPoints.length); | |
3622 } | |
3623 var p = Element.prototype; | |
3624 var matchesSelector = p.matches || p.matchesSelector || p.mozMatchesSelector ||
p.msMatchesSelector || p.oMatchesSelector || p.webkitMatchesSelector; | |
3625 return { | |
3626 getLightChildren: getLightChildren, | |
3627 getComposedParent: getComposedParent, | |
3628 getComposedChildren: getComposedChildren, | |
3629 removeFromComposedParent: removeFromComposedParent, | |
3630 saveLightChildrenIfNeeded: saveLightChildrenIfNeeded, | |
3631 matchesSelector: matchesSelector, | |
3632 hasInsertionPoint: hasInsertionPoint, | |
3633 ctor: DomApi, | |
3634 factory: factory, | |
3635 hasDomApi: hasDomApi, | |
3636 arrayCopy: arrayCopy, | |
3637 arrayCopyChildNodes: arrayCopyChildNodes, | |
3638 arrayCopyChildren: arrayCopyChildren, | |
3639 wrap: wrap | |
3640 }; | |
3641 }(); | |
3642 Polymer.Base.extend(Polymer.dom, { | |
3643 _flushGuard: 0, | |
3644 _FLUSH_MAX: 100, | |
3645 _needsTakeRecords: !Polymer.Settings.useNativeCustomElements, | |
3646 _debouncers: [], | |
3647 _staticFlushList: [], | |
3648 _finishDebouncer: null, | |
3649 flush: function () { | |
3650 this._flushGuard = 0; | |
3651 this._prepareFlush(); | |
3652 while (this._debouncers.length && this._flushGuard < this._FLUSH_MAX) { | |
3653 for (var i = 0; i < this._debouncers.length; i++) { | |
3654 this._debouncers[i].complete(); | |
3655 } | |
3656 if (this._finishDebouncer) { | |
3657 this._finishDebouncer.complete(); | |
3658 } | |
3659 this._prepareFlush(); | |
3660 this._flushGuard++; | |
3661 } | |
3662 if (this._flushGuard >= this._FLUSH_MAX) { | |
3663 console.warn('Polymer.dom.flush aborted. Flush may not be complete.'); | |
3664 } | |
3665 }, | |
3666 _prepareFlush: function () { | |
3667 if (this._needsTakeRecords) { | |
3668 CustomElements.takeRecords(); | |
3669 } | |
3670 for (var i = 0; i < this._staticFlushList.length; i++) { | |
3671 this._staticFlushList[i](); | |
3672 } | |
3673 }, | |
3674 addStaticFlush: function (fn) { | |
3675 this._staticFlushList.push(fn); | |
3676 }, | |
3677 removeStaticFlush: function (fn) { | |
3678 var i = this._staticFlushList.indexOf(fn); | |
3679 if (i >= 0) { | |
3680 this._staticFlushList.splice(i, 1); | |
3681 } | |
3682 }, | |
3683 addDebouncer: function (debouncer) { | |
3684 this._debouncers.push(debouncer); | |
3685 this._finishDebouncer = Polymer.Debounce(this._finishDebouncer, this._finishFlus
h); | |
3686 }, | |
3687 _finishFlush: function () { | |
3688 Polymer.dom._debouncers = []; | |
3689 } | |
3690 }); | |
3691 Polymer.EventApi = function () { | |
3692 'use strict'; | |
3693 var DomApi = Polymer.DomApi.ctor; | |
3694 var Settings = Polymer.Settings; | |
3695 DomApi.Event = function (event) { | |
3696 this.event = event; | |
3697 }; | |
3698 if (Settings.useShadow) { | |
3699 DomApi.Event.prototype = { | |
3700 get rootTarget() { | |
3701 return this.event.path[0]; | |
3702 }, | |
3703 get localTarget() { | |
3704 return this.event.target; | |
3705 }, | |
3706 get path() { | |
3707 return this.event.path; | |
3708 } | |
3709 }; | |
3710 } else { | |
3711 DomApi.Event.prototype = { | |
3712 get rootTarget() { | |
3713 return this.event.target; | |
3714 }, | |
3715 get localTarget() { | |
3716 var current = this.event.currentTarget; | |
3717 var currentRoot = current && Polymer.dom(current).getOwnerRoot(); | |
3718 var p$ = this.path; | |
3719 for (var i = 0; i < p$.length; i++) { | |
3720 if (Polymer.dom(p$[i]).getOwnerRoot() === currentRoot) { | |
3721 return p$[i]; | |
3722 } | |
3723 } | |
3724 }, | |
3725 get path() { | |
3726 if (!this.event._path) { | |
3727 var path = []; | |
3728 var o = this.rootTarget; | |
3729 while (o) { | |
3730 path.push(o); | |
3731 o = Polymer.dom(o).parentNode || o.host; | |
3732 } | |
3733 path.push(window); | |
3734 this.event._path = path; | |
3735 } | |
3736 return this.event._path; | |
3737 } | |
3738 }; | |
3739 } | |
3740 var factory = function (event) { | |
3741 if (!event.__eventApi) { | |
3742 event.__eventApi = new DomApi.Event(event); | |
3743 } | |
3744 return event.__eventApi; | |
3745 }; | |
3746 return { factory: factory }; | |
3747 }(); | |
3748 (function () { | |
3749 'use strict'; | |
3750 var DomApi = Polymer.DomApi.ctor; | |
3751 Object.defineProperty(DomApi.prototype, 'classList', { | |
3752 get: function () { | |
3753 if (!this._classList) { | |
3754 this._classList = new DomApi.ClassList(this); | |
3755 } | |
3756 return this._classList; | |
3757 }, | |
3758 configurable: true | |
3759 }); | |
3760 DomApi.ClassList = function (host) { | |
3761 this.domApi = host; | |
3762 this.node = host.node; | |
3763 }; | |
3764 DomApi.ClassList.prototype = { | |
3765 add: function () { | |
3766 this.node.classList.add.apply(this.node.classList, arguments); | |
3767 this.domApi._distributeParent(); | |
3768 }, | |
3769 remove: function () { | |
3770 this.node.classList.remove.apply(this.node.classList, arguments); | |
3771 this.domApi._distributeParent(); | |
3772 }, | |
3773 toggle: function () { | |
3774 this.node.classList.toggle.apply(this.node.classList, arguments); | |
3775 this.domApi._distributeParent(); | |
3776 }, | |
3777 contains: function () { | |
3778 return this.node.classList.contains.apply(this.node.classList, arguments); | |
3779 } | |
3780 }; | |
3781 }()); | |
3782 (function () { | |
3783 'use strict'; | |
3784 var DomApi = Polymer.DomApi.ctor; | |
3785 var Settings = Polymer.Settings; | |
3786 var hasDomApi = Polymer.DomApi.hasDomApi; | |
3787 DomApi.EffectiveNodesObserver = function (domApi) { | |
3788 this.domApi = domApi; | |
3789 this.node = this.domApi.node; | |
3790 this._listeners = []; | |
3791 }; | |
3792 DomApi.EffectiveNodesObserver.prototype = { | |
3793 addListener: function (callback) { | |
3794 if (!this._isSetup) { | |
3795 this._setup(); | |
3796 this._isSetup = true; | |
3797 } | |
3798 var listener = { | |
3799 fn: callback, | |
3800 _nodes: [] | |
3801 }; | |
3802 this._listeners.push(listener); | |
3803 this._scheduleNotify(); | |
3804 return listener; | |
3805 }, | |
3806 removeListener: function (handle) { | |
3807 var i = this._listeners.indexOf(handle); | |
3808 if (i >= 0) { | |
3809 this._listeners.splice(i, 1); | |
3810 handle._nodes = []; | |
3811 } | |
3812 if (!this._hasListeners()) { | |
3813 this._cleanup(); | |
3814 this._isSetup = false; | |
3815 } | |
3816 }, | |
3817 _setup: function () { | |
3818 this._observeContentElements(this.domApi.childNodes); | |
3819 }, | |
3820 _cleanup: function () { | |
3821 this._unobserveContentElements(this.domApi.childNodes); | |
3822 }, | |
3823 _hasListeners: function () { | |
3824 return Boolean(this._listeners.length); | |
3825 }, | |
3826 _scheduleNotify: function () { | |
3827 if (this._debouncer) { | |
3828 this._debouncer.stop(); | |
3829 } | |
3830 this._debouncer = Polymer.Debounce(this._debouncer, this._notify); | |
3831 this._debouncer.context = this; | |
3832 Polymer.dom.addDebouncer(this._debouncer); | |
3833 }, | |
3834 notify: function () { | |
3835 if (this._hasListeners()) { | |
3836 this._scheduleNotify(); | |
3837 } | |
3838 }, | |
3839 _notify: function (mxns) { | |
3840 this._beforeCallListeners(); | |
3841 this._callListeners(); | |
3842 }, | |
3843 _beforeCallListeners: function () { | |
3844 this._updateContentElements(); | |
3845 }, | |
3846 _updateContentElements: function () { | |
3847 this._observeContentElements(this.domApi.childNodes); | |
3848 }, | |
3849 _observeContentElements: function (elements) { | |
3850 for (var i = 0, n; i < elements.length && (n = elements[i]); i++) { | |
3851 if (this._isContent(n)) { | |
3852 n.__observeNodesMap = n.__observeNodesMap || new WeakMap(); | |
3853 if (!n.__observeNodesMap.has(this)) { | |
3854 n.__observeNodesMap.set(this, this._observeContent(n)); | |
3855 } | |
3856 } | |
3857 } | |
3858 }, | |
3859 _observeContent: function (content) { | |
3860 var self = this; | |
3861 var h = Polymer.dom(content).observeNodes(function () { | |
3862 self._scheduleNotify(); | |
3863 }); | |
3864 h._avoidChangeCalculation = true; | |
3865 return h; | |
3866 }, | |
3867 _unobserveContentElements: function (elements) { | |
3868 for (var i = 0, n, h; i < elements.length && (n = elements[i]); i++) { | |
3869 if (this._isContent(n)) { | |
3870 h = n.__observeNodesMap.get(this); | |
3871 if (h) { | |
3872 Polymer.dom(n).unobserveNodes(h); | |
3873 n.__observeNodesMap.delete(this); | |
3874 } | |
3875 } | |
3876 } | |
3877 }, | |
3878 _isContent: function (node) { | |
3879 return node.localName === 'content'; | |
3880 }, | |
3881 _callListeners: function () { | |
3882 var o$ = this._listeners; | |
3883 var nodes = this._getEffectiveNodes(); | |
3884 for (var i = 0, o; i < o$.length && (o = o$[i]); i++) { | |
3885 var info = this._generateListenerInfo(o, nodes); | |
3886 if (info || o._alwaysNotify) { | |
3887 this._callListener(o, info); | |
3888 } | |
3889 } | |
3890 }, | |
3891 _getEffectiveNodes: function () { | |
3892 return this.domApi.getEffectiveChildNodes(); | |
3893 }, | |
3894 _generateListenerInfo: function (listener, newNodes) { | |
3895 if (listener._avoidChangeCalculation) { | |
3896 return true; | |
3897 } | |
3898 var oldNodes = listener._nodes; | |
3899 var info = { | |
3900 target: this.node, | |
3901 addedNodes: [], | |
3902 removedNodes: [] | |
3903 }; | |
3904 var splices = Polymer.ArraySplice.calculateSplices(newNodes, oldNodes); | |
3905 for (var i = 0, s; i < splices.length && (s = splices[i]); i++) { | |
3906 for (var j = 0, n; j < s.removed.length && (n = s.removed[j]); j++) { | |
3907 info.removedNodes.push(n); | |
3908 } | |
3909 } | |
3910 for (var i = 0, s; i < splices.length && (s = splices[i]); i++) { | |
3911 for (var j = s.index; j < s.index + s.addedCount; j++) { | |
3912 info.addedNodes.push(newNodes[j]); | |
3913 } | |
3914 } | |
3915 listener._nodes = newNodes; | |
3916 if (info.addedNodes.length || info.removedNodes.length) { | |
3917 return info; | |
3918 } | |
3919 }, | |
3920 _callListener: function (listener, info) { | |
3921 return listener.fn.call(this.node, info); | |
3922 }, | |
3923 enableShadowAttributeTracking: function () { | |
3924 } | |
3925 }; | |
3926 if (Settings.useShadow) { | |
3927 var baseSetup = DomApi.EffectiveNodesObserver.prototype._setup; | |
3928 var baseCleanup = DomApi.EffectiveNodesObserver.prototype._cleanup; | |
3929 var beforeCallListeners = DomApi.EffectiveNodesObserver.prototype._beforeCallLis
teners; | |
3930 Polymer.Base.extend(DomApi.EffectiveNodesObserver.prototype, { | |
3931 _setup: function () { | |
3932 if (!this._observer) { | |
3933 var self = this; | |
3934 this._mutationHandler = function (mxns) { | |
3935 if (mxns && mxns.length) { | |
3936 self._scheduleNotify(); | |
3937 } | |
3938 }; | |
3939 this._observer = new MutationObserver(this._mutationHandler); | |
3940 this._boundFlush = function () { | |
3941 self._flush(); | |
3942 }; | |
3943 Polymer.dom.addStaticFlush(this._boundFlush); | |
3944 this._observer.observe(this.node, { childList: true }); | |
3945 } | |
3946 baseSetup.call(this); | |
3947 }, | |
3948 _cleanup: function () { | |
3949 this._observer.disconnect(); | |
3950 this._observer = null; | |
3951 this._mutationHandler = null; | |
3952 Polymer.dom.removeStaticFlush(this._boundFlush); | |
3953 baseCleanup.call(this); | |
3954 }, | |
3955 _flush: function () { | |
3956 if (this._observer) { | |
3957 this._mutationHandler(this._observer.takeRecords()); | |
3958 } | |
3959 }, | |
3960 enableShadowAttributeTracking: function () { | |
3961 if (this._observer) { | |
3962 this._makeContentListenersAlwaysNotify(); | |
3963 this._observer.disconnect(); | |
3964 this._observer.observe(this.node, { | |
3965 childList: true, | |
3966 attributes: true, | |
3967 subtree: true | |
3968 }); | |
3969 var root = this.domApi.getOwnerRoot(); | |
3970 var host = root && root.host; | |
3971 if (host && Polymer.dom(host).observer) { | |
3972 Polymer.dom(host).observer.enableShadowAttributeTracking(); | |
3973 } | |
3974 } | |
3975 }, | |
3976 _makeContentListenersAlwaysNotify: function () { | |
3977 for (var i = 0, h; i < this._listeners.length; i++) { | |
3978 h = this._listeners[i]; | |
3979 h._alwaysNotify = h._isContentListener; | |
3980 } | |
3981 } | |
3982 }); | |
3983 } | |
3984 }()); | |
3985 (function () { | |
3986 'use strict'; | |
3987 var DomApi = Polymer.DomApi.ctor; | |
3988 var Settings = Polymer.Settings; | |
3989 DomApi.DistributedNodesObserver = function (domApi) { | |
3990 DomApi.EffectiveNodesObserver.call(this, domApi); | |
3991 }; | |
3992 DomApi.DistributedNodesObserver.prototype = Object.create(DomApi.EffectiveNodesO
bserver.prototype); | |
3993 Polymer.Base.extend(DomApi.DistributedNodesObserver.prototype, { | |
3994 _setup: function () { | |
3995 }, | |
3996 _cleanup: function () { | |
3997 }, | |
3998 _beforeCallListeners: function () { | |
3999 }, | |
4000 _getEffectiveNodes: function () { | |
4001 return this.domApi.getDistributedNodes(); | |
4002 } | |
4003 }); | |
4004 if (Settings.useShadow) { | |
4005 Polymer.Base.extend(DomApi.DistributedNodesObserver.prototype, { | |
4006 _setup: function () { | |
4007 if (!this._observer) { | |
4008 var root = this.domApi.getOwnerRoot(); | |
4009 var host = root && root.host; | |
4010 if (host) { | |
4011 var self = this; | |
4012 this._observer = Polymer.dom(host).observeNodes(function () { | |
4013 self._scheduleNotify(); | |
4014 }); | |
4015 this._observer._isContentListener = true; | |
4016 if (this._hasAttrSelect()) { | |
4017 Polymer.dom(host).observer.enableShadowAttributeTracking(); | |
4018 } | |
4019 } | |
4020 } | |
4021 }, | |
4022 _hasAttrSelect: function () { | |
4023 var select = this.node.getAttribute('select'); | |
4024 return select && select.match(/[[.]+/); | |
4025 }, | |
4026 _cleanup: function () { | |
4027 var root = this.domApi.getOwnerRoot(); | |
4028 var host = root && root.host; | |
4029 if (host) { | |
4030 Polymer.dom(host).unobserveNodes(this._observer); | |
4031 } | |
4032 this._observer = null; | |
4033 } | |
4034 }); | |
4035 } | |
4036 }()); | |
4037 (function () { | |
4038 var hasDomApi = Polymer.DomApi.hasDomApi; | |
4039 Polymer.Base._addFeature({ | |
4040 _prepShady: function () { | |
4041 this._useContent = this._useContent || Boolean(this._template); | |
4042 }, | |
4043 _poolContent: function () { | |
4044 if (this._useContent) { | |
4045 saveLightChildrenIfNeeded(this); | |
4046 } | |
4047 }, | |
4048 _setupRoot: function () { | |
4049 if (this._useContent) { | |
4050 this._createLocalRoot(); | |
4051 if (!this.dataHost) { | |
4052 upgradeLightChildren(this._lightChildren); | |
4053 } | |
4054 } | |
4055 }, | |
4056 _createLocalRoot: function () { | |
4057 this.shadyRoot = this.root; | |
4058 this.shadyRoot._distributionClean = false; | |
4059 this.shadyRoot._hasDistributed = false; | |
4060 this.shadyRoot._isShadyRoot = true; | |
4061 this.shadyRoot._dirtyRoots = []; | |
4062 var i$ = this.shadyRoot._insertionPoints = !this._notes || this._notes._hasConte
nt ? this.shadyRoot.querySelectorAll('content') : []; | |
4063 saveLightChildrenIfNeeded(this.shadyRoot); | |
4064 for (var i = 0, c; i < i$.length; i++) { | |
4065 c = i$[i]; | |
4066 saveLightChildrenIfNeeded(c); | |
4067 saveLightChildrenIfNeeded(c.parentNode); | |
4068 } | |
4069 this.shadyRoot.host = this; | |
4070 }, | |
4071 get domHost() { | |
4072 var root = Polymer.dom(this).getOwnerRoot(); | |
4073 return root && root.host; | |
4074 }, | |
4075 distributeContent: function (updateInsertionPoints) { | |
4076 if (this.shadyRoot) { | |
4077 var dom = Polymer.dom(this); | |
4078 if (updateInsertionPoints) { | |
4079 dom._updateInsertionPoints(this); | |
4080 } | |
4081 var host = getTopDistributingHost(this); | |
4082 dom._lazyDistribute(host); | |
4083 } | |
4084 }, | |
4085 _distributeContent: function () { | |
4086 if (this._useContent && !this.shadyRoot._distributionClean) { | |
4087 this._beginDistribute(); | |
4088 this._distributeDirtyRoots(); | |
4089 this._finishDistribute(); | |
4090 } | |
4091 }, | |
4092 _beginDistribute: function () { | |
4093 if (this._useContent && hasInsertionPoint(this.shadyRoot)) { | |
4094 this._resetDistribution(); | |
4095 this._distributePool(this.shadyRoot, this._collectPool()); | |
4096 } | |
4097 }, | |
4098 _distributeDirtyRoots: function () { | |
4099 var c$ = this.shadyRoot._dirtyRoots; | |
4100 for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { | |
4101 c._distributeContent(); | |
4102 } | |
4103 this.shadyRoot._dirtyRoots = []; | |
4104 }, | |
4105 _finishDistribute: function () { | |
4106 if (this._useContent) { | |
4107 this.shadyRoot._distributionClean = true; | |
4108 if (hasInsertionPoint(this.shadyRoot)) { | |
4109 this._composeTree(); | |
4110 notifyContentObservers(this.shadyRoot); | |
4111 } else { | |
4112 if (!this.shadyRoot._hasDistributed) { | |
4113 this.textContent = ''; | |
4114 this._composedChildren = null; | |
4115 this.appendChild(this.shadyRoot); | |
4116 } else { | |
4117 var children = this._composeNode(this); | |
4118 this._updateChildNodes(this, children); | |
4119 } | |
4120 } | |
4121 if (!this.shadyRoot._hasDistributed) { | |
4122 notifyInitialDistribution(this); | |
4123 } | |
4124 this.shadyRoot._hasDistributed = true; | |
4125 } | |
4126 }, | |
4127 elementMatches: function (selector, node) { | |
4128 node = node || this; | |
4129 return matchesSelector.call(node, selector); | |
4130 }, | |
4131 _resetDistribution: function () { | |
4132 var children = getLightChildren(this); | |
4133 for (var i = 0; i < children.length; i++) { | |
4134 var child = children[i]; | |
4135 if (child._destinationInsertionPoints) { | |
4136 child._destinationInsertionPoints = undefined; | |
4137 } | |
4138 if (isInsertionPoint(child)) { | |
4139 clearDistributedDestinationInsertionPoints(child); | |
4140 } | |
4141 } | |
4142 var root = this.shadyRoot; | |
4143 var p$ = root._insertionPoints; | |
4144 for (var j = 0; j < p$.length; j++) { | |
4145 p$[j]._distributedNodes = []; | |
4146 } | |
4147 }, | |
4148 _collectPool: function () { | |
4149 var pool = []; | |
4150 var children = getLightChildren(this); | |
4151 for (var i = 0; i < children.length; i++) { | |
4152 var child = children[i]; | |
4153 if (isInsertionPoint(child)) { | |
4154 pool.push.apply(pool, child._distributedNodes); | |
4155 } else { | |
4156 pool.push(child); | |
4157 } | |
4158 } | |
4159 return pool; | |
4160 }, | |
4161 _distributePool: function (node, pool) { | |
4162 var p$ = node._insertionPoints; | |
4163 for (var i = 0, l = p$.length, p; i < l && (p = p$[i]); i++) { | |
4164 this._distributeInsertionPoint(p, pool); | |
4165 maybeRedistributeParent(p, this); | |
4166 } | |
4167 }, | |
4168 _distributeInsertionPoint: function (content, pool) { | |
4169 var anyDistributed = false; | |
4170 for (var i = 0, l = pool.length, node; i < l; i++) { | |
4171 node = pool[i]; | |
4172 if (!node) { | |
4173 continue; | |
4174 } | |
4175 if (this._matchesContentSelect(node, content)) { | |
4176 distributeNodeInto(node, content); | |
4177 pool[i] = undefined; | |
4178 anyDistributed = true; | |
4179 } | |
4180 } | |
4181 if (!anyDistributed) { | |
4182 var children = getLightChildren(content); | |
4183 for (var j = 0; j < children.length; j++) { | |
4184 distributeNodeInto(children[j], content); | |
4185 } | |
4186 } | |
4187 }, | |
4188 _composeTree: function () { | |
4189 this._updateChildNodes(this, this._composeNode(this)); | |
4190 var p$ = this.shadyRoot._insertionPoints; | |
4191 for (var i = 0, l = p$.length, p, parent; i < l && (p = p$[i]); i++) { | |
4192 parent = p._lightParent || p.parentNode; | |
4193 if (!parent._useContent && parent !== this && parent !== this.shadyRoot) { | |
4194 this._updateChildNodes(parent, this._composeNode(parent)); | |
4195 } | |
4196 } | |
4197 }, | |
4198 _composeNode: function (node) { | |
4199 var children = []; | |
4200 var c$ = getLightChildren(node.shadyRoot || node); | |
4201 for (var i = 0; i < c$.length; i++) { | |
4202 var child = c$[i]; | |
4203 if (isInsertionPoint(child)) { | |
4204 var distributedNodes = child._distributedNodes; | |
4205 for (var j = 0; j < distributedNodes.length; j++) { | |
4206 var distributedNode = distributedNodes[j]; | |
4207 if (isFinalDestination(child, distributedNode)) { | |
4208 children.push(distributedNode); | |
4209 } | |
4210 } | |
4211 } else { | |
4212 children.push(child); | |
4213 } | |
4214 } | |
4215 return children; | |
4216 }, | |
4217 _updateChildNodes: function (container, children) { | |
4218 var composed = getComposedChildren(container); | |
4219 var splices = Polymer.ArraySplice.calculateSplices(children, composed); | |
4220 for (var i = 0, d = 0, s; i < splices.length && (s = splices[i]); i++) { | |
4221 for (var j = 0, n; j < s.removed.length && (n = s.removed[j]); j++) { | |
4222 if (getComposedParent(n) === container) { | |
4223 remove(n); | |
4224 } | |
4225 composed.splice(s.index + d, 1); | |
4226 } | |
4227 d -= s.addedCount; | |
4228 } | |
4229 for (var i = 0, s, next; i < splices.length && (s = splices[i]); i++) { | |
4230 next = composed[s.index]; | |
4231 for (var j = s.index, n; j < s.index + s.addedCount; j++) { | |
4232 n = children[j]; | |
4233 insertBefore(container, n, next); | |
4234 composed.splice(j, 0, n); | |
4235 } | |
4236 } | |
4237 ensureComposedParent(container, children); | |
4238 }, | |
4239 _matchesContentSelect: function (node, contentElement) { | |
4240 var select = contentElement.getAttribute('select'); | |
4241 if (!select) { | |
4242 return true; | |
4243 } | |
4244 select = select.trim(); | |
4245 if (!select) { | |
4246 return true; | |
4247 } | |
4248 if (!(node instanceof Element)) { | |
4249 return false; | |
4250 } | |
4251 var validSelectors = /^(:not\()?[*.#[a-zA-Z_|]/; | |
4252 if (!validSelectors.test(select)) { | |
4253 return false; | |
4254 } | |
4255 return this.elementMatches(select, node); | |
4256 }, | |
4257 _elementAdd: function () { | |
4258 }, | |
4259 _elementRemove: function () { | |
4260 } | |
4261 }); | |
4262 var saveLightChildrenIfNeeded = Polymer.DomApi.saveLightChildrenIfNeeded; | |
4263 var getLightChildren = Polymer.DomApi.getLightChildren; | |
4264 var matchesSelector = Polymer.DomApi.matchesSelector; | |
4265 var hasInsertionPoint = Polymer.DomApi.hasInsertionPoint; | |
4266 var getComposedChildren = Polymer.DomApi.getComposedChildren; | |
4267 var getComposedParent = Polymer.DomApi.getComposedParent; | |
4268 var removeFromComposedParent = Polymer.DomApi.removeFromComposedParent; | |
4269 function distributeNodeInto(child, insertionPoint) { | |
4270 insertionPoint._distributedNodes.push(child); | |
4271 var points = child._destinationInsertionPoints; | |
4272 if (!points) { | |
4273 child._destinationInsertionPoints = [insertionPoint]; | |
4274 } else { | |
4275 points.push(insertionPoint); | |
4276 } | |
4277 } | |
4278 function clearDistributedDestinationInsertionPoints(content) { | |
4279 var e$ = content._distributedNodes; | |
4280 if (e$) { | |
4281 for (var i = 0; i < e$.length; i++) { | |
4282 var d = e$[i]._destinationInsertionPoints; | |
4283 if (d) { | |
4284 d.splice(d.indexOf(content) + 1, d.length); | |
4285 } | |
4286 } | |
4287 } | |
4288 } | |
4289 function maybeRedistributeParent(content, host) { | |
4290 var parent = content._lightParent; | |
4291 if (parent && parent.shadyRoot && hasInsertionPoint(parent.shadyRoot) && parent.
shadyRoot._distributionClean) { | |
4292 parent.shadyRoot._distributionClean = false; | |
4293 host.shadyRoot._dirtyRoots.push(parent); | |
4294 } | |
4295 } | |
4296 function isFinalDestination(insertionPoint, node) { | |
4297 var points = node._destinationInsertionPoints; | |
4298 return points && points[points.length - 1] === insertionPoint; | |
4299 } | |
4300 function isInsertionPoint(node) { | |
4301 return node.localName == 'content'; | |
4302 } | |
4303 var nativeInsertBefore = Element.prototype.insertBefore; | |
4304 var nativeRemoveChild = Element.prototype.removeChild; | |
4305 function insertBefore(parentNode, newChild, refChild) { | |
4306 var newChildParent = getComposedParent(newChild); | |
4307 if (newChildParent !== parentNode) { | |
4308 removeFromComposedParent(newChildParent, newChild); | |
4309 } | |
4310 remove(newChild); | |
4311 nativeInsertBefore.call(parentNode, newChild, refChild || null); | |
4312 newChild._composedParent = parentNode; | |
4313 } | |
4314 function remove(node) { | |
4315 var parentNode = getComposedParent(node); | |
4316 if (parentNode) { | |
4317 node._composedParent = null; | |
4318 nativeRemoveChild.call(parentNode, node); | |
4319 } | |
4320 } | |
4321 function ensureComposedParent(parent, children) { | |
4322 for (var i = 0, n; i < children.length; i++) { | |
4323 children[i]._composedParent = parent; | |
4324 } | |
4325 } | |
4326 function getTopDistributingHost(host) { | |
4327 while (host && hostNeedsRedistribution(host)) { | |
4328 host = host.domHost; | |
4329 } | |
4330 return host; | |
4331 } | |
4332 function hostNeedsRedistribution(host) { | |
4333 var c$ = Polymer.dom(host).children; | |
4334 for (var i = 0, c; i < c$.length; i++) { | |
4335 c = c$[i]; | |
4336 if (c.localName === 'content') { | |
4337 return host.domHost; | |
4338 } | |
4339 } | |
4340 } | |
4341 function notifyContentObservers(root) { | |
4342 for (var i = 0, c; i < root._insertionPoints.length; i++) { | |
4343 c = root._insertionPoints[i]; | |
4344 if (hasDomApi(c)) { | |
4345 Polymer.dom(c).notifyObserver(); | |
4346 } | |
4347 } | |
4348 } | |
4349 function notifyInitialDistribution(host) { | |
4350 if (hasDomApi(host)) { | |
4351 Polymer.dom(host).notifyObserver(); | |
4352 } | |
4353 } | |
4354 var needsUpgrade = window.CustomElements && !CustomElements.useNative; | |
4355 function upgradeLightChildren(children) { | |
4356 if (needsUpgrade && children) { | |
4357 for (var i = 0; i < children.length; i++) { | |
4358 CustomElements.upgrade(children[i]); | |
4359 } | |
4360 } | |
4361 } | |
4362 }()); | |
4363 if (Polymer.Settings.useShadow) { | |
4364 Polymer.Base._addFeature({ | |
4365 _poolContent: function () { | |
4366 }, | |
4367 _beginDistribute: function () { | |
4368 }, | |
4369 distributeContent: function () { | |
4370 }, | |
4371 _distributeContent: function () { | |
4372 }, | |
4373 _finishDistribute: function () { | |
4374 }, | |
4375 _createLocalRoot: function () { | |
4376 this.createShadowRoot(); | |
4377 this.shadowRoot.appendChild(this.root); | |
4378 this.root = this.shadowRoot; | |
4379 } | |
4380 }); | |
4381 } | |
4382 Polymer.DomModule = document.createElement('dom-module'); | |
4383 Polymer.Base._addFeature({ | |
4384 _registerFeatures: function () { | |
4385 this._prepIs(); | |
4386 this._prepBehaviors(); | |
4387 this._prepConstructor(); | |
4388 this._prepTemplate(); | |
4389 this._prepShady(); | |
4390 this._prepPropertyInfo(); | |
4391 }, | |
4392 _prepBehavior: function (b) { | |
4393 this._addHostAttributes(b.hostAttributes); | |
4394 }, | |
4395 _initFeatures: function () { | |
4396 this._registerHost(); | |
4397 if (this._template) { | |
4398 this._poolContent(); | |
4399 this._beginHosting(); | |
4400 this._stampTemplate(); | |
4401 this._endHosting(); | |
4402 } | |
4403 this._marshalHostAttributes(); | |
4404 this._setupDebouncers(); | |
4405 this._marshalBehaviors(); | |
4406 this._tryReady(); | |
4407 }, | |
4408 _marshalBehavior: function (b) { | |
4409 } | |
4410 }); | |
4411 Polymer.nar = []; | |
4412 Polymer.Annotations = { | |
4413 parseAnnotations: function (template) { | |
4414 var list = []; | |
4415 var content = template._content || template.content; | |
4416 this._parseNodeAnnotations(content, list, template.hasAttribute('strip-whitespac
e')); | |
4417 return list; | |
4418 }, | |
4419 _parseNodeAnnotations: function (node, list, stripWhiteSpace) { | |
4420 return node.nodeType === Node.TEXT_NODE ? this._parseTextNodeAnnotation(node, li
st) : this._parseElementAnnotations(node, list, stripWhiteSpace); | |
4421 }, | |
4422 _bindingRegex: /([^{[]*)(\{\{|\[\[)(?!\}\}|\]\])(.+?)(?:\]\]|\}\})/g, | |
4423 _parseBindings: function (text) { | |
4424 var re = this._bindingRegex; | |
4425 var parts = []; | |
4426 var m, lastIndex; | |
4427 while ((m = re.exec(text)) !== null) { | |
4428 if (m[1]) { | |
4429 parts.push({ literal: m[1] }); | |
4430 } | |
4431 var mode = m[2][0]; | |
4432 var value = m[3].trim(); | |
4433 var negate = false; | |
4434 if (value[0] == '!') { | |
4435 negate = true; | |
4436 value = value.substring(1).trim(); | |
4437 } | |
4438 var customEvent, notifyEvent, colon; | |
4439 if (mode == '{' && (colon = value.indexOf('::')) > 0) { | |
4440 notifyEvent = value.substring(colon + 2); | |
4441 value = value.substring(0, colon); | |
4442 customEvent = true; | |
4443 } | |
4444 parts.push({ | |
4445 compoundIndex: parts.length, | |
4446 value: value, | |
4447 mode: mode, | |
4448 negate: negate, | |
4449 event: notifyEvent, | |
4450 customEvent: customEvent | |
4451 }); | |
4452 lastIndex = re.lastIndex; | |
4453 } | |
4454 if (lastIndex && lastIndex < text.length) { | |
4455 var literal = text.substring(lastIndex); | |
4456 if (literal) { | |
4457 parts.push({ literal: literal }); | |
4458 } | |
4459 } | |
4460 if (parts.length) { | |
4461 return parts; | |
4462 } | |
4463 }, | |
4464 _literalFromParts: function (parts) { | |
4465 var s = ''; | |
4466 for (var i = 0; i < parts.length; i++) { | |
4467 var literal = parts[i].literal; | |
4468 s += literal || ''; | |
4469 } | |
4470 return s; | |
4471 }, | |
4472 _parseTextNodeAnnotation: function (node, list) { | |
4473 var parts = this._parseBindings(node.textContent); | |
4474 if (parts) { | |
4475 node.textContent = this._literalFromParts(parts) || ' '; | |
4476 var annote = { | |
4477 bindings: [{ | |
4478 kind: 'text', | |
4479 name: 'textContent', | |
4480 parts: parts, | |
4481 isCompound: parts.length !== 1 | |
4482 }] | |
4483 }; | |
4484 list.push(annote); | |
4485 return annote; | |
4486 } | |
4487 }, | |
4488 _parseElementAnnotations: function (element, list, stripWhiteSpace) { | |
4489 var annote = { | |
4490 bindings: [], | |
4491 events: [] | |
4492 }; | |
4493 if (element.localName === 'content') { | |
4494 list._hasContent = true; | |
4495 } | |
4496 this._parseChildNodesAnnotations(element, annote, list, stripWhiteSpace); | |
4497 if (element.attributes) { | |
4498 this._parseNodeAttributeAnnotations(element, annote, list); | |
4499 if (this.prepElement) { | |
4500 this.prepElement(element); | |
4501 } | |
4502 } | |
4503 if (annote.bindings.length || annote.events.length || annote.id) { | |
4504 list.push(annote); | |
4505 } | |
4506 return annote; | |
4507 }, | |
4508 _parseChildNodesAnnotations: function (root, annote, list, stripWhiteSpace) { | |
4509 if (root.firstChild) { | |
4510 var node = root.firstChild; | |
4511 var i = 0; | |
4512 while (node) { | |
4513 var next = node.nextSibling; | |
4514 if (node.localName === 'template' && !node.hasAttribute('preserve-content')) { | |
4515 this._parseTemplate(node, i, list, annote); | |
4516 } | |
4517 if (node.nodeType === Node.TEXT_NODE) { | |
4518 var n = next; | |
4519 while (n && n.nodeType === Node.TEXT_NODE) { | |
4520 node.textContent += n.textContent; | |
4521 next = n.nextSibling; | |
4522 root.removeChild(n); | |
4523 n = next; | |
4524 } | |
4525 if (stripWhiteSpace && !node.textContent.trim()) { | |
4526 root.removeChild(node); | |
4527 i--; | |
4528 } | |
4529 } | |
4530 if (node.parentNode) { | |
4531 var childAnnotation = this._parseNodeAnnotations(node, list, stripWhiteSpace); | |
4532 if (childAnnotation) { | |
4533 childAnnotation.parent = annote; | |
4534 childAnnotation.index = i; | |
4535 } | |
4536 } | |
4537 node = next; | |
4538 i++; | |
4539 } | |
4540 } | |
4541 }, | |
4542 _parseTemplate: function (node, index, list, parent) { | |
4543 var content = document.createDocumentFragment(); | |
4544 content._notes = this.parseAnnotations(node); | |
4545 content.appendChild(node.content); | |
4546 list.push({ | |
4547 bindings: Polymer.nar, | |
4548 events: Polymer.nar, | |
4549 templateContent: content, | |
4550 parent: parent, | |
4551 index: index | |
4552 }); | |
4553 }, | |
4554 _parseNodeAttributeAnnotations: function (node, annotation) { | |
4555 var attrs = Array.prototype.slice.call(node.attributes); | |
4556 for (var i = attrs.length - 1, a; a = attrs[i]; i--) { | |
4557 var n = a.name; | |
4558 var v = a.value; | |
4559 var b; | |
4560 if (n.slice(0, 3) === 'on-') { | |
4561 node.removeAttribute(n); | |
4562 annotation.events.push({ | |
4563 name: n.slice(3), | |
4564 value: v | |
4565 }); | |
4566 } else if (b = this._parseNodeAttributeAnnotation(node, n, v)) { | |
4567 annotation.bindings.push(b); | |
4568 } else if (n === 'id') { | |
4569 annotation.id = v; | |
4570 } | |
4571 } | |
4572 }, | |
4573 _parseNodeAttributeAnnotation: function (node, name, value) { | |
4574 var parts = this._parseBindings(value); | |
4575 if (parts) { | |
4576 var origName = name; | |
4577 var kind = 'property'; | |
4578 if (name[name.length - 1] == '$') { | |
4579 name = name.slice(0, -1); | |
4580 kind = 'attribute'; | |
4581 } | |
4582 var literal = this._literalFromParts(parts); | |
4583 if (literal && kind == 'attribute') { | |
4584 node.setAttribute(name, literal); | |
4585 } | |
4586 if (node.localName == 'input' && name == 'value') { | |
4587 node.setAttribute(origName, ''); | |
4588 } | |
4589 node.removeAttribute(origName); | |
4590 if (kind === 'property') { | |
4591 name = Polymer.CaseMap.dashToCamelCase(name); | |
4592 } | |
4593 return { | |
4594 kind: kind, | |
4595 name: name, | |
4596 parts: parts, | |
4597 literal: literal, | |
4598 isCompound: parts.length !== 1 | |
4599 }; | |
4600 } | |
4601 }, | |
4602 _localSubTree: function (node, host) { | |
4603 return node === host ? node.childNodes : node._lightChildren || node.childNodes; | |
4604 }, | |
4605 findAnnotatedNode: function (root, annote) { | |
4606 var parent = annote.parent && Polymer.Annotations.findAnnotatedNode(root, annote
.parent); | |
4607 return !parent ? root : Polymer.Annotations._localSubTree(parent, root)[annote.i
ndex]; | |
4608 } | |
4609 }; | |
4610 (function () { | |
4611 function resolveCss(cssText, ownerDocument) { | |
4612 return cssText.replace(CSS_URL_RX, function (m, pre, url, post) { | |
4613 return pre + '\'' + resolve(url.replace(/["']/g, ''), ownerDocument) + '\'' + po
st; | |
4614 }); | |
4615 } | |
4616 function resolveAttrs(element, ownerDocument) { | |
4617 for (var name in URL_ATTRS) { | |
4618 var a$ = URL_ATTRS[name]; | |
4619 for (var i = 0, l = a$.length, a, at, v; i < l && (a = a$[i]); i++) { | |
4620 if (name === '*' || element.localName === name) { | |
4621 at = element.attributes[a]; | |
4622 v = at && at.value; | |
4623 if (v && v.search(BINDING_RX) < 0) { | |
4624 at.value = a === 'style' ? resolveCss(v, ownerDocument) : resolve(v, ownerDocume
nt); | |
4625 } | |
4626 } | |
4627 } | |
4628 } | |
4629 } | |
4630 function resolve(url, ownerDocument) { | |
4631 if (url && url[0] === '#') { | |
4632 return url; | |
4633 } | |
4634 var resolver = getUrlResolver(ownerDocument); | |
4635 resolver.href = url; | |
4636 return resolver.href || url; | |
4637 } | |
4638 var tempDoc; | |
4639 var tempDocBase; | |
4640 function resolveUrl(url, baseUri) { | |
4641 if (!tempDoc) { | |
4642 tempDoc = document.implementation.createHTMLDocument('temp'); | |
4643 tempDocBase = tempDoc.createElement('base'); | |
4644 tempDoc.head.appendChild(tempDocBase); | |
4645 } | |
4646 tempDocBase.href = baseUri; | |
4647 return resolve(url, tempDoc); | |
4648 } | |
4649 function getUrlResolver(ownerDocument) { | |
4650 return ownerDocument.__urlResolver || (ownerDocument.__urlResolver = ownerDocume
nt.createElement('a')); | |
4651 } | |
4652 var CSS_URL_RX = /(url\()([^)]*)(\))/g; | |
4653 var URL_ATTRS = { | |
4654 '*': [ | |
4655 'href', | |
4656 'src', | |
4657 'style', | |
4658 'url' | |
4659 ], | |
4660 form: ['action'] | |
4661 }; | |
4662 var BINDING_RX = /\{\{|\[\[/; | |
4663 Polymer.ResolveUrl = { | |
4664 resolveCss: resolveCss, | |
4665 resolveAttrs: resolveAttrs, | |
4666 resolveUrl: resolveUrl | |
4667 }; | |
4668 }()); | |
4669 Polymer.Base._addFeature({ | |
4670 _prepAnnotations: function () { | |
4671 if (!this._template) { | |
4672 this._notes = []; | |
4673 } else { | |
4674 var self = this; | |
4675 Polymer.Annotations.prepElement = function (element) { | |
4676 self._prepElement(element); | |
4677 }; | |
4678 if (this._template._content && this._template._content._notes) { | |
4679 this._notes = this._template._content._notes; | |
4680 } else { | |
4681 this._notes = Polymer.Annotations.parseAnnotations(this._template); | |
4682 } | |
4683 this._processAnnotations(this._notes); | |
4684 Polymer.Annotations.prepElement = null; | |
4685 } | |
4686 }, | |
4687 _processAnnotations: function (notes) { | |
4688 for (var i = 0; i < notes.length; i++) { | |
4689 var note = notes[i]; | |
4690 for (var j = 0; j < note.bindings.length; j++) { | |
4691 var b = note.bindings[j]; | |
4692 for (var k = 0; k < b.parts.length; k++) { | |
4693 var p = b.parts[k]; | |
4694 if (!p.literal) { | |
4695 p.signature = this._parseMethod(p.value); | |
4696 if (!p.signature) { | |
4697 p.model = this._modelForPath(p.value); | |
4698 } | |
4699 } | |
4700 } | |
4701 } | |
4702 if (note.templateContent) { | |
4703 this._processAnnotations(note.templateContent._notes); | |
4704 var pp = note.templateContent._parentProps = this._discoverTemplateParentProps(n
ote.templateContent._notes); | |
4705 var bindings = []; | |
4706 for (var prop in pp) { | |
4707 bindings.push({ | |
4708 index: note.index, | |
4709 kind: 'property', | |
4710 name: '_parent_' + prop, | |
4711 parts: [{ | |
4712 mode: '{', | |
4713 model: prop, | |
4714 value: prop | |
4715 }] | |
4716 }); | |
4717 } | |
4718 note.bindings = note.bindings.concat(bindings); | |
4719 } | |
4720 } | |
4721 }, | |
4722 _discoverTemplateParentProps: function (notes) { | |
4723 var pp = {}; | |
4724 for (var i = 0, n; i < notes.length && (n = notes[i]); i++) { | |
4725 for (var j = 0, b$ = n.bindings, b; j < b$.length && (b = b$[j]); j++) { | |
4726 for (var k = 0, p$ = b.parts, p; k < p$.length && (p = p$[k]); k++) { | |
4727 if (p.signature) { | |
4728 var args = p.signature.args; | |
4729 for (var kk = 0; kk < args.length; kk++) { | |
4730 pp[args[kk].model] = true; | |
4731 } | |
4732 } else { | |
4733 pp[p.model] = true; | |
4734 } | |
4735 } | |
4736 } | |
4737 if (n.templateContent) { | |
4738 var tpp = n.templateContent._parentProps; | |
4739 Polymer.Base.mixin(pp, tpp); | |
4740 } | |
4741 } | |
4742 return pp; | |
4743 }, | |
4744 _prepElement: function (element) { | |
4745 Polymer.ResolveUrl.resolveAttrs(element, this._template.ownerDocument); | |
4746 }, | |
4747 _findAnnotatedNode: Polymer.Annotations.findAnnotatedNode, | |
4748 _marshalAnnotationReferences: function () { | |
4749 if (this._template) { | |
4750 this._marshalIdNodes(); | |
4751 this._marshalAnnotatedNodes(); | |
4752 this._marshalAnnotatedListeners(); | |
4753 } | |
4754 }, | |
4755 _configureAnnotationReferences: function (config) { | |
4756 var notes = this._notes; | |
4757 var nodes = this._nodes; | |
4758 for (var i = 0; i < notes.length; i++) { | |
4759 var note = notes[i]; | |
4760 var node = nodes[i]; | |
4761 this._configureTemplateContent(note, node); | |
4762 this._configureCompoundBindings(note, node); | |
4763 } | |
4764 }, | |
4765 _configureTemplateContent: function (note, node) { | |
4766 if (note.templateContent) { | |
4767 node._content = note.templateContent; | |
4768 } | |
4769 }, | |
4770 _configureCompoundBindings: function (note, node) { | |
4771 var bindings = note.bindings; | |
4772 for (var i = 0; i < bindings.length; i++) { | |
4773 var binding = bindings[i]; | |
4774 if (binding.isCompound) { | |
4775 var storage = node.__compoundStorage__ || (node.__compoundStorage__ = {}); | |
4776 var parts = binding.parts; | |
4777 var literals = new Array(parts.length); | |
4778 for (var j = 0; j < parts.length; j++) { | |
4779 literals[j] = parts[j].literal; | |
4780 } | |
4781 var name = binding.name; | |
4782 storage[name] = literals; | |
4783 if (binding.literal && binding.kind == 'property') { | |
4784 if (node._configValue) { | |
4785 node._configValue(name, binding.literal); | |
4786 } else { | |
4787 node[name] = binding.literal; | |
4788 } | |
4789 } | |
4790 } | |
4791 } | |
4792 }, | |
4793 _marshalIdNodes: function () { | |
4794 this.$ = {}; | |
4795 for (var i = 0, l = this._notes.length, a; i < l && (a = this._notes[i]); i++) { | |
4796 if (a.id) { | |
4797 this.$[a.id] = this._findAnnotatedNode(this.root, a); | |
4798 } | |
4799 } | |
4800 }, | |
4801 _marshalAnnotatedNodes: function () { | |
4802 if (this._notes && this._notes.length) { | |
4803 var r = new Array(this._notes.length); | |
4804 for (var i = 0; i < this._notes.length; i++) { | |
4805 r[i] = this._findAnnotatedNode(this.root, this._notes[i]); | |
4806 } | |
4807 this._nodes = r; | |
4808 } | |
4809 }, | |
4810 _marshalAnnotatedListeners: function () { | |
4811 for (var i = 0, l = this._notes.length, a; i < l && (a = this._notes[i]); i++) { | |
4812 if (a.events && a.events.length) { | |
4813 var node = this._findAnnotatedNode(this.root, a); | |
4814 for (var j = 0, e$ = a.events, e; j < e$.length && (e = e$[j]); j++) { | |
4815 this.listen(node, e.name, e.value); | |
4816 } | |
4817 } | |
4818 } | |
4819 } | |
4820 }); | |
4821 Polymer.Base._addFeature({ | |
4822 listeners: {}, | |
4823 _listenListeners: function (listeners) { | |
4824 var node, name, eventName; | |
4825 for (eventName in listeners) { | |
4826 if (eventName.indexOf('.') < 0) { | |
4827 node = this; | |
4828 name = eventName; | |
4829 } else { | |
4830 name = eventName.split('.'); | |
4831 node = this.$[name[0]]; | |
4832 name = name[1]; | |
4833 } | |
4834 this.listen(node, name, listeners[eventName]); | |
4835 } | |
4836 }, | |
4837 listen: function (node, eventName, methodName) { | |
4838 var handler = this._recallEventHandler(this, eventName, node, methodName); | |
4839 if (!handler) { | |
4840 handler = this._createEventHandler(node, eventName, methodName); | |
4841 } | |
4842 if (handler._listening) { | |
4843 return; | |
4844 } | |
4845 this._listen(node, eventName, handler); | |
4846 handler._listening = true; | |
4847 }, | |
4848 _boundListenerKey: function (eventName, methodName) { | |
4849 return eventName + ':' + methodName; | |
4850 }, | |
4851 _recordEventHandler: function (host, eventName, target, methodName, handler) { | |
4852 var hbl = host.__boundListeners; | |
4853 if (!hbl) { | |
4854 hbl = host.__boundListeners = new WeakMap(); | |
4855 } | |
4856 var bl = hbl.get(target); | |
4857 if (!bl) { | |
4858 bl = {}; | |
4859 hbl.set(target, bl); | |
4860 } | |
4861 var key = this._boundListenerKey(eventName, methodName); | |
4862 bl[key] = handler; | |
4863 }, | |
4864 _recallEventHandler: function (host, eventName, target, methodName) { | |
4865 var hbl = host.__boundListeners; | |
4866 if (!hbl) { | |
4867 return; | |
4868 } | |
4869 var bl = hbl.get(target); | |
4870 if (!bl) { | |
4871 return; | |
4872 } | |
4873 var key = this._boundListenerKey(eventName, methodName); | |
4874 return bl[key]; | |
4875 }, | |
4876 _createEventHandler: function (node, eventName, methodName) { | |
4877 var host = this; | |
4878 var handler = function (e) { | |
4879 if (host[methodName]) { | |
4880 host[methodName](e, e.detail); | |
4881 } else { | |
4882 host._warn(host._logf('_createEventHandler', 'listener method `' + methodName +
'` not defined')); | |
4883 } | |
4884 }; | |
4885 handler._listening = false; | |
4886 this._recordEventHandler(host, eventName, node, methodName, handler); | |
4887 return handler; | |
4888 }, | |
4889 unlisten: function (node, eventName, methodName) { | |
4890 var handler = this._recallEventHandler(this, eventName, node, methodName); | |
4891 if (handler) { | |
4892 this._unlisten(node, eventName, handler); | |
4893 handler._listening = false; | |
4894 } | |
4895 }, | |
4896 _listen: function (node, eventName, handler) { | |
4897 node.addEventListener(eventName, handler); | |
4898 }, | |
4899 _unlisten: function (node, eventName, handler) { | |
4900 node.removeEventListener(eventName, handler); | |
4901 } | |
4902 }); | |
4903 (function () { | |
4904 'use strict'; | |
4905 var wrap = Polymer.DomApi.wrap; | |
4906 var HAS_NATIVE_TA = typeof document.head.style.touchAction === 'string'; | |
4907 var GESTURE_KEY = '__polymerGestures'; | |
4908 var HANDLED_OBJ = '__polymerGesturesHandled'; | |
4909 var TOUCH_ACTION = '__polymerGesturesTouchAction'; | |
4910 var TAP_DISTANCE = 25; | |
4911 var TRACK_DISTANCE = 5; | |
4912 var TRACK_LENGTH = 2; | |
4913 var MOUSE_TIMEOUT = 2500; | |
4914 var MOUSE_EVENTS = [ | |
4915 'mousedown', | |
4916 'mousemove', | |
4917 'mouseup', | |
4918 'click' | |
4919 ]; | |
4920 var MOUSE_WHICH_TO_BUTTONS = [ | |
4921 0, | |
4922 1, | |
4923 4, | |
4924 2 | |
4925 ]; | |
4926 var MOUSE_HAS_BUTTONS = function () { | |
4927 try { | |
4928 return new MouseEvent('test', { buttons: 1 }).buttons === 1; | |
4929 } catch (e) { | |
4930 return false; | |
4931 } | |
4932 }(); | |
4933 var IS_TOUCH_ONLY = navigator.userAgent.match(/iP(?:[oa]d|hone)|Android/); | |
4934 var mouseCanceller = function (mouseEvent) { | |
4935 mouseEvent[HANDLED_OBJ] = { skip: true }; | |
4936 if (mouseEvent.type === 'click') { | |
4937 var path = Polymer.dom(mouseEvent).path; | |
4938 for (var i = 0; i < path.length; i++) { | |
4939 if (path[i] === POINTERSTATE.mouse.target) { | |
4940 return; | |
4941 } | |
4942 } | |
4943 mouseEvent.preventDefault(); | |
4944 mouseEvent.stopPropagation(); | |
4945 } | |
4946 }; | |
4947 function setupTeardownMouseCanceller(setup) { | |
4948 for (var i = 0, en; i < MOUSE_EVENTS.length; i++) { | |
4949 en = MOUSE_EVENTS[i]; | |
4950 if (setup) { | |
4951 document.addEventListener(en, mouseCanceller, true); | |
4952 } else { | |
4953 document.removeEventListener(en, mouseCanceller, true); | |
4954 } | |
4955 } | |
4956 } | |
4957 function ignoreMouse() { | |
4958 if (IS_TOUCH_ONLY) { | |
4959 return; | |
4960 } | |
4961 if (!POINTERSTATE.mouse.mouseIgnoreJob) { | |
4962 setupTeardownMouseCanceller(true); | |
4963 } | |
4964 var unset = function () { | |
4965 setupTeardownMouseCanceller(); | |
4966 POINTERSTATE.mouse.target = null; | |
4967 POINTERSTATE.mouse.mouseIgnoreJob = null; | |
4968 }; | |
4969 POINTERSTATE.mouse.mouseIgnoreJob = Polymer.Debounce(POINTERSTATE.mouse.mouseIgn
oreJob, unset, MOUSE_TIMEOUT); | |
4970 } | |
4971 function hasLeftMouseButton(ev) { | |
4972 var type = ev.type; | |
4973 if (MOUSE_EVENTS.indexOf(type) === -1) { | |
4974 return false; | |
4975 } | |
4976 if (type === 'mousemove') { | |
4977 var buttons = ev.buttons === undefined ? 1 : ev.buttons; | |
4978 if (ev instanceof window.MouseEvent && !MOUSE_HAS_BUTTONS) { | |
4979 buttons = MOUSE_WHICH_TO_BUTTONS[ev.which] || 0; | |
4980 } | |
4981 return Boolean(buttons & 1); | |
4982 } else { | |
4983 var button = ev.button === undefined ? 0 : ev.button; | |
4984 return button === 0; | |
4985 } | |
4986 } | |
4987 function isSyntheticClick(ev) { | |
4988 if (ev.type === 'click') { | |
4989 if (ev.detail === 0) { | |
4990 return true; | |
4991 } | |
4992 var t = Gestures.findOriginalTarget(ev); | |
4993 var bcr = t.getBoundingClientRect(); | |
4994 var x = ev.pageX, y = ev.pageY; | |
4995 return !(x >= bcr.left && x <= bcr.right && (y >= bcr.top && y <= bcr.bottom)); | |
4996 } | |
4997 return false; | |
4998 } | |
4999 var POINTERSTATE = { | |
5000 mouse: { | |
5001 target: null, | |
5002 mouseIgnoreJob: null | |
5003 }, | |
5004 touch: { | |
5005 x: 0, | |
5006 y: 0, | |
5007 id: -1, | |
5008 scrollDecided: false | |
5009 } | |
5010 }; | |
5011 function firstTouchAction(ev) { | |
5012 var path = Polymer.dom(ev).path; | |
5013 var ta = 'auto'; | |
5014 for (var i = 0, n; i < path.length; i++) { | |
5015 n = path[i]; | |
5016 if (n[TOUCH_ACTION]) { | |
5017 ta = n[TOUCH_ACTION]; | |
5018 break; | |
5019 } | |
5020 } | |
5021 return ta; | |
5022 } | |
5023 function trackDocument(stateObj, movefn, upfn) { | |
5024 stateObj.movefn = movefn; | |
5025 stateObj.upfn = upfn; | |
5026 document.addEventListener('mousemove', movefn); | |
5027 document.addEventListener('mouseup', upfn); | |
5028 } | |
5029 function untrackDocument(stateObj) { | |
5030 document.removeEventListener('mousemove', stateObj.movefn); | |
5031 document.removeEventListener('mouseup', stateObj.upfn); | |
5032 } | |
5033 var Gestures = { | |
5034 gestures: {}, | |
5035 recognizers: [], | |
5036 deepTargetFind: function (x, y) { | |
5037 var node = document.elementFromPoint(x, y); | |
5038 var next = node; | |
5039 while (next && next.shadowRoot) { | |
5040 next = next.shadowRoot.elementFromPoint(x, y); | |
5041 if (next) { | |
5042 node = next; | |
5043 } | |
5044 } | |
5045 return node; | |
5046 }, | |
5047 findOriginalTarget: function (ev) { | |
5048 if (ev.path) { | |
5049 return ev.path[0]; | |
5050 } | |
5051 return ev.target; | |
5052 }, | |
5053 handleNative: function (ev) { | |
5054 var handled; | |
5055 var type = ev.type; | |
5056 var node = wrap(ev.currentTarget); | |
5057 var gobj = node[GESTURE_KEY]; | |
5058 if (!gobj) { | |
5059 return; | |
5060 } | |
5061 var gs = gobj[type]; | |
5062 if (!gs) { | |
5063 return; | |
5064 } | |
5065 if (!ev[HANDLED_OBJ]) { | |
5066 ev[HANDLED_OBJ] = {}; | |
5067 if (type.slice(0, 5) === 'touch') { | |
5068 var t = ev.changedTouches[0]; | |
5069 if (type === 'touchstart') { | |
5070 if (ev.touches.length === 1) { | |
5071 POINTERSTATE.touch.id = t.identifier; | |
5072 } | |
5073 } | |
5074 if (POINTERSTATE.touch.id !== t.identifier) { | |
5075 return; | |
5076 } | |
5077 if (!HAS_NATIVE_TA) { | |
5078 if (type === 'touchstart' || type === 'touchmove') { | |
5079 Gestures.handleTouchAction(ev); | |
5080 } | |
5081 } | |
5082 if (type === 'touchend') { | |
5083 POINTERSTATE.mouse.target = Polymer.dom(ev).rootTarget; | |
5084 ignoreMouse(true); | |
5085 } | |
5086 } | |
5087 } | |
5088 handled = ev[HANDLED_OBJ]; | |
5089 if (handled.skip) { | |
5090 return; | |
5091 } | |
5092 var recognizers = Gestures.recognizers; | |
5093 for (var i = 0, r; i < recognizers.length; i++) { | |
5094 r = recognizers[i]; | |
5095 if (gs[r.name] && !handled[r.name]) { | |
5096 if (r.flow && r.flow.start.indexOf(ev.type) > -1) { | |
5097 if (r.reset) { | |
5098 r.reset(); | |
5099 } | |
5100 } | |
5101 } | |
5102 } | |
5103 for (var i = 0, r; i < recognizers.length; i++) { | |
5104 r = recognizers[i]; | |
5105 if (gs[r.name] && !handled[r.name]) { | |
5106 handled[r.name] = true; | |
5107 r[type](ev); | |
5108 } | |
5109 } | |
5110 }, | |
5111 handleTouchAction: function (ev) { | |
5112 var t = ev.changedTouches[0]; | |
5113 var type = ev.type; | |
5114 if (type === 'touchstart') { | |
5115 POINTERSTATE.touch.x = t.clientX; | |
5116 POINTERSTATE.touch.y = t.clientY; | |
5117 POINTERSTATE.touch.scrollDecided = false; | |
5118 } else if (type === 'touchmove') { | |
5119 if (POINTERSTATE.touch.scrollDecided) { | |
5120 return; | |
5121 } | |
5122 POINTERSTATE.touch.scrollDecided = true; | |
5123 var ta = firstTouchAction(ev); | |
5124 var prevent = false; | |
5125 var dx = Math.abs(POINTERSTATE.touch.x - t.clientX); | |
5126 var dy = Math.abs(POINTERSTATE.touch.y - t.clientY); | |
5127 if (!ev.cancelable) { | |
5128 } else if (ta === 'none') { | |
5129 prevent = true; | |
5130 } else if (ta === 'pan-x') { | |
5131 prevent = dy > dx; | |
5132 } else if (ta === 'pan-y') { | |
5133 prevent = dx > dy; | |
5134 } | |
5135 if (prevent) { | |
5136 ev.preventDefault(); | |
5137 } else { | |
5138 Gestures.prevent('track'); | |
5139 } | |
5140 } | |
5141 }, | |
5142 add: function (node, evType, handler) { | |
5143 node = wrap(node); | |
5144 var recognizer = this.gestures[evType]; | |
5145 var deps = recognizer.deps; | |
5146 var name = recognizer.name; | |
5147 var gobj = node[GESTURE_KEY]; | |
5148 if (!gobj) { | |
5149 node[GESTURE_KEY] = gobj = {}; | |
5150 } | |
5151 for (var i = 0, dep, gd; i < deps.length; i++) { | |
5152 dep = deps[i]; | |
5153 if (IS_TOUCH_ONLY && MOUSE_EVENTS.indexOf(dep) > -1) { | |
5154 continue; | |
5155 } | |
5156 gd = gobj[dep]; | |
5157 if (!gd) { | |
5158 gobj[dep] = gd = { _count: 0 }; | |
5159 } | |
5160 if (gd._count === 0) { | |
5161 node.addEventListener(dep, this.handleNative); | |
5162 } | |
5163 gd[name] = (gd[name] || 0) + 1; | |
5164 gd._count = (gd._count || 0) + 1; | |
5165 } | |
5166 node.addEventListener(evType, handler); | |
5167 if (recognizer.touchAction) { | |
5168 this.setTouchAction(node, recognizer.touchAction); | |
5169 } | |
5170 }, | |
5171 remove: function (node, evType, handler) { | |
5172 node = wrap(node); | |
5173 var recognizer = this.gestures[evType]; | |
5174 var deps = recognizer.deps; | |
5175 var name = recognizer.name; | |
5176 var gobj = node[GESTURE_KEY]; | |
5177 if (gobj) { | |
5178 for (var i = 0, dep, gd; i < deps.length; i++) { | |
5179 dep = deps[i]; | |
5180 gd = gobj[dep]; | |
5181 if (gd && gd[name]) { | |
5182 gd[name] = (gd[name] || 1) - 1; | |
5183 gd._count = (gd._count || 1) - 1; | |
5184 if (gd._count === 0) { | |
5185 node.removeEventListener(dep, this.handleNative); | |
5186 } | |
5187 } | |
5188 } | |
5189 } | |
5190 node.removeEventListener(evType, handler); | |
5191 }, | |
5192 register: function (recog) { | |
5193 this.recognizers.push(recog); | |
5194 for (var i = 0; i < recog.emits.length; i++) { | |
5195 this.gestures[recog.emits[i]] = recog; | |
5196 } | |
5197 }, | |
5198 findRecognizerByEvent: function (evName) { | |
5199 for (var i = 0, r; i < this.recognizers.length; i++) { | |
5200 r = this.recognizers[i]; | |
5201 for (var j = 0, n; j < r.emits.length; j++) { | |
5202 n = r.emits[j]; | |
5203 if (n === evName) { | |
5204 return r; | |
5205 } | |
5206 } | |
5207 } | |
5208 return null; | |
5209 }, | |
5210 setTouchAction: function (node, value) { | |
5211 if (HAS_NATIVE_TA) { | |
5212 node.style.touchAction = value; | |
5213 } | |
5214 node[TOUCH_ACTION] = value; | |
5215 }, | |
5216 fire: function (target, type, detail) { | |
5217 var ev = Polymer.Base.fire(type, detail, { | |
5218 node: target, | |
5219 bubbles: true, | |
5220 cancelable: true | |
5221 }); | |
5222 if (ev.defaultPrevented) { | |
5223 var se = detail.sourceEvent; | |
5224 if (se && se.preventDefault) { | |
5225 se.preventDefault(); | |
5226 } | |
5227 } | |
5228 }, | |
5229 prevent: function (evName) { | |
5230 var recognizer = this.findRecognizerByEvent(evName); | |
5231 if (recognizer.info) { | |
5232 recognizer.info.prevent = true; | |
5233 } | |
5234 } | |
5235 }; | |
5236 Gestures.register({ | |
5237 name: 'downup', | |
5238 deps: [ | |
5239 'mousedown', | |
5240 'touchstart', | |
5241 'touchend' | |
5242 ], | |
5243 flow: { | |
5244 start: [ | |
5245 'mousedown', | |
5246 'touchstart' | |
5247 ], | |
5248 end: [ | |
5249 'mouseup', | |
5250 'touchend' | |
5251 ] | |
5252 }, | |
5253 emits: [ | |
5254 'down', | |
5255 'up' | |
5256 ], | |
5257 info: { | |
5258 movefn: function () { | |
5259 }, | |
5260 upfn: function () { | |
5261 } | |
5262 }, | |
5263 reset: function () { | |
5264 untrackDocument(this.info); | |
5265 }, | |
5266 mousedown: function (e) { | |
5267 if (!hasLeftMouseButton(e)) { | |
5268 return; | |
5269 } | |
5270 var t = Gestures.findOriginalTarget(e); | |
5271 var self = this; | |
5272 var movefn = function movefn(e) { | |
5273 if (!hasLeftMouseButton(e)) { | |
5274 self.fire('up', t, e); | |
5275 untrackDocument(self.info); | |
5276 } | |
5277 }; | |
5278 var upfn = function upfn(e) { | |
5279 if (hasLeftMouseButton(e)) { | |
5280 self.fire('up', t, e); | |
5281 } | |
5282 untrackDocument(self.info); | |
5283 }; | |
5284 trackDocument(this.info, movefn, upfn); | |
5285 this.fire('down', t, e); | |
5286 }, | |
5287 touchstart: function (e) { | |
5288 this.fire('down', Gestures.findOriginalTarget(e), e.changedTouches[0]); | |
5289 }, | |
5290 touchend: function (e) { | |
5291 this.fire('up', Gestures.findOriginalTarget(e), e.changedTouches[0]); | |
5292 }, | |
5293 fire: function (type, target, event) { | |
5294 var self = this; | |
5295 Gestures.fire(target, type, { | |
5296 x: event.clientX, | |
5297 y: event.clientY, | |
5298 sourceEvent: event, | |
5299 prevent: function (e) { | |
5300 return Gestures.prevent(e); | |
5301 } | |
5302 }); | |
5303 } | |
5304 }); | |
5305 Gestures.register({ | |
5306 name: 'track', | |
5307 touchAction: 'none', | |
5308 deps: [ | |
5309 'mousedown', | |
5310 'touchstart', | |
5311 'touchmove', | |
5312 'touchend' | |
5313 ], | |
5314 flow: { | |
5315 start: [ | |
5316 'mousedown', | |
5317 'touchstart' | |
5318 ], | |
5319 end: [ | |
5320 'mouseup', | |
5321 'touchend' | |
5322 ] | |
5323 }, | |
5324 emits: ['track'], | |
5325 info: { | |
5326 x: 0, | |
5327 y: 0, | |
5328 state: 'start', | |
5329 started: false, | |
5330 moves: [], | |
5331 addMove: function (move) { | |
5332 if (this.moves.length > TRACK_LENGTH) { | |
5333 this.moves.shift(); | |
5334 } | |
5335 this.moves.push(move); | |
5336 }, | |
5337 movefn: function () { | |
5338 }, | |
5339 upfn: function () { | |
5340 }, | |
5341 prevent: false | |
5342 }, | |
5343 reset: function () { | |
5344 this.info.state = 'start'; | |
5345 this.info.started = false; | |
5346 this.info.moves = []; | |
5347 this.info.x = 0; | |
5348 this.info.y = 0; | |
5349 this.info.prevent = false; | |
5350 untrackDocument(this.info); | |
5351 }, | |
5352 hasMovedEnough: function (x, y) { | |
5353 if (this.info.prevent) { | |
5354 return false; | |
5355 } | |
5356 if (this.info.started) { | |
5357 return true; | |
5358 } | |
5359 var dx = Math.abs(this.info.x - x); | |
5360 var dy = Math.abs(this.info.y - y); | |
5361 return dx >= TRACK_DISTANCE || dy >= TRACK_DISTANCE; | |
5362 }, | |
5363 mousedown: function (e) { | |
5364 if (!hasLeftMouseButton(e)) { | |
5365 return; | |
5366 } | |
5367 var t = Gestures.findOriginalTarget(e); | |
5368 var self = this; | |
5369 var movefn = function movefn(e) { | |
5370 var x = e.clientX, y = e.clientY; | |
5371 if (self.hasMovedEnough(x, y)) { | |
5372 self.info.state = self.info.started ? e.type === 'mouseup' ? 'end' : 'track' : '
start'; | |
5373 self.info.addMove({ | |
5374 x: x, | |
5375 y: y | |
5376 }); | |
5377 if (!hasLeftMouseButton(e)) { | |
5378 self.info.state = 'end'; | |
5379 untrackDocument(self.info); | |
5380 } | |
5381 self.fire(t, e); | |
5382 self.info.started = true; | |
5383 } | |
5384 }; | |
5385 var upfn = function upfn(e) { | |
5386 if (self.info.started) { | |
5387 Gestures.prevent('tap'); | |
5388 movefn(e); | |
5389 } | |
5390 untrackDocument(self.info); | |
5391 }; | |
5392 trackDocument(this.info, movefn, upfn); | |
5393 this.info.x = e.clientX; | |
5394 this.info.y = e.clientY; | |
5395 }, | |
5396 touchstart: function (e) { | |
5397 var ct = e.changedTouches[0]; | |
5398 this.info.x = ct.clientX; | |
5399 this.info.y = ct.clientY; | |
5400 }, | |
5401 touchmove: function (e) { | |
5402 var t = Gestures.findOriginalTarget(e); | |
5403 var ct = e.changedTouches[0]; | |
5404 var x = ct.clientX, y = ct.clientY; | |
5405 if (this.hasMovedEnough(x, y)) { | |
5406 this.info.addMove({ | |
5407 x: x, | |
5408 y: y | |
5409 }); | |
5410 this.fire(t, ct); | |
5411 this.info.state = 'track'; | |
5412 this.info.started = true; | |
5413 } | |
5414 }, | |
5415 touchend: function (e) { | |
5416 var t = Gestures.findOriginalTarget(e); | |
5417 var ct = e.changedTouches[0]; | |
5418 if (this.info.started) { | |
5419 Gestures.prevent('tap'); | |
5420 this.info.state = 'end'; | |
5421 this.info.addMove({ | |
5422 x: ct.clientX, | |
5423 y: ct.clientY | |
5424 }); | |
5425 this.fire(t, ct); | |
5426 } | |
5427 }, | |
5428 fire: function (target, touch) { | |
5429 var secondlast = this.info.moves[this.info.moves.length - 2]; | |
5430 var lastmove = this.info.moves[this.info.moves.length - 1]; | |
5431 var dx = lastmove.x - this.info.x; | |
5432 var dy = lastmove.y - this.info.y; | |
5433 var ddx, ddy = 0; | |
5434 if (secondlast) { | |
5435 ddx = lastmove.x - secondlast.x; | |
5436 ddy = lastmove.y - secondlast.y; | |
5437 } | |
5438 return Gestures.fire(target, 'track', { | |
5439 state: this.info.state, | |
5440 x: touch.clientX, | |
5441 y: touch.clientY, | |
5442 dx: dx, | |
5443 dy: dy, | |
5444 ddx: ddx, | |
5445 ddy: ddy, | |
5446 sourceEvent: touch, | |
5447 hover: function () { | |
5448 return Gestures.deepTargetFind(touch.clientX, touch.clientY); | |
5449 } | |
5450 }); | |
5451 } | |
5452 }); | |
5453 Gestures.register({ | |
5454 name: 'tap', | |
5455 deps: [ | |
5456 'mousedown', | |
5457 'click', | |
5458 'touchstart', | |
5459 'touchend' | |
5460 ], | |
5461 flow: { | |
5462 start: [ | |
5463 'mousedown', | |
5464 'touchstart' | |
5465 ], | |
5466 end: [ | |
5467 'click', | |
5468 'touchend' | |
5469 ] | |
5470 }, | |
5471 emits: ['tap'], | |
5472 info: { | |
5473 x: NaN, | |
5474 y: NaN, | |
5475 prevent: false | |
5476 }, | |
5477 reset: function () { | |
5478 this.info.x = NaN; | |
5479 this.info.y = NaN; | |
5480 this.info.prevent = false; | |
5481 }, | |
5482 save: function (e) { | |
5483 this.info.x = e.clientX; | |
5484 this.info.y = e.clientY; | |
5485 }, | |
5486 mousedown: function (e) { | |
5487 if (hasLeftMouseButton(e)) { | |
5488 this.save(e); | |
5489 } | |
5490 }, | |
5491 click: function (e) { | |
5492 if (hasLeftMouseButton(e)) { | |
5493 this.forward(e); | |
5494 } | |
5495 }, | |
5496 touchstart: function (e) { | |
5497 this.save(e.changedTouches[0]); | |
5498 }, | |
5499 touchend: function (e) { | |
5500 this.forward(e.changedTouches[0]); | |
5501 }, | |
5502 forward: function (e) { | |
5503 var dx = Math.abs(e.clientX - this.info.x); | |
5504 var dy = Math.abs(e.clientY - this.info.y); | |
5505 var t = Gestures.findOriginalTarget(e); | |
5506 if (isNaN(dx) || isNaN(dy) || dx <= TAP_DISTANCE && dy <= TAP_DISTANCE || isSynt
heticClick(e)) { | |
5507 if (!this.info.prevent) { | |
5508 Gestures.fire(t, 'tap', { | |
5509 x: e.clientX, | |
5510 y: e.clientY, | |
5511 sourceEvent: e | |
5512 }); | |
5513 } | |
5514 } | |
5515 } | |
5516 }); | |
5517 var DIRECTION_MAP = { | |
5518 x: 'pan-x', | |
5519 y: 'pan-y', | |
5520 none: 'none', | |
5521 all: 'auto' | |
5522 }; | |
5523 Polymer.Base._addFeature({ | |
5524 _listen: function (node, eventName, handler) { | |
5525 if (Gestures.gestures[eventName]) { | |
5526 Gestures.add(node, eventName, handler); | |
5527 } else { | |
5528 node.addEventListener(eventName, handler); | |
5529 } | |
5530 }, | |
5531 _unlisten: function (node, eventName, handler) { | |
5532 if (Gestures.gestures[eventName]) { | |
5533 Gestures.remove(node, eventName, handler); | |
5534 } else { | |
5535 node.removeEventListener(eventName, handler); | |
5536 } | |
5537 }, | |
5538 setScrollDirection: function (direction, node) { | |
5539 node = node || this; | |
5540 Gestures.setTouchAction(node, DIRECTION_MAP[direction] || 'auto'); | |
5541 } | |
5542 }); | |
5543 Polymer.Gestures = Gestures; | |
5544 }()); | |
5545 Polymer.Async = { | |
5546 _currVal: 0, | |
5547 _lastVal: 0, | |
5548 _callbacks: [], | |
5549 _twiddleContent: 0, | |
5550 _twiddle: document.createTextNode(''), | |
5551 run: function (callback, waitTime) { | |
5552 if (waitTime > 0) { | |
5553 return ~setTimeout(callback, waitTime); | |
5554 } else { | |
5555 this._twiddle.textContent = this._twiddleContent++; | |
5556 this._callbacks.push(callback); | |
5557 return this._currVal++; | |
5558 } | |
5559 }, | |
5560 cancel: function (handle) { | |
5561 if (handle < 0) { | |
5562 clearTimeout(~handle); | |
5563 } else { | |
5564 var idx = handle - this._lastVal; | |
5565 if (idx >= 0) { | |
5566 if (!this._callbacks[idx]) { | |
5567 throw 'invalid async handle: ' + handle; | |
5568 } | |
5569 this._callbacks[idx] = null; | |
5570 } | |
5571 } | |
5572 }, | |
5573 _atEndOfMicrotask: function () { | |
5574 var len = this._callbacks.length; | |
5575 for (var i = 0; i < len; i++) { | |
5576 var cb = this._callbacks[i]; | |
5577 if (cb) { | |
5578 try { | |
5579 cb(); | |
5580 } catch (e) { | |
5581 i++; | |
5582 this._callbacks.splice(0, i); | |
5583 this._lastVal += i; | |
5584 this._twiddle.textContent = this._twiddleContent++; | |
5585 throw e; | |
5586 } | |
5587 } | |
5588 } | |
5589 this._callbacks.splice(0, len); | |
5590 this._lastVal += len; | |
5591 } | |
5592 }; | |
5593 new window.MutationObserver(function () { | |
5594 Polymer.Async._atEndOfMicrotask(); | |
5595 }).observe(Polymer.Async._twiddle, { characterData: true }); | |
5596 Polymer.Debounce = function () { | |
5597 var Async = Polymer.Async; | |
5598 var Debouncer = function (context) { | |
5599 this.context = context; | |
5600 var self = this; | |
5601 this.boundComplete = function () { | |
5602 self.complete(); | |
5603 }; | |
5604 }; | |
5605 Debouncer.prototype = { | |
5606 go: function (callback, wait) { | |
5607 var h; | |
5608 this.finish = function () { | |
5609 Async.cancel(h); | |
5610 }; | |
5611 h = Async.run(this.boundComplete, wait); | |
5612 this.callback = callback; | |
5613 }, | |
5614 stop: function () { | |
5615 if (this.finish) { | |
5616 this.finish(); | |
5617 this.finish = null; | |
5618 } | |
5619 }, | |
5620 complete: function () { | |
5621 if (this.finish) { | |
5622 this.stop(); | |
5623 this.callback.call(this.context); | |
5624 } | |
5625 } | |
5626 }; | |
5627 function debounce(debouncer, callback, wait) { | |
5628 if (debouncer) { | |
5629 debouncer.stop(); | |
5630 } else { | |
5631 debouncer = new Debouncer(this); | |
5632 } | |
5633 debouncer.go(callback, wait); | |
5634 return debouncer; | |
5635 } | |
5636 return debounce; | |
5637 }(); | |
5638 Polymer.Base._addFeature({ | |
5639 $$: function (slctr) { | |
5640 return Polymer.dom(this.root).querySelector(slctr); | |
5641 }, | |
5642 toggleClass: function (name, bool, node) { | |
5643 node = node || this; | |
5644 if (arguments.length == 1) { | |
5645 bool = !node.classList.contains(name); | |
5646 } | |
5647 if (bool) { | |
5648 Polymer.dom(node).classList.add(name); | |
5649 } else { | |
5650 Polymer.dom(node).classList.remove(name); | |
5651 } | |
5652 }, | |
5653 toggleAttribute: function (name, bool, node) { | |
5654 node = node || this; | |
5655 if (arguments.length == 1) { | |
5656 bool = !node.hasAttribute(name); | |
5657 } | |
5658 if (bool) { | |
5659 Polymer.dom(node).setAttribute(name, ''); | |
5660 } else { | |
5661 Polymer.dom(node).removeAttribute(name); | |
5662 } | |
5663 }, | |
5664 classFollows: function (name, toElement, fromElement) { | |
5665 if (fromElement) { | |
5666 Polymer.dom(fromElement).classList.remove(name); | |
5667 } | |
5668 if (toElement) { | |
5669 Polymer.dom(toElement).classList.add(name); | |
5670 } | |
5671 }, | |
5672 attributeFollows: function (name, toElement, fromElement) { | |
5673 if (fromElement) { | |
5674 Polymer.dom(fromElement).removeAttribute(name); | |
5675 } | |
5676 if (toElement) { | |
5677 Polymer.dom(toElement).setAttribute(name, ''); | |
5678 } | |
5679 }, | |
5680 getEffectiveChildNodes: function () { | |
5681 return Polymer.dom(this).getEffectiveChildNodes(); | |
5682 }, | |
5683 getEffectiveChildren: function () { | |
5684 var list = Polymer.dom(this).getEffectiveChildNodes(); | |
5685 return list.filter(function (n) { | |
5686 return n.nodeType === Node.ELEMENT_NODE; | |
5687 }); | |
5688 }, | |
5689 getEffectiveTextContent: function () { | |
5690 var cn = this.getEffectiveChildNodes(); | |
5691 var tc = []; | |
5692 for (var i = 0, c; c = cn[i]; i++) { | |
5693 if (c.nodeType !== Node.COMMENT_NODE) { | |
5694 tc.push(Polymer.dom(c).textContent); | |
5695 } | |
5696 } | |
5697 return tc.join(''); | |
5698 }, | |
5699 queryEffectiveChildren: function (slctr) { | |
5700 var e$ = Polymer.dom(this).queryDistributedElements(slctr); | |
5701 return e$ && e$[0]; | |
5702 }, | |
5703 queryAllEffectiveChildren: function (slctr) { | |
5704 return Polymer.dom(this).queryDistributedElements(slctr); | |
5705 }, | |
5706 getContentChildNodes: function (slctr) { | |
5707 var content = Polymer.dom(this.root).querySelector(slctr || 'content'); | |
5708 return content ? Polymer.dom(content).getDistributedNodes() : []; | |
5709 }, | |
5710 getContentChildren: function (slctr) { | |
5711 return this.getContentChildNodes(slctr).filter(function (n) { | |
5712 return n.nodeType === Node.ELEMENT_NODE; | |
5713 }); | |
5714 }, | |
5715 fire: function (type, detail, options) { | |
5716 options = options || Polymer.nob; | |
5717 var node = options.node || this; | |
5718 var detail = detail === null || detail === undefined ? {} : detail; | |
5719 var bubbles = options.bubbles === undefined ? true : options.bubbles; | |
5720 var cancelable = Boolean(options.cancelable); | |
5721 var useCache = options._useCache; | |
5722 var event = this._getEvent(type, bubbles, cancelable, useCache); | |
5723 event.detail = detail; | |
5724 if (useCache) { | |
5725 this.__eventCache[type] = null; | |
5726 } | |
5727 node.dispatchEvent(event); | |
5728 if (useCache) { | |
5729 this.__eventCache[type] = event; | |
5730 } | |
5731 return event; | |
5732 }, | |
5733 __eventCache: {}, | |
5734 _getEvent: function (type, bubbles, cancelable, useCache) { | |
5735 var event = useCache && this.__eventCache[type]; | |
5736 if (!event || (event.bubbles != bubbles || event.cancelable != cancelable)) { | |
5737 event = new Event(type, { | |
5738 bubbles: Boolean(bubbles), | |
5739 cancelable: cancelable | |
5740 }); | |
5741 } | |
5742 return event; | |
5743 }, | |
5744 async: function (callback, waitTime) { | |
5745 var self = this; | |
5746 return Polymer.Async.run(function () { | |
5747 callback.call(self); | |
5748 }, waitTime); | |
5749 }, | |
5750 cancelAsync: function (handle) { | |
5751 Polymer.Async.cancel(handle); | |
5752 }, | |
5753 arrayDelete: function (path, item) { | |
5754 var index; | |
5755 if (Array.isArray(path)) { | |
5756 index = path.indexOf(item); | |
5757 if (index >= 0) { | |
5758 return path.splice(index, 1); | |
5759 } | |
5760 } else { | |
5761 var arr = this._get(path); | |
5762 index = arr.indexOf(item); | |
5763 if (index >= 0) { | |
5764 return this.splice(path, index, 1); | |
5765 } | |
5766 } | |
5767 }, | |
5768 transform: function (transform, node) { | |
5769 node = node || this; | |
5770 node.style.webkitTransform = transform; | |
5771 node.style.transform = transform; | |
5772 }, | |
5773 translate3d: function (x, y, z, node) { | |
5774 node = node || this; | |
5775 this.transform('translate3d(' + x + ',' + y + ',' + z + ')', node); | |
5776 }, | |
5777 importHref: function (href, onload, onerror) { | |
5778 var l = document.createElement('link'); | |
5779 l.rel = 'import'; | |
5780 l.href = href; | |
5781 var self = this; | |
5782 if (onload) { | |
5783 l.onload = function (e) { | |
5784 return onload.call(self, e); | |
5785 }; | |
5786 } | |
5787 if (onerror) { | |
5788 l.onerror = function (e) { | |
5789 return onerror.call(self, e); | |
5790 }; | |
5791 } | |
5792 document.head.appendChild(l); | |
5793 return l; | |
5794 }, | |
5795 create: function (tag, props) { | |
5796 var elt = document.createElement(tag); | |
5797 if (props) { | |
5798 for (var n in props) { | |
5799 elt[n] = props[n]; | |
5800 } | |
5801 } | |
5802 return elt; | |
5803 }, | |
5804 isLightDescendant: function (node) { | |
5805 return this !== node && this.contains(node) && Polymer.dom(this).getOwnerRoot()
=== Polymer.dom(node).getOwnerRoot(); | |
5806 }, | |
5807 isLocalDescendant: function (node) { | |
5808 return this.root === Polymer.dom(node).getOwnerRoot(); | |
5809 } | |
5810 }); | |
5811 Polymer.Bind = { | |
5812 _dataEventCache: {}, | |
5813 prepareModel: function (model) { | |
5814 Polymer.Base.mixin(model, this._modelApi); | |
5815 }, | |
5816 _modelApi: { | |
5817 _notifyChange: function (source, event, value) { | |
5818 value = value === undefined ? this[source] : value; | |
5819 event = event || Polymer.CaseMap.camelToDashCase(source) + '-changed'; | |
5820 this.fire(event, { value: value }, { | |
5821 bubbles: false, | |
5822 cancelable: false, | |
5823 _useCache: true | |
5824 }); | |
5825 }, | |
5826 _propertySetter: function (property, value, effects, fromAbove) { | |
5827 var old = this.__data__[property]; | |
5828 if (old !== value && (old === old || value === value)) { | |
5829 this.__data__[property] = value; | |
5830 if (typeof value == 'object') { | |
5831 this._clearPath(property); | |
5832 } | |
5833 if (this._propertyChanged) { | |
5834 this._propertyChanged(property, value, old); | |
5835 } | |
5836 if (effects) { | |
5837 this._effectEffects(property, value, effects, old, fromAbove); | |
5838 } | |
5839 } | |
5840 return old; | |
5841 }, | |
5842 __setProperty: function (property, value, quiet, node) { | |
5843 node = node || this; | |
5844 var effects = node._propertyEffects && node._propertyEffects[property]; | |
5845 if (effects) { | |
5846 node._propertySetter(property, value, effects, quiet); | |
5847 } else { | |
5848 node[property] = value; | |
5849 } | |
5850 }, | |
5851 _effectEffects: function (property, value, effects, old, fromAbove) { | |
5852 for (var i = 0, l = effects.length, fx; i < l && (fx = effects[i]); i++) { | |
5853 fx.fn.call(this, property, value, fx.effect, old, fromAbove); | |
5854 } | |
5855 }, | |
5856 _clearPath: function (path) { | |
5857 for (var prop in this.__data__) { | |
5858 if (prop.indexOf(path + '.') === 0) { | |
5859 this.__data__[prop] = undefined; | |
5860 } | |
5861 } | |
5862 } | |
5863 }, | |
5864 ensurePropertyEffects: function (model, property) { | |
5865 if (!model._propertyEffects) { | |
5866 model._propertyEffects = {}; | |
5867 } | |
5868 var fx = model._propertyEffects[property]; | |
5869 if (!fx) { | |
5870 fx = model._propertyEffects[property] = []; | |
5871 } | |
5872 return fx; | |
5873 }, | |
5874 addPropertyEffect: function (model, property, kind, effect) { | |
5875 var fx = this.ensurePropertyEffects(model, property); | |
5876 var propEffect = { | |
5877 kind: kind, | |
5878 effect: effect, | |
5879 fn: Polymer.Bind['_' + kind + 'Effect'] | |
5880 }; | |
5881 fx.push(propEffect); | |
5882 return propEffect; | |
5883 }, | |
5884 createBindings: function (model) { | |
5885 var fx$ = model._propertyEffects; | |
5886 if (fx$) { | |
5887 for (var n in fx$) { | |
5888 var fx = fx$[n]; | |
5889 fx.sort(this._sortPropertyEffects); | |
5890 this._createAccessors(model, n, fx); | |
5891 } | |
5892 } | |
5893 }, | |
5894 _sortPropertyEffects: function () { | |
5895 var EFFECT_ORDER = { | |
5896 'compute': 0, | |
5897 'annotation': 1, | |
5898 'computedAnnotation': 2, | |
5899 'reflect': 3, | |
5900 'notify': 4, | |
5901 'observer': 5, | |
5902 'complexObserver': 6, | |
5903 'function': 7 | |
5904 }; | |
5905 return function (a, b) { | |
5906 return EFFECT_ORDER[a.kind] - EFFECT_ORDER[b.kind]; | |
5907 }; | |
5908 }(), | |
5909 _createAccessors: function (model, property, effects) { | |
5910 var defun = { | |
5911 get: function () { | |
5912 return this.__data__[property]; | |
5913 } | |
5914 }; | |
5915 var setter = function (value) { | |
5916 this._propertySetter(property, value, effects); | |
5917 }; | |
5918 var info = model.getPropertyInfo && model.getPropertyInfo(property); | |
5919 if (info && info.readOnly) { | |
5920 if (!info.computed) { | |
5921 model['_set' + this.upper(property)] = setter; | |
5922 } | |
5923 } else { | |
5924 defun.set = setter; | |
5925 } | |
5926 Object.defineProperty(model, property, defun); | |
5927 }, | |
5928 upper: function (name) { | |
5929 return name[0].toUpperCase() + name.substring(1); | |
5930 }, | |
5931 _addAnnotatedListener: function (model, index, property, path, event) { | |
5932 if (!model._bindListeners) { | |
5933 model._bindListeners = []; | |
5934 } | |
5935 var fn = this._notedListenerFactory(property, path, this._isStructured(path)); | |
5936 var eventName = event || Polymer.CaseMap.camelToDashCase(property) + '-changed'; | |
5937 model._bindListeners.push({ | |
5938 index: index, | |
5939 property: property, | |
5940 path: path, | |
5941 changedFn: fn, | |
5942 event: eventName | |
5943 }); | |
5944 }, | |
5945 _isStructured: function (path) { | |
5946 return path.indexOf('.') > 0; | |
5947 }, | |
5948 _isEventBogus: function (e, target) { | |
5949 return e.path && e.path[0] !== target; | |
5950 }, | |
5951 _notedListenerFactory: function (property, path, isStructured) { | |
5952 return function (target, value, targetPath) { | |
5953 if (targetPath) { | |
5954 this._notifyPath(this._fixPath(path, property, targetPath), value); | |
5955 } else { | |
5956 value = target[property]; | |
5957 if (!isStructured) { | |
5958 this[path] = value; | |
5959 } else { | |
5960 if (this.__data__[path] != value) { | |
5961 this.set(path, value); | |
5962 } | |
5963 } | |
5964 } | |
5965 }; | |
5966 }, | |
5967 prepareInstance: function (inst) { | |
5968 inst.__data__ = Object.create(null); | |
5969 }, | |
5970 setupBindListeners: function (inst) { | |
5971 var b$ = inst._bindListeners; | |
5972 for (var i = 0, l = b$.length, info; i < l && (info = b$[i]); i++) { | |
5973 var node = inst._nodes[info.index]; | |
5974 this._addNotifyListener(node, inst, info.event, info.changedFn); | |
5975 } | |
5976 ; | |
5977 }, | |
5978 _addNotifyListener: function (element, context, event, changedFn) { | |
5979 element.addEventListener(event, function (e) { | |
5980 return context._notifyListener(changedFn, e); | |
5981 }); | |
5982 } | |
5983 }; | |
5984 Polymer.Base.extend(Polymer.Bind, { | |
5985 _shouldAddListener: function (effect) { | |
5986 return effect.name && effect.kind != 'attribute' && effect.kind != 'text' && !ef
fect.isCompound && effect.parts[0].mode === '{' && !effect.parts[0].negate; | |
5987 }, | |
5988 _annotationEffect: function (source, value, effect) { | |
5989 if (source != effect.value) { | |
5990 value = this._get(effect.value); | |
5991 this.__data__[effect.value] = value; | |
5992 } | |
5993 var calc = effect.negate ? !value : value; | |
5994 if (!effect.customEvent || this._nodes[effect.index][effect.name] !== calc) { | |
5995 return this._applyEffectValue(effect, calc); | |
5996 } | |
5997 }, | |
5998 _reflectEffect: function (source, value, effect) { | |
5999 this.reflectPropertyToAttribute(source, effect.attribute, value); | |
6000 }, | |
6001 _notifyEffect: function (source, value, effect, old, fromAbove) { | |
6002 if (!fromAbove) { | |
6003 this._notifyChange(source, effect.event, value); | |
6004 } | |
6005 }, | |
6006 _functionEffect: function (source, value, fn, old, fromAbove) { | |
6007 fn.call(this, source, value, old, fromAbove); | |
6008 }, | |
6009 _observerEffect: function (source, value, effect, old) { | |
6010 var fn = this[effect.method]; | |
6011 if (fn) { | |
6012 fn.call(this, value, old); | |
6013 } else { | |
6014 this._warn(this._logf('_observerEffect', 'observer method `' + effect.method + '
` not defined')); | |
6015 } | |
6016 }, | |
6017 _complexObserverEffect: function (source, value, effect) { | |
6018 var fn = this[effect.method]; | |
6019 if (fn) { | |
6020 var args = Polymer.Bind._marshalArgs(this.__data__, effect, source, value); | |
6021 if (args) { | |
6022 fn.apply(this, args); | |
6023 } | |
6024 } else { | |
6025 this._warn(this._logf('_complexObserverEffect', 'observer method `' + effect.met
hod + '` not defined')); | |
6026 } | |
6027 }, | |
6028 _computeEffect: function (source, value, effect) { | |
6029 var args = Polymer.Bind._marshalArgs(this.__data__, effect, source, value); | |
6030 if (args) { | |
6031 var fn = this[effect.method]; | |
6032 if (fn) { | |
6033 this.__setProperty(effect.name, fn.apply(this, args)); | |
6034 } else { | |
6035 this._warn(this._logf('_computeEffect', 'compute method `' + effect.method + '`
not defined')); | |
6036 } | |
6037 } | |
6038 }, | |
6039 _annotatedComputationEffect: function (source, value, effect) { | |
6040 var computedHost = this._rootDataHost || this; | |
6041 var fn = computedHost[effect.method]; | |
6042 if (fn) { | |
6043 var args = Polymer.Bind._marshalArgs(this.__data__, effect, source, value); | |
6044 if (args) { | |
6045 var computedvalue = fn.apply(computedHost, args); | |
6046 if (effect.negate) { | |
6047 computedvalue = !computedvalue; | |
6048 } | |
6049 this._applyEffectValue(effect, computedvalue); | |
6050 } | |
6051 } else { | |
6052 computedHost._warn(computedHost._logf('_annotatedComputationEffect', 'compute me
thod `' + effect.method + '` not defined')); | |
6053 } | |
6054 }, | |
6055 _marshalArgs: function (model, effect, path, value) { | |
6056 var values = []; | |
6057 var args = effect.args; | |
6058 for (var i = 0, l = args.length; i < l; i++) { | |
6059 var arg = args[i]; | |
6060 var name = arg.name; | |
6061 var v; | |
6062 if (arg.literal) { | |
6063 v = arg.value; | |
6064 } else if (arg.structured) { | |
6065 v = Polymer.Base._get(name, model); | |
6066 } else { | |
6067 v = model[name]; | |
6068 } | |
6069 if (args.length > 1 && v === undefined) { | |
6070 return; | |
6071 } | |
6072 if (arg.wildcard) { | |
6073 var baseChanged = name.indexOf(path + '.') === 0; | |
6074 var matches = effect.trigger.name.indexOf(name) === 0 && !baseChanged; | |
6075 values[i] = { | |
6076 path: matches ? path : name, | |
6077 value: matches ? value : v, | |
6078 base: v | |
6079 }; | |
6080 } else { | |
6081 values[i] = v; | |
6082 } | |
6083 } | |
6084 return values; | |
6085 } | |
6086 }); | |
6087 Polymer.Base._addFeature({ | |
6088 _addPropertyEffect: function (property, kind, effect) { | |
6089 var prop = Polymer.Bind.addPropertyEffect(this, property, kind, effect); | |
6090 prop.pathFn = this['_' + prop.kind + 'PathEffect']; | |
6091 }, | |
6092 _prepEffects: function () { | |
6093 Polymer.Bind.prepareModel(this); | |
6094 this._addAnnotationEffects(this._notes); | |
6095 }, | |
6096 _prepBindings: function () { | |
6097 Polymer.Bind.createBindings(this); | |
6098 }, | |
6099 _addPropertyEffects: function (properties) { | |
6100 if (properties) { | |
6101 for (var p in properties) { | |
6102 var prop = properties[p]; | |
6103 if (prop.observer) { | |
6104 this._addObserverEffect(p, prop.observer); | |
6105 } | |
6106 if (prop.computed) { | |
6107 prop.readOnly = true; | |
6108 this._addComputedEffect(p, prop.computed); | |
6109 } | |
6110 if (prop.notify) { | |
6111 this._addPropertyEffect(p, 'notify', { event: Polymer.CaseMap.camelToDashCase(p)
+ '-changed' }); | |
6112 } | |
6113 if (prop.reflectToAttribute) { | |
6114 this._addPropertyEffect(p, 'reflect', { attribute: Polymer.CaseMap.camelToDashCa
se(p) }); | |
6115 } | |
6116 if (prop.readOnly) { | |
6117 Polymer.Bind.ensurePropertyEffects(this, p); | |
6118 } | |
6119 } | |
6120 } | |
6121 }, | |
6122 _addComputedEffect: function (name, expression) { | |
6123 var sig = this._parseMethod(expression); | |
6124 for (var i = 0, arg; i < sig.args.length && (arg = sig.args[i]); i++) { | |
6125 this._addPropertyEffect(arg.model, 'compute', { | |
6126 method: sig.method, | |
6127 args: sig.args, | |
6128 trigger: arg, | |
6129 name: name | |
6130 }); | |
6131 } | |
6132 }, | |
6133 _addObserverEffect: function (property, observer) { | |
6134 this._addPropertyEffect(property, 'observer', { | |
6135 method: observer, | |
6136 property: property | |
6137 }); | |
6138 }, | |
6139 _addComplexObserverEffects: function (observers) { | |
6140 if (observers) { | |
6141 for (var i = 0, o; i < observers.length && (o = observers[i]); i++) { | |
6142 this._addComplexObserverEffect(o); | |
6143 } | |
6144 } | |
6145 }, | |
6146 _addComplexObserverEffect: function (observer) { | |
6147 var sig = this._parseMethod(observer); | |
6148 for (var i = 0, arg; i < sig.args.length && (arg = sig.args[i]); i++) { | |
6149 this._addPropertyEffect(arg.model, 'complexObserver', { | |
6150 method: sig.method, | |
6151 args: sig.args, | |
6152 trigger: arg | |
6153 }); | |
6154 } | |
6155 }, | |
6156 _addAnnotationEffects: function (notes) { | |
6157 for (var i = 0, note; i < notes.length && (note = notes[i]); i++) { | |
6158 var b$ = note.bindings; | |
6159 for (var j = 0, binding; j < b$.length && (binding = b$[j]); j++) { | |
6160 this._addAnnotationEffect(binding, i); | |
6161 } | |
6162 } | |
6163 }, | |
6164 _addAnnotationEffect: function (note, index) { | |
6165 if (Polymer.Bind._shouldAddListener(note)) { | |
6166 Polymer.Bind._addAnnotatedListener(this, index, note.name, note.parts[0].value,
note.parts[0].event); | |
6167 } | |
6168 for (var i = 0; i < note.parts.length; i++) { | |
6169 var part = note.parts[i]; | |
6170 if (part.signature) { | |
6171 this._addAnnotatedComputationEffect(note, part, index); | |
6172 } else if (!part.literal) { | |
6173 this._addPropertyEffect(part.model, 'annotation', { | |
6174 kind: note.kind, | |
6175 index: index, | |
6176 name: note.name, | |
6177 value: part.value, | |
6178 isCompound: note.isCompound, | |
6179 compoundIndex: part.compoundIndex, | |
6180 event: part.event, | |
6181 customEvent: part.customEvent, | |
6182 negate: part.negate | |
6183 }); | |
6184 } | |
6185 } | |
6186 }, | |
6187 _addAnnotatedComputationEffect: function (note, part, index) { | |
6188 var sig = part.signature; | |
6189 if (sig.static) { | |
6190 this.__addAnnotatedComputationEffect('__static__', index, note, part, null); | |
6191 } else { | |
6192 for (var i = 0, arg; i < sig.args.length && (arg = sig.args[i]); i++) { | |
6193 if (!arg.literal) { | |
6194 this.__addAnnotatedComputationEffect(arg.model, index, note, part, arg); | |
6195 } | |
6196 } | |
6197 } | |
6198 }, | |
6199 __addAnnotatedComputationEffect: function (property, index, note, part, trigger)
{ | |
6200 this._addPropertyEffect(property, 'annotatedComputation', { | |
6201 index: index, | |
6202 isCompound: note.isCompound, | |
6203 compoundIndex: part.compoundIndex, | |
6204 kind: note.kind, | |
6205 name: note.name, | |
6206 negate: part.negate, | |
6207 method: part.signature.method, | |
6208 args: part.signature.args, | |
6209 trigger: trigger | |
6210 }); | |
6211 }, | |
6212 _parseMethod: function (expression) { | |
6213 var m = expression.match(/([^\s]+)\((.*)\)/); | |
6214 if (m) { | |
6215 var sig = { | |
6216 method: m[1], | |
6217 static: true | |
6218 }; | |
6219 if (m[2].trim()) { | |
6220 var args = m[2].replace(/\\,/g, ',').split(','); | |
6221 return this._parseArgs(args, sig); | |
6222 } else { | |
6223 sig.args = Polymer.nar; | |
6224 return sig; | |
6225 } | |
6226 } | |
6227 }, | |
6228 _parseArgs: function (argList, sig) { | |
6229 sig.args = argList.map(function (rawArg) { | |
6230 var arg = this._parseArg(rawArg); | |
6231 if (!arg.literal) { | |
6232 sig.static = false; | |
6233 } | |
6234 return arg; | |
6235 }, this); | |
6236 return sig; | |
6237 }, | |
6238 _parseArg: function (rawArg) { | |
6239 var arg = rawArg.trim().replace(/,/g, ',').replace(/\\(.)/g, '$1'); | |
6240 var a = { | |
6241 name: arg, | |
6242 model: this._modelForPath(arg) | |
6243 }; | |
6244 var fc = arg[0]; | |
6245 if (fc === '-') { | |
6246 fc = arg[1]; | |
6247 } | |
6248 if (fc >= '0' && fc <= '9') { | |
6249 fc = '#'; | |
6250 } | |
6251 switch (fc) { | |
6252 case '\'': | |
6253 case '"': | |
6254 a.value = arg.slice(1, -1); | |
6255 a.literal = true; | |
6256 break; | |
6257 case '#': | |
6258 a.value = Number(arg); | |
6259 a.literal = true; | |
6260 break; | |
6261 } | |
6262 if (!a.literal) { | |
6263 a.structured = arg.indexOf('.') > 0; | |
6264 if (a.structured) { | |
6265 a.wildcard = arg.slice(-2) == '.*'; | |
6266 if (a.wildcard) { | |
6267 a.name = arg.slice(0, -2); | |
6268 } | |
6269 } | |
6270 } | |
6271 return a; | |
6272 }, | |
6273 _marshalInstanceEffects: function () { | |
6274 Polymer.Bind.prepareInstance(this); | |
6275 if (this._bindListeners) { | |
6276 Polymer.Bind.setupBindListeners(this); | |
6277 } | |
6278 }, | |
6279 _applyEffectValue: function (info, value) { | |
6280 var node = this._nodes[info.index]; | |
6281 var property = info.name; | |
6282 if (info.isCompound) { | |
6283 var storage = node.__compoundStorage__[property]; | |
6284 storage[info.compoundIndex] = value; | |
6285 value = storage.join(''); | |
6286 } | |
6287 if (info.kind == 'attribute') { | |
6288 this.serializeValueToAttribute(value, property, node); | |
6289 } else { | |
6290 if (property === 'className') { | |
6291 value = this._scopeElementClass(node, value); | |
6292 } | |
6293 if (property === 'textContent' || node.localName == 'input' && property == 'valu
e') { | |
6294 value = value == undefined ? '' : value; | |
6295 } | |
6296 var pinfo; | |
6297 if (!node._propertyInfo || !(pinfo = node._propertyInfo[property]) || !pinfo.rea
dOnly) { | |
6298 this.__setProperty(property, value, true, node); | |
6299 } | |
6300 } | |
6301 }, | |
6302 _executeStaticEffects: function () { | |
6303 if (this._propertyEffects && this._propertyEffects.__static__) { | |
6304 this._effectEffects('__static__', null, this._propertyEffects.__static__); | |
6305 } | |
6306 } | |
6307 }); | |
6308 Polymer.Base._addFeature({ | |
6309 _setupConfigure: function (initialConfig) { | |
6310 this._config = {}; | |
6311 this._handlers = []; | |
6312 if (initialConfig) { | |
6313 for (var i in initialConfig) { | |
6314 if (initialConfig[i] !== undefined) { | |
6315 this._config[i] = initialConfig[i]; | |
6316 } | |
6317 } | |
6318 } | |
6319 }, | |
6320 _marshalAttributes: function () { | |
6321 this._takeAttributesToModel(this._config); | |
6322 }, | |
6323 _attributeChangedImpl: function (name) { | |
6324 var model = this._clientsReadied ? this : this._config; | |
6325 this._setAttributeToProperty(model, name); | |
6326 }, | |
6327 _configValue: function (name, value) { | |
6328 var info = this._propertyInfo[name]; | |
6329 if (!info || !info.readOnly) { | |
6330 this._config[name] = value; | |
6331 } | |
6332 }, | |
6333 _beforeClientsReady: function () { | |
6334 this._configure(); | |
6335 }, | |
6336 _configure: function () { | |
6337 this._configureAnnotationReferences(); | |
6338 this._aboveConfig = this.mixin({}, this._config); | |
6339 var config = {}; | |
6340 for (var i = 0; i < this.behaviors.length; i++) { | |
6341 this._configureProperties(this.behaviors[i].properties, config); | |
6342 } | |
6343 this._configureProperties(this.properties, config); | |
6344 this.mixin(config, this._aboveConfig); | |
6345 this._config = config; | |
6346 if (this._clients && this._clients.length) { | |
6347 this._distributeConfig(this._config); | |
6348 } | |
6349 }, | |
6350 _configureProperties: function (properties, config) { | |
6351 for (var i in properties) { | |
6352 var c = properties[i]; | |
6353 if (c.value !== undefined) { | |
6354 var value = c.value; | |
6355 if (typeof value == 'function') { | |
6356 value = value.call(this, this._config); | |
6357 } | |
6358 config[i] = value; | |
6359 } | |
6360 } | |
6361 }, | |
6362 _distributeConfig: function (config) { | |
6363 var fx$ = this._propertyEffects; | |
6364 if (fx$) { | |
6365 for (var p in config) { | |
6366 var fx = fx$[p]; | |
6367 if (fx) { | |
6368 for (var i = 0, l = fx.length, x; i < l && (x = fx[i]); i++) { | |
6369 if (x.kind === 'annotation' && !x.isCompound) { | |
6370 var node = this._nodes[x.effect.index]; | |
6371 if (node._configValue) { | |
6372 var value = p === x.effect.value ? config[p] : this._get(x.effect.value, config)
; | |
6373 node._configValue(x.effect.name, value); | |
6374 } | |
6375 } | |
6376 } | |
6377 } | |
6378 } | |
6379 } | |
6380 }, | |
6381 _afterClientsReady: function () { | |
6382 this._executeStaticEffects(); | |
6383 this._applyConfig(this._config, this._aboveConfig); | |
6384 this._flushHandlers(); | |
6385 }, | |
6386 _applyConfig: function (config, aboveConfig) { | |
6387 for (var n in config) { | |
6388 if (this[n] === undefined) { | |
6389 this.__setProperty(n, config[n], n in aboveConfig); | |
6390 } | |
6391 } | |
6392 }, | |
6393 _notifyListener: function (fn, e) { | |
6394 if (!Polymer.Bind._isEventBogus(e, e.target)) { | |
6395 var value, path; | |
6396 if (e.detail) { | |
6397 value = e.detail.value; | |
6398 path = e.detail.path; | |
6399 } | |
6400 if (!this._clientsReadied) { | |
6401 this._queueHandler([ | |
6402 fn, | |
6403 e.target, | |
6404 value, | |
6405 path | |
6406 ]); | |
6407 } else { | |
6408 return fn.call(this, e.target, value, path); | |
6409 } | |
6410 } | |
6411 }, | |
6412 _queueHandler: function (args) { | |
6413 this._handlers.push(args); | |
6414 }, | |
6415 _flushHandlers: function () { | |
6416 var h$ = this._handlers; | |
6417 for (var i = 0, l = h$.length, h; i < l && (h = h$[i]); i++) { | |
6418 h[0].call(this, h[1], h[2], h[3]); | |
6419 } | |
6420 this._handlers = []; | |
6421 } | |
6422 }); | |
6423 (function () { | |
6424 'use strict'; | |
6425 Polymer.Base._addFeature({ | |
6426 notifyPath: function (path, value, fromAbove) { | |
6427 var info = {}; | |
6428 this._get(path, this, info); | |
6429 this._notifyPath(info.path, value, fromAbove); | |
6430 }, | |
6431 _notifyPath: function (path, value, fromAbove) { | |
6432 var old = this._propertySetter(path, value); | |
6433 if (old !== value && (old === old || value === value)) { | |
6434 this._pathEffector(path, value); | |
6435 if (!fromAbove) { | |
6436 this._notifyPathUp(path, value); | |
6437 } | |
6438 return true; | |
6439 } | |
6440 }, | |
6441 _getPathParts: function (path) { | |
6442 if (Array.isArray(path)) { | |
6443 var parts = []; | |
6444 for (var i = 0; i < path.length; i++) { | |
6445 var args = path[i].toString().split('.'); | |
6446 for (var j = 0; j < args.length; j++) { | |
6447 parts.push(args[j]); | |
6448 } | |
6449 } | |
6450 return parts; | |
6451 } else { | |
6452 return path.toString().split('.'); | |
6453 } | |
6454 }, | |
6455 set: function (path, value, root) { | |
6456 var prop = root || this; | |
6457 var parts = this._getPathParts(path); | |
6458 var array; | |
6459 var last = parts[parts.length - 1]; | |
6460 if (parts.length > 1) { | |
6461 for (var i = 0; i < parts.length - 1; i++) { | |
6462 var part = parts[i]; | |
6463 if (array && part[0] == '#') { | |
6464 prop = Polymer.Collection.get(array).getItem(part); | |
6465 } else { | |
6466 prop = prop[part]; | |
6467 if (array && parseInt(part, 10) == part) { | |
6468 parts[i] = Polymer.Collection.get(array).getKey(prop); | |
6469 } | |
6470 } | |
6471 if (!prop) { | |
6472 return; | |
6473 } | |
6474 array = Array.isArray(prop) ? prop : null; | |
6475 } | |
6476 if (array) { | |
6477 var coll = Polymer.Collection.get(array); | |
6478 if (last[0] == '#') { | |
6479 var key = last; | |
6480 var old = coll.getItem(key); | |
6481 last = array.indexOf(old); | |
6482 coll.setItem(key, value); | |
6483 } else if (parseInt(last, 10) == last) { | |
6484 var old = prop[last]; | |
6485 var key = coll.getKey(old); | |
6486 parts[i] = key; | |
6487 coll.setItem(key, value); | |
6488 } | |
6489 } | |
6490 prop[last] = value; | |
6491 if (!root) { | |
6492 this._notifyPath(parts.join('.'), value); | |
6493 } | |
6494 } else { | |
6495 prop[path] = value; | |
6496 } | |
6497 }, | |
6498 get: function (path, root) { | |
6499 return this._get(path, root); | |
6500 }, | |
6501 _get: function (path, root, info) { | |
6502 var prop = root || this; | |
6503 var parts = this._getPathParts(path); | |
6504 var array; | |
6505 for (var i = 0; i < parts.length; i++) { | |
6506 if (!prop) { | |
6507 return; | |
6508 } | |
6509 var part = parts[i]; | |
6510 if (array && part[0] == '#') { | |
6511 prop = Polymer.Collection.get(array).getItem(part); | |
6512 } else { | |
6513 prop = prop[part]; | |
6514 if (info && array && parseInt(part, 10) == part) { | |
6515 parts[i] = Polymer.Collection.get(array).getKey(prop); | |
6516 } | |
6517 } | |
6518 array = Array.isArray(prop) ? prop : null; | |
6519 } | |
6520 if (info) { | |
6521 info.path = parts.join('.'); | |
6522 } | |
6523 return prop; | |
6524 }, | |
6525 _pathEffector: function (path, value) { | |
6526 var model = this._modelForPath(path); | |
6527 var fx$ = this._propertyEffects && this._propertyEffects[model]; | |
6528 if (fx$) { | |
6529 for (var i = 0, fx; i < fx$.length && (fx = fx$[i]); i++) { | |
6530 var fxFn = fx.pathFn; | |
6531 if (fxFn) { | |
6532 fxFn.call(this, path, value, fx.effect); | |
6533 } | |
6534 } | |
6535 } | |
6536 if (this._boundPaths) { | |
6537 this._notifyBoundPaths(path, value); | |
6538 } | |
6539 }, | |
6540 _annotationPathEffect: function (path, value, effect) { | |
6541 if (effect.value === path || effect.value.indexOf(path + '.') === 0) { | |
6542 Polymer.Bind._annotationEffect.call(this, path, value, effect); | |
6543 } else if (path.indexOf(effect.value + '.') === 0 && !effect.negate) { | |
6544 var node = this._nodes[effect.index]; | |
6545 if (node && node._notifyPath) { | |
6546 var p = this._fixPath(effect.name, effect.value, path); | |
6547 node._notifyPath(p, value, true); | |
6548 } | |
6549 } | |
6550 }, | |
6551 _complexObserverPathEffect: function (path, value, effect) { | |
6552 if (this._pathMatchesEffect(path, effect)) { | |
6553 Polymer.Bind._complexObserverEffect.call(this, path, value, effect); | |
6554 } | |
6555 }, | |
6556 _computePathEffect: function (path, value, effect) { | |
6557 if (this._pathMatchesEffect(path, effect)) { | |
6558 Polymer.Bind._computeEffect.call(this, path, value, effect); | |
6559 } | |
6560 }, | |
6561 _annotatedComputationPathEffect: function (path, value, effect) { | |
6562 if (this._pathMatchesEffect(path, effect)) { | |
6563 Polymer.Bind._annotatedComputationEffect.call(this, path, value, effect); | |
6564 } | |
6565 }, | |
6566 _pathMatchesEffect: function (path, effect) { | |
6567 var effectArg = effect.trigger.name; | |
6568 return effectArg == path || effectArg.indexOf(path + '.') === 0 || effect.trigge
r.wildcard && path.indexOf(effectArg) === 0; | |
6569 }, | |
6570 linkPaths: function (to, from) { | |
6571 this._boundPaths = this._boundPaths || {}; | |
6572 if (from) { | |
6573 this._boundPaths[to] = from; | |
6574 } else { | |
6575 this.unlinkPaths(to); | |
6576 } | |
6577 }, | |
6578 unlinkPaths: function (path) { | |
6579 if (this._boundPaths) { | |
6580 delete this._boundPaths[path]; | |
6581 } | |
6582 }, | |
6583 _notifyBoundPaths: function (path, value) { | |
6584 for (var a in this._boundPaths) { | |
6585 var b = this._boundPaths[a]; | |
6586 if (path.indexOf(a + '.') == 0) { | |
6587 this._notifyPath(this._fixPath(b, a, path), value); | |
6588 } else if (path.indexOf(b + '.') == 0) { | |
6589 this._notifyPath(this._fixPath(a, b, path), value); | |
6590 } | |
6591 } | |
6592 }, | |
6593 _fixPath: function (property, root, path) { | |
6594 return property + path.slice(root.length); | |
6595 }, | |
6596 _notifyPathUp: function (path, value) { | |
6597 var rootName = this._modelForPath(path); | |
6598 var dashCaseName = Polymer.CaseMap.camelToDashCase(rootName); | |
6599 var eventName = dashCaseName + this._EVENT_CHANGED; | |
6600 this.fire(eventName, { | |
6601 path: path, | |
6602 value: value | |
6603 }, { | |
6604 bubbles: false, | |
6605 _useCache: true | |
6606 }); | |
6607 }, | |
6608 _modelForPath: function (path) { | |
6609 var dot = path.indexOf('.'); | |
6610 return dot < 0 ? path : path.slice(0, dot); | |
6611 }, | |
6612 _EVENT_CHANGED: '-changed', | |
6613 notifySplices: function (path, splices) { | |
6614 var info = {}; | |
6615 var array = this._get(path, this, info); | |
6616 this._notifySplices(array, info.path, splices); | |
6617 }, | |
6618 _notifySplices: function (array, path, splices) { | |
6619 var change = { | |
6620 keySplices: Polymer.Collection.applySplices(array, splices), | |
6621 indexSplices: splices | |
6622 }; | |
6623 if (!array.hasOwnProperty('splices')) { | |
6624 Object.defineProperty(array, 'splices', { | |
6625 configurable: true, | |
6626 writable: true | |
6627 }); | |
6628 } | |
6629 array.splices = change; | |
6630 this._notifyPath(path + '.splices', change); | |
6631 this._notifyPath(path + '.length', array.length); | |
6632 change.keySplices = null; | |
6633 change.indexSplices = null; | |
6634 }, | |
6635 _notifySplice: function (array, path, index, added, removed) { | |
6636 this._notifySplices(array, path, [{ | |
6637 index: index, | |
6638 addedCount: added, | |
6639 removed: removed, | |
6640 object: array, | |
6641 type: 'splice' | |
6642 }]); | |
6643 }, | |
6644 push: function (path) { | |
6645 var info = {}; | |
6646 var array = this._get(path, this, info); | |
6647 var args = Array.prototype.slice.call(arguments, 1); | |
6648 var len = array.length; | |
6649 var ret = array.push.apply(array, args); | |
6650 if (args.length) { | |
6651 this._notifySplice(array, info.path, len, args.length, []); | |
6652 } | |
6653 return ret; | |
6654 }, | |
6655 pop: function (path) { | |
6656 var info = {}; | |
6657 var array = this._get(path, this, info); | |
6658 var hadLength = Boolean(array.length); | |
6659 var args = Array.prototype.slice.call(arguments, 1); | |
6660 var ret = array.pop.apply(array, args); | |
6661 if (hadLength) { | |
6662 this._notifySplice(array, info.path, array.length, 0, [ret]); | |
6663 } | |
6664 return ret; | |
6665 }, | |
6666 splice: function (path, start, deleteCount) { | |
6667 var info = {}; | |
6668 var array = this._get(path, this, info); | |
6669 if (start < 0) { | |
6670 start = array.length - Math.floor(-start); | |
6671 } else { | |
6672 start = Math.floor(start); | |
6673 } | |
6674 if (!start) { | |
6675 start = 0; | |
6676 } | |
6677 var args = Array.prototype.slice.call(arguments, 1); | |
6678 var ret = array.splice.apply(array, args); | |
6679 var addedCount = Math.max(args.length - 2, 0); | |
6680 if (addedCount || ret.length) { | |
6681 this._notifySplice(array, info.path, start, addedCount, ret); | |
6682 } | |
6683 return ret; | |
6684 }, | |
6685 shift: function (path) { | |
6686 var info = {}; | |
6687 var array = this._get(path, this, info); | |
6688 var hadLength = Boolean(array.length); | |
6689 var args = Array.prototype.slice.call(arguments, 1); | |
6690 var ret = array.shift.apply(array, args); | |
6691 if (hadLength) { | |
6692 this._notifySplice(array, info.path, 0, 0, [ret]); | |
6693 } | |
6694 return ret; | |
6695 }, | |
6696 unshift: function (path) { | |
6697 var info = {}; | |
6698 var array = this._get(path, this, info); | |
6699 var args = Array.prototype.slice.call(arguments, 1); | |
6700 var ret = array.unshift.apply(array, args); | |
6701 if (args.length) { | |
6702 this._notifySplice(array, info.path, 0, args.length, []); | |
6703 } | |
6704 return ret; | |
6705 }, | |
6706 prepareModelNotifyPath: function (model) { | |
6707 this.mixin(model, { | |
6708 fire: Polymer.Base.fire, | |
6709 _getEvent: Polymer.Base._getEvent, | |
6710 __eventCache: Polymer.Base.__eventCache, | |
6711 notifyPath: Polymer.Base.notifyPath, | |
6712 _get: Polymer.Base._get, | |
6713 _EVENT_CHANGED: Polymer.Base._EVENT_CHANGED, | |
6714 _notifyPath: Polymer.Base._notifyPath, | |
6715 _notifyPathUp: Polymer.Base._notifyPathUp, | |
6716 _pathEffector: Polymer.Base._pathEffector, | |
6717 _annotationPathEffect: Polymer.Base._annotationPathEffect, | |
6718 _complexObserverPathEffect: Polymer.Base._complexObserverPathEffect, | |
6719 _annotatedComputationPathEffect: Polymer.Base._annotatedComputationPathEffect, | |
6720 _computePathEffect: Polymer.Base._computePathEffect, | |
6721 _modelForPath: Polymer.Base._modelForPath, | |
6722 _pathMatchesEffect: Polymer.Base._pathMatchesEffect, | |
6723 _notifyBoundPaths: Polymer.Base._notifyBoundPaths, | |
6724 _getPathParts: Polymer.Base._getPathParts | |
6725 }); | |
6726 } | |
6727 }); | |
6728 }()); | |
6729 Polymer.Base._addFeature({ | |
6730 resolveUrl: function (url) { | |
6731 var module = Polymer.DomModule.import(this.is); | |
6732 var root = ''; | |
6733 if (module) { | |
6734 var assetPath = module.getAttribute('assetpath') || ''; | |
6735 root = Polymer.ResolveUrl.resolveUrl(assetPath, module.ownerDocument.baseURI); | |
6736 } | |
6737 return Polymer.ResolveUrl.resolveUrl(url, root); | |
6738 } | |
6739 }); | |
6740 Polymer.CssParse = function () { | |
6741 var api = { | |
6742 parse: function (text) { | |
6743 text = this._clean(text); | |
6744 return this._parseCss(this._lex(text), text); | |
6745 }, | |
6746 _clean: function (cssText) { | |
6747 return cssText.replace(this._rx.comments, '').replace(this._rx.port, ''); | |
6748 }, | |
6749 _lex: function (text) { | |
6750 var root = { | |
6751 start: 0, | |
6752 end: text.length | |
6753 }; | |
6754 var n = root; | |
6755 for (var i = 0, s = 0, l = text.length; i < l; i++) { | |
6756 switch (text[i]) { | |
6757 case this.OPEN_BRACE: | |
6758 if (!n.rules) { | |
6759 n.rules = []; | |
6760 } | |
6761 var p = n; | |
6762 var previous = p.rules[p.rules.length - 1]; | |
6763 n = { | |
6764 start: i + 1, | |
6765 parent: p, | |
6766 previous: previous | |
6767 }; | |
6768 p.rules.push(n); | |
6769 break; | |
6770 case this.CLOSE_BRACE: | |
6771 n.end = i + 1; | |
6772 n = n.parent || root; | |
6773 break; | |
6774 } | |
6775 } | |
6776 return root; | |
6777 }, | |
6778 _parseCss: function (node, text) { | |
6779 var t = text.substring(node.start, node.end - 1); | |
6780 node.parsedCssText = node.cssText = t.trim(); | |
6781 if (node.parent) { | |
6782 var ss = node.previous ? node.previous.end : node.parent.start; | |
6783 t = text.substring(ss, node.start - 1); | |
6784 t = this._expandUnicodeEscapes(t); | |
6785 t = t.replace(this._rx.multipleSpaces, ' '); | |
6786 t = t.substring(t.lastIndexOf(';') + 1); | |
6787 var s = node.parsedSelector = node.selector = t.trim(); | |
6788 node.atRule = s.indexOf(this.AT_START) === 0; | |
6789 if (node.atRule) { | |
6790 if (s.indexOf(this.MEDIA_START) === 0) { | |
6791 node.type = this.types.MEDIA_RULE; | |
6792 } else if (s.match(this._rx.keyframesRule)) { | |
6793 node.type = this.types.KEYFRAMES_RULE; | |
6794 } | |
6795 } else { | |
6796 if (s.indexOf(this.VAR_START) === 0) { | |
6797 node.type = this.types.MIXIN_RULE; | |
6798 } else { | |
6799 node.type = this.types.STYLE_RULE; | |
6800 } | |
6801 } | |
6802 } | |
6803 var r$ = node.rules; | |
6804 if (r$) { | |
6805 for (var i = 0, l = r$.length, r; i < l && (r = r$[i]); i++) { | |
6806 this._parseCss(r, text); | |
6807 } | |
6808 } | |
6809 return node; | |
6810 }, | |
6811 _expandUnicodeEscapes: function (s) { | |
6812 return s.replace(/\\([0-9a-f]{1,6})\s/gi, function () { | |
6813 var code = arguments[1], repeat = 6 - code.length; | |
6814 while (repeat--) { | |
6815 code = '0' + code; | |
6816 } | |
6817 return '\\' + code; | |
6818 }); | |
6819 }, | |
6820 stringify: function (node, preserveProperties, text) { | |
6821 text = text || ''; | |
6822 var cssText = ''; | |
6823 if (node.cssText || node.rules) { | |
6824 var r$ = node.rules; | |
6825 if (r$ && (preserveProperties || !this._hasMixinRules(r$))) { | |
6826 for (var i = 0, l = r$.length, r; i < l && (r = r$[i]); i++) { | |
6827 cssText = this.stringify(r, preserveProperties, cssText); | |
6828 } | |
6829 } else { | |
6830 cssText = preserveProperties ? node.cssText : this.removeCustomProps(node.cssTex
t); | |
6831 cssText = cssText.trim(); | |
6832 if (cssText) { | |
6833 cssText = ' ' + cssText + '\n'; | |
6834 } | |
6835 } | |
6836 } | |
6837 if (cssText) { | |
6838 if (node.selector) { | |
6839 text += node.selector + ' ' + this.OPEN_BRACE + '\n'; | |
6840 } | |
6841 text += cssText; | |
6842 if (node.selector) { | |
6843 text += this.CLOSE_BRACE + '\n\n'; | |
6844 } | |
6845 } | |
6846 return text; | |
6847 }, | |
6848 _hasMixinRules: function (rules) { | |
6849 return rules[0].selector.indexOf(this.VAR_START) === 0; | |
6850 }, | |
6851 removeCustomProps: function (cssText) { | |
6852 return cssText; | |
6853 }, | |
6854 removeCustomPropAssignment: function (cssText) { | |
6855 return cssText.replace(this._rx.customProp, '').replace(this._rx.mixinProp, ''); | |
6856 }, | |
6857 removeCustomPropApply: function (cssText) { | |
6858 return cssText.replace(this._rx.mixinApply, '').replace(this._rx.varApply, ''); | |
6859 }, | |
6860 types: { | |
6861 STYLE_RULE: 1, | |
6862 KEYFRAMES_RULE: 7, | |
6863 MEDIA_RULE: 4, | |
6864 MIXIN_RULE: 1000 | |
6865 }, | |
6866 OPEN_BRACE: '{', | |
6867 CLOSE_BRACE: '}', | |
6868 _rx: { | |
6869 comments: /\/\*[^*]*\*+([^\/*][^*]*\*+)*\//gim, | |
6870 port: /@import[^;]*;/gim, | |
6871 customProp: /(?:^|[\s;])--[^;{]*?:[^{};]*?(?:[;\n]|$)/gim, | |
6872 mixinProp: /(?:^|[\s;])?--[^;{]*?:[^{;]*?{[^}]*?}(?:[;\n]|$)?/gim, | |
6873 mixinApply: /@apply[\s]*\([^)]*?\)[\s]*(?:[;\n]|$)?/gim, | |
6874 varApply: /[^;:]*?:[^;]*?var\([^;]*\)(?:[;\n]|$)?/gim, | |
6875 keyframesRule: /^@[^\s]*keyframes/, | |
6876 multipleSpaces: /\s+/g | |
6877 }, | |
6878 VAR_START: '--', | |
6879 MEDIA_START: '@media', | |
6880 AT_START: '@' | |
6881 }; | |
6882 return api; | |
6883 }(); | |
6884 Polymer.StyleUtil = function () { | |
6885 return { | |
6886 MODULE_STYLES_SELECTOR: 'style, link[rel=import][type~=css], template', | |
6887 INCLUDE_ATTR: 'include', | |
6888 toCssText: function (rules, callback, preserveProperties) { | |
6889 if (typeof rules === 'string') { | |
6890 rules = this.parser.parse(rules); | |
6891 } | |
6892 if (callback) { | |
6893 this.forEachStyleRule(rules, callback); | |
6894 } | |
6895 return this.parser.stringify(rules, preserveProperties); | |
6896 }, | |
6897 forRulesInStyles: function (styles, callback) { | |
6898 if (styles) { | |
6899 for (var i = 0, l = styles.length, s; i < l && (s = styles[i]); i++) { | |
6900 this.forEachStyleRule(this.rulesForStyle(s), callback); | |
6901 } | |
6902 } | |
6903 }, | |
6904 rulesForStyle: function (style) { | |
6905 if (!style.__cssRules && style.textContent) { | |
6906 style.__cssRules = this.parser.parse(style.textContent); | |
6907 } | |
6908 return style.__cssRules; | |
6909 }, | |
6910 clearStyleRules: function (style) { | |
6911 style.__cssRules = null; | |
6912 }, | |
6913 forEachStyleRule: function (node, callback) { | |
6914 if (!node) { | |
6915 return; | |
6916 } | |
6917 var s = node.parsedSelector; | |
6918 var skipRules = false; | |
6919 if (node.type === this.ruleTypes.STYLE_RULE) { | |
6920 callback(node); | |
6921 } else if (node.type === this.ruleTypes.KEYFRAMES_RULE || node.type === this.rul
eTypes.MIXIN_RULE) { | |
6922 skipRules = true; | |
6923 } | |
6924 var r$ = node.rules; | |
6925 if (r$ && !skipRules) { | |
6926 for (var i = 0, l = r$.length, r; i < l && (r = r$[i]); i++) { | |
6927 this.forEachStyleRule(r, callback); | |
6928 } | |
6929 } | |
6930 }, | |
6931 applyCss: function (cssText, moniker, target, afterNode) { | |
6932 var style = document.createElement('style'); | |
6933 if (moniker) { | |
6934 style.setAttribute('scope', moniker); | |
6935 } | |
6936 style.textContent = cssText; | |
6937 target = target || document.head; | |
6938 if (!afterNode) { | |
6939 var n$ = target.querySelectorAll('style[scope]'); | |
6940 afterNode = n$[n$.length - 1]; | |
6941 } | |
6942 target.insertBefore(style, afterNode && afterNode.nextSibling || target.firstChi
ld); | |
6943 return style; | |
6944 }, | |
6945 cssFromModules: function (moduleIds, warnIfNotFound) { | |
6946 var modules = moduleIds.trim().split(' '); | |
6947 var cssText = ''; | |
6948 for (var i = 0; i < modules.length; i++) { | |
6949 cssText += this.cssFromModule(modules[i], warnIfNotFound); | |
6950 } | |
6951 return cssText; | |
6952 }, | |
6953 cssFromModule: function (moduleId, warnIfNotFound) { | |
6954 var m = Polymer.DomModule.import(moduleId); | |
6955 if (m && !m._cssText) { | |
6956 m._cssText = this.cssFromElement(m); | |
6957 } | |
6958 if (!m && warnIfNotFound) { | |
6959 console.warn('Could not find style data in module named', moduleId); | |
6960 } | |
6961 return m && m._cssText || ''; | |
6962 }, | |
6963 cssFromElement: function (element) { | |
6964 var cssText = ''; | |
6965 var content = element.content || element; | |
6966 var e$ = Polymer.DomApi.arrayCopy(content.querySelectorAll(this.MODULE_STYLES_SE
LECTOR)); | |
6967 for (var i = 0, e; i < e$.length; i++) { | |
6968 e = e$[i]; | |
6969 if (e.localName === 'template') { | |
6970 cssText += this.cssFromElement(e); | |
6971 } else { | |
6972 if (e.localName === 'style') { | |
6973 var include = e.getAttribute(this.INCLUDE_ATTR); | |
6974 if (include) { | |
6975 cssText += this.cssFromModules(include, true); | |
6976 } | |
6977 e = e.__appliedElement || e; | |
6978 e.parentNode.removeChild(e); | |
6979 cssText += this.resolveCss(e.textContent, element.ownerDocument); | |
6980 } else if (e.import && e.import.body) { | |
6981 cssText += this.resolveCss(e.import.body.textContent, e.import); | |
6982 } | |
6983 } | |
6984 } | |
6985 return cssText; | |
6986 }, | |
6987 resolveCss: Polymer.ResolveUrl.resolveCss, | |
6988 parser: Polymer.CssParse, | |
6989 ruleTypes: Polymer.CssParse.types | |
6990 }; | |
6991 }(); | |
6992 Polymer.StyleTransformer = function () { | |
6993 var nativeShadow = Polymer.Settings.useNativeShadow; | |
6994 var styleUtil = Polymer.StyleUtil; | |
6995 var api = { | |
6996 dom: function (node, scope, useAttr, shouldRemoveScope) { | |
6997 this._transformDom(node, scope || '', useAttr, shouldRemoveScope); | |
6998 }, | |
6999 _transformDom: function (node, selector, useAttr, shouldRemoveScope) { | |
7000 if (node.setAttribute) { | |
7001 this.element(node, selector, useAttr, shouldRemoveScope); | |
7002 } | |
7003 var c$ = Polymer.dom(node).childNodes; | |
7004 for (var i = 0; i < c$.length; i++) { | |
7005 this._transformDom(c$[i], selector, useAttr, shouldRemoveScope); | |
7006 } | |
7007 }, | |
7008 element: function (element, scope, useAttr, shouldRemoveScope) { | |
7009 if (useAttr) { | |
7010 if (shouldRemoveScope) { | |
7011 element.removeAttribute(SCOPE_NAME); | |
7012 } else { | |
7013 element.setAttribute(SCOPE_NAME, scope); | |
7014 } | |
7015 } else { | |
7016 if (scope) { | |
7017 if (element.classList) { | |
7018 if (shouldRemoveScope) { | |
7019 element.classList.remove(SCOPE_NAME); | |
7020 element.classList.remove(scope); | |
7021 } else { | |
7022 element.classList.add(SCOPE_NAME); | |
7023 element.classList.add(scope); | |
7024 } | |
7025 } else if (element.getAttribute) { | |
7026 var c = element.getAttribute(CLASS); | |
7027 if (shouldRemoveScope) { | |
7028 if (c) { | |
7029 element.setAttribute(CLASS, c.replace(SCOPE_NAME, '').replace(scope, '')); | |
7030 } | |
7031 } else { | |
7032 element.setAttribute(CLASS, c + (c ? ' ' : '') + SCOPE_NAME + ' ' + scope); | |
7033 } | |
7034 } | |
7035 } | |
7036 } | |
7037 }, | |
7038 elementStyles: function (element, callback) { | |
7039 var styles = element._styles; | |
7040 var cssText = ''; | |
7041 for (var i = 0, l = styles.length, s, text; i < l && (s = styles[i]); i++) { | |
7042 var rules = styleUtil.rulesForStyle(s); | |
7043 cssText += nativeShadow ? styleUtil.toCssText(rules, callback) : this.css(rules,
element.is, element.extends, callback, element._scopeCssViaAttr) + '\n\n'; | |
7044 } | |
7045 return cssText.trim(); | |
7046 }, | |
7047 css: function (rules, scope, ext, callback, useAttr) { | |
7048 var hostScope = this._calcHostScope(scope, ext); | |
7049 scope = this._calcElementScope(scope, useAttr); | |
7050 var self = this; | |
7051 return styleUtil.toCssText(rules, function (rule) { | |
7052 if (!rule.isScoped) { | |
7053 self.rule(rule, scope, hostScope); | |
7054 rule.isScoped = true; | |
7055 } | |
7056 if (callback) { | |
7057 callback(rule, scope, hostScope); | |
7058 } | |
7059 }); | |
7060 }, | |
7061 _calcElementScope: function (scope, useAttr) { | |
7062 if (scope) { | |
7063 return useAttr ? CSS_ATTR_PREFIX + scope + CSS_ATTR_SUFFIX : CSS_CLASS_PREFIX +
scope; | |
7064 } else { | |
7065 return ''; | |
7066 } | |
7067 }, | |
7068 _calcHostScope: function (scope, ext) { | |
7069 return ext ? '[is=' + scope + ']' : scope; | |
7070 }, | |
7071 rule: function (rule, scope, hostScope) { | |
7072 this._transformRule(rule, this._transformComplexSelector, scope, hostScope); | |
7073 }, | |
7074 _transformRule: function (rule, transformer, scope, hostScope) { | |
7075 var p$ = rule.selector.split(COMPLEX_SELECTOR_SEP); | |
7076 for (var i = 0, l = p$.length, p; i < l && (p = p$[i]); i++) { | |
7077 p$[i] = transformer.call(this, p, scope, hostScope); | |
7078 } | |
7079 rule.selector = rule.transformedSelector = p$.join(COMPLEX_SELECTOR_SEP); | |
7080 }, | |
7081 _transformComplexSelector: function (selector, scope, hostScope) { | |
7082 var stop = false; | |
7083 var hostContext = false; | |
7084 var self = this; | |
7085 selector = selector.replace(SIMPLE_SELECTOR_SEP, function (m, c, s) { | |
7086 if (!stop) { | |
7087 var info = self._transformCompoundSelector(s, c, scope, hostScope); | |
7088 stop = stop || info.stop; | |
7089 hostContext = hostContext || info.hostContext; | |
7090 c = info.combinator; | |
7091 s = info.value; | |
7092 } else { | |
7093 s = s.replace(SCOPE_JUMP, ' '); | |
7094 } | |
7095 return c + s; | |
7096 }); | |
7097 if (hostContext) { | |
7098 selector = selector.replace(HOST_CONTEXT_PAREN, function (m, pre, paren, post) { | |
7099 return pre + paren + ' ' + hostScope + post + COMPLEX_SELECTOR_SEP + ' ' + pre +
hostScope + paren + post; | |
7100 }); | |
7101 } | |
7102 return selector; | |
7103 }, | |
7104 _transformCompoundSelector: function (selector, combinator, scope, hostScope) { | |
7105 var jumpIndex = selector.search(SCOPE_JUMP); | |
7106 var hostContext = false; | |
7107 if (selector.indexOf(HOST_CONTEXT) >= 0) { | |
7108 hostContext = true; | |
7109 } else if (selector.indexOf(HOST) >= 0) { | |
7110 selector = selector.replace(HOST_PAREN, function (m, host, paren) { | |
7111 return hostScope + paren; | |
7112 }); | |
7113 selector = selector.replace(HOST, hostScope); | |
7114 } else if (jumpIndex !== 0) { | |
7115 selector = scope ? this._transformSimpleSelector(selector, scope) : selector; | |
7116 } | |
7117 if (selector.indexOf(CONTENT) >= 0) { | |
7118 combinator = ''; | |
7119 } | |
7120 var stop; | |
7121 if (jumpIndex >= 0) { | |
7122 selector = selector.replace(SCOPE_JUMP, ' '); | |
7123 stop = true; | |
7124 } | |
7125 return { | |
7126 value: selector, | |
7127 combinator: combinator, | |
7128 stop: stop, | |
7129 hostContext: hostContext | |
7130 }; | |
7131 }, | |
7132 _transformSimpleSelector: function (selector, scope) { | |
7133 var p$ = selector.split(PSEUDO_PREFIX); | |
7134 p$[0] += scope; | |
7135 return p$.join(PSEUDO_PREFIX); | |
7136 }, | |
7137 documentRule: function (rule) { | |
7138 rule.selector = rule.parsedSelector; | |
7139 this.normalizeRootSelector(rule); | |
7140 if (!nativeShadow) { | |
7141 this._transformRule(rule, this._transformDocumentSelector); | |
7142 } | |
7143 }, | |
7144 normalizeRootSelector: function (rule) { | |
7145 if (rule.selector === ROOT) { | |
7146 rule.selector = 'body'; | |
7147 } | |
7148 }, | |
7149 _transformDocumentSelector: function (selector) { | |
7150 return selector.match(SCOPE_JUMP) ? this._transformComplexSelector(selector, SCO
PE_DOC_SELECTOR) : this._transformSimpleSelector(selector.trim(), SCOPE_DOC_SELE
CTOR); | |
7151 }, | |
7152 SCOPE_NAME: 'style-scope' | |
7153 }; | |
7154 var SCOPE_NAME = api.SCOPE_NAME; | |
7155 var SCOPE_DOC_SELECTOR = ':not([' + SCOPE_NAME + '])' + ':not(.' + SCOPE_NAME +
')'; | |
7156 var COMPLEX_SELECTOR_SEP = ','; | |
7157 var SIMPLE_SELECTOR_SEP = /(^|[\s>+~]+)([^\s>+~]+)/g; | |
7158 var HOST = ':host'; | |
7159 var ROOT = ':root'; | |
7160 var HOST_PAREN = /(\:host)(?:\(((?:\([^)(]*\)|[^)(]*)+?)\))/g; | |
7161 var HOST_CONTEXT = ':host-context'; | |
7162 var HOST_CONTEXT_PAREN = /(.*)(?:\:host-context)(?:\(((?:\([^)(]*\)|[^)(]*)+?)\)
)(.*)/; | |
7163 var CONTENT = '::content'; | |
7164 var SCOPE_JUMP = /\:\:content|\:\:shadow|\/deep\//; | |
7165 var CSS_CLASS_PREFIX = '.'; | |
7166 var CSS_ATTR_PREFIX = '[' + SCOPE_NAME + '~='; | |
7167 var CSS_ATTR_SUFFIX = ']'; | |
7168 var PSEUDO_PREFIX = ':'; | |
7169 var CLASS = 'class'; | |
7170 return api; | |
7171 }(); | |
7172 Polymer.StyleExtends = function () { | |
7173 var styleUtil = Polymer.StyleUtil; | |
7174 return { | |
7175 hasExtends: function (cssText) { | |
7176 return Boolean(cssText.match(this.rx.EXTEND)); | |
7177 }, | |
7178 transform: function (style) { | |
7179 var rules = styleUtil.rulesForStyle(style); | |
7180 var self = this; | |
7181 styleUtil.forEachStyleRule(rules, function (rule) { | |
7182 var map = self._mapRule(rule); | |
7183 if (rule.parent) { | |
7184 var m; | |
7185 while (m = self.rx.EXTEND.exec(rule.cssText)) { | |
7186 var extend = m[1]; | |
7187 var extendor = self._findExtendor(extend, rule); | |
7188 if (extendor) { | |
7189 self._extendRule(rule, extendor); | |
7190 } | |
7191 } | |
7192 } | |
7193 rule.cssText = rule.cssText.replace(self.rx.EXTEND, ''); | |
7194 }); | |
7195 return styleUtil.toCssText(rules, function (rule) { | |
7196 if (rule.selector.match(self.rx.STRIP)) { | |
7197 rule.cssText = ''; | |
7198 } | |
7199 }, true); | |
7200 }, | |
7201 _mapRule: function (rule) { | |
7202 if (rule.parent) { | |
7203 var map = rule.parent.map || (rule.parent.map = {}); | |
7204 var parts = rule.selector.split(','); | |
7205 for (var i = 0, p; i < parts.length; i++) { | |
7206 p = parts[i]; | |
7207 map[p.trim()] = rule; | |
7208 } | |
7209 return map; | |
7210 } | |
7211 }, | |
7212 _findExtendor: function (extend, rule) { | |
7213 return rule.parent && rule.parent.map && rule.parent.map[extend] || this._findEx
tendor(extend, rule.parent); | |
7214 }, | |
7215 _extendRule: function (target, source) { | |
7216 if (target.parent !== source.parent) { | |
7217 this._cloneAndAddRuleToParent(source, target.parent); | |
7218 } | |
7219 target.extends = target.extends || []; | |
7220 target.extends.push(source); | |
7221 source.selector = source.selector.replace(this.rx.STRIP, ''); | |
7222 source.selector = (source.selector && source.selector + ',\n') + target.selector
; | |
7223 if (source.extends) { | |
7224 source.extends.forEach(function (e) { | |
7225 this._extendRule(target, e); | |
7226 }, this); | |
7227 } | |
7228 }, | |
7229 _cloneAndAddRuleToParent: function (rule, parent) { | |
7230 rule = Object.create(rule); | |
7231 rule.parent = parent; | |
7232 if (rule.extends) { | |
7233 rule.extends = rule.extends.slice(); | |
7234 } | |
7235 parent.rules.push(rule); | |
7236 }, | |
7237 rx: { | |
7238 EXTEND: /@extends\(([^)]*)\)\s*?;/gim, | |
7239 STRIP: /%[^,]*$/ | |
7240 } | |
7241 }; | |
7242 }(); | |
7243 (function () { | |
7244 var prepElement = Polymer.Base._prepElement; | |
7245 var nativeShadow = Polymer.Settings.useNativeShadow; | |
7246 var styleUtil = Polymer.StyleUtil; | |
7247 var styleTransformer = Polymer.StyleTransformer; | |
7248 var styleExtends = Polymer.StyleExtends; | |
7249 Polymer.Base._addFeature({ | |
7250 _prepElement: function (element) { | |
7251 if (this._encapsulateStyle) { | |
7252 styleTransformer.element(element, this.is, this._scopeCssViaAttr); | |
7253 } | |
7254 prepElement.call(this, element); | |
7255 }, | |
7256 _prepStyles: function () { | |
7257 if (this._encapsulateStyle === undefined) { | |
7258 this._encapsulateStyle = !nativeShadow && Boolean(this._template); | |
7259 } | |
7260 if (this._template) { | |
7261 this._styles = this._collectStyles(); | |
7262 var cssText = styleTransformer.elementStyles(this); | |
7263 if (cssText) { | |
7264 var style = styleUtil.applyCss(cssText, this.is, nativeShadow ? this._template.c
ontent : null); | |
7265 if (!nativeShadow) { | |
7266 this._scopeStyle = style; | |
7267 } | |
7268 } | |
7269 } else { | |
7270 this._styles = []; | |
7271 } | |
7272 }, | |
7273 _collectStyles: function () { | |
7274 var styles = []; | |
7275 var cssText = '', m$ = this.styleModules; | |
7276 if (m$) { | |
7277 for (var i = 0, l = m$.length, m; i < l && (m = m$[i]); i++) { | |
7278 cssText += styleUtil.cssFromModule(m); | |
7279 } | |
7280 } | |
7281 cssText += styleUtil.cssFromModule(this.is); | |
7282 var p = this._template && this._template.parentNode; | |
7283 if (this._template && (!p || p.id.toLowerCase() !== this.is)) { | |
7284 cssText += styleUtil.cssFromElement(this._template); | |
7285 } | |
7286 if (cssText) { | |
7287 var style = document.createElement('style'); | |
7288 style.textContent = cssText; | |
7289 if (styleExtends.hasExtends(style.textContent)) { | |
7290 cssText = styleExtends.transform(style); | |
7291 } | |
7292 styles.push(style); | |
7293 } | |
7294 return styles; | |
7295 }, | |
7296 _elementAdd: function (node) { | |
7297 if (this._encapsulateStyle) { | |
7298 if (node.__styleScoped) { | |
7299 node.__styleScoped = false; | |
7300 } else { | |
7301 styleTransformer.dom(node, this.is, this._scopeCssViaAttr); | |
7302 } | |
7303 } | |
7304 }, | |
7305 _elementRemove: function (node) { | |
7306 if (this._encapsulateStyle) { | |
7307 styleTransformer.dom(node, this.is, this._scopeCssViaAttr, true); | |
7308 } | |
7309 }, | |
7310 scopeSubtree: function (container, shouldObserve) { | |
7311 if (nativeShadow) { | |
7312 return; | |
7313 } | |
7314 var self = this; | |
7315 var scopify = function (node) { | |
7316 if (node.nodeType === Node.ELEMENT_NODE) { | |
7317 node.className = self._scopeElementClass(node, node.className); | |
7318 var n$ = node.querySelectorAll('*'); | |
7319 for (var i = 0, n; i < n$.length && (n = n$[i]); i++) { | |
7320 n.className = self._scopeElementClass(n, n.className); | |
7321 } | |
7322 } | |
7323 }; | |
7324 scopify(container); | |
7325 if (shouldObserve) { | |
7326 var mo = new MutationObserver(function (mxns) { | |
7327 for (var i = 0, m; i < mxns.length && (m = mxns[i]); i++) { | |
7328 if (m.addedNodes) { | |
7329 for (var j = 0; j < m.addedNodes.length; j++) { | |
7330 scopify(m.addedNodes[j]); | |
7331 } | |
7332 } | |
7333 } | |
7334 }); | |
7335 mo.observe(container, { | |
7336 childList: true, | |
7337 subtree: true | |
7338 }); | |
7339 return mo; | |
7340 } | |
7341 } | |
7342 }); | |
7343 }()); | |
7344 Polymer.StyleProperties = function () { | |
7345 'use strict'; | |
7346 var nativeShadow = Polymer.Settings.useNativeShadow; | |
7347 var matchesSelector = Polymer.DomApi.matchesSelector; | |
7348 var styleUtil = Polymer.StyleUtil; | |
7349 var styleTransformer = Polymer.StyleTransformer; | |
7350 return { | |
7351 decorateStyles: function (styles) { | |
7352 var self = this, props = {}; | |
7353 styleUtil.forRulesInStyles(styles, function (rule) { | |
7354 self.decorateRule(rule); | |
7355 self.collectPropertiesInCssText(rule.propertyInfo.cssText, props); | |
7356 }); | |
7357 var names = []; | |
7358 for (var i in props) { | |
7359 names.push(i); | |
7360 } | |
7361 return names; | |
7362 }, | |
7363 decorateRule: function (rule) { | |
7364 if (rule.propertyInfo) { | |
7365 return rule.propertyInfo; | |
7366 } | |
7367 var info = {}, properties = {}; | |
7368 var hasProperties = this.collectProperties(rule, properties); | |
7369 if (hasProperties) { | |
7370 info.properties = properties; | |
7371 rule.rules = null; | |
7372 } | |
7373 info.cssText = this.collectCssText(rule); | |
7374 rule.propertyInfo = info; | |
7375 return info; | |
7376 }, | |
7377 collectProperties: function (rule, properties) { | |
7378 var info = rule.propertyInfo; | |
7379 if (info) { | |
7380 if (info.properties) { | |
7381 Polymer.Base.mixin(properties, info.properties); | |
7382 return true; | |
7383 } | |
7384 } else { | |
7385 var m, rx = this.rx.VAR_ASSIGN; | |
7386 var cssText = rule.parsedCssText; | |
7387 var any; | |
7388 while (m = rx.exec(cssText)) { | |
7389 properties[m[1]] = (m[2] || m[3]).trim(); | |
7390 any = true; | |
7391 } | |
7392 return any; | |
7393 } | |
7394 }, | |
7395 collectCssText: function (rule) { | |
7396 var customCssText = ''; | |
7397 var cssText = rule.parsedCssText; | |
7398 cssText = cssText.replace(this.rx.BRACKETED, '').replace(this.rx.VAR_ASSIGN, '')
; | |
7399 var parts = cssText.split(';'); | |
7400 for (var i = 0, p; i < parts.length; i++) { | |
7401 p = parts[i]; | |
7402 if (p.match(this.rx.MIXIN_MATCH) || p.match(this.rx.VAR_MATCH)) { | |
7403 customCssText += p + ';\n'; | |
7404 } | |
7405 } | |
7406 return customCssText; | |
7407 }, | |
7408 collectPropertiesInCssText: function (cssText, props) { | |
7409 var m; | |
7410 while (m = this.rx.VAR_CAPTURE.exec(cssText)) { | |
7411 props[m[1]] = true; | |
7412 var def = m[2]; | |
7413 if (def && def.match(this.rx.IS_VAR)) { | |
7414 props[def] = true; | |
7415 } | |
7416 } | |
7417 }, | |
7418 reify: function (props) { | |
7419 var names = Object.getOwnPropertyNames(props); | |
7420 for (var i = 0, n; i < names.length; i++) { | |
7421 n = names[i]; | |
7422 props[n] = this.valueForProperty(props[n], props); | |
7423 } | |
7424 }, | |
7425 valueForProperty: function (property, props) { | |
7426 if (property) { | |
7427 if (property.indexOf(';') >= 0) { | |
7428 property = this.valueForProperties(property, props); | |
7429 } else { | |
7430 var self = this; | |
7431 var fn = function (all, prefix, value, fallback) { | |
7432 var propertyValue = self.valueForProperty(props[value], props) || (props[fallbac
k] ? self.valueForProperty(props[fallback], props) : fallback); | |
7433 return prefix + (propertyValue || ''); | |
7434 }; | |
7435 property = property.replace(this.rx.VAR_MATCH, fn); | |
7436 } | |
7437 } | |
7438 return property && property.trim() || ''; | |
7439 }, | |
7440 valueForProperties: function (property, props) { | |
7441 var parts = property.split(';'); | |
7442 for (var i = 0, p, m; i < parts.length; i++) { | |
7443 if (p = parts[i]) { | |
7444 m = p.match(this.rx.MIXIN_MATCH); | |
7445 if (m) { | |
7446 p = this.valueForProperty(props[m[1]], props); | |
7447 } else { | |
7448 var pp = p.split(':'); | |
7449 if (pp[1]) { | |
7450 pp[1] = pp[1].trim(); | |
7451 pp[1] = this.valueForProperty(pp[1], props) || pp[1]; | |
7452 } | |
7453 p = pp.join(':'); | |
7454 } | |
7455 parts[i] = p && p.lastIndexOf(';') === p.length - 1 ? p.slice(0, -1) : p || ''; | |
7456 } | |
7457 } | |
7458 return parts.filter(function (v) { | |
7459 return v; | |
7460 }).join(';'); | |
7461 }, | |
7462 applyProperties: function (rule, props) { | |
7463 var output = ''; | |
7464 if (!rule.propertyInfo) { | |
7465 this.decorateRule(rule); | |
7466 } | |
7467 if (rule.propertyInfo.cssText) { | |
7468 output = this.valueForProperties(rule.propertyInfo.cssText, props); | |
7469 } | |
7470 rule.cssText = output; | |
7471 }, | |
7472 propertyDataFromStyles: function (styles, element) { | |
7473 var props = {}, self = this; | |
7474 var o = [], i = 0; | |
7475 styleUtil.forRulesInStyles(styles, function (rule) { | |
7476 if (!rule.propertyInfo) { | |
7477 self.decorateRule(rule); | |
7478 } | |
7479 if (element && rule.propertyInfo.properties && matchesSelector.call(element, rul
e.transformedSelector || rule.parsedSelector)) { | |
7480 self.collectProperties(rule, props); | |
7481 addToBitMask(i, o); | |
7482 } | |
7483 i++; | |
7484 }); | |
7485 return { | |
7486 properties: props, | |
7487 key: o | |
7488 }; | |
7489 }, | |
7490 scopePropertiesFromStyles: function (styles) { | |
7491 if (!styles._scopeStyleProperties) { | |
7492 styles._scopeStyleProperties = this.selectedPropertiesFromStyles(styles, this.SC
OPE_SELECTORS); | |
7493 } | |
7494 return styles._scopeStyleProperties; | |
7495 }, | |
7496 hostPropertiesFromStyles: function (styles) { | |
7497 if (!styles._hostStyleProperties) { | |
7498 styles._hostStyleProperties = this.selectedPropertiesFromStyles(styles, this.HOS
T_SELECTORS); | |
7499 } | |
7500 return styles._hostStyleProperties; | |
7501 }, | |
7502 selectedPropertiesFromStyles: function (styles, selectors) { | |
7503 var props = {}, self = this; | |
7504 styleUtil.forRulesInStyles(styles, function (rule) { | |
7505 if (!rule.propertyInfo) { | |
7506 self.decorateRule(rule); | |
7507 } | |
7508 for (var i = 0; i < selectors.length; i++) { | |
7509 if (rule.parsedSelector === selectors[i]) { | |
7510 self.collectProperties(rule, props); | |
7511 return; | |
7512 } | |
7513 } | |
7514 }); | |
7515 return props; | |
7516 }, | |
7517 transformStyles: function (element, properties, scopeSelector) { | |
7518 var self = this; | |
7519 var hostSelector = styleTransformer._calcHostScope(element.is, element.extends); | |
7520 var rxHostSelector = element.extends ? '\\' + hostSelector.slice(0, -1) + '\\]'
: hostSelector; | |
7521 var hostRx = new RegExp(this.rx.HOST_PREFIX + rxHostSelector + this.rx.HOST_SUFF
IX); | |
7522 return styleTransformer.elementStyles(element, function (rule) { | |
7523 self.applyProperties(rule, properties); | |
7524 if (rule.cssText && !nativeShadow) { | |
7525 self._scopeSelector(rule, hostRx, hostSelector, element._scopeCssViaAttr, scopeS
elector); | |
7526 } | |
7527 }); | |
7528 }, | |
7529 _scopeSelector: function (rule, hostRx, hostSelector, viaAttr, scopeId) { | |
7530 rule.transformedSelector = rule.transformedSelector || rule.selector; | |
7531 var selector = rule.transformedSelector; | |
7532 var scope = viaAttr ? '[' + styleTransformer.SCOPE_NAME + '~=' + scopeId + ']' :
'.' + scopeId; | |
7533 var parts = selector.split(','); | |
7534 for (var i = 0, l = parts.length, p; i < l && (p = parts[i]); i++) { | |
7535 parts[i] = p.match(hostRx) ? p.replace(hostSelector, hostSelector + scope) : sco
pe + ' ' + p; | |
7536 } | |
7537 rule.selector = parts.join(','); | |
7538 }, | |
7539 applyElementScopeSelector: function (element, selector, old, viaAttr) { | |
7540 var c = viaAttr ? element.getAttribute(styleTransformer.SCOPE_NAME) : element.cl
assName; | |
7541 var v = old ? c.replace(old, selector) : (c ? c + ' ' : '') + this.XSCOPE_NAME +
' ' + selector; | |
7542 if (c !== v) { | |
7543 if (viaAttr) { | |
7544 element.setAttribute(styleTransformer.SCOPE_NAME, v); | |
7545 } else { | |
7546 element.className = v; | |
7547 } | |
7548 } | |
7549 }, | |
7550 applyElementStyle: function (element, properties, selector, style) { | |
7551 var cssText = style ? style.textContent || '' : this.transformStyles(element, pr
operties, selector); | |
7552 var s = element._customStyle; | |
7553 if (s && !nativeShadow && s !== style) { | |
7554 s._useCount--; | |
7555 if (s._useCount <= 0 && s.parentNode) { | |
7556 s.parentNode.removeChild(s); | |
7557 } | |
7558 } | |
7559 if (nativeShadow || (!style || !style.parentNode)) { | |
7560 if (nativeShadow && element._customStyle) { | |
7561 element._customStyle.textContent = cssText; | |
7562 style = element._customStyle; | |
7563 } else if (cssText) { | |
7564 style = styleUtil.applyCss(cssText, selector, nativeShadow ? element.root : null
, element._scopeStyle); | |
7565 } | |
7566 } | |
7567 if (style) { | |
7568 style._useCount = style._useCount || 0; | |
7569 if (element._customStyle != style) { | |
7570 style._useCount++; | |
7571 } | |
7572 element._customStyle = style; | |
7573 } | |
7574 return style; | |
7575 }, | |
7576 mixinCustomStyle: function (props, customStyle) { | |
7577 var v; | |
7578 for (var i in customStyle) { | |
7579 v = customStyle[i]; | |
7580 if (v || v === 0) { | |
7581 props[i] = v; | |
7582 } | |
7583 } | |
7584 }, | |
7585 rx: { | |
7586 VAR_ASSIGN: /(?:^|[;\s{]\s*)(--[\w-]*?)\s*:\s*(?:([^;{]*)|{([^}]*)})(?:(?=[;\s}]
)|$)/gi, | |
7587 MIXIN_MATCH: /(?:^|\W+)@apply[\s]*\(([^)]*)\)/i, | |
7588 VAR_MATCH: /(^|\W+)var\([\s]*([^,)]*)[\s]*,?[\s]*((?:[^,)]*)|(?:[^;]*\([^;)]*\))
)[\s]*?\)/gi, | |
7589 VAR_CAPTURE: /\([\s]*(--[^,\s)]*)(?:,[\s]*(--[^,\s)]*))?(?:\)|,)/gi, | |
7590 IS_VAR: /^--/, | |
7591 BRACKETED: /\{[^}]*\}/g, | |
7592 HOST_PREFIX: '(?:^|[^.#[:])', | |
7593 HOST_SUFFIX: '($|[.:[\\s>+~])' | |
7594 }, | |
7595 HOST_SELECTORS: [':host'], | |
7596 SCOPE_SELECTORS: [':root'], | |
7597 XSCOPE_NAME: 'x-scope' | |
7598 }; | |
7599 function addToBitMask(n, bits) { | |
7600 var o = parseInt(n / 32); | |
7601 var v = 1 << n % 32; | |
7602 bits[o] = (bits[o] || 0) | v; | |
7603 } | |
7604 }(); | |
7605 (function () { | |
7606 Polymer.StyleCache = function () { | |
7607 this.cache = {}; | |
7608 }; | |
7609 Polymer.StyleCache.prototype = { | |
7610 MAX: 100, | |
7611 store: function (is, data, keyValues, keyStyles) { | |
7612 data.keyValues = keyValues; | |
7613 data.styles = keyStyles; | |
7614 var s$ = this.cache[is] = this.cache[is] || []; | |
7615 s$.push(data); | |
7616 if (s$.length > this.MAX) { | |
7617 s$.shift(); | |
7618 } | |
7619 }, | |
7620 retrieve: function (is, keyValues, keyStyles) { | |
7621 var cache = this.cache[is]; | |
7622 if (cache) { | |
7623 for (var i = cache.length - 1, data; i >= 0; i--) { | |
7624 data = cache[i]; | |
7625 if (keyStyles === data.styles && this._objectsEqual(keyValues, data.keyValues))
{ | |
7626 return data; | |
7627 } | |
7628 } | |
7629 } | |
7630 }, | |
7631 clear: function () { | |
7632 this.cache = {}; | |
7633 }, | |
7634 _objectsEqual: function (target, source) { | |
7635 var t, s; | |
7636 for (var i in target) { | |
7637 t = target[i], s = source[i]; | |
7638 if (!(typeof t === 'object' && t ? this._objectsStrictlyEqual(t, s) : t === s))
{ | |
7639 return false; | |
7640 } | |
7641 } | |
7642 if (Array.isArray(target)) { | |
7643 return target.length === source.length; | |
7644 } | |
7645 return true; | |
7646 }, | |
7647 _objectsStrictlyEqual: function (target, source) { | |
7648 return this._objectsEqual(target, source) && this._objectsEqual(source, target); | |
7649 } | |
7650 }; | |
7651 }()); | |
7652 Polymer.StyleDefaults = function () { | |
7653 var styleProperties = Polymer.StyleProperties; | |
7654 var styleUtil = Polymer.StyleUtil; | |
7655 var StyleCache = Polymer.StyleCache; | |
7656 var api = { | |
7657 _styles: [], | |
7658 _properties: null, | |
7659 customStyle: {}, | |
7660 _styleCache: new StyleCache(), | |
7661 addStyle: function (style) { | |
7662 this._styles.push(style); | |
7663 this._properties = null; | |
7664 }, | |
7665 get _styleProperties() { | |
7666 if (!this._properties) { | |
7667 styleProperties.decorateStyles(this._styles); | |
7668 this._styles._scopeStyleProperties = null; | |
7669 this._properties = styleProperties.scopePropertiesFromStyles(this._styles); | |
7670 styleProperties.mixinCustomStyle(this._properties, this.customStyle); | |
7671 styleProperties.reify(this._properties); | |
7672 } | |
7673 return this._properties; | |
7674 }, | |
7675 _needsStyleProperties: function () { | |
7676 }, | |
7677 _computeStyleProperties: function () { | |
7678 return this._styleProperties; | |
7679 }, | |
7680 updateStyles: function (properties) { | |
7681 this._properties = null; | |
7682 if (properties) { | |
7683 Polymer.Base.mixin(this.customStyle, properties); | |
7684 } | |
7685 this._styleCache.clear(); | |
7686 for (var i = 0, s; i < this._styles.length; i++) { | |
7687 s = this._styles[i]; | |
7688 s = s.__importElement || s; | |
7689 s._apply(); | |
7690 } | |
7691 } | |
7692 }; | |
7693 return api; | |
7694 }(); | |
7695 (function () { | |
7696 'use strict'; | |
7697 var serializeValueToAttribute = Polymer.Base.serializeValueToAttribute; | |
7698 var propertyUtils = Polymer.StyleProperties; | |
7699 var styleTransformer = Polymer.StyleTransformer; | |
7700 var styleUtil = Polymer.StyleUtil; | |
7701 var styleDefaults = Polymer.StyleDefaults; | |
7702 var nativeShadow = Polymer.Settings.useNativeShadow; | |
7703 Polymer.Base._addFeature({ | |
7704 _prepStyleProperties: function () { | |
7705 this._ownStylePropertyNames = this._styles ? propertyUtils.decorateStyles(this._
styles) : null; | |
7706 }, | |
7707 customStyle: null, | |
7708 getComputedStyleValue: function (property) { | |
7709 return this._styleProperties && this._styleProperties[property] || getComputedSt
yle(this).getPropertyValue(property); | |
7710 }, | |
7711 _setupStyleProperties: function () { | |
7712 this.customStyle = {}; | |
7713 }, | |
7714 _needsStyleProperties: function () { | |
7715 return Boolean(this._ownStylePropertyNames && this._ownStylePropertyNames.length
); | |
7716 }, | |
7717 _beforeAttached: function () { | |
7718 if (!this._scopeSelector && this._needsStyleProperties()) { | |
7719 this._updateStyleProperties(); | |
7720 } | |
7721 }, | |
7722 _findStyleHost: function () { | |
7723 var e = this, root; | |
7724 while (root = Polymer.dom(e).getOwnerRoot()) { | |
7725 if (Polymer.isInstance(root.host)) { | |
7726 return root.host; | |
7727 } | |
7728 e = root.host; | |
7729 } | |
7730 return styleDefaults; | |
7731 }, | |
7732 _updateStyleProperties: function () { | |
7733 var info, scope = this._findStyleHost(); | |
7734 if (!scope._styleCache) { | |
7735 scope._styleCache = new Polymer.StyleCache(); | |
7736 } | |
7737 var scopeData = propertyUtils.propertyDataFromStyles(scope._styles, this); | |
7738 scopeData.key.customStyle = this.customStyle; | |
7739 info = scope._styleCache.retrieve(this.is, scopeData.key, this._styles); | |
7740 var scopeCached = Boolean(info); | |
7741 if (scopeCached) { | |
7742 this._styleProperties = info._styleProperties; | |
7743 } else { | |
7744 this._computeStyleProperties(scopeData.properties); | |
7745 } | |
7746 this._computeOwnStyleProperties(); | |
7747 if (!scopeCached) { | |
7748 info = styleCache.retrieve(this.is, this._ownStyleProperties, this._styles); | |
7749 } | |
7750 var globalCached = Boolean(info) && !scopeCached; | |
7751 var style = this._applyStyleProperties(info); | |
7752 if (!scopeCached) { | |
7753 style = style && nativeShadow ? style.cloneNode(true) : style; | |
7754 info = { | |
7755 style: style, | |
7756 _scopeSelector: this._scopeSelector, | |
7757 _styleProperties: this._styleProperties | |
7758 }; | |
7759 scopeData.key.customStyle = {}; | |
7760 this.mixin(scopeData.key.customStyle, this.customStyle); | |
7761 scope._styleCache.store(this.is, info, scopeData.key, this._styles); | |
7762 if (!globalCached) { | |
7763 styleCache.store(this.is, Object.create(info), this._ownStyleProperties, this._s
tyles); | |
7764 } | |
7765 } | |
7766 }, | |
7767 _computeStyleProperties: function (scopeProps) { | |
7768 var scope = this._findStyleHost(); | |
7769 if (!scope._styleProperties) { | |
7770 scope._computeStyleProperties(); | |
7771 } | |
7772 var props = Object.create(scope._styleProperties); | |
7773 this.mixin(props, propertyUtils.hostPropertiesFromStyles(this._styles)); | |
7774 scopeProps = scopeProps || propertyUtils.propertyDataFromStyles(scope._styles, t
his).properties; | |
7775 this.mixin(props, scopeProps); | |
7776 this.mixin(props, propertyUtils.scopePropertiesFromStyles(this._styles)); | |
7777 propertyUtils.mixinCustomStyle(props, this.customStyle); | |
7778 propertyUtils.reify(props); | |
7779 this._styleProperties = props; | |
7780 }, | |
7781 _computeOwnStyleProperties: function () { | |
7782 var props = {}; | |
7783 for (var i = 0, n; i < this._ownStylePropertyNames.length; i++) { | |
7784 n = this._ownStylePropertyNames[i]; | |
7785 props[n] = this._styleProperties[n]; | |
7786 } | |
7787 this._ownStyleProperties = props; | |
7788 }, | |
7789 _scopeCount: 0, | |
7790 _applyStyleProperties: function (info) { | |
7791 var oldScopeSelector = this._scopeSelector; | |
7792 this._scopeSelector = info ? info._scopeSelector : this.is + '-' + this.__proto_
_._scopeCount++; | |
7793 var style = propertyUtils.applyElementStyle(this, this._styleProperties, this._s
copeSelector, info && info.style); | |
7794 if (!nativeShadow) { | |
7795 propertyUtils.applyElementScopeSelector(this, this._scopeSelector, oldScopeSelec
tor, this._scopeCssViaAttr); | |
7796 } | |
7797 return style; | |
7798 }, | |
7799 serializeValueToAttribute: function (value, attribute, node) { | |
7800 node = node || this; | |
7801 if (attribute === 'class' && !nativeShadow) { | |
7802 var host = node === this ? this.domHost || this.dataHost : this; | |
7803 if (host) { | |
7804 value = host._scopeElementClass(node, value); | |
7805 } | |
7806 } | |
7807 node = this.shadyRoot && this.shadyRoot._hasDistributed ? Polymer.dom(node) : no
de; | |
7808 serializeValueToAttribute.call(this, value, attribute, node); | |
7809 }, | |
7810 _scopeElementClass: function (element, selector) { | |
7811 if (!nativeShadow && !this._scopeCssViaAttr) { | |
7812 selector += (selector ? ' ' : '') + SCOPE_NAME + ' ' + this.is + (element._scope
Selector ? ' ' + XSCOPE_NAME + ' ' + element._scopeSelector : ''); | |
7813 } | |
7814 return selector; | |
7815 }, | |
7816 updateStyles: function (properties) { | |
7817 if (this.isAttached) { | |
7818 if (properties) { | |
7819 this.mixin(this.customStyle, properties); | |
7820 } | |
7821 if (this._needsStyleProperties()) { | |
7822 this._updateStyleProperties(); | |
7823 } else { | |
7824 this._styleProperties = null; | |
7825 } | |
7826 if (this._styleCache) { | |
7827 this._styleCache.clear(); | |
7828 } | |
7829 this._updateRootStyles(); | |
7830 } | |
7831 }, | |
7832 _updateRootStyles: function (root) { | |
7833 root = root || this.root; | |
7834 var c$ = Polymer.dom(root)._query(function (e) { | |
7835 return e.shadyRoot || e.shadowRoot; | |
7836 }); | |
7837 for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { | |
7838 if (c.updateStyles) { | |
7839 c.updateStyles(); | |
7840 } | |
7841 } | |
7842 } | |
7843 }); | |
7844 Polymer.updateStyles = function (properties) { | |
7845 styleDefaults.updateStyles(properties); | |
7846 Polymer.Base._updateRootStyles(document); | |
7847 }; | |
7848 var styleCache = new Polymer.StyleCache(); | |
7849 Polymer.customStyleCache = styleCache; | |
7850 var SCOPE_NAME = styleTransformer.SCOPE_NAME; | |
7851 var XSCOPE_NAME = propertyUtils.XSCOPE_NAME; | |
7852 }()); | |
7853 Polymer.Base._addFeature({ | |
7854 _registerFeatures: function () { | |
7855 this._prepIs(); | |
7856 this._prepConstructor(); | |
7857 this._prepTemplate(); | |
7858 this._prepStyles(); | |
7859 this._prepStyleProperties(); | |
7860 this._prepAnnotations(); | |
7861 this._prepEffects(); | |
7862 this._prepBehaviors(); | |
7863 this._prepPropertyInfo(); | |
7864 this._prepBindings(); | |
7865 this._prepShady(); | |
7866 }, | |
7867 _prepBehavior: function (b) { | |
7868 this._addPropertyEffects(b.properties); | |
7869 this._addComplexObserverEffects(b.observers); | |
7870 this._addHostAttributes(b.hostAttributes); | |
7871 }, | |
7872 _initFeatures: function () { | |
7873 this._setupConfigure(); | |
7874 this._setupStyleProperties(); | |
7875 this._setupDebouncers(); | |
7876 this._registerHost(); | |
7877 if (this._template) { | |
7878 this._poolContent(); | |
7879 this._beginHosting(); | |
7880 this._stampTemplate(); | |
7881 this._endHosting(); | |
7882 this._marshalAnnotationReferences(); | |
7883 } | |
7884 this._marshalInstanceEffects(); | |
7885 this._marshalBehaviors(); | |
7886 this._marshalHostAttributes(); | |
7887 this._marshalAttributes(); | |
7888 this._tryReady(); | |
7889 }, | |
7890 _marshalBehavior: function (b) { | |
7891 if (b.listeners) { | |
7892 this._listenListeners(b.listeners); | |
7893 } | |
7894 } | |
7895 }); | |
7896 (function () { | |
7897 var nativeShadow = Polymer.Settings.useNativeShadow; | |
7898 var propertyUtils = Polymer.StyleProperties; | |
7899 var styleUtil = Polymer.StyleUtil; | |
7900 var cssParse = Polymer.CssParse; | |
7901 var styleDefaults = Polymer.StyleDefaults; | |
7902 var styleTransformer = Polymer.StyleTransformer; | |
7903 Polymer({ | |
7904 is: 'custom-style', | |
7905 extends: 'style', | |
7906 _template: null, | |
7907 properties: { include: String }, | |
7908 ready: function () { | |
7909 this._tryApply(); | |
7910 }, | |
7911 attached: function () { | |
7912 this._tryApply(); | |
7913 }, | |
7914 _tryApply: function () { | |
7915 if (!this._appliesToDocument) { | |
7916 if (this.parentNode && this.parentNode.localName !== 'dom-module') { | |
7917 this._appliesToDocument = true; | |
7918 var e = this.__appliedElement || this; | |
7919 styleDefaults.addStyle(e); | |
7920 if (e.textContent || this.include) { | |
7921 this._apply(true); | |
7922 } else { | |
7923 var self = this; | |
7924 var observer = new MutationObserver(function () { | |
7925 observer.disconnect(); | |
7926 self._apply(true); | |
7927 }); | |
7928 observer.observe(e, { childList: true }); | |
7929 } | |
7930 } | |
7931 } | |
7932 }, | |
7933 _apply: function (deferProperties) { | |
7934 var e = this.__appliedElement || this; | |
7935 if (this.include) { | |
7936 e.textContent = styleUtil.cssFromModules(this.include, true) + e.textContent; | |
7937 } | |
7938 if (e.textContent) { | |
7939 styleUtil.forEachStyleRule(styleUtil.rulesForStyle(e), function (rule) { | |
7940 styleTransformer.documentRule(rule); | |
7941 }); | |
7942 var self = this; | |
7943 function fn() { | |
7944 self._applyCustomProperties(e); | |
7945 } | |
7946 if (this._pendingApplyProperties) { | |
7947 cancelAnimationFrame(this._pendingApplyProperties); | |
7948 this._pendingApplyProperties = null; | |
7949 } | |
7950 if (deferProperties) { | |
7951 this._pendingApplyProperties = requestAnimationFrame(fn); | |
7952 } else { | |
7953 fn(); | |
7954 } | |
7955 } | |
7956 }, | |
7957 _applyCustomProperties: function (element) { | |
7958 this._computeStyleProperties(); | |
7959 var props = this._styleProperties; | |
7960 var rules = styleUtil.rulesForStyle(element); | |
7961 element.textContent = styleUtil.toCssText(rules, function (rule) { | |
7962 var css = rule.cssText = rule.parsedCssText; | |
7963 if (rule.propertyInfo && rule.propertyInfo.cssText) { | |
7964 css = cssParse.removeCustomPropAssignment(css); | |
7965 rule.cssText = propertyUtils.valueForProperties(css, props); | |
7966 } | |
7967 }); | |
7968 } | |
7969 }); | |
7970 }()); | |
7971 Polymer.Templatizer = { | |
7972 properties: { __hideTemplateChildren__: { observer: '_showHideChildren' } }, | |
7973 _instanceProps: Polymer.nob, | |
7974 _parentPropPrefix: '_parent_', | |
7975 templatize: function (template) { | |
7976 this._templatized = template; | |
7977 if (!template._content) { | |
7978 template._content = template.content; | |
7979 } | |
7980 if (template._content._ctor) { | |
7981 this.ctor = template._content._ctor; | |
7982 this._prepParentProperties(this.ctor.prototype, template); | |
7983 return; | |
7984 } | |
7985 var archetype = Object.create(Polymer.Base); | |
7986 this._customPrepAnnotations(archetype, template); | |
7987 this._prepParentProperties(archetype, template); | |
7988 archetype._prepEffects(); | |
7989 this._customPrepEffects(archetype); | |
7990 archetype._prepBehaviors(); | |
7991 archetype._prepPropertyInfo(); | |
7992 archetype._prepBindings(); | |
7993 archetype._notifyPathUp = this._notifyPathUpImpl; | |
7994 archetype._scopeElementClass = this._scopeElementClassImpl; | |
7995 archetype.listen = this._listenImpl; | |
7996 archetype._showHideChildren = this._showHideChildrenImpl; | |
7997 var _constructor = this._constructorImpl; | |
7998 var ctor = function TemplateInstance(model, host) { | |
7999 _constructor.call(this, model, host); | |
8000 }; | |
8001 ctor.prototype = archetype; | |
8002 archetype.constructor = ctor; | |
8003 template._content._ctor = ctor; | |
8004 this.ctor = ctor; | |
8005 }, | |
8006 _getRootDataHost: function () { | |
8007 return this.dataHost && this.dataHost._rootDataHost || this.dataHost; | |
8008 }, | |
8009 _showHideChildrenImpl: function (hide) { | |
8010 var c = this._children; | |
8011 for (var i = 0; i < c.length; i++) { | |
8012 var n = c[i]; | |
8013 if (Boolean(hide) != Boolean(n.__hideTemplateChildren__)) { | |
8014 if (n.nodeType === Node.TEXT_NODE) { | |
8015 if (hide) { | |
8016 n.__polymerTextContent__ = n.textContent; | |
8017 n.textContent = ''; | |
8018 } else { | |
8019 n.textContent = n.__polymerTextContent__; | |
8020 } | |
8021 } else if (n.style) { | |
8022 if (hide) { | |
8023 n.__polymerDisplay__ = n.style.display; | |
8024 n.style.display = 'none'; | |
8025 } else { | |
8026 n.style.display = n.__polymerDisplay__; | |
8027 } | |
8028 } | |
8029 } | |
8030 n.__hideTemplateChildren__ = hide; | |
8031 } | |
8032 }, | |
8033 _debounceTemplate: function (fn) { | |
8034 Polymer.dom.addDebouncer(this.debounce('_debounceTemplate', fn)); | |
8035 }, | |
8036 _flushTemplates: function (debouncerExpired) { | |
8037 Polymer.dom.flush(); | |
8038 }, | |
8039 _customPrepEffects: function (archetype) { | |
8040 var parentProps = archetype._parentProps; | |
8041 for (var prop in parentProps) { | |
8042 archetype._addPropertyEffect(prop, 'function', this._createHostPropEffector(prop
)); | |
8043 } | |
8044 for (var prop in this._instanceProps) { | |
8045 archetype._addPropertyEffect(prop, 'function', this._createInstancePropEffector(
prop)); | |
8046 } | |
8047 }, | |
8048 _customPrepAnnotations: function (archetype, template) { | |
8049 archetype._template = template; | |
8050 var c = template._content; | |
8051 if (!c._notes) { | |
8052 var rootDataHost = archetype._rootDataHost; | |
8053 if (rootDataHost) { | |
8054 Polymer.Annotations.prepElement = function () { | |
8055 rootDataHost._prepElement(); | |
8056 }; | |
8057 } | |
8058 c._notes = Polymer.Annotations.parseAnnotations(template); | |
8059 Polymer.Annotations.prepElement = null; | |
8060 this._processAnnotations(c._notes); | |
8061 } | |
8062 archetype._notes = c._notes; | |
8063 archetype._parentProps = c._parentProps; | |
8064 }, | |
8065 _prepParentProperties: function (archetype, template) { | |
8066 var parentProps = this._parentProps = archetype._parentProps; | |
8067 if (this._forwardParentProp && parentProps) { | |
8068 var proto = archetype._parentPropProto; | |
8069 var prop; | |
8070 if (!proto) { | |
8071 for (prop in this._instanceProps) { | |
8072 delete parentProps[prop]; | |
8073 } | |
8074 proto = archetype._parentPropProto = Object.create(null); | |
8075 if (template != this) { | |
8076 Polymer.Bind.prepareModel(proto); | |
8077 Polymer.Base.prepareModelNotifyPath(proto); | |
8078 } | |
8079 for (prop in parentProps) { | |
8080 var parentProp = this._parentPropPrefix + prop; | |
8081 var effects = [ | |
8082 { | |
8083 kind: 'function', | |
8084 effect: this._createForwardPropEffector(prop), | |
8085 fn: Polymer.Bind._functionEffect | |
8086 }, | |
8087 { | |
8088 kind: 'notify', | |
8089 fn: Polymer.Bind._notifyEffect, | |
8090 effect: { event: Polymer.CaseMap.camelToDashCase(parentProp) + '-changed' } | |
8091 } | |
8092 ]; | |
8093 Polymer.Bind._createAccessors(proto, parentProp, effects); | |
8094 } | |
8095 } | |
8096 var self = this; | |
8097 if (template != this) { | |
8098 Polymer.Bind.prepareInstance(template); | |
8099 template._forwardParentProp = function (source, value) { | |
8100 self._forwardParentProp(source, value); | |
8101 }; | |
8102 } | |
8103 this._extendTemplate(template, proto); | |
8104 template._pathEffector = function (path, value, fromAbove) { | |
8105 return self._pathEffectorImpl(path, value, fromAbove); | |
8106 }; | |
8107 } | |
8108 }, | |
8109 _createForwardPropEffector: function (prop) { | |
8110 return function (source, value) { | |
8111 this._forwardParentProp(prop, value); | |
8112 }; | |
8113 }, | |
8114 _createHostPropEffector: function (prop) { | |
8115 var prefix = this._parentPropPrefix; | |
8116 return function (source, value) { | |
8117 this.dataHost._templatized[prefix + prop] = value; | |
8118 }; | |
8119 }, | |
8120 _createInstancePropEffector: function (prop) { | |
8121 return function (source, value, old, fromAbove) { | |
8122 if (!fromAbove) { | |
8123 this.dataHost._forwardInstanceProp(this, prop, value); | |
8124 } | |
8125 }; | |
8126 }, | |
8127 _extendTemplate: function (template, proto) { | |
8128 var n$ = Object.getOwnPropertyNames(proto); | |
8129 for (var i = 0, n; i < n$.length && (n = n$[i]); i++) { | |
8130 var val = template[n]; | |
8131 var pd = Object.getOwnPropertyDescriptor(proto, n); | |
8132 Object.defineProperty(template, n, pd); | |
8133 if (val !== undefined) { | |
8134 template._propertySetter(n, val); | |
8135 } | |
8136 } | |
8137 }, | |
8138 _showHideChildren: function (hidden) { | |
8139 }, | |
8140 _forwardInstancePath: function (inst, path, value) { | |
8141 }, | |
8142 _forwardInstanceProp: function (inst, prop, value) { | |
8143 }, | |
8144 _notifyPathUpImpl: function (path, value) { | |
8145 var dataHost = this.dataHost; | |
8146 var dot = path.indexOf('.'); | |
8147 var root = dot < 0 ? path : path.slice(0, dot); | |
8148 dataHost._forwardInstancePath.call(dataHost, this, path, value); | |
8149 if (root in dataHost._parentProps) { | |
8150 dataHost._templatized.notifyPath(dataHost._parentPropPrefix + path, value); | |
8151 } | |
8152 }, | |
8153 _pathEffectorImpl: function (path, value, fromAbove) { | |
8154 if (this._forwardParentPath) { | |
8155 if (path.indexOf(this._parentPropPrefix) === 0) { | |
8156 var subPath = path.substring(this._parentPropPrefix.length); | |
8157 var model = this._modelForPath(subPath); | |
8158 if (model in this._parentProps) { | |
8159 this._forwardParentPath(subPath, value); | |
8160 } | |
8161 } | |
8162 } | |
8163 Polymer.Base._pathEffector.call(this._templatized, path, value, fromAbove); | |
8164 }, | |
8165 _constructorImpl: function (model, host) { | |
8166 this._rootDataHost = host._getRootDataHost(); | |
8167 this._setupConfigure(model); | |
8168 this._registerHost(host); | |
8169 this._beginHosting(); | |
8170 this.root = this.instanceTemplate(this._template); | |
8171 this.root.__noContent = !this._notes._hasContent; | |
8172 this.root.__styleScoped = true; | |
8173 this._endHosting(); | |
8174 this._marshalAnnotatedNodes(); | |
8175 this._marshalInstanceEffects(); | |
8176 this._marshalAnnotatedListeners(); | |
8177 var children = []; | |
8178 for (var n = this.root.firstChild; n; n = n.nextSibling) { | |
8179 children.push(n); | |
8180 n._templateInstance = this; | |
8181 } | |
8182 this._children = children; | |
8183 if (host.__hideTemplateChildren__) { | |
8184 this._showHideChildren(true); | |
8185 } | |
8186 this._tryReady(); | |
8187 }, | |
8188 _listenImpl: function (node, eventName, methodName) { | |
8189 var model = this; | |
8190 var host = this._rootDataHost; | |
8191 var handler = host._createEventHandler(node, eventName, methodName); | |
8192 var decorated = function (e) { | |
8193 e.model = model; | |
8194 handler(e); | |
8195 }; | |
8196 host._listen(node, eventName, decorated); | |
8197 }, | |
8198 _scopeElementClassImpl: function (node, value) { | |
8199 var host = this._rootDataHost; | |
8200 if (host) { | |
8201 return host._scopeElementClass(node, value); | |
8202 } | |
8203 }, | |
8204 stamp: function (model) { | |
8205 model = model || {}; | |
8206 if (this._parentProps) { | |
8207 var templatized = this._templatized; | |
8208 for (var prop in this._parentProps) { | |
8209 model[prop] = templatized[this._parentPropPrefix + prop]; | |
8210 } | |
8211 } | |
8212 return new this.ctor(model, this); | |
8213 }, | |
8214 modelForElement: function (el) { | |
8215 var model; | |
8216 while (el) { | |
8217 if (model = el._templateInstance) { | |
8218 if (model.dataHost != this) { | |
8219 el = model.dataHost; | |
8220 } else { | |
8221 return model; | |
8222 } | |
8223 } else { | |
8224 el = el.parentNode; | |
8225 } | |
8226 } | |
8227 } | |
8228 }; | |
8229 Polymer({ | |
8230 is: 'dom-template', | |
8231 extends: 'template', | |
8232 _template: null, | |
8233 behaviors: [Polymer.Templatizer], | |
8234 ready: function () { | |
8235 this.templatize(this); | |
8236 } | |
8237 }); | |
8238 Polymer._collections = new WeakMap(); | |
8239 Polymer.Collection = function (userArray) { | |
8240 Polymer._collections.set(userArray, this); | |
8241 this.userArray = userArray; | |
8242 this.store = userArray.slice(); | |
8243 this.initMap(); | |
8244 }; | |
8245 Polymer.Collection.prototype = { | |
8246 constructor: Polymer.Collection, | |
8247 initMap: function () { | |
8248 var omap = this.omap = new WeakMap(); | |
8249 var pmap = this.pmap = {}; | |
8250 var s = this.store; | |
8251 for (var i = 0; i < s.length; i++) { | |
8252 var item = s[i]; | |
8253 if (item && typeof item == 'object') { | |
8254 omap.set(item, i); | |
8255 } else { | |
8256 pmap[item] = i; | |
8257 } | |
8258 } | |
8259 }, | |
8260 add: function (item) { | |
8261 var key = this.store.push(item) - 1; | |
8262 if (item && typeof item == 'object') { | |
8263 this.omap.set(item, key); | |
8264 } else { | |
8265 this.pmap[item] = key; | |
8266 } | |
8267 return '#' + key; | |
8268 }, | |
8269 removeKey: function (key) { | |
8270 key = this._parseKey(key); | |
8271 this._removeFromMap(this.store[key]); | |
8272 delete this.store[key]; | |
8273 }, | |
8274 _removeFromMap: function (item) { | |
8275 if (item && typeof item == 'object') { | |
8276 this.omap.delete(item); | |
8277 } else { | |
8278 delete this.pmap[item]; | |
8279 } | |
8280 }, | |
8281 remove: function (item) { | |
8282 var key = this.getKey(item); | |
8283 this.removeKey(key); | |
8284 return key; | |
8285 }, | |
8286 getKey: function (item) { | |
8287 var key; | |
8288 if (item && typeof item == 'object') { | |
8289 key = this.omap.get(item); | |
8290 } else { | |
8291 key = this.pmap[item]; | |
8292 } | |
8293 if (key != undefined) { | |
8294 return '#' + key; | |
8295 } | |
8296 }, | |
8297 getKeys: function () { | |
8298 return Object.keys(this.store).map(function (key) { | |
8299 return '#' + key; | |
8300 }); | |
8301 }, | |
8302 _parseKey: function (key) { | |
8303 if (key[0] == '#') { | |
8304 return key.slice(1); | |
8305 } | |
8306 throw new Error('unexpected key ' + key); | |
8307 }, | |
8308 setItem: function (key, item) { | |
8309 key = this._parseKey(key); | |
8310 var old = this.store[key]; | |
8311 if (old) { | |
8312 this._removeFromMap(old); | |
8313 } | |
8314 if (item && typeof item == 'object') { | |
8315 this.omap.set(item, key); | |
8316 } else { | |
8317 this.pmap[item] = key; | |
8318 } | |
8319 this.store[key] = item; | |
8320 }, | |
8321 getItem: function (key) { | |
8322 key = this._parseKey(key); | |
8323 return this.store[key]; | |
8324 }, | |
8325 getItems: function () { | |
8326 var items = [], store = this.store; | |
8327 for (var key in store) { | |
8328 items.push(store[key]); | |
8329 } | |
8330 return items; | |
8331 }, | |
8332 _applySplices: function (splices) { | |
8333 var keyMap = {}, key; | |
8334 for (var i = 0, s; i < splices.length && (s = splices[i]); i++) { | |
8335 s.addedKeys = []; | |
8336 for (var j = 0; j < s.removed.length; j++) { | |
8337 key = this.getKey(s.removed[j]); | |
8338 keyMap[key] = keyMap[key] ? null : -1; | |
8339 } | |
8340 for (var j = 0; j < s.addedCount; j++) { | |
8341 var item = this.userArray[s.index + j]; | |
8342 key = this.getKey(item); | |
8343 key = key === undefined ? this.add(item) : key; | |
8344 keyMap[key] = keyMap[key] ? null : 1; | |
8345 s.addedKeys.push(key); | |
8346 } | |
8347 } | |
8348 var removed = []; | |
8349 var added = []; | |
8350 for (var key in keyMap) { | |
8351 if (keyMap[key] < 0) { | |
8352 this.removeKey(key); | |
8353 removed.push(key); | |
8354 } | |
8355 if (keyMap[key] > 0) { | |
8356 added.push(key); | |
8357 } | |
8358 } | |
8359 return [{ | |
8360 removed: removed, | |
8361 added: added | |
8362 }]; | |
8363 } | |
8364 }; | |
8365 Polymer.Collection.get = function (userArray) { | |
8366 return Polymer._collections.get(userArray) || new Polymer.Collection(userArray); | |
8367 }; | |
8368 Polymer.Collection.applySplices = function (userArray, splices) { | |
8369 var coll = Polymer._collections.get(userArray); | |
8370 return coll ? coll._applySplices(splices) : null; | |
8371 }; | |
8372 Polymer({ | |
8373 is: 'dom-repeat', | |
8374 extends: 'template', | |
8375 _template: null, | |
8376 properties: { | |
8377 items: { type: Array }, | |
8378 as: { | |
8379 type: String, | |
8380 value: 'item' | |
8381 }, | |
8382 indexAs: { | |
8383 type: String, | |
8384 value: 'index' | |
8385 }, | |
8386 sort: { | |
8387 type: Function, | |
8388 observer: '_sortChanged' | |
8389 }, | |
8390 filter: { | |
8391 type: Function, | |
8392 observer: '_filterChanged' | |
8393 }, | |
8394 observe: { | |
8395 type: String, | |
8396 observer: '_observeChanged' | |
8397 }, | |
8398 delay: Number, | |
8399 initialCount: { | |
8400 type: Number, | |
8401 observer: '_initializeChunking' | |
8402 }, | |
8403 targetFramerate: { | |
8404 type: Number, | |
8405 value: 20 | |
8406 }, | |
8407 _targetFrameTime: { computed: '_computeFrameTime(targetFramerate)' } | |
8408 }, | |
8409 behaviors: [Polymer.Templatizer], | |
8410 observers: ['_itemsChanged(items.*)'], | |
8411 created: function () { | |
8412 this._instances = []; | |
8413 this._pool = []; | |
8414 this._limit = Infinity; | |
8415 var self = this; | |
8416 this._boundRenderChunk = function () { | |
8417 self._renderChunk(); | |
8418 }; | |
8419 }, | |
8420 detached: function () { | |
8421 for (var i = 0; i < this._instances.length; i++) { | |
8422 this._detachInstance(i); | |
8423 } | |
8424 }, | |
8425 attached: function () { | |
8426 var parent = Polymer.dom(Polymer.dom(this).parentNode); | |
8427 for (var i = 0; i < this._instances.length; i++) { | |
8428 this._attachInstance(i, parent); | |
8429 } | |
8430 }, | |
8431 ready: function () { | |
8432 this._instanceProps = { __key__: true }; | |
8433 this._instanceProps[this.as] = true; | |
8434 this._instanceProps[this.indexAs] = true; | |
8435 if (!this.ctor) { | |
8436 this.templatize(this); | |
8437 } | |
8438 }, | |
8439 _sortChanged: function (sort) { | |
8440 var dataHost = this._getRootDataHost(); | |
8441 this._sortFn = sort && (typeof sort == 'function' ? sort : function () { | |
8442 return dataHost[sort].apply(dataHost, arguments); | |
8443 }); | |
8444 this._needFullRefresh = true; | |
8445 if (this.items) { | |
8446 this._debounceTemplate(this._render); | |
8447 } | |
8448 }, | |
8449 _filterChanged: function (filter) { | |
8450 var dataHost = this._getRootDataHost(); | |
8451 this._filterFn = filter && (typeof filter == 'function' ? filter : function () { | |
8452 return dataHost[filter].apply(dataHost, arguments); | |
8453 }); | |
8454 this._needFullRefresh = true; | |
8455 if (this.items) { | |
8456 this._debounceTemplate(this._render); | |
8457 } | |
8458 }, | |
8459 _computeFrameTime: function (rate) { | |
8460 return Math.ceil(1000 / rate); | |
8461 }, | |
8462 _initializeChunking: function () { | |
8463 if (this.initialCount) { | |
8464 this._limit = this.initialCount; | |
8465 this._chunkCount = this.initialCount; | |
8466 this._lastChunkTime = performance.now(); | |
8467 } | |
8468 }, | |
8469 _tryRenderChunk: function () { | |
8470 if (this.items && this._limit < this.items.length) { | |
8471 this.debounce('renderChunk', this._requestRenderChunk); | |
8472 } | |
8473 }, | |
8474 _requestRenderChunk: function () { | |
8475 requestAnimationFrame(this._boundRenderChunk); | |
8476 }, | |
8477 _renderChunk: function () { | |
8478 var currChunkTime = performance.now(); | |
8479 var ratio = this._targetFrameTime / (currChunkTime - this._lastChunkTime); | |
8480 this._chunkCount = Math.round(this._chunkCount * ratio) || 1; | |
8481 this._limit += this._chunkCount; | |
8482 this._lastChunkTime = currChunkTime; | |
8483 this._debounceTemplate(this._render); | |
8484 }, | |
8485 _observeChanged: function () { | |
8486 this._observePaths = this.observe && this.observe.replace('.*', '.').split(' '); | |
8487 }, | |
8488 _itemsChanged: function (change) { | |
8489 if (change.path == 'items') { | |
8490 if (Array.isArray(this.items)) { | |
8491 this.collection = Polymer.Collection.get(this.items); | |
8492 } else if (!this.items) { | |
8493 this.collection = null; | |
8494 } else { | |
8495 this._error(this._logf('dom-repeat', 'expected array for `items`,' + ' found', t
his.items)); | |
8496 } | |
8497 this._keySplices = []; | |
8498 this._indexSplices = []; | |
8499 this._needFullRefresh = true; | |
8500 this._initializeChunking(); | |
8501 this._debounceTemplate(this._render); | |
8502 } else if (change.path == 'items.splices') { | |
8503 this._keySplices = this._keySplices.concat(change.value.keySplices); | |
8504 this._indexSplices = this._indexSplices.concat(change.value.indexSplices); | |
8505 this._debounceTemplate(this._render); | |
8506 } else { | |
8507 var subpath = change.path.slice(6); | |
8508 this._forwardItemPath(subpath, change.value); | |
8509 this._checkObservedPaths(subpath); | |
8510 } | |
8511 }, | |
8512 _checkObservedPaths: function (path) { | |
8513 if (this._observePaths) { | |
8514 path = path.substring(path.indexOf('.') + 1); | |
8515 var paths = this._observePaths; | |
8516 for (var i = 0; i < paths.length; i++) { | |
8517 if (path.indexOf(paths[i]) === 0) { | |
8518 this._needFullRefresh = true; | |
8519 if (this.delay) { | |
8520 this.debounce('render', this._render, this.delay); | |
8521 } else { | |
8522 this._debounceTemplate(this._render); | |
8523 } | |
8524 return; | |
8525 } | |
8526 } | |
8527 } | |
8528 }, | |
8529 render: function () { | |
8530 this._needFullRefresh = true; | |
8531 this._debounceTemplate(this._render); | |
8532 this._flushTemplates(); | |
8533 }, | |
8534 _render: function () { | |
8535 var c = this.collection; | |
8536 if (this._needFullRefresh) { | |
8537 this._applyFullRefresh(); | |
8538 this._needFullRefresh = false; | |
8539 } else if (this._keySplices.length) { | |
8540 if (this._sortFn) { | |
8541 this._applySplicesUserSort(this._keySplices); | |
8542 } else { | |
8543 if (this._filterFn) { | |
8544 this._applyFullRefresh(); | |
8545 } else { | |
8546 this._applySplicesArrayOrder(this._indexSplices); | |
8547 } | |
8548 } | |
8549 } else { | |
8550 } | |
8551 this._keySplices = []; | |
8552 this._indexSplices = []; | |
8553 var keyToIdx = this._keyToInstIdx = {}; | |
8554 for (var i = this._instances.length - 1; i >= 0; i--) { | |
8555 var inst = this._instances[i]; | |
8556 if (inst.isPlaceholder && i < this._limit) { | |
8557 inst = this._insertInstance(i, inst.__key__); | |
8558 } else if (!inst.isPlaceholder && i >= this._limit) { | |
8559 inst = this._downgradeInstance(i, inst.__key__); | |
8560 } | |
8561 keyToIdx[inst.__key__] = i; | |
8562 if (!inst.isPlaceholder) { | |
8563 inst.__setProperty(this.indexAs, i, true); | |
8564 } | |
8565 } | |
8566 this._pool.length = 0; | |
8567 this.fire('dom-change'); | |
8568 this._tryRenderChunk(); | |
8569 }, | |
8570 _applyFullRefresh: function () { | |
8571 var c = this.collection; | |
8572 var keys; | |
8573 if (this._sortFn) { | |
8574 keys = c ? c.getKeys() : []; | |
8575 } else { | |
8576 keys = []; | |
8577 var items = this.items; | |
8578 if (items) { | |
8579 for (var i = 0; i < items.length; i++) { | |
8580 keys.push(c.getKey(items[i])); | |
8581 } | |
8582 } | |
8583 } | |
8584 var self = this; | |
8585 if (this._filterFn) { | |
8586 keys = keys.filter(function (a) { | |
8587 return self._filterFn(c.getItem(a)); | |
8588 }); | |
8589 } | |
8590 if (this._sortFn) { | |
8591 keys.sort(function (a, b) { | |
8592 return self._sortFn(c.getItem(a), c.getItem(b)); | |
8593 }); | |
8594 } | |
8595 for (var i = 0; i < keys.length; i++) { | |
8596 var key = keys[i]; | |
8597 var inst = this._instances[i]; | |
8598 if (inst) { | |
8599 inst.__key__ = key; | |
8600 if (!inst.isPlaceholder && i < this._limit) { | |
8601 inst.__setProperty(this.as, c.getItem(key), true); | |
8602 } | |
8603 } else if (i < this._limit) { | |
8604 this._insertInstance(i, key); | |
8605 } else { | |
8606 this._insertPlaceholder(i, key); | |
8607 } | |
8608 } | |
8609 for (var j = this._instances.length - 1; j >= i; j--) { | |
8610 this._detachAndRemoveInstance(j); | |
8611 } | |
8612 }, | |
8613 _numericSort: function (a, b) { | |
8614 return a - b; | |
8615 }, | |
8616 _applySplicesUserSort: function (splices) { | |
8617 var c = this.collection; | |
8618 var instances = this._instances; | |
8619 var keyMap = {}; | |
8620 for (var i = 0, s; i < splices.length && (s = splices[i]); i++) { | |
8621 for (var j = 0; j < s.removed.length; j++) { | |
8622 var key = s.removed[j]; | |
8623 keyMap[key] = keyMap[key] ? null : -1; | |
8624 } | |
8625 for (var j = 0; j < s.added.length; j++) { | |
8626 var key = s.added[j]; | |
8627 keyMap[key] = keyMap[key] ? null : 1; | |
8628 } | |
8629 } | |
8630 var removedIdxs = []; | |
8631 var addedKeys = []; | |
8632 for (var key in keyMap) { | |
8633 if (keyMap[key] === -1) { | |
8634 removedIdxs.push(this._keyToInstIdx[key]); | |
8635 } | |
8636 if (keyMap[key] === 1) { | |
8637 addedKeys.push(key); | |
8638 } | |
8639 } | |
8640 if (removedIdxs.length) { | |
8641 removedIdxs.sort(this._numericSort); | |
8642 for (var i = removedIdxs.length - 1; i >= 0; i--) { | |
8643 var idx = removedIdxs[i]; | |
8644 if (idx !== undefined) { | |
8645 this._detachAndRemoveInstance(idx); | |
8646 } | |
8647 } | |
8648 } | |
8649 var self = this; | |
8650 if (addedKeys.length) { | |
8651 if (this._filterFn) { | |
8652 addedKeys = addedKeys.filter(function (a) { | |
8653 return self._filterFn(c.getItem(a)); | |
8654 }); | |
8655 } | |
8656 addedKeys.sort(function (a, b) { | |
8657 return self._sortFn(c.getItem(a), c.getItem(b)); | |
8658 }); | |
8659 var start = 0; | |
8660 for (var i = 0; i < addedKeys.length; i++) { | |
8661 start = this._insertRowUserSort(start, addedKeys[i]); | |
8662 } | |
8663 } | |
8664 }, | |
8665 _insertRowUserSort: function (start, key) { | |
8666 var c = this.collection; | |
8667 var item = c.getItem(key); | |
8668 var end = this._instances.length - 1; | |
8669 var idx = -1; | |
8670 while (start <= end) { | |
8671 var mid = start + end >> 1; | |
8672 var midKey = this._instances[mid].__key__; | |
8673 var cmp = this._sortFn(c.getItem(midKey), item); | |
8674 if (cmp < 0) { | |
8675 start = mid + 1; | |
8676 } else if (cmp > 0) { | |
8677 end = mid - 1; | |
8678 } else { | |
8679 idx = mid; | |
8680 break; | |
8681 } | |
8682 } | |
8683 if (idx < 0) { | |
8684 idx = end + 1; | |
8685 } | |
8686 this._insertPlaceholder(idx, key); | |
8687 return idx; | |
8688 }, | |
8689 _applySplicesArrayOrder: function (splices) { | |
8690 var c = this.collection; | |
8691 for (var i = 0, s; i < splices.length && (s = splices[i]); i++) { | |
8692 for (var j = 0; j < s.removed.length; j++) { | |
8693 this._detachAndRemoveInstance(s.index); | |
8694 } | |
8695 for (var j = 0; j < s.addedKeys.length; j++) { | |
8696 this._insertPlaceholder(s.index + j, s.addedKeys[j]); | |
8697 } | |
8698 } | |
8699 }, | |
8700 _detachInstance: function (idx) { | |
8701 var inst = this._instances[idx]; | |
8702 if (!inst.isPlaceholder) { | |
8703 for (var i = 0; i < inst._children.length; i++) { | |
8704 var el = inst._children[i]; | |
8705 Polymer.dom(inst.root).appendChild(el); | |
8706 } | |
8707 return inst; | |
8708 } | |
8709 }, | |
8710 _attachInstance: function (idx, parent) { | |
8711 var inst = this._instances[idx]; | |
8712 if (!inst.isPlaceholder) { | |
8713 parent.insertBefore(inst.root, this); | |
8714 } | |
8715 }, | |
8716 _detachAndRemoveInstance: function (idx) { | |
8717 var inst = this._detachInstance(idx); | |
8718 if (inst) { | |
8719 this._pool.push(inst); | |
8720 } | |
8721 this._instances.splice(idx, 1); | |
8722 }, | |
8723 _insertPlaceholder: function (idx, key) { | |
8724 this._instances.splice(idx, 0, { | |
8725 isPlaceholder: true, | |
8726 __key__: key | |
8727 }); | |
8728 }, | |
8729 _stampInstance: function (idx, key) { | |
8730 var model = { __key__: key }; | |
8731 model[this.as] = this.collection.getItem(key); | |
8732 model[this.indexAs] = idx; | |
8733 return this.stamp(model); | |
8734 }, | |
8735 _insertInstance: function (idx, key) { | |
8736 var inst = this._pool.pop(); | |
8737 if (inst) { | |
8738 inst.__setProperty(this.as, this.collection.getItem(key), true); | |
8739 inst.__setProperty('__key__', key, true); | |
8740 } else { | |
8741 inst = this._stampInstance(idx, key); | |
8742 } | |
8743 var beforeRow = this._instances[idx + 1]; | |
8744 var beforeNode = beforeRow && !beforeRow.isPlaceholder ? beforeRow._children[0]
: this; | |
8745 var parentNode = Polymer.dom(this).parentNode; | |
8746 Polymer.dom(parentNode).insertBefore(inst.root, beforeNode); | |
8747 this._instances[idx] = inst; | |
8748 return inst; | |
8749 }, | |
8750 _downgradeInstance: function (idx, key) { | |
8751 var inst = this._detachInstance(idx); | |
8752 if (inst) { | |
8753 this._pool.push(inst); | |
8754 } | |
8755 inst = { | |
8756 isPlaceholder: true, | |
8757 __key__: key | |
8758 }; | |
8759 this._instances[idx] = inst; | |
8760 return inst; | |
8761 }, | |
8762 _showHideChildren: function (hidden) { | |
8763 for (var i = 0; i < this._instances.length; i++) { | |
8764 this._instances[i]._showHideChildren(hidden); | |
8765 } | |
8766 }, | |
8767 _forwardInstanceProp: function (inst, prop, value) { | |
8768 if (prop == this.as) { | |
8769 var idx; | |
8770 if (this._sortFn || this._filterFn) { | |
8771 idx = this.items.indexOf(this.collection.getItem(inst.__key__)); | |
8772 } else { | |
8773 idx = inst[this.indexAs]; | |
8774 } | |
8775 this.set('items.' + idx, value); | |
8776 } | |
8777 }, | |
8778 _forwardInstancePath: function (inst, path, value) { | |
8779 if (path.indexOf(this.as + '.') === 0) { | |
8780 this._notifyPath('items.' + inst.__key__ + '.' + path.slice(this.as.length + 1),
value); | |
8781 } | |
8782 }, | |
8783 _forwardParentProp: function (prop, value) { | |
8784 var i$ = this._instances; | |
8785 for (var i = 0, inst; i < i$.length && (inst = i$[i]); i++) { | |
8786 if (!inst.isPlaceholder) { | |
8787 inst.__setProperty(prop, value, true); | |
8788 } | |
8789 } | |
8790 }, | |
8791 _forwardParentPath: function (path, value) { | |
8792 var i$ = this._instances; | |
8793 for (var i = 0, inst; i < i$.length && (inst = i$[i]); i++) { | |
8794 if (!inst.isPlaceholder) { | |
8795 inst._notifyPath(path, value, true); | |
8796 } | |
8797 } | |
8798 }, | |
8799 _forwardItemPath: function (path, value) { | |
8800 if (this._keyToInstIdx) { | |
8801 var dot = path.indexOf('.'); | |
8802 var key = path.substring(0, dot < 0 ? path.length : dot); | |
8803 var idx = this._keyToInstIdx[key]; | |
8804 var inst = this._instances[idx]; | |
8805 if (inst && !inst.isPlaceholder) { | |
8806 if (dot >= 0) { | |
8807 path = this.as + '.' + path.substring(dot + 1); | |
8808 inst._notifyPath(path, value, true); | |
8809 } else { | |
8810 inst.__setProperty(this.as, value, true); | |
8811 } | |
8812 } | |
8813 } | |
8814 }, | |
8815 itemForElement: function (el) { | |
8816 var instance = this.modelForElement(el); | |
8817 return instance && instance[this.as]; | |
8818 }, | |
8819 keyForElement: function (el) { | |
8820 var instance = this.modelForElement(el); | |
8821 return instance && instance.__key__; | |
8822 }, | |
8823 indexForElement: function (el) { | |
8824 var instance = this.modelForElement(el); | |
8825 return instance && instance[this.indexAs]; | |
8826 } | |
8827 }); | |
8828 Polymer({ | |
8829 is: 'array-selector', | |
8830 _template: null, | |
8831 properties: { | |
8832 items: { | |
8833 type: Array, | |
8834 observer: 'clearSelection' | |
8835 }, | |
8836 multi: { | |
8837 type: Boolean, | |
8838 value: false, | |
8839 observer: 'clearSelection' | |
8840 }, | |
8841 selected: { | |
8842 type: Object, | |
8843 notify: true | |
8844 }, | |
8845 selectedItem: { | |
8846 type: Object, | |
8847 notify: true | |
8848 }, | |
8849 toggle: { | |
8850 type: Boolean, | |
8851 value: false | |
8852 } | |
8853 }, | |
8854 clearSelection: function () { | |
8855 if (Array.isArray(this.selected)) { | |
8856 for (var i = 0; i < this.selected.length; i++) { | |
8857 this.unlinkPaths('selected.' + i); | |
8858 } | |
8859 } else { | |
8860 this.unlinkPaths('selected'); | |
8861 this.unlinkPaths('selectedItem'); | |
8862 } | |
8863 if (this.multi) { | |
8864 if (!this.selected || this.selected.length) { | |
8865 this.selected = []; | |
8866 this._selectedColl = Polymer.Collection.get(this.selected); | |
8867 } | |
8868 } else { | |
8869 this.selected = null; | |
8870 this._selectedColl = null; | |
8871 } | |
8872 this.selectedItem = null; | |
8873 }, | |
8874 isSelected: function (item) { | |
8875 if (this.multi) { | |
8876 return this._selectedColl.getKey(item) !== undefined; | |
8877 } else { | |
8878 return this.selected == item; | |
8879 } | |
8880 }, | |
8881 deselect: function (item) { | |
8882 if (this.multi) { | |
8883 if (this.isSelected(item)) { | |
8884 var skey = this._selectedColl.getKey(item); | |
8885 this.arrayDelete('selected', item); | |
8886 this.unlinkPaths('selected.' + skey); | |
8887 } | |
8888 } else { | |
8889 this.selected = null; | |
8890 this.selectedItem = null; | |
8891 this.unlinkPaths('selected'); | |
8892 this.unlinkPaths('selectedItem'); | |
8893 } | |
8894 }, | |
8895 select: function (item) { | |
8896 var icol = Polymer.Collection.get(this.items); | |
8897 var key = icol.getKey(item); | |
8898 if (this.multi) { | |
8899 if (this.isSelected(item)) { | |
8900 if (this.toggle) { | |
8901 this.deselect(item); | |
8902 } | |
8903 } else { | |
8904 this.push('selected', item); | |
8905 var skey = this._selectedColl.getKey(item); | |
8906 this.linkPaths('selected.' + skey, 'items.' + key); | |
8907 } | |
8908 } else { | |
8909 if (this.toggle && item == this.selected) { | |
8910 this.deselect(); | |
8911 } else { | |
8912 this.selected = item; | |
8913 this.selectedItem = item; | |
8914 this.linkPaths('selected', 'items.' + key); | |
8915 this.linkPaths('selectedItem', 'items.' + key); | |
8916 } | |
8917 } | |
8918 } | |
8919 }); | |
8920 Polymer({ | |
8921 is: 'dom-if', | |
8922 extends: 'template', | |
8923 _template: null, | |
8924 properties: { | |
8925 'if': { | |
8926 type: Boolean, | |
8927 value: false, | |
8928 observer: '_queueRender' | |
8929 }, | |
8930 restamp: { | |
8931 type: Boolean, | |
8932 value: false, | |
8933 observer: '_queueRender' | |
8934 } | |
8935 }, | |
8936 behaviors: [Polymer.Templatizer], | |
8937 _queueRender: function () { | |
8938 this._debounceTemplate(this._render); | |
8939 }, | |
8940 detached: function () { | |
8941 this._teardownInstance(); | |
8942 }, | |
8943 attached: function () { | |
8944 if (this.if && this.ctor) { | |
8945 this.async(this._ensureInstance); | |
8946 } | |
8947 }, | |
8948 render: function () { | |
8949 this._flushTemplates(); | |
8950 }, | |
8951 _render: function () { | |
8952 if (this.if) { | |
8953 if (!this.ctor) { | |
8954 this.templatize(this); | |
8955 } | |
8956 this._ensureInstance(); | |
8957 this._showHideChildren(); | |
8958 } else if (this.restamp) { | |
8959 this._teardownInstance(); | |
8960 } | |
8961 if (!this.restamp && this._instance) { | |
8962 this._showHideChildren(); | |
8963 } | |
8964 if (this.if != this._lastIf) { | |
8965 this.fire('dom-change'); | |
8966 this._lastIf = this.if; | |
8967 } | |
8968 }, | |
8969 _ensureInstance: function () { | |
8970 if (!this._instance) { | |
8971 var parentNode = Polymer.dom(this).parentNode; | |
8972 if (parentNode) { | |
8973 var parent = Polymer.dom(parentNode); | |
8974 this._instance = this.stamp(); | |
8975 var root = this._instance.root; | |
8976 parent.insertBefore(root, this); | |
8977 } | |
8978 } | |
8979 }, | |
8980 _teardownInstance: function () { | |
8981 if (this._instance) { | |
8982 var c$ = this._instance._children; | |
8983 if (c$) { | |
8984 var parent = Polymer.dom(Polymer.dom(c$[0]).parentNode); | |
8985 for (var i = 0, n; i < c$.length && (n = c$[i]); i++) { | |
8986 parent.removeChild(n); | |
8987 } | |
8988 } | |
8989 this._instance = null; | |
8990 } | |
8991 }, | |
8992 _showHideChildren: function () { | |
8993 var hidden = this.__hideTemplateChildren__ || !this.if; | |
8994 if (this._instance) { | |
8995 this._instance._showHideChildren(hidden); | |
8996 } | |
8997 }, | |
8998 _forwardParentProp: function (prop, value) { | |
8999 if (this._instance) { | |
9000 this._instance[prop] = value; | |
9001 } | |
9002 }, | |
9003 _forwardParentPath: function (path, value) { | |
9004 if (this._instance) { | |
9005 this._instance._notifyPath(path, value, true); | |
9006 } | |
9007 } | |
9008 }); | |
9009 Polymer({ | |
9010 is: 'dom-bind', | |
9011 extends: 'template', | |
9012 _template: null, | |
9013 created: function () { | |
9014 var self = this; | |
9015 Polymer.RenderStatus.whenReady(function () { | |
9016 self._markImportsReady(); | |
9017 }); | |
9018 }, | |
9019 _ensureReady: function () { | |
9020 if (!this._readied) { | |
9021 this._readySelf(); | |
9022 } | |
9023 }, | |
9024 _markImportsReady: function () { | |
9025 this._importsReady = true; | |
9026 this._ensureReady(); | |
9027 }, | |
9028 _registerFeatures: function () { | |
9029 this._prepConstructor(); | |
9030 }, | |
9031 _insertChildren: function () { | |
9032 var parentDom = Polymer.dom(Polymer.dom(this).parentNode); | |
9033 parentDom.insertBefore(this.root, this); | |
9034 }, | |
9035 _removeChildren: function () { | |
9036 if (this._children) { | |
9037 for (var i = 0; i < this._children.length; i++) { | |
9038 this.root.appendChild(this._children[i]); | |
9039 } | |
9040 } | |
9041 }, | |
9042 _initFeatures: function () { | |
9043 }, | |
9044 _scopeElementClass: function (element, selector) { | |
9045 if (this.dataHost) { | |
9046 return this.dataHost._scopeElementClass(element, selector); | |
9047 } else { | |
9048 return selector; | |
9049 } | |
9050 }, | |
9051 _prepConfigure: function () { | |
9052 var config = {}; | |
9053 for (var prop in this._propertyEffects) { | |
9054 config[prop] = this[prop]; | |
9055 } | |
9056 var setupConfigure = this._setupConfigure; | |
9057 this._setupConfigure = function () { | |
9058 setupConfigure.call(this, config); | |
9059 }; | |
9060 }, | |
9061 attached: function () { | |
9062 if (this._importsReady) { | |
9063 this.render(); | |
9064 } | |
9065 }, | |
9066 detached: function () { | |
9067 this._removeChildren(); | |
9068 }, | |
9069 render: function () { | |
9070 this._ensureReady(); | |
9071 if (!this._children) { | |
9072 this._template = this; | |
9073 this._prepAnnotations(); | |
9074 this._prepEffects(); | |
9075 this._prepBehaviors(); | |
9076 this._prepConfigure(); | |
9077 this._prepBindings(); | |
9078 this._prepPropertyInfo(); | |
9079 Polymer.Base._initFeatures.call(this); | |
9080 this._children = Polymer.DomApi.arrayCopyChildNodes(this.root); | |
9081 } | |
9082 this._insertChildren(); | |
9083 this.fire('dom-change'); | |
9084 } | |
9085 }); | |
9086 /** | 1801 /** |
9087 * `IronResizableBehavior` is a behavior that can be used in Polymer elements
to | 1802 * `IronResizableBehavior` is a behavior that can be used in Polymer elements
to |
9088 * coordinate the flow of resize events between "resizers" (elements that cont
rol the | 1803 * coordinate the flow of resize events between "resizers" (elements that cont
rol the |
9089 * size or hidden state of their children) and "resizables" (elements that nee
d to be | 1804 * size or hidden state of their children) and "resizables" (elements that nee
d to be |
9090 * notified when they are resized or un-hidden by their parents in order to ta
ke | 1805 * notified when they are resized or un-hidden by their parents in order to ta
ke |
9091 * action on their new measurements). | 1806 * action on their new measurements). |
9092 * Elements that perform measurement should add the `IronResizableBehavior` be
havior to | 1807 * Elements that perform measurement should add the `IronResizableBehavior` be
havior to |
9093 * their element definition and listen for the `iron-resize` event on themselv
es. | 1808 * their element definition and listen for the `iron-resize` event on themselv
es. |
9094 * This event will be fired when they become showing after having been hidden, | 1809 * This event will be fired when they become showing after having been hidden, |
9095 * when they are resized explicitly by another resizable, or when the window h
as been | 1810 * when they are resized explicitly by another resizable, or when the window h
as been |
(...skipping 8139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17235 Manager.get().updateItem_(index, data); | 9950 Manager.get().updateItem_(index, data); |
17236 }; | 9951 }; |
17237 | 9952 |
17238 return {Manager: Manager}; | 9953 return {Manager: Manager}; |
17239 }); | 9954 }); |
17240 // Copyright 2015 The Chromium Authors. All rights reserved. | 9955 // Copyright 2015 The Chromium Authors. All rights reserved. |
17241 // Use of this source code is governed by a BSD-style license that can be | 9956 // Use of this source code is governed by a BSD-style license that can be |
17242 // found in the LICENSE file. | 9957 // found in the LICENSE file. |
17243 | 9958 |
17244 window.addEventListener('load', downloads.Manager.onLoad); | 9959 window.addEventListener('load', downloads.Manager.onLoad); |
OLD | NEW |