From 84c8289e06c092ac987c2abe0d8394df3ab9630f Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Tue, 13 Sep 2022 05:26:49 +0300 Subject: [PATCH] Fix zoom level related tooltip for Edit button --- app/assets/javascripts/application.js | 15 +++++++++++---- test/system/site_test.rb | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 89f60847f..8b8beb5b4 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -57,15 +57,19 @@ window.updateLinks = function (loc, zoom, layers, object) { }); var editDisabled = zoom < 13; - $("#edit_tab") - .tooltip({ placement: "bottom" }) - .attr("data-bs-original-title", editDisabled ? - I18n.t("javascripts.site.edit_disabled_tooltip") : "") + var editTab = $("#edit_tab"); + editTab // Disable the button group and also the buttons to avoid // inconsistent behaviour when zooming .toggleClass("disabled", editDisabled) .find("a") .toggleClass("disabled", editDisabled); + var editTooltip = bootstrap.Tooltip.getOrCreateInstance(editTab[0], { placement: "bottom" }); + if (editDisabled) { + editTooltip.enable(); + } else { + editTooltip.disable(); + } }; window.maximiseMap = function () { @@ -77,6 +81,9 @@ window.minimiseMap = function () { }; $(document).ready(function () { + $("#edit_tab") + .attr("title", I18n.t("javascripts.site.edit_disabled_tooltip")); + var headerWidth = 0, compactWidth = 0; diff --git a/test/system/site_test.rb b/test/system/site_test.rb index f918b897a..0ed755a09 100644 --- a/test/system/site_test.rb +++ b/test/system/site_test.rb @@ -61,10 +61,24 @@ class SiteTest < ApplicationSystemTestCase find(selector).hover assert_selector ".tooltip", :text => "Zoom in" end + + test "no zoom-in tooltips on high zoom levels, then tooltips appear after zoom out for control '#{selector}'" do + visit "/#map=14/0/0" + + assert_no_selector ".tooltip" + find(selector).hover + assert_no_selector ".tooltip", :text => "Zoom in" + find("h1").hover # un-hover original element + + visit "/#map=10/0/0" + find(selector).hover + 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" -- 2.45.1