From d97665d3315d857415c163facc1a489712f6affb Mon Sep 17 00:00:00 2001 From: Ian Stewart Date: Thu, 13 Nov 2014 03:08:21 +0000 Subject: [PATCH] Twenty Fifteen: unfix the sidebar if we have a menu with submenus as there is a chance visitors might not be able to scroll down to see submenus in some situations. Props mattwiebe, fixes #30208. git-svn-id: https://develop.svn.wordpress.org/trunk@30324 602fd350-edb4-49c9-b593-d223f7449a82 --- .../themes/twentyfifteen/js/functions.js | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/wp-content/themes/twentyfifteen/js/functions.js b/src/wp-content/themes/twentyfifteen/js/functions.js index 8de0bd80f6..0074793456 100644 --- a/src/wp-content/themes/twentyfifteen/js/functions.js +++ b/src/wp-content/themes/twentyfifteen/js/functions.js @@ -50,11 +50,6 @@ // Sidebar (un)fixing: fix when short, un-fix when scroll needed - $body = $( 'body' ); - $window = $( window ); - sidebar = $( '#sidebar' )[0]; - toolbarOffset = $body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0; - function fixedOrScrolledSidebar() { if ( $window.width() >= 955 ) { if ( sidebar.scrollHeight < ( $window.height() - toolbarOffset ) ) { @@ -78,6 +73,22 @@ }; } - $window.on( 'load.twentyfifteen', fixedOrScrolledSidebar ).on( 'resize.twentyfifteen', debouncedFixedOrScrolledSidebar() ); + + $( document ).ready( function() { + // But! We only want to allow fixed sidebars when there are no submenus. + if ( $( '#site-navigation .sub-menu' ).length ) { + return; + } + + // only initialize 'em if we need 'em + $body = $( 'body' ); + $window = $( window ); + sidebar = $( '#sidebar' )[0]; + toolbarOffset = $body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0; + + $window + .on( 'load.twentyfifteen', fixedOrScrolledSidebar ) + .on( 'resize.twentyfifteen', debouncedFixedOrScrolledSidebar() ); + } ); } )( jQuery ); \ No newline at end of file