Gazelle/static/functions/autocomplete.js
2013-07-16 08:00:49 +00:00

33 lines
1.1 KiB
JavaScript

var ARTIST_AUTOCOMPLETE_URL = 'artist.php?action=autocomplete';
var TAGS_AUTOCOMPLETE_URL = 'torrents.php?action=autocomplete_tags';
var SELECTOR = '[data-gazelle-autocomplete="true"]';
$(document).ready(function() {
var url = new URL();
$('#artistsearch' + SELECTOR).autocomplete({
serviceUrl : ARTIST_AUTOCOMPLETE_URL,
onSelect : function(suggestion) {
window.location = 'artist.php?id=' + suggestion['data'];
},
});
if (url.path == 'torrents' || url.path == 'upload' || url.path == 'artist' || (url.path == 'requests' && url.query['action'] == 'new') || url.path == 'collages') {
$("#artist" + SELECTOR).autocomplete({
serviceUrl : ARTIST_AUTOCOMPLETE_URL
});
$("#artistsimilar" + SELECTOR).autocomplete({
serviceUrl : ARTIST_AUTOCOMPLETE_URL
});
}
if (url.path == 'torrents' || url.path == 'upload' || url.path == 'collages' || url.path == 'requests' || url.path == 'top10' || (url.path == 'requests' && url.query['action'] == 'new')) {
$("#tags" + SELECTOR).autocomplete({
serviceUrl : TAGS_AUTOCOMPLETE_URL,
delimiter: ','
});
$("#tagname" + SELECTOR).autocomplete({
serviceUrl : TAGS_AUTOCOMPLETE_URL,
});
}
});