/* DokuWiki MoaiEditor Captcha.js file Version : 0.5a (May 6, 2026) Author : MoaiTools License : GPL 3 (http://www.gnu.org/licenses/gpl.html) */ /* This class integrates www.dokuwiki.org/plugin:captcha into the editor. Functions of this class: - Moves the captcha wrapper to a suitable position depending on mode (desktop, mobile). - Intercepts the Save button click if the captcha input is empty, so that instead of submitting the form the user is reminded to fill the captcha. */ MoaiEditor.Captcha = class { constructor() { this.userWasReminded = false; } // ┌───────────────────────────────────┐ // │ Public │ // └───────────────────────────────────┘ initBeforeLayout () { if (!this.exists()) return; // Add the form attribute to the input elements (as they are no longer inside the form) const inputs = this.wrapper.querySelectorAll("input"); for (let input of inputs) input.setAttribute('form', 'dw__editform'); // Reduce margins and paddings this.wrapper.style.margin = '0'; this.wrapper.style.padding = '5px 10px'; // Intercept the Save button action const original_onclick_save = moaiEditor.buttons.save.__onClick; moaiEditor.buttons.save.__onClick = function (event) { // Submit the form if the captcha input is not empty, or if we reminded the user already const self = moaiEditor.plugins.captcha; const textinput = self.wrapper.querySelector("input[type=text]"); if (textinput.value.length > 0 || self.userWasReminded) return original_onclick_save.bind(moaiEditor.buttons.save, event); // Else, remind the user const msg = "Please fill the captcha below."; event.preventDefault(); // Prevent form submit moaiEditor.dokuMessage(msg, 2); // Show message self.wrapper.style.background = "#ffc"; // Highlight form moaiEditor.layout.goLeft(); // In mobile mode scroll to the left side to show the form self.userWasReminded = true; // Remind the user only once (then make the Save button work as normal again) } } onSpecificLayout(mode) { if (this.wrapper === null) return; if (mode == 'desktop') { moaiEditor.layout.desktop.footerLeft.appendChild(this.wrapper); } if (mode == 'vphone') { const container = document.querySelector("#moaied__phone_left_main"); const separator = document.querySelector("#moaied__phone_left_main_separator"); const element = moaiEditor.createHTML('
'); //this.wrapper.style.background = "rgba(255,255,255,0.4)"; element.appendChild(this.wrapper); container.insertBefore (element, separator); } } // ┌───────────────────────────────────┐ // │ Input events │ // └───────────────────────────────────┘ // ┌───────────────────────────────────┐ // │ Private │ // └───────────────────────────────────┘ exists () { this.wrapper = document.querySelector("#wiki__editbar div.plugin__captcha_wrapper"); if (this.wrapper === null) return false; return true; } }; // End Class