deemix-webui/public/js/app.js

222 lines
5.4 KiB
JavaScript
Raw Normal View History

// Debug messages for socketio
socket.on("message", function(msg){
console.log(msg)
})
2020-04-08 00:19:27 +02:00
$(function() {
// Check if download tab should be open
if (eval(localStorage.getItem("downloadTabOpen")))
$("#show_download_tab").click()
else
$("#hide_download_tab").click()
})
2020-04-08 00:19:27 +02:00
// Show/Hide Download Tab
document.querySelector("#show_download_tab").onclick = (ev)=>{
ev.preventDefault();
document.querySelector("#download_tab_bar").style.display = "none";
document.querySelector("#download_tab").style.display = "block";
localStorage.setItem("downloadTabOpen", true)
2020-04-08 00:19:27 +02:00
}
document.querySelector("#hide_download_tab").onclick = (ev)=>{
ev.preventDefault();
document.querySelector("#download_tab_bar").style.display = "block";
document.querySelector("#download_tab").style.display = "none";
localStorage.setItem("downloadTabOpen", false)
2020-04-08 00:19:27 +02:00
}
2020-04-09 12:50:05 +02:00
function changeTab(evt, section, tabName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName(section+"_tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
2020-04-09 12:50:05 +02:00
}
tablinks = document.getElementsByClassName(section+"_tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
2020-04-09 12:50:05 +02:00
}
document.getElementById(tabName).style.display = "block";
2020-04-09 16:06:33 +02:00
window[section+"_selected"] = tabName
2020-04-09 12:50:05 +02:00
evt.currentTarget.className += " active";
// Check if you need to load more content in the search tab
2020-04-09 16:06:33 +02:00
if (document.getElementById("content").offsetHeight >= document.getElementById("content").scrollHeight && main_selected == "search_tab" && ["track_search", "album_search", "artist_search", "playlist_search"].indexOf(search_selected) != -1){
scrolledSearch(window[search_selected.split("_")[0]+"Search"])
}
}
// Load more content when the search page is at the end
2020-04-09 16:06:33 +02: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){
2020-04-09 16:06:33 +02:00
scrolledSearch(window[search_selected.split("_")[0]+"Search"])
}
}
})
function scrolledSearch(vueTab){
query = vueTab.query
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 16:06:33 +02:00
}
}
function searchUpadate(result){
console.log(result)
vueTab = null;
switch (result.type) {
case "TRACK":
vueTab = trackSearch;
break;
case "ALBUM":
vueTab = albumSearch;
break;
case "ARTIST":
vueTab = artistSearch;
break;
case "PLAYLIST":
vueTab = playlistSearch;
break;
}
if (vueTab && vueTab.results.next != result.next){
vueTab.results.next = result.next
vueTab.results.data = vueTab.results.data.concat(result.data)
}
2020-04-09 12:50:05 +02:00
}
socket.on("search", function(result){searchUpadate(result)})
2020-04-09 12:50:05 +02:00
function clickElement(button){
return document.getElementById(button).click()
2020-04-09 12:24:49 +02:00
}
2020-04-08 18:43:35 +02:00
var mainSearch = new Vue({
el: '#main_search',
data: {
names: {
"TOP_RESULT": "Top Result",
"TRACK": "Tracks",
"ARTIST": "Artists",
"ALBUM": "Albums",
"PLAYLIST": "Playlists"
},
2020-04-10 18:00:42 +02:00
results: {
2020-04-09 16:06:33 +02:00
QUERY: "",
2020-04-08 18:43:35 +02:00
ORDER: [],
ALBUM: {},
ARTIST: {},
TRACK: {},
TOP_RESULT: [],
PLAYLIST: {}
},
},
methods: {
changeSearchTab: function (section) {
if (section != "TOP_RESULT")
clickElement('search_'+section.toLowerCase()+'_tab')
2020-04-10 18:00:42 +02:00
},
2020-04-10 23:04:05 +02:00
addToQueue: function(url){socket.emit("addToQueue", {url: url})}
}
2020-04-08 18:43:35 +02:00
})
2020-04-09 12:24:49 +02:00
var trackSearch = new Vue({
el: '#track_search',
data: {
2020-04-09 16:06:33 +02:00
type: "TRACK",
nb: 40,
query: "",
2020-04-10 18:00:42 +02:00
results: {
2020-04-09 16:06:33 +02:00
data: [],
next: 0,
total: 0
2020-04-09 12:24:49 +02:00
}
2020-04-10 18:00:42 +02:00
},
methods: {
addToQueue: function(url){socket.emit("addToQueue", {url: url})}
}
2020-04-09 12:24:49 +02:00
})
var albumSearch = new Vue({
el: '#album_search',
data: {
2020-04-09 16:06:33 +02:00
type: "ALBUM",
nb: 20,
query: "",
2020-04-10 18:00:42 +02:00
results: {
2020-04-09 16:06:33 +02:00
data: [],
next: 0,
total: 0
2020-04-09 12:24:49 +02:00
}
2020-04-10 18:00:42 +02:00
},
methods: {
addToQueue: function(url){socket.emit("addToQueue", {url: url})}
}
2020-04-09 12:24:49 +02:00
})
var artistSearch = new Vue({
el: '#artist_search',
data: {
2020-04-09 16:06:33 +02:00
type: "ARTIST",
nb: 20,
query: "",
2020-04-10 18:00:42 +02:00
results: {
2020-04-09 16:06:33 +02:00
data: [],
next: 0,
total: 0
2020-04-09 12:24:49 +02:00
}
2020-04-10 18:00:42 +02:00
},
methods: {
addToQueue: function(url){socket.emit("addToQueue", {url: url})}
}
2020-04-09 12:24:49 +02:00
})
var playlistSearch = new Vue({
el: '#playlist_search',
data: {
2020-04-09 16:06:33 +02:00
type: "PLAYLIST",
nb: 20,
query: "",
2020-04-10 18:00:42 +02:00
results: {
2020-04-09 16:06:33 +02:00
data: [],
next: 0,
total: 0
2020-04-09 12:24:49 +02:00
}
2020-04-10 18:00:42 +02:00
},
methods: {
addToQueue: function(url){socket.emit("addToQueue", {url: url})}
}
2020-04-09 12:24:49 +02:00
})
2020-04-08 00:19:27 +02:00
// Search section
2020-04-08 18:43:35 +02:00
$("#searchbar").keyup(function(e){
if(e.keyCode == 13){
term = this.value
console.log(term)
if (isValidURL(term))
socket.emit("addToQueue", {url: term});
2020-04-09 12:24:49 +02:00
else{
2020-04-09 12:50:05 +02:00
document.getElementById("search_tab_content").style.display = "none";
socket.emit("mainSearch", {term: term});
2020-04-09 12:24:49 +02:00
}
2020-04-08 18:43:35 +02:00
}
2020-04-08 00:19:27 +02:00
})
function mainSearchHandler(result){
2020-04-08 00:19:27 +02:00
console.log(result)
2020-04-08 18:43:35 +02:00
mainSearch.results = result
2020-04-09 12:24:49 +02:00
trackSearch.results = result.TRACK
albumSearch.results = result.ALBUM
artistSearch.results = result.ARTIST
playlistSearch.results = result.PLAYLIST
2020-04-09 16:06:33 +02:00
trackSearch.query = result.QUERY
albumSearch.query = result.QUERY
artistSearch.query = result.QUERY
playlistSearch.query = result.QUERY
2020-04-09 12:24:49 +02:00
document.getElementById("search_defaultopen").click();
2020-04-09 12:50:05 +02:00
document.getElementById("search_tab_content").style.display = "block";
document.getElementById("show_searchtab").click();
2020-04-08 00:19:27 +02:00
}
socket.on("mainSearch", function(result){mainSearchHandler(result)})
2020-04-09 12:50:05 +02:00
$(function(){
document.getElementById("main_defaultopen").click();
})