[ 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( $, bp ) {
   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  
  23          $( '#TB_window' ).attr( {
  24                              'role': 'dialog',
  25                              'aria-label': bpHelloStrings.modalLabel
  26                          } )
  27                          .addClass( 'plugin-details-modal' )
  28                          .removeClass( 'thickbox-loading' );
  29  
  30          $( '#TB_ajaxContent' ).prop( 'style', 'height: 100%; width: auto; padding: 0; border: none;' );
  31      };
  32  
  33      /**
  34       * Prints an error message.
  35       *
  36       * @param {string} message The error message to display.
  37       */
  38      var printErrorMessage = function( message ) {
  39          if ( ! message ) {
  40              message = bpHelloStrings.pageNotFound;
  41          }
  42  
  43          $( '#dynamic-content' ).html(
  44              $('<div></div>' ).prop( 'id', 'message' )
  45                      .addClass( 'notice notice-error error' )
  46                      .html(
  47                          $( '<p></p>' ).html( message )
  48                      )
  49          );
  50      };
  51  
  52      // Listen to Tab Menu clicks to display the different screens.
  53      $( '#plugin-information-tabs').on( 'click', 'a', function( event ) {
  54          event.preventDefault();
  55  
  56          var anchor = $( event.currentTarget ), target = $( '#dynamic-content' );
  57  
  58          if ( anchor.hasClass( 'dynamic' ) ) {
  59              $( '#top-features' ).hide();
  60              target.html( '' );
  61              target.addClass( 'show' );
  62  
  63              $( '#TB_window' ).addClass( 'thickbox-loading' );
  64  
  65              bp.apiRequest( {
  66                  url: anchor.data( 'endpoint' ),
  67                  type: 'GET',
  68                  beforeSend: function( xhr, settings ) {
  69                      settings.url = settings.url.replace( '&_wpnonce=none', '' );
  70                  },
  71                  data: {
  72                      context: 'view',
  73                      slug: anchor.data( 'slug' ),
  74                      _wpnonce: 'none'
  75                  }
  76              } ).done( function( data ) {
  77                  var page = _.first( data );
  78  
  79                  if ( page && page.content ) {
  80                      target.html( page.content.rendered );
  81                  } else {
  82                      printErrorMessage();
  83                  }
  84  
  85              } ).fail( function( error ) {
  86                  if ( ! error || ! error.message ) {
  87                      return false;
  88                  }
  89  
  90                  printErrorMessage( error.message );
  91  
  92              } ).always( function() {
  93                  $( '#TB_window' ).removeClass( 'thickbox-loading' );
  94              } );
  95  
  96          } else {
  97              $( '#top-features' ).show();
  98              target.html( '' );
  99              target.removeClass( 'show' );
 100          }
 101      } );
 102  
 103      // Init modal after the screen's loaded.
 104      $( document ).ready( function() {
 105          bpHelloOpenModal();
 106      } );
 107  
 108  }( jQuery, window.bp || {} ) );


Generated: Tue Sep 17 01:01:39 2019 Cross-referenced by PHPXref 0.7.1