| Server IP : 192.241.186.36 / Your IP : 216.73.216.164 Web Server : Apache/2.4.29 (Ubuntu) System : Linux webserver7 4.15.0-194-generic #205-Ubuntu SMP Fri Sep 16 19:49:27 UTC 2022 x86_64 User : root ( 0) PHP Version : 7.4.32 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/adsonicdigital/wp-content/plugins/elementor/app/assets/js/molecules/ |
Upload File : |
import React, { useState, useEffect, useRef } from 'react';
import { arrayToClassName } from '../utils/utils';
export default function Tooltip( props ) {
const baseClassName = 'e-app-tooltip',
classes = [ baseClassName, props.className ],
childRef = useRef( null ),
isAborted = useRef( false ),
isManualControl = Object.prototype.hasOwnProperty.call( props, 'show' ),
[ isLibraryLoaded, setIsLibraryLoaded ] = useState( false ),
[ showTooltip, setShowTooltip ] = useState( false ),
directionsMap = {
top: 's',
right: 'w',
down: 'n',
left: 'e',
},
tipsyConfig = {
trigger: isManualControl ? 'manual' : 'hover',
gravity: directionsMap[ props.direction ],
offset: props.offset,
title() {
return props.title;
},
},
setTipsy = () => {
const $tooltipContainer = jQuery( childRef.current );
$tooltipContainer.tipsy( tipsyConfig );
if ( isManualControl ) {
const displayMode = showTooltip ? 'show' : 'hide';
$tooltipContainer.tipsy( displayMode );
}
};
useEffect( () => {
// In case that the component is disabled the tipsy library will not be loaded by default.
if ( ! props.disabled ) {
isAborted.current = false;
import(
/* webpackIgnore: true */
`${ elementorCommon.config.urls.assets }lib/tipsy/tipsy.min.js?ver=1.0.0`
).then( () => {
if ( ! isAborted.current ) {
if ( isLibraryLoaded ) {
setTipsy();
} else {
setIsLibraryLoaded( true );
}
}
} );
}
return () => {
if ( ! props.disabled ) {
// Aborting the current dynamic-import state update in case of re-render.
isAborted.current = true;
// Cleanup of existing tipsy element in case of re-render.
const nodes = document.querySelectorAll( '.tipsy' );
nodes[ nodes.length - 1 ].remove();
}
};
}, [ props.disabled ] );
useEffect( () => {
if ( isLibraryLoaded ) {
setTipsy();
}
}, [ isLibraryLoaded, showTooltip ] );
useEffect( () => {
// The "show" state should not be changed while the component is disabled.
if ( ! props.disabled && props.show !== showTooltip ) {
setShowTooltip( props.show );
}
}, [ props.show ] );
return (
<props.tag className={ arrayToClassName( classes ) } ref={ childRef }>
{ props.children }
</props.tag>
);
}
Tooltip.propTypes = {
className: PropTypes.string,
offset: PropTypes.number,
show: PropTypes.bool,
direction: PropTypes.oneOf( [ 'top', 'right', 'left', 'down' ] ),
tag: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
disabled: PropTypes.bool,
children: PropTypes.any,
};
Tooltip.defaultProps = {
className: '',
offset: 10,
direction: 'top',
disabled: false,
};