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)
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
<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 %>
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>
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);
<% 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 %>
<% 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 -%>
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());
<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>
<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>
$("#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>