put code into functions
This commit is contained in:
parent
79eb3e91ac
commit
58895aa6fe
3 changed files with 55 additions and 27 deletions
40
build/app.js
40
build/app.js
|
|
@ -6136,18 +6136,37 @@ window.addEventListener('drop', function (event) {
|
|||
document.getElementById("save-area-file").addEventListener("change", function (event) {
|
||||
var label = document.getElementById("save-area-file").nextElementSibling;
|
||||
var labelInitialText = label.innerHTML;
|
||||
var fileName = event.target.files[0].name;
|
||||
/* Shorten the file name if longer than 16 characters. Display first 10 characters and last 4. */
|
||||
|
||||
var fileName = FileNameFormat(event.target.files[0], 16, 10, 4);
|
||||
/* Display a custom formatted last modified date. */
|
||||
|
||||
var fileDate = FileDateFormat(event.target.files[0]);
|
||||
|
||||
if (fileName) {
|
||||
label.innerHTML = "".concat(SYMBOL_FILE).concat(fileName, " ").concat(fileDate);
|
||||
} else {
|
||||
label.innerHTML = labelInitialText;
|
||||
}
|
||||
});
|
||||
|
||||
function FileNameFormat(file, nameLength, beginLength, endLength) {
|
||||
var fileName = file.name;
|
||||
/* Shorten the file name if too long */
|
||||
|
||||
if (fileName.length > 16) {
|
||||
var begin = fileName.slice(0, 10); // take 10 characters from the beginning (0)
|
||||
if (fileName.length > nameLength) {
|
||||
var begin = fileName.slice(0, beginLength); // take X characters from the beginning (0)
|
||||
|
||||
var end = fileName.slice(-4); // take 4 characters from the end (-)
|
||||
var end = fileName.slice(-endLength); // take X characters from the end (-)
|
||||
|
||||
fileName = "".concat(begin, "..").concat(end);
|
||||
}
|
||||
|
||||
var fileDate = new Date(event.target.files[0].lastModified);
|
||||
return fileName;
|
||||
}
|
||||
|
||||
function FileDateFormat(file) {
|
||||
var fileDate = new Date(file.lastModified);
|
||||
var year = fileDate.getFullYear();
|
||||
var month = fileDate.getMonth() + 1;
|
||||
var day = fileDate.getDate();
|
||||
|
|
@ -6159,16 +6178,11 @@ document.getElementById("save-area-file").addEventListener("change", function (e
|
|||
if (hour < 10) hour = "0" + hour;
|
||||
if (minutes < 10) minutes = "0" + minutes;
|
||||
if (seconds < 10) seconds = "0" + seconds;
|
||||
var fileDateFormat = "".concat(year, ".").concat(month, ".").concat(day, " ").concat(hour, ":").concat(minutes, ":").concat(seconds);
|
||||
|
||||
if (fileName) {
|
||||
label.innerHTML = "".concat(SYMBOL_FILE).concat(fileName, " ").concat(fileDateFormat);
|
||||
} else {
|
||||
label.innerHTML = labelInitialText;
|
||||
}
|
||||
});
|
||||
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) -------- */
|
||||
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
||||
return regeneratorRuntime.wrap(function _callee$(_context) {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1128,17 +1128,37 @@ document.getElementById("save-area-file").addEventListener("change", (event) =>
|
|||
var label = document.getElementById("save-area-file").nextElementSibling;
|
||||
var labelInitialText = label.innerHTML;
|
||||
|
||||
var fileName = event.target.files[0].name;
|
||||
/* Shorten the file name if longer than 16 characters. Display first 10 characters and last 4. */
|
||||
var fileName = FileNameFormat(event.target.files[0], 16, 10, 4);
|
||||
|
||||
/* Display a custom formatted last modified date. */
|
||||
var fileDate = FileDateFormat(event.target.files[0]);
|
||||
|
||||
if (fileName) {
|
||||
label.innerHTML = `${SYMBOL_FILE}${fileName} ${fileDate}`;
|
||||
} else {
|
||||
label.innerHTML = labelInitialText;
|
||||
}
|
||||
});
|
||||
|
||||
function FileNameFormat(file, nameLength, beginLength, endLength) {
|
||||
|
||||
var fileName = file.name;
|
||||
|
||||
/* Shorten the file name if too long */
|
||||
if (fileName.length > 16) {
|
||||
if (fileName.length > nameLength) {
|
||||
|
||||
let begin = fileName.slice(0, 10); // take 10 characters from the beginning (0)
|
||||
let end = fileName.slice(-4); // take 4 characters from the end (-)
|
||||
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}`;
|
||||
}
|
||||
|
||||
var fileDate = new Date(event.target.files[0].lastModified);
|
||||
return fileName;
|
||||
}
|
||||
|
||||
function FileDateFormat(file) {
|
||||
|
||||
var fileDate = new Date(file.lastModified);
|
||||
|
||||
var year = fileDate.getFullYear();
|
||||
var month = fileDate.getMonth() + 1;
|
||||
|
|
@ -1153,14 +1173,8 @@ document.getElementById("save-area-file").addEventListener("change", (event) =>
|
|||
if (minutes < 10) minutes = "0" + minutes;
|
||||
if (seconds < 10) seconds = "0" + seconds;
|
||||
|
||||
var fileDateFormat = `${year}.${month}.${day} ${hour}:${minutes}:${seconds}`;
|
||||
|
||||
if (fileName) {
|
||||
label.innerHTML = `${SYMBOL_FILE}${fileName} ${fileDateFormat}`;
|
||||
} else {
|
||||
label.innerHTML = labelInitialText;
|
||||
}
|
||||
});
|
||||
return `${year}.${month}.${day} ${hour}:${minutes}:${seconds}`;
|
||||
}
|
||||
|
||||
/* -------- Clean the text area and file input from leftover save file if present (Firefox especially) -------- */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue