diff --git a/luery.js b/luery.js index fdf603a..a2b0aec 100644 --- a/luery.js +++ b/luery.js @@ -8,10 +8,10 @@ console.log("luery.js ©LJM12914\r\nhttps://github.com/ljm12914/luery\r\nYou are (_=>{ window.luery = luery; eval("window." + (window.lueryShortCut || "$") + " = luery;"); - function luery(s){return new luery.prototype.processInput(s);} + function luery(s){return new luery.prototype.I(s);} luery.p = luery.prototype = { constructor:luery, - processInput:function(s){ + I:function(s){ if(!s) luery.E(); else if(typeof s == "string"){ let a = document.querySelectorAll(s); @@ -31,6 +31,11 @@ console.log("luery.js ©LJM12914\r\nhttps://github.com/ljm12914/luery\r\nYou are if(!((o + "").indexOf("NodeList") + 1)) o.addEventListener(e,f); else if(!((o + "").indexOf("Element") + 1)) for(let i = 0; i < o.length; i++) o[i].addEventListener(e,f); }, + dEvents:(o,e,f)=>{ + if(o.length == 0) luery.E(); + if(!((o + "").indexOf("NodeList") + 1)) o.removeEventListener(e,f); + else if(!((o + "").indexOf("Element") + 1)) for(let i = 0; i < o.length; i++) o[i].removeEventListener(e,f); + }, //判断JSON文本 isJSONText:s=>{ if(typeof s == "string"){ @@ -116,6 +121,7 @@ console.log("luery.js ©LJM12914\r\nhttps://github.com/ljm12914/luery\r\nYou are function f(){ var t = o.offsetTop, l = o.offsetLeft, c = o.offsetParent; while(c !== null){ + //console.log(c.offsetParent); t += c.offsetTop; l += c.offsetLeft; c = c.offsetParent; @@ -123,6 +129,9 @@ console.log("luery.js ©LJM12914\r\nhttps://github.com/ljm12914/luery\r\nYou are return {t:t,l:l}; } function d(a){return parseFloat(o.css(a).replace("px",""));} + }, + dom:(o,t)=>{ + } }); })(); @@ -156,12 +165,8 @@ console.log("luery.js ©LJM12914\r\nhttps://github.com/ljm12914/luery\r\nYou are this.css("display",""); return this; } - g.setAttribute=function(k,v){ - for(let i = 0; i < this.length; i++) this[i].setAttribute(k,v); - return this; - } - g.removeAttribute=function(k){ - for(let i = 0; i < this.length; i++) this[i].removeAttribute(k); + g.attr=function(k,v){ + for(let i = 0; i < this.length; i++) this[i].attr(k,v); return this; } } @@ -227,6 +232,14 @@ console.log("luery.js ©LJM12914\r\nhttps://github.com/ljm12914/luery\r\nYou are } return null; } + v.attr=h.attr=function(k,v){ + if(v === undefined) return this.getAttribute(k); + else{ + if(v === null) this.removeAttribute(k); + else this.setAttribute(k,v); + return this; + } + } } else lueryFail(); })(); \ No newline at end of file diff --git a/luery.min.js b/luery.min.js index 7395f4a..b24ac60 100644 --- a/luery.min.js +++ b/luery.min.js @@ -1 +1 @@ -"use strict";(_=>{function luery(t){return new luery.prototype.processInput(t)}window.luery=luery,eval("window."+(window.lueryShortCut||"$")+" = luery;"),luery.p=luery.prototype={constructor:luery,processInput:function(t){if(t){if("string"==typeof t){let e=document.querySelectorAll(t);return 0==e.length?[]:1==e.length&&t.match(/^.*#[^\s]*$/)?e[0]:e}}else luery.E()}},luery.addFunc=luery.prototype.addFunc=function(t){for(let e in t)this[e]=t[e]},luery.addFunc({E:t=>{throw new TypeError("Invalid argument")},Events:(t,e,r)=>{if(0==t.length&&luery.E(),(t+"").indexOf("NodeList")+1){if(!((t+"").indexOf("Element")+1))for(let s=0;s{if("string"==typeof t)try{let e=JSON.parse(t);return!("object"!=typeof e||!e)}catch(t){return!1}return!1},isJSONObject:t=>{if("object"==typeof t)try{let e=JSON.stringify(t);return!("string"!=typeof e||!e)}catch(t){return!1}return!1},getCookie:t=>{let e=document.cookie.split(";"),r=t+"=";for(let s=0;s{let s=new Date;return s.setTime(s.getTime()+24*r*60*60*1e3),document.cookie=t+"="+e+"; expires="+s.toUTCString(),luery.getCookie(t)},removeCookie:t=>{luery.setCookie(t,"",-1)},scrollBarWidth:t=>{let e,r,s;return s=void 0===t?document.createElement("div"):t.cloneNode(!0),s.css({position:"absolute",top:"-9999px",width:"999px",height:"999px",overflow:"hidden"}),e=document.body.appendChild(s).clientWidth,s.css("overflow","scroll"),r=s.clientWidth,document.body.removeChild(s),e-r},tt:(t,e)=>{var r=luery.tt;switch(e){case"t":return n("top");case"ft":return s().t;case"b":return r(t,"t")+r(t,"h");case"fb":return s().t+r(t,"h");case"l":return n("left");case"fl":return s().l;case"r":return r(t,"l")+r(t,"w");case"fr":return s().l+r(t,"w");case"ah":return t.outerHeight;case"aw":return t.outerWidth;case"h":return t.offsetHeight;case"w":return t.offsetWidth;case"dh":return t.clientHeight;case"dw":return t.clientWidth;case"ph":return r(t,"dh")-n("padding-top")-n("padding-bottom");case"pw":return r(t,"dw")-n("padding-left")-n("padding-right");default:luery.E()}function s(){for(var e=t.offsetTop,r=t.offsetLeft,s=t.offsetParent;null!==s;)e+=s.offsetTop,r+=s.offsetLeft,s=s.offsetParent;return{t:e,l:r}}function n(e){return parseFloat(t.css(e).replace("px",""))}}})})(),(t=>{var e=luery;if(NodeList){let t=NodeList.prototype;t.css=function(t,r){void 0!==r||e.isJSONObject(t)||e.E();for(let e=0;e{function luery(e){return new luery.prototype.I(e)}window.luery=luery,eval("window."+(window.lueryShortCut||"$")+" = luery;"),luery.p=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")},Events:(e,t,r)=>{if(0==e.length&&luery.E(),(e+"").indexOf("NodeList")+1){if(!((e+"").indexOf("Element")+1))for(let s=0;s{if(0==e.length&&luery.E(),(e+"").indexOf("NodeList")+1){if(!((e+"").indexOf("Element")+1))for(let s=0;s{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{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},tt:(e,t)=>{var r=luery.tt;switch(t){case"t":return n("top");case"ft":return s().t;case"b":return r(e,"t")+r(e,"h");case"fb":return s().t+r(e,"h");case"l":return n("left");case"fl":return s().l;case"r":return r(e,"l")+r(e,"w");case"fr":return s().l+r(e,"w");case"ah":return e.outerHeight;case"aw":return e.outerWidth;case"h":return e.offsetHeight;case"w":return e.offsetWidth;case"dh":return e.clientHeight;case"dw":return e.clientWidth;case"ph":return r(e,"dh")-n("padding-top")-n("padding-bottom");case"pw":return r(e,"dw")-n("padding-left")-n("padding-right");default:luery.E()}function s(){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 n(t){return parseFloat(e.css(t).replace("px",""))}},dom:(e,t)=>{}})})(),(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