Move search form to header on small screens
authorJohn Firebaugh <john.firebaugh@gmail.com>
Mon, 11 Nov 2013 21:37:32 +0000 (13:37 -0800)
committerJohn Firebaugh <john.firebaugh@gmail.com>
Mon, 11 Nov 2013 21:38:46 +0000 (13:38 -0800)
app/assets/javascripts/index.js
app/assets/javascripts/index/search.js
app/assets/stylesheets/common.css.scss
app/assets/stylesheets/small.css.scss
app/views/layouts/_header.html.erb
app/views/layouts/_search.html.erb [new file with mode: 0644]
app/views/layouts/map.html.erb

index 5e96c35..7d2e954 100644 (file)
@@ -297,12 +297,13 @@ $(document).ready(function () {
     if (this.host === window.location.host && OSM.route(this.pathname + this.search + this.hash)) e.preventDefault();
   });
 
-  $("#search_form").on("submit", function(e) {
+  $(".search_form").on("submit", function(e) {
     e.preventDefault();
-    OSM.route("/search?query=" + encodeURIComponent($("#query").val()) + OSM.formatHash(map));
+    $("header").addClass("closed");
+    OSM.route("/search?query=" + encodeURIComponent($(this).find("input[name=query]").val()) + OSM.formatHash(map));
   });
 
-  $("#describe_location").on("click", function(e) {
+  $(".describe_location").on("click", function(e) {
     e.preventDefault();
     var precision = zoomPrecision(map.getZoom());
     OSM.route("/search?query=" + encodeURIComponent(
index e92f374..7f6eac9 100644 (file)
@@ -1,10 +1,10 @@
 OSM.Search = function(map) {
-  $("#query")
+  $(".search_form input[name=query]")
     .on("focus", function() {
-      $("#describe_location").fadeOut(100);
+      $(".describe_location").fadeOut(100);
     })
     .on("blur", function() {
-      $("#describe_location").fadeIn(100);
+      $(".describe_location").fadeIn(100);
     });
 
   $("#sidebar_content")
@@ -48,7 +48,8 @@ OSM.Search = function(map) {
 
   page.pushstate = page.popstate = function(path) {
     var params = querystring.parse(path.substring(path.indexOf('?') + 1));
-    $("#query").val(params.query);
+    $(".search_form input[name=query]").val(params.query);
+    map.invalidateSize();
     $("#sidebar_content").load(path, function() {
       if (xhr.getResponseHeader('X-Page-Title')) {
         document.title = xhr.getResponseHeader('X-Page-Title');
@@ -80,7 +81,7 @@ OSM.Search = function(map) {
   page.unload = function() {
     map.removeLayer(marker);
     map.removeObject();
-    $("#query").val("");
+    $(".search_form input[name=query]").val("");
   };
 
   return page;
index 081f094..86b5a6a 100644 (file)
@@ -900,21 +900,25 @@ nav.secondary {
 
 /* Rules for the search box */
 
-#search_form {
+header .search_form {
+  display: none;
+}
+
+.search_form {
   position: relative;
   padding: $lineheight/2;
   background-color: $lightgrey;
 
-  #query_wrapper {
+  .query_wrapper {
     position: relative;
     overflow: hidden;
+    border-radius: 2px 0 0 2px;
   }
 
-  input {
+  input[type=text] {
     width: 100%;
     height: 30px;
     border-right: none;
-    border-radius: 2px 0 0 2px;
 
     transition: 300ms linear;
     -webkit-transition: 300ms linear;
@@ -933,7 +937,7 @@ nav.secondary {
     border-radius: 0 2px 2px 0;
   }
 
-  #describe_location {
+  .describe_location {
     position: absolute;
     top: 6px;
     right: 6px;
index 182272e..5e8edc2 100644 (file)
@@ -32,8 +32,13 @@ header {
   &.closed nav {
     display: none;
   }
+
+  .search_form {
+    display: block;
+  }
 }
 
+#sidebar .search_form,
 #edit_tab,
 #export_tab {
   display: none;
index 1142eeb..334056e 100644 (file)
@@ -7,6 +7,7 @@
   </h1>
   <a href="#" id="menu-icon"></a>
   <nav class='primary'>
+    <%= render :partial => "layouts/search" %>
     <ul>
       <li id="edit_tab" class="dropdown <%= current_page_class(edit_path) %>">
         <%= link_to t('layouts.edit'), edit_path, :class => "tab geolink editlink",
diff --git a/app/views/layouts/_search.html.erb b/app/views/layouts/_search.html.erb
new file mode 100644 (file)
index 0000000..1d054d5
--- /dev/null
@@ -0,0 +1,7 @@
+<%= form_tag search_path, :class => "search_form" do %>
+  <%= submit_tag t('site.search.submit_text') %>
+  <div class='query_wrapper'>
+    <input type="text" name="query" value="<%= params[:query] %>" placeholder="<%= t('site.search.search') %>">
+    <%= link_to t('site.search.where_am_i'), '#', { :class => "describe_location", :title => t('site.search.where_am_i_title') } %>
+  </div>
+<% end %>
index 1daae05..a7d00f5 100644 (file)
 
 <% content_for :content do %>
   <div id="sidebar">
-    <%= form_tag search_path, :id => "search_form" do %>
-      <%= submit_tag t('site.search.submit_text') %>
-      <div id='query_wrapper'>
-        <%= text_field_tag :query, params[:query],
-                           :placeholder => t('site.search.search') %>
-        <%= link_to t('site.search.where_am_i'), '#', { :id => "describe_location", :title => t('site.search.where_am_i_title') } %>
-      </div>
-    <% end %>
+    <%= render :partial => "layouts/search" %>
 
     <% if STATUS == :database_offline or STATUS == :api_offline %>
       <p class="error"><%= t 'layouts.osm_offline' %></p>