Skip to content

Commit

Permalink
[scenePageRemeberState] prettier fix
Browse files Browse the repository at this point in the history
  • Loading branch information
feederbox826 committed Nov 27, 2024
1 parent 36cbeea commit 2deddca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
31 changes: 16 additions & 15 deletions plugins/scenePageRememberStates/scenePageRememberStates.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,38 @@ function sceneDivider(tabs) {
const dividerBtn = document.querySelector(".scene-divider > button");

// check if tab is currently collapsed, and if it should be
const isCollapsed = () => tabs.classList.contains("collapsed")
const storedCollapse = localStorage.getItem("remember-state-divider") == "true"
const isCollapsed = () => tabs.classList.contains("collapsed");
const storedCollapse =
localStorage.getItem("remember-state-divider") == "true";
// if it should be, but is not, collapse
if (storedCollapse && !isCollapsed()) dividerBtn.click()
if (storedCollapse && !isCollapsed()) dividerBtn.click();

// add listener to change desired state based on current collapsed state
dividerBtn.addEventListener("click", () => {
// isCollapsed does not update in time
const newState = !isCollapsed()
localStorage.setItem("remember-state-divider", newState)
})
const newState = !isCollapsed();
localStorage.setItem("remember-state-divider", newState);
});
}

function navTab() {
const detailsNav = document.querySelector(".nav-tabs")
const detailsNav = document.querySelector(".nav-tabs");

// Check local storage for entries
let activeKey = localStorage.getItem("remember-state-navtab");

// click on desired active key if defined
if (activeKey) {
detailsNav.querySelector(`a[data-rb-event-key="${activeKey}"]`).click()
detailsNav.querySelector(`a[data-rb-event-key="${activeKey}"]`).click();
}

// add event listener
detailsNav.querySelectorAll("a").forEach(href => {
href.addEventListener("click", function() {
localStorage.setItem("remember-state-navtab", this.dataset.rbEventKey)
})
})
detailsNav.querySelectorAll("a").forEach((href) => {
href.addEventListener("click", function () {
localStorage.setItem("remember-state-navtab", this.dataset.rbEventKey);
});
});
}

csLib.PathElementListener("/scenes/", ".nav-tabs", navTab)
csLib.PathElementListener("/scenes/", ".scene-tabs", sceneDivider)
csLib.PathElementListener("/scenes/", ".nav-tabs", navTab);
csLib.PathElementListener("/scenes/", ".scene-tabs", sceneDivider);
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ ui:
requires:
- CommunityScriptsUILibrary
javascript:
- scenesPageRememberStates.js
- scenesPageRememberStates.js

0 comments on commit 2deddca

Please sign in to comment.