Merge pull request #4413 from aignatov-bio/ai-sci-7154-update-tinymce-marvinjs-plugin

Update tinyMCE marvinjs plugin [SCI-7154]
This commit is contained in:
aignatov-bio 2022-09-06 13:11:48 +02:00 committed by GitHub
commit eda4f48d60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 47 deletions

View file

@ -161,9 +161,8 @@ var MarvinJsEditorApi = (function() {
} else if (config.objectType === 'Result') {
location.reload();
} else if (config.objectType === 'TinyMceAsset') {
json = tinymce.util.JSON.parse(result);
json = JSON.parse(result);
config.editor.execCommand('mceInsertContent', false, TinyMceBuildHTML(json));
TinyMCE.updateImages(config.editor);
}
$(marvinJsModal).modal('hide');
config.button.dataset.inProgress = false;
@ -280,48 +279,6 @@ var MarvinJsEditorApi = (function() {
};
});
// TinyMCE plugin
/*
(function() {
'use strict';
tinymce.PluginManager.requireLangPack('MarvinJsPlugin');
tinymce.add('tinymce.plugins.MarvinJsPlugin', {
MarvinJsPlugin: function(ed) {
var editor = ed;
function openMarvinJs() {
MarvinJsEditor.open({
mode: 'new-tinymce',
marvinUrl: '/tiny_mce_assets/marvinjs',
editor: editor
});
}
// Add a button that opens a window
editor.addButton('marvinjsplugin', {
tooltip: I18n.t('marvinjs.new_button'),
icon: 'marvinjs',
onclick: openMarvinJs
});
// Adds a menu item to the tools menu
editor.addMenuItem('marvinjsplugin', {
text: I18n.t('marvinjs.new_button'),
icon: 'marvinjs',
context: 'insert',
onclick: openMarvinJs
});
}
});
tinymce.PluginManager.add(
'marvinjsplugin',
tinymce.plugins.MarvinJsPlugin
);
})();
*/
// Initialization
$(document).on('click', '.marvinjs-edit-button', function() {
var editButton = $(this);

View file

@ -21,6 +21,7 @@ import 'tinymce/plugins/insertdatetime';
import 'tinymce/plugins/nonbreaking';
import 'tinymce/plugins/save';
import 'tinymce/plugins/directionality';
import './tinymce/marvinjs/plugin';
window.TinyMCE = (function() {
'use strict';
@ -157,7 +158,7 @@ window.TinyMCE = (function() {
$(selector).closest('.form-group')
.before('<div class="tinymce-placeholder" style="height:' + tinyMceInitSize + 'px"></div>');
tinyMceContainer.addClass('hidden');
plugins = 'table autosave autoresize link advlist codesample autolink lists charmap anchor searchreplace wordcount visualblocks visualchars insertdatetime nonbreaking save directionality';
plugins = 'table autosave autoresize link advlist codesample autolink lists charmap anchor searchreplace wordcount visualblocks visualchars insertdatetime nonbreaking save directionality marvinjs';
// if (typeof (MarvinJsEditor) !== 'undefined') plugins += ' marvinjsplugin';
@ -171,10 +172,10 @@ window.TinyMCE = (function() {
selector: selector,
convert_urls: false,
menubar: 'file edit view insert format table',
toolbar: 'undo redo restoredraft | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | link | forecolor backcolor | codesample',
toolbar: 'undo redo restoredraft | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | link | forecolor backcolor | codesample | marvinjs',
plugins: plugins,
autoresize_bottom_margin: 20,
placeholder: options.placeholder,
// placeholder: options.placeholder,
skin: false,
content_css: false,
content_style: "body { font-family: Lato, sans-serif; }",

View file

@ -0,0 +1,41 @@
/* global tinymce I18n MarvinJsEditor */
// TinyMCE plugin
tinymce.PluginManager.add('marvinjs', (editor) => {
function openMarvinJs() {
MarvinJsEditor.open({
mode: 'new-tinymce',
marvinUrl: '/tiny_mce_assets/marvinjs',
editor
});
}
// Add marvinjs button
editor.ui.registry.addIcon(
'marvinjs',
`<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
<path fill="#595959" d="M15.875 6l8.875 4.438v7L23 15.625v-4.063l-7.125-3.563-7.125 3.563v9.375l5.625 2.813-.75 1.563L7 22V10.437L15.875 6zm-.813 4l.875-.5 6.125 3.063v.938l-7-3.501zm-4.5 10.437l-.938-.438v-7.563l.938-.438v8.439zm17.875 1.938c.459 0 .844.156 1.156.469.312.313.468.698.469 1.156v2.375c0 .209-.104.313-.313.313-.209 0-.313-.104-.313-.313V24c0-.25-.104-.48-.313-.688-.209-.209-.438-.313-.688-.313h-1v1c0 .25-.115.375-.344.375-.23 0-.344-.125-.344-.375v-1.313a.974.974 0 0 0-.281-.719.974.974 0 0 0-.719-.281h-1v1.688c0 .209-.115.313-.344.313-.23 0-.344-.104-.344-.313v-1.375c0-.25-.094-.48-.281-.688a.923.923 0 0 0-.719-.313h-1v3c0 .25-.104.375-.313.375-.209 0-.313-.125-.313-.375v-6c0-.25-.104-.48-.313-.688a.989.989 0 0 0-.719-.313c-.27 0-.5.104-.688.313a1.002 1.002 0 0 0-.281.688v8.375c0 .209-.115.313-.344.313-.23 0-.344-.104-.344-.313V25.31l-.938-.438c-.417-.209-.833-.24-1.25-.094-.417.146-.73.427-.938.844l-.188.25c-.083.209-.02.355.188.438.375.209.802.459 1.281.75.479.291 1.083.781 1.813 1.469.73.688 1.115 1.323 1.156 1.906.042.25-.041.375-.25.375h-.063c-.209 0-.313-.083-.313-.25-.083-.625-.563-1.282-1.438-1.969s-1.709-1.24-2.5-1.656a.95.95 0 0 1-.5-.594 1.015 1.015 0 0 1 .063-.781l.125-.25c.292-.583.74-.98 1.344-1.188a2.215 2.215 0 0 1 1.781.125l.625.313v-6.563c0-.459.167-.844.5-1.156.333-.312.73-.468 1.188-.469.459 0 .844.156 1.156.469.312.313.468.699.469 1.156v2.375h1c.583 0 1.042.208 1.375.625h1.313c.417 0 .771.125 1.063.375.292.25.48.583.563 1h1.063l.005.003z"/>
</svg>`
);
// Add a button that opens a window
editor.ui.registry.addButton('marvinjs', {
tooltip: I18n.t('marvinjs.new_button'),
icon: 'marvinjs',
onAction: openMarvinJs
});
// Adds a menu item to the tools menu
editor.ui.registry.addMenuItem('marvinjs', {
text: I18n.t('marvinjs.new_button'),
icon: 'marvinjs',
context: 'insert',
onclick: openMarvinJs
});
return {
getMetadata: () => ({
name: 'MarvinJs Plugin'
})
};
});