From 7f6320ed10ef13b11e4a1918d3f35340ac0ee545 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 5 Oct 2012 11:58:45 -0700 Subject: [PATCH] Move diary entry JS to page-specific script file --- app/assets/javascripts/diary_entry.js | 33 +++++++++++++++++++++ app/views/diary_entry/edit.html.erb | 42 +++------------------------ config/environments/production.rb | 2 +- 3 files changed, 38 insertions(+), 39 deletions(-) create mode 100644 app/assets/javascripts/diary_entry.js diff --git a/app/assets/javascripts/diary_entry.js b/app/assets/javascripts/diary_entry.js new file mode 100644 index 000000000..7dc988de7 --- /dev/null +++ b/app/assets/javascripts/diary_entry.js @@ -0,0 +1,33 @@ +var marker; + +function setLocation( e ) { + closeMapPopup(); + + var lonlat = getEventPosition(e); + + $("#latitude").val(lonlat.lat); + $("#longitude").val(lonlat.lon); + + if (marker) { + removeMarkerFromMap(marker); + } + + marker = addMarkerToMap(lonlat, null, I18n.t('diary_entry.edit.marker_text')); +} + +function openMap() { + $("#map").show(); + $("#usemap").hide(); + + var params = $("#map").data(); + var centre = new OpenLayers.LonLat(params.lon, params.lat); + var map = createMap("map"); + + setMapCenter(centre, params.zoom); + + if ($("#latitude").val() && $("#longitude").val()) { + marker = addMarkerToMap(centre, null, I18n.t('diary_entry.edit.marker_text')); + } + + 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 33e4d2719..e6674742f 100644 --- a/app/views/diary_entry/edit.html.erb +++ b/app/views/diary_entry/edit.html.erb @@ -1,3 +1,7 @@ +<% content_for :head do %> + <%= javascript_include_tag "diary_entry" %> +<% end %> +

<%= @title %>

<%= error_messages_for 'diary_entry' %> @@ -34,41 +38,3 @@ <% end %> - - diff --git a/config/environments/production.rb b/config/environments/production.rb index 518d712fa..f4602ce70 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -56,7 +56,7 @@ OpenStreetMap::Application.configure do # config.action_controller.asset_host = "http://assets.example.com" # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) - config.assets.precompile += %w( index.js edit.js browse.js changeset.js user.js pngfix.js swfobject.js ) + config.assets.precompile += %w( index.js edit.js browse.js changeset.js user.js diary_entry.js pngfix.js swfobject.js ) config.assets.precompile += %w( large-ltr.css small-ltr.css print-ltr.css ) config.assets.precompile += %w( large-rtl.css small-rtl.css print-rtl.css ) config.assets.precompile += %w( browse.css theme/openstreetmap/style.css ) -- 2.43.2