1
Fork 0
treehouse/static/js/emoji.js

32 lines
862 B
JavaScript
Raw Normal View History

2023-08-28 22:11:18 +02:00
// Emoji zoom-in functionality.
2024-03-03 21:23:37 +01:00
import { addSpell } from "treehouse/spells.js";
import { attachTooltip, Tooltip } from "treehouse/overlay.js";
2024-03-03 21:23:37 +01:00
function createEmojiTooltip(emoji, element) {
let tooltip = new Tooltip(element, "bottom");
tooltip.classList.add("tooltip-emoji");
2024-02-20 21:50:24 +01:00
let img = tooltip.appendChild(new Image());
img.src = element.src;
2024-02-20 21:50:24 +01:00
let description = tooltip.appendChild(document.createElement("p"));
description.textContent = emoji.emojiName;
2024-02-20 21:50:24 +01:00
return tooltip;
2024-02-20 21:50:24 +01:00
}
2024-03-03 21:23:37 +01:00
class Emoji {
constructor(element) {
this.emojiName = element.title;
2023-08-28 22:11:18 +02:00
2024-02-20 21:50:24 +01:00
// title makes the browser add a tooltip. We replace browser tooltips with our own,
// so remove the title.
2024-03-03 21:23:37 +01:00
element.title = "";
2024-02-20 21:50:24 +01:00
attachTooltip(element, () => createEmojiTooltip(this, element)).showOnHover();
2023-08-28 22:11:18 +02:00
}
}
2024-03-03 21:23:37 +01:00
addSpell("emoji", Emoji);