Making WordPress.org

Ticket #358: wordcamp-base.patch

File wordcamp-base.patch, 4.3 KB (added by r3df, 11 years ago)
  • header.php

     
    2222        if ( is_singular() && get_option( 'thread_comments' ) )
    2323                wp_enqueue_script( 'comment-reply' );
    2424
     25        // Adds JavaScript for handling the navigation menu hide-and-show behavior to allow responsive menus.
     26        wp_enqueue_script( 'wordcamp-base-navigation', get_template_directory_uri() . '/lib/navigation/navigation.js', array(), '1.0', true );
     27
     28
    2529        /* Always have wp_head() just before the closing </head>
    2630         * tag of your theme, or you will break many plugins, which
    2731         * generally use this hook to add elements to <head> such
  • lib/navigation/navigation.js

     
     1/**
     2 * navigation.js
     3 *
     4 * Handles toggling the navigation menu for small screens.
     5 */
     6( function() {
     7        var nav = document.getElementById( 'access' ), button, menu;
     8        if ( ! nav )
     9                return;
     10        button = nav.getElementsByTagName( 'h3' )[0];
     11        menu   = nav.getElementsByTagName( 'ul' )[0];
     12        if ( ! button )
     13                return;
     14
     15        // Hide button if menu is missing or empty.
     16        if ( ! menu || ! menu.childNodes.length ) {
     17                button.style.display = 'none';
     18                return;
     19        }
     20
     21        button.onclick = function() {
     22                if ( -1 == menu.className.indexOf( 'menu' ) )
     23                        menu.className = 'menu';
     24
     25                if ( -1 != button.className.indexOf( 'toggled-on' ) ) {
     26                        button.className = button.className.replace( ' toggled-on', '' );
     27                        menu.className = menu.className.replace( ' toggled-on', '' );
     28                } else {
     29                        button.className += ' toggled-on';
     30                        menu.className += ' toggled-on';
     31                }
     32        };
     33} )();
     34 No newline at end of file
  • lib/navigation/navigation.js

     
     1/**
     2 * navigation.js
     3 *
     4 * Handles toggling the navigation menu for small screens.
     5 */
     6( function() {
     7        var nav = document.getElementById( 'access' ), button, menu;
     8        if ( ! nav )
     9                return;
     10        button = nav.getElementsByTagName( 'h3' )[0];
     11        menu   = nav.getElementsByTagName( 'ul' )[0];
     12        if ( ! button )
     13                return;
     14
     15        // Hide button if menu is missing or empty.
     16        if ( ! menu || ! menu.childNodes.length ) {
     17                button.style.display = 'none';
     18                return;
     19        }
     20
     21        button.onclick = function() {
     22                if ( -1 == menu.className.indexOf( 'menu' ) )
     23                        menu.className = 'menu';
     24
     25                if ( -1 != button.className.indexOf( 'toggled-on' ) ) {
     26                        button.className = button.className.replace( ' toggled-on', '' );
     27                        menu.className = menu.className.replace( ' toggled-on', '' );
     28                } else {
     29                        button.className += ' toggled-on';
     30                        menu.className += ' toggled-on';
     31                }
     32        };
     33} )();
     34 No newline at end of file
  • lib/structure/class-wcb-menu.php

     
    88        function content() { ?>
    99                <div id="<?php echo $this->get_id(); ?>" class="grid_12">
    1010                        <div id="access" role="navigation" class="clearfix">
     11                                <?php /* Menu toggle element for responsive menus - hidden by default CSS */ ?>
     12                                <h3 class="menu-toggle"><?php _e( 'Menu', 'wordcampbase' ); ?></h3>
    1113                                <?php /*  Allow screen readers / text browsers to skip the navigation menu and get right to the good stuff */ ?>
    1214                                <div class="skip-link screen-reader-text"><a href="#content" title="<?php esc_attr_e( 'Skip to content', 'wordcampbase' ); ?>"><?php _e( 'Skip to content', 'wordcampbase' ); ?></a></div>
    1315                                <?php /* Our navigation menu.  If one isn't filled out, wp_nav_menu falls back to wp_page_menu.  The menu assiged to the primary position is the one used.  If none is assigned, the menu with the lowest ID is used.  */ ?>
  • style.css

     
    375375        margin: 0 auto;
    376376        width: 940px;
    377377}
     378/* Hide the responsive menu toggle - maintain backwards compatibility */
     379#access .menu-toggle {
     380        display: none;
     381}
    378382#access .menu-header,
    379383div.menu {
    380384        font-size: 13px;