-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjquery.squirrel.min.js
1 lines (1 loc) · 2.83 KB
/
jquery.squirrel.min.js
1
!function(a,b){function c(c,d,e,f){var g=a.JSON.parse(c.getItem(d));if(null===g&&(g={}),h(f)||null===f)return h(g[e])?null:g[e];var i={};return i[e]=f,b.extend(g,i),c.setItem(d,a.JSON.stringify(g)),f}function d(a,b){a.removeItem(b)}function e(a){return"boolean"===b.type(a)}function f(a){return"object"===b.type(a)}function g(a){return"string"===b.type(a)&&b.trim(a).length>0}function h(a){return void 0===a}function i(a,b){return g(a)?a:b}b.fn.extend({squirrel:function(n,o){o=b.extend({},b.fn.squirrel.options,o),o.clearOnSubmit=o.clear_on_submit,o.storageMethod=o.storage_method,o.storageKey=o.storage_key,o.storageKeyPrefix=o.storage_key_prefix;var p=null;if(g(o.storageMethod)?p="LOCAL"===o.storageMethod.toUpperCase()?a.localStorage:a.sessionStorage:null!==o.storageMethod&&f(o.storageMethod)&&(p=o.storageMethod),null===p||!(f(p)&&"getItem"in p&&"removeItem"in p&&"setItem"in p))return this;n=g(n)&&m.test(n)?n.toUpperCase():"START";var q="input[type!=file]:not(.squirrel-ignore), select:not(.squirrel-ignore), textarea:not(.squirrel-ignore)",r="button[type=reset], input[type=reset]",s="input[id], input[name], select[id], select[name], textarea[id], textarea[name]";return o.storageKey=i(o.storageKey,"squirrel"),o.storageKeyPrefix=i(o.storageKeyPrefix,""),this.each(function(){var a=b(this),f=a.attr("data-squirrel"),i=o.storageKeyPrefix+(g(f)?f:o.storageKey);switch(n){case"CLEAR":case"REMOVE":d(p,i);break;case"OFF":case"STOP":a.find(q).off(k),a.find(r).off(j),a.off(l);break;default:a.find("*").filter(s).each(function(){var d=b(this),e=d.attr("name");if(h(e)&&(e=d.attr("id"),h(e)))return a;var f=null;switch(this.tagName){case"INPUT":case"TEXTAREA":var j=d.attr("type");if("checkbox"===j){var k=d.attr("value");g(k)||(k=""),f=c(p,i,e+k),null!==f&&f!==this.checked&&(this.checked=f===!0,d.trigger("change"))}else"radio"===j?(f=c(p,i,e),null!==f&&f!==this.checked&&(this.checked=d.val()===f,d.trigger("change"))):(f=c(p,i,e),null!==f&&!d.is("[readonly]")&&d.is(":enabled")&&d.val()!==f&&d.val(f).trigger("change"));break;case"SELECT":f=c(p,i,e),null!==f&&b.each(b.isArray(f)?f:[f],function(a,c){d.find("option").filter(function(){var a=b(this);return a.val()===c||a.html()===c}).prop("selected",!0).trigger("change")})}}),a.find(q).on(k,function(){var a=b(this),d=a.attr("name");if(!h(d)||(d=a.attr("id"),!h(d))){var e=a.attr("value"),f="checkbox"!==this.type||h(e)?d:d+e;c(p,i,f,"checkbox"===this.type?a.prop("checked"):a.val())}}),a.find(r).on(j,function(){d(p,i)}),a.on(l,function(){(!e(o.clearOnSubmit)||o.clearOnSubmit)&&d(p,i)})}})}});var j="click.squirrel.js",k="blur.squirrel.js keyup.squirrel.js change.squirrel.js",l="submit.squirrel.js",m=/^(?:CLEAR|REMOVE|OFF|STOP)$/i;b.fn.squirrel.options={clear_on_submit:!0,storage_method:"session",storage_key:"squirrel",storage_key_prefix:""},b(function(){b("form.squirrel, form[data-squirrel]").squirrel()})}(window,window.jQuery);