kis-js/kis-min.js

10 lines
3.9 KiB
JavaScript
Executable File

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