[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-activity/admin/js/ -> admin.js (source)

   1  /* global bp_activity_admin_vars, postboxes, wpAjax */
   2  (function( $ ) {
   3  
   4  /**
   5   * Activity reply object for the activity index screen.
   6   *
   7   * @since 1.6.0
   8   */
   9  var activityReply = {
  10  
  11      /**
  12       * Attach event handler functions to the relevant elements.
  13       *
  14       * @since 1.6.0
  15       */
  16      init : function() {
  17          $(document).on( 'click', '.row-actions a.reply',              activityReply.open );
  18          $(document).on( 'click', '#bp-activities-container a.cancel', activityReply.close );
  19          $(document).on( 'click', '#bp-activities-container a.save',   activityReply.send );
  20  
  21          // Close textarea on escape.
  22          $(document).on( 'keyup', '#bp-activities:visible', function( e ) {
  23              if ( 27 === e.which ) {
  24                  activityReply.close();
  25              }
  26          });
  27      },
  28  
  29      /**
  30       * Reveals the entire row when "reply" is pressed.
  31       *
  32       * @since 1.6.0
  33       */
  34      open : function() {
  35          // Hide the container row, and move it to the new location.
  36          var box = $( '#bp-activities-container' ).hide();
  37          $( this ).parents( 'tr' ).after( box );
  38  
  39          // Fade the whole row in, and set focus on the text area.
  40          box.fadeIn( '300' );
  41          $( '#bp-activities' ).focus();
  42  
  43          return false;
  44      },
  45  
  46      /**
  47       * Hide and reset the entire row when "cancel", or escape, are pressed.
  48       *
  49       * @since 1.6.0
  50       */
  51      close : function() {
  52          // Hide the container row.
  53          $('#bp-activities-container').fadeOut( '200', function () {
  54  
  55              // Empty and unfocus the text area.
  56              $( '#bp-activities' ).val( '' ).blur();
  57  
  58              // Remove any error message and disable the spinner.
  59              $( '#bp-replysubmit .error' ).html( '' ).hide();
  60              $( '#bp-replysubmit .waiting' ).hide();
  61          });
  62  
  63          return false;
  64      },
  65  
  66      /**
  67       * Submits "form" via AJAX back to WordPress.
  68       *
  69       * @since 1.6.0
  70       */
  71      send : function() {
  72          // Hide any existing error message, and show the loading spinner.
  73          $( '#bp-replysubmit .error' ).hide();
  74          $( '#bp-replysubmit .waiting' ).show();
  75  
  76          // Grab the nonce.
  77          var reply = {};
  78          reply['_ajax_nonce-bp-activity-admin-reply'] = $( '#bp-activities-container input[name="_ajax_nonce-bp-activity-admin-reply"]' ).val();
  79  
  80          // Get the rest of the data.
  81          reply.action    = 'bp-activity-admin-reply';
  82          reply.content   = $( '#bp-activities' ).val();
  83          reply.parent_id = $( '#bp-activities-container' ).prev().data( 'parent_id' );
  84          reply.root_id   = $( '#bp-activities-container' ).prev().data( 'root_id' );
  85  
  86          // Make the AJAX call.
  87          $.ajax({
  88              data    : reply,
  89              type    : 'POST',
  90              url     : ajaxurl,
  91  
  92              // Callbacks.
  93              error   : function( r ) { activityReply.error( r ); },
  94              success : function( r ) { activityReply.show( r ); }
  95          });
  96  
  97          return false;
  98      },
  99  
 100      /**
 101       * send() error message handler.
 102       *
 103       * @since 1.6.0
 104       */
 105      error : function( r ) {
 106          var er = r.statusText;
 107          $('#bp-replysubmit .waiting').hide();
 108  
 109          if ( r.responseText ) {
 110              er = r.responseText.replace( /<.[^<>]*?>/g, '' );
 111          }
 112  
 113          if ( er ) {
 114              $('#bp-replysubmit .error').html( er ).show();
 115          }
 116      },
 117  
 118      /**
 119       * send() success handler.
 120       *
 121       * @since 1.6.0
 122       */
 123      show : function ( xml ) {
 124          var bg, id, response;
 125  
 126          // Handle any errors in the response.
 127          if ( typeof( xml ) === 'string' ) {
 128              activityReply.error( { 'responseText': xml } );
 129              return false;
 130          }
 131  
 132          response = wpAjax.parseAjaxResponse( xml );
 133          if ( response.errors ) {
 134              activityReply.error( { 'responseText': wpAjax.broken } );
 135              return false;
 136          }
 137          response = response.responses[0];
 138  
 139          // Close and reset the reply row, and add the new Activity item into the list.
 140          $('#bp-activities-container').fadeOut( '200', function () {
 141  
 142              // Empty and unfocus the text area.
 143              $( '#bp-activities' ).val( '' ).blur();
 144  
 145              // Remove any error message and disable the spinner.
 146              $( '#bp-replysubmit .error' ).html( '' ).hide();
 147              $( '#bp-replysubmit .waiting' ).hide();
 148  
 149              // Insert new activity item.
 150              $( '#bp-activities-container' ).before( response.data );
 151  
 152              // Get background colour and animate the flash.
 153              id = $( '#activity-' + response.id );
 154              bg = id.closest( '.widefat' ).css( 'backgroundColor' );
 155              id.animate( { 'backgroundColor': '#CEB' }, 300 ).animate( { 'backgroundColor': bg }, 300 );
 156          });
 157      }
 158  };
 159  
 160  $(document).ready( function () {
 161      // Create the Activity reply object after domready event.
 162      activityReply.init();
 163  
 164      // On the edit screen, unload the close/open toggle js for the action & content metaboxes.
 165      $( '#bp_activity_action h3, #bp_activity_content h3' ).unbind( 'click' );
 166  
 167      // redo the post box toggles to reset the one made by comment.js in favor
 168      // of activity administration page id so that metaboxes are still collapsible
 169      // in single Activity Administration screen.
 170      if ( typeof postboxes !== 'undefined' ) {
 171          postboxes.add_postbox_toggles( bp_activity_admin_vars.page );
 172      }
 173  });
 174  
 175  })(jQuery);


Generated: Tue Apr 23 01:01:07 2024 Cross-referenced by PHPXref 0.7.1