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

Side by Side Diff: polymer_0.5.0/bower_components/webcomponentsjs/webcomponents-lite.js

Issue 786953007: npm_modules: Fork bower_components into Polymer 0.4.0 and 0.5.0 versions (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Created 5 years, 11 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://polyme r.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/CON TRIBUTORS.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/PA TENTS.txt
9 */
10 // @version 0.5.1-1
11 window.WebComponents = window.WebComponents || {};
12
13 (function(scope) {
14 var flags = scope.flags || {};
15 var file = "webcomponents.js";
16 var script = document.querySelector('script[src*="' + file + '"]');
17 var flags = {};
18 if (!flags.noOpts) {
19 location.search.slice(1).split("&").forEach(function(o) {
20 o = o.split("=");
21 o[0] && (flags[o[0]] = o[1] || true);
22 });
23 if (script) {
24 for (var i = 0, a; a = script.attributes[i]; i++) {
25 if (a.name !== "src") {
26 flags[a.name] = a.value || true;
27 }
28 }
29 }
30 if (flags.log) {
31 var parts = flags.log.split(",");
32 flags.log = {};
33 parts.forEach(function(f) {
34 flags.log[f] = true;
35 });
36 } else {
37 flags.log = {};
38 }
39 }
40 flags.shadow = flags.shadow || flags.shadowdom || flags.polyfill;
41 if (flags.shadow === "native") {
42 flags.shadow = false;
43 } else {
44 flags.shadow = flags.shadow || !HTMLElement.prototype.createShadowRoot;
45 }
46 if (flags.register) {
47 window.CustomElements = window.CustomElements || {
48 flags: {}
49 };
50 window.CustomElements.flags.register = flags.register;
51 }
52 scope.flags = flags;
53 })(WebComponents);
54
55 if (typeof WeakMap === "undefined") {
56 (function() {
57 var defineProperty = Object.defineProperty;
58 var counter = Date.now() % 1e9;
59 var WeakMap = function() {
60 this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__");
61 };
62 WeakMap.prototype = {
63 set: function(key, value) {
64 var entry = key[this.name];
65 if (entry && entry[0] === key) entry[1] = value; else defineProperty(key , this.name, {
66 value: [ key, value ],
67 writable: true
68 });
69 return this;
70 },
71 get: function(key) {
72 var entry;
73 return (entry = key[this.name]) && entry[0] === key ? entry[1] : undefin ed;
74 },
75 "delete": function(key) {
76 var entry = key[this.name];
77 if (!entry || entry[0] !== key) return false;
78 entry[0] = entry[1] = undefined;
79 return true;
80 },
81 has: function(key) {
82 var entry = key[this.name];
83 if (!entry) return false;
84 return entry[0] === key;
85 }
86 };
87 window.WeakMap = WeakMap;
88 })();
89 }
90
91 (function(global) {
92 var registrationsTable = new WeakMap();
93 var setImmediate;
94 if (/Trident|Edge/.test(navigator.userAgent)) {
95 setImmediate = setTimeout;
96 } else if (window.setImmediate) {
97 setImmediate = window.setImmediate;
98 } else {
99 var setImmediateQueue = [];
100 var sentinel = String(Math.random());
101 window.addEventListener("message", function(e) {
102 if (e.data === sentinel) {
103 var queue = setImmediateQueue;
104 setImmediateQueue = [];
105 queue.forEach(function(func) {
106 func();
107 });
108 }
109 });
110 setImmediate = function(func) {
111 setImmediateQueue.push(func);
112 window.postMessage(sentinel, "*");
113 };
114 }
115 var isScheduled = false;
116 var scheduledObservers = [];
117 function scheduleCallback(observer) {
118 scheduledObservers.push(observer);
119 if (!isScheduled) {
120 isScheduled = true;
121 setImmediate(dispatchCallbacks);
122 }
123 }
124 function wrapIfNeeded(node) {
125 return window.ShadowDOMPolyfill && window.ShadowDOMPolyfill.wrapIfNeeded(nod e) || node;
126 }
127 function dispatchCallbacks() {
128 isScheduled = false;
129 var observers = scheduledObservers;
130 scheduledObservers = [];
131 observers.sort(function(o1, o2) {
132 return o1.uid_ - o2.uid_;
133 });
134 var anyNonEmpty = false;
135 observers.forEach(function(observer) {
136 var queue = observer.takeRecords();
137 removeTransientObserversFor(observer);
138 if (queue.length) {
139 observer.callback_(queue, observer);
140 anyNonEmpty = true;
141 }
142 });
143 if (anyNonEmpty) dispatchCallbacks();
144 }
145 function removeTransientObserversFor(observer) {
146 observer.nodes_.forEach(function(node) {
147 var registrations = registrationsTable.get(node);
148 if (!registrations) return;
149 registrations.forEach(function(registration) {
150 if (registration.observer === observer) registration.removeTransientObse rvers();
151 });
152 });
153 }
154 function forEachAncestorAndObserverEnqueueRecord(target, callback) {
155 for (var node = target; node; node = node.parentNode) {
156 var registrations = registrationsTable.get(node);
157 if (registrations) {
158 for (var j = 0; j < registrations.length; j++) {
159 var registration = registrations[j];
160 var options = registration.options;
161 if (node !== target && !options.subtree) continue;
162 var record = callback(options);
163 if (record) registration.enqueue(record);
164 }
165 }
166 }
167 }
168 var uidCounter = 0;
169 function JsMutationObserver(callback) {
170 this.callback_ = callback;
171 this.nodes_ = [];
172 this.records_ = [];
173 this.uid_ = ++uidCounter;
174 }
175 JsMutationObserver.prototype = {
176 observe: function(target, options) {
177 target = wrapIfNeeded(target);
178 if (!options.childList && !options.attributes && !options.characterData || options.attributeOldValue && !options.attributes || options.attributeFilter && options.attributeFilter.length && !options.attributes || options.characterDataOl dValue && !options.characterData) {
179 throw new SyntaxError();
180 }
181 var registrations = registrationsTable.get(target);
182 if (!registrations) registrationsTable.set(target, registrations = []);
183 var registration;
184 for (var i = 0; i < registrations.length; i++) {
185 if (registrations[i].observer === this) {
186 registration = registrations[i];
187 registration.removeListeners();
188 registration.options = options;
189 break;
190 }
191 }
192 if (!registration) {
193 registration = new Registration(this, target, options);
194 registrations.push(registration);
195 this.nodes_.push(target);
196 }
197 registration.addListeners();
198 },
199 disconnect: function() {
200 this.nodes_.forEach(function(node) {
201 var registrations = registrationsTable.get(node);
202 for (var i = 0; i < registrations.length; i++) {
203 var registration = registrations[i];
204 if (registration.observer === this) {
205 registration.removeListeners();
206 registrations.splice(i, 1);
207 break;
208 }
209 }
210 }, this);
211 this.records_ = [];
212 },
213 takeRecords: function() {
214 var copyOfRecords = this.records_;
215 this.records_ = [];
216 return copyOfRecords;
217 }
218 };
219 function MutationRecord(type, target) {
220 this.type = type;
221 this.target = target;
222 this.addedNodes = [];
223 this.removedNodes = [];
224 this.previousSibling = null;
225 this.nextSibling = null;
226 this.attributeName = null;
227 this.attributeNamespace = null;
228 this.oldValue = null;
229 }
230 function copyMutationRecord(original) {
231 var record = new MutationRecord(original.type, original.target);
232 record.addedNodes = original.addedNodes.slice();
233 record.removedNodes = original.removedNodes.slice();
234 record.previousSibling = original.previousSibling;
235 record.nextSibling = original.nextSibling;
236 record.attributeName = original.attributeName;
237 record.attributeNamespace = original.attributeNamespace;
238 record.oldValue = original.oldValue;
239 return record;
240 }
241 var currentRecord, recordWithOldValue;
242 function getRecord(type, target) {
243 return currentRecord = new MutationRecord(type, target);
244 }
245 function getRecordWithOldValue(oldValue) {
246 if (recordWithOldValue) return recordWithOldValue;
247 recordWithOldValue = copyMutationRecord(currentRecord);
248 recordWithOldValue.oldValue = oldValue;
249 return recordWithOldValue;
250 }
251 function clearRecords() {
252 currentRecord = recordWithOldValue = undefined;
253 }
254 function recordRepresentsCurrentMutation(record) {
255 return record === recordWithOldValue || record === currentRecord;
256 }
257 function selectRecord(lastRecord, newRecord) {
258 if (lastRecord === newRecord) return lastRecord;
259 if (recordWithOldValue && recordRepresentsCurrentMutation(lastRecord)) retur n recordWithOldValue;
260 return null;
261 }
262 function Registration(observer, target, options) {
263 this.observer = observer;
264 this.target = target;
265 this.options = options;
266 this.transientObservedNodes = [];
267 }
268 Registration.prototype = {
269 enqueue: function(record) {
270 var records = this.observer.records_;
271 var length = records.length;
272 if (records.length > 0) {
273 var lastRecord = records[length - 1];
274 var recordToReplaceLast = selectRecord(lastRecord, record);
275 if (recordToReplaceLast) {
276 records[length - 1] = recordToReplaceLast;
277 return;
278 }
279 } else {
280 scheduleCallback(this.observer);
281 }
282 records[length] = record;
283 },
284 addListeners: function() {
285 this.addListeners_(this.target);
286 },
287 addListeners_: function(node) {
288 var options = this.options;
289 if (options.attributes) node.addEventListener("DOMAttrModified", this, tru e);
290 if (options.characterData) node.addEventListener("DOMCharacterDataModified ", this, true);
291 if (options.childList) node.addEventListener("DOMNodeInserted", this, true );
292 if (options.childList || options.subtree) node.addEventListener("DOMNodeRe moved", this, true);
293 },
294 removeListeners: function() {
295 this.removeListeners_(this.target);
296 },
297 removeListeners_: function(node) {
298 var options = this.options;
299 if (options.attributes) node.removeEventListener("DOMAttrModified", this, true);
300 if (options.characterData) node.removeEventListener("DOMCharacterDataModif ied", this, true);
301 if (options.childList) node.removeEventListener("DOMNodeInserted", this, t rue);
302 if (options.childList || options.subtree) node.removeEventListener("DOMNod eRemoved", this, true);
303 },
304 addTransientObserver: function(node) {
305 if (node === this.target) return;
306 this.addListeners_(node);
307 this.transientObservedNodes.push(node);
308 var registrations = registrationsTable.get(node);
309 if (!registrations) registrationsTable.set(node, registrations = []);
310 registrations.push(this);
311 },
312 removeTransientObservers: function() {
313 var transientObservedNodes = this.transientObservedNodes;
314 this.transientObservedNodes = [];
315 transientObservedNodes.forEach(function(node) {
316 this.removeListeners_(node);
317 var registrations = registrationsTable.get(node);
318 for (var i = 0; i < registrations.length; i++) {
319 if (registrations[i] === this) {
320 registrations.splice(i, 1);
321 break;
322 }
323 }
324 }, this);
325 },
326 handleEvent: function(e) {
327 e.stopImmediatePropagation();
328 switch (e.type) {
329 case "DOMAttrModified":
330 var name = e.attrName;
331 var namespace = e.relatedNode.namespaceURI;
332 var target = e.target;
333 var record = new getRecord("attributes", target);
334 record.attributeName = name;
335 record.attributeNamespace = namespace;
336 var oldValue = e.attrChange === MutationEvent.ADDITION ? null : e.prevVa lue;
337 forEachAncestorAndObserverEnqueueRecord(target, function(options) {
338 if (!options.attributes) return;
339 if (options.attributeFilter && options.attributeFilter.length && optio ns.attributeFilter.indexOf(name) === -1 && options.attributeFilter.indexOf(names pace) === -1) {
340 return;
341 }
342 if (options.attributeOldValue) return getRecordWithOldValue(oldValue);
343 return record;
344 });
345 break;
346
347 case "DOMCharacterDataModified":
348 var target = e.target;
349 var record = getRecord("characterData", target);
350 var oldValue = e.prevValue;
351 forEachAncestorAndObserverEnqueueRecord(target, function(options) {
352 if (!options.characterData) return;
353 if (options.characterDataOldValue) return getRecordWithOldValue(oldVal ue);
354 return record;
355 });
356 break;
357
358 case "DOMNodeRemoved":
359 this.addTransientObserver(e.target);
360
361 case "DOMNodeInserted":
362 var target = e.relatedNode;
363 var changedNode = e.target;
364 var addedNodes, removedNodes;
365 if (e.type === "DOMNodeInserted") {
366 addedNodes = [ changedNode ];
367 removedNodes = [];
368 } else {
369 addedNodes = [];
370 removedNodes = [ changedNode ];
371 }
372 var previousSibling = changedNode.previousSibling;
373 var nextSibling = changedNode.nextSibling;
374 var record = getRecord("childList", target);
375 record.addedNodes = addedNodes;
376 record.removedNodes = removedNodes;
377 record.previousSibling = previousSibling;
378 record.nextSibling = nextSibling;
379 forEachAncestorAndObserverEnqueueRecord(target, function(options) {
380 if (!options.childList) return;
381 return record;
382 });
383 }
384 clearRecords();
385 }
386 };
387 global.JsMutationObserver = JsMutationObserver;
388 if (!global.MutationObserver) global.MutationObserver = JsMutationObserver;
389 })(this);
390
391 window.HTMLImports = window.HTMLImports || {
392 flags: {}
393 };
394
395 (function(scope) {
396 var IMPORT_LINK_TYPE = "import";
397 var useNative = Boolean(IMPORT_LINK_TYPE in document.createElement("link"));
398 var hasShadowDOMPolyfill = Boolean(window.ShadowDOMPolyfill);
399 var wrap = function(node) {
400 return hasShadowDOMPolyfill ? ShadowDOMPolyfill.wrapIfNeeded(node) : node;
401 };
402 var rootDocument = wrap(document);
403 var currentScriptDescriptor = {
404 get: function() {
405 var script = HTMLImports.currentScript || document.currentScript || (docum ent.readyState !== "complete" ? document.scripts[document.scripts.length - 1] : null);
406 return wrap(script);
407 },
408 configurable: true
409 };
410 Object.defineProperty(document, "_currentScript", currentScriptDescriptor);
411 Object.defineProperty(rootDocument, "_currentScript", currentScriptDescriptor) ;
412 var isIE = /Trident|Edge/.test(navigator.userAgent);
413 function whenReady(callback, doc) {
414 doc = doc || rootDocument;
415 whenDocumentReady(function() {
416 watchImportsLoad(callback, doc);
417 }, doc);
418 }
419 var requiredReadyState = isIE ? "complete" : "interactive";
420 var READY_EVENT = "readystatechange";
421 function isDocumentReady(doc) {
422 return doc.readyState === "complete" || doc.readyState === requiredReadyStat e;
423 }
424 function whenDocumentReady(callback, doc) {
425 if (!isDocumentReady(doc)) {
426 var checkReady = function() {
427 if (doc.readyState === "complete" || doc.readyState === requiredReadySta te) {
428 doc.removeEventListener(READY_EVENT, checkReady);
429 whenDocumentReady(callback, doc);
430 }
431 };
432 doc.addEventListener(READY_EVENT, checkReady);
433 } else if (callback) {
434 callback();
435 }
436 }
437 function markTargetLoaded(event) {
438 event.target.__loaded = true;
439 }
440 function watchImportsLoad(callback, doc) {
441 var imports = doc.querySelectorAll("link[rel=import]");
442 var loaded = 0, l = imports.length;
443 function checkDone(d) {
444 if (loaded == l && callback) {
445 callback();
446 }
447 }
448 function loadedImport(e) {
449 markTargetLoaded(e);
450 loaded++;
451 checkDone();
452 }
453 if (l) {
454 for (var i = 0, imp; i < l && (imp = imports[i]); i++) {
455 if (isImportLoaded(imp)) {
456 loadedImport.call(imp, {
457 target: imp
458 });
459 } else {
460 imp.addEventListener("load", loadedImport);
461 imp.addEventListener("error", loadedImport);
462 }
463 }
464 } else {
465 checkDone();
466 }
467 }
468 function isImportLoaded(link) {
469 return useNative ? link.__loaded || link.import && link.import.readyState != = "loading" : link.__importParsed;
470 }
471 if (useNative) {
472 new MutationObserver(function(mxns) {
473 for (var i = 0, l = mxns.length, m; i < l && (m = mxns[i]); i++) {
474 if (m.addedNodes) {
475 handleImports(m.addedNodes);
476 }
477 }
478 }).observe(document.head, {
479 childList: true
480 });
481 function handleImports(nodes) {
482 for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
483 if (isImport(n)) {
484 handleImport(n);
485 }
486 }
487 }
488 function isImport(element) {
489 return element.localName === "link" && element.rel === "import";
490 }
491 function handleImport(element) {
492 var loaded = element.import;
493 if (loaded) {
494 markTargetLoaded({
495 target: element
496 });
497 } else {
498 element.addEventListener("load", markTargetLoaded);
499 element.addEventListener("error", markTargetLoaded);
500 }
501 }
502 (function() {
503 if (document.readyState === "loading") {
504 var imports = document.querySelectorAll("link[rel=import]");
505 for (var i = 0, l = imports.length, imp; i < l && (imp = imports[i]); i+ +) {
506 handleImport(imp);
507 }
508 }
509 })();
510 }
511 whenReady(function() {
512 HTMLImports.ready = true;
513 HTMLImports.readyTime = new Date().getTime();
514 rootDocument.dispatchEvent(new CustomEvent("HTMLImportsLoaded", {
515 bubbles: true
516 }));
517 });
518 scope.IMPORT_LINK_TYPE = IMPORT_LINK_TYPE;
519 scope.useNative = useNative;
520 scope.rootDocument = rootDocument;
521 scope.whenReady = whenReady;
522 scope.isIE = isIE;
523 })(HTMLImports);
524
525 (function(scope) {
526 var modules = [];
527 var addModule = function(module) {
528 modules.push(module);
529 };
530 var initializeModules = function() {
531 modules.forEach(function(module) {
532 module(scope);
533 });
534 };
535 scope.addModule = addModule;
536 scope.initializeModules = initializeModules;
537 })(HTMLImports);
538
539 HTMLImports.addModule(function(scope) {
540 var CSS_URL_REGEXP = /(url\()([^)]*)(\))/g;
541 var CSS_IMPORT_REGEXP = /(@import[\s]+(?!url\())([^;]*)(;)/g;
542 var path = {
543 resolveUrlsInStyle: function(style) {
544 var doc = style.ownerDocument;
545 var resolver = doc.createElement("a");
546 style.textContent = this.resolveUrlsInCssText(style.textContent, resolver) ;
547 return style;
548 },
549 resolveUrlsInCssText: function(cssText, urlObj) {
550 var r = this.replaceUrls(cssText, urlObj, CSS_URL_REGEXP);
551 r = this.replaceUrls(r, urlObj, CSS_IMPORT_REGEXP);
552 return r;
553 },
554 replaceUrls: function(text, urlObj, regexp) {
555 return text.replace(regexp, function(m, pre, url, post) {
556 var urlPath = url.replace(/["']/g, "");
557 urlObj.href = urlPath;
558 urlPath = urlObj.href;
559 return pre + "'" + urlPath + "'" + post;
560 });
561 }
562 };
563 scope.path = path;
564 });
565
566 HTMLImports.addModule(function(scope) {
567 xhr = {
568 async: true,
569 ok: function(request) {
570 return request.status >= 200 && request.status < 300 || request.status === 304 || request.status === 0;
571 },
572 load: function(url, next, nextContext) {
573 var request = new XMLHttpRequest();
574 if (scope.flags.debug || scope.flags.bust) {
575 url += "?" + Math.random();
576 }
577 request.open("GET", url, xhr.async);
578 request.addEventListener("readystatechange", function(e) {
579 if (request.readyState === 4) {
580 var locationHeader = request.getResponseHeader("Location");
581 var redirectedUrl = null;
582 if (locationHeader) {
583 var redirectedUrl = locationHeader.substr(0, 1) === "/" ? location.o rigin + locationHeader : locationHeader;
584 }
585 next.call(nextContext, !xhr.ok(request) && request, request.response | | request.responseText, redirectedUrl);
586 }
587 });
588 request.send();
589 return request;
590 },
591 loadDocument: function(url, next, nextContext) {
592 this.load(url, next, nextContext).responseType = "document";
593 }
594 };
595 scope.xhr = xhr;
596 });
597
598 HTMLImports.addModule(function(scope) {
599 var xhr = scope.xhr;
600 var flags = scope.flags;
601 var Loader = function(onLoad, onComplete) {
602 this.cache = {};
603 this.onload = onLoad;
604 this.oncomplete = onComplete;
605 this.inflight = 0;
606 this.pending = {};
607 };
608 Loader.prototype = {
609 addNodes: function(nodes) {
610 this.inflight += nodes.length;
611 for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
612 this.require(n);
613 }
614 this.checkDone();
615 },
616 addNode: function(node) {
617 this.inflight++;
618 this.require(node);
619 this.checkDone();
620 },
621 require: function(elt) {
622 var url = elt.src || elt.href;
623 elt.__nodeUrl = url;
624 if (!this.dedupe(url, elt)) {
625 this.fetch(url, elt);
626 }
627 },
628 dedupe: function(url, elt) {
629 if (this.pending[url]) {
630 this.pending[url].push(elt);
631 return true;
632 }
633 var resource;
634 if (this.cache[url]) {
635 this.onload(url, elt, this.cache[url]);
636 this.tail();
637 return true;
638 }
639 this.pending[url] = [ elt ];
640 return false;
641 },
642 fetch: function(url, elt) {
643 flags.load && console.log("fetch", url, elt);
644 if (url.match(/^data:/)) {
645 var pieces = url.split(",");
646 var header = pieces[0];
647 var body = pieces[1];
648 if (header.indexOf(";base64") > -1) {
649 body = atob(body);
650 } else {
651 body = decodeURIComponent(body);
652 }
653 setTimeout(function() {
654 this.receive(url, elt, null, body);
655 }.bind(this), 0);
656 } else {
657 var receiveXhr = function(err, resource, redirectedUrl) {
658 this.receive(url, elt, err, resource, redirectedUrl);
659 }.bind(this);
660 xhr.load(url, receiveXhr);
661 }
662 },
663 receive: function(url, elt, err, resource, redirectedUrl) {
664 this.cache[url] = resource;
665 var $p = this.pending[url];
666 for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) {
667 this.onload(url, p, resource, err, redirectedUrl);
668 this.tail();
669 }
670 this.pending[url] = null;
671 },
672 tail: function() {
673 --this.inflight;
674 this.checkDone();
675 },
676 checkDone: function() {
677 if (!this.inflight) {
678 this.oncomplete();
679 }
680 }
681 };
682 scope.Loader = Loader;
683 });
684
685 HTMLImports.addModule(function(scope) {
686 var Observer = function(addCallback) {
687 this.addCallback = addCallback;
688 this.mo = new MutationObserver(this.handler.bind(this));
689 };
690 Observer.prototype = {
691 handler: function(mutations) {
692 for (var i = 0, l = mutations.length, m; i < l && (m = mutations[i]); i++) {
693 if (m.type === "childList" && m.addedNodes.length) {
694 this.addedNodes(m.addedNodes);
695 }
696 }
697 },
698 addedNodes: function(nodes) {
699 if (this.addCallback) {
700 this.addCallback(nodes);
701 }
702 for (var i = 0, l = nodes.length, n, loading; i < l && (n = nodes[i]); i++ ) {
703 if (n.children && n.children.length) {
704 this.addedNodes(n.children);
705 }
706 }
707 },
708 observe: function(root) {
709 this.mo.observe(root, {
710 childList: true,
711 subtree: true
712 });
713 }
714 };
715 scope.Observer = Observer;
716 });
717
718 HTMLImports.addModule(function(scope) {
719 var path = scope.path;
720 var rootDocument = scope.rootDocument;
721 var flags = scope.flags;
722 var isIE = scope.isIE;
723 var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE;
724 var IMPORT_SELECTOR = "link[rel=" + IMPORT_LINK_TYPE + "]";
725 var importParser = {
726 documentSelectors: IMPORT_SELECTOR,
727 importsSelectors: [ IMPORT_SELECTOR, "link[rel=stylesheet]", "style", "scrip t:not([type])", 'script[type="text/javascript"]' ].join(","),
728 map: {
729 link: "parseLink",
730 script: "parseScript",
731 style: "parseStyle"
732 },
733 dynamicElements: [],
734 parseNext: function() {
735 var next = this.nextToParse();
736 if (next) {
737 this.parse(next);
738 }
739 },
740 parse: function(elt) {
741 if (this.isParsed(elt)) {
742 flags.parse && console.log("[%s] is already parsed", elt.localName);
743 return;
744 }
745 var fn = this[this.map[elt.localName]];
746 if (fn) {
747 this.markParsing(elt);
748 fn.call(this, elt);
749 }
750 },
751 parseDynamic: function(elt, quiet) {
752 this.dynamicElements.push(elt);
753 if (!quiet) {
754 this.parseNext();
755 }
756 },
757 markParsing: function(elt) {
758 flags.parse && console.log("parsing", elt);
759 this.parsingElement = elt;
760 },
761 markParsingComplete: function(elt) {
762 elt.__importParsed = true;
763 this.markDynamicParsingComplete(elt);
764 if (elt.__importElement) {
765 elt.__importElement.__importParsed = true;
766 this.markDynamicParsingComplete(elt.__importElement);
767 }
768 this.parsingElement = null;
769 flags.parse && console.log("completed", elt);
770 },
771 markDynamicParsingComplete: function(elt) {
772 var i = this.dynamicElements.indexOf(elt);
773 if (i >= 0) {
774 this.dynamicElements.splice(i, 1);
775 }
776 },
777 parseImport: function(elt) {
778 if (HTMLImports.__importsParsingHook) {
779 HTMLImports.__importsParsingHook(elt);
780 }
781 if (elt.import) {
782 elt.import.__importParsed = true;
783 }
784 this.markParsingComplete(elt);
785 if (elt.__resource && !elt.__error) {
786 elt.dispatchEvent(new CustomEvent("load", {
787 bubbles: false
788 }));
789 } else {
790 elt.dispatchEvent(new CustomEvent("error", {
791 bubbles: false
792 }));
793 }
794 if (elt.__pending) {
795 var fn;
796 while (elt.__pending.length) {
797 fn = elt.__pending.shift();
798 if (fn) {
799 fn({
800 target: elt
801 });
802 }
803 }
804 }
805 this.parseNext();
806 },
807 parseLink: function(linkElt) {
808 if (nodeIsImport(linkElt)) {
809 this.parseImport(linkElt);
810 } else {
811 linkElt.href = linkElt.href;
812 this.parseGeneric(linkElt);
813 }
814 },
815 parseStyle: function(elt) {
816 var src = elt;
817 elt = cloneStyle(elt);
818 elt.__importElement = src;
819 this.parseGeneric(elt);
820 },
821 parseGeneric: function(elt) {
822 this.trackElement(elt);
823 this.addElementToDocument(elt);
824 },
825 rootImportForElement: function(elt) {
826 var n = elt;
827 while (n.ownerDocument.__importLink) {
828 n = n.ownerDocument.__importLink;
829 }
830 return n;
831 },
832 addElementToDocument: function(elt) {
833 var port = this.rootImportForElement(elt.__importElement || elt);
834 port.parentNode.insertBefore(elt, port);
835 },
836 trackElement: function(elt, callback) {
837 var self = this;
838 var done = function(e) {
839 if (callback) {
840 callback(e);
841 }
842 self.markParsingComplete(elt);
843 self.parseNext();
844 };
845 elt.addEventListener("load", done);
846 elt.addEventListener("error", done);
847 if (isIE && elt.localName === "style") {
848 var fakeLoad = false;
849 if (elt.textContent.indexOf("@import") == -1) {
850 fakeLoad = true;
851 } else if (elt.sheet) {
852 fakeLoad = true;
853 var csr = elt.sheet.cssRules;
854 var len = csr ? csr.length : 0;
855 for (var i = 0, r; i < len && (r = csr[i]); i++) {
856 if (r.type === CSSRule.IMPORT_RULE) {
857 fakeLoad = fakeLoad && Boolean(r.styleSheet);
858 }
859 }
860 }
861 if (fakeLoad) {
862 elt.dispatchEvent(new CustomEvent("load", {
863 bubbles: false
864 }));
865 }
866 }
867 },
868 parseScript: function(scriptElt) {
869 var script = document.createElement("script");
870 script.__importElement = scriptElt;
871 script.src = scriptElt.src ? scriptElt.src : generateScriptDataUrl(scriptE lt);
872 scope.currentScript = scriptElt;
873 this.trackElement(script, function(e) {
874 script.parentNode.removeChild(script);
875 scope.currentScript = null;
876 });
877 this.addElementToDocument(script);
878 },
879 nextToParse: function() {
880 this._mayParse = [];
881 return !this.parsingElement && (this.nextToParseInDoc(rootDocument) || thi s.nextToParseDynamic());
882 },
883 nextToParseInDoc: function(doc, link) {
884 if (doc && this._mayParse.indexOf(doc) < 0) {
885 this._mayParse.push(doc);
886 var nodes = doc.querySelectorAll(this.parseSelectorsForNode(doc));
887 for (var i = 0, l = nodes.length, p = 0, n; i < l && (n = nodes[i]); i++ ) {
888 if (!this.isParsed(n)) {
889 if (this.hasResource(n)) {
890 return nodeIsImport(n) ? this.nextToParseInDoc(n.import, n) : n;
891 } else {
892 return;
893 }
894 }
895 }
896 }
897 return link;
898 },
899 nextToParseDynamic: function() {
900 return this.dynamicElements[0];
901 },
902 parseSelectorsForNode: function(node) {
903 var doc = node.ownerDocument || node;
904 return doc === rootDocument ? this.documentSelectors : this.importsSelecto rs;
905 },
906 isParsed: function(node) {
907 return node.__importParsed;
908 },
909 needsDynamicParsing: function(elt) {
910 return this.dynamicElements.indexOf(elt) >= 0;
911 },
912 hasResource: function(node) {
913 if (nodeIsImport(node) && node.import === undefined) {
914 return false;
915 }
916 return true;
917 }
918 };
919 function nodeIsImport(elt) {
920 return elt.localName === "link" && elt.rel === IMPORT_LINK_TYPE;
921 }
922 function generateScriptDataUrl(script) {
923 var scriptContent = generateScriptContent(script);
924 return "data:text/javascript;charset=utf-8," + encodeURIComponent(scriptCont ent);
925 }
926 function generateScriptContent(script) {
927 return script.textContent + generateSourceMapHint(script);
928 }
929 function generateSourceMapHint(script) {
930 var owner = script.ownerDocument;
931 owner.__importedScripts = owner.__importedScripts || 0;
932 var moniker = script.ownerDocument.baseURI;
933 var num = owner.__importedScripts ? "-" + owner.__importedScripts : "";
934 owner.__importedScripts++;
935 return "\n//# sourceURL=" + moniker + num + ".js\n";
936 }
937 function cloneStyle(style) {
938 var clone = style.ownerDocument.createElement("style");
939 clone.textContent = style.textContent;
940 path.resolveUrlsInStyle(clone);
941 return clone;
942 }
943 scope.parser = importParser;
944 scope.IMPORT_SELECTOR = IMPORT_SELECTOR;
945 });
946
947 HTMLImports.addModule(function(scope) {
948 var flags = scope.flags;
949 var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE;
950 var IMPORT_SELECTOR = scope.IMPORT_SELECTOR;
951 var rootDocument = scope.rootDocument;
952 var Loader = scope.Loader;
953 var Observer = scope.Observer;
954 var parser = scope.parser;
955 var importer = {
956 documents: {},
957 documentPreloadSelectors: IMPORT_SELECTOR,
958 importsPreloadSelectors: [ IMPORT_SELECTOR ].join(","),
959 loadNode: function(node) {
960 importLoader.addNode(node);
961 },
962 loadSubtree: function(parent) {
963 var nodes = this.marshalNodes(parent);
964 importLoader.addNodes(nodes);
965 },
966 marshalNodes: function(parent) {
967 return parent.querySelectorAll(this.loadSelectorsForNode(parent));
968 },
969 loadSelectorsForNode: function(node) {
970 var doc = node.ownerDocument || node;
971 return doc === rootDocument ? this.documentPreloadSelectors : this.imports PreloadSelectors;
972 },
973 loaded: function(url, elt, resource, err, redirectedUrl) {
974 flags.load && console.log("loaded", url, elt);
975 elt.__resource = resource;
976 elt.__error = err;
977 if (isImportLink(elt)) {
978 var doc = this.documents[url];
979 if (doc === undefined) {
980 doc = err ? null : makeDocument(resource, redirectedUrl || url);
981 if (doc) {
982 doc.__importLink = elt;
983 this.bootDocument(doc);
984 }
985 this.documents[url] = doc;
986 }
987 elt.import = doc;
988 }
989 parser.parseNext();
990 },
991 bootDocument: function(doc) {
992 this.loadSubtree(doc);
993 this.observer.observe(doc);
994 parser.parseNext();
995 },
996 loadedAll: function() {
997 parser.parseNext();
998 }
999 };
1000 var importLoader = new Loader(importer.loaded.bind(importer), importer.loadedA ll.bind(importer));
1001 importer.observer = new Observer();
1002 function isImportLink(elt) {
1003 return isLinkRel(elt, IMPORT_LINK_TYPE);
1004 }
1005 function isLinkRel(elt, rel) {
1006 return elt.localName === "link" && elt.getAttribute("rel") === rel;
1007 }
1008 function makeDocument(resource, url) {
1009 var doc = document.implementation.createHTMLDocument(IMPORT_LINK_TYPE);
1010 doc._URL = url;
1011 var base = doc.createElement("base");
1012 base.setAttribute("href", url);
1013 if (!doc.baseURI) {
1014 Object.defineProperty(doc, "baseURI", {
1015 value: url
1016 });
1017 }
1018 var meta = doc.createElement("meta");
1019 meta.setAttribute("charset", "utf-8");
1020 doc.head.appendChild(meta);
1021 doc.head.appendChild(base);
1022 doc.body.innerHTML = resource;
1023 if (window.HTMLTemplateElement && HTMLTemplateElement.bootstrap) {
1024 HTMLTemplateElement.bootstrap(doc);
1025 }
1026 return doc;
1027 }
1028 if (!document.baseURI) {
1029 var baseURIDescriptor = {
1030 get: function() {
1031 var base = document.querySelector("base");
1032 return base ? base.href : window.location.href;
1033 },
1034 configurable: true
1035 };
1036 Object.defineProperty(document, "baseURI", baseURIDescriptor);
1037 Object.defineProperty(rootDocument, "baseURI", baseURIDescriptor);
1038 }
1039 scope.importer = importer;
1040 scope.importLoader = importLoader;
1041 });
1042
1043 HTMLImports.addModule(function(scope) {
1044 var parser = scope.parser;
1045 var importer = scope.importer;
1046 var dynamic = {
1047 added: function(nodes) {
1048 var owner, parsed;
1049 for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
1050 if (!owner) {
1051 owner = n.ownerDocument;
1052 parsed = parser.isParsed(owner);
1053 }
1054 loading = this.shouldLoadNode(n);
1055 if (loading) {
1056 importer.loadNode(n);
1057 }
1058 if (this.shouldParseNode(n) && parsed) {
1059 parser.parseDynamic(n, loading);
1060 }
1061 }
1062 },
1063 shouldLoadNode: function(node) {
1064 return node.nodeType === 1 && matches.call(node, importer.loadSelectorsFor Node(node));
1065 },
1066 shouldParseNode: function(node) {
1067 return node.nodeType === 1 && matches.call(node, parser.parseSelectorsForN ode(node));
1068 }
1069 };
1070 importer.observer.addCallback = dynamic.added.bind(dynamic);
1071 var matches = HTMLElement.prototype.matches || HTMLElement.prototype.matchesSe lector || HTMLElement.prototype.webkitMatchesSelector || HTMLElement.prototype.m ozMatchesSelector || HTMLElement.prototype.msMatchesSelector;
1072 });
1073
1074 (function(scope) {
1075 var initializeModules = scope.initializeModules;
1076 var isIE = scope.isIE;
1077 if (scope.useNative) {
1078 return;
1079 }
1080 if (isIE && typeof window.CustomEvent !== "function") {
1081 window.CustomEvent = function(inType, params) {
1082 params = params || {};
1083 var e = document.createEvent("CustomEvent");
1084 e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelab le), params.detail);
1085 return e;
1086 };
1087 window.CustomEvent.prototype = window.Event.prototype;
1088 }
1089 initializeModules();
1090 var rootDocument = scope.rootDocument;
1091 function bootstrap() {
1092 HTMLImports.importer.bootDocument(rootDocument);
1093 }
1094 if (document.readyState === "complete" || document.readyState === "interactive " && !window.attachEvent) {
1095 bootstrap();
1096 } else {
1097 document.addEventListener("DOMContentLoaded", bootstrap);
1098 }
1099 })(HTMLImports);
1100
1101 window.CustomElements = window.CustomElements || {
1102 flags: {}
1103 };
1104
1105 (function(scope) {
1106 var flags = scope.flags;
1107 var modules = [];
1108 var addModule = function(module) {
1109 modules.push(module);
1110 };
1111 var initializeModules = function() {
1112 modules.forEach(function(module) {
1113 module(scope);
1114 });
1115 };
1116 scope.addModule = addModule;
1117 scope.initializeModules = initializeModules;
1118 scope.hasNative = Boolean(document.registerElement);
1119 scope.useNative = !flags.register && scope.hasNative && !window.ShadowDOMPolyf ill && (!window.HTMLImports || HTMLImports.useNative);
1120 })(CustomElements);
1121
1122 CustomElements.addModule(function(scope) {
1123 var IMPORT_LINK_TYPE = window.HTMLImports ? HTMLImports.IMPORT_LINK_TYPE : "no ne";
1124 function forSubtree(node, cb) {
1125 findAllElements(node, function(e) {
1126 if (cb(e)) {
1127 return true;
1128 }
1129 forRoots(e, cb);
1130 });
1131 forRoots(node, cb);
1132 }
1133 function findAllElements(node, find, data) {
1134 var e = node.firstElementChild;
1135 if (!e) {
1136 e = node.firstChild;
1137 while (e && e.nodeType !== Node.ELEMENT_NODE) {
1138 e = e.nextSibling;
1139 }
1140 }
1141 while (e) {
1142 if (find(e, data) !== true) {
1143 findAllElements(e, find, data);
1144 }
1145 e = e.nextElementSibling;
1146 }
1147 return null;
1148 }
1149 function forRoots(node, cb) {
1150 var root = node.shadowRoot;
1151 while (root) {
1152 forSubtree(root, cb);
1153 root = root.olderShadowRoot;
1154 }
1155 }
1156 var processingDocuments;
1157 function forDocumentTree(doc, cb) {
1158 processingDocuments = [];
1159 _forDocumentTree(doc, cb);
1160 processingDocuments = null;
1161 }
1162 function _forDocumentTree(doc, cb) {
1163 doc = wrap(doc);
1164 if (processingDocuments.indexOf(doc) >= 0) {
1165 return;
1166 }
1167 processingDocuments.push(doc);
1168 var imports = doc.querySelectorAll("link[rel=" + IMPORT_LINK_TYPE + "]");
1169 for (var i = 0, l = imports.length, n; i < l && (n = imports[i]); i++) {
1170 if (n.import) {
1171 _forDocumentTree(n.import, cb);
1172 }
1173 }
1174 cb(doc);
1175 }
1176 scope.forDocumentTree = forDocumentTree;
1177 scope.forSubtree = forSubtree;
1178 });
1179
1180 CustomElements.addModule(function(scope) {
1181 var flags = scope.flags;
1182 var forSubtree = scope.forSubtree;
1183 var forDocumentTree = scope.forDocumentTree;
1184 function addedNode(node) {
1185 return added(node) || addedSubtree(node);
1186 }
1187 function added(node) {
1188 if (scope.upgrade(node)) {
1189 return true;
1190 }
1191 attached(node);
1192 }
1193 function addedSubtree(node) {
1194 forSubtree(node, function(e) {
1195 if (added(e)) {
1196 return true;
1197 }
1198 });
1199 }
1200 function attachedNode(node) {
1201 attached(node);
1202 if (inDocument(node)) {
1203 forSubtree(node, function(e) {
1204 attached(e);
1205 });
1206 }
1207 }
1208 var hasPolyfillMutations = !window.MutationObserver || window.MutationObserver === window.JsMutationObserver;
1209 scope.hasPolyfillMutations = hasPolyfillMutations;
1210 var isPendingMutations = false;
1211 var pendingMutations = [];
1212 function deferMutation(fn) {
1213 pendingMutations.push(fn);
1214 if (!isPendingMutations) {
1215 isPendingMutations = true;
1216 setTimeout(takeMutations);
1217 }
1218 }
1219 function takeMutations() {
1220 isPendingMutations = false;
1221 var $p = pendingMutations;
1222 for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) {
1223 p();
1224 }
1225 pendingMutations = [];
1226 }
1227 function attached(element) {
1228 if (hasPolyfillMutations) {
1229 deferMutation(function() {
1230 _attached(element);
1231 });
1232 } else {
1233 _attached(element);
1234 }
1235 }
1236 function _attached(element) {
1237 if (element.__upgraded__ && (element.attachedCallback || element.detachedCal lback)) {
1238 if (!element.__attached && inDocument(element)) {
1239 element.__attached = true;
1240 if (element.attachedCallback) {
1241 element.attachedCallback();
1242 }
1243 }
1244 }
1245 }
1246 function detachedNode(node) {
1247 detached(node);
1248 forSubtree(node, function(e) {
1249 detached(e);
1250 });
1251 }
1252 function detached(element) {
1253 if (hasPolyfillMutations) {
1254 deferMutation(function() {
1255 _detached(element);
1256 });
1257 } else {
1258 _detached(element);
1259 }
1260 }
1261 function _detached(element) {
1262 if (element.__upgraded__ && (element.attachedCallback || element.detachedCal lback)) {
1263 if (element.__attached && !inDocument(element)) {
1264 element.__attached = false;
1265 if (element.detachedCallback) {
1266 element.detachedCallback();
1267 }
1268 }
1269 }
1270 }
1271 function inDocument(element) {
1272 var p = element;
1273 var doc = wrap(document);
1274 while (p) {
1275 if (p == doc) {
1276 return true;
1277 }
1278 p = p.parentNode || p.host;
1279 }
1280 }
1281 function watchShadow(node) {
1282 if (node.shadowRoot && !node.shadowRoot.__watched) {
1283 flags.dom && console.log("watching shadow-root for: ", node.localName);
1284 var root = node.shadowRoot;
1285 while (root) {
1286 observe(root);
1287 root = root.olderShadowRoot;
1288 }
1289 }
1290 }
1291 function handler(mutations) {
1292 if (flags.dom) {
1293 var mx = mutations[0];
1294 if (mx && mx.type === "childList" && mx.addedNodes) {
1295 if (mx.addedNodes) {
1296 var d = mx.addedNodes[0];
1297 while (d && d !== document && !d.host) {
1298 d = d.parentNode;
1299 }
1300 var u = d && (d.URL || d._URL || d.host && d.host.localName) || "";
1301 u = u.split("/?").shift().split("/").pop();
1302 }
1303 }
1304 console.group("mutations (%d) [%s]", mutations.length, u || "");
1305 }
1306 mutations.forEach(function(mx) {
1307 if (mx.type === "childList") {
1308 forEach(mx.addedNodes, function(n) {
1309 if (!n.localName) {
1310 return;
1311 }
1312 addedNode(n);
1313 });
1314 forEach(mx.removedNodes, function(n) {
1315 if (!n.localName) {
1316 return;
1317 }
1318 detachedNode(n);
1319 });
1320 }
1321 });
1322 flags.dom && console.groupEnd();
1323 }
1324 function takeRecords(node) {
1325 node = wrap(node);
1326 if (!node) {
1327 node = wrap(document);
1328 }
1329 while (node.parentNode) {
1330 node = node.parentNode;
1331 }
1332 var observer = node.__observer;
1333 if (observer) {
1334 handler(observer.takeRecords());
1335 takeMutations();
1336 }
1337 }
1338 var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach);
1339 function observe(inRoot) {
1340 if (inRoot.__observer) {
1341 return;
1342 }
1343 var observer = new MutationObserver(handler);
1344 observer.observe(inRoot, {
1345 childList: true,
1346 subtree: true
1347 });
1348 inRoot.__observer = observer;
1349 }
1350 function upgradeDocument(doc) {
1351 doc = wrap(doc);
1352 flags.dom && console.group("upgradeDocument: ", doc.baseURI.split("/").pop() );
1353 addedNode(doc);
1354 observe(doc);
1355 flags.dom && console.groupEnd();
1356 }
1357 function upgradeDocumentTree(doc) {
1358 forDocumentTree(doc, upgradeDocument);
1359 }
1360 var originalCreateShadowRoot = Element.prototype.createShadowRoot;
1361 Element.prototype.createShadowRoot = function() {
1362 var root = originalCreateShadowRoot.call(this);
1363 CustomElements.watchShadow(this);
1364 return root;
1365 };
1366 scope.watchShadow = watchShadow;
1367 scope.upgradeDocumentTree = upgradeDocumentTree;
1368 scope.upgradeSubtree = addedSubtree;
1369 scope.upgradeAll = addedNode;
1370 scope.attachedNode = attachedNode;
1371 scope.takeRecords = takeRecords;
1372 });
1373
1374 CustomElements.addModule(function(scope) {
1375 var flags = scope.flags;
1376 function upgrade(node) {
1377 if (!node.__upgraded__ && node.nodeType === Node.ELEMENT_NODE) {
1378 var is = node.getAttribute("is");
1379 var definition = scope.getRegisteredDefinition(is || node.localName);
1380 if (definition) {
1381 if (is && definition.tag == node.localName) {
1382 return upgradeWithDefinition(node, definition);
1383 } else if (!is && !definition.extends) {
1384 return upgradeWithDefinition(node, definition);
1385 }
1386 }
1387 }
1388 }
1389 function upgradeWithDefinition(element, definition) {
1390 flags.upgrade && console.group("upgrade:", element.localName);
1391 if (definition.is) {
1392 element.setAttribute("is", definition.is);
1393 }
1394 implementPrototype(element, definition);
1395 element.__upgraded__ = true;
1396 created(element);
1397 scope.attachedNode(element);
1398 scope.upgradeSubtree(element);
1399 flags.upgrade && console.groupEnd();
1400 return element;
1401 }
1402 function implementPrototype(element, definition) {
1403 if (Object.__proto__) {
1404 element.__proto__ = definition.prototype;
1405 } else {
1406 customMixin(element, definition.prototype, definition.native);
1407 element.__proto__ = definition.prototype;
1408 }
1409 }
1410 function customMixin(inTarget, inSrc, inNative) {
1411 var used = {};
1412 var p = inSrc;
1413 while (p !== inNative && p !== HTMLElement.prototype) {
1414 var keys = Object.getOwnPropertyNames(p);
1415 for (var i = 0, k; k = keys[i]; i++) {
1416 if (!used[k]) {
1417 Object.defineProperty(inTarget, k, Object.getOwnPropertyDescriptor(p, k));
1418 used[k] = 1;
1419 }
1420 }
1421 p = Object.getPrototypeOf(p);
1422 }
1423 }
1424 function created(element) {
1425 if (element.createdCallback) {
1426 element.createdCallback();
1427 }
1428 }
1429 scope.upgrade = upgrade;
1430 scope.upgradeWithDefinition = upgradeWithDefinition;
1431 scope.implementPrototype = implementPrototype;
1432 });
1433
1434 CustomElements.addModule(function(scope) {
1435 var upgradeDocumentTree = scope.upgradeDocumentTree;
1436 var upgrade = scope.upgrade;
1437 var upgradeWithDefinition = scope.upgradeWithDefinition;
1438 var implementPrototype = scope.implementPrototype;
1439 var useNative = scope.useNative;
1440 function register(name, options) {
1441 var definition = options || {};
1442 if (!name) {
1443 throw new Error("document.registerElement: first argument `name` must not be empty");
1444 }
1445 if (name.indexOf("-") < 0) {
1446 throw new Error("document.registerElement: first argument ('name') must co ntain a dash ('-'). Argument provided was '" + String(name) + "'.");
1447 }
1448 if (isReservedTag(name)) {
1449 throw new Error("Failed to execute 'registerElement' on 'Document': Regist ration failed for type '" + String(name) + "'. The type name is invalid.");
1450 }
1451 if (getRegisteredDefinition(name)) {
1452 throw new Error("DuplicateDefinitionError: a type with name '" + String(na me) + "' is already registered");
1453 }
1454 if (!definition.prototype) {
1455 definition.prototype = Object.create(HTMLElement.prototype);
1456 }
1457 definition.__name = name.toLowerCase();
1458 definition.lifecycle = definition.lifecycle || {};
1459 definition.ancestry = ancestry(definition.extends);
1460 resolveTagName(definition);
1461 resolvePrototypeChain(definition);
1462 overrideAttributeApi(definition.prototype);
1463 registerDefinition(definition.__name, definition);
1464 definition.ctor = generateConstructor(definition);
1465 definition.ctor.prototype = definition.prototype;
1466 definition.prototype.constructor = definition.ctor;
1467 if (scope.ready) {
1468 upgradeDocumentTree(document);
1469 }
1470 return definition.ctor;
1471 }
1472 function overrideAttributeApi(prototype) {
1473 if (prototype.setAttribute._polyfilled) {
1474 return;
1475 }
1476 var setAttribute = prototype.setAttribute;
1477 prototype.setAttribute = function(name, value) {
1478 changeAttribute.call(this, name, value, setAttribute);
1479 };
1480 var removeAttribute = prototype.removeAttribute;
1481 prototype.removeAttribute = function(name) {
1482 changeAttribute.call(this, name, null, removeAttribute);
1483 };
1484 prototype.setAttribute._polyfilled = true;
1485 }
1486 function changeAttribute(name, value, operation) {
1487 name = name.toLowerCase();
1488 var oldValue = this.getAttribute(name);
1489 operation.apply(this, arguments);
1490 var newValue = this.getAttribute(name);
1491 if (this.attributeChangedCallback && newValue !== oldValue) {
1492 this.attributeChangedCallback(name, oldValue, newValue);
1493 }
1494 }
1495 function isReservedTag(name) {
1496 for (var i = 0; i < reservedTagList.length; i++) {
1497 if (name === reservedTagList[i]) {
1498 return true;
1499 }
1500 }
1501 }
1502 var reservedTagList = [ "annotation-xml", "color-profile", "font-face", "font- face-src", "font-face-uri", "font-face-format", "font-face-name", "missing-glyph " ];
1503 function ancestry(extnds) {
1504 var extendee = getRegisteredDefinition(extnds);
1505 if (extendee) {
1506 return ancestry(extendee.extends).concat([ extendee ]);
1507 }
1508 return [];
1509 }
1510 function resolveTagName(definition) {
1511 var baseTag = definition.extends;
1512 for (var i = 0, a; a = definition.ancestry[i]; i++) {
1513 baseTag = a.is && a.tag;
1514 }
1515 definition.tag = baseTag || definition.__name;
1516 if (baseTag) {
1517 definition.is = definition.__name;
1518 }
1519 }
1520 function resolvePrototypeChain(definition) {
1521 if (!Object.__proto__) {
1522 var nativePrototype = HTMLElement.prototype;
1523 if (definition.is) {
1524 var inst = document.createElement(definition.tag);
1525 var expectedPrototype = Object.getPrototypeOf(inst);
1526 if (expectedPrototype === definition.prototype) {
1527 nativePrototype = expectedPrototype;
1528 }
1529 }
1530 var proto = definition.prototype, ancestor;
1531 while (proto && proto !== nativePrototype) {
1532 ancestor = Object.getPrototypeOf(proto);
1533 proto.__proto__ = ancestor;
1534 proto = ancestor;
1535 }
1536 definition.native = nativePrototype;
1537 }
1538 }
1539 function instantiate(definition) {
1540 return upgradeWithDefinition(domCreateElement(definition.tag), definition);
1541 }
1542 var registry = {};
1543 function getRegisteredDefinition(name) {
1544 if (name) {
1545 return registry[name.toLowerCase()];
1546 }
1547 }
1548 function registerDefinition(name, definition) {
1549 registry[name] = definition;
1550 }
1551 function generateConstructor(definition) {
1552 return function() {
1553 return instantiate(definition);
1554 };
1555 }
1556 var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
1557 function createElementNS(namespace, tag, typeExtension) {
1558 if (namespace === HTML_NAMESPACE) {
1559 return createElement(tag, typeExtension);
1560 } else {
1561 return domCreateElementNS(namespace, tag);
1562 }
1563 }
1564 function createElement(tag, typeExtension) {
1565 var definition = getRegisteredDefinition(typeExtension || tag);
1566 if (definition) {
1567 if (tag == definition.tag && typeExtension == definition.is) {
1568 return new definition.ctor();
1569 }
1570 if (!typeExtension && !definition.is) {
1571 return new definition.ctor();
1572 }
1573 }
1574 var element;
1575 if (typeExtension) {
1576 element = createElement(tag);
1577 element.setAttribute("is", typeExtension);
1578 return element;
1579 }
1580 element = domCreateElement(tag);
1581 if (tag.indexOf("-") >= 0) {
1582 implementPrototype(element, HTMLElement);
1583 }
1584 return element;
1585 }
1586 function cloneNode(deep) {
1587 var n = domCloneNode.call(this, deep);
1588 upgrade(n);
1589 return n;
1590 }
1591 var domCreateElement = document.createElement.bind(document);
1592 var domCreateElementNS = document.createElementNS.bind(document);
1593 var domCloneNode = Node.prototype.cloneNode;
1594 var isInstance;
1595 if (!Object.__proto__ && !useNative) {
1596 isInstance = function(obj, ctor) {
1597 var p = obj;
1598 while (p) {
1599 if (p === ctor.prototype) {
1600 return true;
1601 }
1602 p = p.__proto__;
1603 }
1604 return false;
1605 };
1606 } else {
1607 isInstance = function(obj, base) {
1608 return obj instanceof base;
1609 };
1610 }
1611 document.registerElement = register;
1612 document.createElement = createElement;
1613 document.createElementNS = createElementNS;
1614 Node.prototype.cloneNode = cloneNode;
1615 scope.registry = registry;
1616 scope.instanceof = isInstance;
1617 scope.reservedTagList = reservedTagList;
1618 scope.getRegisteredDefinition = getRegisteredDefinition;
1619 document.register = document.registerElement;
1620 });
1621
1622 (function(scope) {
1623 var useNative = scope.useNative;
1624 var initializeModules = scope.initializeModules;
1625 var isIE11OrOlder = /Trident/.test(navigator.userAgent);
1626 if (useNative) {
1627 var nop = function() {};
1628 scope.watchShadow = nop;
1629 scope.upgrade = nop;
1630 scope.upgradeAll = nop;
1631 scope.upgradeDocumentTree = nop;
1632 scope.upgradeSubtree = nop;
1633 scope.takeRecords = nop;
1634 scope.instanceof = function(obj, base) {
1635 return obj instanceof base;
1636 };
1637 } else {
1638 initializeModules();
1639 }
1640 var upgradeDocumentTree = scope.upgradeDocumentTree;
1641 if (!window.wrap) {
1642 if (window.ShadowDOMPolyfill) {
1643 window.wrap = ShadowDOMPolyfill.wrapIfNeeded;
1644 window.unwrap = ShadowDOMPolyfill.unwrapIfNeeded;
1645 } else {
1646 window.wrap = window.unwrap = function(node) {
1647 return node;
1648 };
1649 }
1650 }
1651 function bootstrap() {
1652 upgradeDocumentTree(wrap(document));
1653 if (window.HTMLImports) {
1654 HTMLImports.__importsParsingHook = function(elt) {
1655 upgradeDocumentTree(wrap(elt.import));
1656 };
1657 }
1658 CustomElements.ready = true;
1659 setTimeout(function() {
1660 CustomElements.readyTime = Date.now();
1661 if (window.HTMLImports) {
1662 CustomElements.elapsed = CustomElements.readyTime - HTMLImports.readyTim e;
1663 }
1664 document.dispatchEvent(new CustomEvent("WebComponentsReady", {
1665 bubbles: true
1666 }));
1667 });
1668 }
1669 if (isIE11OrOlder && typeof window.CustomEvent !== "function") {
1670 window.CustomEvent = function(inType, params) {
1671 params = params || {};
1672 var e = document.createEvent("CustomEvent");
1673 e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelab le), params.detail);
1674 return e;
1675 };
1676 window.CustomEvent.prototype = window.Event.prototype;
1677 }
1678 if (document.readyState === "complete" || scope.flags.eager) {
1679 bootstrap();
1680 } else if (document.readyState === "interactive" && !window.attachEvent && (!w indow.HTMLImports || window.HTMLImports.ready)) {
1681 bootstrap();
1682 } else {
1683 var loadEvent = window.HTMLImports && !HTMLImports.ready ? "HTMLImportsLoade d" : "DOMContentLoaded";
1684 window.addEventListener(loadEvent, bootstrap);
1685 }
1686 })(window.CustomElements);
1687
1688 if (typeof HTMLTemplateElement === "undefined") {
1689 (function() {
1690 var TEMPLATE_TAG = "template";
1691 HTMLTemplateElement = function() {};
1692 HTMLTemplateElement.prototype = Object.create(HTMLElement.prototype);
1693 HTMLTemplateElement.decorate = function(template) {
1694 if (!template.content) {
1695 template.content = template.ownerDocument.createDocumentFragment();
1696 var child;
1697 while (child = template.firstChild) {
1698 template.content.appendChild(child);
1699 }
1700 }
1701 };
1702 HTMLTemplateElement.bootstrap = function(doc) {
1703 var templates = doc.querySelectorAll(TEMPLATE_TAG);
1704 for (var i = 0, l = templates.length, t; i < l && (t = templates[i]); i++) {
1705 HTMLTemplateElement.decorate(t);
1706 }
1707 };
1708 addEventListener("DOMContentLoaded", function() {
1709 HTMLTemplateElement.bootstrap(document);
1710 });
1711 })();
1712 }
1713
1714 (function(scope) {
1715 var style = document.createElement("style");
1716 style.textContent = "" + "body {" + "transition: opacity ease-in 0.2s;" + " } \n" + "body[unresolved] {" + "opacity: 0; display: block; overflow: hidden; posi tion: relative;" + " } \n";
1717 var head = document.querySelector("head");
1718 head.insertBefore(style, head.firstChild);
1719 })(window.WebComponents);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698