This project is archived and is in readonly mode.

#35 ✓ invalid
Thomas Aylott

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

Reported by Thomas Aylott | May 28th, 2008 @ 10:05 AM | in 2.0 (closed)

Originally posted on Trac by Devign

Original Trac Ticket

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.


addEvent("domready",function () {
	$("x").addEvent("click",function () { alert("1"); });
	$("x").addEvent("click",function () { alert("2"); });
});

x

FF will alert 1, 2

IE will alert 2, 1

For custom events, it's obviously ok:


addEvent("domready",function () {
	$("x").addEvent("custom",function () { alert("1"); });
	$("x").addEvent("custom",function () { alert("2"); });
	$("x").addEvent("click",function () { this.fireEvent("custom"); });
});

x

alert 1,2 for both browsers.

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

Trac Attachments

Trac Comments

Changed 4 months ago by kamicane



                  Changed 4 months ago by kamicane

          owner
              set to kamicane
        
          status
              changed from new to assigned

          owner
              set to kamicane
        
          status
              changed from new to assigned
        
      

Changed 4 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 3 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/download.... 

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

      

Changed 2 weeks ago by tomocchino


        
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 weeks 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. 

          milestone
              changed from Mootools version 1.2 to Mootools version 1.3
        
      

Changed 2 weeks ago by tomocchino



                  Changed 2 weeks ago by tomocchino

          priority
              changed from major to minor
        
          milestone
              set to Mootools version 1.3

          priority
              changed from major to minor
        
          milestone
              set to Mootools version 1.3
        
      

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Tags

Referenced by

Pages