parent
fc1fdb899d
commit
e9aee88387
Binary file not shown.
|
@ -16,8 +16,7 @@
|
|||
"deploy": "grunt deploy"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fwdekker/template": "^0.0.20",
|
||||
"js-cookie": "^2.2.1"
|
||||
"@fwdekker/template": "^0.0.20"
|
||||
},
|
||||
"devDependencies": {
|
||||
"grunt": "^1.2.1",
|
||||
|
|
|
@ -47,6 +47,6 @@
|
|||
<div id="footer"></div>
|
||||
</main>
|
||||
|
||||
<script src="bundle.js"></script>
|
||||
<script src="bundle.js?v=%%VERSION_NUMBER%%"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {$, doAfterLoad, footer, header, nav} from "@fwdekker/template";
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
|
||||
const storageKey = "/tools/random-fo76//selected-signatures";
|
||||
const signatureColCount = 8;
|
||||
|
||||
|
||||
|
@ -43,35 +43,29 @@ const setAllSignatures = checked => {
|
|||
const checkboxes = document.querySelectorAll("#signatures input");
|
||||
for (let i = 0; i < checkboxes.length; i++)
|
||||
checkboxes[i].checked = checked;
|
||||
saveSelectedSignaturesToCookie();
|
||||
saveSelectedSignaturesToStorage();
|
||||
|
||||
updateSignatureToggle();
|
||||
};
|
||||
|
||||
/**
|
||||
* (De)selects signatures based on the selection stored in a cookie.
|
||||
* (De)selects signatures based on the selection stored in local storage.
|
||||
*/
|
||||
const loadSelectedSignaturesFromCookie = () => {
|
||||
const cookie = Cookies.get("selectedSignatures");
|
||||
const loadSelectedSignaturesFromStorage = () => {
|
||||
const item = localStorage.getItem(storageKey);
|
||||
let signatures;
|
||||
if (cookie === undefined)
|
||||
if (item === null)
|
||||
signatures = [];
|
||||
else
|
||||
signatures = cookie.split(",");
|
||||
signatures = item.split(",");
|
||||
|
||||
setSelectedSignatures(signatures);
|
||||
};
|
||||
|
||||
/**
|
||||
* Saves the currently-selected signatures to a cookie.
|
||||
* Saves the currently-selected signatures to local storage.
|
||||
*/
|
||||
const saveSelectedSignaturesToCookie =
|
||||
() => Cookies.set("selectedSignatures", getSelectedSignatures().join(","), {
|
||||
expires: 5 * 365,
|
||||
secure: true,
|
||||
sameSite: "lax",
|
||||
path: ""
|
||||
});
|
||||
const saveSelectedSignaturesToStorage = () => localStorage.setItem(storageKey, getSelectedSignatures().join(","));
|
||||
|
||||
/**
|
||||
* Updates the button used to toggle all signatures on or off.
|
||||
|
@ -145,7 +139,7 @@ const createSignatureButtons = signatures => {
|
|||
checkbox.value = signature;
|
||||
checkbox.onclick = () => {
|
||||
updateSignatureToggle();
|
||||
saveSelectedSignaturesToCookie();
|
||||
saveSelectedSignaturesToStorage();
|
||||
};
|
||||
col.appendChild(checkbox);
|
||||
|
||||
|
@ -212,7 +206,7 @@ doAfterLoad(() => {
|
|||
downloadSignatures(
|
||||
signatures => {
|
||||
createSignatureButtons(signatures);
|
||||
loadSelectedSignaturesFromCookie();
|
||||
loadSelectedSignaturesFromStorage();
|
||||
},
|
||||
errorResponse => {
|
||||
const form = $("#signatureForm");
|
||||
|
|
Loading…
Reference in New Issue