Javascript Puzzle Anyone??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fancy Pants

    #1

    Javascript Puzzle Anyone??

    Hi everyone,


    Just wanted to post this on here to see what you all could come up
    with. I am creating a Font Sizer and it has to be compatible with
    NN4+,IE4+,Mozil la, And Opera. I have it working fine in all IE
    versions, but it doesn't work at all in the other browsers. Remember,
    this is a relative font sizer. Maybe i can use percentages? Anyone have

    any examples? I can find lots of examples of setting font sizes so that

    EVERYTHING on the page changes ot the same font size, but i don't want
    that. I need something that will take the relative sont size. I have
    alerts set up to let me know what's happening. Here's the code:


    <html>
    <head>


    </head>
    <body>
    <h1>Hello there</h1>
    <h2>Test</h2>
    anything.
    <br><br>
    <button type="submit" onclick="resize BodyText(2, 'n')" >+</button>
    <button type="submit" onclick="resize BodyText(-2, 'n')" >-</button>
    <button type="submit" onclick= "resizeBodyText (0, 'y')" >R</button>


    <script type="text/javascript">
    //----------------------------­---------------------


    var current = parseInt(getCoo kie("fontFactor ­"))
    if (isNaN(current) )
    current= 0;


    resizeBodyText( current, "n")
    function resizeBodyText( factor, reset)
    {
    if (reset=="y")
    factor= (current * -1);


    window.alert(cu rrent + " " + factor)
    //----------------------------­--------------------
    if (document.all) {
    var a = document.all;
    var s = '';
    current += factor;
    var test = "IE!"


    if (current < 0)
    current = 0;


    else
    for (var i = a.length-1; i >0;i--)
    {
    s=a[i].currentStyle.f ontSize+'­';
    s=Right(s,2);
    a[i].style.fontSize = parseInt(a[i].currentStyle.f on­tSize)+facto r+s;


    }


    setCookie("font Factor", current)

    }


    else if (document.getEl ementsByTagName ­) {
    var a = document.getEle mentsByTagName( ­"*");
    var s = '';
    current += factor;
    var test = "Netscape 6+!"
    if (current < 0)
    current = 0;
    else
    for (var i = a.length-1; i >0;i--)
    {
    s=a[i].style.fontSize +'';
    s=Right(s,2);
    a[i].style.fontSize = parseInt(a[i].style.fontSize )+­factor+s;

    }
    setCookie("font Factor", current)
    }
    else if (document.layer s) {
    var a = document.layers ("*");
    var s = '';
    current += factor;
    var test = "Netscape 6+!"
    if (current < 0)
    current = 0;
    else
    for (var i = a.length-1; i >0;i--)
    {
    s=a[i].style.fontSize +'';
    s=Right(s,2);
    a[i].style.fontSize = parseInt(a[i].style.fontSize )+­factor+s;

    }
    setCookie("font Factor", current)
    }
    else if (document.getEl ementById) {
    var a = document.getEle mentById("*")
    var s = '';
    current += factor;
    var test = "Opera 5!"
    if (current < 0)
    current = 0;
    else
    for (var i = a.length-1; i >0;i--)
    {
    s=a[i].style.fontSize +'';
    s=Right(s,2);
    a[i].style.fontSize = parseInt(a[i].style.fontSize )+­factor+s;

    }
    setCookie("font Factor", current)
    }
    else if (document.getCo mputedStyle) {
    var a = document.getCom putedStyle("*")
    var s = '';
    var test = "Mozilla!"
    current += factor;
    if (current < 0)
    current = 0;
    else
    for (var i = a.length-1; i >0;i--)
    {
    s=a[i].style.fontSize +'';
    s=Right(s,2);
    a[i].style.fontSize = parseInt(a[i].style.fontSize )+­factor+s;

    }
    setCookie("font Factor", current)
    }


    }


    //----------------------------­-------------------
    function Right(str, n) {
    if (n <= 0)
    return "";
    else if (n > String(str).len gth)
    return str;
    else {
    var iLen = String(str).len gth;
    return String(str).sub string(iLen, iLen - n);
    }

    }


    //----------------------------­---------------------
    function getCookie(name) {
    var dc = document.cookie ;
    var index = dc.indexOf(name + "=");
    if (index == -1) return null;
    index = dc.indexOf("=", index) + 1; // first character
    var endstr = dc.indexOf(";", index);
    if (endstr == -1) endstr = dc.length; // last character
    return unescape(dc.sub string(index, endstr));
    }
    function setCookie(name, value)
    {
    document.cookie = name + "=" + escape(value);


    }


    </script>

    </body>
    </html>

  • Stephen Chalmers

    #2
    Re: Javascript Puzzle Anyone??

    Fancy Pants <justinfancy@gm ail.com> wrote in message
    news:1118236652 .756527.136070@ g43g2000cwa.goo glegroups.com.. .
    Hi everyone,


    Just wanted to post this on here to see what you all could come up
    with. I am creating a Font Sizer and it has to be compatible with
    NN4+,IE4+,Mozil la, And Opera. I have it working fine in all IE
    versions, but it doesn't work at all in the other browsers. Remember,
    this is a relative font sizer. Maybe i can use percentages? Anyone have

    any examples? I can find lots of examples of setting font sizes so that

    EVERYTHING on the page changes ot the same font size, but i don't want
    that. I need something that will take the relative sont size. I have
    alerts set up to let me know what's happening. Here's the code:
    ----------------------

    You have been told elsewhere:
    http://www.developersdex.com/asp/mes...a.googlegroups.
    com%3E
    how to do this, namely by using relative font sizes for all elements and just changing the size of the body
    font, which resizes all others automatically.
    If you cannot act upon advice there's no point in continually asking the same question, or being a student for
    that matter.

    Here is the minimal modification to your original code.
    It cannot work on NN4.
    Let's hope it never gets used...

    <html>
    <head>
    </head>

    <body style={font-size:12pt}>
    <h1 style={font-size:1.2em}>Hel lo there</h1>
    <h2 style={font-size:1.1em}>Tes t</h2>
    anything.

    <script type="text/javascript">
    if(document.bod y && (document.getEl ementById || document.all) )
    document.write( "<form><inp ut type='button' onclick=\"resiz eBodyText(2, 'n')\" value='2'><inpu t type='button'
    onclick=\"resiz eBodyText(-2, 'n')\" value='-2' ><input type='button' onclick= \"resizeBodyTex t(0, 'y')\"
    value='0'></form>");

    var current = parseInt(getCoo kie("fontFactor "))
    if (isNaN(current) )
    current= 0;

    resizeBodyText( current, "n")

    function resizeBodyText( factor, reset)
    {
    if (reset=="y")
    factor= (current * -1);

    var a=null;

    if (current < 0)
    current = 0;
    else
    if( typeof document.body.c urrentStyle != 'undefined' )
    {
    s=document.body .currentStyle.f ontSize+'';
    s=Right(s,2);
    document.body.s tyle.fontSize= parseInt(docume nt.body.current Style.fontSize, 10)+factor+s;
    }
    else
    if( typeof document.body.s tyle != 'undefined')
    {
    s=document.body .style.fontSize +'';
    s=Right(s,2);
    document.body.s tyle.fontSize = parseInt(docume nt.body.style.f ontSize)+factor +s;
    }

    setCookie("font Factor", current)
    }

    file://-----------------------------------------------
    function Right(str, n)
    {
    if (n <= 0)
    return "";
    else if (n > String(str).len gth)
    return str;
    else {
    var iLen = String(str).len gth;
    return String(str).sub string(iLen, iLen - n);
    }
    }
    file://-------------------------------------------------
    function getCookie(name) {
    var dc = document.cookie ;
    var index = dc.indexOf(name + "=");
    if (index == -1) return null;
    index = dc.indexOf("=", index) + 1; // first character
    var endstr = dc.indexOf(";", index);
    if (endstr == -1) endstr = dc.length; // last character
    return unescape(dc.sub string(index, endstr));
    }
    function setCookie(name, value)
    {
    document.cookie = name + "=" + escape(value);
    }

    </script>
    </body>
    </html>

    --
    Stephen Chalmers http://makeashorterlink.com/?H3E82245A



    Comment

    Working...