mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-15 17:53:08 -07:00
Extract WebUI localStorage access into class
This commit is contained in:
parent
f339f629ae
commit
7047974132
9 changed files with 100 additions and 70 deletions
|
@ -38,26 +38,7 @@
|
|||
----------------------------------------------------------------- */
|
||||
'use strict';
|
||||
|
||||
/* Define localStorage object for older browsers */
|
||||
if (typeof localStorage == 'undefined') {
|
||||
window['localStorage'] = {
|
||||
getItem: function(name) {
|
||||
return Cookie.read(name);
|
||||
},
|
||||
setItem: function(name, value) {
|
||||
Cookie.write(name, value, {
|
||||
duration: 365 * 10
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function getLocalStorageItem(name, defaultVal) {
|
||||
let val = localStorage.getItem(name);
|
||||
if (val === null || val === undefined)
|
||||
val = defaultVal;
|
||||
return val;
|
||||
}
|
||||
const LocalPreferences = new LocalPreferencesClass();
|
||||
|
||||
let saveWindowSize = function() {};
|
||||
let loadWindowWidth = function() {};
|
||||
|
@ -107,16 +88,16 @@ let setQueuePositionFN = function() {};
|
|||
const initializeWindows = function() {
|
||||
saveWindowSize = function(windowId) {
|
||||
const size = $(windowId).getSize();
|
||||
localStorage.setItem('window_' + windowId + '_width', size.x);
|
||||
localStorage.setItem('window_' + windowId + '_height', size.y);
|
||||
LocalPreferences.set('window_' + windowId + '_width', size.x);
|
||||
LocalPreferences.set('window_' + windowId + '_height', size.y);
|
||||
};
|
||||
|
||||
loadWindowWidth = function(windowId, defaultValue) {
|
||||
return getLocalStorageItem('window_' + windowId + '_width', defaultValue);
|
||||
return LocalPreferences.get('window_' + windowId + '_width', defaultValue);
|
||||
};
|
||||
|
||||
loadWindowHeight = function(windowId, defaultValue) {
|
||||
return getLocalStorageItem('window_' + windowId + '_height', defaultValue);
|
||||
return LocalPreferences.get('window_' + windowId + '_height', defaultValue);
|
||||
};
|
||||
|
||||
function addClickEvent(el, fn) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue