-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- rename folder for consistency - use csUiLib - fix inconsitencies with div toggler - remove double lookup with rbEventKey - don't handle active class, let react do it's job Co-authored-by: Elkorol <[email protected]>
- Loading branch information
1 parent
ad21862
commit 36cbeea
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Scene Page Remember States | ||
|
||
This plugin uses local storage to rememebr what is the current active nav tab of the scenes' detail panel, and upon any page load activate the last remembered active nav tab. | ||
|
||
It also rembers the active collapsed state of the divider button and upon page load if it's true, it will automatically collapse the divider. |
38 changes: 38 additions & 0 deletions
38
plugins/scenePageRememberStates/scenePageRememberStates.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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" | ||
// if it should be, but is not, collapse | ||
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) | ||
}) | ||
} | ||
|
||
function navTab() { | ||
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() | ||
} | ||
|
||
// add event listener | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: Scene Page Remember States | ||
description: Uses local storage to remember the state of the scene page detail panel nav bar and activate it on page load. Remembers collapse state of the divider. | ||
url: | ||
version: 0.2 | ||
ui: | ||
requires: | ||
- CommunityScriptsUILibrary | ||
javascript: | ||
- scenesPageRememberStates.js |