Commit b5f2b208 authored by Tristan Cavelier's avatar Tristan Cavelier

removing dependency localorcookiestorage

parent 818282cd
...@@ -9,4 +9,4 @@ ...@@ -9,4 +9,4 @@
* *
* @module JIOStorages * @module JIOStorages
*/ */
(function(LocalOrCookieStorage, $, Base64, sjcl, hex_sha256, jIO) { (function (jIO, $, Base64, sjcl, hex_sha256) {
}( LocalOrCookieStorage, jQuery, Base64, sjcl, hex_sha256, jIO )); }(jIO, jQuery, Base64, sjcl, hex_sha256));
...@@ -14,7 +14,7 @@ var activityUpdater = (function(spec, my) { ...@@ -14,7 +14,7 @@ var activityUpdater = (function(spec, my) {
* @method touch * @method touch
*/ */
priv.touch = function() { priv.touch = function() {
LocalOrCookieStorage.setItem ('jio/id/'+priv.id, Date.now()); localstorage.setItem ('jio/id/'+priv.id, Date.now());
}; };
/** /**
...@@ -72,4 +72,3 @@ var activityUpdater = (function(spec, my) { ...@@ -72,4 +72,3 @@ var activityUpdater = (function(spec, my) {
return that; return that;
}()); }());
var jIO = (function () { (function (scope, hex_md5) {
"use strict"; "use strict";
var localstorage;
if (typeof localStorage !== "undefined") {
localstorage = {
getItem: function (item) {
return JSON.parse(localStorage.getItem(item));
},
setItem: function (item, value) {
return localStorage.setItem(item, JSON.stringify(value));
},
deleteItem: function (item) {
delete localStorage[item];
},
clone: function () {
return JSON.parse(JSON.stringify(localStorage));
}
};
} else {
(function () {
var pseudo_localStorage = {};
localstorage = {
getItem: function (item) {
return JSON.parse(pseudo_localStorage[item]);
},
setItem: function (item, value) {
return pseudo_localStorage[item] = JSON.stringify(value);
},
deleteItem: function (item) {
delete pseudo_localStorage[item];
},
clone: function () {
return JSON.parse(JSON.stringify(pseudo_localStorage));
}
};
}());
}
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// Initialize the jio id and add the new id to the list // Initialize the jio id and add the new id to the list
if (priv.id === null) { if (priv.id === null) {
var i, jio_id_a = var i, jio_id_a =
LocalOrCookieStorage.getItem (jio_id_array_name) || []; localstorage.getItem (jio_id_array_name) || [];
priv.id = 1; priv.id = 1;
for (i = 0; i < jio_id_a.length; i+= 1) { for (i = 0; i < jio_id_a.length; i+= 1) {
if (jio_id_a[i] >= priv.id) { if (jio_id_a[i] >= priv.id) {
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
} }
} }
jio_id_a.push(priv.id); jio_id_a.push(priv.id);
LocalOrCookieStorage.setItem (jio_id_array_name,jio_id_a); localstorage.setItem (jio_id_array_name,jio_id_a);
activityUpdater.setId(priv.id); activityUpdater.setId(priv.id);
jobManager.setId(priv.id); jobManager.setId(priv.id);
} }
......
...@@ -25,7 +25,7 @@ var jobManager = (function(spec) { ...@@ -25,7 +25,7 @@ var jobManager = (function(spec) {
* @return {array} The job array. * @return {array} The job array.
*/ */
priv.getJobArray = function() { priv.getJobArray = function() {
return LocalOrCookieStorage.getItem(priv.getJobArrayName())||[]; return localstorage.getItem(priv.getJobArrayName())||[];
}; };
/** /**
...@@ -37,7 +37,7 @@ var jobManager = (function(spec) { ...@@ -37,7 +37,7 @@ var jobManager = (function(spec) {
for (i = 0; i < priv.job_array.length; i+= 1) { for (i = 0; i < priv.job_array.length; i+= 1) {
new_a.push(priv.job_array[i].serialized()); new_a.push(priv.job_array[i].serialized());
} }
LocalOrCookieStorage.setItem(priv.getJobArrayName(),new_a); localstorage.setItem(priv.getJobArrayName(),new_a);
}; };
/** /**
...@@ -90,7 +90,7 @@ var jobManager = (function(spec) { ...@@ -90,7 +90,7 @@ var jobManager = (function(spec) {
clearInterval(priv.interval_id); clearInterval(priv.interval_id);
priv.interval_id = null; priv.interval_id = null;
if (priv.job_array.length === 0) { if (priv.job_array.length === 0) {
LocalOrCookieStorage.deleteItem(priv.getJobArrayName()); localstorage.deleteItem(priv.getJobArrayName());
} }
} }
}; };
...@@ -105,7 +105,7 @@ var jobManager = (function(spec) { ...@@ -105,7 +105,7 @@ var jobManager = (function(spec) {
var i, jio_id_a; var i, jio_id_a;
priv.lastrestore = priv.lastrestore || 0; priv.lastrestore = priv.lastrestore || 0;
if (priv.lastrestore > (Date.now()) - 2000) { return; } if (priv.lastrestore > (Date.now()) - 2000) { return; }
jio_id_a = LocalOrCookieStorage.getItem('jio/id_array')||[]; jio_id_a = localstorage.getItem('jio/id_array')||[];
for (i = 0; i < jio_id_a.length; i+= 1) { for (i = 0; i < jio_id_a.length; i+= 1) {
priv.restoreOldJioId(jio_id_a[i]); priv.restoreOldJioId(jio_id_a[i]);
} }
...@@ -119,7 +119,7 @@ var jobManager = (function(spec) { ...@@ -119,7 +119,7 @@ var jobManager = (function(spec) {
*/ */
priv.restoreOldJioId = function(id) { priv.restoreOldJioId = function(id) {
var jio_date; var jio_date;
jio_date = LocalOrCookieStorage.getItem('jio/id/'+id)||0; jio_date = localstorage.getItem('jio/id/'+id)||0;
if (new Date(jio_date).getTime() < (Date.now() - 10000)) { // 10 sec if (new Date(jio_date).getTime() < (Date.now() - 10000)) { // 10 sec
priv.restoreOldJobFromJioId(id); priv.restoreOldJobFromJioId(id);
priv.removeOldJioId(id); priv.removeOldJioId(id);
...@@ -134,7 +134,7 @@ var jobManager = (function(spec) { ...@@ -134,7 +134,7 @@ var jobManager = (function(spec) {
*/ */
priv.restoreOldJobFromJioId = function(id) { priv.restoreOldJobFromJioId = function(id) {
var i, jio_job_array; var i, jio_job_array;
jio_job_array = LocalOrCookieStorage.getItem('jio/job_array/'+id)||[]; jio_job_array = localstorage.getItem('jio/job_array/'+id)||[];
for (i = 0; i < jio_job_array.length; i+= 1) { for (i = 0; i < jio_job_array.length; i+= 1) {
var command_object = command(jio_job_array[i].command); var command_object = command(jio_job_array[i].command);
if (command_object.canBeRestored()) { if (command_object.canBeRestored()) {
...@@ -152,14 +152,14 @@ var jobManager = (function(spec) { ...@@ -152,14 +152,14 @@ var jobManager = (function(spec) {
*/ */
priv.removeOldJioId = function(id) { priv.removeOldJioId = function(id) {
var i, jio_id_array, new_array = []; var i, jio_id_array, new_array = [];
jio_id_array = LocalOrCookieStorage.getItem('jio/id_array')||[]; jio_id_array = localstorage.getItem('jio/id_array')||[];
for (i = 0; i < jio_id_array.length; i+= 1) { for (i = 0; i < jio_id_array.length; i+= 1) {
if (jio_id_array[i] !== id) { if (jio_id_array[i] !== id) {
new_array.push(jio_id_array[i]); new_array.push(jio_id_array[i]);
} }
} }
LocalOrCookieStorage.setItem('jio/id_array',new_array); localstorage.setItem('jio/id_array',new_array);
LocalOrCookieStorage.deleteItem('jio/id/'+id); localstorage.deleteItem('jio/id/'+id);
}; };
/** /**
...@@ -168,7 +168,7 @@ var jobManager = (function(spec) { ...@@ -168,7 +168,7 @@ var jobManager = (function(spec) {
* @param {number} id The jio id. * @param {number} id The jio id.
*/ */
priv.removeJobArrayFromJioId = function(id) { priv.removeJobArrayFromJioId = function(id) {
LocalOrCookieStorage.deleteItem('jio/job_array/'+id); localstorage.deleteItem('jio/job_array/'+id);
}; };
/** /**
......
return jioNamespace; Object.defineProperty(scope,"jIO",{
}()); configurable:false,enumerable:false,writable:false,value:jioNamespace
});
}(window, hex_md5));
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