replace popperjs tooltip with html title attribute

~ to reduce the amount of javascript at the cost of ugly tooltips
This commit is contained in:
geoffrey45 2022-09-24 15:19:52 +03:00 committed by Mungai Njoroge
parent 61750f7126
commit a9f8cc63ea
2 changed files with 9 additions and 85 deletions

View File

@ -2,7 +2,7 @@
<div <div
class="songlist-item rounded-sm" class="songlist-item rounded-sm"
:class="[{ current: isCurrent }, { contexton: context_on }]" :class="[{ current: isCurrent }, { contexton: context_on }]"
@dblclick="emitUpdate(track)" @dblclick.prevent="emitUpdate"
@contextmenu.prevent="showMenu" @contextmenu.prevent="showMenu"
> >
<div class="index t-center ellip" @dblclick.prevent.stop="() => {}"> <div class="index t-center ellip" @dblclick.prevent.stop="() => {}">
@ -12,7 +12,7 @@
<HeartSvg /> <HeartSvg />
</div> </div>
<div class="flex"> <div class="flex">
<div @click="emitUpdate(track)" class="thumbnail"> <div @click.pre@dblclick.prevent="emitUpdate" class="thumbnail">
<img <img
loading="lazy" loading="lazy"
:src="imguri + track.image" :src="imguri + track.image"
@ -26,7 +26,7 @@
></div> ></div>
</div> </div>
<div v-tooltip class="song-title"> <div v-tooltip class="song-title">
<div class="title ellip" @click="emitUpdate(track)" ref="artisttitle"> <div class="title ellip" @click.pre@dblclick.prevent="emitUpdate" ref="artisttitle">
{{ track.title }} {{ track.title }}
</div> </div>
<div class="isSmallArtists" style="display: none"> <div class="isSmallArtists" style="display: none">
@ -95,17 +95,13 @@ const emit = defineEmits<{
(e: "playThis"): void; (e: "playThis"): void;
}>(); }>();
function emitUpdate(track: Track) { function emitUpdate() {
emit("playThis"); emit("playThis");
} }
function showMenu(e: Event) { function showMenu(e: Event) {
showContext(e, props.track, options_button_clicked); showContext(e, props.track, options_button_clicked);
} }
onUpdated(() => {
console.log(artisttitle.value);
});
</script> </script>
<style lang="scss"> <style lang="scss">

View File

@ -1,51 +1,3 @@
import { Directive } from "vue";
import { createPopper, Instance, VirtualElement } from "@popperjs/core";
let tooltip: HTMLElement;
let popperInstance: Instance;
let store: any;
// @ts-ignore
const virtualEl = {
getBoundingClientRect: () => new DOMRect(),
} as VirtualElement;
const getTooltip = () => document.getElementById("tooltip") as HTMLElement;
function getInstance() {
if (tooltip && virtualEl) {
return createPopper(virtualEl, getTooltip(), {
placement: "top",
modifiers: [
{
name: "offset",
options: {
offset: [0, 10],
},
},
{
name: "hide",
enabled: true,
},
{
name: "eventListeners",
enabled: false,
},
],
});
}
return null;
}
function showTooltip() {
tooltip.style.visibility = "visible";
}
function hideTooltip() {
tooltip.style.visibility = "hidden";
}
function getElFullWidth(el: HTMLElement) { function getElFullWidth(el: HTMLElement) {
el.style.display = "inline-block"; el.style.display = "inline-block";
el.style.visibility = "hidden"; el.style.visibility = "hidden";
@ -59,34 +11,10 @@ function getElFullWidth(el: HTMLElement) {
export default (el: HTMLElement) => { export default (el: HTMLElement) => {
const fullWidth = getElFullWidth(el.cloneNode(true) as HTMLElement); const fullWidth = getElFullWidth(el.cloneNode(true) as HTMLElement);
if (fullWidth <= el.offsetWidth) return; if (fullWidth <= el.offsetWidth) {
el.title = "";
if (!tooltip) { return;
tooltip = getTooltip();
} }
if (!popperInstance) { el.title = el.innerText;
popperInstance = getInstance() as Instance; };
}
let isHovered = false;
el.addEventListener("mouseover", () => {
isHovered = true;
setTimeout(() => {
if (!isHovered) return;
tooltip.innerText = el.innerText;
virtualEl.getBoundingClientRect = () => el.getBoundingClientRect();
popperInstance.update().then(showTooltip);
}, 1500);
});
["mouseout", "click"].forEach((event) => {
document.addEventListener(event, () => {
isHovered = false;
hideTooltip();
});
});
};