forked from srfrnk/ng-device-detector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ng-device-detector.min.js
1 lines (1 loc) · 5.67 KB
/
ng-device-detector.min.js
1
!function(n){"use strict";n.module("ng.deviceDetector",["reTree"]).constant("BROWSERS",{CHROME:"chrome",FIREFOX:"firefox",SAFARI:"safari",OPERA:"opera",IE:"ie",MS_EDGE:"ms-edge",PS4:"ps4",VITA:"vita",UNKNOWN:"unknown"}).constant("DEVICES",{ANDROID:"android",I_PAD:"ipad",IPHONE:"iphone",I_POD:"ipod",BLACKBERRY:"blackberry",FIREFOX_OS:"firefox-os",CHROME_BOOK:"chrome-book",WINDOWS_PHONE:"windows-phone",PS4:"ps4",VITA:"vita",UNKNOWN:"unknown"}).constant("OS",{WINDOWS:"windows",MAC:"mac",IOS:"ios",ANDROID:"android",LINUX:"linux",UNIX:"unix",FIREFOX_OS:"firefox-os",CHROME_OS:"chrome-os",WINDOWS_PHONE:"windows-phone",PS4:"ps4",VITA:"vita",UNKNOWN:"unknown"}).constant("OS_VERSIONS",{WINDOWS_3_11:"windows-3-11",WINDOWS_95:"windows-95",WINDOWS_ME:"windows-me",WINDOWS_98:"windows-98",WINDOWS_CE:"windows-ce",WINDOWS_2000:"windows-2000",WINDOWS_XP:"windows-xp",WINDOWS_SERVER_2003:"windows-server-2003",WINDOWS_VISTA:"windows-vista",WINDOWS_7:"windows-7",WINDOWS_8_1:"windows-8-1",WINDOWS_8:"windows-8",WINDOWS_10:"windows-10",WINDOWS_PHONE_7_5:"windows-phone-7-5",WINDOWS_PHONE_8_1:"windows-phone-8-1",WINDOWS_PHONE_10:"windows-phone-10",WINDOWS_NT_4_0:"windows-nt-4-0",UNKNOWN:"unknown"}).service("detectUtils",["deviceDetector","DEVICES","BROWSERS","OS",function(n,o,e,O){var i=n;this.isMobile=function(){return"unknown"!==i.device},this.isAndroid=function(){return i.device===o.ANDROID||i.OS===O.ANDROID},this.isIOS=function(){return i.os===O.IOS||i.device===o.I_POD||i.device===o.IPHONE}}]).factory("deviceDetector",["$window","DEVICES","BROWSERS","OS","OS_VERSIONS","reTree",function(n,o,e,O,i,W){var N={WINDOWS:{and:[{or:[/\bWindows|(Win\d\d)\b/,/\bWin 9x\b/]},{not:/\bWindows Phone\b/}]},MAC:{and:[/\bMac OS\b/,{not:/Windows Phone/}]},IOS:{and:[{or:[/\biPad\b/,/\biPhone\b/,/\biPod\b/]},{not:/Windows Phone/}]},ANDROID:{and:[/\bAndroid\b/,{not:/Windows Phone/}]},LINUX:/\bLinux\b/,UNIX:/\bUNIX\b/,FIREFOX_OS:{and:[/\bFirefox\b/,/Mobile\b/]},CHROME_OS:/\bCrOS\b/,WINDOWS_PHONE:{or:[/\bIEMobile\b/,/\bWindows Phone\b/]},PS4:/\bMozilla\/5.0 \(PlayStation 4\b/,VITA:/\bMozilla\/5.0 \(Play(S|s)tation Vita\b/},r={CHROME:{and:[{or:[/\bChrome\b/,/\bCriOS\b/]},{not:{or:[/\bOPR\b/,/\bEdge\b/]}}]},FIREFOX:/\bFirefox\b/,SAFARI:{and:[/^((?!CriOS).)*\Safari\b.*$/,{not:{or:[/\bOPR\b/,/\bEdge\b/,/Windows Phone/]}}]},OPERA:{or:[/Opera\b/,/\bOPR\b/]},IE:{or:[/\bMSIE\b/,/\bTrident\b/]},MS_EDGE:{or:[/\bEdge\b/]},PS4:/\bMozilla\/5.0 \(PlayStation 4\b/,VITA:/\bMozilla\/5.0 \(Play(S|s)tation Vita\b/},I={ANDROID:{and:[/\bAndroid\b/,{not:/Windows Phone/}]},I_PAD:/\biPad\b/,IPHONE:{and:[/\biPhone\b/,{not:/Windows Phone/}]},I_POD:/\biPod\b/,BLACKBERRY:/\bblackberry\b/,FIREFOX_OS:{and:[/\bFirefox\b/,/\bMobile\b/]},CHROME_BOOK:/\bCrOS\b/,WINDOWS_PHONE:{or:[/\bIEMobile\b/,/\bWindows Phone\b/]},PS4:/\bMozilla\/5.0 \(PlayStation 4\b/,VITA:/\bMozilla\/5.0 \(Play(S|s)tation Vita\b/},S={WINDOWS_3_11:/Win16/,WINDOWS_95:/(Windows 95|Win95|Windows_95)/,WINDOWS_ME:/(Win 9x 4.90|Windows ME)/,WINDOWS_98:/(Windows 98|Win98)/,WINDOWS_CE:/Windows CE/,WINDOWS_2000:/(Windows NT 5.0|Windows 2000)/,WINDOWS_XP:/(Windows NT 5.1|Windows XP)/,WINDOWS_SERVER_2003:/Windows NT 5.2/,WINDOWS_VISTA:/Windows NT 6.0/,WINDOWS_7:/(Windows 7|Windows NT 6.1)/,WINDOWS_8_1:/(Windows 8.1|Windows NT 6.3)/,WINDOWS_8:/(Windows 8|Windows NT 6.2)/,WINDOWS_10:/(Windows NT 10.0)/,WINDOWS_PHONE_7_5:/(Windows Phone OS 7.5)/,WINDOWS_PHONE_8_1:/(Windows Phone 8.1)/,WINDOWS_PHONE_10:/(Windows Phone 10)/,WINDOWS_NT_4_0:{and:[/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/,{not:/Windows NT 10.0/}]}},d={CHROME:/\bChrome\/([\d\.]+)\b/,FIREFOX:/\bFirefox\/([\d\.]+)\b/,SAFARI:/\bVersion\/([\d\.]+)\b/,OPERA:[/\bVersion\/([\d\.]+)\b/,/\bOPR\/([\d\.]+)\b/],IE:[/\bMSIE ([\d\.]+\w?)\b/,/\brv:([\d\.]+\w?)\b/],MS_EDGE:/\bEdge\/([\d\.]+)\b/},s=Object.keys(d).reduce(function(n,o){return n[e[o]]=d[o],n},{}),b=n.navigator.userAgent,_={raw:{userAgent:b,os:{},browser:{},device:{}}};if(_.raw.os=Object.keys(O).reduce(function(n,o){return n[O[o]]=W.test(b,N[o]),n},{}),_.raw.browser=Object.keys(e).reduce(function(n,o){return n[e[o]]=W.test(b,r[o]),n},{}),_.raw.device=Object.keys(o).reduce(function(n,e){return n[o[e]]=W.test(b,I[e]),n},{}),_.raw.os_version=Object.keys(i).reduce(function(n,o){return n[i[o]]=W.test(b,S[o]),n},{}),_.os=[O.WINDOWS,O.IOS,O.MAC,O.ANDROID,O.LINUX,O.UNIX,O.FIREFOX_OS,O.CHROME_OS,O.WINDOWS_PHONE,O.PS4,O.VITA].reduce(function(n,o){return n===O.UNKNOWN&&_.raw.os[o]?o:n},O.UNKNOWN),_.browser=[e.CHROME,e.FIREFOX,e.SAFARI,e.OPERA,e.IE,e.MS_EDGE,e.PS4,e.VITA].reduce(function(n,o){return n===e.UNKNOWN&&_.raw.browser[o]?o:n},e.UNKNOWN),_.device=[o.ANDROID,o.I_PAD,o.IPHONE,o.I_POD,o.BLACKBERRY,o.FIREFOX_OS,o.CHROME_BOOK,o.WINDOWS_PHONE,o.PS4,o.VITA].reduce(function(n,e){return n===o.UNKNOWN&&_.raw.device[e]?e:n},o.UNKNOWN),_.os_version=[i.WINDOWS_3_11,i.WINDOWS_95,i.WINDOWS_ME,i.WINDOWS_98,i.WINDOWS_CE,i.WINDOWS_2000,i.WINDOWS_XP,i.WINDOWS_SERVER_2003,i.WINDOWS_VISTA,i.WINDOWS_7,i.WINDOWS_8_1,i.WINDOWS_8,i.WINDOWS_10,i.WINDOWS_PHONE_7_5,i.WINDOWS_PHONE_8_1,i.WINDOWS_PHONE_10,i.WINDOWS_NT_4_0].reduce(function(n,o){return n===i.UNKNOWN&&_.raw.os_version[o]?o:n},i.UNKNOWN),_.browser_version="0",_.browser!==e.UNKNOWN){var t=s[_.browser],w=W.exec(b,t);w&&(_.browser_version=w[1])}return _.isMobile=function(){return[o.ANDROID,o.I_PAD,o.IPHONE,o.I_POD,o.BLACKBERRY,o.FIREFOX_OS,o.WINDOWS_PHONE,o.VITA].some(function(n){return _.device==n})},_.isTablet=function(){return[o.I_PAD,o.FIREFOX_OS].some(function(n){return _.device==n})},_.isDesktop=function(){return[o.PS4,o.CHROME_BOOK,o.UNKNOWN].some(function(n){return _.device==n})},_}]).directive("deviceDetector",["deviceDetector",function(n){return{restrict:"A",link:function(o,e){e.addClass("os-"+n.os),e.addClass("browser-"+n.browser),e.addClass("device-"+n.device)}}}])}(angular);