| 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 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 Loading... |
| 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 Loading... |
| 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.CustomElements = window.CustomElements || { | 424 window.CustomElements = window.CustomElements || { |
| 347 flags: {} | 425 flags: {} |
| 348 }; | 426 }; |
| 349 | 427 |
| 350 (function(scope) { | 428 (function(scope) { |
| 351 var flags = scope.flags; | 429 var flags = scope.flags; |
| 352 var modules = []; | 430 var modules = []; |
| 353 var addModule = function(module) { | 431 var addModule = function(module) { |
| 354 modules.push(module); | 432 modules.push(module); |
| 355 }; | 433 }; |
| 356 var initializeModules = function() { | 434 var initializeModules = function() { |
| 357 modules.forEach(function(module) { | 435 modules.forEach(function(module) { |
| 358 module(scope); | 436 module(scope); |
| 359 }); | 437 }); |
| 360 }; | 438 }; |
| 361 scope.addModule = addModule; | 439 scope.addModule = addModule; |
| 362 scope.initializeModules = initializeModules; | 440 scope.initializeModules = initializeModules; |
| 363 scope.hasNative = Boolean(document.registerElement); | 441 scope.hasNative = Boolean(document.registerElement); |
| 442 scope.isIE = /Trident/.test(navigator.userAgent); |
| 364 scope.useNative = !flags.register && scope.hasNative && !window.ShadowDOMPolyf
ill && (!window.HTMLImports || window.HTMLImports.useNative); | 443 scope.useNative = !flags.register && scope.hasNative && !window.ShadowDOMPolyf
ill && (!window.HTMLImports || window.HTMLImports.useNative); |
| 365 })(window.CustomElements); | 444 })(window.CustomElements); |
| 366 | 445 |
| 367 window.CustomElements.addModule(function(scope) { | 446 window.CustomElements.addModule(function(scope) { |
| 368 var IMPORT_LINK_TYPE = window.HTMLImports ? window.HTMLImports.IMPORT_LINK_TYP
E : "none"; | 447 var IMPORT_LINK_TYPE = window.HTMLImports ? window.HTMLImports.IMPORT_LINK_TYP
E : "none"; |
| 369 function forSubtree(node, cb) { | 448 function forSubtree(node, cb) { |
| 370 findAllElements(node, function(e) { | 449 findAllElements(node, function(e) { |
| 371 if (cb(e)) { | 450 if (cb(e)) { |
| 372 return true; | 451 return true; |
| 373 } | 452 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 cb(doc); | 495 cb(doc); |
| 417 } | 496 } |
| 418 scope.forDocumentTree = forDocumentTree; | 497 scope.forDocumentTree = forDocumentTree; |
| 419 scope.forSubtree = forSubtree; | 498 scope.forSubtree = forSubtree; |
| 420 }); | 499 }); |
| 421 | 500 |
| 422 window.CustomElements.addModule(function(scope) { | 501 window.CustomElements.addModule(function(scope) { |
| 423 var flags = scope.flags; | 502 var flags = scope.flags; |
| 424 var forSubtree = scope.forSubtree; | 503 var forSubtree = scope.forSubtree; |
| 425 var forDocumentTree = scope.forDocumentTree; | 504 var forDocumentTree = scope.forDocumentTree; |
| 426 function addedNode(node) { | 505 function addedNode(node, isAttached) { |
| 427 return added(node) || addedSubtree(node); | 506 return added(node, isAttached) || addedSubtree(node, isAttached); |
| 428 } | 507 } |
| 429 function added(node) { | 508 function added(node, isAttached) { |
| 430 if (scope.upgrade(node)) { | 509 if (scope.upgrade(node, isAttached)) { |
| 431 return true; | 510 return true; |
| 432 } | 511 } |
| 433 attached(node); | 512 if (isAttached) { |
| 513 attached(node); |
| 514 } |
| 434 } | 515 } |
| 435 function addedSubtree(node) { | 516 function addedSubtree(node, isAttached) { |
| 436 forSubtree(node, function(e) { | 517 forSubtree(node, function(e) { |
| 437 if (added(e)) { | 518 if (added(e, isAttached)) { |
| 438 return true; | 519 return true; |
| 439 } | 520 } |
| 440 }); | 521 }); |
| 441 } | 522 } |
| 442 function attachedNode(node) { | 523 var hasThrottledAttached = window.MutationObserver._isPolyfilled && flags["thr
ottle-attached"]; |
| 443 attached(node); | 524 scope.hasPolyfillMutations = hasThrottledAttached; |
| 444 if (inDocument(node)) { | 525 scope.hasThrottledAttached = hasThrottledAttached; |
| 445 forSubtree(node, function(e) { | |
| 446 attached(e); | |
| 447 }); | |
| 448 } | |
| 449 } | |
| 450 var hasPolyfillMutations = !window.MutationObserver || window.MutationObserver
=== window.JsMutationObserver; | |
| 451 scope.hasPolyfillMutations = hasPolyfillMutations; | |
| 452 var isPendingMutations = false; | 526 var isPendingMutations = false; |
| 453 var pendingMutations = []; | 527 var pendingMutations = []; |
| 454 function deferMutation(fn) { | 528 function deferMutation(fn) { |
| 455 pendingMutations.push(fn); | 529 pendingMutations.push(fn); |
| 456 if (!isPendingMutations) { | 530 if (!isPendingMutations) { |
| 457 isPendingMutations = true; | 531 isPendingMutations = true; |
| 458 setTimeout(takeMutations); | 532 setTimeout(takeMutations); |
| 459 } | 533 } |
| 460 } | 534 } |
| 461 function takeMutations() { | 535 function takeMutations() { |
| 462 isPendingMutations = false; | 536 isPendingMutations = false; |
| 463 var $p = pendingMutations; | 537 var $p = pendingMutations; |
| 464 for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) { | 538 for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) { |
| 465 p(); | 539 p(); |
| 466 } | 540 } |
| 467 pendingMutations = []; | 541 pendingMutations = []; |
| 468 } | 542 } |
| 469 function attached(element) { | 543 function attached(element) { |
| 470 if (hasPolyfillMutations) { | 544 if (hasThrottledAttached) { |
| 471 deferMutation(function() { | 545 deferMutation(function() { |
| 472 _attached(element); | 546 _attached(element); |
| 473 }); | 547 }); |
| 474 } else { | 548 } else { |
| 475 _attached(element); | 549 _attached(element); |
| 476 } | 550 } |
| 477 } | 551 } |
| 478 function _attached(element) { | 552 function _attached(element) { |
| 479 if (element.__upgraded__ && (element.attachedCallback || element.detachedCal
lback)) { | 553 if (element.__upgraded__ && !element.__attached) { |
| 480 if (!element.__attached && inDocument(element)) { | 554 element.__attached = true; |
| 481 element.__attached = true; | 555 if (element.attachedCallback) { |
| 482 if (element.attachedCallback) { | 556 element.attachedCallback(); |
| 483 element.attachedCallback(); | |
| 484 } | |
| 485 } | 557 } |
| 486 } | 558 } |
| 487 } | 559 } |
| 488 function detachedNode(node) { | 560 function detachedNode(node) { |
| 489 detached(node); | 561 detached(node); |
| 490 forSubtree(node, function(e) { | 562 forSubtree(node, function(e) { |
| 491 detached(e); | 563 detached(e); |
| 492 }); | 564 }); |
| 493 } | 565 } |
| 494 function detached(element) { | 566 function detached(element) { |
| 495 if (hasPolyfillMutations) { | 567 if (hasThrottledAttached) { |
| 496 deferMutation(function() { | 568 deferMutation(function() { |
| 497 _detached(element); | 569 _detached(element); |
| 498 }); | 570 }); |
| 499 } else { | 571 } else { |
| 500 _detached(element); | 572 _detached(element); |
| 501 } | 573 } |
| 502 } | 574 } |
| 503 function _detached(element) { | 575 function _detached(element) { |
| 504 if (element.__upgraded__ && (element.attachedCallback || element.detachedCal
lback)) { | 576 if (element.__upgraded__ && element.__attached) { |
| 505 if (element.__attached && !inDocument(element)) { | 577 element.__attached = false; |
| 506 element.__attached = false; | 578 if (element.detachedCallback) { |
| 507 if (element.detachedCallback) { | 579 element.detachedCallback(); |
| 508 element.detachedCallback(); | |
| 509 } | |
| 510 } | 580 } |
| 511 } | 581 } |
| 512 } | 582 } |
| 513 function inDocument(element) { | 583 function inDocument(element) { |
| 514 var p = element; | 584 var p = element; |
| 515 var doc = wrap(document); | 585 var doc = window.wrap(document); |
| 516 while (p) { | 586 while (p) { |
| 517 if (p == doc) { | 587 if (p == doc) { |
| 518 return true; | 588 return true; |
| 519 } | 589 } |
| 520 p = p.parentNode || p.nodeType === Node.DOCUMENT_FRAGMENT_NODE && p.host; | 590 p = p.parentNode || p.nodeType === Node.DOCUMENT_FRAGMENT_NODE && p.host; |
| 521 } | 591 } |
| 522 } | 592 } |
| 523 function watchShadow(node) { | 593 function watchShadow(node) { |
| 524 if (node.shadowRoot && !node.shadowRoot.__watched) { | 594 if (node.shadowRoot && !node.shadowRoot.__watched) { |
| 525 flags.dom && console.log("watching shadow-root for: ", node.localName); | 595 flags.dom && console.log("watching shadow-root for: ", node.localName); |
| 526 var root = node.shadowRoot; | 596 var root = node.shadowRoot; |
| 527 while (root) { | 597 while (root) { |
| 528 observe(root); | 598 observe(root); |
| 529 root = root.olderShadowRoot; | 599 root = root.olderShadowRoot; |
| 530 } | 600 } |
| 531 } | 601 } |
| 532 } | 602 } |
| 533 function handler(mutations) { | 603 function handler(root, mutations) { |
| 534 if (flags.dom) { | 604 if (flags.dom) { |
| 535 var mx = mutations[0]; | 605 var mx = mutations[0]; |
| 536 if (mx && mx.type === "childList" && mx.addedNodes) { | 606 if (mx && mx.type === "childList" && mx.addedNodes) { |
| 537 if (mx.addedNodes) { | 607 if (mx.addedNodes) { |
| 538 var d = mx.addedNodes[0]; | 608 var d = mx.addedNodes[0]; |
| 539 while (d && d !== document && !d.host) { | 609 while (d && d !== document && !d.host) { |
| 540 d = d.parentNode; | 610 d = d.parentNode; |
| 541 } | 611 } |
| 542 var u = d && (d.URL || d._URL || d.host && d.host.localName) || ""; | 612 var u = d && (d.URL || d._URL || d.host && d.host.localName) || ""; |
| 543 u = u.split("/?").shift().split("/").pop(); | 613 u = u.split("/?").shift().split("/").pop(); |
| 544 } | 614 } |
| 545 } | 615 } |
| 546 console.group("mutations (%d) [%s]", mutations.length, u || ""); | 616 console.group("mutations (%d) [%s]", mutations.length, u || ""); |
| 547 } | 617 } |
| 618 var isAttached = inDocument(root); |
| 548 mutations.forEach(function(mx) { | 619 mutations.forEach(function(mx) { |
| 549 if (mx.type === "childList") { | 620 if (mx.type === "childList") { |
| 550 forEach(mx.addedNodes, function(n) { | 621 forEach(mx.addedNodes, function(n) { |
| 551 if (!n.localName) { | 622 if (!n.localName) { |
| 552 return; | 623 return; |
| 553 } | 624 } |
| 554 addedNode(n); | 625 addedNode(n, isAttached); |
| 555 }); | 626 }); |
| 556 forEach(mx.removedNodes, function(n) { | 627 forEach(mx.removedNodes, function(n) { |
| 557 if (!n.localName) { | 628 if (!n.localName) { |
| 558 return; | 629 return; |
| 559 } | 630 } |
| 560 detachedNode(n); | 631 detachedNode(n); |
| 561 }); | 632 }); |
| 562 } | 633 } |
| 563 }); | 634 }); |
| 564 flags.dom && console.groupEnd(); | 635 flags.dom && console.groupEnd(); |
| 565 } | 636 } |
| 566 function takeRecords(node) { | 637 function takeRecords(node) { |
| 567 node = window.wrap(node); | 638 node = window.wrap(node); |
| 568 if (!node) { | 639 if (!node) { |
| 569 node = window.wrap(document); | 640 node = window.wrap(document); |
| 570 } | 641 } |
| 571 while (node.parentNode) { | 642 while (node.parentNode) { |
| 572 node = node.parentNode; | 643 node = node.parentNode; |
| 573 } | 644 } |
| 574 var observer = node.__observer; | 645 var observer = node.__observer; |
| 575 if (observer) { | 646 if (observer) { |
| 576 handler(observer.takeRecords()); | 647 handler(node, observer.takeRecords()); |
| 577 takeMutations(); | 648 takeMutations(); |
| 578 } | 649 } |
| 579 } | 650 } |
| 580 var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach); | 651 var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach); |
| 581 function observe(inRoot) { | 652 function observe(inRoot) { |
| 582 if (inRoot.__observer) { | 653 if (inRoot.__observer) { |
| 583 return; | 654 return; |
| 584 } | 655 } |
| 585 var observer = new MutationObserver(handler); | 656 var observer = new MutationObserver(handler.bind(this, inRoot)); |
| 586 observer.observe(inRoot, { | 657 observer.observe(inRoot, { |
| 587 childList: true, | 658 childList: true, |
| 588 subtree: true | 659 subtree: true |
| 589 }); | 660 }); |
| 590 inRoot.__observer = observer; | 661 inRoot.__observer = observer; |
| 591 } | 662 } |
| 592 function upgradeDocument(doc) { | 663 function upgradeDocument(doc) { |
| 593 doc = window.wrap(doc); | 664 doc = window.wrap(doc); |
| 594 flags.dom && console.group("upgradeDocument: ", doc.baseURI.split("/").pop()
); | 665 flags.dom && console.group("upgradeDocument: ", doc.baseURI.split("/").pop()
); |
| 595 addedNode(doc); | 666 var isMainDocument = doc === window.wrap(document); |
| 667 addedNode(doc, isMainDocument); |
| 596 observe(doc); | 668 observe(doc); |
| 597 flags.dom && console.groupEnd(); | 669 flags.dom && console.groupEnd(); |
| 598 } | 670 } |
| 599 function upgradeDocumentTree(doc) { | 671 function upgradeDocumentTree(doc) { |
| 600 forDocumentTree(doc, upgradeDocument); | 672 forDocumentTree(doc, upgradeDocument); |
| 601 } | 673 } |
| 602 var originalCreateShadowRoot = Element.prototype.createShadowRoot; | 674 var originalCreateShadowRoot = Element.prototype.createShadowRoot; |
| 603 if (originalCreateShadowRoot) { | 675 if (originalCreateShadowRoot) { |
| 604 Element.prototype.createShadowRoot = function() { | 676 Element.prototype.createShadowRoot = function() { |
| 605 var root = originalCreateShadowRoot.call(this); | 677 var root = originalCreateShadowRoot.call(this); |
| 606 window.CustomElements.watchShadow(this); | 678 window.CustomElements.watchShadow(this); |
| 607 return root; | 679 return root; |
| 608 }; | 680 }; |
| 609 } | 681 } |
| 610 scope.watchShadow = watchShadow; | 682 scope.watchShadow = watchShadow; |
| 611 scope.upgradeDocumentTree = upgradeDocumentTree; | 683 scope.upgradeDocumentTree = upgradeDocumentTree; |
| 684 scope.upgradeDocument = upgradeDocument; |
| 612 scope.upgradeSubtree = addedSubtree; | 685 scope.upgradeSubtree = addedSubtree; |
| 613 scope.upgradeAll = addedNode; | 686 scope.upgradeAll = addedNode; |
| 614 scope.attachedNode = attachedNode; | 687 scope.attached = attached; |
| 615 scope.takeRecords = takeRecords; | 688 scope.takeRecords = takeRecords; |
| 616 }); | 689 }); |
| 617 | 690 |
| 618 window.CustomElements.addModule(function(scope) { | 691 window.CustomElements.addModule(function(scope) { |
| 619 var flags = scope.flags; | 692 var flags = scope.flags; |
| 620 function upgrade(node) { | 693 function upgrade(node, isAttached) { |
| 694 if (node.localName === "template") { |
| 695 if (window.HTMLTemplateElement && HTMLTemplateElement.decorate) { |
| 696 HTMLTemplateElement.decorate(node); |
| 697 } |
| 698 } |
| 621 if (!node.__upgraded__ && node.nodeType === Node.ELEMENT_NODE) { | 699 if (!node.__upgraded__ && node.nodeType === Node.ELEMENT_NODE) { |
| 622 var is = node.getAttribute("is"); | 700 var is = node.getAttribute("is"); |
| 623 var definition = scope.getRegisteredDefinition(is || node.localName); | 701 var definition = scope.getRegisteredDefinition(node.localName) || scope.ge
tRegisteredDefinition(is); |
| 624 if (definition) { | 702 if (definition) { |
| 625 if (is && definition.tag == node.localName) { | 703 if (is && definition.tag == node.localName || !is && !definition.extends
) { |
| 626 return upgradeWithDefinition(node, definition); | 704 return upgradeWithDefinition(node, definition, isAttached); |
| 627 } else if (!is && !definition.extends) { | |
| 628 return upgradeWithDefinition(node, definition); | |
| 629 } | 705 } |
| 630 } | 706 } |
| 631 } | 707 } |
| 632 } | 708 } |
| 633 function upgradeWithDefinition(element, definition) { | 709 function upgradeWithDefinition(element, definition, isAttached) { |
| 634 flags.upgrade && console.group("upgrade:", element.localName); | 710 flags.upgrade && console.group("upgrade:", element.localName); |
| 635 if (definition.is) { | 711 if (definition.is) { |
| 636 element.setAttribute("is", definition.is); | 712 element.setAttribute("is", definition.is); |
| 637 } | 713 } |
| 638 implementPrototype(element, definition); | 714 implementPrototype(element, definition); |
| 639 element.__upgraded__ = true; | 715 element.__upgraded__ = true; |
| 640 created(element); | 716 created(element); |
| 641 scope.attachedNode(element); | 717 if (isAttached) { |
| 642 scope.upgradeSubtree(element); | 718 scope.attached(element); |
| 719 } |
| 720 scope.upgradeSubtree(element, isAttached); |
| 643 flags.upgrade && console.groupEnd(); | 721 flags.upgrade && console.groupEnd(); |
| 644 return element; | 722 return element; |
| 645 } | 723 } |
| 646 function implementPrototype(element, definition) { | 724 function implementPrototype(element, definition) { |
| 647 if (Object.__proto__) { | 725 if (Object.__proto__) { |
| 648 element.__proto__ = definition.prototype; | 726 element.__proto__ = definition.prototype; |
| 649 } else { | 727 } else { |
| 650 customMixin(element, definition.prototype, definition.native); | 728 customMixin(element, definition.prototype, definition.native); |
| 651 element.__proto__ = definition.prototype; | 729 element.__proto__ = definition.prototype; |
| 652 } | 730 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 669 if (element.createdCallback) { | 747 if (element.createdCallback) { |
| 670 element.createdCallback(); | 748 element.createdCallback(); |
| 671 } | 749 } |
| 672 } | 750 } |
| 673 scope.upgrade = upgrade; | 751 scope.upgrade = upgrade; |
| 674 scope.upgradeWithDefinition = upgradeWithDefinition; | 752 scope.upgradeWithDefinition = upgradeWithDefinition; |
| 675 scope.implementPrototype = implementPrototype; | 753 scope.implementPrototype = implementPrototype; |
| 676 }); | 754 }); |
| 677 | 755 |
| 678 window.CustomElements.addModule(function(scope) { | 756 window.CustomElements.addModule(function(scope) { |
| 679 var isIE11OrOlder = scope.isIE11OrOlder; | 757 var isIE = scope.isIE; |
| 680 var upgradeDocumentTree = scope.upgradeDocumentTree; | 758 var upgradeDocumentTree = scope.upgradeDocumentTree; |
| 681 var upgradeAll = scope.upgradeAll; | 759 var upgradeAll = scope.upgradeAll; |
| 682 var upgradeWithDefinition = scope.upgradeWithDefinition; | 760 var upgradeWithDefinition = scope.upgradeWithDefinition; |
| 683 var implementPrototype = scope.implementPrototype; | 761 var implementPrototype = scope.implementPrototype; |
| 684 var useNative = scope.useNative; | 762 var useNative = scope.useNative; |
| 685 function register(name, options) { | 763 function register(name, options) { |
| 686 var definition = options || {}; | 764 var definition = options || {}; |
| 687 if (!name) { | 765 if (!name) { |
| 688 throw new Error("document.registerElement: first argument `name` must not
be empty"); | 766 throw new Error("document.registerElement: first argument `name` must not
be empty"); |
| 689 } | 767 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 definition.tag = baseTag || definition.__name; | 838 definition.tag = baseTag || definition.__name; |
| 761 if (baseTag) { | 839 if (baseTag) { |
| 762 definition.is = definition.__name; | 840 definition.is = definition.__name; |
| 763 } | 841 } |
| 764 } | 842 } |
| 765 function resolvePrototypeChain(definition) { | 843 function resolvePrototypeChain(definition) { |
| 766 if (!Object.__proto__) { | 844 if (!Object.__proto__) { |
| 767 var nativePrototype = HTMLElement.prototype; | 845 var nativePrototype = HTMLElement.prototype; |
| 768 if (definition.is) { | 846 if (definition.is) { |
| 769 var inst = document.createElement(definition.tag); | 847 var inst = document.createElement(definition.tag); |
| 770 var expectedPrototype = Object.getPrototypeOf(inst); | 848 nativePrototype = Object.getPrototypeOf(inst); |
| 771 if (expectedPrototype === definition.prototype) { | |
| 772 nativePrototype = expectedPrototype; | |
| 773 } | |
| 774 } | 849 } |
| 775 var proto = definition.prototype, ancestor; | 850 var proto = definition.prototype, ancestor; |
| 776 while (proto && proto !== nativePrototype) { | 851 var foundPrototype = false; |
| 852 while (proto) { |
| 853 if (proto == nativePrototype) { |
| 854 foundPrototype = true; |
| 855 } |
| 777 ancestor = Object.getPrototypeOf(proto); | 856 ancestor = Object.getPrototypeOf(proto); |
| 778 proto.__proto__ = ancestor; | 857 if (ancestor) { |
| 858 proto.__proto__ = ancestor; |
| 859 } |
| 779 proto = ancestor; | 860 proto = ancestor; |
| 780 } | 861 } |
| 862 if (!foundPrototype) { |
| 863 console.warn(definition.tag + " prototype not found in prototype chain f
or " + definition.is); |
| 864 } |
| 781 definition.native = nativePrototype; | 865 definition.native = nativePrototype; |
| 782 } | 866 } |
| 783 } | 867 } |
| 784 function instantiate(definition) { | 868 function instantiate(definition) { |
| 785 return upgradeWithDefinition(domCreateElement(definition.tag), definition); | 869 return upgradeWithDefinition(domCreateElement(definition.tag), definition); |
| 786 } | 870 } |
| 787 var registry = {}; | 871 var registry = {}; |
| 788 function getRegisteredDefinition(name) { | 872 function getRegisteredDefinition(name) { |
| 789 if (name) { | 873 if (name) { |
| 790 return registry[name.toLowerCase()]; | 874 return registry[name.toLowerCase()]; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 if (tag.indexOf("-") >= 0) { | 916 if (tag.indexOf("-") >= 0) { |
| 833 implementPrototype(element, HTMLElement); | 917 implementPrototype(element, HTMLElement); |
| 834 } | 918 } |
| 835 return element; | 919 return element; |
| 836 } | 920 } |
| 837 var domCreateElement = document.createElement.bind(document); | 921 var domCreateElement = document.createElement.bind(document); |
| 838 var domCreateElementNS = document.createElementNS.bind(document); | 922 var domCreateElementNS = document.createElementNS.bind(document); |
| 839 var isInstance; | 923 var isInstance; |
| 840 if (!Object.__proto__ && !useNative) { | 924 if (!Object.__proto__ && !useNative) { |
| 841 isInstance = function(obj, ctor) { | 925 isInstance = function(obj, ctor) { |
| 926 if (obj instanceof ctor) { |
| 927 return true; |
| 928 } |
| 842 var p = obj; | 929 var p = obj; |
| 843 while (p) { | 930 while (p) { |
| 844 if (p === ctor.prototype) { | 931 if (p === ctor.prototype) { |
| 845 return true; | 932 return true; |
| 846 } | 933 } |
| 847 p = p.__proto__; | 934 p = p.__proto__; |
| 848 } | 935 } |
| 849 return false; | 936 return false; |
| 850 }; | 937 }; |
| 851 } else { | 938 } else { |
| 852 isInstance = function(obj, base) { | 939 isInstance = function(obj, base) { |
| 853 return obj instanceof base; | 940 return obj instanceof base; |
| 854 }; | 941 }; |
| 855 } | 942 } |
| 856 function wrapDomMethodToForceUpgrade(obj, methodName) { | 943 function wrapDomMethodToForceUpgrade(obj, methodName) { |
| 857 var orig = obj[methodName]; | 944 var orig = obj[methodName]; |
| 858 obj[methodName] = function() { | 945 obj[methodName] = function() { |
| 859 var n = orig.apply(this, arguments); | 946 var n = orig.apply(this, arguments); |
| 860 upgradeAll(n); | 947 upgradeAll(n); |
| 861 return n; | 948 return n; |
| 862 }; | 949 }; |
| 863 } | 950 } |
| 864 wrapDomMethodToForceUpgrade(Node.prototype, "cloneNode"); | 951 wrapDomMethodToForceUpgrade(Node.prototype, "cloneNode"); |
| 865 wrapDomMethodToForceUpgrade(document, "importNode"); | 952 wrapDomMethodToForceUpgrade(document, "importNode"); |
| 866 if (isIE11OrOlder) { | 953 if (isIE) { |
| 867 (function() { | 954 (function() { |
| 868 var importNode = document.importNode; | 955 var importNode = document.importNode; |
| 869 document.importNode = function() { | 956 document.importNode = function() { |
| 870 var n = importNode.apply(document, arguments); | 957 var n = importNode.apply(document, arguments); |
| 871 if (n.nodeType == n.DOCUMENT_FRAGMENT_NODE) { | 958 if (n.nodeType == n.DOCUMENT_FRAGMENT_NODE) { |
| 872 var f = document.createDocumentFragment(); | 959 var f = document.createDocumentFragment(); |
| 873 f.appendChild(n); | 960 f.appendChild(n); |
| 874 return f; | 961 return f; |
| 875 } else { | 962 } else { |
| 876 return n; | 963 return n; |
| 877 } | 964 } |
| 878 }; | 965 }; |
| 879 })(); | 966 })(); |
| 880 } | 967 } |
| 881 document.registerElement = register; | 968 document.registerElement = register; |
| 882 document.createElement = createElement; | 969 document.createElement = createElement; |
| 883 document.createElementNS = createElementNS; | 970 document.createElementNS = createElementNS; |
| 884 scope.registry = registry; | 971 scope.registry = registry; |
| 885 scope.instanceof = isInstance; | 972 scope.instanceof = isInstance; |
| 886 scope.reservedTagList = reservedTagList; | 973 scope.reservedTagList = reservedTagList; |
| 887 scope.getRegisteredDefinition = getRegisteredDefinition; | 974 scope.getRegisteredDefinition = getRegisteredDefinition; |
| 888 document.register = document.registerElement; | 975 document.register = document.registerElement; |
| 889 }); | 976 }); |
| 890 | 977 |
| 891 (function(scope) { | 978 (function(scope) { |
| 892 var useNative = scope.useNative; | 979 var useNative = scope.useNative; |
| 893 var initializeModules = scope.initializeModules; | 980 var initializeModules = scope.initializeModules; |
| 894 var isIE11OrOlder = /Trident/.test(navigator.userAgent); | 981 var isIE = scope.isIE; |
| 895 if (useNative) { | 982 if (useNative) { |
| 896 var nop = function() {}; | 983 var nop = function() {}; |
| 897 scope.watchShadow = nop; | 984 scope.watchShadow = nop; |
| 898 scope.upgrade = nop; | 985 scope.upgrade = nop; |
| 899 scope.upgradeAll = nop; | 986 scope.upgradeAll = nop; |
| 900 scope.upgradeDocumentTree = nop; | 987 scope.upgradeDocumentTree = nop; |
| 901 scope.upgradeSubtree = nop; | 988 scope.upgradeSubtree = nop; |
| 902 scope.takeRecords = nop; | 989 scope.takeRecords = nop; |
| 903 scope.instanceof = function(obj, base) { | 990 scope.instanceof = function(obj, base) { |
| 904 return obj instanceof base; | 991 return obj instanceof base; |
| 905 }; | 992 }; |
| 906 } else { | 993 } else { |
| 907 initializeModules(); | 994 initializeModules(); |
| 908 } | 995 } |
| 909 var upgradeDocumentTree = scope.upgradeDocumentTree; | 996 var upgradeDocumentTree = scope.upgradeDocumentTree; |
| 997 var upgradeDocument = scope.upgradeDocument; |
| 910 if (!window.wrap) { | 998 if (!window.wrap) { |
| 911 if (window.ShadowDOMPolyfill) { | 999 if (window.ShadowDOMPolyfill) { |
| 912 window.wrap = window.ShadowDOMPolyfill.wrapIfNeeded; | 1000 window.wrap = window.ShadowDOMPolyfill.wrapIfNeeded; |
| 913 window.unwrap = window.ShadowDOMPolyfill.unwrapIfNeeded; | 1001 window.unwrap = window.ShadowDOMPolyfill.unwrapIfNeeded; |
| 914 } else { | 1002 } else { |
| 915 window.wrap = window.unwrap = function(node) { | 1003 window.wrap = window.unwrap = function(node) { |
| 916 return node; | 1004 return node; |
| 917 }; | 1005 }; |
| 918 } | 1006 } |
| 919 } | 1007 } |
| 1008 if (window.HTMLImports) { |
| 1009 window.HTMLImports.__importsParsingHook = function(elt) { |
| 1010 if (elt.import) { |
| 1011 upgradeDocument(wrap(elt.import)); |
| 1012 } |
| 1013 }; |
| 1014 } |
| 920 function bootstrap() { | 1015 function bootstrap() { |
| 921 upgradeDocumentTree(window.wrap(document)); | 1016 upgradeDocumentTree(window.wrap(document)); |
| 922 if (window.HTMLImports) { | |
| 923 window.HTMLImports.__importsParsingHook = function(elt) { | |
| 924 upgradeDocumentTree(wrap(elt.import)); | |
| 925 }; | |
| 926 } | |
| 927 window.CustomElements.ready = true; | 1017 window.CustomElements.ready = true; |
| 928 setTimeout(function() { | 1018 var requestAnimationFrame = window.requestAnimationFrame || function(f) { |
| 929 window.CustomElements.readyTime = Date.now(); | 1019 setTimeout(f, 16); |
| 930 if (window.HTMLImports) { | 1020 }; |
| 931 window.CustomElements.elapsed = window.CustomElements.readyTime - window
.HTMLImports.readyTime; | 1021 requestAnimationFrame(function() { |
| 932 } | 1022 setTimeout(function() { |
| 933 document.dispatchEvent(new CustomEvent("WebComponentsReady", { | 1023 window.CustomElements.readyTime = Date.now(); |
| 934 bubbles: true | 1024 if (window.HTMLImports) { |
| 935 })); | 1025 window.CustomElements.elapsed = window.CustomElements.readyTime - wind
ow.HTMLImports.readyTime; |
| 1026 } |
| 1027 document.dispatchEvent(new CustomEvent("WebComponentsReady", { |
| 1028 bubbles: true |
| 1029 })); |
| 1030 }); |
| 936 }); | 1031 }); |
| 937 } | 1032 } |
| 938 if (isIE11OrOlder && typeof window.CustomEvent !== "function") { | |
| 939 window.CustomEvent = function(inType, params) { | |
| 940 params = params || {}; | |
| 941 var e = document.createEvent("CustomEvent"); | |
| 942 e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelab
le), params.detail); | |
| 943 e.preventDefault = function() { | |
| 944 Object.defineProperty(this, "defaultPrevented", { | |
| 945 get: function() { | |
| 946 return true; | |
| 947 } | |
| 948 }); | |
| 949 }; | |
| 950 return e; | |
| 951 }; | |
| 952 window.CustomEvent.prototype = window.Event.prototype; | |
| 953 } | |
| 954 if (document.readyState === "complete" || scope.flags.eager) { | 1033 if (document.readyState === "complete" || scope.flags.eager) { |
| 955 bootstrap(); | 1034 bootstrap(); |
| 956 } else if (document.readyState === "interactive" && !window.attachEvent && (!w
indow.HTMLImports || window.HTMLImports.ready)) { | 1035 } else if (document.readyState === "interactive" && !window.attachEvent && (!w
indow.HTMLImports || window.HTMLImports.ready)) { |
| 957 bootstrap(); | 1036 bootstrap(); |
| 958 } else { | 1037 } else { |
| 959 var loadEvent = window.HTMLImports && !window.HTMLImports.ready ? "HTMLImpor
tsLoaded" : "DOMContentLoaded"; | 1038 var loadEvent = window.HTMLImports && !window.HTMLImports.ready ? "HTMLImpor
tsLoaded" : "DOMContentLoaded"; |
| 960 window.addEventListener(loadEvent, bootstrap); | 1039 window.addEventListener(loadEvent, bootstrap); |
| 961 } | 1040 } |
| 962 scope.isIE11OrOlder = isIE11OrOlder; | |
| 963 })(window.CustomElements); | 1041 })(window.CustomElements); |
| OLD | NEW |