Skip to content

Instantly share code, notes, and snippets.

@bryanpaluch
Created March 20, 2013 16:42
Show Gist options
  • Select an option

  • Save bryanpaluch/5206191 to your computer and use it in GitHub Desktop.

Select an option

Save bryanpaluch/5206191 to your computer and use it in GitHub Desktop.
localStorage all the things!
define([
localStorageHook,
], function(LocalStorageHook){
LocalStorageHook.hook();
});
#callform.row.center
label Phone or Email
input.stored#address(name="address", type="text", placeholder="Enter Phone or Email")
define([
'jquery',
], function($){
var hook = function(){
//Test if we have Local Storage
if(localStorage){
function init(){
$.each($('.stored'), function (){
input_name = $(this).attr('name');
if(localStorage[input_name]){
$(this).val(localStorage[input_name]);
}
});
}
init();
$('.stored').keyup(function(){
localStorage[$(this).attr('name')] = $(this).val();
});
}
}
return {hook:hook}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment