map key more cleanly.
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
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
--- /dev/null
+<% content_for :left_menu do %>
+<%= link_to_function "Map key", "showKey();" %>
+<% end %>
+
+<script type="text/javascript">
+<!--
+ function showKey() {
+ updateSidebar("Map key", "<p><img src='images/keymapnik11.png' /></p>");
+ openSidebar();
+ }
+// -->
+</script>
-<div id="search_results">
- <table class="search_results_title" width="100%">
- <tr>
- <td align="left" id="search_title">Search Results</td>
- <td align="right"><a href="javascript:closeSearchResults()">Close</a></td>
- </tr>
- </table>
- <div id="search_results_content">
- </div>
-</div>
-
<script type="text/javascript">
<!--
- function showKey() {
- $("search_results").style.display = "block";
- $("search_results_content").innerHTML = "<p><img src='images/keymapnik11.png' /></p>";
- $("search_title").innerHTML = "Map key";
- resizeMap();
- }
-
function startSearch() {
- $("search_results_content").innerHTML = "<p class='search_results_entry'>Searching...</p>";
- $("search_title").innerHTML = "Search Results";
+ updateSidebar("Search Results", "<p class='search_results_entry'>Searching...</p>");
+
$("search_field").style.display = "none";
$("search_active").style.display = "inline";
}
$("search_active").style.display = "none";
}
- function openSearchResults() {
- $("search_results").style.display = "block";
- <%= onopen %>
- }
-
- function closeSearchResults() {
- $("search_results").style.display = "none";
- <%= onclose %>
- }
-
function describeLocation() {
var position = getPosition();
--- /dev/null
+<div id="sidebar">
+ <table class="sidebar_title" width="100%">
+ <tr>
+ <td align="left" id="sidebar_title">Search Results</td>
+ <td align="right"><a href="javascript:closeSidebar()">Close</a></td>
+ </tr>
+ </table>
+ <div id="sidebar_content">
+ </div>
+</div>
+
+<script type="text/javascript">
+<!--
+ function openSidebar() {
+ $("sidebar").style.display = "block";
+ <%= onopen %>
+ }
+
+ function closeSidebar() {
+ $("sidebar").style.display = "none";
+ <%= onclose %>
+ }
+
+ function updateSidebar(title, content) {
+ $("sidebar_title").innerHTML = title;
+ $("sidebar_content").innerHTML = content;
+ }
+// -->
+</script>
<% 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] %>
}
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";
}
<% 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' %>
<div id="map"></div>
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);
bottom: 0px;
}
-#search_results {
+#sidebar {
display: none;
position: absolute;
border: 1px solid black;
bottom: 0px;
}
-#search_results_content {
+#sidebar_content {
overflow: auto;
position: absolute;
font-size: 13px;
right: 0px;
}
-.search_results_title {
+.sidebar_title {
margin: 0px;
padding: 3px 6px 3px 6px;
height: 29px;