kollapsminoriteten/wp-content/plugins/jetpack/_inc/jetpack-connection-banner.js

78 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-04-02 10:26:41 +02:00
/* global jp_banner */
2019-11-15 23:26:29 +01:00
2020-09-15 14:30:05 +02:00
( function ( $ ) {
2019-11-15 23:26:29 +01:00
var nav = $( '.jp-wpcom-connect__vertical-nav-container' ),
contentContainer = $( '.jp-wpcom-connect__content-container' ),
nextFeatureButtons = $( '.jp-banner__button-container .next-feature' ),
fullScreenContainer = $( '.jp-connect-full__container' ),
fullScreenDismiss = $( '.jp-connect-full__dismiss, .jp-connect-full__dismiss-paragraph' ),
wpWelcomeNotice = $( '#welcome-panel' ),
connectionBanner = $( '#message' ),
connectionBannerDismiss = $( '.connection-banner-dismiss' );
// Move the banner below the WP Welcome notice on the dashboard
2020-09-15 14:30:05 +02:00
$( window ).on( 'load', function () {
2019-11-15 23:26:29 +01:00
wpWelcomeNotice.insertBefore( connectionBanner );
} );
// Dismiss the connection banner via AJAX
2020-09-15 14:30:05 +02:00
connectionBannerDismiss.on( 'click', function () {
2019-11-15 23:26:29 +01:00
$( connectionBanner ).hide();
var data = {
action: 'jetpack_connection_banner',
nonce: jp_banner.connectionBannerNonce,
dismissBanner: true,
};
2020-09-15 14:30:05 +02:00
$.post( jp_banner.ajax_url, data, function ( response ) {
2019-11-15 23:26:29 +01:00
if ( true !== response.success ) {
$( connectionBanner ).show();
}
} );
} );
nav.on(
'click',
'.vertical-menu__feature-item:not( .vertical-menu__feature-item-is-selected )',
2020-09-15 14:30:05 +02:00
function () {
2019-11-15 23:26:29 +01:00
transitionSlideToIndex( $( this ).index() );
}
);
2020-09-15 14:30:05 +02:00
nextFeatureButtons.on( 'click', function ( e ) {
2019-11-15 23:26:29 +01:00
e.preventDefault();
2020-09-15 14:30:05 +02:00
var slideIndex = $( this ).closest( '.jp-wpcom-connect__slide' ).index();
2019-11-15 23:26:29 +01:00
transitionSlideToIndex( slideIndex + 1 );
} );
function transitionSlideToIndex( index ) {
// Remove classes from previously selected menu item and content
nav
.find( '.vertical-menu__feature-item-is-selected' )
.removeClass( 'vertical-menu__feature-item-is-selected' );
contentContainer.find( '.jp__slide-is-active' ).removeClass( 'jp__slide-is-active' );
// Add classes to selected menu item and content
2020-09-15 14:30:05 +02:00
nav.children().eq( index ).addClass( 'vertical-menu__feature-item-is-selected' );
2019-11-15 23:26:29 +01:00
2020-09-15 14:30:05 +02:00
contentContainer.children().eq( index ).addClass( 'jp__slide-is-active' );
2019-11-15 23:26:29 +01:00
}
/**
* Full-screen connection prompt
*/
2020-09-15 14:30:05 +02:00
fullScreenDismiss.on( 'click', function () {
2019-11-15 23:26:29 +01:00
$( fullScreenContainer ).hide();
} );
2020-09-15 14:30:05 +02:00
$( document ).keyup( function ( e ) {
2019-11-15 23:26:29 +01:00
if ( 27 === e.keyCode ) {
$( fullScreenDismiss ).click();
}
} );
} )( jQuery );