polymer-rails 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/polymer/polymer-micro.html +528 -21
  3. data/app/assets/javascripts/polymer/polymer-mini.html +1304 -27
  4. data/app/assets/javascripts/polymer/polymer.html +3771 -51
  5. data/app/assets/javascripts/webcomponentsjs/webcomponents-lite.js +44 -14
  6. data/app/assets/javascripts/webcomponentsjs/webcomponents.js +7106 -0
  7. data/lib/polymer-rails/version.rb +1 -1
  8. metadata +4 -64
  9. data/app/assets/javascripts/polymer/src/lib/annotations/annotations.html +0 -262
  10. data/app/assets/javascripts/polymer/src/lib/annotations/demo/app-chrome.html +0 -60
  11. data/app/assets/javascripts/polymer/src/lib/array-observe.html +0 -118
  12. data/app/assets/javascripts/polymer/src/lib/array-splice.html +0 -262
  13. data/app/assets/javascripts/polymer/src/lib/async.html +0 -68
  14. data/app/assets/javascripts/polymer/src/lib/base.html +0 -117
  15. data/app/assets/javascripts/polymer/src/lib/bind/accessors.html +0 -223
  16. data/app/assets/javascripts/polymer/src/lib/bind/demo/app-chrome.html +0 -28
  17. data/app/assets/javascripts/polymer/src/lib/bind/demo/app.html +0 -29
  18. data/app/assets/javascripts/polymer/src/lib/bind/demo/src/annotations-bind-demo.html +0 -76
  19. data/app/assets/javascripts/polymer/src/lib/bind/demo/src/bind-demo.html +0 -83
  20. data/app/assets/javascripts/polymer/src/lib/bind/effects.html +0 -80
  21. data/app/assets/javascripts/polymer/src/lib/case-map.html +0 -46
  22. data/app/assets/javascripts/polymer/src/lib/collection.html +0 -179
  23. data/app/assets/javascripts/polymer/src/lib/css-parse.html +0 -131
  24. data/app/assets/javascripts/polymer/src/lib/debounce.html +0 -69
  25. data/app/assets/javascripts/polymer/src/lib/dom-api.html +0 -467
  26. data/app/assets/javascripts/polymer/src/lib/dom-module.html +0 -68
  27. data/app/assets/javascripts/polymer/src/lib/event-api.html +0 -92
  28. data/app/assets/javascripts/polymer/src/lib/expr/focus.html +0 -22
  29. data/app/assets/javascripts/polymer/src/lib/expr/gestures.html +0 -1
  30. data/app/assets/javascripts/polymer/src/lib/expr/log.html +0 -21
  31. data/app/assets/javascripts/polymer/src/lib/expr/sinspect.html +0 -235
  32. data/app/assets/javascripts/polymer/src/lib/expr/style-auditor.html +0 -123
  33. data/app/assets/javascripts/polymer/src/lib/expr/style-protector.html +0 -52
  34. data/app/assets/javascripts/polymer/src/lib/gestures.html +0 -284
  35. data/app/assets/javascripts/polymer/src/lib/lang.html +0 -21
  36. data/app/assets/javascripts/polymer/src/lib/module.html +0 -56
  37. data/app/assets/javascripts/polymer/src/lib/polymer-bootstrap.html +0 -78
  38. data/app/assets/javascripts/polymer/src/lib/resolve-url.html +0 -82
  39. data/app/assets/javascripts/polymer/src/lib/settings.html +0 -52
  40. data/app/assets/javascripts/polymer/src/lib/style-defaults.html +0 -32
  41. data/app/assets/javascripts/polymer/src/lib/style-transformer.html +0 -185
  42. data/app/assets/javascripts/polymer/src/lib/style-util.html +0 -77
  43. data/app/assets/javascripts/polymer/src/lib/template/templatizer.html +0 -132
  44. data/app/assets/javascripts/polymer/src/lib/template/x-array-selector.html +0 -178
  45. data/app/assets/javascripts/polymer/src/lib/template/x-autobind.html +0 -80
  46. data/app/assets/javascripts/polymer/src/lib/template/x-if.html +0 -115
  47. data/app/assets/javascripts/polymer/src/lib/template/x-repeat.html +0 -510
  48. data/app/assets/javascripts/polymer/src/lib/template/x-template.html +0 -39
  49. data/app/assets/javascripts/polymer/src/lib/x-style.html +0 -115
  50. data/app/assets/javascripts/polymer/src/micro/attributes.html +0 -180
  51. data/app/assets/javascripts/polymer/src/micro/constructor.html +0 -74
  52. data/app/assets/javascripts/polymer/src/micro/extends.html +0 -79
  53. data/app/assets/javascripts/polymer/src/micro/mixins.html +0 -40
  54. data/app/assets/javascripts/polymer/src/micro/properties.html +0 -96
  55. data/app/assets/javascripts/polymer/src/micro/tag.html +0 -28
  56. data/app/assets/javascripts/polymer/src/mini/ready.html +0 -180
  57. data/app/assets/javascripts/polymer/src/mini/shadow.html +0 -41
  58. data/app/assets/javascripts/polymer/src/mini/shady.html +0 -365
  59. data/app/assets/javascripts/polymer/src/mini/template.html +0 -56
  60. data/app/assets/javascripts/polymer/src/polymer-lib.html +0 -15
  61. data/app/assets/javascripts/polymer/src/standard/annotations.html +0 -198
  62. data/app/assets/javascripts/polymer/src/standard/configure.html +0 -160
  63. data/app/assets/javascripts/polymer/src/standard/effects.html +0 -215
  64. data/app/assets/javascripts/polymer/src/standard/events.html +0 -127
  65. data/app/assets/javascripts/polymer/src/standard/notify-path.html +0 -260
  66. data/app/assets/javascripts/polymer/src/standard/resolveUrl.html +0 -27
  67. data/app/assets/javascripts/polymer/src/standard/styling.html +0 -157
  68. data/app/assets/javascripts/polymer/src/standard/utils.html +0 -158
  69. data/app/assets/javascripts/polymer/src/standard/x-styling.html +0 -300
@@ -1,59 +1,3779 @@
1
1
  <!--
2
2
  @license
3
+ Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4
+ This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5
+ The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6
+ The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7
+ Code distributed by Google as part of the polymer project is also
8
+ subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9
+ --><!--
10
+ @license
3
11
  Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4
12
  This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5
13
  The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6
14
  The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7
15
  Code distributed by Google as part of the polymer project is also
8
16
  subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9
