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

Side by Side Diff: polymer_1.2.3/bower_components/webcomponentsjs/HTMLImports.js

Issue 1581713003: [third_party] add polymer 1.2.3 (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: 1.2.3 Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 if (typeof WeakMap === "undefined") { 11 if (typeof WeakMap === "undefined") {
12 (function() { 12 (function() {
13 var defineProperty = Object.defineProperty; 13 var defineProperty = Object.defineProperty;
14 var counter = Date.now() % 1e9; 14 var counter = Date.now() % 1e9;
15 var WeakMap = function() { 15 var WeakMap = function() {
16 this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__"); 16 this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__");
17 }; 17 };
18 WeakMap.prototype = { 18 WeakMap.prototype = {
19 set: function(key, value) { 19 set: function(key, value) {
20 var entry = key[this.name]; 20 var entry = key[this.name];
(...skipping 17 matching lines...) Expand all
38 var entry = key[this.name]; 38 var entry = key[this.name];
39 if (!entry) return false; 39 if (!entry) return false;
40 return entry[0] === key; 40 return entry[0] === key;
41 } 41 }
42 }; 42 };
43 window.WeakMap = WeakMap; 43 window.WeakMap = WeakMap;
44 })(); 44 })();
45 } 45 }
46 46
47 (function(global) { 47 (function(global) {
48 if (global.JsMutationObserver) {
49 return;
50 }
48 var registrationsTable = new WeakMap(); 51 var registrationsTable = new WeakMap();
49 var setImmediate; 52 var setImmediate;
50 if (/Trident|Edge/.test(navigator.userAgent)) { 53 if (/Trident|Edge/.test(navigator.userAgent)) {
51 setImmediate = setTimeout; 54 setImmediate = setTimeout;
52 } else if (window.setImmediate) { 55 } else if (window.setImmediate) {
53 setImmediate = window.setImmediate; 56 setImmediate = window.setImmediate;
54 } else { 57 } else {
55 var setImmediateQueue = []; 58 var setImmediateQueue = [];
56 var sentinel = String(Math.random()); 59 var sentinel = String(Math.random());
57 window.addEventListener("message", function(e) { 60 window.addEventListener("message", function(e) {
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 record.nextSibling = nextSibling; 336 record.nextSibling = nextSibling;
334 forEachAncestorAndObserverEnqueueRecord(e.relatedNode, function(options) { 337 forEachAncestorAndObserverEnqueueRecord(e.relatedNode, function(options) {
335 if (!options.childList) return; 338 if (!options.childList) return;
336 return record; 339 return record;
337 }); 340 });
338 } 341 }
339 clearRecords(); 342 clearRecords();
340 } 343 }
341 }; 344 };
342 global.JsMutationObserver = JsMutationObserver; 345 global.JsMutationObserver = JsMutationObserver;
343 if (!global.MutationObserver) global.MutationObserver = JsMutationObserver; 346 if (!global.MutationObserver) {
344 })(this); 347 global.MutationObserver = JsMutationObserver;
348 JsMutationObserver._isPolyfilled = true;
349 }
350 })(self);
351
352 (function(scope) {
353 "use strict";
354 if (!window.performance) {
355 var start = Date.now();
356 window.performance = {
357 now: function() {
358 return Date.now() - start;
359 }
360 };
361 }
362 if (!window.requestAnimationFrame) {
363 window.requestAnimationFrame = function() {
364 var nativeRaf = window.webkitRequestAnimationFrame || window.mozRequestAni mationFrame;
365 return nativeRaf ? function(callback) {
366 return nativeRaf(function() {
367 callback(performance.now());
368 });
369 } : function(callback) {
370 return window.setTimeout(callback, 1e3 / 60);
371 };
372 }();
373 }
374 if (!window.cancelAnimationFrame) {
375 window.cancelAnimationFrame = function() {
376 return window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || function(id) {
377 clearTimeout(id);
378 };
379 }();
380 }
381 var workingDefaultPrevented = function() {
382 var e = document.createEvent("Event");
383 e.initEvent("foo", true, true);
384 e.preventDefault();
385 return e.defaultPrevented;
386 }();
387 if (!workingDefaultPrevented) {
388 var origPreventDefault = Event.prototype.preventDefault;
389 Event.prototype.preventDefault = function() {
390 if (!this.cancelable) {
391 return;
392 }
393 origPreventDefault.call(this);
394 Object.defineProperty(this, "defaultPrevented", {
395 get: function() {
396 return true;
397 },
398 configurable: true
399 });
400 };
401 }
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.cancelab le), params.detail);
408 return e;
409 };
410 window.CustomEvent.prototype = window.Event.prototype;
411 }
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));
418 return e;
419 };
420 window.Event.prototype = origEvent.prototype;
421 }
422 })(window.WebComponents);
345 423
346 window.HTMLImports = window.HTMLImports || { 424 window.HTMLImports = window.HTMLImports || {
347 flags: {} 425 flags: {}
348 }; 426 };
349 427
350 (function(scope) { 428 (function(scope) {
351 var IMPORT_LINK_TYPE = "import"; 429 var IMPORT_LINK_TYPE = "import";
352 var useNative = Boolean(IMPORT_LINK_TYPE in document.createElement("link")); 430 var useNative = Boolean(IMPORT_LINK_TYPE in document.createElement("link"));
353 var hasShadowDOMPolyfill = Boolean(window.ShadowDOMPolyfill); 431 var hasShadowDOMPolyfill = Boolean(window.ShadowDOMPolyfill);
354 var wrap = function(node) { 432 var wrap = function(node) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 checkDone(); 489 checkDone();
412 } 490 }
413 function errorLoadingImport(e) { 491 function errorLoadingImport(e) {
414 errorImports.push(this); 492 errorImports.push(this);
415 parsedCount++; 493 parsedCount++;
416 checkDone(); 494 checkDone();
417 } 495 }
418 if (importCount) { 496 if (importCount) {
419 for (var i = 0, imp; i < importCount && (imp = imports[i]); i++) { 497 for (var i = 0, imp; i < importCount && (imp = imports[i]); i++) {
420 if (isImportLoaded(imp)) { 498 if (isImportLoaded(imp)) {
499 newImports.push(this);
421 parsedCount++; 500 parsedCount++;
422 checkDone(); 501 checkDone();
423 } else { 502 } else {
424 imp.addEventListener("load", loadedImport); 503 imp.addEventListener("load", loadedImport);
425 imp.addEventListener("error", errorLoadingImport); 504 imp.addEventListener("error", errorLoadingImport);
426 } 505 }
427 } 506 }
428 } else { 507 } else {
429 checkDone(); 508 checkDone();
430 } 509 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 return request.status >= 200 && request.status < 300 || request.status === 304 || request.status === 0; 616 return request.status >= 200 && request.status < 300 || request.status === 304 || request.status === 0;
538 }, 617 },
539 load: function(url, next, nextContext) { 618 load: function(url, next, nextContext) {
540 var request = new XMLHttpRequest(); 619 var request = new XMLHttpRequest();
541 if (scope.flags.debug || scope.flags.bust) { 620 if (scope.flags.debug || scope.flags.bust) {
542 url += "?" + Math.random(); 621 url += "?" + Math.random();
543 } 622 }
544 request.open("GET", url, xhr.async); 623 request.open("GET", url, xhr.async);
545 request.addEventListener("readystatechange", function(e) { 624 request.addEventListener("readystatechange", function(e) {
546 if (request.readyState === 4) { 625 if (request.readyState === 4) {
547 var locationHeader = request.getResponseHeader("Location");
548 var redirectedUrl = null; 626 var redirectedUrl = null;
549 if (locationHeader) { 627 try {
550 var redirectedUrl = locationHeader.substr(0, 1) === "/" ? location.o rigin + locationHeader : locationHeader; 628 var locationHeader = request.getResponseHeader("Location");
629 if (locationHeader) {
630 redirectedUrl = locationHeader.substr(0, 1) === "/" ? location.ori gin + locationHeader : locationHeader;
631 }
632 } catch (e) {
633 console.error(e.message);
551 } 634 }
552 next.call(nextContext, !xhr.ok(request) && request, request.response | | request.responseText, redirectedUrl); 635 next.call(nextContext, !xhr.ok(request) && request, request.response | | request.responseText, redirectedUrl);
553 } 636 }
554 }); 637 });
555 request.send(); 638 request.send();
556 return request; 639 return request;
557 }, 640 },
558 loadDocument: function(url, next, nextContext) { 641 loadDocument: function(url, next, nextContext) {
559 this.load(url, next, nextContext).responseType = "document"; 642 this.load(url, next, nextContext).responseType = "document";
560 } 643 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 773
691 window.HTMLImports.addModule(function(scope) { 774 window.HTMLImports.addModule(function(scope) {
692 var path = scope.path; 775 var path = scope.path;
693 var rootDocument = scope.rootDocument; 776 var rootDocument = scope.rootDocument;
694 var flags = scope.flags; 777 var flags = scope.flags;
695 var isIE = scope.isIE; 778 var isIE = scope.isIE;
696 var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE; 779 var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE;
697 var IMPORT_SELECTOR = "link[rel=" + IMPORT_LINK_TYPE + "]"; 780 var IMPORT_SELECTOR = "link[rel=" + IMPORT_LINK_TYPE + "]";
698 var importParser = { 781 var importParser = {
699 documentSelectors: IMPORT_SELECTOR, 782 documentSelectors: IMPORT_SELECTOR,
700 importsSelectors: [ IMPORT_SELECTOR, "link[rel=stylesheet]", "style", "scrip t:not([type])", 'script[type="application/javascript"]', 'script[type="text/java script"]' ].join(","), 783 importsSelectors: [ IMPORT_SELECTOR, "link[rel=stylesheet]:not([type])", "st yle:not([type])", "script:not([type])", 'script[type="application/javascript"]', 'script[type="text/javascript"]' ].join(","),
701 map: { 784 map: {
702 link: "parseLink", 785 link: "parseLink",
703 script: "parseScript", 786 script: "parseScript",
704 style: "parseStyle" 787 style: "parseStyle"
705 }, 788 },
706 dynamicElements: [], 789 dynamicElements: [],
707 parseNext: function() { 790 parseNext: function() {
708 var next = this.nextToParse(); 791 var next = this.nextToParse();
709 if (next) { 792 if (next) {
710 this.parse(next); 793 this.parse(next);
(...skipping 30 matching lines...) Expand all
741 this.parsingElement = null; 824 this.parsingElement = null;
742 flags.parse && console.log("completed", elt); 825 flags.parse && console.log("completed", elt);
743 }, 826 },
744 markDynamicParsingComplete: function(elt) { 827 markDynamicParsingComplete: function(elt) {
745 var i = this.dynamicElements.indexOf(elt); 828 var i = this.dynamicElements.indexOf(elt);
746 if (i >= 0) { 829 if (i >= 0) {
747 this.dynamicElements.splice(i, 1); 830 this.dynamicElements.splice(i, 1);
748 } 831 }
749 }, 832 },
750 parseImport: function(elt) { 833 parseImport: function(elt) {
834 elt.import = elt.__doc;
751 if (window.HTMLImports.__importsParsingHook) { 835 if (window.HTMLImports.__importsParsingHook) {
752 window.HTMLImports.__importsParsingHook(elt); 836 window.HTMLImports.__importsParsingHook(elt);
753 } 837 }
754 if (elt.import) { 838 if (elt.import) {
755 elt.import.__importParsed = true; 839 elt.import.__importParsed = true;
756 } 840 }
757 this.markParsingComplete(elt); 841 this.markParsingComplete(elt);
758 if (elt.__resource && !elt.__error) { 842 if (elt.__resource && !elt.__error) {
759 elt.dispatchEvent(new CustomEvent("load", { 843 elt.dispatchEvent(new CustomEvent("load", {
760 bubbles: false 844 bubbles: false
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 } 887 }
804 return n; 888 return n;
805 }, 889 },
806 addElementToDocument: function(elt) { 890 addElementToDocument: function(elt) {
807 var port = this.rootImportForElement(elt.__importElement || elt); 891 var port = this.rootImportForElement(elt.__importElement || elt);
808 port.parentNode.insertBefore(elt, port); 892 port.parentNode.insertBefore(elt, port);
809 }, 893 },
810 trackElement: function(elt, callback) { 894 trackElement: function(elt, callback) {
811 var self = this; 895 var self = this;
812 var done = function(e) { 896 var done = function(e) {
897 elt.removeEventListener("load", done);
898 elt.removeEventListener("error", done);
813 if (callback) { 899 if (callback) {
814 callback(e); 900 callback(e);
815 } 901 }
816 self.markParsingComplete(elt); 902 self.markParsingComplete(elt);
817 self.parseNext(); 903 self.parseNext();
818 }; 904 };
819 elt.addEventListener("load", done); 905 elt.addEventListener("load", done);
820 elt.addEventListener("error", done); 906 elt.addEventListener("error", done);
821 if (isIE && elt.localName === "style") { 907 if (isIE && elt.localName === "style") {
822 var fakeLoad = false; 908 var fakeLoad = false;
(...skipping 17 matching lines...) Expand all
840 }); 926 });
841 } 927 }
842 } 928 }
843 }, 929 },
844 parseScript: function(scriptElt) { 930 parseScript: function(scriptElt) {
845 var script = document.createElement("script"); 931 var script = document.createElement("script");
846 script.__importElement = scriptElt; 932 script.__importElement = scriptElt;
847 script.src = scriptElt.src ? scriptElt.src : generateScriptDataUrl(scriptE lt); 933 script.src = scriptElt.src ? scriptElt.src : generateScriptDataUrl(scriptE lt);
848 scope.currentScript = scriptElt; 934 scope.currentScript = scriptElt;
849 this.trackElement(script, function(e) { 935 this.trackElement(script, function(e) {
850 script.parentNode.removeChild(script); 936 if (script.parentNode) {
937 script.parentNode.removeChild(script);
938 }
851 scope.currentScript = null; 939 scope.currentScript = null;
852 }); 940 });
853 this.addElementToDocument(script); 941 this.addElementToDocument(script);
854 }, 942 },
855 nextToParse: function() { 943 nextToParse: function() {
856 this._mayParse = []; 944 this._mayParse = [];
857 return !this.parsingElement && (this.nextToParseInDoc(rootDocument) || thi s.nextToParseDynamic()); 945 return !this.parsingElement && (this.nextToParseInDoc(rootDocument) || thi s.nextToParseDynamic());
858 }, 946 },
859 nextToParseInDoc: function(doc, link) { 947 nextToParseInDoc: function(doc, link) {
860 if (doc && this._mayParse.indexOf(doc) < 0) { 948 if (doc && this._mayParse.indexOf(doc) < 0) {
861 this._mayParse.push(doc); 949 this._mayParse.push(doc);
862 var nodes = doc.querySelectorAll(this.parseSelectorsForNode(doc)); 950 var nodes = doc.querySelectorAll(this.parseSelectorsForNode(doc));
863 for (var i = 0, l = nodes.length, p = 0, n; i < l && (n = nodes[i]); i++ ) { 951 for (var i = 0, l = nodes.length, p = 0, n; i < l && (n = nodes[i]); i++ ) {
864 if (!this.isParsed(n)) { 952 if (!this.isParsed(n)) {
865 if (this.hasResource(n)) { 953 if (this.hasResource(n)) {
866 return nodeIsImport(n) ? this.nextToParseInDoc(n.import, n) : n; 954 return nodeIsImport(n) ? this.nextToParseInDoc(n.__doc, n) : n;
867 } else { 955 } else {
868 return; 956 return;
869 } 957 }
870 } 958 }
871 } 959 }
872 } 960 }
873 return link; 961 return link;
874 }, 962 },
875 nextToParseDynamic: function() { 963 nextToParseDynamic: function() {
876 return this.dynamicElements[0]; 964 return this.dynamicElements[0];
877 }, 965 },
878 parseSelectorsForNode: function(node) { 966 parseSelectorsForNode: function(node) {
879 var doc = node.ownerDocument || node; 967 var doc = node.ownerDocument || node;
880 return doc === rootDocument ? this.documentSelectors : this.importsSelecto rs; 968 return doc === rootDocument ? this.documentSelectors : this.importsSelecto rs;
881 }, 969 },
882 isParsed: function(node) { 970 isParsed: function(node) {
883 return node.__importParsed; 971 return node.__importParsed;
884 }, 972 },
885 needsDynamicParsing: function(elt) { 973 needsDynamicParsing: function(elt) {
886 return this.dynamicElements.indexOf(elt) >= 0; 974 return this.dynamicElements.indexOf(elt) >= 0;
887 }, 975 },
888 hasResource: function(node) { 976 hasResource: function(node) {
889 if (nodeIsImport(node) && node.import === undefined) { 977 if (nodeIsImport(node) && node.__doc === undefined) {
890 return false; 978 return false;
891 } 979 }
892 return true; 980 return true;
893 } 981 }
894 }; 982 };
895 function nodeIsImport(elt) { 983 function nodeIsImport(elt) {
896 return elt.localName === "link" && elt.rel === IMPORT_LINK_TYPE; 984 return elt.localName === "link" && elt.rel === IMPORT_LINK_TYPE;
897 } 985 }
898 function generateScriptDataUrl(script) { 986 function generateScriptDataUrl(script) {
899 var scriptContent = generateScriptContent(script); 987 var scriptContent = generateScriptContent(script);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 if (isImportLink(elt)) { 1041 if (isImportLink(elt)) {
954 var doc = this.documents[url]; 1042 var doc = this.documents[url];
955 if (doc === undefined) { 1043 if (doc === undefined) {
956 doc = err ? null : makeDocument(resource, redirectedUrl || url); 1044 doc = err ? null : makeDocument(resource, redirectedUrl || url);
957 if (doc) { 1045 if (doc) {
958 doc.__importLink = elt; 1046 doc.__importLink = elt;
959 this.bootDocument(doc); 1047 this.bootDocument(doc);
960 } 1048 }
961 this.documents[url] = doc; 1049 this.documents[url] = doc;
962 } 1050 }
963 elt.import = doc; 1051 elt.__doc = doc;
964 } 1052 }
965 parser.parseNext(); 1053 parser.parseNext();
966 }, 1054 },
967 bootDocument: function(doc) { 1055 bootDocument: function(doc) {
968 this.loadSubtree(doc); 1056 this.loadSubtree(doc);
969 this.observer.observe(doc); 1057 this.observer.observe(doc);
970 parser.parseNext(); 1058 parser.parseNext();
971 }, 1059 },
972 loadedAll: function() { 1060 loadedAll: function() {
973 parser.parseNext(); 1061 parser.parseNext();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 importer.observer.addCallback = dynamic.added.bind(dynamic); 1137 importer.observer.addCallback = dynamic.added.bind(dynamic);
1050 var matches = HTMLElement.prototype.matches || HTMLElement.prototype.matchesSe lector || HTMLElement.prototype.webkitMatchesSelector || HTMLElement.prototype.m ozMatchesSelector || HTMLElement.prototype.msMatchesSelector; 1138 var matches = HTMLElement.prototype.matches || HTMLElement.prototype.matchesSe lector || HTMLElement.prototype.webkitMatchesSelector || HTMLElement.prototype.m ozMatchesSelector || HTMLElement.prototype.msMatchesSelector;
1051 }); 1139 });
1052 1140
1053 (function(scope) { 1141 (function(scope) {
1054 var initializeModules = scope.initializeModules; 1142 var initializeModules = scope.initializeModules;
1055 var isIE = scope.isIE; 1143 var isIE = scope.isIE;
1056 if (scope.useNative) { 1144 if (scope.useNative) {
1057 return; 1145 return;
1058 } 1146 }
1059 if (isIE && typeof window.CustomEvent !== "function") {
1060 window.CustomEvent = function(inType, params) {
1061 params = params || {};
1062 var e = document.createEvent("CustomEvent");
1063 e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelab le), params.detail);
1064 e.preventDefault = function() {
1065 Object.defineProperty(this, "defaultPrevented", {
1066 get: function() {
1067 return true;
1068 }
1069 });
1070 };
1071 return e;
1072 };
1073 window.CustomEvent.prototype = window.Event.prototype;
1074 }
1075 initializeModules(); 1147 initializeModules();
1076 var rootDocument = scope.rootDocument; 1148 var rootDocument = scope.rootDocument;
1077 function bootstrap() { 1149 function bootstrap() {
1078 window.HTMLImports.importer.bootDocument(rootDocument); 1150 window.HTMLImports.importer.bootDocument(rootDocument);
1079 } 1151 }
1080 if (document.readyState === "complete" || document.readyState === "interactive " && !window.attachEvent) { 1152 if (document.readyState === "complete" || document.readyState === "interactive " && !window.attachEvent) {
1081 bootstrap(); 1153 bootstrap();
1082 } else { 1154 } else {
1083 document.addEventListener("DOMContentLoaded", bootstrap); 1155 document.addEventListener("DOMContentLoaded", bootstrap);
1084 } 1156 }
1085 })(window.HTMLImports); 1157 })(window.HTMLImports);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698