mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 23:16:15 +08:00
Fix MarvinJS image toolbar [SCI-7934]
This commit is contained in:
parent
ed76fac640
commit
fbf7e69100
|
@ -300,7 +300,7 @@ window.I18n = I18n
|
|||
// Multiple modal support
|
||||
// https://stackoverflow.com/a/24914782
|
||||
$(document).on('shown.bs.modal', '.modal', function() {
|
||||
const zIndex = 1040 + 10 * $('.modal:visible').length;
|
||||
const zIndex = 2040 + 10 * $('.modal:visible').length;
|
||||
$(this).css('z-index', zIndex);
|
||||
setTimeout(() => $('.modal-backdrop').not('.modal-stack').css('z-index', zIndex - 1).addClass('modal-stack'));
|
||||
});
|
||||
|
|
|
@ -39,8 +39,33 @@ tinymce.PluginManager.add('custom_image_toolbar', (editor) => {
|
|||
return elem.dataset.sourceType === 'marvinjs';
|
||||
}
|
||||
|
||||
// This method removes image edit button groups if the selected image is a MarvinJS image
|
||||
// Since there is no appropriate TinyMCE event to catch the render of the toolbar
|
||||
// we need to rely on a MutationObserver, which will watch the TinyMCE context toolbar element,
|
||||
// and then remove the two image editing groups.
|
||||
function removeImageEditButtons() {
|
||||
const tinyMceAuxNode = document.getElementsByClassName('tox-tinymce-aux')[0];
|
||||
const tinyMceAuxNodeObserver = new MutationObserver(() => {
|
||||
let toxPop = document.getElementsByClassName('tox-pop')[0];
|
||||
if (!toxPop) return;
|
||||
|
||||
let toolbarGroups = toxPop.getElementsByClassName('tox-toolbar__group');
|
||||
if (toolbarGroups[3]) {
|
||||
toolbarGroups[2].classList.add('hidden');
|
||||
toolbarGroups[3].classList.add('hidden');
|
||||
}
|
||||
});
|
||||
|
||||
tinyMceAuxNodeObserver.observe(tinyMceAuxNode, { attributes: false, childList: true, subtree: false });
|
||||
|
||||
// We can stop observing once the toolbar was loaded and changed.
|
||||
setTimeout(() => { tinyMceAuxNodeObserver.disconnect() }, 100);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
editor.ui.registry.addContextToolbar('marvinJsToolbar', {
|
||||
predicate: (node) => isMarvinJs(node),
|
||||
predicate: (node) => isMarvinJs(node) && removeImageEditButtons(),
|
||||
items: 'marvinjs_edit',
|
||||
position: 'node',
|
||||
scope: 'node'
|
||||
|
|
Loading…
Reference in a new issue