forked from fabiospampinato/cash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcash.min.js
35 lines (35 loc) · 13 KB
/
cash.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* MIT https://github.com/kenwheeler/cash */
(function(){
'use strict';var e=document,f=window,k=Array.prototype,l=k.filter,m=k.indexOf,aa=k.map,n=k.push,q=k.reverse,r=k.slice,ba=k.splice,ca=/^#[\w-]*$/,da=/^\.[\w-]*$/,ea=/<.+>/,fa=/^\w+$/;function t(a,b){void 0===b&&(b=e);return da.test(a)?b.getElementsByClassName(a.slice(1)):fa.test(a)?b.getElementsByTagName(a):b.querySelectorAll(a)}
var u=function(){function a(a,c){void 0===c&&(c=e);if(a){if(a instanceof u)return a;var b=a;if(v(a)){if(b=c instanceof u?c[0]:c,b=ca.test(a)?b.getElementById(a.slice(1)):ea.test(a)?w(a):t(a,b),!b)return}else if(x(a))return this.ready(a);if(b.nodeType||b===f)b=[b];this.length=b.length;a=0;for(c=this.length;a<c;a++)this[a]=b[a]}}a.prototype.init=function(b,c){return new a(b,c)};return a}(),y=u.prototype.init;y.fn=y.prototype=u.prototype;u.prototype.length=0;u.prototype.splice=ba;
u.prototype.get=function(a){return void 0===a?r.call(this):this[0>a?a+this.length:a]};u.prototype.eq=function(a){return y(this.get(a))};u.prototype.first=function(){return this.eq(0)};u.prototype.last=function(){return this.eq(-1)};u.prototype.map=function(a){return y(aa.call(this,function(b,c){return a.call(b,c,b)}))};u.prototype.slice=function(){return y(r.apply(this,arguments))};var ha=/(?:^\w|[A-Z]|\b\w)/g,ia=/[\s-_]+/g;
function z(a){return a.replace(ha,function(a,c){return a[c?"toUpperCase":"toLowerCase"]()}).replace(ia,"")}y.camelCase=z;function A(a,b){for(var c=0,d=a.length;c<d&&!1!==b.call(a[c],a[c],c,a);c++);}y.each=A;u.prototype.each=function(a){A(this,function(b,c){return a.call(b,c,b)});return this};u.prototype.removeProp=function(a){return this.each(function(b,c){delete c[a]})};
u.prototype.extend=y.extend=function(a){void 0===a&&(a=this);for(var b=arguments,c=b.length,d=2>c?0:1;d<c;d++)for(var g in b[d])a[g]=b[d][g];return a};var B=1;y.guid=B;function C(a,b){var c=a&&(a.matches||a.webkitMatchesSelector||a.mozMatchesSelector||a.msMatchesSelector||a.oMatchesSelector);return!!c&&c.call(a,b)}y.matches=C;function x(a){return"function"===typeof a}function v(a){return"string"===typeof a}function D(a){return!isNaN(parseFloat(a))&&isFinite(a)}var E=Array.isArray;y.isFunction=x;
y.isString=v;y.isNumeric=D;y.isArray=E;u.prototype.prop=function(a,b){if(a){if(v(a))return 2>arguments.length?this[0]&&this[0][a]:this.each(function(c,g){g[a]=b});for(var c in a)this.prop(c,a[c]);return this}};function F(a){return v(a)?function(b,c){return C(c,a)}:x(a)?a:a instanceof u?function(b,c){return a.is(c)}:function(b,c){return c===a}}u.prototype.filter=function(a){if(!a)return y();var b=F(a);return y(l.call(this,function(a,d){return b.call(a,d,a)}))};var ja=/\S+/g;
function G(a){return v(a)?a.match(ja)||[]:[]}u.prototype.hasClass=function(a){var b=G(a),c=!1;b.length&&this.each(function(a,g){c=g.classList.contains(b[0]);return!c});return c};u.prototype.removeAttr=function(a){var b=G(a);return b.length?this.each(function(a,d){A(b,function(a){d.removeAttribute(a)})}):this};
u.prototype.attr=function(a,b){if(a){if(v(a)){if(2>arguments.length){if(!this[0])return;var c=this[0].getAttribute(a);return null===c?void 0:c}return null===b?this.removeAttr(a):this.each(function(c,g){g.setAttribute(a,b)})}for(c in a)this.attr(c,a[c]);return this}};u.prototype.toggleClass=function(a,b){var c=G(a),d=void 0!==b;return c.length?this.each(function(a,h){A(c,function(a){d?b?h.classList.add(a):h.classList.remove(a):h.classList.toggle(a)})}):this};
u.prototype.addClass=function(a){return this.toggleClass(a,!0)};u.prototype.removeClass=function(a){return arguments.length?this.toggleClass(a,!1):this.attr("class","")};function I(a){return a.filter(function(a,c,d){return d.indexOf(a)===c})}y.unique=I;u.prototype.add=function(a,b){return y(I(this.get().concat(y(a,b).get())))};function J(a,b,c){if(1===a.nodeType)return a=f.getComputedStyle(a,null),b?c?a.getPropertyValue(b):a[b]:a}function K(a,b){return parseInt(J(a,b),10)||0}
var L=/^--/,M={},ka=e.createElement("div").style,la=["webkit","moz","ms","o"];function N(a,b){void 0===b&&(b=L.test(a));if(b)return a;if(!M[a]){b=z(a);var c=""+b.charAt(0).toUpperCase()+b.slice(1);b=(b+" "+la.join(c+" ")+c).split(" ");A(b,function(b){if(b in ka)return M[a]=b,!1})}return M[a]}y.prefixedProp=N;var ma={animationIterationCount:!0,columnCount:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0};
function O(a,b,c){void 0===c&&(c=L.test(a));return c||ma[a]||!D(b)?b:b+"px"}u.prototype.css=function(a,b){if(v(a)){var c=L.test(a);a=N(a,c);if(2>arguments.length)return this[0]&&J(this[0],a,c);if(!a)return this;b=O(a,b,c);return this.each(function(d,h){1===h.nodeType&&(c?h.style.setProperty(a,b):h.style[a]=b)})}for(var d in a)this.css(d,a[d]);return this};var na=/^data-(.*)/;y.hasData=function(a){return"__cashData"in a};function P(a){return a.__cashData=a.__cashData||{}}
function Q(a,b){var c=P(a);if(b){if(!(b in c)&&(a=a.dataset?a.dataset[b]||a.dataset[z(b)]:y(a).attr("data-"+b),void 0!==a)){try{a=JSON.parse(a)}catch(d){}c[b]=a}return c[b]}return c}u.prototype.data=function(a,b){var c=this;if(!a){if(!this[0])return;A(this[0].attributes,function(a){(a=a.name.match(na))&&c.data(a[1])});return Q(this[0])}if(v(a))return void 0===b?this[0]&&Q(this[0],a):this.each(function(c,d){P(d)[a]=b});for(var d in a)this.data(d,a[d]);return this};
u.prototype.removeData=function(a){return this.each(function(b,c){void 0===a?delete c.__cashData:delete P(c)[a]})};function R(a,b){return K(a,"border"+(b?"Left":"Top")+"Width")+K(a,"padding"+(b?"Left":"Top"))+K(a,"padding"+(b?"Right":"Bottom"))+K(a,"border"+(b?"Right":"Bottom")+"Width")}A(["Width","Height"],function(a){u.prototype["inner"+a]=function(){if(this[0])return this[0]===f?f["inner"+a]:this[0]["client"+a]}});
A(["width","height"],function(a,b){u.prototype[a]=function(c){if(!this[0])return void 0===c?void 0:this;if(!arguments.length)return this[0]===f?this[0][z("outer-"+a)]:this[0].getBoundingClientRect()[a]-R(this[0],!b);var d=parseInt(c,10);return this.each(function(c,h){1===h.nodeType&&(c=J(h,"boxSizing"),h.style[a]=O(a,d+("border-box"===c?R(h,!b):0)))})}});
A(["Width","Height"],function(a,b){u.prototype["outer"+a]=function(c){if(this[0])return this[0]===f?f["outer"+a]:this[0]["offset"+a]+(c?K(this[0],"margin"+(b?"Top":"Left"))+K(this[0],"margin"+(b?"Bottom":"Right")):0)}});function S(a,b){for(var c=0,d=b.length;c<d;c++)if(0>a.indexOf(b[c]))return!1;return!0}function oa(a,b,c){A(a[c],function(a){b.removeEventListener(c,a[1])});delete a[c]}
function pa(a,b,c,d){d.guid=d.guid||B++;var g=a.__cashEvents=a.__cashEvents||{};g[b]=g[b]||[];g[b].push([c,d]);a.addEventListener(b,d)}function T(a){a=a.split(".");return[a[0],a.slice(1).sort()]}function U(a,b,c,d){var g=a.__cashEvents=a.__cashEvents||{};if(b){var h=g[b];h&&(d&&(d.guid=d.guid||B++),g[b]=h.filter(function(g){var h=g[0];g=g[1];if(d&&g.guid!==d.guid||!S(h,c))return!0;a.removeEventListener(b,g)}))}else if(c&&c.length)for(b in g)U(a,b,c,d);else for(b in g)oa(g,a,b)}
u.prototype.off=function(a,b){var c=this;void 0===a?this.each(function(a,b){return U(b)}):A(G(a),function(a){a=T(a);var d=a[0],h=a[1];c.each(function(a,c){return U(c,d,h,b)})});return this};
u.prototype.on=function(a,b,c,d){var g=this;if(!v(a)){for(var h in a)this.on(h,b,a[h]);return this}x(b)&&(c=b,b="");A(G(a),function(a){a=T(a);var h=a[0],H=a[1];g.each(function(a,g){a=function qa(a){if(!a.namespace||S(H,a.namespace.split("."))){var p=g;if(b)for(p=a.target;!C(p,b);){if(p===g)return;p=p.parentNode;if(!p)return}a.namespace=a.namespace||"";p=c.call(p,a,a.data);d&&U(g,h,H,qa);!1===p&&(a.preventDefault(),a.stopPropagation())}};a.guid=c.guid=c.guid||B++;pa(g,h,H,a)})});return this};
u.prototype.one=function(a,b,c){return this.on(a,b,c,!0)};u.prototype.ready=function(a){function b(){return a(y)}"loading"!==e.readyState?setTimeout(b):e.addEventListener("DOMContentLoaded",b);return this};u.prototype.trigger=function(a,b){var c=a;if(v(a)){var d=T(a);a=d[0];d=d[1];c=e.createEvent("HTMLEvents");c.initEvent(a,!0,!0);c.namespace=d.join(".")}c.data=b;return this.each(function(a,b){b.dispatchEvent(c)})};
function ra(a){var b=[];A(a.options,function(a){!a.selected||a.disabled||a.parentNode.disabled||b.push(a.value)});return b}var sa=/select-one/i,V=/select-multiple/i;function W(a){var b=a.type;return sa.test(b)?0>a.selectedIndex?null:a.options[a.selectedIndex].value:V.test(b)?ra(a):a.value||""}var ta=/%20/g,ua=/file|reset|submit|button|image/i,va=/radio|checkbox/i;
u.prototype.serialize=function(){var a="";this.each(function(b,c){A(c.elements||[c],function(b){if(!b.disabled&&b.name&&"FIELDSET"!==b.tagName&&!ua.test(b.type)&&(!va.test(b.type)||b.checked)){var c=W(b);void 0!==c&&(c=E(c)?c:[c],A(c,function(c){var d=a;c="&"+encodeURIComponent(b.name)+"="+encodeURIComponent(c).replace(ta,"+");a=d+c}))}})});return a.substr(1)};
u.prototype.val=function(a){return void 0===a?this[0]&&W(this[0]):this.each(function(b,c){b=V.test(c.type);var d=null===a?b?[]:"":a;b&&E(d)?A(c.options,function(a){a.selected=0<=d.indexOf(a.value)}):c.value=d})};u.prototype.clone=function(){return this.map(function(a,b){return b.cloneNode(!0)})};u.prototype.detach=function(){return this.each(function(a,b){b.parentNode&&b.parentNode.removeChild(b)})};var wa=/^\s*<(\w+)[^>]*>/,xa=/^\s*<(\w+)\s*\/?>(?:<\/\1>)?\s*$/,X;
function w(a){if(!X){var b=e.createElement("table"),c=e.createElement("tr");X={"*":e.createElement("div"),tr:e.createElement("tbody"),td:c,th:c,thead:b,tbody:b,tfoot:b}}if(!v(a))return[];if(xa.test(a))return[e.createElement(RegExp.$1)];b=wa.test(a)&&RegExp.$1;b=X[b]||X["*"];b.innerHTML=a;return y(b.childNodes).detach().get()}y.parseHTML=w;u.prototype.empty=function(){var a=this[0];if(a)for(;a.firstChild;)a.removeChild(a.firstChild);return this};
function Y(a,b,c){A(a,function(a,g){A(b,function(b){b=g?b.cloneNode(!0):b;c?a.insertBefore(b,a.childNodes[0]):a.appendChild(b)})})}u.prototype.append=function(){var a=this;A(arguments,function(b){Y(a,y(b))});return this};u.prototype.appendTo=function(a){Y(y(a),this);return this};u.prototype.html=function(a){return void 0===a?this[0]&&this[0].innerHTML:this.each(function(b,c){c.innerHTML=a})};
u.prototype.insertAfter=function(a){var b=this;y(a).each(function(a,d){var c=d.parentNode;c&&b.each(function(b,g){c.insertBefore(a?g.cloneNode(!0):g,d.nextSibling)})});return this};u.prototype.after=function(){var a=this;A(q.apply(arguments),function(b){q.apply(y(b).slice()).insertAfter(a)});return this};u.prototype.insertBefore=function(a){var b=this;y(a).each(function(a,d){var c=d.parentNode;c&&b.each(function(b,g){c.insertBefore(a?g.cloneNode(!0):g,d)})});return this};
u.prototype.before=function(){var a=this;A(arguments,function(b){y(b).insertBefore(a)});return this};u.prototype.prepend=function(){var a=this;A(arguments,function(b){Y(a,y(b),!0)});return this};u.prototype.prependTo=function(a){Y(y(a),q.apply(this.slice()),!0);return this};u.prototype.remove=function(){return this.detach().off()};
u.prototype.replaceWith=function(a){var b=this;return this.each(function(c,d){var g=d.parentNode;if(g){c=c?y(a).clone():y(a);if(!c[0])return b.remove(),!1;g.replaceChild(c[0],d);y(c[0]).after(c.slice(1))}})};u.prototype.replaceAll=function(a){y(a).replaceWith(this);return this};u.prototype.text=function(a){return void 0===a?this[0]?this[0].textContent:"":this.each(function(b,c){c.textContent=a})};var Z=e.documentElement;
u.prototype.offset=function(){var a=this[0];if(a)return a=a.getBoundingClientRect(),{top:a.top+f.pageYOffset-Z.clientTop,left:a.left+f.pageXOffset-Z.clientLeft}};u.prototype.offsetParent=function(){return y(this[0]&&this[0].offsetParent)};u.prototype.position=function(){var a=this[0];if(a)return{left:a.offsetLeft,top:a.offsetTop}};u.prototype.children=function(a){var b=[];this.each(function(a,d){n.apply(b,d.children)});b=y(I(b));return a?b.filter(a):b};
u.prototype.contents=function(){var a=[];this.each(function(b,c){n.apply(a,"IFRAME"===c.tagName?[c.contentDocument]:c.childNodes)});return y(a.length&&I(a))};u.prototype.find=function(a){for(var b=[],c=0,d=this.length;c<d;c++){var g=t(a,this[c]);g.length&&n.apply(b,g)}return y(b.length&&I(b))};u.prototype.has=function(a){var b=v(a)?function(b,d){return!!t(a,d).length}:function(b,d){return d.contains(a)};return this.filter(b)};
u.prototype.is=function(a){if(!a||!this[0])return!1;var b=F(a),c=!1;this.each(function(a,g){c=b.call(g,a,g);return!c});return c};u.prototype.next=function(){return y(this[0]&&this[0].nextElementSibling)};u.prototype.not=function(a){if(!a||!this[0])return this;var b=F(a);return this.filter(function(a,d){return!b.call(d,a,d)})};u.prototype.parent=function(){var a=[];this.each(function(b,c){c&&c.parentNode&&a.push(c.parentNode)});return y(I(a))};
u.prototype.index=function(a){var b=a?y(a)[0]:this[0];a=a?this:y(b).parent().children();return m.call(a,b)};u.prototype.closest=function(a){return a&&this[0]?this.is(a)?this.filter(a):this.parent().closest(a):y()};u.prototype.parents=function(a){var b=[],c;this.each(function(d,g){for(c=g;c&&c.parentNode&&c!==e.body.parentNode;)c=c.parentNode,(!a||a&&C(c,a))&&b.push(c)});return y(I(b))};u.prototype.prev=function(){return y(this[0]&&this[0].previousElementSibling)};
u.prototype.siblings=function(){var a=this[0];return this.parent().children().filter(function(b,c){return c!==a})};"undefined"!==typeof exports?module.exports=y:f.cash=f.$=y;
})();