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
111 lines (97 loc) · 2.76 KB
/
polyfills.js
File metadata and controls
111 lines (97 loc) · 2.76 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
/* eslint-disable no-extend-native, one-var, no-self-compare */
import { isSSR } from './plugins/platform'
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 && 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 (!isSSR && 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
}
}
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
}
})
}