All-Resources/[ox]/ox_target/web/js/createOptions.js
2026-04-14 17:41:39 +02:00

31 lines
1005 B
JavaScript

import { fetchNui } from "./fetchNui.js";
const optionsWrapper = document.getElementById("options-wrapper");
function onClick() {
// when nuifocus is disabled after a click, the hover event is never released
this.style.pointerEvents = "none";
fetchNui("select", [this.targetType, this.targetId, this.zoneId]);
// is there a better way to handle this? probably
setTimeout(() => (this.style.pointerEvents = "auto"), 100);
}
export function createOptions(type, data, id, zoneId) {
if (data.hide) return;
const option = document.createElement("div");
const iconElement = `<i class="fa-fw ${data.icon} option-icon" ${
data.iconColor ? `style = color:${data.iconColor} !important` : null
}"></i>`;
option.innerHTML = `${iconElement}<p class="option-label">${data.label}</p>`;
option.className = "option-container";
option.targetType = type;
option.targetId = id;
option.zoneId = zoneId;
option.addEventListener("click", onClick);
optionsWrapper.appendChild(option);
}