Skip to content

Commit

Permalink
Fix several issues when loading page.
Browse files Browse the repository at this point in the history
- Shaking - fixed.
- Jump to the bottom directly - fixed.
- Long loading time - fixed.
  • Loading branch information
renintw committed Sep 7, 2022
1 parent 6504f63 commit 1c6f594
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions source/wp-content/themes/wporg-gutenberg/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,24 @@ function () {
function gutenberg_editor_scripts_and_styles( $hook ) {

if ( wp_is_mobile() ) {
/**
* Scripts
*/
$temporary_content = include __DIR__ . '/gutenberg-content.php';
echo( do_blocks( $temporary_content['content'] ) );
$script = sprintf(
'wp.domReady( function () { document.querySelector(".wp-site-blocks").innerHTML = %s } );',
wp_json_encode( do_blocks( $temporary_content['content'] ) )
);
wp_add_inline_script( 'wp-edit-post', $script );

/**
* Styles
*/
$block_editor_css = get_block_editor_theme_styles()[0]['css'];
wp_add_inline_style(
'wp-edit-post',
$block_editor_css . 'body,p{font-size:inherit;} h1,h2,h3,h4,h5,h6{font-weight:inherit;} .wp-block-button__link{border-radius: var(--wp--custom--button--border--radius);}'
);
} else {
// Enqueue heartbeat separately as an "optional" dependency of the editor.
// Heartbeat is used for automatic nonce refreshing, but some hosts choose
Expand Down Expand Up @@ -324,10 +340,6 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
wp_enqueue_style( 'global-styles-css-custom-properties' );
wp_enqueue_style( 'wp-block-spacer' );

if ( wp_is_mobile() ) {
$block_editor_css = get_block_editor_theme_styles()[0]['css'];
wp_add_inline_style( 'wp-edit-post', $block_editor_css . '.wp-site-blocks{all:unset;} body{font-size:inherit;} h1,h2,h3,h4,h5,h6{font-weight:inherit;}' );
}
/**
* Fires after block assets have been enqueued for the editing interface.
*
Expand Down

0 comments on commit 1c6f594

Please sign in to comment.