Browse Source

Use localStorage instead of cookies

adaptive-webui-19844
buinsky 10 years ago
parent
commit
740617e5ce
  1. 14
      src/webui/www/public/scripts/client.js
  2. 2
      src/webui/www/public/scripts/dynamicTable.js
  3. 42
      src/webui/www/public/scripts/mocha-init.js

14
src/webui/www/public/scripts/client.js

@ -33,9 +33,8 @@ window.addEvent('load', function(){ @@ -33,9 +33,8 @@ window.addEvent('load', function(){
var saveColumnSizes = function() {
var filters_width = $('Filters').getSize().x;
var properties_height = $('propertiesPanel').getSize().y;
// Save it in a cookie
Cookie.write('filters_width', filters_width);
Cookie.write('properties_height', properties_height);
localStorage.setItem('filters_width', filters_width);
localStorage.setItem('properties_height', properties_height);
}
/*MochaUI.Desktop = new MochaUI.Desktop();
@ -45,7 +44,7 @@ window.addEvent('load', function(){ @@ -45,7 +44,7 @@ window.addEvent('load', function(){
});*/
MochaUI.Desktop.initialize();
var filt_w = Cookie.read('filters_width');
var filt_w = localStorage.getItem('filters_width');
if($defined(filt_w))
filt_w = filt_w.toInt();
else
@ -112,7 +111,7 @@ window.addEvent('load', function(){ @@ -112,7 +111,7 @@ window.addEvent('load', function(){
.replace("%2", friendlyUnit(info.dl_info_data, false)));
$("UpInfos").set('html', "_(U: %1 - T: %2)".replace("%1", friendlyUnit(info.up_info_speed, true))
.replace("%2", friendlyUnit(info.up_info_data, false)));
if(Cookie.read('speed_in_browser_title_bar') == 'true')
if(localStorage.getItem('speed_in_browser_title_bar') == 'true')
document.title = "_(D:%1 U:%2)".replace("%1", friendlyUnit(info.dl_info_speed, true)).replace("%2", friendlyUnit(info.up_info_speed, true));
else
document.title = "_(qBittorrent web User Interface)";
@ -226,7 +225,7 @@ window.addEvent('load', function(){ @@ -226,7 +225,7 @@ window.addEvent('load', function(){
onResize: saveColumnSizes,
height: null
});
var prop_h = Cookie.read('properties_height');
var prop_h = localStorage.getItem('properties_height');
if($defined(prop_h))
prop_h = prop_h.toInt();
else
@ -258,8 +257,7 @@ window.addEvent('load', function(){ @@ -258,8 +257,7 @@ window.addEvent('load', function(){
$(f+"_filter").addClass("selectedFilter");
myTable.setFilter(f);
ajaxfn();
// Remember this via Cookie
Cookie.write('selected_filter', f);
localStorage.setItem('selected_filter', f);
}
});

2
src/webui/www/public/scripts/dynamicTable.js

@ -42,7 +42,7 @@ var dynamicTable = new Class ({ @@ -42,7 +42,7 @@ var dynamicTable = new Class ({
this.cur = new Array();
this.priority_hidden = false;
this.progressIndex = progressIndex;
this.filter = Cookie.read('selected_filter');
this.filter = localStorage.getItem('selected_filter');
if(!$defined(this.filter)) {
this.filter = 'all';
}

42
src/webui/www/public/scripts/mocha-init.js

@ -9,6 +9,18 @@ @@ -9,6 +9,18 @@
----------------------------------------------------------------- */
/* 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});
}
}
}
initializeWindows = function(){
function addClickEvent(el, fn){
@ -269,23 +281,23 @@ initializeWindows = function(){ @@ -269,23 +281,23 @@ initializeWindows = function(){
}).send();
});
updateSpeedInBrowserTitleBarLinkCheckState = function()
{
if (Cookie.read('speed_in_browser_title_bar') == 'true')
$(speedInBrowserTitleBarLink).firstChild.style.opacity = '1';
else
$(speedInBrowserTitleBarLink).firstChild.style.opacity = '0';
}
updateSpeedInBrowserTitleBarLinkCheckState = function()
{
if (localStorage.getItem('speed_in_browser_title_bar') == 'true')
$(speedInBrowserTitleBarLink).firstChild.style.opacity = '1';
else
$(speedInBrowserTitleBarLink).firstChild.style.opacity = '0';
}
updateSpeedInBrowserTitleBarLinkCheckState();
updateSpeedInBrowserTitleBarLinkCheckState();
addClickEvent('speedInBrowserTitleBar', function(e){
new Event(e).stop();
var speed_in_browser_title_bar = Cookie.read('speed_in_browser_title_bar');
speed_in_browser_title_bar = speed_in_browser_title_bar == 'true' ? 'false' : 'true';
Cookie.write('speed_in_browser_title_bar', speed_in_browser_title_bar, {duration: 365 * 10});
updateSpeedInBrowserTitleBarLinkCheckState(true);
});
addClickEvent('speedInBrowserTitleBar', function(e){
new Event(e).stop();
var speed_in_browser_title_bar = localStorage.getItem('speed_in_browser_title_bar');
speed_in_browser_title_bar = speed_in_browser_title_bar == 'true' ? 'false' : 'true';
localStorage.setItem('speed_in_browser_title_bar', speed_in_browser_title_bar);
updateSpeedInBrowserTitleBarLinkCheckState();
});
// Deactivate menu header links
$$('a.returnFalse').each(function(el){

Loading…
Cancel
Save