-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathatomical.min.js
7 lines (7 loc) · 8.61 KB
/
atomical.min.js
1
2
3
4
5
6
7
/*!
* AtomicalJS v2.7.0 - Ultra Lightweight Vanilla Javascript jQuery alternative.
* Copyright 2019-2023 Silvio Delgado (https://github.com/silviodelgado)
* Licensed under MIT (https://opensource.org/licenses/MIT)
* https://github.com/silviodelgado/AtomicalJS
*/
(function(e,t){"function"==typeof define&&define.amd?define([],t(e)):(e.noConflict=e.$,e.$=t(e),e.atomical=t(e))})("undefined"!=typeof global?global:this.window||this.global,function(e){"use strict";const t={$el:null,$elems:[],$noConflict:!1},l=function(e,l,o){if("string"==typeof e&&0===e.indexOf("<")){var n=document.createElement("div");return n.innerHTML=e,o?1===n.children.length?n.children[0]:n.children:(t.$elems=Array.from(n.children),void(t.$el=1===n.children.length?n.children[0]:n.children))}if("object"==typeof e)return o?e:(t.$elems=[e],void(t.$el=e));if(e){let n=(l||document).querySelectorAll(e),s=Array.from(n);return o?1===n.length?s[0]:n:(t.$elems=s,void(t.$el=1===n.length?s[0]:n))}},o=(n,s)=>(t.$noConflict||(e.$=o),l(n,s),o);o.count=(()=>t.$elems.length),o.off=(()=>"object"==typeof t.$el&&0==t.$elems.length?o:(t.$elems.forEach((e,t)=>{if(null==e.parentNode)return o;e.parentNode.replaceChild(e.cloneNode(!0),e)}),o)),o.on=((e,l)=>"object"==typeof t.$el&&0==t.$elems.length?o:"function"!=typeof l?o:(t.$elems.forEach((t,o)=>{t.addEventListener(e,l)}),o)),o.show=(()=>void 0===t.$el||0==t.$elems.length?o:void 0===t.$el.length?(t.$el.style.display="",o):(t.$elems.forEach((e,t)=>{e.style.display=""}),o)),o.hide=(()=>void 0===t.$el||0==t.$elems.length?o:void 0===t.$el.length?(t.$el.style.display="none",o):(t.$elems.forEach((e,t)=>{e.style.display="none"}),o)),o.toggle=(()=>void 0===t.$el||0==t.$elems.length?o:(t.$elems.forEach((e,t)=>{e.style.display="none"==e.style.display?null:"none"}),o)),o.fadeIn=(e=>void 0===t.$el||0==t.$elems.length?o:(t.$elems.forEach(function(t,l){t.style.opacity=0,t.style.display=null,setTimeout(function(){t.style.transition="opacity 400ms ease 0s",t.style.opacity=1,t.style.display=null,e&&"function"==typeof e&&e.call(this)},50)}),o)),o.fadeOut=(e=>void 0===t.$el||0==t.$elems.length?o:(t.$elems.forEach((t,l)=>{t.style.transition="opacity 400ms ease 0s",t.style.opacity=0,setTimeout(()=>{t.style.display="none",e&&"function"==typeof e&&e.call(this)},400)}),o)),o.attr=((e,l)=>void 0===t.$el||0==t.$elems.length?o:void 0!==l?(t.$elems.forEach((t,o)=>{t.setAttribute(e,l)}),o):void 0===t.$el.length?t.$el.getAttribute(e):void 0),o.removeAttr=(e=>void 0===t.$el||0==t.$elems.length?o:(t.$elems.forEach((t,l)=>{t.removeAttribute(e)}),o)),o.val=(e=>void 0===t.$el||0==t.$elems.length?o:void 0!==e?(t.$elems.forEach((t,l)=>{t.value=e}),o):void 0===t.$el.length?t.$el.value:void 0),o.focus=(()=>void 0===t.$el||0==t.$elems.length?o:void 0!==t.$el.length?o:(t.$elems[0].focus(),o)),o.data=((e,l)=>void 0===t.$el||0==t.$elems.length?o:void 0!==l?(t.$elems.forEach((t,o)=>{t.setAttribute("data-"+e,l)}),o):void 0===t.$el.length?t.$el.getAttribute("data-"+e):void 0),o.hasClass=(e=>void 0!==t.$el&&0!=t.$elems.length&&(void 0===t.$el.length&&t.$el.className.indexOf(e)>=0)),o.addClass=(e=>{if(void 0===t.$el||0==t.$elems.length)return o;let l=e.split(" ").join(",");return t.$elems.forEach((e,t)=>{e.classList.add(l)}),o}),o.removeClass=(e=>{if(void 0===t.$el||0==t.$elems.length)return o;let l=e.split(" ");return t.$elems.forEach((e,t)=>{l.map(t=>{e.classList.remove(t)})}),o}),o.toggleClass=(e=>{if(void 0===t.$el||0==t.$elems.length)return o;let l=e.split(" ");return t.$elems.forEach((e,t)=>{l.map(t=>{e.classList.toggle(t)})}),o}),o.css=((e,l)=>void 0===t.$el||0==t.$elems.length?o:void 0!==l?(t.$elems.forEach((t,o)=>{t.style[e]=l}),o):void 0!==t.$el.length?o:(t.$el.style[e],o)),o.toggleProperty=((e,l)=>void 0===t.$el||0==t.$elems.length?o:void 0!==l?(t.$elems.forEach((t,o)=>{t.style[e]=""==t.style[e]?l:null}),o):void 0!==t.$el.length?o:(t.$el[e]=l,o)),o.prependTo=((e,n)=>{if(void 0===t.$el||0==t.$elems.length)return o;let s=l(e,n,!0);return"object"!=typeof s?o:(s.insertBefore(t.$el,s.firstChild),o)}),o.appendTo=((e,n)=>{if(void 0===t.$el||0==t.$elems.length)return o;let s=l(e,n,!0);return"object"!=typeof s?o:(s.appendChild(t.$el),o)}),o.append=(e=>{if(void 0===t.$el||0==t.$elems.length)return o;var l=document.createElement("div");l.innerHTML=e;let n=Array.from(l.children);return t.$elems.forEach((e,t)=>{n.map(t=>{let l=document.createElement(t.tagName);l.innerHTML=t.innerHTML,e.appendChild(l)})}),o}),o.first=(()=>void 0===t.$el||0==t.$elems.length?null:t.$elems[0]),o.last=(()=>void 0===t.$el||0==t.$elems.length?null:t.$elems[t.$elems.length-1]),o.parent=(()=>void 0===t.$el||0==t.$elems.length?null:void 0!==t.$el.length?null:t.$el.parentNode),o.closest=(e=>{if(void 0===t.$el||0==t.$elems.length)return o;if(void 0!==t.$el.length)return;let l=t.$el.closest(e);return l}),o.remove=(()=>void 0===t.$el||0==t.$elems.length?o:(t.$elems.forEach((e,t)=>{e.parentNode.removeChild(e)}),o)),o.html=(e=>void 0===t.$el||0==t.$elems.length?o:void 0!==e?(t.$elems.forEach((t,l)=>{t.innerHTML=e}),o):void 0!==t.$el.length?o:t.$el.innerHTML),o.text=(e=>void 0===t.$el||0==t.$elems.length?o:void 0!==e?(t.$elems.forEach((t,l)=>{t.textContent=e}),o):void 0!==t.$el.length?o:t.$el.textContent),o.width=(e=>void 0===t.$el||0==t.$elems.length?o:void 0!==e?(t.$elems.forEach((t,l)=>{t.style.width=e+"px"}),o):void 0===t.$el.length?parseFloat(getComputedStyle(t.$el,null).width.replace("px","")):void 0),o.height=(e=>{if(void 0!==t.$el&&0!=t.$elems.length){if(void 0!==e)return t.$elems.forEach((t,l)=>{t.style.height=e+"px"}),o;if(void 0===t.$el.length)return parseFloat(getComputedStyle(t.$el,null).height.replace("px",""))}}),o.trigger=(e=>void 0===t.$el||0==t.$elems.length?o:(t.$elems.forEach((t,l)=>{if("click"===e){let e=new MouseEvent("click",{bubbles:!0,cancelable:!0,view:window});return void t.dispatchEvent(e)}let o=document.createEvent("HTMLEvents");o.initEvent(e,!0,!1),t.dispatchEvent(o)}),o)),o.el=(()=>void 0===t.$el||0===t.$elems.length?null:t.$elems),o.extend=function(e,t){if("object"!=typeof e||"object"!=typeof t)return!1;var l=Object.assign({},e);for(var n in t)t.hasOwnProperty(n)&&(n in l?"object"!=typeof l[n]?l[n]=t[n]:"object"!=typeof t[n]?l[n]=t[n]:l[n].concat&&t[n].concat?l[n]=e[n].concat(t[n]):l[n]=o.extend(l[n],t[n]):l[n]=t[n]);return l};const n={request:{data:{Accept:"application/json","Content-Type":"application/json;charset=UTF-8",IsAjaxRequest:!0,timeout:3e4},callback:()=>{},error:()=>{}},response:{data:{},callback:()=>{},error:()=>{}}};o.interceptors={request:{use:(e,t)=>{n.request.callback=e,n.request.error=t}},response:{use:(e,t)=>{n.response.callback=e,n.response.error=t}}};const s=e=>{const t=o.extend({isJSON:!0,resultJSON:!0,replaceHeaders:!1},e);if(null==t.url||""==t.url)return;let l=new AbortController,s=t.data||{};n.request.callback&&"function"==typeof n.request.callback&&(n.request.data=n.request.callback.call(this,n.request.data)||n.request.data);const r={method:t.method,headers:n.request.data,timeout:n.request.data.timeout,signal:l.signal};t.replaceHeaders&&(r.headers={}),void 0!==t.mode&&(r.mode=t.mode),r.headers=o.extend(r.headers,t.headers||{}),"POST"===t.method&&(r.body=t.isJSON?JSON.stringify(s):s);let i=fetch(t.url,r),a=setTimeout(()=>l.abort(),r.timeout);i.then(e=>{if(!e.ok)throw n.response.error&&"function"==typeof n.response.error&&n.response.error.call(this,e.statusText),Error(e.status+" "+e.statusText);return t.resultJSON?e.json():e.text()}).then(e=>{n.response.data.data=e||{},n.response.callback&&"function"==typeof n.response.callback&&(n.response.data=n.response.callback.call(this,n.response.data)||n.response.data),t.success&&"function"==typeof t.success&&t.success.call(this,n.response.data)}).catch(e=>{t.error&&"function"==typeof t.error&&t.error.call(this,e),n.request.error&&"function"==typeof n.request.error&&n.request.error.call(this,e),console.error("err",e)}).finally(()=>{clearTimeout(a),t.always&&"function"==typeof t.always&&t.always.call(this,err)})};return o.post=((e,t,l,n)=>{"object"==typeof l&&(n=l,l=null),"function"==typeof t&&(l=t,t={});let r=o.extend({url:e,data:t||{},success:l,method:"POST"},n||{});s(r)}),o.get=((e,t,l)=>{"object"==typeof t&&(l=t,t=null);let n=o.extend({url:e,method:"GET",success:t,resultJSON:!1},l||{});s(n)}),o.getJSON=((e,t,l)=>{"object"==typeof t&&(l=t,t=null);let n=o.extend({url:e,method:"GET",success:t},l||{});s(n)}),o.ready=(e=>void 0===t.$el||0==t.$elems.length?o:"function"==typeof e?"complete"===document.readyState?(window.setTimeout(e),o):void 0!==t.$el.length?o:(t.$el.addEventListener("DOMContentLoaded",e),o):void 0),o.each=((e,l)=>("function"==typeof e&&(l=e,e=t.$elems),Array.isArray(e)&&0!=e.length&&"function"==typeof l?(Array.prototype.forEach.call(e,l),o):o)),o.noConflict=(()=>{t.$noConflict=!0,e.$=e.noConflict}),o.fn=o.prototype={},o});