From: John Firebaugh Date: Fri, 5 Oct 2012 19:03:26 +0000 (-0700) Subject: Clean up diary_entry.js X-Git-Tag: live~5822 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/8d13c394001ea1f98290dddb304b13c08f2ac77e Clean up diary_entry.js --- diff --git a/app/assets/javascripts/diary_entry.js b/app/assets/javascripts/diary_entry.js index 7dc988de7..c16930480 100644 --- a/app/assets/javascripts/diary_entry.js +++ b/app/assets/javascripts/diary_entry.js @@ -1,33 +1,37 @@ -var marker; +$(document).ready(function () { + var marker; -function setLocation( e ) { - closeMapPopup(); + function setLocation(e) { + closeMapPopup(); - var lonlat = getEventPosition(e); + var lonlat = getEventPosition(e); - $("#latitude").val(lonlat.lat); - $("#longitude").val(lonlat.lon); + $("#latitude").val(lonlat.lat); + $("#longitude").val(lonlat.lon); - if (marker) { - removeMarkerFromMap(marker); + if (marker) { + removeMarkerFromMap(marker); + } + + marker = addMarkerToMap(lonlat, null, I18n.t('diary_entry.edit.marker_text')); } - marker = addMarkerToMap(lonlat, null, I18n.t('diary_entry.edit.marker_text')); -} + $("#usemap").click(function (e) { + e.preventDefault(); -function openMap() { - $("#map").show(); - $("#usemap").hide(); + $("#map").show(); + $("#usemap").hide(); - var params = $("#map").data(); - var centre = new OpenLayers.LonLat(params.lon, params.lat); - var map = createMap("map"); + var params = $("#map").data(); + var centre = new OpenLayers.LonLat(params.lon, params.lat); + var map = createMap("map"); - setMapCenter(centre, params.zoom); + setMapCenter(centre, params.zoom); - if ($("#latitude").val() && $("#longitude").val()) { - marker = addMarkerToMap(centre, null, I18n.t('diary_entry.edit.marker_text')); - } + if ($("#latitude").val() && $("#longitude").val()) { + marker = addMarkerToMap(centre, null, I18n.t('diary_entry.edit.marker_text')); + } - map.events.register("click", map, setLocation); -} + map.events.register("click", map, setLocation); + }); +}); diff --git a/app/views/diary_entry/edit.html.erb b/app/views/diary_entry/edit.html.erb index e6674742f..0cdd3b098 100644 --- a/app/views/diary_entry/edit.html.erb +++ b/app/views/diary_entry/edit.html.erb @@ -25,7 +25,7 @@ <%= content_tag "div", "", :id => "map", :data => {:lat => @lat, :lon => @lon, :zoom => @zoom} %> <%= t 'diary_entry.edit.latitude' -%> <%= f.text_field :latitude, :size => 20, :id => "latitude" %> <%= t 'diary_entry.edit.longitude' -%> <%= f.text_field :longitude, :size => 20, :id => "longitude" %> - <%= t 'diary_entry.edit.use_map_link' -%> + <%= t 'diary_entry.edit.use_map_link' -%>