Commit 4a01d505 authored by Tristan Cavelier's avatar Tristan Cavelier

deleteItem from pseudo localStorages renamed to removeItem + fix "null" bug

parent 2f914bc0
...@@ -15,13 +15,14 @@ var newLocalStorage = function (spec, my) { ...@@ -15,13 +15,14 @@ var newLocalStorage = function (spec, my) {
*/ */
localstorage = { localstorage = {
getItem: function (item) { getItem: function (item) {
return JSON.parse(localStorage.getItem(item)); var value = localStorage.getItem(item);
return value === null? null: JSON.parse(value);
}, },
setItem: function (item, value) { setItem: function (item, value) {
return localStorage.setItem(item, JSON.stringify(value)); return localStorage.setItem(item, JSON.stringify(value));
}, },
deleteItem: function (item) { removeItem: function (item) {
delete localStorage[item]; return localStorage.removeItem(item);
} }
}; };
...@@ -253,7 +254,7 @@ var newLocalStorage = function (spec, my) { ...@@ -253,7 +254,7 @@ var newLocalStorage = function (spec, my) {
priv.localpath + "/" + command.getDocId()); priv.localpath + "/" + command.getDocId());
if (typeof command.getAttachmentId() === "string") { if (typeof command.getAttachmentId() === "string") {
// seeking for an attachment // seeking for an attachment
localstorage.deleteItem( localstorage.removeItem(
priv.localpath + "/" + command.getDocId() + "/" + priv.localpath + "/" + command.getDocId() + "/" +
command.getAttachmentId()); command.getAttachmentId());
// remove attachment from document // remove attachment from document
...@@ -281,11 +282,11 @@ var newLocalStorage = function (spec, my) { ...@@ -281,11 +282,11 @@ var newLocalStorage = function (spec, my) {
attachment_list.push(i); attachment_list.push(i);
} }
} }
localstorage.deleteItem( localstorage.removeItem(
priv.localpath + "/" + command.getDocId()); priv.localpath + "/" + command.getDocId());
// delete all attachments // delete all attachments
for (i = 0; i < attachment_list.length; i += 1) { for (i = 0; i < attachment_list.length; i += 1) {
localstorage.deleteItem( localstorage.removeItem(
priv.localpath+"/"+command.getDocId()+"/"+ priv.localpath+"/"+command.getDocId()+"/"+
attachment_list[i]); attachment_list[i]);
} }
......
...@@ -4,12 +4,13 @@ ...@@ -4,12 +4,13 @@
if (typeof localStorage !== "undefined") { if (typeof localStorage !== "undefined") {
localstorage = { localstorage = {
getItem: function (item) { getItem: function (item) {
return JSON.parse(localStorage.getItem(item)); var value = localStorage.getItem(item);
return value === null? null: JSON.parse(value);
}, },
setItem: function (item, value) { setItem: function (item, value) {
return localStorage.setItem(item, JSON.stringify(value)); return localStorage.setItem(item, JSON.stringify(value));
}, },
deleteItem: function (item) { removeItem: function (item) {
delete localStorage[item]; delete localStorage[item];
}, },
clone: function () { clone: function () {
...@@ -21,12 +22,14 @@ ...@@ -21,12 +22,14 @@
var pseudo_localStorage = {}; var pseudo_localStorage = {};
localstorage = { localstorage = {
getItem: function (item) { getItem: function (item) {
return JSON.parse(pseudo_localStorage[item]); var value = pseudo_localStorage[item];
return value === undefined?
null: JSON.parse(pseudo_localStorage[item]);
}, },
setItem: function (item, value) { setItem: function (item, value) {
return pseudo_localStorage[item] = JSON.stringify(value); return pseudo_localStorage[item] = JSON.stringify(value);
}, },
deleteItem: function (item) { removeItem: function (item) {
delete pseudo_localStorage[item]; delete pseudo_localStorage[item];
}, },
clone: function () { clone: function () {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment