]> source.dussan.org Git - gwtquery.git/commitdiff
correct implemenation of curCSS method
authorJulien Dramaix <julien.dramaix@gmail.com>
Tue, 18 Jan 2011 22:14:59 +0000 (22:14 +0000)
committerJulien Dramaix <julien.dramaix@gmail.com>
Tue, 18 Jan 2011 22:14:59 +0000 (22:14 +0000)
gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java
gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java

index 563eb9dc14b3af505c5abd702bcc4c7b6c0eeb06..446a739c77f2e3e892224025cbbbf7666a50bb9c 100644 (file)
@@ -52,23 +52,26 @@ public class DocumentStyleImpl {
    */
   public String curCSS(Element elem, String name, boolean force) {
     name = fixPropertyName(name);
+    //value defined in the element style
+    String ret = elem.getStyle().getProperty(name);
+    
     if ("height".equalsIgnoreCase(name)) {
-      return String.valueOf(getHeight(elem));
+      return force ? String.valueOf(getHeight(elem))+"px" : ret;
     }
     if ("width".equalsIgnoreCase(name)) {
-      return String.valueOf(getWidth(elem));
+      return force ? String.valueOf(getWidth(elem))+"px" : ret;
     }    
     if ("opacity".equalsIgnoreCase(name)) {
-      return String.valueOf(getOpacity(elem));
+      return force ? String.valueOf(getOpacity(elem)) : ret;
     }
-    if (!force && elem.getStyle().getProperty(name) != null) {
-      String ret = elem.getStyle().getProperty(name);
+    if (!force) {   
       return ret == null ? "" : ret;
     } else {
       return getComputedStyle(elem, hyphenize(name), name, null);
     }
   }
   
+  
   /**
    * Fix style property names.
    */
index f7c54c50e4a3e7561fbf549fe394fa19825a9dd8..ba15210aab3ebdd67719da71a93e94e4938fd859 100644 (file)
@@ -455,7 +455,7 @@ public class GQueryCoreTest extends GWTTestCase {
     assertEquals("0.6", g.css("opacity", false));
     assertEquals("0.6", g.css("opacity", true));
     g.css("opacity", "");
-    assertEquals("1.0", g.css("opacity", false));
+    assertEquals("", g.css("opacity", false));
     assertEquals("1.0", g.css("opacity", true));
     g.css("opacity", "0.4");
     assertEquals("0.4", g.css("opacity", false));
@@ -743,8 +743,8 @@ public class GQueryCoreTest extends GWTTestCase {
     assertEquals(100, (int)GQUtils.cur(g.get(0), "height", false));
     assertEquals(100, (int)GQUtils.cur(g.get(0), "width", true));
     assertEquals(100, (int)GQUtils.cur(g.get(0), "height", true));
-    assertEquals("100", g.css("width"));
-    assertEquals("100", g.css("height"));
+    assertEquals("100px", g.css("width"));
+    assertEquals("100px", g.css("height"));
     assertEquals("100px", g.get(0).getStyle().getProperty("width"));
     assertEquals("100px", g.get(0).getStyle().getProperty("height"));
   }