From: Manolo Carrasco Date: Mon, 25 Apr 2011 11:39:39 +0000 (+0000) Subject: Fix $(window).width/height X-Git-Tag: release-1.3.2~376 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d57b621ed3a5e7b005c9b10ccea5d215c21572bc;p=gwtquery.git Fix $(window).width/height --- diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java index 477b2afd..e554f4ae 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java @@ -16,7 +16,9 @@ package com.google.gwt.query.client.impl; import com.google.gwt.dom.client.Element; +import com.google.gwt.query.client.GQuery; import com.google.gwt.query.client.js.JsUtils; +import com.google.gwt.user.client.Window; /** * A helper class to get computed CSS styles for elements. @@ -48,6 +50,15 @@ public class DocumentStyleImpl { * - Otherwise it returns the real computed value. */ public double cur(Element elem, String prop, boolean force) { + if (elem.equals(GQuery.window)) { + if ("width".equals(prop)) { + return Window.getClientWidth(); + } + if ("height".equals(prop)) { + return Window.getClientHeight(); + } + elem = GQuery.body; + } if (elem.getPropertyString(prop) != null && (elem.getStyle() == null || elem.getStyle().getProperty(prop) == null)) { return elem.getPropertyDouble(prop); diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java index b3c6bf94..11b15310 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java @@ -1310,5 +1310,10 @@ public class GQueryCoreTest extends GWTTestCase { assertEquals("div", m.get(5).get(0).toLowerCase()); assertEquals("i", m.get(0).get(0).toLowerCase()); } - + + public void testWindowSize() { + GQuery w = $(GQuery.window); + assertTrue(w.width() > 0); + assertTrue(w.height() > 0); + } }