Skip to content

Commit

Permalink
Fixes scrollbar issue if upsell nudge is loaded in sidebar (#38170)
Browse files Browse the repository at this point in the history
* Fixes scrollbar issue if upsell nudge is loaded in sidebar.

* changelog

* Update script import code
  • Loading branch information
candy02058912 authored Jul 5, 2024
1 parent 0ac906f commit 6675a6d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fixes scrollbar issue if upsell nudge is loaded in specific viewport.
17 changes: 17 additions & 0 deletions projects/packages/masterbar/src/admin-menu/class-admin-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Automattic\Jetpack\Masterbar;

use Automattic\Jetpack\Assets;
use Automattic\Jetpack\Assets\Logo;
use Automattic\Jetpack\Redirect;

Expand Down Expand Up @@ -514,6 +515,22 @@ public function wp_ajax_upsell_nudge_jitm() {
wp_die();
}

/**
* Fixes scrollbar issue if upsell nudge is loaded.
* https://github.com/Automattic/dotcom-forge/issues/7936
*/
public function wpcom_upsell_nudge_jitm_fix() {
$assets_base_path = '../../dist/admin-menu/';
Assets::register_script(
'wpcom-upsell-nudge-jitm-fix',
$assets_base_path . 'wpcom-upsell-nudge-jitm-fix.js',
__FILE__,
array(
'enqueue' => true,
)
);
}

/**
* Returns the first available upsell nudge.
* Needs to be implemented separately for each child menu class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected function __construct() {
add_action( 'wp_ajax_sidebar_state', array( $this, 'ajax_sidebar_state' ) );
add_action( 'wp_ajax_jitm_dismiss', array( $this, 'wp_ajax_jitm_dismiss' ) );
add_action( 'wp_ajax_upsell_nudge_jitm', array( $this, 'wp_ajax_upsell_nudge_jitm' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'wpcom_upsell_nudge_jitm_fix' ) );
add_action( 'admin_init', array( $this, 'sync_sidebar_collapsed_state' ) );
add_action( 'admin_menu', array( $this, 'remove_submenus' ), 140 ); // After hookpress hook at 130.
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const wpcomFixSidebarScrolling = () => {
const observer = new MutationObserver( mutationList => {
mutationList.forEach( mutation => {
mutation.addedNodes.forEach( node => {
// The domain upsell nudge is added.
if ( node.id === 'toplevel_page_site-notices' ) {
window.dispatchEvent( new Event( 'resize' ) );
}
} );
} );
} );
observer.observe( document.querySelector( '#adminmenu' ), {
childList: true,
} );
};

document.addEventListener( 'DOMContentLoaded', wpcomFixSidebarScrolling );

0 comments on commit 6675a6d

Please sign in to comment.