2
0
forked from Wavyzz/dolibarr

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 */
}
});
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");
});
';
}