name_selector.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. var user_select_param;
  2. function name_selector_init(container, parameter) {
  3. user_select_param = parameter;
  4. $.get(
  5. "../ucenter/get.php",
  6. {
  7. id: $("#" + parameter.input_id).val(),
  8. },
  9. function (data, status) {
  10. let result = JSON.parse(data);
  11. let html =
  12. '<div id="user_select_nickname" onclick="user_select_click()">';
  13. if (result.length > 0) {
  14. html += result[0].nickname;
  15. } else {
  16. html += gLocal.gui.not_found;
  17. }
  18. html += "</div>";
  19. html +=
  20. "<div id='user_selector_popwin' style='position: absolute; background-color: dimgray; padding: 8px;display: none;'>";
  21. html +=
  22. "<input id='user_selector_input' type='input' onkeyup=\"user_select_search_keyup(event,this)\" />";
  23. html += "<div id='user_selector_list'></div>";
  24. html += "<span onclick='user_select_close()'>"+gLocal.gui.close+"</span>";
  25. html += "</div>";
  26. $("#" + container).html(html);
  27. }
  28. );
  29. }
  30. function user_select_click() {
  31. $("#user_selector_popwin").show();
  32. }
  33. function user_select_close() {
  34. $("#user_selector_popwin").hide();
  35. }
  36. function user_select_search_keyup(e, obj) {
  37. var keynum;
  38. var keychar;
  39. var numcheck;
  40. if (window.event) {
  41. // IE
  42. keynum = e.keyCode;
  43. } else if (e.which) {
  44. // Netscape/Firefox/Opera
  45. keynum = e.which;
  46. }
  47. var keychar = String.fromCharCode(keynum);
  48. if (keynum == 13) {
  49. } else {
  50. user_select_search(obj.value);
  51. }
  52. }
  53. function user_select_search(keyword) {
  54. $.get(
  55. "../ucenter/get.php",
  56. {
  57. username: keyword,
  58. },
  59. function (data, status) {
  60. let result = JSON.parse(data);
  61. let html = "<div id='user_list'>";
  62. if (result.length > 0) {
  63. for (x in result) {
  64. html +=
  65. "<div><a onclick=\"user_select_apply('" +
  66. result[x].id +
  67. "','" +
  68. result[x].nickname +
  69. "')\">" +
  70. result[x].nickname +
  71. "[" +
  72. result[x].email +
  73. "]</a></div>";
  74. }
  75. }
  76. html += "</div>";
  77. $("#user_selector_list").html(html);
  78. }
  79. );
  80. }
  81. function user_select_apply(userid, nickname) {
  82. $("#" + user_select_param.input_id).val(userid);
  83. $("#user_select_nickname").html(nickname);
  84. $("#user_selector_popwin").hide();
  85. }