<commit_before>/**
 * Mobile dropdowns
 * Toggles dropdowns using css class 'open' instead of pseudo class :hover
 * Usage:
 * <li class="dropdown">
 *     <a data-plenty-enable="CONDITION">...</a>
 * </li>
 *
 * possible values for CONDITION
 * "touch"                        : use 'open'-class if device is touch-device AND media size is 'md' or 'lg'
 * "toggle-xs-sm-or-touch" : use 'open'-class if device is "touch" (as above) OR media size is 'xs' or 'sm'
 *
 */
(function( $, pm )
{
    pm.directive( 'MobileDropdown', function( MediaSize )
    {
        // store all dropdown elements
        var dropdownElements = [];

        // store dropdown elements which should be closed by clicking outside the element itself
        var closableDropdownElements = [];

        return {
            initDropdowns: initDropdowns,
            openDropdown : openDropdown,
            slideDropdown: slideDropdown
        };

        function initDropdowns()
        {
            $( window ).on( 'orientationchange sizeChange', function()
            {
                resetDropdowns( dropdownElements );
                resetDropdowns( closableDropdownElements );
            } );

            // handle "close menu on click outside"
            $( 'html' ).on( "click touchstart", function( event )
            {
                resetDropdowns( closableDropdownElements, event );
            } );
        }

        function resetDropdowns( dropdownList, event )
        {
            var $current;
            for ( var i = 0; i < dropdownList.length; i++ )
            {
                $current = $( dropdownList[i] );
                if ( !!event )
                {
                    if ( $current.find( $( event.target ) ).length === 0 )
                    {
                        $current.removeClass( 'open' );
                    }
                }
                else
                {
                    $current.removeClass( 'open' );
                }
            }

        }

        function openDropdown( elem, alwaysClickable )
        {
            var $elem   = $( elem );
            var $parent = $elem.parent();

            // case 1: xs || sm || ( touch && ( md || lg ) ) -> open/close via click on small devices, open/close via
            // css-hover on desktop, open/close via click on touch-desktop (e.g. top navigation)

            if ( !!alwaysClickable && ( MediaSize.isInterval( 'xs, sm' ) || ( Modernizr.touch && MediaSize.isInterval( 'md, lg' ) ) ) )
            {
                if ( !$parent.is( '.open' ) )
                {
                    showDropdownHideOthers( $elem, $parent );

                    // if href
                    if ( !$elem.attr( 'href' ) )
                    {
                        avoidRedirectinStopPropagation( $parent.not( $elem ) );
                    }
                }
                else
                {
                    if ( !$elem.attr( 'href' ) )
                    {
                        // hide dropdown
                        $parent.removeClass( 'open' );
                    }
                }
            }

            // case 2: touch && ( md || lg ) -> open via 1st click on touch-desktop, return false (e.g. main navigation)

            if ( !alwaysClickable && ( Modernizr.touch && MediaSize.isInterval( 'md, lg' ) ) )
            {
                if ( !$parent.is( '.open' ) )
                {
                    showDropdownHideOthers( $elem, $parent );

                    avoidRedirectinStopPropagation( $parent );
                }
                else
                {
                    // redirect to href if dropdown is already open
                    // do nothing
                }
            }
        }

        function showDropdownHideOthers( elem, parent )
        {
            var $parent = $( parent );

            // hide other dropdowns
            resetDropdowns( closableDropdownElements, elem );

            // remember opened dropdown<commit_msg>Revert "ADD second parameter elem to prevent login dropdown from closing on input focus"<commit_after>/**
 * Mobile dropdowns
 * Toggles dropdowns using css class 'open' instead of pseudo class :hover
 * Usage:
 * <li class="dropdown">
 *     <a data-plenty-enable="CONDITION">...</a>
 * </li>
 *
 * possible values for CONDITION
 * "touch"                        : use 'open'-class if device is touch-device AND media size is 'md' or 'lg'
 * "toggle-xs-sm-or-touch" : use 'open'-class if device is "touch" (as above) OR media size is 'xs' or 'sm'
 *
 */
(function( $, pm )
{
    pm.directive( 'MobileDropdown', function( MediaSize )
    {
        // store all dropdown elements
        var dropdownElements = [];

        // store dropdown elements which should be closed by clicking outside the element itself
        var closableDropdownElements = [];

        return {
            initDropdowns: initDropdowns,
            openDropdown : openDropdown,
            slideDropdown: slideDropdown
        };

        function initDropdowns()
        {
            $( window ).on( 'orientationchange sizeChange', function()
            {
                resetDropdowns( dropdownElements );
                resetDropdowns( closableDropdownElements );
            } );

            // handle "close menu on click outside"
            $( 'html' ).on( "click touchstart", function( event )
            {
                resetDropdowns( closableDropdownElements, event );
            } );
        }

        function resetDropdowns( dropdownList, event )
        {
            var $current;
            for ( var i = 0; i < dropdownList.length; i++ )
            {
                $current = $( dropdownList[i] );
                if ( !!event )
                {
                    if ( $current.find( $( event.target ) ).length === 0 )
                    {
                        $current.removeClass( 'open' );
                    }
                }
                else
                {
                    $current.removeClass( 'open' );
                }
            }

        }

        function openDropdown( elem, alwaysClickable )
        {
            var $elem   = $( elem );
            var $parent = $elem.parent();

            // case 1: xs || sm || ( touch && ( md || lg ) ) -> open/close via click on small devices, open/close via
            // css-hover on desktop, open/close via click on touch-desktop (e.g. top navigation)

            if ( !!alwaysClickable && ( MediaSize.isInterval( 'xs, sm' ) || ( Modernizr.touch && MediaSize.isInterval( 'md, lg' ) ) ) )
            {
                if ( !$parent.is( '.open' ) )
                {
                    showDropdownHideOthers( $elem, $parent );

                    // if href
                    if ( !$elem.attr( 'href' ) )
                    {
                        avoidRedirectinStopPropagation( $parent.not( $elem ) );
                    }
                }
                else
                {
                    if ( !$elem.attr( 'href' ) )
                    {
                        // hide dropdown
                        $parent.removeClass( 'open' );
                    }
                }
            }

            // case 2: touch && ( md || lg ) -> open via 1st click on touch-desktop, return false (e.g. main navigation)

            if ( !alwaysClickable && ( Modernizr.touch && MediaSize.isInterval( 'md, lg' ) ) )
            {
                if ( !$parent.is( '.open' ) )
                {
                    showDropdownHideOthers( $elem, $parent );

                    avoidRedirectinStopPropagation( $parent );
                }
                else
                {
                    // redirect to href if dropdown is already open
                    // do nothing
                }
            }
        }

        function showDropdownHideOthers( elem, parent )
        {
            var $parent = $( parent );

            // hide other dropdowns
            resetDropdowns( closableDropdownElements );

            // remember opened dropdown
{'fraction_non_alphanumeric': 0.10874147551146932, 'fraction_numerical': 0.0012399256044637321, 'mean_word_length': 1.2153254600384509, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '2954608', 'n_tokens_mistral': 2133, 'n_tokens_neox': 1969, 'n_words': 541}