mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
Implement functionality for feature-detecting webStorage
This commit is contained in:
parent
5788e77501
commit
c7ef23ee40
@ -24,3 +24,38 @@
|
||||
*/
|
||||
export const dragAndDropAvailable = 'draggable' in document.createElement('div') &&
|
||||
!/Mobile|Android|Slick\/|Kindle|BlackBerry|Opera Mini|Opera Mobi/i.test(navigator.userAgent);
|
||||
|
||||
/**
|
||||
* Function that detects whether localStorage/sessionStorage is both supported
|
||||
* and available.
|
||||
* Taken from:
|
||||
* https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API
|
||||
*
|
||||
* We're explicitly NOT exporting this function, as we want for both localStorage, as well as
|
||||
* sessionStorage proxy functions to be exported.
|
||||
*
|
||||
* @param {oneOfType(['localStorage', 'sessionStorage'])}
|
||||
* @return {bool} Is localStorage or sessionStorage available on this browser
|
||||
*/
|
||||
function storageAvailable(type) {
|
||||
try {
|
||||
var storage = window[type],
|
||||
x = '__storage_test__';
|
||||
storage.setItem(x, x);
|
||||
storage.removeItem(x);
|
||||
return true;
|
||||
}
|
||||
catch(e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function detects whether sessionStorage is both supported
|
||||
* and available.
|
||||
* @return {bool} Is sessionStorage available on this browser
|
||||
*/
|
||||
export function sessionStorageAvailable() {
|
||||
return storageAvailable('sessionStorage');
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user