Skip to content
Closed
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
26 changes: 21 additions & 5 deletions compat/block-editor/widget-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,16 +940,29 @@ let sowbSiteEditorCanvas = false;
* @returns {jQuery} jQuery reference to the widget form
*/
const sowbGetBlockForm = ( clientId ) => {
if ( sowbSiteEditorCanvas === false ) {
sowbSiteEditorCanvas = jQuery( '.edit-site-visual-editor__editor-canvas' );
// Re-resolve the editor canvas on every call rather than caching to false,
// because the iframe element is mounted asynchronously by the block editor.
// Site Editor uses `.edit-site-visual-editor__editor-canvas`; the post editor
// (default since WP 6.5) uses `iframe[name="editor-canvas"]`.
let $canvas = jQuery( '.edit-site-visual-editor__editor-canvas' );
if ( $canvas.length === 0 ) {
$canvas = jQuery( 'iframe[name="editor-canvas"]' );
}

if ( sowbSiteEditorCanvas.length === 0 ) {
// Cache the resolved canvas for use by sowbMaybeSetupSiteEditorAssets()
// and other consumers, but only when the canvas is actually present so
// we never lock in an empty result before the iframe has mounted.
if ( $canvas.length > 0 ) {
sowbSiteEditorCanvas = $canvas;
}

if ( $canvas.length === 0 ) {
// No iframe (e.g. widgets.php Block Widgets screen, classic editor).
return jQuery( '[data-block="' + clientId + '"]' ).find( '.siteorigin-widget-form-main' );
}

// Return the main WB form.
return sowbSiteEditorCanvas
// Return the main WB form from inside the editor iframe.
return $canvas
.contents()
.find( '[data-block="' + clientId + '"]' )
.find( '.siteorigin-widget-form-main' );
Expand All @@ -968,6 +981,9 @@ const sowbCanvasCloneElements = [
'#jquery-ui-sortable-js',
'#jquery-ui-resizable-js',
'#jquery-ui-draggable-js',
'#jquery-touch-punch-js',
'#iris-js',
'#wp-color-picker-js',
'#wplink-js-extra',
'#wplink-js',
'#buttons-css',
Expand Down