|
1 /** |
|
2 * Suggests users in a multisite environment. |
|
3 * |
|
4 * For input fields where the admin can select a user based on email or |
|
5 * username, this script shows an autocompletion menu for these inputs. Should |
|
6 * only be used in a multisite environment. Only users in the currently active |
|
7 * site are shown. |
|
8 * |
|
9 * @since 3.4.0 |
|
10 * @output wp-admin/js/user-suggest.js |
|
11 */ |
|
12 |
1 /* global ajaxurl, current_site_id, isRtl */ |
13 /* global ajaxurl, current_site_id, isRtl */ |
2 |
14 |
3 (function( $ ) { |
15 (function( $ ) { |
4 var id = ( typeof current_site_id !== 'undefined' ) ? '&site_id=' + current_site_id : ''; |
16 var id = ( typeof current_site_id !== 'undefined' ) ? '&site_id=' + current_site_id : ''; |
5 $(document).ready( function() { |
17 $(document).ready( function() { |
6 var position = { offset: '0, -1' }; |
18 var position = { offset: '0, -1' }; |
7 if ( typeof isRtl !== 'undefined' && isRtl ) { |
19 if ( typeof isRtl !== 'undefined' && isRtl ) { |
8 position.my = 'right top'; |
20 position.my = 'right top'; |
9 position.at = 'right bottom'; |
21 position.at = 'right bottom'; |
10 } |
22 } |
|
23 |
|
24 /** |
|
25 * Adds an autocomplete function to input fields marked with the class |
|
26 * 'wp-suggest-user'. |
|
27 * |
|
28 * A minimum of two characters is required to trigger the suggestions. The |
|
29 * autocompletion menu is shown at the left bottom of the input field. On |
|
30 * RTL installations, it is shown at the right top. Adds the class 'open' to |
|
31 * the input field when the autocompletion menu is shown. |
|
32 * |
|
33 * Does a backend call to retrieve the users. |
|
34 * |
|
35 * Optional data-attributes: |
|
36 * - data-autocomplete-type (add, search) |
|
37 * The action that is going to be performed: search for existing users |
|
38 * or add a new one. Default: add |
|
39 * - data-autocomplete-field (user_login, user_email) |
|
40 * The field that is returned as the value for the suggestion. |
|
41 * Default: user_login |
|
42 * |
|
43 * @see wp-admin/includes/admin-actions.php:wp_ajax_autocomplete_user() |
|
44 */ |
11 $( '.wp-suggest-user' ).each( function(){ |
45 $( '.wp-suggest-user' ).each( function(){ |
12 var $this = $( this ), |
46 var $this = $( this ), |
13 autocompleteType = ( typeof $this.data( 'autocompleteType' ) !== 'undefined' ) ? $this.data( 'autocompleteType' ) : 'add', |
47 autocompleteType = ( typeof $this.data( 'autocompleteType' ) !== 'undefined' ) ? $this.data( 'autocompleteType' ) : 'add', |
14 autocompleteField = ( typeof $this.data( 'autocompleteField' ) !== 'undefined' ) ? $this.data( 'autocompleteField' ) : 'user_login'; |
48 autocompleteField = ( typeof $this.data( 'autocompleteField' ) !== 'undefined' ) ? $this.data( 'autocompleteField' ) : 'user_login'; |
15 |
49 |