<commit_before>/**
 * Collapse plugin for jQuery
 * ---
 * @author <NAME> (http://webcloud.se)
 * @version 0.1
 * @updated 28-APR-2010
 * ---
 * Note: For cookie support you need 
 * the cookie plugin from here: http://plugins.jquery.com/project/cookie
 * ---
 */
 
 (function($) {
    $.fn.extend({
        collapse: function(options) {
            
            var defaults = {
                inactive : "inactive",
                active : "active",
                head : "h3",
                group : "ul",
                speed : 100,
                cookie : "collapse"
            };
            
            // 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);<commit_msg>restructured internal methods<commit_after>/**
 * Collapse plugin for jQuery
 * ---
 * @author <NAME> (http://webcloud.se)
 * @version 0.1
 * @updated 28-APR-2010
 * ---
 * Note: For cookie support you need 
 * the cookie plugin from here: http://plugins.jquery.com/project/cookie
 * ---
 */
 
(function($) {
    $.fn.extend({
        collapse: function(options) {
            
            var defaults = {
                open : false,
                inactive : "inactive",
                active : "active",
                head : "h3",
                group : "ul",
                speed : 100,
                cookie : "collapse"
            };
            
            // Set a cookie counter so we dont get cookie name collisions
            var op = $.extend(defaults, options);
                cookie_counter = 0;
                
            // Internal method for showing 
            var _show = function(el) {
                $.each(el, function() {
                    $(this).show().prev().removeClass(op.inactive).addClass(op.active);
                });
            }
            
            // Internal method for hiding
            var _hide = function(el) {
                $.each(el, function() {
                    $(this).hide().prev().removeClass(op.active).addClass(op.inactive);
                }); 
            }
                
            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;

                // Open by default
                if(op.open) {
                    _show(panel);
                }
                
                // Look for existing cookies
                for (c=0;c<=l;c++) {
                    var val = $.cookie(cookie + c);
                    if ( val == c + "open" ) {
                        _show(panel.eq(c));
                    } else if ( val == c + "closed") {
                        _hide(panel.eq(c))
                    }
                };
                sections.click(function(e) {
                    e.preventDefault();
                    var num = sections.index(this),
                        cookieName = cookie + num,
                        cookieVal = num,
                        ul = $(this).next(op.group);
                    // Hide
                    if($(this).hasClass(op.active)) {
                        _hide(ul.slideUp(op.speed));
                        cookieVal += 'closed'
                        $.cookie(cookieName, cookieVal, { path: '/', expires: 10 });
                        return;
                    }
                    // Show
                    _show(ul.slideDown(op.speed));
                    cookieVal += 'open';
                    $.cookie(cookieName, cookieVal, { path: '/', expires: 10 });
                });
            });
        }
    });
})(jQuery);
{'fraction_non_alphanumeric': 0.12504409171075836, 'fraction_numerical': 0.006349206349206349, 'mean_word_length': 0.991921320688444, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6466903', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1324, 'n_words': 295}