From 55e5d645e14407d336293257d3a98eab0a06b7cd Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Fri, 28 Mar 2008 13:13:16 -0500 Subject: [PATCH] Fix issues where Firefox improperly returns the wrong node from a call to Event.element. Also fixes possible exception in Event.element in IE. --- CHANGELOG | 4 ++++ src/event.js | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ff224f0..8ab6ef8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +* Fix issues where Firefox improperly returns the wrong node from a call to Event.element. Also fixes possible exception in Event.element in IE. [jdalton, Andrew Dupont] + +* Fix issue where Safari 3 deletes custom properties from the document object when the page is returned to via the back button. [mzsanford, kangax, Andrew Dupont] + * Integrate support for the W3C Selectors API into the Selector class. Will now use the API when possible (browser supports the API *and* recognizes the given selector). Means minor changes to the semantics of :enabled, :disabled, and :empty in order to comply with CSS spec. * Avoid re-extending element in Element#getDimensions. [kangax] diff --git a/src/event.js b/src/event.js index 5ccc055..ee31b02 100644 --- a/src/event.js +++ b/src/event.js @@ -59,8 +59,23 @@ Event.Methods = (function() { isRightClick: function(event) { return isButton(event, 2) }, element: function(event) { - var node = Event.extend(event).target; - return Element.extend(node.nodeType == Node.TEXT_NODE ? node.parentNode : node); + event = Event.extend(event); + + var node = eventTarget, type = event.type; + + if (event.currentTarget) { + // Firefox screws up the "click" event when moving between radio buttons + // via arrow keys. It also screws up the "load" and "error" events on images, + // reporting the document as the target instead of the original image. + var currentTarget = event.currentTarget; + var tagName = currentTarget.tagName.toUpperCase(); + if (['load', 'error'].include(type) || + (tagName === 'INPUT' && currentTarget.type === 'radio' && type === 'click')) + node = currentTarget; + } + + return Element.extend(node && node.nodeType == Node.TEXT_NODE ? + node.parentNode : node); }, findElement: function(event, expression) {