benmajor / jQuery-Touch-Events

A collection of mobile event plugins for jQuery.
MIT License
699 stars 225 forks source link

Bug: Events can't be set on window or document #163

Closed vHeemstra closed 4 years ago

vHeemstra commented 4 years ago

Problem If you attach a tap* event (maybe others as well) to window or document, the jQuery library throws an error: "Uncaught TypeError: elem.getClientRects is not a function" at jQuery.fn.init.offset.

Reason This is because of the .offset() call on window/document, which is not allowed according to this answer on a similar case.

Possible solution Maybe some check if the element invoking the event is window or document, and if so, set the offset data object to { x: 0, y: 0 } (since window and document are at the origin of measurement).

Temporary workaround As a temporary workaround, I attached the events to body, but it's not ideal.