|
| 1 | +(() => { |
| 2 | + const SELECTOR_MODAL = '#generalModal'; |
| 3 | + const SELECTOR_COPY_BUTTON = '.copy-button'; |
| 4 | + const SELECTOR_ALERT_SUCCESS = '#general-alert-success'; |
| 5 | + |
| 6 | + function handleCopyButtons(generalModal) { |
| 7 | + const alertSuccessDiv = generalModal.querySelector(SELECTOR_ALERT_SUCCESS); |
| 8 | + const copyButtons = generalModal.querySelectorAll(SELECTOR_COPY_BUTTON); |
| 9 | + if (!navigator.clipboard || !navigator.clipboard.writeText) { |
| 10 | + console.info('"navigator.clipboard.writeText" is not available. Update to a modern browser to copy code to the system\'s clipboard'); |
| 11 | + copyButtons.forEach(button => button.disabled = true); |
| 12 | + } else { |
| 13 | + copyButtons.forEach(button => { |
| 14 | + button.addEventListener('click', function () { |
| 15 | + const targetId = this.getAttribute('data-target'); |
| 16 | + const targetElement = generalModal.querySelector(`#${targetId}`); |
| 17 | + if (!targetElement) { |
| 18 | + console.warn('Cannot copy link as no input is available!'); |
| 19 | + return; |
| 20 | + } |
| 21 | + alertSuccessDiv.classList.remove('d-none'); |
| 22 | + alertSuccessDiv.innerHTML = `Path <code>${htmlEscape(targetElement.value)}</code> was copied to your clipboard.`; |
| 23 | + navigator.clipboard.writeText(targetElement.value); |
| 24 | + }); |
| 25 | + }); |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + function htmlEscape(text) { |
| 30 | + const div = document.createElement('div'); |
| 31 | + div.textContent = text; |
| 32 | + return div.innerHTML; |
| 33 | + } |
| 34 | + |
| 35 | + const generalModal = document.querySelector(SELECTOR_MODAL); |
| 36 | + if (generalModal) { |
| 37 | + generalModal.addEventListener('show.bs.modal', function (event) { |
| 38 | + const item = event.relatedTarget; |
| 39 | + if (!item.dataset.filename) { |
| 40 | + return; |
| 41 | + } |
| 42 | + const generalModalLabel = generalModal.querySelector('#generalModalLabel'); |
| 43 | + const content = generalModal.querySelector('#generalModalContent'); |
| 44 | + generalModalLabel.innerText = item.dataset.filename; |
| 45 | + if (item.dataset.scope) { |
| 46 | + generalModalLabel.innerText += ' (' + item.dataset.scope + ')'; |
| 47 | + } |
| 48 | + handleCopyButtons(generalModal); |
| 49 | + content.innerHTML = ''; |
| 50 | + if (item.dataset.shortdescription) { |
| 51 | + content.innerHTML += `<p>${item.dataset.shortdescription}</p>`; |
| 52 | + } |
| 53 | + content.innerHTML += ` |
| 54 | + <div class="mb-3"> |
| 55 | + <label class="form-label" for="composer-path">Path in Composer-based TYPO3 Installations: </label> |
| 56 | + <div class="input-group"> |
| 57 | + <textarea class="form-control code" id="composer-path" readonly>${item.dataset.composerpath}${item.dataset.filename}</textarea> |
| 58 | + <button type="button" class="btn btn-outline-secondary copy-button" data-target="composer-path"><i class="far fa-clone"></i></button> |
| 59 | + </div> |
| 60 | + <p>Example: <code>${item.dataset.composerpathprefix}${item.dataset.composerpath}${item.dataset.filename}</code></p> |
| 61 | + </div> |
| 62 | + <div class="mb-3"> |
| 63 | + <label class="form-label" for="classic-path">Path in Classic TYPO3 Installations: </label> |
| 64 | + <div class="input-group"> |
| 65 | + <textarea class="form-control code" id="classic-path" readonly>${item.dataset.classicpath}${item.dataset.filename}</textarea> |
| 66 | + <button type="button" class="btn btn-outline-secondary copy-button" data-target="classic-path"><i class="far fa-clone"></i></button> |
| 67 | + </div> |
| 68 | + <p>Example: <code>${item.dataset.classicpathprefix}${item.dataset.classicpath}${item.dataset.filename}</code></p> |
| 69 | + </div> |
| 70 | + `; |
| 71 | + var links = ''; |
| 72 | + if (item.dataset.source) { |
| 73 | + const url = new URL(item.dataset.source); |
| 74 | + var srcString = 'Source'; |
| 75 | + if (url.hostname === 'github.com') { |
| 76 | + srcString = 'GitHub'; |
| 77 | + } |
| 78 | + if (url.hostname === 'gitlab.com') { |
| 79 | + srcString = 'GitLab'; |
| 80 | + } |
| 81 | + links += `<a class="btn btn-light" href="${item.dataset.source}">${srcString}</a>`; |
| 82 | + } |
| 83 | + if (item.dataset.issues) { |
| 84 | + links += `<a class="btn btn-light" href="${item.dataset.issues}">Report issue</a>`; |
| 85 | + } |
| 86 | + if (links) { |
| 87 | + content.innerHTML += `<div class="btn-group mt-2" role="group" aria-label="Links to GitHub / GitLab">${links}</div>`; |
| 88 | + } |
| 89 | + const generalModalCustomButtons = generalModal.querySelector('#generalModalCustomButtons'); |
| 90 | + |
| 91 | + // Add more buttons to the modal footer |
| 92 | + generalModalCustomButtons.innerHTML = ` |
| 93 | + <a href="${item.href}" class="btn btn-default"><i class="fa-solid fa-arrow-right"></i> Documentation</a> |
| 94 | + `; |
| 95 | + if (item.dataset.documentation) { |
| 96 | + const url = new URL(item.dataset.documentation); |
| 97 | + const isExternal = url.hostname !== 'docs.typo3.org'; |
| 98 | + generalModalCustomButtons.innerHTML += ` |
| 99 | + <a href="${item.dataset.documentation}" class="btn btn-default"> |
| 100 | + <i class="fa-solid fa-book"></i> Documentation ${isExternal ? '(external)' : ''} |
| 101 | + </a> |
| 102 | + `; |
| 103 | + } |
| 104 | + if (item.dataset.homepage) { |
| 105 | + const url = new URL(item.dataset.homepage); |
| 106 | + const isTER = url.hostname === 'extensions.typo3.org'; |
| 107 | + if (isTER) { |
| 108 | + generalModalCustomButtons.innerHTML += ` |
| 109 | + <a href="${item.dataset.homepage}" class="btn btn-default"> |
| 110 | + <i class="fa-brands fa-typo3"></i> TER |
| 111 | + </a> |
| 112 | + `; |
| 113 | + } |
| 114 | + } |
| 115 | + handleCopyButtons(generalModal); |
| 116 | + }); |
| 117 | + } |
| 118 | +})(); |
0 commit comments