3
* Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7
* Code distributed by Google as part of the polymer project is also
8
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11
if (typeof WeakMap === "undefined") {
13
var defineProperty = Object.defineProperty;
14
var counter = Date.now() % 1e9;
15
var WeakMap = function() {
16
this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__");
19
set: function(key, value) {
20
var entry = key[this.name];
21
if (entry && entry[0] === key) entry[1] = value; else defineProperty(key, this.name, {
22
value: [ key, value ],
29
return (entry = key[this.name]) && entry[0] === key ? entry[1] : undefined;
31
"delete": function(key) {
32
var entry = key[this.name];
33
if (!entry || entry[0] !== key) return false;
34
entry[0] = entry[1] = undefined;
38
var entry = key[this.name];
39
if (!entry) return false;
40
return entry[0] === key;
43
window.WeakMap = WeakMap;
48
if (global.JsMutationObserver) {
51
var registrationsTable = new WeakMap();
53
if (/Trident|Edge/.test(navigator.userAgent)) {
54
setImmediate = setTimeout;
55
} else if (window.setImmediate) {
56
setImmediate = window.setImmediate;
58
var setImmediateQueue = [];
59
var sentinel = String(Math.random());
60
window.addEventListener("message", function(e) {
61
if (e.data === sentinel) {
62
var queue = setImmediateQueue;
63
setImmediateQueue = [];
64
queue.forEach(function(func) {
69
setImmediate = function(func) {
70
setImmediateQueue.push(func);
71
window.postMessage(sentinel, "*");
74
var isScheduled = false;
75
var scheduledObservers = [];
76
function scheduleCallback(observer) {
77
scheduledObservers.push(observer);
80
setImmediate(dispatchCallbacks);
83
function wrapIfNeeded(node) {
84
return window.ShadowDOMPolyfill && window.ShadowDOMPolyfill.wrapIfNeeded(node) || node;
86
function dispatchCallbacks() {
88
var observers = scheduledObservers;
89
scheduledObservers = [];
90
observers.sort(function(o1, o2) {
91
return o1.uid_ - o2.uid_;
93
var anyNonEmpty = false;
94
observers.forEach(function(observer) {
95
var queue = observer.takeRecords();
96
removeTransientObserversFor(observer);
98
observer.callback_(queue, observer);
102
if (anyNonEmpty) dispatchCallbacks();
104
function removeTransientObserversFor(observer) {
105
observer.nodes_.forEach(function(node) {
106
var registrations = registrationsTable.get(node);
107
if (!registrations) return;
108
registrations.forEach(function(registration) {
109
if (registration.observer === observer) registration.removeTransientObservers();
113
function forEachAncestorAndObserverEnqueueRecord(target, callback) {
114
for (var node = target; node; node = node.parentNode) {
115
var registrations = registrationsTable.get(node);
117
for (var j = 0; j < registrations.length; j++) {
118
var registration = registrations[j];
119
var options = registration.options;
120
if (node !== target && !options.subtree) continue;
121
var record = callback(options);
122
if (record) registration.enqueue(record);
128
function JsMutationObserver(callback) {
129
this.callback_ = callback;
132
this.uid_ = ++uidCounter;
134
JsMutationObserver.prototype = {
135
observe: function(target, options) {
136
target = wrapIfNeeded(target);
137
if (!options.childList && !options.attributes && !options.characterData || options.attributeOldValue && !options.attributes || options.attributeFilter && options.attributeFilter.length && !options.attributes || options.characterDataOldValue && !options.characterData) {
138
throw new SyntaxError();
140
var registrations = registrationsTable.get(target);
141
if (!registrations) registrationsTable.set(target, registrations = []);
143
for (var i = 0; i < registrations.length; i++) {
144
if (registrations[i].observer === this) {
145
registration = registrations[i];
146
registration.removeListeners();
147
registration.options = options;
152
registration = new Registration(this, target, options);
153
registrations.push(registration);
154
this.nodes_.push(target);
156
registration.addListeners();
158
disconnect: function() {
159
this.nodes_.forEach(function(node) {
160
var registrations = registrationsTable.get(node);
161
for (var i = 0; i < registrations.length; i++) {
162
var registration = registrations[i];
163
if (registration.observer === this) {
164
registration.removeListeners();
165
registrations.splice(i, 1);
172
takeRecords: function() {
173
var copyOfRecords = this.records_;
175
return copyOfRecords;
178
function MutationRecord(type, target) {
180
this.target = target;
181
this.addedNodes = [];
182
this.removedNodes = [];
183
this.previousSibling = null;
184
this.nextSibling = null;
185
this.attributeName = null;
186
this.attributeNamespace = null;
187
this.oldValue = null;
189
function copyMutationRecord(original) {
190
var record = new MutationRecord(original.type, original.target);
191
record.addedNodes = original.addedNodes.slice();
192
record.removedNodes = original.removedNodes.slice();
193
record.previousSibling = original.previousSibling;
194
record.nextSibling = original.nextSibling;
195
record.attributeName = original.attributeName;
196
record.attributeNamespace = original.attributeNamespace;
197
record.oldValue = original.oldValue;
200
var currentRecord, recordWithOldValue;
201
function getRecord(type, target) {
202
return currentRecord = new MutationRecord(type, target);
204
function getRecordWithOldValue(oldValue) {
205
if (recordWithOldValue) return recordWithOldValue;
206
recordWithOldValue = copyMutationRecord(currentRecord);
207
recordWithOldValue.oldValue = oldValue;
208
return recordWithOldValue;
210
function clearRecords() {
211
currentRecord = recordWithOldValue = undefined;
213
function recordRepresentsCurrentMutation(record) {
214
return record === recordWithOldValue || record === currentRecord;
216
function selectRecord(lastRecord, newRecord) {
217
if (lastRecord === newRecord) return lastRecord;
218
if (recordWithOldValue && recordRepresentsCurrentMutation(lastRecord)) return recordWithOldValue;
221
function Registration(observer, target, options) {
222
this.observer = observer;
223
this.target = target;
224
this.options = options;
225
this.transientObservedNodes = [];
227
Registration.prototype = {
228
enqueue: function(record) {
229
var records = this.observer.records_;
230
var length = records.length;
231
if (records.length > 0) {
232
var lastRecord = records[length - 1];
233
var recordToReplaceLast = selectRecord(lastRecord, record);
234
if (recordToReplaceLast) {
235
records[length - 1] = recordToReplaceLast;
239
scheduleCallback(this.observer);
241
records[length] = record;
243
addListeners: function() {
244
this.addListeners_(this.target);
246
addListeners_: function(node) {
247
var options = this.options;
248
if (options.attributes) node.addEventListener("DOMAttrModified", this, true);
249
if (options.characterData) node.addEventListener("DOMCharacterDataModified", this, true);
250
if (options.childList) node.addEventListener("DOMNodeInserted", this, true);
251
if (options.childList || options.subtree) node.addEventListener("DOMNodeRemoved", this, true);
253
removeListeners: function() {
254
this.removeListeners_(this.target);
256
removeListeners_: function(node) {
257
var options = this.options;
258
if (options.attributes) node.removeEventListener("DOMAttrModified", this, true);
259
if (options.characterData) node.removeEventListener("DOMCharacterDataModified", this, true);
260
if (options.childList) node.removeEventListener("DOMNodeInserted", this, true);
261
if (options.childList || options.subtree) node.removeEventListener("DOMNodeRemoved", this, true);
263
addTransientObserver: function(node) {
264
if (node === this.target) return;
265
this.addListeners_(node);
266
this.transientObservedNodes.push(node);
267
var registrations = registrationsTable.get(node);
268
if (!registrations) registrationsTable.set(node, registrations = []);
269
registrations.push(this);
271
removeTransientObservers: function() {
272
var transientObservedNodes = this.transientObservedNodes;
273
this.transientObservedNodes = [];
274
transientObservedNodes.forEach(function(node) {
275
this.removeListeners_(node);
276
var registrations = registrationsTable.get(node);
277
for (var i = 0; i < registrations.length; i++) {
278
if (registrations[i] === this) {
279
registrations.splice(i, 1);
285
handleEvent: function(e) {
286
e.stopImmediatePropagation();
288
case "DOMAttrModified":
289
var name = e.attrName;
290
var namespace = e.relatedNode.namespaceURI;
291
var target = e.target;
292
var record = new getRecord("attributes", target);
293
record.attributeName = name;
294
record.attributeNamespace = namespace;
295
var oldValue = e.attrChange === MutationEvent.ADDITION ? null : e.prevValue;
296
forEachAncestorAndObserverEnqueueRecord(target, function(options) {
297
if (!options.attributes) return;
298
if (options.attributeFilter && options.attributeFilter.length && options.attributeFilter.indexOf(name) === -1 && options.attributeFilter.indexOf(namespace) === -1) {
301
if (options.attributeOldValue) return getRecordWithOldValue(oldValue);
306
case "DOMCharacterDataModified":
307
var target = e.target;
308
var record = getRecord("characterData", target);
309
var oldValue = e.prevValue;
310
forEachAncestorAndObserverEnqueueRecord(target, function(options) {
311
if (!options.characterData) return;
312
if (options.characterDataOldValue) return getRecordWithOldValue(oldValue);
317
case "DOMNodeRemoved":
318
this.addTransientObserver(e.target);
320
case "DOMNodeInserted":
321
var changedNode = e.target;
322
var addedNodes, removedNodes;
323
if (e.type === "DOMNodeInserted") {
324
addedNodes = [ changedNode ];
328
removedNodes = [ changedNode ];
330
var previousSibling = changedNode.previousSibling;
331
var nextSibling = changedNode.nextSibling;
332
var record = getRecord("childList", e.target.parentNode);
333
record.addedNodes = addedNodes;
334
record.removedNodes = removedNodes;
335
record.previousSibling = previousSibling;
336
record.nextSibling = nextSibling;
337
forEachAncestorAndObserverEnqueueRecord(e.relatedNode, function(options) {
338
if (!options.childList) return;
345
global.JsMutationObserver = JsMutationObserver;
346
if (!global.MutationObserver) {
347
global.MutationObserver = JsMutationObserver;
348
JsMutationObserver._isPolyfilled = true;
354
if (!window.performance) {
355
var start = Date.now();
356
window.performance = {
358
return Date.now() - start;
362
if (!window.requestAnimationFrame) {
363
window.requestAnimationFrame = function() {
364
var nativeRaf = window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame;
365
return nativeRaf ? function(callback) {
366
return nativeRaf(function() {
367
callback(performance.now());
369
} : function(callback) {
370
return window.setTimeout(callback, 1e3 / 60);
374
if (!window.cancelAnimationFrame) {
375
window.cancelAnimationFrame = function() {
376
return window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || function(id) {
381
var workingDefaultPrevented = function() {
382
var e = document.createEvent("Event");
383
e.initEvent("foo", true, true);
385
return e.defaultPrevented;
387
if (!workingDefaultPrevented) {
388
var origPreventDefault = Event.prototype.preventDefault;
389
Event.prototype.preventDefault = function() {
390
if (!this.cancelable) {
393
origPreventDefault.call(this);
394
Object.defineProperty(this, "defaultPrevented", {
402
var isIE = /Trident/.test(navigator.userAgent);
403
if (!window.CustomEvent || isIE && typeof window.CustomEvent !== "function") {
404
window.CustomEvent = function(inType, params) {
405
params = params || {};
406
var e = document.createEvent("CustomEvent");
407
e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable), params.detail);
410
window.CustomEvent.prototype = window.Event.prototype;
412
if (!window.Event || isIE && typeof window.Event !== "function") {
413
var origEvent = window.Event;
414
window.Event = function(inType, params) {
415
params = params || {};
416
var e = document.createEvent("Event");
417
e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable));
420
window.Event.prototype = origEvent.prototype;
422
})(window.WebComponents);
424
window.HTMLImports = window.HTMLImports || {
429
var IMPORT_LINK_TYPE = "import";
430
var useNative = Boolean(IMPORT_LINK_TYPE in document.createElement("link"));
431
var hasShadowDOMPolyfill = Boolean(window.ShadowDOMPolyfill);
432
var wrap = function(node) {
433
return hasShadowDOMPolyfill ? window.ShadowDOMPolyfill.wrapIfNeeded(node) : node;
435
var rootDocument = wrap(document);
436
var currentScriptDescriptor = {
438
var script = window.HTMLImports.currentScript || document.currentScript || (document.readyState !== "complete" ? document.scripts[document.scripts.length - 1] : null);
443
Object.defineProperty(document, "_currentScript", currentScriptDescriptor);
444
Object.defineProperty(rootDocument, "_currentScript", currentScriptDescriptor);
445
var isIE = /Trident/.test(navigator.userAgent);
446
function whenReady(callback, doc) {
447
doc = doc || rootDocument;
448
whenDocumentReady(function() {
449
watchImportsLoad(callback, doc);
452
var requiredReadyState = isIE ? "complete" : "interactive";
453
var READY_EVENT = "readystatechange";
454
function isDocumentReady(doc) {
455
return doc.readyState === "complete" || doc.readyState === requiredReadyState;
457
function whenDocumentReady(callback, doc) {
458
if (!isDocumentReady(doc)) {
459
var checkReady = function() {
460
if (doc.readyState === "complete" || doc.readyState === requiredReadyState) {
461
doc.removeEventListener(READY_EVENT, checkReady);
462
whenDocumentReady(callback, doc);
465
doc.addEventListener(READY_EVENT, checkReady);
466
} else if (callback) {
470
function markTargetLoaded(event) {
471
event.target.__loaded = true;
473
function watchImportsLoad(callback, doc) {
474
var imports = doc.querySelectorAll("link[rel=import]");
475
var parsedCount = 0, importCount = imports.length, newImports = [], errorImports = [];
476
function checkDone() {
477
if (parsedCount == importCount && callback) {
480
loadedImports: newImports,
481
errorImports: errorImports
485
function loadedImport(e) {
487
newImports.push(this);
491
function errorLoadingImport(e) {
492
errorImports.push(this);
497
for (var i = 0, imp; i < importCount && (imp = imports[i]); i++) {
498
if (isImportLoaded(imp)) {
499
newImports.push(this);
503
imp.addEventListener("load", loadedImport);
504
imp.addEventListener("error", errorLoadingImport);
511
function isImportLoaded(link) {
512
return useNative ? link.__loaded || link.import && link.import.readyState !== "loading" : link.__importParsed;
515
new MutationObserver(function(mxns) {
516
for (var i = 0, l = mxns.length, m; i < l && (m = mxns[i]); i++) {
518
handleImports(m.addedNodes);
521
}).observe(document.head, {
524
function handleImports(nodes) {
525
for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
531
function isImport(element) {
532
return element.localName === "link" && element.rel === "import";
534
function handleImport(element) {
535
var loaded = element.import;
541
element.addEventListener("load", markTargetLoaded);
542
element.addEventListener("error", markTargetLoaded);
546
if (document.readyState === "loading") {
547
var imports = document.querySelectorAll("link[rel=import]");
548
for (var i = 0, l = imports.length, imp; i < l && (imp = imports[i]); i++) {
554
whenReady(function(detail) {
555
window.HTMLImports.ready = true;
556
window.HTMLImports.readyTime = new Date().getTime();
557
var evt = rootDocument.createEvent("CustomEvent");
558
evt.initCustomEvent("HTMLImportsLoaded", true, true, detail);
559
rootDocument.dispatchEvent(evt);
561
scope.IMPORT_LINK_TYPE = IMPORT_LINK_TYPE;
562
scope.useNative = useNative;
563
scope.rootDocument = rootDocument;
564
scope.whenReady = whenReady;
566
})(window.HTMLImports);
570
var addModule = function(module) {
571
modules.push(module);
573
var initializeModules = function() {
574
modules.forEach(function(module) {
578
scope.addModule = addModule;
579
scope.initializeModules = initializeModules;
580
})(window.HTMLImports);
582
window.HTMLImports.addModule(function(scope) {
583
var CSS_URL_REGEXP = /(url\()([^)]*)(\))/g;
584
var CSS_IMPORT_REGEXP = /(@import[\s]+(?!url\())([^;]*)(;)/g;
586
resolveUrlsInStyle: function(style, linkUrl) {
587
var doc = style.ownerDocument;
588
var resolver = doc.createElement("a");
589
style.textContent = this.resolveUrlsInCssText(style.textContent, linkUrl, resolver);
592
resolveUrlsInCssText: function(cssText, linkUrl, urlObj) {
593
var r = this.replaceUrls(cssText, urlObj, linkUrl, CSS_URL_REGEXP);
594
r = this.replaceUrls(r, urlObj, linkUrl, CSS_IMPORT_REGEXP);
597
replaceUrls: function(text, urlObj, linkUrl, regexp) {
598
return text.replace(regexp, function(m, pre, url, post) {
599
var urlPath = url.replace(/["']/g, "");
601
urlPath = new URL(urlPath, linkUrl).href;
603
urlObj.href = urlPath;
604
urlPath = urlObj.href;
605
return pre + "'" + urlPath + "'" + post;
612
window.HTMLImports.addModule(function(scope) {
615
ok: function(request) {
616
return request.status >= 200 && request.status < 300 || request.status === 304 || request.status === 0;
618
load: function(url, next, nextContext) {
619
var request = new XMLHttpRequest();
620
if (scope.flags.debug || scope.flags.bust) {
621
url += "?" + Math.random();
623
request.open("GET", url, xhr.async);
624
request.addEventListener("readystatechange", function(e) {
625
if (request.readyState === 4) {
626
var redirectedUrl = null;
628
var locationHeader = request.getResponseHeader("Location");
629
if (locationHeader) {
630
redirectedUrl = locationHeader.substr(0, 1) === "/" ? location.origin + locationHeader : locationHeader;
633
console.error(e.message);
635
next.call(nextContext, !xhr.ok(request) && request, request.response || request.responseText, redirectedUrl);
641
loadDocument: function(url, next, nextContext) {
642
this.load(url, next, nextContext).responseType = "document";
648
window.HTMLImports.addModule(function(scope) {
650
var flags = scope.flags;
651
var Loader = function(onLoad, onComplete) {
653
this.onload = onLoad;
654
this.oncomplete = onComplete;
659
addNodes: function(nodes) {
660
this.inflight += nodes.length;
661
for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
666
addNode: function(node) {
671
require: function(elt) {
672
var url = elt.src || elt.href;
674
if (!this.dedupe(url, elt)) {
675
this.fetch(url, elt);
678
dedupe: function(url, elt) {
679
if (this.pending[url]) {
680
this.pending[url].push(elt);
684
if (this.cache[url]) {
685
this.onload(url, elt, this.cache[url]);
689
this.pending[url] = [ elt ];
692
fetch: function(url, elt) {
693
flags.load && console.log("fetch", url, elt);
695
setTimeout(function() {
696
this.receive(url, elt, {
697
error: "href must be specified"
700
} else if (url.match(/^data:/)) {
701
var pieces = url.split(",");
702
var header = pieces[0];
703
var body = pieces[1];
704
if (header.indexOf(";base64") > -1) {
707
body = decodeURIComponent(body);
709
setTimeout(function() {
710
this.receive(url, elt, null, body);
713
var receiveXhr = function(err, resource, redirectedUrl) {
714
this.receive(url, elt, err, resource, redirectedUrl);
716
xhr.load(url, receiveXhr);
719
receive: function(url, elt, err, resource, redirectedUrl) {
720
this.cache[url] = resource;
721
var $p = this.pending[url];
722
for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) {
723
this.onload(url, p, resource, err, redirectedUrl);
726
this.pending[url] = null;
732
checkDone: function() {
733
if (!this.inflight) {
738
scope.Loader = Loader;
741
window.HTMLImports.addModule(function(scope) {
742
var Observer = function(addCallback) {
743
this.addCallback = addCallback;
744
this.mo = new MutationObserver(this.handler.bind(this));
746
Observer.prototype = {
747
handler: function(mutations) {
748
for (var i = 0, l = mutations.length, m; i < l && (m = mutations[i]); i++) {
749
if (m.type === "childList" && m.addedNodes.length) {
750
this.addedNodes(m.addedNodes);
754
addedNodes: function(nodes) {
755
if (this.addCallback) {
756
this.addCallback(nodes);
758
for (var i = 0, l = nodes.length, n, loading; i < l && (n = nodes[i]); i++) {
759
if (n.children && n.children.length) {
760
this.addedNodes(n.children);
764
observe: function(root) {
765
this.mo.observe(root, {
771
scope.Observer = Observer;
774
window.HTMLImports.addModule(function(scope) {
775
var path = scope.path;
776
var rootDocument = scope.rootDocument;
777
var flags = scope.flags;
778
var isIE = scope.isIE;
779
var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE;
780
var IMPORT_SELECTOR = "link[rel=" + IMPORT_LINK_TYPE + "]";
782
documentSelectors: IMPORT_SELECTOR,
783
importsSelectors: [ IMPORT_SELECTOR, "link[rel=stylesheet]:not([type])", "style:not([type])", "script:not([type])", 'script[type="application/javascript"]', 'script[type="text/javascript"]' ].join(","),
786
script: "parseScript",
790
parseNext: function() {
791
var next = this.nextToParse();
796
parse: function(elt) {
797
if (this.isParsed(elt)) {
798
flags.parse && console.log("[%s] is already parsed", elt.localName);
801
var fn = this[this.map[elt.localName]];
803
this.markParsing(elt);
807
parseDynamic: function(elt, quiet) {
808
this.dynamicElements.push(elt);
813
markParsing: function(elt) {
814
flags.parse && console.log("parsing", elt);
815
this.parsingElement = elt;
817
markParsingComplete: function(elt) {
818
elt.__importParsed = true;
819
this.markDynamicParsingComplete(elt);
820
if (elt.__importElement) {
821
elt.__importElement.__importParsed = true;
822
this.markDynamicParsingComplete(elt.__importElement);
824
this.parsingElement = null;
825
flags.parse && console.log("completed", elt);
827
markDynamicParsingComplete: function(elt) {
828
var i = this.dynamicElements.indexOf(elt);
830
this.dynamicElements.splice(i, 1);
833
parseImport: function(elt) {
834
elt.import = elt.__doc;
835
if (window.HTMLImports.__importsParsingHook) {
836
window.HTMLImports.__importsParsingHook(elt);
839
elt.import.__importParsed = true;
841
this.markParsingComplete(elt);
842
if (elt.__resource && !elt.__error) {
843
elt.dispatchEvent(new CustomEvent("load", {
847
elt.dispatchEvent(new CustomEvent("error", {
853
while (elt.__pending.length) {
854
fn = elt.__pending.shift();
864
parseLink: function(linkElt) {
865
if (nodeIsImport(linkElt)) {
866
this.parseImport(linkElt);
868
linkElt.href = linkElt.href;
869
this.parseGeneric(linkElt);
872
parseStyle: function(elt) {
874
elt = cloneStyle(elt);
875
src.__appliedElement = elt;
876
elt.__importElement = src;
877
this.parseGeneric(elt);
879
parseGeneric: function(elt) {
880
this.trackElement(elt);
881
this.addElementToDocument(elt);
883
rootImportForElement: function(elt) {
885
while (n.ownerDocument.__importLink) {
886
n = n.ownerDocument.__importLink;
890
addElementToDocument: function(elt) {
891
var port = this.rootImportForElement(elt.__importElement || elt);
892
port.parentNode.insertBefore(elt, port);
894
trackElement: function(elt, callback) {
896
var done = function(e) {
897
elt.removeEventListener("load", done);
898
elt.removeEventListener("error", done);
902
self.markParsingComplete(elt);
905
elt.addEventListener("load", done);
906
elt.addEventListener("error", done);
907
if (isIE && elt.localName === "style") {
908
var fakeLoad = false;
909
if (elt.textContent.indexOf("@import") == -1) {
911
} else if (elt.sheet) {
913
var csr = elt.sheet.cssRules;
914
var len = csr ? csr.length : 0;
915
for (var i = 0, r; i < len && (r = csr[i]); i++) {
916
if (r.type === CSSRule.IMPORT_RULE) {
917
fakeLoad = fakeLoad && Boolean(r.styleSheet);
922
setTimeout(function() {
923
elt.dispatchEvent(new CustomEvent("load", {
930
parseScript: function(scriptElt) {
931
var script = document.createElement("script");
932
script.__importElement = scriptElt;
933
script.src = scriptElt.src ? scriptElt.src : generateScriptDataUrl(scriptElt);
934
scope.currentScript = scriptElt;
935
this.trackElement(script, function(e) {
936
if (script.parentNode) {
937
script.parentNode.removeChild(script);
939
scope.currentScript = null;
941
this.addElementToDocument(script);
943
nextToParse: function() {
945
return !this.parsingElement && (this.nextToParseInDoc(rootDocument) || this.nextToParseDynamic());
947
nextToParseInDoc: function(doc, link) {
948
if (doc && this._mayParse.indexOf(doc) < 0) {
949
this._mayParse.push(doc);
950
var nodes = doc.querySelectorAll(this.parseSelectorsForNode(doc));
951
for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
952
if (!this.isParsed(n)) {
953
if (this.hasResource(n)) {
954
return nodeIsImport(n) ? this.nextToParseInDoc(n.__doc, n) : n;
963
nextToParseDynamic: function() {
964
return this.dynamicElements[0];
966
parseSelectorsForNode: function(node) {
967
var doc = node.ownerDocument || node;
968
return doc === rootDocument ? this.documentSelectors : this.importsSelectors;
970
isParsed: function(node) {
971
return node.__importParsed;
973
needsDynamicParsing: function(elt) {
974
return this.dynamicElements.indexOf(elt) >= 0;
976
hasResource: function(node) {
977
if (nodeIsImport(node) && node.__doc === undefined) {
983
function nodeIsImport(elt) {
984
return elt.localName === "link" && elt.rel === IMPORT_LINK_TYPE;
986
function generateScriptDataUrl(script) {
987
var scriptContent = generateScriptContent(script);
988
return "data:text/javascript;charset=utf-8," + encodeURIComponent(scriptContent);
990
function generateScriptContent(script) {
991
return script.textContent + generateSourceMapHint(script);
993
function generateSourceMapHint(script) {
994
var owner = script.ownerDocument;
995
owner.__importedScripts = owner.__importedScripts || 0;
996
var moniker = script.ownerDocument.baseURI;
997
var num = owner.__importedScripts ? "-" + owner.__importedScripts : "";
998
owner.__importedScripts++;
999
return "\n//# sourceURL=" + moniker + num + ".js\n";
1001
function cloneStyle(style) {
1002
var clone = style.ownerDocument.createElement("style");
1003
clone.textContent = style.textContent;
1004
path.resolveUrlsInStyle(clone);
1007
scope.parser = importParser;
1008
scope.IMPORT_SELECTOR = IMPORT_SELECTOR;
1011
window.HTMLImports.addModule(function(scope) {
1012
var flags = scope.flags;
1013
var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE;
1014
var IMPORT_SELECTOR = scope.IMPORT_SELECTOR;
1015
var rootDocument = scope.rootDocument;
1016
var Loader = scope.Loader;
1017
var Observer = scope.Observer;
1018
var parser = scope.parser;
1021
documentPreloadSelectors: IMPORT_SELECTOR,
1022
importsPreloadSelectors: [ IMPORT_SELECTOR ].join(","),
1023
loadNode: function(node) {
1024
importLoader.addNode(node);
1026
loadSubtree: function(parent) {
1027
var nodes = this.marshalNodes(parent);
1028
importLoader.addNodes(nodes);
1030
marshalNodes: function(parent) {
1031
return parent.querySelectorAll(this.loadSelectorsForNode(parent));
1033
loadSelectorsForNode: function(node) {
1034
var doc = node.ownerDocument || node;
1035
return doc === rootDocument ? this.documentPreloadSelectors : this.importsPreloadSelectors;
1037
loaded: function(url, elt, resource, err, redirectedUrl) {
1038
flags.load && console.log("loaded", url, elt);
1039
elt.__resource = resource;
1041
if (isImportLink(elt)) {
1042
var doc = this.documents[url];
1043
if (doc === undefined) {
1044
doc = err ? null : makeDocument(resource, redirectedUrl || url);
1046
doc.__importLink = elt;
1047
this.bootDocument(doc);
1049
this.documents[url] = doc;
1055
bootDocument: function(doc) {
1056
this.loadSubtree(doc);
1057
this.observer.observe(doc);
1060
loadedAll: function() {
1064
var importLoader = new Loader(importer.loaded.bind(importer), importer.loadedAll.bind(importer));
1065
importer.observer = new Observer();
1066
function isImportLink(elt) {
1067
return isLinkRel(elt, IMPORT_LINK_TYPE);
1069
function isLinkRel(elt, rel) {
1070
return elt.localName === "link" && elt.getAttribute("rel") === rel;
1072
function hasBaseURIAccessor(doc) {
1073
return !!Object.getOwnPropertyDescriptor(doc, "baseURI");
1075
function makeDocument(resource, url) {
1076
var doc = document.implementation.createHTMLDocument(IMPORT_LINK_TYPE);
1078
var base = doc.createElement("base");
1079
base.setAttribute("href", url);
1080
if (!doc.baseURI && !hasBaseURIAccessor(doc)) {
1081
Object.defineProperty(doc, "baseURI", {
1085
var meta = doc.createElement("meta");
1086
meta.setAttribute("charset", "utf-8");
1087
doc.head.appendChild(meta);
1088
doc.head.appendChild(base);
1089
doc.body.innerHTML = resource;
1090
if (window.HTMLTemplateElement && HTMLTemplateElement.bootstrap) {
1091
HTMLTemplateElement.bootstrap(doc);
1095
if (!document.baseURI) {
1096
var baseURIDescriptor = {
1098
var base = document.querySelector("base");
1099
return base ? base.href : window.location.href;
1103
Object.defineProperty(document, "baseURI", baseURIDescriptor);
1104
Object.defineProperty(rootDocument, "baseURI", baseURIDescriptor);
1106
scope.importer = importer;
1107
scope.importLoader = importLoader;
1110
window.HTMLImports.addModule(function(scope) {
1111
var parser = scope.parser;
1112
var importer = scope.importer;
1114
added: function(nodes) {
1115
var owner, parsed, loading;
1116
for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
1118
owner = n.ownerDocument;
1119
parsed = parser.isParsed(owner);
1121
loading = this.shouldLoadNode(n);
1123
importer.loadNode(n);
1125
if (this.shouldParseNode(n) && parsed) {
1126
parser.parseDynamic(n, loading);
1130
shouldLoadNode: function(node) {
1131
return node.nodeType === 1 && matches.call(node, importer.loadSelectorsForNode(node));
1133
shouldParseNode: function(node) {
1134
return node.nodeType === 1 && matches.call(node, parser.parseSelectorsForNode(node));
1137
importer.observer.addCallback = dynamic.added.bind(dynamic);
1138
var matches = HTMLElement.prototype.matches || HTMLElement.prototype.matchesSelector || HTMLElement.prototype.webkitMatchesSelector || HTMLElement.prototype.mozMatchesSelector || HTMLElement.prototype.msMatchesSelector;
1142
var initializeModules = scope.initializeModules;
1143
var isIE = scope.isIE;
1144
if (scope.useNative) {
1147
initializeModules();
1148
var rootDocument = scope.rootDocument;
1149
function bootstrap() {
1150
window.HTMLImports.importer.bootDocument(rootDocument);
1152
if (document.readyState === "complete" || document.readyState === "interactive" && !window.attachEvent) {
1155
document.addEventListener("DOMContentLoaded", bootstrap);
1157
})(window.HTMLImports);
b'\\ No newline at end of file'