OLD | NEW |
(Empty) | |
| 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://polyme
r.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/CON
TRIBUTORS.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/PA
TENTS.txt |
| 9 */ |
| 10 // @version 0.7.21 |
| 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 |
| 52 (function(scope) { |
| 53 "use strict"; |
| 54 var hasWorkingUrl = false; |
| 55 if (!scope.forceJURL) { |
| 56 try { |
| 57 var u = new URL("b", "http://a"); |
| 58 u.pathname = "c%20d"; |
| 59 hasWorkingUrl = u.href === "http://a/c%20d"; |
| 60 } catch (e) {} |
| 61 } |
| 62 if (hasWorkingUrl) return; |
| 63 var relative = Object.create(null); |
| 64 relative["ftp"] = 21; |
| 65 relative["file"] = 0; |
| 66 relative["gopher"] = 70; |
| 67 relative["http"] = 80; |
| 68 relative["https"] = 443; |
| 69 relative["ws"] = 80; |
| 70 relative["wss"] = 443; |
| 71 var relativePathDotMapping = Object.create(null); |
| 72 relativePathDotMapping["%2e"] = "."; |
| 73 relativePathDotMapping[".%2e"] = ".."; |
| 74 relativePathDotMapping["%2e."] = ".."; |
| 75 relativePathDotMapping["%2e%2e"] = ".."; |
| 76 function isRelativeScheme(scheme) { |
| 77 return relative[scheme] !== undefined; |
| 78 } |
| 79 function invalid() { |
| 80 clear.call(this); |
| 81 this._isInvalid = true; |
| 82 } |
| 83 function IDNAToASCII(h) { |
| 84 if ("" == h) { |
| 85 invalid.call(this); |
| 86 } |
| 87 return h.toLowerCase(); |
| 88 } |
| 89 function percentEscape(c) { |
| 90 var unicode = c.charCodeAt(0); |
| 91 if (unicode > 32 && unicode < 127 && [ 34, 35, 60, 62, 63, 96 ].indexOf(unic
ode) == -1) { |
| 92 return c; |
| 93 } |
| 94 return encodeURIComponent(c); |
| 95 } |
| 96 function percentEscapeQuery(c) { |
| 97 var unicode = c.charCodeAt(0); |
| 98 if (unicode > 32 && unicode < 127 && [ 34, 35, 60, 62, 96 ].indexOf(unicode)
== -1) { |
| 99 return c; |
| 100 } |
| 101 return encodeURIComponent(c); |
| 102 } |
| 103 var EOF = undefined, ALPHA = /[a-zA-Z]/, ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/; |
| 104 function parse(input, stateOverride, base) { |
| 105 function err(message) { |
| 106 errors.push(message); |
| 107 } |
| 108 var state = stateOverride || "scheme start", cursor = 0, buffer = "", seenAt
= false, seenBracket = false, errors = []; |
| 109 loop: while ((input[cursor - 1] != EOF || cursor == 0) && !this._isInvalid)
{ |
| 110 var c = input[cursor]; |
| 111 switch (state) { |
| 112 case "scheme start": |
| 113 if (c && ALPHA.test(c)) { |
| 114 buffer += c.toLowerCase(); |
| 115 state = "scheme"; |
| 116 } else if (!stateOverride) { |
| 117 buffer = ""; |
| 118 state = "no scheme"; |
| 119 continue; |
| 120 } else { |
| 121 err("Invalid scheme."); |
| 122 break loop; |
| 123 } |
| 124 break; |
| 125 |
| 126 case "scheme": |
| 127 if (c && ALPHANUMERIC.test(c)) { |
| 128 buffer += c.toLowerCase(); |
| 129 } else if (":" == c) { |
| 130 this._scheme = buffer; |
| 131 buffer = ""; |
| 132 if (stateOverride) { |
| 133 break loop; |
| 134 } |
| 135 if (isRelativeScheme(this._scheme)) { |
| 136 this._isRelative = true; |
| 137 } |
| 138 if ("file" == this._scheme) { |
| 139 state = "relative"; |
| 140 } else if (this._isRelative && base && base._scheme == this._scheme) { |
| 141 state = "relative or authority"; |
| 142 } else if (this._isRelative) { |
| 143 state = "authority first slash"; |
| 144 } else { |
| 145 state = "scheme data"; |
| 146 } |
| 147 } else if (!stateOverride) { |
| 148 buffer = ""; |
| 149 cursor = 0; |
| 150 state = "no scheme"; |
| 151 continue; |
| 152 } else if (EOF == c) { |
| 153 break loop; |
| 154 } else { |
| 155 err("Code point not allowed in scheme: " + c); |
| 156 break loop; |
| 157 } |
| 158 break; |
| 159 |
| 160 case "scheme data": |
| 161 if ("?" == c) { |
| 162 this._query = "?"; |
| 163 state = "query"; |
| 164 } else if ("#" == c) { |
| 165 this._fragment = "#"; |
| 166 state = "fragment"; |
| 167 } else { |
| 168 if (EOF != c && " " != c && "\n" != c && "\r" != c) { |
| 169 this._schemeData += percentEscape(c); |
| 170 } |
| 171 } |
| 172 break; |
| 173 |
| 174 case "no scheme": |
| 175 if (!base || !isRelativeScheme(base._scheme)) { |
| 176 err("Missing scheme."); |
| 177 invalid.call(this); |
| 178 } else { |
| 179 state = "relative"; |
| 180 continue; |
| 181 } |
| 182 break; |
| 183 |
| 184 case "relative or authority": |
| 185 if ("/" == c && "/" == input[cursor + 1]) { |
| 186 state = "authority ignore slashes"; |
| 187 } else { |
| 188 err("Expected /, got: " + c); |
| 189 state = "relative"; |
| 190 continue; |
| 191 } |
| 192 break; |
| 193 |
| 194 case "relative": |
| 195 this._isRelative = true; |
| 196 if ("file" != this._scheme) this._scheme = base._scheme; |
| 197 if (EOF == c) { |
| 198 this._host = base._host; |
| 199 this._port = base._port; |
| 200 this._path = base._path.slice(); |
| 201 this._query = base._query; |
| 202 this._username = base._username; |
| 203 this._password = base._password; |
| 204 break loop; |
| 205 } else if ("/" == c || "\\" == c) { |
| 206 if ("\\" == c) err("\\ is an invalid code point."); |
| 207 state = "relative slash"; |
| 208 } else if ("?" == c) { |
| 209 this._host = base._host; |
| 210 this._port = base._port; |
| 211 this._path = base._path.slice(); |
| 212 this._query = "?"; |
| 213 this._username = base._username; |
| 214 this._password = base._password; |
| 215 state = "query"; |
| 216 } else if ("#" == c) { |
| 217 this._host = base._host; |
| 218 this._port = base._port; |
| 219 this._path = base._path.slice(); |
| 220 this._query = base._query; |
| 221 this._fragment = "#"; |
| 222 this._username = base._username; |
| 223 this._password = base._password; |
| 224 state = "fragment"; |
| 225 } else { |
| 226 var nextC = input[cursor + 1]; |
| 227 var nextNextC = input[cursor + 2]; |
| 228 if ("file" != this._scheme || !ALPHA.test(c) || nextC != ":" && nextC
!= "|" || EOF != nextNextC && "/" != nextNextC && "\\" != nextNextC && "?" != ne
xtNextC && "#" != nextNextC) { |
| 229 this._host = base._host; |
| 230 this._port = base._port; |
| 231 this._username = base._username; |
| 232 this._password = base._password; |
| 233 this._path = base._path.slice(); |
| 234 this._path.pop(); |
| 235 } |
| 236 state = "relative path"; |
| 237 continue; |
| 238 } |
| 239 break; |
| 240 |
| 241 case "relative slash": |
| 242 if ("/" == c || "\\" == c) { |
| 243 if ("\\" == c) { |
| 244 err("\\ is an invalid code point."); |
| 245 } |
| 246 if ("file" == this._scheme) { |
| 247 state = "file host"; |
| 248 } else { |
| 249 state = "authority ignore slashes"; |
| 250 } |
| 251 } else { |
| 252 if ("file" != this._scheme) { |
| 253 this._host = base._host; |
| 254 this._port = base._port; |
| 255 this._username = base._username; |
| 256 this._password = base._password; |
| 257 } |
| 258 state = "relative path"; |
| 259 continue; |
| 260 } |
| 261 break; |
| 262 |
| 263 case "authority first slash": |
| 264 if ("/" == c) { |
| 265 state = "authority second slash"; |
| 266 } else { |
| 267 err("Expected '/', got: " + c); |
| 268 state = "authority ignore slashes"; |
| 269 continue; |
| 270 } |
| 271 break; |
| 272 |
| 273 case "authority second slash": |
| 274 state = "authority ignore slashes"; |
| 275 if ("/" != c) { |
| 276 err("Expected '/', got: " + c); |
| 277 continue; |
| 278 } |
| 279 break; |
| 280 |
| 281 case "authority ignore slashes": |
| 282 if ("/" != c && "\\" != c) { |
| 283 state = "authority"; |
| 284 continue; |
| 285 } else { |
| 286 err("Expected authority, got: " + c); |
| 287 } |
| 288 break; |
| 289 |
| 290 case "authority": |
| 291 if ("@" == c) { |
| 292 if (seenAt) { |
| 293 err("@ already seen."); |
| 294 buffer += "%40"; |
| 295 } |
| 296 seenAt = true; |
| 297 for (var i = 0; i < buffer.length; i++) { |
| 298 var cp = buffer[i]; |
| 299 if (" " == cp || "\n" == cp || "\r" == cp) { |
| 300 err("Invalid whitespace in authority."); |
| 301 continue; |
| 302 } |
| 303 if (":" == cp && null === this._password) { |
| 304 this._password = ""; |
| 305 continue; |
| 306 } |
| 307 var tempC = percentEscape(cp); |
| 308 null !== this._password ? this._password += tempC : this._username +
= tempC; |
| 309 } |
| 310 buffer = ""; |
| 311 } else if (EOF == c || "/" == c || "\\" == c || "?" == c || "#" == c) { |
| 312 cursor -= buffer.length; |
| 313 buffer = ""; |
| 314 state = "host"; |
| 315 continue; |
| 316 } else { |
| 317 buffer += c; |
| 318 } |
| 319 break; |
| 320 |
| 321 case "file host": |
| 322 if (EOF == c || "/" == c || "\\" == c || "?" == c || "#" == c) { |
| 323 if (buffer.length == 2 && ALPHA.test(buffer[0]) && (buffer[1] == ":" |
| buffer[1] == "|")) { |
| 324 state = "relative path"; |
| 325 } else if (buffer.length == 0) { |
| 326 state = "relative path start"; |
| 327 } else { |
| 328 this._host = IDNAToASCII.call(this, buffer); |
| 329 buffer = ""; |
| 330 state = "relative path start"; |
| 331 } |
| 332 continue; |
| 333 } else if (" " == c || "\n" == c || "\r" == c) { |
| 334 err("Invalid whitespace in file host."); |
| 335 } else { |
| 336 buffer += c; |
| 337 } |
| 338 break; |
| 339 |
| 340 case "host": |
| 341 case "hostname": |
| 342 if (":" == c && !seenBracket) { |
| 343 this._host = IDNAToASCII.call(this, buffer); |
| 344 buffer = ""; |
| 345 state = "port"; |
| 346 if ("hostname" == stateOverride) { |
| 347 break loop; |
| 348 } |
| 349 } else if (EOF == c || "/" == c || "\\" == c || "?" == c || "#" == c) { |
| 350 this._host = IDNAToASCII.call(this, buffer); |
| 351 buffer = ""; |
| 352 state = "relative path start"; |
| 353 if (stateOverride) { |
| 354 break loop; |
| 355 } |
| 356 continue; |
| 357 } else if (" " != c && "\n" != c && "\r" != c) { |
| 358 if ("[" == c) { |
| 359 seenBracket = true; |
| 360 } else if ("]" == c) { |
| 361 seenBracket = false; |
| 362 } |
| 363 buffer += c; |
| 364 } else { |
| 365 err("Invalid code point in host/hostname: " + c); |
| 366 } |
| 367 break; |
| 368 |
| 369 case "port": |
| 370 if (/[0-9]/.test(c)) { |
| 371 buffer += c; |
| 372 } else if (EOF == c || "/" == c || "\\" == c || "?" == c || "#" == c ||
stateOverride) { |
| 373 if ("" != buffer) { |
| 374 var temp = parseInt(buffer, 10); |
| 375 if (temp != relative[this._scheme]) { |
| 376 this._port = temp + ""; |
| 377 } |
| 378 buffer = ""; |
| 379 } |
| 380 if (stateOverride) { |
| 381 break loop; |
| 382 } |
| 383 state = "relative path start"; |
| 384 continue; |
| 385 } else if (" " == c || "\n" == c || "\r" == c) { |
| 386 err("Invalid code point in port: " + c); |
| 387 } else { |
| 388 invalid.call(this); |
| 389 } |
| 390 break; |
| 391 |
| 392 case "relative path start": |
| 393 if ("\\" == c) err("'\\' not allowed in path."); |
| 394 state = "relative path"; |
| 395 if ("/" != c && "\\" != c) { |
| 396 continue; |
| 397 } |
| 398 break; |
| 399 |
| 400 case "relative path": |
| 401 if (EOF == c || "/" == c || "\\" == c || !stateOverride && ("?" == c ||
"#" == c)) { |
| 402 if ("\\" == c) { |
| 403 err("\\ not allowed in relative path."); |
| 404 } |
| 405 var tmp; |
| 406 if (tmp = relativePathDotMapping[buffer.toLowerCase()]) { |
| 407 buffer = tmp; |
| 408 } |
| 409 if (".." == buffer) { |
| 410 this._path.pop(); |
| 411 if ("/" != c && "\\" != c) { |
| 412 this._path.push(""); |
| 413 } |
| 414 } else if ("." == buffer && "/" != c && "\\" != c) { |
| 415 this._path.push(""); |
| 416 } else if ("." != buffer) { |
| 417 if ("file" == this._scheme && this._path.length == 0 && buffer.lengt
h == 2 && ALPHA.test(buffer[0]) && buffer[1] == "|") { |
| 418 buffer = buffer[0] + ":"; |
| 419 } |
| 420 this._path.push(buffer); |
| 421 } |
| 422 buffer = ""; |
| 423 if ("?" == c) { |
| 424 this._query = "?"; |
| 425 state = "query"; |
| 426 } else if ("#" == c) { |
| 427 this._fragment = "#"; |
| 428 state = "fragment"; |
| 429 } |
| 430 } else if (" " != c && "\n" != c && "\r" != c) { |
| 431 buffer += percentEscape(c); |
| 432 } |
| 433 break; |
| 434 |
| 435 case "query": |
| 436 if (!stateOverride && "#" == c) { |
| 437 this._fragment = "#"; |
| 438 state = "fragment"; |
| 439 } else if (EOF != c && " " != c && "\n" != c && "\r" != c) { |
| 440 this._query += percentEscapeQuery(c); |
| 441 } |
| 442 break; |
| 443 |
| 444 case "fragment": |
| 445 if (EOF != c && " " != c && "\n" != c && "\r" != c) { |
| 446 this._fragment += c; |
| 447 } |
| 448 break; |
| 449 } |
| 450 cursor++; |
| 451 } |
| 452 } |
| 453 function clear() { |
| 454 this._scheme = ""; |
| 455 this._schemeData = ""; |
| 456 this._username = ""; |
| 457 this._password = null; |
| 458 this._host = ""; |
| 459 this._port = ""; |
| 460 this._path = []; |
| 461 this._query = ""; |
| 462 this._fragment = ""; |
| 463 this._isInvalid = false; |
| 464 this._isRelative = false; |
| 465 } |
| 466 function jURL(url, base) { |
| 467 if (base !== undefined && !(base instanceof jURL)) base = new jURL(String(ba
se)); |
| 468 this._url = url; |
| 469 clear.call(this); |
| 470 var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, ""); |
| 471 parse.call(this, input, null, base); |
| 472 } |
| 473 jURL.prototype = { |
| 474 toString: function() { |
| 475 return this.href; |
| 476 }, |
| 477 get href() { |
| 478 if (this._isInvalid) return this._url; |
| 479 var authority = ""; |
| 480 if ("" != this._username || null != this._password) { |
| 481 authority = this._username + (null != this._password ? ":" + this._passw
ord : "") + "@"; |
| 482 } |
| 483 return this.protocol + (this._isRelative ? "//" + authority + this.host :
"") + this.pathname + this._query + this._fragment; |
| 484 }, |
| 485 set href(href) { |
| 486 clear.call(this); |
| 487 parse.call(this, href); |
| 488 }, |
| 489 get protocol() { |
| 490 return this._scheme + ":"; |
| 491 }, |
| 492 set protocol(protocol) { |
| 493 if (this._isInvalid) return; |
| 494 parse.call(this, protocol + ":", "scheme start"); |
| 495 }, |
| 496 get host() { |
| 497 return this._isInvalid ? "" : this._port ? this._host + ":" + this._port :
this._host; |
| 498 }, |
| 499 set host(host) { |
| 500 if (this._isInvalid || !this._isRelative) return; |
| 501 parse.call(this, host, "host"); |
| 502 }, |
| 503 get hostname() { |
| 504 return this._host; |
| 505 }, |
| 506 set hostname(hostname) { |
| 507 if (this._isInvalid || !this._isRelative) return; |
| 508 parse.call(this, hostname, "hostname"); |
| 509 }, |
| 510 get port() { |
| 511 return this._port; |
| 512 }, |
| 513 set port(port) { |
| 514 if (this._isInvalid || !this._isRelative) return; |
| 515 parse.call(this, port, "port"); |
| 516 }, |
| 517 get pathname() { |
| 518 return this._isInvalid ? "" : this._isRelative ? "/" + this._path.join("/"
) : this._schemeData; |
| 519 }, |
| 520 set pathname(pathname) { |
| 521 if (this._isInvalid || !this._isRelative) return; |
| 522 this._path = []; |
| 523 parse.call(this, pathname, "relative path start"); |
| 524 }, |
| 525 get search() { |
| 526 return this._isInvalid || !this._query || "?" == this._query ? "" : this._
query; |
| 527 }, |
| 528 set search(search) { |
| 529 if (this._isInvalid || !this._isRelative) return; |
| 530 this._query = "?"; |
| 531 if ("?" == search[0]) search = search.slice(1); |
| 532 parse.call(this, search, "query"); |
| 533 }, |
| 534 get hash() { |
| 535 return this._isInvalid || !this._fragment || "#" == this._fragment ? "" :
this._fragment; |
| 536 }, |
| 537 set hash(hash) { |
| 538 if (this._isInvalid) return; |
| 539 this._fragment = "#"; |
| 540 if ("#" == hash[0]) hash = hash.slice(1); |
| 541 parse.call(this, hash, "fragment"); |
| 542 }, |
| 543 get origin() { |
| 544 var host; |
| 545 if (this._isInvalid || !this._scheme) { |
| 546 return ""; |
| 547 } |
| 548 switch (this._scheme) { |
| 549 case "data": |
| 550 case "file": |
| 551 case "javascript": |
| 552 case "mailto": |
| 553 return "null"; |
| 554 } |
| 555 host = this.host; |
| 556 if (!host) { |
| 557 return ""; |
| 558 } |
| 559 return this._scheme + "://" + host; |
| 560 } |
| 561 }; |
| 562 var OriginalURL = scope.URL; |
| 563 if (OriginalURL) { |
| 564 jURL.createObjectURL = function(blob) { |
| 565 return OriginalURL.createObjectURL.apply(OriginalURL, arguments); |
| 566 }; |
| 567 jURL.revokeObjectURL = function(url) { |
| 568 OriginalURL.revokeObjectURL(url); |
| 569 }; |
| 570 } |
| 571 scope.URL = jURL; |
| 572 })(self); |
| 573 |
| 574 if (typeof WeakMap === "undefined") { |
| 575 (function() { |
| 576 var defineProperty = Object.defineProperty; |
| 577 var counter = Date.now() % 1e9; |
| 578 var WeakMap = function() { |
| 579 this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__"); |
| 580 }; |
| 581 WeakMap.prototype = { |
| 582 set: function(key, value) { |
| 583 var entry = key[this.name]; |
| 584 if (entry && entry[0] === key) entry[1] = value; else defineProperty(key
, this.name, { |
| 585 value: [ key, value ], |
| 586 writable: true |
| 587 }); |
| 588 return this; |
| 589 }, |
| 590 get: function(key) { |
| 591 var entry; |
| 592 return (entry = key[this.name]) && entry[0] === key ? entry[1] : undefin
ed; |
| 593 }, |
| 594 "delete": function(key) { |
| 595 var entry = key[this.name]; |
| 596 if (!entry || entry[0] !== key) return false; |
| 597 entry[0] = entry[1] = undefined; |
| 598 return true; |
| 599 }, |
| 600 has: function(key) { |
| 601 var entry = key[this.name]; |
| 602 if (!entry) return false; |
| 603 return entry[0] === key; |
| 604 } |
| 605 }; |
| 606 window.WeakMap = WeakMap; |
| 607 })(); |
| 608 } |
| 609 |
| 610 (function(global) { |
| 611 if (global.JsMutationObserver) { |
| 612 return; |
| 613 } |
| 614 var registrationsTable = new WeakMap(); |
| 615 var setImmediate; |
| 616 if (/Trident|Edge/.test(navigator.userAgent)) { |
| 617 setImmediate = setTimeout; |
| 618 } else if (window.setImmediate) { |
| 619 setImmediate = window.setImmediate; |
| 620 } else { |
| 621 var setImmediateQueue = []; |
| 622 var sentinel = String(Math.random()); |
| 623 window.addEventListener("message", function(e) { |
| 624 if (e.data === sentinel) { |
| 625 var queue = setImmediateQueue; |
| 626 setImmediateQueue = []; |
| 627 queue.forEach(function(func) { |
| 628 func(); |
| 629 }); |
| 630 } |
| 631 }); |
| 632 setImmediate = function(func) { |
| 633 setImmediateQueue.push(func); |
| 634 window.postMessage(sentinel, "*"); |
| 635 }; |
| 636 } |
| 637 var isScheduled = false; |
| 638 var scheduledObservers = []; |
| 639 function scheduleCallback(observer) { |
| 640 scheduledObservers.push(observer); |
| 641 if (!isScheduled) { |
| 642 isScheduled = true; |
| 643 setImmediate(dispatchCallbacks); |
| 644 } |
| 645 } |
| 646 function wrapIfNeeded(node) { |
| 647 return window.ShadowDOMPolyfill && window.ShadowDOMPolyfill.wrapIfNeeded(nod
e) || node; |
| 648 } |
| 649 function dispatchCallbacks() { |
| 650 isScheduled = false; |
| 651 var observers = scheduledObservers; |
| 652 scheduledObservers = []; |
| 653 observers.sort(function(o1, o2) { |
| 654 return o1.uid_ - o2.uid_; |
| 655 }); |
| 656 var anyNonEmpty = false; |
| 657 observers.forEach(function(observer) { |
| 658 var queue = observer.takeRecords(); |
| 659 removeTransientObserversFor(observer); |
| 660 if (queue.length) { |
| 661 observer.callback_(queue, observer); |
| 662 anyNonEmpty = true; |
| 663 } |
| 664 }); |
| 665 if (anyNonEmpty) dispatchCallbacks(); |
| 666 } |
| 667 function removeTransientObserversFor(observer) { |
| 668 observer.nodes_.forEach(function(node) { |
| 669 var registrations = registrationsTable.get(node); |
| 670 if (!registrations) return; |
| 671 registrations.forEach(function(registration) { |
| 672 if (registration.observer === observer) registration.removeTransientObse
rvers(); |
| 673 }); |
| 674 }); |
| 675 } |
| 676 function forEachAncestorAndObserverEnqueueRecord(target, callback) { |
| 677 for (var node = target; node; node = node.parentNode) { |
| 678 var registrations = registrationsTable.get(node); |
| 679 if (registrations) { |
| 680 for (var j = 0; j < registrations.length; j++) { |
| 681 var registration = registrations[j]; |
| 682 var options = registration.options; |
| 683 if (node !== target && !options.subtree) continue; |
| 684 var record = callback(options); |
| 685 if (record) registration.enqueue(record); |
| 686 } |
| 687 } |
| 688 } |
| 689 } |
| 690 var uidCounter = 0; |
| 691 function JsMutationObserver(callback) { |
| 692 this.callback_ = callback; |
| 693 this.nodes_ = []; |
| 694 this.records_ = []; |
| 695 this.uid_ = ++uidCounter; |
| 696 } |
| 697 JsMutationObserver.prototype = { |
| 698 observe: function(target, options) { |
| 699 target = wrapIfNeeded(target); |
| 700 if (!options.childList && !options.attributes && !options.characterData ||
options.attributeOldValue && !options.attributes || options.attributeFilter &&
options.attributeFilter.length && !options.attributes || options.characterDataOl
dValue && !options.characterData) { |
| 701 throw new SyntaxError(); |
| 702 } |
| 703 var registrations = registrationsTable.get(target); |
| 704 if (!registrations) registrationsTable.set(target, registrations = []); |
| 705 var registration; |
| 706 for (var i = 0; i < registrations.length; i++) { |
| 707 if (registrations[i].observer === this) { |
| 708 registration = registrations[i]; |
| 709 registration.removeListeners(); |
| 710 registration.options = options; |
| 711 break; |
| 712 } |
| 713 } |
| 714 if (!registration) { |
| 715 registration = new Registration(this, target, options); |
| 716 registrations.push(registration); |
| 717 this.nodes_.push(target); |
| 718 } |
| 719 registration.addListeners(); |
| 720 }, |
| 721 disconnect: function() { |
| 722 this.nodes_.forEach(function(node) { |
| 723 var registrations = registrationsTable.get(node); |
| 724 for (var i = 0; i < registrations.length; i++) { |
| 725 var registration = registrations[i]; |
| 726 if (registration.observer === this) { |
| 727 registration.removeListeners(); |
| 728 registrations.splice(i, 1); |
| 729 break; |
| 730 } |
| 731 } |
| 732 }, this); |
| 733 this.records_ = []; |
| 734 }, |
| 735 takeRecords: function() { |
| 736 var copyOfRecords = this.records_; |
| 737 this.records_ = []; |
| 738 return copyOfRecords; |
| 739 } |
| 740 }; |
| 741 function MutationRecord(type, target) { |
| 742 this.type = type; |
| 743 this.target = target; |
| 744 this.addedNodes = []; |
| 745 this.removedNodes = []; |
| 746 this.previousSibling = null; |
| 747 this.nextSibling = null; |
| 748 this.attributeName = null; |
| 749 this.attributeNamespace = null; |
| 750 this.oldValue = null; |
| 751 } |
| 752 function copyMutationRecord(original) { |
| 753 var record = new MutationRecord(original.type, original.target); |
| 754 record.addedNodes = original.addedNodes.slice(); |
| 755 record.removedNodes = original.removedNodes.slice(); |
| 756 record.previousSibling = original.previousSibling; |
| 757 record.nextSibling = original.nextSibling; |
| 758 record.attributeName = original.attributeName; |
| 759 record.attributeNamespace = original.attributeNamespace; |
| 760 record.oldValue = original.oldValue; |
| 761 return record; |
| 762 } |
| 763 var currentRecord, recordWithOldValue; |
| 764 function getRecord(type, target) { |
| 765 return currentRecord = new MutationRecord(type, target); |
| 766 } |
| 767 function getRecordWithOldValue(oldValue) { |
| 768 if (recordWithOldValue) return recordWithOldValue; |
| 769 recordWithOldValue = copyMutationRecord(currentRecord); |
| 770 recordWithOldValue.oldValue = oldValue; |
| 771 return recordWithOldValue; |
| 772 } |
| 773 function clearRecords() { |
| 774 currentRecord = recordWithOldValue = undefined; |
| 775 } |
| 776 function recordRepresentsCurrentMutation(record) { |
| 777 return record === recordWithOldValue || record === currentRecord; |
| 778 } |
| 779 function selectRecord(lastRecord, newRecord) { |
| 780 if (lastRecord === newRecord) return lastRecord; |
| 781 if (recordWithOldValue && recordRepresentsCurrentMutation(lastRecord)) retur
n recordWithOldValue; |
| 782 return null; |
| 783 } |
| 784 function Registration(observer, target, options) { |
| 785 this.observer = observer; |
| 786 this.target = target; |
| 787 this.options = options; |
| 788 this.transientObservedNodes = []; |
| 789 } |
| 790 Registration.prototype = { |
| 791 enqueue: function(record) { |
| 792 var records = this.observer.records_; |
| 793 var length = records.length; |
| 794 if (records.length > 0) { |
| 795 var lastRecord = records[length - 1]; |
| 796 var recordToReplaceLast = selectRecord(lastRecord, record); |
| 797 if (recordToReplaceLast) { |
| 798 records[length - 1] = recordToReplaceLast; |
| 799 return; |
| 800 } |
| 801 } else { |
| 802 scheduleCallback(this.observer); |
| 803 } |
| 804 records[length] = record; |
| 805 }, |
| 806 addListeners: function() { |
| 807 this.addListeners_(this.target); |
| 808 }, |
| 809 addListeners_: function(node) { |
| 810 var options = this.options; |
| 811 if (options.attributes) node.addEventListener("DOMAttrModified", this, tru
e); |
| 812 if (options.characterData) node.addEventListener("DOMCharacterDataModified
", this, true); |
| 813 if (options.childList) node.addEventListener("DOMNodeInserted", this, true
); |
| 814 if (options.childList || options.subtree) node.addEventListener("DOMNodeRe
moved", this, true); |
| 815 }, |
| 816 removeListeners: function() { |
| 817 this.removeListeners_(this.target); |
| 818 }, |
| 819 removeListeners_: function(node) { |
| 820 var options = this.options; |
| 821 if (options.attributes) node.removeEventListener("DOMAttrModified", this,
true); |
| 822 if (options.characterData) node.removeEventListener("DOMCharacterDataModif
ied", this, true); |
| 823 if (options.childList) node.removeEventListener("DOMNodeInserted", this, t
rue); |
| 824 if (options.childList || options.subtree) node.removeEventListener("DOMNod
eRemoved", this, true); |
| 825 }, |
| 826 addTransientObserver: function(node) { |
| 827 if (node === this.target) return; |
| 828 this.addListeners_(node); |
| 829 this.transientObservedNodes.push(node); |
| 830 var registrations = registrationsTable.get(node); |
| 831 if (!registrations) registrationsTable.set(node, registrations = []); |
| 832 registrations.push(this); |
| 833 }, |
| 834 removeTransientObservers: function() { |
| 835 var transientObservedNodes = this.transientObservedNodes; |
| 836 this.transientObservedNodes = []; |
| 837 transientObservedNodes.forEach(function(node) { |
| 838 this.removeListeners_(node); |
| 839 var registrations = registrationsTable.get(node); |
| 840 for (var i = 0; i < registrations.length; i++) { |
| 841 if (registrations[i] === this) { |
| 842 registrations.splice(i, 1); |
| 843 break; |
| 844 } |
| 845 } |
| 846 }, this); |
| 847 }, |
| 848 handleEvent: function(e) { |
| 849 e.stopImmediatePropagation(); |
| 850 switch (e.type) { |
| 851 case "DOMAttrModified": |
| 852 var name = e.attrName; |
| 853 var namespace = e.relatedNode.namespaceURI; |
| 854 var target = e.target; |
| 855 var record = new getRecord("attributes", target); |
| 856 record.attributeName = name; |
| 857 record.attributeNamespace = namespace; |
| 858 var oldValue = e.attrChange === MutationEvent.ADDITION ? null : e.prevVa
lue; |
| 859 forEachAncestorAndObserverEnqueueRecord(target, function(options) { |
| 860 if (!options.attributes) return; |
| 861 if (options.attributeFilter && options.attributeFilter.length && optio
ns.attributeFilter.indexOf(name) === -1 && options.attributeFilter.indexOf(names
pace) === -1) { |
| 862 return; |
| 863 } |
| 864 if (options.attributeOldValue) return getRecordWithOldValue(oldValue); |
| 865 return record; |
| 866 }); |
| 867 break; |
| 868 |
| 869 case "DOMCharacterDataModified": |
| 870 var target = e.target; |
| 871 var record = getRecord("characterData", target); |
| 872 var oldValue = e.prevValue; |
| 873 forEachAncestorAndObserverEnqueueRecord(target, function(options) { |
| 874 if (!options.characterData) return; |
| 875 if (options.characterDataOldValue) return getRecordWithOldValue(oldVal
ue); |
| 876 return record; |
| 877 }); |
| 878 break; |
| 879 |
| 880 case "DOMNodeRemoved": |
| 881 this.addTransientObserver(e.target); |
| 882 |
| 883 case "DOMNodeInserted": |
| 884 var changedNode = e.target; |
| 885 var addedNodes, removedNodes; |
| 886 if (e.type === "DOMNodeInserted") { |
| 887 addedNodes = [ changedNode ]; |
| 888 removedNodes = []; |
| 889 } else { |
| 890 addedNodes = []; |
| 891 removedNodes = [ changedNode ]; |
| 892 } |
| 893 var previousSibling = changedNode.previousSibling; |
| 894 var nextSibling = changedNode.nextSibling; |
| 895 var record = getRecord("childList", e.target.parentNode); |
| 896 record.addedNodes = addedNodes; |
| 897 record.removedNodes = removedNodes; |
| 898 record.previousSibling = previousSibling; |
| 899 record.nextSibling = nextSibling; |
| 900 forEachAncestorAndObserverEnqueueRecord(e.relatedNode, function(options)
{ |
| 901 if (!options.childList) return; |
| 902 return record; |
| 903 }); |
| 904 } |
| 905 clearRecords(); |
| 906 } |
| 907 }; |
| 908 global.JsMutationObserver = JsMutationObserver; |
| 909 if (!global.MutationObserver) { |
| 910 global.MutationObserver = JsMutationObserver; |
| 911 JsMutationObserver._isPolyfilled = true; |
| 912 } |
| 913 })(self); |
| 914 |
| 915 (function() { |
| 916 var needsTemplate = typeof HTMLTemplateElement === "undefined"; |
| 917 var needsCloning = function() { |
| 918 if (!needsTemplate) { |
| 919 var frag = document.createDocumentFragment(); |
| 920 var t = document.createElement("template"); |
| 921 frag.appendChild(t); |
| 922 t.content.appendChild(document.createElement("div")); |
| 923 var clone = frag.cloneNode(true); |
| 924 return clone.firstChild.content.childNodes.length === 0; |
| 925 } |
| 926 }(); |
| 927 var TEMPLATE_TAG = "template"; |
| 928 var TemplateImpl = function() {}; |
| 929 if (needsTemplate) { |
| 930 var contentDoc = document.implementation.createHTMLDocument("template"); |
| 931 var canDecorate = true; |
| 932 var templateStyle = document.createElement("style"); |
| 933 templateStyle.textContent = TEMPLATE_TAG + "{display:none;}"; |
| 934 var head = document.head; |
| 935 head.insertBefore(templateStyle, head.firstElementChild); |
| 936 TemplateImpl.prototype = Object.create(HTMLElement.prototype); |
| 937 TemplateImpl.decorate = function(template) { |
| 938 if (template.content) { |
| 939 return; |
| 940 } |
| 941 template.content = contentDoc.createDocumentFragment(); |
| 942 var child; |
| 943 while (child = template.firstChild) { |
| 944 template.content.appendChild(child); |
| 945 } |
| 946 if (canDecorate) { |
| 947 try { |
| 948 Object.defineProperty(template, "innerHTML", { |
| 949 get: function() { |
| 950 var o = ""; |
| 951 for (var e = this.content.firstChild; e; e = e.nextSibling) { |
| 952 o += e.outerHTML || escapeData(e.data); |
| 953 } |
| 954 return o; |
| 955 }, |
| 956 set: function(text) { |
| 957 contentDoc.body.innerHTML = text; |
| 958 TemplateImpl.bootstrap(contentDoc); |
| 959 while (this.content.firstChild) { |
| 960 this.content.removeChild(this.content.firstChild); |
| 961 } |
| 962 while (contentDoc.body.firstChild) { |
| 963 this.content.appendChild(contentDoc.body.firstChild); |
| 964 } |
| 965 }, |
| 966 configurable: true |
| 967 }); |
| 968 template.cloneNode = function(deep) { |
| 969 return TemplateImpl.cloneNode(this, deep); |
| 970 }; |
| 971 } catch (err) { |
| 972 canDecorate = false; |
| 973 } |
| 974 } |
| 975 TemplateImpl.bootstrap(template.content); |
| 976 }; |
| 977 TemplateImpl.bootstrap = function(doc) { |
| 978 var templates = doc.querySelectorAll(TEMPLATE_TAG); |
| 979 for (var i = 0, l = templates.length, t; i < l && (t = templates[i]); i++)
{ |
| 980 TemplateImpl.decorate(t); |
| 981 } |
| 982 }; |
| 983 document.addEventListener("DOMContentLoaded", function() { |
| 984 TemplateImpl.bootstrap(document); |
| 985 }); |
| 986 var createElement = document.createElement; |
| 987 document.createElement = function() { |
| 988 "use strict"; |
| 989 var el = createElement.apply(document, arguments); |
| 990 if (el.localName == "template") { |
| 991 TemplateImpl.decorate(el); |
| 992 } |
| 993 return el; |
| 994 }; |
| 995 var escapeDataRegExp = /[&\u00A0<>]/g; |
| 996 function escapeReplace(c) { |
| 997 switch (c) { |
| 998 case "&": |
| 999 return "&"; |
| 1000 |
| 1001 case "<": |
| 1002 return "<"; |
| 1003 |
| 1004 case ">": |
| 1005 return ">"; |
| 1006 |
| 1007 case "Â ": |
| 1008 return " "; |
| 1009 } |
| 1010 } |
| 1011 function escapeData(s) { |
| 1012 return s.replace(escapeDataRegExp, escapeReplace); |
| 1013 } |
| 1014 } |
| 1015 if (needsTemplate || needsCloning) { |
| 1016 var nativeCloneNode = Node.prototype.cloneNode; |
| 1017 TemplateImpl.cloneNode = function(template, deep) { |
| 1018 var clone = nativeCloneNode.call(template); |
| 1019 if (this.decorate) { |
| 1020 this.decorate(clone); |
| 1021 } |
| 1022 if (deep) { |
| 1023 clone.content.appendChild(nativeCloneNode.call(template.content, true)); |
| 1024 this.fixClonedDom(clone.content, template.content); |
| 1025 } |
| 1026 return clone; |
| 1027 }; |
| 1028 TemplateImpl.fixClonedDom = function(clone, source) { |
| 1029 var s$ = source.querySelectorAll(TEMPLATE_TAG); |
| 1030 var t$ = clone.querySelectorAll(TEMPLATE_TAG); |
| 1031 for (var i = 0, l = t$.length, t, s; i < l; i++) { |
| 1032 s = s$[i]; |
| 1033 t = t$[i]; |
| 1034 if (this.decorate) { |
| 1035 this.decorate(s); |
| 1036 } |
| 1037 t.parentNode.replaceChild(s.cloneNode(true), t); |
| 1038 } |
| 1039 }; |
| 1040 var originalImportNode = document.importNode; |
| 1041 Node.prototype.cloneNode = function(deep) { |
| 1042 var dom = nativeCloneNode.call(this, deep); |
| 1043 if (deep) { |
| 1044 TemplateImpl.fixClonedDom(dom, this); |
| 1045 } |
| 1046 return dom; |
| 1047 }; |
| 1048 document.importNode = function(element, deep) { |
| 1049 if (element.localName === TEMPLATE_TAG) { |
| 1050 return TemplateImpl.cloneNode(element, deep); |
| 1051 } else { |
| 1052 var dom = originalImportNode.call(document, element, deep); |
| 1053 if (deep) { |
| 1054 TemplateImpl.fixClonedDom(dom, element); |
| 1055 } |
| 1056 return dom; |
| 1057 } |
| 1058 }; |
| 1059 if (needsCloning) { |
| 1060 HTMLTemplateElement.prototype.cloneNode = function(deep) { |
| 1061 return TemplateImpl.cloneNode(this, deep); |
| 1062 }; |
| 1063 } |
| 1064 } |
| 1065 if (needsTemplate) { |
| 1066 HTMLTemplateElement = TemplateImpl; |
| 1067 } |
| 1068 })(); |
| 1069 |
| 1070 (function(scope) { |
| 1071 "use strict"; |
| 1072 if (!window.performance) { |
| 1073 var start = Date.now(); |
| 1074 window.performance = { |
| 1075 now: function() { |
| 1076 return Date.now() - start; |
| 1077 } |
| 1078 }; |
| 1079 } |
| 1080 if (!window.requestAnimationFrame) { |
| 1081 window.requestAnimationFrame = function() { |
| 1082 var nativeRaf = window.webkitRequestAnimationFrame || window.mozRequestAni
mationFrame; |
| 1083 return nativeRaf ? function(callback) { |
| 1084 return nativeRaf(function() { |
| 1085 callback(performance.now()); |
| 1086 }); |
| 1087 } : function(callback) { |
| 1088 return window.setTimeout(callback, 1e3 / 60); |
| 1089 }; |
| 1090 }(); |
| 1091 } |
| 1092 if (!window.cancelAnimationFrame) { |
| 1093 window.cancelAnimationFrame = function() { |
| 1094 return window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame
|| function(id) { |
| 1095 clearTimeout(id); |
| 1096 }; |
| 1097 }(); |
| 1098 } |
| 1099 var workingDefaultPrevented = function() { |
| 1100 var e = document.createEvent("Event"); |
| 1101 e.initEvent("foo", true, true); |
| 1102 e.preventDefault(); |
| 1103 return e.defaultPrevented; |
| 1104 }(); |
| 1105 if (!workingDefaultPrevented) { |
| 1106 var origPreventDefault = Event.prototype.preventDefault; |
| 1107 Event.prototype.preventDefault = function() { |
| 1108 if (!this.cancelable) { |
| 1109 return; |
| 1110 } |
| 1111 origPreventDefault.call(this); |
| 1112 Object.defineProperty(this, "defaultPrevented", { |
| 1113 get: function() { |
| 1114 return true; |
| 1115 }, |
| 1116 configurable: true |
| 1117 }); |
| 1118 }; |
| 1119 } |
| 1120 var isIE = /Trident/.test(navigator.userAgent); |
| 1121 if (!window.CustomEvent || isIE && typeof window.CustomEvent !== "function") { |
| 1122 window.CustomEvent = function(inType, params) { |
| 1123 params = params || {}; |
| 1124 var e = document.createEvent("CustomEvent"); |
| 1125 e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelab
le), params.detail); |
| 1126 return e; |
| 1127 }; |
| 1128 window.CustomEvent.prototype = window.Event.prototype; |
| 1129 } |
| 1130 if (!window.Event || isIE && typeof window.Event !== "function") { |
| 1131 var origEvent = window.Event; |
| 1132 window.Event = function(inType, params) { |
| 1133 params = params || {}; |
| 1134 var e = document.createEvent("Event"); |
| 1135 e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable)); |
| 1136 return e; |
| 1137 }; |
| 1138 window.Event.prototype = origEvent.prototype; |
| 1139 } |
| 1140 })(window.WebComponents); |
| 1141 |
| 1142 window.HTMLImports = window.HTMLImports || { |
| 1143 flags: {} |
| 1144 }; |
| 1145 |
| 1146 (function(scope) { |
| 1147 var IMPORT_LINK_TYPE = "import"; |
| 1148 var useNative = Boolean(IMPORT_LINK_TYPE in document.createElement("link")); |
| 1149 var hasShadowDOMPolyfill = Boolean(window.ShadowDOMPolyfill); |
| 1150 var wrap = function(node) { |
| 1151 return hasShadowDOMPolyfill ? window.ShadowDOMPolyfill.wrapIfNeeded(node) :
node; |
| 1152 }; |
| 1153 var rootDocument = wrap(document); |
| 1154 var currentScriptDescriptor = { |
| 1155 get: function() { |
| 1156 var script = window.HTMLImports.currentScript || document.currentScript ||
(document.readyState !== "complete" ? document.scripts[document.scripts.length
- 1] : null); |
| 1157 return wrap(script); |
| 1158 }, |
| 1159 configurable: true |
| 1160 }; |
| 1161 Object.defineProperty(document, "_currentScript", currentScriptDescriptor); |
| 1162 Object.defineProperty(rootDocument, "_currentScript", currentScriptDescriptor)
; |
| 1163 var isIE = /Trident/.test(navigator.userAgent); |
| 1164 function whenReady(callback, doc) { |
| 1165 doc = doc || rootDocument; |
| 1166 whenDocumentReady(function() { |
| 1167 watchImportsLoad(callback, doc); |
| 1168 }, doc); |
| 1169 } |
| 1170 var requiredReadyState = isIE ? "complete" : "interactive"; |
| 1171 var READY_EVENT = "readystatechange"; |
| 1172 function isDocumentReady(doc) { |
| 1173 return doc.readyState === "complete" || doc.readyState === requiredReadyStat
e; |
| 1174 } |
| 1175 function whenDocumentReady(callback, doc) { |
| 1176 if (!isDocumentReady(doc)) { |
| 1177 var checkReady = function() { |
| 1178 if (doc.readyState === "complete" || doc.readyState === requiredReadySta
te) { |
| 1179 doc.removeEventListener(READY_EVENT, checkReady); |
| 1180 whenDocumentReady(callback, doc); |
| 1181 } |
| 1182 }; |
| 1183 doc.addEventListener(READY_EVENT, checkReady); |
| 1184 } else if (callback) { |
| 1185 callback(); |
| 1186 } |
| 1187 } |
| 1188 function markTargetLoaded(event) { |
| 1189 event.target.__loaded = true; |
| 1190 } |
| 1191 function watchImportsLoad(callback, doc) { |
| 1192 var imports = doc.querySelectorAll("link[rel=import]"); |
| 1193 var parsedCount = 0, importCount = imports.length, newImports = [], errorImp
orts = []; |
| 1194 function checkDone() { |
| 1195 if (parsedCount == importCount && callback) { |
| 1196 callback({ |
| 1197 allImports: imports, |
| 1198 loadedImports: newImports, |
| 1199 errorImports: errorImports |
| 1200 }); |
| 1201 } |
| 1202 } |
| 1203 function loadedImport(e) { |
| 1204 markTargetLoaded(e); |
| 1205 newImports.push(this); |
| 1206 parsedCount++; |
| 1207 checkDone(); |
| 1208 } |
| 1209 function errorLoadingImport(e) { |
| 1210 errorImports.push(this); |
| 1211 parsedCount++; |
| 1212 checkDone(); |
| 1213 } |
| 1214 if (importCount) { |
| 1215 for (var i = 0, imp; i < importCount && (imp = imports[i]); i++) { |
| 1216 if (isImportLoaded(imp)) { |
| 1217 newImports.push(this); |
| 1218 parsedCount++; |
| 1219 checkDone(); |
| 1220 } else { |
| 1221 imp.addEventListener("load", loadedImport); |
| 1222 imp.addEventListener("error", errorLoadingImport); |
| 1223 } |
| 1224 } |
| 1225 } else { |
| 1226 checkDone(); |
| 1227 } |
| 1228 } |
| 1229 function isImportLoaded(link) { |
| 1230 return useNative ? link.__loaded || link.import && link.import.readyState !=
= "loading" : link.__importParsed; |
| 1231 } |
| 1232 if (useNative) { |
| 1233 new MutationObserver(function(mxns) { |
| 1234 for (var i = 0, l = mxns.length, m; i < l && (m = mxns[i]); i++) { |
| 1235 if (m.addedNodes) { |
| 1236 handleImports(m.addedNodes); |
| 1237 } |
| 1238 } |
| 1239 }).observe(document.head, { |
| 1240 childList: true |
| 1241 }); |
| 1242 function handleImports(nodes) { |
| 1243 for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) { |
| 1244 if (isImport(n)) { |
| 1245 handleImport(n); |
| 1246 } |
| 1247 } |
| 1248 } |
| 1249 function isImport(element) { |
| 1250 return element.localName === "link" && element.rel === "import"; |
| 1251 } |
| 1252 function handleImport(element) { |
| 1253 var loaded = element.import; |
| 1254 if (loaded) { |
| 1255 markTargetLoaded({ |
| 1256 target: element |
| 1257 }); |
| 1258 } else { |
| 1259 element.addEventListener("load", markTargetLoaded); |
| 1260 element.addEventListener("error", markTargetLoaded); |
| 1261 } |
| 1262 } |
| 1263 (function() { |
| 1264 if (document.readyState === "loading") { |
| 1265 var imports = document.querySelectorAll("link[rel=import]"); |
| 1266 for (var i = 0, l = imports.length, imp; i < l && (imp = imports[i]); i+
+) { |
| 1267 handleImport(imp); |
| 1268 } |
| 1269 } |
| 1270 })(); |
| 1271 } |
| 1272 whenReady(function(detail) { |
| 1273 window.HTMLImports.ready = true; |
| 1274 window.HTMLImports.readyTime = new Date().getTime(); |
| 1275 var evt = rootDocument.createEvent("CustomEvent"); |
| 1276 evt.initCustomEvent("HTMLImportsLoaded", true, true, detail); |
| 1277 rootDocument.dispatchEvent(evt); |
| 1278 }); |
| 1279 scope.IMPORT_LINK_TYPE = IMPORT_LINK_TYPE; |
| 1280 scope.useNative = useNative; |
| 1281 scope.rootDocument = rootDocument; |
| 1282 scope.whenReady = whenReady; |
| 1283 scope.isIE = isIE; |
| 1284 })(window.HTMLImports); |
| 1285 |
| 1286 (function(scope) { |
| 1287 var modules = []; |
| 1288 var addModule = function(module) { |
| 1289 modules.push(module); |
| 1290 }; |
| 1291 var initializeModules = function() { |
| 1292 modules.forEach(function(module) { |
| 1293 module(scope); |
| 1294 }); |
| 1295 }; |
| 1296 scope.addModule = addModule; |
| 1297 scope.initializeModules = initializeModules; |
| 1298 })(window.HTMLImports); |
| 1299 |
| 1300 window.HTMLImports.addModule(function(scope) { |
| 1301 var CSS_URL_REGEXP = /(url\()([^)]*)(\))/g; |
| 1302 var CSS_IMPORT_REGEXP = /(@import[\s]+(?!url\())([^;]*)(;)/g; |
| 1303 var path = { |
| 1304 resolveUrlsInStyle: function(style, linkUrl) { |
| 1305 var doc = style.ownerDocument; |
| 1306 var resolver = doc.createElement("a"); |
| 1307 style.textContent = this.resolveUrlsInCssText(style.textContent, linkUrl,
resolver); |
| 1308 return style; |
| 1309 }, |
| 1310 resolveUrlsInCssText: function(cssText, linkUrl, urlObj) { |
| 1311 var r = this.replaceUrls(cssText, urlObj, linkUrl, CSS_URL_REGEXP); |
| 1312 r = this.replaceUrls(r, urlObj, linkUrl, CSS_IMPORT_REGEXP); |
| 1313 return r; |
| 1314 }, |
| 1315 replaceUrls: function(text, urlObj, linkUrl, regexp) { |
| 1316 return text.replace(regexp, function(m, pre, url, post) { |
| 1317 var urlPath = url.replace(/["']/g, ""); |
| 1318 if (linkUrl) { |
| 1319 urlPath = new URL(urlPath, linkUrl).href; |
| 1320 } |
| 1321 urlObj.href = urlPath; |
| 1322 urlPath = urlObj.href; |
| 1323 return pre + "'" + urlPath + "'" + post; |
| 1324 }); |
| 1325 } |
| 1326 }; |
| 1327 scope.path = path; |
| 1328 }); |
| 1329 |
| 1330 window.HTMLImports.addModule(function(scope) { |
| 1331 var xhr = { |
| 1332 async: true, |
| 1333 ok: function(request) { |
| 1334 return request.status >= 200 && request.status < 300 || request.status ===
304 || request.status === 0; |
| 1335 }, |
| 1336 load: function(url, next, nextContext) { |
| 1337 var request = new XMLHttpRequest(); |
| 1338 if (scope.flags.debug || scope.flags.bust) { |
| 1339 url += "?" + Math.random(); |
| 1340 } |
| 1341 request.open("GET", url, xhr.async); |
| 1342 request.addEventListener("readystatechange", function(e) { |
| 1343 if (request.readyState === 4) { |
| 1344 var redirectedUrl = null; |
| 1345 try { |
| 1346 var locationHeader = request.getResponseHeader("Location"); |
| 1347 if (locationHeader) { |
| 1348 redirectedUrl = locationHeader.substr(0, 1) === "/" ? location.ori
gin + locationHeader : locationHeader; |
| 1349 } |
| 1350 } catch (e) { |
| 1351 console.error(e.message); |
| 1352 } |
| 1353 next.call(nextContext, !xhr.ok(request) && request, request.response |
| request.responseText, redirectedUrl); |
| 1354 } |
| 1355 }); |
| 1356 request.send(); |
| 1357 return request; |
| 1358 }, |
| 1359 loadDocument: function(url, next, nextContext) { |
| 1360 this.load(url, next, nextContext).responseType = "document"; |
| 1361 } |
| 1362 }; |
| 1363 scope.xhr = xhr; |
| 1364 }); |
| 1365 |
| 1366 window.HTMLImports.addModule(function(scope) { |
| 1367 var xhr = scope.xhr; |
| 1368 var flags = scope.flags; |
| 1369 var Loader = function(onLoad, onComplete) { |
| 1370 this.cache = {}; |
| 1371 this.onload = onLoad; |
| 1372 this.oncomplete = onComplete; |
| 1373 this.inflight = 0; |
| 1374 this.pending = {}; |
| 1375 }; |
| 1376 Loader.prototype = { |
| 1377 addNodes: function(nodes) { |
| 1378 this.inflight += nodes.length; |
| 1379 for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) { |
| 1380 this.require(n); |
| 1381 } |
| 1382 this.checkDone(); |
| 1383 }, |
| 1384 addNode: function(node) { |
| 1385 this.inflight++; |
| 1386 this.require(node); |
| 1387 this.checkDone(); |
| 1388 }, |
| 1389 require: function(elt) { |
| 1390 var url = elt.src || elt.href; |
| 1391 elt.__nodeUrl = url; |
| 1392 if (!this.dedupe(url, elt)) { |
| 1393 this.fetch(url, elt); |
| 1394 } |
| 1395 }, |
| 1396 dedupe: function(url, elt) { |
| 1397 if (this.pending[url]) { |
| 1398 this.pending[url].push(elt); |
| 1399 return true; |
| 1400 } |
| 1401 var resource; |
| 1402 if (this.cache[url]) { |
| 1403 this.onload(url, elt, this.cache[url]); |
| 1404 this.tail(); |
| 1405 return true; |
| 1406 } |
| 1407 this.pending[url] = [ elt ]; |
| 1408 return false; |
| 1409 }, |
| 1410 fetch: function(url, elt) { |
| 1411 flags.load && console.log("fetch", url, elt); |
| 1412 if (!url) { |
| 1413 setTimeout(function() { |
| 1414 this.receive(url, elt, { |
| 1415 error: "href must be specified" |
| 1416 }, null); |
| 1417 }.bind(this), 0); |
| 1418 } else if (url.match(/^data:/)) { |
| 1419 var pieces = url.split(","); |
| 1420 var header = pieces[0]; |
| 1421 var body = pieces[1]; |
| 1422 if (header.indexOf(";base64") > -1) { |
| 1423 body = atob(body); |
| 1424 } else { |
| 1425 body = decodeURIComponent(body); |
| 1426 } |
| 1427 setTimeout(function() { |
| 1428 this.receive(url, elt, null, body); |
| 1429 }.bind(this), 0); |
| 1430 } else { |
| 1431 var receiveXhr = function(err, resource, redirectedUrl) { |
| 1432 this.receive(url, elt, err, resource, redirectedUrl); |
| 1433 }.bind(this); |
| 1434 xhr.load(url, receiveXhr); |
| 1435 } |
| 1436 }, |
| 1437 receive: function(url, elt, err, resource, redirectedUrl) { |
| 1438 this.cache[url] = resource; |
| 1439 var $p = this.pending[url]; |
| 1440 for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) { |
| 1441 this.onload(url, p, resource, err, redirectedUrl); |
| 1442 this.tail(); |
| 1443 } |
| 1444 this.pending[url] = null; |
| 1445 }, |
| 1446 tail: function() { |
| 1447 --this.inflight; |
| 1448 this.checkDone(); |
| 1449 }, |
| 1450 checkDone: function() { |
| 1451 if (!this.inflight) { |
| 1452 this.oncomplete(); |
| 1453 } |
| 1454 } |
| 1455 }; |
| 1456 scope.Loader = Loader; |
| 1457 }); |
| 1458 |
| 1459 window.HTMLImports.addModule(function(scope) { |
| 1460 var Observer = function(addCallback) { |
| 1461 this.addCallback = addCallback; |
| 1462 this.mo = new MutationObserver(this.handler.bind(this)); |
| 1463 }; |
| 1464 Observer.prototype = { |
| 1465 handler: function(mutations) { |
| 1466 for (var i = 0, l = mutations.length, m; i < l && (m = mutations[i]); i++)
{ |
| 1467 if (m.type === "childList" && m.addedNodes.length) { |
| 1468 this.addedNodes(m.addedNodes); |
| 1469 } |
| 1470 } |
| 1471 }, |
| 1472 addedNodes: function(nodes) { |
| 1473 if (this.addCallback) { |
| 1474 this.addCallback(nodes); |
| 1475 } |
| 1476 for (var i = 0, l = nodes.length, n, loading; i < l && (n = nodes[i]); i++
) { |
| 1477 if (n.children && n.children.length) { |
| 1478 this.addedNodes(n.children); |
| 1479 } |
| 1480 } |
| 1481 }, |
| 1482 observe: function(root) { |
| 1483 this.mo.observe(root, { |
| 1484 childList: true, |
| 1485 subtree: true |
| 1486 }); |
| 1487 } |
| 1488 }; |
| 1489 scope.Observer = Observer; |
| 1490 }); |
| 1491 |
| 1492 window.HTMLImports.addModule(function(scope) { |
| 1493 var path = scope.path; |
| 1494 var rootDocument = scope.rootDocument; |
| 1495 var flags = scope.flags; |
| 1496 var isIE = scope.isIE; |
| 1497 var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE; |
| 1498 var IMPORT_SELECTOR = "link[rel=" + IMPORT_LINK_TYPE + "]"; |
| 1499 var importParser = { |
| 1500 documentSelectors: IMPORT_SELECTOR, |
| 1501 importsSelectors: [ IMPORT_SELECTOR, "link[rel=stylesheet]:not([type])", "st
yle:not([type])", "script:not([type])", 'script[type="application/javascript"]',
'script[type="text/javascript"]' ].join(","), |
| 1502 map: { |
| 1503 link: "parseLink", |
| 1504 script: "parseScript", |
| 1505 style: "parseStyle" |
| 1506 }, |
| 1507 dynamicElements: [], |
| 1508 parseNext: function() { |
| 1509 var next = this.nextToParse(); |
| 1510 if (next) { |
| 1511 this.parse(next); |
| 1512 } |
| 1513 }, |
| 1514 parse: function(elt) { |
| 1515 if (this.isParsed(elt)) { |
| 1516 flags.parse && console.log("[%s] is already parsed", elt.localName); |
| 1517 return; |
| 1518 } |
| 1519 var fn = this[this.map[elt.localName]]; |
| 1520 if (fn) { |
| 1521 this.markParsing(elt); |
| 1522 fn.call(this, elt); |
| 1523 } |
| 1524 }, |
| 1525 parseDynamic: function(elt, quiet) { |
| 1526 this.dynamicElements.push(elt); |
| 1527 if (!quiet) { |
| 1528 this.parseNext(); |
| 1529 } |
| 1530 }, |
| 1531 markParsing: function(elt) { |
| 1532 flags.parse && console.log("parsing", elt); |
| 1533 this.parsingElement = elt; |
| 1534 }, |
| 1535 markParsingComplete: function(elt) { |
| 1536 elt.__importParsed = true; |
| 1537 this.markDynamicParsingComplete(elt); |
| 1538 if (elt.__importElement) { |
| 1539 elt.__importElement.__importParsed = true; |
| 1540 this.markDynamicParsingComplete(elt.__importElement); |
| 1541 } |
| 1542 this.parsingElement = null; |
| 1543 flags.parse && console.log("completed", elt); |
| 1544 }, |
| 1545 markDynamicParsingComplete: function(elt) { |
| 1546 var i = this.dynamicElements.indexOf(elt); |
| 1547 if (i >= 0) { |
| 1548 this.dynamicElements.splice(i, 1); |
| 1549 } |
| 1550 }, |
| 1551 parseImport: function(elt) { |
| 1552 elt.import = elt.__doc; |
| 1553 if (window.HTMLImports.__importsParsingHook) { |
| 1554 window.HTMLImports.__importsParsingHook(elt); |
| 1555 } |
| 1556 if (elt.import) { |
| 1557 elt.import.__importParsed = true; |
| 1558 } |
| 1559 this.markParsingComplete(elt); |
| 1560 if (elt.__resource && !elt.__error) { |
| 1561 elt.dispatchEvent(new CustomEvent("load", { |
| 1562 bubbles: false |
| 1563 })); |
| 1564 } else { |
| 1565 elt.dispatchEvent(new CustomEvent("error", { |
| 1566 bubbles: false |
| 1567 })); |
| 1568 } |
| 1569 if (elt.__pending) { |
| 1570 var fn; |
| 1571 while (elt.__pending.length) { |
| 1572 fn = elt.__pending.shift(); |
| 1573 if (fn) { |
| 1574 fn({ |
| 1575 target: elt |
| 1576 }); |
| 1577 } |
| 1578 } |
| 1579 } |
| 1580 this.parseNext(); |
| 1581 }, |
| 1582 parseLink: function(linkElt) { |
| 1583 if (nodeIsImport(linkElt)) { |
| 1584 this.parseImport(linkElt); |
| 1585 } else { |
| 1586 linkElt.href = linkElt.href; |
| 1587 this.parseGeneric(linkElt); |
| 1588 } |
| 1589 }, |
| 1590 parseStyle: function(elt) { |
| 1591 var src = elt; |
| 1592 elt = cloneStyle(elt); |
| 1593 src.__appliedElement = elt; |
| 1594 elt.__importElement = src; |
| 1595 this.parseGeneric(elt); |
| 1596 }, |
| 1597 parseGeneric: function(elt) { |
| 1598 this.trackElement(elt); |
| 1599 this.addElementToDocument(elt); |
| 1600 }, |
| 1601 rootImportForElement: function(elt) { |
| 1602 var n = elt; |
| 1603 while (n.ownerDocument.__importLink) { |
| 1604 n = n.ownerDocument.__importLink; |
| 1605 } |
| 1606 return n; |
| 1607 }, |
| 1608 addElementToDocument: function(elt) { |
| 1609 var port = this.rootImportForElement(elt.__importElement || elt); |
| 1610 port.parentNode.insertBefore(elt, port); |
| 1611 }, |
| 1612 trackElement: function(elt, callback) { |
| 1613 var self = this; |
| 1614 var done = function(e) { |
| 1615 elt.removeEventListener("load", done); |
| 1616 elt.removeEventListener("error", done); |
| 1617 if (callback) { |
| 1618 callback(e); |
| 1619 } |
| 1620 self.markParsingComplete(elt); |
| 1621 self.parseNext(); |
| 1622 }; |
| 1623 elt.addEventListener("load", done); |
| 1624 elt.addEventListener("error", done); |
| 1625 if (isIE && elt.localName === "style") { |
| 1626 var fakeLoad = false; |
| 1627 if (elt.textContent.indexOf("@import") == -1) { |
| 1628 fakeLoad = true; |
| 1629 } else if (elt.sheet) { |
| 1630 fakeLoad = true; |
| 1631 var csr = elt.sheet.cssRules; |
| 1632 var len = csr ? csr.length : 0; |
| 1633 for (var i = 0, r; i < len && (r = csr[i]); i++) { |
| 1634 if (r.type === CSSRule.IMPORT_RULE) { |
| 1635 fakeLoad = fakeLoad && Boolean(r.styleSheet); |
| 1636 } |
| 1637 } |
| 1638 } |
| 1639 if (fakeLoad) { |
| 1640 setTimeout(function() { |
| 1641 elt.dispatchEvent(new CustomEvent("load", { |
| 1642 bubbles: false |
| 1643 })); |
| 1644 }); |
| 1645 } |
| 1646 } |
| 1647 }, |
| 1648 parseScript: function(scriptElt) { |
| 1649 var script = document.createElement("script"); |
| 1650 script.__importElement = scriptElt; |
| 1651 script.src = scriptElt.src ? scriptElt.src : generateScriptDataUrl(scriptE
lt); |
| 1652 scope.currentScript = scriptElt; |
| 1653 this.trackElement(script, function(e) { |
| 1654 if (script.parentNode) { |
| 1655 script.parentNode.removeChild(script); |
| 1656 } |
| 1657 scope.currentScript = null; |
| 1658 }); |
| 1659 this.addElementToDocument(script); |
| 1660 }, |
| 1661 nextToParse: function() { |
| 1662 this._mayParse = []; |
| 1663 return !this.parsingElement && (this.nextToParseInDoc(rootDocument) || thi
s.nextToParseDynamic()); |
| 1664 }, |
| 1665 nextToParseInDoc: function(doc, link) { |
| 1666 if (doc && this._mayParse.indexOf(doc) < 0) { |
| 1667 this._mayParse.push(doc); |
| 1668 var nodes = doc.querySelectorAll(this.parseSelectorsForNode(doc)); |
| 1669 for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) { |
| 1670 if (!this.isParsed(n)) { |
| 1671 if (this.hasResource(n)) { |
| 1672 return nodeIsImport(n) ? this.nextToParseInDoc(n.__doc, n) : n; |
| 1673 } else { |
| 1674 return; |
| 1675 } |
| 1676 } |
| 1677 } |
| 1678 } |
| 1679 return link; |
| 1680 }, |
| 1681 nextToParseDynamic: function() { |
| 1682 return this.dynamicElements[0]; |
| 1683 }, |
| 1684 parseSelectorsForNode: function(node) { |
| 1685 var doc = node.ownerDocument || node; |
| 1686 return doc === rootDocument ? this.documentSelectors : this.importsSelecto
rs; |
| 1687 }, |
| 1688 isParsed: function(node) { |
| 1689 return node.__importParsed; |
| 1690 }, |
| 1691 needsDynamicParsing: function(elt) { |
| 1692 return this.dynamicElements.indexOf(elt) >= 0; |
| 1693 }, |
| 1694 hasResource: function(node) { |
| 1695 if (nodeIsImport(node) && node.__doc === undefined) { |
| 1696 return false; |
| 1697 } |
| 1698 return true; |
| 1699 } |
| 1700 }; |
| 1701 function nodeIsImport(elt) { |
| 1702 return elt.localName === "link" && elt.rel === IMPORT_LINK_TYPE; |
| 1703 } |
| 1704 function generateScriptDataUrl(script) { |
| 1705 var scriptContent = generateScriptContent(script); |
| 1706 return "data:text/javascript;charset=utf-8," + encodeURIComponent(scriptCont
ent); |
| 1707 } |
| 1708 function generateScriptContent(script) { |
| 1709 return script.textContent + generateSourceMapHint(script); |
| 1710 } |
| 1711 function generateSourceMapHint(script) { |
| 1712 var owner = script.ownerDocument; |
| 1713 owner.__importedScripts = owner.__importedScripts || 0; |
| 1714 var moniker = script.ownerDocument.baseURI; |
| 1715 var num = owner.__importedScripts ? "-" + owner.__importedScripts : ""; |
| 1716 owner.__importedScripts++; |
| 1717 return "\n//# sourceURL=" + moniker + num + ".js\n"; |
| 1718 } |
| 1719 function cloneStyle(style) { |
| 1720 var clone = style.ownerDocument.createElement("style"); |
| 1721 clone.textContent = style.textContent; |
| 1722 path.resolveUrlsInStyle(clone); |
| 1723 return clone; |
| 1724 } |
| 1725 scope.parser = importParser; |
| 1726 scope.IMPORT_SELECTOR = IMPORT_SELECTOR; |
| 1727 }); |
| 1728 |
| 1729 window.HTMLImports.addModule(function(scope) { |
| 1730 var flags = scope.flags; |
| 1731 var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE; |
| 1732 var IMPORT_SELECTOR = scope.IMPORT_SELECTOR; |
| 1733 var rootDocument = scope.rootDocument; |
| 1734 var Loader = scope.Loader; |
| 1735 var Observer = scope.Observer; |
| 1736 var parser = scope.parser; |
| 1737 var importer = { |
| 1738 documents: {}, |
| 1739 documentPreloadSelectors: IMPORT_SELECTOR, |
| 1740 importsPreloadSelectors: [ IMPORT_SELECTOR ].join(","), |
| 1741 loadNode: function(node) { |
| 1742 importLoader.addNode(node); |
| 1743 }, |
| 1744 loadSubtree: function(parent) { |
| 1745 var nodes = this.marshalNodes(parent); |
| 1746 importLoader.addNodes(nodes); |
| 1747 }, |
| 1748 marshalNodes: function(parent) { |
| 1749 return parent.querySelectorAll(this.loadSelectorsForNode(parent)); |
| 1750 }, |
| 1751 loadSelectorsForNode: function(node) { |
| 1752 var doc = node.ownerDocument || node; |
| 1753 return doc === rootDocument ? this.documentPreloadSelectors : this.imports
PreloadSelectors; |
| 1754 }, |
| 1755 loaded: function(url, elt, resource, err, redirectedUrl) { |
| 1756 flags.load && console.log("loaded", url, elt); |
| 1757 elt.__resource = resource; |
| 1758 elt.__error = err; |
| 1759 if (isImportLink(elt)) { |
| 1760 var doc = this.documents[url]; |
| 1761 if (doc === undefined) { |
| 1762 doc = err ? null : makeDocument(resource, redirectedUrl || url); |
| 1763 if (doc) { |
| 1764 doc.__importLink = elt; |
| 1765 this.bootDocument(doc); |
| 1766 } |
| 1767 this.documents[url] = doc; |
| 1768 } |
| 1769 elt.__doc = doc; |
| 1770 } |
| 1771 parser.parseNext(); |
| 1772 }, |
| 1773 bootDocument: function(doc) { |
| 1774 this.loadSubtree(doc); |
| 1775 this.observer.observe(doc); |
| 1776 parser.parseNext(); |
| 1777 }, |
| 1778 loadedAll: function() { |
| 1779 parser.parseNext(); |
| 1780 } |
| 1781 }; |
| 1782 var importLoader = new Loader(importer.loaded.bind(importer), importer.loadedA
ll.bind(importer)); |
| 1783 importer.observer = new Observer(); |
| 1784 function isImportLink(elt) { |
| 1785 return isLinkRel(elt, IMPORT_LINK_TYPE); |
| 1786 } |
| 1787 function isLinkRel(elt, rel) { |
| 1788 return elt.localName === "link" && elt.getAttribute("rel") === rel; |
| 1789 } |
| 1790 function hasBaseURIAccessor(doc) { |
| 1791 return !!Object.getOwnPropertyDescriptor(doc, "baseURI"); |
| 1792 } |
| 1793 function makeDocument(resource, url) { |
| 1794 var doc = document.implementation.createHTMLDocument(IMPORT_LINK_TYPE); |
| 1795 doc._URL = url; |
| 1796 var base = doc.createElement("base"); |
| 1797 base.setAttribute("href", url); |
| 1798 if (!doc.baseURI && !hasBaseURIAccessor(doc)) { |
| 1799 Object.defineProperty(doc, "baseURI", { |
| 1800 value: url |
| 1801 }); |
| 1802 } |
| 1803 var meta = doc.createElement("meta"); |
| 1804 meta.setAttribute("charset", "utf-8"); |
| 1805 doc.head.appendChild(meta); |
| 1806 doc.head.appendChild(base); |
| 1807 doc.body.innerHTML = resource; |
| 1808 if (window.HTMLTemplateElement && HTMLTemplateElement.bootstrap) { |
| 1809 HTMLTemplateElement.bootstrap(doc); |
| 1810 } |
| 1811 return doc; |
| 1812 } |
| 1813 if (!document.baseURI) { |
| 1814 var baseURIDescriptor = { |
| 1815 get: function() { |
| 1816 var base = document.querySelector("base"); |
| 1817 return base ? base.href : window.location.href; |
| 1818 }, |
| 1819 configurable: true |
| 1820 }; |
| 1821 Object.defineProperty(document, "baseURI", baseURIDescriptor); |
| 1822 Object.defineProperty(rootDocument, "baseURI", baseURIDescriptor); |
| 1823 } |
| 1824 scope.importer = importer; |
| 1825 scope.importLoader = importLoader; |
| 1826 }); |
| 1827 |
| 1828 window.HTMLImports.addModule(function(scope) { |
| 1829 var parser = scope.parser; |
| 1830 var importer = scope.importer; |
| 1831 var dynamic = { |
| 1832 added: function(nodes) { |
| 1833 var owner, parsed, loading; |
| 1834 for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) { |
| 1835 if (!owner) { |
| 1836 owner = n.ownerDocument; |
| 1837 parsed = parser.isParsed(owner); |
| 1838 } |
| 1839 loading = this.shouldLoadNode(n); |
| 1840 if (loading) { |
| 1841 importer.loadNode(n); |
| 1842 } |
| 1843 if (this.shouldParseNode(n) && parsed) { |
| 1844 parser.parseDynamic(n, loading); |
| 1845 } |
| 1846 } |
| 1847 }, |
| 1848 shouldLoadNode: function(node) { |
| 1849 return node.nodeType === 1 && matches.call(node, importer.loadSelectorsFor
Node(node)); |
| 1850 }, |
| 1851 shouldParseNode: function(node) { |
| 1852 return node.nodeType === 1 && matches.call(node, parser.parseSelectorsForN
ode(node)); |
| 1853 } |
| 1854 }; |
| 1855 importer.observer.addCallback = dynamic.added.bind(dynamic); |
| 1856 var matches = HTMLElement.prototype.matches || HTMLElement.prototype.matchesSe
lector || HTMLElement.prototype.webkitMatchesSelector || HTMLElement.prototype.m
ozMatchesSelector || HTMLElement.prototype.msMatchesSelector; |
| 1857 }); |
| 1858 |
| 1859 (function(scope) { |
| 1860 var initializeModules = scope.initializeModules; |
| 1861 var isIE = scope.isIE; |
| 1862 if (scope.useNative) { |
| 1863 return; |
| 1864 } |
| 1865 initializeModules(); |
| 1866 var rootDocument = scope.rootDocument; |
| 1867 function bootstrap() { |
| 1868 window.HTMLImports.importer.bootDocument(rootDocument); |
| 1869 } |
| 1870 if (document.readyState === "complete" || document.readyState === "interactive
" && !window.attachEvent) { |
| 1871 bootstrap(); |
| 1872 } else { |
| 1873 document.addEventListener("DOMContentLoaded", bootstrap); |
| 1874 } |
| 1875 })(window.HTMLImports); |
| 1876 |
| 1877 window.CustomElements = window.CustomElements || { |
| 1878 flags: {} |
| 1879 }; |
| 1880 |
| 1881 (function(scope) { |
| 1882 var flags = scope.flags; |
| 1883 var modules = []; |
| 1884 var addModule = function(module) { |
| 1885 modules.push(module); |
| 1886 }; |
| 1887 var initializeModules = function() { |
| 1888 modules.forEach(function(module) { |
| 1889 module(scope); |
| 1890 }); |
| 1891 }; |
| 1892 scope.addModule = addModule; |
| 1893 scope.initializeModules = initializeModules; |
| 1894 scope.hasNative = Boolean(document.registerElement); |
| 1895 scope.isIE = /Trident/.test(navigator.userAgent); |
| 1896 scope.useNative = !flags.register && scope.hasNative && !window.ShadowDOMPolyf
ill && (!window.HTMLImports || window.HTMLImports.useNative); |
| 1897 })(window.CustomElements); |
| 1898 |
| 1899 window.CustomElements.addModule(function(scope) { |
| 1900 var IMPORT_LINK_TYPE = window.HTMLImports ? window.HTMLImports.IMPORT_LINK_TYP
E : "none"; |
| 1901 function forSubtree(node, cb) { |
| 1902 findAllElements(node, function(e) { |
| 1903 if (cb(e)) { |
| 1904 return true; |
| 1905 } |
| 1906 forRoots(e, cb); |
| 1907 }); |
| 1908 forRoots(node, cb); |
| 1909 } |
| 1910 function findAllElements(node, find, data) { |
| 1911 var e = node.firstElementChild; |
| 1912 if (!e) { |
| 1913 e = node.firstChild; |
| 1914 while (e && e.nodeType !== Node.ELEMENT_NODE) { |
| 1915 e = e.nextSibling; |
| 1916 } |
| 1917 } |
| 1918 while (e) { |
| 1919 if (find(e, data) !== true) { |
| 1920 findAllElements(e, find, data); |
| 1921 } |
| 1922 e = e.nextElementSibling; |
| 1923 } |
| 1924 return null; |
| 1925 } |
| 1926 function forRoots(node, cb) { |
| 1927 var root = node.shadowRoot; |
| 1928 while (root) { |
| 1929 forSubtree(root, cb); |
| 1930 root = root.olderShadowRoot; |
| 1931 } |
| 1932 } |
| 1933 function forDocumentTree(doc, cb) { |
| 1934 _forDocumentTree(doc, cb, []); |
| 1935 } |
| 1936 function _forDocumentTree(doc, cb, processingDocuments) { |
| 1937 doc = window.wrap(doc); |
| 1938 if (processingDocuments.indexOf(doc) >= 0) { |
| 1939 return; |
| 1940 } |
| 1941 processingDocuments.push(doc); |
| 1942 var imports = doc.querySelectorAll("link[rel=" + IMPORT_LINK_TYPE + "]"); |
| 1943 for (var i = 0, l = imports.length, n; i < l && (n = imports[i]); i++) { |
| 1944 if (n.import) { |
| 1945 _forDocumentTree(n.import, cb, processingDocuments); |
| 1946 } |
| 1947 } |
| 1948 cb(doc); |
| 1949 } |
| 1950 scope.forDocumentTree = forDocumentTree; |
| 1951 scope.forSubtree = forSubtree; |
| 1952 }); |
| 1953 |
| 1954 window.CustomElements.addModule(function(scope) { |
| 1955 var flags = scope.flags; |
| 1956 var forSubtree = scope.forSubtree; |
| 1957 var forDocumentTree = scope.forDocumentTree; |
| 1958 function addedNode(node, isAttached) { |
| 1959 return added(node, isAttached) || addedSubtree(node, isAttached); |
| 1960 } |
| 1961 function added(node, isAttached) { |
| 1962 if (scope.upgrade(node, isAttached)) { |
| 1963 return true; |
| 1964 } |
| 1965 if (isAttached) { |
| 1966 attached(node); |
| 1967 } |
| 1968 } |
| 1969 function addedSubtree(node, isAttached) { |
| 1970 forSubtree(node, function(e) { |
| 1971 if (added(e, isAttached)) { |
| 1972 return true; |
| 1973 } |
| 1974 }); |
| 1975 } |
| 1976 var hasThrottledAttached = window.MutationObserver._isPolyfilled && flags["thr
ottle-attached"]; |
| 1977 scope.hasPolyfillMutations = hasThrottledAttached; |
| 1978 scope.hasThrottledAttached = hasThrottledAttached; |
| 1979 var isPendingMutations = false; |
| 1980 var pendingMutations = []; |
| 1981 function deferMutation(fn) { |
| 1982 pendingMutations.push(fn); |
| 1983 if (!isPendingMutations) { |
| 1984 isPendingMutations = true; |
| 1985 setTimeout(takeMutations); |
| 1986 } |
| 1987 } |
| 1988 function takeMutations() { |
| 1989 isPendingMutations = false; |
| 1990 var $p = pendingMutations; |
| 1991 for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) { |
| 1992 p(); |
| 1993 } |
| 1994 pendingMutations = []; |
| 1995 } |
| 1996 function attached(element) { |
| 1997 if (hasThrottledAttached) { |
| 1998 deferMutation(function() { |
| 1999 _attached(element); |
| 2000 }); |
| 2001 } else { |
| 2002 _attached(element); |
| 2003 } |
| 2004 } |
| 2005 function _attached(element) { |
| 2006 if (element.__upgraded__ && !element.__attached) { |
| 2007 element.__attached = true; |
| 2008 if (element.attachedCallback) { |
| 2009 element.attachedCallback(); |
| 2010 } |
| 2011 } |
| 2012 } |
| 2013 function detachedNode(node) { |
| 2014 detached(node); |
| 2015 forSubtree(node, function(e) { |
| 2016 detached(e); |
| 2017 }); |
| 2018 } |
| 2019 function detached(element) { |
| 2020 if (hasThrottledAttached) { |
| 2021 deferMutation(function() { |
| 2022 _detached(element); |
| 2023 }); |
| 2024 } else { |
| 2025 _detached(element); |
| 2026 } |
| 2027 } |
| 2028 function _detached(element) { |
| 2029 if (element.__upgraded__ && element.__attached) { |
| 2030 element.__attached = false; |
| 2031 if (element.detachedCallback) { |
| 2032 element.detachedCallback(); |
| 2033 } |
| 2034 } |
| 2035 } |
| 2036 function inDocument(element) { |
| 2037 var p = element; |
| 2038 var doc = window.wrap(document); |
| 2039 while (p) { |
| 2040 if (p == doc) { |
| 2041 return true; |
| 2042 } |
| 2043 p = p.parentNode || p.nodeType === Node.DOCUMENT_FRAGMENT_NODE && p.host; |
| 2044 } |
| 2045 } |
| 2046 function watchShadow(node) { |
| 2047 if (node.shadowRoot && !node.shadowRoot.__watched) { |
| 2048 flags.dom && console.log("watching shadow-root for: ", node.localName); |
| 2049 var root = node.shadowRoot; |
| 2050 while (root) { |
| 2051 observe(root); |
| 2052 root = root.olderShadowRoot; |
| 2053 } |
| 2054 } |
| 2055 } |
| 2056 function handler(root, mutations) { |
| 2057 if (flags.dom) { |
| 2058 var mx = mutations[0]; |
| 2059 if (mx && mx.type === "childList" && mx.addedNodes) { |
| 2060 if (mx.addedNodes) { |
| 2061 var d = mx.addedNodes[0]; |
| 2062 while (d && d !== document && !d.host) { |
| 2063 d = d.parentNode; |
| 2064 } |
| 2065 var u = d && (d.URL || d._URL || d.host && d.host.localName) || ""; |
| 2066 u = u.split("/?").shift().split("/").pop(); |
| 2067 } |
| 2068 } |
| 2069 console.group("mutations (%d) [%s]", mutations.length, u || ""); |
| 2070 } |
| 2071 var isAttached = inDocument(root); |
| 2072 mutations.forEach(function(mx) { |
| 2073 if (mx.type === "childList") { |
| 2074 forEach(mx.addedNodes, function(n) { |
| 2075 if (!n.localName) { |
| 2076 return; |
| 2077 } |
| 2078 addedNode(n, isAttached); |
| 2079 }); |
| 2080 forEach(mx.removedNodes, function(n) { |
| 2081 if (!n.localName) { |
| 2082 return; |
| 2083 } |
| 2084 detachedNode(n); |
| 2085 }); |
| 2086 } |
| 2087 }); |
| 2088 flags.dom && console.groupEnd(); |
| 2089 } |
| 2090 function takeRecords(node) { |
| 2091 node = window.wrap(node); |
| 2092 if (!node) { |
| 2093 node = window.wrap(document); |
| 2094 } |
| 2095 while (node.parentNode) { |
| 2096 node = node.parentNode; |
| 2097 } |
| 2098 var observer = node.__observer; |
| 2099 if (observer) { |
| 2100 handler(node, observer.takeRecords()); |
| 2101 takeMutations(); |
| 2102 } |
| 2103 } |
| 2104 var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach); |
| 2105 function observe(inRoot) { |
| 2106 if (inRoot.__observer) { |
| 2107 return; |
| 2108 } |
| 2109 var observer = new MutationObserver(handler.bind(this, inRoot)); |
| 2110 observer.observe(inRoot, { |
| 2111 childList: true, |
| 2112 subtree: true |
| 2113 }); |
| 2114 inRoot.__observer = observer; |
| 2115 } |
| 2116 function upgradeDocument(doc) { |
| 2117 doc = window.wrap(doc); |
| 2118 flags.dom && console.group("upgradeDocument: ", doc.baseURI.split("/").pop()
); |
| 2119 var isMainDocument = doc === window.wrap(document); |
| 2120 addedNode(doc, isMainDocument); |
| 2121 observe(doc); |
| 2122 flags.dom && console.groupEnd(); |
| 2123 } |
| 2124 function upgradeDocumentTree(doc) { |
| 2125 forDocumentTree(doc, upgradeDocument); |
| 2126 } |
| 2127 var originalCreateShadowRoot = Element.prototype.createShadowRoot; |
| 2128 if (originalCreateShadowRoot) { |
| 2129 Element.prototype.createShadowRoot = function() { |
| 2130 var root = originalCreateShadowRoot.call(this); |
| 2131 window.CustomElements.watchShadow(this); |
| 2132 return root; |
| 2133 }; |
| 2134 } |
| 2135 scope.watchShadow = watchShadow; |
| 2136 scope.upgradeDocumentTree = upgradeDocumentTree; |
| 2137 scope.upgradeDocument = upgradeDocument; |
| 2138 scope.upgradeSubtree = addedSubtree; |
| 2139 scope.upgradeAll = addedNode; |
| 2140 scope.attached = attached; |
| 2141 scope.takeRecords = takeRecords; |
| 2142 }); |
| 2143 |
| 2144 window.CustomElements.addModule(function(scope) { |
| 2145 var flags = scope.flags; |
| 2146 function upgrade(node, isAttached) { |
| 2147 if (node.localName === "template") { |
| 2148 if (window.HTMLTemplateElement && HTMLTemplateElement.decorate) { |
| 2149 HTMLTemplateElement.decorate(node); |
| 2150 } |
| 2151 } |
| 2152 if (!node.__upgraded__ && node.nodeType === Node.ELEMENT_NODE) { |
| 2153 var is = node.getAttribute("is"); |
| 2154 var definition = scope.getRegisteredDefinition(node.localName) || scope.ge
tRegisteredDefinition(is); |
| 2155 if (definition) { |
| 2156 if (is && definition.tag == node.localName || !is && !definition.extends
) { |
| 2157 return upgradeWithDefinition(node, definition, isAttached); |
| 2158 } |
| 2159 } |
| 2160 } |
| 2161 } |
| 2162 function upgradeWithDefinition(element, definition, isAttached) { |
| 2163 flags.upgrade && console.group("upgrade:", element.localName); |
| 2164 if (definition.is) { |
| 2165 element.setAttribute("is", definition.is); |
| 2166 } |
| 2167 implementPrototype(element, definition); |
| 2168 element.__upgraded__ = true; |
| 2169 created(element); |
| 2170 if (isAttached) { |
| 2171 scope.attached(element); |
| 2172 } |
| 2173 scope.upgradeSubtree(element, isAttached); |
| 2174 flags.upgrade && console.groupEnd(); |
| 2175 return element; |
| 2176 } |
| 2177 function implementPrototype(element, definition) { |
| 2178 if (Object.__proto__) { |
| 2179 element.__proto__ = definition.prototype; |
| 2180 } else { |
| 2181 customMixin(element, definition.prototype, definition.native); |
| 2182 element.__proto__ = definition.prototype; |
| 2183 } |
| 2184 } |
| 2185 function customMixin(inTarget, inSrc, inNative) { |
| 2186 var used = {}; |
| 2187 var p = inSrc; |
| 2188 while (p !== inNative && p !== HTMLElement.prototype) { |
| 2189 var keys = Object.getOwnPropertyNames(p); |
| 2190 for (var i = 0, k; k = keys[i]; i++) { |
| 2191 if (!used[k]) { |
| 2192 Object.defineProperty(inTarget, k, Object.getOwnPropertyDescriptor(p,
k)); |
| 2193 used[k] = 1; |
| 2194 } |
| 2195 } |
| 2196 p = Object.getPrototypeOf(p); |
| 2197 } |
| 2198 } |
| 2199 function created(element) { |
| 2200 if (element.createdCallback) { |
| 2201 element.createdCallback(); |
| 2202 } |
| 2203 } |
| 2204 scope.upgrade = upgrade; |
| 2205 scope.upgradeWithDefinition = upgradeWithDefinition; |
| 2206 scope.implementPrototype = implementPrototype; |
| 2207 }); |
| 2208 |
| 2209 window.CustomElements.addModule(function(scope) { |
| 2210 var isIE = scope.isIE; |
| 2211 var upgradeDocumentTree = scope.upgradeDocumentTree; |
| 2212 var upgradeAll = scope.upgradeAll; |
| 2213 var upgradeWithDefinition = scope.upgradeWithDefinition; |
| 2214 var implementPrototype = scope.implementPrototype; |
| 2215 var useNative = scope.useNative; |
| 2216 function register(name, options) { |
| 2217 var definition = options || {}; |
| 2218 if (!name) { |
| 2219 throw new Error("document.registerElement: first argument `name` must not
be empty"); |
| 2220 } |
| 2221 if (name.indexOf("-") < 0) { |
| 2222 throw new Error("document.registerElement: first argument ('name') must co
ntain a dash ('-'). Argument provided was '" + String(name) + "'."); |
| 2223 } |
| 2224 if (isReservedTag(name)) { |
| 2225 throw new Error("Failed to execute 'registerElement' on 'Document': Regist
ration failed for type '" + String(name) + "'. The type name is invalid."); |
| 2226 } |
| 2227 if (getRegisteredDefinition(name)) { |
| 2228 throw new Error("DuplicateDefinitionError: a type with name '" + String(na
me) + "' is already registered"); |
| 2229 } |
| 2230 if (!definition.prototype) { |
| 2231 definition.prototype = Object.create(HTMLElement.prototype); |
| 2232 } |
| 2233 definition.__name = name.toLowerCase(); |
| 2234 definition.lifecycle = definition.lifecycle || {}; |
| 2235 definition.ancestry = ancestry(definition.extends); |
| 2236 resolveTagName(definition); |
| 2237 resolvePrototypeChain(definition); |
| 2238 overrideAttributeApi(definition.prototype); |
| 2239 registerDefinition(definition.__name, definition); |
| 2240 definition.ctor = generateConstructor(definition); |
| 2241 definition.ctor.prototype = definition.prototype; |
| 2242 definition.prototype.constructor = definition.ctor; |
| 2243 if (scope.ready) { |
| 2244 upgradeDocumentTree(document); |
| 2245 } |
| 2246 return definition.ctor; |
| 2247 } |
| 2248 function overrideAttributeApi(prototype) { |
| 2249 if (prototype.setAttribute._polyfilled) { |
| 2250 return; |
| 2251 } |
| 2252 var setAttribute = prototype.setAttribute; |
| 2253 prototype.setAttribute = function(name, value) { |
| 2254 changeAttribute.call(this, name, value, setAttribute); |
| 2255 }; |
| 2256 var removeAttribute = prototype.removeAttribute; |
| 2257 prototype.removeAttribute = function(name) { |
| 2258 changeAttribute.call(this, name, null, removeAttribute); |
| 2259 }; |
| 2260 prototype.setAttribute._polyfilled = true; |
| 2261 } |
| 2262 function changeAttribute(name, value, operation) { |
| 2263 name = name.toLowerCase(); |
| 2264 var oldValue = this.getAttribute(name); |
| 2265 operation.apply(this, arguments); |
| 2266 var newValue = this.getAttribute(name); |
| 2267 if (this.attributeChangedCallback && newValue !== oldValue) { |
| 2268 this.attributeChangedCallback(name, oldValue, newValue); |
| 2269 } |
| 2270 } |
| 2271 function isReservedTag(name) { |
| 2272 for (var i = 0; i < reservedTagList.length; i++) { |
| 2273 if (name === reservedTagList[i]) { |
| 2274 return true; |
| 2275 } |
| 2276 } |
| 2277 } |
| 2278 var reservedTagList = [ "annotation-xml", "color-profile", "font-face", "font-
face-src", "font-face-uri", "font-face-format", "font-face-name", "missing-glyph
" ]; |
| 2279 function ancestry(extnds) { |
| 2280 var extendee = getRegisteredDefinition(extnds); |
| 2281 if (extendee) { |
| 2282 return ancestry(extendee.extends).concat([ extendee ]); |
| 2283 } |
| 2284 return []; |
| 2285 } |
| 2286 function resolveTagName(definition) { |
| 2287 var baseTag = definition.extends; |
| 2288 for (var i = 0, a; a = definition.ancestry[i]; i++) { |
| 2289 baseTag = a.is && a.tag; |
| 2290 } |
| 2291 definition.tag = baseTag || definition.__name; |
| 2292 if (baseTag) { |
| 2293 definition.is = definition.__name; |
| 2294 } |
| 2295 } |
| 2296 function resolvePrototypeChain(definition) { |
| 2297 if (!Object.__proto__) { |
| 2298 var nativePrototype = HTMLElement.prototype; |
| 2299 if (definition.is) { |
| 2300 var inst = document.createElement(definition.tag); |
| 2301 nativePrototype = Object.getPrototypeOf(inst); |
| 2302 } |
| 2303 var proto = definition.prototype, ancestor; |
| 2304 var foundPrototype = false; |
| 2305 while (proto) { |
| 2306 if (proto == nativePrototype) { |
| 2307 foundPrototype = true; |
| 2308 } |
| 2309 ancestor = Object.getPrototypeOf(proto); |
| 2310 if (ancestor) { |
| 2311 proto.__proto__ = ancestor; |
| 2312 } |
| 2313 proto = ancestor; |
| 2314 } |
| 2315 if (!foundPrototype) { |
| 2316 console.warn(definition.tag + " prototype not found in prototype chain f
or " + definition.is); |
| 2317 } |
| 2318 definition.native = nativePrototype; |
| 2319 } |
| 2320 } |
| 2321 function instantiate(definition) { |
| 2322 return upgradeWithDefinition(domCreateElement(definition.tag), definition); |
| 2323 } |
| 2324 var registry = {}; |
| 2325 function getRegisteredDefinition(name) { |
| 2326 if (name) { |
| 2327 return registry[name.toLowerCase()]; |
| 2328 } |
| 2329 } |
| 2330 function registerDefinition(name, definition) { |
| 2331 registry[name] = definition; |
| 2332 } |
| 2333 function generateConstructor(definition) { |
| 2334 return function() { |
| 2335 return instantiate(definition); |
| 2336 }; |
| 2337 } |
| 2338 var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml"; |
| 2339 function createElementNS(namespace, tag, typeExtension) { |
| 2340 if (namespace === HTML_NAMESPACE) { |
| 2341 return createElement(tag, typeExtension); |
| 2342 } else { |
| 2343 return domCreateElementNS(namespace, tag); |
| 2344 } |
| 2345 } |
| 2346 function createElement(tag, typeExtension) { |
| 2347 if (tag) { |
| 2348 tag = tag.toLowerCase(); |
| 2349 } |
| 2350 if (typeExtension) { |
| 2351 typeExtension = typeExtension.toLowerCase(); |
| 2352 } |
| 2353 var definition = getRegisteredDefinition(typeExtension || tag); |
| 2354 if (definition) { |
| 2355 if (tag == definition.tag && typeExtension == definition.is) { |
| 2356 return new definition.ctor(); |
| 2357 } |
| 2358 if (!typeExtension && !definition.is) { |
| 2359 return new definition.ctor(); |
| 2360 } |
| 2361 } |
| 2362 var element; |
| 2363 if (typeExtension) { |
| 2364 element = createElement(tag); |
| 2365 element.setAttribute("is", typeExtension); |
| 2366 return element; |
| 2367 } |
| 2368 element = domCreateElement(tag); |
| 2369 if (tag.indexOf("-") >= 0) { |
| 2370 implementPrototype(element, HTMLElement); |
| 2371 } |
| 2372 return element; |
| 2373 } |
| 2374 var domCreateElement = document.createElement.bind(document); |
| 2375 var domCreateElementNS = document.createElementNS.bind(document); |
| 2376 var isInstance; |
| 2377 if (!Object.__proto__ && !useNative) { |
| 2378 isInstance = function(obj, ctor) { |
| 2379 if (obj instanceof ctor) { |
| 2380 return true; |
| 2381 } |
| 2382 var p = obj; |
| 2383 while (p) { |
| 2384 if (p === ctor.prototype) { |
| 2385 return true; |
| 2386 } |
| 2387 p = p.__proto__; |
| 2388 } |
| 2389 return false; |
| 2390 }; |
| 2391 } else { |
| 2392 isInstance = function(obj, base) { |
| 2393 return obj instanceof base; |
| 2394 }; |
| 2395 } |
| 2396 function wrapDomMethodToForceUpgrade(obj, methodName) { |
| 2397 var orig = obj[methodName]; |
| 2398 obj[methodName] = function() { |
| 2399 var n = orig.apply(this, arguments); |
| 2400 upgradeAll(n); |
| 2401 return n; |
| 2402 }; |
| 2403 } |
| 2404 wrapDomMethodToForceUpgrade(Node.prototype, "cloneNode"); |
| 2405 wrapDomMethodToForceUpgrade(document, "importNode"); |
| 2406 if (isIE) { |
| 2407 (function() { |
| 2408 var importNode = document.importNode; |
| 2409 document.importNode = function() { |
| 2410 var n = importNode.apply(document, arguments); |
| 2411 if (n.nodeType == n.DOCUMENT_FRAGMENT_NODE) { |
| 2412 var f = document.createDocumentFragment(); |
| 2413 f.appendChild(n); |
| 2414 return f; |
| 2415 } else { |
| 2416 return n; |
| 2417 } |
| 2418 }; |
| 2419 })(); |
| 2420 } |
| 2421 document.registerElement = register; |
| 2422 document.createElement = createElement; |
| 2423 document.createElementNS = createElementNS; |
| 2424 scope.registry = registry; |
| 2425 scope.instanceof = isInstance; |
| 2426 scope.reservedTagList = reservedTagList; |
| 2427 scope.getRegisteredDefinition = getRegisteredDefinition; |
| 2428 document.register = document.registerElement; |
| 2429 }); |
| 2430 |
| 2431 (function(scope) { |
| 2432 var useNative = scope.useNative; |
| 2433 var initializeModules = scope.initializeModules; |
| 2434 var isIE = scope.isIE; |
| 2435 if (useNative) { |
| 2436 var nop = function() {}; |
| 2437 scope.watchShadow = nop; |
| 2438 scope.upgrade = nop; |
| 2439 scope.upgradeAll = nop; |
| 2440 scope.upgradeDocumentTree = nop; |
| 2441 scope.upgradeSubtree = nop; |
| 2442 scope.takeRecords = nop; |
| 2443 scope.instanceof = function(obj, base) { |
| 2444 return obj instanceof base; |
| 2445 }; |
| 2446 } else { |
| 2447 initializeModules(); |
| 2448 } |
| 2449 var upgradeDocumentTree = scope.upgradeDocumentTree; |
| 2450 var upgradeDocument = scope.upgradeDocument; |
| 2451 if (!window.wrap) { |
| 2452 if (window.ShadowDOMPolyfill) { |
| 2453 window.wrap = window.ShadowDOMPolyfill.wrapIfNeeded; |
| 2454 window.unwrap = window.ShadowDOMPolyfill.unwrapIfNeeded; |
| 2455 } else { |
| 2456 window.wrap = window.unwrap = function(node) { |
| 2457 return node; |
| 2458 }; |
| 2459 } |
| 2460 } |
| 2461 if (window.HTMLImports) { |
| 2462 window.HTMLImports.__importsParsingHook = function(elt) { |
| 2463 if (elt.import) { |
| 2464 upgradeDocument(wrap(elt.import)); |
| 2465 } |
| 2466 }; |
| 2467 } |
| 2468 function bootstrap() { |
| 2469 upgradeDocumentTree(window.wrap(document)); |
| 2470 window.CustomElements.ready = true; |
| 2471 var requestAnimationFrame = window.requestAnimationFrame || function(f) { |
| 2472 setTimeout(f, 16); |
| 2473 }; |
| 2474 requestAnimationFrame(function() { |
| 2475 setTimeout(function() { |
| 2476 window.CustomElements.readyTime = Date.now(); |
| 2477 if (window.HTMLImports) { |
| 2478 window.CustomElements.elapsed = window.CustomElements.readyTime - wind
ow.HTMLImports.readyTime; |
| 2479 } |
| 2480 document.dispatchEvent(new CustomEvent("WebComponentsReady", { |
| 2481 bubbles: true |
| 2482 })); |
| 2483 }); |
| 2484 }); |
| 2485 } |
| 2486 if (document.readyState === "complete" || scope.flags.eager) { |
| 2487 bootstrap(); |
| 2488 } else if (document.readyState === "interactive" && !window.attachEvent && (!w
indow.HTMLImports || window.HTMLImports.ready)) { |
| 2489 bootstrap(); |
| 2490 } else { |
| 2491 var loadEvent = window.HTMLImports && !window.HTMLImports.ready ? "HTMLImpor
tsLoaded" : "DOMContentLoaded"; |
| 2492 window.addEventListener(loadEvent, bootstrap); |
| 2493 } |
| 2494 })(window.CustomElements); |
| 2495 |
| 2496 (function(scope) { |
| 2497 var style = document.createElement("style"); |
| 2498 style.textContent = "" + "body {" + "transition: opacity ease-in 0.2s;" + " }
\n" + "body[unresolved] {" + "opacity: 0; display: block; overflow: hidden; posi
tion: relative;" + " } \n"; |
| 2499 var head = document.querySelector("head"); |
| 2500 head.insertBefore(style, head.firstChild); |
| 2501 })(window.WebComponents); |
OLD | NEW |