Skip to content

Commit 2660f08

Browse files
add better filtering of input values, add logic for rich text iconSet display matching tool rec
1 parent e29e557 commit 2660f08

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

src/scripts.js

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,15 @@ function setStateProps(index, state) {
172172
setStatePropsAttribution(state);
173173
}
174174

175+
175176
// isolated function to just set the attribution
176177
// subset of state.props (for use other places)
177178
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;
179+
state.props.attribution.title = document.querySelector('#attribution-details #title').value.replace(/(<([^>]+)>)/gi, "");
180+
state.props.attribution.creator = document.querySelector('#attribution-details #creator').value.replace(/(<([^>]+)>)/gi, "");
181+
state.props.attribution.workLink = document.querySelector('#attribution-details #work-link').value.replace(/(<([^>]+)>)/gi, "");
182+
state.props.attribution.creatorLink = document.querySelector('#attribution-details #creator-link').value.replace(/(<([^>]+)>)/gi, "");
183+
state.props.attribution.workCreationYear = document.querySelector('#attribution-details #work-creation-year').value.replace(/(<([^>]+)>)/gi, "");
183184
}
184185

185186
// function to reset values beyond current fieldset
@@ -294,9 +295,42 @@ function renderMarkingFormats(state) {
294295
//templateContent.textContent = parseTokens("year", attribution.workCreationYear, templateContent.textContent);
295296
//document.querySelector('#mark-your-work .plain-text.mark').appendChild(templateContent);
296297

297-
298298
// set contents of rich text mark
299-
let richTextMark = attribution.title + ' © ' + attribution.workCreationYear + ' by ' + attribution.creator + ' is ' + typeAsVerb + ' ' + '<a href="#">' + state.props.toolShort + '</a> <svg><use href="vocabulary/svg/cc/icons/cc-icons.svg#cc-logo"></use></svg> <svg><use href="vocabulary/svg/cc/icons/cc-icons.svg#cc-by"></use></svg> <svg><use href="vocabulary/svg/cc/icons/cc-icons.svg#cc-sa"></use></svg> ';
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>';
305+
306+
const currentTool = state.props.tool;
307+
switch (currentTool) {
308+
case 'cc-0':
309+
ccIconSet = ccSVG + zeroSVG;
310+
break;
311+
case 'cc-by':
312+
ccIconSet = ccSVG + bySVG;
313+
break;
314+
case 'cc-by-sa':
315+
ccIconSet = ccSVG + bySVG + saSVG;
316+
break;
317+
case 'cc-by-nd':
318+
ccIconSet = ccSVG + bySVG + ndSVG;
319+
break;
320+
case 'cc-by-nc':
321+
ccIconSet = ccSVG + bySVG + ncSVG;
322+
break;
323+
case 'cc-by-nc-sa':
324+
ccIconSet = ccSVG + bySVG + ncSVG + saSVG;
325+
break;
326+
case 'cc-by-nc-nd':
327+
ccIconSet = ccSVG + bySVG + ncSVG + ndSVG;
328+
break;
329+
default:
330+
currentTool = '';
331+
}
332+
333+
let richTextMark = attribution.title + ' © ' + attribution.workCreationYear + ' by ' + attribution.creator + ' is ' + typeAsVerb + ' ' + '<a href="#">' + state.props.toolShort + '</a>' + ccIconSet;
300334
document.querySelector('#mark-your-work .rich-text.mark').innerHTML = richTextMark;
301335

302336

src/style.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ ol li:has(.disable) {
109109
grid-template-columns: 1fr 1fr;
110110
}
111111

112+
.mark svg {
113+
display: inline;
114+
/* font-size: 1em; */
115+
width: 1.3em;
116+
height: 1.3em;
117+
}
118+
112119

113120
/* debug styles */
114121
.help {

0 commit comments

Comments
 (0)