This repository has been archived on 2024-04-29. You can view files and clone it, but cannot push or open issues or pull requests.
node-fftcg/src/index/localStorage.coffee

22 lines
606 B
CoffeeScript
Raw Normal View History

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