@@ -54,34 +54,27 @@ var CacheClassExplorer = function (treeViewContainer, classViewContainer) {
5454 dependencyLevel : id ( "setting.dependencyLevel" )
5555 }
5656 } ;
57- var selfAux = this ;
58- var settingsValue = function ( name , defaultVal ) {
59- try {
60- if ( selfAux . elements . settings [ name ] . type == "checkbox" ) {
61- return localStorage . getItem ( name ) === null ? ( defaultVal || false )
62- : localStorage . getItem ( name ) === "true"
63- }
64- if ( [ "text" , "number" ] . indexOf ( selfAux . elements . settings [ name ] . type ) >= 0 ) {
65- var ret = localStorage . getItem ( name ) ;
66- if ( ret === null ) ret = defaultVal ;
67- return ret ;
68- }
69- } catch ( error ) {
70- return localStorage . getItem ( name ) === null ? ( defaultVal || false )
71- : localStorage . getItem ( name ) === "true" }
57+
58+ var getSettingsValue = function ( name , defaultVal ) {
59+ var item = localStorage . getItem ( name ) ;
60+ try {
61+ return item ? JSON . parse ( item ) . data : defaultVal ;
62+ } catch ( e ) { // non-parsable data
63+ return defaultVal ;
64+ }
7265 } ;
7366
7467 // note: this.elements is required to be modified with the same name as settings keys
7568 this . settings = {
76- showDataTypesOnDiagram : settingsValue ( "showDataTypesOnDiagram" ) ,
77- showClassIcons : settingsValue ( "showClassIcons" , true ) ,
78- showPropertyIcons : settingsValue ( "showPropertyIcons" , true ) ,
79- showParameters : settingsValue ( "showParameters" , true ) ,
80- showProperties : settingsValue ( "showProperties" , true ) ,
81- showMethods : settingsValue ( "showMethods" , true ) ,
82- showQueries : settingsValue ( "showQueries" , true ) ,
83- showXDatas : settingsValue ( "showXDatas" , true ) ,
84- dependencyLevel : settingsValue ( "dependencyLevel" , "" )
69+ showDataTypesOnDiagram : getSettingsValue ( "showDataTypesOnDiagram" ) ,
70+ showClassIcons : getSettingsValue ( "showClassIcons" , true ) ,
71+ showPropertyIcons : getSettingsValue ( "showPropertyIcons" , true ) ,
72+ showParameters : getSettingsValue ( "showParameters" , true ) ,
73+ showProperties : getSettingsValue ( "showProperties" , true ) ,
74+ showMethods : getSettingsValue ( "showMethods" , true ) ,
75+ showQueries : getSettingsValue ( "showQueries" , true ) ,
76+ showXDatas : getSettingsValue ( "showXDatas" , true ) ,
77+ dependencyLevel : getSettingsValue ( "dependencyLevel" , "" )
8578 } ;
8679
8780 this . UI = new UI ( this ) ;
@@ -103,28 +96,22 @@ var CacheClassExplorer = function (treeViewContainer, classViewContainer) {
10396CacheClassExplorer . prototype . initSettings = function ( ) {
10497
10598 var self = this ,
106- textChanged = "Please, re-render diagram to make changes apply." ;
99+ TEXT_CHANGED = "Please, re-render diagram to make changes apply." ;
107100
108101 for ( var st in this . elements . settings ) {
109- if ( ! this . elements . settings [ st ] ) {
110- console . warn ( st , "is Bred Sivoi Cobyly." ) ;
111- continue ;
112- }
113-
114- if ( [ "text" , "number" ] . indexOf ( this . elements . settings [ st ] . type ) >= 0 ) this . elements . settings [ st ] . value = this . settings [ st ] ;
115- if ( this . elements . settings [ st ] . type == "checkbox" ) this . elements . settings [ st ] . checked = this . settings [ st ] ;
102+
103+ var element = this . elements . settings [ st ] ;
104+
105+ // dropdown ("select") support is not predicted
106+ element [ element . type === "checkbox" ? "checked" : "value" ] = this . settings [ st ] ;
116107
117- this . elements . settings [ st ] . addEventListener ( "change" , ( function ( st ) {
118- return function ( e ) {
119- self . elements . settingsExtraText . innerHTML = textChanged ;
120- if ( [ "text" , "number" ] . indexOf ( ( e . target || e . srcElement ) . type ) >= 0 ) self . settings [ st ] = ( e . target || e . srcElement ) . value
121- if ( ( e . target || e . srcElement ) . type == "checkbox" ) self . settings [ st ] = ( e . target || e . srcElement ) . checked
122- localStorage . setItem (
123- st ,
124- self . settings [ st ]
125- ) ;
126- } ;
127- } ) ( st ) ) ;
108+ element . addEventListener ( "change" , ( function ( st , element ) { return function ( ) {
109+ self . elements . settingsExtraText . innerHTML = TEXT_CHANGED ;
110+ localStorage . setItem ( st , self . settings [ st ] = JSON . stringify ( {
111+ data : element [ element . type === "checkbox" ? "checked" : "value" ]
112+ } ) ) ;
113+ } ; } ) ( st , element ) ) ;
114+
128115 }
129116
130117} ;
@@ -172,7 +159,7 @@ CacheClassExplorer.prototype.updateURL = function () {
172159 var obj = {
173160 name : this . classTree . SELECTED_NAME ,
174161 type : this . classTree . SELECTED_TYPE ,
175- level : this . classTree . SELECTED_LEVEL ,
162+ level : this . classTree . SELECTED_LEVEL
176163 } ;
177164
178165 if ( this . NAMESPACE ) obj [ "namespace" ] = this . NAMESPACE ;
0 commit comments