-
Notifications
You must be signed in to change notification settings - Fork 8
/
script.js
83 lines (73 loc) · 3.14 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import Sticky from "./components/Sticky.js";
import StoryColumn from "./components/StoryColumn.js";
import kanbanData from "./data.js";
import Modal from "./components/Modal.js";
var docFragment = document.createDocumentFragment();
for (let storyType of kanbanData.columns) {
const storyColumn = new StoryColumn(storyType);
const columnDiv = storyColumn.createColumn();
columnDiv.classList.add("column-holder")
docFragment.appendChild(columnDiv);
}
for (let stickyData of kanbanData.stories) {
const sticky = new Sticky(stickyData.name, stickyData.description, stickyData.type, stickyData.priority, stickyData.column);
docFragment.getElementById(stickyData.column).appendChild(sticky.createSticky());
}
document.getElementById("gridLayout").appendChild(docFragment);
//Set the darkmode is enabled
if (window.localStorage.getItem("darkMode")) {
let darkMode = window.localStorage.getItem("darkMode") === "true" ? true : false;
document.getElementById("darkMode").checked = darkMode;
turnDarkModeOn(darkMode);
}
//Set the Autosave is enabled
if (window.localStorage.getItem("autosave")) {
let autosave = window.localStorage.getItem("autosave");
if (autosave === undefined) autosave = true;
else autosave = autosave === "true" ? true : false;
if (autosave) document.getElementById("autosave").checked = autosave;
}
else{
document.getElementById("autosave").checked = true;
}
function turnDarkModeOn(darkMode = true) {
if (!darkMode) {
document.documentElement.style.setProperty("--main-bg-color", "#fff");
document.documentElement.style.setProperty("--main-fg-color", "#000");
} else {
document.documentElement.style.setProperty("--main-fg-color", "#fff");
document.documentElement.style.setProperty("--main-bg-color", "#000");
}
}
//Listeners
document.getElementById("addSticky").addEventListener("click", () => {
Modal.showModal();
});
document.getElementById("reset").addEventListener("click", () => {
if (document.getElementById("autosave").checked) localStorage.setItem("stories", "[]");
const stickies = document.getElementsByClassName("sticky");
while (stickies.length) stickies[0].remove();
});
document.getElementById("darkMode").addEventListener("change", () => {
turnDarkModeOn(event.target.checked);
});
//On close or refresh save the data to json if save is enabled
window.addEventListener("unload", () => {
localStorage.setItem("autosave", document.getElementById("autosave").checked);
if (!document.getElementById("autosave").checked) return;
const stories = [];
for (let storyType of kanbanData.columns) {
const stickies = document.getElementById(storyType).getElementsByClassName("sticky");
for (let sticky of stickies) {
stories.push({
column: storyType,
name: sticky.querySelector(".sticky-name").textContent,
description: sticky.querySelector(".sticky-description").textContent,
type: sticky.querySelector(".sticky-type").classList[1],
priority: sticky.querySelector(".sticky-priority").classList[1],
});
}
}
localStorage.setItem("stories", JSON.stringify(stories));
localStorage.setItem("darkMode", document.getElementById("darkMode").checked);
});