joe223 / tiny-swiper

Ingenious JavaScript Carousel powered by wonderful plugins. Lightweight yet extensible. Import plugins as needed, No more, no less.
https://tiny-swiper.js.org
1.29k stars 58 forks source link

Incorrect detect of touch enabled devices #21

Closed utilmind closed 3 years ago

utilmind commented 4 years ago

Hello! Unfortunately tiny-swiper makes false-positive detection of false enabled device.

Tested in Windows (laptop), using latest Chrome, FireFox, Opera and Edge (honestly tested in all these browsers and all returns "2" for navigator.maxTouchPoints). Only IE11 returned "undefined".

Here is, on my opinion, the most reliable way to detect touch enabled device. You may consider of something similar for tiny-swiper. (It's in jQuery but you can write self-destructing event handler in vanillaJS).

    isTouchDevice = false;
    $(window).one("touchstart", function() {
      isTouchDevice = true;
    });

Or just remove navigator.maxTouchPoints from detectTouch().

joe223 commented 4 years ago

Hi @utilmind , Sorry for the late reply. I'm stick on my full-time job this days.

We use Duck Typing in detectTouch methods —— It supports touch if this browser has document.maxTouchPoints or window.DocumentTouch , or window.ontouchstart.

That gives us a pretty fast and sync way to get the support in modern browsers(Without using the single condition).

Really glad to got your advise 😁