1
1
<template >
2
2
<div
3
- :class =" `collapsable ${rowColSpanClass} ${collapseClass} ${!cutToHeight ? 'full-height' : ''}`"
3
+ v-bind:class =" [
4
+ { 'is-open': isExpanded, 'full-height': cutToHeight },
5
+ `collapsable ${rowColSpanClass}`
6
+ ]"
4
7
:style =" `${color ? 'background: '+color : ''}; ${sanitizeCustomStyles(customStyles)};`"
5
8
>
6
9
<input
@@ -72,12 +75,32 @@ export default {
72
75
const { rows , cols , checkSpanNum } = this ;
73
76
return ` ${ checkSpanNum (cols, ' col' )} ${ checkSpanNum (rows, ' row' )} ` ;
74
77
},
78
+ isExpanded: {
79
+ // getter
80
+ get () {
81
+ if (this .collapsed !== undefined ) return ! this .collapsed ;
82
+ const collapseStateObject = this .initialiseStorage (); // Check local storage
83
+ if (collapseStateObject[this .uniqueKey ] !== undefined ) {
84
+ return collapseStateObject[this .uniqueKey ];
85
+ }
86
+ return true ; // Nothing specified, return Open
87
+ },
88
+ // setter
89
+ set (newState ) {
90
+ // Get the current localstorage collapse state object
91
+ const collapseState = JSON .parse (localStorage[localStorageKeys .COLLAPSE_STATE ]);
92
+ // Add the new state to it
93
+ collapseState[this .uniqueKey ] = newState;
94
+ // Stringify, and set the new object into local storage
95
+ localStorage .setItem (localStorageKeys .COLLAPSE_STATE , JSON .stringify (collapseState));
96
+ },
97
+ },
75
98
},
76
99
data : () => ({
77
- isExpanded: false ,
100
+ // isExpanded: false,
78
101
}),
79
102
mounted () {
80
- this .isExpanded = this .getCollapseState ();
103
+ // this.isExpanded = this.getCollapseState();
81
104
},
82
105
methods: {
83
106
/* Check that row & column span is valid, and not over the max */
@@ -93,43 +116,17 @@ export default {
93
116
},
94
117
/* Returns local storage collapse state data, and if not yet set then initialized is */
95
118
initialiseStorage () {
96
- const storageKey = localStorageKeys .COLLAPSE_STATE ;
97
- /* Initialize function will create and set a blank object to storage */
98
- const initStorage = () => localStorage .setItem (storageKey, JSON .stringify ({}));
99
119
// If not yet set, then call initialize
100
- if (! localStorage[storageKey ]) {
101
- initStorage ( );
120
+ if (! localStorage[localStorageKeys . COLLAPSE_STATE ]) {
121
+ localStorage . setItem ( localStorageKeys . COLLAPSE_STATE , JSON . stringify ({}) );
102
122
return {};
103
123
}
104
124
// Otherwise, return value of local storage
105
- return JSON .parse (localStorage[storageKey]);
106
- },
107
- /* If specified by user, return conf collapse state, otherwise check local storage */
108
- getCollapseState () {
109
- if (this .collapsed !== undefined ) return ! this .collapsed ; // Check users config
110
- const collapseStateObject = this .initialiseStorage (); // Check local storage
111
- if (collapseStateObject[this .uniqueKey ] !== undefined ) {
112
- return collapseStateObject[this .uniqueKey ];
113
- }
114
- // Nothing specified, return Open
115
- return true ;
125
+ return JSON .parse (localStorage[localStorageKeys .COLLAPSE_STATE ]);
116
126
},
117
- /* When section collapsed, update local storage, to remember for next time */
118
- setCollapseState (id , newState ) {
119
- // Get the current localstorage collapse state object
120
- const collapseState = JSON .parse (localStorage[localStorageKeys .COLLAPSE_STATE ]);
121
- // Add the new state to it
122
- collapseState[id] = newState;
123
- // Stringify, and set the new object into local storage
124
- localStorage .setItem (localStorageKeys .COLLAPSE_STATE , JSON .stringify (collapseState));
125
- },
126
- /* Called when collapse state changes, trigger local storage update if needed */
127
+ // /* Called when collapse state changes, trigger local storage update if needed */
127
128
collapseChanged (whatChanged ) {
128
129
this .isExpanded = whatChanged .srcElement .checked ;
129
- if (this .collapseState === undefined ) { // Only run, if user hasn't manually set prop
130
- this .initialiseStorage ();
131
- this .setCollapseState (this .uniqueKey .toString (), this .isExpanded );
132
- }
133
130
},
134
131
openEditModal () {
135
132
this .$emit (' openEditSection' );
0 commit comments