Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- perf improvement on persist with redundant events

  • Loading branch information...
commit 6ab320097ec8ddad64bfac7d8e1da081e4511b91 1 parent 21a6387
Guillaume Potier authored
4 CHANGELOG.md
View
@@ -1,5 +1,9 @@
#Changelog
+* **1.1.1** :
+
+ - perf improvement on persist with redundant events
+
* **1.1.0** :
- added auto-expiration feature
2  README.md
View
@@ -10,7 +10,7 @@ http://garlicjs.org/
#Version
-1.1.0
+1.1.1
See CHANGELOG for more info.
22 dist/garlic-standalone.min.js
View
@@ -1,4 +1,4 @@
-/* Garlicjs dist/garlic-standalone.min.js build version 1.1.0 http://garlicjs.org */
+/* Garlicjs dist/garlic-standalone.min.js build version 1.1.1 http://garlicjs.org */
var Zepto=function(){function c(a){return"[object Function]"==M.call(a)}function j(a){return a instanceof Object}function t(a){return j(a)&&a.__proto__==Object.prototype}function e(a){return a instanceof Array}function f(a){return"number"==typeof a.length}function h(a){return a.replace(/::/g,"/").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/_/g,"-").toLowerCase()}function v(a){return a in B?B[a]:B[a]=RegExp("(^|\\s)"+a+"(\\s|$)")}function k(a){return"children"in
a?w.call(a.children):b.map(a.childNodes,function(a){if(1==a.nodeType)return a})}function m(a,b,d){for(q in b)d&&t(b[q])?(t(a[q])||(a[q]={}),m(a[q],b[q],d)):b[q]!==l&&(a[q]=b[q])}function n(a,r){return r===l?b(a):b(a).filter(r)}function i(a,b,d,g){return c(b)?b.call(a,d,g):b}function u(a,b){var d=a.className,c=d&&d.baseVal!==l;if(b===l)return c?d.baseVal:d;c?d.baseVal=b:a.className=b}function y(a){var r;try{return a?"true"==a||("false"==a?!1:"null"==a?null:isNaN(r=Number(a))?/^[\[\{]/.test(a)?b.parseJSON(a):
a:r):a}catch(d){return a}}function z(a,b){b(a);for(var d in a.childNodes)z(a.childNodes[d],b)}var l,q,b,g,o=[],w=o.slice,x=o.filter,s=window.document,C={},B={},D=s.defaultView.getComputedStyle,G={"column-count":1,columns:1,"font-weight":1,"line-height":1,opacity:1,"z-index":1,zoom:1},H=/^\s*<(\w+|!)[^>]*>/,N=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,I=/^(?:body|html)$/i,O="val css html text data width height offset".split(" "),E=s.createElement("table"),J=s.createElement("tr"),
@@ -35,13 +35,13 @@ function(c){return c?this.bind(b,c):this.trigger(b)}});["focus","blur"].forEach(
f){return void 0===f?c.isPlainObject(e)?this.each(function(f,i){c.each(e,function(c,e){t(i,c,e)})}):0==this.length?void 0:j(this[0],e):this.each(function(){t(this,e,f)})};c.fn.removeData=function(f){return"string"==typeof f&&(f=f.split(/\s+/)),this.each(function(){var m=this[v],n=m&&e[m];n&&c.each(f,function(){delete n[h(this)]})})}})(Zepto);
!function(c){var j=function(){this.defined="undefined"!==typeof localStorage};j.prototype={constructor:j,get:function(c,f){return localStorage.getItem(c)?localStorage.getItem(c):"undefined"!==typeof f?f:null},has:function(c){return localStorage.getItem(c)?!0:!1},set:function(c,f,h){"string"===typeof f&&(""===f?this.destroy(c):localStorage.setItem(c,f));return"function"===typeof h?h():!0},destroy:function(c,f){localStorage.removeItem(c);return"function"===typeof f?f():!0},clean:function(c){for(var f=
localStorage.length-1;0<=f;f--)"undefined"===typeof Array.indexOf&&-1!==localStorage.key(f).indexOf("garlic:")&&localStorage.removeItem(localStorage.key(f));return"function"===typeof c?c():!0},clear:function(c){localStorage.clear();return"function"===typeof c?c():!0}};var t=function(c,f,h){this.init("garlic",c,f,h)};t.prototype={constructor:t,init:function(e,f,h,j){this.type=e;this.$element=c(f);this.options=this.getOptions(j);this.storage=h;this.path=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,c.proxy(this.persist,this));if(this.options.destroy)c(this.parentForm).on("submit reset",!1,c.proxy(this.destroy,this));this.retrieve()},getOptions:function(e){return e=c.extend({},c.fn[this.type].defaults,e,this.$element.data())},persist:function(){this.options.expires&&
-this.storage.set(this.expiresFlag,((new Date).getTime()+1E3*this.options.expires).toString());if(this.$element.is("input[type=checkbox]"))return this.storage.set(this.path,this.$element.attr("checked")?"checked":"unchecked");this.storage.set(this.path,this.$element.val())},retrieve:function(){if(this.storage.has(this.path)){if(this.options.expires){var c=(new Date).getTime();if(this.storage.get(this.expiresFlag)<c.toString()){this.storage.destroy(this.path);return}this.$element.attr("expires-in",
-Math.floor((parseInt(this.storage.get(this.expiresFlag))-c)/1E3))}c=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"===c||this.$element.val()===c)return this.$element.attr("checked",!0);"unchecked"===c&&this.$element.attr("checked",!1)}else this.$element.val(c),this.options.onRetrieve(this.$element,c)}},detectConflict:function(){var e=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 f=!1;this.$element.find("option").each(function(){0!==c(this).index()&&(c(this).attr("selected")&&c(this).val()!==e.storage.get(this.path))&&(f=!0)});return f}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 e=c(this.options.conflictManager.template);this.$element.after(e.text(this.options.conflictManager.message));
-e.on("click",!1,c.proxy(this.swap,this))},swap:function(){var e=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());c(this.$element).val(e)},destroy:function(){this.storage.destroy(this.path)},remove:function(){this.remove();this.$element.is("input[type=radio], input[type=checkbox]")?c(this.$element).attr("checked",!1):this.$element.val("")},getPath:function(e){"undefined"===
-typeof e&&(e=this.$element);if(1!=e.length)return!1;for(var f="",h=e.is("input[type=checkbox]"),j=e;j.length;){var e=j[0],k=e.nodeName;if(!k)break;var k=k.toLowerCase(),j=j.parent(),m=j.children(k);if(c(e).is("form, input, select, textarea")||h)if(k+=c(e).attr("name")?"."+c(e).attr("name"):"",1<m.length&&!c(e).is("input[type=radio]")&&(k+=":eq("+m.index(e)+")"),f=k+(f?">"+f:""),"form"==e.nodeName.toLowerCase())break}return"garlic:"+document.domain+(this.options.domain?"*":window.location.pathname)+
-">"+f},getStorage:function(){return this.storage}};c.fn.garlic=function(e,f){function h(f){var i=c(f),h=i.data("garlic"),j=c.extend({},v,i.data());if("undefined"===typeof j.storage||j.storage)if(h||i.data("garlic",h=new t(f,k,j)),"string"===typeof e&&"function"===typeof h[e])return h[e]()}var v=c.extend(!0,{},c.fn.garlic.defaults,e,this.data()),k=new j,m=!1;if(!k.defined)return!1;this.each(function(){c(this).is("form")?c(this).find(v.inputs).each(function(){m=h(c(this))}):c(this).is(v.inputs)&&(m=
-h(c(this)))});return"function"===typeof f?f():m};c.fn.garlic.Constructor=t;c.fn.garlic.defaults={destroy:!0,inputs:"input, textarea, select",events:"DOMAttrModified textInput input change keypress paste focus".split(" "),domain:!1,expires:!1,conflictManager:{enabled:!0,garlicPriority:!0,template:'<span class="garlic-swap"></span>',message:"This is your saved data. Click here to see default one",onConflictDetected:function(){return!0}},onRetrieve:function(){}};c(window).on("load",function(){c('[data-persist="garlic"]').each(function(){c(this).garlic()})})}(window.jQuery||
-window.Zepto);
+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,c.proxy(this.persist,this));if(this.options.destroy)c(this.parentForm).on("submit reset",!1,c.proxy(this.destroy,this));this.retrieve()},getOptions:function(e){return e=c.extend({},c.fn[this.type].defaults,e,this.$element.data())},persist:function(){if(this.val!==this.$element.val()){this.val=
+this.$element.val();this.options.expires&&this.storage.set(this.expiresFlag,((new Date).getTime()+1E3*this.options.expires).toString());if(this.$element.is("input[type=checkbox]"))return this.storage.set(this.path,this.$element.attr("checked")?"checked":"unchecked");this.storage.set(this.path,this.$element.val())}},retrieve:function(){if(this.storage.has(this.path)){if(this.options.expires){var c=(new Date).getTime();if(this.storage.get(this.expiresFlag)<c.toString()){this.storage.destroy(this.path);
+return}this.$element.attr("expires-in",Math.floor((parseInt(this.storage.get(this.expiresFlag))-c)/1E3))}c=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"===c||this.$element.val()===c)return this.$element.attr("checked",!0);"unchecked"===c&&this.$element.attr("checked",!1)}else this.$element.val(c),this.options.onRetrieve(this.$element,c)}},detectConflict:function(){var e=
+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 f=!1;this.$element.find("option").each(function(){0!==c(this).index()&&(c(this).attr("selected")&&c(this).val()!==e.storage.get(this.path))&&(f=!0)});return f}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 e=c(this.options.conflictManager.template);
+this.$element.after(e.text(this.options.conflictManager.message));e.on("click",!1,c.proxy(this.swap,this))},swap:function(){var e=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());c(this.$element).val(e)},destroy:function(){this.storage.destroy(this.path)},remove:function(){this.remove();this.$element.is("input[type=radio], input[type=checkbox]")?c(this.$element).attr("checked",
+!1):this.$element.val("")},getPath:function(e){"undefined"===typeof e&&(e=this.$element);if(1!=e.length)return!1;for(var f="",h=e.is("input[type=checkbox]"),j=e;j.length;){var e=j[0],k=e.nodeName;if(!k)break;var k=k.toLowerCase(),j=j.parent(),m=j.children(k);if(c(e).is("form, input, select, textarea")||h)if(k+=c(e).attr("name")?"."+c(e).attr("name"):"",1<m.length&&!c(e).is("input[type=radio]")&&(k+=":eq("+m.index(e)+")"),f=k+(f?">"+f:""),"form"==e.nodeName.toLowerCase())break}return"garlic:"+document.domain+
+(this.options.domain?"*":window.location.pathname)+">"+f},getStorage:function(){return this.storage}};c.fn.garlic=function(e,f){function h(f){var i=c(f),h=i.data("garlic"),j=c.extend({},v,i.data());if("undefined"===typeof j.storage||j.storage)if(h||i.data("garlic",h=new t(f,k,j)),"string"===typeof e&&"function"===typeof h[e])return h[e]()}var v=c.extend(!0,{},c.fn.garlic.defaults,e,this.data()),k=new j,m=!1;if(!k.defined)return!1;this.each(function(){c(this).is("form")?c(this).find(v.inputs).each(function(){m=
+h(c(this))}):c(this).is(v.inputs)&&(m=h(c(this)))});return"function"===typeof f?f():m};c.fn.garlic.Constructor=t;c.fn.garlic.defaults={destroy:!0,inputs:"input, textarea, select",events:"DOMAttrModified textInput input change keypress paste focus".split(" "),domain:!1,expires:!1,conflictManager:{enabled:!0,garlicPriority:!0,template:'<span class="garlic-swap"></span>',message:"This is your saved data. Click here to see default one",onConflictDetected:function(){return!0}},onRetrieve:function(){}};
+c(window).on("load",function(){c('[data-persist="garlic"]').each(function(){c(this).garlic()})})}(window.jQuery||window.Zepto);
22 dist/garlic.min.js
View
@@ -1,13 +1,13 @@
-/* Garlicjs dist/garlic.min.js build version 1.1.0 http://garlicjs.org */
+/* Garlicjs dist/garlic.min.js build version 1.1.1 http://garlicjs.org */
!function(b){var h=function(){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 i=function(a,b,d){this.init("garlic",a,b,d)};i.prototype={constructor:i,init:function(a,c,d,f){this.type=a;this.$element=b(c);this.options=this.getOptions(f);this.storage=d;this.path=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 a=b.extend({},b.fn[this.type].defaults,a,this.$element.data())},persist:function(){this.options.expires&&
-this.storage.set(this.expiresFlag,((new Date).getTime()+1E3*this.options.expires).toString());if(this.$element.is("input[type=checkbox]"))return this.storage.set(this.path,this.$element.attr("checked")?"checked":"unchecked");this.storage.set(this.path,this.$element.val())},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.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).attr("checked",!1):this.$element.val("")},getPath:function(a){"undefined"===
-typeof a&&(a=this.$element);if(1!=a.length)return!1;for(var c="",d=a.is("input[type=checkbox]"),f=a;f.length;){var a=f[0],e=a.nodeName;if(!e)break;var e=e.toLowerCase(),f=f.parent(),g=f.children(e);if(b(a).is("form, input, select, textarea")||d)if(e+=b(a).attr("name")?"."+b(a).attr("name"):"",1<g.length&&!b(a).is("input[type=radio]")&&(e+=":eq("+g.index(a)+")"),c=e+(c?">"+c:""),"form"==a.nodeName.toLowerCase())break}return"garlic:"+document.domain+(this.options.domain?"*":window.location.pathname)+
-">"+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({},f,d.data());if("undefined"===typeof h.storage||h.storage)if(g||d.data("garlic",g=new i(c,e,h)),"string"===typeof a&&"function"===typeof g[a])return g[a]()}var f=b.extend(!0,{},b.fn.garlic.defaults,a,this.data()),e=new h,g=!1;if(!e.defined)return!1;this.each(function(){b(this).is("form")?b(this).find(f.inputs).each(function(){g=d(b(this))}):b(this).is(f.inputs)&&(g=
-d(b(this)))});return"function"===typeof c?c():g};b.fn.garlic.Constructor=i;b.fn.garlic.defaults={destroy:!0,inputs:"input, textarea, select",events:"DOMAttrModified textInput input change keypress paste focus".split(" "),domain:!1,expires:!1,conflictManager:{enabled:!0,garlicPriority:!0,template:'<span class="garlic-swap"></span>',message:"This is your saved data. Click here to see default one",onConflictDetected:function(){return!0}},onRetrieve:function(){}};b(window).on("load",function(){b('[data-persist="garlic"]').each(function(){b(this).garlic()})})}(window.jQuery||
-window.Zepto);
+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 a=b.extend({},b.fn[this.type].defaults,a,this.$element.data())},persist:function(){if(this.val!==this.$element.val()){this.val=
+this.$element.val();this.options.expires&&this.storage.set(this.expiresFlag,((new Date).getTime()+1E3*this.options.expires).toString());if(this.$element.is("input[type=checkbox]"))return this.storage.set(this.path,this.$element.attr("checked")?"checked":"unchecked");this.storage.set(this.path,this.$element.val())}},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.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).attr("checked",
+!1):this.$element.val("")},getPath:function(a){"undefined"===typeof a&&(a=this.$element);if(1!=a.length)return!1;for(var c="",d=a.is("input[type=checkbox]"),f=a;f.length;){var a=f[0],e=a.nodeName;if(!e)break;var e=e.toLowerCase(),f=f.parent(),g=f.children(e);if(b(a).is("form, input, select, textarea")||d)if(e+=b(a).attr("name")?"."+b(a).attr("name"):"",1<g.length&&!b(a).is("input[type=radio]")&&(e+=":eq("+g.index(a)+")"),c=e+(c?">"+c:""),"form"==a.nodeName.toLowerCase())break}return"garlic:"+document.domain+
+(this.options.domain?"*":window.location.pathname)+">"+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({},f,d.data());if("undefined"===typeof h.storage||h.storage)if(g||d.data("garlic",g=new i(c,e,h)),"string"===typeof a&&"function"===typeof g[a])return g[a]()}var f=b.extend(!0,{},b.fn.garlic.defaults,a,this.data()),e=new h,g=!1;if(!e.defined)return!1;this.each(function(){b(this).is("form")?b(this).find(f.inputs).each(function(){g=
+d(b(this))}):b(this).is(f.inputs)&&(g=d(b(this)))});return"function"===typeof c?c():g};b.fn.garlic.Constructor=i;b.fn.garlic.defaults={destroy:!0,inputs:"input, textarea, select",events:"DOMAttrModified textInput input change keypress paste focus".split(" "),domain:!1,expires:!1,conflictManager:{enabled:!0,garlicPriority:!0,template:'<span class="garlic-swap"></span>',message:"This is your saved data. Click here to see default one",onConflictDetected:function(){return!0}},onRetrieve:function(){}};
+b(window).on("load",function(){b('[data-persist="garlic"]').each(function(){b(this).garlic()})})}(window.jQuery||window.Zepto);
7 garlic.js
View
@@ -107,6 +107,13 @@
/* temporary store data / state in localStorage */
, persist: function () {
+ // some binded events are redundant (change & paste for example), persist only once by field val
+ if ( this.val === this.$element.val() ) {
+ return;
+ }
+
+ this.val = this.$element.val();
+
// if auto-expires is enabled, set the expiration date for future auto-deletion
if ( this.options.expires ) {
this.storage.set( this.expiresFlag , ( new Date().getTime() + this.options.expires * 1000 ).toString() );
10 index.html
View
@@ -105,10 +105,10 @@ <h1 class="">
<div class="row well intro">
<div id="head-download" class="download">
- <a href="https://github.com/guillaumepotier/Garlic.js/archive/1.1.0.zip">
+ <a href="https://github.com/guillaumepotier/Garlic.js/archive/1.1.1.zip">
<img width="90" border="0" src="http://github.com/images/modules/download/zip.png" onclick="onclick=”var that=this;_gaq.push(['_trackEvent','Download','ZIP',this.href]);setTimeout(function(){location.href=that.href;},200);return false;”">
</a>
- <a href="https://github.com/guillaumepotier/Garlic.js/archive/1.1.0.tar.gz">
+ <a href="https://github.com/guillaumepotier/Garlic.js/archive/1.1.1.tar.gz">
<img width="90" border="0" src="http://github.com/images/modules/download/tar.png" onclick="onclick=”var that=this;_gaq.push(['_trackEvent','Download','TAR',this.href]);setTimeout(function(){location.href=that.href;},200);return false;”">
</a>
</div>
@@ -295,10 +295,10 @@ <h1 class="">
<h1>Download</h1>
</div>
<div id="download" class="download">
- <a href="https://github.com/guillaumepotier/Garlic.js/archive/1.1.0.zip" onclick="onclick=”var that=this;_gaq.push(['_trackEvent','Download','ZIP',this.href]);setTimeout(function(){location.href=that.href;},200);return false;”" >
+ <a href="https://github.com/guillaumepotier/Garlic.js/archive/1.1.1.zip" onclick="onclick=”var that=this;_gaq.push(['_trackEvent','Download','ZIP',this.href]);setTimeout(function(){location.href=that.href;},200);return false;”" >
<img width="90" border="0" src="http://github.com/images/modules/download/zip.png">
</a>
- <a href="https://github.com/guillaumepotier/Garlic.js/archive/1.1.0.tar.gz" onclick="onclick=”var that=this;_gaq.push(['_trackEvent','Download','TAR',this.href]);setTimeout(function(){location.href=that.href;},200);return false;”">
+ <a href="https://github.com/guillaumepotier/Garlic.js/archive/1.1.1.tar.gz" onclick="onclick=”var that=this;_gaq.push(['_trackEvent','Download','TAR',this.href]);setTimeout(function(){location.href=that.href;},200);return false;”">
<img width="90" border="0" src="http://github.com/images/modules/download/tar.png">
</a>
</div>
@@ -403,7 +403,7 @@ <h1 class="">
<div class="page-header">
<h1>Version / Licence</h1>
</div>
- <a href="https://github.com/guillaumepotier/Garlic.js/blob/master/README.md">1.1.0 - MIT</a> - <a href="https://github.com/guillaumepotier/Garlic.js/blob/master/CHANGELOG.md">See changelog</a>
+ <a href="https://github.com/guillaumepotier/Garlic.js/blob/master/README.md">1.1.1 - MIT</a> - <a href="https://github.com/guillaumepotier/Garlic.js/blob/master/CHANGELOG.md">See changelog</a>
<a href="#top" class="pull-right">Top</a>
</section>
</div>
Please sign in to comment.
Something went wrong with that request. Please try again.