Set serviceWorker to allow offline usage

Close #15, close #14
This commit is contained in:
2022-11-07 03:55:07 +01:00
parent 3e4554f759
commit 326af61836
10 changed files with 172 additions and 29 deletions

View File

@ -1,5 +1,10 @@
"use strict";
if ('serviceWorker' in navigator) {
console.log("Registering service worker");
navigator.serviceWorker.register('/sw.js');
}
class CsvxmlValidator {
fieldList; // {}{}
@ -625,6 +630,7 @@ class CsvxmlPage {
const input = document.createElement("input");
input.type = "file";
input.id = "fileToUpload";
input.setAttribute("tabindex", "1");
input.accept = ".csv";
input.required = "required";
input.addEventListener('change', async function() {
@ -703,8 +709,9 @@ class CsvxmlPage {
function genButton(id, text, link = "") {
const output = document.createElement("a");
const output = document.createElement("span");
output.id = id;
output.setAttribute("tabindex", "1");
output.textContent = text;
output.classList.add("buttonLike");
if (link !== "") output.href = link;
@ -719,7 +726,8 @@ class CsvxmlPage {
const dlAllButton = genButton("dlAll", this.tls.download_csv_all);
dlAllButton.cursor = "pointer";
dlAllButton.addEventListener('click', function() {
dlAllButton.addEventListener('click', function(e) {
e.preventDefault();
app.generateCsv();
});
options.appendChild(dlAllButton);
@ -739,6 +747,7 @@ class CsvxmlPage {
options.appendChild(this.unsetSelectionButton);
this.csvBySelectionButton.addEventListener('click', function(e) {
e.preventDefault();
let selected = document.getElementsByClassName("humanTLToggled");
let selectedFields = [];
@ -750,6 +759,7 @@ class CsvxmlPage {
});
optionSelectRequired.addEventListener('click', function(e) {
e.preventDefault();
app.doForFieldList(function(field) {
if (field.classList.contains("requiredField") === false) return;
@ -763,6 +773,7 @@ class CsvxmlPage {
});
optionSelectAll.addEventListener('click', function(e) {
e.preventDefault();
app.doForFieldList(function(field) {
if (field.classList.contains("humanTLToggled") === true) return;
@ -775,6 +786,7 @@ class CsvxmlPage {
});
this.unsetSelectionButton.addEventListener('click', function(e) {
e.preventDefault();
app.doForFieldList(function(field) {
if (field.classList.contains("humanTLToggled") === false) return;
@ -893,6 +905,7 @@ class CsvxmlPage {
}
const lang = getLang();
document.documentElement.setAttribute("lang", lang);
document.body.classList.add("loading");