Autofocus the search field on the index page

This commit is contained in:
Paweł Paprota 2012-12-13 19:14:58 +00:00 committed by Tom Hughes
parent 00548468ac
commit bdc536d126
2 changed files with 7 additions and 1 deletions

View file

@ -128,4 +128,10 @@ $(document).ready(function () {
if ($("#query").val()) {
$("#search_form").submit();
}
// Focus the search field for browsers that don't support
// the HTML5 'autofocus' attribute
if (!("autofocus" in document.createElement("input"))) {
$("#query").focus();
}
});

View file

@ -19,7 +19,7 @@
<div id="search_field">
<%= form_tag url_for(:controller => :geocoder, :action => :search), :id => "search_form" do %>
<%= submit_tag t('site.search.submit_text') %>
<%= text_field_tag :query, h(params[:query]), :tabindex => "1", :placeholder => t('site.search.search') %>
<%= text_field_tag :query, h(params[:query]), :tabindex => "1", :placeholder => t('site.search.search'), :autofocus => "autofocus" %>
<% end %>
</div>
</div>