X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/19a014bde6c8eb0c1b394fae8cf302487e7717b0..e6b0e1ae7ef45b87a61f18bb50296273d6dd1bfb:/app/assets/javascripts/leaflet.sidebar.js diff --git a/app/assets/javascripts/leaflet.sidebar.js b/app/assets/javascripts/leaflet.sidebar.js index 7e72278e3..910da53f2 100644 --- a/app/assets/javascripts/leaflet.sidebar.js +++ b/app/assets/javascripts/leaflet.sidebar.js @@ -1,7 +1,7 @@ L.OSM.sidebar = function (selector) { - var control = {}, - sidebar = $(selector), - current = $(), + const control = {}, + sidebar = $(selector); + let current = $(), currentButton = $(), map; @@ -17,7 +17,9 @@ L.OSM.sidebar = function (selector) { }; control.togglePane = function (pane, button) { - var paneWidth = 250; + const mediumDeviceWidth = window.getComputedStyle(document.documentElement).getPropertyValue("--bs-breakpoint-md"); + const isMediumDevice = window.matchMedia(`(max-width: ${mediumDeviceWidth})`).matches; + const paneWidth = 250; current .hide() @@ -27,16 +29,22 @@ L.OSM.sidebar = function (selector) { .removeClass("active"); if (current === pane) { - if ($("html").attr("dir") === "rtl") { - map.panBy([-paneWidth, 0], { animate: false }); - } $(sidebar).hide(); + $("#content").addClass("overlay-right-sidebar"); current = currentButton = $(); + if (isMediumDevice) { + map.panBy([0, -$("#map").height() / 2], { animate: false }); + } else if ($("html").attr("dir") === "rtl") { + map.panBy([-paneWidth, 0], { animate: false }); + } } else { $(sidebar).show(); + $("#content").removeClass("overlay-right-sidebar"); current = pane; currentButton = button || $(); - if ($("html").attr("dir") === "rtl") { + if (isMediumDevice) { + map.panBy([0, $("#map").height()], { animate: false }); + } else if ($("html").attr("dir") === "rtl") { map.panBy([paneWidth, 0], { animate: false }); } }