1/** 2 * @license 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://polymer.github.io/LICENSE.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/CONTRIBUTORS.txt 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/PATENTS.txt 9 */ 10// @version 0.7.24 11if (typeof WeakMap === "undefined") { 12 (function() { 13 var defineProperty = Object.defineProperty; 14 var counter = Date.now() % 1e9; 15 var WeakMap = function() { 16 this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__"); 17 }; 18 WeakMap.prototype = { 19 set: function(key, value) { 20 var entry = key[this.name]; 21 if (entry && entry[0] === key) entry[1] = value; else defineProperty(key, this.name, { 22 value: [ key, value ], 23 writable: true 24 }); 25 return this; 26 }, 27 get: function(key) { 28 var entry; 29 return (entry = key[this.name]) && entry[0] === key ? entry[1] : undefined; 30 }, 31 "delete": function(key) { 32 var entry = key[this.name]; 33 if (!entry || entry[0] !== key) return false; 34 entry[0] = entry[1] = undefined; 35 return true; 36 }, 37 has: function(key) { 38 var entry = key[this.name]; 39 if (!entry) return false; 40 return entry[0] === key; 41 } 42 }; 43 window.WeakMap = WeakMap; 44 })(); 45} 46 47(function(global) { 48 if (global.JsMutationObserver) { 49 return; 50 } 51 var registrationsTable = new WeakMap(); 52 var setImmediate; 53 if (/Trident|Edge/.test(navigator.userAgent)) { 54 setImmediate = setTimeout; 55 } else if (window.setImmediate) { 56 setImmediate = window.setImmediate; 57 } else { 58 var setImmediateQueue = []; 59 var sentinel = String(Math.random()); 60 window.addEventListener("message", function(e) { 61 if (e.data === sentinel) { 62 var queue = setImmediateQueue; 63 setImmediateQueue = []; 64 queue.forEach(function(func) { 65 func(); 66 }); 67 } 68 }); 69 setImmediate = function(func) { 70 setImmediateQueue.push(func); 71 window.postMessage(sentinel, "*"); 72 }; 73 } 74 var isScheduled = false; 75 var scheduledObservers = []; 76 function scheduleCallback(observer) { 77 scheduledObservers.push(observer); 78 if (!isScheduled) { 79 isScheduled = true; 80 setImmediate(dispatchCallbacks); 81 } 82 } 83 function wrapIfNeeded(node) { 84 return window.ShadowDOMPolyfill && window.ShadowDOMPolyfill.wrapIfNeeded(node) || node; 85 } 86 function dispatchCallbacks() { 87 isScheduled = false; 88 var observers = scheduledObservers; 89 scheduledObservers = []; 90 observers.sort(function(o1, o2) { 91 return o1.uid_ - o2.uid_; 92 }); 93 var anyNonEmpty = false; 94 observers.forEach(function(observer) { 95 var queue = observer.takeRecords(); 96 removeTransientObserversFor(observer); 97 if (queue.length) { 98 observer.callback_(queue, observer); 99 anyNonEmpty = true; 100 } 101 }); 102 if (anyNonEmpty) dispatchCallbacks(); 103 } 104 function removeTransientObserversFor(observer) { 105 observer.nodes_.forEach(function(node) { 106 var registrations = registrationsTable.get(node); 107 if (!registrations) return; 108 registrations.forEach(function(registration) { 109 if (registration.observer === observer) registration.removeTransientObservers(); 110 }); 111 }); 112 } 113 function forEachAncestorAndObserverEnqueueRecord(target, callback) { 114 for (var node = target; node; node = node.parentNode) { 115 var registrations = registrationsTable.get(node); 116 if (registrations) { 117 for (var j = 0; j < registrations.length; j++) { 118 var registration = registrations[j]; 119 var options = registration.options; 120 if (node !== target && !options.subtree) continue; 121 var record = callback(options); 122 if (record) registration.enqueue(record); 123 } 124 } 125 } 126 } 127 var uidCounter = 0; 128 function JsMutationObserver(callback) { 129 this.callback_ = callback; 130 this.nodes_ = []; 131 this.records_ = []; 132 this.uid_ = ++uidCounter; 133 } 134 JsMutationObserver.prototype = { 135 observe: function(target, options) { 136 target = wrapIfNeeded(target); 137 if (!options.childList && !options.attributes && !options.characterData || options.attributeOldValue && !options.attributes || options.attributeFilter && options.attributeFilter.length && !options.attributes || options.characterDataOldValue && !options.characterData) { 138 throw new SyntaxError(); 139 } 140 var registrations = registrationsTable.get(target); 141 if (!registrations) registrationsTable.set(target, registrations = []); 142 var registration; 143 for (var i = 0; i < registrations.length; i++) { 144 if (registrations[i].observer === this) { 145 registration = registrations[i]; 146 registration.removeListeners(); 147 registration.options = options; 148 break; 149 } 150 } 151 if (!registration) { 152 registration = new Registration(this, target, options); 153 registrations.push(registration); 154 this.nodes_.push(target); 155 } 156 registration.addListeners(); 157 }, 158 disconnect: function() { 159 this.nodes_.forEach(function(node) { 160 var registrations = registrationsTable.get(node); 161 for (var i = 0; i < registrations.length; i++) { 162 var registration = registrations[i]; 163 if (registration.observer === this) { 164 registration.removeListeners(); 165 registrations.splice(i, 1); 166 break; 167 } 168 } 169 }, this); 170 this.records_ = []; 171 }, 172 takeRecords: function() { 173 var copyOfRecords = this.records_; 174 this.records_ = []; 175 return copyOfRecords; 176 } 177 }; 178 function MutationRecord(type, target) { 179 this.type = type; 180 this.target = target; 181 this.addedNodes = []; 182 this.removedNodes = []; 183 this.previousSibling = null; 184 this.nextSibling = null; 185 this.attributeName = null; 186 this.attributeNamespace = null; 187 this.oldValue = null; 188 } 189 function copyMutationRecord(original) { 190 var record = new MutationRecord(original.type, original.target); 191 record.addedNodes = original.addedNodes.slice(); 192 record.removedNodes = original.removedNodes.slice(); 193 record.previousSibling = original.previousSibling; 194 record.nextSibling = original.nextSibling; 195 record.attributeName = original.attributeName; 196 record.attributeNamespace = original.attributeNamespace; 197 record.oldValue = original.oldValue; 198 return record; 199 } 200 var currentRecord, recordWithOldValue; 201 function getRecord(type, target) { 202 return currentRecord = new MutationRecord(type, target); 203 } 204 function getRecordWithOldValue(oldValue) { 205 if (recordWithOldValue) return recordWithOldValue; 206 recordWithOldValue = copyMutationRecord(currentRecord); 207 recordWithOldValue.oldValue = oldValue; 208 return recordWithOldValue; 209 } 210 function clearRecords() { 211 currentRecord = recordWithOldValue = undefined; 212 } 213 function recordRepresentsCurrentMutation(record) { 214 return record === recordWithOldValue || record === currentRecord; 215 } 216 function selectRecord(lastRecord, newRecord) { 217 if (lastRecord === newRecord) return lastRecord; 218 if (recordWithOldValue && recordRepresentsCurrentMutation(lastRecord)) return recordWithOldValue; 219 return null; 220 } 221 function Registration(observer, target, options) { 222 this.observer = observer; 223 this.target = target; 224 this.options = options; 225 this.transientObservedNodes = []; 226 } 227 Registration.prototype = { 228 enqueue: function(record) { 229 var records = this.observer.records_; 230 var length = records.length; 231 if (records.length > 0) { 232 var lastRecord = records[length - 1]; 233 var recordToReplaceLast = selectRecord(lastRecord, record); 234 if (recordToReplaceLast) { 235 records[length - 1] = recordToReplaceLast; 236 return; 237 } 238 } else { 239 scheduleCallback(this.observer); 240 } 241 records[length] = record; 242 }, 243 addListeners: function() { 244 this.addListeners_(this.target); 245 }, 246 addListeners_: function(node) { 247 var options = this.options; 248 if (options.attributes) node.addEventListener("DOMAttrModified", this, true); 249 if (options.characterData) node.addEventListener("DOMCharacterDataModified", this, true); 250 if (options.childList) node.addEventListener("DOMNodeInserted", this, true); 251 if (options.childList || options.subtree) node.addEventListener("DOMNodeRemoved", this, true); 252 }, 253 removeListeners: function() { 254 this.removeListeners_(this.target); 255 }, 256 removeListeners_: function(node) { 257 var options = this.options; 258 if (options.attributes) node.removeEventListener("DOMAttrModified", this, true); 259 if (options.characterData) node.removeEventListener("DOMCharacterDataModified", this, true); 260 if (options.childList) node.removeEventListener("DOMNodeInserted", this, true); 261 if (options.childList || options.subtree) node.removeEventListener("DOMNodeRemoved", this, true); 262 }, 263 addTransientObserver: function(node) { 264 if (node === this.target) return; 265 this.addListeners_(node); 266 this.transientObservedNodes.push(node); 267 var registrations = registrationsTable.get(node); 268 if (!registrations) registrationsTable.set(node, registrations = []); 269 registrations.push(this); 270 }, 271 removeTransientObservers: function() { 272 var transientObservedNodes = this.transientObservedNodes; 273 this.transientObservedNodes = []; 274 transientObservedNodes.forEach(function(node) { 275 this.removeListeners_(node); 276 var registrations = registrationsTable.get(node); 277 for (var i = 0; i < registrations.length; i++) { 278 if (registrations[i] === this) { 279 registrations.splice(i, 1); 280 break; 281 } 282 } 283 }, this); 284 }, 285 handleEvent: function(e) { 286 e.stopImmediatePropagation(); 287 switch (e.type) { 288 case "DOMAttrModified": 289 var name = e.attrName; 290 var namespace = e.relatedNode.namespaceURI; 291 var target = e.target; 292 var record = new getRecord("attributes", target); 293 record.attributeName = name; 294 record.attributeNamespace = namespace; 295 var oldValue = e.attrChange === MutationEvent.ADDITION ? null : e.prevValue; 296 forEachAncestorAndObserverEnqueueRecord(target, function(options) { 297 if (!options.attributes) return; 298 if (options.attributeFilter && options.attributeFilter.length && options.attributeFilter.indexOf(name) === -1 && options.attributeFilter.indexOf(namespace) === -1) { 299 return; 300 } 301 if (options.attributeOldValue) return getRecordWithOldValue(oldValue); 302 return record; 303 }); 304 break; 305 306 case "DOMCharacterDataModified": 307 var target = e.target; 308 var record = getRecord("characterData", target); 309 var oldValue = e.prevValue; 310 forEachAncestorAndObserverEnqueueRecord(target, function(options) { 311 if (!options.characterData) return; 312 if (options.characterDataOldValue) return getRecordWithOldValue(oldValue); 313 return record; 314 }); 315 break; 316 317 case "DOMNodeRemoved": 318 this.addTransientObserver(e.target); 319 320 case "DOMNodeInserted": 321 var changedNode = e.target; 322 var addedNodes, removedNodes; 323 if (e.type === "DOMNodeInserted") { 324 addedNodes = [ changedNode ]; 325 removedNodes = []; 326 } else { 327 addedNodes = []; 328 removedNodes = [ changedNode ]; 329 } 330 var previousSibling = changedNode.previousSibling; 331 var nextSibling = changedNode.nextSibling; 332 var record = getRecord("childList", e.target.parentNode); 333 record.addedNodes = addedNodes; 334 record.removedNodes = removedNodes; 335 record.previousSibling = previousSibling; 336 record.nextSibling = nextSibling; 337 forEachAncestorAndObserverEnqueueRecord(e.relatedNode, function(options) { 338 if (!options.childList) return; 339 return record; 340 }); 341 } 342 clearRecords(); 343 } 344 }; 345 global.JsMutationObserver = JsMutationObserver; 346 if (!global.MutationObserver) { 347 global.MutationObserver = JsMutationObserver; 348 JsMutationObserver._isPolyfilled = true; 349 } 350})(self); 351 352(function(scope) { 353 "use strict"; 354 if (!(window.performance && window.performance.now)) { 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.mozRequestAnimationFrame; 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.cancelable), 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 424window.CustomElements = window.CustomElements || { 425 flags: {} 426}; 427 428(function(scope) { 429 var flags = scope.flags; 430 var modules = []; 431 var addModule = function(module) { 432 modules.push(module); 433 }; 434 var initializeModules = function() { 435 modules.forEach(function(module) { 436 module(scope); 437 }); 438 }; 439 scope.addModule = addModule; 440 scope.initializeModules = initializeModules; 441 scope.hasNative = Boolean(document.registerElement); 442 scope.isIE = /Trident/.test(navigator.userAgent); 443 scope.useNative = !flags.register && scope.hasNative && !window.ShadowDOMPolyfill && (!window.HTMLImports || window.HTMLImports.useNative); 444})(window.CustomElements); 445 446window.CustomElements.addModule(function(scope) { 447 var IMPORT_LINK_TYPE = window.HTMLImports ? window.HTMLImports.IMPORT_LINK_TYPE : "none"; 448 function forSubtree(node, cb) { 449 findAllElements(node, function(e) { 450 if (cb(e)) { 451 return true; 452 } 453 forRoots(e, cb); 454 }); 455 forRoots(node, cb); 456 } 457 function findAllElements(node, find, data) { 458 var e = node.firstElementChild; 459 if (!e) { 460 e = node.firstChild; 461 while (e && e.nodeType !== Node.ELEMENT_NODE) { 462 e = e.nextSibling; 463 } 464 } 465 while (e) { 466 if (find(e, data) !== true) { 467 findAllElements(e, find, data); 468 } 469 e = e.nextElementSibling; 470 } 471 return null; 472 } 473 function forRoots(node, cb) { 474 var root = node.shadowRoot; 475 while (root) { 476 forSubtree(root, cb); 477 root = root.olderShadowRoot; 478 } 479 } 480 function forDocumentTree(doc, cb) { 481 _forDocumentTree(doc, cb, []); 482 } 483 function _forDocumentTree(doc, cb, processingDocuments) { 484 doc = window.wrap(doc); 485 if (processingDocuments.indexOf(doc) >= 0) { 486 return; 487 } 488 processingDocuments.push(doc); 489 var imports = doc.querySelectorAll("link[rel=" + IMPORT_LINK_TYPE + "]"); 490 for (var i = 0, l = imports.length, n; i < l && (n = imports[i]); i++) { 491 if (n.import) { 492 _forDocumentTree(n.import, cb, processingDocuments); 493 } 494 } 495 cb(doc); 496 } 497 scope.forDocumentTree = forDocumentTree; 498 scope.forSubtree = forSubtree; 499}); 500 501window.CustomElements.addModule(function(scope) { 502 var flags = scope.flags; 503 var forSubtree = scope.forSubtree; 504 var forDocumentTree = scope.forDocumentTree; 505 function addedNode(node, isAttached) { 506 return added(node, isAttached) || addedSubtree(node, isAttached); 507 } 508 function added(node, isAttached) { 509 if (scope.upgrade(node, isAttached)) { 510 return true; 511 } 512 if (isAttached) { 513 attached(node); 514 } 515 } 516 function addedSubtree(node, isAttached) { 517 forSubtree(node, function(e) { 518 if (added(e, isAttached)) { 519 return true; 520 } 521 }); 522 } 523 var hasThrottledAttached = window.MutationObserver._isPolyfilled && flags["throttle-attached"]; 524 scope.hasPolyfillMutations = hasThrottledAttached; 525 scope.hasThrottledAttached = hasThrottledAttached; 526 var isPendingMutations = false; 527 var pendingMutations = []; 528 function deferMutation(fn) { 529 pendingMutations.push(fn); 530 if (!isPendingMutations) { 531 isPendingMutations = true; 532 setTimeout(takeMutations); 533 } 534 } 535 function takeMutations() { 536 isPendingMutations = false; 537 var $p = pendingMutations; 538 for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) { 539 p(); 540 } 541 pendingMutations = []; 542 } 543 function attached(element) { 544 if (hasThrottledAttached) { 545 deferMutation(function() { 546 _attached(element); 547 }); 548 } else { 549 _attached(element); 550 } 551 } 552 function _attached(element) { 553 if (element.__upgraded__ && !element.__attached) { 554 element.__attached = true; 555 if (element.attachedCallback) { 556 element.attachedCallback(); 557 } 558 } 559 } 560 function detachedNode(node) { 561 detached(node); 562 forSubtree(node, function(e) { 563 detached(e); 564 }); 565 } 566 function detached(element) { 567 if (hasThrottledAttached) { 568 deferMutation(function() { 569 _detached(element); 570 }); 571 } else { 572 _detached(element); 573 } 574 } 575 function _detached(element) { 576 if (element.__upgraded__ && element.__attached) { 577 element.__attached = false; 578 if (element.detachedCallback) { 579 element.detachedCallback(); 580 } 581 } 582 } 583 function inDocument(element) { 584 var p = element; 585 var doc = window.wrap(document); 586 while (p) { 587 if (p == doc) { 588 return true; 589 } 590 p = p.parentNode || p.nodeType === Node.DOCUMENT_FRAGMENT_NODE && p.host; 591 } 592 } 593 function watchShadow(node) { 594 if (node.shadowRoot && !node.shadowRoot.__watched) { 595 flags.dom && console.log("watching shadow-root for: ", node.localName); 596 var root = node.shadowRoot; 597 while (root) { 598 observe(root); 599 root = root.olderShadowRoot; 600 } 601 } 602 } 603 function handler(root, mutations) { 604 if (flags.dom) { 605 var mx = mutations[0]; 606 if (mx && mx.type === "childList" && mx.addedNodes) { 607 if (mx.addedNodes) { 608 var d = mx.addedNodes[0]; 609 while (d && d !== document && !d.host) { 610 d = d.parentNode; 611 } 612 var u = d && (d.URL || d._URL || d.host && d.host.localName) || ""; 613 u = u.split("/?").shift().split("/").pop(); 614 } 615 } 616 console.group("mutations (%d) [%s]", mutations.length, u || ""); 617 } 618 var isAttached = inDocument(root); 619 mutations.forEach(function(mx) { 620 if (mx.type === "childList") { 621 forEach(mx.addedNodes, function(n) { 622 if (!n.localName) { 623 return; 624 } 625 addedNode(n, isAttached); 626 }); 627 forEach(mx.removedNodes, function(n) { 628 if (!n.localName) { 629 return; 630 } 631 detachedNode(n); 632 }); 633 } 634 }); 635 flags.dom && console.groupEnd(); 636 } 637 function takeRecords(node) { 638 node = window.wrap(node); 639 if (!node) { 640 node = window.wrap(document); 641 } 642 while (node.parentNode) { 643 node = node.parentNode; 644 } 645 var observer = node.__observer; 646 if (observer) { 647 handler(node, observer.takeRecords()); 648 takeMutations(); 649 } 650 } 651 var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach); 652 function observe(inRoot) { 653 if (inRoot.__observer) { 654 return; 655 } 656 var observer = new MutationObserver(handler.bind(this, inRoot)); 657 observer.observe(inRoot, { 658 childList: true, 659 subtree: true 660 }); 661 inRoot.__observer = observer; 662 } 663 function upgradeDocument(doc) { 664 doc = window.wrap(doc); 665 flags.dom && console.group("upgradeDocument: ", doc.baseURI.split("/").pop()); 666 var isMainDocument = doc === window.wrap(document); 667 addedNode(doc, isMainDocument); 668 observe(doc); 669 flags.dom && console.groupEnd(); 670 } 671 function upgradeDocumentTree(doc) { 672 forDocumentTree(doc, upgradeDocument); 673 } 674 var originalCreateShadowRoot = Element.prototype.createShadowRoot; 675 if (originalCreateShadowRoot) { 676 Element.prototype.createShadowRoot = function() { 677 var root = originalCreateShadowRoot.call(this); 678 window.CustomElements.watchShadow(this); 679 return root; 680 }; 681 } 682 scope.watchShadow = watchShadow; 683 scope.upgradeDocumentTree = upgradeDocumentTree; 684 scope.upgradeDocument = upgradeDocument; 685 scope.upgradeSubtree = addedSubtree; 686 scope.upgradeAll = addedNode; 687 scope.attached = attached; 688 scope.takeRecords = takeRecords; 689}); 690 691window.CustomElements.addModule(function(scope) { 692 var flags = scope.flags; 693 function upgrade(node, isAttached) { 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) { 700 var is = node.getAttribute("is"); 701 var definition = scope.getRegisteredDefinition(node.localName) || scope.getRegisteredDefinition(is); 702 if (definition) { 703 if (is && definition.tag == node.localName || !is && !definition.extends) { 704 return upgradeWithDefinition(node, definition, isAttached); 705 } 706 } 707 } 708 } 709 function upgradeWithDefinition(element, definition, isAttached) { 710 flags.upgrade && console.group("upgrade:", element.localName); 711 if (definition.is) { 712 element.setAttribute("is", definition.is); 713 } 714 implementPrototype(element, definition); 715 element.__upgraded__ = true; 716 created(element); 717 if (isAttached) { 718 scope.attached(element); 719 } 720 scope.upgradeSubtree(element, isAttached); 721 flags.upgrade && console.groupEnd(); 722 return element; 723 } 724 function implementPrototype(element, definition) { 725 if (Object.__proto__) { 726 element.__proto__ = definition.prototype; 727 } else { 728 customMixin(element, definition.prototype, definition.native); 729 element.__proto__ = definition.prototype; 730 } 731 } 732 function customMixin(inTarget, inSrc, inNative) { 733 var used = {}; 734 var p = inSrc; 735 while (p !== inNative && p !== HTMLElement.prototype) { 736 var keys = Object.getOwnPropertyNames(p); 737 for (var i = 0, k; k = keys[i]; i++) { 738 if (!used[k]) { 739 Object.defineProperty(inTarget, k, Object.getOwnPropertyDescriptor(p, k)); 740 used[k] = 1; 741 } 742 } 743 p = Object.getPrototypeOf(p); 744 } 745 } 746 function created(element) { 747 if (element.createdCallback) { 748 element.createdCallback(); 749 } 750 } 751 scope.upgrade = upgrade; 752 scope.upgradeWithDefinition = upgradeWithDefinition; 753 scope.implementPrototype = implementPrototype; 754}); 755 756window.CustomElements.addModule(function(scope) { 757 var isIE = scope.isIE; 758 var upgradeDocumentTree = scope.upgradeDocumentTree; 759 var upgradeAll = scope.upgradeAll; 760 var upgradeWithDefinition = scope.upgradeWithDefinition; 761 var implementPrototype = scope.implementPrototype; 762 var useNative = scope.useNative; 763 function register(name, options) { 764 var definition = options || {}; 765 if (!name) { 766 throw new Error("document.registerElement: first argument `name` must not be empty"); 767 } 768 if (name.indexOf("-") < 0) { 769 throw new Error("document.registerElement: first argument ('name') must contain a dash ('-'). Argument provided was '" + String(name) + "'."); 770 } 771 if (isReservedTag(name)) { 772 throw new Error("Failed to execute 'registerElement' on 'Document': Registration failed for type '" + String(name) + "'. The type name is invalid."); 773 } 774 if (getRegisteredDefinition(name)) { 775 throw new Error("DuplicateDefinitionError: a type with name '" + String(name) + "' is already registered"); 776 } 777 if (!definition.prototype) { 778 definition.prototype = Object.create(HTMLElement.prototype); 779 } 780 definition.__name = name.toLowerCase(); 781 if (definition.extends) { 782 definition.extends = definition.extends.toLowerCase(); 783 } 784 definition.lifecycle = definition.lifecycle || {}; 785 definition.ancestry = ancestry(definition.extends); 786 resolveTagName(definition); 787 resolvePrototypeChain(definition); 788 overrideAttributeApi(definition.prototype); 789 registerDefinition(definition.__name, definition); 790 definition.ctor = generateConstructor(definition); 791 definition.ctor.prototype = definition.prototype; 792 definition.prototype.constructor = definition.ctor; 793 if (scope.ready) { 794 upgradeDocumentTree(document); 795 } 796 return definition.ctor; 797 } 798 function overrideAttributeApi(prototype) { 799 if (prototype.setAttribute._polyfilled) { 800 return; 801 } 802 var setAttribute = prototype.setAttribute; 803 prototype.setAttribute = function(name, value) { 804 changeAttribute.call(this, name, value, setAttribute); 805 }; 806 var removeAttribute = prototype.removeAttribute; 807 prototype.removeAttribute = function(name) { 808 changeAttribute.call(this, name, null, removeAttribute); 809 }; 810 prototype.setAttribute._polyfilled = true; 811 } 812 function changeAttribute(name, value, operation) { 813 name = name.toLowerCase(); 814 var oldValue = this.getAttribute(name); 815 operation.apply(this, arguments); 816 var newValue = this.getAttribute(name); 817 if (this.attributeChangedCallback && newValue !== oldValue) { 818 this.attributeChangedCallback(name, oldValue, newValue); 819 } 820 } 821 function isReservedTag(name) { 822 for (var i = 0; i < reservedTagList.length; i++) { 823 if (name === reservedTagList[i]) { 824 return true; 825 } 826 } 827 } 828 var reservedTagList = [ "annotation-xml", "color-profile", "font-face", "font-face-src", "font-face-uri", "font-face-format", "font-face-name", "missing-glyph" ]; 829 function ancestry(extnds) { 830 var extendee = getRegisteredDefinition(extnds); 831 if (extendee) { 832 return ancestry(extendee.extends).concat([ extendee ]); 833 } 834 return []; 835 } 836 function resolveTagName(definition) { 837 var baseTag = definition.extends; 838 for (var i = 0, a; a = definition.ancestry[i]; i++) { 839 baseTag = a.is && a.tag; 840 } 841 definition.tag = baseTag || definition.__name; 842 if (baseTag) { 843 definition.is = definition.__name; 844 } 845 } 846 function resolvePrototypeChain(definition) { 847 if (!Object.__proto__) { 848 var nativePrototype = HTMLElement.prototype; 849 if (definition.is) { 850 var inst = document.createElement(definition.tag); 851 nativePrototype = Object.getPrototypeOf(inst); 852 } 853 var proto = definition.prototype, ancestor; 854 var foundPrototype = false; 855 while (proto) { 856 if (proto == nativePrototype) { 857 foundPrototype = true; 858 } 859 ancestor = Object.getPrototypeOf(proto); 860 if (ancestor) { 861 proto.__proto__ = ancestor; 862 } 863 proto = ancestor; 864 } 865 if (!foundPrototype) { 866 console.warn(definition.tag + " prototype not found in prototype chain for " + definition.is); 867 } 868 definition.native = nativePrototype; 869 } 870 } 871 function instantiate(definition) { 872 return upgradeWithDefinition(domCreateElement(definition.tag), definition); 873 } 874 var registry = {}; 875 function getRegisteredDefinition(name) { 876 if (name) { 877 return registry[name.toLowerCase()]; 878 } 879 } 880 function registerDefinition(name, definition) { 881 registry[name] = definition; 882 } 883 function generateConstructor(definition) { 884 return function() { 885 return instantiate(definition); 886 }; 887 } 888 var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml"; 889 function createElementNS(namespace, tag, typeExtension) { 890 if (namespace === HTML_NAMESPACE) { 891 return createElement(tag, typeExtension); 892 } else { 893 return domCreateElementNS(namespace, tag); 894 } 895 } 896 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); 904 if (definition) { 905 if (tag == definition.tag && typeExtension == definition.is) { 906 return new definition.ctor(); 907 } 908 if (!typeExtension && !definition.is) { 909 return new definition.ctor(); 910 } 911 } 912 var element; 913 if (typeExtension) { 914 element = createElement(tag); 915 element.setAttribute("is", typeExtension); 916 return element; 917 } 918 element = domCreateElement(tag); 919 if (tag.indexOf("-") >= 0) { 920 implementPrototype(element, HTMLElement); 921 } 922 return element; 923 } 924 var domCreateElement = document.createElement.bind(document); 925 var domCreateElementNS = document.createElementNS.bind(document); 926 var isInstance; 927 if (!Object.__proto__ && !useNative) { 928 isInstance = function(obj, ctor) { 929 if (obj instanceof ctor) { 930 return true; 931 } 932 var p = obj; 933 while (p) { 934 if (p === ctor.prototype) { 935 return true; 936 } 937 p = p.__proto__; 938 } 939 return false; 940 }; 941 } else { 942 isInstance = function(obj, base) { 943 return obj instanceof base; 944 }; 945 } 946 function wrapDomMethodToForceUpgrade(obj, methodName) { 947 var orig = obj[methodName]; 948 obj[methodName] = function() { 949 var n = orig.apply(this, arguments); 950 upgradeAll(n); 951 return n; 952 }; 953 } 954 wrapDomMethodToForceUpgrade(Node.prototype, "cloneNode"); 955 wrapDomMethodToForceUpgrade(document, "importNode"); 956 document.registerElement = register; 957 document.createElement = createElement; 958 document.createElementNS = createElementNS; 959 scope.registry = registry; 960 scope.instanceof = isInstance; 961 scope.reservedTagList = reservedTagList; 962 scope.getRegisteredDefinition = getRegisteredDefinition; 963 document.register = document.registerElement; 964}); 965 966(function(scope) { 967 var useNative = scope.useNative; 968 var initializeModules = scope.initializeModules; 969 var isIE = scope.isIE; 970 if (useNative) { 971 var nop = function() {}; 972 scope.watchShadow = nop; 973 scope.upgrade = nop; 974 scope.upgradeAll = nop; 975 scope.upgradeDocumentTree = nop; 976 scope.upgradeSubtree = nop; 977 scope.takeRecords = nop; 978 scope.instanceof = function(obj, base) { 979 return obj instanceof base; 980 }; 981 } else { 982 initializeModules(); 983 } 984 var upgradeDocumentTree = scope.upgradeDocumentTree; 985 var upgradeDocument = scope.upgradeDocument; 986 if (!window.wrap) { 987 if (window.ShadowDOMPolyfill) { 988 window.wrap = window.ShadowDOMPolyfill.wrapIfNeeded; 989 window.unwrap = window.ShadowDOMPolyfill.unwrapIfNeeded; 990 } else { 991 window.wrap = window.unwrap = function(node) { 992 return node; 993 }; 994 } 995 } 996 if (window.HTMLImports) { 997 window.HTMLImports.__importsParsingHook = function(elt) { 998 if (elt.import) { 999 upgradeDocument(wrap(elt.import)); 1000 } 1001 }; 1002 } 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 - window.HTMLImports.readyTime; 1014 } 1015 document.dispatchEvent(new CustomEvent("WebComponentsReady", { 1016 bubbles: true 1017 })); 1018 }); 1019 }); 1020 } 1021 if (document.readyState === "complete" || scope.flags.eager) { 1022 bootstrap(); 1023 } else if (document.readyState === "interactive" && !window.attachEvent && (!window.HTMLImports || window.HTMLImports.ready)) { 1024 bootstrap(); 1025 } else { 1026 var loadEvent = window.HTMLImports && !window.HTMLImports.ready ? "HTMLImportsLoaded" : "DOMContentLoaded"; 1027 window.addEventListener(loadEvent, bootstrap); 1028 } 1029})(window.CustomElements);