in partnership with mediatemple

Ticket #742 (assigned defect)

Opened 4 months ago

Last modified 2 days ago

IE's attachEvent, FF's addEventListener and Event fire order

Reported by: Devign Owned by: kamicane
Type: defect Priority: minor
Milestone: Mootools version 1.3 Component: Core
Keywords: Events, Event order Cc:

Description

IE 6/7 with attachEvent fires event reversed as they were attached. It's a common issue, not related to mootools. However, the Events class can handle it.

<script type="text/javascript">
addEvent("domready",function () {
	$("x").addEvent("click",function () { alert("1"); });
	$("x").addEvent("click",function () { alert("2"); });
});
</script>
<div id="x">x</div>

FF will alert 1, 2
IE will alert 2, 1

For custom events, it's obviously ok:

<script type="text/javascript">
addEvent("domready",function () {
	$("x").addEvent("custom",function () { alert("1"); });
	$("x").addEvent("custom",function () { alert("2"); });
	$("x").addEvent("click",function () { this.fireEvent("custom"); });
});
</script>
<div id="x">x</div>

alert 1,2 for both browsers.

Though I'm not relying on the event order, it might affect stuff without noticing.

Change History

Changed 4 months ago by kamicane

  • owner set to kamicane
  • status changed from new to assigned

Changed 3 months ago by kamicane

I tested more, and it seems to be more complicated than that.

Events are fired in random order in explorer, I suspect there's nothing we can do about that.

Changed 3 months ago by Devign

A pretty nasty solution could be handling all events with mootools and attach to an element only one event that will simply fire a list of attached events.
What do you think? Will it be a performance issue? Or vice versa?

Changed 2 months ago by jakub.pawlowicz

Guys, I've managed to implement Devign suggestion by changing addEvent/removeEvent methods from Element.Event.js.
Please find the diff here http://jakub.pawlowi.cz/downloads/Element.Event.IE.diff.

The code is still not perfect, but it works fine.

Changed 3 days ago by tomocchino

  • milestone changed from Mootools version 1.2 to Mootools version 1.3

Devign, your suggestion is certainly not a bad one, but it would be a very big overhaul to the events system, some of which jakub seems to have experimented with.

We won't add this for 1.2 but I'll move the ticket to 1.3 so we can readdress it later if we choose to. In my opinion, however, it's not really good practice to attach events that depend on others since they should be mutually exclusive.

Changed 2 days ago by tomocchino

  • priority changed from major to minor
  • milestone set to Mootools version 1.3
Note: See TracTickets for help on using tickets.