From 96c67a7ff7acc590bc4b1aced56ee0290cc1b589 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Mon, 7 Feb 2022 10:05:43 +0200 Subject: [PATCH] Fix empty content of tooltip after 'copy' action in docs (#35773) Co-authored-by: XhmikosR --- site/assets/js/application.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/site/assets/js/application.js b/site/assets/js/application.js index e2a464d3ce..6a8c63cbb6 100644 --- a/site/assets/js/application.js +++ b/site/assets/js/application.js @@ -118,7 +118,8 @@ } // Insert copy to clipboard button before .highlight - var btnHtml = '
' + var btnTitle = 'Copy to clipboard' + var btnHtml = '
' document.querySelectorAll('div.highlight') .forEach(function (element) { element.insertAdjacentHTML('beforebegin', btnHtml) @@ -126,7 +127,7 @@ document.querySelectorAll('.btn-clipboard') .forEach(function (btn) { - var tooltipBtn = new bootstrap.Tooltip(btn) + var tooltipBtn = new bootstrap.Tooltip(btn, { title: btnTitle }) btn.addEventListener('mouseleave', function () { // Explicitly hide tooltip, since after clicking it remains @@ -144,11 +145,10 @@ clipboard.on('success', function (event) { var tooltipBtn = bootstrap.Tooltip.getInstance(event.trigger) - var originalTitle = event.trigger.getAttribute('title') tooltipBtn.setContent({ '.tooltip-inner': 'Copied!' }) event.trigger.addEventListener('hidden.bs.tooltip', function () { - tooltipBtn.setContent({ '.tooltip-inner': originalTitle }) + tooltipBtn.setContent({ '.tooltip-inner': btnTitle }) }, { once: true }) event.clearSelection() }) @@ -157,11 +157,10 @@ var modifierKey = /mac/i.test(navigator.userAgent) ? '\u2318' : 'Ctrl-' var fallbackMsg = 'Press ' + modifierKey + 'C to copy' var tooltipBtn = bootstrap.Tooltip.getInstance(event.trigger) - var originalTitle = event.trigger.getAttribute('title') tooltipBtn.setContent({ '.tooltip-inner': fallbackMsg }) event.trigger.addEventListener('hidden.bs.tooltip', function () { - tooltipBtn.setContent({ '.tooltip-inner': originalTitle }) + tooltipBtn.setContent({ '.tooltip-inner': btnTitle }) }, { once: true }) })