]> git.openstreetmap.org Git - rails.git/commitdiff
Replace some inline javascript with a UJS solution
authorTom Hughes <tom@compton.nu>
Mon, 6 May 2013 10:09:17 +0000 (11:09 +0100)
committerTom Hughes <tom@compton.nu>
Mon, 6 May 2013 10:09:17 +0000 (11:09 +0100)
app/assets/javascripts/application.js
app/assets/javascripts/geocoder.js [new file with mode: 0644]
app/views/geocoder/results.html.erb

index 284ec77e618576c66f54984e5948c95c7ee1c8b7..4c2b7940370d3d07aa04375456a2d1501cad4861 100644 (file)
@@ -18,6 +18,7 @@
 //= require sidebar
 //= require richtext
 //= require resize
 //= require sidebar
 //= require richtext
 //= require resize
+//= require geocoder
 
 function zoomPrecision(zoom) {
     var decimals = Math.pow(10, Math.floor(zoom/3));
 
 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 (file)
index 0000000..0809bef
--- /dev/null
@@ -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);
+    });
+  });
+});
index 7fd21775ec81264df6393a9f4f614824770e3f8a..f98f2abc9e3c490f7643c749c8bd1a9138a4a853 100644 (file)
@@ -7,20 +7,11 @@
   <% end %>
 </ul>
   <% if @more_params %>
   <% end %>
 </ul>
   <% if @more_params %>
-    <div id="search_more_<%= @more_params.hash %>">
+    <div class="search_more">
       <div class="inner12 search_results_entry">
       <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>
       </div>
-      <%= image_tag "searching.gif", :class => "search_searching" %>
+      <%= image_tag "searching.gif", :class => ["search_searching", "hidden"] %>
     </div>
     </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 %>
   <% end %>
 <% end %>