[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-core/admin/js/ -> hello.js (source)

   1  /* global bpHelloStrings */
   2  /**
   3   * Loads for BuddyPress Hello in wp-admin for query string `hello=buddypress`.
   4   *
   5   * @since 3.0.0
   6   */
   7  (function( $, wp ) {
   8      // Bail if not set
   9      if ( typeof bpHelloStrings === 'undefined' ) {
  10          return;
  11      }
  12  
  13      /**
  14       * Open the BuddyPress Hello modal.
  15       */
  16      var bpHelloOpenModal = function() {
  17          if ( 'function' !== typeof window.tb_show ) {
  18              return false;
  19          }
  20  
  21          window.tb_show( 'BuddyPress', '#TB_inline?inlineId=bp-hello-container' );
  22          window.bpAdjustThickbox( bpHelloStrings.modalLabel );
  23      };
  24  
  25      /**
  26       * Prints an error message.
  27       *
  28       * @param {string} message The error message to display.
  29       */
  30      var printErrorMessage = function( message ) {
  31          if ( ! message ) {
  32              message = bpHelloStrings.pageNotFound;
  33          }
  34  
  35          $( '#dynamic-content' ).html(
  36              $('<div></div>' ).prop( 'id', 'message' )
  37                      .addClass( 'notice notice-error error' )
  38                      .html(
  39                          $( '<p></p>' ).html( message )
  40                      )
  41          );
  42      };
  43  
  44      // Listen to Tab Menu clicks to display the different screens.
  45      $( '#plugin-information-tabs').on( 'click', 'a', function( event ) {
  46          event.preventDefault();
  47  
  48          var anchor = $( event.currentTarget ), target = $( '#dynamic-content' );
  49  
  50          if ( anchor.hasClass( 'dynamic' ) ) {
  51              $( '#top-features' ).hide();
  52              target.html( '' );
  53              target.addClass( 'show' );
  54  
  55              $( '#TB_window' ).addClass( 'thickbox-loading' );
  56  
  57              wp.apiRequest( {
  58                  url: anchor.data( 'endpoint' ),
  59                  type: 'GET',
  60                  beforeSend: function( xhr, settings ) {
  61                      settings.url = settings.url.replace( '&_wpnonce=none', '' );
  62                  },
  63                  data: {
  64                      context: 'view',
  65                      slug: anchor.data( 'slug' ),
  66                      _wpnonce: 'none'
  67                  }
  68              } ).done( function( data ) {
  69                  var page = _.first( data );
  70  
  71                  if ( page && page.content ) {
  72                      target.html( page.content.rendered );
  73                  } else {
  74                      printErrorMessage();
  75                  }
  76  
  77              } ).fail( function( error ) {
  78                  if ( ! error || ! error.message ) {
  79                      return false;
  80                  }
  81  
  82                  printErrorMessage( error.message );
  83  
  84              } ).always( function() {
  85                  $( '#TB_window' ).removeClass( 'thickbox-loading' );
  86              } );
  87  
  88          } else {
  89              $( '#top-features' ).show();
  90              target.html( '' );
  91              target.removeClass( 'show' );
  92          }
  93      } );
  94  
  95      // Init modal after the screen's loaded.
  96      $( function() {
  97          bpHelloOpenModal();
  98      } );
  99  
 100  }( jQuery, window.wp || {} ) );


Generated: Thu Apr 18 01:01:15 2024 Cross-referenced by PHPXref 0.7.1