Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: polymer_1.0.4/bower_components/polymer/polymer-mini.html

Issue 1205703007: Add polymer 1.0 to npm_modules (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Renamed folder to 1.0.4 Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.g ithub.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/CONTRI BUTORS.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/PATEN TS.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 },
18 _stampTemplate: function () {
19 if (this._template) {
20 this.root = this.instanceTemplate(this._template);
21 }
22 },
23 instanceTemplate: function (template) {
24 var dom = document.importNode(template._content || template.content, true);
25 return dom;
26 }
27 });
28 (function () {
29 var baseAttachedCallback = Polymer.Base.attachedCallback;
30 Polymer.Base._addFeature({
31 _hostStack: [],
32 ready: function () {
33 },
34 _pushHost: function (host) {
35 this.dataHost = host = host || Polymer.Base._hostStack[Polymer.Base._hostStack.l ength - 1];
36 if (host && host._clients) {
37 host._clients.push(this);
38 }
39 this._beginHost();
40 },
41 _beginHost: function () {
42 Polymer.Base._hostStack.push(this);
43 if (!this._clients) {
44 this._clients = [];
45 }
46 },
47 _popHost: function () {
48 Polymer.Base._hostStack.pop();
49 },
50 _tryReady: function () {
51 if (this._canReady()) {
52 this._ready();
53 }
54 },
55 _canReady: function () {
56 return !this.dataHost || this.dataHost._clientsReadied;
57 },
58 _ready: function () {
59 this._beforeClientsReady();
60 this._setupRoot();
61 this._readyClients();
62 this._afterClientsReady();
63 this._readySelf();
64 },
65 _readyClients: function () {
66 this._beginDistribute();
67 var c$ = this._clients;
68 for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) {
69 c._ready();
70 }
71 this._finishDistribute();
72 this._clientsReadied = true;
73 this._clients = null;
74 },
75 _readySelf: function () {
76 this._doBehavior('ready');
77 this._readied = true;
78 if (this._attachedPending) {
79 this._attachedPending = false;
80 this.attachedCallback();
81 }
82 },
83 _beforeClientsReady: function () {
84 },
85 _afterClientsReady: function () {
86 },
87 _beforeAttached: function () {
88 },
89 attachedCallback: function () {
90 if (this._readied) {
91 this._beforeAttached();
92 baseAttachedCallback.call(this);
93 } else {
94 this._attachedPending = true;
95 }
96 }
97 });
98 }());
99 Polymer.ArraySplice = function () {
100 function newSplice(index, removed, addedCount) {
101 return {
102 index: index,
103 removed: removed,
104 addedCount: addedCount
105 };
106 }
107 var EDIT_LEAVE = 0;
108 var EDIT_UPDATE = 1;
109 var EDIT_ADD = 2;
110 var EDIT_DELETE = 3;
111 function ArraySplice() {
112 }
113 ArraySplice.prototype = {
114 calcEditDistances: function (current, currentStart, currentEnd, old, oldStart, o ldEnd) {
115 var rowCount = oldEnd - oldStart + 1;
116 var columnCount = currentEnd - currentStart + 1;
117 var distances = new Array(rowCount);
118 for (var i = 0; i < rowCount; i++) {
119 distances[i] = new Array(columnCount);
120 distances[i][0] = i;
121 }
122 for (var j = 0; j < columnCount; j++)
123 distances[0][j] = j;
124 for (var i = 1; i < rowCount; i++) {
125 for (var j = 1; j < columnCount; j++) {
126 if (this.equals(current[currentStart + j - 1], old[oldStart + i - 1]))
127 distances[i][j] = distances[i - 1][j - 1];
128 else {
129 var north = distances[i - 1][j] + 1;
130 var west = distances[i][j - 1] + 1;
131 distances[i][j] = north < west ? north : west;
132 }
133 }
134 }
135 return distances;
136 },
137 spliceOperationsFromEditDistances: function (distances) {
138 var i = distances.length - 1;
139 var j = distances[0].length - 1;
140 var current = distances[i][j];
141 var edits = [];
142 while (i > 0 || j > 0) {
143 if (i == 0) {
144 edits.push(EDIT_ADD);
145 j--;
146 continue;
147 }
148 if (j == 0) {
149 edits.push(EDIT_DELETE);
150 i--;
151 continue;
152 }
153 var northWest = distances[i - 1][j - 1];
154 var west = distances[i - 1][j];
155 var north = distances[i][j - 1];
156 var min;
157 if (west < north)
158 min = west < northWest ? west : northWest;
159 else
160 min = north < northWest ? north : northWest;
161 if (min == northWest) {
162 if (northWest == current) {
163 edits.push(EDIT_LEAVE);
164 } else {
165 edits.push(EDIT_UPDATE);
166 current = northWest;
167 }
168 i--;
169 j--;
170 } else if (min == west) {
171 edits.push(EDIT_DELETE);
172 i--;
173 current = west;
174 } else {
175 edits.push(EDIT_ADD);
176 j--;
177 current = north;
178 }
179 }
180 edits.reverse();
181 return edits;
182 },
183 calcSplices: function (current, currentStart, currentEnd, old, oldStart, oldEnd) {
184 var prefixCount = 0;
185 var suffixCount = 0;
186 var minLength = Math.min(currentEnd - currentStart, oldEnd - oldStart);
187 if (currentStart == 0 && oldStart == 0)
188 prefixCount = this.sharedPrefix(current, old, minLength);
189 if (currentEnd == current.length && oldEnd == old.length)
190 suffixCount = this.sharedSuffix(current, old, minLength - prefixCount);
191 currentStart += prefixCount;
192 oldStart += prefixCount;
193 currentEnd -= suffixCount;
194 oldEnd -= suffixCount;
195 if (currentEnd - currentStart == 0 && oldEnd - oldStart == 0)
196 return [];
197 if (currentStart == currentEnd) {
198 var splice = newSplice(currentStart, [], 0);
199 while (oldStart < oldEnd)
200 splice.removed.push(old[oldStart++]);
201 return [splice];
202 } else if (oldStart == oldEnd)
203 return [newSplice(currentStart, [], currentEnd - currentStart)];
204 var ops = this.spliceOperationsFromEditDistances(this.calcEditDistances(current, currentStart, currentEnd, old, oldStart, oldEnd));
205 var splice = undefined;
206 var splices = [];
207 var index = currentStart;
208 var oldIndex = oldStart;
209 for (var i = 0; i < ops.length; i++) {
210 switch (ops[i]) {
211 case EDIT_LEAVE:
212 if (splice) {
213 splices.push(splice);
214 splice = undefined;
215 }
216 index++;
217 oldIndex++;
218 break;
219 case EDIT_UPDATE:
220 if (!splice)
221 splice = newSplice(index, [], 0);
222 splice.addedCount++;
223 index++;
224 splice.removed.push(old[oldIndex]);
225 oldIndex++;
226 break;
227 case EDIT_ADD:
228 if (!splice)
229 splice = newSplice(index, [], 0);
230 splice.addedCount++;
231 index++;
232 break;
233 case EDIT_DELETE:
234 if (!splice)
235 splice = newSplice(index, [], 0);
236 splice.removed.push(old[oldIndex]);
237 oldIndex++;
238 break;
239 }
240 }
241 if (splice) {
242 splices.push(splice);
243 }
244 return splices;
245 },
246 sharedPrefix: function (current, old, searchLength) {
247 for (var i = 0; i < searchLength; i++)
248 if (!this.equals(current[i], old[i]))
249 return i;
250 return searchLength;
251 },
252 sharedSuffix: function (current, old, searchLength) {
253 var index1 = current.length;
254 var index2 = old.length;
255 var count = 0;
256 while (count < searchLength && this.equals(current[--index1], old[--index2]))
257 count++;
258 return count;
259 },
260 calculateSplices: function (current, previous) {
261 return this.calcSplices(current, 0, current.length, previous, 0, previous.length );
262 },
263 equals: function (currentValue, previousValue) {
264 return currentValue === previousValue;
265 }
266 };
267 return new ArraySplice();
268 }();
269 Polymer.EventApi = function () {
270 var Settings = Polymer.Settings;
271 var EventApi = function (event) {
272 this.event = event;
273 };
274 if (Settings.useShadow) {
275 EventApi.prototype = {
276 get rootTarget() {
277 return this.event.path[0];
278 },
279 get localTarget() {
280 return this.event.target;
281 },
282 get path() {
283 return this.event.path;
284 }
285 };
286 } else {
287 EventApi.prototype = {
288 get rootTarget() {
289 return this.event.target;
290 },
291 get localTarget() {
292 var current = this.event.currentTarget;
293 var currentRoot = current && Polymer.dom(current).getOwnerRoot();
294 var p$ = this.path;
295 for (var i = 0; i < p$.length; i++) {
296 if (Polymer.dom(p$[i]).getOwnerRoot() === currentRoot) {
297 return p$[i];
298 }
299 }
300 },
301 get path() {
302 if (!this.event._path) {
303 var path = [];
304 var o = this.rootTarget;
305 while (o) {
306 path.push(o);
307 o = Polymer.dom(o).parentNode || o.host;
308 }
309 path.push(window);
310 this.event._path = path;
311 }
312 return this.event._path;
313 }
314 };
315 }
316 var factory = function (event) {
317 if (!event.__eventApi) {
318 event.__eventApi = new EventApi(event);
319 }
320 return event.__eventApi;
321 };
322 return { factory: factory };
323 }();
324 Polymer.domInnerHTML = function () {
325 var escapeAttrRegExp = /[&\u00A0"]/g;
326 var escapeDataRegExp = /[&\u00A0<>]/g;
327 function escapeReplace(c) {
328 switch (c) {
329 case '&':
330 return '&amp;';
331 case '<':
332 return '&lt;';
333 case '>':
334 return '&gt;';
335 case '"':
336 return '&quot;';
337 case '\xA0':
338 return '&nbsp;';
339 }
340 }
341 function escapeAttr(s) {
342 return s.replace(escapeAttrRegExp, escapeReplace);
343 }
344 function escapeData(s) {
345 return s.replace(escapeDataRegExp, escapeReplace);
346 }
347 function makeSet(arr) {
348 var set = {};
349 for (var i = 0; i < arr.length; i++) {
350 set[arr[i]] = true;
351 }
352 return set;
353 }
354 var voidElements = makeSet([
355 'area',
356 'base',
357 'br',
358 'col',
359 'command',
360 'embed',
361 'hr',
362 'img',
363 'input',
364 'keygen',
365 'link',
366 'meta',
367 'param',
368 'source',
369 'track',
370 'wbr'
371 ]);
372 var plaintextParents = makeSet([
373 'style',
374 'script',
375 'xmp',
376 'iframe',
377 'noembed',
378 'noframes',
379 'plaintext',
380 'noscript'
381 ]);
382 function getOuterHTML(node, parentNode, composed) {
383 switch (node.nodeType) {
384 case Node.ELEMENT_NODE:
385 var tagName = node.localName;
386 var s = '<' + tagName;
387 var attrs = node.attributes;
388 for (var i = 0, attr; attr = attrs[i]; i++) {
389 s += ' ' + attr.name + '="' + escapeAttr(attr.value) + '"';
390 }
391 s += '>';
392 if (voidElements[tagName]) {
393 return s;
394 }
395 return s + getInnerHTML(node, composed) + '</' + tagName + '>';
396 case Node.TEXT_NODE:
397 var data = node.data;
398 if (parentNode && plaintextParents[parentNode.localName]) {
399 return data;
400 }
401 return escapeData(data);
402 case Node.COMMENT_NODE:
403 return '<!--' + node.data + '-->';
404 default:
405 console.error(node);
406 throw new Error('not implemented');
407 }
408 }
409 function getInnerHTML(node, composed) {
410 if (node instanceof HTMLTemplateElement)
411 node = node.content;
412 var s = '';
413 var c$ = Polymer.dom(node).childNodes;
414 c$ = composed ? node._composedChildren : c$;
415 for (var i = 0, l = c$.length, child; i < l && (child = c$[i]); i++) {
416 s += getOuterHTML(child, node, composed);
417 }
418 return s;
419 }
420 return { getInnerHTML: getInnerHTML };
421 }();
422 Polymer.DomApi = function () {
423 'use strict';
424 var Settings = Polymer.Settings;
425 var getInnerHTML = Polymer.domInnerHTML.getInnerHTML;
426 var nativeInsertBefore = Element.prototype.insertBefore;
427 var nativeRemoveChild = Element.prototype.removeChild;
428 var nativeAppendChild = Element.prototype.appendChild;
429 var dirtyRoots = [];
430 var DomApi = function (node) {
431 this.node = node;
432 if (this.patch) {
433 this.patch();
434 }
435 };
436 DomApi.prototype = {
437 flush: function () {
438 for (var i = 0, host; i < dirtyRoots.length; i++) {
439 host = dirtyRoots[i];
440 host.flushDebouncer('_distribute');
441 }
442 dirtyRoots = [];
443 },
444 _lazyDistribute: function (host) {
445 if (host.shadyRoot && host.shadyRoot._distributionClean) {
446 host.shadyRoot._distributionClean = false;
447 host.debounce('_distribute', host._distributeContent);
448 dirtyRoots.push(host);
449 }
450 },
451 appendChild: function (node) {
452 var handled;
453 this._removeNodeFromHost(node, true);
454 if (this._nodeIsInLogicalTree(this.node)) {
455 this._addLogicalInfo(node, this.node);
456 this._addNodeToHost(node);
457 handled = this._maybeDistribute(node, this.node);
458 }
459 if (!handled && !this._tryRemoveUndistributedNode(node)) {
460 var container = this.node._isShadyRoot ? this.node.host : this.node;
461 addToComposedParent(container, node);
462 nativeAppendChild.call(container, node);
463 }
464 return node;
465 },
466 insertBefore: function (node, ref_node) {
467 if (!ref_node) {
468 return this.appendChild(node);
469 }
470 var handled;
471 this._removeNodeFromHost(node, true);
472 if (this._nodeIsInLogicalTree(this.node)) {
473 saveLightChildrenIfNeeded(this.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 this._addLogicalInfo(node, this.node, index);
480 this._addNodeToHost(node);
481 handled = this._maybeDistribute(node, this.node);
482 }
483 if (!handled && !this._tryRemoveUndistributedNode(node)) {
484 ref_node = ref_node.localName === CONTENT ? this._firstComposedNode(ref_node) : ref_node;
485 var container = this.node._isShadyRoot ? this.node.host : this.node;
486 addToComposedParent(container, node, ref_node);
487 nativeInsertBefore.call(container, node, ref_node);
488 }
489 return node;
490 },
491 removeChild: function (node) {
492 if (factory(node).parentNode !== this.node) {
493 console.warn('The node to be removed is not a child of this node', node);
494 }
495 var handled;
496 if (this._nodeIsInLogicalTree(this.node)) {
497 this._removeNodeFromHost(node);
498 handled = this._maybeDistribute(node, this.node);
499 }
500 if (!handled) {
501 var container = this.node._isShadyRoot ? this.node.host : this.node;
502 if (container === node.parentNode) {
503 removeFromComposedParent(container, node);
504 nativeRemoveChild.call(container, node);
505 }
506 }
507 return node;
508 },
509 replaceChild: function (node, ref_node) {
510 this.insertBefore(node, ref_node);
511 this.removeChild(ref_node);
512 return node;
513 },
514 getOwnerRoot: function () {
515 return this._ownerShadyRootForNode(this.node);
516 },
517 _ownerShadyRootForNode: function (node) {
518 if (!node) {
519 return;
520 }
521 if (node._ownerShadyRoot === undefined) {
522 var root;
523 if (node._isShadyRoot) {
524 root = node;
525 } else {
526 var parent = Polymer.dom(node).parentNode;
527 if (parent) {
528 root = parent._isShadyRoot ? parent : this._ownerShadyRootForNode(parent);
529 } else {
530 root = null;
531 }
532 }
533 node._ownerShadyRoot = root;
534 }
535 return node._ownerShadyRoot;
536 },
537 _maybeDistribute: function (node, parent) {
538 var fragContent = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && node.querySel ector(CONTENT);
539 var wrappedContent = fragContent && fragContent.parentNode.nodeType !== Node.DOC UMENT_FRAGMENT_NODE;
540 var hasContent = fragContent || node.localName === CONTENT;
541 if (hasContent) {
542 var root = this._ownerShadyRootForNode(parent);
543 if (root) {
544 var host = root.host;
545 this._updateInsertionPoints(host);
546 this._lazyDistribute(host);
547 }
548 }
549 var parentNeedsDist = this._parentNeedsDistribution(parent);
550 if (parentNeedsDist) {
551 this._lazyDistribute(parent);
552 }
553 return parentNeedsDist || hasContent && !wrappedContent;
554 },
555 _tryRemoveUndistributedNode: function (node) {
556 if (this.node.shadyRoot) {
557 if (node.parentNode) {
558 nativeRemoveChild.call(node.parentNode, node);
559 }
560 return true;
561 }
562 },
563 _updateInsertionPoints: function (host) {
564 host.shadyRoot._insertionPoints = factory(host.shadyRoot).querySelectorAll(CONTE NT);
565 },
566 _nodeIsInLogicalTree: function (node) {
567 return Boolean(node._lightParent || node._isShadyRoot || this._ownerShadyRootFor Node(node) || node.shadyRoot);
568 },
569 _parentNeedsDistribution: function (parent) {
570 return parent && parent.shadyRoot && hasInsertionPoint(parent.shadyRoot);
571 },
572 _removeNodeFromHost: function (node, ensureComposedRemoval) {
573 var hostNeedsDist;
574 var root;
575 var parent = node._lightParent;
576 if (parent) {
577 root = this._ownerShadyRootForNode(node);
578 if (root) {
579 root.host._elementRemove(node);
580 hostNeedsDist = this._removeDistributedChildren(root, node);
581 }
582 this._removeLogicalInfo(node, node._lightParent);
583 }
584 this._removeOwnerShadyRoot(node);
585 if (root && hostNeedsDist) {
586 this._updateInsertionPoints(root.host);
587 this._lazyDistribute(root.host);
588 } else if (ensureComposedRemoval) {
589 removeFromComposedParent(parent || node.parentNode, node);
590 }
591 },
592 _removeDistributedChildren: function (root, container) {
593 var hostNeedsDist;
594 var ip$ = root._insertionPoints;
595 for (var i = 0; i < ip$.length; i++) {
596 var content = ip$[i];
597 if (this._contains(container, content)) {
598 var dc$ = factory(content).getDistributedNodes();
599 for (var j = 0; j < dc$.length; j++) {
600 hostNeedsDist = true;
601 var node = dc$[i];
602 var parent = node.parentNode;
603 if (parent) {
604 removeFromComposedParent(parent, node);
605 nativeRemoveChild.call(parent, node);
606 }
607 }
608 }
609 }
610 return hostNeedsDist;
611 },
612 _contains: function (container, node) {
613 while (node) {
614 if (node == container) {
615 return true;
616 }
617 node = factory(node).parentNode;
618 }
619 },
620 _addNodeToHost: function (node) {
621 var checkNode = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE ? node.firstChild : node;
622 var root = this._ownerShadyRootForNode(checkNode);
623 if (root) {
624 root.host._elementAdd(node);
625 }
626 },
627 _addLogicalInfo: function (node, container, index) {
628 saveLightChildrenIfNeeded(container);
629 var children = factory(container).childNodes;
630 index = index === undefined ? children.length : index;
631 if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
632 var c$ = Array.prototype.slice.call(node.childNodes);
633 for (var i = 0, n; i < c$.length && (n = c$[i]); i++) {
634 children.splice(index++, 0, n);
635 n._lightParent = container;
636 }
637 } else {
638 children.splice(index, 0, node);
639 node._lightParent = container;
640 }
641 },
642 _removeLogicalInfo: function (node, container) {
643 var children = factory(container).childNodes;
644 var index = children.indexOf(node);
645 if (index < 0 || container !== node._lightParent) {
646 throw Error('The node to be removed is not a child of this node');
647 }
648 children.splice(index, 1);
649 node._lightParent = null;
650 },
651 _removeOwnerShadyRoot: function (node) {
652 var hasCachedRoot = factory(node).getOwnerRoot() !== undefined;
653 if (hasCachedRoot) {
654 var c$ = factory(node).childNodes;
655 for (var i = 0, l = c$.length, n; i < l && (n = c$[i]); i++) {
656 this._removeOwnerShadyRoot(n);
657 }
658 }
659 node._ownerShadyRoot = undefined;
660 },
661 _firstComposedNode: function (content) {
662 var n$ = factory(content).getDistributedNodes();
663 for (var i = 0, l = n$.length, n, p$; i < l && (n = n$[i]); i++) {
664 p$ = factory(n).getDestinationInsertionPoints();
665 if (p$[p$.length - 1] === content) {
666 return n;
667 }
668 }
669 },
670 querySelector: function (selector) {
671 return this.querySelectorAll(selector)[0];
672 },
673 querySelectorAll: function (selector) {
674 return this._query(function (n) {
675 return matchesSelector.call(n, selector);
676 }, this.node);
677 },
678 _query: function (matcher, node) {
679 node = node || this.node;
680 var list = [];
681 this._queryElements(factory(node).childNodes, matcher, list);
682 return list;
683 },
684 _queryElements: function (elements, matcher, list) {
685 for (var i = 0, l = elements.length, c; i < l && (c = elements[i]); i++) {
686 if (c.nodeType === Node.ELEMENT_NODE) {
687 this._queryElement(c, matcher, list);
688 }
689 }
690 },
691 _queryElement: function (node, matcher, list) {
692 if (matcher(node)) {
693 list.push(node);
694 }
695 this._queryElements(factory(node).childNodes, matcher, list);
696 },
697 getDestinationInsertionPoints: function () {
698 return this.node._destinationInsertionPoints || [];
699 },
700 getDistributedNodes: function () {
701 return this.node._distributedNodes || [];
702 },
703 queryDistributedElements: function (selector) {
704 var c$ = this.childNodes;
705 var list = [];
706 this._distributedFilter(selector, c$, list);
707 for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) {
708 if (c.localName === CONTENT) {
709 this._distributedFilter(selector, factory(c).getDistributedNodes(), list);
710 }
711 }
712 return list;
713 },
714 _distributedFilter: function (selector, list, results) {
715 results = results || [];
716 for (var i = 0, l = list.length, d; i < l && (d = list[i]); i++) {
717 if (d.nodeType === Node.ELEMENT_NODE && d.localName !== CONTENT && matchesSelect or.call(d, selector)) {
718 results.push(d);
719 }
720 }
721 return results;
722 },
723 _clear: function () {
724 while (this.childNodes.length) {
725 this.removeChild(this.childNodes[0]);
726 }
727 },
728 setAttribute: function (name, value) {
729 this.node.setAttribute(name, value);
730 this._distributeParent();
731 },
732 removeAttribute: function (name) {
733 this.node.removeAttribute(name);
734 this._distributeParent();
735 },
736 _distributeParent: function () {
737 if (this._parentNeedsDistribution(this.parentNode)) {
738 this._lazyDistribute(this.parentNode);
739 }
740 }
741 };
742 Object.defineProperty(DomApi.prototype, 'classList', {
743 get: function () {
744 if (!this._classList) {
745 this._classList = new DomApi.ClassList(this);
746 }
747 return this._classList;
748 },
749 configurable: true
750 });
751 DomApi.ClassList = function (host) {
752 this.domApi = host;
753 this.node = host.node;
754 };
755 DomApi.ClassList.prototype = {
756 add: function () {
757 this.node.classList.add.apply(this.node.classList, arguments);
758 this.domApi._distributeParent();
759 },
760 remove: function () {
761 this.node.classList.remove.apply(this.node.classList, arguments);
762 this.domApi._distributeParent();
763 },
764 toggle: function () {
765 this.node.classList.toggle.apply(this.node.classList, arguments);
766 this.domApi._distributeParent();
767 }
768 };
769 if (!Settings.useShadow) {
770 Object.defineProperties(DomApi.prototype, {
771 childNodes: {
772 get: function () {
773 var c$ = getLightChildren(this.node);
774 return Array.isArray(c$) ? c$ : Array.prototype.slice.call(c$);
775 },
776 configurable: true
777 },
778 children: {
779 get: function () {
780 return Array.prototype.filter.call(this.childNodes, function (n) {
781 return n.nodeType === Node.ELEMENT_NODE;
782 });
783 },
784 configurable: true
785 },
786 parentNode: {
787 get: function () {
788 return this.node._lightParent || (this.node.__patched ? this.node._composedParen t : this.node.parentNode);
789 },
790 configurable: true
791 },
792 firstChild: {
793 get: function () {
794 return this.childNodes[0];
795 },
796 configurable: true
797 },
798 lastChild: {
799 get: function () {
800 var c$ = this.childNodes;
801 return c$[c$.length - 1];
802 },
803 configurable: true
804 },
805 nextSibling: {
806 get: function () {
807 var c$ = this.parentNode && factory(this.parentNode).childNodes;
808 if (c$) {
809 return c$[Array.prototype.indexOf.call(c$, this.node) + 1];
810 }
811 },
812 configurable: true
813 },
814 previousSibling: {
815 get: function () {
816 var c$ = this.parentNode && factory(this.parentNode).childNodes;
817 if (c$) {
818 return c$[Array.prototype.indexOf.call(c$, this.node) - 1];
819 }
820 },
821 configurable: true
822 },
823 firstElementChild: {
824 get: function () {
825 return this.children[0];
826 },
827 configurable: true
828 },
829 lastElementChild: {
830 get: function () {
831 var c$ = this.children;
832 return c$[c$.length - 1];
833 },
834 configurable: true
835 },
836 nextElementSibling: {
837 get: function () {
838 var c$ = this.parentNode && factory(this.parentNode).children;
839 if (c$) {
840 return c$[Array.prototype.indexOf.call(c$, this.node) + 1];
841 }
842 },
843 configurable: true
844 },
845 previousElementSibling: {
846 get: function () {
847 var c$ = this.parentNode && factory(this.parentNode).children;
848 if (c$) {
849 return c$[Array.prototype.indexOf.call(c$, this.node) - 1];
850 }
851 },
852 configurable: true
853 },
854 textContent: {
855 get: function () {
856 if (this.node.nodeType === Node.TEXT_NODE) {
857 return this.node.textContent;
858 } else {
859 return Array.prototype.map.call(this.childNodes, function (c) {
860 return c.textContent;
861 }).join('');
862 }
863 },
864 set: function (text) {
865 this._clear();
866 if (text) {
867 this.appendChild(document.createTextNode(text));
868 }
869 },
870 configurable: true
871 },
872 innerHTML: {
873 get: function () {
874 if (this.node.nodeType === Node.TEXT_NODE) {
875 return null;
876 } else {
877 return getInnerHTML(this.node);
878 }
879 },
880 set: function (text) {
881 if (this.node.nodeType !== Node.TEXT_NODE) {
882 this._clear();
883 var d = document.createElement('div');
884 d.innerHTML = text;
885 for (var e = d.firstChild; e; e = e.nextSibling) {
886 this.appendChild(e);
887 }
888 }
889 },
890 configurable: true
891 }
892 });
893 DomApi.prototype._getComposedInnerHTML = function () {
894 return getInnerHTML(this.node, true);
895 };
896 } else {
897 DomApi.prototype.querySelectorAll = function (selector) {
898 return Array.prototype.slice.call(this.node.querySelectorAll(selector));
899 };
900 DomApi.prototype.getOwnerRoot = function () {
901 var n = this.node;
902 while (n) {
903 if (n.nodeType === Node.DOCUMENT_FRAGMENT_NODE && n.host) {
904 return n;
905 }
906 n = n.parentNode;
907 }
908 };
909 DomApi.prototype.getDestinationInsertionPoints = function () {
910 var n$ = this.node.getDestinationInsertionPoints();
911 return n$ ? Array.prototype.slice.call(n$) : [];
912 };
913 DomApi.prototype.getDistributedNodes = function () {
914 var n$ = this.node.getDistributedNodes();
915 return n$ ? Array.prototype.slice.call(n$) : [];
916 };
917 DomApi.prototype._distributeParent = function () {
918 };
919 Object.defineProperties(DomApi.prototype, {
920 childNodes: {
921 get: function () {
922 return Array.prototype.slice.call(this.node.childNodes);
923 },
924 configurable: true
925 },
926 children: {
927 get: function () {
928 return Array.prototype.slice.call(this.node.children);
929 },
930 configurable: true
931 },
932 textContent: {
933 get: function () {
934 return this.node.textContent;
935 },
936 set: function (value) {
937 return this.node.textContent = value;
938 },
939 configurable: true
940 },
941 innerHTML: {
942 get: function () {
943 return this.node.innerHTML;
944 },
945 set: function (value) {
946 return this.node.innerHTML = value;
947 },
948 configurable: true
949 }
950 });
951 var forwards = [
952 'parentNode',
953 'firstChild',
954 'lastChild',
955 'nextSibling',
956 'previousSibling',
957 'firstElementChild',
958 'lastElementChild',
959 'nextElementSibling',
960 'previousElementSibling'
961 ];
962 forwards.forEach(function (name) {
963 Object.defineProperty(DomApi.prototype, name, {
964 get: function () {
965 return this.node[name];
966 },
967 configurable: true
968 });
969 });
970 }
971 var CONTENT = 'content';
972 var factory = function (node, patch) {
973 node = node || document;
974 if (!node.__domApi) {
975 node.__domApi = new DomApi(node, patch);
976 }
977 return node.__domApi;
978 };
979 Polymer.dom = function (obj, patch) {
980 if (obj instanceof Event) {
981 return Polymer.EventApi.factory(obj);
982 } else {
983 return factory(obj, patch);
984 }
985 };
986 Polymer.dom.flush = DomApi.prototype.flush;
987 function getLightChildren(node) {
988 var children = node._lightChildren;
989 return children ? children : node.childNodes;
990 }
991 function getComposedChildren(node) {
992 if (!node._composedChildren) {
993 node._composedChildren = Array.prototype.slice.call(node.childNodes);
994 }
995 return node._composedChildren;
996 }
997 function addToComposedParent(parent, node, ref_node) {
998 var children = getComposedChildren(parent);
999 var i = ref_node ? children.indexOf(ref_node) : -1;
1000 if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
1001 var fragChildren = getComposedChildren(node);
1002 for (var j = 0; j < fragChildren.length; j++) {
1003 addNodeToComposedChildren(fragChildren[j], parent, children, i + j);
1004 }
1005 node._composedChildren = null;
1006 } else {
1007 addNodeToComposedChildren(node, parent, children, i);
1008 }
1009 }
1010 function addNodeToComposedChildren(node, parent, children, i) {
1011 node._composedParent = parent;
1012 children.splice(i >= 0 ? i : children.length, 0, node);
1013 }
1014 function removeFromComposedParent(parent, node) {
1015 node._composedParent = null;
1016 if (parent) {
1017 var children = getComposedChildren(parent);
1018 var i = children.indexOf(node);
1019 if (i >= 0) {
1020 children.splice(i, 1);
1021 }
1022 }
1023 }
1024 function saveLightChildrenIfNeeded(node) {
1025 if (!node._lightChildren) {
1026 var c$ = Array.prototype.slice.call(node.childNodes);
1027 for (var i = 0, l = c$.length, child; i < l && (child = c$[i]); i++) {
1028 child._lightParent = child._lightParent || node;
1029 }
1030 node._lightChildren = c$;
1031 }
1032 }
1033 function hasInsertionPoint(root) {
1034 return Boolean(root._insertionPoints.length);
1035 }
1036 var p = Element.prototype;
1037 var matchesSelector = p.matches || p.matchesSelector || p.mozMatchesSelector || p.msMatchesSelector || p.oMatchesSelector || p.webkitMatchesSelector;
1038 return {
1039 getLightChildren: getLightChildren,
1040 getComposedChildren: getComposedChildren,
1041 removeFromComposedParent: removeFromComposedParent,
1042 saveLightChildrenIfNeeded: saveLightChildrenIfNeeded,
1043 matchesSelector: matchesSelector,
1044 hasInsertionPoint: hasInsertionPoint,
1045 ctor: DomApi,
1046 factory: factory
1047 };
1048 }();
1049 (function () {
1050 Polymer.Base._addFeature({
1051 _prepShady: function () {
1052 this._useContent = this._useContent || Boolean(this._template);
1053 if (this._useContent) {
1054 this._template._hasInsertionPoint = this._template.content.querySelector('conten t');
1055 }
1056 },
1057 _poolContent: function () {
1058 if (this._useContent) {
1059 saveLightChildrenIfNeeded(this);
1060 }
1061 },
1062 _setupRoot: function () {
1063 if (this._useContent) {
1064 this._createLocalRoot();
1065 if (!this.dataHost) {
1066 upgradeLightChildren(this._lightChildren);
1067 }
1068 }
1069 },
1070 _createLocalRoot: function () {
1071 this.shadyRoot = this.root;
1072 this.shadyRoot._distributionClean = false;
1073 this.shadyRoot._isShadyRoot = true;
1074 this.shadyRoot._dirtyRoots = [];
1075 this.shadyRoot._insertionPoints = this._template._hasInsertionPoint ? this.shady Root.querySelectorAll('content') : [];
1076 saveLightChildrenIfNeeded(this.shadyRoot);
1077 this.shadyRoot.host = this;
1078 },
1079 get domHost() {
1080 var root = Polymer.dom(this).getOwnerRoot();
1081 return root && root.host;
1082 },
1083 distributeContent: function (updateInsertionPoints) {
1084 if (this.shadyRoot) {
1085 var dom = Polymer.dom(this);
1086 if (updateInsertionPoints) {
1087 dom._updateInsertionPoints(this);
1088 }
1089 var host = getTopDistributingHost(this);
1090 dom._lazyDistribute(host);
1091 }
1092 },
1093 _distributeContent: function () {
1094 if (this._useContent && !this.shadyRoot._distributionClean) {
1095 this._beginDistribute();
1096 this._distributeDirtyRoots();
1097 this._finishDistribute();
1098 }
1099 },
1100 _beginDistribute: function () {
1101 if (this._useContent && hasInsertionPoint(this.shadyRoot)) {
1102 this._resetDistribution();
1103 this._distributePool(this.shadyRoot, this._collectPool());
1104 }
1105 },
1106 _distributeDirtyRoots: function () {
1107 var c$ = this.shadyRoot._dirtyRoots;
1108 for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) {
1109 c._distributeContent();
1110 }
1111 this.shadyRoot._dirtyRoots = [];
1112 },
1113 _finishDistribute: function () {
1114 if (this._useContent) {
1115 if (hasInsertionPoint(this.shadyRoot)) {
1116 this._composeTree();
1117 } else {
1118 if (!this.shadyRoot._hasDistributed) {
1119 this.textContent = '';
1120 this._composedChildren = null;
1121 this.appendChild(this.shadyRoot);
1122 } else {
1123 var children = this._composeNode(this);
1124 this._updateChildNodes(this, children);
1125 }
1126 }
1127 this.shadyRoot._hasDistributed = true;
1128 this.shadyRoot._distributionClean = true;
1129 }
1130 },
1131 elementMatches: function (selector, node) {
1132 node = node || this;
1133 return matchesSelector.call(node, selector);
1134 },
1135 _resetDistribution: function () {
1136 var children = getLightChildren(this);
1137 for (var i = 0; i < children.length; i++) {
1138 var child = children[i];
1139 if (child._destinationInsertionPoints) {
1140 child._destinationInsertionPoints = undefined;
1141 }
1142 if (isInsertionPoint(child)) {
1143 clearDistributedDestinationInsertionPoints(child);
1144 }
1145 }
1146 var root = this.shadyRoot;
1147 var p$ = root._insertionPoints;
1148 for (var j = 0; j < p$.length; j++) {
1149 p$[j]._distributedNodes = [];
1150 }
1151 },
1152 _collectPool: function () {
1153 var pool = [];
1154 var children = getLightChildren(this);
1155 for (var i = 0; i < children.length; i++) {
1156 var child = children[i];
1157 if (isInsertionPoint(child)) {
1158 pool.push.apply(pool, child._distributedNodes);
1159 } else {
1160 pool.push(child);
1161 }
1162 }
1163 return pool;
1164 },
1165 _distributePool: function (node, pool) {
1166 var p$ = node._insertionPoints;
1167 for (var i = 0, l = p$.length, p; i < l && (p = p$[i]); i++) {
1168 this._distributeInsertionPoint(p, pool);
1169 maybeRedistributeParent(p, this);
1170 }
1171 },
1172 _distributeInsertionPoint: function (content, pool) {
1173 var anyDistributed = false;
1174 for (var i = 0, l = pool.length, node; i < l; i++) {
1175 node = pool[i];
1176 if (!node) {
1177 continue;
1178 }
1179 if (this._matchesContentSelect(node, content)) {
1180 distributeNodeInto(node, content);
1181 pool[i] = undefined;
1182 anyDistributed = true;
1183 }
1184 }
1185 if (!anyDistributed) {
1186 var children = getLightChildren(content);
1187 for (var j = 0; j < children.length; j++) {
1188 distributeNodeInto(children[j], content);
1189 }
1190 }
1191 },
1192 _composeTree: function () {
1193 this._updateChildNodes(this, this._composeNode(this));
1194 var p$ = this.shadyRoot._insertionPoints;
1195 for (var i = 0, l = p$.length, p, parent; i < l && (p = p$[i]); i++) {
1196 parent = p._lightParent || p.parentNode;
1197 if (!parent._useContent && parent !== this && parent !== this.shadyRoot) {
1198 this._updateChildNodes(parent, this._composeNode(parent));
1199 }
1200 }
1201 },
1202 _composeNode: function (node) {
1203 var children = [];
1204 var c$ = getLightChildren(node.shadyRoot || node);
1205 for (var i = 0; i < c$.length; i++) {
1206 var child = c$[i];
1207 if (isInsertionPoint(child)) {
1208 var distributedNodes = child._distributedNodes;
1209 for (var j = 0; j < distributedNodes.length; j++) {
1210 var distributedNode = distributedNodes[j];
1211 if (isFinalDestination(child, distributedNode)) {
1212 children.push(distributedNode);
1213 }
1214 }
1215 } else {
1216 children.push(child);
1217 }
1218 }
1219 return children;
1220 },
1221 _updateChildNodes: function (container, children) {
1222 var composed = getComposedChildren(container);
1223 var splices = Polymer.ArraySplice.calculateSplices(children, composed);
1224 for (var i = 0, d = 0, s; i < splices.length && (s = splices[i]); i++) {
1225 for (var j = 0, n; j < s.removed.length && (n = s.removed[j]); j++) {
1226 remove(n);
1227 composed.splice(s.index + d, 1);
1228 }
1229 d -= s.addedCount;
1230 }
1231 for (var i = 0, s, next; i < splices.length && (s = splices[i]); i++) {
1232 next = composed[s.index];
1233 for (var j = s.index, n; j < s.index + s.addedCount; j++) {
1234 n = children[j];
1235 insertBefore(container, n, next);
1236 composed.splice(j, 0, n);
1237 }
1238 }
1239 },
1240 _matchesContentSelect: function (node, contentElement) {
1241 var select = contentElement.getAttribute('select');
1242 if (!select) {
1243 return true;
1244 }
1245 select = select.trim();
1246 if (!select) {
1247 return true;
1248 }
1249 if (!(node instanceof Element)) {
1250 return false;
1251 }
1252 var validSelectors = /^(:not\()?[*.#[a-zA-Z_|]/;
1253 if (!validSelectors.test(select)) {
1254 return false;
1255 }
1256 return this.elementMatches(select, node);
1257 },
1258 _elementAdd: function () {
1259 },
1260 _elementRemove: function () {
1261 }
1262 });
1263 var saveLightChildrenIfNeeded = Polymer.DomApi.saveLightChildrenIfNeeded;
1264 var getLightChildren = Polymer.DomApi.getLightChildren;
1265 var matchesSelector = Polymer.DomApi.matchesSelector;
1266 var hasInsertionPoint = Polymer.DomApi.hasInsertionPoint;
1267 var getComposedChildren = Polymer.DomApi.getComposedChildren;
1268 var removeFromComposedParent = Polymer.DomApi.removeFromComposedParent;
1269 function distributeNodeInto(child, insertionPoint) {
1270 insertionPoint._distributedNodes.push(child);
1271 var points = child._destinationInsertionPoints;
1272 if (!points) {
1273 child._destinationInsertionPoints = [insertionPoint];
1274 } else {
1275 points.push(insertionPoint);
1276 }
1277 }
1278 function clearDistributedDestinationInsertionPoints(content) {
1279 var e$ = content._distributedNodes;
1280 if (e$) {
1281 for (var i = 0; i < e$.length; i++) {
1282 var d = e$[i]._destinationInsertionPoints;
1283 if (d) {
1284 d.splice(d.indexOf(content) + 1, d.length);
1285 }
1286 }
1287 }
1288 }
1289 function maybeRedistributeParent(content, host) {
1290 var parent = content._lightParent;
1291 if (parent && parent.shadyRoot && hasInsertionPoint(parent.shadyRoot) && parent. shadyRoot._distributionClean) {
1292 parent.shadyRoot._distributionClean = false;
1293 host.shadyRoot._dirtyRoots.push(parent);
1294 }
1295 }
1296 function isFinalDestination(insertionPoint, node) {
1297 var points = node._destinationInsertionPoints;
1298 return points && points[points.length - 1] === insertionPoint;
1299 }
1300 function isInsertionPoint(node) {
1301 return node.localName == 'content';
1302 }
1303 var nativeInsertBefore = Element.prototype.insertBefore;
1304 var nativeRemoveChild = Element.prototype.removeChild;
1305 function insertBefore(parentNode, newChild, refChild) {
1306 var newChildParent = getComposedParent(newChild);
1307 if (newChildParent !== parentNode) {
1308 removeFromComposedParent(newChildParent, newChild);
1309 }
1310 remove(newChild);
1311 saveLightChildrenIfNeeded(parentNode);
1312 nativeInsertBefore.call(parentNode, newChild, refChild || null);
1313 newChild._composedParent = parentNode;
1314 }
1315 function remove(node) {
1316 var parentNode = getComposedParent(node);
1317 if (parentNode) {
1318 saveLightChildrenIfNeeded(parentNode);
1319 node._composedParent = null;
1320 nativeRemoveChild.call(parentNode, node);
1321 }
1322 }
1323 function getComposedParent(node) {
1324 return node.__patched ? node._composedParent : node.parentNode;
1325 }
1326 function getTopDistributingHost(host) {
1327 while (host && hostNeedsRedistribution(host)) {
1328 host = host.domHost;
1329 }
1330 return host;
1331 }
1332 function hostNeedsRedistribution(host) {
1333 var c$ = Polymer.dom(host).children;
1334 for (var i = 0, c; i < c$.length; i++) {
1335 c = c$[i];
1336 if (c.localName === 'content') {
1337 return host.domHost;
1338 }
1339 }
1340 }
1341 var needsUpgrade = window.CustomElements && !CustomElements.useNative;
1342 function upgradeLightChildren(children) {
1343 if (needsUpgrade && children) {
1344 for (var i = 0; i < children.length; i++) {
1345 CustomElements.upgrade(children[i]);
1346 }
1347 }
1348 }
1349 }());
1350 if (Polymer.Settings.useShadow) {
1351 Polymer.Base._addFeature({
1352 _poolContent: function () {
1353 },
1354 _beginDistribute: function () {
1355 },
1356 distributeContent: function () {
1357 },
1358 _distributeContent: function () {
1359 },
1360 _finishDistribute: function () {
1361 },
1362 _createLocalRoot: function () {
1363 this.createShadowRoot();
1364 this.shadowRoot.appendChild(this.root);
1365 this.root = this.shadowRoot;
1366 }
1367 });
1368 }
1369 Polymer.DomModule = document.createElement('dom-module');
1370 Polymer.Base._addFeature({
1371 _registerFeatures: function () {
1372 this._prepIs();
1373 this._prepAttributes();
1374 this._prepBehaviors();
1375 this._prepExtends();
1376 this._prepConstructor();
1377 this._prepTemplate();
1378 this._prepShady();
1379 },
1380 _prepBehavior: function (b) {
1381 this._addHostAttributes(b.hostAttributes);
1382 },
1383 _initFeatures: function () {
1384 this._poolContent();
1385 this._pushHost();
1386 this._stampTemplate();
1387 this._popHost();
1388 this._marshalHostAttributes();
1389 this._setupDebouncers();
1390 this._marshalBehaviors();
1391 this._tryReady();
1392 },
1393 _marshalBehavior: function (b) {
1394 }
1395 });</script>
1396
OLDNEW
« no previous file with comments | « polymer_1.0.4/bower_components/polymer/polymer-micro.html ('k') | polymer_1.0.4/bower_components/prism-element/.bower.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698