Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DeviceDetection = function ()
- {
- this.construct = function (userAgent) {
- "undefined" == typeof userAgent && (userAgent = navigator.userAgent);
- this.userAgent = userAgent;
- this.checks = {
- iphone: Boolean(userAgent.match(/iPhone/)),
- ipod: Boolean(userAgent.match(/iPod/)),
- ipad: Boolean(userAgent.match(/iPad/)),
- blackberry: Boolean(userAgent.match(/BlackBerry/)),
- playbook: Boolean(userAgent.match(/PlayBook/)),
- android: Boolean(userAgent.match(/Android/)),
- macOS: Boolean(userAgent.match(/Mac OS X/)),
- win: Boolean(userAgent.match(/Windows/)),
- mac: Boolean(userAgent.match(/Macintosh/)),
- wphone: Boolean(userAgent.match(/(Windows Phone OS|Windows CE|Windows Mobile)/)),
- mobile: Boolean(userAgent.match(/Mobile/)),
- androidTablet: Boolean(userAgent.match(/(GT-P1000|SGH-T849|SHW-M180S)/)),
- tabletPc: Boolean(userAgent.match(/Tablet PC/)),
- palmDevice: Boolean(userAgent.match(/(PalmOS|PalmSource| Pre\/)/)),
- kindle: Boolean(userAgent.match(/(Kindle)/)),
- otherMobileHints: Boolean(userAgent.match(/(Opera Mini|IEMobile|SonyEricsson|smartphone)/))
- }
- };
- this.isTouchDevice = function () {
- return this.checks.iphone || this.checks.ipod || this.checks.ipad
- };
- this.isApple = function () {
- return this.checks.iphone || this.checks.ipod || this.checks.ipad || this.checks.macOS || this.checks.mac
- };
- this.isIOS = function () {
- return this.checks.iphone || this.checks.ipod || this.checks.ipad
- };
- this.isBlackberry = function () {
- return this.checks.blackberry
- };
- this.isAndroid = function () {
- return this.checks.android
- };
- this.isTablet = function () {
- return this.checks.ipad || this.checks.tabletPc || this.checks.playbook || this.checks.androidTablet || this.checks.kindle
- };
- this.isDesktop = function () {
- return !this.isTouchDevice() && !this.isSmartPhone() && !this.isTablet()
- };
- this.isSmartPhone = function () {
- return (this.checks.mobile || this.checks.blackberry || this.checks.palmDevice || this.checks.otherMobileHints) && !this.isTablet() && !this.checks.ipod
- };
- this.construct();
- return this
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement