]> git.openstreetmap.org Git - rails.git/commitdiff
Replace link_to_function with UJS based code
authorTom Hughes <tom@compton.nu>
Fri, 1 Jun 2012 15:45:32 +0000 (16:45 +0100)
committerTom Hughes <tom@compton.nu>
Fri, 1 Jun 2012 18:34:22 +0000 (19:34 +0100)
app/helpers/geocoder_helper.rb
app/helpers/user_helper.rb
app/views/site/_key.html.erb
app/views/site/_potlatch.html.erb
app/views/site/_potlatch2.html.erb
app/views/site/edit.html.erb
app/views/site/index.html.erb
app/views/user/login.html.erb
app/views/user/new.html.erb

index 082f9e5304180aed93ed6a01f359f65debc4158c..735ac815302f8ec86ec0c5a97bd8e71fc3ccee6b 100644 (file)
@@ -1,23 +1,21 @@
 module GeocoderHelper
   def result_to_html(result)
-    html_options = {}
-    #html_options[:title] = strip_tags(result[:description]) if result[:description]
+    html_options = { :class => "set_position" }
+
     if result[:min_lon] and result[:min_lat] and result[:max_lon] and result[:max_lat]
-      html_options[:href] = raw("?minlon=#{result[:min_lon]}&minlat=#{result[:min_lat]}&maxlon=#{result[:max_lon]}&maxlat=#{result[:max_lat]}")
+      url = "?minlon=#{result[:min_lon]}&minlat=#{result[:min_lat]}&maxlon=#{result[:max_lon]}&maxlat=#{result[:max_lat]}"
     else
-      html_options[:href] = raw("?mlat=#{result[:lat]}&mlon=#{result[:lon]}&zoom=#{result[:zoom]}")
+      url = "?mlat=#{result[:lat]}&mlon=#{result[:lon]}&zoom=#{result[:zoom]}"
+    end
+
+    result.each do |key,value|
+      html_options["data-#{key.to_s.tr('_', '-')}"] = value
     end
 
     html = ""
     html << result[:prefix] if result[:prefix]
     html << " " if result[:prefix] and result[:name]
-
-    if result[:min_lon] and result[:min_lat] and result[:max_lon] and result[:max_lat]
-      html << link_to_function(result[:name],"setPosition(#{result[:lat]}, #{result[:lon]}, null, #{result[:min_lon]}, #{result[:min_lat]}, #{result[:max_lon]}, #{result[:max_lat]})", html_options)  if result[:name]
-    else
-      html << link_to_function(result[:name],"setPosition(#{result[:lat]}, #{result[:lon]}, #{result[:zoom]})", html_options)  if result[:name]
-    end
-
+    html << link_to(result[:name], url, html_options) if result[:name]
     html << result[:suffix] if result[:suffix]
 
     return raw(html)
index 7a9a75c3134d7a1fe36b5a2272e2e19494f84212..dd33ed7c4e4741aecdf4d0bd7432662e4e7dda66 100644 (file)
@@ -4,10 +4,11 @@ module UserHelper
   end
 
   def openid_button(name, url)
-    link_to_function(
+    link_to(
       image_tag("#{name}.png", :alt => t("user.login.openid_providers.#{name}.alt")),
-      "submitOpenidUrl('#{url}')",
-      :title => t("user.login.openid_providers.#{name}.title")
+      "#",
+      :class => "openid_button", "data-url" => url,
+      :title => t("user.login.openid_providers.#{name}.title"),
     )
   end
 end
index 54bbca6a7727d667fd39f8cdcd3b20df00e665a7..15f64275c5e1960d220b6ff367d1a1ddcadbcf7a 100644 (file)
@@ -1,5 +1,18 @@
 <script type="text/javascript">
-  function openMapKey() {
+$(document).ready(function () {
+  var updateMapKey = function () {
+    $("#sidebar_content").load("<%= url_for :action => :key %>", {
+      layer: map.baseLayer.keyid,
+      zoom: map.getZoom()
+    });
+  }
+
+  var closeMapKey = function () {
+    map.events.unregister("zoomend", map, updateMapKey);
+    map.events.unregister("changelayer", map, updateMapKey);
+  }
+
+  $("#open_map_key").click(function () {
     updateMapKey();
 
     openSidebar({ 
 
     map.events.register("zoomend", map, updateMapKey);
     map.events.register("changelayer", map, updateMapKey);
-  }
-
-  function closeMapKey() {
-    map.events.unregister("zoomend", map, updateMapKey);
-    map.events.unregister("changelayer", map, updateMapKey);
-  }
-
-  function updateMapKey() {
-    $("#sidebar_content").load("<%= url_for :action => :key %>", {
-      layer: map.baseLayer.keyid,
-      zoom: map.getZoom()
-    });
-  }
+  });
+});
 </script>
 
 <% content_for :left_menu do %>
-  <li><%= link_to_function t('site.key.map_key'), "openMapKey()", :title => t('site.key.map_key_tooltip') %></li>
+  <li><%= link_to t("site.key.map_key"), "#", :id => "open_map_key", :title => t("site.key.map_key_tooltip") %></li>
 <% end %>
index 9dcceeb9b014ee4e2fad7784748b2015522b16b8..2cdccc4b0cdfe35eea93c6634a8b1dc65a92ec60 100644 (file)
 
   doSWF(<%= @lat || 'null' %>,<%= @lon || 'null' %>,<%= @zoom %>);
 
-  function setPosition(lat, lon, zoom) {
-    doSWF(lat, lon, zoom || 15);
-  }
+  $(document).ready(function () {
+    $("body").on("click", "a.set_position", function () {
+      var lat = parseFloat($(this).attr("data-lat"));
+      var lon = parseFloat($(this).attr("data-lon"));
+      var zoom = parseInt($(this).attr("data-zoom"));
+
+      doSWF(lat, lon, zoom || 15);
+    });
+  });
 </script>
index 95a52368e3024a3a60b76391c1f01b1d2822ac4f..4559282ca465b031dfd152baff9d6adb4ace54f2 100644 (file)
   doSWF(<%= @lat || 'null' %>,<%= @lon || 'null' %>,<%= @zoom %>);
   <% end -%>
 
-  function setPosition(lat, lon, zoom) {
-    $("#potlatch").each(function () {
-      this.setPosition(lat, lon, Math.max(zoom || 15, 13));
+  $(document).ready(function () {
+    $("body").on("click", "a.set_position", function () {
+      var lat = parseFloat($(this).attr("data-lat"));
+      var lon = parseFloat($(this).attr("data-lon"));
+      var zoom = parseInt($(this).attr("data-zoom"));
+
+      $("#potlatch").each(function () {
+        this.setPosition(lat, lon, Math.max(zoom || 15, 13));
+      });
     });
-  }
+  });
 
   function mapMoved(lon, lat, zoom, minlon, minlat, maxlon, maxlat) {
     updatelinks(lon, lat, zoom, null, minlon, minlat, maxlon, maxlat);
index 84de929541dfc2235571a3d4617677f136f012ba..a87da1125e233fce24e0b939c9a29a657ca1f631 100644 (file)
@@ -11,7 +11,7 @@
 <% else %>
 <% content_for :greeting do %>
 <% if @user and !@user.home_lon.nil? and !@user.home_lat.nil? %>
-<%= link_to_function t('layouts.home'), "setPosition(#{@user.home_lat}, #{@user.home_lon}, 10)", { :title => t('layouts.home_tooltip') } %> |
+<%= link_to t("layouts.home"), "#", :class => "set_position", "data-lat" => @user.home_lat, "data-lon" => @user.home_lon, "data-zoom" => 15, :title => t("layouts.home_tooltip") %> |
 <% end %>
 <% end %>
 
index 4c954e6cb4f135e745220acf3976278d16f69852..0bbf66e1557ab43473e81c88b05f8048dc4eacb9 100644 (file)
@@ -1,12 +1,12 @@
 <% if @user and !@user.home_lon.nil? and !@user.home_lat.nil? %>
   <% content_for :greeting do %>
-    <%= link_to_function t('layouts.home'), "setPosition(#{@user.home_lat}, #{@user.home_lon}, 15)", { :title => t('layouts.home_tooltip') } %> |
+    <%= link_to t("layouts.home"), "#", :class => "set_position", "data-lat" => @user.home_lat, "data-lon" => @user.home_lon, "data-zoom" => 15, :title => t("layouts.home_tooltip") %> |
   <% end %>
 <% end %>
 
 <% unless STATUS == :api_offline or STATUS == :database_offline -%>
   <% content_for :editmenu do -%>
-    <li><%= link_to_function(t('browse.start_rjs.data_layer_name'), 'showData()') %></li>
+    <li><%= link_to t("browse.start_rjs.data_layer_name"), "#", :id => "show_data" %></li>
   <% end -%>
 <% end -%>
 
@@ -193,27 +193,38 @@ end
     handleResize();
   }
 
-  function showData() {
-    $.ajax({ url: "<%= url_for :controller => :browse, :action => :start %>" });
-  }
+  $(document).ready(function () {
+    $("#show_data").click(function () {
+      $.ajax({ url: "<%= url_for :controller => :browse, :action => :start %>" });
+    });
 
-  function setPosition(lat, lon, zoom, min_lon, min_lat, max_lon, max_lat) {
-    var centre = new OpenLayers.LonLat(lon, lat);
+    $("body").on("click", "a.set_position", function () {
+      var lat = parseFloat($(this).attr("data-lat"));
+      var lon = parseFloat($(this).attr("data-lon"));
+      var zoom = parseInt($(this).attr("data-zoom"));
+      var min_lon = parseFloat($(this).attr("data-min-lon"));
+      var min_lat = parseFloat($(this).attr("data-min-lat"));
+      var max_lon = parseFloat($(this).attr("data-max-lon"));
+      var max_lat = parseFloat($(this).attr("data-max-lat"));
+      var centre = new OpenLayers.LonLat(lon, lat);
 
-    if (min_lon && min_lat && max_lon && max_lat) {
-      var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
+      if (min_lon && min_lat && max_lon && max_lat) {
+        var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
 
-      map.zoomToExtent(proj(bbox));
-    } else {
-      setMapCenter(centre, zoom);
-    }
+        map.zoomToExtent(proj(bbox));
+      } else {
+        setMapCenter(centre, zoom);
+      }
 
-    if (marker) {
-      removeMarkerFromMap(marker);
-    }
+      if (marker) {
+        removeMarkerFromMap(marker);
+      }
 
-    marker = addMarkerToMap(centre, getArrowIcon());
-  }
+      marker = addMarkerToMap(centre, getArrowIcon());
+
+      return false;
+    });
+  });
 
   function updateLocation() {
     var lonlat = unproj(map.getCenter());
index c185a11b7fa416a3858b2bd2af256d3e4ded1fd3..5208d0a7f03c0c340aade3b3c6fd21f04a387a90 100644 (file)
@@ -32,7 +32,7 @@
 
       <table id="login_openid_buttons">
         <tr>
-          <td><%= link_to_function(image_tag("openid.png", :alt => t("user.login.openid_providers.openid.title")), "showOpenidUrl()", :title => t("user.login.openid_providers.openid.title")) %></td>
+          <td><%= link_to image_tag("openid.png", :alt => t("user.login.openid_providers.openid.title")), "#", :id => "openid_open_url", :title => t("user.login.openid_providers.openid.title") %></td>
           <td><%= openid_button "google", "gmail.com" %></td>
           <td><%= openid_button "yahoo", "me.yahoo.com" %></td>
           <td><%= openid_button "myopenid", "myopenid.com" %></td>
 </div>
 
 <script type="text/javascript">
-function showOpenidUrl() {
-  $("#openid_url").val("http://");
-  $("#login_openid_buttons").hide();
-  $("#login_openid_url").show();
-  $("#login_openid_submit").show();
-}
+$(document).ready(function() {
+  $("#openid_open_url").click(function() {
+    $("#openid_url").val("http://");
+    $("#login_openid_buttons").hide();
+    $("#login_openid_url").show();
+    $("#login_openid_submit").show();
+  });
 
-function submitOpenidUrl(url) {
-  $("#openid_url").val(url);
-  $("#login_form").submit();
-}
+  $(".openid_button").click(function() {
+    $("#openid_url").val($(this).attr("data-url"));
+    $("#login_form").submit();
+  });
 
-$("#login_openid_url").hide();
-$("#login_openid_submit").hide();
+  $("#login_openid_url").hide();
+  $("#login_openid_submit").hide();
+});
 </script>
index e8400eb9019a687c629a5c8eac5d5eb82e8e6fdb..f45072a92c8f6b2f366168f8b6b29f7a11ec7f10 100644 (file)
@@ -51,7 +51,7 @@
     <tr>
       <td></td>
       <td>
-        <span id="openid_prompt" class="minorNote"><%= link_to_function(raw(t('user.new.use openid', :logo => openid_logo)), "enableOpenID()") %></span>
+        <span id="openid_prompt" class="minorNote"><%= link_to raw(t("user.new.use openid", :logo => openid_logo)), "#", :id => "openid_enable" %></span>
         <span id="openid_note" class="minorNote"><%= t 'user.new.openid no password' %></span>
       </td>
     </tr>
@@ -88,9 +88,13 @@ function disableOpenID()
   $("#openid_url").prop("disabled", true);
 }
 
-<% if params[:openid] or (@user and @user.openid_url and not @user.openid_url.empty?) -%>
-enableOpenID();
-<% else -%>
-disableOpenID();
-<% end -%>
+$(document).ready(function () {
+  $("#openid_enable").click(enableOpenID);
+
+  <% if params[:openid] or (@user and @user.openid_url and not @user.openid_url.empty?) -%>
+  enableOpenID();
+  <% else -%>
+  disableOpenID();
+  <% end -%>
+});
 </script>