暫無描述

jetpack-connection-banner.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* global jQuery, jp_banner */
  2. ( function ( $ ) {
  3. var nav = $( '.jp-wpcom-connect__vertical-nav-container' ),
  4. contentContainer = $( '.jp-wpcom-connect__content-container' ),
  5. nextFeatureButtons = $( '.jp-banner__button-container .next-feature' ),
  6. fullScreenContainer = $( '.jp-connect-full__container' ),
  7. fullScreenDismiss = $( '.jp-connect-full__dismiss, .jp-connect-full__dismiss-paragraph' ),
  8. wpWelcomeNotice = $( '#welcome-panel' ),
  9. connectionBanner = $( '#message' ),
  10. connectionBannerDismiss = $( '.connection-banner-dismiss' );
  11. // Move the banner below the WP Welcome notice on the dashboard
  12. $( window ).on( 'load', function () {
  13. wpWelcomeNotice.insertBefore( connectionBanner );
  14. } );
  15. // Dismiss the connection banner via AJAX
  16. connectionBannerDismiss.on( 'click', function () {
  17. $( connectionBanner ).hide();
  18. var data = {
  19. action: 'jetpack_connection_banner',
  20. nonce: jp_banner.connectionBannerNonce,
  21. dismissBanner: true,
  22. };
  23. $.post( jp_banner.ajax_url, data, function ( response ) {
  24. if ( true !== response.success ) {
  25. $( connectionBanner ).show();
  26. }
  27. } );
  28. } );
  29. nav.on(
  30. 'click',
  31. '.vertical-menu__feature-item:not( .vertical-menu__feature-item-is-selected )',
  32. function () {
  33. transitionSlideToIndex( $( this ).index() );
  34. }
  35. );
  36. nextFeatureButtons.on( 'click', function ( e ) {
  37. e.preventDefault();
  38. var slideIndex = $( this ).closest( '.jp-wpcom-connect__slide' ).index();
  39. transitionSlideToIndex( slideIndex + 1 );
  40. } );
  41. function transitionSlideToIndex( index ) {
  42. // Remove classes from previously selected menu item and content
  43. nav
  44. .find( '.vertical-menu__feature-item-is-selected' )
  45. .removeClass( 'vertical-menu__feature-item-is-selected' );
  46. contentContainer.find( '.jp__slide-is-active' ).removeClass( 'jp__slide-is-active' );
  47. // Add classes to selected menu item and content
  48. nav.children().eq( index ).addClass( 'vertical-menu__feature-item-is-selected' );
  49. contentContainer.children().eq( index ).addClass( 'jp__slide-is-active' );
  50. }
  51. /**
  52. * Full-screen connection prompt
  53. */
  54. fullScreenDismiss.on( 'click', function () {
  55. $( fullScreenContainer ).hide();
  56. } );
  57. $( document ).keyup( function ( e ) {
  58. if ( 27 === e.keyCode ) {
  59. $( fullScreenDismiss ).click();
  60. }
  61. } );
  62. } )( jQuery );