views:

12

answers:

1

Hello,

I'm writing my own widget and all works fine except the destroy method. It seems that all events aren't unbind properly...

(function($) {
    var _super = $.Widget.prototype;

    //
    $.widget("my.cool", {
        _create: function() {
            var $self = this, $element = this.widget();
            $element.mousedown($self.select);
            _super._create.apply(this, arguments);
        },
        // Destroying widget
        destroy: function() {
            var $element = this.widget();
            $element.unbind(".cool");
            _super.destroy.apply(this, arguments);
        },
        select: function() {
            alert("selected");
        }
    });
}) (jQuery);

To test it :

$("<div>").cool().cool("destroy").trigger("mousedown").data("events")

Even destroyed, I show the alert("selected"), events aren't unbind properly and I can see the "mousedown" in events data.

What's wrong with this?

A: 

Doh !

I found why, event should be bind like this :

$element.bind("mousedown.cool", $self.select);

And not like this :

$element.mousedown($self.select);
Arnaud F.