Skip to content

Commit a7f41b8

Browse files
Merge pull request #563 from creativecommons/render-marking
render "mark you work" section, add logic and `state` to support
2 parents 3d280de + f2f926e commit a7f41b8

File tree

3 files changed

+122
-4
lines changed

3 files changed

+122
-4
lines changed

src/index.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ <h2>Mark Your Work</h2>
347347
<p>Choose the kind of work to get appropriate license code or public domain marking.</p>
348348
</header>
349349

350-
<h3>Website</h3>
350+
<!-- <h3>Website</h3>
351351
<p>If you are licensing or marking one work, paste the code next to it. If you are licensing or marking the whole page or blog, you can paste the code at the bottom of the page.</p>
352352
353353
<h4>Rich Text</h4>
@@ -357,13 +357,13 @@ <h4>HTML</h4>
357357
<p>[contextually formatted mark here]</p>
358358
359359
<h4>XMP</h4>
360-
<p>[contextually formatted mark here]</p>
360+
<p>[contextually formatted mark here]</p> -->
361361

362362
<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>[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: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,46 @@ function setStateProps(index, state) {
140140
}
141141
});
142142

143+
// set licenseFull, licenseShort, licenseURL
144+
if (state.props.license != 'unknown' | state.props.license != 'cc-0' ) {
145+
146+
formattedLicense = state.props.license.replace(/-/, ' ').toUpperCase();
147+
state.props.licenseShort = formattedLicense + ' 4.0';
148+
149+
// set licenseFhort
150+
151+
shortName = state.props.license.replace(/cc-/, '');
152+
state.props.licenseURL = 'https://creativecommons.org/licenses/'+ shortName +'/4.0/';
153+
}
154+
155+
if (state.props.license == 'cc-0') {
156+
157+
state.props.licenseShort = 'CC0 1.0';
158+
159+
// set licenseFull
160+
161+
state.props.licenseURL = 'https://creativecommons.org/publicdomain/zero/1.0/';
162+
}
163+
164+
165+
166+
143167
state.props.cursor = index;
144168
console.log('cursor at:');
145169
console.log(index);
146170

171+
state.props.attribution = [];
172+
setStatePropsAttribution(state);
173+
}
174+
175+
// isolated function to just set the attribution
176+
// subset of state.props (for use other places)
177+
function setStatePropsAttribution(state) {
178+
state.props.attribution.title = document.querySelector('#attribution-details #title').value;
179+
state.props.attribution.creator = document.querySelector('#attribution-details #creator').value;
180+
state.props.attribution.workLink = document.querySelector('#attribution-details #work-link').value;
181+
state.props.attribution.creatorLink = document.querySelector('#attribution-details #creator-link').value;
182+
state.props.attribution.workCreationYear = document.querySelector('#attribution-details #work-creation-year').value;
147183
}
148184

149185
// function to reset values beyond current fieldset
@@ -199,6 +235,59 @@ function renderLicenseRec(state) {
199235
}
200236
}
201237

238+
// render specifically the mark formats subsections
239+
function renderMarkingFormats(state) {
240+
241+
242+
if (state.props.license != 'unknown' ) {}
243+
244+
setStatePropsAttribution(state);
245+
246+
//let title = state.props.attribution.title;
247+
//let workCreationYear = state.props.attribution.workCreationYear;
248+
249+
//let phrase = '(c) ' + workCreationYear + ' ' + title + ' is licensed under ';
250+
251+
let attribution = state.props.attribution;
252+
253+
let type = "licensed under";
254+
if (state.props.license == 'cc-0') {
255+
type = "marked";
256+
}
257+
258+
let mark = attribution.title + ' © ' + attribution.workCreationYear + ' by ' + attribution.creator + ' is ' + type + ' ' + state.props.licenseShort + '. To view a copy of this license, visit ' + state.props.licenseURL;
259+
260+
document.querySelector('#mark-your-work .plain-text.mark').textContent = mark;
261+
}
262+
263+
264+
265+
// function to render "mark your work",
266+
// if valid license from state.parts and/or state.current
267+
// if attribution details input(s) filled out
268+
function renderMarkYourWork(state) {
269+
if (state.props.license != 'unknown' ) {
270+
// load attribution details template,
271+
// populate from attribution text values
272+
document.querySelector('#mark-your-work').classList.remove('disable');
273+
274+
//state.props.attribution.title
275+
// let title = state.props.attribution.title;
276+
// let workCreationYear = state.props.attribution.workCreationYear;
277+
278+
// let phrase = '(c) ' + workCreationYear + ' ' + title + ' is licensed under ';
279+
280+
// document.querySelector('#mark-your-work .mark-holder').textContent = phrase + state.props.license;
281+
renderMarkingFormats(state);
282+
283+
}
284+
285+
else if (state.props.license == 'unknown') {
286+
document.querySelector('#mark-your-work').classList.add('disable');
287+
}
288+
289+
}
290+
202291
// function to set default UX states on Steps
203292
// set default visibly disabled pathways
204293

@@ -215,6 +304,7 @@ function setDefaults(applyDefaults) {
215304
}
216305

217306
document.querySelector('#license-recommendation').classList.add('disable');
307+
document.querySelector('#mark-your-work').classList.add('disable');
218308
}
219309

220310
// stepper logic here for what parts of form are
@@ -316,6 +406,26 @@ function watchFieldsets(fieldsets, state) {
316406
renderSteps(applyDefaults, state);
317407

318408
renderLicenseRec(state);
409+
410+
renderMarkYourWork(state);
411+
412+
console.log(state.props.licenseShort);
413+
414+
});
415+
416+
});
417+
}
418+
419+
function watchAttributionDetails(fieldsets, state) {
420+
421+
let textFields = fieldsets[8].querySelectorAll('input');
422+
423+
textFields.forEach((element, index) => {
424+
425+
element.addEventListener("keyup", (event) => {
426+
console.log('typing is happening');
427+
428+
renderMarkingFormats(state);
319429
});
320430

321431
});
@@ -333,4 +443,8 @@ console.log(state.possibilities);
333443
setDefaults(applyDefaults);
334444
console.log("initial defaults applied");
335445

446+
setStateProps(0, state);
447+
console.log("initial defaults applied");
448+
336449
watchFieldsets(fieldsets, state);
450+
watchAttributionDetails(fieldsets, state);

src/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,6 @@ ol li:has(.disable) {
111111

112112

113113
/* debug styles */
114-
#mark-your-work, .help {
114+
.help {
115115
display: none;
116116
}

0 commit comments

Comments
 (0)