Results 1 to 2 of 2

Thread: jquery default issue

  1. #1
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default jquery default issue

    Hi I have this code below.
    What I need to do and can not figure it out is, when a person first goes to a page and no cookie is found, i want it to show all div expaned, right now they are all staying close.
    Please help I been trying to figure this out for over 2 days now.

    What I was thinking is maybe check to see if cookies is set for this page, and if no cookie for this page is found, open all div's

    OPEN ALL DIVS ON PAGE

    Can anyone help me with this please

    HTML Code:
    (function($) {
        $.fn.extend({
            collapse: function(options) {
                
                var defaults = {
                    inactive : "inactive",
                    active : "active",
                    head : ".demo",
                    group : ".power1",
                    speed : 300,
                    cookie : "collapse3"  
                };
                // Set a cookie counter so we dont get name collisions
                var op = $.extend(defaults, options);
                    cookie_counter = 0;
    
                return this.each(function() {
                    
                    // Increment cookie name counter
                    cookie_counter++;
    
                    var obj = $(this),
                        sections = obj.find(op.head).addClass(op.inactive),
                        panel = obj.find(op.group).hide(),
                        l = sections.length,
                        cookie = op.cookie + "_" + cookie_counter;
    
                    // Look for existing cookies
    
                    for (c=0;c<=l;c++) {
                        var cvalue = $.cookie(cookie + c);
                        if ( cvalue == 'open' + c ) {
                            panel.eq(c).show();
                            panel.eq(c).prev().removeClass(op.inactive).addClass(op.active);
                        };
    	                };                 
                    sections.click(function(e) {
                        e.preventDefault();
                        var num = sections.index(this);
                        var cookieName = cookie + num;
                        var ul = $(this).next(op.group);
                        // If item is open, slide up
                        if($(this).hasClass(op.active)) {
                            ul.slideUp(op.speed);
                            $(this).removeClass(op.active).addClass(op.inactive);
                            $.cookie(cookieName, null, { path: '/', expires: 10 });
                            return
                        }
                        // Else slide down
                        ul.slideDown(op.speed);
                        $(this).addClass(op.active).removeClass(op.inactive);
                        var cookieValue = 'open' + num;
                        $.cookie(cookieName, cookieValue, { path: '/', expires: 10 });
                        
                    });
    
                });
            }
        });
    })(jQuery);

  2. #2
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I forgot to mention that currently when going to the page without clicking to expand a div, they are all closed by default.

    I changed this below from hide to show but then no cookies are set or something.

    panel = obj.find(op.group).hide(),

Bookmarks

Posting Permissions

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