Created
June 29, 2012 03:38
-
-
Save jaredatch/3015507 to your computer and use it in GitHub Desktop.
Mobile Genesis menus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($){ | |
// Mobile navigation | |
$('#prim-selector, #sec-selector').change(function(){ | |
if ($(this).val()!='') { | |
window.location.href=$(this).val(); | |
} | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Mobile primary navigation | |
* | |
* @since 1.0 | |
*/ | |
function ja_mobile_menu_primary(){ | |
if ( has_nav_menu( 'primary') && genesis_get_option( 'nav' ) ){ | |
wp_nav_menu( array( | |
'theme_location' => 'primary', | |
'walker' => new Walker_Nav_Menu_Mobile(), | |
'items_wrap' => '<select class="default" id="prim-selector" name="prim-selector">%3$s</select>', | |
'container_id' => 'mobile-menu-primary' | |
)); | |
} | |
} | |
add_action( 'genesis_before_header','ja_mobile_menu_primary' ); | |
/** | |
* Mobile secondary navigation | |
* | |
* @since 1.0 | |
*/ | |
function ja_mobile_menu_secondary(){ | |
if ( has_nav_menu( 'secondary') && genesis_get_option( 'subnav' )){ | |
wp_nav_menu( array( | |
'theme_location' => 'secondary', | |
'walker' => new Walker_Nav_Menu_Mobile(), | |
'items_wrap' => '<select class="default" id="sec-selector" name="sec-selector">%3$s</select>', | |
'container_id' => 'mobile-menu-secondary' | |
)); | |
} | |
} | |
add_action( 'genesis_after_header','ja_mobile_menu_secondary' ); | |
/** | |
* Mobile menu walker class | |
* | |
* @since 1.0 | |
*/ | |
class Walker_Nav_Menu_Mobile extends Walker_Nav_Menu{ | |
var $to_depth = -1; | |
function start_lvl( &$output, $depth ){ | |
$output .= '</option>'; | |
} | |
function end_lvl( &$output, $depth ){ | |
$indent = str_repeat( "\t", $depth ); | |
} | |
function start_el( &$output, $item, $depth, $args ){ | |
$indent = ( $depth ) ? str_repeat( " ", $depth * 4 ) : ''; | |
$class_names = $value = ''; | |
$classes = empty( $item->classes ) ? array() : ( array ) $item->classes; | |
$classes[] = 'menu-item-' . $item->ID; | |
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) ); | |
$class_names = ' class="' . esc_attr( $class_names ) . '"'; | |
$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args ); | |
$id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : ''; | |
$value = ' value="'. $item->url .'"'; | |
$output .= '<option' . $id. $value . $class_names . '>'; | |
$item_output = $args->before; | |
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after; | |
$output .= $indent . $item_output; | |
} | |
function end_el( &$output, $item, $depth ){ | |
if( substr($output, -9 ) != '</option>') | |
$output .= "</option>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment