<commit_before>/**
 * Work in progress
 * v. 0.0.-1
 */

(function( $, undefined ) {
    $.widget( "dattaya.maccordion", {
        options: {
            active     : 0,
            header     : "> li > :first-child,> :not(li):even",
            event      : "click",
            easing     : "swing",
            speed      : "normal",
            disabled   : false,
            heightStyle: false,
            animated   : true,
            icons: {
                activeHeader: "ui-icon-triangle-1-s",
                header      : "ui-icon-triangle-1-e"
            }
        },

        /**
         *
         * @param {jQuery} $headers
         */
        _toggle: function( $headers ) {

            var options = this.options;

            if ( $headers.length == 0 )
                return;

            console.debug( "_toggle" );

            $headers
                .toggleClass( "ui-state-active ui-corner-all ui-corner-top dattaya-maccordion-header-active" )
                .find( ".dattaya-maccordion-header-icon" )
                    .toggleClass( options.icons.header + " " + options.icons.activeHeader );

            // ARIA
            $headers.maccordionToggleAttributes( "aria-selected aria-expanded" );

            if ( options.animated ) {
                $headers.next()
                    .slideToggle( this.options.speed, this.options.easing );
            } else {
                $headers.next().toggle();
            }

            $headers.next().toggleClass( "dattaya-maccordion-content-active" );
        },

        /**
         *
         * @param {Object} event
         */
        _eventHandler: function( event ) {
            var options = this.options;

            if ( options.disabled ) {
                return;
            }

            console.debug( event.type === "keypress" ? "click" : event.type );

            this._toggle( $( event.currentTarget ) );

            event.preventDefault();
        },

        _create: function() {
            var options = this.options;

            this._setupElement();

            this.$headers = this.element.find( options.header );

            this._setupTabs( this.$headers );

            // HELPERS {
            $.fn.maccordionToggleAttributes = function( attributes ) {
                attributes = $.trim( attributes ).split( " " );
                this.each( function( index, el ) {
                    $.each( attributes, function( index, attr ) {
                        $( el ).attr( attr, $( el ).attr( attr ) != "true" );
                    } );
                } );
            };
            // }

            this._activate( options.active );

            this._setZeroTabindex( this.$headers.eq( 0 ) );

            this._heightStyle();
        },

        destroy: function() {
            // clean up main element
            this.element
                .removeClass( "dattaya-maccordion ui-widget ui-helper-reset" )
                .removeAttr( "aria-multiselectable role" );

            // clean up headers
            this.$headers
                .off( ".maccordion" )
                .removeClass( "dattaya-maccordion-header ui-helper-reset ui-state-default " +
                "ui-corner-all ui-state-active ui-corner-top dattaya-maccordion-header-active " +
                "ui-maccordion-disabled ui-state-disabled ui-state-focus ui-state-hover" )
                .removeAttr( "role tabindex aria-selected aria-expanded" );

            this._destroyIcons( this.$headers );

            // clean up content
            this.$headers.next()
                .css( "display", "" )
                .removeClass( "dattaya-maccordion-content ui-helper-reset ui-widget-content " +
                "ui-corner-bottom dattaya-maccordion-content-active " +
                "ui-maccordion-disabled ui-state-disabled" )
                .removeAttr( "role" );

            console.debug( "destroy" );

            return $.Widget.prototype.destroy.call( this );
        },

        /**
         *
         * @param {Number[]|String|Boolean|jQuery} active
         */
        _activate: function( active ) {

            console.debug( "_activate" );

            this._toggle( this._transformActiveToElement( active ) );
        },

        _keydown: function( event ) {

            if ( this.options.disabled || event.altKey || event.ctrlKey ) {
                return;
            }
<commit_msg>new methods _cleanupHeaders, _cleanupContents, _cleanupElement, _setupHelpers - result of extracting code.<commit_after>/**
 * Work in progress
 * v. 0.0.-1
 */

(function( $, undefined ) {
    $.widget( "dattaya.maccordion", {
        options: {
            active     : 0,
            header     : "> li > :first-child,> :not(li):even",
            event      : "click",
            easing     : "swing",
            speed      : "normal",
            disabled   : false,
            heightStyle: false,
            animated   : true,
            icons: {
                activeHeader: "ui-icon-triangle-1-s",
                header      : "ui-icon-triangle-1-e"
            }
        },

        /**
         *
         * @param {jQuery} $headers
         */
        _toggle: function( $headers ) {

            var options = this.options;

            if ( $headers.length == 0 )
                return;

            console.debug( "_toggle" );

            $headers
                .toggleClass( "ui-state-active ui-corner-all ui-corner-top dattaya-maccordion-header-active" )
                .find( ".dattaya-maccordion-header-icon" )
                    .toggleClass( options.icons.header + " " + options.icons.activeHeader );

            // ARIA
            $headers.maccordionToggleAttributes( "aria-selected aria-expanded" );

            if ( options.animated ) {
                $headers.next()
                    .slideToggle( this.options.speed, this.options.easing );
            } else {
                $headers.next().toggle();
            }

            $headers.next().toggleClass( "dattaya-maccordion-content-active" );
        },

        /**
         *
         * @param {Object} event
         */
        _eventHandler: function( event ) {
            var options = this.options;

            if ( options.disabled ) {
                return;
            }

            console.debug( event.type === "keypress" ? "click" : event.type );

            this._toggle( $( event.currentTarget ) );

            event.preventDefault();
        },

        _create: function() {
            var options = this.options;

            this._setupElement();

            this.$headers = this.element.find( options.header );

            this._setupTabs( this.$headers );

            this._setupHelpers();

            this._activate( options.active );

            this._setZeroTabindex( this.$headers.eq( 0 ) );

            this._heightStyle();
        },

        _setupHelpers: function() {
            if ( !$.fn.maccordionToggleAttributes ) {
                $.fn.maccordionToggleAttributes = function( attributes ) {
                    attributes = $.trim( attributes ).split( " " );
                    this.each( function( index, el ) {
                        $.each( attributes, function( index, attr ) {
                            $( el ).attr( attr, $( el ).attr( attr ) != "true" );
                        } );
                    } );
                };
            }
        },

        destroy: function() {

            this._cleanupElement();

            this._cleanupHeaders();

            this._destroyIcons( this.$headers );

            this._cleanupContents();

            return $.Widget.prototype.destroy.call( this );
        },

        _cleanupHeaders: function() {
            this.$headers
                .off( ".maccordion" )
                .removeClass( "dattaya-maccordion-header ui-helper-reset ui-state-default " +
                "ui-corner-all ui-state-active ui-corner-top dattaya-maccordion-header-active " +
                "ui-maccordion-disabled ui-state-disabled ui-state-focus ui-state-hover" )
                .removeAttr( "role tabindex aria-selected aria-expanded" );
        },

        _cleanupContents: function() {
            this.$headers.next()
                .css( "display", "" )
                .removeClass( "dattaya-maccordion-content ui-helper-reset ui-widget-content " +
                "ui-corner-bottom dattaya-maccordion-content-active " +
                "ui-maccordion-disabled ui-state-disabled" )
                .removeAttr( "role" );
        },

        _cleanupElement: function() {
            this.element
                .removeClass( "dattaya-maccordion ui-widget ui-helper-reset" )
                .removeAttr( "aria-multiselectable role" );
        },

        /**
         *
         * @param {Number[]|String|Boolean|jQuery} active
         */
        _activate: function( active ) {

            console.debug( "_activate" );

            this._toggle( this._transformActiveToElement( active ) );
        },

        _keydown: function( event ) {

            if ( this.options.disabled || event.altKey || event.ctrlKey ) {
                return;
            }

{'fraction_non_alphanumeric': 0.12644304073186668, 'fraction_numerical': 0.0017425397516880855, 'mean_word_length': 1.3408106041294927, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4412562', 'n_tokens_mistral': 2531, 'n_tokens_neox': 2361, 'n_words': 438}