-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmiq-min.js
14 lines (14 loc) · 3.59 KB
/
miq-min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
miq 1.15.0
@copyright 2019 Edwin Martin
@see {@link http://www.bitstorm.org/javascript/miq/}
@license MIT
*/
'use strict';self.miq=function(a,b){b=b&&b.first||b||document;if("function"==typeof a)"loading"==b.readyState?b.addEventListener("DOMContentLoaded",a):a();else{var c=Object.create(miq.fn),d;c.length=0;"object"==typeof a?"length"in a?a.forEach(function(a){c.push(a)}):c.push(a):a?(d=a.match(/<(.+)>/))?c.push(b.createElement(d[1])):c=miq(b.querySelectorAll(a)):c.push(b.createDocumentFragment());return c}};
miq.fn=Object.create(Array.prototype,{first:{get:function(){return this[0]}},eq:{value:function(a){return miq(this[a||0])}},on:{value:function(a,b){for(var c=0;c<this.length;c++)this[c].addEventListener(a,b);return this}},off:{value:function(a,b){for(var c=0;c<this.length;c++)this[c].removeEventListener(a,b);return this}},addClass:{value:function(a){for(var b=0;b<this.length;b++)miq.fn.hasClass.call({first:this[b]},a)||(this[b].className+=" "+a);return this}},removeClass:{value:function(a){for(var b=
0;b<this.length;b++)this[b].className=this[b].className.replace(a,"");return this}},hasClass:{value:function(a){return""!=this.first.className&&(new RegExp("\\b"+a+"\\b")).test(this.first.className)}},prop:{value:function(a,b){if("undefined"==typeof b)return this.first[a];for(var c=0;c<this.length;c++)this[c][a]=b;return this}},attr:{value:function(a,b){if("undefined"==typeof b)return this.first.getAttribute(a);for(var c=0;c<this.length;c++)this[c].setAttribute(a,b);return this}},removeAttr:{value:function(a){for(var b=
0;b<this.length;b++)this[b].removeAttribute(a);return this}},val:{value:function(a){var b=this.first,c="value";switch(b.tagName){case "SELECT":c="selectedIndex";break;case "OPTION":c="selected";break;case "INPUT":if("checkbox"==b.type||"radio"==b.type)c="checked"}return this.prop(c,a)}},append:{value:function(a){a=miq(a);for(var b=a.length,c=0;c<b;c++)this.first.appendChild(a[c].first||a[c]);return this}},before:{value:function(a){this.first.parentElement.insertBefore(miq().append(a).first,this.first);
return this}},parent:{value:function(){return miq(this.first.parentNode)}},clone:{value:function(){return miq(this.first.cloneNode(!0))}},remove:{value:function(){for(var a=0;a<this.length;a++)this[a].parentNode.removeChild(this[a]);return this}},find:{value:function(a){return miq(a,this.first)}},closest:{value:function(a){var b=this.first;do if(b[miq.matches](a))return miq(b);while(b=b.parentElement);return null}},is:{value:function(a){return miq(this.filter(function(b){return b[miq.matches](a)}))}},
css:{value:function(a,b){if("undefined"==typeof b)return this.first.style[a];for(var c=0;c<this.length;c++)this[c].style[a]=b;return this}},html:{value:function(a){return this.prop("innerHTML",a)}},text:{value:function(a){return this.prop("textContent",a)}}});miq.miq="1.15.0";
miq.ajaxCallback=function(a,b,c,d){var e=new XMLHttpRequest;e.onreadystatechange=function(){if(4==e.readyState)if(200==e.status){switch(d.dataType){case "xml":var a=e.responseXML;break;case "json":a=JSON.parse(e.responseText);break;default:a=e.responseText}b(a)}else c&&c("Ajax error: "+e.status)};e.open(d.method||"GET",a,!0);if(d.headers)for(var f in d.headers)e.setRequestHeader(f,d.headers[f]);e.send(d.data||"")};miq.ajax=function(a,b){return new Promise(function(c,d){miq.ajaxCallback(a,c,d,b)})};
miq.matches=["matches","webkitMatchesSelector","mozMatchesSelector","msMatchesSelector"].filter(function(a){return a in document.documentElement})[0];"function"===typeof define&&define.amd?define(function(){return miq}):"object"===typeof module&&module.exports?module.exports=miq:"undefined"==typeof self.$&&(self.$=miq);