-
-
Save xergioalex/974c2e286f4c3c26b8a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Utils = { | |
// Detect if support local storage | |
supports_html5_storage: function () { | |
try { | |
localStorage.setItem('testKey', 'test'); | |
localStorage.removeItem('testKey'); | |
return true; | |
} catch (e) { | |
return false; | |
} | |
}, | |
// Save data in browser | |
saveDataInBrowser: function (key, data) { | |
if (this.supports_html5_storage()) { | |
localStorage.setItem(key, data); | |
} else { | |
$.cookie(key, data, { path: '/' }); | |
} | |
}, | |
// Save data in browser | |
getDataFromBrowser: function (key) { | |
if (this.supports_html5_storage()) { | |
return localStorage.getItem(key); | |
} else { | |
return $.cookie('laboratoryBackup'); | |
} | |
}, | |
// Remove data in browser | |
removeDataInBrowser: function (key) { | |
if (this.supports_html5_storage()) { | |
localStorage.removeItem(key); | |
} else { | |
$.removeCookie('key', { path: '/' }); | |
} | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment