Inside the textResize() function, on the first line try adding:
level = parseInt(level);

I'm thinking when you're manually calling textResize, you're doing
something like:
textResize(3);

But when you're doing it through the cookie, it's not an Integer, it's
a String:
textResize("3");

Your switch statement is testing for Integers, so "3" doesn't match
anything. And you don't have a default condition either to act on it,
so it does nothing.

On Jul 23, 1:07 pm, Magnificent
<imightbewrongbutidontthin...@gmail.com> wrote:
> Hello all,
>
> I'm doing a text resizer with a cookie to remember the font size
> level. I'm running into a little problem and was wondering if someone
> sees something obvious I'm missing.  The cookie is being set/read OK
> and the text resizer works when triggered manually, but it's not being
> executed on page load when you navigate to other pages.
>
> For example, on the home page, I set it to the largest size, size 3.
> This gets set to the cookie.  If you quit/relaunch the browser, the
> cookie still reports size 3.  Also, when you navigate to another page,
> onload, it reads the size 3 and it passes it to the textResize()
> function (these are my console.log() lines), but the text isn't
> actually resized on page load.  If you trigger the text resizer
> manually, it works.
>
> I'm controlling the font size by adding (or removing) a class to the
> body tag.  Anyone have any ideas why the text isn't resizing
> automatically onload?
>
> //START text resizer
> //on dom ready either set default cookie or read existing cookie
> $(function() {
>         //if no cookie, set cookie for default textsize of 1 (out of 3
> possible sizes)
>         //persist cookie for 365 days, 1 year
>         if (!$.cookie("textsize")){
>                 $.cookie("textsize", "1", { path: '/', expires: 365 });
>         }
>
>         //get cookie value and pass to textResize function
>         var cookie_val = $.cookie("textsize");
>         console.log("onload: " + cookie_val);
>         textResize(cookie_val);
>
> });
>
> function textResize(level){
>         var body = $("body");
>         console.log("textResize: " + level);
>
>         switch(level) {
>                 case 1:
>                         body.removeClass('bigText biggerText');
>                         $.cookie("textsize", "1", { path: '/', expires: 365 
> });
>                         break;
>                 case 2:
>                         body.removeClass('biggerText').addClass('bigText');
>                         $.cookie("textsize", "2", { path: '/', expires: 365 
> });
>                         break;
>                 case 3:
>                         body.addClass('biggerText');
>                         $.cookie("textsize", "3", { path: '/', expires: 365 
> });
>                         break;
>         }}
>
> //END text resizer

Reply via email to