perf(backoffice): Summernote só nas páginas com editor

Os ~100 KB do editor e da tradução eram carregados em todas as páginas do
backoffice. Agora o footer só os pede quando existe um textarea.js-wysiwyg.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
andreandClaude Opus 5.5 committed 2026-09-25 11:43:42 +01:00
1 parent b202262da0
commit fcf86b60ea
1 file changed
+14 -3
+14 -3
View File
@@ -6,14 +6,14 @@
<?= script_tag('assets/vendor/jquery/jquery-3.7.1.min.js') ?>
<?= script_tag('assets/vendor/bootstrap5/js/bootstrap.bundle.min.js') ?>
<?= script_tag('assets/js/password-toggle.js') ?>
<?= script_tag('assets/vendor/summernote/summernote-bs5.min.js') ?>
<?= script_tag('assets/vendor/summernote/lang/summernote-pt-PT.min.js') ?>
<?php // Summernote (~100 KB) só nas páginas que têm um editor: carregado a pedido, abaixo. ?>
<script>window.SUMMERNOTE_SRC = [<?= json_encode(_asset_versioned('assets/vendor/summernote/summernote-bs5.min.js')) ?>, <?= json_encode(_asset_versioned('assets/vendor/summernote/lang/summernote-pt-PT.min.js')) ?>];</script>
<script>
// Attach Summernote to any <textarea class="js-wysiwyg">. The editor keeps the
// underlying textarea in sync, so normal form POSTs submit the generated HTML.
// Inline image upload is intentionally omitted (base64 would bloat the row) —
// modules that need images use their own file-upload fields.
document.addEventListener('DOMContentLoaded', function () {
function initWysiwyg() {
if (!window.jQuery || !jQuery.fn || !jQuery.fn.summernote) return;
jQuery('textarea.js-wysiwyg').each(function () {
var $ta = jQuery(this);
@@ -32,6 +32,17 @@ document.addEventListener('DOMContentLoaded', function () {
popover: { image: [], air: [] }
});
});
}
document.addEventListener('DOMContentLoaded', function () {
if (!document.querySelector('textarea.js-wysiwyg')) return;
// Carrega o editor e a tradução por ordem, só aqui.
(function next(i) {
if (i >= window.SUMMERNOTE_SRC.length) return initWysiwyg();
var s = document.createElement('script');
s.src = window.SUMMERNOTE_SRC[i];
s.onload = function () { next(i + 1); };
document.body.appendChild(s);
})(0);
});
// Tema: claro / escuro / automático (o <head> já aplicou o guardado).