22 lines
606 B
CoffeeScript
22 lines
606 B
CoffeeScript
|
|
window.storageAvailable = (type) ->
|
||
|
|
try
|
||
|
|
storage = window[type]
|
||
|
|
x = '__storage_test__'
|
||
|
|
storage.setItem x, x
|
||
|
|
storage.removeItem x
|
||
|
|
true
|
||
|
|
|
||
|
|
catch e
|
||
|
|
e instanceof DOMException and
|
||
|
|
# everything except Firefox
|
||
|
|
(e.code == 22 or
|
||
|
|
# Firefox
|
||
|
|
e.code == 1014 or
|
||
|
|
# test name field too, because code might not be present
|
||
|
|
# everything except Firefox
|
||
|
|
e.name == 'QuotaExceededError' or
|
||
|
|
# Firefox
|
||
|
|
e.name == 'NS_ERROR_DOM_QUOTA_REACHED') and
|
||
|
|
# acknowledge QuotaExceededError only if there's something already stored
|
||
|
|
storage.length != 0
|