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.5.1-1 |
| 11 window.WebComponents = window.WebComponents || {}; |
| 12 |
| 13 (function(scope) { |
| 14 var flags = scope.flags || {}; |
| 15 var file = "webcomponents.js"; |
| 16 var script = document.querySelector('script[src*="' + file + '"]'); |
| 17 var flags = {}; |
| 18 if (!flags.noOpts) { |
| 19 location.search.slice(1).split("&").forEach(function(o) { |
| 20 o = o.split("="); |
| 21 o[0] && (flags[o[0]] = o[1] || true); |
| 22 }); |
| 23 if (script) { |
| 24 for (var i = 0, a; a = script.attributes[i]; i++) { |
| 25 if (a.name !== "src") { |
| 26 flags[a.name] = a.value || true; |
| 27 } |
| 28 } |
| 29 } |
| 30 if (flags.log) { |
| 31 var parts = flags.log.split(","); |
| 32 flags.log = {}; |
| 33 parts.forEach(function(f) { |
| 34 flags.log[f] = true; |
| 35 }); |
| 36 } else { |
| 37 flags.log = {}; |
| 38 } |
| 39 } |
| 40 flags.shadow = flags.shadow || flags.shadowdom || flags.polyfill; |
| 41 if (flags.shadow === "native") { |
| 42 flags.shadow = false; |
| 43 } else { |
| 44 flags.shadow = flags.shadow || !HTMLElement.prototype.createShadowRoot; |
| 45 } |
| 46 if (flags.register) { |
| 47 window.CustomElements = window.CustomElements || { |
| 48 flags: {} |
| 49 }; |
| 50 window.CustomElements.flags.register = flags.register; |
| 51 } |
| 52 scope.flags = flags; |
| 53 })(WebComponents); |
| 54 |
| 55 if (WebComponents.flags.shadow) { |
| 56 if (typeof WeakMap === "undefined") { |
| 57 (function() { |
| 58 var defineProperty = Object.defineProperty; |
| 59 var counter = Date.now() % 1e9; |
| 60 var WeakMap = function() { |
| 61 this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__"); |
| 62 }; |
| 63 WeakMap.prototype = { |
| 64 set: function(key, value) { |
| 65 var entry = key[this.name]; |
| 66 if (entry && entry[0] === key) entry[1] = value; else defineProperty(k
ey, this.name, { |
| 67 value: [ key, value ], |
| 68 writable: true |
| 69 }); |
| 70 return this; |
| 71 }, |
| 72 get: function(key) { |
| 73 var entry; |
| 74 return (entry = key[this.name]) && entry[0] === key ? entry[1] : undef
ined; |
| 75 }, |
| 76 "delete": function(key) { |
| 77 var entry = key[this.name]; |
| 78 if (!entry || entry[0] !== key) return false; |
| 79 entry[0] = entry[1] = undefined; |
| 80 return true; |
| 81 }, |
| 82 has: function(key) { |
| 83 var entry = key[this.name]; |
| 84 if (!entry) return false; |
| 85 return entry[0] === key; |
| 86 } |
| 87 }; |
| 88 window.WeakMap = WeakMap; |
| 89 })(); |
| 90 } |
| 91 window.ShadowDOMPolyfill = {}; |
| 92 (function(scope) { |
| 93 "use strict"; |
| 94 var constructorTable = new WeakMap(); |
| 95 var nativePrototypeTable = new WeakMap(); |
| 96 var wrappers = Object.create(null); |
| 97 function detectEval() { |
| 98 if (typeof chrome !== "undefined" && chrome.app && chrome.app.runtime) { |
| 99 return false; |
| 100 } |
| 101 if (navigator.getDeviceStorage) { |
| 102 return false; |
| 103 } |
| 104 try { |
| 105 var f = new Function("return true;"); |
| 106 return f(); |
| 107 } catch (ex) { |
| 108 return false; |
| 109 } |
| 110 } |
| 111 var hasEval = detectEval(); |
| 112 function assert(b) { |
| 113 if (!b) throw new Error("Assertion failed"); |
| 114 } |
| 115 var defineProperty = Object.defineProperty; |
| 116 var getOwnPropertyNames = Object.getOwnPropertyNames; |
| 117 var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; |
| 118 function mixin(to, from) { |
| 119 var names = getOwnPropertyNames(from); |
| 120 for (var i = 0; i < names.length; i++) { |
| 121 var name = names[i]; |
| 122 defineProperty(to, name, getOwnPropertyDescriptor(from, name)); |
| 123 } |
| 124 return to; |
| 125 } |
| 126 function mixinStatics(to, from) { |
| 127 var names = getOwnPropertyNames(from); |
| 128 for (var i = 0; i < names.length; i++) { |
| 129 var name = names[i]; |
| 130 switch (name) { |
| 131 case "arguments": |
| 132 case "caller": |
| 133 case "length": |
| 134 case "name": |
| 135 case "prototype": |
| 136 case "toString": |
| 137 continue; |
| 138 } |
| 139 defineProperty(to, name, getOwnPropertyDescriptor(from, name)); |
| 140 } |
| 141 return to; |
| 142 } |
| 143 function oneOf(object, propertyNames) { |
| 144 for (var i = 0; i < propertyNames.length; i++) { |
| 145 if (propertyNames[i] in object) return propertyNames[i]; |
| 146 } |
| 147 } |
| 148 var nonEnumerableDataDescriptor = { |
| 149 value: undefined, |
| 150 configurable: true, |
| 151 enumerable: false, |
| 152 writable: true |
| 153 }; |
| 154 function defineNonEnumerableDataProperty(object, name, value) { |
| 155 nonEnumerableDataDescriptor.value = value; |
| 156 defineProperty(object, name, nonEnumerableDataDescriptor); |
| 157 } |
| 158 getOwnPropertyNames(window); |
| 159 function getWrapperConstructor(node) { |
| 160 var nativePrototype = node.__proto__ || Object.getPrototypeOf(node); |
| 161 var wrapperConstructor = constructorTable.get(nativePrototype); |
| 162 if (wrapperConstructor) return wrapperConstructor; |
| 163 var parentWrapperConstructor = getWrapperConstructor(nativePrototype); |
| 164 var GeneratedWrapper = createWrapperConstructor(parentWrapperConstructor); |
| 165 registerInternal(nativePrototype, GeneratedWrapper, node); |
| 166 return GeneratedWrapper; |
| 167 } |
| 168 function addForwardingProperties(nativePrototype, wrapperPrototype) { |
| 169 installProperty(nativePrototype, wrapperPrototype, true); |
| 170 } |
| 171 function registerInstanceProperties(wrapperPrototype, instanceObject) { |
| 172 installProperty(instanceObject, wrapperPrototype, false); |
| 173 } |
| 174 var isFirefox = /Firefox/.test(navigator.userAgent); |
| 175 var dummyDescriptor = { |
| 176 get: function() {}, |
| 177 set: function(v) {}, |
| 178 configurable: true, |
| 179 enumerable: true |
| 180 }; |
| 181 function isEventHandlerName(name) { |
| 182 return /^on[a-z]+$/.test(name); |
| 183 } |
| 184 function isIdentifierName(name) { |
| 185 return /^\w[a-zA-Z_0-9]*$/.test(name); |
| 186 } |
| 187 function getGetter(name) { |
| 188 return hasEval && isIdentifierName(name) ? new Function("return this.__imp
l4cf1e782hg__." + name) : function() { |
| 189 return this.__impl4cf1e782hg__[name]; |
| 190 }; |
| 191 } |
| 192 function getSetter(name) { |
| 193 return hasEval && isIdentifierName(name) ? new Function("v", "this.__impl4
cf1e782hg__." + name + " = v") : function(v) { |
| 194 this.__impl4cf1e782hg__[name] = v; |
| 195 }; |
| 196 } |
| 197 function getMethod(name) { |
| 198 return hasEval && isIdentifierName(name) ? new Function("return this.__imp
l4cf1e782hg__." + name + ".apply(this.__impl4cf1e782hg__, arguments)") : functio
n() { |
| 199 return this.__impl4cf1e782hg__[name].apply(this.__impl4cf1e782hg__, argu
ments); |
| 200 }; |
| 201 } |
| 202 function getDescriptor(source, name) { |
| 203 try { |
| 204 return Object.getOwnPropertyDescriptor(source, name); |
| 205 } catch (ex) { |
| 206 return dummyDescriptor; |
| 207 } |
| 208 } |
| 209 var isBrokenSafari = function() { |
| 210 var descr = Object.getOwnPropertyDescriptor(Node.prototype, "nodeType"); |
| 211 return descr && !descr.get && !descr.set; |
| 212 }(); |
| 213 function installProperty(source, target, allowMethod, opt_blacklist) { |
| 214 var names = getOwnPropertyNames(source); |
| 215 for (var i = 0; i < names.length; i++) { |
| 216 var name = names[i]; |
| 217 if (name === "polymerBlackList_") continue; |
| 218 if (name in target) continue; |
| 219 if (source.polymerBlackList_ && source.polymerBlackList_[name]) continue
; |
| 220 if (isFirefox) { |
| 221 source.__lookupGetter__(name); |
| 222 } |
| 223 var descriptor = getDescriptor(source, name); |
| 224 var getter, setter; |
| 225 if (allowMethod && typeof descriptor.value === "function") { |
| 226 target[name] = getMethod(name); |
| 227 continue; |
| 228 } |
| 229 var isEvent = isEventHandlerName(name); |
| 230 if (isEvent) getter = scope.getEventHandlerGetter(name); else getter = g
etGetter(name); |
| 231 if (descriptor.writable || descriptor.set || isBrokenSafari) { |
| 232 if (isEvent) setter = scope.getEventHandlerSetter(name); else setter =
getSetter(name); |
| 233 } |
| 234 defineProperty(target, name, { |
| 235 get: getter, |
| 236 set: setter, |
| 237 configurable: descriptor.configurable, |
| 238 enumerable: descriptor.enumerable |
| 239 }); |
| 240 } |
| 241 } |
| 242 function register(nativeConstructor, wrapperConstructor, opt_instance) { |
| 243 var nativePrototype = nativeConstructor.prototype; |
| 244 registerInternal(nativePrototype, wrapperConstructor, opt_instance); |
| 245 mixinStatics(wrapperConstructor, nativeConstructor); |
| 246 } |
| 247 function registerInternal(nativePrototype, wrapperConstructor, opt_instance)
{ |
| 248 var wrapperPrototype = wrapperConstructor.prototype; |
| 249 assert(constructorTable.get(nativePrototype) === undefined); |
| 250 constructorTable.set(nativePrototype, wrapperConstructor); |
| 251 nativePrototypeTable.set(wrapperPrototype, nativePrototype); |
| 252 addForwardingProperties(nativePrototype, wrapperPrototype); |
| 253 if (opt_instance) registerInstanceProperties(wrapperPrototype, opt_instanc
e); |
| 254 defineNonEnumerableDataProperty(wrapperPrototype, "constructor", wrapperCo
nstructor); |
| 255 wrapperConstructor.prototype = wrapperPrototype; |
| 256 } |
| 257 function isWrapperFor(wrapperConstructor, nativeConstructor) { |
| 258 return constructorTable.get(nativeConstructor.prototype) === wrapperConstr
uctor; |
| 259 } |
| 260 function registerObject(object) { |
| 261 var nativePrototype = Object.getPrototypeOf(object); |
| 262 var superWrapperConstructor = getWrapperConstructor(nativePrototype); |
| 263 var GeneratedWrapper = createWrapperConstructor(superWrapperConstructor); |
| 264 registerInternal(nativePrototype, GeneratedWrapper, object); |
| 265 return GeneratedWrapper; |
| 266 } |
| 267 function createWrapperConstructor(superWrapperConstructor) { |
| 268 function GeneratedWrapper(node) { |
| 269 superWrapperConstructor.call(this, node); |
| 270 } |
| 271 var p = Object.create(superWrapperConstructor.prototype); |
| 272 p.constructor = GeneratedWrapper; |
| 273 GeneratedWrapper.prototype = p; |
| 274 return GeneratedWrapper; |
| 275 } |
| 276 function isWrapper(object) { |
| 277 return object && object.__impl4cf1e782hg__; |
| 278 } |
| 279 function isNative(object) { |
| 280 return !isWrapper(object); |
| 281 } |
| 282 function wrap(impl) { |
| 283 if (impl === null) return null; |
| 284 assert(isNative(impl)); |
| 285 return impl.__wrapper8e3dd93a60__ || (impl.__wrapper8e3dd93a60__ = new (ge
tWrapperConstructor(impl))(impl)); |
| 286 } |
| 287 function unwrap(wrapper) { |
| 288 if (wrapper === null) return null; |
| 289 assert(isWrapper(wrapper)); |
| 290 return wrapper.__impl4cf1e782hg__; |
| 291 } |
| 292 function unsafeUnwrap(wrapper) { |
| 293 return wrapper.__impl4cf1e782hg__; |
| 294 } |
| 295 function setWrapper(impl, wrapper) { |
| 296 wrapper.__impl4cf1e782hg__ = impl; |
| 297 impl.__wrapper8e3dd93a60__ = wrapper; |
| 298 } |
| 299 function unwrapIfNeeded(object) { |
| 300 return object && isWrapper(object) ? unwrap(object) : object; |
| 301 } |
| 302 function wrapIfNeeded(object) { |
| 303 return object && !isWrapper(object) ? wrap(object) : object; |
| 304 } |
| 305 function rewrap(node, wrapper) { |
| 306 if (wrapper === null) return; |
| 307 assert(isNative(node)); |
| 308 assert(wrapper === undefined || isWrapper(wrapper)); |
| 309 node.__wrapper8e3dd93a60__ = wrapper; |
| 310 } |
| 311 var getterDescriptor = { |
| 312 get: undefined, |
| 313 configurable: true, |
| 314 enumerable: true |
| 315 }; |
| 316 function defineGetter(constructor, name, getter) { |
| 317 getterDescriptor.get = getter; |
| 318 defineProperty(constructor.prototype, name, getterDescriptor); |
| 319 } |
| 320 function defineWrapGetter(constructor, name) { |
| 321 defineGetter(constructor, name, function() { |
| 322 return wrap(this.__impl4cf1e782hg__[name]); |
| 323 }); |
| 324 } |
| 325 function forwardMethodsToWrapper(constructors, names) { |
| 326 constructors.forEach(function(constructor) { |
| 327 names.forEach(function(name) { |
| 328 constructor.prototype[name] = function() { |
| 329 var w = wrapIfNeeded(this); |
| 330 return w[name].apply(w, arguments); |
| 331 }; |
| 332 }); |
| 333 }); |
| 334 } |
| 335 scope.assert = assert; |
| 336 scope.constructorTable = constructorTable; |
| 337 scope.defineGetter = defineGetter; |
| 338 scope.defineWrapGetter = defineWrapGetter; |
| 339 scope.forwardMethodsToWrapper = forwardMethodsToWrapper; |
| 340 scope.isWrapper = isWrapper; |
| 341 scope.isWrapperFor = isWrapperFor; |
| 342 scope.mixin = mixin; |
| 343 scope.nativePrototypeTable = nativePrototypeTable; |
| 344 scope.oneOf = oneOf; |
| 345 scope.registerObject = registerObject; |
| 346 scope.registerWrapper = register; |
| 347 scope.rewrap = rewrap; |
| 348 scope.setWrapper = setWrapper; |
| 349 scope.unsafeUnwrap = unsafeUnwrap; |
| 350 scope.unwrap = unwrap; |
| 351 scope.unwrapIfNeeded = unwrapIfNeeded; |
| 352 scope.wrap = wrap; |
| 353 scope.wrapIfNeeded = wrapIfNeeded; |
| 354 scope.wrappers = wrappers; |
| 355 })(window.ShadowDOMPolyfill); |
| 356 (function(scope) { |
| 357 "use strict"; |
| 358 function newSplice(index, removed, addedCount) { |
| 359 return { |
| 360 index: index, |
| 361 removed: removed, |
| 362 addedCount: addedCount |
| 363 }; |
| 364 } |
| 365 var EDIT_LEAVE = 0; |
| 366 var EDIT_UPDATE = 1; |
| 367 var EDIT_ADD = 2; |
| 368 var EDIT_DELETE = 3; |
| 369 function ArraySplice() {} |
| 370 ArraySplice.prototype = { |
| 371 calcEditDistances: function(current, currentStart, currentEnd, old, oldSta
rt, oldEnd) { |
| 372 var rowCount = oldEnd - oldStart + 1; |
| 373 var columnCount = currentEnd - currentStart + 1; |
| 374 var distances = new Array(rowCount); |
| 375 for (var i = 0; i < rowCount; i++) { |
| 376 distances[i] = new Array(columnCount); |
| 377 distances[i][0] = i; |
| 378 } |
| 379 for (var j = 0; j < columnCount; j++) distances[0][j] = j; |
| 380 for (var i = 1; i < rowCount; i++) { |
| 381 for (var j = 1; j < columnCount; j++) { |
| 382 if (this.equals(current[currentStart + j - 1], old[oldStart + i - 1]
)) distances[i][j] = distances[i - 1][j - 1]; else { |
| 383 var north = distances[i - 1][j] + 1; |
| 384 var west = distances[i][j - 1] + 1; |
| 385 distances[i][j] = north < west ? north : west; |
| 386 } |
| 387 } |
| 388 } |
| 389 return distances; |
| 390 }, |
| 391 spliceOperationsFromEditDistances: function(distances) { |
| 392 var i = distances.length - 1; |
| 393 var j = distances[0].length - 1; |
| 394 var current = distances[i][j]; |
| 395 var edits = []; |
| 396 while (i > 0 || j > 0) { |
| 397 if (i == 0) { |
| 398 edits.push(EDIT_ADD); |
| 399 j--; |
| 400 continue; |
| 401 } |
| 402 if (j == 0) { |
| 403 edits.push(EDIT_DELETE); |
| 404 i--; |
| 405 continue; |
| 406 } |
| 407 var northWest = distances[i - 1][j - 1]; |
| 408 var west = distances[i - 1][j]; |
| 409 var north = distances[i][j - 1]; |
| 410 var min; |
| 411 if (west < north) min = west < northWest ? west : northWest; else min
= north < northWest ? north : northWest; |
| 412 if (min == northWest) { |
| 413 if (northWest == current) { |
| 414 edits.push(EDIT_LEAVE); |
| 415 } else { |
| 416 edits.push(EDIT_UPDATE); |
| 417 current = northWest; |
| 418 } |
| 419 i--; |
| 420 j--; |
| 421 } else if (min == west) { |
| 422 edits.push(EDIT_DELETE); |
| 423 i--; |
| 424 current = west; |
| 425 } else { |
| 426 edits.push(EDIT_ADD); |
| 427 j--; |
| 428 current = north; |
| 429 } |
| 430 } |
| 431 edits.reverse(); |
| 432 return edits; |
| 433 }, |
| 434 calcSplices: function(current, currentStart, currentEnd, old, oldStart, ol
dEnd) { |
| 435 var prefixCount = 0; |
| 436 var suffixCount = 0; |
| 437 var minLength = Math.min(currentEnd - currentStart, oldEnd - oldStart); |
| 438 if (currentStart == 0 && oldStart == 0) prefixCount = this.sharedPrefix(
current, old, minLength); |
| 439 if (currentEnd == current.length && oldEnd == old.length) suffixCount =
this.sharedSuffix(current, old, minLength - prefixCount); |
| 440 currentStart += prefixCount; |
| 441 oldStart += prefixCount; |
| 442 currentEnd -= suffixCount; |
| 443 oldEnd -= suffixCount; |
| 444 if (currentEnd - currentStart == 0 && oldEnd - oldStart == 0) return []; |
| 445 if (currentStart == currentEnd) { |
| 446 var splice = newSplice(currentStart, [], 0); |
| 447 while (oldStart < oldEnd) splice.removed.push(old[oldStart++]); |
| 448 return [ splice ]; |
| 449 } else if (oldStart == oldEnd) return [ newSplice(currentStart, [], curr
entEnd - currentStart) ]; |
| 450 var ops = this.spliceOperationsFromEditDistances(this.calcEditDistances(
current, currentStart, currentEnd, old, oldStart, oldEnd)); |
| 451 var splice = undefined; |
| 452 var splices = []; |
| 453 var index = currentStart; |
| 454 var oldIndex = oldStart; |
| 455 for (var i = 0; i < ops.length; i++) { |
| 456 switch (ops[i]) { |
| 457 case EDIT_LEAVE: |
| 458 if (splice) { |
| 459 splices.push(splice); |
| 460 splice = undefined; |
| 461 } |
| 462 index++; |
| 463 oldIndex++; |
| 464 break; |
| 465 |
| 466 case EDIT_UPDATE: |
| 467 if (!splice) splice = newSplice(index, [], 0); |
| 468 splice.addedCount++; |
| 469 index++; |
| 470 splice.removed.push(old[oldIndex]); |
| 471 oldIndex++; |
| 472 break; |
| 473 |
| 474 case EDIT_ADD: |
| 475 if (!splice) splice = newSplice(index, [], 0); |
| 476 splice.addedCount++; |
| 477 index++; |
| 478 break; |
| 479 |
| 480 case EDIT_DELETE: |
| 481 if (!splice) splice = newSplice(index, [], 0); |
| 482 splice.removed.push(old[oldIndex]); |
| 483 oldIndex++; |
| 484 break; |
| 485 } |
| 486 } |
| 487 if (splice) { |
| 488 splices.push(splice); |
| 489 } |
| 490 return splices; |
| 491 }, |
| 492 sharedPrefix: function(current, old, searchLength) { |
| 493 for (var i = 0; i < searchLength; i++) if (!this.equals(current[i], old[
i])) return i; |
| 494 return searchLength; |
| 495 }, |
| 496 sharedSuffix: function(current, old, searchLength) { |
| 497 var index1 = current.length; |
| 498 var index2 = old.length; |
| 499 var count = 0; |
| 500 while (count < searchLength && this.equals(current[--index1], old[--inde
x2])) count++; |
| 501 return count; |
| 502 }, |
| 503 calculateSplices: function(current, previous) { |
| 504 return this.calcSplices(current, 0, current.length, previous, 0, previou
s.length); |
| 505 }, |
| 506 equals: function(currentValue, previousValue) { |
| 507 return currentValue === previousValue; |
| 508 } |
| 509 }; |
| 510 scope.ArraySplice = ArraySplice; |
| 511 })(window.ShadowDOMPolyfill); |
| 512 (function(context) { |
| 513 "use strict"; |
| 514 var OriginalMutationObserver = window.MutationObserver; |
| 515 var callbacks = []; |
| 516 var pending = false; |
| 517 var timerFunc; |
| 518 function handle() { |
| 519 pending = false; |
| 520 var copies = callbacks.slice(0); |
| 521 callbacks = []; |
| 522 for (var i = 0; i < copies.length; i++) { |
| 523 (0, copies[i])(); |
| 524 } |
| 525 } |
| 526 if (OriginalMutationObserver) { |
| 527 var counter = 1; |
| 528 var observer = new OriginalMutationObserver(handle); |
| 529 var textNode = document.createTextNode(counter); |
| 530 observer.observe(textNode, { |
| 531 characterData: true |
| 532 }); |
| 533 timerFunc = function() { |
| 534 counter = (counter + 1) % 2; |
| 535 textNode.data = counter; |
| 536 }; |
| 537 } else { |
| 538 timerFunc = window.setTimeout; |
| 539 } |
| 540 function setEndOfMicrotask(func) { |
| 541 callbacks.push(func); |
| 542 if (pending) return; |
| 543 pending = true; |
| 544 timerFunc(handle, 0); |
| 545 } |
| 546 context.setEndOfMicrotask = setEndOfMicrotask; |
| 547 })(window.ShadowDOMPolyfill); |
| 548 (function(scope) { |
| 549 "use strict"; |
| 550 var setEndOfMicrotask = scope.setEndOfMicrotask; |
| 551 var wrapIfNeeded = scope.wrapIfNeeded; |
| 552 var wrappers = scope.wrappers; |
| 553 var registrationsTable = new WeakMap(); |
| 554 var globalMutationObservers = []; |
| 555 var isScheduled = false; |
| 556 function scheduleCallback(observer) { |
| 557 if (observer.scheduled_) return; |
| 558 observer.scheduled_ = true; |
| 559 globalMutationObservers.push(observer); |
| 560 if (isScheduled) return; |
| 561 setEndOfMicrotask(notifyObservers); |
| 562 isScheduled = true; |
| 563 } |
| 564 function notifyObservers() { |
| 565 isScheduled = false; |
| 566 while (globalMutationObservers.length) { |
| 567 var notifyList = globalMutationObservers; |
| 568 globalMutationObservers = []; |
| 569 notifyList.sort(function(x, y) { |
| 570 return x.uid_ - y.uid_; |
| 571 }); |
| 572 for (var i = 0; i < notifyList.length; i++) { |
| 573 var mo = notifyList[i]; |
| 574 mo.scheduled_ = false; |
| 575 var queue = mo.takeRecords(); |
| 576 removeTransientObserversFor(mo); |
| 577 if (queue.length) { |
| 578 mo.callback_(queue, mo); |
| 579 } |
| 580 } |
| 581 } |
| 582 } |
| 583 function MutationRecord(type, target) { |
| 584 this.type = type; |
| 585 this.target = target; |
| 586 this.addedNodes = new wrappers.NodeList(); |
| 587 this.removedNodes = new wrappers.NodeList(); |
| 588 this.previousSibling = null; |
| 589 this.nextSibling = null; |
| 590 this.attributeName = null; |
| 591 this.attributeNamespace = null; |
| 592 this.oldValue = null; |
| 593 } |
| 594 function registerTransientObservers(ancestor, node) { |
| 595 for (;ancestor; ancestor = ancestor.parentNode) { |
| 596 var registrations = registrationsTable.get(ancestor); |
| 597 if (!registrations) continue; |
| 598 for (var i = 0; i < registrations.length; i++) { |
| 599 var registration = registrations[i]; |
| 600 if (registration.options.subtree) registration.addTransientObserver(no
de); |
| 601 } |
| 602 } |
| 603 } |
| 604 function removeTransientObserversFor(observer) { |
| 605 for (var i = 0; i < observer.nodes_.length; i++) { |
| 606 var node = observer.nodes_[i]; |
| 607 var registrations = registrationsTable.get(node); |
| 608 if (!registrations) return; |
| 609 for (var j = 0; j < registrations.length; j++) { |
| 610 var registration = registrations[j]; |
| 611 if (registration.observer === observer) registration.removeTransientOb
servers(); |
| 612 } |
| 613 } |
| 614 } |
| 615 function enqueueMutation(target, type, data) { |
| 616 var interestedObservers = Object.create(null); |
| 617 var associatedStrings = Object.create(null); |
| 618 for (var node = target; node; node = node.parentNode) { |
| 619 var registrations = registrationsTable.get(node); |
| 620 if (!registrations) continue; |
| 621 for (var j = 0; j < registrations.length; j++) { |
| 622 var registration = registrations[j]; |
| 623 var options = registration.options; |
| 624 if (node !== target && !options.subtree) continue; |
| 625 if (type === "attributes" && !options.attributes) continue; |
| 626 if (type === "attributes" && options.attributeFilter && (data.namespac
e !== null || options.attributeFilter.indexOf(data.name) === -1)) { |
| 627 continue; |
| 628 } |
| 629 if (type === "characterData" && !options.characterData) continue; |
| 630 if (type === "childList" && !options.childList) continue; |
| 631 var observer = registration.observer; |
| 632 interestedObservers[observer.uid_] = observer; |
| 633 if (type === "attributes" && options.attributeOldValue || type === "ch
aracterData" && options.characterDataOldValue) { |
| 634 associatedStrings[observer.uid_] = data.oldValue; |
| 635 } |
| 636 } |
| 637 } |
| 638 for (var uid in interestedObservers) { |
| 639 var observer = interestedObservers[uid]; |
| 640 var record = new MutationRecord(type, target); |
| 641 if ("name" in data && "namespace" in data) { |
| 642 record.attributeName = data.name; |
| 643 record.attributeNamespace = data.namespace; |
| 644 } |
| 645 if (data.addedNodes) record.addedNodes = data.addedNodes; |
| 646 if (data.removedNodes) record.removedNodes = data.removedNodes; |
| 647 if (data.previousSibling) record.previousSibling = data.previousSibling; |
| 648 if (data.nextSibling) record.nextSibling = data.nextSibling; |
| 649 if (associatedStrings[uid] !== undefined) record.oldValue = associatedSt
rings[uid]; |
| 650 scheduleCallback(observer); |
| 651 observer.records_.push(record); |
| 652 } |
| 653 } |
| 654 var slice = Array.prototype.slice; |
| 655 function MutationObserverOptions(options) { |
| 656 this.childList = !!options.childList; |
| 657 this.subtree = !!options.subtree; |
| 658 if (!("attributes" in options) && ("attributeOldValue" in options || "attr
ibuteFilter" in options)) { |
| 659 this.attributes = true; |
| 660 } else { |
| 661 this.attributes = !!options.attributes; |
| 662 } |
| 663 if ("characterDataOldValue" in options && !("characterData" in options)) t
his.characterData = true; else this.characterData = !!options.characterData; |
| 664 if (!this.attributes && (options.attributeOldValue || "attributeFilter" in
options) || !this.characterData && options.characterDataOldValue) { |
| 665 throw new TypeError(); |
| 666 } |
| 667 this.characterData = !!options.characterData; |
| 668 this.attributeOldValue = !!options.attributeOldValue; |
| 669 this.characterDataOldValue = !!options.characterDataOldValue; |
| 670 if ("attributeFilter" in options) { |
| 671 if (options.attributeFilter == null || typeof options.attributeFilter !=
= "object") { |
| 672 throw new TypeError(); |
| 673 } |
| 674 this.attributeFilter = slice.call(options.attributeFilter); |
| 675 } else { |
| 676 this.attributeFilter = null; |
| 677 } |
| 678 } |
| 679 var uidCounter = 0; |
| 680 function MutationObserver(callback) { |
| 681 this.callback_ = callback; |
| 682 this.nodes_ = []; |
| 683 this.records_ = []; |
| 684 this.uid_ = ++uidCounter; |
| 685 this.scheduled_ = false; |
| 686 } |
| 687 MutationObserver.prototype = { |
| 688 constructor: MutationObserver, |
| 689 observe: function(target, options) { |
| 690 target = wrapIfNeeded(target); |
| 691 var newOptions = new MutationObserverOptions(options); |
| 692 var registration; |
| 693 var registrations = registrationsTable.get(target); |
| 694 if (!registrations) registrationsTable.set(target, registrations = []); |
| 695 for (var i = 0; i < registrations.length; i++) { |
| 696 if (registrations[i].observer === this) { |
| 697 registration = registrations[i]; |
| 698 registration.removeTransientObservers(); |
| 699 registration.options = newOptions; |
| 700 } |
| 701 } |
| 702 if (!registration) { |
| 703 registration = new Registration(this, target, newOptions); |
| 704 registrations.push(registration); |
| 705 this.nodes_.push(target); |
| 706 } |
| 707 }, |
| 708 disconnect: function() { |
| 709 this.nodes_.forEach(function(node) { |
| 710 var registrations = registrationsTable.get(node); |
| 711 for (var i = 0; i < registrations.length; i++) { |
| 712 var registration = registrations[i]; |
| 713 if (registration.observer === this) { |
| 714 registrations.splice(i, 1); |
| 715 break; |
| 716 } |
| 717 } |
| 718 }, this); |
| 719 this.records_ = []; |
| 720 }, |
| 721 takeRecords: function() { |
| 722 var copyOfRecords = this.records_; |
| 723 this.records_ = []; |
| 724 return copyOfRecords; |
| 725 } |
| 726 }; |
| 727 function Registration(observer, target, options) { |
| 728 this.observer = observer; |
| 729 this.target = target; |
| 730 this.options = options; |
| 731 this.transientObservedNodes = []; |
| 732 } |
| 733 Registration.prototype = { |
| 734 addTransientObserver: function(node) { |
| 735 if (node === this.target) return; |
| 736 scheduleCallback(this.observer); |
| 737 this.transientObservedNodes.push(node); |
| 738 var registrations = registrationsTable.get(node); |
| 739 if (!registrations) registrationsTable.set(node, registrations = []); |
| 740 registrations.push(this); |
| 741 }, |
| 742 removeTransientObservers: function() { |
| 743 var transientObservedNodes = this.transientObservedNodes; |
| 744 this.transientObservedNodes = []; |
| 745 for (var i = 0; i < transientObservedNodes.length; i++) { |
| 746 var node = transientObservedNodes[i]; |
| 747 var registrations = registrationsTable.get(node); |
| 748 for (var j = 0; j < registrations.length; j++) { |
| 749 if (registrations[j] === this) { |
| 750 registrations.splice(j, 1); |
| 751 break; |
| 752 } |
| 753 } |
| 754 } |
| 755 } |
| 756 }; |
| 757 scope.enqueueMutation = enqueueMutation; |
| 758 scope.registerTransientObservers = registerTransientObservers; |
| 759 scope.wrappers.MutationObserver = MutationObserver; |
| 760 scope.wrappers.MutationRecord = MutationRecord; |
| 761 })(window.ShadowDOMPolyfill); |
| 762 (function(scope) { |
| 763 "use strict"; |
| 764 function TreeScope(root, parent) { |
| 765 this.root = root; |
| 766 this.parent = parent; |
| 767 } |
| 768 TreeScope.prototype = { |
| 769 get renderer() { |
| 770 if (this.root instanceof scope.wrappers.ShadowRoot) { |
| 771 return scope.getRendererForHost(this.root.host); |
| 772 } |
| 773 return null; |
| 774 }, |
| 775 contains: function(treeScope) { |
| 776 for (;treeScope; treeScope = treeScope.parent) { |
| 777 if (treeScope === this) return true; |
| 778 } |
| 779 return false; |
| 780 } |
| 781 }; |
| 782 function setTreeScope(node, treeScope) { |
| 783 if (node.treeScope_ !== treeScope) { |
| 784 node.treeScope_ = treeScope; |
| 785 for (var sr = node.shadowRoot; sr; sr = sr.olderShadowRoot) { |
| 786 sr.treeScope_.parent = treeScope; |
| 787 } |
| 788 for (var child = node.firstChild; child; child = child.nextSibling) { |
| 789 setTreeScope(child, treeScope); |
| 790 } |
| 791 } |
| 792 } |
| 793 function getTreeScope(node) { |
| 794 if (node instanceof scope.wrappers.Window) { |
| 795 debugger; |
| 796 } |
| 797 if (node.treeScope_) return node.treeScope_; |
| 798 var parent = node.parentNode; |
| 799 var treeScope; |
| 800 if (parent) treeScope = getTreeScope(parent); else treeScope = new TreeSco
pe(node, null); |
| 801 return node.treeScope_ = treeScope; |
| 802 } |
| 803 scope.TreeScope = TreeScope; |
| 804 scope.getTreeScope = getTreeScope; |
| 805 scope.setTreeScope = setTreeScope; |
| 806 })(window.ShadowDOMPolyfill); |
| 807 (function(scope) { |
| 808 "use strict"; |
| 809 var forwardMethodsToWrapper = scope.forwardMethodsToWrapper; |
| 810 var getTreeScope = scope.getTreeScope; |
| 811 var mixin = scope.mixin; |
| 812 var registerWrapper = scope.registerWrapper; |
| 813 var setWrapper = scope.setWrapper; |
| 814 var unsafeUnwrap = scope.unsafeUnwrap; |
| 815 var unwrap = scope.unwrap; |
| 816 var wrap = scope.wrap; |
| 817 var wrappers = scope.wrappers; |
| 818 var wrappedFuns = new WeakMap(); |
| 819 var listenersTable = new WeakMap(); |
| 820 var handledEventsTable = new WeakMap(); |
| 821 var currentlyDispatchingEvents = new WeakMap(); |
| 822 var targetTable = new WeakMap(); |
| 823 var currentTargetTable = new WeakMap(); |
| 824 var relatedTargetTable = new WeakMap(); |
| 825 var eventPhaseTable = new WeakMap(); |
| 826 var stopPropagationTable = new WeakMap(); |
| 827 var stopImmediatePropagationTable = new WeakMap(); |
| 828 var eventHandlersTable = new WeakMap(); |
| 829 var eventPathTable = new WeakMap(); |
| 830 function isShadowRoot(node) { |
| 831 return node instanceof wrappers.ShadowRoot; |
| 832 } |
| 833 function rootOfNode(node) { |
| 834 return getTreeScope(node).root; |
| 835 } |
| 836 function getEventPath(node, event) { |
| 837 var path = []; |
| 838 var current = node; |
| 839 path.push(current); |
| 840 while (current) { |
| 841 var destinationInsertionPoints = getDestinationInsertionPoints(current); |
| 842 if (destinationInsertionPoints && destinationInsertionPoints.length > 0)
{ |
| 843 for (var i = 0; i < destinationInsertionPoints.length; i++) { |
| 844 var insertionPoint = destinationInsertionPoints[i]; |
| 845 if (isShadowInsertionPoint(insertionPoint)) { |
| 846 var shadowRoot = rootOfNode(insertionPoint); |
| 847 var olderShadowRoot = shadowRoot.olderShadowRoot; |
| 848 if (olderShadowRoot) path.push(olderShadowRoot); |
| 849 } |
| 850 path.push(insertionPoint); |
| 851 } |
| 852 current = destinationInsertionPoints[destinationInsertionPoints.length
- 1]; |
| 853 } else { |
| 854 if (isShadowRoot(current)) { |
| 855 if (inSameTree(node, current) && eventMustBeStopped(event)) { |
| 856 break; |
| 857 } |
| 858 current = current.host; |
| 859 path.push(current); |
| 860 } else { |
| 861 current = current.parentNode; |
| 862 if (current) path.push(current); |
| 863 } |
| 864 } |
| 865 } |
| 866 return path; |
| 867 } |
| 868 function eventMustBeStopped(event) { |
| 869 if (!event) return false; |
| 870 switch (event.type) { |
| 871 case "abort": |
| 872 case "error": |
| 873 case "select": |
| 874 case "change": |
| 875 case "load": |
| 876 case "reset": |
| 877 case "resize": |
| 878 case "scroll": |
| 879 case "selectstart": |
| 880 return true; |
| 881 } |
| 882 return false; |
| 883 } |
| 884 function isShadowInsertionPoint(node) { |
| 885 return node instanceof HTMLShadowElement; |
| 886 } |
| 887 function getDestinationInsertionPoints(node) { |
| 888 return scope.getDestinationInsertionPoints(node); |
| 889 } |
| 890 function eventRetargetting(path, currentTarget) { |
| 891 if (path.length === 0) return currentTarget; |
| 892 if (currentTarget instanceof wrappers.Window) currentTarget = currentTarge
t.document; |
| 893 var currentTargetTree = getTreeScope(currentTarget); |
| 894 var originalTarget = path[0]; |
| 895 var originalTargetTree = getTreeScope(originalTarget); |
| 896 var relativeTargetTree = lowestCommonInclusiveAncestor(currentTargetTree,
originalTargetTree); |
| 897 for (var i = 0; i < path.length; i++) { |
| 898 var node = path[i]; |
| 899 if (getTreeScope(node) === relativeTargetTree) return node; |
| 900 } |
| 901 return path[path.length - 1]; |
| 902 } |
| 903 function getTreeScopeAncestors(treeScope) { |
| 904 var ancestors = []; |
| 905 for (;treeScope; treeScope = treeScope.parent) { |
| 906 ancestors.push(treeScope); |
| 907 } |
| 908 return ancestors; |
| 909 } |
| 910 function lowestCommonInclusiveAncestor(tsA, tsB) { |
| 911 var ancestorsA = getTreeScopeAncestors(tsA); |
| 912 var ancestorsB = getTreeScopeAncestors(tsB); |
| 913 var result = null; |
| 914 while (ancestorsA.length > 0 && ancestorsB.length > 0) { |
| 915 var a = ancestorsA.pop(); |
| 916 var b = ancestorsB.pop(); |
| 917 if (a === b) result = a; else break; |
| 918 } |
| 919 return result; |
| 920 } |
| 921 function getTreeScopeRoot(ts) { |
| 922 if (!ts.parent) return ts; |
| 923 return getTreeScopeRoot(ts.parent); |
| 924 } |
| 925 function relatedTargetResolution(event, currentTarget, relatedTarget) { |
| 926 if (currentTarget instanceof wrappers.Window) currentTarget = currentTarge
t.document; |
| 927 var currentTargetTree = getTreeScope(currentTarget); |
| 928 var relatedTargetTree = getTreeScope(relatedTarget); |
| 929 var relatedTargetEventPath = getEventPath(relatedTarget, event); |
| 930 var lowestCommonAncestorTree; |
| 931 var lowestCommonAncestorTree = lowestCommonInclusiveAncestor(currentTarget
Tree, relatedTargetTree); |
| 932 if (!lowestCommonAncestorTree) lowestCommonAncestorTree = relatedTargetTre
e.root; |
| 933 for (var commonAncestorTree = lowestCommonAncestorTree; commonAncestorTree
; commonAncestorTree = commonAncestorTree.parent) { |
| 934 var adjustedRelatedTarget; |
| 935 for (var i = 0; i < relatedTargetEventPath.length; i++) { |
| 936 var node = relatedTargetEventPath[i]; |
| 937 if (getTreeScope(node) === commonAncestorTree) return node; |
| 938 } |
| 939 } |
| 940 return null; |
| 941 } |
| 942 function inSameTree(a, b) { |
| 943 return getTreeScope(a) === getTreeScope(b); |
| 944 } |
| 945 var NONE = 0; |
| 946 var CAPTURING_PHASE = 1; |
| 947 var AT_TARGET = 2; |
| 948 var BUBBLING_PHASE = 3; |
| 949 var pendingError; |
| 950 function dispatchOriginalEvent(originalEvent) { |
| 951 if (handledEventsTable.get(originalEvent)) return; |
| 952 handledEventsTable.set(originalEvent, true); |
| 953 dispatchEvent(wrap(originalEvent), wrap(originalEvent.target)); |
| 954 if (pendingError) { |
| 955 var err = pendingError; |
| 956 pendingError = null; |
| 957 throw err; |
| 958 } |
| 959 } |
| 960 function isLoadLikeEvent(event) { |
| 961 switch (event.type) { |
| 962 case "load": |
| 963 case "beforeunload": |
| 964 case "unload": |
| 965 return true; |
| 966 } |
| 967 return false; |
| 968 } |
| 969 function dispatchEvent(event, originalWrapperTarget) { |
| 970 if (currentlyDispatchingEvents.get(event)) throw new Error("InvalidStateEr
ror"); |
| 971 currentlyDispatchingEvents.set(event, true); |
| 972 scope.renderAllPending(); |
| 973 var eventPath; |
| 974 var overrideTarget; |
| 975 var win; |
| 976 if (isLoadLikeEvent(event) && !event.bubbles) { |
| 977 var doc = originalWrapperTarget; |
| 978 if (doc instanceof wrappers.Document && (win = doc.defaultView)) { |
| 979 overrideTarget = doc; |
| 980 eventPath = []; |
| 981 } |
| 982 } |
| 983 if (!eventPath) { |
| 984 if (originalWrapperTarget instanceof wrappers.Window) { |
| 985 win = originalWrapperTarget; |
| 986 eventPath = []; |
| 987 } else { |
| 988 eventPath = getEventPath(originalWrapperTarget, event); |
| 989 if (!isLoadLikeEvent(event)) { |
| 990 var doc = eventPath[eventPath.length - 1]; |
| 991 if (doc instanceof wrappers.Document) win = doc.defaultView; |
| 992 } |
| 993 } |
| 994 } |
| 995 eventPathTable.set(event, eventPath); |
| 996 if (dispatchCapturing(event, eventPath, win, overrideTarget)) { |
| 997 if (dispatchAtTarget(event, eventPath, win, overrideTarget)) { |
| 998 dispatchBubbling(event, eventPath, win, overrideTarget); |
| 999 } |
| 1000 } |
| 1001 eventPhaseTable.set(event, NONE); |
| 1002 currentTargetTable.delete(event, null); |
| 1003 currentlyDispatchingEvents.delete(event); |
| 1004 return event.defaultPrevented; |
| 1005 } |
| 1006 function dispatchCapturing(event, eventPath, win, overrideTarget) { |
| 1007 var phase = CAPTURING_PHASE; |
| 1008 if (win) { |
| 1009 if (!invoke(win, event, phase, eventPath, overrideTarget)) return false; |
| 1010 } |
| 1011 for (var i = eventPath.length - 1; i > 0; i--) { |
| 1012 if (!invoke(eventPath[i], event, phase, eventPath, overrideTarget)) retu
rn false; |
| 1013 } |
| 1014 return true; |
| 1015 } |
| 1016 function dispatchAtTarget(event, eventPath, win, overrideTarget) { |
| 1017 var phase = AT_TARGET; |
| 1018 var currentTarget = eventPath[0] || win; |
| 1019 return invoke(currentTarget, event, phase, eventPath, overrideTarget); |
| 1020 } |
| 1021 function dispatchBubbling(event, eventPath, win, overrideTarget) { |
| 1022 var phase = BUBBLING_PHASE; |
| 1023 for (var i = 1; i < eventPath.length; i++) { |
| 1024 if (!invoke(eventPath[i], event, phase, eventPath, overrideTarget)) retu
rn; |
| 1025 } |
| 1026 if (win && eventPath.length > 0) { |
| 1027 invoke(win, event, phase, eventPath, overrideTarget); |
| 1028 } |
| 1029 } |
| 1030 function invoke(currentTarget, event, phase, eventPath, overrideTarget) { |
| 1031 var listeners = listenersTable.get(currentTarget); |
| 1032 if (!listeners) return true; |
| 1033 var target = overrideTarget || eventRetargetting(eventPath, currentTarget)
; |
| 1034 if (target === currentTarget) { |
| 1035 if (phase === CAPTURING_PHASE) return true; |
| 1036 if (phase === BUBBLING_PHASE) phase = AT_TARGET; |
| 1037 } else if (phase === BUBBLING_PHASE && !event.bubbles) { |
| 1038 return true; |
| 1039 } |
| 1040 if ("relatedTarget" in event) { |
| 1041 var originalEvent = unwrap(event); |
| 1042 var unwrappedRelatedTarget = originalEvent.relatedTarget; |
| 1043 if (unwrappedRelatedTarget) { |
| 1044 if (unwrappedRelatedTarget instanceof Object && unwrappedRelatedTarget
.addEventListener) { |
| 1045 var relatedTarget = wrap(unwrappedRelatedTarget); |
| 1046 var adjusted = relatedTargetResolution(event, currentTarget, related
Target); |
| 1047 if (adjusted === target) return true; |
| 1048 } else { |
| 1049 adjusted = null; |
| 1050 } |
| 1051 relatedTargetTable.set(event, adjusted); |
| 1052 } |
| 1053 } |
| 1054 eventPhaseTable.set(event, phase); |
| 1055 var type = event.type; |
| 1056 var anyRemoved = false; |
| 1057 targetTable.set(event, target); |
| 1058 currentTargetTable.set(event, currentTarget); |
| 1059 listeners.depth++; |
| 1060 for (var i = 0, len = listeners.length; i < len; i++) { |
| 1061 var listener = listeners[i]; |
| 1062 if (listener.removed) { |
| 1063 anyRemoved = true; |
| 1064 continue; |
| 1065 } |
| 1066 if (listener.type !== type || !listener.capture && phase === CAPTURING_P
HASE || listener.capture && phase === BUBBLING_PHASE) { |
| 1067 continue; |
| 1068 } |
| 1069 try { |
| 1070 if (typeof listener.handler === "function") listener.handler.call(curr
entTarget, event); else listener.handler.handleEvent(event); |
| 1071 if (stopImmediatePropagationTable.get(event)) return false; |
| 1072 } catch (ex) { |
| 1073 if (!pendingError) pendingError = ex; |
| 1074 } |
| 1075 } |
| 1076 listeners.depth--; |
| 1077 if (anyRemoved && listeners.depth === 0) { |
| 1078 var copy = listeners.slice(); |
| 1079 listeners.length = 0; |
| 1080 for (var i = 0; i < copy.length; i++) { |
| 1081 if (!copy[i].removed) listeners.push(copy[i]); |
| 1082 } |
| 1083 } |
| 1084 return !stopPropagationTable.get(event); |
| 1085 } |
| 1086 function Listener(type, handler, capture) { |
| 1087 this.type = type; |
| 1088 this.handler = handler; |
| 1089 this.capture = Boolean(capture); |
| 1090 } |
| 1091 Listener.prototype = { |
| 1092 equals: function(that) { |
| 1093 return this.handler === that.handler && this.type === that.type && this.
capture === that.capture; |
| 1094 }, |
| 1095 get removed() { |
| 1096 return this.handler === null; |
| 1097 }, |
| 1098 remove: function() { |
| 1099 this.handler = null; |
| 1100 } |
| 1101 }; |
| 1102 var OriginalEvent = window.Event; |
| 1103 OriginalEvent.prototype.polymerBlackList_ = { |
| 1104 returnValue: true, |
| 1105 keyLocation: true |
| 1106 }; |
| 1107 function Event(type, options) { |
| 1108 if (type instanceof OriginalEvent) { |
| 1109 var impl = type; |
| 1110 if (!OriginalBeforeUnloadEvent && impl.type === "beforeunload" && !(this
instanceof BeforeUnloadEvent)) { |
| 1111 return new BeforeUnloadEvent(impl); |
| 1112 } |
| 1113 setWrapper(impl, this); |
| 1114 } else { |
| 1115 return wrap(constructEvent(OriginalEvent, "Event", type, options)); |
| 1116 } |
| 1117 } |
| 1118 Event.prototype = { |
| 1119 get target() { |
| 1120 return targetTable.get(this); |
| 1121 }, |
| 1122 get currentTarget() { |
| 1123 return currentTargetTable.get(this); |
| 1124 }, |
| 1125 get eventPhase() { |
| 1126 return eventPhaseTable.get(this); |
| 1127 }, |
| 1128 get path() { |
| 1129 var eventPath = eventPathTable.get(this); |
| 1130 if (!eventPath) return []; |
| 1131 return eventPath.slice(); |
| 1132 }, |
| 1133 stopPropagation: function() { |
| 1134 stopPropagationTable.set(this, true); |
| 1135 }, |
| 1136 stopImmediatePropagation: function() { |
| 1137 stopPropagationTable.set(this, true); |
| 1138 stopImmediatePropagationTable.set(this, true); |
| 1139 } |
| 1140 }; |
| 1141 registerWrapper(OriginalEvent, Event, document.createEvent("Event")); |
| 1142 function unwrapOptions(options) { |
| 1143 if (!options || !options.relatedTarget) return options; |
| 1144 return Object.create(options, { |
| 1145 relatedTarget: { |
| 1146 value: unwrap(options.relatedTarget) |
| 1147 } |
| 1148 }); |
| 1149 } |
| 1150 function registerGenericEvent(name, SuperEvent, prototype) { |
| 1151 var OriginalEvent = window[name]; |
| 1152 var GenericEvent = function(type, options) { |
| 1153 if (type instanceof OriginalEvent) setWrapper(type, this); else return w
rap(constructEvent(OriginalEvent, name, type, options)); |
| 1154 }; |
| 1155 GenericEvent.prototype = Object.create(SuperEvent.prototype); |
| 1156 if (prototype) mixin(GenericEvent.prototype, prototype); |
| 1157 if (OriginalEvent) { |
| 1158 try { |
| 1159 registerWrapper(OriginalEvent, GenericEvent, new OriginalEvent("temp")
); |
| 1160 } catch (ex) { |
| 1161 registerWrapper(OriginalEvent, GenericEvent, document.createEvent(name
)); |
| 1162 } |
| 1163 } |
| 1164 return GenericEvent; |
| 1165 } |
| 1166 var UIEvent = registerGenericEvent("UIEvent", Event); |
| 1167 var CustomEvent = registerGenericEvent("CustomEvent", Event); |
| 1168 var relatedTargetProto = { |
| 1169 get relatedTarget() { |
| 1170 var relatedTarget = relatedTargetTable.get(this); |
| 1171 if (relatedTarget !== undefined) return relatedTarget; |
| 1172 return wrap(unwrap(this).relatedTarget); |
| 1173 } |
| 1174 }; |
| 1175 function getInitFunction(name, relatedTargetIndex) { |
| 1176 return function() { |
| 1177 arguments[relatedTargetIndex] = unwrap(arguments[relatedTargetIndex]); |
| 1178 var impl = unwrap(this); |
| 1179 impl[name].apply(impl, arguments); |
| 1180 }; |
| 1181 } |
| 1182 var mouseEventProto = mixin({ |
| 1183 initMouseEvent: getInitFunction("initMouseEvent", 14) |
| 1184 }, relatedTargetProto); |
| 1185 var focusEventProto = mixin({ |
| 1186 initFocusEvent: getInitFunction("initFocusEvent", 5) |
| 1187 }, relatedTargetProto); |
| 1188 var MouseEvent = registerGenericEvent("MouseEvent", UIEvent, mouseEventProto
); |
| 1189 var FocusEvent = registerGenericEvent("FocusEvent", UIEvent, focusEventProto
); |
| 1190 var defaultInitDicts = Object.create(null); |
| 1191 var supportsEventConstructors = function() { |
| 1192 try { |
| 1193 new window.FocusEvent("focus"); |
| 1194 } catch (ex) { |
| 1195 return false; |
| 1196 } |
| 1197 return true; |
| 1198 }(); |
| 1199 function constructEvent(OriginalEvent, name, type, options) { |
| 1200 if (supportsEventConstructors) return new OriginalEvent(type, unwrapOption
s(options)); |
| 1201 var event = unwrap(document.createEvent(name)); |
| 1202 var defaultDict = defaultInitDicts[name]; |
| 1203 var args = [ type ]; |
| 1204 Object.keys(defaultDict).forEach(function(key) { |
| 1205 var v = options != null && key in options ? options[key] : defaultDict[k
ey]; |
| 1206 if (key === "relatedTarget") v = unwrap(v); |
| 1207 args.push(v); |
| 1208 }); |
| 1209 event["init" + name].apply(event, args); |
| 1210 return event; |
| 1211 } |
| 1212 if (!supportsEventConstructors) { |
| 1213 var configureEventConstructor = function(name, initDict, superName) { |
| 1214 if (superName) { |
| 1215 var superDict = defaultInitDicts[superName]; |
| 1216 initDict = mixin(mixin({}, superDict), initDict); |
| 1217 } |
| 1218 defaultInitDicts[name] = initDict; |
| 1219 }; |
| 1220 configureEventConstructor("Event", { |
| 1221 bubbles: false, |
| 1222 cancelable: false |
| 1223 }); |
| 1224 configureEventConstructor("CustomEvent", { |
| 1225 detail: null |
| 1226 }, "Event"); |
| 1227 configureEventConstructor("UIEvent", { |
| 1228 view: null, |
| 1229 detail: 0 |
| 1230 }, "Event"); |
| 1231 configureEventConstructor("MouseEvent", { |
| 1232 screenX: 0, |
| 1233 screenY: 0, |
| 1234 clientX: 0, |
| 1235 clientY: 0, |
| 1236 ctrlKey: false, |
| 1237 altKey: false, |
| 1238 shiftKey: false, |
| 1239 metaKey: false, |
| 1240 button: 0, |
| 1241 relatedTarget: null |
| 1242 }, "UIEvent"); |
| 1243 configureEventConstructor("FocusEvent", { |
| 1244 relatedTarget: null |
| 1245 }, "UIEvent"); |
| 1246 } |
| 1247 var OriginalBeforeUnloadEvent = window.BeforeUnloadEvent; |
| 1248 function BeforeUnloadEvent(impl) { |
| 1249 Event.call(this, impl); |
| 1250 } |
| 1251 BeforeUnloadEvent.prototype = Object.create(Event.prototype); |
| 1252 mixin(BeforeUnloadEvent.prototype, { |
| 1253 get returnValue() { |
| 1254 return unsafeUnwrap(this).returnValue; |
| 1255 }, |
| 1256 set returnValue(v) { |
| 1257 unsafeUnwrap(this).returnValue = v; |
| 1258 } |
| 1259 }); |
| 1260 if (OriginalBeforeUnloadEvent) registerWrapper(OriginalBeforeUnloadEvent, Be
foreUnloadEvent); |
| 1261 function isValidListener(fun) { |
| 1262 if (typeof fun === "function") return true; |
| 1263 return fun && fun.handleEvent; |
| 1264 } |
| 1265 function isMutationEvent(type) { |
| 1266 switch (type) { |
| 1267 case "DOMAttrModified": |
| 1268 case "DOMAttributeNameChanged": |
| 1269 case "DOMCharacterDataModified": |
| 1270 case "DOMElementNameChanged": |
| 1271 case "DOMNodeInserted": |
| 1272 case "DOMNodeInsertedIntoDocument": |
| 1273 case "DOMNodeRemoved": |
| 1274 case "DOMNodeRemovedFromDocument": |
| 1275 case "DOMSubtreeModified": |
| 1276 return true; |
| 1277 } |
| 1278 return false; |
| 1279 } |
| 1280 var OriginalEventTarget = window.EventTarget; |
| 1281 function EventTarget(impl) { |
| 1282 setWrapper(impl, this); |
| 1283 } |
| 1284 var methodNames = [ "addEventListener", "removeEventListener", "dispatchEven
t" ]; |
| 1285 [ Node, Window ].forEach(function(constructor) { |
| 1286 var p = constructor.prototype; |
| 1287 methodNames.forEach(function(name) { |
| 1288 Object.defineProperty(p, name + "_", { |
| 1289 value: p[name] |
| 1290 }); |
| 1291 }); |
| 1292 }); |
| 1293 function getTargetToListenAt(wrapper) { |
| 1294 if (wrapper instanceof wrappers.ShadowRoot) wrapper = wrapper.host; |
| 1295 return unwrap(wrapper); |
| 1296 } |
| 1297 EventTarget.prototype = { |
| 1298 addEventListener: function(type, fun, capture) { |
| 1299 if (!isValidListener(fun) || isMutationEvent(type)) return; |
| 1300 var listener = new Listener(type, fun, capture); |
| 1301 var listeners = listenersTable.get(this); |
| 1302 if (!listeners) { |
| 1303 listeners = []; |
| 1304 listeners.depth = 0; |
| 1305 listenersTable.set(this, listeners); |
| 1306 } else { |
| 1307 for (var i = 0; i < listeners.length; i++) { |
| 1308 if (listener.equals(listeners[i])) return; |
| 1309 } |
| 1310 } |
| 1311 listeners.push(listener); |
| 1312 var target = getTargetToListenAt(this); |
| 1313 target.addEventListener_(type, dispatchOriginalEvent, true); |
| 1314 }, |
| 1315 removeEventListener: function(type, fun, capture) { |
| 1316 capture = Boolean(capture); |
| 1317 var listeners = listenersTable.get(this); |
| 1318 if (!listeners) return; |
| 1319 var count = 0, found = false; |
| 1320 for (var i = 0; i < listeners.length; i++) { |
| 1321 if (listeners[i].type === type && listeners[i].capture === capture) { |
| 1322 count++; |
| 1323 if (listeners[i].handler === fun) { |
| 1324 found = true; |
| 1325 listeners[i].remove(); |
| 1326 } |
| 1327 } |
| 1328 } |
| 1329 if (found && count === 1) { |
| 1330 var target = getTargetToListenAt(this); |
| 1331 target.removeEventListener_(type, dispatchOriginalEvent, true); |
| 1332 } |
| 1333 }, |
| 1334 dispatchEvent: function(event) { |
| 1335 var nativeEvent = unwrap(event); |
| 1336 var eventType = nativeEvent.type; |
| 1337 handledEventsTable.set(nativeEvent, false); |
| 1338 scope.renderAllPending(); |
| 1339 var tempListener; |
| 1340 if (!hasListenerInAncestors(this, eventType)) { |
| 1341 tempListener = function() {}; |
| 1342 this.addEventListener(eventType, tempListener, true); |
| 1343 } |
| 1344 try { |
| 1345 return unwrap(this).dispatchEvent_(nativeEvent); |
| 1346 } finally { |
| 1347 if (tempListener) this.removeEventListener(eventType, tempListener, tr
ue); |
| 1348 } |
| 1349 } |
| 1350 }; |
| 1351 function hasListener(node, type) { |
| 1352 var listeners = listenersTable.get(node); |
| 1353 if (listeners) { |
| 1354 for (var i = 0; i < listeners.length; i++) { |
| 1355 if (!listeners[i].removed && listeners[i].type === type) return true; |
| 1356 } |
| 1357 } |
| 1358 return false; |
| 1359 } |
| 1360 function hasListenerInAncestors(target, type) { |
| 1361 for (var node = unwrap(target); node; node = node.parentNode) { |
| 1362 if (hasListener(wrap(node), type)) return true; |
| 1363 } |
| 1364 return false; |
| 1365 } |
| 1366 if (OriginalEventTarget) registerWrapper(OriginalEventTarget, EventTarget); |
| 1367 function wrapEventTargetMethods(constructors) { |
| 1368 forwardMethodsToWrapper(constructors, methodNames); |
| 1369 } |
| 1370 var originalElementFromPoint = document.elementFromPoint; |
| 1371 function elementFromPoint(self, document, x, y) { |
| 1372 scope.renderAllPending(); |
| 1373 var element = wrap(originalElementFromPoint.call(unsafeUnwrap(document), x
, y)); |
| 1374 if (!element) return null; |
| 1375 var path = getEventPath(element, null); |
| 1376 var idx = path.lastIndexOf(self); |
| 1377 if (idx == -1) return null; else path = path.slice(0, idx); |
| 1378 return eventRetargetting(path, self); |
| 1379 } |
| 1380 function getEventHandlerGetter(name) { |
| 1381 return function() { |
| 1382 var inlineEventHandlers = eventHandlersTable.get(this); |
| 1383 return inlineEventHandlers && inlineEventHandlers[name] && inlineEventHa
ndlers[name].value || null; |
| 1384 }; |
| 1385 } |
| 1386 function getEventHandlerSetter(name) { |
| 1387 var eventType = name.slice(2); |
| 1388 return function(value) { |
| 1389 var inlineEventHandlers = eventHandlersTable.get(this); |
| 1390 if (!inlineEventHandlers) { |
| 1391 inlineEventHandlers = Object.create(null); |
| 1392 eventHandlersTable.set(this, inlineEventHandlers); |
| 1393 } |
| 1394 var old = inlineEventHandlers[name]; |
| 1395 if (old) this.removeEventListener(eventType, old.wrapped, false); |
| 1396 if (typeof value === "function") { |
| 1397 var wrapped = function(e) { |
| 1398 var rv = value.call(this, e); |
| 1399 if (rv === false) e.preventDefault(); else if (name === "onbeforeunl
oad" && typeof rv === "string") e.returnValue = rv; |
| 1400 }; |
| 1401 this.addEventListener(eventType, wrapped, false); |
| 1402 inlineEventHandlers[name] = { |
| 1403 value: value, |
| 1404 wrapped: wrapped |
| 1405 }; |
| 1406 } |
| 1407 }; |
| 1408 } |
| 1409 scope.elementFromPoint = elementFromPoint; |
| 1410 scope.getEventHandlerGetter = getEventHandlerGetter; |
| 1411 scope.getEventHandlerSetter = getEventHandlerSetter; |
| 1412 scope.wrapEventTargetMethods = wrapEventTargetMethods; |
| 1413 scope.wrappers.BeforeUnloadEvent = BeforeUnloadEvent; |
| 1414 scope.wrappers.CustomEvent = CustomEvent; |
| 1415 scope.wrappers.Event = Event; |
| 1416 scope.wrappers.EventTarget = EventTarget; |
| 1417 scope.wrappers.FocusEvent = FocusEvent; |
| 1418 scope.wrappers.MouseEvent = MouseEvent; |
| 1419 scope.wrappers.UIEvent = UIEvent; |
| 1420 })(window.ShadowDOMPolyfill); |
| 1421 (function(scope) { |
| 1422 "use strict"; |
| 1423 var UIEvent = scope.wrappers.UIEvent; |
| 1424 var mixin = scope.mixin; |
| 1425 var registerWrapper = scope.registerWrapper; |
| 1426 var setWrapper = scope.setWrapper; |
| 1427 var unsafeUnwrap = scope.unsafeUnwrap; |
| 1428 var wrap = scope.wrap; |
| 1429 var OriginalTouchEvent = window.TouchEvent; |
| 1430 if (!OriginalTouchEvent) return; |
| 1431 var nativeEvent; |
| 1432 try { |
| 1433 nativeEvent = document.createEvent("TouchEvent"); |
| 1434 } catch (ex) { |
| 1435 return; |
| 1436 } |
| 1437 var nonEnumDescriptor = { |
| 1438 enumerable: false |
| 1439 }; |
| 1440 function nonEnum(obj, prop) { |
| 1441 Object.defineProperty(obj, prop, nonEnumDescriptor); |
| 1442 } |
| 1443 function Touch(impl) { |
| 1444 setWrapper(impl, this); |
| 1445 } |
| 1446 Touch.prototype = { |
| 1447 get target() { |
| 1448 return wrap(unsafeUnwrap(this).target); |
| 1449 } |
| 1450 }; |
| 1451 var descr = { |
| 1452 configurable: true, |
| 1453 enumerable: true, |
| 1454 get: null |
| 1455 }; |
| 1456 [ "clientX", "clientY", "screenX", "screenY", "pageX", "pageY", "identifier"
, "webkitRadiusX", "webkitRadiusY", "webkitRotationAngle", "webkitForce" ].forEa
ch(function(name) { |
| 1457 descr.get = function() { |
| 1458 return unsafeUnwrap(this)[name]; |
| 1459 }; |
| 1460 Object.defineProperty(Touch.prototype, name, descr); |
| 1461 }); |
| 1462 function TouchList() { |
| 1463 this.length = 0; |
| 1464 nonEnum(this, "length"); |
| 1465 } |
| 1466 TouchList.prototype = { |
| 1467 item: function(index) { |
| 1468 return this[index]; |
| 1469 } |
| 1470 }; |
| 1471 function wrapTouchList(nativeTouchList) { |
| 1472 var list = new TouchList(); |
| 1473 for (var i = 0; i < nativeTouchList.length; i++) { |
| 1474 list[i] = new Touch(nativeTouchList[i]); |
| 1475 } |
| 1476 list.length = i; |
| 1477 return list; |
| 1478 } |
| 1479 function TouchEvent(impl) { |
| 1480 UIEvent.call(this, impl); |
| 1481 } |
| 1482 TouchEvent.prototype = Object.create(UIEvent.prototype); |
| 1483 mixin(TouchEvent.prototype, { |
| 1484 get touches() { |
| 1485 return wrapTouchList(unsafeUnwrap(this).touches); |
| 1486 }, |
| 1487 get targetTouches() { |
| 1488 return wrapTouchList(unsafeUnwrap(this).targetTouches); |
| 1489 }, |
| 1490 get changedTouches() { |
| 1491 return wrapTouchList(unsafeUnwrap(this).changedTouches); |
| 1492 }, |
| 1493 initTouchEvent: function() { |
| 1494 throw new Error("Not implemented"); |
| 1495 } |
| 1496 }); |
| 1497 registerWrapper(OriginalTouchEvent, TouchEvent, nativeEvent); |
| 1498 scope.wrappers.Touch = Touch; |
| 1499 scope.wrappers.TouchEvent = TouchEvent; |
| 1500 scope.wrappers.TouchList = TouchList; |
| 1501 })(window.ShadowDOMPolyfill); |
| 1502 (function(scope) { |
| 1503 "use strict"; |
| 1504 var unsafeUnwrap = scope.unsafeUnwrap; |
| 1505 var wrap = scope.wrap; |
| 1506 var nonEnumDescriptor = { |
| 1507 enumerable: false |
| 1508 }; |
| 1509 function nonEnum(obj, prop) { |
| 1510 Object.defineProperty(obj, prop, nonEnumDescriptor); |
| 1511 } |
| 1512 function NodeList() { |
| 1513 this.length = 0; |
| 1514 nonEnum(this, "length"); |
| 1515 } |
| 1516 NodeList.prototype = { |
| 1517 item: function(index) { |
| 1518 return this[index]; |
| 1519 } |
| 1520 }; |
| 1521 nonEnum(NodeList.prototype, "item"); |
| 1522 function wrapNodeList(list) { |
| 1523 if (list == null) return list; |
| 1524 var wrapperList = new NodeList(); |
| 1525 for (var i = 0, length = list.length; i < length; i++) { |
| 1526 wrapperList[i] = wrap(list[i]); |
| 1527 } |
| 1528 wrapperList.length = length; |
| 1529 return wrapperList; |
| 1530 } |
| 1531 function addWrapNodeListMethod(wrapperConstructor, name) { |
| 1532 wrapperConstructor.prototype[name] = function() { |
| 1533 return wrapNodeList(unsafeUnwrap(this)[name].apply(unsafeUnwrap(this), a
rguments)); |
| 1534 }; |
| 1535 } |
| 1536 scope.wrappers.NodeList = NodeList; |
| 1537 scope.addWrapNodeListMethod = addWrapNodeListMethod; |
| 1538 scope.wrapNodeList = wrapNodeList; |
| 1539 })(window.ShadowDOMPolyfill); |
| 1540 (function(scope) { |
| 1541 "use strict"; |
| 1542 scope.wrapHTMLCollection = scope.wrapNodeList; |
| 1543 scope.wrappers.HTMLCollection = scope.wrappers.NodeList; |
| 1544 })(window.ShadowDOMPolyfill); |
| 1545 (function(scope) { |
| 1546 "use strict"; |
| 1547 var EventTarget = scope.wrappers.EventTarget; |
| 1548 var NodeList = scope.wrappers.NodeList; |
| 1549 var TreeScope = scope.TreeScope; |
| 1550 var assert = scope.assert; |
| 1551 var defineWrapGetter = scope.defineWrapGetter; |
| 1552 var enqueueMutation = scope.enqueueMutation; |
| 1553 var getTreeScope = scope.getTreeScope; |
| 1554 var isWrapper = scope.isWrapper; |
| 1555 var mixin = scope.mixin; |
| 1556 var registerTransientObservers = scope.registerTransientObservers; |
| 1557 var registerWrapper = scope.registerWrapper; |
| 1558 var setTreeScope = scope.setTreeScope; |
| 1559 var unsafeUnwrap = scope.unsafeUnwrap; |
| 1560 var unwrap = scope.unwrap; |
| 1561 var unwrapIfNeeded = scope.unwrapIfNeeded; |
| 1562 var wrap = scope.wrap; |
| 1563 var wrapIfNeeded = scope.wrapIfNeeded; |
| 1564 var wrappers = scope.wrappers; |
| 1565 function assertIsNodeWrapper(node) { |
| 1566 assert(node instanceof Node); |
| 1567 } |
| 1568 function createOneElementNodeList(node) { |
| 1569 var nodes = new NodeList(); |
| 1570 nodes[0] = node; |
| 1571 nodes.length = 1; |
| 1572 return nodes; |
| 1573 } |
| 1574 var surpressMutations = false; |
| 1575 function enqueueRemovalForInsertedNodes(node, parent, nodes) { |
| 1576 enqueueMutation(parent, "childList", { |
| 1577 removedNodes: nodes, |
| 1578 previousSibling: node.previousSibling, |
| 1579 nextSibling: node.nextSibling |
| 1580 }); |
| 1581 } |
| 1582 function enqueueRemovalForInsertedDocumentFragment(df, nodes) { |
| 1583 enqueueMutation(df, "childList", { |
| 1584 removedNodes: nodes |
| 1585 }); |
| 1586 } |
| 1587 function collectNodes(node, parentNode, previousNode, nextNode) { |
| 1588 if (node instanceof DocumentFragment) { |
| 1589 var nodes = collectNodesForDocumentFragment(node); |
| 1590 surpressMutations = true; |
| 1591 for (var i = nodes.length - 1; i >= 0; i--) { |
| 1592 node.removeChild(nodes[i]); |
| 1593 nodes[i].parentNode_ = parentNode; |
| 1594 } |
| 1595 surpressMutations = false; |
| 1596 for (var i = 0; i < nodes.length; i++) { |
| 1597 nodes[i].previousSibling_ = nodes[i - 1] || previousNode; |
| 1598 nodes[i].nextSibling_ = nodes[i + 1] || nextNode; |
| 1599 } |
| 1600 if (previousNode) previousNode.nextSibling_ = nodes[0]; |
| 1601 if (nextNode) nextNode.previousSibling_ = nodes[nodes.length - 1]; |
| 1602 return nodes; |
| 1603 } |
| 1604 var nodes = createOneElementNodeList(node); |
| 1605 var oldParent = node.parentNode; |
| 1606 if (oldParent) { |
| 1607 oldParent.removeChild(node); |
| 1608 } |
| 1609 node.parentNode_ = parentNode; |
| 1610 node.previousSibling_ = previousNode; |
| 1611 node.nextSibling_ = nextNode; |
| 1612 if (previousNode) previousNode.nextSibling_ = node; |
| 1613 if (nextNode) nextNode.previousSibling_ = node; |
| 1614 return nodes; |
| 1615 } |
| 1616 function collectNodesNative(node) { |
| 1617 if (node instanceof DocumentFragment) return collectNodesForDocumentFragme
nt(node); |
| 1618 var nodes = createOneElementNodeList(node); |
| 1619 var oldParent = node.parentNode; |
| 1620 if (oldParent) enqueueRemovalForInsertedNodes(node, oldParent, nodes); |
| 1621 return nodes; |
| 1622 } |
| 1623 function collectNodesForDocumentFragment(node) { |
| 1624 var nodes = new NodeList(); |
| 1625 var i = 0; |
| 1626 for (var child = node.firstChild; child; child = child.nextSibling) { |
| 1627 nodes[i++] = child; |
| 1628 } |
| 1629 nodes.length = i; |
| 1630 enqueueRemovalForInsertedDocumentFragment(node, nodes); |
| 1631 return nodes; |
| 1632 } |
| 1633 function snapshotNodeList(nodeList) { |
| 1634 return nodeList; |
| 1635 } |
| 1636 function nodeWasAdded(node, treeScope) { |
| 1637 setTreeScope(node, treeScope); |
| 1638 node.nodeIsInserted_(); |
| 1639 } |
| 1640 function nodesWereAdded(nodes, parent) { |
| 1641 var treeScope = getTreeScope(parent); |
| 1642 for (var i = 0; i < nodes.length; i++) { |
| 1643 nodeWasAdded(nodes[i], treeScope); |
| 1644 } |
| 1645 } |
| 1646 function nodeWasRemoved(node) { |
| 1647 setTreeScope(node, new TreeScope(node, null)); |
| 1648 } |
| 1649 function nodesWereRemoved(nodes) { |
| 1650 for (var i = 0; i < nodes.length; i++) { |
| 1651 nodeWasRemoved(nodes[i]); |
| 1652 } |
| 1653 } |
| 1654 function ensureSameOwnerDocument(parent, child) { |
| 1655 var ownerDoc = parent.nodeType === Node.DOCUMENT_NODE ? parent : parent.ow
nerDocument; |
| 1656 if (ownerDoc !== child.ownerDocument) ownerDoc.adoptNode(child); |
| 1657 } |
| 1658 function adoptNodesIfNeeded(owner, nodes) { |
| 1659 if (!nodes.length) return; |
| 1660 var ownerDoc = owner.ownerDocument; |
| 1661 if (ownerDoc === nodes[0].ownerDocument) return; |
| 1662 for (var i = 0; i < nodes.length; i++) { |
| 1663 scope.adoptNodeNoRemove(nodes[i], ownerDoc); |
| 1664 } |
| 1665 } |
| 1666 function unwrapNodesForInsertion(owner, nodes) { |
| 1667 adoptNodesIfNeeded(owner, nodes); |
| 1668 var length = nodes.length; |
| 1669 if (length === 1) return unwrap(nodes[0]); |
| 1670 var df = unwrap(owner.ownerDocument.createDocumentFragment()); |
| 1671 for (var i = 0; i < length; i++) { |
| 1672 df.appendChild(unwrap(nodes[i])); |
| 1673 } |
| 1674 return df; |
| 1675 } |
| 1676 function clearChildNodes(wrapper) { |
| 1677 if (wrapper.firstChild_ !== undefined) { |
| 1678 var child = wrapper.firstChild_; |
| 1679 while (child) { |
| 1680 var tmp = child; |
| 1681 child = child.nextSibling_; |
| 1682 tmp.parentNode_ = tmp.previousSibling_ = tmp.nextSibling_ = undefined; |
| 1683 } |
| 1684 } |
| 1685 wrapper.firstChild_ = wrapper.lastChild_ = undefined; |
| 1686 } |
| 1687 function removeAllChildNodes(wrapper) { |
| 1688 if (wrapper.invalidateShadowRenderer()) { |
| 1689 var childWrapper = wrapper.firstChild; |
| 1690 while (childWrapper) { |
| 1691 assert(childWrapper.parentNode === wrapper); |
| 1692 var nextSibling = childWrapper.nextSibling; |
| 1693 var childNode = unwrap(childWrapper); |
| 1694 var parentNode = childNode.parentNode; |
| 1695 if (parentNode) originalRemoveChild.call(parentNode, childNode); |
| 1696 childWrapper.previousSibling_ = childWrapper.nextSibling_ = childWrapp
er.parentNode_ = null; |
| 1697 childWrapper = nextSibling; |
| 1698 } |
| 1699 wrapper.firstChild_ = wrapper.lastChild_ = null; |
| 1700 } else { |
| 1701 var node = unwrap(wrapper); |
| 1702 var child = node.firstChild; |
| 1703 var nextSibling; |
| 1704 while (child) { |
| 1705 nextSibling = child.nextSibling; |
| 1706 originalRemoveChild.call(node, child); |
| 1707 child = nextSibling; |
| 1708 } |
| 1709 } |
| 1710 } |
| 1711 function invalidateParent(node) { |
| 1712 var p = node.parentNode; |
| 1713 return p && p.invalidateShadowRenderer(); |
| 1714 } |
| 1715 function cleanupNodes(nodes) { |
| 1716 for (var i = 0, n; i < nodes.length; i++) { |
| 1717 n = nodes[i]; |
| 1718 n.parentNode.removeChild(n); |
| 1719 } |
| 1720 } |
| 1721 var originalImportNode = document.importNode; |
| 1722 var originalCloneNode = window.Node.prototype.cloneNode; |
| 1723 function cloneNode(node, deep, opt_doc) { |
| 1724 var clone; |
| 1725 if (opt_doc) clone = wrap(originalImportNode.call(opt_doc, unsafeUnwrap(no
de), false)); else clone = wrap(originalCloneNode.call(unsafeUnwrap(node), false
)); |
| 1726 if (deep) { |
| 1727 for (var child = node.firstChild; child; child = child.nextSibling) { |
| 1728 clone.appendChild(cloneNode(child, true, opt_doc)); |
| 1729 } |
| 1730 if (node instanceof wrappers.HTMLTemplateElement) { |
| 1731 var cloneContent = clone.content; |
| 1732 for (var child = node.content.firstChild; child; child = child.nextSib
ling) { |
| 1733 cloneContent.appendChild(cloneNode(child, true, opt_doc)); |
| 1734 } |
| 1735 } |
| 1736 } |
| 1737 return clone; |
| 1738 } |
| 1739 function contains(self, child) { |
| 1740 if (!child || getTreeScope(self) !== getTreeScope(child)) return false; |
| 1741 for (var node = child; node; node = node.parentNode) { |
| 1742 if (node === self) return true; |
| 1743 } |
| 1744 return false; |
| 1745 } |
| 1746 var OriginalNode = window.Node; |
| 1747 function Node(original) { |
| 1748 assert(original instanceof OriginalNode); |
| 1749 EventTarget.call(this, original); |
| 1750 this.parentNode_ = undefined; |
| 1751 this.firstChild_ = undefined; |
| 1752 this.lastChild_ = undefined; |
| 1753 this.nextSibling_ = undefined; |
| 1754 this.previousSibling_ = undefined; |
| 1755 this.treeScope_ = undefined; |
| 1756 } |
| 1757 var OriginalDocumentFragment = window.DocumentFragment; |
| 1758 var originalAppendChild = OriginalNode.prototype.appendChild; |
| 1759 var originalCompareDocumentPosition = OriginalNode.prototype.compareDocument
Position; |
| 1760 var originalInsertBefore = OriginalNode.prototype.insertBefore; |
| 1761 var originalRemoveChild = OriginalNode.prototype.removeChild; |
| 1762 var originalReplaceChild = OriginalNode.prototype.replaceChild; |
| 1763 var isIe = /Trident|Edge/.test(navigator.userAgent); |
| 1764 var removeChildOriginalHelper = isIe ? function(parent, child) { |
| 1765 try { |
| 1766 originalRemoveChild.call(parent, child); |
| 1767 } catch (ex) { |
| 1768 if (!(parent instanceof OriginalDocumentFragment)) throw ex; |
| 1769 } |
| 1770 } : function(parent, child) { |
| 1771 originalRemoveChild.call(parent, child); |
| 1772 }; |
| 1773 Node.prototype = Object.create(EventTarget.prototype); |
| 1774 mixin(Node.prototype, { |
| 1775 appendChild: function(childWrapper) { |
| 1776 return this.insertBefore(childWrapper, null); |
| 1777 }, |
| 1778 insertBefore: function(childWrapper, refWrapper) { |
| 1779 assertIsNodeWrapper(childWrapper); |
| 1780 var refNode; |
| 1781 if (refWrapper) { |
| 1782 if (isWrapper(refWrapper)) { |
| 1783 refNode = unwrap(refWrapper); |
| 1784 } else { |
| 1785 refNode = refWrapper; |
| 1786 refWrapper = wrap(refNode); |
| 1787 } |
| 1788 } else { |
| 1789 refWrapper = null; |
| 1790 refNode = null; |
| 1791 } |
| 1792 refWrapper && assert(refWrapper.parentNode === this); |
| 1793 var nodes; |
| 1794 var previousNode = refWrapper ? refWrapper.previousSibling : this.lastCh
ild; |
| 1795 var useNative = !this.invalidateShadowRenderer() && !invalidateParent(ch
ildWrapper); |
| 1796 if (useNative) nodes = collectNodesNative(childWrapper); else nodes = co
llectNodes(childWrapper, this, previousNode, refWrapper); |
| 1797 if (useNative) { |
| 1798 ensureSameOwnerDocument(this, childWrapper); |
| 1799 clearChildNodes(this); |
| 1800 originalInsertBefore.call(unsafeUnwrap(this), unwrap(childWrapper), re
fNode); |
| 1801 } else { |
| 1802 if (!previousNode) this.firstChild_ = nodes[0]; |
| 1803 if (!refWrapper) { |
| 1804 this.lastChild_ = nodes[nodes.length - 1]; |
| 1805 if (this.firstChild_ === undefined) this.firstChild_ = this.firstChi
ld; |
| 1806 } |
| 1807 var parentNode = refNode ? refNode.parentNode : unsafeUnwrap(this); |
| 1808 if (parentNode) { |
| 1809 originalInsertBefore.call(parentNode, unwrapNodesForInsertion(this,
nodes), refNode); |
| 1810 } else { |
| 1811 adoptNodesIfNeeded(this, nodes); |
| 1812 } |
| 1813 } |
| 1814 enqueueMutation(this, "childList", { |
| 1815 addedNodes: nodes, |
| 1816 nextSibling: refWrapper, |
| 1817 previousSibling: previousNode |
| 1818 }); |
| 1819 nodesWereAdded(nodes, this); |
| 1820 return childWrapper; |
| 1821 }, |
| 1822 removeChild: function(childWrapper) { |
| 1823 assertIsNodeWrapper(childWrapper); |
| 1824 if (childWrapper.parentNode !== this) { |
| 1825 var found = false; |
| 1826 var childNodes = this.childNodes; |
| 1827 for (var ieChild = this.firstChild; ieChild; ieChild = ieChild.nextSib
ling) { |
| 1828 if (ieChild === childWrapper) { |
| 1829 found = true; |
| 1830 break; |
| 1831 } |
| 1832 } |
| 1833 if (!found) { |
| 1834 throw new Error("NotFoundError"); |
| 1835 } |
| 1836 } |
| 1837 var childNode = unwrap(childWrapper); |
| 1838 var childWrapperNextSibling = childWrapper.nextSibling; |
| 1839 var childWrapperPreviousSibling = childWrapper.previousSibling; |
| 1840 if (this.invalidateShadowRenderer()) { |
| 1841 var thisFirstChild = this.firstChild; |
| 1842 var thisLastChild = this.lastChild; |
| 1843 var parentNode = childNode.parentNode; |
| 1844 if (parentNode) removeChildOriginalHelper(parentNode, childNode); |
| 1845 if (thisFirstChild === childWrapper) this.firstChild_ = childWrapperNe
xtSibling; |
| 1846 if (thisLastChild === childWrapper) this.lastChild_ = childWrapperPrev
iousSibling; |
| 1847 if (childWrapperPreviousSibling) childWrapperPreviousSibling.nextSibli
ng_ = childWrapperNextSibling; |
| 1848 if (childWrapperNextSibling) { |
| 1849 childWrapperNextSibling.previousSibling_ = childWrapperPreviousSibli
ng; |
| 1850 } |
| 1851 childWrapper.previousSibling_ = childWrapper.nextSibling_ = childWrapp
er.parentNode_ = undefined; |
| 1852 } else { |
| 1853 clearChildNodes(this); |
| 1854 removeChildOriginalHelper(unsafeUnwrap(this), childNode); |
| 1855 } |
| 1856 if (!surpressMutations) { |
| 1857 enqueueMutation(this, "childList", { |
| 1858 removedNodes: createOneElementNodeList(childWrapper), |
| 1859 nextSibling: childWrapperNextSibling, |
| 1860 previousSibling: childWrapperPreviousSibling |
| 1861 }); |
| 1862 } |
| 1863 registerTransientObservers(this, childWrapper); |
| 1864 return childWrapper; |
| 1865 }, |
| 1866 replaceChild: function(newChildWrapper, oldChildWrapper) { |
| 1867 assertIsNodeWrapper(newChildWrapper); |
| 1868 var oldChildNode; |
| 1869 if (isWrapper(oldChildWrapper)) { |
| 1870 oldChildNode = unwrap(oldChildWrapper); |
| 1871 } else { |
| 1872 oldChildNode = oldChildWrapper; |
| 1873 oldChildWrapper = wrap(oldChildNode); |
| 1874 } |
| 1875 if (oldChildWrapper.parentNode !== this) { |
| 1876 throw new Error("NotFoundError"); |
| 1877 } |
| 1878 var nextNode = oldChildWrapper.nextSibling; |
| 1879 var previousNode = oldChildWrapper.previousSibling; |
| 1880 var nodes; |
| 1881 var useNative = !this.invalidateShadowRenderer() && !invalidateParent(ne
wChildWrapper); |
| 1882 if (useNative) { |
| 1883 nodes = collectNodesNative(newChildWrapper); |
| 1884 } else { |
| 1885 if (nextNode === newChildWrapper) nextNode = newChildWrapper.nextSibli
ng; |
| 1886 nodes = collectNodes(newChildWrapper, this, previousNode, nextNode); |
| 1887 } |
| 1888 if (!useNative) { |
| 1889 if (this.firstChild === oldChildWrapper) this.firstChild_ = nodes[0]; |
| 1890 if (this.lastChild === oldChildWrapper) this.lastChild_ = nodes[nodes.
length - 1]; |
| 1891 oldChildWrapper.previousSibling_ = oldChildWrapper.nextSibling_ = oldC
hildWrapper.parentNode_ = undefined; |
| 1892 if (oldChildNode.parentNode) { |
| 1893 originalReplaceChild.call(oldChildNode.parentNode, unwrapNodesForIns
ertion(this, nodes), oldChildNode); |
| 1894 } |
| 1895 } else { |
| 1896 ensureSameOwnerDocument(this, newChildWrapper); |
| 1897 clearChildNodes(this); |
| 1898 originalReplaceChild.call(unsafeUnwrap(this), unwrap(newChildWrapper),
oldChildNode); |
| 1899 } |
| 1900 enqueueMutation(this, "childList", { |
| 1901 addedNodes: nodes, |
| 1902 removedNodes: createOneElementNodeList(oldChildWrapper), |
| 1903 nextSibling: nextNode, |
| 1904 previousSibling: previousNode |
| 1905 }); |
| 1906 nodeWasRemoved(oldChildWrapper); |
| 1907 nodesWereAdded(nodes, this); |
| 1908 return oldChildWrapper; |
| 1909 }, |
| 1910 nodeIsInserted_: function() { |
| 1911 for (var child = this.firstChild; child; child = child.nextSibling) { |
| 1912 child.nodeIsInserted_(); |
| 1913 } |
| 1914 }, |
| 1915 hasChildNodes: function() { |
| 1916 return this.firstChild !== null; |
| 1917 }, |
| 1918 get parentNode() { |
| 1919 return this.parentNode_ !== undefined ? this.parentNode_ : wrap(unsafeUn
wrap(this).parentNode); |
| 1920 }, |
| 1921 get firstChild() { |
| 1922 return this.firstChild_ !== undefined ? this.firstChild_ : wrap(unsafeUn
wrap(this).firstChild); |
| 1923 }, |
| 1924 get lastChild() { |
| 1925 return this.lastChild_ !== undefined ? this.lastChild_ : wrap(unsafeUnwr
ap(this).lastChild); |
| 1926 }, |
| 1927 get nextSibling() { |
| 1928 return this.nextSibling_ !== undefined ? this.nextSibling_ : wrap(unsafe
Unwrap(this).nextSibling); |
| 1929 }, |
| 1930 get previousSibling() { |
| 1931 return this.previousSibling_ !== undefined ? this.previousSibling_ : wra
p(unsafeUnwrap(this).previousSibling); |
| 1932 }, |
| 1933 get parentElement() { |
| 1934 var p = this.parentNode; |
| 1935 while (p && p.nodeType !== Node.ELEMENT_NODE) { |
| 1936 p = p.parentNode; |
| 1937 } |
| 1938 return p; |
| 1939 }, |
| 1940 get textContent() { |
| 1941 var s = ""; |
| 1942 for (var child = this.firstChild; child; child = child.nextSibling) { |
| 1943 if (child.nodeType != Node.COMMENT_NODE) { |
| 1944 s += child.textContent; |
| 1945 } |
| 1946 } |
| 1947 return s; |
| 1948 }, |
| 1949 set textContent(textContent) { |
| 1950 if (textContent == null) textContent = ""; |
| 1951 var removedNodes = snapshotNodeList(this.childNodes); |
| 1952 if (this.invalidateShadowRenderer()) { |
| 1953 removeAllChildNodes(this); |
| 1954 if (textContent !== "") { |
| 1955 var textNode = unsafeUnwrap(this).ownerDocument.createTextNode(textC
ontent); |
| 1956 this.appendChild(textNode); |
| 1957 } |
| 1958 } else { |
| 1959 clearChildNodes(this); |
| 1960 unsafeUnwrap(this).textContent = textContent; |
| 1961 } |
| 1962 var addedNodes = snapshotNodeList(this.childNodes); |
| 1963 enqueueMutation(this, "childList", { |
| 1964 addedNodes: addedNodes, |
| 1965 removedNodes: removedNodes |
| 1966 }); |
| 1967 nodesWereRemoved(removedNodes); |
| 1968 nodesWereAdded(addedNodes, this); |
| 1969 }, |
| 1970 get childNodes() { |
| 1971 var wrapperList = new NodeList(); |
| 1972 var i = 0; |
| 1973 for (var child = this.firstChild; child; child = child.nextSibling) { |
| 1974 wrapperList[i++] = child; |
| 1975 } |
| 1976 wrapperList.length = i; |
| 1977 return wrapperList; |
| 1978 }, |
| 1979 cloneNode: function(deep) { |
| 1980 return cloneNode(this, deep); |
| 1981 }, |
| 1982 contains: function(child) { |
| 1983 return contains(this, wrapIfNeeded(child)); |
| 1984 }, |
| 1985 compareDocumentPosition: function(otherNode) { |
| 1986 return originalCompareDocumentPosition.call(unsafeUnwrap(this), unwrapIf
Needed(otherNode)); |
| 1987 }, |
| 1988 normalize: function() { |
| 1989 var nodes = snapshotNodeList(this.childNodes); |
| 1990 var remNodes = []; |
| 1991 var s = ""; |
| 1992 var modNode; |
| 1993 for (var i = 0, n; i < nodes.length; i++) { |
| 1994 n = nodes[i]; |
| 1995 if (n.nodeType === Node.TEXT_NODE) { |
| 1996 if (!modNode && !n.data.length) this.removeNode(n); else if (!modNod
e) modNode = n; else { |
| 1997 s += n.data; |
| 1998 remNodes.push(n); |
| 1999 } |
| 2000 } else { |
| 2001 if (modNode && remNodes.length) { |
| 2002 modNode.data += s; |
| 2003 cleanupNodes(remNodes); |
| 2004 } |
| 2005 remNodes = []; |
| 2006 s = ""; |
| 2007 modNode = null; |
| 2008 if (n.childNodes.length) n.normalize(); |
| 2009 } |
| 2010 } |
| 2011 if (modNode && remNodes.length) { |
| 2012 modNode.data += s; |
| 2013 cleanupNodes(remNodes); |
| 2014 } |
| 2015 } |
| 2016 }); |
| 2017 defineWrapGetter(Node, "ownerDocument"); |
| 2018 registerWrapper(OriginalNode, Node, document.createDocumentFragment()); |
| 2019 delete Node.prototype.querySelector; |
| 2020 delete Node.prototype.querySelectorAll; |
| 2021 Node.prototype = mixin(Object.create(EventTarget.prototype), Node.prototype)
; |
| 2022 scope.cloneNode = cloneNode; |
| 2023 scope.nodeWasAdded = nodeWasAdded; |
| 2024 scope.nodeWasRemoved = nodeWasRemoved; |
| 2025 scope.nodesWereAdded = nodesWereAdded; |
| 2026 scope.nodesWereRemoved = nodesWereRemoved; |
| 2027 scope.originalInsertBefore = originalInsertBefore; |
| 2028 scope.originalRemoveChild = originalRemoveChild; |
| 2029 scope.snapshotNodeList = snapshotNodeList; |
| 2030 scope.wrappers.Node = Node; |
| 2031 })(window.ShadowDOMPolyfill); |
| 2032 (function(scope) { |
| 2033 "use strict"; |
| 2034 var HTMLCollection = scope.wrappers.HTMLCollection; |
| 2035 var NodeList = scope.wrappers.NodeList; |
| 2036 var getTreeScope = scope.getTreeScope; |
| 2037 var unsafeUnwrap = scope.unsafeUnwrap; |
| 2038 var wrap = scope.wrap; |
| 2039 var originalDocumentQuerySelector = document.querySelector; |
| 2040 var originalElementQuerySelector = document.documentElement.querySelector; |
| 2041 var originalDocumentQuerySelectorAll = document.querySelectorAll; |
| 2042 var originalElementQuerySelectorAll = document.documentElement.querySelector
All; |
| 2043 var originalDocumentGetElementsByTagName = document.getElementsByTagName; |
| 2044 var originalElementGetElementsByTagName = document.documentElement.getElemen
tsByTagName; |
| 2045 var originalDocumentGetElementsByTagNameNS = document.getElementsByTagNameNS
; |
| 2046 var originalElementGetElementsByTagNameNS = document.documentElement.getElem
entsByTagNameNS; |
| 2047 var OriginalElement = window.Element; |
| 2048 var OriginalDocument = window.HTMLDocument || window.Document; |
| 2049 function filterNodeList(list, index, result, deep) { |
| 2050 var wrappedItem = null; |
| 2051 var root = null; |
| 2052 for (var i = 0, length = list.length; i < length; i++) { |
| 2053 wrappedItem = wrap(list[i]); |
| 2054 if (!deep && (root = getTreeScope(wrappedItem).root)) { |
| 2055 if (root instanceof scope.wrappers.ShadowRoot) { |
| 2056 continue; |
| 2057 } |
| 2058 } |
| 2059 result[index++] = wrappedItem; |
| 2060 } |
| 2061 return index; |
| 2062 } |
| 2063 function shimSelector(selector) { |
| 2064 return String(selector).replace(/\/deep\//g, " "); |
| 2065 } |
| 2066 function findOne(node, selector) { |
| 2067 var m, el = node.firstElementChild; |
| 2068 while (el) { |
| 2069 if (el.matches(selector)) return el; |
| 2070 m = findOne(el, selector); |
| 2071 if (m) return m; |
| 2072 el = el.nextElementSibling; |
| 2073 } |
| 2074 return null; |
| 2075 } |
| 2076 function matchesSelector(el, selector) { |
| 2077 return el.matches(selector); |
| 2078 } |
| 2079 var XHTML_NS = "http://www.w3.org/1999/xhtml"; |
| 2080 function matchesTagName(el, localName, localNameLowerCase) { |
| 2081 var ln = el.localName; |
| 2082 return ln === localName || ln === localNameLowerCase && el.namespaceURI ==
= XHTML_NS; |
| 2083 } |
| 2084 function matchesEveryThing() { |
| 2085 return true; |
| 2086 } |
| 2087 function matchesLocalNameOnly(el, ns, localName) { |
| 2088 return el.localName === localName; |
| 2089 } |
| 2090 function matchesNameSpace(el, ns) { |
| 2091 return el.namespaceURI === ns; |
| 2092 } |
| 2093 function matchesLocalNameNS(el, ns, localName) { |
| 2094 return el.namespaceURI === ns && el.localName === localName; |
| 2095 } |
| 2096 function findElements(node, index, result, p, arg0, arg1) { |
| 2097 var el = node.firstElementChild; |
| 2098 while (el) { |
| 2099 if (p(el, arg0, arg1)) result[index++] = el; |
| 2100 index = findElements(el, index, result, p, arg0, arg1); |
| 2101 el = el.nextElementSibling; |
| 2102 } |
| 2103 return index; |
| 2104 } |
| 2105 function querySelectorAllFiltered(p, index, result, selector, deep) { |
| 2106 var target = unsafeUnwrap(this); |
| 2107 var list; |
| 2108 var root = getTreeScope(this).root; |
| 2109 if (root instanceof scope.wrappers.ShadowRoot) { |
| 2110 return findElements(this, index, result, p, selector, null); |
| 2111 } else if (target instanceof OriginalElement) { |
| 2112 list = originalElementQuerySelectorAll.call(target, selector); |
| 2113 } else if (target instanceof OriginalDocument) { |
| 2114 list = originalDocumentQuerySelectorAll.call(target, selector); |
| 2115 } else { |
| 2116 return findElements(this, index, result, p, selector, null); |
| 2117 } |
| 2118 return filterNodeList(list, index, result, deep); |
| 2119 } |
| 2120 var SelectorsInterface = { |
| 2121 querySelector: function(selector) { |
| 2122 var shimmed = shimSelector(selector); |
| 2123 var deep = shimmed !== selector; |
| 2124 selector = shimmed; |
| 2125 var target = unsafeUnwrap(this); |
| 2126 var wrappedItem; |
| 2127 var root = getTreeScope(this).root; |
| 2128 if (root instanceof scope.wrappers.ShadowRoot) { |
| 2129 return findOne(this, selector); |
| 2130 } else if (target instanceof OriginalElement) { |
| 2131 wrappedItem = wrap(originalElementQuerySelector.call(target, selector)
); |
| 2132 } else if (target instanceof OriginalDocument) { |
| 2133 wrappedItem = wrap(originalDocumentQuerySelector.call(target, selector
)); |
| 2134 } else { |
| 2135 return findOne(this, selector); |
| 2136 } |
| 2137 if (!wrappedItem) { |
| 2138 return wrappedItem; |
| 2139 } else if (!deep && (root = getTreeScope(wrappedItem).root)) { |
| 2140 if (root instanceof scope.wrappers.ShadowRoot) { |
| 2141 return findOne(this, selector); |
| 2142 } |
| 2143 } |
| 2144 return wrappedItem; |
| 2145 }, |
| 2146 querySelectorAll: function(selector) { |
| 2147 var shimmed = shimSelector(selector); |
| 2148 var deep = shimmed !== selector; |
| 2149 selector = shimmed; |
| 2150 var result = new NodeList(); |
| 2151 result.length = querySelectorAllFiltered.call(this, matchesSelector, 0,
result, selector, deep); |
| 2152 return result; |
| 2153 } |
| 2154 }; |
| 2155 function getElementsByTagNameFiltered(p, index, result, localName, lowercase
) { |
| 2156 var target = unsafeUnwrap(this); |
| 2157 var list; |
| 2158 var root = getTreeScope(this).root; |
| 2159 if (root instanceof scope.wrappers.ShadowRoot) { |
| 2160 return findElements(this, index, result, p, localName, lowercase); |
| 2161 } else if (target instanceof OriginalElement) { |
| 2162 list = originalElementGetElementsByTagName.call(target, localName, lower
case); |
| 2163 } else if (target instanceof OriginalDocument) { |
| 2164 list = originalDocumentGetElementsByTagName.call(target, localName, lowe
rcase); |
| 2165 } else { |
| 2166 return findElements(this, index, result, p, localName, lowercase); |
| 2167 } |
| 2168 return filterNodeList(list, index, result, false); |
| 2169 } |
| 2170 function getElementsByTagNameNSFiltered(p, index, result, ns, localName) { |
| 2171 var target = unsafeUnwrap(this); |
| 2172 var list; |
| 2173 var root = getTreeScope(this).root; |
| 2174 if (root instanceof scope.wrappers.ShadowRoot) { |
| 2175 return findElements(this, index, result, p, ns, localName); |
| 2176 } else if (target instanceof OriginalElement) { |
| 2177 list = originalElementGetElementsByTagNameNS.call(target, ns, localName)
; |
| 2178 } else if (target instanceof OriginalDocument) { |
| 2179 list = originalDocumentGetElementsByTagNameNS.call(target, ns, localName
); |
| 2180 } else { |
| 2181 return findElements(this, index, result, p, ns, localName); |
| 2182 } |
| 2183 return filterNodeList(list, index, result, false); |
| 2184 } |
| 2185 var GetElementsByInterface = { |
| 2186 getElementsByTagName: function(localName) { |
| 2187 var result = new HTMLCollection(); |
| 2188 var match = localName === "*" ? matchesEveryThing : matchesTagName; |
| 2189 result.length = getElementsByTagNameFiltered.call(this, match, 0, result
, localName, localName.toLowerCase()); |
| 2190 return result; |
| 2191 }, |
| 2192 getElementsByClassName: function(className) { |
| 2193 return this.querySelectorAll("." + className); |
| 2194 }, |
| 2195 getElementsByTagNameNS: function(ns, localName) { |
| 2196 var result = new HTMLCollection(); |
| 2197 var match = null; |
| 2198 if (ns === "*") { |
| 2199 match = localName === "*" ? matchesEveryThing : matchesLocalNameOnly; |
| 2200 } else { |
| 2201 match = localName === "*" ? matchesNameSpace : matchesLocalNameNS; |
| 2202 } |
| 2203 result.length = getElementsByTagNameNSFiltered.call(this, match, 0, resu
lt, ns || null, localName); |
| 2204 return result; |
| 2205 } |
| 2206 }; |
| 2207 scope.GetElementsByInterface = GetElementsByInterface; |
| 2208 scope.SelectorsInterface = SelectorsInterface; |
| 2209 })(window.ShadowDOMPolyfill); |
| 2210 (function(scope) { |
| 2211 "use strict"; |
| 2212 var NodeList = scope.wrappers.NodeList; |
| 2213 function forwardElement(node) { |
| 2214 while (node && node.nodeType !== Node.ELEMENT_NODE) { |
| 2215 node = node.nextSibling; |
| 2216 } |
| 2217 return node; |
| 2218 } |
| 2219 function backwardsElement(node) { |
| 2220 while (node && node.nodeType !== Node.ELEMENT_NODE) { |
| 2221 node = node.previousSibling; |
| 2222 } |
| 2223 return node; |
| 2224 } |
| 2225 var ParentNodeInterface = { |
| 2226 get firstElementChild() { |
| 2227 return forwardElement(this.firstChild); |
| 2228 }, |
| 2229 get lastElementChild() { |
| 2230 return backwardsElement(this.lastChild); |
| 2231 }, |
| 2232 get childElementCount() { |
| 2233 var count = 0; |
| 2234 for (var child = this.firstElementChild; child; child = child.nextElemen
tSibling) { |
| 2235 count++; |
| 2236 } |
| 2237 return count; |
| 2238 }, |
| 2239 get children() { |
| 2240 var wrapperList = new NodeList(); |
| 2241 var i = 0; |
| 2242 for (var child = this.firstElementChild; child; child = child.nextElemen
tSibling) { |
| 2243 wrapperList[i++] = child; |
| 2244 } |
| 2245 wrapperList.length = i; |
| 2246 return wrapperList; |
| 2247 }, |
| 2248 remove: function() { |
| 2249 var p = this.parentNode; |
| 2250 if (p) p.removeChild(this); |
| 2251 } |
| 2252 }; |
| 2253 var ChildNodeInterface = { |
| 2254 get nextElementSibling() { |
| 2255 return forwardElement(this.nextSibling); |
| 2256 }, |
| 2257 get previousElementSibling() { |
| 2258 return backwardsElement(this.previousSibling); |
| 2259 } |
| 2260 }; |
| 2261 scope.ChildNodeInterface = ChildNodeInterface; |
| 2262 scope.ParentNodeInterface = ParentNodeInterface; |
| 2263 })(window.ShadowDOMPolyfill); |
| 2264 (function(scope) { |
| 2265 "use strict"; |
| 2266 var ChildNodeInterface = scope.ChildNodeInterface; |
| 2267 var Node = scope.wrappers.Node; |
| 2268 var enqueueMutation = scope.enqueueMutation; |
| 2269 var mixin = scope.mixin; |
| 2270 var registerWrapper = scope.registerWrapper; |
| 2271 var unsafeUnwrap = scope.unsafeUnwrap; |
| 2272 var OriginalCharacterData = window.CharacterData; |
| 2273 function CharacterData(node) { |
| 2274 Node.call(this, node); |
| 2275 } |
| 2276 CharacterData.prototype = Object.create(Node.prototype); |
| 2277 mixin(CharacterData.prototype, { |
| 2278 get textContent() { |
| 2279 return this.data; |
| 2280 }, |
| 2281 set textContent(value) { |
| 2282 this.data = value; |
| 2283 }, |
| 2284 get data() { |
| 2285 return unsafeUnwrap(this).data; |
| 2286 }, |
| 2287 set data(value) { |
| 2288 var oldValue = unsafeUnwrap(this).data; |
| 2289 enqueueMutation(this, "characterData", { |
| 2290 oldValue: oldValue |
| 2291 }); |
| 2292 unsafeUnwrap(this).data = value; |
| 2293 } |
| 2294 }); |
| 2295 mixin(CharacterData.prototype, ChildNodeInterface); |
| 2296 registerWrapper(OriginalCharacterData, CharacterData, document.createTextNod
e("")); |
| 2297 scope.wrappers.CharacterData = CharacterData; |
| 2298 })(window.ShadowDOMPolyfill); |
| 2299 (function(scope) { |
| 2300 "use strict"; |
| 2301 var CharacterData = scope.wrappers.CharacterData; |
| 2302 var enqueueMutation = scope.enqueueMutation; |
| 2303 var mixin = scope.mixin; |
| 2304 var registerWrapper = scope.registerWrapper; |
| 2305 function toUInt32(x) { |
| 2306 return x >>> 0; |
| 2307 } |
| 2308 var OriginalText = window.Text; |
| 2309 function Text(node) { |
| 2310 CharacterData.call(this, node); |
| 2311 } |
| 2312 Text.prototype = Object.create(CharacterData.prototype); |
| 2313 mixin(Text.prototype, { |
| 2314 splitText: function(offset) { |
| 2315 offset = toUInt32(offset); |
| 2316 var s = this.data; |
| 2317 if (offset > s.length) throw new Error("IndexSizeError"); |
| 2318 var head = s.slice(0, offset); |
| 2319 var tail = s.slice(offset); |
| 2320 this.data = head; |
| 2321 var newTextNode = this.ownerDocument.createTextNode(tail); |
| 2322 if (this.parentNode) this.parentNode.insertBefore(newTextNode, this.next
Sibling); |
| 2323 return newTextNode; |
| 2324 } |
| 2325 }); |
| 2326 registerWrapper(OriginalText, Text, document.createTextNode("")); |
| 2327 scope.wrappers.Text = Text; |
| 2328 })(window.ShadowDOMPolyfill); |
| 2329 (function(scope) { |
| 2330 "use strict"; |
| 2331 var setWrapper = scope.setWrapper; |
| 2332 var unsafeUnwrap = scope.unsafeUnwrap; |
| 2333 function invalidateClass(el) { |
| 2334 scope.invalidateRendererBasedOnAttribute(el, "class"); |
| 2335 } |
| 2336 function DOMTokenList(impl, ownerElement) { |
| 2337 setWrapper(impl, this); |
| 2338 this.ownerElement_ = ownerElement; |
| 2339 } |
| 2340 DOMTokenList.prototype = { |
| 2341 constructor: DOMTokenList, |
| 2342 get length() { |
| 2343 return unsafeUnwrap(this).length; |
| 2344 }, |
| 2345 item: function(index) { |
| 2346 return unsafeUnwrap(this).item(index); |
| 2347 }, |
| 2348 contains: function(token) { |
| 2349 return unsafeUnwrap(this).contains(token); |
| 2350 }, |
| 2351 add: function() { |
| 2352 unsafeUnwrap(this).add.apply(unsafeUnwrap(this), arguments); |
| 2353 invalidateClass(this.ownerElement_); |
| 2354 }, |
| 2355 remove: function() { |
| 2356 unsafeUnwrap(this).remove.apply(unsafeUnwrap(this), arguments); |
| 2357 invalidateClass(this.ownerElement_); |
| 2358 }, |
| 2359 toggle: function(token) { |
| 2360 var rv = unsafeUnwrap(this).toggle.apply(unsafeUnwrap(this), arguments); |
| 2361 invalidateClass(this.ownerElement_); |
| 2362 return rv; |
| 2363 }, |
| 2364 toString: function() { |
| 2365 return unsafeUnwrap(this).toString(); |
| 2366 } |
| 2367 }; |
| 2368 scope.wrappers.DOMTokenList = DOMTokenList; |
| 2369 })(window.ShadowDOMPolyfill); |
| 2370 (function(scope) { |
| 2371 "use strict"; |
| 2372 var ChildNodeInterface = scope.ChildNodeInterface; |
| 2373 var GetElementsByInterface = scope.GetElementsByInterface; |
| 2374 var Node = scope.wrappers.Node; |
| 2375 var DOMTokenList = scope.wrappers.DOMTokenList; |
| 2376 var ParentNodeInterface = scope.ParentNodeInterface; |
| 2377 var SelectorsInterface = scope.SelectorsInterface; |
| 2378 var addWrapNodeListMethod = scope.addWrapNodeListMethod; |
| 2379 var enqueueMutation = scope.enqueueMutation; |
| 2380 var mixin = scope.mixin; |
| 2381 var oneOf = scope.oneOf; |
| 2382 var registerWrapper = scope.registerWrapper; |
| 2383 var unsafeUnwrap = scope.unsafeUnwrap; |
| 2384 var wrappers = scope.wrappers; |
| 2385 var OriginalElement = window.Element; |
| 2386 var matchesNames = [ "matches", "mozMatchesSelector", "msMatchesSelector", "
webkitMatchesSelector" ].filter(function(name) { |
| 2387 return OriginalElement.prototype[name]; |
| 2388 }); |
| 2389 var matchesName = matchesNames[0]; |
| 2390 var originalMatches = OriginalElement.prototype[matchesName]; |
| 2391 function invalidateRendererBasedOnAttribute(element, name) { |
| 2392 var p = element.parentNode; |
| 2393 if (!p || !p.shadowRoot) return; |
| 2394 var renderer = scope.getRendererForHost(p); |
| 2395 if (renderer.dependsOnAttribute(name)) renderer.invalidate(); |
| 2396 } |
| 2397 function enqueAttributeChange(element, name, oldValue) { |
| 2398 enqueueMutation(element, "attributes", { |
| 2399 name: name, |
| 2400 namespace: null, |
| 2401 oldValue: oldValue |
| 2402 }); |
| 2403 } |
| 2404 var classListTable = new WeakMap(); |
| 2405 function Element(node) { |
| 2406 Node.call(this, node); |
| 2407 } |
| 2408 Element.prototype = Object.create(Node.prototype); |
| 2409 mixin(Element.prototype, { |
| 2410 createShadowRoot: function() { |
| 2411 var newShadowRoot = new wrappers.ShadowRoot(this); |
| 2412 unsafeUnwrap(this).polymerShadowRoot_ = newShadowRoot; |
| 2413 var renderer = scope.getRendererForHost(this); |
| 2414 renderer.invalidate(); |
| 2415 return newShadowRoot; |
| 2416 }, |
| 2417 get shadowRoot() { |
| 2418 return unsafeUnwrap(this).polymerShadowRoot_ || null; |
| 2419 }, |
| 2420 setAttribute: function(name, value) { |
| 2421 var oldValue = unsafeUnwrap(this).getAttribute(name); |
| 2422 unsafeUnwrap(this).setAttribute(name, value); |
| 2423 enqueAttributeChange(this, name, oldValue); |
| 2424 invalidateRendererBasedOnAttribute(this, name); |
| 2425 }, |
| 2426 removeAttribute: function(name) { |
| 2427 var oldValue = unsafeUnwrap(this).getAttribute(name); |
| 2428 unsafeUnwrap(this).removeAttribute(name); |
| 2429 enqueAttributeChange(this, name, oldValue); |
| 2430 invalidateRendererBasedOnAttribute(this, name); |
| 2431 }, |
| 2432 matches: function(selector) { |
| 2433 return originalMatches.call(unsafeUnwrap(this), selector); |
| 2434 }, |
| 2435 get classList() { |
| 2436 var list = classListTable.get(this); |
| 2437 if (!list) { |
| 2438 classListTable.set(this, list = new DOMTokenList(unsafeUnwrap(this).cl
assList, this)); |
| 2439 } |
| 2440 return list; |
| 2441 }, |
| 2442 get className() { |
| 2443 return unsafeUnwrap(this).className; |
| 2444 }, |
| 2445 set className(v) { |
| 2446 this.setAttribute("class", v); |
| 2447 }, |
| 2448 get id() { |
| 2449 return unsafeUnwrap(this).id; |
| 2450 }, |
| 2451 set id(v) { |
| 2452 this.setAttribute("id", v); |
| 2453 } |
| 2454 }); |
| 2455 matchesNames.forEach(function(name) { |
| 2456 if (name !== "matches") { |
| 2457 Element.prototype[name] = function(selector) { |
| 2458 return this.matches(selector); |
| 2459 }; |
| 2460 } |
| 2461 }); |
| 2462 if (OriginalElement.prototype.webkitCreateShadowRoot) { |
| 2463 Element.prototype.webkitCreateShadowRoot = Element.prototype.createShadowR
oot; |
| 2464 } |
| 2465 mixin(Element.prototype, ChildNodeInterface); |
| 2466 mixin(Element.prototype, GetElementsByInterface); |
| 2467 mixin(Element.prototype, ParentNodeInterface); |
| 2468 mixin(Element.prototype, SelectorsInterface); |
| 2469 registerWrapper(OriginalElement, Element, document.createElementNS(null, "x"
)); |
| 2470 scope.invalidateRendererBasedOnAttribute = invalidateRendererBasedOnAttribut
e; |
| 2471 scope.matchesNames = matchesNames; |
| 2472 scope.wrappers.Element = Element; |
| 2473 })(window.ShadowDOMPolyfill); |
| 2474 (function(scope) { |
| 2475 "use strict"; |
| 2476 var Element = scope.wrappers.Element; |
| 2477 var defineGetter = scope.defineGetter; |
| 2478 var enqueueMutation = scope.enqueueMutation; |
| 2479 var mixin = scope.mixin; |
| 2480 var nodesWereAdded = scope.nodesWereAdded; |
| 2481 var nodesWereRemoved = scope.nodesWereRemoved; |
| 2482 var registerWrapper = scope.registerWrapper; |
| 2483 var snapshotNodeList = scope.snapshotNodeList; |
| 2484 var unsafeUnwrap = scope.unsafeUnwrap; |
| 2485 var unwrap = scope.unwrap; |
| 2486 var wrap = scope.wrap; |
| 2487 var wrappers = scope.wrappers; |
| 2488 var escapeAttrRegExp = /[&\u00A0"]/g; |
| 2489 var escapeDataRegExp = /[&\u00A0<>]/g; |
| 2490 function escapeReplace(c) { |
| 2491 switch (c) { |
| 2492 case "&": |
| 2493 return "&"; |
| 2494 |
| 2495 case "<": |
| 2496 return "<"; |
| 2497 |
| 2498 case ">": |
| 2499 return ">"; |
| 2500 |
| 2501 case '"': |
| 2502 return """; |
| 2503 |
| 2504 case "Â ": |
| 2505 return " "; |
| 2506 } |
| 2507 } |
| 2508 function escapeAttr(s) { |
| 2509 return s.replace(escapeAttrRegExp, escapeReplace); |
| 2510 } |
| 2511 function escapeData(s) { |
| 2512 return s.replace(escapeDataRegExp, escapeReplace); |
| 2513 } |
| 2514 function makeSet(arr) { |
| 2515 var set = {}; |
| 2516 for (var i = 0; i < arr.length; i++) { |
| 2517 set[arr[i]] = true; |
| 2518 } |
| 2519 return set; |
| 2520 } |
| 2521 var voidElements = makeSet([ "area", "base", "br", "col", "command", "embed"
, "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "w
br" ]); |
| 2522 var plaintextParents = makeSet([ "style", "script", "xmp", "iframe", "noembe
d", "noframes", "plaintext", "noscript" ]); |
| 2523 function getOuterHTML(node, parentNode) { |
| 2524 switch (node.nodeType) { |
| 2525 case Node.ELEMENT_NODE: |
| 2526 var tagName = node.tagName.toLowerCase(); |
| 2527 var s = "<" + tagName; |
| 2528 var attrs = node.attributes; |
| 2529 for (var i = 0, attr; attr = attrs[i]; i++) { |
| 2530 s += " " + attr.name + '="' + escapeAttr(attr.value) + '"'; |
| 2531 } |
| 2532 s += ">"; |
| 2533 if (voidElements[tagName]) return s; |
| 2534 return s + getInnerHTML(node) + "</" + tagName + ">"; |
| 2535 |
| 2536 case Node.TEXT_NODE: |
| 2537 var data = node.data; |
| 2538 if (parentNode && plaintextParents[parentNode.localName]) return data; |
| 2539 return escapeData(data); |
| 2540 |
| 2541 case Node.COMMENT_NODE: |
| 2542 return "<!--" + node.data + "-->"; |
| 2543 |
| 2544 default: |
| 2545 console.error(node); |
| 2546 throw new Error("not implemented"); |
| 2547 } |
| 2548 } |
| 2549 function getInnerHTML(node) { |
| 2550 if (node instanceof wrappers.HTMLTemplateElement) node = node.content; |
| 2551 var s = ""; |
| 2552 for (var child = node.firstChild; child; child = child.nextSibling) { |
| 2553 s += getOuterHTML(child, node); |
| 2554 } |
| 2555 return s; |
| 2556 } |
| 2557 function setInnerHTML(node, value, opt_tagName) { |
| 2558 var tagName = opt_tagName || "div"; |
| 2559 node.textContent = ""; |
| 2560 var tempElement = unwrap(node.ownerDocument.createElement(tagName)); |
| 2561 tempElement.innerHTML = value; |
| 2562 var firstChild; |
| 2563 while (firstChild = tempElement.firstChild) { |
| 2564 node.appendChild(wrap(firstChild)); |
| 2565 } |
| 2566 } |
| 2567 var oldIe = /MSIE/.test(navigator.userAgent); |
| 2568 var OriginalHTMLElement = window.HTMLElement; |
| 2569 var OriginalHTMLTemplateElement = window.HTMLTemplateElement; |
| 2570 function HTMLElement(node) { |
| 2571 Element.call(this, node); |
| 2572 } |
| 2573 HTMLElement.prototype = Object.create(Element.prototype); |
| 2574 mixin(HTMLElement.prototype, { |
| 2575 get innerHTML() { |
| 2576 return getInnerHTML(this); |
| 2577 }, |
| 2578 set innerHTML(value) { |
| 2579 if (oldIe && plaintextParents[this.localName]) { |
| 2580 this.textContent = value; |
| 2581 return; |
| 2582 } |
| 2583 var removedNodes = snapshotNodeList(this.childNodes); |
| 2584 if (this.invalidateShadowRenderer()) { |
| 2585 if (this instanceof wrappers.HTMLTemplateElement) setInnerHTML(this.co
ntent, value); else setInnerHTML(this, value, this.tagName); |
| 2586 } else if (!OriginalHTMLTemplateElement && this instanceof wrappers.HTML
TemplateElement) { |
| 2587 setInnerHTML(this.content, value); |
| 2588 } else { |
| 2589 unsafeUnwrap(this).innerHTML = value; |
| 2590 } |
| 2591 var addedNodes = snapshotNodeList(this.childNodes); |
| 2592 enqueueMutation(this, "childList", { |
| 2593 addedNodes: addedNodes, |
| 2594 removedNodes: removedNodes |
| 2595 }); |
| 2596 nodesWereRemoved(removedNodes); |
| 2597 nodesWereAdded(addedNodes, this); |
| 2598 }, |
| 2599 get outerHTML() { |
| 2600 return getOuterHTML(this, this.parentNode); |
| 2601 }, |
| 2602 set outerHTML(value) { |
| 2603 var p = this.parentNode; |
| 2604 if (p) { |
| 2605 p.invalidateShadowRenderer(); |
| 2606 var df = frag(p, value); |
| 2607 p.replaceChild(df, this); |
| 2608 } |
| 2609 }, |
| 2610 insertAdjacentHTML: function(position, text) { |
| 2611 var contextElement, refNode; |
| 2612 switch (String(position).toLowerCase()) { |
| 2613 case "beforebegin": |
| 2614 contextElement = this.parentNode; |
| 2615 refNode = this; |
| 2616 break; |
| 2617 |
| 2618 case "afterend": |
| 2619 contextElement = this.parentNode; |
| 2620 refNode = this.nextSibling; |
| 2621 break; |
| 2622 |
| 2623 case "afterbegin": |
| 2624 contextElement = this; |
| 2625 refNode = this.firstChild; |
| 2626 break; |
| 2627 |
| 2628 case "beforeend": |
| 2629 contextElement = this; |
| 2630 refNode = null; |
| 2631 break; |
| 2632 |
| 2633 default: |
| 2634 return; |
| 2635 } |
| 2636 var df = frag(contextElement, text); |
| 2637 contextElement.insertBefore(df, refNode); |
| 2638 }, |
| 2639 get hidden() { |
| 2640 return this.hasAttribute("hidden"); |
| 2641 }, |
| 2642 set hidden(v) { |
| 2643 if (v) { |
| 2644 this.setAttribute("hidden", ""); |
| 2645 } else { |
| 2646 this.removeAttribute("hidden"); |
| 2647 } |
| 2648 } |
| 2649 }); |
| 2650 function frag(contextElement, html) { |
| 2651 var p = unwrap(contextElement.cloneNode(false)); |
| 2652 p.innerHTML = html; |
| 2653 var df = unwrap(document.createDocumentFragment()); |
| 2654 var c; |
| 2655 while (c = p.firstChild) { |
| 2656 df.appendChild(c); |
| 2657 } |
| 2658 return wrap(df); |
| 2659 } |
| 2660 function getter(name) { |
| 2661 return function() { |
| 2662 scope.renderAllPending(); |
| 2663 return unsafeUnwrap(this)[name]; |
| 2664 }; |
| 2665 } |
| 2666 function getterRequiresRendering(name) { |
| 2667 defineGetter(HTMLElement, name, getter(name)); |
| 2668 } |
| 2669 [ "clientHeight", "clientLeft", "clientTop", "clientWidth", "offsetHeight",
"offsetLeft", "offsetTop", "offsetWidth", "scrollHeight", "scrollWidth" ].forEac
h(getterRequiresRendering); |
| 2670 function getterAndSetterRequiresRendering(name) { |
| 2671 Object.defineProperty(HTMLElement.prototype, name, { |
| 2672 get: getter(name), |
| 2673 set: function(v) { |
| 2674 scope.renderAllPending(); |
| 2675 unsafeUnwrap(this)[name] = v; |
| 2676 }, |
| 2677 configurable: true, |
| 2678 enumerable: true |
| 2679 }); |
| 2680 } |
| 2681 [ "scrollLeft", "scrollTop" ].forEach(getterAndSetterRequiresRendering); |
| 2682 function methodRequiresRendering(name) { |
| 2683 Object.defineProperty(HTMLElement.prototype, name, { |
| 2684 value: function() { |
| 2685 scope.renderAllPending(); |
| 2686 return unsafeUnwrap(this)[name].apply(unsafeUnwrap(this), arguments); |
| 2687 }, |
| 2688 configurable: true, |
| 2689 enumerable: true |
| 2690 }); |
| 2691 } |
| 2692 [ "getBoundingClientRect", "getClientRects", "scrollIntoView" ].forEach(meth
odRequiresRendering); |
| 2693 registerWrapper(OriginalHTMLElement, HTMLElement, document.createElement("b"
)); |
| 2694 scope.wrappers.HTMLElement = HTMLElement; |
| 2695 scope.getInnerHTML = getInnerHTML; |
| 2696 scope.setInnerHTML = setInnerHTML; |
| 2697 })(window.ShadowDOMPolyfill); |
| 2698 (function(scope) { |
| 2699 "use strict"; |
| 2700 var HTMLElement = scope.wrappers.HTMLElement; |
| 2701 var mixin = scope.mixin; |
| 2702 var registerWrapper = scope.registerWrapper; |
| 2703 var unsafeUnwrap = scope.unsafeUnwrap; |
| 2704 var wrap = scope.wrap; |
| 2705 var OriginalHTMLCanvasElement = window.HTMLCanvasElement; |
| 2706 function HTMLCanvasElement(node) { |
| 2707 HTMLElement.call(this, node); |
| 2708 } |
| 2709 HTMLCanvasElement.prototype = Object.create(HTMLElement.prototype); |
| 2710 mixin(HTMLCanvasElement.prototype, { |
| 2711 getContext: function() { |
| 2712 var context = unsafeUnwrap(this).getContext.apply(unsafeUnwrap(this), ar
guments); |
| 2713 return context && wrap(context); |
| 2714 } |
| 2715 }); |
| 2716 registerWrapper(OriginalHTMLCanvasElement, HTMLCanvasElement, document.creat
eElement("canvas")); |
| 2717 scope.wrappers.HTMLCanvasElement = HTMLCanvasElement; |
| 2718 })(window.ShadowDOMPolyfill); |
| 2719 (function(scope) { |
| 2720 "use strict"; |
| 2721 var HTMLElement = scope.wrappers.HTMLElement; |
| 2722 var mixin = scope.mixin; |
| 2723 var registerWrapper = scope.registerWrapper; |
| 2724 var OriginalHTMLContentElement = window.HTMLContentElement; |
| 2725 function HTMLContentElement(node) { |
| 2726 HTMLElement.call(this, node); |
| 2727 } |
| 2728 HTMLContentElement.prototype = Object.create(HTMLElement.prototype); |
| 2729 mixin(HTMLContentElement.prototype, { |
| 2730 constructor: HTMLContentElement, |
| 2731 get select() { |
| 2732 return this.getAttribute("select"); |
| 2733 }, |
| 2734 set select(value) { |
| 2735 this.setAttribute("select", value); |
| 2736 }, |
| 2737 setAttribute: function(n, v) { |
| 2738 HTMLElement.prototype.setAttribute.call(this, n, v); |
| 2739 if (String(n).toLowerCase() === "select") this.invalidateShadowRenderer(
true); |
| 2740 } |
| 2741 }); |
| 2742 if (OriginalHTMLContentElement) registerWrapper(OriginalHTMLContentElement,
HTMLContentElement); |
| 2743 scope.wrappers.HTMLContentElement = HTMLContentElement; |
| 2744 })(window.ShadowDOMPolyfill); |
| 2745 (function(scope) { |
| 2746 "use strict"; |
| 2747 var HTMLElement = scope.wrappers.HTMLElement; |
| 2748 var mixin = scope.mixin; |
| 2749 var registerWrapper = scope.registerWrapper; |
| 2750 var wrapHTMLCollection = scope.wrapHTMLCollection; |
| 2751 var unwrap = scope.unwrap; |
| 2752 var OriginalHTMLFormElement = window.HTMLFormElement; |
| 2753 function HTMLFormElement(node) { |
| 2754 HTMLElement.call(this, node); |
| 2755 } |
| 2756 HTMLFormElement.prototype = Object.create(HTMLElement.prototype); |
| 2757 mixin(HTMLFormElement.prototype, { |
| 2758 get elements() { |
| 2759 return wrapHTMLCollection(unwrap(this).elements); |
| 2760 } |
| 2761 }); |
| 2762 registerWrapper(OriginalHTMLFormElement, HTMLFormElement, document.createEle
ment("form")); |
| 2763 scope.wrappers.HTMLFormElement = HTMLFormElement; |
| 2764 })(window.ShadowDOMPolyfill); |
| 2765 (function(scope) { |
| 2766 "use strict"; |
| 2767 var HTMLElement = scope.wrappers.HTMLElement; |
| 2768 var registerWrapper = scope.registerWrapper; |
| 2769 var unwrap = scope.unwrap; |
| 2770 var rewrap = scope.rewrap; |
| 2771 var OriginalHTMLImageElement = window.HTMLImageElement; |
| 2772 function HTMLImageElement(node) { |
| 2773 HTMLElement.call(this, node); |
| 2774 } |
| 2775 HTMLImageElement.prototype = Object.create(HTMLElement.prototype); |
| 2776 registerWrapper(OriginalHTMLImageElement, HTMLImageElement, document.createE
lement("img")); |
| 2777 function Image(width, height) { |
| 2778 if (!(this instanceof Image)) { |
| 2779 throw new TypeError("DOM object constructor cannot be called as a functi
on."); |
| 2780 } |
| 2781 var node = unwrap(document.createElement("img")); |
| 2782 HTMLElement.call(this, node); |
| 2783 rewrap(node, this); |
| 2784 if (width !== undefined) node.width = width; |
| 2785 if (height !== undefined) node.height = height; |
| 2786 } |
| 2787 Image.prototype = HTMLImageElement.prototype; |
| 2788 scope.wrappers.HTMLImageElement = HTMLImageElement; |
| 2789 scope.wrappers.Image = Image; |
| 2790 })(window.ShadowDOMPolyfill); |
| 2791 (function(scope) { |
| 2792 "use strict"; |
| 2793 var HTMLElement = scope.wrappers.HTMLElement; |
| 2794 var mixin = scope.mixin; |
| 2795 var NodeList = scope.wrappers.NodeList; |
| 2796 var registerWrapper = scope.registerWrapper; |
| 2797 var OriginalHTMLShadowElement = window.HTMLShadowElement; |
| 2798 function HTMLShadowElement(node) { |
| 2799 HTMLElement.call(this, node); |
| 2800 } |
| 2801 HTMLShadowElement.prototype = Object.create(HTMLElement.prototype); |
| 2802 HTMLShadowElement.prototype.constructor = HTMLShadowElement; |
| 2803 if (OriginalHTMLShadowElement) registerWrapper(OriginalHTMLShadowElement, HT
MLShadowElement); |
| 2804 scope.wrappers.HTMLShadowElement = HTMLShadowElement; |
| 2805 })(window.ShadowDOMPolyfill); |
| 2806 (function(scope) { |
| 2807 "use strict"; |
| 2808 var HTMLElement = scope.wrappers.HTMLElement; |
| 2809 var mixin = scope.mixin; |
| 2810 var registerWrapper = scope.registerWrapper; |
| 2811 var unsafeUnwrap = scope.unsafeUnwrap; |
| 2812 var unwrap = scope.unwrap; |
| 2813 var wrap = scope.wrap; |
| 2814 var contentTable = new WeakMap(); |
| 2815 var templateContentsOwnerTable = new WeakMap(); |
| 2816 function getTemplateContentsOwner(doc) { |
| 2817 if (!doc.defaultView) return doc; |
| 2818 var d = templateContentsOwnerTable.get(doc); |
| 2819 if (!d) { |
| 2820 d = doc.implementation.createHTMLDocument(""); |
| 2821 while (d.lastChild) { |
| 2822 d.removeChild(d.lastChild); |
| 2823 } |
| 2824 templateContentsOwnerTable.set(doc, d); |
| 2825 } |
| 2826 return d; |
| 2827 } |
| 2828 function extractContent(templateElement) { |
| 2829 var doc = getTemplateContentsOwner(templateElement.ownerDocument); |
| 2830 var df = unwrap(doc.createDocumentFragment()); |
| 2831 var child; |
| 2832 while (child = templateElement.firstChild) { |
| 2833 df.appendChild(child); |
| 2834 } |
| 2835 return df; |
| 2836 } |
| 2837 var OriginalHTMLTemplateElement = window.HTMLTemplateElement; |
| 2838 function HTMLTemplateElement(node) { |
| 2839 HTMLElement.call(this, node); |
| 2840 if (!OriginalHTMLTemplateElement) { |
| 2841 var content = extractContent(node); |
| 2842 contentTable.set(this, wrap(content)); |
| 2843 } |
| 2844 } |
| 2845 HTMLTemplateElement.prototype = Object.create(HTMLElement.prototype); |
| 2846 mixin(HTMLTemplateElement.prototype, { |
| 2847 constructor: HTMLTemplateElement, |
| 2848 get content() { |
| 2849 if (OriginalHTMLTemplateElement) return wrap(unsafeUnwrap(this).content)
; |
| 2850 return contentTable.get(this); |
| 2851 } |
| 2852 }); |
| 2853 if (OriginalHTMLTemplateElement) registerWrapper(OriginalHTMLTemplateElement
, HTMLTemplateElement); |
| 2854 scope.wrappers.HTMLTemplateElement = HTMLTemplateElement; |
| 2855 })(window.ShadowDOMPolyfill); |
| 2856 (function(scope) { |
| 2857 "use strict"; |
| 2858 var HTMLElement = scope.wrappers.HTMLElement; |
| 2859 var registerWrapper = scope.registerWrapper; |
| 2860 var OriginalHTMLMediaElement = window.HTMLMediaElement; |
| 2861 if (!OriginalHTMLMediaElement) return; |
| 2862 function HTMLMediaElement(node) { |
| 2863 HTMLElement.call(this, node); |
| 2864 } |
| 2865 HTMLMediaElement.prototype = Object.create(HTMLElement.prototype); |
| 2866 registerWrapper(OriginalHTMLMediaElement, HTMLMediaElement, document.createE
lement("audio")); |
| 2867 scope.wrappers.HTMLMediaElement = HTMLMediaElement; |
| 2868 })(window.ShadowDOMPolyfill); |
| 2869 (function(scope) { |
| 2870 "use strict"; |
| 2871 var HTMLMediaElement = scope.wrappers.HTMLMediaElement; |
| 2872 var registerWrapper = scope.registerWrapper; |
| 2873 var unwrap = scope.unwrap; |
| 2874 var rewrap = scope.rewrap; |
| 2875 var OriginalHTMLAudioElement = window.HTMLAudioElement; |
| 2876 if (!OriginalHTMLAudioElement) return; |
| 2877 function HTMLAudioElement(node) { |
| 2878 HTMLMediaElement.call(this, node); |
| 2879 } |
| 2880 HTMLAudioElement.prototype = Object.create(HTMLMediaElement.prototype); |
| 2881 registerWrapper(OriginalHTMLAudioElement, HTMLAudioElement, document.createE
lement("audio")); |
| 2882 function Audio(src) { |
| 2883 if (!(this instanceof Audio)) { |
| 2884 throw new TypeError("DOM object constructor cannot be called as a functi
on."); |
| 2885 } |
| 2886 var node = unwrap(document.createElement("audio")); |
| 2887 HTMLMediaElement.call(this, node); |
| 2888 rewrap(node, this); |
| 2889 node.setAttribute("preload", "auto"); |
| 2890 if (src !== undefined) node.setAttribute("src", src); |
| 2891 } |
| 2892 Audio.prototype = HTMLAudioElement.prototype; |
| 2893 scope.wrappers.HTMLAudioElement = HTMLAudioElement; |
| 2894 scope.wrappers.Audio = Audio; |
| 2895 })(window.ShadowDOMPolyfill); |
| 2896 (function(scope) { |
| 2897 "use strict"; |
| 2898 var HTMLElement = scope.wrappers.HTMLElement; |
| 2899 var mixin = scope.mixin; |
| 2900 var registerWrapper = scope.registerWrapper; |
| 2901 var rewrap = scope.rewrap; |
| 2902 var unwrap = scope.unwrap; |
| 2903 var wrap = scope.wrap; |
| 2904 var OriginalHTMLOptionElement = window.HTMLOptionElement; |
| 2905 function trimText(s) { |
| 2906 return s.replace(/\s+/g, " ").trim(); |
| 2907 } |
| 2908 function HTMLOptionElement(node) { |
| 2909 HTMLElement.call(this, node); |
| 2910 } |
| 2911 HTMLOptionElement.prototype = Object.create(HTMLElement.prototype); |
| 2912 mixin(HTMLOptionElement.prototype, { |
| 2913 get text() { |
| 2914 return trimText(this.textContent); |
| 2915 }, |
| 2916 set text(value) { |
| 2917 this.textContent = trimText(String(value)); |
| 2918 }, |
| 2919 get form() { |
| 2920 return wrap(unwrap(this).form); |
| 2921 } |
| 2922 }); |
| 2923 registerWrapper(OriginalHTMLOptionElement, HTMLOptionElement, document.creat
eElement("option")); |
| 2924 function Option(text, value, defaultSelected, selected) { |
| 2925 if (!(this instanceof Option)) { |
| 2926 throw new TypeError("DOM object constructor cannot be called as a functi
on."); |
| 2927 } |
| 2928 var node = unwrap(document.createElement("option")); |
| 2929 HTMLElement.call(this, node); |
| 2930 rewrap(node, this); |
| 2931 if (text !== undefined) node.text = text; |
| 2932 if (value !== undefined) node.setAttribute("value", value); |
| 2933 if (defaultSelected === true) node.setAttribute("selected", ""); |
| 2934 node.selected = selected === true; |
| 2935 } |
| 2936 Option.prototype = HTMLOptionElement.prototype; |
| 2937 scope.wrappers.HTMLOptionElement = HTMLOptionElement; |
| 2938 scope.wrappers.Option = Option; |
| 2939 })(window.ShadowDOMPolyfill); |
| 2940 (function(scope) { |
| 2941 "use strict"; |
| 2942 var HTMLElement = scope.wrappers.HTMLElement; |
| 2943 var mixin = scope.mixin; |
| 2944 var registerWrapper = scope.registerWrapper; |
| 2945 var unwrap = scope.unwrap; |
| 2946 var wrap = scope.wrap; |
| 2947 var OriginalHTMLSelectElement = window.HTMLSelectElement; |
| 2948 function HTMLSelectElement(node) { |
| 2949 HTMLElement.call(this, node); |
| 2950 } |
| 2951 HTMLSelectElement.prototype = Object.create(HTMLElement.prototype); |
| 2952 mixin(HTMLSelectElement.prototype, { |
| 2953 add: function(element, before) { |
| 2954 if (typeof before === "object") before = unwrap(before); |
| 2955 unwrap(this).add(unwrap(element), before); |
| 2956 }, |
| 2957 remove: function(indexOrNode) { |
| 2958 if (indexOrNode === undefined) { |
| 2959 HTMLElement.prototype.remove.call(this); |
| 2960 return; |
| 2961 } |
| 2962 if (typeof indexOrNode === "object") indexOrNode = unwrap(indexOrNode); |
| 2963 unwrap(this).remove(indexOrNode); |
| 2964 }, |
| 2965 get form() { |
| 2966 return wrap(unwrap(this).form); |
| 2967 } |
| 2968 }); |
| 2969 registerWrapper(OriginalHTMLSelectElement, HTMLSelectElement, document.creat
eElement("select")); |
| 2970 scope.wrappers.HTMLSelectElement = HTMLSelectElement; |
| 2971 })(window.ShadowDOMPolyfill); |
| 2972 (function(scope) { |
| 2973 "use strict"; |
| 2974 var HTMLElement = scope.wrappers.HTMLElement; |
| 2975 var mixin = scope.mixin; |
| 2976 var registerWrapper = scope.registerWrapper; |
| 2977 var unwrap = scope.unwrap; |
| 2978 var wrap = scope.wrap; |
| 2979 var wrapHTMLCollection = scope.wrapHTMLCollection; |
| 2980 var OriginalHTMLTableElement = window.HTMLTableElement; |
| 2981 function HTMLTableElement(node) { |
| 2982 HTMLElement.call(this, node); |
| 2983 } |
| 2984 HTMLTableElement.prototype = Object.create(HTMLElement.prototype); |
| 2985 mixin(HTMLTableElement.prototype, { |
| 2986 get caption() { |
| 2987 return wrap(unwrap(this).caption); |
| 2988 }, |
| 2989 createCaption: function() { |
| 2990 return wrap(unwrap(this).createCaption()); |
| 2991 }, |
| 2992 get tHead() { |
| 2993 return wrap(unwrap(this).tHead); |
| 2994 }, |
| 2995 createTHead: function() { |
| 2996 return wrap(unwrap(this).createTHead()); |
| 2997 }, |
| 2998 createTFoot: function() { |
| 2999 return wrap(unwrap(this).createTFoot()); |
| 3000 }, |
| 3001 get tFoot() { |
| 3002 return wrap(unwrap(this).tFoot); |
| 3003 }, |
| 3004 get tBodies() { |
| 3005 return wrapHTMLCollection(unwrap(this).tBodies); |
| 3006 }, |
| 3007 createTBody: function() { |
| 3008 return wrap(unwrap(this).createTBody()); |
| 3009 }, |
| 3010 get rows() { |
| 3011 return wrapHTMLCollection(unwrap(this).rows); |
| 3012 }, |
| 3013 insertRow: function(index) { |
| 3014 return wrap(unwrap(this).insertRow(index)); |
| 3015 } |
| 3016 }); |
| 3017 registerWrapper(OriginalHTMLTableElement, HTMLTableElement, document.createE
lement("table")); |
| 3018 scope.wrappers.HTMLTableElement = HTMLTableElement; |
| 3019 })(window.ShadowDOMPolyfill); |
| 3020 (function(scope) { |
| 3021 "use strict"; |
| 3022 var HTMLElement = scope.wrappers.HTMLElement; |
| 3023 var mixin = scope.mixin; |
| 3024 var registerWrapper = scope.registerWrapper; |
| 3025 var wrapHTMLCollection = scope.wrapHTMLCollection; |
| 3026 var unwrap = scope.unwrap; |
| 3027 var wrap = scope.wrap; |
| 3028 var OriginalHTMLTableSectionElement = window.HTMLTableSectionElement; |
| 3029 function HTMLTableSectionElement(node) { |
| 3030 HTMLElement.call(this, node); |
| 3031 } |
| 3032 HTMLTableSectionElement.prototype = Object.create(HTMLElement.prototype); |
| 3033 mixin(HTMLTableSectionElement.prototype, { |
| 3034 constructor: HTMLTableSectionElement, |
| 3035 get rows() { |
| 3036 return wrapHTMLCollection(unwrap(this).rows); |
| 3037 }, |
| 3038 insertRow: function(index) { |
| 3039 return wrap(unwrap(this).insertRow(index)); |
| 3040 } |
| 3041 }); |
| 3042 registerWrapper(OriginalHTMLTableSectionElement, HTMLTableSectionElement, do
cument.createElement("thead")); |
| 3043 scope.wrappers.HTMLTableSectionElement = HTMLTableSectionElement; |
| 3044 })(window.ShadowDOMPolyfill); |
| 3045 (function(scope) { |
| 3046 "use strict"; |
| 3047 var HTMLElement = scope.wrappers.HTMLElement; |
| 3048 var mixin = scope.mixin; |
| 3049 var registerWrapper = scope.registerWrapper; |
| 3050 var wrapHTMLCollection = scope.wrapHTMLCollection; |
| 3051 var unwrap = scope.unwrap; |
| 3052 var wrap = scope.wrap; |
| 3053 var OriginalHTMLTableRowElement = window.HTMLTableRowElement; |
| 3054 function HTMLTableRowElement(node) { |
| 3055 HTMLElement.call(this, node); |
| 3056 } |
| 3057 HTMLTableRowElement.prototype = Object.create(HTMLElement.prototype); |
| 3058 mixin(HTMLTableRowElement.prototype, { |
| 3059 get cells() { |
| 3060 return wrapHTMLCollection(unwrap(this).cells); |
| 3061 }, |
| 3062 insertCell: function(index) { |
| 3063 return wrap(unwrap(this).insertCell(index)); |
| 3064 } |
| 3065 }); |
| 3066 registerWrapper(OriginalHTMLTableRowElement, HTMLTableRowElement, document.c
reateElement("tr")); |
| 3067 scope.wrappers.HTMLTableRowElement = HTMLTableRowElement; |
| 3068 })(window.ShadowDOMPolyfill); |
| 3069 (function(scope) { |
| 3070 "use strict"; |
| 3071 var HTMLContentElement = scope.wrappers.HTMLContentElement; |
| 3072 var HTMLElement = scope.wrappers.HTMLElement; |
| 3073 var HTMLShadowElement = scope.wrappers.HTMLShadowElement; |
| 3074 var HTMLTemplateElement = scope.wrappers.HTMLTemplateElement; |
| 3075 var mixin = scope.mixin; |
| 3076 var registerWrapper = scope.registerWrapper; |
| 3077 var OriginalHTMLUnknownElement = window.HTMLUnknownElement; |
| 3078 function HTMLUnknownElement(node) { |
| 3079 switch (node.localName) { |
| 3080 case "content": |
| 3081 return new HTMLContentElement(node); |
| 3082 |
| 3083 case "shadow": |
| 3084 return new HTMLShadowElement(node); |
| 3085 |
| 3086 case "template": |
| 3087 return new HTMLTemplateElement(node); |
| 3088 } |
| 3089 HTMLElement.call(this, node); |
| 3090 } |
| 3091 HTMLUnknownElement.prototype = Object.create(HTMLElement.prototype); |
| 3092 registerWrapper(OriginalHTMLUnknownElement, HTMLUnknownElement); |
| 3093 scope.wrappers.HTMLUnknownElement = HTMLUnknownElement; |
| 3094 })(window.ShadowDOMPolyfill); |
| 3095 (function(scope) { |
| 3096 "use strict"; |
| 3097 var Element = scope.wrappers.Element; |
| 3098 var HTMLElement = scope.wrappers.HTMLElement; |
| 3099 var registerObject = scope.registerObject; |
| 3100 var SVG_NS = "http://www.w3.org/2000/svg"; |
| 3101 var svgTitleElement = document.createElementNS(SVG_NS, "title"); |
| 3102 var SVGTitleElement = registerObject(svgTitleElement); |
| 3103 var SVGElement = Object.getPrototypeOf(SVGTitleElement.prototype).constructo
r; |
| 3104 if (!("classList" in svgTitleElement)) { |
| 3105 var descr = Object.getOwnPropertyDescriptor(Element.prototype, "classList"
); |
| 3106 Object.defineProperty(HTMLElement.prototype, "classList", descr); |
| 3107 delete Element.prototype.classList; |
| 3108 } |
| 3109 scope.wrappers.SVGElement = SVGElement; |
| 3110 })(window.ShadowDOMPolyfill); |
| 3111 (function(scope) { |
| 3112 "use strict"; |
| 3113 var mixin = scope.mixin; |
| 3114 var registerWrapper = scope.registerWrapper; |
| 3115 var unwrap = scope.unwrap; |
| 3116 var wrap = scope.wrap; |
| 3117 var OriginalSVGUseElement = window.SVGUseElement; |
| 3118 var SVG_NS = "http://www.w3.org/2000/svg"; |
| 3119 var gWrapper = wrap(document.createElementNS(SVG_NS, "g")); |
| 3120 var useElement = document.createElementNS(SVG_NS, "use"); |
| 3121 var SVGGElement = gWrapper.constructor; |
| 3122 var parentInterfacePrototype = Object.getPrototypeOf(SVGGElement.prototype); |
| 3123 var parentInterface = parentInterfacePrototype.constructor; |
| 3124 function SVGUseElement(impl) { |
| 3125 parentInterface.call(this, impl); |
| 3126 } |
| 3127 SVGUseElement.prototype = Object.create(parentInterfacePrototype); |
| 3128 if ("instanceRoot" in useElement) { |
| 3129 mixin(SVGUseElement.prototype, { |
| 3130 get instanceRoot() { |
| 3131 return wrap(unwrap(this).instanceRoot); |
| 3132 }, |
| 3133 get animatedInstanceRoot() { |
| 3134 return wrap(unwrap(this).animatedInstanceRoot); |
| 3135 } |
| 3136 }); |
| 3137 } |
| 3138 registerWrapper(OriginalSVGUseElement, SVGUseElement, useElement); |
| 3139 scope.wrappers.SVGUseElement = SVGUseElement; |
| 3140 })(window.ShadowDOMPolyfill); |
| 3141 (function(scope) { |
| 3142 "use strict"; |
| 3143 var EventTarget = scope.wrappers.EventTarget; |
| 3144 var mixin = scope.mixin; |
| 3145 var registerWrapper = scope.registerWrapper; |
| 3146 var unsafeUnwrap = scope.unsafeUnwrap; |
| 3147 var wrap = scope.wrap; |
| 3148 var OriginalSVGElementInstance = window.SVGElementInstance; |
| 3149 if (!OriginalSVGElementInstance) return; |
| 3150 function SVGElementInstance(impl) { |
| 3151 EventTarget.call(this, impl); |
| 3152 } |
| 3153 SVGElementInstance.prototype = Object.create(EventTarget.prototype); |
| 3154 mixin(SVGElementInstance.prototype, { |
| 3155 get correspondingElement() { |
| 3156 return wrap(unsafeUnwrap(this).correspondingElement); |
| 3157 }, |
| 3158 get correspondingUseElement() { |
| 3159 return wrap(unsafeUnwrap(this).correspondingUseElement); |
| 3160 }, |
| 3161 get parentNode() { |
| 3162 return wrap(unsafeUnwrap(this).parentNode); |
| 3163 }, |
| 3164 get childNodes() { |
| 3165 throw new Error("Not implemented"); |
| 3166 }, |
| 3167 get firstChild() { |
| 3168 return wrap(unsafeUnwrap(this).firstChild); |
| 3169 }, |
| 3170 get lastChild() { |
| 3171 return wrap(unsafeUnwrap(this).lastChild); |
| 3172 }, |
| 3173 get previousSibling() { |
| 3174 return wrap(unsafeUnwrap(this).previousSibling); |
| 3175 }, |
| 3176 get nextSibling() { |
| 3177 return wrap(unsafeUnwrap(this).nextSibling); |
| 3178 } |
| 3179 }); |
| 3180 registerWrapper(OriginalSVGElementInstance, SVGElementInstance); |
| 3181 scope.wrappers.SVGElementInstance = SVGElementInstance; |
| 3182 })(window.ShadowDOMPolyfill); |
| 3183 (function(scope) { |
| 3184 "use strict"; |
| 3185 var mixin = scope.mixin; |
| 3186 var registerWrapper = scope.registerWrapper; |
| 3187 var setWrapper = scope.setWrapper; |
| 3188 var unsafeUnwrap = scope.unsafeUnwrap; |
| 3189 var unwrap = scope.unwrap; |
| 3190 var unwrapIfNeeded = scope.unwrapIfNeeded; |
| 3191 var wrap = scope.wrap; |
| 3192 var OriginalCanvasRenderingContext2D = window.CanvasRenderingContext2D; |
| 3193 function CanvasRenderingContext2D(impl) { |
| 3194 setWrapper(impl, this); |
| 3195 } |
| 3196 mixin(CanvasRenderingContext2D.prototype, { |
| 3197 get canvas() { |
| 3198 return wrap(unsafeUnwrap(this).canvas); |
| 3199 }, |
| 3200 drawImage: function() { |
| 3201 arguments[0] = unwrapIfNeeded(arguments[0]); |
| 3202 unsafeUnwrap(this).drawImage.apply(unsafeUnwrap(this), arguments); |
| 3203 }, |
| 3204 createPattern: function() { |
| 3205 arguments[0] = unwrap(arguments[0]); |
| 3206 return unsafeUnwrap(this).createPattern.apply(unsafeUnwrap(this), argume
nts); |
| 3207 } |
| 3208 }); |
| 3209 registerWrapper(OriginalCanvasRenderingContext2D, CanvasRenderingContext2D,
document.createElement("canvas").getContext("2d")); |
| 3210 scope.wrappers.CanvasRenderingContext2D = CanvasRenderingContext2D; |
| 3211 })(window.ShadowDOMPolyfill); |
| 3212 (function(scope) { |
| 3213 "use strict"; |
| 3214 var mixin = scope.mixin; |
| 3215 var registerWrapper = scope.registerWrapper; |
| 3216 var setWrapper = scope.setWrapper; |
| 3217 var unsafeUnwrap = scope.unsafeUnwrap; |
| 3218 var unwrapIfNeeded = scope.unwrapIfNeeded; |
| 3219 var wrap = scope.wrap; |
| 3220 var OriginalWebGLRenderingContext = window.WebGLRenderingContext; |
| 3221 if (!OriginalWebGLRenderingContext) return; |
| 3222 function WebGLRenderingContext(impl) { |
| 3223 setWrapper(impl, this); |
| 3224 } |
| 3225 mixin(WebGLRenderingContext.prototype, { |
| 3226 get canvas() { |
| 3227 return wrap(unsafeUnwrap(this).canvas); |
| 3228 }, |
| 3229 texImage2D: function() { |
| 3230 arguments[5] = unwrapIfNeeded(arguments[5]); |
| 3231 unsafeUnwrap(this).texImage2D.apply(unsafeUnwrap(this), arguments); |
| 3232 }, |
| 3233 texSubImage2D: function() { |
| 3234 arguments[6] = unwrapIfNeeded(arguments[6]); |
| 3235 unsafeUnwrap(this).texSubImage2D.apply(unsafeUnwrap(this), arguments); |
| 3236 } |
| 3237 }); |
| 3238 var instanceProperties = /WebKit/.test(navigator.userAgent) ? { |
| 3239 drawingBufferHeight: null, |
| 3240 drawingBufferWidth: null |
| 3241 } : {}; |
| 3242 registerWrapper(OriginalWebGLRenderingContext, WebGLRenderingContext, instan
ceProperties); |
| 3243 scope.wrappers.WebGLRenderingContext = WebGLRenderingContext; |
| 3244 })(window.ShadowDOMPolyfill); |
| 3245 (function(scope) { |
| 3246 "use strict"; |
| 3247 var registerWrapper = scope.registerWrapper; |
| 3248 var setWrapper = scope.setWrapper; |
| 3249 var unsafeUnwrap = scope.unsafeUnwrap; |
| 3250 var unwrap = scope.unwrap; |
| 3251 var unwrapIfNeeded = scope.unwrapIfNeeded; |
| 3252 var wrap = scope.wrap; |
| 3253 var OriginalRange = window.Range; |
| 3254 function Range(impl) { |
| 3255 setWrapper(impl, this); |
| 3256 } |
| 3257 Range.prototype = { |
| 3258 get startContainer() { |
| 3259 return wrap(unsafeUnwrap(this).startContainer); |
| 3260 }, |
| 3261 get endContainer() { |
| 3262 return wrap(unsafeUnwrap(this).endContainer); |
| 3263 }, |
| 3264 get commonAncestorContainer() { |
| 3265 return wrap(unsafeUnwrap(this).commonAncestorContainer); |
| 3266 }, |
| 3267 setStart: function(refNode, offset) { |
| 3268 unsafeUnwrap(this).setStart(unwrapIfNeeded(refNode), offset); |
| 3269 }, |
| 3270 setEnd: function(refNode, offset) { |
| 3271 unsafeUnwrap(this).setEnd(unwrapIfNeeded(refNode), offset); |
| 3272 }, |
| 3273 setStartBefore: function(refNode) { |
| 3274 unsafeUnwrap(this).setStartBefore(unwrapIfNeeded(refNode)); |
| 3275 }, |
| 3276 setStartAfter: function(refNode) { |
| 3277 unsafeUnwrap(this).setStartAfter(unwrapIfNeeded(refNode)); |
| 3278 }, |
| 3279 setEndBefore: function(refNode) { |
| 3280 unsafeUnwrap(this).setEndBefore(unwrapIfNeeded(refNode)); |
| 3281 }, |
| 3282 setEndAfter: function(refNode) { |
| 3283 unsafeUnwrap(this).setEndAfter(unwrapIfNeeded(refNode)); |
| 3284 }, |
| 3285 selectNode: function(refNode) { |
| 3286 unsafeUnwrap(this).selectNode(unwrapIfNeeded(refNode)); |
| 3287 }, |
| 3288 selectNodeContents: function(refNode) { |
| 3289 unsafeUnwrap(this).selectNodeContents(unwrapIfNeeded(refNode)); |
| 3290 }, |
| 3291 compareBoundaryPoints: function(how, sourceRange) { |
| 3292 return unsafeUnwrap(this).compareBoundaryPoints(how, unwrap(sourceRange)
); |
| 3293 }, |
| 3294 extractContents: function() { |
| 3295 return wrap(unsafeUnwrap(this).extractContents()); |
| 3296 }, |
| 3297 cloneContents: function() { |
| 3298 return wrap(unsafeUnwrap(this).cloneContents()); |
| 3299 }, |
| 3300 insertNode: function(node) { |
| 3301 unsafeUnwrap(this).insertNode(unwrapIfNeeded(node)); |
| 3302 }, |
| 3303 surroundContents: function(newParent) { |
| 3304 unsafeUnwrap(this).surroundContents(unwrapIfNeeded(newParent)); |
| 3305 }, |
| 3306 cloneRange: function() { |
| 3307 return wrap(unsafeUnwrap(this).cloneRange()); |
| 3308 }, |
| 3309 isPointInRange: function(node, offset) { |
| 3310 return unsafeUnwrap(this).isPointInRange(unwrapIfNeeded(node), offset); |
| 3311 }, |
| 3312 comparePoint: function(node, offset) { |
| 3313 return unsafeUnwrap(this).comparePoint(unwrapIfNeeded(node), offset); |
| 3314 }, |
| 3315 intersectsNode: function(node) { |
| 3316 return unsafeUnwrap(this).intersectsNode(unwrapIfNeeded(node)); |
| 3317 }, |
| 3318 toString: function() { |
| 3319 return unsafeUnwrap(this).toString(); |
| 3320 } |
| 3321 }; |
| 3322 if (OriginalRange.prototype.createContextualFragment) { |
| 3323 Range.prototype.createContextualFragment = function(html) { |
| 3324 return wrap(unsafeUnwrap(this).createContextualFragment(html)); |
| 3325 }; |
| 3326 } |
| 3327 registerWrapper(window.Range, Range, document.createRange()); |
| 3328 scope.wrappers.Range = Range; |
| 3329 })(window.ShadowDOMPolyfill); |
| 3330 (function(scope) { |
| 3331 "use strict"; |
| 3332 var GetElementsByInterface = scope.GetElementsByInterface; |
| 3333 var ParentNodeInterface = scope.ParentNodeInterface; |
| 3334 var SelectorsInterface = scope.SelectorsInterface; |
| 3335 var mixin = scope.mixin; |
| 3336 var registerObject = scope.registerObject; |
| 3337 var DocumentFragment = registerObject(document.createDocumentFragment()); |
| 3338 mixin(DocumentFragment.prototype, ParentNodeInterface); |
| 3339 mixin(DocumentFragment.prototype, SelectorsInterface); |
| 3340 mixin(DocumentFragment.prototype, GetElementsByInterface); |
| 3341 var Comment = registerObject(document.createComment("")); |
| 3342 scope.wrappers.Comment = Comment; |
| 3343 scope.wrappers.DocumentFragment = DocumentFragment; |
| 3344 })(window.ShadowDOMPolyfill); |
| 3345 (function(scope) { |
| 3346 "use strict"; |
| 3347 var DocumentFragment = scope.wrappers.DocumentFragment; |
| 3348 var TreeScope = scope.TreeScope; |
| 3349 var elementFromPoint = scope.elementFromPoint; |
| 3350 var getInnerHTML = scope.getInnerHTML; |
| 3351 var getTreeScope = scope.getTreeScope; |
| 3352 var mixin = scope.mixin; |
| 3353 var rewrap = scope.rewrap; |
| 3354 var setInnerHTML = scope.setInnerHTML; |
| 3355 var unsafeUnwrap = scope.unsafeUnwrap; |
| 3356 var unwrap = scope.unwrap; |
| 3357 var shadowHostTable = new WeakMap(); |
| 3358 var nextOlderShadowTreeTable = new WeakMap(); |
| 3359 var spaceCharRe = /[ \t\n\r\f]/; |
| 3360 function ShadowRoot(hostWrapper) { |
| 3361 var node = unwrap(unsafeUnwrap(hostWrapper).ownerDocument.createDocumentFr
agment()); |
| 3362 DocumentFragment.call(this, node); |
| 3363 rewrap(node, this); |
| 3364 var oldShadowRoot = hostWrapper.shadowRoot; |
| 3365 nextOlderShadowTreeTable.set(this, oldShadowRoot); |
| 3366 this.treeScope_ = new TreeScope(this, getTreeScope(oldShadowRoot || hostWr
apper)); |
| 3367 shadowHostTable.set(this, hostWrapper); |
| 3368 } |
| 3369 ShadowRoot.prototype = Object.create(DocumentFragment.prototype); |
| 3370 mixin(ShadowRoot.prototype, { |
| 3371 constructor: ShadowRoot, |
| 3372 get innerHTML() { |
| 3373 return getInnerHTML(this); |
| 3374 }, |
| 3375 set innerHTML(value) { |
| 3376 setInnerHTML(this, value); |
| 3377 this.invalidateShadowRenderer(); |
| 3378 }, |
| 3379 get olderShadowRoot() { |
| 3380 return nextOlderShadowTreeTable.get(this) || null; |
| 3381 }, |
| 3382 get host() { |
| 3383 return shadowHostTable.get(this) || null; |
| 3384 }, |
| 3385 invalidateShadowRenderer: function() { |
| 3386 return shadowHostTable.get(this).invalidateShadowRenderer(); |
| 3387 }, |
| 3388 elementFromPoint: function(x, y) { |
| 3389 return elementFromPoint(this, this.ownerDocument, x, y); |
| 3390 }, |
| 3391 getElementById: function(id) { |
| 3392 if (spaceCharRe.test(id)) return null; |
| 3393 return this.querySelector('[id="' + id + '"]'); |
| 3394 } |
| 3395 }); |
| 3396 scope.wrappers.ShadowRoot = ShadowRoot; |
| 3397 })(window.ShadowDOMPolyfill); |
| 3398 (function(scope) { |
| 3399 "use strict"; |
| 3400 var Element = scope.wrappers.Element; |
| 3401 var HTMLContentElement = scope.wrappers.HTMLContentElement; |
| 3402 var HTMLShadowElement = scope.wrappers.HTMLShadowElement; |
| 3403 var Node = scope.wrappers.Node; |
| 3404 var ShadowRoot = scope.wrappers.ShadowRoot; |
| 3405 var assert = scope.assert; |
| 3406 var getTreeScope = scope.getTreeScope; |
| 3407 var mixin = scope.mixin; |
| 3408 var oneOf = scope.oneOf; |
| 3409 var unsafeUnwrap = scope.unsafeUnwrap; |
| 3410 var unwrap = scope.unwrap; |
| 3411 var wrap = scope.wrap; |
| 3412 var ArraySplice = scope.ArraySplice; |
| 3413 function updateWrapperUpAndSideways(wrapper) { |
| 3414 wrapper.previousSibling_ = wrapper.previousSibling; |
| 3415 wrapper.nextSibling_ = wrapper.nextSibling; |
| 3416 wrapper.parentNode_ = wrapper.parentNode; |
| 3417 } |
| 3418 function updateWrapperDown(wrapper) { |
| 3419 wrapper.firstChild_ = wrapper.firstChild; |
| 3420 wrapper.lastChild_ = wrapper.lastChild; |
| 3421 } |
| 3422 function updateAllChildNodes(parentNodeWrapper) { |
| 3423 assert(parentNodeWrapper instanceof Node); |
| 3424 for (var childWrapper = parentNodeWrapper.firstChild; childWrapper; childW
rapper = childWrapper.nextSibling) { |
| 3425 updateWrapperUpAndSideways(childWrapper); |
| 3426 } |
| 3427 updateWrapperDown(parentNodeWrapper); |
| 3428 } |
| 3429 function insertBefore(parentNodeWrapper, newChildWrapper, refChildWrapper) { |
| 3430 var parentNode = unwrap(parentNodeWrapper); |
| 3431 var newChild = unwrap(newChildWrapper); |
| 3432 var refChild = refChildWrapper ? unwrap(refChildWrapper) : null; |
| 3433 remove(newChildWrapper); |
| 3434 updateWrapperUpAndSideways(newChildWrapper); |
| 3435 if (!refChildWrapper) { |
| 3436 parentNodeWrapper.lastChild_ = parentNodeWrapper.lastChild; |
| 3437 if (parentNodeWrapper.lastChild === parentNodeWrapper.firstChild) parent
NodeWrapper.firstChild_ = parentNodeWrapper.firstChild; |
| 3438 var lastChildWrapper = wrap(parentNode.lastChild); |
| 3439 if (lastChildWrapper) lastChildWrapper.nextSibling_ = lastChildWrapper.n
extSibling; |
| 3440 } else { |
| 3441 if (parentNodeWrapper.firstChild === refChildWrapper) parentNodeWrapper.
firstChild_ = refChildWrapper; |
| 3442 refChildWrapper.previousSibling_ = refChildWrapper.previousSibling; |
| 3443 } |
| 3444 scope.originalInsertBefore.call(parentNode, newChild, refChild); |
| 3445 } |
| 3446 function remove(nodeWrapper) { |
| 3447 var node = unwrap(nodeWrapper); |
| 3448 var parentNode = node.parentNode; |
| 3449 if (!parentNode) return; |
| 3450 var parentNodeWrapper = wrap(parentNode); |
| 3451 updateWrapperUpAndSideways(nodeWrapper); |
| 3452 if (nodeWrapper.previousSibling) nodeWrapper.previousSibling.nextSibling_
= nodeWrapper; |
| 3453 if (nodeWrapper.nextSibling) nodeWrapper.nextSibling.previousSibling_ = no
deWrapper; |
| 3454 if (parentNodeWrapper.lastChild === nodeWrapper) parentNodeWrapper.lastChi
ld_ = nodeWrapper; |
| 3455 if (parentNodeWrapper.firstChild === nodeWrapper) parentNodeWrapper.firstC
hild_ = nodeWrapper; |
| 3456 scope.originalRemoveChild.call(parentNode, node); |
| 3457 } |
| 3458 var distributedNodesTable = new WeakMap(); |
| 3459 var destinationInsertionPointsTable = new WeakMap(); |
| 3460 var rendererForHostTable = new WeakMap(); |
| 3461 function resetDistributedNodes(insertionPoint) { |
| 3462 distributedNodesTable.set(insertionPoint, []); |
| 3463 } |
| 3464 function getDistributedNodes(insertionPoint) { |
| 3465 var rv = distributedNodesTable.get(insertionPoint); |
| 3466 if (!rv) distributedNodesTable.set(insertionPoint, rv = []); |
| 3467 return rv; |
| 3468 } |
| 3469 function getChildNodesSnapshot(node) { |
| 3470 var result = [], i = 0; |
| 3471 for (var child = node.firstChild; child; child = child.nextSibling) { |
| 3472 result[i++] = child; |
| 3473 } |
| 3474 return result; |
| 3475 } |
| 3476 var request = oneOf(window, [ "requestAnimationFrame", "mozRequestAnimationF
rame", "webkitRequestAnimationFrame", "setTimeout" ]); |
| 3477 var pendingDirtyRenderers = []; |
| 3478 var renderTimer; |
| 3479 function renderAllPending() { |
| 3480 for (var i = 0; i < pendingDirtyRenderers.length; i++) { |
| 3481 var renderer = pendingDirtyRenderers[i]; |
| 3482 var parentRenderer = renderer.parentRenderer; |
| 3483 if (parentRenderer && parentRenderer.dirty) continue; |
| 3484 renderer.render(); |
| 3485 } |
| 3486 pendingDirtyRenderers = []; |
| 3487 } |
| 3488 function handleRequestAnimationFrame() { |
| 3489 renderTimer = null; |
| 3490 renderAllPending(); |
| 3491 } |
| 3492 function getRendererForHost(host) { |
| 3493 var renderer = rendererForHostTable.get(host); |
| 3494 if (!renderer) { |
| 3495 renderer = new ShadowRenderer(host); |
| 3496 rendererForHostTable.set(host, renderer); |
| 3497 } |
| 3498 return renderer; |
| 3499 } |
| 3500 function getShadowRootAncestor(node) { |
| 3501 var root = getTreeScope(node).root; |
| 3502 if (root instanceof ShadowRoot) return root; |
| 3503 return null; |
| 3504 } |
| 3505 function getRendererForShadowRoot(shadowRoot) { |
| 3506 return getRendererForHost(shadowRoot.host); |
| 3507 } |
| 3508 var spliceDiff = new ArraySplice(); |
| 3509 spliceDiff.equals = function(renderNode, rawNode) { |
| 3510 return unwrap(renderNode.node) === rawNode; |
| 3511 }; |
| 3512 function RenderNode(node) { |
| 3513 this.skip = false; |
| 3514 this.node = node; |
| 3515 this.childNodes = []; |
| 3516 } |
| 3517 RenderNode.prototype = { |
| 3518 append: function(node) { |
| 3519 var rv = new RenderNode(node); |
| 3520 this.childNodes.push(rv); |
| 3521 return rv; |
| 3522 }, |
| 3523 sync: function(opt_added) { |
| 3524 if (this.skip) return; |
| 3525 var nodeWrapper = this.node; |
| 3526 var newChildren = this.childNodes; |
| 3527 var oldChildren = getChildNodesSnapshot(unwrap(nodeWrapper)); |
| 3528 var added = opt_added || new WeakMap(); |
| 3529 var splices = spliceDiff.calculateSplices(newChildren, oldChildren); |
| 3530 var newIndex = 0, oldIndex = 0; |
| 3531 var lastIndex = 0; |
| 3532 for (var i = 0; i < splices.length; i++) { |
| 3533 var splice = splices[i]; |
| 3534 for (;lastIndex < splice.index; lastIndex++) { |
| 3535 oldIndex++; |
| 3536 newChildren[newIndex++].sync(added); |
| 3537 } |
| 3538 var removedCount = splice.removed.length; |
| 3539 for (var j = 0; j < removedCount; j++) { |
| 3540 var wrapper = wrap(oldChildren[oldIndex++]); |
| 3541 if (!added.get(wrapper)) remove(wrapper); |
| 3542 } |
| 3543 var addedCount = splice.addedCount; |
| 3544 var refNode = oldChildren[oldIndex] && wrap(oldChildren[oldIndex]); |
| 3545 for (var j = 0; j < addedCount; j++) { |
| 3546 var newChildRenderNode = newChildren[newIndex++]; |
| 3547 var newChildWrapper = newChildRenderNode.node; |
| 3548 insertBefore(nodeWrapper, newChildWrapper, refNode); |
| 3549 added.set(newChildWrapper, true); |
| 3550 newChildRenderNode.sync(added); |
| 3551 } |
| 3552 lastIndex += addedCount; |
| 3553 } |
| 3554 for (var i = lastIndex; i < newChildren.length; i++) { |
| 3555 newChildren[i].sync(added); |
| 3556 } |
| 3557 } |
| 3558 }; |
| 3559 function ShadowRenderer(host) { |
| 3560 this.host = host; |
| 3561 this.dirty = false; |
| 3562 this.invalidateAttributes(); |
| 3563 this.associateNode(host); |
| 3564 } |
| 3565 ShadowRenderer.prototype = { |
| 3566 render: function(opt_renderNode) { |
| 3567 if (!this.dirty) return; |
| 3568 this.invalidateAttributes(); |
| 3569 var host = this.host; |
| 3570 this.distribution(host); |
| 3571 var renderNode = opt_renderNode || new RenderNode(host); |
| 3572 this.buildRenderTree(renderNode, host); |
| 3573 var topMostRenderer = !opt_renderNode; |
| 3574 if (topMostRenderer) renderNode.sync(); |
| 3575 this.dirty = false; |
| 3576 }, |
| 3577 get parentRenderer() { |
| 3578 return getTreeScope(this.host).renderer; |
| 3579 }, |
| 3580 invalidate: function() { |
| 3581 if (!this.dirty) { |
| 3582 this.dirty = true; |
| 3583 var parentRenderer = this.parentRenderer; |
| 3584 if (parentRenderer) parentRenderer.invalidate(); |
| 3585 pendingDirtyRenderers.push(this); |
| 3586 if (renderTimer) return; |
| 3587 renderTimer = window[request](handleRequestAnimationFrame, 0); |
| 3588 } |
| 3589 }, |
| 3590 distribution: function(root) { |
| 3591 this.resetAllSubtrees(root); |
| 3592 this.distributionResolution(root); |
| 3593 }, |
| 3594 resetAll: function(node) { |
| 3595 if (isInsertionPoint(node)) resetDistributedNodes(node); else resetDesti
nationInsertionPoints(node); |
| 3596 this.resetAllSubtrees(node); |
| 3597 }, |
| 3598 resetAllSubtrees: function(node) { |
| 3599 for (var child = node.firstChild; child; child = child.nextSibling) { |
| 3600 this.resetAll(child); |
| 3601 } |
| 3602 if (node.shadowRoot) this.resetAll(node.shadowRoot); |
| 3603 if (node.olderShadowRoot) this.resetAll(node.olderShadowRoot); |
| 3604 }, |
| 3605 distributionResolution: function(node) { |
| 3606 if (isShadowHost(node)) { |
| 3607 var shadowHost = node; |
| 3608 var pool = poolPopulation(shadowHost); |
| 3609 var shadowTrees = getShadowTrees(shadowHost); |
| 3610 for (var i = 0; i < shadowTrees.length; i++) { |
| 3611 this.poolDistribution(shadowTrees[i], pool); |
| 3612 } |
| 3613 for (var i = shadowTrees.length - 1; i >= 0; i--) { |
| 3614 var shadowTree = shadowTrees[i]; |
| 3615 var shadow = getShadowInsertionPoint(shadowTree); |
| 3616 if (shadow) { |
| 3617 var olderShadowRoot = shadowTree.olderShadowRoot; |
| 3618 if (olderShadowRoot) { |
| 3619 pool = poolPopulation(olderShadowRoot); |
| 3620 } |
| 3621 for (var j = 0; j < pool.length; j++) { |
| 3622 destributeNodeInto(pool[j], shadow); |
| 3623 } |
| 3624 } |
| 3625 this.distributionResolution(shadowTree); |
| 3626 } |
| 3627 } |
| 3628 for (var child = node.firstChild; child; child = child.nextSibling) { |
| 3629 this.distributionResolution(child); |
| 3630 } |
| 3631 }, |
| 3632 poolDistribution: function(node, pool) { |
| 3633 if (node instanceof HTMLShadowElement) return; |
| 3634 if (node instanceof HTMLContentElement) { |
| 3635 var content = node; |
| 3636 this.updateDependentAttributes(content.getAttribute("select")); |
| 3637 var anyDistributed = false; |
| 3638 for (var i = 0; i < pool.length; i++) { |
| 3639 var node = pool[i]; |
| 3640 if (!node) continue; |
| 3641 if (matches(node, content)) { |
| 3642 destributeNodeInto(node, content); |
| 3643 pool[i] = undefined; |
| 3644 anyDistributed = true; |
| 3645 } |
| 3646 } |
| 3647 if (!anyDistributed) { |
| 3648 for (var child = content.firstChild; child; child = child.nextSiblin
g) { |
| 3649 destributeNodeInto(child, content); |
| 3650 } |
| 3651 } |
| 3652 return; |
| 3653 } |
| 3654 for (var child = node.firstChild; child; child = child.nextSibling) { |
| 3655 this.poolDistribution(child, pool); |
| 3656 } |
| 3657 }, |
| 3658 buildRenderTree: function(renderNode, node) { |
| 3659 var children = this.compose(node); |
| 3660 for (var i = 0; i < children.length; i++) { |
| 3661 var child = children[i]; |
| 3662 var childRenderNode = renderNode.append(child); |
| 3663 this.buildRenderTree(childRenderNode, child); |
| 3664 } |
| 3665 if (isShadowHost(node)) { |
| 3666 var renderer = getRendererForHost(node); |
| 3667 renderer.dirty = false; |
| 3668 } |
| 3669 }, |
| 3670 compose: function(node) { |
| 3671 var children = []; |
| 3672 var p = node.shadowRoot || node; |
| 3673 for (var child = p.firstChild; child; child = child.nextSibling) { |
| 3674 if (isInsertionPoint(child)) { |
| 3675 this.associateNode(p); |
| 3676 var distributedNodes = getDistributedNodes(child); |
| 3677 for (var j = 0; j < distributedNodes.length; j++) { |
| 3678 var distributedNode = distributedNodes[j]; |
| 3679 if (isFinalDestination(child, distributedNode)) children.push(dist
ributedNode); |
| 3680 } |
| 3681 } else { |
| 3682 children.push(child); |
| 3683 } |
| 3684 } |
| 3685 return children; |
| 3686 }, |
| 3687 invalidateAttributes: function() { |
| 3688 this.attributes = Object.create(null); |
| 3689 }, |
| 3690 updateDependentAttributes: function(selector) { |
| 3691 if (!selector) return; |
| 3692 var attributes = this.attributes; |
| 3693 if (/\.\w+/.test(selector)) attributes["class"] = true; |
| 3694 if (/#\w+/.test(selector)) attributes["id"] = true; |
| 3695 selector.replace(/\[\s*([^\s=\|~\]]+)/g, function(_, name) { |
| 3696 attributes[name] = true; |
| 3697 }); |
| 3698 }, |
| 3699 dependsOnAttribute: function(name) { |
| 3700 return this.attributes[name]; |
| 3701 }, |
| 3702 associateNode: function(node) { |
| 3703 unsafeUnwrap(node).polymerShadowRenderer_ = this; |
| 3704 } |
| 3705 }; |
| 3706 function poolPopulation(node) { |
| 3707 var pool = []; |
| 3708 for (var child = node.firstChild; child; child = child.nextSibling) { |
| 3709 if (isInsertionPoint(child)) { |
| 3710 pool.push.apply(pool, getDistributedNodes(child)); |
| 3711 } else { |
| 3712 pool.push(child); |
| 3713 } |
| 3714 } |
| 3715 return pool; |
| 3716 } |
| 3717 function getShadowInsertionPoint(node) { |
| 3718 if (node instanceof HTMLShadowElement) return node; |
| 3719 if (node instanceof HTMLContentElement) return null; |
| 3720 for (var child = node.firstChild; child; child = child.nextSibling) { |
| 3721 var res = getShadowInsertionPoint(child); |
| 3722 if (res) return res; |
| 3723 } |
| 3724 return null; |
| 3725 } |
| 3726 function destributeNodeInto(child, insertionPoint) { |
| 3727 getDistributedNodes(insertionPoint).push(child); |
| 3728 var points = destinationInsertionPointsTable.get(child); |
| 3729 if (!points) destinationInsertionPointsTable.set(child, [ insertionPoint ]
); else points.push(insertionPoint); |
| 3730 } |
| 3731 function getDestinationInsertionPoints(node) { |
| 3732 return destinationInsertionPointsTable.get(node); |
| 3733 } |
| 3734 function resetDestinationInsertionPoints(node) { |
| 3735 destinationInsertionPointsTable.set(node, undefined); |
| 3736 } |
| 3737 var selectorStartCharRe = /^(:not\()?[*.#[a-zA-Z_|]/; |
| 3738 function matches(node, contentElement) { |
| 3739 var select = contentElement.getAttribute("select"); |
| 3740 if (!select) return true; |
| 3741 select = select.trim(); |
| 3742 if (!select) return true; |
| 3743 if (!(node instanceof Element)) return false; |
| 3744 if (!selectorStartCharRe.test(select)) return false; |
| 3745 try { |
| 3746 return node.matches(select); |
| 3747 } catch (ex) { |
| 3748 return false; |
| 3749 } |
| 3750 } |
| 3751 function isFinalDestination(insertionPoint, node) { |
| 3752 var points = getDestinationInsertionPoints(node); |
| 3753 return points && points[points.length - 1] === insertionPoint; |
| 3754 } |
| 3755 function isInsertionPoint(node) { |
| 3756 return node instanceof HTMLContentElement || node instanceof HTMLShadowEle
ment; |
| 3757 } |
| 3758 function isShadowHost(shadowHost) { |
| 3759 return shadowHost.shadowRoot; |
| 3760 } |
| 3761 function getShadowTrees(host) { |
| 3762 var trees = []; |
| 3763 for (var tree = host.shadowRoot; tree; tree = tree.olderShadowRoot) { |
| 3764 trees.push(tree); |
| 3765 } |
| 3766 return trees; |
| 3767 } |
| 3768 function render(host) { |
| 3769 new ShadowRenderer(host).render(); |
| 3770 } |
| 3771 Node.prototype.invalidateShadowRenderer = function(force) { |
| 3772 var renderer = unsafeUnwrap(this).polymerShadowRenderer_; |
| 3773 if (renderer) { |
| 3774 renderer.invalidate(); |
| 3775 return true; |
| 3776 } |
| 3777 return false; |
| 3778 }; |
| 3779 HTMLContentElement.prototype.getDistributedNodes = HTMLShadowElement.prototy
pe.getDistributedNodes = function() { |
| 3780 renderAllPending(); |
| 3781 return getDistributedNodes(this); |
| 3782 }; |
| 3783 Element.prototype.getDestinationInsertionPoints = function() { |
| 3784 renderAllPending(); |
| 3785 return getDestinationInsertionPoints(this) || []; |
| 3786 }; |
| 3787 HTMLContentElement.prototype.nodeIsInserted_ = HTMLShadowElement.prototype.n
odeIsInserted_ = function() { |
| 3788 this.invalidateShadowRenderer(); |
| 3789 var shadowRoot = getShadowRootAncestor(this); |
| 3790 var renderer; |
| 3791 if (shadowRoot) renderer = getRendererForShadowRoot(shadowRoot); |
| 3792 unsafeUnwrap(this).polymerShadowRenderer_ = renderer; |
| 3793 if (renderer) renderer.invalidate(); |
| 3794 }; |
| 3795 scope.getRendererForHost = getRendererForHost; |
| 3796 scope.getShadowTrees = getShadowTrees; |
| 3797 scope.renderAllPending = renderAllPending; |
| 3798 scope.getDestinationInsertionPoints = getDestinationInsertionPoints; |
| 3799 scope.visual = { |
| 3800 insertBefore: insertBefore, |
| 3801 remove: remove |
| 3802 }; |
| 3803 })(window.ShadowDOMPolyfill); |
| 3804 (function(scope) { |
| 3805 "use strict"; |
| 3806 var HTMLElement = scope.wrappers.HTMLElement; |
| 3807 var assert = scope.assert; |
| 3808 var mixin = scope.mixin; |
| 3809 var registerWrapper = scope.registerWrapper; |
| 3810 var unwrap = scope.unwrap; |
| 3811 var wrap = scope.wrap; |
| 3812 var elementsWithFormProperty = [ "HTMLButtonElement", "HTMLFieldSetElement",
"HTMLInputElement", "HTMLKeygenElement", "HTMLLabelElement", "HTMLLegendElement
", "HTMLObjectElement", "HTMLOutputElement", "HTMLTextAreaElement" ]; |
| 3813 function createWrapperConstructor(name) { |
| 3814 if (!window[name]) return; |
| 3815 assert(!scope.wrappers[name]); |
| 3816 var GeneratedWrapper = function(node) { |
| 3817 HTMLElement.call(this, node); |
| 3818 }; |
| 3819 GeneratedWrapper.prototype = Object.create(HTMLElement.prototype); |
| 3820 mixin(GeneratedWrapper.prototype, { |
| 3821 get form() { |
| 3822 return wrap(unwrap(this).form); |
| 3823 } |
| 3824 }); |
| 3825 registerWrapper(window[name], GeneratedWrapper, document.createElement(nam
e.slice(4, -7))); |
| 3826 scope.wrappers[name] = GeneratedWrapper; |
| 3827 } |
| 3828 elementsWithFormProperty.forEach(createWrapperConstructor); |
| 3829 })(window.ShadowDOMPolyfill); |
| 3830 (function(scope) { |
| 3831 "use strict"; |
| 3832 var registerWrapper = scope.registerWrapper; |
| 3833 var setWrapper = scope.setWrapper; |
| 3834 var unsafeUnwrap = scope.unsafeUnwrap; |
| 3835 var unwrap = scope.unwrap; |
| 3836 var unwrapIfNeeded = scope.unwrapIfNeeded; |
| 3837 var wrap = scope.wrap; |
| 3838 var OriginalSelection = window.Selection; |
| 3839 function Selection(impl) { |
| 3840 setWrapper(impl, this); |
| 3841 } |
| 3842 Selection.prototype = { |
| 3843 get anchorNode() { |
| 3844 return wrap(unsafeUnwrap(this).anchorNode); |
| 3845 }, |
| 3846 get focusNode() { |
| 3847 return wrap(unsafeUnwrap(this).focusNode); |
| 3848 }, |
| 3849 addRange: function(range) { |
| 3850 unsafeUnwrap(this).addRange(unwrap(range)); |
| 3851 }, |
| 3852 collapse: function(node, index) { |
| 3853 unsafeUnwrap(this).collapse(unwrapIfNeeded(node), index); |
| 3854 }, |
| 3855 containsNode: function(node, allowPartial) { |
| 3856 return unsafeUnwrap(this).containsNode(unwrapIfNeeded(node), allowPartia
l); |
| 3857 }, |
| 3858 extend: function(node, offset) { |
| 3859 unsafeUnwrap(this).extend(unwrapIfNeeded(node), offset); |
| 3860 }, |
| 3861 getRangeAt: function(index) { |
| 3862 return wrap(unsafeUnwrap(this).getRangeAt(index)); |
| 3863 }, |
| 3864 removeRange: function(range) { |
| 3865 unsafeUnwrap(this).removeRange(unwrap(range)); |
| 3866 }, |
| 3867 selectAllChildren: function(node) { |
| 3868 unsafeUnwrap(this).selectAllChildren(unwrapIfNeeded(node)); |
| 3869 }, |
| 3870 toString: function() { |
| 3871 return unsafeUnwrap(this).toString(); |
| 3872 } |
| 3873 }; |
| 3874 registerWrapper(window.Selection, Selection, window.getSelection()); |
| 3875 scope.wrappers.Selection = Selection; |
| 3876 })(window.ShadowDOMPolyfill); |
| 3877 (function(scope) { |
| 3878 "use strict"; |
| 3879 var GetElementsByInterface = scope.GetElementsByInterface; |
| 3880 var Node = scope.wrappers.Node; |
| 3881 var ParentNodeInterface = scope.ParentNodeInterface; |
| 3882 var Selection = scope.wrappers.Selection; |
| 3883 var SelectorsInterface = scope.SelectorsInterface; |
| 3884 var ShadowRoot = scope.wrappers.ShadowRoot; |
| 3885 var TreeScope = scope.TreeScope; |
| 3886 var cloneNode = scope.cloneNode; |
| 3887 var defineWrapGetter = scope.defineWrapGetter; |
| 3888 var elementFromPoint = scope.elementFromPoint; |
| 3889 var forwardMethodsToWrapper = scope.forwardMethodsToWrapper; |
| 3890 var matchesNames = scope.matchesNames; |
| 3891 var mixin = scope.mixin; |
| 3892 var registerWrapper = scope.registerWrapper; |
| 3893 var renderAllPending = scope.renderAllPending; |
| 3894 var rewrap = scope.rewrap; |
| 3895 var setWrapper = scope.setWrapper; |
| 3896 var unsafeUnwrap = scope.unsafeUnwrap; |
| 3897 var unwrap = scope.unwrap; |
| 3898 var wrap = scope.wrap; |
| 3899 var wrapEventTargetMethods = scope.wrapEventTargetMethods; |
| 3900 var wrapNodeList = scope.wrapNodeList; |
| 3901 var implementationTable = new WeakMap(); |
| 3902 function Document(node) { |
| 3903 Node.call(this, node); |
| 3904 this.treeScope_ = new TreeScope(this, null); |
| 3905 } |
| 3906 Document.prototype = Object.create(Node.prototype); |
| 3907 defineWrapGetter(Document, "documentElement"); |
| 3908 defineWrapGetter(Document, "body"); |
| 3909 defineWrapGetter(Document, "head"); |
| 3910 function wrapMethod(name) { |
| 3911 var original = document[name]; |
| 3912 Document.prototype[name] = function() { |
| 3913 return wrap(original.apply(unsafeUnwrap(this), arguments)); |
| 3914 }; |
| 3915 } |
| 3916 [ "createComment", "createDocumentFragment", "createElement", "createElement
NS", "createEvent", "createEventNS", "createRange", "createTextNode", "getElemen
tById" ].forEach(wrapMethod); |
| 3917 var originalAdoptNode = document.adoptNode; |
| 3918 function adoptNodeNoRemove(node, doc) { |
| 3919 originalAdoptNode.call(unsafeUnwrap(doc), unwrap(node)); |
| 3920 adoptSubtree(node, doc); |
| 3921 } |
| 3922 function adoptSubtree(node, doc) { |
| 3923 if (node.shadowRoot) doc.adoptNode(node.shadowRoot); |
| 3924 if (node instanceof ShadowRoot) adoptOlderShadowRoots(node, doc); |
| 3925 for (var child = node.firstChild; child; child = child.nextSibling) { |
| 3926 adoptSubtree(child, doc); |
| 3927 } |
| 3928 } |
| 3929 function adoptOlderShadowRoots(shadowRoot, doc) { |
| 3930 var oldShadowRoot = shadowRoot.olderShadowRoot; |
| 3931 if (oldShadowRoot) doc.adoptNode(oldShadowRoot); |
| 3932 } |
| 3933 var originalGetSelection = document.getSelection; |
| 3934 mixin(Document.prototype, { |
| 3935 adoptNode: function(node) { |
| 3936 if (node.parentNode) node.parentNode.removeChild(node); |
| 3937 adoptNodeNoRemove(node, this); |
| 3938 return node; |
| 3939 }, |
| 3940 elementFromPoint: function(x, y) { |
| 3941 return elementFromPoint(this, this, x, y); |
| 3942 }, |
| 3943 importNode: function(node, deep) { |
| 3944 return cloneNode(node, deep, unsafeUnwrap(this)); |
| 3945 }, |
| 3946 getSelection: function() { |
| 3947 renderAllPending(); |
| 3948 return new Selection(originalGetSelection.call(unwrap(this))); |
| 3949 }, |
| 3950 getElementsByName: function(name) { |
| 3951 return SelectorsInterface.querySelectorAll.call(this, "[name=" + JSON.st
ringify(String(name)) + "]"); |
| 3952 } |
| 3953 }); |
| 3954 if (document.registerElement) { |
| 3955 var originalRegisterElement = document.registerElement; |
| 3956 Document.prototype.registerElement = function(tagName, object) { |
| 3957 var prototype, extendsOption; |
| 3958 if (object !== undefined) { |
| 3959 prototype = object.prototype; |
| 3960 extendsOption = object.extends; |
| 3961 } |
| 3962 if (!prototype) prototype = Object.create(HTMLElement.prototype); |
| 3963 if (scope.nativePrototypeTable.get(prototype)) { |
| 3964 throw new Error("NotSupportedError"); |
| 3965 } |
| 3966 var proto = Object.getPrototypeOf(prototype); |
| 3967 var nativePrototype; |
| 3968 var prototypes = []; |
| 3969 while (proto) { |
| 3970 nativePrototype = scope.nativePrototypeTable.get(proto); |
| 3971 if (nativePrototype) break; |
| 3972 prototypes.push(proto); |
| 3973 proto = Object.getPrototypeOf(proto); |
| 3974 } |
| 3975 if (!nativePrototype) { |
| 3976 throw new Error("NotSupportedError"); |
| 3977 } |
| 3978 var newPrototype = Object.create(nativePrototype); |
| 3979 for (var i = prototypes.length - 1; i >= 0; i--) { |
| 3980 newPrototype = Object.create(newPrototype); |
| 3981 } |
| 3982 [ "createdCallback", "attachedCallback", "detachedCallback", "attributeC
hangedCallback" ].forEach(function(name) { |
| 3983 var f = prototype[name]; |
| 3984 if (!f) return; |
| 3985 newPrototype[name] = function() { |
| 3986 if (!(wrap(this) instanceof CustomElementConstructor)) { |
| 3987 rewrap(this); |
| 3988 } |
| 3989 f.apply(wrap(this), arguments); |
| 3990 }; |
| 3991 }); |
| 3992 var p = { |
| 3993 prototype: newPrototype |
| 3994 }; |
| 3995 if (extendsOption) p.extends = extendsOption; |
| 3996 function CustomElementConstructor(node) { |
| 3997 if (!node) { |
| 3998 if (extendsOption) { |
| 3999 return document.createElement(extendsOption, tagName); |
| 4000 } else { |
| 4001 return document.createElement(tagName); |
| 4002 } |
| 4003 } |
| 4004 setWrapper(node, this); |
| 4005 } |
| 4006 CustomElementConstructor.prototype = prototype; |
| 4007 CustomElementConstructor.prototype.constructor = CustomElementConstructo
r; |
| 4008 scope.constructorTable.set(newPrototype, CustomElementConstructor); |
| 4009 scope.nativePrototypeTable.set(prototype, newPrototype); |
| 4010 var nativeConstructor = originalRegisterElement.call(unwrap(this), tagNa
me, p); |
| 4011 return CustomElementConstructor; |
| 4012 }; |
| 4013 forwardMethodsToWrapper([ window.HTMLDocument || window.Document ], [ "reg
isterElement" ]); |
| 4014 } |
| 4015 forwardMethodsToWrapper([ window.HTMLBodyElement, window.HTMLDocument || win
dow.Document, window.HTMLHeadElement, window.HTMLHtmlElement ], [ "appendChild",
"compareDocumentPosition", "contains", "getElementsByClassName", "getElementsBy
TagName", "getElementsByTagNameNS", "insertBefore", "querySelector", "querySelec
torAll", "removeChild", "replaceChild" ].concat(matchesNames)); |
| 4016 forwardMethodsToWrapper([ window.HTMLDocument || window.Document ], [ "adopt
Node", "importNode", "contains", "createComment", "createDocumentFragment", "cre
ateElement", "createElementNS", "createEvent", "createEventNS", "createRange", "
createTextNode", "elementFromPoint", "getElementById", "getElementsByName", "get
Selection" ]); |
| 4017 mixin(Document.prototype, GetElementsByInterface); |
| 4018 mixin(Document.prototype, ParentNodeInterface); |
| 4019 mixin(Document.prototype, SelectorsInterface); |
| 4020 mixin(Document.prototype, { |
| 4021 get implementation() { |
| 4022 var implementation = implementationTable.get(this); |
| 4023 if (implementation) return implementation; |
| 4024 implementation = new DOMImplementation(unwrap(this).implementation); |
| 4025 implementationTable.set(this, implementation); |
| 4026 return implementation; |
| 4027 }, |
| 4028 get defaultView() { |
| 4029 return wrap(unwrap(this).defaultView); |
| 4030 } |
| 4031 }); |
| 4032 registerWrapper(window.Document, Document, document.implementation.createHTM
LDocument("")); |
| 4033 if (window.HTMLDocument) registerWrapper(window.HTMLDocument, Document); |
| 4034 wrapEventTargetMethods([ window.HTMLBodyElement, window.HTMLDocument || wind
ow.Document, window.HTMLHeadElement ]); |
| 4035 function DOMImplementation(impl) { |
| 4036 setWrapper(impl, this); |
| 4037 } |
| 4038 function wrapImplMethod(constructor, name) { |
| 4039 var original = document.implementation[name]; |
| 4040 constructor.prototype[name] = function() { |
| 4041 return wrap(original.apply(unsafeUnwrap(this), arguments)); |
| 4042 }; |
| 4043 } |
| 4044 function forwardImplMethod(constructor, name) { |
| 4045 var original = document.implementation[name]; |
| 4046 constructor.prototype[name] = function() { |
| 4047 return original.apply(unsafeUnwrap(this), arguments); |
| 4048 }; |
| 4049 } |
| 4050 wrapImplMethod(DOMImplementation, "createDocumentType"); |
| 4051 wrapImplMethod(DOMImplementation, "createDocument"); |
| 4052 wrapImplMethod(DOMImplementation, "createHTMLDocument"); |
| 4053 forwardImplMethod(DOMImplementation, "hasFeature"); |
| 4054 registerWrapper(window.DOMImplementation, DOMImplementation); |
| 4055 forwardMethodsToWrapper([ window.DOMImplementation ], [ "createDocumentType"
, "createDocument", "createHTMLDocument", "hasFeature" ]); |
| 4056 scope.adoptNodeNoRemove = adoptNodeNoRemove; |
| 4057 scope.wrappers.DOMImplementation = DOMImplementation; |
| 4058 scope.wrappers.Document = Document; |
| 4059 })(window.ShadowDOMPolyfill); |
| 4060 (function(scope) { |
| 4061 "use strict"; |
| 4062 var EventTarget = scope.wrappers.EventTarget; |
| 4063 var Selection = scope.wrappers.Selection; |
| 4064 var mixin = scope.mixin; |
| 4065 var registerWrapper = scope.registerWrapper; |
| 4066 var renderAllPending = scope.renderAllPending; |
| 4067 var unwrap = scope.unwrap; |
| 4068 var unwrapIfNeeded = scope.unwrapIfNeeded; |
| 4069 var wrap = scope.wrap; |
| 4070 var OriginalWindow = window.Window; |
| 4071 var originalGetComputedStyle = window.getComputedStyle; |
| 4072 var originalGetDefaultComputedStyle = window.getDefaultComputedStyle; |
| 4073 var originalGetSelection = window.getSelection; |
| 4074 function Window(impl) { |
| 4075 EventTarget.call(this, impl); |
| 4076 } |
| 4077 Window.prototype = Object.create(EventTarget.prototype); |
| 4078 OriginalWindow.prototype.getComputedStyle = function(el, pseudo) { |
| 4079 return wrap(this || window).getComputedStyle(unwrapIfNeeded(el), pseudo); |
| 4080 }; |
| 4081 if (originalGetDefaultComputedStyle) { |
| 4082 OriginalWindow.prototype.getDefaultComputedStyle = function(el, pseudo) { |
| 4083 return wrap(this || window).getDefaultComputedStyle(unwrapIfNeeded(el),
pseudo); |
| 4084 }; |
| 4085 } |
| 4086 OriginalWindow.prototype.getSelection = function() { |
| 4087 return wrap(this || window).getSelection(); |
| 4088 }; |
| 4089 delete window.getComputedStyle; |
| 4090 delete window.getDefaultComputedStyle; |
| 4091 delete window.getSelection; |
| 4092 [ "addEventListener", "removeEventListener", "dispatchEvent" ].forEach(funct
ion(name) { |
| 4093 OriginalWindow.prototype[name] = function() { |
| 4094 var w = wrap(this || window); |
| 4095 return w[name].apply(w, arguments); |
| 4096 }; |
| 4097 delete window[name]; |
| 4098 }); |
| 4099 mixin(Window.prototype, { |
| 4100 getComputedStyle: function(el, pseudo) { |
| 4101 renderAllPending(); |
| 4102 return originalGetComputedStyle.call(unwrap(this), unwrapIfNeeded(el), p
seudo); |
| 4103 }, |
| 4104 getSelection: function() { |
| 4105 renderAllPending(); |
| 4106 return new Selection(originalGetSelection.call(unwrap(this))); |
| 4107 }, |
| 4108 get document() { |
| 4109 return wrap(unwrap(this).document); |
| 4110 } |
| 4111 }); |
| 4112 if (originalGetDefaultComputedStyle) { |
| 4113 Window.prototype.getDefaultComputedStyle = function(el, pseudo) { |
| 4114 renderAllPending(); |
| 4115 return originalGetDefaultComputedStyle.call(unwrap(this), unwrapIfNeeded
(el), pseudo); |
| 4116 }; |
| 4117 } |
| 4118 registerWrapper(OriginalWindow, Window, window); |
| 4119 scope.wrappers.Window = Window; |
| 4120 })(window.ShadowDOMPolyfill); |
| 4121 (function(scope) { |
| 4122 "use strict"; |
| 4123 var unwrap = scope.unwrap; |
| 4124 var OriginalDataTransfer = window.DataTransfer || window.Clipboard; |
| 4125 var OriginalDataTransferSetDragImage = OriginalDataTransfer.prototype.setDra
gImage; |
| 4126 if (OriginalDataTransferSetDragImage) { |
| 4127 OriginalDataTransfer.prototype.setDragImage = function(image, x, y) { |
| 4128 OriginalDataTransferSetDragImage.call(this, unwrap(image), x, y); |
| 4129 }; |
| 4130 } |
| 4131 })(window.ShadowDOMPolyfill); |
| 4132 (function(scope) { |
| 4133 "use strict"; |
| 4134 var registerWrapper = scope.registerWrapper; |
| 4135 var setWrapper = scope.setWrapper; |
| 4136 var unwrap = scope.unwrap; |
| 4137 var OriginalFormData = window.FormData; |
| 4138 if (!OriginalFormData) return; |
| 4139 function FormData(formElement) { |
| 4140 var impl; |
| 4141 if (formElement instanceof OriginalFormData) { |
| 4142 impl = formElement; |
| 4143 } else { |
| 4144 impl = new OriginalFormData(formElement && unwrap(formElement)); |
| 4145 } |
| 4146 setWrapper(impl, this); |
| 4147 } |
| 4148 registerWrapper(OriginalFormData, FormData, new OriginalFormData()); |
| 4149 scope.wrappers.FormData = FormData; |
| 4150 })(window.ShadowDOMPolyfill); |
| 4151 (function(scope) { |
| 4152 "use strict"; |
| 4153 var unwrapIfNeeded = scope.unwrapIfNeeded; |
| 4154 var originalSend = XMLHttpRequest.prototype.send; |
| 4155 XMLHttpRequest.prototype.send = function(obj) { |
| 4156 return originalSend.call(this, unwrapIfNeeded(obj)); |
| 4157 }; |
| 4158 })(window.ShadowDOMPolyfill); |
| 4159 (function(scope) { |
| 4160 "use strict"; |
| 4161 var isWrapperFor = scope.isWrapperFor; |
| 4162 var elements = { |
| 4163 a: "HTMLAnchorElement", |
| 4164 area: "HTMLAreaElement", |
| 4165 audio: "HTMLAudioElement", |
| 4166 base: "HTMLBaseElement", |
| 4167 body: "HTMLBodyElement", |
| 4168 br: "HTMLBRElement", |
| 4169 button: "HTMLButtonElement", |
| 4170 canvas: "HTMLCanvasElement", |
| 4171 caption: "HTMLTableCaptionElement", |
| 4172 col: "HTMLTableColElement", |
| 4173 content: "HTMLContentElement", |
| 4174 data: "HTMLDataElement", |
| 4175 datalist: "HTMLDataListElement", |
| 4176 del: "HTMLModElement", |
| 4177 dir: "HTMLDirectoryElement", |
| 4178 div: "HTMLDivElement", |
| 4179 dl: "HTMLDListElement", |
| 4180 embed: "HTMLEmbedElement", |
| 4181 fieldset: "HTMLFieldSetElement", |
| 4182 font: "HTMLFontElement", |
| 4183 form: "HTMLFormElement", |
| 4184 frame: "HTMLFrameElement", |
| 4185 frameset: "HTMLFrameSetElement", |
| 4186 h1: "HTMLHeadingElement", |
| 4187 head: "HTMLHeadElement", |
| 4188 hr: "HTMLHRElement", |
| 4189 html: "HTMLHtmlElement", |
| 4190 iframe: "HTMLIFrameElement", |
| 4191 img: "HTMLImageElement", |
| 4192 input: "HTMLInputElement", |
| 4193 keygen: "HTMLKeygenElement", |
| 4194 label: "HTMLLabelElement", |
| 4195 legend: "HTMLLegendElement", |
| 4196 li: "HTMLLIElement", |
| 4197 link: "HTMLLinkElement", |
| 4198 map: "HTMLMapElement", |
| 4199 marquee: "HTMLMarqueeElement", |
| 4200 menu: "HTMLMenuElement", |
| 4201 menuitem: "HTMLMenuItemElement", |
| 4202 meta: "HTMLMetaElement", |
| 4203 meter: "HTMLMeterElement", |
| 4204 object: "HTMLObjectElement", |
| 4205 ol: "HTMLOListElement", |
| 4206 optgroup: "HTMLOptGroupElement", |
| 4207 option: "HTMLOptionElement", |
| 4208 output: "HTMLOutputElement", |
| 4209 p: "HTMLParagraphElement", |
| 4210 param: "HTMLParamElement", |
| 4211 pre: "HTMLPreElement", |
| 4212 progress: "HTMLProgressElement", |
| 4213 q: "HTMLQuoteElement", |
| 4214 script: "HTMLScriptElement", |
| 4215 select: "HTMLSelectElement", |
| 4216 shadow: "HTMLShadowElement", |
| 4217 source: "HTMLSourceElement", |
| 4218 span: "HTMLSpanElement", |
| 4219 style: "HTMLStyleElement", |
| 4220 table: "HTMLTableElement", |
| 4221 tbody: "HTMLTableSectionElement", |
| 4222 template: "HTMLTemplateElement", |
| 4223 textarea: "HTMLTextAreaElement", |
| 4224 thead: "HTMLTableSectionElement", |
| 4225 time: "HTMLTimeElement", |
| 4226 title: "HTMLTitleElement", |
| 4227 tr: "HTMLTableRowElement", |
| 4228 track: "HTMLTrackElement", |
| 4229 ul: "HTMLUListElement", |
| 4230 video: "HTMLVideoElement" |
| 4231 }; |
| 4232 function overrideConstructor(tagName) { |
| 4233 var nativeConstructorName = elements[tagName]; |
| 4234 var nativeConstructor = window[nativeConstructorName]; |
| 4235 if (!nativeConstructor) return; |
| 4236 var element = document.createElement(tagName); |
| 4237 var wrapperConstructor = element.constructor; |
| 4238 window[nativeConstructorName] = wrapperConstructor; |
| 4239 } |
| 4240 Object.keys(elements).forEach(overrideConstructor); |
| 4241 Object.getOwnPropertyNames(scope.wrappers).forEach(function(name) { |
| 4242 window[name] = scope.wrappers[name]; |
| 4243 }); |
| 4244 })(window.ShadowDOMPolyfill); |
| 4245 (function(scope) { |
| 4246 var ShadowCSS = { |
| 4247 strictStyling: false, |
| 4248 registry: {}, |
| 4249 shimStyling: function(root, name, extendsName) { |
| 4250 var scopeStyles = this.prepareRoot(root, name, extendsName); |
| 4251 var typeExtension = this.isTypeExtension(extendsName); |
| 4252 var scopeSelector = this.makeScopeSelector(name, typeExtension); |
| 4253 var cssText = stylesToCssText(scopeStyles, true); |
| 4254 cssText = this.scopeCssText(cssText, scopeSelector); |
| 4255 if (root) { |
| 4256 root.shimmedStyle = cssText; |
| 4257 } |
| 4258 this.addCssToDocument(cssText, name); |
| 4259 }, |
| 4260 shimStyle: function(style, selector) { |
| 4261 return this.shimCssText(style.textContent, selector); |
| 4262 }, |
| 4263 shimCssText: function(cssText, selector) { |
| 4264 cssText = this.insertDirectives(cssText); |
| 4265 return this.scopeCssText(cssText, selector); |
| 4266 }, |
| 4267 makeScopeSelector: function(name, typeExtension) { |
| 4268 if (name) { |
| 4269 return typeExtension ? "[is=" + name + "]" : name; |
| 4270 } |
| 4271 return ""; |
| 4272 }, |
| 4273 isTypeExtension: function(extendsName) { |
| 4274 return extendsName && extendsName.indexOf("-") < 0; |
| 4275 }, |
| 4276 prepareRoot: function(root, name, extendsName) { |
| 4277 var def = this.registerRoot(root, name, extendsName); |
| 4278 this.replaceTextInStyles(def.rootStyles, this.insertDirectives); |
| 4279 this.removeStyles(root, def.rootStyles); |
| 4280 if (this.strictStyling) { |
| 4281 this.applyScopeToContent(root, name); |
| 4282 } |
| 4283 return def.scopeStyles; |
| 4284 }, |
| 4285 removeStyles: function(root, styles) { |
| 4286 for (var i = 0, l = styles.length, s; i < l && (s = styles[i]); i++) { |
| 4287 s.parentNode.removeChild(s); |
| 4288 } |
| 4289 }, |
| 4290 registerRoot: function(root, name, extendsName) { |
| 4291 var def = this.registry[name] = { |
| 4292 root: root, |
| 4293 name: name, |
| 4294 extendsName: extendsName |
| 4295 }; |
| 4296 var styles = this.findStyles(root); |
| 4297 def.rootStyles = styles; |
| 4298 def.scopeStyles = def.rootStyles; |
| 4299 var extendee = this.registry[def.extendsName]; |
| 4300 if (extendee) { |
| 4301 def.scopeStyles = extendee.scopeStyles.concat(def.scopeStyles); |
| 4302 } |
| 4303 return def; |
| 4304 }, |
| 4305 findStyles: function(root) { |
| 4306 if (!root) { |
| 4307 return []; |
| 4308 } |
| 4309 var styles = root.querySelectorAll("style"); |
| 4310 return Array.prototype.filter.call(styles, function(s) { |
| 4311 return !s.hasAttribute(NO_SHIM_ATTRIBUTE); |
| 4312 }); |
| 4313 }, |
| 4314 applyScopeToContent: function(root, name) { |
| 4315 if (root) { |
| 4316 Array.prototype.forEach.call(root.querySelectorAll("*"), function(node
) { |
| 4317 node.setAttribute(name, ""); |
| 4318 }); |
| 4319 Array.prototype.forEach.call(root.querySelectorAll("template"), functi
on(template) { |
| 4320 this.applyScopeToContent(template.content, name); |
| 4321 }, this); |
| 4322 } |
| 4323 }, |
| 4324 insertDirectives: function(cssText) { |
| 4325 cssText = this.insertPolyfillDirectivesInCssText(cssText); |
| 4326 return this.insertPolyfillRulesInCssText(cssText); |
| 4327 }, |
| 4328 insertPolyfillDirectivesInCssText: function(cssText) { |
| 4329 cssText = cssText.replace(cssCommentNextSelectorRe, function(match, p1)
{ |
| 4330 return p1.slice(0, -2) + "{"; |
| 4331 }); |
| 4332 return cssText.replace(cssContentNextSelectorRe, function(match, p1) { |
| 4333 return p1 + " {"; |
| 4334 }); |
| 4335 }, |
| 4336 insertPolyfillRulesInCssText: function(cssText) { |
| 4337 cssText = cssText.replace(cssCommentRuleRe, function(match, p1) { |
| 4338 return p1.slice(0, -1); |
| 4339 }); |
| 4340 return cssText.replace(cssContentRuleRe, function(match, p1, p2, p3) { |
| 4341 var rule = match.replace(p1, "").replace(p2, ""); |
| 4342 return p3 + rule; |
| 4343 }); |
| 4344 }, |
| 4345 scopeCssText: function(cssText, scopeSelector) { |
| 4346 var unscoped = this.extractUnscopedRulesFromCssText(cssText); |
| 4347 cssText = this.insertPolyfillHostInCssText(cssText); |
| 4348 cssText = this.convertColonHost(cssText); |
| 4349 cssText = this.convertColonHostContext(cssText); |
| 4350 cssText = this.convertShadowDOMSelectors(cssText); |
| 4351 if (scopeSelector) { |
| 4352 var self = this, cssText; |
| 4353 withCssRules(cssText, function(rules) { |
| 4354 cssText = self.scopeRules(rules, scopeSelector); |
| 4355 }); |
| 4356 } |
| 4357 cssText = cssText + "\n" + unscoped; |
| 4358 return cssText.trim(); |
| 4359 }, |
| 4360 extractUnscopedRulesFromCssText: function(cssText) { |
| 4361 var r = "", m; |
| 4362 while (m = cssCommentUnscopedRuleRe.exec(cssText)) { |
| 4363 r += m[1].slice(0, -1) + "\n\n"; |
| 4364 } |
| 4365 while (m = cssContentUnscopedRuleRe.exec(cssText)) { |
| 4366 r += m[0].replace(m[2], "").replace(m[1], m[3]) + "\n\n"; |
| 4367 } |
| 4368 return r; |
| 4369 }, |
| 4370 convertColonHost: function(cssText) { |
| 4371 return this.convertColonRule(cssText, cssColonHostRe, this.colonHostPart
Replacer); |
| 4372 }, |
| 4373 convertColonHostContext: function(cssText) { |
| 4374 return this.convertColonRule(cssText, cssColonHostContextRe, this.colonH
ostContextPartReplacer); |
| 4375 }, |
| 4376 convertColonRule: function(cssText, regExp, partReplacer) { |
| 4377 return cssText.replace(regExp, function(m, p1, p2, p3) { |
| 4378 p1 = polyfillHostNoCombinator; |
| 4379 if (p2) { |
| 4380 var parts = p2.split(","), r = []; |
| 4381 for (var i = 0, l = parts.length, p; i < l && (p = parts[i]); i++) { |
| 4382 p = p.trim(); |
| 4383 r.push(partReplacer(p1, p, p3)); |
| 4384 } |
| 4385 return r.join(","); |
| 4386 } else { |
| 4387 return p1 + p3; |
| 4388 } |
| 4389 }); |
| 4390 }, |
| 4391 colonHostContextPartReplacer: function(host, part, suffix) { |
| 4392 if (part.match(polyfillHost)) { |
| 4393 return this.colonHostPartReplacer(host, part, suffix); |
| 4394 } else { |
| 4395 return host + part + suffix + ", " + part + " " + host + suffix; |
| 4396 } |
| 4397 }, |
| 4398 colonHostPartReplacer: function(host, part, suffix) { |
| 4399 return host + part.replace(polyfillHost, "") + suffix; |
| 4400 }, |
| 4401 convertShadowDOMSelectors: function(cssText) { |
| 4402 for (var i = 0; i < shadowDOMSelectorsRe.length; i++) { |
| 4403 cssText = cssText.replace(shadowDOMSelectorsRe[i], " "); |
| 4404 } |
| 4405 return cssText; |
| 4406 }, |
| 4407 scopeRules: function(cssRules, scopeSelector) { |
| 4408 var cssText = ""; |
| 4409 if (cssRules) { |
| 4410 Array.prototype.forEach.call(cssRules, function(rule) { |
| 4411 if (rule.selectorText && (rule.style && rule.style.cssText !== undef
ined)) { |
| 4412 cssText += this.scopeSelector(rule.selectorText, scopeSelector, th
is.strictStyling) + " {\n "; |
| 4413 cssText += this.propertiesFromRule(rule) + "\n}\n\n"; |
| 4414 } else if (rule.type === CSSRule.MEDIA_RULE) { |
| 4415 cssText += "@media " + rule.media.mediaText + " {\n"; |
| 4416 cssText += this.scopeRules(rule.cssRules, scopeSelector); |
| 4417 cssText += "\n}\n\n"; |
| 4418 } else { |
| 4419 try { |
| 4420 if (rule.cssText) { |
| 4421 cssText += rule.cssText + "\n\n"; |
| 4422 } |
| 4423 } catch (x) { |
| 4424 if (rule.type === CSSRule.KEYFRAMES_RULE && rule.cssRules) { |
| 4425 cssText += this.ieSafeCssTextFromKeyFrameRule(rule); |
| 4426 } |
| 4427 } |
| 4428 } |
| 4429 }, this); |
| 4430 } |
| 4431 return cssText; |
| 4432 }, |
| 4433 ieSafeCssTextFromKeyFrameRule: function(rule) { |
| 4434 var cssText = "@keyframes " + rule.name + " {"; |
| 4435 Array.prototype.forEach.call(rule.cssRules, function(rule) { |
| 4436 cssText += " " + rule.keyText + " {" + rule.style.cssText + "}"; |
| 4437 }); |
| 4438 cssText += " }"; |
| 4439 return cssText; |
| 4440 }, |
| 4441 scopeSelector: function(selector, scopeSelector, strict) { |
| 4442 var r = [], parts = selector.split(","); |
| 4443 parts.forEach(function(p) { |
| 4444 p = p.trim(); |
| 4445 if (this.selectorNeedsScoping(p, scopeSelector)) { |
| 4446 p = strict && !p.match(polyfillHostNoCombinator) ? this.applyStrictS
electorScope(p, scopeSelector) : this.applySelectorScope(p, scopeSelector); |
| 4447 } |
| 4448 r.push(p); |
| 4449 }, this); |
| 4450 return r.join(", "); |
| 4451 }, |
| 4452 selectorNeedsScoping: function(selector, scopeSelector) { |
| 4453 if (Array.isArray(scopeSelector)) { |
| 4454 return true; |
| 4455 } |
| 4456 var re = this.makeScopeMatcher(scopeSelector); |
| 4457 return !selector.match(re); |
| 4458 }, |
| 4459 makeScopeMatcher: function(scopeSelector) { |
| 4460 scopeSelector = scopeSelector.replace(/\[/g, "\\[").replace(/\[/g, "\\]"
); |
| 4461 return new RegExp("^(" + scopeSelector + ")" + selectorReSuffix, "m"); |
| 4462 }, |
| 4463 applySelectorScope: function(selector, selectorScope) { |
| 4464 return Array.isArray(selectorScope) ? this.applySelectorScopeList(select
or, selectorScope) : this.applySimpleSelectorScope(selector, selectorScope); |
| 4465 }, |
| 4466 applySelectorScopeList: function(selector, scopeSelectorList) { |
| 4467 var r = []; |
| 4468 for (var i = 0, s; s = scopeSelectorList[i]; i++) { |
| 4469 r.push(this.applySimpleSelectorScope(selector, s)); |
| 4470 } |
| 4471 return r.join(", "); |
| 4472 }, |
| 4473 applySimpleSelectorScope: function(selector, scopeSelector) { |
| 4474 if (selector.match(polyfillHostRe)) { |
| 4475 selector = selector.replace(polyfillHostNoCombinator, scopeSelector); |
| 4476 return selector.replace(polyfillHostRe, scopeSelector + " "); |
| 4477 } else { |
| 4478 return scopeSelector + " " + selector; |
| 4479 } |
| 4480 }, |
| 4481 applyStrictSelectorScope: function(selector, scopeSelector) { |
| 4482 scopeSelector = scopeSelector.replace(/\[is=([^\]]*)\]/g, "$1"); |
| 4483 var splits = [ " ", ">", "+", "~" ], scoped = selector, attrName = "[" +
scopeSelector + "]"; |
| 4484 splits.forEach(function(sep) { |
| 4485 var parts = scoped.split(sep); |
| 4486 scoped = parts.map(function(p) { |
| 4487 var t = p.trim().replace(polyfillHostRe, ""); |
| 4488 if (t && splits.indexOf(t) < 0 && t.indexOf(attrName) < 0) { |
| 4489 p = t.replace(/([^:]*)(:*)(.*)/, "$1" + attrName + "$2$3"); |
| 4490 } |
| 4491 return p; |
| 4492 }).join(sep); |
| 4493 }); |
| 4494 return scoped; |
| 4495 }, |
| 4496 insertPolyfillHostInCssText: function(selector) { |
| 4497 return selector.replace(colonHostContextRe, polyfillHostContext).replace
(colonHostRe, polyfillHost); |
| 4498 }, |
| 4499 propertiesFromRule: function(rule) { |
| 4500 var cssText = rule.style.cssText; |
| 4501 if (rule.style.content && !rule.style.content.match(/['"]+|attr/)) { |
| 4502 cssText = cssText.replace(/content:[^;]*;/g, "content: '" + rule.style
.content + "';"); |
| 4503 } |
| 4504 var style = rule.style; |
| 4505 for (var i in style) { |
| 4506 if (style[i] === "initial") { |
| 4507 cssText += i + ": initial; "; |
| 4508 } |
| 4509 } |
| 4510 return cssText; |
| 4511 }, |
| 4512 replaceTextInStyles: function(styles, action) { |
| 4513 if (styles && action) { |
| 4514 if (!(styles instanceof Array)) { |
| 4515 styles = [ styles ]; |
| 4516 } |
| 4517 Array.prototype.forEach.call(styles, function(s) { |
| 4518 s.textContent = action.call(this, s.textContent); |
| 4519 }, this); |
| 4520 } |
| 4521 }, |
| 4522 addCssToDocument: function(cssText, name) { |
| 4523 if (cssText.match("@import")) { |
| 4524 addOwnSheet(cssText, name); |
| 4525 } else { |
| 4526 addCssToDocument(cssText); |
| 4527 } |
| 4528 } |
| 4529 }; |
| 4530 var selectorRe = /([^{]*)({[\s\S]*?})/gim, cssCommentRe = /\/\*[^*]*\*+([^/*
][^*]*\*+)*\//gim, cssCommentNextSelectorRe = /\/\*\s*@polyfill ([^*]*\*+([^/*][
^*]*\*+)*\/)([^{]*?){/gim, cssContentNextSelectorRe = /polyfill-next-selector[^}
]*content\:[\s]*?['"](.*?)['"][;\s]*}([^{]*?){/gim, cssCommentRuleRe = /\/\*\s@p
olyfill-rule([^*]*\*+([^/*][^*]*\*+)*)\//gim, cssContentRuleRe = /(polyfill-rule
)[^}]*(content\:[\s]*['"](.*?)['"])[;\s]*[^}]*}/gim, cssCommentUnscopedRuleRe =
/\/\*\s@polyfill-unscoped-rule([^*]*\*+([^/*][^*]*\*+)*)\//gim, cssContentUnscop
edRuleRe = /(polyfill-unscoped-rule)[^}]*(content\:[\s]*['"](.*?)['"])[;\s]*[^}]
*}/gim, cssPseudoRe = /::(x-[^\s{,(]*)/gim, cssPartRe = /::part\(([^)]*)\)/gim,
polyfillHost = "-shadowcsshost", polyfillHostContext = "-shadowcsscontext", pare
nSuffix = ")(?:\\((" + "(?:\\([^)(]*\\)|[^)(]*)+?" + ")\\))?([^,{]*)"; |
| 4531 var cssColonHostRe = new RegExp("(" + polyfillHost + parenSuffix, "gim"), cs
sColonHostContextRe = new RegExp("(" + polyfillHostContext + parenSuffix, "gim")
, selectorReSuffix = "([>\\s~+[.,{:][\\s\\S]*)?$", colonHostRe = /\:host/gim, co
lonHostContextRe = /\:host-context/gim, polyfillHostNoCombinator = polyfillHost
+ "-no-combinator", polyfillHostRe = new RegExp(polyfillHost, "gim"), polyfillHo
stContextRe = new RegExp(polyfillHostContext, "gim"), shadowDOMSelectorsRe = [ /
\^\^/g, /\^/g, /\/shadow\//g, /\/shadow-deep\//g, /::shadow/g, /\/deep\//g, /::c
ontent/g ]; |
| 4532 function stylesToCssText(styles, preserveComments) { |
| 4533 var cssText = ""; |
| 4534 Array.prototype.forEach.call(styles, function(s) { |
| 4535 cssText += s.textContent + "\n\n"; |
| 4536 }); |
| 4537 if (!preserveComments) { |
| 4538 cssText = cssText.replace(cssCommentRe, ""); |
| 4539 } |
| 4540 return cssText; |
| 4541 } |
| 4542 function cssTextToStyle(cssText) { |
| 4543 var style = document.createElement("style"); |
| 4544 style.textContent = cssText; |
| 4545 return style; |
| 4546 } |
| 4547 function cssToRules(cssText) { |
| 4548 var style = cssTextToStyle(cssText); |
| 4549 document.head.appendChild(style); |
| 4550 var rules = []; |
| 4551 if (style.sheet) { |
| 4552 try { |
| 4553 rules = style.sheet.cssRules; |
| 4554 } catch (e) {} |
| 4555 } else { |
| 4556 console.warn("sheet not found", style); |
| 4557 } |
| 4558 style.parentNode.removeChild(style); |
| 4559 return rules; |
| 4560 } |
| 4561 var frame = document.createElement("iframe"); |
| 4562 frame.style.display = "none"; |
| 4563 function initFrame() { |
| 4564 frame.initialized = true; |
| 4565 document.body.appendChild(frame); |
| 4566 var doc = frame.contentDocument; |
| 4567 var base = doc.createElement("base"); |
| 4568 base.href = document.baseURI; |
| 4569 doc.head.appendChild(base); |
| 4570 } |
| 4571 function inFrame(fn) { |
| 4572 if (!frame.initialized) { |
| 4573 initFrame(); |
| 4574 } |
| 4575 document.body.appendChild(frame); |
| 4576 fn(frame.contentDocument); |
| 4577 document.body.removeChild(frame); |
| 4578 } |
| 4579 var isChrome = navigator.userAgent.match("Chrome"); |
| 4580 function withCssRules(cssText, callback) { |
| 4581 if (!callback) { |
| 4582 return; |
| 4583 } |
| 4584 var rules; |
| 4585 if (cssText.match("@import") && isChrome) { |
| 4586 var style = cssTextToStyle(cssText); |
| 4587 inFrame(function(doc) { |
| 4588 doc.head.appendChild(style.impl); |
| 4589 rules = Array.prototype.slice.call(style.sheet.cssRules, 0); |
| 4590 callback(rules); |
| 4591 }); |
| 4592 } else { |
| 4593 rules = cssToRules(cssText); |
| 4594 callback(rules); |
| 4595 } |
| 4596 } |
| 4597 function rulesToCss(cssRules) { |
| 4598 for (var i = 0, css = []; i < cssRules.length; i++) { |
| 4599 css.push(cssRules[i].cssText); |
| 4600 } |
| 4601 return css.join("\n\n"); |
| 4602 } |
| 4603 function addCssToDocument(cssText) { |
| 4604 if (cssText) { |
| 4605 getSheet().appendChild(document.createTextNode(cssText)); |
| 4606 } |
| 4607 } |
| 4608 function addOwnSheet(cssText, name) { |
| 4609 var style = cssTextToStyle(cssText); |
| 4610 style.setAttribute(name, ""); |
| 4611 style.setAttribute(SHIMMED_ATTRIBUTE, ""); |
| 4612 document.head.appendChild(style); |
| 4613 } |
| 4614 var SHIM_ATTRIBUTE = "shim-shadowdom"; |
| 4615 var SHIMMED_ATTRIBUTE = "shim-shadowdom-css"; |
| 4616 var NO_SHIM_ATTRIBUTE = "no-shim"; |
| 4617 var sheet; |
| 4618 function getSheet() { |
| 4619 if (!sheet) { |
| 4620 sheet = document.createElement("style"); |
| 4621 sheet.setAttribute(SHIMMED_ATTRIBUTE, ""); |
| 4622 sheet[SHIMMED_ATTRIBUTE] = true; |
| 4623 } |
| 4624 return sheet; |
| 4625 } |
| 4626 if (window.ShadowDOMPolyfill) { |
| 4627 addCssToDocument("style { display: none !important; }\n"); |
| 4628 var doc = ShadowDOMPolyfill.wrap(document); |
| 4629 var head = doc.querySelector("head"); |
| 4630 head.insertBefore(getSheet(), head.childNodes[0]); |
| 4631 document.addEventListener("DOMContentLoaded", function() { |
| 4632 var urlResolver = scope.urlResolver; |
| 4633 if (window.HTMLImports && !HTMLImports.useNative) { |
| 4634 var SHIM_SHEET_SELECTOR = "link[rel=stylesheet]" + "[" + SHIM_ATTRIBUT
E + "]"; |
| 4635 var SHIM_STYLE_SELECTOR = "style[" + SHIM_ATTRIBUTE + "]"; |
| 4636 HTMLImports.importer.documentPreloadSelectors += "," + SHIM_SHEET_SELE
CTOR; |
| 4637 HTMLImports.importer.importsPreloadSelectors += "," + SHIM_SHEET_SELEC
TOR; |
| 4638 HTMLImports.parser.documentSelectors = [ HTMLImports.parser.documentSe
lectors, SHIM_SHEET_SELECTOR, SHIM_STYLE_SELECTOR ].join(","); |
| 4639 var originalParseGeneric = HTMLImports.parser.parseGeneric; |
| 4640 HTMLImports.parser.parseGeneric = function(elt) { |
| 4641 if (elt[SHIMMED_ATTRIBUTE]) { |
| 4642 return; |
| 4643 } |
| 4644 var style = elt.__importElement || elt; |
| 4645 if (!style.hasAttribute(SHIM_ATTRIBUTE)) { |
| 4646 originalParseGeneric.call(this, elt); |
| 4647 return; |
| 4648 } |
| 4649 if (elt.__resource) { |
| 4650 style = elt.ownerDocument.createElement("style"); |
| 4651 style.textContent = elt.__resource; |
| 4652 } |
| 4653 HTMLImports.path.resolveUrlsInStyle(style); |
| 4654 style.textContent = ShadowCSS.shimStyle(style); |
| 4655 style.removeAttribute(SHIM_ATTRIBUTE, ""); |
| 4656 style.setAttribute(SHIMMED_ATTRIBUTE, ""); |
| 4657 style[SHIMMED_ATTRIBUTE] = true; |
| 4658 if (style.parentNode !== head) { |
| 4659 if (elt.parentNode === head) { |
| 4660 head.replaceChild(style, elt); |
| 4661 } else { |
| 4662 this.addElementToDocument(style); |
| 4663 } |
| 4664 } |
| 4665 style.__importParsed = true; |
| 4666 this.markParsingComplete(elt); |
| 4667 this.parseNext(); |
| 4668 }; |
| 4669 var hasResource = HTMLImports.parser.hasResource; |
| 4670 HTMLImports.parser.hasResource = function(node) { |
| 4671 if (node.localName === "link" && node.rel === "stylesheet" && node.h
asAttribute(SHIM_ATTRIBUTE)) { |
| 4672 return node.__resource; |
| 4673 } else { |
| 4674 return hasResource.call(this, node); |
| 4675 } |
| 4676 }; |
| 4677 } |
| 4678 }); |
| 4679 } |
| 4680 scope.ShadowCSS = ShadowCSS; |
| 4681 })(window.WebComponents); |
| 4682 } |
| 4683 |
| 4684 (function(scope) { |
| 4685 if (window.ShadowDOMPolyfill) { |
| 4686 window.wrap = ShadowDOMPolyfill.wrapIfNeeded; |
| 4687 window.unwrap = ShadowDOMPolyfill.unwrapIfNeeded; |
| 4688 } else { |
| 4689 window.wrap = window.unwrap = function(n) { |
| 4690 return n; |
| 4691 }; |
| 4692 } |
| 4693 })(window.WebComponents); |
| 4694 |
| 4695 (function(global) { |
| 4696 var registrationsTable = new WeakMap(); |
| 4697 var setImmediate; |
| 4698 if (/Trident|Edge/.test(navigator.userAgent)) { |
| 4699 setImmediate = setTimeout; |
| 4700 } else if (window.setImmediate) { |
| 4701 setImmediate = window.setImmediate; |
| 4702 } else { |
| 4703 var setImmediateQueue = []; |
| 4704 var sentinel = String(Math.random()); |
| 4705 window.addEventListener("message", function(e) { |
| 4706 if (e.data === sentinel) { |
| 4707 var queue = setImmediateQueue; |
| 4708 setImmediateQueue = []; |
| 4709 queue.forEach(function(func) { |
| 4710 func(); |
| 4711 }); |
| 4712 } |
| 4713 }); |
| 4714 setImmediate = function(func) { |
| 4715 setImmediateQueue.push(func); |
| 4716 window.postMessage(sentinel, "*"); |
| 4717 }; |
| 4718 } |
| 4719 var isScheduled = false; |
| 4720 var scheduledObservers = []; |
| 4721 function scheduleCallback(observer) { |
| 4722 scheduledObservers.push(observer); |
| 4723 if (!isScheduled) { |
| 4724 isScheduled = true; |
| 4725 setImmediate(dispatchCallbacks); |
| 4726 } |
| 4727 } |
| 4728 function wrapIfNeeded(node) { |
| 4729 return window.ShadowDOMPolyfill && window.ShadowDOMPolyfill.wrapIfNeeded(nod
e) || node; |
| 4730 } |
| 4731 function dispatchCallbacks() { |
| 4732 isScheduled = false; |
| 4733 var observers = scheduledObservers; |
| 4734 scheduledObservers = []; |
| 4735 observers.sort(function(o1, o2) { |
| 4736 return o1.uid_ - o2.uid_; |
| 4737 }); |
| 4738 var anyNonEmpty = false; |
| 4739 observers.forEach(function(observer) { |
| 4740 var queue = observer.takeRecords(); |
| 4741 removeTransientObserversFor(observer); |
| 4742 if (queue.length) { |
| 4743 observer.callback_(queue, observer); |
| 4744 anyNonEmpty = true; |
| 4745 } |
| 4746 }); |
| 4747 if (anyNonEmpty) dispatchCallbacks(); |
| 4748 } |
| 4749 function removeTransientObserversFor(observer) { |
| 4750 observer.nodes_.forEach(function(node) { |
| 4751 var registrations = registrationsTable.get(node); |
| 4752 if (!registrations) return; |
| 4753 registrations.forEach(function(registration) { |
| 4754 if (registration.observer === observer) registration.removeTransientObse
rvers(); |
| 4755 }); |
| 4756 }); |
| 4757 } |
| 4758 function forEachAncestorAndObserverEnqueueRecord(target, callback) { |
| 4759 for (var node = target; node; node = node.parentNode) { |
| 4760 var registrations = registrationsTable.get(node); |
| 4761 if (registrations) { |
| 4762 for (var j = 0; j < registrations.length; j++) { |
| 4763 var registration = registrations[j]; |
| 4764 var options = registration.options; |
| 4765 if (node !== target && !options.subtree) continue; |
| 4766 var record = callback(options); |
| 4767 if (record) registration.enqueue(record); |
| 4768 } |
| 4769 } |
| 4770 } |
| 4771 } |
| 4772 var uidCounter = 0; |
| 4773 function JsMutationObserver(callback) { |
| 4774 this.callback_ = callback; |
| 4775 this.nodes_ = []; |
| 4776 this.records_ = []; |
| 4777 this.uid_ = ++uidCounter; |
| 4778 } |
| 4779 JsMutationObserver.prototype = { |
| 4780 observe: function(target, options) { |
| 4781 target = wrapIfNeeded(target); |
| 4782 if (!options.childList && !options.attributes && !options.characterData ||
options.attributeOldValue && !options.attributes || options.attributeFilter &&
options.attributeFilter.length && !options.attributes || options.characterDataOl
dValue && !options.characterData) { |
| 4783 throw new SyntaxError(); |
| 4784 } |
| 4785 var registrations = registrationsTable.get(target); |
| 4786 if (!registrations) registrationsTable.set(target, registrations = []); |
| 4787 var registration; |
| 4788 for (var i = 0; i < registrations.length; i++) { |
| 4789 if (registrations[i].observer === this) { |
| 4790 registration = registrations[i]; |
| 4791 registration.removeListeners(); |
| 4792 registration.options = options; |
| 4793 break; |
| 4794 } |
| 4795 } |
| 4796 if (!registration) { |
| 4797 registration = new Registration(this, target, options); |
| 4798 registrations.push(registration); |
| 4799 this.nodes_.push(target); |
| 4800 } |
| 4801 registration.addListeners(); |
| 4802 }, |
| 4803 disconnect: function() { |
| 4804 this.nodes_.forEach(function(node) { |
| 4805 var registrations = registrationsTable.get(node); |
| 4806 for (var i = 0; i < registrations.length; i++) { |
| 4807 var registration = registrations[i]; |
| 4808 if (registration.observer === this) { |
| 4809 registration.removeListeners(); |
| 4810 registrations.splice(i, 1); |
| 4811 break; |
| 4812 } |
| 4813 } |
| 4814 }, this); |
| 4815 this.records_ = []; |
| 4816 }, |
| 4817 takeRecords: function() { |
| 4818 var copyOfRecords = this.records_; |
| 4819 this.records_ = []; |
| 4820 return copyOfRecords; |
| 4821 } |
| 4822 }; |
| 4823 function MutationRecord(type, target) { |
| 4824 this.type = type; |
| 4825 this.target = target; |
| 4826 this.addedNodes = []; |
| 4827 this.removedNodes = []; |
| 4828 this.previousSibling = null; |
| 4829 this.nextSibling = null; |
| 4830 this.attributeName = null; |
| 4831 this.attributeNamespace = null; |
| 4832 this.oldValue = null; |
| 4833 } |
| 4834 function copyMutationRecord(original) { |
| 4835 var record = new MutationRecord(original.type, original.target); |
| 4836 record.addedNodes = original.addedNodes.slice(); |
| 4837 record.removedNodes = original.removedNodes.slice(); |
| 4838 record.previousSibling = original.previousSibling; |
| 4839 record.nextSibling = original.nextSibling; |
| 4840 record.attributeName = original.attributeName; |
| 4841 record.attributeNamespace = original.attributeNamespace; |
| 4842 record.oldValue = original.oldValue; |
| 4843 return record; |
| 4844 } |
| 4845 var currentRecord, recordWithOldValue; |
| 4846 function getRecord(type, target) { |
| 4847 return currentRecord = new MutationRecord(type, target); |
| 4848 } |
| 4849 function getRecordWithOldValue(oldValue) { |
| 4850 if (recordWithOldValue) return recordWithOldValue; |
| 4851 recordWithOldValue = copyMutationRecord(currentRecord); |
| 4852 recordWithOldValue.oldValue = oldValue; |
| 4853 return recordWithOldValue; |
| 4854 } |
| 4855 function clearRecords() { |
| 4856 currentRecord = recordWithOldValue = undefined; |
| 4857 } |
| 4858 function recordRepresentsCurrentMutation(record) { |
| 4859 return record === recordWithOldValue || record === currentRecord; |
| 4860 } |
| 4861 function selectRecord(lastRecord, newRecord) { |
| 4862 if (lastRecord === newRecord) return lastRecord; |
| 4863 if (recordWithOldValue && recordRepresentsCurrentMutation(lastRecord)) retur
n recordWithOldValue; |
| 4864 return null; |
| 4865 } |
| 4866 function Registration(observer, target, options) { |
| 4867 this.observer = observer; |
| 4868 this.target = target; |
| 4869 this.options = options; |
| 4870 this.transientObservedNodes = []; |
| 4871 } |
| 4872 Registration.prototype = { |
| 4873 enqueue: function(record) { |
| 4874 var records = this.observer.records_; |
| 4875 var length = records.length; |
| 4876 if (records.length > 0) { |
| 4877 var lastRecord = records[length - 1]; |
| 4878 var recordToReplaceLast = selectRecord(lastRecord, record); |
| 4879 if (recordToReplaceLast) { |
| 4880 records[length - 1] = recordToReplaceLast; |
| 4881 return; |
| 4882 } |
| 4883 } else { |
| 4884 scheduleCallback(this.observer); |
| 4885 } |
| 4886 records[length] = record; |
| 4887 }, |
| 4888 addListeners: function() { |
| 4889 this.addListeners_(this.target); |
| 4890 }, |
| 4891 addListeners_: function(node) { |
| 4892 var options = this.options; |
| 4893 if (options.attributes) node.addEventListener("DOMAttrModified", this, tru
e); |
| 4894 if (options.characterData) node.addEventListener("DOMCharacterDataModified
", this, true); |
| 4895 if (options.childList) node.addEventListener("DOMNodeInserted", this, true
); |
| 4896 if (options.childList || options.subtree) node.addEventListener("DOMNodeRe
moved", this, true); |
| 4897 }, |
| 4898 removeListeners: function() { |
| 4899 this.removeListeners_(this.target); |
| 4900 }, |
| 4901 removeListeners_: function(node) { |
| 4902 var options = this.options; |
| 4903 if (options.attributes) node.removeEventListener("DOMAttrModified", this,
true); |
| 4904 if (options.characterData) node.removeEventListener("DOMCharacterDataModif
ied", this, true); |
| 4905 if (options.childList) node.removeEventListener("DOMNodeInserted", this, t
rue); |
| 4906 if (options.childList || options.subtree) node.removeEventListener("DOMNod
eRemoved", this, true); |
| 4907 }, |
| 4908 addTransientObserver: function(node) { |
| 4909 if (node === this.target) return; |
| 4910 this.addListeners_(node); |
| 4911 this.transientObservedNodes.push(node); |
| 4912 var registrations = registrationsTable.get(node); |
| 4913 if (!registrations) registrationsTable.set(node, registrations = []); |
| 4914 registrations.push(this); |
| 4915 }, |
| 4916 removeTransientObservers: function() { |
| 4917 var transientObservedNodes = this.transientObservedNodes; |
| 4918 this.transientObservedNodes = []; |
| 4919 transientObservedNodes.forEach(function(node) { |
| 4920 this.removeListeners_(node); |
| 4921 var registrations = registrationsTable.get(node); |
| 4922 for (var i = 0; i < registrations.length; i++) { |
| 4923 if (registrations[i] === this) { |
| 4924 registrations.splice(i, 1); |
| 4925 break; |
| 4926 } |
| 4927 } |
| 4928 }, this); |
| 4929 }, |
| 4930 handleEvent: function(e) { |
| 4931 e.stopImmediatePropagation(); |
| 4932 switch (e.type) { |
| 4933 case "DOMAttrModified": |
| 4934 var name = e.attrName; |
| 4935 var namespace = e.relatedNode.namespaceURI; |
| 4936 var target = e.target; |
| 4937 var record = new getRecord("attributes", target); |
| 4938 record.attributeName = name; |
| 4939 record.attributeNamespace = namespace; |
| 4940 var oldValue = e.attrChange === MutationEvent.ADDITION ? null : e.prevVa
lue; |
| 4941 forEachAncestorAndObserverEnqueueRecord(target, function(options) { |
| 4942 if (!options.attributes) return; |
| 4943 if (options.attributeFilter && options.attributeFilter.length && optio
ns.attributeFilter.indexOf(name) === -1 && options.attributeFilter.indexOf(names
pace) === -1) { |
| 4944 return; |
| 4945 } |
| 4946 if (options.attributeOldValue) return getRecordWithOldValue(oldValue); |
| 4947 return record; |
| 4948 }); |
| 4949 break; |
| 4950 |
| 4951 case "DOMCharacterDataModified": |
| 4952 var target = e.target; |
| 4953 var record = getRecord("characterData", target); |
| 4954 var oldValue = e.prevValue; |
| 4955 forEachAncestorAndObserverEnqueueRecord(target, function(options) { |
| 4956 if (!options.characterData) return; |
| 4957 if (options.characterDataOldValue) return getRecordWithOldValue(oldVal
ue); |
| 4958 return record; |
| 4959 }); |
| 4960 break; |
| 4961 |
| 4962 case "DOMNodeRemoved": |
| 4963 this.addTransientObserver(e.target); |
| 4964 |
| 4965 case "DOMNodeInserted": |
| 4966 var target = e.relatedNode; |
| 4967 var changedNode = e.target; |
| 4968 var addedNodes, removedNodes; |
| 4969 if (e.type === "DOMNodeInserted") { |
| 4970 addedNodes = [ changedNode ]; |
| 4971 removedNodes = []; |
| 4972 } else { |
| 4973 addedNodes = []; |
| 4974 removedNodes = [ changedNode ]; |
| 4975 } |
| 4976 var previousSibling = changedNode.previousSibling; |
| 4977 var nextSibling = changedNode.nextSibling; |
| 4978 var record = getRecord("childList", target); |
| 4979 record.addedNodes = addedNodes; |
| 4980 record.removedNodes = removedNodes; |
| 4981 record.previousSibling = previousSibling; |
| 4982 record.nextSibling = nextSibling; |
| 4983 forEachAncestorAndObserverEnqueueRecord(target, function(options) { |
| 4984 if (!options.childList) return; |
| 4985 return record; |
| 4986 }); |
| 4987 } |
| 4988 clearRecords(); |
| 4989 } |
| 4990 }; |
| 4991 global.JsMutationObserver = JsMutationObserver; |
| 4992 if (!global.MutationObserver) global.MutationObserver = JsMutationObserver; |
| 4993 })(this); |
| 4994 |
| 4995 window.HTMLImports = window.HTMLImports || { |
| 4996 flags: {} |
| 4997 }; |
| 4998 |
| 4999 (function(scope) { |
| 5000 var IMPORT_LINK_TYPE = "import"; |
| 5001 var useNative = Boolean(IMPORT_LINK_TYPE in document.createElement("link")); |
| 5002 var hasShadowDOMPolyfill = Boolean(window.ShadowDOMPolyfill); |
| 5003 var wrap = function(node) { |
| 5004 return hasShadowDOMPolyfill ? ShadowDOMPolyfill.wrapIfNeeded(node) : node; |
| 5005 }; |
| 5006 var rootDocument = wrap(document); |
| 5007 var currentScriptDescriptor = { |
| 5008 get: function() { |
| 5009 var script = HTMLImports.currentScript || document.currentScript || (docum
ent.readyState !== "complete" ? document.scripts[document.scripts.length - 1] :
null); |
| 5010 return wrap(script); |
| 5011 }, |
| 5012 configurable: true |
| 5013 }; |
| 5014 Object.defineProperty(document, "_currentScript", currentScriptDescriptor); |
| 5015 Object.defineProperty(rootDocument, "_currentScript", currentScriptDescriptor)
; |
| 5016 var isIE = /Trident|Edge/.test(navigator.userAgent); |
| 5017 function whenReady(callback, doc) { |
| 5018 doc = doc || rootDocument; |
| 5019 whenDocumentReady(function() { |
| 5020 watchImportsLoad(callback, doc); |
| 5021 }, doc); |
| 5022 } |
| 5023 var requiredReadyState = isIE ? "complete" : "interactive"; |
| 5024 var READY_EVENT = "readystatechange"; |
| 5025 function isDocumentReady(doc) { |
| 5026 return doc.readyState === "complete" || doc.readyState === requiredReadyStat
e; |
| 5027 } |
| 5028 function whenDocumentReady(callback, doc) { |
| 5029 if (!isDocumentReady(doc)) { |
| 5030 var checkReady = function() { |
| 5031 if (doc.readyState === "complete" || doc.readyState === requiredReadySta
te) { |
| 5032 doc.removeEventListener(READY_EVENT, checkReady); |
| 5033 whenDocumentReady(callback, doc); |
| 5034 } |
| 5035 }; |
| 5036 doc.addEventListener(READY_EVENT, checkReady); |
| 5037 } else if (callback) { |
| 5038 callback(); |
| 5039 } |
| 5040 } |
| 5041 function markTargetLoaded(event) { |
| 5042 event.target.__loaded = true; |
| 5043 } |
| 5044 function watchImportsLoad(callback, doc) { |
| 5045 var imports = doc.querySelectorAll("link[rel=import]"); |
| 5046 var loaded = 0, l = imports.length; |
| 5047 function checkDone(d) { |
| 5048 if (loaded == l && callback) { |
| 5049 callback(); |
| 5050 } |
| 5051 } |
| 5052 function loadedImport(e) { |
| 5053 markTargetLoaded(e); |
| 5054 loaded++; |
| 5055 checkDone(); |
| 5056 } |
| 5057 if (l) { |
| 5058 for (var i = 0, imp; i < l && (imp = imports[i]); i++) { |
| 5059 if (isImportLoaded(imp)) { |
| 5060 loadedImport.call(imp, { |
| 5061 target: imp |
| 5062 }); |
| 5063 } else { |
| 5064 imp.addEventListener("load", loadedImport); |
| 5065 imp.addEventListener("error", loadedImport); |
| 5066 } |
| 5067 } |
| 5068 } else { |
| 5069 checkDone(); |
| 5070 } |
| 5071 } |
| 5072 function isImportLoaded(link) { |
| 5073 return useNative ? link.__loaded || link.import && link.import.readyState !=
= "loading" : link.__importParsed; |
| 5074 } |
| 5075 if (useNative) { |
| 5076 new MutationObserver(function(mxns) { |
| 5077 for (var i = 0, l = mxns.length, m; i < l && (m = mxns[i]); i++) { |
| 5078 if (m.addedNodes) { |
| 5079 handleImports(m.addedNodes); |
| 5080 } |
| 5081 } |
| 5082 }).observe(document.head, { |
| 5083 childList: true |
| 5084 }); |
| 5085 function handleImports(nodes) { |
| 5086 for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) { |
| 5087 if (isImport(n)) { |
| 5088 handleImport(n); |
| 5089 } |
| 5090 } |
| 5091 } |
| 5092 function isImport(element) { |
| 5093 return element.localName === "link" && element.rel === "import"; |
| 5094 } |
| 5095 function handleImport(element) { |
| 5096 var loaded = element.import; |
| 5097 if (loaded) { |
| 5098 markTargetLoaded({ |
| 5099 target: element |
| 5100 }); |
| 5101 } else { |
| 5102 element.addEventListener("load", markTargetLoaded); |
| 5103 element.addEventListener("error", markTargetLoaded); |
| 5104 } |
| 5105 } |
| 5106 (function() { |
| 5107 if (document.readyState === "loading") { |
| 5108 var imports = document.querySelectorAll("link[rel=import]"); |
| 5109 for (var i = 0, l = imports.length, imp; i < l && (imp = imports[i]); i+
+) { |
| 5110 handleImport(imp); |
| 5111 } |
| 5112 } |
| 5113 })(); |
| 5114 } |
| 5115 whenReady(function() { |
| 5116 HTMLImports.ready = true; |
| 5117 HTMLImports.readyTime = new Date().getTime(); |
| 5118 rootDocument.dispatchEvent(new CustomEvent("HTMLImportsLoaded", { |
| 5119 bubbles: true |
| 5120 })); |
| 5121 }); |
| 5122 scope.IMPORT_LINK_TYPE = IMPORT_LINK_TYPE; |
| 5123 scope.useNative = useNative; |
| 5124 scope.rootDocument = rootDocument; |
| 5125 scope.whenReady = whenReady; |
| 5126 scope.isIE = isIE; |
| 5127 })(HTMLImports); |
| 5128 |
| 5129 (function(scope) { |
| 5130 var modules = []; |
| 5131 var addModule = function(module) { |
| 5132 modules.push(module); |
| 5133 }; |
| 5134 var initializeModules = function() { |
| 5135 modules.forEach(function(module) { |
| 5136 module(scope); |
| 5137 }); |
| 5138 }; |
| 5139 scope.addModule = addModule; |
| 5140 scope.initializeModules = initializeModules; |
| 5141 })(HTMLImports); |
| 5142 |
| 5143 HTMLImports.addModule(function(scope) { |
| 5144 var CSS_URL_REGEXP = /(url\()([^)]*)(\))/g; |
| 5145 var CSS_IMPORT_REGEXP = /(@import[\s]+(?!url\())([^;]*)(;)/g; |
| 5146 var path = { |
| 5147 resolveUrlsInStyle: function(style) { |
| 5148 var doc = style.ownerDocument; |
| 5149 var resolver = doc.createElement("a"); |
| 5150 style.textContent = this.resolveUrlsInCssText(style.textContent, resolver)
; |
| 5151 return style; |
| 5152 }, |
| 5153 resolveUrlsInCssText: function(cssText, urlObj) { |
| 5154 var r = this.replaceUrls(cssText, urlObj, CSS_URL_REGEXP); |
| 5155 r = this.replaceUrls(r, urlObj, CSS_IMPORT_REGEXP); |
| 5156 return r; |
| 5157 }, |
| 5158 replaceUrls: function(text, urlObj, regexp) { |
| 5159 return text.replace(regexp, function(m, pre, url, post) { |
| 5160 var urlPath = url.replace(/["']/g, ""); |
| 5161 urlObj.href = urlPath; |
| 5162 urlPath = urlObj.href; |
| 5163 return pre + "'" + urlPath + "'" + post; |
| 5164 }); |
| 5165 } |
| 5166 }; |
| 5167 scope.path = path; |
| 5168 }); |
| 5169 |
| 5170 HTMLImports.addModule(function(scope) { |
| 5171 xhr = { |
| 5172 async: true, |
| 5173 ok: function(request) { |
| 5174 return request.status >= 200 && request.status < 300 || request.status ===
304 || request.status === 0; |
| 5175 }, |
| 5176 load: function(url, next, nextContext) { |
| 5177 var request = new XMLHttpRequest(); |
| 5178 if (scope.flags.debug || scope.flags.bust) { |
| 5179 url += "?" + Math.random(); |
| 5180 } |
| 5181 request.open("GET", url, xhr.async); |
| 5182 request.addEventListener("readystatechange", function(e) { |
| 5183 if (request.readyState === 4) { |
| 5184 var locationHeader = request.getResponseHeader("Location"); |
| 5185 var redirectedUrl = null; |
| 5186 if (locationHeader) { |
| 5187 var redirectedUrl = locationHeader.substr(0, 1) === "/" ? location.o
rigin + locationHeader : locationHeader; |
| 5188 } |
| 5189 next.call(nextContext, !xhr.ok(request) && request, request.response |
| request.responseText, redirectedUrl); |
| 5190 } |
| 5191 }); |
| 5192 request.send(); |
| 5193 return request; |
| 5194 }, |
| 5195 loadDocument: function(url, next, nextContext) { |
| 5196 this.load(url, next, nextContext).responseType = "document"; |
| 5197 } |
| 5198 }; |
| 5199 scope.xhr = xhr; |
| 5200 }); |
| 5201 |
| 5202 HTMLImports.addModule(function(scope) { |
| 5203 var xhr = scope.xhr; |
| 5204 var flags = scope.flags; |
| 5205 var Loader = function(onLoad, onComplete) { |
| 5206 this.cache = {}; |
| 5207 this.onload = onLoad; |
| 5208 this.oncomplete = onComplete; |
| 5209 this.inflight = 0; |
| 5210 this.pending = {}; |
| 5211 }; |
| 5212 Loader.prototype = { |
| 5213 addNodes: function(nodes) { |
| 5214 this.inflight += nodes.length; |
| 5215 for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) { |
| 5216 this.require(n); |
| 5217 } |
| 5218 this.checkDone(); |
| 5219 }, |
| 5220 addNode: function(node) { |
| 5221 this.inflight++; |
| 5222 this.require(node); |
| 5223 this.checkDone(); |
| 5224 }, |
| 5225 require: function(elt) { |
| 5226 var url = elt.src || elt.href; |
| 5227 elt.__nodeUrl = url; |
| 5228 if (!this.dedupe(url, elt)) { |
| 5229 this.fetch(url, elt); |
| 5230 } |
| 5231 }, |
| 5232 dedupe: function(url, elt) { |
| 5233 if (this.pending[url]) { |
| 5234 this.pending[url].push(elt); |
| 5235 return true; |
| 5236 } |
| 5237 var resource; |
| 5238 if (this.cache[url]) { |
| 5239 this.onload(url, elt, this.cache[url]); |
| 5240 this.tail(); |
| 5241 return true; |
| 5242 } |
| 5243 this.pending[url] = [ elt ]; |
| 5244 return false; |
| 5245 }, |
| 5246 fetch: function(url, elt) { |
| 5247 flags.load && console.log("fetch", url, elt); |
| 5248 if (url.match(/^data:/)) { |
| 5249 var pieces = url.split(","); |
| 5250 var header = pieces[0]; |
| 5251 var body = pieces[1]; |
| 5252 if (header.indexOf(";base64") > -1) { |
| 5253 body = atob(body); |
| 5254 } else { |
| 5255 body = decodeURIComponent(body); |
| 5256 } |
| 5257 setTimeout(function() { |
| 5258 this.receive(url, elt, null, body); |
| 5259 }.bind(this), 0); |
| 5260 } else { |
| 5261 var receiveXhr = function(err, resource, redirectedUrl) { |
| 5262 this.receive(url, elt, err, resource, redirectedUrl); |
| 5263 }.bind(this); |
| 5264 xhr.load(url, receiveXhr); |
| 5265 } |
| 5266 }, |
| 5267 receive: function(url, elt, err, resource, redirectedUrl) { |
| 5268 this.cache[url] = resource; |
| 5269 var $p = this.pending[url]; |
| 5270 for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) { |
| 5271 this.onload(url, p, resource, err, redirectedUrl); |
| 5272 this.tail(); |
| 5273 } |
| 5274 this.pending[url] = null; |
| 5275 }, |
| 5276 tail: function() { |
| 5277 --this.inflight; |
| 5278 this.checkDone(); |
| 5279 }, |
| 5280 checkDone: function() { |
| 5281 if (!this.inflight) { |
| 5282 this.oncomplete(); |
| 5283 } |
| 5284 } |
| 5285 }; |
| 5286 scope.Loader = Loader; |
| 5287 }); |
| 5288 |
| 5289 HTMLImports.addModule(function(scope) { |
| 5290 var Observer = function(addCallback) { |
| 5291 this.addCallback = addCallback; |
| 5292 this.mo = new MutationObserver(this.handler.bind(this)); |
| 5293 }; |
| 5294 Observer.prototype = { |
| 5295 handler: function(mutations) { |
| 5296 for (var i = 0, l = mutations.length, m; i < l && (m = mutations[i]); i++)
{ |
| 5297 if (m.type === "childList" && m.addedNodes.length) { |
| 5298 this.addedNodes(m.addedNodes); |
| 5299 } |
| 5300 } |
| 5301 }, |
| 5302 addedNodes: function(nodes) { |
| 5303 if (this.addCallback) { |
| 5304 this.addCallback(nodes); |
| 5305 } |
| 5306 for (var i = 0, l = nodes.length, n, loading; i < l && (n = nodes[i]); i++
) { |
| 5307 if (n.children && n.children.length) { |
| 5308 this.addedNodes(n.children); |
| 5309 } |
| 5310 } |
| 5311 }, |
| 5312 observe: function(root) { |
| 5313 this.mo.observe(root, { |
| 5314 childList: true, |
| 5315 subtree: true |
| 5316 }); |
| 5317 } |
| 5318 }; |
| 5319 scope.Observer = Observer; |
| 5320 }); |
| 5321 |
| 5322 HTMLImports.addModule(function(scope) { |
| 5323 var path = scope.path; |
| 5324 var rootDocument = scope.rootDocument; |
| 5325 var flags = scope.flags; |
| 5326 var isIE = scope.isIE; |
| 5327 var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE; |
| 5328 var IMPORT_SELECTOR = "link[rel=" + IMPORT_LINK_TYPE + "]"; |
| 5329 var importParser = { |
| 5330 documentSelectors: IMPORT_SELECTOR, |
| 5331 importsSelectors: [ IMPORT_SELECTOR, "link[rel=stylesheet]", "style", "scrip
t:not([type])", 'script[type="text/javascript"]' ].join(","), |
| 5332 map: { |
| 5333 link: "parseLink", |
| 5334 script: "parseScript", |
| 5335 style: "parseStyle" |
| 5336 }, |
| 5337 dynamicElements: [], |
| 5338 parseNext: function() { |
| 5339 var next = this.nextToParse(); |
| 5340 if (next) { |
| 5341 this.parse(next); |
| 5342 } |
| 5343 }, |
| 5344 parse: function(elt) { |
| 5345 if (this.isParsed(elt)) { |
| 5346 flags.parse && console.log("[%s] is already parsed", elt.localName); |
| 5347 return; |
| 5348 } |
| 5349 var fn = this[this.map[elt.localName]]; |
| 5350 if (fn) { |
| 5351 this.markParsing(elt); |
| 5352 fn.call(this, elt); |
| 5353 } |
| 5354 }, |
| 5355 parseDynamic: function(elt, quiet) { |
| 5356 this.dynamicElements.push(elt); |
| 5357 if (!quiet) { |
| 5358 this.parseNext(); |
| 5359 } |
| 5360 }, |
| 5361 markParsing: function(elt) { |
| 5362 flags.parse && console.log("parsing", elt); |
| 5363 this.parsingElement = elt; |
| 5364 }, |
| 5365 markParsingComplete: function(elt) { |
| 5366 elt.__importParsed = true; |
| 5367 this.markDynamicParsingComplete(elt); |
| 5368 if (elt.__importElement) { |
| 5369 elt.__importElement.__importParsed = true; |
| 5370 this.markDynamicParsingComplete(elt.__importElement); |
| 5371 } |
| 5372 this.parsingElement = null; |
| 5373 flags.parse && console.log("completed", elt); |
| 5374 }, |
| 5375 markDynamicParsingComplete: function(elt) { |
| 5376 var i = this.dynamicElements.indexOf(elt); |
| 5377 if (i >= 0) { |
| 5378 this.dynamicElements.splice(i, 1); |
| 5379 } |
| 5380 }, |
| 5381 parseImport: function(elt) { |
| 5382 if (HTMLImports.__importsParsingHook) { |
| 5383 HTMLImports.__importsParsingHook(elt); |
| 5384 } |
| 5385 if (elt.import) { |
| 5386 elt.import.__importParsed = true; |
| 5387 } |
| 5388 this.markParsingComplete(elt); |
| 5389 if (elt.__resource && !elt.__error) { |
| 5390 elt.dispatchEvent(new CustomEvent("load", { |
| 5391 bubbles: false |
| 5392 })); |
| 5393 } else { |
| 5394 elt.dispatchEvent(new CustomEvent("error", { |
| 5395 bubbles: false |
| 5396 })); |
| 5397 } |
| 5398 if (elt.__pending) { |
| 5399 var fn; |
| 5400 while (elt.__pending.length) { |
| 5401 fn = elt.__pending.shift(); |
| 5402 if (fn) { |
| 5403 fn({ |
| 5404 target: elt |
| 5405 }); |
| 5406 } |
| 5407 } |
| 5408 } |
| 5409 this.parseNext(); |
| 5410 }, |
| 5411 parseLink: function(linkElt) { |
| 5412 if (nodeIsImport(linkElt)) { |
| 5413 this.parseImport(linkElt); |
| 5414 } else { |
| 5415 linkElt.href = linkElt.href; |
| 5416 this.parseGeneric(linkElt); |
| 5417 } |
| 5418 }, |
| 5419 parseStyle: function(elt) { |
| 5420 var src = elt; |
| 5421 elt = cloneStyle(elt); |
| 5422 elt.__importElement = src; |
| 5423 this.parseGeneric(elt); |
| 5424 }, |
| 5425 parseGeneric: function(elt) { |
| 5426 this.trackElement(elt); |
| 5427 this.addElementToDocument(elt); |
| 5428 }, |
| 5429 rootImportForElement: function(elt) { |
| 5430 var n = elt; |
| 5431 while (n.ownerDocument.__importLink) { |
| 5432 n = n.ownerDocument.__importLink; |
| 5433 } |
| 5434 return n; |
| 5435 }, |
| 5436 addElementToDocument: function(elt) { |
| 5437 var port = this.rootImportForElement(elt.__importElement || elt); |
| 5438 port.parentNode.insertBefore(elt, port); |
| 5439 }, |
| 5440 trackElement: function(elt, callback) { |
| 5441 var self = this; |
| 5442 var done = function(e) { |
| 5443 if (callback) { |
| 5444 callback(e); |
| 5445 } |
| 5446 self.markParsingComplete(elt); |
| 5447 self.parseNext(); |
| 5448 }; |
| 5449 elt.addEventListener("load", done); |
| 5450 elt.addEventListener("error", done); |
| 5451 if (isIE && elt.localName === "style") { |
| 5452 var fakeLoad = false; |
| 5453 if (elt.textContent.indexOf("@import") == -1) { |
| 5454 fakeLoad = true; |
| 5455 } else if (elt.sheet) { |
| 5456 fakeLoad = true; |
| 5457 var csr = elt.sheet.cssRules; |
| 5458 var len = csr ? csr.length : 0; |
| 5459 for (var i = 0, r; i < len && (r = csr[i]); i++) { |
| 5460 if (r.type === CSSRule.IMPORT_RULE) { |
| 5461 fakeLoad = fakeLoad && Boolean(r.styleSheet); |
| 5462 } |
| 5463 } |
| 5464 } |
| 5465 if (fakeLoad) { |
| 5466 elt.dispatchEvent(new CustomEvent("load", { |
| 5467 bubbles: false |
| 5468 })); |
| 5469 } |
| 5470 } |
| 5471 }, |
| 5472 parseScript: function(scriptElt) { |
| 5473 var script = document.createElement("script"); |
| 5474 script.__importElement = scriptElt; |
| 5475 script.src = scriptElt.src ? scriptElt.src : generateScriptDataUrl(scriptE
lt); |
| 5476 scope.currentScript = scriptElt; |
| 5477 this.trackElement(script, function(e) { |
| 5478 script.parentNode.removeChild(script); |
| 5479 scope.currentScript = null; |
| 5480 }); |
| 5481 this.addElementToDocument(script); |
| 5482 }, |
| 5483 nextToParse: function() { |
| 5484 this._mayParse = []; |
| 5485 return !this.parsingElement && (this.nextToParseInDoc(rootDocument) || thi
s.nextToParseDynamic()); |
| 5486 }, |
| 5487 nextToParseInDoc: function(doc, link) { |
| 5488 if (doc && this._mayParse.indexOf(doc) < 0) { |
| 5489 this._mayParse.push(doc); |
| 5490 var nodes = doc.querySelectorAll(this.parseSelectorsForNode(doc)); |
| 5491 for (var i = 0, l = nodes.length, p = 0, n; i < l && (n = nodes[i]); i++
) { |
| 5492 if (!this.isParsed(n)) { |
| 5493 if (this.hasResource(n)) { |
| 5494 return nodeIsImport(n) ? this.nextToParseInDoc(n.import, n) : n; |
| 5495 } else { |
| 5496 return; |
| 5497 } |
| 5498 } |
| 5499 } |
| 5500 } |
| 5501 return link; |
| 5502 }, |
| 5503 nextToParseDynamic: function() { |
| 5504 return this.dynamicElements[0]; |
| 5505 }, |
| 5506 parseSelectorsForNode: function(node) { |
| 5507 var doc = node.ownerDocument || node; |
| 5508 return doc === rootDocument ? this.documentSelectors : this.importsSelecto
rs; |
| 5509 }, |
| 5510 isParsed: function(node) { |
| 5511 return node.__importParsed; |
| 5512 }, |
| 5513 needsDynamicParsing: function(elt) { |
| 5514 return this.dynamicElements.indexOf(elt) >= 0; |
| 5515 }, |
| 5516 hasResource: function(node) { |
| 5517 if (nodeIsImport(node) && node.import === undefined) { |
| 5518 return false; |
| 5519 } |
| 5520 return true; |
| 5521 } |
| 5522 }; |
| 5523 function nodeIsImport(elt) { |
| 5524 return elt.localName === "link" && elt.rel === IMPORT_LINK_TYPE; |
| 5525 } |
| 5526 function generateScriptDataUrl(script) { |
| 5527 var scriptContent = generateScriptContent(script); |
| 5528 return "data:text/javascript;charset=utf-8," + encodeURIComponent(scriptCont
ent); |
| 5529 } |
| 5530 function generateScriptContent(script) { |
| 5531 return script.textContent + generateSourceMapHint(script); |
| 5532 } |
| 5533 function generateSourceMapHint(script) { |
| 5534 var owner = script.ownerDocument; |
| 5535 owner.__importedScripts = owner.__importedScripts || 0; |
| 5536 var moniker = script.ownerDocument.baseURI; |
| 5537 var num = owner.__importedScripts ? "-" + owner.__importedScripts : ""; |
| 5538 owner.__importedScripts++; |
| 5539 return "\n//# sourceURL=" + moniker + num + ".js\n"; |
| 5540 } |
| 5541 function cloneStyle(style) { |
| 5542 var clone = style.ownerDocument.createElement("style"); |
| 5543 clone.textContent = style.textContent; |
| 5544 path.resolveUrlsInStyle(clone); |
| 5545 return clone; |
| 5546 } |
| 5547 scope.parser = importParser; |
| 5548 scope.IMPORT_SELECTOR = IMPORT_SELECTOR; |
| 5549 }); |
| 5550 |
| 5551 HTMLImports.addModule(function(scope) { |
| 5552 var flags = scope.flags; |
| 5553 var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE; |
| 5554 var IMPORT_SELECTOR = scope.IMPORT_SELECTOR; |
| 5555 var rootDocument = scope.rootDocument; |
| 5556 var Loader = scope.Loader; |
| 5557 var Observer = scope.Observer; |
| 5558 var parser = scope.parser; |
| 5559 var importer = { |
| 5560 documents: {}, |
| 5561 documentPreloadSelectors: IMPORT_SELECTOR, |
| 5562 importsPreloadSelectors: [ IMPORT_SELECTOR ].join(","), |
| 5563 loadNode: function(node) { |
| 5564 importLoader.addNode(node); |
| 5565 }, |
| 5566 loadSubtree: function(parent) { |
| 5567 var nodes = this.marshalNodes(parent); |
| 5568 importLoader.addNodes(nodes); |
| 5569 }, |
| 5570 marshalNodes: function(parent) { |
| 5571 return parent.querySelectorAll(this.loadSelectorsForNode(parent)); |
| 5572 }, |
| 5573 loadSelectorsForNode: function(node) { |
| 5574 var doc = node.ownerDocument || node; |
| 5575 return doc === rootDocument ? this.documentPreloadSelectors : this.imports
PreloadSelectors; |
| 5576 }, |
| 5577 loaded: function(url, elt, resource, err, redirectedUrl) { |
| 5578 flags.load && console.log("loaded", url, elt); |
| 5579 elt.__resource = resource; |
| 5580 elt.__error = err; |
| 5581 if (isImportLink(elt)) { |
| 5582 var doc = this.documents[url]; |
| 5583 if (doc === undefined) { |
| 5584 doc = err ? null : makeDocument(resource, redirectedUrl || url); |
| 5585 if (doc) { |
| 5586 doc.__importLink = elt; |
| 5587 this.bootDocument(doc); |
| 5588 } |
| 5589 this.documents[url] = doc; |
| 5590 } |
| 5591 elt.import = doc; |
| 5592 } |
| 5593 parser.parseNext(); |
| 5594 }, |
| 5595 bootDocument: function(doc) { |
| 5596 this.loadSubtree(doc); |
| 5597 this.observer.observe(doc); |
| 5598 parser.parseNext(); |
| 5599 }, |
| 5600 loadedAll: function() { |
| 5601 parser.parseNext(); |
| 5602 } |
| 5603 }; |
| 5604 var importLoader = new Loader(importer.loaded.bind(importer), importer.loadedA
ll.bind(importer)); |
| 5605 importer.observer = new Observer(); |
| 5606 function isImportLink(elt) { |
| 5607 return isLinkRel(elt, IMPORT_LINK_TYPE); |
| 5608 } |
| 5609 function isLinkRel(elt, rel) { |
| 5610 return elt.localName === "link" && elt.getAttribute("rel") === rel; |
| 5611 } |
| 5612 function makeDocument(resource, url) { |
| 5613 var doc = document.implementation.createHTMLDocument(IMPORT_LINK_TYPE); |
| 5614 doc._URL = url; |
| 5615 var base = doc.createElement("base"); |
| 5616 base.setAttribute("href", url); |
| 5617 if (!doc.baseURI) { |
| 5618 Object.defineProperty(doc, "baseURI", { |
| 5619 value: url |
| 5620 }); |
| 5621 } |
| 5622 var meta = doc.createElement("meta"); |
| 5623 meta.setAttribute("charset", "utf-8"); |
| 5624 doc.head.appendChild(meta); |
| 5625 doc.head.appendChild(base); |
| 5626 doc.body.innerHTML = resource; |
| 5627 if (window.HTMLTemplateElement && HTMLTemplateElement.bootstrap) { |
| 5628 HTMLTemplateElement.bootstrap(doc); |
| 5629 } |
| 5630 return doc; |
| 5631 } |
| 5632 if (!document.baseURI) { |
| 5633 var baseURIDescriptor = { |
| 5634 get: function() { |
| 5635 var base = document.querySelector("base"); |
| 5636 return base ? base.href : window.location.href; |
| 5637 }, |
| 5638 configurable: true |
| 5639 }; |
| 5640 Object.defineProperty(document, "baseURI", baseURIDescriptor); |
| 5641 Object.defineProperty(rootDocument, "baseURI", baseURIDescriptor); |
| 5642 } |
| 5643 scope.importer = importer; |
| 5644 scope.importLoader = importLoader; |
| 5645 }); |
| 5646 |
| 5647 HTMLImports.addModule(function(scope) { |
| 5648 var parser = scope.parser; |
| 5649 var importer = scope.importer; |
| 5650 var dynamic = { |
| 5651 added: function(nodes) { |
| 5652 var owner, parsed; |
| 5653 for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) { |
| 5654 if (!owner) { |
| 5655 owner = n.ownerDocument; |
| 5656 parsed = parser.isParsed(owner); |
| 5657 } |
| 5658 loading = this.shouldLoadNode(n); |
| 5659 if (loading) { |
| 5660 importer.loadNode(n); |
| 5661 } |
| 5662 if (this.shouldParseNode(n) && parsed) { |
| 5663 parser.parseDynamic(n, loading); |
| 5664 } |
| 5665 } |
| 5666 }, |
| 5667 shouldLoadNode: function(node) { |
| 5668 return node.nodeType === 1 && matches.call(node, importer.loadSelectorsFor
Node(node)); |
| 5669 }, |
| 5670 shouldParseNode: function(node) { |
| 5671 return node.nodeType === 1 && matches.call(node, parser.parseSelectorsForN
ode(node)); |
| 5672 } |
| 5673 }; |
| 5674 importer.observer.addCallback = dynamic.added.bind(dynamic); |
| 5675 var matches = HTMLElement.prototype.matches || HTMLElement.prototype.matchesSe
lector || HTMLElement.prototype.webkitMatchesSelector || HTMLElement.prototype.m
ozMatchesSelector || HTMLElement.prototype.msMatchesSelector; |
| 5676 }); |
| 5677 |
| 5678 (function(scope) { |
| 5679 var initializeModules = scope.initializeModules; |
| 5680 var isIE = scope.isIE; |
| 5681 if (scope.useNative) { |
| 5682 return; |
| 5683 } |
| 5684 if (isIE && typeof window.CustomEvent !== "function") { |
| 5685 window.CustomEvent = function(inType, params) { |
| 5686 params = params || {}; |
| 5687 var e = document.createEvent("CustomEvent"); |
| 5688 e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelab
le), params.detail); |
| 5689 return e; |
| 5690 }; |
| 5691 window.CustomEvent.prototype = window.Event.prototype; |
| 5692 } |
| 5693 initializeModules(); |
| 5694 var rootDocument = scope.rootDocument; |
| 5695 function bootstrap() { |
| 5696 HTMLImports.importer.bootDocument(rootDocument); |
| 5697 } |
| 5698 if (document.readyState === "complete" || document.readyState === "interactive
" && !window.attachEvent) { |
| 5699 bootstrap(); |
| 5700 } else { |
| 5701 document.addEventListener("DOMContentLoaded", bootstrap); |
| 5702 } |
| 5703 })(HTMLImports); |
| 5704 |
| 5705 window.CustomElements = window.CustomElements || { |
| 5706 flags: {} |
| 5707 }; |
| 5708 |
| 5709 (function(scope) { |
| 5710 var flags = scope.flags; |
| 5711 var modules = []; |
| 5712 var addModule = function(module) { |
| 5713 modules.push(module); |
| 5714 }; |
| 5715 var initializeModules = function() { |
| 5716 modules.forEach(function(module) { |
| 5717 module(scope); |
| 5718 }); |
| 5719 }; |
| 5720 scope.addModule = addModule; |
| 5721 scope.initializeModules = initializeModules; |
| 5722 scope.hasNative = Boolean(document.registerElement); |
| 5723 scope.useNative = !flags.register && scope.hasNative && !window.ShadowDOMPolyf
ill && (!window.HTMLImports || HTMLImports.useNative); |
| 5724 })(CustomElements); |
| 5725 |
| 5726 CustomElements.addModule(function(scope) { |
| 5727 var IMPORT_LINK_TYPE = window.HTMLImports ? HTMLImports.IMPORT_LINK_TYPE : "no
ne"; |
| 5728 function forSubtree(node, cb) { |
| 5729 findAllElements(node, function(e) { |
| 5730 if (cb(e)) { |
| 5731 return true; |
| 5732 } |
| 5733 forRoots(e, cb); |
| 5734 }); |
| 5735 forRoots(node, cb); |
| 5736 } |
| 5737 function findAllElements(node, find, data) { |
| 5738 var e = node.firstElementChild; |
| 5739 if (!e) { |
| 5740 e = node.firstChild; |
| 5741 while (e && e.nodeType !== Node.ELEMENT_NODE) { |
| 5742 e = e.nextSibling; |
| 5743 } |
| 5744 } |
| 5745 while (e) { |
| 5746 if (find(e, data) !== true) { |
| 5747 findAllElements(e, find, data); |
| 5748 } |
| 5749 e = e.nextElementSibling; |
| 5750 } |
| 5751 return null; |
| 5752 } |
| 5753 function forRoots(node, cb) { |
| 5754 var root = node.shadowRoot; |
| 5755 while (root) { |
| 5756 forSubtree(root, cb); |
| 5757 root = root.olderShadowRoot; |
| 5758 } |
| 5759 } |
| 5760 var processingDocuments; |
| 5761 function forDocumentTree(doc, cb) { |
| 5762 processingDocuments = []; |
| 5763 _forDocumentTree(doc, cb); |
| 5764 processingDocuments = null; |
| 5765 } |
| 5766 function _forDocumentTree(doc, cb) { |
| 5767 doc = wrap(doc); |
| 5768 if (processingDocuments.indexOf(doc) >= 0) { |
| 5769 return; |
| 5770 } |
| 5771 processingDocuments.push(doc); |
| 5772 var imports = doc.querySelectorAll("link[rel=" + IMPORT_LINK_TYPE + "]"); |
| 5773 for (var i = 0, l = imports.length, n; i < l && (n = imports[i]); i++) { |
| 5774 if (n.import) { |
| 5775 _forDocumentTree(n.import, cb); |
| 5776 } |
| 5777 } |
| 5778 cb(doc); |
| 5779 } |
| 5780 scope.forDocumentTree = forDocumentTree; |
| 5781 scope.forSubtree = forSubtree; |
| 5782 }); |
| 5783 |
| 5784 CustomElements.addModule(function(scope) { |
| 5785 var flags = scope.flags; |
| 5786 var forSubtree = scope.forSubtree; |
| 5787 var forDocumentTree = scope.forDocumentTree; |
| 5788 function addedNode(node) { |
| 5789 return added(node) || addedSubtree(node); |
| 5790 } |
| 5791 function added(node) { |
| 5792 if (scope.upgrade(node)) { |
| 5793 return true; |
| 5794 } |
| 5795 attached(node); |
| 5796 } |
| 5797 function addedSubtree(node) { |
| 5798 forSubtree(node, function(e) { |
| 5799 if (added(e)) { |
| 5800 return true; |
| 5801 } |
| 5802 }); |
| 5803 } |
| 5804 function attachedNode(node) { |
| 5805 attached(node); |
| 5806 if (inDocument(node)) { |
| 5807 forSubtree(node, function(e) { |
| 5808 attached(e); |
| 5809 }); |
| 5810 } |
| 5811 } |
| 5812 var hasPolyfillMutations = !window.MutationObserver || window.MutationObserver
=== window.JsMutationObserver; |
| 5813 scope.hasPolyfillMutations = hasPolyfillMutations; |
| 5814 var isPendingMutations = false; |
| 5815 var pendingMutations = []; |
| 5816 function deferMutation(fn) { |
| 5817 pendingMutations.push(fn); |
| 5818 if (!isPendingMutations) { |
| 5819 isPendingMutations = true; |
| 5820 setTimeout(takeMutations); |
| 5821 } |
| 5822 } |
| 5823 function takeMutations() { |
| 5824 isPendingMutations = false; |
| 5825 var $p = pendingMutations; |
| 5826 for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) { |
| 5827 p(); |
| 5828 } |
| 5829 pendingMutations = []; |
| 5830 } |
| 5831 function attached(element) { |
| 5832 if (hasPolyfillMutations) { |
| 5833 deferMutation(function() { |
| 5834 _attached(element); |
| 5835 }); |
| 5836 } else { |
| 5837 _attached(element); |
| 5838 } |
| 5839 } |
| 5840 function _attached(element) { |
| 5841 if (element.__upgraded__ && (element.attachedCallback || element.detachedCal
lback)) { |
| 5842 if (!element.__attached && inDocument(element)) { |
| 5843 element.__attached = true; |
| 5844 if (element.attachedCallback) { |
| 5845 element.attachedCallback(); |
| 5846 } |
| 5847 } |
| 5848 } |
| 5849 } |
| 5850 function detachedNode(node) { |
| 5851 detached(node); |
| 5852 forSubtree(node, function(e) { |
| 5853 detached(e); |
| 5854 }); |
| 5855 } |
| 5856 function detached(element) { |
| 5857 if (hasPolyfillMutations) { |
| 5858 deferMutation(function() { |
| 5859 _detached(element); |
| 5860 }); |
| 5861 } else { |
| 5862 _detached(element); |
| 5863 } |
| 5864 } |
| 5865 function _detached(element) { |
| 5866 if (element.__upgraded__ && (element.attachedCallback || element.detachedCal
lback)) { |
| 5867 if (element.__attached && !inDocument(element)) { |
| 5868 element.__attached = false; |
| 5869 if (element.detachedCallback) { |
| 5870 element.detachedCallback(); |
| 5871 } |
| 5872 } |
| 5873 } |
| 5874 } |
| 5875 function inDocument(element) { |
| 5876 var p = element; |
| 5877 var doc = wrap(document); |
| 5878 while (p) { |
| 5879 if (p == doc) { |
| 5880 return true; |
| 5881 } |
| 5882 p = p.parentNode || p.host; |
| 5883 } |
| 5884 } |
| 5885 function watchShadow(node) { |
| 5886 if (node.shadowRoot && !node.shadowRoot.__watched) { |
| 5887 flags.dom && console.log("watching shadow-root for: ", node.localName); |
| 5888 var root = node.shadowRoot; |
| 5889 while (root) { |
| 5890 observe(root); |
| 5891 root = root.olderShadowRoot; |
| 5892 } |
| 5893 } |
| 5894 } |
| 5895 function handler(mutations) { |
| 5896 if (flags.dom) { |
| 5897 var mx = mutations[0]; |
| 5898 if (mx && mx.type === "childList" && mx.addedNodes) { |
| 5899 if (mx.addedNodes) { |
| 5900 var d = mx.addedNodes[0]; |
| 5901 while (d && d !== document && !d.host) { |
| 5902 d = d.parentNode; |
| 5903 } |
| 5904 var u = d && (d.URL || d._URL || d.host && d.host.localName) || ""; |
| 5905 u = u.split("/?").shift().split("/").pop(); |
| 5906 } |
| 5907 } |
| 5908 console.group("mutations (%d) [%s]", mutations.length, u || ""); |
| 5909 } |
| 5910 mutations.forEach(function(mx) { |
| 5911 if (mx.type === "childList") { |
| 5912 forEach(mx.addedNodes, function(n) { |
| 5913 if (!n.localName) { |
| 5914 return; |
| 5915 } |
| 5916 addedNode(n); |
| 5917 }); |
| 5918 forEach(mx.removedNodes, function(n) { |
| 5919 if (!n.localName) { |
| 5920 return; |
| 5921 } |
| 5922 detachedNode(n); |
| 5923 }); |
| 5924 } |
| 5925 }); |
| 5926 flags.dom && console.groupEnd(); |
| 5927 } |
| 5928 function takeRecords(node) { |
| 5929 node = wrap(node); |
| 5930 if (!node) { |
| 5931 node = wrap(document); |
| 5932 } |
| 5933 while (node.parentNode) { |
| 5934 node = node.parentNode; |
| 5935 } |
| 5936 var observer = node.__observer; |
| 5937 if (observer) { |
| 5938 handler(observer.takeRecords()); |
| 5939 takeMutations(); |
| 5940 } |
| 5941 } |
| 5942 var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach); |
| 5943 function observe(inRoot) { |
| 5944 if (inRoot.__observer) { |
| 5945 return; |
| 5946 } |
| 5947 var observer = new MutationObserver(handler); |
| 5948 observer.observe(inRoot, { |
| 5949 childList: true, |
| 5950 subtree: true |
| 5951 }); |
| 5952 inRoot.__observer = observer; |
| 5953 } |
| 5954 function upgradeDocument(doc) { |
| 5955 doc = wrap(doc); |
| 5956 flags.dom && console.group("upgradeDocument: ", doc.baseURI.split("/").pop()
); |
| 5957 addedNode(doc); |
| 5958 observe(doc); |
| 5959 flags.dom && console.groupEnd(); |
| 5960 } |
| 5961 function upgradeDocumentTree(doc) { |
| 5962 forDocumentTree(doc, upgradeDocument); |
| 5963 } |
| 5964 var originalCreateShadowRoot = Element.prototype.createShadowRoot; |
| 5965 Element.prototype.createShadowRoot = function() { |
| 5966 var root = originalCreateShadowRoot.call(this); |
| 5967 CustomElements.watchShadow(this); |
| 5968 return root; |
| 5969 }; |
| 5970 scope.watchShadow = watchShadow; |
| 5971 scope.upgradeDocumentTree = upgradeDocumentTree; |
| 5972 scope.upgradeSubtree = addedSubtree; |
| 5973 scope.upgradeAll = addedNode; |
| 5974 scope.attachedNode = attachedNode; |
| 5975 scope.takeRecords = takeRecords; |
| 5976 }); |
| 5977 |
| 5978 CustomElements.addModule(function(scope) { |
| 5979 var flags = scope.flags; |
| 5980 function upgrade(node) { |
| 5981 if (!node.__upgraded__ && node.nodeType === Node.ELEMENT_NODE) { |
| 5982 var is = node.getAttribute("is"); |
| 5983 var definition = scope.getRegisteredDefinition(is || node.localName); |
| 5984 if (definition) { |
| 5985 if (is && definition.tag == node.localName) { |
| 5986 return upgradeWithDefinition(node, definition); |
| 5987 } else if (!is && !definition.extends) { |
| 5988 return upgradeWithDefinition(node, definition); |
| 5989 } |
| 5990 } |
| 5991 } |
| 5992 } |
| 5993 function upgradeWithDefinition(element, definition) { |
| 5994 flags.upgrade && console.group("upgrade:", element.localName); |
| 5995 if (definition.is) { |
| 5996 element.setAttribute("is", definition.is); |
| 5997 } |
| 5998 implementPrototype(element, definition); |
| 5999 element.__upgraded__ = true; |
| 6000 created(element); |
| 6001 scope.attachedNode(element); |
| 6002 scope.upgradeSubtree(element); |
| 6003 flags.upgrade && console.groupEnd(); |
| 6004 return element; |
| 6005 } |
| 6006 function implementPrototype(element, definition) { |
| 6007 if (Object.__proto__) { |
| 6008 element.__proto__ = definition.prototype; |
| 6009 } else { |
| 6010 customMixin(element, definition.prototype, definition.native); |
| 6011 element.__proto__ = definition.prototype; |
| 6012 } |
| 6013 } |
| 6014 function customMixin(inTarget, inSrc, inNative) { |
| 6015 var used = {}; |
| 6016 var p = inSrc; |
| 6017 while (p !== inNative && p !== HTMLElement.prototype) { |
| 6018 var keys = Object.getOwnPropertyNames(p); |
| 6019 for (var i = 0, k; k = keys[i]; i++) { |
| 6020 if (!used[k]) { |
| 6021 Object.defineProperty(inTarget, k, Object.getOwnPropertyDescriptor(p,
k)); |
| 6022 used[k] = 1; |
| 6023 } |
| 6024 } |
| 6025 p = Object.getPrototypeOf(p); |
| 6026 } |
| 6027 } |
| 6028 function created(element) { |
| 6029 if (element.createdCallback) { |
| 6030 element.createdCallback(); |
| 6031 } |
| 6032 } |
| 6033 scope.upgrade = upgrade; |
| 6034 scope.upgradeWithDefinition = upgradeWithDefinition; |
| 6035 scope.implementPrototype = implementPrototype; |
| 6036 }); |
| 6037 |
| 6038 CustomElements.addModule(function(scope) { |
| 6039 var upgradeDocumentTree = scope.upgradeDocumentTree; |
| 6040 var upgrade = scope.upgrade; |
| 6041 var upgradeWithDefinition = scope.upgradeWithDefinition; |
| 6042 var implementPrototype = scope.implementPrototype; |
| 6043 var useNative = scope.useNative; |
| 6044 function register(name, options) { |
| 6045 var definition = options || {}; |
| 6046 if (!name) { |
| 6047 throw new Error("document.registerElement: first argument `name` must not
be empty"); |
| 6048 } |
| 6049 if (name.indexOf("-") < 0) { |
| 6050 throw new Error("document.registerElement: first argument ('name') must co
ntain a dash ('-'). Argument provided was '" + String(name) + "'."); |
| 6051 } |
| 6052 if (isReservedTag(name)) { |
| 6053 throw new Error("Failed to execute 'registerElement' on 'Document': Regist
ration failed for type '" + String(name) + "'. The type name is invalid."); |
| 6054 } |
| 6055 if (getRegisteredDefinition(name)) { |
| 6056 throw new Error("DuplicateDefinitionError: a type with name '" + String(na
me) + "' is already registered"); |
| 6057 } |
| 6058 if (!definition.prototype) { |
| 6059 definition.prototype = Object.create(HTMLElement.prototype); |
| 6060 } |
| 6061 definition.__name = name.toLowerCase(); |
| 6062 definition.lifecycle = definition.lifecycle || {}; |
| 6063 definition.ancestry = ancestry(definition.extends); |
| 6064 resolveTagName(definition); |
| 6065 resolvePrototypeChain(definition); |
| 6066 overrideAttributeApi(definition.prototype); |
| 6067 registerDefinition(definition.__name, definition); |
| 6068 definition.ctor = generateConstructor(definition); |
| 6069 definition.ctor.prototype = definition.prototype; |
| 6070 definition.prototype.constructor = definition.ctor; |
| 6071 if (scope.ready) { |
| 6072 upgradeDocumentTree(document); |
| 6073 } |
| 6074 return definition.ctor; |
| 6075 } |
| 6076 function overrideAttributeApi(prototype) { |
| 6077 if (prototype.setAttribute._polyfilled) { |
| 6078 return; |
| 6079 } |
| 6080 var setAttribute = prototype.setAttribute; |
| 6081 prototype.setAttribute = function(name, value) { |
| 6082 changeAttribute.call(this, name, value, setAttribute); |
| 6083 }; |
| 6084 var removeAttribute = prototype.removeAttribute; |
| 6085 prototype.removeAttribute = function(name) { |
| 6086 changeAttribute.call(this, name, null, removeAttribute); |
| 6087 }; |
| 6088 prototype.setAttribute._polyfilled = true; |
| 6089 } |
| 6090 function changeAttribute(name, value, operation) { |
| 6091 name = name.toLowerCase(); |
| 6092 var oldValue = this.getAttribute(name); |
| 6093 operation.apply(this, arguments); |
| 6094 var newValue = this.getAttribute(name); |
| 6095 if (this.attributeChangedCallback && newValue !== oldValue) { |
| 6096 this.attributeChangedCallback(name, oldValue, newValue); |
| 6097 } |
| 6098 } |
| 6099 function isReservedTag(name) { |
| 6100 for (var i = 0; i < reservedTagList.length; i++) { |
| 6101 if (name === reservedTagList[i]) { |
| 6102 return true; |
| 6103 } |
| 6104 } |
| 6105 } |
| 6106 var reservedTagList = [ "annotation-xml", "color-profile", "font-face", "font-
face-src", "font-face-uri", "font-face-format", "font-face-name", "missing-glyph
" ]; |
| 6107 function ancestry(extnds) { |
| 6108 var extendee = getRegisteredDefinition(extnds); |
| 6109 if (extendee) { |
| 6110 return ancestry(extendee.extends).concat([ extendee ]); |
| 6111 } |
| 6112 return []; |
| 6113 } |
| 6114 function resolveTagName(definition) { |
| 6115 var baseTag = definition.extends; |
| 6116 for (var i = 0, a; a = definition.ancestry[i]; i++) { |
| 6117 baseTag = a.is && a.tag; |
| 6118 } |
| 6119 definition.tag = baseTag || definition.__name; |
| 6120 if (baseTag) { |
| 6121 definition.is = definition.__name; |
| 6122 } |
| 6123 } |
| 6124 function resolvePrototypeChain(definition) { |
| 6125 if (!Object.__proto__) { |
| 6126 var nativePrototype = HTMLElement.prototype; |
| 6127 if (definition.is) { |
| 6128 var inst = document.createElement(definition.tag); |
| 6129 var expectedPrototype = Object.getPrototypeOf(inst); |
| 6130 if (expectedPrototype === definition.prototype) { |
| 6131 nativePrototype = expectedPrototype; |
| 6132 } |
| 6133 } |
| 6134 var proto = definition.prototype, ancestor; |
| 6135 while (proto && proto !== nativePrototype) { |
| 6136 ancestor = Object.getPrototypeOf(proto); |
| 6137 proto.__proto__ = ancestor; |
| 6138 proto = ancestor; |
| 6139 } |
| 6140 definition.native = nativePrototype; |
| 6141 } |
| 6142 } |
| 6143 function instantiate(definition) { |
| 6144 return upgradeWithDefinition(domCreateElement(definition.tag), definition); |
| 6145 } |
| 6146 var registry = {}; |
| 6147 function getRegisteredDefinition(name) { |
| 6148 if (name) { |
| 6149 return registry[name.toLowerCase()]; |
| 6150 } |
| 6151 } |
| 6152 function registerDefinition(name, definition) { |
| 6153 registry[name] = definition; |
| 6154 } |
| 6155 function generateConstructor(definition) { |
| 6156 return function() { |
| 6157 return instantiate(definition); |
| 6158 }; |
| 6159 } |
| 6160 var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml"; |
| 6161 function createElementNS(namespace, tag, typeExtension) { |
| 6162 if (namespace === HTML_NAMESPACE) { |
| 6163 return createElement(tag, typeExtension); |
| 6164 } else { |
| 6165 return domCreateElementNS(namespace, tag); |
| 6166 } |
| 6167 } |
| 6168 function createElement(tag, typeExtension) { |
| 6169 var definition = getRegisteredDefinition(typeExtension || tag); |
| 6170 if (definition) { |
| 6171 if (tag == definition.tag && typeExtension == definition.is) { |
| 6172 return new definition.ctor(); |
| 6173 } |
| 6174 if (!typeExtension && !definition.is) { |
| 6175 return new definition.ctor(); |
| 6176 } |
| 6177 } |
| 6178 var element; |
| 6179 if (typeExtension) { |
| 6180 element = createElement(tag); |
| 6181 element.setAttribute("is", typeExtension); |
| 6182 return element; |
| 6183 } |
| 6184 element = domCreateElement(tag); |
| 6185 if (tag.indexOf("-") >= 0) { |
| 6186 implementPrototype(element, HTMLElement); |
| 6187 } |
| 6188 return element; |
| 6189 } |
| 6190 function cloneNode(deep) { |
| 6191 var n = domCloneNode.call(this, deep); |
| 6192 upgrade(n); |
| 6193 return n; |
| 6194 } |
| 6195 var domCreateElement = document.createElement.bind(document); |
| 6196 var domCreateElementNS = document.createElementNS.bind(document); |
| 6197 var domCloneNode = Node.prototype.cloneNode; |
| 6198 var isInstance; |
| 6199 if (!Object.__proto__ && !useNative) { |
| 6200 isInstance = function(obj, ctor) { |
| 6201 var p = obj; |
| 6202 while (p) { |
| 6203 if (p === ctor.prototype) { |
| 6204 return true; |
| 6205 } |
| 6206 p = p.__proto__; |
| 6207 } |
| 6208 return false; |
| 6209 }; |
| 6210 } else { |
| 6211 isInstance = function(obj, base) { |
| 6212 return obj instanceof base; |
| 6213 }; |
| 6214 } |
| 6215 document.registerElement = register; |
| 6216 document.createElement = createElement; |
| 6217 document.createElementNS = createElementNS; |
| 6218 Node.prototype.cloneNode = cloneNode; |
| 6219 scope.registry = registry; |
| 6220 scope.instanceof = isInstance; |
| 6221 scope.reservedTagList = reservedTagList; |
| 6222 scope.getRegisteredDefinition = getRegisteredDefinition; |
| 6223 document.register = document.registerElement; |
| 6224 }); |
| 6225 |
| 6226 (function(scope) { |
| 6227 var useNative = scope.useNative; |
| 6228 var initializeModules = scope.initializeModules; |
| 6229 var isIE11OrOlder = /Trident/.test(navigator.userAgent); |
| 6230 if (useNative) { |
| 6231 var nop = function() {}; |
| 6232 scope.watchShadow = nop; |
| 6233 scope.upgrade = nop; |
| 6234 scope.upgradeAll = nop; |
| 6235 scope.upgradeDocumentTree = nop; |
| 6236 scope.upgradeSubtree = nop; |
| 6237 scope.takeRecords = nop; |
| 6238 scope.instanceof = function(obj, base) { |
| 6239 return obj instanceof base; |
| 6240 }; |
| 6241 } else { |
| 6242 initializeModules(); |
| 6243 } |
| 6244 var upgradeDocumentTree = scope.upgradeDocumentTree; |
| 6245 if (!window.wrap) { |
| 6246 if (window.ShadowDOMPolyfill) { |
| 6247 window.wrap = ShadowDOMPolyfill.wrapIfNeeded; |
| 6248 window.unwrap = ShadowDOMPolyfill.unwrapIfNeeded; |
| 6249 } else { |
| 6250 window.wrap = window.unwrap = function(node) { |
| 6251 return node; |
| 6252 }; |
| 6253 } |
| 6254 } |
| 6255 function bootstrap() { |
| 6256 upgradeDocumentTree(wrap(document)); |
| 6257 if (window.HTMLImports) { |
| 6258 HTMLImports.__importsParsingHook = function(elt) { |
| 6259 upgradeDocumentTree(wrap(elt.import)); |
| 6260 }; |
| 6261 } |
| 6262 CustomElements.ready = true; |
| 6263 setTimeout(function() { |
| 6264 CustomElements.readyTime = Date.now(); |
| 6265 if (window.HTMLImports) { |
| 6266 CustomElements.elapsed = CustomElements.readyTime - HTMLImports.readyTim
e; |
| 6267 } |
| 6268 document.dispatchEvent(new CustomEvent("WebComponentsReady", { |
| 6269 bubbles: true |
| 6270 })); |
| 6271 }); |
| 6272 } |
| 6273 if (isIE11OrOlder && typeof window.CustomEvent !== "function") { |
| 6274 window.CustomEvent = function(inType, params) { |
| 6275 params = params || {}; |
| 6276 var e = document.createEvent("CustomEvent"); |
| 6277 e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelab
le), params.detail); |
| 6278 return e; |
| 6279 }; |
| 6280 window.CustomEvent.prototype = window.Event.prototype; |
| 6281 } |
| 6282 if (document.readyState === "complete" || scope.flags.eager) { |
| 6283 bootstrap(); |
| 6284 } else if (document.readyState === "interactive" && !window.attachEvent && (!w
indow.HTMLImports || window.HTMLImports.ready)) { |
| 6285 bootstrap(); |
| 6286 } else { |
| 6287 var loadEvent = window.HTMLImports && !HTMLImports.ready ? "HTMLImportsLoade
d" : "DOMContentLoaded"; |
| 6288 window.addEventListener(loadEvent, bootstrap); |
| 6289 } |
| 6290 })(window.CustomElements); |
| 6291 |
| 6292 (function(scope) { |
| 6293 if (!Function.prototype.bind) { |
| 6294 Function.prototype.bind = function(scope) { |
| 6295 var self = this; |
| 6296 var args = Array.prototype.slice.call(arguments, 1); |
| 6297 return function() { |
| 6298 var args2 = args.slice(); |
| 6299 args2.push.apply(args2, arguments); |
| 6300 return self.apply(scope, args2); |
| 6301 }; |
| 6302 }; |
| 6303 } |
| 6304 })(window.WebComponents); |
| 6305 |
| 6306 (function(scope) { |
| 6307 "use strict"; |
| 6308 if (!window.performance) { |
| 6309 var start = Date.now(); |
| 6310 window.performance = { |
| 6311 now: function() { |
| 6312 return Date.now() - start; |
| 6313 } |
| 6314 }; |
| 6315 } |
| 6316 if (!window.requestAnimationFrame) { |
| 6317 window.requestAnimationFrame = function() { |
| 6318 var nativeRaf = window.webkitRequestAnimationFrame || window.mozRequestAni
mationFrame; |
| 6319 return nativeRaf ? function(callback) { |
| 6320 return nativeRaf(function() { |
| 6321 callback(performance.now()); |
| 6322 }); |
| 6323 } : function(callback) { |
| 6324 return window.setTimeout(callback, 1e3 / 60); |
| 6325 }; |
| 6326 }(); |
| 6327 } |
| 6328 if (!window.cancelAnimationFrame) { |
| 6329 window.cancelAnimationFrame = function() { |
| 6330 return window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame
|| function(id) { |
| 6331 clearTimeout(id); |
| 6332 }; |
| 6333 }(); |
| 6334 } |
| 6335 var elementDeclarations = []; |
| 6336 var polymerStub = function(name, dictionary) { |
| 6337 if (typeof name !== "string" && arguments.length === 1) { |
| 6338 Array.prototype.push.call(arguments, document._currentScript); |
| 6339 } |
| 6340 elementDeclarations.push(arguments); |
| 6341 }; |
| 6342 window.Polymer = polymerStub; |
| 6343 scope.consumeDeclarations = function(callback) { |
| 6344 scope.consumeDeclarations = function() { |
| 6345 throw "Possible attempt to load Polymer twice"; |
| 6346 }; |
| 6347 if (callback) { |
| 6348 callback(elementDeclarations); |
| 6349 } |
| 6350 elementDeclarations = null; |
| 6351 }; |
| 6352 function installPolymerWarning() { |
| 6353 if (window.Polymer === polymerStub) { |
| 6354 window.Polymer = function() { |
| 6355 throw new Error("You tried to use polymer without loading it first. To "
+ 'load polymer, <link rel="import" href="' + 'components/polymer/polymer.html"
>'); |
| 6356 }; |
| 6357 } |
| 6358 } |
| 6359 if (HTMLImports.useNative) { |
| 6360 installPolymerWarning(); |
| 6361 } else { |
| 6362 addEventListener("DOMContentLoaded", installPolymerWarning); |
| 6363 } |
| 6364 })(window.WebComponents); |
| 6365 |
| 6366 (function(scope) { |
| 6367 var style = document.createElement("style"); |
| 6368 style.textContent = "" + "body {" + "transition: opacity ease-in 0.2s;" + " }
\n" + "body[unresolved] {" + "opacity: 0; display: block; overflow: hidden; posi
tion: relative;" + " } \n"; |
| 6369 var head = document.querySelector("head"); |
| 6370 head.insertBefore(style, head.firstChild); |
| 6371 })(window.WebComponents); |
| 6372 |
| 6373 (function(scope) { |
| 6374 window.Platform = scope; |
| 6375 })(window.WebComponents); |
OLD | NEW |