From ece8af9ea76649293b1f9cb80b1a4504b660b7ad Mon Sep 17 00:00:00 2001 From: Malay Ladu Date: Wed, 26 Mar 2025 22:38:51 +0530 Subject: [PATCH] `gw-rich-text-html-fields.php`: Added support to switch between visual and text mode. --- gravity-forms/gw-rich-text-html-fields.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gravity-forms/gw-rich-text-html-fields.php b/gravity-forms/gw-rich-text-html-fields.php index a5d01f2c8..e743793d4 100644 --- a/gravity-forms/gw-rich-text-html-fields.php +++ b/gravity-forms/gw-rich-text-html-fields.php @@ -9,8 +9,7 @@ * * @todo * 1. Add merge tag selector. - * 2. Allow switching to text mode: window.switchEditors.go( 'rich_field_content', mode ) - * 3. Add support for inserting images. + * 2. Add support for inserting images. */ add_action( 'admin_init', function() { @@ -68,8 +67,16 @@ } ); } ); jQuery( document).on( 'tinymce-editor-setup', function ( event, editor ) { - if ( editor.id === 'field_rich_content' ) { + var editorId = 'field_rich_content'; + if ( editor.id === editorId ) { editor.settings.toolbar1 = 'bold,italic,underline,bullist,numlist,alignleft,aligncenter,alignright,link'; + + // Switch to visual/text mode. + jQuery(`#wp-${editorId}-wrap .switch-tmce, #wp-${editorId}-wrap .switch-html`).on('click', function() { + var mode = jQuery(this).hasClass('switch-tmce') ? 'tmce' : 'html'; + + window.switchEditors.go(editorId, mode); + }); } } );