/**
* Tooltip that automatically show and hide themselves on mouseenter and mouseleave events.
* Will also remove themselves if the node to watch is removed from DOM through
* a MutationObserver.
*
* Note this is not using Discord's internals but normal DOM manipulation and emulates
* Discord's own tooltips as closely as possible.
*
* @module EmulatedTooltip
* @version 0.0.1
*/
import Utils from "../modules/utils";
import WebpackModules from "../modules/webpackModules";
import DOM from "../modules/domtools";
const TooltipClasses = WebpackModules.findByProps("tooltip", "tooltipBlack");
const TooltipLayers = WebpackModules.findByProps("layer", "layerContainer");
const getClass = function(sideOrColor) {
const upperCase = sideOrColor[0].toUpperCase() + sideOrColor.slice(1);
const tooltipClass = TooltipClasses[`tooltip${upperCase}`];
if (tooltipClass) return tooltipClass;
return null;
};
const classExists = function(sideOrColor) {
return getClass(sideOrColor) ? true : false;
};
const toPx = function(value) {
return `${value}px`;
};
/*
*/
export default class EmulatedTooltip {
/**
*
* @constructor
* @param {(HTMLElement|jQuery)} node - DOM node to monitor and show the tooltip on
* @param {string} tip - string to show in the tooltip
* @param {object} options - additional options for the tooltip
* @param {string} [options.style=black] - correlates to the discord styling/colors (black, brand, green, grey, red, yellow)
* @param {string} [options.side=top] - can be any of top, right, bottom, left
* @param {boolean} [options.preventFlip=false] - prevents moving the tooltip to the opposite side if it is too big or goes offscreen
* @param {boolean} [options.disabled=false] - whether the tooltip should be disabled from showing on hover
*/
constructor(node, text, options = {}) {
const {style = "black", side = "top", preventFlip = false, disabled = false} = options;
this.node = node instanceof jQuery ? node[0] : node;
this.label = text;
this.style = style.toLowerCase();
this.side = side.toLowerCase();
this.preventFlip = preventFlip;
this.disabled = disabled;
if (!classExists(this.side)) return Utils.err("EmulatedTooltip", `Side ${this.side} does not exist.`);
if (!classExists(this.style)) return Utils.err("EmulatedTooltip", `Style ${this.style} does not exist.`);
this.element = DOM.createElement(`