forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolyfills.js
More file actions
171 lines (151 loc) · 4.35 KB
/
polyfills.js
File metadata and controls
171 lines (151 loc) · 4.35 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* eslint-disable no-extend-native, one-var, no-self-compare */
import { isSSR } from './plugins/platform.js'
function assign (target, firstSource) {
if (target === undefined || target === null) {
throw new TypeError('Cannot convert first argument to object')
}
var to = Object(target)
for (var i = 1; i < arguments.length; i++) {
var nextSource = arguments[i]
if (nextSource === undefined || nextSource === null) {
continue
}
var keysArray = Object.keys(Object(nextSource))
for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
var nextKey = keysArray[nextIndex]
var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey)
if (desc !== undefined && desc.enumerable) {
to[nextKey] = nextSource[nextKey]
}
}
}
return to
}
if (!Object.assign) {
Object.defineProperty(Object, 'assign', {
enumerable: false,
configurable: true,
writable: true,
value: assign
})
}
if (!Number.isInteger) {
Number.isInteger = function (value) {
return typeof value === 'number' &&
isFinite(value) &&
Math.floor(value) === value
}
}
if (!Array.prototype.includes) {
Array.prototype.includes = function (searchEl, startFrom) {
'use strict'
let O = Object(this)
let len = parseInt(O.length, 10) || 0
if (len === 0) {
return false
}
let n = parseInt(startFrom, 10) || 0
let k
if (n >= 0) {
k = n
}
else {
k = len + n
if (k < 0) { k = 0 }
}
let curEl
while (k < len) {
curEl = O[k]
if (searchEl === curEl ||
(searchEl !== searchEl && curEl !== curEl)) { // NaN !== NaN
return true
}
k++
}
return false
}
}
if (!String.prototype.startsWith) {
String.prototype.startsWith = function (str, position) {
position = position || 0
return this.substr(position, str.length) === str
}
}
if (!String.prototype.endsWith) {
String.prototype.endsWith = function (str, position) {
let subjectString = this.toString()
if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
position = subjectString.length
}
position -= str.length
let lastIndex = subjectString.indexOf(str, position)
return lastIndex !== -1 && lastIndex === position
}
}
if (!isSSR) {
if (typeof Element.prototype.matches !== 'function') {
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.mozMatchesSelector || Element.prototype.webkitMatchesSelector || function matches (selector) {
let
element = this,
elements = (element.document || element.ownerDocument).querySelectorAll(selector),
index = 0
while (elements[index] && elements[index] !== element) {
++index
}
return Boolean(elements[index])
}
}
if (typeof Element.prototype.closest !== 'function') {
Element.prototype.closest = function closest (selector) {
let el = this
while (el && el.nodeType === 1) {
if (el.matches(selector)) {
return el
}
el = el.parentNode
}
return null
}
}
// from:https://github.com/jserz/js_piece/blob/master/DOM/ChildNode/remove()/remove().md
(function (arr) {
arr.forEach(item => {
if (item.hasOwnProperty('remove')) { return }
Object.defineProperty(item, 'remove', {
configurable: true,
enumerable: true,
writable: true,
value () {
if (this.parentNode !== null) {
this.parentNode.removeChild(this)
}
}
})
})
})([Element.prototype, CharacterData.prototype, DocumentType.prototype])
}
if (!Array.prototype.find) {
Object.defineProperty(Array.prototype, 'find', {
value (predicate) {
'use strict'
if (this == null) {
throw new TypeError('Array.prototype.find called on null or undefined')
}
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function')
}
let value
const
list = Object(this),
length = list.length >>> 0,
thisArg = arguments[1]
for (let i = 0; i < length; i++) {
value = list[i]
if (predicate.call(thisArg, value, i, list)) {
return value
}
}
return undefined
}
})
}