From 79b9d32a2feccb50325108cff00805eb5f59afe0 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Tue, 27 May 2025 17:11:28 +0300 Subject: [PATCH] Add "Scroll to changeset" context menu item to history pages --- .../javascripts/index/history-changesets-layer.js | 15 ++++++++++++++- app/assets/javascripts/index/history.js | 4 ++++ config/locales/en.yml | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/index/history-changesets-layer.js b/app/assets/javascripts/index/history-changesets-layer.js index d65e8e276..4572b420b 100644 --- a/app/assets/javascripts/index/history-changesets-layer.js +++ b/app/assets/javascripts/index/history-changesets-layer.js @@ -5,7 +5,20 @@ OSM.HistoryChangesetBboxLayer = L.FeatureGroup.extend({ addChangesetLayer: function (changeset) { const style = this._getChangesetStyle(changeset); - const rectangle = L.rectangle(changeset.bounds, style); + const rectangle = L.rectangle(changeset.bounds, { + ...style, + contextmenu: true, + contextmenuItems: [{ + text: OSM.i18n.t("javascripts.context.scroll_to_changeset"), + callback: () => { + this.fire("requestscrolltochangeset", { id: changeset.id }, true); + }, + index: 0 + }, { + separator: true, + index: 1 + }] + }); rectangle.id = changeset.id; return this.addLayer(rectangle); }, diff --git a/app/assets/javascripts/index/history.js b/app/assets/javascripts/index/history.js index 3e6520d78..f3b2be170 100644 --- a/app/assets/javascripts/index/history.js +++ b/app/assets/javascripts/index/history.js @@ -28,6 +28,10 @@ OSM.History = function (map) { }) .on("click", function (e) { clickChangeset(e.layer.id, e.originalEvent); + }) + .on("requestscrolltochangeset", function (e) { + const [item] = $(`#changeset_${e.id}`); + item?.scrollIntoView({ block: "nearest", behavior: "smooth" }); }); let changesetIntersectionObserver; diff --git a/config/locales/en.yml b/config/locales/en.yml index 388f6adfd..e8ffb911b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3437,6 +3437,7 @@ en: show_address: Show address query_features: Query features centre_map: Centre map here + scroll_to_changeset: Scroll to changeset home: marker_title: My home location not_set: Home location is not set for your account -- 2.39.5