Disable TinyMCE branding badge in editor configuration
This commit is contained in:
@@ -16,6 +16,8 @@ $(document).ready(function () {
|
||||
clearableTextAreaSetup();
|
||||
|
||||
|
||||
|
||||
|
||||
document.body.addEventListener("htmx:responseError", function(e) {
|
||||
let el = document.getElementById("htmx-error");
|
||||
var error;
|
||||
@@ -738,3 +740,44 @@ function initializeClock(id, endtime) {
|
||||
|
||||
window.initializeClock = initializeClock
|
||||
|
||||
|
||||
|
||||
// Unwrap single-root <p> elements from TinyMCE content before any form submit.
|
||||
// This prevents a single wrapping <p> from being sent to the server while
|
||||
// preserving other markup. We use a delegated submit listener so it works
|
||||
// for dynamically-added forms as well (e.g. admin inlines).
|
||||
document.addEventListener('submit', function(evt) {
|
||||
try {
|
||||
var form = evt.target;
|
||||
if (!form || !form.querySelector) return;
|
||||
// Find all tinyMCE textareas inside the form
|
||||
var areas = form.querySelectorAll('textarea.tinymce');
|
||||
areas.forEach(function(area) {
|
||||
var id = area.id;
|
||||
if (!id) return;
|
||||
var ed = (typeof tinyMCE !== 'undefined') ? tinyMCE.get(id) : null;
|
||||
if (!ed) return;
|
||||
var html = (ed.getContent && typeof ed.getContent === 'function') ? ed.getContent({format: 'html'}) : area.value;
|
||||
if (!html) return;
|
||||
// Use a temporary container to inspect top-level elements safely
|
||||
var tmp = document.createElement('div');
|
||||
tmp.innerHTML = html.trim();
|
||||
// If there is exactly one top-level element and it is a <p>, unwrap it
|
||||
if (tmp.childElementCount === 1 && tmp.firstElementChild && tmp.firstElementChild.tagName.toLowerCase() === 'p') {
|
||||
var inner = tmp.firstElementChild.innerHTML;
|
||||
// Update editor content and the underlying textarea value
|
||||
try {
|
||||
ed.setContent(inner);
|
||||
} catch (e) {
|
||||
// fallback: set textarea value directly
|
||||
area.value = inner;
|
||||
}
|
||||
// Ensure the textarea value matches (some setups sync on save, some don't)
|
||||
area.value = inner;
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
// be resilient; don't prevent form submission if something goes wrong here
|
||||
console.error('TinyMCE submit postprocess error', e);
|
||||
}
|
||||
}, true);
|
||||
@@ -303,6 +303,10 @@ TINYMCE_DEFAULT_CONFIG = {
|
||||
"skin": "oxide-dark",
|
||||
"menubar": "tools",
|
||||
"content_css": "dark",
|
||||
# Disable the "Powered by Tiny" branding badge in the editor UI
|
||||
# (TinyMCE option: https://www.tiny.cloud/docs/configure/editor-appearance/#branding)
|
||||
"branding": False,
|
||||
"promotion": False,
|
||||
}
|
||||
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
|
||||
|
||||
Reference in New Issue
Block a user