|
|
|
const sq={default:function(t){const e=typeof t;return"string"===e?"<"===t[0]?this.build(t):sq.find(t):"object"===e?sq.wrap([t]):void document.addEventListener("DOMContentLoaded",t,!1)},build:function(t){let e=document.createElement("template");return e.innerHTML=t.trim(),sq.wrap([e.content.firstChild])},find:function(t){const e=(this[0]||document).querySelectorAll(t);return sq.wrap(e)},children:function(){return sq.wrap(this[0].children)},parent:function(){return sq.wrap([this[0].parentElement])},on:function(t,e){return this.each(n=>n.addEventListener(t,t=>{t.target=n,e(t)})),this},each:function(t){const e=this.length;for(let n=0;n<e;n++)t(this[n])},appendTo:function(t){return t="string"==typeof t?sq.find(t)[0]:t.on?t[0]:t,this.each(e=>t.appendChild(e)),this},prependTo:function(t){return t[0].insertBefore(this[0],t.children()[0]),this},remove:function(){this.each(t=>t.remove())},addClass:function(t){return t.split(" ").forEach(t=>this.each(e=>e.classList.add(t))),this},removeClass:function(t){return t.split(" ").forEach(t=>this.each(e=>e.classList.remove(t))),this},hasClass:function(t){return this[0].classList.contains(t)},toggleClass:function(t){this.hasClass(t)?this.removeClass(t):this.addClass(t)},show:function(){return this.each(t=>t.attributeStyleMap.set("display","block")),this},hide:function(){return this.each(t=>t.attributeStyleMap.set("display","none")),this},css:function(t,e){let n=t,i=arguments.length;return 1===i&&"string"==typeof t?(this[0].attributeStyleMap.get(t)||{}).value:(2===i&&(n={[t]:e}),Object.keys(n).forEach(t=>{let e=n[t];!["left","top","width","height"].includes(t)||e.indexOf&&-1!==e.indexOf("%")||(e+="px"),this.each(n=>e?n.attributeStyleMap.set(t,e):n.attributeStyleMap.delete(t))}),this)},empty:function(){let t=this[0];for(;t.firstChild;)t.removeChild(t.firstChild);return this},is:function(t){return this.width()&&this.height()},html:function(t){return arguments.length?(this[0].innerHTML=t,this):this[0].innerHTML},click:function(){return this[0].click(),this},next:function(){return sq.wrap([this[0].nextSibling])},scrollTop:function(t){if(!arguments.length)return this[0].scrollTop;this[0].scrollTop=t},val:function(t){return arguments.length?(this[0].value=t,this):this[0].value},attr:function(t,e){return 1===arguments.length?this[0].getAttribute(t):(this[0].setAttribute(t,e),this)},insertAfter:function(t){return t[0].parentNode.insertBefore(this[0],t[0].nextSibling),this},insertBefore:function(t){return t[0].parentNode.insertBefore(this[0],t[0]),this},index:function(){let t=this[0];return Array.prototype.indexOf.call(t.parentElement.children,t)},offset:function(){return this[0].getBoundingClientRect()},data:function(t,e){return this.dataSet||(this.dataSet={}),1===arguments.length?this.dataSet[t]:(this.dataSet[t]=e,this)},removeData:function(t){this.dataSet&&delete this.dataSet[t]},wrap:function(t){let e={length:t.length};Object.keys(sq).forEach(t=>e[t]=sq[t].bind(e));for(let n=0;n<t.length;n++)e[n]=t[n];return e},width:function(){return this[0].offsetWidth},height:function(){return this[0].offsetHeight},eq:function(t){return sq.wrap([this[t]])},focus:function(){return this[0].focus(),this},cloneRecursive:function(t,e){if("object"!=typeof t)return t;if(!t)return t;if(t instanceof Array){e&&e.push||(e=[]);for(let n=0;n<t.length;n++)e[n]=sq.cloneRecursive(t[n],e[n]);return e}e||(e={});for(let n in t)t.hasOwnProperty(n)&&(e[n]=sq.cloneRecursive(t[n],e[n]));return e},extend:function(t,e){let n=arguments.length;for(let t=2;t<n;t++)sq.cloneRecursive(arguments[t],e);return e}};window.$=sq.default.bind(sq),Object.keys(sq).forEach(t=>window.$[t]=sq[t].bind(sq)); |
|
|
|
const sq={default:function(t){const e=typeof t;return"string"===e?"<"===t[0]?this.build(t):sq.find(t):"object"===e?sq.wrap([t]):void document.addEventListener("DOMContentLoaded",t,!1)},build:function(t){let e=document.createElement("template");return e.innerHTML=t.trim(),sq.wrap([e.content.firstChild])},find:function(t){const e=(this[0]||document).querySelectorAll(t);return sq.wrap(e)},children:function(){return sq.wrap(this[0].children)},parent:function(){return sq.wrap([this[0].parentElement])},on:function(t,e){return this.each(n=>n.addEventListener(t,t=>{t.target=n,e(t)})),this},each:function(t){const e=this.length;for(let n=0;n<e;n++)t(this[n])},appendTo:function(t){return t="string"==typeof t?sq.find(t)[0]:t.on?t[0]:t,this.each(e=>t.appendChild(e)),this},prependTo:function(t){return t[0].insertBefore(this[0],t.children()[0]),this},remove:function(){this.each(t=>t.remove())},addClass:function(t){return t.split(" ").forEach(t=>this.each(e=>e.classList.add(t))),this},removeClass:function(t){return t.split(" ").forEach(t=>this.each(e=>e.classList.remove(t))),this},hasClass:function(t){return this[0].classList.contains(t)},toggleClass:function(t){this.hasClass(t)?this.removeClass(t):this.addClass(t)},show:function(){return this.each(t=>t.attributeStyleMap.set("display","block")),this},hide:function(){return this.each(t=>t.attributeStyleMap.set("display","none")),this},css:function(t,e){let n=t,i=arguments.length;return 1===i&&"string"==typeof t?(this[0].attributeStyleMap.get(t)||{}).value:(2===i&&(n={[t]:e}),Object.keys(n).forEach(t=>{let e=n[t];!["left","top","width","height"].includes(t)||e.indexOf&&-1!==e.indexOf("%")||(e+="px"),this.each(n=>e?n.attributeStyleMap.set(t,e):n.attributeStyleMap.delete(t))}),this)},empty:function(){let t=this[0];for(;t.firstChild;)t.removeChild(t.firstChild);return this},is:function(t){return this.width()&&this.height()},html:function(t){return arguments.length?(this[0].innerHTML=t,this):this[0].innerHTML},click:function(){return this[0].click(),this},next:function(){return sq.wrap([this[0].nextSibling])},scrollTop:function(t){if(!arguments.length)return this[0].scrollTop;this[0].scrollTop=t},val:function(t){return arguments.length?(this[0].value=t,this):this[0].value},attr:function(t,e){return 1===arguments.length?this[0].getAttribute(t):(this[0].setAttribute(t,e),this)},insertAfter:function(t){return t[0].parentNode.insertBefore(this[0],t[0].nextSibling),this},insertBefore:function(t){return t[0].parentNode.insertBefore(this[0],t[0]),this},index:function(){let t=this[0];return Array.prototype.indexOf.call(t.parentElement.children,t)},offset:function(){return this[0].getBoundingClientRect()},data:function(t,e){return this.dataSet||(this.dataSet={}),1===arguments.length?this.dataSet[t]:(this.dataSet[t]=e,this)},removeData:function(t){return this.dataSet&&delete this.dataSet[t],this},wrap:function(t){let e={length:t.length};Object.keys(sq).forEach(t=>e[t]=sq[t].bind(e));for(let n=0;n<t.length;n++)e[n]=t[n];return e},width:function(){return this[0].offsetWidth},height:function(){return this[0].offsetHeight},eq:function(t){return sq.wrap([this[t]])},focus:function(){return this[0].focus(),this},cloneRecursive:function(t,e){if("object"!=typeof t)return t;if(!t)return t;if(t instanceof Array){e&&e.push||(e=[]);for(let n=0;n<t.length;n++)e[n]=sq.cloneRecursive(t[n],e[n]);return e}e||(e={});for(let n in t)t.hasOwnProperty(n)&&(e[n]=sq.cloneRecursive(t[n],e[n]));return e},extend:function(t,e){let n=arguments.length;for(let t=2;t<n;t++)sq.cloneRecursive(arguments[t],e);return e}};window.$=sq.default.bind(sq),Object.keys(sq).forEach(t=>window.$[t]=sq[t].bind(sq)); |