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