]> git.openstreetmap.org Git - rails.git/commitdiff
Eliminate templating from most javascript
authorTom Hughes <tom@compton.nu>
Mon, 23 Feb 2015 21:18:39 +0000 (21:18 +0000)
committerTom Hughes <tom@compton.nu>
Mon, 23 Feb 2015 21:45:57 +0000 (21:45 +0000)
app/assets/javascripts/embed.js [moved from app/assets/javascripts/embed.js.erb with 89% similarity]
app/assets/javascripts/index/directions.js [moved from app/assets/javascripts/index/directions.js.erb with 96% similarity]
app/assets/javascripts/index/new_note.js [moved from app/assets/javascripts/index/new_note.js.erb with 95% similarity]
app/assets/javascripts/index/note.js [moved from app/assets/javascripts/index/note.js.erb with 94% similarity]
app/assets/javascripts/index/notes.js [moved from app/assets/javascripts/index/notes.js.erb with 92% similarity]
app/assets/javascripts/leaflet.map.js [moved from app/assets/javascripts/leaflet.map.js.erb with 95% similarity]
app/assets/javascripts/osm.js.erb

similarity index 89%
rename from app/assets/javascripts/embed.js.erb
rename to app/assets/javascripts/embed.js
index 59ef7f070294aa23caf8b65caf6c6633e6e311c7..ba734706b8bfc2413f88da96b86b1b4e31df6158 100644 (file)
@@ -28,10 +28,10 @@ window.onload = function () {
 
   if (args.marker) {
     L.marker(args.marker.split(','), {icon: L.icon({
-      iconUrl: <%= asset_path('images/marker-icon.png').to_json %>,
+      iconUrl: OSM.MARKER_ICON,
       iconSize: new L.Point(25, 41),
       iconAnchor: new L.Point(12, 41),
-      shadowUrl: <%= asset_path('images/marker-shadow.png').to_json %>,
+      shadowUrl: OSM.MARKER_SHADOW,
       shadowSize: new L.Point(41, 41)
     })}).addTo(map);
   }
similarity index 96%
rename from app/assets/javascripts/index/directions.js.erb
rename to app/assets/javascripts/index/directions.js
index faa9226358f6ca1471f98a7b8788dc386359defe..31144a54716ec8c7dd2a1ef54d6819de892555b6 100644 (file)
@@ -22,8 +22,8 @@ OSM.Directions = function (map) {
   });
 
   var endpoints = [
-    Endpoint($("input[name='route_from']"), <%= asset_path('marker-green.png').to_json %>),
-    Endpoint($("input[name='route_to']"),   <%= asset_path('marker-red.png').to_json %>)
+    Endpoint($("input[name='route_from']"), OSM.MARKER_GREEN),
+    Endpoint($("input[name='route_to']"), OSM.MARKER_RED)
   ];
 
   function Endpoint(input, iconUrl) {
@@ -35,7 +35,7 @@ OSM.Directions = function (map) {
         iconSize: [25, 41],
         iconAnchor: [12, 41],
         popupAnchor: [1, -34],
-        shadowUrl: <%= asset_path('images/marker-shadow.png').to_json %>,
+        shadowUrl: OSM.MARKER_SHADOW,
         shadowSize: [41, 41]
       }),
       draggable: true
@@ -73,7 +73,7 @@ OSM.Directions = function (map) {
 
       endpoint.awaitingGeocode = true;
 
-      $.getJSON(document.location.protocol + '<%= NOMINATIM_URL %>search?q=' + encodeURIComponent(endpoint.value) + '&format=json', function (json) {
+      $.getJSON(document.location.protocol + OSM.NOMINATIM_URL + 'search?q=' + encodeURIComponent(endpoint.value) + '&format=json', function (json) {
         endpoint.awaitingGeocode = false;
         endpoint.hasGeocode = true;
         if (json.length == 0) {
similarity index 95%
rename from app/assets/javascripts/index/new_note.js.erb
rename to app/assets/javascripts/index/new_note.js
index 9990da7836c366830edb216b614a2a5e5ebf6634..4fe3fcaeb93c65aaba07edb9281850fdfe1f66ec 100644 (file)
@@ -8,17 +8,17 @@ OSM.NewNote = function(map) {
 
   var noteIcons = {
     "new": L.icon({
-      iconUrl: "<%= image_path 'new_note_marker.png' %>",
+      iconUrl: OSM.NEW_NOTE_MARKER,
       iconSize: [25, 40],
       iconAnchor: [12, 40]
     }),
     "open": L.icon({
-      iconUrl: "<%= image_path 'open_note_marker.png' %>",
+      iconUrl: OSM.OPEN_NOTE_MARKER,
       iconSize: [25, 40],
       iconAnchor: [12, 40]
     }),
     "closed": L.icon({
-      iconUrl: "<%= image_path 'closed_note_marker.png' %>",
+      iconUrl: OSM.CLOSED_NOTE_MARKER,
       iconSize: [25, 40],
       iconAnchor: [12, 40]
     })
similarity index 94%
rename from app/assets/javascripts/index/note.js.erb
rename to app/assets/javascripts/index/note.js
index 2c9e42210008bf6b1653d5d530233d114090e51e..2d4a8decff96e87ece810aa4c506e00a8c3eea6c 100644 (file)
@@ -6,17 +6,17 @@ OSM.Note = function (map) {
 
   var noteIcons = {
     "new": L.icon({
-      iconUrl: "<%= image_path('new_note_marker.png') %>",
+      iconUrl: OSM.NEW_NOTE_MARKER,
       iconSize: [25, 40],
       iconAnchor: [12, 40]
     }),
     "open": L.icon({
-      iconUrl: "<%= image_path('open_note_marker.png') %>",
+      iconUrl: OSM.OPEN_NOTE_MARKER,
       iconSize: [25, 40],
       iconAnchor: [12, 40]
     }),
     "closed": L.icon({
-      iconUrl: "<%= image_path('closed_note_marker.png') %>",
+      iconUrl: OSM.CLOSED_NOTE_MARKER,
       iconSize: [25, 40],
       iconAnchor: [12, 40]
     })
similarity index 92%
rename from app/assets/javascripts/index/notes.js.erb
rename to app/assets/javascripts/index/notes.js
index 4e45cbe05238b092f88559e930fc9d01f28bb73f..524b0b55f81adfc5d4fdc6eaa7dcfbe1098ca339 100644 (file)
@@ -4,17 +4,17 @@ function initializeNotes(map) {
 
   var noteIcons = {
     "new": L.icon({
-      iconUrl: "<%= image_path 'new_note_marker.png' %>",
+      iconUrl: OSM.NEW_NOTE_MARKER,
       iconSize: [25, 40],
       iconAnchor: [12, 40]
     }),
     "open": L.icon({
-      iconUrl: "<%= image_path 'open_note_marker.png' %>",
+      iconUrl: OSM.OPEN_NOTE_MARKER,
       iconSize: [25, 40],
       iconAnchor: [12, 40]
     }),
     "closed": L.icon({
-      iconUrl: "<%= image_path 'closed_note_marker.png' %>",
+      iconUrl: OSM.CLOSED_NOTE_MARKER,
       iconSize: [25, 40],
       iconAnchor: [12, 40]
     })
similarity index 95%
rename from app/assets/javascripts/leaflet.map.js.erb
rename to app/assets/javascripts/leaflet.map.js
index 14cddafce7ca6001026981991d8df91df8702e1e..2201afe68a83baa73cd891fa43162980e7aa327c 100644 (file)
@@ -261,9 +261,9 @@ L.OSM.Map = L.Map.extend({
 L.Icon.Default.imagePath = "/images";
 
 L.Icon.Default.imageUrls = {
-  "/images/marker-icon.png": "<%= asset_path("images/marker-icon.png") %>",
-  "/images/marker-icon-2x.png": "<%= asset_path("images/marker-icon-2x.png") %>",
-  "/images/marker-shadow.png": "<%= asset_path("images/marker-shadow.png") %>"
+  "/images/marker-icon.png": OSM.MARKER_ICON,
+  "/images/marker-icon-2x.png": OSM.MARKER_ICON_2X,
+  "/images/marker-shadow.png": OSM.MARKER_SHADOW
 };
 
 L.extend(L.Icon.Default.prototype, {
@@ -277,11 +277,11 @@ L.extend(L.Icon.Default.prototype, {
 
 function getUserIcon(url) {
   return L.icon({
-    iconUrl: url || <%= asset_path('marker-red.png').to_json %>,
+    iconUrl: url || OSM.MARKER_RED,
     iconSize: [25, 41],
     iconAnchor: [12, 41],
     popupAnchor: [1, -34],
-    shadowUrl: <%= asset_path('images/marker-shadow.png').to_json %>,
+    shadowUrl: OSM.MARKER_SHADOW,
     shadowSize: [41, 41]
   });
 }
index 15c1682d5f0e14e925a8c5a4496da16ff577dc02..d933043b54298141ac41db1bee9c57115aa297c5 100644 (file)
@@ -9,6 +9,17 @@ OSM = {
   STATUS:                <%= STATUS.to_json %>,
   MAX_NOTE_REQUEST_AREA: <%= MAX_NOTE_REQUEST_AREA.to_json %>,
   OVERPASS_URL:          <%= OVERPASS_URL.to_json %>,
+  NOMINATIM_URL:         <%= NOMINATIM_URL.to_json %>,
+
+  MARKER_GREEN:          <%= image_path("marker-green.png").to_json %>,
+  MARKER_RED:            <%= image_path("marker-red.png").to_json %>,
+  MARKER_ICON:           <%= image_path("marker-icon.png").to_json %>,
+  MARKER_ICON_2X:        <%= image_path("marker-icon-2x.png").to_json %>,
+  MARKER_SHADOW:         <%= image_path("marker-shadow.png").to_json %>,
+
+  NEW_NOTE_MARKER:       <%= image_path("new_note_marker.png").to_json %>,
+  OPEN_NOTE_MARKER:      <%= image_path("open_note_marker.png").to_json %>,
+  CLOSED_NOTE_MARKER:    <%= image_path("closed_note_marker.png").to_json %>,
 
   apiUrl: function (object) {
     var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + object.id;