Summary Files Commits Branches @commit @diff @stats
path: root / checklist.html
diff options
context:
space:
mode:
Commit582c0e444d99f39256fca36a64f0bf94b95a5c11 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-12-22 18:39:04 +0200
Committer
 Syndamia <kamen@syndamia.com>
2022-12-22 18:39:04 +0200
Filesf5663d89936dc69125449f8e9395bfc05e69fc30 /checklist.html
small-web-utilities-582c0e444d99f39256fca36a64f0bf94b95a5c11.tar
small-web-utilities-582c0e444d99f39256fca36a64f0bf94b95a5c11.tar.gz
small-web-utilities-582c0e444d99f39256fca36a64f0bf94b95a5c11.zip
Parent81b4a96469f44cca1598a658628aaa046821a6ef (diff)
[checklist] Added checklist
1 files changed, 263 insertions, 0 deletions
-rw-r--r--checklist.html263
diff --git a/checklist.html b/checklist.html
new file mode 100644
index 0000000..b07ae4a
--- /dev/null
+++ b/checklist.html
@@ -0,0 +1,263 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Check list</title>
+<style>
+#notice {
+ font-size: 0.9em;
+ color: gray;
+ font-style: italic;
+}
+</style>
+<style>
+.list-item {
+ margin-left: 1em;
+}
+
+input {
+ vertical-align: middle;
+}
+
+.checked {
+ color: gray;
+ font-style: italic;
+ text-decoration: line-through;
+}
+
+.textlike:not(:focus) {
+ border: none;
+ background: none;
+}
+</style>
+<style id="stylesheet-locked">
+#article-add-item, #article-sub-item, .item-add, .item-remove {
+ display: none;
+}
+</style>
+ </head>
+ <body>
+ <header>
+ <h2>Checklists</h2>
+ <p>
+ With plus you add an item to the bottom of a checklist.
+ With minus you remove it. With "Lock" you disable all adding and removeal of items.
+ "U" and "C" buttons correspond to uncheck and check functionality.
+ "Export" creates and puts a string, representing the whole checklist and what items are checked, in the text box on the right, as well as in the current link.
+ This means that, after pressing "Export", you can copy the link of the current page and share it, or you can copy the text itself (double-click to select all).
+ "Import" reads the checklist data from the link if the text input is empty, otherwise it reads from the text input on the right.
+ </p>
+ <a href="/">Home</a>
+ <span id="notice">&emsp; Made by <a href="https://syndamia.com">Syndamia</a>, licensed under <a href="https://gitlab.com/Syndamia/small-web-utilities/-/blob/main/LICENSE">GNU GPLv3</a></span>
+ <hr>
+ </header>
+
+ <div>
+ <input type="button" value="Import" id="import-btn">
+ <input type="button" value="Export" id="export-btn">
+ <input type="text" id="exp-imp-text">
+ </div>
+ <br>
+ <input type="button" value="Uncheck all" id="uncheck-all">
+ <input type="button" value="Check all" id="check-all">
+ <input type="button" value="Lock" id="lock-items">
+ <input type="button" value="+" id="article-add-item">
+ <input type="button" value="-" id="article-sub-item">
+ <article id="lists"></article>
+ <script>
+ const lists = document.getElementById('lists');
+ const stylesheetLocked = document.getElementById('stylesheet-locked');
+ stylesheetLocked.disabled = true;
+ const expImpText = document.getElementById('exp-imp-text');
+ const url = new URL(location.href);
+
+ /* Item functionality */
+
+ function changeCheck(current, check) {
+ current.children[0].checked = check;
+ if (current.children[1].classList.contains('checked') !== check) {
+ current.children[1].classList.toggle('checked');
+ }
+
+ for (var i = 6; i < current.children.length; i++) {
+ changeCheck(current.children[i], check);
+ }
+ }
+
+ function changeCheckLists(check) {
+ for (var i = 0; i < lists.children.length; i++) {
+ changeCheck(lists.children[i], check);
+ }
+ }
+
+ function newBlankItem(initialText, initialWidth, checked) {
+ var holder = document.createElement('div');
+ holder.classList.add('list-item');
+
+ var text = document.createElement('input');
+ text.classList.add('textlike');
+ text.type = 'text';
+ text.style.width = "160px";
+ text.onkeypress = function () {
+ this.style.width = Math.max(16, this.value.length) * 10 + "px";
+ }
+
+ var checkbox = document.createElement('input');
+ checkbox.type = 'checkbox';
+ checkbox.onclick = function () {
+ text.classList.toggle('checked');
+ };
+
+ holder.appendChild(checkbox);
+ holder.appendChild(text);
+
+ var add = document.createElement('input');
+ add.type = 'button';
+ add.value = '+';
+ add.classList.add('item-add');
+ add.onclick = function () {
+ holder.appendChild(newBlankItem());
+ }
+ holder.appendChild(add);
+
+ var sub = document.createElement('input');
+ sub.type = 'button';
+ sub.value = '-';
+ sub.classList.add('item-remove');
+ sub.onclick = function () {
+ holder.remove();
+ }
+ holder.appendChild(sub);
+
+ var uncheck = document.createElement('input');
+ uncheck.type = 'button';
+ uncheck.value = 'U';
+ uncheck.onclick = function () {
+ changeCheck(holder, false);
+ }
+ holder.appendChild(uncheck);
+
+ var check = document.createElement('input');
+ check.type = 'button';
+ check.value = 'C';
+ check.onclick = function () {
+ changeCheck(holder, true);
+ }
+ holder.appendChild(check);
+
+ if (initialText) text.value = initialText;
+ if (initialWidth) text.style.width = initialWidth;
+ if (checked) checkbox.click();
+
+ return holder;
+ }
+
+ document.getElementById('article-add-item').onclick = function () {
+ lists.appendChild(newBlankItem());
+ }
+
+ document.getElementById('article-sub-item').onclick = function () {
+ lists.innerHTML = "";
+ }
+
+ document.getElementById('lock-items').onclick = function () {
+ stylesheetLocked.disabled = !stylesheetLocked.disabled;
+ }
+
+ document.getElementById('uncheck-all').onclick = function () {
+ changeCheckLists(false);
+ }
+
+ document.getElementById('check-all').onclick = function () {
+ changeCheckLists(true);
+ }
+
+ /* Import-export */
+
+ function stringify(current) {
+ var str = "";
+ var start = 6;
+ if (!current) {
+ current = lists;
+ start = 0;
+ }
+ else {
+ str = "\"" + encodeURIComponent(current.children[1].value) + "\"" + current.children[1].style.width + current.children[0].checked;
+ }
+
+ for (var i = start; i < current.children.length; i++) {
+ str += "-" + stringify(current.children[i]) + "_";
+ }
+ return str;
+ }
+
+ function parse(str, par, i) {
+ if (!i) i = 0;
+
+ var text = "";
+ var width = "";
+ var recurse = true;
+ var current;
+
+ var j = 0;
+ while (i < str.length) {
+ switch (str[i]) {
+ // Item text
+ case '"':
+ j = str.indexOf('"', ++i);
+ text = decodeURIComponent(str.substring(i, j));
+ i = j;
+ break;
+
+ // Textbox width
+ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
+ j = str.indexOf('x', i);
+ width = str.substring(i, j + 1);
+ i = j;
+ break;
+
+ // Is checked
+ case 't':
+ current = newBlankItem(text, width, true);
+ par.appendChild(current);
+ i += 3;
+ break;
+
+ // Is not checked
+ case 'f':
+ current = newBlankItem(text, width, false);
+ par.appendChild(current);
+ i += 4;
+ break;
+
+ // On end of item
+ case '_':
+ if (par != lists) return i;
+ recurse = false;
+ break;
+
+ // On start of item
+ case '-':
+ if (recurse) i = parse(str, current, i + 1);
+ recurse = true;
+ break;
+ }
+
+ ++i;
+ }
+ }
+
+ document.getElementById('import-btn').onclick = function () {
+ if (expImpText.value != "")
+ parse(expImpText.value, lists);
+ else
+ parse(url.searchParams.get('list'), lists);
+ }
+
+ document.getElementById('export-btn').onclick = function () {
+ expImpText.value = stringify().substring(1);
+ url.searchParams.set('list', expImpText.value);
+ history.pushState(null, '', url);
+ }
+ </script>
+ </body>
+</html>