Try a better implementation of ajax tooltip to avoid all on fast hover

This commit is contained in:
Laurent Destailleur
2023-04-10 00:28:29 +02:00
parent 74d41c3d11
commit d5bc5a5d4f
2 changed files with 41 additions and 19 deletions

View File

@@ -79,26 +79,48 @@ if (empty($conf->dol_no_mouse_hover)) {
return $(this).prop("title"); /* To force to get title as is */ return $(this).prop("title"); /* To force to get title as is */
} }
}); });
jQuery(".classforajaxtooltip").tooltip({
show: { collision: "flipfit", effect:"toggle", delay:50, duration: 20 }, var opendelay = 80;
hide: { delay: 250, duration: 20 }, var elemtostoretooltiptimer = jQuery("#dialogforpopup");
target = jQuery(".classforajaxtooltip");
target.tooltip({
tooltipClass: "mytooltip", tooltipClass: "mytooltip",
open: function (event, ui) { show: { collision: "flipfit", effect:"toggle", delay: 0, duration: 20 },
var elem = $(this); hide: { delay: 250, duration: 20 }
var params = JSON.parse($(this).attr("data-params")); });
var currenttoken = jQuery("meta[name=anti-csrf-currenttoken]").attr("content");
params.token = currenttoken; 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({ $.ajax({
url:"'. DOL_URL_ROOT.'/core/ajax/ajaxtooltip.php", url:"'. DOL_URL_ROOT.'/core/ajax/ajaxtooltip.php",
type: "post", type: "post",
async: false, async: true,
data: params, data: params,
success: function(response){ success: function(response){
// Setting content option // Setting content option
elem.tooltip("option","content",response); 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");
}); });
'; ';
} }

View File

@@ -2917,7 +2917,7 @@ class Societe extends CommonObject
$result .= $linkstart; $result .= $linkstart;
if ($withpicto) { 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) { if ($withpicto != 2) {
$result .= dol_escape_htmltag($maxlen ? dol_trunc($name, $maxlen) : $name); $result .= dol_escape_htmltag($maxlen ? dol_trunc($name, $maxlen) : $name);