Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Nov 15, 2020

Conversation

mviggiano
Copy link

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.

@@ -110,10 +110,19 @@
if ( 'html' === core_editor_state || 'tinymce' === core_editor_state ) {
setUserSetting( 'editor', core_editor_state );
}
},

should_readd_rte: function( e, el ) {

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
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' ) ) {

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
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
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
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
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