From: Tom Hughes Date: Fri, 1 Jun 2012 15:45:32 +0000 (+0100) Subject: Replace link_to_function with UJS based code X-Git-Tag: live~6070 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/490226ad6d28cf9eff1fc78c7c69bef750321614?ds=sidebyside Replace link_to_function with UJS based code --- diff --git a/app/helpers/geocoder_helper.rb b/app/helpers/geocoder_helper.rb index 082f9e530..735ac8153 100644 --- a/app/helpers/geocoder_helper.rb +++ b/app/helpers/geocoder_helper.rb @@ -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) diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb index 7a9a75c31..dd33ed7c4 100644 --- a/app/helpers/user_helper.rb +++ b/app/helpers/user_helper.rb @@ -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 diff --git a/app/views/site/_key.html.erb b/app/views/site/_key.html.erb index 54bbca6a7..15f64275c 100644 --- a/app/views/site/_key.html.erb +++ b/app/views/site/_key.html.erb @@ -1,5 +1,18 @@ <% content_for :left_menu do %> -
  • <%= link_to_function t('site.key.map_key'), "openMapKey()", :title => t('site.key.map_key_tooltip') %>
  • +
  • <%= link_to t("site.key.map_key"), "#", :id => "open_map_key", :title => t("site.key.map_key_tooltip") %>
  • <% end %> diff --git a/app/views/site/_potlatch.html.erb b/app/views/site/_potlatch.html.erb index 9dcceeb9b..2cdccc4b0 100644 --- a/app/views/site/_potlatch.html.erb +++ b/app/views/site/_potlatch.html.erb @@ -44,7 +44,13 @@ 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); + }); + }); diff --git a/app/views/site/_potlatch2.html.erb b/app/views/site/_potlatch2.html.erb index 95a52368e..4559282ca 100644 --- a/app/views/site/_potlatch2.html.erb +++ b/app/views/site/_potlatch2.html.erb @@ -73,11 +73,17 @@ 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); diff --git a/app/views/site/edit.html.erb b/app/views/site/edit.html.erb index 84de92954..a87da1125 100644 --- a/app/views/site/edit.html.erb +++ b/app/views/site/edit.html.erb @@ -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 %> diff --git a/app/views/site/index.html.erb b/app/views/site/index.html.erb index 4c954e6cb..0bbf66e15 100644 --- a/app/views/site/index.html.erb +++ b/app/views/site/index.html.erb @@ -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 -%> -
  • <%= link_to_function(t('browse.start_rjs.data_layer_name'), 'showData()') %>
  • +
  • <%= link_to t("browse.start_rjs.data_layer_name"), "#", :id => "show_data" %>
  • <% 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()); diff --git a/app/views/user/login.html.erb b/app/views/user/login.html.erb index c185a11b7..5208d0a7f 100644 --- a/app/views/user/login.html.erb +++ b/app/views/user/login.html.erb @@ -32,7 +32,7 @@ - + @@ -65,18 +65,20 @@ diff --git a/app/views/user/new.html.erb b/app/views/user/new.html.erb index e8400eb90..f45072a92 100644 --- a/app/views/user/new.html.erb +++ b/app/views/user/new.html.erb @@ -51,7 +51,7 @@ @@ -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 -%> +});
    <%= link_to_function(image_tag("openid.png", :alt => t("user.login.openid_providers.openid.title")), "showOpenidUrl()", :title => t("user.login.openid_providers.openid.title")) %><%= 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") %> <%= openid_button "google", "gmail.com" %> <%= openid_button "yahoo", "me.yahoo.com" %> <%= openid_button "myopenid", "myopenid.com" %>
    - <%= link_to_function(raw(t('user.new.use openid', :logo => openid_logo)), "enableOpenID()") %> + <%= link_to raw(t("user.new.use openid", :logo => openid_logo)), "#", :id => "openid_enable" %> <%= t 'user.new.openid no password' %>