Skip to content

Commit f57f94f

Browse files
add long name toggles, events, watchers, markProps
1 parent 00a04a5 commit f57f94f

File tree

3 files changed

+100
-45
lines changed

3 files changed

+100
-45
lines changed

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ <h4>Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International</
801801
</template>
802802

803803
<template id="plain-text" class="mark">
804-
<p>{{title}} © {{year}} by {{creator}} is {{typeAsVerb}} {{toolShort}}. To view a copy of this {{type}}, visit {{toolURL}}</p>
804+
<p>{{title}} © {{year}} by {{creator}} is {{typeAsVerb}} {{toolName}}. To view a copy of this {{type}}, visit {{toolURL}}</p>
805805
</template>
806806

807807
</body>

src/scripts.js

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

27+
// all found toggles
28+
const toggles = document.querySelectorAll('#mark-your-work footer input');
29+
2730
// empty defaults obj
2831
let applyDefaults = {};
2932

@@ -141,35 +144,39 @@ function setStateProps(index, state) {
141144
});
142145

143146
// set toolFull, toolShort, toolURL
144-
if (state.props.tool != 'unknown' | state.props.tool != 'cc-0' ) {
147+
if (state.props.tool != 'unknown' && state.props.tool != 'cc-0' ) { // was OR, changes to AND
145148

146149
formattedTool = state.props.tool.replace(/-/, ' ').toUpperCase();
147150
state.props.toolShort = formattedTool + ' 4.0';
148151

149-
// set toolShort
150-
152+
// set shortName
151153
shortName = state.props.tool.replace(/cc-/, '');
152154
state.props.toolURL = 'https://creativecommons.org/licenses/'+ shortName +'/4.0/';
153155
}
154156

157+
if (state.props.tool != 'unknown' ) {
158+
//set longName
159+
let tool = state.props.tool;
160+
let template = document.getElementById(tool);
161+
let templateContent = template.content.cloneNode(true);
162+
state.props.toolLong = templateContent.querySelector('header h4').textContent;
163+
}
164+
155165
if (state.props.tool == 'cc-0') {
156166

157167
state.props.toolShort = 'CC0 1.0';
158168

159169
// set toolFull
160-
161170
state.props.toolURL = 'https://creativecommons.org/publicdomain/zero/1.0/';
162171
}
163172

164-
165-
166-
167173
state.props.cursor = index;
168174
console.log('cursor at:');
169175
console.log(index);
170176

171177
state.props.attribution = [];
172178
setStatePropsAttribution(state);
179+
173180
}
174181

175182

@@ -279,29 +286,40 @@ function renderMarkingFormats(state) {
279286
markProps.type = type;
280287
markProps.typeAsVerb = typeAsVerb;
281288
markProps.toolShort = state.props.toolShort;
289+
markProps.toolLong = state.props.toolLong;
282290
markProps.toolURL = state.props.toolURL;
283291

292+
293+
// set contents of plain text mark
294+
plainTextFullName = document.querySelector('#plain-text-full-name').checked;
295+
296+
if (plainTextFullName == true) {
297+
markProps.toolName = state.props.toolLong;
298+
299+
} else {
300+
markProps.toolName = state.props.toolShort;
301+
}
302+
284303
// could carve out separate sections for different mark formats here
285304
// only handles plain text at the moment
286305
for (const [key, value] of Object.entries(markProps)) {
287306
templateContent.textContent = parseTokens(key, value, templateContent.textContent);
288307
console.log(`${key}: ${value}`);
289308
console.log(templateContent);
290309
}
291-
292310
document.querySelector('#mark-your-work .plain-text.mark').appendChild(templateContent);
293311

294312

295313
//templateContent.textContent = parseTokens("year", attribution.workCreationYear, templateContent.textContent);
296314
//document.querySelector('#mark-your-work .plain-text.mark').appendChild(templateContent);
297315

298316
// set contents of rich text mark
299-
let ccSVG = '<svg><use href="vocabulary/svg/cc/icons/cc-icons.svg#cc-logo"></use></svg>';
300-
let bySVG = '<svg><use href="vocabulary/svg/cc/icons/cc-icons.svg#cc-by"></use></svg>';
301-
let saSVG = '<svg><use href="vocabulary/svg/cc/icons/cc-icons.svg#cc-sa"></use></svg>';
302-
let ncSVG = '<svg><use href="vocabulary/svg/cc/icons/cc-icons.svg#cc-nc"></use></svg>';
303-
let ndSVG = '<svg><use href="vocabulary/svg/cc/icons/cc-icons.svg#cc-nd"></use></svg>';
304-
let zeroSVG = '<svg><use href="vocabulary/svg/cc/icons/cc-icons.svg#cc-zero"></use></svg>';
317+
let ccSVG = '<img src="https://mirrors.creativecommons.org/presskit/icons/cc.svg" style="max-width: 1em;max-height:1em;margin-left: .2em;">';
318+
let bySVG = '<img src="https://mirrors.creativecommons.org/presskit/icons/by.svg" style="max-width: 1em;max-height:1em;margin-left: .2em;">';
319+
let saSVG = '<img src="https://mirrors.creativecommons.org/presskit/icons/sa.svg" style="max-width: 1em;max-height:1em;margin-left: .2em;">';
320+
let ncSVG = '<img src="https://mirrors.creativecommons.org/presskit/icons/nc.svg" style="max-width: 1em;max-height:1em;margin-left: .2em;">';
321+
let ndSVG = '<img src="https://mirrors.creativecommons.org/presskit/icons/nd.svg" style="max-width: 1em;max-height:1em;margin-left: .2em;">';
322+
let zeroSVG = '<img src="https://mirrors.creativecommons.org/presskit/icons/cc-zero.svg" style="max-width: 1em;max-height:1em;margin-left: .2em;">';
305323

306324
const currentTool = state.props.tool;
307325
switch (currentTool) {
@@ -330,11 +348,28 @@ function renderMarkingFormats(state) {
330348
currentTool = '';
331349
}
332350

333-
let richTextMark = attribution.title + ' © ' + attribution.workCreationYear + ' by ' + attribution.creator + ' is ' + typeAsVerb + ' ' + '<a href="' + state.props.toolURL + '">' + state.props.toolShort + '</a>' + ccIconSet;
351+
richTextFullName = document.querySelector('#rich-text-full-name').checked;
352+
353+
if (richTextFullName == true) {
354+
markProps.toolName = state.props.toolLong;
355+
356+
} else {
357+
markProps.toolName = state.props.toolShort;
358+
}
359+
360+
let richTextMark = attribution.title + ' © ' + attribution.workCreationYear + ' by ' + attribution.creator + ' is ' + typeAsVerb + ' ' + '<a href="' + state.props.toolURL + '">' + markProps.toolName + '</a>' + ccIconSet;
334361
document.querySelector('#mark-your-work .rich-text.mark').innerHTML = richTextMark;
335362

336363

337364
// set contents of HTML mark
365+
htmlFullName = document.querySelector('#html-full-name').checked;
366+
367+
if (htmlFullName == true) {
368+
markProps.toolName = state.props.toolLong;
369+
370+
} else {
371+
markProps.toolName = state.props.toolShort;
372+
}
338373
defaultHTML = '<p xmlns:cc="http://creativecommons.org/ns#">This work is licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="license noopener noreferrer">CC BY-SA 4.0<img src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1" alt=""><img src="https://mirrors.creativecommons.org/presskit/icons/by.svg" alt=""><img src="https://mirrors.creativecommons.org/presskit/icons/sa.svg" alt=""></a></p>';
339374
let htmlMark = '<textarea readonly="true">' + defaultHTML + '</textarea>';
340375
document.querySelector('#mark-your-work .html.mark').innerHTML = htmlMark;
@@ -534,24 +569,44 @@ function watchAttributionDetails(fieldsets, state) {
534569
});
535570
}
536571

