[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  /* global BP_Group_Admin, group_id, isRtl */
   2  
   3  (function($) {
   4  	function add_member_to_list( e, ui ) {
   5          $('#bp-groups-new-members-list').append('<li data-login="' + ui.item.value + '"><a href="#" class="bp-groups-remove-new-member">x</a> ' + ui.item.label + '</li>');
   6      }
   7  
   8      var id = 'undefined' !== typeof group_id ? '&group_id=' + group_id : '';
   9      $(document).ready( function() {
  10          window.warn_on_leave = false;
  11  
  12          /* Initialize autocomplete */
  13          $( '.bp-suggest-user' ).autocomplete({
  14              source:    ajaxurl + '?action=bp_group_admin_member_autocomplete' + id,
  15              delay:     500,
  16              minLength: 2,
  17              position:  ( 'undefined' !== typeof isRtl && isRtl ) ? { my: 'right top', at: 'right bottom', offset: '0, -1' } : { offset: '0, -1' },
  18              open:      function() { $(this).addClass('open'); },
  19              close:     function() { $(this).removeClass('open'); $(this).val(''); },
  20              select:    function( event, ui ) { add_member_to_list( event, ui ); }
  21          });
  22  
  23          /* Replace noscript placeholder */
  24          $( '#bp-groups-new-members.bp-suggest-user' ).prop( 'placeholder', BP_Group_Admin.add_member_placeholder );
  25  
  26          /* Remove a member on 'x' click */
  27          $( '#bp_group_add_members' ).on( 'click', '.bp-groups-remove-new-member', function( e ) {
  28              e.preventDefault();
  29              $( e.target.parentNode ).remove();
  30          } );
  31  
  32          /* Warn before leaving unsaved changes */
  33          $(document).on( 'change', 'input#bp-groups-name, input#bp-groups-description, select.bp-groups-role, #bp-groups-settings-section-status input[type="radio"]', function() {
  34              window.warn_on_leave = true;
  35          });
  36  
  37          $( 'input#save' ).on( 'click', function() {
  38              /* Check for users to add */
  39              var users_to_add = [];
  40  
  41              $( '#bp-groups-new-members-list li' ).each( function() {
  42                  users_to_add.push( $(this).data('login' ) );
  43              } );
  44  
  45              /* There are users to add, include a comma separated list of users login in the main field */
  46              if ( users_to_add.length ) {
  47                  $( '#bp-groups-new-members' ).val( '' ).val( users_to_add.join( ', ' ) );
  48              }
  49  
  50              window.warn_on_leave = false;
  51          });
  52  
  53          window.onbeforeunload = function() {
  54              if ( window.warn_on_leave ) {
  55                  return BP_Group_Admin.warn_on_leave;
  56              }
  57          };
  58      });
  59  })(jQuery);


Generated: Fri Nov 22 01:00:56 2024 Cross-referenced by PHPXref 0.7.1