forked from barisaydinoglu/Detectizr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetectizr.min.js
12 lines (12 loc) · 8.01 KB
/
detectizr.min.js
1
2
3
4
5
6
7
8
9
10
11
12
/*!
* Detectizr v1.4.3
* http://barisaydinoglu.github.com/Detectizr/
* https://github.com/barisaydinoglu/Detectizr
* Written by Baris Aydinoglu (http://baris.aydinoglu.info) - Copyright © 2012
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
(function(d,b){var e=d.Modernizr,c={addAllFeaturesAsClass:false,detectDevice:true,detectDeviceModel:true,detectScreen:true,detectOS:true,detectBrowser:true,detectPlugins:true};function a(h){var w=function(B,l){var k,j,A;if(arguments.length>2){for(k=1,j=arguments.length;k<j;k+=1){w(B,arguments[k])}}else{for(A in l){if(l.hasOwnProperty(A)){B[A]=l[A]}}}return B},u=this,g=e.Detectizr.device,m=document.documentElement,v=["tv","tablet","mobile","desktop"],q={java:{substrs:["Java"],progIds:["JavaWebStart.isInstalled"]},acrobat:{substrs:["Adobe","Acrobat"],progIds:["AcroPDF.PDF","PDF.PDFCtrl.5"]},flash:{substrs:["Shockwave","Flash"],progIds:["ShockwaveFlash.ShockwaveFlash"]},mediaplayer:{substrs:["Windows Media"],progIds:["MediaPlayer.MediaPlayer"]},silverlight:{substrs:["Silverlight"],progIds:["AgControl.AgControl"]}},r,p,o,n,s,t,x,z,y;c=w({},c,h||{});u.is=function(i){return g.userAgent.indexOf(i)>-1};u.test=function(i){return i.test(g.userAgent)};u.exec=function(i){return i.exec(g.userAgent)};u.toCamel=function(i){if(i===null||i===undefined){return""}return String(i).replace(/((\s|\-|\.)+[a-z0-9])/g,function(j){return j.toUpperCase().replace(/(\s|\-|\.)/g,"")})};u.addVersionTest=function(k,j,i){if(j!==null&&j!==undefined&&j!==""){j=u.toCamel(j);if(j!==""){if(i!==undefined&&i>0){j=j.substr(0,i)}u.addConditionalTest(k+j,true)}}};u.checkOrientation=function(){d.clearTimeout(x);x=d.setTimeout(function(){y=g.orientation;if(d.innerHeight>d.innerWidth){g.orientation="portrait"}else{g.orientation="landscape"}u.addConditionalTest(g.orientation,true);if(y!==g.orientation){u.addConditionalTest(y,false)}},10)};u.addConditionalTest=function(i,j){if(i===null||i===undefined||i===""){return}if(c.addAllFeaturesAsClass){e.addTest(i,j)}else{j=typeof j==="function"?j():j;if(j){e.addTest(i,true)}else{delete e[i];z=new RegExp("\\b"+i+"\\b");m.className=m.className.replace(z,"")}}};if(c.detectDevice){if(u.test(/GoogleTV|SmartTV|Internet.TV|NetCast|NETTV|AppleTV|boxee|Kylo|Roku|DLNADOC|CE\-HTML/i)){g.type=v[0];g.model="smartTv"}else{if(u.test(/Xbox|PLAYSTATION.3|Wii/i)){g.type=v[0];g.model="gameConsole"}else{if(u.test(/iP(a|ro)d/i)){g.type=v[1];g.model="ipad"}else{if((u.test(/tablet/i)&&!u.test(/RX-34/i))||u.test(/FOLIO/i)){g.type=v[1]}else{if(u.test(/Linux/i)&&u.test(/Android/i)&&!u.test(/Fennec|mobi|HTC.Magic|HTCX06HT|Nexus.One|SC-02B|fone.945/i)){g.type=v[1];g.model="android"}else{if(u.test(/Kindle/i)||(u.test(/Mac.OS/i)&&u.test(/Silk/i))){g.type=v[1];g.model="kindle"}else{if(u.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/i)||(u.test(/MB511/i)&&u.test(/RUTEM/i))){g.type=v[1];g.model="android"}else{g.model=u.exec(/iphone|ipod|android|blackberry|opera mini|opera mobi|skyfire|maemo|windows phone|palm|iemobile|symbian|symbianos|fennec|j2me/i);if(g.model!==null){g.type=v[2];g.model=String(g.model)}else{g.model="";if(u.test(/BOLT|Fennec|Iris|Maemo|Minimo|Mobi|mowser|NetFront|Novarra|Prism|RX-34|Skyfire|Tear|XV6875|XV6975|Google.Wireless.Transcoder/i)){g.type=v[2]}else{if(u.test(/Opera/i)&&u.test(/Windows.NT.5/i)&&u.test(/HTC|Xda|Mini|Vario|SAMSUNG\-GT\-i8000|SAMSUNG\-SGH\-i9/i)){g.type=v[2]}else{if((u.test(/Windows.(NT|XP|ME|9)/i)&&!u.test(/Phone/i))||u.test(/Win(9|.9|NT)/i)){g.type=v[3]}else{if(u.test(/Macintosh|PowerPC/i)&&!u.test(/Silk/i)){g.type=v[3]}else{if(u.test(/Linux/i)&&u.test(/X11/i)){g.type=v[3]}else{if(u.test(/Solaris|SunOS|BSD/i)){g.type=v[3]}else{if(u.test(/Bot|Crawler|Spider|Yahoo|ia_archiver|Covario-IDS|findlinks|DataparkSearch|larbin|Mediapartners-Google|NG-Search|Snappy|Teoma|Jeeves|TinEye/i)&&!u.test(/Mobile/i)){g.type=v[3];g.model="crawler"}else{g.type=v[2]}}}}}}}}}}}}}}}for(r=0,p=v.length;r<p;r+=1){u.addConditionalTest(v[r],(g.type===v[r]))}if(c.detectDeviceModel){u.addConditionalTest(u.toCamel(g.model),true)}if(g.type===v[1]||g.type===v[2]){d.onresize=function(i){u.checkOrientation(i)};u.checkOrientation()}}if(c.detectScreen&&!!e.mq){u.addConditionalTest("smallScreen",e.mq("only screen and (max-width: 480px)"));u.addConditionalTest("verySmallScreen",e.mq("only screen and (max-width: 320px)"));u.addConditionalTest("veryVerySmallScreen",e.mq("only screen and (max-width: 240px)"))}if(c.detectOS){if(g.model!==""){if(g.model==="ipad"||g.model==="iphone"||g.model==="ipod"){g.osVersion=(u.test(/os\s(\d+)_/)?RegExp.$1:"");g.os="ios"}else{if(g.model==="android"){g.osVersion=(u.test(/os\s(\d+)_/)?RegExp.$1:"").substr(0,2);g.os="android"}}}if(g.os===""){if(u.is("win")||u.is("16bit")){g.os="windows";if(u.is("windows nt 6.2")){g.osVersion="8"}else{if(u.is("windows nt 6.1")){g.osVersion="7"}else{if(u.is("windows nt 6.0")){g.osVersion="vista"}else{if(u.is("windows nt 5.2")||u.is("windows nt 5.1")||u.is("windows xp")){g.osVersion="xp"}else{if(u.is("windows nt 5.0")||u.is("windows 2000")){g.osVersion="2k"}else{if(u.is("winnt")||u.is("windows nt")){g.osVersion="nt"}else{if(u.is("win98")||u.is("windows 98")){g.osVersion="98"}else{if(u.is("win95")||u.is("windows 95")){g.osVersion="95"}}}}}}}}}else{if(u.is("mac")||u.is("darwin")){g.os="mac";if(u.is("68k")||u.is("68000")){g.osVersion="68k"}else{if(u.is("ppc")||u.is("powerpc")){g.osVersion="ppc"}else{if(u.is("os x")){g.osVersion="os x"}}}}else{if(u.is("webtv")){g.os="webtv"}else{if(u.is("x11")||u.is("inux")){g.os="linux"}else{if(u.is("sunos")){g.os="sun"}else{if(u.is("irix")){g.os="irix"}else{if(u.is("freebsd")){g.os="freebsd"}else{if(u.is("bsd")){g.os="bsd"}}}}}}}}}if(g.os!==""){u.addConditionalTest(g.os,true);u.addVersionTest(g.os,g.osVersion)}}if(c.detectBrowser){if(!u.test(/opera|webtv/i)&&u.test(/msie\s([0-9]{1,})/)){g.browser="ie";if(!d.addEventListener&&document.documentMode&&document.documentMode===7){g.browserVersion="8compat"}else{g.browserVersion=(u.test(/trident\/4\.0/)?"8":RegExp.$1)}}else{if(u.is("firefox")){g.browserEngine="gecko";g.browser="firefox";g.browserVersion=(u.test(/firefox\/(\d+(\.?\d+)*)/)?RegExp.$1:"").substr(0,2)}else{if(u.is("gecko/")){g.browserEngine="gecko"}else{if(u.is("opera")){g.browser="opera";g.browserVersion=(u.test(/version\/(\d+)/)?RegExp.$1:(u.test(/opera(\s|\/)(\d+)/)?RegExp.$2:""))}else{if(u.is("konqueror")){g.browser="konqueror"}else{if(u.is("chrome")){g.browserEngine="webkit";g.browser="chrome";g.browserVersion=(u.test(/chrome\/(\d+)/)?RegExp.$1:"")}else{if(u.is("iron")){g.browserEngine="webkit";g.browser="iron"}else{if(u.is("applewebkit/")){g.browser="safari";g.browserEngine="webkit";g.browserVersion=(u.test(/version\/(\d+)/)?RegExp.$1:"")}else{if(u.is("mozilla/")){g.browserEngine="gecko"}}}}}}}}}if(g.browser!==""){u.addConditionalTest(g.browser,true);if(g.browserVersion!==""){u.addVersionTest(g.browser,g.browserVersion)}}u.addConditionalTest(g.browserEngine,true)}if(c.detectPlugins){u.detectPlugin=function(i){if(b.plugins){for(r=0,p=b.plugins.length;r<p;r+=1){var j=b.plugins[r],l=j.name+j.description,k=0;for(o=0,n=i.length;o<n;o+=1){if(l.indexOf(i[o])!==-1){k+=1}}if(k===i.length){return true}}}return false};u.detectObject=function(i,j){if(d.ActiveXObject){for(r=0,p=i.length;r<p;r+=1){try{var l=new ActiveXObject(i[r]);if(l){return j&&j[r]?j[r].call(l):true}}catch(k){}}}return false};for(s in q){if(q.hasOwnProperty(s)){t=q[s];if(u.detectPlugin(t.substrs)||u.detectObject(t.progIds,t.fns)){g.browserPlugins.push(s);u.addConditionalTest(s,true)}}}}}function f(){if(e!==undefined){e.Detectizr=e.Detectizr||{};e.Detectizr.device={type:"",model:"",orientation:"",browser:"",browserEngine:"",browserPlugins:[],browserVersion:"",os:"",osVersion:"",userAgent:(b.userAgent||b.vendor||d.opera).toLowerCase()};e.Detectizr.detect=function(g){return new a(g)}}}f()}(this,navigator));