PageRenderTime 63ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/Test04/www/bower_components/webcomponentsjs/webcomponents-lite.js

https://gitlab.com/hemantr/Test04
JavaScript | 1581 lines | 1545 code | 26 blank | 10 comment | 423 complexity | 8697073030ca5b029699efc69a31b4ee MD5 | raw file
  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.20
  11. (function() {
  12. window.WebComponents = window.WebComponents || {
  13. flags: {}
  14. };
  15. var file = "webcomponents-lite.js";
  16. var script = document.querySelector('script[src*="' + file + '"]');
  17. var flags = {};
  18. if (!flags.noOpts) {
  19. location.search.slice(1).split("&").forEach(function(option) {
  20. var parts = option.split("=");
  21. var match;
  22. if (parts[0] && (match = parts[0].match(/wc-(.+)/))) {
  23. flags[match[1]] = parts[1] || true;
  24. }
  25. });
  26. if (script) {
  27. for (var i = 0, a; a = script.attributes[i]; i++) {
  28. if (a.name !== "src") {
  29. flags[a.name] = a.value || true;
  30. }
  31. }
  32. }
  33. if (flags.log && flags.log.split) {
  34. var parts = flags.log.split(",");
  35. flags.log = {};
  36. parts.forEach(function(f) {
  37. flags.log[f] = true;
  38. });
  39. } else {
  40. flags.log = {};
  41. }
  42. }
  43. if (flags.register) {
  44. window.CustomElements = window.CustomElements || {
  45. flags: {}
  46. };
  47. window.CustomElements.flags.register = flags.register;
  48. }
  49. WebComponents.flags = flags;
  50. })();
  51. (function(scope) {
  52. "use strict";
  53. var hasWorkingUrl = false;
  54. if (!scope.forceJURL) {
  55. try {
  56. var u = new URL("b", "http://a");
  57. u.pathname = "c%20d";
  58. hasWorkingUrl = u.href === "http://a/c%20d";
  59. } catch (e) {}
  60. }
  61. if (hasWorkingUrl) return;
  62. var relative = Object.create(null);
  63. relative["ftp"] = 21;
  64. relative["file"] = 0;
  65. relative["gopher"] = 70;
  66. relative["http"] = 80;
  67. relative["https"] = 443;
  68. relative["ws"] = 80;
  69. relative["wss"] = 443;
  70. var relativePathDotMapping = Object.create(null);
  71. relativePathDotMapping["%2e"] = ".";
  72. relativePathDotMapping[".%2e"] = "..";
  73. relativePathDotMapping["%2e."] = "..";
  74. relativePathDotMapping["%2e%2e"] = "..";
  75. function isRelativeScheme(scheme) {
  76. return relative[scheme] !== undefined;
  77. }
  78. function invalid() {
  79. clear.call(this);
  80. this._isInvalid = true;
  81. }
  82. function IDNAToASCII(h) {
  83. if ("" == h) {
  84. invalid.call(this);
  85. }
  86. return h.toLowerCase();
  87. }
  88. function percentEscape(c) {
  89. var unicode = c.charCodeAt(0);
  90. if (unicode > 32 && unicode < 127 && [ 34, 35, 60, 62, 63, 96 ].indexOf(unicode) == -1) {
  91. return c;
  92. }
  93. return encodeURIComponent(c);
  94. }
  95. function percentEscapeQuery(c) {
  96. var unicode = c.charCodeAt(0);
  97. if (unicode > 32 && unicode < 127 && [ 34, 35, 60, 62, 96 ].indexOf(unicode) == -1) {
  98. return c;
  99. }
  100. return encodeURIComponent(c);
  101. }
  102. var EOF = undefined, ALPHA = /[a-zA-Z]/, ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  103. function parse(input, stateOverride, base) {
  104. function err(message) {
  105. errors.push(message);
  106. }
  107. var state = stateOverride || "scheme start", cursor = 0, buffer = "", seenAt = false, seenBracket = false, errors = [];
  108. loop: while ((input[cursor - 1] != EOF || cursor == 0) && !this._isInvalid) {
  109. var c = input[cursor];
  110. switch (state) {
  111. case "scheme start":
  112. if (c && ALPHA.test(c)) {
  113. buffer += c.toLowerCase();
  114. state = "scheme";
  115. } else if (!stateOverride) {
  116. buffer = "";
  117. state = "no scheme";
  118. continue;
  119. } else {
  120. err("Invalid scheme.");
  121. break loop;
  122. }
  123. break;
  124. case "scheme":
  125. if (c && ALPHANUMERIC.test(c)) {
  126. buffer += c.toLowerCase();
  127. } else if (":" == c) {
  128. this._scheme = buffer;
  129. buffer = "";
  130. if (stateOverride) {
  131. break loop;
  132. }
  133. if (isRelativeScheme(this._scheme)) {
  134. this._isRelative = true;
  135. }
  136. if ("file" == this._scheme) {
  137. state = "relative";
  138. } else if (this._isRelative && base && base._scheme == this._scheme) {
  139. state = "relative or authority";
  140. } else if (this._isRelative) {
  141. state = "authority first slash";
  142. } else {
  143. state = "scheme data";
  144. }
  145. } else if (!stateOverride) {
  146. buffer = "";
  147. cursor = 0;
  148. state = "no scheme";
  149. continue;
  150. } else if (EOF == c) {
  151. break loop;
  152. } else {
  153. err("Code point not allowed in scheme: " + c);
  154. break loop;
  155. }
  156. break;
  157. case "scheme data":
  158. if ("?" == c) {
  159. this._query = "?";
  160. state = "query";
  161. } else if ("#" == c) {
  162. this._fragment = "#";
  163. state = "fragment";
  164. } else {
  165. if (EOF != c && " " != c && "\n" != c && "\r" != c) {
  166. this._schemeData += percentEscape(c);
  167. }
  168. }
  169. break;
  170. case "no scheme":
  171. if (!base || !isRelativeScheme(base._scheme)) {
  172. err("Missing scheme.");
  173. invalid.call(this);
  174. } else {
  175. state = "relative";
  176. continue;
  177. }
  178. break;
  179. case "relative or authority":
  180. if ("/" == c && "/" == input[cursor + 1]) {
  181. state = "authority ignore slashes";
  182. } else {
  183. err("Expected /, got: " + c);
  184. state = "relative";
  185. continue;
  186. }
  187. break;
  188. case "relative":
  189. this._isRelative = true;
  190. if ("file" != this._scheme) this._scheme = base._scheme;
  191. if (EOF == c) {
  192. this._host = base._host;
  193. this._port = base._port;
  194. this._path = base._path.slice();
  195. this._query = base._query;
  196. this._username = base._username;
  197. this._password = base._password;
  198. break loop;
  199. } else if ("/" == c || "\\" == c) {
  200. if ("\\" == c) err("\\ is an invalid code point.");
  201. state = "relative slash";
  202. } else if ("?" == c) {
  203. this._host = base._host;
  204. this._port = base._port;
  205. this._path = base._path.slice();
  206. this._query = "?";
  207. this._username = base._username;
  208. this._password = base._password;
  209. state = "query";
  210. } else if ("#" == c) {
  211. this._host = base._host;
  212. this._port = base._port;
  213. this._path = base._path.slice();
  214. this._query = base._query;
  215. this._fragment = "#";
  216. this._username = base._username;
  217. this._password = base._password;
  218. state = "fragment";
  219. } else {
  220. var nextC = input[cursor + 1];
  221. var nextNextC = input[cursor + 2];
  222. if ("file" != this._scheme || !ALPHA.test(c) || nextC != ":" && nextC != "|" || EOF != nextNextC && "/" != nextNextC && "\\" != nextNextC && "?" != nextNextC && "#" != nextNextC) {
  223. this._host = base._host;
  224. this._port = base._port;
  225. this._username = base._username;
  226. this._password = base._password;
  227. this._path = base._path.slice();
  228. this._path.pop();
  229. }
  230. state = "relative path";
  231. continue;
  232. }
  233. break;
  234. case "relative slash":
  235. if ("/" == c || "\\" == c) {
  236. if ("\\" == c) {
  237. err("\\ is an invalid code point.");
  238. }
  239. if ("file" == this._scheme) {
  240. state = "file host";
  241. } else {
  242. state = "authority ignore slashes";
  243. }
  244. } else {
  245. if ("file" != this._scheme) {
  246. this._host = base._host;
  247. this._port = base._port;
  248. this._username = base._username;
  249. this._password = base._password;
  250. }
  251. state = "relative path";
  252. continue;
  253. }
  254. break;
  255. case "authority first slash":
  256. if ("/" == c) {
  257. state = "authority second slash";
  258. } else {
  259. err("Expected '/', got: " + c);
  260. state = "authority ignore slashes";
  261. continue;
  262. }
  263. break;
  264. case "authority second slash":
  265. state = "authority ignore slashes";
  266. if ("/" != c) {
  267. err("Expected '/', got: " + c);
  268. continue;
  269. }
  270. break;
  271. case "authority ignore slashes":
  272. if ("/" != c && "\\" != c) {
  273. state = "authority";
  274. continue;
  275. } else {
  276. err("Expected authority, got: " + c);
  277. }
  278. break;
  279. case "authority":
  280. if ("@" == c) {
  281. if (seenAt) {
  282. err("@ already seen.");
  283. buffer += "%40";
  284. }
  285. seenAt = true;
  286. for (var i = 0; i < buffer.length; i++) {
  287. var cp = buffer[i];
  288. if (" " == cp || "\n" == cp || "\r" == cp) {
  289. err("Invalid whitespace in authority.");
  290. continue;
  291. }
  292. if (":" == cp && null === this._password) {
  293. this._password = "";
  294. continue;
  295. }
  296. var tempC = percentEscape(cp);
  297. null !== this._password ? this._password += tempC : this._username += tempC;
  298. }
  299. buffer = "";
  300. } else if (EOF == c || "/" == c || "\\" == c || "?" == c || "#" == c) {
  301. cursor -= buffer.length;
  302. buffer = "";
  303. state = "host";
  304. continue;
  305. } else {
  306. buffer += c;
  307. }
  308. break;
  309. case "file host":
  310. if (EOF == c || "/" == c || "\\" == c || "?" == c || "#" == c) {
  311. if (buffer.length == 2 && ALPHA.test(buffer[0]) && (buffer[1] == ":" || buffer[1] == "|")) {
  312. state = "relative path";
  313. } else if (buffer.length == 0) {
  314. state = "relative path start";
  315. } else {
  316. this._host = IDNAToASCII.call(this, buffer);
  317. buffer = "";
  318. state = "relative path start";
  319. }
  320. continue;
  321. } else if (" " == c || "\n" == c || "\r" == c) {
  322. err("Invalid whitespace in file host.");
  323. } else {
  324. buffer += c;
  325. }
  326. break;
  327. case "host":
  328. case "hostname":
  329. if (":" == c && !seenBracket) {
  330. this._host = IDNAToASCII.call(this, buffer);
  331. buffer = "";
  332. state = "port";
  333. if ("hostname" == stateOverride) {
  334. break loop;
  335. }
  336. } else if (EOF == c || "/" == c || "\\" == c || "?" == c || "#" == c) {
  337. this._host = IDNAToASCII.call(this, buffer);
  338. buffer = "";
  339. state = "relative path start";
  340. if (stateOverride) {
  341. break loop;
  342. }
  343. continue;
  344. } else if (" " != c && "\n" != c && "\r" != c) {
  345. if ("[" == c) {
  346. seenBracket = true;
  347. } else if ("]" == c) {
  348. seenBracket = false;
  349. }
  350. buffer += c;
  351. } else {
  352. err("Invalid code point in host/hostname: " + c);
  353. }
  354. break;
  355. case "port":
  356. if (/[0-9]/.test(c)) {
  357. buffer += c;
  358. } else if (EOF == c || "/" == c || "\\" == c || "?" == c || "#" == c || stateOverride) {
  359. if ("" != buffer) {
  360. var temp = parseInt(buffer, 10);
  361. if (temp != relative[this._scheme]) {
  362. this._port = temp + "";
  363. }
  364. buffer = "";
  365. }
  366. if (stateOverride) {
  367. break loop;
  368. }
  369. state = "relative path start";
  370. continue;
  371. } else if (" " == c || "\n" == c || "\r" == c) {
  372. err("Invalid code point in port: " + c);
  373. } else {
  374. invalid.call(this);
  375. }
  376. break;
  377. case "relative path start":
  378. if ("\\" == c) err("'\\' not allowed in path.");
  379. state = "relative path";
  380. if ("/" != c && "\\" != c) {
  381. continue;
  382. }
  383. break;
  384. case "relative path":
  385. if (EOF == c || "/" == c || "\\" == c || !stateOverride && ("?" == c || "#" == c)) {
  386. if ("\\" == c) {
  387. err("\\ not allowed in relative path.");
  388. }
  389. var tmp;
  390. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  391. buffer = tmp;
  392. }
  393. if (".." == buffer) {
  394. this._path.pop();
  395. if ("/" != c && "\\" != c) {
  396. this._path.push("");
  397. }
  398. } else if ("." == buffer && "/" != c && "\\" != c) {
  399. this._path.push("");
  400. } else if ("." != buffer) {
  401. if ("file" == this._scheme && this._path.length == 0 && buffer.length == 2 && ALPHA.test(buffer[0]) && buffer[1] == "|") {
  402. buffer = buffer[0] + ":";
  403. }
  404. this._path.push(buffer);
  405. }
  406. buffer = "";
  407. if ("?" == c) {
  408. this._query = "?";
  409. state = "query";
  410. } else if ("#" == c) {
  411. this._fragment = "#";
  412. state = "fragment";
  413. }
  414. } else if (" " != c && "\n" != c && "\r" != c) {
  415. buffer += percentEscape(c);
  416. }
  417. break;
  418. case "query":
  419. if (!stateOverride && "#" == c) {
  420. this._fragment = "#";
  421. state = "fragment";
  422. } else if (EOF != c && " " != c && "\n" != c && "\r" != c) {
  423. this._query += percentEscapeQuery(c);
  424. }
  425. break;
  426. case "fragment":
  427. if (EOF != c && " " != c && "\n" != c && "\r" != c) {
  428. this._fragment += c;
  429. }
  430. break;
  431. }
  432. cursor++;
  433. }
  434. }
  435. function clear() {
  436. this._scheme = "";
  437. this._schemeData = "";
  438. this._username = "";
  439. this._password = null;
  440. this._host = "";
  441. this._port = "";
  442. this._path = [];
  443. this._query = "";
  444. this._fragment = "";
  445. this._isInvalid = false;
  446. this._isRelative = false;
  447. }
  448. function jURL(url, base) {
  449. if (base !== undefined && !(base instanceof jURL)) base = new jURL(String(base));
  450. this._url = url;
  451. clear.call(this);
  452. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, "");
  453. parse.call(this, input, null, base);
  454. }
  455. jURL.prototype = {
  456. toString: function() {
  457. return this.href;
  458. },
  459. get href() {
  460. if (this._isInvalid) return this._url;
  461. var authority = "";
  462. if ("" != this._username || null != this._password) {
  463. authority = this._username + (null != this._password ? ":" + this._password : "") + "@";
  464. }
  465. return this.protocol + (this._isRelative ? "//" + authority + this.host : "") + this.pathname + this._query + this._fragment;
  466. },
  467. set href(href) {
  468. clear.call(this);
  469. parse.call(this, href);
  470. },
  471. get protocol() {
  472. return this._scheme + ":";
  473. },
  474. set protocol(protocol) {
  475. if (this._isInvalid) return;
  476. parse.call(this, protocol + ":", "scheme start");
  477. },
  478. get host() {
  479. return this._isInvalid ? "" : this._port ? this._host + ":" + this._port : this._host;
  480. },
  481. set host(host) {
  482. if (this._isInvalid || !this._isRelative) return;
  483. parse.call(this, host, "host");
  484. },
  485. get hostname() {
  486. return this._host;
  487. },
  488. set hostname(hostname) {
  489. if (this._isInvalid || !this._isRelative) return;
  490. parse.call(this, hostname, "hostname");
  491. },
  492. get port() {
  493. return this._port;
  494. },
  495. set port(port) {
  496. if (this._isInvalid || !this._isRelative) return;
  497. parse.call(this, port, "port");
  498. },
  499. get pathname() {
  500. return this._isInvalid ? "" : this._isRelative ? "/" + this._path.join("/") : this._schemeData;
  501. },
  502. set pathname(pathname) {
  503. if (this._isInvalid || !this._isRelative) return;
  504. this._path = [];
  505. parse.call(this, pathname, "relative path start");
  506. },
  507. get search() {
  508. return this._isInvalid || !this._query || "?" == this._query ? "" : this._query;
  509. },
  510. set search(search) {
  511. if (this._isInvalid || !this._isRelative) return;
  512. this._query = "?";
  513. if ("?" == search[0]) search = search.slice(1);
  514. parse.call(this, search, "query");
  515. },
  516. get hash() {
  517. return this._isInvalid || !this._fragment || "#" == this._fragment ? "" : this._fragment;
  518. },
  519. set hash(hash) {
  520. if (this._isInvalid) return;
  521. this._fragment = "#";
  522. if ("#" == hash[0]) hash = hash.slice(1);
  523. parse.call(this, hash, "fragment");
  524. },
  525. get origin() {
  526. var host;
  527. if (this._isInvalid || !this._scheme) {
  528. return "";
  529. }
  530. switch (this._scheme) {
  531. case "data":
  532. case "file":
  533. case "javascript":
  534. case "mailto":
  535. return "null";
  536. }
  537. host = this.host;
  538. if (!host) {
  539. return "";
  540. }
  541. return this._scheme + "://" + host;
  542. }
  543. };
  544. var OriginalURL = scope.URL;
  545. if (OriginalURL) {
  546. jURL.createObjectURL = function(blob) {
  547. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  548. };
  549. jURL.revokeObjectURL = function(url) {
  550. OriginalURL.revokeObjectURL(url);
  551. };
  552. }
  553. scope.URL = jURL;
  554. })(self);
  555. if (typeof WeakMap === "undefined") {
  556. (function() {
  557. var defineProperty = Object.defineProperty;
  558. var counter = Date.now() % 1e9;
  559. var WeakMap = function() {
  560. this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__");
  561. };
  562. WeakMap.prototype = {
  563. set: function(key, value) {
  564. var entry = key[this.name];
  565. if (entry && entry[0] === key) entry[1] = value; else defineProperty(key, this.name, {
  566. value: [ key, value ],
  567. writable: true
  568. });
  569. return this;
  570. },
  571. get: function(key) {
  572. var entry;
  573. return (entry = key[this.name]) && entry[0] === key ? entry[1] : undefined;
  574. },
  575. "delete": function(key) {
  576. var entry = key[this.name];
  577. if (!entry || entry[0] !== key) return false;
  578. entry[0] = entry[1] = undefined;
  579. return true;
  580. },
  581. has: function(key) {
  582. var entry = key[this.name];
  583. if (!entry) return false;
  584. return entry[0] === key;
  585. }
  586. };
  587. window.WeakMap = WeakMap;
  588. })();
  589. }
  590. (function(global) {
  591. if (global.JsMutationObserver) {
  592. return;
  593. }
  594. var registrationsTable = new WeakMap();
  595. var setImmediate;
  596. if (/Trident|Edge/.test(navigator.userAgent)) {
  597. setImmediate = setTimeout;
  598. } else if (window.setImmediate) {
  599. setImmediate = window.setImmediate;
  600. } else {
  601. var setImmediateQueue = [];
  602. var sentinel = String(Math.random());
  603. window.addEventListener("message", function(e) {
  604. if (e.data === sentinel) {
  605. var queue = setImmediateQueue;
  606. setImmediateQueue = [];
  607. queue.forEach(function(func) {
  608. func();
  609. });
  610. }
  611. });
  612. setImmediate = function(func) {
  613. setImmediateQueue.push(func);
  614. window.postMessage(sentinel, "*");
  615. };
  616. }
  617. var isScheduled = false;
  618. var scheduledObservers = [];
  619. function scheduleCallback(observer) {
  620. scheduledObservers.push(observer);
  621. if (!isScheduled) {
  622. isScheduled = true;
  623. setImmediate(dispatchCallbacks);
  624. }
  625. }
  626. function wrapIfNeeded(node) {
  627. return window.ShadowDOMPolyfill && window.ShadowDOMPolyfill.wrapIfNeeded(node) || node;
  628. }
  629. function dispatchCallbacks() {
  630. isScheduled = false;
  631. var observers = scheduledObservers;
  632. scheduledObservers = [];
  633. observers.sort(function(o1, o2) {
  634. return o1.uid_ - o2.uid_;
  635. });
  636. var anyNonEmpty = false;
  637. observers.forEach(function(observer) {
  638. var queue = observer.takeRecords();
  639. removeTransientObserversFor(observer);
  640. if (queue.length) {
  641. observer.callback_(queue, observer);
  642. anyNonEmpty = true;
  643. }
  644. });
  645. if (anyNonEmpty) dispatchCallbacks();
  646. }
  647. function removeTransientObserversFor(observer) {
  648. observer.nodes_.forEach(function(node) {
  649. var registrations = registrationsTable.get(node);
  650. if (!registrations) return;
  651. registrations.forEach(function(registration) {
  652. if (registration.observer === observer) registration.removeTransientObservers();
  653. });
  654. });
  655. }
  656. function forEachAncestorAndObserverEnqueueRecord(target, callback) {
  657. for (var node = target; node; node = node.parentNode) {
  658. var registrations = registrationsTable.get(node);
  659. if (registrations) {
  660. for (var j = 0; j < registrations.length; j++) {
  661. var registration = registrations[j];
  662. var options = registration.options;
  663. if (node !== target && !options.subtree) continue;
  664. var record = callback(options);
  665. if (record) registration.enqueue(record);
  666. }
  667. }
  668. }
  669. }
  670. var uidCounter = 0;
  671. function JsMutationObserver(callback) {
  672. this.callback_ = callback;
  673. this.nodes_ = [];
  674. this.records_ = [];
  675. this.uid_ = ++uidCounter;
  676. }
  677. JsMutationObserver.prototype = {
  678. observe: function(target, options) {
  679. target = wrapIfNeeded(target);
  680. if (!options.childList && !options.attributes && !options.characterData || options.attributeOldValue && !options.attributes || options.attributeFilter && options.attributeFilter.length && !options.attributes || options.characterDataOldValue && !options.characterData) {
  681. throw new SyntaxError();
  682. }
  683. var registrations = registrationsTable.get(target);
  684. if (!registrations) registrationsTable.set(target, registrations = []);
  685. var registration;
  686. for (var i = 0; i < registrations.length; i++) {
  687. if (registrations[i].observer === this) {
  688. registration = registrations[i];
  689. registration.removeListeners();
  690. registration.options = options;
  691. break;
  692. }
  693. }
  694. if (!registration) {
  695. registration = new Registration(this, target, options);
  696. registrations.push(registration);
  697. this.nodes_.push(target);
  698. }
  699. registration.addListeners();
  700. },
  701. disconnect: function() {
  702. this.nodes_.forEach(function(node) {
  703. var registrations = registrationsTable.get(node);
  704. for (var i = 0; i < registrations.length; i++) {
  705. var registration = registrations[i];
  706. if (registration.observer === this) {
  707. registration.removeListeners();
  708. registrations.splice(i, 1);
  709. break;
  710. }
  711. }
  712. }, this);
  713. this.records_ = [];
  714. },
  715. takeRecords: function() {
  716. var copyOfRecords = this.records_;
  717. this.records_ = [];
  718. return copyOfRecords;
  719. }
  720. };
  721. function MutationRecord(type, target) {
  722. this.type = type;
  723. this.target = target;
  724. this.addedNodes = [];
  725. this.removedNodes = [];
  726. this.previousSibling = null;
  727. this.nextSibling = null;
  728. this.attributeName = null;
  729. this.attributeNamespace = null;
  730. this.oldValue = null;
  731. }
  732. function copyMutationRecord(original) {
  733. var record = new MutationRecord(original.type, original.target);
  734. record.addedNodes = original.addedNodes.slice();
  735. record.removedNodes = original.removedNodes.slice();
  736. record.previousSibling = original.previousSibling;
  737. record.nextSibling = original.nextSibling;
  738. record.attributeName = original.attributeName;
  739. record.attributeNamespace = original.attributeNamespace;
  740. record.oldValue = original.oldValue;
  741. return record;
  742. }
  743. var currentRecord, recordWithOldValue;
  744. function getRecord(type, target) {
  745. return currentRecord = new MutationRecord(type, target);
  746. }
  747. function getRecordWithOldValue(oldValue) {
  748. if (recordWithOldValue) return recordWithOldValue;
  749. recordWithOldValue = copyMutationRecord(currentRecord);
  750. recordWithOldValue.oldValue = oldValue;
  751. return recordWithOldValue;
  752. }
  753. function clearRecords() {
  754. currentRecord = recordWithOldValue = undefined;
  755. }
  756. function recordRepresentsCurrentMutation(record) {
  757. return record === recordWithOldValue || record === currentRecord;
  758. }
  759. function selectRecord(lastRecord, newRecord) {
  760. if (lastRecord === newRecord) return lastRecord;
  761. if (recordWithOldValue && recordRepresentsCurrentMutation(lastRecord)) return recordWithOldValue;
  762. return null;
  763. }
  764. function Registration(observer, target, options) {
  765. this.observer = observer;
  766. this.target = target;
  767. this.options = options;
  768. this.transientObservedNodes = [];
  769. }
  770. Registration.prototype = {
  771. enqueue: function(record) {
  772. var records = this.observer.records_;
  773. var length = records.length;
  774. if (records.length > 0) {
  775. var lastRecord = records[length - 1];
  776. var recordToReplaceLast = selectRecord(lastRecord, record);
  777. if (recordToReplaceLast) {
  778. records[length - 1] = recordToReplaceLast;
  779. return;
  780. }
  781. } else {
  782. scheduleCallback(this.observer);
  783. }
  784. records[length] = record;
  785. },
  786. addListeners: function() {
  787. this.addListeners_(this.target);
  788. },
  789. addListeners_: function(node) {
  790. var options = this.options;
  791. if (options.attributes) node.addEventListener("DOMAttrModified", this, true);
  792. if (options.characterData) node.addEventListener("DOMCharacterDataModified", this, true);
  793. if (options.childList) node.addEventListener("DOMNodeInserted", this, true);
  794. if (options.childList || options.subtree) node.addEventListener("DOMNodeRemoved", this, true);
  795. },
  796. removeListeners: function() {
  797. this.removeListeners_(this.target);
  798. },
  799. removeListeners_: function(node) {
  800. var options = this.options;
  801. if (options.attributes) node.removeEventListener("DOMAttrModified", this, true);
  802. if (options.characterData) node.removeEventListener("DOMCharacterDataModified", this, true);
  803. if (options.childList) node.removeEventListener("DOMNodeInserted", this, true);
  804. if (options.childList || options.subtree) node.removeEventListener("DOMNodeRemoved", this, true);
  805. },
  806. addTransientObserver: function(node) {
  807. if (node === this.target) return;
  808. this.addListeners_(node);
  809. this.transientObservedNodes.push(node);
  810. var registrations = registrationsTable.get(node);
  811. if (!registrations) registrationsTable.set(node, registrations = []);
  812. registrations.push(this);
  813. },
  814. removeTransientObservers: function() {
  815. var transientObservedNodes = this.transientObservedNodes;
  816. this.transientObservedNodes = [];
  817. transientObservedNodes.forEach(function(node) {
  818. this.removeListeners_(node);
  819. var registrations = registrationsTable.get(node);
  820. for (var i = 0; i < registrations.length; i++) {
  821. if (registrations[i] === this) {
  822. registrations.splice(i, 1);
  823. break;
  824. }
  825. }
  826. }, this);
  827. },
  828. handleEvent: function(e) {
  829. e.stopImmediatePropagation();
  830. switch (e.type) {
  831. case "DOMAttrModified":
  832. var name = e.attrName;
  833. var namespace = e.relatedNode.namespaceURI;
  834. var target = e.target;
  835. var record = new getRecord("attributes", target);
  836. record.attributeName = name;
  837. record.attributeNamespace = namespace;
  838. var oldValue = e.attrChange === MutationEvent.ADDITION ? null : e.prevValue;
  839. forEachAncestorAndObserverEnqueueRecord(target, function(options) {
  840. if (!options.attributes) return;
  841. if (options.attributeFilter && options.attributeFilter.length && options.attributeFilter.indexOf(name) === -1 && options.attributeFilter.indexOf(namespace) === -1) {
  842. return;
  843. }
  844. if (options.attributeOldValue) return getRecordWithOldValue(oldValue);
  845. return record;
  846. });
  847. break;
  848. case "DOMCharacterDataModified":
  849. var target = e.target;
  850. var record = getRecord("characterData", target);
  851. var oldValue = e.prevValue;
  852. forEachAncestorAndObserverEnqueueRecord(target, function(options) {
  853. if (!options.characterData) return;
  854. if (options.characterDataOldValue) return getRecordWithOldValue(oldValue);
  855. return record;
  856. });
  857. break;
  858. case "DOMNodeRemoved":
  859. this.addTransientObserver(e.target);
  860. case "DOMNodeInserted":
  861. var changedNode = e.target;
  862. var addedNodes, removedNodes;
  863. if (e.type === "DOMNodeInserted") {
  864. addedNodes = [ changedNode ];
  865. removedNodes = [];
  866. } else {
  867. addedNodes = [];
  868. removedNodes = [ changedNode ];
  869. }
  870. var previousSibling = changedNode.previousSibling;
  871. var nextSibling = changedNode.nextSibling;
  872. var record = getRecord("childList", e.target.parentNode);
  873. record.addedNodes = addedNodes;
  874. record.removedNodes = removedNodes;
  875. record.previousSibling = previousSibling;
  876. record.nextSibling = nextSibling;
  877. forEachAncestorAndObserverEnqueueRecord(e.relatedNode, function(options) {
  878. if (!options.childList) return;
  879. return record;
  880. });
  881. }
  882. clearRecords();
  883. }
  884. };
  885. global.JsMutationObserver = JsMutationObserver;
  886. if (!global.MutationObserver) {
  887. global.MutationObserver = JsMutationObserver;
  888. JsMutationObserver._isPolyfilled = true;
  889. }
  890. })(self);
  891. if (typeof HTMLTemplateElement === "undefined") {
  892. (function() {
  893. var TEMPLATE_TAG = "template";
  894. var contentDoc = document.implementation.createHTMLDocument("template");
  895. var canDecorate = true;
  896. HTMLTemplateElement = function() {};
  897. HTMLTemplateElement.prototype = Object.create(HTMLElement.prototype);
  898. HTMLTemplateElement.decorate = function(template) {
  899. if (template.content) {
  900. return;
  901. }
  902. template.content = contentDoc.createDocumentFragment();
  903. var child;
  904. while (child = template.firstChild) {
  905. template.content.appendChild(child);
  906. }
  907. if (canDecorate) {
  908. try {
  909. Object.defineProperty(template, "innerHTML", {
  910. get: function() {
  911. var o = "";
  912. for (var e = this.content.firstChild; e; e = e.nextSibling) {
  913. o += e.outerHTML || escapeData(e.data);
  914. }
  915. return o;
  916. },
  917. set: function(text) {
  918. contentDoc.body.innerHTML = text;
  919. HTMLTemplateElement.bootstrap(contentDoc);
  920. while (this.content.firstChild) {
  921. this.content.removeChild(this.content.firstChild);
  922. }
  923. while (contentDoc.body.firstChild) {
  924. this.content.appendChild(contentDoc.body.firstChild);
  925. }
  926. },
  927. configurable: true
  928. });
  929. } catch (err) {
  930. canDecorate = false;
  931. }
  932. }
  933. HTMLTemplateElement.bootstrap(template.content);
  934. };
  935. HTMLTemplateElement.bootstrap = function(doc) {
  936. var templates = doc.querySelectorAll(TEMPLATE_TAG);
  937. for (var i = 0, l = templates.length, t; i < l && (t = templates[i]); i++) {
  938. HTMLTemplateElement.decorate(t);
  939. }
  940. };
  941. document.addEventListener("DOMContentLoaded", function() {
  942. HTMLTemplateElement.bootstrap(document);
  943. });
  944. var createElement = document.createElement;
  945. document.createElement = function() {
  946. "use strict";
  947. var el = createElement.apply(document, arguments);
  948. if (el.localName == "template") {
  949. HTMLTemplateElement.decorate(el);
  950. }
  951. return el;
  952. };
  953. var escapeDataRegExp = /[&\u00A0<>]/g;
  954. function escapeReplace(c) {
  955. switch (c) {
  956. case "&":
  957. return "&amp;";
  958. case "<":
  959. return "&lt;";
  960. case ">":
  961. return "&gt;";
  962. case " ":
  963. return "&nbsp;";
  964. }
  965. }
  966. function escapeData(s) {
  967. return s.replace(escapeDataRegExp, escapeReplace);
  968. }
  969. })();
  970. }
  971. (function(scope) {
  972. "use strict";
  973. if (!window.performance) {
  974. var start = Date.now();
  975. window.performance = {
  976. now: function() {
  977. return Date.now() - start;
  978. }
  979. };
  980. }
  981. if (!window.requestAnimationFrame) {
  982. window.requestAnimationFrame = function() {
  983. var nativeRaf = window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame;
  984. return nativeRaf ? function(callback) {
  985. return nativeRaf(function() {
  986. callback(performance.now());
  987. });
  988. } : function(callback) {
  989. return window.setTimeout(callback, 1e3 / 60);
  990. };
  991. }();
  992. }
  993. if (!window.cancelAnimationFrame) {
  994. window.cancelAnimationFrame = function() {
  995. return window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || function(id) {
  996. clearTimeout(id);
  997. };
  998. }();
  999. }
  1000. var workingDefaultPrevented = function() {
  1001. var e = document.createEvent("Event");
  1002. e.initEvent("foo", true, true);
  1003. e.preventDefault();
  1004. return e.defaultPrevented;
  1005. }();
  1006. if (!workingDefaultPrevented) {
  1007. var origPreventDefault = Event.prototype.preventDefault;
  1008. Event.prototype.preventDefault = function() {
  1009. if (!this.cancelable) {
  1010. return;
  1011. }
  1012. origPreventDefault.call(this);
  1013. Object.defineProperty(this, "defaultPrevented", {
  1014. get: function() {
  1015. return true;
  1016. },
  1017. configurable: true
  1018. });
  1019. };
  1020. }
  1021. var isIE = /Trident/.test(navigator.userAgent);
  1022. if (!window.CustomEvent || isIE && typeof window.CustomEvent !== "function") {
  1023. window.CustomEvent = function(inType, params) {
  1024. params = params || {};
  1025. var e = document.createEvent("CustomEvent");
  1026. e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable), params.detail);
  1027. return e;
  1028. };
  1029. window.CustomEvent.prototype = window.Event.prototype;
  1030. }
  1031. if (!window.Event || isIE && typeof window.Event !== "function") {
  1032. var origEvent = window.Event;
  1033. window.Event = function(inType, params) {
  1034. params = params || {};
  1035. var e = document.createEvent("Event");
  1036. e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable));
  1037. return e;
  1038. };
  1039. window.Event.prototype = origEvent.prototype;
  1040. }
  1041. })(window.WebComponents);
  1042. window.HTMLImports = window.HTMLImports || {
  1043. flags: {}
  1044. };
  1045. (function(scope) {
  1046. var IMPORT_LINK_TYPE = "import";
  1047. var useNative = Boolean(IMPORT_LINK_TYPE in document.createElement("link"));
  1048. var hasShadowDOMPolyfill = Boolean(window.ShadowDOMPolyfill);
  1049. var wrap = function(node) {
  1050. return hasShadowDOMPolyfill ? window.ShadowDOMPolyfill.wrapIfNeeded(node) : node;
  1051. };
  1052. var rootDocument = wrap(document);
  1053. var currentScriptDescriptor = {
  1054. get: function() {
  1055. var script = window.HTMLImports.currentScript || document.currentScript || (document.readyState !== "complete" ? document.scripts[document.scripts.length - 1] : null);
  1056. return wrap(script);
  1057. },
  1058. configurable: true
  1059. };
  1060. Object.defineProperty(document, "_currentScript", currentScriptDescriptor);
  1061. Object.defineProperty(rootDocument, "_currentScript", currentScriptDescriptor);
  1062. var isIE = /Trident/.test(navigator.userAgent);
  1063. function whenReady(callback, doc) {
  1064. doc = doc || rootDocument;
  1065. whenDocumentReady(function() {
  1066. watchImportsLoad(callback, doc);
  1067. }, doc);
  1068. }
  1069. var requiredReadyState = isIE ? "complete" : "interactive";
  1070. var READY_EVENT = "readystatechange";
  1071. function isDocumentReady(doc) {
  1072. return doc.readyState === "complete" || doc.readyState === requiredReadyState;
  1073. }
  1074. function whenDocumentReady(callback, doc) {
  1075. if (!isDocumentReady(doc)) {
  1076. var checkReady = function() {
  1077. if (doc.readyState === "complete" || doc.readyState === requiredReadyState) {
  1078. doc.removeEventListener(READY_EVENT, checkReady);
  1079. whenDocumentReady(callback, doc);
  1080. }
  1081. };
  1082. doc.addEventListener(READY_EVENT, checkReady);
  1083. } else if (callback) {
  1084. callback();
  1085. }
  1086. }
  1087. function markTargetLoaded(event) {
  1088. event.target.__loaded = true;
  1089. }
  1090. function watchImportsLoad(callback, doc) {
  1091. var imports = doc.querySelectorAll("link[rel=import]");
  1092. var parsedCount = 0, importCount = imports.length, newImports = [], errorImports = [];
  1093. function checkDone() {
  1094. if (parsedCount == importCount && callback) {
  1095. callback({
  1096. allImports: imports,
  1097. loadedImports: newImports,
  1098. errorImports: errorImports
  1099. });
  1100. }
  1101. }
  1102. function loadedImport(e) {
  1103. markTargetLoaded(e);
  1104. newImports.push(this);
  1105. parsedCount++;
  1106. checkDone();
  1107. }
  1108. function errorLoadingImport(e) {
  1109. errorImports.push(this);
  1110. parsedCount++;
  1111. checkDone();
  1112. }
  1113. if (importCount) {
  1114. for (var i = 0, imp; i < importCount && (imp = imports[i]); i++) {
  1115. if (isImportLoaded(imp)) {
  1116. newImports.push(this);
  1117. parsedCount++;
  1118. checkDone();
  1119. } else {
  1120. imp.addEventListener("load", loadedImport);
  1121. imp.addEventListener("error", errorLoadingImport);
  1122. }
  1123. }
  1124. } else {
  1125. checkDone();
  1126. }
  1127. }
  1128. function isImportLoaded(link) {
  1129. return useNative ? link.__loaded || link.import && link.import.readyState !== "loading" : link.__importParsed;
  1130. }
  1131. if (useNative) {
  1132. new MutationObserver(function(mxns) {
  1133. for (var i = 0, l = mxns.length, m; i < l && (m = mxns[i]); i++) {
  1134. if (m.addedNodes) {
  1135. handleImports(m.addedNodes);
  1136. }
  1137. }
  1138. }).observe(document.head, {
  1139. childList: true
  1140. });
  1141. function handleImports(nodes) {
  1142. for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
  1143. if (isImport(n)) {
  1144. handleImport(n);
  1145. }
  1146. }
  1147. }
  1148. function isImport(element) {
  1149. return element.localName === "link" && element.rel === "import";
  1150. }
  1151. function handleImport(element) {
  1152. var loaded = element.import;
  1153. if (loaded) {
  1154. markTargetLoaded({
  1155. target: element
  1156. });
  1157. } else {
  1158. element.addEventListener("load", markTargetLoaded);
  1159. element.addEventListener("error", markTargetLoaded);
  1160. }
  1161. }
  1162. (function() {
  1163. if (document.readyState === "loading") {
  1164. var imports = document.querySelectorAll("link[rel=import]");
  1165. for (var i = 0, l = imports.length, imp; i < l && (imp = imports[i]); i++) {
  1166. handleImport(imp);
  1167. }
  1168. }
  1169. })();
  1170. }
  1171. whenReady(function(detail) {
  1172. window.HTMLImports.ready = true;
  1173. window.HTMLImports.readyTime = new Date().getTime();
  1174. var evt = rootDocument.createEvent("CustomEvent");
  1175. evt.initCustomEvent("HTMLImportsLoaded", true, true, detail);
  1176. rootDocument.dispatchEvent(evt);
  1177. });
  1178. scope.IMPORT_LINK_TYPE = IMPORT_LINK_TYPE;
  1179. scope.useNative = useNative;
  1180. scope.rootDocument = rootDocument;
  1181. scope.whenReady = whenReady;
  1182. scope.isIE = isIE;
  1183. })(window.HTMLImports);
  1184. (function(scope) {
  1185. var modules = [];
  1186. var addModule = function(module) {
  1187. modules.push(module);
  1188. };
  1189. var initializeModules = function() {
  1190. modules.forEach(function(module) {
  1191. module(scope);
  1192. });
  1193. };
  1194. scope.addModule = addModule;
  1195. scope.initializeModules = initializeModules;
  1196. })(window.HTMLImports);
  1197. window.HTMLImports.addModule(function(scope) {
  1198. var CSS_URL_REGEXP = /(url\()([^)]*)(\))/g;
  1199. var CSS_IMPORT_REGEXP = /(@import[\s]+(?!url\())([^;]*)(;)/g;
  1200. var path = {
  1201. resolveUrlsInStyle: function(style, linkUrl) {
  1202. var doc = style.ownerDocument;
  1203. var resolver = doc.createElement("a");
  1204. style.textContent = this.resolveUrlsInCssText(style.textContent, linkUrl, resolver);
  1205. return style;
  1206. },
  1207. resolveUrlsInCssText: function(cssText, linkUrl, urlObj) {
  1208. var r = this.replaceUrls(cssText, urlObj, linkUrl, CSS_URL_REGEXP);
  1209. r = this.replaceUrls(r, urlObj, linkUrl, CSS_IMPORT_REGEXP);
  1210. return r;
  1211. },
  1212. replaceUrls: function(text, urlObj, linkUrl, regexp) {
  1213. return text.replace(regexp, function(m, pre, url, post) {
  1214. var urlPath = url.replace(/["']/g, "");
  1215. if (linkUrl) {
  1216. urlPath = new URL(urlPath, linkUrl).href;
  1217. }
  1218. urlObj.href = urlPath;
  1219. urlPath = urlObj.href;
  1220. return pre + "'" + urlPath + "'" + post;
  1221. });
  1222. }
  1223. };
  1224. scope.path = path;
  1225. });
  1226. window.HTMLImports.addModule(function(scope) {
  1227. var xhr = {
  1228. async: true,
  1229. ok: function(request) {
  1230. return request.status >= 200 && request.status < 300 || request.status === 304 || request.status === 0;
  1231. },
  1232. load: function(url, next, nextContext) {
  1233. var request = new XMLHttpRequest();
  1234. if (scope.flags.debug || scope.flags.bust) {
  1235. url += "?" + Math.random();
  1236. }
  1237. request.open("GET", url, xhr.async);
  1238. request.addEventListener("readystatechange", function(e) {
  1239. if (request.readyState === 4) {
  1240. var redirectedUrl = null;
  1241. try {
  1242. var locationHeader = request.getResponseHeader("Location");
  1243. if (locationHeader) {
  1244. redirectedUrl = locationHeader.substr(0, 1) === "/" ? location.origin + locationHeader : locationHeader;
  1245. }
  1246. } catch (e) {
  1247. console.error(e.message);
  1248. }
  1249. next.call(nextContext, !xhr.ok(request) && request, request.response || request.responseText, redirectedUrl);
  1250. }
  1251. });
  1252. request.send();
  1253. return request;
  1254. },
  1255. loadDocument: function(url, next, nextContext) {
  1256. this.load(url, next, nextContext).responseType = "document";
  1257. }
  1258. };
  1259. scope.xhr = xhr;
  1260. });
  1261. window.HTMLImports.addModule(function(scope) {
  1262. var xhr = scope.xhr;
  1263. var flags = scope.flags;
  1264. var Loader = function(onLoad, onComplete) {
  1265. this.cache = {};
  1266. this.onload = onLoad;
  1267. this.oncomplete = onComplete;
  1268. this.inflight = 0;
  1269. this.pending = {};
  1270. };
  1271. Loader.prototype = {
  1272. addNodes: function(nodes) {
  1273. this.inflight += nodes.length;
  1274. for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
  1275. this.require(n);
  1276. }
  1277. this.checkDone();
  1278. },
  1279. addNode: function(node) {
  1280. this.inflight++;
  1281. this.require(node);
  1282. this.checkDone();
  1283. },
  1284. require: function(elt) {
  1285. var url = elt.src || elt.href;
  1286. elt.__nodeUrl = url;
  1287. if (!this.dedupe(url, elt)) {
  1288. this.fetch(url, elt);
  1289. }
  1290. },
  1291. dedupe: function(url, elt) {
  1292. if (this.pending[url]) {
  1293. this.pending[url].push(elt);
  1294. return true;
  1295. }
  1296. var resource;
  1297. if (this.cache[url]) {
  1298. this.onload(url, elt, this.cache[url]);
  1299. this.tail();
  1300. return true;
  1301. }
  1302. this.pending[url] = [ elt ];
  1303. return false;
  1304. },
  1305. fetch: function(url, elt) {
  1306. flags.load && console.log("fetch", url, elt);
  1307. if (!url) {
  1308. setTimeout(function() {
  1309. this.receive(url, elt, {
  1310. error: "href must be specified"
  1311. }, null);
  1312. }.bind(this), 0);
  1313. } else if (url.match(/^data:/)) {
  1314. var pieces = url.split(",");
  1315. var header = pieces[0];
  1316. var body = pieces[1];
  1317. if (header.indexOf(";base64") > -1) {
  1318. body = atob(body);
  1319. } else {
  1320. body = decodeURIComponent(body);
  1321. }
  1322. setTimeout(function() {
  1323. this.receive(url, elt, null, body);
  1324. }.bind(this), 0);
  1325. } else {
  1326. var receiveXhr = function(err, resource, redirectedUrl) {
  1327. this.receive(url, elt, err, resource, redirectedUrl);
  1328. }.bind(this);
  1329. xhr.load(url, receiveXhr);
  1330. }
  1331. },
  1332. receive: function(url, elt, err, resource, redirectedUrl) {
  1333. this.cache[url] = resource;
  1334. var $p = this.pending[url];
  1335. for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) {
  1336. this.onload(url, p, resource, err, redirectedUrl);
  1337. this.tail();
  1338. }
  1339. this.pending[url] = null;
  1340. },
  1341. tail: function() {
  1342. --this.inflight;
  1343. this.checkDone();
  1344. },
  1345. checkDone: function() {
  1346. if (!this.inflight) {
  1347. this.oncomplete();
  1348. }
  1349. }
  1350. };
  1351. scope.Loader = Loader;
  1352. });
  1353. window.HTMLImports.addModule(function(scope) {
  1354. var Observer = function(addCallback) {
  1355. this.addCallback = addCallback;
  1356. this.mo = new MutationObserver(this.handler.bind(this));
  1357. };
  1358. Observer.prototype = {
  1359. handler: function(mutations) {
  1360. for (var i = 0, l = mutations.length, m; i < l && (m = mutations[i]); i++) {
  1361. if (m.type === "childList" && m.addedNodes.length) {
  1362. this.addedNodes(m.addedNodes);
  1363. }
  1364. }
  1365. },
  1366. addedNodes: function(nodes) {
  1367. if (this.addCallback) {
  1368. this.addCallback(nodes);
  1369. }
  1370. for (var i = 0, l = nodes.length, n, loading; i < l && (n = nodes[i]); i++) {
  1371. if (n.children && n.children.length) {
  1372. this.addedNodes(n.children);
  1373. }
  1374. }
  1375. },
  1376. observe: function(root) {
  1377. this.mo.observe(root, {
  1378. childList: true,
  1379. subtree: true
  1380. });
  1381. }
  1382. };
  1383. scope.Observer = Observer;
  1384. });
  1385. window.HTMLImports.addModule(function(scope) {
  1386. var path = scope.path;
  1387. var rootDocument = scope.rootDocument;
  1388. var flags = scope.flags;
  1389. var isIE = scope.isIE;
  1390. var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE;
  1391. var IMPORT_SELECTOR = "link[rel=" + IMPORT_LINK_TYPE + "]";
  1392. var importParser = {
  1393. documentSelectors: IMPORT_SELECTOR,
  1394. importsSelectors: [ IMPORT_SELECTOR, "link[rel=stylesheet]:not([type])", "style:not([type])", "script:not([type])", 'script[type="application/javascript"]', 'script[type="text/javascript"]' ].join(","),
  1395. map: {
  1396. link: "parseLink",
  1397. script: "parseScript",
  1398. style: "parseStyle"
  1399. },
  1400. dynamicElements: [],
  1401. parseNext: function() {
  1402. var next = this.nextToParse();
  1403. if (next) {
  1404. this.parse(next);
  1405. }
  1406. },
  1407. parse: function(elt) {
  1408. if (this.isParsed(elt)) {
  1409. flags.parse && console.log("[%s] is already parsed", elt.localName);
  1410. return;
  1411. }
  1412. var fn = this[this.map[elt.localName]];
  1413. if (fn) {
  1414. this.markParsing(elt);
  1415. fn.call(this, elt);
  1416. }
  1417. },
  1418. parseDynamic: function(elt, quiet) {
  1419. this.dynamicElements.push(elt);
  1420. if (!quiet) {
  1421. this.parseNext();
  1422. }
  1423. },
  1424. markParsing: function(elt) {
  1425. flags.parse && console.log("parsing", elt);
  1426. this.parsingElement = elt;
  1427. },
  1428. markParsingComplete: function(elt) {
  1429. elt.__importParsed = true;
  1430. this.markDynamicParsingComplete(elt);
  1431. if (elt.__importElement) {
  1432. elt.__importElement.__importParsed = true;
  1433. this.markDynamicParsingComplete(elt.__importElement);
  1434. }
  1435. this.parsingElement = null;
  1436. flags.parse && console.log("completed", elt);
  1437. },
  1438. markDynamicParsingComplete: function(elt) {
  1439. var i = this.dynamicElements.indexOf(elt);
  1440. if (i >= 0) {
  1441. this.dynamicElements.splice(i, 1);
  1442. }
  1443. },
  1444. parseImport: function(elt) {
  1445. elt.import = elt.__doc;
  1446. if (window.HTMLImports.__importsParsingHook) {
  1447. window.HTMLImports.__importsParsingHook(elt);
  1448. }
  1449. if (elt.import) {
  1450. elt.import.__importParsed = true;
  1451. }
  1452. this.markParsingComplete(elt);
  1453. if (elt.__resource && !elt.__error) {
  1454. elt.dispatchEvent(new CustomEvent("load", {
  1455. bubbles: false
  1456. }));
  1457. } else {
  1458. elt.dispatchEvent(new CustomEvent("error", {
  1459. bubbles: false
  1460. }));
  1461. }
  1462. if (elt.__pending) {
  1463. var fn;
  1464. while (elt.__pending.length) {
  1465. fn = elt.__pending.shift();
  1466. if (fn) {
  1467. fn({
  1468. target: elt
  1469. });
  1470. }
  1471. }
  1472. }
  1473. this.parseNext();
  1474. },
  1475. parseLink: function(linkElt) {
  1476. if (nodeIsImport(linkElt)) {
  1477. this.parseImport(linkElt);
  1478. } else {
  1479. linkElt.href = linkElt.href;
  1480. this.parseGeneric(linkElt);
  1481. }
  1482. },
  1483. parseStyle: function(elt) {
  1484. var src = elt;
  1485. elt = cloneStyle(elt);
  1486. src.__appliedElement = elt;
  1487. elt.__importElement = src;
  1488. this.parseGeneric(elt);
  1489. },
  1490. parseGeneric: function(elt) {
  1491. this.trackElement(elt);
  1492. this.addElementToDocument(elt);
  1493. },
  1494. rootImportForElement: function(elt) {
  1495. var n = elt;
  1496. while (n.ownerDocument.__importLink) {
  1497. n = n.ownerDocument.__importLink;
  1498. }
  1499. return n;
  1500. },
  1501. addElementToDocument: function(elt) {
  1502. var port = this.rootImportForElement(elt.__importElement || elt);
  1503. port.parentNode.insertBefore(elt, port);
  1504. },
  1505. trackElement: function(elt, callback) {
  1506. var self = this;
  1507. var done = function(e) {
  1508. elt.removeEventListener("load", done);
  1509. elt.removeEventListener("error", done);
  1510. if (callback) {
  1511. callback(e);
  1512. }
  1513. self.markParsingComplete(elt);
  1514. self.parseNext();
  1515. };
  1516. elt.addEventListener("load", done);
  1517. elt.addEventListener("error", done);
  1518. if (isIE && elt.localName === "style") {
  1519. var fakeLoad = false;
  1520. if (elt.textContent.indexOf("@import") == -1) {
  1521. fakeLoad = true;
  1522. } else if (elt.sheet) {
  1523. fakeLoad = true;
  1524. var csr = elt.sheet.cssRules;
  1525. var len = csr ? csr.length : 0;
  1526. for (var i = 0, r; i < len && (r = csr[i]); i++) {
  1527. if (r.type === CSSRule.IMPORT_RULE) {
  1528. fakeLoad = fakeLoad && Boolean(r.styleSheet);
  1529. }
  1530. }
  1531. }
  1532. if (fakeLoad) {
  1533. setTimeout(function() {
  1534. elt.dispatchEvent(new CustomEvent("load", {
  1535. bubbles: false
  1536. }));
  1537. });
  1538. }
  1539. }
  1540. },
  1541. parseScript: function(scriptElt) {
  1542. var script = document.createElement("script");
  1543. script.__importElement = scriptElt;
  1544. script.src = scriptElt.src ? scriptElt.src : generateScriptDataUrl(scriptElt);
  1545. scope.current