andreruffert / rangeslider.js

🎚 HTML5 input range slider element jQuery polyfill
https://rangeslider.js.org
MIT License
2.17k stars 401 forks source link

Only works with touch for touchscreen laptops #34

Closed austinpray closed 10 years ago

austinpray commented 10 years ago

Hey there,

So I discovered a weird bug related to those hybrid touchscreen laptops floating around there on the market. Issue is verified to exist even on: http://andreruffert.github.io/rangeslider.js/

If you are using a laptop with a touchscreen, you cannot modify the slider with anything other than touch. You can touch the dial and move it like normal, but cannot use the mouse to modify the dial.

This looks like the culprit in the source:

function isTouchScreen() {
        var bool = false,
            DocumentTouch = DocumentTouch || {};
        if(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
            bool = true;
        }
        return bool;
    }

    var pluginName = 'rangeslider',
        pluginInstances = [],
        touchevents = isTouchScreen(),
        inputrange = supportsRange(),
        defaults = {
            polyfill: true,
            rangeClass: 'rangeslider',
            fillClass: 'rangeslider__fill',
            handleClass: 'rangeslider__handle',
            startEvent: ((!touchevents) ? 'mousedown' : 'touchstart') + '.' + pluginName,
            moveEvent: ((!touchevents) ? 'mousemove' : 'touchmove') + '.' + pluginName,
            endEvent: ((!touchevents) ? 'mouseup' : 'touchend') + '.' + pluginName
        };

Can the plugin work with both touchstart AND mouse events?

andreruffert commented 10 years ago

@austinpray thanks I know! I've already planned to change this in the next release :v:

austinpray commented 10 years ago

Great!! When is that due for?

andreruffert commented 10 years ago

@austinpray I made some optimizations see pr #36. Would be great if you can test the optimizations on your fancy device :wink:

austinpray commented 10 years ago

Neat! I will try it out and see if the issue is resolved. Thank you!

Note: it isn't my device it was failing on, I wouldn't be caught dead with one of those monstrosities. Who wants to get their grubby fingers all over their laptop screen??

austinpray commented 10 years ago

FYI this fixes the issue. Both the mouse and touch functionality work side-by-side.

andreruffert commented 10 years ago

As expected. Thanks dude!

austinpray commented 10 years ago

siqqq