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

10 lines
3.6 KiB
JavaScript
Executable File

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