Skip to content

Instantly share code, notes, and snippets.

@10h30
Forked from srikat/functions.php
Last active February 3, 2017 00:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 10h30/5d1dc71edf30879f0aca to your computer and use it in GitHub Desktop.
Save 10h30/5d1dc71edf30879f0aca to your computer and use it in GitHub Desktop.
How to set up animated Search form in Genesis. http://sridharkatakam.com/set-animated-search-form-genesis/
//* Enqueue scripts and styles
add_action( 'wp_enqueue_scripts', 'custom_enqueue_scripts_styles' );
function custom_enqueue_scripts_styles() {
wp_enqueue_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css' );
wp_enqueue_script( 'global', get_bloginfo( 'stylesheet_directory' ) . '/js/global.js', array( 'jquery' ), '1.0.0', true );
}
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( $ ){
$( '#main-nav-search-link' ).click(function(event){
if ( event.target !== this )
return;
$('.search-div' ).slideToggle(function() {
$(this).parent().toggleClass( 'search-open' );
});
});
});
jQuery(function( $ ){
$('#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 .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;
}
/*li a.icon-search:hover {
border-bottom: none;
}*/
.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;
}
.search-div .search-form input[type="search"] {
width: 100%;
padding: 10px;
font-size: 16px;
}
.search-div .search-form input[type="submit"] {
position: absolute;
right: -1px;
bottom: 1px;
padding: 10px 14px;
-webkit-border-radius: 0;
border-radius: 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: 800px) {
.nav-primary .genesis-nav-menu > .search {
display: block;
text-align: left;
}
.search-div {
left: 0;
}
}
@media only screen and (max-width: 340px) {
.search-div {
width: auto;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment