From 95a2ffa0f23ea18eac5d5bd2ba83e41ddf8b8034 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Thu, 22 Oct 2020 21:29:53 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B02224=20-=20Portal:=20Enable=20tooltips?= =?UTF-8?q?=20for=20object's=20attributes=20description=20in=20dynamically?= =?UTF-8?q?=20added=20content=20as=20well=20(AJAX,=20forms,=20...)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../portal/templates/layout.html.twig | 15 ++++++++++++--- js/utils.js | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/datamodels/2.x/itop-portal-base/portal/templates/layout.html.twig b/datamodels/2.x/itop-portal-base/portal/templates/layout.html.twig index 34ba1a8eb..f1c429f4d 100644 --- a/datamodels/2.x/itop-portal-base/portal/templates/layout.html.twig +++ b/datamodels/2.x/itop-portal-base/portal/templates/layout.html.twig @@ -509,9 +509,18 @@ } }); - // Enable tooltips based on existing HTML markup, won't work on markup added dynamically after DOM ready (AJAX, ...) - $('[data-tooltip-content]:not([data-tooltip-instanciated="true"])').each(function(){ - CombodoGlobalToolbox.InitTooltipFromMarkup($(this)); + // Enable tooltips based on existing HTML markup, won't work on markup added dynamically after DOM ready (AJAX, ...) ... + CombodoGlobalToolbox.InitAllNonInstantiatedTooltips(); + // ... except for object form which are handled with the following ... + $('body').on('form_built', function(oEvent){ + CombodoGlobalToolbox.InitAllNonInstantiatedTooltips($(oEvent.target)); + }); + // ... and BS modals which are handle with the following + $('body').on('loaded.bs.modal', function (oEvent){ + // Little timeout for stuff that need a moment to get ready but don't have a proper event. + setTimeout(function(){ + //CombodoGlobalToolbox.InitAllNonInstantiatedTooltips($(oEvent.target)); + }, 500); }); // Initialize confirmation message handler when a form with touched fields is closed diff --git a/js/utils.js b/js/utils.js index 4e91adb07..b08a39cab 100644 --- a/js/utils.js +++ b/js/utils.js @@ -882,5 +882,23 @@ const CombodoGlobalToolbox = { // Mark tooltip as instanciated oElem.attr('data-tooltip-instanciated', 'true'); + }, + /** + * Instantiate all tooltips that are not already. + * Useful after AJAX calls or dynamic content modification for examples. + * + * @param {Object} oContainerElem Tooltips will only be instantiated if they are contained within this jQuery object + * @constructor + */ + InitAllNonInstantiatedTooltips: function(oContainerElem = null) + { + if(oContainerElem === null) + { + oContainerElem = $('body'); + } + + oContainerElem.find('[data-tooltip-content]:not([data-tooltip-instanciated="true"])').each(function(){ + CombodoGlobalToolbox.InitTooltipFromMarkup($(this)); + }); } }; \ No newline at end of file