polymer-rails 1.2.4.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4496 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4
- * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5
- * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6
- * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7
- * Code distributed by Google as part of the polymer project is also
8
- * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9
- */
10
- // @version 0.7.20
11
- if (typeof WeakMap === "undefined") {
12
- (function() {
13
- var defineProperty = Object.defineProperty;
14
- var counter = Date.now() % 1e9;
15
- var WeakMap = function() {
16
- this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__");
17
- };
18
- WeakMap.prototype = {
19
- set: function(key, value) {
20
- var entry = key[this.name];
21
- if (entry && entry[0] === key) entry[1] = value; else defineProperty(key, this.name, {
22
- value: [ key, value ],
23
- writable: true
24
- });
25
- return this;
26
- },
27
- get: function(key) {
28
- var entry;
29
- return (entry = key[this.name]) && entry[0] === key ? entry[1] : undefined;
30
- },
31
- "delete": function(key) {
32
- var entry = key[this.name];
33
- if (!entry || entry[0] !== key) return false;
34
- entry[0] = entry[1] = undefined;
35
- return true;
36
- },
37
- has: function(key) {
38
- var entry = key[this.name];
39
- if (!entry) return false;
40
- return entry[0] === key;
41
- }
42
- };
43
- window.WeakMap = WeakMap;
44
- })();
45
- }
46
-
47
- window.ShadowDOMPolyfill = {};
48
-
49
- (function(scope) {
50
- "use strict";
51
- var constructorTable = new WeakMap();
52
- var nativePrototypeTable = new WeakMap();
53
- var wrappers = Object.create(null);
54
- function detectEval() {
55
- if (typeof chrome !== "undefined" && chrome.app && chrome.app.runtime) {
56
- return false;
57
- }
58
- if (navigator.getDeviceStorage) {
59
- return false;
60
- }
61
- try {
62
- var f = new Function("return true;");
63
- return f();
64
- } catch (ex) {
65
- return false;
66
- }
67
- }
68
- var hasEval = detectEval();
69
- function assert(b) {
70
- if (!b) throw new Error("Assertion failed");
71
- }
72
- var defineProperty = Object.defineProperty;
73
- var getOwnPropertyNames = Object.getOwnPropertyNames;
74
- var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
75
- function mixin(to, from) {
76
- var names = getOwnPropertyNames(from);
77
- for (var i = 0; i < names.length; i++) {
78
- var name = names[i];
79
- defineProperty(to, name, getOwnPropertyDescriptor(from, name));
80
- }
81
- return to;
82
- }
83
- function mixinStatics(to, from) {
84
- var names = getOwnPropertyNames(from);
85
- for (var i = 0; i < names.length; i++) {
86
- var name = names[i];
87
- switch (name) {
88
- case "arguments":
89
- case "caller":
90
- case "length":
91
- case "name":
92
- case "prototype":
93
- case "toString":
94
- continue;
95
- }
96
- defineProperty(to, name, getOwnPropertyDescriptor(from, name));
97
- }
98
- return to;
99
- }
100
- function oneOf(object, propertyNames) {
101
- for (var i = 0; i < propertyNames.length; i++) {
102
- if (propertyNames[i] in object) return propertyNames[i];
103
- }
104
- }
105
- var nonEnumerableDataDescriptor = {
106
- value: undefined,
107
- configurable: true,
108
- enumerable: false,
109
- writable: true
110
- };
111
- function defineNonEnumerableDataProperty(object, name, value) {
112
- nonEnumerableDataDescriptor.value = value;
113
- defineProperty(object, name, nonEnumerableDataDescriptor);
114
- }
115
- getOwnPropertyNames(window);
116
- function getWrapperConstructor(node, opt_instance) {
117
- var nativePrototype = node.__proto__ || Object.getPrototypeOf(node);
118
- if (isFirefox) {
119
- try {
120
- getOwnPropertyNames(nativePrototype);
121
- } catch (error) {
122
- nativePrototype = nativePrototype.__proto__;
123
- }
124
- }
125
- var wrapperConstructor = constructorTable.get(nativePrototype);
126
- if (wrapperConstructor) return wrapperConstructor;
127
- var parentWrapperConstructor = getWrapperConstructor(nativePrototype);
128
- var GeneratedWrapper = createWrapperConstructor(parentWrapperConstructor);
129
- registerInternal(nativePrototype, GeneratedWrapper, opt_instance);
130
- return GeneratedWrapper;
131
- }
132
- function addForwardingProperties(nativePrototype, wrapperPrototype) {
133
- installProperty(nativePrototype, wrapperPrototype, true);
134
- }
135
- function registerInstanceProperties(wrapperPrototype, instanceObject) {
136
- installProperty(instanceObject, wrapperPrototype, false);
137
- }
138
- var isFirefox = /Firefox/.test(navigator.userAgent);
139
- var dummyDescriptor = {
140
- get: function() {},
141
- set: function(v) {},
142
- configurable: true,
143
- enumerable: true
144
- };
145
- function isEventHandlerName(name) {
146
- return /^on[a-z]+$/.test(name);
147
- }
148
- function isIdentifierName(name) {
149
- return /^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test(name);
150
- }
151
- function getGetter(name) {
152
- return hasEval && isIdentifierName(name) ? new Function("return this.__impl4cf1e782hg__." + name) : function() {
153
- return this.__impl4cf1e782hg__[name];
154
- };
155
- }
156
- function getSetter(name) {
157
- return hasEval && isIdentifierName(name) ? new Function("v", "this.__impl4cf1e782hg__." + name + " = v") : function(v) {
158
- this.__impl4cf1e782hg__[name] = v;
159
- };
160
- }
161
- function getMethod(name) {
162
- return hasEval && isIdentifierName(name) ? new Function("return this.__impl4cf1e782hg__." + name + ".apply(this.__impl4cf1e782hg__, arguments)") : function() {
163
- return this.__impl4cf1e782hg__[name].apply(this.__impl4cf1e782hg__, arguments);
164
- };
165
- }
166
- function getDescriptor(source, name) {
167
- try {
168
- return Object.getOwnPropertyDescriptor(source, name);
169
- } catch (ex) {
170
- return dummyDescriptor;
171
- }
172
- }
173
- var isBrokenSafari = function() {
174
- var descr = Object.getOwnPropertyDescriptor(Node.prototype, "nodeType");
175
- return descr && !descr.get && !descr.set;
176
- }();
177
- function installProperty(source, target, allowMethod, opt_blacklist) {
178
- var names = getOwnPropertyNames(source);
179
- for (var i = 0; i < names.length; i++) {
180
- var name = names[i];
181
- if (name === "polymerBlackList_") continue;
182
- if (name in target) continue;
183
- if (source.polymerBlackList_ && source.polymerBlackList_[name]) continue;
184
- if (isFirefox) {
185
- source.__lookupGetter__(name);
186
- }
187
- var descriptor = getDescriptor(source, name);
188
- var getter, setter;
189
- if (typeof descriptor.value === "function") {
190
- if (allowMethod) {
191
- target[name] = getMethod(name);
192
- }
193
- continue;
194
- }
195
- var isEvent = isEventHandlerName(name);
196
- if (isEvent) getter = scope.getEventHandlerGetter(name); else getter = getGetter(name);
197
- if (descriptor.writable || descriptor.set || isBrokenSafari) {
198
- if (isEvent) setter = scope.getEventHandlerSetter(name); else setter = getSetter(name);
199
- }
200
- var configurable = isBrokenSafari || descriptor.configurable;
201
- defineProperty(target, name, {
202
- get: getter,
203
- set: setter,
204
- configurable: configurable,
205
- enumerable: descriptor.enumerable
206
- });
207
- }
208
- }
209
- function register(nativeConstructor, wrapperConstructor, opt_instance) {
210
- if (nativeConstructor == null) {
211
- return;
212
- }
213
- var nativePrototype = nativeConstructor.prototype;
214
- registerInternal(nativePrototype, wrapperConstructor, opt_instance);
215
- mixinStatics(wrapperConstructor, nativeConstructor);
216
- }
217
- function registerInternal(nativePrototype, wrapperConstructor, opt_instance) {
218
- var wrapperPrototype = wrapperConstructor.prototype;
219
- assert(constructorTable.get(nativePrototype) === undefined);
220
- constructorTable.set(nativePrototype, wrapperConstructor);
221
- nativePrototypeTable.set(wrapperPrototype, nativePrototype);
222
- addForwardingProperties(nativePrototype, wrapperPrototype);
223
- if (opt_instance) registerInstanceProperties(wrapperPrototype, opt_instance);
224
- defineNonEnumerableDataProperty(wrapperPrototype, "constructor", wrapperConstructor);
225
- wrapperConstructor.prototype = wrapperPrototype;
226
- }
227
- function isWrapperFor(wrapperConstructor, nativeConstructor) {
228
- return constructorTable.get(nativeConstructor.prototype) === wrapperConstructor;
229
- }
230
- function registerObject(object) {
231
- var nativePrototype = Object.getPrototypeOf(object);
232
- var superWrapperConstructor = getWrapperConstructor(nativePrototype);
233
- var GeneratedWrapper = createWrapperConstructor(superWrapperConstructor);
234
- registerInternal(nativePrototype, GeneratedWrapper, object);
235
- return GeneratedWrapper;
236
- }
237
- function createWrapperConstructor(superWrapperConstructor) {
238
- function GeneratedWrapper(node) {
239
- superWrapperConstructor.call(this, node);
240
- }
241
- var p = Object.create(superWrapperConstructor.prototype);
242
- p.constructor = GeneratedWrapper;
243
- GeneratedWrapper.prototype = p;
244
- return GeneratedWrapper;
245
- }
246
- function isWrapper(object) {
247
- return object && object.__impl4cf1e782hg__;
248
- }
249
- function isNative(object) {
250
- return !isWrapper(object);
251
- }
252
- function wrap(impl) {
253
- if (impl === null) return null;
254
- assert(isNative(impl));
255
- var wrapper = impl.__wrapper8e3dd93a60__;
256
- if (wrapper != null) {
257
- return wrapper;
258
- }
259
- return impl.__wrapper8e3dd93a60__ = new (getWrapperConstructor(impl, impl))(impl);
260
- }
261
- function unwrap(wrapper) {
262
- if (wrapper === null) return null;
263
- assert(isWrapper(wrapper));
264
- return wrapper.__impl4cf1e782hg__;
265
- }
266
- function unsafeUnwrap(wrapper) {
267
- return wrapper.__impl4cf1e782hg__;
268
- }
269
- function setWrapper(impl, wrapper) {
270
- wrapper.__impl4cf1e782hg__ = impl;
271
- impl.__wrapper8e3dd93a60__ = wrapper;
272
- }
273
- function unwrapIfNeeded(object) {
274
- return object && isWrapper(object) ? unwrap(object) : object;
275
- }
276
- function wrapIfNeeded(object) {
277
- return object && !isWrapper(object) ? wrap(object) : object;
278
- }
279
- function rewrap(node, wrapper) {
280
- if (wrapper === null) return;
281
- assert(isNative(node));
282
- assert(wrapper === undefined || isWrapper(wrapper));
283
- node.__wrapper8e3dd93a60__ = wrapper;
284
- }
285
- var getterDescriptor = {
286
- get: undefined,
287
- configurable: true,
288
- enumerable: true
289
- };
290
- function defineGetter(constructor, name, getter) {
291
- getterDescriptor.get = getter;
292
- defineProperty(constructor.prototype, name, getterDescriptor);
293
- }
294
- function defineWrapGetter(constructor, name) {
295
- defineGetter(constructor, name, function() {
296
- return wrap(this.__impl4cf1e782hg__[name]);
297
- });
298
- }
299
- function forwardMethodsToWrapper(constructors, names) {
300
- constructors.forEach(function(constructor) {
301
- names.forEach(function(name) {
302
- constructor.prototype[name] = function() {
303
- var w = wrapIfNeeded(this);
304
- return w[name].apply(w, arguments);
305
- };
306
- });
307
- });
308
- }
309
- scope.addForwardingProperties = addForwardingProperties;
310
- scope.assert = assert;
311
- scope.constructorTable = constructorTable;
312
- scope.defineGetter = defineGetter;
313
- scope.defineWrapGetter = defineWrapGetter;
314
- scope.forwardMethodsToWrapper = forwardMethodsToWrapper;
315
- scope.isIdentifierName = isIdentifierName;
316
- scope.isWrapper = isWrapper;
317
- scope.isWrapperFor = isWrapperFor;
318
- scope.mixin = mixin;
319
- scope.nativePrototypeTable = nativePrototypeTable;
320
- scope.oneOf = oneOf;
321
- scope.registerObject = registerObject;
322
- scope.registerWrapper = register;
323
- scope.rewrap = rewrap;
324
- scope.setWrapper = setWrapper;
325
- scope.unsafeUnwrap = unsafeUnwrap;
326
- scope.unwrap = unwrap;
327
- scope.unwrapIfNeeded = unwrapIfNeeded;
328
- scope.wrap = wrap;
329
- scope.wrapIfNeeded = wrapIfNeeded;
330
- scope.wrappers = wrappers;
331
- })(window.ShadowDOMPolyfill);
332
-
333
- (function(scope) {
334
- "use strict";
335
- function newSplice(index, removed, addedCount) {
336
- return {
337
- index: index,
338
- removed: removed,
339
- addedCount: addedCount
340
- };
341
- }
342
- var EDIT_LEAVE = 0;
343
- var EDIT_UPDATE = 1;
344
- var EDIT_ADD = 2;
345
- var EDIT_DELETE = 3;
346
- function ArraySplice() {}
347
- ArraySplice.prototype = {
348
- calcEditDistances: function(current, currentStart, currentEnd, old, oldStart, oldEnd) {
349
- var rowCount = oldEnd - oldStart + 1;
350
- var columnCount = currentEnd - currentStart + 1;
351
- var distances = new Array(rowCount);
352
- for (var i = 0; i < rowCount; i++) {
353
- distances[i] = new Array(columnCount);
354
- distances[i][0] = i;
355
- }
356
- for (var j = 0; j < columnCount; j++) distances[0][j] = j;
357
- for (var i = 1; i < rowCount; i++) {
358
- for (var j = 1; j < columnCount; j++) {
359
- if (this.equals(current[currentStart + j - 1], old[oldStart + i - 1])) distances[i][j] = distances[i - 1][j - 1]; else {
360
- var north = distances[i - 1][j] + 1;
361
- var west = distances[i][j - 1] + 1;
362
- distances[i][j] = north < west ? north : west;
363
- }
364
- }
365
- }
366
- return distances;
367
- },
368
- spliceOperationsFromEditDistances: function(distances) {
369
- var i = distances.length - 1;
370
- var j = distances[0].length - 1;
371
- var current = distances[i][j];
372
- var edits = [];
373
- while (i > 0 || j > 0) {
374
- if (i == 0) {
375
- edits.push(EDIT_ADD);
376
- j--;
377
- continue;
378
- }
379
- if (j == 0) {
380
- edits.push(EDIT_DELETE);
381
- i--;
382
- continue;
383
- }
384
- var northWest = distances[i - 1][j - 1];
385
- var west = distances[i - 1][j];
386
- var north = distances[i][j - 1];
387
- var min;
388
- if (west < north) min = west < northWest ? west : northWest; else min = north < northWest ? north : northWest;
389
- if (min == northWest) {
390
- if (northWest == current) {
391
- edits.push(EDIT_LEAVE);
392
- } else {
393
- edits.push(EDIT_UPDATE);
394
- current = northWest;
395
- }
396
- i--;
397
- j--;
398
- } else if (min == west) {
399
- edits.push(EDIT_DELETE);
400
- i--;
401
- current = west;
402
- } else {
403
- edits.push(EDIT_ADD);
404
- j--;
405
- current = north;
406
- }
407
- }
408
- edits.reverse();
409
- return edits;
410
- },
411
- calcSplices: function(current, currentStart, currentEnd, old, oldStart, oldEnd) {
412
- var prefixCount = 0;
413
- var suffixCount = 0;
414
- var minLength = Math.min(currentEnd - currentStart, oldEnd - oldStart);
415
- if (currentStart == 0 && oldStart == 0) prefixCount = this.sharedPrefix(current, old, minLength);
416
- if (currentEnd == current.length && oldEnd == old.length) suffixCount = this.sharedSuffix(current, old, minLength - prefixCount);
417
- currentStart += prefixCount;
418
- oldStart += prefixCount;
419
- currentEnd -= suffixCount;
420
- oldEnd -= suffixCount;
421
- if (currentEnd - currentStart == 0 && oldEnd - oldStart == 0) return [];
422
- if (currentStart == currentEnd) {
423
- var splice = newSplice(currentStart, [], 0);
424
- while (oldStart < oldEnd) splice.removed.push(old[oldStart++]);
425
- return [ splice ];
426
- } else if (oldStart == oldEnd) return [ newSplice(currentStart, [], currentEnd - currentStart) ];
427
- var ops = this.spliceOperationsFromEditDistances(this.calcEditDistances(current, currentStart, currentEnd, old, oldStart, oldEnd));
428
- var splice = undefined;
429
- var splices = [];
430
- var index = currentStart;
431
- var oldIndex = oldStart;
432
- for (var i = 0; i < ops.length; i++) {
433
- switch (ops[i]) {
434
- case EDIT_LEAVE:
435
- if (splice) {
436
- splices.push(splice);
437
- splice = undefined;
438
- }
439
- index++;
440
- oldIndex++;
441
- break;
442
-
443
- case EDIT_UPDATE:
444
- if (!splice) splice = newSplice(index, [], 0);
445
- splice.addedCount++;
446
- index++;
447
- splice.removed.push(old[oldIndex]);
448
- oldIndex++;
449
- break;
450
-
451
- case EDIT_ADD:
452
- if (!splice) splice = newSplice(index, [], 0);
453
- splice.addedCount++;
454
- index++;
455
- break;
456
-
457
- case EDIT_DELETE:
458
- if (!splice) splice = newSplice(index, [], 0);
459
- splice.removed.push(old[oldIndex]);
460
- oldIndex++;
461
- break;
462
- }
463
- }
464
- if (splice) {
465
- splices.push(splice);
466
- }
467
- return splices;
468
- },
469
- sharedPrefix: function(current, old, searchLength) {
470
- for (var i = 0; i < searchLength; i++) if (!this.equals(current[i], old[i])) return i;
471
- return searchLength;
472
- },
473
- sharedSuffix: function(current, old, searchLength) {
474
- var index1 = current.length;
475
- var index2 = old.length;
476
- var count = 0;
477
- while (count < searchLength && this.equals(current[--index1], old[--index2])) count++;
478
- return count;
479
- },
480
- calculateSplices: function(current, previous) {
481
- return this.calcSplices(current, 0, current.length, previous, 0, previous.length);
482
- },
483
- equals: function(currentValue, previousValue) {
484
- return currentValue === previousValue;
485
- }
486
- };
487
- scope.ArraySplice = ArraySplice;
488
- })(window.ShadowDOMPolyfill);
489
-
490
- (function(context) {
491
- "use strict";
492
- var OriginalMutationObserver = window.MutationObserver;
493
- var callbacks = [];
494
- var pending = false;
495
- var timerFunc;
496
- function handle() {
497
- pending = false;
498
- var copies = callbacks.slice(0);
499
- callbacks = [];
500
- for (var i = 0; i < copies.length; i++) {
501
- (0, copies[i])();
502
- }
503
- }
504
- if (OriginalMutationObserver) {
505
- var counter = 1;
506
- var observer = new OriginalMutationObserver(handle);
507
- var textNode = document.createTextNode(counter);
508
- observer.observe(textNode, {
509
- characterData: true
510
- });
511
- timerFunc = function() {
512
- counter = (counter + 1) % 2;
513
- textNode.data = counter;
514
- };
515
- } else {
516
- timerFunc = window.setTimeout;
517
- }
518
- function setEndOfMicrotask(func) {
519
- callbacks.push(func);
520
- if (pending) return;
521
- pending = true;
522
- timerFunc(handle, 0);
523
- }
524
- context.setEndOfMicrotask = setEndOfMicrotask;
525
- })(window.ShadowDOMPolyfill);
526
-
527
- (function(scope) {
528
- "use strict";
529
- var setEndOfMicrotask = scope.setEndOfMicrotask;
530
- var wrapIfNeeded = scope.wrapIfNeeded;
531
- var wrappers = scope.wrappers;
532
- var registrationsTable = new WeakMap();
533
- var globalMutationObservers = [];
534
- var isScheduled = false;
535
- function scheduleCallback(observer) {
536
- if (observer.scheduled_) return;
537
- observer.scheduled_ = true;
538
- globalMutationObservers.push(observer);
539
- if (isScheduled) return;
540
- setEndOfMicrotask(notifyObservers);
541
- isScheduled = true;
542
- }
543
- function notifyObservers() {
544
- isScheduled = false;
545
- while (globalMutationObservers.length) {
546
- var notifyList = globalMutationObservers;
547
- globalMutationObservers = [];
548
- notifyList.sort(function(x, y) {
549
- return x.uid_ - y.uid_;
550
- });
551
- for (var i = 0; i < notifyList.length; i++) {
552
- var mo = notifyList[i];
553
- mo.scheduled_ = false;
554
- var queue = mo.takeRecords();
555
- removeTransientObserversFor(mo);
556
- if (queue.length) {
557
- mo.callback_(queue, mo);
558
- }
559
- }
560
- }
561
- }
562
- function MutationRecord(type, target) {
563
- this.type = type;
564
- this.target = target;
565
- this.addedNodes = new wrappers.NodeList();
566
- this.removedNodes = new wrappers.NodeList();
567
- this.previousSibling = null;
568
- this.nextSibling = null;
569
- this.attributeName = null;
570
- this.attributeNamespace = null;
571
- this.oldValue = null;
572
- }
573
- function registerTransientObservers(ancestor, node) {
574
- for (;ancestor; ancestor = ancestor.parentNode) {
575
- var registrations = registrationsTable.get(ancestor);
576
- if (!registrations) continue;
577
- for (var i = 0; i < registrations.length; i++) {
578
- var registration = registrations[i];
579
- if (registration.options.subtree) registration.addTransientObserver(node);
580
- }
581
- }
582
- }
583
- function removeTransientObserversFor(observer) {
584
- for (var i = 0; i < observer.nodes_.length; i++) {
585
- var node = observer.nodes_[i];
586
- var registrations = registrationsTable.get(node);
587
- if (!registrations) return;
588
- for (var j = 0; j < registrations.length; j++) {
589
- var registration = registrations[j];
590
- if (registration.observer === observer) registration.removeTransientObservers();
591
- }
592
- }
593
- }
594
- function enqueueMutation(target, type, data) {
595
- var interestedObservers = Object.create(null);
596
- var associatedStrings = Object.create(null);
597
- for (var node = target; node; node = node.parentNode) {
598
- var registrations = registrationsTable.get(node);
599
- if (!registrations) continue;
600
- for (var j = 0; j < registrations.length; j++) {
601
- var registration = registrations[j];
602
- var options = registration.options;
603
- if (node !== target && !options.subtree) continue;
604
- if (type === "attributes" && !options.attributes) continue;
605
- if (type === "attributes" && options.attributeFilter && (data.namespace !== null || options.attributeFilter.indexOf(data.name) === -1)) {
606
- continue;
607
- }
608
- if (type === "characterData" && !options.characterData) continue;
609
- if (type === "childList" && !options.childList) continue;
610
- var observer = registration.observer;
611
- interestedObservers[observer.uid_] = observer;
612
- if (type === "attributes" && options.attributeOldValue || type === "characterData" && options.characterDataOldValue) {
613
- associatedStrings[observer.uid_] = data.oldValue;
614
- }
615
- }
616
- }
617
- for (var uid in interestedObservers) {
618
- var observer = interestedObservers[uid];
619
- var record = new MutationRecord(type, target);
620
- if ("name" in data && "namespace" in data) {
621
- record.attributeName = data.name;
622
- record.attributeNamespace = data.namespace;
623
- }
624
- if (data.addedNodes) record.addedNodes = data.addedNodes;
625
- if (data.removedNodes) record.removedNodes = data.removedNodes;
626
- if (data.previousSibling) record.previousSibling = data.previousSibling;
627
- if (data.nextSibling) record.nextSibling = data.nextSibling;
628
- if (associatedStrings[uid] !== undefined) record.oldValue = associatedStrings[uid];
629
- scheduleCallback(observer);
630
- observer.records_.push(record);
631
- }
632
- }
633
- var slice = Array.prototype.slice;
634
- function MutationObserverOptions(options) {
635
- this.childList = !!options.childList;
636
- this.subtree = !!options.subtree;
637
- if (!("attributes" in options) && ("attributeOldValue" in options || "attributeFilter" in options)) {
638
- this.attributes = true;
639
- } else {
640
- this.attributes = !!options.attributes;
641
- }
642
- if ("characterDataOldValue" in options && !("characterData" in options)) this.characterData = true; else this.characterData = !!options.characterData;
643
- if (!this.attributes && (options.attributeOldValue || "attributeFilter" in options) || !this.characterData && options.characterDataOldValue) {
644
- throw new TypeError();
645
- }
646
- this.characterData = !!options.characterData;
647
- this.attributeOldValue = !!options.attributeOldValue;
648
- this.characterDataOldValue = !!options.characterDataOldValue;
649
- if ("attributeFilter" in options) {
650
- if (options.attributeFilter == null || typeof options.attributeFilter !== "object") {
651
- throw new TypeError();
652
- }
653
- this.attributeFilter = slice.call(options.attributeFilter);
654
- } else {
655
- this.attributeFilter = null;
656
- }
657
- }
658
- var uidCounter = 0;
659
- function MutationObserver(callback) {
660
- this.callback_ = callback;
661
- this.nodes_ = [];
662
- this.records_ = [];
663
- this.uid_ = ++uidCounter;
664
- this.scheduled_ = false;
665
- }
666
- MutationObserver.prototype = {
667
- constructor: MutationObserver,
668
- observe: function(target, options) {
669
- target = wrapIfNeeded(target);
670
- var newOptions = new MutationObserverOptions(options);
671
- var registration;
672
- var registrations = registrationsTable.get(target);
673
- if (!registrations) registrationsTable.set(target, registrations = []);
674
- for (var i = 0; i < registrations.length; i++) {
675
- if (registrations[i].observer === this) {
676
- registration = registrations[i];
677
- registration.removeTransientObservers();
678
- registration.options = newOptions;
679
- }
680
- }
681
- if (!registration) {
682
- registration = new Registration(this, target, newOptions);
683
- registrations.push(registration);
684
- this.nodes_.push(target);
685
- }
686
- },
687
- disconnect: function() {
688
- this.nodes_.forEach(function(node) {
689
- var registrations = registrationsTable.get(node);
690
- for (var i = 0; i < registrations.length; i++) {
691
- var registration = registrations[i];
692
- if (registration.observer === this) {
693
- registrations.splice(i, 1);
694
- break;
695
- }
696
- }
697
- }, this);
698
- this.records_ = [];
699
- },
700
- takeRecords: function() {
701
- var copyOfRecords = this.records_;
702
- this.records_ = [];
703
- return copyOfRecords;
704
- }
705
- };
706
- function Registration(observer, target, options) {
707
- this.observer = observer;
708
- this.target = target;
709
- this.options = options;
710
- this.transientObservedNodes = [];
711
- }
712
- Registration.prototype = {
713
- addTransientObserver: function(node) {
714
- if (node === this.target) return;
715
- scheduleCallback(this.observer);
716
- this.transientObservedNodes.push(node);
717
- var registrations = registrationsTable.get(node);
718
- if (!registrations) registrationsTable.set(node, registrations = []);
719
- registrations.push(this);
720
- },
721
- removeTransientObservers: function() {
722
- var transientObservedNodes = this.transientObservedNodes;
723
- this.transientObservedNodes = [];
724
- for (var i = 0; i < transientObservedNodes.length; i++) {
725
- var node = transientObservedNodes[i];
726
- var registrations = registrationsTable.get(node);
727
- for (var j = 0; j < registrations.length; j++) {
728
- if (registrations[j] === this) {
729
- registrations.splice(j, 1);
730
- break;
731
- }
732
- }
733
- }
734
- }
735
- };
736
- scope.enqueueMutation = enqueueMutation;
737
- scope.registerTransientObservers = registerTransientObservers;
738
- scope.wrappers.MutationObserver = MutationObserver;
739
- scope.wrappers.MutationRecord = MutationRecord;
740
- })(window.ShadowDOMPolyfill);
741
-
742
- (function(scope) {
743
- "use strict";
744
- function TreeScope(root, parent) {
745
- this.root = root;
746
- this.parent = parent;
747
- }
748
- TreeScope.prototype = {
749
- get renderer() {
750
- if (this.root instanceof scope.wrappers.ShadowRoot) {
751
- return scope.getRendererForHost(this.root.host);
752
- }
753
- return null;
754
- },
755
- contains: function(treeScope) {
756
- for (;treeScope; treeScope = treeScope.parent) {
757
- if (treeScope === this) return true;
758
- }
759
- return false;
760
- }
761
- };
762
- function setTreeScope(node, treeScope) {
763
- if (node.treeScope_ !== treeScope) {
764
- node.treeScope_ = treeScope;
765
- for (var sr = node.shadowRoot; sr; sr = sr.olderShadowRoot) {
766
- sr.treeScope_.parent = treeScope;
767
- }
768
- for (var child = node.firstChild; child; child = child.nextSibling) {
769
- setTreeScope(child, treeScope);
770
- }
771
- }
772
- }
773
- function getTreeScope(node) {
774
- if (node instanceof scope.wrappers.Window) {
775
- debugger;
776
- }
777
- if (node.treeScope_) return node.treeScope_;
778
- var parent = node.parentNode;
779
- var treeScope;
780
- if (parent) treeScope = getTreeScope(parent); else treeScope = new TreeScope(node, null);
781
- return node.treeScope_ = treeScope;
782
- }
783
- scope.TreeScope = TreeScope;
784
- scope.getTreeScope = getTreeScope;
785
- scope.setTreeScope = setTreeScope;
786
- })(window.ShadowDOMPolyfill);
787
-
788
- (function(scope) {
789
- "use strict";
790
- var forwardMethodsToWrapper = scope.forwardMethodsToWrapper;
791
- var getTreeScope = scope.getTreeScope;
792
- var mixin = scope.mixin;
793
- var registerWrapper = scope.registerWrapper;
794
- var setWrapper = scope.setWrapper;
795
- var unsafeUnwrap = scope.unsafeUnwrap;
796
- var unwrap = scope.unwrap;
797
- var wrap = scope.wrap;
798
- var wrappers = scope.wrappers;
799
- var wrappedFuns = new WeakMap();
800
- var listenersTable = new WeakMap();
801
- var handledEventsTable = new WeakMap();
802
- var currentlyDispatchingEvents = new WeakMap();
803
- var targetTable = new WeakMap();
804
- var currentTargetTable = new WeakMap();
805
- var relatedTargetTable = new WeakMap();
806
- var eventPhaseTable = new WeakMap();
807
- var stopPropagationTable = new WeakMap();
808
- var stopImmediatePropagationTable = new WeakMap();
809
- var eventHandlersTable = new WeakMap();
810
- var eventPathTable = new WeakMap();
811
- function isShadowRoot(node) {
812
- return node instanceof wrappers.ShadowRoot;
813
- }
814
- function rootOfNode(node) {
815
- return getTreeScope(node).root;
816
- }
817
- function getEventPath(node, event) {
818
- var path = [];
819
- var current = node;
820
- path.push(current);
821
- while (current) {
822
- var destinationInsertionPoints = getDestinationInsertionPoints(current);
823
- if (destinationInsertionPoints && destinationInsertionPoints.length > 0) {
824
- for (var i = 0; i < destinationInsertionPoints.length; i++) {
825
- var insertionPoint = destinationInsertionPoints[i];
826
- if (isShadowInsertionPoint(insertionPoint)) {
827
- var shadowRoot = rootOfNode(insertionPoint);
828
- var olderShadowRoot = shadowRoot.olderShadowRoot;
829
- if (olderShadowRoot) path.push(olderShadowRoot);
830
- }
831
- path.push(insertionPoint);
832
- }
833
- current = destinationInsertionPoints[destinationInsertionPoints.length - 1];
834
- } else {
835
- if (isShadowRoot(current)) {
836
- if (inSameTree(node, current) && eventMustBeStopped(event)) {
837
- break;
838
- }
839
- current = current.host;
840
- path.push(current);
841
- } else {
842
- current = current.parentNode;
843
- if (current) path.push(current);
844
- }
845
- }
846
- }
847
- return path;
848
- }
849
- function eventMustBeStopped(event) {
850
- if (!event) return false;
851
- switch (event.type) {
852
- case "abort":
853
- case "error":
854
- case "select":
855
- case "change":
856
- case "load":
857
- case "reset":
858
- case "resize":
859
- case "scroll":
860
- case "selectstart":
861
- return true;
862
- }
863
- return false;
864
- }
865
- function isShadowInsertionPoint(node) {
866
- return node instanceof HTMLShadowElement;
867
- }
868
- function getDestinationInsertionPoints(node) {
869
- return scope.getDestinationInsertionPoints(node);
870
- }
871
- function eventRetargetting(path, currentTarget) {
872
- if (path.length === 0) return currentTarget;
873
- if (currentTarget instanceof wrappers.Window) currentTarget = currentTarget.document;
874
- var currentTargetTree = getTreeScope(currentTarget);
875
- var originalTarget = path[0];
876
- var originalTargetTree = getTreeScope(originalTarget);
877
- var relativeTargetTree = lowestCommonInclusiveAncestor(currentTargetTree, originalTargetTree);
878
- for (var i = 0; i < path.length; i++) {
879
- var node = path[i];
880
- if (getTreeScope(node) === relativeTargetTree) return node;
881
- }
882
- return path[path.length - 1];
883
- }
884
- function getTreeScopeAncestors(treeScope) {
885
- var ancestors = [];
886
- for (;treeScope; treeScope = treeScope.parent) {
887
- ancestors.push(treeScope);
888
- }
889
- return ancestors;
890
- }
891
- function lowestCommonInclusiveAncestor(tsA, tsB) {
892
- var ancestorsA = getTreeScopeAncestors(tsA);
893
- var ancestorsB = getTreeScopeAncestors(tsB);
894
- var result = null;
895
- while (ancestorsA.length > 0 && ancestorsB.length > 0) {
896
- var a = ancestorsA.pop();
897
- var b = ancestorsB.pop();
898
- if (a === b) result = a; else break;
899
- }
900
- return result;
901
- }
902
- function getTreeScopeRoot(ts) {
903
- if (!ts.parent) return ts;
904
- return getTreeScopeRoot(ts.parent);
905
- }
906
- function relatedTargetResolution(event, currentTarget, relatedTarget) {
907
- if (currentTarget instanceof wrappers.Window) currentTarget = currentTarget.document;
908
- var currentTargetTree = getTreeScope(currentTarget);
909
- var relatedTargetTree = getTreeScope(relatedTarget);
910
- var relatedTargetEventPath = getEventPath(relatedTarget, event);
911
- var lowestCommonAncestorTree;
912
- var lowestCommonAncestorTree = lowestCommonInclusiveAncestor(currentTargetTree, relatedTargetTree);
913
- if (!lowestCommonAncestorTree) lowestCommonAncestorTree = relatedTargetTree.root;
914
- for (var commonAncestorTree = lowestCommonAncestorTree; commonAncestorTree; commonAncestorTree = commonAncestorTree.parent) {
915
- var adjustedRelatedTarget;
916
- for (var i = 0; i < relatedTargetEventPath.length; i++) {
917
- var node = relatedTargetEventPath[i];
918
- if (getTreeScope(node) === commonAncestorTree) return node;
919
- }
920
- }
921
- return null;
922
- }
923
- function inSameTree(a, b) {
924
- return getTreeScope(a) === getTreeScope(b);
925
- }
926
- var NONE = 0;
927
- var CAPTURING_PHASE = 1;
928
- var AT_TARGET = 2;
929
- var BUBBLING_PHASE = 3;
930
- var pendingError;
931
- function dispatchOriginalEvent(originalEvent) {
932
- if (handledEventsTable.get(originalEvent)) return;
933
- handledEventsTable.set(originalEvent, true);
934
- dispatchEvent(wrap(originalEvent), wrap(originalEvent.target));
935
- if (pendingError) {
936
- var err = pendingError;
937
- pendingError = null;
938
- throw err;
939
- }
940
- }
941
- function isLoadLikeEvent(event) {
942
- switch (event.type) {
943
- case "load":
944
- case "beforeunload":
945
- case "unload":
946
- return true;
947
- }
948
- return false;
949
- }
950
- function dispatchEvent(event, originalWrapperTarget) {
951
- if (currentlyDispatchingEvents.get(event)) throw new Error("InvalidStateError");
952
- currentlyDispatchingEvents.set(event, true);
953
- scope.renderAllPending();
954
- var eventPath;
955
- var overrideTarget;
956
- var win;
957
- if (isLoadLikeEvent(event) && !event.bubbles) {
958
- var doc = originalWrapperTarget;
959
- if (doc instanceof wrappers.Document && (win = doc.defaultView)) {
960
- overrideTarget = doc;
961
- eventPath = [];
962
- }
963
- }
964
- if (!eventPath) {
965
- if (originalWrapperTarget instanceof wrappers.Window) {
966
- win = originalWrapperTarget;
967
- eventPath = [];
968
- } else {
969
- eventPath = getEventPath(originalWrapperTarget, event);
970
- if (!isLoadLikeEvent(event)) {
971
- var doc = eventPath[eventPath.length - 1];
972
- if (doc instanceof wrappers.Document) win = doc.defaultView;
973
- }
974
- }
975
- }
976
- eventPathTable.set(event, eventPath);
977
- if (dispatchCapturing(event, eventPath, win, overrideTarget)) {
978
- if (dispatchAtTarget(event, eventPath, win, overrideTarget)) {
979
- dispatchBubbling(event, eventPath, win, overrideTarget);
980
- }
981
- }
982
- eventPhaseTable.set(event, NONE);
983
- currentTargetTable.delete(event, null);
984
- currentlyDispatchingEvents.delete(event);
985
- return event.defaultPrevented;
986
- }
987
- function dispatchCapturing(event, eventPath, win, overrideTarget) {
988
- var phase = CAPTURING_PHASE;
989
- if (win) {
990
- if (!invoke(win, event, phase, eventPath, overrideTarget)) return false;
991
- }
992
- for (var i = eventPath.length - 1; i > 0; i--) {
993
- if (!invoke(eventPath[i], event, phase, eventPath, overrideTarget)) return false;
994
- }
995
- return true;
996
- }
997
- function dispatchAtTarget(event, eventPath, win, overrideTarget) {
998
- var phase = AT_TARGET;
999
- var currentTarget = eventPath[0] || win;
1000
- return invoke(currentTarget, event, phase, eventPath, overrideTarget);
1001
- }
1002
- function dispatchBubbling(event, eventPath, win, overrideTarget) {
1003
- var phase = BUBBLING_PHASE;
1004
- for (var i = 1; i < eventPath.length; i++) {
1005
- if (!invoke(eventPath[i], event, phase, eventPath, overrideTarget)) return;
1006
- }
1007
- if (win && eventPath.length > 0) {
1008
- invoke(win, event, phase, eventPath, overrideTarget);
1009
- }
1010
- }
1011
- function invoke(currentTarget, event, phase, eventPath, overrideTarget) {
1012
- var listeners = listenersTable.get(currentTarget);
1013
- if (!listeners) return true;
1014
- var target = overrideTarget || eventRetargetting(eventPath, currentTarget);
1015
- if (target === currentTarget) {
1016
- if (phase === CAPTURING_PHASE) return true;
1017
- if (phase === BUBBLING_PHASE) phase = AT_TARGET;
1018
- } else if (phase === BUBBLING_PHASE && !event.bubbles) {
1019
- return true;
1020
- }
1021
- if ("relatedTarget" in event) {
1022
- var originalEvent = unwrap(event);
1023
- var unwrappedRelatedTarget = originalEvent.relatedTarget;
1024
- if (unwrappedRelatedTarget) {
1025
- if (unwrappedRelatedTarget instanceof Object && unwrappedRelatedTarget.addEventListener) {
1026
- var relatedTarget = wrap(unwrappedRelatedTarget);
1027
- var adjusted = relatedTargetResolution(event, currentTarget, relatedTarget);
1028
- if (adjusted === target) return true;
1029
- } else {
1030
- adjusted = null;
1031
- }
1032
- relatedTargetTable.set(event, adjusted);
1033
- }
1034
- }
1035
- eventPhaseTable.set(event, phase);
1036
- var type = event.type;
1037
- var anyRemoved = false;
1038
- targetTable.set(event, target);
1039
- currentTargetTable.set(event, currentTarget);
1040
- listeners.depth++;
1041
- for (var i = 0, len = listeners.length; i < len; i++) {
1042
- var listener = listeners[i];
1043
- if (listener.removed) {
1044
- anyRemoved = true;
1045
- continue;
1046
- }
1047
- if (listener.type !== type || !listener.capture && phase === CAPTURING_PHASE || listener.capture && phase === BUBBLING_PHASE) {
1048
- continue;
1049
- }
1050
- try {
1051
- if (typeof listener.handler === "function") listener.handler.call(currentTarget, event); else listener.handler.handleEvent(event);
1052
- if (stopImmediatePropagationTable.get(event)) return false;
1053
- } catch (ex) {
1054
- if (!pendingError) pendingError = ex;
1055
- }
1056
- }
1057
- listeners.depth--;
1058
- if (anyRemoved && listeners.depth === 0) {
1059
- var copy = listeners.slice();
1060
- listeners.length = 0;
1061
- for (var i = 0; i < copy.length; i++) {
1062
- if (!copy[i].removed) listeners.push(copy[i]);
1063
- }
1064
- }
1065
- return !stopPropagationTable.get(event);
1066
- }
1067
- function Listener(type, handler, capture) {
1068
- this.type = type;
1069
- this.handler = handler;
1070
- this.capture = Boolean(capture);
1071
- }
1072
- Listener.prototype = {
1073
- equals: function(that) {
1074
- return this.handler === that.handler && this.type === that.type && this.capture === that.capture;
1075
- },
1076
- get removed() {
1077
- return this.handler === null;
1078
- },
1079
- remove: function() {
1080
- this.handler = null;
1081
- }
1082
- };
1083
- var OriginalEvent = window.Event;
1084
- OriginalEvent.prototype.polymerBlackList_ = {
1085
- returnValue: true,
1086
- keyLocation: true
1087
- };
1088
- function Event(type, options) {
1089
- if (type instanceof OriginalEvent) {
1090
- var impl = type;
1091
- if (!OriginalBeforeUnloadEvent && impl.type === "beforeunload" && !(this instanceof BeforeUnloadEvent)) {
1092
- return new BeforeUnloadEvent(impl);
1093
- }
1094
- setWrapper(impl, this);
1095
- } else {
1096
- return wrap(constructEvent(OriginalEvent, "Event", type, options));
1097
- }
1098
- }
1099
- Event.prototype = {
1100
- get target() {
1101
- return targetTable.get(this);
1102
- },
1103
- get currentTarget() {
1104
- return currentTargetTable.get(this);
1105
- },
1106
- get eventPhase() {
1107
- return eventPhaseTable.get(this);
1108
- },
1109
- get path() {
1110
- var eventPath = eventPathTable.get(this);
1111
- if (!eventPath) return [];
1112
- return eventPath.slice();
1113
- },
1114
- stopPropagation: function() {
1115
- stopPropagationTable.set(this, true);
1116
- },
1117
- stopImmediatePropagation: function() {
1118
- stopPropagationTable.set(this, true);
1119
- stopImmediatePropagationTable.set(this, true);
1120
- }
1121
- };
1122
- var supportsDefaultPrevented = function() {
1123
- var e = document.createEvent("Event");
1124
- e.initEvent("test", true, true);
1125
- e.preventDefault();
1126
- return e.defaultPrevented;
1127
- }();
1128
- if (!supportsDefaultPrevented) {
1129
- Event.prototype.preventDefault = function() {
1130
- if (!this.cancelable) return;
1131
- unsafeUnwrap(this).preventDefault();
1132
- Object.defineProperty(this, "defaultPrevented", {
1133
- get: function() {
1134
- return true;
1135
- },
1136
- configurable: true
1137
- });
1138
- };
1139
- }
1140
- registerWrapper(OriginalEvent, Event, document.createEvent("Event"));
1141
- function unwrapOptions(options) {
1142
- if (!options || !options.relatedTarget) return options;
1143
- return Object.create(options, {
1144
- relatedTarget: {
1145
- value: unwrap(options.relatedTarget)
1146
- }
1147
- });
1148
- }
1149
- function registerGenericEvent(name, SuperEvent, prototype) {
1150
- var OriginalEvent = window[name];
1151
- var GenericEvent = function(type, options) {
1152
- if (type instanceof OriginalEvent) setWrapper(type, this); else return wrap(constructEvent(OriginalEvent, name, type, options));
1153
- };
1154
- GenericEvent.prototype = Object.create(SuperEvent.prototype);
1155
- if (prototype) mixin(GenericEvent.prototype, prototype);
1156
- if (OriginalEvent) {
1157
- try {
1158
- registerWrapper(OriginalEvent, GenericEvent, new OriginalEvent("temp"));
1159
- } catch (ex) {
1160
- registerWrapper(OriginalEvent, GenericEvent, document.createEvent(name));
1161
- }
1162
- }
1163
- return GenericEvent;
1164
- }
1165
- var UIEvent = registerGenericEvent("UIEvent", Event);
1166
- var CustomEvent = registerGenericEvent("CustomEvent", Event);
1167
- var relatedTargetProto = {
1168
- get relatedTarget() {
1169
- var relatedTarget = relatedTargetTable.get(this);
1170
- if (relatedTarget !== undefined) return relatedTarget;
1171
- return wrap(unwrap(this).relatedTarget);
1172
- }
1173
- };
1174
- function getInitFunction(name, relatedTargetIndex) {
1175
- return function() {
1176
- arguments[relatedTargetIndex] = unwrap(arguments[relatedTargetIndex]);
1177
- var impl = unwrap(this);
1178
- impl[name].apply(impl, arguments);
1179
- };
1180
- }
1181
- var mouseEventProto = mixin({
1182
- initMouseEvent: getInitFunction("initMouseEvent", 14)
1183
- }, relatedTargetProto);
1184
- var focusEventProto = mixin({
1185
- initFocusEvent: getInitFunction("initFocusEvent", 5)
1186
- }, relatedTargetProto);
1187
- var MouseEvent = registerGenericEvent("MouseEvent", UIEvent, mouseEventProto);
1188
- var FocusEvent = registerGenericEvent("FocusEvent", UIEvent, focusEventProto);
1189
- var defaultInitDicts = Object.create(null);
1190
- var supportsEventConstructors = function() {
1191
- try {
1192
- new window.FocusEvent("focus");
1193
- } catch (ex) {
1194
- return false;
1195
- }
1196
- return true;
1197
- }();
1198
- function constructEvent(OriginalEvent, name, type, options) {
1199
- if (supportsEventConstructors) return new OriginalEvent(type, unwrapOptions(options));
1200
- var event = unwrap(document.createEvent(name));
1201
- var defaultDict = defaultInitDicts[name];
1202
- var args = [ type ];
1203
- Object.keys(defaultDict).forEach(function(key) {
1204
- var v = options != null && key in options ? options[key] : defaultDict[key];
1205
- if (key === "relatedTarget") v = unwrap(v);
1206
- args.push(v);
1207
- });
1208
- event["init" + name].apply(event, args);
1209
- return event;
1210
- }
1211
- if (!supportsEventConstructors) {
1212
- var configureEventConstructor = function(name, initDict, superName) {
1213
- if (superName) {
1214
- var superDict = defaultInitDicts[superName];
1215
- initDict = mixin(mixin({}, superDict), initDict);
1216
- }
1217
- defaultInitDicts[name] = initDict;
1218
- };
1219
- configureEventConstructor("Event", {
1220
- bubbles: false,
1221
- cancelable: false
1222
- });
1223
- configureEventConstructor("CustomEvent", {
1224
- detail: null
1225
- }, "Event");
1226
- configureEventConstructor("UIEvent", {
1227
- view: null,
1228
- detail: 0
1229
- }, "Event");
1230
- configureEventConstructor("MouseEvent", {
1231
- screenX: 0,
1232
- screenY: 0,
1233
- clientX: 0,
1234
- clientY: 0,
1235
- ctrlKey: false,
1236
- altKey: false,
1237
- shiftKey: false,
1238
- metaKey: false,
1239
- button: 0,
1240
- relatedTarget: null
1241
- }, "UIEvent");
1242
- configureEventConstructor("FocusEvent", {
1243
- relatedTarget: null
1244
- }, "UIEvent");
1245
- }
1246
- var OriginalBeforeUnloadEvent = window.BeforeUnloadEvent;
1247
- function BeforeUnloadEvent(impl) {
1248
- Event.call(this, impl);
1249
- }
1250
- BeforeUnloadEvent.prototype = Object.create(Event.prototype);
1251
- mixin(BeforeUnloadEvent.prototype, {
1252
- get returnValue() {
1253
- return unsafeUnwrap(this).returnValue;
1254
- },
1255
- set returnValue(v) {
1256
- unsafeUnwrap(this).returnValue = v;
1257
- }
1258
- });
1259
- if (OriginalBeforeUnloadEvent) registerWrapper(OriginalBeforeUnloadEvent, BeforeUnloadEvent);
1260
- function isValidListener(fun) {
1261
- if (typeof fun === "function") return true;
1262
- return fun && fun.handleEvent;
1263
- }
1264
- function isMutationEvent(type) {
1265
- switch (type) {
1266
- case "DOMAttrModified":
1267
- case "DOMAttributeNameChanged":
1268
- case "DOMCharacterDataModified":
1269
- case "DOMElementNameChanged":
1270
- case "DOMNodeInserted":
1271
- case "DOMNodeInsertedIntoDocument":
1272
- case "DOMNodeRemoved":
1273
- case "DOMNodeRemovedFromDocument":
1274
- case "DOMSubtreeModified":
1275
- return true;
1276
- }
1277
- return false;
1278
- }
1279
- var OriginalEventTarget = window.EventTarget;
1280
- function EventTarget(impl) {
1281
- setWrapper(impl, this);
1282
- }
1283
- var methodNames = [ "addEventListener", "removeEventListener", "dispatchEvent" ];
1284
- [ Node, Window ].forEach(function(constructor) {
1285
- var p = constructor.prototype;
1286
- methodNames.forEach(function(name) {
1287
- Object.defineProperty(p, name + "_", {
1288
- value: p[name]
1289
- });
1290
- });
1291
- });
1292
- function getTargetToListenAt(wrapper) {
1293
- if (wrapper instanceof wrappers.ShadowRoot) wrapper = wrapper.host;
1294
- return unwrap(wrapper);
1295
- }
1296
- EventTarget.prototype = {
1297
- addEventListener: function(type, fun, capture) {
1298
- if (!isValidListener(fun) || isMutationEvent(type)) return;
1299
- var listener = new Listener(type, fun, capture);
1300
- var listeners = listenersTable.get(this);
1301
- if (!listeners) {
1302
- listeners = [];
1303
- listeners.depth = 0;
1304
- listenersTable.set(this, listeners);
1305
- } else {
1306
- for (var i = 0; i < listeners.length; i++) {
1307
- if (listener.equals(listeners[i])) return;
1308
- }
1309
- }
1310
- listeners.push(listener);
1311
- var target = getTargetToListenAt(this);
1312
- target.addEventListener_(type, dispatchOriginalEvent, true);
1313
- },
1314
- removeEventListener: function(type, fun, capture) {
1315
- capture = Boolean(capture);
1316
- var listeners = listenersTable.get(this);
1317
- if (!listeners) return;
1318
- var count = 0, found = false;
1319
- for (var i = 0; i < listeners.length; i++) {
1320
- if (listeners[i].type === type && listeners[i].capture === capture) {
1321
- count++;
1322
- if (listeners[i].handler === fun) {
1323
- found = true;
1324
- listeners[i].remove();
1325
- }
1326
- }
1327
- }
1328
- if (found && count === 1) {
1329
- var target = getTargetToListenAt(this);
1330
- target.removeEventListener_(type, dispatchOriginalEvent, true);
1331
- }
1332
- },
1333
- dispatchEvent: function(event) {
1334
- var nativeEvent = unwrap(event);
1335
- var eventType = nativeEvent.type;
1336
- handledEventsTable.set(nativeEvent, false);
1337
- scope.renderAllPending();
1338
- var tempListener;
1339
- if (!hasListenerInAncestors(this, eventType)) {
1340
- tempListener = function() {};
1341
- this.addEventListener(eventType, tempListener, true);
1342
- }
1343
- try {
1344
- return unwrap(this).dispatchEvent_(nativeEvent);
1345
- } finally {
1346
- if (tempListener) this.removeEventListener(eventType, tempListener, true);
1347
- }
1348
- }
1349
- };
1350
- function hasListener(node, type) {
1351
- var listeners = listenersTable.get(node);
1352
- if (listeners) {
1353
- for (var i = 0; i < listeners.length; i++) {
1354
- if (!listeners[i].removed && listeners[i].type === type) return true;
1355
- }
1356
- }
1357
- return false;
1358
- }
1359
- function hasListenerInAncestors(target, type) {
1360
- for (var node = unwrap(target); node; node = node.parentNode) {
1361
- if (hasListener(wrap(node), type)) return true;
1362
- }
1363
- return false;
1364
- }
1365
- if (OriginalEventTarget) registerWrapper(OriginalEventTarget, EventTarget);
1366
- function wrapEventTargetMethods(constructors) {
1367
- forwardMethodsToWrapper(constructors, methodNames);
1368
- }
1369
- var originalElementFromPoint = document.elementFromPoint;
1370
- function elementFromPoint(self, document, x, y) {
1371
- scope.renderAllPending();
1372
- var element = wrap(originalElementFromPoint.call(unsafeUnwrap(document), x, y));
1373
- if (!element) return null;
1374
- var path = getEventPath(element, null);
1375
- var idx = path.lastIndexOf(self);
1376
- if (idx == -1) return null; else path = path.slice(0, idx);
1377
- return eventRetargetting(path, self);
1378
- }
1379
- function getEventHandlerGetter(name) {
1380
- return function() {
1381
- var inlineEventHandlers = eventHandlersTable.get(this);
1382
- return inlineEventHandlers && inlineEventHandlers[name] && inlineEventHandlers[name].value || null;
1383
- };
1384
- }
1385
- function getEventHandlerSetter(name) {
1386
- var eventType = name.slice(2);
1387
- return function(value) {
1388
- var inlineEventHandlers = eventHandlersTable.get(this);
1389
- if (!inlineEventHandlers) {
1390
- inlineEventHandlers = Object.create(null);
1391
- eventHandlersTable.set(this, inlineEventHandlers);
1392
- }
1393
- var old = inlineEventHandlers[name];
1394
- if (old) this.removeEventListener(eventType, old.wrapped, false);
1395
- if (typeof value === "function") {
1396
- var wrapped = function(e) {
1397
- var rv = value.call(this, e);
1398
- if (rv === false) e.preventDefault(); else if (name === "onbeforeunload" && typeof rv === "string") e.returnValue = rv;
1399
- };
1400
- this.addEventListener(eventType, wrapped, false);
1401
- inlineEventHandlers[name] = {
1402
- value: value,
1403
- wrapped: wrapped
1404
- };
1405
- }
1406
- };
1407
- }
1408
- scope.elementFromPoint = elementFromPoint;
1409
- scope.getEventHandlerGetter = getEventHandlerGetter;
1410
- scope.getEventHandlerSetter = getEventHandlerSetter;
1411
- scope.wrapEventTargetMethods = wrapEventTargetMethods;
1412
- scope.wrappers.BeforeUnloadEvent = BeforeUnloadEvent;
1413
- scope.wrappers.CustomEvent = CustomEvent;
1414
- scope.wrappers.Event = Event;
1415
- scope.wrappers.EventTarget = EventTarget;
1416
- scope.wrappers.FocusEvent = FocusEvent;
1417
- scope.wrappers.MouseEvent = MouseEvent;
1418
- scope.wrappers.UIEvent = UIEvent;
1419
- })(window.ShadowDOMPolyfill);
1420
-
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" ].forEach(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
-
1503
- (function(scope) {
1504
- "use strict";
1505
- var unsafeUnwrap = scope.unsafeUnwrap;
1506
- var wrap = scope.wrap;
1507
- var nonEnumDescriptor = {
1508
- enumerable: false
1509
- };
1510
- function nonEnum(obj, prop) {
1511
- Object.defineProperty(obj, prop, nonEnumDescriptor);
1512
- }
1513
- function NodeList() {
1514
- this.length = 0;
1515
- nonEnum(this, "length");
1516
- }
1517
- NodeList.prototype = {
1518
- item: function(index) {
1519
- return this[index];
1520
- }
1521
- };
1522
- nonEnum(NodeList.prototype, "item");
1523
- function wrapNodeList(list) {
1524
- if (list == null) return list;
1525
- var wrapperList = new NodeList();
1526
- for (var i = 0, length = list.length; i < length; i++) {
1527
- wrapperList[i] = wrap(list[i]);
1528
- }
1529
- wrapperList.length = length;
1530
- return wrapperList;
1531
- }
1532
- function addWrapNodeListMethod(wrapperConstructor, name) {
1533
- wrapperConstructor.prototype[name] = function() {
1534
- return wrapNodeList(unsafeUnwrap(this)[name].apply(unsafeUnwrap(this), arguments));
1535
- };
1536
- }
1537
- scope.wrappers.NodeList = NodeList;
1538
- scope.addWrapNodeListMethod = addWrapNodeListMethod;
1539
- scope.wrapNodeList = wrapNodeList;
1540
- })(window.ShadowDOMPolyfill);
1541
-
1542
- (function(scope) {
1543
- "use strict";
1544
- scope.wrapHTMLCollection = scope.wrapNodeList;
1545
- scope.wrappers.HTMLCollection = scope.wrappers.NodeList;
1546
- })(window.ShadowDOMPolyfill);
1547
-
1548
- (function(scope) {
1549
- "use strict";
1550
- var EventTarget = scope.wrappers.EventTarget;
1551
- var NodeList = scope.wrappers.NodeList;
1552
- var TreeScope = scope.TreeScope;
1553
- var assert = scope.assert;
1554
- var defineWrapGetter = scope.defineWrapGetter;
1555
- var enqueueMutation = scope.enqueueMutation;
1556
- var getTreeScope = scope.getTreeScope;
1557
- var isWrapper = scope.isWrapper;
1558
- var mixin = scope.mixin;
1559
- var registerTransientObservers = scope.registerTransientObservers;
1560
- var registerWrapper = scope.registerWrapper;
1561
- var setTreeScope = scope.setTreeScope;
1562
- var unsafeUnwrap = scope.unsafeUnwrap;
1563
- var unwrap = scope.unwrap;
1564
- var unwrapIfNeeded = scope.unwrapIfNeeded;
1565
- var wrap = scope.wrap;
1566
- var wrapIfNeeded = scope.wrapIfNeeded;
1567
- var wrappers = scope.wrappers;
1568
- function assertIsNodeWrapper(node) {
1569
- assert(node instanceof Node);
1570
- }
1571
- function createOneElementNodeList(node) {
1572
- var nodes = new NodeList();
1573
- nodes[0] = node;
1574
- nodes.length = 1;
1575
- return nodes;
1576
- }
1577
- var surpressMutations = false;
1578
- function enqueueRemovalForInsertedNodes(node, parent, nodes) {
1579
- enqueueMutation(parent, "childList", {
1580
- removedNodes: nodes,
1581
- previousSibling: node.previousSibling,
1582
- nextSibling: node.nextSibling
1583
- });
1584
- }
1585
- function enqueueRemovalForInsertedDocumentFragment(df, nodes) {
1586
- enqueueMutation(df, "childList", {
1587
- removedNodes: nodes
1588
- });
1589
- }
1590
- function collectNodes(node, parentNode, previousNode, nextNode) {
1591
- if (node instanceof DocumentFragment) {
1592
- var nodes = collectNodesForDocumentFragment(node);
1593
- surpressMutations = true;
1594
- for (var i = nodes.length - 1; i >= 0; i--) {
1595
- node.removeChild(nodes[i]);
1596
- nodes[i].parentNode_ = parentNode;
1597
- }
1598
- surpressMutations = false;
1599
- for (var i = 0; i < nodes.length; i++) {
1600
- nodes[i].previousSibling_ = nodes[i - 1] || previousNode;
1601
- nodes[i].nextSibling_ = nodes[i + 1] || nextNode;
1602
- }
1603
- if (previousNode) previousNode.nextSibling_ = nodes[0];
1604
- if (nextNode) nextNode.previousSibling_ = nodes[nodes.length - 1];
1605
- return nodes;
1606
- }
1607
- var nodes = createOneElementNodeList(node);
1608
- var oldParent = node.parentNode;
1609
- if (oldParent) {
1610
- oldParent.removeChild(node);
1611
- }
1612
- node.parentNode_ = parentNode;
1613
- node.previousSibling_ = previousNode;
1614
- node.nextSibling_ = nextNode;
1615
- if (previousNode) previousNode.nextSibling_ = node;
1616
- if (nextNode) nextNode.previousSibling_ = node;
1617
- return nodes;
1618
- }
1619
- function collectNodesNative(node) {
1620
- if (node instanceof DocumentFragment) return collectNodesForDocumentFragment(node);
1621
- var nodes = createOneElementNodeList(node);
1622
- var oldParent = node.parentNode;
1623
- if (oldParent) enqueueRemovalForInsertedNodes(node, oldParent, nodes);
1624
- return nodes;
1625
- }
1626
- function collectNodesForDocumentFragment(node) {
1627
- var nodes = new NodeList();
1628
- var i = 0;
1629
- for (var child = node.firstChild; child; child = child.nextSibling) {
1630
- nodes[i++] = child;
1631
- }
1632
- nodes.length = i;
1633
- enqueueRemovalForInsertedDocumentFragment(node, nodes);
1634
- return nodes;
1635
- }
1636
- function snapshotNodeList(nodeList) {
1637
- return nodeList;
1638
- }
1639
- function nodeWasAdded(node, treeScope) {
1640
- setTreeScope(node, treeScope);
1641
- node.nodeIsInserted_();
1642
- }
1643
- function nodesWereAdded(nodes, parent) {
1644
- var treeScope = getTreeScope(parent);
1645
- for (var i = 0; i < nodes.length; i++) {
1646
- nodeWasAdded(nodes[i], treeScope);
1647
- }
1648
- }
1649
- function nodeWasRemoved(node) {
1650
- setTreeScope(node, new TreeScope(node, null));
1651
- }
1652
- function nodesWereRemoved(nodes) {
1653
- for (var i = 0; i < nodes.length; i++) {
1654
- nodeWasRemoved(nodes[i]);
1655
- }
1656
- }
1657
- function ensureSameOwnerDocument(parent, child) {
1658
- var ownerDoc = parent.nodeType === Node.DOCUMENT_NODE ? parent : parent.ownerDocument;
1659
- if (ownerDoc !== child.ownerDocument) ownerDoc.adoptNode(child);
1660
- }
1661
- function adoptNodesIfNeeded(owner, nodes) {
1662
- if (!nodes.length) return;
1663
- var ownerDoc = owner.ownerDocument;
1664
- if (ownerDoc === nodes[0].ownerDocument) return;
1665
- for (var i = 0; i < nodes.length; i++) {
1666
- scope.adoptNodeNoRemove(nodes[i], ownerDoc);
1667
- }
1668
- }
1669
- function unwrapNodesForInsertion(owner, nodes) {
1670
- adoptNodesIfNeeded(owner, nodes);
1671
- var length = nodes.length;
1672
- if (length === 1) return unwrap(nodes[0]);
1673
- var df = unwrap(owner.ownerDocument.createDocumentFragment());
1674
- for (var i = 0; i < length; i++) {
1675
- df.appendChild(unwrap(nodes[i]));
1676
- }
1677
- return df;
1678
- }
1679
- function clearChildNodes(wrapper) {
1680
- if (wrapper.firstChild_ !== undefined) {
1681
- var child = wrapper.firstChild_;
1682
- while (child) {
1683
- var tmp = child;
1684
- child = child.nextSibling_;
1685
- tmp.parentNode_ = tmp.previousSibling_ = tmp.nextSibling_ = undefined;
1686
- }
1687
- }
1688
- wrapper.firstChild_ = wrapper.lastChild_ = undefined;
1689
- }
1690
- function removeAllChildNodes(wrapper) {
1691
- if (wrapper.invalidateShadowRenderer()) {
1692
- var childWrapper = wrapper.firstChild;
1693
- while (childWrapper) {
1694
- assert(childWrapper.parentNode === wrapper);
1695
- var nextSibling = childWrapper.nextSibling;
1696
- var childNode = unwrap(childWrapper);
1697
- var parentNode = childNode.parentNode;
1698
- if (parentNode) originalRemoveChild.call(parentNode, childNode);
1699
- childWrapper.previousSibling_ = childWrapper.nextSibling_ = childWrapper.parentNode_ = null;
1700
- childWrapper = nextSibling;
1701
- }
1702
- wrapper.firstChild_ = wrapper.lastChild_ = null;
1703
- } else {
1704
- var node = unwrap(wrapper);
1705
- var child = node.firstChild;
1706
- var nextSibling;
1707
- while (child) {
1708
- nextSibling = child.nextSibling;
1709
- originalRemoveChild.call(node, child);
1710
- child = nextSibling;
1711
- }
1712
- }
1713
- }
1714
- function invalidateParent(node) {
1715
- var p = node.parentNode;
1716
- return p && p.invalidateShadowRenderer();
1717
- }
1718
- function cleanupNodes(nodes) {
1719
- for (var i = 0, n; i < nodes.length; i++) {
1720
- n = nodes[i];
1721
- n.parentNode.removeChild(n);
1722
- }
1723
- }
1724
- var originalImportNode = document.importNode;
1725
- var originalCloneNode = window.Node.prototype.cloneNode;
1726
- function cloneNode(node, deep, opt_doc) {
1727
- var clone;
1728
- if (opt_doc) clone = wrap(originalImportNode.call(opt_doc, unsafeUnwrap(node), false)); else clone = wrap(originalCloneNode.call(unsafeUnwrap(node), false));
1729
- if (deep) {
1730
- for (var child = node.firstChild; child; child = child.nextSibling) {
1731
- clone.appendChild(cloneNode(child, true, opt_doc));
1732
- }
1733
- if (node instanceof wrappers.HTMLTemplateElement) {
1734
- var cloneContent = clone.content;
1735
- for (var child = node.content.firstChild; child; child = child.nextSibling) {
1736
- cloneContent.appendChild(cloneNode(child, true, opt_doc));
1737
- }
1738
- }
1739
- }
1740
- return clone;
1741
- }
1742
- function contains(self, child) {
1743
- if (!child || getTreeScope(self) !== getTreeScope(child)) return false;
1744
- for (var node = child; node; node = node.parentNode) {
1745
- if (node === self) return true;
1746
- }
1747
- return false;
1748
- }
1749
- var OriginalNode = window.Node;
1750
- function Node(original) {
1751
- assert(original instanceof OriginalNode);
1752
- EventTarget.call(this, original);
1753
- this.parentNode_ = undefined;
1754
- this.firstChild_ = undefined;
1755
- this.lastChild_ = undefined;
1756
- this.nextSibling_ = undefined;
1757
- this.previousSibling_ = undefined;
1758
- this.treeScope_ = undefined;
1759
- }
1760
- var OriginalDocumentFragment = window.DocumentFragment;
1761
- var originalAppendChild = OriginalNode.prototype.appendChild;
1762
- var originalCompareDocumentPosition = OriginalNode.prototype.compareDocumentPosition;
1763
- var originalIsEqualNode = OriginalNode.prototype.isEqualNode;
1764
- var originalInsertBefore = OriginalNode.prototype.insertBefore;
1765
- var originalRemoveChild = OriginalNode.prototype.removeChild;
1766
- var originalReplaceChild = OriginalNode.prototype.replaceChild;
1767
- var isIEOrEdge = /Trident|Edge/.test(navigator.userAgent);
1768
- var removeChildOriginalHelper = isIEOrEdge ? function(parent, child) {
1769
- try {
1770
- originalRemoveChild.call(parent, child);
1771
- } catch (ex) {
1772
- if (!(parent instanceof OriginalDocumentFragment)) throw ex;
1773
- }
1774
- } : function(parent, child) {
1775
- originalRemoveChild.call(parent, child);
1776
- };
1777
- Node.prototype = Object.create(EventTarget.prototype);
1778
- mixin(Node.prototype, {
1779
- appendChild: function(childWrapper) {
1780
- return this.insertBefore(childWrapper, null);
1781
- },
1782
- insertBefore: function(childWrapper, refWrapper) {
1783
- assertIsNodeWrapper(childWrapper);
1784
- var refNode;
1785
- if (refWrapper) {
1786
- if (isWrapper(refWrapper)) {
1787
- refNode = unwrap(refWrapper);
1788
- } else {
1789
- refNode = refWrapper;
1790
- refWrapper = wrap(refNode);
1791
- }
1792
- } else {
1793
- refWrapper = null;
1794
- refNode = null;
1795
- }
1796
- refWrapper && assert(refWrapper.parentNode === this);
1797
- var nodes;
1798
- var previousNode = refWrapper ? refWrapper.previousSibling : this.lastChild;
1799
- var useNative = !this.invalidateShadowRenderer() && !invalidateParent(childWrapper);
1800
- if (useNative) nodes = collectNodesNative(childWrapper); else nodes = collectNodes(childWrapper, this, previousNode, refWrapper);
1801
- if (useNative) {
1802
- ensureSameOwnerDocument(this, childWrapper);
1803
- clearChildNodes(this);
1804
- originalInsertBefore.call(unsafeUnwrap(this), unwrap(childWrapper), refNode);
1805
- } else {
1806
- if (!previousNode) this.firstChild_ = nodes[0];
1807
- if (!refWrapper) {
1808
- this.lastChild_ = nodes[nodes.length - 1];
1809
- if (this.firstChild_ === undefined) this.firstChild_ = this.firstChild;
1810
- }
1811
- var parentNode = refNode ? refNode.parentNode : unsafeUnwrap(this);
1812
- if (parentNode) {
1813
- originalInsertBefore.call(parentNode, unwrapNodesForInsertion(this, nodes), refNode);
1814
- } else {
1815
- adoptNodesIfNeeded(this, nodes);
1816
- }
1817
- }
1818
- enqueueMutation(this, "childList", {
1819
- addedNodes: nodes,
1820
- nextSibling: refWrapper,
1821
- previousSibling: previousNode
1822
- });
1823
- nodesWereAdded(nodes, this);
1824
- return childWrapper;
1825
- },
1826
- removeChild: function(childWrapper) {
1827
- assertIsNodeWrapper(childWrapper);
1828
- if (childWrapper.parentNode !== this) {
1829
- var found = false;
1830
- var childNodes = this.childNodes;
1831
- for (var ieChild = this.firstChild; ieChild; ieChild = ieChild.nextSibling) {
1832
- if (ieChild === childWrapper) {
1833
- found = true;
1834
- break;
1835
- }
1836
- }
1837
- if (!found) {
1838
- throw new Error("NotFoundError");
1839
- }
1840
- }
1841
- var childNode = unwrap(childWrapper);
1842
- var childWrapperNextSibling = childWrapper.nextSibling;
1843
- var childWrapperPreviousSibling = childWrapper.previousSibling;
1844
- if (this.invalidateShadowRenderer()) {
1845
- var thisFirstChild = this.firstChild;
1846
- var thisLastChild = this.lastChild;
1847
- var parentNode = childNode.parentNode;
1848
- if (parentNode) removeChildOriginalHelper(parentNode, childNode);
1849
- if (thisFirstChild === childWrapper) this.firstChild_ = childWrapperNextSibling;
1850
- if (thisLastChild === childWrapper) this.lastChild_ = childWrapperPreviousSibling;
1851
- if (childWrapperPreviousSibling) childWrapperPreviousSibling.nextSibling_ = childWrapperNextSibling;
1852
- if (childWrapperNextSibling) {
1853
- childWrapperNextSibling.previousSibling_ = childWrapperPreviousSibling;
1854
- }
1855
- childWrapper.previousSibling_ = childWrapper.nextSibling_ = childWrapper.parentNode_ = undefined;
1856
- } else {
1857
- clearChildNodes(this);
1858
- removeChildOriginalHelper(unsafeUnwrap(this), childNode);
1859
- }
1860
- if (!surpressMutations) {
1861
- enqueueMutation(this, "childList", {
1862
- removedNodes: createOneElementNodeList(childWrapper),
1863
- nextSibling: childWrapperNextSibling,
1864
- previousSibling: childWrapperPreviousSibling
1865
- });
1866
- }
1867
- registerTransientObservers(this, childWrapper);
1868
- return childWrapper;
1869
- },
1870
- replaceChild: function(newChildWrapper, oldChildWrapper) {
1871
- assertIsNodeWrapper(newChildWrapper);
1872
- var oldChildNode;
1873
- if (isWrapper(oldChildWrapper)) {
1874
- oldChildNode = unwrap(oldChildWrapper);
1875
- } else {
1876
- oldChildNode = oldChildWrapper;
1877
- oldChildWrapper = wrap(oldChildNode);
1878
- }
1879
- if (oldChildWrapper.parentNode !== this) {
1880
- throw new Error("NotFoundError");
1881
- }
1882
- var nextNode = oldChildWrapper.nextSibling;
1883
- var previousNode = oldChildWrapper.previousSibling;
1884
- var nodes;
1885
- var useNative = !this.invalidateShadowRenderer() && !invalidateParent(newChildWrapper);
1886
- if (useNative) {
1887
- nodes = collectNodesNative(newChildWrapper);
1888
- } else {
1889
- if (nextNode === newChildWrapper) nextNode = newChildWrapper.nextSibling;
1890
- nodes = collectNodes(newChildWrapper, this, previousNode, nextNode);
1891
- }
1892
- if (!useNative) {
1893
- if (this.firstChild === oldChildWrapper) this.firstChild_ = nodes[0];
1894
- if (this.lastChild === oldChildWrapper) this.lastChild_ = nodes[nodes.length - 1];
1895
- oldChildWrapper.previousSibling_ = oldChildWrapper.nextSibling_ = oldChildWrapper.parentNode_ = undefined;
1896
- if (oldChildNode.parentNode) {
1897
- originalReplaceChild.call(oldChildNode.parentNode, unwrapNodesForInsertion(this, nodes), oldChildNode);
1898
- }
1899
- } else {
1900
- ensureSameOwnerDocument(this, newChildWrapper);
1901
- clearChildNodes(this);
1902
- originalReplaceChild.call(unsafeUnwrap(this), unwrap(newChildWrapper), oldChildNode);
1903
- }
1904
- enqueueMutation(this, "childList", {
1905
- addedNodes: nodes,
1906
- removedNodes: createOneElementNodeList(oldChildWrapper),
1907
- nextSibling: nextNode,
1908
- previousSibling: previousNode
1909
- });
1910
- nodeWasRemoved(oldChildWrapper);
1911
- nodesWereAdded(nodes, this);
1912
- return oldChildWrapper;
1913
- },
1914
- nodeIsInserted_: function() {
1915
- for (var child = this.firstChild; child; child = child.nextSibling) {
1916
- child.nodeIsInserted_();
1917
- }
1918
- },
1919
- hasChildNodes: function() {
1920
- return this.firstChild !== null;
1921
- },
1922
- get parentNode() {
1923
- return this.parentNode_ !== undefined ? this.parentNode_ : wrap(unsafeUnwrap(this).parentNode);
1924
- },
1925
- get firstChild() {
1926
- return this.firstChild_ !== undefined ? this.firstChild_ : wrap(unsafeUnwrap(this).firstChild);
1927
- },
1928
- get lastChild() {
1929
- return this.lastChild_ !== undefined ? this.lastChild_ : wrap(unsafeUnwrap(this).lastChild);
1930
- },
1931
- get nextSibling() {
1932
- return this.nextSibling_ !== undefined ? this.nextSibling_ : wrap(unsafeUnwrap(this).nextSibling);
1933
- },
1934
- get previousSibling() {
1935
- return this.previousSibling_ !== undefined ? this.previousSibling_ : wrap(unsafeUnwrap(this).previousSibling);
1936
- },
1937
- get parentElement() {
1938
- var p = this.parentNode;
1939
- while (p && p.nodeType !== Node.ELEMENT_NODE) {
1940
- p = p.parentNode;
1941
- }
1942
- return p;
1943
- },
1944
- get textContent() {
1945
- var s = "";
1946
- for (var child = this.firstChild; child; child = child.nextSibling) {
1947
- if (child.nodeType != Node.COMMENT_NODE) {
1948
- s += child.textContent;
1949
- }
1950
- }
1951
- return s;
1952
- },
1953
- set textContent(textContent) {
1954
- if (textContent == null) textContent = "";
1955
- var removedNodes = snapshotNodeList(this.childNodes);
1956
- if (this.invalidateShadowRenderer()) {
1957
- removeAllChildNodes(this);
1958
- if (textContent !== "") {
1959
- var textNode = unsafeUnwrap(this).ownerDocument.createTextNode(textContent);
1960
- this.appendChild(textNode);
1961
- }
1962
- } else {
1963
- clearChildNodes(this);
1964
- unsafeUnwrap(this).textContent = textContent;
1965
- }
1966
- var addedNodes = snapshotNodeList(this.childNodes);
1967
- enqueueMutation(this, "childList", {
1968
- addedNodes: addedNodes,
1969
- removedNodes: removedNodes
1970
- });
1971
- nodesWereRemoved(removedNodes);
1972
- nodesWereAdded(addedNodes, this);
1973
- },
1974
- get childNodes() {
1975
- var wrapperList = new NodeList();
1976
- var i = 0;
1977
- for (var child = this.firstChild; child; child = child.nextSibling) {
1978
- wrapperList[i++] = child;
1979
- }
1980
- wrapperList.length = i;
1981
- return wrapperList;
1982
- },
1983
- cloneNode: function(deep) {
1984
- return cloneNode(this, deep);
1985
- },
1986
- contains: function(child) {
1987
- return contains(this, wrapIfNeeded(child));
1988
- },
1989
- compareDocumentPosition: function(otherNode) {
1990
- return originalCompareDocumentPosition.call(unsafeUnwrap(this), unwrapIfNeeded(otherNode));
1991
- },
1992
- isEqualNode: function(otherNode) {
1993
- return originalIsEqualNode.call(unsafeUnwrap(this), unwrapIfNeeded(otherNode));
1994
- },
1995
- normalize: function() {
1996
- var nodes = snapshotNodeList(this.childNodes);
1997
- var remNodes = [];
1998
- var s = "";
1999
- var modNode;
2000
- for (var i = 0, n; i < nodes.length; i++) {
2001
- n = nodes[i];
2002
- if (n.nodeType === Node.TEXT_NODE) {
2003
- if (!modNode && !n.data.length) this.removeChild(n); else if (!modNode) modNode = n; else {
2004
- s += n.data;
2005
- remNodes.push(n);
2006
- }
2007
- } else {
2008
- if (modNode && remNodes.length) {
2009
- modNode.data += s;
2010
- cleanupNodes(remNodes);
2011
- }
2012
- remNodes = [];
2013
- s = "";
2014
- modNode = null;
2015
- if (n.childNodes.length) n.normalize();
2016
- }
2017
- }
2018
- if (modNode && remNodes.length) {
2019
- modNode.data += s;
2020
- cleanupNodes(remNodes);
2021
- }
2022
- }
2023
- });
2024
- defineWrapGetter(Node, "ownerDocument");
2025
- registerWrapper(OriginalNode, Node, document.createDocumentFragment());
2026
- delete Node.prototype.querySelector;
2027
- delete Node.prototype.querySelectorAll;
2028
- Node.prototype = mixin(Object.create(EventTarget.prototype), Node.prototype);
2029
- scope.cloneNode = cloneNode;
2030
- scope.nodeWasAdded = nodeWasAdded;
2031
- scope.nodeWasRemoved = nodeWasRemoved;
2032
- scope.nodesWereAdded = nodesWereAdded;
2033
- scope.nodesWereRemoved = nodesWereRemoved;
2034
- scope.originalInsertBefore = originalInsertBefore;
2035
- scope.originalRemoveChild = originalRemoveChild;
2036
- scope.snapshotNodeList = snapshotNodeList;
2037
- scope.wrappers.Node = Node;
2038
- })(window.ShadowDOMPolyfill);
2039
-
2040
- (function(scope) {
2041
- "use strict";
2042
- var HTMLCollection = scope.wrappers.HTMLCollection;
2043
- var NodeList = scope.wrappers.NodeList;
2044
- var getTreeScope = scope.getTreeScope;
2045
- var unsafeUnwrap = scope.unsafeUnwrap;
2046
- var wrap = scope.wrap;
2047
- var originalDocumentQuerySelector = document.querySelector;
2048
- var originalElementQuerySelector = document.documentElement.querySelector;
2049
- var originalDocumentQuerySelectorAll = document.querySelectorAll;
2050
- var originalElementQuerySelectorAll = document.documentElement.querySelectorAll;
2051
- var originalDocumentGetElementsByTagName = document.getElementsByTagName;
2052
- var originalElementGetElementsByTagName = document.documentElement.getElementsByTagName;
2053
- var originalDocumentGetElementsByTagNameNS = document.getElementsByTagNameNS;
2054
- var originalElementGetElementsByTagNameNS = document.documentElement.getElementsByTagNameNS;
2055
- var OriginalElement = window.Element;
2056
- var OriginalDocument = window.HTMLDocument || window.Document;
2057
- function filterNodeList(list, index, result, deep) {
2058
- var wrappedItem = null;
2059
- var root = null;
2060
- for (var i = 0, length = list.length; i < length; i++) {
2061
- wrappedItem = wrap(list[i]);
2062
- if (!deep && (root = getTreeScope(wrappedItem).root)) {
2063
- if (root instanceof scope.wrappers.ShadowRoot) {
2064
- continue;
2065
- }
2066
- }
2067
- result[index++] = wrappedItem;
2068
- }
2069
- return index;
2070
- }
2071
- function shimSelector(selector) {
2072
- return String(selector).replace(/\/deep\/|::shadow|>>>/g, " ");
2073
- }
2074
- function shimMatchesSelector(selector) {
2075
- return String(selector).replace(/:host\(([^\s]+)\)/g, "$1").replace(/([^\s]):host/g, "$1").replace(":host", "*").replace(/\^|\/shadow\/|\/shadow-deep\/|::shadow|\/deep\/|::content|>>>/g, " ");
2076
- }
2077
- function findOne(node, selector) {
2078
- var m, el = node.firstElementChild;
2079
- while (el) {
2080
- if (el.matches(selector)) return el;
2081
- m = findOne(el, selector);
2082
- if (m) return m;
2083
- el = el.nextElementSibling;
2084
- }
2085
- return null;
2086
- }
2087
- function matchesSelector(el, selector) {
2088
- return el.matches(selector);
2089
- }
2090
- var XHTML_NS = "http://www.w3.org/1999/xhtml";
2091
- function matchesTagName(el, localName, localNameLowerCase) {
2092
- var ln = el.localName;
2093
- return ln === localName || ln === localNameLowerCase && el.namespaceURI === XHTML_NS;
2094
- }
2095
- function matchesEveryThing() {
2096
- return true;
2097
- }
2098
- function matchesLocalNameOnly(el, ns, localName) {
2099
- return el.localName === localName;
2100
- }
2101
- function matchesNameSpace(el, ns) {
2102
- return el.namespaceURI === ns;
2103
- }
2104
- function matchesLocalNameNS(el, ns, localName) {
2105
- return el.namespaceURI === ns && el.localName === localName;
2106
- }
2107
- function findElements(node, index, result, p, arg0, arg1) {
2108
- var el = node.firstElementChild;
2109
- while (el) {
2110
- if (p(el, arg0, arg1)) result[index++] = el;
2111
- index = findElements(el, index, result, p, arg0, arg1);
2112
- el = el.nextElementSibling;
2113
- }
2114
- return index;
2115
- }
2116
- function querySelectorAllFiltered(p, index, result, selector, deep) {
2117
- var target = unsafeUnwrap(this);
2118
- var list;
2119
- var root = getTreeScope(this).root;
2120
- if (root instanceof scope.wrappers.ShadowRoot) {
2121
- return findElements(this, index, result, p, selector, null);
2122
- } else if (target instanceof OriginalElement) {
2123
- list = originalElementQuerySelectorAll.call(target, selector);
2124
- } else if (target instanceof OriginalDocument) {
2125
- list = originalDocumentQuerySelectorAll.call(target, selector);
2126
- } else {
2127
- return findElements(this, index, result, p, selector, null);
2128
- }
2129
- return filterNodeList(list, index, result, deep);
2130
- }
2131
- var SelectorsInterface = {
2132
- querySelector: function(selector) {
2133
- var shimmed = shimSelector(selector);
2134
- var deep = shimmed !== selector;
2135
- selector = shimmed;
2136
- var target = unsafeUnwrap(this);
2137
- var wrappedItem;
2138
- var root = getTreeScope(this).root;
2139
- if (root instanceof scope.wrappers.ShadowRoot) {
2140
- return findOne(this, selector);
2141
- } else if (target instanceof OriginalElement) {
2142
- wrappedItem = wrap(originalElementQuerySelector.call(target, selector));
2143
- } else if (target instanceof OriginalDocument) {
2144
- wrappedItem = wrap(originalDocumentQuerySelector.call(target, selector));
2145
- } else {
2146
- return findOne(this, selector);
2147
- }
2148
- if (!wrappedItem) {
2149
- return wrappedItem;
2150
- } else if (!deep && (root = getTreeScope(wrappedItem).root)) {
2151
- if (root instanceof scope.wrappers.ShadowRoot) {
2152
- return findOne(this, selector);
2153
- }
2154
- }
2155
- return wrappedItem;
2156
- },
2157
- querySelectorAll: function(selector) {
2158
- var shimmed = shimSelector(selector);
2159
- var deep = shimmed !== selector;
2160
- selector = shimmed;
2161
- var result = new NodeList();
2162
- result.length = querySelectorAllFiltered.call(this, matchesSelector, 0, result, selector, deep);
2163
- return result;
2164
- }
2165
- };
2166
- var MatchesInterface = {
2167
- matches: function(selector) {
2168
- selector = shimMatchesSelector(selector);
2169
- return scope.originalMatches.call(unsafeUnwrap(this), selector);
2170
- }
2171
- };
2172
- function getElementsByTagNameFiltered(p, index, result, localName, lowercase) {
2173
- var target = unsafeUnwrap(this);
2174
- var list;
2175
- var root = getTreeScope(this).root;
2176
- if (root instanceof scope.wrappers.ShadowRoot) {
2177
- return findElements(this, index, result, p, localName, lowercase);
2178
- } else if (target instanceof OriginalElement) {
2179
- list = originalElementGetElementsByTagName.call(target, localName, lowercase);
2180
- } else if (target instanceof OriginalDocument) {
2181
- list = originalDocumentGetElementsByTagName.call(target, localName, lowercase);
2182
- } else {
2183
- return findElements(this, index, result, p, localName, lowercase);
2184
- }
2185
- return filterNodeList(list, index, result, false);
2186
- }
2187
- function getElementsByTagNameNSFiltered(p, index, result, ns, localName) {
2188
- var target = unsafeUnwrap(this);
2189
- var list;
2190
- var root = getTreeScope(this).root;
2191
- if (root instanceof scope.wrappers.ShadowRoot) {
2192
- return findElements(this, index, result, p, ns, localName);
2193
- } else if (target instanceof OriginalElement) {
2194
- list = originalElementGetElementsByTagNameNS.call(target, ns, localName);
2195
- } else if (target instanceof OriginalDocument) {
2196
- list = originalDocumentGetElementsByTagNameNS.call(target, ns, localName);
2197
- } else {
2198
- return findElements(this, index, result, p, ns, localName);
2199
- }
2200
- return filterNodeList(list, index, result, false);
2201
- }
2202
- var GetElementsByInterface = {
2203
- getElementsByTagName: function(localName) {
2204
- var result = new HTMLCollection();
2205
- var match = localName === "*" ? matchesEveryThing : matchesTagName;
2206
- result.length = getElementsByTagNameFiltered.call(this, match, 0, result, localName, localName.toLowerCase());
2207
- return result;
2208
- },
2209
- getElementsByClassName: function(className) {
2210
- return this.querySelectorAll("." + className);
2211
- },
2212
- getElementsByTagNameNS: function(ns, localName) {
2213
- var result = new HTMLCollection();
2214
- var match = null;
2215
- if (ns === "*") {
2216
- match = localName === "*" ? matchesEveryThing : matchesLocalNameOnly;
2217
- } else {
2218
- match = localName === "*" ? matchesNameSpace : matchesLocalNameNS;
2219
- }
2220
- result.length = getElementsByTagNameNSFiltered.call(this, match, 0, result, ns || null, localName);
2221
- return result;
2222
- }
2223
- };
2224
- scope.GetElementsByInterface = GetElementsByInterface;
2225
- scope.SelectorsInterface = SelectorsInterface;
2226
- scope.MatchesInterface = MatchesInterface;
2227
- })(window.ShadowDOMPolyfill);
2228
-
2229
- (function(scope) {
2230
- "use strict";
2231
- var NodeList = scope.wrappers.NodeList;
2232
- function forwardElement(node) {
2233
- while (node && node.nodeType !== Node.ELEMENT_NODE) {
2234
- node = node.nextSibling;
2235
- }
2236
- return node;
2237
- }
2238
- function backwardsElement(node) {
2239
- while (node && node.nodeType !== Node.ELEMENT_NODE) {
2240
- node = node.previousSibling;
2241
- }
2242
- return node;
2243
- }
2244
- var ParentNodeInterface = {
2245
- get firstElementChild() {
2246
- return forwardElement(this.firstChild);
2247
- },
2248
- get lastElementChild() {
2249
- return backwardsElement(this.lastChild);
2250
- },
2251
- get childElementCount() {
2252
- var count = 0;
2253
- for (var child = this.firstElementChild; child; child = child.nextElementSibling) {
2254
- count++;
2255
- }
2256
- return count;
2257
- },
2258
- get children() {
2259
- var wrapperList = new NodeList();
2260
- var i = 0;
2261
- for (var child = this.firstElementChild; child; child = child.nextElementSibling) {
2262
- wrapperList[i++] = child;
2263
- }
2264
- wrapperList.length = i;
2265
- return wrapperList;
2266
- },
2267
- remove: function() {
2268
- var p = this.parentNode;
2269
- if (p) p.removeChild(this);
2270
- }
2271
- };
2272
- var ChildNodeInterface = {
2273
- get nextElementSibling() {
2274
- return forwardElement(this.nextSibling);
2275
- },
2276
- get previousElementSibling() {
2277
- return backwardsElement(this.previousSibling);
2278
- }
2279
- };
2280
- var NonElementParentNodeInterface = {
2281
- getElementById: function(id) {
2282
- if (/[ \t\n\r\f]/.test(id)) return null;
2283
- return this.querySelector('[id="' + id + '"]');
2284
- }
2285
- };
2286
- scope.ChildNodeInterface = ChildNodeInterface;
2287
- scope.NonElementParentNodeInterface = NonElementParentNodeInterface;
2288
- scope.ParentNodeInterface = ParentNodeInterface;
2289
- })(window.ShadowDOMPolyfill);
2290
-
2291
- (function(scope) {
2292
- "use strict";
2293
- var ChildNodeInterface = scope.ChildNodeInterface;
2294
- var Node = scope.wrappers.Node;
2295
- var enqueueMutation = scope.enqueueMutation;
2296
- var mixin = scope.mixin;
2297
- var registerWrapper = scope.registerWrapper;
2298
- var unsafeUnwrap = scope.unsafeUnwrap;
2299
- var OriginalCharacterData = window.CharacterData;
2300
- function CharacterData(node) {
2301
- Node.call(this, node);
2302
- }
2303
- CharacterData.prototype = Object.create(Node.prototype);
2304
- mixin(CharacterData.prototype, {
2305
- get nodeValue() {
2306
- return this.data;
2307
- },
2308
- set nodeValue(data) {
2309
- this.data = data;
2310
- },
2311
- get textContent() {
2312
- return this.data;
2313
- },
2314
- set textContent(value) {
2315
- this.data = value;
2316
- },
2317
- get data() {
2318
- return unsafeUnwrap(this).data;
2319
- },
2320
- set data(value) {
2321
- var oldValue = unsafeUnwrap(this).data;
2322
- enqueueMutation(this, "characterData", {
2323
- oldValue: oldValue
2324
- });
2325
- unsafeUnwrap(this).data = value;
2326
- }
2327
- });
2328
- mixin(CharacterData.prototype, ChildNodeInterface);
2329
- registerWrapper(OriginalCharacterData, CharacterData, document.createTextNode(""));
2330
- scope.wrappers.CharacterData = CharacterData;
2331
- })(window.ShadowDOMPolyfill);
2332
-
2333
- (function(scope) {
2334
- "use strict";
2335
- var CharacterData = scope.wrappers.CharacterData;
2336
- var enqueueMutation = scope.enqueueMutation;
2337
- var mixin = scope.mixin;
2338
- var registerWrapper = scope.registerWrapper;
2339
- function toUInt32(x) {
2340
- return x >>> 0;
2341
- }
2342
- var OriginalText = window.Text;
2343
- function Text(node) {
2344
- CharacterData.call(this, node);
2345
- }
2346
- Text.prototype = Object.create(CharacterData.prototype);
2347
- mixin(Text.prototype, {
2348
- splitText: function(offset) {
2349
- offset = toUInt32(offset);
2350
- var s = this.data;
2351
- if (offset > s.length) throw new Error("IndexSizeError");
2352
- var head = s.slice(0, offset);
2353
- var tail = s.slice(offset);
2354
- this.data = head;
2355
- var newTextNode = this.ownerDocument.createTextNode(tail);
2356
- if (this.parentNode) this.parentNode.insertBefore(newTextNode, this.nextSibling);
2357
- return newTextNode;
2358
- }
2359
- });
2360
- registerWrapper(OriginalText, Text, document.createTextNode(""));
2361
- scope.wrappers.Text = Text;
2362
- })(window.ShadowDOMPolyfill);
2363
-
2364
- (function(scope) {
2365
- "use strict";
2366
- if (!window.DOMTokenList) {
2367
- console.warn("Missing DOMTokenList prototype, please include a " + "compatible classList polyfill such as http://goo.gl/uTcepH.");
2368
- return;
2369
- }
2370
- var unsafeUnwrap = scope.unsafeUnwrap;
2371
- var enqueueMutation = scope.enqueueMutation;
2372
- function getClass(el) {
2373
- return unsafeUnwrap(el).getAttribute("class");
2374
- }
2375
- function enqueueClassAttributeChange(el, oldValue) {
2376
- enqueueMutation(el, "attributes", {
2377
- name: "class",
2378
- namespace: null,
2379
- oldValue: oldValue
2380
- });
2381
- }
2382
- function invalidateClass(el) {
2383
- scope.invalidateRendererBasedOnAttribute(el, "class");
2384
- }
2385
- function changeClass(tokenList, method, args) {
2386
- var ownerElement = tokenList.ownerElement_;
2387
- if (ownerElement == null) {
2388
- return method.apply(tokenList, args);
2389
- }
2390
- var oldValue = getClass(ownerElement);
2391
- var retv = method.apply(tokenList, args);
2392
- if (getClass(ownerElement) !== oldValue) {
2393
- enqueueClassAttributeChange(ownerElement, oldValue);
2394
- invalidateClass(ownerElement);
2395
- }
2396
- return retv;
2397
- }
2398
- var oldAdd = DOMTokenList.prototype.add;
2399
- DOMTokenList.prototype.add = function() {
2400
- changeClass(this, oldAdd, arguments);
2401
- };
2402
- var oldRemove = DOMTokenList.prototype.remove;
2403
- DOMTokenList.prototype.remove = function() {
2404
- changeClass(this, oldRemove, arguments);
2405
- };
2406
- var oldToggle = DOMTokenList.prototype.toggle;
2407
- DOMTokenList.prototype.toggle = function() {
2408
- return changeClass(this, oldToggle, arguments);
2409
- };
2410
- })(window.ShadowDOMPolyfill);
2411
-
2412
- (function(scope) {
2413
- "use strict";
2414
- var ChildNodeInterface = scope.ChildNodeInterface;
2415
- var GetElementsByInterface = scope.GetElementsByInterface;
2416
- var Node = scope.wrappers.Node;
2417
- var ParentNodeInterface = scope.ParentNodeInterface;
2418
- var SelectorsInterface = scope.SelectorsInterface;
2419
- var MatchesInterface = scope.MatchesInterface;
2420
- var addWrapNodeListMethod = scope.addWrapNodeListMethod;
2421
- var enqueueMutation = scope.enqueueMutation;
2422
- var mixin = scope.mixin;
2423
- var oneOf = scope.oneOf;
2424
- var registerWrapper = scope.registerWrapper;
2425
- var unsafeUnwrap = scope.unsafeUnwrap;
2426
- var wrappers = scope.wrappers;
2427
- var OriginalElement = window.Element;
2428
- var matchesNames = [ "matches", "mozMatchesSelector", "msMatchesSelector", "webkitMatchesSelector" ].filter(function(name) {
2429
- return OriginalElement.prototype[name];
2430
- });
2431
- var matchesName = matchesNames[0];
2432
- var originalMatches = OriginalElement.prototype[matchesName];
2433
- function invalidateRendererBasedOnAttribute(element, name) {
2434
- var p = element.parentNode;
2435
- if (!p || !p.shadowRoot) return;
2436
- var renderer = scope.getRendererForHost(p);
2437
- if (renderer.dependsOnAttribute(name)) renderer.invalidate();
2438
- }
2439
- function enqueAttributeChange(element, name, oldValue) {
2440
- enqueueMutation(element, "attributes", {
2441
- name: name,
2442
- namespace: null,
2443
- oldValue: oldValue
2444
- });
2445
- }
2446
- var classListTable = new WeakMap();
2447
- function Element(node) {
2448
- Node.call(this, node);
2449
- }
2450
- Element.prototype = Object.create(Node.prototype);
2451
- mixin(Element.prototype, {
2452
- createShadowRoot: function() {
2453
- var newShadowRoot = new wrappers.ShadowRoot(this);
2454
- unsafeUnwrap(this).polymerShadowRoot_ = newShadowRoot;
2455
- var renderer = scope.getRendererForHost(this);
2456
- renderer.invalidate();
2457
- return newShadowRoot;
2458
- },
2459
- get shadowRoot() {
2460
- return unsafeUnwrap(this).polymerShadowRoot_ || null;
2461
- },
2462
- setAttribute: function(name, value) {
2463
- var oldValue = unsafeUnwrap(this).getAttribute(name);
2464
- unsafeUnwrap(this).setAttribute(name, value);
2465
- enqueAttributeChange(this, name, oldValue);
2466
- invalidateRendererBasedOnAttribute(this, name);
2467
- },
2468
- removeAttribute: function(name) {
2469
- var oldValue = unsafeUnwrap(this).getAttribute(name);
2470
- unsafeUnwrap(this).removeAttribute(name);
2471
- enqueAttributeChange(this, name, oldValue);
2472
- invalidateRendererBasedOnAttribute(this, name);
2473
- },
2474
- get classList() {
2475
- var list = classListTable.get(this);
2476
- if (!list) {
2477
- list = unsafeUnwrap(this).classList;
2478
- if (!list) return;
2479
- list.ownerElement_ = this;
2480
- classListTable.set(this, list);
2481
- }
2482
- return list;
2483
- },
2484
- get className() {
2485
- return unsafeUnwrap(this).className;
2486
- },
2487
- set className(v) {
2488
- this.setAttribute("class", v);
2489
- },
2490
- get id() {
2491
- return unsafeUnwrap(this).id;
2492
- },
2493
- set id(v) {
2494
- this.setAttribute("id", v);
2495
- }
2496
- });
2497
- matchesNames.forEach(function(name) {
2498
- if (name !== "matches") {
2499
- Element.prototype[name] = function(selector) {
2500
- return this.matches(selector);
2501
- };
2502
- }
2503
- });
2504
- if (OriginalElement.prototype.webkitCreateShadowRoot) {
2505
- Element.prototype.webkitCreateShadowRoot = Element.prototype.createShadowRoot;
2506
- }
2507
- mixin(Element.prototype, ChildNodeInterface);
2508
- mixin(Element.prototype, GetElementsByInterface);
2509
- mixin(Element.prototype, ParentNodeInterface);
2510
- mixin(Element.prototype, SelectorsInterface);
2511
- mixin(Element.prototype, MatchesInterface);
2512
- registerWrapper(OriginalElement, Element, document.createElementNS(null, "x"));
2513
- scope.invalidateRendererBasedOnAttribute = invalidateRendererBasedOnAttribute;
2514
- scope.matchesNames = matchesNames;
2515
- scope.originalMatches = originalMatches;
2516
- scope.wrappers.Element = Element;
2517
- })(window.ShadowDOMPolyfill);
2518
-
2519
- (function(scope) {
2520
- "use strict";
2521
- var Element = scope.wrappers.Element;
2522
- var defineGetter = scope.defineGetter;
2523
- var enqueueMutation = scope.enqueueMutation;
2524
- var mixin = scope.mixin;
2525
- var nodesWereAdded = scope.nodesWereAdded;
2526
- var nodesWereRemoved = scope.nodesWereRemoved;
2527
- var registerWrapper = scope.registerWrapper;
2528
- var snapshotNodeList = scope.snapshotNodeList;
2529
- var unsafeUnwrap = scope.unsafeUnwrap;
2530
- var unwrap = scope.unwrap;
2531
- var wrap = scope.wrap;
2532
- var wrappers = scope.wrappers;
2533
- var escapeAttrRegExp = /[&\u00A0"]/g;
2534
- var escapeDataRegExp = /[&\u00A0<>]/g;
2535
- function escapeReplace(c) {
2536
- switch (c) {
2537
- case "&":
2538
- return "&amp;";
2539
-
2540
- case "<":
2541
- return "&lt;";
2542
-
2543
- case ">":
2544
- return "&gt;";
2545
-
2546
- case '"':
2547
- return "&quot;";
2548
-
2549
- case " ":
2550
- return "&nbsp;";
2551
- }
2552
- }
2553
- function escapeAttr(s) {
2554
- return s.replace(escapeAttrRegExp, escapeReplace);
2555
- }
2556
- function escapeData(s) {
2557
- return s.replace(escapeDataRegExp, escapeReplace);
2558
- }
2559
- function makeSet(arr) {
2560
- var set = {};
2561
- for (var i = 0; i < arr.length; i++) {
2562
- set[arr[i]] = true;
2563
- }
2564
- return set;
2565
- }
2566
- var voidElements = makeSet([ "area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr" ]);
2567
- var plaintextParents = makeSet([ "style", "script", "xmp", "iframe", "noembed", "noframes", "plaintext", "noscript" ]);
2568
- var XHTML_NS = "http://www.w3.org/1999/xhtml";
2569
- function needsSelfClosingSlash(node) {
2570
- if (node.namespaceURI !== XHTML_NS) return true;
2571
- var doctype = node.ownerDocument.doctype;
2572
- return doctype && doctype.publicId && doctype.systemId;
2573
- }
2574
- function getOuterHTML(node, parentNode) {
2575
- switch (node.nodeType) {
2576
- case Node.ELEMENT_NODE:
2577
- var tagName = node.tagName.toLowerCase();
2578
- var s = "<" + tagName;
2579
- var attrs = node.attributes;
2580
- for (var i = 0, attr; attr = attrs[i]; i++) {
2581
- s += " " + attr.name + '="' + escapeAttr(attr.value) + '"';
2582
- }
2583
- if (voidElements[tagName]) {
2584
- if (needsSelfClosingSlash(node)) s += "/";
2585
- return s + ">";
2586
- }
2587
- return s + ">" + getInnerHTML(node) + "</" + tagName + ">";
2588
-
2589
- case Node.TEXT_NODE:
2590
- var data = node.data;
2591
- if (parentNode && plaintextParents[parentNode.localName]) return data;
2592
- return escapeData(data);
2593
-
2594
- case Node.COMMENT_NODE:
2595
- return "<!--" + node.data + "-->";
2596
-
2597
- default:
2598
- console.error(node);
2599
- throw new Error("not implemented");
2600
- }
2601
- }
2602
- function getInnerHTML(node) {
2603
- if (node instanceof wrappers.HTMLTemplateElement) node = node.content;
2604
- var s = "";
2605
- for (var child = node.firstChild; child; child = child.nextSibling) {
2606
- s += getOuterHTML(child, node);
2607
- }
2608
- return s;
2609
- }
2610
- function setInnerHTML(node, value, opt_tagName) {
2611
- var tagName = opt_tagName || "div";
2612
- node.textContent = "";
2613
- var tempElement = unwrap(node.ownerDocument.createElement(tagName));
2614
- tempElement.innerHTML = value;
2615
- var firstChild;
2616
- while (firstChild = tempElement.firstChild) {
2617
- node.appendChild(wrap(firstChild));
2618
- }
2619
- }
2620
- var oldIe = /MSIE/.test(navigator.userAgent);
2621
- var OriginalHTMLElement = window.HTMLElement;
2622
- var OriginalHTMLTemplateElement = window.HTMLTemplateElement;
2623
- function HTMLElement(node) {
2624
- Element.call(this, node);
2625
- }
2626
- HTMLElement.prototype = Object.create(Element.prototype);
2627
- mixin(HTMLElement.prototype, {
2628
- get innerHTML() {
2629
- return getInnerHTML(this);
2630
- },
2631
- set innerHTML(value) {
2632
- if (oldIe && plaintextParents[this.localName]) {
2633
- this.textContent = value;
2634
- return;
2635
- }
2636
- var removedNodes = snapshotNodeList(this.childNodes);
2637
- if (this.invalidateShadowRenderer()) {
2638
- if (this instanceof wrappers.HTMLTemplateElement) setInnerHTML(this.content, value); else setInnerHTML(this, value, this.tagName);
2639
- } else if (!OriginalHTMLTemplateElement && this instanceof wrappers.HTMLTemplateElement) {
2640
- setInnerHTML(this.content, value);
2641
- } else {
2642
- unsafeUnwrap(this).innerHTML = value;
2643
- }
2644
- var addedNodes = snapshotNodeList(this.childNodes);
2645
- enqueueMutation(this, "childList", {
2646
- addedNodes: addedNodes,
2647
- removedNodes: removedNodes
2648
- });
2649
- nodesWereRemoved(removedNodes);
2650
- nodesWereAdded(addedNodes, this);
2651
- },
2652
- get outerHTML() {
2653
- return getOuterHTML(this, this.parentNode);
2654
- },
2655
- set outerHTML(value) {
2656
- var p = this.parentNode;
2657
- if (p) {
2658
- p.invalidateShadowRenderer();
2659
- var df = frag(p, value);
2660
- p.replaceChild(df, this);
2661
- }
2662
- },
2663
- insertAdjacentHTML: function(position, text) {
2664
- var contextElement, refNode;
2665
- switch (String(position).toLowerCase()) {
2666
- case "beforebegin":
2667
- contextElement = this.parentNode;
2668
- refNode = this;
2669
- break;
2670
-
2671
- case "afterend":
2672
- contextElement = this.parentNode;
2673
- refNode = this.nextSibling;
2674
- break;
2675
-
2676
- case "afterbegin":
2677
- contextElement = this;
2678
- refNode = this.firstChild;
2679
- break;
2680
-
2681
- case "beforeend":
2682
- contextElement = this;
2683
- refNode = null;
2684
- break;
2685
-
2686
- default:
2687
- return;
2688
- }
2689
- var df = frag(contextElement, text);
2690
- contextElement.insertBefore(df, refNode);
2691
- },
2692
- get hidden() {
2693
- return this.hasAttribute("hidden");
2694
- },
2695
- set hidden(v) {
2696
- if (v) {
2697
- this.setAttribute("hidden", "");
2698
- } else {
2699
- this.removeAttribute("hidden");
2700
- }
2701
- }
2702
- });
2703
- function frag(contextElement, html) {
2704
- var p = unwrap(contextElement.cloneNode(false));
2705
- p.innerHTML = html;
2706
- var df = unwrap(document.createDocumentFragment());
2707
- var c;
2708
- while (c = p.firstChild) {
2709
- df.appendChild(c);
2710
- }
2711
- return wrap(df);
2712
- }
2713
- function getter(name) {
2714
- return function() {
2715
- scope.renderAllPending();
2716
- return unsafeUnwrap(this)[name];
2717
- };
2718
- }
2719
- function getterRequiresRendering(name) {
2720
- defineGetter(HTMLElement, name, getter(name));
2721
- }
2722
- [ "clientHeight", "clientLeft", "clientTop", "clientWidth", "offsetHeight", "offsetLeft", "offsetTop", "offsetWidth", "scrollHeight", "scrollWidth" ].forEach(getterRequiresRendering);
2723
- function getterAndSetterRequiresRendering(name) {
2724
- Object.defineProperty(HTMLElement.prototype, name, {
2725
- get: getter(name),
2726
- set: function(v) {
2727
- scope.renderAllPending();
2728
- unsafeUnwrap(this)[name] = v;
2729
- },
2730
- configurable: true,
2731
- enumerable: true
2732
- });
2733
- }
2734
- [ "scrollLeft", "scrollTop" ].forEach(getterAndSetterRequiresRendering);
2735
- function methodRequiresRendering(name) {
2736
- Object.defineProperty(HTMLElement.prototype, name, {
2737
- value: function() {
2738
- scope.renderAllPending();
2739
- return unsafeUnwrap(this)[name].apply(unsafeUnwrap(this), arguments);
2740
- },
2741
- configurable: true,
2742
- enumerable: true
2743
- });
2744
- }
2745
- [ "focus", "getBoundingClientRect", "getClientRects", "scrollIntoView" ].forEach(methodRequiresRendering);
2746
- registerWrapper(OriginalHTMLElement, HTMLElement, document.createElement("b"));
2747
- scope.wrappers.HTMLElement = HTMLElement;
2748
- scope.getInnerHTML = getInnerHTML;
2749
- scope.setInnerHTML = setInnerHTML;
2750
- })(window.ShadowDOMPolyfill);
2751
-
2752
- (function(scope) {
2753
- "use strict";
2754
- var HTMLElement = scope.wrappers.HTMLElement;
2755
- var mixin = scope.mixin;
2756
- var registerWrapper = scope.registerWrapper;
2757
- var unsafeUnwrap = scope.unsafeUnwrap;
2758
- var wrap = scope.wrap;
2759
- var OriginalHTMLCanvasElement = window.HTMLCanvasElement;
2760
- function HTMLCanvasElement(node) {
2761
- HTMLElement.call(this, node);
2762
- }
2763
- HTMLCanvasElement.prototype = Object.create(HTMLElement.prototype);
2764
- mixin(HTMLCanvasElement.prototype, {
2765
- getContext: function() {
2766
- var context = unsafeUnwrap(this).getContext.apply(unsafeUnwrap(this), arguments);
2767
- return context && wrap(context);
2768
- }
2769
- });
2770
- registerWrapper(OriginalHTMLCanvasElement, HTMLCanvasElement, document.createElement("canvas"));
2771
- scope.wrappers.HTMLCanvasElement = HTMLCanvasElement;
2772
- })(window.ShadowDOMPolyfill);
2773
-
2774
- (function(scope) {
2775
- "use strict";
2776
- var HTMLElement = scope.wrappers.HTMLElement;
2777
- var mixin = scope.mixin;
2778
- var registerWrapper = scope.registerWrapper;
2779
- var OriginalHTMLContentElement = window.HTMLContentElement;
2780
- function HTMLContentElement(node) {
2781
- HTMLElement.call(this, node);
2782
- }
2783
- HTMLContentElement.prototype = Object.create(HTMLElement.prototype);
2784
- mixin(HTMLContentElement.prototype, {
2785
- constructor: HTMLContentElement,
2786
- get select() {
2787
- return this.getAttribute("select");
2788
- },
2789
- set select(value) {
2790
- this.setAttribute("select", value);
2791
- },
2792
- setAttribute: function(n, v) {
2793
- HTMLElement.prototype.setAttribute.call(this, n, v);
2794
- if (String(n).toLowerCase() === "select") this.invalidateShadowRenderer(true);
2795
- }
2796
- });
2797
- if (OriginalHTMLContentElement) registerWrapper(OriginalHTMLContentElement, HTMLContentElement);
2798
- scope.wrappers.HTMLContentElement = HTMLContentElement;
2799
- })(window.ShadowDOMPolyfill);
2800
-
2801
- (function(scope) {
2802
- "use strict";
2803
- var HTMLElement = scope.wrappers.HTMLElement;
2804
- var mixin = scope.mixin;
2805
- var registerWrapper = scope.registerWrapper;
2806
- var wrapHTMLCollection = scope.wrapHTMLCollection;
2807
- var unwrap = scope.unwrap;
2808
- var OriginalHTMLFormElement = window.HTMLFormElement;
2809
- function HTMLFormElement(node) {
2810
- HTMLElement.call(this, node);
2811
- }
2812
- HTMLFormElement.prototype = Object.create(HTMLElement.prototype);
2813
- mixin(HTMLFormElement.prototype, {
2814
- get elements() {
2815
- return wrapHTMLCollection(unwrap(this).elements);
2816
- }
2817
- });
2818
- registerWrapper(OriginalHTMLFormElement, HTMLFormElement, document.createElement("form"));
2819
- scope.wrappers.HTMLFormElement = HTMLFormElement;
2820
- })(window.ShadowDOMPolyfill);
2821
-
2822
- (function(scope) {
2823
- "use strict";
2824
- var HTMLElement = scope.wrappers.HTMLElement;
2825
- var registerWrapper = scope.registerWrapper;
2826
- var unwrap = scope.unwrap;
2827
- var rewrap = scope.rewrap;
2828
- var OriginalHTMLImageElement = window.HTMLImageElement;
2829
- function HTMLImageElement(node) {
2830
- HTMLElement.call(this, node);
2831
- }
2832
- HTMLImageElement.prototype = Object.create(HTMLElement.prototype);
2833
- registerWrapper(OriginalHTMLImageElement, HTMLImageElement, document.createElement("img"));
2834
- function Image(width, height) {
2835
- if (!(this instanceof Image)) {
2836
- throw new TypeError("DOM object constructor cannot be called as a function.");
2837
- }
2838
- var node = unwrap(document.createElement("img"));
2839
- HTMLElement.call(this, node);
2840
- rewrap(node, this);
2841
- if (width !== undefined) node.width = width;
2842
- if (height !== undefined) node.height = height;
2843
- }
2844
- Image.prototype = HTMLImageElement.prototype;
2845
- scope.wrappers.HTMLImageElement = HTMLImageElement;
2846
- scope.wrappers.Image = Image;
2847
- })(window.ShadowDOMPolyfill);
2848
-
2849
- (function(scope) {
2850
- "use strict";
2851
- var HTMLElement = scope.wrappers.HTMLElement;
2852
- var mixin = scope.mixin;
2853
- var NodeList = scope.wrappers.NodeList;
2854
- var registerWrapper = scope.registerWrapper;
2855
- var OriginalHTMLShadowElement = window.HTMLShadowElement;
2856
- function HTMLShadowElement(node) {
2857
- HTMLElement.call(this, node);
2858
- }
2859
- HTMLShadowElement.prototype = Object.create(HTMLElement.prototype);
2860
- HTMLShadowElement.prototype.constructor = HTMLShadowElement;
2861
- if (OriginalHTMLShadowElement) registerWrapper(OriginalHTMLShadowElement, HTMLShadowElement);
2862
- scope.wrappers.HTMLShadowElement = HTMLShadowElement;
2863
- })(window.ShadowDOMPolyfill);
2864
-
2865
- (function(scope) {
2866
- "use strict";
2867
- var HTMLElement = scope.wrappers.HTMLElement;
2868
- var mixin = scope.mixin;
2869
- var registerWrapper = scope.registerWrapper;
2870
- var unsafeUnwrap = scope.unsafeUnwrap;
2871
- var unwrap = scope.unwrap;
2872
- var wrap = scope.wrap;
2873
- var contentTable = new WeakMap();
2874
- var templateContentsOwnerTable = new WeakMap();
2875
- function getTemplateContentsOwner(doc) {
2876
- if (!doc.defaultView) return doc;
2877
- var d = templateContentsOwnerTable.get(doc);
2878
- if (!d) {
2879
- d = doc.implementation.createHTMLDocument("");
2880
- while (d.lastChild) {
2881
- d.removeChild(d.lastChild);
2882
- }
2883
- templateContentsOwnerTable.set(doc, d);
2884
- }
2885
- return d;
2886
- }
2887
- function extractContent(templateElement) {
2888
- var doc = getTemplateContentsOwner(templateElement.ownerDocument);
2889
- var df = unwrap(doc.createDocumentFragment());
2890
- var child;
2891
- while (child = templateElement.firstChild) {
2892
- df.appendChild(child);
2893
- }
2894
- return df;
2895
- }
2896
- var OriginalHTMLTemplateElement = window.HTMLTemplateElement;
2897
- function HTMLTemplateElement(node) {
2898
- HTMLElement.call(this, node);
2899
- if (!OriginalHTMLTemplateElement) {
2900
- var content = extractContent(node);
2901
- contentTable.set(this, wrap(content));
2902
- }
2903
- }
2904
- HTMLTemplateElement.prototype = Object.create(HTMLElement.prototype);
2905
- mixin(HTMLTemplateElement.prototype, {
2906
- constructor: HTMLTemplateElement,
2907
- get content() {
2908
- if (OriginalHTMLTemplateElement) return wrap(unsafeUnwrap(this).content);
2909
- return contentTable.get(this);
2910
- }
2911
- });
2912
- if (OriginalHTMLTemplateElement) registerWrapper(OriginalHTMLTemplateElement, HTMLTemplateElement);
2913
- scope.wrappers.HTMLTemplateElement = HTMLTemplateElement;
2914
- })(window.ShadowDOMPolyfill);
2915
-
2916
- (function(scope) {
2917
- "use strict";
2918
- var HTMLElement = scope.wrappers.HTMLElement;
2919
- var registerWrapper = scope.registerWrapper;
2920
- var OriginalHTMLMediaElement = window.HTMLMediaElement;
2921
- if (!OriginalHTMLMediaElement) return;
2922
- function HTMLMediaElement(node) {
2923
- HTMLElement.call(this, node);
2924
- }
2925
- HTMLMediaElement.prototype = Object.create(HTMLElement.prototype);
2926
- registerWrapper(OriginalHTMLMediaElement, HTMLMediaElement, document.createElement("audio"));
2927
- scope.wrappers.HTMLMediaElement = HTMLMediaElement;
2928
- })(window.ShadowDOMPolyfill);
2929
-
2930
- (function(scope) {
2931
- "use strict";
2932
- var HTMLMediaElement = scope.wrappers.HTMLMediaElement;
2933
- var registerWrapper = scope.registerWrapper;
2934
- var unwrap = scope.unwrap;
2935
- var rewrap = scope.rewrap;
2936
- var OriginalHTMLAudioElement = window.HTMLAudioElement;
2937
- if (!OriginalHTMLAudioElement) return;
2938
- function HTMLAudioElement(node) {
2939
- HTMLMediaElement.call(this, node);
2940
- }
2941
- HTMLAudioElement.prototype = Object.create(HTMLMediaElement.prototype);
2942
- registerWrapper(OriginalHTMLAudioElement, HTMLAudioElement, document.createElement("audio"));
2943
- function Audio(src) {
2944
- if (!(this instanceof Audio)) {
2945
- throw new TypeError("DOM object constructor cannot be called as a function.");
2946
- }
2947
- var node = unwrap(document.createElement("audio"));
2948
- HTMLMediaElement.call(this, node);
2949
- rewrap(node, this);
2950
- node.setAttribute("preload", "auto");
2951
- if (src !== undefined) node.setAttribute("src", src);
2952
- }
2953
- Audio.prototype = HTMLAudioElement.prototype;
2954
- scope.wrappers.HTMLAudioElement = HTMLAudioElement;
2955
- scope.wrappers.Audio = Audio;
2956
- })(window.ShadowDOMPolyfill);
2957
-
2958
- (function(scope) {
2959
- "use strict";
2960
- var HTMLElement = scope.wrappers.HTMLElement;
2961
- var mixin = scope.mixin;
2962
- var registerWrapper = scope.registerWrapper;
2963
- var rewrap = scope.rewrap;
2964
- var unwrap = scope.unwrap;
2965
- var wrap = scope.wrap;
2966
- var OriginalHTMLOptionElement = window.HTMLOptionElement;
2967
- function trimText(s) {
2968
- return s.replace(/\s+/g, " ").trim();
2969
- }
2970
- function HTMLOptionElement(node) {
2971
- HTMLElement.call(this, node);
2972
- }
2973
- HTMLOptionElement.prototype = Object.create(HTMLElement.prototype);
2974
- mixin(HTMLOptionElement.prototype, {
2975
- get text() {
2976
- return trimText(this.textContent);
2977
- },
2978
- set text(value) {
2979
- this.textContent = trimText(String(value));
2980
- },
2981
- get form() {
2982
- return wrap(unwrap(this).form);
2983
- }
2984
- });
2985
- registerWrapper(OriginalHTMLOptionElement, HTMLOptionElement, document.createElement("option"));
2986
- function Option(text, value, defaultSelected, selected) {
2987
- if (!(this instanceof Option)) {
2988
- throw new TypeError("DOM object constructor cannot be called as a function.");
2989
- }
2990
- var node = unwrap(document.createElement("option"));
2991
- HTMLElement.call(this, node);
2992
- rewrap(node, this);
2993
- if (text !== undefined) node.text = text;
2994
- if (value !== undefined) node.setAttribute("value", value);
2995
- if (defaultSelected === true) node.setAttribute("selected", "");
2996
- node.selected = selected === true;
2997
- }
2998
- Option.prototype = HTMLOptionElement.prototype;
2999
- scope.wrappers.HTMLOptionElement = HTMLOptionElement;
3000
- scope.wrappers.Option = Option;
3001
- })(window.ShadowDOMPolyfill);
3002
-
3003
- (function(scope) {
3004
- "use strict";
3005
- var HTMLElement = scope.wrappers.HTMLElement;
3006
- var mixin = scope.mixin;
3007
- var registerWrapper = scope.registerWrapper;
3008
- var unwrap = scope.unwrap;
3009
- var wrap = scope.wrap;
3010
- var OriginalHTMLSelectElement = window.HTMLSelectElement;
3011
- function HTMLSelectElement(node) {
3012
- HTMLElement.call(this, node);
3013
- }
3014
- HTMLSelectElement.prototype = Object.create(HTMLElement.prototype);
3015
- mixin(HTMLSelectElement.prototype, {
3016
- add: function(element, before) {
3017
- if (typeof before === "object") before = unwrap(before);
3018
- unwrap(this).add(unwrap(element), before);
3019
- },
3020
- remove: function(indexOrNode) {
3021
- if (indexOrNode === undefined) {
3022
- HTMLElement.prototype.remove.call(this);
3023
- return;
3024
- }
3025
- if (typeof indexOrNode === "object") indexOrNode = unwrap(indexOrNode);
3026
- unwrap(this).remove(indexOrNode);
3027
- },
3028
- get form() {
3029
- return wrap(unwrap(this).form);
3030
- }
3031
- });
3032
- registerWrapper(OriginalHTMLSelectElement, HTMLSelectElement, document.createElement("select"));
3033
- scope.wrappers.HTMLSelectElement = HTMLSelectElement;
3034
- })(window.ShadowDOMPolyfill);
3035
-
3036
- (function(scope) {
3037
- "use strict";
3038
- var HTMLElement = scope.wrappers.HTMLElement;
3039
- var mixin = scope.mixin;
3040
- var registerWrapper = scope.registerWrapper;
3041
- var unwrap = scope.unwrap;
3042
- var wrap = scope.wrap;
3043
- var wrapHTMLCollection = scope.wrapHTMLCollection;
3044
- var OriginalHTMLTableElement = window.HTMLTableElement;
3045
- function HTMLTableElement(node) {
3046
- HTMLElement.call(this, node);
3047
- }
3048
- HTMLTableElement.prototype = Object.create(HTMLElement.prototype);
3049
- mixin(HTMLTableElement.prototype, {
3050
- get caption() {
3051
- return wrap(unwrap(this).caption);
3052
- },
3053
- createCaption: function() {
3054
- return wrap(unwrap(this).createCaption());
3055
- },
3056
- get tHead() {
3057
- return wrap(unwrap(this).tHead);
3058
- },
3059
- createTHead: function() {
3060
- return wrap(unwrap(this).createTHead());
3061
- },
3062
- createTFoot: function() {
3063
- return wrap(unwrap(this).createTFoot());
3064
- },
3065
- get tFoot() {
3066
- return wrap(unwrap(this).tFoot);
3067
- },
3068
- get tBodies() {
3069
- return wrapHTMLCollection(unwrap(this).tBodies);
3070
- },
3071
- createTBody: function() {
3072
- return wrap(unwrap(this).createTBody());
3073
- },
3074
- get rows() {
3075
- return wrapHTMLCollection(unwrap(this).rows);
3076
- },
3077
- insertRow: function(index) {
3078
- return wrap(unwrap(this).insertRow(index));
3079
- }
3080
- });
3081
- registerWrapper(OriginalHTMLTableElement, HTMLTableElement, document.createElement("table"));
3082
- scope.wrappers.HTMLTableElement = HTMLTableElement;
3083
- })(window.ShadowDOMPolyfill);
3084
-
3085
- (function(scope) {
3086
- "use strict";
3087
- var HTMLElement = scope.wrappers.HTMLElement;
3088
- var mixin = scope.mixin;
3089
- var registerWrapper = scope.registerWrapper;
3090
- var wrapHTMLCollection = scope.wrapHTMLCollection;
3091
- var unwrap = scope.unwrap;
3092
- var wrap = scope.wrap;
3093
- var OriginalHTMLTableSectionElement = window.HTMLTableSectionElement;
3094
- function HTMLTableSectionElement(node) {
3095
- HTMLElement.call(this, node);
3096
- }
3097
- HTMLTableSectionElement.prototype = Object.create(HTMLElement.prototype);
3098
- mixin(HTMLTableSectionElement.prototype, {
3099
- constructor: HTMLTableSectionElement,
3100
- get rows() {
3101
- return wrapHTMLCollection(unwrap(this).rows);
3102
- },
3103
- insertRow: function(index) {
3104
- return wrap(unwrap(this).insertRow(index));
3105
- }
3106
- });
3107
- registerWrapper(OriginalHTMLTableSectionElement, HTMLTableSectionElement, document.createElement("thead"));
3108
- scope.wrappers.HTMLTableSectionElement = HTMLTableSectionElement;
3109
- })(window.ShadowDOMPolyfill);
3110
-
3111
- (function(scope) {
3112
- "use strict";
3113
- var HTMLElement = scope.wrappers.HTMLElement;
3114
- var mixin = scope.mixin;
3115
- var registerWrapper = scope.registerWrapper;
3116
- var wrapHTMLCollection = scope.wrapHTMLCollection;
3117
- var unwrap = scope.unwrap;
3118
- var wrap = scope.wrap;
3119
- var OriginalHTMLTableRowElement = window.HTMLTableRowElement;
3120
- function HTMLTableRowElement(node) {
3121
- HTMLElement.call(this, node);
3122
- }
3123
- HTMLTableRowElement.prototype = Object.create(HTMLElement.prototype);
3124
- mixin(HTMLTableRowElement.prototype, {
3125
- get cells() {
3126
- return wrapHTMLCollection(unwrap(this).cells);
3127
- },
3128
- insertCell: function(index) {
3129
- return wrap(unwrap(this).insertCell(index));
3130
- }
3131
- });
3132
- registerWrapper(OriginalHTMLTableRowElement, HTMLTableRowElement, document.createElement("tr"));
3133
- scope.wrappers.HTMLTableRowElement = HTMLTableRowElement;
3134
- })(window.ShadowDOMPolyfill);
3135
-
3136
- (function(scope) {
3137
- "use strict";
3138
- var HTMLContentElement = scope.wrappers.HTMLContentElement;
3139
- var HTMLElement = scope.wrappers.HTMLElement;
3140
- var HTMLShadowElement = scope.wrappers.HTMLShadowElement;
3141
- var HTMLTemplateElement = scope.wrappers.HTMLTemplateElement;
3142
- var mixin = scope.mixin;
3143
- var registerWrapper = scope.registerWrapper;
3144
- var OriginalHTMLUnknownElement = window.HTMLUnknownElement;
3145
- function HTMLUnknownElement(node) {
3146
- switch (node.localName) {
3147
- case "content":
3148
- return new HTMLContentElement(node);
3149
-
3150
- case "shadow":
3151
- return new HTMLShadowElement(node);
3152
-
3153
- case "template":
3154
- return new HTMLTemplateElement(node);
3155
- }
3156
- HTMLElement.call(this, node);
3157
- }
3158
- HTMLUnknownElement.prototype = Object.create(HTMLElement.prototype);
3159
- registerWrapper(OriginalHTMLUnknownElement, HTMLUnknownElement);
3160
- scope.wrappers.HTMLUnknownElement = HTMLUnknownElement;
3161
- })(window.ShadowDOMPolyfill);
3162
-
3163
- (function(scope) {
3164
- "use strict";
3165
- var Element = scope.wrappers.Element;
3166
- var HTMLElement = scope.wrappers.HTMLElement;
3167
- var registerWrapper = scope.registerWrapper;
3168
- var defineWrapGetter = scope.defineWrapGetter;
3169
- var unsafeUnwrap = scope.unsafeUnwrap;
3170
- var wrap = scope.wrap;
3171
- var mixin = scope.mixin;
3172
- var SVG_NS = "http://www.w3.org/2000/svg";
3173
- var OriginalSVGElement = window.SVGElement;
3174
- var svgTitleElement = document.createElementNS(SVG_NS, "title");
3175
- if (!("classList" in svgTitleElement)) {
3176
- var descr = Object.getOwnPropertyDescriptor(Element.prototype, "classList");
3177
- Object.defineProperty(HTMLElement.prototype, "classList", descr);
3178
- delete Element.prototype.classList;
3179
- }
3180
- function SVGElement(node) {
3181
- Element.call(this, node);
3182
- }
3183
- SVGElement.prototype = Object.create(Element.prototype);
3184
- mixin(SVGElement.prototype, {
3185
- get ownerSVGElement() {
3186
- return wrap(unsafeUnwrap(this).ownerSVGElement);
3187
- }
3188
- });
3189
- registerWrapper(OriginalSVGElement, SVGElement, document.createElementNS(SVG_NS, "title"));
3190
- scope.wrappers.SVGElement = SVGElement;
3191
- })(window.ShadowDOMPolyfill);
3192
-
3193
- (function(scope) {
3194
- "use strict";
3195
- var mixin = scope.mixin;
3196
- var registerWrapper = scope.registerWrapper;
3197
- var unwrap = scope.unwrap;
3198
- var wrap = scope.wrap;
3199
- var OriginalSVGUseElement = window.SVGUseElement;
3200
- var SVG_NS = "http://www.w3.org/2000/svg";
3201
- var gWrapper = wrap(document.createElementNS(SVG_NS, "g"));
3202
- var useElement = document.createElementNS(SVG_NS, "use");
3203
- var SVGGElement = gWrapper.constructor;
3204
- var parentInterfacePrototype = Object.getPrototypeOf(SVGGElement.prototype);
3205
- var parentInterface = parentInterfacePrototype.constructor;
3206
- function SVGUseElement(impl) {
3207
- parentInterface.call(this, impl);
3208
- }
3209
- SVGUseElement.prototype = Object.create(parentInterfacePrototype);
3210
- if ("instanceRoot" in useElement) {
3211
- mixin(SVGUseElement.prototype, {
3212
- get instanceRoot() {
3213
- return wrap(unwrap(this).instanceRoot);
3214
- },
3215
- get animatedInstanceRoot() {
3216
- return wrap(unwrap(this).animatedInstanceRoot);
3217
- }
3218
- });
3219
- }
3220
- registerWrapper(OriginalSVGUseElement, SVGUseElement, useElement);
3221
- scope.wrappers.SVGUseElement = SVGUseElement;
3222
- })(window.ShadowDOMPolyfill);
3223
-
3224
- (function(scope) {
3225
- "use strict";
3226
- var EventTarget = scope.wrappers.EventTarget;
3227
- var mixin = scope.mixin;
3228
- var registerWrapper = scope.registerWrapper;
3229
- var unsafeUnwrap = scope.unsafeUnwrap;
3230
- var wrap = scope.wrap;
3231
- var OriginalSVGElementInstance = window.SVGElementInstance;
3232
- if (!OriginalSVGElementInstance) return;
3233
- function SVGElementInstance(impl) {
3234
- EventTarget.call(this, impl);
3235
- }
3236
- SVGElementInstance.prototype = Object.create(EventTarget.prototype);
3237
- mixin(SVGElementInstance.prototype, {
3238
- get correspondingElement() {
3239
- return wrap(unsafeUnwrap(this).correspondingElement);
3240
- },
3241
- get correspondingUseElement() {
3242
- return wrap(unsafeUnwrap(this).correspondingUseElement);
3243
- },
3244
- get parentNode() {
3245
- return wrap(unsafeUnwrap(this).parentNode);
3246
- },
3247
- get childNodes() {
3248
- throw new Error("Not implemented");
3249
- },
3250
- get firstChild() {
3251
- return wrap(unsafeUnwrap(this).firstChild);
3252
- },
3253
- get lastChild() {
3254
- return wrap(unsafeUnwrap(this).lastChild);
3255
- },
3256
- get previousSibling() {
3257
- return wrap(unsafeUnwrap(this).previousSibling);
3258
- },
3259
- get nextSibling() {
3260
- return wrap(unsafeUnwrap(this).nextSibling);
3261
- }
3262
- });
3263
- registerWrapper(OriginalSVGElementInstance, SVGElementInstance);
3264
- scope.wrappers.SVGElementInstance = SVGElementInstance;
3265
- })(window.ShadowDOMPolyfill);
3266
-
3267
- (function(scope) {
3268
- "use strict";
3269
- var mixin = scope.mixin;
3270
- var registerWrapper = scope.registerWrapper;
3271
- var setWrapper = scope.setWrapper;
3272
- var unsafeUnwrap = scope.unsafeUnwrap;
3273
- var unwrap = scope.unwrap;
3274
- var unwrapIfNeeded = scope.unwrapIfNeeded;
3275
- var wrap = scope.wrap;
3276
- var OriginalCanvasRenderingContext2D = window.CanvasRenderingContext2D;
3277
- function CanvasRenderingContext2D(impl) {
3278
- setWrapper(impl, this);
3279
- }
3280
- mixin(CanvasRenderingContext2D.prototype, {
3281
- get canvas() {
3282
- return wrap(unsafeUnwrap(this).canvas);
3283
- },
3284
- drawImage: function() {
3285
- arguments[0] = unwrapIfNeeded(arguments[0]);
3286
- unsafeUnwrap(this).drawImage.apply(unsafeUnwrap(this), arguments);
3287
- },
3288
- createPattern: function() {
3289
- arguments[0] = unwrap(arguments[0]);
3290
- return unsafeUnwrap(this).createPattern.apply(unsafeUnwrap(this), arguments);
3291
- }
3292
- });
3293
- registerWrapper(OriginalCanvasRenderingContext2D, CanvasRenderingContext2D, document.createElement("canvas").getContext("2d"));
3294
- scope.wrappers.CanvasRenderingContext2D = CanvasRenderingContext2D;
3295
- })(window.ShadowDOMPolyfill);
3296
-
3297
- (function(scope) {
3298
- "use strict";
3299
- var addForwardingProperties = scope.addForwardingProperties;
3300
- var mixin = scope.mixin;
3301
- var registerWrapper = scope.registerWrapper;
3302
- var setWrapper = scope.setWrapper;
3303
- var unsafeUnwrap = scope.unsafeUnwrap;
3304
- var unwrapIfNeeded = scope.unwrapIfNeeded;
3305
- var wrap = scope.wrap;
3306
- var OriginalWebGLRenderingContext = window.WebGLRenderingContext;
3307
- if (!OriginalWebGLRenderingContext) return;
3308
- function WebGLRenderingContext(impl) {
3309
- setWrapper(impl, this);
3310
- }
3311
- mixin(WebGLRenderingContext.prototype, {
3312
- get canvas() {
3313
- return wrap(unsafeUnwrap(this).canvas);
3314
- },
3315
- texImage2D: function() {
3316
- arguments[5] = unwrapIfNeeded(arguments[5]);
3317
- unsafeUnwrap(this).texImage2D.apply(unsafeUnwrap(this), arguments);
3318
- },
3319
- texSubImage2D: function() {
3320
- arguments[6] = unwrapIfNeeded(arguments[6]);
3321
- unsafeUnwrap(this).texSubImage2D.apply(unsafeUnwrap(this), arguments);
3322
- }
3323
- });
3324
- var OriginalWebGLRenderingContextBase = Object.getPrototypeOf(OriginalWebGLRenderingContext.prototype);
3325
- if (OriginalWebGLRenderingContextBase !== Object.prototype) {
3326
- addForwardingProperties(OriginalWebGLRenderingContextBase, WebGLRenderingContext.prototype);
3327
- }
3328
- var instanceProperties = /WebKit/.test(navigator.userAgent) ? {
3329
- drawingBufferHeight: null,
3330
- drawingBufferWidth: null
3331
- } : {};
3332
- registerWrapper(OriginalWebGLRenderingContext, WebGLRenderingContext, instanceProperties);
3333
- scope.wrappers.WebGLRenderingContext = WebGLRenderingContext;
3334
- })(window.ShadowDOMPolyfill);
3335
-
3336
- (function(scope) {
3337
- "use strict";
3338
- var Node = scope.wrappers.Node;
3339
- var GetElementsByInterface = scope.GetElementsByInterface;
3340
- var NonElementParentNodeInterface = scope.NonElementParentNodeInterface;
3341
- var ParentNodeInterface = scope.ParentNodeInterface;
3342
- var SelectorsInterface = scope.SelectorsInterface;
3343
- var mixin = scope.mixin;
3344
- var registerObject = scope.registerObject;
3345
- var registerWrapper = scope.registerWrapper;
3346
- var OriginalDocumentFragment = window.DocumentFragment;
3347
- function DocumentFragment(node) {
3348
- Node.call(this, node);
3349
- }
3350
- DocumentFragment.prototype = Object.create(Node.prototype);
3351
- mixin(DocumentFragment.prototype, ParentNodeInterface);
3352
- mixin(DocumentFragment.prototype, SelectorsInterface);
3353
- mixin(DocumentFragment.prototype, GetElementsByInterface);
3354
- mixin(DocumentFragment.prototype, NonElementParentNodeInterface);
3355
- registerWrapper(OriginalDocumentFragment, DocumentFragment, document.createDocumentFragment());
3356
- scope.wrappers.DocumentFragment = DocumentFragment;
3357
- var Comment = registerObject(document.createComment(""));
3358
- scope.wrappers.Comment = Comment;
3359
- })(window.ShadowDOMPolyfill);
3360
-
3361
- (function(scope) {
3362
- "use strict";
3363
- var DocumentFragment = scope.wrappers.DocumentFragment;
3364
- var TreeScope = scope.TreeScope;
3365
- var elementFromPoint = scope.elementFromPoint;
3366
- var getInnerHTML = scope.getInnerHTML;
3367
- var getTreeScope = scope.getTreeScope;
3368
- var mixin = scope.mixin;
3369
- var rewrap = scope.rewrap;
3370
- var setInnerHTML = scope.setInnerHTML;
3371
- var unsafeUnwrap = scope.unsafeUnwrap;
3372
- var unwrap = scope.unwrap;
3373
- var wrap = scope.wrap;
3374
- var shadowHostTable = new WeakMap();
3375
- var nextOlderShadowTreeTable = new WeakMap();
3376
- function ShadowRoot(hostWrapper) {
3377
- var node = unwrap(unsafeUnwrap(hostWrapper).ownerDocument.createDocumentFragment());
3378
- DocumentFragment.call(this, node);
3379
- rewrap(node, this);
3380
- var oldShadowRoot = hostWrapper.shadowRoot;
3381
- nextOlderShadowTreeTable.set(this, oldShadowRoot);
3382
- this.treeScope_ = new TreeScope(this, getTreeScope(oldShadowRoot || hostWrapper));
3383
- shadowHostTable.set(this, hostWrapper);
3384
- }
3385
- ShadowRoot.prototype = Object.create(DocumentFragment.prototype);
3386
- mixin(ShadowRoot.prototype, {
3387
- constructor: ShadowRoot,
3388
- get innerHTML() {
3389
- return getInnerHTML(this);
3390
- },
3391
- set innerHTML(value) {
3392
- setInnerHTML(this, value);
3393
- this.invalidateShadowRenderer();
3394
- },
3395
- get olderShadowRoot() {
3396
- return nextOlderShadowTreeTable.get(this) || null;
3397
- },
3398
- get host() {
3399
- return shadowHostTable.get(this) || null;
3400
- },
3401
- invalidateShadowRenderer: function() {
3402
- return shadowHostTable.get(this).invalidateShadowRenderer();
3403
- },
3404
- elementFromPoint: function(x, y) {
3405
- return elementFromPoint(this, this.ownerDocument, x, y);
3406
- },
3407
- getSelection: function() {
3408
- return document.getSelection();
3409
- },
3410
- get activeElement() {
3411
- var unwrappedActiveElement = unwrap(this).ownerDocument.activeElement;
3412
- if (!unwrappedActiveElement || !unwrappedActiveElement.nodeType) return null;
3413
- var activeElement = wrap(unwrappedActiveElement);
3414
- if (activeElement === this.host) {
3415
- return null;
3416
- }
3417
- while (!this.contains(activeElement) && !this.host.contains(activeElement)) {
3418
- while (activeElement.parentNode) {
3419
- activeElement = activeElement.parentNode;
3420
- }
3421
- if (activeElement.host) {
3422
- activeElement = activeElement.host;
3423
- } else {
3424
- return null;
3425
- }
3426
- }
3427
- return activeElement;
3428
- }
3429
- });
3430
- scope.wrappers.ShadowRoot = ShadowRoot;
3431
- })(window.ShadowDOMPolyfill);
3432
-
3433
- (function(scope) {
3434
- "use strict";
3435
- var registerWrapper = scope.registerWrapper;
3436
- var setWrapper = scope.setWrapper;
3437
- var unsafeUnwrap = scope.unsafeUnwrap;
3438
- var unwrap = scope.unwrap;
3439
- var unwrapIfNeeded = scope.unwrapIfNeeded;
3440
- var wrap = scope.wrap;
3441
- var getTreeScope = scope.getTreeScope;
3442
- var OriginalRange = window.Range;
3443
- var ShadowRoot = scope.wrappers.ShadowRoot;
3444
- function getHost(node) {
3445
- var root = getTreeScope(node).root;
3446
- if (root instanceof ShadowRoot) {
3447
- return root.host;
3448
- }
3449
- return null;
3450
- }
3451
- function hostNodeToShadowNode(refNode, offset) {
3452
- if (refNode.shadowRoot) {
3453
- offset = Math.min(refNode.childNodes.length - 1, offset);
3454
- var child = refNode.childNodes[offset];
3455
- if (child) {
3456
- var insertionPoint = scope.getDestinationInsertionPoints(child);
3457
- if (insertionPoint.length > 0) {
3458
- var parentNode = insertionPoint[0].parentNode;
3459
- if (parentNode.nodeType == Node.ELEMENT_NODE) {
3460
- refNode = parentNode;
3461
- }
3462
- }
3463
- }
3464
- }
3465
- return refNode;
3466
- }
3467
- function shadowNodeToHostNode(node) {
3468
- node = wrap(node);
3469
- return getHost(node) || node;
3470
- }
3471
- function Range(impl) {
3472
- setWrapper(impl, this);
3473
- }
3474
- Range.prototype = {
3475
- get startContainer() {
3476
- return shadowNodeToHostNode(unsafeUnwrap(this).startContainer);
3477
- },
3478
- get endContainer() {
3479
- return shadowNodeToHostNode(unsafeUnwrap(this).endContainer);
3480
- },
3481
- get commonAncestorContainer() {
3482
- return shadowNodeToHostNode(unsafeUnwrap(this).commonAncestorContainer);
3483
- },
3484
- setStart: function(refNode, offset) {
3485
- refNode = hostNodeToShadowNode(refNode, offset);
3486
- unsafeUnwrap(this).setStart(unwrapIfNeeded(refNode), offset);
3487
- },
3488
- setEnd: function(refNode, offset) {
3489
- refNode = hostNodeToShadowNode(refNode, offset);
3490
- unsafeUnwrap(this).setEnd(unwrapIfNeeded(refNode), offset);
3491
- },
3492
- setStartBefore: function(refNode) {
3493
- unsafeUnwrap(this).setStartBefore(unwrapIfNeeded(refNode));
3494
- },
3495
- setStartAfter: function(refNode) {
3496
- unsafeUnwrap(this).setStartAfter(unwrapIfNeeded(refNode));
3497
- },
3498
- setEndBefore: function(refNode) {
3499
- unsafeUnwrap(this).setEndBefore(unwrapIfNeeded(refNode));
3500
- },
3501
- setEndAfter: function(refNode) {
3502
- unsafeUnwrap(this).setEndAfter(unwrapIfNeeded(refNode));
3503
- },
3504
- selectNode: function(refNode) {
3505
- unsafeUnwrap(this).selectNode(unwrapIfNeeded(refNode));
3506
- },
3507
- selectNodeContents: function(refNode) {
3508
- unsafeUnwrap(this).selectNodeContents(unwrapIfNeeded(refNode));
3509
- },
3510
- compareBoundaryPoints: function(how, sourceRange) {
3511
- return unsafeUnwrap(this).compareBoundaryPoints(how, unwrap(sourceRange));
3512
- },
3513
- extractContents: function() {
3514
- return wrap(unsafeUnwrap(this).extractContents());
3515
- },
3516
- cloneContents: function() {
3517
- return wrap(unsafeUnwrap(this).cloneContents());
3518
- },
3519
- insertNode: function(node) {
3520
- unsafeUnwrap(this).insertNode(unwrapIfNeeded(node));
3521
- },
3522
- surroundContents: function(newParent) {
3523
- unsafeUnwrap(this).surroundContents(unwrapIfNeeded(newParent));
3524
- },
3525
- cloneRange: function() {
3526
- return wrap(unsafeUnwrap(this).cloneRange());
3527
- },
3528
- isPointInRange: function(node, offset) {
3529
- return unsafeUnwrap(this).isPointInRange(unwrapIfNeeded(node), offset);
3530
- },
3531
- comparePoint: function(node, offset) {
3532
- return unsafeUnwrap(this).comparePoint(unwrapIfNeeded(node), offset);
3533
- },
3534
- intersectsNode: function(node) {
3535
- return unsafeUnwrap(this).intersectsNode(unwrapIfNeeded(node));
3536
- },
3537
- toString: function() {
3538
- return unsafeUnwrap(this).toString();
3539
- }
3540
- };
3541
- if (OriginalRange.prototype.createContextualFragment) {
3542
- Range.prototype.createContextualFragment = function(html) {
3543
- return wrap(unsafeUnwrap(this).createContextualFragment(html));
3544
- };
3545
- }
3546
- registerWrapper(window.Range, Range, document.createRange());
3547
- scope.wrappers.Range = Range;
3548
- })(window.ShadowDOMPolyfill);
3549
-
3550
- (function(scope) {
3551
- "use strict";
3552
- var Element = scope.wrappers.Element;
3553
- var HTMLContentElement = scope.wrappers.HTMLContentElement;
3554
- var HTMLShadowElement = scope.wrappers.HTMLShadowElement;
3555
- var Node = scope.wrappers.Node;
3556
- var ShadowRoot = scope.wrappers.ShadowRoot;
3557
- var assert = scope.assert;
3558
- var getTreeScope = scope.getTreeScope;
3559
- var mixin = scope.mixin;
3560
- var oneOf = scope.oneOf;
3561
- var unsafeUnwrap = scope.unsafeUnwrap;
3562
- var unwrap = scope.unwrap;
3563
- var wrap = scope.wrap;
3564
- var ArraySplice = scope.ArraySplice;
3565
- function updateWrapperUpAndSideways(wrapper) {
3566
- wrapper.previousSibling_ = wrapper.previousSibling;
3567
- wrapper.nextSibling_ = wrapper.nextSibling;
3568
- wrapper.parentNode_ = wrapper.parentNode;
3569
- }
3570
- function updateWrapperDown(wrapper) {
3571
- wrapper.firstChild_ = wrapper.firstChild;
3572
- wrapper.lastChild_ = wrapper.lastChild;
3573
- }
3574
- function updateAllChildNodes(parentNodeWrapper) {
3575
- assert(parentNodeWrapper instanceof Node);
3576
- for (var childWrapper = parentNodeWrapper.firstChild; childWrapper; childWrapper = childWrapper.nextSibling) {
3577
- updateWrapperUpAndSideways(childWrapper);
3578
- }
3579
- updateWrapperDown(parentNodeWrapper);
3580
- }
3581
- function insertBefore(parentNodeWrapper, newChildWrapper, refChildWrapper) {
3582
- var parentNode = unwrap(parentNodeWrapper);
3583
- var newChild = unwrap(newChildWrapper);
3584
- var refChild = refChildWrapper ? unwrap(refChildWrapper) : null;
3585
- remove(newChildWrapper);
3586
- updateWrapperUpAndSideways(newChildWrapper);
3587
- if (!refChildWrapper) {
3588
- parentNodeWrapper.lastChild_ = parentNodeWrapper.lastChild;
3589
- if (parentNodeWrapper.lastChild === parentNodeWrapper.firstChild) parentNodeWrapper.firstChild_ = parentNodeWrapper.firstChild;
3590
- var lastChildWrapper = wrap(parentNode.lastChild);
3591
- if (lastChildWrapper) lastChildWrapper.nextSibling_ = lastChildWrapper.nextSibling;
3592
- } else {
3593
- if (parentNodeWrapper.firstChild === refChildWrapper) parentNodeWrapper.firstChild_ = refChildWrapper;
3594
- refChildWrapper.previousSibling_ = refChildWrapper.previousSibling;
3595
- }
3596
- scope.originalInsertBefore.call(parentNode, newChild, refChild);
3597
- }
3598
- function remove(nodeWrapper) {
3599
- var node = unwrap(nodeWrapper);
3600
- var parentNode = node.parentNode;
3601
- if (!parentNode) return;
3602
- var parentNodeWrapper = wrap(parentNode);
3603
- updateWrapperUpAndSideways(nodeWrapper);
3604
- if (nodeWrapper.previousSibling) nodeWrapper.previousSibling.nextSibling_ = nodeWrapper;
3605
- if (nodeWrapper.nextSibling) nodeWrapper.nextSibling.previousSibling_ = nodeWrapper;
3606
- if (parentNodeWrapper.lastChild === nodeWrapper) parentNodeWrapper.lastChild_ = nodeWrapper;
3607
- if (parentNodeWrapper.firstChild === nodeWrapper) parentNodeWrapper.firstChild_ = nodeWrapper;
3608
- scope.originalRemoveChild.call(parentNode, node);
3609
- }
3610
- var distributedNodesTable = new WeakMap();
3611
- var destinationInsertionPointsTable = new WeakMap();
3612
- var rendererForHostTable = new WeakMap();
3613
- function resetDistributedNodes(insertionPoint) {
3614
- distributedNodesTable.set(insertionPoint, []);
3615
- }
3616
- function getDistributedNodes(insertionPoint) {
3617
- var rv = distributedNodesTable.get(insertionPoint);
3618
- if (!rv) distributedNodesTable.set(insertionPoint, rv = []);
3619
- return rv;
3620
- }
3621
- function getChildNodesSnapshot(node) {
3622
- var result = [], i = 0;
3623
- for (var child = node.firstChild; child; child = child.nextSibling) {
3624
- result[i++] = child;
3625
- }
3626
- return result;
3627
- }
3628
- var request = oneOf(window, [ "requestAnimationFrame", "mozRequestAnimationFrame", "webkitRequestAnimationFrame", "setTimeout" ]);
3629
- var pendingDirtyRenderers = [];
3630
- var renderTimer;
3631
- function renderAllPending() {
3632
- for (var i = 0; i < pendingDirtyRenderers.length; i++) {
3633
- var renderer = pendingDirtyRenderers[i];
3634
- var parentRenderer = renderer.parentRenderer;
3635
- if (parentRenderer && parentRenderer.dirty) continue;
3636
- renderer.render();
3637
- }
3638
- pendingDirtyRenderers = [];
3639
- }
3640
- function handleRequestAnimationFrame() {
3641
- renderTimer = null;
3642
- renderAllPending();
3643
- }
3644
- function getRendererForHost(host) {
3645
- var renderer = rendererForHostTable.get(host);
3646
- if (!renderer) {
3647
- renderer = new ShadowRenderer(host);
3648
- rendererForHostTable.set(host, renderer);
3649
- }
3650
- return renderer;
3651
- }
3652
- function getShadowRootAncestor(node) {
3653
- var root = getTreeScope(node).root;
3654
- if (root instanceof ShadowRoot) return root;
3655
- return null;
3656
- }
3657
- function getRendererForShadowRoot(shadowRoot) {
3658
- return getRendererForHost(shadowRoot.host);
3659
- }
3660
- var spliceDiff = new ArraySplice();
3661
- spliceDiff.equals = function(renderNode, rawNode) {
3662
- return unwrap(renderNode.node) === rawNode;
3663
- };
3664
- function RenderNode(node) {
3665
- this.skip = false;
3666
- this.node = node;
3667
- this.childNodes = [];
3668
- }
3669
- RenderNode.prototype = {
3670
- append: function(node) {
3671
- var rv = new RenderNode(node);
3672
- this.childNodes.push(rv);
3673
- return rv;
3674
- },
3675
- sync: function(opt_added) {
3676
- if (this.skip) return;
3677
- var nodeWrapper = this.node;
3678
- var newChildren = this.childNodes;
3679
- var oldChildren = getChildNodesSnapshot(unwrap(nodeWrapper));
3680
- var added = opt_added || new WeakMap();
3681
- var splices = spliceDiff.calculateSplices(newChildren, oldChildren);
3682
- var newIndex = 0, oldIndex = 0;
3683
- var lastIndex = 0;
3684
- for (var i = 0; i < splices.length; i++) {
3685
- var splice = splices[i];
3686
- for (;lastIndex < splice.index; lastIndex++) {
3687
- oldIndex++;
3688
- newChildren[newIndex++].sync(added);
3689
- }
3690
- var removedCount = splice.removed.length;
3691
- for (var j = 0; j < removedCount; j++) {
3692
- var wrapper = wrap(oldChildren[oldIndex++]);
3693
- if (!added.get(wrapper)) remove(wrapper);
3694
- }
3695
- var addedCount = splice.addedCount;
3696
- var refNode = oldChildren[oldIndex] && wrap(oldChildren[oldIndex]);
3697
- for (var j = 0; j < addedCount; j++) {
3698
- var newChildRenderNode = newChildren[newIndex++];
3699
- var newChildWrapper = newChildRenderNode.node;
3700
- insertBefore(nodeWrapper, newChildWrapper, refNode);
3701
- added.set(newChildWrapper, true);
3702
- newChildRenderNode.sync(added);
3703
- }
3704
- lastIndex += addedCount;
3705
- }
3706
- for (var i = lastIndex; i < newChildren.length; i++) {
3707
- newChildren[i].sync(added);
3708
- }
3709
- }
3710
- };
3711
- function ShadowRenderer(host) {
3712
- this.host = host;
3713
- this.dirty = false;
3714
- this.invalidateAttributes();
3715
- this.associateNode(host);
3716
- }
3717
- ShadowRenderer.prototype = {
3718
- render: function(opt_renderNode) {
3719
- if (!this.dirty) return;
3720
- this.invalidateAttributes();
3721
- var host = this.host;
3722
- this.distribution(host);
3723
- var renderNode = opt_renderNode || new RenderNode(host);
3724
- this.buildRenderTree(renderNode, host);
3725
- var topMostRenderer = !opt_renderNode;
3726
- if (topMostRenderer) renderNode.sync();
3727
- this.dirty = false;
3728
- },
3729
- get parentRenderer() {
3730
- return getTreeScope(this.host).renderer;
3731
- },
3732
- invalidate: function() {
3733
- if (!this.dirty) {
3734
- this.dirty = true;
3735
- var parentRenderer = this.parentRenderer;
3736
- if (parentRenderer) parentRenderer.invalidate();
3737
- pendingDirtyRenderers.push(this);
3738
- if (renderTimer) return;
3739
- renderTimer = window[request](handleRequestAnimationFrame, 0);
3740
- }
3741
- },
3742
- distribution: function(root) {
3743
- this.resetAllSubtrees(root);
3744
- this.distributionResolution(root);
3745
- },
3746
- resetAll: function(node) {
3747
- if (isInsertionPoint(node)) resetDistributedNodes(node); else resetDestinationInsertionPoints(node);
3748
- this.resetAllSubtrees(node);
3749
- },
3750
- resetAllSubtrees: function(node) {
3751
- for (var child = node.firstChild; child; child = child.nextSibling) {
3752
- this.resetAll(child);
3753
- }
3754
- if (node.shadowRoot) this.resetAll(node.shadowRoot);
3755
- if (node.olderShadowRoot) this.resetAll(node.olderShadowRoot);
3756
- },
3757
- distributionResolution: function(node) {
3758
- if (isShadowHost(node)) {
3759
- var shadowHost = node;
3760
- var pool = poolPopulation(shadowHost);
3761
- var shadowTrees = getShadowTrees(shadowHost);
3762
- for (var i = 0; i < shadowTrees.length; i++) {
3763
- this.poolDistribution(shadowTrees[i], pool);
3764
- }
3765
- for (var i = shadowTrees.length - 1; i >= 0; i--) {
3766
- var shadowTree = shadowTrees[i];
3767
- var shadow = getShadowInsertionPoint(shadowTree);
3768
- if (shadow) {
3769
- var olderShadowRoot = shadowTree.olderShadowRoot;
3770
- if (olderShadowRoot) {
3771
- pool = poolPopulation(olderShadowRoot);
3772
- }
3773
- for (var j = 0; j < pool.length; j++) {
3774
- destributeNodeInto(pool[j], shadow);
3775
- }
3776
- }
3777
- this.distributionResolution(shadowTree);
3778
- }
3779
- }
3780
- for (var child = node.firstChild; child; child = child.nextSibling) {
3781
- this.distributionResolution(child);
3782
- }
3783
- },
3784
- poolDistribution: function(node, pool) {
3785
- if (node instanceof HTMLShadowElement) return;
3786
- if (node instanceof HTMLContentElement) {
3787
- var content = node;
3788
- this.updateDependentAttributes(content.getAttribute("select"));
3789
- var anyDistributed = false;
3790
- for (var i = 0; i < pool.length; i++) {
3791
- var node = pool[i];
3792
- if (!node) continue;
3793
- if (matches(node, content)) {
3794
- destributeNodeInto(node, content);
3795
- pool[i] = undefined;
3796
- anyDistributed = true;
3797
- }
3798
- }
3799
- if (!anyDistributed) {
3800
- for (var child = content.firstChild; child; child = child.nextSibling) {
3801
- destributeNodeInto(child, content);
3802
- }
3803
- }
3804
- return;
3805
- }
3806
- for (var child = node.firstChild; child; child = child.nextSibling) {
3807
- this.poolDistribution(child, pool);
3808
- }
3809
- },
3810
- buildRenderTree: function(renderNode, node) {
3811
- var children = this.compose(node);
3812
- for (var i = 0; i < children.length; i++) {
3813
- var child = children[i];
3814
- var childRenderNode = renderNode.append(child);
3815
- this.buildRenderTree(childRenderNode, child);
3816
- }
3817
- if (isShadowHost(node)) {
3818
- var renderer = getRendererForHost(node);
3819
- renderer.dirty = false;
3820
- }
3821
- },
3822
- compose: function(node) {
3823
- var children = [];
3824
- var p = node.shadowRoot || node;
3825
- for (var child = p.firstChild; child; child = child.nextSibling) {
3826
- if (isInsertionPoint(child)) {
3827
- this.associateNode(p);
3828
- var distributedNodes = getDistributedNodes(child);
3829
- for (var j = 0; j < distributedNodes.length; j++) {
3830
- var distributedNode = distributedNodes[j];
3831
- if (isFinalDestination(child, distributedNode)) children.push(distributedNode);
3832
- }
3833
- } else {
3834
- children.push(child);
3835
- }
3836
- }
3837
- return children;
3838
- },
3839
- invalidateAttributes: function() {
3840
- this.attributes = Object.create(null);
3841
- },
3842
- updateDependentAttributes: function(selector) {
3843
- if (!selector) return;
3844
- var attributes = this.attributes;
3845
- if (/\.\w+/.test(selector)) attributes["class"] = true;
3846
- if (/#\w+/.test(selector)) attributes["id"] = true;
3847
- selector.replace(/\[\s*([^\s=\|~\]]+)/g, function(_, name) {
3848
- attributes[name] = true;
3849
- });
3850
- },
3851
- dependsOnAttribute: function(name) {
3852
- return this.attributes[name];
3853
- },
3854
- associateNode: function(node) {
3855
- unsafeUnwrap(node).polymerShadowRenderer_ = this;
3856
- }
3857
- };
3858
- function poolPopulation(node) {
3859
- var pool = [];
3860
- for (var child = node.firstChild; child; child = child.nextSibling) {
3861
- if (isInsertionPoint(child)) {
3862
- pool.push.apply(pool, getDistributedNodes(child));
3863
- } else {
3864
- pool.push(child);
3865
- }
3866
- }
3867
- return pool;
3868
- }
3869
- function getShadowInsertionPoint(node) {
3870
- if (node instanceof HTMLShadowElement) return node;
3871
- if (node instanceof HTMLContentElement) return null;
3872
- for (var child = node.firstChild; child; child = child.nextSibling) {
3873
- var res = getShadowInsertionPoint(child);
3874
- if (res) return res;
3875
- }
3876
- return null;
3877
- }
3878
- function destributeNodeInto(child, insertionPoint) {
3879
- getDistributedNodes(insertionPoint).push(child);
3880
- var points = destinationInsertionPointsTable.get(child);
3881
- if (!points) destinationInsertionPointsTable.set(child, [ insertionPoint ]); else points.push(insertionPoint);
3882
- }
3883
- function getDestinationInsertionPoints(node) {
3884
- return destinationInsertionPointsTable.get(node);
3885
- }
3886
- function resetDestinationInsertionPoints(node) {
3887
- destinationInsertionPointsTable.set(node, undefined);
3888
- }
3889
- var selectorStartCharRe = /^(:not\()?[*.#[a-zA-Z_|]/;
3890
- function matches(node, contentElement) {
3891
- var select = contentElement.getAttribute("select");
3892
- if (!select) return true;
3893
- select = select.trim();
3894
- if (!select) return true;
3895
- if (!(node instanceof Element)) return false;
3896
- if (!selectorStartCharRe.test(select)) return false;
3897
- try {
3898
- return node.matches(select);
3899
- } catch (ex) {
3900
- return false;
3901
- }
3902
- }
3903
- function isFinalDestination(insertionPoint, node) {
3904
- var points = getDestinationInsertionPoints(node);
3905
- return points && points[points.length - 1] === insertionPoint;
3906
- }
3907
- function isInsertionPoint(node) {
3908
- return node instanceof HTMLContentElement || node instanceof HTMLShadowElement;
3909
- }
3910
- function isShadowHost(shadowHost) {
3911
- return shadowHost.shadowRoot;
3912
- }
3913
- function getShadowTrees(host) {
3914
- var trees = [];
3915
- for (var tree = host.shadowRoot; tree; tree = tree.olderShadowRoot) {
3916
- trees.push(tree);
3917
- }
3918
- return trees;
3919
- }
3920
- function render(host) {
3921
- new ShadowRenderer(host).render();
3922
- }
3923
- Node.prototype.invalidateShadowRenderer = function(force) {
3924
- var renderer = unsafeUnwrap(this).polymerShadowRenderer_;
3925
- if (renderer) {
3926
- renderer.invalidate();
3927
- return true;
3928
- }
3929
- return false;
3930
- };
3931
- HTMLContentElement.prototype.getDistributedNodes = HTMLShadowElement.prototype.getDistributedNodes = function() {
3932
- renderAllPending();
3933
- return getDistributedNodes(this);
3934
- };
3935
- Element.prototype.getDestinationInsertionPoints = function() {
3936
- renderAllPending();
3937
- return getDestinationInsertionPoints(this) || [];
3938
- };
3939
- HTMLContentElement.prototype.nodeIsInserted_ = HTMLShadowElement.prototype.nodeIsInserted_ = function() {
3940
- this.invalidateShadowRenderer();
3941
- var shadowRoot = getShadowRootAncestor(this);
3942
- var renderer;
3943
- if (shadowRoot) renderer = getRendererForShadowRoot(shadowRoot);
3944
- unsafeUnwrap(this).polymerShadowRenderer_ = renderer;
3945
- if (renderer) renderer.invalidate();
3946
- };
3947
- scope.getRendererForHost = getRendererForHost;
3948
- scope.getShadowTrees = getShadowTrees;
3949
- scope.renderAllPending = renderAllPending;
3950
- scope.getDestinationInsertionPoints = getDestinationInsertionPoints;
3951
- scope.visual = {
3952
- insertBefore: insertBefore,
3953
- remove: remove
3954
- };
3955
- })(window.ShadowDOMPolyfill);
3956
-
3957
- (function(scope) {
3958
- "use strict";
3959
- var HTMLElement = scope.wrappers.HTMLElement;
3960
- var assert = scope.assert;
3961
- var mixin = scope.mixin;
3962
- var registerWrapper = scope.registerWrapper;
3963
- var unwrap = scope.unwrap;
3964
- var wrap = scope.wrap;
3965
- var elementsWithFormProperty = [ "HTMLButtonElement", "HTMLFieldSetElement", "HTMLInputElement", "HTMLKeygenElement", "HTMLLabelElement", "HTMLLegendElement", "HTMLObjectElement", "HTMLOutputElement", "HTMLTextAreaElement" ];
3966
- function createWrapperConstructor(name) {
3967
- if (!window[name]) return;
3968
- assert(!scope.wrappers[name]);
3969
- var GeneratedWrapper = function(node) {
3970
- HTMLElement.call(this, node);
3971
- };
3972
- GeneratedWrapper.prototype = Object.create(HTMLElement.prototype);
3973
- mixin(GeneratedWrapper.prototype, {
3974
- get form() {
3975
- return wrap(unwrap(this).form);
3976
- }
3977
- });
3978
- registerWrapper(window[name], GeneratedWrapper, document.createElement(name.slice(4, -7)));
3979
- scope.wrappers[name] = GeneratedWrapper;
3980
- }
3981
- elementsWithFormProperty.forEach(createWrapperConstructor);
3982
- })(window.ShadowDOMPolyfill);
3983
-
3984
- (function(scope) {
3985
- "use strict";
3986
- var registerWrapper = scope.registerWrapper;
3987
- var setWrapper = scope.setWrapper;
3988
- var unsafeUnwrap = scope.unsafeUnwrap;
3989
- var unwrap = scope.unwrap;
3990
- var unwrapIfNeeded = scope.unwrapIfNeeded;
3991
- var wrap = scope.wrap;
3992
- var OriginalSelection = window.Selection;
3993
- function Selection(impl) {
3994
- setWrapper(impl, this);
3995
- }
3996
- Selection.prototype = {
3997
- get anchorNode() {
3998
- return wrap(unsafeUnwrap(this).anchorNode);
3999
- },
4000
- get focusNode() {
4001
- return wrap(unsafeUnwrap(this).focusNode);
4002
- },
4003
- addRange: function(range) {
4004
- unsafeUnwrap(this).addRange(unwrapIfNeeded(range));
4005
- },
4006
- collapse: function(node, index) {
4007
- unsafeUnwrap(this).collapse(unwrapIfNeeded(node), index);
4008
- },
4009
- containsNode: function(node, allowPartial) {
4010
- return unsafeUnwrap(this).containsNode(unwrapIfNeeded(node), allowPartial);
4011
- },
4012
- getRangeAt: function(index) {
4013
- return wrap(unsafeUnwrap(this).getRangeAt(index));
4014
- },
4015
- removeRange: function(range) {
4016
- unsafeUnwrap(this).removeRange(unwrap(range));
4017
- },
4018
- selectAllChildren: function(node) {
4019
- unsafeUnwrap(this).selectAllChildren(node instanceof ShadowRoot ? unsafeUnwrap(node.host) : unwrapIfNeeded(node));
4020
- },
4021
- toString: function() {
4022
- return unsafeUnwrap(this).toString();
4023
- }
4024
- };
4025
- if (OriginalSelection.prototype.extend) {
4026
- Selection.prototype.extend = function(node, offset) {
4027
- unsafeUnwrap(this).extend(unwrapIfNeeded(node), offset);
4028
- };
4029
- }
4030
- registerWrapper(window.Selection, Selection, window.getSelection());
4031
- scope.wrappers.Selection = Selection;
4032
- })(window.ShadowDOMPolyfill);
4033
-
4034
- (function(scope) {
4035
- "use strict";
4036
- var registerWrapper = scope.registerWrapper;
4037
- var setWrapper = scope.setWrapper;
4038
- var unsafeUnwrap = scope.unsafeUnwrap;
4039
- var unwrapIfNeeded = scope.unwrapIfNeeded;
4040
- var wrap = scope.wrap;
4041
- var OriginalTreeWalker = window.TreeWalker;
4042
- function TreeWalker(impl) {
4043
- setWrapper(impl, this);
4044
- }
4045
- TreeWalker.prototype = {
4046
- get root() {
4047
- return wrap(unsafeUnwrap(this).root);
4048
- },
4049
- get currentNode() {
4050
- return wrap(unsafeUnwrap(this).currentNode);
4051
- },
4052
- set currentNode(node) {
4053
- unsafeUnwrap(this).currentNode = unwrapIfNeeded(node);
4054
- },
4055
- get filter() {
4056
- return unsafeUnwrap(this).filter;
4057
- },
4058
- parentNode: function() {
4059
- return wrap(unsafeUnwrap(this).parentNode());
4060
- },
4061
- firstChild: function() {
4062
- return wrap(unsafeUnwrap(this).firstChild());
4063
- },
4064
- lastChild: function() {
4065
- return wrap(unsafeUnwrap(this).lastChild());
4066
- },
4067
- previousSibling: function() {
4068
- return wrap(unsafeUnwrap(this).previousSibling());
4069
- },
4070
- previousNode: function() {
4071
- return wrap(unsafeUnwrap(this).previousNode());
4072
- },
4073
- nextNode: function() {
4074
- return wrap(unsafeUnwrap(this).nextNode());
4075
- }
4076
- };
4077
- registerWrapper(OriginalTreeWalker, TreeWalker);
4078
- scope.wrappers.TreeWalker = TreeWalker;
4079
- })(window.ShadowDOMPolyfill);
4080
-
4081
- (function(scope) {
4082
- "use strict";
4083
- var GetElementsByInterface = scope.GetElementsByInterface;
4084
- var Node = scope.wrappers.Node;
4085
- var ParentNodeInterface = scope.ParentNodeInterface;
4086
- var NonElementParentNodeInterface = scope.NonElementParentNodeInterface;
4087
- var Selection = scope.wrappers.Selection;
4088
- var SelectorsInterface = scope.SelectorsInterface;
4089
- var ShadowRoot = scope.wrappers.ShadowRoot;
4090
- var TreeScope = scope.TreeScope;
4091
- var cloneNode = scope.cloneNode;
4092
- var defineGetter = scope.defineGetter;
4093
- var defineWrapGetter = scope.defineWrapGetter;
4094
- var elementFromPoint = scope.elementFromPoint;
4095
- var forwardMethodsToWrapper = scope.forwardMethodsToWrapper;
4096
- var matchesNames = scope.matchesNames;
4097
- var mixin = scope.mixin;
4098
- var registerWrapper = scope.registerWrapper;
4099
- var renderAllPending = scope.renderAllPending;
4100
- var rewrap = scope.rewrap;
4101
- var setWrapper = scope.setWrapper;
4102
- var unsafeUnwrap = scope.unsafeUnwrap;
4103
- var unwrap = scope.unwrap;
4104
- var wrap = scope.wrap;
4105
- var wrapEventTargetMethods = scope.wrapEventTargetMethods;
4106
- var wrapNodeList = scope.wrapNodeList;
4107
- var implementationTable = new WeakMap();
4108
- function Document(node) {
4109
- Node.call(this, node);
4110
- this.treeScope_ = new TreeScope(this, null);
4111
- }
4112
- Document.prototype = Object.create(Node.prototype);
4113
- defineWrapGetter(Document, "documentElement");
4114
- defineWrapGetter(Document, "body");
4115
- defineWrapGetter(Document, "head");
4116
- defineGetter(Document, "activeElement", function() {
4117
- var unwrappedActiveElement = unwrap(this).activeElement;
4118
- if (!unwrappedActiveElement || !unwrappedActiveElement.nodeType) return null;
4119
- var activeElement = wrap(unwrappedActiveElement);
4120
- while (!this.contains(activeElement)) {
4121
- while (activeElement.parentNode) {
4122
- activeElement = activeElement.parentNode;
4123
- }
4124
- if (activeElement.host) {
4125
- activeElement = activeElement.host;
4126
- } else {
4127
- return null;
4128
- }
4129
- }
4130
- return activeElement;
4131
- });
4132
- function wrapMethod(name) {
4133
- var original = document[name];
4134
- Document.prototype[name] = function() {
4135
- return wrap(original.apply(unsafeUnwrap(this), arguments));
4136
- };
4137
- }
4138
- [ "createComment", "createDocumentFragment", "createElement", "createElementNS", "createEvent", "createEventNS", "createRange", "createTextNode" ].forEach(wrapMethod);
4139
- var originalAdoptNode = document.adoptNode;
4140
- function adoptNodeNoRemove(node, doc) {
4141
- originalAdoptNode.call(unsafeUnwrap(doc), unwrap(node));
4142
- adoptSubtree(node, doc);
4143
- }
4144
- function adoptSubtree(node, doc) {
4145
- if (node.shadowRoot) doc.adoptNode(node.shadowRoot);
4146
- if (node instanceof ShadowRoot) adoptOlderShadowRoots(node, doc);
4147
- for (var child = node.firstChild; child; child = child.nextSibling) {
4148
- adoptSubtree(child, doc);
4149
- }
4150
- }
4151
- function adoptOlderShadowRoots(shadowRoot, doc) {
4152
- var oldShadowRoot = shadowRoot.olderShadowRoot;
4153
- if (oldShadowRoot) doc.adoptNode(oldShadowRoot);
4154
- }
4155
- var originalGetSelection = document.getSelection;
4156
- mixin(Document.prototype, {
4157
- adoptNode: function(node) {
4158
- if (node.parentNode) node.parentNode.removeChild(node);
4159
- adoptNodeNoRemove(node, this);
4160
- return node;
4161
- },
4162
- elementFromPoint: function(x, y) {
4163
- return elementFromPoint(this, this, x, y);
4164
- },
4165
- importNode: function(node, deep) {
4166
- return cloneNode(node, deep, unsafeUnwrap(this));
4167
- },
4168
- getSelection: function() {
4169
- renderAllPending();
4170
- return new Selection(originalGetSelection.call(unwrap(this)));
4171
- },
4172
- getElementsByName: function(name) {
4173
- return SelectorsInterface.querySelectorAll.call(this, "[name=" + JSON.stringify(String(name)) + "]");
4174
- }
4175
- });
4176
- var originalCreateTreeWalker = document.createTreeWalker;
4177
- var TreeWalkerWrapper = scope.wrappers.TreeWalker;
4178
- Document.prototype.createTreeWalker = function(root, whatToShow, filter, expandEntityReferences) {
4179
- var newFilter = null;
4180
- if (filter) {
4181
- if (filter.acceptNode && typeof filter.acceptNode === "function") {
4182
- newFilter = {
4183
- acceptNode: function(node) {
4184
- return filter.acceptNode(wrap(node));
4185
- }
4186
- };
4187
- } else if (typeof filter === "function") {
4188
- newFilter = function(node) {
4189
- return filter(wrap(node));
4190
- };
4191
- }
4192
- }
4193
- return new TreeWalkerWrapper(originalCreateTreeWalker.call(unwrap(this), unwrap(root), whatToShow, newFilter, expandEntityReferences));
4194
- };
4195
- if (document.registerElement) {
4196
- var originalRegisterElement = document.registerElement;
4197
- Document.prototype.registerElement = function(tagName, object) {
4198
- var prototype, extendsOption;
4199
- if (object !== undefined) {
4200
- prototype = object.prototype;
4201
- extendsOption = object.extends;
4202
- }
4203
- if (!prototype) prototype = Object.create(HTMLElement.prototype);
4204
- if (scope.nativePrototypeTable.get(prototype)) {
4205
- throw new Error("NotSupportedError");
4206
- }
4207
- var proto = Object.getPrototypeOf(prototype);
4208
- var nativePrototype;
4209
- var prototypes = [];
4210
- while (proto) {
4211
- nativePrototype = scope.nativePrototypeTable.get(proto);
4212
- if (nativePrototype) break;
4213
- prototypes.push(proto);
4214
- proto = Object.getPrototypeOf(proto);
4215
- }
4216
- if (!nativePrototype) {
4217
- throw new Error("NotSupportedError");
4218
- }
4219
- var newPrototype = Object.create(nativePrototype);
4220
- for (var i = prototypes.length - 1; i >= 0; i--) {
4221
- newPrototype = Object.create(newPrototype);
4222
- }
4223
- [ "createdCallback", "attachedCallback", "detachedCallback", "attributeChangedCallback" ].forEach(function(name) {
4224
- var f = prototype[name];
4225
- if (!f) return;
4226
- newPrototype[name] = function() {
4227
- if (!(wrap(this) instanceof CustomElementConstructor)) {
4228
- rewrap(this);
4229
- }
4230
- f.apply(wrap(this), arguments);
4231
- };
4232
- });
4233
- var p = {
4234
- prototype: newPrototype
4235
- };
4236
- if (extendsOption) p.extends = extendsOption;
4237
- function CustomElementConstructor(node) {
4238
- if (!node) {
4239
- if (extendsOption) {
4240
- return document.createElement(extendsOption, tagName);
4241
- } else {
4242
- return document.createElement(tagName);
4243
- }
4244
- }
4245
- setWrapper(node, this);
4246
- }
4247
- CustomElementConstructor.prototype = prototype;
4248
- CustomElementConstructor.prototype.constructor = CustomElementConstructor;
4249
- scope.constructorTable.set(newPrototype, CustomElementConstructor);
4250
- scope.nativePrototypeTable.set(prototype, newPrototype);
4251
- var nativeConstructor = originalRegisterElement.call(unwrap(this), tagName, p);
4252
- return CustomElementConstructor;
4253
- };
4254
- forwardMethodsToWrapper([ window.HTMLDocument || window.Document ], [ "registerElement" ]);
4255
- }
4256
- forwardMethodsToWrapper([ window.HTMLBodyElement, window.HTMLDocument || window.Document, window.HTMLHeadElement, window.HTMLHtmlElement ], [ "appendChild", "compareDocumentPosition", "contains", "getElementsByClassName", "getElementsByTagName", "getElementsByTagNameNS", "insertBefore", "querySelector", "querySelectorAll", "removeChild", "replaceChild" ]);
4257
- forwardMethodsToWrapper([ window.HTMLBodyElement, window.HTMLHeadElement, window.HTMLHtmlElement ], matchesNames);
4258
- forwardMethodsToWrapper([ window.HTMLDocument || window.Document ], [ "adoptNode", "importNode", "contains", "createComment", "createDocumentFragment", "createElement", "createElementNS", "createEvent", "createEventNS", "createRange", "createTextNode", "createTreeWalker", "elementFromPoint", "getElementById", "getElementsByName", "getSelection" ]);
4259
- mixin(Document.prototype, GetElementsByInterface);
4260
- mixin(Document.prototype, ParentNodeInterface);
4261
- mixin(Document.prototype, SelectorsInterface);
4262
- mixin(Document.prototype, NonElementParentNodeInterface);
4263
- mixin(Document.prototype, {
4264
- get implementation() {
4265
- var implementation = implementationTable.get(this);
4266
- if (implementation) return implementation;
4267
- implementation = new DOMImplementation(unwrap(this).implementation);
4268
- implementationTable.set(this, implementation);
4269
- return implementation;
4270
- },
4271
- get defaultView() {
4272
- return wrap(unwrap(this).defaultView);
4273
- }
4274
- });
4275
- registerWrapper(window.Document, Document, document.implementation.createHTMLDocument(""));
4276
- if (window.HTMLDocument) registerWrapper(window.HTMLDocument, Document);
4277
- wrapEventTargetMethods([ window.HTMLBodyElement, window.HTMLDocument || window.Document, window.HTMLHeadElement ]);
4278
- function DOMImplementation(impl) {
4279
- setWrapper(impl, this);
4280
- }
4281
- var originalCreateDocument = document.implementation.createDocument;
4282
- DOMImplementation.prototype.createDocument = function() {
4283
- arguments[2] = unwrap(arguments[2]);
4284
- return wrap(originalCreateDocument.apply(unsafeUnwrap(this), arguments));
4285
- };
4286
- function wrapImplMethod(constructor, name) {
4287
- var original = document.implementation[name];
4288
- constructor.prototype[name] = function() {
4289
- return wrap(original.apply(unsafeUnwrap(this), arguments));
4290
- };
4291
- }
4292
- function forwardImplMethod(constructor, name) {
4293
- var original = document.implementation[name];
4294
- constructor.prototype[name] = function() {
4295
- return original.apply(unsafeUnwrap(this), arguments);
4296
- };
4297
- }
4298
- wrapImplMethod(DOMImplementation, "createDocumentType");
4299
- wrapImplMethod(DOMImplementation, "createHTMLDocument");
4300
- forwardImplMethod(DOMImplementation, "hasFeature");
4301
- registerWrapper(window.DOMImplementation, DOMImplementation);
4302
- forwardMethodsToWrapper([ window.DOMImplementation ], [ "createDocument", "createDocumentType", "createHTMLDocument", "hasFeature" ]);
4303
- scope.adoptNodeNoRemove = adoptNodeNoRemove;
4304
- scope.wrappers.DOMImplementation = DOMImplementation;
4305
- scope.wrappers.Document = Document;
4306
- })(window.ShadowDOMPolyfill);
4307
-
4308
- (function(scope) {
4309
- "use strict";
4310
- var EventTarget = scope.wrappers.EventTarget;
4311
- var Selection = scope.wrappers.Selection;
4312
- var mixin = scope.mixin;
4313
- var registerWrapper = scope.registerWrapper;
4314
- var renderAllPending = scope.renderAllPending;
4315
- var unwrap = scope.unwrap;
4316
- var unwrapIfNeeded = scope.unwrapIfNeeded;
4317
- var wrap = scope.wrap;
4318
- var OriginalWindow = window.Window;
4319
- var originalGetComputedStyle = window.getComputedStyle;
4320
- var originalGetDefaultComputedStyle = window.getDefaultComputedStyle;
4321
- var originalGetSelection = window.getSelection;
4322
- function Window(impl) {
4323
- EventTarget.call(this, impl);
4324
- }
4325
- Window.prototype = Object.create(EventTarget.prototype);
4326
- OriginalWindow.prototype.getComputedStyle = function(el, pseudo) {
4327
- return wrap(this || window).getComputedStyle(unwrapIfNeeded(el), pseudo);
4328
- };
4329
- if (originalGetDefaultComputedStyle) {
4330
- OriginalWindow.prototype.getDefaultComputedStyle = function(el, pseudo) {
4331
- return wrap(this || window).getDefaultComputedStyle(unwrapIfNeeded(el), pseudo);
4332
- };
4333
- }
4334
- OriginalWindow.prototype.getSelection = function() {
4335
- return wrap(this || window).getSelection();
4336
- };
4337
- delete window.getComputedStyle;
4338
- delete window.getDefaultComputedStyle;
4339
- delete window.getSelection;
4340
- [ "addEventListener", "removeEventListener", "dispatchEvent" ].forEach(function(name) {
4341
- OriginalWindow.prototype[name] = function() {
4342
- var w = wrap(this || window);
4343
- return w[name].apply(w, arguments);
4344
- };
4345
- delete window[name];
4346
- });
4347
- mixin(Window.prototype, {
4348
- getComputedStyle: function(el, pseudo) {
4349
- renderAllPending();
4350
- return originalGetComputedStyle.call(unwrap(this), unwrapIfNeeded(el), pseudo);
4351
- },
4352
- getSelection: function() {
4353
- renderAllPending();
4354
- return new Selection(originalGetSelection.call(unwrap(this)));
4355
- },
4356
- get document() {
4357
- return wrap(unwrap(this).document);
4358
- }
4359
- });
4360
- if (originalGetDefaultComputedStyle) {
4361
- Window.prototype.getDefaultComputedStyle = function(el, pseudo) {
4362
- renderAllPending();
4363
- return originalGetDefaultComputedStyle.call(unwrap(this), unwrapIfNeeded(el), pseudo);
4364
- };
4365
- }
4366
- registerWrapper(OriginalWindow, Window, window);
4367
- scope.wrappers.Window = Window;
4368
- })(window.ShadowDOMPolyfill);
4369
-
4370
- (function(scope) {
4371
- "use strict";
4372
- var unwrap = scope.unwrap;
4373
- var OriginalDataTransfer = window.DataTransfer || window.Clipboard;
4374
- var OriginalDataTransferSetDragImage = OriginalDataTransfer.prototype.setDragImage;
4375
- if (OriginalDataTransferSetDragImage) {
4376
- OriginalDataTransfer.prototype.setDragImage = function(image, x, y) {
4377
- OriginalDataTransferSetDragImage.call(this, unwrap(image), x, y);
4378
- };
4379
- }
4380
- })(window.ShadowDOMPolyfill);
4381
-
4382
- (function(scope) {
4383
- "use strict";
4384
- var registerWrapper = scope.registerWrapper;
4385
- var setWrapper = scope.setWrapper;
4386
- var unwrap = scope.unwrap;
4387
- var OriginalFormData = window.FormData;
4388
- if (!OriginalFormData) return;
4389
- function FormData(formElement) {
4390
- var impl;
4391
- if (formElement instanceof OriginalFormData) {
4392
- impl = formElement;
4393
- } else {
4394
- impl = new OriginalFormData(formElement && unwrap(formElement));
4395
- }
4396
- setWrapper(impl, this);
4397
- }
4398
- registerWrapper(OriginalFormData, FormData, new OriginalFormData());
4399
- scope.wrappers.FormData = FormData;
4400
- })(window.ShadowDOMPolyfill);
4401
-
4402
- (function(scope) {
4403
- "use strict";
4404
- var unwrapIfNeeded = scope.unwrapIfNeeded;
4405
- var originalSend = XMLHttpRequest.prototype.send;
4406
- XMLHttpRequest.prototype.send = function(obj) {
4407
- return originalSend.call(this, unwrapIfNeeded(obj));
4408
- };
4409
- })(window.ShadowDOMPolyfill);
4410
-
4411
- (function(scope) {
4412
- "use strict";
4413
- var isWrapperFor = scope.isWrapperFor;
4414
- var elements = {
4415
- a: "HTMLAnchorElement",
4416
- area: "HTMLAreaElement",
4417
- audio: "HTMLAudioElement",
4418
- base: "HTMLBaseElement",
4419
- body: "HTMLBodyElement",
4420
- br: "HTMLBRElement",
4421
- button: "HTMLButtonElement",
4422
- canvas: "HTMLCanvasElement",
4423
- caption: "HTMLTableCaptionElement",
4424
- col: "HTMLTableColElement",
4425
- content: "HTMLContentElement",
4426
- data: "HTMLDataElement",
4427
- datalist: "HTMLDataListElement",
4428
- del: "HTMLModElement",
4429
- dir: "HTMLDirectoryElement",
4430
- div: "HTMLDivElement",
4431
- dl: "HTMLDListElement",
4432
- embed: "HTMLEmbedElement",
4433
- fieldset: "HTMLFieldSetElement",
4434
- font: "HTMLFontElement",
4435
- form: "HTMLFormElement",
4436
- frame: "HTMLFrameElement",
4437
- frameset: "HTMLFrameSetElement",
4438
- h1: "HTMLHeadingElement",
4439
- head: "HTMLHeadElement",
4440
- hr: "HTMLHRElement",
4441
- html: "HTMLHtmlElement",
4442
- iframe: "HTMLIFrameElement",
4443
- img: "HTMLImageElement",
4444
- input: "HTMLInputElement",
4445
- keygen: "HTMLKeygenElement",
4446
- label: "HTMLLabelElement",
4447
- legend: "HTMLLegendElement",
4448
- li: "HTMLLIElement",
4449
- link: "HTMLLinkElement",
4450
- map: "HTMLMapElement",
4451
- marquee: "HTMLMarqueeElement",
4452
- menu: "HTMLMenuElement",
4453
- menuitem: "HTMLMenuItemElement",
4454
- meta: "HTMLMetaElement",
4455
- meter: "HTMLMeterElement",
4456
- object: "HTMLObjectElement",
4457
- ol: "HTMLOListElement",
4458
- optgroup: "HTMLOptGroupElement",
4459
- option: "HTMLOptionElement",
4460
- output: "HTMLOutputElement",
4461
- p: "HTMLParagraphElement",
4462
- param: "HTMLParamElement",
4463
- pre: "HTMLPreElement",
4464
- progress: "HTMLProgressElement",
4465
- q: "HTMLQuoteElement",
4466
- script: "HTMLScriptElement",
4467
- select: "HTMLSelectElement",
4468
- shadow: "HTMLShadowElement",
4469
- source: "HTMLSourceElement",
4470
- span: "HTMLSpanElement",
4471
- style: "HTMLStyleElement",
4472
- table: "HTMLTableElement",
4473
- tbody: "HTMLTableSectionElement",
4474
- template: "HTMLTemplateElement",
4475
- textarea: "HTMLTextAreaElement",
4476
- thead: "HTMLTableSectionElement",
4477
- time: "HTMLTimeElement",
4478
- title: "HTMLTitleElement",
4479
- tr: "HTMLTableRowElement",
4480
- track: "HTMLTrackElement",
4481
- ul: "HTMLUListElement",
4482
- video: "HTMLVideoElement"
4483
- };
4484
- function overrideConstructor(tagName) {
4485
- var nativeConstructorName = elements[tagName];
4486
- var nativeConstructor = window[nativeConstructorName];
4487
- if (!nativeConstructor) return;
4488
- var element = document.createElement(tagName);
4489
- var wrapperConstructor = element.constructor;
4490
- window[nativeConstructorName] = wrapperConstructor;
4491
- }
4492
- Object.keys(elements).forEach(overrideConstructor);
4493
- Object.getOwnPropertyNames(scope.wrappers).forEach(function(name) {
4494
- window[name] = scope.wrappers[name];
4495
- });
4496
- })(window.ShadowDOMPolyfill);