+ * var md = new MobileDetect(window.navigator.userAgent);
+ * if (md.mobile()) {
+ * location.href = (md.mobileGrade() === 'A') ? '/mobile/' : '/lynx/';
+ * }
+ *
+ *
+ * @param {string} userAgent typically taken from window.navigator.userAgent or http_header['User-Agent']
+ * @param {number} [maxPhoneWidth=600] only for browsers specify a value for the maximum
+ * width of smallest device side (in logical "CSS" pixels) until a device detected as mobile will be handled
+ * as phone.
+ * This is only used in cases where the device cannot be classified as phone or tablet.
+ * See Declaring Tablet Layouts
+ * for Android.
+ * If you provide a value < 0, then this "fuzzy" check is disabled.
+ * @constructor
+ * @global
+ */
+ function MobileDetect(userAgent, maxPhoneWidth) {
+ this.ua = userAgent || '';
+ this._cache = {};
+ //600dp is typical 7" tablet minimum width
+ this.maxPhoneWidth = maxPhoneWidth || 600;
+ }
+
+ MobileDetect.prototype = {
+ constructor: MobileDetect,
/**
- * Check the version of the given property in the User-Agent.
+ * Returns the detected phone or tablet type or null if it is not a mobile device.
+ *
+ * For a list of possible return values see {@link MobileDetect#phone} and {@link MobileDetect#tablet}.
+ *
+ * If the device is not detected by the regular expressions from Mobile-Detect, a test is made against
+ * the patterns of detectmobilebrowsers.com. If this test
+ * is positive, a value of UnknownPhone, UnknownTablet or
+ * UnknownMobile is returned.
+ * When used in browser, the decision whether phone or tablet is made based on screen.width/height.
+ *
+ * When used server-side (node.js), there is no way to tell the difference between UnknownTablet
+ * and UnknownMobile, so you will get UnknownMobile here.
+ * Be aware that since v1.0.0 in this special case you will get UnknownMobile only for:
+ * {@link MobileDetect#mobile}, not for {@link MobileDetect#phone} and {@link MobileDetect#tablet}.
+ * In versions before v1.0.0 all 3 methods returned UnknownMobile which was tedious to use.
+ *
+ * In most cases you will use the return value just as a boolean.
+ *
+ * @returns {String} the key for the phone family or tablet family, e.g. "Nexus".
+ * @function MobileDetect#mobile
+ */
+ mobile: function () {
+ impl.prepareDetectionCache(this._cache, this.ua, this.maxPhoneWidth);
+ return this._cache.mobile;
+ },
+
+ /**
+ * Returns the detected phone type/family string or null.
+ *
+ * The returned tablet (family or producer) is one of following keys:
+ * iPhone, BlackBerry, HTC, Nexus, Dell, Motorola, Samsung, LG, Sony, Asus,
+ * Micromax, Palm, Vertu, Pantech, Fly, Wiko, iMobile, SimValley, Wolfgang,
+ * Alcatel, Nintendo, Amoi, INQ, GenericPhone
+ *
+ * If the device is not detected by the regular expressions from Mobile-Detect, a test is made against
+ * the patterns of detectmobilebrowsers.com. If this test
+ * is positive, a value of UnknownPhone or UnknownMobile is returned.
+ * When used in browser, the decision whether phone or tablet is made based on screen.width/height.
+ *
+ * When used server-side (node.js), there is no way to tell the difference between UnknownTablet
+ * and UnknownMobile, so you will get null here, while {@link MobileDetect#mobile}
+ * will return UnknownMobile.
+ * Be aware that since v1.0.0 in this special case you will get UnknownMobile only for:
+ * {@link MobileDetect#mobile}, not for {@link MobileDetect#phone} and {@link MobileDetect#tablet}.
+ * In versions before v1.0.0 all 3 methods returned UnknownMobile which was tedious to use.
+ *
+ * In most cases you will use the return value just as a boolean.
+ *
+ * @returns {String} the key of the phone family or producer, e.g. "iPhone"
+ * @function MobileDetect#phone
+ */
+ phone: function () {
+ impl.prepareDetectionCache(this._cache, this.ua, this.maxPhoneWidth);
+ return this._cache.phone;
+ },
+
+ /**
+ * Returns the detected tablet type/family string or null.
+ *
+ * The returned tablet (family or producer) is one of following keys:
+ * iPad, NexusTablet, SamsungTablet, Kindle, SurfaceTablet, HPTablet, AsusTablet,
+ * BlackBerryTablet, HTCtablet, MotorolaTablet, NookTablet, AcerTablet,
+ * ToshibaTablet, LGTablet, FujitsuTablet, PrestigioTablet, LenovoTablet,
+ * DellTablet, YarvikTablet, MedionTablet, ArnovaTablet, IntensoTablet, IRUTablet,
+ * MegafonTablet, EbodaTablet, AllViewTablet, ArchosTablet, AinolTablet,
+ * SonyTablet, PhilipsTablet, CubeTablet, CobyTablet, MIDTablet, MSITablet,
+ * SMiTTablet, RockChipTablet, FlyTablet, bqTablet, HuaweiTablet, NecTablet,
+ * PantechTablet, BronchoTablet, VersusTablet, ZyncTablet, PositivoTablet,
+ * NabiTablet, KoboTablet, DanewTablet, TexetTablet, PlaystationTablet,
+ * TrekstorTablet, PyleAudioTablet, AdvanTablet, DanyTechTablet, GalapadTablet,
+ * MicromaxTablet, KarbonnTablet, AllFineTablet, PROSCANTablet, YONESTablet,
+ * ChangJiaTablet, GUTablet, PointOfViewTablet, OvermaxTablet, HCLTablet,
+ * DPSTablet, VistureTablet, CrestaTablet, MediatekTablet, ConcordeTablet,
+ * GoCleverTablet, ModecomTablet, VoninoTablet, ECSTablet, StorexTablet,
+ * VodafoneTablet, EssentielBTablet, RossMoorTablet, iMobileTablet, TolinoTablet,
+ * AudioSonicTablet, AMPETablet, SkkTablet, TecnoTablet, JXDTablet, iJoyTablet,
+ * FX2Tablet, XoroTablet, ViewsonicTablet, OdysTablet, CaptivaTablet,
+ * IconbitTablet, TeclastTablet, JaytechTablet, BlaupunktTablet, DigmaTablet,
+ * EvolioTablet, LavaTablet, CelkonTablet, WolderTablet, MiTablet, NibiruTablet,
+ * NexoTablet, UbislateTablet, PocketBookTablet, Hudl, TelstraTablet, GenericTablet
+ *
+ * If the device is not detected by the regular expressions from Mobile-Detect, a test is made against
+ * the patterns of detectmobilebrowsers.com. If this test
+ * is positive, a value of UnknownTablet or UnknownMobile is returned.
+ * When used in browser, the decision whether phone or tablet is made based on screen.width/height.
+ *
+ * When used server-side (node.js), there is no way to tell the difference between UnknownTablet
+ * and UnknownMobile, so you will get null here, while {@link MobileDetect#mobile}
+ * will return UnknownMobile.
+ * Be aware that since v1.0.0 in this special case you will get UnknownMobile only for:
+ * {@link MobileDetect#mobile}, not for {@link MobileDetect#phone} and {@link MobileDetect#tablet}.
+ * In versions before v1.0.0 all 3 methods returned UnknownMobile which was tedious to use.
+ *
+ * In most cases you will use the return value just as a boolean.
+ *
+ * @returns {String} the key of the tablet family or producer, e.g. "SamsungTablet"
+ * @function MobileDetect#tablet
+ */
+ tablet: function () {
+ impl.prepareDetectionCache(this._cache, this.ua, this.maxPhoneWidth);
+ return this._cache.tablet;
+ },
+
+ /**
+ * Returns the detected user-agent string or null.
+ *
+ * The returned user-agent is one of following keys:
+ * Chrome, Dolfin, Opera, Skyfire, IE, Firefox, Bolt, TeaShark, Blazer, Safari,
+ * Tizen, UCBrowser, baiduboxapp, baidubrowser, DiigoBrowser, Puffin, Mercury,
+ * ObigoBrowser, NetFront, GenericBrowser
+ *
+ * @returns {String} the key for the detected user-agent or null
+ * @function MobileDetect#userAgent
+ */
+ userAgent: function () {
+ if (this._cache.userAgent === undefined) {
+ this._cache.userAgent = impl.findMatch(impl.mobileDetectRules.uas, this.ua);
+ }
+ return this._cache.userAgent;
+ },
+
+ /**
+ * Returns the detected operating system string or null.
+ *
+ * The operating system is one of following keys:
+ * AndroidOS, BlackBerryOS, PalmOS, SymbianOS, WindowsMobileOS, WindowsPhoneOS,
+ * iOS, MeeGoOS, MaemoOS, JavaOS, webOS, badaOS, BREWOS
+ *
+ * @returns {String} the key for the detected operating system.
+ * @function MobileDetect#os
+ */
+ os: function () {
+ if (this._cache.os === undefined) {
+ this._cache.os = impl.detectOS(this.ua);
+ }
+ return this._cache.os;
+ },
+
+ /**
+ * Get the version (as Number) of the given property in the User-Agent.
+ *
* Will return a float number. (eg. 2_0 will return 2.0, 4.3.1 will return 4.31)
*
- * @param {String} propertyName
- * @param {String} userAgent
- * @return {Number} version or NaN if version not found
- * @private
- */
- impl.getVersion = function (propertyName, userAgent) {
- var version = impl.getVersionStr(propertyName, userAgent);
- return version ? impl.prepareVersionNo(version) : NaN;
- };
-
- /**
- * Prepare the version number.
+ * @param {String} key a key defining a thing which has a version.
+ * You can use one of following keys:
+ * Mobile, Build, Version, VendorID, iPad, iPhone, iPod, Kindle, Chrome, Coast,
+ * Dolfin, Firefox, Fennec, IE, NetFront, NokiaBrowser, Opera, Opera Mini, Opera
+ * Mobi, UC Browser, MQQBrowser, MicroMessenger, baiduboxapp, baidubrowser, Iron,
+ * Safari, Skyfire, Tizen, Webkit, Gecko, Trident, Presto, iOS, Android,
+ * BlackBerry, BREW, Java, Windows Phone OS, Windows Phone, Windows CE, Windows
+ * NT, Symbian, webOS
*
- * @param {String} version
- * @return {Number} the version number as a floating number
- * @private
+ * @returns {Number} the version as float or NaN if User-Agent doesn't contain this version.
+ * Be careful when comparing this value with '==' operator!
+ * @function MobileDetect#version
*/
- impl.prepareVersionNo = function (version) {
- var numbers;
-
- numbers = version.split(/[a-z._ \/\-]/i);
- if (numbers.length === 1) {
- version = numbers[0];
- }
- if (numbers.length > 1) {
- version = numbers[0] + '.';
- numbers.shift();
- version += numbers.join('');
- }
- return Number(version);
- };
-
- impl.isMobileFallback = function (userAgent) {
- return impl.detectMobileBrowsers.fullPattern.test(userAgent) ||
- impl.detectMobileBrowsers.shortPattern.test(userAgent.substr(0, 4));
- };
-
- impl.prepareDetectionCache = function (cache, userAgent, maxPhoneWidth) {
- if (cache.mobile !== undefined) {
- return;
- }
- var phone, tablet, phoneSized;
-
- // first check for stronger tablet rules, then phone (see issue#5)
- tablet = impl.findMatch(impl.mobileDetectRules.tablets, userAgent);
- if (tablet) {
- cache.mobile = cache.tablet = tablet;
- cache.phone = null;
- return; // unambiguously identified as tablet
- }
-
- phone = impl.findMatch(impl.mobileDetectRules.phones, userAgent);
- if (phone) {
- cache.mobile = cache.phone = phone;
- cache.tablet = null;
- return; // unambiguously identified as phone
- }
-
- // our rules haven't found a match -> try more general fallback rules
- if (impl.isMobileFallback(userAgent)) {
- phoneSized = MobileDetect.isPhoneSized(maxPhoneWidth);
- if (phoneSized === undefined) {
- cache.mobile = impl.FALLBACK_MOBILE;
- cache.tablet = cache.phone = null;
- } else if (phoneSized) {
- cache.mobile = cache.phone = impl.FALLBACK_PHONE;
- cache.tablet = null;
- } else {
- cache.mobile = cache.tablet = impl.FALLBACK_TABLET;
- cache.phone = null;
- }
- } else {
- // not mobile at all!
- cache.mobile = cache.tablet = cache.phone = null;
- }
- };
-
- // t is a reference to a MobileDetect instance
- impl.mobileGrade = function (t) {
- // impl note:
- // To keep in sync w/ Mobile_Detect.php easily, the following code is tightly aligned to the PHP version.
- // When changes are made in Mobile_Detect.php, copy this method and replace:
- // $this-> / t.
- // self::MOBILE_GRADE_(.) / '$1'
- // , self::VERSION_TYPE_FLOAT / (nothing)
- // isIOS() / os('iOS')
- // [reg] / (nothing) <-- jsdelivr complaining about unescaped unicode character U+00AE
- var $isMobile = t.mobile() !== null;
-
- if (
- // Apple iOS 3.2-5.1 - Tested on the original iPad (4.3 / 5.0), iPad 2 (4.3), iPad 3 (5.1), original iPhone (3.1), iPhone 3 (3.2), 3GS (4.3), 4 (4.3 / 5.0), and 4S (5.1)
- t.os('iOS') && t.version('iPad') >= 4.3 ||
- t.os('iOS') && t.version('iPhone') >= 3.1 ||
- t.os('iOS') && t.version('iPod') >= 3.1 ||
-
- // Android 2.1-2.3 - Tested on the HTC Incredible (2.2), original Droid (2.2), HTC Aria (2.1), Google Nexus S (2.3). Functional on 1.5 & 1.6 but performance may be sluggish, tested on Google G1 (1.5)
- // Android 3.1 (Honeycomb) - Tested on the Samsung Galaxy Tab 10.1 and Motorola XOOM
- // Android 4.0 (ICS) - Tested on a Galaxy Nexus. Note: transition performance can be poor on upgraded devices
- // Android 4.1 (Jelly Bean) - Tested on a Galaxy Nexus and Galaxy 7
- (t.version('Android') > 2.1 && t.is('Webkit')) ||
-
- // Windows Phone 7-7.5 - Tested on the HTC Surround (7.0) HTC Trophy (7.5), LG-E900 (7.5), Nokia Lumia 800
- t.version('Windows Phone OS') >= 7.0 ||
-
- // Blackberry 7 - Tested on BlackBerry Torch 9810
- // Blackberry 6.0 - Tested on the Torch 9800 and Style 9670
- t.is('BlackBerry') && t.version('BlackBerry') >= 6.0 ||
- // Blackberry Playbook (1.0-2.0) - Tested on PlayBook
- t.match('Playbook.*Tablet') ||
-
- // Palm WebOS (1.4-2.0) - Tested on the Palm Pixi (1.4), Pre (1.4), Pre 2 (2.0)
- (t.version('webOS') >= 1.4 && t.match('Palm|Pre|Pixi')) ||
- // Palm WebOS 3.0 - Tested on HP TouchPad
- t.match('hp.*TouchPad') ||
-
- // Firefox Mobile (12 Beta) - Tested on Android 2.3 device
- (t.is('Firefox') && t.version('Firefox') >= 12) ||
-
- // Chrome for Android - Tested on Android 4.0, 4.1 device
- (t.is('Chrome') && t.is('AndroidOS') && t.version('Android') >= 4.0) ||
-
- // Skyfire 4.1 - Tested on Android 2.3 device
- (t.is('Skyfire') && t.version('Skyfire') >= 4.1 && t.is('AndroidOS') && t.version('Android') >= 2.3) ||
-
- // Opera Mobile 11.5-12: Tested on Android 2.3
- (t.is('Opera') && t.version('Opera Mobi') > 11 && t.is('AndroidOS')) ||
-
- // Meego 1.2 - Tested on Nokia 950 and N9
- t.is('MeeGoOS') ||
-
- // Tizen (pre-release) - Tested on early hardware
- t.is('Tizen') ||
-
- // Samsung Bada 2.0 - Tested on a Samsung Wave 3, Dolphin browser
- // @todo: more tests here!
- t.is('Dolfin') && t.version('Bada') >= 2.0 ||
-
- // UC Browser - Tested on Android 2.3 device
- ((t.is('UC Browser') || t.is('Dolfin')) && t.version('Android') >= 2.3) ||
-
- // Kindle 3 and Fire - Tested on the built-in WebKit browser for each
- (t.match('Kindle Fire') ||
- t.is('Kindle') && t.version('Kindle') >= 3.0) ||
-
- // Nook Color 1.4.1 - Tested on original Nook Color, not Nook Tablet
- t.is('AndroidOS') && t.is('NookTablet') ||
-
- // Chrome Desktop 11-21 - Tested on OS X 10.7 and Windows 7
- t.version('Chrome') >= 11 && !$isMobile ||
-
- // Safari Desktop 4-5 - Tested on OS X 10.7 and Windows 7
- t.version('Safari') >= 5.0 && !$isMobile ||
-
- // Firefox Desktop 4-13 - Tested on OS X 10.7 and Windows 7
- t.version('Firefox') >= 4.0 && !$isMobile ||
-
- // Internet Explorer 7-9 - Tested on Windows XP, Vista and 7
- t.version('MSIE') >= 7.0 && !$isMobile ||
-
- // Opera Desktop 10-12 - Tested on OS X 10.7 and Windows 7
- // @reference: http://my.opera.com/community/openweb/idopera/
- t.version('Opera') >= 10 && !$isMobile
-
- ) {
- return 'A';
- }
-
- if (
- t.os('iOS') && t.version('iPad') < 4.3 ||
- t.os('iOS') && t.version('iPhone') < 3.1 ||
- t.os('iOS') && t.version('iPod') < 3.1 ||
-
- // Blackberry 5.0: Tested on the Storm 2 9550, Bold 9770
- t.is('Blackberry') && t.version('BlackBerry') >= 5 && t.version('BlackBerry') < 6 ||
-
- //Opera Mini (5.0-6.5) - Tested on iOS 3.2/4.3 and Android 2.3
- (t.version('Opera Mini') >= 5.0 && t.version('Opera Mini') <= 6.5 &&
- (t.version('Android') >= 2.3 || t.is('iOS'))) ||
-
- // Nokia Symbian^3 - Tested on Nokia N8 (Symbian^3), C7 (Symbian^3), also works on N97 (Symbian^1)
- t.match('NokiaN8|NokiaC7|N97.*Series60|Symbian/3') ||
-
- // @todo: report this (tested on Nokia N71)
- t.version('Opera Mobi') >= 11 && t.is('SymbianOS')
- ) {
- return 'B';
- }
-
- if (
- // Blackberry 4.x - Tested on the Curve 8330
- t.version('BlackBerry') < 5.0 ||
- // Windows Mobile - Tested on the HTC Leo (WinMo 5.2)
- t.match('MSIEMobile|Windows CE.*Mobile') || t.version('Windows Mobile') <= 5.2
-
- ) {
- return 'C';
- }
-
- //All older smartphone platforms and featurephones - Any device that doesn't support media queries
- //will receive the basic, C grade experience.
- return 'C';
- };
-
- impl.detectOS = function (ua) {
- return impl.findMatch(impl.mobileDetectRules.oss0, ua) ||
- impl.findMatch(impl.mobileDetectRules.oss, ua);
- };
-
- impl.getDeviceSmallerSide = function () {
- return window.screen.width < window.screen.height ?
- window.screen.width :
- window.screen.height;
- };
+ version: function (key) {
+ return impl.getVersion(key, this.ua);
+ },
/**
- * Constructor for MobileDetect object.
+ * Get the version (as String) of the given property in the User-Agent.
*
- * Such an object will keep a reference to the given user-agent string and cache most of the detect queries.
- *
- * var md = new MobileDetect(window.navigator.userAgent);
- * if (md.mobile()) {
- * location.href = (md.mobileGrade() === 'A') ? '/mobile/' : '/lynx/';
- * }
- *
+ * @param {String} key a key defining a thing which has a version.
+ * You can use one of following keys:
+ * Mobile, Build, Version, VendorID, iPad, iPhone, iPod, Kindle, Chrome, Coast,
+ * Dolfin, Firefox, Fennec, IE, NetFront, NokiaBrowser, Opera, Opera Mini, Opera
+ * Mobi, UC Browser, MQQBrowser, MicroMessenger, baiduboxapp, baidubrowser, Iron,
+ * Safari, Skyfire, Tizen, Webkit, Gecko, Trident, Presto, iOS, Android,
+ * BlackBerry, BREW, Java, Windows Phone OS, Windows Phone, Windows CE, Windows
+ * NT, Symbian, webOS
*
- * @param {string} userAgent typically taken from window.navigator.userAgent or http_header['User-Agent']
- * @param {number} [maxPhoneWidth=600] only for browsers specify a value for the maximum
- * width of smallest device side (in logical "CSS" pixels) until a device detected as mobile will be handled
- * as phone.
- * This is only used in cases where the device cannot be classified as phone or tablet.
- * See Declaring Tablet Layouts
- * for Android.
- * If you provide a value < 0, then this "fuzzy" check is disabled.
- * @constructor
- * @global
+ * @returns {String} the "raw" version as String or null if User-Agent doesn't contain this version.
+ *
+ * @function MobileDetect#versionStr
*/
- function MobileDetect(userAgent, maxPhoneWidth) {
- this.ua = userAgent || '';
- this._cache = {};
- //600dp is typical 7" tablet minimum width
- this.maxPhoneWidth = maxPhoneWidth || 600;
- }
+ versionStr: function (key) {
+ return impl.getVersionStr(key, this.ua);
+ },
- MobileDetect.prototype = {
- constructor: MobileDetect,
+ /**
+ * Global test key against userAgent, os, phone, tablet and some other properties of userAgent string.
+ *
+ * @param {String} key the key (case-insensitive) of a userAgent, an operating system, phone or
+ * tablet family.
+ * For a complete list of possible values, see {@link MobileDetect#userAgent},
+ * {@link MobileDetect#os}, {@link MobileDetect#phone}, {@link MobileDetect#tablet}.
+ * Additionally you have following keys:
+ * Bot, MobileBot, DesktopMode, TV, WebKit, Console, Watch
+ *
+ * @returns {boolean} true when the given key is one of the defined keys of userAgent, os, phone,
+ * tablet or one of the listed additional keys, otherwise false
+ * @function MobileDetect#is
+ */
+ is: function (key) {
+ return equalIC(key, this.userAgent()) ||
+ equalIC(key, this.os()) ||
+ equalIC(key, this.phone()) ||
+ equalIC(key, this.tablet()) ||
+ equalIC(key, impl.findMatch(impl.mobileDetectRules.utils, this.ua));
+ },
- /**
- * Returns the detected phone or tablet type or null if it is not a mobile device.
- *
- * For a list of possible return values see {@link MobileDetect#phone} and {@link MobileDetect#tablet}.
- *
- * If the device is not detected by the regular expressions from Mobile-Detect, a test is made against
- * the patterns of detectmobilebrowsers.com. If this test
- * is positive, a value of UnknownPhone, UnknownTablet or
- * UnknownMobile is returned.
- * When used in browser, the decision whether phone or tablet is made based on screen.width/height.
- *
- * When used server-side (node.js), there is no way to tell the difference between UnknownTablet
- * and UnknownMobile, so you will get UnknownMobile here.
- * Be aware that since v1.0.0 in this special case you will get UnknownMobile only for:
- * {@link MobileDetect#mobile}, not for {@link MobileDetect#phone} and {@link MobileDetect#tablet}.
- * In versions before v1.0.0 all 3 methods returned UnknownMobile which was tedious to use.
- *
- * In most cases you will use the return value just as a boolean.
- *
- * @returns {String} the key for the phone family or tablet family, e.g. "Nexus".
- * @function MobileDetect#mobile
- */
- mobile: function () {
- impl.prepareDetectionCache(this._cache, this.ua, this.maxPhoneWidth);
- return this._cache.mobile;
- },
-
- /**
- * Returns the detected phone type/family string or null.
- *
- * The returned tablet (family or producer) is one of following keys:
- * iPhone, BlackBerry, HTC, Nexus, Dell, Motorola, Samsung, LG, Sony, Asus,
- * Micromax, Palm, Vertu, Pantech, Fly, Wiko, iMobile, SimValley, Wolfgang,
- * Alcatel, Nintendo, Amoi, INQ, GenericPhone
- *
- * If the device is not detected by the regular expressions from Mobile-Detect, a test is made against
- * the patterns of detectmobilebrowsers.com. If this test
- * is positive, a value of UnknownPhone or UnknownMobile is returned.
- * When used in browser, the decision whether phone or tablet is made based on screen.width/height.
- *
- * When used server-side (node.js), there is no way to tell the difference between UnknownTablet
- * and UnknownMobile, so you will get null here, while {@link MobileDetect#mobile}
- * will return UnknownMobile.
- * Be aware that since v1.0.0 in this special case you will get UnknownMobile only for:
- * {@link MobileDetect#mobile}, not for {@link MobileDetect#phone} and {@link MobileDetect#tablet}.
- * In versions before v1.0.0 all 3 methods returned UnknownMobile which was tedious to use.
- *
- * In most cases you will use the return value just as a boolean.
- *
- * @returns {String} the key of the phone family or producer, e.g. "iPhone"
- * @function MobileDetect#phone
- */
- phone: function () {
- impl.prepareDetectionCache(this._cache, this.ua, this.maxPhoneWidth);
- return this._cache.phone;
- },
-
- /**
- * Returns the detected tablet type/family string or null.
- *
- * The returned tablet (family or producer) is one of following keys:
- * iPad, NexusTablet, SamsungTablet, Kindle, SurfaceTablet, HPTablet, AsusTablet,
- * BlackBerryTablet, HTCtablet, MotorolaTablet, NookTablet, AcerTablet,
- * ToshibaTablet, LGTablet, FujitsuTablet, PrestigioTablet, LenovoTablet,
- * DellTablet, YarvikTablet, MedionTablet, ArnovaTablet, IntensoTablet, IRUTablet,
- * MegafonTablet, EbodaTablet, AllViewTablet, ArchosTablet, AinolTablet,
- * SonyTablet, PhilipsTablet, CubeTablet, CobyTablet, MIDTablet, MSITablet,
- * SMiTTablet, RockChipTablet, FlyTablet, bqTablet, HuaweiTablet, NecTablet,
- * PantechTablet, BronchoTablet, VersusTablet, ZyncTablet, PositivoTablet,
- * NabiTablet, KoboTablet, DanewTablet, TexetTablet, PlaystationTablet,
- * TrekstorTablet, PyleAudioTablet, AdvanTablet, DanyTechTablet, GalapadTablet,
- * MicromaxTablet, KarbonnTablet, AllFineTablet, PROSCANTablet, YONESTablet,
- * ChangJiaTablet, GUTablet, PointOfViewTablet, OvermaxTablet, HCLTablet,
- * DPSTablet, VistureTablet, CrestaTablet, MediatekTablet, ConcordeTablet,
- * GoCleverTablet, ModecomTablet, VoninoTablet, ECSTablet, StorexTablet,
- * VodafoneTablet, EssentielBTablet, RossMoorTablet, iMobileTablet, TolinoTablet,
- * AudioSonicTablet, AMPETablet, SkkTablet, TecnoTablet, JXDTablet, iJoyTablet,
- * FX2Tablet, XoroTablet, ViewsonicTablet, OdysTablet, CaptivaTablet,
- * IconbitTablet, TeclastTablet, JaytechTablet, BlaupunktTablet, DigmaTablet,
- * EvolioTablet, LavaTablet, CelkonTablet, WolderTablet, MiTablet, NibiruTablet,
- * NexoTablet, UbislateTablet, PocketBookTablet, Hudl, TelstraTablet, GenericTablet
- *
- * If the device is not detected by the regular expressions from Mobile-Detect, a test is made against
- * the patterns of detectmobilebrowsers.com. If this test
- * is positive, a value of UnknownTablet or UnknownMobile is returned.
- * When used in browser, the decision whether phone or tablet is made based on screen.width/height.
- *
- * When used server-side (node.js), there is no way to tell the difference between UnknownTablet
- * and UnknownMobile, so you will get null here, while {@link MobileDetect#mobile}
- * will return UnknownMobile.
- * Be aware that since v1.0.0 in this special case you will get UnknownMobile only for:
- * {@link MobileDetect#mobile}, not for {@link MobileDetect#phone} and {@link MobileDetect#tablet}.
- * In versions before v1.0.0 all 3 methods returned UnknownMobile which was tedious to use.
- *
- * In most cases you will use the return value just as a boolean.
- *
- * @returns {String} the key of the tablet family or producer, e.g. "SamsungTablet"
- * @function MobileDetect#tablet
- */
- tablet: function () {
- impl.prepareDetectionCache(this._cache, this.ua, this.maxPhoneWidth);
- return this._cache.tablet;
- },
-
- /**
- * Returns the detected user-agent string or null.
- *
- * The returned user-agent is one of following keys:
- * Chrome, Dolfin, Opera, Skyfire, IE, Firefox, Bolt, TeaShark, Blazer, Safari,
- * Tizen, UCBrowser, baiduboxapp, baidubrowser, DiigoBrowser, Puffin, Mercury,
- * ObigoBrowser, NetFront, GenericBrowser
- *
- * @returns {String} the key for the detected user-agent or null
- * @function MobileDetect#userAgent
- */
- userAgent: function () {
- if (this._cache.userAgent === undefined) {
- this._cache.userAgent = impl.findMatch(impl.mobileDetectRules.uas, this.ua);
- }
- return this._cache.userAgent;
- },
-
- /**
- * Returns the detected operating system string or null.
- *
- * The operating system is one of following keys:
- * AndroidOS, BlackBerryOS, PalmOS, SymbianOS, WindowsMobileOS, WindowsPhoneOS,
- * iOS, MeeGoOS, MaemoOS, JavaOS, webOS, badaOS, BREWOS
- *
- * @returns {String} the key for the detected operating system.
- * @function MobileDetect#os
- */
- os: function () {
- if (this._cache.os === undefined) {
- this._cache.os = impl.detectOS(this.ua);
- }
- return this._cache.os;
- },
-
- /**
- * Get the version (as Number) of the given property in the User-Agent.
- *
- * Will return a float number. (eg. 2_0 will return 2.0, 4.3.1 will return 4.31)
- *
- * @param {String} key a key defining a thing which has a version.
- * You can use one of following keys:
- * Mobile, Build, Version, VendorID, iPad, iPhone, iPod, Kindle, Chrome, Coast,
- * Dolfin, Firefox, Fennec, IE, NetFront, NokiaBrowser, Opera, Opera Mini, Opera
- * Mobi, UC Browser, MQQBrowser, MicroMessenger, baiduboxapp, baidubrowser, Iron,
- * Safari, Skyfire, Tizen, Webkit, Gecko, Trident, Presto, iOS, Android,
- * BlackBerry, BREW, Java, Windows Phone OS, Windows Phone, Windows CE, Windows
- * NT, Symbian, webOS
- *
- * @returns {Number} the version as float or NaN if User-Agent doesn't contain this version.
- * Be careful when comparing this value with '==' operator!
- * @function MobileDetect#version
- */
- version: function (key) {
- return impl.getVersion(key, this.ua);
- },
-
- /**
- * Get the version (as String) of the given property in the User-Agent.
- *
- *
- * @param {String} key a key defining a thing which has a version.
- * You can use one of following keys:
- * Mobile, Build, Version, VendorID, iPad, iPhone, iPod, Kindle, Chrome, Coast,
- * Dolfin, Firefox, Fennec, IE, NetFront, NokiaBrowser, Opera, Opera Mini, Opera
- * Mobi, UC Browser, MQQBrowser, MicroMessenger, baiduboxapp, baidubrowser, Iron,
- * Safari, Skyfire, Tizen, Webkit, Gecko, Trident, Presto, iOS, Android,
- * BlackBerry, BREW, Java, Windows Phone OS, Windows Phone, Windows CE, Windows
- * NT, Symbian, webOS
- *
- * @returns {String} the "raw" version as String or null if User-Agent doesn't contain this version.
- *
- * @function MobileDetect#versionStr
- */
- versionStr: function (key) {
- return impl.getVersionStr(key, this.ua);
- },
-
- /**
- * Global test key against userAgent, os, phone, tablet and some other properties of userAgent string.
- *
- * @param {String} key the key (case-insensitive) of a userAgent, an operating system, phone or
- * tablet family.
- * For a complete list of possible values, see {@link MobileDetect#userAgent},
- * {@link MobileDetect#os}, {@link MobileDetect#phone}, {@link MobileDetect#tablet}.
- * Additionally you have following keys:
- * Bot, MobileBot, DesktopMode, TV, WebKit, Console, Watch
- *
- * @returns {boolean} true when the given key is one of the defined keys of userAgent, os, phone,
- * tablet or one of the listed additional keys, otherwise false
- * @function MobileDetect#is
- */
- is: function (key) {
- return equalIC(key, this.userAgent()) ||
- equalIC(key, this.os()) ||
- equalIC(key, this.phone()) ||
- equalIC(key, this.tablet()) ||
- equalIC(key, impl.findMatch(impl.mobileDetectRules.utils, this.ua));
- },
-
- /**
- * Do a quick test against navigator::userAgent.
- *
- * @param {String|RegExp} pattern the pattern, either as String or RegExp
- * (a string will be converted to a case-insensitive RegExp).
- * @returns {boolean} true when the pattern matches, otherwise false
- * @function MobileDetect#match
- */
- match: function (pattern) {
- if (!(pattern instanceof RegExp)) {
- pattern = new RegExp(pattern, 'i');
- }
- return pattern.test(this.ua);
- },
-
- /**
- * Checks whether the mobile device can be considered as phone regarding screen.width.
- *
- * Obviously this method makes sense in browser environments only (not for Node.js)!
- * @param {number} [maxPhoneWidth] the maximum logical pixels (aka. CSS-pixels) to be considered as phone.
- * The argument is optional and if not present or falsy, the value of the constructor is taken.
- * @returns {boolean|undefined} undefined if screen size wasn't detectable, else true
- * when screen.width is less or equal to maxPhoneWidth, otherwise false.
- * Will always return undefined server-side.
- */
- isPhoneSized: function (maxPhoneWidth) {
- return MobileDetect.isPhoneSized(maxPhoneWidth || this.maxPhoneWidth);
- },
-
- /**
- * Returns the mobile grade ('A', 'B', 'C').
- *
- * @returns {String} one of the mobile grades ('A', 'B', 'C').
- * @function MobileDetect#mobileGrade
- */
- mobileGrade: function () {
- if (this._cache.grade === undefined) {
- this._cache.grade = impl.mobileGrade(this);
- }
- return this._cache.grade;
+ /**
+ * Do a quick test against navigator::userAgent.
+ *
+ * @param {String|RegExp} pattern the pattern, either as String or RegExp
+ * (a string will be converted to a case-insensitive RegExp).
+ * @returns {boolean} true when the pattern matches, otherwise false
+ * @function MobileDetect#match
+ */
+ match: function (pattern) {
+ if (!(pattern instanceof RegExp)) {
+ pattern = new RegExp(pattern, 'i');
}
- };
+ return pattern.test(this.ua);
+ },
- // environment-dependent
- if (typeof window !== 'undefined' && window.screen) {
- MobileDetect.isPhoneSized = function (maxPhoneWidth) {
- return maxPhoneWidth < 0 ? undefined : impl.getDeviceSmallerSide() <= maxPhoneWidth;
- };
- } else {
- MobileDetect.isPhoneSized = function () { };
+ /**
+ * Checks whether the mobile device can be considered as phone regarding screen.width.
+ *
+ * Obviously this method makes sense in browser environments only (not for Node.js)!
+ * @param {number} [maxPhoneWidth] the maximum logical pixels (aka. CSS-pixels) to be considered as phone.
+ * The argument is optional and if not present or falsy, the value of the constructor is taken.
+ * @returns {boolean|undefined} undefined if screen size wasn't detectable, else true
+ * when screen.width is less or equal to maxPhoneWidth, otherwise false.
+ * Will always return undefined server-side.
+ */
+ isPhoneSized: function (maxPhoneWidth) {
+ return MobileDetect.isPhoneSized(maxPhoneWidth || this.maxPhoneWidth);
+ },
+
+ /**
+ * Returns the mobile grade ('A', 'B', 'C').
+ *
+ * @returns {String} one of the mobile grades ('A', 'B', 'C').
+ * @function MobileDetect#mobileGrade
+ */
+ mobileGrade: function () {
+ if (this._cache.grade === undefined) {
+ this._cache.grade = impl.mobileGrade(this);
+ }
+ return this._cache.grade;
}
+ };
- // should not be replaced by a completely new object - just overwrite existing methods
- MobileDetect._impl = impl;
-
- return MobileDetect;
- }); // end of call of define()
-})((function (undefined) {
- if (typeof define === 'function' && define.amd) {
- return define;
- } else if (typeof module !== 'undefined' && module.exports) {
- return function (factory) { module.exports = factory(); };
- } else if (typeof window !== 'undefined') {
- return function (factory) { window.MobileDetect = factory(); };
+ // environment-dependent
+ if (typeof window !== 'undefined' && window.screen) {
+ MobileDetect.isPhoneSized = function (maxPhoneWidth) {
+ return maxPhoneWidth < 0 ? undefined : impl.getDeviceSmallerSide() <= maxPhoneWidth;
+ };
} else {
- // please file a bug if you get this error!
- throw new Error('unknown environment');
+ MobileDetect.isPhoneSized = function () { };
}
-})());
+
+ // should not be replaced by a completely new object - just overwrite existing methods
+ MobileDetect._impl = impl;
+
+ window.MobileDetect = MobileDetect;
+
+})();
(function (jQuery, window, undefined) {
"use strict";