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

Side by Side Diff: packages/web_components/lib/webcomponents.js

Issue 2312183003: Removed Polymer from Observatory deps (Closed)
Patch Set: Created 4 years, 3 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.5.1 10 // @version 0.7.21
11 window.WebComponents = window.WebComponents || {}; 11 (function() {
12 12 window.WebComponents = window.WebComponents || {
13 (function(scope) { 13 flags: {}
14 var flags = scope.flags || {}; 14 };
15 var file = "webcomponents.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 = {};
17 if (!flags.noOpts) { 18 if (!flags.noOpts) {
18 location.search.slice(1).split("&").forEach(function(o) { 19 location.search.slice(1).split("&").forEach(function(option) {
19 o = o.split("="); 20 var parts = option.split("=");
20 o[0] && (flags[o[0]] = o[1] || true); 21 var match;
22 if (parts[0] && (match = parts[0].match(/wc-(.+)/))) {
23 flags[match[1]] = parts[1] || true;
24 }
21 }); 25 });
22 if (script) { 26 if (script) {
23 for (var i = 0, a; a = script.attributes[i]; i++) { 27 for (var i = 0, a; a = script.attributes[i]; i++) {
24 if (a.name !== "src") { 28 if (a.name !== "src") {
25 flags[a.name] = a.value || true; 29 flags[a.name] = a.value || true;
26 } 30 }
27 } 31 }
28 } 32 }
29 if (flags.log) { 33 if (flags.log && flags.log.split) {
30 var parts = flags.log.split(","); 34 var parts = flags.log.split(",");
31 flags.log = {}; 35 flags.log = {};
32 parts.forEach(function(f) { 36 parts.forEach(function(f) {
33 flags.log[f] = true; 37 flags.log[f] = true;
34 }); 38 });
35 } else { 39 } else {
36 flags.log = {}; 40 flags.log = {};
37 } 41 }
38 } 42 }
39 flags.shadow = flags.shadow || flags.shadowdom || flags.polyfill; 43 flags.shadow = flags.shadow || flags.shadowdom || flags.polyfill;
40 if (flags.shadow === "native") { 44 if (flags.shadow === "native") {
41 flags.shadow = false; 45 flags.shadow = false;
42 } else { 46 } else {
43 flags.shadow = flags.shadow || !HTMLElement.prototype.createShadowRoot; 47 flags.shadow = flags.shadow || !HTMLElement.prototype.createShadowRoot;
44 } 48 }
45 if (flags.register) { 49 if (flags.register) {
46 window.CustomElements = window.CustomElements || { 50 window.CustomElements = window.CustomElements || {
47 flags: {} 51 flags: {}
48 }; 52 };
49 window.CustomElements.flags.register = flags.register; 53 window.CustomElements.flags.register = flags.register;
50 } 54 }
51 scope.flags = flags; 55 WebComponents.flags = flags;
52 })(WebComponents); 56 })();
53 57
54 if (WebComponents.flags.shadow) { 58 if (WebComponents.flags.shadow) {
55 if (typeof WeakMap === "undefined") { 59 if (typeof WeakMap === "undefined") {
56 (function() { 60 (function() {
57 var defineProperty = Object.defineProperty; 61 var defineProperty = Object.defineProperty;
58 var counter = Date.now() % 1e9; 62 var counter = Date.now() % 1e9;
59 var WeakMap = function() { 63 var WeakMap = function() {
60 this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__"); 64 this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__");
61 }; 65 };
62 WeakMap.prototype = { 66 WeakMap.prototype = {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 value: undefined, 152 value: undefined,
149 configurable: true, 153 configurable: true,
150 enumerable: false, 154 enumerable: false,
151 writable: true 155 writable: true
152 }; 156 };
153 function defineNonEnumerableDataProperty(object, name, value) { 157 function defineNonEnumerableDataProperty(object, name, value) {
154 nonEnumerableDataDescriptor.value = value; 158 nonEnumerableDataDescriptor.value = value;
155 defineProperty(object, name, nonEnumerableDataDescriptor); 159 defineProperty(object, name, nonEnumerableDataDescriptor);
156 } 160 }
157 getOwnPropertyNames(window); 161 getOwnPropertyNames(window);
158 function getWrapperConstructor(node) { 162 function getWrapperConstructor(node, opt_instance) {
159 var nativePrototype = node.__proto__ || Object.getPrototypeOf(node); 163 var nativePrototype = node.__proto__ || Object.getPrototypeOf(node);
164 if (isFirefox) {
165 try {
166 getOwnPropertyNames(nativePrototype);
167 } catch (error) {
168 nativePrototype = nativePrototype.__proto__;
169 }
170 }
160 var wrapperConstructor = constructorTable.get(nativePrototype); 171 var wrapperConstructor = constructorTable.get(nativePrototype);
161 if (wrapperConstructor) return wrapperConstructor; 172 if (wrapperConstructor) return wrapperConstructor;
162 var parentWrapperConstructor = getWrapperConstructor(nativePrototype); 173 var parentWrapperConstructor = getWrapperConstructor(nativePrototype);
163 var GeneratedWrapper = createWrapperConstructor(parentWrapperConstructor); 174 var GeneratedWrapper = createWrapperConstructor(parentWrapperConstructor);
164 registerInternal(nativePrototype, GeneratedWrapper, node); 175 registerInternal(nativePrototype, GeneratedWrapper, opt_instance);
165 return GeneratedWrapper; 176 return GeneratedWrapper;
166 } 177 }
167 function addForwardingProperties(nativePrototype, wrapperPrototype) { 178 function addForwardingProperties(nativePrototype, wrapperPrototype) {
168 installProperty(nativePrototype, wrapperPrototype, true); 179 installProperty(nativePrototype, wrapperPrototype, true);
169 } 180 }
170 function registerInstanceProperties(wrapperPrototype, instanceObject) { 181 function registerInstanceProperties(wrapperPrototype, instanceObject) {
171 installProperty(instanceObject, wrapperPrototype, false); 182 installProperty(instanceObject, wrapperPrototype, false);
172 } 183 }
173 var isFirefox = /Firefox/.test(navigator.userAgent); 184 var isFirefox = /Firefox/.test(navigator.userAgent);
174 var dummyDescriptor = { 185 var dummyDescriptor = {
175 get: function() {}, 186 get: function() {},
176 set: function(v) {}, 187 set: function(v) {},
177 configurable: true, 188 configurable: true,
178 enumerable: true 189 enumerable: true
179 }; 190 };
180 function isEventHandlerName(name) { 191 function isEventHandlerName(name) {
181 return /^on[a-z]+$/.test(name); 192 return /^on[a-z]+$/.test(name);
182 } 193 }
183 function isIdentifierName(name) { 194 function isIdentifierName(name) {
184 return /^\w[a-zA-Z_0-9]*$/.test(name); 195 return /^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test(name);
185 } 196 }
186 function getGetter(name) { 197 function getGetter(name) {
187 return hasEval && isIdentifierName(name) ? new Function("return this.__imp l4cf1e782hg__." + name) : function() { 198 return hasEval && isIdentifierName(name) ? new Function("return this.__imp l4cf1e782hg__." + name) : function() {
188 return this.__impl4cf1e782hg__[name]; 199 return this.__impl4cf1e782hg__[name];
189 }; 200 };
190 } 201 }
191 function getSetter(name) { 202 function getSetter(name) {
192 return hasEval && isIdentifierName(name) ? new Function("v", "this.__impl4 cf1e782hg__." + name + " = v") : function(v) { 203 return hasEval && isIdentifierName(name) ? new Function("v", "this.__impl4 cf1e782hg__." + name + " = v") : function(v) {
193 this.__impl4cf1e782hg__[name] = v; 204 this.__impl4cf1e782hg__[name] = v;
194 }; 205 };
(...skipping 19 matching lines...) Expand all
214 for (var i = 0; i < names.length; i++) { 225 for (var i = 0; i < names.length; i++) {
215 var name = names[i]; 226 var name = names[i];
216 if (name === "polymerBlackList_") continue; 227 if (name === "polymerBlackList_") continue;
217 if (name in target) continue; 228 if (name in target) continue;
218 if (source.polymerBlackList_ && source.polymerBlackList_[name]) continue ; 229 if (source.polymerBlackList_ && source.polymerBlackList_[name]) continue ;
219 if (isFirefox) { 230 if (isFirefox) {
220 source.__lookupGetter__(name); 231 source.__lookupGetter__(name);
221 } 232 }
222 var descriptor = getDescriptor(source, name); 233 var descriptor = getDescriptor(source, name);
223 var getter, setter; 234 var getter, setter;
224 if (allowMethod && typeof descriptor.value === "function") { 235 if (typeof descriptor.value === "function") {
225 target[name] = getMethod(name); 236 if (allowMethod) {
237 target[name] = getMethod(name);
238 }
226 continue; 239 continue;
227 } 240 }
228 var isEvent = isEventHandlerName(name); 241 var isEvent = isEventHandlerName(name);
229 if (isEvent) getter = scope.getEventHandlerGetter(name); else getter = g etGetter(name); 242 if (isEvent) getter = scope.getEventHandlerGetter(name); else getter = g etGetter(name);
230 if (descriptor.writable || descriptor.set || isBrokenSafari) { 243 if (descriptor.writable || descriptor.set || isBrokenSafari) {
231 if (isEvent) setter = scope.getEventHandlerSetter(name); else setter = getSetter(name); 244 if (isEvent) setter = scope.getEventHandlerSetter(name); else setter = getSetter(name);
232 } 245 }
246 var configurable = isBrokenSafari || descriptor.configurable;
233 defineProperty(target, name, { 247 defineProperty(target, name, {
234 get: getter, 248 get: getter,
235 set: setter, 249 set: setter,
236 configurable: descriptor.configurable, 250 configurable: configurable,
237 enumerable: descriptor.enumerable 251 enumerable: descriptor.enumerable
238 }); 252 });
239 } 253 }
240 } 254 }
241 function register(nativeConstructor, wrapperConstructor, opt_instance) { 255 function register(nativeConstructor, wrapperConstructor, opt_instance) {
256 if (nativeConstructor == null) {
257 return;
258 }
242 var nativePrototype = nativeConstructor.prototype; 259 var nativePrototype = nativeConstructor.prototype;
243 registerInternal(nativePrototype, wrapperConstructor, opt_instance); 260 registerInternal(nativePrototype, wrapperConstructor, opt_instance);
244 mixinStatics(wrapperConstructor, nativeConstructor); 261 mixinStatics(wrapperConstructor, nativeConstructor);
245 } 262 }
246 function registerInternal(nativePrototype, wrapperConstructor, opt_instance) { 263 function registerInternal(nativePrototype, wrapperConstructor, opt_instance) {
247 var wrapperPrototype = wrapperConstructor.prototype; 264 var wrapperPrototype = wrapperConstructor.prototype;
248 assert(constructorTable.get(nativePrototype) === undefined); 265 assert(constructorTable.get(nativePrototype) === undefined);
249 constructorTable.set(nativePrototype, wrapperConstructor); 266 constructorTable.set(nativePrototype, wrapperConstructor);
250 nativePrototypeTable.set(wrapperPrototype, nativePrototype); 267 nativePrototypeTable.set(wrapperPrototype, nativePrototype);
251 addForwardingProperties(nativePrototype, wrapperPrototype); 268 addForwardingProperties(nativePrototype, wrapperPrototype);
(...skipping 22 matching lines...) Expand all
274 } 291 }
275 function isWrapper(object) { 292 function isWrapper(object) {
276 return object && object.__impl4cf1e782hg__; 293 return object && object.__impl4cf1e782hg__;
277 } 294 }
278 function isNative(object) { 295 function isNative(object) {
279 return !isWrapper(object); 296 return !isWrapper(object);
280 } 297 }
281 function wrap(impl) { 298 function wrap(impl) {
282 if (impl === null) return null; 299 if (impl === null) return null;
283 assert(isNative(impl)); 300 assert(isNative(impl));
284 return impl.__wrapper8e3dd93a60__ || (impl.__wrapper8e3dd93a60__ = new (ge tWrapperConstructor(impl))(impl)); 301 var wrapper = impl.__wrapper8e3dd93a60__;
302 if (wrapper != null) {
303 return wrapper;
304 }
305 return impl.__wrapper8e3dd93a60__ = new (getWrapperConstructor(impl, impl) )(impl);
285 } 306 }
286 function unwrap(wrapper) { 307 function unwrap(wrapper) {
287 if (wrapper === null) return null; 308 if (wrapper === null) return null;
288 assert(isWrapper(wrapper)); 309 assert(isWrapper(wrapper));
289 return wrapper.__impl4cf1e782hg__; 310 return wrapper.__impl4cf1e782hg__;
290 } 311 }
291 function unsafeUnwrap(wrapper) { 312 function unsafeUnwrap(wrapper) {
292 return wrapper.__impl4cf1e782hg__; 313 return wrapper.__impl4cf1e782hg__;
293 } 314 }
294 function setWrapper(impl, wrapper) { 315 function setWrapper(impl, wrapper) {
(...skipping 29 matching lines...) Expand all
324 function forwardMethodsToWrapper(constructors, names) { 345 function forwardMethodsToWrapper(constructors, names) {
325 constructors.forEach(function(constructor) { 346 constructors.forEach(function(constructor) {
326 names.forEach(function(name) { 347 names.forEach(function(name) {
327 constructor.prototype[name] = function() { 348 constructor.prototype[name] = function() {
328 var w = wrapIfNeeded(this); 349 var w = wrapIfNeeded(this);
329 return w[name].apply(w, arguments); 350 return w[name].apply(w, arguments);
330 }; 351 };
331 }); 352 });
332 }); 353 });
333 } 354 }
355 scope.addForwardingProperties = addForwardingProperties;
334 scope.assert = assert; 356 scope.assert = assert;
335 scope.constructorTable = constructorTable; 357 scope.constructorTable = constructorTable;
336 scope.defineGetter = defineGetter; 358 scope.defineGetter = defineGetter;
337 scope.defineWrapGetter = defineWrapGetter; 359 scope.defineWrapGetter = defineWrapGetter;
338 scope.forwardMethodsToWrapper = forwardMethodsToWrapper; 360 scope.forwardMethodsToWrapper = forwardMethodsToWrapper;
361 scope.isIdentifierName = isIdentifierName;
339 scope.isWrapper = isWrapper; 362 scope.isWrapper = isWrapper;
340 scope.isWrapperFor = isWrapperFor; 363 scope.isWrapperFor = isWrapperFor;
341 scope.mixin = mixin; 364 scope.mixin = mixin;
342 scope.nativePrototypeTable = nativePrototypeTable; 365 scope.nativePrototypeTable = nativePrototypeTable;
343 scope.oneOf = oneOf; 366 scope.oneOf = oneOf;
344 scope.registerObject = registerObject; 367 scope.registerObject = registerObject;
345 scope.registerWrapper = register; 368 scope.registerWrapper = register;
346 scope.rewrap = rewrap; 369 scope.rewrap = rewrap;
347 scope.setWrapper = setWrapper; 370 scope.setWrapper = setWrapper;
348 scope.unsafeUnwrap = unsafeUnwrap; 371 scope.unsafeUnwrap = unsafeUnwrap;
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 return eventPath.slice(); 1153 return eventPath.slice();
1131 }, 1154 },
1132 stopPropagation: function() { 1155 stopPropagation: function() {
1133 stopPropagationTable.set(this, true); 1156 stopPropagationTable.set(this, true);
1134 }, 1157 },
1135 stopImmediatePropagation: function() { 1158 stopImmediatePropagation: function() {
1136 stopPropagationTable.set(this, true); 1159 stopPropagationTable.set(this, true);
1137 stopImmediatePropagationTable.set(this, true); 1160 stopImmediatePropagationTable.set(this, true);
1138 } 1161 }
1139 }; 1162 };
1163 var supportsDefaultPrevented = function() {
1164 var e = document.createEvent("Event");
1165 e.initEvent("test", true, true);
1166 e.preventDefault();
1167 return e.defaultPrevented;
1168 }();
1169 if (!supportsDefaultPrevented) {
1170 Event.prototype.preventDefault = function() {
1171 if (!this.cancelable) return;
1172 unsafeUnwrap(this).preventDefault();
1173 Object.defineProperty(this, "defaultPrevented", {
1174 get: function() {
1175 return true;
1176 },
1177 configurable: true
1178 });
1179 };
1180 }
1140 registerWrapper(OriginalEvent, Event, document.createEvent("Event")); 1181 registerWrapper(OriginalEvent, Event, document.createEvent("Event"));
1141 function unwrapOptions(options) { 1182 function unwrapOptions(options) {
1142 if (!options || !options.relatedTarget) return options; 1183 if (!options || !options.relatedTarget) return options;
1143 return Object.create(options, { 1184 return Object.create(options, {
1144 relatedTarget: { 1185 relatedTarget: {
1145 value: unwrap(options.relatedTarget) 1186 value: unwrap(options.relatedTarget)
1146 } 1187 }
1147 }); 1188 });
1148 } 1189 }
1149 function registerGenericEvent(name, SuperEvent, prototype) { 1190 function registerGenericEvent(name, SuperEvent, prototype) {
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 this.parentNode_ = undefined; 1790 this.parentNode_ = undefined;
1750 this.firstChild_ = undefined; 1791 this.firstChild_ = undefined;
1751 this.lastChild_ = undefined; 1792 this.lastChild_ = undefined;
1752 this.nextSibling_ = undefined; 1793 this.nextSibling_ = undefined;
1753 this.previousSibling_ = undefined; 1794 this.previousSibling_ = undefined;
1754 this.treeScope_ = undefined; 1795 this.treeScope_ = undefined;
1755 } 1796 }
1756 var OriginalDocumentFragment = window.DocumentFragment; 1797 var OriginalDocumentFragment = window.DocumentFragment;
1757 var originalAppendChild = OriginalNode.prototype.appendChild; 1798 var originalAppendChild = OriginalNode.prototype.appendChild;
1758 var originalCompareDocumentPosition = OriginalNode.prototype.compareDocument Position; 1799 var originalCompareDocumentPosition = OriginalNode.prototype.compareDocument Position;
1800 var originalIsEqualNode = OriginalNode.prototype.isEqualNode;
1759 var originalInsertBefore = OriginalNode.prototype.insertBefore; 1801 var originalInsertBefore = OriginalNode.prototype.insertBefore;
1760 var originalRemoveChild = OriginalNode.prototype.removeChild; 1802 var originalRemoveChild = OriginalNode.prototype.removeChild;
1761 var originalReplaceChild = OriginalNode.prototype.replaceChild; 1803 var originalReplaceChild = OriginalNode.prototype.replaceChild;
1762 var isIe = /Trident/.test(navigator.userAgent); 1804 var isIEOrEdge = /Trident|Edge/.test(navigator.userAgent);
1763 var removeChildOriginalHelper = isIe ? function(parent, child) { 1805 var removeChildOriginalHelper = isIEOrEdge ? function(parent, child) {
1764 try { 1806 try {
1765 originalRemoveChild.call(parent, child); 1807 originalRemoveChild.call(parent, child);
1766 } catch (ex) { 1808 } catch (ex) {
1767 if (!(parent instanceof OriginalDocumentFragment)) throw ex; 1809 if (!(parent instanceof OriginalDocumentFragment)) throw ex;
1768 } 1810 }
1769 } : function(parent, child) { 1811 } : function(parent, child) {
1770 originalRemoveChild.call(parent, child); 1812 originalRemoveChild.call(parent, child);
1771 }; 1813 };
1772 Node.prototype = Object.create(EventTarget.prototype); 1814 Node.prototype = Object.create(EventTarget.prototype);
1773 mixin(Node.prototype, { 1815 mixin(Node.prototype, {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1977 }, 2019 },
1978 cloneNode: function(deep) { 2020 cloneNode: function(deep) {
1979 return cloneNode(this, deep); 2021 return cloneNode(this, deep);
1980 }, 2022 },
1981 contains: function(child) { 2023 contains: function(child) {
1982 return contains(this, wrapIfNeeded(child)); 2024 return contains(this, wrapIfNeeded(child));
1983 }, 2025 },
1984 compareDocumentPosition: function(otherNode) { 2026 compareDocumentPosition: function(otherNode) {
1985 return originalCompareDocumentPosition.call(unsafeUnwrap(this), unwrapIf Needed(otherNode)); 2027 return originalCompareDocumentPosition.call(unsafeUnwrap(this), unwrapIf Needed(otherNode));
1986 }, 2028 },
2029 isEqualNode: function(otherNode) {
2030 return originalIsEqualNode.call(unsafeUnwrap(this), unwrapIfNeeded(other Node));
2031 },
1987 normalize: function() { 2032 normalize: function() {
1988 var nodes = snapshotNodeList(this.childNodes); 2033 var nodes = snapshotNodeList(this.childNodes);
1989 var remNodes = []; 2034 var remNodes = [];
1990 var s = ""; 2035 var s = "";
1991 var modNode; 2036 var modNode;
1992 for (var i = 0, n; i < nodes.length; i++) { 2037 for (var i = 0, n; i < nodes.length; i++) {
1993 n = nodes[i]; 2038 n = nodes[i];
1994 if (n.nodeType === Node.TEXT_NODE) { 2039 if (n.nodeType === Node.TEXT_NODE) {
1995 if (!modNode && !n.data.length) this.removeNode(n); else if (!modNod e) modNode = n; else { 2040 if (!modNode && !n.data.length) this.removeChild(n); else if (!modNo de) modNode = n; else {
1996 s += n.data; 2041 s += n.data;
1997 remNodes.push(n); 2042 remNodes.push(n);
1998 } 2043 }
1999 } else { 2044 } else {
2000 if (modNode && remNodes.length) { 2045 if (modNode && remNodes.length) {
2001 modNode.data += s; 2046 modNode.data += s;
2002 cleanupNodes(remNodes); 2047 cleanupNodes(remNodes);
2003 } 2048 }
2004 remNodes = []; 2049 remNodes = [];
2005 s = ""; 2050 s = "";
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2053 if (!deep && (root = getTreeScope(wrappedItem).root)) { 2098 if (!deep && (root = getTreeScope(wrappedItem).root)) {
2054 if (root instanceof scope.wrappers.ShadowRoot) { 2099 if (root instanceof scope.wrappers.ShadowRoot) {
2055 continue; 2100 continue;
2056 } 2101 }
2057 } 2102 }
2058 result[index++] = wrappedItem; 2103 result[index++] = wrappedItem;
2059 } 2104 }
2060 return index; 2105 return index;
2061 } 2106 }
2062 function shimSelector(selector) { 2107 function shimSelector(selector) {
2063 return String(selector).replace(/\/deep\//g, " "); 2108 return String(selector).replace(/\/deep\/|::shadow|>>>/g, " ");
2109 }
2110 function shimMatchesSelector(selector) {
2111 return String(selector).replace(/:host\(([^\s]+)\)/g, "$1").replace(/([^\s ]):host/g, "$1").replace(":host", "*").replace(/\^|\/shadow\/|\/shadow-deep\/|:: shadow|\/deep\/|::content|>>>/g, " ");
2064 } 2112 }
2065 function findOne(node, selector) { 2113 function findOne(node, selector) {
2066 var m, el = node.firstElementChild; 2114 var m, el = node.firstElementChild;
2067 while (el) { 2115 while (el) {
2068 if (el.matches(selector)) return el; 2116 if (el.matches(selector)) return el;
2069 m = findOne(el, selector); 2117 m = findOne(el, selector);
2070 if (m) return m; 2118 if (m) return m;
2071 el = el.nextElementSibling; 2119 el = el.nextElementSibling;
2072 } 2120 }
2073 return null; 2121 return null;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2144 }, 2192 },
2145 querySelectorAll: function(selector) { 2193 querySelectorAll: function(selector) {
2146 var shimmed = shimSelector(selector); 2194 var shimmed = shimSelector(selector);
2147 var deep = shimmed !== selector; 2195 var deep = shimmed !== selector;
2148 selector = shimmed; 2196 selector = shimmed;
2149 var result = new NodeList(); 2197 var result = new NodeList();
2150 result.length = querySelectorAllFiltered.call(this, matchesSelector, 0, result, selector, deep); 2198 result.length = querySelectorAllFiltered.call(this, matchesSelector, 0, result, selector, deep);
2151 return result; 2199 return result;
2152 } 2200 }
2153 }; 2201 };
2202 var MatchesInterface = {
2203 matches: function(selector) {
2204 selector = shimMatchesSelector(selector);
2205 return scope.originalMatches.call(unsafeUnwrap(this), selector);
2206 }
2207 };
2154 function getElementsByTagNameFiltered(p, index, result, localName, lowercase ) { 2208 function getElementsByTagNameFiltered(p, index, result, localName, lowercase ) {
2155 var target = unsafeUnwrap(this); 2209 var target = unsafeUnwrap(this);
2156 var list; 2210 var list;
2157 var root = getTreeScope(this).root; 2211 var root = getTreeScope(this).root;
2158 if (root instanceof scope.wrappers.ShadowRoot) { 2212 if (root instanceof scope.wrappers.ShadowRoot) {
2159 return findElements(this, index, result, p, localName, lowercase); 2213 return findElements(this, index, result, p, localName, lowercase);
2160 } else if (target instanceof OriginalElement) { 2214 } else if (target instanceof OriginalElement) {
2161 list = originalElementGetElementsByTagName.call(target, localName, lower case); 2215 list = originalElementGetElementsByTagName.call(target, localName, lower case);
2162 } else if (target instanceof OriginalDocument) { 2216 } else if (target instanceof OriginalDocument) {
2163 list = originalDocumentGetElementsByTagName.call(target, localName, lowe rcase); 2217 list = originalDocumentGetElementsByTagName.call(target, localName, lowe rcase);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2198 match = localName === "*" ? matchesEveryThing : matchesLocalNameOnly; 2252 match = localName === "*" ? matchesEveryThing : matchesLocalNameOnly;
2199 } else { 2253 } else {
2200 match = localName === "*" ? matchesNameSpace : matchesLocalNameNS; 2254 match = localName === "*" ? matchesNameSpace : matchesLocalNameNS;
2201 } 2255 }
2202 result.length = getElementsByTagNameNSFiltered.call(this, match, 0, resu lt, ns || null, localName); 2256 result.length = getElementsByTagNameNSFiltered.call(this, match, 0, resu lt, ns || null, localName);
2203 return result; 2257 return result;
2204 } 2258 }
2205 }; 2259 };
2206 scope.GetElementsByInterface = GetElementsByInterface; 2260 scope.GetElementsByInterface = GetElementsByInterface;
2207 scope.SelectorsInterface = SelectorsInterface; 2261 scope.SelectorsInterface = SelectorsInterface;
2262 scope.MatchesInterface = MatchesInterface;
2208 })(window.ShadowDOMPolyfill); 2263 })(window.ShadowDOMPolyfill);
2209 (function(scope) { 2264 (function(scope) {
2210 "use strict"; 2265 "use strict";
2211 var NodeList = scope.wrappers.NodeList; 2266 var NodeList = scope.wrappers.NodeList;
2212 function forwardElement(node) { 2267 function forwardElement(node) {
2213 while (node && node.nodeType !== Node.ELEMENT_NODE) { 2268 while (node && node.nodeType !== Node.ELEMENT_NODE) {
2214 node = node.nextSibling; 2269 node = node.nextSibling;
2215 } 2270 }
2216 return node; 2271 return node;
2217 } 2272 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2250 } 2305 }
2251 }; 2306 };
2252 var ChildNodeInterface = { 2307 var ChildNodeInterface = {
2253 get nextElementSibling() { 2308 get nextElementSibling() {
2254 return forwardElement(this.nextSibling); 2309 return forwardElement(this.nextSibling);
2255 }, 2310 },
2256 get previousElementSibling() { 2311 get previousElementSibling() {
2257 return backwardsElement(this.previousSibling); 2312 return backwardsElement(this.previousSibling);
2258 } 2313 }
2259 }; 2314 };
2315 var NonElementParentNodeInterface = {
2316 getElementById: function(id) {
2317 if (/[ \t\n\r\f]/.test(id)) return null;
2318 return this.querySelector('[id="' + id + '"]');
2319 }
2320 };
2260 scope.ChildNodeInterface = ChildNodeInterface; 2321 scope.ChildNodeInterface = ChildNodeInterface;
2322 scope.NonElementParentNodeInterface = NonElementParentNodeInterface;
2261 scope.ParentNodeInterface = ParentNodeInterface; 2323 scope.ParentNodeInterface = ParentNodeInterface;
2262 })(window.ShadowDOMPolyfill); 2324 })(window.ShadowDOMPolyfill);
2263 (function(scope) { 2325 (function(scope) {
2264 "use strict"; 2326 "use strict";
2265 var ChildNodeInterface = scope.ChildNodeInterface; 2327 var ChildNodeInterface = scope.ChildNodeInterface;
2266 var Node = scope.wrappers.Node; 2328 var Node = scope.wrappers.Node;
2267 var enqueueMutation = scope.enqueueMutation; 2329 var enqueueMutation = scope.enqueueMutation;
2268 var mixin = scope.mixin; 2330 var mixin = scope.mixin;
2269 var registerWrapper = scope.registerWrapper; 2331 var registerWrapper = scope.registerWrapper;
2270 var unsafeUnwrap = scope.unsafeUnwrap; 2332 var unsafeUnwrap = scope.unsafeUnwrap;
2271 var OriginalCharacterData = window.CharacterData; 2333 var OriginalCharacterData = window.CharacterData;
2272 function CharacterData(node) { 2334 function CharacterData(node) {
2273 Node.call(this, node); 2335 Node.call(this, node);
2274 } 2336 }
2275 CharacterData.prototype = Object.create(Node.prototype); 2337 CharacterData.prototype = Object.create(Node.prototype);
2276 mixin(CharacterData.prototype, { 2338 mixin(CharacterData.prototype, {
2339 get nodeValue() {
2340 return this.data;
2341 },
2342 set nodeValue(data) {
2343 this.data = data;
2344 },
2277 get textContent() { 2345 get textContent() {
2278 return this.data; 2346 return this.data;
2279 }, 2347 },
2280 set textContent(value) { 2348 set textContent(value) {
2281 this.data = value; 2349 this.data = value;
2282 }, 2350 },
2283 get data() { 2351 get data() {
2284 return unsafeUnwrap(this).data; 2352 return unsafeUnwrap(this).data;
2285 }, 2353 },
2286 set data(value) { 2354 set data(value) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2320 var newTextNode = this.ownerDocument.createTextNode(tail); 2388 var newTextNode = this.ownerDocument.createTextNode(tail);
2321 if (this.parentNode) this.parentNode.insertBefore(newTextNode, this.next Sibling); 2389 if (this.parentNode) this.parentNode.insertBefore(newTextNode, this.next Sibling);
2322 return newTextNode; 2390 return newTextNode;
2323 } 2391 }
2324 }); 2392 });
2325 registerWrapper(OriginalText, Text, document.createTextNode("")); 2393 registerWrapper(OriginalText, Text, document.createTextNode(""));
2326 scope.wrappers.Text = Text; 2394 scope.wrappers.Text = Text;
2327 })(window.ShadowDOMPolyfill); 2395 })(window.ShadowDOMPolyfill);
2328 (function(scope) { 2396 (function(scope) {
2329 "use strict"; 2397 "use strict";
2330 var setWrapper = scope.setWrapper; 2398 if (!window.DOMTokenList) {
2399 console.warn("Missing DOMTokenList prototype, please include a " + "compat ible classList polyfill such as http://goo.gl/uTcepH.");
2400 return;
2401 }
2331 var unsafeUnwrap = scope.unsafeUnwrap; 2402 var unsafeUnwrap = scope.unsafeUnwrap;
2403 var enqueueMutation = scope.enqueueMutation;
2404 function getClass(el) {
2405 return unsafeUnwrap(el).getAttribute("class");
2406 }
2407 function enqueueClassAttributeChange(el, oldValue) {
2408 enqueueMutation(el, "attributes", {
2409 name: "class",
2410 namespace: null,
2411 oldValue: oldValue
2412 });
2413 }
2332 function invalidateClass(el) { 2414 function invalidateClass(el) {
2333 scope.invalidateRendererBasedOnAttribute(el, "class"); 2415 scope.invalidateRendererBasedOnAttribute(el, "class");
2334 } 2416 }
2335 function DOMTokenList(impl, ownerElement) { 2417 function changeClass(tokenList, method, args) {
2336 setWrapper(impl, this); 2418 var ownerElement = tokenList.ownerElement_;
2337 this.ownerElement_ = ownerElement; 2419 if (ownerElement == null) {
2420 return method.apply(tokenList, args);
2421 }
2422 var oldValue = getClass(ownerElement);
2423 var retv = method.apply(tokenList, args);
2424 if (getClass(ownerElement) !== oldValue) {
2425 enqueueClassAttributeChange(ownerElement, oldValue);
2426 invalidateClass(ownerElement);
2427 }
2428 return retv;
2338 } 2429 }
2339 DOMTokenList.prototype = { 2430 var oldAdd = DOMTokenList.prototype.add;
2340 constructor: DOMTokenList, 2431 DOMTokenList.prototype.add = function() {
2341 get length() { 2432 changeClass(this, oldAdd, arguments);
2342 return unsafeUnwrap(this).length;
2343 },
2344 item: function(index) {
2345 return unsafeUnwrap(this).item(index);
2346 },
2347 contains: function(token) {
2348 return unsafeUnwrap(this).contains(token);
2349 },
2350 add: function() {
2351 unsafeUnwrap(this).add.apply(unsafeUnwrap(this), arguments);
2352 invalidateClass(this.ownerElement_);
2353 },
2354 remove: function() {
2355 unsafeUnwrap(this).remove.apply(unsafeUnwrap(this), arguments);
2356 invalidateClass(this.ownerElement_);
2357 },
2358 toggle: function(token) {
2359 var rv = unsafeUnwrap(this).toggle.apply(unsafeUnwrap(this), arguments);
2360 invalidateClass(this.ownerElement_);
2361 return rv;
2362 },
2363 toString: function() {
2364 return unsafeUnwrap(this).toString();
2365 }
2366 }; 2433 };
2367 scope.wrappers.DOMTokenList = DOMTokenList; 2434 var oldRemove = DOMTokenList.prototype.remove;
2435 DOMTokenList.prototype.remove = function() {
2436 changeClass(this, oldRemove, arguments);
2437 };
2438 var oldToggle = DOMTokenList.prototype.toggle;
2439 DOMTokenList.prototype.toggle = function() {
2440 return changeClass(this, oldToggle, arguments);
2441 };
2368 })(window.ShadowDOMPolyfill); 2442 })(window.ShadowDOMPolyfill);
2369 (function(scope) { 2443 (function(scope) {
2370 "use strict"; 2444 "use strict";
2371 var ChildNodeInterface = scope.ChildNodeInterface; 2445 var ChildNodeInterface = scope.ChildNodeInterface;
2372 var GetElementsByInterface = scope.GetElementsByInterface; 2446 var GetElementsByInterface = scope.GetElementsByInterface;
2373 var Node = scope.wrappers.Node; 2447 var Node = scope.wrappers.Node;
2374 var DOMTokenList = scope.wrappers.DOMTokenList;
2375 var ParentNodeInterface = scope.ParentNodeInterface; 2448 var ParentNodeInterface = scope.ParentNodeInterface;
2376 var SelectorsInterface = scope.SelectorsInterface; 2449 var SelectorsInterface = scope.SelectorsInterface;
2450 var MatchesInterface = scope.MatchesInterface;
2377 var addWrapNodeListMethod = scope.addWrapNodeListMethod; 2451 var addWrapNodeListMethod = scope.addWrapNodeListMethod;
2378 var enqueueMutation = scope.enqueueMutation; 2452 var enqueueMutation = scope.enqueueMutation;
2379 var mixin = scope.mixin; 2453 var mixin = scope.mixin;
2380 var oneOf = scope.oneOf; 2454 var oneOf = scope.oneOf;
2381 var registerWrapper = scope.registerWrapper; 2455 var registerWrapper = scope.registerWrapper;
2382 var unsafeUnwrap = scope.unsafeUnwrap; 2456 var unsafeUnwrap = scope.unsafeUnwrap;
2383 var wrappers = scope.wrappers; 2457 var wrappers = scope.wrappers;
2384 var OriginalElement = window.Element; 2458 var OriginalElement = window.Element;
2385 var matchesNames = [ "matches", "mozMatchesSelector", "msMatchesSelector", " webkitMatchesSelector" ].filter(function(name) { 2459 var matchesNames = [ "matches", "mozMatchesSelector", "msMatchesSelector", " webkitMatchesSelector" ].filter(function(name) {
2386 return OriginalElement.prototype[name]; 2460 return OriginalElement.prototype[name];
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2421 unsafeUnwrap(this).setAttribute(name, value); 2495 unsafeUnwrap(this).setAttribute(name, value);
2422 enqueAttributeChange(this, name, oldValue); 2496 enqueAttributeChange(this, name, oldValue);
2423 invalidateRendererBasedOnAttribute(this, name); 2497 invalidateRendererBasedOnAttribute(this, name);
2424 }, 2498 },
2425 removeAttribute: function(name) { 2499 removeAttribute: function(name) {
2426 var oldValue = unsafeUnwrap(this).getAttribute(name); 2500 var oldValue = unsafeUnwrap(this).getAttribute(name);
2427 unsafeUnwrap(this).removeAttribute(name); 2501 unsafeUnwrap(this).removeAttribute(name);
2428 enqueAttributeChange(this, name, oldValue); 2502 enqueAttributeChange(this, name, oldValue);
2429 invalidateRendererBasedOnAttribute(this, name); 2503 invalidateRendererBasedOnAttribute(this, name);
2430 }, 2504 },
2431 matches: function(selector) {
2432 return originalMatches.call(unsafeUnwrap(this), selector);
2433 },
2434 get classList() { 2505 get classList() {
2435 var list = classListTable.get(this); 2506 var list = classListTable.get(this);
2436 if (!list) { 2507 if (!list) {
2437 classListTable.set(this, list = new DOMTokenList(unsafeUnwrap(this).cl assList, this)); 2508 list = unsafeUnwrap(this).classList;
2509 if (!list) return;
2510 list.ownerElement_ = this;
2511 classListTable.set(this, list);
2438 } 2512 }
2439 return list; 2513 return list;
2440 }, 2514 },
2441 get className() { 2515 get className() {
2442 return unsafeUnwrap(this).className; 2516 return unsafeUnwrap(this).className;
2443 }, 2517 },
2444 set className(v) { 2518 set className(v) {
2445 this.setAttribute("class", v); 2519 this.setAttribute("class", v);
2446 }, 2520 },
2447 get id() { 2521 get id() {
(...skipping 10 matching lines...) Expand all
2458 }; 2532 };
2459 } 2533 }
2460 }); 2534 });
2461 if (OriginalElement.prototype.webkitCreateShadowRoot) { 2535 if (OriginalElement.prototype.webkitCreateShadowRoot) {
2462 Element.prototype.webkitCreateShadowRoot = Element.prototype.createShadowR oot; 2536 Element.prototype.webkitCreateShadowRoot = Element.prototype.createShadowR oot;
2463 } 2537 }
2464 mixin(Element.prototype, ChildNodeInterface); 2538 mixin(Element.prototype, ChildNodeInterface);
2465 mixin(Element.prototype, GetElementsByInterface); 2539 mixin(Element.prototype, GetElementsByInterface);
2466 mixin(Element.prototype, ParentNodeInterface); 2540 mixin(Element.prototype, ParentNodeInterface);
2467 mixin(Element.prototype, SelectorsInterface); 2541 mixin(Element.prototype, SelectorsInterface);
2542 mixin(Element.prototype, MatchesInterface);
2468 registerWrapper(OriginalElement, Element, document.createElementNS(null, "x" )); 2543 registerWrapper(OriginalElement, Element, document.createElementNS(null, "x" ));
2469 scope.invalidateRendererBasedOnAttribute = invalidateRendererBasedOnAttribut e; 2544 scope.invalidateRendererBasedOnAttribute = invalidateRendererBasedOnAttribut e;
2470 scope.matchesNames = matchesNames; 2545 scope.matchesNames = matchesNames;
2546 scope.originalMatches = originalMatches;
2471 scope.wrappers.Element = Element; 2547 scope.wrappers.Element = Element;
2472 })(window.ShadowDOMPolyfill); 2548 })(window.ShadowDOMPolyfill);
2473 (function(scope) { 2549 (function(scope) {
2474 "use strict"; 2550 "use strict";
2475 var Element = scope.wrappers.Element; 2551 var Element = scope.wrappers.Element;
2476 var defineGetter = scope.defineGetter; 2552 var defineGetter = scope.defineGetter;
2477 var enqueueMutation = scope.enqueueMutation; 2553 var enqueueMutation = scope.enqueueMutation;
2478 var mixin = scope.mixin; 2554 var mixin = scope.mixin;
2479 var nodesWereAdded = scope.nodesWereAdded; 2555 var nodesWereAdded = scope.nodesWereAdded;
2480 var nodesWereRemoved = scope.nodesWereRemoved; 2556 var nodesWereRemoved = scope.nodesWereRemoved;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2512 } 2588 }
2513 function makeSet(arr) { 2589 function makeSet(arr) {
2514 var set = {}; 2590 var set = {};
2515 for (var i = 0; i < arr.length; i++) { 2591 for (var i = 0; i < arr.length; i++) {
2516 set[arr[i]] = true; 2592 set[arr[i]] = true;
2517 } 2593 }
2518 return set; 2594 return set;
2519 } 2595 }
2520 var voidElements = makeSet([ "area", "base", "br", "col", "command", "embed" , "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "w br" ]); 2596 var voidElements = makeSet([ "area", "base", "br", "col", "command", "embed" , "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "w br" ]);
2521 var plaintextParents = makeSet([ "style", "script", "xmp", "iframe", "noembe d", "noframes", "plaintext", "noscript" ]); 2597 var plaintextParents = makeSet([ "style", "script", "xmp", "iframe", "noembe d", "noframes", "plaintext", "noscript" ]);
2598 var XHTML_NS = "http://www.w3.org/1999/xhtml";
2599 function needsSelfClosingSlash(node) {
2600 if (node.namespaceURI !== XHTML_NS) return true;
2601 var doctype = node.ownerDocument.doctype;
2602 return doctype && doctype.publicId && doctype.systemId;
2603 }
2522 function getOuterHTML(node, parentNode) { 2604 function getOuterHTML(node, parentNode) {
2523 switch (node.nodeType) { 2605 switch (node.nodeType) {
2524 case Node.ELEMENT_NODE: 2606 case Node.ELEMENT_NODE:
2525 var tagName = node.tagName.toLowerCase(); 2607 var tagName = node.tagName.toLowerCase();
2526 var s = "<" + tagName; 2608 var s = "<" + tagName;
2527 var attrs = node.attributes; 2609 var attrs = node.attributes;
2528 for (var i = 0, attr; attr = attrs[i]; i++) { 2610 for (var i = 0, attr; attr = attrs[i]; i++) {
2529 s += " " + attr.name + '="' + escapeAttr(attr.value) + '"'; 2611 s += " " + attr.name + '="' + escapeAttr(attr.value) + '"';
2530 } 2612 }
2531 s += ">"; 2613 if (voidElements[tagName]) {
2532 if (voidElements[tagName]) return s; 2614 if (needsSelfClosingSlash(node)) s += "/";
2533 return s + getInnerHTML(node) + "</" + tagName + ">"; 2615 return s + ">";
2616 }
2617 return s + ">" + getInnerHTML(node) + "</" + tagName + ">";
2534 2618
2535 case Node.TEXT_NODE: 2619 case Node.TEXT_NODE:
2536 var data = node.data; 2620 var data = node.data;
2537 if (parentNode && plaintextParents[parentNode.localName]) return data; 2621 if (parentNode && plaintextParents[parentNode.localName]) return data;
2538 return escapeData(data); 2622 return escapeData(data);
2539 2623
2540 case Node.COMMENT_NODE: 2624 case Node.COMMENT_NODE:
2541 return "<!--" + node.data + "-->"; 2625 return "<!--" + node.data + "-->";
2542 2626
2543 default: 2627 default:
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
2681 function methodRequiresRendering(name) { 2765 function methodRequiresRendering(name) {
2682 Object.defineProperty(HTMLElement.prototype, name, { 2766 Object.defineProperty(HTMLElement.prototype, name, {
2683 value: function() { 2767 value: function() {
2684 scope.renderAllPending(); 2768 scope.renderAllPending();
2685 return unsafeUnwrap(this)[name].apply(unsafeUnwrap(this), arguments); 2769 return unsafeUnwrap(this)[name].apply(unsafeUnwrap(this), arguments);
2686 }, 2770 },
2687 configurable: true, 2771 configurable: true,
2688 enumerable: true 2772 enumerable: true
2689 }); 2773 });
2690 } 2774 }
2691 [ "getBoundingClientRect", "getClientRects", "scrollIntoView" ].forEach(meth odRequiresRendering); 2775 [ "focus", "getBoundingClientRect", "getClientRects", "scrollIntoView" ].for Each(methodRequiresRendering);
2692 registerWrapper(OriginalHTMLElement, HTMLElement, document.createElement("b" )); 2776 registerWrapper(OriginalHTMLElement, HTMLElement, document.createElement("b" ));
2693 scope.wrappers.HTMLElement = HTMLElement; 2777 scope.wrappers.HTMLElement = HTMLElement;
2694 scope.getInnerHTML = getInnerHTML; 2778 scope.getInnerHTML = getInnerHTML;
2695 scope.setInnerHTML = setInnerHTML; 2779 scope.setInnerHTML = setInnerHTML;
2696 })(window.ShadowDOMPolyfill); 2780 })(window.ShadowDOMPolyfill);
2697 (function(scope) { 2781 (function(scope) {
2698 "use strict"; 2782 "use strict";
2699 var HTMLElement = scope.wrappers.HTMLElement; 2783 var HTMLElement = scope.wrappers.HTMLElement;
2700 var mixin = scope.mixin; 2784 var mixin = scope.mixin;
2701 var registerWrapper = scope.registerWrapper; 2785 var registerWrapper = scope.registerWrapper;
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
3088 HTMLElement.call(this, node); 3172 HTMLElement.call(this, node);
3089 } 3173 }
3090 HTMLUnknownElement.prototype = Object.create(HTMLElement.prototype); 3174 HTMLUnknownElement.prototype = Object.create(HTMLElement.prototype);
3091 registerWrapper(OriginalHTMLUnknownElement, HTMLUnknownElement); 3175 registerWrapper(OriginalHTMLUnknownElement, HTMLUnknownElement);
3092 scope.wrappers.HTMLUnknownElement = HTMLUnknownElement; 3176 scope.wrappers.HTMLUnknownElement = HTMLUnknownElement;
3093 })(window.ShadowDOMPolyfill); 3177 })(window.ShadowDOMPolyfill);
3094 (function(scope) { 3178 (function(scope) {
3095 "use strict"; 3179 "use strict";
3096 var Element = scope.wrappers.Element; 3180 var Element = scope.wrappers.Element;
3097 var HTMLElement = scope.wrappers.HTMLElement; 3181 var HTMLElement = scope.wrappers.HTMLElement;
3098 var registerObject = scope.registerObject; 3182 var registerWrapper = scope.registerWrapper;
3183 var defineWrapGetter = scope.defineWrapGetter;
3184 var unsafeUnwrap = scope.unsafeUnwrap;
3185 var wrap = scope.wrap;
3186 var mixin = scope.mixin;
3099 var SVG_NS = "http://www.w3.org/2000/svg"; 3187 var SVG_NS = "http://www.w3.org/2000/svg";
3188 var OriginalSVGElement = window.SVGElement;
3100 var svgTitleElement = document.createElementNS(SVG_NS, "title"); 3189 var svgTitleElement = document.createElementNS(SVG_NS, "title");
3101 var SVGTitleElement = registerObject(svgTitleElement);
3102 var SVGElement = Object.getPrototypeOf(SVGTitleElement.prototype).constructo r;
3103 if (!("classList" in svgTitleElement)) { 3190 if (!("classList" in svgTitleElement)) {
3104 var descr = Object.getOwnPropertyDescriptor(Element.prototype, "classList" ); 3191 var descr = Object.getOwnPropertyDescriptor(Element.prototype, "classList" );
3105 Object.defineProperty(HTMLElement.prototype, "classList", descr); 3192 Object.defineProperty(HTMLElement.prototype, "classList", descr);
3106 delete Element.prototype.classList; 3193 delete Element.prototype.classList;
3107 } 3194 }
3195 function SVGElement(node) {
3196 Element.call(this, node);
3197 }
3198 SVGElement.prototype = Object.create(Element.prototype);
3199 mixin(SVGElement.prototype, {
3200 get ownerSVGElement() {
3201 return wrap(unsafeUnwrap(this).ownerSVGElement);
3202 }
3203 });
3204 registerWrapper(OriginalSVGElement, SVGElement, document.createElementNS(SVG _NS, "title"));
3108 scope.wrappers.SVGElement = SVGElement; 3205 scope.wrappers.SVGElement = SVGElement;
3109 })(window.ShadowDOMPolyfill); 3206 })(window.ShadowDOMPolyfill);
3110 (function(scope) { 3207 (function(scope) {
3111 "use strict"; 3208 "use strict";
3112 var mixin = scope.mixin; 3209 var mixin = scope.mixin;
3113 var registerWrapper = scope.registerWrapper; 3210 var registerWrapper = scope.registerWrapper;
3114 var unwrap = scope.unwrap; 3211 var unwrap = scope.unwrap;
3115 var wrap = scope.wrap; 3212 var wrap = scope.wrap;
3116 var OriginalSVGUseElement = window.SVGUseElement; 3213 var OriginalSVGUseElement = window.SVGUseElement;
3117 var SVG_NS = "http://www.w3.org/2000/svg"; 3214 var SVG_NS = "http://www.w3.org/2000/svg";
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
3203 createPattern: function() { 3300 createPattern: function() {
3204 arguments[0] = unwrap(arguments[0]); 3301 arguments[0] = unwrap(arguments[0]);
3205 return unsafeUnwrap(this).createPattern.apply(unsafeUnwrap(this), argume nts); 3302 return unsafeUnwrap(this).createPattern.apply(unsafeUnwrap(this), argume nts);
3206 } 3303 }
3207 }); 3304 });
3208 registerWrapper(OriginalCanvasRenderingContext2D, CanvasRenderingContext2D, document.createElement("canvas").getContext("2d")); 3305 registerWrapper(OriginalCanvasRenderingContext2D, CanvasRenderingContext2D, document.createElement("canvas").getContext("2d"));
3209 scope.wrappers.CanvasRenderingContext2D = CanvasRenderingContext2D; 3306 scope.wrappers.CanvasRenderingContext2D = CanvasRenderingContext2D;
3210 })(window.ShadowDOMPolyfill); 3307 })(window.ShadowDOMPolyfill);
3211 (function(scope) { 3308 (function(scope) {
3212 "use strict"; 3309 "use strict";
3310 var addForwardingProperties = scope.addForwardingProperties;
3213 var mixin = scope.mixin; 3311 var mixin = scope.mixin;
3214 var registerWrapper = scope.registerWrapper; 3312 var registerWrapper = scope.registerWrapper;
3215 var setWrapper = scope.setWrapper; 3313 var setWrapper = scope.setWrapper;
3216 var unsafeUnwrap = scope.unsafeUnwrap; 3314 var unsafeUnwrap = scope.unsafeUnwrap;
3217 var unwrapIfNeeded = scope.unwrapIfNeeded; 3315 var unwrapIfNeeded = scope.unwrapIfNeeded;
3218 var wrap = scope.wrap; 3316 var wrap = scope.wrap;
3219 var OriginalWebGLRenderingContext = window.WebGLRenderingContext; 3317 var OriginalWebGLRenderingContext = window.WebGLRenderingContext;
3220 if (!OriginalWebGLRenderingContext) return; 3318 if (!OriginalWebGLRenderingContext) return;
3221 function WebGLRenderingContext(impl) { 3319 function WebGLRenderingContext(impl) {
3222 setWrapper(impl, this); 3320 setWrapper(impl, this);
3223 } 3321 }
3224 mixin(WebGLRenderingContext.prototype, { 3322 mixin(WebGLRenderingContext.prototype, {
3225 get canvas() { 3323 get canvas() {
3226 return wrap(unsafeUnwrap(this).canvas); 3324 return wrap(unsafeUnwrap(this).canvas);
3227 }, 3325 },
3228 texImage2D: function() { 3326 texImage2D: function() {
3229 arguments[5] = unwrapIfNeeded(arguments[5]); 3327 arguments[5] = unwrapIfNeeded(arguments[5]);
3230 unsafeUnwrap(this).texImage2D.apply(unsafeUnwrap(this), arguments); 3328 unsafeUnwrap(this).texImage2D.apply(unsafeUnwrap(this), arguments);
3231 }, 3329 },
3232 texSubImage2D: function() { 3330 texSubImage2D: function() {
3233 arguments[6] = unwrapIfNeeded(arguments[6]); 3331 arguments[6] = unwrapIfNeeded(arguments[6]);
3234 unsafeUnwrap(this).texSubImage2D.apply(unsafeUnwrap(this), arguments); 3332 unsafeUnwrap(this).texSubImage2D.apply(unsafeUnwrap(this), arguments);
3235 } 3333 }
3236 }); 3334 });
3335 var OriginalWebGLRenderingContextBase = Object.getPrototypeOf(OriginalWebGLR enderingContext.prototype);
3336 if (OriginalWebGLRenderingContextBase !== Object.prototype) {
3337 addForwardingProperties(OriginalWebGLRenderingContextBase, WebGLRenderingC ontext.prototype);
3338 }
3237 var instanceProperties = /WebKit/.test(navigator.userAgent) ? { 3339 var instanceProperties = /WebKit/.test(navigator.userAgent) ? {
3238 drawingBufferHeight: null, 3340 drawingBufferHeight: null,
3239 drawingBufferWidth: null 3341 drawingBufferWidth: null
3240 } : {}; 3342 } : {};
3241 registerWrapper(OriginalWebGLRenderingContext, WebGLRenderingContext, instan ceProperties); 3343 registerWrapper(OriginalWebGLRenderingContext, WebGLRenderingContext, instan ceProperties);
3242 scope.wrappers.WebGLRenderingContext = WebGLRenderingContext; 3344 scope.wrappers.WebGLRenderingContext = WebGLRenderingContext;
3243 })(window.ShadowDOMPolyfill); 3345 })(window.ShadowDOMPolyfill);
3244 (function(scope) { 3346 (function(scope) {
3245 "use strict"; 3347 "use strict";
3348 var Node = scope.wrappers.Node;
3349 var GetElementsByInterface = scope.GetElementsByInterface;
3350 var NonElementParentNodeInterface = scope.NonElementParentNodeInterface;
3351 var ParentNodeInterface = scope.ParentNodeInterface;
3352 var SelectorsInterface = scope.SelectorsInterface;
3353 var mixin = scope.mixin;
3354 var registerObject = scope.registerObject;
3355 var registerWrapper = scope.registerWrapper;
3356 var OriginalDocumentFragment = window.DocumentFragment;
3357 function DocumentFragment(node) {
3358 Node.call(this, node);
3359 }
3360 DocumentFragment.prototype = Object.create(Node.prototype);
3361 mixin(DocumentFragment.prototype, ParentNodeInterface);
3362 mixin(DocumentFragment.prototype, SelectorsInterface);
3363 mixin(DocumentFragment.prototype, GetElementsByInterface);
3364 mixin(DocumentFragment.prototype, NonElementParentNodeInterface);
3365 registerWrapper(OriginalDocumentFragment, DocumentFragment, document.createD ocumentFragment());
3366 scope.wrappers.DocumentFragment = DocumentFragment;
3367 var Comment = registerObject(document.createComment(""));
3368 scope.wrappers.Comment = Comment;
3369 })(window.ShadowDOMPolyfill);
3370 (function(scope) {
3371 "use strict";
3372 var DocumentFragment = scope.wrappers.DocumentFragment;
3373 var TreeScope = scope.TreeScope;
3374 var elementFromPoint = scope.elementFromPoint;
3375 var getInnerHTML = scope.getInnerHTML;
3376 var getTreeScope = scope.getTreeScope;
3377 var mixin = scope.mixin;
3378 var rewrap = scope.rewrap;
3379 var setInnerHTML = scope.setInnerHTML;
3380 var unsafeUnwrap = scope.unsafeUnwrap;
3381 var unwrap = scope.unwrap;
3382 var wrap = scope.wrap;
3383 var shadowHostTable = new WeakMap();
3384 var nextOlderShadowTreeTable = new WeakMap();
3385 function ShadowRoot(hostWrapper) {
3386 var node = unwrap(unsafeUnwrap(hostWrapper).ownerDocument.createDocumentFr agment());
3387 DocumentFragment.call(this, node);
3388 rewrap(node, this);
3389 var oldShadowRoot = hostWrapper.shadowRoot;
3390 nextOlderShadowTreeTable.set(this, oldShadowRoot);
3391 this.treeScope_ = new TreeScope(this, getTreeScope(oldShadowRoot || hostWr apper));
3392 shadowHostTable.set(this, hostWrapper);
3393 }
3394 ShadowRoot.prototype = Object.create(DocumentFragment.prototype);
3395 mixin(ShadowRoot.prototype, {
3396 constructor: ShadowRoot,
3397 get innerHTML() {
3398 return getInnerHTML(this);
3399 },
3400 set innerHTML(value) {
3401 setInnerHTML(this, value);
3402 this.invalidateShadowRenderer();
3403 },
3404 get olderShadowRoot() {
3405 return nextOlderShadowTreeTable.get(this) || null;
3406 },
3407 get host() {
3408 return shadowHostTable.get(this) || null;
3409 },
3410 invalidateShadowRenderer: function() {
3411 return shadowHostTable.get(this).invalidateShadowRenderer();
3412 },
3413 elementFromPoint: function(x, y) {
3414 return elementFromPoint(this, this.ownerDocument, x, y);
3415 },
3416 getSelection: function() {
3417 return document.getSelection();
3418 },
3419 get activeElement() {
3420 var unwrappedActiveElement = unwrap(this).ownerDocument.activeElement;
3421 if (!unwrappedActiveElement || !unwrappedActiveElement.nodeType) return null;
3422 var activeElement = wrap(unwrappedActiveElement);
3423 while (!this.contains(activeElement)) {
3424 while (activeElement.parentNode) {
3425 activeElement = activeElement.parentNode;
3426 }
3427 if (activeElement.host) {
3428 activeElement = activeElement.host;
3429 } else {
3430 return null;
3431 }
3432 }
3433 return activeElement;
3434 }
3435 });
3436 scope.wrappers.ShadowRoot = ShadowRoot;
3437 })(window.ShadowDOMPolyfill);
3438 (function(scope) {
3439 "use strict";
3246 var registerWrapper = scope.registerWrapper; 3440 var registerWrapper = scope.registerWrapper;
3247 var setWrapper = scope.setWrapper; 3441 var setWrapper = scope.setWrapper;
3248 var unsafeUnwrap = scope.unsafeUnwrap; 3442 var unsafeUnwrap = scope.unsafeUnwrap;
3249 var unwrap = scope.unwrap; 3443 var unwrap = scope.unwrap;
3250 var unwrapIfNeeded = scope.unwrapIfNeeded; 3444 var unwrapIfNeeded = scope.unwrapIfNeeded;
3251 var wrap = scope.wrap; 3445 var wrap = scope.wrap;
3446 var getTreeScope = scope.getTreeScope;
3252 var OriginalRange = window.Range; 3447 var OriginalRange = window.Range;
3448 var ShadowRoot = scope.wrappers.ShadowRoot;
3449 function getHost(node) {
3450 var root = getTreeScope(node).root;
3451 if (root instanceof ShadowRoot) {
3452 return root.host;
3453 }
3454 return null;
3455 }
3456 function hostNodeToShadowNode(refNode, offset) {
3457 if (refNode.shadowRoot) {
3458 offset = Math.min(refNode.childNodes.length - 1, offset);
3459 var child = refNode.childNodes[offset];
3460 if (child) {
3461 var insertionPoint = scope.getDestinationInsertionPoints(child);
3462 if (insertionPoint.length > 0) {
3463 var parentNode = insertionPoint[0].parentNode;
3464 if (parentNode.nodeType == Node.ELEMENT_NODE) {
3465 refNode = parentNode;
3466 }
3467 }
3468 }
3469 }
3470 return refNode;
3471 }
3472 function shadowNodeToHostNode(node) {
3473 node = wrap(node);
3474 return getHost(node) || node;
3475 }
3253 function Range(impl) { 3476 function Range(impl) {
3254 setWrapper(impl, this); 3477 setWrapper(impl, this);
3255 } 3478 }
3256 Range.prototype = { 3479 Range.prototype = {
3257 get startContainer() { 3480 get startContainer() {
3258 return wrap(unsafeUnwrap(this).startContainer); 3481 return shadowNodeToHostNode(unsafeUnwrap(this).startContainer);
3259 }, 3482 },
3260 get endContainer() { 3483 get endContainer() {
3261 return wrap(unsafeUnwrap(this).endContainer); 3484 return shadowNodeToHostNode(unsafeUnwrap(this).endContainer);
3262 }, 3485 },
3263 get commonAncestorContainer() { 3486 get commonAncestorContainer() {
3264 return wrap(unsafeUnwrap(this).commonAncestorContainer); 3487 return shadowNodeToHostNode(unsafeUnwrap(this).commonAncestorContainer);
3265 }, 3488 },
3266 setStart: function(refNode, offset) { 3489 setStart: function(refNode, offset) {
3490 refNode = hostNodeToShadowNode(refNode, offset);
3267 unsafeUnwrap(this).setStart(unwrapIfNeeded(refNode), offset); 3491 unsafeUnwrap(this).setStart(unwrapIfNeeded(refNode), offset);
3268 }, 3492 },
3269 setEnd: function(refNode, offset) { 3493 setEnd: function(refNode, offset) {
3494 refNode = hostNodeToShadowNode(refNode, offset);
3270 unsafeUnwrap(this).setEnd(unwrapIfNeeded(refNode), offset); 3495 unsafeUnwrap(this).setEnd(unwrapIfNeeded(refNode), offset);
3271 }, 3496 },
3272 setStartBefore: function(refNode) { 3497 setStartBefore: function(refNode) {
3273 unsafeUnwrap(this).setStartBefore(unwrapIfNeeded(refNode)); 3498 unsafeUnwrap(this).setStartBefore(unwrapIfNeeded(refNode));
3274 }, 3499 },
3275 setStartAfter: function(refNode) { 3500 setStartAfter: function(refNode) {
3276 unsafeUnwrap(this).setStartAfter(unwrapIfNeeded(refNode)); 3501 unsafeUnwrap(this).setStartAfter(unwrapIfNeeded(refNode));
3277 }, 3502 },
3278 setEndBefore: function(refNode) { 3503 setEndBefore: function(refNode) {
3279 unsafeUnwrap(this).setEndBefore(unwrapIfNeeded(refNode)); 3504 unsafeUnwrap(this).setEndBefore(unwrapIfNeeded(refNode));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
3321 if (OriginalRange.prototype.createContextualFragment) { 3546 if (OriginalRange.prototype.createContextualFragment) {
3322 Range.prototype.createContextualFragment = function(html) { 3547 Range.prototype.createContextualFragment = function(html) {
3323 return wrap(unsafeUnwrap(this).createContextualFragment(html)); 3548 return wrap(unsafeUnwrap(this).createContextualFragment(html));
3324 }; 3549 };
3325 } 3550 }
3326 registerWrapper(window.Range, Range, document.createRange()); 3551 registerWrapper(window.Range, Range, document.createRange());
3327 scope.wrappers.Range = Range; 3552 scope.wrappers.Range = Range;
3328 })(window.ShadowDOMPolyfill); 3553 })(window.ShadowDOMPolyfill);
3329 (function(scope) { 3554 (function(scope) {
3330 "use strict"; 3555 "use strict";
3331 var GetElementsByInterface = scope.GetElementsByInterface;
3332 var ParentNodeInterface = scope.ParentNodeInterface;
3333 var SelectorsInterface = scope.SelectorsInterface;
3334 var mixin = scope.mixin;
3335 var registerObject = scope.registerObject;
3336 var DocumentFragment = registerObject(document.createDocumentFragment());
3337 mixin(DocumentFragment.prototype, ParentNodeInterface);
3338 mixin(DocumentFragment.prototype, SelectorsInterface);
3339 mixin(DocumentFragment.prototype, GetElementsByInterface);
3340 var Comment = registerObject(document.createComment(""));
3341 scope.wrappers.Comment = Comment;
3342 scope.wrappers.DocumentFragment = DocumentFragment;
3343 })(window.ShadowDOMPolyfill);
3344 (function(scope) {
3345 "use strict";
3346 var DocumentFragment = scope.wrappers.DocumentFragment;
3347 var TreeScope = scope.TreeScope;
3348 var elementFromPoint = scope.elementFromPoint;
3349 var getInnerHTML = scope.getInnerHTML;
3350 var getTreeScope = scope.getTreeScope;
3351 var mixin = scope.mixin;
3352 var rewrap = scope.rewrap;
3353 var setInnerHTML = scope.setInnerHTML;
3354 var unsafeUnwrap = scope.unsafeUnwrap;
3355 var unwrap = scope.unwrap;
3356 var shadowHostTable = new WeakMap();
3357 var nextOlderShadowTreeTable = new WeakMap();
3358 var spaceCharRe = /[ \t\n\r\f]/;
3359 function ShadowRoot(hostWrapper) {
3360 var node = unwrap(unsafeUnwrap(hostWrapper).ownerDocument.createDocumentFr agment());
3361 DocumentFragment.call(this, node);
3362 rewrap(node, this);
3363 var oldShadowRoot = hostWrapper.shadowRoot;
3364 nextOlderShadowTreeTable.set(this, oldShadowRoot);
3365 this.treeScope_ = new TreeScope(this, getTreeScope(oldShadowRoot || hostWr apper));
3366 shadowHostTable.set(this, hostWrapper);
3367 }
3368 ShadowRoot.prototype = Object.create(DocumentFragment.prototype);
3369 mixin(ShadowRoot.prototype, {
3370 constructor: ShadowRoot,
3371 get innerHTML() {
3372 return getInnerHTML(this);
3373 },
3374 set innerHTML(value) {
3375 setInnerHTML(this, value);
3376 this.invalidateShadowRenderer();
3377 },
3378 get olderShadowRoot() {
3379 return nextOlderShadowTreeTable.get(this) || null;
3380 },
3381 get host() {
3382 return shadowHostTable.get(this) || null;
3383 },
3384 invalidateShadowRenderer: function() {
3385 return shadowHostTable.get(this).invalidateShadowRenderer();
3386 },
3387 elementFromPoint: function(x, y) {
3388 return elementFromPoint(this, this.ownerDocument, x, y);
3389 },
3390 getElementById: function(id) {
3391 if (spaceCharRe.test(id)) return null;
3392 return this.querySelector('[id="' + id + '"]');
3393 }
3394 });
3395 scope.wrappers.ShadowRoot = ShadowRoot;
3396 })(window.ShadowDOMPolyfill);
3397 (function(scope) {
3398 "use strict";
3399 var Element = scope.wrappers.Element; 3556 var Element = scope.wrappers.Element;
3400 var HTMLContentElement = scope.wrappers.HTMLContentElement; 3557 var HTMLContentElement = scope.wrappers.HTMLContentElement;
3401 var HTMLShadowElement = scope.wrappers.HTMLShadowElement; 3558 var HTMLShadowElement = scope.wrappers.HTMLShadowElement;
3402 var Node = scope.wrappers.Node; 3559 var Node = scope.wrappers.Node;
3403 var ShadowRoot = scope.wrappers.ShadowRoot; 3560 var ShadowRoot = scope.wrappers.ShadowRoot;
3404 var assert = scope.assert; 3561 var assert = scope.assert;
3405 var getTreeScope = scope.getTreeScope; 3562 var getTreeScope = scope.getTreeScope;
3406 var mixin = scope.mixin; 3563 var mixin = scope.mixin;
3407 var oneOf = scope.oneOf; 3564 var oneOf = scope.oneOf;
3408 var unsafeUnwrap = scope.unsafeUnwrap; 3565 var unsafeUnwrap = scope.unsafeUnwrap;
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
3839 setWrapper(impl, this); 3996 setWrapper(impl, this);
3840 } 3997 }
3841 Selection.prototype = { 3998 Selection.prototype = {
3842 get anchorNode() { 3999 get anchorNode() {
3843 return wrap(unsafeUnwrap(this).anchorNode); 4000 return wrap(unsafeUnwrap(this).anchorNode);
3844 }, 4001 },
3845 get focusNode() { 4002 get focusNode() {
3846 return wrap(unsafeUnwrap(this).focusNode); 4003 return wrap(unsafeUnwrap(this).focusNode);
3847 }, 4004 },
3848 addRange: function(range) { 4005 addRange: function(range) {
3849 unsafeUnwrap(this).addRange(unwrap(range)); 4006 unsafeUnwrap(this).addRange(unwrapIfNeeded(range));
3850 }, 4007 },
3851 collapse: function(node, index) { 4008 collapse: function(node, index) {
3852 unsafeUnwrap(this).collapse(unwrapIfNeeded(node), index); 4009 unsafeUnwrap(this).collapse(unwrapIfNeeded(node), index);
3853 }, 4010 },
3854 containsNode: function(node, allowPartial) { 4011 containsNode: function(node, allowPartial) {
3855 return unsafeUnwrap(this).containsNode(unwrapIfNeeded(node), allowPartia l); 4012 return unsafeUnwrap(this).containsNode(unwrapIfNeeded(node), allowPartia l);
3856 }, 4013 },
3857 extend: function(node, offset) {
3858 unsafeUnwrap(this).extend(unwrapIfNeeded(node), offset);
3859 },
3860 getRangeAt: function(index) { 4014 getRangeAt: function(index) {
3861 return wrap(unsafeUnwrap(this).getRangeAt(index)); 4015 return wrap(unsafeUnwrap(this).getRangeAt(index));
3862 }, 4016 },
3863 removeRange: function(range) { 4017 removeRange: function(range) {
3864 unsafeUnwrap(this).removeRange(unwrap(range)); 4018 unsafeUnwrap(this).removeRange(unwrap(range));
3865 }, 4019 },
3866 selectAllChildren: function(node) { 4020 selectAllChildren: function(node) {
3867 unsafeUnwrap(this).selectAllChildren(unwrapIfNeeded(node)); 4021 unsafeUnwrap(this).selectAllChildren(node instanceof ShadowRoot ? unsafe Unwrap(node.host) : unwrapIfNeeded(node));
3868 }, 4022 },
3869 toString: function() { 4023 toString: function() {
3870 return unsafeUnwrap(this).toString(); 4024 return unsafeUnwrap(this).toString();
3871 } 4025 }
3872 }; 4026 };
4027 if (OriginalSelection.prototype.extend) {
4028 Selection.prototype.extend = function(node, offset) {
4029 unsafeUnwrap(this).extend(unwrapIfNeeded(node), offset);
4030 };
4031 }
3873 registerWrapper(window.Selection, Selection, window.getSelection()); 4032 registerWrapper(window.Selection, Selection, window.getSelection());
3874 scope.wrappers.Selection = Selection; 4033 scope.wrappers.Selection = Selection;
3875 })(window.ShadowDOMPolyfill); 4034 })(window.ShadowDOMPolyfill);
3876 (function(scope) { 4035 (function(scope) {
3877 "use strict"; 4036 "use strict";
4037 var registerWrapper = scope.registerWrapper;
4038 var setWrapper = scope.setWrapper;
4039 var unsafeUnwrap = scope.unsafeUnwrap;
4040 var unwrapIfNeeded = scope.unwrapIfNeeded;
4041 var wrap = scope.wrap;
4042 var OriginalTreeWalker = window.TreeWalker;
4043 function TreeWalker(impl) {
4044 setWrapper(impl, this);
4045 }
4046 TreeWalker.prototype = {
4047 get root() {
4048 return wrap(unsafeUnwrap(this).root);
4049 },
4050 get currentNode() {
4051 return wrap(unsafeUnwrap(this).currentNode);
4052 },
4053 set currentNode(node) {
4054 unsafeUnwrap(this).currentNode = unwrapIfNeeded(node);
4055 },
4056 get filter() {
4057 return unsafeUnwrap(this).filter;
4058 },
4059 parentNode: function() {
4060 return wrap(unsafeUnwrap(this).parentNode());
4061 },
4062 firstChild: function() {
4063 return wrap(unsafeUnwrap(this).firstChild());
4064 },
4065 lastChild: function() {
4066 return wrap(unsafeUnwrap(this).lastChild());
4067 },
4068 previousSibling: function() {
4069 return wrap(unsafeUnwrap(this).previousSibling());
4070 },
4071 previousNode: function() {
4072 return wrap(unsafeUnwrap(this).previousNode());
4073 },
4074 nextNode: function() {
4075 return wrap(unsafeUnwrap(this).nextNode());
4076 }
4077 };
4078 registerWrapper(OriginalTreeWalker, TreeWalker);
4079 scope.wrappers.TreeWalker = TreeWalker;
4080 })(window.ShadowDOMPolyfill);
4081 (function(scope) {
4082 "use strict";
3878 var GetElementsByInterface = scope.GetElementsByInterface; 4083 var GetElementsByInterface = scope.GetElementsByInterface;
3879 var Node = scope.wrappers.Node; 4084 var Node = scope.wrappers.Node;
3880 var ParentNodeInterface = scope.ParentNodeInterface; 4085 var ParentNodeInterface = scope.ParentNodeInterface;
4086 var NonElementParentNodeInterface = scope.NonElementParentNodeInterface;
3881 var Selection = scope.wrappers.Selection; 4087 var Selection = scope.wrappers.Selection;
3882 var SelectorsInterface = scope.SelectorsInterface; 4088 var SelectorsInterface = scope.SelectorsInterface;
3883 var ShadowRoot = scope.wrappers.ShadowRoot; 4089 var ShadowRoot = scope.wrappers.ShadowRoot;
3884 var TreeScope = scope.TreeScope; 4090 var TreeScope = scope.TreeScope;
3885 var cloneNode = scope.cloneNode; 4091 var cloneNode = scope.cloneNode;
4092 var defineGetter = scope.defineGetter;
3886 var defineWrapGetter = scope.defineWrapGetter; 4093 var defineWrapGetter = scope.defineWrapGetter;
3887 var elementFromPoint = scope.elementFromPoint; 4094 var elementFromPoint = scope.elementFromPoint;
3888 var forwardMethodsToWrapper = scope.forwardMethodsToWrapper; 4095 var forwardMethodsToWrapper = scope.forwardMethodsToWrapper;
3889 var matchesNames = scope.matchesNames; 4096 var matchesNames = scope.matchesNames;
3890 var mixin = scope.mixin; 4097 var mixin = scope.mixin;
3891 var registerWrapper = scope.registerWrapper; 4098 var registerWrapper = scope.registerWrapper;
3892 var renderAllPending = scope.renderAllPending; 4099 var renderAllPending = scope.renderAllPending;
3893 var rewrap = scope.rewrap; 4100 var rewrap = scope.rewrap;
3894 var setWrapper = scope.setWrapper; 4101 var setWrapper = scope.setWrapper;
3895 var unsafeUnwrap = scope.unsafeUnwrap; 4102 var unsafeUnwrap = scope.unsafeUnwrap;
3896 var unwrap = scope.unwrap; 4103 var unwrap = scope.unwrap;
3897 var wrap = scope.wrap; 4104 var wrap = scope.wrap;
3898 var wrapEventTargetMethods = scope.wrapEventTargetMethods; 4105 var wrapEventTargetMethods = scope.wrapEventTargetMethods;
3899 var wrapNodeList = scope.wrapNodeList; 4106 var wrapNodeList = scope.wrapNodeList;
3900 var implementationTable = new WeakMap(); 4107 var implementationTable = new WeakMap();
3901 function Document(node) { 4108 function Document(node) {
3902 Node.call(this, node); 4109 Node.call(this, node);
3903 this.treeScope_ = new TreeScope(this, null); 4110 this.treeScope_ = new TreeScope(this, null);
3904 } 4111 }
3905 Document.prototype = Object.create(Node.prototype); 4112 Document.prototype = Object.create(Node.prototype);
3906 defineWrapGetter(Document, "documentElement"); 4113 defineWrapGetter(Document, "documentElement");
3907 defineWrapGetter(Document, "body"); 4114 defineWrapGetter(Document, "body");
3908 defineWrapGetter(Document, "head"); 4115 defineWrapGetter(Document, "head");
4116 defineGetter(Document, "activeElement", function() {
4117 var unwrappedActiveElement = unwrap(this).activeElement;
4118 if (!unwrappedActiveElement || !unwrappedActiveElement.nodeType) return nu ll;
4119 var activeElement = wrap(unwrappedActiveElement);
4120 while (!this.contains(activeElement)) {
4121 while (activeElement.parentNode) {
4122 activeElement = activeElement.parentNode;
4123 }
4124 if (activeElement.host) {
4125 activeElement = activeElement.host;
4126 } else {
4127 return null;
4128 }
4129 }
4130 return activeElement;
4131 });
3909 function wrapMethod(name) { 4132 function wrapMethod(name) {
3910 var original = document[name]; 4133 var original = document[name];
3911 Document.prototype[name] = function() { 4134 Document.prototype[name] = function() {
3912 return wrap(original.apply(unsafeUnwrap(this), arguments)); 4135 return wrap(original.apply(unsafeUnwrap(this), arguments));
3913 }; 4136 };
3914 } 4137 }
3915 [ "createComment", "createDocumentFragment", "createElement", "createElement NS", "createEvent", "createEventNS", "createRange", "createTextNode", "getElemen tById" ].forEach(wrapMethod); 4138 [ "createComment", "createDocumentFragment", "createElement", "createElement NS", "createEvent", "createEventNS", "createRange", "createTextNode" ].forEach(w rapMethod);
3916 var originalAdoptNode = document.adoptNode; 4139 var originalAdoptNode = document.adoptNode;
3917 function adoptNodeNoRemove(node, doc) { 4140 function adoptNodeNoRemove(node, doc) {
3918 originalAdoptNode.call(unsafeUnwrap(doc), unwrap(node)); 4141 originalAdoptNode.call(unsafeUnwrap(doc), unwrap(node));
3919 adoptSubtree(node, doc); 4142 adoptSubtree(node, doc);
3920 } 4143 }
3921 function adoptSubtree(node, doc) { 4144 function adoptSubtree(node, doc) {
3922 if (node.shadowRoot) doc.adoptNode(node.shadowRoot); 4145 if (node.shadowRoot) doc.adoptNode(node.shadowRoot);
3923 if (node instanceof ShadowRoot) adoptOlderShadowRoots(node, doc); 4146 if (node instanceof ShadowRoot) adoptOlderShadowRoots(node, doc);
3924 for (var child = node.firstChild; child; child = child.nextSibling) { 4147 for (var child = node.firstChild; child; child = child.nextSibling) {
3925 adoptSubtree(child, doc); 4148 adoptSubtree(child, doc);
(...skipping 17 matching lines...) Expand all
3943 return cloneNode(node, deep, unsafeUnwrap(this)); 4166 return cloneNode(node, deep, unsafeUnwrap(this));
3944 }, 4167 },
3945 getSelection: function() { 4168 getSelection: function() {
3946 renderAllPending(); 4169 renderAllPending();
3947 return new Selection(originalGetSelection.call(unwrap(this))); 4170 return new Selection(originalGetSelection.call(unwrap(this)));
3948 }, 4171 },
3949 getElementsByName: function(name) { 4172 getElementsByName: function(name) {
3950 return SelectorsInterface.querySelectorAll.call(this, "[name=" + JSON.st ringify(String(name)) + "]"); 4173 return SelectorsInterface.querySelectorAll.call(this, "[name=" + JSON.st ringify(String(name)) + "]");
3951 } 4174 }
3952 }); 4175 });
4176 var originalCreateTreeWalker = document.createTreeWalker;
4177 var TreeWalkerWrapper = scope.wrappers.TreeWalker;
4178 Document.prototype.createTreeWalker = function(root, whatToShow, filter, exp andEntityReferences) {
4179 var newFilter = null;
4180 if (filter) {
4181 if (filter.acceptNode && typeof filter.acceptNode === "function") {
4182 newFilter = {
4183 acceptNode: function(node) {
4184 return filter.acceptNode(wrap(node));
4185 }
4186 };
4187 } else if (typeof filter === "function") {
4188 newFilter = function(node) {
4189 return filter(wrap(node));
4190 };
4191 }
4192 }
4193 return new TreeWalkerWrapper(originalCreateTreeWalker.call(unwrap(this), u nwrap(root), whatToShow, newFilter, expandEntityReferences));
4194 };
3953 if (document.registerElement) { 4195 if (document.registerElement) {
3954 var originalRegisterElement = document.registerElement; 4196 var originalRegisterElement = document.registerElement;
3955 Document.prototype.registerElement = function(tagName, object) { 4197 Document.prototype.registerElement = function(tagName, object) {
3956 var prototype, extendsOption; 4198 var prototype, extendsOption;
3957 if (object !== undefined) { 4199 if (object !== undefined) {
3958 prototype = object.prototype; 4200 prototype = object.prototype;
3959 extendsOption = object.extends; 4201 extendsOption = object.extends;
3960 } 4202 }
3961 if (!prototype) prototype = Object.create(HTMLElement.prototype); 4203 if (!prototype) prototype = Object.create(HTMLElement.prototype);
3962 if (scope.nativePrototypeTable.get(prototype)) { 4204 if (scope.nativePrototypeTable.get(prototype)) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
4004 } 4246 }
4005 CustomElementConstructor.prototype = prototype; 4247 CustomElementConstructor.prototype = prototype;
4006 CustomElementConstructor.prototype.constructor = CustomElementConstructo r; 4248 CustomElementConstructor.prototype.constructor = CustomElementConstructo r;
4007 scope.constructorTable.set(newPrototype, CustomElementConstructor); 4249 scope.constructorTable.set(newPrototype, CustomElementConstructor);
4008 scope.nativePrototypeTable.set(prototype, newPrototype); 4250 scope.nativePrototypeTable.set(prototype, newPrototype);
4009 var nativeConstructor = originalRegisterElement.call(unwrap(this), tagNa me, p); 4251 var nativeConstructor = originalRegisterElement.call(unwrap(this), tagNa me, p);
4010 return CustomElementConstructor; 4252 return CustomElementConstructor;
4011 }; 4253 };
4012 forwardMethodsToWrapper([ window.HTMLDocument || window.Document ], [ "reg isterElement" ]); 4254 forwardMethodsToWrapper([ window.HTMLDocument || window.Document ], [ "reg isterElement" ]);
4013 } 4255 }
4014 forwardMethodsToWrapper([ window.HTMLBodyElement, window.HTMLDocument || win dow.Document, window.HTMLHeadElement, window.HTMLHtmlElement ], [ "appendChild", "compareDocumentPosition", "contains", "getElementsByClassName", "getElementsBy TagName", "getElementsByTagNameNS", "insertBefore", "querySelector", "querySelec torAll", "removeChild", "replaceChild" ].concat(matchesNames)); 4256 forwardMethodsToWrapper([ window.HTMLBodyElement, window.HTMLDocument || win dow.Document, window.HTMLHeadElement, window.HTMLHtmlElement ], [ "appendChild", "compareDocumentPosition", "contains", "getElementsByClassName", "getElementsBy TagName", "getElementsByTagNameNS", "insertBefore", "querySelector", "querySelec torAll", "removeChild", "replaceChild" ]);
4015 forwardMethodsToWrapper([ window.HTMLDocument || window.Document ], [ "adopt Node", "importNode", "contains", "createComment", "createDocumentFragment", "cre ateElement", "createElementNS", "createEvent", "createEventNS", "createRange", " createTextNode", "elementFromPoint", "getElementById", "getElementsByName", "get Selection" ]); 4257 forwardMethodsToWrapper([ window.HTMLBodyElement, window.HTMLHeadElement, wi ndow.HTMLHtmlElement ], matchesNames);
4258 forwardMethodsToWrapper([ window.HTMLDocument || window.Document ], [ "adopt Node", "importNode", "contains", "createComment", "createDocumentFragment", "cre ateElement", "createElementNS", "createEvent", "createEventNS", "createRange", " createTextNode", "createTreeWalker", "elementFromPoint", "getElementById", "getE lementsByName", "getSelection" ]);
4016 mixin(Document.prototype, GetElementsByInterface); 4259 mixin(Document.prototype, GetElementsByInterface);
4017 mixin(Document.prototype, ParentNodeInterface); 4260 mixin(Document.prototype, ParentNodeInterface);
4018 mixin(Document.prototype, SelectorsInterface); 4261 mixin(Document.prototype, SelectorsInterface);
4262 mixin(Document.prototype, NonElementParentNodeInterface);
4019 mixin(Document.prototype, { 4263 mixin(Document.prototype, {
4020 get implementation() { 4264 get implementation() {
4021 var implementation = implementationTable.get(this); 4265 var implementation = implementationTable.get(this);
4022 if (implementation) return implementation; 4266 if (implementation) return implementation;
4023 implementation = new DOMImplementation(unwrap(this).implementation); 4267 implementation = new DOMImplementation(unwrap(this).implementation);
4024 implementationTable.set(this, implementation); 4268 implementationTable.set(this, implementation);
4025 return implementation; 4269 return implementation;
4026 }, 4270 },
4027 get defaultView() { 4271 get defaultView() {
4028 return wrap(unwrap(this).defaultView); 4272 return wrap(unwrap(this).defaultView);
4029 } 4273 }
4030 }); 4274 });
4031 registerWrapper(window.Document, Document, document.implementation.createHTM LDocument("")); 4275 registerWrapper(window.Document, Document, document.implementation.createHTM LDocument(""));
4032 if (window.HTMLDocument) registerWrapper(window.HTMLDocument, Document); 4276 if (window.HTMLDocument) registerWrapper(window.HTMLDocument, Document);
4033 wrapEventTargetMethods([ window.HTMLBodyElement, window.HTMLDocument || wind ow.Document, window.HTMLHeadElement ]); 4277 wrapEventTargetMethods([ window.HTMLBodyElement, window.HTMLDocument || wind ow.Document, window.HTMLHeadElement ]);
4034 function DOMImplementation(impl) { 4278 function DOMImplementation(impl) {
4035 setWrapper(impl, this); 4279 setWrapper(impl, this);
4036 } 4280 }
4281 var originalCreateDocument = document.implementation.createDocument;
4282 DOMImplementation.prototype.createDocument = function() {
4283 arguments[2] = unwrap(arguments[2]);
4284 return wrap(originalCreateDocument.apply(unsafeUnwrap(this), arguments));
4285 };
4037 function wrapImplMethod(constructor, name) { 4286 function wrapImplMethod(constructor, name) {
4038 var original = document.implementation[name]; 4287 var original = document.implementation[name];
4039 constructor.prototype[name] = function() { 4288 constructor.prototype[name] = function() {
4040 return wrap(original.apply(unsafeUnwrap(this), arguments)); 4289 return wrap(original.apply(unsafeUnwrap(this), arguments));
4041 }; 4290 };
4042 } 4291 }
4043 function forwardImplMethod(constructor, name) { 4292 function forwardImplMethod(constructor, name) {
4044 var original = document.implementation[name]; 4293 var original = document.implementation[name];
4045 constructor.prototype[name] = function() { 4294 constructor.prototype[name] = function() {
4046 return original.apply(unsafeUnwrap(this), arguments); 4295 return original.apply(unsafeUnwrap(this), arguments);
4047 }; 4296 };
4048 } 4297 }
4049 wrapImplMethod(DOMImplementation, "createDocumentType"); 4298 wrapImplMethod(DOMImplementation, "createDocumentType");
4050 wrapImplMethod(DOMImplementation, "createDocument");
4051 wrapImplMethod(DOMImplementation, "createHTMLDocument"); 4299 wrapImplMethod(DOMImplementation, "createHTMLDocument");
4052 forwardImplMethod(DOMImplementation, "hasFeature"); 4300 forwardImplMethod(DOMImplementation, "hasFeature");
4053 registerWrapper(window.DOMImplementation, DOMImplementation); 4301 registerWrapper(window.DOMImplementation, DOMImplementation);
4054 forwardMethodsToWrapper([ window.DOMImplementation ], [ "createDocumentType" , "createDocument", "createHTMLDocument", "hasFeature" ]); 4302 forwardMethodsToWrapper([ window.DOMImplementation ], [ "createDocument", "c reateDocumentType", "createHTMLDocument", "hasFeature" ]);
4055 scope.adoptNodeNoRemove = adoptNodeNoRemove; 4303 scope.adoptNodeNoRemove = adoptNodeNoRemove;
4056 scope.wrappers.DOMImplementation = DOMImplementation; 4304 scope.wrappers.DOMImplementation = DOMImplementation;
4057 scope.wrappers.Document = Document; 4305 scope.wrappers.Document = Document;
4058 })(window.ShadowDOMPolyfill); 4306 })(window.ShadowDOMPolyfill);
4059 (function(scope) { 4307 (function(scope) {
4060 "use strict"; 4308 "use strict";
4061 var EventTarget = scope.wrappers.EventTarget; 4309 var EventTarget = scope.wrappers.EventTarget;
4062 var Selection = scope.wrappers.Selection; 4310 var Selection = scope.wrappers.Selection;
4063 var mixin = scope.mixin; 4311 var mixin = scope.mixin;
4064 var registerWrapper = scope.registerWrapper; 4312 var registerWrapper = scope.registerWrapper;
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
4449 return r.join(", "); 4697 return r.join(", ");
4450 }, 4698 },
4451 selectorNeedsScoping: function(selector, scopeSelector) { 4699 selectorNeedsScoping: function(selector, scopeSelector) {
4452 if (Array.isArray(scopeSelector)) { 4700 if (Array.isArray(scopeSelector)) {
4453 return true; 4701 return true;
4454 } 4702 }
4455 var re = this.makeScopeMatcher(scopeSelector); 4703 var re = this.makeScopeMatcher(scopeSelector);
4456 return !selector.match(re); 4704 return !selector.match(re);
4457 }, 4705 },
4458 makeScopeMatcher: function(scopeSelector) { 4706 makeScopeMatcher: function(scopeSelector) {
4459 scopeSelector = scopeSelector.replace(/\[/g, "\\[").replace(/\[/g, "\\]" ); 4707 scopeSelector = scopeSelector.replace(/\[/g, "\\[").replace(/\]/g, "\\]" );
4460 return new RegExp("^(" + scopeSelector + ")" + selectorReSuffix, "m"); 4708 return new RegExp("^(" + scopeSelector + ")" + selectorReSuffix, "m");
4461 }, 4709 },
4462 applySelectorScope: function(selector, selectorScope) { 4710 applySelectorScope: function(selector, selectorScope) {
4463 return Array.isArray(selectorScope) ? this.applySelectorScopeList(select or, selectorScope) : this.applySimpleSelectorScope(selector, selectorScope); 4711 return Array.isArray(selectorScope) ? this.applySelectorScopeList(select or, selectorScope) : this.applySimpleSelectorScope(selector, selectorScope);
4464 }, 4712 },
4465 applySelectorScopeList: function(selector, scopeSelectorList) { 4713 applySelectorScopeList: function(selector, scopeSelectorList) {
4466 var r = []; 4714 var r = [];
4467 for (var i = 0, s; s = scopeSelectorList[i]; i++) { 4715 for (var i = 0, s; s = scopeSelectorList[i]; i++) {
4468 r.push(this.applySimpleSelectorScope(selector, s)); 4716 r.push(this.applySimpleSelectorScope(selector, s));
4469 } 4717 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
4519 } 4767 }
4520 }, 4768 },
4521 addCssToDocument: function(cssText, name) { 4769 addCssToDocument: function(cssText, name) {
4522 if (cssText.match("@import")) { 4770 if (cssText.match("@import")) {
4523 addOwnSheet(cssText, name); 4771 addOwnSheet(cssText, name);
4524 } else { 4772 } else {
4525 addCssToDocument(cssText); 4773 addCssToDocument(cssText);
4526 } 4774 }
4527 } 4775 }
4528 }; 4776 };
4529 var selectorRe = /([^{]*)({[\s\S]*?})/gim, cssCommentRe = /\/\*[^*]*\*+([^/* ][^*]*\*+)*\//gim, cssCommentNextSelectorRe = /\/\*\s*@polyfill ([^*]*\*+([^/*][ ^*]*\*+)*\/)([^{]*?){/gim, cssContentNextSelectorRe = /polyfill-next-selector[^} ]*content\:[\s]*?['"](.*?)['"][;\s]*}([^{]*?){/gim, cssCommentRuleRe = /\/\*\s@p olyfill-rule([^*]*\*+([^/*][^*]*\*+)*)\//gim, cssContentRuleRe = /(polyfill-rule )[^}]*(content\:[\s]*['"](.*?)['"])[;\s]*[^}]*}/gim, cssCommentUnscopedRuleRe = /\/\*\s@polyfill-unscoped-rule([^*]*\*+([^/*][^*]*\*+)*)\//gim, cssContentUnscop edRuleRe = /(polyfill-unscoped-rule)[^}]*(content\:[\s]*['"](.*?)['"])[;\s]*[^}] *}/gim, cssPseudoRe = /::(x-[^\s{,(]*)/gim, cssPartRe = /::part\(([^)]*)\)/gim, polyfillHost = "-shadowcsshost", polyfillHostContext = "-shadowcsscontext", pare nSuffix = ")(?:\\((" + "(?:\\([^)(]*\\)|[^)(]*)+?" + ")\\))?([^,{]*)"; 4777 var selectorRe = /([^{]*)({[\s\S]*?})/gim, cssCommentRe = /\/\*[^*]*\*+([^\/ *][^*]*\*+)*\//gim, cssCommentNextSelectorRe = /\/\*\s*@polyfill ([^*]*\*+([^\/* ][^*]*\*+)*\/)([^{]*?){/gim, cssContentNextSelectorRe = /polyfill-next-selector[ ^}]*content\:[\s]*?['"](.*?)['"][;\s]*}([^{]*?){/gim, cssCommentRuleRe = /\/\*\s @polyfill-rule([^*]*\*+([^\/*][^*]*\*+)*)\//gim, cssContentRuleRe = /(polyfill-r ule)[^}]*(content\:[\s]*['"](.*?)['"])[;\s]*[^}]*}/gim, cssCommentUnscopedRuleRe = /\/\*\s@polyfill-unscoped-rule([^*]*\*+([^\/*][^*]*\*+)*)\//gim, cssContentUn scopedRuleRe = /(polyfill-unscoped-rule)[^}]*(content\:[\s]*['"](.*?)['"])[;\s]* [^}]*}/gim, cssPseudoRe = /::(x-[^\s{,(]*)/gim, cssPartRe = /::part\(([^)]*)\)/g im, polyfillHost = "-shadowcsshost", polyfillHostContext = "-shadowcsscontext", parenSuffix = ")(?:\\((" + "(?:\\([^)(]*\\)|[^)(]*)+?" + ")\\))?([^,{]*)";
4530 var cssColonHostRe = new RegExp("(" + polyfillHost + parenSuffix, "gim"), cs sColonHostContextRe = new RegExp("(" + polyfillHostContext + parenSuffix, "gim") , selectorReSuffix = "([>\\s~+[.,{:][\\s\\S]*)?$", colonHostRe = /\:host/gim, co lonHostContextRe = /\:host-context/gim, polyfillHostNoCombinator = polyfillHost + "-no-combinator", polyfillHostRe = new RegExp(polyfillHost, "gim"), polyfillHo stContextRe = new RegExp(polyfillHostContext, "gim"), shadowDOMSelectorsRe = [ / \^\^/g, /\^/g, /\/shadow\//g, /\/shadow-deep\//g, /::shadow/g, /\/deep\//g, /::c ontent/g ]; 4778 var cssColonHostRe = new RegExp("(" + polyfillHost + parenSuffix, "gim"), cs sColonHostContextRe = new RegExp("(" + polyfillHostContext + parenSuffix, "gim") , selectorReSuffix = "([>\\s~+[.,{:][\\s\\S]*)?$", colonHostRe = /\:host/gim, co lonHostContextRe = /\:host-context/gim, polyfillHostNoCombinator = polyfillHost + "-no-combinator", polyfillHostRe = new RegExp(polyfillHost, "gim"), polyfillHo stContextRe = new RegExp(polyfillHostContext, "gim"), shadowDOMSelectorsRe = [ / >>>/g, /::shadow/g, /::content/g, /\/deep\//g, /\/shadow\//g, /\/shadow-deep\//g , /\^\^/g, /\^/g ];
4531 function stylesToCssText(styles, preserveComments) { 4779 function stylesToCssText(styles, preserveComments) {
4532 var cssText = ""; 4780 var cssText = "";
4533 Array.prototype.forEach.call(styles, function(s) { 4781 Array.prototype.forEach.call(styles, function(s) {
4534 cssText += s.textContent + "\n\n"; 4782 cssText += s.textContent + "\n\n";
4535 }); 4783 });
4536 if (!preserveComments) { 4784 if (!preserveComments) {
4537 cssText = cssText.replace(cssCommentRe, ""); 4785 cssText = cssText.replace(cssCommentRe, "");
4538 } 4786 }
4539 return cssText; 4787 return cssText;
4540 } 4788 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
4642 } 4890 }
4643 var style = elt.__importElement || elt; 4891 var style = elt.__importElement || elt;
4644 if (!style.hasAttribute(SHIM_ATTRIBUTE)) { 4892 if (!style.hasAttribute(SHIM_ATTRIBUTE)) {
4645 originalParseGeneric.call(this, elt); 4893 originalParseGeneric.call(this, elt);
4646 return; 4894 return;
4647 } 4895 }
4648 if (elt.__resource) { 4896 if (elt.__resource) {
4649 style = elt.ownerDocument.createElement("style"); 4897 style = elt.ownerDocument.createElement("style");
4650 style.textContent = elt.__resource; 4898 style.textContent = elt.__resource;
4651 } 4899 }
4652 HTMLImports.path.resolveUrlsInStyle(style); 4900 HTMLImports.path.resolveUrlsInStyle(style, elt.href);
4653 style.textContent = ShadowCSS.shimStyle(style); 4901 style.textContent = ShadowCSS.shimStyle(style);
4654 style.removeAttribute(SHIM_ATTRIBUTE, ""); 4902 style.removeAttribute(SHIM_ATTRIBUTE, "");
4655 style.setAttribute(SHIMMED_ATTRIBUTE, ""); 4903 style.setAttribute(SHIMMED_ATTRIBUTE, "");
4656 style[SHIMMED_ATTRIBUTE] = true; 4904 style[SHIMMED_ATTRIBUTE] = true;
4657 if (style.parentNode !== head) { 4905 if (style.parentNode !== head) {
4658 if (elt.parentNode === head) { 4906 if (elt.parentNode === head) {
4659 head.replaceChild(style, elt); 4907 head.replaceChild(style, elt);
4660 } else { 4908 } else {
4661 this.addElementToDocument(style); 4909 this.addElementToDocument(style);
4662 } 4910 }
(...skipping 21 matching lines...) Expand all
4684 if (window.ShadowDOMPolyfill) { 4932 if (window.ShadowDOMPolyfill) {
4685 window.wrap = ShadowDOMPolyfill.wrapIfNeeded; 4933 window.wrap = ShadowDOMPolyfill.wrapIfNeeded;
4686 window.unwrap = ShadowDOMPolyfill.unwrapIfNeeded; 4934 window.unwrap = ShadowDOMPolyfill.unwrapIfNeeded;
4687 } else { 4935 } else {
4688 window.wrap = window.unwrap = function(n) { 4936 window.wrap = window.unwrap = function(n) {
4689 return n; 4937 return n;
4690 }; 4938 };
4691 } 4939 }
4692 })(window.WebComponents); 4940 })(window.WebComponents);
4693 4941
4942 (function(scope) {
4943 "use strict";
4944 var hasWorkingUrl = false;
4945 if (!scope.forceJURL) {
4946 try {
4947 var u = new URL("b", "http://a");
4948 u.pathname = "c%20d";
4949 hasWorkingUrl = u.href === "http://a/c%20d";
4950 } catch (e) {}
4951 }
4952 if (hasWorkingUrl) return;
4953 var relative = Object.create(null);
4954 relative["ftp"] = 21;
4955 relative["file"] = 0;
4956 relative["gopher"] = 70;
4957 relative["http"] = 80;
4958 relative["https"] = 443;
4959 relative["ws"] = 80;
4960 relative["wss"] = 443;
4961 var relativePathDotMapping = Object.create(null);
4962 relativePathDotMapping["%2e"] = ".";
4963 relativePathDotMapping[".%2e"] = "..";
4964 relativePathDotMapping["%2e."] = "..";
4965 relativePathDotMapping["%2e%2e"] = "..";
4966 function isRelativeScheme(scheme) {
4967 return relative[scheme] !== undefined;
4968 }
4969 function invalid() {
4970 clear.call(this);
4971 this._isInvalid = true;
4972 }
4973 function IDNAToASCII(h) {
4974 if ("" == h) {
4975 invalid.call(this);
4976 }
4977 return h.toLowerCase();
4978 }
4979 function percentEscape(c) {
4980 var unicode = c.charCodeAt(0);
4981 if (unicode > 32 && unicode < 127 && [ 34, 35, 60, 62, 63, 96 ].indexOf(unic ode) == -1) {
4982 return c;
4983 }
4984 return encodeURIComponent(c);
4985 }
4986 function percentEscapeQuery(c) {
4987 var unicode = c.charCodeAt(0);
4988 if (unicode > 32 && unicode < 127 && [ 34, 35, 60, 62, 96 ].indexOf(unicode) == -1) {
4989 return c;
4990 }
4991 return encodeURIComponent(c);
4992 }
4993 var EOF = undefined, ALPHA = /[a-zA-Z]/, ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
4994 function parse(input, stateOverride, base) {
4995 function err(message) {
4996 errors.push(message);
4997 }
4998 var state = stateOverride || "scheme start", cursor = 0, buffer = "", seenAt = false, seenBracket = false, errors = [];
4999 loop: while ((input[cursor - 1] != EOF || cursor == 0) && !this._isInvalid) {
5000 var c = input[cursor];
5001 switch (state) {
5002 case "scheme start":
5003 if (c && ALPHA.test(c)) {
5004 buffer += c.toLowerCase();
5005 state = "scheme";
5006 } else if (!stateOverride) {
5007 buffer = "";
5008 state = "no scheme";
5009 continue;
5010 } else {
5011 err("Invalid scheme.");
5012 break loop;
5013 }
5014 break;
5015
5016 case "scheme":
5017 if (c && ALPHANUMERIC.test(c)) {
5018 buffer += c.toLowerCase();
5019 } else if (":" == c) {
5020 this._scheme = buffer;
5021 buffer = "";
5022 if (stateOverride) {
5023 break loop;
5024 }
5025 if (isRelativeScheme(this._scheme)) {
5026 this._isRelative = true;
5027 }
5028 if ("file" == this._scheme) {
5029 state = "relative";
5030 } else if (this._isRelative && base && base._scheme == this._scheme) {
5031 state = "relative or authority";
5032 } else if (this._isRelative) {
5033 state = "authority first slash";
5034 } else {
5035 state = "scheme data";
5036 }
5037 } else if (!stateOverride) {
5038 buffer = "";
5039 cursor = 0;
5040 state = "no scheme";
5041 continue;
5042 } else if (EOF == c) {
5043 break loop;
5044 } else {
5045 err("Code point not allowed in scheme: " + c);
5046 break loop;
5047 }
5048 break;
5049
5050 case "scheme data":
5051 if ("?" == c) {
5052 this._query = "?";
5053 state = "query";
5054 } else if ("#" == c) {
5055 this._fragment = "#";
5056 state = "fragment";
5057 } else {
5058 if (EOF != c && " " != c && "\n" != c && "\r" != c) {
5059 this._schemeData += percentEscape(c);
5060 }
5061 }
5062 break;
5063
5064 case "no scheme":
5065 if (!base || !isRelativeScheme(base._scheme)) {
5066 err("Missing scheme.");
5067 invalid.call(this);
5068 } else {
5069 state = "relative";
5070 continue;
5071 }
5072 break;
5073
5074 case "relative or authority":
5075 if ("/" == c && "/" == input[cursor + 1]) {
5076 state = "authority ignore slashes";
5077 } else {
5078 err("Expected /, got: " + c);
5079 state = "relative";
5080 continue;
5081 }
5082 break;
5083
5084 case "relative":
5085 this._isRelative = true;
5086 if ("file" != this._scheme) this._scheme = base._scheme;
5087 if (EOF == c) {
5088 this._host = base._host;
5089 this._port = base._port;
5090 this._path = base._path.slice();
5091 this._query = base._query;
5092 this._username = base._username;
5093 this._password = base._password;
5094 break loop;
5095 } else if ("/" == c || "\\" == c) {
5096 if ("\\" == c) err("\\ is an invalid code point.");
5097 state = "relative slash";
5098 } else if ("?" == c) {
5099 this._host = base._host;
5100 this._port = base._port;
5101 this._path = base._path.slice();
5102 this._query = "?";
5103 this._username = base._username;
5104 this._password = base._password;
5105 state = "query";
5106 } else if ("#" == c) {
5107 this._host = base._host;
5108 this._port = base._port;
5109 this._path = base._path.slice();
5110 this._query = base._query;
5111 this._fragment = "#";
5112 this._username = base._username;
5113 this._password = base._password;
5114 state = "fragment";
5115 } else {
5116 var nextC = input[cursor + 1];
5117 var nextNextC = input[cursor + 2];
5118 if ("file" != this._scheme || !ALPHA.test(c) || nextC != ":" && nextC != "|" || EOF != nextNextC && "/" != nextNextC && "\\" != nextNextC && "?" != ne xtNextC && "#" != nextNextC) {
5119 this._host = base._host;
5120 this._port = base._port;
5121 this._username = base._username;
5122 this._password = base._password;
5123 this._path = base._path.slice();
5124 this._path.pop();
5125 }
5126 state = "relative path";
5127 continue;
5128 }
5129 break;
5130
5131 case "relative slash":
5132 if ("/" == c || "\\" == c) {
5133 if ("\\" == c) {
5134 err("\\ is an invalid code point.");
5135 }
5136 if ("file" == this._scheme) {
5137 state = "file host";
5138 } else {
5139 state = "authority ignore slashes";
5140 }
5141 } else {
5142 if ("file" != this._scheme) {
5143 this._host = base._host;
5144 this._port = base._port;
5145 this._username = base._username;
5146 this._password = base._password;
5147 }
5148 state = "relative path";
5149 continue;
5150 }
5151 break;
5152
5153 case "authority first slash":
5154 if ("/" == c) {
5155 state = "authority second slash";
5156 } else {
5157 err("Expected '/', got: " + c);
5158 state = "authority ignore slashes";
5159 continue;
5160 }
5161 break;
5162
5163 case "authority second slash":
5164 state = "authority ignore slashes";
5165 if ("/" != c) {
5166 err("Expected '/', got: " + c);
5167 continue;
5168 }
5169 break;
5170
5171 case "authority ignore slashes":
5172 if ("/" != c && "\\" != c) {
5173 state = "authority";
5174 continue;
5175 } else {
5176 err("Expected authority, got: " + c);
5177 }
5178 break;
5179
5180 case "authority":
5181 if ("@" == c) {
5182 if (seenAt) {
5183 err("@ already seen.");
5184 buffer += "%40";
5185 }
5186 seenAt = true;
5187 for (var i = 0; i < buffer.length; i++) {
5188 var cp = buffer[i];
5189 if (" " == cp || "\n" == cp || "\r" == cp) {
5190 err("Invalid whitespace in authority.");
5191 continue;
5192 }
5193 if (":" == cp && null === this._password) {
5194 this._password = "";
5195 continue;
5196 }
5197 var tempC = percentEscape(cp);
5198 null !== this._password ? this._password += tempC : this._username + = tempC;
5199 }
5200 buffer = "";
5201 } else if (EOF == c || "/" == c || "\\" == c || "?" == c || "#" == c) {
5202 cursor -= buffer.length;
5203 buffer = "";
5204 state = "host";
5205 continue;
5206 } else {
5207 buffer += c;
5208 }
5209 break;
5210
5211 case "file host":
5212 if (EOF == c || "/" == c || "\\" == c || "?" == c || "#" == c) {
5213 if (buffer.length == 2 && ALPHA.test(buffer[0]) && (buffer[1] == ":" | | buffer[1] == "|")) {
5214 state = "relative path";
5215 } else if (buffer.length == 0) {
5216 state = "relative path start";
5217 } else {
5218 this._host = IDNAToASCII.call(this, buffer);
5219 buffer = "";
5220 state = "relative path start";
5221 }
5222 continue;
5223 } else if (" " == c || "\n" == c || "\r" == c) {
5224 err("Invalid whitespace in file host.");
5225 } else {
5226 buffer += c;
5227 }
5228 break;
5229
5230 case "host":
5231 case "hostname":
5232 if (":" == c && !seenBracket) {
5233 this._host = IDNAToASCII.call(this, buffer);
5234 buffer = "";
5235 state = "port";
5236 if ("hostname" == stateOverride) {
5237 break loop;
5238 }
5239 } else if (EOF == c || "/" == c || "\\" == c || "?" == c || "#" == c) {
5240 this._host = IDNAToASCII.call(this, buffer);
5241 buffer = "";
5242 state = "relative path start";
5243 if (stateOverride) {
5244 break loop;
5245 }
5246 continue;
5247 } else if (" " != c && "\n" != c && "\r" != c) {
5248 if ("[" == c) {
5249 seenBracket = true;
5250 } else if ("]" == c) {
5251 seenBracket = false;
5252 }
5253 buffer += c;
5254 } else {
5255 err("Invalid code point in host/hostname: " + c);
5256 }
5257 break;
5258
5259 case "port":
5260 if (/[0-9]/.test(c)) {
5261 buffer += c;
5262 } else if (EOF == c || "/" == c || "\\" == c || "?" == c || "#" == c || stateOverride) {
5263 if ("" != buffer) {
5264 var temp = parseInt(buffer, 10);
5265 if (temp != relative[this._scheme]) {
5266 this._port = temp + "";
5267 }
5268 buffer = "";
5269 }
5270 if (stateOverride) {
5271 break loop;
5272 }
5273 state = "relative path start";
5274 continue;
5275 } else if (" " == c || "\n" == c || "\r" == c) {
5276 err("Invalid code point in port: " + c);
5277 } else {
5278 invalid.call(this);
5279 }
5280 break;
5281
5282 case "relative path start":
5283 if ("\\" == c) err("'\\' not allowed in path.");
5284 state = "relative path";
5285 if ("/" != c && "\\" != c) {
5286 continue;
5287 }
5288 break;
5289
5290 case "relative path":
5291 if (EOF == c || "/" == c || "\\" == c || !stateOverride && ("?" == c || "#" == c)) {
5292 if ("\\" == c) {
5293 err("\\ not allowed in relative path.");
5294 }
5295 var tmp;
5296 if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
5297 buffer = tmp;
5298 }
5299 if (".." == buffer) {
5300 this._path.pop();
5301 if ("/" != c && "\\" != c) {
5302 this._path.push("");
5303 }
5304 } else if ("." == buffer && "/" != c && "\\" != c) {
5305 this._path.push("");
5306 } else if ("." != buffer) {
5307 if ("file" == this._scheme && this._path.length == 0 && buffer.lengt h == 2 && ALPHA.test(buffer[0]) && buffer[1] == "|") {
5308 buffer = buffer[0] + ":";
5309 }
5310 this._path.push(buffer);
5311 }
5312 buffer = "";
5313 if ("?" == c) {
5314 this._query = "?";
5315 state = "query";
5316 } else if ("#" == c) {
5317 this._fragment = "#";
5318 state = "fragment";
5319 }
5320 } else if (" " != c && "\n" != c && "\r" != c) {
5321 buffer += percentEscape(c);
5322 }
5323 break;
5324
5325 case "query":
5326 if (!stateOverride && "#" == c) {
5327 this._fragment = "#";
5328 state = "fragment";
5329 } else if (EOF != c && " " != c && "\n" != c && "\r" != c) {
5330 this._query += percentEscapeQuery(c);
5331 }
5332 break;
5333
5334 case "fragment":
5335 if (EOF != c && " " != c && "\n" != c && "\r" != c) {
5336 this._fragment += c;
5337 }
5338 break;
5339 }
5340 cursor++;
5341 }
5342 }
5343 function clear() {
5344 this._scheme = "";
5345 this._schemeData = "";
5346 this._username = "";
5347 this._password = null;
5348 this._host = "";
5349 this._port = "";
5350 this._path = [];
5351 this._query = "";
5352 this._fragment = "";
5353 this._isInvalid = false;
5354 this._isRelative = false;
5355 }
5356 function jURL(url, base) {
5357 if (base !== undefined && !(base instanceof jURL)) base = new jURL(String(ba se));
5358 this._url = url;
5359 clear.call(this);
5360 var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, "");
5361 parse.call(this, input, null, base);
5362 }
5363 jURL.prototype = {
5364 toString: function() {
5365 return this.href;
5366 },
5367 get href() {
5368 if (this._isInvalid) return this._url;
5369 var authority = "";
5370 if ("" != this._username || null != this._password) {
5371 authority = this._username + (null != this._password ? ":" + this._passw ord : "") + "@";
5372 }
5373 return this.protocol + (this._isRelative ? "//" + authority + this.host : "") + this.pathname + this._query + this._fragment;
5374 },
5375 set href(href) {
5376 clear.call(this);
5377 parse.call(this, href);
5378 },
5379 get protocol() {
5380 return this._scheme + ":";
5381 },
5382 set protocol(protocol) {
5383 if (this._isInvalid) return;
5384 parse.call(this, protocol + ":", "scheme start");
5385 },
5386 get host() {
5387 return this._isInvalid ? "" : this._port ? this._host + ":" + this._port : this._host;
5388 },
5389 set host(host) {
5390 if (this._isInvalid || !this._isRelative) return;
5391 parse.call(this, host, "host");
5392 },
5393 get hostname() {
5394 return this._host;
5395 },
5396 set hostname(hostname) {
5397 if (this._isInvalid || !this._isRelative) return;
5398 parse.call(this, hostname, "hostname");
5399 },
5400 get port() {
5401 return this._port;
5402 },
5403 set port(port) {
5404 if (this._isInvalid || !this._isRelative) return;
5405 parse.call(this, port, "port");
5406 },
5407 get pathname() {
5408 return this._isInvalid ? "" : this._isRelative ? "/" + this._path.join("/" ) : this._schemeData;
5409 },
5410 set pathname(pathname) {
5411 if (this._isInvalid || !this._isRelative) return;
5412 this._path = [];
5413 parse.call(this, pathname, "relative path start");
5414 },
5415 get search() {
5416 return this._isInvalid || !this._query || "?" == this._query ? "" : this._ query;
5417 },
5418 set search(search) {
5419 if (this._isInvalid || !this._isRelative) return;
5420 this._query = "?";
5421 if ("?" == search[0]) search = search.slice(1);
5422 parse.call(this, search, "query");
5423 },
5424 get hash() {
5425 return this._isInvalid || !this._fragment || "#" == this._fragment ? "" : this._fragment;
5426 },
5427 set hash(hash) {
5428 if (this._isInvalid) return;
5429 this._fragment = "#";
5430 if ("#" == hash[0]) hash = hash.slice(1);
5431 parse.call(this, hash, "fragment");
5432 },
5433 get origin() {
5434 var host;
5435 if (this._isInvalid || !this._scheme) {
5436 return "";
5437 }
5438 switch (this._scheme) {
5439 case "data":
5440 case "file":
5441 case "javascript":
5442 case "mailto":
5443 return "null";
5444 }
5445 host = this.host;
5446 if (!host) {
5447 return "";
5448 }
5449 return this._scheme + "://" + host;
5450 }
5451 };
5452 var OriginalURL = scope.URL;
5453 if (OriginalURL) {
5454 jURL.createObjectURL = function(blob) {
5455 return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
5456 };
5457 jURL.revokeObjectURL = function(url) {
5458 OriginalURL.revokeObjectURL(url);
5459 };
5460 }
5461 scope.URL = jURL;
5462 })(self);
5463
4694 (function(global) { 5464 (function(global) {
5465 if (global.JsMutationObserver) {
5466 return;
5467 }
4695 var registrationsTable = new WeakMap(); 5468 var registrationsTable = new WeakMap();
4696 var setImmediate; 5469 var setImmediate;
4697 if (/Trident/.test(navigator.userAgent)) { 5470 if (/Trident|Edge/.test(navigator.userAgent)) {
4698 setImmediate = setTimeout; 5471 setImmediate = setTimeout;
4699 } else if (window.setImmediate) { 5472 } else if (window.setImmediate) {
4700 setImmediate = window.setImmediate; 5473 setImmediate = window.setImmediate;
4701 } else { 5474 } else {
4702 var setImmediateQueue = []; 5475 var setImmediateQueue = [];
4703 var sentinel = String(Math.random()); 5476 var sentinel = String(Math.random());
4704 window.addEventListener("message", function(e) { 5477 window.addEventListener("message", function(e) {
4705 if (e.data === sentinel) { 5478 if (e.data === sentinel) {
4706 var queue = setImmediateQueue; 5479 var queue = setImmediateQueue;
4707 setImmediateQueue = []; 5480 setImmediateQueue = [];
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
4955 if (!options.characterData) return; 5728 if (!options.characterData) return;
4956 if (options.characterDataOldValue) return getRecordWithOldValue(oldVal ue); 5729 if (options.characterDataOldValue) return getRecordWithOldValue(oldVal ue);
4957 return record; 5730 return record;
4958 }); 5731 });
4959 break; 5732 break;
4960 5733
4961 case "DOMNodeRemoved": 5734 case "DOMNodeRemoved":
4962 this.addTransientObserver(e.target); 5735 this.addTransientObserver(e.target);
4963 5736
4964 case "DOMNodeInserted": 5737 case "DOMNodeInserted":
4965 var target = e.relatedNode;
4966 var changedNode = e.target; 5738 var changedNode = e.target;
4967 var addedNodes, removedNodes; 5739 var addedNodes, removedNodes;
4968 if (e.type === "DOMNodeInserted") { 5740 if (e.type === "DOMNodeInserted") {
4969 addedNodes = [ changedNode ]; 5741 addedNodes = [ changedNode ];
4970 removedNodes = []; 5742 removedNodes = [];
4971 } else { 5743 } else {
4972 addedNodes = []; 5744 addedNodes = [];
4973 removedNodes = [ changedNode ]; 5745 removedNodes = [ changedNode ];
4974 } 5746 }
4975 var previousSibling = changedNode.previousSibling; 5747 var previousSibling = changedNode.previousSibling;
4976 var nextSibling = changedNode.nextSibling; 5748 var nextSibling = changedNode.nextSibling;
4977 var record = getRecord("childList", target); 5749 var record = getRecord("childList", e.target.parentNode);
4978 record.addedNodes = addedNodes; 5750 record.addedNodes = addedNodes;
4979 record.removedNodes = removedNodes; 5751 record.removedNodes = removedNodes;
4980 record.previousSibling = previousSibling; 5752 record.previousSibling = previousSibling;
4981 record.nextSibling = nextSibling; 5753 record.nextSibling = nextSibling;
4982 forEachAncestorAndObserverEnqueueRecord(target, function(options) { 5754 forEachAncestorAndObserverEnqueueRecord(e.relatedNode, function(options) {
4983 if (!options.childList) return; 5755 if (!options.childList) return;
4984 return record; 5756 return record;
4985 }); 5757 });
4986 } 5758 }
4987 clearRecords(); 5759 clearRecords();
4988 } 5760 }
4989 }; 5761 };
4990 global.JsMutationObserver = JsMutationObserver; 5762 global.JsMutationObserver = JsMutationObserver;
4991 if (!global.MutationObserver) global.MutationObserver = JsMutationObserver; 5763 if (!global.MutationObserver) {
4992 })(this); 5764 global.MutationObserver = JsMutationObserver;
5765 JsMutationObserver._isPolyfilled = true;
5766 }
5767 })(self);
5768
5769 (function(scope) {
5770 "use strict";
5771 if (!window.performance) {
5772 var start = Date.now();
5773 window.performance = {
5774 now: function() {
5775 return Date.now() - start;
5776 }
5777 };
5778 }
5779 if (!window.requestAnimationFrame) {
5780 window.requestAnimationFrame = function() {
5781 var nativeRaf = window.webkitRequestAnimationFrame || window.mozRequestAni mationFrame;
5782 return nativeRaf ? function(callback) {
5783 return nativeRaf(function() {
5784 callback(performance.now());
5785 });
5786 } : function(callback) {
5787 return window.setTimeout(callback, 1e3 / 60);
5788 };
5789 }();
5790 }
5791 if (!window.cancelAnimationFrame) {
5792 window.cancelAnimationFrame = function() {
5793 return window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || function(id) {
5794 clearTimeout(id);
5795 };
5796 }();
5797 }
5798 var workingDefaultPrevented = function() {
5799 var e = document.createEvent("Event");
5800 e.initEvent("foo", true, true);
5801 e.preventDefault();
5802 return e.defaultPrevented;
5803 }();
5804 if (!workingDefaultPrevented) {
5805 var origPreventDefault = Event.prototype.preventDefault;
5806 Event.prototype.preventDefault = function() {
5807 if (!this.cancelable) {
5808 return;
5809 }
5810 origPreventDefault.call(this);
5811 Object.defineProperty(this, "defaultPrevented", {
5812 get: function() {
5813 return true;
5814 },
5815 configurable: true
5816 });
5817 };
5818 }
5819 var isIE = /Trident/.test(navigator.userAgent);
5820 if (!window.CustomEvent || isIE && typeof window.CustomEvent !== "function") {
5821 window.CustomEvent = function(inType, params) {
5822 params = params || {};
5823 var e = document.createEvent("CustomEvent");
5824 e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelab le), params.detail);
5825 return e;
5826 };
5827 window.CustomEvent.prototype = window.Event.prototype;
5828 }
5829 if (!window.Event || isIE && typeof window.Event !== "function") {
5830 var origEvent = window.Event;
5831 window.Event = function(inType, params) {
5832 params = params || {};
5833 var e = document.createEvent("Event");
5834 e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable));
5835 return e;
5836 };
5837 window.Event.prototype = origEvent.prototype;
5838 }
5839 })(window.WebComponents);
4993 5840
4994 window.HTMLImports = window.HTMLImports || { 5841 window.HTMLImports = window.HTMLImports || {
4995 flags: {} 5842 flags: {}
4996 }; 5843 };
4997 5844
4998 (function(scope) { 5845 (function(scope) {
4999 var IMPORT_LINK_TYPE = "import"; 5846 var IMPORT_LINK_TYPE = "import";
5000 var useNative = Boolean(IMPORT_LINK_TYPE in document.createElement("link")); 5847 var useNative = Boolean(IMPORT_LINK_TYPE in document.createElement("link"));
5001 var hasShadowDOMPolyfill = Boolean(window.ShadowDOMPolyfill); 5848 var hasShadowDOMPolyfill = Boolean(window.ShadowDOMPolyfill);
5002 var wrap = function(node) { 5849 var wrap = function(node) {
5003 return hasShadowDOMPolyfill ? ShadowDOMPolyfill.wrapIfNeeded(node) : node; 5850 return hasShadowDOMPolyfill ? window.ShadowDOMPolyfill.wrapIfNeeded(node) : node;
5004 }; 5851 };
5005 var rootDocument = wrap(document); 5852 var rootDocument = wrap(document);
5006 var currentScriptDescriptor = { 5853 var currentScriptDescriptor = {
5007 get: function() { 5854 get: function() {
5008 var script = HTMLImports.currentScript || document.currentScript || (docum ent.readyState !== "complete" ? document.scripts[document.scripts.length - 1] : null); 5855 var script = window.HTMLImports.currentScript || document.currentScript || (document.readyState !== "complete" ? document.scripts[document.scripts.length - 1] : null);
5009 return wrap(script); 5856 return wrap(script);
5010 }, 5857 },
5011 configurable: true 5858 configurable: true
5012 }; 5859 };
5013 Object.defineProperty(document, "_currentScript", currentScriptDescriptor); 5860 Object.defineProperty(document, "_currentScript", currentScriptDescriptor);
5014 Object.defineProperty(rootDocument, "_currentScript", currentScriptDescriptor) ; 5861 Object.defineProperty(rootDocument, "_currentScript", currentScriptDescriptor) ;
5015 var isIE = /Trident/.test(navigator.userAgent); 5862 var isIE = /Trident/.test(navigator.userAgent);
5016 function whenReady(callback, doc) { 5863 function whenReady(callback, doc) {
5017 doc = doc || rootDocument; 5864 doc = doc || rootDocument;
5018 whenDocumentReady(function() { 5865 whenDocumentReady(function() {
(...skipping 16 matching lines...) Expand all
5035 doc.addEventListener(READY_EVENT, checkReady); 5882 doc.addEventListener(READY_EVENT, checkReady);
5036 } else if (callback) { 5883 } else if (callback) {
5037 callback(); 5884 callback();
5038 } 5885 }
5039 } 5886 }
5040 function markTargetLoaded(event) { 5887 function markTargetLoaded(event) {
5041 event.target.__loaded = true; 5888 event.target.__loaded = true;
5042 } 5889 }
5043 function watchImportsLoad(callback, doc) { 5890 function watchImportsLoad(callback, doc) {
5044 var imports = doc.querySelectorAll("link[rel=import]"); 5891 var imports = doc.querySelectorAll("link[rel=import]");
5045 var loaded = 0, l = imports.length; 5892 var parsedCount = 0, importCount = imports.length, newImports = [], errorImp orts = [];
5046 function checkDone(d) { 5893 function checkDone() {
5047 if (loaded == l && callback) { 5894 if (parsedCount == importCount && callback) {
5048 callback(); 5895 callback({
5896 allImports: imports,
5897 loadedImports: newImports,
5898 errorImports: errorImports
5899 });
5049 } 5900 }
5050 } 5901 }
5051 function loadedImport(e) { 5902 function loadedImport(e) {
5052 markTargetLoaded(e); 5903 markTargetLoaded(e);
5053 loaded++; 5904 newImports.push(this);
5905 parsedCount++;
5054 checkDone(); 5906 checkDone();
5055 } 5907 }
5056 if (l) { 5908 function errorLoadingImport(e) {
5057 for (var i = 0, imp; i < l && (imp = imports[i]); i++) { 5909 errorImports.push(this);
5910 parsedCount++;
5911 checkDone();
5912 }
5913 if (importCount) {
5914 for (var i = 0, imp; i < importCount && (imp = imports[i]); i++) {
5058 if (isImportLoaded(imp)) { 5915 if (isImportLoaded(imp)) {
5059 loadedImport.call(imp, { 5916 newImports.push(this);
5060 target: imp 5917 parsedCount++;
5061 }); 5918 checkDone();
5062 } else { 5919 } else {
5063 imp.addEventListener("load", loadedImport); 5920 imp.addEventListener("load", loadedImport);
5064 imp.addEventListener("error", loadedImport); 5921 imp.addEventListener("error", errorLoadingImport);
5065 } 5922 }
5066 } 5923 }
5067 } else { 5924 } else {
5068 checkDone(); 5925 checkDone();
5069 } 5926 }
5070 } 5927 }
5071 function isImportLoaded(link) { 5928 function isImportLoaded(link) {
5072 return useNative ? link.__loaded || link.import && link.import.readyState != = "loading" : link.__importParsed; 5929 return useNative ? link.__loaded || link.import && link.import.readyState != = "loading" : link.__importParsed;
5073 } 5930 }
5074 if (useNative) { 5931 if (useNative) {
(...skipping 29 matching lines...) Expand all
5104 } 5961 }
5105 (function() { 5962 (function() {
5106 if (document.readyState === "loading") { 5963 if (document.readyState === "loading") {
5107 var imports = document.querySelectorAll("link[rel=import]"); 5964 var imports = document.querySelectorAll("link[rel=import]");
5108 for (var i = 0, l = imports.length, imp; i < l && (imp = imports[i]); i+ +) { 5965 for (var i = 0, l = imports.length, imp; i < l && (imp = imports[i]); i+ +) {
5109 handleImport(imp); 5966 handleImport(imp);
5110 } 5967 }
5111 } 5968 }
5112 })(); 5969 })();
5113 } 5970 }
5114 whenReady(function() { 5971 whenReady(function(detail) {
5115 HTMLImports.ready = true; 5972 window.HTMLImports.ready = true;
5116 HTMLImports.readyTime = new Date().getTime(); 5973 window.HTMLImports.readyTime = new Date().getTime();
5117 rootDocument.dispatchEvent(new CustomEvent("HTMLImportsLoaded", { 5974 var evt = rootDocument.createEvent("CustomEvent");
5118 bubbles: true 5975 evt.initCustomEvent("HTMLImportsLoaded", true, true, detail);
5119 })); 5976 rootDocument.dispatchEvent(evt);
5120 }); 5977 });
5121 scope.IMPORT_LINK_TYPE = IMPORT_LINK_TYPE; 5978 scope.IMPORT_LINK_TYPE = IMPORT_LINK_TYPE;
5122 scope.useNative = useNative; 5979 scope.useNative = useNative;
5123 scope.rootDocument = rootDocument; 5980 scope.rootDocument = rootDocument;
5124 scope.whenReady = whenReady; 5981 scope.whenReady = whenReady;
5125 scope.isIE = isIE; 5982 scope.isIE = isIE;
5126 })(HTMLImports); 5983 })(window.HTMLImports);
5127 5984
5128 (function(scope) { 5985 (function(scope) {
5129 var modules = []; 5986 var modules = [];
5130 var addModule = function(module) { 5987 var addModule = function(module) {
5131 modules.push(module); 5988 modules.push(module);
5132 }; 5989 };
5133 var initializeModules = function() { 5990 var initializeModules = function() {
5134 modules.forEach(function(module) { 5991 modules.forEach(function(module) {
5135 module(scope); 5992 module(scope);
5136 }); 5993 });
5137 }; 5994 };
5138 scope.addModule = addModule; 5995 scope.addModule = addModule;
5139 scope.initializeModules = initializeModules; 5996 scope.initializeModules = initializeModules;
5140 })(HTMLImports); 5997 })(window.HTMLImports);
5141 5998
5142 HTMLImports.addModule(function(scope) { 5999 window.HTMLImports.addModule(function(scope) {
5143 var CSS_URL_REGEXP = /(url\()([^)]*)(\))/g; 6000 var CSS_URL_REGEXP = /(url\()([^)]*)(\))/g;
5144 var CSS_IMPORT_REGEXP = /(@import[\s]+(?!url\())([^;]*)(;)/g; 6001 var CSS_IMPORT_REGEXP = /(@import[\s]+(?!url\())([^;]*)(;)/g;
5145 var path = { 6002 var path = {
5146 resolveUrlsInStyle: function(style) { 6003 resolveUrlsInStyle: function(style, linkUrl) {
5147 var doc = style.ownerDocument; 6004 var doc = style.ownerDocument;
5148 var resolver = doc.createElement("a"); 6005 var resolver = doc.createElement("a");
5149 style.textContent = this.resolveUrlsInCssText(style.textContent, resolver) ; 6006 style.textContent = this.resolveUrlsInCssText(style.textContent, linkUrl, resolver);
5150 return style; 6007 return style;
5151 }, 6008 },
5152 resolveUrlsInCssText: function(cssText, urlObj) { 6009 resolveUrlsInCssText: function(cssText, linkUrl, urlObj) {
5153 var r = this.replaceUrls(cssText, urlObj, CSS_URL_REGEXP); 6010 var r = this.replaceUrls(cssText, urlObj, linkUrl, CSS_URL_REGEXP);
5154 r = this.replaceUrls(r, urlObj, CSS_IMPORT_REGEXP); 6011 r = this.replaceUrls(r, urlObj, linkUrl, CSS_IMPORT_REGEXP);
5155 return r; 6012 return r;
5156 }, 6013 },
5157 replaceUrls: function(text, urlObj, regexp) { 6014 replaceUrls: function(text, urlObj, linkUrl, regexp) {
5158 return text.replace(regexp, function(m, pre, url, post) { 6015 return text.replace(regexp, function(m, pre, url, post) {
5159 var urlPath = url.replace(/["']/g, ""); 6016 var urlPath = url.replace(/["']/g, "");
6017 if (linkUrl) {
6018 urlPath = new URL(urlPath, linkUrl).href;
6019 }
5160 urlObj.href = urlPath; 6020 urlObj.href = urlPath;
5161 urlPath = urlObj.href; 6021 urlPath = urlObj.href;
5162 return pre + "'" + urlPath + "'" + post; 6022 return pre + "'" + urlPath + "'" + post;
5163 }); 6023 });
5164 } 6024 }
5165 }; 6025 };
5166 scope.path = path; 6026 scope.path = path;
5167 }); 6027 });
5168 6028
5169 HTMLImports.addModule(function(scope) { 6029 window.HTMLImports.addModule(function(scope) {
5170 xhr = { 6030 var xhr = {
5171 async: true, 6031 async: true,
5172 ok: function(request) { 6032 ok: function(request) {
5173 return request.status >= 200 && request.status < 300 || request.status === 304 || request.status === 0; 6033 return request.status >= 200 && request.status < 300 || request.status === 304 || request.status === 0;
5174 }, 6034 },
5175 load: function(url, next, nextContext) { 6035 load: function(url, next, nextContext) {
5176 var request = new XMLHttpRequest(); 6036 var request = new XMLHttpRequest();
5177 if (scope.flags.debug || scope.flags.bust) { 6037 if (scope.flags.debug || scope.flags.bust) {
5178 url += "?" + Math.random(); 6038 url += "?" + Math.random();
5179 } 6039 }
5180 request.open("GET", url, xhr.async); 6040 request.open("GET", url, xhr.async);
5181 request.addEventListener("readystatechange", function(e) { 6041 request.addEventListener("readystatechange", function(e) {
5182 if (request.readyState === 4) { 6042 if (request.readyState === 4) {
5183 var locationHeader = request.getResponseHeader("Location");
5184 var redirectedUrl = null; 6043 var redirectedUrl = null;
5185 if (locationHeader) { 6044 try {
5186 var redirectedUrl = locationHeader.substr(0, 1) === "/" ? location.o rigin + locationHeader : locationHeader; 6045 var locationHeader = request.getResponseHeader("Location");
6046 if (locationHeader) {
6047 redirectedUrl = locationHeader.substr(0, 1) === "/" ? location.ori gin + locationHeader : locationHeader;
6048 }
6049 } catch (e) {
6050 console.error(e.message);
5187 } 6051 }
5188 next.call(nextContext, !xhr.ok(request) && request, request.response | | request.responseText, redirectedUrl); 6052 next.call(nextContext, !xhr.ok(request) && request, request.response | | request.responseText, redirectedUrl);
5189 } 6053 }
5190 }); 6054 });
5191 request.send(); 6055 request.send();
5192 return request; 6056 return request;
5193 }, 6057 },
5194 loadDocument: function(url, next, nextContext) { 6058 loadDocument: function(url, next, nextContext) {
5195 this.load(url, next, nextContext).responseType = "document"; 6059 this.load(url, next, nextContext).responseType = "document";
5196 } 6060 }
5197 }; 6061 };
5198 scope.xhr = xhr; 6062 scope.xhr = xhr;
5199 }); 6063 });
5200 6064
5201 HTMLImports.addModule(function(scope) { 6065 window.HTMLImports.addModule(function(scope) {
5202 var xhr = scope.xhr; 6066 var xhr = scope.xhr;
5203 var flags = scope.flags; 6067 var flags = scope.flags;
5204 var Loader = function(onLoad, onComplete) { 6068 var Loader = function(onLoad, onComplete) {
5205 this.cache = {}; 6069 this.cache = {};
5206 this.onload = onLoad; 6070 this.onload = onLoad;
5207 this.oncomplete = onComplete; 6071 this.oncomplete = onComplete;
5208 this.inflight = 0; 6072 this.inflight = 0;
5209 this.pending = {}; 6073 this.pending = {};
5210 }; 6074 };
5211 Loader.prototype = { 6075 Loader.prototype = {
(...skipping 25 matching lines...) Expand all
5237 if (this.cache[url]) { 6101 if (this.cache[url]) {
5238 this.onload(url, elt, this.cache[url]); 6102 this.onload(url, elt, this.cache[url]);
5239 this.tail(); 6103 this.tail();
5240 return true; 6104 return true;
5241 } 6105 }
5242 this.pending[url] = [ elt ]; 6106 this.pending[url] = [ elt ];
5243 return false; 6107 return false;
5244 }, 6108 },
5245 fetch: function(url, elt) { 6109 fetch: function(url, elt) {
5246 flags.load && console.log("fetch", url, elt); 6110 flags.load && console.log("fetch", url, elt);
5247 if (url.match(/^data:/)) { 6111 if (!url) {
6112 setTimeout(function() {
6113 this.receive(url, elt, {
6114 error: "href must be specified"
6115 }, null);
6116 }.bind(this), 0);
6117 } else if (url.match(/^data:/)) {
5248 var pieces = url.split(","); 6118 var pieces = url.split(",");
5249 var header = pieces[0]; 6119 var header = pieces[0];
5250 var body = pieces[1]; 6120 var body = pieces[1];
5251 if (header.indexOf(";base64") > -1) { 6121 if (header.indexOf(";base64") > -1) {
5252 body = atob(body); 6122 body = atob(body);
5253 } else { 6123 } else {
5254 body = decodeURIComponent(body); 6124 body = decodeURIComponent(body);
5255 } 6125 }
5256 setTimeout(function() { 6126 setTimeout(function() {
5257 this.receive(url, elt, null, body); 6127 this.receive(url, elt, null, body);
(...skipping 20 matching lines...) Expand all
5278 }, 6148 },
5279 checkDone: function() { 6149 checkDone: function() {
5280 if (!this.inflight) { 6150 if (!this.inflight) {
5281 this.oncomplete(); 6151 this.oncomplete();
5282 } 6152 }
5283 } 6153 }
5284 }; 6154 };
5285 scope.Loader = Loader; 6155 scope.Loader = Loader;
5286 }); 6156 });
5287 6157
5288 HTMLImports.addModule(function(scope) { 6158 window.HTMLImports.addModule(function(scope) {
5289 var Observer = function(addCallback) { 6159 var Observer = function(addCallback) {
5290 this.addCallback = addCallback; 6160 this.addCallback = addCallback;
5291 this.mo = new MutationObserver(this.handler.bind(this)); 6161 this.mo = new MutationObserver(this.handler.bind(this));
5292 }; 6162 };
5293 Observer.prototype = { 6163 Observer.prototype = {
5294 handler: function(mutations) { 6164 handler: function(mutations) {
5295 for (var i = 0, l = mutations.length, m; i < l && (m = mutations[i]); i++) { 6165 for (var i = 0, l = mutations.length, m; i < l && (m = mutations[i]); i++) {
5296 if (m.type === "childList" && m.addedNodes.length) { 6166 if (m.type === "childList" && m.addedNodes.length) {
5297 this.addedNodes(m.addedNodes); 6167 this.addedNodes(m.addedNodes);
5298 } 6168 }
(...skipping 12 matching lines...) Expand all
5311 observe: function(root) { 6181 observe: function(root) {
5312 this.mo.observe(root, { 6182 this.mo.observe(root, {
5313 childList: true, 6183 childList: true,
5314 subtree: true 6184 subtree: true
5315 }); 6185 });
5316 } 6186 }
5317 }; 6187 };
5318 scope.Observer = Observer; 6188 scope.Observer = Observer;
5319 }); 6189 });
5320 6190
5321 HTMLImports.addModule(function(scope) { 6191 window.HTMLImports.addModule(function(scope) {
5322 var path = scope.path; 6192 var path = scope.path;
5323 var rootDocument = scope.rootDocument; 6193 var rootDocument = scope.rootDocument;
5324 var flags = scope.flags; 6194 var flags = scope.flags;
5325 var isIE = scope.isIE; 6195 var isIE = scope.isIE;
5326 var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE; 6196 var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE;
5327 var IMPORT_SELECTOR = "link[rel=" + IMPORT_LINK_TYPE + "]"; 6197 var IMPORT_SELECTOR = "link[rel=" + IMPORT_LINK_TYPE + "]";
5328 var importParser = { 6198 var importParser = {
5329 documentSelectors: IMPORT_SELECTOR, 6199 documentSelectors: IMPORT_SELECTOR,
5330 importsSelectors: [ IMPORT_SELECTOR, "link[rel=stylesheet]", "style", "scrip t:not([type])", 'script[type="text/javascript"]' ].join(","), 6200 importsSelectors: [ IMPORT_SELECTOR, "link[rel=stylesheet]:not([type])", "st yle:not([type])", "script:not([type])", 'script[type="application/javascript"]', 'script[type="text/javascript"]' ].join(","),
5331 map: { 6201 map: {
5332 link: "parseLink", 6202 link: "parseLink",
5333 script: "parseScript", 6203 script: "parseScript",
5334 style: "parseStyle" 6204 style: "parseStyle"
5335 }, 6205 },
5336 dynamicElements: [], 6206 dynamicElements: [],
5337 parseNext: function() { 6207 parseNext: function() {
5338 var next = this.nextToParse(); 6208 var next = this.nextToParse();
5339 if (next) { 6209 if (next) {
5340 this.parse(next); 6210 this.parse(next);
(...skipping 30 matching lines...) Expand all
5371 this.parsingElement = null; 6241 this.parsingElement = null;
5372 flags.parse && console.log("completed", elt); 6242 flags.parse && console.log("completed", elt);
5373 }, 6243 },
5374 markDynamicParsingComplete: function(elt) { 6244 markDynamicParsingComplete: function(elt) {
5375 var i = this.dynamicElements.indexOf(elt); 6245 var i = this.dynamicElements.indexOf(elt);
5376 if (i >= 0) { 6246 if (i >= 0) {
5377 this.dynamicElements.splice(i, 1); 6247 this.dynamicElements.splice(i, 1);
5378 } 6248 }
5379 }, 6249 },
5380 parseImport: function(elt) { 6250 parseImport: function(elt) {
5381 if (HTMLImports.__importsParsingHook) { 6251 elt.import = elt.__doc;
5382 HTMLImports.__importsParsingHook(elt); 6252 if (window.HTMLImports.__importsParsingHook) {
6253 window.HTMLImports.__importsParsingHook(elt);
5383 } 6254 }
5384 if (elt.import) { 6255 if (elt.import) {
5385 elt.import.__importParsed = true; 6256 elt.import.__importParsed = true;
5386 } 6257 }
5387 this.markParsingComplete(elt); 6258 this.markParsingComplete(elt);
5388 if (elt.__resource && !elt.__error) { 6259 if (elt.__resource && !elt.__error) {
5389 elt.dispatchEvent(new CustomEvent("load", { 6260 elt.dispatchEvent(new CustomEvent("load", {
5390 bubbles: false 6261 bubbles: false
5391 })); 6262 }));
5392 } else { 6263 } else {
(...skipping 18 matching lines...) Expand all
5411 if (nodeIsImport(linkElt)) { 6282 if (nodeIsImport(linkElt)) {
5412 this.parseImport(linkElt); 6283 this.parseImport(linkElt);
5413 } else { 6284 } else {
5414 linkElt.href = linkElt.href; 6285 linkElt.href = linkElt.href;
5415 this.parseGeneric(linkElt); 6286 this.parseGeneric(linkElt);
5416 } 6287 }
5417 }, 6288 },
5418 parseStyle: function(elt) { 6289 parseStyle: function(elt) {
5419 var src = elt; 6290 var src = elt;
5420 elt = cloneStyle(elt); 6291 elt = cloneStyle(elt);
6292 src.__appliedElement = elt;
5421 elt.__importElement = src; 6293 elt.__importElement = src;
5422 this.parseGeneric(elt); 6294 this.parseGeneric(elt);
5423 }, 6295 },
5424 parseGeneric: function(elt) { 6296 parseGeneric: function(elt) {
5425 this.trackElement(elt); 6297 this.trackElement(elt);
5426 this.addElementToDocument(elt); 6298 this.addElementToDocument(elt);
5427 }, 6299 },
5428 rootImportForElement: function(elt) { 6300 rootImportForElement: function(elt) {
5429 var n = elt; 6301 var n = elt;
5430 while (n.ownerDocument.__importLink) { 6302 while (n.ownerDocument.__importLink) {
5431 n = n.ownerDocument.__importLink; 6303 n = n.ownerDocument.__importLink;
5432 } 6304 }
5433 return n; 6305 return n;
5434 }, 6306 },
5435 addElementToDocument: function(elt) { 6307 addElementToDocument: function(elt) {
5436 var port = this.rootImportForElement(elt.__importElement || elt); 6308 var port = this.rootImportForElement(elt.__importElement || elt);
5437 var l = port.__insertedElements = port.__insertedElements || 0; 6309 port.parentNode.insertBefore(elt, port);
5438 var refNode = port.nextElementSibling;
5439 for (var i = 0; i < l; i++) {
5440 refNode = refNode && refNode.nextElementSibling;
5441 }
5442 port.parentNode.insertBefore(elt, refNode);
5443 }, 6310 },
5444 trackElement: function(elt, callback) { 6311 trackElement: function(elt, callback) {
5445 var self = this; 6312 var self = this;
5446 var done = function(e) { 6313 var done = function(e) {
6314 elt.removeEventListener("load", done);
6315 elt.removeEventListener("error", done);
5447 if (callback) { 6316 if (callback) {
5448 callback(e); 6317 callback(e);
5449 } 6318 }
5450 self.markParsingComplete(elt); 6319 self.markParsingComplete(elt);
5451 self.parseNext(); 6320 self.parseNext();
5452 }; 6321 };
5453 elt.addEventListener("load", done); 6322 elt.addEventListener("load", done);
5454 elt.addEventListener("error", done); 6323 elt.addEventListener("error", done);
5455 if (isIE && elt.localName === "style") { 6324 if (isIE && elt.localName === "style") {
5456 var fakeLoad = false; 6325 var fakeLoad = false;
5457 if (elt.textContent.indexOf("@import") == -1) { 6326 if (elt.textContent.indexOf("@import") == -1) {
5458 fakeLoad = true; 6327 fakeLoad = true;
5459 } else if (elt.sheet) { 6328 } else if (elt.sheet) {
5460 fakeLoad = true; 6329 fakeLoad = true;
5461 var csr = elt.sheet.cssRules; 6330 var csr = elt.sheet.cssRules;
5462 var len = csr ? csr.length : 0; 6331 var len = csr ? csr.length : 0;
5463 for (var i = 0, r; i < len && (r = csr[i]); i++) { 6332 for (var i = 0, r; i < len && (r = csr[i]); i++) {
5464 if (r.type === CSSRule.IMPORT_RULE) { 6333 if (r.type === CSSRule.IMPORT_RULE) {
5465 fakeLoad = fakeLoad && Boolean(r.styleSheet); 6334 fakeLoad = fakeLoad && Boolean(r.styleSheet);
5466 } 6335 }
5467 } 6336 }
5468 } 6337 }
5469 if (fakeLoad) { 6338 if (fakeLoad) {
5470 elt.dispatchEvent(new CustomEvent("load", { 6339 setTimeout(function() {
5471 bubbles: false 6340 elt.dispatchEvent(new CustomEvent("load", {
5472 })); 6341 bubbles: false
6342 }));
6343 });
5473 } 6344 }
5474 } 6345 }
5475 }, 6346 },
5476 parseScript: function(scriptElt) { 6347 parseScript: function(scriptElt) {
5477 var script = document.createElement("script"); 6348 var script = document.createElement("script");
5478 script.__importElement = scriptElt; 6349 script.__importElement = scriptElt;
5479 script.src = scriptElt.src ? scriptElt.src : generateScriptDataUrl(scriptE lt); 6350 script.src = scriptElt.src ? scriptElt.src : generateScriptDataUrl(scriptE lt);
5480 scope.currentScript = scriptElt; 6351 scope.currentScript = scriptElt;
5481 this.trackElement(script, function(e) { 6352 this.trackElement(script, function(e) {
5482 script.parentNode.removeChild(script); 6353 if (script.parentNode) {
6354 script.parentNode.removeChild(script);
6355 }
5483 scope.currentScript = null; 6356 scope.currentScript = null;
5484 }); 6357 });
5485 this.addElementToDocument(script); 6358 this.addElementToDocument(script);
5486 }, 6359 },
5487 nextToParse: function() { 6360 nextToParse: function() {
5488 this._mayParse = []; 6361 this._mayParse = [];
5489 return !this.parsingElement && (this.nextToParseInDoc(rootDocument) || thi s.nextToParseDynamic()); 6362 return !this.parsingElement && (this.nextToParseInDoc(rootDocument) || thi s.nextToParseDynamic());
5490 }, 6363 },
5491 nextToParseInDoc: function(doc, link) { 6364 nextToParseInDoc: function(doc, link) {
5492 if (doc && this._mayParse.indexOf(doc) < 0) { 6365 if (doc && this._mayParse.indexOf(doc) < 0) {
5493 this._mayParse.push(doc); 6366 this._mayParse.push(doc);
5494 var nodes = doc.querySelectorAll(this.parseSelectorsForNode(doc)); 6367 var nodes = doc.querySelectorAll(this.parseSelectorsForNode(doc));
5495 for (var i = 0, l = nodes.length, p = 0, n; i < l && (n = nodes[i]); i++ ) { 6368 for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
5496 if (!this.isParsed(n)) { 6369 if (!this.isParsed(n)) {
5497 if (this.hasResource(n)) { 6370 if (this.hasResource(n)) {
5498 return nodeIsImport(n) ? this.nextToParseInDoc(n.import, n) : n; 6371 return nodeIsImport(n) ? this.nextToParseInDoc(n.__doc, n) : n;
5499 } else { 6372 } else {
5500 return; 6373 return;
5501 } 6374 }
5502 } 6375 }
5503 } 6376 }
5504 } 6377 }
5505 return link; 6378 return link;
5506 }, 6379 },
5507 nextToParseDynamic: function() { 6380 nextToParseDynamic: function() {
5508 return this.dynamicElements[0]; 6381 return this.dynamicElements[0];
5509 }, 6382 },
5510 parseSelectorsForNode: function(node) { 6383 parseSelectorsForNode: function(node) {
5511 var doc = node.ownerDocument || node; 6384 var doc = node.ownerDocument || node;
5512 return doc === rootDocument ? this.documentSelectors : this.importsSelecto rs; 6385 return doc === rootDocument ? this.documentSelectors : this.importsSelecto rs;
5513 }, 6386 },
5514 isParsed: function(node) { 6387 isParsed: function(node) {
5515 return node.__importParsed; 6388 return node.__importParsed;
5516 }, 6389 },
5517 needsDynamicParsing: function(elt) { 6390 needsDynamicParsing: function(elt) {
5518 return this.dynamicElements.indexOf(elt) >= 0; 6391 return this.dynamicElements.indexOf(elt) >= 0;
5519 }, 6392 },
5520 hasResource: function(node) { 6393 hasResource: function(node) {
5521 if (nodeIsImport(node) && node.import === undefined) { 6394 if (nodeIsImport(node) && node.__doc === undefined) {
5522 return false; 6395 return false;
5523 } 6396 }
5524 return true; 6397 return true;
5525 } 6398 }
5526 }; 6399 };
5527 function nodeIsImport(elt) { 6400 function nodeIsImport(elt) {
5528 return elt.localName === "link" && elt.rel === IMPORT_LINK_TYPE; 6401 return elt.localName === "link" && elt.rel === IMPORT_LINK_TYPE;
5529 } 6402 }
5530 function generateScriptDataUrl(script) { 6403 function generateScriptDataUrl(script) {
5531 var scriptContent = generateScriptContent(script); 6404 var scriptContent = generateScriptContent(script);
(...skipping 13 matching lines...) Expand all
5545 function cloneStyle(style) { 6418 function cloneStyle(style) {
5546 var clone = style.ownerDocument.createElement("style"); 6419 var clone = style.ownerDocument.createElement("style");
5547 clone.textContent = style.textContent; 6420 clone.textContent = style.textContent;
5548 path.resolveUrlsInStyle(clone); 6421 path.resolveUrlsInStyle(clone);
5549 return clone; 6422 return clone;
5550 } 6423 }
5551 scope.parser = importParser; 6424 scope.parser = importParser;
5552 scope.IMPORT_SELECTOR = IMPORT_SELECTOR; 6425 scope.IMPORT_SELECTOR = IMPORT_SELECTOR;
5553 }); 6426 });
5554 6427
5555 HTMLImports.addModule(function(scope) { 6428 window.HTMLImports.addModule(function(scope) {
5556 var flags = scope.flags; 6429 var flags = scope.flags;
5557 var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE; 6430 var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE;
5558 var IMPORT_SELECTOR = scope.IMPORT_SELECTOR; 6431 var IMPORT_SELECTOR = scope.IMPORT_SELECTOR;
5559 var rootDocument = scope.rootDocument; 6432 var rootDocument = scope.rootDocument;
5560 var Loader = scope.Loader; 6433 var Loader = scope.Loader;
5561 var Observer = scope.Observer; 6434 var Observer = scope.Observer;
5562 var parser = scope.parser; 6435 var parser = scope.parser;
5563 var importer = { 6436 var importer = {
5564 documents: {}, 6437 documents: {},
5565 documentPreloadSelectors: IMPORT_SELECTOR, 6438 documentPreloadSelectors: IMPORT_SELECTOR,
(...skipping 19 matching lines...) Expand all
5585 if (isImportLink(elt)) { 6458 if (isImportLink(elt)) {
5586 var doc = this.documents[url]; 6459 var doc = this.documents[url];
5587 if (doc === undefined) { 6460 if (doc === undefined) {
5588 doc = err ? null : makeDocument(resource, redirectedUrl || url); 6461 doc = err ? null : makeDocument(resource, redirectedUrl || url);
5589 if (doc) { 6462 if (doc) {
5590 doc.__importLink = elt; 6463 doc.__importLink = elt;
5591 this.bootDocument(doc); 6464 this.bootDocument(doc);
5592 } 6465 }
5593 this.documents[url] = doc; 6466 this.documents[url] = doc;
5594 } 6467 }
5595 elt.import = doc; 6468 elt.__doc = doc;
5596 } 6469 }
5597 parser.parseNext(); 6470 parser.parseNext();
5598 }, 6471 },
5599 bootDocument: function(doc) { 6472 bootDocument: function(doc) {
5600 this.loadSubtree(doc); 6473 this.loadSubtree(doc);
5601 this.observer.observe(doc); 6474 this.observer.observe(doc);
5602 parser.parseNext(); 6475 parser.parseNext();
5603 }, 6476 },
5604 loadedAll: function() { 6477 loadedAll: function() {
5605 parser.parseNext(); 6478 parser.parseNext();
5606 } 6479 }
5607 }; 6480 };
5608 var importLoader = new Loader(importer.loaded.bind(importer), importer.loadedA ll.bind(importer)); 6481 var importLoader = new Loader(importer.loaded.bind(importer), importer.loadedA ll.bind(importer));
5609 importer.observer = new Observer(); 6482 importer.observer = new Observer();
5610 function isImportLink(elt) { 6483 function isImportLink(elt) {
5611 return isLinkRel(elt, IMPORT_LINK_TYPE); 6484 return isLinkRel(elt, IMPORT_LINK_TYPE);
5612 } 6485 }
5613 function isLinkRel(elt, rel) { 6486 function isLinkRel(elt, rel) {
5614 return elt.localName === "link" && elt.getAttribute("rel") === rel; 6487 return elt.localName === "link" && elt.getAttribute("rel") === rel;
5615 } 6488 }
6489 function hasBaseURIAccessor(doc) {
6490 return !!Object.getOwnPropertyDescriptor(doc, "baseURI");
6491 }
5616 function makeDocument(resource, url) { 6492 function makeDocument(resource, url) {
5617 var doc = document.implementation.createHTMLDocument(IMPORT_LINK_TYPE); 6493 var doc = document.implementation.createHTMLDocument(IMPORT_LINK_TYPE);
5618 doc._URL = url; 6494 doc._URL = url;
5619 var base = doc.createElement("base"); 6495 var base = doc.createElement("base");
5620 base.setAttribute("href", url); 6496 base.setAttribute("href", url);
5621 if (!doc.baseURI) { 6497 if (!doc.baseURI && !hasBaseURIAccessor(doc)) {
5622 doc.baseURI = url; 6498 Object.defineProperty(doc, "baseURI", {
6499 value: url
6500 });
5623 } 6501 }
5624 var meta = doc.createElement("meta"); 6502 var meta = doc.createElement("meta");
5625 meta.setAttribute("charset", "utf-8"); 6503 meta.setAttribute("charset", "utf-8");
5626 doc.head.appendChild(meta); 6504 doc.head.appendChild(meta);
5627 doc.head.appendChild(base); 6505 doc.head.appendChild(base);
5628 doc.body.innerHTML = resource; 6506 doc.body.innerHTML = resource;
5629 if (window.HTMLTemplateElement && HTMLTemplateElement.bootstrap) { 6507 if (window.HTMLTemplateElement && HTMLTemplateElement.bootstrap) {
5630 HTMLTemplateElement.bootstrap(doc); 6508 HTMLTemplateElement.bootstrap(doc);
5631 } 6509 }
5632 return doc; 6510 return doc;
5633 } 6511 }
5634 if (!document.baseURI) { 6512 if (!document.baseURI) {
5635 var baseURIDescriptor = { 6513 var baseURIDescriptor = {
5636 get: function() { 6514 get: function() {
5637 var base = document.querySelector("base"); 6515 var base = document.querySelector("base");
5638 return base ? base.href : window.location.href; 6516 return base ? base.href : window.location.href;
5639 }, 6517 },
5640 configurable: true 6518 configurable: true
5641 }; 6519 };
5642 Object.defineProperty(document, "baseURI", baseURIDescriptor); 6520 Object.defineProperty(document, "baseURI", baseURIDescriptor);
5643 Object.defineProperty(rootDocument, "baseURI", baseURIDescriptor); 6521 Object.defineProperty(rootDocument, "baseURI", baseURIDescriptor);
5644 } 6522 }
5645 scope.importer = importer; 6523 scope.importer = importer;
5646 scope.importLoader = importLoader; 6524 scope.importLoader = importLoader;
5647 }); 6525 });
5648 6526
5649 HTMLImports.addModule(function(scope) { 6527 window.HTMLImports.addModule(function(scope) {
5650 var parser = scope.parser; 6528 var parser = scope.parser;
5651 var importer = scope.importer; 6529 var importer = scope.importer;
5652 var dynamic = { 6530 var dynamic = {
5653 added: function(nodes) { 6531 added: function(nodes) {
5654 var owner, parsed; 6532 var owner, parsed, loading;
5655 for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) { 6533 for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
5656 if (!owner) { 6534 if (!owner) {
5657 owner = n.ownerDocument; 6535 owner = n.ownerDocument;
5658 parsed = parser.isParsed(owner); 6536 parsed = parser.isParsed(owner);
5659 } 6537 }
5660 loading = this.shouldLoadNode(n); 6538 loading = this.shouldLoadNode(n);
5661 if (loading) { 6539 if (loading) {
5662 importer.loadNode(n); 6540 importer.loadNode(n);
5663 } 6541 }
5664 if (this.shouldParseNode(n) && parsed) { 6542 if (this.shouldParseNode(n) && parsed) {
5665 parser.parseDynamic(n, loading); 6543 parser.parseDynamic(n, loading);
5666 } 6544 }
5667 } 6545 }
5668 }, 6546 },
5669 shouldLoadNode: function(node) { 6547 shouldLoadNode: function(node) {
5670 return node.nodeType === 1 && matches.call(node, importer.loadSelectorsFor Node(node)); 6548 return node.nodeType === 1 && matches.call(node, importer.loadSelectorsFor Node(node));
5671 }, 6549 },
5672 shouldParseNode: function(node) { 6550 shouldParseNode: function(node) {
5673 return node.nodeType === 1 && matches.call(node, parser.parseSelectorsForN ode(node)); 6551 return node.nodeType === 1 && matches.call(node, parser.parseSelectorsForN ode(node));
5674 } 6552 }
5675 }; 6553 };
5676 importer.observer.addCallback = dynamic.added.bind(dynamic); 6554 importer.observer.addCallback = dynamic.added.bind(dynamic);
5677 var matches = HTMLElement.prototype.matches || HTMLElement.prototype.matchesSe lector || HTMLElement.prototype.webkitMatchesSelector || HTMLElement.prototype.m ozMatchesSelector || HTMLElement.prototype.msMatchesSelector; 6555 var matches = HTMLElement.prototype.matches || HTMLElement.prototype.matchesSe lector || HTMLElement.prototype.webkitMatchesSelector || HTMLElement.prototype.m ozMatchesSelector || HTMLElement.prototype.msMatchesSelector;
5678 }); 6556 });
5679 6557
5680 (function(scope) { 6558 (function(scope) {
5681 initializeModules = scope.initializeModules; 6559 var initializeModules = scope.initializeModules;
6560 var isIE = scope.isIE;
5682 if (scope.useNative) { 6561 if (scope.useNative) {
5683 return; 6562 return;
5684 } 6563 }
5685 if (typeof window.CustomEvent !== "function") {
5686 window.CustomEvent = function(inType, dictionary) {
5687 var e = document.createEvent("HTMLEvents");
5688 e.initEvent(inType, dictionary.bubbles === false ? false : true, dictionar y.cancelable === false ? false : true, dictionary.detail);
5689 return e;
5690 };
5691 }
5692 initializeModules(); 6564 initializeModules();
5693 var rootDocument = scope.rootDocument; 6565 var rootDocument = scope.rootDocument;
5694 function bootstrap() { 6566 function bootstrap() {
5695 HTMLImports.importer.bootDocument(rootDocument); 6567 window.HTMLImports.importer.bootDocument(rootDocument);
5696 } 6568 }
5697 if (document.readyState === "complete" || document.readyState === "interactive " && !window.attachEvent) { 6569 if (document.readyState === "complete" || document.readyState === "interactive " && !window.attachEvent) {
5698 bootstrap(); 6570 bootstrap();
5699 } else { 6571 } else {
5700 document.addEventListener("DOMContentLoaded", bootstrap); 6572 document.addEventListener("DOMContentLoaded", bootstrap);
5701 } 6573 }
5702 })(HTMLImports); 6574 })(window.HTMLImports);
5703 6575
5704 window.CustomElements = window.CustomElements || { 6576 window.CustomElements = window.CustomElements || {
5705 flags: {} 6577 flags: {}
5706 }; 6578 };
5707 6579
5708 (function(scope) { 6580 (function(scope) {
5709 var flags = scope.flags; 6581 var flags = scope.flags;
5710 var modules = []; 6582 var modules = [];
5711 var addModule = function(module) { 6583 var addModule = function(module) {
5712 modules.push(module); 6584 modules.push(module);
5713 }; 6585 };
5714 var initializeModules = function() { 6586 var initializeModules = function() {
5715 modules.forEach(function(module) { 6587 modules.forEach(function(module) {
5716 module(scope); 6588 module(scope);
5717 }); 6589 });
5718 }; 6590 };
5719 scope.addModule = addModule; 6591 scope.addModule = addModule;
5720 scope.initializeModules = initializeModules; 6592 scope.initializeModules = initializeModules;
5721 scope.hasNative = Boolean(document.registerElement); 6593 scope.hasNative = Boolean(document.registerElement);
5722 scope.useNative = !flags.register && scope.hasNative && !window.ShadowDOMPolyf ill && (!window.HTMLImports || HTMLImports.useNative); 6594 scope.isIE = /Trident/.test(navigator.userAgent);
5723 })(CustomElements); 6595 scope.useNative = !flags.register && scope.hasNative && !window.ShadowDOMPolyf ill && (!window.HTMLImports || window.HTMLImports.useNative);
6596 })(window.CustomElements);
5724 6597
5725 CustomElements.addModule(function(scope) { 6598 window.CustomElements.addModule(function(scope) {
5726 var IMPORT_LINK_TYPE = window.HTMLImports ? HTMLImports.IMPORT_LINK_TYPE : "no ne"; 6599 var IMPORT_LINK_TYPE = window.HTMLImports ? window.HTMLImports.IMPORT_LINK_TYP E : "none";
5727 function forSubtree(node, cb) { 6600 function forSubtree(node, cb) {
5728 findAllElements(node, function(e) { 6601 findAllElements(node, function(e) {
5729 if (cb(e)) { 6602 if (cb(e)) {
5730 return true; 6603 return true;
5731 } 6604 }
5732 forRoots(e, cb); 6605 forRoots(e, cb);
5733 }); 6606 });
5734 forRoots(node, cb); 6607 forRoots(node, cb);
5735 } 6608 }
5736 function findAllElements(node, find, data) { 6609 function findAllElements(node, find, data) {
(...skipping 12 matching lines...) Expand all
5749 } 6622 }
5750 return null; 6623 return null;
5751 } 6624 }
5752 function forRoots(node, cb) { 6625 function forRoots(node, cb) {
5753 var root = node.shadowRoot; 6626 var root = node.shadowRoot;
5754 while (root) { 6627 while (root) {
5755 forSubtree(root, cb); 6628 forSubtree(root, cb);
5756 root = root.olderShadowRoot; 6629 root = root.olderShadowRoot;
5757 } 6630 }
5758 } 6631 }
5759 var processingDocuments;
5760 function forDocumentTree(doc, cb) { 6632 function forDocumentTree(doc, cb) {
5761 processingDocuments = []; 6633 _forDocumentTree(doc, cb, []);
5762 _forDocumentTree(doc, cb);
5763 processingDocuments = null;
5764 } 6634 }
5765 function _forDocumentTree(doc, cb) { 6635 function _forDocumentTree(doc, cb, processingDocuments) {
5766 doc = wrap(doc); 6636 doc = window.wrap(doc);
5767 if (processingDocuments.indexOf(doc) >= 0) { 6637 if (processingDocuments.indexOf(doc) >= 0) {
5768 return; 6638 return;
5769 } 6639 }
5770 processingDocuments.push(doc); 6640 processingDocuments.push(doc);
5771 var imports = doc.querySelectorAll("link[rel=" + IMPORT_LINK_TYPE + "]"); 6641 var imports = doc.querySelectorAll("link[rel=" + IMPORT_LINK_TYPE + "]");
5772 for (var i = 0, l = imports.length, n; i < l && (n = imports[i]); i++) { 6642 for (var i = 0, l = imports.length, n; i < l && (n = imports[i]); i++) {
5773 if (n.import) { 6643 if (n.import) {
5774 _forDocumentTree(n.import, cb); 6644 _forDocumentTree(n.import, cb, processingDocuments);
5775 } 6645 }
5776 } 6646 }
5777 cb(doc); 6647 cb(doc);
5778 } 6648 }
5779 scope.forDocumentTree = forDocumentTree; 6649 scope.forDocumentTree = forDocumentTree;
5780 scope.forSubtree = forSubtree; 6650 scope.forSubtree = forSubtree;
5781 }); 6651 });
5782 6652
5783 CustomElements.addModule(function(scope) { 6653 window.CustomElements.addModule(function(scope) {
5784 var flags = scope.flags; 6654 var flags = scope.flags;
5785 var forSubtree = scope.forSubtree; 6655 var forSubtree = scope.forSubtree;
5786 var forDocumentTree = scope.forDocumentTree; 6656 var forDocumentTree = scope.forDocumentTree;
5787 function addedNode(node) { 6657 function addedNode(node, isAttached) {
5788 return added(node) || addedSubtree(node); 6658 return added(node, isAttached) || addedSubtree(node, isAttached);
5789 } 6659 }
5790 function added(node) { 6660 function added(node, isAttached) {
5791 if (scope.upgrade(node)) { 6661 if (scope.upgrade(node, isAttached)) {
5792 return true; 6662 return true;
5793 } 6663 }
5794 attached(node); 6664 if (isAttached) {
6665 attached(node);
6666 }
5795 } 6667 }
5796 function addedSubtree(node) { 6668 function addedSubtree(node, isAttached) {
5797 forSubtree(node, function(e) { 6669 forSubtree(node, function(e) {
5798 if (added(e)) { 6670 if (added(e, isAttached)) {
5799 return true; 6671 return true;
5800 } 6672 }
5801 }); 6673 });
5802 } 6674 }
5803 function attachedNode(node) { 6675 var hasThrottledAttached = window.MutationObserver._isPolyfilled && flags["thr ottle-attached"];
5804 attached(node); 6676 scope.hasPolyfillMutations = hasThrottledAttached;
5805 if (inDocument(node)) { 6677 scope.hasThrottledAttached = hasThrottledAttached;
5806 forSubtree(node, function(e) {
5807 attached(e);
5808 });
5809 }
5810 }
5811 var hasPolyfillMutations = !window.MutationObserver || window.MutationObserver === window.JsMutationObserver;
5812 scope.hasPolyfillMutations = hasPolyfillMutations;
5813 var isPendingMutations = false; 6678 var isPendingMutations = false;
5814 var pendingMutations = []; 6679 var pendingMutations = [];
5815 function deferMutation(fn) { 6680 function deferMutation(fn) {
5816 pendingMutations.push(fn); 6681 pendingMutations.push(fn);
5817 if (!isPendingMutations) { 6682 if (!isPendingMutations) {
5818 isPendingMutations = true; 6683 isPendingMutations = true;
5819 setTimeout(takeMutations); 6684 setTimeout(takeMutations);
5820 } 6685 }
5821 } 6686 }
5822 function takeMutations() { 6687 function takeMutations() {
5823 isPendingMutations = false; 6688 isPendingMutations = false;
5824 var $p = pendingMutations; 6689 var $p = pendingMutations;
5825 for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) { 6690 for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) {
5826 p(); 6691 p();
5827 } 6692 }
5828 pendingMutations = []; 6693 pendingMutations = [];
5829 } 6694 }
5830 function attached(element) { 6695 function attached(element) {
5831 if (hasPolyfillMutations) { 6696 if (hasThrottledAttached) {
5832 deferMutation(function() { 6697 deferMutation(function() {
5833 _attached(element); 6698 _attached(element);
5834 }); 6699 });
5835 } else { 6700 } else {
5836 _attached(element); 6701 _attached(element);
5837 } 6702 }
5838 } 6703 }
5839 function _attached(element) { 6704 function _attached(element) {
5840 if (element.__upgraded__ && (element.attachedCallback || element.detachedCal lback)) { 6705 if (element.__upgraded__ && !element.__attached) {
5841 if (!element.__attached && inDocument(element)) { 6706 element.__attached = true;
5842 element.__attached = true; 6707 if (element.attachedCallback) {
5843 if (element.attachedCallback) { 6708 element.attachedCallback();
5844 element.attachedCallback();
5845 }
5846 } 6709 }
5847 } 6710 }
5848 } 6711 }
5849 function detachedNode(node) { 6712 function detachedNode(node) {
5850 detached(node); 6713 detached(node);
5851 forSubtree(node, function(e) { 6714 forSubtree(node, function(e) {
5852 detached(e); 6715 detached(e);
5853 }); 6716 });
5854 } 6717 }
5855 function detached(element) { 6718 function detached(element) {
5856 if (hasPolyfillMutations) { 6719 if (hasThrottledAttached) {
5857 deferMutation(function() { 6720 deferMutation(function() {
5858 _detached(element); 6721 _detached(element);
5859 }); 6722 });
5860 } else { 6723 } else {
5861 _detached(element); 6724 _detached(element);
5862 } 6725 }
5863 } 6726 }
5864 function _detached(element) { 6727 function _detached(element) {
5865 if (element.__upgraded__ && (element.attachedCallback || element.detachedCal lback)) { 6728 if (element.__upgraded__ && element.__attached) {
5866 if (element.__attached && !inDocument(element)) { 6729 element.__attached = false;
5867 element.__attached = false; 6730 if (element.detachedCallback) {
5868 if (element.detachedCallback) { 6731 element.detachedCallback();
5869 element.detachedCallback();
5870 }
5871 } 6732 }
5872 } 6733 }
5873 } 6734 }
5874 function inDocument(element) { 6735 function inDocument(element) {
5875 var p = element; 6736 var p = element;
5876 var doc = wrap(document); 6737 var doc = window.wrap(document);
5877 while (p) { 6738 while (p) {
5878 if (p == doc) { 6739 if (p == doc) {
5879 return true; 6740 return true;
5880 } 6741 }
5881 p = p.parentNode || p.host; 6742 p = p.parentNode || p.nodeType === Node.DOCUMENT_FRAGMENT_NODE && p.host;
5882 } 6743 }
5883 } 6744 }
5884 function watchShadow(node) { 6745 function watchShadow(node) {
5885 if (node.shadowRoot && !node.shadowRoot.__watched) { 6746 if (node.shadowRoot && !node.shadowRoot.__watched) {
5886 flags.dom && console.log("watching shadow-root for: ", node.localName); 6747 flags.dom && console.log("watching shadow-root for: ", node.localName);
5887 var root = node.shadowRoot; 6748 var root = node.shadowRoot;
5888 while (root) { 6749 while (root) {
5889 observe(root); 6750 observe(root);
5890 root = root.olderShadowRoot; 6751 root = root.olderShadowRoot;
5891 } 6752 }
5892 } 6753 }
5893 } 6754 }
5894 function handler(mutations) { 6755 function handler(root, mutations) {
5895 if (flags.dom) { 6756 if (flags.dom) {
5896 var mx = mutations[0]; 6757 var mx = mutations[0];
5897 if (mx && mx.type === "childList" && mx.addedNodes) { 6758 if (mx && mx.type === "childList" && mx.addedNodes) {
5898 if (mx.addedNodes) { 6759 if (mx.addedNodes) {
5899 var d = mx.addedNodes[0]; 6760 var d = mx.addedNodes[0];
5900 while (d && d !== document && !d.host) { 6761 while (d && d !== document && !d.host) {
5901 d = d.parentNode; 6762 d = d.parentNode;
5902 } 6763 }
5903 var u = d && (d.URL || d._URL || d.host && d.host.localName) || ""; 6764 var u = d && (d.URL || d._URL || d.host && d.host.localName) || "";
5904 u = u.split("/?").shift().split("/").pop(); 6765 u = u.split("/?").shift().split("/").pop();
5905 } 6766 }
5906 } 6767 }
5907 console.group("mutations (%d) [%s]", mutations.length, u || ""); 6768 console.group("mutations (%d) [%s]", mutations.length, u || "");
5908 } 6769 }
6770 var isAttached = inDocument(root);
5909 mutations.forEach(function(mx) { 6771 mutations.forEach(function(mx) {
5910 if (mx.type === "childList") { 6772 if (mx.type === "childList") {
5911 forEach(mx.addedNodes, function(n) { 6773 forEach(mx.addedNodes, function(n) {
5912 if (!n.localName) { 6774 if (!n.localName) {
5913 return; 6775 return;
5914 } 6776 }
5915 addedNode(n); 6777 addedNode(n, isAttached);
5916 }); 6778 });
5917 forEach(mx.removedNodes, function(n) { 6779 forEach(mx.removedNodes, function(n) {
5918 if (!n.localName) { 6780 if (!n.localName) {
5919 return; 6781 return;
5920 } 6782 }
5921 detachedNode(n); 6783 detachedNode(n);
5922 }); 6784 });
5923 } 6785 }
5924 }); 6786 });
5925 flags.dom && console.groupEnd(); 6787 flags.dom && console.groupEnd();
5926 } 6788 }
5927 function takeRecords(node) { 6789 function takeRecords(node) {
5928 node = wrap(node); 6790 node = window.wrap(node);
5929 if (!node) { 6791 if (!node) {
5930 node = wrap(document); 6792 node = window.wrap(document);
5931 } 6793 }
5932 while (node.parentNode) { 6794 while (node.parentNode) {
5933 node = node.parentNode; 6795 node = node.parentNode;
5934 } 6796 }
5935 var observer = node.__observer; 6797 var observer = node.__observer;
5936 if (observer) { 6798 if (observer) {
5937 handler(observer.takeRecords()); 6799 handler(node, observer.takeRecords());
5938 takeMutations(); 6800 takeMutations();
5939 } 6801 }
5940 } 6802 }
5941 var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach); 6803 var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach);
5942 function observe(inRoot) { 6804 function observe(inRoot) {
5943 if (inRoot.__observer) { 6805 if (inRoot.__observer) {
5944 return; 6806 return;
5945 } 6807 }
5946 var observer = new MutationObserver(handler); 6808 var observer = new MutationObserver(handler.bind(this, inRoot));
5947 observer.observe(inRoot, { 6809 observer.observe(inRoot, {
5948 childList: true, 6810 childList: true,
5949 subtree: true 6811 subtree: true
5950 }); 6812 });
5951 inRoot.__observer = observer; 6813 inRoot.__observer = observer;
5952 } 6814 }
5953 function upgradeDocument(doc) { 6815 function upgradeDocument(doc) {
5954 doc = wrap(doc); 6816 doc = window.wrap(doc);
5955 flags.dom && console.group("upgradeDocument: ", doc.baseURI.split("/").pop() ); 6817 flags.dom && console.group("upgradeDocument: ", doc.baseURI.split("/").pop() );
5956 addedNode(doc); 6818 var isMainDocument = doc === window.wrap(document);
6819 addedNode(doc, isMainDocument);
5957 observe(doc); 6820 observe(doc);
5958 flags.dom && console.groupEnd(); 6821 flags.dom && console.groupEnd();
5959 } 6822 }
5960 function upgradeDocumentTree(doc) { 6823 function upgradeDocumentTree(doc) {
5961 forDocumentTree(doc, upgradeDocument); 6824 forDocumentTree(doc, upgradeDocument);
5962 } 6825 }
5963 var originalCreateShadowRoot = Element.prototype.createShadowRoot; 6826 var originalCreateShadowRoot = Element.prototype.createShadowRoot;
5964 Element.prototype.createShadowRoot = function() { 6827 if (originalCreateShadowRoot) {
5965 var root = originalCreateShadowRoot.call(this); 6828 Element.prototype.createShadowRoot = function() {
5966 CustomElements.watchShadow(this); 6829 var root = originalCreateShadowRoot.call(this);
5967 return root; 6830 window.CustomElements.watchShadow(this);
5968 }; 6831 return root;
6832 };
6833 }
5969 scope.watchShadow = watchShadow; 6834 scope.watchShadow = watchShadow;
5970 scope.upgradeDocumentTree = upgradeDocumentTree; 6835 scope.upgradeDocumentTree = upgradeDocumentTree;
6836 scope.upgradeDocument = upgradeDocument;
5971 scope.upgradeSubtree = addedSubtree; 6837 scope.upgradeSubtree = addedSubtree;
5972 scope.upgradeAll = addedNode; 6838 scope.upgradeAll = addedNode;
5973 scope.attachedNode = attachedNode; 6839 scope.attached = attached;
5974 scope.takeRecords = takeRecords; 6840 scope.takeRecords = takeRecords;
5975 }); 6841 });
5976 6842
5977 CustomElements.addModule(function(scope) { 6843 window.CustomElements.addModule(function(scope) {
5978 var flags = scope.flags; 6844 var flags = scope.flags;
5979 function upgrade(node) { 6845 function upgrade(node, isAttached) {
6846 if (node.localName === "template") {
6847 if (window.HTMLTemplateElement && HTMLTemplateElement.decorate) {
6848 HTMLTemplateElement.decorate(node);
6849 }
6850 }
5980 if (!node.__upgraded__ && node.nodeType === Node.ELEMENT_NODE) { 6851 if (!node.__upgraded__ && node.nodeType === Node.ELEMENT_NODE) {
5981 var is = node.getAttribute("is"); 6852 var is = node.getAttribute("is");
5982 var definition = scope.getRegisteredDefinition(is || node.localName); 6853 var definition = scope.getRegisteredDefinition(node.localName) || scope.ge tRegisteredDefinition(is);
5983 if (definition) { 6854 if (definition) {
5984 if (is && definition.tag == node.localName) { 6855 if (is && definition.tag == node.localName || !is && !definition.extends ) {
5985 return upgradeWithDefinition(node, definition); 6856 return upgradeWithDefinition(node, definition, isAttached);
5986 } else if (!is && !definition.extends) {
5987 return upgradeWithDefinition(node, definition);
5988 } 6857 }
5989 } 6858 }
5990 } 6859 }
5991 } 6860 }
5992 function upgradeWithDefinition(element, definition) { 6861 function upgradeWithDefinition(element, definition, isAttached) {
5993 flags.upgrade && console.group("upgrade:", element.localName); 6862 flags.upgrade && console.group("upgrade:", element.localName);
5994 if (definition.is) { 6863 if (definition.is) {
5995 element.setAttribute("is", definition.is); 6864 element.setAttribute("is", definition.is);
5996 } 6865 }
5997 implementPrototype(element, definition); 6866 implementPrototype(element, definition);
5998 element.__upgraded__ = true; 6867 element.__upgraded__ = true;
5999 created(element); 6868 created(element);
6000 scope.attachedNode(element); 6869 if (isAttached) {
6001 scope.upgradeSubtree(element); 6870 scope.attached(element);
6871 }
6872 scope.upgradeSubtree(element, isAttached);
6002 flags.upgrade && console.groupEnd(); 6873 flags.upgrade && console.groupEnd();
6003 return element; 6874 return element;
6004 } 6875 }
6005 function implementPrototype(element, definition) { 6876 function implementPrototype(element, definition) {
6006 if (Object.__proto__) { 6877 if (Object.__proto__) {
6007 element.__proto__ = definition.prototype; 6878 element.__proto__ = definition.prototype;
6008 } else { 6879 } else {
6009 customMixin(element, definition.prototype, definition.native); 6880 customMixin(element, definition.prototype, definition.native);
6010 element.__proto__ = definition.prototype; 6881 element.__proto__ = definition.prototype;
6011 } 6882 }
(...skipping 15 matching lines...) Expand all
6027 function created(element) { 6898 function created(element) {
6028 if (element.createdCallback) { 6899 if (element.createdCallback) {
6029 element.createdCallback(); 6900 element.createdCallback();
6030 } 6901 }
6031 } 6902 }
6032 scope.upgrade = upgrade; 6903 scope.upgrade = upgrade;
6033 scope.upgradeWithDefinition = upgradeWithDefinition; 6904 scope.upgradeWithDefinition = upgradeWithDefinition;
6034 scope.implementPrototype = implementPrototype; 6905 scope.implementPrototype = implementPrototype;
6035 }); 6906 });
6036 6907
6037 CustomElements.addModule(function(scope) { 6908 window.CustomElements.addModule(function(scope) {
6909 var isIE = scope.isIE;
6038 var upgradeDocumentTree = scope.upgradeDocumentTree; 6910 var upgradeDocumentTree = scope.upgradeDocumentTree;
6039 var upgrade = scope.upgrade; 6911 var upgradeAll = scope.upgradeAll;
6040 var upgradeWithDefinition = scope.upgradeWithDefinition; 6912 var upgradeWithDefinition = scope.upgradeWithDefinition;
6041 var implementPrototype = scope.implementPrototype; 6913 var implementPrototype = scope.implementPrototype;
6042 var useNative = scope.useNative; 6914 var useNative = scope.useNative;
6043 function register(name, options) { 6915 function register(name, options) {
6044 var definition = options || {}; 6916 var definition = options || {};
6045 if (!name) { 6917 if (!name) {
6046 throw new Error("document.registerElement: first argument `name` must not be empty"); 6918 throw new Error("document.registerElement: first argument `name` must not be empty");
6047 } 6919 }
6048 if (name.indexOf("-") < 0) { 6920 if (name.indexOf("-") < 0) {
6049 throw new Error("document.registerElement: first argument ('name') must co ntain a dash ('-'). Argument provided was '" + String(name) + "'."); 6921 throw new Error("document.registerElement: first argument ('name') must co ntain a dash ('-'). Argument provided was '" + String(name) + "'.");
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
6118 definition.tag = baseTag || definition.__name; 6990 definition.tag = baseTag || definition.__name;
6119 if (baseTag) { 6991 if (baseTag) {
6120 definition.is = definition.__name; 6992 definition.is = definition.__name;
6121 } 6993 }
6122 } 6994 }
6123 function resolvePrototypeChain(definition) { 6995 function resolvePrototypeChain(definition) {
6124 if (!Object.__proto__) { 6996 if (!Object.__proto__) {
6125 var nativePrototype = HTMLElement.prototype; 6997 var nativePrototype = HTMLElement.prototype;
6126 if (definition.is) { 6998 if (definition.is) {
6127 var inst = document.createElement(definition.tag); 6999 var inst = document.createElement(definition.tag);
6128 var expectedPrototype = Object.getPrototypeOf(inst); 7000 nativePrototype = Object.getPrototypeOf(inst);
6129 if (expectedPrototype === definition.prototype) {
6130 nativePrototype = expectedPrototype;
6131 }
6132 } 7001 }
6133 var proto = definition.prototype, ancestor; 7002 var proto = definition.prototype, ancestor;
6134 while (proto && proto !== nativePrototype) { 7003 var foundPrototype = false;
7004 while (proto) {
7005 if (proto == nativePrototype) {
7006 foundPrototype = true;
7007 }
6135 ancestor = Object.getPrototypeOf(proto); 7008 ancestor = Object.getPrototypeOf(proto);
6136 proto.__proto__ = ancestor; 7009 if (ancestor) {
7010 proto.__proto__ = ancestor;
7011 }
6137 proto = ancestor; 7012 proto = ancestor;
6138 } 7013 }
7014 if (!foundPrototype) {
7015 console.warn(definition.tag + " prototype not found in prototype chain f or " + definition.is);
7016 }
6139 definition.native = nativePrototype; 7017 definition.native = nativePrototype;
6140 } 7018 }
6141 } 7019 }
6142 function instantiate(definition) { 7020 function instantiate(definition) {
6143 return upgradeWithDefinition(domCreateElement(definition.tag), definition); 7021 return upgradeWithDefinition(domCreateElement(definition.tag), definition);
6144 } 7022 }
6145 var registry = {}; 7023 var registry = {};
6146 function getRegisteredDefinition(name) { 7024 function getRegisteredDefinition(name) {
6147 if (name) { 7025 if (name) {
6148 return registry[name.toLowerCase()]; 7026 return registry[name.toLowerCase()];
6149 } 7027 }
6150 } 7028 }
6151 function registerDefinition(name, definition) { 7029 function registerDefinition(name, definition) {
6152 registry[name] = definition; 7030 registry[name] = definition;
6153 } 7031 }
6154 function generateConstructor(definition) { 7032 function generateConstructor(definition) {
6155 return function() { 7033 return function() {
6156 return instantiate(definition); 7034 return instantiate(definition);
6157 }; 7035 };
6158 } 7036 }
6159 var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml"; 7037 var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
6160 function createElementNS(namespace, tag, typeExtension) { 7038 function createElementNS(namespace, tag, typeExtension) {
6161 if (namespace === HTML_NAMESPACE) { 7039 if (namespace === HTML_NAMESPACE) {
6162 return createElement(tag, typeExtension); 7040 return createElement(tag, typeExtension);
6163 } else { 7041 } else {
6164 return domCreateElementNS(namespace, tag); 7042 return domCreateElementNS(namespace, tag);
6165 } 7043 }
6166 } 7044 }
6167 function createElement(tag, typeExtension) { 7045 function createElement(tag, typeExtension) {
7046 if (tag) {
7047 tag = tag.toLowerCase();
7048 }
7049 if (typeExtension) {
7050 typeExtension = typeExtension.toLowerCase();
7051 }
6168 var definition = getRegisteredDefinition(typeExtension || tag); 7052 var definition = getRegisteredDefinition(typeExtension || tag);
6169 if (definition) { 7053 if (definition) {
6170 if (tag == definition.tag && typeExtension == definition.is) { 7054 if (tag == definition.tag && typeExtension == definition.is) {
6171 return new definition.ctor(); 7055 return new definition.ctor();
6172 } 7056 }
6173 if (!typeExtension && !definition.is) { 7057 if (!typeExtension && !definition.is) {
6174 return new definition.ctor(); 7058 return new definition.ctor();
6175 } 7059 }
6176 } 7060 }
6177 var element; 7061 var element;
6178 if (typeExtension) { 7062 if (typeExtension) {
6179 element = createElement(tag); 7063 element = createElement(tag);
6180 element.setAttribute("is", typeExtension); 7064 element.setAttribute("is", typeExtension);
6181 return element; 7065 return element;
6182 } 7066 }
6183 element = domCreateElement(tag); 7067 element = domCreateElement(tag);
6184 if (tag.indexOf("-") >= 0) { 7068 if (tag.indexOf("-") >= 0) {
6185 implementPrototype(element, HTMLElement); 7069 implementPrototype(element, HTMLElement);
6186 } 7070 }
6187 return element; 7071 return element;
6188 } 7072 }
6189 function cloneNode(deep) {
6190 var n = domCloneNode.call(this, deep);
6191 upgrade(n);
6192 return n;
6193 }
6194 var domCreateElement = document.createElement.bind(document); 7073 var domCreateElement = document.createElement.bind(document);
6195 var domCreateElementNS = document.createElementNS.bind(document); 7074 var domCreateElementNS = document.createElementNS.bind(document);
6196 var domCloneNode = Node.prototype.cloneNode;
6197 var isInstance; 7075 var isInstance;
6198 if (!Object.__proto__ && !useNative) { 7076 if (!Object.__proto__ && !useNative) {
6199 isInstance = function(obj, ctor) { 7077 isInstance = function(obj, ctor) {
7078 if (obj instanceof ctor) {
7079 return true;
7080 }
6200 var p = obj; 7081 var p = obj;
6201 while (p) { 7082 while (p) {
6202 if (p === ctor.prototype) { 7083 if (p === ctor.prototype) {
6203 return true; 7084 return true;
6204 } 7085 }
6205 p = p.__proto__; 7086 p = p.__proto__;
6206 } 7087 }
6207 return false; 7088 return false;
6208 }; 7089 };
6209 } else { 7090 } else {
6210 isInstance = function(obj, base) { 7091 isInstance = function(obj, base) {
6211 return obj instanceof base; 7092 return obj instanceof base;
6212 }; 7093 };
6213 } 7094 }
7095 function wrapDomMethodToForceUpgrade(obj, methodName) {
7096 var orig = obj[methodName];
7097 obj[methodName] = function() {
7098 var n = orig.apply(this, arguments);
7099 upgradeAll(n);
7100 return n;
7101 };
7102 }
7103 wrapDomMethodToForceUpgrade(Node.prototype, "cloneNode");
7104 wrapDomMethodToForceUpgrade(document, "importNode");
7105 if (isIE) {
7106 (function() {
7107 var importNode = document.importNode;
7108 document.importNode = function() {
7109 var n = importNode.apply(document, arguments);
7110 if (n.nodeType == n.DOCUMENT_FRAGMENT_NODE) {
7111 var f = document.createDocumentFragment();
7112 f.appendChild(n);
7113 return f;
7114 } else {
7115 return n;
7116 }
7117 };
7118 })();
7119 }
6214 document.registerElement = register; 7120 document.registerElement = register;
6215 document.createElement = createElement; 7121 document.createElement = createElement;
6216 document.createElementNS = createElementNS; 7122 document.createElementNS = createElementNS;
6217 Node.prototype.cloneNode = cloneNode;
6218 scope.registry = registry; 7123 scope.registry = registry;
6219 scope.instanceof = isInstance; 7124 scope.instanceof = isInstance;
6220 scope.reservedTagList = reservedTagList; 7125 scope.reservedTagList = reservedTagList;
6221 scope.getRegisteredDefinition = getRegisteredDefinition; 7126 scope.getRegisteredDefinition = getRegisteredDefinition;
6222 document.register = document.registerElement; 7127 document.register = document.registerElement;
6223 }); 7128 });
6224 7129
6225 (function(scope) { 7130 (function(scope) {
6226 var useNative = scope.useNative; 7131 var useNative = scope.useNative;
6227 var initializeModules = scope.initializeModules; 7132 var initializeModules = scope.initializeModules;
7133 var isIE = scope.isIE;
6228 if (useNative) { 7134 if (useNative) {
6229 var nop = function() {}; 7135 var nop = function() {};
6230 scope.watchShadow = nop; 7136 scope.watchShadow = nop;
6231 scope.upgrade = nop; 7137 scope.upgrade = nop;
6232 scope.upgradeAll = nop; 7138 scope.upgradeAll = nop;
6233 scope.upgradeDocumentTree = nop; 7139 scope.upgradeDocumentTree = nop;
6234 scope.upgradeSubtree = nop; 7140 scope.upgradeSubtree = nop;
6235 scope.takeRecords = nop; 7141 scope.takeRecords = nop;
6236 scope.instanceof = function(obj, base) { 7142 scope.instanceof = function(obj, base) {
6237 return obj instanceof base; 7143 return obj instanceof base;
6238 }; 7144 };
6239 } else { 7145 } else {
6240 initializeModules(); 7146 initializeModules();
6241 } 7147 }
6242 var upgradeDocumentTree = scope.upgradeDocumentTree; 7148 var upgradeDocumentTree = scope.upgradeDocumentTree;
7149 var upgradeDocument = scope.upgradeDocument;
6243 if (!window.wrap) { 7150 if (!window.wrap) {
6244 if (window.ShadowDOMPolyfill) { 7151 if (window.ShadowDOMPolyfill) {
6245 window.wrap = ShadowDOMPolyfill.wrapIfNeeded; 7152 window.wrap = window.ShadowDOMPolyfill.wrapIfNeeded;
6246 window.unwrap = ShadowDOMPolyfill.unwrapIfNeeded; 7153 window.unwrap = window.ShadowDOMPolyfill.unwrapIfNeeded;
6247 } else { 7154 } else {
6248 window.wrap = window.unwrap = function(node) { 7155 window.wrap = window.unwrap = function(node) {
6249 return node; 7156 return node;
6250 }; 7157 };
6251 } 7158 }
6252 } 7159 }
7160 if (window.HTMLImports) {
7161 window.HTMLImports.__importsParsingHook = function(elt) {
7162 if (elt.import) {
7163 upgradeDocument(wrap(elt.import));
7164 }
7165 };
7166 }
6253 function bootstrap() { 7167 function bootstrap() {
6254 upgradeDocumentTree(wrap(document)); 7168 upgradeDocumentTree(window.wrap(document));
6255 if (window.HTMLImports) { 7169 window.CustomElements.ready = true;
6256 HTMLImports.__importsParsingHook = function(elt) { 7170 var requestAnimationFrame = window.requestAnimationFrame || function(f) {
6257 upgradeDocumentTree(wrap(elt.import)); 7171 setTimeout(f, 16);
6258 }; 7172 };
6259 } 7173 requestAnimationFrame(function() {
6260 CustomElements.ready = true; 7174 setTimeout(function() {
6261 setTimeout(function() { 7175 window.CustomElements.readyTime = Date.now();
6262 CustomElements.readyTime = Date.now(); 7176 if (window.HTMLImports) {
6263 if (window.HTMLImports) { 7177 window.CustomElements.elapsed = window.CustomElements.readyTime - wind ow.HTMLImports.readyTime;
6264 CustomElements.elapsed = CustomElements.readyTime - HTMLImports.readyTim e; 7178 }
6265 } 7179 document.dispatchEvent(new CustomEvent("WebComponentsReady", {
6266 document.dispatchEvent(new CustomEvent("WebComponentsReady", { 7180 bubbles: true
6267 bubbles: true 7181 }));
6268 })); 7182 });
6269 }); 7183 });
6270 } 7184 }
6271 if (typeof window.CustomEvent !== "function") {
6272 window.CustomEvent = function(inType, params) {
6273 params = params || {};
6274 var e = document.createEvent("CustomEvent");
6275 e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelab le), params.detail);
6276 return e;
6277 };
6278 window.CustomEvent.prototype = window.Event.prototype;
6279 }
6280 if (document.readyState === "complete" || scope.flags.eager) { 7185 if (document.readyState === "complete" || scope.flags.eager) {
6281 bootstrap(); 7186 bootstrap();
6282 } else if (document.readyState === "interactive" && !window.attachEvent && (!w indow.HTMLImports || window.HTMLImports.ready)) { 7187 } else if (document.readyState === "interactive" && !window.attachEvent && (!w indow.HTMLImports || window.HTMLImports.ready)) {
6283 bootstrap(); 7188 bootstrap();
6284 } else { 7189 } else {
6285 var loadEvent = window.HTMLImports && !HTMLImports.ready ? "HTMLImportsLoade d" : "DOMContentLoaded"; 7190 var loadEvent = window.HTMLImports && !window.HTMLImports.ready ? "HTMLImpor tsLoaded" : "DOMContentLoaded";
6286 window.addEventListener(loadEvent, bootstrap); 7191 window.addEventListener(loadEvent, bootstrap);
6287 } 7192 }
6288 })(window.CustomElements); 7193 })(window.CustomElements);
6289 7194
6290 (function(scope) { 7195 (function(scope) {
6291 if (!Function.prototype.bind) { 7196 if (!Function.prototype.bind) {
6292 Function.prototype.bind = function(scope) { 7197 Function.prototype.bind = function(scope) {
6293 var self = this; 7198 var self = this;
6294 var args = Array.prototype.slice.call(arguments, 1); 7199 var args = Array.prototype.slice.call(arguments, 1);
6295 return function() { 7200 return function() {
6296 var args2 = args.slice(); 7201 var args2 = args.slice();
6297 args2.push.apply(args2, arguments); 7202 args2.push.apply(args2, arguments);
6298 return self.apply(scope, args2); 7203 return self.apply(scope, args2);
6299 }; 7204 };
6300 }; 7205 };
6301 } 7206 }
6302 })(window.WebComponents); 7207 })(window.WebComponents);
6303 7208
6304 (function(scope) { 7209 (function(scope) {
6305 "use strict";
6306 if (!window.performance) {
6307 var start = Date.now();
6308 window.performance = {
6309 now: function() {
6310 return Date.now() - start;
6311 }
6312 };
6313 }
6314 if (!window.requestAnimationFrame) {
6315 window.requestAnimationFrame = function() {
6316 var nativeRaf = window.webkitRequestAnimationFrame || window.mozRequestAni mationFrame;
6317 return nativeRaf ? function(callback) {
6318 return nativeRaf(function() {
6319 callback(performance.now());
6320 });
6321 } : function(callback) {
6322 return window.setTimeout(callback, 1e3 / 60);
6323 };
6324 }();
6325 }
6326 if (!window.cancelAnimationFrame) {
6327 window.cancelAnimationFrame = function() {
6328 return window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || function(id) {
6329 clearTimeout(id);
6330 };
6331 }();
6332 }
6333 var elementDeclarations = [];
6334 var polymerStub = function(name, dictionary) {
6335 if (typeof name !== "string" && arguments.length === 1) {
6336 Array.prototype.push.call(arguments, document._currentScript);
6337 }
6338 elementDeclarations.push(arguments);
6339 };
6340 window.Polymer = polymerStub;
6341 scope.consumeDeclarations = function(callback) {
6342 scope.consumeDeclarations = function() {
6343 throw "Possible attempt to load Polymer twice";
6344 };
6345 if (callback) {
6346 callback(elementDeclarations);
6347 }
6348 elementDeclarations = null;
6349 };
6350 function installPolymerWarning() {
6351 if (window.Polymer === polymerStub) {
6352 window.Polymer = function() {
6353 throw new Error("You tried to use polymer without loading it first. To " + 'load polymer, <link rel="import" href="' + 'components/polymer/polymer.html" >');
6354 };
6355 }
6356 }
6357 if (HTMLImports.useNative) {
6358 installPolymerWarning();
6359 } else {
6360 addEventListener("DOMContentLoaded", installPolymerWarning);
6361 }
6362 })(window.WebComponents);
6363
6364 (function(scope) {
6365 var style = document.createElement("style"); 7210 var style = document.createElement("style");
6366 style.textContent = "" + "body {" + "transition: opacity ease-in 0.2s;" + " } \n" + "body[unresolved] {" + "opacity: 0; display: block; overflow: hidden; posi tion: relative;" + " } \n"; 7211 style.textContent = "" + "body {" + "transition: opacity ease-in 0.2s;" + " } \n" + "body[unresolved] {" + "opacity: 0; display: block; overflow: hidden; posi tion: relative;" + " } \n";
6367 var head = document.querySelector("head"); 7212 var head = document.querySelector("head");
6368 head.insertBefore(style, head.firstChild); 7213 head.insertBefore(style, head.firstChild);
6369 })(window.WebComponents); 7214 })(window.WebComponents);
6370 7215
6371 (function(scope) { 7216 (function(scope) {
6372 window.Platform = scope; 7217 window.Platform = scope;
6373 })(window.WebComponents); 7218 })(window.WebComponents);
OLDNEW
« no previous file with comments | « packages/web_components/lib/src/init.dart ('k') | packages/web_components/lib/webcomponents-lite.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698