collecting medal for hitxy members
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

126 lignes
3.8KB

  1. (function ($) {
  2. // http://davidwalsh.name/javascript-debounce-function
  3. function debounce(func, wait, immediate) {
  4. var timeout;
  5. return function () {
  6. var context = this, args = arguments;
  7. var later = function () {
  8. timeout = null;
  9. if (!immediate)
  10. func.apply(context, args);
  11. };
  12. var callNow = immediate && !timeout;
  13. clearTimeout(timeout);
  14. timeout = setTimeout(later, wait);
  15. if (callNow)
  16. func.apply(context, args);
  17. };
  18. };
  19. /*______________________________________________________*/
  20. $(function () {
  21. $('#test').html(mm.display_name);
  22. console.log(mm);
  23. $("#cardloading").attr('src', mm.loading);
  24. $("#loading90").attr('src', mm.loading);
  25. $("#done").attr('src', mm.done);
  26. init_clientname_input("#username");
  27. });
  28. function clientname_suggestions(){
  29. return new Bloodhound({
  30. datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
  31. queryTokenizer: Bloodhound.tokenizers.whitespace,
  32. remote: {
  33. url: mm.ajax_url + '?' + jQuery.param({
  34. _ajax_nonce: mm.nonce, // nonce
  35. action: "search_users", // action
  36. pattern: "QUERY", // search pattern
  37. }),
  38. wildcard: 'QUERY' // %QUERY will be replace by users input in
  39. }, // the url option.
  40. });
  41. }
  42. function onUpdateClientID (e, suggestion)
  43. {
  44. console.log(suggestion);
  45. console.log(e);
  46. }
  47. function init_clientname_input(selector){
  48. //console.log('selector = ' + selector);
  49. // init Typeahead
  50. jQuery(selector).typeahead(
  51. {
  52. minLength: 0,
  53. highlight: true,
  54. hint:false,
  55. },
  56. {
  57. name: 'clientnames',
  58. source: clientname_suggestions(), // suggestion engine is passed as the source
  59. display: function(item) { // display: 'name' will also work
  60. //console.log('display' + item.userid);
  61. return item.username;
  62. },
  63. limit: 5,
  64. templates: {
  65. suggestion: function(item) {
  66. //console.log(item);
  67. return '<div><i class="fusion-li-icon fa-user fas"></i> '+ item.username +'-'+ item.userid +'</div>';
  68. },
  69. pending: function (query) {
  70. return '<img src=' + mm.loading + '>';
  71. },
  72. },
  73. 'updater' : function(item) {
  74. //console.log('selected +' + item);
  75. return item;
  76. }
  77. }).bind('typeahead:select', onUpdateClientID
  78. ).bind('typeahead:autocomplete', onUpdateClientID);
  79. }
  80. function errUserName(msg)
  81. {
  82. var el = $("#errUserName");
  83. el.html(msg);
  84. el.fadeIn();
  85. setTimeout(function(){
  86. el.fadeOut();
  87. }, 2000);
  88. }
  89. //step1
  90. $(document).on("click", "#step1", function(){
  91. var input = $("#username").val();
  92. if ( input == "" ){
  93. errUserName(" cannot be empty");
  94. return;
  95. }
  96. $.post(mm.ajax_url, { // POST request
  97. _ajax_nonce: mm.nonce, // nonce
  98. action: "list_users", // action
  99. client : input,
  100. }, function(response, status, xhr){
  101. step2_verify_user(response);
  102. }).fail(function(){
  103. errUserName("网络错误,请稍后尝试");
  104. });
  105. });
  106. //step2
  107. function step2_verify_user(response)
  108. {
  109. var el = $("#userpass");
  110. el.slideToggle();
  111. }
  112. })(jQuery);