1class gcLocalStorage { 2 constructor(project_name, only_session) { 3 this.projectName = 'Geocms'; 4 this.storageObject = null; 5 this.storageData = {}; 6 this.debugFlag = true; 7 this.projectName = project_name ? project_name : this.projectName; 8 if (only_session) { 9 this.projectName = 'session' + this.projectName[0].toUpperCase() + this.projectName.substr(1).toLowerCase(); 10 this.storageObject = window.sessionStorage; 11 } 12 else { 13 this.projectName = 'local' + this.projectName[0].toUpperCase() + this.projectName.substr(1).toLowerCase(); 14 this.storageObject = window.localStorage; 15 } 16 let current = this.storageObject.getItem(this.projectName); 17 if (current === null) { 18 this.debug(this.projectName + 'neu erzeugen'); 19 this.storageData = { projectName: this.projectName }; 20 this.storageObject.setItem(this.projectName, JSON.stringify(this.storageData)); 21 } 22 else { 23 this.debug(this.projectName + ' vorhanden'); 24 this.storageData = JSON.parse(this.storageObject.getItem(this.projectName)); 25 } 26 window.addEventListener('storage', gcLocalStorage.refreshAll); 27 } 28 static refreshAll() { 29 if (window.hasOwnProperty('GeoCMSLocalStorage')) { 30 console.log('Local aktualisiert ..........'); 31 window['GeoCMSLocalStorage'].refresh(); 32 } 33 if (window.hasOwnProperty('GeoCMSSessionStorage')) { 34 console.log('Session aktualisiert ..........'); 35 window['GeoCMSSessionStorage'].refresh(); 36 } 37 } 38 refresh() { 39 this.storageData = JSON.parse(this.storageObject.getItem(this.projectName)); 40 } 41 debug(msg) { 42 if (this.debugFlag) { 43 console.log(msg); 44 } 45 } 46 getProjectName() { 47 return this.projectName; 48 } 49 save() { 50 this.storageObject.setItem(this.projectName, JSON.stringify(this.storageData)); 51 } 52 getItem(path) { 53 return this.getNestedValue(path, null); 54 } 55 setItem(path, value) { 56 return this.setNestedValue(path, value); 57 } 58 removeItem(path) { 59 this.setNestedValue(path, null); 60 } 61 getNestedValue(path, defValue) { 62 let buffer = this.storageData; 63 let pathItems = path.split('::'); 64 let item = null; 65 while (pathItems.length) { 66 item = pathItems.shift(); 67 if (typeof buffer[item] !== "undefined") { 68 buffer = buffer[item]; 69 } 70 else { 71 return typeof defValue !== "undefined" ? defValue : null; 72 } 73 } 74 return buffer; 75 } 76 setNestedValue(path, value) { 77 let buffer = this.storageData; 78 let pathItems = path.split('::'); 79 this.storageData = this._setNestedValue(buffer, pathItems, value, false); 80 this.save(); 81 } 82 addNestedValue(path, value) { 83 let buffer = this.storageData; 84 let pathItems = path.split('::'); 85 this.storageData = this._setNestedValue(buffer, pathItems, value, true); 86 this.save(); 87 } 88 exitsKey(path) { 89 let test = '__dfsdf16516dfdf15820358sdf__'; 90 let check = this.getNestedValue(path, test); 91 return check !== test; 92 } 93 isNull(path) { 94 let test = '__dfsdf16516dfdf15820358sdf__'; 95 let check = this.getNestedValue(path, test); 96 return check !== test && !check; 97 } 98 setNull(path) { 99 this.setNestedValue(path, null); 100 } 101 _setNestedValue(buffer, pathItems, value, add) { 102 if (pathItems) { 103 let item = pathItems.shift(); 104 if (pathItems.length) { 105 if (typeof buffer[item] !== "undefined") { 106 buffer[item] = this._setNestedValue(buffer[item], pathItems, value, add); 107 } 108 else { 109 buffer[item] = this._setNestedValue({}, pathItems, value, add); 110 } 111 } 112 else { 113 if (add && buffer[item] && Array.isArray(buffer[item])) { 114 buffer[item].push(value); 115 } 116 else { 117 buffer[item] = value; 118 } 119 } 120 } 121 return buffer; 122 } 123} 124//# sourceMappingURL=gcLocalStorage.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.