Commit 1a74ef2ff828aca7c377a1cd66f355dd31aee0a3

Authored by isisadmin
2 parents b9c8df01 cc819354

client refactoring

js/deepClient_old.js deleted
1   -/**
2   - * Created by Luigi Serra on 10/06/2015.
3   - */
4   -
5   -var ComponentService =
6   -{
7   - deep_url:"",
8   -
9   - getComponent: function(params){//params = {component, data, fields, placeHolder}
10   - var request = this.getXMLHttpRequest();
11   - var component = params.component;
12   -
13   - request.onreadystatechange = function(){
14   - if(request.readyState == 4){
15   - try {
16   - var resp = JSON.parse(request.response);
17   - var link = '<link rel="import" href="' + resp.bridge_link + resp.component_link +'">';
18   - //Build jsonPath query string
19   - var query = "";
20   - for(var i=0;i < params.fields.length;i++){
21   - var query_elements = params.fields[i].split(',');
22   - query += "$";
23   - for(var j=0; j < query_elements.length - 1;j++){
24   - query += "['" + query_elements[j] + "']";
25   - }
26   - query += "[*]" + "['" + query_elements[query_elements.length - 1] + "']";
27   - query += "###";
28   - }
29   - query = query.substring(0, query.length - 3);
30   -
31   - //Build datalet injecting html code
32   - var datalet_code = link + '<' + params.component;
33   - var keys = Object.keys(params.params);
34   - for(var i = 0; i < keys.length; i++){
35   - datalet_code += ' ' + keys[i] + '="' + params.params[keys[i]] +'"';
36   - }
37   - datalet_code += ' query="' + query + '"></' + params.component + '>';
38   -
39   - (params.placeHolder.constructor == HTMLElement || params.placeHolder.constructor == HTMLDivElement) ? $(params.placeHolder).html(datalet_code) :/*Injection from Web Component*/
40   - $("#" + params.placeHolder).html(datalet_code);/*Injection from a static web page*/
41   -
42   - } catch (e){
43   - var resp = {
44   - status: 'error',
45   - data: 'Unknown error occurred: [' + request.response + ']'
46   - };
47   - }
48   - }};
49   -
50   - request.open('GET', this.deep_url + component);
51   - request.send();
52   - },
53   -
54   - getXMLHttpRequest: function ()
55   - {
56   - if (window.XMLHttpRequest) {
57   - return new XMLHttpRequest();
58   - }
59   - else {
60   - try {
61   - return new ActiveXObject("MSXML2.XMLHTTP.3.0");
62   - }
63   - catch(ex) {
64   - return null;
65   - }
66   - }
67   - }
68   -}
js/webcomponents.js deleted
Changes suppressed. Click to show
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.5.5
11   -window.WebComponents = window.WebComponents || {};
12   -
13   -(function(scope) {
14   - var flags = scope.flags || {};
15   - var file = "webcomponents.js";
16   - var script = document.querySelector('script[src*="' + file + '"]');
17   - if (!flags.noOpts) {
18   - location.search.slice(1).split("&").forEach(function(o) {
19   - o = o.split("=");
20   - o[0] && (flags[o[0]] = o[1] || true);
21   - });
22   - if (script) {
23   - for (var i = 0, a; a = script.attributes[i]; i++) {
24   - if (a.name !== "src") {
25   - flags[a.name] = a.value || true;
26   - }
27   - }
28   - }
29   - if (flags.log) {
30   - var parts = flags.log.split(",");
31   - flags.log = {};
32   - parts.forEach(function(f) {
33   - flags.log[f] = true;
34   - });
35   - } else {
36   - flags.log = {};
37   - }
38   - }
39   - flags.shadow = flags.shadow || flags.shadowdom || flags.polyfill;
40   - if (flags.shadow === "native") {
41   - flags.shadow = false;
42   - } else {
43   - flags.shadow = flags.shadow || !HTMLElement.prototype.createShadowRoot;
44   - }
45   - if (flags.register) {
46   - window.CustomElements = window.CustomElements || {
47   - flags: {}
48   - };
49   - window.CustomElements.flags.register = flags.register;
50   - }
51   - scope.flags = flags;
52   -})(WebComponents);
53   -
54   -if (WebComponents.flags.shadow) {
55   - if (typeof WeakMap === "undefined") {
56   - (function() {
57   - var defineProperty = Object.defineProperty;
58   - var counter = Date.now() % 1e9;
59   - var WeakMap = function() {
60   - this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__");
61   - };
62   - WeakMap.prototype = {
63   - set: function(key, value) {
64   - var entry = key[this.name];
65   - if (entry && entry[0] === key) entry[1] = value; else defineProperty(key, this.name, {
66   - value: [ key, value ],
67   - writable: true
68   - });
69   - return this;
70   - },
71   - get: function(key) {
72   - var entry;
73   - return (entry = key[this.name]) && entry[0] === key ? entry[1] : undefined;
74   - },
75   - "delete": function(key) {
76   - var entry = key[this.name];
77   - if (!entry || entry[0] !== key) return false;
78   - entry[0] = entry[1] = undefined;
79   - return true;
80   - },
81   - has: function(key) {
82   - var entry = key[this.name];
83   - if (!entry) return false;
84   - return entry[0] === key;
85   - }
86   - };
87   - window.WeakMap = WeakMap;
88   - })();
89   - }
90   - window.ShadowDOMPolyfill = {};
91   - (function(scope) {
92   - "use strict";
93   - var constructorTable = new WeakMap();
94   - var nativePrototypeTable = new WeakMap();
95   - var wrappers = Object.create(null);
96   - function detectEval() {
97   - if (typeof chrome !== "undefined" && chrome.app && chrome.app.runtime) {
98   - return false;
99   - }
100   - if (navigator.getDeviceStorage) {
101   - return false;
102   - }
103   - try {
104   - var f = new Function("return true;");
105   - return f();
106   - } catch (ex) {
107   - return false;
108   - }
109   - }
110   - var hasEval = detectEval();
111   - function assert(b) {
112   - if (!b) throw new Error("Assertion failed");
113   - }
114   - var defineProperty = Object.defineProperty;
115   - var getOwnPropertyNames = Object.getOwnPropertyNames;
116   - var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
117   - function mixin(to, from) {
118   - var names = getOwnPropertyNames(from);
119   - for (var i = 0; i < names.length; i++) {
120   - var name = names[i];
121   - defineProperty(to, name, getOwnPropertyDescriptor(from, name));
122   - }
123   - return to;
124   - }
125   - function mixinStatics(to, from) {
126   - var names = getOwnPropertyNames(from);
127   - for (var i = 0; i < names.length; i++) {
128   - var name = names[i];
129   - switch (name) {
130   - case "arguments":
131   - case "caller":
132   - case "length":
133   - case "name":
134   - case "prototype":
135   - case "toString":
136   - continue;
137   - }
138   - defineProperty(to, name, getOwnPropertyDescriptor(from, name));
139   - }
140   - return to;
141   - }
142   - function oneOf(object, propertyNames) {
143   - for (var i = 0; i < propertyNames.length; i++) {
144   - if (propertyNames[i] in object) return propertyNames[i];
145   - }
146   - }
147   - var nonEnumerableDataDescriptor = {
148   - value: undefined,
149   - configurable: true,
150   - enumerable: false,
151   - writable: true
152   - };
153   - function defineNonEnumerableDataProperty(object, name, value) {
154   - nonEnumerableDataDescriptor.value = value;
155   - defineProperty(object, name, nonEnumerableDataDescriptor);
156   - }
157   - getOwnPropertyNames(window);
158   - function getWrapperConstructor(node) {
159   - var nativePrototype = node.__proto__ || Object.getPrototypeOf(node);
160   - if (isFirefox) {
161   - try {
162   - getOwnPropertyNames(nativePrototype);
163   - } catch (error) {
164   - nativePrototype = nativePrototype.__proto__;
165   - }
166   - }
167   - var wrapperConstructor = constructorTable.get(nativePrototype);
168   - if (wrapperConstructor) return wrapperConstructor;
169   - var parentWrapperConstructor = getWrapperConstructor(nativePrototype);
170   - var GeneratedWrapper = createWrapperConstructor(parentWrapperConstructor);
171   - registerInternal(nativePrototype, GeneratedWrapper, node);
172   - return GeneratedWrapper;
173   - }
174   - function addForwardingProperties(nativePrototype, wrapperPrototype) {
175   - installProperty(nativePrototype, wrapperPrototype, true);
176   - }
177   - function registerInstanceProperties(wrapperPrototype, instanceObject) {
178   - installProperty(instanceObject, wrapperPrototype, false);
179   - }
180   - var isFirefox = /Firefox/.test(navigator.userAgent);
181   - var dummyDescriptor = {
182   - get: function() {},
183   - set: function(v) {},
184   - configurable: true,
185   - enumerable: true
186   - };
187   - function isEventHandlerName(name) {
188   - return /^on[a-z]+$/.test(name);
189   - }
190   - function isIdentifierName(name) {
191   - return /^\w[a-zA-Z_0-9]*$/.test(name);
192   - }
193   - function getGetter(name) {
194   - return hasEval && isIdentifierName(name) ? new Function("return this.__impl4cf1e782hg__." + name) : function() {
195   - return this.__impl4cf1e782hg__[name];
196   - };
197   - }
198   - function getSetter(name) {
199   - return hasEval && isIdentifierName(name) ? new Function("v", "this.__impl4cf1e782hg__." + name + " = v") : function(v) {
200   - this.__impl4cf1e782hg__[name] = v;
201   - };
202   - }
203   - function getMethod(name) {
204   - return hasEval && isIdentifierName(name) ? new Function("return this.__impl4cf1e782hg__." + name + ".apply(this.__impl4cf1e782hg__, arguments)") : function() {
205   - return this.__impl4cf1e782hg__[name].apply(this.__impl4cf1e782hg__, arguments);
206   - };
207   - }
208   - function getDescriptor(source, name) {
209   - try {
210   - return Object.getOwnPropertyDescriptor(source, name);
211   - } catch (ex) {
212   - return dummyDescriptor;
213   - }
214   - }
215   - var isBrokenSafari = function() {
216   - var descr = Object.getOwnPropertyDescriptor(Node.prototype, "nodeType");
217   - return descr && !descr.get && !descr.set;
218   - }();
219   - function installProperty(source, target, allowMethod, opt_blacklist) {
220   - var names = getOwnPropertyNames(source);
221   - for (var i = 0; i < names.length; i++) {
222   - var name = names[i];
223   - if (name === "polymerBlackList_") continue;
224   - if (name in target) continue;
225   - if (source.polymerBlackList_ && source.polymerBlackList_[name]) continue;
226   - if (isFirefox) {
227   - source.__lookupGetter__(name);
228   - }
229   - var descriptor = getDescriptor(source, name);
230   - var getter, setter;
231   - if (allowMethod && typeof descriptor.value === "function") {
232   - target[name] = getMethod(name);
233   - continue;
234   - }
235   - var isEvent = isEventHandlerName(name);
236   - if (isEvent) getter = scope.getEventHandlerGetter(name); else getter = getGetter(name);
237   - if (descriptor.writable || descriptor.set || isBrokenSafari) {
238   - if (isEvent) setter = scope.getEventHandlerSetter(name); else setter = getSetter(name);
239   - }
240   - var configurable = isBrokenSafari || descriptor.configurable;
241   - defineProperty(target, name, {
242   - get: getter,
243   - set: setter,
244   - configurable: configurable,
245   - enumerable: descriptor.enumerable
246   - });
247   - }
248   - }
249   - function register(nativeConstructor, wrapperConstructor, opt_instance) {
250   - var nativePrototype = nativeConstructor.prototype;
251   - registerInternal(nativePrototype, wrapperConstructor, opt_instance);
252   - mixinStatics(wrapperConstructor, nativeConstructor);
253   - }
254   - function registerInternal(nativePrototype, wrapperConstructor, opt_instance) {
255   - var wrapperPrototype = wrapperConstructor.prototype;
256   - assert(constructorTable.get(nativePrototype) === undefined);
257   - constructorTable.set(nativePrototype, wrapperConstructor);
258   - nativePrototypeTable.set(wrapperPrototype, nativePrototype);
259   - addForwardingProperties(nativePrototype, wrapperPrototype);
260   - if (opt_instance) registerInstanceProperties(wrapperPrototype, opt_instance);
261   - defineNonEnumerableDataProperty(wrapperPrototype, "constructor", wrapperConstructor);
262   - wrapperConstructor.prototype = wrapperPrototype;
263   - }
264   - function isWrapperFor(wrapperConstructor, nativeConstructor) {
265   - return constructorTable.get(nativeConstructor.prototype) === wrapperConstructor;
266   - }
267   - function registerObject(object) {
268   - var nativePrototype = Object.getPrototypeOf(object);
269   - var superWrapperConstructor = getWrapperConstructor(nativePrototype);
270   - var GeneratedWrapper = createWrapperConstructor(superWrapperConstructor);
271   - registerInternal(nativePrototype, GeneratedWrapper, object);
272   - return GeneratedWrapper;
273   - }
274   - function createWrapperConstructor(superWrapperConstructor) {
275   - function GeneratedWrapper(node) {
276   - superWrapperConstructor.call(this, node);
277   - }
278   - var p = Object.create(superWrapperConstructor.prototype);
279   - p.constructor = GeneratedWrapper;
280   - GeneratedWrapper.prototype = p;
281   - return GeneratedWrapper;
282   - }
283   - function isWrapper(object) {
284   - return object && object.__impl4cf1e782hg__;
285   - }
286   - function isNative(object) {
287   - return !isWrapper(object);
288   - }
289   - function wrap(impl) {
290   - if (impl === null) return null;
291   - assert(isNative(impl));
292   - return impl.__wrapper8e3dd93a60__ || (impl.__wrapper8e3dd93a60__ = new (getWrapperConstructor(impl))(impl));
293   - }
294   - function unwrap(wrapper) {
295   - if (wrapper === null) return null;
296   - assert(isWrapper(wrapper));
297   - return wrapper.__impl4cf1e782hg__;
298   - }
299   - function unsafeUnwrap(wrapper) {
300   - return wrapper.__impl4cf1e782hg__;
301   - }
302   - function setWrapper(impl, wrapper) {
303   - wrapper.__impl4cf1e782hg__ = impl;
304   - impl.__wrapper8e3dd93a60__ = wrapper;
305   - }
306   - function unwrapIfNeeded(object) {
307   - return object && isWrapper(object) ? unwrap(object) : object;
308   - }
309   - function wrapIfNeeded(object) {
310   - return object && !isWrapper(object) ? wrap(object) : object;
311   - }
312   - function rewrap(node, wrapper) {
313   - if (wrapper === null) return;
314   - assert(isNative(node));
315   - assert(wrapper === undefined || isWrapper(wrapper));
316   - node.__wrapper8e3dd93a60__ = wrapper;
317   - }
318   - var getterDescriptor = {
319   - get: undefined,
320   - configurable: true,
321   - enumerable: true
322   - };
323   - function defineGetter(constructor, name, getter) {
324   - getterDescriptor.get = getter;
325   - defineProperty(constructor.prototype, name, getterDescriptor);
326   - }
327   - function defineWrapGetter(constructor, name) {
328   - defineGetter(constructor, name, function() {
329   - return wrap(this.__impl4cf1e782hg__[name]);
330   - });
331   - }
332   - function forwardMethodsToWrapper(constructors, names) {
333   - constructors.forEach(function(constructor) {
334   - names.forEach(function(name) {
335   - constructor.prototype[name] = function() {
336   - var w = wrapIfNeeded(this);
337   - return w[name].apply(w, arguments);
338   - };
339   - });
340   - });
341   - }
342   - scope.assert = assert;
343   - scope.constructorTable = constructorTable;
344   - scope.defineGetter = defineGetter;
345   - scope.defineWrapGetter = defineWrapGetter;
346   - scope.forwardMethodsToWrapper = forwardMethodsToWrapper;
347   - scope.isWrapper = isWrapper;
348   - scope.isWrapperFor = isWrapperFor;
349   - scope.mixin = mixin;
350   - scope.nativePrototypeTable = nativePrototypeTable;
351   - scope.oneOf = oneOf;
352   - scope.registerObject = registerObject;
353   - scope.registerWrapper = register;
354   - scope.rewrap = rewrap;
355   - scope.setWrapper = setWrapper;
356   - scope.unsafeUnwrap = unsafeUnwrap;
357   - scope.unwrap = unwrap;
358   - scope.unwrapIfNeeded = unwrapIfNeeded;
359   - scope.wrap = wrap;
360   - scope.wrapIfNeeded = wrapIfNeeded;
361   - scope.wrappers = wrappers;
362   - })(window.ShadowDOMPolyfill);
363   - (function(scope) {
364   - "use strict";
365   - function newSplice(index, removed, addedCount) {
366   - return {
367   - index: index,
368   - removed: removed,
369   - addedCount: addedCount
370   - };
371   - }
372   - var EDIT_LEAVE = 0;
373   - var EDIT_UPDATE = 1;
374   - var EDIT_ADD = 2;
375   - var EDIT_DELETE = 3;
376   - function ArraySplice() {}
377   - ArraySplice.prototype = {
378   - calcEditDistances: function(current, currentStart, currentEnd, old, oldStart, oldEnd) {
379   - var rowCount = oldEnd - oldStart + 1;
380   - var columnCount = currentEnd - currentStart + 1;
381   - var distances = new Array(rowCount);
382   - for (var i = 0; i < rowCount; i++) {
383   - distances[i] = new Array(columnCount);
384   - distances[i][0] = i;
385   - }
386   - for (var j = 0; j < columnCount; j++) distances[0][j] = j;
387   - for (var i = 1; i < rowCount; i++) {
388   - for (var j = 1; j < columnCount; j++) {
389   - if (this.equals(current[currentStart + j - 1], old[oldStart + i - 1])) distances[i][j] = distances[i - 1][j - 1]; else {
390   - var north = distances[i - 1][j] + 1;
391   - var west = distances[i][j - 1] + 1;
392   - distances[i][j] = north < west ? north : west;
393   - }
394   - }
395   - }
396   - return distances;
397   - },
398   - spliceOperationsFromEditDistances: function(distances) {
399   - var i = distances.length - 1;
400   - var j = distances[0].length - 1;
401   - var current = distances[i][j];
402   - var edits = [];
403   - while (i > 0 || j > 0) {
404   - if (i == 0) {
405   - edits.push(EDIT_ADD);
406   - j--;
407   - continue;
408   - }
409   - if (j == 0) {
410   - edits.push(EDIT_DELETE);
411   - i--;
412   - continue;
413   - }
414   - var northWest = distances[i - 1][j - 1];
415   - var west = distances[i - 1][j];
416   - var north = distances[i][j - 1];
417   - var min;
418   - if (west < north) min = west < northWest ? west : northWest; else min = north < northWest ? north : northWest;
419   - if (min == northWest) {
420   - if (northWest == current) {
421   - edits.push(EDIT_LEAVE);
422   - } else {
423   - edits.push(EDIT_UPDATE);
424   - current = northWest;
425   - }
426   - i--;
427   - j--;
428   - } else if (min == west) {
429   - edits.push(EDIT_DELETE);
430   - i--;
431   - current = west;
432   - } else {
433   - edits.push(EDIT_ADD);
434   - j--;
435   - current = north;
436   - }
437   - }
438   - edits.reverse();
439   - return edits;
440   - },
441   - calcSplices: function(current, currentStart, currentEnd, old, oldStart, oldEnd) {
442   - var prefixCount = 0;
443   - var suffixCount = 0;
444   - var minLength = Math.min(currentEnd - currentStart, oldEnd - oldStart);
445   - if (currentStart == 0 && oldStart == 0) prefixCount = this.sharedPrefix(current, old, minLength);
446   - if (currentEnd == current.length && oldEnd == old.length) suffixCount = this.sharedSuffix(current, old, minLength - prefixCount);
447   - currentStart += prefixCount;
448   - oldStart += prefixCount;
449   - currentEnd -= suffixCount;
450   - oldEnd -= suffixCount;
451   - if (currentEnd - currentStart == 0 && oldEnd - oldStart == 0) return [];
452   - if (currentStart == currentEnd) {
453   - var splice = newSplice(currentStart, [], 0);
454   - while (oldStart < oldEnd) splice.removed.push(old[oldStart++]);
455   - return [ splice ];
456   - } else if (oldStart == oldEnd) return [ newSplice(currentStart, [], currentEnd - currentStart) ];
457   - var ops = this.spliceOperationsFromEditDistances(this.calcEditDistances(current, currentStart, currentEnd, old, oldStart, oldEnd));
458   - var splice = undefined;
459   - var splices = [];
460   - var index = currentStart;
461   - var oldIndex = oldStart;
462   - for (var i = 0; i < ops.length; i++) {
463   - switch (ops[i]) {
464   - case EDIT_LEAVE:
465   - if (splice) {
466   - splices.push(splice);
467   - splice = undefined;
468   - }
469   - index++;
470   - oldIndex++;
471   - break;
472   -
473   - case EDIT_UPDATE:
474   - if (!splice) splice = newSplice(index, [], 0);
475   - splice.addedCount++;
476   - index++;
477   - splice.removed.push(old[oldIndex]);
478   - oldIndex++;
479   - break;
480   -
481   - case EDIT_ADD:
482   - if (!splice) splice = newSplice(index, [], 0);
483   - splice.addedCount++;
484   - index++;
485   - break;
486   -
487   - case EDIT_DELETE:
488   - if (!splice) splice = newSplice(index, [], 0);
489   - splice.removed.push(old[oldIndex]);
490   - oldIndex++;
491   - break;
492   - }
493   - }
494   - if (splice) {
495   - splices.push(splice);
496   - }
497   - return splices;
498   - },
499   - sharedPrefix: function(current, old, searchLength) {
500   - for (var i = 0; i < searchLength; i++) if (!this.equals(current[i], old[i])) return i;
501   - return searchLength;
502   - },
503   - sharedSuffix: function(current, old, searchLength) {
504   - var index1 = current.length;
505   - var index2 = old.length;
506   - var count = 0;
507   - while (count < searchLength && this.equals(current[--index1], old[--index2])) count++;
508   - return count;
509   - },
510   - calculateSplices: function(current, previous) {
511   - return this.calcSplices(current, 0, current.length, previous, 0, previous.length);
512   - },
513   - equals: function(currentValue, previousValue) {
514   - return currentValue === previousValue;
515   - }
516   - };
517   - scope.ArraySplice = ArraySplice;
518   - })(window.ShadowDOMPolyfill);
519   - (function(context) {
520   - "use strict";
521   - var OriginalMutationObserver = window.MutationObserver;
522   - var callbacks = [];
523   - var pending = false;
524   - var timerFunc;
525   - function handle() {
526   - pending = false;
527   - var copies = callbacks.slice(0);
528   - callbacks = [];
529   - for (var i = 0; i < copies.length; i++) {
530   - (0, copies[i])();
531   - }
532   - }
533   - if (OriginalMutationObserver) {
534   - var counter = 1;
535   - var observer = new OriginalMutationObserver(handle);
536   - var textNode = document.createTextNode(counter);
537   - observer.observe(textNode, {
538   - characterData: true
539   - });
540   - timerFunc = function() {
541   - counter = (counter + 1) % 2;
542   - textNode.data = counter;
543   - };
544   - } else {
545   - timerFunc = window.setTimeout;
546   - }
547   - function setEndOfMicrotask(func) {
548   - callbacks.push(func);
549   - if (pending) return;
550   - pending = true;
551   - timerFunc(handle, 0);
552   - }
553   - context.setEndOfMicrotask = setEndOfMicrotask;
554   - })(window.ShadowDOMPolyfill);
555   - (function(scope) {
556   - "use strict";
557   - var setEndOfMicrotask = scope.setEndOfMicrotask;
558   - var wrapIfNeeded = scope.wrapIfNeeded;
559   - var wrappers = scope.wrappers;
560   - var registrationsTable = new WeakMap();
561   - var globalMutationObservers = [];
562   - var isScheduled = false;
563   - function scheduleCallback(observer) {
564   - if (observer.scheduled_) return;
565   - observer.scheduled_ = true;
566   - globalMutationObservers.push(observer);
567   - if (isScheduled) return;
568   - setEndOfMicrotask(notifyObservers);
569   - isScheduled = true;
570   - }
571   - function notifyObservers() {
572   - isScheduled = false;
573   - while (globalMutationObservers.length) {
574   - var notifyList = globalMutationObservers;
575   - globalMutationObservers = [];
576   - notifyList.sort(function(x, y) {
577   - return x.uid_ - y.uid_;
578   - });
579   - for (var i = 0; i < notifyList.length; i++) {
580   - var mo = notifyList[i];
581   - mo.scheduled_ = false;
582   - var queue = mo.takeRecords();
583   - removeTransientObserversFor(mo);
584   - if (queue.length) {
585   - mo.callback_(queue, mo);
586   - }
587   - }
588   - }
589   - }
590   - function MutationRecord(type, target) {
591   - this.type = type;
592   - this.target = target;
593   - this.addedNodes = new wrappers.NodeList();
594   - this.removedNodes = new wrappers.NodeList();
595   - this.previousSibling = null;
596   - this.nextSibling = null;
597   - this.attributeName = null;
598   - this.attributeNamespace = null;
599   - this.oldValue = null;
600   - }
601   - function registerTransientObservers(ancestor, node) {
602   - for (;ancestor; ancestor = ancestor.parentNode) {
603   - var registrations = registrationsTable.get(ancestor);
604   - if (!registrations) continue;
605   - for (var i = 0; i < registrations.length; i++) {
606   - var registration = registrations[i];
607   - if (registration.options.subtree) registration.addTransientObserver(node);
608   - }
609   - }
610   - }
611   - function removeTransientObserversFor(observer) {
612   - for (var i = 0; i < observer.nodes_.length; i++) {
613   - var node = observer.nodes_[i];
614   - var registrations = registrationsTable.get(node);
615   - if (!registrations) return;
616   - for (var j = 0; j < registrations.length; j++) {
617   - var registration = registrations[j];
618   - if (registration.observer === observer) registration.removeTransientObservers();
619   - }
620   - }
621   - }
622   - function enqueueMutation(target, type, data) {
623   - var interestedObservers = Object.create(null);
624   - var associatedStrings = Object.create(null);
625   - for (var node = target; node; node = node.parentNode) {
626   - var registrations = registrationsTable.get(node);
627   - if (!registrations) continue;
628   - for (var j = 0; j < registrations.length; j++) {
629   - var registration = registrations[j];
630   - var options = registration.options;
631   - if (node !== target && !options.subtree) continue;
632   - if (type === "attributes" && !options.attributes) continue;
633   - if (type === "attributes" && options.attributeFilter && (data.namespace !== null || options.attributeFilter.indexOf(data.name) === -1)) {
634   - continue;
635   - }
636   - if (type === "characterData" && !options.characterData) continue;
637   - if (type === "childList" && !options.childList) continue;
638   - var observer = registration.observer;
639   - interestedObservers[observer.uid_] = observer;
640   - if (type === "attributes" && options.attributeOldValue || type === "characterData" && options.characterDataOldValue) {
641   - associatedStrings[observer.uid_] = data.oldValue;
642   - }
643   - }
644   - }
645   - for (var uid in interestedObservers) {
646   - var observer = interestedObservers[uid];
647   - var record = new MutationRecord(type, target);
648   - if ("name" in data && "namespace" in data) {
649   - record.attributeName = data.name;
650   - record.attributeNamespace = data.namespace;
651   - }
652   - if (data.addedNodes) record.addedNodes = data.addedNodes;
653   - if (data.removedNodes) record.removedNodes = data.removedNodes;
654   - if (data.previousSibling) record.previousSibling = data.previousSibling;
655   - if (data.nextSibling) record.nextSibling = data.nextSibling;
656   - if (associatedStrings[uid] !== undefined) record.oldValue = associatedStrings[uid];
657   - scheduleCallback(observer);
658   - observer.records_.push(record);
659   - }
660   - }
661   - var slice = Array.prototype.slice;
662   - function MutationObserverOptions(options) {
663   - this.childList = !!options.childList;
664   - this.subtree = !!options.subtree;
665   - if (!("attributes" in options) && ("attributeOldValue" in options || "attributeFilter" in options)) {
666   - this.attributes = true;
667   - } else {
668   - this.attributes = !!options.attributes;
669   - }
670   - if ("characterDataOldValue" in options && !("characterData" in options)) this.characterData = true; else this.characterData = !!options.characterData;
671   - if (!this.attributes && (options.attributeOldValue || "attributeFilter" in options) || !this.characterData && options.characterDataOldValue) {
672   - throw new TypeError();
673   - }
674   - this.characterData = !!options.characterData;
675   - this.attributeOldValue = !!options.attributeOldValue;
676   - this.characterDataOldValue = !!options.characterDataOldValue;
677   - if ("attributeFilter" in options) {
678   - if (options.attributeFilter == null || typeof options.attributeFilter !== "object") {
679   - throw new TypeError();
680   - }
681   - this.attributeFilter = slice.call(options.attributeFilter);
682   - } else {
683   - this.attributeFilter = null;
684   - }
685   - }
686   - var uidCounter = 0;
687   - function MutationObserver(callback) {
688   - this.callback_ = callback;
689   - this.nodes_ = [];
690   - this.records_ = [];
691   - this.uid_ = ++uidCounter;
692   - this.scheduled_ = false;
693   - }
694   - MutationObserver.prototype = {
695   - constructor: MutationObserver,
696   - observe: function(target, options) {
697   - target = wrapIfNeeded(target);
698   - var newOptions = new MutationObserverOptions(options);
699   - var registration;
700   - var registrations = registrationsTable.get(target);
701   - if (!registrations) registrationsTable.set(target, registrations = []);
702   - for (var i = 0; i < registrations.length; i++) {
703   - if (registrations[i].observer === this) {
704   - registration = registrations[i];
705   - registration.removeTransientObservers();
706   - registration.options = newOptions;
707   - }
708   - }
709   - if (!registration) {
710   - registration = new Registration(this, target, newOptions);
711   - registrations.push(registration);
712   - this.nodes_.push(target);
713   - }
714   - },
715   - disconnect: function() {
716   - this.nodes_.forEach(function(node) {
717   - var registrations = registrationsTable.get(node);
718   - for (var i = 0; i < registrations.length; i++) {
719   - var registration = registrations[i];
720   - if (registration.observer === this) {
721   - registrations.splice(i, 1);
722   - break;
723   - }
724   - }
725   - }, this);
726   - this.records_ = [];
727   - },
728   - takeRecords: function() {
729   - var copyOfRecords = this.records_;
730   - this.records_ = [];
731   - return copyOfRecords;
732   - }
733   - };
734   - function Registration(observer, target, options) {
735   - this.observer = observer;
736   - this.target = target;
737   - this.options = options;
738   - this.transientObservedNodes = [];
739   - }
740   - Registration.prototype = {
741   - addTransientObserver: function(node) {
742   - if (node === this.target) return;
743   - scheduleCallback(this.observer);
744   - this.transientObservedNodes.push(node);
745   - var registrations = registrationsTable.get(node);
746   - if (!registrations) registrationsTable.set(node, registrations = []);
747   - registrations.push(this);
748   - },
749   - removeTransientObservers: function() {
750   - var transientObservedNodes = this.transientObservedNodes;
751   - this.transientObservedNodes = [];
752   - for (var i = 0; i < transientObservedNodes.length; i++) {
753   - var node = transientObservedNodes[i];
754   - var registrations = registrationsTable.get(node);
755   - for (var j = 0; j < registrations.length; j++) {
756   - if (registrations[j] === this) {
757   - registrations.splice(j, 1);
758   - break;
759   - }
760   - }
761   - }
762   - }
763   - };
764   - scope.enqueueMutation = enqueueMutation;
765   - scope.registerTransientObservers = registerTransientObservers;
766   - scope.wrappers.MutationObserver = MutationObserver;
767   - scope.wrappers.MutationRecord = MutationRecord;
768   - })(window.ShadowDOMPolyfill);
769   - (function(scope) {
770   - "use strict";
771   - function TreeScope(root, parent) {
772   - this.root = root;
773   - this.parent = parent;
774   - }
775   - TreeScope.prototype = {
776   - get renderer() {
777   - if (this.root instanceof scope.wrappers.ShadowRoot) {
778   - return scope.getRendererForHost(this.root.host);
779   - }
780   - return null;
781   - },
782   - contains: function(treeScope) {
783   - for (;treeScope; treeScope = treeScope.parent) {
784   - if (treeScope === this) return true;
785   - }
786   - return false;
787   - }
788   - };
789   - function setTreeScope(node, treeScope) {
790   - if (node.treeScope_ !== treeScope) {
791   - node.treeScope_ = treeScope;
792   - for (var sr = node.shadowRoot; sr; sr = sr.olderShadowRoot) {
793   - sr.treeScope_.parent = treeScope;
794   - }
795   - for (var child = node.firstChild; child; child = child.nextSibling) {
796   - setTreeScope(child, treeScope);
797   - }
798   - }
799   - }
800   - function getTreeScope(node) {
801   - if (node instanceof scope.wrappers.Window) {
802   - debugger;
803   - }
804   - if (node.treeScope_) return node.treeScope_;
805   - var parent = node.parentNode;
806   - var treeScope;
807   - if (parent) treeScope = getTreeScope(parent); else treeScope = new TreeScope(node, null);
808   - return node.treeScope_ = treeScope;
809   - }
810   - scope.TreeScope = TreeScope;
811   - scope.getTreeScope = getTreeScope;
812   - scope.setTreeScope = setTreeScope;
813   - })(window.ShadowDOMPolyfill);
814   - (function(scope) {
815   - "use strict";
816   - var forwardMethodsToWrapper = scope.forwardMethodsToWrapper;
817   - var getTreeScope = scope.getTreeScope;
818   - var mixin = scope.mixin;
819   - var registerWrapper = scope.registerWrapper;
820   - var setWrapper = scope.setWrapper;
821   - var unsafeUnwrap = scope.unsafeUnwrap;
822   - var unwrap = scope.unwrap;
823   - var wrap = scope.wrap;
824   - var wrappers = scope.wrappers;
825   - var wrappedFuns = new WeakMap();
826   - var listenersTable = new WeakMap();
827   - var handledEventsTable = new WeakMap();
828   - var currentlyDispatchingEvents = new WeakMap();
829   - var targetTable = new WeakMap();
830   - var currentTargetTable = new WeakMap();
831   - var relatedTargetTable = new WeakMap();
832   - var eventPhaseTable = new WeakMap();
833   - var stopPropagationTable = new WeakMap();
834   - var stopImmediatePropagationTable = new WeakMap();
835   - var eventHandlersTable = new WeakMap();
836   - var eventPathTable = new WeakMap();
837   - function isShadowRoot(node) {
838   - return node instanceof wrappers.ShadowRoot;
839   - }
840   - function rootOfNode(node) {
841   - return getTreeScope(node).root;
842   - }
843   - function getEventPath(node, event) {
844   - var path = [];
845   - var current = node;
846   - path.push(current);
847   - while (current) {
848   - var destinationInsertionPoints = getDestinationInsertionPoints(current);
849   - if (destinationInsertionPoints && destinationInsertionPoints.length > 0) {
850   - for (var i = 0; i < destinationInsertionPoints.length; i++) {
851   - var insertionPoint = destinationInsertionPoints[i];
852   - if (isShadowInsertionPoint(insertionPoint)) {
853   - var shadowRoot = rootOfNode(insertionPoint);
854   - var olderShadowRoot = shadowRoot.olderShadowRoot;
855   - if (olderShadowRoot) path.push(olderShadowRoot);
856   - }
857   - path.push(insertionPoint);
858   - }
859   - current = destinationInsertionPoints[destinationInsertionPoints.length - 1];
860   - } else {
861   - if (isShadowRoot(current)) {
862   - if (inSameTree(node, current) && eventMustBeStopped(event)) {
863   - break;
864   - }
865   - current = current.host;
866   - path.push(current);
867   - } else {
868   - current = current.parentNode;
869   - if (current) path.push(current);
870   - }
871   - }
872   - }
873   - return path;
874   - }
875   - function eventMustBeStopped(event) {
876   - if (!event) return false;
877   - switch (event.type) {
878   - case "abort":
879   - case "error":
880   - case "select":
881   - case "change":
882   - case "load":
883   - case "reset":
884   - case "resize":
885   - case "scroll":
886   - case "selectstart":
887   - return true;
888   - }
889   - return false;
890   - }
891   - function isShadowInsertionPoint(node) {
892   - return node instanceof HTMLShadowElement;
893   - }
894   - function getDestinationInsertionPoints(node) {
895   - return scope.getDestinationInsertionPoints(node);
896   - }
897   - function eventRetargetting(path, currentTarget) {
898   - if (path.length === 0) return currentTarget;
899   - if (currentTarget instanceof wrappers.Window) currentTarget = currentTarget.document;
900   - var currentTargetTree = getTreeScope(currentTarget);
901   - var originalTarget = path[0];
902   - var originalTargetTree = getTreeScope(originalTarget);
903   - var relativeTargetTree = lowestCommonInclusiveAncestor(currentTargetTree, originalTargetTree);
904   - for (var i = 0; i < path.length; i++) {
905   - var node = path[i];
906   - if (getTreeScope(node) === relativeTargetTree) return node;
907   - }
908   - return path[path.length - 1];
909   - }
910   - function getTreeScopeAncestors(treeScope) {
911   - var ancestors = [];
912   - for (;treeScope; treeScope = treeScope.parent) {
913   - ancestors.push(treeScope);
914   - }
915   - return ancestors;
916   - }
917   - function lowestCommonInclusiveAncestor(tsA, tsB) {
918   - var ancestorsA = getTreeScopeAncestors(tsA);
919   - var ancestorsB = getTreeScopeAncestors(tsB);
920   - var result = null;
921   - while (ancestorsA.length > 0 && ancestorsB.length > 0) {
922   - var a = ancestorsA.pop();
923   - var b = ancestorsB.pop();
924   - if (a === b) result = a; else break;
925   - }
926   - return result;
927   - }
928   - function getTreeScopeRoot(ts) {
929   - if (!ts.parent) return ts;
930   - return getTreeScopeRoot(ts.parent);
931   - }
932   - function relatedTargetResolution(event, currentTarget, relatedTarget) {
933   - if (currentTarget instanceof wrappers.Window) currentTarget = currentTarget.document;
934   - var currentTargetTree = getTreeScope(currentTarget);
935   - var relatedTargetTree = getTreeScope(relatedTarget);
936   - var relatedTargetEventPath = getEventPath(relatedTarget, event);
937   - var lowestCommonAncestorTree;
938   - var lowestCommonAncestorTree = lowestCommonInclusiveAncestor(currentTargetTree, relatedTargetTree);
939   - if (!lowestCommonAncestorTree) lowestCommonAncestorTree = relatedTargetTree.root;
940   - for (var commonAncestorTree = lowestCommonAncestorTree; commonAncestorTree; commonAncestorTree = commonAncestorTree.parent) {
941   - var adjustedRelatedTarget;
942   - for (var i = 0; i < relatedTargetEventPath.length; i++) {
943   - var node = relatedTargetEventPath[i];
944   - if (getTreeScope(node) === commonAncestorTree) return node;
945   - }
946   - }
947   - return null;
948   - }
949   - function inSameTree(a, b) {
950   - return getTreeScope(a) === getTreeScope(b);
951   - }
952   - var NONE = 0;
953   - var CAPTURING_PHASE = 1;
954   - var AT_TARGET = 2;
955   - var BUBBLING_PHASE = 3;
956   - var pendingError;
957   - function dispatchOriginalEvent(originalEvent) {
958   - if (handledEventsTable.get(originalEvent)) return;
959   - handledEventsTable.set(originalEvent, true);
960   - dispatchEvent(wrap(originalEvent), wrap(originalEvent.target));
961   - if (pendingError) {
962   - var err = pendingError;
963   - pendingError = null;
964   - throw err;
965   - }
966   - }
967   - function isLoadLikeEvent(event) {
968   - switch (event.type) {
969   - case "load":
970   - case "beforeunload":
971   - case "unload":
972   - return true;
973   - }
974   - return false;
975   - }
976   - function dispatchEvent(event, originalWrapperTarget) {
977   - if (currentlyDispatchingEvents.get(event)) throw new Error("InvalidStateError");
978   - currentlyDispatchingEvents.set(event, true);
979   - scope.renderAllPending();
980   - var eventPath;
981   - var overrideTarget;
982   - var win;
983   - if (isLoadLikeEvent(event) && !event.bubbles) {
984   - var doc = originalWrapperTarget;
985   - if (doc instanceof wrappers.Document && (win = doc.defaultView)) {
986   - overrideTarget = doc;
987   - eventPath = [];
988   - }
989   - }
990   - if (!eventPath) {
991   - if (originalWrapperTarget instanceof wrappers.Window) {
992   - win = originalWrapperTarget;
993   - eventPath = [];
994   - } else {
995   - eventPath = getEventPath(originalWrapperTarget, event);
996   - if (!isLoadLikeEvent(event)) {
997   - var doc = eventPath[eventPath.length - 1];
998   - if (doc instanceof wrappers.Document) win = doc.defaultView;
999   - }
1000   - }
1001   - }
1002   - eventPathTable.set(event, eventPath);
1003   - if (dispatchCapturing(event, eventPath, win, overrideTarget)) {
1004   - if (dispatchAtTarget(event, eventPath, win, overrideTarget)) {
1005   - dispatchBubbling(event, eventPath, win, overrideTarget);
1006   - }
1007   - }
1008   - eventPhaseTable.set(event, NONE);
1009   - currentTargetTable.delete(event, null);
1010   - currentlyDispatchingEvents.delete(event);
1011   - return event.defaultPrevented;
1012   - }
1013   - function dispatchCapturing(event, eventPath, win, overrideTarget) {
1014   - var phase = CAPTURING_PHASE;
1015   - if (win) {
1016   - if (!invoke(win, event, phase, eventPath, overrideTarget)) return false;
1017   - }
1018   - for (var i = eventPath.length - 1; i > 0; i--) {
1019   - if (!invoke(eventPath[i], event, phase, eventPath, overrideTarget)) return false;
1020   - }
1021   - return true;
1022   - }
1023   - function dispatchAtTarget(event, eventPath, win, overrideTarget) {
1024   - var phase = AT_TARGET;
1025   - var currentTarget = eventPath[0] || win;
1026   - return invoke(currentTarget, event, phase, eventPath, overrideTarget);
1027   - }
1028   - function dispatchBubbling(event, eventPath, win, overrideTarget) {
1029   - var phase = BUBBLING_PHASE;
1030   - for (var i = 1; i < eventPath.length; i++) {
1031   - if (!invoke(eventPath[i], event, phase, eventPath, overrideTarget)) return;
1032   - }
1033   - if (win && eventPath.length > 0) {
1034   - invoke(win, event, phase, eventPath, overrideTarget);
1035   - }
1036   - }
1037   - function invoke(currentTarget, event, phase, eventPath, overrideTarget) {
1038   - var listeners = listenersTable.get(currentTarget);
1039   - if (!listeners) return true;
1040   - var target = overrideTarget || eventRetargetting(eventPath, currentTarget);
1041   - if (target === currentTarget) {
1042   - if (phase === CAPTURING_PHASE) return true;
1043   - if (phase === BUBBLING_PHASE) phase = AT_TARGET;
1044   - } else if (phase === BUBBLING_PHASE && !event.bubbles) {
1045   - return true;
1046   - }
1047   - if ("relatedTarget" in event) {
1048   - var originalEvent = unwrap(event);
1049   - var unwrappedRelatedTarget = originalEvent.relatedTarget;
1050   - if (unwrappedRelatedTarget) {
1051   - if (unwrappedRelatedTarget instanceof Object && unwrappedRelatedTarget.addEventListener) {
1052   - var relatedTarget = wrap(unwrappedRelatedTarget);
1053   - var adjusted = relatedTargetResolution(event, currentTarget, relatedTarget);
1054   - if (adjusted === target) return true;
1055   - } else {
1056   - adjusted = null;
1057   - }
1058   - relatedTargetTable.set(event, adjusted);
1059   - }
1060   - }
1061   - eventPhaseTable.set(event, phase);
1062   - var type = event.type;
1063   - var anyRemoved = false;
1064   - targetTable.set(event, target);
1065   - currentTargetTable.set(event, currentTarget);
1066   - listeners.depth++;
1067   - for (var i = 0, len = listeners.length; i < len; i++) {
1068   - var listener = listeners[i];
1069   - if (listener.removed) {
1070   - anyRemoved = true;
1071   - continue;
1072   - }
1073   - if (listener.type !== type || !listener.capture && phase === CAPTURING_PHASE || listener.capture && phase === BUBBLING_PHASE) {
1074   - continue;
1075   - }
1076   - try {
1077   - if (typeof listener.handler === "function") listener.handler.call(currentTarget, event); else listener.handler.handleEvent(event);
1078   - if (stopImmediatePropagationTable.get(event)) return false;
1079   - } catch (ex) {
1080   - if (!pendingError) pendingError = ex;
1081   - }
1082   - }
1083   - listeners.depth--;
1084   - if (anyRemoved && listeners.depth === 0) {
1085   - var copy = listeners.slice();
1086   - listeners.length = 0;
1087   - for (var i = 0; i < copy.length; i++) {
1088   - if (!copy[i].removed) listeners.push(copy[i]);
1089   - }
1090   - }
1091   - return !stopPropagationTable.get(event);
1092   - }
1093   - function Listener(type, handler, capture) {
1094   - this.type = type;
1095   - this.handler = handler;
1096   - this.capture = Boolean(capture);
1097   - }
1098   - Listener.prototype = {
1099   - equals: function(that) {
1100   - return this.handler === that.handler && this.type === that.type && this.capture === that.capture;
1101   - },
1102   - get removed() {
1103   - return this.handler === null;
1104   - },
1105   - remove: function() {
1106   - this.handler = null;
1107   - }
1108   - };
1109   - var OriginalEvent = window.Event;
1110   - OriginalEvent.prototype.polymerBlackList_ = {
1111   - returnValue: true,
1112   - keyLocation: true
1113   - };
1114   - function Event(type, options) {
1115   - if (type instanceof OriginalEvent) {
1116   - var impl = type;
1117   - if (!OriginalBeforeUnloadEvent && impl.type === "beforeunload" && !(this instanceof BeforeUnloadEvent)) {
1118   - return new BeforeUnloadEvent(impl);
1119   - }
1120   - setWrapper(impl, this);
1121   - } else {
1122   - return wrap(constructEvent(OriginalEvent, "Event", type, options));
1123   - }
1124   - }
1125   - Event.prototype = {
1126   - get target() {
1127   - return targetTable.get(this);
1128   - },
1129   - get currentTarget() {
1130   - return currentTargetTable.get(this);
1131   - },
1132   - get eventPhase() {
1133   - return eventPhaseTable.get(this);
1134   - },
1135   - get path() {
1136   - var eventPath = eventPathTable.get(this);
1137   - if (!eventPath) return [];
1138   - return eventPath.slice();
1139   - },
1140   - stopPropagation: function() {
1141   - stopPropagationTable.set(this, true);
1142   - },
1143   - stopImmediatePropagation: function() {
1144   - stopPropagationTable.set(this, true);
1145   - stopImmediatePropagationTable.set(this, true);
1146   - }
1147   - };
1148   - registerWrapper(OriginalEvent, Event, document.createEvent("Event"));
1149   - function unwrapOptions(options) {
1150   - if (!options || !options.relatedTarget) return options;
1151   - return Object.create(options, {
1152   - relatedTarget: {
1153   - value: unwrap(options.relatedTarget)
1154   - }
1155   - });
1156   - }
1157   - function registerGenericEvent(name, SuperEvent, prototype) {
1158   - var OriginalEvent = window[name];
1159   - var GenericEvent = function(type, options) {
1160   - if (type instanceof OriginalEvent) setWrapper(type, this); else return wrap(constructEvent(OriginalEvent, name, type, options));
1161   - };
1162   - GenericEvent.prototype = Object.create(SuperEvent.prototype);
1163   - if (prototype) mixin(GenericEvent.prototype, prototype);
1164   - if (OriginalEvent) {
1165   - try {
1166   - registerWrapper(OriginalEvent, GenericEvent, new OriginalEvent("temp"));
1167   - } catch (ex) {
1168   - registerWrapper(OriginalEvent, GenericEvent, document.createEvent(name));
1169   - }
1170   - }
1171   - return GenericEvent;
1172   - }
1173   - var UIEvent = registerGenericEvent("UIEvent", Event);
1174   - var CustomEvent = registerGenericEvent("CustomEvent", Event);
1175   - var relatedTargetProto = {
1176   - get relatedTarget() {
1177   - var relatedTarget = relatedTargetTable.get(this);
1178   - if (relatedTarget !== undefined) return relatedTarget;
1179   - return wrap(unwrap(this).relatedTarget);
1180   - }
1181   - };
1182   - function getInitFunction(name, relatedTargetIndex) {
1183   - return function() {
1184   - arguments[relatedTargetIndex] = unwrap(arguments[relatedTargetIndex]);
1185   - var impl = unwrap(this);
1186   - impl[name].apply(impl, arguments);
1187   - };
1188   - }
1189   - var mouseEventProto = mixin({
1190   - initMouseEvent: getInitFunction("initMouseEvent", 14)
1191   - }, relatedTargetProto);
1192   - var focusEventProto = mixin({
1193   - initFocusEvent: getInitFunction("initFocusEvent", 5)
1194   - }, relatedTargetProto);
1195   - var MouseEvent = registerGenericEvent("MouseEvent", UIEvent, mouseEventProto);
1196   - var FocusEvent = registerGenericEvent("FocusEvent", UIEvent, focusEventProto);
1197   - var defaultInitDicts = Object.create(null);
1198   - var supportsEventConstructors = function() {
1199   - try {
1200   - new window.FocusEvent("focus");
1201   - } catch (ex) {
1202   - return false;
1203   - }
1204   - return true;
1205   - }();
1206   - function constructEvent(OriginalEvent, name, type, options) {
1207   - if (supportsEventConstructors) return new OriginalEvent(type, unwrapOptions(options));
1208   - var event = unwrap(document.createEvent(name));
1209   - var defaultDict = defaultInitDicts[name];
1210   - var args = [ type ];
1211   - Object.keys(defaultDict).forEach(function(key) {
1212   - var v = options != null && key in options ? options[key] : defaultDict[key];
1213   - if (key === "relatedTarget") v = unwrap(v);
1214   - args.push(v);
1215   - });
1216   - event["init" + name].apply(event, args);
1217   - return event;
1218   - }
1219   - if (!supportsEventConstructors) {
1220   - var configureEventConstructor = function(name, initDict, superName) {
1221   - if (superName) {
1222   - var superDict = defaultInitDicts[superName];
1223   - initDict = mixin(mixin({}, superDict), initDict);
1224   - }
1225   - defaultInitDicts[name] = initDict;
1226   - };
1227   - configureEventConstructor("Event", {
1228   - bubbles: false,
1229   - cancelable: false
1230   - });
1231   - configureEventConstructor("CustomEvent", {
1232   - detail: null
1233   - }, "Event");
1234   - configureEventConstructor("UIEvent", {
1235   - view: null,
1236   - detail: 0
1237   - }, "Event");
1238   - configureEventConstructor("MouseEvent", {
1239   - screenX: 0,
1240   - screenY: 0,
1241   - clientX: 0,
1242   - clientY: 0,
1243   - ctrlKey: false,
1244   - altKey: false,
1245   - shiftKey: false,
1246   - metaKey: false,
1247   - button: 0,
1248   - relatedTarget: null
1249   - }, "UIEvent");
1250   - configureEventConstructor("FocusEvent", {
1251   - relatedTarget: null
1252   - }, "UIEvent");
1253   - }
1254   - var OriginalBeforeUnloadEvent = window.BeforeUnloadEvent;
1255   - function BeforeUnloadEvent(impl) {
1256   - Event.call(this, impl);
1257   - }
1258   - BeforeUnloadEvent.prototype = Object.create(Event.prototype);
1259   - mixin(BeforeUnloadEvent.prototype, {
1260   - get returnValue() {
1261   - return unsafeUnwrap(this).returnValue;
1262   - },
1263   - set returnValue(v) {
1264   - unsafeUnwrap(this).returnValue = v;
1265   - }
1266   - });
1267   - if (OriginalBeforeUnloadEvent) registerWrapper(OriginalBeforeUnloadEvent, BeforeUnloadEvent);
1268   - function isValidListener(fun) {
1269   - if (typeof fun === "function") return true;
1270   - return fun && fun.handleEvent;
1271   - }
1272   - function isMutationEvent(type) {
1273   - switch (type) {
1274   - case "DOMAttrModified":
1275   - case "DOMAttributeNameChanged":
1276   - case "DOMCharacterDataModified":
1277   - case "DOMElementNameChanged":
1278   - case "DOMNodeInserted":
1279   - case "DOMNodeInsertedIntoDocument":
1280   - case "DOMNodeRemoved":
1281   - case "DOMNodeRemovedFromDocument":
1282   - case "DOMSubtreeModified":
1283   - return true;
1284   - }
1285   - return false;
1286   - }
1287   - var OriginalEventTarget = window.EventTarget;
1288   - function EventTarget(impl) {
1289   - setWrapper(impl, this);
1290   - }
1291   - var methodNames = [ "addEventListener", "removeEventListener", "dispatchEvent" ];
1292   - [ Node, Window ].forEach(function(constructor) {
1293   - var p = constructor.prototype;
1294   - methodNames.forEach(function(name) {
1295   - Object.defineProperty(p, name + "_", {
1296   - value: p[name]
1297   - });
1298   - });
1299   - });
1300   - function getTargetToListenAt(wrapper) {
1301   - if (wrapper instanceof wrappers.ShadowRoot) wrapper = wrapper.host;
1302   - return unwrap(wrapper);
1303   - }
1304   - EventTarget.prototype = {
1305   - addEventListener: function(type, fun, capture) {
1306   - if (!isValidListener(fun) || isMutationEvent(type)) return;
1307   - var listener = new Listener(type, fun, capture);
1308   - var listeners = listenersTable.get(this);
1309   - if (!listeners) {
1310   - listeners = [];
1311   - listeners.depth = 0;
1312   - listenersTable.set(this, listeners);
1313   - } else {
1314   - for (var i = 0; i < listeners.length; i++) {
1315   - if (listener.equals(listeners[i])) return;
1316   - }
1317   - }
1318   - listeners.push(listener);
1319   - var target = getTargetToListenAt(this);
1320   - target.addEventListener_(type, dispatchOriginalEvent, true);
1321   - },
1322   - removeEventListener: function(type, fun, capture) {
1323   - capture = Boolean(capture);
1324   - var listeners = listenersTable.get(this);
1325   - if (!listeners) return;
1326   - var count = 0, found = false;
1327   - for (var i = 0; i < listeners.length; i++) {
1328   - if (listeners[i].type === type && listeners[i].capture === capture) {
1329   - count++;
1330   - if (listeners[i].handler === fun) {
1331   - found = true;
1332   - listeners[i].remove();
1333   - }
1334   - }
1335   - }
1336   - if (found && count === 1) {
1337   - var target = getTargetToListenAt(this);
1338   - target.removeEventListener_(type, dispatchOriginalEvent, true);
1339   - }
1340   - },
1341   - dispatchEvent: function(event) {
1342   - var nativeEvent = unwrap(event);
1343   - var eventType = nativeEvent.type;
1344   - handledEventsTable.set(nativeEvent, false);
1345   - scope.renderAllPending();
1346   - var tempListener;
1347   - if (!hasListenerInAncestors(this, eventType)) {
1348   - tempListener = function() {};
1349   - this.addEventListener(eventType, tempListener, true);
1350   - }
1351   - try {
1352   - return unwrap(this).dispatchEvent_(nativeEvent);
1353   - } finally {
1354   - if (tempListener) this.removeEventListener(eventType, tempListener, true);
1355   - }
1356   - }
1357   - };
1358   - function hasListener(node, type) {
1359   - var listeners = listenersTable.get(node);
1360   - if (listeners) {
1361   - for (var i = 0; i < listeners.length; i++) {
1362   - if (!listeners[i].removed && listeners[i].type === type) return true;
1363   - }
1364   - }
1365   - return false;
1366   - }
1367   - function hasListenerInAncestors(target, type) {
1368   - for (var node = unwrap(target); node; node = node.parentNode) {
1369   - if (hasListener(wrap(node), type)) return true;
1370   - }
1371   - return false;
1372   - }
1373   - if (OriginalEventTarget) registerWrapper(OriginalEventTarget, EventTarget);
1374   - function wrapEventTargetMethods(constructors) {
1375   - forwardMethodsToWrapper(constructors, methodNames);
1376   - }
1377   - var originalElementFromPoint = document.elementFromPoint;
1378   - function elementFromPoint(self, document, x, y) {
1379   - scope.renderAllPending();
1380   - var element = wrap(originalElementFromPoint.call(unsafeUnwrap(document), x, y));
1381   - if (!element) return null;
1382   - var path = getEventPath(element, null);
1383   - var idx = path.lastIndexOf(self);
1384   - if (idx == -1) return null; else path = path.slice(0, idx);
1385   - return eventRetargetting(path, self);
1386   - }
1387   - function getEventHandlerGetter(name) {
1388   - return function() {
1389   - var inlineEventHandlers = eventHandlersTable.get(this);
1390   - return inlineEventHandlers && inlineEventHandlers[name] && inlineEventHandlers[name].value || null;
1391   - };
1392   - }
1393   - function getEventHandlerSetter(name) {
1394   - var eventType = name.slice(2);
1395   - return function(value) {
1396   - var inlineEventHandlers = eventHandlersTable.get(this);
1397   - if (!inlineEventHandlers) {
1398   - inlineEventHandlers = Object.create(null);
1399   - eventHandlersTable.set(this, inlineEventHandlers);
1400   - }
1401   - var old = inlineEventHandlers[name];
1402   - if (old) this.removeEventListener(eventType, old.wrapped, false);
1403   - if (typeof value === "function") {
1404   - var wrapped = function(e) {
1405   - var rv = value.call(this, e);
1406   - if (rv === false) e.preventDefault(); else if (name === "onbeforeunload" && typeof rv === "string") e.returnValue = rv;
1407   - };
1408   - this.addEventListener(eventType, wrapped, false);
1409   - inlineEventHandlers[name] = {
1410   - value: value,
1411   - wrapped: wrapped
1412   - };
1413   - }
1414   - };
1415   - }
1416   - scope.elementFromPoint = elementFromPoint;
1417   - scope.getEventHandlerGetter = getEventHandlerGetter;
1418   - scope.getEventHandlerSetter = getEventHandlerSetter;
1419   - scope.wrapEventTargetMethods = wrapEventTargetMethods;
1420   - scope.wrappers.BeforeUnloadEvent = BeforeUnloadEvent;
1421   - scope.wrappers.CustomEvent = CustomEvent;
1422   - scope.wrappers.Event = Event;
1423   - scope.wrappers.EventTarget = EventTarget;
1424   - scope.wrappers.FocusEvent = FocusEvent;
1425   - scope.wrappers.MouseEvent = MouseEvent;
1426   - scope.wrappers.UIEvent = UIEvent;
1427   - })(window.ShadowDOMPolyfill);
1428   - (function(scope) {
1429   - "use strict";
1430   - var UIEvent = scope.wrappers.UIEvent;
1431   - var mixin = scope.mixin;
1432   - var registerWrapper = scope.registerWrapper;
1433   - var setWrapper = scope.setWrapper;
1434   - var unsafeUnwrap = scope.unsafeUnwrap;
1435   - var wrap = scope.wrap;
1436   - var OriginalTouchEvent = window.TouchEvent;
1437   - if (!OriginalTouchEvent) return;
1438   - var nativeEvent;
1439   - try {
1440   - nativeEvent = document.createEvent("TouchEvent");
1441   - } catch (ex) {
1442   - return;
1443   - }
1444   - var nonEnumDescriptor = {
1445   - enumerable: false
1446   - };
1447   - function nonEnum(obj, prop) {
1448   - Object.defineProperty(obj, prop, nonEnumDescriptor);
1449   - }
1450   - function Touch(impl) {
1451   - setWrapper(impl, this);
1452   - }
1453   - Touch.prototype = {
1454   - get target() {
1455   - return wrap(unsafeUnwrap(this).target);
1456   - }
1457   - };
1458   - var descr = {
1459   - configurable: true,
1460   - enumerable: true,
1461   - get: null
1462   - };
1463   - [ "clientX", "clientY", "screenX", "screenY", "pageX", "pageY", "identifier", "webkitRadiusX", "webkitRadiusY", "webkitRotationAngle", "webkitForce" ].forEach(function(name) {
1464   - descr.get = function() {
1465   - return unsafeUnwrap(this)[name];
1466   - };
1467   - Object.defineProperty(Touch.prototype, name, descr);
1468   - });
1469   - function TouchList() {
1470   - this.length = 0;
1471   - nonEnum(this, "length");
1472   - }
1473   - TouchList.prototype = {
1474   - item: function(index) {
1475   - return this[index];
1476   - }
1477   - };
1478   - function wrapTouchList(nativeTouchList) {
1479   - var list = new TouchList();
1480   - for (var i = 0; i < nativeTouchList.length; i++) {
1481   - list[i] = new Touch(nativeTouchList[i]);
1482   - }
1483   - list.length = i;
1484   - return list;
1485   - }
1486   - function TouchEvent(impl) {
1487   - UIEvent.call(this, impl);
1488   - }
1489   - TouchEvent.prototype = Object.create(UIEvent.prototype);
1490   - mixin(TouchEvent.prototype, {
1491   - get touches() {
1492   - return wrapTouchList(unsafeUnwrap(this).touches);
1493   - },
1494   - get targetTouches() {
1495   - return wrapTouchList(unsafeUnwrap(this).targetTouches);
1496   - },
1497   - get changedTouches() {
1498   - return wrapTouchList(unsafeUnwrap(this).changedTouches);
1499   - },
1500   - initTouchEvent: function() {
1501   - throw new Error("Not implemented");
1502   - }
1503   - });
1504   - registerWrapper(OriginalTouchEvent, TouchEvent, nativeEvent);
1505   - scope.wrappers.Touch = Touch;
1506   - scope.wrappers.TouchEvent = TouchEvent;
1507   - scope.wrappers.TouchList = TouchList;
1508   - })(window.ShadowDOMPolyfill);
1509   - (function(scope) {
1510   - "use strict";
1511   - var unsafeUnwrap = scope.unsafeUnwrap;
1512   - var wrap = scope.wrap;
1513   - var nonEnumDescriptor = {
1514   - enumerable: false
1515   - };
1516   - function nonEnum(obj, prop) {
1517   - Object.defineProperty(obj, prop, nonEnumDescriptor);
1518   - }
1519   - function NodeList() {
1520   - this.length = 0;
1521   - nonEnum(this, "length");
1522   - }
1523   - NodeList.prototype = {
1524   - item: function(index) {
1525   - return this[index];
1526   - }
1527   - };
1528   - nonEnum(NodeList.prototype, "item");
1529   - function wrapNodeList(list) {
1530   - if (list == null) return list;
1531   - var wrapperList = new NodeList();
1532   - for (var i = 0, length = list.length; i < length; i++) {
1533   - wrapperList[i] = wrap(list[i]);
1534   - }
1535   - wrapperList.length = length;
1536   - return wrapperList;
1537   - }
1538   - function addWrapNodeListMethod(wrapperConstructor, name) {
1539   - wrapperConstructor.prototype[name] = function() {
1540   - return wrapNodeList(unsafeUnwrap(this)[name].apply(unsafeUnwrap(this), arguments));
1541   - };
1542   - }
1543   - scope.wrappers.NodeList = NodeList;
1544   - scope.addWrapNodeListMethod = addWrapNodeListMethod;
1545   - scope.wrapNodeList = wrapNodeList;
1546   - })(window.ShadowDOMPolyfill);
1547   - (function(scope) {
1548   - "use strict";
1549   - scope.wrapHTMLCollection = scope.wrapNodeList;
1550   - scope.wrappers.HTMLCollection = scope.wrappers.NodeList;
1551   - })(window.ShadowDOMPolyfill);
1552   - (function(scope) {
1553   - "use strict";
1554   - var EventTarget = scope.wrappers.EventTarget;
1555   - var NodeList = scope.wrappers.NodeList;
1556   - var TreeScope = scope.TreeScope;
1557   - var assert = scope.assert;
1558   - var defineWrapGetter = scope.defineWrapGetter;
1559   - var enqueueMutation = scope.enqueueMutation;
1560   - var getTreeScope = scope.getTreeScope;
1561   - var isWrapper = scope.isWrapper;
1562   - var mixin = scope.mixin;
1563   - var registerTransientObservers = scope.registerTransientObservers;
1564   - var registerWrapper = scope.registerWrapper;
1565   - var setTreeScope = scope.setTreeScope;
1566   - var unsafeUnwrap = scope.unsafeUnwrap;
1567   - var unwrap = scope.unwrap;
1568   - var unwrapIfNeeded = scope.unwrapIfNeeded;
1569   - var wrap = scope.wrap;
1570   - var wrapIfNeeded = scope.wrapIfNeeded;
1571   - var wrappers = scope.wrappers;
1572   - function assertIsNodeWrapper(node) {
1573   - assert(node instanceof Node);
1574   - }
1575   - function createOneElementNodeList(node) {
1576   - var nodes = new NodeList();
1577   - nodes[0] = node;
1578   - nodes.length = 1;
1579   - return nodes;
1580   - }
1581   - var surpressMutations = false;
1582   - function enqueueRemovalForInsertedNodes(node, parent, nodes) {
1583   - enqueueMutation(parent, "childList", {
1584   - removedNodes: nodes,
1585   - previousSibling: node.previousSibling,
1586   - nextSibling: node.nextSibling
1587   - });
1588   - }
1589   - function enqueueRemovalForInsertedDocumentFragment(df, nodes) {
1590   - enqueueMutation(df, "childList", {
1591   - removedNodes: nodes
1592   - });
1593   - }
1594   - function collectNodes(node, parentNode, previousNode, nextNode) {
1595   - if (node instanceof DocumentFragment) {
1596   - var nodes = collectNodesForDocumentFragment(node);
1597   - surpressMutations = true;
1598   - for (var i = nodes.length - 1; i >= 0; i--) {
1599   - node.removeChild(nodes[i]);
1600   - nodes[i].parentNode_ = parentNode;
1601   - }
1602   - surpressMutations = false;
1603   - for (var i = 0; i < nodes.length; i++) {
1604   - nodes[i].previousSibling_ = nodes[i - 1] || previousNode;
1605   - nodes[i].nextSibling_ = nodes[i + 1] || nextNode;
1606   - }
1607   - if (previousNode) previousNode.nextSibling_ = nodes[0];
1608   - if (nextNode) nextNode.previousSibling_ = nodes[nodes.length - 1];
1609   - return nodes;
1610   - }
1611   - var nodes = createOneElementNodeList(node);
1612   - var oldParent = node.parentNode;
1613   - if (oldParent) {
1614   - oldParent.removeChild(node);
1615   - }
1616   - node.parentNode_ = parentNode;
1617   - node.previousSibling_ = previousNode;
1618   - node.nextSibling_ = nextNode;
1619   - if (previousNode) previousNode.nextSibling_ = node;
1620   - if (nextNode) nextNode.previousSibling_ = node;
1621   - return nodes;
1622   - }
1623   - function collectNodesNative(node) {
1624   - if (node instanceof DocumentFragment) return collectNodesForDocumentFragment(node);
1625   - var nodes = createOneElementNodeList(node);
1626   - var oldParent = node.parentNode;
1627   - if (oldParent) enqueueRemovalForInsertedNodes(node, oldParent, nodes);
1628   - return nodes;
1629   - }
1630   - function collectNodesForDocumentFragment(node) {
1631   - var nodes = new NodeList();
1632   - var i = 0;
1633   - for (var child = node.firstChild; child; child = child.nextSibling) {
1634   - nodes[i++] = child;
1635   - }
1636   - nodes.length = i;
1637   - enqueueRemovalForInsertedDocumentFragment(node, nodes);
1638   - return nodes;
1639   - }
1640   - function snapshotNodeList(nodeList) {
1641   - return nodeList;
1642   - }
1643   - function nodeWasAdded(node, treeScope) {
1644   - setTreeScope(node, treeScope);
1645   - node.nodeIsInserted_();
1646   - }
1647   - function nodesWereAdded(nodes, parent) {
1648   - var treeScope = getTreeScope(parent);
1649   - for (var i = 0; i < nodes.length; i++) {
1650   - nodeWasAdded(nodes[i], treeScope);
1651   - }
1652   - }
1653   - function nodeWasRemoved(node) {
1654   - setTreeScope(node, new TreeScope(node, null));
1655   - }
1656   - function nodesWereRemoved(nodes) {
1657   - for (var i = 0; i < nodes.length; i++) {
1658   - nodeWasRemoved(nodes[i]);
1659   - }
1660   - }
1661   - function ensureSameOwnerDocument(parent, child) {
1662   - var ownerDoc = parent.nodeType === Node.DOCUMENT_NODE ? parent : parent.ownerDocument;
1663   - if (ownerDoc !== child.ownerDocument) ownerDoc.adoptNode(child);
1664   - }
1665   - function adoptNodesIfNeeded(owner, nodes) {
1666   - if (!nodes.length) return;
1667   - var ownerDoc = owner.ownerDocument;
1668   - if (ownerDoc === nodes[0].ownerDocument) return;
1669   - for (var i = 0; i < nodes.length; i++) {
1670   - scope.adoptNodeNoRemove(nodes[i], ownerDoc);
1671   - }
1672   - }
1673   - function unwrapNodesForInsertion(owner, nodes) {
1674   - adoptNodesIfNeeded(owner, nodes);