View Full Version : controlling bootstrap order
27 Jan 2012, 9:36 AM
1. Browser Loads scripts (GWT and JQuery)
2. GWT onModuleLoad
3. add HTML snippets with JS using JQuery
4. execute JS added in snippets (which run on JQuery Ready function)
My question is: It is possible with the above architecture that jquery JS will fire the ready function between 1&4. After we go to attach to JQuery ready function in 4., that event is never fired so the JS will never be called. Is this possible? If yes, what is a better architecture,
27 Jan 2012, 12:09 PM
Your question isn't quite clear - are you asking when the ready event is called, or asking why some ready handlers are not triggered if they are attached too late?
I believe the ready function is usually called before the onModuleLoad has been run (using the default iframe linker anyway), so it is too late to add handlers for the event - if you add a click handler to a button that has already been clicked, in the same way, it will never be called.
jQuery uses the ready handler as a way to set up calls that should be run after the dom is ready, whereas onModuleLoad is run after entire page has been loaded, as the last resource to download from the main page (again, using the default iframe linker). If you are attaching jquery ready handlers in your onModuleLoad then, it is already too late.
Some options for you to consider:
Use a different event - loaded, for example might fire after both ready and onModuleLoad, but some testing would need to be done to be sure.
Fire an event or a callback from within your onModule load, and have those setup scripts keyed to work from that. Look into JSNI in the GWT documentation for how to do things like this.
Consider a different linker so that your GWT code runs earlier in the page lifecycle
If you can provide more information about what kinds of handlers you are attaching and when they are being attached, it might be possible to give you more specific advice.
27 Jan 2012, 1:14 PM
I think you have answered my question but I will provide more details:
Step 1 - We have a html page which loads both jquery and ExtGWT.
Step 2 - GWT onModuleLoad is run and all our GWT code executes
Step 3 - In our GWT code, we add HTML snippets which has JS using JQuery
Step 4 - The JS in snippets is executed (which run on JQuery Ready function)
I have to test some more but I believe step 4 will fail because JQuery Ready will be called before step 2 and because our scripts are not attached only in 4. Thus our scripts in step 4. will never be executed. Does this make sense,
27 Jan 2012, 1:30 PM
Yes, and for the reasons I mentioned in my other post, I think you are correct that those ready handlers (step 4) will not run, because that has already come and gone.
An idea to consider - instead of adding ready handlers in your GWT code, just run the code, as the ready event has already run. If that code is depending on some other work to be done that hasn't yet been completed, I think that points to the ready event not being the correct event to listen for.
Powered by vBulletin® Version 4.1.5 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.