Skip to content

Commit 9bc594f

Browse files
add functions for mark handling, add new watcher for keyup on attribution text inputs in addition to general fieldset change
1 parent e010c3d commit 9bc594f

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

src/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ <h3>Print Work or Media</h3>
363363
<p>Copy the text below and paste it on the title and/or copyright page of your print work or presentation, or in the credits of your media.</p>
364364

365365
<h4>Plain Text</h4>
366-
<p class="mark-holder">[contextually formatted mark here]</p>
366+
<p class="plain-text mark">[contextually formatted mark here]</p>
367367

368368
<footer>
369369
<p>[toggle: (license abbreviation) | (full license name)]</p>
@@ -711,5 +711,9 @@ <h4>Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International</
711711
<a href="https://creativecommons.org/licenses/by-nc-nd/4.0/?ref=chooser-v2">See the License Deed</a>
712712
</template>
713713

714+
<template id="plain-text" class="mark">
715+
<p></p>
716+
</template>
717+
714718
</body>
715719
</html>

src/scripts.js

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,17 @@ function setStateProps(index, state) {
145145
console.log(index);
146146

147147
state.props.attribution = [];
148+
setStatePropsAttribution(state);
149+
}
150+
151+
// isolated function to just set the attribution
152+
// subset of state.props (for use other places)
153+
function setStatePropsAttribution(state) {
148154
state.props.attribution.title = document.querySelector('#attribution-details #title').value;
149155
state.props.attribution.creator = document.querySelector('#attribution-details #creator').value;
150156
state.props.attribution.workLink = document.querySelector('#attribution-details #work-link').value;
151157
state.props.attribution.creatorLink = document.querySelector('#attribution-details #creator-link').value;
152158
state.props.attribution.workCreationYear = document.querySelector('#attribution-details #work-creation-year').value;
153-
154159
}
155160

156161
// function to reset values beyond current fieldset
@@ -206,6 +211,24 @@ function renderLicenseRec(state) {
206211
}
207212
}
208213

214+
// render specifically the mark formats subsections
215+
function renderMarkingFormats(state) {
216+
217+
218+
if (state.props.license != 'unknown' ) {}
219+
220+
setStatePropsAttribution(state);
221+
222+
let title = state.props.attribution.title;
223+
let workCreationYear = state.props.attribution.workCreationYear;
224+
225+
let phrase = '(c) ' + workCreationYear + ' ' + title + ' is licensed under ';
226+
227+
document.querySelector('#mark-your-work .plain-text.mark').textContent = phrase + state.props.license;
228+
}
229+
230+
231+
209232
// function to render "mark your work",
210233
// if valid license from state.parts and/or state.current
211234
// if attribution details input(s) filled out
@@ -216,17 +239,18 @@ function renderMarkYourWork(state) {
216239
document.querySelector('#mark-your-work').classList.remove('disable');
217240

218241
//state.props.attribution.title
219-
let title = state.props.attribution.title;
220-
let workCreationYear = state.props.attribution.workCreationYear;
242+
// let title = state.props.attribution.title;
243+
// let workCreationYear = state.props.attribution.workCreationYear;
221244

222-
let phrase = '(c) ' + workCreationYear + ' ' + title + ' is licensed under ';
245+
// let phrase = '(c) ' + workCreationYear + ' ' + title + ' is licensed under ';
223246

224-
document.querySelector('#mark-your-work .mark-holder').textContent = phrase + state.props.license;
247+
// document.querySelector('#mark-your-work .mark-holder').textContent = phrase + state.props.license;
248+
renderMarkingFormats(state);
225249

226250
}
227251

228252
else if (state.props.license == 'unknown') {
229-
// set to empty
253+
document.querySelector('#mark-your-work').classList.add('disable');
230254
}
231255

232256
}
@@ -351,6 +375,22 @@ function watchFieldsets(fieldsets, state) {
351375
renderLicenseRec(state);
352376

353377
renderMarkYourWork(state);
378+
379+
});
380+
381+
});
382+
}
383+
384+
function watchAttributionDetails(fieldsets, state) {
385+
386+
let textFields = fieldsets[8].querySelectorAll('input');
387+
388+
textFields.forEach((element, index) => {
389+
390+
element.addEventListener("keyup", (event) => {
391+
console.log('typing is happening');
392+
393+
renderMarkingFormats(state);
354394
});
355395

356396
});
@@ -368,4 +408,8 @@ console.log(state.possibilities);
368408
setDefaults(applyDefaults);
369409
console.log("initial defaults applied");
370410

411+
setStateProps(0, state);
412+
console.log("initial defaults applied");
413+
371414
watchFieldsets(fieldsets, state);
415+
watchAttributionDetails(fieldsets, state);

0 commit comments

Comments
 (0)