Thanks, Benjamin, this worked. Here is my code for listening for global
events that I find very useful.
This way, you can nicely decouple objects which do not need to know
about each others' existence or name. this was inspired by dojo.event ...
Best, Christian
/**
* dispatches global events
* @param mixed events either a string containing event name(s)
separated by comma
* or a hash with the event name(s) as key(s) and the data to dispatch
with the event(s) as
* value(s).
**/
zophe.event.dispatch = function ( events )
{
var hash = {}, eventName;
if ( typeof events != "object" ) {
events = events.split(",");
for ( var i=0; i<events.length; i++ ){
hash[events[i]]=true;
}
} else {
hash = events;
}
for ( eventName in hash ) {
window.application.createDispatchDataEvent( eventName,
hash[eventName] );
window.application.debug ( [ "Dispatching event " + eventName,
hash[eventName] ] );
}
QxWidget.flushGlobalQueues();
}
/**
* listens for a global event and triggers function
* @param string name
* @param function callbackFunc
*/
zophe.event.listen = function ( name, callbackFunc )
{
window.application.addEventListener ( name, callbackFunc );
};
/**
* listens for an event just once
* @param string event name
* @param function handler function
**/
zophe.event.listen_once = function ( name, callbackFunc )
{
var o = {
callback: function(e) {
callbackFunc(e);
window.application.removeEventListener ( name, o.callback,
QxConst.CORE_EMPTY );
delete ( o );
}
};
window.application.addEventListener ( name, o.callback );
};
Benjamin Reitzammer schrieb:
> Hi Christian,
> sorry for being so late, but better late than never ;)
>
> On 6/8/06, Christian Boulanger <[EMAIL PROTECTED]> wrote:
>
>> I now use the following code, which works:
>>
> [...]
>
>> But it is hardly ideal because it produces a lot of useless objects...
>> Maybe someone has a better way of doing this...
>>
>
> If you look at the code in QxTarget.addEventListener and
> QxTarget.removeEventListener you see, that the matching that is done
> to find the listener which should be removed, is done using the third
> argument to the method call, the (optional) context object on which
> the method will be called.
> If it's not specified, QxConst.CORE_EMPTY is used.
>
> So your code to remove an event listener should probably look
> something like the following:
>
> window.application.removeEventListener ( name, o.callback, QxConst.CORE_EMPTY
> );
>
> I know this is hardly ideal, but it works (in my application, havent
> tested your code though).
>
> Maybe the qooxdoo team should consider making removing of event
> listeners, which do not work in the context of a specific object, a
> little easier aka without internal knowledge of QxTarget.
>
> HTH
> Cheers
>
> Benjamin
>
> P.S. I hope gmail doesn't mess up my message again ... if you have
> problems reading my mail, please tell me.
>
>
> _______________________________________________
> 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