#35 ✓not_for_core
Andrew Dupont

Element#visible should consider hidden ancestors

Reported by Andrew Dupont | April 21st, 2008 @ 04:56 PM | in 1.7

Requested by the bastards from ticket #9. You people drive me crazy.

Comments and changes to this ticket

  • Andrew Dupont

    Andrew Dupont April 21st, 2008 @ 04:57 PM

    • State changed from “new” to “enhancement”
  • Juriy Zaytsev

    Juriy Zaytsev April 21st, 2008 @ 06:39 PM

    : )

    Thanks Andrew, I'll submit patch/tests later today.

  • Tobie Langel
  • Tobie Langel

    Tobie Langel April 21st, 2008 @ 08:25 PM

    This issue has crept up on trac a couple of times.

    Here's my take on it from a while back.

    Looks like HTML5 solves the problem with the irrelevant attribute.

    Until then, I must admit failing to see how we can elegantly solution this nor how adding parentNode check to Element#visible has an actual usecase.

  • Juriy Zaytsev

    Juriy Zaytsev April 21st, 2008 @ 08:57 PM

    Tobie,

    my idea [1] was to simply follow the same path we took, but extend it with an optional condition to check ancestor's styles. Such functionality is often viable.

    E.g. I needed to preload background images of all elements that are not "shown" on a page load - i.e. those with "visibility:hidden", "display:none" or any of those styles on element's ancestor. I had to traverse ancestors of each element manually, because simply doing:

     
    $$('*').findAll(function(el) {
      return !el.visible() || el.getStyle('visibility') == 'hidden';
    });
    
    

    was not good enough.

    [1] http://dev.rubyonrails.org/ticke...

  • Tobie Langel

    Tobie Langel April 21st, 2008 @ 09:08 PM

    As far as I'm concerned, that use case is too application-specific to be fit for core.

    It also makes the whole hide/show/toggle/visible api less consistent, which I'd rather avoid, getting users to understand the limitations of the CSS display property was hard enough, I don't think it's worth confusing them more with an extra param that has very limited use-cases so far.

  • Juriy Zaytsev

    Juriy Zaytsev April 23rd, 2008 @ 11:58 PM

    So am I closing this as a "wont_fix"?

    Are there any other use cases where this could be useful?

  • Tobie Langel

    Tobie Langel April 24th, 2008 @ 03:46 PM

    • State changed from “enhancement” to “not_for_core”

    Ya, we might as well close it for now.

  • Joshua Szmajda

    Joshua Szmajda July 17th, 2009 @ 08:07 PM

    • Tag set to dom

    We've found need for this true visibility test in our applications. Element.getDimensions requires the target element be visible when computing its dimensions. We needed to augment prototype to be able to test for visibility. What we do is simply walk up the DOM tree until we find a hidden element or the document object itself.

    I've attached a patch proposal to augment Prototype core to support this with an optional additional parameter indicating the request for DOM tree traversal.

  • Tobie Langel

    Tobie Langel July 18th, 2009 @ 01:56 AM

    Joshua: How do you handle the case where a parent node is hidden by external rather than inline style rules?

  • Joshua Szmajda

    Joshua Szmajda July 20th, 2009 @ 06:36 PM

    Tobie: I didn't consider that case. I think it's perhaps outside of the scope of the function, as the original implementation doesn't handle that case either.

    For my purposes in a rich internet app, all potential hiding elements have inline display: styles anyway due to the need to manipulate them during application operation.

  • Tobie Langel

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

    • Tag changed from dom to section:dom

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

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

Attachments

Pages