Re: Determining number of visible OPTIONs in a SELECT

"John M. Hann" <[email protected]>
Newsgroups gmane.comp.web.dom.wdf
Message-ID <[email protected]>
Excellent!  Glad you got this working.  

I imagine that the "ListViewer._optionHeight -= 6;"  code will get more complex as you discover other nuances with themes, etc.  

-- John

http://e-numera.com/ 

--- In [email protected], Ian Petersen <ispeters@g...> wrote:
>
> For anyone who's interested, here's what I did.  The following code
> has to run after the body exists.  Also, ListViewer is the class I'm
> using to manage paging the data, so I store the height of one option
> in ListViewer._optionHeight.
> 
> The project I'm working on only supports IE and Mozilla, so I
> unfortunately don't have the time or resources to test in Opera,
> Safari, or Konqueror, but it seems to work in IE and Mozilla.
> 
> Anyway, here's the code:
> 
> // this anonymous function makes an attempt at figuring out how tall an
> // OPTION element is.  We use the result when computing the optimum page
> // size in the auto-page-size calculation.
> (function() {
>     var select = document.createElement('select');
>     var option = document.createElement('option');
> 
>     select.size = 1;
>     select.style.border = 'none';
>     select.style.visibility = 'hidden';
> 
>     document.body.appendChild(select);
> 
>     // store the clientHeight _before_ we put the option inside the select
>     // because otherwise Mozilla goes kinda wonky....
>     ListViewer._optionHeight = select.clientHeight;
> 
>     select.appendChild(option);
> 
>     // detect IE...
>     if(!option.offsetHeight) {
>         // This -= 6 is a magic number determined by trial and error to fix
>         // IE.  I can't explain why it's 6 and not some other number.  It
>         // might be different from 6 in a different version of Windows or
>         // IE, or with a different theme.  Setting the font size to Extra
>         // Large did not affect it, and choosing one of the high-contrast
>         // themes did not affect it.  Six seems like a good approximation
>         // for now.
>         ListViewer._optionHeight -= 6;
>     }
> 
>     select.removeChild(option);
>     document.body.removeChild(select);
> 
>     // we probably don't need to do this, but I _really_ don't want to leak
>     // memory...
>     option = null;
>     select = null;
> })();
> 
> 
> Thanks for the suggestions,
> 
> Ian
> 
> --
> Tired of pop-ups, security holes, and spyware?
> Try Firefox: http://www.getfirefox.com
>



[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Fair play? Video games influencing politics. Click and talk back!
http://us.click.yahoo.com/u8TY5A/tzNLAA/yQLSAA/9rHolB/TM
--------------------------------------------------------------------~-> 

Unsubscribe
[email protected]

List info
http://www.quirksmode.org/dom/list.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/wdf-dom/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.