Fix tiny mce visuals, saving and cursor position

This commit is contained in:
Mojca Lorber 2019-05-10 10:52:14 +02:00
parent 3bb268459f
commit 8e6413b031
2 changed files with 21 additions and 5 deletions

View file

@ -57,6 +57,7 @@ var TinyMCE = (function() {
menubar: 'file edit view insert format',
toolbar: 'undo redo restoredraft | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link | forecolor backcolor | customimageuploader | codesample',
plugins: 'autosave autoresize customimageuploader link advlist codesample autolink lists charmap hr anchor searchreplace wordcount visualblocks visualchars insertdatetime nonbreaking save directionality paste textcolor colorpicker textpattern',
autoresize_bottom_margin: 20,
codesample_languages: [
{ text: 'R', value: 'r' },
{ text: 'MATLAB', value: 'matlab' },
@ -139,6 +140,7 @@ var TinyMCE = (function() {
$('.tinymce-placeholder').remove();
moveToolbar(editor, editorToolbar, editorToolbaroffset);
}, 400);
// Init saved status label
if (editor.getContent() !== '') {
editorForm.find('.tinymce-status-badge').removeClass('hidden');
@ -149,7 +151,6 @@ var TinyMCE = (function() {
moveToolbar(editor, editorToolbar, editorToolbaroffset);
});
// Update scroll position after exit
function updateScrollPosition() {
if (editorForm.offset().top < $(window).scrollTop()) {
@ -157,6 +158,16 @@ var TinyMCE = (function() {
}
}
// Saving at clicking anywhere outside of the editor
editor.on('blur', function(event) {
event.preventDefault();
editorForm.clearFormErrors();
editor.setProgressState(1);
editor.save();
editorForm.submit();
updateScrollPosition();
});
// Init Save button
editorForm
.find('.tinymce-save-button')
@ -202,6 +213,11 @@ var TinyMCE = (function() {
})
.removeClass('hidden');
// Set cursor to the end of the content
editor.focus();
editor.selection.select(editor.getBody(), true);
editor.selection.collapse(false);
SmartAnnotation.init($(editor.contentDocument.activeElement));
initHighlightjsIframe($(this.iframeElement).contents());
},

View file

@ -4,12 +4,12 @@
.tinymce-view {
border: solid 1px;
border-color: $color-white;
box-shadow: 1px 0 2px $color-alto;
min-height: 200px;
border-radius: 3px;
min-height: 100px;
padding: 3px;
&:hover {
border-color: $color-alto;
border-color: $color-gainsboro;
cursor: pointer;
}
@ -59,4 +59,4 @@
.mce-toolbar {
background: $color-white !important;
}
// scss-lint:enable ImportantRule
// scss-lint:enable ImportantRule