Hey Adrian,

2009/6/28 Adrian Sutherland <[email protected]>:
> I found this post - http://forums.htmlhelp.com/index.php?showtopic=5399
>
> Basically (if you believe the information) it seems you have to use a
> setTimeout() - which seems too much of a hack even for me! So what I
> did is use a select() after the focus() and it works fine. I do this
> for both IE and FF - I've not decided if I should only use this logic
> for IE only. The post's essential point about a separate thread that
> IE used for Javascript would explain the random failures - again I
> have not validated if this is in fact true however! And I don't know
> why select() should help ...

Indeed, I usually take these random hints with a solid grain of salt!
Perhaps that select() also implies some kind of focus()?

> Looking at this lead me to a possible bug in Witty:
>
> If you use a JSlot and use exec() on it, then the created javascript
> call is something like xyz(this, e). Of course the "e" causes a
> javascript error because clearly it has not been set/defined - no
> event. Maybe the generated java should be xzy(this, null) - err... is
> null valid javascript?

You are right about the bug and the solution. I have fixed this in public git.

> In the end I used WApplication::doJavaScript() which worked fine -
> but, of course, it sends all the javascript to the browser each time
> (I guess) - while JSlot seems to be sent once even if you execute it
> several times (perhaps?).

That is true (at least if you pass it a WWidget parent which scopes the slot).

> Is there a way of defining "global" functions that I can call from my
> JSlots (or doJavaScript) - of course I can reverse engineer the way Wt
> calls JSlots - but it would be good to have thoughts on the "official"
> best practice.

There are several public, but not documented methods, for this (which
are indeed also by JSlot and several widgets). You might as well use
these until we have decided on the proper API for this. The reason for
them being undocumented is that I am still a bit unsure of the proper
signature for it (all in all it would be nice if Wt provided better
support for JavaScript than it does now). Another problem is that I am
unsure about possible JavaScript circular reference memory leaks with
the current API.

WApplication::declareJavaScriptFunction(): declares a "global" function:
e.g. wApp->declareJavaScriptFunction("myfoo", "function(a, b) { return
a + b; }");

WApplication::javaScriptClass(): the scope for "global" functions
(which is currently fixed to "Wt", but which we will allow to be
customized, so that a single web page can simultaneously have
different Wt applications in it, using the widget set mode.

A call to the declared javascript function thus is:
wApp->javaScriptClass() + ".myfoo(4, 5);"

It's all very verbose as well -- perhaps that could be improved before
deciding on a public API as well.

Regards,
koen

------------------------------------------------------------------------------
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to