Commit 9d7451b2 authored by Tristan Cavelier's avatar Tristan Cavelier

LocalOrCookieStorage removed

parent 995d1278
......@@ -60,7 +60,7 @@ jIO is separated in 2 parts, core library and storage library(ies). The core mus
Getting started
---------------
This short tutorial is designed to help you get started using jIO. First, download the jIO core and the jIO storages scripts (git clone http://git.erp5.org/repos/jio.git) and their dependencies ([LocalOrCookieStorage](http://git.erp5.org/gitweb/jio.git/blob_plain/refs/heads/master:/src/localorcookiestorage.js), [jQuery](http://jquery.com), [base64](http://www.webtoolkit.info/javascript-base64.html), [sjcl](http://crypto.stanford.edu/sjcl/), [sha2](http://anmar.eu.org/projects/jssha2/)). Then, add the scripts in your HTML page as following:
This short tutorial is designed to help you get started using jIO. First, download the jIO core and the jIO storages scripts (git clone http://git.erp5.org/repos/jio.git) and their dependencies ([jQuery](http://jquery.com), [base64](http://www.webtoolkit.info/javascript-base64.html), [sjcl](http://crypto.stanford.edu/sjcl/), [sha2](http://anmar.eu.org/projects/jssha2/)). Then, add the scripts in your HTML page as following:
```
<!-- jIO Core -->
......
......@@ -137,7 +137,6 @@ var clearlog = function () {
<hr />
<div id="log">
</div>
<script type="text/javascript" src="../localorcookiestorage.js"></script>
<script type="text/javascript" src="../lib/md5/md5.js"></script>
<script type="text/javascript" src="../jio.js"></script>
<script type="text/javascript" src="../lib/jquery/jquery.min.js"></script>
......
/*global module:false*/
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: '<json:package.json>',
meta: {
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - '+
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> Nexedi;' +
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
},
concat: {
dist: {
src: ['<banner:meta.banner>',
'<file_strip_banner:../../src/<%= pkg.name %>.js>'],
dest: '../../<%= pkg.name %>.js'
}
},
min: {
dist: {
src: ['<banner:meta.banner>', '<config:concat.dist.dest>'],
dest: '../../<%= pkg.name %>.min.js'
}
},
qunit: {
files: []
},
lint: {
files: ['grunt.js','../../src/<%= pkg.name %>.js']
},
watch: {
files: '<config:lint.files>',
tasks: 'lint'
},
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
browser: true
},
globals: {
jQuery: true,
LocalOrCookieStorage: true,
Base64: true,
JIO: true,
console: true,
unescape: true,
// Needed to avoid "not defined error" with requireJs
define: true,
require: true,
// Needed to avoid "not defined error" with sinonJs
sinon: true,
module: true,
test: true,
ok: true,
deepEqual: true,
expect: true,
stop: true,
start: true,
equal: true
}
},
uglify: {}
});
// Default task.
grunt.registerTask('default', 'lint concat min');
};
{
"name": "localorcookiestorage",
"title": "Local Or Cookie Storage",
"description": "A small API which can manipulate data into local persistent storage.",
"version": "0.1.0",
"homepage": "",
"author": {
"name": "Tristan Cavelier",
"email": "tristan.cavelier@tiolive.com"
},
"repository": {
"type": "git",
"url": "http://git.erp5.org/repos/jio.git"
},
"bugs": {
"url": ""
},
"licenses": [
],
"dependencies": {
},
"keywords": []
}
......@@ -58,7 +58,6 @@ module.exports = function(grunt) {
globals: {
jQuery: true,
sjcl: true,
LocalOrCookieStorage: true,
Base64: true,
MD5: true,
hex_sha256: true,
......
......@@ -87,7 +87,6 @@ module.exports = function(grunt) {
browser: true
},
globals: {
LocalOrCookieStorage: true,
hex_md5: true,
console: true,
unescape: true,
......
......@@ -37,9 +37,9 @@ var newIndexStorage = function ( spec, my ) {
};
priv.indexStorage = function () {
var obj = LocalOrCookieStorage.getItem (storage_object_name) || {};
var obj = localStorage.getItem (storage_object_name) || {};
obj[priv.secondstorage_spec] = new Date().getTime();
LocalOrCookieStorage.setItem (storage_object_name,obj);
localStorage.setItem (storage_object_name,obj);
};
priv.formatToFileObject = function (row) {
......@@ -68,24 +68,24 @@ var newIndexStorage = function ( spec, my ) {
for (i = 0; i < file_array.length; i+= 1) {
obj[file_array[i].id] = priv.formatToFileObject(file_array[i]);
}
LocalOrCookieStorage.setItem (storage_file_object_name,obj);
localStorage.setItem (storage_file_object_name,obj);
};
priv.getFileObject = function (docid) {
var obj = LocalOrCookieStorage.getItem (storage_file_object_name) || {};
var obj = localStorage.getItem (storage_file_object_name) || {};
return obj[docid];
};
priv.addFile = function (file_obj) {
var obj = LocalOrCookieStorage.getItem (storage_file_object_name) || {};
var obj = localStorage.getItem (storage_file_object_name) || {};
obj[file_obj._id] = file_obj;
LocalOrCookieStorage.setItem (storage_file_object_name,obj);
localStorage.setItem (storage_file_object_name,obj);
};
priv.removeFile = function (docid) {
var obj = LocalOrCookieStorage.getItem (storage_file_object_name) || {};
var obj = localStorage.getItem (storage_file_object_name) || {};
delete obj[docid];
LocalOrCookieStorage.setItem (storage_file_object_name,obj);
localStorage.setItem (storage_file_object_name,obj);
};
/**
......@@ -167,7 +167,7 @@ var newIndexStorage = function ( spec, my ) {
* @method allDocs
*/
that.allDocs = function (command) {
var obj = LocalOrCookieStorage.getItem (storage_file_object_name);
var obj = localStorage.getItem (storage_file_object_name);
if (obj) {
priv.update();
setTimeout(function (){
......
......@@ -90,7 +90,7 @@ var jobManager = (function(spec) {
clearInterval(priv.interval_id);
priv.interval_id = null;
if (priv.job_array.length === 0) {
localstorage.deleteItem(priv.getJobArrayName());
localstorage.removeItem(priv.getJobArrayName());
}
}
};
......@@ -159,7 +159,7 @@ var jobManager = (function(spec) {
}
}
localstorage.setItem('jio/id_array',new_array);
localstorage.deleteItem('jio/id/'+id);
localstorage.removeItem('jio/id/'+id);
};
/**
......@@ -168,7 +168,7 @@ var jobManager = (function(spec) {
* @param {number} id The jio id.
*/
priv.removeJobArrayFromJioId = function(id) {
localstorage.deleteItem('jio/job_array/'+id);
localstorage.removeItem('jio/job_array/'+id);
};
/**
......
var LocalOrCookieStorage =
(function () { var local_cookie_loader_function = function () {
// localorcookiestorage.js
// Creates an object that can store persistent information in localStorage.
// If it is not supported by the browser, it will store in cookies.
// Methods :
// - LocalOrCookieStorage.setItem('name',value);
// Sets an item with its value.
// - LocalOrCookieStorage.getItem('name');
// Returns a copy of the item.
// - LocalOrCookieStorage.deleteItem('name');
// Deletes an item forever.
// - LocalOrCookieStorage.getAll();
// Returns a new object containing all items and their values.
////////////////////////////////////////////////////////////////////////////
// cookies & localStorage
var BrowserStorage = function () {
};
BrowserStorage.prototype = {
getItem: function (name) {
return JSON.parse(localStorage.getItem(name));
},
setItem: function (name,value) {
if (name) {
return localStorage.setItem(name,JSON.stringify(value));
}
},
getAll: function() {
return localStorage;
},
deleteItem: function (name) {
if (name) {
delete localStorage[name];
}
}
};
var CookieStorage = function () {
};
CookieStorage.prototype = {
getItem: function (name) {
var cookies = document.cookie.split(';'), i;
for (i = 0; i < cookies.length; i += 1) {
var x = cookies[i].substr(0, cookies[i].indexOf('=')),
y = cookies[i].substr(cookies[i].indexOf('=')+1);
x = x.replace(/^\s+|\s+$/g,"");
if( x === name ) { return unescape(y); }
}
return null;
},
setItem: function (name,value) {
// function to store into cookies
if (value !== undefined) {
document.cookie = name+'='+JSON.stringify(value)+';domain='+
window.location.hostname+
';path='+window.location.pathname;
return true;
}
return false;
},
getAll: function() {
var retObject = {}, i,
cookies = document.cookie.split(':');
for (i = 0; i < cookies.length; i += 1) {
var x = cookies[i].substr(0, cookies[i].indexOf('=')),
y = cookies[i].substr(cookies[i].indexOf('=')+1);
x = x.replace(/^\s+|\s+$/g,"");
retObject[x] = unescape(y);
}
return retObject;
},
deleteItem: function (name) {
document.cookie = name+'=null;domain='+window.location.hostname+
';path='+window.location.pathname+
';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
};
// set good localStorage
try {
if (localStorage.getItem) {
return new BrowserStorage();
} else {
return new CookieStorage();
}
}
catch (e) {
return new CookieStorage();
}
// end cookies & localStorages
////////////////////////////////////////////////////////////////////////////
};
if (window.requirejs) {
define ('LocalOrCookieStorage',[], local_cookie_loader_function);
return undefined;
} else {
return local_cookie_loader_function ();
}
}());
var LocalOrCookieStorage = (function () {
var tmp = function () {
this.storage = {};
};
tmp.prototype = {
getItem: function (k) {
var v = (typeof this.storage[k] === 'undefined' ?
null: this.storage[k]);
return JSON.parse (v);
},
setItem: function (k,v) {
this.storage[k] = JSON.stringify (v);
},
deleteItem: function (k) {
delete this.storage[k];
},
getAll: function () {
return this.storage;
}
};
return new tmp();
}());
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