Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Collapsible tables with persistent cookie?

    Hi all,

    I've got a problem with some collapsible tables I want to include on a phpBB3 template. Basically, I want the forum categories on the main page to be collapsible like vBulletin, and have the user's browser remember the state of the tables. Not being proficient in JavaScript at all, I'm having a terrible time getting it to work. My own attempts at trying to fix this just bust the code and the DHTML no longer works.

    The script I'm using now would work great except the cookie shows it expires upon quiting the browser. I'd like it to expire in 90 days or a year. Something like that.

    Here is my test site so you can see what I mean. And here is the code I have in the head content.

    Code:
        <script language="javascript">
        function init()
        {
            var cookie = getCookie('collapse_obj');
            if(cookie)
            {
                var values = cookie.split(',');
    
                for(var i = 0; i < values.length; i++)
                {
                    var itm = getItem(values[i]);
    
                    if(itm)
                        itm.style.display = 'none';
                }
            }
        }
    
        function makeCookie(name, value, time()+604800);
        {
            var cookie = name + '=' + escape(value) + ';';
            document.cookie = cookie;
        }
    
        function getCookie(name)
        {
            if(document.cookie == '')
                return false;
    
            var firstPos;
            var lastPos;
            var cookie = document.cookie;
    
            firstPos = cookie.indexOf(name);
    
            if(firstPos != -1)
            {
                firstPos += name.length + 1;
                lastPos = cookie.indexOf(';', firstPos);
    
                if(lastPos == -1)
                    lastPos = cookie.length;
    
                return unescape(cookie.substring(firstPos, lastPos));
            }
    
            else
                return false;
        }
    
        function getItem(id)
        {
            var itm = false;
            if(document.getElementById)
                itm = document.getElementById(id);
            else if(document.all)
                itm = document.all[id];
            else if(document.layers)
                itm = document.layers[id];
    
            return itm;
        }
    
        function toggleItem(id)
        {
            itm = getItem(id);
    
            if(!itm)
                return false;
    
            if(itm.style.display == 'none')
                itm.style.display = '';
            else
                itm.style.display = 'none';
    
            ////////////////////
    
            cookie = getCookie('collapse_obj');
            values = new Array();
            newval = new Array();
            add    = 1;
    
            if(cookie)
            {
                values = cookie.split(',');
    
                for(var i = 0; i < values.length; i++)
                {
                    if(values[i] == id)
                        add = 0;
                    else
                        newval[newval.length] = values[i];
                }
            }
    
            if(add)
                newval[newval.length] = id;
    
            makeCookie('collapse_obj', newval.join(','));
    
            return false;
        }
        </script>
    Thanx.

  • #2
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No one can help I take it?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •