Replace some inline javascript with a UJS solution

This commit is contained in:
Tom Hughes 2013-05-06 11:09:17 +01:00
parent 8bb7cdb75a
commit e84b2bd22f
3 changed files with 18 additions and 12 deletions

View file

@ -18,6 +18,7 @@
//= require sidebar
//= require richtext
//= require resize
//= require geocoder
function zoomPrecision(zoom) {
var decimals = Math.pow(10, Math.floor(zoom/3));

View file

@ -0,0 +1,14 @@
$(document).ready(function () {
$("body").on("click", ".search_more a", function (e) {
e.preventDefault();
var div = $(this).parents(".search_more");
div.find(".search_results_entry").hide();
div.find(".search_searching").show();
$.get($(this).attr("href"), function(data) {
div.replaceWith(data);
});
});
});

View file

@ -7,20 +7,11 @@
<% end %>
</ul>
<% if @more_params %>
<div id="search_more_<%= @more_params.hash %>">
<div class="search_more">
<div class="inner12 search_results_entry">
<%= link_to t('geocoder.results.more_results'), "#", :class => "button" %>
<%= link_to t('geocoder.results.more_results'), url_for(@more_params), :class => "button" %>
</div>
<%= image_tag "searching.gif", :class => "search_searching" %>
<%= image_tag "searching.gif", :class => ["search_searching", "hidden"] %>
</div>
<script type="text/javascript">
$("#search_more_<%= @more_params.hash %> .search_searching").hide();
$("#search_more_<%= @more_params.hash %> a").click(function () {
$("#search_more_<%= @more_params.hash %> .search_results_entry").hide();
$("#search_more_<%= @more_params.hash %> .search_searching").show();
$("#search_more_<%= @more_params.hash %>").load("<%= raw url_for(@more_params) %>");
});
</script>
<% end %>
<% end %>