Skip navigation
Brewster Jones
Currently Being Moderated

Remember last tab visited with Adobe Spry Tabs

Aug 10, 2012 2:47 PM

Tags: #spry #tabbed_panels #spry_cookies

I have been searching for an answer for this for sometime now.  The http://go.spry-it.com/cookie  is not working and all forums say to go there.  Any help/suggestions.  I want to go to the last tab looked at to pop focus after a page refresh or page change.  Cookies etc. Any help would be appreciated.

 
Replies
  • Currently Being Moderated
    Aug 10, 2012 10:30 PM   in reply to Brewster Jones

    Have a look at the following

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Spry Accordion</title>
    <link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet">
    </head>
    <body>
    <div id="TabbedPanels1" class="TabbedPanels">
      <ul class="TabbedPanelsTabGroup">
        <li class="TabbedPanelsTab" tabindex="0">Tab 1</li>
        <li class="TabbedPanelsTab" tabindex="0">Tab 2</li>
      </ul>
      <div class="TabbedPanelsContentGroup">
        <div class="TabbedPanelsContent">Content 1</div>
        <div class="TabbedPanelsContent">Content 2</div>
      </div>
    </div>
    <script src="SpryAssets/SpryTabbedPanels.js"></script>
    <script>
    var Spry; if (!Spry) Spry = {}; if (!Spry.Utils) Spry.Utils = {};
    
    // We need an unload listener so we can store the data when the user leaves the page
    // SpryDOMUtils.js only provides us with a load listener so we create this function
    
    Spry.Utils.addUnLoadListener = function(handler /* function */)
    { 
        if (typeof window.addEventListener != 'undefined')
            window.addEventListener('unload', handler, false);
        else if (typeof document.addEventListener != 'undefined')
            document.addEventListener('unload', handler, false);
        else if (typeof window.attachEvent != 'undefined')
            window.attachEvent('onunload', handler);
    };
    
    Spry.Utils.Cookie = function(type /* String*/, name /* String */, value /* String or number */, options /* object */){
        var name = name + '=';
            
        if(type == 'create'){
            // start cookie String creation
            var str = name + value;
            
            // check if we have options to add
            if(options){
                // convert days and create an expire setting
                if(options.days){
                    var date = new Date();
                    str += '; expires=' + (date.setTime(date.getTime() + (options.days * 86400000 /* one day 24 hours x 60 min x 60 seconds x 1000 milliseconds */))).toGMTString();
                }
                // possible path settings
                if(options.path){
                    str += '; path=' + options.path                
                }
                // allow cookies to be set per domain
                if(options.domain){
                    str += '; domain=' + options.domain;
                }
            } else {
                // always set the path to /
                str += '; path=/';
            }
            // set the cookie
            document.cookie = str;
        } else if(type == 'read'){
            var c = document.cookie.split(';'),
                str = name,
                i = 0,
                length = c.length;
            
            // loop through our cookies
            for(; i < length; i++){
                while(c[i].charAt(0) == ' ')
                    c[i] = c[i].substring(1,c[i].length);
                    if(c[i].indexOf(str) == 0){
                        return c[i].substring(str.length,c[i].length);
                    }
            }
            return false;
        } else {
            // remove the cookie, this is done by settings an empty cookie with a negative date
            Spry.Utils.Cookie('create',name,null,{days:-1});
        }
    };
    var cookie = Spry.Utils.Cookie('read','panel');
    //alert(cookie);
    var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1", {defaultTab: cookie ? parseFloat(cookie) : 0});
    Spry.Utils.addUnLoadListener(function(){
        Spry.Utils.Cookie('create','panel',TabbedPanels1.getCurrentTabIndex());
    });
    </script>
    </body>
    </html>

     

    Gramps

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points