[dokuwiki] Re: [OFFTOPIC] odd addEvent problem

On Wed, Aug 02, 2006 at 09:29:24AM +0200, Andreas Gohr wrote:
> Michael Klier writes:
> 
> It's about a DokuWiki plugin using DokuWiki's script libs. I think it's 
> pretty ontopic :-)

ok :-)

> My last guess is that there is a problem with using argv in the closure of 
> addEvent. In my opinion it should work the way you do it, but closures are 
> a bit tricky. It might be that the argv you use in the closure keeps 
> changing it's value while the loop runs. You might wanna try this (untested 
> and maybe stupid):
> 
> attachToolEvents: function(obj) {
>   ...
>         // attach the Event
>         calendar.buttonAttach(button,argv);
>   ...
> },
> 
> buttonAttach: function(button,argv){
>    addEvent(button,'click',function() { return calendar.show(argv); });
> },
> 
> The idea is to force the argv to be out of the loop scope into the 
> buttonAttach function scope. No idea if this really changes anything.

That was it :-D! Now it works the way it should although it`s odd to me
anyway (JS is sometimes really strange to me).

Thanks for your help Andi.

Michael

PS.: Now I only need a smart data model for the calendar plugin (no DB,
I like to keep it as wikilike as possible) ;-). Ideas welcome ;-).

-- 
Michael Klier

mail:   chi@xxxxxxxxxxx
www:    http://www.chimeric.de
icq:    206179334
jabber: chi@xxxxxxxxxxxxx
key:    http://downloads.chimeric.de/chi.asc
key-id: 0x8308F551

Other related posts: