group localestorage related code into the extension
This commit is contained in:
@@ -340,21 +340,6 @@ export default class ConfigObj {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// LOAD CONTENT
|
|
||||||
if (this.editor.storage && // Cookies do not have enough available memory to hold large documents
|
|
||||||
(this.curConfig.forceStorage ||
|
|
||||||
(!this.curConfig.noStorageOnLoad &&
|
|
||||||
(/(?:^|;\s*)svgeditstore=prefsAndContent/).test(document.cookie))
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
const name = 'svgedit-' + this.curConfig.canvasName
|
|
||||||
const cached = this.editor.storage.getItem(name)
|
|
||||||
if (cached) {
|
|
||||||
this.editor.loadFromString(cached)
|
|
||||||
this.editor.topPanel.updateTitle(this.editor.storage.getItem(`title-${name}`) ?? 'untitled.svg')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// LOAD PREFS
|
// LOAD PREFS
|
||||||
Object.keys(this.defaultPrefs).forEach((key) => {
|
Object.keys(this.defaultPrefs).forEach((key) => {
|
||||||
const storeKey = 'svg-edit-' + key
|
const storeKey = 'svg-edit-' + key
|
||||||
|
|||||||
@@ -81,9 +81,26 @@ export default {
|
|||||||
// or adding of new storage takes place regardless of settings, set
|
// or adding of new storage takes place regardless of settings, set
|
||||||
// the "noStorageOnLoad" config setting to true in svgedit-config-*.js.
|
// the "noStorageOnLoad" config setting to true in svgedit-config-*.js.
|
||||||
noStorageOnLoad,
|
noStorageOnLoad,
|
||||||
forceStorage
|
forceStorage,
|
||||||
|
canvasName
|
||||||
} = svgEditor.configObj.curConfig
|
} = svgEditor.configObj.curConfig
|
||||||
|
|
||||||
|
// LOAD STORAGE CONTENT IF ANY
|
||||||
|
if (
|
||||||
|
storage && // Cookies do not have enough available memory to hold large documents
|
||||||
|
(forceStorage ||
|
||||||
|
(!noStorageOnLoad &&
|
||||||
|
/(?:^|;\s*)svgeditstore=prefsAndContent/.test(document.cookie)))
|
||||||
|
) {
|
||||||
|
const key = 'svgedit-' + canvasName
|
||||||
|
const cached = storage.getItem(key)
|
||||||
|
if (cached) {
|
||||||
|
svgEditor.loadFromString(cached)
|
||||||
|
const name = storage.getItem(`title-${key}`) ?? 'untitled.svg'
|
||||||
|
svgEditor.topPanel.updateTitle(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// storageDialog added to DOM
|
// storageDialog added to DOM
|
||||||
const storageBox = document.createElement('se-storage-dialog')
|
const storageBox = document.createElement('se-storage-dialog')
|
||||||
storageBox.setAttribute('id', 'se-storage-dialog')
|
storageBox.setAttribute('id', 'se-storage-dialog')
|
||||||
@@ -141,7 +158,7 @@ export default {
|
|||||||
* @param {string} svgString
|
* @param {string} svgString
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
const setSvgContentStorage = (svgString) => {
|
const setSvgContentStorage = svgString => {
|
||||||
const name = `svgedit-${svgEditor.configObj.curConfig.canvasName}`
|
const name = `svgedit-${svgEditor.configObj.curConfig.canvasName}`
|
||||||
if (!svgString) {
|
if (!svgString) {
|
||||||
storage.removeItem(name)
|
storage.removeItem(name)
|
||||||
@@ -161,7 +178,7 @@ export default {
|
|||||||
* 3. Use localStorage (where available) or cookies to set preferences.
|
* 3. Use localStorage (where available) or cookies to set preferences.
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function setupBeforeUnloadListener () {
|
const setupBeforeUnloadListener = () => {
|
||||||
window.addEventListener('beforeunload', function () {
|
window.addEventListener('beforeunload', function () {
|
||||||
// Don't save anything unless the user opted in to storage
|
// Don't save anything unless the user opted in to storage
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user