!function(t){"use strict";var e=function(t){this.defined="undefined"!=typeof localStorage;var e="garlic:"+document.domain+">test";try{localStorage.setItem(e,e),localStorage.removeItem(e)}catch(t){this.defined=!1}};e.prototype={constructor:e,get:function(t,e){var i=localStorage.getItem(t);if(i){try{i=JSON.parse(i)}catch(t){}return i}return void 0!==e?e:null},has:function(t){return!!localStorage.getItem(t)},set:function(t,e,i){return""===e||e instanceof Array&&0===e.length?this.destroy(t):(e=JSON.stringify(e),localStorage.setItem(t,e)),"function"!=typeof i||i()},destroy:function(t,e){return localStorage.removeItem(t),"function"!=typeof e||e()},clean:function(t){for(var e=localStorage.length-1;e>=0;e--)void 0===Array.indexOf&&-1!==localStorage.key(e).indexOf("garlic:")&&localStorage.removeItem(localStorage.key(e));return"function"!=typeof t||t()},clear:function(t){return localStorage.clear(),"function"!=typeof t||t()}};var i=function(t,e,i){this.init("garlic",t,e,i)};i.prototype={constructor:i,init:function(e,i,n,s){this.type=e,this.$element=t(i),this.options=this.getOptions(s),this.storage=n,this.path=this.options.getPath(this.$element)||this.getPath(),this.parentForm=this.$element.closest("form"),this.$element.addClass("garlic-auto-save"),this.expiresFlag=!!this.options.expires&&(this.$element.data("expires")?this.path:this.getPath(this.parentForm))+"_flag",this.$element.on(this.options.events.join("."+this.type+" "),!1,t.proxy(this.persist,this)),this.options.destroy&&t(this.parentForm).on("submit reset",!1,t.proxy(this.destroy,this)),this.retrieve()},getOptions:function(e){return t.extend({},t.fn[this.type].defaults,e,this.$element.data())},persist:function(){if(this.val!==this.getVal()){this.val=this.getVal(),this.options.expires&&this.storage.set(this.expiresFlag,((new Date).getTime()+1e3*this.options.expires).toString());var t=this.options.prePersist(this.$element,this.val);"string"==typeof t&&(this.val=t),this.storage.set(this.path,this.val),this.options.onPersist(this.$element,this.val)}},getVal:function(){return this.$element.is("input[type=checkbox]")?this.$element.prop("checked")?"checked":"unchecked":this.$element.val()},retrieve:function(){if(this.storage.has(this.path)){if(this.options.expires){var t=(new Date).getTime();if(this.storage.get(this.expiresFlag)1&&!t(a).is("input[type=radio]")&&(o+=":eq("+h.index(a)+")"),i=o+(i?">"+i:""),"form"==a.nodeName.toLowerCase())break;s=r}else s=r}return"garlic:"+document.domain+(this.options.domain?"*":window.location.pathname)+">"+i},getStorage:function(){return this.storage}},t.fn.garlic=function(n,s){var a=t.extend(!0,{},t.fn.garlic.defaults,n,this.data()),o=new e,r=!1;if(!o.defined)return!1;function h(e){var s=t(e),r=s.data("garlic"),h=t.extend({},a,s.data());if((void 0===h.storage||h.storage)&&"password"!==t(e).attr("type"))return r||s.data("garlic",r=new i(e,o,h)),"string"==typeof n&&"function"==typeof r[n]?r[n]():void 0}return this.each(function(){if(t(this).is("form"))t(this).find(a.inputs).each(function(){t(this).is(a.excluded)||(r=h(t(this)))});else if(t(this).is(a.inputs)){if(t(this).is(a.excluded))return;r=h(t(this))}}),"function"==typeof s?s():r},t.fn.garlic.Constructor=i,t.fn.garlic.defaults={destroy:!0,inputs:"input, textarea, select",excluded:'input[type="file"], input[type="hidden"], input[type="submit"], input[type="reset"]',events:["DOMAttrModified","textInput","input","change","click","keypress","paste","focus"],domain:!1,expires:!1,conflictManager:{enabled:!1,garlicPriority:!0,template:'',message:"This is your saved data. Click here to see default one",onConflictDetected:function(t,e){return!0}},getPath:function(t){},preRetrieve:function(t,e,i){return i},onRetrieve:function(t,e){},prePersist:function(t,e){return!1},onPersist:function(t,e){},onSwap:function(t,e,i){}},t(window).on("load",function(){t('[data-persist="garlic"]').each(function(){t(this).garlic()})})}(window.jQuery||window.Zepto);