Files
OpenVPN-Monitoring-Simple/APP_UI/src/directives/noteTooltip.js
T

37 lines
991 B
JavaScript
Raw Normal View History

import { Tooltip } from 'bootstrap';
// v-note-tooltip="text": Bootstrap tooltip with the profile note.
// No tooltip for an empty value; plain text only (html: false).
const create = (el, text) => {
el._noteTooltip = new Tooltip(el, {
title: text,
placement: 'top',
container: 'body',
html: false,
trigger: 'hover',
customClass: 'note-tooltip'
});
};
const destroy = (el) => {
el._noteTooltip?.dispose();
el._noteTooltip = null;
};
// Hide on click: the row click opens the details modal
const hideOnClick = (el) => el._noteTooltip?.hide();
export default {
mounted(el, binding) {
el.addEventListener('click', () => hideOnClick(el));
if (binding.value) create(el, binding.value);
},
updated(el, binding) {
if (binding.value === binding.oldValue) return;
destroy(el);
if (binding.value) create(el, binding.value);
},
unmounted(el) {
destroy(el);
}
};