diff --git a/html-editor-lib.pl b/html-editor-lib.pl index 921ea83d2..83e3960e6 100644 --- a/html-editor-lib.pl +++ b/html-editor-lib.pl @@ -16,6 +16,7 @@ $html_editor_load_scripts .= < + EOF return $html_editor_load_scripts; @@ -302,8 +303,26 @@ my $html_editor_init_script = this.quill.format('blockquote', true); }); editor.on('text-change', function() { - targ.value = editor.root.innerHTML + "
"; - sessionStorage.setItem('$module_name/quill=last-message', targ.value); + // This should most probably go to onSubmit event + const cloneId = '${target_name}clonedHTMLEditor', + clonedHTMLEditor = document.createElement('div'); + clonedHTMLEditor.id = cloneId; + clonedHTMLEditor.innerHTML = editor.root.innerHTML; + document.body.appendChild(clonedHTMLEditor); + computedStyleToInlineStyle(clonedHTMLEditor, { + recursive: true, + properties: [ + 'color', 'background-color', 'position', 'box-sizing', 'width', 'height', + 'margin', 'padding', 'border', 'font-size', 'font-family', 'line-height', + 'text-align', 'content', 'text-decoration', 'overflow', + 'list-style-type', 'counter-reset', 'counter-increment', 'ratio', + 'opacity', 'cursor', 'left', 'top', 'right', 'bottom', 'vertical-align', + 'direction', 'white-space', 'border-radius' + ] + }); + targ.value = clonedHTMLEditor.innerHTML + "
"; + clonedHTMLEditor.remove(); + sessionStorage.setItem('$module_name/quill=last-message', editor.root.innerHTML); let extraValue = String(), sync = JSON.parse('@{[&convert_to_json($opts->{'textarea'}->{'sync'}->{'data'})]}'), position = '@{[$opts->{'textarea'}->{'sync'}->{'position'}]}', @@ -358,7 +377,7 @@ my $html_editor_init_script = // Update editor on initial load editor.pasteHTML(targ.value); - sessionStorage.setItem('$module_name/quill=last-message', targ.value); + sessionStorage.setItem('$module_name/quill=last-message', editor.root.innerHTML); } @{[$opts->{'load'} ? "fn_${module_name}_html_editor_init()" : '']} diff --git a/unauthenticated/js/computed-style-to-inline-style.min.js b/unauthenticated/js/computed-style-to-inline-style.min.js new file mode 100644 index 000000000..61088f52d --- /dev/null +++ b/unauthenticated/js/computed-style-to-inline-style.min.js @@ -0,0 +1,6 @@ +/*! + computed-style-to-inline-style v3.0.0 (https://github.com/lukehorvat/computed-style-to-inline-style) + Copyright (c) 2016 Luke Horvat + Licensed under MIT (https://github.com/lukehorvat/computed-style-to-inline-style/blob/master/LICENSE) + */ +!function(e,t){if("function"==typeof define&&define.amd)define(["module"],t);else if("undefined"!=typeof exports)t(module);else{var o={exports:{}};t(o),e.computedStyleToInlineStyle=o.exports}}(this,(function(e){var t=Array.prototype.forEach;e.exports=function e(o){var r,i,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!o)throw new Error("No element specified.");n.recursive&&(i=o.children,t).call(i,(function(t){e(t,n)}));var l=getComputedStyle(o);(r=n.properties||l,t).call(r,(function(e){o.style[e]=l.getPropertyValue(e),o.removeAttribute("class"),o.removeAttribute("id")}))}})); \ No newline at end of file