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

Side by Side Diff: third_party/polymer/components/webcomponentsjs/CustomElements.js

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

Powered by Google App Engine
This is Rietveld 408576698