GWT and jQuery.width()/bind()

22 views
Skip to first unread message

Darnok

unread,
Sep 14, 2011, 12:42:53 PM9/14/11
to Google Web Toolkit
I've developed a jQuery Widget, one of the things it does is appends
html and checks its width. This works standalone, but as soon as I
use it inside GWT page, the jQuery.width()/innerWidth()/outerWidth()
gets unexpected results, most often 0. Seems like there's a race
condition between the assignment of actual widths and me calling this
being available to width(). Is there a way to ensure that dynamically
created html is ready for subsequent use?
eg.
// css: .header { padding: 10px; }
$(root).append('<div id="h1">AAA</div>');
var h = $('#h1', root)
h.text(); // ok, gets AAA
h.width(); // most often 0
h.outerWidth(); // sometimes 0, sometimes 20 (10+10 of padding)

I also notice similar case in event handling - outside of GWT page
it's ok to bind jQuery hadlers and then trigger them straight after.
Inside GWT, the initial trigger might just be eaten up, eg:
$('.scrollable', root).bind('scroll', function(ui) {
console.log('scrolled!');
});
$('.scrolable', root).scrollLeft(100); // might not print "scrolled!"

This behaviour appears in both GWT Development mode and Compiled mode.

Jeff Larsen

unread,
Sep 15, 2011, 5:34:42 AM9/15/11
to google-we...@googlegroups.com
Have you looked at gwtQuery? That could probably solve your problems. It is a gwt port of JQuery



Darnok

unread,
Sep 15, 2011, 9:48:21 AM9/15/11
to Google Web Toolkit
Yes, I've tried, and getting the same issues with gwtQuery.
Reply all
Reply to author
Forward
0 new messages