2023-11-12 23:09:21 +03:00
|
|
|
var u=function(e,t){if(!(this instanceof u))return new u(e,t);if(e instanceof u)return e;typeof e=="string"&&(e=this.select(e,t)),e&&e.nodeName&&(e=[e]),this.nodes=this.slice(e)};u.prototype={get length(){return this.nodes.length}},u.prototype.nodes=[],u.prototype.addClass=function(){return this.eacharg(arguments,function(e,t){e.classList.add(t)})},u.prototype.adjacent=function(e,t,n){return typeof t=="number"&&(t===0?t=[]:t=new Array(t).join().split(",").map(Number.call,Number)),this.each(function(s,o){var i=document.createDocumentFragment();u(t||{}).map(function(t,n){var i=typeof e=="function"?e.call(this,t,n,s,o):e;return typeof i=="string"?this.generate(i):u(i)}).each(function(e){this.isInPage(e)?i.appendChild(u(e).clone().first()):i.appendChild(e)}),n.call(this,s,i)})},u.prototype.after=function(e,t){return this.adjacent(e,t,function(e,t){e.parentNode.insertBefore(t,e.nextSibling)})},u.prototype.append=function(e,t){return this.adjacent(e,t,function(e,t){e.appendChild(t)})},u.prototype.args=function(e,t,n){return typeof e=="function"&&(e=e(t,n)),typeof e!="string"&&(e=this.slice(e).map(this.str(t,n))),e.toString().split(/[\s,]+/).filter(function(e){return e.length})},u.prototype.array=function(e){e=e;var t=this;return this.nodes.reduce(function(n,s,o){var i;return e?(i=e.call(t,s,o),i||(i=!1),typeof i=="string"&&(i=u(i)),i instanceof u&&(i=i.nodes)):i=s.innerHTML,n.concat(i!==!1?i:[])},[])},u.prototype.attr=function(e,t,n){return n=n?"data-":"",this.pairs(e,t,function(e,t){return e.getAttribute(n+t)},function(e,t,s){s?e.setAttribute(n+t,s):e.removeAttribute(n+t)})},u.prototype.before=function(e,t){return this.adjacent(e,t,function(e,t){e.parentNode.insertBefore(t,e)})},u.prototype.children=function(e){return this.map(function(e){return this.slice(e.children)}).filter(e)},u.prototype.clone=function(){return this.map(function(e){var n=e.cloneNode(!0),s=this.getAll(n);return this.getAll(e).each(function(e,t){for(var n in this.mirror)this.mirror[n]&&this.mirror[n](e,s.nodes[t])}),n})},u.prototype.getAll=function(t){return u([t].concat(u("*",t).nodes))},u.prototype.mirror={},u.prototype.mirror.events=function(e,t){if(!e._e)return;for(var n in e._e)e._e[n].forEach(function(e){u(t).on(n,e.callback)})},u.prototype.mirror.select=function(e,t){u(e).is("select")&&(t.value=e.value)},u.prototype.mirror.textarea=function(e,t){u(e).is("textarea")&&(t.value=e.value)},u.prototype.closest=function(e){return this.map(function(t){do if(u(t).is(e))return t;while((t=t.parentNode)&&t!==document)})},u.prototype.data=function(e,t){return this.attr(e,t,!0)},u.prototype.each=function(e){return this.nodes.forEach(e.bind(this)),this},u.prototype.eacharg=function(e,t){return this.each(function(n,s){this.args(e,n,s).forEach(function(e){t.call(this,n,e)},this)})},u.prototype.empty=function(){return this.each(function(e){for(;e.firstChild;)e.removeChild(e.firstChild)})},u.prototype.filter=function(e){var t=function(t){return t.matches=t.matches||t.msMatchesSelector||t.webkitMatchesSelector,t.matches(e||"*")};return typeof e=="function"&&(t=e),e instanceof u&&(t=function(t){return e.nodes.indexOf(t)!==-1}),u(this.nodes.filter(t))},u.prototype.find=function(e){return this.map(function(t){return u(e||"*",t)})},u.prototype.first=function(){return this.nodes[0]||!1},u.prototype.generate=function(e){return/^\s*<tr[> ]/.test(e)?u(document.createElement("table")).html(e).children().children().nodes:/^\s*<t(h|d)[> ]/.test(e)?u(document.createElement("table")).html(e).children().children().children().nodes:/^\s*</.test(e)?u(document.createElement("div")).html(e).children().nodes:document.createTextNode(e)},u.prototype.handle=function(){var e=this.slice(arguments).map(function(e){return typeof e=="function"?function(t){t.preventDefault(),e.apply(this,arguments)}:e},this);return this.on.apply(this,e)},u.prototype.hasClass=function(){return this.is("."+this.args(arguments).join("."))},u.prototype.html=function(e){return e===void 0?this.first().innerHTML||"":this.each(function(t){t.innerHTML=e})},u.prototype.is=function(e){return this.filter(e).length>0},u.prot
|