1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Palette: Remember category open/close state across reloads.

This commit is contained in:
Bruno Feurer 2022-08-30 15:08:43 +02:00
parent 30ea300f65
commit fc5a0ceaf5

View File

@ -65,12 +65,14 @@ RED.palette = (function() {
catDiv.addClass("red-ui-palette-closed"); catDiv.addClass("red-ui-palette-closed");
$("#red-ui-palette-base-category-"+category).slideUp(); $("#red-ui-palette-base-category-"+category).slideUp();
$("#red-ui-palette-header-"+category+" i").removeClass("expanded"); $("#red-ui-palette-header-"+category+" i").removeClass("expanded");
rememberCategoryState(category, false)
}, },
open: function() { open: function() {
catDiv.addClass("red-ui-palette-open"); catDiv.addClass("red-ui-palette-open");
catDiv.removeClass("red-ui-palette-closed"); catDiv.removeClass("red-ui-palette-closed");
$("#red-ui-palette-base-category-"+category).slideDown(); $("#red-ui-palette-base-category-"+category).slideDown();
$("#red-ui-palette-header-"+category+" i").addClass("expanded"); $("#red-ui-palette-header-"+category+" i").addClass("expanded");
rememberCategoryState(category, true)
}, },
toggle: function() { toggle: function() {
if (catDiv.hasClass("red-ui-palette-open")) { if (catDiv.hasClass("red-ui-palette-open")) {
@ -85,6 +87,22 @@ RED.palette = (function() {
categoryContainers[category].toggle(); categoryContainers[category].toggle();
}); });
} }
function rememberCategoryState(cat, open) {
const stateStr = localStorage.getItem('closedCategories');
if (!stateStr && open) return;
const state = stateStr ? JSON.parse(stateStr) : [];
const idx = state.indexOf(cat);
if (open && idx >= 0)
state.splice(idx, 1);
else if (!open && idx < 0)
state.push(cat);
else
return;
if (state.length <= 0)
localStorage.removeItem('closedCategories');
else
localStorage.setItem('closedCategories', JSON.stringify(state));
}
function setLabel(type, el,label, info) { function setLabel(type, el,label, info) {
var nodeWidth = 82; var nodeWidth = 82;
@ -407,7 +425,12 @@ RED.palette = (function() {
var categoryNode = $("#red-ui-palette-container-"+rootCategory); var categoryNode = $("#red-ui-palette-container-"+rootCategory);
if (categoryNode.find(".red-ui-palette-node").length === 1) { if (categoryNode.find(".red-ui-palette-node").length === 1) {
const closedCategoriesStr = localStorage.getItem('closedCategories');
const closedCategories = closedCategoriesStr ? JSON.parse(closedCategoriesStr) : [];
if (closedCategories.indexOf(rootCategory) < 0)
categoryContainers[rootCategory].open(); categoryContainers[rootCategory].open();
else
categoryContainers[rootCategory].close();
} }
} }