- -->
10
-
11
- <link rel="import" href="polymer-mini.html">
12
-
13
- <link rel="import" href="src/standard/annotations.html">
14
- <link rel="import" href="src/standard/events.html">
15
- <link rel="import" href="src/standard/utils.html">
16
- <link rel="import" href="src/standard/effects.html">
17
- <link rel="import" href="src/standard/configure.html">
18
- <link rel="import" href="src/standard/notify-path.html">
19
- <link rel="import" href="src/standard/resolveUrl.html">
20
- <link rel="import" href="src/standard/styling.html">
21
- <link rel="import" href="src/standard/x-styling.html">
22
-
23
- <script>
24
-
25
- Polymer.Base.addFeature({
26
-
27
- registerFeatures: function() {
28
- this._prepIs();
29
- this._prepMixins();
30
- this._prepExtends();
31
- this._prepConstructor();
32
- this._prepTemplate();
33
- this._prepAnnotations();
34
- this._prepEffects();
35
- this._prepContent();
36
- },
37
-
38
- initFeatures: function() {
39
- this._poolContent();
40
- this._setupConfigure();
41
- this._pushHost();
42
- this._stampTemplate();
43
- this._popHost();
44
- this._marshalAnnotationReferences();
45
- this._marshalInstanceEffects();
46
- this._marshalAttributes();
47
- this._marshalListeners();
48
- this._readyContent();
49
- }
50
-
51
- });
52
-
53
- </script>
54
-
55
- <link rel="import" href="src/lib/x-style.html">
56
- <link rel="import" href="src/lib/template/x-autobind.html">
57
- <link rel="import" href="src/lib/template/x-template.html">
58
- <link rel="import" href="src/lib/template/x-repeat.html">
59
- <link rel="import" href="src/lib/template/x-array-selector.html">
17
+ --><link rel="import" href="polymer-mini.html">
18
+
19
+ <script>Polymer.nar = [];
20
+
21
+ Polymer.Annotations = {
22
+ parseAnnotations: function(template) {
23
+ var list = [];
24
+ var content = template._content || template.content;
25
+ this._parseNodeAnnotations(content, list);
26
+ return list;
27
+ },
28
+ _parseNodeAnnotations: function(node, list) {
29
+ return node.nodeType === Node.TEXT_NODE ? this._parseTextNodeAnnotation(node, list) : this._parseElementAnnotations(node, list);
30
+ },
31
+ _testEscape: function(value) {
32
+ var escape = value.slice(0, 2);
33
+ if (escape === "{{" || escape === "[[") {
34
+ return escape;
35
+ }
36
+ },
37
+ _parseTextNodeAnnotation: function(node, list) {
38
+ var v = node.textContent;
39
+ var escape = this._testEscape(v);
40
+ if (escape) {
41
+ node.textContent = " ";
42
+ var annote = {
43
+ bindings: [ {
44
+ kind: "text",
45
+ mode: escape[0],
46
+ value: v.slice(2, -2).trim()
47
+ } ]
48
+ };
49
+ list.push(annote);
50
+ return annote;
51
+ }
52
+ },
53
+ _parseElementAnnotations: function(element, list) {
54
+ var annote = {
55
+ bindings: [],
56
+ events: []
57
+ };
58
+ this._parseChildNodesAnnotations(element, annote, list);
59
+ if (element.attributes) {
60
+ this._parseNodeAttributeAnnotations(element, annote, list);
61
+ if (this.prepElement) {
62
+ this.prepElement(element);
63
+ }
64
+ }
65
+ if (annote.bindings.length || annote.events.length || annote.id) {
66
+ list.push(annote);
67
+ }
68
+ return annote;
69
+ },
70
+ _parseChildNodesAnnotations: function(root, annote, list, callback) {
71
+ if (root.firstChild) {
72
+ for (var i = 0, node = root.firstChild; node; node = node.nextSibling, i++) {
73
+ if (node.localName === "template" && !node.hasAttribute("preserve-content")) {
74
+ this._parseTemplate(node, i, list, annote);
75
+ }
76
+ var childAnnotation = this._parseNodeAnnotations(node, list, callback);
77
+ if (childAnnotation) {
78
+ childAnnotation.parent = annote;
79
+ childAnnotation.index = i;
80
+ }
81
+ }
82
+ }
83
+ },
84
+ _parseTemplate: function(node, index, list, parent) {
85
+ var content = document.createDocumentFragment();
86
+ content._notes = this.parseAnnotations(node);
87
+ content.appendChild(node.content);
88
+ list.push({
89
+ bindings: Polymer.nar,
90
+ events: Polymer.nar,
91
+ templateContent: content,
92
+ parent: parent,
93
+ index: index
94
+ });
95
+ },
96
+ _parseNodeAttributeAnnotations: function(node, annotation) {
97
+ for (var i = node.attributes.length - 1, a; a = node.attributes[i]; i--) {
98
+ var n = a.name, v = a.value;
99
+ if (n === "id" && !this._testEscape(v)) {
100
+ annotation.id = v;
101
+ } else if (n.slice(0, 3) === "on-") {
102
+ node.removeAttribute(n);
103
+ annotation.events.push({
104
+ name: n.slice(3),
105
+ value: v
106
+ });
107
+ } else {
108
+ var b = this._parseNodeAttributeAnnotation(node, n, v);
109
+ if (b) {
110
+ annotation.bindings.push(b);
111
+ }
112
+ }
113
+ }
114
+ },
115
+ _parseNodeAttributeAnnotation: function(node, n, v) {
116
+ var escape = this._testEscape(v);
117
+ if (escape) {
118
+ var customEvent;
119
+ var name = n;
120
+ var mode = escape[0];
121
+ v = v.slice(2, -2).trim();
122
+ var not = false;
123
+ if (v[0] == "!") {
124
+ v = v.substring(1);
125
+ not = true;
126
+ }
127
+ var kind = "property";
128
+ if (n[n.length - 1] == "$") {
129
+ name = n.slice(0, -1);
130
+ kind = "attribute";
131
+ }
132
+ var notifyEvent, colon;
133
+ if (mode == "{" && (colon = v.indexOf("::")) > 0) {
134
+ notifyEvent = v.substring(colon + 2);
135
+ v = v.substring(0, colon);
136
+ customEvent = true;
137
+ }
138
+ if (node.localName == "input" && n == "value") {
139
+ node.setAttribute(n, "");
140
+ }
141
+ node.removeAttribute(n);
142
+ if (kind === "property") {
143
+ name = Polymer.CaseMap.dashToCamelCase(name);
144
+ }
145
+ return {
146
+ kind: kind,
147
+ mode: mode,
148
+ name: name,
149
+ value: v,
150
+ negate: not,
151
+ event: notifyEvent,
152
+ customEvent: customEvent
153
+ };
154
+ }
155
+ },
156
+ _localSubTree: function(node, host) {
157
+ return node === host ? node.childNodes : node._lightChildren || node.childNodes;
158
+ },
159
+ findAnnotatedNode: function(root, annote) {
160
+ var parent = annote.parent && Polymer.Annotations.findAnnotatedNode(root, annote.parent);
161
+ return !parent ? root : Polymer.Annotations._localSubTree(parent, root)[annote.index];
162
+ }
163
+ };
164
+
165
+ (function() {
166
+ function resolveCss(cssText, ownerDocument) {
167
+ return cssText.replace(CSS_URL_RX, function(m, pre, url, post) {
168
+ return pre + "'" + resolve(url.replace(/["']/g, ""), ownerDocument) + "'" + post;
169
+ });
170
+ }
171
+ function resolveAttrs(element, ownerDocument) {
172
+ for (var name in URL_ATTRS) {
173
+ var a$ = URL_ATTRS[name];
174
+ for (var i = 0, l = a$.length, a, at, v; i < l && (a = a$[i]); i++) {
175
+ if (name === "*" || element.localName === name) {
176
+ at = element.attributes[a];
177
+ v = at && at.value;
178
+ if (v && v.search(BINDING_RX) < 0) {
179
+ at.value = a === "style" ? resolveCss(v, ownerDocument) : resolve(v, ownerDocument);
180
+ }
181
+ }
182
+ }
183
+ }
184
+ }
185
+ function resolve(url, ownerDocument) {
186
+ var resolver = getUrlResolver(ownerDocument);
187
+ resolver.href = url;
188
+ return resolver.href || url;
189
+ }
190
+ var tempDoc;
191
+ var tempDocBase;
192
+ function resolveUrl(url, baseUri) {
193
+ if (!tempDoc) {
194
+ tempDoc = document.implementation.createHTMLDocument("temp");
195
+ tempDocBase = tempDoc.createElement("base");
196
+ tempDoc.head.appendChild(tempDocBase);
197
+ }
198
+ tempDocBase.href = baseUri;
199
+ return resolve(url, tempDoc);
200
+ }
201
+ function getUrlResolver(ownerDocument) {
202
+ return ownerDocument.__urlResolver || (ownerDocument.__urlResolver = ownerDocument.createElement("a"));
203
+ }
204
+ var CSS_URL_RX = /(url\()([^)]*)(\))/g;
205
+ var URL_ATTRS = {
206
+ "*": [ "href", "src", "style", "url" ],
207
+ form: [ "action" ]
208
+ };
209
+ var BINDING_RX = /\{\{|\[\[/;
210
+ Polymer.ResolveUrl = {
211
+ resolveCss: resolveCss,
212
+ resolveAttrs: resolveAttrs,
213
+ resolveUrl: resolveUrl
214
+ };
215
+ })();
216
+
217
+ Polymer.Base._addFeature({
218
+ _prepAnnotations: function() {
219
+ if (!this._template) {
220
+ this._notes = [];
221
+ } else {
222
+ Polymer.Annotations.prepElement = this._prepElement.bind(this);
223
+ this._notes = Polymer.Annotations.parseAnnotations(this._template);
224
+ this._processAnnotations(this._notes);
225
+ Polymer.Annotations.prepElement = null;
226
+ }
227
+ },
228
+ _processAnnotations: function(notes) {
229
+ for (var i = 0; i < notes.length; i++) {
230
+ var note = notes[i];
231
+ for (var j = 0; j < note.bindings.length; j++) {
232
+ var b = note.bindings[j];
233
+ b.signature = this._parseMethod(b.value);
234
+ if (!b.signature) {
235
+ b.model = this._modelForPath(b.value);
236
+ }
237
+ }
238
+ if (note.templateContent) {
239
+ this._processAnnotations(note.templateContent._notes);
240
+ var pp = note.templateContent._parentProps = this._discoverTemplateParentProps(note.templateContent._notes);
241
+ var bindings = [];
242
+ for (var prop in pp) {
243
+ bindings.push({
244
+ index: note.index,
245
+ kind: "property",
246
+ mode: "{",
247
+ name: "_parent_" + prop,
248
+ model: prop,
249
+ value: prop
250
+ });
251
+ }
252
+ note.bindings = note.bindings.concat(bindings);
253
+ }
254
+ }
255
+ },
256
+ _discoverTemplateParentProps: function(notes) {
257
+ var pp = {};
258
+ notes.forEach(function(n) {
259
+ n.bindings.forEach(function(b) {
260
+ if (b.signature) {
261
+ var args = b.signature.args;
262
+ for (var k = 0; k < args.length; k++) {
263
+ pp[args[k].model] = true;
264
+ }
265
+ } else {
266
+ pp[b.model] = true;
267
+ }
268
+ });
269
+ if (n.templateContent) {
270
+ var tpp = n.templateContent._parentProps;
271
+ Polymer.Base.mixin(pp, tpp);
272
+ }
273
+ });
274
+ return pp;
275
+ },
276
+ _prepElement: function(element) {
277
+ Polymer.ResolveUrl.resolveAttrs(element, this._template.ownerDocument);
278
+ },
279
+ _findAnnotatedNode: Polymer.Annotations.findAnnotatedNode,
280
+ _marshalAnnotationReferences: function() {
281
+ if (this._template) {
282
+ this._marshalIdNodes();
283
+ this._marshalAnnotatedNodes();
284
+ this._marshalAnnotatedListeners();
285
+ }
286
+ },
287
+ _configureAnnotationReferences: function() {
288
+ this._configureTemplateContent();
289
+ },
290
+ _configureTemplateContent: function() {
291
+ this._notes.forEach(function(note, i) {
292
+ if (note.templateContent) {
293
+ this._nodes[i]._content = note.templateContent;
294
+ }
295
+ }, this);
296
+ },
297
+ _marshalIdNodes: function() {
298
+ this.$ = {};
299
+ this._notes.forEach(function(a) {
300
+ if (a.id) {
301
+ this.$[a.id] = this._findAnnotatedNode(this.root, a);
302
+ }
303
+ }, this);
304
+ },
305
+ _marshalAnnotatedNodes: function() {
306
+ if (this._nodes) {
307
+ this._nodes = this._nodes.map(function(a) {
308
+ return this._findAnnotatedNode(this.root, a);
309
+ }, this);
310
+ }
311
+ },
312
+ _marshalAnnotatedListeners: function() {
313
+ this._notes.forEach(function(a) {
314
+ if (a.events && a.events.length) {
315
+ var node = this._findAnnotatedNode(this.root, a);
316
+ a.events.forEach(function(e) {
317
+ this.listen(node, e.name, e.value);
318
+ }, this);
319
+ }
320
+ }, this);
321
+ }
322
+ });
323
+
324
+ Polymer.Base._addFeature({
325
+ listeners: {},
326
+ _listenListeners: function(listeners) {
327
+ var node, name, key;
328
+ for (key in listeners) {
329
+ if (key.indexOf(".") < 0) {
330
+ node = this;
331
+ name = key;
332
+ } else {
333
+ name = key.split(".");
334
+ node = this.$[name[0]];
335
+ name = name[1];
336
+ }
337
+ this.listen(node, name, listeners[key]);
338
+ }
339
+ },
340
+ listen: function(node, eventName, methodName) {
341
+ this._listen(node, eventName, this._createEventHandler(node, eventName, methodName));
342
+ },
343
+ _createEventHandler: function(node, eventName, methodName) {
344
+ var host = this;
345
+ return function(e) {
346
+ if (host[methodName]) {
347
+ host[methodName](e, e.detail);
348
+ } else {
349
+ host._warn(host._logf("_createEventHandler", "listener method `" + methodName + "` not defined"));
350
+ }
351
+ };
352
+ },
353
+ _listen: function(node, eventName, handler) {
354
+ node.addEventListener(eventName, handler);
355
+ }
356
+ });
357
+
358
+ (function() {
359
+ "use strict";
360
+ var HAS_NATIVE_TA = typeof document.head.style.touchAction === "string";
361
+ var GESTURE_KEY = "__polymerGestures";
362
+ var HANDLED_OBJ = "__polymerGesturesHandled";
363
+ var TOUCH_ACTION = "__polymerGesturesTouchAction";
364
+ var TAP_DISTANCE = 25;
365
+ var TRACK_DISTANCE = 5;
366
+ var TRACK_LENGTH = 2;
367
+ var MOUSE_TIMEOUT = 2500;
368
+ var MOUSE_EVENTS = [ "mousedown", "mousemove", "mouseup", "click" ];
369
+ var mouseCanceller = function(mouseEvent) {
370
+ mouseEvent[HANDLED_OBJ] = {
371
+ skip: true
372
+ };
373
+ if (mouseEvent.type === "click") {
374
+ var path = Polymer.dom(mouseEvent).path;
375
+ for (var i = 0; i < path.length; i++) {
376
+ if (path[i] === POINTERSTATE.mouse.target) {
377
+ return;
378
+ }
379
+ }
380
+ mouseEvent.preventDefault();
381
+ mouseEvent.stopPropagation();
382
+ }
383
+ };
384
+ function setupTeardownMouseCanceller(setup) {
385
+ for (var i = 0, en; i < MOUSE_EVENTS.length; i++) {
386
+ en = MOUSE_EVENTS[i];
387
+ if (setup) {
388
+ document.addEventListener(en, mouseCanceller, true);
389
+ } else {
390
+ document.removeEventListener(en, mouseCanceller, true);
391
+ }
392
+ }
393
+ }
394
+ function ignoreMouse() {
395
+ if (!POINTERSTATE.mouse.mouseIgnoreJob) {
396
+ setupTeardownMouseCanceller(true);
397
+ }
398
+ var unset = function() {
399
+ setupTeardownMouseCanceller();
400
+ POINTERSTATE.mouse.target = null;
401
+ POINTERSTATE.mouse.mouseIgnoreJob = null;
402
+ };
403
+ POINTERSTATE.mouse.mouseIgnoreJob = Polymer.Debounce(POINTERSTATE.mouse.mouseIgnoreJob, unset, MOUSE_TIMEOUT);
404
+ }
405
+ var POINTERSTATE = {
406
+ tapPrevented: false,
407
+ mouse: {
408
+ target: null,
409
+ mouseIgnoreJob: null
410
+ },
411
+ touch: {
412
+ x: 0,
413
+ y: 0,
414
+ id: -1,
415
+ scrollDecided: false
416
+ }
417
+ };
418
+ function firstTouchAction(ev) {
419
+ var path = Polymer.dom(ev).path;
420
+ var ta = "auto";
421
+ for (var i = 0, n; i < path.length; i++) {
422
+ n = path[i];
423
+ if (n[TOUCH_ACTION]) {
424
+ ta = n[TOUCH_ACTION];
425
+ break;
426
+ }
427
+ }
428
+ return ta;
429
+ }
430
+ var Gestures = {
431
+ gestures: {},
432
+ recognizers: [],
433
+ deepTargetFind: function(x, y) {
434
+ var node = document.elementFromPoint(x, y);
435
+ var next = node;
436
+ while (next && next.shadowRoot) {
437
+ next = next.shadowRoot.elementFromPoint(x, y);
438
+ if (next) {
439
+ node = next;
440
+ }
441
+ }
442
+ return node;
443
+ },
444
+ handleNative: function(ev) {
445
+ var handled;
446
+ var type = ev.type;
447
+ var node = ev.currentTarget;
448
+ var gobj = node[GESTURE_KEY];
449
+ var gs = gobj[type];
450
+ if (!gs) {
451
+ return;
452
+ }
453
+ if (!ev[HANDLED_OBJ]) {
454
+ ev[HANDLED_OBJ] = {};
455
+ if (type.slice(0, 5) === "touch") {
456
+ var t = ev.changedTouches[0];
457
+ if (type === "touchstart") {
458
+ if (ev.touches.length === 1) {
459
+ POINTERSTATE.touch.id = t.identifier;
460
+ }
461
+ }
462
+ if (POINTERSTATE.touch.id !== t.identifier) {
463
+ return;
464
+ }
465
+ if (!HAS_NATIVE_TA) {
466
+ if (type === "touchstart" || type === "touchmove") {
467
+ Gestures.handleTouchAction(ev);
468
+ }
469
+ }
470
+ if (type === "touchend") {
471
+ POINTERSTATE.mouse.target = Polymer.dom(ev).rootTarget;
472
+ ignoreMouse(true);
473
+ }
474
+ }
475
+ }
476
+ handled = ev[HANDLED_OBJ];
477
+ if (handled.skip) {
478
+ return;
479
+ }
480
+ var recognizers = Gestures.recognizers;
481
+ for (var i = 0, r; i < recognizers.length; i++) {
482
+ r = recognizers[i];
483
+ if (gs[r.name] && !handled[r.name]) {
484
+ handled[r.name] = true;
485
+ r[type](ev);
486
+ }
487
+ }
488
+ },
489
+ handleTouchAction: function(ev) {
490
+ var t = ev.changedTouches[0];
491
+ var type = ev.type;
492
+ if (type === "touchstart") {
493
+ POINTERSTATE.touch.x = t.clientX;
494
+ POINTERSTATE.touch.y = t.clientY;
495
+ POINTERSTATE.touch.scrollDecided = false;
496
+ } else if (type === "touchmove") {
497
+ if (POINTERSTATE.touch.scrollDecided) {
498
+ return;
499
+ }
500
+ POINTERSTATE.touch.scrollDecided = true;
501
+ var ta = firstTouchAction(ev);
502
+ var prevent = false;
503
+ var dx = Math.abs(POINTERSTATE.touch.x - t.clientX);
504
+ var dy = Math.abs(POINTERSTATE.touch.y - t.clientY);
505
+ if (!ev.cancelable) {} else if (ta === "none") {
506
+ prevent = true;
507
+ } else if (ta === "pan-x") {
508
+ prevent = dy > dx;
509
+ } else if (ta === "pan-y") {
510
+ prevent = dx > dy;
511
+ }
512
+ if (prevent) {
513
+ ev.preventDefault();
514
+ }
515
+ }
516
+ },
517
+ add: function(node, evType, handler) {
518
+ var recognizer = this.gestures[evType];
519
+ var deps = recognizer.deps;
520
+ var name = recognizer.name;
521
+ var gobj = node[GESTURE_KEY];
522
+ if (!gobj) {
523
+ node[GESTURE_KEY] = gobj = {};
524
+ }
525
+ for (var i = 0, dep, gd; i < deps.length; i++) {
526
+ dep = deps[i];
527
+ gd = gobj[dep];
528
+ if (!gd) {
529
+ gobj[dep] = gd = {};
530
+ node.addEventListener(dep, this.handleNative);
531
+ }
532
+ gd[name] = (gd[name] || 0) + 1;
533
+ }
534
+ node.addEventListener(evType, handler);
535
+ if (recognizer.touchAction) {
536
+ this.setTouchAction(node, recognizer.touchAction);
537
+ }
538
+ },
539
+ register: function(recog) {
540
+ this.recognizers.push(recog);
541
+ for (var i = 0; i < recog.emits.length; i++) {
542
+ this.gestures[recog.emits[i]] = recog;
543
+ }
544
+ },
545
+ setTouchAction: function(node, value) {
546
+ if (HAS_NATIVE_TA) {
547
+ node.style.touchAction = value;
548
+ }
549
+ node[TOUCH_ACTION] = value;
550
+ },
551
+ fire: function(target, type, detail) {
552
+ var ev = new CustomEvent(type, {
553
+ detail: detail,
554
+ bubbles: true,
555
+ cancelable: true
556
+ });
557
+ target.dispatchEvent(ev);
558
+ }
559
+ };
560
+ Gestures.register({
561
+ name: "downup",
562
+ deps: [ "mousedown", "touchstart", "touchend" ],
563
+ emits: [ "down", "up" ],
564
+ mousedown: function(e) {
565
+ var t = e.currentTarget;
566
+ var self = this;
567
+ var upfn = function upfn(e) {
568
+ self.fire("up", t, e);
569
+ document.removeEventListener("mouseup", upfn);
570
+ };
571
+ document.addEventListener("mouseup", upfn);
572
+ this.fire("down", t, e);
573
+ },
574
+ touchstart: function(e) {
575
+ this.fire("down", e.currentTarget, e.changedTouches[0]);
576
+ },
577
+ touchend: function(e) {
578
+ this.fire("up", e.currentTarget, e.changedTouches[0]);
579
+ },
580
+ fire: function(type, target, event) {
581
+ Gestures.fire(target, type, {
582
+ x: event.clientX,
583
+ y: event.clientY,
584
+ sourceEvent: event
585
+ });
586
+ }
587
+ });
588
+ Gestures.register({
589
+ name: "track",
590
+ touchAction: "none",
591
+ deps: [ "mousedown", "touchstart", "touchmove", "touchend" ],
592
+ emits: [ "track" ],
593
+ info: {
594
+ x: 0,
595
+ y: 0,
596
+ state: "start",
597
+ started: false,
598
+ moves: [],
599
+ addMove: function(move) {
600
+ if (this.moves.length > TRACK_LENGTH) {
601
+ this.moves.shift();
602
+ }
603
+ this.moves.push(move);
604
+ }
605
+ },
606
+ clearInfo: function() {
607
+ this.info.state = "start";
608
+ this.info.started = false;
609
+ this.info.moves = [];
610
+ this.info.x = 0;
611
+ this.info.y = 0;
612
+ },
613
+ hasMovedEnough: function(x, y) {
614
+ if (this.info.started) {
615
+ return true;
616
+ }
617
+ var dx = Math.abs(this.info.x - x);
618
+ var dy = Math.abs(this.info.y - y);
619
+ return dx >= TRACK_DISTANCE || dy >= TRACK_DISTANCE;
620
+ },
621
+ mousedown: function(e) {
622
+ var t = e.currentTarget;
623
+ var self = this;
624
+ var movefn = function movefn(e) {
625
+ var x = e.clientX, y = e.clientY;
626
+ if (self.hasMovedEnough(x, y)) {
627
+ self.info.state = self.info.started ? e.type === "mouseup" ? "end" : "track" : "start";
628
+ self.info.addMove({
629
+ x: x,
630
+ y: y
631
+ });
632
+ self.fire(t, e);
633
+ e.preventDefault();
634
+ self.info.started = true;
635
+ }
636
+ };
637
+ var upfn = function upfn(e) {
638
+ if (self.info.started) {
639
+ POINTERSTATE.tapPrevented = true;
640
+ movefn(e);
641
+ }
642
+ self.clearInfo();
643
+ document.removeEventListener("mousemove", movefn);
644
+ document.removeEventListener("mouseup", upfn);
645
+ };
646
+ document.addEventListener("mousemove", movefn);
647
+ document.addEventListener("mouseup", upfn);
648
+ this.info.x = e.clientX;
649
+ this.info.y = e.clientY;
650
+ },
651
+ touchstart: function(e) {
652
+ var ct = e.changedTouches[0];
653
+ this.info.x = ct.clientX;
654
+ this.info.y = ct.clientY;
655
+ },
656
+ touchmove: function(e) {
657
+ var t = e.currentTarget;
658
+ var ct = e.changedTouches[0];
659
+ var x = ct.clientX, y = ct.clientY;
660
+ if (this.hasMovedEnough(x, y)) {
661
+ this.info.addMove({
662
+ x: x,
663
+ y: y
664
+ });
665
+ this.fire(t, ct);
666
+ this.info.state = "track";
667
+ this.info.started = true;
668
+ }
669
+ },
670
+ touchend: function(e) {
671
+ var t = e.currentTarget;
672
+ var ct = e.changedTouches[0];
673
+ if (this.info.started) {
674
+ POINTERSTATE.tapPrevented = true;
675
+ this.info.state = "end";
676
+ this.info.addMove({
677
+ x: ct.clientX,
678
+ y: ct.clientY
679
+ });
680
+ this.fire(t, ct);
681
+ }
682
+ this.clearInfo();
683
+ },
684
+ fire: function(target, touch) {
685
+ var secondlast = this.info.moves[this.info.moves.length - 2];
686
+ var lastmove = this.info.moves[this.info.moves.length - 1];
687
+ var dx = lastmove.x - this.info.x;
688
+ var dy = lastmove.y - this.info.y;
689
+ var ddx, ddy = 0;
690
+ if (secondlast) {
691
+ ddx = lastmove.x - secondlast.x;
692
+ ddy = lastmove.y - secondlast.y;
693
+ }
694
+ return Gestures.fire(target, "track", {
695
+ state: this.info.state,
696
+ x: touch.clientX,
697
+ y: touch.clientY,
698
+ dx: dx,
699
+ dy: dy,
700
+ ddx: ddx,
701
+ ddy: ddy,
702
+ sourceEvent: touch,
703
+ hover: function() {
704
+ return Gestures.deepTargetFind(touch.clientX, touch.clientY);
705
+ }
706
+ });
707
+ }
708
+ });
709
+ Gestures.register({
710
+ name: "tap",
711
+ deps: [ "mousedown", "click", "touchstart", "touchend" ],
712
+ emits: [ "tap" ],
713
+ start: {
714
+ x: NaN,
715
+ y: NaN
716
+ },
717
+ reset: function() {
718
+ this.start.x = NaN;
719
+ this.start.y = NaN;
720
+ },
721
+ save: function(e) {
722
+ this.start.x = e.clientX;
723
+ this.start.y = e.clientY;
724
+ },
725
+ mousedown: function(e) {
726
+ POINTERSTATE.tapPrevented = false;
727
+ this.save(e);
728
+ },
729
+ click: function(e) {
730
+ this.forward(e);
731
+ },
732
+ touchstart: function(e) {
733
+ POINTERSTATE.tapPrevented = false;
734
+ this.save(e.changedTouches[0]);
735
+ },
736
+ touchend: function(e) {
737
+ this.forward(e.changedTouches[0]);
738
+ },
739
+ forward: function(e) {
740
+ var dx = Math.abs(e.clientX - this.start.x);
741
+ var dy = Math.abs(e.clientY - this.start.y);
742
+ if (isNaN(dx) || isNaN(dy) || dx <= TAP_DISTANCE && dy <= TAP_DISTANCE) {
743
+ if (!POINTERSTATE.tapPrevented) {
744
+ Gestures.fire(e.target, "tap", {
745
+ x: e.clientX,
746
+ y: e.clientY,
747
+ sourceEvent: e
748
+ });
749
+ }
750
+ }
751
+ this.reset();
752
+ }
753
+ });
754
+ var DIRECTION_MAP = {
755
+ x: "pan-x",
756
+ y: "pan-y",
757
+ none: "none",
758
+ all: "auto"
759
+ };
760
+ Polymer.Base._addFeature({
761
+ _listen: function(node, eventName, handler) {
762
+ if (Gestures.gestures[eventName]) {
763
+ Gestures.add(node, eventName, handler);
764
+ } else {
765
+ node.addEventListener(eventName, handler);
766
+ }
767
+ },
768
+ setScrollDirection: function(direction, node) {
769
+ node = node || this;
770
+ Gestures.setTouchAction(node, DIRECTION_MAP[direction] || "auto");
771
+ }
772
+ });
773
+ Polymer.Gestures = Gestures;
774
+ })();
775
+
776
+ Polymer.Async = function() {
777
+ var currVal = 0;
778
+ var lastVal = 0;
779
+ var callbacks = [];
780
+ var twiddle = document.createTextNode("");
781
+ function runAsync(callback, waitTime) {
782
+ if (waitTime > 0) {
783
+ return ~setTimeout(callback, waitTime);
784
+ } else {
785
+ twiddle.textContent = currVal++;
786
+ callbacks.push(callback);
787
+ return currVal - 1;
788
+ }
789
+ }
790
+ function cancelAsync(handle) {
791
+ if (handle < 0) {
792
+ clearTimeout(~handle);
793
+ } else {
794
+ var idx = handle - lastVal;
795
+ if (idx >= 0) {
796
+ if (!callbacks[idx]) {
797
+ throw "invalid async handle: " + handle;
798
+ }
799
+ callbacks[idx] = null;
800
+ }
801
+ }
802
+ }
803
+ function atEndOfMicrotask() {
804
+ var len = callbacks.length;
805
+ for (var i = 0; i < len; i++) {
806
+ var cb = callbacks[i];
807
+ if (cb) {
808
+ cb();
809
+ }
810
+ }
811
+ callbacks.splice(0, len);
812
+ lastVal += len;
813
+ }
814
+ new (window.MutationObserver || JsMutationObserver)(atEndOfMicrotask).observe(twiddle, {
815
+ characterData: true
816
+ });
817
+ return {
818
+ run: runAsync,
819
+ cancel: cancelAsync
820
+ };
821
+ }();
822
+
823
+ Polymer.Debounce = function() {
824
+ var Async = Polymer.Async;
825
+ var Debouncer = function(context) {
826
+ this.context = context;
827
+ this.boundComplete = this.complete.bind(this);
828
+ };
829
+ Debouncer.prototype = {
830
+ go: function(callback, wait) {
831
+ var h;
832
+ this.finish = function() {
833
+ Async.cancel(h);
834
+ };
835
+ h = Async.run(this.boundComplete, wait);
836
+ this.callback = callback;
837
+ },
838
+ stop: function() {
839
+ if (this.finish) {
840
+ this.finish();
841
+ this.finish = null;
842
+ }
843
+ },
844
+ complete: function() {
845
+ if (this.finish) {
846
+ this.stop();
847
+ this.callback.call(this.context);
848
+ }
849
+ }
850
+ };
851
+ function debounce(debouncer, callback, wait) {
852
+ if (debouncer) {
853
+ debouncer.stop();
854
+ } else {
855
+ debouncer = new Debouncer(this);
856
+ }
857
+ debouncer.go(callback, wait);
858
+ return debouncer;
859
+ }
860
+ return debounce;
861
+ }();
862
+
863
+ Polymer.Base._addFeature({
864
+ $$: function(slctr) {
865
+ return Polymer.dom(this.root).querySelector(slctr);
866
+ },
867
+ toggleClass: function(name, bool, node) {
868
+ node = node || this;
869
+ if (arguments.length == 1) {
870
+ bool = !node.classList.contains(name);
871
+ }
872
+ if (bool) {
873
+ Polymer.dom(node).classList.add(name);
874
+ } else {
875
+ Polymer.dom(node).classList.remove(name);
876
+ }
877
+ },
878
+ toggleAttribute: function(name, bool, node) {
879
+ node = node || this;
880
+ if (arguments.length == 1) {
881
+ bool = !node.hasAttribute(name);
882
+ }
883
+ if (bool) {
884
+ Polymer.dom(node).setAttribute(name, "");
885
+ } else {
886
+ Polymer.dom(node).removeAttribute(name);
887
+ }
888
+ },
889
+ classFollows: function(name, toElement, fromElement) {
890
+ if (fromElement) {
891
+ Polymer.dom(fromElement).classList.remove(name);
892
+ }
893
+ if (toElement) {
894
+ Polymer.dom(toElement).classList.add(name);
895
+ }
896
+ },
897
+ attributeFollows: function(name, toElement, fromElement) {
898
+ if (fromElement) {
899
+ Polymer.dom(fromElement).removeAttribute(name);
900
+ }
901
+ if (toElement) {
902
+ Polymer.dom(toElement).setAttribute(name, "");
903
+ }
904
+ },
905
+ getContentChildNodes: function(slctr) {
906
+ return Polymer.dom(Polymer.dom(this.root).querySelector(slctr || "content")).getDistributedNodes();
907
+ },
908
+ getContentChildren: function(slctr) {
909
+ return this.getContentChildNodes(slctr).filter(function(n) {
910
+ return n.nodeType === Node.ELEMENT_NODE;
911
+ });
912
+ },
913
+ fire: function(type, detail, options) {
914
+ options = options || Polymer.nob;
915
+ var node = options.node || this;
916
+ var detail = detail === null || detail === undefined ? Polymer.nob : detail;
917
+ var bubbles = options.bubbles === undefined ? true : options.bubbles;
918
+ var event = new CustomEvent(type, {
919
+ bubbles: Boolean(bubbles),
920
+ cancelable: Boolean(options.cancelable),
921
+ detail: detail
922
+ });
923
+ node.dispatchEvent(event);
924
+ return event;
925
+ },
926
+ async: function(callback, waitTime) {
927
+ return Polymer.Async.run(callback.bind(this), waitTime);
928
+ },
929
+ cancelAsync: function(handle) {
930
+ Polymer.Async.cancel(handle);
931
+ },
932
+ arrayDelete: function(path, item) {
933
+ var index;
934
+ if (Array.isArray(path)) {
935
+ index = path.indexOf(item);
936
+ if (index >= 0) {
937
+ return path.splice(index, 1);
938
+ }
939
+ } else {
940
+ var arr = this.get(path);
941
+ index = arr.indexOf(item);
942
+ if (index >= 0) {
943
+ return this.splice(path, index, 1);
944
+ }
945
+ }
946
+ },
947
+ transform: function(transform, node) {
948
+ node = node || this;
949
+ node.style.webkitTransform = transform;
950
+ node.style.transform = transform;
951
+ },
952
+ translate3d: function(x, y, z, node) {
953
+ node = node || this;
954
+ this.transform("translate3d(" + x + "," + y + "," + z + ")", node);
955
+ },
956
+ importHref: function(href, onload, onerror) {
957
+ var l = document.createElement("link");
958
+ l.rel = "import";
959
+ l.href = href;
960
+ if (onload) {
961
+ l.onload = onload.bind(this);
962
+ }
963
+ if (onerror) {
964
+ l.onerror = onerror.bind(this);
965
+ }
966
+ document.head.appendChild(l);
967
+ return l;
968
+ },
969
+ create: function(tag, props) {
970
+ var elt = document.createElement(tag);
971
+ if (props) {
972
+ for (var n in props) {
973
+ elt[n] = props[n];
974
+ }
975
+ }
976
+ return elt;
977
+ },
978
+ mixin: function(target, source) {
979
+ for (var i in source) {
980
+ target[i] = source[i];
981
+ }
982
+ }
983
+ });
984
+
985
+ Polymer.Bind = {
986
+ prepareModel: function(model) {
987
+ model._propertyEffects = {};
988
+ model._bindListeners = [];
989
+ var api = this._modelApi;
990
+ for (var n in api) {
991
+ model[n] = api[n];
992
+ }
993
+ },
994
+ _modelApi: {
995
+ _notifyChange: function(property) {
996
+ var eventName = Polymer.CaseMap.camelToDashCase(property) + "-changed";
997
+ this.fire(eventName, {
998
+ value: this[property]
999
+ }, {
1000
+ bubbles: false
1001
+ });
1002
+ },
1003
+ _propertySet: function(property, value, effects) {
1004
+ var old = this.__data__[property];
1005
+ if (old !== value) {
1006
+ this.__data__[property] = value;
1007
+ if (typeof value == "object") {
1008
+ this._clearPath(property);
1009
+ }
1010
+ if (this._propertyChanged) {
1011
+ this._propertyChanged(property, value, old);
1012
+ }
1013
+ if (effects) {
1014
+ this._effectEffects(property, value, effects, old);
1015
+ }
1016
+ }
1017
+ return old;
1018
+ },
1019
+ _effectEffects: function(property, value, effects, old) {
1020
+ effects.forEach(function(fx) {
1021
+ var fn = Polymer.Bind["_" + fx.kind + "Effect"];
1022
+ if (fn) {
1023
+ fn.call(this, property, value, fx.effect, old);
1024
+ }
1025
+ }, this);
1026
+ },
1027
+ _clearPath: function(path) {
1028
+ for (var prop in this.__data__) {
1029
+ if (prop.indexOf(path + ".") === 0) {
1030
+ this.__data__[prop] = undefined;
1031
+ }
1032
+ }
1033
+ }
1034
+ },
1035
+ ensurePropertyEffects: function(model, property) {
1036
+ var fx = model._propertyEffects[property];
1037
+ if (!fx) {
1038
+ fx = model._propertyEffects[property] = [];
1039
+ }
1040
+ return fx;
1041
+ },
1042
+ addPropertyEffect: function(model, property, kind, effect) {
1043
+ var fx = this.ensurePropertyEffects(model, property);
1044
+ fx.push({
1045
+ kind: kind,
1046
+ effect: effect
1047
+ });
1048
+ },
1049
+ createBindings: function(model) {
1050
+ var fx$ = model._propertyEffects;
1051
+ if (fx$) {
1052
+ for (var n in fx$) {
1053
+ var fx = fx$[n];
1054
+ fx.sort(this._sortPropertyEffects);
1055
+ this._createAccessors(model, n, fx);
1056
+ }
1057
+ }
1058
+ },
1059
+ _sortPropertyEffects: function() {
1060
+ var EFFECT_ORDER = {
1061
+ compute: 0,
1062
+ annotation: 1,
1063
+ computedAnnotation: 2,
1064
+ reflect: 3,
1065
+ notify: 4,
1066
+ observer: 5,
1067
+ complexObserver: 6,
1068
+ "function": 7
1069
+ };
1070
+ return function(a, b) {
1071
+ return EFFECT_ORDER[a.kind] - EFFECT_ORDER[b.kind];
1072
+ };
1073
+ }(),
1074
+ _createAccessors: function(model, property, effects) {
1075
+ var defun = {
1076
+ get: function() {
1077
+ return this.__data__[property];
1078
+ }
1079
+ };
1080
+ var setter = function(value) {
1081
+ this._propertySet(property, value, effects);
1082
+ };
1083
+ if (model.getPropertyInfo && model.getPropertyInfo(property).readOnly) {
1084
+ model["_set" + this.upper(property)] = setter;
1085
+ } else {
1086
+ defun.set = setter;
1087
+ }
1088
+ Object.defineProperty(model, property, defun);
1089
+ },
1090
+ upper: function(name) {
1091
+ return name[0].toUpperCase() + name.substring(1);
1092
+ },
1093
+ _addAnnotatedListener: function(model, index, property, path, event) {
1094
+ var fn = this._notedListenerFactory(property, path, this._isStructured(path), this._isEventBogus);
1095
+ var eventName = event || Polymer.CaseMap.camelToDashCase(property) + "-changed";
1096
+ model._bindListeners.push({
1097
+ index: index,
1098
+ property: property,
1099
+ path: path,
1100
+ changedFn: fn,
1101
+ event: eventName
1102
+ });
1103
+ },
1104
+ _isStructured: function(path) {
1105
+ return path.indexOf(".") > 0;
1106
+ },
1107
+ _isEventBogus: function(e, target) {
1108
+ return e.path && e.path[0] !== target;
1109
+ },
1110
+ _notedListenerFactory: function(property, path, isStructured, bogusTest) {
1111
+ return function(e, target) {
1112
+ if (!bogusTest(e, target)) {
1113
+ if (e.detail && e.detail.path) {
1114
+ this.notifyPath(this._fixPath(path, property, e.detail.path), e.detail.value);
1115
+ } else {
1116
+ var value = target[property];
1117
+ if (!isStructured) {
1118
+ this[path] = target[property];
1119
+ } else {
1120
+ if (this.__data__[path] != value) {
1121
+ this.set(path, value);
1122
+ }
1123
+ }
1124
+ }
1125
+ }
1126
+ };
1127
+ },
1128
+ prepareInstance: function(inst) {
1129
+ inst.__data__ = Object.create(null);
1130
+ },
1131
+ setupBindListeners: function(inst) {
1132
+ inst._bindListeners.forEach(function(info) {
1133
+ var node = inst._nodes[info.index];
1134
+ node.addEventListener(info.event, inst._notifyListener.bind(inst, info.changedFn));
1135
+ });
1136
+ }
1137
+ };
1138
+
1139
+ Polymer.Base.extend(Polymer.Bind, {
1140
+ _shouldAddListener: function(effect) {
1141
+ return effect.name && effect.mode === "{" && !effect.negate && effect.kind != "attribute";
1142
+ },
1143
+ _annotationEffect: function(source, value, effect) {
1144
+ if (source != effect.value) {
1145
+ value = this.get(effect.value);
1146
+ this.__data__[effect.value] = value;
1147
+ }
1148
+ var calc = effect.negate ? !value : value;
1149
+ if (!effect.customEvent || this._nodes[effect.index][effect.name] !== calc) {
1150
+ return this._applyEffectValue(calc, effect);
1151
+ }
1152
+ },
1153
+ _reflectEffect: function(source) {
1154
+ this.reflectPropertyToAttribute(source);
1155
+ },
1156
+ _notifyEffect: function(source) {
1157
+ this._notifyChange(source);
1158
+ },
1159
+ _functionEffect: function(source, value, fn, old) {
1160
+ fn.call(this, source, value, old);
1161
+ },
1162
+ _observerEffect: function(source, value, effect, old) {
1163
+ var fn = this[effect.method];
1164
+ if (fn) {
1165
+ fn.call(this, value, old);
1166
+ } else {
1167
+ this._warn(this._logf("_observerEffect", "observer method `" + effect.method + "` not defined"));
1168
+ }
1169
+ },
1170
+ _complexObserverEffect: function(source, value, effect) {
1171
+ var fn = this[effect.method];
1172
+ if (fn) {
1173
+ var args = Polymer.Bind._marshalArgs(this.__data__, effect, source, value);
1174
+ if (args) {
1175
+ fn.apply(this, args);
1176
+ }
1177
+ } else {
1178
+ this._warn(this._logf("_complexObserverEffect", "observer method `" + effect.method + "` not defined"));
1179
+ }
1180
+ },
1181
+ _computeEffect: function(source, value, effect) {
1182
+ var args = Polymer.Bind._marshalArgs(this.__data__, effect, source, value);
1183
+ if (args) {
1184
+ var fn = this[effect.method];
1185
+ if (fn) {
1186
+ this[effect.property] = fn.apply(this, args);
1187
+ } else {
1188
+ this._warn(this._logf("_computeEffect", "compute method `" + effect.method + "` not defined"));
1189
+ }
1190
+ }
1191
+ },
1192
+ _annotatedComputationEffect: function(source, value, effect) {
1193
+ var computedHost = this._rootDataHost || this;
1194
+ var fn = computedHost[effect.method];
1195
+ if (fn) {
1196
+ var args = Polymer.Bind._marshalArgs(this.__data__, effect, source, value);
1197
+ if (args) {
1198
+ var computedvalue = fn.apply(computedHost, args);
1199
+ if (effect.negate) {
1200
+ computedvalue = !computedvalue;
1201
+ }
1202
+ this._applyEffectValue(computedvalue, effect);
1203
+ }
1204
+ } else {
1205
+ computedHost._warn(computedHost._logf("_annotatedComputationEffect", "compute method `" + effect.method + "` not defined"));
1206
+ }
1207
+ },
1208
+ _marshalArgs: function(model, effect, path, value) {
1209
+ var values = [];
1210
+ var args = effect.args;
1211
+ for (var i = 0, l = args.length; i < l; i++) {
1212
+ var arg = args[i];
1213
+ var name = arg.name;
1214
+ if (arg.literal) {
1215
+ v = arg.value;
1216
+ } else if (arg.structured) {
1217
+ v = Polymer.Base.get(name, model);
1218
+ } else {
1219
+ v = model[name];
1220
+ }
1221
+ if (args.length > 1 && v === undefined) {
1222
+ return;
1223
+ }
1224
+ if (arg.wildcard) {
1225
+ var baseChanged = name.indexOf(path + ".") === 0;
1226
+ var matches = effect.trigger.name.indexOf(name) === 0 && !baseChanged;
1227
+ values[i] = {
1228
+ path: matches ? path : name,
1229
+ value: matches ? value : v,
1230
+ base: v
1231
+ };
1232
+ } else {
1233
+ values[i] = v;
1234
+ }
1235
+ }
1236
+ return values;
1237
+ }
1238
+ });
1239
+
1240
+ Polymer.Base._addFeature({
1241
+ _addPropertyEffect: function(property, kind, effect) {
1242
+ Polymer.Bind.addPropertyEffect(this, property, kind, effect);
1243
+ },
1244
+ _prepEffects: function() {
1245
+ Polymer.Bind.prepareModel(this);
1246
+ this._addAnnotationEffects(this._notes);
1247
+ },
1248
+ _prepBindings: function() {
1249
+ Polymer.Bind.createBindings(this);
1250
+ },
1251
+ _addPropertyEffects: function(properties) {
1252
+ if (properties) {
1253
+ for (var p in properties) {
1254
+ var prop = properties[p];
1255
+ if (prop.observer) {
1256
+ this._addObserverEffect(p, prop.observer);
1257
+ }
1258
+ if (prop.computed) {
1259
+ this._addComputedEffect(p, prop.computed);
1260
+ }
1261
+ if (prop.notify) {
1262
+ this._addPropertyEffect(p, "notify");
1263
+ }
1264
+ if (prop.reflectToAttribute) {
1265
+ this._addPropertyEffect(p, "reflect");
1266
+ }
1267
+ if (prop.readOnly) {
1268
+ Polymer.Bind.ensurePropertyEffects(this, p);
1269
+ }
1270
+ }
1271
+ }
1272
+ },
1273
+ _addComputedEffect: function(name, expression) {
1274
+ var sig = this._parseMethod(expression);
1275
+ sig.args.forEach(function(arg) {
1276
+ this._addPropertyEffect(arg.model, "compute", {
1277
+ method: sig.method,
1278
+ args: sig.args,
1279
+ trigger: arg,
1280
+ property: name
1281
+ });
1282
+ }, this);
1283
+ },
1284
+ _addObserverEffect: function(property, observer) {
1285
+ this._addPropertyEffect(property, "observer", {
1286
+ method: observer,
1287
+ property: property
1288
+ });
1289
+ },
1290
+ _addComplexObserverEffects: function(observers) {
1291
+ if (observers) {
1292
+ observers.forEach(function(observer) {
1293
+ this._addComplexObserverEffect(observer);
1294
+ }, this);
1295
+ }
1296
+ },
1297
+ _addComplexObserverEffect: function(observer) {
1298
+ var sig = this._parseMethod(observer);
1299
+ sig.args.forEach(function(arg) {
1300
+ this._addPropertyEffect(arg.model, "complexObserver", {
1301
+ method: sig.method,
1302
+ args: sig.args,
1303
+ trigger: arg
1304
+ });
1305
+ }, this);
1306
+ },
1307
+ _addAnnotationEffects: function(notes) {
1308
+ this._nodes = [];
1309
+ notes.forEach(function(note) {
1310
+ var index = this._nodes.push(note) - 1;
1311
+ note.bindings.forEach(function(binding) {
1312
+ this._addAnnotationEffect(binding, index);
1313
+ }, this);
1314
+ }, this);
1315
+ },
1316
+ _addAnnotationEffect: function(note, index) {
1317
+ if (Polymer.Bind._shouldAddListener(note)) {
1318
+ Polymer.Bind._addAnnotatedListener(this, index, note.name, note.value, note.event);
1319
+ }
1320
+ if (note.signature) {
1321
+ this._addAnnotatedComputationEffect(note, index);
1322
+ } else {
1323
+ note.index = index;
1324
+ this._addPropertyEffect(note.model, "annotation", note);
1325
+ }
1326
+ },
1327
+ _addAnnotatedComputationEffect: function(note, index) {
1328
+ var sig = note.signature;
1329
+ if (sig.static) {
1330
+ this.__addAnnotatedComputationEffect("__static__", index, note, sig, null);
1331
+ } else {
1332
+ sig.args.forEach(function(arg) {
1333
+ if (!arg.literal) {
1334
+ this.__addAnnotatedComputationEffect(arg.model, index, note, sig, arg);
1335
+ }
1336
+ }, this);
1337
+ }
1338
+ },
1339
+ __addAnnotatedComputationEffect: function(property, index, note, sig, trigger) {
1340
+ this._addPropertyEffect(property, "annotatedComputation", {
1341
+ index: index,
1342
+ kind: note.kind,
1343
+ property: note.name,
1344
+ negate: note.negate,
1345
+ method: sig.method,
1346
+ args: sig.args,
1347
+ trigger: trigger
1348
+ });
1349
+ },
1350
+ _parseMethod: function(expression) {
1351
+ var m = expression.match(/(\w*)\((.*)\)/);
1352
+ if (m) {
1353
+ var sig = {
1354
+ method: m[1],
1355
+ "static": true
1356
+ };
1357
+ if (m[2].trim()) {
1358
+ var args = m[2].replace(/\\,/g, "&comma;").split(",");
1359
+ return this._parseArgs(args, sig);
1360
+ } else {
1361
+ sig.args = Polymer.nar;
1362
+ return sig;
1363
+ }
1364
+ }
1365
+ },
1366
+ _parseArgs: function(argList, sig) {
1367
+ sig.args = argList.map(function(rawArg) {
1368
+ var arg = this._parseArg(rawArg);
1369
+ if (!arg.literal) {
1370
+ sig.static = false;
1371
+ }
1372
+ return arg;
1373
+ }, this);
1374
+ return sig;
1375
+ },
1376
+ _parseArg: function(rawArg) {
1377
+ var arg = rawArg.trim().replace(/&comma;/g, ",").replace(/\\(.)/g, "$1");
1378
+ var a = {
1379
+ name: arg,
1380
+ model: this._modelForPath(arg)
1381
+ };
1382
+ var fc = arg[0];
1383
+ if (fc >= "0" && fc <= "9") {
1384
+ fc = "#";
1385
+ }
1386
+ switch (fc) {
1387
+ case "'":
1388
+ case '"':
1389
+ a.value = arg.slice(1, -1);
1390
+ a.literal = true;
1391
+ break;
1392
+
1393
+ case "#":
1394
+ a.value = Number(arg);
1395
+ a.literal = true;
1396
+ break;
1397
+ }
1398
+ if (!a.literal) {
1399
+ a.structured = arg.indexOf(".") > 0;
1400
+ if (a.structured) {
1401
+ a.wildcard = arg.slice(-2) == ".*";
1402
+ if (a.wildcard) {
1403
+ a.name = arg.slice(0, -2);
1404
+ }
1405
+ }
1406
+ }
1407
+ return a;
1408
+ },
1409
+ _marshalInstanceEffects: function() {
1410
+ Polymer.Bind.prepareInstance(this);
1411
+ Polymer.Bind.setupBindListeners(this);
1412
+ },
1413
+ _applyEffectValue: function(value, info) {
1414
+ var node = this._nodes[info.index];
1415
+ var property = info.property || info.name || "textContent";
1416
+ if (info.kind == "attribute") {
1417
+ this.serializeValueToAttribute(value, property, node);
1418
+ } else {
1419
+ if (property === "className") {
1420
+ value = this._scopeElementClass(node, value);
1421
+ }
1422
+ if (property === "textContent" || node.localName == "input" && property == "value") {
1423
+ value = value == undefined ? "" : value;
1424
+ }
1425
+ return node[property] = value;
1426
+ }
1427
+ },
1428
+ _executeStaticEffects: function() {
1429
+ if (this._propertyEffects.__static__) {
1430
+ this._effectEffects("__static__", null, this._propertyEffects.__static__);
1431
+ }
1432
+ }
1433
+ });
1434
+
1435
+ Polymer.Base._addFeature({
1436
+ _setupConfigure: function(initialConfig) {
1437
+ this._config = initialConfig || {};
1438
+ this._handlers = [];
1439
+ },
1440
+ _marshalAttributes: function() {
1441
+ this._takeAttributesToModel(this._config);
1442
+ },
1443
+ _configValue: function(name, value) {
1444
+ this._config[name] = value;
1445
+ },
1446
+ _beforeClientsReady: function() {
1447
+ this._configure();
1448
+ },
1449
+ _configure: function() {
1450
+ this._configureAnnotationReferences();
1451
+ var config = {};
1452
+ this.behaviors.forEach(function(b) {
1453
+ this._configureProperties(b.properties, config);
1454
+ }, this);
1455
+ this._configureProperties(this.properties, config);
1456
+ this._mixinConfigure(config, this._config);
1457
+ this._config = config;
1458
+ this._distributeConfig(this._config);
1459
+ },
1460
+ _configureProperties: function(properties, config) {
1461
+ for (var i in properties) {
1462
+ var c = properties[i];
1463
+ if (c.value !== undefined) {
1464
+ var value = c.value;
1465
+ if (typeof value == "function") {
1466
+ value = value.call(this, this._config);
1467
+ }
1468
+ config[i] = value;
1469
+ }
1470
+ }
1471
+ },
1472
+ _mixinConfigure: function(a, b) {
1473
+ for (var prop in b) {
1474
+ if (!this.getPropertyInfo(prop).readOnly) {
1475
+ a[prop] = b[prop];
1476
+ }
1477
+ }
1478
+ },
1479
+ _distributeConfig: function(config) {
1480
+ var fx$ = this._propertyEffects;
1481
+ if (fx$) {
1482
+ for (var p in config) {
1483
+ var fx = fx$[p];
1484
+ if (fx) {
1485
+ for (var i = 0, l = fx.length, x; i < l && (x = fx[i]); i++) {
1486
+ if (x.kind === "annotation") {
1487
+ var node = this._nodes[x.effect.index];
1488
+ if (node._configValue) {
1489
+ var value = p === x.effect.value ? config[p] : this.get(x.effect.value, config);
1490
+ node._configValue(x.effect.name, value);
1491
+ }
1492
+ }
1493
+ }
1494
+ }
1495
+ }
1496
+ }
1497
+ },
1498
+ _afterClientsReady: function() {
1499
+ this._executeStaticEffects();
1500
+ this._applyConfig(this._config);
1501
+ this._flushHandlers();
1502
+ },
1503
+ _applyConfig: function(config) {
1504
+ for (var n in config) {
1505
+ if (this[n] === undefined) {
1506
+ var effects = this._propertyEffects[n];
1507
+ if (effects) {
1508
+ this._propertySet(n, config[n], effects);
1509
+ } else {
1510
+ this[n] = config[n];
1511
+ }
1512
+ }
1513
+ }
1514
+ },
1515
+ _notifyListener: function(fn, e) {
1516
+ if (!this._clientsReadied) {
1517
+ this._queueHandler([ fn, e, e.target ]);
1518
+ } else {
1519
+ return fn.call(this, e, e.target);
1520
+ }
1521
+ },
1522
+ _queueHandler: function(args) {
1523
+ this._handlers.push(args);
1524
+ },
1525
+ _flushHandlers: function() {
1526
+ var h$ = this._handlers;
1527
+ for (var i = 0, l = h$.length, h; i < l && (h = h$[i]); i++) {
1528
+ h[0].call(this, h[1], h[2]);
1529
+ }
1530
+ }
1531
+ });
1532
+
1533
+ (function() {
1534
+ "use strict";
1535
+ Polymer.Base._addFeature({
1536
+ notifyPath: function(path, value, fromAbove) {
1537
+ var old = this._propertySet(path, value);
1538
+ if (old !== value) {
1539
+ this._pathEffector(path, value);
1540
+ if (!fromAbove) {
1541
+ this._notifyPath(path, value);
1542
+ }
1543
+ }
1544
+ },
1545
+ _getPathParts: function(path) {
1546
+ if (Array.isArray(path)) {
1547
+ var parts = [];
1548
+ for (var i = 0; i < path.length; i++) {
1549
+ var args = path[i].toString().split(".");
1550
+ for (var j = 0; j < args.length; j++) {
1551
+ parts.push(args[j]);
1552
+ }
1553
+ }
1554
+ return parts;
1555
+ } else {
1556
+ return path.toString().split(".");
1557
+ }
1558
+ },
1559
+ set: function(path, value, root) {
1560
+ var prop = root || this;
1561
+ var parts = this._getPathParts(path);
1562
+ var array;
1563
+ var last = parts[parts.length - 1];
1564
+ if (parts.length > 1) {
1565
+ for (var i = 0; i < parts.length - 1; i++) {
1566
+ prop = prop[parts[i]];
1567
+ if (array) {
1568
+ parts[i] = Polymer.Collection.get(array).getKey(prop);
1569
+ }
1570
+ if (!prop) {
1571
+ return;
1572
+ }
1573
+ array = Array.isArray(prop) ? prop : null;
1574
+ }
1575
+ prop[last] = value;
1576
+ if (!root) {
1577
+ this.notifyPath(parts.join("."), value);
1578
+ }
1579
+ } else {
1580
+ prop[path] = value;
1581
+ }
1582
+ },
1583
+ get: function(path, root) {
1584
+ var prop = root || this;
1585
+ var parts = this._getPathParts(path);
1586
+ var last = parts.pop();
1587
+ while (parts.length) {
1588
+ prop = prop[parts.shift()];
1589
+ if (!prop) {
1590
+ return;
1591
+ }
1592
+ }
1593
+ return prop[last];
1594
+ },
1595
+ _pathEffector: function(path, value) {
1596
+ var model = this._modelForPath(path);
1597
+ var fx$ = this._propertyEffects[model];
1598
+ if (fx$) {
1599
+ fx$.forEach(function(fx) {
1600
+ var fxFn = this["_" + fx.kind + "PathEffect"];
1601
+ if (fxFn) {
1602
+ fxFn.call(this, path, value, fx.effect);
1603
+ }
1604
+ }, this);
1605
+ }
1606
+ if (this._boundPaths) {
1607
+ this._notifyBoundPaths(path, value);
1608
+ }
1609
+ },
1610
+ _annotationPathEffect: function(path, value, effect) {
1611
+ if (effect.value === path || effect.value.indexOf(path + ".") === 0) {
1612
+ Polymer.Bind._annotationEffect.call(this, path, value, effect);
1613
+ } else if (path.indexOf(effect.value + ".") === 0 && !effect.negate) {
1614
+ var node = this._nodes[effect.index];
1615
+ if (node && node.notifyPath) {
1616
+ var p = this._fixPath(effect.name, effect.value, path);
1617
+ node.notifyPath(p, value, true);
1618
+ }
1619
+ }
1620
+ },
1621
+ _complexObserverPathEffect: function(path, value, effect) {
1622
+ if (this._pathMatchesEffect(path, effect)) {
1623
+ Polymer.Bind._complexObserverEffect.call(this, path, value, effect);
1624
+ }
1625
+ },
1626
+ _computePathEffect: function(path, value, effect) {
1627
+ if (this._pathMatchesEffect(path, effect)) {
1628
+ Polymer.Bind._computeEffect.call(this, path, value, effect);
1629
+ }
1630
+ },
1631
+ _annotatedComputationPathEffect: function(path, value, effect) {
1632
+ if (this._pathMatchesEffect(path, effect)) {
1633
+ Polymer.Bind._annotatedComputationEffect.call(this, path, value, effect);
1634
+ }
1635
+ },
1636
+ _pathMatchesEffect: function(path, effect) {
1637
+ var effectArg = effect.trigger.name;
1638
+ return effectArg == path || effectArg.indexOf(path + ".") === 0 || effect.trigger.wildcard && path.indexOf(effectArg) === 0;
1639
+ },
1640
+ linkPaths: function(to, from) {
1641
+ this._boundPaths = this._boundPaths || {};
1642
+ if (from) {
1643
+ this._boundPaths[to] = from;
1644
+ } else {
1645
+ this.unbindPath(to);
1646
+ }
1647
+ },
1648
+ unlinkPaths: function(path) {
1649
+ if (this._boundPaths) {
1650
+ delete this._boundPaths[path];
1651
+ }
1652
+ },
1653
+ _notifyBoundPaths: function(path, value) {
1654
+ var from, to;
1655
+ for (var a in this._boundPaths) {
1656
+ var b = this._boundPaths[a];
1657
+ if (path.indexOf(a + ".") == 0) {
1658
+ from = a;
1659
+ to = b;
1660
+ break;
1661
+ }
1662
+ if (path.indexOf(b + ".") == 0) {
1663
+ from = b;
1664
+ to = a;
1665
+ break;
1666
+ }
1667
+ }
1668
+ if (from && to) {
1669
+ var p = this._fixPath(to, from, path);
1670
+ this.notifyPath(p, value);
1671
+ }
1672
+ },
1673
+ _fixPath: function(property, root, path) {
1674
+ return property + path.slice(root.length);
1675
+ },
1676
+ _notifyPath: function(path, value) {
1677
+ var rootName = this._modelForPath(path);
1678
+ var dashCaseName = Polymer.CaseMap.camelToDashCase(rootName);
1679
+ var eventName = dashCaseName + this._EVENT_CHANGED;
1680
+ this.fire(eventName, {
1681
+ path: path,
1682
+ value: value
1683
+ }, {
1684
+ bubbles: false
1685
+ });
1686
+ },
1687
+ _modelForPath: function(path) {
1688
+ var dot = path.indexOf(".");
1689
+ return dot < 0 ? path : path.slice(0, dot);
1690
+ },
1691
+ _EVENT_CHANGED: "-changed",
1692
+ _notifySplice: function(array, path, index, added, removed) {
1693
+ var splices = [ {
1694
+ index: index,
1695
+ addedCount: added,
1696
+ removed: removed,
1697
+ object: array,
1698
+ type: "splice"
1699
+ } ];
1700
+ var change = {
1701
+ keySplices: Polymer.Collection.get(array).applySplices(splices),
1702
+ indexSplices: splices
1703
+ };
1704
+ this.set(path + ".splices", change);
1705
+ if (added != removed.length) {
1706
+ this.notifyPath(path + ".length", array.length);
1707
+ }
1708
+ change.keySplices = null;
1709
+ change.indexSplices = null;
1710
+ },
1711
+ push: function(path) {
1712
+ var array = this.get(path);
1713
+ var args = Array.prototype.slice.call(arguments, 1);
1714
+ var len = array.length;
1715
+ var ret = array.push.apply(array, args);
1716
+ this._notifySplice(array, path, len, args.length, []);
1717
+ return ret;
1718
+ },
1719
+ pop: function(path) {
1720
+ var array = this.get(path);
1721
+ var args = Array.prototype.slice.call(arguments, 1);
1722
+ var rem = array.slice(-1);
1723
+ var ret = array.pop.apply(array, args);
1724
+ this._notifySplice(array, path, array.length, 0, rem);
1725
+ return ret;
1726
+ },
1727
+ splice: function(path, start, deleteCount) {
1728
+ var array = this.get(path);
1729
+ var args = Array.prototype.slice.call(arguments, 1);
1730
+ var rem = array.slice(start, start + deleteCount);
1731
+ var ret = array.splice.apply(array, args);
1732
+ this._notifySplice(array, path, start, args.length - 2, rem);
1733
+ return ret;
1734
+ },
1735
+ shift: function(path) {
1736
+ var array = this.get(path);
1737
+ var args = Array.prototype.slice.call(arguments, 1);
1738
+ var ret = array.shift.apply(array, args);
1739
+ this._notifySplice(array, path, 0, 0, [ ret ]);
1740
+ return ret;
1741
+ },
1742
+ unshift: function(path) {
1743
+ var array = this.get(path);
1744
+ var args = Array.prototype.slice.call(arguments, 1);
1745
+ var ret = array.unshift.apply(array, args);
1746
+ this._notifySplice(array, path, 0, args.length, []);
1747
+ return ret;
1748
+ }
1749
+ });
1750
+ })();
1751
+
1752
+ Polymer.Base._addFeature({
1753
+ resolveUrl: function(url) {
1754
+ var module = Polymer.DomModule.import(this.is);
1755
+ var root = "";
1756
+ if (module) {
1757
+ var assetPath = module.getAttribute("assetpath") || "";
1758
+ root = Polymer.ResolveUrl.resolveUrl(assetPath, module.ownerDocument.baseURI);
1759
+ }
1760
+ return Polymer.ResolveUrl.resolveUrl(url, root);
1761
+ }
1762
+ });
1763
+
1764
+ Polymer.CssParse = function() {
1765
+ var api = {
1766
+ parse: function(text) {
1767
+ text = this._clean(text);
1768
+ return this._parseCss(this._lex(text), text);
1769
+ },
1770
+ _clean: function(cssText) {
1771
+ return cssText.replace(rx.comments, "").replace(rx.port, "");
1772
+ },
1773
+ _lex: function(text) {
1774
+ var root = {
1775
+ start: 0,
1776
+ end: text.length
1777
+ };
1778
+ var n = root;
1779
+ for (var i = 0, s = 0, l = text.length; i < l; i++) {
1780
+ switch (text[i]) {
1781
+ case this.OPEN_BRACE:
1782
+ if (!n.rules) {
1783
+ n.rules = [];
1784
+ }
1785
+ var p = n;
1786
+ var previous = p.rules[p.rules.length - 1];
1787
+ n = {
1788
+ start: i + 1,
1789
+ parent: p,
1790
+ previous: previous
1791
+ };
1792
+ p.rules.push(n);
1793
+ break;
1794
+
1795
+ case this.CLOSE_BRACE:
1796
+ n.end = i + 1;
1797
+ n = n.parent || root;
1798
+ break;
1799
+ }
1800
+ }
1801
+ return root;
1802
+ },
1803
+ _parseCss: function(node, text) {
1804
+ var t = text.substring(node.start, node.end - 1);
1805
+ node.parsedCssText = node.cssText = t.trim();
1806
+ if (node.parent) {
1807
+ var ss = node.previous ? node.previous.end : node.parent.start;
1808
+ t = text.substring(ss, node.start - 1);
1809
+ t = t.substring(t.lastIndexOf(";") + 1);
1810
+ var s = node.parsedSelector = node.selector = t.trim();
1811
+ node.atRule = s.indexOf(AT_START) === 0;
1812
+ if (node.atRule) {
1813
+ if (s.indexOf(MEDIA_START) === 0) {
1814
+ node.type = this.types.MEDIA_RULE;
1815
+ } else if (s.match(rx.keyframesRule)) {
1816
+ node.type = this.types.KEYFRAMES_RULE;
1817
+ }
1818
+ } else {
1819
+ if (s.indexOf(VAR_START) === 0) {
1820
+ node.type = this.types.MIXIN_RULE;
1821
+ } else {
1822
+ node.type = this.types.STYLE_RULE;
1823
+ }
1824
+ }
1825
+ }
1826
+ var r$ = node.rules;
1827
+ if (r$) {
1828
+ for (var i = 0, l = r$.length, r; i < l && (r = r$[i]); i++) {
1829
+ this._parseCss(r, text);
1830
+ }
1831
+ }
1832
+ return node;
1833
+ },
1834
+ stringify: function(node, preserveProperties, text) {
1835
+ text = text || "";
1836
+ var cssText = "";
1837
+ if (node.cssText || node.rules) {
1838
+ var r$ = node.rules;
1839
+ if (r$ && (preserveProperties || !hasMixinRules(r$))) {
1840
+ for (var i = 0, l = r$.length, r; i < l && (r = r$[i]); i++) {
1841
+ cssText = this.stringify(r, preserveProperties, cssText);
1842
+ }
1843
+ } else {
1844
+ cssText = preserveProperties ? node.cssText : removeCustomProps(node.cssText);
1845
+ cssText = cssText.trim();
1846
+ if (cssText) {
1847
+ cssText = " " + cssText + "\n";
1848
+ }
1849
+ }
1850
+ }
1851
+ if (cssText) {
1852
+ if (node.selector) {
1853
+ text += node.selector + " " + this.OPEN_BRACE + "\n";
1854
+ }
1855
+ text += cssText;
1856
+ if (node.selector) {
1857
+ text += this.CLOSE_BRACE + "\n\n";
1858
+ }
1859
+ }
1860
+ return text;
1861
+ },
1862
+ types: {
1863
+ STYLE_RULE: 1,
1864
+ KEYFRAMES_RULE: 7,
1865
+ MEDIA_RULE: 4,
1866
+ MIXIN_RULE: 1e3
1867
+ },
1868
+ OPEN_BRACE: "{",
1869
+ CLOSE_BRACE: "}"
1870
+ };
1871
+ function hasMixinRules(rules) {
1872
+ return rules[0].selector.indexOf(VAR_START) >= 0;
1873
+ }
1874
+ function removeCustomProps(cssText) {
1875
+ return cssText.replace(rx.customProp, "").replace(rx.mixinProp, "").replace(rx.mixinApply, "").replace(rx.varApply, "");
1876
+ }
1877
+ var VAR_START = "--";
1878
+ var MEDIA_START = "@media";
1879
+ var AT_START = "@";
1880
+ var rx = {
1881
+ comments: /\/\*[^*]*\*+([^\/*][^*]*\*+)*\//gim,
1882
+ port: /@import[^;]*;/gim,
1883
+ customProp: /(?:^|[\s;])--[^;{]*?:[^{};]*?;/gim,
1884
+ mixinProp: /(?:^|[\s;])--[^;{]*?:[^{;]*?{[^}]*?};?/gim,
1885
+ mixinApply: /@apply[\s]*\([^)]*?\)[\s]*;/gim,
1886
+ varApply: /[^;:]*?:[^;]*var[^;]*;/gim,
1887
+ keyframesRule: /^@[^\s]*keyframes/
1888
+ };
1889
+ return api;
1890
+ }();
1891
+
1892
+ Polymer.StyleUtil = function() {
1893
+ return {
1894
+ MODULE_STYLES_SELECTOR: "style, link[rel=import][type~=css]",
1895
+ toCssText: function(rules, callback, preserveProperties) {
1896
+ if (typeof rules === "string") {
1897
+ rules = this.parser.parse(rules);
1898
+ }
1899
+ if (callback) {
1900
+ this.forEachStyleRule(rules, callback);
1901
+ }
1902
+ return this.parser.stringify(rules, preserveProperties);
1903
+ },
1904
+ forRulesInStyles: function(styles, callback) {
1905
+ for (var i = 0, l = styles.length, s; i < l && (s = styles[i]); i++) {
1906
+ this.forEachStyleRule(this.rulesForStyle(s), callback);
1907
+ }
1908
+ },
1909
+ rulesForStyle: function(style) {
1910
+ if (!style.__cssRules) {
1911
+ style.__cssRules = this.parser.parse(style.textContent);
1912
+ }
1913
+ return style.__cssRules;
1914
+ },
1915
+ clearStyleRules: function(style) {
1916
+ style.__cssRules = null;
1917
+ },
1918
+ forEachStyleRule: function(node, callback) {
1919
+ var s = node.selector;
1920
+ var skipRules = false;
1921
+ if (node.type === this.ruleTypes.STYLE_RULE) {
1922
+ callback(node);
1923
+ } else if (node.type === this.ruleTypes.KEYFRAMES_RULE || node.type === this.ruleTypes.MIXIN_RULE) {
1924
+ skipRules = true;
1925
+ }
1926
+ var r$ = node.rules;
1927
+ if (r$ && !skipRules) {
1928
+ for (var i = 0, l = r$.length, r; i < l && (r = r$[i]); i++) {
1929
+ this.forEachStyleRule(r, callback);
1930
+ }
1931
+ }
1932
+ },
1933
+ applyCss: function(cssText, moniker, target, afterNode) {
1934
+ var style = document.createElement("style");
1935
+ if (moniker) {
1936
+ style.setAttribute("scope", moniker);
1937
+ }
1938
+ style.textContent = cssText;
1939
+ target = target || document.head;
1940
+ if (!afterNode) {
1941
+ var n$ = target.querySelectorAll("style[scope]");
1942
+ afterNode = n$[n$.length - 1];
1943
+ }
1944
+ target.insertBefore(style, afterNode && afterNode.nextSibling || target.firstChild);
1945
+ return style;
1946
+ },
1947
+ cssFromModule: function(moduleId) {
1948
+ var m = Polymer.DomModule.import(moduleId);
1949
+ if (m && !m._cssText) {
1950
+ var cssText = "";
1951
+ var e$ = Array.prototype.slice.call(m.querySelectorAll(this.MODULE_STYLES_SELECTOR));
1952
+ for (var i = 0, e; i < e$.length; i++) {
1953
+ e = e$[i];
1954
+ if (e.localName === "style") {
1955
+ e = e.__appliedElement || e;
1956
+ e.parentNode.removeChild(e);
1957
+ } else {
1958
+ e = e.import && e.import.body;
1959
+ }
1960
+ if (e) {
1961
+ cssText += Polymer.ResolveUrl.resolveCss(e.textContent, e.ownerDocument);
1962
+ }
1963
+ }
1964
+ m._cssText = cssText;
1965
+ }
1966
+ return m && m._cssText || "";
1967
+ },
1968
+ parser: Polymer.CssParse,
1969
+ ruleTypes: Polymer.CssParse.types
1970
+ };
1971
+ }();
1972
+
1973
+ Polymer.StyleTransformer = function() {
1974
+ var nativeShadow = Polymer.Settings.useNativeShadow;
1975
+ var styleUtil = Polymer.StyleUtil;
1976
+ var api = {
1977
+ dom: function(node, scope, useAttr, shouldRemoveScope) {
1978
+ this._transformDom(node, scope || "", useAttr, shouldRemoveScope);
1979
+ },
1980
+ _transformDom: function(node, selector, useAttr, shouldRemoveScope) {
1981
+ if (node.setAttribute) {
1982
+ this.element(node, selector, useAttr, shouldRemoveScope);
1983
+ }
1984
+ var c$ = Polymer.dom(node).childNodes;
1985
+ for (var i = 0; i < c$.length; i++) {
1986
+ this._transformDom(c$[i], selector, useAttr, shouldRemoveScope);
1987
+ }
1988
+ },
1989
+ element: function(element, scope, useAttr, shouldRemoveScope) {
1990
+ if (useAttr) {
1991
+ if (shouldRemoveScope) {
1992
+ element.removeAttribute(SCOPE_NAME);
1993
+ } else {
1994
+ element.setAttribute(SCOPE_NAME, scope);
1995
+ }
1996
+ } else {
1997
+ if (scope) {
1998
+ if (element.classList) {
1999
+ if (shouldRemoveScope) {
2000
+ element.classList.remove(SCOPE_NAME);
2001
+ element.classList.remove(scope);
2002
+ } else {
2003
+ element.classList.add(SCOPE_NAME);
2004
+ element.classList.add(scope);
2005
+ }
2006
+ } else if (element.getAttribute) {
2007
+ var c = element.getAttribute(CLASS);
2008
+ if (shouldRemoveScope) {
2009
+ if (c) {
2010
+ element.setAttribute(CLASS, c.replace(SCOPE_NAME, "").replace(scope, ""));
2011
+ }
2012
+ } else {
2013
+ element.setAttribute(CLASS, c + (c ? " " : "") + SCOPE_NAME + " " + scope);
2014
+ }
2015
+ }
2016
+ }
2017
+ }
2018
+ },
2019
+ elementStyles: function(element, callback) {
2020
+ var styles = element._styles;
2021
+ var cssText = "";
2022
+ for (var i = 0, l = styles.length, s, text; i < l && (s = styles[i]); i++) {
2023
+ var rules = styleUtil.rulesForStyle(s);
2024
+ cssText += nativeShadow ? styleUtil.toCssText(rules, callback) : this.css(rules, element.is, element.extends, callback, element._scopeCssViaAttr) + "\n\n";
2025
+ }
2026
+ return cssText.trim();
2027
+ },
2028
+ css: function(rules, scope, ext, callback, useAttr) {
2029
+ var hostScope = this._calcHostScope(scope, ext);
2030
+ scope = this._calcElementScope(scope, useAttr);
2031
+ var self = this;
2032
+ return styleUtil.toCssText(rules, function(rule) {
2033
+ if (!rule.isScoped) {
2034
+ self.rule(rule, scope, hostScope);
2035
+ rule.isScoped = true;
2036
+ }
2037
+ if (callback) {
2038
+ callback(rule, scope, hostScope);
2039
+ }
2040
+ });
2041
+ },
2042
+ _calcElementScope: function(scope, useAttr) {
2043
+ if (scope) {
2044
+ return useAttr ? CSS_ATTR_PREFIX + scope + CSS_ATTR_SUFFIX : CSS_CLASS_PREFIX + scope;
2045
+ } else {
2046
+ return "";
2047
+ }
2048
+ },
2049
+ _calcHostScope: function(scope, ext) {
2050
+ return ext ? "[is=" + scope + "]" : scope;
2051
+ },
2052
+ rule: function(rule, scope, hostScope) {
2053
+ this._transformRule(rule, this._transformComplexSelector, scope, hostScope);
2054
+ },
2055
+ _transformRule: function(rule, transformer, scope, hostScope) {
2056
+ var p$ = rule.selector.split(COMPLEX_SELECTOR_SEP);
2057
+ for (var i = 0, l = p$.length, p; i < l && (p = p$[i]); i++) {
2058
+ p$[i] = transformer.call(this, p, scope, hostScope);
2059
+ }
2060
+ rule.selector = p$.join(COMPLEX_SELECTOR_SEP);
2061
+ },
2062
+ _transformComplexSelector: function(selector, scope, hostScope) {
2063
+ var stop = false;
2064
+ var self = this;
2065
+ selector = selector.replace(SIMPLE_SELECTOR_SEP, function(m, c, s) {
2066
+ if (!stop) {
2067
+ var o = self._transformCompoundSelector(s, c, scope, hostScope);
2068
+ if (o.stop) {
2069
+ stop = true;
2070
+ }
2071
+ c = o.combinator;
2072
+ s = o.value;
2073
+ }
2074
+ return c + s;
2075
+ });
2076
+ return selector;
2077
+ },
2078
+ _transformCompoundSelector: function(selector, combinator, scope, hostScope) {
2079
+ var jumpIndex = selector.search(SCOPE_JUMP);
2080
+ if (selector.indexOf(HOST) >= 0) {
2081
+ selector = selector.replace(HOST_PAREN, function(m, host, paren) {
2082
+ return hostScope + paren;
2083
+ });
2084
+ selector = selector.replace(HOST, hostScope);
2085
+ } else if (jumpIndex !== 0) {
2086
+ selector = scope ? this._transformSimpleSelector(selector, scope) : selector;
2087
+ }
2088
+ if (selector.indexOf(CONTENT) >= 0) {
2089
+ combinator = "";
2090
+ }
2091
+ var stop;
2092
+ if (jumpIndex >= 0) {
2093
+ selector = selector.replace(SCOPE_JUMP, " ");
2094
+ stop = true;
2095
+ }
2096
+ return {
2097
+ value: selector,
2098
+ combinator: combinator,
2099
+ stop: stop
2100
+ };
2101
+ },
2102
+ _transformSimpleSelector: function(selector, scope) {
2103
+ var p$ = selector.split(PSEUDO_PREFIX);
2104
+ p$[0] += scope;
2105
+ return p$.join(PSEUDO_PREFIX);
2106
+ },
2107
+ rootRule: function(rule) {
2108
+ this._transformRule(rule, this._transformRootSelector);
2109
+ },
2110
+ _transformRootSelector: function(selector) {
2111
+ return selector.match(SCOPE_JUMP) ? this._transformComplexSelector(selector) : selector.trim() + SCOPE_ROOT_SELECTOR;
2112
+ },
2113
+ SCOPE_NAME: "style-scope"
2114
+ };
2115
+ var SCOPE_NAME = api.SCOPE_NAME;
2116
+ var SCOPE_ROOT_SELECTOR = ":not([" + SCOPE_NAME + "])" + ":not(." + SCOPE_NAME + ")";
2117
+ var COMPLEX_SELECTOR_SEP = ",";
2118
+ var SIMPLE_SELECTOR_SEP = /(^|[\s>+~]+)([^\s>+~]+)/g;
2119
+ var HOST = ":host";
2120
+ var HOST_PAREN = /(\:host)(?:\(((?:\([^)(]*\)|[^)(]*)+?)\))/g;
2121
+ var CONTENT = "::content";
2122
+ var SCOPE_JUMP = /\:\:content|\:\:shadow|\/deep\//;
2123
+ var CSS_CLASS_PREFIX = ".";
2124
+ var CSS_ATTR_PREFIX = "[" + SCOPE_NAME + "~=";
2125
+ var CSS_ATTR_SUFFIX = "]";
2126
+ var PSEUDO_PREFIX = ":";
2127
+ var CLASS = "class";
2128
+ return api;
2129
+ }();
2130
+
2131
+ Polymer.StyleExtends = function() {
2132
+ var styleUtil = Polymer.StyleUtil;
2133
+ return {
2134
+ hasExtends: function(cssText) {
2135
+ return Boolean(cssText.match(this.rx.EXTEND));
2136
+ },
2137
+ transform: function(style) {
2138
+ var rules = styleUtil.rulesForStyle(style);
2139
+ var self = this;
2140
+ styleUtil.forEachStyleRule(rules, function(rule) {
2141
+ var map = self._mapRule(rule);
2142
+ if (rule.parent) {
2143
+ var m;
2144
+ while (m = self.rx.EXTEND.exec(rule.cssText)) {
2145
+ var extend = m[1];
2146
+ var extendor = self._findExtendor(extend, rule);
2147
+ if (extendor) {
2148
+ self._extendRule(rule, extendor);
2149
+ }
2150
+ }
2151
+ }
2152
+ rule.cssText = rule.cssText.replace(self.rx.EXTEND, "");
2153
+ });
2154
+ return styleUtil.toCssText(rules, function(rule) {
2155
+ if (rule.selector.match(self.rx.STRIP)) {
2156
+ rule.cssText = "";
2157
+ }
2158
+ }, true);
2159
+ },
2160
+ _mapRule: function(rule) {
2161
+ if (rule.parent) {
2162
+ var map = rule.parent.map || (rule.parent.map = {});
2163
+ var parts = rule.selector.split(",");
2164
+ for (var i = 0, p; i < parts.length; i++) {
2165
+ p = parts[i];
2166
+ map[p.trim()] = rule;
2167
+ }
2168
+ return map;
2169
+ }
2170
+ },
2171
+ _findExtendor: function(extend, rule) {
2172
+ return rule.parent && rule.parent.map && rule.parent.map[extend] || this._findExtendor(extend, rule.parent);
2173
+ },
2174
+ _extendRule: function(target, source) {
2175
+ if (target.parent !== source.parent) {
2176
+ this._cloneAndAddRuleToParent(source, target.parent);
2177
+ }
2178
+ target.extends = target.extends || (target.extends = []);
2179
+ target.extends.push(source);
2180
+ source.selector = source.selector.replace(this.rx.STRIP, "");
2181
+ source.selector = (source.selector && source.selector + ",\n") + target.selector;
2182
+ if (source.extends) {
2183
+ source.extends.forEach(function(e) {
2184
+ this._extendRule(target, e);
2185
+ }, this);
2186
+ }
2187
+ },
2188
+ _cloneAndAddRuleToParent: function(rule, parent) {
2189
+ rule = Object.create(rule);
2190
+ rule.parent = parent;
2191
+ if (rule.extends) {
2192
+ rule.extends = rule.extends.slice();
2193
+ }
2194
+ parent.rules.push(rule);
2195
+ },
2196
+ rx: {
2197
+ EXTEND: /@extends\(([^)]*)\)\s*?;/gim,
2198
+ STRIP: /%[^,]*$/
2199
+ }
2200
+ };
2201
+ }();
2202
+
2203
+ (function() {
2204
+ var prepElement = Polymer.Base._prepElement;
2205
+ var nativeShadow = Polymer.Settings.useNativeShadow;
2206
+ var styleUtil = Polymer.StyleUtil;
2207
+ var styleTransformer = Polymer.StyleTransformer;
2208
+ var styleExtends = Polymer.StyleExtends;
2209
+ Polymer.Base._addFeature({
2210
+ _prepElement: function(element) {
2211
+ if (this._encapsulateStyle) {
2212
+ styleTransformer.element(element, this.is, this._scopeCssViaAttr);
2213
+ }
2214
+ prepElement.call(this, element);
2215
+ },
2216
+ _prepStyles: function() {
2217
+ if (this._encapsulateStyle === undefined) {
2218
+ this._encapsulateStyle = !nativeShadow && Boolean(this._template);
2219
+ }
2220
+ this._styles = this._collectStyles();
2221
+ var cssText = styleTransformer.elementStyles(this);
2222
+ if (cssText && this._template) {
2223
+ var style = styleUtil.applyCss(cssText, this.is, nativeShadow ? this._template.content : null);
2224
+ if (!nativeShadow) {
2225
+ this._scopeStyle = style;
2226
+ }
2227
+ }
2228
+ },
2229
+ _collectStyles: function() {
2230
+ var styles = [];
2231
+ var cssText = "", m$ = this.styleModules;
2232
+ if (m$) {
2233
+ for (var i = 0, l = m$.length, m; i < l && (m = m$[i]); i++) {
2234
+ cssText += styleUtil.cssFromModule(m);
2235
+ }
2236
+ }
2237
+ cssText += styleUtil.cssFromModule(this.is);
2238
+ if (cssText) {
2239
+ var style = document.createElement("style");
2240
+ style.textContent = cssText;
2241
+ if (styleExtends.hasExtends(style.textContent)) {
2242
+ cssText = styleExtends.transform(style);
2243
+ }
2244
+ styles.push(style);
2245
+ }
2246
+ return styles;
2247
+ },
2248
+ _elementAdd: function(node) {
2249
+ if (this._encapsulateStyle && !node.__styleScoped) {
2250
+ styleTransformer.dom(node, this.is, this._scopeCssViaAttr);
2251
+ }
2252
+ },
2253
+ _elementRemove: function(node) {
2254
+ if (this._encapsulateStyle) {
2255
+ styleTransformer.dom(node, this.is, this._scopeCssViaAttr, true);
2256
+ }
2257
+ },
2258
+ scopeSubtree: function(container, shouldObserve) {
2259
+ if (nativeShadow) {
2260
+ return;
2261
+ }
2262
+ var self = this;
2263
+ var scopify = function(node) {
2264
+ if (node.nodeType === Node.ELEMENT_NODE) {
2265
+ node.className = self._scopeElementClass(node, node.className);
2266
+ var n$ = node.querySelectorAll("*");
2267
+ Array.prototype.forEach.call(n$, function(n) {
2268
+ n.className = self._scopeElementClass(n, n.className);
2269
+ });
2270
+ }
2271
+ };
2272
+ scopify(container);
2273
+ if (shouldObserve) {
2274
+ var mo = new MutationObserver(function(mxns) {
2275
+ mxns.forEach(function(m) {
2276
+ if (m.addedNodes) {
2277
+ for (var i = 0; i < m.addedNodes.length; i++) {
2278
+ scopify(m.addedNodes[i]);
2279
+ }
2280
+ }
2281
+ });
2282
+ });
2283
+ mo.observe(container, {
2284
+ childList: true,
2285
+ subtree: true
2286
+ });
2287
+ return mo;
2288
+ }
2289
+ }
2290
+ });
2291
+ })();
2292
+
2293
+ Polymer.StyleProperties = function() {
2294
+ var nativeShadow = Polymer.Settings.useNativeShadow;
2295
+ var matchesSelector = Polymer.DomApi.matchesSelector;
2296
+ var styleUtil = Polymer.StyleUtil;
2297
+ var styleTransformer = Polymer.StyleTransformer;
2298
+ return {
2299
+ decorateStyles: function(styles) {
2300
+ var self = this, props = {};
2301
+ styleUtil.forRulesInStyles(styles, function(rule) {
2302
+ self.decorateRule(rule);
2303
+ self.collectPropertiesInCssText(rule.propertyInfo.cssText, props);
2304
+ });
2305
+ var names = [];
2306
+ for (var i in props) {
2307
+ names.push(i);
2308
+ }
2309
+ return names;
2310
+ },
2311
+ decorateRule: function(rule) {
2312
+ if (rule.propertyInfo) {
2313
+ return rule.propertyInfo;
2314
+ }
2315
+ var info = {}, properties = {};
2316
+ var hasProperties = this.collectProperties(rule, properties);
2317
+ if (hasProperties) {
2318
+ info.properties = properties;
2319
+ rule.rules = null;
2320
+ }
2321
+ info.cssText = this.collectCssText(rule);
2322
+ rule.propertyInfo = info;
2323
+ return info;
2324
+ },
2325
+ collectProperties: function(rule, properties) {
2326
+ var info = rule.propertyInfo;
2327
+ if (info) {
2328
+ if (info.properties) {
2329
+ Polymer.Base.mixin(properties, info.properties);
2330
+ return true;
2331
+ }
2332
+ } else {
2333
+ var m, rx = this.rx.VAR_ASSIGN;
2334
+ var cssText = rule.parsedCssText;
2335
+ var any;
2336
+ while (m = rx.exec(cssText)) {
2337
+ properties[m[1]] = (m[2] || m[3]).trim();
2338
+ any = true;
2339
+ }
2340
+ return any;
2341
+ }
2342
+ },
2343
+ collectCssText: function(rule) {
2344
+ var customCssText = "";
2345
+ var cssText = rule.parsedCssText;
2346
+ cssText = cssText.replace(this.rx.BRACKETED, "").replace(this.rx.VAR_ASSIGN, "");
2347
+ var parts = cssText.split(";");
2348
+ for (var i = 0, p; i < parts.length; i++) {
2349
+ p = parts[i];
2350
+ if (p.match(this.rx.MIXIN_MATCH) || p.match(this.rx.VAR_MATCH)) {
2351
+ customCssText += p + ";\n";
2352
+ }
2353
+ }
2354
+ return customCssText;
2355
+ },
2356
+ collectPropertiesInCssText: function(cssText, props) {
2357
+ var m;
2358
+ while (m = this.rx.VAR_CAPTURE.exec(cssText)) {
2359
+ props[m[1]] = true;
2360
+ }
2361
+ },
2362
+ reify: function(props) {
2363
+ var names = Object.getOwnPropertyNames(props);
2364
+ for (var i = 0, n; i < names.length; i++) {
2365
+ n = names[i];
2366
+ props[n] = this.valueForProperty(props[n], props);
2367
+ }
2368
+ },
2369
+ valueForProperty: function(property, props) {
2370
+ if (property) {
2371
+ if (property.indexOf(";") >= 0) {
2372
+ property = this.valueForProperties(property, props);
2373
+ } else {
2374
+ var self = this;
2375
+ var fn = function(all, prefix, value, fallback) {
2376
+ var propertyValue = self.valueForProperty(props[value], props) || (props[fallback] ? self.valueForProperty(props[fallback], props) : fallback);
2377
+ return prefix + (propertyValue || "");
2378
+ };
2379
+ property = property.replace(this.rx.VAR_MATCH, fn);
2380
+ }
2381
+ }
2382
+ return property && property.trim() || "";
2383
+ },
2384
+ valueForProperties: function(property, props) {
2385
+ var parts = property.split(";");
2386
+ for (var i = 0, p, m; i < parts.length && (p = parts[i]); i++) {
2387
+ m = p.match(this.rx.MIXIN_MATCH);
2388
+ if (m) {
2389
+ p = this.valueForProperty(props[m[1]], props);
2390
+ } else {
2391
+ var pp = p.split(":");
2392
+ if (pp[1]) {
2393
+ pp[1] = pp[1].trim();
2394
+ pp[1] = this.valueForProperty(pp[1], props) || pp[1];
2395
+ }
2396
+ p = pp.join(":");
2397
+ }
2398
+ parts[i] = p && p.lastIndexOf(";") === p.length - 1 ? p.slice(0, -1) : p || "";
2399
+ }
2400
+ return parts.join(";");
2401
+ },
2402
+ applyProperties: function(rule, props) {
2403
+ var output = "";
2404
+ if (!rule.properties) {
2405
+ this.decorateRule(rule);
2406
+ }
2407
+ if (rule.propertyInfo.cssText) {
2408
+ output = this.valueForProperties(rule.propertyInfo.cssText, props);
2409
+ }
2410
+ rule.cssText = output;
2411
+ },
2412
+ propertyDataFromStyles: function(styles, element) {
2413
+ var props = {}, self = this;
2414
+ var o = [], i = 0;
2415
+ styleUtil.forRulesInStyles(styles, function(rule) {
2416
+ if (!rule.propertyInfo) {
2417
+ self.decorateRule(rule);
2418
+ }
2419
+ if (element && rule.propertyInfo.properties && matchesSelector.call(element, rule.selector)) {
2420
+ self.collectProperties(rule, props);
2421
+ addToBitMask(i, o);
2422
+ }
2423
+ i++;
2424
+ });
2425
+ return {
2426
+ properties: props,
2427
+ key: o
2428
+ };
2429
+ },
2430
+ scopePropertiesFromStyles: function(styles) {
2431
+ if (!styles._scopeStyleProperties) {
2432
+ styles._scopeStyleProperties = this.selectedPropertiesFromStyles(styles, this.SCOPE_SELECTORS);
2433
+ }
2434
+ return styles._scopeStyleProperties;
2435
+ },
2436
+ hostPropertiesFromStyles: function(styles) {
2437
+ if (!styles._hostStyleProperties) {
2438
+ styles._hostStyleProperties = this.selectedPropertiesFromStyles(styles, this.HOST_SELECTORS);
2439
+ }
2440
+ return styles._hostStyleProperties;
2441
+ },
2442
+ selectedPropertiesFromStyles: function(styles, selectors) {
2443
+ var props = {}, self = this;
2444
+ styleUtil.forRulesInStyles(styles, function(rule) {
2445
+ if (!rule.propertyInfo) {
2446
+ self.decorateRule(rule);
2447
+ }
2448
+ for (var i = 0; i < selectors.length; i++) {
2449
+ if (rule.parsedSelector === selectors[i]) {
2450
+ self.collectProperties(rule, props);
2451
+ return;
2452
+ }
2453
+ }
2454
+ });
2455
+ return props;
2456
+ },
2457
+ transformStyles: function(element, properties, scopeSelector) {
2458
+ var self = this;
2459
+ var hostRx = new RegExp(this.rx.HOST_PREFIX + element.is + this.rx.HOST_SUFFIX);
2460
+ return styleTransformer.elementStyles(element, function(rule) {
2461
+ self.applyProperties(rule, properties);
2462
+ if (rule.cssText && !nativeShadow) {
2463
+ self._scopeSelector(rule, hostRx, element.is, element._scopeCssViaAttr, scopeSelector);
2464
+ }
2465
+ });
2466
+ },
2467
+ _scopeSelector: function(rule, hostRx, is, viaAttr, scopeId) {
2468
+ rule.transformedSelector = rule.transformedSelector || rule.selector;
2469
+ var selector = rule.transformedSelector;
2470
+ var scope = viaAttr ? "[" + styleTransformer.SCOPE_NAME + "~=" + scopeId + "]" : "." + scopeId;
2471
+ var parts = selector.split(",");
2472
+ for (var i = 0, l = parts.length, p; i < l && (p = parts[i]); i++) {
2473
+ parts[i] = p.match(hostRx) ? p.replace(is, is + scope) : scope + " " + p;
2474
+ }
2475
+ rule.selector = parts.join(",");
2476
+ },
2477
+ applyElementScopeSelector: function(element, selector, old, viaAttr) {
2478
+ var c = viaAttr ? element.getAttribute(styleTransformer.SCOPE_NAME) : element.className;
2479
+ v = old ? c.replace(old, selector) : (c ? c + " " : "") + this.XSCOPE_NAME + " " + selector;
2480
+ if (c !== v) {
2481
+ if (viaAttr) {
2482
+ element.setAttribute(styleTransformer.SCOPE_NAME, v);
2483
+ } else {
2484
+ element.className = v;
2485
+ }
2486
+ }
2487
+ },
2488
+ applyElementStyle: function(element, properties, selector, style) {
2489
+ var cssText = style ? style.textContent || "" : this.transformStyles(element, properties, selector);
2490
+ var s = element._customStyle;
2491
+ if (s && !nativeShadow && s !== style) {
2492
+ s._useCount--;
2493
+ if (s._useCount <= 0) {
2494
+ s.parentNode.removeChild(s);
2495
+ }
2496
+ }
2497
+ if (nativeShadow || (!style || !style.parentNode)) {
2498
+ if (nativeShadow && element._customStyle) {
2499
+ element._customStyle.textContent = cssText;
2500
+ style = element._customStyle;
2501
+ } else if (cssText) {
2502
+ style = styleUtil.applyCss(cssText, selector, nativeShadow ? element.root : null, element._scopeStyle);
2503
+ }
2504
+ }
2505
+ if (style) {
2506
+ style._useCount = style._useCount || 0;
2507
+ if (element._customStyle != style) {
2508
+ style._useCount++;
2509
+ }
2510
+ element._customStyle = style;
2511
+ }
2512
+ return style;
2513
+ },
2514
+ rx: {
2515
+ VAR_ASSIGN: /(?:^|;\s*)(--[^\:;]*?):\s*?(?:([^;{]*?)|{([^}]*)})(?=;)/gim,
2516
+ MIXIN_MATCH: /(?:^|\W+)@apply[\s]*\(([^)]*)\);?/im,
2517
+ VAR_MATCH: /(^|\W+)var\([\s]*([^,)]*)[\s]*,?[\s]*((?:[^,)]*)|(?:[^;]*\([^;)]*\)))[\s]*?\)/gim,
2518
+ VAR_CAPTURE: /\([\s]*(--[^,\s)]*)(?:,[\s]*(--[^,\s)]*))?(?:\)|,)/gim,
2519
+ BRACKETED: /\{[^}]*\}/g,
2520
+ HOST_PREFIX: "(?:^|[^.])",
2521
+ HOST_SUFFIX: "($|[.:[\\s>+~])"
2522
+ },
2523
+ HOST_SELECTORS: [ ":host" ],
2524
+ SCOPE_SELECTORS: [ ":root" ],
2525
+ XSCOPE_NAME: "x-scope"
2526
+ };
2527
+ function addToBitMask(n, bits) {
2528
+ var o = parseInt(n / 32);
2529
+ var v = 1 << n % 32;
2530
+ bits[o] = (bits[o] || 0) | v;
2531
+ }
2532
+ }();
2533
+
2534
+ Polymer.StyleDefaults = function() {
2535
+ var styleProperties = Polymer.StyleProperties;
2536
+ var styleUtil = Polymer.StyleUtil;
2537
+ var style = document.createElement("style");
2538
+ var api = {
2539
+ style: style,
2540
+ _styles: [ style ],
2541
+ _properties: null,
2542
+ applyCss: function(cssText) {
2543
+ this.style.textContent += cssText;
2544
+ styleUtil.clearStyleRules(this.style);
2545
+ this._properties = null;
2546
+ },
2547
+ get _styleProperties() {
2548
+ if (!this._properties) {
2549
+ styleProperties.decorateStyles(this._styles);
2550
+ this._styles._scopeStyleProperties = null;
2551
+ this._properties = styleProperties.scopePropertiesFromStyles(this._styles);
2552
+ }
2553
+ return this._properties;
2554
+ },
2555
+ _needsStyleProperties: function() {},
2556
+ _computeStyleProperties: function() {
2557
+ return this._styleProperties;
2558
+ }
2559
+ };
2560
+ return api;
2561
+ }();
2562
+
2563
+ (function() {
2564
+ Polymer.StyleCache = function() {
2565
+ this.cache = {};
2566
+ };
2567
+ Polymer.StyleCache.prototype = {
2568
+ MAX: 100,
2569
+ store: function(is, data, keyValues, keyStyles) {
2570
+ data.keyValues = keyValues;
2571
+ data.styles = keyStyles;
2572
+ var s$ = this.cache[is] = this.cache[is] || [];
2573
+ s$.push(data);
2574
+ if (s$.length > this.MAX) {
2575
+ s$.shift();
2576
+ }
2577
+ },
2578
+ retrieve: function(is, keyValues, keyStyles) {
2579
+ var cache = this.cache[is];
2580
+ if (cache) {
2581
+ for (var i = cache.length - 1, data; i >= 0; i--) {
2582
+ data = cache[i];
2583
+ if (keyStyles === data.styles && this._objectsEqual(keyValues, data.keyValues)) {
2584
+ return data;
2585
+ }
2586
+ }
2587
+ }
2588
+ },
2589
+ clear: function() {
2590
+ this.cache = {};
2591
+ },
2592
+ _objectsEqual: function(target, source) {
2593
+ for (var i in target) {
2594
+ if (target[i] !== source[i]) {
2595
+ return false;
2596
+ }
2597
+ }
2598
+ if (Array.isArray(target)) {
2599
+ return target.length === source.length;
2600
+ }
2601
+ return true;
2602
+ }
2603
+ };
2604
+ })();
2605
+
2606
+ (function() {
2607
+ var serializeValueToAttribute = Polymer.Base.serializeValueToAttribute;
2608
+ var propertyUtils = Polymer.StyleProperties;
2609
+ var styleTransformer = Polymer.StyleTransformer;
2610
+ var styleUtil = Polymer.StyleUtil;
2611
+ var styleDefaults = Polymer.StyleDefaults;
2612
+ var nativeShadow = Polymer.Settings.useNativeShadow;
2613
+ Polymer.Base._addFeature({
2614
+ _prepStyleProperties: function() {
2615
+ this._ownStylePropertyNames = this._styles ? propertyUtils.decorateStyles(this._styles) : [];
2616
+ },
2617
+ _setupStyleProperties: function() {
2618
+ this.customStyle = {};
2619
+ },
2620
+ _needsStyleProperties: function() {
2621
+ return Boolean(this._ownStylePropertyNames && this._ownStylePropertyNames.length);
2622
+ },
2623
+ _beforeAttached: function() {
2624
+ if (!this._scopeSelector && this._needsStyleProperties()) {
2625
+ this._updateStyleProperties();
2626
+ }
2627
+ },
2628
+ _updateStyleProperties: function() {
2629
+ var info, scope = this.domHost || styleDefaults;
2630
+ if (!scope._styleCache) {
2631
+ scope._styleCache = new Polymer.StyleCache();
2632
+ }
2633
+ var scopeData = propertyUtils.propertyDataFromStyles(scope._styles, this);
2634
+ info = scope._styleCache.retrieve(this.is, scopeData.key, this._styles);
2635
+ var scopeCached = Boolean(info);
2636
+ if (scopeCached) {
2637
+ this._styleProperties = info._styleProperties;
2638
+ } else {
2639
+ this._computeStyleProperties(scopeData.properties);
2640
+ }
2641
+ this._computeOwnStyleProperties();
2642
+ if (!scopeCached) {
2643
+ info = styleCache.retrieve(this.is, this._ownStyleProperties, this._styles);
2644
+ }
2645
+ var globalCached = Boolean(info) && !scopeCached;
2646
+ style = this._applyStyleProperties(info);
2647
+ if (!scopeCached) {
2648
+ var cacheableStyle = style;
2649
+ if (nativeShadow) {
2650
+ cacheableStyle = style.cloneNode ? style.cloneNode(true) : Object.create(style || null);
2651
+ }
2652
+ info = {
2653
+ style: cacheableStyle,
2654
+ _scopeSelector: this._scopeSelector,
2655
+ _styleProperties: this._styleProperties
2656
+ };
2657
+ scope._styleCache.store(this.is, info, scopeData.key, this._styles);
2658
+ if (!globalCached) {
2659
+ styleCache.store(this.is, Object.create(info), this._ownStyleProperties, this._styles);
2660
+ }
2661
+ }
2662
+ },
2663
+ _computeStyleProperties: function(scopeProps) {
2664
+ var scope = this.domHost || styleDefaults;
2665
+ if (!scope._styleProperties) {
2666
+ scope._computeStyleProperties();
2667
+ }
2668
+ var props = Object.create(scope._styleProperties);
2669
+ this.mixin(props, propertyUtils.hostPropertiesFromStyles(this._styles));
2670
+ scopeProps = scopeProps || propertyUtils.propertyDataFromStyles(scope._styles, this).properties;
2671
+ this.mixin(props, scopeProps);
2672
+ this.mixin(props, propertyUtils.scopePropertiesFromStyles(this._styles));
2673
+ this.mixin(props, this.customStyle);
2674
+ propertyUtils.reify(props);
2675
+ this._styleProperties = props;
2676
+ },
2677
+ _computeOwnStyleProperties: function() {
2678
+ var props = {};
2679
+ for (var i = 0, n; i < this._ownStylePropertyNames.length; i++) {
2680
+ n = this._ownStylePropertyNames[i];
2681
+ props[n] = this._styleProperties[n];
2682
+ }
2683
+ this._ownStyleProperties = props;
2684
+ },
2685
+ _scopeCount: 0,
2686
+ _applyStyleProperties: function(info) {
2687
+ var oldScopeSelector = this._scopeSelector;
2688
+ this._scopeSelector = info ? info._scopeSelector : this.is + "-" + this.__proto__._scopeCount++;
2689
+ style = propertyUtils.applyElementStyle(this, this._styleProperties, this._scopeSelector, info && info.style);
2690
+ if ((style || oldScopeSelector) && !nativeShadow) {
2691
+ propertyUtils.applyElementScopeSelector(this, this._scopeSelector, oldScopeSelector, this._scopeCssViaAttr);
2692
+ }
2693
+ return style || {};
2694
+ },
2695
+ serializeValueToAttribute: function(value, attribute, node) {
2696
+ node = node || this;
2697
+ if (attribute === "class") {
2698
+ var host = node === this ? this.domHost || this.dataHost : this;
2699
+ if (host) {
2700
+ value = host._scopeElementClass(node, value);
2701
+ }
2702
+ }
2703
+ node = Polymer.dom(node);
2704
+ serializeValueToAttribute.call(this, value, attribute, node);
2705
+ },
2706
+ _scopeElementClass: function(element, selector) {
2707
+ if (!nativeShadow && !this._scopeCssViaAttr) {
2708
+ selector += (selector ? " " : "") + SCOPE_NAME + " " + this.is + (element._scopeSelector ? " " + XSCOPE_NAME + " " + element._scopeSelector : "");
2709
+ }
2710
+ return selector;
2711
+ },
2712
+ updateStyles: function() {
2713
+ if (this.isAttached) {
2714
+ if (this._needsStyleProperties()) {
2715
+ this._updateStyleProperties();
2716
+ } else {
2717
+ this._styleProperties = null;
2718
+ }
2719
+ if (this._styleCache) {
2720
+ this._styleCache.clear();
2721
+ }
2722
+ this._updateRootStyles();
2723
+ }
2724
+ },
2725
+ _updateRootStyles: function(root) {
2726
+ root = root || this.root;
2727
+ var c$ = Polymer.dom(root)._query(function(e) {
2728
+ return e.shadyRoot || e.shadowRoot;
2729
+ });
2730
+ for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) {
2731
+ if (c.updateStyles) {
2732
+ c.updateStyles();
2733
+ }
2734
+ }
2735
+ }
2736
+ });
2737
+ Polymer.updateStyles = function() {
2738
+ styleDefaults._styleCache.clear();
2739
+ Polymer.Base._updateRootStyles(document);
2740
+ };
2741
+ var styleCache = new Polymer.StyleCache();
2742
+ Polymer.customStyleCache = styleCache;
2743
+ var SCOPE_NAME = styleTransformer.SCOPE_NAME;
2744
+ var XSCOPE_NAME = propertyUtils.XSCOPE_NAME;
2745
+ })();
2746
+
2747
+ Polymer.Base._addFeature({
2748
+ _registerFeatures: function() {
2749
+ this._prepIs();
2750
+ this._prepAttributes();
2751
+ this._prepExtends();
2752
+ this._prepConstructor();
2753
+ this._prepTemplate();
2754
+ this._prepStyles();
2755
+ this._prepStyleProperties();
2756
+ this._prepAnnotations();
2757
+ this._prepEffects();
2758
+ this._prepBehaviors();
2759
+ this._prepBindings();
2760
+ this._prepShady();
2761
+ },
2762
+ _prepBehavior: function(b) {
2763
+ this._addPropertyEffects(b.properties);
2764
+ this._addComplexObserverEffects(b.observers);
2765
+ this._addHostAttributes(b.hostAttributes);
2766
+ },
2767
+ _initFeatures: function() {
2768
+ this._poolContent();
2769
+ this._setupConfigure();
2770
+ this._setupStyleProperties();
2771
+ this._pushHost();
2772
+ this._stampTemplate();
2773
+ this._popHost();
2774
+ this._marshalAnnotationReferences();
2775
+ this._marshalHostAttributes();
2776
+ this._setupDebouncers();
2777
+ this._marshalInstanceEffects();
2778
+ this._marshalBehaviors();
2779
+ this._marshalAttributes();
2780
+ this._tryReady();
2781
+ },
2782
+ _marshalBehavior: function(b) {
2783
+ this._listenListeners(b.listeners);
2784
+ }
2785
+ });
2786
+
2787
+ (function() {
2788
+ var nativeShadow = Polymer.Settings.useNativeShadow;
2789
+ var propertyUtils = Polymer.StyleProperties;
2790
+ var styleUtil = Polymer.StyleUtil;
2791
+ var styleDefaults = Polymer.StyleDefaults;
2792
+ Polymer({
2793
+ is: "custom-style",
2794
+ "extends": "style",
2795
+ created: function() {
2796
+ this._appliesToDocument = this.parentNode.localName !== "dom-module";
2797
+ if (this._appliesToDocument) {
2798
+ var e = this.__appliedElement || this;
2799
+ var rules = styleUtil.rulesForStyle(e);
2800
+ propertyUtils.decorateStyles([ e ]);
2801
+ this._rulesToDefaultProperties(rules);
2802
+ this.async(this._applyStyle);
2803
+ }
2804
+ },
2805
+ _applyStyle: function() {
2806
+ var e = this.__appliedElement || this;
2807
+ this._computeStyleProperties();
2808
+ var props = this._styleProperties;
2809
+ var self = this;
2810
+ e.textContent = styleUtil.toCssText(styleUtil.rulesForStyle(e), function(rule) {
2811
+ if (rule.selector === ":root") {
2812
+ rule.selector = "body";
2813
+ }
2814
+ var css = rule.cssText = rule.parsedCssText;
2815
+ if (rule.propertyInfo.cssText) {
2816
+ css = css.replace(propertyUtils.rx.VAR_ASSIGN, "");
2817
+ rule.cssText = propertyUtils.valueForProperties(css, props);
2818
+ }
2819
+ if (!nativeShadow) {
2820
+ Polymer.StyleTransformer.rootRule(rule);
2821
+ }
2822
+ });
2823
+ },
2824
+ _rulesToDefaultProperties: function(rules) {
2825
+ styleUtil.forEachStyleRule(rules, function(rule) {
2826
+ if (!rule.propertyInfo.properties) {
2827
+ rule.cssText = "";
2828
+ }
2829
+ });
2830
+ var cssText = styleUtil.parser.stringify(rules, true);
2831
+ if (cssText) {
2832
+ styleDefaults.applyCss(cssText);
2833
+ }
2834
+ }
2835
+ });
2836
+ })();
2837
+
2838
+ Polymer.Templatizer = {
2839
+ properties: {
2840
+ _hideTemplateChildren: {
2841
+ observer: "_hideTemplateChildrenChanged"
2842
+ }
2843
+ },
2844
+ _templatizerStatic: {
2845
+ count: 0,
2846
+ callbacks: {},
2847
+ debouncer: null
2848
+ },
2849
+ _instanceProps: Polymer.nob,
2850
+ created: function() {
2851
+ this._templatizerId = this._templatizerStatic.count++;
2852
+ },
2853
+ templatize: function(template) {
2854
+ if (!template._content) {
2855
+ template._content = template.content;
2856
+ }
2857
+ if (template._content._ctor) {
2858
+ this.ctor = template._content._ctor;
2859
+ this._prepParentProperties(this.ctor.prototype, template);
2860
+ return;
2861
+ }
2862
+ var archetype = Object.create(Polymer.Base);
2863
+ this._customPrepAnnotations(archetype, template);
2864
+ archetype._prepEffects();
2865
+ this._customPrepEffects(archetype);
2866
+ archetype._prepBehaviors();
2867
+ archetype._prepBindings();
2868
+ this._prepParentProperties(archetype, template);
2869
+ archetype._notifyPath = this._notifyPathImpl;
2870
+ archetype._scopeElementClass = this._scopeElementClassImpl;
2871
+ archetype.listen = this._listenImpl;
2872
+ var _constructor = this._constructorImpl;
2873
+ var ctor = function TemplateInstance(model, host) {
2874
+ _constructor.call(this, model, host);
2875
+ };
2876
+ ctor.prototype = archetype;
2877
+ archetype.constructor = ctor;
2878
+ template._content._ctor = ctor;
2879
+ this.ctor = ctor;
2880
+ },
2881
+ _getRootDataHost: function() {
2882
+ return this.dataHost && this.dataHost._rootDataHost || this.dataHost;
2883
+ },
2884
+ _hideTemplateChildrenChanged: function(hidden) {
2885
+ if (this._hideChildren) {
2886
+ this._hideChildren(hidden);
2887
+ }
2888
+ },
2889
+ _debounceTemplate: function(fn) {
2890
+ this._templatizerStatic.callbacks[this._templatizerId] = fn.bind(this);
2891
+ this._templatizerStatic.debouncer = Polymer.Debounce(this._templatizerStatic.debouncer, this._flushTemplates.bind(this, true));
2892
+ },
2893
+ _flushTemplates: function(debouncerExpired) {
2894
+ var db = this._templatizerStatic.debouncer;
2895
+ while (debouncerExpired || db && db.finish) {
2896
+ db.stop();
2897
+ var cbs = this._templatizerStatic.callbacks;
2898
+ this._templatizerStatic.callbacks = {};
2899
+ for (var id in cbs) {
2900
+ cbs[id]();
2901
+ }
2902
+ debouncerExpired = false;
2903
+ }
2904
+ },
2905
+ _customPrepEffects: function(archetype) {
2906
+ var parentProps = archetype._parentProps;
2907
+ for (var prop in parentProps) {
2908
+ archetype._addPropertyEffect(prop, "function", this._createHostPropEffector(prop));
2909
+ }
2910
+ },
2911
+ _customPrepAnnotations: function(archetype, template) {
2912
+ archetype._template = template;
2913
+ var c = template._content;
2914
+ if (!c._notes) {
2915
+ var rootDataHost = archetype._rootDataHost;
2916
+ if (rootDataHost) {
2917
+ Polymer.Annotations.prepElement = rootDataHost._prepElement.bind(rootDataHost);
2918
+ }
2919
+ c._notes = Polymer.Annotations.parseAnnotations(template);
2920
+ Polymer.Annotations.prepElement = null;
2921
+ this._processAnnotations(c._notes);
2922
+ }
2923
+ archetype._notes = c._notes;
2924
+ archetype._parentProps = c._parentProps;
2925
+ },
2926
+ _prepParentProperties: function(archetype, template) {
2927
+ var parentProps = this._parentProps = archetype._parentProps;
2928
+ if (this._forwardParentProp && parentProps) {
2929
+ var proto = archetype._parentPropProto;
2930
+ var prop;
2931
+ if (!proto) {
2932
+ for (prop in this._instanceProps) {
2933
+ delete parentProps[prop];
2934
+ }
2935
+ proto = archetype._parentPropProto = Object.create(null);
2936
+ if (template != this) {
2937
+ Polymer.Bind.prepareModel(proto);
2938
+ }
2939
+ for (prop in parentProps) {
2940
+ var parentProp = "_parent_" + prop;
2941
+ var effects = [ {
2942
+ kind: "function",
2943
+ effect: this._createForwardPropEffector(prop)
2944
+ }, {
2945
+ kind: "notify"
2946
+ } ];
2947
+ Polymer.Bind._createAccessors(proto, parentProp, effects);
2948
+ }
2949
+ }
2950
+ if (template != this) {
2951
+ Polymer.Bind.prepareInstance(template);
2952
+ template._forwardParentProp = this._forwardParentProp.bind(this);
2953
+ }
2954
+ this._extendTemplate(template, proto);
2955
+ }
2956
+ },
2957
+ _createForwardPropEffector: function(prop) {
2958
+ return function(source, value) {
2959
+ this._forwardParentProp(prop, value);
2960
+ };
2961
+ },
2962
+ _createHostPropEffector: function(prop) {
2963
+ return function(source, value) {
2964
+ this.dataHost["_parent_" + prop] = value;
2965
+ };
2966
+ },
2967
+ _extendTemplate: function(template, proto) {
2968
+ Object.getOwnPropertyNames(proto).forEach(function(n) {
2969
+ var val = template[n];
2970
+ var pd = Object.getOwnPropertyDescriptor(proto, n);
2971
+ Object.defineProperty(template, n, pd);
2972
+ if (val !== undefined) {
2973
+ template._propertySet(n, val);
2974
+ }
2975
+ });
2976
+ },
2977
+ _forwardInstancePath: function(inst, path, value) {},
2978
+ _notifyPathImpl: function(path, value) {
2979
+ var dataHost = this.dataHost;
2980
+ var dot = path.indexOf(".");
2981
+ var root = dot < 0 ? path : path.slice(0, dot);
2982
+ dataHost._forwardInstancePath.call(dataHost, this, path, value);
2983
+ if (root in dataHost._parentProps) {
2984
+ dataHost.notifyPath("_parent_" + path, value);
2985
+ }
2986
+ },
2987
+ _pathEffector: function(path, value, fromAbove) {
2988
+ if (this._forwardParentPath) {
2989
+ if (path.indexOf("_parent_") === 0) {
2990
+ this._forwardParentPath(path.substring(8), value);
2991
+ }
2992
+ }
2993
+ Polymer.Base._pathEffector.apply(this, arguments);
2994
+ },
2995
+ _constructorImpl: function(model, host) {
2996
+ this._rootDataHost = host._getRootDataHost();
2997
+ this._setupConfigure(model);
2998
+ this._pushHost(host);
2999
+ this.root = this.instanceTemplate(this._template);
3000
+ this.root.__styleScoped = true;
3001
+ this._popHost();
3002
+ this._marshalAnnotatedNodes();
3003
+ this._marshalInstanceEffects();
3004
+ this._marshalAnnotatedListeners();
3005
+ var children = [];
3006
+ for (var n = this.root.firstChild; n; n = n.nextSibling) {
3007
+ children.push(n);
3008
+ n._templateInstance = this;
3009
+ }
3010
+ this._children = children;
3011
+ this._tryReady();
3012
+ },
3013
+ _listenImpl: function(node, eventName, methodName) {
3014
+ var model = this;
3015
+ var host = this._rootDataHost;
3016
+ var handler = host._createEventHandler(node, eventName, methodName);
3017
+ var decorated = function(e) {
3018
+ e.model = model;
3019
+ handler(e);
3020
+ };
3021
+ host._listen(node, eventName, decorated);
3022
+ },
3023
+ _scopeElementClassImpl: function(node, value) {
3024
+ var host = this._rootDataHost;
3025
+ if (host) {
3026
+ return host._scopeElementClass(node, value);
3027
+ }
3028
+ },
3029
+ stamp: function(model) {
3030
+ model = model || {};
3031
+ if (this._parentProps) {
3032
+ for (var prop in this._parentProps) {
3033
+ model[prop] = this["_parent_" + prop];
3034
+ }
3035
+ }
3036
+ return new this.ctor(model, this);
3037
+ }
3038
+ };
3039
+
3040
+ Polymer({
3041
+ is: "dom-template",
3042
+ "extends": "template",
3043
+ behaviors: [ Polymer.Templatizer ],
3044
+ ready: function() {
3045
+ this.templatize(this);
3046
+ }
3047
+ });
3048
+
3049
+ Polymer._collections = new WeakMap();
3050
+
3051
+ Polymer.Collection = function(userArray) {
3052
+ Polymer._collections.set(userArray, this);
3053
+ this.userArray = userArray;
3054
+ this.store = userArray.slice();
3055
+ this.initMap();
3056
+ };
3057
+
3058
+ Polymer.Collection.prototype = {
3059
+ constructor: Polymer.Collection,
3060
+ initMap: function() {
3061
+ var omap = this.omap = new WeakMap();
3062
+ var pmap = this.pmap = {};
3063
+ var s = this.store;
3064
+ for (var i = 0; i < s.length; i++) {
3065
+ var item = s[i];
3066
+ if (item && typeof item == "object") {
3067
+ omap.set(item, i);
3068
+ } else {
3069
+ pmap[item] = i;
3070
+ }
3071
+ }
3072
+ },
3073
+ add: function(item) {
3074
+ var key = this.store.push(item) - 1;
3075
+ if (item && typeof item == "object") {
3076
+ this.omap.set(item, key);
3077
+ } else {
3078
+ this.pmap[item] = key;
3079
+ }
3080
+ return key;
3081
+ },
3082
+ removeKey: function(key) {
3083
+ this._removeFromMap(this.store[key]);
3084
+ delete this.store[key];
3085
+ },
3086
+ _removeFromMap: function(item) {
3087
+ if (typeof item == "object") {
3088
+ this.omap.delete(item);
3089
+ } else {
3090
+ delete this.pmap[item];
3091
+ }
3092
+ },
3093
+ remove: function(item) {
3094
+ var key = this.getKey(item);
3095
+ this.removeKey(key);
3096
+ return key;
3097
+ },
3098
+ getKey: function(item) {
3099
+ if (typeof item == "object") {
3100
+ return this.omap.get(item);
3101
+ } else {
3102
+ return this.pmap[item];
3103
+ }
3104
+ },
3105
+ getKeys: function() {
3106
+ return Object.keys(this.store);
3107
+ },
3108
+ setItem: function(key, value) {
3109
+ this.store[key] = value;
3110
+ },
3111
+ getItem: function(key) {
3112
+ return this.store[key];
3113
+ },
3114
+ getItems: function() {
3115
+ var items = [], store = this.store;
3116
+ for (var key in store) {
3117
+ items.push(store[key]);
3118
+ }
3119
+ return items;
3120
+ },
3121
+ applySplices: function(splices) {
3122
+ var keySplices = [];
3123
+ for (var i = 0; i < splices.length; i++) {
3124
+ var j, o, key, s = splices[i];
3125
+ var removed = [];
3126
+ for (j = 0; j < s.removed.length; j++) {
3127
+ o = s.removed[j];
3128
+ key = this.remove(o);
3129
+ removed.push(key);
3130
+ }
3131
+ var added = [];
3132
+ for (j = 0; j < s.addedCount; j++) {
3133
+ o = this.userArray[s.index + j];
3134
+ key = this.add(o);
3135
+ added.push(key);
3136
+ }
3137
+ keySplices.push({
3138
+ index: s.index,
3139
+ removed: removed,
3140
+ removedItems: s.removed,
3141
+ added: added
3142
+ });
3143
+ }
3144
+ return keySplices;
3145
+ }
3146
+ };
3147
+
3148
+ Polymer.Collection.get = function(userArray) {
3149
+ return Polymer._collections.get(userArray) || new Polymer.Collection(userArray);
3150
+ };
3151
+
3152
+ Polymer({
3153
+ is: "dom-repeat",
3154
+ "extends": "template",
3155
+ properties: {
3156
+ items: {
3157
+ type: Array
3158
+ },
3159
+ as: {
3160
+ type: String,
3161
+ value: "item"
3162
+ },
3163
+ indexAs: {
3164
+ type: String,
3165
+ value: "index"
3166
+ },
3167
+ sort: {
3168
+ type: Function,
3169
+ observer: "_sortChanged"
3170
+ },
3171
+ filter: {
3172
+ type: Function,
3173
+ observer: "_filterChanged"
3174
+ },
3175
+ observe: {
3176
+ type: String,
3177
+ observer: "_observeChanged"
3178
+ },
3179
+ delay: Number
3180
+ },
3181
+ behaviors: [ Polymer.Templatizer ],
3182
+ observers: [ "_itemsChanged(items.*)" ],
3183
+ detached: function() {
3184
+ if (this.rows) {
3185
+ for (var i = 0; i < this.rows.length; i++) {
3186
+ this._detachRow(i);
3187
+ }
3188
+ }
3189
+ this.rows = null;
3190
+ },
3191
+ ready: function() {
3192
+ this._instanceProps = {
3193
+ __key__: true
3194
+ };
3195
+ this._instanceProps[this.as] = true;
3196
+ this._instanceProps[this.indexAs] = true;
3197
+ if (!this.ctor) {
3198
+ this.templatize(this);
3199
+ }
3200
+ },
3201
+ _sortChanged: function() {
3202
+ var dataHost = this._getRootDataHost();
3203
+ var sort = this.sort;
3204
+ this._sortFn = sort && (typeof sort == "function" ? sort : function() {
3205
+ return dataHost[sort].apply(dataHost, arguments);
3206
+ });
3207
+ this._fullRefresh = true;
3208
+ if (this.items) {
3209
+ this._debounceTemplate(this._render);
3210
+ }
3211
+ },
3212
+ _filterChanged: function() {
3213
+ var dataHost = this._getRootDataHost();
3214
+ var filter = this.filter;
3215
+ this._filterFn = filter && (typeof filter == "function" ? filter : function() {
3216
+ return dataHost[filter].apply(dataHost, arguments);
3217
+ });
3218
+ this._fullRefresh = true;
3219
+ if (this.items) {
3220
+ this._debounceTemplate(this._render);
3221
+ }
3222
+ },
3223
+ _observeChanged: function() {
3224
+ this._observePaths = this.observe && this.observe.replace(".*", ".").split(" ");
3225
+ },
3226
+ _itemsChanged: function(change) {
3227
+ if (change.path == "items") {
3228
+ if (Array.isArray(this.items)) {
3229
+ this.collection = Polymer.Collection.get(this.items);
3230
+ } else if (!this.items) {
3231
+ this.collection = null;
3232
+ } else {
3233
+ this._error(this._logf("dom-repeat", "expected array for `items`," + " found", this.items));
3234
+ }
3235
+ this._splices = [];
3236
+ this._fullRefresh = true;
3237
+ this._debounceTemplate(this._render);
3238
+ } else if (change.path == "items.splices") {
3239
+ this._splices = this._splices.concat(change.value.keySplices);
3240
+ this._debounceTemplate(this._render);
3241
+ } else {
3242
+ var subpath = change.path.slice(6);
3243
+ this._forwardItemPath(subpath, change.value);
3244
+ this._checkObservedPaths(subpath);
3245
+ }
3246
+ },
3247
+ _checkObservedPaths: function(path) {
3248
+ if (this._observePaths) {
3249
+ path = path.substring(path.indexOf(".") + 1);
3250
+ var paths = this._observePaths;
3251
+ for (var i = 0; i < paths.length; i++) {
3252
+ if (path.indexOf(paths[i]) === 0) {
3253
+ this._fullRefresh = true;
3254
+ if (this.delay) {
3255
+ this.debounce("render", this._render, this.delay);
3256
+ } else {
3257
+ this._debounceTemplate(this._render);
3258
+ }
3259
+ return;
3260
+ }
3261
+ }
3262
+ }
3263
+ },
3264
+ render: function() {
3265
+ this._fullRefresh = true;
3266
+ this.debounce("render", this._render);
3267
+ this._flushTemplates();
3268
+ },
3269
+ _render: function() {
3270
+ var c = this.collection;
3271
+ if (!this._fullRefresh) {
3272
+ if (this._sortFn) {
3273
+ this._applySplicesViewSort(this._splices);
3274
+ } else {
3275
+ if (this._filterFn) {
3276
+ this._fullRefresh = true;
3277
+ } else {
3278
+ this._applySplicesArraySort(this._splices);
3279
+ }
3280
+ }
3281
+ }
3282
+ if (this._fullRefresh) {
3283
+ this._sortAndFilter();
3284
+ this._fullRefresh = false;
3285
+ }
3286
+ this._splices = [];
3287
+ var rowForKey = this._rowForKey = {};
3288
+ var keys = this._orderedKeys;
3289
+ this.rows = this.rows || [];
3290
+ for (var i = 0; i < keys.length; i++) {
3291
+ var key = keys[i];
3292
+ var item = c.getItem(key);
3293
+ var row = this.rows[i];
3294
+ rowForKey[key] = i;
3295
+ if (!row) {
3296
+ this.rows.push(row = this._insertRow(i, null, item));
3297
+ }
3298
+ row[this.as] = item;
3299
+ row.__key__ = key;
3300
+ row[this.indexAs] = i;
3301
+ }
3302
+ for (;i < this.rows.length; i++) {
3303
+ this._detachRow(i);
3304
+ }
3305
+ this.rows.splice(keys.length, this.rows.length - keys.length);
3306
+ this.fire("dom-change");
3307
+ },
3308
+ _sortAndFilter: function() {
3309
+ var c = this.collection;
3310
+ if (!this._sortFn) {
3311
+ this._orderedKeys = [];
3312
+ var items = this.items;
3313
+ if (items) {
3314
+ for (var i = 0; i < items.length; i++) {
3315
+ this._orderedKeys.push(c.getKey(items[i]));
3316
+ }
3317
+ }
3318
+ } else {
3319
+ this._orderedKeys = c ? c.getKeys() : [];
3320
+ }
3321
+ if (this._filterFn) {
3322
+ this._orderedKeys = this._orderedKeys.filter(function(a) {
3323
+ return this._filterFn(c.getItem(a));
3324
+ }, this);
3325
+ }
3326
+ if (this._sortFn) {
3327
+ this._orderedKeys.sort(function(a, b) {
3328
+ return this._sortFn(c.getItem(a), c.getItem(b));
3329
+ }.bind(this));
3330
+ }
3331
+ },
3332
+ _keySort: function(a, b) {
3333
+ return this.collection.getKey(a) - this.collection.getKey(b);
3334
+ },
3335
+ _applySplicesViewSort: function(splices) {
3336
+ var c = this.collection;
3337
+ var keys = this._orderedKeys;
3338
+ var rows = this.rows;
3339
+ var removedRows = [];
3340
+ var addedKeys = [];
3341
+ var pool = [];
3342
+ var sortFn = this._sortFn || this._keySort.bind(this);
3343
+ splices.forEach(function(s) {
3344
+ for (var i = 0; i < s.removed.length; i++) {
3345
+ var idx = this._rowForKey[s.removed[i]];
3346
+ if (idx != null) {
3347
+ removedRows.push(idx);
3348
+ }
3349
+ }
3350
+ for (var i = 0; i < s.added.length; i++) {
3351
+ addedKeys.push(s.added[i]);
3352
+ }
3353
+ }, this);
3354
+ if (removedRows.length) {
3355
+ removedRows.sort();
3356
+ for (var i = removedRows.length - 1; i >= 0; i--) {
3357
+ var idx = removedRows[i];
3358
+ pool.push(this._detachRow(idx));
3359
+ rows.splice(idx, 1);
3360
+ keys.splice(idx, 1);
3361
+ }
3362
+ }
3363
+ if (addedKeys.length) {
3364
+ if (this._filterFn) {
3365
+ addedKeys = addedKeys.filter(function(a) {
3366
+ return this._filterFn(c.getItem(a));
3367
+ }, this);
3368
+ }
3369
+ addedKeys.sort(function(a, b) {
3370
+ return this._sortFn(c.getItem(a), c.getItem(b));
3371
+ }.bind(this));
3372
+ var start = 0;
3373
+ for (var i = 0; i < addedKeys.length; i++) {
3374
+ start = this._insertRowIntoViewSort(start, addedKeys[i], pool);
3375
+ }
3376
+ }
3377
+ },
3378
+ _insertRowIntoViewSort: function(start, key, pool) {
3379
+ var c = this.collection;
3380
+ var item = c.getItem(key);
3381
+ var end = this.rows.length - 1;
3382
+ var idx = -1;
3383
+ var sortFn = this._sortFn || this._keySort.bind(this);
3384
+ while (start <= end) {
3385
+ var mid = start + end >> 1;
3386
+ var midKey = this._orderedKeys[mid];
3387
+ var cmp = sortFn(c.getItem(midKey), item);
3388
+ if (cmp < 0) {
3389
+ start = mid + 1;
3390
+ } else if (cmp > 0) {
3391
+ end = mid - 1;
3392
+ } else {
3393
+ idx = mid;
3394
+ break;
3395
+ }
3396
+ }
3397
+ if (idx < 0) {
3398
+ idx = end + 1;
3399
+ }
3400
+ this._orderedKeys.splice(idx, 0, key);
3401
+ this.rows.splice(idx, 0, this._insertRow(idx, pool, c.getItem(key)));
3402
+ return idx;
3403
+ },
3404
+ _applySplicesArraySort: function(splices) {
3405
+ var keys = this._orderedKeys;
3406
+ var pool = [];
3407
+ splices.forEach(function(s) {
3408
+ for (var i = 0; i < s.removed.length; i++) {
3409
+ pool.push(this._detachRow(s.index + i));
3410
+ }
3411
+ this.rows.splice(s.index, s.removed.length);
3412
+ }, this);
3413
+ var c = this.collection;
3414
+ splices.forEach(function(s) {
3415
+ var args = [ s.index, s.removed.length ].concat(s.added);
3416
+ keys.splice.apply(keys, args);
3417
+ for (var i = 0; i < s.added.length; i++) {
3418
+ var item = c.getItem(s.added[i]);
3419
+ var row = this._insertRow(s.index + i, pool, item);
3420
+ this.rows.splice(s.index + i, 0, row);
3421
+ }
3422
+ }, this);
3423
+ },
3424
+ _detachRow: function(idx) {
3425
+ var row = this.rows[idx];
3426
+ var parentNode = Polymer.dom(this).parentNode;
3427
+ for (var i = 0; i < row._children.length; i++) {
3428
+ var el = row._children[i];
3429
+ Polymer.dom(row.root).appendChild(el);
3430
+ }
3431
+ return row;
3432
+ },
3433
+ _insertRow: function(idx, pool, item) {
3434
+ var row = pool && pool.pop() || this._generateRow(idx, item);
3435
+ var beforeRow = this.rows[idx];
3436
+ var beforeNode = beforeRow ? beforeRow._children[0] : this;
3437
+ var parentNode = Polymer.dom(this).parentNode;
3438
+ Polymer.dom(parentNode).insertBefore(row.root, beforeNode);
3439
+ return row;
3440
+ },
3441
+ _generateRow: function(idx, item) {
3442
+ var model = {
3443
+ __key__: this.collection.getKey(item)
3444
+ };
3445
+ model[this.as] = item;
3446
+ model[this.indexAs] = idx;
3447
+ var row = this.stamp(model);
3448
+ return row;
3449
+ },
3450
+ _hideChildren: function(hidden) {
3451
+ if (this.rows) {
3452
+ for (var i = 0; i < this.rows.length; i++) {
3453
+ var c$ = this.rows[i]._children;
3454
+ for (var j = 0; j < c$.length; j++) {
3455
+ var c = c$[j];
3456
+ if (c.style) {
3457
+ c.style.display = hidden ? "none" : "";
3458
+ }
3459
+ c._hideTemplateChildren = hidden;
3460
+ }
3461
+ }
3462
+ }
3463
+ },
3464
+ _forwardInstancePath: function(row, path, value) {
3465
+ if (path.indexOf(this.as + ".") === 0) {
3466
+ this.notifyPath("items." + row.__key__ + "." + path.slice(this.as.length + 1), value);
3467
+ return true;
3468
+ }
3469
+ },
3470
+ _forwardParentProp: function(prop, value) {
3471
+ if (this.rows) {
3472
+ this.rows.forEach(function(row) {
3473
+ row[prop] = value;
3474
+ }, this);
3475
+ }
3476
+ },
3477
+ _forwardParentPath: function(path, value) {
3478
+ if (this.rows) {
3479
+ this.rows.forEach(function(row) {
3480
+ row.notifyPath(path, value, true);
3481
+ }, this);
3482
+ }
3483
+ },
3484
+ _forwardItemPath: function(path, value) {
3485
+ if (this._rowForKey) {
3486
+ var dot = path.indexOf(".");
3487
+ var key = path.substring(0, dot < 0 ? path.length : dot);
3488
+ var idx = this._rowForKey[key];
3489
+ var row = this.rows[idx];
3490
+ if (row) {
3491
+ if (dot >= 0) {
3492
+ path = this.as + "." + path.substring(dot + 1);
3493
+ row.notifyPath(path, value, true);
3494
+ } else {
3495
+ row[this.as] = value;
3496
+ }
3497
+ }
3498
+ }
3499
+ },
3500
+ modelForElement: function(el) {
3501
+ var model;
3502
+ while (el) {
3503
+ if (model = el._templateInstance) {
3504
+ if (model.dataHost != this) {
3505
+ el = model.dataHost;
3506
+ } else {
3507
+ return model;
3508
+ }
3509
+ } else {
3510
+ el = el.parentNode;
3511
+ }
3512
+ }
3513
+ },
3514
+ itemForElement: function(el) {
3515
+ var instance = this.modelForElement(el);
3516
+ return instance && instance[this.as];
3517
+ },
3518
+ keyForElement: function(el) {
3519
+ var instance = this.modelForElement(el);
3520
+ return instance && instance.__key__;
3521
+ },
3522
+ indexForElement: function(el) {
3523
+ var instance = this.modelForElement(el);
3524
+ return instance && instance[this.indexAs];
3525
+ }
3526
+ });
3527
+
3528
+ Polymer({
3529
+ is: "array-selector",
3530
+ properties: {
3531
+ items: {
3532
+ type: Array,
3533
+ observer: "_itemsChanged"
3534
+ },
3535
+ selected: {
3536
+ type: Object,
3537
+ notify: true
3538
+ },
3539
+ toggle: Boolean,
3540
+ multi: Boolean
3541
+ },
3542
+ _itemsChanged: function() {
3543
+ if (Array.isArray(this.selected)) {
3544
+ for (var i = 0; i < this.selected.length; i++) {
3545
+ this.unlinkPaths("selected." + i);
3546
+ }
3547
+ } else {
3548
+ this.unlinkPaths("selected");
3549
+ }
3550
+ if (this.multi) {
3551
+ this.selected = [];
3552
+ } else {
3553
+ this.selected = null;
3554
+ }
3555
+ },
3556
+ deselect: function(item) {
3557
+ if (this.multi) {
3558
+ var scol = Polymer.Collection.get(this.selected);
3559
+ var sidx = this.selected.indexOf(item);
3560
+ if (sidx >= 0) {
3561
+ var skey = scol.getKey(item);
3562
+ this.splice("selected", sidx, 1);
3563
+ this.unlinkPaths("selected." + skey);
3564
+ return true;
3565
+ }
3566
+ } else {
3567
+ this.selected = null;
3568
+ this.unlinkPaths("selected");
3569
+ }
3570
+ },
3571
+ select: function(item) {
3572
+ var icol = Polymer.Collection.get(this.items);
3573
+ var key = icol.getKey(item);
3574
+ if (this.multi) {
3575
+ var scol = Polymer.Collection.get(this.selected);
3576
+ var skey = scol.getKey(item);
3577
+ if (skey >= 0) {
3578
+ this.deselect(item);
3579
+ } else if (this.toggle) {
3580
+ this.push("selected", item);
3581
+ this.async(function() {
3582
+ skey = scol.getKey(item);
3583
+ this.linkPaths("selected." + skey, "items." + key);
3584
+ });
3585
+ }
3586
+ } else {
3587
+ if (this.toggle && item == this.selected) {
3588
+ this.deselect();
3589
+ } else {
3590
+ this.linkPaths("selected", "items." + key);
3591
+ this.selected = item;
3592
+ }
3593
+ }
3594
+ }
3595
+ });
3596
+
3597
+ Polymer({
3598
+ is: "dom-if",
3599
+ "extends": "template",
3600
+ properties: {
3601
+ "if": {
3602
+ type: Boolean,
3603
+ value: false
3604
+ },
3605
+ restamp: {
3606
+ type: Boolean,
3607
+ value: false
3608
+ }
3609
+ },
3610
+ behaviors: [ Polymer.Templatizer ],
3611
+ observers: [ "_queueRender(if, restamp)" ],
3612
+ _queueRender: function() {
3613
+ this._debounceTemplate(this._render);
3614
+ },
3615
+ detached: function() {
3616
+ this._teardownInstance();
3617
+ },
3618
+ attached: function() {
3619
+ if (this.if && this.ctor) {
3620
+ this.async(this._ensureInstance);
3621
+ }
3622
+ },
3623
+ render: function() {
3624
+ this._flushTemplates();
3625
+ },
3626
+ _render: function() {
3627
+ if (this.if) {
3628
+ if (!this.ctor) {
3629
+ this._wrapTextNodes(this._content || this.content);
3630
+ this.templatize(this);
3631
+ }
3632
+ this._ensureInstance();
3633
+ this._hideTemplateChildren = false;
3634
+ } else if (this.restamp) {
3635
+ this._teardownInstance();
3636
+ }
3637
+ if (!this.restamp && this._instance) {
3638
+ this._hideTemplateChildren = !this.if;
3639
+ }
3640
+ if (this.if != this._lastIf) {
3641
+ this.fire("dom-change");
3642
+ this._lastIf = this.if;
3643
+ }
3644
+ },
3645
+ _ensureInstance: function() {
3646
+ if (!this._instance) {
3647
+ this._instance = this.stamp();
3648
+ var root = this._instance.root;
3649
+ var parent = Polymer.dom(Polymer.dom(this).parentNode);
3650
+ parent.insertBefore(root, this);
3651
+ }
3652
+ },
3653
+ _teardownInstance: function() {
3654
+ if (this._instance) {
3655
+ var c = this._instance._children;
3656
+ if (c) {
3657
+ var parent = Polymer.dom(Polymer.dom(c[0]).parentNode);
3658
+ c.forEach(function(n) {
3659
+ parent.removeChild(n);
3660
+ });
3661
+ }
3662
+ this._instance = null;
3663
+ }
3664
+ },
3665
+ _wrapTextNodes: function(root) {
3666
+ for (var n = root.firstChild; n; n = n.nextSibling) {
3667
+ if (n.nodeType === Node.TEXT_NODE) {
3668
+ var s = document.createElement("span");
3669
+ root.insertBefore(s, n);
3670
+ s.appendChild(n);
3671
+ n = s;
3672
+ }
3673
+ }
3674
+ },
3675
+ _hideChildren: function(hidden) {
3676
+ if (this._instance) {
3677
+ var c$ = this._instance._children;
3678
+ for (var i = 0; i < c$.length; i++) {
3679
+ var c = c$[i];
3680
+ c.style.display = hidden ? "none" : "";
3681
+ c._hideTemplateChildren = hidden;
3682
+ }
3683
+ }
3684
+ },
3685
+ _forwardParentProp: function(prop, value) {
3686
+ if (this._instance) {
3687
+ this._instance[prop] = value;
3688
+ }
3689
+ },
3690
+ _forwardParentPath: function(path, value) {
3691
+ if (this._instance) {
3692
+ this._instance.notifyPath(path, value, true);
3693
+ }
3694
+ }
3695
+ });
3696
+
3697
+ Polymer.ImportStatus = {
3698
+ _ready: false,
3699
+ _callbacks: [],
3700
+ whenLoaded: function(cb) {
3701
+ if (this._ready) {
3702
+ cb();
3703
+ } else {
3704
+ this._callbacks.push(cb);
3705
+ }
3706
+ },
3707
+ _importsLoaded: function() {
3708
+ this._ready = true;
3709
+ this._callbacks.forEach(function(cb) {
3710
+ cb();
3711
+ });
3712
+ this._callbacks = [];
3713
+ }
3714
+ };
3715
+
3716
+ window.addEventListener("load", function() {
3717
+ Polymer.ImportStatus._importsLoaded();
3718
+ });
3719
+
3720
+ if (window.HTMLImports) {
3721
+ HTMLImports.whenReady(function() {
3722
+ Polymer.ImportStatus._importsLoaded();
3723
+ });
3724
+ }
3725
+
3726
+ Polymer({
3727
+ is: "dom-bind",
3728
+ "extends": "template",
3729
+ created: function() {
3730
+ Polymer.ImportStatus.whenLoaded(this._readySelf.bind(this));
3731
+ },
3732
+ _registerFeatures: function() {
3733
+ this._prepExtends();
3734
+ this._prepConstructor();
3735
+ },
3736
+ _insertChildren: function() {
3737
+ var parentDom = Polymer.dom(Polymer.dom(this).parentNode);
3738
+ parentDom.insertBefore(this.root, this);
3739
+ },
3740
+ _removeChildren: function() {
3741
+ if (this._children) {
3742
+ for (var i = 0; i < this._children.length; i++) {
3743
+ this.root.appendChild(this._children[i]);
3744
+ }
3745
+ }
3746
+ },
3747
+ _initFeatures: function() {},
3748
+ _scopeElementClass: function(element, selector) {
3749
+ if (this.dataHost) {
3750
+ return this.dataHost._scopeElementClass(element, selector);
3751
+ } else {
3752
+ return selector;
3753
+ }
3754
+ },
3755
+ _prepConfigure: function() {
3756
+ var config = {};
3757
+ for (var prop in this._propertyEffects) {
3758
+ config[prop] = this[prop];
3759
+ }
3760
+ this._setupConfigure = this._setupConfigure.bind(this, config);
3761
+ },
3762
+ attached: function() {
3763
+ if (!this._children) {
3764
+ this._template = this;
3765
+ this._prepAnnotations();
3766
+ this._prepEffects();
3767
+ this._prepBehaviors();
3768
+ this._prepConfigure();
3769
+ this._prepBindings();
3770
+ Polymer.Base._initFeatures.call(this);
3771
+ this._children = Array.prototype.slice.call(this.root.childNodes);
3772
+ }
3773
+ this._insertChildren();
3774
+ this.fire("dom-change");
3775
+ },
3776
+ detached: function() {
3777
+ this._removeChildren();
3778
+ }
3779
+ });</script>