This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
luery.min.js
1 lines (1 loc) · 5.6 KB
/
luery.min.js
1
"use strict";(_=>{function luery(e){return new luery.prototype.I(e)}window.luery=luery,eval("window."+(window.lueryShortCut||"$")+" = luery;"),luery.prototype={constructor:luery,I:function(e){if(e){if("string"==typeof e){let t=document.querySelectorAll(e);return 0==t.length?[]:1==t.length&&e.match(/^.*#[^\s]*$/)?t[0]:t}}else luery.E()}},luery.addFunc=luery.prototype.addFunc=function(e){for(let t in e)this[t]=e[t]},luery.addFunc({E:e=>{throw new TypeError(`Invalid argument${e?" ":""}${void 0===e?"":e}`)},Events:(e,t,r)=>{if(0==e.length&&luery.E(),(e+"").indexOf("NodeList")+1){if(!((e+"").indexOf("Element")+1))for(let s=0;s<e.length;s++)e[s].addEventListener(t,r)}else e.addEventListener(t,r)},dEvents:(e,t,r)=>{if(0==e.length&&luery.E(),(e+"").indexOf("NodeList")+1){if(!((e+"").indexOf("Element")+1))for(let s=0;s<e.length;s++)e[s].removeEventListener(t,r)}else e.removeEventListener(t,r)},isJSONText:e=>{if("string"==typeof e)try{let t=JSON.parse(e);return!("object"!=typeof t||!t)}catch(e){return!1}return!1},isJSONObject:e=>{if("object"==typeof e)try{let t=JSON.stringify(e);return!("string"!=typeof t||!t)}catch(e){return!1}return!1},getCookie:e=>{let t=document.cookie.split(";"),r=e+"=";for(let s=0;s<t.length;s++){let n=t[s].trim();if(!n.indexOf(e))return n.substring(r.length,n.length)}return""},setCookie:(e,t,r)=>{let s=new Date;return s.setTime(s.getTime()+24*r*60*60*1e3),document.cookie=e+"="+t+"; expires="+s.toUTCString(),luery.getCookie(e)},removeCookie:e=>{luery.setCookie(e,"",-1)},scrollBarWidth:e=>{let t,r,s;return s=void 0===e?document.createElement("div"):e.cloneNode(!0),s.css({position:"absolute",top:"-9999px",width:"999px",height:"999px",overflow:"hidden"}),t=document.body.appendChild(s).clientWidth,s.css("overflow","scroll"),r=s.clientWidth,document.body.removeChild(s),t-r},dom:(e,t)=>{var r=0;return-1!=t.indexOf("-")?(-1!=t.indexOf("--")&&(n("width"),t.replace("--","-")),s(t.substring(0,t.indexOf("-")),"left"),s(t.substring(t.indexOf("-")+1,t.length),"right")):-1!=!t.indexOf("|")&&(-1!=t.indexOf("||")&&(n("height"),t.replace("||","|")),s(t.substring(0,t.indexOf("|")),"top"),s(t.substring(t.indexOf("|")+1,t.length),"bottom")),r;function s(e,t){-1!=e.indexOf("m")&&(r+=i("margin-"+t)),-1!=e.indexOf("b")&&(r+=i("border-"+t+"-width")),-1!=e.indexOf("p")&&(r+=i("padding-"+t))}function n(t){if("auto"==e.css(t)){var s=e.cloneNode(!0);s.css({display:"block",position:"absolute",top:"-9999rem"}),document.body.append(s),r+=i(t,s),document.body.removeChild(s)}else r+=i(t)}function i(t,r){return null==r&&(r=e),parseFloat(r.css(t).replace("px",""))}},rect:(e,t)=>{var r=luery,s=r.rect;switch(t){case"t":return i("top");case"b":return s(e,"t")+r.dom(e,"bp||pb");case"l":return i("left");case"r":return s(e,"l")+r.dom(e,"bp--pb");case"ft":return n().t;case"fb":return s(e,"ft")+r.dom(e,"bp||pb");case"fl":return n().l;case"fr":return s(e,"fl")+r.dom(e,"bp--pb");default:r.E()}function n(){for(var t=e.offsetTop,r=e.offsetLeft,s=e.offsetParent;null!==s;)t+=s.offsetTop,r+=s.offsetLeft,s=s.offsetParent;return{t:t,l:r}}function i(t,r){return null==r&&(r=e),parseFloat(r.css(t).replace("px",""))}}})})(),(e=>{var t=luery;if(NodeList){let e=NodeList.prototype;e.css=function(e,r){void 0!==r||t.isJSONObject(e)||t.E();for(let t=0;t<this.length;t++)if(void 0!==r)this[t].style.setProperty(e,r);else for(let r in e)this[t].style.setProperty(r,e[r]);return this},e.addClass=function(e){for(let t=0;t<this.length;t++)this[t].addClass(e);return this},e.removeClass=function(e){for(let t=0;t<this.length;t++)this[t].removeClass(e);return this},e.hide=function(){return this.css("display","none"),this},e.show=function(){return this.css("display",""),this},e.attr=function(e,t){for(let r=0;r<this.length;r++)this[r].attr(e,t);return this}}else lueryFail();if(HTMLElement&&SVGElement){let e=SVGElement.prototype,r=HTMLElement.prototype;e.css=r.css=function(e,r){if(void 0!==r)return this.style.setProperty(e,r),this;if(t.isJSONObject(e)){for(let t in e)this.style.setProperty(t,e[t]);return this}return getComputedStyle?document.defaultView.getComputedStyle(this,!1)[e]:Element.currentStyle[e]},e.hasClass=r.hasClass=function(e){return!!this.className.match(new RegExp("(\\s|^)"+e+"(\\s|$)"))},e.addClass=r.addClass=function(e){return e||t.E(),this.hasClass(e)||(""==this.className?this.className+=e:this.className+=" "+e),this},e.removeClass=r.removeClass=function(e){if(e.match(" ")){e=e.split(" ");for(let t=0;t<e.length;t++)this.removeClass(e[t])}else this.hasClass(e)&&(this.className=this.className.replace(e,""),this.className=this.className.replace(/^\s+|\s+$/g,""),this.className=this.className.replace(" "," "));return this},e.parent=r.parent=function(){return this.parentNode||this.parentElement},e.hide=r.hide=function(){return this.css("display","none"),this},e.show=r.show=function(){return this.css("display","unset"),this},e.isInClass=r.isInClass=function(e){e||t.E();let r=this;if(r===e)return!1;for(;"HTML"!=r.tagName;){if(r.hasClass(e))return!0;r=r.parent()}return!1},e.isInId=r.isInId=function(e){e||t.E();let r=this;if(r===e)return!1;for(;"HTML"!=r.tagName;){if(r.id===e)return!0;r=r.parent()}return!1},e.isInElement=r.isInElement=function(e){e||t.E();let r=this;if(r===e)return!1;for(;"HTML"!=r.tagName;){if(r===e)return!0;r=r.parent()}return!1},e.isChildOf=r.isChildOf=function(e){e||t.E();var r=e.childNodes;for(let e=0;e<r.length;e++)if(r[e]===this)return!0;return!1},e.getParentByClass=r.getParentByClass=function(e){e||t.E();let r=this;for(r=r.parent();"HTML"!=r.tagName;){if(r.hasClass(e))return r;r=r.parent()}return null},e.attr=r.attr=function(e,t){return void 0===t?this.getAttribute(e):(null===t?this.removeAttribute(e):this.setAttribute(e,t),this)}}else lueryFail()})();