BrowserWidget, JQuery document.ready and BrowserFunctions [message #1067613] |
Tue, 09 July 2013 10:55  |
Eclipse User |
|
|
|
Hi,
We use a jquery-based calendar script wrapped by a BrowserWidget in RCP.
When we tried it in RAP it didn't work.
The reason is that the calendar script calls a BrowserFunction in the document.ready like this:
$(document).ready(function () {
theJavaFunction();
});
But at this time "theJavaFunction", which is a SWT-BrowserFunction is not yet available. When i call it later, like when i click a button, it works fine.
I wrote a small snippet to reproduce the error, its attached to this post.
Should i file a bug?
Is there a workaround?
Thanks in advance,
Stefan
|
|
|
Re: BrowserWidget, JQuery document.ready and BrowserFunctions [message #1067700 is a reply to message #1067613] |
Wed, 10 July 2013 03:52   |
Eclipse User |
|
|
|
Hi Stefan,
BrowserFuction is attached to the client document in the document
"onload" event. According to JQuery documentation the .ready() function
is not compatible with body onload event (see [1]). You could try the
JQuery .load() function instead as suggested in the documentation.
[1] http://api.jquery.com/ready/
HTH,
Ivan
On 7/9/2013 5:55 PM, Stefan M wrote:
> Hi,
>
> We use a jquery-based calendar script wrapped by a BrowserWidget in RCP.
> When we tried it in RAP it didn't work.
> The reason is that the calendar script calls a BrowserFunction in the document.ready like this:
>
>
> $(document).ready(function () {
> theJavaFunction();
> });
>
> But at this time "theJavaFunction", which is a SWT-BrowserFunction is not yet available. When i call it later, like when i click a button, it works fine.
>
> I wrote a small snippet to reproduce the error, its attached to this post.
> Should i file a bug?
> Is there a workaround?
>
> Thanks in advance,
> Stefan
--
Ivan Furnadjiev
Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/
Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
|
|
|
|
Re: BrowserWidget, JQuery document.ready and BrowserFunctions [message #1067905 is a reply to message #1067613] |
Thu, 11 July 2013 04:06   |
Eclipse User |
|
|
|
Hi.
The problem here, I think, is that both your script and RAP try to do
something on the load event. RAP attaches the browserFunctions, your
script calls them. But since your script runs inside the iframe it's
called first. SWT/RCP does has better control over the browser widget
and can probably make sure it's notified first. To fix this, simply put
your code in a timeout:
$(document).ready(function () {
window.setTimeout( callTheJavaFunction, 0 );
});
Greetings,
Tim
Am 09.07.2013 16:55, schrieb Stefan M:
> Hi,
>
> We use a jquery-based calendar script wrapped by a BrowserWidget in RCP.
> When we tried it in RAP it didn't work.
> The reason is that the calendar script calls a BrowserFunction in the document.ready like this:
>
>
> $(document).ready(function () {
> theJavaFunction();
> });
>
> But at this time "theJavaFunction", which is a SWT-BrowserFunction is not yet available. When i call it later, like when i click a button, it works fine.
>
> I wrote a small snippet to reproduce the error, its attached to this post.
> Should i file a bug?
> Is there a workaround?
>
> Thanks in advance,
> Stefan
>
--
Tim Buschtöns
Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/
Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05651 seconds