From d5bc5a5d4f946e3c61aaa72b43a88af8d82c8f05 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Apr 2023 00:28:29 +0200 Subject: [PATCH] Try a better implementation of ajax tooltip to avoid all on fast hover --- htdocs/core/js/lib_foot.js.php | 58 ++++++++++++++++++-------- htdocs/societe/class/societe.class.php | 2 +- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/htdocs/core/js/lib_foot.js.php b/htdocs/core/js/lib_foot.js.php index 7e300ddebc0..d8f1450d025 100644 --- a/htdocs/core/js/lib_foot.js.php +++ b/htdocs/core/js/lib_foot.js.php @@ -79,26 +79,48 @@ if (empty($conf->dol_no_mouse_hover)) { return $(this).prop("title"); /* To force to get title as is */ } }); - jQuery(".classforajaxtooltip").tooltip({ - show: { collision: "flipfit", effect:"toggle", delay:50, duration: 20 }, - hide: { delay: 250, duration: 20 }, + + var opendelay = 80; + var elemtostoretooltiptimer = jQuery("#dialogforpopup"); + + target = jQuery(".classforajaxtooltip"); + target.tooltip({ tooltipClass: "mytooltip", - open: function (event, ui) { - var elem = $(this); - var params = JSON.parse($(this).attr("data-params")); - var currenttoken = jQuery("meta[name=anti-csrf-currenttoken]").attr("content"); - params.token = currenttoken; + show: { collision: "flipfit", effect:"toggle", delay: 0, duration: 20 }, + hide: { delay: 250, duration: 20 } + }); + + target.off("mouseover mouseout"); + target.on("mouseover", function(event) { + console.log("we will create timer for ajax call"); + var params = JSON.parse($(this).attr("data-params")); + var elemfortooltip = $(this); + var currenttoken = jQuery("meta[name=anti-csrf-currenttoken]").attr("content"); + params.token = currenttoken; + + event.stopImmediatePropagation(); + clearTimeout(elemtostoretooltiptimer.data("openTimeoutId")); + elemtostoretooltiptimer.data("openTimeoutId", setTimeout(function() { + target.tooltip("close"); $.ajax({ - url:"'. DOL_URL_ROOT.'/core/ajax/ajaxtooltip.php", - type: "post", - async: false, - data: params, - success: function(response){ - // Setting content option - elem.tooltip("option","content",response); - } - }); - } + url:"'. DOL_URL_ROOT.'/core/ajax/ajaxtooltip.php", + type: "post", + async: true, + data: params, + success: function(response){ + // Setting content option + console.log("ajax success"); + elemfortooltip.tooltip("option","content",response); + elemfortooltip.tooltip("open"); + } + }); + }, opendelay)); + }); + target.on("mouseout", function(event) { + console.log("mouse out"); + event.stopImmediatePropagation(); + clearTimeout(elemtostoretooltiptimer.data("openTimeoutId")); + target.tooltip("close"); }); '; } diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index f85f03cf8d8..402d649b9bb 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -2917,7 +2917,7 @@ class Societe extends CommonObject $result .= $linkstart; if ($withpicto) { - $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams.' class="'.(($withpicto != 2) ? 'paddingright ' : '').$classfortooltip.'"'), 0, 0, $notooltip ? 0 : 1); + $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams.' class="'.(($withpicto != 2) ? 'paddingright' : '').'"'), 0, 0, $notooltip ? 0 : 1); } if ($withpicto != 2) { $result .= dol_escape_htmltag($maxlen ? dol_trunc($name, $maxlen) : $name);