]> git.openstreetmap.org Git - rails.git/commitdiff
Fix zoom level related tooltips for layer checkboxes
authorAnton Khorev <tony29@yandex.ru>
Tue, 13 Sep 2022 01:20:57 +0000 (04:20 +0300)
committerAnton Khorev <tony29@yandex.ru>
Tue, 13 Sep 2022 01:20:57 +0000 (04:20 +0300)
app/assets/javascripts/leaflet.layers.js
test/system/site_test.rb

index d762696a18e556b4ffa5fb2548733ae9bd512251..f372b86cfbe5819886b78726d9b87f9651fa1e5b 100644 (file)
@@ -98,11 +98,15 @@ L.OSM.layers = function (options) {
 
       var addOverlay = function (layer, name, maxArea) {
         var item = $("<li>")
-          .tooltip({
-            placement: "top"
-          })
           .appendTo(overlays);
 
+        var tooltip;
+        if (name === "notes" || name === "data") {
+          item.attr("title", I18n.t("javascripts.site.map_" + name + "_zoom_in_tooltip"));
+          tooltip = new bootstrap.Tooltip(item[0]);
+          tooltip.disable();
+        }
+
         var label = $("<label>")
           .attr("class", "form-check-label")
           .appendTo(item);
@@ -145,8 +149,13 @@ L.OSM.layers = function (options) {
           }
 
           $(item).attr("class", disabled ? "disabled" : "");
-          item.attr("data-bs-original-title", disabled ? // has additional bug when zooming out from enabled state
-            I18n.t("javascripts.site.map_" + name + "_zoom_in_tooltip") : "");
+          if (tooltip) {
+            if (disabled) {
+              tooltip.enable();
+            } else {
+              tooltip.disable();
+            }
+          }
         });
       };
 
index 2809feb93bc3a2f16d4566109ce4d7c713dbfcb9..f918b897aa529ff1d05b789446db2041db121087 100644 (file)
@@ -62,4 +62,18 @@ class SiteTest < ApplicationSystemTestCase
       assert_selector ".tooltip", :text => "Zoom in"
     end
   end
+
+  test "notes layer tooltip appears on zoom out" do
+    visit "/#map=9/40/-4" # depends on zoom levels where notes are allowed
+    find(".control-layers .control-button").click
+    li = find(".layers-ui .overlay-layers li:first-child")
+    li.not_matches_css? ".disabled"
+    li.hover # try to trigger disabled tooltip
+    zoomout = find(".control-button.zoomout")
+    zoomout.hover # un-hover the tooltip that's being tested
+    zoomout.click
+    li.matches_css? ".disabled"
+    li.hover
+    assert_selector ".tooltip", :text => "Zoom in"
+  end
 end