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) {
*/
localstorage = {
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) {
return localStorage.setItem(item, JSON.stringify(value));
},
deleteItem: function (item) {
delete localStorage[item];
removeItem: function (item) {
return localStorage.removeItem(item);
}
};
......@@ -253,7 +254,7 @@ var newLocalStorage = function (spec, my) {
priv.localpath + "/" + command.getDocId());
if (typeof command.getAttachmentId() === "string") {
// seeking for an attachment
localstorage.deleteItem(
localstorage.removeItem(
priv.localpath + "/" + command.getDocId() + "/" +
command.getAttachmentId());
// remove attachment from document
......@@ -281,11 +282,11 @@ var newLocalStorage = function (spec, my) {
attachment_list.push(i);
}
}
localstorage.deleteItem(
localstorage.removeItem(
priv.localpath + "/" + command.getDocId());
// delete all attachments
for (i = 0; i < attachment_list.length; i += 1) {
localstorage.deleteItem(
localstorage.removeItem(
priv.localpath+"/"+command.getDocId()+"/"+
attachment_list[i]);
}
......
......@@ -4,12 +4,13 @@
if (typeof localStorage !== "undefined") {
localstorage = {
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) {
return localStorage.setItem(item, JSON.stringify(value));
},
deleteItem: function (item) {
removeItem: function (item) {
delete localStorage[item];
},
clone: function () {
......@@ -21,12 +22,14 @@
var pseudo_localStorage = {};
localstorage = {
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) {
return pseudo_localStorage[item] = JSON.stringify(value);
},
deleteItem: function (item) {
removeItem: function (item) {
delete pseudo_localStorage[item];
},
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