This project is archived and is in readonly mode.

#1090 ✓wontfix
Kevin Sweeney

Destroying Element with Duplicate Event Handlers Throws Error in IE8

Reported by Kevin Sweeney | November 15th, 2010 @ 08:24 PM | in 1.3.1 (closed)

Given the following markup:



<ul id="list">
   <li><a href="#">One</a><a href="#" class="remove">Remove</a></li>
   <li><a href="#">Two</a><a href="#" class="remove">Remove</a></li>
   <li><a href="#">Three</a><a href="#" class="remove">Remove</a></li>
   <li><a href="#">Four</a><a href="#" class="remove">Remove</a></li>
   <li><a href="#">Five</a><a href="#" class="remove">Remove</a></li>
</ul>



Attempting to destroy one of the parent LI elements when the remove link is clicked throws "Object does not support this property or method":
http://jsfiddle.net/44GbP/

If only one click event is added, it works as expected: http://jsfiddle.net/UxtmM/

I have tracked this down to the clean call within the Element.destroy() method.

Comments and changes to this ticket

  • Jason Beaudoin

    Jason Beaudoin November 19th, 2010 @ 03:06 PM

    I can confirm that there is a problem with the element.destroy method in IE7 (haven't tried later versions). In my tests, it fails on line 3218 at Array.each(children, clean) which returns "Object doesn't support this property or method". I wasn't able to figure out how to fix it.

  • gonchuki

    gonchuki November 19th, 2010 @ 10:49 PM

    error is at line 3604 in a vanilla mootools-core-1.3-full-nocompat.js (sorry, no git on this machine to check with updated source and point to the actual line)

    event = new Event(event, self.getWindow());
    

    looks like self (which points to this inside the invoke) is not extended in IE, and wrapping it in document.id makes the trick. I could test it locally doing some Fiddler trickery to replace the JS in jsfiddle and it works and doesn't throw any error in IE. (don't know if it's the proper fix either)

  • gonchuki

    gonchuki November 19th, 2010 @ 10:52 PM

    Jason, is your issue with the same code snippet?
    I could only test it in IE8 and what I mentioned is the only error I saw.

  • Arian

    Arian November 19th, 2010 @ 11:48 PM

    • State changed from “new” to “open”
    • Milestone set to 1.3.1
    • Milestone order changed from “833” to “0”
  • Jason Beaudoin

    Jason Beaudoin November 22nd, 2010 @ 07:03 PM

    Gonchuki... I can demonstrate the failure on this page here:
    http://www.coldfiredesigns.com/2010/downloads/test/test.html

    After you click on the link and rollout, you will generate an error in IE. The error occurs on line 495 of my custom class:
    http://www.coldfiredesigns.com/2010/downloads/test/Message-Class/So...

    I corrected the problem for my class by replacing destroy() with dispose(). That did the trick.

  • gonchuki

    gonchuki November 22nd, 2010 @ 08:44 PM

    @Jason,
    My IE8 is kind of crashing after I trigger the JS debugger but the source of the error seems to be in the render function of Fx (with yet again another unwrapped element). Wild guess: maybe the destroy method is unwrapping the element too soon and something gets broken up in the chain?

  • mattcoz

    mattcoz November 26th, 2010 @ 09:17 PM

    The problem here is that the second event is being run before the first event. So it is being destroyed and then the first event is trying to be called on it. Since it has already been cleaned it fails. I think we have two options here:

    1. Stop events after an element has been destroyed.
    2. Use the generic Element.getWindow(self) instead of self.getWindow().
  • Christoph Pojer

    Christoph Pojer January 11th, 2011 @ 12:09 AM

    • State changed from “open” to “wontfix”

    In IE you cannot rely on the order of event handlers. If an Element gets destroyed there is no point in further executing its event handlers so maybe you should fix this issue differently.

    In any case, this issue will likely be fixed in MooTools 2.0 but not before.

Create your profile

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

Shared Ticket Bins

Pages