This repository was archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfayQuery.min.js
1 lines (1 loc) · 5 KB
/
fayQuery.min.js
1
(function(){function b(c){return b.$(document,c)}b.$=function(c,a){if(a instanceof HTMLElement)return a.dataset||(a.dataset=b.createDataSet(a)),new b.CustomList([a]);if(a instanceof Array||a instanceof HTMLCollection||a instanceof NodeList)return new b.CustomList(a);for(var d=c.querySelectorAll(a),f=0;f<d.length;f++)d[f].dataset||(d[f].dataset=b.createDataSet(d[f]));return new b.CustomList(d)};b.createDataSet=function(c){for(var a={},d=0;d<c.attributes.length;d++)if("data-"==c.attributes[d].name.substring(0,5)){for(var b=c.attributes[d].name.substring(5),e=b.match(/-(.)/);null!=e;)b=b.replace(e[0],e[1].toUpperCase()),e=b.match(/-(.)/);a[b]=c.attributes[d].value}return a};b.CustomList=function(c){for(var a=0;a<c.length;a++)this[a]=c[a];this.length=c.length};b.CustomList.prototype.get=function(c){if(0<this.length)return this[0][c]};b.CustomList.prototype.getAttribute=function(c){if(0<this.length)return this[0].getAttribute(c)};b.CustomList.prototype.set=function(c,a){for(var d=0;d<this.length;d++)this[d][c]=a;return this};b.CustomList.prototype.setAttribute=function(c,a){for(var d=0;d<this.length;d++)this[d].setAttribute(c,a);return this};b.CustomList.prototype.append=function(c,a){for(var d=0;d<this.length;d++){var b=this[d][c];this[d][c]="undefined"===typeof b?a:b+a}return this};b.CustomList.prototype.appendAttribute=function(c,a){for(var d=0;d<this.length;d++){var b=this[d].getAttribute(a);this[d].setAttribute(c,"string"===typeof b?b+a:a)}return this};b.CustomList.prototype.setStyle=function(c){if(c instanceof String||"string"===typeof c)for(var a=0;a<this.length;a++)this[a].style.cssText+=";"+c;else for(a=0;a<this.length;a++)for(var d in c)this[a].style[d]=c[d];return this};b.CustomList.prototype.setInnerHTML=function(c){for(var a=0;a<this.length;a++)this[a].innerHTML=c;return this};b.CustomList.prototype.addEventListener=function(c,a,d,b){for(var e=0;e<this.length;e++)this[e].addEventListener(c,a,d,b);return this};b.CustomList.prototype.removeEventListener=function(c,a,d,b){for(var e=0;e<this.length;e++)this[e].removeEventListener(c,a,d,b);return this};b.remove=function(c){c.parentNode&&c.parentNode.removeChild(c)};b.CustomList.prototype.remove=function(){for(var c=0;c<this.length;c++)b.remove(this[c]);return this};b.hasClass=function(c,a){return c.classList.contains(a)};b.CustomList.prototype.hasClass=function(c){for(var a=0;a<this.length;a++)if(b.hasClass(this[a],c))return!0;return!1};b.CustomList.prototype.allHaveClass=function(c){for(var a=0;a<this.length;a++)if(!b.hasClass(this[a],c))return!1;return!0};b.addClass=function(c,a){c.classList.add(a)};b.CustomList.prototype.addClass=function(c){for(var a=0;a<this.length;a++)b.addClass(this[a],c);return this};b.removeClass=function(c,a){c.classList.remove(a)};b.CustomList.prototype.removeClass=function(c){for(var a=0;a<this.length;a++)b.removeClass(this[a],c);return this};b.toggleClass=function(c,a){c.classList.toggle(a)};b.CustomList.prototype.toggleClass=function(c){for(var a=0;a<this.length;a++)b.toggleClass(this[a],c);return this};b.CustomList.prototype.run=function(c){var a=Array.prototype.slice.call(arguments,1);a.push(0);for(var b=0;b<this.length;b++)a[a.length-1]=b,c.apply(this[b],a);return this};b.CustomList.prototype.each=function(c){for(var a=Array.prototype.slice.call(arguments,1),b=0;b<this.length&&!1!==c.apply(this[b],a);b++);return this};b.getText=function(c){return c.innerText||c.textContent};b.CustomList.prototype.getText=function(){if(0<this.length)return b.getText(this[0])};b.doRequest=function(c,a,d,f,e,n,h,k,l,m){return new b.Request(c,a,d,f,e,n,h,k,l,m)};b.toQueryString=function(c){var a=[],b;for(b in c)c.hasOwnProperty(b)&&a.push(encodeURIComponent(b)+"="+encodeURIComponent(c[b]));return a.join("&")};b.Request=function(c,a,d,f,e,n,h,k,l,m){this.xhr=new XMLHttpRequest;"number"===typeof m&&(this.xhr.timeout=m);this.xhr.open(a,c,!0);d instanceof HTMLFormElement?d=new FormData(d):"object"!==typeof d||FormData&&d instanceof FormData||(d=b.toQueryString(d),this.xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded"));var g=this;this.xhr.onreadystatechange=function(b){4==g.xhr.readyState&&(200==g.xhr.status?f(b,g.xhr):"function"===typeof e?e(b,g.xhr):0<e?g.resend(c,a,d,f,e-1,n,h,k,l,m):n(b,g.xhr))};"function"===typeof k&&this.xhr.upload.addEventListener("progress",k);"function"===typeof l&&this.xhr.addEventListener("progress",l);"function"===typeof h&&h(this.xhr,d);this.xhr.send(d)};b.Request.prototype.abort=function(){this.xhr.abort()};b.Request.prototype.resend=function(b,a,d,f,e,n,h,k,l,m){this.xhr=new XMLHttpRequest;"number"===typeof m&&(this.xhr.timeout=m);this.xhr.open(a,b,!0);var g=this;this.xhr.onreadystatechange=function(p){4==g.xhr.readyState&&(200==g.xhr.status?f(p,g.xhr):"function"===typeof e?e(p,g.xhr):0<e?g.resend(b,a,d,f,e-1,n,h,k,l,m):n(p,g.xhr))};"function"===typeof k&&this.xhr.upload.addEventListener("progress",k);"function"===typeof l&&this.xhr.addEventListener("progress",l);"function"===typeof h&&h(this.xhr,d);this.xhr.send(d)};window.fayQuery=b;"$"in window||(window.$=b);window.getFayQuery=function(){return b}})();