forked from simsalabim/sisyphus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsisyphus.min.js
1 lines (1 loc) · 2.12 KB
/
sisyphus.min.js
1
(function(a){function k(){try{return"localStorage"in window&&window["localStorage"]!==null}catch(a){return false}}function j(a,b,c,d){var e=false;a.each(function(){var a=c+b[0].id+this.name;localStorage.removeItem(a);e=true});if(e&&typeof d.onReleaseDataCallback=="function"){d.onReleaseDataCallback.call()}}function i(a,b,c,d){b.submit(function(){j(a,b,c,d)});b.bind("reset",function(){j(a,b,c,d)})}function h(b,c,d){b.onchange=function(){var e=a(b).val();if(b.type=="checkbox"){if(b.name.indexOf("[")!=-1){e=[];a('[name="'+b.name+'"]:checked').each(function(){e.push(this.value)})}else{e=a(b).is(":checked")}}if(b.type=="radio"){e=b.value}try{localStorage.setItem(c,e)}catch(f){}if(typeof d.onSaveCallback=="function"){d.onSaveCallback.call()}}}function g(a,b,c){setTimeout(function(a){function d(){try{localStorage.setItem(b,a.value)}catch(e){}if(typeof c.onSaveCallback=="function"){c.onSaveCallback.call()}setTimeout(d,c.timeout*1e3)}return d}(a),c.timeout*1e3)}function f(a,b,c){a.oninput=function(){try{localStorage.setItem(b,a.value)}catch(d){}if(typeof c.onSaveCallback=="function"){c.onSaveCallback.call()}}}function e(b,c,d){if(a(b).is(":text")||a(b).is("textarea")){if(!d.timeout){f(b,c,d)}else{g(b,c,d)}}else{h(b,c,d)}}function d(b,c,d){if(b.type=="checkbox"&&c!="false"&&b.name.indexOf("[")==-1){b.checked=true}else if(b.type=="radio"){if(b.value==c){a(b).attr("checked","checked")}}else if(b.name.indexOf("[")==-1){b.value=c}else{c=c.split(",");a(b).val(c)}}function c(a,b,c,f){var g=false;a.each(function(){var a=c+b[0].id+this.name+f.customKeyPrefix;var h=localStorage.getItem(a);if(h){d(this,h,f);g=true}e(this,a,f)});if(g&&typeof f.onRestoreCallback=="function"){f.onRestoreCallback.call()}}function b(b,d){if(!k()){return false}console.log(d);var e=window.location.hostname+window.location.pathname+window.location.search;a(b).each(function(){var b=a(this);var f=b.find(":input");c(f,b,e,d);i(f,b,e,d)})}a.fn.sisyphus=function(c){c=a.extend(a.fn.sisyphus.defaults,c);b(this,c)};a.fn.sisyphus.defaults={excludeFields:null,customKeyPrefix:"",timeout:0,onSaveCallback:function(){},onRestoreCallback:function(){},onReleaseDataCallback:function(){}}})(jQuery)