537-
// full flow logic
538-
setStateParts(state);
539-
console.log("state.parts (at default)");
540-
console.log(state.parts);
572+
function watchMarkToggles(toggles, state) {
573+
574+
toggles.forEach((element, index) => {
575+
576+
element.addEventListener("click", (event) => {
577+
console.log('toggling is happening');
578+
579+
renderMarkingFormats(state);
580+
});
581+
582+
});
583+
}
584+
541585

542-
setStatePossibilities(state);
543-
console.log("state.possibilities");
544-
console.log(state.possibilities);
545586

546-
setDefaults(applyDefaults);
547-
console.log("initial defaults applied");
548587

549-
setStateProps(0, state);
550-
console.log("initial defaults applied");
588+
document.addEventListener("DOMContentLoaded", (event) => {
589+
// full flow logic
590+
setStateParts(state);
591+
console.log("state.parts (at default)");
592+
console.log(state.parts);
593+
594+
setStatePossibilities(state);
595+
console.log("state.possibilities");
596+
console.log(state.possibilities);
597+
598+
setDefaults(applyDefaults);
599+
console.log("initial defaults applied");
551600

552-
watchFieldsets(fieldsets, state);
553-
watchAttributionDetails(fieldsets, state);
601+
setStateProps(0, state);
602+
console.log("initial defaults applied");
554603

604+
watchFieldsets(fieldsets, state);
605+
watchAttributionDetails(fieldsets, state);
606+
watchMarkToggles(toggles, state);
607+
608+
console.log("DOM fully loaded and parsed");
609+
});
555610

556611

557612
// rough panel expansion test

src/style.css

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,24 +141,24 @@ form#chooser > ol {
141141
}
142142

143143
form#chooser > ol li {
144-
counter-increment: chooser-counter;
144+
counter-increment: chooser-counter;
145145
}
146146
form#chooser > ol li::before {
147-
position: absolute;
148-
--size: 32px;
149-
left: calc(-1 * var(--size) - 25px);
150-
min-height: 2em;
151-
min-width: 2em;
152-
padding-top: .4em;
153-
box-sizing: border-box;
154-
155-
content: counter(chooser-counter);
156-
font-weight: bold;
157-
border-radius: 200px;
158-
background: var(--vocabulary-neutral-color-lighter-gray);
159-
color: black;
160-
text-align: center;
161-
vertical-align: middle;
147+
position: absolute;
148+
--size: 32px;
149+
left: calc(-1 * var(--size) - 25px);
150+
min-height: 2em;
151+
min-width: 2em;
152+
padding-top: .4em;
153+
box-sizing: border-box;
154+
155+
content: counter(chooser-counter);
156+
font-weight: bold;
157+
border-radius: 200px;
158+
background: var(--vocabulary-neutral-color-lighter-gray);
159+
color: black;
160+
text-align: center;
161+
vertical-align: middle;
162162

163163
}
164164

0 commit comments

Comments
 (0)