Changes to frontend locals for templates to match backend change. Regression caused ban modal to be broken because captchaType is no longer used in the captcha include.

close #487
Make the "pre-checking" of bans there not check all checkboxes inform because that included captcha options. Now it is explicitly "checkedbans" inputs. Otherwise all the boxes in grid captchas were filled in by default.
merge-requests/341/head
Thomas Lynch 2 years ago
parent b2fab97881
commit 3017029f61
  1. 12
      gulp/res/js/captcha.js
  2. 6
      gulp/res/js/forms.js
  3. 12
      gulpfile.js

@ -1,4 +1,4 @@
/* globals captchaType captchaGridSize captchaformsection */
/* globals captchaOptions captchaformsection */
const captchaCookieRegex = /captchaid=(.[^;]*)/ig;
class CaptchaController {
@ -41,11 +41,11 @@ class CaptchaController {
if (captcha.closest('form').dataset.captchaPreload == 'true') {
return this.loadCaptcha(captcha);
}
if (captchaType === 'grid' || captchaType === 'grid2') {
if (captchaOptions.type === 'grid' || captchaOptions.type === 'grid2') {
let hoverListener = captcha.closest('details') || captcha;
//captcha.parentElement.previousSibling.previousSibling.tagName === 'SUMMARY' ? captcha.parentElement.previousSibling.previousSibling : captcha.parentElement;
hoverListener.addEventListener('mouseover', () => this.loadCaptcha(captcha), { once: true });
} else { //captchaType === 'text'
} else { //captchaOptions.type === 'text'
captcha.placeholder = 'focus to load captcha';
captcha.addEventListener('focus', () => this.loadCaptcha(captcha), { once: true });
}
@ -95,7 +95,7 @@ class CaptchaController {
addMissingCaptcha() {
const postSubmitButton = document.getElementById('submitpost');
const captchaFormSectionHtml = captchaformsection({ captchaGridSize });
const captchaFormSectionHtml = captchaformsection({ captchaOptions });
postSubmitButton.insertAdjacentHTML('beforebegin', captchaFormSectionHtml);
const captchaFormSection = postSubmitButton.previousSibling;
const captchaField = captchaFormSection.querySelector('.captchafield');
@ -116,12 +116,12 @@ class CaptchaController {
refreshDiv.classList.add('captcharefresh', 'noselect');
refreshDiv.addEventListener('click', (e) => this.refreshCaptchas(e), true);
refreshDiv.textContent = '↻';
if (captchaType === 'text') {
if (captchaOptions.type === 'text') {
field.placeholder = 'loading';
}
captchaImg.src = imgSrc;
captchaImg.onload = () => {
if (captchaType === 'text') {
if (captchaOptions.type === 'text') {
field.placeholder = 'Captcha text';
}
captchaDiv.appendChild(captchaImg);

@ -338,11 +338,9 @@ class postFormHandler {
const modalBanned = document.getElementById('modalbanned');
const modalBanForm = modalBanned.querySelector('form');
const modalAppealHandler = new postFormHandler(modalBanForm);
for (let modalFormElement of modalAppealHandler.form.elements) {
for (let modalFormElement of modalBanForm.querySelectorAll('input[name="checkedbans"]')) {
//for ease of appeal, pre-check all the bans in this case.
if (modalFormElement.type === 'checkbox') {
modalFormElement.checked = true;
}
modalFormElement.checked = true;
}
const appealCaptcha = modalAppealHandler.captchaField;
if (appealCaptcha) {

@ -444,10 +444,18 @@ async function scripts() {
try {
// compile some locals/variables needed from configs in fe scripts
const captchaOptions = config.get.captchaOptions;
//smaller set of captchaoptions needed for some frontend scripts to build includes
const reducedCaptchaOptions = {
grid: {
size: captchaOptions.grid.size,
question: captchaOptions.grid.question,
},
type: captchaOptions.type,
};
const locals = `const themes = ['${themes.join('\', \'')}'];
const codeThemes = ['${codeThemes.join('\', \'')}'];
const captchaType = '${config.get.captchaOptions.type}';
const captchaGridSize = ${config.get.captchaOptions.grid.size};
const captchaOptions = ${JSON.stringify(reducedCaptchaOptions)};
const SERVER_TIMEZONE = '${Intl.DateTimeFormat().resolvedOptions().timeZone}';
const settings = ${JSON.stringify(config.get.frontendScriptDefault)};
const extraLocals = ${JSON.stringify({ meta: config.get.meta, reverseImageLinksURL: config.get.reverseImageLinksURL })};

Loading…
Cancel
Save