Skip to content

Commit 93746cd

Browse files
clean up the logic paths to prep for better pathstate flow
1 parent 6454dde commit 93746cd

File tree

2 files changed

+145
-102
lines changed

2 files changed

+145
-102
lines changed

src/scripts-old.js

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
2+
let rawStatePathRoutes = [
3+
'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-0/waive-your-copyright+waive+read/attribution-details&license=cc-0',
4+
'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-by/attribution-details&license=cc-by',
5+
'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-by-sa/attribution-details&license=cc-by-sa',
6+
'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-by-nd/attribution-details&license=cc-by-nd',
7+
'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-by-nc/attribution-details&license=cc-by-nc',
8+
'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-by-nc-sa/attribution-details&license=cc-by-nc-sa',
9+
'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-by-nc-nd/attribution-details&license=cc-by-nc-nd',
10+
11+
'do-you-know-which-license-you-need/no/require-attribution/yes/allow-commerical-use/yes/allow-derivatives/yes/share-alike/yes/confirmation+ownership+read+revocation/attribution-details&license=cc-by',
12+
'do-you-know-which-license-you-need/no/require-attribution/yes/allow-commerical-use/yes/allow-derivatives/yes/share-alike/no/confirmation+ownership+read+revocation/attribution-details&license=cc-by-sa',
13+
'do-you-know-which-license-you-need/no/require-attribution/yes/allow-commerical-use/yes/allow-derivatives/no/confirmation+ownership+read+revocation/attribution-details&license=cc-by-nd',
14+
'do-you-know-which-license-you-need/no/require-attribution/yes/allow-commerical-use/no/allow-derivatives/yes/share-alike/yes/confirmation+ownership+read+revocation/attribution-details&license=cc-by-nc',
15+
'do-you-know-which-license-you-need/no/require-attribution/yes/allow-commerical-use/no/allow-derivatives/yes/share-alike/no/confirmation+ownership+read+revocation/attribution-details&license=cc-by-nc-sa',
16+
'do-you-know-which-license-you-need/no/require-attribution/yes/allow-commerical-use/no/allow-derivatives/no/confirmation+ownership+read+revocation/attribution-details&license=cc-by-nc-nd',
17+
'do-you-know-which-license-you-need/no/require-attribution/no/waive-your-copyright+waive+read/attribution-details&license=cc-0'
18+
];
19+
20+
21+
let rawStatePath = rawStatePathRoutes[13];
22+
let statePath = rawStatePath.split("/");
23+
24+
let last = statePath[statePath.length - 1].split("&")
25+
let license = last[1].split("=");
26+
27+
28+
console.log(statePath[0]);
29+
console.log(statePath[1]);
30+
31+
console.log(statePath[2]);
32+
console.log(statePath[3]);
33+
34+
console.log(statePath[4]);
35+
36+
37+
console.log(statePath[5]);
38+
console.log(statePath[6]);
39+
console.log(statePath[7]);
40+
console.log(statePath[8]);
41+
console.log(statePath[9]);
42+
console.log(statePath[10]);
43+
console.log(statePath[11]);
44+
45+
46+
console.log(last[0]);
47+
48+
console.log(license[1]);
49+
50+
51+
52+
53+
document.querySelector('#require-attribution').classList.toggle('disable');
54+
55+
document.querySelector('#allow-commercial-use').classList.toggle('disable');
56+
57+
document.querySelector('#allow-derivatives').classList.toggle('disable');
58+
59+
document.querySelector('#share-alike').classList.toggle('disable');
60+
61+
document.querySelector('#waive-your-copyright').classList.toggle('disable');
62+
63+
document.querySelector('#confirmation').classList.toggle('disable');
64+
65+
66+
67+
// Get the form
68+
const form = document.forms[0];
69+
70+
// Get the form's radio buttons
71+
const helpChoice = form.elements["choose"];
72+
73+
// Choose the "red" option
74+
console.log(helpChoice.value);
75+
76+
const selectElement = document.querySelector("#do-you-know-which-license-you-need");
77+
78+
selectElement.addEventListener("change", (event) => {
79+
console.log(helpChoice.value);
80+
81+
if (helpChoice.value == 'no') {
82+
83+
document.querySelector('#which-license-do-you-need').classList.toggle('disable');
84+
85+
} else {
86+
87+
document.querySelector('#which-license-do-you-need').classList.remove('disable');
88+
}
89+
90+
document.querySelector('#require-attribution').classList.toggle('disable');
91+
92+
document.querySelector('#allow-commercial-use').classList.toggle('disable');
93+
94+
document.querySelector('#allow-derivatives').classList.toggle('disable');
95+
96+
document.querySelector('#share-alike').classList.toggle('disable');
97+
98+
document.querySelector('#confirmation').classList.toggle('disable');
99+
});
100+
101+
102+
const licenseElement = document.querySelector("#which-license-do-you-need");
103+
104+
const licenseChoice = form.elements["license"];
105+
106+
licenseElement.addEventListener("change", (event) => {
107+
console.log(licenseChoice.value);
108+
109+
if (licenseChoice.value == 'cc-0') {
110+
111+
document.querySelector('#waive-your-copyright').classList.toggle('disable');
112+
} else {
113+
114+
document.querySelector('#waive-your-copyright').classList.add('disable');
115+
}
116+
117+
});
118+
119+
const attributionElement = document.querySelector("#require-attribution");
120+
121+
const attributionChoice = form.elements["attribution"];
122+
123+
attributionElement.addEventListener("change", (event) => {
124+
console.log(attributionChoice.value);
125+
126+
document.querySelector('#allow-commercial-use').classList.toggle('disable');
127+
128+
document.querySelector('#allow-derivatives').classList.toggle('disable');
129+
130+
document.querySelector('#share-alike').classList.toggle('disable');
131+
132+
document.querySelector('#waive-your-copyright').classList.remove('disable');
133+
134+
document.querySelector('#confirmation').classList.toggle('disable');
135+
136+
});

src/scripts.js

Lines changed: 9 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -25,112 +25,19 @@ let last = statePath[statePath.length - 1].split("&")
2525
let license = last[1].split("=");
2626

2727

28-
console.log(statePath[0]);
29-
console.log(statePath[1]);
3028

31-
console.log(statePath[2]);
32-
console.log(statePath[3]);
3329

34-
console.log(statePath[4]);
30+
const fieldsets = document.querySelectorAll('fieldset');
3531

32+
fieldsets.forEach((element, index) => {
3633

37-
console.log(statePath[5]);
38-
console.log(statePath[6]);
39-
console.log(statePath[7]);
40-
console.log(statePath[8]);
41-
console.log(statePath[9]);
42-
console.log(statePath[10]);
43-
console.log(statePath[11]);
34+
element.addEventListener("change", (event) => {
35+
console.log(index);
36+
//console.log(element.id);
37+
//console.log(event.target.value);
38+
39+
console.log(element.id + '/' + event.target.value + '/' );
4440

45-
46-
console.log(last[0]);
47-
48-
console.log(license[1]);
49-
50-
51-
52-
53-
document.querySelector('#require-attribution').classList.toggle('disable');
54-
55-
document.querySelector('#allow-commercial-use').classList.toggle('disable');
56-
57-
document.querySelector('#allow-derivatives').classList.toggle('disable');
58-
59-
document.querySelector('#share-alike').classList.toggle('disable');
60-
61-
document.querySelector('#waive-your-copyright').classList.toggle('disable');
62-
63-
document.querySelector('#confirmation').classList.toggle('disable');
64-
65-
66-
67-
// Get the form
68-
const form = document.forms[0];
69-
70-
// Get the form's radio buttons
71-
const helpChoice = form.elements["choose"];
72-
73-
// Choose the "red" option
74-
console.log(helpChoice.value);
75-
76-
const selectElement = document.querySelector("#do-you-know-which-license-you-need");
77-
78-
selectElement.addEventListener("change", (event) => {
79-
console.log(helpChoice.value);
80-
81-
if (helpChoice.value == 'no') {
82-
83-
document.querySelector('#which-license-do-you-need').classList.toggle('disable');
84-
85-
} else {
86-
87-
document.querySelector('#which-license-do-you-need').classList.remove('disable');
88-
}
89-
90-
document.querySelector('#require-attribution').classList.toggle('disable');
91-
92-
document.querySelector('#allow-commercial-use').classList.toggle('disable');
93-
94-
document.querySelector('#allow-derivatives').classList.toggle('disable');
95-
96-
document.querySelector('#share-alike').classList.toggle('disable');
97-
98-
document.querySelector('#confirmation').classList.toggle('disable');
99-
});
100-
101-
102-
const licenseElement = document.querySelector("#which-license-do-you-need");
103-
104-
const licenseChoice = form.elements["license"];
105-
106-
licenseElement.addEventListener("change", (event) => {
107-
console.log(licenseChoice.value);
108-
109-
if (licenseChoice.value == 'cc-0') {
110-
111-
document.querySelector('#waive-your-copyright').classList.toggle('disable');
112-
} else {
113-
114-
document.querySelector('#waive-your-copyright').classList.add('disable');
115-
}
116-
117-
});
118-
119-
const attributionElement = document.querySelector("#require-attribution");
120-
121-
const attributionChoice = form.elements["attribution"];
122-
123-
attributionElement.addEventListener("change", (event) => {
124-
console.log(attributionChoice.value);
125-
126-
document.querySelector('#allow-commercial-use').classList.toggle('disable');
127-
128-
document.querySelector('#allow-derivatives').classList.toggle('disable');
129-
130-
document.querySelector('#share-alike').classList.toggle('disable');
131-
132-
document.querySelector('#waive-your-copyright').classList.remove('disable');
133-
134-
document.querySelector('#confirmation').classList.toggle('disable');
41+
});
13542

13643
});

0 commit comments

Comments
 (0)