polymer-rails 1.1.5 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (25) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/polymer/LICENSE.txt +27 -0
  3. data/app/assets/javascripts/polymer/bower.json +27 -0
  4. data/app/assets/javascripts/polymer/build.log +27 -0
  5. data/app/assets/javascripts/polymer/polymer-micro.html +598 -597
  6. data/app/assets/javascripts/polymer/polymer-mini.html +1859 -1527
  7. data/app/assets/javascripts/polymer/polymer.html +4467 -4284
  8. data/app/assets/javascripts/webcomponentsjs/CustomElements.js +1041 -0
  9. data/app/assets/javascripts/webcomponentsjs/CustomElements.min.js +11 -0
  10. data/app/assets/javascripts/webcomponentsjs/HTMLImports.js +1155 -0
  11. data/app/assets/javascripts/webcomponentsjs/HTMLImports.min.js +11 -0
  12. data/app/assets/javascripts/webcomponentsjs/MutationObserver.js +350 -0
  13. data/app/assets/javascripts/webcomponentsjs/MutationObserver.min.js +11 -0
  14. data/app/assets/javascripts/webcomponentsjs/README.md +125 -0
  15. data/app/assets/javascripts/webcomponentsjs/ShadowDOM.js +4452 -0
  16. data/app/assets/javascripts/webcomponentsjs/ShadowDOM.min.js +13 -0
  17. data/app/assets/javascripts/webcomponentsjs/bower.json +21 -0
  18. data/app/assets/javascripts/webcomponentsjs/build.log +398 -0
  19. data/app/assets/javascripts/webcomponentsjs/package.json +28 -0
  20. data/app/assets/javascripts/webcomponentsjs/webcomponents-lite.js +169 -151
  21. data/app/assets/javascripts/webcomponentsjs/webcomponents-lite.min.js +12 -0
  22. data/app/assets/javascripts/webcomponentsjs/webcomponents.js +108 -70
  23. data/app/assets/javascripts/webcomponentsjs/webcomponents.min.js +14 -0
  24. data/lib/polymer-rails/version.rb +1 -1
  25. metadata +22 -5
