Skip to content

Instantly share code, notes, and snippets.

@stugoo
Created May 16, 2012 15:54
Show Gist options
  • Save stugoo/2711536 to your computer and use it in GitHub Desktop.
Save stugoo/2711536 to your computer and use it in GitHub Desktop.
session / local storage switcher
shortlistings = {
storeInSession: true,
killFunctions : function() {
// kill the functions
}
setStorage : function(type,store) {
var JSON_str = '';
JSON_str = JSON.stringify(store);
if( shortlistBar.storeInSession ) {
sessionStorage.setItem(type, JSON_str); // session storage
} else {
localStorage.setItem(type, JSON_str); //local storage
}
},
getStorage : function(type) {
var store;
if( shortlistBar.storeInSession ) {
store = sessionStorage.getItem(type) || null;//session storage
} else {
store = localStorage.getItem(type) || null; //local storage
}
return store;
},
sessionManagement: function() {
// clear all storage
$('input[name=cookieSettings]').change(function() {
var radio = $('input[name=cookieSettings]:checked').val();
if ((setting === 'permanent') || (setting === undefined)) {
shortlistBar.storeInSession = false // localStorage
} else if ((setting === 'session') || (setting === undefined)) {
shortlistBar.storeInSession = true // sessionStorage
} else if ((radio === 'off') ) {
if (confirm('are you sure you wish to delete all cookies/storage?')) {
sessionStorage.clear();
localStorage.clear(); // empty storage
shortlistBar.killFunctions(); // kill all the functions!
}
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment