Skip to content

Commit 2ff11c7

Browse files
add styling and functionality to hide steps in relation to state to enable dynamic stepping
1 parent c6a8d74 commit 2ff11c7

File tree

2 files changed

+117
-16
lines changed

2 files changed

+117
-16
lines changed

src/scripts.js

Lines changed: 113 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ let state = {};
2424
// all found fieldsets
2525
const fieldsets = document.querySelectorAll('fieldset');
2626

27+
// empty defaults obj
28+
let applyDefaults = {};
29+
30+
// set elemnts which need defaults
31+
// on initial page load
32+
applyDefaults.elements = [
33+
'#require-attribution',
34+
'#allow-commercial-use',
35+
'#allow-derivatives',
36+
'#share-alike',
37+
'#waive-your-copyright',
38+
'#confirmation'
39+
];
40+
2741
// function to parse and build state.possibilities
2842
// from rawStatePathRoutes
2943
function setStatePossibilities(state) {
@@ -129,6 +143,100 @@ function setStateProps(state) {
129143

130144
}
131145

146+
// function to render "license recommendation",
147+
// if valid license from state.parts and/or state.current
148+
function renderLicenseRec(state) {
149+
document.querySelector('#license-recommendation header h3').textContent = state.props.license;
150+
}
151+
152+
// function to set default UX states on Steps
153+
// set default visibly disabled pathways
154+
155+
function setDefaults(applyDefaults) {
156+
157+
applyDefaults.elements.forEach((element) => {
158+
document.querySelector(element).classList.toggle('disable');
159+
});
160+
161+
if (state.parts[0] == 'do-you-know-which-license-you-need/yes/' ) {
162+
applyDefaults.elements.forEach((element) => {
163+
document.querySelector(element).classList.add('disable');
164+
});
165+
}
166+
}
167+
168+
// stepper logic here for what parts of form are
169+
// displayed/hidden, as state.parts and state.current
170+
// are updated
171+
function renderSteps(applyDefaults, state) {
172+
173+
// check if visitor needs help, start help pathways
174+
if (state.current == 'do-you-know-which-license-you-need/no/' ) {
175+
176+
applyDefaults.elements.forEach((element) => {
177+
document.querySelector(element).classList.remove('disable');
178+
});
179+
document.querySelector('#which-license-do-you-need').classList.toggle('disable');
180+
document.querySelector('#waive-your-copyright').classList.add('disable');
181+
182+
console.log("pass one");
183+
184+
}
185+
186+
// if visitor doesn't need help
187+
if (state.current == 'do-you-know-which-license-you-need/yes/' ) {
188+
189+
applyDefaults.elements.forEach((element) => {
190+
document.querySelector(element).classList.add('disable');
191+
});
192+
document.querySelector('#which-license-do-you-need').classList.toggle('disable');
193+
document.querySelector('#waive-your-copyright').classList.add('disable');
194+
195+
}
196+
197+
// check if cc0
198+
if (state.parts[2] == 'require-attribution/no/' || state.parts[1] == 'which-license-do-you-need/cc-0/' ) {
199+
200+
applyDefaults.elements.forEach((element) => {
201+
document.querySelector(element).classList.add('disable');
202+
});
203+
204+
//if (state.parts[0] == 'do-you-know-which-license-you-need/no/') {
205+
//document.querySelector('#require-attribution').classList.remove('disable');
206+
//}
207+
document.querySelector('#waive-your-copyright').classList.remove('disable');
208+
209+
} else {
210+
document.querySelector('#waive-your-copyright').classList.add('disable');
211+
}
212+
if (state.parts[2] == 'require-attribution/no/') {
213+
document.querySelector('#require-attribution').classList.remove('disable');
214+
//document.querySelector('#confirmation').classList.remove('disable');
215+
}
216+
217+
// walk away from cc-0, reset attribution choice point
218+
if (state.parts[2] == 'require-attribution/yes/') {
219+
applyDefaults.elements.forEach((element) => {
220+
document.querySelector(element).classList.remove('disable');
221+
});
222+
document.querySelector('#require-attribution').classList.remove('disable');
223+
document.querySelector('#waive-your-copyright').classList.add('disable');
224+
225+
//document.querySelector('#confirmation').classList.remove('disable');
226+
}
227+
228+
// tie SA to ND choice
229+
if (state.parts[4] == 'allow-derivatives/no/') {
230+
document.querySelector('#share-alike').classList.add('disable');
231+
}
232+
233+
}
234+
235+
// function to render "mark your work", from attribution fields
236+
// if valid license from state.parts and/or state.current
237+
238+
// function to handle error state
239+
132240
// function to watch for fieldset changes
133241
function watchFieldsets(fieldsets, state) {
134242
fieldsets.forEach((element, index) => {
@@ -148,28 +256,14 @@ function watchFieldsets(fieldsets, state) {
148256
console.log("state.props (after change)");
149257
console.log(state.props);
150258

259+
renderSteps(applyDefaults, state);
260+
151261
renderLicenseRec(state);
152262
});
153263

154264
});
155265
}
156266

157-
// stepper logic here for what parts of form are
158-
// displayed/hidden, as state.parts and state.current
159-
// are updated
160-
161-
// function to render "license recommendation",
162-
// if valid license from state.parts and/or state.current
163-
function renderLicenseRec(state) {
164-
document.querySelector('#license-recommendation header h3').textContent = state.props.license;
165-
}
166-
167-
// function to render "mark your work", from attribution fields
168-
// if valid license from state.parts and/or state.current
169-
170-
// function to handle error state
171-
172-
173267
// full flow logic
174268
setStateParts(state);
175269
console.log("state.parts (at default)");
@@ -179,4 +273,7 @@ setStatePossibilities(state);
179273
console.log("state.possibilities");
180274
console.log(state.possibilities);
181275

276+
setDefaults(applyDefaults);
277+
console.log("initial defaults applied");
278+
182279
watchFieldsets(fieldsets, state);

src/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ dd {
7474
margin-left: .2em;
7575
}
7676

77+
ol li:has(.disable) {
78+
display: none;
79+
}
80+
7781

7882
.license header {
7983
display: flex;

0 commit comments

Comments
 (0)