How to use mobile-detect - 10 common examples

To help you get started, we’ve selected a few mobile-detect examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flow-typed / flow-typed / definitions / npm / mobile-detect_v1.x.x / test_mobile-detect_v1.x.x.js View on Github external
// @flow
import MobileDetect from 'mobile-detect';

/* Trivial case */

// $ExpectError
MobileDetect.foo();

const detect = new MobileDetect('');

detect.mobile();
detect.mobileGrade();
detect.os();
detect.phone();
detect.tablet();
detect.userAgent();
detect.userAgents();
detect.version('Mobile');
detect.versionStr('Mobile');
detect.isPhoneSized(1024);

// $ExpectError
detect.foo();
github collective-soundworks / soundworks / src / client / Platform.js View on Github external
_getPlatform() {
    const ua = window.navigator.userAgent
    const md = new MobileDetect(ua);
    client.platform.isMobile = (md.mobile() !== null); // true if phone or tablet
    client.platform.os = (() => {
      let os = md.os();

      if (os === 'AndroidOS') {
        return 'android';
      } else if (os === 'iOS') {
        return 'ios';
      } else {
        return 'other';
      }
    })();
  }
github collective-soundworks / soundworks / src / client / services / Platform.js View on Github external
_definePlatform() {
    const ua = window.navigator.userAgent
    const md = new MobileDetect(ua);

    client.platform.isMobile = (md.mobile() !== null); // true if phone or tablet
    client.platform.os = (function() {
      const os = md.os();

      if (os === 'AndroidOS')
        return 'android';
      else if (os === 'iOS')
        return 'ios';
      else
        return 'other';
    })();
  }
}
github Rebelizer / pellet / src / manifest.js View on Github external
}

        if(fs.existsSync(path.resolve(options.projectRootPath, 'node_modules', 'pellet', 'node_modules', 'messageformat'))) {
          externalDependencies.messageformat = path.join('pellet', 'node_modules', 'messageformat');
        } else {
          externalDependencies.messageformat = path.resolve(__dirname, '..', 'node_modules', 'messageformat');
        }

        if(fs.existsSync(path.resolve(options.projectRootPath, 'node_modules', 'pellet', 'node_modules', 'superagent'))) {
          externalDependencies.superagent = path.join('pellet', 'node_modules', 'superagent');
        } else {
          externalDependencies.superagent = path.resolve(__dirname, '..', 'node_modules', 'superagent');
        }

        if (fs.existsSync(path.resolve(options.projectRootPath, 'node_modules', 'pellet', 'node_modules', 'mobile-detect', 'mobile-detect.min.js'))) {
          externalDependencies['mobile-detect/mobile-detect.min.js'] = path.join('pellet', 'node_modules', 'mobile-detect', 'mobile-detect.min.js');
        } else {
          externalDependencies['mobile-detect/mobile-detect.min.js'] = path.resolve(__dirname, '..', 'node_modules', 'mobile-detect', 'mobile-detect.min.js');
        }
      } else {
        externalDependencies = {
          React: 'react/addons',
          react: 'react/addons',
          intl: 'intl',
          superagent:'superagent',
          messageformat: 'messageformat',
          ejs: 'ejs'
        };

        //if (!fs.existsSync(path.resolve(__dirname, '..', 'node_modules', 'mobile-detect', 'mobile-detect.min.js'))) {
        //  externalDependencies['mobile-detect/mobile-detect.min.js'] = path.resolve(__dirname, '..', 'node_modules', 'mobile-detect', 'mobile-detect.min.js');
        //}
github Paratii-Video / paratii-player / imports / lib / sniffing / index.js View on Github external
function Sniffer (...opts) {
  this.classes = ''
  this.debug = (opts[0].debug)
  this.embedded = false
  this._mobileSniffer = new MobileDetect(window.navigator.userAgent)
}
github meetup / meetup-web-platform / packages / mwp-core / src / renderers / server-render.jsx View on Github external
const getMedia = (userAgent: string, userAgentDevice: string) => {
	const isAtSmallUp = true;
	let isMobile = true;
	let isTablet = false;

	if (userAgentDevice) {
		isMobile =
			userAgentDevice === 'smartphone' ||
			userAgentDevice === 'mobilebot' ||
			userAgentDevice === 'mobile';
		isTablet = userAgentDevice === 'tablet';
	} else {
		const mobileDetect = new MobileDetect(userAgent);
		isMobile = Boolean(mobileDetect.phone());
		isTablet = Boolean(mobileDetect.tablet());
	}

	return {
		isAtSmallUp,
		isAtMediumUp: isTablet || !isMobile,
		isAtLargeUp: !isMobile && !isTablet,
	};
};
github CRUKorg / cruk-searchkit / src / components / search / date / CRUKSearchkitDateRange.jsx View on Github external
render() {
    const argState = this.accessor.getQueryObject();
    let { focusedInput, startDate, endDate, initialVisibleMonth } = this.state;
    /**
     * These functions can return null so check for bool true.
     */
    const md = new MobileDetect(window.navigator.userAgent);
    const isMobile = md.mobile() || md.phone();
    const numberOfMonths = isMobile ? 1 : 2;

    if (this.noArgs && argState[this.props.id] !== undefined && Object.keys(argState[this.props.id]).length > 0) {
      if (typeof argState[this.props.id].min !== undefined) {
        startDate =  moment(argState[this.props.id].min)
        initialVisibleMonth = () => startDate
      }
      endDate = (typeof argState[this.props.id].max !== undefined) ? moment(argState[this.props.id].max) : null
    }

    return (
      <div>
        </div>
github andrevvm / wp-vuejs / _app / src / App.vue View on Github external
created() {
    var md = new MobileDetect(window.navigator.userAgent);
    this.$store.state.mobile = md.mobile();
  }
}
github UXVirtual / night-sky / online / assets / src / index.js View on Github external
skyboxContainer2RotZ: 175, //ajust X value to rotate sky into position according to long

    skyboxRotX: 54,
    skyboxRotY: 326,
    skyboxRotZ: 347
};

var defaultWaterSide = THREE.FrontSide;

var debugOn = false;

var pointClouds = [];

var spriteContainer;

var md = new MobileDetect(window.navigator.userAgent);

var androidVersion = md.versionStr('Android');

var iOSVersion = md.versionStr('iOS')


var oldAndroid = (androidVersion !== null &amp;&amp; cmpVersions(androidVersion,'5', '.') &lt; 0);

var oldIOS = (iOSVersion !== null &amp;&amp; cmpVersions(iOSVersion,'9', '_') &lt; 0);

var canHandleOrientation = false;

(function() {

    var originalGetExtensionFunction = WebGLRenderingContext.prototype.getExtension;
github slidewiki / slidewiki-platform / components / DeckCollection / GroupCollections.js View on Github external
componentDidMount() {
        let userAgent = window.navigator.userAgent;
        let mobile = new MobileDetect(userAgent);
        this.setState({isMobile: (mobile.phone() !== null ) ? true : false});
    }

mobile-detect

Device detection (phone, tablet, desktop, mobile grade, os, versions)

MIT
Latest version published 4 years ago

Package Health Score

58 / 100
Full package analysis