sdwebserver/public/js/pequejs.min.js

3 lines
3.4 KiB
JavaScript
Raw Normal View History

2022-03-14 19:13:10 +01:00
/*! pequejs 1.1.0 */
var $=function(){"use strict";function e(t){this.elements="document"===t?[document]:"window"===t?[window]:"object"==typeof t?[t]:document.querySelectorAll(t)}return e.prototype.html=function(e){if(!e)return this.elements[0].innerHTML;this.each(function(t){t.innerHTML=e})},e.prototype.text=function(e){if(!e)return this.elements[0].textContent;this.each(function(t){t.textContent=e})},e.prototype.on=function(e,n,o=null){if("string"==typeof n&&"function"==typeof o)document.addEventListener(e,function(t){for(var e=t.target;e&&e!==this;e=e.parentNode)if(e.matches(n)){o.call(e,t);break}},!1);else{if("function"!=typeof n)return!1;this.each(function(t){t.addEventListener(e,n)})}},e.prototype.show=function(e){this.each(function(t){t.style.display=e||"block"})},e.prototype.hide=function(){this.each(function(t){t.style.display="none"})},e.prototype.attr=function(e,n=null){if(null===n)return this.elements[0].getAttribute(e);this.each(function(t){t.setAttribute(e,n)})},e.prototype.removeAttr=function(e){this.each(function(t){t.removeAttribute(e)})},e.prototype.append=function(e){this.each(function(t){t.innerHTML+=e})},e.prototype.empty=function(){this.each(function(t){for(;t.firstChild;)t.removeChild(t.firstChild)})},e.prototype.hasClass=function(e){var n=!1;return this.each(function(t){if(t.classList.contains(e))return n=!0}),n},e.prototype.addClass=function(e){this.each(function(t){t.classList.add.apply(t.classList,e.split(" "))})},e.prototype.removeClass=function(e){this.each(function(t){t.classList.remove.apply(t.classList,e.split(" "))})},e.prototype.toggleClass=function(e){this.each(function(t){$(t).hasClass(e)?$(t).removeClass(e):$(t).addClass(e)})},e.prototype.val=function(t){if(!t)return this.elements[0].value;this.elements[0].value=t},e.prototype.is=function(t){var e=this.elements[0];return(e.matches||e.matchesSelector||e.msMatchesSelector||e.mozMatchesSelector||e.webkitMatchesSelector||e.oMatchesSelector).call(e,t)},e.prototype.each=function(e){if("function"!=typeof e)return"undefined";this.elements.forEach(function(t){if(!1===e.call(this,t))return!1})},e.prototype.ajax=function(t,e){if(!t&&!e)return!1;if(!e.success)return!1;e.type?e.type=e.type.toUpperCase():e.type="GET",e.contentType||(e.contentType="application/x-www-form-urlencoded; charset=UTF-8"),e.dataType||(e.dataType="json"),e.async||(e.async=!0);var n=t,o=[];e.data&&(Object.keys(e.data).map(function(t){o.push(t+"="+encodeURIComponent(e.data[t]))}),o=o.join("&"));t=new XMLHttpRequest;"GET"===e.type&&(n+="?"+o),t.open(e.type,n,e.async),t.setRequestHeader("Content-Type",e.contentType),t.onload=function(){200<=this.status&&this.status<400?(o="json"===e.dataType?JSON.parse(this.response):"text"===e.dataType||"html"===e.dataType?this.responseText:this.response,e.success(o)):e.error&&e.error(this.status,this.statusText)},t.onerror=function(){e.error&&e.error(this.status,this.statusText)},o&&"GET"!==e.type?t.send(o):t.send()},e.prototype.get=function(t,e,n){var o={type:"GET"};"function"==typeof e?(o.success=function(t){return e(t)},o.error=function(){return e(!1)}):(o.data=e,o.success=function(t){"function"==typeof n&&n(t)},o.error=function(){"function"==typeof n&&n(!1)}),this.ajax(t,o)},e.prototype.post=function(t,e,n){if(!t||!e||!n)return!1;this.ajax(t,{type:"POST",data:e,success:function(t){"function"==typeof n&&n(t)},error:function(){"function"==typeof n&&n(!1)}})},function(t){return new e(t)}}();