diff --git a/app/assets/javascripts/tinymce/plugins/placeholder/plugin.js b/app/assets/javascripts/tinymce/plugins/placeholder/plugin.js index 55e5804d9..7e7007445 100644 --- a/app/assets/javascripts/tinymce/plugins/placeholder/plugin.js +++ b/app/assets/javascripts/tinymce/plugins/placeholder/plugin.js @@ -5,8 +5,8 @@ tinymce.PluginManager.add('placeholder', function(editor) { var editorForm = $(editor.getContainer()).closest('form'); var editorToolbar = editorForm.find('.mce-top-part'); var placeholderText = editor.getElement().getAttribute('placeholder') || editor.settings.placeholder; - var placeholderAttrs = editor.settings.placeholder_attrs || { - style: { + var placeholderAttrs = { + style: ` position: 'absolute', top: (editorToolbar.height()) + 'px', left: 0, @@ -15,7 +15,7 @@ tinymce.PluginManager.add('placeholder', function(editor) { width: 'calc(100% - 50px)', overflow: 'hidden', 'white-space': 'pre-wrap' - } + ` }; var contentAreaContainer = editor.getContentAreaContainer(); diff --git a/app/assets/stylesheets/tiny_mce.scss b/app/assets/stylesheets/tiny_mce.scss index 2d4cd4e52..329abcd49 100644 --- a/app/assets/stylesheets/tiny_mce.scss +++ b/app/assets/stylesheets/tiny_mce.scss @@ -38,6 +38,16 @@ position: relative !important; } +.tox.tox-tinymce { + left: -100000px; + position: absolute; + + &.tox-tinymce--loaded { + left: 0; + position: relative; + } +} + .tinymce-placeholder { background: $color-concrete; opacity: .7; @@ -45,8 +55,15 @@ width: 100%; } -.tinymce-save-button, -.tinymce-cancel-button { +.tox-edit-area { + label { + color: $color-silver-chalice !important; + padding: 5px !important; + } +} + +.tinymce-save-button.tox-mbtn, +.tinymce-cancel-button.tox-mbtn { cursor: pointer; .fas { @@ -54,6 +71,10 @@ font-weight: 900; margin-top: 3px; } + + &:hover { + background: transparent !important; + } } .tinymce-save-controls { diff --git a/app/javascript/packs/tiny_mce.js b/app/javascript/packs/tiny_mce.js index e5f227a6e..6e78d4339 100644 --- a/app/javascript/packs/tiny_mce.js +++ b/app/javascript/packs/tiny_mce.js @@ -183,9 +183,10 @@ window.TinyMCE = (() => { } 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, convert_urls: false, + promotion: false, menu: { 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', plugins, autoresize_bottom_margin: 20, - // placeholder: options.placeholder, + placeholder: options.placeholder, skin: false, content_css: false, toolbar_sticky: true, @@ -272,13 +273,14 @@ window.TinyMCE = (() => { } ], 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'); $('.tinymce-placeholder').css('height', `${$(editor.editorContainer).height()}px`); - $(editor.editorContainer).css('max-height', '0').css('opacity', '0') setTimeout(() => { - $(editor.editorContainer).css('max-height', '').css('opacity', '') + editorContainer.addClass('tox-tinymce--loaded'); $('.tinymce-placeholder').remove(); }, 400); @@ -351,6 +353,8 @@ window.TinyMCE = (() => { SmartAnnotation.init($(editor.contentDocument.activeElement)); SmartAnnotation.preventPropagation('.atwho-user-popover'); initHighlightjsIframe($(editor.iframeElement).contents()); + + if (options.afterInitCallback) { options.afterInitCallback(); } }, setup: (editor) => { editor.on('keydown', (e) => { diff --git a/app/javascript/packs/tinymce/placeholder/plugin.js b/app/javascript/packs/tinymce/placeholder/plugin.js index 3c122feec..b53b77a7f 100644 --- a/app/javascript/packs/tinymce/placeholder/plugin.js +++ b/app/javascript/packs/tinymce/placeholder/plugin.js @@ -6,7 +6,7 @@ tinymce.PluginManager.add('placeholder', (editor) => { // const editorToolbar = editorForm.find('.tox-editor-header'); const placeholderText = editor.getElement().getAttribute('placeholder'); const placeholderAttrs = { - style: { + style: ` position: 'absolute', top: '0px', left: '0px', @@ -15,7 +15,7 @@ tinymce.PluginManager.add('placeholder', (editor) => { width: 'calc(100% - 50px)', overflow: 'hidden', 'white-space': 'pre-wrap' - } + ` }; const contentAreaContainer = editor.getContentAreaContainer(); diff --git a/app/javascript/vue/protocol/container.vue b/app/javascript/vue/protocol/container.vue index 9607fffc8..2966709c5 100644 --- a/app/javascript/vue/protocol/container.vue +++ b/app/javascript/vue/protocol/container.vue @@ -204,7 +204,7 @@ }); }, updateDescription(protocol) { - this.protocol.attributes = protocol.data.attributes + this.protocol.attributes = protocol.attributes }, addStep(position) { $.post(this.urls.add_step_url, {position: position}, (result) => { diff --git a/app/javascript/vue/protocol/step_elements/text.vue b/app/javascript/vue/protocol/step_elements/text.vue index 234bdef27..b6e72675f 100644 --- a/app/javascript/vue/protocol/step_elements/text.vue +++ b/app/javascript/vue/protocol/step_elements/text.vue @@ -79,17 +79,17 @@ methods: { enableEditMode() { if (!this.element.attributes.orderable.urls.update_url) return - if (this.inEditMode == true) return + if (this.inEditMode) return this.inEditMode = true }, disableEditMode() { this.inEditMode = false }, update(data) { - this.element.attributes.orderable.text_view = data.data.attributes.text_view - this.element.attributes.orderable.text = data.data.attributes.text - this.element.attributes.orderable.name = data.data.attributes.name - this.element.attributes.orderable.updated_at = data.data.attributes.updated_at + this.element.attributes.orderable.text_view = data.attributes.text_view + this.element.attributes.orderable.text = data.attributes.text + this.element.attributes.orderable.name = data.attributes.name + this.element.attributes.orderable.updated_at = data.attributes.updated_at this.$emit('update', this.element, true) } } diff --git a/app/javascript/vue/shared/tinymce.vue b/app/javascript/vue/shared/tinymce.vue index 3b87b21c3..8be017633 100644 --- a/app/javascript/vue/shared/tinymce.vue +++ b/app/javascript/vue/shared/tinymce.vue @@ -4,13 +4,13 @@
+
this.characterLimit) { return( @@ -116,13 +116,13 @@ mounted() { if (this.inEditMode) { this.initTinymce(); + } else { + this.wrapTables(); } }, methods: { initTinymce(e) { let textArea = `#${this.objectType}_textarea_${this.objectId}`; - const vueTinyMce = this; - if (this.active) 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).parent().hasClass('atwho-inserted')) return - TinyMCE.init( - textArea, - { - onSaveCallback(data) { - if (data) { - vueTinyMce.$emit('update', data) + TinyMCE.init(textArea, { + onSaveCallback: (data) => { + if (data.data) { + this.$emit('update', data.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) { return $(`meta[name=\'${name}\']`).attr('content'); }, + wrapTables() { + $(this.$el).find('.tinymce-view table').wrapAll('
'); + }, initCharacterCount() { 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) => { - 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); @@ -165,7 +168,7 @@ }); }, editorInstance() { - return tinyMCE.editors[0]; + return tinyMCE.activeEditor; } } } diff --git a/yarn.lock b/yarn.lock index 36f3baa09..abe498bd7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10687,9 +10687,9 @@ tiny-warning@^1.0.0: integrity sha512-rru86D9CpQRLvsFG5XFdy0KdLAvjdQDyZCsRcuu60WtzFylDM3eAWSxEVz5kzL2Gp544XiUvPbVKtOA/txLi9Q== tinymce@^6.1.2: - version "6.1.2" - resolved "https://registry.yarnpkg.com/tinymce/-/tinymce-6.1.2.tgz" - integrity sha512-tl4KbEKdPzyPTatJkblN2AqzRj9jaRGyATnwaSnsLFGKb4AI6B+4e0Gc8dUDXuqAjgSnHokhzamrQJLbSn4CmQ== + version "6.3.1" + resolved "https://registry.yarnpkg.com/tinymce/-/tinymce-6.3.1.tgz#cc5cf2b9f702d429cf5d1d21ed62245d768bfc4f" + integrity sha512-+oCwXuTxAdJXVJ0130OxQz0JDNsqg3deuzgeUo8X5Vb27EzCJgXwO5eWvCxvkxpQo4oiHMVlM4tUIpTUHufHGQ== tmp@^0.0.33: version "0.0.33"