From: Paweł Paprota Date: Thu, 13 Dec 2012 19:14:58 +0000 (+0000) Subject: Autofocus the search field on the index page X-Git-Tag: live~5147 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/bdc536d126d884b0795bf82784fc81d4a5e47dcc Autofocus the search field on the index page --- diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index c908f1e34..5cf9c15ff 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -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(); + } }); diff --git a/app/views/site/_search.html.erb b/app/views/site/_search.html.erb index bcab7e404..c074a49a3 100644 --- a/app/views/site/_search.html.erb +++ b/app/views/site/_search.html.erb @@ -19,7 +19,7 @@
<%= 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 %>