prototypejs / prototype

Prototype JavaScript framework
http://prototypejs.org/
Other
3.54k stars 640 forks source link

Event.PointerX and Event.PointerY doesnt work on mobile safari (iphone/ipad) #178

Open jwestbrook opened 10 years ago

jwestbrook commented 10 years ago

previous lighthouse ticket #1253 by qrizly


I changed the following pointerX and pointerY function to give me an usable position. I am not sure how to create a test for this case if somebody can give pointers to do so i will try that

  function pointerX(event) {
    var docElement = document.documentElement,
     body = document.body || { scrollLeft: 0 };

    if (event.changedTouches) return (event.changedTouches[0].clientX +
      (docElement.scrollLeft || body.scrollLeft) -
      (docElement.clientLeft || 0));

    return event.pageX || (event.clientX +
      (docElement.scrollLeft || body.scrollLeft) -
      (docElement.clientLeft || 0));
  }

  function pointerY(event) {
    var docElement = document.documentElement,
     body = document.body || { scrollTop: 0 };

    if (event.changedTouches) return (event.changedTouches[0].clientY +
      (docElement.scrollLeft || body.scrollLeft) -
      (docElement.clientLeft || 0));

    return  event.pageY || (event.clientY +
       (docElement.scrollTop || body.scrollTop) -
       (docElement.clientTop || 0));
  }