forked from eviweb/css_browser_selector
-
Notifications
You must be signed in to change notification settings - Fork 1
/
css_browser_selector_dev.js
165 lines (137 loc) · 6.16 KB
/
css_browser_selector_dev.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
CSS Browser Selector 0.6.1
Originally written by Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Co-maintained by:
https://github.com/verbatim/css_browser_selector
*/
showLog=true;
function log(m) {if ( window.console && showLog ) {console.log(m); } }
/*
Default config for CSS browser selector
You can overwrite config variables with:
var CSS_BROWSER_SELECTOR_CONFIG = {
'showScreenSize': true
}
Add this to your HTML head before css_browser_selector_dev.js is loaded.
*/
var showScreenSize = false;
// End default configuration
function css_browser_selector(u)
{
var uaInfo = {},
screens = [320, 480, 640, 768, 1024, 1152, 1280, 1440, 1680, 1920, 2560],
allScreens = screens.length,
ua=u.toLowerCase(),
is=function(t) { return RegExp(t,"i").test(ua); },
version = function(p,n)
{
n=n.replace(".","_"); var i = n.indexOf('_'), ver="";
while (i>0) {ver += " "+ p+n.substring(0,i);i = n.indexOf('_', i+1);}
ver += " "+p+n; return ver;
},
g='gecko',
w='webkit',
c='chrome',
f='firefox',
s='safari',
o='opera',
a='android',
bb='blackberry',
lang='lang_',
dv='device_',
html=document.documentElement,
b= [
// browser
(!(/opera|webtv|firefox/i.test(ua))&&/trident|msie/i.test(ua)&&/(msie\s|rv\:)(\d+)/.test(ua))?('ie ie'+(/trident\/4\.0/.test(ua) ? '8' : RegExp.$2))
:is('firefox/')?g+ " " + f+(/firefox\/((\d+)(\.(\d+))(\.\d+)*)/.test(ua)?' '+f+RegExp.$2 + ' '+f+RegExp.$2+"_"+RegExp.$4:'')
:is('gecko/')?g
:is('opera')?o+(/version\/((\d+)(\.(\d+))(\.\d+)*)/.test(ua)?' '+o+RegExp.$2 + ' '+o+RegExp.$2+"_"+RegExp.$4 : (/opera(\s|\/)(\d+)\.(\d+)/.test(ua)?' '+o+RegExp.$2+" "+o+RegExp.$2+"_"+RegExp.$3:''))
:is('konqueror')?'konqueror'
:is('blackberry') ?
(
( /Version\/(\d+)(\.(\d+)+)/i.test(ua)
? " " + bb+ RegExp.$1 + " "+bb+ RegExp.$1+RegExp.$2.replace('.','_')
: (/Blackberry ?(([0-9]+)([a-z]?))[\/|;]/gi.test(ua)
? ' ' +bb+RegExp.$2 + (RegExp.$3?' ' +bb+RegExp.$2+RegExp.$3:'')
: '')
)
) // blackberry
:is('android') ?
(
( /Version\/(\d+)(\.(\d+))+/i.test(ua)
? " " + a+ RegExp.$1 + " "+a+ RegExp.$1+RegExp.$2.replace('.','_')
: '')
+ (/Android (.+); (.+) Build/i.test(ua)
? ' '+dv+( (RegExp.$2).replace(/ /g,"_") ).replace(/-/g,"_")
:'' )
) //android
:is('chrome')?w+ ' '+c+(/chrome\/((\d+)(\.(\d+))(\.\d+)*)/.test(ua)?' '+c+RegExp.$2 +((RegExp.$4>0) ? ' '+c+RegExp.$2+"_"+RegExp.$4:''):'')
:is('iron')?w+' iron'
:is('applewebkit/') ?
( w+ ' '+ s +
( /version\/((\d+)(\.(\d+))(\.\d+)*)/.test(ua)
? ' '+ s +RegExp.$2 + " "+s+ RegExp.$2+RegExp.$3.replace('.','_')
: ( / Safari\/(\d+)/i.test(ua)
?
( (RegExp.$1=="419" || RegExp.$1=="417" || RegExp.$1=="416" || RegExp.$1=="412" ) ? ' '+ s + '2_0'
: RegExp.$1=="312" ? ' '+ s + '1_3'
: RegExp.$1=="125" ? ' '+ s + '1_2'
: RegExp.$1=="85" ? ' '+ s + '1_0'
: '' )
:'')
)
) //applewebkit
:is('mozilla/')?g
:''
// os/platform
,is('j2me')?'j2me'
:is('playbook')?'playbook'
:is('kindle|silk')?'kindle'
:is('playbook')?'playbook'
:is('mac')?'mac'+ (/mac os x ((\d+)[.|_](\d+))/.test(ua) ? ( ' mac' + (RegExp.$2) + ' mac' + (RegExp.$1).replace('.',"_") ) : '' )
:is('win')?'win'+
(is('windows nt 6.2')?' win8'
:is('windows nt 6.1')?' win7'
:is('windows nt 6.0')?' vista'
:is('windows nt 5.2') || is('windows nt 5.1') ? ' win_xp'
:is('windows nt 5.0')?' win_2k'
:is('windows nt 4.0') || is('WinNT4.0') ?' win_nt'
: ''
)
:is('freebsd')?'freebsd'
:(is('x11|linux'))?'linux'
:''
// user agent language
,(/[; |\[](([a-z]{2})(\-[a-z]{2})?)[)|;|\]]/i.test(ua))?(lang+RegExp.$2).replace("-","_")+(RegExp.$3!=''?(' '+lang+RegExp.$1).replace("-","_"):''):''
// beta: test if running iPad app
,( is('ipad|iphone|ipod') && !is('safari') ) ? 'ipad_app' : ''
], // b
config = {};
// Get default config and from global var CSS_BROWSER_SELECTOR_CONFIG
config.showScreensize = showScreenSize;
if(typeof CSS_BROWSER_SELECTOR_CONFIG != 'undefined') {
if(CSS_BROWSER_SELECTOR_CONFIG.showScreenSize != undefined) {
config.showScreenSize = CSS_BROWSER_SELECTOR_CONFIG.showScreenSize;
}
}
function screenSize()
{
var w = window.outerWidth || html.clientWidth;
// var h = window.outerHeight || html.clientHeight;
for (var i=(allScreens-1);i>=0;i--) { if (w >= screens[i] ) { uaInfo.maxw = screens[i]; break; }}
var widthClasses="";
for (var info in uaInfo) { widthClasses+=" "+info+"_"+ uaInfo[info] };
html.className = ( html.className +widthClasses );
return widthClasses;
} // screenSize
if(config.showScreenSize) {
window.onresize = screenSize;
screenSize();
}
var cssbs = (b.join(' ')) + " js ";
html.className = ( cssbs + html.className.replace(/\b(no[-|_]?)?js\b/g,"") ).replace(/^ /, "").replace(/ +/g," ");
return cssbs;
}
css_browser_selector(navigator.userAgent);