Commit effc66a8 authored by Tristan Cavelier's avatar Tristan Cavelier

localstorage.js amd compatible now

parent b56a8a06
/*
* Copyright 2013, Nexedi SA
* Released under the LGPL license.
* http://www.gnu.org/licenses/lgpl.html
*/
* Copyright 2013, Nexedi SA
* Released under the LGPL license.
* http://www.gnu.org/licenses/lgpl.html
*/
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global jIO: true, localStorage: true, setTimeout: true,
complex_queries: true */
complex_queries, define */
/**
* JIO Local Storage. Type = 'local'.
......@@ -43,7 +43,18 @@
*
* @class LocalStorage
*/
jIO.addStorageType('local', function (spec, my) {
// define([module_name], [dependencies], module);
(function (dependencies, module) {
"use strict";
if (typeof define === 'function' && define.amd) {
return define(dependencies, module);
}
module(jIO, complex_queries);
}(['jio', 'complex_queries'], function (jIO, complex_queries) {
"use strict";
jIO.addStorageType('local', function (spec, my) {
spec = spec || {};
var that, priv, localstorage;
......@@ -240,7 +251,9 @@ jIO.addStorageType('local', function (spec, my) {
*/
that.get = function (command) {
setTimeout(function () {
var doc = localstorage.getItem(priv.localpath + "/" + command.getDocId());
var doc = localstorage.getItem(
priv.localpath + "/" + command.getDocId()
);
if (doc !== null) {
that.success(doc);
} else {
......@@ -262,8 +275,10 @@ jIO.addStorageType('local', function (spec, my) {
*/
that.getAttachment = function (command) {
setTimeout(function () {
var doc = localstorage.getItem(priv.localpath + "/" + command.getDocId() +
"/" + command.getAttachmentId());
var doc = localstorage.getItem(
priv.localpath + "/" + command.getDocId() +
"/" + command.getAttachmentId()
);
if (doc !== null) {
that.success(doc);
} else {
......@@ -370,7 +385,9 @@ jIO.addStorageType('local', function (spec, my) {
* @param {object} command The JIO command
*/
that.allDocs = function (command) {
var i, row, path_re, rows = [], document_list = [], option, document_object;
var i, row, path_re, rows, document_list, option, document_object;
rows = [];
document_list = [];
path_re = new RegExp(
"^" + complex_queries.stringEscapeRegexpCharacters(priv.localpath) +
"/[^/]+$"
......@@ -434,4 +451,5 @@ jIO.addStorageType('local', function (spec, my) {
};
return that;
});
});
}));
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