cheminfo / nmrium

React component to display and process nuclear magnetic resonance (NMR) spectra.
https://docs.nmrium.org
MIT License
55 stars 26 forks source link

Touch screen devices (code from Rainer Haessner) #1161

Open nes-cgn opened 3 years ago

nes-cgn commented 3 years ago

Here comes what Rainer mentioned in our meeting from July 2nd:


const hasTouchScreen = function () {

  let hasTouchScreen = false;

  if ("maxTouchPoints" in navigator) {

    hasTouchScreen = navigator.maxTouchPoints > 0;

  } else if ("msMaxTouchPoints" in navigator) {

    hasTouchScreen = navigator.msMaxTouchPoints > 0;

  } else {

    let mQ = window.matchMedia && matchMedia("(pointer:coarse)");

    if (mQ && mQ.media === "(pointer:coarse)") {

      hasTouchScreen = !!mQ.matches;

    } else if ("orientation" in window) {

      hasTouchScreen = true; // deprecated, but good fallback

    } else {

      // Only as a last resort, fall back to user agent sniffing

      let UA = navigator.userAgent;

      hasTouchScreen =

        /\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) || /\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA);

    }

  }

  return hasTouchScreen;

};
targos commented 3 years ago

The thing is that we don't really want to detect if the device has a touch screen. What we want to flag is whether the it has no mouse. There are a lot of laptops now that have a touch screen (mine included) but people use them with a mouse.