This repository has been archived by the owner on Jun 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
webcomponents-platform.js
135 lines (121 loc) · 4 KB
/
webcomponents-platform.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
* @license
* Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
(function() {
'use strict';
// defaultPrevented is broken in IE.
// https://connect.microsoft.com/IE/feedback/details/790389/event-defaultprevented-returns-false-after-preventdefault-was-called
var workingDefaultPrevented = (function() {
var e = document.createEvent('Event');
e.initEvent('foo', true, true);
e.preventDefault();
return e.defaultPrevented;
})();
if (!workingDefaultPrevented) {
var origPreventDefault = Event.prototype.preventDefault;
Event.prototype.preventDefault = function() {
if (!this.cancelable) {
return;
}
origPreventDefault.call(this);
Object.defineProperty(this, 'defaultPrevented', {
get: function() {
return true;
},
configurable: true
});
};
}
var isIE = /Trident/.test(navigator.userAgent);
// Event constructor shim
if (!window.Event || isIE && (typeof window.Event !== 'function')) {
var origEvent = window.Event;
/**
* @param {!string} inType
* @param {?(EventInit)=} params
*/
window.Event = function(inType, params) {
params = params || {};
var e = document.createEvent('Event');
e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable));
return e;
};
if (origEvent) {
for (var i in origEvent) {
window.Event[i] = origEvent[i];
}
window.Event.prototype = origEvent.prototype;
}
}
// CustomEvent constructor shim
if (!window.CustomEvent || isIE && (typeof window.CustomEvent !== 'function')) {
/**
* @template T
* @param {!string} inType
* @param {?(CustomEventInit<T>)=} params
*/
window.CustomEvent = function(inType, params) {
params = params || {};
var e = /** @type {!CustomEvent} */ (document.createEvent('CustomEvent'));
e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable), params.detail);
return e;
};
window.CustomEvent.prototype = window.Event.prototype;
}
if (!window.MouseEvent || isIE && (typeof window.MouseEvent !== 'function')) {
var origMouseEvent = window.MouseEvent;
/**
*
* @param {!string} inType
* @param {?(MouseEventInit)=} params
*/
window.MouseEvent = function(inType, params) {
params = params || {};
var e = document.createEvent('MouseEvent');
e.initMouseEvent(inType,
Boolean(params.bubbles), Boolean(params.cancelable),
params.view || window, params.detail,
params.screenX, params.screenY, params.clientX, params.clientY,
params.ctrlKey, params.altKey, params.shiftKey, params.metaKey,
params.button, params.relatedTarget);
return e;
};
if (origMouseEvent) {
for (var i in origMouseEvent) {
window.MouseEvent[i] = origMouseEvent[i];
}
}
window.MouseEvent.prototype = origMouseEvent.prototype;
}
// ES6 stuff
if (!Array.from) {
Array.from = function (object) {
return [].slice.call(/** @type {IArrayLike} */(object));
};
}
if (!Object.assign) {
var assign = function(target, source) {
var n$ = Object.getOwnPropertyNames(source);
for (var i=0, p; i < n$.length; i++) {
p = n$[i];
target[p] = source[p];
}
}
Object.assign = function(target, sources) {
var args = [].slice.call(arguments, 1);
for (var i=0, s; i < args.length; i++) {
s = args[i];
if (s) {
assign(target, s);
}
}
return target;
}
}
})();