2020-04-17 17:39:51 +00:00
|
|
|
var search_selected = ''
|
|
|
|
var main_selected = ''
|
|
|
|
var windows_stack = []
|
|
|
|
var currentStack = {}
|
|
|
|
|
|
|
|
function changeTab(evt, section, tabName) {
|
|
|
|
windows_stack = []
|
|
|
|
currentStack = {}
|
|
|
|
var i, tabcontent, tablinks
|
|
|
|
tabcontent = document.getElementsByClassName(section + '_tabcontent')
|
|
|
|
for (i = 0; i < tabcontent.length; i++) {
|
|
|
|
tabcontent[i].style.display = 'none'
|
|
|
|
}
|
|
|
|
tablinks = document.getElementsByClassName(section + '_tablinks')
|
|
|
|
for (i = 0; i < tablinks.length; i++) {
|
2020-04-17 20:11:53 +00:00
|
|
|
tablinks[i].classList.remove('active')
|
2020-04-17 17:39:51 +00:00
|
|
|
}
|
|
|
|
if (tabName == 'settings_tab' && main_selected != 'settings_tab') {
|
2020-04-19 16:55:24 +00:00
|
|
|
SettingsTab.settings = { ...lastSettings }
|
2020-04-17 17:39:51 +00:00
|
|
|
}
|
2020-04-17 20:11:53 +00:00
|
|
|
|
2020-04-17 17:39:51 +00:00
|
|
|
document.getElementById(tabName).style.display = 'block'
|
|
|
|
window[section + '_selected'] = tabName
|
2020-04-17 20:11:53 +00:00
|
|
|
|
2020-04-18 09:40:19 +00:00
|
|
|
// Not choosing .currentTarget beacuse the event
|
2020-04-17 20:11:53 +00:00
|
|
|
// is delegated, so it refers to #sidebar
|
|
|
|
evt.target.classList.add('active')
|
|
|
|
|
2020-04-17 17:39:51 +00:00
|
|
|
// Check if you need to load more content in the search tab
|
|
|
|
if (
|
|
|
|
main_selected == 'search_tab' &&
|
2020-04-19 17:22:21 +00:00
|
|
|
['track_search', 'album_search', 'artist_search', 'playlist_search'].indexOf(search_selected) != -1 &&
|
|
|
|
MainSearch.results[search_selected.split('_')[0]+"Tab"].data.length == 0
|
2020-04-17 17:39:51 +00:00
|
|
|
) {
|
2020-04-19 17:22:21 +00:00
|
|
|
search(search_selected.split('_')[0])
|
2020-04-17 17:39:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-18 09:40:19 +00:00
|
|
|
function showTab(type, id, back=false) {
|
2020-04-17 20:11:53 +00:00
|
|
|
if (windows_stack.length == 0) windows_stack.push({ tab: main_selected })
|
2020-04-18 09:40:19 +00:00
|
|
|
else if (!back) windows_stack.push(currentStack)
|
2020-04-17 20:11:53 +00:00
|
|
|
if (type == 'artist') tab = 'artist_tab'
|
|
|
|
else tab = 'tracklist_tab'
|
|
|
|
currentStack = { type: type, id: id }
|
2020-04-17 17:39:51 +00:00
|
|
|
let tabcontent = document.getElementsByClassName('main_tabcontent')
|
|
|
|
for (let i = 0; i < tabcontent.length; i++) {
|
|
|
|
tabcontent[i].style.display = 'none'
|
|
|
|
}
|
|
|
|
document.getElementById(tab).style.display = 'block'
|
|
|
|
}
|
|
|
|
|
2020-04-17 20:11:53 +00:00
|
|
|
function backTab() {
|
|
|
|
if (windows_stack.length == 1) {
|
|
|
|
clickElement('main_' + main_selected + 'link')
|
|
|
|
} else {
|
2020-04-17 17:39:51 +00:00
|
|
|
let tabObj = windows_stack.pop()
|
2020-04-18 13:42:00 +00:00
|
|
|
if (tabObj.type == 'artist') resetArtistTab()
|
|
|
|
else resetTracklistTab()
|
|
|
|
socket.emit('getTracklist', {type: tabObj.type, id: tabObj.id})
|
2020-04-18 09:40:19 +00:00
|
|
|
showTab(tabObj.type, tabObj.id, true)
|
2020-04-17 17:39:51 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-17 20:11:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles click Event on the sidebar and changes tab
|
|
|
|
* according to clicked icon.
|
|
|
|
* Uses event delegation
|
|
|
|
* @param {Event} event
|
|
|
|
* @since ?.?.?
|
|
|
|
*/
|
|
|
|
function handleSidebarClick(event) {
|
|
|
|
let targetID = event.target.id
|
|
|
|
|
|
|
|
switch (targetID) {
|
|
|
|
case 'main_search_tablink':
|
|
|
|
changeTab(event, 'main', 'search_tab')
|
|
|
|
break
|
|
|
|
case 'main_home_tablink':
|
|
|
|
changeTab(event, 'main', 'home_tab')
|
|
|
|
break
|
|
|
|
case 'main_charts_tablink':
|
|
|
|
changeTab(event, 'main', 'charts_tab')
|
|
|
|
break
|
|
|
|
case 'main_favorites_tablink':
|
|
|
|
changeTab(event, 'main', 'favorites_tab')
|
|
|
|
break
|
|
|
|
case 'main_analyzer_tablink':
|
|
|
|
changeTab(event, 'main', 'analyzer_tab')
|
|
|
|
break
|
|
|
|
case 'main_settings_tablink':
|
|
|
|
changeTab(event, 'main', 'settings_tab')
|
|
|
|
break
|
|
|
|
case 'main_about_tablink':
|
|
|
|
changeTab(event, 'main', 'about_tab')
|
|
|
|
break
|
|
|
|
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('sidebar').addEventListener('click', handleSidebarClick)
|