diff --git a/docs/wp-content/themes/vocabulary-theme/chooser/css/chooser.css b/docs/wp-content/themes/vocabulary-theme/chooser/css/chooser.css new file mode 100644 index 00000000000..edce47ac2d1 --- /dev/null +++ b/docs/wp-content/themes/vocabulary-theme/chooser/css/chooser.css @@ -0,0 +1,367 @@ +:root { + + /* localized cc sprite names */ + --cc-by: url('../../vocabulary/svg/cc/icons/cc-icons.svg#cc-by'); + --cc-nc: url('../../vocabulary/svg/cc/icons/cc-icons.svg#cc-nc'); + --cc-nd: url('../../vocabulary/svg/cc/icons/cc-icons.svg#cc-nd'); + --cc-pd: url('../../vocabulary/svg/cc/icons/cc-icons.svg#cc-pd'); + --cc-pdm: url('../../vocabulary/svg/cc/icons/cc-icons.svg#cc-pdm'); + --cc-sa: url('../../vocabulary/svg/cc/icons/cc-icons.svg#cc-sa'); + --cc-zero: url('../../vocabulary/svg/cc/icons/cc-icons.svg#cc-zero'); +} + +.chooser-page .icon-attach.cc-by:before { + --icon-sprite: var(--cc-by); + margin-right: .2em; + margin-bottom: -.125em; +} + +.chooser-page .icon-attach.cc-nc:before { + --icon-sprite: var(--cc-nc); + margin-right: .2em; + margin-bottom: -.125em; +} + +.chooser-page .icon-attach.cc-nd:before { + --icon-sprite: var(--cc-nd); + margin-right: .2em; + margin-bottom: -.125em; +} + +.chooser-page .icon-attach.cc-pd:before { + --icon-sprite: var(--cc-pd); + margin-right: .2em; + margin-bottom: -.125em; +} + +.chooser-page .icon-attach.cc-pdm:before { + --icon-sprite: var(--cc-pdm); + margin-right: .2em; + margin-bottom: -.125em; +} + +.chooser-page .icon-attach.cc-sa:before { + --icon-sprite: var(--cc-sa); + margin-right: .2em; + margin-bottom: -.125em; +} + +.chooser-page .icon-attach.cc-zero:before { + --icon-sprite: var(--cc-zero); + margin-right: .2em; + margin-bottom: -.125em; +} + +.chooser-page dl div { + margin-bottom: .8em; +} + +.chooser-page dt, .chooser-page dd { + display: inline-block; +} + +.chooser-page dt:after { + content: ':'; +} + +.chooser-page dd { + margin-left: .2em; +} + +.chooser-page dd span { + display: block; +} + +.chooser-page ol li:has(.disable) { + display: none; +} + +.chooser-page .disable { + display: none; +} + +.chooser-page .hide { + display: none; +} + +.chooser-page .tool header { + display: flex; + flex-wrap: wrap; +} + +.chooser-page .tool header > h4 { + width: 100%; +} + +.chooser-page .tool header > .tool-icons { + order: -1; + margin: 0 1em 0 0; +} + +.chooser-page .tool .tool-icons svg { + display: inline; + width: 1.9em; + height: 1.9em; + margin-right: .3em; +} + +.chooser-page .content { + display: grid; + gap: 2em; + grid-template-columns: 1fr 2fr; +} + +.chooser-page .mark svg { + display: inline; + width: 1.3em; + height: 1.3em; +} + +.chooser-page .mark svg:first-of-type { + margin-left: .5em; +} + +.chooser-page .tool-rec-details input { + color: lightgray; +} + +.chooser-page form#chooser > ol { + position: relative; + + list-style: none; + counter-reset: chooser-counter; +} + +.chooser-page form#chooser > ol li { + counter-increment: chooser-counter; +} +.chooser-page form#chooser > ol li::before { + position: absolute; + --size: 32px; + left: calc(-1 * var(--size) - 25px); + min-height: 2em; + min-width: 2em; + padding-top: .4em; + box-sizing: border-box; + + content: counter(chooser-counter); + font-weight: bold; + border-radius: 200px; + background: var(--vocabulary-neutral-color-lighter-gray); + color: black; + text-align: center; + vertical-align: middle; +} + +.chooser-page form#chooser legend { + font-weight: bold; +} + +.chooser-page form#chooser fieldset { + margin-bottom: 1em; +} + +.chooser-page form#chooser label { + font-size: .7em; + font-weight: 400; +} + +.chooser-page form#chooser #attribution-details span { + display: inline-block; + padding: .7em 0; + + font-size: .8em; + line-height: 1.3; +} + +.chooser-page form#chooser #attribution-details div { + margin-bottom: .5em; +} + +.chooser-page form#chooser #waive-your-copyright div { + margin-bottom: 1em; +} + +.chooser-page form#chooser #attribution-details input { + padding: .2em .2em; + + font-size: 1em; +} + +.chooser-page form#chooser #atrribution-details input::placeholder { + opacity: .5; +} + +.chooser-page aside #empty { + min-height: 10em; + padding: 2em; + + background: var(--vocabulary-brand-color-soft-turquoise); + background: var(--vocabulary-neutral-color-lighter-gray); +} + +.chooser-page aside #empty p { + font-size: 1.2em; +} + +.chooser-page #tool-recommendation { + margin-bottom: 4em; + + font-family: 'Source Sans Pro'; +} + +.chooser-page #tool-recommendation .tool { + padding: 2em; + + background: var(--vocabulary-brand-color-soft-turquoise); +} + +.chooser-page #tool-recommendation .tool a { + --underline-background-color: var(--vocabulary-brand-color-soft-turquoise); +} + +.chooser-page #tool-recommendation h3 { + margin: 0; + + font-family: 'Source Sans Pro'; + font-size: 1.4em; +} + +.chooser-page #tool-recommendation h4 { + margin: .2em; + + font-family: 'Source Sans Pro'; + font-size: 1.4em; +} + +.chooser-page #tool-recommendation p { + font-size: 1.2em; +} + +.chooser-page #tool-recommendation a { + font-weight: 700; +} + +.chooser-page #tool-recommendation .conditions-definitions { + margin-bottom: 2em; + + font-family: 'Source Sans Pro'; +} + +.chooser-page #tool-recommendation .conditions-definitions dt { + font-weight: 700; +} + +.chooser-page #mark-your-work textarea { + min-height: 9em; + width: 90%; + margin: 1em; + box-sizing: border-box; +} + +.chooser-page #mark-your-work p { + font-size: 1.2em; +} + +.chooser-page details { + font-family: 'Source Sans Pro'; + + border: 2px solid var(--vocabulary-neutral-color-lighter-gray); + border-radius: 5px; +} + +.chooser-page details details { + margin: 1em; +} + +.chooser-page details.medium { + margin-bottom: 1em; +} + +.chooser-page details summary { + padding: .2em .5em; + + background: var(--vocabulary-neutral-color-lighter-gray); + font-size: 1.6em; +} + +.chooser-page details.format summary { + font-size: 1.3em; +} + +.chooser-page summary:hover { + cursor: pointer; +} + +.chooser-page summary::marker { + font-size: .8em; +} + +.chooser-page details p { + padding: 0 1em; + + font-size: 1em; +} + +.chooser-page details.format footer { + display: flex; + justify-content: space-between; + padding: 1em; +} + +.chooser-page details.format footer label { + margin-left: .2em; +} + +.chooser-page details.format footer button { + padding: .5em 1em; + + background: #324C7F; + color: white; + border-radius: 3px; + border: none; +} + +.chooser-page details.format footer button:hover { + cursor: pointer; +} + +.chooser-page .content { + grid-column: 3 / 10; +} + +.chooser-page #help { + margin-top: 4em; + } + + .chooser-page #help details { + margin-bottom: 1em; + } + + .chooser-page #help ul { + font-size: 1em; + padding: 0 1em; + } + + .chooser-page #help ul li { + padding-bottom: .5em; + } + + .chooser-page #help dl { + padding: 0 1em; + } + + +@media (max-width: 705px) { + .chooser-page .content { + display: block; + } +} + +.chooser-page .panel { + display: none; +} + +.chooser-page .panel.expand { + display: initial; +} diff --git a/docs/wp-content/themes/vocabulary-theme/chooser/js/chooser.js b/docs/wp-content/themes/vocabulary-theme/chooser/js/chooser.js new file mode 100644 index 00000000000..5b26846dc7e --- /dev/null +++ b/docs/wp-content/themes/vocabulary-theme/chooser/js/chooser.js @@ -0,0 +1,620 @@ + +// all possible State Path Routes +let rawStatePathRoutes = [ + 'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-0/waive-your-copyright+waive+read/(attribution-details)&tool=cc-0', + 'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-by/(attribution-details)&tool=cc-by', + 'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-by-sa/(attribution-details)&tool=cc-by-sa', + 'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-by-nd/(attribution-details)&tool=cc-by-nd', + 'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-by-nc/(attribution-details)&tool=cc-by-nc', + 'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-by-nc-sa/(attribution-details)&tool=cc-by-nc-sa', + 'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-by-nc-nd/(attribution-details)&tool=cc-by-nc-nd', + + 'do-you-know-which-license-you-need/no/require-attribution/yes/allow-commercial-use/yes/allow-derivatives/yes/share-alike/no/confirmation+ownership+read+revocation/(attribution-details)&tool=cc-by', + 'do-you-know-which-license-you-need/no/require-attribution/yes/allow-commercial-use/yes/allow-derivatives/yes/share-alike/yes/confirmation+ownership+read+revocation/(attribution-details)&tool=cc-by-sa', + 'do-you-know-which-license-you-need/no/require-attribution/yes/allow-commercial-use/yes/allow-derivatives/no/confirmation+ownership+read+revocation/(attribution-details)&tool=cc-by-nd', + 'do-you-know-which-license-you-need/no/require-attribution/yes/allow-commercial-use/no/allow-derivatives/yes/share-alike/no/confirmation+ownership+read+revocation/(attribution-details)&tool=cc-by-nc', + 'do-you-know-which-license-you-need/no/require-attribution/yes/allow-commercial-use/no/allow-derivatives/yes/share-alike/yes/confirmation+ownership+read+revocation/(attribution-details)&tool=cc-by-nc-sa', + 'do-you-know-which-license-you-need/no/require-attribution/yes/allow-commercial-use/no/allow-derivatives/no/confirmation+ownership+read+revocation/(attribution-details)&tool=cc-by-nc-nd', + 'do-you-know-which-license-you-need/no/require-attribution/no/waive-your-copyright+waive+read/(attribution-details)&tool=cc-0' +]; + +// empty state obj +let state = {}; + +// all found fieldsets +const fieldsets = document.querySelectorAll('fieldset'); + +// all found toggles +const toggles = document.querySelectorAll('#mark-your-work footer input'); + +// all found copiers +const copiers = document.querySelectorAll('#mark-your-work footer button'); + +// empty defaults obj +let applyDefaults = {}; + +// set elemnts which need defaults +// on initial page load +applyDefaults.elements = [ + '#require-attribution', + '#allow-commercial-use', + '#allow-derivatives', + '#share-alike', + '#waive-your-copyright', + '#confirmation' +]; + +// function to parse and build state.possibilities +// from rawStatePathRoutes +function setStatePossibilities(state) { + + // create state possibilities from possible tools with adjoining statePaths + state.possibilities = []; + rawStatePathRoutes.forEach((path, index) => { + + statePath = path.split("&"); + statepath = statePath; + tool = statePath[statePath.length - 1].split("="); + tool = tool[1]; + + regEx = /\(([^)]+)\)/g; + optionals = statePath[0].match(regEx); + + optionals.forEach ((optional) => { + + noOptionalsPath = statePath[0].replace(optional,''); + + }); + + fullPath = statePath[0].replace(/[{()}]/g, '') + '/'; + + if (state.possibilities[tool] == undefined) { + state.possibilities[tool] = []; + } + state.possibilities[tool].push(fullPath); + state.possibilities[tool].push(noOptionalsPath); + + }); +} + +// function to establish state.parts +function setStateParts(state) { + state.parts = []; + + // temp defaults + state.parts[0] = 'do-you-know-which-license-you-need/yes/'; + state.parts[8] = 'attribution-details/'; +} +// function to update state.parts +function updateStateParts(element, index, event, state) { + + state.parts[index] = element.id + '/' + event.target.value + '/'; + + // check if checkbox, with siblings + if (event.target.getAttribute('type') == 'checkbox') { + let checkboxElements = element.querySelectorAll('input[type="checkbox"]'); + let checkboxes = []; + checkboxElements.forEach((checkbox, index) => { + if (checkbox.checked) { + checkboxes[index] = checkbox.value; + } + }); + + + let joinedCheckboxes = checkboxes.filter(Boolean).join('+'); + + state.parts[index] = element.id + '+' + joinedCheckboxes + '/';; + } + + // check if text input + if (event.target.getAttribute('type') == 'text') { + + state.parts[index] = element.id + '/'; + + } +} + +// function to combine current tracked +// state.parts into state.current +function setStateCurrent(element, index, state) { + state.parts.forEach((element, i) => { + if (i > index) { + state.parts.splice(i); + } + }); + + state.current = state.parts.join('') //.slice(0, -1); +} + +// function to set state.props +// including setting state.props.tool (if valid) +// or error +function setStateProps(index, state) { + + state.props = {}; + state.props.tool = 'unknown'; + + // check and match possibilities + Object.keys(state.possibilities).forEach((possibility) => { + if(state.possibilities[possibility].includes(state.current)) { + state.props.tool = possibility; + } + }); + + // set toolFull, toolShort, toolURL + if (state.props.tool != 'unknown' && state.props.tool != 'cc-0' ) { // was OR, changes to AND + + formattedTool = state.props.tool.replace(/-/, ' ').toUpperCase(); + state.props.toolShort = formattedTool + ' 4.0'; + + // set shortName + shortName = state.props.tool.replace(/cc-/, ''); + state.props.toolURL = 'https://creativecommons.org/licenses/'+ shortName +'/4.0/'; + } + + if (state.props.tool != 'unknown' ) { + //set longName + let tool = state.props.tool; + let template = document.getElementById(tool); + let templateContent = template.content.cloneNode(true); + state.props.toolLong = templateContent.querySelector('header h4').textContent; + } + + if (state.props.tool == 'cc-0') { + + state.props.toolShort = 'CC0 1.0'; + + // set toolFull + state.props.toolURL = 'https://creativecommons.org/publicdomain/zero/1.0/'; + } + + state.props.cursor = index; + + state.props.attribution = []; + setStatePropsAttribution(state); +} + +// function to just set the attribution +// subset of state.props (for use other places) +function setStatePropsAttribution(state) { + + if (document.querySelector('#attribution-details #title').value == '') { + state.props.attribution.title = document.querySelector('#attribution-details #title').placeholder.replace(/(<([^>]+)>)/gi, ""); + } else { + state.props.attribution.title = document.querySelector('#attribution-details #title').value.replace(/(<([^>]+)>)/gi, ""); + } + + if (document.querySelector('#attribution-details #creator').value == '') { + state.props.attribution.creator = document.querySelector('#attribution-details #creator').placeholder.replace(/(<([^>]+)>)/gi, ""); + } else { + state.props.attribution.creator = document.querySelector('#attribution-details #creator').value.replace(/(<([^>]+)>)/gi, ""); + } + + if (document.querySelector('#attribution-details #work-link').value == '') { + state.props.attribution.workLink = document.querySelector('#attribution-details #work-link').placeholder.replace(/(<([^>]+)>)/gi, ""); + } else { + state.props.attribution.workLink = document.querySelector('#attribution-details #work-link').value.replace(/(<([^>]+)>)/gi, ""); + } + + if (document.querySelector('#attribution-details #creator-link').value == '') { + state.props.attribution.creatorLink = document.querySelector('#attribution-details #creator-link').placeholder.replace(/(<([^>]+)>)/gi, ""); + } else { + state.props.attribution.creatorLink = document.querySelector('#attribution-details #creator-link').value.replace(/(<([^>]+)>)/gi, ""); + } + + if (document.querySelector('#attribution-details #work-creation-year').value == '') { + state.props.attribution.workCreationYear = document.querySelector('#attribution-details #work-creation-year').placeholder.replace(/(<([^>]+)>)/gi, ""); + } else { + state.props.attribution.workCreationYear = document.querySelector('#attribution-details #work-creation-year').value.replace(/(<([^>]+)>)/gi, ""); + } +} + +// function to reset values beyond current fieldset +// [T]: this could potentially do with a refactor +// check for input type, and them perform +// contextual resets to universal defaults +// unchecked for radio/checkbox, noselect for +// selection dropdown, etc. +function clearStepsAfterCursor(fieldsets, state) { + fieldsets.forEach((element, index) => { + if (index > state.props.cursor) { + + if (index == 1) { + element.querySelector("#tool").value = "noselect"; + } + + if (index != 1 | index != 8) { + + let inputs = element.querySelectorAll('input'); + inputs.forEach((input, i) => { + input.checked = false; + }); + } + } + }); +} + +// function to render "tool recommendation", +// if valid tool from state.parts and/or state.current +function renderToolRec(state) { + + if (state.props.tool != 'unknown' ) { + document.querySelector('#tool-recommendation').classList.remove('disable'); + + let tool = state.props.tool; + let template = document.getElementById(tool); + let templateContent = template.content.cloneNode(true); + document.querySelector('#tool-recommendation .tool').textContent = ''; + document.querySelector('#tool-recommendation .tool').appendChild(templateContent); + } + else if (state.props.tool == 'unknown') { + document.querySelector('#tool-recommendation').classList.add('disable'); + document.querySelector('#tool-recommendation .tool').textContent = ''; + } + +} + +// render specifically the mark formats subsections +function renderMarkingFormats(state) { + + if (state.props.tool != 'unknown' ) {} + + setStatePropsAttribution(state); + + let attribution = state.props.attribution; + + let type = "license"; + let typeAsVerb = "licensed under"; + let copyright = ' © ' + attribution.workCreationYear; + if (state.props.tool == 'cc-0') { + type = "mark"; + typeAsVerb = "marked"; + copyright = ''; + } + + // set contents of plain text mark + // [T]: reverse use of