Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9920 (closed defect: fixed)

Opened 11 months ago

Last modified 6 months ago

[PATCH] Event.pointer returns incorrect value in IE

Reported by: ephogy Assigned to: sam
Priority: low Milestone: 2.x
Component: Prototype Version: edge
Severity: minor Keywords: Event.pointer
Cc:

Description

IE7 has a 2 pixel border around the window which can not be styled/removed. positioning elements within the body at 300px,200px will result in a mouse pointer location of 302px,202px. The following fix ensures that Opera, IE6/7, Firefox and Safari all return the same values. The work around I used was as follows

Prototype.Browser.IE7 = !!(window.attachEvent && !window.opera) && /MSIE 7/.test(navigator.userAgent);

if (Prototype.Browser.IE7) {

Event.pointer = function(event) {

return {

x: event.clientX + document.documentElement.scrollLeft - 2, y: event.clientY + document.documentElement.scrollTop - 2

};

}

}

Attachments

clientLeft_clentTop.diff (0.7 kB) - added by kangax on 10/19/07 15:01:02.
event.js.patch (0.7 kB) - added by RQuadling on 03/19/08 15:19:44.
Patch to fix Event.pointer on IE when dealing with pre dom:loaded custom events (compatible with changeset 9060)

Change History

10/19/07 13:13:03 changed by ephogy

See Ticket #9921 for unified patch

10/19/07 15:00:30 changed by kangax

  • priority changed from normal to low.
  • severity changed from normal to minor.
  • summary changed from Event.pointer returns incorrect value for IE7 to Event.pointer returns incorrect value in IE.

@ephogy, thanks for reporting it - this seems like a valid bug.

The problem is not IE7, though, but IE in general and the way it calculates clientX/clientY in standards mode. This doesn't happen in quirks mode. The fix is trivial - extract clientLeft/clientTop values (if present). The patch is attached

Here's a couple of references:
http://hartshorne.ca/2006/01/23/javascript_cursor_position/ http://trac.openlayers.org/ticket/863

10/19/07 15:01:02 changed by kangax

  • attachment clientLeft_clentTop.diff added.

10/19/07 17:56:43 changed by kangax

  • summary changed from Event.pointer returns incorrect value in IE to [PATCH] Event.pointer returns incorrect value in IE.

10/23/07 18:55:52 changed by kangax

btw,
Mochikit takes this into account
Ajaxian wrote about it

03/19/08 07:01:57 changed by tobie

  • status changed from new to closed.
  • resolution set to fixed.

(In [9060]) prototype: Fix Event#pointer in IE standard mode. Closes #9920.

03/19/08 15:19:44 changed by RQuadling

  • attachment event.js.patch added.

Patch to fix Event.pointer on IE when dealing with pre dom:loaded custom events (compatible with changeset 9060)