| Index: third_party/polymer/components/webcomponentsjs/CustomElements.js
|
| diff --git a/third_party/polymer/components/webcomponentsjs/CustomElements.js b/third_party/polymer/components/webcomponentsjs/CustomElements.js
|
| index 931f6c22e18e8851b972aede1610d2dba5e24a86..71731bdbb945e34b97aab1a2ccfd8822de6e1b91 100644
|
| --- a/third_party/polymer/components/webcomponentsjs/CustomElements.js
|
| +++ b/third_party/polymer/components/webcomponentsjs/CustomElements.js
|
| @@ -7,7 +7,7 @@
|
| * Code distributed by Google as part of the polymer project is also
|
| * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
| */
|
| -// @version 0.7.22
|
| +// @version 0.6.1
|
| if (typeof WeakMap === "undefined") {
|
| (function() {
|
| var defineProperty = Object.defineProperty;
|
| @@ -45,9 +45,6 @@ if (typeof WeakMap === "undefined") {
|
| }
|
|
|
| (function(global) {
|
| - if (global.JsMutationObserver) {
|
| - return;
|
| - }
|
| var registrationsTable = new WeakMap();
|
| var setImmediate;
|
| if (/Trident|Edge/.test(navigator.userAgent)) {
|
| @@ -343,83 +340,8 @@ if (typeof WeakMap === "undefined") {
|
| }
|
| };
|
| global.JsMutationObserver = JsMutationObserver;
|
| - if (!global.MutationObserver) {
|
| - global.MutationObserver = JsMutationObserver;
|
| - JsMutationObserver._isPolyfilled = true;
|
| - }
|
| -})(self);
|
| -
|
| -(function(scope) {
|
| - "use strict";
|
| - if (!window.performance) {
|
| - var start = Date.now();
|
| - window.performance = {
|
| - now: function() {
|
| - return Date.now() - start;
|
| - }
|
| - };
|
| - }
|
| - if (!window.requestAnimationFrame) {
|
| - window.requestAnimationFrame = function() {
|
| - var nativeRaf = window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame;
|
| - return nativeRaf ? function(callback) {
|
| - return nativeRaf(function() {
|
| - callback(performance.now());
|
| - });
|
| - } : function(callback) {
|
| - return window.setTimeout(callback, 1e3 / 60);
|
| - };
|
| - }();
|
| - }
|
| - if (!window.cancelAnimationFrame) {
|
| - window.cancelAnimationFrame = function() {
|
| - return window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || function(id) {
|
| - clearTimeout(id);
|
| - };
|
| - }();
|
| - }
|
| - var workingDefaultPrevented = function() {
|
| - var e = document.createEvent("Event");
|
| - e.initEvent("foo", true, true);
|
| - e.preventDefault();
|
| - return e.defaultPrevented;
|
| - }();
|
| - if (!workingDefaultPrevented) {
|
| - var origPreventDefault = Event.prototype.preventDefault;
|
| - Event.prototype.preventDefault = function() {
|
| - if (!this.cancelable) {
|
| - return;
|
| - }
|
| - origPreventDefault.call(this);
|
| - Object.defineProperty(this, "defaultPrevented", {
|
| - get: function() {
|
| - return true;
|
| - },
|
| - configurable: true
|
| - });
|
| - };
|
| - }
|
| - var isIE = /Trident/.test(navigator.userAgent);
|
| - if (!window.CustomEvent || isIE && typeof window.CustomEvent !== "function") {
|
| - window.CustomEvent = function(inType, params) {
|
| - params = params || {};
|
| - var e = document.createEvent("CustomEvent");
|
| - e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable), params.detail);
|
| - return e;
|
| - };
|
| - window.CustomEvent.prototype = window.Event.prototype;
|
| - }
|
| - if (!window.Event || isIE && typeof window.Event !== "function") {
|
| - var origEvent = window.Event;
|
| - window.Event = function(inType, params) {
|
| - params = params || {};
|
| - var e = document.createEvent("Event");
|
| - e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable));
|
| - return e;
|
| - };
|
| - window.Event.prototype = origEvent.prototype;
|
| - }
|
| -})(window.WebComponents);
|
| + if (!global.MutationObserver) global.MutationObserver = JsMutationObserver;
|
| +})(this);
|
|
|
| window.CustomElements = window.CustomElements || {
|
| flags: {}
|
| @@ -439,12 +361,11 @@ window.CustomElements = window.CustomElements || {
|
| scope.addModule = addModule;
|
| scope.initializeModules = initializeModules;
|
| scope.hasNative = Boolean(document.registerElement);
|
| - scope.isIE = /Trident/.test(navigator.userAgent);
|
| - scope.useNative = !flags.register && scope.hasNative && !window.ShadowDOMPolyfill && (!window.HTMLImports || window.HTMLImports.useNative);
|
| -})(window.CustomElements);
|
| + scope.useNative = !flags.register && scope.hasNative && !window.ShadowDOMPolyfill && (!window.HTMLImports || HTMLImports.useNative);
|
| +})(CustomElements);
|
|
|
| -window.CustomElements.addModule(function(scope) {
|
| - var IMPORT_LINK_TYPE = window.HTMLImports ? window.HTMLImports.IMPORT_LINK_TYPE : "none";
|
| +CustomElements.addModule(function(scope) {
|
| + var IMPORT_LINK_TYPE = window.HTMLImports ? HTMLImports.IMPORT_LINK_TYPE : "none";
|
| function forSubtree(node, cb) {
|
| findAllElements(node, function(e) {
|
| if (cb(e)) {
|
| @@ -481,7 +402,7 @@ window.CustomElements.addModule(function(scope) {
|
| _forDocumentTree(doc, cb, []);
|
| }
|
| function _forDocumentTree(doc, cb, processingDocuments) {
|
| - doc = window.wrap(doc);
|
| + doc = wrap(doc);
|
| if (processingDocuments.indexOf(doc) >= 0) {
|
| return;
|
| }
|
| @@ -498,31 +419,36 @@ window.CustomElements.addModule(function(scope) {
|
| scope.forSubtree = forSubtree;
|
| });
|
|
|
| -window.CustomElements.addModule(function(scope) {
|
| +CustomElements.addModule(function(scope) {
|
| var flags = scope.flags;
|
| var forSubtree = scope.forSubtree;
|
| var forDocumentTree = scope.forDocumentTree;
|
| - function addedNode(node, isAttached) {
|
| - return added(node, isAttached) || addedSubtree(node, isAttached);
|
| + function addedNode(node) {
|
| + return added(node) || addedSubtree(node);
|
| }
|
| - function added(node, isAttached) {
|
| - if (scope.upgrade(node, isAttached)) {
|
| + function added(node) {
|
| + if (scope.upgrade(node)) {
|
| return true;
|
| }
|
| - if (isAttached) {
|
| - attached(node);
|
| - }
|
| + attached(node);
|
| }
|
| - function addedSubtree(node, isAttached) {
|
| + function addedSubtree(node) {
|
| forSubtree(node, function(e) {
|
| - if (added(e, isAttached)) {
|
| + if (added(e)) {
|
| return true;
|
| }
|
| });
|
| }
|
| - var hasThrottledAttached = window.MutationObserver._isPolyfilled && flags["throttle-attached"];
|
| - scope.hasPolyfillMutations = hasThrottledAttached;
|
| - scope.hasThrottledAttached = hasThrottledAttached;
|
| + function attachedNode(node) {
|
| + attached(node);
|
| + if (inDocument(node)) {
|
| + forSubtree(node, function(e) {
|
| + attached(e);
|
| + });
|
| + }
|
| + }
|
| + var hasPolyfillMutations = !window.MutationObserver || window.MutationObserver === window.JsMutationObserver;
|
| + scope.hasPolyfillMutations = hasPolyfillMutations;
|
| var isPendingMutations = false;
|
| var pendingMutations = [];
|
| function deferMutation(fn) {
|
| @@ -541,7 +467,7 @@ window.CustomElements.addModule(function(scope) {
|
| pendingMutations = [];
|
| }
|
| function attached(element) {
|
| - if (hasThrottledAttached) {
|
| + if (hasPolyfillMutations) {
|
| deferMutation(function() {
|
| _attached(element);
|
| });
|
| @@ -550,10 +476,12 @@ window.CustomElements.addModule(function(scope) {
|
| }
|
| }
|
| function _attached(element) {
|
| - if (element.__upgraded__ && !element.__attached) {
|
| - element.__attached = true;
|
| - if (element.attachedCallback) {
|
| - element.attachedCallback();
|
| + if (element.__upgraded__ && (element.attachedCallback || element.detachedCallback)) {
|
| + if (!element.__attached && inDocument(element)) {
|
| + element.__attached = true;
|
| + if (element.attachedCallback) {
|
| + element.attachedCallback();
|
| + }
|
| }
|
| }
|
| }
|
| @@ -564,7 +492,7 @@ window.CustomElements.addModule(function(scope) {
|
| });
|
| }
|
| function detached(element) {
|
| - if (hasThrottledAttached) {
|
| + if (hasPolyfillMutations) {
|
| deferMutation(function() {
|
| _detached(element);
|
| });
|
| @@ -573,16 +501,18 @@ window.CustomElements.addModule(function(scope) {
|
| }
|
| }
|
| function _detached(element) {
|
| - if (element.__upgraded__ && element.__attached) {
|
| - element.__attached = false;
|
| - if (element.detachedCallback) {
|
| - element.detachedCallback();
|
| + if (element.__upgraded__ && (element.attachedCallback || element.detachedCallback)) {
|
| + if (element.__attached && !inDocument(element)) {
|
| + element.__attached = false;
|
| + if (element.detachedCallback) {
|
| + element.detachedCallback();
|
| + }
|
| }
|
| }
|
| }
|
| function inDocument(element) {
|
| var p = element;
|
| - var doc = window.wrap(document);
|
| + var doc = wrap(document);
|
| while (p) {
|
| if (p == doc) {
|
| return true;
|
| @@ -600,7 +530,7 @@ window.CustomElements.addModule(function(scope) {
|
| }
|
| }
|
| }
|
| - function handler(root, mutations) {
|
| + function handler(mutations) {
|
| if (flags.dom) {
|
| var mx = mutations[0];
|
| if (mx && mx.type === "childList" && mx.addedNodes) {
|
| @@ -615,14 +545,13 @@ window.CustomElements.addModule(function(scope) {
|
| }
|
| console.group("mutations (%d) [%s]", mutations.length, u || "");
|
| }
|
| - var isAttached = inDocument(root);
|
| mutations.forEach(function(mx) {
|
| if (mx.type === "childList") {
|
| forEach(mx.addedNodes, function(n) {
|
| if (!n.localName) {
|
| return;
|
| }
|
| - addedNode(n, isAttached);
|
| + addedNode(n);
|
| });
|
| forEach(mx.removedNodes, function(n) {
|
| if (!n.localName) {
|
| @@ -635,16 +564,16 @@ window.CustomElements.addModule(function(scope) {
|
| flags.dom && console.groupEnd();
|
| }
|
| function takeRecords(node) {
|
| - node = window.wrap(node);
|
| + node = wrap(node);
|
| if (!node) {
|
| - node = window.wrap(document);
|
| + node = wrap(document);
|
| }
|
| while (node.parentNode) {
|
| node = node.parentNode;
|
| }
|
| var observer = node.__observer;
|
| if (observer) {
|
| - handler(node, observer.takeRecords());
|
| + handler(observer.takeRecords());
|
| takeMutations();
|
| }
|
| }
|
| @@ -653,7 +582,7 @@ window.CustomElements.addModule(function(scope) {
|
| if (inRoot.__observer) {
|
| return;
|
| }
|
| - var observer = new MutationObserver(handler.bind(this, inRoot));
|
| + var observer = new MutationObserver(handler);
|
| observer.observe(inRoot, {
|
| childList: true,
|
| subtree: true
|
| @@ -661,10 +590,9 @@ window.CustomElements.addModule(function(scope) {
|
| inRoot.__observer = observer;
|
| }
|
| function upgradeDocument(doc) {
|
| - doc = window.wrap(doc);
|
| + doc = wrap(doc);
|
| flags.dom && console.group("upgradeDocument: ", doc.baseURI.split("/").pop());
|
| - var isMainDocument = doc === window.wrap(document);
|
| - addedNode(doc, isMainDocument);
|
| + addedNode(doc);
|
| observe(doc);
|
| flags.dom && console.groupEnd();
|
| }
|
| @@ -675,38 +603,34 @@ window.CustomElements.addModule(function(scope) {
|
| if (originalCreateShadowRoot) {
|
| Element.prototype.createShadowRoot = function() {
|
| var root = originalCreateShadowRoot.call(this);
|
| - window.CustomElements.watchShadow(this);
|
| + CustomElements.watchShadow(this);
|
| return root;
|
| };
|
| }
|
| scope.watchShadow = watchShadow;
|
| scope.upgradeDocumentTree = upgradeDocumentTree;
|
| - scope.upgradeDocument = upgradeDocument;
|
| scope.upgradeSubtree = addedSubtree;
|
| scope.upgradeAll = addedNode;
|
| - scope.attached = attached;
|
| + scope.attachedNode = attachedNode;
|
| scope.takeRecords = takeRecords;
|
| });
|
|
|
| -window.CustomElements.addModule(function(scope) {
|
| +CustomElements.addModule(function(scope) {
|
| var flags = scope.flags;
|
| - function upgrade(node, isAttached) {
|
| - if (node.localName === "template") {
|
| - if (window.HTMLTemplateElement && HTMLTemplateElement.decorate) {
|
| - HTMLTemplateElement.decorate(node);
|
| - }
|
| - }
|
| + function upgrade(node) {
|
| if (!node.__upgraded__ && node.nodeType === Node.ELEMENT_NODE) {
|
| var is = node.getAttribute("is");
|
| - var definition = scope.getRegisteredDefinition(node.localName) || scope.getRegisteredDefinition(is);
|
| + var definition = scope.getRegisteredDefinition(is || node.localName);
|
| if (definition) {
|
| - if (is && definition.tag == node.localName || !is && !definition.extends) {
|
| - return upgradeWithDefinition(node, definition, isAttached);
|
| + if (is && definition.tag == node.localName) {
|
| + return upgradeWithDefinition(node, definition);
|
| + } else if (!is && !definition.extends) {
|
| + return upgradeWithDefinition(node, definition);
|
| }
|
| }
|
| }
|
| }
|
| - function upgradeWithDefinition(element, definition, isAttached) {
|
| + function upgradeWithDefinition(element, definition) {
|
| flags.upgrade && console.group("upgrade:", element.localName);
|
| if (definition.is) {
|
| element.setAttribute("is", definition.is);
|
| @@ -714,10 +638,8 @@ window.CustomElements.addModule(function(scope) {
|
| implementPrototype(element, definition);
|
| element.__upgraded__ = true;
|
| created(element);
|
| - if (isAttached) {
|
| - scope.attached(element);
|
| - }
|
| - scope.upgradeSubtree(element, isAttached);
|
| + scope.attachedNode(element);
|
| + scope.upgradeSubtree(element);
|
| flags.upgrade && console.groupEnd();
|
| return element;
|
| }
|
| @@ -753,8 +675,8 @@ window.CustomElements.addModule(function(scope) {
|
| scope.implementPrototype = implementPrototype;
|
| });
|
|
|
| -window.CustomElements.addModule(function(scope) {
|
| - var isIE = scope.isIE;
|
| +CustomElements.addModule(function(scope) {
|
| + var isIE11OrOlder = scope.isIE11OrOlder;
|
| var upgradeDocumentTree = scope.upgradeDocumentTree;
|
| var upgradeAll = scope.upgradeAll;
|
| var upgradeWithDefinition = scope.upgradeWithDefinition;
|
| @@ -778,9 +700,6 @@ window.CustomElements.addModule(function(scope) {
|
| definition.prototype = Object.create(HTMLElement.prototype);
|
| }
|
| definition.__name = name.toLowerCase();
|
| - if (definition.extends) {
|
| - definition.extends = definition.extends.toLowerCase();
|
| - }
|
| definition.lifecycle = definition.lifecycle || {};
|
| definition.ancestry = ancestry(definition.extends);
|
| resolveTagName(definition);
|
| @@ -848,23 +767,17 @@ window.CustomElements.addModule(function(scope) {
|
| var nativePrototype = HTMLElement.prototype;
|
| if (definition.is) {
|
| var inst = document.createElement(definition.tag);
|
| - nativePrototype = Object.getPrototypeOf(inst);
|
| + var expectedPrototype = Object.getPrototypeOf(inst);
|
| + if (expectedPrototype === definition.prototype) {
|
| + nativePrototype = expectedPrototype;
|
| + }
|
| }
|
| var proto = definition.prototype, ancestor;
|
| - var foundPrototype = false;
|
| - while (proto) {
|
| - if (proto == nativePrototype) {
|
| - foundPrototype = true;
|
| - }
|
| + while (proto && proto !== nativePrototype) {
|
| ancestor = Object.getPrototypeOf(proto);
|
| - if (ancestor) {
|
| - proto.__proto__ = ancestor;
|
| - }
|
| + proto.__proto__ = ancestor;
|
| proto = ancestor;
|
| }
|
| - if (!foundPrototype) {
|
| - console.warn(definition.tag + " prototype not found in prototype chain for " + definition.is);
|
| - }
|
| definition.native = nativePrototype;
|
| }
|
| }
|
| @@ -894,12 +807,6 @@ window.CustomElements.addModule(function(scope) {
|
| }
|
| }
|
| function createElement(tag, typeExtension) {
|
| - if (tag) {
|
| - tag = tag.toLowerCase();
|
| - }
|
| - if (typeExtension) {
|
| - typeExtension = typeExtension.toLowerCase();
|
| - }
|
| var definition = getRegisteredDefinition(typeExtension || tag);
|
| if (definition) {
|
| if (tag == definition.tag && typeExtension == definition.is) {
|
| @@ -926,9 +833,6 @@ window.CustomElements.addModule(function(scope) {
|
| var isInstance;
|
| if (!Object.__proto__ && !useNative) {
|
| isInstance = function(obj, ctor) {
|
| - if (obj instanceof ctor) {
|
| - return true;
|
| - }
|
| var p = obj;
|
| while (p) {
|
| if (p === ctor.prototype) {
|
| @@ -953,6 +857,21 @@ window.CustomElements.addModule(function(scope) {
|
| }
|
| wrapDomMethodToForceUpgrade(Node.prototype, "cloneNode");
|
| wrapDomMethodToForceUpgrade(document, "importNode");
|
| + if (isIE11OrOlder) {
|
| + (function() {
|
| + var importNode = document.importNode;
|
| + document.importNode = function() {
|
| + var n = importNode.apply(document, arguments);
|
| + if (n.nodeType == n.DOCUMENT_FRAGMENT_NODE) {
|
| + var f = document.createDocumentFragment();
|
| + f.appendChild(n);
|
| + return f;
|
| + } else {
|
| + return n;
|
| + }
|
| + };
|
| + })();
|
| + }
|
| document.registerElement = register;
|
| document.createElement = createElement;
|
| document.createElementNS = createElementNS;
|
| @@ -966,7 +885,7 @@ window.CustomElements.addModule(function(scope) {
|
| (function(scope) {
|
| var useNative = scope.useNative;
|
| var initializeModules = scope.initializeModules;
|
| - var isIE = scope.isIE;
|
| + var isIE11OrOlder = /Trident/.test(navigator.userAgent);
|
| if (useNative) {
|
| var nop = function() {};
|
| scope.watchShadow = nop;
|
| @@ -982,48 +901,50 @@ window.CustomElements.addModule(function(scope) {
|
| initializeModules();
|
| }
|
| var upgradeDocumentTree = scope.upgradeDocumentTree;
|
| - var upgradeDocument = scope.upgradeDocument;
|
| if (!window.wrap) {
|
| if (window.ShadowDOMPolyfill) {
|
| - window.wrap = window.ShadowDOMPolyfill.wrapIfNeeded;
|
| - window.unwrap = window.ShadowDOMPolyfill.unwrapIfNeeded;
|
| + window.wrap = ShadowDOMPolyfill.wrapIfNeeded;
|
| + window.unwrap = ShadowDOMPolyfill.unwrapIfNeeded;
|
| } else {
|
| window.wrap = window.unwrap = function(node) {
|
| return node;
|
| };
|
| }
|
| }
|
| - if (window.HTMLImports) {
|
| - window.HTMLImports.__importsParsingHook = function(elt) {
|
| - if (elt.import) {
|
| - upgradeDocument(wrap(elt.import));
|
| + function bootstrap() {
|
| + upgradeDocumentTree(wrap(document));
|
| + if (window.HTMLImports) {
|
| + HTMLImports.__importsParsingHook = function(elt) {
|
| + upgradeDocumentTree(wrap(elt.import));
|
| + };
|
| + }
|
| + CustomElements.ready = true;
|
| + setTimeout(function() {
|
| + CustomElements.readyTime = Date.now();
|
| + if (window.HTMLImports) {
|
| + CustomElements.elapsed = CustomElements.readyTime - HTMLImports.readyTime;
|
| }
|
| - };
|
| + document.dispatchEvent(new CustomEvent("WebComponentsReady", {
|
| + bubbles: true
|
| + }));
|
| + });
|
| }
|
| - function bootstrap() {
|
| - upgradeDocumentTree(window.wrap(document));
|
| - window.CustomElements.ready = true;
|
| - var requestAnimationFrame = window.requestAnimationFrame || function(f) {
|
| - setTimeout(f, 16);
|
| + if (isIE11OrOlder && typeof window.CustomEvent !== "function") {
|
| + window.CustomEvent = function(inType, params) {
|
| + params = params || {};
|
| + var e = document.createEvent("CustomEvent");
|
| + e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable), params.detail);
|
| + return e;
|
| };
|
| - requestAnimationFrame(function() {
|
| - setTimeout(function() {
|
| - window.CustomElements.readyTime = Date.now();
|
| - if (window.HTMLImports) {
|
| - window.CustomElements.elapsed = window.CustomElements.readyTime - window.HTMLImports.readyTime;
|
| - }
|
| - document.dispatchEvent(new CustomEvent("WebComponentsReady", {
|
| - bubbles: true
|
| - }));
|
| - });
|
| - });
|
| + window.CustomEvent.prototype = window.Event.prototype;
|
| }
|
| if (document.readyState === "complete" || scope.flags.eager) {
|
| bootstrap();
|
| } else if (document.readyState === "interactive" && !window.attachEvent && (!window.HTMLImports || window.HTMLImports.ready)) {
|
| bootstrap();
|
| } else {
|
| - var loadEvent = window.HTMLImports && !window.HTMLImports.ready ? "HTMLImportsLoaded" : "DOMContentLoaded";
|
| + var loadEvent = window.HTMLImports && !HTMLImports.ready ? "HTMLImportsLoaded" : "DOMContentLoaded";
|
| window.addEventListener(loadEvent, bootstrap);
|
| }
|
| + scope.isIE11OrOlder = isIE11OrOlder;
|
| })(window.CustomElements);
|
|
|