-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetect_flex.js
More file actions
77 lines (59 loc) · 1.82 KB
/
detect_flex.js
File metadata and controls
77 lines (59 loc) · 1.82 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
;
/** TAB === 2 space
*
*
______________________________________________________________________*/
(function () {
window._DD;
var documentLink = document,
getComputedStyleLink = window.getComputedStyle,
documentHeadLink = documentLink.getElementsByTagName('head')[0],
elementForTesting = documentLink.createElement('p'),
elementForTestingStyle = elementForTesting.style,
display = 'display',
displayVariant = [
'flex', // 1
'-webkit-flex', // 2
'-ms-flexbox', // 3
'-webkit-box', // 4
'-moz-box', // 5
'table', // 6
'inline' // 7
],
abilityFlexWrap = [
'flexWrap',
'WebkitFlexWrap',
'msFlexWrap'
];
documentHeadLink.appendChild(elementForTesting);
for (var i = 0, len = displayVariant.length; i < len; i++) {
if (abilityFlexWrap[i] && !(abilityFlexWrap[i] in elementForTestingStyle)) continue;
elementForTestingStyle.cssText = display + ':' + displayVariant[i];
var getDisplayStyle =
(getComputedStyleLink) ? getComputedStyleLink(elementForTesting, null).getPropertyValue(display) :
elementForTesting.currentStyle[display];
if (getDisplayStyle == displayVariant[i]) {
_DD = i + 1;
break;
}
}
documentHeadLink.removeChild(elementForTesting);
if (_DD != 1) {
var load = documentLink.createElement('link'),
url =
(_DD < 4) ? 'supportVendor.css' :
(_DD < 6) ? 'supportBox.css' :
(_DD < 7) ? 'supportTable.css' :
'supportInline.css';
load.type = 'text/css';
load.href = url;
load.rel = 'stylesheet';
documentHeadLink.appendChild(load);
}
if (!window.matchMedia && !window.msMatchMedia && !window.CSSMediaRule) {
var load = documentLink.createElement('script');
load.type = 'text/javascript';
load.src = 'respond.js'; // https://github.com/scottjehl/Respond
documentHeadLink.appendChild(load);
}
})();