Create utils.js

This commit is contained in:
Silver Kuusik 2018-07-08 20:52:44 +02:00 committed by GitHub
parent acb9effd52
commit 1331408a39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

24
assets/js/utils.js Normal file
View File

@ -0,0 +1,24 @@
// Function to get data from localStorage
function getLocalStorageItem(item) {
// When cookies are disabled
if (!cookiesEnabled) return "";
// Try to get data from localStorage
try {
return localStorage.getItem(item);
// Failed to access localStorage
} catch {
// Return empty result
return "";
}
}
// Function to set data to local storage
function setLocalStorageItem(item, value) {
// When cookies are disabled
if (!cookiesEnabled) return;
// Try to save data to localStorage
try {
localStorage.setItem(item, value)
// Failed to access localStorage
} catch {}
}