forked from fabiospampinato/cash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcash.min.js
37 lines (37 loc) · 14.4 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
36
37
/* MIT https://github.com/kenwheeler/cash */
(function(){
'use strict';var e=document,g=window,k=e.createElement("div"),l=Array.prototype,m=l.filter,n=l.indexOf,aa=l.map,q=l.push,r=l.reverse,u=l.slice,v=l.some,ba=l.splice,ca=/^#[\w-]*$/,da=/^\.[\w-]*$/,ea=/<.+>/,fa=/^\w+$/;function w(a,b){void 0===b&&(b=e);return b!==e&&1!==b.nodeType?[]:da.test(a)?b.getElementsByClassName(a.slice(1)):fa.test(a)?b.getElementsByTagName(a):b.querySelectorAll(a)}
var x=function(){function a(a,c){void 0===c&&(c=e);if(a){if(a instanceof x)return a;var b=a;if(y(a)){if(b=c instanceof x?c[0]:c,b=ca.test(a)?b.getElementById(a.slice(1)):ea.test(a)?z(a):w(a,b),!b)return}else if(A(a))return this.ready(a);if(b.nodeType||b===g)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}(),B=x.prototype.init;B.fn=B.prototype=x.prototype;x.prototype.length=0;x.prototype.splice=ba;
x.prototype.get=function(a){return void 0===a?u.call(this):this[0>a?a+this.length:a]};x.prototype.eq=function(a){return B(this.get(a))};x.prototype.first=function(){return this.eq(0)};x.prototype.last=function(){return this.eq(-1)};x.prototype.map=function(a){return B(aa.call(this,function(b,c){return a.call(b,c,b)}))};x.prototype.slice=function(){return B(u.apply(this,arguments))};var ha=/-([a-z])/g;function ia(a,b){return b.toUpperCase()}function C(a){return a.replace(ha,ia)}B.camelCase=C;
function D(a,b){for(var c=0,d=a.length;c<d&&!1!==b.call(a[c],c,a[c]);c++);}B.each=D;x.prototype.each=function(a){D(this,a);return this};x.prototype.removeProp=function(a){return this.each(function(b,c){delete c[a]})};function E(a){for(var b=1;b<arguments.length;b++);b=arguments;for(var c=b.length,d=2>c?0:1;d<c;d++)for(var f in b[d])a[f]=b[d][f];return a}x.prototype.extend=function(a){return E(B.fn,a)};B.extend=E;var F=1;B.guid=F;
function G(a,b){var c=a&&(a.matches||a.webkitMatchesSelector||a.mozMatchesSelector||a.msMatchesSelector||a.oMatchesSelector);return!!c&&c.call(a,b)}B.matches=G;function H(a,b,c){for(var d=[],f=0,h=a.length;f<h;f++)for(var p=a[f][b];null!=p;){d.push(p);if(!c)break;p=p[b]}return d}function A(a){return"function"===typeof a}function y(a){return"string"===typeof a}function ja(a){return!isNaN(parseFloat(a))&&isFinite(a)}var I=Array.isArray;B.isFunction=A;B.isString=y;B.isNumeric=ja;B.isArray=I;
x.prototype.prop=function(a,b){if(a){if(y(a))return 2>arguments.length?this[0]&&this[0][a]:this.each(function(c,f){f[a]=b});for(var c in a)this.prop(c,a[c]);return this}};function J(a){return y(a)?function(b,c){return G(c,a)}:A(a)?a:a instanceof x?function(b,c){return a.is(c)}:function(b,c){return c===a}}x.prototype.filter=function(a){if(!a)return B();var b=J(a);return B(m.call(this,function(a,d){return b.call(a,d,a)}))};function K(a,b){return b&&a.length?a.filter(b):a}var ka=/\S+/g;
function L(a){return y(a)?a.match(ka)||[]:[]}x.prototype.hasClass=function(a){return a&&v.call(this,function(b){return b.classList.contains(a)})};x.prototype.removeAttr=function(a){var b=L(a);return b.length?this.each(function(a,d){D(b,function(a,b){d.removeAttribute(b)})}):this};
x.prototype.attr=function(a,b){if(a){if(y(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,f){f.setAttribute(a,b)})}for(c in a)this.attr(c,a[c]);return this}};x.prototype.toggleClass=function(a,b){var c=L(a),d=void 0!==b;return c.length?this.each(function(a,h){D(c,function(a,c){d?b?h.classList.add(c):h.classList.remove(c):h.classList.toggle(c)})}):this};
x.prototype.addClass=function(a){return this.toggleClass(a,!0)};x.prototype.removeClass=function(a){return arguments.length?this.toggleClass(a,!1):this.attr("class","")};function N(a){return 1<a.length?m.call(a,function(a,c,d){return n.call(d,a)===c}):a}B.unique=N;x.prototype.add=function(a,b){return B(N(this.get().concat(B(a,b).get())))};function O(a,b,c){if(1===a.nodeType&&b)return a=g.getComputedStyle(a,null),b?c?a.getPropertyValue(b)||void 0:a[b]:a}
function P(a,b){return parseInt(O(a,b),10)||0}var Q=/^--/,R={},la=k.style,ma=["webkit","moz","ms","o"];function na(a,b){void 0===b&&(b=Q.test(a));if(b)return a;if(!R[a]){b=C(a);var c=""+b.charAt(0).toUpperCase()+b.slice(1);b=(b+" "+ma.join(c+" ")+c).split(" ");D(b,function(b,c){if(c in la)return R[a]=c,!1})}return R[a]}B.prefixedProp=na;var oa={animationIterationCount:!0,columnCount:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0};
function pa(a,b,c){void 0===c&&(c=Q.test(a));return c||oa[a]||!ja(b)?b:b+"px"}x.prototype.css=function(a,b){if(y(a)){var c=Q.test(a);a=na(a,c);if(2>arguments.length)return this[0]&&O(this[0],a,c);if(!a)return this;b=pa(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 qa=/^data-(.*)/;B.hasData=function(a){return"__cashData"in a};function S(a){return a.__cashData=a.__cashData||{}}
function ra(a,b){var c=S(a);if(b){if(!(b in c)&&(a=a.dataset?a.dataset[b]||a.dataset[C(b)]:B(a).attr("data-"+b),void 0!==a)){try{a=JSON.parse(a)}catch(d){}c[b]=a}return c[b]}return c}x.prototype.data=function(a,b){var c=this;if(!a){if(!this[0])return;D(this[0].attributes,function(a,b){(a=b.name.match(qa))&&c.data(a[1])});return ra(this[0])}if(y(a))return void 0===b?this[0]&&ra(this[0],a):this.each(function(c,d){S(d)[a]=b});for(var d in a)this.data(d,a[d]);return this};
x.prototype.removeData=function(a){return this.each(function(b,c){void 0===a?delete c.__cashData:delete S(c)[a]})};function sa(a,b){return P(a,"border"+(b?"Left":"Top")+"Width")+P(a,"padding"+(b?"Left":"Top"))+P(a,"padding"+(b?"Right":"Bottom"))+P(a,"border"+(b?"Right":"Bottom")+"Width")}D(["Width","Height"],function(a,b){x.prototype["inner"+b]=function(){if(this[0])return this[0]===g?g["inner"+b]:this[0]["client"+b]}});
D(["width","height"],function(a,b){x.prototype[b]=function(c){if(!this[0])return void 0===c?void 0:this;if(!arguments.length)return this[0]===g?this[0][C("outer-"+b)]:this[0].getBoundingClientRect()[b]-sa(this[0],!a);var d=parseInt(c,10);return this.each(function(c,h){1===h.nodeType&&(c=O(h,"boxSizing"),h.style[b]=pa(b,d+("border-box"===c?sa(h,!a):0)))})}});
D(["Width","Height"],function(a,b){x.prototype["outer"+b]=function(c){if(this[0])return this[0]===g?g["outer"+b]:this[0]["offset"+b]+(c?P(this[0],"margin"+(a?"Top":"Left"))+P(this[0],"margin"+(a?"Bottom":"Right")):0)}});var T={};
x.prototype.toggle=function(a){return this.each(function(b,c){if(a=void 0!==a?a:"none"===O(c,"display")){if(c.style.display="","none"===O(c,"display")){b=c.style;c=c.tagName;if(T[c])c=T[c];else{var d=e.createElement(c);e.body.appendChild(d);var f=O(d,"display");e.body.removeChild(d);c=T[c]="none"!==f?f:"block"}b.display=c}}else c.style.display="none"})};x.prototype.hide=function(){return this.toggle(!1)};x.prototype.show=function(){return this.toggle(!0)};
function ta(a,b){return!b||!v.call(b,function(b){return 0>a.indexOf(b)})}var U={focus:"focusin",blur:"focusout"},ua={mouseenter:"mouseover",mouseleave:"mouseout"},va=/^(?:mouse|pointer|contextmenu|drag|drop|click|dblclick)/i;function wa(a,b,c,d){d.guid=d.guid||F++;var f=a.__cashEvents=a.__cashEvents||{};f[b]=f[b]||[];f[b].push([c,d]);a.addEventListener(b,d)}function V(a){a=a.split(".");return[a[0],a.slice(1).sort()]}
function W(a,b,c,d){var f=a.__cashEvents=a.__cashEvents||{};if(b)f[b]&&(f[b]=f[b].filter(function(f){var h=f[0];f=f[1];if(d&&f.guid!==d.guid||!ta(h,c))return!0;a.removeEventListener(b,f)}));else{for(b in f)W(a,b,c,d);delete a.__cashEvents}}x.prototype.off=function(a,b){var c=this;void 0===a?this.each(function(a,b){return W(b)}):D(L(a),function(a,f){a=V(ua[f]||U[f]||f);var d=a[0],p=a[1];c.each(function(a,c){return W(c,d,p,b)})});return this};
x.prototype.on=function(a,b,c,d){var f=this;if(!y(a)){for(var h in a)this.on(h,b,a[h]);return this}A(b)&&(c=b,b="");D(L(a),function(a,h){a=V(ua[h]||U[h]||h);var p=a[0],M=a[1];f.each(function(a,f){a=function za(a){if(!a.namespace||ta(M,a.namespace.split("."))){var h=f;if(b){for(var t=a.target;!G(t,b);){if(t===f)return;t=t.parentNode;if(!t)return}h=t;a.__delegate=!0}a.__delegate&&Object.defineProperty(a,"currentTarget",{configurable:!0,get:function(){return h}});t=c.call(h,a,a.data);d&&W(f,p,M,za);
!1===t&&(a.preventDefault(),a.stopPropagation())}};a.guid=c.guid=c.guid||F++;wa(f,p,M,a)})});return this};x.prototype.one=function(a,b,c){return this.on(a,b,c,!0)};x.prototype.ready=function(a){function b(){return a(B)}"loading"!==e.readyState?setTimeout(b):e.addEventListener("DOMContentLoaded",b);return this};
x.prototype.trigger=function(a,b){var c=a;if(y(a)){var d=V(a);a=d[0];d=d[1];var f=va.test(a)?"MouseEvents":"HTMLEvents";c=e.createEvent(f);c.initEvent(a,!0,!0);c.namespace=d.join(".")}c.data=b;var h=c.type in U;return this.each(function(a,b){if(h&&A(b[c.type]))b[c.type]();else b.dispatchEvent(c)})};function xa(a){return a.multiple?H(m.call(a.options,function(a){return a.selected&&!a.disabled&&!a.parentNode.disabled}),"value"):a.value||""}var ya=/%20/g,Aa=/file|reset|submit|button|image/i,Ba=/radio|checkbox/i;
x.prototype.serialize=function(){var a="";this.each(function(b,c){D(c.elements||[c],function(b,c){c.disabled||!c.name||"FIELDSET"===c.tagName||Aa.test(c.type)||Ba.test(c.type)&&!c.checked||(b=xa(c),void 0!==b&&(b=I(b)?b:[b],D(b,function(b,d){b=a;d="&"+encodeURIComponent(c.name)+"="+encodeURIComponent(d).replace(ya,"+");a=b+d})))})});return a.substr(1)};
x.prototype.val=function(a){return void 0===a?this[0]&&xa(this[0]):this.each(function(b,c){if("SELECT"===c.tagName){var d=I(a)?a:null===a?[]:[a];D(c.options,function(a,b){b.selected=0<=d.indexOf(b.value)})}else c.value=null===a?"":a})};x.prototype.clone=function(){return this.map(function(a,b){return b.cloneNode(!0)})};x.prototype.detach=function(){return this.each(function(a,b){b.parentNode&&b.parentNode.removeChild(b)})};var Ca=/^\s*<(\w+)[^>]*>/,Da=/^\s*<(\w+)\s*\/?>(?:<\/\1>)?\s*$/,X;
function z(a){if(!X){var b=e.createElement("table"),c=e.createElement("tr");X={"*":k,tr:e.createElement("tbody"),td:c,th:c,thead:b,tbody:b,tfoot:b}}if(!y(a))return[];if(Da.test(a))return[e.createElement(RegExp.$1)];b=Ca.test(a)&&RegExp.$1;b=X[b]||X["*"];b.innerHTML=a;return B(b.childNodes).detach().get()}B.parseHTML=z;x.prototype.empty=function(){var a=this[0];if(a)for(;a.firstChild;)a.removeChild(a.firstChild);return this};
x.prototype.html=function(a){return void 0===a?this[0]&&this[0].innerHTML:this.each(function(b,c){c.innerHTML=a})};x.prototype.remove=function(){return this.detach().off()};x.prototype.text=function(a){return void 0===a?this[0]?this[0].textContent:"":this.each(function(b,c){c.textContent=a})};x.prototype.unwrap=function(){this.parent().each(function(a,b){a=B(b);a.replaceWith(a.children())});return this};var Ea=e.documentElement;
x.prototype.offset=function(){var a=this[0];if(a)return a=a.getBoundingClientRect(),{top:a.top+g.pageYOffset-Ea.clientTop,left:a.left+g.pageXOffset-Ea.clientLeft}};x.prototype.offsetParent=function(){return B(this[0]&&this[0].offsetParent)};x.prototype.position=function(){var a=this[0];if(a)return{left:a.offsetLeft,top:a.offsetTop}};x.prototype.children=function(a){var b=[];this.each(function(a,d){q.apply(b,d.children)});return K(B(N(b)),a)};
x.prototype.contents=function(){var a=[];this.each(function(b,c){q.apply(a,"IFRAME"===c.tagName?[c.contentDocument]:c.childNodes)});return B(N(a))};x.prototype.find=function(a){for(var b=[],c=0,d=this.length;c<d;c++){var f=w(a,this[c]);f.length&&q.apply(b,f)}return B(N(b))};var Fa=/^$|^module$|\/(?:java|ecma)script/i,Ga=/^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g;
function Y(a){a=B(a);a.filter("script").add(a.find("script")).each(function(a,c){!c.src&&Fa.test(c.type)&&c.ownerDocument.documentElement.contains(c)&&eval(c.textContent.replace(Ga,""))})}function Z(a,b,c){D(a,function(a,f){D(b,function(b,d){b=a?d.cloneNode(!0):d;c?f.insertBefore(b,c&&f.firstChild):f.appendChild(b);Y(b)})})}x.prototype.append=function(){var a=this;D(arguments,function(b,c){Z(a,B(c))});return this};x.prototype.appendTo=function(a){Z(B(a),this);return this};
x.prototype.insertAfter=function(a){var b=this;B(a).each(function(a,d){var c=d.parentNode;c&&b.each(function(b,f){b=a?f.cloneNode(!0):f;c.insertBefore(b,d.nextSibling);Y(b)})});return this};x.prototype.after=function(){var a=this;D(r.apply(arguments),function(b,c){r.apply(B(c).slice()).insertAfter(a)});return this};x.prototype.insertBefore=function(a){var b=this;B(a).each(function(a,d){var c=d.parentNode;c&&b.each(function(b,f){b=a?f.cloneNode(!0):f;c.insertBefore(b,d);Y(b)})});return this};
x.prototype.before=function(){var a=this;D(arguments,function(b,c){B(c).insertBefore(a)});return this};x.prototype.prepend=function(){var a=this;D(arguments,function(b,c){Z(a,B(c),!0)});return this};x.prototype.prependTo=function(a){Z(B(a),r.apply(this.slice()),!0);return this};x.prototype.replaceWith=function(a){return this.before(a).remove()};x.prototype.replaceAll=function(a){B(a).replaceWith(this);return this};
x.prototype.wrapAll=function(a){if(this[0]){a=B(a);this.first().before(a);for(a=a[0];a.children.length;)a=a.firstElementChild;this.appendTo(a)}return this};x.prototype.wrap=function(a){return this.each(function(b,c){var d=B(a)[0];B(c).wrapAll(b?d.cloneNode(!0):d)})};x.prototype.wrapInner=function(a){return this.each(function(b,c){b=B(c);c=b.contents();c.length?c.wrapAll(a):b.append(a)})};
x.prototype.has=function(a){var b=y(a)?function(b,d){return!!w(a,d).length}:function(b,d){return d.contains(a)};return this.filter(b)};x.prototype.is=function(a){if(!a||!this[0])return!1;var b=J(a),c=!1;this.each(function(a,f){c=b.call(f,a,f);return!c});return c};x.prototype.next=function(a,b){return K(B(N(H(this,"nextElementSibling",b))),a)};x.prototype.nextAll=function(a){return this.next(a,!0)};
x.prototype.not=function(a){if(!a||!this[0])return this;var b=J(a);return this.filter(function(a,d){return!b.call(d,a,d)})};x.prototype.parent=function(a){return K(B(N(H(this,"parentNode"))),a)};x.prototype.index=function(a){var b=a?B(a)[0]:this[0];a=a?this:B(b).parent().children();return n.call(a,b)};x.prototype.closest=function(a){if(!a||!this[0])return B();var b=this.filter(a);return b.length?b:this.parent().closest(a)};
x.prototype.parents=function(a){return K(B(N(H(this,"parentElement",!0))),a)};x.prototype.prev=function(a,b){return K(B(N(H(this,"previousElementSibling",b))),a)};x.prototype.prevAll=function(a){return this.prev(a,!0)};x.prototype.siblings=function(a){var b=this[0];return K(this.parent().children().filter(function(a,d){return d!==b}),a)};"undefined"!==typeof exports?module.exports=B:g.cash=g.$=B;
})();