elm-lang / mouse

Track global mouse clicks and movements, helpful for dragging.

Home Page:http://package.elm-lang.org/packages/elm-lang/mouse/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Non-integral `pageX` and `pageY` don't work

crazymykl opened this issue · comments

The CSSOM View Module redefines pageX and pageY as double. To make matters worse, IE 11 is prescient, and already treats them as such. IE 10 seems to exhibit the same issue.

(Crummy) SSCCE: on IE 11, go to jquery.com, scroll down the page a bit, run $('body').on('mousemove', function (e) { console.log(e.pageX, e.pageY) }), and waggle the cursor. Non-integral Y positions abound.

It would be nice to (also) get a patch version that decodes them as floats then rounds, just so existing libraries (e. g. https://github.com/zaboco/elm-draggable) work without changes.

It would be useful to have these values as floats with the decimals intact. We have a package that relies on detecting the direction of the mouse pointer movement (comparing last position to current position), and without the decimals, the algorithm does a lousy job at slow speeds because all values are rounded to the closest integer - any small movement registers as no movement.

I hit this issue today on IE 10, I don't need the position value but the Decoder is failing because pageX and pageY are Float in IE and the Position decoder expects Ints. Hence this line, in the DOM library in DOM.js:22 is never executed

_elm_lang$core$Native_Scheduler.rawSpawn(toTask(result._0));

I imagine the fix would be easy but would require a major bump in the version. Something like

type alias Position =
    { x : Float
    , y : Float
    }

position : Json.Decoder Position
position =
    Json.map2 Position
        (Json.field "pageX" Json.float)
        (Json.field "pageY" Json.float)

All the libraries that use elm-lang/mouse are not behaving as expected in IE.
List of open source projects using elm-lang/mouse:
https://github.com/search?q=elm-lang%2Fmouse&type=Code&utf8=%E2%9C%93

The Browser.Events module in elm/browser allows you to do whatever you want here.