@@ -1,1527 +1,1859 @@
1
- <!--
2
- @license
3
- Copyright (c) 2014 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
- --><link rel="import" href="polymer-micro.html">
10
-
11
- <script>Polymer.Base._addFeature({
12
- _prepTemplate: function () {
13
- this._template = this._template || Polymer.DomModule.import(this.is, 'template');
14
- if (this._template && this._template.hasAttribute('is')) {
15
- this._warn(this._logf('_prepTemplate', 'top-level Polymer template ' + 'must not be a type-extension, found', this._template, 'Move inside simple <template>.'));
16
- }
17
- if (this._template && !this._template.content && HTMLTemplateElement.bootstrap) {
18
- HTMLTemplateElement.decorate(this._template);
19
- HTMLTemplateElement.bootstrap(this._template.content);
20
- }
21
- },
22
- _stampTemplate: function () {
23
- if (this._template) {
24
- this.root = this.instanceTemplate(this._template);
25
- }
26
- },
27
- instanceTemplate: function (template) {
28
- var dom = document.importNode(template._content || template.content, true);
29
- return dom;
30
- }
31
- });
32
- (function () {
33
- var baseAttachedCallback = Polymer.Base.attachedCallback;
34
- Polymer.Base._addFeature({
35
- _hostStack: [],
36
- ready: function () {
37
- },
38
- _pushHost: function (host) {
39
- this.dataHost = host = host || Polymer.Base._hostStack[Polymer.Base._hostStack.length - 1];
40
- if (host && host._clients) {
41
- host._clients.push(this);
42
- }
43
- this._beginHost();
44
- },
45
- _beginHost: function () {
46
- Polymer.Base._hostStack.push(this);
47
- if (!this._clients) {
48
- this._clients = [];
49
- }
50
- },
51
- _popHost: function () {
52
- Polymer.Base._hostStack.pop();
53
- },
54
- _tryReady: function () {
55
- if (this._canReady()) {
56
- this._ready();
57
- }
58
- },
59
- _canReady: function () {
60
- return !this.dataHost || this.dataHost._clientsReadied;
61
- },
62
- _ready: function () {
63
- this._beforeClientsReady();
64
- this._setupRoot();
65
- this._readyClients();
66
- this._afterClientsReady();
67
- this._readySelf();
68
- },
69
- _readyClients: function () {
70
- this._beginDistribute();
71
- var c$ = this._clients;
72
- for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) {
73
- c._ready();
74
- }
75
- this._finishDistribute();
76
- this._clientsReadied = true;
77
- this._clients = null;
78
- },
79
- _readySelf: function () {
80
- this._doBehavior('ready');
81
- this._readied = true;
82
- if (this._attachedPending) {
83
- this._attachedPending = false;
84
- this.attachedCallback();
85
- }
86
- },
87
- _beforeClientsReady: function () {
88
- },
89
- _afterClientsReady: function () {
90
- },
91
- _beforeAttached: function () {
92
- },
93
- attachedCallback: function () {
94
- if (this._readied) {
95
- this._beforeAttached();
96
- baseAttachedCallback.call(this);
97
- } else {
98
- this._attachedPending = true;
99
- }
100
- }
101
- });
102
- }());
103
- Polymer.ArraySplice = function () {
104
- function newSplice(index, removed, addedCount) {
105
- return {
106
- index: index,
107
- removed: removed,
108
- addedCount: addedCount
109
- };
110
- }
111
- var EDIT_LEAVE = 0;
112
- var EDIT_UPDATE = 1;
113
- var EDIT_ADD = 2;
114
- var EDIT_DELETE = 3;
115
- function ArraySplice() {
116
- }
117
- ArraySplice.prototype = {
118
- calcEditDistances: function (current, currentStart, currentEnd, old, oldStart, oldEnd) {
119
- var rowCount = oldEnd - oldStart + 1;
120
- var columnCount = currentEnd - currentStart + 1;
121
- var distances = new Array(rowCount);
122
- for (var i = 0; i < rowCount; i++) {
123
- distances[i] = new Array(columnCount);
124
- distances[i][0] = i;
125
- }
126
- for (var j = 0; j < columnCount; j++)
127
- distances[0][j] = j;
128
- for (var i = 1; i < rowCount; i++) {
129
- for (var j = 1; j < columnCount; j++) {
130
- if (this.equals(current[currentStart + j - 1], old[oldStart + i - 1]))
131
- distances[i][j] = distances[i - 1][j - 1];
132
- else {
133
- var north = distances[i - 1][j] + 1;
134
- var west = distances[i][j - 1] + 1;
135
- distances[i][j] = north < west ? north : west;
136
- }
137
- }
138
- }
139
- return distances;
140
- },
141
- spliceOperationsFromEditDistances: function (distances) {
142
- var i = distances.length - 1;
143
- var j = distances[0].length - 1;
144
- var current = distances[i][j];
145
- var edits = [];
146
- while (i > 0 || j > 0) {
147
- if (i == 0) {
148
- edits.push(EDIT_ADD);
149
- j--;
150
- continue;
151
- }
152
- if (j == 0) {
153
- edits.push(EDIT_DELETE);
154
- i--;
155
- continue;
156
- }
157
- var northWest = distances[i - 1][j - 1];
158
- var west = distances[i - 1][j];
159
- var north = distances[i][j - 1];
160
- var min;
161
- if (west < north)
162
- min = west < northWest ? west : northWest;
163
- else
164
- min = north < northWest ? north : northWest;
165
- if (min == northWest) {
166
- if (northWest == current) {
167
- edits.push(EDIT_LEAVE);
168
- } else {
169
- edits.push(EDIT_UPDATE);
170
- current = northWest;
171
- }
172
- i--;
173
- j--;
174
- } else if (min == west) {
175
- edits.push(EDIT_DELETE);
176
- i--;
177
- current = west;
178
- } else {
179
- edits.push(EDIT_ADD);
180
- j--;
181
- current = north;
182
- }
183
- }
184
- edits.reverse();
185
- return edits;
186
- },
187
- calcSplices: function (current, currentStart, currentEnd, old, oldStart, oldEnd) {
188
- var prefixCount = 0;
189
- var suffixCount = 0;
190
- var minLength = Math.min(currentEnd - currentStart, oldEnd - oldStart);
191
- if (currentStart == 0 && oldStart == 0)
192
- prefixCount = this.sharedPrefix(current, old, minLength);
193
- if (currentEnd == current.length && oldEnd == old.length)
194
- suffixCount = this.sharedSuffix(current, old, minLength - prefixCount);
195
- currentStart += prefixCount;
196
- oldStart += prefixCount;
197
- currentEnd -= suffixCount;
198
- oldEnd -= suffixCount;
199
- if (currentEnd - currentStart == 0 && oldEnd - oldStart == 0)
200
- return [];
201
- if (currentStart == currentEnd) {
202
- var splice = newSplice(currentStart, [], 0);
203
- while (oldStart < oldEnd)
204
- splice.removed.push(old[oldStart++]);
205
- return [splice];
206
- } else if (oldStart == oldEnd)
207
- return [newSplice(currentStart, [], currentEnd - currentStart)];
208
- var ops = this.spliceOperationsFromEditDistances(this.calcEditDistances(current, currentStart, currentEnd, old, oldStart, oldEnd));
209
- var splice = undefined;
210
- var splices = [];
211
- var index = currentStart;
212
- var oldIndex = oldStart;
213
- for (var i = 0; i < ops.length; i++) {
214
- switch (ops[i]) {
215
- case EDIT_LEAVE:
216
- if (splice) {
217
- splices.push(splice);
218
- splice = undefined;
219
- }
220
- index++;
221
- oldIndex++;
222
- break;
223
- case EDIT_UPDATE:
224
- if (!splice)
225
- splice = newSplice(index, [], 0);
226
- splice.addedCount++;
227
- index++;
228
- splice.removed.push(old[oldIndex]);
229
- oldIndex++;
230
- break;
231
- case EDIT_ADD:
232
- if (!splice)
233
- splice = newSplice(index, [], 0);
234
- splice.addedCount++;
235
- index++;
236
- break;
237
- case EDIT_DELETE:
238
- if (!splice)
239
- splice = newSplice(index, [], 0);
240
- splice.removed.push(old[oldIndex]);
241
- oldIndex++;
242
- break;
243
- }
244
- }
245
- if (splice) {
246
- splices.push(splice);
247
- }
248
- return splices;
249
- },
250
- sharedPrefix: function (current, old, searchLength) {
251
- for (var i = 0; i < searchLength; i++)
252
- if (!this.equals(current[i], old[i]))
253
- return i;
254
- return searchLength;
255
- },
256
- sharedSuffix: function (current, old, searchLength) {
257
- var index1 = current.length;
258
- var index2 = old.length;
259
- var count = 0;
260
- while (count < searchLength && this.equals(current[--index1], old[--index2]))
261
- count++;
262
- return count;
263
- },
264
- calculateSplices: function (current, previous) {
265
- return this.calcSplices(current, 0, current.length, previous, 0, previous.length);
266
- },
267
- equals: function (currentValue, previousValue) {
268
- return currentValue === previousValue;
269
- }
270
- };
271
- return new ArraySplice();
272
- }();
273
- Polymer.EventApi = function () {
274
- var Settings = Polymer.Settings;
275
- var EventApi = function (event) {
276
- this.event = event;
277
- };
278
- if (Settings.useShadow) {
279
- EventApi.prototype = {
280
- get rootTarget() {
281
- return this.event.path[0];
282
- },
283
- get localTarget() {
284
- return this.event.target;
285
- },
286
- get path() {
287
- return this.event.path;
288
- }
289
- };
290
- } else {
291
- EventApi.prototype = {
292
- get rootTarget() {
293
- return this.event.target;
294
- },
295
- get localTarget() {
296
- var current = this.event.currentTarget;
297
- var currentRoot = current && Polymer.dom(current).getOwnerRoot();
298
- var p$ = this.path;
299
- for (var i = 0; i < p$.length; i++) {
300
- if (Polymer.dom(p$[i]).getOwnerRoot() === currentRoot) {
301
- return p$[i];
302
- }
303
- }
304
- },
305
- get path() {
306
- if (!this.event._path) {
307
- var path = [];
308
- var o = this.rootTarget;
309
- while (o) {
310
- path.push(o);
311
- o = Polymer.dom(o).parentNode || o.host;
312
- }
313
- path.push(window);
314
- this.event._path = path;
315
- }
316
- return this.event._path;
317
- }
318
- };
319
- }
320
- var factory = function (event) {
321
- if (!event.__eventApi) {
322
- event.__eventApi = new EventApi(event);
323
- }
324
- return event.__eventApi;
325
- };
326
- return { factory: factory };
327
- }();
328
- Polymer.domInnerHTML = function () {
329
- var escapeAttrRegExp = /[&\u00A0"]/g;
330
- var escapeDataRegExp = /[&\u00A0<>]/g;
331
- function escapeReplace(c) {
332
- switch (c) {
333
- case '&':
334
- return '&amp;';
335
- case '<':
336
- return '&lt;';
337
- case '>':
338
- return '&gt;';
339
- case '"':
340
- return '&quot;';
341
- case '\xA0':
342
- return '&nbsp;';
343
- }
344
- }
345
- function escapeAttr(s) {
346
- return s.replace(escapeAttrRegExp, escapeReplace);
347
- }
348
- function escapeData(s) {
349
- return s.replace(escapeDataRegExp, escapeReplace);
350
- }
351
- function makeSet(arr) {
352
- var set = {};
353
- for (var i = 0; i < arr.length; i++) {
354
- set[arr[i]] = true;
355
- }
356
- return set;
357
- }
358
- var voidElements = makeSet([
359
- 'area',
360
- 'base',
361
- 'br',
362
- 'col',
363
- 'command',
364
- 'embed',
365
- 'hr',
366
- 'img',
367
- 'input',
368
- 'keygen',
369
- 'link',
370
- 'meta',
371
- 'param',
372
- 'source',
373
- 'track',
374
- 'wbr'
375
- ]);
376
- var plaintextParents = makeSet([
377
- 'style',
378
- 'script',
379
- 'xmp',
380
- 'iframe',
381
- 'noembed',
382
- 'noframes',
383
- 'plaintext',
384
- 'noscript'
385
- ]);
386
- function getOuterHTML(node, parentNode, composed) {
387
- switch (node.nodeType) {
388
- case Node.ELEMENT_NODE:
389
- var tagName = node.localName;
390
- var s = '<' + tagName;
391
- var attrs = node.attributes;
392
- for (var i = 0, attr; attr = attrs[i]; i++) {
393
- s += ' ' + attr.name + '="' + escapeAttr(attr.value) + '"';
394
- }
395
- s += '>';
396
- if (voidElements[tagName]) {
397
- return s;
398
- }
399
- return s + getInnerHTML(node, composed) + '</' + tagName + '>';
400
- case Node.TEXT_NODE:
401
- var data = node.data;
402
- if (parentNode && plaintextParents[parentNode.localName]) {
403
- return data;
404
- }
405
- return escapeData(data);
406
- case Node.COMMENT_NODE:
407
- return '<!--' + node.data + '-->';
408
- default:
409
- console.error(node);
410
- throw new Error('not implemented');
411
- }
412
- }
413
- function getInnerHTML(node, composed) {
414
- if (node instanceof HTMLTemplateElement)
415
- node = node.content;
416
- var s = '';
417
- var c$ = Polymer.dom(node).childNodes;
418
- c$ = composed ? node._composedChildren : c$;
419
- for (var i = 0, l = c$.length, child; i < l && (child = c$[i]); i++) {
420
- s += getOuterHTML(child, node, composed);
421
- }
422
- return s;
423
- }
424
- return { getInnerHTML: getInnerHTML };
425
- }();
426
- Polymer.DomApi = function () {
427
- 'use strict';
428
- var Settings = Polymer.Settings;
429
- var getInnerHTML = Polymer.domInnerHTML.getInnerHTML;
430
- var nativeInsertBefore = Element.prototype.insertBefore;
431
- var nativeRemoveChild = Element.prototype.removeChild;
432
- var nativeAppendChild = Element.prototype.appendChild;
433
- var nativeCloneNode = Element.prototype.cloneNode;
434
- var nativeImportNode = Document.prototype.importNode;
435
- var DomApi = function (node) {
436
- this.node = node;
437
- if (this.patch) {
438
- this.patch();
439
- }
440
- };
441
- if (window.wrap && Settings.useShadow && !Settings.useNativeShadow) {
442
- DomApi = function (node) {
443
- this.node = wrap(node);
444
- if (this.patch) {
445
- this.patch();
446
- }
447
- };
448
- }
449
- DomApi.prototype = {
450
- flush: function () {
451
- Polymer.dom.flush();
452
- },
453
- _lazyDistribute: function (host) {
454
- if (host.shadyRoot && host.shadyRoot._distributionClean) {
455
- host.shadyRoot._distributionClean = false;
456
- Polymer.dom.addDebouncer(host.debounce('_distribute', host._distributeContent));
457
- }
458
- },
459
- appendChild: function (node) {
460
- return this._addNode(node);
461
- },
462
- insertBefore: function (node, ref_node) {
463
- return this._addNode(node, ref_node);
464
- },
465
- _addNode: function (node, ref_node) {
466
- this._removeNodeFromHost(node, true);
467
- var addedInsertionPoint;
468
- var root = this.getOwnerRoot();
469
- if (root) {
470
- addedInsertionPoint = this._maybeAddInsertionPoint(node, this.node);
471
- }
472
- if (this._nodeHasLogicalChildren(this.node)) {
473
- if (ref_node) {
474
- var children = this.childNodes;
475
- var index = children.indexOf(ref_node);
476
- if (index < 0) {
477
- throw Error('The ref_node to be inserted before is not a child ' + 'of this node');
478
- }
479
- }
480
- this._addLogicalInfo(node, this.node, index);
481
- }
482
- this._addNodeToHost(node);
483
- if (!this._maybeDistribute(node, this.node) && !this._tryRemoveUndistributedNode(node)) {
484
- if (ref_node) {
485
- ref_node = ref_node.localName === CONTENT ? this._firstComposedNode(ref_node) : ref_node;
486
- }
487
- var container = this.node._isShadyRoot ? this.node.host : this.node;
488
- addToComposedParent(container, node, ref_node);
489
- if (ref_node) {
490
- nativeInsertBefore.call(container, node, ref_node);
491
- } else {
492
- nativeAppendChild.call(container, node);
493
- }
494
- }
495
- if (addedInsertionPoint) {
496
- this._updateInsertionPoints(root.host);
497
- }
498
- return node;
499
- },
500
- removeChild: function (node) {
501
- if (factory(node).parentNode !== this.node) {
502
- console.warn('The node to be removed is not a child of this node', node);
503
- }
504
- this._removeNodeFromHost(node);
505
- if (!this._maybeDistribute(node, this.node)) {
506
- var container = this.node._isShadyRoot ? this.node.host : this.node;
507
- if (container === node.parentNode) {
508
- removeFromComposedParent(container, node);
509
- nativeRemoveChild.call(container, node);
510
- }
511
- }
512
- return node;
513
- },
514
- replaceChild: function (node, ref_node) {
515
- this.insertBefore(node, ref_node);
516
- this.removeChild(ref_node);
517
- return node;
518
- },
519
- _hasCachedOwnerRoot: function (node) {
520
- return Boolean(node._ownerShadyRoot !== undefined);
521
- },
522
- getOwnerRoot: function () {
523
- return this._ownerShadyRootForNode(this.node);
524
- },
525
- _ownerShadyRootForNode: function (node) {
526
- if (!node) {
527
- return;
528
- }
529
- if (node._ownerShadyRoot === undefined) {
530
- var root;
531
- if (node._isShadyRoot) {
532
- root = node;
533
- } else {
534
- var parent = Polymer.dom(node).parentNode;
535
- if (parent) {
536
- root = parent._isShadyRoot ? parent : this._ownerShadyRootForNode(parent);
537
- } else {
538
- root = null;
539
- }
540
- }
541
- node._ownerShadyRoot = root;
542
- }
543
- return node._ownerShadyRoot;
544
- },
545
- _maybeDistribute: function (node, parent) {
546
- var fragContent = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && !node.__noContent && Polymer.dom(node).querySelector(CONTENT);
547
- var wrappedContent = fragContent && Polymer.dom(fragContent).parentNode.nodeType !== Node.DOCUMENT_FRAGMENT_NODE;
548
- var hasContent = fragContent || node.localName === CONTENT;
549
- if (hasContent) {
550
- var root = this._ownerShadyRootForNode(parent);
551
- if (root) {
552
- var host = root.host;
553
- this._lazyDistribute(host);
554
- }
555
- }
556
- var parentNeedsDist = this._parentNeedsDistribution(parent);
557
- if (parentNeedsDist) {
558
- this._lazyDistribute(parent);
559
- }
560
- return parentNeedsDist || hasContent && !wrappedContent;
561
- },
562
- _maybeAddInsertionPoint: function (node, parent) {
563
- var added;
564
- if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && !node.__noContent) {
565
- var c$ = factory(node).querySelectorAll(CONTENT);
566
- for (var i = 0, n, np, na; i < c$.length && (n = c$[i]); i++) {
567
- np = factory(n).parentNode;
568
- if (np === node) {
569
- np = parent;
570
- }
571
- na = this._maybeAddInsertionPoint(n, np);
572
- added = added || na;
573
- }
574
- } else if (node.localName === CONTENT) {
575
- saveLightChildrenIfNeeded(parent);
576
- saveLightChildrenIfNeeded(node);
577
- added = true;
578
- }
579
- return added;
580
- },
581
- _tryRemoveUndistributedNode: function (node) {
582
- if (this.node.shadyRoot) {
583
- var parent = getComposedParent(node);
584
- if (parent) {
585
- nativeRemoveChild.call(parent, node);
586
- }
587
- return true;
588
- }
589
- },
590
- _updateInsertionPoints: function (host) {
591
- var i$ = host.shadyRoot._insertionPoints = factory(host.shadyRoot).querySelectorAll(CONTENT);
592
- for (var i = 0, c; i < i$.length; i++) {
593
- c = i$[i];
594
- saveLightChildrenIfNeeded(c);
595
- saveLightChildrenIfNeeded(factory(c).parentNode);
596
- }
597
- },
598
- _nodeHasLogicalChildren: function (node) {
599
- return Boolean(node._lightChildren !== undefined);
600
- },
601
- _parentNeedsDistribution: function (parent) {
602
- return parent && parent.shadyRoot && hasInsertionPoint(parent.shadyRoot);
603
- },
604
- _removeNodeFromHost: function (node, ensureComposedRemoval) {
605
- var hostNeedsDist;
606
- var root;
607
- var parent = node._lightParent;
608
- if (parent) {
609
- factory(node)._distributeParent();
610
- root = this._ownerShadyRootForNode(node);
611
- if (root) {
612
- root.host._elementRemove(node);
613
- hostNeedsDist = this._removeDistributedChildren(root, node);
614
- }
615
- this._removeLogicalInfo(node, node._lightParent);
616
- }
617
- this._removeOwnerShadyRoot(node);
618
- if (root && hostNeedsDist) {
619
- this._updateInsertionPoints(root.host);
620
- this._lazyDistribute(root.host);
621
- } else if (ensureComposedRemoval) {
622
- removeFromComposedParent(getComposedParent(node), node);
623
- }
624
- },
625
- _removeDistributedChildren: function (root, container) {
626
- var hostNeedsDist;
627
- var ip$ = root._insertionPoints;
628
- for (var i = 0; i < ip$.length; i++) {
629
- var content = ip$[i];
630
- if (this._contains(container, content)) {
631
- var dc$ = factory(content).getDistributedNodes();
632
- for (var j = 0; j < dc$.length; j++) {
633
- hostNeedsDist = true;
634
- var node = dc$[j];
635
- var parent = node.parentNode;
636
- if (parent) {
637
- removeFromComposedParent(parent, node);
638
- nativeRemoveChild.call(parent, node);
639
- }
640
- }
641
- }
642
- }
643
- return hostNeedsDist;
644
- },
645
- _contains: function (container, node) {
646
- while (node) {
647
- if (node == container) {
648
- return true;
649
- }
650
- node = factory(node).parentNode;
651
- }
652
- },
653
- _addNodeToHost: function (node) {
654
- var root = this.getOwnerRoot();
655
- if (root) {
656
- root.host._elementAdd(node);
657
- }
658
- },
659
- _addLogicalInfo: function (node, container, index) {
660
- var children = factory(container).childNodes;
661
- index = index === undefined ? children.length : index;
662
- if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
663
- var c$ = Array.prototype.slice.call(node.childNodes);
664
- for (var i = 0, n; i < c$.length && (n = c$[i]); i++) {
665
- children.splice(index++, 0, n);
666
- n._lightParent = container;
667
- }
668
- } else {
669
- children.splice(index, 0, node);
670
- node._lightParent = container;
671
- }
672
- },
673
- _removeLogicalInfo: function (node, container) {
674
- var children = factory(container).childNodes;
675
- var index = children.indexOf(node);
676
- if (index < 0 || container !== node._lightParent) {
677
- throw Error('The node to be removed is not a child of this node');
678
- }
679
- children.splice(index, 1);
680
- node._lightParent = null;
681
- },
682
- _removeOwnerShadyRoot: function (node) {
683
- if (this._hasCachedOwnerRoot(node)) {
684
- var c$ = factory(node).childNodes;
685
- for (var i = 0, l = c$.length, n; i < l && (n = c$[i]); i++) {
686
- this._removeOwnerShadyRoot(n);
687
- }
688
- }
689
- node._ownerShadyRoot = undefined;
690
- },
691
- _firstComposedNode: function (content) {
692
- var n$ = factory(content).getDistributedNodes();
693
- for (var i = 0, l = n$.length, n, p$; i < l && (n = n$[i]); i++) {
694
- p$ = factory(n).getDestinationInsertionPoints();
695
- if (p$[p$.length - 1] === content) {
696
- return n;
697
- }
698
- }
699
- },
700
- querySelector: function (selector) {
701
- return this.querySelectorAll(selector)[0];
702
- },
703
- querySelectorAll: function (selector) {
704
- return this._query(function (n) {
705
- return matchesSelector.call(n, selector);
706
- }, this.node);
707
- },
708
- _query: function (matcher, node) {
709
- node = node || this.node;
710
- var list = [];
711
- this._queryElements(factory(node).childNodes, matcher, list);
712
- return list;
713
- },
714
- _queryElements: function (elements, matcher, list) {
715
- for (var i = 0, l = elements.length, c; i < l && (c = elements[i]); i++) {
716
- if (c.nodeType === Node.ELEMENT_NODE) {
717
- this._queryElement(c, matcher, list);
718
- }
719
- }
720
- },
721
- _queryElement: function (node, matcher, list) {
722
- if (matcher(node)) {
723
- list.push(node);
724
- }
725
- this._queryElements(factory(node).childNodes, matcher, list);
726
- },
727
- getDestinationInsertionPoints: function () {
728
- return this.node._destinationInsertionPoints || [];
729
- },
730
- getDistributedNodes: function () {
731
- return this.node._distributedNodes || [];
732
- },
733
- queryDistributedElements: function (selector) {
734
- var c$ = this.childNodes;
735
- var list = [];
736
- this._distributedFilter(selector, c$, list);
737
- for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) {
738
- if (c.localName === CONTENT) {
739
- this._distributedFilter(selector, factory(c).getDistributedNodes(), list);
740
- }
741
- }
742
- return list;
743
- },
744
- _distributedFilter: function (selector, list, results) {
745
- results = results || [];
746
- for (var i = 0, l = list.length, d; i < l && (d = list[i]); i++) {
747
- if (d.nodeType === Node.ELEMENT_NODE && d.localName !== CONTENT && matchesSelector.call(d, selector)) {
748
- results.push(d);
749
- }
750
- }
751
- return results;
752
- },
753
- _clear: function () {
754
- while (this.childNodes.length) {
755
- this.removeChild(this.childNodes[0]);
756
- }
757
- },
758
- setAttribute: function (name, value) {
759
- this.node.setAttribute(name, value);
760
- this._distributeParent();
761
- },
762
- removeAttribute: function (name) {
763
- this.node.removeAttribute(name);
764
- this._distributeParent();
765
- },
766
- _distributeParent: function () {
767
- if (this._parentNeedsDistribution(this.parentNode)) {
768
- this._lazyDistribute(this.parentNode);
769
- }
770
- },
771
- cloneNode: function (deep) {
772
- var n = nativeCloneNode.call(this.node, false);
773
- if (deep) {
774
- var c$ = this.childNodes;
775
- var d = factory(n);
776
- for (var i = 0, nc; i < c$.length; i++) {
777
- nc = factory(c$[i]).cloneNode(true);
778
- d.appendChild(nc);
779
- }
780
- }
781
- return n;
782
- },
783
- importNode: function (externalNode, deep) {
784
- var doc = this.node instanceof Document ? this.node : this.node.ownerDocument;
785
- var n = nativeImportNode.call(doc, externalNode, false);
786
- if (deep) {
787
- var c$ = factory(externalNode).childNodes;
788
- var d = factory(n);
789
- for (var i = 0, nc; i < c$.length; i++) {
790
- nc = factory(doc).importNode(c$[i], true);
791
- d.appendChild(nc);
792
- }
793
- }
794
- return n;
795
- }
796
- };
797
- Object.defineProperty(DomApi.prototype, 'classList', {
798
- get: function () {
799
- if (!this._classList) {
800
- this._classList = new DomApi.ClassList(this);
801
- }
802
- return this._classList;
803
- },
804
- configurable: true
805
- });
806
- DomApi.ClassList = function (host) {
807
- this.domApi = host;
808
- this.node = host.node;
809
- };
810
- DomApi.ClassList.prototype = {
811
- add: function () {
812
- this.node.classList.add.apply(this.node.classList, arguments);
813
- this.domApi._distributeParent();
814
- },
815
- remove: function () {
816
- this.node.classList.remove.apply(this.node.classList, arguments);
817
- this.domApi._distributeParent();
818
- },
819
- toggle: function () {
820
- this.node.classList.toggle.apply(this.node.classList, arguments);
821
- this.domApi._distributeParent();
822
- },
823
- contains: function () {
824
- return this.node.classList.contains.apply(this.node.classList, arguments);
825
- }
826
- };
827
- if (!Settings.useShadow) {
828
- Object.defineProperties(DomApi.prototype, {
829
- childNodes: {
830
- get: function () {
831
- var c$ = getLightChildren(this.node);
832
- return Array.isArray(c$) ? c$ : Array.prototype.slice.call(c$);
833
- },
834
- configurable: true
835
- },
836
- children: {
837
- get: function () {
838
- return Array.prototype.filter.call(this.childNodes, function (n) {
839
- return n.nodeType === Node.ELEMENT_NODE;
840
- });
841
- },
842
- configurable: true
843
- },
844
- parentNode: {
845
- get: function () {
846
- return this.node._lightParent || getComposedParent(this.node);
847
- },
848
- configurable: true
849
- },
850
- firstChild: {
851
- get: function () {
852
- return this.childNodes[0];
853
- },
854
- configurable: true
855
- },
856
- lastChild: {
857
- get: function () {
858
- var c$ = this.childNodes;
859
- return c$[c$.length - 1];
860
- },
861
- configurable: true
862
- },
863
- nextSibling: {
864
- get: function () {
865
- var c$ = this.parentNode && factory(this.parentNode).childNodes;
866
- if (c$) {
867
- return c$[Array.prototype.indexOf.call(c$, this.node) + 1];
868
- }
869
- },
870
- configurable: true
871
- },
872
- previousSibling: {
873
- get: function () {
874
- var c$ = this.parentNode && factory(this.parentNode).childNodes;
875
- if (c$) {
876
- return c$[Array.prototype.indexOf.call(c$, this.node) - 1];
877
- }
878
- },
879
- configurable: true
880
- },
881
- firstElementChild: {
882
- get: function () {
883
- return this.children[0];
884
- },
885
- configurable: true
886
- },
887
- lastElementChild: {
888
- get: function () {
889
- var c$ = this.children;
890
- return c$[c$.length - 1];
891
- },
892
- configurable: true
893
- },
894
- nextElementSibling: {
895
- get: function () {
896
- var c$ = this.parentNode && factory(this.parentNode).children;
897
- if (c$) {
898
- return c$[Array.prototype.indexOf.call(c$, this.node) + 1];
899
- }
900
- },
901
- configurable: true
902
- },
903
- previousElementSibling: {
904
- get: function () {
905
- var c$ = this.parentNode && factory(this.parentNode).children;
906
- if (c$) {
907
- return c$[Array.prototype.indexOf.call(c$, this.node) - 1];
908
- }
909
- },
910
- configurable: true
911
- },
912
- textContent: {
913
- get: function () {
914
- var nt = this.node.nodeType;
915
- if (nt === Node.TEXT_NODE || nt === Node.COMMENT_NODE) {
916
- return this.node.textContent;
917
- } else {
918
- var tc = [];
919
- for (var i = 0, cn = this.childNodes, c; c = cn[i]; i++) {
920
- if (c.nodeType !== Node.COMMENT_NODE) {
921
- tc.push(c.textContent);
922
- }
923
- }
924
- return tc.join('');
925
- }
926
- },
927
- set: function (text) {
928
- var nt = this.node.nodeType;
929
- if (nt === Node.TEXT_NODE || nt === Node.COMMENT_NODE) {
930
- this.node.textContent = text;
931
- } else {
932
- this._clear();
933
- if (text) {
934
- this.appendChild(document.createTextNode(text));
935
- }
936
- }
937
- },
938
- configurable: true
939
- },
940
- innerHTML: {
941
- get: function () {
942
- var nt = this.node.nodeType;
943
- if (nt === Node.TEXT_NODE || nt === Node.COMMENT_NODE) {
944
- return null;
945
- } else {
946
- return getInnerHTML(this.node);
947
- }
948
- },
949
- set: function (text) {
950
- var nt = this.node.nodeType;
951
- if (nt !== Node.TEXT_NODE || nt !== Node.COMMENT_NODE) {
952
- this._clear();
953
- var d = document.createElement('div');
954
- d.innerHTML = text;
955
- var c$ = Array.prototype.slice.call(d.childNodes);
956
- for (var i = 0; i < c$.length; i++) {
957
- this.appendChild(c$[i]);
958
- }
959
- }
960
- },
961
- configurable: true
962
- }
963
- });
964
- DomApi.prototype._getComposedInnerHTML = function () {
965
- return getInnerHTML(this.node, true);
966
- };
967
- } else {
968
- var forwardMethods = [
969
- 'cloneNode',
970
- 'appendChild',
971
- 'insertBefore',
972
- 'removeChild',
973
- 'replaceChild'
974
- ];
975
- forwardMethods.forEach(function (name) {
976
- DomApi.prototype[name] = function () {
977
- return this.node[name].apply(this.node, arguments);
978
- };
979
- });
980
- DomApi.prototype.querySelectorAll = function (selector) {
981
- return Array.prototype.slice.call(this.node.querySelectorAll(selector));
982
- };
983
- DomApi.prototype.getOwnerRoot = function () {
984
- var n = this.node;
985
- while (n) {
986
- if (n.nodeType === Node.DOCUMENT_FRAGMENT_NODE && n.host) {
987
- return n;
988
- }
989
- n = n.parentNode;
990
- }
991
- };
992
- DomApi.prototype.importNode = function (externalNode, deep) {
993
- var doc = this.node instanceof Document ? this.node : this.node.ownerDocument;
994
- return doc.importNode(externalNode, deep);
995
- };
996
- DomApi.prototype.getDestinationInsertionPoints = function () {
997
- var n$ = this.node.getDestinationInsertionPoints && this.node.getDestinationInsertionPoints();
998
- return n$ ? Array.prototype.slice.call(n$) : [];
999
- };
1000
- DomApi.prototype.getDistributedNodes = function () {
1001
- var n$ = this.node.getDistributedNodes && this.node.getDistributedNodes();
1002
- return n$ ? Array.prototype.slice.call(n$) : [];
1003
- };
1004
- DomApi.prototype._distributeParent = function () {
1005
- };
1006
- Object.defineProperties(DomApi.prototype, {
1007
- childNodes: {
1008
- get: function () {
1009
- return Array.prototype.slice.call(this.node.childNodes);
1010
- },
1011
- configurable: true
1012
- },
1013
- children: {
1014
- get: function () {
1015
- return Array.prototype.slice.call(this.node.children);
1016
- },
1017
- configurable: true
1018
- },
1019
- textContent: {
1020
- get: function () {
1021
- return this.node.textContent;
1022
- },
1023
- set: function (value) {
1024
- return this.node.textContent = value;
1025
- },
1026
- configurable: true
1027
- },
1028
- innerHTML: {
1029
- get: function () {
1030
- return this.node.innerHTML;
1031
- },
1032
- set: function (value) {
1033
- return this.node.innerHTML = value;
1034
- },
1035
- configurable: true
1036
- }
1037
- });
1038
- var forwardProperties = [
1039
- 'parentNode',
1040
- 'firstChild',
1041
- 'lastChild',
1042
- 'nextSibling',
1043
- 'previousSibling',
1044
- 'firstElementChild',
1045
- 'lastElementChild',
1046
- 'nextElementSibling',
1047
- 'previousElementSibling'
1048
- ];
1049
- forwardProperties.forEach(function (name) {
1050
- Object.defineProperty(DomApi.prototype, name, {
1051
- get: function () {
1052
- return this.node[name];
1053
- },
1054
- configurable: true
1055
- });
1056
- });
1057
- }
1058
- var CONTENT = 'content';
1059
- var factory = function (node, patch) {
1060
- node = node || document;
1061
- if (!node.__domApi) {
1062
- node.__domApi = new DomApi(node, patch);
1063
- }
1064
- return node.__domApi;
1065
- };
1066
- Polymer.dom = function (obj, patch) {
1067
- if (obj instanceof Event) {
1068
- return Polymer.EventApi.factory(obj);
1069
- } else {
1070
- return factory(obj, patch);
1071
- }
1072
- };
1073
- Polymer.Base.extend(Polymer.dom, {
1074
- _flushGuard: 0,
1075
- _FLUSH_MAX: 100,
1076
- _needsTakeRecords: !Polymer.Settings.useNativeCustomElements,
1077
- _debouncers: [],
1078
- _finishDebouncer: null,
1079
- flush: function () {
1080
- for (var i = 0; i < this._debouncers.length; i++) {
1081
- this._debouncers[i].complete();
1082
- }
1083
- if (this._finishDebouncer) {
1084
- this._finishDebouncer.complete();
1085
- }
1086
- this._flushPolyfills();
1087
- if (this._debouncers.length && this._flushGuard < this._FLUSH_MAX) {
1088
- this._flushGuard++;
1089
- this.flush();
1090
- } else {
1091
- if (this._flushGuard >= this._FLUSH_MAX) {
1092
- console.warn('Polymer.dom.flush aborted. Flush may not be complete.');
1093
- }
1094
- this._flushGuard = 0;
1095
- }
1096
- },
1097
- _flushPolyfills: function () {
1098
- if (this._needsTakeRecords) {
1099
- CustomElements.takeRecords();
1100
- }
1101
- },
1102
- addDebouncer: function (debouncer) {
1103
- this._debouncers.push(debouncer);
1104
- this._finishDebouncer = Polymer.Debounce(this._finishDebouncer, this._finishFlush);
1105
- },
1106
- _finishFlush: function () {
1107
- Polymer.dom._debouncers = [];
1108
- }
1109
- });
1110
- function getLightChildren(node) {
1111
- var children = node._lightChildren;
1112
- return children ? children : node.childNodes;
1113
- }
1114
- function getComposedChildren(node) {
1115
- if (!node._composedChildren) {
1116
- node._composedChildren = Array.prototype.slice.call(node.childNodes);
1117
- }
1118
- return node._composedChildren;
1119
- }
1120
- function addToComposedParent(parent, node, ref_node) {
1121
- var children = getComposedChildren(parent);
1122
- var i = ref_node ? children.indexOf(ref_node) : -1;
1123
- if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
1124
- var fragChildren = getComposedChildren(node);
1125
- for (var j = 0; j < fragChildren.length; j++) {
1126
- addNodeToComposedChildren(fragChildren[j], parent, children, i + j);
1127
- }
1128
- node._composedChildren = null;
1129
- } else {
1130
- addNodeToComposedChildren(node, parent, children, i);
1131
- }
1132
- }
1133
- function getComposedParent(node) {
1134
- return node.__patched ? node._composedParent : node.parentNode;
1135
- }
1136
- function addNodeToComposedChildren(node, parent, children, i) {
1137
- node._composedParent = parent;
1138
- children.splice(i >= 0 ? i : children.length, 0, node);
1139
- }
1140
- function removeFromComposedParent(parent, node) {
1141
- node._composedParent = null;
1142
- if (parent) {
1143
- var children = getComposedChildren(parent);
1144
- var i = children.indexOf(node);
1145
- if (i >= 0) {
1146
- children.splice(i, 1);
1147
- }
1148
- }
1149
- }
1150
- function saveLightChildrenIfNeeded(node) {
1151
- if (!node._lightChildren) {
1152
- var c$ = Array.prototype.slice.call(node.childNodes);
1153
- for (var i = 0, l = c$.length, child; i < l && (child = c$[i]); i++) {
1154
- child._lightParent = child._lightParent || node;
1155
- }
1156
- node._lightChildren = c$;
1157
- }
1158
- }
1159
- function hasInsertionPoint(root) {
1160
- return Boolean(root && root._insertionPoints.length);
1161
- }
1162
- var p = Element.prototype;
1163
- var matchesSelector = p.matches || p.matchesSelector || p.mozMatchesSelector || p.msMatchesSelector || p.oMatchesSelector || p.webkitMatchesSelector;
1164
- return {
1165
- getLightChildren: getLightChildren,
1166
- getComposedParent: getComposedParent,
1167
- getComposedChildren: getComposedChildren,
1168
- removeFromComposedParent: removeFromComposedParent,
1169
- saveLightChildrenIfNeeded: saveLightChildrenIfNeeded,
1170
- matchesSelector: matchesSelector,
1171
- hasInsertionPoint: hasInsertionPoint,
1172
- ctor: DomApi,
1173
- factory: factory
1174
- };
1175
- }();
1176
- (function () {
1177
- Polymer.Base._addFeature({
1178
- _prepShady: function () {
1179
- this._useContent = this._useContent || Boolean(this._template);
1180
- },
1181
- _poolContent: function () {
1182
- if (this._useContent) {
1183
- saveLightChildrenIfNeeded(this);
1184
- }
1185
- },
1186
- _setupRoot: function () {
1187
- if (this._useContent) {
1188
- this._createLocalRoot();
1189
- if (!this.dataHost) {
1190
- upgradeLightChildren(this._lightChildren);
1191
- }
1192
- }
1193
- },
1194
- _createLocalRoot: function () {
1195
- this.shadyRoot = this.root;
1196
- this.shadyRoot._distributionClean = false;
1197
- this.shadyRoot._isShadyRoot = true;
1198
- this.shadyRoot._dirtyRoots = [];
1199
- var i$ = this.shadyRoot._insertionPoints = !this._notes || this._notes._hasContent ? this.shadyRoot.querySelectorAll('content') : [];
1200
- saveLightChildrenIfNeeded(this.shadyRoot);
1201
- for (var i = 0, c; i < i$.length; i++) {
1202
- c = i$[i];
1203
- saveLightChildrenIfNeeded(c);
1204
- saveLightChildrenIfNeeded(c.parentNode);
1205
- }
1206
- this.shadyRoot.host = this;
1207
- },
1208
- get domHost() {
1209
- var root = Polymer.dom(this).getOwnerRoot();
1210
- return root && root.host;
1211
- },
1212
- distributeContent: function (updateInsertionPoints) {
1213
- if (this.shadyRoot) {
1214
- var dom = Polymer.dom(this);
1215
- if (updateInsertionPoints) {
1216
- dom._updateInsertionPoints(this);
1217
- }
1218
- var host = getTopDistributingHost(this);
1219
- dom._lazyDistribute(host);
1220
- }
1221
- },
1222
- _distributeContent: function () {
1223
- if (this._useContent && !this.shadyRoot._distributionClean) {
1224
- this._beginDistribute();
1225
- this._distributeDirtyRoots();
1226
- this._finishDistribute();
1227
- }
1228
- },
1229
- _beginDistribute: function () {
1230
- if (this._useContent && hasInsertionPoint(this.shadyRoot)) {
1231
- this._resetDistribution();
1232
- this._distributePool(this.shadyRoot, this._collectPool());
1233
- }
1234
- },
1235
- _distributeDirtyRoots: function () {
1236
- var c$ = this.shadyRoot._dirtyRoots;
1237
- for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) {
1238
- c._distributeContent();
1239
- }
1240
- this.shadyRoot._dirtyRoots = [];
1241
- },
1242
- _finishDistribute: function () {
1243
- if (this._useContent) {
1244
- this.shadyRoot._distributionClean = true;
1245
- if (hasInsertionPoint(this.shadyRoot)) {
1246
- this._composeTree();
1247
- } else {
1248
- if (!this.shadyRoot._hasDistributed) {
1249
- this.textContent = '';
1250
- this._composedChildren = null;
1251
- this.appendChild(this.shadyRoot);
1252
- } else {
1253
- var children = this._composeNode(this);
1254
- this._updateChildNodes(this, children);
1255
- }
1256
- }
1257
- this.shadyRoot._hasDistributed = true;
1258
- }
1259
- },
1260
- elementMatches: function (selector, node) {
1261
- node = node || this;
1262
- return matchesSelector.call(node, selector);
1263
- },
1264
- _resetDistribution: function () {
1265
- var children = getLightChildren(this);
1266
- for (var i = 0; i < children.length; i++) {
1267
- var child = children[i];
1268
- if (child._destinationInsertionPoints) {
1269
- child._destinationInsertionPoints = undefined;
1270
- }
1271
- if (isInsertionPoint(child)) {
1272
- clearDistributedDestinationInsertionPoints(child);
1273
- }
1274
- }
1275
- var root = this.shadyRoot;
1276
- var p$ = root._insertionPoints;
1277
- for (var j = 0; j < p$.length; j++) {
1278
- p$[j]._distributedNodes = [];
1279
- }
1280
- },
1281
- _collectPool: function () {
1282
- var pool = [];
1283
- var children = getLightChildren(this);
1284
- for (var i = 0; i < children.length; i++) {
1285
- var child = children[i];
1286
- if (isInsertionPoint(child)) {
1287
- pool.push.apply(pool, child._distributedNodes);
1288
- } else {
1289
- pool.push(child);
1290
- }
1291
- }
1292
- return pool;
1293
- },
1294
- _distributePool: function (node, pool) {
1295
- var p$ = node._insertionPoints;
1296
- for (var i = 0, l = p$.length, p; i < l && (p = p$[i]); i++) {
1297
- this._distributeInsertionPoint(p, pool);
1298
- maybeRedistributeParent(p, this);
1299
- }
1300
- },
1301
- _distributeInsertionPoint: function (content, pool) {
1302
- var anyDistributed = false;
1303
- for (var i = 0, l = pool.length, node; i < l; i++) {
1304
- node = pool[i];
1305
- if (!node) {
1306
- continue;
1307
- }
1308
- if (this._matchesContentSelect(node, content)) {
1309
- distributeNodeInto(node, content);
1310
- pool[i] = undefined;
1311
- anyDistributed = true;
1312
- }
1313
- }
1314
- if (!anyDistributed) {
1315
- var children = getLightChildren(content);
1316
- for (var j = 0; j < children.length; j++) {
1317
- distributeNodeInto(children[j], content);
1318
- }
1319
- }
1320
- },
1321
- _composeTree: function () {
1322
- this._updateChildNodes(this, this._composeNode(this));
1323
- var p$ = this.shadyRoot._insertionPoints;
1324
- for (var i = 0, l = p$.length, p, parent; i < l && (p = p$[i]); i++) {
1325
- parent = p._lightParent || p.parentNode;
1326
- if (!parent._useContent && parent !== this && parent !== this.shadyRoot) {
1327
- this._updateChildNodes(parent, this._composeNode(parent));
1328
- }
1329
- }
1330
- },
1331
- _composeNode: function (node) {
1332
- var children = [];
1333
- var c$ = getLightChildren(node.shadyRoot || node);
1334
- for (var i = 0; i < c$.length; i++) {
1335
- var child = c$[i];
1336
- if (isInsertionPoint(child)) {
1337
- var distributedNodes = child._distributedNodes;
1338
- for (var j = 0; j < distributedNodes.length; j++) {
1339
- var distributedNode = distributedNodes[j];
1340
- if (isFinalDestination(child, distributedNode)) {
1341
- children.push(distributedNode);
1342
- }
1343
- }
1344
- } else {
1345
- children.push(child);
1346
- }
1347
- }
1348
- return children;
1349
- },
1350
- _updateChildNodes: function (container, children) {
1351
- var composed = getComposedChildren(container);
1352
- var splices = Polymer.ArraySplice.calculateSplices(children, composed);
1353
- for (var i = 0, d = 0, s; i < splices.length && (s = splices[i]); i++) {
1354
- for (var j = 0, n; j < s.removed.length && (n = s.removed[j]); j++) {
1355
- if (getComposedParent(n) === container) {
1356
- remove(n);
1357
- }
1358
- composed.splice(s.index + d, 1);
1359
- }
1360
- d -= s.addedCount;
1361
- }
1362
- for (var i = 0, s, next; i < splices.length && (s = splices[i]); i++) {
1363
- next = composed[s.index];
1364
- for (var j = s.index, n; j < s.index + s.addedCount; j++) {
1365
- n = children[j];
1366
- insertBefore(container, n, next);
1367
- composed.splice(j, 0, n);
1368
- }
1369
- }
1370
- ensureComposedParent(container, children);
1371
- },
1372
- _matchesContentSelect: function (node, contentElement) {
1373
- var select = contentElement.getAttribute('select');
1374
- if (!select) {
1375
- return true;
1376
- }
1377
- select = select.trim();
1378
- if (!select) {
1379
- return true;
1380
- }
1381
- if (!(node instanceof Element)) {
1382
- return false;
1383
- }
1384
- var validSelectors = /^(:not\()?[*.#[a-zA-Z_|]/;
1385
- if (!validSelectors.test(select)) {
1386
- return false;
1387
- }
1388
- return this.elementMatches(select, node);
1389
- },
1390
- _elementAdd: function () {
1391
- },
1392
- _elementRemove: function () {
1393
- }
1394
- });
1395
- var saveLightChildrenIfNeeded = Polymer.DomApi.saveLightChildrenIfNeeded;
1396
- var getLightChildren = Polymer.DomApi.getLightChildren;
1397
- var matchesSelector = Polymer.DomApi.matchesSelector;
1398
- var hasInsertionPoint = Polymer.DomApi.hasInsertionPoint;
1399
- var getComposedChildren = Polymer.DomApi.getComposedChildren;
1400
- var getComposedParent = Polymer.DomApi.getComposedParent;
1401
- var removeFromComposedParent = Polymer.DomApi.removeFromComposedParent;
1402
- function distributeNodeInto(child, insertionPoint) {
1403
- insertionPoint._distributedNodes.push(child);
1404
- var points = child._destinationInsertionPoints;
1405
- if (!points) {
1406
- child._destinationInsertionPoints = [insertionPoint];
1407
- } else {
1408
- points.push(insertionPoint);
1409
- }
1410
- }
1411
- function clearDistributedDestinationInsertionPoints(content) {
1412
- var e$ = content._distributedNodes;
1413
- if (e$) {
1414
- for (var i = 0; i < e$.length; i++) {
1415
- var d = e$[i]._destinationInsertionPoints;
1416
- if (d) {
1417
- d.splice(d.indexOf(content) + 1, d.length);
1418
- }
1419
- }
1420
- }
1421
- }
1422
- function maybeRedistributeParent(content, host) {
1423
- var parent = content._lightParent;
1424
- if (parent && parent.shadyRoot && hasInsertionPoint(parent.shadyRoot) && parent.shadyRoot._distributionClean) {
1425
- parent.shadyRoot._distributionClean = false;
1426
- host.shadyRoot._dirtyRoots.push(parent);
1427
- }
1428
- }
1429
- function isFinalDestination(insertionPoint, node) {
1430
- var points = node._destinationInsertionPoints;
1431
- return points && points[points.length - 1] === insertionPoint;
1432
- }
1433
- function isInsertionPoint(node) {
1434
- return node.localName == 'content';
1435
- }
1436
- var nativeInsertBefore = Element.prototype.insertBefore;
1437
- var nativeRemoveChild = Element.prototype.removeChild;
1438
- function insertBefore(parentNode, newChild, refChild) {
1439
- var newChildParent = getComposedParent(newChild);
1440
- if (newChildParent !== parentNode) {
1441
- removeFromComposedParent(newChildParent, newChild);
1442
- }
1443
- remove(newChild);
1444
- nativeInsertBefore.call(parentNode, newChild, refChild || null);
1445
- newChild._composedParent = parentNode;
1446
- }
1447
- function remove(node) {
1448
- var parentNode = getComposedParent(node);
1449
- if (parentNode) {
1450
- node._composedParent = null;
1451
- nativeRemoveChild.call(parentNode, node);
1452
- }
1453
- }
1454
- function ensureComposedParent(parent, children) {
1455
- for (var i = 0, n; i < children.length; i++) {
1456
- children[i]._composedParent = parent;
1457
- }
1458
- }
1459
- function getTopDistributingHost(host) {
1460
- while (host && hostNeedsRedistribution(host)) {
1461
- host = host.domHost;
1462
- }
1463
- return host;
1464
- }
1465
- function hostNeedsRedistribution(host) {
1466
- var c$ = Polymer.dom(host).children;
1467
- for (var i = 0, c; i < c$.length; i++) {
1468
- c = c$[i];
1469
- if (c.localName === 'content') {
1470
- return host.domHost;
1471
- }
1472
- }
1473
- }
1474
- var needsUpgrade = window.CustomElements && !CustomElements.useNative;
1475
- function upgradeLightChildren(children) {
1476
- if (needsUpgrade && children) {
1477
- for (var i = 0; i < children.length; i++) {
1478
- CustomElements.upgrade(children[i]);
1479
- }
1480
- }
1481
- }
1482
- }());
1483
- if (Polymer.Settings.useShadow) {
1484
- Polymer.Base._addFeature({
1485
- _poolContent: function () {
1486
- },
1487
- _beginDistribute: function () {
1488
- },
1489
- distributeContent: function () {
1490
- },
1491
- _distributeContent: function () {
1492
- },
1493
- _finishDistribute: function () {
1494
- },
1495
- _createLocalRoot: function () {
1496
- this.createShadowRoot();
1497
- this.shadowRoot.appendChild(this.root);
1498
- this.root = this.shadowRoot;
1499
- }
1500
- });
1501
- }
1502
- Polymer.DomModule = document.createElement('dom-module');
1503
- Polymer.Base._addFeature({
1504
- _registerFeatures: function () {
1505
- this._prepIs();
1506
- this._prepAttributes();
1507
- this._prepBehaviors();
1508
- this._prepConstructor();
1509
- this._prepTemplate();
1510
- this._prepShady();
1511
- },
1512
- _prepBehavior: function (b) {
1513
- this._addHostAttributes(b.hostAttributes);
1514
- },
1515
- _initFeatures: function () {
1516
- this._poolContent();
1517
- this._pushHost();
1518
- this._stampTemplate();
1519
- this._popHost();
1520
- this._marshalHostAttributes();
1521
- this._setupDebouncers();
1522
- this._marshalBehaviors();
1523
- this._tryReady();
1524
- },
1525
- _marshalBehavior: function (b) {
1526
- }
1527
- });</script>
1
+ <!--
2
+ @license
3
+ Copyright (c) 2014 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
+ --><link rel="import" href="polymer-micro.html">
10
+
11
+ <script>Polymer.Base._addFeature({
12
+ _prepTemplate: function () {
13
+ this._template = this._template || Polymer.DomModule.import(this.is, 'template');
14
+ if (this._template && this._template.hasAttribute('is')) {
15
+ this._warn(this._logf('_prepTemplate', 'top-level Polymer template ' + 'must not be a type-extension, found', this._template, 'Move inside simple <template>.'));
16
+ }
17
+ if (this._template && !this._template.content && HTMLTemplateElement.bootstrap) {
18
+ HTMLTemplateElement.decorate(this._template);
19
+ HTMLTemplateElement.bootstrap(this._template.content);
20
+ }
21
+ },
22
+ _stampTemplate: function () {
23
+ if (this._template) {
24
+ this.root = this.instanceTemplate(this._template);
25
+ }
26
+ },
27
+ instanceTemplate: function (template) {
28
+ var dom = document.importNode(template._content || template.content, true);
29
+ return dom;
30
+ }
31
+ });
32
+ (function () {
33
+ var baseAttachedCallback = Polymer.Base.attachedCallback;
34
+ Polymer.Base._addFeature({
35
+ _hostStack: [],
36
+ ready: function () {
37
+ },
38
+ _pushHost: function (host) {
39
+ this.dataHost = host = host || Polymer.Base._hostStack[Polymer.Base._hostStack.length - 1];
40
+ if (host && host._clients) {
41
+ host._clients.push(this);
42
+ }
43
+ this._beginHost();
44
+ },
45
+ _beginHost: function () {
46
+ Polymer.Base._hostStack.push(this);
47
+ if (!this._clients) {
48
+ this._clients = [];
49
+ }
50
+ },
51
+ _popHost: function () {
52
+ Polymer.Base._hostStack.pop();
53
+ },
54
+ _tryReady: function () {
55
+ if (this._canReady()) {
56
+ this._ready();
57
+ }
58
+ },
59
+ _canReady: function () {
60
+ return !this.dataHost || this.dataHost._clientsReadied;
61
+ },
62
+ _ready: function () {
63
+ this._beforeClientsReady();
64
+ this._setupRoot();
65
+ this._readyClients();
66
+ this._afterClientsReady();
67
+ this._readySelf();
68
+ },
69
+ _readyClients: function () {
70
+ this._beginDistribute();
71
+ var c$ = this._clients;
72
+ for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) {
73
+ c._ready();
74
+ }
75
+ this._finishDistribute();
76
+ this._clientsReadied = true;
77
+ this._clients = null;
78
+ },
79
+ _readySelf: function () {
80
+ this._doBehavior('ready');
81
+ this._readied = true;
82
+ if (this._attachedPending) {
83
+ this._attachedPending = false;
84
+ this.attachedCallback();
85
+ }
86
+ },
87
+ _beforeClientsReady: function () {
88
+ },
89
+ _afterClientsReady: function () {
90
+ },
91
+ _beforeAttached: function () {
92
+ },
93
+ attachedCallback: function () {
94
+ if (this._readied) {
95
+ this._beforeAttached();
96
+ baseAttachedCallback.call(this);
97
+ } else {
98
+ this._attachedPending = true;
99
+ }
100
+ }
101
+ });
102
+ }());
103
+ Polymer.ArraySplice = function () {
104
+ function newSplice(index, removed, addedCount) {
105
+ return {
106
+ index: index,
107
+ removed: removed,
108
+ addedCount: addedCount
109
+ };
110
+ }
111
+ var EDIT_LEAVE = 0;
112
+ var EDIT_UPDATE = 1;
113
+ var EDIT_ADD = 2;
114
+ var EDIT_DELETE = 3;
115
+ function ArraySplice() {
116
+ }
117
+ ArraySplice.prototype = {
118
+ calcEditDistances: function (current, currentStart, currentEnd, old, oldStart, oldEnd) {
119
+ var rowCount = oldEnd - oldStart + 1;
120
+ var columnCount = currentEnd - currentStart + 1;
121
+ var distances = new Array(rowCount);
122
+ for (var i = 0; i < rowCount; i++) {
123
+ distances[i] = new Array(columnCount);
124
+ distances[i][0] = i;
125
+ }
126
+ for (var j = 0; j < columnCount; j++)
127
+ distances[0][j] = j;
128
+ for (var i = 1; i < rowCount; i++) {
129
+ for (var j = 1; j < columnCount; j++) {
130
+ if (this.equals(current[currentStart + j - 1], old[oldStart + i - 1]))
131
+ distances[i][j] = distances[i - 1][j - 1];
132
+ else {
133
+ var north = distances[i - 1][j] + 1;
134
+ var west = distances[i][j - 1] + 1;
135
+ distances[i][j] = north < west ? north : west;
136
+ }
137
+ }
138
+ }
139
+ return distances;
140
+ },
141
+ spliceOperationsFromEditDistances: function (distances) {
142
+ var i = distances.length - 1;
143
+ var j = distances[0].length - 1;
144
+ var current = distances[i][j];
145
+ var edits = [];
146
+ while (i > 0 || j > 0) {
147
+ if (i == 0) {
148
+ edits.push(EDIT_ADD);
149
+ j--;
150
+ continue;
151
+ }
152
+ if (j == 0) {
153
+ edits.push(EDIT_DELETE);
154
+ i--;
155
+ continue;
156
+ }
157
+ var northWest = distances[i - 1][j - 1];
158
+ var west = distances[i - 1][j];
159
+ var north = distances[i][j - 1];
160
+ var min;
161
+ if (west < north)
162
+ min = west < northWest ? west : northWest;
163
+ else
164
+ min = north < northWest ? north : northWest;
165
+ if (min == northWest) {
166
+ if (northWest == current) {
167
+ edits.push(EDIT_LEAVE);
168
+ } else {
169
+ edits.push(EDIT_UPDATE);
170
+ current = northWest;
171
+ }
172
+ i--;
173
+ j--;
174
+ } else if (min == west) {
175
+ edits.push(EDIT_DELETE);
176
+ i--;
177
+ current = west;
178
+ } else {
179
+ edits.push(EDIT_ADD);
180
+ j--;
181
+ current = north;
182
+ }
183
+ }
184
+ edits.reverse();
185
+ return edits;
186
+ },
187
+ calcSplices: function (current, currentStart, currentEnd, old, oldStart, oldEnd) {
188
+ var prefixCount = 0;
189
+ var suffixCount = 0;
190
+ var minLength = Math.min(currentEnd - currentStart, oldEnd - oldStart);
191
+ if (currentStart == 0 && oldStart == 0)
192
+ prefixCount = this.sharedPrefix(current, old, minLength);
193
+ if (currentEnd == current.length && oldEnd == old.length)
194
+ suffixCount = this.sharedSuffix(current, old, minLength - prefixCount);
195
+ currentStart += prefixCount;
196
+ oldStart += prefixCount;
197
+ currentEnd -= suffixCount;
198
+ oldEnd -= suffixCount;
199
+ if (currentEnd - currentStart == 0 && oldEnd - oldStart == 0)
200
+ return [];
201
+ if (currentStart == currentEnd) {
202
+ var splice = newSplice(currentStart, [], 0);
203
+ while (oldStart < oldEnd)
204
+ splice.removed.push(old[oldStart++]);
205
+ return [splice];
206
+ } else if (oldStart == oldEnd)
207
+ return [newSplice(currentStart, [], currentEnd - currentStart)];
208
+ var ops = this.spliceOperationsFromEditDistances(this.calcEditDistances(current, currentStart, currentEnd, old, oldStart, oldEnd));
209
+ var splice = undefined;
210
+ var splices = [];
211
+ var index = currentStart;
212
+ var oldIndex = oldStart;
213
+ for (var i = 0; i < ops.length; i++) {
214
+ switch (ops[i]) {
215
+ case EDIT_LEAVE:
216
+ if (splice) {
217
+ splices.push(splice);
218
+ splice = undefined;
219
+ }
220
+ index++;
221
+ oldIndex++;
222
+ break;
223
+ case EDIT_UPDATE:
224
+ if (!splice)
225
+ splice = newSplice(index, [], 0);
226
+ splice.addedCount++;
227
+ index++;
228
+ splice.removed.push(old[oldIndex]);
229
+ oldIndex++;
230
+ break;
231
+ case EDIT_ADD:
232
+ if (!splice)
233
+ splice = newSplice(index, [], 0);
234
+ splice.addedCount++;
235
+ index++;
236
+ break;
237
+ case EDIT_DELETE:
238
+ if (!splice)
239
+ splice = newSplice(index, [], 0);
240
+ splice.removed.push(old[oldIndex]);
241
+ oldIndex++;
242
+ break;
243
+ }
244
+ }
245
+ if (splice) {
246
+ splices.push(splice);
247
+ }
248
+ return splices;
249
+ },
250
+ sharedPrefix: function (current, old, searchLength) {
251
+ for (var i = 0; i < searchLength; i++)
252
+ if (!this.equals(current[i], old[i]))
253
+ return i;
254
+ return searchLength;
255
+ },
256
+ sharedSuffix: function (current, old, searchLength) {
257
+ var index1 = current.length;
258
+ var index2 = old.length;
259
+ var count = 0;
260
+ while (count < searchLength && this.equals(current[--index1], old[--index2]))
261
+ count++;
262
+ return count;
263
+ },
264
+ calculateSplices: function (current, previous) {
265
+ return this.calcSplices(current, 0, current.length, previous, 0, previous.length);
266
+ },
267
+ equals: function (currentValue, previousValue) {
268
+ return currentValue === previousValue;
269
+ }
270
+ };
271
+ return new ArraySplice();
272
+ }();
273
+ Polymer.domInnerHTML = function () {
274
+ var escapeAttrRegExp = /[&\u00A0"]/g;
275
+ var escapeDataRegExp = /[&\u00A0<>]/g;
276
+ function escapeReplace(c) {
277
+ switch (c) {
278
+ case '&':
279
+ return '&amp;';
280
+ case '<':
281
+ return '&lt;';
282
+ case '>':
283
+ return '&gt;';
284
+ case '"':
285
+ return '&quot;';
286
+ case '\xA0':
287
+ return '&nbsp;';
288
+ }
289
+ }
290
+ function escapeAttr(s) {
291
+ return s.replace(escapeAttrRegExp, escapeReplace);
292
+ }
293
+ function escapeData(s) {
294
+ return s.replace(escapeDataRegExp, escapeReplace);
295
+ }
296
+ function makeSet(arr) {
297
+ var set = {};
298
+ for (var i = 0; i < arr.length; i++) {
299
+ set[arr[i]] = true;
300
+ }
301
+ return set;
302
+ }
303
+ var voidElements = makeSet([
304
+ 'area',
305
+ 'base',
306
+ 'br',
307
+ 'col',
308
+ 'command',
309
+ 'embed',
310
+ 'hr',
311
+ 'img',
312
+ 'input',
313
+ 'keygen',
314
+ 'link',
315
+ 'meta',
316
+ 'param',
317
+ 'source',
318
+ 'track',
319
+ 'wbr'
320
+ ]);
321
+ var plaintextParents = makeSet([
322
+ 'style',
323
+ 'script',
324
+ 'xmp',
325
+ 'iframe',
326
+ 'noembed',
327
+ 'noframes',
328
+ 'plaintext',
329
+ 'noscript'
330
+ ]);
331
+ function getOuterHTML(node, parentNode, composed) {
332
+ switch (node.nodeType) {
333
+ case Node.ELEMENT_NODE:
334
+ var tagName = node.localName;
335
+ var s = '<' + tagName;
336
+ var attrs = node.attributes;
337
+ for (var i = 0, attr; attr = attrs[i]; i++) {
338
+ s += ' ' + attr.name + '="' + escapeAttr(attr.value) + '"';
339
+ }
340
+ s += '>';
341
+ if (voidElements[tagName]) {
342
+ return s;
343
+ }
344
+ return s + getInnerHTML(node, composed) + '</' + tagName + '>';
345
+ case Node.TEXT_NODE:
346
+ var data = node.data;
347
+ if (parentNode && plaintextParents[parentNode.localName]) {
348
+ return data;
349
+ }
350
+ return escapeData(data);
351
+ case Node.COMMENT_NODE:
352
+ return '<!--' + node.data + '-->';
353
+ default:
354
+ console.error(node);
355
+ throw new Error('not implemented');
356
+ }
357
+ }
358
+ function getInnerHTML(node, composed) {
359
+ if (node instanceof HTMLTemplateElement)
360
+ node = node.content;
361
+ var s = '';
362
+ var c$ = Polymer.dom(node).childNodes;
363
+ c$ = composed ? node._composedChildren : c$;
364
+ for (var i = 0, l = c$.length, child; i < l && (child = c$[i]); i++) {
365
+ s += getOuterHTML(child, node, composed);
366
+ }
367
+ return s;
368
+ }
369
+ return { getInnerHTML: getInnerHTML };
370
+ }();
371
+ Polymer.DomApi = function () {
372
+ 'use strict';
373
+ var Settings = Polymer.Settings;
374
+ var getInnerHTML = Polymer.domInnerHTML.getInnerHTML;
375
+ var nativeInsertBefore = Element.prototype.insertBefore;
376
+ var nativeRemoveChild = Element.prototype.removeChild;
377
+ var nativeAppendChild = Element.prototype.appendChild;
378
+ var nativeCloneNode = Element.prototype.cloneNode;
379
+ var nativeImportNode = Document.prototype.importNode;
380
+ var DomApi = function (node) {
381
+ this.node = node;
382
+ if (this.patch) {
383
+ this.patch();
384
+ }
385
+ };
386
+ if (window.wrap && Settings.useShadow && !Settings.useNativeShadow) {
387
+ DomApi = function (node) {
388
+ this.node = wrap(node);
389
+ if (this.patch) {
390
+ this.patch();
391
+ }
392
+ };
393
+ }
394
+ DomApi.prototype = {
395
+ flush: function () {
396
+ Polymer.dom.flush();
397
+ },
398
+ _lazyDistribute: function (host) {
399
+ if (host.shadyRoot && host.shadyRoot._distributionClean) {
400
+ host.shadyRoot._distributionClean = false;
401
+ Polymer.dom.addDebouncer(host.debounce('_distribute', host._distributeContent));
402
+ }
403
+ },
404
+ appendChild: function (node) {
405
+ return this._addNode(node);
406
+ },
407
+ insertBefore: function (node, ref_node) {
408
+ return this._addNode(node, ref_node);
409
+ },
410
+ _addNode: function (node, ref_node) {
411
+ this._removeNodeFromParent(node);
412
+ var addedInsertionPoint;
413
+ var root = this.getOwnerRoot();
414
+ if (root) {
415
+ addedInsertionPoint = this._maybeAddInsertionPoint(node, this.node);
416
+ }
417
+ if (this._nodeHasLogicalChildren(this.node)) {
418
+ if (ref_node) {
419
+ var children = this.childNodes;
420
+ var index = children.indexOf(ref_node);
421
+ if (index < 0) {
422
+ throw Error('The ref_node to be inserted before is not a child ' + 'of this node');
423
+ }
424
+ }
425
+ this._addLogicalInfo(node, this.node, index);
426
+ }
427
+ this._addNodeToHost(node);
428
+ if (!this._maybeDistribute(node, this.node) && !this._tryRemoveUndistributedNode(node)) {
429
+ if (ref_node) {
430
+ ref_node = ref_node.localName === CONTENT ? this._firstComposedNode(ref_node) : ref_node;
431
+ }
432
+ var container = this.node._isShadyRoot ? this.node.host : this.node;
433
+ addToComposedParent(container, node, ref_node);
434
+ if (ref_node) {
435
+ nativeInsertBefore.call(container, node, ref_node);
436
+ } else {
437
+ nativeAppendChild.call(container, node);
438
+ }
439
+ }
440
+ if (addedInsertionPoint) {
441
+ this._updateInsertionPoints(root.host);
442
+ }
443
+ this.notifyObserver();
444
+ return node;
445
+ },
446
+ removeChild: function (node) {
447
+ if (factory(node).parentNode !== this.node) {
448
+ console.warn('The node to be removed is not a child of this node', node);
449
+ }
450
+ this._removeNodeFromHost(node);
451
+ if (!this._maybeDistribute(node, this.node)) {
452
+ var container = this.node._isShadyRoot ? this.node.host : this.node;
453
+ if (container === node.parentNode) {
454
+ removeFromComposedParent(container, node);
455
+ nativeRemoveChild.call(container, node);
456
+ }
457
+ }
458
+ this.notifyObserver();
459
+ return node;
460
+ },
461
+ replaceChild: function (node, ref_node) {
462
+ this.insertBefore(node, ref_node);
463
+ this.removeChild(ref_node);
464
+ return node;
465
+ },
466
+ _hasCachedOwnerRoot: function (node) {
467
+ return Boolean(node._ownerShadyRoot !== undefined);
468
+ },
469
+ getOwnerRoot: function () {
470
+ return this._ownerShadyRootForNode(this.node);
471
+ },
472
+ _ownerShadyRootForNode: function (node) {
473
+ if (!node) {
474
+ return;
475
+ }
476
+ if (node._ownerShadyRoot === undefined) {
477
+ var root;
478
+ if (node._isShadyRoot) {
479
+ root = node;
480
+ } else {
481
+ var parent = Polymer.dom(node).parentNode;
482
+ if (parent) {
483
+ root = parent._isShadyRoot ? parent : this._ownerShadyRootForNode(parent);
484
+ } else {
485
+ root = null;
486
+ }
487
+ }
488
+ node._ownerShadyRoot = root;
489
+ }
490
+ return node._ownerShadyRoot;
491
+ },
492
+ _maybeDistribute: function (node, parent) {
493
+ var fragContent = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && !node.__noContent && Polymer.dom(node).querySelector(CONTENT);
494
+ var wrappedContent = fragContent && Polymer.dom(fragContent).parentNode.nodeType !== Node.DOCUMENT_FRAGMENT_NODE;
495
+ var hasContent = fragContent || node.localName === CONTENT;
496
+ if (hasContent) {
497
+ var root = this._ownerShadyRootForNode(parent);
498
+ if (root) {
499
+ var host = root.host;
500
+ this._lazyDistribute(host);
501
+ }
502
+ }
503
+ var parentNeedsDist = this._parentNeedsDistribution(parent);
504
+ if (parentNeedsDist) {
505
+ this._lazyDistribute(parent);
506
+ }
507
+ return parentNeedsDist || hasContent && !wrappedContent;
508
+ },
509
+ _maybeAddInsertionPoint: function (node, parent) {
510
+ var added;
511
+ if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && !node.__noContent) {
512
+ var c$ = factory(node).querySelectorAll(CONTENT);
513
+ for (var i = 0, n, np, na; i < c$.length && (n = c$[i]); i++) {
514
+ np = factory(n).parentNode;
515
+ if (np === node) {
516
+ np = parent;
517
+ }
518
+ na = this._maybeAddInsertionPoint(n, np);
519
+ added = added || na;
520
+ }
521
+ } else if (node.localName === CONTENT) {
522
+ saveLightChildrenIfNeeded(parent);
523
+ saveLightChildrenIfNeeded(node);
524
+ added = true;
525
+ }
526
+ return added;
527
+ },
528
+ _tryRemoveUndistributedNode: function (node) {
529
+ if (this.node.shadyRoot) {
530
+ var parent = getComposedParent(node);
531
+ if (parent) {
532
+ nativeRemoveChild.call(parent, node);
533
+ }
534
+ return true;
535
+ }
536
+ },
537
+ _updateInsertionPoints: function (host) {
538
+ var i$ = host.shadyRoot._insertionPoints = factory(host.shadyRoot).querySelectorAll(CONTENT);
539
+ for (var i = 0, c; i < i$.length; i++) {
540
+ c = i$[i];
541
+ saveLightChildrenIfNeeded(c);
542
+ saveLightChildrenIfNeeded(factory(c).parentNode);
543
+ }
544
+ },
545
+ _nodeHasLogicalChildren: function (node) {
546
+ return Boolean(node._lightChildren !== undefined);
547
+ },
548
+ _parentNeedsDistribution: function (parent) {
549
+ return parent && parent.shadyRoot && hasInsertionPoint(parent.shadyRoot);
550
+ },
551
+ _removeNodeFromParent: function (node) {
552
+ var parent = node._lightParent || node.parentNode;
553
+ if (parent && hasDomApi(parent)) {
554
+ factory(parent).notifyObserver();
555
+ }
556
+ this._removeNodeFromHost(node, true);
557
+ },
558
+ _removeNodeFromHost: function (node, ensureComposedRemoval) {
559
+ var hostNeedsDist;
560
+ var root;
561
+ var parent = node._lightParent;
562
+ if (parent) {
563
+ factory(node)._distributeParent();
564
+ root = this._ownerShadyRootForNode(node);
565
+ if (root) {
566
+ root.host._elementRemove(node);
567
+ hostNeedsDist = this._removeDistributedChildren(root, node);
568
+ }
569
+ this._removeLogicalInfo(node, parent);
570
+ }
571
+ this._removeOwnerShadyRoot(node);
572
+ if (root && hostNeedsDist) {
573
+ this._updateInsertionPoints(root.host);
574
+ this._lazyDistribute(root.host);
575
+ } else if (ensureComposedRemoval) {
576
+ removeFromComposedParent(getComposedParent(node), node);
577
+ }
578
+ },
579
+ _removeDistributedChildren: function (root, container) {
580
+ var hostNeedsDist;
581
+ var ip$ = root._insertionPoints;
582
+ for (var i = 0; i < ip$.length; i++) {
583
+ var content = ip$[i];
584
+ if (this._contains(container, content)) {
585
+ var dc$ = factory(content).getDistributedNodes();
586
+ for (var j = 0; j < dc$.length; j++) {
587
+ hostNeedsDist = true;
588
+ var node = dc$[j];
589
+ var parent = node.parentNode;
590
+ if (parent) {
591
+ removeFromComposedParent(parent, node);
592
+ nativeRemoveChild.call(parent, node);
593
+ }
594
+ }
595
+ }
596
+ }
597
+ return hostNeedsDist;
598
+ },
599
+ _contains: function (container, node) {
600
+ while (node) {
601
+ if (node == container) {
602
+ return true;
603
+ }
604
+ node = factory(node).parentNode;
605
+ }
606
+ },
607
+ _addNodeToHost: function (node) {
608
+ var root = this.getOwnerRoot();
609
+ if (root) {
610
+ root.host._elementAdd(node);
611
+ }
612
+ },
613
+ _addLogicalInfo: function (node, container, index) {
614
+ var children = factory(container).childNodes;
615
+ index = index === undefined ? children.length : index;
616
+ if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
617
+ var c$ = Array.prototype.slice.call(node.childNodes);
618
+ for (var i = 0, n; i < c$.length && (n = c$[i]); i++) {
619
+ children.splice(index++, 0, n);
620
+ n._lightParent = container;
621
+ }
622
+ } else {
623
+ children.splice(index, 0, node);
624
+ node._lightParent = container;
625
+ }
626
+ },
627
+ _removeLogicalInfo: function (node, container) {
628
+ var children = factory(container).childNodes;
629
+ var index = children.indexOf(node);
630
+ if (index < 0 || container !== node._lightParent) {
631
+ throw Error('The node to be removed is not a child of this node');
632
+ }
633
+ children.splice(index, 1);
634
+ node._lightParent = null;
635
+ },
636
+ _removeOwnerShadyRoot: function (node) {
637
+ if (this._hasCachedOwnerRoot(node)) {
638
+ var c$ = factory(node).childNodes;
639
+ for (var i = 0, l = c$.length, n; i < l && (n = c$[i]); i++) {
640
+ this._removeOwnerShadyRoot(n);
641
+ }
642
+ }
643
+ node._ownerShadyRoot = undefined;
644
+ },
645
+ _firstComposedNode: function (content) {
646
+ var n$ = factory(content).getDistributedNodes();
647
+ for (var i = 0, l = n$.length, n, p$; i < l && (n = n$[i]); i++) {
648
+ p$ = factory(n).getDestinationInsertionPoints();
649
+ if (p$[p$.length - 1] === content) {
650
+ return n;
651
+ }
652
+ }
653
+ },
654
+ querySelector: function (selector) {
655
+ return this.querySelectorAll(selector)[0];
656
+ },
657
+ querySelectorAll: function (selector) {
658
+ return this._query(function (n) {
659
+ return matchesSelector.call(n, selector);
660
+ }, this.node);
661
+ },
662
+ _query: function (matcher, node) {
663
+ node = node || this.node;
664
+ var list = [];
665
+ this._queryElements(factory(node).childNodes, matcher, list);
666
+ return list;
667
+ },
668
+ _queryElements: function (elements, matcher, list) {
669
+ for (var i = 0, l = elements.length, c; i < l && (c = elements[i]); i++) {
670
+ if (c.nodeType === Node.ELEMENT_NODE) {
671
+ this._queryElement(c, matcher, list);
672
+ }
673
+ }
674
+ },
675
+ _queryElement: function (node, matcher, list) {
676
+ if (matcher(node)) {
677
+ list.push(node);
678
+ }
679
+ this._queryElements(factory(node).childNodes, matcher, list);
680
+ },
681
+ getDestinationInsertionPoints: function () {
682
+ return this.node._destinationInsertionPoints || [];
683
+ },
684
+ getDistributedNodes: function () {
685
+ return this.node._distributedNodes || [];
686
+ },
687
+ queryDistributedElements: function (selector) {
688
+ var c$ = this.getEffectiveChildNodes();
689
+ var list = [];
690
+ for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) {
691
+ if (c.nodeType === Node.ELEMENT_NODE && matchesSelector.call(c, selector)) {
692
+ list.push(c);
693
+ }
694
+ }
695
+ return list;
696
+ },
697
+ getEffectiveChildNodes: function () {
698
+ var list = [];
699
+ var c$ = this.childNodes;
700
+ for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) {
701
+ if (c.localName === CONTENT) {
702
+ var d$ = factory(c).getDistributedNodes();
703
+ for (var j = 0; j < d$.length; j++) {
704
+ list.push(d$[j]);
705
+ }
706
+ } else {
707
+ list.push(c);
708
+ }
709
+ }
710
+ return list;
711
+ },
712
+ _clear: function () {
713
+ while (this.childNodes.length) {
714
+ this.removeChild(this.childNodes[0]);
715
+ }
716
+ },
717
+ setAttribute: function (name, value) {
718
+ this.node.setAttribute(name, value);
719
+ this._distributeParent();
720
+ },
721
+ removeAttribute: function (name) {
722
+ this.node.removeAttribute(name);
723
+ this._distributeParent();
724
+ },
725
+ _distributeParent: function () {
726
+ if (this._parentNeedsDistribution(this.parentNode)) {
727
+ this._lazyDistribute(this.parentNode);
728
+ }
729
+ },
730
+ cloneNode: function (deep) {
731
+ var n = nativeCloneNode.call(this.node, false);
732
+ if (deep) {
733
+ var c$ = this.childNodes;
734
+ var d = factory(n);
735
+ for (var i = 0, nc; i < c$.length; i++) {
736
+ nc = factory(c$[i]).cloneNode(true);
737
+ d.appendChild(nc);
738
+ }
739
+ }
740
+ return n;
741
+ },
742
+ importNode: function (externalNode, deep) {
743
+ var doc = this.node instanceof Document ? this.node : this.node.ownerDocument;
744
+ var n = nativeImportNode.call(doc, externalNode, false);
745
+ if (deep) {
746
+ var c$ = factory(externalNode).childNodes;
747
+ var d = factory(n);
748
+ for (var i = 0, nc; i < c$.length; i++) {
749
+ nc = factory(doc).importNode(c$[i], true);
750
+ d.appendChild(nc);
751
+ }
752
+ }
753
+ return n;
754
+ },
755
+ observeNodes: function (callback) {
756
+ if (callback) {
757
+ if (!this.observer) {
758
+ this.observer = this.node.localName === CONTENT ? new DomApi.DistributedNodesObserver(this) : new DomApi.EffectiveNodesObserver(this);
759
+ }
760
+ return this.observer.addListener(callback);
761
+ }
762
+ },
763
+ unobserveNodes: function (handle) {
764
+ if (this.observer) {
765
+ this.observer.removeListener(handle);
766
+ }
767
+ },
768
+ notifyObserver: function () {
769
+ if (this.observer) {
770
+ this.observer.notify();
771
+ }
772
+ }
773
+ };
774
+ if (!Settings.useShadow) {
775
+ Object.defineProperties(DomApi.prototype, {
776
+ childNodes: {
777
+ get: function () {
778
+ var c$ = getLightChildren(this.node);
779
+ return Array.isArray(c$) ? c$ : Array.prototype.slice.call(c$);
780
+ },
781
+ configurable: true
782
+ },
783
+ children: {
784
+ get: function () {
785
+ return Array.prototype.filter.call(this.childNodes, function (n) {
786
+ return n.nodeType === Node.ELEMENT_NODE;
787
+ });
788
+ },
789
+ configurable: true
790
+ },
791
+ parentNode: {
792
+ get: function () {
793
+ return this.node._lightParent || getComposedParent(this.node);
794
+ },
795
+ configurable: true
796
+ },
797
+ firstChild: {
798
+ get: function () {
799
+ return this.childNodes[0];
800
+ },
801
+ configurable: true
802
+ },
803
+ lastChild: {
804
+ get: function () {
805
+ var c$ = this.childNodes;
806
+ return c$[c$.length - 1];
807
+ },
808
+ configurable: true
809
+ },
810
+ nextSibling: {
811
+ get: function () {
812
+ var c$ = this.parentNode && factory(this.parentNode).childNodes;
813
+ if (c$) {
814
+ return c$[Array.prototype.indexOf.call(c$, this.node) + 1];
815
+ }
816
+ },
817
+ configurable: true
818
+ },
819
+ previousSibling: {
820
+ get: function () {
821
+ var c$ = this.parentNode && factory(this.parentNode).childNodes;
822
+ if (c$) {
823
+ return c$[Array.prototype.indexOf.call(c$, this.node) - 1];
824
+ }
825
+ },
826
+ configurable: true
827
+ },
828
+ firstElementChild: {
829
+ get: function () {
830
+ return this.children[0];
831
+ },
832
+ configurable: true
833
+ },
834
+ lastElementChild: {
835
+ get: function () {
836
+ var c$ = this.children;
837
+ return c$[c$.length - 1];
838
+ },
839
+ configurable: true
840
+ },
841
+ nextElementSibling: {
842
+ get: function () {
843
+ var c$ = this.parentNode && factory(this.parentNode).children;
844
+ if (c$) {
845
+ return c$[Array.prototype.indexOf.call(c$, this.node) + 1];
846
+ }
847
+ },
848
+ configurable: true
849
+ },
850
+ previousElementSibling: {
851
+ get: function () {
852
+ var c$ = this.parentNode && factory(this.parentNode).children;
853
+ if (c$) {
854
+ return c$[Array.prototype.indexOf.call(c$, this.node) - 1];
855
+ }
856
+ },
857
+ configurable: true
858
+ },
859
+ textContent: {
860
+ get: function () {
861
+ var nt = this.node.nodeType;
862
+ if (nt === Node.TEXT_NODE || nt === Node.COMMENT_NODE) {
863
+ return this.node.textContent;
864
+ } else {
865
+ var tc = [];
866
+ for (var i = 0, cn = this.childNodes, c; c = cn[i]; i++) {
867
+ if (c.nodeType !== Node.COMMENT_NODE) {
868
+ tc.push(c.textContent);
869
+ }
870
+ }
871
+ return tc.join('');
872
+ }
873
+ },
874
+ set: function (text) {
875
+ var nt = this.node.nodeType;
876
+ if (nt === Node.TEXT_NODE || nt === Node.COMMENT_NODE) {
877
+ this.node.textContent = text;
878
+ } else {
879
+ this._clear();
880
+ if (text) {
881
+ this.appendChild(document.createTextNode(text));
882
+ }
883
+ }
884
+ },
885
+ configurable: true
886
+ },
887
+ innerHTML: {
888
+ get: function () {
889
+ var nt = this.node.nodeType;
890
+ if (nt === Node.TEXT_NODE || nt === Node.COMMENT_NODE) {
891
+ return null;
892
+ } else {
893
+ return getInnerHTML(this.node);
894
+ }
895
+ },
896
+ set: function (text) {
897
+ var nt = this.node.nodeType;
898
+ if (nt !== Node.TEXT_NODE || nt !== Node.COMMENT_NODE) {
899
+ this._clear();
900
+ var d = document.createElement('div');
901
+ d.innerHTML = text;
902
+ var c$ = Array.prototype.slice.call(d.childNodes);
903
+ for (var i = 0; i < c$.length; i++) {
904
+ this.appendChild(c$[i]);
905
+ }
906
+ }
907
+ },
908
+ configurable: true
909
+ }
910
+ });
911
+ DomApi.prototype._getComposedInnerHTML = function () {
912
+ return getInnerHTML(this.node, true);
913
+ };
914
+ } else {
915
+ var forwardMethods = [
916
+ 'cloneNode',
917
+ 'appendChild',
918
+ 'insertBefore',
919
+ 'removeChild',
920
+ 'replaceChild'
921
+ ];
922
+ forwardMethods.forEach(function (name) {
923
+ DomApi.prototype[name] = function () {
924
+ return this.node[name].apply(this.node, arguments);
925
+ };
926
+ });
927
+ DomApi.prototype.querySelectorAll = function (selector) {
928
+ return Array.prototype.slice.call(this.node.querySelectorAll(selector));
929
+ };
930
+ DomApi.prototype.getOwnerRoot = function () {
931
+ var n = this.node;
932
+ while (n) {
933
+ if (n.nodeType === Node.DOCUMENT_FRAGMENT_NODE && n.host) {
934
+ return n;
935
+ }
936
+ n = n.parentNode;
937
+ }
938
+ };
939
+ DomApi.prototype.importNode = function (externalNode, deep) {
940
+ var doc = this.node instanceof Document ? this.node : this.node.ownerDocument;
941
+ return doc.importNode(externalNode, deep);
942
+ };
943
+ DomApi.prototype.getDestinationInsertionPoints = function () {
944
+ var n$ = this.node.getDestinationInsertionPoints && this.node.getDestinationInsertionPoints();
945
+ return n$ ? Array.prototype.slice.call(n$) : [];
946
+ };
947
+ DomApi.prototype.getDistributedNodes = function () {
948
+ var n$ = this.node.getDistributedNodes && this.node.getDistributedNodes();
949
+ return n$ ? Array.prototype.slice.call(n$) : [];
950
+ };
951
+ DomApi.prototype._distributeParent = function () {
952
+ };
953
+ var nativeForwards = [
954
+ 'appendChild',
955
+ 'insertBefore',
956
+ 'removeChild',
957
+ 'replaceChild'
958
+ ];
959
+ nativeForwards.forEach(function (forward) {
960
+ DomApi.prototype[forward] = function () {
961
+ return this.node[forward].apply(this.node, arguments);
962
+ };
963
+ });
964
+ Object.defineProperties(DomApi.prototype, {
965
+ childNodes: {
966
+ get: function () {
967
+ return Array.prototype.slice.call(this.node.childNodes);
968
+ },
969
+ configurable: true
970
+ },
971
+ children: {
972
+ get: function () {
973
+ return Array.prototype.slice.call(this.node.children);
974
+ },
975
+ configurable: true
976
+ },
977
+ textContent: {
978
+ get: function () {
979
+ return this.node.textContent;
980
+ },
981
+ set: function (value) {
982
+ return this.node.textContent = value;
983
+ },
984
+ configurable: true
985
+ },
986
+ innerHTML: {
987
+ get: function () {
988
+ return this.node.innerHTML;
989
+ },
990
+ set: function (value) {
991
+ return this.node.innerHTML = value;
992
+ },
993
+ configurable: true
994
+ }
995
+ });
996
+ var forwardProperties = [
997
+ 'parentNode',
998
+ 'firstChild',
999
+ 'lastChild',
1000
+ 'nextSibling',
1001
+ 'previousSibling',
1002
+ 'firstElementChild',
1003
+ 'lastElementChild',
1004
+ 'nextElementSibling',
1005
+ 'previousElementSibling'
1006
+ ];
1007
+ forwardProperties.forEach(function (name) {
1008
+ Object.defineProperty(DomApi.prototype, name, {
1009
+ get: function () {
1010
+ return this.node[name];
1011
+ },
1012
+ configurable: true
1013
+ });
1014
+ });
1015
+ }
1016
+ var CONTENT = 'content';
1017
+ function factory(node, patch) {
1018
+ node = node || document;
1019
+ if (!node.__domApi) {
1020
+ node.__domApi = new DomApi(node, patch);
1021
+ }
1022
+ return node.__domApi;
1023
+ }
1024
+ ;
1025
+ function hasDomApi(node) {
1026
+ return Boolean(node.__domApi);
1027
+ }
1028
+ Polymer.dom = function (obj, patch) {
1029
+ if (obj instanceof Event) {
1030
+ return Polymer.EventApi.factory(obj);
1031
+ } else {
1032
+ return factory(obj, patch);
1033
+ }
1034
+ };
1035
+ function getLightChildren(node) {
1036
+ var children = node._lightChildren;
1037
+ return children ? children : node.childNodes;
1038
+ }
1039
+ function getComposedChildren(node) {
1040
+ if (!node._composedChildren) {
1041
+ node._composedChildren = Array.prototype.slice.call(node.childNodes);
1042
+ }
1043
+ return node._composedChildren;
1044
+ }
1045
+ function addToComposedParent(parent, node, ref_node) {
1046
+ var children = getComposedChildren(parent);
1047
+ var i = ref_node ? children.indexOf(ref_node) : -1;
1048
+ if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
1049
+ var fragChildren = getComposedChildren(node);
1050
+ for (var j = 0; j < fragChildren.length; j++) {
1051
+ addNodeToComposedChildren(fragChildren[j], parent, children, i + j);
1052
+ }
1053
+ node._composedChildren = null;
1054
+ } else {
1055
+ addNodeToComposedChildren(node, parent, children, i);
1056
+ }
1057
+ }
1058
+ function getComposedParent(node) {
1059
+ return node.__patched ? node._composedParent : node.parentNode;
1060
+ }
1061
+ function addNodeToComposedChildren(node, parent, children, i) {
1062
+ node._composedParent = parent;
1063
+ children.splice(i >= 0 ? i : children.length, 0, node);
1064
+ }
1065
+ function removeFromComposedParent(parent, node) {
1066
+ node._composedParent = null;
1067
+ if (parent) {
1068
+ var children = getComposedChildren(parent);
1069
+ var i = children.indexOf(node);
1070
+ if (i >= 0) {
1071
+ children.splice(i, 1);
1072
+ }
1073
+ }
1074
+ }
1075
+ function saveLightChildrenIfNeeded(node) {
1076
+ if (!node._lightChildren) {
1077
+ var c$ = Array.prototype.slice.call(node.childNodes);
1078
+ for (var i = 0, l = c$.length, child; i < l && (child = c$[i]); i++) {
1079
+ child._lightParent = child._lightParent || node;
1080
+ }
1081
+ node._lightChildren = c$;
1082
+ }
1083
+ }
1084
+ function hasInsertionPoint(root) {
1085
+ return Boolean(root && root._insertionPoints.length);
1086
+ }
1087
+ var p = Element.prototype;
1088
+ var matchesSelector = p.matches || p.matchesSelector || p.mozMatchesSelector || p.msMatchesSelector || p.oMatchesSelector || p.webkitMatchesSelector;
1089
+ return {
1090
+ getLightChildren: getLightChildren,
1091
+ getComposedParent: getComposedParent,
1092
+ getComposedChildren: getComposedChildren,
1093
+ removeFromComposedParent: removeFromComposedParent,
1094
+ saveLightChildrenIfNeeded: saveLightChildrenIfNeeded,
1095
+ matchesSelector: matchesSelector,
1096
+ hasInsertionPoint: hasInsertionPoint,
1097
+ ctor: DomApi,
1098
+ factory: factory,
1099
+ hasDomApi: hasDomApi
1100
+ };
1101
+ }();
1102
+ Polymer.Base.extend(Polymer.dom, {
1103
+ _flushGuard: 0,
1104
+ _FLUSH_MAX: 100,
1105
+ _needsTakeRecords: !Polymer.Settings.useNativeCustomElements,
1106
+ _debouncers: [],
1107
+ _staticFlushList: [],
1108
+ _finishDebouncer: null,
1109
+ flush: function () {
1110
+ this._flushGuard = 0;
1111
+ this._prepareFlush();
1112
+ while (this._debouncers.length && this._flushGuard < this._FLUSH_MAX) {
1113
+ for (var i = 0; i < this._debouncers.length; i++) {
1114
+ this._debouncers[i].complete();
1115
+ }
1116
+ if (this._finishDebouncer) {
1117
+ this._finishDebouncer.complete();
1118
+ }
1119
+ this._prepareFlush();
1120
+ this._flushGuard++;
1121
+ }
1122
+ if (this._flushGuard >= this._FLUSH_MAX) {
1123
+ console.warn('Polymer.dom.flush aborted. Flush may not be complete.');
1124
+ }
1125
+ },
1126
+ _prepareFlush: function () {
1127
+ if (this._needsTakeRecords) {
1128
+ CustomElements.takeRecords();
1129
+ }
1130
+ for (var i = 0; i < this._staticFlushList.length; i++) {
1131
+ this._staticFlushList[i]();
1132
+ }
1133
+ },
1134
+ addStaticFlush: function (fn) {
1135
+ this._staticFlushList.push(fn);
1136
+ },
1137
+ removeStaticFlush: function (fn) {
1138
+ var i = this._staticFlushList.indexOf(fn);
1139
+ if (i >= 0) {
1140
+ this._staticFlushList.splice(i, 1);
1141
+ }
1142
+ },
1143
+ addDebouncer: function (debouncer) {
1144
+ this._debouncers.push(debouncer);
1145
+ this._finishDebouncer = Polymer.Debounce(this._finishDebouncer, this._finishFlush);
1146
+ },
1147
+ _finishFlush: function () {
1148
+ Polymer.dom._debouncers = [];
1149
+ }
1150
+ });
1151
+ Polymer.EventApi = function () {
1152
+ 'use strict';
1153
+ var DomApi = Polymer.DomApi.ctor;
1154
+ var Settings = Polymer.Settings;
1155
+ DomApi.Event = function (event) {
1156
+ this.event = event;
1157
+ };
1158
+ if (Settings.useShadow) {
1159
+ DomApi.Event.prototype = {
1160
+ get rootTarget() {
1161
+ return this.event.path[0];
1162
+ },
1163
+ get localTarget() {
1164
+ return this.event.target;
1165
+ },
1166
+ get path() {
1167
+ return this.event.path;
1168
+ }
1169
+ };
1170
+ } else {
1171
+ DomApi.Event.prototype = {
1172
+ get rootTarget() {
1173
+ return this.event.target;
1174
+ },
1175
+ get localTarget() {
1176
+ var current = this.event.currentTarget;
1177
+ var currentRoot = current && Polymer.dom(current).getOwnerRoot();
1178
+ var p$ = this.path;
1179
+ for (var i = 0; i < p$.length; i++) {
1180
+ if (Polymer.dom(p$[i]).getOwnerRoot() === currentRoot) {
1181
+ return p$[i];
1182
+ }
1183
+ }
1184
+ },
1185
+ get path() {
1186
+ if (!this.event._path) {
1187
+ var path = [];
1188
+ var o = this.rootTarget;
1189
+ while (o) {
1190
+ path.push(o);
1191
+ o = Polymer.dom(o).parentNode || o.host;
1192
+ }
1193
+ path.push(window);
1194
+ this.event._path = path;
1195
+ }
1196
+ return this.event._path;
1197
+ }
1198
+ };
1199
+ }
1200
+ var factory = function (event) {
1201
+ if (!event.__eventApi) {
1202
+ event.__eventApi = new DomApi.Event(event);
1203
+ }
1204
+ return event.__eventApi;
1205
+ };
1206
+ return { factory: factory };
1207
+ }();
1208
+ (function () {
1209
+ 'use strict';
1210
+ var DomApi = Polymer.DomApi.ctor;
1211
+ Object.defineProperty(DomApi.prototype, 'classList', {
1212
+ get: function () {
1213
+ if (!this._classList) {
1214
+ this._classList = new DomApi.ClassList(this);
1215
+ }
1216
+ return this._classList;
1217
+ },
1218
+ configurable: true
1219
+ });
1220
+ DomApi.ClassList = function (host) {
1221
+ this.domApi = host;
1222
+ this.node = host.node;
1223
+ };
1224
+ DomApi.ClassList.prototype = {
1225
+ add: function () {
1226
+ this.node.classList.add.apply(this.node.classList, arguments);
1227
+ this.domApi._distributeParent();
1228
+ },
1229
+ remove: function () {
1230
+ this.node.classList.remove.apply(this.node.classList, arguments);
1231
+ this.domApi._distributeParent();
1232
+ },
1233
+ toggle: function () {
1234
+ this.node.classList.toggle.apply(this.node.classList, arguments);
1235
+ this.domApi._distributeParent();
1236
+ },
1237
+ contains: function () {
1238
+ return this.node.classList.contains.apply(this.node.classList, arguments);
1239
+ }
1240
+ };
1241
+ }());
1242
+ (function () {
1243
+ 'use strict';
1244
+ var DomApi = Polymer.DomApi.ctor;
1245
+ var Settings = Polymer.Settings;
1246
+ var hasDomApi = Polymer.DomApi.hasDomApi;
1247
+ DomApi.EffectiveNodesObserver = function (domApi) {
1248
+ this.domApi = domApi;
1249
+ this.node = this.domApi.node;
1250
+ this._listeners = [];
1251
+ };
1252
+ DomApi.EffectiveNodesObserver.prototype = {
1253
+ addListener: function (callback) {
1254
+ if (!this._isSetup) {
1255
+ this._setup();
1256
+ this._isSetup = true;
1257
+ }
1258
+ var listener = {
1259
+ fn: callback,
1260
+ _nodes: []
1261
+ };
1262
+ this._listeners.push(listener);
1263
+ this._scheduleNotify();
1264
+ return listener;
1265
+ },
1266
+ removeListener: function (handle) {
1267
+ var i = this._listeners.indexOf(handle);
1268
+ if (i >= 0) {
1269
+ this._listeners.splice(i, 1);
1270
+ handle._nodes = [];
1271
+ }
1272
+ if (!this._hasListeners()) {
1273
+ this._cleanup();
1274
+ this._isSetup = false;
1275
+ }
1276
+ },
1277
+ _setup: function () {
1278
+ this._observeContentElements(this.domApi.childNodes);
1279
+ },
1280
+ _cleanup: function () {
1281
+ this._unobserveContentElements(this.domApi.childNodes);
1282
+ },
1283
+ _hasListeners: function () {
1284
+ return Boolean(this._listeners.length);
1285
+ },
1286
+ _scheduleNotify: function () {
1287
+ if (this._debouncer) {
1288
+ this._debouncer.stop();
1289
+ }
1290
+ this._debouncer = Polymer.Debounce(this._debouncer, this._notify);
1291
+ this._debouncer.context = this;
1292
+ Polymer.dom.addDebouncer(this._debouncer);
1293
+ },
1294
+ notify: function () {
1295
+ if (this._hasListeners()) {
1296
+ this._scheduleNotify();
1297
+ }
1298
+ },
1299
+ _notify: function (mxns) {
1300
+ this._beforeCallListeners();
1301
+ this._callListeners();
1302
+ },
1303
+ _beforeCallListeners: function () {
1304
+ this._updateContentElements();
1305
+ },
1306
+ _updateContentElements: function () {
1307
+ this._observeContentElements(this.domApi.childNodes);
1308
+ },
1309
+ _observeContentElements: function (elements) {
1310
+ for (var i = 0, n; i < elements.length && (n = elements[i]); i++) {
1311
+ if (this._isContent(n)) {
1312
+ n.__observeNodesMap = n.__observeNodesMap || new WeakMap();
1313
+ if (!n.__observeNodesMap.has(this)) {
1314
+ n.__observeNodesMap.set(this, this._observeContent(n));
1315
+ }
1316
+ }
1317
+ }
1318
+ },
1319
+ _observeContent: function (content) {
1320
+ var h = Polymer.dom(content).observeNodes(this._scheduleNotify.bind(this));
1321
+ h._avoidChangeCalculation = true;
1322
+ return h;
1323
+ },
1324
+ _unobserveContentElements: function (elements) {
1325
+ for (var i = 0, n, h; i < elements.length && (n = elements[i]); i++) {
1326
+ if (this._isContent(n)) {
1327
+ h = n.__observeNodesMap.get(this);
1328
+ if (h) {
1329
+ Polymer.dom(n).unobserveNodes(h);
1330
+ n.__observeNodesMap.delete(this);
1331
+ }
1332
+ }
1333
+ }
1334
+ },
1335
+ _isContent: function (node) {
1336
+ return node.localName === 'content';
1337
+ },
1338
+ _callListeners: function () {
1339
+ var o$ = this._listeners;
1340
+ var nodes = this._getEffectiveNodes();
1341
+ for (var i = 0, o; i < o$.length && (o = o$[i]); i++) {
1342
+ var info = this._generateListenerInfo(o, nodes);
1343
+ if (info || o._alwaysNotify) {
1344
+ this._callListener(o, info);
1345
+ }
1346
+ }
1347
+ },
1348
+ _getEffectiveNodes: function () {
1349
+ return this.domApi.getEffectiveChildNodes();
1350
+ },
1351
+ _generateListenerInfo: function (listener, newNodes) {
1352
+ if (listener._avoidChangeCalculation) {
1353
+ return true;
1354
+ }
1355
+ var oldNodes = listener._nodes;
1356
+ var info = {
1357
+ target: this.node,
1358
+ addedNodes: [],
1359
+ removedNodes: []
1360
+ };
1361
+ var splices = Polymer.ArraySplice.calculateSplices(newNodes, oldNodes);
1362
+ for (var i = 0, s; i < splices.length && (s = splices[i]); i++) {
1363
+ for (var j = 0, n; j < s.removed.length && (n = s.removed[j]); j++) {
1364
+ info.removedNodes.push(n);
1365
+ }
1366
+ }
1367
+ for (var i = 0, s; i < splices.length && (s = splices[i]); i++) {
1368
+ for (var j = s.index; j < s.index + s.addedCount; j++) {
1369
+ info.addedNodes.push(newNodes[j]);
1370
+ }
1371
+ }
1372
+ listener._nodes = newNodes;
1373
+ if (info.addedNodes.length || info.removedNodes.length) {
1374
+ return info;
1375
+ }
1376
+ },
1377
+ _callListener: function (listener, info) {
1378
+ return listener.fn.call(this.node, info);
1379
+ },
1380
+ enableShadowAttributeTracking: function () {
1381
+ }
1382
+ };
1383
+ if (Settings.useShadow) {
1384
+ var baseSetup = DomApi.EffectiveNodesObserver.prototype._setup;
1385
+ var baseCleanup = DomApi.EffectiveNodesObserver.prototype._cleanup;
1386
+ var beforeCallListeners = DomApi.EffectiveNodesObserver.prototype._beforeCallListeners;
1387
+ Polymer.Base.extend(DomApi.EffectiveNodesObserver.prototype, {
1388
+ _setup: function () {
1389
+ if (!this._observer) {
1390
+ var self = this;
1391
+ this._mutationHandler = function (mxns) {
1392
+ if (mxns && mxns.length) {
1393
+ self._scheduleNotify();
1394
+ }
1395
+ };
1396
+ this._observer = new MutationObserver(this._mutationHandler);
1397
+ this._boundFlush = this._flush.bind(this);
1398
+ Polymer.dom.addStaticFlush(this._boundFlush);
1399
+ this._observer.observe(this.node, { childList: true });
1400
+ }
1401
+ baseSetup.call(this);
1402
+ },
1403
+ _cleanup: function () {
1404
+ this._observer.disconnect();
1405
+ this._observer = null;
1406
+ this._mutationHandler = null;
1407
+ Polymer.dom.removeStaticFlush(this._boundFlush);
1408
+ baseCleanup.call(this);
1409
+ },
1410
+ _flush: function () {
1411
+ if (this._observer) {
1412
+ this._mutationHandler(this._observer.takeRecords());
1413
+ }
1414
+ },
1415
+ enableShadowAttributeTracking: function () {
1416
+ if (this._observer) {
1417
+ this._makeContentListenersAlwaysNotify();
1418
+ this._observer.disconnect();
1419
+ this._observer.observe(this.node, {
1420
+ childList: true,
1421
+ attributes: true,
1422
+ subtree: true
1423
+ });
1424
+ var root = this.domApi.getOwnerRoot();
1425
+ var host = root && root.host;
1426
+ if (host && Polymer.dom(host).observer) {
1427
+ Polymer.dom(host).observer.enableShadowAttributeTracking();
1428
+ }
1429
+ }
1430
+ },
1431
+ _makeContentListenersAlwaysNotify: function () {
1432
+ for (var i = 0, h; i < this._listeners.length; i++) {
1433
+ h = this._listeners[i];
1434
+ h._alwaysNotify = h._isContentListener;
1435
+ }
1436
+ }
1437
+ });
1438
+ }
1439
+ }());
1440
+ (function () {
1441
+ 'use strict';
1442
+ var DomApi = Polymer.DomApi.ctor;
1443
+ var Settings = Polymer.Settings;
1444
+ DomApi.DistributedNodesObserver = function (domApi) {
1445
+ DomApi.EffectiveNodesObserver.call(this, domApi);
1446
+ };
1447
+ DomApi.DistributedNodesObserver.prototype = Object.create(DomApi.EffectiveNodesObserver.prototype);
1448
+ Polymer.Base.extend(DomApi.DistributedNodesObserver.prototype, {
1449
+ _setup: function () {
1450
+ },
1451
+ _cleanup: function () {
1452
+ },
1453
+ _beforeCallListeners: function () {
1454
+ },
1455
+ _getEffectiveNodes: function () {
1456
+ return this.domApi.getDistributedNodes();
1457
+ }
1458
+ });
1459
+ if (Settings.useShadow) {
1460
+ Polymer.Base.extend(DomApi.DistributedNodesObserver.prototype, {
1461
+ _setup: function () {
1462
+ if (!this._observer) {
1463
+ var root = this.domApi.getOwnerRoot();
1464
+ var host = root && root.host;
1465
+ if (host) {
1466
+ this._observer = Polymer.dom(host).observeNodes(this._scheduleNotify.bind(this));
1467
+ this._observer._isContentListener = true;
1468
+ if (this._hasAttrSelect()) {
1469
+ Polymer.dom(host).observer.enableShadowAttributeTracking();
1470
+ }
1471
+ }
1472
+ }
1473
+ },
1474
+ _hasAttrSelect: function () {
1475
+ var select = this.node.getAttribute('select');
1476
+ return select && select.match(/[[.]+/);
1477
+ },
1478
+ _cleanup: function () {
1479
+ var root = this.domApi.getOwnerRoot();
1480
+ var host = root && root.host;
1481
+ if (host) {
1482
+ Polymer.dom(host).unobserveNodes(this._observer);
1483
+ }
1484
+ this._observer = null;
1485
+ }
1486
+ });
1487
+ }
1488
+ }());
1489
+ (function () {
1490
+ var hasDomApi = Polymer.DomApi.hasDomApi;
1491
+ Polymer.Base._addFeature({
1492
+ _prepShady: function () {
1493
+ this._useContent = this._useContent || Boolean(this._template);
1494
+ },
1495
+ _poolContent: function () {
1496
+ if (this._useContent) {
1497
+ saveLightChildrenIfNeeded(this);
1498
+ }
1499
+ },
1500
+ _setupRoot: function () {
1501
+ if (this._useContent) {
1502
+ this._createLocalRoot();
1503
+ if (!this.dataHost) {
1504
+ upgradeLightChildren(this._lightChildren);
1505
+ }
1506
+ }
1507
+ },
1508
+ _createLocalRoot: function () {
1509
+ this.shadyRoot = this.root;
1510
+ this.shadyRoot._distributionClean = false;
1511
+ this.shadyRoot._isShadyRoot = true;
1512
+ this.shadyRoot._dirtyRoots = [];
1513
+ var i$ = this.shadyRoot._insertionPoints = !this._notes || this._notes._hasContent ? this.shadyRoot.querySelectorAll('content') : [];
1514
+ saveLightChildrenIfNeeded(this.shadyRoot);
1515
+ for (var i = 0, c; i < i$.length; i++) {
1516
+ c = i$[i];
1517
+ saveLightChildrenIfNeeded(c);
1518
+ saveLightChildrenIfNeeded(c.parentNode);
1519
+ }
1520
+ this.shadyRoot.host = this;
1521
+ },
1522
+ get domHost() {
1523
+ var root = Polymer.dom(this).getOwnerRoot();
1524
+ return root && root.host;
1525
+ },
1526
+ distributeContent: function (updateInsertionPoints) {
1527
+ if (this.shadyRoot) {
1528
+ var dom = Polymer.dom(this);
1529
+ if (updateInsertionPoints) {
1530
+ dom._updateInsertionPoints(this);
1531
+ }
1532
+ var host = getTopDistributingHost(this);
1533
+ dom._lazyDistribute(host);
1534
+ }
1535
+ },
1536
+ _distributeContent: function () {
1537
+ if (this._useContent && !this.shadyRoot._distributionClean) {
1538
+ this._beginDistribute();
1539
+ this._distributeDirtyRoots();
1540
+ this._finishDistribute();
1541
+ }
1542
+ },
1543
+ _beginDistribute: function () {
1544
+ if (this._useContent && hasInsertionPoint(this.shadyRoot)) {
1545
+ this._resetDistribution();
1546
+ this._distributePool(this.shadyRoot, this._collectPool());
1547
+ }
1548
+ },
1549
+ _distributeDirtyRoots: function () {
1550
+ var c$ = this.shadyRoot._dirtyRoots;
1551
+ for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) {
1552
+ c._distributeContent();
1553
+ }
1554
+ this.shadyRoot._dirtyRoots = [];
1555
+ },
1556
+ _finishDistribute: function () {
1557
+ if (this._useContent) {
1558
+ this.shadyRoot._distributionClean = true;
1559
+ if (hasInsertionPoint(this.shadyRoot)) {
1560
+ this._composeTree();
1561
+ notifyContentObservers(this.shadyRoot);
1562
+ } else {
1563
+ if (!this.shadyRoot._hasDistributed) {
1564
+ this.textContent = '';
1565
+ this._composedChildren = null;
1566
+ this.appendChild(this.shadyRoot);
1567
+ } else {
1568
+ var children = this._composeNode(this);
1569
+ this._updateChildNodes(this, children);
1570
+ }
1571
+ }
1572
+ if (!this.shadyRoot._hasDistributed) {
1573
+ notifyInitialDistribution(this);
1574
+ }
1575
+ this.shadyRoot._hasDistributed = true;
1576
+ }
1577
+ },
1578
+ elementMatches: function (selector, node) {
1579
+ node = node || this;
1580
+ return matchesSelector.call(node, selector);
1581
+ },
1582
+ _resetDistribution: function () {
1583
+ var children = getLightChildren(this);
1584
+ for (var i = 0; i < children.length; i++) {
1585
+ var child = children[i];
1586
+ if (child._destinationInsertionPoints) {
1587
+ child._destinationInsertionPoints = undefined;
1588
+ }
1589
+ if (isInsertionPoint(child)) {
1590
+ clearDistributedDestinationInsertionPoints(child);
1591
+ }
1592
+ }
1593
+ var root = this.shadyRoot;
1594
+ var p$ = root._insertionPoints;
1595
+ for (var j = 0; j < p$.length; j++) {
1596
+ p$[j]._distributedNodes = [];
1597
+ }
1598
+ },
1599
+ _collectPool: function () {
1600
+ var pool = [];
1601
+ var children = getLightChildren(this);
1602
+ for (var i = 0; i < children.length; i++) {
1603
+ var child = children[i];
1604
+ if (isInsertionPoint(child)) {
1605
+ pool.push.apply(pool, child._distributedNodes);
1606
+ } else {
1607
+ pool.push(child);
1608
+ }
1609
+ }
1610
+ return pool;
1611
+ },
1612
+ _distributePool: function (node, pool) {
1613
+ var p$ = node._insertionPoints;
1614
+ for (var i = 0, l = p$.length, p; i < l && (p = p$[i]); i++) {
1615
+ this._distributeInsertionPoint(p, pool);
1616
+ maybeRedistributeParent(p, this);
1617
+ }
1618
+ },
1619
+ _distributeInsertionPoint: function (content, pool) {
1620
+ var anyDistributed = false;
1621
+ for (var i = 0, l = pool.length, node; i < l; i++) {
1622
+ node = pool[i];
1623
+ if (!node) {
1624
+ continue;
1625
+ }
1626
+ if (this._matchesContentSelect(node, content)) {
1627
+ distributeNodeInto(node, content);
1628
+ pool[i] = undefined;
1629
+ anyDistributed = true;
1630
+ }
1631
+ }
1632
+ if (!anyDistributed) {
1633
+ var children = getLightChildren(content);
1634
+ for (var j = 0; j < children.length; j++) {
1635
+ distributeNodeInto(children[j], content);
1636
+ }
1637
+ }
1638
+ },
1639
+ _composeTree: function () {
1640
+ this._updateChildNodes(this, this._composeNode(this));
1641
+ var p$ = this.shadyRoot._insertionPoints;
1642
+ for (var i = 0, l = p$.length, p, parent; i < l && (p = p$[i]); i++) {
1643
+ parent = p._lightParent || p.parentNode;
1644
+ if (!parent._useContent && parent !== this && parent !== this.shadyRoot) {
1645
+ this._updateChildNodes(parent, this._composeNode(parent));
1646
+ }
1647
+ }
1648
+ },
1649
+ _composeNode: function (node) {
1650
+ var children = [];
1651
+ var c$ = getLightChildren(node.shadyRoot || node);
1652
+ for (var i = 0; i < c$.length; i++) {
1653
+ var child = c$[i];
1654
+ if (isInsertionPoint(child)) {
1655
+ var distributedNodes = child._distributedNodes;
1656
+ for (var j = 0; j < distributedNodes.length; j++) {
1657
+ var distributedNode = distributedNodes[j];
1658
+ if (isFinalDestination(child, distributedNode)) {
1659
+ children.push(distributedNode);
1660
+ }
1661
+ }
1662
+ } else {
1663
+ children.push(child);
1664
+ }
1665
+ }
1666
+ return children;
1667
+ },
1668
+ _updateChildNodes: function (container, children) {
1669
+ var composed = getComposedChildren(container);
1670
+ var splices = Polymer.ArraySplice.calculateSplices(children, composed);
1671
+ for (var i = 0, d = 0, s; i < splices.length && (s = splices[i]); i++) {
1672
+ for (var j = 0, n; j < s.removed.length && (n = s.removed[j]); j++) {
1673
+ if (getComposedParent(n) === container) {
1674
+ remove(n);
1675
+ }
1676
+ composed.splice(s.index + d, 1);
1677
+ }
1678
+ d -= s.addedCount;
1679
+ }
1680
+ for (var i = 0, s, next; i < splices.length && (s = splices[i]); i++) {
1681
+ next = composed[s.index];
1682
+ for (var j = s.index, n; j < s.index + s.addedCount; j++) {
1683
+ n = children[j];
1684
+ insertBefore(container, n, next);
1685
+ composed.splice(j, 0, n);
1686
+ }
1687
+ }
1688
+ ensureComposedParent(container, children);
1689
+ },
1690
+ _matchesContentSelect: function (node, contentElement) {
1691
+ var select = contentElement.getAttribute('select');
1692
+ if (!select) {
1693
+ return true;
1694
+ }
1695
+ select = select.trim();
1696
+ if (!select) {
1697
+ return true;
1698
+ }
1699
+ if (!(node instanceof Element)) {
1700
+ return false;
1701
+ }
1702
+ var validSelectors = /^(:not\()?[*.#[a-zA-Z_|]/;
1703
+ if (!validSelectors.test(select)) {
1704
+ return false;
1705
+ }
1706
+ return this.elementMatches(select, node);
1707
+ },
1708
+ _elementAdd: function () {
1709
+ },
1710
+ _elementRemove: function () {
1711
+ }
1712
+ });
1713
+ var saveLightChildrenIfNeeded = Polymer.DomApi.saveLightChildrenIfNeeded;
1714
+ var getLightChildren = Polymer.DomApi.getLightChildren;
1715
+ var matchesSelector = Polymer.DomApi.matchesSelector;
1716
+ var hasInsertionPoint = Polymer.DomApi.hasInsertionPoint;
1717
+ var getComposedChildren = Polymer.DomApi.getComposedChildren;
1718
+ var getComposedParent = Polymer.DomApi.getComposedParent;
1719
+ var removeFromComposedParent = Polymer.DomApi.removeFromComposedParent;
1720
+ function distributeNodeInto(child, insertionPoint) {
1721
+ insertionPoint._distributedNodes.push(child);
1722
+ var points = child._destinationInsertionPoints;
1723
+ if (!points) {
1724
+ child._destinationInsertionPoints = [insertionPoint];
1725
+ } else {
1726
+ points.push(insertionPoint);
1727
+ }
1728
+ }
1729
+ function clearDistributedDestinationInsertionPoints(content) {
1730
+ var e$ = content._distributedNodes;
1731
+ if (e$) {
1732
+ for (var i = 0; i < e$.length; i++) {
1733
+ var d = e$[i]._destinationInsertionPoints;
1734
+ if (d) {
1735
+ d.splice(d.indexOf(content) + 1, d.length);
1736
+ }
1737
+ }
1738
+ }
1739
+ }
1740
+ function maybeRedistributeParent(content, host) {
1741
+ var parent = content._lightParent;
1742
+ if (parent && parent.shadyRoot && hasInsertionPoint(parent.shadyRoot) && parent.shadyRoot._distributionClean) {
1743
+ parent.shadyRoot._distributionClean = false;
1744
+ host.shadyRoot._dirtyRoots.push(parent);
1745
+ }
1746
+ }
1747
+ function isFinalDestination(insertionPoint, node) {
1748
+ var points = node._destinationInsertionPoints;
1749
+ return points && points[points.length - 1] === insertionPoint;
1750
+ }
1751
+ function isInsertionPoint(node) {
1752
+ return node.localName == 'content';
1753
+ }
1754
+ var nativeInsertBefore = Element.prototype.insertBefore;
1755
+ var nativeRemoveChild = Element.prototype.removeChild;
1756
+ function insertBefore(parentNode, newChild, refChild) {
1757
+ var newChildParent = getComposedParent(newChild);
1758
+ if (newChildParent !== parentNode) {
1759
+ removeFromComposedParent(newChildParent, newChild);
1760
+ }
1761
+ remove(newChild);
1762
+ nativeInsertBefore.call(parentNode, newChild, refChild || null);
1763
+ newChild._composedParent = parentNode;
1764
+ }
1765
+ function remove(node) {
1766
+ var parentNode = getComposedParent(node);
1767
+ if (parentNode) {
1768
+ node._composedParent = null;
1769
+ nativeRemoveChild.call(parentNode, node);
1770
+ }
1771
+ }
1772
+ function ensureComposedParent(parent, children) {
1773
+ for (var i = 0, n; i < children.length; i++) {
1774
+ children[i]._composedParent = parent;
1775
+ }
1776
+ }
1777
+ function getTopDistributingHost(host) {
1778
+ while (host && hostNeedsRedistribution(host)) {
1779
+ host = host.domHost;
1780
+ }
1781
+ return host;
1782
+ }
1783
+ function hostNeedsRedistribution(host) {
1784
+ var c$ = Polymer.dom(host).children;
1785
+ for (var i = 0, c; i < c$.length; i++) {
1786
+ c = c$[i];
1787
+ if (c.localName === 'content') {
1788
+ return host.domHost;
1789
+ }
1790
+ }
1791
+ }
1792
+ function notifyContentObservers(root) {
1793
+ for (var i = 0, c; i < root._insertionPoints.length; i++) {
1794
+ c = root._insertionPoints[i];
1795
+ if (hasDomApi(c)) {
1796
+ Polymer.dom(c).notifyObserver();
1797
+ }
1798
+ }
1799
+ }
1800
+ function notifyInitialDistribution(host) {
1801
+ if (hasDomApi(host)) {
1802
+ Polymer.dom(host).notifyObserver();
1803
+ }
1804
+ }
1805
+ var needsUpgrade = window.CustomElements && !CustomElements.useNative;
1806
+ function upgradeLightChildren(children) {
1807
+ if (needsUpgrade && children) {
1808
+ for (var i = 0; i < children.length; i++) {
1809
+ CustomElements.upgrade(children[i]);
1810
+ }
1811
+ }
1812
+ }
1813
+ }());
1814
+ if (Polymer.Settings.useShadow) {
1815
+ Polymer.Base._addFeature({
1816
+ _poolContent: function () {
1817
+ },
1818
+ _beginDistribute: function () {
1819
+ },
1820
+ distributeContent: function () {
1821
+ },
1822
+ _distributeContent: function () {
1823
+ },
1824
+ _finishDistribute: function () {
1825
+ },
1826
+ _createLocalRoot: function () {
1827
+ this.createShadowRoot();
1828
+ this.shadowRoot.appendChild(this.root);
1829
+ this.root = this.shadowRoot;
1830
+ }
1831
+ });
1832
+ }
1833
+ Polymer.DomModule = document.createElement('dom-module');
1834
+ Polymer.Base._addFeature({
1835
+ _registerFeatures: function () {
1836
+ this._prepIs();
1837
+ this._prepAttributes();
1838
+ this._prepBehaviors();
1839
+ this._prepConstructor();
1840
+ this._prepTemplate();
1841
+ this._prepShady();
1842
+ },
1843
+ _prepBehavior: function (b) {
1844
+ this._addHostAttributes(b.hostAttributes);
1845
+ },
1846
+ _initFeatures: function () {
1847
+ this._poolContent();
1848
+ this._pushHost();
1849
+ this._stampTemplate();
1850
+ this._popHost();
1851
+ this._marshalHostAttributes();
1852
+ this._setupDebouncers();
1853
+ this._marshalBehaviors();
1854
+ this._tryReady();
1855
+ },
1856
+ _marshalBehavior: function (b) {
1857
+ }
1858
+ });</script>
1859
+