forked from gwendall/way.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
way.min.js
1 lines (1 loc) · 19.9 KB
/
way.min.js
1
!function(a,b){"function"==typeof define&&define.amd?define(b):"object"==typeof exports?module.exports=b():a.way=b()}(this,function(){"use strict";var a,b,c="way",d=function(){this._watchers={},this._watchersAll={}};d.prototype.constructor=d,d.prototype.watchAll=function(a){this._watchersAll=this._watchersAll||[],n.contains(this._watchersAll,a)||this._watchersAll.push(a)},d.prototype.watch=function(a,b){this._watchers||(this._watchers={}),this._watchers[a]=this._watchers[a]||[],this._watchers[a].push(b)},d.prototype.findWatcherDeps=function(a){var b=[],c=n.keys(this._watchers);return c.forEach(function(c){g(a,c)&&b.push(c)}),b},d.prototype.emitChange=function(a){this._watchers||(this._watchers={});var b=this,c=b.findWatcherDeps(a);c.forEach(function(a){b._watchers[a]&&b._watchers[a].forEach(function(c){c.apply(b,[b.get(a)])})}),b._watchersAll&&n.isArray(b._watchersAll)&&b._watchersAll.forEach(function(c){n.isFunction(c)&&c.apply(b,[a,b.get(a)])})};var e=function(){this.data={},this._bindings={},this.options={persistent:!0,timeoutInput:50,timeoutDOM:500}};e.prototype=Object.create(d.prototype),e.constructor=e,e.prototype.dom=function(a){return this._element=b.dom(a).get(0),this},e.prototype.toStorage=function(a,b){var c=this,b=b||c._element,a=a||c.dom(b).getOptions(),d=c.dom(b).toJSON(a),e=c.dom(b).scope(),f=e?e+"."+a.data:a.data;return a.readonly?!1:void c.set(f,d,a)},e.prototype.toJSON=function(a,b){var c=this,b=b||c._element,d=c.dom(b).getValue(),a=a||c.dom(b).getOptions();return n.isArray(a.pick)&&(d=k(d,a.pick,!0)),n.isArray(a.omit)&&(d=k(d,a.omit,!1)),d},e.prototype.fromStorage=function(a,b){var c=this,b=b||c._element,a=a||c.dom(b).getOptions();if(a.writeonly)return!1;var d=c.dom(b).scope(),e=d?d+"."+a.data:a.data,f=c.get(e);c.dom(b).fromJSON(f,a)},e.prototype.fromJSON=function(a,b,c){var d=this,c=c||d._element,b=b||d.dom(c).getOptions();if(b.writeonly)return!1;if(n.isObject(a)){n.isArray(b.pick)&&(a=k(a,b.pick,!0)),n.isArray(b.omit)&&(a=k(a,b.omit,!1));var e=n.isObject(d.dom(c).toJSON())?d.dom(c).toJSON():{};a=n.extend(e,a)}b.json&&(a=A.isStringified(a)?a:A.prettyprint(a)),d.dom(c).setValue(a,b)},e.prototype.getValue=function(a){var c=this,a=a||c._element,d={SELECT:function(){return b.dom(a).val()},INPUT:function(){var c=b.dom(a).type();return n.contains(["text","password"],c)?b.dom(a).val():n.contains(["checkbox","radio"],c)?b.dom(a).prop("checked")?b.dom(a).val():null:void 0},TEXTAREA:function(){return b.dom(a).val()}},e=function(){return b.dom(a).html()},f=b.dom(a).get(0).tagName,g=d[f]||e;return g()},e.prototype._transforms={uppercase:function(a){return n.isString(a)?a.toUpperCase():a},lowercase:function(a){return n.isString(a)?a.toLowerCase():a},reverse:function(a){return a&&a.split&&n.isFunction(a.split)?a.split("").reverse().join(""):a}},e.prototype.registerTransform=function(a,b){var c=this;n.isFunction(b)&&(c._transforms[a]=b)},e.prototype.setValue=function(a,c,d){var e=this,d=d||e._element,c=c||e.dom(d).getOptions();c.transform=c.transform||[],c.transform.forEach(function(b){var c=e._transforms[b]||function(a){return a};a=c(a)});var f={SELECT:function(a){b.dom(d).val(a)},INPUT:function(a){n.isString(a)||(a=JSON.stringify(a));var c=b.dom(d).get(0).type;n.contains(["text","password"],c)&&b.dom(d).val(a||""),n.contains(["checkbox","radio"],c)&&(a===b.dom(d).val()?b.dom(d).prop("checked",!0):b.dom(d).prop("checked",!1))},TEXTAREA:function(a){n.isString(a)||(a=JSON.stringify(a)),b.dom(d).val(a||"")},PRE:function(a){c.html?b.dom(d).html(a):b.dom(d).text(a)},IMG:function(a){if(!a)return a=c.default||"",b.dom(d).attr("src",a),!1;var e=function(a,c){b.dom(d).addClass("way-loading"),b.dom("img",{src:a,onerror:function(){c(!1)},onload:function(){c(!0)}})};e(a,function(e){b.dom(d).removeClass("way-loading"),e?b.dom(d).removeClass("way-error").addClass("way-success"):(a?b.dom(d).addClass("way-error"):b.dom(d).removeClass("way-error").removeClass("way-success"),a=c.default||""),b.dom(d).attr("src",a)})}},g=function(a){c.html?b.dom(d).html(a):b.dom(d).text(a)},h=b.dom(d).get(0).tagName,i=f[h]||g;i(a)},e.prototype.setDefault=function(a,b,c){var d=this,c=c||d._element,a=a||!1,b=b?n.extend(d.dom(c).getOptions(),b):d.dom(c).getOptions();return b.default?void(a?d.set(b.data,b.default,b):d.dom(c).setValue(b.default,b)):!1},e.prototype.setDefaults=function(){var a=this,d="["+c+"-default]",e=b.dom(d).get();for(var f in e){var g=e[f],h=a.dom(g).getOptions(),i=h.data||null,j=i?a.get(i):null;j||a.dom(g).setDefault()}},e.prototype.registerBindings=function(){var a=this,d="["+c+"-data]";a._bindings={};var e=b.dom(d).get();for(var f in e){var g=e[f],h=a.dom(g).getOptions(),i=a.dom(g).scope(),d=i?i+"."+h.data:h.data;a._bindings[d]=a._bindings[d]||[],n.contains(a._bindings[d],b.dom(g).get(0))||a._bindings[d].push(b.dom(g).get(0))}},e.prototype.updateBindings=function(a){var c=this;c._bindings=c._bindings||{};var d=l(c._bindings,a);d.forEach(function(a){var d=b.dom(a).get(0)===b.dom(":focus").get(0)?!0:!1;d||c.dom(a).fromStorage()}),c._bindings.__all__&&c._bindings.__all__.forEach(function(a){c.dom(a).fromJSON(c.data)})},e.prototype.registerRepeats=function(){var a=this,d="["+c+"-repeat]";a._repeats=a._repeats||{},a._repeatsCount=a._repeatsCount||0;var e=b.dom(d).get();for(var f in e){var g=e[f],h=a.dom(g).getOptions();a._repeats[h.repeat]=a._repeats[h.repeat]||[];var i=c+'-repeat-wrapper="'+a._repeatsCount+'"',j=b.dom(g).parent("["+i+"]");if(!j.length){a._repeats[h.repeat].push({id:a._repeatsCount,element:b.dom(g).clone(!0).removeAttr(c+"-repeat").removeAttr(c+"-filter").get(0),selector:h.repeat,filter:h.filter});var k=document.createElement("div");b.dom(k).attr(c+"-repeat-wrapper",a._repeatsCount),b.dom(k).attr(c+"-scope",h.repeat),h.filter&&b.dom(k).attr(c+"-filter",h.filter),b.dom(g).replaceWith(k),a.updateRepeats(h.repeat),a._repeatsCount++}}},e.prototype.updateRepeats=function(a){var d=this;d._repeats=d._repeats||{};var e=l(d._repeats,a);e.forEach(function(a){var e="["+c+'-repeat-wrapper="'+a.id+'"]',f=d.get(a.selector),g=[];a.filter=a.filter||[],b.dom(e).empty();for(var h in f){b.dom(a.element).attr(c+"-scope",h);var i=b.dom(a.element).get(0).outerHTML;i=i.replace(/\$\$key/gi,h),g.push(i)}b.dom(e).html(g.join("")),d.registerBindings(),d.updateBindings()})},e.prototype.updateForms=function(){var a=this,d="form["+c+"-data]",e=b.dom(d).get();for(var f in e){var g=e[f],i=a.dom(g).getOptions(),j=i.data;b.dom(g).removeAttr(c+"-data");var k=b.dom(g).find("[name]").reverse().get();for(var f in k){var l=k[f],m=b.dom(l).attr("name");if(h(m,"[]")){var n=m.split("[]")[0],o="[name^='"+n+"']",p=b.dom(g).find(o).get().length;m=n+"."+p}var d=j+"."+m;i.data=d,a.dom(l).setOptions(i),b.dom(l).removeAttr("name")}}},e.prototype.registerDependencies=function(){this.registerBindings(),this.registerRepeats()},e.prototype.updateDependencies=function(a){this.updateBindings(a),this.updateRepeats(a),this.updateForms(a)},e.prototype.setOptions=function(a,d){var e=this,d=e._element||d;for(var f in a){var g=c+"-"+f,h=a[f];b.dom(d).attr(g,h)}},e.prototype.getOptions=function(a){var b=this,a=a||b._element,d={data:null,html:!1,readonly:!1,writeonly:!1,persistent:!1};return n.extend(d,b.dom(a).getAttrs(c))},e.prototype.getAttrs=function(a,c){var d=this,c=c||d._element,e=function(a,b){var c={pick:"array",omit:"array",readonly:"boolean",writeonly:"boolean",json:"boolean",html:"boolean",persistent:"boolean"},d={array:function(a){return a.split(",")},"boolean":function(a){return"true"===a?!0:"false"===a?!1:!0}},e=function(){return b},f=c[a]||null,g=d[f]||e;return g(b)},f={},h=[].slice.call(b.dom(c).get(0).attributes);return h.forEach(function(b){var c=a&&g(b.name,a+"-")?!0:!1;if(c){var d=a?b.name.slice(a.length+1,b.name.length):b.name,h=e(d,b.value);n.contains(["transform","filter"],d)&&(h=h.split("|")),f[d]=h}}),f},e.prototype.scope=function(a,d){var e=this,d=d||e._element,f=c+"-scope",g=c+"-scope-break",h=[],i="",j="["+g+"], ["+f+"]",k=b.dom(d).parents(j).get();for(var l in k){var m=k[l];if(b.dom(m).attr(g))break;var o=b.dom(m).attr(f);h.unshift(o)}return b.dom(d).attr(f)&&h.push(b.dom(d).attr(f)),b.dom(d).attr(g)&&(h=[]),i=n.compact(h).join(".")},e.prototype.get=function(a){var b=this;return void 0===a||n.isString(a)?b.data?a?A.get(b.data,a):b.data:{}:!1},e.prototype.set=function(a,b,c){if(!a)return!1;if("this"===a.split(".")[0])return console.log('Sorry, "this" is a reserved word in way.js'),!1;var d=this;if(c=c||{},a){if(!n.isString(a))return!1;d.data=d.data||{},d.data=a?A.set(d.data,a,b):{},d.updateDependencies(a),d.emitChange(a,b),c.persistent&&d.backup(a)}},e.prototype.push=function(a,b,c){if(!a)return!1;var d=this;c=c||{},a&&(d.data=a?A.push(d.data,a,b,!0):{}),d.updateDependencies(a),d.emitChange(a,null),c.persistent&&d.backup(a)},e.prototype.remove=function(a,b){var c=this;b=b||{},c.data=a?A.remove(c.data,a):{},c.updateDependencies(a),c.emitChange(a,null),b.persistent&&c.backup(a)},e.prototype.clear=function(){this.remove(null,{persistent:!0})},e.prototype.backup=function(){var a=this;if(a.options.persistent)try{var b=a.data||{};localStorage.setItem(c,JSON.stringify(b))}catch(d){console.log("Your browser does not support localStorage.")}},e.prototype.restore=function(){var a=this;if(a.options.persistent)try{var b=localStorage.getItem(c);try{b=JSON.parse(b);for(var d in b)a.set(d,b[d])}catch(e){}}catch(e){console.log("Your browser does not support localStorage.")}};var f=function(a,b){var c=["matches","matchesSelector","webkitMatchesSelector","mozMatchesSelector","msMatchesSelector","oMatchesSelector"],d=null;for(var e in c)if(d=c[e],n.isFunction(a[d]))return a[d](b);return!1},g=function(a,b){return""===b?!0:null===a||null===b?!1:(a=String(a),b=String(b),a.length>=b.length&&a.slice(0,b.length)===b)},h=function(a,b){return""===b?!0:null===a||null===b?!1:(a=String(a),b=String(b),a.length>=b.length&&a.slice(a.length-b.length,a.length)===b)},i=function(a){return n.pick(a,n.compact(n.keys(a)))},j=function(a,b,c){var d=n.keys(a);return d.forEach(function(d){c?g(d,b)||delete a[d]:g(d,b)&&delete a[d]}),a},k=function(a,b,c){var d=A.flatten(a);for(var e in b)d=j(d,b[e],c);var f=A.unflatten(d);return i(f)},l=function(a,b){var c=[];if(b){var d=b.split("."),e=d[d.length-1],f=!isNaN(e);if(f){d.pop();var h=d.join(".");c=a[h]?n.union(c,a[h]):c}for(var h in a)g(h,b)&&(c=n.union(c,a[h]))}else for(var h in a)c=n.union(c,a[h]);return c},m=function(a){return a&&n.isString(a)?a.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"):a},n={},o=Array.prototype,p=Object.prototype,q=Function.prototype,r=(Array.isArray,Object.keys),s=(q.bind,o.push),t=o.slice,u=o.concat,v=p.toString,w=p.hasOwnProperty,x=function(a,b,c,d){if(b&&n.every(a,n.isArray))return u.apply(d,a);for(var e=0,f=a.length;f>e;e++){var g=a[e];n.isArray(g)||n.isArguments(g)?b?s.apply(d,g):x(g,b,c,d):c||d.push(g)}return d},y=function(a,b,c){if(void 0===b)return a;switch(null==c?3:c){case 1:return function(c){return a.call(b,c)};case 2:return function(c,d){return a.call(b,c,d)};case 3:return function(c,d,e){return a.call(b,c,d,e)};case 4:return function(c,d,e,f){return a.call(b,c,d,e,f)}}return function(){return a.apply(b,arguments)}};n.compact=function(a){return n.filter(a,n.identity)},n.filter=function(a,b,c){var d=[];return null==a?d:(b=n.iteratee(b,c),n.each(a,function(a,c,e){b(a,c,e)&&d.push(a)}),d)},n.identity=function(a){return a},n.every=function(a,b,c){if(null==a)return!0;b=n.iteratee(b,c);var d,e,f=a.length!==+a.length&&n.keys(a),g=(f||a).length;for(d=0;g>d;d++)if(e=f?f[d]:d,!b(a[e],e,a))return!1;return!0},n.union=function(){return n.uniq(x(arguments,!0,!0,[]))},n.uniq=function(a,b,c,d){if(null==a)return[];n.isBoolean(b)||(d=c,c=b,b=!1),null!=c&&(c=n.iteratee(c,d));for(var e=[],f=[],g=0,h=a.length;h>g;g++){var i=a[g];if(b)g&&f===i||e.push(i),f=i;else if(c){var j=c(i,g,a);n.indexOf(f,j)<0&&(f.push(j),e.push(i))}else n.indexOf(e,i)<0&&e.push(i)}return e},n.pick=function(a,b,c){var d,e={};if(null==a)return e;if(n.isFunction(b)){b=y(b,c);for(d in a){var f=a[d];b(f,d,a)&&(e[d]=f)}}else{var g=u.apply([],t.call(arguments,1));a=new Object(a);for(var h=0,i=g.length;i>h;h++)d=g[h],d in a&&(e[d]=a[d])}return e},n.has=function(a,b){return null!=a&&w.call(a,b)},n.keys=function(a){if(!n.isObject(a))return[];if(r)return r(a);var b=[];for(var c in a)n.has(a,c)&&b.push(c);return b},n.contains=function(a,b){return null==a?!1:(a.length!==+a.length&&(a=n.values(a)),n.indexOf(a,b)>=0)},n.sortedIndex=function(a,b,c,d){c=n.iteratee(c,d,1);for(var e=c(b),f=0,g=a.length;g>f;){var h=f+g>>>1;c(a[h])<e?f=h+1:g=h}return f},n.property=function(a){return function(b){return b[a]}},n.iteratee=function(a,b,c){return null==a?n.identity:n.isFunction(a)?y(a,b,c):n.isObject(a)?n.matches(a):n.property(a)},n.pairs=function(a){for(var b=n.keys(a),c=b.length,d=Array(c),e=0;c>e;e++)d[e]=[b[e],a[b[e]]];return d},n.matches=function(a){var b=n.pairs(a),c=b.length;return function(a){if(null==a)return!c;a=new Object(a);for(var d=0;c>d;d++){var e=b[d],f=e[0];if(e[1]!==a[f]||!(f in a))return!1}return!0}},n.indexOf=function(a,b,c){if(null==a)return-1;var d=0,e=a.length;if(c){if("number"!=typeof c)return d=n.sortedIndex(a,b),a[d]===b?d:-1;d=0>c?Math.max(0,e+c):c}for(;e>d;d++)if(a[d]===b)return d;return-1},n.values=function(a){for(var b=n.keys(a),c=b.length,d=Array(c),e=0;c>e;e++)d[e]=a[b[e]];return d},n.extend=function(a){if(!n.isObject(a))return a;for(var b,c,d=1,e=arguments.length;e>d;d++){b=arguments[d];for(c in b)w.call(b,c)&&(a[c]=b[c])}return a},n.isArray=function(a){return"[object Array]"===v.call(a)},n.isBoolean=function(a){return a===!0||a===!1||"[object Boolean]"===v.call(a)},n.isUndefined=function(a){return void 0===a},n.isObject=function(a){var b=typeof a;return"function"===b||"object"===b&&!!a},n.each=function(a,b,c){if(null==a)return a;b=y(b,c);var d,e=a.length;if(e===+e)for(d=0;e>d;d++)b(a[d],d,a);else{var f=n.keys(a);for(d=0,e=f.length;e>d;d++)b(a[f[d]],f[d],a)}return a},n.each(["Arguments","Function","String","Number","Date","RegExp"],function(a){n["is"+a]=function(b){return v.call(b)==="[object "+a+"]"}});var z=function(a,b,c,d){var e,f=b.replace(/\[(["']?)([^\1]+?)\1?\]/g,".$2").replace(/^\./,"").split("."),g=0,h=f.length;if(arguments.length>2){for(e=a,h--;h>g;)b=f[g++],a=a[b]=n.isObject(a[b])?a[b]:{};d?n.isArray(a)?a.splice(f[g],1):delete a[f[g]]:a[f[g]]=c,c=e}else{for(;null!=(a=a[f[g++]])&&h>g;);c=h>g?void 0:a}return c},A={};A.VERSION="0.1.0",A.debug=!0,A.exit=function(a,b,c,d){if(A.debug){var e={};e.noJSON="Not a JSON",e.noString="Not a String",e.noArray="Not an Array",e.missing="Missing argument";var f={source:a,data:c,value:d};f.message=e[b]?e[b]:"No particular reason",console.log("Error",f)}},A.is=function(a){return"[object Object]"==v.call(a)},A.isStringified=function(a){var b=!1;try{b=/^[\],:{}\s]*$/.test(a.replace(/\\["\\\/bfnrtu]/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))}catch(c){}return b},A.get=function(a,b){return void 0==a?A.exit("get","missing","json",a):void 0==b?A.exit("get","missing","selector",b):n.isString(b)?z(a,b):A.exit("get","noString","selector",b)},A.set=function(a,b,c){return void 0==a?A.exit("set","missing","json",a):void 0==b?A.exit("set","missing","selector",b):n.isString(b)?c?z(a,b,c):A.remove(a,b):A.exit("set","noString","selector",b)},A.remove=function(a,b){return void 0==a?A.exit("remove","missing","json",a):void 0==b?A.exit("remove","missing","selector",b):n.isString(b)?z(a,b,null,!0):A.exit("remove","noString","selector",b)},A.push=function(a,b,c,d){if(void 0==a)return A.exit("push","missing","json",a);if(void 0==b)return A.exit("push","missing","selector",b);var e=A.get(a,b);if(!n.isArray(e)){if(!d)return A.exit("push","noArray","array",e);e=[]}return e.push(c),A.set(a,b,e)},A.unshift=function(a,b,c){if(void 0==a)return A.exit("unshift","missing","json",a);if(void 0==b)return A.exit("unshift","missing","selector",b);if(void 0==c)return A.exit("unshift","missing","value",c);var d=A.get(a,b);return n.isArray(d)?(d.unshift(c),A.set(a,b,d)):A.exit("unshift","noArray","array",d)},A.flatten=function(a){function b(a,d){if(Object(a)!==a)c[d]=a;else if(Array.isArray(a))for(var e=0,f=a.length;f>e;e++)b(a[e],d?d+"."+e:""+e),0==f&&(c[d]=[]);else{var g=!0;for(var h in a)g=!1,b(a[h],d?d+"."+h:h);g&&(c[d]={})}}if("Object"!=a.constructor.name)return A.exit("flatten","noJSON","json",a);var c={};return b(a,""),c},A.unflatten=function(a){if(Object(a)!==a||Array.isArray(a))return a;var b,c,d,e,f,g={};for(var h in a){b=g,c="",e=0;do d=h.indexOf(".",e),f=h.substring(e,-1!==d?d:void 0),b=b[c]||(b[c]=isNaN(parseInt(f))?{}:[]),c=f,e=d+1;while(d>=0);b[c]=a[h]}return g[""]},A.prettyprint=function(a){return JSON.stringify(a,void 0,2)};var B=function(){};B.constructor=B,B.prototype.dom=function(a,b){var c=this,d=[];if(!b)return n.isString(a)?d=[].slice.call(document.querySelectorAll(a)):n.isObject(a)&&a.attributes&&(d=[a]),c._elements=d,c.length=d.length,c;var e=document.createElement(a);for(var f in b)e[f]=b[f]},B.prototype.on=function(a,b){var c=this,d=c._elements;a=a.split(" ");for(var e=0,f=d.length;f>e;e++)for(var g=d[e],h=0,i=a.length;i>h;h++)g.addEventListener&&g.addEventListener(a[h],b,!1)},B.prototype.find=function(a){var b=this,c=b.get(0),d=[];return n.isString(a)&&(d=[].slice.call(c.querySelectorAll(a))),b._elements=d,b},B.prototype.get=function(a,b){var c=this,d=c._elements||[],e=d[a]||{};return b?(c._element=e,c):n.isNumber(a)?e:d},B.prototype.reverse=function(){return this._elements=this._elements.reverse(),this},B.prototype.val=function(a){return this.prop("value",a)},B.prototype.type=function(a){return this.prop("type",a)},B.prototype.html=function(a){return this.prop("innerHTML",a)},B.prototype.text=function(a){return this.prop("innerHTML",m(a))},B.prototype.prop=function(a,b){var c=this,d=c._elements;for(var e in d){if(n.isUndefined(b))return d[e][a];d[e][a]=b}},B.prototype.attr=function(a,b){var c=this,d=c._elements;for(var e in d){if(void 0===b)return d[e].getAttribute(a);d[e].setAttribute(a,b)}return c},B.prototype.removeAttr=function(a){var b=this;for(var c in b._elements)b._elements[c].removeAttribute(a);return b},B.prototype.addClass=function(a){var b=this;for(var c in b._elements)b._elements[c].classList.add(a);return b},B.prototype.removeClass=function(a){var b=this;for(var c in b._elements)b._elements[c].classList.remove(a);return b},B.prototype.parents=function(a){for(var b=this,c=b.get(0),d=c.parentNode,e=[];null!==d;){var g=d,h=f(g,a),i=void 0===g.doctype?!0:!1;a||(h=!0),h&&i&&e.push(g),d=g.parentNode}return b._elements=e,b},B.prototype.parent=function(a){var b=this,c=b.get(0),d=c.parentNode,e=f(d,a);return a||(e=!0),e?d:{}},B.prototype.clone=function(a){var b=this,c=b.get(0),d=c.cloneNode(!0);return b._elements=[d],a?b:d},B.prototype.empty=function(a){var b=this,c=b.get(0);if(!c||!c.hasChildNodes)return a?b:c;for(;c.hasChildNodes();)c.removeChild(c.lastChild);return a?b:c},B.prototype.replaceWith=function(a){var b=this,c=b.get(0),d=c.parentNode;d.replaceChild(a,c)},B.prototype.ready=function(a){document&&n.isFunction(document.addEventListener)?document.addEventListener("DOMContentLoaded",a,!1):window&&n.isFunction(window.addEventListener)?window.addEventListener("load",a,!1):document.onreadystatechange=function(){"complete"===document.readyState&&a()}},a=new e;var C=null,D=function(c){C&&clearTimeout(C),C=setTimeout(function(){var d=b.dom(c.target).get(0);a.dom(d).toStorage()},a.options.timeout)},E=function(b){b.preventDefault();var c=a.dom(this).getOptions();a.remove(c.data,c)},F=function(b){b.preventDefault();var c=a.dom(this).getOptions();if(!c||!c["action-push"])return!1;var d=c["action-push"].split(":"),e=d[0]||null,f=d[1]||null;a.push(e,f,c)},G=function(b){b.preventDefault();var c=a.dom(this).getOptions();return c&&c["action-remove"]?void a.remove(c["action-remove"],c):!1},H=null,I=function(){H&&clearTimeout(H),H=setTimeout(function(){a.registerDependencies(),J()},a.options.timeoutDOM)};b=new B,a.w=b;var J=function(){b.dom("body").on("DOMSubtreeModified",I),b.dom("["+c+"-data]").on("input change",D),b.dom("["+c+"-clear]").on("click",E),b.dom("["+c+"-action-remove]").on("click",G),b.dom("["+c+"-action-push]").on("click",F)},K=function(){J(),a.restore(),a.setDefaults(),a.registerDependencies(),a.updateDependencies()};return b.ready(K),a});