Skip to content

Instantly share code, notes, and snippets.

@srikat srikat/responsive-menu.js Secret
Last active Aug 29, 2015

Embed
What would you like to do?
//* Reposition the primary navigation menu
remove_action( 'genesis_after_header', 'genesis_do_nav' );
add_action( 'genesis_after_header', 'genesis_do_nav', 15 );
// Remove the header right widget area
unregister_sidebar( 'header-right' );
// Reposition the primary navigation menu
remove_action( 'genesis_after_header', 'genesis_do_nav' );
// add_action( 'genesis_after_header', 'genesis_do_nav', 15 );
add_action( 'genesis_header', 'genesis_do_nav' );
add_filter( 'wp_nav_menu_items', 'theme_menu_extras', 10, 2 );
/**
* Filter menu items to append a search form.
*
* @param string $menu HTML string of list items.
* @param stdClass $args Menu arguments.
*
* @return string Amended HTML string of list items.
*/
function theme_menu_extras( $menu, $args ) {
if ( 'primary' !== $args->theme_location )
return $menu;
$menu .= '<li class="search"><a id="main-nav-search-link" class="icon-search"></a><div class="search-div">' . get_search_form( false ) . '</div></li>';
return $menu;
}
// Customize search form input button text
add_filter( 'genesis_search_button_text', 'sp_search_button_text' );
function sp_search_button_text( $text ) {
return esc_attr( 'Go' );
}
jQuery(function( $ ){
$("header .genesis-nav-menu").addClass("responsive-menu").before('<div id="responsive-menu-icon"></div>');
$("#responsive-menu-icon").click(function(){
$("header .genesis-nav-menu").slideToggle();
});
$(window).resize(function(){
if(window.innerWidth > 768) {
$("header .genesis-nav-menu").removeAttr("style");
}
});
$('#main-nav-search-link').click(function(){
$('.search-div').show('slow');
});
$("*", document.body).click(function(event){
// event.stopPropagation();
var el = $(event.target);
var gsfrm = $(el).closest('form');
if(el.attr('id') !='main-nav-search-link' && el.attr('role') != 'search' && gsfrm.attr('role') != 'search'){
$('.search-div').hide('slow');
}
});
});
/*
Animated Search Form
---------------------------------------------------------------------------------------------------- */
.nav-primary {
background: transparent;
float: right;
}
.nav-primary a,
.nav-primary .genesis-nav-menu .sub-menu a {
color: #333;
}
.nav-primary .genesis-nav-menu .sub-menu a {
background-color: #fff;
border: 1px solid #eee;
border-top: none;
}
.nav-primary .genesis-nav-menu .sub-menu a:hover {
color: #0ebfe9;
}
.nav-primary .genesis-nav-menu > .search {
display: inline-block;
position: relative;
width: auto;
padding: 0;
}
li a.icon-search:before {
font-family: FontAwesome;
font-weight: normal;
font-style: normal;
text-decoration: inherit;
content: "\f002";
}
li a.icon-search {
cursor: pointer;
}
.search-div {
display: none;
position: absolute;
z-index: 10;
right: 0;
width: 300px;
padding: 10px;
-webkit-border-radius: 0 0 6px 6px;
border-radius: 0 0 6px 6px;
background: #f2efef;
}
.search-div .search-form {
position: relative;
margin-top: 0;
}
.search-div .search-form input[type="search"] {
width: 100%;
padding: 10px;
font-size: 16px;
}
.search-div .search-form input[type="submit"] {
right: 3px;
padding: 12px 14px;
clip: auto;
width: auto;
height: auto;
margin: 0;
}
/* Clear search field placeholder text on focus */
input:focus::-webkit-input-placeholder {
color: transparent;
}
input:focus:-moz-placeholder {
color: transparent;
} /* Firefox 18- */
input:focus::-moz-placeholder {
color: transparent;
} /* Firefox 19+ */
input:focus:-ms-input-placeholder {
color: transparent;
} /* oldIE ;) */
@media only screen and (max-width: 1023px) {
.title-area,
.nav-primary {
float: none;
}
.nav-primary {
text-align: center;
}
.site-header .search-form {
width: 100%;
}
}
@media only screen and (max-width: 768px) {
.nav-primary {
margin-top: 10px;
}
}
@media only screen and (max-width: 320px) {
.search-div {
right: -86px;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.