-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcss_browser_selector.js
151 lines (144 loc) · 4.44 KB
/
css_browser_selector.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
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
/*
CSS Browser Selector js v0.5.3 (July 2, 2013)
-- original --
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://choosealicense.com/licenses/mit/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
-- /original --
Fork project: http://code.google.com/p/css-browser-selector/
Song Hyo-Jin (shj at xenosi.de)
*/
function css_browser_selector(u) {
var ua = u.toLowerCase(),
is = function(t) {
return ua.indexOf(t) > -1
},
g = 'gecko',
w = 'webkit',
s = 'safari',
c = 'chrome',
o = 'opera',
m = 'mobile',
v = 0,
r = window.devicePixelRatio ? (window.devicePixelRatio + '').replace('.', '_') : '1';
var res = [
/* IE */
(!(/opera|webtv/.test(ua)) && /msie\s(\d+)/.test(ua) && (v = RegExp.$1 * 1)) ?
('ie ie' + v + ((v == 6 || v == 7) ?
' ie67 ie678 ie6789' : (v == 8) ?
' ie678 ie6789' : (v == 9) ?
' ie6789 ie9m' : (v > 9 ) ?
' ie9m' : '')) :
/* EDGE */
(/edge\/(\d+)\.(\d+)/.test(ua) && (v = [RegExp.$1, RegExp.$2])) ?
(is('chrome/') ? 'chrome edge' : 'ie ie' + v[0] + ' ie' + v[0] + '_' + v[1] + ' ie9m edge') :
/* IE 11 */
(/trident\/\d+.*?;\s*rv:(\d+)\.(\d+)\)/.test(ua) && (v = [RegExp.$1, RegExp.$2])) ?
'ie ie' + v[0] + ' ie' + v[0] + '_' + v[1] + ' ie9m' :
/* FF */
(/firefox\/(\d+)\.(\d+)/.test(ua) && (re = RegExp)) ?
g + ' ff ff' + re.$1 + ' ff' + re.$1 + '_' + re.$2 :
is('gecko/') ? g :
/* Opera - old */
is(o) ? 'old' + o + (/version\/(\d+)/.test(ua) ? ' ' + o + RegExp.$1 :
(/opera(\s|\/)(\d+)/.test(ua) ? ' ' + o + RegExp.$2 : '')) :
/* K */
is('konqueror') ? 'konqueror' :
/* Black Berry */
is('blackberry') ? m + ' blackberry' :
/* Chrome */
(is(c) || is('crios')) ? w + ' ' + c :
/* Iron */
is('iron') ? w + ' iron' :
/* Safari */
!is('cpu os') && is('applewebkit/') ? w + ' ' + s :
/* Mozilla */
is('mozilla/') ? g : '',
/* Android */
is('android') ? m + ' android' : '',
/* Tablet */
is('tablet') ? 'tablet' : '',
/* blink or webkit engine browsers */
/* Opera */
is('opr/') ? o : '',
/* Yandex */
is('yabrowser') ? 'yandex' : '',
/* Machine */
is('j2me') ? m + ' j2me' :
is('ipad; u; cpu os') ? m + ' chrome android tablet' :
is('ipad;u;cpu os') ? m + ' chromedef android tablet' :
is('iphone') ? m + ' ios iphone' :
is('ipod') ? m + ' ios ipod' :
is('ipad') ? m + ' ios ipad tablet' :
is('mac') ? 'mac' :
is('darwin') ? 'mac' :
is('webtv') ? 'webtv' :
is('win') ? 'win' + (is('windows nt 6.0') ? ' vista' : '') :
is('freebsd') ? 'freebsd' :
(is('x11') || is('linux')) ? 'linux' : '',
/* Ratio (Retina) */
(r != '1') ? ' retina ratio' + r : '',
'js portrait'].join(' ');
if(window.jQuery && !window.jQuery.browser) {
window.jQuery.browser = v ? {msie: 1, version: v} : {};
}
return res;
};
(function(d, w) {
var _c = css_browser_selector(navigator.userAgent);
var h = d.documentElement;
h.className += ' ' + _c;
var _d = _c.replace(/^\s*|\s*$/g, '').split(/ +/);
w.CSSBS = 1;
for(var i = 0; i < _d.length; i++) {
w['CSSBS_' + _d[i]] = 1;
}
var _de = function(v) {
return d.documentElement[v] || d.body[v];
}
if(w.jQuery) {
(function($) {
var p = 'portrait', l = 'landscape';
var m = 'smartnarrow', mw = 'smartwide', t = 'tabletnarrow', tw = 'tabletwide', ac = m + ' ' + mw + ' ' + t + ' ' + tw + ' pc';
var $h = $(h);
var to = 0, cw = 0;
/* ie7 cpu 100% fix */
function CSSSelectorUpdateSize() {
if(to != 0) return;
try {
var _cw = _de('clientWidth'), _ch = _de('clientHeight');
if(_cw > _ch) {
$h.removeClass(p).addClass(l);
} else {
$h.removeClass(l).addClass(p);
}
if(_cw == cw) return;
cw = _cw;
//clearTimeout(to);
} catch(e) {
}
to = setTimeout(CSSSelectorUpdateSize_, 100);
}
function CSSSelectorUpdateSize_() {
try {
$h.removeClass(ac);
$h.addClass(
(cw <= 360) ? m :
(cw <= 640) ? mw :
(cw <= 768) ? t :
(cw <= 1024) ? tw : 'pc'
);
} catch(e) {
}
to = 0;
}
if(w.CSSBS_ie) {
setInterval(CSSSelectorUpdateSize, 1000);
} else {
$(w).on('resize orientationchange', CSSSelectorUpdateSize).trigger('resize');
}
$(w).load(CSSSelectorUpdateSize);
})(w.jQuery);
}
})(document, window);