diff --git a/media/css/main.css b/media/css/main.css index 3be226d3..28e01b8d 100644 --- a/media/css/main.css +++ b/media/css/main.css @@ -1851,6 +1851,14 @@ details.release-notes-list { max-width: 650px; } +.moderation-preview-iframe { + width: 100%; + min-height: 400px; + border: 1px solid var(--button-input-bdr-color); + border-radius: 5px; + background-color: #fff; +} + /* Buttons that are images */ button.imagebutton { border: 0; diff --git a/media/js/moderation_preview.js b/media/js/moderation_preview.js new file mode 100644 index 00000000..a6634463 --- /dev/null +++ b/media/js/moderation_preview.js @@ -0,0 +1,33 @@ +/* + * Moderation preview handler + * Renders HTML content in iframes to isolate styles from the main page + */ +document.addEventListener('DOMContentLoaded', function() { + /* Find preview data textareas and render them in iframes */ + var dataAreas = document.getElementsByClassName('moderation-preview-data'); + for (var i = 0; i < dataAreas.length; i++) { + var dataArea = dataAreas[i]; + var container = dataArea.parentElement; + var content = dataArea.value; + + /* Create an iframe to isolate the HTML content styles */ + var iframe = document.createElement('iframe'); + iframe.className = 'moderation-preview-iframe'; + iframe.sandbox = 'allow-same-origin'; + iframe.srcdoc = content; + + /* Resize iframe to fit content after it loads */ + iframe.onload = function() { + try { + var contentHeight = this.contentDocument.body.scrollHeight; + if (contentHeight > 0) { + this.style.height = (contentHeight + 20) + 'px'; + } + } catch (e) { + /* Ignore cross-origin errors */ + } + }; + + container.appendChild(iframe); + } +}); diff --git a/templates/account/submit_preview.html b/templates/account/submit_preview.html index 054e03bf..c7ac5a6e 100644 --- a/templates/account/submit_preview.html +++ b/templates/account/submit_preview.html @@ -17,7 +17,16 @@ {%for fld, title, contents, mdcontents, note in preview %}