diff --git a/assets/js/helper.mjs b/assets/js/helper.mjs new file mode 100644 index 00000000..9e22f548 --- /dev/null +++ b/assets/js/helper.mjs @@ -0,0 +1,122 @@ +// helper.mjs + +/** + * Copies the text content of an HTML element to the clipboard. + * @async + * @function clipText + * @param {string} [id=""] - The ID of the HTML element to copy the text from. + * @throws {Error} Throws an error if the specified element is missing. + * @returns {Promise} A Promise that resolves when the text has been copied to the clipboard. + */ +export async function clipText(id = ``) { + const element = document.getElementById(id); + if (element === null) { + throw Error(`select text element "${id}" is missing`); + } + element.focus(); // select the element to avoid NotAllowedError: Clipboard write is not allowed in this context + await navigator.clipboard.writeText(`${element.textContent}`).then( + function () { + console.log( + `Copied ${humanFilesize(element.textContent.length)} to the clipboard` + ); + const button = document.getElementById(`copyReadme`), + oneSecond = 1000; + if (button === null) return; + const save = button.textContent; + button.textContent = `✓ Copied`; + window.setTimeout(() => { + button.textContent = `${save}`; + }, oneSecond); + }, + function (err) { + console.error(`could not save any text to the clipboard: ${err}`); + } + ); +} + +/** + * Retrieves an element from the DOM using its ID. + * + * @param {string} elementId - The ID of the element to retrieve. + * @returns {HTMLElement} - The retrieved element. + * @throws {Error} - If the element is not found in the DOM. + */ +export function getElmById(elementId) { + const element = document.getElementById(elementId); + if (element == null) { + throw new Error(`The ${elementId} element is null.`); + } + return element; +} + +/** + * Converts a file size in bytes to a human-readable format. + * + * @param {number} size - The file size in bytes. + * @returns {string} A human-readable string representation of the file size. + */ +export function humanFilesize(size = 0) { + const three = 3, + round = 100, + kB = 1000, + MB = Math.pow(kB, 2), + GB = Math.pow(kB, three); + if (size > GB) + return `${(Math.round((size * round) / GB) / round).toFixed(2)} GB`; + if (size > MB) + return `${(Math.round((size * round) / MB) / round).toFixed(1)} MB`; + if (size > kB) + return `${(Math.round((size * round) / kB) / round).toFixed()} kB`; + return `${Math.round(size).toFixed()} bytes`; +} + +/** + * Checks if a given year is valid, i.e. between 1980 and the current year. + * @param {number} year - The year to be validated. + * @returns {boolean} - Returns true if the year is valid, false otherwise. + */ +export function validYear(year) { + if (`${year}` == "") { + return true; + } + const epochYear = 1980; + const currentYear = new Date().getFullYear(); + if (year < epochYear || year > currentYear) { + return false; + } + return true; +} + +/** + * Checks if a given month is valid. + * @param {number} month - The month to be validated. + * @returns {boolean} - Returns true if the month is valid, false otherwise. + */ +export function validMonth(month) { + if (`${month}` == "") { + return true; + } + const jan = 1, + dec = 12; + if (month < jan || month > dec) { + return false; + } + return true; +} + +/** + * Checks if a given day is valid. + * @param {number} day - The day to be checked. + * @returns {boolean} - Returns true if the day is valid, false otherwise. + */ +export function validDay(day) { + if (`${day}` == "") { + return true; + } + const first = 1, + last = 31; + if (day < first || day > last) { + return false; + } + return true; +} diff --git a/assets/js/readme.js b/assets/js/readme.js index 445ac18a..a6dfe0a5 100644 --- a/assets/js/readme.js +++ b/assets/js/readme.js @@ -1,75 +1,19 @@ -/** - * Immediately invoked function expression that sets up the functionality for the readme text page. - * @function - */ +// readme.js + +import { clipText, getElmById } from "./helper.mjs"; + (() => { "use strict"; const hide = `d-none`; - const preLatin1 = document.getElementById("readmeLatin1"); - const pre437 = document.getElementById("readmeCP437"); - const copyBtn = document.getElementById(`copyReadme`); - const openSans = document.getElementById(`openSansFont`); - const topaz = document.getElementById(`topazFont`); - const vga = document.getElementById(`vgaFont`); const blackBG = ["reader-invert", "border", "border-black", "rounded-1"]; - - /** - * Converts a file size in bytes to a human-readable format. - * - * @param {number} size - The file size in bytes. - * @returns {string} A human-readable string representation of the file size. - */ - function humanFilesize(size = 0) { - const three = 3, - round = 100, - kB = 1000, - MB = Math.pow(kB, 2), - GB = Math.pow(kB, three); - if (size > GB) - return `${(Math.round((size * round) / GB) / round).toFixed(2)} GB`; - if (size > MB) - return `${(Math.round((size * round) / MB) / round).toFixed(1)} MB`; - if (size > kB) - return `${(Math.round((size * round) / kB) / round).toFixed()} kB`; - return `${Math.round(size).toFixed()} bytes`; - } - - /** - * Copies the text content of an HTML element to the clipboard. - * @async - * @function clipText - * @param {string} [id=""] - The ID of the HTML element to copy the text from. - * @throws {Error} Throws an error if the specified element is missing. - * @returns {Promise} A Promise that resolves when the text has been copied to the clipboard. - */ - async function clipText(id = ``) { - const element = document.getElementById(id); - if (element === null) throw Error(`select text element "${id}" is missing`); - element.focus(); // select the element to avoid NotAllowedError: Clipboard write is not allowed in this context - await navigator.clipboard.writeText(`${element.textContent}`).then( - function () { - console.log( - `Copied ${humanFilesize(element.textContent.length)} to the clipboard` - ); - const button = document.getElementById(`copyReadme`), - oneSecond = 1000; - if (button === null) return; - const save = button.textContent; - button.textContent = `✓ Copied`; - window.setTimeout(() => { - button.textContent = `${save}`; - }, oneSecond); - }, - function (err) { - console.error(`could not save any text to the clipboard: ${err}`); - } - ); - } + const preLatin1 = getElmById("readmeLatin1"), + pre437 = getElmById("readmeCP437"); /** * Event listener for the Open Sans font radio button. * @function */ + const openSans = document.getElementById(`openSansFont`); if (openSans !== null) { openSans.addEventListener("click", () => { preLatin1.classList.remove(hide, "font-amiga", ...blackBG); @@ -82,6 +26,7 @@ * Event listener for the Topaz font radio button. * @function */ + const topaz = document.getElementById(`topazFont`); if (topaz !== null) { topaz.addEventListener("click", () => { preLatin1.classList.remove(hide, "font-opensans"); @@ -94,6 +39,7 @@ * Event listener for the VGA font radio button. * @function */ + const vga = document.getElementById(`vgaFont`); if (vga !== null) { vga.addEventListener("click", () => { preLatin1.classList.add(hide); @@ -101,14 +47,14 @@ }); } - if (typeof navigator.clipboard === `undefined`) copyBtn.classList.add(hide); - /** - * Event listener for the copy button. - * @function - */ else - copyBtn.addEventListener(`click`, () => { + const copier = getElmById(`copyReadme`); + if (typeof navigator.clipboard === `undefined`) { + copier.classList.add(hide); + } else { + copier.addEventListener(`click`, () => { if (topaz !== null && topaz.checked) clipText(`readmeLatin1`); else if (vga !== null && vga.checked) clipText(`readmeCP437`); else clipText(`readmeCP437`); }); + } })(); diff --git a/assets/js/uploader-advanced.mjs b/assets/js/uploader-advanced.mjs index aeb43fa8..84dcb0d6 100644 --- a/assets/js/uploader-advanced.mjs +++ b/assets/js/uploader-advanced.mjs @@ -1,4 +1,4 @@ -import { validYear, validMonth, validDay } from "./uploader.mjs"; +import { validYear, validMonth, validDay } from "./helper.mjs"; export default advancedUploader; diff --git a/assets/js/uploader-image.mjs b/assets/js/uploader-image.mjs index 4c1442e5..5d2e5364 100644 --- a/assets/js/uploader-image.mjs +++ b/assets/js/uploader-image.mjs @@ -1,4 +1,4 @@ -import { validYear, validMonth } from "./uploader.mjs"; +import { validYear, validMonth } from "./helper.mjs"; export default imageSubmit; const imgFile = document.getElementById("imageFile"); diff --git a/assets/js/uploader-intro.mjs b/assets/js/uploader-intro.mjs index 421fa60a..d21fad25 100644 --- a/assets/js/uploader-intro.mjs +++ b/assets/js/uploader-intro.mjs @@ -1,4 +1,4 @@ -import { validYear, validMonth } from "./uploader.mjs"; +import { validYear, validMonth } from "./helper.mjs"; export default introSubmit; const introFrm = document.getElementById("introUploader"); diff --git a/assets/js/uploader-magazine.mjs b/assets/js/uploader-magazine.mjs index fabf2be1..13c59747 100644 --- a/assets/js/uploader-magazine.mjs +++ b/assets/js/uploader-magazine.mjs @@ -1,4 +1,4 @@ -import { validYear, validMonth, validDay } from "./uploader.mjs"; +import { validYear, validMonth, validDay } from "./helper.mjs"; export default magazineSubmit; // Elements for the magazine uploader const magFile = document.getElementById("magFile"); diff --git a/assets/js/uploader-text.mjs b/assets/js/uploader-text.mjs index 0fd49e42..09fa507f 100644 --- a/assets/js/uploader-text.mjs +++ b/assets/js/uploader-text.mjs @@ -1,6 +1,7 @@ // uploader-text.mjs -import { getElmById, validYear, validMonth } from "./uploader.mjs"; -export default textSubmit; + +import { getElmById, validYear, validMonth } from "./helper.mjs"; +export default textUploader; /** * Submits the text form when the specified element is clicked. @@ -8,7 +9,7 @@ export default textSubmit; * @param {string} formId - The ID of the form to be submitted. * @throws {Error} If the specified element or form is null. */ -export function textSubmit(elementId, formId) { +export function textUploader(elementId, formId) { const element = document.getElementById(elementId); if (element == null) { throw new Error(`The ${elementId} element is null.`); diff --git a/assets/js/uploader.js b/assets/js/uploader.js index 89dd3333..0b601883 100644 --- a/assets/js/uploader.js +++ b/assets/js/uploader.js @@ -1,16 +1,12 @@ -/** - * This module handles the uploader functionality for the website. - * It contains functions to validate client input and show/hide modals. - * @module uploader - * @requires bootstrap - */ +// uploader.js + import { advancedUploader } from "./uploader-advanced.mjs"; import { imageSubmit } from "./uploader-image.mjs"; import { introSubmit } from "./uploader-intro.mjs"; +import { keyboardShortcuts } from "./uploader-keyboard.mjs"; import { magazineSubmit } from "./uploader-magazine.mjs"; -import { textSubmit } from "./uploader-text.mjs"; import { pagination } from "./uploader.mjs"; -import { keyboardShortcuts } from "./uploader-keyboard.mjs"; +import { textUploader } from "./uploader-text.mjs"; (() => { "use strict"; @@ -20,5 +16,5 @@ import { keyboardShortcuts } from "./uploader-keyboard.mjs"; imageSubmit(`imageSubmit`); introSubmit(`introSubmit`); magazineSubmit(`magSubmit`); - textSubmit(`textSubmit`, `textUploader`); + textUploader(`textSubmit`, `textUploader`); })(); diff --git a/assets/js/uploader.mjs b/assets/js/uploader.mjs index 91cd0fea..e2d396a7 100644 --- a/assets/js/uploader.mjs +++ b/assets/js/uploader.mjs @@ -1,19 +1,6 @@ -export default getElmById; +// uploader.mjs -/** - * Retrieves an element from the DOM using its ID. - * - * @param {string} elementId - The ID of the element to retrieve. - * @returns {HTMLElement} - The retrieved element. - * @throws {Error} - If the element is not found in the DOM. - */ -export function getElmById(elementId) { - const element = document.getElementById(elementId); - if (element == null) { - throw new Error(`The ${elementId} element is null.`); - } - return element; -} +import { getElmById } from "./helper.mjs"; /** * Retrieves a modal object by its element ID. @@ -86,54 +73,3 @@ export function pagination(elementId) { pageRangeLabel.textContent = "Jump to page " + pageRange.value; }); } - -/** - * Checks if a given year is valid, i.e. between 1980 and the current year. - * @param {number} year - The year to be validated. - * @returns {boolean} - Returns true if the year is valid, false otherwise. - */ -export function validYear(year) { - if (`${year}` == "") { - return true; - } - const epochYear = 1980; - const currentYear = new Date().getFullYear(); - if (year < epochYear || year > currentYear) { - return false; - } - return true; -} - -/** - * Checks if a given month is valid. - * @param {number} month - The month to be validated. - * @returns {boolean} - Returns true if the month is valid, false otherwise. - */ -export function validMonth(month) { - if (`${month}` == "") { - return true; - } - const jan = 1, - dec = 12; - if (month < jan || month > dec) { - return false; - } - return true; -} - -/** - * Checks if a given day is valid. - * @param {number} day - The day to be checked. - * @returns {boolean} - Returns true if the day is valid, false otherwise. - */ -export function validDay(day) { - if (`${day}` == "") { - return true; - } - const first = 1, - last = 31; - if (day < first || day > last) { - return false; - } - return true; -} diff --git a/assets/js/votes-pouet.js b/assets/js/votes-pouet.js index 5e306784..fc30cbe2 100644 --- a/assets/js/votes-pouet.js +++ b/assets/js/votes-pouet.js @@ -16,10 +16,10 @@ return `${location.protocol}//${location.host}/pouet/vote/${id}`; }; - const element = document.getElementById(`pouetVoteID`); - const row = document.getElementById(`pouetRow`); - const stars = document.getElementById(`pouetStars`); - const votes = document.getElementById(`pouetVotes`); + const element = document.getElementById(`pouetVoteID`), + row = document.getElementById(`pouetRow`), + stars = document.getElementById(`pouetStars`), + votes = document.getElementById(`pouetVotes`); if (element === null || row === null || stars === null || votes === null) return; @@ -44,7 +44,7 @@ row.classList.add(`d-none`); return; } - + let s = `${result.stars} star`; if (result.stars !== 1) s += `s`; stars.innerHTML = s; diff --git a/public/js/readme.min.js b/public/js/readme.min.js index fec52f9e..9acbdce9 100644 --- a/public/js/readme.min.js +++ b/public/js/readme.min.js @@ -1,2 +1,2 @@ /* readme.min.js © Defacto2 2024 */ -(()=>{"use strict";const t="d-none",o=document.getElementById("readmeLatin1"),r=document.getElementById("readmeCP437"),l=document.getElementById("copyReadme"),u=document.getElementById("openSansFont"),a=document.getElementById("topazFont"),c=document.getElementById("vgaFont"),m=["reader-invert","border","border-black","rounded-1"];function B(e=0){const s=Math.pow(1e3,2),p=Math.pow(1e3,3);return e>p?`${(Math.round(e*100/p)/100).toFixed(2)} GB`:e>s?`${(Math.round(e*100/s)/100).toFixed(1)} MB`:e>1e3?`${(Math.round(e*100/1e3)/100).toFixed()} kB`:`${Math.round(e).toFixed()} bytes`}async function i(e=""){const d=document.getElementById(e);if(d===null)throw Error(`select text element "${e}" is missing`);d.focus(),await navigator.clipboard.writeText(`${d.textContent}`).then(function(){console.log(`Copied ${B(d.textContent.length)} to the clipboard`);const n=document.getElementById("copyReadme"),f=1e3;if(n===null)return;const s=n.textContent;n.textContent="\u2713 Copied",window.setTimeout(()=>{n.textContent=`${s}`},f)},function(n){console.error(`could not save any text to the clipboard: ${n}`)})}u!==null&&u.addEventListener("click",()=>{o.classList.remove(t,"font-amiga",...m),o.classList.add("font-opensans"),r.classList.add(t)}),a!==null&&a.addEventListener("click",()=>{o.classList.remove(t,"font-opensans"),o.classList.add("font-amiga",...m),r.classList.add(t)}),c!==null&&c.addEventListener("click",()=>{o.classList.add(t),r.classList.remove(t)}),typeof navigator.clipboard>"u"?l.classList.add(t):l.addEventListener("click",()=>{a!==null&&a.checked?i("readmeLatin1"):(c!==null&&c.checked,i("readmeCP437"))})})(); +(()=>{async function i(e=""){let n=document.getElementById(e);if(n===null)throw Error(`select text element "${e}" is missing`);n.focus(),await navigator.clipboard.writeText(`${n.textContent}`).then(function(){console.log(`Copied ${l(n.textContent.length)} to the clipboard`);let t=document.getElementById("copyReadme"),a=1e3;if(t===null)return;let o=t.textContent;t.textContent="\u2713 Copied",window.setTimeout(()=>{t.textContent=`${o}`},a)},function(t){console.error(`could not save any text to the clipboard: ${t}`)})}function c(e){let n=document.getElementById(e);if(n==null)throw new Error(`The ${e} element is null.`);return n}function l(e=0){let o=Math.pow(1e3,2),r=Math.pow(1e3,3);return e>r?`${(Math.round(e*100/r)/100).toFixed(2)} GB`:e>o?`${(Math.round(e*100/o)/100).toFixed(1)} MB`:e>1e3?`${(Math.round(e*100/1e3)/100).toFixed()} kB`:`${Math.round(e).toFixed()} bytes`}(()=>{"use strict";let e="d-none",n=["reader-invert","border","border-black","rounded-1"],t=c("readmeLatin1"),a=c("readmeCP437"),o=document.getElementById("openSansFont");o!==null&&o.addEventListener("click",()=>{t.classList.remove(e,"font-amiga",...n),t.classList.add("font-opensans"),a.classList.add(e)});let r=document.getElementById("topazFont");r!==null&&r.addEventListener("click",()=>{t.classList.remove(e,"font-opensans"),t.classList.add("font-amiga",...n),a.classList.add(e)});let d=document.getElementById("vgaFont");d!==null&&d.addEventListener("click",()=>{t.classList.add(e),a.classList.remove(e)});let s=c("copyReadme");typeof navigator.clipboard>"u"?s.classList.add(e):s.addEventListener("click",()=>{r!==null&&r.checked?i("readmeLatin1"):d!==null&&d.checked?i("readmeCP437"):i("readmeCP437")})})();})(); diff --git a/public/js/uploader.min.js b/public/js/uploader.min.js index bd19122c..afce837e 100644 --- a/public/js/uploader.min.js +++ b/public/js/uploader.min.js @@ -1,2 +1,2 @@ /* uploader.min.js © Defacto2 2024 */ -(()=>{function m(e){let a=document.getElementById(e);if(a==null)throw new Error(`The ${e} element is null.`);return a}function f(e){if(bootstrap===void 0)throw new Error("The bootstrap object is undefined.");let a=m(e);return new bootstrap.Modal(a)}function g(e,a){let t=document.getElementById(a);if(t==null)throw new Error(`The ${a} element is null.`);let s=m(e);if(s.addEventListener("shown.bs.modal",function(){t.focus()}),bootstrap===void 0)throw new Error("The bootstrap object is undefined.");return new bootstrap.Modal(s)}function W(e){let a=document.getElementById(e);if(typeof a>"u"||a===null)return;a.addEventListener("change",function(){let y=a.value,E=new URL(window.location.href),u=E.pathname.split("/"),V=u[u.length-1];!isNaN(V)&&typeof Number(V)=="number"?u[u.length-1]=y:u.push(y),E.pathname=u.join("/"),window.location.href=E.href});let t="paginationRangeLabel",s=document.getElementById(t);if(s===null)throw new Error(`The ${t} element is null.`);a.addEventListener("input",function(){s.textContent="Jump to page "+a.value})}function l(e){if(`${e}`=="")return!0;let a=1980,t=new Date().getFullYear();return!(et)}function i(e){return`${e}`==""?!0:!(e<1||e>12)}function v(e){return`${e}`==""?!0:!(e<1||e>31)}function X(e){let a=document.getElementById(e);if(a==null)throw new Error(`The ${e} element is null.`);a.addEventListener("click",function(){let t="Choose...",s=!0;_(),h.value==""&&(h.classList.add(n),s=!1),(p.value==""||p.value==t)&&(p.classList.add(n),s=!1),(L.value==""||L.value==t)&&(L.classList.add(n),s=!1),B.value==""&&(B.classList.add(n),s=!1),I.value==""&&(I.classList.add(n),s=!1),l(b.value)==!1&&(b.classList.add(n),s=!1),i(w.value)==!1&&(w.classList.add(n),s=!1),v(x.value)==!1&&(x.classList.add(n),s=!1),s==!0&&Z.submit()})}var n="is-invalid",Z=document.getElementById("advancedUploader");Z.addEventListener("reset",_);function _(){h.classList.remove(n),p.classList.remove(n),L.classList.remove(n),B.classList.remove(n),I.classList.remove(n),b.classList.remove(n),w.classList.remove(n),x.classList.remove(n)}var h=document.getElementById("advFile"),p=document.getElementById("advSelOS"),L=document.getElementById("advSelCat"),B=document.getElementById("advTitle"),I=document.getElementById("releasersAdv"),b=document.getElementById("advYear"),w=document.getElementById("advMonth"),x=document.getElementById("advDay");var M=document.getElementById("imageFile"),k=document.getElementById("imageTitle"),T=document.getElementById("imageReleasers"),S=document.getElementById("imageYear"),Y=document.getElementById("imageMonth"),ee=document.getElementById("imageUploader"),r="is-invalid";function te(){M.classList.remove(r),k.classList.remove(r),T.classList.remove(r),S.classList.remove(r),Y.classList.remove(r)}ee.addEventListener("reset",te);function ae(e){let a=document.getElementById(e);if(a==null)throw new Error(`The ${e} element is null.`);a.addEventListener("click",function(){let t=!0;te(),M.value==""&&(M.classList.add(r),t=!1),k.value==""&&(k.classList.add(r),t=!1),T.value==""&&(T.classList.add(r),t=!1),l(S.value)==!1&&(S.classList.add(r),t=!1),i(Y.value)==!1&&(Y.classList.add(r),t=!1),t==!0&&ee.submit()})}var se=document.getElementById("introUploader"),R=document.getElementById("introFile"),F=document.getElementById("releaseTitle"),$=document.getElementById("introReleasers"),D=document.getElementById("introYear"),U=document.getElementById("introMonth"),d="is-invalid";function ne(){R.classList.remove(d),F.classList.remove(d),$.classList.remove(d),D.classList.remove(d),U.classList.remove(d)}se.addEventListener("reset",ne);function oe(e){let a=document.getElementById(e);if(a==null)throw new Error(`The ${e} element is null.`);a.addEventListener("click",function(){let t=!0;ne(),R.value==""&&(R.classList.add(d),t=!1),F.value==""&&(F.classList.add(d),t=!1),$.value==""&&($.classList.add(d),t=!1),l(D.value)==!1&&(D.classList.add(d),t=!1),i(U.value)==!1&&(U.classList.add(d),t=!1),t==!0&&se.submit()})}var z=document.getElementById("magFile"),N=document.getElementById("magTitle"),K=document.getElementById("magIssue"),j=document.getElementById("magYear"),A=document.getElementById("magMonth"),C=document.getElementById("magDay"),o="is-invalid";function pe(){z.classList.remove(o),N.classList.remove(o),K.classList.remove(o),j.classList.remove(o),A.classList.remove(o),C.classList.remove(o)}var Le=document.getElementById("magUploader");function le(e){let a=document.getElementById(e);if(a==null)throw new Error(`The ${e} element is null.`);a.addEventListener("click",function(){let t=!0;pe(),z.value==""&&(z.classList.add(o),t=!1),N.value==""&&(N.classList.add(o),t=!1),K.value==""&&(K.classList.add(o),t=!1),l(j.value)==!1&&(j.classList.add(o),t=!1),i(A.value)==!1&&(A.classList.add(o),t=!1),v(C.value)==!1&&(C.classList.add(o),t=!1),t==!0&&Le.submit()})}function ie(e,a){let t=document.getElementById(e);if(t==null)throw new Error(`The ${e} element is null.`);let s=document.getElementById(a);if(s==null)throw new Error(`The ${a} form element is null.`);s.addEventListener("reset",re),t.addEventListener("click",function(){ye()==!0&&s.submit()})}var P=m("textFile"),O=m("textTitle"),J=m("textReleasers"),q=m("textYear"),G=m("textMonth"),c="is-invalid";function re(){P.classList.remove(c),O.classList.remove(c),J.classList.remove(c),q.classList.remove(c),G.classList.remove(c)}function ye(){let e=!0;return re(),P.value==""&&(P.classList.add(c),e=!1),O.value==""&&(O.classList.add(c),e=!1),J.value==""&&(J.classList.add(c),e=!1),l(q.value)==!1&&(q.classList.add(c),e=!1),i(G.value)==!1&&(G.classList.add(c),e=!1),e}var Ee=g("uploader-pouet","pouet-submission"),he=g("uploader-demozoo","demozoo-submission"),Be=g("uploader-intro","uploader-intro-file"),Ie=f("uploaderText"),be=f("uploaderImg"),we=f("uploaderMag"),xe=f("uploaderAdv"),Me=f("termsModal"),ke="d",Te="p",Se="i",Ye="n",Re="g",Fe="m",$e="a",De="t",de=document.getElementById("paginationStart"),ce=document.getElementById("paginationPrev"),me=document.getElementById("paginationPrev2"),ue=document.getElementById("paginationNext"),fe=document.getElementById("paginationNext2"),ge=document.getElementById("paginationEnd"),H="ArrowRight",Q="ArrowLeft";function ve(){document.addEventListener("keydown",function(e){if(e.ctrlKey&&e.altKey)switch(e.key){case ke:he.show();break;case Te:Ee.show();break;case Se:Be.show();break;case Ye:Ie.show();break;case Re:be.show();break;case Fe:we.show();break;case $e:xe.show();break;case De:Me.show();break}if(e.ctrlKey&&e.key==Q){de?.click();return}if(e.ctrlKey&&e.key==H){ge?.click();return}if(e.shiftKey&&e.key==Q){me?.click();return}if(e.shiftKey&&e.key==H){fe?.click();return}if(e.key==Q){ce?.click();return}if(e.key==H){ue?.click();return}})}(()=>{"use strict";ve(),W("paginationRange"),X("advSubmit"),ae("imageSubmit"),oe("introSubmit"),le("magSubmit"),ie("textSubmit","textUploader")})();})(); +(()=>{function u(e){let n=document.getElementById(e);if(n==null)throw new Error(`The ${e} element is null.`);return n}function l(e){if(`${e}`=="")return!0;let n=1980,t=new Date().getFullYear();return!(et)}function i(e){return`${e}`==""?!0:!(e<1||e>12)}function g(e){return`${e}`==""?!0:!(e<1||e>31)}function W(e){let n=document.getElementById(e);if(n==null)throw new Error(`The ${e} element is null.`);n.addEventListener("click",function(){let t="Choose...",o=!0;Z(),L.value==""&&(L.classList.add(a),o=!1),(v.value==""||v.value==t)&&(v.classList.add(a),o=!1),(p.value==""||p.value==t)&&(p.classList.add(a),o=!1),B.value==""&&(B.classList.add(a),o=!1),w.value==""&&(w.classList.add(a),o=!1),l(x.value)==!1&&(x.classList.add(a),o=!1),i(I.value)==!1&&(I.classList.add(a),o=!1),g(b.value)==!1&&(b.classList.add(a),o=!1),o==!0&&X.submit()})}var a="is-invalid",X=document.getElementById("advancedUploader");X.addEventListener("reset",Z);function Z(){L.classList.remove(a),v.classList.remove(a),p.classList.remove(a),B.classList.remove(a),w.classList.remove(a),x.classList.remove(a),I.classList.remove(a),b.classList.remove(a)}var L=document.getElementById("advFile"),v=document.getElementById("advSelOS"),p=document.getElementById("advSelCat"),B=document.getElementById("advTitle"),w=document.getElementById("releasersAdv"),x=document.getElementById("advYear"),I=document.getElementById("advMonth"),b=document.getElementById("advDay");var M=document.getElementById("imageFile"),k=document.getElementById("imageTitle"),T=document.getElementById("imageReleasers"),$=document.getElementById("imageYear"),S=document.getElementById("imageMonth"),_=document.getElementById("imageUploader"),r="is-invalid";function ee(){M.classList.remove(r),k.classList.remove(r),T.classList.remove(r),$.classList.remove(r),S.classList.remove(r)}_.addEventListener("reset",ee);function te(e){let n=document.getElementById(e);if(n==null)throw new Error(`The ${e} element is null.`);n.addEventListener("click",function(){let t=!0;ee(),M.value==""&&(M.classList.add(r),t=!1),k.value==""&&(k.classList.add(r),t=!1),T.value==""&&(T.classList.add(r),t=!1),l($.value)==!1&&($.classList.add(r),t=!1),i(S.value)==!1&&(S.classList.add(r),t=!1),t==!0&&_.submit()})}var ne=document.getElementById("introUploader"),F=document.getElementById("introFile"),Y=document.getElementById("releaseTitle"),R=document.getElementById("introReleasers"),C=document.getElementById("introYear"),U=document.getElementById("introMonth"),d="is-invalid";function oe(){F.classList.remove(d),Y.classList.remove(d),R.classList.remove(d),C.classList.remove(d),U.classList.remove(d)}ne.addEventListener("reset",oe);function ae(e){let n=document.getElementById(e);if(n==null)throw new Error(`The ${e} element is null.`);n.addEventListener("click",function(){let t=!0;oe(),F.value==""&&(F.classList.add(d),t=!1),Y.value==""&&(Y.classList.add(d),t=!1),R.value==""&&(R.classList.add(d),t=!1),l(C.value)==!1&&(C.classList.add(d),t=!1),i(U.value)==!1&&(U.classList.add(d),t=!1),t==!0&&ne.submit()})}function f(e){if(bootstrap===void 0)throw new Error("The bootstrap object is undefined.");let n=u(e);return new bootstrap.Modal(n)}function h(e,n){let t=document.getElementById(n);if(t==null)throw new Error(`The ${n} element is null.`);let o=u(e);if(o.addEventListener("shown.bs.modal",function(){t.focus()}),bootstrap===void 0)throw new Error("The bootstrap object is undefined.");return new bootstrap.Modal(o)}function se(e){let n=document.getElementById(e);if(typeof n>"u"||n===null)return;n.addEventListener("change",function(){let y=n.value,E=new URL(window.location.href),m=E.pathname.split("/"),V=m[m.length-1];!isNaN(V)&&typeof Number(V)=="number"?m[m.length-1]=y:m.push(y),E.pathname=m.join("/"),window.location.href=E.href});let t="paginationRangeLabel",o=document.getElementById(t);if(o===null)throw new Error(`The ${t} element is null.`);n.addEventListener("input",function(){o.textContent="Jump to page "+n.value})}var pe=h("uploader-pouet","pouet-submission"),he=h("uploader-demozoo","demozoo-submission"),ye=h("uploader-intro","uploader-intro-file"),Ee=f("uploaderText"),Le=f("uploaderImg"),Be=f("uploaderMag"),we=f("uploaderAdv"),xe=f("termsModal"),Ie="d",be="p",Me="i",ke="n",Te="g",$e="m",Se="a",Fe="t",le=document.getElementById("paginationStart"),ie=document.getElementById("paginationPrev"),re=document.getElementById("paginationPrev2"),de=document.getElementById("paginationNext"),ce=document.getElementById("paginationNext2"),ue=document.getElementById("paginationEnd"),D="ArrowRight",N="ArrowLeft";function me(){document.addEventListener("keydown",function(e){if(e.ctrlKey&&e.altKey)switch(e.key){case Ie:he.show();break;case be:pe.show();break;case Me:ye.show();break;case ke:Ee.show();break;case Te:Le.show();break;case $e:Be.show();break;case Se:we.show();break;case Fe:xe.show();break}if(e.ctrlKey&&e.key==N){le?.click();return}if(e.ctrlKey&&e.key==D){ue?.click();return}if(e.shiftKey&&e.key==N){re?.click();return}if(e.shiftKey&&e.key==D){ce?.click();return}if(e.key==N){ie?.click();return}if(e.key==D){de?.click();return}})}var K=document.getElementById("magFile"),j=document.getElementById("magTitle"),A=document.getElementById("magIssue"),P=document.getElementById("magYear"),O=document.getElementById("magMonth"),z=document.getElementById("magDay"),s="is-invalid";function Ye(){K.classList.remove(s),j.classList.remove(s),A.classList.remove(s),P.classList.remove(s),O.classList.remove(s),z.classList.remove(s)}var Re=document.getElementById("magUploader");function fe(e){let n=document.getElementById(e);if(n==null)throw new Error(`The ${e} element is null.`);n.addEventListener("click",function(){let t=!0;Ye(),K.value==""&&(K.classList.add(s),t=!1),j.value==""&&(j.classList.add(s),t=!1),A.value==""&&(A.classList.add(s),t=!1),l(P.value)==!1&&(P.classList.add(s),t=!1),i(O.value)==!1&&(O.classList.add(s),t=!1),g(z.value)==!1&&(z.classList.add(s),t=!1),t==!0&&Re.submit()})}function ge(e,n){let t=document.getElementById(e);if(t==null)throw new Error(`The ${e} element is null.`);let o=document.getElementById(n);if(o==null)throw new Error(`The ${n} form element is null.`);o.addEventListener("reset",ve),t.addEventListener("click",function(){Ce()==!0&&o.submit()})}var G=u("textFile"),J=u("textTitle"),q=u("textReleasers"),H=u("textYear"),Q=u("textMonth"),c="is-invalid";function ve(){G.classList.remove(c),J.classList.remove(c),q.classList.remove(c),H.classList.remove(c),Q.classList.remove(c)}function Ce(){let e=!0;return ve(),G.value==""&&(G.classList.add(c),e=!1),J.value==""&&(J.classList.add(c),e=!1),q.value==""&&(q.classList.add(c),e=!1),l(H.value)==!1&&(H.classList.add(c),e=!1),i(Q.value)==!1&&(Q.classList.add(c),e=!1),e}(()=>{"use strict";me(),se("paginationRange"),W("advSubmit"),te("imageSubmit"),ae("introSubmit"),fe("magSubmit"),ge("textSubmit","textUploader")})();})(); diff --git a/runner/runner.go b/runner/runner.go index 0a83a2d3..4719547e 100644 --- a/runner/runner.go +++ b/runner/runner.go @@ -29,8 +29,6 @@ func NamedJS() []string { "editor-assets", "editor-archive", "editor-forapproval", - "readme", - //"uploader", "votes-pouet", } } @@ -74,10 +72,28 @@ func JS(name string) api.BuildOptions { } } +func Readme() api.BuildOptions { + min := "readme.min.js" + entryjs := filepath.Join("assets", "js", "readme.js") + output := filepath.Join("public", "js", min) + return api.BuildOptions{ + EntryPoints: []string{entryjs}, + Outfile: output, + Target: api.ES2020, // specify JS language version + Write: true, // write the output file to disk + Bundle: true, // bundle dependencies into the output file + MinifyWhitespace: true, + MinifyIdentifiers: true, + MinifySyntax: true, + Banner: map[string]string{ + "js": fmt.Sprintf("/* %s %s %s */", min, C, time.Now().Format("2006")), + }, + } +} + func Uploader() api.BuildOptions { min := "uploader.min.js" entryjs := filepath.Join("assets", "js", "uploader.js") - //entrymjs := filepath.Join("assets", "js", "uploader.mjs") output := filepath.Join("public", "js", min) return api.BuildOptions{ EntryPoints: []string{entryjs}, @@ -107,6 +123,12 @@ func main() { fmt.Fprintf(os.Stderr, "JS build failed: %v\n", result.Errors) } } + { + result := api.Build(Readme()) + if len(result.Errors) > 0 { + fmt.Fprintf(os.Stderr, "JS build failed: %v\n", result.Errors) + } + } { result := api.Build(Uploader()) if len(result.Errors) > 0 {