Skip to content

gcoai-stream-to-paragraph-field.js: Fixed duplicate code and an issue with snippet not working. #1047

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

Merged
merged 1 commit into from
Mar 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions gc-openai/gcoai-stream-to-paragraph-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ $streamFieldInput.on( 'change', function() {
$input = $( `#input_GFFORMID_${responseFieldId}` );
var inputValue = this.value;

// Get HTML from response field if TinyMCE is available.
if (window.tinyMCE) {
var html = $streamFieldInput.closest( '.gfield' ).find('.gcoai-output').html();
// Check if the response field has TinyMCE enabled.
var tiny = window.tinyMCE && tinyMCE.get( $input.attr( 'id' ) );

// Get HTML for the response field if TinyMCE is available.
if (tiny) {
var html = $streamFieldInput.closest( '.gfield' ).find('.gcoai-output').html();

// Set HTML content in TinyMCE.
var tiny = tinyMCE.get( $input.attr( 'id' ) );
if (tiny) {
tiny.setContent( html );
}
tiny.setContent( html );
} else {
// If TinyMCE is not available, use plain text.
$input.val( inputValue );
Expand All @@ -57,13 +57,4 @@ if ( $wpEditor.length ) {

$( `#input_GFFORMID_${promptFieldId}` ).on( 'blur', function() {
$streamButton.trigger( 'click' );
} );

$wpEditor = $newButton.parents('.wp-editor-container');
if ($wpEditor.length) {
$newButton.insertAfter($wpEditor);
}

$( `#input_GFFORMID_${promptFieldId}` ).on('blur', function() {
$streamButton.trigger('click');
});
Loading