forked from SpoTUI/SpoTUI
refactor(theme): refactor theme.js
- Added closeActivePanel
This commit is contained in:
@@ -1209,12 +1209,17 @@ const COMMAND_LIST = [
|
|||||||
function handleGlobalEsc(e) {
|
function handleGlobalEsc(e) {
|
||||||
if (e.key === "Escape") {
|
if (e.key === "Escape") {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (helpPanelOpen) closeHelpPanel();
|
closeActivePanel();
|
||||||
if (aboutPanelOpen) closeAboutPanel();
|
|
||||||
if (lyricsPanelOpen) closeLyricsPanel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function closeActivePanel() {
|
||||||
|
if (helpPanelOpen) setPanelState("spotui-help-panel", "spotui-help-panel", "helpPanelOpen", false);
|
||||||
|
if (aboutPanelOpen) setPanelState("spotui-about-panel", "spotui-about-panel", "aboutPanelOpen", false);
|
||||||
|
if (lyricsPanelOpen) closeLyricsPanel();
|
||||||
|
if (playlistPanelOpen) closePlaylistPanel();
|
||||||
|
}
|
||||||
|
|
||||||
function setPanelState(panelId, className, openVarName, targetState) {
|
function setPanelState(panelId, className, openVarName, targetState) {
|
||||||
const panels = {
|
const panels = {
|
||||||
'helpPanelOpen': () => helpPanelOpen = targetState,
|
'helpPanelOpen': () => helpPanelOpen = targetState,
|
||||||
@@ -1233,13 +1238,9 @@ function setPanelState(panelId, className, openVarName, targetState) {
|
|||||||
else document.removeEventListener("keydown", handleGlobalEsc);
|
else document.removeEventListener("keydown", handleGlobalEsc);
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeHelpPanel() { if (helpPanelOpen) setPanelState("spotui-help-panel", "spotui-help-panel", "helpPanelOpen", false); }
|
|
||||||
|
|
||||||
function openHelpPanel() {
|
function openHelpPanel() {
|
||||||
if (helpPanelOpen) { closeHelpPanel(); return; }
|
if (helpPanelOpen) { setPanelState("spotui-help-panel", "spotui-help-panel", "helpPanelOpen", false); return; }
|
||||||
if (lyricsPanelOpen) closeLyricsPanel();
|
closeActivePanel();
|
||||||
if (playlistPanelOpen) closePlaylistPanel();
|
|
||||||
if (aboutPanelOpen) closeAboutPanel();
|
|
||||||
|
|
||||||
setPanelState("spotui-help-panel", "spotui-help-panel", "helpPanelOpen", true);
|
setPanelState("spotui-help-panel", "spotui-help-panel", "helpPanelOpen", true);
|
||||||
const panel = document.getElementById("spotui-help-panel");
|
const panel = document.getElementById("spotui-help-panel");
|
||||||
@@ -1250,13 +1251,9 @@ function openHelpPanel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeAboutPanel() { if (aboutPanelOpen) setPanelState("spotui-about-panel", "spotui-about-panel", "aboutPanelOpen", false); }
|
|
||||||
|
|
||||||
function openAboutPanel() {
|
function openAboutPanel() {
|
||||||
if (aboutPanelOpen) { closeAboutPanel(); return; }
|
if (aboutPanelOpen) { setPanelState("spotui-about-panel", "spotui-about-panel", "aboutPanelOpen", false); return; }
|
||||||
if (lyricsPanelOpen) closeLyricsPanel();
|
closeActivePanel();
|
||||||
if (playlistPanelOpen) closePlaylistPanel();
|
|
||||||
if (helpPanelOpen) closeHelpPanel();
|
|
||||||
|
|
||||||
setPanelState("spotui-about-panel", "spotui-about-panel", "aboutPanelOpen", true);
|
setPanelState("spotui-about-panel", "spotui-about-panel", "aboutPanelOpen", true);
|
||||||
const panel = document.getElementById("spotui-about-panel");
|
const panel = document.getElementById("spotui-about-panel");
|
||||||
@@ -1282,8 +1279,7 @@ function closePlaylistPanel() {
|
|||||||
|
|
||||||
async function openPlaylistPanel() {
|
async function openPlaylistPanel() {
|
||||||
if (playlistPanelOpen) { closePlaylistPanel(); return; }
|
if (playlistPanelOpen) { closePlaylistPanel(); return; }
|
||||||
if (lyricsPanelOpen) closeLyricsPanel();
|
closeActivePanel();
|
||||||
if (helpPanelOpen) closeHelpPanel();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
playlists = await getPlaylists();
|
playlists = await getPlaylists();
|
||||||
@@ -1732,8 +1728,7 @@ function storeLyricsOpen(open) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function openLyricsPanel() {
|
function openLyricsPanel() {
|
||||||
if (playlistPanelOpen) closePlaylistPanel();
|
closeActivePanel();
|
||||||
if (helpPanelOpen) closeHelpPanel();
|
|
||||||
lyricsPanelOpen = true;
|
lyricsPanelOpen = true;
|
||||||
storeLyricsOpen(true);
|
storeLyricsOpen(true);
|
||||||
document.body.classList.add("spotui-lyrics-panel");
|
document.body.classList.add("spotui-lyrics-panel");
|
||||||
|
|||||||
Reference in New Issue
Block a user