Created
May 20, 2015 18:32
-
-
Save nicocedron/004dd723a464893e5390 to your computer and use it in GitHub Desktop.
Use localStorage in Incognito mode using UnderScore, jQuery Cookie.
This file contains hidden or 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
hasStorage = -> | |
try | |
mod = new Date | |
localStorage.setItem mod, mod.toString() | |
result = localStorage.getItem(mod) == mod.toString() | |
localStorage.removeItem mod | |
return result | |
if !hasStorage() | |
window.CustomStorage = | |
length: 0 | |
setItem: (item, val)-> | |
@[item] = val | |
$.cookie(item, val); | |
@length+= 1 | |
getItem: (item)-> | |
@[item] | |
removeItem: (item)-> | |
delete @[item] | |
$.removeCookie(item); | |
@length-= 1 | |
window.CustomStorage = _.extend(window.CustomStorage, $.cookie()); | |
window.CustomStorage.length = Object.keys(window.CustomStorage).length - 4 | |
window.CustomSessionStorage = {} | |
else | |
window.CustomStorage = localStorage; | |
window.CustomSessionStorage = sessionStorage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment