From d85d29155f38ca1d44801e6be1a629dcde3c02a4 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Thu, 22 Oct 2020 14:08:45 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B02847=20-=20Tooltip:=20Improve=20mechanis?= =?UTF-8?q?m=20to=20instantiate=20them=20only=20once?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/pages/backoffice/toolbox.js | 2 +- js/utils.js | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/js/pages/backoffice/toolbox.js b/js/pages/backoffice/toolbox.js index 256a6fc88..df7f11a1a 100644 --- a/js/pages/backoffice/toolbox.js +++ b/js/pages/backoffice/toolbox.js @@ -70,7 +70,7 @@ const CombodoBackofficeToolbox = { // Processing $(document).ready(function(){ // Enable tooltips based on existing HTML markup, won't work on markup added dynamically after DOM ready (AJAX, ...) - $('[data-tooltip-content]').each(function(){ + $('[data-tooltip-content]:not([data-tooltip-instanciated="true"])').each(function(){ CombodoGlobalToolbox.InitTooltipFromMarkup($(this)); }); }); \ No newline at end of file diff --git a/js/utils.js b/js/utils.js index 40681a645..e7ca41882 100644 --- a/js/utils.js +++ b/js/utils.js @@ -813,15 +813,22 @@ const CombodoGlobalToolbox = { * * Note: Content SHOULD be HTML entity encoded to avoid markup breaks (eg. when using a double quote in a sentence) * - * @param oElem + * @param {Object} oElem The jQuery object representing the element + * @param {boolean} bForce When set to true, tooltip will be instanciate even if one already exists, overwritting it. * @constructor */ - InitTooltipFromMarkup: function(oElem) + InitTooltipFromMarkup: function(oElem, bForce = false) { const oOptions = { allowHTML: true, // Always true so line breaks can work. Don't worry content will be sanitized. }; + // First, check if the tooltip isn't already instanciated + if((oElem.attr('data-tooltip-instanciated') === 'true') && (bForce === false)) + { + return false; + } + // Content must be reworked before getting into the tooltip // - Should we enable HTML content or keep text as is const bEnableHTML = oElem.attr('data-tooltip-html-enabled') === 'true'; @@ -870,5 +877,8 @@ const CombodoGlobalToolbox = { ]; tippy(oElem[0], oOptions); + + // Mark tooltip as instanciated + oElem.attr('data-tooltip-instanciated', 'true'); } }; \ No newline at end of file