From 1331408a39fdab9dd1c973e30ac6af707ad0ded3 Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Sun, 8 Jul 2018 20:52:44 +0200 Subject: [PATCH] Create utils.js --- assets/js/utils.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 assets/js/utils.js diff --git a/assets/js/utils.js b/assets/js/utils.js new file mode 100644 index 0000000..14b34b1 --- /dev/null +++ b/assets/js/utils.js @@ -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 {} +}