From 740617e5ce7f8b76233dac3ac02c8ce4b29c5302 Mon Sep 17 00:00:00 2001 From: buinsky Date: Sun, 30 Nov 2014 01:40:26 +0300 Subject: [PATCH] Use localStorage instead of cookies --- src/webui/www/public/scripts/client.js | 14 +++---- src/webui/www/public/scripts/dynamicTable.js | 2 +- src/webui/www/public/scripts/mocha-init.js | 42 +++++++++++++------- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/webui/www/public/scripts/client.js b/src/webui/www/public/scripts/client.js index 89dda29b6..b69f979e1 100644 --- a/src/webui/www/public/scripts/client.js +++ b/src/webui/www/public/scripts/client.js @@ -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(){ });*/ 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(){ .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(){ 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(){ $(f+"_filter").addClass("selectedFilter"); myTable.setFilter(f); ajaxfn(); - // Remember this via Cookie - Cookie.write('selected_filter', f); + localStorage.setItem('selected_filter', f); } }); diff --git a/src/webui/www/public/scripts/dynamicTable.js b/src/webui/www/public/scripts/dynamicTable.js index a05f69caa..7792c9958 100644 --- a/src/webui/www/public/scripts/dynamicTable.js +++ b/src/webui/www/public/scripts/dynamicTable.js @@ -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'; } diff --git a/src/webui/www/public/scripts/mocha-init.js b/src/webui/www/public/scripts/mocha-init.js index 6eac507f3..eb6a56bfe 100644 --- a/src/webui/www/public/scripts/mocha-init.js +++ b/src/webui/www/public/scripts/mocha-init.js @@ -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(){ }).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){