kis-js/kis-lite-dom-min.js

10 lines
3.5 KiB
JavaScript
Executable File

(function(e){var d,h,b;d=function(a,c){b=a===e?d.el!==e?d.el:document.documentElement:h(a,c);d.prototype.el=b;var g=Object.create(d),f;for(f in g)"object"===typeof g[f]&&(g[f].el=b);g.el=b;return g};h=function(a,c){var b;if("string"!=typeof a||a===e)return a;c=null!=c&&1===c.nodeType?c:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);b=c.querySelectorAll(a);return 1===b.length?b[0]:b};d.ext=function(a,c){c.el=b;d[a]=c};d.ext("each",function(a){b.length!==e&&b!==
window?[].forEach.call(b,a):a.call(b,b)});d.type=function(a){return function(){return a&&a!==this}.call(a)?(typeof a).toLowerCase():{}.toString.call(a).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};d=window.$_=window.$_||d;d.$=h})();
(function(e){var d={_do:function(d,b,a,c,g){var f=new XMLHttpRequest;a===e&&(a=function(){});g=g?"POST":"GET";"GET"===g&&(d+=d.match(/\?/)?this._serialize(b):"?"+this._serialize(b));f.open(g,d);f.onreadystatechange=function(){4===f.readyState&&(200===f.status?a.call(f.responseText,f.responseText):c!==e&&c.call(f.status,f.status))};"POST"===g?(f.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),f.send(this._serialize(b))):f.send(null)},_serialize:function(d){var b,a,c=[];for(b in d)d.hasOwnProperty(b)&&
"function"!==$_.type(d[b])&&(a=d[b].toString(),b=encodeURIComponent(b),a=encodeURIComponent(a),c.push(b+"="+a));return c.join("&")}};$_.ext("get",function(e,b,a,c){d._do(e,b,a,c,!1)});$_.ext("post",function(e,b,a,c){d._do(e,b,a,c,!0)})})();
(function(e){var d,h;d=function(b,a,c,g){var f,e;if(a.match(/^([\w\-]+)$/))!0===g?b.addEventListener(a,c,!1):b.removeEventListener(a,c,!1);else for(a=a.split(" "),e=a.length,f=0;f<e;f++)d(b,a[f],c,g)};h=function(b,a,c,g){d(b,c,function(c){var d,e;e=$_.$(a,b);for(d in e)c.target==e[d]&&(g.call(e[d],c),c.stopPropagation())},!0)};$_.ext("event",{create:function(b,a){a=a||{};var c=document.createEvent("CustomEvent");c.initCustomEvent(b,!0,!0,a);return c},add:function(b,a){$_.each(function(c){d(c,b,a,
!0)})},remove:function(b,a){$_.each(function(c){d(c,b,a,!1)})},live:function(b,a,c){h(document.documentElement,b,a,c)},delegate:function(b,a,c){$_.each(function(g){h(g,b,a,c)})},trigger:function(b){return this.el.dispatchEvent(b)}})})();
(function(e){function d(a,c,b){var d;a.hasAttribute(c)&&(d=a.getAttribute(c));if(d===e&&(b===e||null===b))return null;if(b===e)return d;b!==e&&null!==b?a.setAttribute(c,b):null===b&&a.removeAttribute(c);return b!==e?b:d}function h(a){return String(a).replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function b(a,c,b){c=h(c);if(b===e&&a.style[c]!==e)return a.style[c];if(a.style[c]!==e)return a.style[c]=b,null}$_.ext("dom",{addClass:function(a){$_.each(function(c){c.classList.add(a)})},
removeClass:function(a){$_.each(function(c){c.classList.remove(a)})},hide:function(){this.css("display","none")},show:function(a){a===e&&(a="block");this.css("display",a)},attr:function(a,c){var b=this.el;if(1<b.length&&c===e)return null;if(1<b.length&&c!==e)$_.each(function(b){return d(b,a,c)});else return d(b,a,c)},text:function(a){var b,d,f;f=this.el;d=a!==e?!0:!1;b=f.textContent;return d?f.textContent=a:b},css:function(a,c){if("object"===$_.type(a))Object.keys(a).forEach(function(c){$_.each(function(d){b(d,
c,a[c])})});else if(c===e&&"object"!==$_.type(a))return b(this.el,a);$_.each(function(d){b(d,a,c)})},append:function(a){this.el.insertAdjacentHTML("beforeend",a)},prepend:function(a){this.el.insertAdjacentHTML("afterbegin",a)},html:function(a){a!==e&&(this.el.innerHTML=a);return this.el.innerHTML}})})();