Skip to content

Fix for tinymce editor not being initialized on richtext fields#628

Merged
dlh01 merged 6 commits intomasterfrom
collapsed-richtext-tinymce-reinit
Nov 15, 2020
Merged

Fix for tinymce editor not being initialized on richtext fields#628
dlh01 merged 6 commits intomasterfrom
collapsed-richtext-tinymce-reinit

Conversation

@mviggiano
Copy link
Copy Markdown

Meta boxes with Fieldmanager_RichTextArea fields inside of them that were collapsed on page load did not have their TinyMCE initialized due to not being visible. This PR will add code to check on postbox-toggle events whether or not the toggled postbox has such a field, and if so, whether or not it has been initialized. If it has a field that has not been initialized, the code will call add_rte_to_visible_textareas() again to add the TinyMCE to the textarea.

}
},

should_readd_rte: function( e, el ) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this spelled correctly (readd)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I'm aware?

js/richtext.js Outdated

should_readd_rte: function( e, el ) {
if ( ! $( el ).hasClass( 'closed' ) && $( el ).find( 'textarea.fm-richtext' ).length ) {
if ( ! $( el ).find( 'textarea' ).hasClass( 'fm-tinymce' ) ) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could combine these loops and do it without jQuery:

if (
  !el.classList.contains( 'closed' ) && 
  el.querySelector('textarea.fm-richtext') &&
  !el.querySelector( 'textarea.fm-tinymce') 
) {
  fm.richtextarea.add_rte_to_visible_textareas();
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this - thanks for the tip!

Copy link
Copy Markdown
Contributor

@mboynes mboynes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we can merge this, you need to bump the version number on the JS file.

@mboynes mboynes added this to the 1.2.0 milestone Oct 7, 2017
@mslinnea
Copy link
Copy Markdown
Member

@mboynes @dlh01 I've fixed the merge conflicts here and I think this is ready for 1.4.0. I tested this solution in a Gutenberg environment and it works there as well.

@dlh01
Copy link
Copy Markdown
Member

dlh01 commented Nov 15, 2020

Thanks @mslinnea!

@dlh01 dlh01 merged commit 9a6d6f0 into master Nov 15, 2020
@dlh01 dlh01 deleted the collapsed-richtext-tinymce-reinit branch November 15, 2020 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants