Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. DeviceDetection = function ()
  2. {
  3.     this.construct = function (userAgent) {
  4.         "undefined" == typeof userAgent && (userAgent = navigator.userAgent);
  5.         this.userAgent = userAgent;
  6.         this.checks = {
  7.             iphone:             Boolean(userAgent.match(/iPhone/)),
  8.             ipod:               Boolean(userAgent.match(/iPod/)),
  9.             ipad:               Boolean(userAgent.match(/iPad/)),
  10.             blackberry:         Boolean(userAgent.match(/BlackBerry/)),
  11.             playbook:           Boolean(userAgent.match(/PlayBook/)),
  12.             android:            Boolean(userAgent.match(/Android/)),
  13.             macOS:              Boolean(userAgent.match(/Mac OS X/)),
  14.             win:                Boolean(userAgent.match(/Windows/)),
  15.             mac:                Boolean(userAgent.match(/Macintosh/)),
  16.             wphone:             Boolean(userAgent.match(/(Windows Phone OS|Windows CE|Windows Mobile)/)),
  17.             mobile:             Boolean(userAgent.match(/Mobile/)),
  18.             androidTablet:      Boolean(userAgent.match(/(GT-P1000|SGH-T849|SHW-M180S)/)),
  19.             tabletPc:           Boolean(userAgent.match(/Tablet PC/)),
  20.             palmDevice:         Boolean(userAgent.match(/(PalmOS|PalmSource| Pre\/)/)),
  21.             kindle:             Boolean(userAgent.match(/(Kindle)/)),
  22.             otherMobileHints:   Boolean(userAgent.match(/(Opera Mini|IEMobile|SonyEricsson|smartphone)/))
  23.         }
  24.     };
  25.     this.isTouchDevice = function () {
  26.         return this.checks.iphone || this.checks.ipod || this.checks.ipad
  27.     };
  28.     this.isApple = function () {
  29.         return this.checks.iphone || this.checks.ipod || this.checks.ipad || this.checks.macOS || this.checks.mac
  30.     };
  31.     this.isIOS = function () {
  32.         return this.checks.iphone || this.checks.ipod || this.checks.ipad
  33.     };
  34.     this.isBlackberry = function () {
  35.         return this.checks.blackberry
  36.     };
  37.     this.isAndroid = function () {
  38.         return this.checks.android
  39.     };
  40.     this.isTablet = function () {
  41.         return this.checks.ipad || this.checks.tabletPc || this.checks.playbook || this.checks.androidTablet || this.checks.kindle
  42.     };
  43.     this.isDesktop = function () {
  44.         return !this.isTouchDevice() && !this.isSmartPhone() && !this.isTablet()
  45.     };
  46.     this.isSmartPhone = function () {
  47.         return (this.checks.mobile || this.checks.blackberry || this.checks.palmDevice || this.checks.otherMobileHints) && !this.isTablet() && !this.checks.ipod
  48.     };
  49.     this.construct();
  50.     return this
  51. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement