Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Nicolas Wavrant
jio
Commits
543a7490
Commit
543a7490
authored
Feb 27, 2015
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to use sessionStorage.
parent
bb18e075
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
14 deletions
+43
-14
src/jio.storage/localstorage.js
src/jio.storage/localstorage.js
+17
-11
test/jio.storage/localstorage.tests.js
test/jio.storage/localstorage.tests.js
+26
-3
No files found.
src/jio.storage/localstorage.js
View file @
543a7490
...
...
@@ -5,7 +5,7 @@
*/
/*jslint nomen: true */
/*global jIO, localStorage, Blob, RSVP */
/*global jIO,
sessionStorage,
localStorage, Blob, RSVP */
/**
* JIO Local Storage. Type = 'local'.
...
...
@@ -14,17 +14,22 @@
* Storage Description:
*
* {
* "type": "local"
* "type": "local",
* "sessiononly": false
* }
*
* @class LocalStorage
*/
(
function
(
jIO
,
localStorage
,
Blob
,
RSVP
)
{
(
function
(
jIO
,
sessionStorage
,
localStorage
,
Blob
,
RSVP
)
{
"
use strict
"
;
function
LocalStorage
()
{
return
;
function
LocalStorage
(
spec
)
{
if
(
spec
.
sessiononly
===
true
)
{
this
.
_storage
=
sessionStorage
;
}
else
{
this
.
_storage
=
localStorage
;
}
}
function
restrictDocumentId
(
id
)
{
...
...
@@ -42,8 +47,8 @@
found
=
false
,
key
;
for
(
key
in
localS
torage
)
{
if
(
localS
torage
.
hasOwnProperty
(
key
))
{
for
(
key
in
this
.
_s
torage
)
{
if
(
this
.
_s
torage
.
hasOwnProperty
(
key
))
{
attachments
[
key
]
=
{};
found
=
true
;
}
...
...
@@ -57,7 +62,7 @@
LocalStorage
.
prototype
.
getAttachment
=
function
(
param
)
{
restrictDocumentId
(
param
.
_id
);
var
textstring
=
localS
torage
.
getItem
(
param
.
_attachment
);
var
textstring
=
this
.
_s
torage
.
getItem
(
param
.
_attachment
);
if
(
textstring
===
null
)
{
throw
new
jIO
.
util
.
jIOError
(
...
...
@@ -69,6 +74,7 @@
};
LocalStorage
.
prototype
.
putAttachment
=
function
(
param
)
{
var
context
=
this
;
restrictDocumentId
(
param
.
_id
);
// the document already exists
...
...
@@ -78,13 +84,13 @@
return
jIO
.
util
.
readBlobAsText
(
param
.
_blob
);
})
.
push
(
function
(
e
)
{
localS
torage
.
setItem
(
param
.
_attachment
,
e
.
target
.
result
);
context
.
_s
torage
.
setItem
(
param
.
_attachment
,
e
.
target
.
result
);
});
};
LocalStorage
.
prototype
.
removeAttachment
=
function
(
param
)
{
restrictDocumentId
(
param
.
_id
);
return
localS
torage
.
removeItem
(
param
.
_attachment
);
return
this
.
_s
torage
.
removeItem
(
param
.
_attachment
);
};
...
...
@@ -101,4 +107,4 @@
jIO
.
addStorage
(
'
local
'
,
LocalStorage
);
}(
jIO
,
localStorage
,
Blob
,
RSVP
));
}(
jIO
,
sessionStorage
,
localStorage
,
Blob
,
RSVP
));
test/jio.storage/localstorage.tests.js
View file @
543a7490
/*jslint nomen: true */
/*global localStorage, Blob, document*/
(
function
(
jIO
,
localStorage
,
QUnit
,
Blob
,
document
)
{
/*global
sessionStorage,
localStorage, Blob, document*/
(
function
(
jIO
,
sessionStorage
,
localStorage
,
QUnit
,
Blob
,
document
)
{
"
use strict
"
;
var
test
=
QUnit
.
test
,
stop
=
QUnit
.
stop
,
...
...
@@ -11,6 +11,29 @@
equal
=
QUnit
.
equal
,
module
=
QUnit
.
module
;
/////////////////////////////////////////////////////////////////
// localStorage.constructor
/////////////////////////////////////////////////////////////////
module
(
"
localStorage.constructor
"
);
test
(
"
local storage by default
"
,
function
()
{
var
jio
=
jIO
.
createJIO
({
type
:
"
local
"
});
equal
(
jio
.
__type
,
"
local
"
);
equal
(
jio
.
__storage
.
_storage
,
localStorage
);
});
test
(
"
sessiononly
"
,
function
()
{
var
jio
=
jIO
.
createJIO
({
type
:
"
local
"
,
sessiononly
:
true
});
equal
(
jio
.
__type
,
"
local
"
);
equal
(
jio
.
__storage
.
_storage
,
sessionStorage
);
});
/////////////////////////////////////////////////////////////////
// localStorage.get
/////////////////////////////////////////////////////////////////
...
...
@@ -429,4 +452,4 @@
});
});
}(
jIO
,
localStorage
,
QUnit
,
Blob
,
document
));
}(
jIO
,
sessionStorage
,
localStorage
,
QUnit
,
Blob
,
document
));
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment