From: Andy Allan Date: Wed, 14 Aug 2024 13:38:28 +0000 (+0100) Subject: Merge pull request #5056 from AntonKhorev/diary-og-description X-Git-Tag: live~1025 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/735a5cf9e25b81d03db80ca4393aa34ea74d612a?hp=5f4ae358140bbfce2c5648a556aeb7a55f89536e Merge pull request #5056 from AntonKhorev/diary-og-description Set og:description meta tag to diary entry description --- diff --git a/Gemfile.lock b/Gemfile.lock index 00984911c..4cb7d0729 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -95,8 +95,8 @@ GEM autoprefixer-rails (10.4.19.0) execjs (~> 2) aws-eventstream (1.3.0) - aws-partitions (1.962.0) - aws-sdk-core (3.201.3) + aws-partitions (1.963.0) + aws-sdk-core (3.201.4) aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.651.0) aws-sigv4 (~> 1.8) @@ -152,7 +152,7 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - concurrent-ruby (1.3.3) + concurrent-ruby (1.3.4) config (5.5.1) deep_merge (~> 1.2, >= 1.2.1) connection_pool (2.4.1) @@ -403,8 +403,8 @@ GEM actionpack (>= 4.2) omniauth (~> 2.0) openstreetmap-deadlock_retry (1.3.1) - parallel (1.25.1) - parser (3.3.4.0) + parallel (1.26.2) + parser (3.3.4.2) ast (~> 2.4.1) racc pg (1.5.7) @@ -485,7 +485,7 @@ GEM io-console (~> 0.5) request_store (1.7.0) rack (>= 1.4) - rexml (3.3.4) + rexml (3.3.5) strscan rinku (2.0.6) rotp (6.3.0) diff --git a/app/assets/javascripts/index/directions-endpoint.js b/app/assets/javascripts/index/directions-endpoint.js new file mode 100644 index 000000000..0f53e77d9 --- /dev/null +++ b/app/assets/javascripts/index/directions-endpoint.js @@ -0,0 +1,84 @@ +OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, geocodeCallback) { + var endpoint = {}; + + endpoint.marker = L.marker([0, 0], { + icon: L.icon({ + iconUrl: iconUrl, + iconSize: [25, 41], + iconAnchor: [12, 41], + popupAnchor: [1, -34], + shadowUrl: OSM.MARKER_SHADOW, + shadowSize: [41, 41] + }), + draggable: true, + autoPan: true + }); + + endpoint.marker.on("drag dragend", function (e) { + endpoint.setLatLng(e.target.getLatLng()); + dragCallback(e.type === "drag"); + }); + + input.on("keydown", function () { + input.removeClass("is-invalid"); + }); + + input.on("change", function (e) { + // make text the same in both text boxes + var value = e.target.value; + endpoint.setValue(value); + }); + + endpoint.setValue = function (value, latlng) { + endpoint.value = value; + delete endpoint.latlng; + input.removeClass("is-invalid"); + input.val(value); + + if (latlng) { + endpoint.setLatLng(latlng); + } else { + endpoint.getGeocode(); + } + }; + + endpoint.getGeocode = function () { + // if no one has entered a value yet, then we can't geocode, so don't + // even try. + if (!endpoint.value) { + return; + } + + endpoint.awaitingGeocode = true; + + var viewbox = map.getBounds().toBBoxString(); // ,,, + + $.getJSON(OSM.NOMINATIM_URL + "search?q=" + encodeURIComponent(endpoint.value) + "&format=json&viewbox=" + viewbox, function (json) { + endpoint.awaitingGeocode = false; + endpoint.hasGeocode = true; + if (json.length === 0) { + input.addClass("is-invalid"); + alert(I18n.t("javascripts.directions.errors.no_place", { place: endpoint.value })); + return; + } + + endpoint.setLatLng(L.latLng(json[0])); + + input.val(json[0].display_name); + + geocodeCallback(); + }); + }; + + endpoint.setLatLng = function (ll) { + var precision = OSM.zoomPrecision(map.getZoom()); + input.val(ll.lat.toFixed(precision) + ", " + ll.lng.toFixed(precision)); + endpoint.hasGeocode = true; + endpoint.latlng = ll; + endpoint.marker + .setLatLng(ll) + .addTo(map); + }; + + return endpoint; +}; diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index ae01cb566..ccd4a68c2 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -1,9 +1,10 @@ +//= require ./directions-endpoint //= require_self //= require_tree ./directions //= require qs/dist/qs OSM.Directions = function (map) { - var awaitingRoute; // true if we've asked the engine for a route and are waiting to hear back + var routeRequest = null; // jqXHR object of an ongoing route request or null var chosenEngine; var popup = L.popup({ autoPanPadding: [100, 100] }); @@ -21,17 +22,19 @@ OSM.Directions = function (map) { }); var endpointDragCallback = function (dragging) { - if (map.hasLayer(polyline)) { - getRoute(false, !dragging); - } + if (!map.hasLayer(polyline)) return; + if (dragging && !chosenEngine.draggable) return; + if (dragging && routeRequest) return; + + getRoute(false, !dragging); }; var endpointGeocodeCallback = function () { getRoute(true, true); }; var endpoints = [ - Endpoint($("input[name='route_from']"), OSM.MARKER_GREEN, endpointDragCallback, endpointGeocodeCallback), - Endpoint($("input[name='route_to']"), OSM.MARKER_RED, endpointDragCallback, endpointGeocodeCallback) + OSM.DirectionsEndpoint(map, $("input[name='route_from']"), OSM.MARKER_GREEN, endpointDragCallback, endpointGeocodeCallback), + OSM.DirectionsEndpoint(map, $("input[name='route_to']"), OSM.MARKER_RED, endpointDragCallback, endpointGeocodeCallback) ]; var expiry = new Date(); @@ -51,94 +54,6 @@ OSM.Directions = function (map) { select.append(""); }); - function Endpoint(input, iconUrl, dragCallback, geocodeCallback) { - var endpoint = {}; - - endpoint.marker = L.marker([0, 0], { - icon: L.icon({ - iconUrl: iconUrl, - iconSize: [25, 41], - iconAnchor: [12, 41], - popupAnchor: [1, -34], - shadowUrl: OSM.MARKER_SHADOW, - shadowSize: [41, 41] - }), - draggable: true, - autoPan: true - }); - - endpoint.marker.on("drag dragend", function (e) { - var dragging = (e.type === "drag"); - if (dragging && !chosenEngine.draggable) return; - if (dragging && awaitingRoute) return; - endpoint.setLatLng(e.target.getLatLng()); - dragCallback(dragging); - }); - - input.on("keydown", function () { - input.removeClass("is-invalid"); - }); - - input.on("change", function (e) { - // make text the same in both text boxes - var value = e.target.value; - endpoint.setValue(value); - }); - - endpoint.setValue = function (value, latlng) { - endpoint.value = value; - delete endpoint.latlng; - input.removeClass("is-invalid"); - input.val(value); - - if (latlng) { - endpoint.setLatLng(latlng); - } else { - endpoint.getGeocode(); - } - }; - - endpoint.getGeocode = function () { - // if no one has entered a value yet, then we can't geocode, so don't - // even try. - if (!endpoint.value) { - return; - } - - endpoint.awaitingGeocode = true; - - var viewbox = map.getBounds().toBBoxString(); // ,,, - - $.getJSON(OSM.NOMINATIM_URL + "search?q=" + encodeURIComponent(endpoint.value) + "&format=json&viewbox=" + viewbox, function (json) { - endpoint.awaitingGeocode = false; - endpoint.hasGeocode = true; - if (json.length === 0) { - input.addClass("is-invalid"); - alert(I18n.t("javascripts.directions.errors.no_place", { place: endpoint.value })); - return; - } - - endpoint.setLatLng(L.latLng(json[0])); - - input.val(json[0].display_name); - - geocodeCallback(); - }); - }; - - endpoint.setLatLng = function (ll) { - var precision = OSM.zoomPrecision(map.getZoom()); - input.val(ll.lat.toFixed(precision) + ", " + ll.lng.toFixed(precision)); - endpoint.hasGeocode = true; - endpoint.latlng = ll; - endpoint.marker - .setLatLng(ll) - .addTo(map); - }; - - return endpoint; - } - $(".directions_form .reverse_directions").on("click", function () { var coordFrom = endpoints[0].latlng, coordTo = endpoints[1].latlng, @@ -202,7 +117,7 @@ OSM.Directions = function (map) { function getRoute(fitRoute, reportErrors) { // Cancel any route that is already in progress - if (awaitingRoute) awaitingRoute.abort(); + if (routeRequest) routeRequest.abort(); // go fetch geocodes for any endpoints which have not already // been geocoded. @@ -236,8 +151,8 @@ OSM.Directions = function (map) { $("#sidebar_content").html($(".directions_form .loader_copy").html()); map.setSidebarOverlaid(false); - awaitingRoute = chosenEngine.getRoute([o, d], function (err, route) { - awaitingRoute = null; + routeRequest = chosenEngine.getRoute([o, d], function (err, route) { + routeRequest = null; if (err) { map.removeLayer(polyline); diff --git a/app/assets/javascripts/leaflet.layers.js b/app/assets/javascripts/leaflet.layers.js index 55d492b29..82efab506 100644 --- a/app/assets/javascripts/leaflet.layers.js +++ b/app/assets/javascripts/leaflet.layers.js @@ -22,7 +22,7 @@ L.OSM.layers = function (options) { .prop("checked", map.hasLayer(layer)) .appendTo(buttonContainer); - var item = $("