text: // garlic 1.2.4 + pull request #68
  !function(b){var h=function(a){this.defined="undefined"!==typeof localStorage};h.prototype={constructor:h,get:function(a,b){return localStorage.getItem(a)?localStorage.getItem(a):"undefined"!==typeof b?b:null},has:function(a){return localStorage.getItem(a)?!0:!1},set:function(a,b,d){"string"===typeof b&&(""===b?this.destroy(a):localStorage.setItem(a,b));return"function"===typeof d?d():!0},destroy:function(a,b){localStorage.removeItem(a);return"function"===typeof b?b():!0},clean:function(a){for(var b=
  localStorage.length-1;0<=b;b--)"undefined"===typeof Array.indexOf&&-1!==localStorage.key(b).indexOf("garlic:")&&localStorage.removeItem(localStorage.key(b));return"function"===typeof a?a():!0},clear:function(a){localStorage.clear();return"function"===typeof a?a():!0}};var k=function(a,b,d){this.init("garlic",a,b,d)};k.prototype={constructor:k,init:function(a,c,d,e){this.type=a;this.$element=b(c);this.options=this.getOptions(e);this.storage=d;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?!1:(this.$element.data("expires")?this.path:this.getPath(this.parentForm))+"_flag";this.$element.on(this.options.events.join("."+this.type+" "),!1,b.proxy(this.persist,this));if(this.options.destroy)b(this.parentForm).on("submit reset",!1,b.proxy(this.destroy,this));this.retrieve()},getOptions:function(a){return b.extend({},b.fn[this.type].defaults,a,this.$element.data())},
  persist:function(){this.val!==this.getVal()&&(this.val=this.getVal(),this.options.expires&&this.storage.set(this.expiresFlag,((new Date).getTime()+1E3*this.options.expires).toString()),this.storage.set(this.path,this.getVal()),this.options.onPersist(this.$element,this.getVal()))},getVal:function(){return!this.$element.is("input[type=checkbox]")?this.$element.val():this.$element.prop("checked")?"checked":"unchecked"},retrieve:function(){if(this.storage.has(this.path)){if(this.options.expires){var a=
  (new Date).getTime();if(this.storage.get(this.expiresFlag)<a.toString()){this.storage.destroy(this.path);return}this.$element.attr("expires-in",Math.floor((parseInt(this.storage.get(this.expiresFlag))-a)/1E3))}a=this.storage.get(this.path);if(this.options.conflictManager.enabled&&this.detectConflict())return this.conflictManager();if(this.$element.is("input[type=radio], input[type=checkbox]")){if("checked"===a||this.$element.val()===a)return this.$element.attr("checked",!0);"unchecked"===a&&this.$element.attr("checked",
  !1)}else this.$element.val(a),this.$element.trigger("input"),this.options.onRetrieve(this.$element,a)}},detectConflict:function(){var a=this;if(this.$element.is("input[type=checkbox], input[type=radio]"))return!1;if(this.$element.val()&&this.storage.get(this.path)!==this.$element.val()){if(this.$element.is("select")){var c=!1;this.$element.find("option").each(function(){0!==b(this).index()&&(b(this).attr("selected")&&b(this).val()!==a.storage.get(this.path))&&(c=!0)});return c}return!0}return!1},
  conflictManager:function(){if("function"===typeof this.options.conflictManager.onConflictDetected&&!this.options.conflictManager.onConflictDetected(this.$element,this.storage.get(this.path)))return!1;this.options.conflictManager.garlicPriority?(this.$element.data("swap-data",this.$element.val()),this.$element.data("swap-state","garlic"),this.$element.val(this.storage.get(this.path))):(this.$element.data("swap-data",this.storage.get(this.path)),this.$element.data("swap-state","default"));this.swapHandler();
  this.$element.addClass("garlic-conflict-detected");this.$element.closest("input[type=submit]").attr("disabled",!0)},swapHandler:function(){var a=b(this.options.conflictManager.template);this.$element.after(a.text(this.options.conflictManager.message));a.on("click",!1,b.proxy(this.swap,this))},swap:function(){var a=this.$element.data("swap-data");this.$element.data("swap-state","garlic"===this.$element.data("swap-state")?"default":"garlic");this.$element.data("swap-data",this.$element.val());b(this.$element).val(a)},
  destroy:function(){this.storage.destroy(this.path)},remove:function(){this.remove();this.$element.is("input[type=radio], input[type=checkbox]")?b(this.$element).prop("checked",!1):this.$element.val("")},getPath:function(a){"undefined"===typeof a&&(a=this.$element);if(this.options.getPath(a))return this.options.getPath(a);if(1!=a.length)return!1;for(var c="",d=a.is("input[type=checkbox]"),e=a;e.length;){a=e[0];var f=a.nodeName;if(!f)break;var f=f.toLowerCase(),e=e.parent(),g=e.children(f);if(b(a).is("form, input, select, textarea")||
  d)if(f+=b(a).attr("name")?"."+b(a).attr("name"):"",1<g.length&&!b(a).is("input[type=radio]")&&(f+=":eq("+g.index(a)+")"),c=f+(c?">"+c:""),"form"==a.nodeName.toLowerCase())break}return"garlic:"+document.domain+(this.options.domain?"*":window.location.pathname)+window.location.hash+">"+c},getStorage:function(){return this.storage}};b.fn.garlic=function(a,c){function d(c){var d=b(c),g=d.data("garlic"),h=b.extend({},e,d.data());if(("undefined"===typeof h.storage||h.storage)&&"password"!==b(c).attr("type"))if(g||d.data("garlic",
  g=new k(c,f,h)),"string"===typeof a&&"function"===typeof g[a])return g[a]()}var e=b.extend(!0,{},b.fn.garlic.defaults,a,this.data()),f=new h,g=!1;if(!f.defined)return!1;this.each(function(){b(this).is("form")?b(this).find(e.inputs).each(function(){b(this).is(e.excluded)||(g=d(b(this)))}):b(this).is(e.inputs)&&!b(this).is(e.excluded)&&(g=d(b(this)))});return"function"===typeof c?c():g};b.fn.garlic.Constructor=k;b.fn.garlic.defaults={destroy:!0,inputs:"input, textarea, select",excluded:'input[type="file"], input[type="hidden"], input[type="submit"]',
  events:"DOMAttrModified textInput input change click keypress paste focus".split(" "),domain:!1,expires:!1,conflictManager:{enabled:!1,garlicPriority:!0,template:'<span class="garlic-swap"></span>',message:"This is your saved data. Click here to see default one",onConflictDetected:function(a,b){return!0}},getPath:function(a){},onRetrieve:function(a,b){},onPersist:function(a,b){}};b(window).on("load",function(){b('[data-persist="garlic"]').each(function(){b(this).garlic()})})}(window.jQuery||window.Zepto);
  