From 2aa6ed1f495ce2674934cab9a5ba45cc6b144a39 Mon Sep 17 00:00:00 2001 From: razyees Date: Mon, 11 Mar 2019 14:54:00 +0545 Subject: [PATCH 1/3] Tweak - Autofocus on search box --- js/custom.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/js/custom.js b/js/custom.js index aec3e9c..e6daa14 100644 --- a/js/custom.js +++ b/js/custom.js @@ -8,6 +8,11 @@ jQuery(document).ready(function() { jQuery('.header-search-icon').click(function(){ jQuery('#masthead .search-form').toggle('slow'); + + // focus after some time to fix conflict with toggleClass + setTimeout( function () { + jQuery( '#masthead .search-form input' ).focus(); + }, 200 ); }); jQuery(window).bind('scroll', function() { From 2b3e36ec279a6fed5e533e79a6f32c9e9b77301c Mon Sep 17 00:00:00 2001 From: razyees Date: Mon, 11 Mar 2019 14:56:46 +0545 Subject: [PATCH 2/3] Tweak - Hide search on esc --- js/custom.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/js/custom.js b/js/custom.js index e6daa14..efd83bc 100644 --- a/js/custom.js +++ b/js/custom.js @@ -6,6 +6,9 @@ jQuery(document).ready(function() { jQuery('body').css({ 'margin-top': divheight }); } + var hideSearchForm = function() { + jQuery( '#masthead .search-form' ).hide( 'slow' ); + }; jQuery('.header-search-icon').click(function(){ jQuery('#masthead .search-form').toggle('slow'); @@ -13,6 +16,20 @@ jQuery(document).ready(function() { setTimeout( function () { jQuery( '#masthead .search-form input' ).focus(); }, 200 ); + + // For esc key press. + jQuery( document ).on( 'keyup', function ( e ) { + + // on esc key press. + if ( 27 === e.keyCode ) { + // if search box is opened + if ( jQuery( '#masthead' ).has( '.search-form' ) ) { + hideSearchForm(); + } + + } + } ); + }); jQuery(window).bind('scroll', function() { From 795ae54ce254cc9bbcccc3cd4d01f787f9208a56 Mon Sep 17 00:00:00 2001 From: razyees Date: Mon, 11 Mar 2019 14:58:27 +0545 Subject: [PATCH 3/3] Tweak - Hide search on clicking outside of search box --- js/custom.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/js/custom.js b/js/custom.js index efd83bc..13a6322 100644 --- a/js/custom.js +++ b/js/custom.js @@ -30,6 +30,14 @@ jQuery(document).ready(function() { } } ); + jQuery( document ).on( 'click', function( e ) { + var container = jQuery( '.search-form, .header-search-icon, .search-form input' ); + if ( ! container.is( e.target ) ) { + hideSearchForm(); + } + + } ); + }); jQuery(window).bind('scroll', function() {