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

Side by Side Diff: third_party/polymer/components/webcomponentsjs/webcomponents-lite.js

Issue 2113853002: Run bower update (Closed) Base URL: https://github.com/catapult-project/catapult@polymer10-migration
Patch Set: Created 4 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
1 /** 1 /**
2 * @license 2 * @license
3 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. 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 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 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 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 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 8 * subject to an additional IP rights grant found at http://polymer.github.io/PA TENTS.txt
9 */ 9 */
10 // @version 0.7.22 10 // @version 0.6.1
11 (function() { 11 window.WebComponents = window.WebComponents || {};
12 window.WebComponents = window.WebComponents || { 12
13 flags: {} 13 (function(scope) {
14 }; 14 var flags = scope.flags || {};
15 var file = "webcomponents-lite.js"; 15 var file = "webcomponents.js";
16 var script = document.querySelector('script[src*="' + file + '"]'); 16 var script = document.querySelector('script[src*="' + file + '"]');
17 var flags = {};
18 if (!flags.noOpts) { 17 if (!flags.noOpts) {
19 location.search.slice(1).split("&").forEach(function(option) { 18 location.search.slice(1).split("&").forEach(function(o) {
20 var parts = option.split("="); 19 o = o.split("=");
21 var match; 20 o[0] && (flags[o[0]] = o[1] || true);
22 if (parts[0] && (match = parts[0].match(/wc-(.+)/))) {
23 flags[match[1]] = parts[1] || true;
24 }
25 }); 21 });
26 if (script) { 22 if (script) {
27 for (var i = 0, a; a = script.attributes[i]; i++) { 23 for (var i = 0, a; a = script.attributes[i]; i++) {
28 if (a.name !== "src") { 24 if (a.name !== "src") {
29 flags[a.name] = a.value || true; 25 flags[a.name] = a.value || true;
30 } 26 }
31 } 27 }
32 } 28 }
33 if (flags.log && flags.log.split) { 29 if (flags.log && flags.log.split) {
34 var parts = flags.log.split(","); 30 var parts = flags.log.split(",");
35 flags.log = {}; 31 flags.log = {};
36 parts.forEach(function(f) { 32 parts.forEach(function(f) {
37 flags.log[f] = true; 33 flags.log[f] = true;
38 }); 34 });
39 } else { 35 } else {
40 flags.log = {}; 36 flags.log = {};
41 } 37 }
42 } 38 }
39 flags.shadow = flags.shadow || flags.shadowdom || flags.polyfill;
40 if (flags.shadow === "native") {
41 flags.shadow = false;
42 } else {
43 flags.shadow = flags.shadow || !HTMLElement.prototype.createShadowRoot;
44 }
43 if (flags.register) { 45 if (flags.register) {
44 window.CustomElements = window.CustomElements || { 46 window.CustomElements = window.CustomElements || {
45 flags: {} 47 flags: {}
46 }; 48 };
47 window.CustomElements.flags.register = flags.register; 49 window.CustomElements.flags.register = flags.register;
48 } 50 }
49 WebComponents.flags = flags; 51 scope.flags = flags;
50 })(); 52 })(WebComponents);
51 53
52 (function(scope) { 54 (function(scope) {
53 "use strict"; 55 "use strict";
54 var hasWorkingUrl = false; 56 var hasWorkingUrl = false;
55 if (!scope.forceJURL) { 57 if (!scope.forceJURL) {
56 try { 58 try {
57 var u = new URL("b", "http://a"); 59 var u = new URL("b", "http://a");
58 u.pathname = "c%20d"; 60 u.pathname = "c%20d";
59 hasWorkingUrl = u.href === "http://a/c%20d"; 61 hasWorkingUrl = u.href === "http://a/c%20d";
60 } catch (e) {} 62 } catch (e) {}
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } else if (EOF == c) { 154 } else if (EOF == c) {
153 break loop; 155 break loop;
154 } else { 156 } else {
155 err("Code point not allowed in scheme: " + c); 157 err("Code point not allowed in scheme: " + c);
156 break loop; 158 break loop;
157 } 159 }
158 break; 160 break;
159 161
160 case "scheme data": 162 case "scheme data":
161 if ("?" == c) { 163 if ("?" == c) {
162 this._query = "?"; 164 query = "?";
163 state = "query"; 165 state = "query";
164 } else if ("#" == c) { 166 } else if ("#" == c) {
165 this._fragment = "#"; 167 this._fragment = "#";
166 state = "fragment"; 168 state = "fragment";
167 } else { 169 } else {
168 if (EOF != c && " " != c && "\n" != c && "\r" != c) { 170 if (EOF != c && " " != c && "\n" != c && "\r" != c) {
169 this._schemeData += percentEscape(c); 171 this._schemeData += percentEscape(c);
170 } 172 }
171 } 173 }
172 break; 174 break;
(...skipping 19 matching lines...) Expand all
192 break; 194 break;
193 195
194 case "relative": 196 case "relative":
195 this._isRelative = true; 197 this._isRelative = true;
196 if ("file" != this._scheme) this._scheme = base._scheme; 198 if ("file" != this._scheme) this._scheme = base._scheme;
197 if (EOF == c) { 199 if (EOF == c) {
198 this._host = base._host; 200 this._host = base._host;
199 this._port = base._port; 201 this._port = base._port;
200 this._path = base._path.slice(); 202 this._path = base._path.slice();
201 this._query = base._query; 203 this._query = base._query;
202 this._username = base._username;
203 this._password = base._password;
204 break loop; 204 break loop;
205 } else if ("/" == c || "\\" == c) { 205 } else if ("/" == c || "\\" == c) {
206 if ("\\" == c) err("\\ is an invalid code point."); 206 if ("\\" == c) err("\\ is an invalid code point.");
207 state = "relative slash"; 207 state = "relative slash";
208 } else if ("?" == c) { 208 } else if ("?" == c) {
209 this._host = base._host; 209 this._host = base._host;
210 this._port = base._port; 210 this._port = base._port;
211 this._path = base._path.slice(); 211 this._path = base._path.slice();
212 this._query = "?"; 212 this._query = "?";
213 this._username = base._username;
214 this._password = base._password;
215 state = "query"; 213 state = "query";
216 } else if ("#" == c) { 214 } else if ("#" == c) {
217 this._host = base._host; 215 this._host = base._host;
218 this._port = base._port; 216 this._port = base._port;
219 this._path = base._path.slice(); 217 this._path = base._path.slice();
220 this._query = base._query; 218 this._query = base._query;
221 this._fragment = "#"; 219 this._fragment = "#";
222 this._username = base._username;
223 this._password = base._password;
224 state = "fragment"; 220 state = "fragment";
225 } else { 221 } else {
226 var nextC = input[cursor + 1]; 222 var nextC = input[cursor + 1];
227 var nextNextC = input[cursor + 2]; 223 var nextNextC = input[cursor + 2];
228 if ("file" != this._scheme || !ALPHA.test(c) || nextC != ":" && nextC != "|" || EOF != nextNextC && "/" != nextNextC && "\\" != nextNextC && "?" != ne xtNextC && "#" != nextNextC) { 224 if ("file" != this._scheme || !ALPHA.test(c) || nextC != ":" && nextC != "|" || EOF != nextNextC && "/" != nextNextC && "\\" != nextNextC && "?" != ne xtNextC && "#" != nextNextC) {
229 this._host = base._host; 225 this._host = base._host;
230 this._port = base._port; 226 this._port = base._port;
231 this._username = base._username;
232 this._password = base._password;
233 this._path = base._path.slice(); 227 this._path = base._path.slice();
234 this._path.pop(); 228 this._path.pop();
235 } 229 }
236 state = "relative path"; 230 state = "relative path";
237 continue; 231 continue;
238 } 232 }
239 break; 233 break;
240 234
241 case "relative slash": 235 case "relative slash":
242 if ("/" == c || "\\" == c) { 236 if ("/" == c || "\\" == c) {
243 if ("\\" == c) { 237 if ("\\" == c) {
244 err("\\ is an invalid code point."); 238 err("\\ is an invalid code point.");
245 } 239 }
246 if ("file" == this._scheme) { 240 if ("file" == this._scheme) {
247 state = "file host"; 241 state = "file host";
248 } else { 242 } else {
249 state = "authority ignore slashes"; 243 state = "authority ignore slashes";
250 } 244 }
251 } else { 245 } else {
252 if ("file" != this._scheme) { 246 if ("file" != this._scheme) {
253 this._host = base._host; 247 this._host = base._host;
254 this._port = base._port; 248 this._port = base._port;
255 this._username = base._username;
256 this._password = base._password;
257 } 249 }
258 state = "relative path"; 250 state = "relative path";
259 continue; 251 continue;
260 } 252 }
261 break; 253 break;
262 254
263 case "authority first slash": 255 case "authority first slash":
264 if ("/" == c) { 256 if ("/" == c) {
265 state = "authority second slash"; 257 state = "authority second slash";
266 } else { 258 } else {
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 var OriginalURL = scope.URL; 554 var OriginalURL = scope.URL;
563 if (OriginalURL) { 555 if (OriginalURL) {
564 jURL.createObjectURL = function(blob) { 556 jURL.createObjectURL = function(blob) {
565 return OriginalURL.createObjectURL.apply(OriginalURL, arguments); 557 return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
566 }; 558 };
567 jURL.revokeObjectURL = function(url) { 559 jURL.revokeObjectURL = function(url) {
568 OriginalURL.revokeObjectURL(url); 560 OriginalURL.revokeObjectURL(url);
569 }; 561 };
570 } 562 }
571 scope.URL = jURL; 563 scope.URL = jURL;
572 })(self); 564 })(this);
573 565
574 if (typeof WeakMap === "undefined") { 566 if (typeof WeakMap === "undefined") {
575 (function() { 567 (function() {
576 var defineProperty = Object.defineProperty; 568 var defineProperty = Object.defineProperty;
577 var counter = Date.now() % 1e9; 569 var counter = Date.now() % 1e9;
578 var WeakMap = function() { 570 var WeakMap = function() {
579 this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__"); 571 this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__");
580 }; 572 };
581 WeakMap.prototype = { 573 WeakMap.prototype = {
582 set: function(key, value) { 574 set: function(key, value) {
(...skipping 18 matching lines...) Expand all
601 var entry = key[this.name]; 593 var entry = key[this.name];
602 if (!entry) return false; 594 if (!entry) return false;
603 return entry[0] === key; 595 return entry[0] === key;
604 } 596 }
605 }; 597 };
606 window.WeakMap = WeakMap; 598 window.WeakMap = WeakMap;
607 })(); 599 })();
608 } 600 }
609 601
610 (function(global) { 602 (function(global) {
611 if (global.JsMutationObserver) {
612 return;
613 }
614 var registrationsTable = new WeakMap(); 603 var registrationsTable = new WeakMap();
615 var setImmediate; 604 var setImmediate;
616 if (/Trident|Edge/.test(navigator.userAgent)) { 605 if (/Trident|Edge/.test(navigator.userAgent)) {
617 setImmediate = setTimeout; 606 setImmediate = setTimeout;
618 } else if (window.setImmediate) { 607 } else if (window.setImmediate) {
619 setImmediate = window.setImmediate; 608 setImmediate = window.setImmediate;
620 } else { 609 } else {
621 var setImmediateQueue = []; 610 var setImmediateQueue = [];
622 var sentinel = String(Math.random()); 611 var sentinel = String(Math.random());
623 window.addEventListener("message", function(e) { 612 window.addEventListener("message", function(e) {
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 record.nextSibling = nextSibling; 888 record.nextSibling = nextSibling;
900 forEachAncestorAndObserverEnqueueRecord(e.relatedNode, function(options) { 889 forEachAncestorAndObserverEnqueueRecord(e.relatedNode, function(options) {
901 if (!options.childList) return; 890 if (!options.childList) return;
902 return record; 891 return record;
903 }); 892 });
904 } 893 }
905 clearRecords(); 894 clearRecords();
906 } 895 }
907 }; 896 };
908 global.JsMutationObserver = JsMutationObserver; 897 global.JsMutationObserver = JsMutationObserver;
909 if (!global.MutationObserver) { 898 if (!global.MutationObserver) global.MutationObserver = JsMutationObserver;
910 global.MutationObserver = JsMutationObserver; 899 })(this);
911 JsMutationObserver._isPolyfilled = true;
912 }
913 })(self);
914
915 (function() {
916 var needsTemplate = typeof HTMLTemplateElement === "undefined";
917 if (/Trident/.test(navigator.userAgent)) {
918 (function() {
919 var importNode = document.importNode;
920 document.importNode = function() {
921 var n = importNode.apply(document, arguments);
922 if (n.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
923 var f = document.createDocumentFragment();
924 f.appendChild(n);
925 return f;
926 } else {
927 return n;
928 }
929 };
930 })();
931 }
932 var needsCloning = function() {
933 if (!needsTemplate) {
934 var t = document.createElement("template");
935 var t2 = document.createElement("template");
936 t2.content.appendChild(document.createElement("div"));
937 t.content.appendChild(t2);
938 var clone = t.cloneNode(true);
939 return clone.content.childNodes.length === 0 || clone.content.firstChild.c ontent.childNodes.length === 0;
940 }
941 }();
942 var TEMPLATE_TAG = "template";
943 var TemplateImpl = function() {};
944 if (needsTemplate) {
945 var contentDoc = document.implementation.createHTMLDocument("template");
946 var canDecorate = true;
947 var templateStyle = document.createElement("style");
948 templateStyle.textContent = TEMPLATE_TAG + "{display:none;}";
949 var head = document.head;
950 head.insertBefore(templateStyle, head.firstElementChild);
951 TemplateImpl.prototype = Object.create(HTMLElement.prototype);
952 TemplateImpl.decorate = function(template) {
953 if (template.content) {
954 return;
955 }
956 template.content = contentDoc.createDocumentFragment();
957 var child;
958 while (child = template.firstChild) {
959 template.content.appendChild(child);
960 }
961 template.cloneNode = function(deep) {
962 return TemplateImpl.cloneNode(this, deep);
963 };
964 if (canDecorate) {
965 try {
966 Object.defineProperty(template, "innerHTML", {
967 get: function() {
968 var o = "";
969 for (var e = this.content.firstChild; e; e = e.nextSibling) {
970 o += e.outerHTML || escapeData(e.data);
971 }
972 return o;
973 },
974 set: function(text) {
975 contentDoc.body.innerHTML = text;
976 TemplateImpl.bootstrap(contentDoc);
977 while (this.content.firstChild) {
978 this.content.removeChild(this.content.firstChild);
979 }
980 while (contentDoc.body.firstChild) {
981 this.content.appendChild(contentDoc.body.firstChild);
982 }
983 },
984 configurable: true
985 });
986 } catch (err) {
987 canDecorate = false;
988 }
989 }
990 TemplateImpl.bootstrap(template.content);
991 };
992 TemplateImpl.bootstrap = function(doc) {
993 var templates = doc.querySelectorAll(TEMPLATE_TAG);
994 for (var i = 0, l = templates.length, t; i < l && (t = templates[i]); i++) {
995 TemplateImpl.decorate(t);
996 }
997 };
998 document.addEventListener("DOMContentLoaded", function() {
999 TemplateImpl.bootstrap(document);
1000 });
1001 var createElement = document.createElement;
1002 document.createElement = function() {
1003 "use strict";
1004 var el = createElement.apply(document, arguments);
1005 if (el.localName === "template") {
1006 TemplateImpl.decorate(el);
1007 }
1008 return el;
1009 };
1010 var escapeDataRegExp = /[&\u00A0<>]/g;
1011 function escapeReplace(c) {
1012 switch (c) {
1013 case "&":
1014 return "&amp;";
1015
1016 case "<":
1017 return "&lt;";
1018
1019 case ">":
1020 return "&gt;";
1021
1022 case " ":
1023 return "&nbsp;";
1024 }
1025 }
1026 function escapeData(s) {
1027 return s.replace(escapeDataRegExp, escapeReplace);
1028 }
1029 }
1030 if (needsTemplate || needsCloning) {
1031 var nativeCloneNode = Node.prototype.cloneNode;
1032 TemplateImpl.cloneNode = function(template, deep) {
1033 var clone = nativeCloneNode.call(template, false);
1034 if (this.decorate) {
1035 this.decorate(clone);
1036 }
1037 if (deep) {
1038 clone.content.appendChild(nativeCloneNode.call(template.content, true));
1039 this.fixClonedDom(clone.content, template.content);
1040 }
1041 return clone;
1042 };
1043 TemplateImpl.fixClonedDom = function(clone, source) {
1044 if (!source.querySelectorAll) return;
1045 var s$ = source.querySelectorAll(TEMPLATE_TAG);
1046 var t$ = clone.querySelectorAll(TEMPLATE_TAG);
1047 for (var i = 0, l = t$.length, t, s; i < l; i++) {
1048 s = s$[i];
1049 t = t$[i];
1050 if (this.decorate) {
1051 this.decorate(s);
1052 }
1053 t.parentNode.replaceChild(s.cloneNode(true), t);
1054 }
1055 };
1056 var originalImportNode = document.importNode;
1057 Node.prototype.cloneNode = function(deep) {
1058 var dom = nativeCloneNode.call(this, deep);
1059 if (deep) {
1060 TemplateImpl.fixClonedDom(dom, this);
1061 }
1062 return dom;
1063 };
1064 document.importNode = function(element, deep) {
1065 if (element.localName === TEMPLATE_TAG) {
1066 return TemplateImpl.cloneNode(element, deep);
1067 } else {
1068 var dom = originalImportNode.call(document, element, deep);
1069 if (deep) {
1070 TemplateImpl.fixClonedDom(dom, element);
1071 }
1072 return dom;
1073 }
1074 };
1075 if (needsCloning) {
1076 HTMLTemplateElement.prototype.cloneNode = function(deep) {
1077 return TemplateImpl.cloneNode(this, deep);
1078 };
1079 }
1080 }
1081 if (needsTemplate) {
1082 window.HTMLTemplateElement = TemplateImpl;
1083 }
1084 })();
1085
1086 (function(scope) {
1087 "use strict";
1088 if (!window.performance) {
1089 var start = Date.now();
1090 window.performance = {
1091 now: function() {
1092 return Date.now() - start;
1093 }
1094 };
1095 }
1096 if (!window.requestAnimationFrame) {
1097 window.requestAnimationFrame = function() {
1098 var nativeRaf = window.webkitRequestAnimationFrame || window.mozRequestAni mationFrame;
1099 return nativeRaf ? function(callback) {
1100 return nativeRaf(function() {
1101 callback(performance.now());
1102 });
1103 } : function(callback) {
1104 return window.setTimeout(callback, 1e3 / 60);
1105 };
1106 }();
1107 }
1108 if (!window.cancelAnimationFrame) {
1109 window.cancelAnimationFrame = function() {
1110 return window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || function(id) {
1111 clearTimeout(id);
1112 };
1113 }();
1114 }
1115 var workingDefaultPrevented = function() {
1116 var e = document.createEvent("Event");
1117 e.initEvent("foo", true, true);
1118 e.preventDefault();
1119 return e.defaultPrevented;
1120 }();
1121 if (!workingDefaultPrevented) {
1122 var origPreventDefault = Event.prototype.preventDefault;
1123 Event.prototype.preventDefault = function() {
1124 if (!this.cancelable) {
1125 return;
1126 }
1127 origPreventDefault.call(this);
1128 Object.defineProperty(this, "defaultPrevented", {
1129 get: function() {
1130 return true;
1131 },
1132 configurable: true
1133 });
1134 };
1135 }
1136 var isIE = /Trident/.test(navigator.userAgent);
1137 if (!window.CustomEvent || isIE && typeof window.CustomEvent !== "function") {
1138 window.CustomEvent = function(inType, params) {
1139 params = params || {};
1140 var e = document.createEvent("CustomEvent");
1141 e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelab le), params.detail);
1142 return e;
1143 };
1144 window.CustomEvent.prototype = window.Event.prototype;
1145 }
1146 if (!window.Event || isIE && typeof window.Event !== "function") {
1147 var origEvent = window.Event;
1148 window.Event = function(inType, params) {
1149 params = params || {};
1150 var e = document.createEvent("Event");
1151 e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable));
1152 return e;
1153 };
1154 window.Event.prototype = origEvent.prototype;
1155 }
1156 })(window.WebComponents);
1157 900
1158 window.HTMLImports = window.HTMLImports || { 901 window.HTMLImports = window.HTMLImports || {
1159 flags: {} 902 flags: {}
1160 }; 903 };
1161 904
1162 (function(scope) { 905 (function(scope) {
1163 var IMPORT_LINK_TYPE = "import"; 906 var IMPORT_LINK_TYPE = "import";
1164 var useNative = Boolean(IMPORT_LINK_TYPE in document.createElement("link")); 907 var useNative = Boolean(IMPORT_LINK_TYPE in document.createElement("link"));
1165 var hasShadowDOMPolyfill = Boolean(window.ShadowDOMPolyfill); 908 var hasShadowDOMPolyfill = Boolean(window.ShadowDOMPolyfill);
1166 var wrap = function(node) { 909 var wrap = function(node) {
1167 return hasShadowDOMPolyfill ? window.ShadowDOMPolyfill.wrapIfNeeded(node) : node; 910 return hasShadowDOMPolyfill ? ShadowDOMPolyfill.wrapIfNeeded(node) : node;
1168 }; 911 };
1169 var rootDocument = wrap(document); 912 var rootDocument = wrap(document);
1170 var currentScriptDescriptor = { 913 var currentScriptDescriptor = {
1171 get: function() { 914 get: function() {
1172 var script = window.HTMLImports.currentScript || document.currentScript || (document.readyState !== "complete" ? document.scripts[document.scripts.length - 1] : null); 915 var script = HTMLImports.currentScript || document.currentScript || (docum ent.readyState !== "complete" ? document.scripts[document.scripts.length - 1] : null);
1173 return wrap(script); 916 return wrap(script);
1174 }, 917 },
1175 configurable: true 918 configurable: true
1176 }; 919 };
1177 Object.defineProperty(document, "_currentScript", currentScriptDescriptor); 920 Object.defineProperty(document, "_currentScript", currentScriptDescriptor);
1178 Object.defineProperty(rootDocument, "_currentScript", currentScriptDescriptor) ; 921 Object.defineProperty(rootDocument, "_currentScript", currentScriptDescriptor) ;
1179 var isIE = /Trident/.test(navigator.userAgent); 922 var isIE = /Trident|Edge/.test(navigator.userAgent);
1180 function whenReady(callback, doc) { 923 function whenReady(callback, doc) {
1181 doc = doc || rootDocument; 924 doc = doc || rootDocument;
1182 whenDocumentReady(function() { 925 whenDocumentReady(function() {
1183 watchImportsLoad(callback, doc); 926 watchImportsLoad(callback, doc);
1184 }, doc); 927 }, doc);
1185 } 928 }
1186 var requiredReadyState = isIE ? "complete" : "interactive"; 929 var requiredReadyState = isIE ? "complete" : "interactive";
1187 var READY_EVENT = "readystatechange"; 930 var READY_EVENT = "readystatechange";
1188 function isDocumentReady(doc) { 931 function isDocumentReady(doc) {
1189 return doc.readyState === "complete" || doc.readyState === requiredReadyStat e; 932 return doc.readyState === "complete" || doc.readyState === requiredReadyStat e;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 checkDone(); 966 checkDone();
1224 } 967 }
1225 function errorLoadingImport(e) { 968 function errorLoadingImport(e) {
1226 errorImports.push(this); 969 errorImports.push(this);
1227 parsedCount++; 970 parsedCount++;
1228 checkDone(); 971 checkDone();
1229 } 972 }
1230 if (importCount) { 973 if (importCount) {
1231 for (var i = 0, imp; i < importCount && (imp = imports[i]); i++) { 974 for (var i = 0, imp; i < importCount && (imp = imports[i]); i++) {
1232 if (isImportLoaded(imp)) { 975 if (isImportLoaded(imp)) {
1233 newImports.push(this);
1234 parsedCount++; 976 parsedCount++;
1235 checkDone(); 977 checkDone();
1236 } else { 978 } else {
1237 imp.addEventListener("load", loadedImport); 979 imp.addEventListener("load", loadedImport);
1238 imp.addEventListener("error", errorLoadingImport); 980 imp.addEventListener("error", errorLoadingImport);
1239 } 981 }
1240 } 982 }
1241 } else { 983 } else {
1242 checkDone(); 984 checkDone();
1243 } 985 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 (function() { 1021 (function() {
1280 if (document.readyState === "loading") { 1022 if (document.readyState === "loading") {
1281 var imports = document.querySelectorAll("link[rel=import]"); 1023 var imports = document.querySelectorAll("link[rel=import]");
1282 for (var i = 0, l = imports.length, imp; i < l && (imp = imports[i]); i+ +) { 1024 for (var i = 0, l = imports.length, imp; i < l && (imp = imports[i]); i+ +) {
1283 handleImport(imp); 1025 handleImport(imp);
1284 } 1026 }
1285 } 1027 }
1286 })(); 1028 })();
1287 } 1029 }
1288 whenReady(function(detail) { 1030 whenReady(function(detail) {
1289 window.HTMLImports.ready = true; 1031 HTMLImports.ready = true;
1290 window.HTMLImports.readyTime = new Date().getTime(); 1032 HTMLImports.readyTime = new Date().getTime();
1291 var evt = rootDocument.createEvent("CustomEvent"); 1033 var evt = rootDocument.createEvent("CustomEvent");
1292 evt.initCustomEvent("HTMLImportsLoaded", true, true, detail); 1034 evt.initCustomEvent("HTMLImportsLoaded", true, true, detail);
1293 rootDocument.dispatchEvent(evt); 1035 rootDocument.dispatchEvent(evt);
1294 }); 1036 });
1295 scope.IMPORT_LINK_TYPE = IMPORT_LINK_TYPE; 1037 scope.IMPORT_LINK_TYPE = IMPORT_LINK_TYPE;
1296 scope.useNative = useNative; 1038 scope.useNative = useNative;
1297 scope.rootDocument = rootDocument; 1039 scope.rootDocument = rootDocument;
1298 scope.whenReady = whenReady; 1040 scope.whenReady = whenReady;
1299 scope.isIE = isIE; 1041 scope.isIE = isIE;
1300 })(window.HTMLImports); 1042 })(HTMLImports);
1301 1043
1302 (function(scope) { 1044 (function(scope) {
1303 var modules = []; 1045 var modules = [];
1304 var addModule = function(module) { 1046 var addModule = function(module) {
1305 modules.push(module); 1047 modules.push(module);
1306 }; 1048 };
1307 var initializeModules = function() { 1049 var initializeModules = function() {
1308 modules.forEach(function(module) { 1050 modules.forEach(function(module) {
1309 module(scope); 1051 module(scope);
1310 }); 1052 });
1311 }; 1053 };
1312 scope.addModule = addModule; 1054 scope.addModule = addModule;
1313 scope.initializeModules = initializeModules; 1055 scope.initializeModules = initializeModules;
1314 })(window.HTMLImports); 1056 })(HTMLImports);
1315 1057
1316 window.HTMLImports.addModule(function(scope) { 1058 HTMLImports.addModule(function(scope) {
1317 var CSS_URL_REGEXP = /(url\()([^)]*)(\))/g; 1059 var CSS_URL_REGEXP = /(url\()([^)]*)(\))/g;
1318 var CSS_IMPORT_REGEXP = /(@import[\s]+(?!url\())([^;]*)(;)/g; 1060 var CSS_IMPORT_REGEXP = /(@import[\s]+(?!url\())([^;]*)(;)/g;
1319 var path = { 1061 var path = {
1320 resolveUrlsInStyle: function(style, linkUrl) { 1062 resolveUrlsInStyle: function(style, linkUrl) {
1321 var doc = style.ownerDocument; 1063 var doc = style.ownerDocument;
1322 var resolver = doc.createElement("a"); 1064 var resolver = doc.createElement("a");
1323 style.textContent = this.resolveUrlsInCssText(style.textContent, linkUrl, resolver); 1065 style.textContent = this.resolveUrlsInCssText(style.textContent, linkUrl, resolver);
1324 return style; 1066 return style;
1325 }, 1067 },
1326 resolveUrlsInCssText: function(cssText, linkUrl, urlObj) { 1068 resolveUrlsInCssText: function(cssText, linkUrl, urlObj) {
1327 var r = this.replaceUrls(cssText, urlObj, linkUrl, CSS_URL_REGEXP); 1069 var r = this.replaceUrls(cssText, urlObj, linkUrl, CSS_URL_REGEXP);
1328 r = this.replaceUrls(r, urlObj, linkUrl, CSS_IMPORT_REGEXP); 1070 r = this.replaceUrls(r, urlObj, linkUrl, CSS_IMPORT_REGEXP);
1329 return r; 1071 return r;
1330 }, 1072 },
1331 replaceUrls: function(text, urlObj, linkUrl, regexp) { 1073 replaceUrls: function(text, urlObj, linkUrl, regexp) {
1332 return text.replace(regexp, function(m, pre, url, post) { 1074 return text.replace(regexp, function(m, pre, url, post) {
1333 var urlPath = url.replace(/["']/g, ""); 1075 var urlPath = url.replace(/["']/g, "");
1334 if (linkUrl) { 1076 if (linkUrl) {
1335 urlPath = new URL(urlPath, linkUrl).href; 1077 urlPath = new URL(urlPath, linkUrl).href;
1336 } 1078 }
1337 urlObj.href = urlPath; 1079 urlObj.href = urlPath;
1338 urlPath = urlObj.href; 1080 urlPath = urlObj.href;
1339 return pre + "'" + urlPath + "'" + post; 1081 return pre + "'" + urlPath + "'" + post;
1340 }); 1082 });
1341 } 1083 }
1342 }; 1084 };
1343 scope.path = path; 1085 scope.path = path;
1344 }); 1086 });
1345 1087
1346 window.HTMLImports.addModule(function(scope) { 1088 HTMLImports.addModule(function(scope) {
1347 var xhr = { 1089 var xhr = {
1348 async: true, 1090 async: true,
1349 ok: function(request) { 1091 ok: function(request) {
1350 return request.status >= 200 && request.status < 300 || request.status === 304 || request.status === 0; 1092 return request.status >= 200 && request.status < 300 || request.status === 304 || request.status === 0;
1351 }, 1093 },
1352 load: function(url, next, nextContext) { 1094 load: function(url, next, nextContext) {
1353 var request = new XMLHttpRequest(); 1095 var request = new XMLHttpRequest();
1354 if (scope.flags.debug || scope.flags.bust) { 1096 if (scope.flags.debug || scope.flags.bust) {
1355 url += "?" + Math.random(); 1097 url += "?" + Math.random();
1356 } 1098 }
1357 request.open("GET", url, xhr.async); 1099 request.open("GET", url, xhr.async);
1358 request.addEventListener("readystatechange", function(e) { 1100 request.addEventListener("readystatechange", function(e) {
1359 if (request.readyState === 4) { 1101 if (request.readyState === 4) {
1102 var locationHeader = request.getResponseHeader("Location");
1360 var redirectedUrl = null; 1103 var redirectedUrl = null;
1361 try { 1104 if (locationHeader) {
1362 var locationHeader = request.getResponseHeader("Location"); 1105 var redirectedUrl = locationHeader.substr(0, 1) === "/" ? location.o rigin + locationHeader : locationHeader;
1363 if (locationHeader) {
1364 redirectedUrl = locationHeader.substr(0, 1) === "/" ? location.ori gin + locationHeader : locationHeader;
1365 }
1366 } catch (e) {
1367 console.error(e.message);
1368 } 1106 }
1369 next.call(nextContext, !xhr.ok(request) && request, request.response | | request.responseText, redirectedUrl); 1107 next.call(nextContext, !xhr.ok(request) && request, request.response | | request.responseText, redirectedUrl);
1370 } 1108 }
1371 }); 1109 });
1372 request.send(); 1110 request.send();
1373 return request; 1111 return request;
1374 }, 1112 },
1375 loadDocument: function(url, next, nextContext) { 1113 loadDocument: function(url, next, nextContext) {
1376 this.load(url, next, nextContext).responseType = "document"; 1114 this.load(url, next, nextContext).responseType = "document";
1377 } 1115 }
1378 }; 1116 };
1379 scope.xhr = xhr; 1117 scope.xhr = xhr;
1380 }); 1118 });
1381 1119
1382 window.HTMLImports.addModule(function(scope) { 1120 HTMLImports.addModule(function(scope) {
1383 var xhr = scope.xhr; 1121 var xhr = scope.xhr;
1384 var flags = scope.flags; 1122 var flags = scope.flags;
1385 var Loader = function(onLoad, onComplete) { 1123 var Loader = function(onLoad, onComplete) {
1386 this.cache = {}; 1124 this.cache = {};
1387 this.onload = onLoad; 1125 this.onload = onLoad;
1388 this.oncomplete = onComplete; 1126 this.oncomplete = onComplete;
1389 this.inflight = 0; 1127 this.inflight = 0;
1390 this.pending = {}; 1128 this.pending = {};
1391 }; 1129 };
1392 Loader.prototype = { 1130 Loader.prototype = {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 }, 1203 },
1466 checkDone: function() { 1204 checkDone: function() {
1467 if (!this.inflight) { 1205 if (!this.inflight) {
1468 this.oncomplete(); 1206 this.oncomplete();
1469 } 1207 }
1470 } 1208 }
1471 }; 1209 };
1472 scope.Loader = Loader; 1210 scope.Loader = Loader;
1473 }); 1211 });
1474 1212
1475 window.HTMLImports.addModule(function(scope) { 1213 HTMLImports.addModule(function(scope) {
1476 var Observer = function(addCallback) { 1214 var Observer = function(addCallback) {
1477 this.addCallback = addCallback; 1215 this.addCallback = addCallback;
1478 this.mo = new MutationObserver(this.handler.bind(this)); 1216 this.mo = new MutationObserver(this.handler.bind(this));
1479 }; 1217 };
1480 Observer.prototype = { 1218 Observer.prototype = {
1481 handler: function(mutations) { 1219 handler: function(mutations) {
1482 for (var i = 0, l = mutations.length, m; i < l && (m = mutations[i]); i++) { 1220 for (var i = 0, l = mutations.length, m; i < l && (m = mutations[i]); i++) {
1483 if (m.type === "childList" && m.addedNodes.length) { 1221 if (m.type === "childList" && m.addedNodes.length) {
1484 this.addedNodes(m.addedNodes); 1222 this.addedNodes(m.addedNodes);
1485 } 1223 }
(...skipping 12 matching lines...) Expand all
1498 observe: function(root) { 1236 observe: function(root) {
1499 this.mo.observe(root, { 1237 this.mo.observe(root, {
1500 childList: true, 1238 childList: true,
1501 subtree: true 1239 subtree: true
1502 }); 1240 });
1503 } 1241 }
1504 }; 1242 };
1505 scope.Observer = Observer; 1243 scope.Observer = Observer;
1506 }); 1244 });
1507 1245
1508 window.HTMLImports.addModule(function(scope) { 1246 HTMLImports.addModule(function(scope) {
1509 var path = scope.path; 1247 var path = scope.path;
1510 var rootDocument = scope.rootDocument; 1248 var rootDocument = scope.rootDocument;
1511 var flags = scope.flags; 1249 var flags = scope.flags;
1512 var isIE = scope.isIE; 1250 var isIE = scope.isIE;
1513 var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE; 1251 var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE;
1514 var IMPORT_SELECTOR = "link[rel=" + IMPORT_LINK_TYPE + "]"; 1252 var IMPORT_SELECTOR = "link[rel=" + IMPORT_LINK_TYPE + "]";
1515 var importParser = { 1253 var importParser = {
1516 documentSelectors: IMPORT_SELECTOR, 1254 documentSelectors: IMPORT_SELECTOR,
1517 importsSelectors: [ IMPORT_SELECTOR, "link[rel=stylesheet]:not([type])", "st yle:not([type])", "script:not([type])", 'script[type="application/javascript"]', 'script[type="text/javascript"]' ].join(","), 1255 importsSelectors: [ IMPORT_SELECTOR, "link[rel=stylesheet]", "style", "scrip t:not([type])", 'script[type="text/javascript"]' ].join(","),
1518 map: { 1256 map: {
1519 link: "parseLink", 1257 link: "parseLink",
1520 script: "parseScript", 1258 script: "parseScript",
1521 style: "parseStyle" 1259 style: "parseStyle"
1522 }, 1260 },
1523 dynamicElements: [], 1261 dynamicElements: [],
1524 parseNext: function() { 1262 parseNext: function() {
1525 var next = this.nextToParse(); 1263 var next = this.nextToParse();
1526 if (next) { 1264 if (next) {
1527 this.parse(next); 1265 this.parse(next);
(...skipping 30 matching lines...) Expand all
1558 this.parsingElement = null; 1296 this.parsingElement = null;
1559 flags.parse && console.log("completed", elt); 1297 flags.parse && console.log("completed", elt);
1560 }, 1298 },
1561 markDynamicParsingComplete: function(elt) { 1299 markDynamicParsingComplete: function(elt) {
1562 var i = this.dynamicElements.indexOf(elt); 1300 var i = this.dynamicElements.indexOf(elt);
1563 if (i >= 0) { 1301 if (i >= 0) {
1564 this.dynamicElements.splice(i, 1); 1302 this.dynamicElements.splice(i, 1);
1565 } 1303 }
1566 }, 1304 },
1567 parseImport: function(elt) { 1305 parseImport: function(elt) {
1568 elt.import = elt.__doc; 1306 if (HTMLImports.__importsParsingHook) {
1569 if (window.HTMLImports.__importsParsingHook) { 1307 HTMLImports.__importsParsingHook(elt);
1570 window.HTMLImports.__importsParsingHook(elt);
1571 } 1308 }
1572 if (elt.import) { 1309 if (elt.import) {
1573 elt.import.__importParsed = true; 1310 elt.import.__importParsed = true;
1574 } 1311 }
1575 this.markParsingComplete(elt); 1312 this.markParsingComplete(elt);
1576 if (elt.__resource && !elt.__error) { 1313 if (elt.__resource && !elt.__error) {
1577 elt.dispatchEvent(new CustomEvent("load", { 1314 elt.dispatchEvent(new CustomEvent("load", {
1578 bubbles: false 1315 bubbles: false
1579 })); 1316 }));
1580 } else { 1317 } else {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 } 1358 }
1622 return n; 1359 return n;
1623 }, 1360 },
1624 addElementToDocument: function(elt) { 1361 addElementToDocument: function(elt) {
1625 var port = this.rootImportForElement(elt.__importElement || elt); 1362 var port = this.rootImportForElement(elt.__importElement || elt);
1626 port.parentNode.insertBefore(elt, port); 1363 port.parentNode.insertBefore(elt, port);
1627 }, 1364 },
1628 trackElement: function(elt, callback) { 1365 trackElement: function(elt, callback) {
1629 var self = this; 1366 var self = this;
1630 var done = function(e) { 1367 var done = function(e) {
1631 elt.removeEventListener("load", done);
1632 elt.removeEventListener("error", done);
1633 if (callback) { 1368 if (callback) {
1634 callback(e); 1369 callback(e);
1635 } 1370 }
1636 self.markParsingComplete(elt); 1371 self.markParsingComplete(elt);
1637 self.parseNext(); 1372 self.parseNext();
1638 }; 1373 };
1639 elt.addEventListener("load", done); 1374 elt.addEventListener("load", done);
1640 elt.addEventListener("error", done); 1375 elt.addEventListener("error", done);
1641 if (isIE && elt.localName === "style") { 1376 if (isIE && elt.localName === "style") {
1642 var fakeLoad = false; 1377 var fakeLoad = false;
1643 if (elt.textContent.indexOf("@import") == -1) { 1378 if (elt.textContent.indexOf("@import") == -1) {
1644 fakeLoad = true; 1379 fakeLoad = true;
1645 } else if (elt.sheet) { 1380 } else if (elt.sheet) {
1646 fakeLoad = true; 1381 fakeLoad = true;
1647 var csr = elt.sheet.cssRules; 1382 var csr = elt.sheet.cssRules;
1648 var len = csr ? csr.length : 0; 1383 var len = csr ? csr.length : 0;
1649 for (var i = 0, r; i < len && (r = csr[i]); i++) { 1384 for (var i = 0, r; i < len && (r = csr[i]); i++) {
1650 if (r.type === CSSRule.IMPORT_RULE) { 1385 if (r.type === CSSRule.IMPORT_RULE) {
1651 fakeLoad = fakeLoad && Boolean(r.styleSheet); 1386 fakeLoad = fakeLoad && Boolean(r.styleSheet);
1652 } 1387 }
1653 } 1388 }
1654 } 1389 }
1655 if (fakeLoad) { 1390 if (fakeLoad) {
1656 setTimeout(function() { 1391 elt.dispatchEvent(new CustomEvent("load", {
1657 elt.dispatchEvent(new CustomEvent("load", { 1392 bubbles: false
1658 bubbles: false 1393 }));
1659 }));
1660 });
1661 } 1394 }
1662 } 1395 }
1663 }, 1396 },
1664 parseScript: function(scriptElt) { 1397 parseScript: function(scriptElt) {
1665 var script = document.createElement("script"); 1398 var script = document.createElement("script");
1666 script.__importElement = scriptElt; 1399 script.__importElement = scriptElt;
1667 script.src = scriptElt.src ? scriptElt.src : generateScriptDataUrl(scriptE lt); 1400 script.src = scriptElt.src ? scriptElt.src : generateScriptDataUrl(scriptE lt);
1668 scope.currentScript = scriptElt; 1401 scope.currentScript = scriptElt;
1669 this.trackElement(script, function(e) { 1402 this.trackElement(script, function(e) {
1670 if (script.parentNode) { 1403 script.parentNode.removeChild(script);
1671 script.parentNode.removeChild(script);
1672 }
1673 scope.currentScript = null; 1404 scope.currentScript = null;
1674 }); 1405 });
1675 this.addElementToDocument(script); 1406 this.addElementToDocument(script);
1676 }, 1407 },
1677 nextToParse: function() { 1408 nextToParse: function() {
1678 this._mayParse = []; 1409 this._mayParse = [];
1679 return !this.parsingElement && (this.nextToParseInDoc(rootDocument) || thi s.nextToParseDynamic()); 1410 return !this.parsingElement && (this.nextToParseInDoc(rootDocument) || thi s.nextToParseDynamic());
1680 }, 1411 },
1681 nextToParseInDoc: function(doc, link) { 1412 nextToParseInDoc: function(doc, link) {
1682 if (doc && this._mayParse.indexOf(doc) < 0) { 1413 if (doc && this._mayParse.indexOf(doc) < 0) {
1683 this._mayParse.push(doc); 1414 this._mayParse.push(doc);
1684 var nodes = doc.querySelectorAll(this.parseSelectorsForNode(doc)); 1415 var nodes = doc.querySelectorAll(this.parseSelectorsForNode(doc));
1685 for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) { 1416 for (var i = 0, l = nodes.length, p = 0, n; i < l && (n = nodes[i]); i++ ) {
1686 if (!this.isParsed(n)) { 1417 if (!this.isParsed(n)) {
1687 if (this.hasResource(n)) { 1418 if (this.hasResource(n)) {
1688 return nodeIsImport(n) ? this.nextToParseInDoc(n.__doc, n) : n; 1419 return nodeIsImport(n) ? this.nextToParseInDoc(n.import, n) : n;
1689 } else { 1420 } else {
1690 return; 1421 return;
1691 } 1422 }
1692 } 1423 }
1693 } 1424 }
1694 } 1425 }
1695 return link; 1426 return link;
1696 }, 1427 },
1697 nextToParseDynamic: function() { 1428 nextToParseDynamic: function() {
1698 return this.dynamicElements[0]; 1429 return this.dynamicElements[0];
1699 }, 1430 },
1700 parseSelectorsForNode: function(node) { 1431 parseSelectorsForNode: function(node) {
1701 var doc = node.ownerDocument || node; 1432 var doc = node.ownerDocument || node;
1702 return doc === rootDocument ? this.documentSelectors : this.importsSelecto rs; 1433 return doc === rootDocument ? this.documentSelectors : this.importsSelecto rs;
1703 }, 1434 },
1704 isParsed: function(node) { 1435 isParsed: function(node) {
1705 return node.__importParsed; 1436 return node.__importParsed;
1706 }, 1437 },
1707 needsDynamicParsing: function(elt) { 1438 needsDynamicParsing: function(elt) {
1708 return this.dynamicElements.indexOf(elt) >= 0; 1439 return this.dynamicElements.indexOf(elt) >= 0;
1709 }, 1440 },
1710 hasResource: function(node) { 1441 hasResource: function(node) {
1711 if (nodeIsImport(node) && node.__doc === undefined) { 1442 if (nodeIsImport(node) && node.import === undefined) {
1712 return false; 1443 return false;
1713 } 1444 }
1714 return true; 1445 return true;
1715 } 1446 }
1716 }; 1447 };
1717 function nodeIsImport(elt) { 1448 function nodeIsImport(elt) {
1718 return elt.localName === "link" && elt.rel === IMPORT_LINK_TYPE; 1449 return elt.localName === "link" && elt.rel === IMPORT_LINK_TYPE;
1719 } 1450 }
1720 function generateScriptDataUrl(script) { 1451 function generateScriptDataUrl(script) {
1721 var scriptContent = generateScriptContent(script); 1452 var scriptContent = generateScriptContent(script);
(...skipping 13 matching lines...) Expand all
1735 function cloneStyle(style) { 1466 function cloneStyle(style) {
1736 var clone = style.ownerDocument.createElement("style"); 1467 var clone = style.ownerDocument.createElement("style");
1737 clone.textContent = style.textContent; 1468 clone.textContent = style.textContent;
1738 path.resolveUrlsInStyle(clone); 1469 path.resolveUrlsInStyle(clone);
1739 return clone; 1470 return clone;
1740 } 1471 }
1741 scope.parser = importParser; 1472 scope.parser = importParser;
1742 scope.IMPORT_SELECTOR = IMPORT_SELECTOR; 1473 scope.IMPORT_SELECTOR = IMPORT_SELECTOR;
1743 }); 1474 });
1744 1475
1745 window.HTMLImports.addModule(function(scope) { 1476 HTMLImports.addModule(function(scope) {
1746 var flags = scope.flags; 1477 var flags = scope.flags;
1747 var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE; 1478 var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE;
1748 var IMPORT_SELECTOR = scope.IMPORT_SELECTOR; 1479 var IMPORT_SELECTOR = scope.IMPORT_SELECTOR;
1749 var rootDocument = scope.rootDocument; 1480 var rootDocument = scope.rootDocument;
1750 var Loader = scope.Loader; 1481 var Loader = scope.Loader;
1751 var Observer = scope.Observer; 1482 var Observer = scope.Observer;
1752 var parser = scope.parser; 1483 var parser = scope.parser;
1753 var importer = { 1484 var importer = {
1754 documents: {}, 1485 documents: {},
1755 documentPreloadSelectors: IMPORT_SELECTOR, 1486 documentPreloadSelectors: IMPORT_SELECTOR,
(...skipping 19 matching lines...) Expand all
1775 if (isImportLink(elt)) { 1506 if (isImportLink(elt)) {
1776 var doc = this.documents[url]; 1507 var doc = this.documents[url];
1777 if (doc === undefined) { 1508 if (doc === undefined) {
1778 doc = err ? null : makeDocument(resource, redirectedUrl || url); 1509 doc = err ? null : makeDocument(resource, redirectedUrl || url);
1779 if (doc) { 1510 if (doc) {
1780 doc.__importLink = elt; 1511 doc.__importLink = elt;
1781 this.bootDocument(doc); 1512 this.bootDocument(doc);
1782 } 1513 }
1783 this.documents[url] = doc; 1514 this.documents[url] = doc;
1784 } 1515 }
1785 elt.__doc = doc; 1516 elt.import = doc;
1786 } 1517 }
1787 parser.parseNext(); 1518 parser.parseNext();
1788 }, 1519 },
1789 bootDocument: function(doc) { 1520 bootDocument: function(doc) {
1790 this.loadSubtree(doc); 1521 this.loadSubtree(doc);
1791 this.observer.observe(doc); 1522 this.observer.observe(doc);
1792 parser.parseNext(); 1523 parser.parseNext();
1793 }, 1524 },
1794 loadedAll: function() { 1525 loadedAll: function() {
1795 parser.parseNext(); 1526 parser.parseNext();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1834 }, 1565 },
1835 configurable: true 1566 configurable: true
1836 }; 1567 };
1837 Object.defineProperty(document, "baseURI", baseURIDescriptor); 1568 Object.defineProperty(document, "baseURI", baseURIDescriptor);
1838 Object.defineProperty(rootDocument, "baseURI", baseURIDescriptor); 1569 Object.defineProperty(rootDocument, "baseURI", baseURIDescriptor);
1839 } 1570 }
1840 scope.importer = importer; 1571 scope.importer = importer;
1841 scope.importLoader = importLoader; 1572 scope.importLoader = importLoader;
1842 }); 1573 });
1843 1574
1844 window.HTMLImports.addModule(function(scope) { 1575 HTMLImports.addModule(function(scope) {
1845 var parser = scope.parser; 1576 var parser = scope.parser;
1846 var importer = scope.importer; 1577 var importer = scope.importer;
1847 var dynamic = { 1578 var dynamic = {
1848 added: function(nodes) { 1579 added: function(nodes) {
1849 var owner, parsed, loading; 1580 var owner, parsed, loading;
1850 for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) { 1581 for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
1851 if (!owner) { 1582 if (!owner) {
1852 owner = n.ownerDocument; 1583 owner = n.ownerDocument;
1853 parsed = parser.isParsed(owner); 1584 parsed = parser.isParsed(owner);
1854 } 1585 }
(...skipping 16 matching lines...) Expand all
1871 importer.observer.addCallback = dynamic.added.bind(dynamic); 1602 importer.observer.addCallback = dynamic.added.bind(dynamic);
1872 var matches = HTMLElement.prototype.matches || HTMLElement.prototype.matchesSe lector || HTMLElement.prototype.webkitMatchesSelector || HTMLElement.prototype.m ozMatchesSelector || HTMLElement.prototype.msMatchesSelector; 1603 var matches = HTMLElement.prototype.matches || HTMLElement.prototype.matchesSe lector || HTMLElement.prototype.webkitMatchesSelector || HTMLElement.prototype.m ozMatchesSelector || HTMLElement.prototype.msMatchesSelector;
1873 }); 1604 });
1874 1605
1875 (function(scope) { 1606 (function(scope) {
1876 var initializeModules = scope.initializeModules; 1607 var initializeModules = scope.initializeModules;
1877 var isIE = scope.isIE; 1608 var isIE = scope.isIE;
1878 if (scope.useNative) { 1609 if (scope.useNative) {
1879 return; 1610 return;
1880 } 1611 }
1612 if (isIE && typeof window.CustomEvent !== "function") {
1613 window.CustomEvent = function(inType, params) {
1614 params = params || {};
1615 var e = document.createEvent("CustomEvent");
1616 e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelab le), params.detail);
1617 return e;
1618 };
1619 window.CustomEvent.prototype = window.Event.prototype;
1620 }
1881 initializeModules(); 1621 initializeModules();
1882 var rootDocument = scope.rootDocument; 1622 var rootDocument = scope.rootDocument;
1883 function bootstrap() { 1623 function bootstrap() {
1884 window.HTMLImports.importer.bootDocument(rootDocument); 1624 HTMLImports.importer.bootDocument(rootDocument);
1885 } 1625 }
1886 if (document.readyState === "complete" || document.readyState === "interactive " && !window.attachEvent) { 1626 if (document.readyState === "complete" || document.readyState === "interactive " && !window.attachEvent) {
1887 bootstrap(); 1627 bootstrap();
1888 } else { 1628 } else {
1889 document.addEventListener("DOMContentLoaded", bootstrap); 1629 document.addEventListener("DOMContentLoaded", bootstrap);
1890 } 1630 }
1891 })(window.HTMLImports); 1631 })(HTMLImports);
1892 1632
1893 window.CustomElements = window.CustomElements || { 1633 window.CustomElements = window.CustomElements || {
1894 flags: {} 1634 flags: {}
1895 }; 1635 };
1896 1636
1897 (function(scope) { 1637 (function(scope) {
1898 var flags = scope.flags; 1638 var flags = scope.flags;
1899 var modules = []; 1639 var modules = [];
1900 var addModule = function(module) { 1640 var addModule = function(module) {
1901 modules.push(module); 1641 modules.push(module);
1902 }; 1642 };
1903 var initializeModules = function() { 1643 var initializeModules = function() {
1904 modules.forEach(function(module) { 1644 modules.forEach(function(module) {
1905 module(scope); 1645 module(scope);
1906 }); 1646 });
1907 }; 1647 };
1908 scope.addModule = addModule; 1648 scope.addModule = addModule;
1909 scope.initializeModules = initializeModules; 1649 scope.initializeModules = initializeModules;
1910 scope.hasNative = Boolean(document.registerElement); 1650 scope.hasNative = Boolean(document.registerElement);
1911 scope.isIE = /Trident/.test(navigator.userAgent); 1651 scope.useNative = !flags.register && scope.hasNative && !window.ShadowDOMPolyf ill && (!window.HTMLImports || HTMLImports.useNative);
1912 scope.useNative = !flags.register && scope.hasNative && !window.ShadowDOMPolyf ill && (!window.HTMLImports || window.HTMLImports.useNative); 1652 })(CustomElements);
1913 })(window.CustomElements);
1914 1653
1915 window.CustomElements.addModule(function(scope) { 1654 CustomElements.addModule(function(scope) {
1916 var IMPORT_LINK_TYPE = window.HTMLImports ? window.HTMLImports.IMPORT_LINK_TYP E : "none"; 1655 var IMPORT_LINK_TYPE = window.HTMLImports ? HTMLImports.IMPORT_LINK_TYPE : "no ne";
1917 function forSubtree(node, cb) { 1656 function forSubtree(node, cb) {
1918 findAllElements(node, function(e) { 1657 findAllElements(node, function(e) {
1919 if (cb(e)) { 1658 if (cb(e)) {
1920 return true; 1659 return true;
1921 } 1660 }
1922 forRoots(e, cb); 1661 forRoots(e, cb);
1923 }); 1662 });
1924 forRoots(node, cb); 1663 forRoots(node, cb);
1925 } 1664 }
1926 function findAllElements(node, find, data) { 1665 function findAllElements(node, find, data) {
(...skipping 16 matching lines...) Expand all
1943 var root = node.shadowRoot; 1682 var root = node.shadowRoot;
1944 while (root) { 1683 while (root) {
1945 forSubtree(root, cb); 1684 forSubtree(root, cb);
1946 root = root.olderShadowRoot; 1685 root = root.olderShadowRoot;
1947 } 1686 }
1948 } 1687 }
1949 function forDocumentTree(doc, cb) { 1688 function forDocumentTree(doc, cb) {
1950 _forDocumentTree(doc, cb, []); 1689 _forDocumentTree(doc, cb, []);
1951 } 1690 }
1952 function _forDocumentTree(doc, cb, processingDocuments) { 1691 function _forDocumentTree(doc, cb, processingDocuments) {
1953 doc = window.wrap(doc); 1692 doc = wrap(doc);
1954 if (processingDocuments.indexOf(doc) >= 0) { 1693 if (processingDocuments.indexOf(doc) >= 0) {
1955 return; 1694 return;
1956 } 1695 }
1957 processingDocuments.push(doc); 1696 processingDocuments.push(doc);
1958 var imports = doc.querySelectorAll("link[rel=" + IMPORT_LINK_TYPE + "]"); 1697 var imports = doc.querySelectorAll("link[rel=" + IMPORT_LINK_TYPE + "]");
1959 for (var i = 0, l = imports.length, n; i < l && (n = imports[i]); i++) { 1698 for (var i = 0, l = imports.length, n; i < l && (n = imports[i]); i++) {
1960 if (n.import) { 1699 if (n.import) {
1961 _forDocumentTree(n.import, cb, processingDocuments); 1700 _forDocumentTree(n.import, cb, processingDocuments);
1962 } 1701 }
1963 } 1702 }
1964 cb(doc); 1703 cb(doc);
1965 } 1704 }
1966 scope.forDocumentTree = forDocumentTree; 1705 scope.forDocumentTree = forDocumentTree;
1967 scope.forSubtree = forSubtree; 1706 scope.forSubtree = forSubtree;
1968 }); 1707 });
1969 1708
1970 window.CustomElements.addModule(function(scope) { 1709 CustomElements.addModule(function(scope) {
1971 var flags = scope.flags; 1710 var flags = scope.flags;
1972 var forSubtree = scope.forSubtree; 1711 var forSubtree = scope.forSubtree;
1973 var forDocumentTree = scope.forDocumentTree; 1712 var forDocumentTree = scope.forDocumentTree;
1974 function addedNode(node, isAttached) { 1713 function addedNode(node) {
1975 return added(node, isAttached) || addedSubtree(node, isAttached); 1714 return added(node) || addedSubtree(node);
1976 } 1715 }
1977 function added(node, isAttached) { 1716 function added(node) {
1978 if (scope.upgrade(node, isAttached)) { 1717 if (scope.upgrade(node)) {
1979 return true; 1718 return true;
1980 } 1719 }
1981 if (isAttached) { 1720 attached(node);
1982 attached(node);
1983 }
1984 } 1721 }
1985 function addedSubtree(node, isAttached) { 1722 function addedSubtree(node) {
1986 forSubtree(node, function(e) { 1723 forSubtree(node, function(e) {
1987 if (added(e, isAttached)) { 1724 if (added(e)) {
1988 return true; 1725 return true;
1989 } 1726 }
1990 }); 1727 });
1991 } 1728 }
1992 var hasThrottledAttached = window.MutationObserver._isPolyfilled && flags["thr ottle-attached"]; 1729 function attachedNode(node) {
1993 scope.hasPolyfillMutations = hasThrottledAttached; 1730 attached(node);
1994 scope.hasThrottledAttached = hasThrottledAttached; 1731 if (inDocument(node)) {
1732 forSubtree(node, function(e) {
1733 attached(e);
1734 });
1735 }
1736 }
1737 var hasPolyfillMutations = !window.MutationObserver || window.MutationObserver === window.JsMutationObserver;
1738 scope.hasPolyfillMutations = hasPolyfillMutations;
1995 var isPendingMutations = false; 1739 var isPendingMutations = false;
1996 var pendingMutations = []; 1740 var pendingMutations = [];
1997 function deferMutation(fn) { 1741 function deferMutation(fn) {
1998 pendingMutations.push(fn); 1742 pendingMutations.push(fn);
1999 if (!isPendingMutations) { 1743 if (!isPendingMutations) {
2000 isPendingMutations = true; 1744 isPendingMutations = true;
2001 setTimeout(takeMutations); 1745 setTimeout(takeMutations);
2002 } 1746 }
2003 } 1747 }
2004 function takeMutations() { 1748 function takeMutations() {
2005 isPendingMutations = false; 1749 isPendingMutations = false;
2006 var $p = pendingMutations; 1750 var $p = pendingMutations;
2007 for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) { 1751 for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) {
2008 p(); 1752 p();
2009 } 1753 }
2010 pendingMutations = []; 1754 pendingMutations = [];
2011 } 1755 }
2012 function attached(element) { 1756 function attached(element) {
2013 if (hasThrottledAttached) { 1757 if (hasPolyfillMutations) {
2014 deferMutation(function() { 1758 deferMutation(function() {
2015 _attached(element); 1759 _attached(element);
2016 }); 1760 });
2017 } else { 1761 } else {
2018 _attached(element); 1762 _attached(element);
2019 } 1763 }
2020 } 1764 }
2021 function _attached(element) { 1765 function _attached(element) {
2022 if (element.__upgraded__ && !element.__attached) { 1766 if (element.__upgraded__ && (element.attachedCallback || element.detachedCal lback)) {
2023 element.__attached = true; 1767 if (!element.__attached && inDocument(element)) {
2024 if (element.attachedCallback) { 1768 element.__attached = true;
2025 element.attachedCallback(); 1769 if (element.attachedCallback) {
1770 element.attachedCallback();
1771 }
2026 } 1772 }
2027 } 1773 }
2028 } 1774 }
2029 function detachedNode(node) { 1775 function detachedNode(node) {
2030 detached(node); 1776 detached(node);
2031 forSubtree(node, function(e) { 1777 forSubtree(node, function(e) {
2032 detached(e); 1778 detached(e);
2033 }); 1779 });
2034 } 1780 }
2035 function detached(element) { 1781 function detached(element) {
2036 if (hasThrottledAttached) { 1782 if (hasPolyfillMutations) {
2037 deferMutation(function() { 1783 deferMutation(function() {
2038 _detached(element); 1784 _detached(element);
2039 }); 1785 });
2040 } else { 1786 } else {
2041 _detached(element); 1787 _detached(element);
2042 } 1788 }
2043 } 1789 }
2044 function _detached(element) { 1790 function _detached(element) {
2045 if (element.__upgraded__ && element.__attached) { 1791 if (element.__upgraded__ && (element.attachedCallback || element.detachedCal lback)) {
2046 element.__attached = false; 1792 if (element.__attached && !inDocument(element)) {
2047 if (element.detachedCallback) { 1793 element.__attached = false;
2048 element.detachedCallback(); 1794 if (element.detachedCallback) {
1795 element.detachedCallback();
1796 }
2049 } 1797 }
2050 } 1798 }
2051 } 1799 }
2052 function inDocument(element) { 1800 function inDocument(element) {
2053 var p = element; 1801 var p = element;
2054 var doc = window.wrap(document); 1802 var doc = wrap(document);
2055 while (p) { 1803 while (p) {
2056 if (p == doc) { 1804 if (p == doc) {
2057 return true; 1805 return true;
2058 } 1806 }
2059 p = p.parentNode || p.nodeType === Node.DOCUMENT_FRAGMENT_NODE && p.host; 1807 p = p.parentNode || p.nodeType === Node.DOCUMENT_FRAGMENT_NODE && p.host;
2060 } 1808 }
2061 } 1809 }
2062 function watchShadow(node) { 1810 function watchShadow(node) {
2063 if (node.shadowRoot && !node.shadowRoot.__watched) { 1811 if (node.shadowRoot && !node.shadowRoot.__watched) {
2064 flags.dom && console.log("watching shadow-root for: ", node.localName); 1812 flags.dom && console.log("watching shadow-root for: ", node.localName);
2065 var root = node.shadowRoot; 1813 var root = node.shadowRoot;
2066 while (root) { 1814 while (root) {
2067 observe(root); 1815 observe(root);
2068 root = root.olderShadowRoot; 1816 root = root.olderShadowRoot;
2069 } 1817 }
2070 } 1818 }
2071 } 1819 }
2072 function handler(root, mutations) { 1820 function handler(mutations) {
2073 if (flags.dom) { 1821 if (flags.dom) {
2074 var mx = mutations[0]; 1822 var mx = mutations[0];
2075 if (mx && mx.type === "childList" && mx.addedNodes) { 1823 if (mx && mx.type === "childList" && mx.addedNodes) {
2076 if (mx.addedNodes) { 1824 if (mx.addedNodes) {
2077 var d = mx.addedNodes[0]; 1825 var d = mx.addedNodes[0];
2078 while (d && d !== document && !d.host) { 1826 while (d && d !== document && !d.host) {
2079 d = d.parentNode; 1827 d = d.parentNode;
2080 } 1828 }
2081 var u = d && (d.URL || d._URL || d.host && d.host.localName) || ""; 1829 var u = d && (d.URL || d._URL || d.host && d.host.localName) || "";
2082 u = u.split("/?").shift().split("/").pop(); 1830 u = u.split("/?").shift().split("/").pop();
2083 } 1831 }
2084 } 1832 }
2085 console.group("mutations (%d) [%s]", mutations.length, u || ""); 1833 console.group("mutations (%d) [%s]", mutations.length, u || "");
2086 } 1834 }
2087 var isAttached = inDocument(root);
2088 mutations.forEach(function(mx) { 1835 mutations.forEach(function(mx) {
2089 if (mx.type === "childList") { 1836 if (mx.type === "childList") {
2090 forEach(mx.addedNodes, function(n) { 1837 forEach(mx.addedNodes, function(n) {
2091 if (!n.localName) { 1838 if (!n.localName) {
2092 return; 1839 return;
2093 } 1840 }
2094 addedNode(n, isAttached); 1841 addedNode(n);
2095 }); 1842 });
2096 forEach(mx.removedNodes, function(n) { 1843 forEach(mx.removedNodes, function(n) {
2097 if (!n.localName) { 1844 if (!n.localName) {
2098 return; 1845 return;
2099 } 1846 }
2100 detachedNode(n); 1847 detachedNode(n);
2101 }); 1848 });
2102 } 1849 }
2103 }); 1850 });
2104 flags.dom && console.groupEnd(); 1851 flags.dom && console.groupEnd();
2105 } 1852 }
2106 function takeRecords(node) { 1853 function takeRecords(node) {
2107 node = window.wrap(node); 1854 node = wrap(node);
2108 if (!node) { 1855 if (!node) {
2109 node = window.wrap(document); 1856 node = wrap(document);
2110 } 1857 }
2111 while (node.parentNode) { 1858 while (node.parentNode) {
2112 node = node.parentNode; 1859 node = node.parentNode;
2113 } 1860 }
2114 var observer = node.__observer; 1861 var observer = node.__observer;
2115 if (observer) { 1862 if (observer) {
2116 handler(node, observer.takeRecords()); 1863 handler(observer.takeRecords());
2117 takeMutations(); 1864 takeMutations();
2118 } 1865 }
2119 } 1866 }
2120 var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach); 1867 var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach);
2121 function observe(inRoot) { 1868 function observe(inRoot) {
2122 if (inRoot.__observer) { 1869 if (inRoot.__observer) {
2123 return; 1870 return;
2124 } 1871 }
2125 var observer = new MutationObserver(handler.bind(this, inRoot)); 1872 var observer = new MutationObserver(handler);
2126 observer.observe(inRoot, { 1873 observer.observe(inRoot, {
2127 childList: true, 1874 childList: true,
2128 subtree: true 1875 subtree: true
2129 }); 1876 });
2130 inRoot.__observer = observer; 1877 inRoot.__observer = observer;
2131 } 1878 }
2132 function upgradeDocument(doc) { 1879 function upgradeDocument(doc) {
2133 doc = window.wrap(doc); 1880 doc = wrap(doc);
2134 flags.dom && console.group("upgradeDocument: ", doc.baseURI.split("/").pop() ); 1881 flags.dom && console.group("upgradeDocument: ", doc.baseURI.split("/").pop() );
2135 var isMainDocument = doc === window.wrap(document); 1882 addedNode(doc);
2136 addedNode(doc, isMainDocument);
2137 observe(doc); 1883 observe(doc);
2138 flags.dom && console.groupEnd(); 1884 flags.dom && console.groupEnd();
2139 } 1885 }
2140 function upgradeDocumentTree(doc) { 1886 function upgradeDocumentTree(doc) {
2141 forDocumentTree(doc, upgradeDocument); 1887 forDocumentTree(doc, upgradeDocument);
2142 } 1888 }
2143 var originalCreateShadowRoot = Element.prototype.createShadowRoot; 1889 var originalCreateShadowRoot = Element.prototype.createShadowRoot;
2144 if (originalCreateShadowRoot) { 1890 if (originalCreateShadowRoot) {
2145 Element.prototype.createShadowRoot = function() { 1891 Element.prototype.createShadowRoot = function() {
2146 var root = originalCreateShadowRoot.call(this); 1892 var root = originalCreateShadowRoot.call(this);
2147 window.CustomElements.watchShadow(this); 1893 CustomElements.watchShadow(this);
2148 return root; 1894 return root;
2149 }; 1895 };
2150 } 1896 }
2151 scope.watchShadow = watchShadow; 1897 scope.watchShadow = watchShadow;
2152 scope.upgradeDocumentTree = upgradeDocumentTree; 1898 scope.upgradeDocumentTree = upgradeDocumentTree;
2153 scope.upgradeDocument = upgradeDocument;
2154 scope.upgradeSubtree = addedSubtree; 1899 scope.upgradeSubtree = addedSubtree;
2155 scope.upgradeAll = addedNode; 1900 scope.upgradeAll = addedNode;
2156 scope.attached = attached; 1901 scope.attachedNode = attachedNode;
2157 scope.takeRecords = takeRecords; 1902 scope.takeRecords = takeRecords;
2158 }); 1903 });
2159 1904
2160 window.CustomElements.addModule(function(scope) { 1905 CustomElements.addModule(function(scope) {
2161 var flags = scope.flags; 1906 var flags = scope.flags;
2162 function upgrade(node, isAttached) { 1907 function upgrade(node) {
2163 if (node.localName === "template") {
2164 if (window.HTMLTemplateElement && HTMLTemplateElement.decorate) {
2165 HTMLTemplateElement.decorate(node);
2166 }
2167 }
2168 if (!node.__upgraded__ && node.nodeType === Node.ELEMENT_NODE) { 1908 if (!node.__upgraded__ && node.nodeType === Node.ELEMENT_NODE) {
2169 var is = node.getAttribute("is"); 1909 var is = node.getAttribute("is");
2170 var definition = scope.getRegisteredDefinition(node.localName) || scope.ge tRegisteredDefinition(is); 1910 var definition = scope.getRegisteredDefinition(is || node.localName);
2171 if (definition) { 1911 if (definition) {
2172 if (is && definition.tag == node.localName || !is && !definition.extends ) { 1912 if (is && definition.tag == node.localName) {
2173 return upgradeWithDefinition(node, definition, isAttached); 1913 return upgradeWithDefinition(node, definition);
1914 } else if (!is && !definition.extends) {
1915 return upgradeWithDefinition(node, definition);
2174 } 1916 }
2175 } 1917 }
2176 } 1918 }
2177 } 1919 }
2178 function upgradeWithDefinition(element, definition, isAttached) { 1920 function upgradeWithDefinition(element, definition) {
2179 flags.upgrade && console.group("upgrade:", element.localName); 1921 flags.upgrade && console.group("upgrade:", element.localName);
2180 if (definition.is) { 1922 if (definition.is) {
2181 element.setAttribute("is", definition.is); 1923 element.setAttribute("is", definition.is);
2182 } 1924 }
2183 implementPrototype(element, definition); 1925 implementPrototype(element, definition);
2184 element.__upgraded__ = true; 1926 element.__upgraded__ = true;
2185 created(element); 1927 created(element);
2186 if (isAttached) { 1928 scope.attachedNode(element);
2187 scope.attached(element); 1929 scope.upgradeSubtree(element);
2188 }
2189 scope.upgradeSubtree(element, isAttached);
2190 flags.upgrade && console.groupEnd(); 1930 flags.upgrade && console.groupEnd();
2191 return element; 1931 return element;
2192 } 1932 }
2193 function implementPrototype(element, definition) { 1933 function implementPrototype(element, definition) {
2194 if (Object.__proto__) { 1934 if (Object.__proto__) {
2195 element.__proto__ = definition.prototype; 1935 element.__proto__ = definition.prototype;
2196 } else { 1936 } else {
2197 customMixin(element, definition.prototype, definition.native); 1937 customMixin(element, definition.prototype, definition.native);
2198 element.__proto__ = definition.prototype; 1938 element.__proto__ = definition.prototype;
2199 } 1939 }
(...skipping 15 matching lines...) Expand all
2215 function created(element) { 1955 function created(element) {
2216 if (element.createdCallback) { 1956 if (element.createdCallback) {
2217 element.createdCallback(); 1957 element.createdCallback();
2218 } 1958 }
2219 } 1959 }
2220 scope.upgrade = upgrade; 1960 scope.upgrade = upgrade;
2221 scope.upgradeWithDefinition = upgradeWithDefinition; 1961 scope.upgradeWithDefinition = upgradeWithDefinition;
2222 scope.implementPrototype = implementPrototype; 1962 scope.implementPrototype = implementPrototype;
2223 }); 1963 });
2224 1964
2225 window.CustomElements.addModule(function(scope) { 1965 CustomElements.addModule(function(scope) {
2226 var isIE = scope.isIE; 1966 var isIE11OrOlder = scope.isIE11OrOlder;
2227 var upgradeDocumentTree = scope.upgradeDocumentTree; 1967 var upgradeDocumentTree = scope.upgradeDocumentTree;
2228 var upgradeAll = scope.upgradeAll; 1968 var upgradeAll = scope.upgradeAll;
2229 var upgradeWithDefinition = scope.upgradeWithDefinition; 1969 var upgradeWithDefinition = scope.upgradeWithDefinition;
2230 var implementPrototype = scope.implementPrototype; 1970 var implementPrototype = scope.implementPrototype;
2231 var useNative = scope.useNative; 1971 var useNative = scope.useNative;
2232 function register(name, options) { 1972 function register(name, options) {
2233 var definition = options || {}; 1973 var definition = options || {};
2234 if (!name) { 1974 if (!name) {
2235 throw new Error("document.registerElement: first argument `name` must not be empty"); 1975 throw new Error("document.registerElement: first argument `name` must not be empty");
2236 } 1976 }
2237 if (name.indexOf("-") < 0) { 1977 if (name.indexOf("-") < 0) {
2238 throw new Error("document.registerElement: first argument ('name') must co ntain a dash ('-'). Argument provided was '" + String(name) + "'."); 1978 throw new Error("document.registerElement: first argument ('name') must co ntain a dash ('-'). Argument provided was '" + String(name) + "'.");
2239 } 1979 }
2240 if (isReservedTag(name)) { 1980 if (isReservedTag(name)) {
2241 throw new Error("Failed to execute 'registerElement' on 'Document': Regist ration failed for type '" + String(name) + "'. The type name is invalid."); 1981 throw new Error("Failed to execute 'registerElement' on 'Document': Regist ration failed for type '" + String(name) + "'. The type name is invalid.");
2242 } 1982 }
2243 if (getRegisteredDefinition(name)) { 1983 if (getRegisteredDefinition(name)) {
2244 throw new Error("DuplicateDefinitionError: a type with name '" + String(na me) + "' is already registered"); 1984 throw new Error("DuplicateDefinitionError: a type with name '" + String(na me) + "' is already registered");
2245 } 1985 }
2246 if (!definition.prototype) { 1986 if (!definition.prototype) {
2247 definition.prototype = Object.create(HTMLElement.prototype); 1987 definition.prototype = Object.create(HTMLElement.prototype);
2248 } 1988 }
2249 definition.__name = name.toLowerCase(); 1989 definition.__name = name.toLowerCase();
2250 if (definition.extends) {
2251 definition.extends = definition.extends.toLowerCase();
2252 }
2253 definition.lifecycle = definition.lifecycle || {}; 1990 definition.lifecycle = definition.lifecycle || {};
2254 definition.ancestry = ancestry(definition.extends); 1991 definition.ancestry = ancestry(definition.extends);
2255 resolveTagName(definition); 1992 resolveTagName(definition);
2256 resolvePrototypeChain(definition); 1993 resolvePrototypeChain(definition);
2257 overrideAttributeApi(definition.prototype); 1994 overrideAttributeApi(definition.prototype);
2258 registerDefinition(definition.__name, definition); 1995 registerDefinition(definition.__name, definition);
2259 definition.ctor = generateConstructor(definition); 1996 definition.ctor = generateConstructor(definition);
2260 definition.ctor.prototype = definition.prototype; 1997 definition.ctor.prototype = definition.prototype;
2261 definition.prototype.constructor = definition.ctor; 1998 definition.prototype.constructor = definition.ctor;
2262 if (scope.ready) { 1999 if (scope.ready) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2310 definition.tag = baseTag || definition.__name; 2047 definition.tag = baseTag || definition.__name;
2311 if (baseTag) { 2048 if (baseTag) {
2312 definition.is = definition.__name; 2049 definition.is = definition.__name;
2313 } 2050 }
2314 } 2051 }
2315 function resolvePrototypeChain(definition) { 2052 function resolvePrototypeChain(definition) {
2316 if (!Object.__proto__) { 2053 if (!Object.__proto__) {
2317 var nativePrototype = HTMLElement.prototype; 2054 var nativePrototype = HTMLElement.prototype;
2318 if (definition.is) { 2055 if (definition.is) {
2319 var inst = document.createElement(definition.tag); 2056 var inst = document.createElement(definition.tag);
2320 nativePrototype = Object.getPrototypeOf(inst); 2057 var expectedPrototype = Object.getPrototypeOf(inst);
2058 if (expectedPrototype === definition.prototype) {
2059 nativePrototype = expectedPrototype;
2060 }
2321 } 2061 }
2322 var proto = definition.prototype, ancestor; 2062 var proto = definition.prototype, ancestor;
2323 var foundPrototype = false; 2063 while (proto && proto !== nativePrototype) {
2324 while (proto) {
2325 if (proto == nativePrototype) {
2326 foundPrototype = true;
2327 }
2328 ancestor = Object.getPrototypeOf(proto); 2064 ancestor = Object.getPrototypeOf(proto);
2329 if (ancestor) { 2065 proto.__proto__ = ancestor;
2330 proto.__proto__ = ancestor;
2331 }
2332 proto = ancestor; 2066 proto = ancestor;
2333 } 2067 }
2334 if (!foundPrototype) {
2335 console.warn(definition.tag + " prototype not found in prototype chain f or " + definition.is);
2336 }
2337 definition.native = nativePrototype; 2068 definition.native = nativePrototype;
2338 } 2069 }
2339 } 2070 }
2340 function instantiate(definition) { 2071 function instantiate(definition) {
2341 return upgradeWithDefinition(domCreateElement(definition.tag), definition); 2072 return upgradeWithDefinition(domCreateElement(definition.tag), definition);
2342 } 2073 }
2343 var registry = {}; 2074 var registry = {};
2344 function getRegisteredDefinition(name) { 2075 function getRegisteredDefinition(name) {
2345 if (name) { 2076 if (name) {
2346 return registry[name.toLowerCase()]; 2077 return registry[name.toLowerCase()];
2347 } 2078 }
2348 } 2079 }
2349 function registerDefinition(name, definition) { 2080 function registerDefinition(name, definition) {
2350 registry[name] = definition; 2081 registry[name] = definition;
2351 } 2082 }
2352 function generateConstructor(definition) { 2083 function generateConstructor(definition) {
2353 return function() { 2084 return function() {
2354 return instantiate(definition); 2085 return instantiate(definition);
2355 }; 2086 };
2356 } 2087 }
2357 var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml"; 2088 var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
2358 function createElementNS(namespace, tag, typeExtension) { 2089 function createElementNS(namespace, tag, typeExtension) {
2359 if (namespace === HTML_NAMESPACE) { 2090 if (namespace === HTML_NAMESPACE) {
2360 return createElement(tag, typeExtension); 2091 return createElement(tag, typeExtension);
2361 } else { 2092 } else {
2362 return domCreateElementNS(namespace, tag); 2093 return domCreateElementNS(namespace, tag);
2363 } 2094 }
2364 } 2095 }
2365 function createElement(tag, typeExtension) { 2096 function createElement(tag, typeExtension) {
2366 if (tag) {
2367 tag = tag.toLowerCase();
2368 }
2369 if (typeExtension) {
2370 typeExtension = typeExtension.toLowerCase();
2371 }
2372 var definition = getRegisteredDefinition(typeExtension || tag); 2097 var definition = getRegisteredDefinition(typeExtension || tag);
2373 if (definition) { 2098 if (definition) {
2374 if (tag == definition.tag && typeExtension == definition.is) { 2099 if (tag == definition.tag && typeExtension == definition.is) {
2375 return new definition.ctor(); 2100 return new definition.ctor();
2376 } 2101 }
2377 if (!typeExtension && !definition.is) { 2102 if (!typeExtension && !definition.is) {
2378 return new definition.ctor(); 2103 return new definition.ctor();
2379 } 2104 }
2380 } 2105 }
2381 var element; 2106 var element;
2382 if (typeExtension) { 2107 if (typeExtension) {
2383 element = createElement(tag); 2108 element = createElement(tag);
2384 element.setAttribute("is", typeExtension); 2109 element.setAttribute("is", typeExtension);
2385 return element; 2110 return element;
2386 } 2111 }
2387 element = domCreateElement(tag); 2112 element = domCreateElement(tag);
2388 if (tag.indexOf("-") >= 0) { 2113 if (tag.indexOf("-") >= 0) {
2389 implementPrototype(element, HTMLElement); 2114 implementPrototype(element, HTMLElement);
2390 } 2115 }
2391 return element; 2116 return element;
2392 } 2117 }
2393 var domCreateElement = document.createElement.bind(document); 2118 var domCreateElement = document.createElement.bind(document);
2394 var domCreateElementNS = document.createElementNS.bind(document); 2119 var domCreateElementNS = document.createElementNS.bind(document);
2395 var isInstance; 2120 var isInstance;
2396 if (!Object.__proto__ && !useNative) { 2121 if (!Object.__proto__ && !useNative) {
2397 isInstance = function(obj, ctor) { 2122 isInstance = function(obj, ctor) {
2398 if (obj instanceof ctor) {
2399 return true;
2400 }
2401 var p = obj; 2123 var p = obj;
2402 while (p) { 2124 while (p) {
2403 if (p === ctor.prototype) { 2125 if (p === ctor.prototype) {
2404 return true; 2126 return true;
2405 } 2127 }
2406 p = p.__proto__; 2128 p = p.__proto__;
2407 } 2129 }
2408 return false; 2130 return false;
2409 }; 2131 };
2410 } else { 2132 } else {
2411 isInstance = function(obj, base) { 2133 isInstance = function(obj, base) {
2412 return obj instanceof base; 2134 return obj instanceof base;
2413 }; 2135 };
2414 } 2136 }
2415 function wrapDomMethodToForceUpgrade(obj, methodName) { 2137 function wrapDomMethodToForceUpgrade(obj, methodName) {
2416 var orig = obj[methodName]; 2138 var orig = obj[methodName];
2417 obj[methodName] = function() { 2139 obj[methodName] = function() {
2418 var n = orig.apply(this, arguments); 2140 var n = orig.apply(this, arguments);
2419 upgradeAll(n); 2141 upgradeAll(n);
2420 return n; 2142 return n;
2421 }; 2143 };
2422 } 2144 }
2423 wrapDomMethodToForceUpgrade(Node.prototype, "cloneNode"); 2145 wrapDomMethodToForceUpgrade(Node.prototype, "cloneNode");
2424 wrapDomMethodToForceUpgrade(document, "importNode"); 2146 wrapDomMethodToForceUpgrade(document, "importNode");
2147 if (isIE11OrOlder) {
2148 (function() {
2149 var importNode = document.importNode;
2150 document.importNode = function() {
2151 var n = importNode.apply(document, arguments);
2152 if (n.nodeType == n.DOCUMENT_FRAGMENT_NODE) {
2153 var f = document.createDocumentFragment();
2154 f.appendChild(n);
2155 return f;
2156 } else {
2157 return n;
2158 }
2159 };
2160 })();
2161 }
2425 document.registerElement = register; 2162 document.registerElement = register;
2426 document.createElement = createElement; 2163 document.createElement = createElement;
2427 document.createElementNS = createElementNS; 2164 document.createElementNS = createElementNS;
2428 scope.registry = registry; 2165 scope.registry = registry;
2429 scope.instanceof = isInstance; 2166 scope.instanceof = isInstance;
2430 scope.reservedTagList = reservedTagList; 2167 scope.reservedTagList = reservedTagList;
2431 scope.getRegisteredDefinition = getRegisteredDefinition; 2168 scope.getRegisteredDefinition = getRegisteredDefinition;
2432 document.register = document.registerElement; 2169 document.register = document.registerElement;
2433 }); 2170 });
2434 2171
2435 (function(scope) { 2172 (function(scope) {
2436 var useNative = scope.useNative; 2173 var useNative = scope.useNative;
2437 var initializeModules = scope.initializeModules; 2174 var initializeModules = scope.initializeModules;
2438 var isIE = scope.isIE; 2175 var isIE11OrOlder = /Trident/.test(navigator.userAgent);
2439 if (useNative) { 2176 if (useNative) {
2440 var nop = function() {}; 2177 var nop = function() {};
2441 scope.watchShadow = nop; 2178 scope.watchShadow = nop;
2442 scope.upgrade = nop; 2179 scope.upgrade = nop;
2443 scope.upgradeAll = nop; 2180 scope.upgradeAll = nop;
2444 scope.upgradeDocumentTree = nop; 2181 scope.upgradeDocumentTree = nop;
2445 scope.upgradeSubtree = nop; 2182 scope.upgradeSubtree = nop;
2446 scope.takeRecords = nop; 2183 scope.takeRecords = nop;
2447 scope.instanceof = function(obj, base) { 2184 scope.instanceof = function(obj, base) {
2448 return obj instanceof base; 2185 return obj instanceof base;
2449 }; 2186 };
2450 } else { 2187 } else {
2451 initializeModules(); 2188 initializeModules();
2452 } 2189 }
2453 var upgradeDocumentTree = scope.upgradeDocumentTree; 2190 var upgradeDocumentTree = scope.upgradeDocumentTree;
2454 var upgradeDocument = scope.upgradeDocument;
2455 if (!window.wrap) { 2191 if (!window.wrap) {
2456 if (window.ShadowDOMPolyfill) { 2192 if (window.ShadowDOMPolyfill) {
2457 window.wrap = window.ShadowDOMPolyfill.wrapIfNeeded; 2193 window.wrap = ShadowDOMPolyfill.wrapIfNeeded;
2458 window.unwrap = window.ShadowDOMPolyfill.unwrapIfNeeded; 2194 window.unwrap = ShadowDOMPolyfill.unwrapIfNeeded;
2459 } else { 2195 } else {
2460 window.wrap = window.unwrap = function(node) { 2196 window.wrap = window.unwrap = function(node) {
2461 return node; 2197 return node;
2462 }; 2198 };
2463 } 2199 }
2464 } 2200 }
2465 if (window.HTMLImports) { 2201 function bootstrap() {
2466 window.HTMLImports.__importsParsingHook = function(elt) { 2202 upgradeDocumentTree(wrap(document));
2467 if (elt.import) { 2203 if (window.HTMLImports) {
2468 upgradeDocument(wrap(elt.import)); 2204 HTMLImports.__importsParsingHook = function(elt) {
2205 upgradeDocumentTree(wrap(elt.import));
2206 };
2207 }
2208 CustomElements.ready = true;
2209 setTimeout(function() {
2210 CustomElements.readyTime = Date.now();
2211 if (window.HTMLImports) {
2212 CustomElements.elapsed = CustomElements.readyTime - HTMLImports.readyTim e;
2469 } 2213 }
2214 document.dispatchEvent(new CustomEvent("WebComponentsReady", {
2215 bubbles: true
2216 }));
2217 });
2218 }
2219 if (isIE11OrOlder && typeof window.CustomEvent !== "function") {
2220 window.CustomEvent = function(inType, params) {
2221 params = params || {};
2222 var e = document.createEvent("CustomEvent");
2223 e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelab le), params.detail);
2224 return e;
2470 }; 2225 };
2471 } 2226 window.CustomEvent.prototype = window.Event.prototype;
2472 function bootstrap() {
2473 upgradeDocumentTree(window.wrap(document));
2474 window.CustomElements.ready = true;
2475 var requestAnimationFrame = window.requestAnimationFrame || function(f) {
2476 setTimeout(f, 16);
2477 };
2478 requestAnimationFrame(function() {
2479 setTimeout(function() {
2480 window.CustomElements.readyTime = Date.now();
2481 if (window.HTMLImports) {
2482 window.CustomElements.elapsed = window.CustomElements.readyTime - wind ow.HTMLImports.readyTime;
2483 }
2484 document.dispatchEvent(new CustomEvent("WebComponentsReady", {
2485 bubbles: true
2486 }));
2487 });
2488 });
2489 } 2227 }
2490 if (document.readyState === "complete" || scope.flags.eager) { 2228 if (document.readyState === "complete" || scope.flags.eager) {
2491 bootstrap(); 2229 bootstrap();
2492 } else if (document.readyState === "interactive" && !window.attachEvent && (!w indow.HTMLImports || window.HTMLImports.ready)) { 2230 } else if (document.readyState === "interactive" && !window.attachEvent && (!w indow.HTMLImports || window.HTMLImports.ready)) {
2493 bootstrap(); 2231 bootstrap();
2494 } else { 2232 } else {
2495 var loadEvent = window.HTMLImports && !window.HTMLImports.ready ? "HTMLImpor tsLoaded" : "DOMContentLoaded"; 2233 var loadEvent = window.HTMLImports && !HTMLImports.ready ? "HTMLImportsLoade d" : "DOMContentLoaded";
2496 window.addEventListener(loadEvent, bootstrap); 2234 window.addEventListener(loadEvent, bootstrap);
2497 } 2235 }
2236 scope.isIE11OrOlder = isIE11OrOlder;
2498 })(window.CustomElements); 2237 })(window.CustomElements);
2499 2238
2239 if (typeof HTMLTemplateElement === "undefined") {
2240 (function() {
2241 var TEMPLATE_TAG = "template";
2242 HTMLTemplateElement = function() {};
2243 HTMLTemplateElement.prototype = Object.create(HTMLElement.prototype);
2244 HTMLTemplateElement.decorate = function(template) {
2245 if (!template.content) {
2246 template.content = template.ownerDocument.createDocumentFragment();
2247 var child;
2248 while (child = template.firstChild) {
2249 template.content.appendChild(child);
2250 }
2251 }
2252 };
2253 HTMLTemplateElement.bootstrap = function(doc) {
2254 var templates = doc.querySelectorAll(TEMPLATE_TAG);
2255 for (var i = 0, l = templates.length, t; i < l && (t = templates[i]); i++) {
2256 HTMLTemplateElement.decorate(t);
2257 }
2258 };
2259 addEventListener("DOMContentLoaded", function() {
2260 HTMLTemplateElement.bootstrap(document);
2261 });
2262 })();
2263 }
2264
2500 (function(scope) { 2265 (function(scope) {
2501 var style = document.createElement("style"); 2266 var style = document.createElement("style");
2502 style.textContent = "" + "body {" + "transition: opacity ease-in 0.2s;" + " } \n" + "body[unresolved] {" + "opacity: 0; display: block; overflow: hidden; posi tion: relative;" + " } \n"; 2267 style.textContent = "" + "body {" + "transition: opacity ease-in 0.2s;" + " } \n" + "body[unresolved] {" + "opacity: 0; display: block; overflow: hidden; posi tion: relative;" + " } \n";
2503 var head = document.querySelector("head"); 2268 var head = document.querySelector("head");
2504 head.insertBefore(style, head.firstChild); 2269 head.insertBefore(style, head.firstChild);
2505 })(window.WebComponents); 2270 })(window.WebComponents);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698