2020-04-10 14:12:21 +00:00
|
|
|
// Load more content when the search page is at the end
|
2020-04-16 17:57:34 +00:00
|
|
|
$('#content').on('scroll', function () {
|
|
|
|
if ($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) {
|
|
|
|
if (
|
|
|
|
main_selected == 'search_tab' &&
|
|
|
|
['track_search', 'album_search', 'artist_search', 'playlist_search'].indexOf(search_selected) != -1
|
|
|
|
) {
|
|
|
|
scrolledSearch(window[search_selected.split('_')[0] + 'Search'])
|
2020-04-09 14:06:33 +00:00
|
|
|
}
|
2020-04-16 17:57:34 +00:00
|
|
|
}
|
2020-04-09 14:06:33 +00:00
|
|
|
})
|
|
|
|
|
2020-04-16 17:57:34 +00:00
|
|
|
function scrolledSearch(vueTab) {
|
2020-04-09 14:06:33 +00:00
|
|
|
query = vueTab.query
|
2020-04-16 17:57:34 +00:00
|
|
|
if (vueTab.results.next < vueTab.results.total) {
|
|
|
|
socket.emit('search', {
|
|
|
|
term: vueTab.query,
|
|
|
|
type: vueTab.type,
|
|
|
|
start: vueTab.results.next,
|
|
|
|
nb: vueTab.nb
|
|
|
|
})
|
2020-04-09 14:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 17:57:34 +00:00
|
|
|
function searchUpadate(result) {
|
2020-04-09 14:06:33 +00:00
|
|
|
console.log(result)
|
2020-04-16 17:57:34 +00:00
|
|
|
vueTab = null
|
2020-04-09 14:06:33 +00:00
|
|
|
switch (result.type) {
|
2020-04-16 17:57:34 +00:00
|
|
|
case 'TRACK':
|
|
|
|
vueTab = trackSearch
|
|
|
|
break
|
|
|
|
case 'ALBUM':
|
|
|
|
vueTab = albumSearch
|
|
|
|
break
|
|
|
|
case 'ARTIST':
|
|
|
|
vueTab = artistSearch
|
|
|
|
break
|
|
|
|
case 'PLAYLIST':
|
|
|
|
vueTab = playlistSearch
|
|
|
|
break
|
2020-04-09 14:06:33 +00:00
|
|
|
}
|
2020-04-16 17:57:34 +00:00
|
|
|
if (vueTab && vueTab.results.next != result.next) {
|
2020-04-09 14:06:33 +00:00
|
|
|
vueTab.results.next = result.next
|
|
|
|
vueTab.results.data = vueTab.results.data.concat(result.data)
|
|
|
|
}
|
2020-04-09 10:50:05 +00:00
|
|
|
}
|
2020-04-16 17:57:34 +00:00
|
|
|
socket.on('search', function (result) {
|
|
|
|
searchUpadate(result)
|
|
|
|
})
|
2020-04-09 10:50:05 +00:00
|
|
|
|
2020-04-16 17:57:34 +00:00
|
|
|
function clickElement(button) {
|
2020-04-09 12:44:51 +00:00
|
|
|
return document.getElementById(button).click()
|
2020-04-09 10:24:49 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 17:57:34 +00:00
|
|
|
function sendAddToQueue(url, bitrate = null) {
|
2020-04-18 12:59:58 +00:00
|
|
|
if (url.indexOf(";") != -1){
|
|
|
|
urls = url.split(";")
|
|
|
|
urls.forEach(url=>{
|
|
|
|
socket.emit('addToQueue', { url: url, bitrate: bitrate })
|
|
|
|
})
|
2020-04-18 13:02:11 +00:00
|
|
|
}else if(url != ""){
|
2020-04-18 12:59:58 +00:00
|
|
|
socket.emit('addToQueue', { url: url, bitrate: bitrate })
|
|
|
|
}
|
2020-04-14 08:34:31 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 17:57:34 +00:00
|
|
|
let MainSearch = new Vue({
|
|
|
|
el: '#main_search',
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
names: {
|
|
|
|
TOP_RESULT: 'Top Result',
|
|
|
|
TRACK: 'Tracks',
|
|
|
|
ARTIST: 'Artists',
|
|
|
|
ALBUM: 'Albums',
|
|
|
|
PLAYLIST: 'Playlists'
|
|
|
|
},
|
|
|
|
results: {
|
|
|
|
QUERY: '',
|
|
|
|
ORDER: [],
|
|
|
|
ALBUM: {},
|
|
|
|
ARTIST: {},
|
|
|
|
TRACK: {},
|
|
|
|
TOP_RESULT: [],
|
|
|
|
PLAYLIST: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-04-09 12:44:51 +00:00
|
|
|
methods: {
|
2020-04-16 17:57:34 +00:00
|
|
|
changeSearchTab(section) {
|
|
|
|
if (section != 'TOP_RESULT') clickElement('search_' + section.toLowerCase() + '_tab')
|
2020-04-10 16:00:42 +00:00
|
|
|
},
|
2020-04-17 10:15:12 +00:00
|
|
|
addToQueue: function(e){e.stopPropagation(); sendAddToQueue(e.currentTarget.dataset.link)},
|
2020-04-16 11:38:59 +00:00
|
|
|
openQualityModal: function(e){e.preventDefault(); openQualityModal(e.currentTarget.dataset.link)}
|
2020-04-09 12:44:51 +00:00
|
|
|
}
|
2020-04-08 16:43:35 +00:00
|
|
|
})
|
|
|
|
|
2020-04-09 10:24:49 +00:00
|
|
|
var trackSearch = new Vue({
|
2020-04-16 17:57:34 +00:00
|
|
|
el: '#track_search',
|
|
|
|
data: {
|
|
|
|
type: 'TRACK',
|
2020-04-09 14:06:33 +00:00
|
|
|
nb: 40,
|
2020-04-16 17:57:34 +00:00
|
|
|
query: '',
|
2020-04-10 16:00:42 +00:00
|
|
|
results: {
|
2020-04-09 14:06:33 +00:00
|
|
|
data: [],
|
|
|
|
next: 0,
|
|
|
|
total: 0
|
2020-04-09 10:24:49 +00:00
|
|
|
}
|
2020-04-16 17:57:34 +00:00
|
|
|
},
|
2020-04-10 16:00:42 +00:00
|
|
|
methods: {
|
2020-04-17 10:15:12 +00:00
|
|
|
addToQueue: function(e){e.stopPropagation(); sendAddToQueue(e.currentTarget.dataset.link)},
|
2020-04-16 11:38:59 +00:00
|
|
|
openQualityModal: function(e){e.preventDefault(); openQualityModal(e.currentTarget.dataset.link)}
|
2020-04-10 16:00:42 +00:00
|
|
|
}
|
2020-04-09 10:24:49 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
var albumSearch = new Vue({
|
2020-04-16 17:57:34 +00:00
|
|
|
el: '#album_search',
|
|
|
|
data: {
|
|
|
|
type: 'ALBUM',
|
2020-04-09 14:06:33 +00:00
|
|
|
nb: 20,
|
2020-04-16 17:57:34 +00:00
|
|
|
query: '',
|
2020-04-10 16:00:42 +00:00
|
|
|
results: {
|
2020-04-09 14:06:33 +00:00
|
|
|
data: [],
|
|
|
|
next: 0,
|
|
|
|
total: 0
|
2020-04-09 10:24:49 +00:00
|
|
|
}
|
2020-04-16 17:57:34 +00:00
|
|
|
},
|
2020-04-10 16:00:42 +00:00
|
|
|
methods: {
|
2020-04-17 10:15:12 +00:00
|
|
|
addToQueue: function(e){e.stopPropagation(); sendAddToQueue(e.currentTarget.dataset.link)},
|
2020-04-16 11:38:59 +00:00
|
|
|
openQualityModal: function(e){e.preventDefault(); openQualityModal(e.currentTarget.dataset.link)}
|
2020-04-10 16:00:42 +00:00
|
|
|
}
|
2020-04-09 10:24:49 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
var artistSearch = new Vue({
|
2020-04-16 17:57:34 +00:00
|
|
|
el: '#artist_search',
|
|
|
|
data: {
|
|
|
|
type: 'ARTIST',
|
2020-04-09 14:06:33 +00:00
|
|
|
nb: 20,
|
2020-04-16 17:57:34 +00:00
|
|
|
query: '',
|
2020-04-10 16:00:42 +00:00
|
|
|
results: {
|
2020-04-09 14:06:33 +00:00
|
|
|
data: [],
|
|
|
|
next: 0,
|
|
|
|
total: 0
|
2020-04-09 10:24:49 +00:00
|
|
|
}
|
2020-04-16 17:57:34 +00:00
|
|
|
},
|
2020-04-10 16:00:42 +00:00
|
|
|
methods: {
|
2020-04-17 10:15:12 +00:00
|
|
|
addToQueue: function(e){e.stopPropagation(); sendAddToQueue(e.currentTarget.dataset.link)},
|
2020-04-16 11:38:59 +00:00
|
|
|
openQualityModal: function(e){e.preventDefault(); openQualityModal(e.currentTarget.dataset.link)}
|
2020-04-10 16:00:42 +00:00
|
|
|
}
|
2020-04-09 10:24:49 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
var playlistSearch = new Vue({
|
2020-04-16 17:57:34 +00:00
|
|
|
el: '#playlist_search',
|
|
|
|
data: {
|
|
|
|
type: 'PLAYLIST',
|
2020-04-09 14:06:33 +00:00
|
|
|
nb: 20,
|
2020-04-16 17:57:34 +00:00
|
|
|
query: '',
|
2020-04-10 16:00:42 +00:00
|
|
|
results: {
|
2020-04-09 14:06:33 +00:00
|
|
|
data: [],
|
|
|
|
next: 0,
|
|
|
|
total: 0
|
2020-04-09 10:24:49 +00:00
|
|
|
}
|
2020-04-16 17:57:34 +00:00
|
|
|
},
|
2020-04-10 16:00:42 +00:00
|
|
|
methods: {
|
2020-04-17 10:15:12 +00:00
|
|
|
addToQueue: function(e){e.stopPropagation(); sendAddToQueue(e.currentTarget.dataset.link)},
|
2020-04-16 11:38:59 +00:00
|
|
|
openQualityModal: function(e){e.preventDefault(); openQualityModal(e.currentTarget.dataset.link)}
|
2020-04-10 16:00:42 +00:00
|
|
|
}
|
2020-04-09 10:24:49 +00:00
|
|
|
})
|
|
|
|
|
2020-04-16 17:57:34 +00:00
|
|
|
let term = null
|
|
|
|
|
2020-04-07 22:19:27 +00:00
|
|
|
// Search section
|
2020-04-16 13:45:17 +00:00
|
|
|
$("#searchbar").keyup(function(e){
|
2020-04-08 16:43:35 +00:00
|
|
|
if(e.keyCode == 13){
|
2020-04-16 13:28:19 +00:00
|
|
|
term = this.value
|
|
|
|
if (isValidURL(term)){
|
|
|
|
if (e.ctrlKey){
|
|
|
|
openQualityModal(term);
|
|
|
|
}else{
|
|
|
|
sendAddToQueue(term);
|
|
|
|
}
|
|
|
|
}else{
|
2020-04-17 19:33:46 +00:00
|
|
|
console.log( term );
|
2020-04-18 12:59:58 +00:00
|
|
|
|
2020-04-17 10:15:12 +00:00
|
|
|
if (term != MainSearch.results.QUERY || main_selected == 'search_tab'){
|
|
|
|
document.getElementById("search_tab_content").style.display = "none";
|
|
|
|
socket.emit("mainSearch", {term: term});
|
|
|
|
}else{
|
|
|
|
document.getElementById('search_all_tab').click()
|
|
|
|
document.getElementById('search_tab_content').style.display = 'block'
|
|
|
|
document.getElementById('main_search_tablink').click()
|
|
|
|
}
|
2020-04-09 10:24:49 +00:00
|
|
|
}
|
2020-04-16 17:57:34 +00:00
|
|
|
}
|
2020-04-07 22:19:27 +00:00
|
|
|
})
|
|
|
|
|
2020-04-16 17:57:34 +00:00
|
|
|
function mainSearchHandler(result) {
|
|
|
|
MainSearch.results = result
|
2020-04-09 10:24:49 +00:00
|
|
|
trackSearch.results = result.TRACK
|
|
|
|
albumSearch.results = result.ALBUM
|
|
|
|
artistSearch.results = result.ARTIST
|
|
|
|
playlistSearch.results = result.PLAYLIST
|
2020-04-09 14:06:33 +00:00
|
|
|
trackSearch.query = result.QUERY
|
|
|
|
albumSearch.query = result.QUERY
|
|
|
|
artistSearch.query = result.QUERY
|
|
|
|
playlistSearch.query = result.QUERY
|
2020-04-16 17:57:34 +00:00
|
|
|
document.getElementById('search_all_tab').click()
|
|
|
|
document.getElementById('search_tab_content').style.display = 'block'
|
|
|
|
document.getElementById('main_search_tablink').click()
|
2020-04-07 22:19:27 +00:00
|
|
|
}
|
2020-04-16 19:26:00 +00:00
|
|
|
|
2020-04-16 17:57:34 +00:00
|
|
|
socket.on('mainSearch', function (result) {
|
|
|
|
mainSearchHandler(result)
|
2020-04-17 10:15:12 +00:00
|
|
|
})
|