OLD | NEW |
1 /** | 1 /** |
2 * @license | 2 * @license |
3 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | 3 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
4 * This code may only be used under the BSD style license found at http://polyme
r.github.io/LICENSE.txt | 4 * This code may only be used under the BSD style license found at http://polyme
r.github.io/LICENSE.txt |
5 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.
txt | 5 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.
txt |
6 * The complete set of contributors may be found at http://polymer.github.io/CON
TRIBUTORS.txt | 6 * The complete set of contributors may be found at http://polymer.github.io/CON
TRIBUTORS.txt |
7 * Code distributed by Google as part of the polymer project is also | 7 * Code distributed by Google as part of the polymer project is also |
8 * subject to an additional IP rights grant found at http://polymer.github.io/PA
TENTS.txt | 8 * subject to an additional IP rights grant found at http://polymer.github.io/PA
TENTS.txt |
9 */ | 9 */ |
10 // @version 0.7.5 | 10 // @version 0.7.20 |
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-lite.js"; | 15 var file = "webcomponents-lite.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(option) { | 19 location.search.slice(1).split("&").forEach(function(option) { |
19 var parts = option.split("="); | 20 var parts = option.split("="); |
20 var match; | 21 var match; |
21 if (parts[0] && (match = parts[0].match(/wc-(.+)/))) { | 22 if (parts[0] && (match = parts[0].match(/wc-(.+)/))) { |
22 flags[match[1]] = parts[1] || true; | 23 flags[match[1]] = parts[1] || true; |
23 } | 24 } |
24 }); | 25 }); |
25 if (script) { | 26 if (script) { |
26 for (var i = 0, a; a = script.attributes[i]; i++) { | 27 for (var i = 0, a; a = script.attributes[i]; i++) { |
27 if (a.name !== "src") { | 28 if (a.name !== "src") { |
28 flags[a.name] = a.value || true; | 29 flags[a.name] = a.value || true; |
29 } | 30 } |
30 } | 31 } |
31 } | 32 } |
32 if (flags.log) { | 33 if (flags.log && flags.log.split) { |
33 var parts = flags.log.split(","); | 34 var parts = flags.log.split(","); |
34 flags.log = {}; | 35 flags.log = {}; |
35 parts.forEach(function(f) { | 36 parts.forEach(function(f) { |
36 flags.log[f] = true; | 37 flags.log[f] = true; |
37 }); | 38 }); |
38 } else { | 39 } else { |
39 flags.log = {}; | 40 flags.log = {}; |
40 } | 41 } |
41 } | 42 } |
42 flags.shadow = flags.shadow || flags.shadowdom || flags.polyfill; | |
43 if (flags.shadow === "native") { | |
44 flags.shadow = false; | |
45 } else { | |
46 flags.shadow = flags.shadow || !HTMLElement.prototype.createShadowRoot; | |
47 } | |
48 if (flags.register) { | 43 if (flags.register) { |
49 window.CustomElements = window.CustomElements || { | 44 window.CustomElements = window.CustomElements || { |
50 flags: {} | 45 flags: {} |
51 }; | 46 }; |
52 window.CustomElements.flags.register = flags.register; | 47 window.CustomElements.flags.register = flags.register; |
53 } | 48 } |
54 scope.flags = flags; | 49 WebComponents.flags = flags; |
55 })(window.WebComponents); | 50 })(); |
56 | 51 |
57 (function(scope) { | 52 (function(scope) { |
58 "use strict"; | 53 "use strict"; |
59 var hasWorkingUrl = false; | 54 var hasWorkingUrl = false; |
60 if (!scope.forceJURL) { | 55 if (!scope.forceJURL) { |
61 try { | 56 try { |
62 var u = new URL("b", "http://a"); | 57 var u = new URL("b", "http://a"); |
63 u.pathname = "c%20d"; | 58 u.pathname = "c%20d"; |
64 hasWorkingUrl = u.href === "http://a/c%20d"; | 59 hasWorkingUrl = u.href === "http://a/c%20d"; |
65 } catch (e) {} | 60 } catch (e) {} |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 var OriginalURL = scope.URL; | 562 var OriginalURL = scope.URL; |
568 if (OriginalURL) { | 563 if (OriginalURL) { |
569 jURL.createObjectURL = function(blob) { | 564 jURL.createObjectURL = function(blob) { |
570 return OriginalURL.createObjectURL.apply(OriginalURL, arguments); | 565 return OriginalURL.createObjectURL.apply(OriginalURL, arguments); |
571 }; | 566 }; |
572 jURL.revokeObjectURL = function(url) { | 567 jURL.revokeObjectURL = function(url) { |
573 OriginalURL.revokeObjectURL(url); | 568 OriginalURL.revokeObjectURL(url); |
574 }; | 569 }; |
575 } | 570 } |
576 scope.URL = jURL; | 571 scope.URL = jURL; |
577 })(this); | 572 })(self); |
578 | 573 |
579 if (typeof WeakMap === "undefined") { | 574 if (typeof WeakMap === "undefined") { |
580 (function() { | 575 (function() { |
581 var defineProperty = Object.defineProperty; | 576 var defineProperty = Object.defineProperty; |
582 var counter = Date.now() % 1e9; | 577 var counter = Date.now() % 1e9; |
583 var WeakMap = function() { | 578 var WeakMap = function() { |
584 this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__"); | 579 this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__"); |
585 }; | 580 }; |
586 WeakMap.prototype = { | 581 WeakMap.prototype = { |
587 set: function(key, value) { | 582 set: function(key, value) { |
(...skipping 18 matching lines...) Expand all Loading... |
606 var entry = key[this.name]; | 601 var entry = key[this.name]; |
607 if (!entry) return false; | 602 if (!entry) return false; |
608 return entry[0] === key; | 603 return entry[0] === key; |
609 } | 604 } |
610 }; | 605 }; |
611 window.WeakMap = WeakMap; | 606 window.WeakMap = WeakMap; |
612 })(); | 607 })(); |
613 } | 608 } |
614 | 609 |
615 (function(global) { | 610 (function(global) { |
| 611 if (global.JsMutationObserver) { |
| 612 return; |
| 613 } |
616 var registrationsTable = new WeakMap(); | 614 var registrationsTable = new WeakMap(); |
617 var setImmediate; | 615 var setImmediate; |
618 if (/Trident|Edge/.test(navigator.userAgent)) { | 616 if (/Trident|Edge/.test(navigator.userAgent)) { |
619 setImmediate = setTimeout; | 617 setImmediate = setTimeout; |
620 } else if (window.setImmediate) { | 618 } else if (window.setImmediate) { |
621 setImmediate = window.setImmediate; | 619 setImmediate = window.setImmediate; |
622 } else { | 620 } else { |
623 var setImmediateQueue = []; | 621 var setImmediateQueue = []; |
624 var sentinel = String(Math.random()); | 622 var sentinel = String(Math.random()); |
625 window.addEventListener("message", function(e) { | 623 window.addEventListener("message", function(e) { |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 record.nextSibling = nextSibling; | 899 record.nextSibling = nextSibling; |
902 forEachAncestorAndObserverEnqueueRecord(e.relatedNode, function(options)
{ | 900 forEachAncestorAndObserverEnqueueRecord(e.relatedNode, function(options)
{ |
903 if (!options.childList) return; | 901 if (!options.childList) return; |
904 return record; | 902 return record; |
905 }); | 903 }); |
906 } | 904 } |
907 clearRecords(); | 905 clearRecords(); |
908 } | 906 } |
909 }; | 907 }; |
910 global.JsMutationObserver = JsMutationObserver; | 908 global.JsMutationObserver = JsMutationObserver; |
911 if (!global.MutationObserver) global.MutationObserver = JsMutationObserver; | 909 if (!global.MutationObserver) { |
912 })(this); | 910 global.MutationObserver = JsMutationObserver; |
| 911 JsMutationObserver._isPolyfilled = true; |
| 912 } |
| 913 })(self); |
| 914 |
| 915 if (typeof HTMLTemplateElement === "undefined") { |
| 916 (function() { |
| 917 var TEMPLATE_TAG = "template"; |
| 918 var contentDoc = document.implementation.createHTMLDocument("template"); |
| 919 var canDecorate = true; |
| 920 HTMLTemplateElement = function() {}; |
| 921 HTMLTemplateElement.prototype = Object.create(HTMLElement.prototype); |
| 922 HTMLTemplateElement.decorate = function(template) { |
| 923 if (template.content) { |
| 924 return; |
| 925 } |
| 926 template.content = contentDoc.createDocumentFragment(); |
| 927 var child; |
| 928 while (child = template.firstChild) { |
| 929 template.content.appendChild(child); |
| 930 } |
| 931 if (canDecorate) { |
| 932 try { |
| 933 Object.defineProperty(template, "innerHTML", { |
| 934 get: function() { |
| 935 var o = ""; |
| 936 for (var e = this.content.firstChild; e; e = e.nextSibling) { |
| 937 o += e.outerHTML || escapeData(e.data); |
| 938 } |
| 939 return o; |
| 940 }, |
| 941 set: function(text) { |
| 942 contentDoc.body.innerHTML = text; |
| 943 HTMLTemplateElement.bootstrap(contentDoc); |
| 944 while (this.content.firstChild) { |
| 945 this.content.removeChild(this.content.firstChild); |
| 946 } |
| 947 while (contentDoc.body.firstChild) { |
| 948 this.content.appendChild(contentDoc.body.firstChild); |
| 949 } |
| 950 }, |
| 951 configurable: true |
| 952 }); |
| 953 } catch (err) { |
| 954 canDecorate = false; |
| 955 } |
| 956 } |
| 957 HTMLTemplateElement.bootstrap(template.content); |
| 958 }; |
| 959 HTMLTemplateElement.bootstrap = function(doc) { |
| 960 var templates = doc.querySelectorAll(TEMPLATE_TAG); |
| 961 for (var i = 0, l = templates.length, t; i < l && (t = templates[i]); i++)
{ |
| 962 HTMLTemplateElement.decorate(t); |
| 963 } |
| 964 }; |
| 965 document.addEventListener("DOMContentLoaded", function() { |
| 966 HTMLTemplateElement.bootstrap(document); |
| 967 }); |
| 968 var createElement = document.createElement; |
| 969 document.createElement = function() { |
| 970 "use strict"; |
| 971 var el = createElement.apply(document, arguments); |
| 972 if (el.localName == "template") { |
| 973 HTMLTemplateElement.decorate(el); |
| 974 } |
| 975 return el; |
| 976 }; |
| 977 var escapeDataRegExp = /[&\u00A0<>]/g; |
| 978 function escapeReplace(c) { |
| 979 switch (c) { |
| 980 case "&": |
| 981 return "&"; |
| 982 |
| 983 case "<": |
| 984 return "<"; |
| 985 |
| 986 case ">": |
| 987 return ">"; |
| 988 |
| 989 case "Â ": |
| 990 return " "; |
| 991 } |
| 992 } |
| 993 function escapeData(s) { |
| 994 return s.replace(escapeDataRegExp, escapeReplace); |
| 995 } |
| 996 })(); |
| 997 } |
| 998 |
| 999 (function(scope) { |
| 1000 "use strict"; |
| 1001 if (!window.performance) { |
| 1002 var start = Date.now(); |
| 1003 window.performance = { |
| 1004 now: function() { |
| 1005 return Date.now() - start; |
| 1006 } |
| 1007 }; |
| 1008 } |
| 1009 if (!window.requestAnimationFrame) { |
| 1010 window.requestAnimationFrame = function() { |
| 1011 var nativeRaf = window.webkitRequestAnimationFrame || window.mozRequestAni
mationFrame; |
| 1012 return nativeRaf ? function(callback) { |
| 1013 return nativeRaf(function() { |
| 1014 callback(performance.now()); |
| 1015 }); |
| 1016 } : function(callback) { |
| 1017 return window.setTimeout(callback, 1e3 / 60); |
| 1018 }; |
| 1019 }(); |
| 1020 } |
| 1021 if (!window.cancelAnimationFrame) { |
| 1022 window.cancelAnimationFrame = function() { |
| 1023 return window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame
|| function(id) { |
| 1024 clearTimeout(id); |
| 1025 }; |
| 1026 }(); |
| 1027 } |
| 1028 var workingDefaultPrevented = function() { |
| 1029 var e = document.createEvent("Event"); |
| 1030 e.initEvent("foo", true, true); |
| 1031 e.preventDefault(); |
| 1032 return e.defaultPrevented; |
| 1033 }(); |
| 1034 if (!workingDefaultPrevented) { |
| 1035 var origPreventDefault = Event.prototype.preventDefault; |
| 1036 Event.prototype.preventDefault = function() { |
| 1037 if (!this.cancelable) { |
| 1038 return; |
| 1039 } |
| 1040 origPreventDefault.call(this); |
| 1041 Object.defineProperty(this, "defaultPrevented", { |
| 1042 get: function() { |
| 1043 return true; |
| 1044 }, |
| 1045 configurable: true |
| 1046 }); |
| 1047 }; |
| 1048 } |
| 1049 var isIE = /Trident/.test(navigator.userAgent); |
| 1050 if (!window.CustomEvent || isIE && typeof window.CustomEvent !== "function") { |
| 1051 window.CustomEvent = function(inType, params) { |
| 1052 params = params || {}; |
| 1053 var e = document.createEvent("CustomEvent"); |
| 1054 e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelab
le), params.detail); |
| 1055 return e; |
| 1056 }; |
| 1057 window.CustomEvent.prototype = window.Event.prototype; |
| 1058 } |
| 1059 if (!window.Event || isIE && typeof window.Event !== "function") { |
| 1060 var origEvent = window.Event; |
| 1061 window.Event = function(inType, params) { |
| 1062 params = params || {}; |
| 1063 var e = document.createEvent("Event"); |
| 1064 e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable)); |
| 1065 return e; |
| 1066 }; |
| 1067 window.Event.prototype = origEvent.prototype; |
| 1068 } |
| 1069 })(window.WebComponents); |
913 | 1070 |
914 window.HTMLImports = window.HTMLImports || { | 1071 window.HTMLImports = window.HTMLImports || { |
915 flags: {} | 1072 flags: {} |
916 }; | 1073 }; |
917 | 1074 |
918 (function(scope) { | 1075 (function(scope) { |
919 var IMPORT_LINK_TYPE = "import"; | 1076 var IMPORT_LINK_TYPE = "import"; |
920 var useNative = Boolean(IMPORT_LINK_TYPE in document.createElement("link")); | 1077 var useNative = Boolean(IMPORT_LINK_TYPE in document.createElement("link")); |
921 var hasShadowDOMPolyfill = Boolean(window.ShadowDOMPolyfill); | 1078 var hasShadowDOMPolyfill = Boolean(window.ShadowDOMPolyfill); |
922 var wrap = function(node) { | 1079 var wrap = function(node) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 checkDone(); | 1136 checkDone(); |
980 } | 1137 } |
981 function errorLoadingImport(e) { | 1138 function errorLoadingImport(e) { |
982 errorImports.push(this); | 1139 errorImports.push(this); |
983 parsedCount++; | 1140 parsedCount++; |
984 checkDone(); | 1141 checkDone(); |
985 } | 1142 } |
986 if (importCount) { | 1143 if (importCount) { |
987 for (var i = 0, imp; i < importCount && (imp = imports[i]); i++) { | 1144 for (var i = 0, imp; i < importCount && (imp = imports[i]); i++) { |
988 if (isImportLoaded(imp)) { | 1145 if (isImportLoaded(imp)) { |
| 1146 newImports.push(this); |
989 parsedCount++; | 1147 parsedCount++; |
990 checkDone(); | 1148 checkDone(); |
991 } else { | 1149 } else { |
992 imp.addEventListener("load", loadedImport); | 1150 imp.addEventListener("load", loadedImport); |
993 imp.addEventListener("error", errorLoadingImport); | 1151 imp.addEventListener("error", errorLoadingImport); |
994 } | 1152 } |
995 } | 1153 } |
996 } else { | 1154 } else { |
997 checkDone(); | 1155 checkDone(); |
998 } | 1156 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 return request.status >= 200 && request.status < 300 || request.status ===
304 || request.status === 0; | 1263 return request.status >= 200 && request.status < 300 || request.status ===
304 || request.status === 0; |
1106 }, | 1264 }, |
1107 load: function(url, next, nextContext) { | 1265 load: function(url, next, nextContext) { |
1108 var request = new XMLHttpRequest(); | 1266 var request = new XMLHttpRequest(); |
1109 if (scope.flags.debug || scope.flags.bust) { | 1267 if (scope.flags.debug || scope.flags.bust) { |
1110 url += "?" + Math.random(); | 1268 url += "?" + Math.random(); |
1111 } | 1269 } |
1112 request.open("GET", url, xhr.async); | 1270 request.open("GET", url, xhr.async); |
1113 request.addEventListener("readystatechange", function(e) { | 1271 request.addEventListener("readystatechange", function(e) { |
1114 if (request.readyState === 4) { | 1272 if (request.readyState === 4) { |
1115 var locationHeader = request.getResponseHeader("Location"); | |
1116 var redirectedUrl = null; | 1273 var redirectedUrl = null; |
1117 if (locationHeader) { | 1274 try { |
1118 var redirectedUrl = locationHeader.substr(0, 1) === "/" ? location.o
rigin + locationHeader : locationHeader; | 1275 var locationHeader = request.getResponseHeader("Location"); |
| 1276 if (locationHeader) { |
| 1277 redirectedUrl = locationHeader.substr(0, 1) === "/" ? location.ori
gin + locationHeader : locationHeader; |
| 1278 } |
| 1279 } catch (e) { |
| 1280 console.error(e.message); |
1119 } | 1281 } |
1120 next.call(nextContext, !xhr.ok(request) && request, request.response |
| request.responseText, redirectedUrl); | 1282 next.call(nextContext, !xhr.ok(request) && request, request.response |
| request.responseText, redirectedUrl); |
1121 } | 1283 } |
1122 }); | 1284 }); |
1123 request.send(); | 1285 request.send(); |
1124 return request; | 1286 return request; |
1125 }, | 1287 }, |
1126 loadDocument: function(url, next, nextContext) { | 1288 loadDocument: function(url, next, nextContext) { |
1127 this.load(url, next, nextContext).responseType = "document"; | 1289 this.load(url, next, nextContext).responseType = "document"; |
1128 } | 1290 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1258 | 1420 |
1259 window.HTMLImports.addModule(function(scope) { | 1421 window.HTMLImports.addModule(function(scope) { |
1260 var path = scope.path; | 1422 var path = scope.path; |
1261 var rootDocument = scope.rootDocument; | 1423 var rootDocument = scope.rootDocument; |
1262 var flags = scope.flags; | 1424 var flags = scope.flags; |
1263 var isIE = scope.isIE; | 1425 var isIE = scope.isIE; |
1264 var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE; | 1426 var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE; |
1265 var IMPORT_SELECTOR = "link[rel=" + IMPORT_LINK_TYPE + "]"; | 1427 var IMPORT_SELECTOR = "link[rel=" + IMPORT_LINK_TYPE + "]"; |
1266 var importParser = { | 1428 var importParser = { |
1267 documentSelectors: IMPORT_SELECTOR, | 1429 documentSelectors: IMPORT_SELECTOR, |
1268 importsSelectors: [ IMPORT_SELECTOR, "link[rel=stylesheet]", "style", "scrip
t:not([type])", 'script[type="application/javascript"]', 'script[type="text/java
script"]' ].join(","), | 1430 importsSelectors: [ IMPORT_SELECTOR, "link[rel=stylesheet]:not([type])", "st
yle:not([type])", "script:not([type])", 'script[type="application/javascript"]',
'script[type="text/javascript"]' ].join(","), |
1269 map: { | 1431 map: { |
1270 link: "parseLink", | 1432 link: "parseLink", |
1271 script: "parseScript", | 1433 script: "parseScript", |
1272 style: "parseStyle" | 1434 style: "parseStyle" |
1273 }, | 1435 }, |
1274 dynamicElements: [], | 1436 dynamicElements: [], |
1275 parseNext: function() { | 1437 parseNext: function() { |
1276 var next = this.nextToParse(); | 1438 var next = this.nextToParse(); |
1277 if (next) { | 1439 if (next) { |
1278 this.parse(next); | 1440 this.parse(next); |
(...skipping 30 matching lines...) Expand all Loading... |
1309 this.parsingElement = null; | 1471 this.parsingElement = null; |
1310 flags.parse && console.log("completed", elt); | 1472 flags.parse && console.log("completed", elt); |
1311 }, | 1473 }, |
1312 markDynamicParsingComplete: function(elt) { | 1474 markDynamicParsingComplete: function(elt) { |
1313 var i = this.dynamicElements.indexOf(elt); | 1475 var i = this.dynamicElements.indexOf(elt); |
1314 if (i >= 0) { | 1476 if (i >= 0) { |
1315 this.dynamicElements.splice(i, 1); | 1477 this.dynamicElements.splice(i, 1); |
1316 } | 1478 } |
1317 }, | 1479 }, |
1318 parseImport: function(elt) { | 1480 parseImport: function(elt) { |
| 1481 elt.import = elt.__doc; |
1319 if (window.HTMLImports.__importsParsingHook) { | 1482 if (window.HTMLImports.__importsParsingHook) { |
1320 window.HTMLImports.__importsParsingHook(elt); | 1483 window.HTMLImports.__importsParsingHook(elt); |
1321 } | 1484 } |
1322 if (elt.import) { | 1485 if (elt.import) { |
1323 elt.import.__importParsed = true; | 1486 elt.import.__importParsed = true; |
1324 } | 1487 } |
1325 this.markParsingComplete(elt); | 1488 this.markParsingComplete(elt); |
1326 if (elt.__resource && !elt.__error) { | 1489 if (elt.__resource && !elt.__error) { |
1327 elt.dispatchEvent(new CustomEvent("load", { | 1490 elt.dispatchEvent(new CustomEvent("load", { |
1328 bubbles: false | 1491 bubbles: false |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1371 } | 1534 } |
1372 return n; | 1535 return n; |
1373 }, | 1536 }, |
1374 addElementToDocument: function(elt) { | 1537 addElementToDocument: function(elt) { |
1375 var port = this.rootImportForElement(elt.__importElement || elt); | 1538 var port = this.rootImportForElement(elt.__importElement || elt); |
1376 port.parentNode.insertBefore(elt, port); | 1539 port.parentNode.insertBefore(elt, port); |
1377 }, | 1540 }, |
1378 trackElement: function(elt, callback) { | 1541 trackElement: function(elt, callback) { |
1379 var self = this; | 1542 var self = this; |
1380 var done = function(e) { | 1543 var done = function(e) { |
| 1544 elt.removeEventListener("load", done); |
| 1545 elt.removeEventListener("error", done); |
1381 if (callback) { | 1546 if (callback) { |
1382 callback(e); | 1547 callback(e); |
1383 } | 1548 } |
1384 self.markParsingComplete(elt); | 1549 self.markParsingComplete(elt); |
1385 self.parseNext(); | 1550 self.parseNext(); |
1386 }; | 1551 }; |
1387 elt.addEventListener("load", done); | 1552 elt.addEventListener("load", done); |
1388 elt.addEventListener("error", done); | 1553 elt.addEventListener("error", done); |
1389 if (isIE && elt.localName === "style") { | 1554 if (isIE && elt.localName === "style") { |
1390 var fakeLoad = false; | 1555 var fakeLoad = false; |
(...skipping 17 matching lines...) Expand all Loading... |
1408 }); | 1573 }); |
1409 } | 1574 } |
1410 } | 1575 } |
1411 }, | 1576 }, |
1412 parseScript: function(scriptElt) { | 1577 parseScript: function(scriptElt) { |
1413 var script = document.createElement("script"); | 1578 var script = document.createElement("script"); |
1414 script.__importElement = scriptElt; | 1579 script.__importElement = scriptElt; |
1415 script.src = scriptElt.src ? scriptElt.src : generateScriptDataUrl(scriptE
lt); | 1580 script.src = scriptElt.src ? scriptElt.src : generateScriptDataUrl(scriptE
lt); |
1416 scope.currentScript = scriptElt; | 1581 scope.currentScript = scriptElt; |
1417 this.trackElement(script, function(e) { | 1582 this.trackElement(script, function(e) { |
1418 script.parentNode.removeChild(script); | 1583 if (script.parentNode) { |
| 1584 script.parentNode.removeChild(script); |
| 1585 } |
1419 scope.currentScript = null; | 1586 scope.currentScript = null; |
1420 }); | 1587 }); |
1421 this.addElementToDocument(script); | 1588 this.addElementToDocument(script); |
1422 }, | 1589 }, |
1423 nextToParse: function() { | 1590 nextToParse: function() { |
1424 this._mayParse = []; | 1591 this._mayParse = []; |
1425 return !this.parsingElement && (this.nextToParseInDoc(rootDocument) || thi
s.nextToParseDynamic()); | 1592 return !this.parsingElement && (this.nextToParseInDoc(rootDocument) || thi
s.nextToParseDynamic()); |
1426 }, | 1593 }, |
1427 nextToParseInDoc: function(doc, link) { | 1594 nextToParseInDoc: function(doc, link) { |
1428 if (doc && this._mayParse.indexOf(doc) < 0) { | 1595 if (doc && this._mayParse.indexOf(doc) < 0) { |
1429 this._mayParse.push(doc); | 1596 this._mayParse.push(doc); |
1430 var nodes = doc.querySelectorAll(this.parseSelectorsForNode(doc)); | 1597 var nodes = doc.querySelectorAll(this.parseSelectorsForNode(doc)); |
1431 for (var i = 0, l = nodes.length, p = 0, n; i < l && (n = nodes[i]); i++
) { | 1598 for (var i = 0, l = nodes.length, p = 0, n; i < l && (n = nodes[i]); i++
) { |
1432 if (!this.isParsed(n)) { | 1599 if (!this.isParsed(n)) { |
1433 if (this.hasResource(n)) { | 1600 if (this.hasResource(n)) { |
1434 return nodeIsImport(n) ? this.nextToParseInDoc(n.import, n) : n; | 1601 return nodeIsImport(n) ? this.nextToParseInDoc(n.__doc, n) : n; |
1435 } else { | 1602 } else { |
1436 return; | 1603 return; |
1437 } | 1604 } |
1438 } | 1605 } |
1439 } | 1606 } |
1440 } | 1607 } |
1441 return link; | 1608 return link; |
1442 }, | 1609 }, |
1443 nextToParseDynamic: function() { | 1610 nextToParseDynamic: function() { |
1444 return this.dynamicElements[0]; | 1611 return this.dynamicElements[0]; |
1445 }, | 1612 }, |
1446 parseSelectorsForNode: function(node) { | 1613 parseSelectorsForNode: function(node) { |
1447 var doc = node.ownerDocument || node; | 1614 var doc = node.ownerDocument || node; |
1448 return doc === rootDocument ? this.documentSelectors : this.importsSelecto
rs; | 1615 return doc === rootDocument ? this.documentSelectors : this.importsSelecto
rs; |
1449 }, | 1616 }, |
1450 isParsed: function(node) { | 1617 isParsed: function(node) { |
1451 return node.__importParsed; | 1618 return node.__importParsed; |
1452 }, | 1619 }, |
1453 needsDynamicParsing: function(elt) { | 1620 needsDynamicParsing: function(elt) { |
1454 return this.dynamicElements.indexOf(elt) >= 0; | 1621 return this.dynamicElements.indexOf(elt) >= 0; |
1455 }, | 1622 }, |
1456 hasResource: function(node) { | 1623 hasResource: function(node) { |
1457 if (nodeIsImport(node) && node.import === undefined) { | 1624 if (nodeIsImport(node) && node.__doc === undefined) { |
1458 return false; | 1625 return false; |
1459 } | 1626 } |
1460 return true; | 1627 return true; |
1461 } | 1628 } |
1462 }; | 1629 }; |
1463 function nodeIsImport(elt) { | 1630 function nodeIsImport(elt) { |
1464 return elt.localName === "link" && elt.rel === IMPORT_LINK_TYPE; | 1631 return elt.localName === "link" && elt.rel === IMPORT_LINK_TYPE; |
1465 } | 1632 } |
1466 function generateScriptDataUrl(script) { | 1633 function generateScriptDataUrl(script) { |
1467 var scriptContent = generateScriptContent(script); | 1634 var scriptContent = generateScriptContent(script); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 if (isImportLink(elt)) { | 1688 if (isImportLink(elt)) { |
1522 var doc = this.documents[url]; | 1689 var doc = this.documents[url]; |
1523 if (doc === undefined) { | 1690 if (doc === undefined) { |
1524 doc = err ? null : makeDocument(resource, redirectedUrl || url); | 1691 doc = err ? null : makeDocument(resource, redirectedUrl || url); |
1525 if (doc) { | 1692 if (doc) { |
1526 doc.__importLink = elt; | 1693 doc.__importLink = elt; |
1527 this.bootDocument(doc); | 1694 this.bootDocument(doc); |
1528 } | 1695 } |
1529 this.documents[url] = doc; | 1696 this.documents[url] = doc; |
1530 } | 1697 } |
1531 elt.import = doc; | 1698 elt.__doc = doc; |
1532 } | 1699 } |
1533 parser.parseNext(); | 1700 parser.parseNext(); |
1534 }, | 1701 }, |
1535 bootDocument: function(doc) { | 1702 bootDocument: function(doc) { |
1536 this.loadSubtree(doc); | 1703 this.loadSubtree(doc); |
1537 this.observer.observe(doc); | 1704 this.observer.observe(doc); |
1538 parser.parseNext(); | 1705 parser.parseNext(); |
1539 }, | 1706 }, |
1540 loadedAll: function() { | 1707 loadedAll: function() { |
1541 parser.parseNext(); | 1708 parser.parseNext(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1617 importer.observer.addCallback = dynamic.added.bind(dynamic); | 1784 importer.observer.addCallback = dynamic.added.bind(dynamic); |
1618 var matches = HTMLElement.prototype.matches || HTMLElement.prototype.matchesSe
lector || HTMLElement.prototype.webkitMatchesSelector || HTMLElement.prototype.m
ozMatchesSelector || HTMLElement.prototype.msMatchesSelector; | 1785 var matches = HTMLElement.prototype.matches || HTMLElement.prototype.matchesSe
lector || HTMLElement.prototype.webkitMatchesSelector || HTMLElement.prototype.m
ozMatchesSelector || HTMLElement.prototype.msMatchesSelector; |
1619 }); | 1786 }); |
1620 | 1787 |
1621 (function(scope) { | 1788 (function(scope) { |
1622 var initializeModules = scope.initializeModules; | 1789 var initializeModules = scope.initializeModules; |
1623 var isIE = scope.isIE; | 1790 var isIE = scope.isIE; |
1624 if (scope.useNative) { | 1791 if (scope.useNative) { |
1625 return; | 1792 return; |
1626 } | 1793 } |
1627 if (isIE && typeof window.CustomEvent !== "function") { | |
1628 window.CustomEvent = function(inType, params) { | |
1629 params = params || {}; | |
1630 var e = document.createEvent("CustomEvent"); | |
1631 e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelab
le), params.detail); | |
1632 e.preventDefault = function() { | |
1633 Object.defineProperty(this, "defaultPrevented", { | |
1634 get: function() { | |
1635 return true; | |
1636 } | |
1637 }); | |
1638 }; | |
1639 return e; | |
1640 }; | |
1641 window.CustomEvent.prototype = window.Event.prototype; | |
1642 } | |
1643 initializeModules(); | 1794 initializeModules(); |
1644 var rootDocument = scope.rootDocument; | 1795 var rootDocument = scope.rootDocument; |
1645 function bootstrap() { | 1796 function bootstrap() { |
1646 window.HTMLImports.importer.bootDocument(rootDocument); | 1797 window.HTMLImports.importer.bootDocument(rootDocument); |
1647 } | 1798 } |
1648 if (document.readyState === "complete" || document.readyState === "interactive
" && !window.attachEvent) { | 1799 if (document.readyState === "complete" || document.readyState === "interactive
" && !window.attachEvent) { |
1649 bootstrap(); | 1800 bootstrap(); |
1650 } else { | 1801 } else { |
1651 document.addEventListener("DOMContentLoaded", bootstrap); | 1802 document.addEventListener("DOMContentLoaded", bootstrap); |
1652 } | 1803 } |
(...skipping 10 matching lines...) Expand all Loading... |
1663 modules.push(module); | 1814 modules.push(module); |
1664 }; | 1815 }; |
1665 var initializeModules = function() { | 1816 var initializeModules = function() { |
1666 modules.forEach(function(module) { | 1817 modules.forEach(function(module) { |
1667 module(scope); | 1818 module(scope); |
1668 }); | 1819 }); |
1669 }; | 1820 }; |
1670 scope.addModule = addModule; | 1821 scope.addModule = addModule; |
1671 scope.initializeModules = initializeModules; | 1822 scope.initializeModules = initializeModules; |
1672 scope.hasNative = Boolean(document.registerElement); | 1823 scope.hasNative = Boolean(document.registerElement); |
| 1824 scope.isIE = /Trident/.test(navigator.userAgent); |
1673 scope.useNative = !flags.register && scope.hasNative && !window.ShadowDOMPolyf
ill && (!window.HTMLImports || window.HTMLImports.useNative); | 1825 scope.useNative = !flags.register && scope.hasNative && !window.ShadowDOMPolyf
ill && (!window.HTMLImports || window.HTMLImports.useNative); |
1674 })(window.CustomElements); | 1826 })(window.CustomElements); |
1675 | 1827 |
1676 window.CustomElements.addModule(function(scope) { | 1828 window.CustomElements.addModule(function(scope) { |
1677 var IMPORT_LINK_TYPE = window.HTMLImports ? window.HTMLImports.IMPORT_LINK_TYP
E : "none"; | 1829 var IMPORT_LINK_TYPE = window.HTMLImports ? window.HTMLImports.IMPORT_LINK_TYP
E : "none"; |
1678 function forSubtree(node, cb) { | 1830 function forSubtree(node, cb) { |
1679 findAllElements(node, function(e) { | 1831 findAllElements(node, function(e) { |
1680 if (cb(e)) { | 1832 if (cb(e)) { |
1681 return true; | 1833 return true; |
1682 } | 1834 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1725 cb(doc); | 1877 cb(doc); |
1726 } | 1878 } |
1727 scope.forDocumentTree = forDocumentTree; | 1879 scope.forDocumentTree = forDocumentTree; |
1728 scope.forSubtree = forSubtree; | 1880 scope.forSubtree = forSubtree; |
1729 }); | 1881 }); |
1730 | 1882 |
1731 window.CustomElements.addModule(function(scope) { | 1883 window.CustomElements.addModule(function(scope) { |
1732 var flags = scope.flags; | 1884 var flags = scope.flags; |
1733 var forSubtree = scope.forSubtree; | 1885 var forSubtree = scope.forSubtree; |
1734 var forDocumentTree = scope.forDocumentTree; | 1886 var forDocumentTree = scope.forDocumentTree; |
1735 function addedNode(node) { | 1887 function addedNode(node, isAttached) { |
1736 return added(node) || addedSubtree(node); | 1888 return added(node, isAttached) || addedSubtree(node, isAttached); |
1737 } | 1889 } |
1738 function added(node) { | 1890 function added(node, isAttached) { |
1739 if (scope.upgrade(node)) { | 1891 if (scope.upgrade(node, isAttached)) { |
1740 return true; | 1892 return true; |
1741 } | 1893 } |
1742 attached(node); | 1894 if (isAttached) { |
| 1895 attached(node); |
| 1896 } |
1743 } | 1897 } |
1744 function addedSubtree(node) { | 1898 function addedSubtree(node, isAttached) { |
1745 forSubtree(node, function(e) { | 1899 forSubtree(node, function(e) { |
1746 if (added(e)) { | 1900 if (added(e, isAttached)) { |
1747 return true; | 1901 return true; |
1748 } | 1902 } |
1749 }); | 1903 }); |
1750 } | 1904 } |
1751 function attachedNode(node) { | 1905 var hasThrottledAttached = window.MutationObserver._isPolyfilled && flags["thr
ottle-attached"]; |
1752 attached(node); | 1906 scope.hasPolyfillMutations = hasThrottledAttached; |
1753 if (inDocument(node)) { | 1907 scope.hasThrottledAttached = hasThrottledAttached; |
1754 forSubtree(node, function(e) { | |
1755 attached(e); | |
1756 }); | |
1757 } | |
1758 } | |
1759 var hasPolyfillMutations = !window.MutationObserver || window.MutationObserver
=== window.JsMutationObserver; | |
1760 scope.hasPolyfillMutations = hasPolyfillMutations; | |
1761 var isPendingMutations = false; | 1908 var isPendingMutations = false; |
1762 var pendingMutations = []; | 1909 var pendingMutations = []; |
1763 function deferMutation(fn) { | 1910 function deferMutation(fn) { |
1764 pendingMutations.push(fn); | 1911 pendingMutations.push(fn); |
1765 if (!isPendingMutations) { | 1912 if (!isPendingMutations) { |
1766 isPendingMutations = true; | 1913 isPendingMutations = true; |
1767 setTimeout(takeMutations); | 1914 setTimeout(takeMutations); |
1768 } | 1915 } |
1769 } | 1916 } |
1770 function takeMutations() { | 1917 function takeMutations() { |
1771 isPendingMutations = false; | 1918 isPendingMutations = false; |
1772 var $p = pendingMutations; | 1919 var $p = pendingMutations; |
1773 for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) { | 1920 for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) { |
1774 p(); | 1921 p(); |
1775 } | 1922 } |
1776 pendingMutations = []; | 1923 pendingMutations = []; |
1777 } | 1924 } |
1778 function attached(element) { | 1925 function attached(element) { |
1779 if (hasPolyfillMutations) { | 1926 if (hasThrottledAttached) { |
1780 deferMutation(function() { | 1927 deferMutation(function() { |
1781 _attached(element); | 1928 _attached(element); |
1782 }); | 1929 }); |
1783 } else { | 1930 } else { |
1784 _attached(element); | 1931 _attached(element); |
1785 } | 1932 } |
1786 } | 1933 } |
1787 function _attached(element) { | 1934 function _attached(element) { |
1788 if (element.__upgraded__ && (element.attachedCallback || element.detachedCal
lback)) { | 1935 if (element.__upgraded__ && !element.__attached) { |
1789 if (!element.__attached && inDocument(element)) { | 1936 element.__attached = true; |
1790 element.__attached = true; | 1937 if (element.attachedCallback) { |
1791 if (element.attachedCallback) { | 1938 element.attachedCallback(); |
1792 element.attachedCallback(); | |
1793 } | |
1794 } | 1939 } |
1795 } | 1940 } |
1796 } | 1941 } |
1797 function detachedNode(node) { | 1942 function detachedNode(node) { |
1798 detached(node); | 1943 detached(node); |
1799 forSubtree(node, function(e) { | 1944 forSubtree(node, function(e) { |
1800 detached(e); | 1945 detached(e); |
1801 }); | 1946 }); |
1802 } | 1947 } |
1803 function detached(element) { | 1948 function detached(element) { |
1804 if (hasPolyfillMutations) { | 1949 if (hasThrottledAttached) { |
1805 deferMutation(function() { | 1950 deferMutation(function() { |
1806 _detached(element); | 1951 _detached(element); |
1807 }); | 1952 }); |
1808 } else { | 1953 } else { |
1809 _detached(element); | 1954 _detached(element); |
1810 } | 1955 } |
1811 } | 1956 } |
1812 function _detached(element) { | 1957 function _detached(element) { |
1813 if (element.__upgraded__ && (element.attachedCallback || element.detachedCal
lback)) { | 1958 if (element.__upgraded__ && element.__attached) { |
1814 if (element.__attached && !inDocument(element)) { | 1959 element.__attached = false; |
1815 element.__attached = false; | 1960 if (element.detachedCallback) { |
1816 if (element.detachedCallback) { | 1961 element.detachedCallback(); |
1817 element.detachedCallback(); | |
1818 } | |
1819 } | 1962 } |
1820 } | 1963 } |
1821 } | 1964 } |
1822 function inDocument(element) { | 1965 function inDocument(element) { |
1823 var p = element; | 1966 var p = element; |
1824 var doc = wrap(document); | 1967 var doc = window.wrap(document); |
1825 while (p) { | 1968 while (p) { |
1826 if (p == doc) { | 1969 if (p == doc) { |
1827 return true; | 1970 return true; |
1828 } | 1971 } |
1829 p = p.parentNode || p.nodeType === Node.DOCUMENT_FRAGMENT_NODE && p.host; | 1972 p = p.parentNode || p.nodeType === Node.DOCUMENT_FRAGMENT_NODE && p.host; |
1830 } | 1973 } |
1831 } | 1974 } |
1832 function watchShadow(node) { | 1975 function watchShadow(node) { |
1833 if (node.shadowRoot && !node.shadowRoot.__watched) { | 1976 if (node.shadowRoot && !node.shadowRoot.__watched) { |
1834 flags.dom && console.log("watching shadow-root for: ", node.localName); | 1977 flags.dom && console.log("watching shadow-root for: ", node.localName); |
1835 var root = node.shadowRoot; | 1978 var root = node.shadowRoot; |
1836 while (root) { | 1979 while (root) { |
1837 observe(root); | 1980 observe(root); |
1838 root = root.olderShadowRoot; | 1981 root = root.olderShadowRoot; |
1839 } | 1982 } |
1840 } | 1983 } |
1841 } | 1984 } |
1842 function handler(mutations) { | 1985 function handler(root, mutations) { |
1843 if (flags.dom) { | 1986 if (flags.dom) { |
1844 var mx = mutations[0]; | 1987 var mx = mutations[0]; |
1845 if (mx && mx.type === "childList" && mx.addedNodes) { | 1988 if (mx && mx.type === "childList" && mx.addedNodes) { |
1846 if (mx.addedNodes) { | 1989 if (mx.addedNodes) { |
1847 var d = mx.addedNodes[0]; | 1990 var d = mx.addedNodes[0]; |
1848 while (d && d !== document && !d.host) { | 1991 while (d && d !== document && !d.host) { |
1849 d = d.parentNode; | 1992 d = d.parentNode; |
1850 } | 1993 } |
1851 var u = d && (d.URL || d._URL || d.host && d.host.localName) || ""; | 1994 var u = d && (d.URL || d._URL || d.host && d.host.localName) || ""; |
1852 u = u.split("/?").shift().split("/").pop(); | 1995 u = u.split("/?").shift().split("/").pop(); |
1853 } | 1996 } |
1854 } | 1997 } |
1855 console.group("mutations (%d) [%s]", mutations.length, u || ""); | 1998 console.group("mutations (%d) [%s]", mutations.length, u || ""); |
1856 } | 1999 } |
| 2000 var isAttached = inDocument(root); |
1857 mutations.forEach(function(mx) { | 2001 mutations.forEach(function(mx) { |
1858 if (mx.type === "childList") { | 2002 if (mx.type === "childList") { |
1859 forEach(mx.addedNodes, function(n) { | 2003 forEach(mx.addedNodes, function(n) { |
1860 if (!n.localName) { | 2004 if (!n.localName) { |
1861 return; | 2005 return; |
1862 } | 2006 } |
1863 addedNode(n); | 2007 addedNode(n, isAttached); |
1864 }); | 2008 }); |
1865 forEach(mx.removedNodes, function(n) { | 2009 forEach(mx.removedNodes, function(n) { |
1866 if (!n.localName) { | 2010 if (!n.localName) { |
1867 return; | 2011 return; |
1868 } | 2012 } |
1869 detachedNode(n); | 2013 detachedNode(n); |
1870 }); | 2014 }); |
1871 } | 2015 } |
1872 }); | 2016 }); |
1873 flags.dom && console.groupEnd(); | 2017 flags.dom && console.groupEnd(); |
1874 } | 2018 } |
1875 function takeRecords(node) { | 2019 function takeRecords(node) { |
1876 node = window.wrap(node); | 2020 node = window.wrap(node); |
1877 if (!node) { | 2021 if (!node) { |
1878 node = window.wrap(document); | 2022 node = window.wrap(document); |
1879 } | 2023 } |
1880 while (node.parentNode) { | 2024 while (node.parentNode) { |
1881 node = node.parentNode; | 2025 node = node.parentNode; |
1882 } | 2026 } |
1883 var observer = node.__observer; | 2027 var observer = node.__observer; |
1884 if (observer) { | 2028 if (observer) { |
1885 handler(observer.takeRecords()); | 2029 handler(node, observer.takeRecords()); |
1886 takeMutations(); | 2030 takeMutations(); |
1887 } | 2031 } |
1888 } | 2032 } |
1889 var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach); | 2033 var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach); |
1890 function observe(inRoot) { | 2034 function observe(inRoot) { |
1891 if (inRoot.__observer) { | 2035 if (inRoot.__observer) { |
1892 return; | 2036 return; |
1893 } | 2037 } |
1894 var observer = new MutationObserver(handler); | 2038 var observer = new MutationObserver(handler.bind(this, inRoot)); |
1895 observer.observe(inRoot, { | 2039 observer.observe(inRoot, { |
1896 childList: true, | 2040 childList: true, |
1897 subtree: true | 2041 subtree: true |
1898 }); | 2042 }); |
1899 inRoot.__observer = observer; | 2043 inRoot.__observer = observer; |
1900 } | 2044 } |
1901 function upgradeDocument(doc) { | 2045 function upgradeDocument(doc) { |
1902 doc = window.wrap(doc); | 2046 doc = window.wrap(doc); |
1903 flags.dom && console.group("upgradeDocument: ", doc.baseURI.split("/").pop()
); | 2047 flags.dom && console.group("upgradeDocument: ", doc.baseURI.split("/").pop()
); |
1904 addedNode(doc); | 2048 var isMainDocument = doc === window.wrap(document); |
| 2049 addedNode(doc, isMainDocument); |
1905 observe(doc); | 2050 observe(doc); |
1906 flags.dom && console.groupEnd(); | 2051 flags.dom && console.groupEnd(); |
1907 } | 2052 } |
1908 function upgradeDocumentTree(doc) { | 2053 function upgradeDocumentTree(doc) { |
1909 forDocumentTree(doc, upgradeDocument); | 2054 forDocumentTree(doc, upgradeDocument); |
1910 } | 2055 } |
1911 var originalCreateShadowRoot = Element.prototype.createShadowRoot; | 2056 var originalCreateShadowRoot = Element.prototype.createShadowRoot; |
1912 if (originalCreateShadowRoot) { | 2057 if (originalCreateShadowRoot) { |
1913 Element.prototype.createShadowRoot = function() { | 2058 Element.prototype.createShadowRoot = function() { |
1914 var root = originalCreateShadowRoot.call(this); | 2059 var root = originalCreateShadowRoot.call(this); |
1915 window.CustomElements.watchShadow(this); | 2060 window.CustomElements.watchShadow(this); |
1916 return root; | 2061 return root; |
1917 }; | 2062 }; |
1918 } | 2063 } |
1919 scope.watchShadow = watchShadow; | 2064 scope.watchShadow = watchShadow; |
1920 scope.upgradeDocumentTree = upgradeDocumentTree; | 2065 scope.upgradeDocumentTree = upgradeDocumentTree; |
| 2066 scope.upgradeDocument = upgradeDocument; |
1921 scope.upgradeSubtree = addedSubtree; | 2067 scope.upgradeSubtree = addedSubtree; |
1922 scope.upgradeAll = addedNode; | 2068 scope.upgradeAll = addedNode; |
1923 scope.attachedNode = attachedNode; | 2069 scope.attached = attached; |
1924 scope.takeRecords = takeRecords; | 2070 scope.takeRecords = takeRecords; |
1925 }); | 2071 }); |
1926 | 2072 |
1927 window.CustomElements.addModule(function(scope) { | 2073 window.CustomElements.addModule(function(scope) { |
1928 var flags = scope.flags; | 2074 var flags = scope.flags; |
1929 function upgrade(node) { | 2075 function upgrade(node, isAttached) { |
| 2076 if (node.localName === "template") { |
| 2077 if (window.HTMLTemplateElement && HTMLTemplateElement.decorate) { |
| 2078 HTMLTemplateElement.decorate(node); |
| 2079 } |
| 2080 } |
1930 if (!node.__upgraded__ && node.nodeType === Node.ELEMENT_NODE) { | 2081 if (!node.__upgraded__ && node.nodeType === Node.ELEMENT_NODE) { |
1931 var is = node.getAttribute("is"); | 2082 var is = node.getAttribute("is"); |
1932 var definition = scope.getRegisteredDefinition(is || node.localName); | 2083 var definition = scope.getRegisteredDefinition(node.localName) || scope.ge
tRegisteredDefinition(is); |
1933 if (definition) { | 2084 if (definition) { |
1934 if (is && definition.tag == node.localName) { | 2085 if (is && definition.tag == node.localName || !is && !definition.extends
) { |
1935 return upgradeWithDefinition(node, definition); | 2086 return upgradeWithDefinition(node, definition, isAttached); |
1936 } else if (!is && !definition.extends) { | |
1937 return upgradeWithDefinition(node, definition); | |
1938 } | 2087 } |
1939 } | 2088 } |
1940 } | 2089 } |
1941 } | 2090 } |
1942 function upgradeWithDefinition(element, definition) { | 2091 function upgradeWithDefinition(element, definition, isAttached) { |
1943 flags.upgrade && console.group("upgrade:", element.localName); | 2092 flags.upgrade && console.group("upgrade:", element.localName); |
1944 if (definition.is) { | 2093 if (definition.is) { |
1945 element.setAttribute("is", definition.is); | 2094 element.setAttribute("is", definition.is); |
1946 } | 2095 } |
1947 implementPrototype(element, definition); | 2096 implementPrototype(element, definition); |
1948 element.__upgraded__ = true; | 2097 element.__upgraded__ = true; |
1949 created(element); | 2098 created(element); |
1950 scope.attachedNode(element); | 2099 if (isAttached) { |
1951 scope.upgradeSubtree(element); | 2100 scope.attached(element); |
| 2101 } |
| 2102 scope.upgradeSubtree(element, isAttached); |
1952 flags.upgrade && console.groupEnd(); | 2103 flags.upgrade && console.groupEnd(); |
1953 return element; | 2104 return element; |
1954 } | 2105 } |
1955 function implementPrototype(element, definition) { | 2106 function implementPrototype(element, definition) { |
1956 if (Object.__proto__) { | 2107 if (Object.__proto__) { |
1957 element.__proto__ = definition.prototype; | 2108 element.__proto__ = definition.prototype; |
1958 } else { | 2109 } else { |
1959 customMixin(element, definition.prototype, definition.native); | 2110 customMixin(element, definition.prototype, definition.native); |
1960 element.__proto__ = definition.prototype; | 2111 element.__proto__ = definition.prototype; |
1961 } | 2112 } |
(...skipping 16 matching lines...) Expand all Loading... |
1978 if (element.createdCallback) { | 2129 if (element.createdCallback) { |
1979 element.createdCallback(); | 2130 element.createdCallback(); |
1980 } | 2131 } |
1981 } | 2132 } |
1982 scope.upgrade = upgrade; | 2133 scope.upgrade = upgrade; |
1983 scope.upgradeWithDefinition = upgradeWithDefinition; | 2134 scope.upgradeWithDefinition = upgradeWithDefinition; |
1984 scope.implementPrototype = implementPrototype; | 2135 scope.implementPrototype = implementPrototype; |
1985 }); | 2136 }); |
1986 | 2137 |
1987 window.CustomElements.addModule(function(scope) { | 2138 window.CustomElements.addModule(function(scope) { |
1988 var isIE11OrOlder = scope.isIE11OrOlder; | 2139 var isIE = scope.isIE; |
1989 var upgradeDocumentTree = scope.upgradeDocumentTree; | 2140 var upgradeDocumentTree = scope.upgradeDocumentTree; |
1990 var upgradeAll = scope.upgradeAll; | 2141 var upgradeAll = scope.upgradeAll; |
1991 var upgradeWithDefinition = scope.upgradeWithDefinition; | 2142 var upgradeWithDefinition = scope.upgradeWithDefinition; |
1992 var implementPrototype = scope.implementPrototype; | 2143 var implementPrototype = scope.implementPrototype; |
1993 var useNative = scope.useNative; | 2144 var useNative = scope.useNative; |
1994 function register(name, options) { | 2145 function register(name, options) { |
1995 var definition = options || {}; | 2146 var definition = options || {}; |
1996 if (!name) { | 2147 if (!name) { |
1997 throw new Error("document.registerElement: first argument `name` must not
be empty"); | 2148 throw new Error("document.registerElement: first argument `name` must not
be empty"); |
1998 } | 2149 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2069 definition.tag = baseTag || definition.__name; | 2220 definition.tag = baseTag || definition.__name; |
2070 if (baseTag) { | 2221 if (baseTag) { |
2071 definition.is = definition.__name; | 2222 definition.is = definition.__name; |
2072 } | 2223 } |
2073 } | 2224 } |
2074 function resolvePrototypeChain(definition) { | 2225 function resolvePrototypeChain(definition) { |
2075 if (!Object.__proto__) { | 2226 if (!Object.__proto__) { |
2076 var nativePrototype = HTMLElement.prototype; | 2227 var nativePrototype = HTMLElement.prototype; |
2077 if (definition.is) { | 2228 if (definition.is) { |
2078 var inst = document.createElement(definition.tag); | 2229 var inst = document.createElement(definition.tag); |
2079 var expectedPrototype = Object.getPrototypeOf(inst); | 2230 nativePrototype = Object.getPrototypeOf(inst); |
2080 if (expectedPrototype === definition.prototype) { | |
2081 nativePrototype = expectedPrototype; | |
2082 } | |
2083 } | 2231 } |
2084 var proto = definition.prototype, ancestor; | 2232 var proto = definition.prototype, ancestor; |
2085 while (proto && proto !== nativePrototype) { | 2233 var foundPrototype = false; |
| 2234 while (proto) { |
| 2235 if (proto == nativePrototype) { |
| 2236 foundPrototype = true; |
| 2237 } |
2086 ancestor = Object.getPrototypeOf(proto); | 2238 ancestor = Object.getPrototypeOf(proto); |
2087 proto.__proto__ = ancestor; | 2239 if (ancestor) { |
| 2240 proto.__proto__ = ancestor; |
| 2241 } |
2088 proto = ancestor; | 2242 proto = ancestor; |
2089 } | 2243 } |
| 2244 if (!foundPrototype) { |
| 2245 console.warn(definition.tag + " prototype not found in prototype chain f
or " + definition.is); |
| 2246 } |
2090 definition.native = nativePrototype; | 2247 definition.native = nativePrototype; |
2091 } | 2248 } |
2092 } | 2249 } |
2093 function instantiate(definition) { | 2250 function instantiate(definition) { |
2094 return upgradeWithDefinition(domCreateElement(definition.tag), definition); | 2251 return upgradeWithDefinition(domCreateElement(definition.tag), definition); |
2095 } | 2252 } |
2096 var registry = {}; | 2253 var registry = {}; |
2097 function getRegisteredDefinition(name) { | 2254 function getRegisteredDefinition(name) { |
2098 if (name) { | 2255 if (name) { |
2099 return registry[name.toLowerCase()]; | 2256 return registry[name.toLowerCase()]; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2141 if (tag.indexOf("-") >= 0) { | 2298 if (tag.indexOf("-") >= 0) { |
2142 implementPrototype(element, HTMLElement); | 2299 implementPrototype(element, HTMLElement); |
2143 } | 2300 } |
2144 return element; | 2301 return element; |
2145 } | 2302 } |
2146 var domCreateElement = document.createElement.bind(document); | 2303 var domCreateElement = document.createElement.bind(document); |
2147 var domCreateElementNS = document.createElementNS.bind(document); | 2304 var domCreateElementNS = document.createElementNS.bind(document); |
2148 var isInstance; | 2305 var isInstance; |
2149 if (!Object.__proto__ && !useNative) { | 2306 if (!Object.__proto__ && !useNative) { |
2150 isInstance = function(obj, ctor) { | 2307 isInstance = function(obj, ctor) { |
| 2308 if (obj instanceof ctor) { |
| 2309 return true; |
| 2310 } |
2151 var p = obj; | 2311 var p = obj; |
2152 while (p) { | 2312 while (p) { |
2153 if (p === ctor.prototype) { | 2313 if (p === ctor.prototype) { |
2154 return true; | 2314 return true; |
2155 } | 2315 } |
2156 p = p.__proto__; | 2316 p = p.__proto__; |
2157 } | 2317 } |
2158 return false; | 2318 return false; |
2159 }; | 2319 }; |
2160 } else { | 2320 } else { |
2161 isInstance = function(obj, base) { | 2321 isInstance = function(obj, base) { |
2162 return obj instanceof base; | 2322 return obj instanceof base; |
2163 }; | 2323 }; |
2164 } | 2324 } |
2165 function wrapDomMethodToForceUpgrade(obj, methodName) { | 2325 function wrapDomMethodToForceUpgrade(obj, methodName) { |
2166 var orig = obj[methodName]; | 2326 var orig = obj[methodName]; |
2167 obj[methodName] = function() { | 2327 obj[methodName] = function() { |
2168 var n = orig.apply(this, arguments); | 2328 var n = orig.apply(this, arguments); |
2169 upgradeAll(n); | 2329 upgradeAll(n); |
2170 return n; | 2330 return n; |
2171 }; | 2331 }; |
2172 } | 2332 } |
2173 wrapDomMethodToForceUpgrade(Node.prototype, "cloneNode"); | 2333 wrapDomMethodToForceUpgrade(Node.prototype, "cloneNode"); |
2174 wrapDomMethodToForceUpgrade(document, "importNode"); | 2334 wrapDomMethodToForceUpgrade(document, "importNode"); |
2175 if (isIE11OrOlder) { | 2335 if (isIE) { |
2176 (function() { | 2336 (function() { |
2177 var importNode = document.importNode; | 2337 var importNode = document.importNode; |
2178 document.importNode = function() { | 2338 document.importNode = function() { |
2179 var n = importNode.apply(document, arguments); | 2339 var n = importNode.apply(document, arguments); |
2180 if (n.nodeType == n.DOCUMENT_FRAGMENT_NODE) { | 2340 if (n.nodeType == n.DOCUMENT_FRAGMENT_NODE) { |
2181 var f = document.createDocumentFragment(); | 2341 var f = document.createDocumentFragment(); |
2182 f.appendChild(n); | 2342 f.appendChild(n); |
2183 return f; | 2343 return f; |
2184 } else { | 2344 } else { |
2185 return n; | 2345 return n; |
2186 } | 2346 } |
2187 }; | 2347 }; |
2188 })(); | 2348 })(); |
2189 } | 2349 } |
2190 document.registerElement = register; | 2350 document.registerElement = register; |
2191 document.createElement = createElement; | 2351 document.createElement = createElement; |
2192 document.createElementNS = createElementNS; | 2352 document.createElementNS = createElementNS; |
2193 scope.registry = registry; | 2353 scope.registry = registry; |
2194 scope.instanceof = isInstance; | 2354 scope.instanceof = isInstance; |
2195 scope.reservedTagList = reservedTagList; | 2355 scope.reservedTagList = reservedTagList; |
2196 scope.getRegisteredDefinition = getRegisteredDefinition; | 2356 scope.getRegisteredDefinition = getRegisteredDefinition; |
2197 document.register = document.registerElement; | 2357 document.register = document.registerElement; |
2198 }); | 2358 }); |
2199 | 2359 |
2200 (function(scope) { | 2360 (function(scope) { |
2201 var useNative = scope.useNative; | 2361 var useNative = scope.useNative; |
2202 var initializeModules = scope.initializeModules; | 2362 var initializeModules = scope.initializeModules; |
2203 var isIE11OrOlder = /Trident/.test(navigator.userAgent); | 2363 var isIE = scope.isIE; |
2204 if (useNative) { | 2364 if (useNative) { |
2205 var nop = function() {}; | 2365 var nop = function() {}; |
2206 scope.watchShadow = nop; | 2366 scope.watchShadow = nop; |
2207 scope.upgrade = nop; | 2367 scope.upgrade = nop; |
2208 scope.upgradeAll = nop; | 2368 scope.upgradeAll = nop; |
2209 scope.upgradeDocumentTree = nop; | 2369 scope.upgradeDocumentTree = nop; |
2210 scope.upgradeSubtree = nop; | 2370 scope.upgradeSubtree = nop; |
2211 scope.takeRecords = nop; | 2371 scope.takeRecords = nop; |
2212 scope.instanceof = function(obj, base) { | 2372 scope.instanceof = function(obj, base) { |
2213 return obj instanceof base; | 2373 return obj instanceof base; |
2214 }; | 2374 }; |
2215 } else { | 2375 } else { |
2216 initializeModules(); | 2376 initializeModules(); |
2217 } | 2377 } |
2218 var upgradeDocumentTree = scope.upgradeDocumentTree; | 2378 var upgradeDocumentTree = scope.upgradeDocumentTree; |
| 2379 var upgradeDocument = scope.upgradeDocument; |
2219 if (!window.wrap) { | 2380 if (!window.wrap) { |
2220 if (window.ShadowDOMPolyfill) { | 2381 if (window.ShadowDOMPolyfill) { |
2221 window.wrap = window.ShadowDOMPolyfill.wrapIfNeeded; | 2382 window.wrap = window.ShadowDOMPolyfill.wrapIfNeeded; |
2222 window.unwrap = window.ShadowDOMPolyfill.unwrapIfNeeded; | 2383 window.unwrap = window.ShadowDOMPolyfill.unwrapIfNeeded; |
2223 } else { | 2384 } else { |
2224 window.wrap = window.unwrap = function(node) { | 2385 window.wrap = window.unwrap = function(node) { |
2225 return node; | 2386 return node; |
2226 }; | 2387 }; |
2227 } | 2388 } |
2228 } | 2389 } |
| 2390 if (window.HTMLImports) { |
| 2391 window.HTMLImports.__importsParsingHook = function(elt) { |
| 2392 if (elt.import) { |
| 2393 upgradeDocument(wrap(elt.import)); |
| 2394 } |
| 2395 }; |
| 2396 } |
2229 function bootstrap() { | 2397 function bootstrap() { |
2230 upgradeDocumentTree(window.wrap(document)); | 2398 upgradeDocumentTree(window.wrap(document)); |
2231 if (window.HTMLImports) { | |
2232 window.HTMLImports.__importsParsingHook = function(elt) { | |
2233 upgradeDocumentTree(wrap(elt.import)); | |
2234 }; | |
2235 } | |
2236 window.CustomElements.ready = true; | 2399 window.CustomElements.ready = true; |
2237 setTimeout(function() { | 2400 var requestAnimationFrame = window.requestAnimationFrame || function(f) { |
2238 window.CustomElements.readyTime = Date.now(); | 2401 setTimeout(f, 16); |
2239 if (window.HTMLImports) { | 2402 }; |
2240 window.CustomElements.elapsed = window.CustomElements.readyTime - window
.HTMLImports.readyTime; | 2403 requestAnimationFrame(function() { |
2241 } | 2404 setTimeout(function() { |
2242 document.dispatchEvent(new CustomEvent("WebComponentsReady", { | 2405 window.CustomElements.readyTime = Date.now(); |
2243 bubbles: true | 2406 if (window.HTMLImports) { |
2244 })); | 2407 window.CustomElements.elapsed = window.CustomElements.readyTime - wind
ow.HTMLImports.readyTime; |
| 2408 } |
| 2409 document.dispatchEvent(new CustomEvent("WebComponentsReady", { |
| 2410 bubbles: true |
| 2411 })); |
| 2412 }); |
2245 }); | 2413 }); |
2246 } | 2414 } |
2247 if (isIE11OrOlder && typeof window.CustomEvent !== "function") { | |
2248 window.CustomEvent = function(inType, params) { | |
2249 params = params || {}; | |
2250 var e = document.createEvent("CustomEvent"); | |
2251 e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelab
le), params.detail); | |
2252 e.preventDefault = function() { | |
2253 Object.defineProperty(this, "defaultPrevented", { | |
2254 get: function() { | |
2255 return true; | |
2256 } | |
2257 }); | |
2258 }; | |
2259 return e; | |
2260 }; | |
2261 window.CustomEvent.prototype = window.Event.prototype; | |
2262 } | |
2263 if (document.readyState === "complete" || scope.flags.eager) { | 2415 if (document.readyState === "complete" || scope.flags.eager) { |
2264 bootstrap(); | 2416 bootstrap(); |
2265 } else if (document.readyState === "interactive" && !window.attachEvent && (!w
indow.HTMLImports || window.HTMLImports.ready)) { | 2417 } else if (document.readyState === "interactive" && !window.attachEvent && (!w
indow.HTMLImports || window.HTMLImports.ready)) { |
2266 bootstrap(); | 2418 bootstrap(); |
2267 } else { | 2419 } else { |
2268 var loadEvent = window.HTMLImports && !window.HTMLImports.ready ? "HTMLImpor
tsLoaded" : "DOMContentLoaded"; | 2420 var loadEvent = window.HTMLImports && !window.HTMLImports.ready ? "HTMLImpor
tsLoaded" : "DOMContentLoaded"; |
2269 window.addEventListener(loadEvent, bootstrap); | 2421 window.addEventListener(loadEvent, bootstrap); |
2270 } | 2422 } |
2271 scope.isIE11OrOlder = isIE11OrOlder; | |
2272 })(window.CustomElements); | 2423 })(window.CustomElements); |
2273 | 2424 |
2274 if (typeof HTMLTemplateElement === "undefined") { | |
2275 (function() { | |
2276 var TEMPLATE_TAG = "template"; | |
2277 HTMLTemplateElement = function() {}; | |
2278 HTMLTemplateElement.prototype = Object.create(HTMLElement.prototype); | |
2279 HTMLTemplateElement.decorate = function(template) { | |
2280 if (!template.content) { | |
2281 template.content = template.ownerDocument.createDocumentFragment(); | |
2282 } | |
2283 var child; | |
2284 while (child = template.firstChild) { | |
2285 template.content.appendChild(child); | |
2286 } | |
2287 }; | |
2288 HTMLTemplateElement.bootstrap = function(doc) { | |
2289 var templates = doc.querySelectorAll(TEMPLATE_TAG); | |
2290 for (var i = 0, l = templates.length, t; i < l && (t = templates[i]); i++)
{ | |
2291 HTMLTemplateElement.decorate(t); | |
2292 } | |
2293 }; | |
2294 window.addEventListener("DOMContentLoaded", function() { | |
2295 HTMLTemplateElement.bootstrap(document); | |
2296 }); | |
2297 var createElement = document.createElement; | |
2298 document.createElement = function() { | |
2299 "use strict"; | |
2300 var el = createElement.apply(document, arguments); | |
2301 if (el.localName == "template") { | |
2302 HTMLTemplateElement.decorate(el); | |
2303 } | |
2304 return el; | |
2305 }; | |
2306 })(); | |
2307 } | |
2308 | |
2309 (function(scope) { | 2425 (function(scope) { |
2310 var style = document.createElement("style"); | 2426 var style = document.createElement("style"); |
2311 style.textContent = "" + "body {" + "transition: opacity ease-in 0.2s;" + " }
\n" + "body[unresolved] {" + "opacity: 0; display: block; overflow: hidden; posi
tion: relative;" + " } \n"; | 2427 style.textContent = "" + "body {" + "transition: opacity ease-in 0.2s;" + " }
\n" + "body[unresolved] {" + "opacity: 0; display: block; overflow: hidden; posi
tion: relative;" + " } \n"; |
2312 var head = document.querySelector("head"); | 2428 var head = document.querySelector("head"); |
2313 head.insertBefore(style, head.firstChild); | 2429 head.insertBefore(style, head.firstChild); |
2314 })(window.WebComponents); | 2430 })(window.WebComponents); |
OLD | NEW |