Ticket #21562: 21562.2.diff

File 21562.2.diff, 4.0 KB (added by obenland, 9 months ago)
  • wp-content/themes/twentytwelve/style.css

     
    514514} 
    515515 
    516516/* Navigation Menu */ 
    517 .main-navigation { 
     517.main-navigation .menu { 
    518518        display: inline-block; 
    519519        margin-top: 24px; 
    520520        margin-top: 1.714285714rem; 
  • wp-content/themes/twentytwelve/functions.php

     
    164164add_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 ); 
    165165 
    166166/** 
     167 * Prevents menu markup to be shown, when there are no menu items. 
     168 * 
     169 * @since Twenty Twelve 1.0 
     170 *  
     171 * @param string $nav_menu Menu markup 
     172 * @return string Menu markup or empty string 
     173 */ 
     174function twentytwelve_prevent_empty_menu( $nav_menu ) { 
     175         
     176        // If there are no list items present 
     177        if ( ! stristr( $nav_menu, '<li') ) 
     178                $nav_menu = ''; 
     179 
     180        return $nav_menu; 
     181} 
     182add_filter( 'wp_nav_menu', 'twentytwelve_prevent_empty_menu' ); 
     183 
     184/** 
    167185 * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link. 
    168186 * 
    169187 * @since Twenty Twelve 1.0 
  • wp-content/themes/twentytwelve/js/theme.js

     
    55 */ 
    66 
    77jQuery( document ).ready( function( $ ) { 
     8         
    89        var masthead = $( '#masthead' ), 
    9                 largeWindow = window.matchMedia( 'screen and (min-width: 600px)' ), 
     10                smallWindow = window.matchMedia( 'screen and (max-width: 599px)' ), 
    1011                timeout = false; 
    11  
    12         $.fn.smallMenu = function() { 
    13                 masthead.find( '.site-navigation' ).removeClass( 'main-navigation' ).addClass( 'main-small-navigation' ); 
    14                 masthead.find( '.site-navigation h3' ).removeClass( 'assistive-text' ).addClass( 'menu-toggle' ); 
    15  
    16                 $( '.menu-toggle' ).off( 'click' ).click( function() { 
    17                         masthead.find( '.menu' ).slideToggle(); 
    18                         $( this ).toggleClass( 'toggled-on' ); 
     12         
     13        // Check for menu items. 
     14        if ( '0' != masthead.find( '.menu' ).children().length ) { 
     15                 
     16                $.fn.smallMenu = function() { 
     17                        masthead.find( '.site-navigation' ).removeClass( 'main-navigation' ).addClass( 'main-small-navigation' ); 
     18                        masthead.find( '.site-navigation h3' ).removeClass( 'assistive-text' ).addClass( 'menu-toggle' ); 
     19         
     20                        $( '.menu-toggle' ).off( 'click' ).click( function() { 
     21                                masthead.find( '.menu' ).slideToggle(); 
     22                                $( this ).toggleClass( 'toggled-on' ); 
     23                        } ); 
     24                }; 
     25                 
     26                // Check viewport width on first load. 
     27                if ( smallWindow.matches ) 
     28                        $.fn.smallMenu(); 
     29         
     30                // Check viewport width when user resizes the browser window. 
     31                $( window ).resize( function() { 
     32                        if ( false !== timeout ) 
     33                                clearTimeout( timeout ); 
     34         
     35                        timeout = setTimeout( function() { 
     36                                if ( smallWindow.matches ) { 
     37                                        $.fn.smallMenu(); 
     38                                } else { 
     39                                        masthead.find( '.site-navigation' ).removeClass( 'main-small-navigation' ).addClass( 'main-navigation' ); 
     40                                        masthead.find( '.site-navigation h3' ).removeClass( 'menu-toggle' ).addClass( 'assistive-text' ); 
     41                                        masthead.find( '.menu' ).removeAttr( 'style' ); 
     42                                } 
     43                        }, 200 ); 
    1944                } ); 
    20         }; 
    21  
    22         // Check viewport width on first load. 
    23         if ( ! largeWindow.matches ) 
    24                 $.fn.smallMenu(); 
    25  
    26         // Check viewport width when user resizes the browser window. 
    27         $( window ).resize( function() { 
    28                 if ( false !== timeout ) 
    29                         clearTimeout( timeout ); 
    30  
    31                 timeout = setTimeout( function() { 
    32                         if ( ! largeWindow.matches ) { 
    33                                 $.fn.smallMenu(); 
    34                         } else { 
    35                                 masthead.find( '.site-navigation' ).removeClass( 'main-small-navigation' ).addClass( 'main-navigation' ); 
    36                                 masthead.find( '.site-navigation h3' ).removeClass( 'menu-toggle' ).addClass( 'assistive-text' ); 
    37                                 masthead.find( '.menu' ).removeAttr( 'style' ); 
    38                         } 
    39                 }, 200 ); 
    40         } ); 
     45        } 
    4146} ); 
     47 No newline at end of file