-
Notifications
You must be signed in to change notification settings - Fork 0
/
squery.min.js
1 lines (1 loc) · 9.8 KB
/
squery.min.js
1
"use strict";if("undefined"==typeof _PQ){class t{constructor(){this.ac=[],this.wa=[]}isW(t){const e=Object.prototype.toString.call(window);return function(t){let i,s,r;switch(i=Object.prototype.toString.call(t),e){case"[object DOMWindow]":case"[object Window]":case"[object global]":return i===e}if("self"in t){r=t.hasOwnProperty("self");try{r&&(s=t.self),delete t.self,r&&(t.self=s)}catch(t){return!0}}return!1}(t)}remove(t){t&&t.remove()}before(t,e){t&&t.insertAdjacentHTML("beforebegin",e)}after(t,e){t&&t.insertAdjacentHTML("afterend",e)}prepend(t,e){t&&t.insertAdjacentHTML("afterbegin",e)}append(t,e){t&&t.insertAdjacentHTML("beforeend",e)}prop(t,e,i){t&&t.style.setProperty(e,i)}addClass(t,e){t&&t.classList.add(e)}removeClass(t,e){t&&t.classList.remove(e)}toggleClass(t,e){t&&t.classList.toggle(e)}show(t,e="block"){t&&("none"===e&&(e="block"),t.style.visibility="visible",t.style.display=e,t.style.opacity=1)}hide(t){t&&(t.style.visibility="hidden",t.style.display="none",t.style.opacity=0)}animate(t,e,i,s,r,h){t&&("number"==typeof i&&(h=r,r=s,s=i,i=null),void 0===s&&(s=500),i||(i={}),i.duration||(i.duration=s),t.animate(e,i).onfinish=()=>{r&&r.bind(t)(),h&&h.bind(t)()})}isVisible(t){return!("none"===window.getComputedStyle(t).display||!t?.offsetHeight)}fadeIn(t,e,i,s="inline-block"){let r=parseFloat(t.style.opacity);isNaN(r)&&(r=this.isVisible(t)?1:0),this.animate(t,[{opacity:r},{opacity:1}],{easing:"ease-in"},e,(()=>{t.style.opacity=1}),i),this.show(t,s)}fadeOut(t,e,i){let s=parseFloat(t.style.opacity);isNaN(s)&&(s=1),this.animate(t,[{opacity:s},{opacity:0}],{easing:"ease-out"},e,(()=>{this.hide(t)}),i)}each(t,e,i){return e.apply(t,[i])}}class e{constructor(){this.b=0,this.el=[],this.disp=[],this.fOb={},this.v=void 0}_setEl(t){if(this.el=[],t){this.v=t?.value;let e=t.length;e||t instanceof NodeList?this.el=Array.from(t):0!==e?this.el=[t]:i.isW(t)&&(this.el=t)}this.length=this.el.length,this.b||(this.b=1),this._svD()}_th(){return this}_svD(){this.disp=[];let t=0;i.isW(this.el)||this.el?.forEach((e=>{if(this.disp[t]="none",e){let s="block";i.isW(e)||e===document||(s=window.getComputedStyle(e).display),s&&"none"!==s&&(this.disp[t]=s)}++t}))}setEl(t){return this._setEl(t),this}doc(){return this.setEl(document)}win(){return this.setEl(window)}ob(t){return this.setEl(t)}get(t=null){return null!==t?this.el[t]:this.el}_wh(t,e){return i.isW(this.el)?"width"==t?window.innerWidth:window.innerHeight:void 0!==e?(this.el?.forEach((i=>{"function"==typeof e&&(e=e()),i.style[t]="string"==typeof e?e:e+"px"})),this):parseFloat(getComputedStyle(this.el[0],null)[t].replace("px",""))}width(t){return this._wh("width",t)}height(t){return this._wh("height",t)}innerWidth(){return this.el[0].clientWidth}innerHeight(){return this.el[0].clientHeight}outerWidth(){return this.el[0].offsetWidth}outerHeight(){return this.el[0].offsetHeight}offset(){return this.el[0].getBoundingClientRect()}pos(){return{left:this.el[0].offsetLeft,top:this.el[0].offsetTop}}position(){return this.pos()}_fd(t,...e){let s=0;return this.el?.forEach((r=>{i[t](r,...e,this.disp[s++])})),this}show(){return this._fd("show")}fadeIn(t=500,e){return this._fd("fadeIn",t,e)}isVisible(){return i.isVisible(this.el)}_u(){if(!this.el||!this.el[0])return 1}_vs(t,e){if(!this._u())return void 0!==e?(this.el?.forEach((i=>i[t]=e)),this):this.el[0][t]}prop(t,e){return this._vs(t,e)}scrollTop(t){return this._vs("scrollTop",t)}scrollLeft(t){return this._vs("scrollLeft",t)}scroll(t,e){return e=e?"instant":"smooth",i.isW(this.el)?window.scroll({top:t,behavior:e}):(this.el?.forEach((i=>i.scroll({top:t,behavior:e}))),this)}scrollToElement(t=50,e){if(this._u())return this;e=e?"instant":"smooth";const i=document.body.getBoundingClientRect().top,s=this.el[0].getBoundingClientRect().top-i;return window.scrollTo({top:s-t,behavior:e}),this}animate(t,e,s,r){let h=()=>{this.css(t[1])};return"number"==typeof e&&(r=h),this.el?.forEach((n=>{i.animate(n,t,e,s,r,h)})),this}each(t){let e=0;return this.el?.every((s=>!1!==i.each(s,t,e++))),this}attr(t,e){if(!this._u())return void 0===e?this.el[0].getAttribute(t):(this.el.forEach((i=>i.setAttribute(t,e))),this)}data(t,e){if(!this._u())return void 0===e?this.el[0].dataset[t]:(this.el.forEach((i=>i.dataset[t]=e)),this)}removeData(t){return this.el.forEach((e=>delete e.dataset[t])),this}prop(t,e){if(!this._u())return void 0===e?this.el[0][t]:(this.el.forEach((i=>i[t]=e)),this)}removeAttr(t){return this.el.forEach((e=>e.removeAttribute(t))),this}removeProp(t){return this.removeAttr(t)}_fv(t,e){let i=this.el&&this.el[0];return null!==e?i?(this.el.forEach((i=>i[t]=e)),this):this:i?this.el[0][t]:void 0}html(t=null){return null===t||"object"!=typeof t||Array.isArray(t)?this._fv("innerHTML",t):(this._fv("innerHTML","").get(0).append(t),this)}oHtml(t){return void 0!==t?this.replaceWith(t):this.el[0]?.outerHTML}text(t=null){return this._fv("innerText",t)}val(t=null){return null===t&&void 0!==this.v?this.v:this._fv("value",t)}css(t,e=null){if(!this._u()){if(t){let i=(t,e)=>(t=t.replace(/-([a-z])/g,(function(t){return t[1].toUpperCase()})),null!==e?(this.el.forEach((i=>i.style[t]=e)),this):this.el[0].style[t]);return"object"==typeof t?(Object.keys(t).forEach((e=>i(e,t[e]))),this):i(t,e)}return this.el[0].style}}eq(t){return t<0&&(t=this.el.length+t),this.el&&this.el[t]?sq(this.el[t])._th():sq(0)._th()}not(t){if(this.el){let e=[];return this.el.forEach((i=>{i.matches(t)||e.push(i)})),sq(e)._th()}return this}filter(t){if(this.el){let e=[];return"function"==typeof t?this.el.forEach((i=>{Array.prototype.filter.call(i,t)&&e.push(i)})):this.el.forEach((i=>{i.matches(t)&&e.push(i)})),sq(e)._th()}return this}is(t){let e=!1;return this.el?.forEach((i=>{i.matches(t)&&(e=!0)})),e}find(t){if(this.el){let e=[];return this.el.forEach((i=>{let s=i.querySelectorAll(t);s.length&&(e=e.concat(Array.from(s)))})),sq(e)._th()}return this}has(t){if(this.el){let e=[];return this.el.forEach((i=>{i.querySelector(t)&&e.push(i)})),sq(e)._th()}return this}contains(t,e){if(this.el){let i=[];return this.el.forEach((s=>{(e&&s?.innerHTML.includes(t)||!e&&s?.innerText.includes(t))&&i.push(s)})),sq(i)._th()}return this}first(){return this.el?sq(this.el[0])._th():this}last(){return this.el?sq(this.el[this.el.length-1])._th():this}index(){if(!this.el)return-1;let t=0,e=this.el[0];for(;this.el[0]=this.el[0].previousElementSibling;)++t;return this.el[0]=e,t}slice(t,e){let i=[];if(this.el){let s=this.el.length;e||(e=s),t<0&&(t=s+t),e<0&&(e=s+e);for(let s=t;s<e;++s)i.push(this.el[s])}return sq(i)._th()}parent(){if(this.el){let t=[];return this.el.forEach((e=>{e?.parentNode&&t.push(e.parentNode)})),sq(t)._th()}return this}parents(){if(this.el){let t=[];return this.el.forEach((e=>{let i=e.parentNode;for(;i!==document;){let e=i;t.push(e),i=e?.parentNode}})),t=[...new Set(t)],sq(t)._th()}return this}closest(t){if(this.el){let e=[];return this.el.forEach((i=>{let s=i.closest(t);s&&e.push(s)})),e=[...new Set(e)],sq(e)._th()}return this}children(){if(this.el){let t=[];return this.el.forEach((e=>{e.children?.length&&(t=t.concat(Array.from(e.children)))})),sq(t)._th()}return this}prev(){if(this.el){let t=[];return this.el.forEach((e=>{e.previousElementSibling&&t.push(e.previousElementSibling)})),sq(t)._th()}return this}next(){if(this.el){let t=[];return this.el.forEach((e=>{e.nextElementSibling&&t.push(e.nextElementSibling)})),sq(t)._th()}return this}siblings(){if(this.el){let t=[];return this.el.forEach((e=>{if(e.parentNode){let i=e.parentNode.firstChild;for(;i;)1===i.nodeType&&i!==e&&t.push(i),i=i.nextSibling}})),sq(t)._th()}return this}_sAC(t,e){let s=i.ac.length;return i.ac[s]={ev:t,f:e},s}_sSA(t,e,i){if(!t.getAttribute)return;let s=t.getAttribute("sq-"+e);s||(s=""),s+=","+i,t.setAttribute("sq-"+e,s)}_sSW(t,e){let s=i.wa[t];s||(s=""),s+=","+e,i.wa[t]=s}onf(t,e,i){return this.el?.forEach((s=>{let r=t=>{let r=t.target;for(;r;){if(r.matches(e)&&!1===i.bind(s.querySelectorAll(e))(t))return t.preventDefault(),void t.stopImmediatePropagation();r=r.parentElement}},h=this._sAC(t,r);s.querySelectorAll(e)?.forEach((e=>this._sSA(e,t,h))),s.addEventListener(t,r)})),this}on(t,e){const s=t.split(" ");if(s.length>1)return s.forEach((t=>this.on(t,e))),this;let r=t=>{!1===e.bind(t.currentTarget)(t)&&(t.preventDefault(),t.stopImmediatePropagation())},h=this._sAC(t,r);return i.isW(this.el)?(this._sSW(t,h),window.addEventListener(t,r)):this.el?.forEach((e=>{this._sSA(e,t,h),e.addEventListener(t,r)})),this}off(t){const e=t.split(" ");if(e.length>1)return e.forEach((t=>this.off(t))),this;if(i.isW(this.el)){let e=i.wa[t]?.split(",");e?.forEach((e=>{i.ac[e]?.f&&window.removeEventListener(t,i.ac[e].f)}))}else this.el?.forEach((e=>{let s=e.getAttribute("sq-"+t)?.split(",");s?.forEach((s=>{i.ac[s]?.f&&(e.removeEventListener(t,i.ac[s].f),document.removeEventListener(t,i.ac[s].f))}))}));return this}trg(t,e=1,i=0){return this.el?.forEach((s=>{let r=new Event(t,{bubbles:e,composed:i});s.dispatchEvent(r)})),this}trigger(t,e=1,i=0){this.trg(t,e,i)}_f(t,...e){return this.el?.forEach((s=>{i[t](s,...e)})),this}remove(){return this._f("remove")}before(t){return this._f("before",t)}after(t){return this._f("after",t)}prepend(t){return this._f("prepend",t)}append(t){return this._f("append",t)}replaceWith(t){return this.el?.forEach((e=>e.outerHTML=t)),this}addClass(t){return this._f("addClass",t)}hasClass(t){return!!this.el[0]?.classList.contains(t)}removeClass(t){return this._f("removeClass",t)}toggleClass(t){return this._f("toggleClass",t)}_fsd(t,...e){return this.el?(this._svD(),this.el.forEach((s=>{i[t](s,...e)})),this):this}fadeOut(t=500,e){return this._fsd("fadeOut",t,e)}hide(){return this._fsd("hide")}isPageLoaded(){let t=document.readyState;return"complete"===t||"loaded"===t}}let i=new t;var sq=function(t){let i=new e,s=typeof t;if("string"!==s){if("function"===s)return void document.addEventListener("DOMContentLoaded",(e=>t(e)));switch(t){case document:return i.doc(t);case window:return i.win(t)}return i.ob(t)}return i.setEl(document.querySelectorAll(t))},sQuery=sq,_SQ=e.prototype}