113 lines
2.8 KiB
JavaScript
113 lines
2.8 KiB
JavaScript
var $inp;
|
|
|
|
let lore = false;
|
|
let cordX = 0;
|
|
let cordY = 0;
|
|
|
|
function data_update(name, value) {
|
|
return new Promise((resulve, reject) => {
|
|
$.ajax({
|
|
url: window.api + "player/update",
|
|
type: "POST",
|
|
data: { [name]: value },
|
|
|
|
xhrFields: { withCredentials: true },
|
|
success: function (resp) {
|
|
msg(resp.Status, resp.Message);
|
|
resulve(true);
|
|
},
|
|
error: function (resp, status, jqXHR) {
|
|
msg(
|
|
resp.responseJSON?.Status || "Erro",
|
|
resp.responseJSON?.Message || "Algo deu errado.",
|
|
);
|
|
resulve(false);
|
|
},
|
|
});
|
|
});
|
|
}
|
|
|
|
function editInput(name, x, y) {
|
|
var input = `
|
|
<nav id="FloatInput" style="top: ${y - 50}px; left: ${x - 100}px">
|
|
<input type="text" placeholder="${name}" name="${name}" />
|
|
</nav>
|
|
`;
|
|
$inp = $(input).appendTo("body").focus();
|
|
|
|
$inp.on("keydown", function (e) {
|
|
if (e.which === 13) {
|
|
switch ($(this).find("input").val().length > 0) {
|
|
case true:
|
|
let name = $(this).find("input").attr("name");
|
|
let value = $(this).find("input").val();
|
|
data_update(name, value).then((result) => {
|
|
if (result) {
|
|
$(this).remove();
|
|
}
|
|
});
|
|
break;
|
|
case false:
|
|
$(this).remove();
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
$inp.on("keypress keydown", function (e) {
|
|
switch (e.key) {
|
|
case "Delete":
|
|
$(this).remove();
|
|
break;
|
|
case "Backspace":
|
|
if ($(this).find("input").val() === "") {
|
|
$(this).remove();
|
|
}
|
|
break;
|
|
}
|
|
});
|
|
}
|
|
|
|
$(document).ready(function () {
|
|
$(document).on("mousemove", function (e) {
|
|
cordX = e.clientX;
|
|
cordY = e.clientY;
|
|
});
|
|
$(".editbtn").on("click", function (e) {
|
|
let reqbtn = e.currentTarget.className.split(" ");
|
|
let nameclass =
|
|
reqbtn.length > 1
|
|
? editInput(reqbtn[1], cordX, cordY)
|
|
: msg("Error", "erro, ainda não foi definido a classe desse botão");
|
|
});
|
|
|
|
$(".lore").on("click", function (e) {
|
|
switch (lore) {
|
|
case false:
|
|
$(".lore span").text("close");
|
|
$("#lore").hide();
|
|
$("#lore_edit").show();
|
|
$(".lore_edit").css("display", "block");
|
|
lore = true;
|
|
break;
|
|
case true:
|
|
$(".lore span").text("edit");
|
|
$("#lore").show();
|
|
$("#lore_edit").hide();
|
|
$(".lore_edit").css("display", "none");
|
|
lore = false;
|
|
break;
|
|
}
|
|
});
|
|
$(".lore_edit").on("click", function (e) {
|
|
data_update("lore", $("#lore_edit").val()).then((result) => {
|
|
if (result) {
|
|
$(".lore span").text("edit");
|
|
$("#lore").show();
|
|
$("#lore_edit").hide();
|
|
$(".lore_edit").css("display", "none");
|
|
lore = false;
|
|
}
|
|
});
|
|
});
|
|
});
|