PageSourceSearch

https://www.barwoodpilon.com/js/detectizr.js

js barwoodpilon.com collected 2026-10-05 04:10:45 UTC 17,713 bytes, 527 lines download raw bytes

1/*!
2 * Detectizr v@VERSION
3 * http://barisaydinoglu.github.com/Detectizr/
4 *
5 * Written by Baris Aydinoglu (http://baris.aydinoglu.info) - Copyright 2012
6 * Released under the MIT license
7 *
8 * Date: @DATE
9 */
10window.Detectizr = (function(window, navigator, document, undefined) {
11	var Detectizr = {},
12		Modernizr = window.Modernizr,
13		deviceTypes = ["tv", "tablet", "mobile", "desktop"],
14		options = {
15			// option for enabling HTML classes of all features (not only the true features) to be added
16			addAllFeaturesAsClass: false,
17			// option for enabling detection of device
18			detectDevice: true,
19			// option for enabling detection of device model
20			detectDeviceModel: true,
21			// option for enabling detection of screen size
22			detectScreen: true,
23			// option for enabling detection of operating system type and version
24			detectOS: true,
25			// option for enabling detection of browser type and version
26			detectBrowser: true,
27			// option for enabling detection of common browser plugins
28			detectPlugins: true
29		},
30		plugins2detect = [{
31			name: "adobereader",
32			substrs: ["Adobe", "Acrobat"],
33			// AcroPDF.PDF is used by version 7 and later
34			// PDF.PdfCtrl is used by version 6 and earlier
35			progIds: ["AcroPDF.PDF", "PDF.PDFCtrl.5"]
36		}, {
37			name: "flash",
38			substrs: ["Shockwave Flash"],
39			progIds: ["ShockwaveFlash.ShockwaveFlash.1"]
40		}, {
41			name: "wmplayer",
42			substrs: ["Windows Media"],
43			progIds: ["wmplayer.ocx"]
44		}, {
45			name: "silverlight",
46			substrs: ["Silverlight"],
47			progIds: ["AgControl.AgControl"]
48		}, {
49			name: "quicktime",
50			substrs: ["QuickTime"],
51			progIds: ["QuickTime.QuickTime"]
52		}],
53		rclass = /[\t\r\n]/g,
54		docElement = document.documentElement,
55		resizeTimeoutId,
56		oldOrientation;
57
58	// Create Global "extend" method, so Detectizr does not need jQuery.extend
59	function extend(obj, extObj) {
60		var a, b, i;
61		if (arguments.length > 2) {
62			for (a = 1, b = arguments.length; a < b; a += 1) {
63				extend(obj, arguments[a]);
64			}
65		} else {
66			for (i in extObj) {
67				if (extObj.hasOwnProperty(i)) {
68					obj[i] = extObj[i];
69				}
70			}
71		}
72		return obj;
73	}
74
75	// simplified and localized indexOf method as one parameter fixed as useragent
76	function is(key) {
77		return Detectizr.browser.userAgent.indexOf(key) > -1;
78	}
79
80	// simplified and localized regex test method as one parameter fixed as useragent
81	function test(regex) {
82		return regex.test(Detectizr.browser.userAgent);
83	}
84
85	// simplified and localized regex exec method as one parameter fixed as useragent
86	function exec(regex) {
87		return regex.exec(Detectizr.browser.userAgent);
88	}
89
90	// localized string trim method
91	function trim(value) {
92		return value.replace(/^\s+|\s+$/g, "");
93	}
94
95	// convert string to camelcase
96	function toCamel(string) {
97		if (string === null || string === undefined) {
98			return "";
99		}
100		return String(string).replace(/((\s|\-|\.)+[a-z0-9])/g, function($1) {
101			return $1.toUpperCase().replace(/(\s|\-|\.)/g, "");
102		});
103	}
104
105	// removeClass function inspired from jQuery.removeClass
106	function removeClass(element, value) {
107		var class2remove = value || "",
108			cur = element.nodeType === 1 && (element.className ? (" " + element.className + " ").replace(rclass, " ") : "");
109		if (cur) {
110			while (cur.indexOf(" " + class2remove + " ") >= 0) {
111				cur = cur.replace(" " + class2remove + " ", " ");
112			}
113			element.className = value ? trim(cur) : "";
114		}
115	}
116
117	// add version test to Modernizr
118	function addVersionTest(version, major, minor) {
119		if (!!version) {
120			version = toCamel(version);
121			if (!!major) {
122				major = toCamel(major);
123				addConditionalTest(version + major, true);
124				if (!!minor) {
125					addConditionalTest(version + major + "_" + minor, true);
126				}
127			}
128		}
129	}
130
131	// add test to Modernizr based on a condition
132	function addConditionalTest(feature, test) {
133		if (!!feature && !!Modernizr) {
134			if (options.addAllFeaturesAsClass) {
135				Modernizr.addTest(feature, test);
136			} else {
137				test = typeof test === "function" ? test() : test;
138				if (test) {
139					Modernizr.addTest(feature, true);
140				} else {
141					delete Modernizr[feature];
142					removeClass(docElement, feature);
143				}
144			}
145		}
146	}
147
148	// set version based on versionFull
149	function setVersion(versionType, versionFull) {
150		versionType.version = versionFull;
151		var versionArray = versionFull.split(".");
152		if (versionArray.length > 0) {
153			versionArray = versionArray.reverse();
154			versionType.major = versionArray.pop();
155			if (versionArray.length > 0) {
156				versionType.minor = versionArray.pop();
157				if (versionArray.length > 0) {
158					versionArray = versionArray.reverse();
159					versionType.patch = versionArray.join(".");
160				} else {
161					versionType.patch = "0";
162				}
163			} else {
164				versionType.minor = "0";
165			}
166		} else {
167			versionType.major = "0";
168		}
169	}
170
171	function checkOrientation() {
172		//timeout wrapper points with doResizeCode as callback
173		window.clearTimeout(resizeTimeoutId);
174		resizeTimeoutId = window.setTimeout(function() {
175			oldOrientation = Detectizr.device.orientation;
176			//wrapper for height/width check
177			if (window.innerHeight > window.innerWidth) {
178				Detectizr.device.orientation = "portrait";
179			} else {
180				Detectizr.device.orientation = "landscape";
181			}
182			addConditionalTest(Detectizr.device.orientation, true);
183			if (oldOrientation !== Detectizr.device.orientation) {
184				addConditionalTest(oldOrientation, false);
185			}
186		}, 10);
187	}
188
189	function detectPlugin(substrs) {
190		var plugins = navigator.plugins,
191			plugin, haystack, pluginFoundText, j, k;
192		for (j = plugins.length - 1; j >= 0; j--) {
193			plugin = plugins[j];
194			haystack = plugin.name + plugin.description;
195			pluginFoundText = 0;
196			for (k = substrs.length; k >= 0; k--) {
197				if (haystack.indexOf(substrs[k]) !== -1) {
198					pluginFoundText += 1;
199				}
200			}
201			if (pluginFoundText === substrs.length) {
202				return true;
203			}
204		}
205		return false;
206	}
207
208	function detectObject(progIds) {
209		var j;
210		for (j = progIds.length - 1; j >= 0; j--) {
211			try {
212				new ActiveXObject(progIds[j]);
213			} catch (e) {
214				// Ignore
215			}
216		}
217		return false;
218	}
219
220	function detect(opt) {
221		var i, j, device, os, browser, plugin2detect, pluginFound;
222
223		options = extend({}, options, opt || {});
224
225		/** Device detection **/
226		if (options.detectDevice) {
227			Detectizr.device = {
228				type: "",
229				model: "",
230				orientation: ""
231			};
232			device = Detectizr.device;
233			if (test(/googletv|smarttv|smart-tv|internet.tv|netcast|nettv|appletv|boxee|kylo|roku|dlnadoc|roku|pov_tv|hbbtv|ce\-html/)) {
234				// Check if user agent is a smart tv
235				device.type = deviceTypes[0];
236				device.model = "smartTv";
237			} else if (test(/xbox|playstation.3|wii/)) {
238				// Check if user agent is a game console
239				device.type = deviceTypes[0];
240				device.model = "gameConsole";
241			} else if (test(/ip(a|ro)d/)) {
242				// Check if user agent is a iPad
243				device.type = deviceTypes[1];
244				device.model = "ipad";
245			} else if ((test(/tablet/) && !test(/rx-34/)) || test(/folio/)) {
246				// Check if user agent is a Tablet
247				device.type = deviceTypes[1];
248				device.model = String(exec(/playbook/) || "");
249			} else if (test(/linux/) && test(/android/) && !test(/fennec|mobi|htc.magic|htcX06ht|nexus.one|sc-02b|fone.945/)) {
250				// Check if user agent is an Android Tablet
251				device.type = deviceTypes[1];
252				device.model = "android";
253			} else if (test(/kindle/) || (test(/mac.os/) && test(/silk/))) {
254				// Check if user agent is a Kindle or Kindle Fire
255				device.type = deviceTypes[1];
256				device.model = "kindle";
257			} else if (test(/gt-p10|sc-01c|shw-m180s|sgh-t849|sch-i800|shw-m180l|sph-p100|sgh-i987|zt180|htc(.flyer|\_flyer)|sprint.atp51|viewpad7|pandigital(sprnova|nova)|ideos.s7|dell.streak.7|advent.vega|a101it|a70bht|mid7015|next2|nook/) || (test(/mb511/) && test(/rutem/))) {
258				// Check if user agent is a pre Android 3.0 Tablet
259				device.type = deviceTypes[1];
260				device.model = "android";
261			} else if (test(/bb10/)) {
262				// Check if user agent is a BB10 device
263				device.type = deviceTypes[1];
264				device.model = "blackberry";
265			} else {
266				// Check if user agent is one of common mobile types
267				device.model = exec(/iphone|ipod|android|blackberry|opera mini|opera mobi|skyfire|maemo|windows phone|palm|iemobile|symbian|symbianos|fennec|j2me/);
268				if (device.model !== null) {
269					device.type = deviceTypes[2];
270					device.model = String(device.model);
271				} else {
272					device.model = "";
273					if (test(/bolt|fennec|iris|maemo|minimo|mobi|mowser|netfront|novarra|prism|rx-34|skyfire|tear|xv6875|xv6975|google.wireless.transcoder/)) {
274						// Check if user agent is unique Mobile User Agent
275						device.type = deviceTypes[2];
276					} else if (test(/opera/) && test(/windows.nt.5/) && test(/htc|xda|mini|vario|samsung\-gt\-i8000|samsung\-sgh\-i9/)) {
277						// Check if user agent is an odd Opera User Agent - http://goo.gl/nK90K
278						device.type = deviceTypes[2];
279					} else if ((test(/windows.(nt|xp|me|9)/) && !test(/phone/)) || test(/win(9|.9|nt)/) || test(/\(windows 8\)/)) {
280						// Check if user agent is Windows Desktop, "(Windows 8)" Chrome extra exception
281						device.type = deviceTypes[3];
282					} else if (test(/macintosh|powerpc/) && !test(/silk/)) {
283						// Check if agent is Mac Desktop
284						device.type = deviceTypes[3];
285						device.model = "mac";
286					} else if (test(/linux/) && test(/x11/)) {
287						// Check if user agent is a Linux Desktop
288						device.type = deviceTypes[3];
289					} else if (test(/solaris|sunos|bsd/)) {
290						// Check if user agent is a Solaris, SunOS, BSD Desktop
291						device.type = deviceTypes[3];
292					} else if (test(/cros/)) {
293						// Check if user agent is a Chromebook
294						device.type = deviceTypes[3];
295					} else if (test(/bot|crawler|spider|yahoo|ia_archiver|covario-ids|findlinks|dataparksearch|larbin|mediapartners-google|ng-search|snappy|teoma|jeeves|tineye/) && !test(/mobile/)) {
296						// Check if user agent is a Desktop BOT/Crawler/Spider
297						device.type = deviceTypes[3];
298						device.model = "crawler";
299					} else {
300						// Otherwise assume it is a Mobile Device
301						device.type = deviceTypes[2];
302					}
303				}
304			}
305			for (i = 0, j = deviceTypes.length; i < j; i += 1) {
306				addConditionalTest(deviceTypes[i], (device.type === deviceTypes[i]));
307			}
308			if (options.detectDeviceModel) {
309				addConditionalTest(toCamel(device.model), true);
310			}
311		}
312
313		/** Screen detection **/
314		if (options.detectScreen) {
315			device.screen = {};
316			if (!!Modernizr && !!Modernizr.mq) {
317				if (Modernizr.mq("only screen and (max-width: 240px)")) {
318					device.screen.size = "veryVerySmall";
319					addConditionalTest("veryVerySmallScreen", true);
320				} else if (Modernizr.mq("only screen and (max-width: 320px)")) {
321					device.screen.size = "verySmall";
322					addConditionalTest("verySmallScreen", true);
323				} else if (Modernizr.mq("only screen and (max-width: 480px)")) {
324					device.screen.size = "small";
325					addConditionalTest("smallScreen", true);
326				}
327				if (device.type === deviceTypes[1] || device.type === deviceTypes[2]) {
328					if (Modernizr.mq("only screen and (-moz-min-device-pixel-ratio: 1.3), only screen and (-o-min-device-pixel-ratio: 2.6/2), only screen and (-webkit-min-device-pixel-ratio: 1.3), only screen  and (min-device-pixel-ratio: 1.3), only screen and (min-resolution: 1.3dppx)")) {
329						device.screen.resolution = "high";
330						addConditionalTest("highresolution", true);
331					}
332				}
333			}
334			if (device.type === deviceTypes[1] || device.type === deviceTypes[2]) {
335				window.onresize = function(event) {
336					checkOrientation(event);
337				};
338				checkOrientation();
339			} else {
340				device.orientation = "landscape";
341				addConditionalTest(device.orientation, true);
342			}
343		}
344
345		/** OS detection **/
346		if (options.detectOS) {
347			Detectizr.os = {};
348			os = Detectizr.os;
349			if (device.model !== "") {
350				if (device.model === "ipad" || device.model === "iphone" || device.model === "ipod") {
351					os.name = "ios";
352					setVersion(os, (test(/os\s([\d_]+)/) ? RegExp.$1 : "").replace(/_/g, "."));
353				} else if (device.model === "android") {
354					os.name = "android";
355					setVersion(os, (test(/android\s([\d\.]+)/) ? RegExp.$1 : ""));
356				} else if (device.model === "blackberry") {
357					os.name = "blackberry";
358					setVersion(os, (test(/version\/([^\s]+)/) ? RegExp.$1 : ""));
359				} else if (device.model === "playbook") {
360					os.name = "blackberry";
361					setVersion(os, (test(/os ([^\s]+)/) ? RegExp.$1.replace(";", "") : ""));
362				}
363			}
364			if (!os.name) {
365				if (is("win") || is("16bit")) {
366					os.name = "windows";
367					if (is("windows nt 10")) {
368						setVersion(os, "10");
369					} else if (is("windows nt 6.3")) {
370						setVersion(os, "8.1");
371					} else if (is("windows nt 6.2") || test(/\(windows 8\)/)) { //windows 8 chrome mac fix
372						setVersion(os, "8");
373					} else if (is("windows nt 6.1")) {
374						setVersion(os, "7");
375					} else if (is("windows nt 6.0")) {
376						setVersion(os, "vista");
377					}
377 else if (is("windows nt 5.2") || is("windows nt 5.1") || is("windows xp")) {
378						setVersion(os, "xp");
379					} else if (is("windows nt 5.0") || is("windows 2000")) {
380						setVersion(os, "2k");
381					} else if (is("winnt") || is("windows nt")) {
382						setVersion(os, "nt");
383					} else if (is("win98") || is("windows 98")) {
384						setVersion(os, "98");
385					} else if (is("win95") || is("windows 95")) {
386						setVersion(os, "95");
387					}
388				} else if (is("mac") || is("darwin")) {
389					os.name = "mac os";
390					if (is("68k") || is("68000")) {
391						setVersion(os, "68k");
392					} else if (is("ppc") || is("powerpc")) {
393						setVersion(os, "ppc");
394					} else if (is("os x")) {
395						setVersion(os, (test(/os\sx\s([\d_]+)/) ? RegExp.$1 : "os x").replace(/_/g, "."));
396					}
397				} else if (is("webtv")) {
398					os.name = "webtv";
399				} else if (is("x11") || is("inux")) {
400					os.name = "linux";
401				} else if (is("sunos")) {
402					os.name = "sun";
403				} else if (is("irix")) {
404					os.name = "irix";
405				} else if (is("freebsd")) {
406					os.name = "freebsd";
407				} else if (is("bsd")) {
408					os.name = "bsd";
409				}
410			}
411			if (!!os.name) {
412				addConditionalTest(os.name, true);
413				if (!!os.major) {
414					addVersionTest(os.name, os.major);
415					if (!!os.minor) {
416						addVersionTest(os.name, os.major, os.minor);
417					}
418				}
419			}
420			if (test(/\sx64|\sx86|\swin64|\swow64|\samd64/)) {
421				os.addressRegisterSize = "64bit";
422			} else {
423				os.addressRegisterSize = "32bit";
424			}
425			addConditionalTest(os.addressRegisterSize, true);
426		}
427
428		/** Browser detection **/
429		if (options.detectBrowser) {
430			browser = Detectizr.browser;
431			if (!test(/opera|webtv/) && (test(/msie\s([\d\w\.]+)/) || is("trident"))) {
432				browser.engine = "trident";
433				browser.name = "ie";
434				if (!window.addEventListener && document.documentMode && document.documentMode === 7) {
435					setVersion(browser, "8.compat");
436				} else if (test(/trident.*rv[ :](\d+)\./)) {
437					setVersion(browser, RegExp.$1);
438				} else {
439					setVersion(browser, (test(/trident\/4\.0/) ? "8" : RegExp.$1));
440				}
441			} else if (is("firefox")) {
442				browser.engine = "gecko";
443				browser.name = "firefox";
444				setVersion(browser, (test(/firefox\/([\d\w\.]+)/) ? RegExp.$1 : ""));
445			} else if (is("gecko/")) {
446				browser.engine = "gecko";
447			} else if (is("opera")) {
448				browser.name = "opera";
449				browser.engine = "presto";
450				setVersion(browser, (test(/version\/([\d\.]+)/) ? RegExp.$1 : (test(/opera(\s|\/)([\d\.]+)/) ? RegExp.$2 : "")));
451			} else if (is("konqueror")) {
452				browser.name = "konqueror";
453			} else if (is("edge")) {
454				browser.engine = "webkit";
455				browser.name = "edge";
456				setVersion(browser, (test(/edge\/([\d\.]+)/) ? RegExp.$1 : ""));
457			} else if (is("chrome")) {
458				browser.engine = "webkit";
459				browser.name = "chrome";
460				setVersion(browser, (test(/chrome\/([\d\.]+)/) ? RegExp.$1 : ""));
461			} else if (is("iron")) {
462				browser.engine = "webkit";
463				browser.name = "iron";
464			} else if (is("crios")) {
465				browser.name = "chrome";
466				browser.engine = "webkit";
467				setVersion(browser, (test(/crios\/([\d\.]+)/) ? RegExp.$1 : ""));
468			} else if (is("applewebkit/")) {
469				browser.name = "safari";
470				browser.engine = "webkit";
471				setVersion(browser, (test(/version\/([\d\.]+)/) ? RegExp.$1 : ""));
472			} else if (is("mozilla/")) {
473				browser.engine = "gecko";
474			}
475			if (!!browser.name) {
476				addConditionalTest(browser.name, true);
477				if (!!browser.major) {
478					addVersionTest(browser.name, browser.major);
479					if (!!browser.minor) {
480						addVersionTest(browser.name, browser.major, browser.minor);
481					}
482				}
483			}
484			addConditionalTest(browser.engine, true);
485
486			// Browser Language
487			browser.language = navigator.userLanguage || navigator.language;
488			addConditionalTest(browser.language, true);
489		}
490
491		/** Plugin detection **/
492		if (options.detectPlugins) {
493			browser.plugins = [];
494			for (i = plugins2detect.length - 1; i >= 0; i--) {
495				plugin2detect = plugins2detect[i];
496				pluginFound = false;
497				if (window.ActiveXObject) {
498					pluginFound = detectObject(plugin2detect.progIds);
499				} else if (navigator.plugins) {
500					pluginFound = detectPlugin(plugin2detect.substrs);
501				}
502				if (pluginFound) {
503					browser.plugins.push(plugin2detect.name);
504					addConditionalTest(plugin2detect.name, true);
505				}
506			}
507			if (navigator.javaEnabled()) {
508				browser.plugins.push("java");
509				addConditionalTest("java", true);
510			}
511		}
512	}
513	Detectizr.detect = function(settings) {
514		return detect(settings);
515	};
516	Detectizr.init = function() {
517		if (Detectizr !== undefined) {
518			Detectizr.browser = {
519				userAgent: (navigator.userAgent || navigator.vendor || window.opera).toLowerCase()
520			};
521			Detectizr.detect();
522		}
523	};
524	Detectizr.init();
525
526	return Detectizr;
527}(this, this.navigator, this.document));

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.