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

View file

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

View file

@ -10,10 +10,10 @@
Utils = require('Utils'),
Settings = require('Storage:Settings'),
LocalStorage = require('Storage:LocalStorage'),
Data = require('Storage:RainLoop:Data'),
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
NextStorageDriver = require('_').find([
require('Storage:LocalStorage:Cookie'),
require('Storage:LocalStorage:LocalStorage')
require('Storage:LocalStorage:LocalStorage'),
require('Storage:LocalStorage:Cookie')
], function (NextStorageDriver) {
return NextStorageDriver && NextStorageDriver.supported();
})
@ -26,6 +26,9 @@
}
}
/**
* @type {LocalStorageDriver|CookieDriver|null}
*/
LocalStorage.prototype.oDriver = null;
/**

View file

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

View file

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

View file

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

View file

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

File diff suppressed because one or more lines are too long

View file

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

File diff suppressed because one or more lines are too long