drag and drop: display file name and date on the button

This commit is contained in:
ReznoRMichael 2021-07-21 14:24:47 +02:00
parent 58895aa6fe
commit de96ac01da
3 changed files with 99 additions and 69 deletions

View file

@ -6082,6 +6082,37 @@ function SelectCopyInputText(mouseEvent) {
if (tooltipFill.length && tooltipId.length) FillInnerHTML(tooltipId, tooltipFill); if (tooltipFill.length && tooltipId.length) FillInnerHTML(tooltipId, tooltipFill);
} }
function FileNameFormat(file, nameLength, beginLength, endLength) {
var fileName = file.name;
/* Shorten the file name if too long */
if (fileName.length > nameLength) {
var begin = fileName.slice(0, beginLength); // take X characters from the beginning (0)
var end = fileName.slice(-endLength); // take X characters from the end (-)
fileName = "".concat(begin, "..").concat(end);
}
return fileName;
}
function FileDateFormat(file) {
var fileDate = new Date(file.lastModified);
var year = fileDate.getFullYear();
var month = fileDate.getMonth() + 1;
var day = fileDate.getDate();
var hour = fileDate.getHours();
var minutes = fileDate.getMinutes();
var seconds = fileDate.getSeconds();
if (month < 10) month = "0" + month;
if (day < 10) day = "0" + day;
if (hour < 10) hour = "0" + hour;
if (minutes < 10) minutes = "0" + minutes;
if (seconds < 10) seconds = "0" + seconds;
return "".concat(year, ".").concat(month, ".").concat(day, " ").concat(hour, ":").concat(minutes, ":").concat(seconds);
}
/* ========================== Event Listeners ========================== */ /* ========================== Event Listeners ========================== */
/* --------------- Toggle visibility of scroll arrow ------------------ */ /* --------------- Toggle visibility of scroll arrow ------------------ */
@ -6130,6 +6161,21 @@ window.addEventListener('drop', function (event) {
/* Launch save file analyzing */ /* Launch save file analyzing */
(0,_LoadSaveFile_js__WEBPACK_IMPORTED_MODULE_1__.LoadSaveFile)(dt, new Date()); (0,_LoadSaveFile_js__WEBPACK_IMPORTED_MODULE_1__.LoadSaveFile)(dt, new Date());
var label = document.getElementById("save-area-file").nextElementSibling;
var labelInitialText = label.innerHTML;
/* Shorten the file name if longer than 16 characters. Display first 10 characters and last 4. */
var fileName = FileNameFormat(dt.files[0], 16, 10, 4);
/* Display a custom formatted last modified date. */
var fileDate = FileDateFormat(dt.files[0]);
/* Display the save file name and date on the button */
if (fileName) {
label.innerHTML = "".concat(SYMBOL_FILE).concat(fileName, " ").concat(fileDate);
} else {
label.innerHTML = labelInitialText;
}
}); });
/* ---------- Monitor file input change and show the file name when file is loaded ----------- */ /* ---------- Monitor file input change and show the file name when file is loaded ----------- */
@ -6149,40 +6195,8 @@ document.getElementById("save-area-file").addEventListener("change", function (e
label.innerHTML = labelInitialText; label.innerHTML = labelInitialText;
} }
}); });
function FileNameFormat(file, nameLength, beginLength, endLength) {
var fileName = file.name;
/* Shorten the file name if too long */
if (fileName.length > nameLength) {
var begin = fileName.slice(0, beginLength); // take X characters from the beginning (0)
var end = fileName.slice(-endLength); // take X characters from the end (-)
fileName = "".concat(begin, "..").concat(end);
}
return fileName;
}
function FileDateFormat(file) {
var fileDate = new Date(file.lastModified);
var year = fileDate.getFullYear();
var month = fileDate.getMonth() + 1;
var day = fileDate.getDate();
var hour = fileDate.getHours();
var minutes = fileDate.getMinutes();
var seconds = fileDate.getSeconds();
if (month < 10) month = "0" + month;
if (day < 10) day = "0" + day;
if (hour < 10) hour = "0" + hour;
if (minutes < 10) minutes = "0" + minutes;
if (seconds < 10) seconds = "0" + seconds;
return "".concat(year, ".").concat(month, ".").concat(day, " ").concat(hour, ":").concat(minutes, ":").concat(seconds);
}
/* -------- Clean the text area and file input from leftover save file if present (Firefox especially) -------- */ /* -------- Clean the text area and file input from leftover save file if present (Firefox especially) -------- */
document.addEventListener("DOMContentLoaded", function () { document.addEventListener("DOMContentLoaded", function () {
_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
return regeneratorRuntime.wrap(function _callee$(_context) { return regeneratorRuntime.wrap(function _callee$(_context) {

File diff suppressed because one or more lines are too long

View file

@ -1059,6 +1059,41 @@ function SelectCopyInputText(mouseEvent, tooltipId = "", tooltipFill = "") {
if (tooltipFill.length && tooltipId.length) FillInnerHTML(tooltipId, tooltipFill); if (tooltipFill.length && tooltipId.length) FillInnerHTML(tooltipId, tooltipFill);
} }
function FileNameFormat(file, nameLength, beginLength, endLength) {
var fileName = file.name;
/* Shorten the file name if too long */
if (fileName.length > nameLength) {
let begin = fileName.slice(0, beginLength); // take X characters from the beginning (0)
let end = fileName.slice(-endLength); // take X characters from the end (-)
fileName = `${begin}..${end}`;
}
return fileName;
}
function FileDateFormat(file) {
var fileDate = new Date(file.lastModified);
var year = fileDate.getFullYear();
var month = fileDate.getMonth() + 1;
var day = fileDate.getDate();
var hour = fileDate.getHours();
var minutes = fileDate.getMinutes();
var seconds = fileDate.getSeconds();
if (month < 10) month = "0" + month;
if (day < 10) day = "0" + day;
if (hour < 10) hour = "0" + hour;
if (minutes < 10) minutes = "0" + minutes;
if (seconds < 10) seconds = "0" + seconds;
return `${year}.${month}.${day} ${hour}:${minutes}:${seconds}`;
}
/* ========================== Event Listeners ========================== */ /* ========================== Event Listeners ========================== */
/* --------------- Toggle visibility of scroll arrow ------------------ */ /* --------------- Toggle visibility of scroll arrow ------------------ */
@ -1119,6 +1154,22 @@ window.addEventListener('drop', (event) => {
/* Launch save file analyzing */ /* Launch save file analyzing */
LoadSaveFile(dt, new Date()); LoadSaveFile(dt, new Date());
var label = document.getElementById("save-area-file").nextElementSibling;
var labelInitialText = label.innerHTML;
/* Shorten the file name if longer than 16 characters. Display first 10 characters and last 4. */
var fileName = FileNameFormat(dt.files[0], 16, 10, 4);
/* Display a custom formatted last modified date. */
var fileDate = FileDateFormat(dt.files[0]);
/* Display the save file name and date on the button */
if (fileName) {
label.innerHTML = `${SYMBOL_FILE}${fileName} ${fileDate}`;
} else {
label.innerHTML = labelInitialText;
}
}); });
/* ---------- Monitor file input change and show the file name when file is loaded ----------- */ /* ---------- Monitor file input change and show the file name when file is loaded ----------- */
@ -1141,41 +1192,6 @@ document.getElementById("save-area-file").addEventListener("change", (event) =>
} }
}); });
function FileNameFormat(file, nameLength, beginLength, endLength) {
var fileName = file.name;
/* Shorten the file name if too long */
if (fileName.length > nameLength) {
let begin = fileName.slice(0, beginLength); // take X characters from the beginning (0)
let end = fileName.slice(-endLength); // take X characters from the end (-)
fileName = `${begin}..${end}`;
}
return fileName;
}
function FileDateFormat(file) {
var fileDate = new Date(file.lastModified);
var year = fileDate.getFullYear();
var month = fileDate.getMonth() + 1;
var day = fileDate.getDate();
var hour = fileDate.getHours();
var minutes = fileDate.getMinutes();
var seconds = fileDate.getSeconds();
if (month < 10) month = "0" + month;
if (day < 10) day = "0" + day;
if (hour < 10) hour = "0" + hour;
if (minutes < 10) minutes = "0" + minutes;
if (seconds < 10) seconds = "0" + seconds;
return `${year}.${month}.${day} ${hour}:${minutes}:${seconds}`;
}
/* -------- Clean the text area and file input from leftover save file if present (Firefox especially) -------- */ /* -------- Clean the text area and file input from leftover save file if present (Firefox especially) -------- */
document.addEventListener("DOMContentLoaded", () => { document.addEventListener("DOMContentLoaded", () => {