Index: polymer_1.2.3/bower_components/webcomponentsjs/CustomElements.js |
diff --git a/polymer_1.0.4/bower_components/webcomponentsjs/CustomElements.js b/polymer_1.2.3/bower_components/webcomponentsjs/CustomElements.js |
similarity index 84% |
copy from polymer_1.0.4/bower_components/webcomponentsjs/CustomElements.js |
copy to polymer_1.2.3/bower_components/webcomponentsjs/CustomElements.js |
index ae4af3b5b1e95e6e7c3a1811964b219ba3d93dad..aa358bde4947db99f4411c9ad580ebe8879c4a8a 100644 |
--- a/polymer_1.0.4/bower_components/webcomponentsjs/CustomElements.js |
+++ b/polymer_1.2.3/bower_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.5 |
+// @version 0.7.20 |
if (typeof WeakMap === "undefined") { |
(function() { |
var defineProperty = Object.defineProperty; |
@@ -45,6 +45,9 @@ if (typeof WeakMap === "undefined") { |
} |
(function(global) { |
+ if (global.JsMutationObserver) { |
+ return; |
+ } |
var registrationsTable = new WeakMap(); |
var setImmediate; |
if (/Trident|Edge/.test(navigator.userAgent)) { |
@@ -340,8 +343,83 @@ if (typeof WeakMap === "undefined") { |
} |
}; |
global.JsMutationObserver = JsMutationObserver; |
- if (!global.MutationObserver) global.MutationObserver = JsMutationObserver; |
-})(this); |
+ 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); |
window.CustomElements = window.CustomElements || { |
flags: {} |
@@ -361,6 +439,7 @@ 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); |
@@ -423,32 +502,27 @@ window.CustomElements.addModule(function(scope) { |
var flags = scope.flags; |
var forSubtree = scope.forSubtree; |
var forDocumentTree = scope.forDocumentTree; |
- function addedNode(node) { |
- return added(node) || addedSubtree(node); |
+ function addedNode(node, isAttached) { |
+ return added(node, isAttached) || addedSubtree(node, isAttached); |
} |
- function added(node) { |
- if (scope.upgrade(node)) { |
+ function added(node, isAttached) { |
+ if (scope.upgrade(node, isAttached)) { |
return true; |
} |
- attached(node); |
+ if (isAttached) { |
+ attached(node); |
+ } |
} |
- function addedSubtree(node) { |
+ function addedSubtree(node, isAttached) { |
forSubtree(node, function(e) { |
- if (added(e)) { |
+ if (added(e, isAttached)) { |
return true; |
} |
}); |
} |
- 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 hasThrottledAttached = window.MutationObserver._isPolyfilled && flags["throttle-attached"]; |
+ scope.hasPolyfillMutations = hasThrottledAttached; |
+ scope.hasThrottledAttached = hasThrottledAttached; |
var isPendingMutations = false; |
var pendingMutations = []; |
function deferMutation(fn) { |
@@ -467,7 +541,7 @@ window.CustomElements.addModule(function(scope) { |
pendingMutations = []; |
} |
function attached(element) { |
- if (hasPolyfillMutations) { |
+ if (hasThrottledAttached) { |
deferMutation(function() { |
_attached(element); |
}); |
@@ -476,12 +550,10 @@ window.CustomElements.addModule(function(scope) { |
} |
} |
function _attached(element) { |
- if (element.__upgraded__ && (element.attachedCallback || element.detachedCallback)) { |
- if (!element.__attached && inDocument(element)) { |
- element.__attached = true; |
- if (element.attachedCallback) { |
- element.attachedCallback(); |
- } |
+ if (element.__upgraded__ && !element.__attached) { |
+ element.__attached = true; |
+ if (element.attachedCallback) { |
+ element.attachedCallback(); |
} |
} |
} |
@@ -492,7 +564,7 @@ window.CustomElements.addModule(function(scope) { |
}); |
} |
function detached(element) { |
- if (hasPolyfillMutations) { |
+ if (hasThrottledAttached) { |
deferMutation(function() { |
_detached(element); |
}); |
@@ -501,18 +573,16 @@ window.CustomElements.addModule(function(scope) { |
} |
} |
function _detached(element) { |
- if (element.__upgraded__ && (element.attachedCallback || element.detachedCallback)) { |
- if (element.__attached && !inDocument(element)) { |
- element.__attached = false; |
- if (element.detachedCallback) { |
- element.detachedCallback(); |
- } |
+ if (element.__upgraded__ && element.__attached) { |
+ element.__attached = false; |
+ if (element.detachedCallback) { |
+ element.detachedCallback(); |
} |
} |
} |
function inDocument(element) { |
var p = element; |
- var doc = wrap(document); |
+ var doc = window.wrap(document); |
while (p) { |
if (p == doc) { |
return true; |
@@ -530,7 +600,7 @@ window.CustomElements.addModule(function(scope) { |
} |
} |
} |
- function handler(mutations) { |
+ function handler(root, mutations) { |
if (flags.dom) { |
var mx = mutations[0]; |
if (mx && mx.type === "childList" && mx.addedNodes) { |
@@ -545,13 +615,14 @@ 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); |
+ addedNode(n, isAttached); |
}); |
forEach(mx.removedNodes, function(n) { |
if (!n.localName) { |
@@ -573,7 +644,7 @@ window.CustomElements.addModule(function(scope) { |
} |
var observer = node.__observer; |
if (observer) { |
- handler(observer.takeRecords()); |
+ handler(node, observer.takeRecords()); |
takeMutations(); |
} |
} |
@@ -582,7 +653,7 @@ window.CustomElements.addModule(function(scope) { |
if (inRoot.__observer) { |
return; |
} |
- var observer = new MutationObserver(handler); |
+ var observer = new MutationObserver(handler.bind(this, inRoot)); |
observer.observe(inRoot, { |
childList: true, |
subtree: true |
@@ -592,7 +663,8 @@ window.CustomElements.addModule(function(scope) { |
function upgradeDocument(doc) { |
doc = window.wrap(doc); |
flags.dom && console.group("upgradeDocument: ", doc.baseURI.split("/").pop()); |
- addedNode(doc); |
+ var isMainDocument = doc === window.wrap(document); |
+ addedNode(doc, isMainDocument); |
observe(doc); |
flags.dom && console.groupEnd(); |
} |
@@ -609,28 +681,32 @@ window.CustomElements.addModule(function(scope) { |
} |
scope.watchShadow = watchShadow; |
scope.upgradeDocumentTree = upgradeDocumentTree; |
+ scope.upgradeDocument = upgradeDocument; |
scope.upgradeSubtree = addedSubtree; |
scope.upgradeAll = addedNode; |
- scope.attachedNode = attachedNode; |
+ scope.attached = attached; |
scope.takeRecords = takeRecords; |
}); |
window.CustomElements.addModule(function(scope) { |
var flags = scope.flags; |
- function upgrade(node) { |
+ function upgrade(node, isAttached) { |
+ if (node.localName === "template") { |
+ if (window.HTMLTemplateElement && HTMLTemplateElement.decorate) { |
+ HTMLTemplateElement.decorate(node); |
+ } |
+ } |
if (!node.__upgraded__ && node.nodeType === Node.ELEMENT_NODE) { |
var is = node.getAttribute("is"); |
- var definition = scope.getRegisteredDefinition(is || node.localName); |
+ var definition = scope.getRegisteredDefinition(node.localName) || scope.getRegisteredDefinition(is); |
if (definition) { |
- if (is && definition.tag == node.localName) { |
- return upgradeWithDefinition(node, definition); |
- } else if (!is && !definition.extends) { |
- return upgradeWithDefinition(node, definition); |
+ if (is && definition.tag == node.localName || !is && !definition.extends) { |
+ return upgradeWithDefinition(node, definition, isAttached); |
} |
} |
} |
} |
- function upgradeWithDefinition(element, definition) { |
+ function upgradeWithDefinition(element, definition, isAttached) { |
flags.upgrade && console.group("upgrade:", element.localName); |
if (definition.is) { |
element.setAttribute("is", definition.is); |
@@ -638,8 +714,10 @@ window.CustomElements.addModule(function(scope) { |
implementPrototype(element, definition); |
element.__upgraded__ = true; |
created(element); |
- scope.attachedNode(element); |
- scope.upgradeSubtree(element); |
+ if (isAttached) { |
+ scope.attached(element); |
+ } |
+ scope.upgradeSubtree(element, isAttached); |
flags.upgrade && console.groupEnd(); |
return element; |
} |
@@ -676,7 +754,7 @@ window.CustomElements.addModule(function(scope) { |
}); |
window.CustomElements.addModule(function(scope) { |
- var isIE11OrOlder = scope.isIE11OrOlder; |
+ var isIE = scope.isIE; |
var upgradeDocumentTree = scope.upgradeDocumentTree; |
var upgradeAll = scope.upgradeAll; |
var upgradeWithDefinition = scope.upgradeWithDefinition; |
@@ -767,17 +845,23 @@ window.CustomElements.addModule(function(scope) { |
var nativePrototype = HTMLElement.prototype; |
if (definition.is) { |
var inst = document.createElement(definition.tag); |
- var expectedPrototype = Object.getPrototypeOf(inst); |
- if (expectedPrototype === definition.prototype) { |
- nativePrototype = expectedPrototype; |
- } |
+ nativePrototype = Object.getPrototypeOf(inst); |
} |
var proto = definition.prototype, ancestor; |
- while (proto && proto !== nativePrototype) { |
+ var foundPrototype = false; |
+ while (proto) { |
+ if (proto == nativePrototype) { |
+ foundPrototype = true; |
+ } |
ancestor = Object.getPrototypeOf(proto); |
- proto.__proto__ = ancestor; |
+ if (ancestor) { |
+ proto.__proto__ = ancestor; |
+ } |
proto = ancestor; |
} |
+ if (!foundPrototype) { |
+ console.warn(definition.tag + " prototype not found in prototype chain for " + definition.is); |
+ } |
definition.native = nativePrototype; |
} |
} |
@@ -839,6 +923,9 @@ 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) { |
@@ -863,7 +950,7 @@ window.CustomElements.addModule(function(scope) { |
} |
wrapDomMethodToForceUpgrade(Node.prototype, "cloneNode"); |
wrapDomMethodToForceUpgrade(document, "importNode"); |
- if (isIE11OrOlder) { |
+ if (isIE) { |
(function() { |
var importNode = document.importNode; |
document.importNode = function() { |
@@ -891,7 +978,7 @@ window.CustomElements.addModule(function(scope) { |
(function(scope) { |
var useNative = scope.useNative; |
var initializeModules = scope.initializeModules; |
- var isIE11OrOlder = /Trident/.test(navigator.userAgent); |
+ var isIE = scope.isIE; |
if (useNative) { |
var nop = function() {}; |
scope.watchShadow = nop; |
@@ -907,6 +994,7 @@ 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; |
@@ -917,39 +1005,30 @@ window.CustomElements.addModule(function(scope) { |
}; |
} |
} |
+ if (window.HTMLImports) { |
+ window.HTMLImports.__importsParsingHook = function(elt) { |
+ if (elt.import) { |
+ upgradeDocument(wrap(elt.import)); |
+ } |
+ }; |
+ } |
function bootstrap() { |
upgradeDocumentTree(window.wrap(document)); |
- if (window.HTMLImports) { |
- window.HTMLImports.__importsParsingHook = function(elt) { |
- upgradeDocumentTree(wrap(elt.import)); |
- }; |
- } |
window.CustomElements.ready = true; |
- 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 |
- })); |
- }); |
- } |
- 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); |
- e.preventDefault = function() { |
- Object.defineProperty(this, "defaultPrevented", { |
- get: function() { |
- return true; |
- } |
- }); |
- }; |
- return e; |
+ var requestAnimationFrame = window.requestAnimationFrame || function(f) { |
+ setTimeout(f, 16); |
}; |
- window.CustomEvent.prototype = window.Event.prototype; |
+ 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 |
+ })); |
+ }); |
+ }); |
} |
if (document.readyState === "complete" || scope.flags.eager) { |
bootstrap(); |
@@ -959,5 +1038,4 @@ window.CustomElements.addModule(function(scope) { |
var loadEvent = window.HTMLImports && !window.HTMLImports.ready ? "HTMLImportsLoaded" : "DOMContentLoaded"; |
window.addEventListener(loadEvent, bootstrap); |
} |
- scope.isIE11OrOlder = isIE11OrOlder; |
})(window.CustomElements); |