Make WordPress Core

Changeset 32807


Ignore:
Timestamp:
06/16/2015 10:17:39 PM (11 years ago)
Author:
ocean90
Message:

Twenty Fifteen: Wrap navigation helpers into a function so it can be called on a refresh event of the Customize Preview.

props westonruter.
see #32576.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyfifteen/js/functions.js

    r31934 r32807  
    1010            bottom = false, windowWidth, windowHeight, lastWindowPos = 0,
    1111            topOffset = 0, bodyHeight, sidebarHeight, resizeTimer,
    12                 secondary, button;
     12            secondary, button;
    1313
    14         // Add dropdown toggle that display child menu items.
    15         $( '.main-navigation .menu-item-has-children > a' ).after( '<button class="dropdown-toggle" aria-expanded="false">' + screenReaderText.expand + '</button>' );
    1614
    17         // Toggle buttons and submenu items with active children menu items.
    18         $( '.main-navigation .current-menu-ancestor > button' ).addClass( 'toggle-on' );
    19         $( '.main-navigation .current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' );
     15        function initMainNavigation() {
     16                // Add dropdown toggle that display child menu items.
     17                $( '.main-navigation .menu-item-has-children > a' ).after( '<button class="dropdown-toggle" aria-expanded="false">' + screenReaderText.expand + '</button>' );
    2018
    21         $( '.dropdown-toggle' ).click( function( e ) {
    22                 var _this = $( this );
    23                 e.preventDefault();
    24                 _this.toggleClass( 'toggle-on' );
    25                 _this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' );
    26                 _this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' );
    27                 _this.html( _this.html() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand );
    28         } );
     19                // Toggle buttons and submenu items with active children menu items.
     20                $( '.main-navigation .current-menu-ancestor > button' ).addClass( 'toggle-on' );
     21                $( '.main-navigation .current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' );
     22
     23                $( '.dropdown-toggle' ).click( function( e ) {
     24                        var _this = $( this );
     25                        e.preventDefault();
     26                        _this.toggleClass( 'toggle-on' );
     27                        _this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' );
     28                        _this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' );
     29                        _this.html( _this.html() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand );
     30                } );
     31        }
     32        initMainNavigation();
     33        $( document ).on( 'customize-preview-menu-refreshed', initMainNavigation );
    2934
    3035        secondary = $( '#secondary' );
Note: See TracChangeset for help on using the changeset viewer.