BioTorrents.de’s version of Gazelle
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.

autocomplete.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. var ARTIST_AUTOCOMPLETE_URL = 'artist.php?action=autocomplete';
  2. var TAGS_AUTOCOMPLETE_URL = 'torrents.php?action=autocomplete_tags';
  3. var SELECTOR = '[data-gazelle-autocomplete="true"]';
  4. $(document).ready(initAutocomplete)
  5. /**
  6. * initAutocomplete
  7. */
  8. function initAutocomplete() {
  9. if (!$.Autocomplete) {
  10. window.setTimeout(function () {
  11. initAutocomplete();
  12. }, 500)
  13. return;
  14. }
  15. var url = {
  16. path: window.location.pathname.split('/').reverse()[0].split(".")[0],
  17. query: window.location.search.slice(1).split('&').reduce((a, b) => Object.assign(a, { [b.split('=')[0]]: b.split('=')[1] }), {})
  18. }
  19. $('#artistsearch' + SELECTOR).autocomplete({
  20. deferRequestBy: 300,
  21. onSelect: function (suggestion) {
  22. window.location = 'artist.php?id=' + suggestion['data'];
  23. },
  24. serviceUrl: ARTIST_AUTOCOMPLETE_URL,
  25. });
  26. if (url.path == 'torrents' || url.path == 'upload' || url.path == 'artist' || (url.path == 'requests' && url.query['action'] == 'new')) {
  27. $("#artist" + SELECTOR).autocomplete({
  28. deferRequestBy: 300,
  29. serviceUrl: ARTIST_AUTOCOMPLETE_URL
  30. });
  31. }
  32. if (url.path == 'torrents' || url.path == 'upload' || url.path == 'collages' || url.path == 'requests' || url.path == 'top10' || (url.path == 'requests' && url.query['action'] == 'new')) {
  33. $("#tags" + SELECTOR).autocomplete({
  34. deferRequestBy: 300,
  35. delimiter: ',',
  36. serviceUrl: TAGS_AUTOCOMPLETE_URL
  37. });
  38. $("#tagname" + SELECTOR).autocomplete({
  39. deferRequestBy: 300,
  40. delimiter: ',',
  41. serviceUrl: TAGS_AUTOCOMPLETE_URL
  42. });
  43. }
  44. if (url.path == 'upload' || (url.path == 'torrents' && url.query['action'] == 'editgroup')) {
  45. $("#artist_0" + SELECTOR).autocomplete({
  46. deferRequestBy: 300,
  47. serviceUrl: ARTIST_AUTOCOMPLETE_URL
  48. });
  49. }
  50. if (url.path == 'requests' && url.query['action'] == 'new') {
  51. $("#artist_0" + SELECTOR).autocomplete({
  52. deferRequestBy: 300,
  53. serviceUrl: ARTIST_AUTOCOMPLETE_URL
  54. });
  55. }
  56. };