-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGStime.min.js
More file actions
2 lines (2 loc) · 9.27 KB
/
GStime.min.js
File metadata and controls
2 lines (2 loc) · 9.27 KB
1
2
/* GStime.js v1.4.0 | GLOBUS.studio | MIT License */
(t=>{let e="undefined"!=typeof document;function r(t){if(!(this instanceof r))return new r(t);this.elements=[],e&&("string"==typeof t?t.startsWith("<")&&t.endsWith(">")?this.elements=[this.createHTML(t)]:this.elements=Array.from(document.querySelectorAll(t)):t instanceof Element?this.elements=[t]:(t instanceof NodeList||Array.isArray(t))&&(this.elements=Array.from(t)))}r.prototype.createHTML=function(t){var e=document.createElement("div");return e.innerHTML=t.trim(),e.firstChild},r.prototype.each=function(n){return this.elements.forEach((t,e)=>n.call(t,e,t)),this},r.prototype.on=function(t,i,o){return"function"==typeof i?(o=i,i=null,this.each(function(){this.addEventListener(t,o,!1)})):this.each(function(){this.addEventListener(t,function(t){var e,n=document.querySelectorAll(i);let r=t.target;for(;r&&r!==this;)Array.from(n).includes(r)&&((e=Object.create(t)).currentTarget=r,o.call(r,e)),r=r.parentNode},!1)})},r.prototype.off=function(t,e){return this.each(function(){this.removeEventListener(t,e,!1)})},r.prototype.val=function(t){return void 0===t?this.elements[0]?this.elements[0].value:void 0:this.each(function(){this.value=t})},r.prototype.append=function(t){return this.each(function(){this.insertAdjacentHTML("beforeend",t)})},r.prototype.prepend=function(t){return this.each(function(){this.insertAdjacentHTML("afterbegin",t)})},r.prototype.html=function(t){return void 0===t?this.elements[0]?this.elements[0].innerHTML:void 0:this.each(function(){this.innerHTML=t})},r.prototype.css=function(t,e){return"string"==typeof t&&void 0===e?this.elements[0]?getComputedStyle(this.elements[0])[t]:void 0:this.each(function(){"object"==typeof t?Object.assign(this.style,t):this.style[t]=e})},r.prototype.hide=function(){return this.css("display","none")},r.prototype.show=function(){return this.css("display","")},r.prototype.toggle=function(){return this.each(function(){this.style.display="none"===this.style.display?"":"none"})},r.prototype.clone=function(){return new r(this.elements.map(t=>t.cloneNode(!0)))},r.prototype.animate=function(o,e,n){let r=performance.now(),s=this.elements.map(e=>Object.fromEntries(Object.keys(o).map(t=>[t,parseFloat(getComputedStyle(e)[t])||0]))),a=t=>{t-=r;let i=Math.min(t/e,1);this.elements.forEach((t,e)=>{for(var n in o){var r=s[e][n],r=r+(parseFloat(o[n])-r)*i;t.style[n]=r+"px"}}),i<1?requestAnimationFrame(a):"function"==typeof n&&n()};return requestAnimationFrame(a),this},r.prototype.fadeOut=function(t,e){return this.animate({opacity:0},t,()=>{this.hide(),"function"==typeof e&&e()})},r.prototype.fadeIn=function(t,e){return this.show().css("opacity",0).animate({opacity:1},t,e)},r.prototype.hasClass=function(t){return!!this.elements[0]&&this.elements[0].classList.contains(t)},r.prototype.addClass=function(t){return this.each(function(){this.classList.add(t)})},r.prototype.removeClass=function(t){return this.each(function(){this.classList.remove(t)})},r.prototype.toggleClass=function(t){return this.each(function(){this.classList.toggle(t)})},r.prototype.attr=function(t,e){return void 0===e?this.elements[0]?this.elements[0].getAttribute(t):void 0:this.each(function(){this.setAttribute(t,e)})},r.prototype.removeAttr=function(t){return this.each(function(){this.removeAttribute(t)})},r.prototype.width=function(t){return void 0===t?this.elements[0]?this.elements[0].offsetWidth:void 0:this.css("width","number"==typeof t?t+"px":t)},r.prototype.height=function(t){return void 0===t?this.elements[0]?this.elements[0].offsetHeight:void 0:this.css("height","number"==typeof t?t+"px":t)},r.prototype.offset=function(){var t;if(this.elements[0])return{top:(t=this.elements[0].getBoundingClientRect()).top+window.pageYOffset,left:t.left+window.pageXOffset}},r.prototype.position=function(){return this.elements[0]?{top:this.elements[0].offsetTop,left:this.elements[0].offsetLeft}:void 0},r.get=function(t,e,n){return r.ajax({url:t,method:"GET",data:e,...n})},r.post=function(t,e,n){return r.ajax({url:t,method:"POST",data:e,...n})},r.put=function(t,e,n){return r.ajax({url:t,method:"PUT",data:e,...n})},r.delete=function(t,e,n){return r.ajax({url:t,method:"DELETE",data:e,...n})},r.ajax=function(n){return new Promise((t,e)=>{if(n&&void 0!==n.url){let r={method:"GET",headers:{},timeout:0,...n};if(r.beforeSend&&!1===r.beforeSend())e(new Error("Request aborted by beforeSend callback"));else{if(r.data){if("GET"===r.method.toUpperCase())r.url+="?"+new URLSearchParams(r.data);else if("object"==typeof r.data)if(r.headers["Content-Type"]){if(r.headers["Content-Type"].includes("application/x-www-form-urlencoded"))r.body=new URLSearchParams(r.data).toString();else if(r.headers["Content-Type"].includes("multipart/form-data")){var i,o=new FormData;for(i in r.data)o.append(i,r.data[i]);r.body=o,delete r.headers["Content-Type"]}}else r.headers["Content-Type"]="application/json",r.body=JSON.stringify(r.data);else r.body=r.data;delete r.data}let n;var s,a=fetch(r.url,r);function l(t){var e;if(t.ok)return(e=t.headers.get("content-type"))&&e.includes("application/json")?t.json():e&&e.includes("text")?t.text():e&&e.includes("xml")?t.text().then(t=>(new DOMParser).parseFromString(t,"text/xml")):t.blob();throw new Error("HTTP error! status: "+t.status)}function p(t){r.error&&r.error(t),e(t)}0<r.timeout?(s=new Promise((t,e)=>{n=setTimeout(()=>{e(new Error(`Request timeout after ${r.timeout}ms`))},r.timeout)}),Promise.race([a,s]).then(l).catch(p).finally(()=>clearTimeout(n))):a.then(l).catch(p)}}else e(new Error("A URL is required for the ajax request"))})},r.prototype.after=function(t){return this.each(function(){this.insertAdjacentHTML("afterend",t)})},r.prototype.before=function(t){return this.each(function(){this.insertAdjacentHTML("beforebegin",t)})},r.prototype.remove=function(){return this.each(function(){this.parentNode.removeChild(this)})},r.prototype.parent=function(){return new r(this.elements.map(t=>t.parentNode).filter(Boolean))},r.prototype.children=function(){return new r(this.elements.flatMap(t=>Array.from(t.children)))},r.prototype.siblings=function(){return new r(this.elements.flatMap(e=>Array.from(e.parentNode.children).filter(t=>t!==e)))},r.prototype.find=function(e){return new r(this.elements.flatMap(t=>Array.from(t.querySelectorAll(e))))},r.prototype.closest=function(e){return new r(this.elements.map(t=>t.closest(e)).filter(Boolean))},r.each=function(t,n){if(Array.isArray(t))t.forEach((t,e)=>n.call(t,e,t));else for(var e in t)t.hasOwnProperty(e)&&n.call(t[e],e,t[e]);return t},r.map=function(t,e){if(Array.isArray(t))return t.map(e);var n,r={};for(n in t)t.hasOwnProperty(n)&&(r[n]=e.call(t[n],n,t[n]));return r},r.ready=function(t){e&&("loading"!==document.readyState?t():document.addEventListener("DOMContentLoaded",t))},r.prototype.slideUp=function(i,o){return this.each(function(){let n=this;var t=n.offsetHeight;let r={overflow:n.style.overflow,height:n.style.height,paddingTop:n.style.paddingTop,paddingBottom:n.style.paddingBottom,marginTop:n.style.marginTop,marginBottom:n.style.marginBottom};n.style.overflow="hidden",n.style.height=t+"px",requestAnimationFrame(()=>{n.style.height="0px",n.style.paddingTop="0px",n.style.paddingBottom="0px",n.style.marginTop="0px",n.style.marginBottom="0px",n.style.transition=`height ${i}ms, padding ${i}ms, margin ${i}ms`;function e(){for(var t in n.style.display="none",r)n.style[t]=r[t];n.style.transition="",n.removeEventListener("transitionend",e),"function"==typeof o&&o.call(n)}n.addEventListener("transitionend",e,{once:!0})})})},r.prototype.slideDown=function(r,i){return this.each(function(){let e=this,n=(e.style.overflow="hidden",e.style.display="block",e.style.height="0px",e.style.paddingTop="0px",e.style.paddingBottom="0px",e.style.marginTop="0px",e.style.marginBottom="0px",e.scrollHeight);requestAnimationFrame(()=>{e.style.transition=`height ${r}ms, padding ${r}ms, margin ${r}ms`,e.style.height=n+"px",e.style.paddingTop="",e.style.paddingBottom="",e.style.marginTop="",e.style.marginBottom="";function t(){e.style.height="",e.style.overflow="",e.style.transition="",e.removeEventListener("transitionend",t),"function"==typeof i&&i.call(e)}e.addEventListener("transitionend",t,{once:!0})})})},r.prototype.slideToggle=function(t,e){return this.each(function(){"none"===window.getComputedStyle(this).display?new r(this).slideDown(t,e):new r(this).slideUp(t,e)})},r.prototype.colorAnimate=function(i,e,n){function o(t){if(!t)return[0,0,0,0];if(t.startsWith("rgb"))return t.match(/[\d.]+/g).map(Number);if(t.startsWith("#")){if(4===t.length)return[parseInt(t[1]+t[1],16),parseInt(t[2]+t[2],16),parseInt(t[3]+t[3],16),1];if(7===t.length)return[parseInt(t.substring(1,3),16),parseInt(t.substring(3,5),16),parseInt(t.substring(5,7),16),1];if(9===t.length)return[parseInt(t.substring(1,3),16),parseInt(t.substring(3,5),16),parseInt(t.substring(5,7),16),parseInt(t.substring(7,9),16)/255]}return[0,0,0,1]}let s=performance.now(),a={},l=(this.elements.forEach(t=>{var e,n=getComputedStyle(t);for(e in i)a[e]||(a[e]={}),a[e][t]=o(n[e])}),t=>{t-=s;let r=Math.min(t/e,1);this.elements.forEach(t=>{for(var e in i){var n=((t,n,r)=>t.map((t,e)=>Math.round(t+(n[e]-t)*r)))(a[e][t],o(i[e]),r);4===n.length?t.style[e]=`rgba(${n[0]}, ${n[1]}, ${n[2]}, ${n[3]})`:t.style[e]=`rgb(${n[0]}, ${n[1]}, ${n[2]})`}}),r<1?requestAnimationFrame(l):"function"==typeof n&&n()});return requestAnimationFrame(l),this},t.GStime=r,t.$=function(t){return new r(t)}})("undefined"!=typeof window?window:this);