-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
129 lines (105 loc) · 3.41 KB
/
main.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
let savedResults = [];
// localStorage.removeItem("Saved-Results");
let oldData = localStorage.getItem("Saved-Results")
if (oldData) {
savedResults = [oldData]
}
function isArray(myArray) {
return myArray.constructor.toString().indexOf("Array") > -1;
}
function submitResults(event) {
let all = document.getElementsByTagName("*");
let inputs = [];
let results = {};
for (let i = 0, max = all.length; i < max; i++) {
if (all[i].nodeName === "INPUT" ||
all[i].nodeName === "TEXTAREA" ||
all[i].nodeName == "SELECT") {
inputs.push(all[i]);
}
}
for (let i = 0, max = inputs.length; i < max; i++) {
results[inputs[i].id] = inputs[i].value;
}
console.log(results)
generateQRCode(JSON.stringify(results))
if (isArray(savedResults)) {
console.log("array is array")
console.log(JSON.stringify(results))
savedResults.push(results);
localStorage.setItem("Saved-Results", savedResults);
} else {
console.log("array is not array")
}
}
function generateQRCode(results) {
let qrText = results
let qrcode = new QRious({
element: document.getElementById("qrcode-2"),
background: '#ffffff',
backgroundAlpha: 1,
foreground: '#000000',
foregroundAlpha: 1,
level: 'H',
padding: 0,
size: 500,
value: qrText
});
}
function clearForm() {
let all = document.getElementsByTagName("*");
let inputs = []
for (let i = 0, max = all.length; i < max; i++) {
if (all[i].nodeName === "INPUT") {
inputs.push(all[i]);
}
}
for (let i = 0, max = all.length; i < max; i++) {
if (all[i].nodeName === "TEXTAREA") {
inputs.push(all[i]);
}
}
for (let i = 0, max = all.length; i < max; i++) {
if (all[i].nodeName === "SELECT") {
inputs.push(all[i]);
}
}
for (let i = 0, max = inputs.length; i < max; i++) {
inputs[i].value = "";
}
}
var coll = document.getElementsByClassName("collapsible")
var i
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function () {
this.classList.toggle("active")
var section = this.nextElementSibling
if (section.style.display === "block") {
section.style.display = "none"
} else {
section.style.display = "block"
}
});
}
const textAreaElement = document.querySelector("#Notes")
const characterCounterElement = document.querySelector("#character-counter")
const typedCharactersElement = document.querySelector("#typed-characters")
const maximumCharacters = 100
textAreaElement.addEventListener("keyup", (event) => {
const typedCharacters = textAreaElement.value.length
typedCharactersElement.textContent = maximumCharacters - typedCharacters;
if (typedCharacters >= 80 && typedCharacters < 100) {
textAreaElement.classList = "text-warning"
console.log("warning")
} else if (typedCharacters >= 100) {
textAreaElement.classList = "text-danger"
console.log("danger")
} else {
textAreaElement.classList = "text-fine"
}
if (typedCharacters > maximumCharacters) {
return false;
}
});
document.getElementById("endOfForm").addEventListener('click', submitResults)
document.getElementById("clearForm").addEventListener('click', clearForm)