use sortablejs instead of jquery-ui (#1115)

This commit is contained in:
jatdung
2023-02-11 04:32:58 +08:00
committed by GitHub
parent 1ad5603c3e
commit cd4b522935
8 changed files with 167 additions and 236 deletions

View File

@@ -52,15 +52,38 @@ $.when($.ready).then(() => {
}
}); */
$("#sortable").sortable({
stop() {
const idsInOrder = $("#sortable").sortable("toArray", {
attribute: "data-id",
const sortableEl = document.getElementById("sortable");
let sortable;
if (sortableEl !== null) {
// eslint-disable-next-line no-undef
sortable = Sortable.create(sortableEl, {
disabled: true,
animation: 150,
forceFallback: !(
navigator.userAgent.toLowerCase().indexOf("firefox") > -1
),
draggable: ".item-container",
onEnd() {
const idsInOrder = sortable.toArray();
$.post(`${base}order`, { order: idsInOrder });
},
});
// prevent Firefox drag behavior
if (navigator.userAgent.toLowerCase().indexOf("firefox") > -1) {
sortable.option("setData", (dataTransfer) => {
dataTransfer.setData("Text", "");
});
$.post(`${base}order`, { order: idsInOrder });
},
});
$("#sortable").sortable("disable");
sortableEl.addEventListener("dragstart", (event) => {
const { target } = event;
if (target.nodeName.toLowerCase() === "a") {
event.preventDefault();
event.stopPropagation();
event.dataTransfer.setData("Text", "");
}
});
}
}
$("#main")
.on("mouseenter", "#sortable.ui-sortable-disabled .item", function () {
@@ -138,10 +161,10 @@ $.when($.ready).then(() => {
$(".item-edit").hide();
$("#app").removeClass("sidebar");
$("#sortable .tooltip").css("display", "");
$("#sortable").sortable("disable");
if (sortable !== undefined) sortable.option("disabled", true);
} else {
$("#sortable .tooltip").css("display", "none");
$("#sortable").sortable("enable");
if (sortable !== undefined) sortable.option("disabled", false);
setTimeout(() => {
$(".add-item").fadeIn();
$(".item-edit").fadeIn();

View File

@@ -1125,6 +1125,16 @@ select:-webkit-autofill:focus {
color: $app-text!important;
}
.sortable-drag {
opacity: 1!important;
}
#sortable {
.sortable-ghost:not(.sortable-drag) {
opacity: 0;
}
}
#sortable:focus-within {
.item:focus-within {
outline: 1px solid #ffffff91;