mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-04-06 04:10:22 +08:00
Merge pull request #4704 from artoscinote/ma_SCI_7574
Upgrade TinyMCE to 6.3, fix issues [SCI-7574]
This commit is contained in:
commit
bb766ee0f9
8 changed files with 75 additions and 47 deletions
|
@ -5,8 +5,8 @@ tinymce.PluginManager.add('placeholder', function(editor) {
|
||||||
var editorForm = $(editor.getContainer()).closest('form');
|
var editorForm = $(editor.getContainer()).closest('form');
|
||||||
var editorToolbar = editorForm.find('.mce-top-part');
|
var editorToolbar = editorForm.find('.mce-top-part');
|
||||||
var placeholderText = editor.getElement().getAttribute('placeholder') || editor.settings.placeholder;
|
var placeholderText = editor.getElement().getAttribute('placeholder') || editor.settings.placeholder;
|
||||||
var placeholderAttrs = editor.settings.placeholder_attrs || {
|
var placeholderAttrs = {
|
||||||
style: {
|
style: `
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
top: (editorToolbar.height()) + 'px',
|
top: (editorToolbar.height()) + 'px',
|
||||||
left: 0,
|
left: 0,
|
||||||
|
@ -15,7 +15,7 @@ tinymce.PluginManager.add('placeholder', function(editor) {
|
||||||
width: 'calc(100% - 50px)',
|
width: 'calc(100% - 50px)',
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
'white-space': 'pre-wrap'
|
'white-space': 'pre-wrap'
|
||||||
}
|
`
|
||||||
};
|
};
|
||||||
var contentAreaContainer = editor.getContentAreaContainer();
|
var contentAreaContainer = editor.getContentAreaContainer();
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,16 @@
|
||||||
position: relative !important;
|
position: relative !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tox.tox-tinymce {
|
||||||
|
left: -100000px;
|
||||||
|
position: absolute;
|
||||||
|
|
||||||
|
&.tox-tinymce--loaded {
|
||||||
|
left: 0;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.tinymce-placeholder {
|
.tinymce-placeholder {
|
||||||
background: $color-concrete;
|
background: $color-concrete;
|
||||||
opacity: .7;
|
opacity: .7;
|
||||||
|
@ -45,8 +55,15 @@
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tinymce-save-button,
|
.tox-edit-area {
|
||||||
.tinymce-cancel-button {
|
label {
|
||||||
|
color: $color-silver-chalice !important;
|
||||||
|
padding: 5px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.tinymce-save-button.tox-mbtn,
|
||||||
|
.tinymce-cancel-button.tox-mbtn {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
.fas {
|
.fas {
|
||||||
|
@ -54,6 +71,10 @@
|
||||||
font-weight: 900;
|
font-weight: 900;
|
||||||
margin-top: 3px;
|
margin-top: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: transparent !important;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.tinymce-save-controls {
|
.tinymce-save-controls {
|
||||||
|
|
14
app/javascript/packs/tiny_mce.js
vendored
14
app/javascript/packs/tiny_mce.js
vendored
|
@ -183,9 +183,10 @@ window.TinyMCE = (() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return tinyMCE.init({
|
return tinyMCE.init({
|
||||||
cache_suffix: '?v=6.1.2', // This suffix should be changed any time library is updated
|
cache_suffix: '?v=6.3.1', // This suffix should be changed any time library is updated
|
||||||
selector,
|
selector,
|
||||||
convert_urls: false,
|
convert_urls: false,
|
||||||
|
promotion: false,
|
||||||
menu: {
|
menu: {
|
||||||
insert: { title: 'Insert', items: 'link codesample inserttable | charmap hr | nonbreaking anchor | insertdatetime customimageuploader marvinjs' },
|
insert: { title: 'Insert', items: 'link codesample inserttable | charmap hr | nonbreaking anchor | insertdatetime customimageuploader marvinjs' },
|
||||||
},
|
},
|
||||||
|
@ -193,7 +194,7 @@ window.TinyMCE = (() => {
|
||||||
toolbar: 'undo redo restoredraft | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | link | forecolor backcolor | codesample | customimageuploader marvinjs | help',
|
toolbar: 'undo redo restoredraft | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | link | forecolor backcolor | codesample | customimageuploader marvinjs | help',
|
||||||
plugins,
|
plugins,
|
||||||
autoresize_bottom_margin: 20,
|
autoresize_bottom_margin: 20,
|
||||||
// placeholder: options.placeholder,
|
placeholder: options.placeholder,
|
||||||
skin: false,
|
skin: false,
|
||||||
content_css: false,
|
content_css: false,
|
||||||
toolbar_sticky: true,
|
toolbar_sticky: true,
|
||||||
|
@ -272,13 +273,14 @@ window.TinyMCE = (() => {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
init_instance_callback: (editor) => {
|
init_instance_callback: (editor) => {
|
||||||
const editorForm = $(editor.getContainer()).closest('form');
|
|
||||||
|
const editorContainer = $(editor.getContainer());
|
||||||
|
const editorForm = editorContainer.closest('form');
|
||||||
const menuBar = editorForm.find('.tox-menubar');
|
const menuBar = editorForm.find('.tox-menubar');
|
||||||
|
|
||||||
$('.tinymce-placeholder').css('height', `${$(editor.editorContainer).height()}px`);
|
$('.tinymce-placeholder').css('height', `${$(editor.editorContainer).height()}px`);
|
||||||
$(editor.editorContainer).css('max-height', '0').css('opacity', '0')
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
$(editor.editorContainer).css('max-height', '').css('opacity', '')
|
editorContainer.addClass('tox-tinymce--loaded');
|
||||||
$('.tinymce-placeholder').remove();
|
$('.tinymce-placeholder').remove();
|
||||||
}, 400);
|
}, 400);
|
||||||
|
|
||||||
|
@ -351,6 +353,8 @@ window.TinyMCE = (() => {
|
||||||
SmartAnnotation.init($(editor.contentDocument.activeElement));
|
SmartAnnotation.init($(editor.contentDocument.activeElement));
|
||||||
SmartAnnotation.preventPropagation('.atwho-user-popover');
|
SmartAnnotation.preventPropagation('.atwho-user-popover');
|
||||||
initHighlightjsIframe($(editor.iframeElement).contents());
|
initHighlightjsIframe($(editor.iframeElement).contents());
|
||||||
|
|
||||||
|
if (options.afterInitCallback) { options.afterInitCallback(); }
|
||||||
},
|
},
|
||||||
setup: (editor) => {
|
setup: (editor) => {
|
||||||
editor.on('keydown', (e) => {
|
editor.on('keydown', (e) => {
|
||||||
|
|
|
@ -6,7 +6,7 @@ tinymce.PluginManager.add('placeholder', (editor) => {
|
||||||
// const editorToolbar = editorForm.find('.tox-editor-header');
|
// const editorToolbar = editorForm.find('.tox-editor-header');
|
||||||
const placeholderText = editor.getElement().getAttribute('placeholder');
|
const placeholderText = editor.getElement().getAttribute('placeholder');
|
||||||
const placeholderAttrs = {
|
const placeholderAttrs = {
|
||||||
style: {
|
style: `
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
top: '0px',
|
top: '0px',
|
||||||
left: '0px',
|
left: '0px',
|
||||||
|
@ -15,7 +15,7 @@ tinymce.PluginManager.add('placeholder', (editor) => {
|
||||||
width: 'calc(100% - 50px)',
|
width: 'calc(100% - 50px)',
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
'white-space': 'pre-wrap'
|
'white-space': 'pre-wrap'
|
||||||
}
|
`
|
||||||
};
|
};
|
||||||
const contentAreaContainer = editor.getContentAreaContainer();
|
const contentAreaContainer = editor.getContentAreaContainer();
|
||||||
|
|
||||||
|
|
|
@ -204,7 +204,7 @@
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
updateDescription(protocol) {
|
updateDescription(protocol) {
|
||||||
this.protocol.attributes = protocol.data.attributes
|
this.protocol.attributes = protocol.attributes
|
||||||
},
|
},
|
||||||
addStep(position) {
|
addStep(position) {
|
||||||
$.post(this.urls.add_step_url, {position: position}, (result) => {
|
$.post(this.urls.add_step_url, {position: position}, (result) => {
|
||||||
|
|
|
@ -79,17 +79,17 @@
|
||||||
methods: {
|
methods: {
|
||||||
enableEditMode() {
|
enableEditMode() {
|
||||||
if (!this.element.attributes.orderable.urls.update_url) return
|
if (!this.element.attributes.orderable.urls.update_url) return
|
||||||
if (this.inEditMode == true) return
|
if (this.inEditMode) return
|
||||||
this.inEditMode = true
|
this.inEditMode = true
|
||||||
},
|
},
|
||||||
disableEditMode() {
|
disableEditMode() {
|
||||||
this.inEditMode = false
|
this.inEditMode = false
|
||||||
},
|
},
|
||||||
update(data) {
|
update(data) {
|
||||||
this.element.attributes.orderable.text_view = data.data.attributes.text_view
|
this.element.attributes.orderable.text_view = data.attributes.text_view
|
||||||
this.element.attributes.orderable.text = data.data.attributes.text
|
this.element.attributes.orderable.text = data.attributes.text
|
||||||
this.element.attributes.orderable.name = data.data.attributes.name
|
this.element.attributes.orderable.name = data.attributes.name
|
||||||
this.element.attributes.orderable.updated_at = data.data.attributes.updated_at
|
this.element.attributes.orderable.updated_at = data.attributes.updated_at
|
||||||
this.$emit('update', this.element, true)
|
this.$emit('update', this.element, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,13 @@
|
||||||
<form class="tiny-mce-editor" role="form" :action="updateUrl" accept-charset="UTF-8" data-remote="true" method="post">
|
<form class="tiny-mce-editor" role="form" :action="updateUrl" accept-charset="UTF-8" data-remote="true" method="post">
|
||||||
<input type="hidden" name="_method" value="patch">
|
<input type="hidden" name="_method" value="patch">
|
||||||
<div class="hidden tinymce-cancel-button tox-mbtn" tabindex="-1">
|
<div class="hidden tinymce-cancel-button tox-mbtn" tabindex="-1">
|
||||||
<button type="button" tabindex="-1">
|
<button type="button" tabindex="-1">
|
||||||
<span class="fas fa-times"></span>
|
<span class="fas fa-times"></span>
|
||||||
<span class="mce-txt">{{ i18n.t('general.cancel') }}</span>
|
<span class="mce-txt">{{ i18n.t('general.cancel') }}</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="hidden tinymce-save-button tox-mbtn" tabindex="-1">
|
<div class="hidden tinymce-save-button tox-mbtn" tabindex="-1">
|
||||||
<button type="button" tabindex="-1">
|
<button type="button" tabindex="-1" >
|
||||||
<span class="fas fa-check"></span>
|
<span class="fas fa-check"></span>
|
||||||
<span class="mce-txt">{{ i18n.t('general.save') }}</span>
|
<span class="mce-txt">{{ i18n.t('general.save') }}</span>
|
||||||
</button>
|
</button>
|
||||||
|
@ -19,6 +19,7 @@
|
||||||
<i class="fas fa-check-circle"></i>
|
<i class="fas fa-check-circle"></i>
|
||||||
<span>{{ i18n.t('tiny_mce.saved_label') }}</span>
|
<span>{{ i18n.t('tiny_mce.saved_label') }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div :id="`${objectType}_view_${objectId}`"
|
<div :id="`${objectType}_view_${objectId}`"
|
||||||
@click="initTinymce"
|
@click="initTinymce"
|
||||||
v-html="value_html"
|
v-html="value_html"
|
||||||
|
@ -85,6 +86,8 @@
|
||||||
inEditMode() {
|
inEditMode() {
|
||||||
if (this.inEditMode) {
|
if (this.inEditMode) {
|
||||||
this.initTinymce();
|
this.initTinymce();
|
||||||
|
} else {
|
||||||
|
this.wrapTables();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
characterCount() {
|
characterCount() {
|
||||||
|
@ -94,9 +97,6 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
editorInstance() {
|
|
||||||
return tinyMCE.activeEditor;
|
|
||||||
},
|
|
||||||
error() {
|
error() {
|
||||||
if(this.characterLimit && this.characterCount > this.characterLimit) {
|
if(this.characterLimit && this.characterCount > this.characterLimit) {
|
||||||
return(
|
return(
|
||||||
|
@ -116,13 +116,13 @@
|
||||||
mounted() {
|
mounted() {
|
||||||
if (this.inEditMode) {
|
if (this.inEditMode) {
|
||||||
this.initTinymce();
|
this.initTinymce();
|
||||||
|
} else {
|
||||||
|
this.wrapTables();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
initTinymce(e) {
|
initTinymce(e) {
|
||||||
let textArea = `#${this.objectType}_textarea_${this.objectId}`;
|
let textArea = `#${this.objectType}_textarea_${this.objectId}`;
|
||||||
const vueTinyMce = this;
|
|
||||||
|
|
||||||
|
|
||||||
if (this.active) return
|
if (this.active) return
|
||||||
if (e && $(e.target).prop("tagName") === 'A') return
|
if (e && $(e.target).prop("tagName") === 'A') return
|
||||||
|
@ -130,31 +130,34 @@
|
||||||
if (e && $(e.target).hasClass('record-info-link')) return
|
if (e && $(e.target).hasClass('record-info-link')) return
|
||||||
if (e && $(e.target).parent().hasClass('atwho-inserted')) return
|
if (e && $(e.target).parent().hasClass('atwho-inserted')) return
|
||||||
|
|
||||||
TinyMCE.init(
|
TinyMCE.init(textArea, {
|
||||||
textArea,
|
onSaveCallback: (data) => {
|
||||||
{
|
if (data.data) {
|
||||||
onSaveCallback(data) {
|
this.$emit('update', data.data)
|
||||||
if (data) {
|
|
||||||
vueTinyMce.$emit('update', data)
|
|
||||||
}
|
}
|
||||||
vueTinyMce.$emit('editingDisabled');
|
this.$emit('editingDisabled');
|
||||||
}
|
},
|
||||||
|
afterInitCallback: () => {
|
||||||
|
this.active = true;
|
||||||
|
this.initCharacterCount();
|
||||||
|
this.$emit('editingEnabled');
|
||||||
|
},
|
||||||
|
placeholder: this.placeholder
|
||||||
}
|
}
|
||||||
).then(() => {
|
)
|
||||||
this.active = true;
|
|
||||||
this.initCharacterCount();
|
|
||||||
this.$emit('editingEnabled');
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
getStaticUrl(name) {
|
getStaticUrl(name) {
|
||||||
return $(`meta[name=\'${name}\']`).attr('content');
|
return $(`meta[name=\'${name}\']`).attr('content');
|
||||||
},
|
},
|
||||||
|
wrapTables() {
|
||||||
|
$(this.$el).find('.tinymce-view table').wrapAll('<div style="overflow: auto"></div>');
|
||||||
|
},
|
||||||
initCharacterCount() {
|
initCharacterCount() {
|
||||||
if (!this.editorInstance()) return;
|
if (!this.editorInstance()) return;
|
||||||
|
|
||||||
this.characterCount = $(this.editorInstance().getContent()).text().length;
|
this.characterCount = this.editorInstance().plugins.wordcount.body.getCharacterCount();
|
||||||
this.editorInstance().on('input change paste keydown', (e) => {
|
this.editorInstance().on('input change paste keydown', (e) => {
|
||||||
e.currentTarget && (this.characterCount = (e.currentTarget).innerText.length);
|
e.currentTarget && (this.characterCount = this.editorInstance().plugins.wordcount.body.getCharacterCount());
|
||||||
});
|
});
|
||||||
|
|
||||||
this.editorInstance().on('remove', () => this.active = false);
|
this.editorInstance().on('remove', () => this.active = false);
|
||||||
|
@ -165,7 +168,7 @@
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
editorInstance() {
|
editorInstance() {
|
||||||
return tinyMCE.editors[0];
|
return tinyMCE.activeEditor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10687,9 +10687,9 @@ tiny-warning@^1.0.0:
|
||||||
integrity sha512-rru86D9CpQRLvsFG5XFdy0KdLAvjdQDyZCsRcuu60WtzFylDM3eAWSxEVz5kzL2Gp544XiUvPbVKtOA/txLi9Q==
|
integrity sha512-rru86D9CpQRLvsFG5XFdy0KdLAvjdQDyZCsRcuu60WtzFylDM3eAWSxEVz5kzL2Gp544XiUvPbVKtOA/txLi9Q==
|
||||||
|
|
||||||
tinymce@^6.1.2:
|
tinymce@^6.1.2:
|
||||||
version "6.1.2"
|
version "6.3.1"
|
||||||
resolved "https://registry.yarnpkg.com/tinymce/-/tinymce-6.1.2.tgz"
|
resolved "https://registry.yarnpkg.com/tinymce/-/tinymce-6.3.1.tgz#cc5cf2b9f702d429cf5d1d21ed62245d768bfc4f"
|
||||||
integrity sha512-tl4KbEKdPzyPTatJkblN2AqzRj9jaRGyATnwaSnsLFGKb4AI6B+4e0Gc8dUDXuqAjgSnHokhzamrQJLbSn4CmQ==
|
integrity sha512-+oCwXuTxAdJXVJ0130OxQz0JDNsqg3deuzgeUo8X5Vb27EzCJgXwO5eWvCxvkxpQo4oiHMVlM4tUIpTUHufHGQ==
|
||||||
|
|
||||||
tmp@^0.0.33:
|
tmp@^0.0.33:
|
||||||
version "0.0.33"
|
version "0.0.33"
|
||||||
|
|
Loading…
Add table
Reference in a new issue