-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvw-polyfill.min.js
59 lines (52 loc) · 1.92 KB
/
vw-polyfill.min.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
/** vw-polyfill[https://github.com/RaySnow/vw-polyfill] by [email protected] MIT **/!function () {
function i(e, t) {
if (e.type && (e.type = "text/css"), e.styleSheet) return e.styleSheet.cssText = t;
t = document.createTextNode(t);
e.appendChild(t)
}
function e() {
function d(t) {
var n = /([+-]?[0-9.]+)vw/, e = document.createElement("style"), o = t.match(/([+-]?[0-9.]+)vw/g);
o && (o.forEach(function (e) {
t = t.replace(n, e.replace("vw", "rem"))
}), i(e, t), (document.head || document.getElementsByTagName("head")[0]).appendChild(e))
}
var e = document.getElementsByTagName("link"), t = document.getElementsByTagName("style"), n = [].forEach;
n.call(t, function (e) {
d(e.textContent)
}), n.call(e, function (e) {
var t, n, o;
t = e.href, n = function () {
d(this.responseText)
}, (e = new XMLHttpRequest).open("GET", t, !0), e.onload = n, e.onerror = o, e.send()
})
}
function a() {
try {
n = document.documentElement, t(), window.addEventListener("resize", t), window.addEventListener("pageshow", function (e) {
e.persisted && t()
}), e()
} catch (e) {
void 0
}
function t() {
var e = n.clientWidth / 100;
n.style.fontSize = e + "px"
}
var n
}
function t() {
try {
if (!window) return;
var t = document.body, n = document.getElementsByTagName("head")[0], o = document.createElement("div"),
d = document.createElement("style"), c = parseInt(window.innerWidth / 2, 10);
o.id = "testVw", t.appendChild(o), n.appendChild(d), i(d, "#testVw { width: 50vw; }"), setTimeout(function () {
var e;
parseInt((e = o, window.getComputedStyle ? getComputedStyle(e, null) : e.currentStyle).width, 10) === c && a(), t.removeChild(o), n.removeChild(d)
}, 1)
} catch (e) {
void 0
}
}
window.__vwPolyfill = {init: t}, t()
}();