IE 11上的Dropdown Toggle Button消失

时间:2018-01-18 23:10:54

标签: javascript jquery wordpress toggle dropdown

我在WordPress中创建了一个自定义网站。 http://www.seattlestormbasketball.com/stormcares/

除IE 11外,一切都运行良好。导航菜单上的下拉切换显示在主页上,但不显示在任何内页上。

JS

(function( $ ) {
var masthead, menuToggle, siteNavContain, siteNavigation;

function initMainNavigation( container ) {

    // Add dropdown toggle that displays child menu items.
    var dropdownToggle = $( '<button />', { 'class': 'dropdown-toggle', 'aria-expanded': false })
        .append( $( '<i />', { 'class': 'dropdown-symbol fa fa-plus-circle' }) )
        .append( $( '<span />', { 'class': 'screen-reader-text', text: ezmacScreenReaderText.expand }) );

    container.find( '.menu-item-has-children > a, .page_item_has_children > a' ).after( dropdownToggle );

    container.find( '.dropdown-toggle' ).click( function( e ) {
        var _this = $( this ),
            screenReaderSpan = _this.find( '.screen-reader-text' );

        e.preventDefault();
        _this.toggleClass( 'toggled-on' );
        _this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' );

        _this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' );

        screenReaderSpan.text( screenReaderSpan.text() === ezmacScreenReaderText.expand ? ezmacScreenReaderText.collapse : ezmacScreenReaderText.expand );
    });
}

initMainNavigation( $( '.main-navigation' ) );

masthead       = $( '#masthead' );
menuToggle     = masthead.find( '.menu-toggle' );
siteNavContain = masthead.find( '.main-navigation' );
siteNavigation = masthead.find( '.main-navigation > div > ul' );

// Enable menuToggle.
(function() {

    // Return early if menuToggle is missing.
    if ( ! menuToggle.length ) {
        return;
    }

    // Add an initial value for the attribute.
    menuToggle.attr( 'aria-expanded', 'false' );

    menuToggle.on( 'click.ezmac', function() {
        siteNavContain.toggleClass( 'toggled-on' );

        $( this ).attr( 'aria-expanded', siteNavContain.hasClass( 'toggled-on' ) );
    });
})();

// Fix sub-menus for touch devices and better focus for hidden submenu items for accessibility.
(function() {
    if ( ! siteNavigation.length || ! siteNavigation.children().length ) {
        return;
    }

    // Toggle `focus` class to allow submenu access on tablets.
    function toggleFocusClassTouchScreen() {
        if ( 'none' === $( '.menu-toggle' ).css( 'display' ) ) {

            $( document.body ).on( 'touchstart.ezmac', function( e ) {
                if ( ! $( e.target ).closest( '.main-navigation li' ).length ) {
                    $( '.main-navigation li' ).removeClass( 'focus' );
                }
            });

            siteNavigation.find( '.menu-item-has-children > a, .page_item_has_children > a' )
                .on( 'touchstart.ezmac', function( e ) {
                    var el = $( this ).parent( 'li' );

                    if ( ! el.hasClass( 'focus' ) ) {
                        e.preventDefault();
                        el.toggleClass( 'focus' );
                        el.siblings( '.focus' ).removeClass( 'focus' );
                    }
                });

        } else {
            siteNavigation.find( '.menu-item-has-children > a, .page_item_has_children > a' ).unbind( 'touchstart.ezmac' );
        }
    }

    if ( 'ontouchstart' in window ) {
        $( window ).on( 'resize.ezmac', toggleFocusClassTouchScreen );
        toggleFocusClassTouchScreen();
    }

    siteNavigation.find( 'a' ).on( 'focus.ezmac blur.ezmac', function() {
        $( this ).parents( '.menu-item, .page_item' ).toggleClass( 'focus' );
    });
})();

//Change Font-Awesome dropdown symbols on toggle
$(".dropdown-symbol").click(function(e) {

    if( $(this).hasClass("fa-plus-circle") ) {
        $(this).removeClass("fa-plus-circle").addClass("fa-minus-circle");
    } else {
        // if other menus are open remove open class and add closed
        $(this).siblings().removeClass("fa-plus-circle").addClass("fa-minus-circle"); 
        $(this).removeClass("fa-minus-circle").addClass("fa-plus-circle");
    }

});


})( jQuery );

就像我之前提到的,在所有其他浏览器甚至旧版本的IE中都很有用,但不是IE 11

非常感谢任何帮助。谢谢!

0 个答案:

没有答案