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.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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') || url.path == 'collages') {
  24. $("#artist" + SELECTOR).autocomplete({
  25. deferRequestBy: 300,
  26. serviceUrl : ARTIST_AUTOCOMPLETE_URL
  27. });
  28. $("#artistsimilar" + SELECTOR).autocomplete({
  29. deferRequestBy: 300,
  30. serviceUrl : ARTIST_AUTOCOMPLETE_URL
  31. });
  32. }
  33. if (url.path == 'torrents' || url.path == 'upload' || url.path == 'collages' || url.path == 'requests' || url.path == 'top10' || (url.path == 'requests' && url.query['action'] == 'new')) {
  34. $("#tags" + SELECTOR).autocomplete({
  35. deferRequestBy: 300,
  36. delimiter: ',',
  37. serviceUrl : TAGS_AUTOCOMPLETE_URL
  38. });
  39. $("#tagname" + SELECTOR).autocomplete({
  40. deferRequestBy: 300,
  41. delimiter: ',',
  42. serviceUrl : TAGS_AUTOCOMPLETE_URL
  43. });
  44. }
  45. };