/* DokuWiki MoaiEditor Preview.js file Version : 0.5a (May 6, 2026) Author : MoaiTools License : GPL 3 (http://www.gnu.org/licenses/gpl.html) */ /* This class implements some methods for working with the preview. */ MoaiEditor.Preview = class { constructor () { // Constants this.name = 'Preview'; // Variables this.container = null; // Preview container element // Objects this.scroll = new MoaiEditor.PreviewScroll(this); } // ┌───────────────────────────────────┐ // │ Public │ // └───────────────────────────────────┘ init() { this.container = document.querySelector("#moaied__preview"); // Create content div this.content = moaiEditor.createHTML('
'); this.container.appendChild(this.content); // Create flash box this.flashbox = moaiEditor.createHTML('
'); } // ──────────────────────────────────── set pointerEvents(boolean) { if (boolean) this.container.style.pointerEvents = 'auto'; else this.container.style.pointerEvents = 'none'; } // ──────────────────────────────────── flash(flash, data=null) { if (flash == 'remove') { this.flashbox.remove(); return; } if (flash === null) return; this.flashbox.remove(); this.flashbox = moaiEditor.createHTML('
'); if (flash === false) this.flashbox.classList.add('red'); const rect = moaiEditor.scroll.tools.getRectRelativeToParent(data.element); this.flashbox.style.top = rect.top + 'px'; this.flashbox.style.left = rect.left + 'px'; this.flashbox.style.width = rect.width + 'px'; this.flashbox.style.height = rect.height + 'px'; this.container.appendChild(this.flashbox); } // ┌───────────────────────────────────┐ // │ Input events │ // └───────────────────────────────────┘ onScroll() { // Debugline //this.scroll.debugLine(); } }; // End Class // ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ // ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ /* This class implements the 'scroll.max', 'scroll.top' and 'scroll.smooth' getters and setters. */ MoaiEditor.PreviewScroll = class { constructor (outer) { this.outer = outer; this.smoothvalue = false; } // ──────────────────────────────────── get max() { return moaiEditor.scroll.tools.getMaxScrollY(this.outer.container); } // ──────────────────────────────────── get top() { return this.outer.container.scrollTop; } set top(value) { this.outer.container.scrollTop = value; } // ──────────────────────────────────── get smooth() { return this.smoothvalue; } set smooth(boolean) { var value = 'auto'; if (boolean) value = 'smooth'; this.smoothvalue = boolean; this.outer.container.style.scrollBehavior = value; } // ──────────────────────────────────── debugLine() { // Exit if debugline is not enabled const line = document.querySelector("#moai__debug div:nth-child(2)"); if (!line) return; // Debug line const text = "scroll:"+Math.floor(this.top)+" maxScroll:"+this.max; line.textContent = text; } }; // End Class