1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-30 05:31:58 +02:00

Implement functionality for feature-detecting webStorage

This commit is contained in:
Tim Daubenschütz 2015-10-28 17:53:26 +01:00
parent 5788e77501
commit c7ef23ee40

View File

@ -23,4 +23,39 @@
* @type {bool} Is drag and drop available on this browser
*/
export const dragAndDropAvailable = 'draggable' in document.createElement('div') &&
!/Mobile|Android|Slick\/|Kindle|BlackBerry|Opera Mini|Opera Mobi/i.test(navigator.userAgent);
!/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');
}