简体   繁体   中英

How to destroy YUI Panel on close?

I want to be able to destroy a YUI Panel when the user clicks the close button.

I have tried using hideEvent but that does not work. I'm assuming since the object is still active and therefore cannot be destroyed:

panel.hideEvent.subscribe(function(o) {
    panel.destroy();
});

Is there a way I can destroy the Panel when a user clicks close? The close button is not assigned an ID although it is assigned a class:

<a class="container-close" href="#">Close</a>

Ending up having to use the setTimeout() function:

panel.hideEvent.subscribe(function(o) {
    setTimeout(function() {panel.destroy();}, 0);
});

using the hideEvent as above leads to javascript errors in firebug. the following solution works without problems:

dlg -> instance of yui2 dialog or similar. dlg.close -> is the html element of the close icon

Use the following code after having the dialog rendered:

//remove the default click handler (._doClose)
YAHOO.util.Event.removeListener(dlg.close, "click");   

//add a new click handler (._doClose)
YAHOO.util.Event.on(dlg.close, "click", function(){
    this.destroy();
}, dlg, true);

Where win is a YUI simple dialog, I use this:

w.win.hideEvent.subscribe(function(e) {
                                                    this.destroy();

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM