From 973576bc6b6f80aecd60835af1113fb36e1c5c00 Mon Sep 17 00:00:00 2001 From: hdvos Date: Wed, 25 Jan 2023 10:49:00 +0100 Subject: [PATCH 1/5] use different method to check for active editor --- js/src/collect/collect-v5.js | 11 +++++++--- js/src/collect/tinymceHelpers.js | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 js/src/collect/tinymceHelpers.js diff --git a/js/src/collect/collect-v5.js b/js/src/collect/collect-v5.js index 88c6ce33..74b59114 100644 --- a/js/src/collect/collect-v5.js +++ b/js/src/collect/collect-v5.js @@ -1,4 +1,7 @@ /* global _, acf, jQuery, wp */ + +const isTinyMCEAvailable = require( "./tinymceHelpers" ); + module.exports = function() { var outerFieldsName = [ "flexible_content", @@ -10,13 +13,15 @@ module.exports = function() { var outerFields = []; var acfFields = []; - if ( wp.data.select( "core/block-editor" ) ) { + // Check whether classic editor is used. + if ( isTinyMCEAvailable( "content" ) ) { + acfFields = acf.get_fields(); + } else { + // Assume Gutenberg is used. // Return only fields in metabox areas (either below or side) or // ACF block fields in the content (not in the sidebar, to prevent duplicates) var parentContainer = jQuery( ".metabox-location-normal, .metabox-location-side, .acf-block-component.acf-block-body" ); acfFields = acf.get_fields( false, parentContainer ); - } else { - acfFields = acf.get_fields(); } var fields = _.map( acfFields, function( field ) { diff --git a/js/src/collect/tinymceHelpers.js b/js/src/collect/tinymceHelpers.js new file mode 100644 index 00000000..a40711ac --- /dev/null +++ b/js/src/collect/tinymceHelpers.js @@ -0,0 +1,35 @@ +/* global tinyMCE */ + +/** + * Returns whether or not the tinyMCE script is available on the page. + * + * @returns {boolean} True when tinyMCE is loaded. + */ +function isTinyMCELoaded() { + return ( + typeof tinyMCE !== "undefined" && + typeof tinyMCE.editors !== "undefined" && + tinyMCE.editors.length !== 0 + ); +} + +/** + * Returns whether or not a tinyMCE editor with the given ID is available. + * + * @param {string} editorID The ID of the tinyMCE editor. + * + * @returns {void} + */ +function isTinyMCEAvailable( editorID ) { + if ( ! isTinyMCELoaded() ) { + return false; + } + + const editor = tinyMCE.get( editorID ); + + return ( + editor !== null && ! editor.isHidden() + ); +} + +module.exports = isTinyMCEAvailable; From 6286282963722b9665a5c2c48ed4fc9b3e0cdd1c Mon Sep 17 00:00:00 2001 From: hdvos Date: Mon, 30 Jan 2023 13:36:31 +0100 Subject: [PATCH 2/5] use `window` to detect which editor is used. --- js/src/collect/collect-v5.js | 12 +++++------ js/src/collect/tinymceHelpers.js | 35 -------------------------------- 2 files changed, 5 insertions(+), 42 deletions(-) delete mode 100644 js/src/collect/tinymceHelpers.js diff --git a/js/src/collect/collect-v5.js b/js/src/collect/collect-v5.js index 74b59114..5ee46879 100644 --- a/js/src/collect/collect-v5.js +++ b/js/src/collect/collect-v5.js @@ -1,6 +1,4 @@ -/* global _, acf, jQuery, wp */ - -const isTinyMCEAvailable = require( "./tinymceHelpers" ); +/* global _, acf, jQuery, wp, window */ module.exports = function() { var outerFieldsName = [ @@ -14,14 +12,14 @@ module.exports = function() { var acfFields = []; // Check whether classic editor is used. - if ( isTinyMCEAvailable( "content" ) ) { - acfFields = acf.get_fields(); + if ( window.wpseoScriptData.isBlockEditor ) { + var parentContainer = jQuery( ".metabox-location-normal, .metabox-location-side, .acf-block-component.acf-block-body" ); + acfFields = acf.get_fields( false, parentContainer ); } else { // Assume Gutenberg is used. // Return only fields in metabox areas (either below or side) or // ACF block fields in the content (not in the sidebar, to prevent duplicates) - var parentContainer = jQuery( ".metabox-location-normal, .metabox-location-side, .acf-block-component.acf-block-body" ); - acfFields = acf.get_fields( false, parentContainer ); + acfFields = acf.get_fields(); } var fields = _.map( acfFields, function( field ) { diff --git a/js/src/collect/tinymceHelpers.js b/js/src/collect/tinymceHelpers.js deleted file mode 100644 index a40711ac..00000000 --- a/js/src/collect/tinymceHelpers.js +++ /dev/null @@ -1,35 +0,0 @@ -/* global tinyMCE */ - -/** - * Returns whether or not the tinyMCE script is available on the page. - * - * @returns {boolean} True when tinyMCE is loaded. - */ -function isTinyMCELoaded() { - return ( - typeof tinyMCE !== "undefined" && - typeof tinyMCE.editors !== "undefined" && - tinyMCE.editors.length !== 0 - ); -} - -/** - * Returns whether or not a tinyMCE editor with the given ID is available. - * - * @param {string} editorID The ID of the tinyMCE editor. - * - * @returns {void} - */ -function isTinyMCEAvailable( editorID ) { - if ( ! isTinyMCELoaded() ) { - return false; - } - - const editor = tinyMCE.get( editorID ); - - return ( - editor !== null && ! editor.isHidden() - ); -} - -module.exports = isTinyMCEAvailable; From 4b384e01d0385e7ad4bc0ceabc36ca4cec8f100e Mon Sep 17 00:00:00 2001 From: hdvos Date: Tue, 31 Jan 2023 11:13:13 +0100 Subject: [PATCH 3/5] Update js/src/collect/collect-v5.js Co-authored-by: Aida Marfuaty <48715883+FAMarfuaty@users.noreply.github.com> --- js/src/collect/collect-v5.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/js/src/collect/collect-v5.js b/js/src/collect/collect-v5.js index 5ee46879..aa05e791 100644 --- a/js/src/collect/collect-v5.js +++ b/js/src/collect/collect-v5.js @@ -11,8 +11,12 @@ module.exports = function() { var outerFields = []; var acfFields = []; - // Check whether classic editor is used. + // Check if Gutenberg editor is used. if ( window.wpseoScriptData.isBlockEditor ) { + /* + * Return only fields in metabox areas (either below or side) or + * ACF block fields in the content (not in the sidebar, to prevent duplicates). + */ var parentContainer = jQuery( ".metabox-location-normal, .metabox-location-side, .acf-block-component.acf-block-body" ); acfFields = acf.get_fields( false, parentContainer ); } else { From e6fd09ccc22f4da4fd0fe6286f128fb194bbb098 Mon Sep 17 00:00:00 2001 From: hdvos Date: Tue, 31 Jan 2023 11:13:24 +0100 Subject: [PATCH 4/5] Update js/src/collect/collect-v5.js Co-authored-by: Aida Marfuaty <48715883+FAMarfuaty@users.noreply.github.com> --- js/src/collect/collect-v5.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/js/src/collect/collect-v5.js b/js/src/collect/collect-v5.js index aa05e791..5796c999 100644 --- a/js/src/collect/collect-v5.js +++ b/js/src/collect/collect-v5.js @@ -20,9 +20,6 @@ module.exports = function() { var parentContainer = jQuery( ".metabox-location-normal, .metabox-location-side, .acf-block-component.acf-block-body" ); acfFields = acf.get_fields( false, parentContainer ); } else { - // Assume Gutenberg is used. - // Return only fields in metabox areas (either below or side) or - // ACF block fields in the content (not in the sidebar, to prevent duplicates) acfFields = acf.get_fields(); } From e115e6f278d063d7dcee90095f7ce908a7620e55 Mon Sep 17 00:00:00 2001 From: hdvos Date: Tue, 31 Jan 2023 11:17:02 +0100 Subject: [PATCH 5/5] fix incorrect indent (ESLint) --- js/src/collect/collect-v5.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/src/collect/collect-v5.js b/js/src/collect/collect-v5.js index 5796c999..1ae78185 100644 --- a/js/src/collect/collect-v5.js +++ b/js/src/collect/collect-v5.js @@ -11,7 +11,7 @@ module.exports = function() { var outerFields = []; var acfFields = []; - // Check if Gutenberg editor is used. + // Check if Gutenberg editor is used. if ( window.wpseoScriptData.isBlockEditor ) { /* * Return only fields in metabox areas (either below or side) or