From d0a813097044d3933012fe2d001ecdb4b32e1b1a Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Tue, 16 Jun 2015 22:17:39 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@32807 602fd350-edb4-49c9-b593-d223f7449a82 --- .../themes/twentyfifteen/js/functions.js | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/wp-content/themes/twentyfifteen/js/functions.js b/src/wp-content/themes/twentyfifteen/js/functions.js index eeeecd2246..64a696860d 100644 --- a/src/wp-content/themes/twentyfifteen/js/functions.js +++ b/src/wp-content/themes/twentyfifteen/js/functions.js @@ -9,23 +9,28 @@ var $body, $window, $sidebar, adminbarOffset, top = false, bottom = false, windowWidth, windowHeight, lastWindowPos = 0, topOffset = 0, bodyHeight, sidebarHeight, resizeTimer, - secondary, button; + secondary, button; - // Add dropdown toggle that display child menu items. - $( '.main-navigation .menu-item-has-children > a' ).after( '' ); - // Toggle buttons and submenu items with active children menu items. - $( '.main-navigation .current-menu-ancestor > button' ).addClass( 'toggle-on' ); - $( '.main-navigation .current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' ); + function initMainNavigation() { + // Add dropdown toggle that display child menu items. + $( '.main-navigation .menu-item-has-children > a' ).after( '' ); - $( '.dropdown-toggle' ).click( function( e ) { - var _this = $( this ); - e.preventDefault(); - _this.toggleClass( 'toggle-on' ); - _this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' ); - _this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' ); - _this.html( _this.html() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand ); - } ); + // Toggle buttons and submenu items with active children menu items. + $( '.main-navigation .current-menu-ancestor > button' ).addClass( 'toggle-on' ); + $( '.main-navigation .current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' ); + + $( '.dropdown-toggle' ).click( function( e ) { + var _this = $( this ); + e.preventDefault(); + _this.toggleClass( 'toggle-on' ); + _this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' ); + _this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' ); + _this.html( _this.html() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand ); + } ); + } + initMainNavigation(); + $( document ).on( 'customize-preview-menu-refreshed', initMainNavigation ); secondary = $( '#secondary' ); button = $( '.site-branding' ).find( '.secondary-toggle' );