So you’re saying that when a user enters text into Quill it is saved to a database. Then when the user returns to the site at a later date, the following line is enough to fetch the text they previously entered and display it in the editor:
const editorContent = '<%=Myhtml%>';
However, when you expand your script to allow users to add images (which are uploaded to your server — not stored in the database), then the above line doesn’t work.
In Example #1 (no upload of photo script) all data stored in database displays in editor.
In Example #2 (modified script of #1) even though information is in the database and the images are stored in a folder on the server, it doesn’t show in the editor.
If I move <%=Myhtml%> (the ASP call for the data) outside of the editor then the information is displayed on the page including photos - it’s just not displaying in editor.
Interesting. Sounds like it might be a timing issue, that the script is inserting the images in the editor, before they have had time to load.
I’m not seeing the editorContent variablke used anywhere in the code that you posted. Could you pls add the code that inserts the database response into the editor.
// Fetch content from database here
var editorContent = '<%=rs("myHtml")%>';
var editor = document.getElementById('editor-container');
var hiddenInput = document.getElementById('myHtml');
var form = document.forms.mainform;
var quill = new Quill(editor, {
modules: {
syntax: true,
toolbar: '#toolbar-container'
},
placeholder: 'Compose an epic...',
theme: 'snow'
});
editor.firstChild.innerHTML = editorContent;
form.addEventListener('submit', function (e) {
e.preventDefault();
hiddenInput.value = editor.firstChild.innerHTML;
this.submit();
});
function selectLocalImage() {
var input = document.createElement('input');
input.setAttribute('type', 'file');
input.click(); // Listen upload local image and save to server
input.onchange = function () {
var file = input.files[0]; // file type is only image.
if (/^image\//.test(file.type)) {
saveToServer(file);
} else {
console.warn('You could only upload images.');
}
};
}
function saveToServer(file) {
var fd = new FormData();
fd.append('image', file);
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://localhost/post.asp', true);
xhr.onload = function () {
if (xhr.status === 200) {
var url = xhr.responseText;
insertToEditor(url);
}
};
xhr.send(fd);
}
function insertToEditor(url) {
// push image url to rich editor.
var range = quill.getSelection();
quill.insertEmbed(range.index, 'image', "https://mydomain".concat(url));
}
quill.getModule('toolbar').addHandler('image', function () {
selectLocalImage();
});
That works as far as inserting the data into the editor, but only in IE on an Windows 8.1, the upload icon doesn’t work (interesting). Works in IE, Windows 10 though.
In all of IE when you click on the image it is surrounded with square dots as a placeholder. This is good for deleting or hyperlinking. In Chrome and FF it doesn’t have the squares around the image, so if you want to hyperlink it you have to place the cursor next to it; then it will hyperlink.
Not sure if that is fixable or not? Maybe that is a characteristic of FF and Chrome, not sure.
Not a problem - you have been a tremendous help and your knowledge in this matter is impressive. Thank you very much!
PS… The alignments of left, right, center, justify don’t work. In the editor they properly display, but once posted all alignments are left. I am guessing that must be a Quill issue.
Not sure I quite follow here. Do you mean that you can justify text in the editor just fine, but when you save it to the database, then reload the saved text, the justify styles are no longer applied?
I am surprised I didn’t catch that earlier. I have double and triple checked it with different browsers and different web pages. Here you can see the results: First the editor view and second the output page.
OUTPUT PAGE:
This is the html on the output page:
<h1 class="ql-align-center">Hello, this is a test!</h1><h1>Hello, this is a test!</h1><h1 class="ql-align-right"><span style="color: rgb(230, 0, 0);">Hello, this is a test!</span></h1><h1><u style="color: rgb(0, 102, 204);">Hello, this is a test!</u></h1></font>
I also tried, thinking this was my issue, putting the css links from Quill on the output page and that didn’t make any difference.
Thanks for the link. For me, in latest Firefox, the justification works as expected. This is what I see when I align the text differently, then press the back button and refresh the page.
The text alignments (not just justifications, but center, right) and the font formatting isn’t correct on the OUTPUT page. It’s okay in the editor, but the editor is what is not going to be viewed ultimately from the customer. What is in the Editor in terms of formatting should carryover to the post or output page.
All browsers are the same in terms of results.
Take the html from the output page and insert into a different page and you will get the same results.
<h1 class="ql-align-right">Right Align</h1><h1 class="ql-align-center">Centered Text</h1><h1 class="ql-align-justify"><br></h1><h1 class="ql-align-justify">Justified Text Justified Text Justified Text Justified Text Justified Text Justified Text</h1><p><br></p><p class="ql-align-center"><br></p>
Yes, I had mentioned that I had tried that before and it doesn’t change the outcome. Take another look at your view source because I added that to my post page.
The styles are in the quill.snow.css file. Here you find:
.ql-editor .ql-align-right {
text-align: right;
}
Which means the CSS is looking for an element with a class of ql-align-right inside an element with a class of ql-editor.
Add that to your outputted HTML and you should be good.
i.e. change this:
Done! - Below is the the response.write myHtml<br><br>
You can use your back arrow key to go back to the editor<br><br>
Be sure to REFRESH the page to see the changes in the editor<br><br>
Right click to view source.
<h1>Left Align</h1>
<h1 class="ql-align-right">Right Align</h1>
<h1 class="ql-align-center">Centered Text</h1>
<h1 class="ql-align-justify"><br></h1><h1 class="ql-align-justify">Justified Text Justified Text Justified Text Justified Text Justified Text Justified Text</h1>
to:
<div class="ql-editor">
Done! - Below is the the response.write myHtml<br><br>
You can use your back arrow key to go back to the editor<br><br>
Be sure to REFRESH the page to see the changes in the editor<br><br>
Right click to view source.
<h1>Left Align</h1>
<h1 class="ql-align-right">Right Align</h1>
<h1 class="ql-align-center">Centered Text</h1>
<h1 class="ql-align-justify"><br></h1><h1 class="ql-align-justify">Justified Text Justified Text Justified Text Justified Text Justified Text Justified Text</h1>
</div>
Added that to the post page and still no difference.
Once I get this correct, would probably need to add center and justify - plus Sans Serif and Serif. The larger text sizes and colors work but not what we are currently discussing.