From 516aef5d07eaaad43311bc60018648b952d95a1d Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Mon, 8 Oct 2007 23:32:58 +0000 Subject: [PATCH 1/1] Split out sidebar code from the search code so it can be reused for the map key more cleanly. --- app/controllers/geocoder_controller.rb | 8 +++---- app/views/site/_key.rhtml | 12 ++++++++++ app/views/site/_search.rhtml | 32 ++------------------------ app/views/site/_sidebar.rhtml | 29 +++++++++++++++++++++++ app/views/site/edit.rhtml | 13 ++++++----- app/views/site/index.rhtml | 18 +++++++-------- public/stylesheets/site.css | 6 ++--- 7 files changed, 65 insertions(+), 53 deletions(-) create mode 100644 app/views/site/_key.rhtml create mode 100644 app/views/site/_sidebar.rhtml diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 8abcbdc44..27e7cbf3e 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -21,13 +21,13 @@ class GeocoderController < ApplicationController results_count = count_results(results) render :update do |page| - page.replace_html :search_results_content, :partial => 'results', :object => results + page.replace_html :sidebar_content, :partial => 'results', :object => results if results_count == 1 position = results.collect { |s| s[:results] }.compact.flatten[0] page.call "setPosition", position[:lat], position[:lon], position[:zoom] else - page.call "openSearchResults" + page.call "openSidebar" end end end @@ -44,8 +44,8 @@ class GeocoderController < ApplicationController results.push description_geonames(lat, lon) render :update do |page| - page.replace_html :search_results_content, :partial => 'results', :object => results - page.call "openSearchResults" + page.replace_html :sidebar_content, :partial => 'results', :object => results + page.call "openSidebar" end end diff --git a/app/views/site/_key.rhtml b/app/views/site/_key.rhtml new file mode 100644 index 000000000..2d8f1bc76 --- /dev/null +++ b/app/views/site/_key.rhtml @@ -0,0 +1,12 @@ +<% content_for :left_menu do %> +<%= link_to_function "Map key", "showKey();" %> +<% end %> + + diff --git a/app/views/site/_search.rhtml b/app/views/site/_search.rhtml index c874e180c..19b4ca2d1 100644 --- a/app/views/site/_search.rhtml +++ b/app/views/site/_search.rhtml @@ -1,26 +1,8 @@ -
- - - - - -
Search ResultsClose
-
-
-
- diff --git a/app/views/site/edit.rhtml b/app/views/site/edit.rhtml index 6b5952f38..ceb4702d4 100644 --- a/app/views/site/edit.rhtml +++ b/app/views/site/edit.rhtml @@ -13,7 +13,8 @@ <% end %> <% end %> -<%= render :partial => 'search', :locals => { :onopen => "resizeMap();", :onclose => "resizeMap();" } %> +<%= render :partial => 'sidebar', :locals => { :onopen => "resizeMap();", :onclose => "resizeMap();" } %> +<%= render :partial => 'search' %> <% session[:token] = @user.tokens.create.token unless session[:token] %> @@ -68,14 +69,14 @@ } function resizeMap() { - var search_results_width = $("search_results").offsetWidth; + var sidebar_width = $("sidebar").offsetWidth; - if (search_results_width > 0) { - search_results_width = search_results_width + 5 + if (sidebar_width > 0) { + sidebar_width = sidebar_width + 5 } - $("map").style.left = (search_results_width) + "px"; - $("map").style.width = ($("content").offsetWidth - search_results_width) + "px"; + $("map").style.left = (sidebar_width) + "px"; + $("map").style.width = ($("content").offsetWidth - sidebar_width) + "px"; $("map").style.height = ($("content").offsetHeight - 2) + "px"; } diff --git a/app/views/site/index.rhtml b/app/views/site/index.rhtml index 8615c59be..1d8444221 100644 --- a/app/views/site/index.rhtml +++ b/app/views/site/index.rhtml @@ -4,11 +4,9 @@ <% end %> <% end %> -<% content_for :left_menu do %> -<%= link_to_function "Map key", "showKey();" %> -<% end %> - -<%= render :partial => 'search', :locals => { :onopen => "resizeMap();", :onclose => "resizeMap();" } %> +<%= render :partial => 'sidebar', :locals => { :onopen => "resizeMap();", :onclose => "resizeMap();" } %> +<%= render :partial => 'key' %> +<%= render :partial => 'search' %>
@@ -139,14 +137,14 @@ function resizeMap() { var centre = map.getCenter(); var zoom = map.getZoom(); - var search_results_width = $("search_results").offsetWidth; + var sidebar_width = $("sidebar").offsetWidth; - if (search_results_width > 0) { - search_results_width = search_results_width + 5 + if (sidebar_width > 0) { + sidebar_width = sidebar_width + 5 } - $("map").style.left = (search_results_width) + "px"; - $("map").style.width = ($("content").offsetWidth - search_results_width) + "px"; + $("map").style.left = (sidebar_width) + "px"; + $("map").style.width = ($("content").offsetWidth - sidebar_width) + "px"; $("map").style.height = ($("content").offsetHeight - 2) + "px"; map.setCenter(centre, zoom); diff --git a/public/stylesheets/site.css b/public/stylesheets/site.css index edaf46cef..b11eb191d 100644 --- a/public/stylesheets/site.css +++ b/public/stylesheets/site.css @@ -413,7 +413,7 @@ hides rule from IE5-Mac \*/ bottom: 0px; } -#search_results { +#sidebar { display: none; position: absolute; border: 1px solid black; @@ -425,7 +425,7 @@ hides rule from IE5-Mac \*/ bottom: 0px; } -#search_results_content { +#sidebar_content { overflow: auto; position: absolute; font-size: 13px; @@ -436,7 +436,7 @@ hides rule from IE5-Mac \*/ right: 0px; } -.search_results_title { +.sidebar_title { margin: 0px; padding: 3px 6px 3px 6px; height: 29px; -- 2.43.2