0
Welcome Guest! Login
0 items Join Now

Javascript + Cookie

    • Leckenby's Avatar
    • Leckenby
    • Elite Rocketeer
    • Posts: 714
    • Thanks: 0

    Javascript + Cookie

    Posted 16 years 8 months ago
    • I am trying to make a button which shows and hides a div panel. I am developing on leckenby.org for now (though it will be moved in the end), and you can see if you click "Members Area" in the bottom right that the top menu changes because the div is loaded over the top.

      Now this is my code to do this:

      window.addEvent("domready",function(){

      Fx.Height = Fx.Style.extend({initialize: function(el, options){this.parent(el, 'height', options);this.element.setStyle('overflow', 'hidden');},toggle: function(){return (this.element.offsetHeight > 0) ? this.custom(this.element.offsetHeight, 0) : this.custom(0, this.element.scrollHeight);},show: function(){return this.set(this.element.scrollHeight);}});

      Fx.Opacity = Fx.Style.extend({initialize: function(el, options){this.now = 1;this.parent(el, 'opacity', options);},toggle: function(){return (this.now > 0) ? this.start(1, 0) : this.start(0, 1);},show: function(){return this.set(1);}});

      var hiding = new Fx.Opacity($('insetwrap'), {duration: 250});
      var isVisible = false;

      $('insetwrap').setStyle("display","block");

      if(Cookie.get('mm_marea') != 'true'){
      hiding.hide();
      }else{
      isVisible = true;
      $('b_marea').toggleClass('close_marea');
      }

      $('b_marea').addEvent("click", function(){
      if(isVisible){
      hiding.start(0);
      isVisible = false;
      $('b_marea').toggleClass('close_marea');
      Cookie.remove('mm_marea');
      }
      else{
      hiding.start(1);
      isVisible = true;
      $('b_marea').toggleClass('close_marea');
      Cookie.set('mm_marea', 'true', {path: "/", duration: 200});
      }
      });
      });

      basically it just changes the top div (insetwrap) to display or not display, and then changes the class of the button (so I can have a picture for the button which changes between open/close etc).

      Now this part works, but I am also trying to set a cookie so it remembers whether it is open or closed when you change page, so that if you change page with member area open, it stays open. This is the bit I am struggling with.

      Could anyone look at my code and see why that part is not working?

      Thanks
      James
    • Leckenby's Avatar
    • Leckenby
    • Elite Rocketeer
    • Posts: 714
    • Thanks: 0

    Re: Javascript + Cookie

    Posted 16 years 8 months ago
    • Scrub this post:

      Problem was that I left ' visibility: hidden; opacity: 0;' in the style of insetwrap, when the script does it all!

Time to create page: 0.053 seconds