glsearch.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. $.widget("custom.catcomplete", $.ui.autocomplete, {
  2. _create: function () {
  3. this._super();
  4. this.widget().menu("option", "items", "> :not(.ui-autocomplete-category)");
  5. },
  6. _renderMenu: function (ul, items) {
  7. var that = this,
  8. currentCategory = "";
  9. $.each(items, function (index, item) {
  10. var li;
  11. if (item.category != currentCategory) {
  12. ul.append("<li class=\'ui-autocomplete-category\'>" + item.category + "</li>");
  13. currentCategory = item.category;
  14. }
  15. li = that._renderItemData(ul, item);
  16. if (item.category) {
  17. li.attr("aria-label", item.category + " : " + item.label);
  18. }
  19. });
  20. }
  21. });
  22. $(function () {
  23. var cache = {};
  24. $("#globalsearch").catcomplete({
  25. minLength: 2,
  26. focus: function (event, ui) {
  27. $("#globalsearch_type").val(ui.item.type);
  28. },
  29. source: function (request, response) {
  30. var term = request.term;
  31. if (term in cache) {
  32. response(cache[ term ]);
  33. return;
  34. }
  35. $.getJSON("?module=usersearch&glosearch=true", request, function (data, status, xhr) {
  36. cache[ term ] = data;
  37. response(data);
  38. });
  39. }
  40. });
  41. });