collecting medal for hitxy members
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

224 lines
6.2KB

  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. $(':radio:not(:checked)').attr('disabled', true);
  27. init_clientname_input("#username");
  28. });
  29. function clientname_suggestions(){
  30. return new Bloodhound({
  31. datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
  32. queryTokenizer: Bloodhound.tokenizers.whitespace,
  33. remote: {
  34. url: mm.ajax_url + '?' + jQuery.param({
  35. _ajax_nonce: mm.nonce, // nonce
  36. action: "search_users", // action
  37. pattern: "QUERY", // search pattern
  38. }),
  39. wildcard: 'QUERY' // %QUERY will be replace by users input in
  40. }, // the url option.
  41. });
  42. }
  43. function onUpdateClientID (e, suggestion)
  44. {
  45. mm.current_user = suggestion.userid;
  46. $.post(mm.ajax_url, { // POST request
  47. _ajax_nonce: mm.nonce, // nonce
  48. action: "list_users", // action
  49. client : suggestion.userid,
  50. name : ''
  51. }, function(response, status, xhr){
  52. step2_verify_user(response);
  53. }).fail(function(){
  54. errUserName("Network Error, Please try again later");
  55. });
  56. }
  57. function init_clientname_input(selector){
  58. //console.log('selector = ' + selector);
  59. // init Typeahead
  60. jQuery(selector).typeahead(
  61. {
  62. minLength: 0,
  63. highlight: true,
  64. hint:false,
  65. },
  66. {
  67. name: 'clientnames',
  68. source: clientname_suggestions(), // suggestion engine is passed as the source
  69. display: function(item) { // display: 'name' will also work
  70. //console.log('display' + item.userid);
  71. return item.username;
  72. },
  73. limit: 5,
  74. templates: {
  75. suggestion: function(item) {
  76. //console.log(item);
  77. return '<div><i class="fusion-li-icon fa-user fas"></i> '+ item.username +'-'+ item.userid +'</div>';
  78. },
  79. pending: function (query) {
  80. return '<img src=' + mm.search_user + '>';
  81. },
  82. },
  83. 'updater' : function(item) {
  84. //console.log('selected +' + item);
  85. return item;
  86. }
  87. }).bind('typeahead:select', onUpdateClientID
  88. ).bind('typeahead:autocomplete', onUpdateClientID);
  89. }
  90. function errUserName(msg)
  91. {
  92. var el = $("#errUserName");
  93. el.html(msg);
  94. el.fadeIn();
  95. setTimeout(function(){
  96. el.fadeOut();
  97. }, 2000);
  98. }
  99. //step1
  100. $(document).on("click", "#step1", function(){
  101. var input = $("#username").val();
  102. if ( input == "" ){
  103. errUserName(" cannot be empty");
  104. return;
  105. }
  106. $.post(mm.ajax_url, { // POST request
  107. _ajax_nonce: mm.nonce, // nonce
  108. action: "list_users", // action
  109. client : mm.current_user,
  110. name : input,
  111. }, function(response, status, xhr){
  112. step2_verify_user(response);
  113. }).fail(function(){
  114. errUserName("Network Error, Please try again later");
  115. });
  116. });
  117. //step2
  118. function step2_verify_user(response)
  119. {
  120. console.log(response);
  121. var el = $("#userpass");
  122. el.slideUp();
  123. el.slideDown();
  124. $("#vmobile").text(response.phone);
  125. $("#vemail").text(response.email);
  126. }
  127. //verify
  128. $(document).on("click", "#step2", function(){
  129. var input = $("#verifycode").val();
  130. var method = $("#verify_method").val();
  131. $.post(mm.ajax_url, { // POST request
  132. _ajax_nonce: mm.nonce, // nonce
  133. action: "verify_user", // action
  134. client : mm.current_user,
  135. method: method,
  136. verifycode : input,
  137. }, function(response, status, xhr){
  138. step3_show_details(response);
  139. }).fail(function(){
  140. errUserName("Network Error, Please try again later");
  141. });
  142. });
  143. function step3_show_details(response)
  144. {
  145. var el = $('#details');
  146. el.slideDown();
  147. if ( response.pass ){
  148. el.slideDown();
  149. $("#errVerify").text("");
  150. }else {
  151. el.hide();
  152. $("#errVerify").text("Incorrect, please try again");
  153. }
  154. }
  155. //apply card
  156. $(document).on("click", "#cardbtn", function(){
  157. var loading = $('#cardloading');
  158. var check = $('#card');
  159. $(this).hide();
  160. loading.show();
  161. setTimeout(function(){
  162. loading.hide();
  163. check.show();
  164. }, 2000);
  165. });
  166. //apply 90 meda;
  167. $(document).on("click", "#btn90", function(){
  168. var loading = $('#loading90');
  169. var check = $('#medal90');
  170. $(this).hide();
  171. loading.show();
  172. setTimeout(function(){
  173. loading.hide();
  174. check.show();
  175. }, 2000);
  176. });
  177. //confirm;
  178. $(document).on("click", "#confirm", function(){
  179. var search = $("#search");
  180. var verify = $("#userpass");
  181. var details = $("#details");
  182. var btn = $('#confirm');
  183. var img = $('#done');
  184. $(this).hide();
  185. verify.hide();
  186. details.hide();
  187. search.hide();
  188. img.show();
  189. setTimeout(function(){
  190. btn.show();
  191. img.hide();
  192. }, 4000);
  193. });
  194. })(jQuery);