mirror of
https://code.castopod.org/adaures/castopod
synced 2025-04-19 04:51:17 +00:00

- 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
62 lines
1.7 KiB
TypeScript
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;
|