Created
May 16, 2012 15:54
-
-
Save stugoo/2711536 to your computer and use it in GitHub Desktop.
session / local storage switcher
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
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