Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » BrowserWidget, JQuery document.ready and BrowserFunctions
BrowserWidget, JQuery document.ready and BrowserFunctions [message #1067613] Tue, 09 July 2013 10:55 Go to next message
Stefan M is currently offline Stefan M
Messages: 29
Registered: September 2012
Junior Member
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 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan Furnadjiev
Messages: 1777
Registered: July 2009
Senior Member
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 #1067720 is a reply to message #1067700] Wed, 10 July 2013 05:43 Go to previous messageGo to next message
Stefan M is currently offline Stefan M
Messages: 29
Registered: September 2012
Junior Member
Hi Ivan,

I tried "$(window).load( function (){" instead of $(document).ready( function(){".
It isn't working either. You can check using my snippet i postet here.
Also plain javascript window.onload does not work.
Why are the BrowserFunction's put into place at a different time compared to the SWT-BrowserWidget?
What can i do now to make this work?
Re: BrowserWidget, JQuery document.ready and BrowserFunctions [message #1067905 is a reply to message #1067613] Thu, 11 July 2013 04:06 Go to previous messageGo to next message
Tim Buschtoens is currently offline Tim Buschtoens
Messages: 379
Registered: July 2009
Senior Member
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/
Re: BrowserWidget, JQuery document.ready and BrowserFunctions [message #1067953 is a reply to message #1067905] Thu, 11 July 2013 08:18 Go to previous messageGo to next message
Stefan M is currently offline Stefan M
Messages: 29
Registered: September 2012
Junior Member
I tried the aproach with "window.setTimeout(..." in my snippet, it worked there.
When i tried the same with our calendar-integration in our application it did not work, i get the same error as before. I checked also with higher timeouts (up to 10 secs), the BrowserFunction is not defined.
I created a snippet-plugin and put the same html and js - files in as we use in our application. There it works.
I cant see any difference, can you give me some hints where i can debug to see why the BrowserFunction is not defined in the client?

Thanks for your help

[Updated on: Thu, 11 July 2013 08:18]

Report message to a moderator

Re: BrowserWidget, JQuery document.ready and BrowserFunctions [message #1075617 is a reply to message #1067953] Mon, 29 July 2013 14:59 Go to previous message
Stefan M is currently offline Stefan M
Messages: 29
Registered: September 2012
Junior Member
Thanks to some suggestions from Tim we found the problem (although we do not know why its happening in this case):
Our html containing the calendar script also features a css for printing:
<link rel='stylesheet' type='text/css' href='../fullcalendar/fullcalendar.print.css' media='print' />

When
media='print'
is in place the page never completes loading.
Removing this solved the problem, as we do not want to support printing the calendar in RAP it does not matter.

Thanks for your help.
Previous Topic:Widget is disposed exception on table when double click
Next Topic:error occurs occasionally when using MARKUP_ENABLED img tag
Goto Forum:
  


Current Time: Sat Jul 26 15:32:16 EDT 2014

Powered by FUDForum. Page generated in 0.02537 seconds