#51 ✓duplicate
Kenneth Kin Lum

getDimensions() inconsistency with "hidden" elements

Reported by Kenneth Kin Lum | April 25th, 2008 @ 07:29 PM | in 1.6.0.3

would the following be a bug? it is from the recent prototype.js

When "display" is not "none", the offsetWidth is used but when "display"

is "none", then clientWidth is used. They differ since the offsetWidth

includes the border's width and clientWidth doesn't. also offsetWidth

doesn't take into consideration of scrollbar's presence, while

clientWidth does. (subtracting about 15 to 17 pixels)

(the same applies to height).

Thanks!

getDimensions: function(element) {

element = $(element);

var display = $(element).getStyle('display');

if (display != 'none' && display != null) // Safari bug

return {width: element.offsetWidth, height:

element.offsetHeight};

// All *Width and *Height properties give 0 on elements with

display none,

// so enable the element temporarily

var els = element.style;

var originalVisibility = els.visibility;

var originalPosition = els.position;

var originalDisplay = els.display;

els.visibility = 'hidden';

els.position = 'absolute';

els.display = 'block';

var originalWidth = element.clientWidth;

var originalHeight = element.clientHeight;

els.display = originalDisplay;

els.position = originalPosition;

els.visibility = originalVisibility;

return {width: originalWidth, height: originalHeight};

}

Comments and changes to this ticket

  • Juriy Zaytsev

    Juriy Zaytsev April 25th, 2008 @ 10:48 PM

    • State changed from “new” to “bug”
    • Title changed from “a bug for getWidth() and getDimensions() ?” to “getDimensions() inconsistency with "hidden" elements”
  • John-David Dalton

    John-David Dalton May 29th, 2008 @ 04:34 AM

    • Milestone set to 1.6.0.3
    • Assigned user set to “John-David Dalton”
  • Nick Stakenburg

    Nick Stakenburg June 9th, 2008 @ 06:14 PM

    After investigating this on the mailing list it seems like Element#getDimensions has some issues in latest GIT. http://groups.google.com/group/p...

    I figured it was related to this since I had to revert the following change before things started working properly:

    var display = element.getStyle('display'),
     dimensions = { width: element.clientWidth, height: element.clientHeight };
    // to
     dimensions = { width: element.offsetWidth, height: element.offsetHeight };
    

    It was done like this in 1.6.0.2, it had the comment 'Safari bug' attached to it, but I guess there is more to this then just a Safari bug, it seems like offsetWidth/Height is required for correct dimensions, not just on Safari.

    Might be a good idea to revert this back and investigate before changing to clientWidth.

  • John-David Dalton

    John-David Dalton June 9th, 2008 @ 09:36 PM

    Nick can you please make some failing test

    cases and attach them to this ticket?

    I removed the "Safari fix" because it was causing errors

    in other browsers.

    This week is all about testing so any unit tests or ways to patch

    this to make the current unit tests work and the newer failing tests work would be great :)

    Thanx,

    JDD

  • Nick Stakenburg

    Nick Stakenburg June 10th, 2008 @ 09:39 PM

    I'll try to create some failing test cases for this. What can you tell me about moving away from clientWidth/Height and the errors you mentioned? Unit tests seemed to pass before, I'm guessing those errors are caused by new unit tests?

  • John-David Dalton

    John-David Dalton June 11th, 2008 @ 03:45 PM

    Ya with the safari fix in:

      if (display != 'none' && display != null) // Safari bug
      return {width: element.offsetWidth, height: element.offsetHeight};
    

    It causes the dom_test "testElementClonePosition" to fail on every browser (in Windows).

  • Nick Stakenburg

    Nick Stakenburg June 11th, 2008 @ 04:48 PM

    Thanks, clonePosition seems to have changed since the last time I checked. I'll have to dig into that.

    After some more tests it seems that Element#cumulativeOffset is also bugged in IE. Reverting to the 1.6.0.2 version fixed that as well. It could also be a bug in Element#getOffsetParent, not sure yet. I'll open a different ticket on this when I know more, since it's not related to dimensions.

  • Nick Stakenburg

    Nick Stakenburg June 12th, 2008 @ 05:55 PM

    Created a new ticket with tests #162

  • John-David Dalton

    John-David Dalton June 13th, 2008 @ 11:13 PM

    I have a fix for getDimensions and cumulativeOffset working. I will commit a patch to my fork ASAP and send Andrew the patches. Turns out it wasn't related to offsetParent :).

  • John-David Dalton

    John-David Dalton June 16th, 2008 @ 09:33 PM

    Nick, I have added a patch for the issues you where seeing at:

    http://prototype.lighthouseapp.c...

  • John-David Dalton

    John-David Dalton June 20th, 2008 @ 10:43 PM

    • State changed from “bug” to “duplicate”

    Closing this as duplicate follow the link in my previous comment.

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 02:10 AM

    • Tag set to dimensions, section:dom

    [not-tagged:"dom" tagged:"section:dom" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 02:18 AM

    • Tag changed from dimensions, section:dom to section:dom

    [not-tagged:"dimensions" tagged:"section:dom" bulk edit command]

  • jeuxnewbanat

    jeuxnewbanat March 18th, 2016 @ 02:09 AM

    لعبة تلبيس الاميرة او تلبيس باربي هاتان اللعبتين مشابهتين كتيرا والتي يمتازان بأفضل بأجمل واحسن العاب تلبيس

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

Pages