N°2847 - Tooltip: Improve mechanism to instantiate them only once

This commit is contained in:
Molkobain
2020-10-22 14:08:45 +02:00
parent 91ee5ebfeb
commit d85d29155f
2 changed files with 13 additions and 3 deletions

View File

@@ -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));
});
});

View File

@@ -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');
}
};