PageSourceSearch

https://www.apli.com/modules/contrib/browserclass/js/browserclass.js?tlwav8

js apli.com collected 2026-09-25 18:43:20 UTC 7,078 bytes, 249 lines download raw bytes

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