Yassine Doghri e0da11517d refactor: update js files to typescript and replace parcel with rollup
- add basic rollup config to bundle minified and browser compatible js
- use babel to transpile
typescript files to js
- add static code checkers: eslint and stylelint
- update package.json
scripts
- update DEPENDENCIES.md file to include rollup and popper
- set html in rss feed
description fields
- update Podcast and Episode entities to add description_html attribute
generated by parsing markdown to html using parsedown

#9
2020-10-15 14:41:12 +00:00

62 lines
1.7 KiB
TypeScript

import { createPopper, Placement } from "@popperjs/core";
const Tooltip = (): void => {
const tooltipContainers: NodeListOf<HTMLElement> = document.querySelectorAll(
"[data-toggle='tooltip']"
);
for (let i = 0; i < tooltipContainers.length; i++) {
const tooltipReference = tooltipContainers[i];
const tooltipContent = tooltipReference.title;
const tooltip = document.createElement("div");
tooltip.setAttribute("id", "tooltip");
tooltip.setAttribute(
"class",
"px-2 py-1 text-sm bg-gray-900 text-white rounded"
);
tooltip.innerHTML = tooltipContent;
const popper = createPopper(tooltipReference, tooltip, {
placement: tooltipReference.dataset.placement as Placement,
modifiers: [
{
name: "offset",
options: {
offset: [0, 8],
},
},
],
});
const show = () => {
tooltipReference.removeAttribute("title");
tooltipReference.setAttribute("aria-describedby", "tooltip");
document.body.appendChild(tooltip);
popper.update();
};
const hide = () => {
const element = document.getElementById("tooltip");
tooltipReference.removeAttribute("aria-describedby");
tooltipReference.setAttribute("title", tooltipContent);
if (element) {
document.body.removeChild(element);
}
};
const showEvents = ["mouseenter", "focus"];
const hideEvents = ["mouseleave", "blur"];
showEvents.forEach((event) => {
tooltipReference.addEventListener(event, show);
});
hideEvents.forEach((event) => {
tooltipReference.addEventListener(event, hide);
});
}
};
export default Tooltip;