-
Notifications
You must be signed in to change notification settings - Fork 31
/
polyfills.js
58 lines (51 loc) · 1.48 KB
/
polyfills.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
import smoothScroll from 'smoothscroll-polyfill'
smoothScroll.polyfill()
// should be after React import for IE11
// 'require' used because inside condition
if(!!window.MSInputMethodContext && !!document.documentMode) { // IE11 check
require('whatwg-fetch')
// classList.toggle polyfill for IE
DOMTokenList.prototype.toggle = function(token, force) {
if(force === undefined) {
force = !this.contains(token)
}
return this[force ? 'add' : 'remove'](token)
}
}
// node.remove polyfill fro IE
;(function() {
var arr = [window.Element, window.CharacterData, window.DocumentType]
var args = []
arr.forEach(function(item) {
if(item) {
args.push(item.prototype)
}
})
// from:https://github.com/jserz/js_piece/blob/master/DOM/ChildNode/remove()/remove().md
;(function(arr) {
arr.forEach(function(item) {
if(item.hasOwnProperty('remove')) {
return
}
Object.defineProperty(item, 'remove', {
configurable: true,
enumerable: true,
writable: true,
value: function remove() {
this.parentNode.removeChild(this)
},
})
})
})(args)
})()
;(function() {
// IE
if(!Element.prototype.scrollIntoViewIfNeeded) {
Element.prototype.scrollIntoViewIfNeeded = function() {
const rect = this.getBoundingClientRect()
if(rect.top < 0 || rect.bottom > window.innerHeight || rect.left < 0 || rect.right > window.innerWidth) {
this.scrollIntoView()
}
}
}
})()