PluginProbe
Front End PM / trunk
Front End PM vtrunk
trunk 1.1 1.2 1.3 10.1.1 10.1.2 10.1.3 10.1.4 10.1.5 10.1.6 10.1.7 10.2.1 11.1.1 11.2.1 11.2.2 11.2.3 11.3.1 11.3.3 11.3.4 11.3.5 11.3.6 11.3.7 11.3.8 11.3.9 11.4.1 All 58 releases
front-end-pm / assets / js / script.js

script.js in Front End PM trunk, at assets/js/script.js

52 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery( document ).ready( function( $ ) {
2 var fep_delay = ( function() {
3 var timer = 0;
4 return function( callback, ms ) {
5 clearTimeout ( timer );
6 timer = setTimeout( callback, ms );
7 };
8 })();
9
10 $( document ).on( 'keyup', '#fep-message-top', function() {
11 fep_delay( function() {
12 $( '#fep-result' ).hide();
13 var display_name = $( '#fep-message-top' ).val();
14 var data = {
15 q: display_name
16 };
17 if ( ! display_name ) {
18 return;
19 }
20 $( '#fep-message-top' ).addClass( 'fep-loading-gif' );
21 $.ajax({
22 url: fep_script.root +'/users/autosuggestion/',
23 method: 'get',
24 data: data,
25 dataType: 'json',
26 beforeSend: function ( xhr ) {
27 xhr.setRequestHeader( 'X-WP-Nonce', fep_script.nonce );
28 }
29 }).done( function( response ) {
30 $( '#fep-result' ).html('<ul></ul>');
31 if ( $.isEmptyObject( response ) ) {
32 $( '#fep-result ul' ).append('<li>' + fep_script.no_match + '</li>');
33 } else {
34 $.each( response.slice(0,5), function(i, v) {
35 $( '#fep-result ul' ).append('<li><a href="#" data-user_nicename="' + v.nicename + '" data-user_name="' + v.name + '">' + v.name + '</a></li>');
36 });
37 }
38 $( '#fep-result' ).show();
39 }).always( function() {
40 $( '#fep-message-top' ).removeClass( 'fep-loading-gif' );
41 });
42 }, 300 );
43 });
44
45 $( document ).on( 'click', '#fep-result a', function(e) {
46 e.preventDefault();
47 $( '#fep-message-to' ).val( $(this).data('user_nicename') );
48 $( '#fep-message-top' ).val( $(this).data('user_name') );
49 $( '#fep-result' ).hide();
50 });
51 });
52