Timtech4u / gwtquery

Automatically exported from code.google.com/p/gwtquery
MIT License
0 stars 0 forks source link

width() and heigth() returns 0 on element having "display: none" as css property #145

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
GQuery div = $("<div 
/>").attr("style","position:absolute;display:none;").text("give some 
dimensions");

int width = div.width();
int height = div.height();

width and height are both equals to zero. 

jQuery computes the width and the height of this element by temporary setting 
the display property to block before to calculate the width and setting back 
the display to none after the computation.

Original issue reported on code.google.com by julien.d...@gmail.com on 31 Jul 2012 at 7:14

GoogleCodeExporter commented 9 years ago
To be precise JQuery change the following values before the computation (only 
if the element is not displayed):
display: "block"
position: "absolute"
visibility: "hidden"

Original comment by julien.d...@gmail.com on 31 Jul 2012 at 7:14

GoogleCodeExporter commented 9 years ago
There are errors in my gwtquery project, something like:
Description Resource    Path    Location    Type
The method f(Object[]) is ambiguous for the type 
Function    GQuery.java /gwtquery/src/main/java/com/google/gwt/query/client line 
417 Java Problem

And I changed the code to fix this bug:

added the following in GQuery.java:
  private int getLayoutProperty(String name) {
        if (isEmpty()) {
            return 0;
        }
        if (!isVisible()) {
            Style style = get(0).getStyle();
            String display = style.getDisplay();
            String position = style.getPosition();
            String visibility = style.getVisibility();
            try {
                style.setDisplay(Display.BLOCK);
                style.setPosition(Position.ABSOLUTE);
                style.setVisibility(Visibility.HIDDEN);
                return (int) cur(name, true);
            } finally {
                style.setProperty("display", display);
                style.setProperty("position", position);
                style.setProperty("visibility", visibility);
            }
        }
        return (int) cur(name, true);
  }

change the following in GQuery.java:
  public int width() {
    return getLayoutProperty("width");
  }

  public int height() {
      return getLayoutProperty("height");
  }

And because of the errors, I can't write and run the tests.

Would anyone please refine and commit the code? If this piece of code is 
acceptable.

Thanks.

Original comment by wanjunf...@gmail.com on 6 Sep 2012 at 9:22

GoogleCodeExporter commented 9 years ago
@wanjunfeng could you seend an project so as we could see the issue. Also we 
need to know your operating system, java version and gwt/gquery versions

Original comment by manuel.carrasco.m on 7 Sep 2012 at 4:58

GoogleCodeExporter commented 9 years ago
@wanjunfeng your comment seems to be related to issue144

Original comment by manuel.carrasco.m on 7 Sep 2012 at 5:01

GoogleCodeExporter commented 9 years ago
Manolo,

I think that Wanjunfeng send a fix for this issue but he was not able to test 
it due to the issue 144. As I'm on holidays for 3 weeks could you review his 
code (comment 2) ?

Original comment by julien.d...@gmail.com on 8 Sep 2012 at 8:22

GoogleCodeExporter commented 9 years ago
Fixed with r1059, I have change the patch to address the other width/height 
methods as well, and added a test.

@wanjunfeng could you test that this fixes your code?
@Julien let me know it it looks good for you.

Thanks for contributing.
- Manolo

Original comment by manuel.carrasco.m on 10 Sep 2012 at 10:00

GoogleCodeExporter commented 9 years ago
Would you please let me know if the fix is included in the latest snapshot 
package? 

I checked the changes, looks good to me. I'll test it when there is a package.

Thanks for the fix.

Original comment by wanjunf...@gmail.com on 10 Sep 2012 at 10:16

GoogleCodeExporter commented 9 years ago
I published the snapshot to sonatype maven repos, I've just updated the 
download page with the link.

Original comment by manuel.carrasco.m on 10 Sep 2012 at 9:32

GoogleCodeExporter commented 9 years ago
It works for me.

Thanks!

Original comment by wanjunf...@gmail.com on 11 Sep 2012 at 7:49

GoogleCodeExporter commented 9 years ago
Doesn't work for me, even with the latest snapshot. 
Please see the attached sample project. 

Original comment by ortega....@gmail.com on 12 Oct 2012 at 1:05

Attachments:

GoogleCodeExporter commented 9 years ago
I reopen the issue. It's not fixed correctly.

Original comment by julien.d...@gmail.com on 12 Oct 2012 at 4:13

GoogleCodeExporter commented 9 years ago

Julien, It's a different issue, the problem now is that gquery does not compute 
certain values when the element is detached from the dom, that is the case in 
this example. 

Maybe we should determine whether the node is attached to the dom  when 
computing forced attributes, and attach it's grand-grand parent to the dom.

- Manolo

Original comment by manuel.carrasco.m on 12 Oct 2012 at 5:16

GoogleCodeExporter commented 9 years ago
I've committed a fix for the issue, @ortega.nav could you test if it works for 
you.

Snapshots are updated 

http://code.google.com/p/gwtquery/source/detail?r=eb0ef954258a36db8fa2fc72c09ac6
3232e2202a#

- Manolo

Original comment by manuel.carrasco.m on 12 Oct 2012 at 6:33

GoogleCodeExporter commented 9 years ago

Original comment by manuel.carrasco.m on 10 Dec 2012 at 7:58