Skip to content

Commit 0a44995

Browse files
committed
Backport relevant parts of @webcomponents/platform
1 parent 8fc25a6 commit 0a44995

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed

.editorconfig

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
trim_trailing_whitespace = true
7+
indent_style = space
8+
indent_size = 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2016 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+
11+
(function() {
12+
'use strict';
13+
14+
// defaultPrevented is broken in IE.
15+
// https://connect.microsoft.com/IE/feedback/details/790389/event-defaultprevented-returns-false-after-preventdefault-was-called
16+
var workingDefaultPrevented = (function() {
17+
var e = document.createEvent('Event');
18+
e.initEvent('foo', true, true);
19+
e.preventDefault();
20+
return e.defaultPrevented;
21+
})();
22+
23+
if (!workingDefaultPrevented) {
24+
var origPreventDefault = Event.prototype.preventDefault;
25+
Event.prototype.preventDefault = function() {
26+
if (!this.cancelable) {
27+
return;
28+
}
29+
30+
origPreventDefault.call(this);
31+
32+
Object.defineProperty(this, 'defaultPrevented', {
33+
get: function() {
34+
return true;
35+
},
36+
configurable: true
37+
});
38+
};
39+
}
40+
41+
var isIE = /Trident/.test(navigator.userAgent);
42+
43+
// Event constructor shim
44+
if (!window.Event || isIE && (typeof window.Event !== 'function')) {
45+
var origEvent = window.Event;
46+
/**
47+
* @param {!string} inType
48+
* @param {?(EventInit)=} params
49+
*/
50+
window.Event = function(inType, params) {
51+
params = params || {};
52+
var e = document.createEvent('Event');
53+
e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable));
54+
return e;
55+
};
56+
if (origEvent) {
57+
for (var i in origEvent) {
58+
window.Event[i] = origEvent[i];
59+
}
60+
window.Event.prototype = origEvent.prototype;
61+
}
62+
}
63+
64+
// CustomEvent constructor shim
65+
if (!window.CustomEvent || isIE && (typeof window.CustomEvent !== 'function')) {
66+
/**
67+
* @template T
68+
* @param {!string} inType
69+
* @param {?(CustomEventInit<T>)=} params
70+
*/
71+
window.CustomEvent = function(inType, params) {
72+
params = params || {};
73+
var e = document.createEvent('CustomEvent');
74+
e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable), params.detail);
75+
return e;
76+
};
77+
window.CustomEvent.prototype = window.Event.prototype;
78+
}
79+
80+
if (!window.MouseEvent || isIE && (typeof window.MouseEvent !== 'function')) {
81+
var origMouseEvent = window.MouseEvent;
82+
/**
83+
*
84+
* @param {!string} inType
85+
* @param {?(MouseEventInit)=} params
86+
*/
87+
window.MouseEvent = function(inType, params) {
88+
params = params || {};
89+
var e = document.createEvent('MouseEvent');
90+
e.initMouseEvent(inType,
91+
Boolean(params.bubbles), Boolean(params.cancelable),
92+
params.view || window, params.detail,
93+
params.screenX, params.screenY, params.clientX, params.clientY,
94+
params.ctrlKey, params.altKey, params.shiftKey, params.metaKey,
95+
params.button, params.relatedTarget);
96+
return e;
97+
};
98+
if (origMouseEvent) {
99+
for (var i in origMouseEvent) {
100+
window.MouseEvent[i] = origMouseEvent[i];
101+
}
102+
}
103+
window.MouseEvent.prototype = origMouseEvent.prototype;
104+
}
105+
})();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2016 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+
11+
(function() {
12+
'use strict';
13+
14+
if (!Array.from) {
15+
Array.from = function (object) {
16+
return [].slice.call(/** @type {IArrayLike} */(object));
17+
};
18+
}
19+
20+
if (!Object.assign) {
21+
var assign = function(target, source) {
22+
var n$ = Object.getOwnPropertyNames(source);
23+
for (var i=0, p; i < n$.length; i++) {
24+
p = n$[i];
25+
target[p] = source[p];
26+
}
27+
}
28+
29+
Object.assign = function(target, sources) {
30+
var args = [].slice.call(arguments, 1);
31+
for (var i=0, s; i < args.length; i++) {
32+
s = args[i];
33+
if (s) {
34+
assign(target, s);
35+
}
36+
}
37+
return target;
38+
}
39+
}
40+
})();

0 commit comments

Comments
 (0)