Oppaitime'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 1.9KB

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