Skip to content

Commit

Permalink
Many minor cleanups in event.js.
Browse files Browse the repository at this point in the history
  • Loading branch information
savetheclocktower committed May 19, 2008
1 parent 3953445 commit 8c2873f
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/event.js
Expand Up @@ -60,17 +60,14 @@ Event.Methods = (function() {

element: function(event) {
event = Event.extend(event);
var node = event.target, currentTarget = event.currentTarget, type = event.type;

var node = event.target, type = event.type;

if (event.currentTarget && event.currentTarget.tagName) {
if (currentTarget && currentTarget.tagName) {
// 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"))
(currentTarget.tagName.toUpperCase() === "INPUT" && currentTarget.type === "radio" && type === "click"))
node = currentTarget;
}

Expand Down Expand Up @@ -127,13 +124,13 @@ Event.extend = (function() {
if (!event) return false;
if (event._extendedByPrototype) return event;

event._extendedByPrototype = Prototype.emptyFunction;
var pointer = Event.pointer(event);
Object.extend(event, {
target: event.srcElement,
_extendedByPrototype: Prototype.emptyFunction,
target: Element.extend(event.srcElement),

This comment has been minimized.

Copy link
@tobie

tobie Sep 3, 2008

Collaborator

As per specs, Event#target can be any kind of NODE element and is thus not guaranteed to be an element. There’s no point in extending it in IE as we cannot guarantee that it will be an extended element in browsers which are spec compliant with regards to events but which do not fully implement the HTMLElement interface (Safari, notably).

relatedTarget: Event.relatedTarget(event),
pageX: pointer.x,
pageY: pointer.y
pageX: pointer.x,
pageY: pointer.y
});
return Object.extend(event, methods);
};
Expand Down

1 comment on commit 8c2873f

@savetheclocktower
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. We have Event#element for that.

Please sign in to comment.