collecting medal for hitxy members
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 satır
4.9KB

  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.search_user + '>';
  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("Network Error, Please try again later");
  104. });
  105. });
  106. //step2
  107. function step2_verify_user(response)
  108. {
  109. var el = $("#userpass");
  110. el.slideToggle();
  111. }
  112. //verify
  113. $(document).on("click", "#step2", function(){
  114. var el = $('#details');
  115. el.slideDown();
  116. });
  117. //apply card
  118. $(document).on("click", "#cardbtn", function(){
  119. var loading = $('#cardloading');
  120. var check = $('#card');
  121. $(this).hide();
  122. loading.show();
  123. setTimeout(function(){
  124. loading.hide();
  125. check.show();
  126. }, 2000);
  127. });
  128. //apply 90 meda;
  129. $(document).on("click", "#btn90", function(){
  130. var loading = $('#loading90');
  131. var check = $('#medal90');
  132. $(this).hide();
  133. loading.show();
  134. setTimeout(function(){
  135. loading.hide();
  136. check.show();
  137. }, 2000);
  138. });
  139. //confirm;
  140. $(document).on("click", "#confirm", function(){
  141. var search = $("#search");
  142. var verify = $("#userpass");
  143. var details = $("#details");
  144. var btn = $('#confirm');
  145. var img = $('#done');
  146. $(this).hide();
  147. verify.hide();
  148. details.hide();
  149. search.hide();
  150. img.show();
  151. setTimeout(function(){
  152. btn.show();
  153. img.hide();
  154. }, 4000);
  155. });
  156. })(jQuery);