From e84b2bd22f7c92fb7a128a91c999f86e350bf04d Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Mon, 6 May 2013 11:09:17 +0100 Subject: [PATCH] Replace some inline javascript with a UJS solution --- app/assets/javascripts/application.js | 1 + app/assets/javascripts/geocoder.js | 14 ++++++++++++++ app/views/geocoder/results.html.erb | 15 +++------------ 3 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 app/assets/javascripts/geocoder.js diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 284ec77e6..4c2b79403 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -18,6 +18,7 @@ //= require sidebar //= require richtext //= require resize +//= require geocoder function zoomPrecision(zoom) { var decimals = Math.pow(10, Math.floor(zoom/3)); diff --git a/app/assets/javascripts/geocoder.js b/app/assets/javascripts/geocoder.js new file mode 100644 index 000000000..0809bef78 --- /dev/null +++ b/app/assets/javascripts/geocoder.js @@ -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); + }); + }); +}); diff --git a/app/views/geocoder/results.html.erb b/app/views/geocoder/results.html.erb index 7fd21775e..f98f2abc9 100644 --- a/app/views/geocoder/results.html.erb +++ b/app/views/geocoder/results.html.erb @@ -7,20 +7,11 @@ <% end %> <% if @more_params %> -
+
- <%= link_to t('geocoder.results.more_results'), "#", :class => "button" %> + <%= link_to t('geocoder.results.more_results'), url_for(@more_params), :class => "button" %>
- <%= image_tag "searching.gif", :class => "search_searching" %> + <%= image_tag "searching.gif", :class => ["search_searching", "hidden"] %>
- <% end %> <% end %> -- 2.39.5