PageSourceSearch

http://www.fps-solutions.com/sites/all/modules/browserclass/browserclass.js?rvxt6o

js fps-solutions.com collected 2026-10-02 23:03:48 UTC 7,164 bytes, 252 lines download raw bytes

1
2(function ($) {
3  var BrowserClass = {
4    init: function() {
5      this.classes = [];
6      this.agent = navigator.userAgent.toLowerCase();
7      this.checkBrowser();
8      this.checkPlatform();
9      if (this.isMobile(this.classes)) {
10        this.classes.push('mobile');
11      } else {
12        this.classes.push('desktop');
13      }
14    },
15
16    checkBrowser: function() {
17      var matches = Array();
18      var aresult = '';
19      var aversion = '';
20      var resultant = '';
21
22      var iePattern = /(?:\b(ms)?ie\s+|\btrident\/7\.0;.*\s+rv:)(\d+)/;
23      var ieMatch = this.agent.match(iePattern);
24
25      if (ieMatch) {
26        this.classes.push('ie');
27
28        if (typeof ieMatch[2] !== 'undefined') {
29          this.classes.push('ie' + ieMatch[2]);
30        }
31      }
32
33      if (this.agent.match(/opera/)) {
34        this.classes.push('opera');
35        
36        aresult = this.stristr(this.agent, 'version').split('/');
37        if(aresult[1]) {
38          aversion = aresult[1].split(' ');
39          this.classes.push('opera' + this.clearVersion(aversion[0]));
40        }
41      }
42
43      // Check for chrome desktop first, then chrome mobile, lastly check for
44      // safari, as these are mutually exclusive.
45      if (this.agent.match(/chrome/)) {
46        this.classes.push('chrome');
47        
48        aresult = this.stristr(this.agent, 'chrome').split('/');
49        aversion = aresult[1].split(' ');
50        this.classes.push('chrome' + this.clearVersion(aversion[0]));
51      } else if (this.agent.match(/crios/)) {
52        this.classes.push('chrome');
53        aresult = this.stristr(this.agent, 'crios').split('/');
54
55        if (aresult[1]) {
56          aversion = aresult[1].split(' ');
57          this.classes.push('chrome' + this.clearVersion(aversion[0]));
58        }
59      } else if (this.agent.match(/safari/)) {
60        this.classes.push('safari');
61        aresult = this.stristr(this.agent, 'version').split('/');
62        
63        if(aresult[1]) {
64          aversion = aresult[1].split(' ');
65          this.classes.push('safari' + this.clearVersion(aversion[0]));
66        }
67      }
68
69      if (this.agent.match(/netscape/)) {
70        this.classes.push('netscape');
71        
72        matches = this.agent.match(/navigator\/([^ ]*)/);
73        if (matches) {
74          this.classes.push('netscape' + this.clearVersion(matches[1]));
75        }
76        else {
77          matches = this.agent.match(/netscape6?\/([^ ]*)/);
78          if (matches) {
79            this.classes.push('netscape' + this.clearVersion(matches[1]));
80          }
81        }
82      }
83
84      if (this.agent.match(/firefox/)) {
85        this.classes.push('ff');
86        matches = this.agent.match(/firefox[\/ \(]([^ ;\)]+)/);
87        if(matches) {
88          this.classes.push('ff' + this.clearVersion(matches[1]));
89        }
90      }
91
92      if (this.agent.match(/konqueror/)) {
93        this.classes.push('konqueror');
94        
95        aresult = this.stristr(this.agent, 'konqueror').split(' ');
96        aversion = aresult[0].split('/');
97        this.classes.push('konqueror' + this.clearVersion(aversion[1]));
98      }
99
100      if (this.agent.match(/dillo/)) {
101        this.classes.push('dillo');
102      }
103
104      if (this.agent.match(/chimera/)) {
105        this.classes.push('chimera');
106      }
107
108      if (this.agent.match(/beonex/)) {
109        this.classes.push('beonex');
110      }
111
112      if (this.agent.match(/aweb/)) {
113        this.classes.push('aweb');
114      }
115
116      if (this.agent.match(/amaya/)) {
117        this.classes.push('amaya');
118      }
119
120      if (this.agent.match(/icab/)) {
121        this.classes.push('icab');
122      }
123
124      if (this.agent.match(/lynx/)) {
125        this.classes.push('lynx');
126      }
127
128      if (this.agent.match(/galeon/)) {
129        this.classes.push('galeon');
130      }
131
132      if (this.agent.match(/opera mini/)) {
133        this.classes.push('operamini');
134        
135        resultant = this.stristr(this.agent, 'opera mini');
136        if(resultant.match('/\//')) {
137          aresult = resultant.split('/');
138          aversion = aresult[1].split(' ');
139          this.classes.push('operamini' + this.clearVersion(aversion[0]));
140        }
141        else {
142          aversion = this.stristr(resultant, 'opera mini').split(' ');
143          this.classes.push('operamini' + this.clearVersion(aversion[1]));
144        }
145      }
146    },
147
148    checkPlatform: function() {
149      if (this.agent.match(/windows/)) {
150        this.classes.push('win');
151      }
152
153      if (this.agent.match(/ipad/)) {
154        this.classes.push('ipad');
155      }
156
157      if (this.agent.match(/ipod/)) {
158        this.classes.push('ipod');
159      }
160
161      if (this.agent.match(/iphone/)) {
162        this.classes.push('iphone');
163      }
164
165      if (this.agent.match(/mac/)) {
166        this.classes.push('mac');
167      }
168
169      if (this.agent.match(/android/)) {
170        this.classes.push('android');
171      }
172
173      if (this.agent.match(/linux/)) {
174        this.classes.push('linux');
175      }
176
177      if (this.agent.match(/nokia/)) {
178        this.classes.push('nokia');
179      }
180
181      if (this.agent.match(/blackberry/)) {
182        this.classes.push('blackberry');
183      }
184
185      if (this.agent.match(/freebsd/)) {
186        this.classes.push('freebsd');
187      }
188
189      if (this.agent.match(/openbsd/)) {
190        this.classes.push('openbsd');
191      }
192
193      if (this.agent.match(/netbsd/)) {
194        this.classes.push('netbsd');
195      }
196    },
197
198    isMobile: function(classes) {
199      var mobile_devices = ['ipad', 'ipod', 'iphone', 'android', 'blackberry', 'operamini'];
200      var mobile_devices_test = false;
201
202      $.each(mobile_devices, function(index, value) {
203        if ($.inArray(value, classes) != -1) {
204          mobile_devices_test = true;
205
206          // Terminate the $.each() loop, since a match has been found.
207          return false;
208        }
209      });
210
211      if (mobile_devices_test || this.agent.match(/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|pda|psp|treo)/)) {
212        return true;
213      }
214    },
215    
216    clearVersion: function(version) {
217      version = version.replace('/[^0-9,.,a-z,A-Z-]/', '');
218      var find = (version + '').indexOf('.');
219      return version.substr(0, find);
220    },
221    
222    stristr: function(haystack, needle, bool) {
223      // Finds first occurrence of a string within another, case insensitive  
224      // 
225      // version: 1103.1210
226      // discuss at: http://phpjs.org/functions/stristr
227      // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
228      // +   bugfxied by: Onno Marsman
229      // *     example 1: stristr('Kevin van Zonneveld', 'Van');
230      // *     returns 1: 'van Zonneveld'
231      // *     example 2: stristr('Kevin van Zonneveld', 'VAN', true);
232      // *     returns 2: 'Kevin '
233      var pos = 0;
234
235      haystack += '';
236      pos = haystack.toLowerCase().indexOf((needle + '').toLowerCase());
237      if (pos == -1) {
238          return false;
239      } else {
240          if (bool) {
241              return haystack.substr(0, pos);
242          } else {
243              return haystack.slice(pos);
244          }
245      }
246    }
247
248  };
249
250  BrowserClass.init();
251  $('body').addClass(BrowserClass.classes.join(' '));
252})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.