]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1533269 - Tooltip displayed at wrong position when page is zoomed or scrolled...
authorKohei Yoshino <kohei.yoshino@gmail.com>
Thu, 25 Jul 2019 16:36:49 +0000 (12:36 -0400)
committerGitHub <noreply@github.com>
Thu, 25 Jul 2019 16:36:49 +0000 (12:36 -0400)
extensions/BugModal/web/bug_modal.js

index a0f33fac7968c9478ac96dbc006c358cd47bd113..f6593f509c853c62518ffd35b5619f319e1f1730 100644 (file)
@@ -212,10 +212,36 @@ $(function() {
         });
 
     // use non-native tooltips for relative/absolute times and bug summaries
-    $('.rel-time, .rel-time-title, .abs-time-title, .bz_bug_link, .tt').tooltip({
+    const tooltip_sources = $('.rel-time, .rel-time-title, .abs-time-title, .bz_bug_link, .tt').tooltip({
         position: { my: "left top+8", at: "left bottom", collision: "flipfit" },
         show: { effect: 'none' },
         hide: { effect: 'none' }
+    }).on('tooltipopen', function(event, ui) {
+        const $this = $(this);
+        const $parent = $this.offsetParent();
+        const { top, left } = $this.position();
+        const right_margin = $parent.width() - left;
+        const flip = right_margin < 250;
+
+        // Move the tooltip from `<body>` to a proper parent and position
+        // because the tooltip `position` option doesn't accept `within` for
+        // some reason
+        ui.tooltip
+          .appendTo($parent)
+          .css({
+            top: `${parseInt(top + $this.height() + 4)}px`,
+            right: flip ? `${parseInt(right_margin - $this.width())}px` : 'auto',
+            left: flip ? 'auto' : `${parseInt(left)}px`,
+          });
+    });
+
+    // Don't show the tooltip when the window gets focus
+    window.addEventListener('focus', event => {
+      // Temporarily disable the tooltip and enable it again
+      tooltip_sources.tooltip('option', 'disabled', true);
+      window.setTimeout(() => {
+        tooltip_sources.tooltip('option', 'disabled', false);
+      }, 150);
     });
 
     // tooltips create a new ui-helper-hidden-accessible div each time a