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.su开发者_如何学Gobscribe(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);
});
Where win is a YUI simple dialog, I use this:
w.win.hideEvent.subscribe(function(e) {
this.destroy();
});
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);
精彩评论