From 347bcb0cf4e84fa9538b4e89b41d36457914114c Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 23 May 2013 22:58:49 -0700 Subject: [PATCH] client side config uses localstorage instead of cookies --- UI/Config.js | 43 ++------------- UI/Index.html | 1 - UI/JsLibraries/jquery.cookie.js | 95 --------------------------------- 3 files changed, 4 insertions(+), 135 deletions(-) delete mode 100644 UI/JsLibraries/jquery.cookie.js diff --git a/UI/Config.js b/UI/Config.js index 407199e00..b25d3af74 100644 --- a/UI/Config.js +++ b/UI/Config.js @@ -1,55 +1,20 @@ "use strict"; define(['app'], function () { - $.cookie.json = true; - - NzbDrone.Config.SeriesViewStyle = function (value) { - var key = 'seriesViewStyle'; - - if (value !== undefined) { - NzbDrone.Config.SetValue(key, value); - } - else { - return NzbDrone.Config.GetValue(key, 1); - } - }; - NzbDrone.Config.GetValue = function (key, defaultValue) { - var cookie = NzbDrone.Config.GetCookie(); - - if (!cookie) { - return defaultValue; - } - var value = cookie[key]; + var storeValue = localStorage.getItem(key); - if (value === undefined) { + if (!storeValue) { return defaultValue; } - else { - return value; - } + return storeValue; }; NzbDrone.Config.SetValue = function (key, value) { - var cookie = NzbDrone.Config.GetCookie(); - - if (!cookie) { - cookie = {}; - } - console.log('Config: [{0}] => [{1}] '.format(key, value)); - - cookie[key] = value; - NzbDrone.Config.SetCookie(cookie); - }; - - NzbDrone.Config.GetCookie = function () { - return $.cookie('NzbDroneConfig'); + localStorage.setItem(key, value); }; - NzbDrone.Config.SetCookie = function (cookie) { - $.cookie('NzbDroneConfig', cookie, { expires: 365, path: '/' }); - }; }); diff --git a/UI/Index.html b/UI/Index.html index f27193482..1afead069 100644 --- a/UI/Index.html +++ b/UI/Index.html @@ -93,7 +93,6 @@ - diff --git a/UI/JsLibraries/jquery.cookie.js b/UI/JsLibraries/jquery.cookie.js deleted file mode 100644 index c4f99af00..000000000 --- a/UI/JsLibraries/jquery.cookie.js +++ /dev/null @@ -1,95 +0,0 @@ -/*! - * jQuery Cookie Plugin v1.3.1 - * https://github.com/carhartl/jquery-cookie - * - * Copyright 2013 Klaus Hartl - * Released under the MIT license - */ -(function (factory) { - if (typeof define === 'function' && define.amd) { - // AMD. Register as anonymous module. - define(['jquery'], factory); - } else { - // Browser globals. - factory(jQuery); - } -}(function ($) { - - var pluses = /\+/g; - - function raw(s) { - return s; - } - - function decoded(s) { - return decodeURIComponent(s.replace(pluses, ' ')); - } - - function converted(s) { - if (s.indexOf('"') === 0) { - // This is a quoted cookie as according to RFC2068, unescape - s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\'); - } - try { - return config.json ? JSON.parse(s) : s; - } catch(er) {} - } - - var config = $.cookie = function (key, value, options) { - - // write - if (value !== undefined) { - options = $.extend({}, config.defaults, options); - - if (typeof options.expires === 'number') { - var days = options.expires, t = options.expires = new Date(); - t.setDate(t.getDate() + days); - } - - value = config.json ? JSON.stringify(value) : String(value); - - return (document.cookie = [ - config.raw ? key : encodeURIComponent(key), - '=', - config.raw ? value : encodeURIComponent(value), - options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE - options.path ? '; path=' + options.path : '', - options.domain ? '; domain=' + options.domain : '', - options.secure ? '; secure' : '' - ].join('')); - } - - // read - var decode = config.raw ? raw : decoded; - var cookies = document.cookie.split('; '); - var result = key ? undefined : {}; - for (var i = 0, l = cookies.length; i < l; i++) { - var parts = cookies[i].split('='); - var name = decode(parts.shift()); - var cookie = decode(parts.join('=')); - - if (key && key === name) { - result = converted(cookie); - break; - } - - if (!key) { - result[name] = converted(cookie); - } - } - - return result; - }; - - config.defaults = {}; - - $.removeCookie = function (key, options) { - if ($.cookie(key) !== undefined) { - // Must not alter options, thus extending a fresh object... - $.cookie(key, '', $.extend({}, options, { expires: -1 })); - return true; - } - return false; - }; - -}));