2020-04-07 22:19:27 +00:00
|
|
|
// Initialization
|
|
|
|
doAjax("/init", "POST");
|
|
|
|
|
2020-04-08 16:43:35 +00:00
|
|
|
// Functions to connect to the Flask server
|
2020-04-07 22:19:27 +00:00
|
|
|
function getHttpRequestObject(){
|
|
|
|
var xmlHttpRequst = false;
|
|
|
|
if (window.XMLHttpRequest){
|
|
|
|
xmlHttpRequst = new XMLHttpRequest();
|
2020-04-08 16:43:35 +00:00
|
|
|
}else if (window.ActiveXObject){
|
2020-04-07 22:19:27 +00:00
|
|
|
xmlHttpRequst = new ActiveXObject("Microsoft.XMLHTTP");
|
|
|
|
}
|
|
|
|
return xmlHttpRequst;
|
|
|
|
}
|
|
|
|
function doAjax(url, method, responseHandler, data){
|
|
|
|
url = url || "";
|
|
|
|
method = method || "GET";
|
|
|
|
async = true;
|
|
|
|
data = data || {};
|
|
|
|
|
|
|
|
if(url == ""){
|
|
|
|
alert("URL cannot be null/blank");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var xmlHttpRequest = getHttpRequestObject();
|
|
|
|
|
|
|
|
if(xmlHttpRequest != false){
|
|
|
|
xmlHttpRequest.open(method, url, async);
|
|
|
|
if(method == "POST"){
|
|
|
|
xmlHttpRequest.setRequestHeader("Content-Type", "application/json");
|
|
|
|
}
|
2020-04-08 16:43:35 +00:00
|
|
|
if (typeof responseHandler === "function"){
|
|
|
|
xmlHttpRequest.onreadystatechange = function(){
|
|
|
|
if(this.readyState === XMLHttpRequest.DONE && this.status === 200) {
|
|
|
|
responseHandler(JSON.parse(this.responseText))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-07 22:19:27 +00:00
|
|
|
xmlHttpRequest.send(JSON.stringify(data));
|
2020-04-08 16:43:35 +00:00
|
|
|
}else{
|
2020-04-07 22:19:27 +00:00
|
|
|
alert("Please use a browser with Ajax support!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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";
|
|
|
|
}
|
|
|
|
document.querySelector("#hide_download_tab").onclick = (ev)=>{
|
|
|
|
ev.preventDefault();
|
|
|
|
document.querySelector("#download_tab_bar").style.display = "block";
|
|
|
|
document.querySelector("#download_tab").style.display = "none";
|
|
|
|
}
|
|
|
|
|
2020-04-09 10:24:49 +00:00
|
|
|
// searchTab
|
|
|
|
|
|
|
|
function searchTab(evt, tabName) {
|
|
|
|
var i, tabcontent, tablinks;
|
|
|
|
tabcontent = document.getElementsByClassName("search_tabcontent");
|
|
|
|
for (i = 0; i < tabcontent.length; i++) {
|
|
|
|
tabcontent[i].style.display = "none";
|
|
|
|
}
|
|
|
|
tablinks = document.getElementsByClassName("search_tablinks");
|
|
|
|
for (i = 0; i < tablinks.length; i++) {
|
|
|
|
tablinks[i].className = tablinks[i].className.replace(" active", "");
|
|
|
|
}
|
|
|
|
document.getElementById(tabName).style.display = "block";
|
|
|
|
evt.currentTarget.className += " active";
|
|
|
|
}
|
|
|
|
|
2020-04-08 16:43:35 +00:00
|
|
|
var mainSearch = new Vue({
|
|
|
|
el: '#main_search',
|
|
|
|
data: {
|
|
|
|
names: {
|
|
|
|
"TOP_RESULT": "Top Result",
|
|
|
|
"TRACK": "Tracks",
|
|
|
|
"ARTIST": "Artists",
|
|
|
|
"ALBUM": "Albums",
|
|
|
|
"PLAYLIST": "Playlists"
|
|
|
|
},
|
|
|
|
results: {
|
|
|
|
ORDER: [],
|
|
|
|
ALBUM: {},
|
|
|
|
ARTIST: {},
|
|
|
|
TRACK: {},
|
|
|
|
TOP_RESULT: [],
|
|
|
|
PLAYLIST: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-04-09 10:24:49 +00:00
|
|
|
var trackSearch = new Vue({
|
|
|
|
el: '#track_search',
|
|
|
|
data: {
|
|
|
|
results: {
|
|
|
|
data: []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
var albumSearch = new Vue({
|
|
|
|
el: '#album_search',
|
|
|
|
data: {
|
|
|
|
results: {
|
|
|
|
data: []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
var artistSearch = new Vue({
|
|
|
|
el: '#artist_search',
|
|
|
|
data: {
|
|
|
|
results: {
|
|
|
|
data: []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
var playlistSearch = new Vue({
|
|
|
|
el: '#playlist_search',
|
|
|
|
data: {
|
|
|
|
results: {
|
|
|
|
data: []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-04-07 22:19:27 +00:00
|
|
|
// Search section
|
2020-04-08 16:43:35 +00:00
|
|
|
$("#searchbar").keyup(function(e){
|
|
|
|
if(e.keyCode == 13){
|
|
|
|
term = this.value
|
|
|
|
console.log(term)
|
2020-04-08 17:01:50 +00:00
|
|
|
if (isValidURL(term))
|
|
|
|
doAjax("/download", "POST", null, {url: term});
|
2020-04-09 10:24:49 +00:00
|
|
|
else{
|
|
|
|
document.getElementById("search_tab").style.display = "none";
|
2020-04-08 17:01:50 +00:00
|
|
|
doAjax("/search", "POST", searchHandler, {term: term});
|
2020-04-09 10:24:49 +00:00
|
|
|
}
|
2020-04-08 16:43:35 +00:00
|
|
|
}
|
2020-04-07 22:19:27 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
function searchHandler(result){
|
|
|
|
console.log(result)
|
2020-04-08 16:43:35 +00:00
|
|
|
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
|
|
|
|
document.getElementById("search_defaultopen").click();
|
|
|
|
document.getElementById("search_tab").style.display = "block";
|
2020-04-07 22:19:27 +00:00
|
|
|
}
|