/* jshint esversion: 6 */
const updateRenameValue = ($inputs, $value) => {
let files = [];
$inputs.each((i, ele) => {
files.push({
original: $(ele).data("original"),
new: $(ele).val(),
});
});
$value.val(JSON.stringify(files));
};
$select.on("change-files", (e, files) => {
if (files.length == 0) {
$(".rename-files").html(
`
`
);
return;
}
$(".rename-files").html(
files
.map((f) => {
return `
`;
})
.join("")
);
$(".rename-files-input").on("keydown", (e) => {
if (e.keyCode == 13) {
e.preventDefault();
const $next = $(e.target).parent().nextAll().find("input")[0];
if ($next) {
$next.focus();
if ($next.type == "text") {
$next.select();
}
}
}
});
$(".rename-files").each((i, ele) => {
const $value = $(ele).parent().find(".rename-files-value");
const $inputs = $(ele)
.find(".rename-files-input")
.on("focus blur change", (e) => {
updateRenameValue($inputs, $value);
});
updateRenameValue($inputs, $value);
});
});
updateSelected();