Files
Elite-Gaming-FiveM-Old/resources/BigDaddy-Money/nui/menu.js
T
2025-07-17 06:17:07 -07:00

91 lines
3.3 KiB
JavaScript

var to;
$(document).ready(function () {
$(".menuitemholder").hover(
function () {
clearTimeout(to), $(".menuitemholder").removeClass("hover"), $(this).addClass("hover"), $("#secondarylabel").html($(this).attr("data-name"));
},
function () {
var e = this;
to = setTimeout(function () {
$(e).removeClass("hover"), $("#secondarylabel").html("");
}, 400);
}
);
$(".menuitemholder").click(function () {
CallBack("ItemClick", $(this).attr("data-id"));
});
eventCallback = {
Visible: function (e) {
e.visible ? $("#menu").removeClass("hidden") : $("#menu").addClass("hidden");
},
toggle: function (e) {
$("#menu").hasClass("hidden") ? $("#menu").removeClass("hidden") : $("#menu").addClass("hidden");
},
RenderMenu: function (e) {
Reset();
var t = JSON.parse(e.items),
a = 0;
for ($("#mainlabel").html(e.menuname), a = 0; a < t.items.length; a++)
if (((tot = a + 1), a > 11));
else {
var n = $("#opt" + (a + 1)),
s = $("#mih" + (a + 1)),
i = $("#icon" + (a + 1));
$(s).attr("data-id", t.items[a].id), $(s).attr("data-name", t.items[a].description);
var o = "";
(o = imageExists("assets/img/" + t.items[a].icon + ".svg") ? t.items[a].icon + ".svg" : t.items[a].icon + ".png"),
$(i).attr("src", "assets/img/" + o),
$(n).removeClass("hidden"),
event.data.visible && $("#menu").removeClass("hidden"),
event.data.back ? $("#backbutton").removeClass("hidden") : $("#backbutton").hasClass("hidden") || $("#backbutton").addClass("hidden");
}
if (a < 12) {
for (let d = 1; d < tot; d++) $("#opt" + (d + 1)).css("transform", "translate(-50%,0%) rotate(" + (360 / tot) * d + "deg)"), $("#icon" + (d + 1)).css("transform", "translate(-50%,2vh) rotate(-" + (360 / tot) * d + "deg)");
for (let r = tot + 1; r < 13; r++) $("#opt" + r).remove();
}
},
};
window.addEventListener("message", function (e) {
eventCallback[e.data.action](e.data);
}),
window.addEventListener("keyup", (e) => {
e.key, ("Backspace" != e.key && "Escape" != e.key && (keepOpen || e.key != menukey)) || CallBack("MenuClosed");
});
});
function CallBack(e, t) {
fetch(`https://${window.GetParentResourceName ? window.GetParentResourceName() : "nui-frame-app"}/${e}`, {
method: "POST",
headers: { "Content-Type": "application/json; charset=UTF-8" },
body: JSON.stringify({ itemId: void 0 != t ? t : "" }),
});
}
function Reset() {
$("#menuHolder").html($("#defaultMenu").html()),
$(".menuitemholder").hover(
function () {
clearTimeout(to), $(".menuitemholder").removeClass("hover"), $(this).addClass("hover"), $("#secondarylabel").html($(this).attr("data-name"));
},
function () {
var e = this;
to = setTimeout(function () {
$(e).removeClass("hover"), $("#secondarylabel").html("");
}, 400);
}
),
$(".menuitemholder").click(function () {
console.log("clicky: " + $(this).attr("data-id")), CallBack("ItemClick", $(this).attr("data-id"));
});
}
function imageExists(e) {
var t = new XMLHttpRequest();
return t.open("HEAD", e, !1), t.send(), 404 != t.status;
}