I now use the following code, which works:
/**
* listens for an event just once
* @param string event name
* @param function handler function
**/
zophe.event.once = function ( name, callbackFunc )
{
var o = {
hasBeenCalled : null,
callback: function(e) {
if ( this.hasBeenCalled ) return;
callbackFunc(e);
this.hasBeenCalled = true;
}
};
window.application.addEventListener ( name, o.callback );
};
But it is hardly ideal because it produces a lot of useless objects...
Maybe someone has a better way of doing this...
Christian
Christian Boulanger schrieb:
> Hi everybody,
>
> I am trying to listen to an event just once, but I don't get it to work.
> Here is my code:
>
> /**
> * listens for an event just once
> * @param string event name
> * @param function handler function
> **/
> zophe.event.once = function ( name, callbackFunc )
> {
> var o = { callback: function(e) {
> callbackFunc(e);
> zophe.event._remove ( this );
> } };
>
> window.application.addEventListener ( name, o.callback );
> };
>
> zophe.event._remove = function ( o )
> {
> window.application.removeEventListener ( name, o.callback );
> delete ( o );
> }
>
> Now I do:
>
> zophe.event.once( "requests-completed", function(){
> alert ( "all requests completed" );
> });
>
> It will continue to call my alert function if a "request-completed"
> event is dispatched. Any ideas?
>
> Christian
>
>
>
> _______________________________________________
> Qooxdoo-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
_______________________________________________
Qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel