sphinxsearch.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. function appendToList(value, login, title) {
  2. var billingLink = '?module=userprofile&username=';
  3. var userLink = billingLink.concat(login);
  4. var node = document.createElement("li");
  5. var link = document.createElement("a");
  6. var container = document.createElement("div");
  7. var textnode = document.createTextNode(value);
  8. link.appendChild(textnode);
  9. link.title = title;
  10. link.href = userLink;
  11. node.classList.add('ui-menu-item');
  12. container.appendChild(link);
  13. container.classList.add('ui-menu');
  14. container.classList.add('ui-menu-item-wrapper');
  15. node.appendChild(container);
  16. document.getElementById("ssearchcontainer").appendChild(node);
  17. showSearchContainer();
  18. }
  19. function querySearch(value) {
  20. var searchList = document.getElementById('ssearchcontainer');
  21. if (value !== "") {
  22. animationStart();
  23. var xhr = new XMLHttpRequest();
  24. var searchString = 'search=';
  25. var searchQuery = searchString.concat(value);
  26. xhr.open('POST', '?module=usersearch&sphinxsearch=true', true);
  27. xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  28. xhr.onload = function () {
  29. searchList.innerHTML = "";
  30. var JSONresponse = JSON.parse(this.responseText);
  31. JSONresponse.forEach(function (object) {
  32. if (object.value !== undefined) {
  33. var description = object.title.concat(": ");
  34. var fulldesc = description.concat(object.value);
  35. appendToList(object.value, object.login, fulldesc);
  36. }
  37. })
  38. animationStop();
  39. };
  40. xhr.send(searchQuery);
  41. } else {
  42. searchList.innerHTML = "";
  43. hideSearchContainer();
  44. }
  45. }
  46. function hideSearchContainer() {
  47. document.getElementById("ssearchcontainer").style.display = "none";
  48. }
  49. function showSearchContainer() {
  50. document.getElementById("ssearchcontainer").style.display = "block";
  51. }
  52. function animationStart() {
  53. document.getElementById("sphinxsearchinput").className = "sphinxsearch-input-loading";
  54. }
  55. function animationStop() {
  56. document.getElementById("sphinxsearchinput").className = "sphinxsearch-input";
  57. }
  58. //some reaction on ESC key
  59. $(document).keyup(function (e) {
  60. if (e.keyCode == 27) {
  61. hideSearchContainer();
  62. }
  63. });