Some improvements for local storage on IE.

This commit is contained in:
Martin Edenhofer 2012-11-27 03:07:59 +01:00
parent a07b137b8a
commit a24c632cbf

View file

@ -30,13 +30,27 @@ class App.Store
# The actual Singleton class
class _Singleton
store: {}
constructor: ->
@support = true
if !window.localStorage
@support = false
# @support = false
# write to local storage
write: (key, value) ->
localStorage.setItem( key, JSON.stringify( value ) )
@store[key] = value
return if !@support
try
localStorage.setItem( key, JSON.stringify( value ) )
catch e
if e is QUOTA_EXCEEDED_ERR
# do something nice to notify your users
App.Log.log 'App.Store', 'error', 'Local storage quote exceeded, please relogin!'
# get item
get: (key) ->
return @store[key] if !@support
value = localStorage.getItem( key )
return if !value
object = JSON.parse( value )
@ -44,18 +58,28 @@ class _Singleton
# delete item
delete: (key) ->
@store.delete key
return if !@support
localStorage.removeItem( key )
# clear local storage
clear: ->
@store = {}
localStorage.clear()
# return list of all keys
list: ->
list = []
logLength = localStorage.length-1;
for count in [0..logLength]
key = localStorage.key( count )
if key
if !@support
for key of @store
list.push key
return list
# logLength = localStorage.length-1;
# for count in [0..logLength]
# key = localStorage.key( count )
# if key
# list.push key
for key of window.localStorage
list.push key
list