Created
February 2, 2014 17:18
-
-
Save christianjul/8771586 to your computer and use it in GitHub Desktop.
Very generic but working implementation of session storage fallback for safari in privacy mode
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
submission = { | |
handle: function (event) { | |
event.preventDefault(); | |
event.stopPropagation(); | |
var id, | |
data, | |
storage = submission.getStorage(), | |
nextUrl; | |
data = storage.getItem('Opeepl'); | |
if (data === null) { | |
data = {}; | |
} else { | |
data = JSON.parse(data); | |
} | |
id = $('[name*=__identity]').val(); | |
data[id] = $(this).serializeArray(); | |
storage.setItem('Opeepl', JSON.stringify(data)); | |
nextUrl = OPEEPL.next(data[id]); | |
if (nextUrl) { | |
window.location.replace(nextUrl); | |
} else { | |
storage.clear(); | |
OPEEPL.submit(data); | |
} | |
return false; | |
}, | |
sessionStorageAvailable: function () { | |
var storageTestKey = 'sTest', | |
storage = sessionStorage; | |
try { | |
storage.setItem(storageTestKey, 'test'); | |
storage.removeItem(storageTestKey); | |
return true; | |
} catch (e) { | |
// Just in case this isnt only ios specific we log it | |
// if (e.code !== 22 && storage.length === 0) { | |
// throw e; | |
// } | |
track(e); | |
return false; | |
} | |
}, | |
getStorage: function () { | |
var storage; | |
if (submission.sessionStorageAvailable()) { | |
storage = sessionStorage; | |
} else { | |
storage = { | |
getItem: function (name) { | |
var value; | |
//just ignore name for now | |
if (window.name.length === 0) { | |
value = null; | |
} else { | |
value = window.name; | |
} | |
return value; | |
}, | |
setItem: function (name, data) { | |
window.name = data; | |
}, | |
clear: function () { | |
window.name = ''; | |
} | |
}; | |
} | |
return storage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
part of larger script, but shows the concept.