mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-02 05:59:21 +03:00
Replaced dev/Common/ClientStorageDriver/* with webstorage polyfill
Cleanup some other code
This commit is contained in:
parent
0e8bf13d5d
commit
b837013cfb
13 changed files with 201 additions and 594 deletions
|
|
@ -1,3 +1,4 @@
|
|||
(w=>{
|
||||
|
||||
Array.prototype.flat || Object.defineProperty(Array.prototype, 'flat', {
|
||||
configurable: true,
|
||||
|
|
@ -15,18 +16,47 @@ Array.prototype.flat || Object.defineProperty(Array.prototype, 'flat', {
|
|||
writable: true
|
||||
});
|
||||
|
||||
if (!window.ResizeObserver) {
|
||||
window.ResizeObserver = class {
|
||||
constructor(callback) {
|
||||
this.observer = new MutationObserver(callback.debounce(250));
|
||||
}
|
||||
w.ResizeObserver || (w.ResizeObserver = class {
|
||||
constructor(callback) {
|
||||
this.observer = new MutationObserver(callback.debounce(250));
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
this.observer.disconnect();
|
||||
}
|
||||
disconnect() {
|
||||
this.observer.disconnect();
|
||||
}
|
||||
|
||||
observe(target) {
|
||||
this.observer.observe(target, { attributes: true, subtree: true, attributeFilter: ['style'] });
|
||||
}
|
||||
};
|
||||
}
|
||||
observe(target) {
|
||||
this.observer.observe(target, { attributes: true, subtree: true, attributeFilter: ['style'] });
|
||||
}
|
||||
});
|
||||
|
||||
const Storage = type => {
|
||||
let name = type+'Storage';
|
||||
try {
|
||||
w[name].setItem('storage', '');
|
||||
w[name].getItem('storage');
|
||||
w[name].removeItem('storage');
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
const cookieName = encodeURIComponent(name+('session' === type ? w.name || (w.name = Date.now()) : ''));
|
||||
|
||||
// initialise if there's already data
|
||||
let data = document.cookie.match('(^|;) ?'+cookieName+'=([^;]*)(;|$)');
|
||||
data = data ? decodeURIComponent(data[2]) : null;
|
||||
data = data ? JSON.parse(data) : {};
|
||||
|
||||
w[name] = {
|
||||
getItem: key => data[key] === undefined ? null : data[key],
|
||||
setItem: function (key, value) {
|
||||
data[key] = ''+value; // forces the value to a string
|
||||
document.cookie = cookieName+'='+encodeURIComponent(JSON.stringify(data))
|
||||
+"; expires="+('local' === type ? (new Date(Date.now()+(365*24*60*60*1000))).toGMTString() : '')
|
||||
+"; path=/; samesite=strict";
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
Storage('local');
|
||||
Storage('session');
|
||||
|
||||
})(window);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue