123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- /**
- * Utility class for working with persisted application settings
- */
- var mxSettings =
- {
- // NOTE: Hardcoded in index.html due to timing of JS loading
- key: '.drawio-config',
- settings:
- {
- language: '',
- libraries: Sidebar.prototype.defaultEntries,
- customLibraries: [],
- plugins: [],
- formatWidth: '240',
- currentEdgeStyle: Graph.prototype.defaultEdgeStyle,
- currentVertexStyle: {},
- createTarget: false,
- pageFormat: mxGraph.prototype.pageFormat,
- search: true,
- showStartScreen: true,
- gridColor: mxGraphView.prototype.gridColor,
- autosave: true,
- version: 12,
- // Only defined and true for new settings which haven't been saved
- isNew: true
- },
- getLanguage: function()
- {
- return this.settings.language;
- },
- setLanguage: function(lang)
- {
- this.settings.language = lang;
- },
- getUi: function()
- {
- return this.settings.ui;
- },
- setUi: function(ui)
- {
- this.settings.ui = ui;
- },
- getShowStartScreen: function()
- {
- return this.settings.showStartScreen;
- },
- setShowStartScreen: function(showStartScreen)
- {
- this.settings.showStartScreen = showStartScreen;
- },
- getGridColor: function()
- {
- return this.settings.gridColor;
- },
- setGridColor: function(gridColor)
- {
- this.settings.gridColor = gridColor;
- },
- getAutosave: function()
- {
- return this.settings.autosave;
- },
- setAutosave: function(autosave)
- {
- this.settings.autosave = autosave;
- },
- getLibraries: function()
- {
- return this.settings.libraries;
- },
- setLibraries: function(libs)
- {
- this.settings.libraries = libs;
- },
- addCustomLibrary: function(id)
- {
- // Makes sure to update the latest data from the localStorage
- mxSettings.load();
-
- if (mxUtils.indexOf(this.settings.customLibraries, id) < 0)
- {
- this.settings.customLibraries.push(id);
- }
-
- mxSettings.save();
- },
- removeCustomLibrary: function(id)
- {
- // Makes sure to update the latest data from the localStorage
- mxSettings.load();
- mxUtils.remove(id, this.settings.customLibraries);
- mxSettings.save();
- },
- getCustomLibraries: function()
- {
- return this.settings.customLibraries;
- },
- getPlugins: function()
- {
- return this.settings.plugins;
- },
- setPlugins: function(plugins)
- {
- this.settings.plugins = plugins;
- },
- getFormatWidth: function()
- {
- return parseInt(this.settings.formatWidth);
- },
- setFormatWidth: function(formatWidth)
- {
- this.settings.formatWidth = formatWidth;
- },
- getCurrentEdgeStyle: function()
- {
- return this.settings.currentEdgeStyle;
- },
- setCurrentEdgeStyle: function(value)
- {
- this.settings.currentEdgeStyle = value;
- },
- getCurrentVertexStyle: function()
- {
- return this.settings.currentVertexStyle;
- },
- setCurrentVertexStyle: function(value)
- {
- this.settings.currentVertexStyle = value;
- },
- isCreateTarget: function()
- {
- return this.settings.createTarget;
- },
- setCreateTarget: function(value)
- {
- this.settings.createTarget = value;
- },
- getPageFormat: function()
- {
- return this.settings.pageFormat;
- },
- setPageFormat: function(value)
- {
- this.settings.pageFormat = value;
- },
- save: function()
- {
- if (isLocalStorage && typeof(JSON) !== 'undefined')
- {
- try
- {
- delete this.settings.isNew;
- this.settings.version = 12;
- localStorage.setItem(mxSettings.key, JSON.stringify(this.settings));
- }
- catch (e)
- {
- // ignores quota exceeded
- }
- }
- },
- load: function()
- {
- if (isLocalStorage && typeof(JSON) !== 'undefined')
- {
- mxSettings.parse(localStorage.getItem(mxSettings.key));
- }
- },
- parse: function(value)
- {
- if (value != null)
- {
- this.settings = JSON.parse(value);
- if (this.settings.plugins == null)
- {
- this.settings.plugins = [];
- }
-
- if (this.settings.libraries == null)
- {
- this.settings.libraries = Sidebar.prototype.defaultEntries;
- }
-
- if (this.settings.customLibraries == null)
- {
- this.settings.customLibraries = [];
- }
-
- if (this.settings.ui == null)
- {
- this.settings.ui = '';
- }
-
- if (this.settings.formatWidth == null)
- {
- this.settings.formatWidth = '240';
- }
-
- if (this.settings.lastAlert != null)
- {
- delete this.settings.lastAlert;
- }
-
- if (this.settings.currentEdgeStyle == null)
- {
- this.settings.currentEdgeStyle = Graph.prototype.defaultEdgeStyle;
- }
- else if (this.settings.version <= 10)
- {
- // Adds new defaults for jetty size and loop routing
- this.settings.currentEdgeStyle['orthogonalLoop'] = 1;
- this.settings.currentEdgeStyle['jettySize'] = 'auto';
- }
-
- if (this.settings.currentVertexStyle == null)
- {
- this.settings.currentVertexStyle = {};
- }
-
- if (this.settings.createTarget == null)
- {
- this.settings.createTarget = false;
- }
-
- if (this.settings.pageFormat == null)
- {
- this.settings.pageFormat = mxGraph.prototype.pageFormat;
- }
-
- if (this.settings.search == null)
- {
- this.settings.search = true;
- }
-
- if (this.settings.showStartScreen == null)
- {
- this.settings.showStartScreen = true;
- }
-
- if (this.settings.gridColor == null)
- {
- this.settings.gridColor = mxGraphView.prototype.gridColor;
- }
-
- if (this.settings.autosave == null)
- {
- this.settings.autosave = true;
- }
-
- if (this.settings.scratchpadSeen != null)
- {
- delete this.settings.scratchpadSeen;
- }
- }
- },
- clear: function()
- {
- if (isLocalStorage)
- {
- localStorage.removeItem(mxSettings.key);
- }
- }
- }
- /**
- * Variable: mxLoadSettings
- *
- * Optional global config variable to toggle loading the settings. Default is true.
- *
- * (code)
- * <script type="text/javascript">
- * var mxLoadSettings = false;
- * </script>
- * (end)
- */
- if (typeof(mxLoadSettings) == 'undefined' || mxLoadSettings)
- {
- // Loads initial content
- mxSettings.load();
- }
|