Fix local storage (Closes #303)

This commit is contained in:
RainLoop Team 2014-09-02 15:34:17 +04:00
parent 77870442fe
commit 664c1dca80
11 changed files with 147 additions and 103 deletions

View file

@ -19,7 +19,7 @@
kn = require('App:Knoin'), kn = require('App:Knoin'),
LocalStorage = require('Storage:LocalStorage'), Local = require('Storage:LocalStorage'),
Settings = require('Storage:Settings'), Settings = require('Storage:Settings'),
Data = require('Storage:RainLoop:Data'), Data = require('Storage:RainLoop:Data'),
Cache = require('Storage:RainLoop:Cache'), Cache = require('Storage:RainLoop:Cache'),
@ -1185,7 +1185,7 @@
}); });
} }
LocalStorage.set(Enums.ClientSideKeyName.FoldersLashHash, oData.Result.FoldersHash); Local.set(Enums.ClientSideKeyName.FoldersLashHash, oData.Result.FoldersHash);
} }
}; };
@ -1195,8 +1195,8 @@
*/ */
RainLoopApp.prototype.isFolderExpanded = function (sFullNameHash) RainLoopApp.prototype.isFolderExpanded = function (sFullNameHash)
{ {
var aExpandedList = LocalStorage.get(Enums.ClientSideKeyName.ExpandedFolders); var aExpandedList = Local.get(Enums.ClientSideKeyName.ExpandedFolders);
return _.isArray(aExpandedList) && -1 !== _.indexOf(aExpandedList, sFullNameHash); return Utils.isArray(aExpandedList) && -1 !== _.indexOf(aExpandedList, sFullNameHash);
}; };
/** /**
@ -1205,8 +1205,8 @@
*/ */
RainLoopApp.prototype.setExpandedFolder = function (sFullNameHash, bExpanded) RainLoopApp.prototype.setExpandedFolder = function (sFullNameHash, bExpanded)
{ {
var aExpandedList = LocalStorage.get(Enums.ClientSideKeyName.ExpandedFolders); var aExpandedList = Local.get(Enums.ClientSideKeyName.ExpandedFolders);
if (!_.isArray(aExpandedList)) if (!Utils.isArray(aExpandedList))
{ {
aExpandedList = []; aExpandedList = [];
} }
@ -1221,7 +1221,7 @@
aExpandedList = _.without(aExpandedList, sFullNameHash); aExpandedList = _.without(aExpandedList, sFullNameHash);
} }
LocalStorage.set(Enums.ClientSideKeyName.ExpandedFolders, aExpandedList); Local.set(Enums.ClientSideKeyName.ExpandedFolders, aExpandedList);
}; };
RainLoopApp.prototype.initLayoutResizer = function (sLeft, sRight, sClientSideKeyName) RainLoopApp.prototype.initLayoutResizer = function (sLeft, sRight, sClientSideKeyName)
@ -1232,7 +1232,7 @@
oLeft = $(sLeft), oLeft = $(sLeft),
oRight = $(sRight), oRight = $(sRight),
mLeftWidth = LocalStorage.get(sClientSideKeyName) || null, mLeftWidth = Local.get(sClientSideKeyName) || null,
fSetWidth = function (iWidth) { fSetWidth = function (iWidth) {
if (iWidth) if (iWidth)
@ -1256,7 +1256,7 @@
else else
{ {
oLeft.resizable('enable'); oLeft.resizable('enable');
var iWidth = Utils.pInt(LocalStorage.get(sClientSideKeyName)) || iMinWidth; var iWidth = Utils.pInt(Local.get(sClientSideKeyName)) || iMinWidth;
fSetWidth(iWidth > iMinWidth ? iWidth : iMinWidth); fSetWidth(iWidth > iMinWidth ? iWidth : iMinWidth);
} }
}, },
@ -1264,7 +1264,7 @@
fResizeFunction = function (oEvent, oObject) { fResizeFunction = function (oEvent, oObject) {
if (oObject && oObject.size && oObject.size.width) if (oObject && oObject.size && oObject.size.width)
{ {
LocalStorage.set(sClientSideKeyName, oObject.size.width); Local.set(sClientSideKeyName, oObject.size.width);
oRight.css({ oRight.css({
'left': '' + oObject.size.width + 'px' 'left': '' + oObject.size.width + 'px'

View file

@ -67,7 +67,7 @@
* @const * @const
* @type {string} * @type {string}
*/ */
Consts.Values.ClientSideCookieIndexName = 'rlcsc'; Consts.Values.ClientSideStorageIndexName = 'rlcsc';
/** /**
* @const * @const

View file

@ -10,10 +10,10 @@
Utils = require('Utils'), Utils = require('Utils'),
Settings = require('Storage:Settings'), Settings = require('Storage:Settings'),
LocalStorage = require('Storage:LocalStorage'),
Data = require('Storage:RainLoop:Data'), Data = require('Storage:RainLoop:Data'),
Cache = require('Storage:RainLoop:Cache'), Cache = require('Storage:RainLoop:Cache'),
Remote = require('Storage:RainLoop:Remote') Remote = require('Storage:RainLoop:Remote'),
LocalStorage = require('Storage:LocalStorage')
; ;
/** /**

View file

@ -11,8 +11,8 @@
{ {
var var
NextStorageDriver = require('_').find([ NextStorageDriver = require('_').find([
require('Storage:LocalStorage:Cookie'), require('Storage:LocalStorage:LocalStorage'),
require('Storage:LocalStorage:LocalStorage') require('Storage:LocalStorage:Cookie')
], function (NextStorageDriver) { ], function (NextStorageDriver) {
return NextStorageDriver && NextStorageDriver.supported(); return NextStorageDriver && NextStorageDriver.supported();
}) })
@ -26,6 +26,9 @@
} }
} }
/**
* @type {LocalStorageDriver|CookieDriver|null}
*/
LocalStorage.prototype.oDriver = null; LocalStorage.prototype.oDriver = null;
/** /**

View file

@ -17,37 +17,46 @@
*/ */
function CookieDriver() function CookieDriver()
{ {
} }
/**
* @static
* @return {boolean}
*/
CookieDriver.supported = function () CookieDriver.supported = function ()
{ {
return true; return !!(window.navigator && window.navigator.cookieEnabled);
}; };
/** /**
* @param {string} sKey * @param {string} sKey
* @param {*} mData * @param {*} mData
* @returns {boolean} * @return {boolean}
*/ */
CookieDriver.prototype.set = function (sKey, mData) CookieDriver.prototype.set = function (sKey, mData)
{ {
var var
mCokieValue = $.cookie(Consts.Values.ClientSideCookieIndexName), mStorageValue = $.cookie(Consts.Values.ClientSideStorageIndexName),
bResult = false, bResult = false,
mResult = null mResult = null
; ;
try try
{ {
mResult = null === mCokieValue ? null : JSON.parse(mCokieValue); mResult = null === mStorageValue ? null : JSON.parse(mStorageValue);
if (!mResult) }
{ catch (oException) {}
mResult = {};
}
mResult[sKey] = mData; if (!mResult)
$.cookie(Consts.Values.ClientSideCookieIndexName, JSON.stringify(mResult), { {
mResult = {};
}
mResult[sKey] = mData;
try
{
$.cookie(Consts.Values.ClientSideStorageIndexName, JSON.stringify(mResult), {
'expires': 30 'expires': 30
}); });
@ -60,18 +69,18 @@
/** /**
* @param {string} sKey * @param {string} sKey
* @returns {*} * @return {*}
*/ */
CookieDriver.prototype.get = function (sKey) CookieDriver.prototype.get = function (sKey)
{ {
var var
mCokieValue = $.cookie(Consts.Values.ClientSideCookieIndexName), mStorageValue = $.cookie(Consts.Values.ClientSideStorageIndexName),
mResult = null mResult = null
; ;
try try
{ {
mResult = null === mCokieValue ? null : JSON.parse(mCokieValue); mResult = null === mStorageValue ? null : JSON.parse(mStorageValue);
if (mResult && !Utils.isUnd(mResult[sKey])) if (mResult && !Utils.isUnd(mResult[sKey]))
{ {
mResult = mResult[sKey]; mResult = mResult[sKey];

View file

@ -19,6 +19,10 @@
{ {
} }
/**
* @static
* @return {boolean}
*/
LocalStorageDriver.supported = function () LocalStorageDriver.supported = function ()
{ {
return !!window.localStorage; return !!window.localStorage;
@ -27,26 +31,32 @@
/** /**
* @param {string} sKey * @param {string} sKey
* @param {*} mData * @param {*} mData
* @returns {boolean} * @return {boolean}
*/ */
LocalStorageDriver.prototype.set = function (sKey, mData) LocalStorageDriver.prototype.set = function (sKey, mData)
{ {
var var
mCookieValue = window.localStorage[Consts.Values.ClientSideCookieIndexName] || null, mStorageValue = window.localStorage[Consts.Values.ClientSideStorageIndexName] || null,
bResult = false, bResult = false,
mResult = null mResult = null
; ;
try try
{ {
mResult = null === mCookieValue ? null : JSON.parse(mCookieValue); mResult = null === mStorageValue ? null : JSON.parse(mStorageValue);
if (!mResult) }
{ catch (oException) {}
mResult = {};
}
mResult[sKey] = mData; if (!mResult)
window.localStorage[Consts.Values.ClientSideCookieIndexName] = JSON.stringify(mResult); {
mResult = {};
}
mResult[sKey] = mData;
try
{
window.localStorage[Consts.Values.ClientSideStorageIndexName] = JSON.stringify(mResult);
bResult = true; bResult = true;
} }
@ -57,18 +67,18 @@
/** /**
* @param {string} sKey * @param {string} sKey
* @returns {*} * @return {*}
*/ */
LocalStorageDriver.prototype.get = function (sKey) LocalStorageDriver.prototype.get = function (sKey)
{ {
var var
mCokieValue = window.localStorage[Consts.Values.ClientSideCookieIndexName] || null, mStorageValue = window.localStorage[Consts.Values.ClientSideStorageIndexName] || null,
mResult = null mResult = null
; ;
try try
{ {
mResult = null === mCokieValue ? null : JSON.parse(mCokieValue); mResult = null === mStorageValue ? null : JSON.parse(mStorageValue);
if (mResult && !Utils.isUnd(mResult[sKey])) if (mResult && !Utils.isUnd(mResult[sKey]))
{ {
mResult = mResult[sKey]; mResult = mResult[sKey];

View file

@ -637,7 +637,7 @@
filter: Alpha(Opacity=30); filter: Alpha(Opacity=30);
} }
/*! normalize.css 2012-03-11T12:53 UTC - http://github.com/necolas/normalize.css */ /*! normalize.css 2012-03-11T12:53 UTC - http://github.com/necolas/normalize.css */
/* ============================================================================= /* =============================================================================
@ -1150,7 +1150,7 @@ table {
border-spacing: 0; border-spacing: 0;
border-collapse: collapse; border-collapse: collapse;
} }
@charset "UTF-8"; @charset "UTF-8";
@font-face { @font-face {
@ -1522,7 +1522,7 @@ table {
.icon-resize-out:before { .icon-resize-out:before {
content: "\e06d"; content: "\e06d";
} }
/** initial setup **/ /** initial setup **/
.nano { .nano {
/* /*
@ -1638,7 +1638,7 @@ table {
.nano > .pane2.active > .slider2 { .nano > .pane2.active > .slider2 {
background-color: rgba(0, 0, 0, 0.4); background-color: rgba(0, 0, 0, 0.4);
} }
/* Magnific Popup CSS */ /* Magnific Popup CSS */
.mfp-bg { .mfp-bg {
position: fixed; position: fixed;
@ -2094,7 +2094,7 @@ img.mfp-img {
padding-top: 0; padding-top: 0;
} }
/* overlay at start */ /* overlay at start */
.mfp-fade.mfp-bg { .mfp-fade.mfp-bg {
@ -2135,7 +2135,7 @@ img.mfp-img {
-ms-transform: translateX(50px); -ms-transform: translateX(50px);
transform: translateX(50px); transform: translateX(50px);
} }
.simple-pace { .simple-pace {
pointer-events: none; pointer-events: none;
@ -2210,7 +2210,7 @@ img.mfp-img {
transform: translate(-32px, 0); transform: translate(-32px, 0);
transform: translate(-32px, 0); transform: translate(-32px, 0);
} }
} }
.inputosaurus-container { .inputosaurus-container {
display: inline-block; display: inline-block;
margin: 0 5px 0 0; margin: 0 5px 0 0;
@ -2275,7 +2275,7 @@ img.mfp-img {
.inputosaurus-input-hidden { .inputosaurus-input-hidden {
display: none; display: none;
} }
.flag-wrapper { .flag-wrapper {
display: inline-block; display: inline-block;
width: 24px; width: 24px;
@ -2401,7 +2401,7 @@ img.mfp-img {
.flag.flag-zh-cn, .flag.flag-zh-cn,
.flag.flag-zh-hk { .flag.flag-zh-hk {
background-position: -208px -22px; background-position: -208px -22px;
} }
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */ /* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
.clearfix { .clearfix {
*zoom: 1; *zoom: 1;

View file

@ -743,7 +743,7 @@
* @const * @const
* @type {string} * @type {string}
*/ */
Consts.Values.ClientSideCookieIndexName = 'rlcsc'; Consts.Values.ClientSideStorageIndexName = 'rlcsc';
/** /**
* @const * @const

File diff suppressed because one or more lines are too long

View file

@ -300,7 +300,7 @@
kn = require('App:Knoin'), kn = require('App:Knoin'),
LocalStorage = require('Storage:LocalStorage'), Local = require('Storage:LocalStorage'),
Settings = require('Storage:Settings'), Settings = require('Storage:Settings'),
Data = require('Storage:RainLoop:Data'), Data = require('Storage:RainLoop:Data'),
Cache = require('Storage:RainLoop:Cache'), Cache = require('Storage:RainLoop:Cache'),
@ -1466,7 +1466,7 @@
}); });
} }
LocalStorage.set(Enums.ClientSideKeyName.FoldersLashHash, oData.Result.FoldersHash); Local.set(Enums.ClientSideKeyName.FoldersLashHash, oData.Result.FoldersHash);
} }
}; };
@ -1476,8 +1476,8 @@
*/ */
RainLoopApp.prototype.isFolderExpanded = function (sFullNameHash) RainLoopApp.prototype.isFolderExpanded = function (sFullNameHash)
{ {
var aExpandedList = LocalStorage.get(Enums.ClientSideKeyName.ExpandedFolders); var aExpandedList = Local.get(Enums.ClientSideKeyName.ExpandedFolders);
return _.isArray(aExpandedList) && -1 !== _.indexOf(aExpandedList, sFullNameHash); return Utils.isArray(aExpandedList) && -1 !== _.indexOf(aExpandedList, sFullNameHash);
}; };
/** /**
@ -1486,8 +1486,8 @@
*/ */
RainLoopApp.prototype.setExpandedFolder = function (sFullNameHash, bExpanded) RainLoopApp.prototype.setExpandedFolder = function (sFullNameHash, bExpanded)
{ {
var aExpandedList = LocalStorage.get(Enums.ClientSideKeyName.ExpandedFolders); var aExpandedList = Local.get(Enums.ClientSideKeyName.ExpandedFolders);
if (!_.isArray(aExpandedList)) if (!Utils.isArray(aExpandedList))
{ {
aExpandedList = []; aExpandedList = [];
} }
@ -1502,7 +1502,7 @@
aExpandedList = _.without(aExpandedList, sFullNameHash); aExpandedList = _.without(aExpandedList, sFullNameHash);
} }
LocalStorage.set(Enums.ClientSideKeyName.ExpandedFolders, aExpandedList); Local.set(Enums.ClientSideKeyName.ExpandedFolders, aExpandedList);
}; };
RainLoopApp.prototype.initLayoutResizer = function (sLeft, sRight, sClientSideKeyName) RainLoopApp.prototype.initLayoutResizer = function (sLeft, sRight, sClientSideKeyName)
@ -1513,7 +1513,7 @@
oLeft = $(sLeft), oLeft = $(sLeft),
oRight = $(sRight), oRight = $(sRight),
mLeftWidth = LocalStorage.get(sClientSideKeyName) || null, mLeftWidth = Local.get(sClientSideKeyName) || null,
fSetWidth = function (iWidth) { fSetWidth = function (iWidth) {
if (iWidth) if (iWidth)
@ -1537,7 +1537,7 @@
else else
{ {
oLeft.resizable('enable'); oLeft.resizable('enable');
var iWidth = Utils.pInt(LocalStorage.get(sClientSideKeyName)) || iMinWidth; var iWidth = Utils.pInt(Local.get(sClientSideKeyName)) || iMinWidth;
fSetWidth(iWidth > iMinWidth ? iWidth : iMinWidth); fSetWidth(iWidth > iMinWidth ? iWidth : iMinWidth);
} }
}, },
@ -1545,7 +1545,7 @@
fResizeFunction = function (oEvent, oObject) { fResizeFunction = function (oEvent, oObject) {
if (oObject && oObject.size && oObject.size.width) if (oObject && oObject.size && oObject.size.width)
{ {
LocalStorage.set(sClientSideKeyName, oObject.size.width); Local.set(sClientSideKeyName, oObject.size.width);
oRight.css({ oRight.css({
'left': '' + oObject.size.width + 'px' 'left': '' + oObject.size.width + 'px'
@ -2131,7 +2131,7 @@
* @const * @const
* @type {string} * @type {string}
*/ */
Consts.Values.ClientSideCookieIndexName = 'rlcsc'; Consts.Values.ClientSideStorageIndexName = 'rlcsc';
/** /**
* @const * @const
@ -11718,10 +11718,10 @@ module.exports = window;
Utils = require('Utils'), Utils = require('Utils'),
Settings = require('Storage:Settings'), Settings = require('Storage:Settings'),
LocalStorage = require('Storage:LocalStorage'),
Data = require('Storage:RainLoop:Data'), Data = require('Storage:RainLoop:Data'),
Cache = require('Storage:RainLoop:Cache'), Cache = require('Storage:RainLoop:Cache'),
Remote = require('Storage:RainLoop:Remote') Remote = require('Storage:RainLoop:Remote'),
LocalStorage = require('Storage:LocalStorage')
; ;
/** /**
@ -14735,8 +14735,8 @@ module.exports = window;
{ {
var var
NextStorageDriver = require('_').find([ NextStorageDriver = require('_').find([
require('Storage:LocalStorage:Cookie'), require('Storage:LocalStorage:LocalStorage'),
require('Storage:LocalStorage:LocalStorage') require('Storage:LocalStorage:Cookie')
], function (NextStorageDriver) { ], function (NextStorageDriver) {
return NextStorageDriver && NextStorageDriver.supported(); return NextStorageDriver && NextStorageDriver.supported();
}) })
@ -14750,6 +14750,9 @@ module.exports = window;
} }
} }
/**
* @type {LocalStorageDriver|CookieDriver|null}
*/
LocalStorage.prototype.oDriver = null; LocalStorage.prototype.oDriver = null;
/** /**
@ -14794,37 +14797,46 @@ module.exports = window;
*/ */
function CookieDriver() function CookieDriver()
{ {
} }
/**
* @static
* @return {boolean}
*/
CookieDriver.supported = function () CookieDriver.supported = function ()
{ {
return true; return !!(window.navigator && window.navigator.cookieEnabled);
}; };
/** /**
* @param {string} sKey * @param {string} sKey
* @param {*} mData * @param {*} mData
* @returns {boolean} * @return {boolean}
*/ */
CookieDriver.prototype.set = function (sKey, mData) CookieDriver.prototype.set = function (sKey, mData)
{ {
var var
mCokieValue = $.cookie(Consts.Values.ClientSideCookieIndexName), mStorageValue = $.cookie(Consts.Values.ClientSideStorageIndexName),
bResult = false, bResult = false,
mResult = null mResult = null
; ;
try try
{ {
mResult = null === mCokieValue ? null : JSON.parse(mCokieValue); mResult = null === mStorageValue ? null : JSON.parse(mStorageValue);
if (!mResult) }
{ catch (oException) {}
mResult = {};
}
mResult[sKey] = mData; if (!mResult)
$.cookie(Consts.Values.ClientSideCookieIndexName, JSON.stringify(mResult), { {
mResult = {};
}
mResult[sKey] = mData;
try
{
$.cookie(Consts.Values.ClientSideStorageIndexName, JSON.stringify(mResult), {
'expires': 30 'expires': 30
}); });
@ -14837,18 +14849,18 @@ module.exports = window;
/** /**
* @param {string} sKey * @param {string} sKey
* @returns {*} * @return {*}
*/ */
CookieDriver.prototype.get = function (sKey) CookieDriver.prototype.get = function (sKey)
{ {
var var
mCokieValue = $.cookie(Consts.Values.ClientSideCookieIndexName), mStorageValue = $.cookie(Consts.Values.ClientSideStorageIndexName),
mResult = null mResult = null
; ;
try try
{ {
mResult = null === mCokieValue ? null : JSON.parse(mCokieValue); mResult = null === mStorageValue ? null : JSON.parse(mStorageValue);
if (mResult && !Utils.isUnd(mResult[sKey])) if (mResult && !Utils.isUnd(mResult[sKey]))
{ {
mResult = mResult[sKey]; mResult = mResult[sKey];
@ -14888,6 +14900,10 @@ module.exports = window;
{ {
} }
/**
* @static
* @return {boolean}
*/
LocalStorageDriver.supported = function () LocalStorageDriver.supported = function ()
{ {
return !!window.localStorage; return !!window.localStorage;
@ -14896,26 +14912,32 @@ module.exports = window;
/** /**
* @param {string} sKey * @param {string} sKey
* @param {*} mData * @param {*} mData
* @returns {boolean} * @return {boolean}
*/ */
LocalStorageDriver.prototype.set = function (sKey, mData) LocalStorageDriver.prototype.set = function (sKey, mData)
{ {
var var
mCookieValue = window.localStorage[Consts.Values.ClientSideCookieIndexName] || null, mStorageValue = window.localStorage[Consts.Values.ClientSideStorageIndexName] || null,
bResult = false, bResult = false,
mResult = null mResult = null
; ;
try try
{ {
mResult = null === mCookieValue ? null : JSON.parse(mCookieValue); mResult = null === mStorageValue ? null : JSON.parse(mStorageValue);
if (!mResult) }
{ catch (oException) {}
mResult = {};
}
mResult[sKey] = mData; if (!mResult)
window.localStorage[Consts.Values.ClientSideCookieIndexName] = JSON.stringify(mResult); {
mResult = {};
}
mResult[sKey] = mData;
try
{
window.localStorage[Consts.Values.ClientSideStorageIndexName] = JSON.stringify(mResult);
bResult = true; bResult = true;
} }
@ -14926,18 +14948,18 @@ module.exports = window;
/** /**
* @param {string} sKey * @param {string} sKey
* @returns {*} * @return {*}
*/ */
LocalStorageDriver.prototype.get = function (sKey) LocalStorageDriver.prototype.get = function (sKey)
{ {
var var
mCokieValue = window.localStorage[Consts.Values.ClientSideCookieIndexName] || null, mStorageValue = window.localStorage[Consts.Values.ClientSideStorageIndexName] || null,
mResult = null mResult = null
; ;
try try
{ {
mResult = null === mCokieValue ? null : JSON.parse(mCokieValue); mResult = null === mStorageValue ? null : JSON.parse(mStorageValue);
if (mResult && !Utils.isUnd(mResult[sKey])) if (mResult && !Utils.isUnd(mResult[sKey]))
{ {
mResult = mResult[sKey]; mResult = mResult[sKey];

File diff suppressed because one or more lines are too long