Implemented simple tab system

This commit is contained in:
RemixDev 2020-04-09 12:50:05 +02:00
parent bba5e6522c
commit 11164375be
3 changed files with 139 additions and 112 deletions

View File

@ -13,6 +13,9 @@ aside#sidebar > .side_icon{
font-size: 24px;
margin: 12px;
}
.side_icon.active{
color: #0A84FF;
}
/* Rest of the app */
main#main_content{
@ -85,11 +88,8 @@ div#middle_section {
}
}
/* Search Tab */
.search_tabcontent {
display: none;
}
#search_tab{
/* Tabs */
.search_tabcontent, .main_tabcontent {
display: none;
}

View File

@ -11,26 +11,28 @@
<body>
<aside id="sidebar">
<i class="material-icons side_icon">menu</i>
<i class="material-icons side_icon">home</i>
<i class="material-icons side_icon">bubble_chart</i>
<i class="material-icons side_icon">album</i>
<i class="material-icons side_icon">link</i>
<i class="material-icons side_icon">settings</i>
<i class="material-icons side_icon">info</i>
<i onclick="changeTab(event, 'main', 'search_tab')" id="show_searchtab" class="main_tablinks"></i>
<i onclick="changeTab(event, 'main', 'home_tab')" id="main_defaultopen" class="material-icons side_icon main_tablinks">home</i>
<i onclick="changeTab(event, 'main', 'charts_tab')" class="material-icons side_icon main_tablinks">bubble_chart</i>
<i onclick="changeTab(event, 'main', 'favorites_tab')" class="material-icons side_icon main_tablinks">album</i>
<i onclick="changeTab(event, 'main', 'analyzer_tab')" class="material-icons side_icon main_tablinks">link</i>
<i onclick="changeTab(event, 'main', 'settings_tab')" class="material-icons side_icon main_tablinks">settings</i>
<i onclick="changeTab(event, 'main', 'about_tab')" class="material-icons side_icon main_tablinks">info</i>
</aside>
<main id="main_content">
<div id="middle_section">
<header id="search"><input id="searchbar" type="text" name="searchbar" value="" placeholder="Search..."></header>
<section id="content"><div id="container">
<div id="search_tab">
<div id="search_tab" class="main_tabcontent">
<div class="tab">
<button class="search_tablinks" id="search_defaultopen" onclick="searchTab(event, 'main_search')">All</button>
<button class="search_tablinks" onclick="searchTab(event, 'track_search')">Tracks</button>
<button class="search_tablinks" onclick="searchTab(event, 'album_search')">Album</button>
<button class="search_tablinks" onclick="searchTab(event, 'artist_search')">Artist</button>
<button class="search_tablinks" onclick="searchTab(event, 'playlist_search')">Playlist</button>
<button class="search_tablinks" id="search_defaultopen" onclick="changeTab(event, 'search', 'main_search')">All</button>
<button class="search_tablinks" onclick="changeTab(event, 'search', 'track_search')">Tracks</button>
<button class="search_tablinks" onclick="changeTab(event, 'search', 'album_search')">Album</button>
<button class="search_tablinks" onclick="changeTab(event, 'search', 'artist_search')">Artist</button>
<button class="search_tablinks" onclick="changeTab(event, 'search', 'playlist_search')">Playlist</button>
</div>
<div id="search_tab_content">
<!-- ### Main Search Tab ### -->
<div id="main_search" class="search_tabcontent">
<template v-for="section in results.ORDER">
@ -135,7 +137,13 @@ <h1>No Playlists found</h1>
</div>
</div>
</div>
</div>
<div id="home_tab" class="main_tabcontent"><h1>Home</h1></div>
<div id="charts_tab" class="main_tabcontent"><h1>Charts</h1></div>
<div id="favorites_tab" class="main_tabcontent"><h1>Favorites</h1></div>
<div id="analyzer_tab" class="main_tabcontent"><h1>Link Analyzer</h1></div>
<div id="settings_tab" class="main_tabcontent"><h1>Settings</h1></div>
<div id="about_tab" class="main_tabcontent"><h1>About</h1></div>
</div></section>
</div>
<div id="download_tab_container">

View File

@ -53,6 +53,20 @@ document.querySelector("#hide_download_tab").onclick = (ev)=>{
document.querySelector("#download_tab").style.display = "none";
}
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";
}
tablinks = document.getElementsByClassName(section+"_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";
}
// searchTab
function searchTab(evt, tabName) {
@ -134,7 +148,7 @@ $("#searchbar").keyup(function(e){
if (isValidURL(term))
doAjax("/download", "POST", null, {url: term});
else{
document.getElementById("search_tab").style.display = "none";
document.getElementById("search_tab_content").style.display = "none";
doAjax("/search", "POST", searchHandler, {term: term});
}
}
@ -148,5 +162,10 @@ function searchHandler(result){
artistSearch.results = result.ARTIST
playlistSearch.results = result.PLAYLIST
document.getElementById("search_defaultopen").click();
document.getElementById("search_tab").style.display = "block";
document.getElementById("search_tab_content").style.display = "block";
document.getElementById("show_searchtab").click();
}
$(function(){
document.getElementById("main_defaultopen").click();
})