]> git.openstreetmap.org Git - rails.git/commitdiff
Autofocus the search field on the index page
authorPaweł Paprota <ppawel@fastmail.fm>
Thu, 13 Dec 2012 19:14:58 +0000 (19:14 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 13 Dec 2012 19:16:41 +0000 (19:16 +0000)
app/assets/javascripts/index.js
app/views/site/_search.html.erb

index c908f1e3490353d72d53d067e2ad614ff8560aa7..5cf9c15ff0311a7d5763a72f95f160624125341a 100644 (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();
+  }
 });
index bcab7e4047b7eed6073886aaf0644585478cb435..c074a49a30804082ff6c1d5fbe8e07abf3eb423d 100644 (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>