Last active
August 29, 2015 14:24
-
-
Save stricte/d48e678b39351eb2f942 to your computer and use it in GitHub Desktop.
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
| jQuery(function(){ | |
| $.fn.formBackUp = function() { | |
| if(!localStorage) { | |
| return false; | |
| } | |
| var form = this; | |
| var datas = {}; | |
| var ls = null; | |
| datas.href = document.location.href; | |
| if(localStorage['formBackUp']) { | |
| ls = JSON.parse(localStorage['formBackUp']); | |
| if(ls.href == datas.href) { | |
| for(var id in ls) { | |
| if(id != 'href') { | |
| $('#'+id).val(ls[id]); | |
| datas[id] = ls.id; | |
| } | |
| } | |
| } | |
| } | |
| form.find('input, textarea').keyup(function(e){ | |
| datas[$(this).attr('id')] = $(this).val(); | |
| localStorage.setItem('formBackUp', JSON.stringify(datas)); | |
| }); | |
| form.submit(function(e){ | |
| localStorage.removeItem('formBackUp'); | |
| }); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment