PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.3.0
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.3.0
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 All 162 releases
cartflows / modules / gutenberg / src / controls / scrollBlockToView.js

scrollBlockToView.js in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.3.0, at modules/gutenberg/src/controls/scrollBlockToView.js

48 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { select } from '@wordpress/data';
2
3 const scrollBlockToView = () => {
4
5 // Scroll the view to the selected block after device type change in editor.
6 const { getSelectedBlock } = select( 'core/block-editor' );
7 const selectedBlockID = getSelectedBlock()?.clientId ? `block-${getSelectedBlock()?.clientId}` : false;
8
9 if ( ! selectedBlockID ) {
10 return;
11 }
12
13 setTimeout( ()=> {
14 const currentDocument = getCurrentDocument();
15 const selectedBlockElementToScroll = currentDocument.getElementById ( selectedBlockID );
16
17 if ( selectedBlockElementToScroll ) {
18 selectedBlockElementToScroll.scrollIntoView( {behavior: 'smooth'} );
19 }
20 }, 500 )
21 }
22
23 const getCurrentDocument = () => {
24
25 const tabletPreview = document.getElementsByClassName( 'is-tablet-preview' );
26 const mobilePreview = document.getElementsByClassName( 'is-mobile-preview' );
27 if ( 0 !== tabletPreview.length || 0 !== mobilePreview.length ) {
28
29 const preview = tabletPreview[0] || mobilePreview[0];
30
31 let iframe = false;
32
33 if ( preview ) {
34 iframe = preview.getElementsByTagName( 'iframe' )[0];
35 }
36
37 const iframeDocument = iframe?.contentWindow.document || iframe?.contentDocument;
38
39 if ( iframeDocument ) {
40 return iframeDocument;
41 }
42 }
43
44 return document;
45 };
46
47 export default scrollBlockToView;
48