- This topic has 7 replies, 3 voices, and was last updated 4 years ago by Tom.
-
AuthorPosts
-
March 30, 2020 at 5:25 am #1219355Tesco
Hi,
The search bar on the navigation menu can be very discreet by using some colours and I thought to use an overlay layer activated by a javascript function.
I’ve implemented the overlay div and the custom Javascript codes on separated hooks (which I think is the correct way..?), but I need to place an action on click
onclick="ShowHideOverlayer();"
on the button that opens the search bar (afterclass="search-item active close-search sfHover"
).Is there a way to do it?
Also, I already use this code to customize the placeholder inside it…
add_filter( 'generate_navigation_search_output','tu_custom_placeholder_on_search_on_navigation' ); function tu_custom_placeholder_on_search_on_navigation() { printf( '<form method="get" class="search-form navigation-search" action="%1$s"> <input type="search" placeholder="Enter your search here..." class="search-field" value="%2$s" name="s" title="%3$s"/> </form>', esc_url( home_url( '/' ) ), esc_attr( get_search_query() ), esc_attr_x( 'Search', 'label', 'generatepress' ) ); }
March 30, 2020 at 10:10 am #1219830TomLead DeveloperLead DeveloperHi there,
It’s not possible to filter the toggle right now.
However, you can try this:
document.querySelector( '.search-item' ).addEventListener( 'click', 'ShowHideOverlayer' );
March 30, 2020 at 2:04 pm #1220084TescoI’ve put this inside my hook (wp_footer) like so:
<script> document.querySelector( '.search-item' ).addEventListener( 'click', 'ShowHideOverlayer' ); </script>
but is not working…
Something wrong here?
ps – Ideally, this should run
onload
March 30, 2020 at 4:01 pm #1220158TomLead DeveloperLead DeveloperWhere is
ShowHideOverlayer()
defined?March 30, 2020 at 4:09 pm #1220163Tescosorry…
Just below as stated here:
<script> document.querySelector( '.search-item' ).addEventListener( 'click', 'ShowHideOverlayer' ); function ShowHideOverlayer() {document.getElementById("overlay").style.display = "block";} </script>
March 31, 2020 at 2:44 am #1220501DavidStaffCustomer SupportHi there,
did you resolve this ? It looks to be working to me – although you need to add some code for removing the overlay on second click.
March 31, 2020 at 3:13 am #1220521TescoHi, David.
…not yet… Can you please share the second click solution?
March 31, 2020 at 9:22 am #1221057TomLead DeveloperLead DeveloperTry this:
<script> document.querySelector( '.search-item' ).addEventListener( 'click', function() { document.getElementById("overlay").style.display = "block"; } ); </script>
So that will look for an element with the ID “overlay” and display it when you click the
.search-item
element. -
AuthorPosts
- You must be logged in to reply to this topic.