tooltip.js updated

pull/3845/head
Furkan Sezis 2023-04-09 18:11:56 +03:00
parent 9cbbb79f9c
commit 70af953e9d
1 changed files with 63 additions and 25 deletions

View File

@ -47,54 +47,90 @@ function unbindScrollListener(el) {
} }
function onMouseEnter(event) { function onMouseEnter(event) {
show(event.currentTarget); const el = event.currentTarget;
const showDelay = el.$_ptooltipShowDelay;
show(event.currentTarget, showDelay);
} }
function onMouseLeave(event) { function onMouseLeave(event) {
hide(event.currentTarget); const el = event.currentTarget;
const hideDelay = el.$_ptooltipHideDelay;
hide(event.currentTarget, hideDelay);
} }
function onFocus(event) { function onFocus(event) {
show(event.currentTarget); const el = event.currentTarget;
const showDelay = el.$_ptooltipShowDelay;
console.log('focus', showDelay);
show(event.currentTarget, showDelay);
} }
function onBlur(event) { function onBlur(event) {
hide(event.currentTarget); const el = event.currentTarget;
const hideDelay = el.$_ptooltipHideDelay;
hide(event.currentTarget, hideDelay);
} }
function onClick(event) { function onClick(event) {
hide(event.currentTarget); const el = event.currentTarget;
const hideDelay = el.$_ptooltipHideDelay;
hide(event.currentTarget, hideDelay);
} }
function onKeydown(event) { function onKeydown(event) {
event.code === 'Escape' && hide(event.currentTarget); event.code === 'Escape' && hide(event.currentTarget, hideDelay);
} }
function show(el) { let timer;
if (el.$_ptooltipDisabled) {
return;
}
let tooltipElement = create(el); function show(el, showDelay) {
function tooltipActions() {
align(el); if (el.$_ptooltipDisabled) {
DomHandler.fadeIn(tooltipElement, 250); return;
window.addEventListener('resize', function onWindowResize() {
if (!DomHandler.isTouchDevice()) {
hide(el);
} }
this.removeEventListener('resize', onWindowResize); let tooltipElement = create(el);
});
bindScrollListener(el); align(el);
ZIndexUtils.set('tooltip', tooltipElement, el.$_ptooltipZIndex); DomHandler.fadeIn(tooltipElement, 250);
window.addEventListener('resize', function onWindowResize() {
if (!DomHandler.isTouchDevice()) {
hide(el);
}
this.removeEventListener('resize', onWindowResize);
});
bindScrollListener(el);
ZIndexUtils.set('tooltip', tooltipElement, el.$_ptooltipZIndex);
}
if (showDelay !== undefined) {
timer = setTimeout(tooltipActions, showDelay);
} else {
tooltipActions();
}
} }
function hide(el) { function hide(el, hideDelay) {
remove(el); function tooltipRemoval() {
unbindScrollListener(el); remove(el);
unbindScrollListener(el);
}
clearTimeout(timer);
if (hideDelay !== undefined) {
setTimeout(tooltipRemoval, hideDelay);
} else {
tooltipRemoval();
}
} }
function getTooltipElement(el) { function getTooltipElement(el) {
@ -332,6 +368,8 @@ const Tooltip = {
target.$_ptooltipClass = options.value.class; target.$_ptooltipClass = options.value.class;
target.$_ptooltipFitContent = !!options.value.fitContent === options.value.fitContent ? options.value.fitContent : true; target.$_ptooltipFitContent = !!options.value.fitContent === options.value.fitContent ? options.value.fitContent : true;
target.$_ptooltipIdAttr = options.value.id || ''; target.$_ptooltipIdAttr = options.value.id || '';
target.$_ptooltipShowDelay = options.value.showDelay || 0;
target.$_ptooltipHideDelay = options.value.hideDelay || 0;
} }
} }