kis-js/kis-min.js

10 lines
4.2 KiB
JavaScript
Executable File

(function(e){var d,m,f;d=function(k){f=k===e?d.el!==e?d.el:document.documentElement:m(k);d.prototype.el=f;k=Object.create(d);for(var n in k)"object"===typeof k[n]&&(k[n].el=f);k.el=f;return k};m=function(d,f){var l;if("string"!=typeof d||d===e)return d;l=null!=f&&1===f.nodeType?f:document;if(d.match(/^#([\w\-]+$)/))return document.getElementById(d.split("#")[1]);l=l.querySelectorAll(d);return 1===l.length?l[0]:l};d.ext=function(e,m){m.el=f;d[e]=m};d.ext("each",function(d){f.length!==e&&f!==window?
[].forEach.call(f,d):d.call(f,f)});d.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()};d=window.$_=window.$_||d;d.$=m})();Promise.prototype.done||(Promise.prototype.done=function(e,d){this.then(e,d).then(null,function(d){setTimeout(function(){throw d;},0)})});
(function(e,d){function m(a,b,c){var h;a.hasAttribute(b)&&(h=a.getAttribute(b));if(h===d&&(c===d||null===c))return null;if(c===d)return h;c!==d&&null!==c?a.setAttribute(b,c):null===c&&a.removeAttribute(b);return c!==d?c:h}function f(a){return String(a).replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function k(a,b,c){var h;b=f(b);h={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if(c===d&&a.style[b]!==d)return a.style[b];if(c===d&&a.style[h[b]]!==d)return a.style[h[b]];
if(a.style[b]!==d)return a.style[b]=c,null;if(a.style[h[b]])return a.style[h[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 m(c,a,b)});else return m(c,a,b)},text:function(a){var b,
c,h;h=this.el;c=a!==d?!0:!1;b=h.textContent;return c?h.textContent=a:b},css:function(a,b){var c=null;if("object"===e.type(a))for(c in a)a.hasOwnProperty(c)&&e.each(function(b){k(b,c,a[c])});else if(b===d&&"object"!==e.type(a))return k(this.el,a);e.each(function(c){k(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 n={_do:function(a,b,
c,h,e){var g=new XMLHttpRequest;c===d&&(c=function(){});e=e?"POST":"GET";"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):h!==d&&h.call(g.status,g.status))};"POST"===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){n._do(a,b,c,d,!1)});e.ext("post",function(a,b,c,d){n._do(a,b,c,d,!0)});var l,r;l=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++)l(a,b[e],c,d)};r=function(a,b,c,d){l(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){if(/MSIE|Trident/i.test(navigator.userAgent)){var c=document.createEvent("CustomEvent");c.initCustomEvent(a,!0,!0,b);return c}return new CustomEvent(a,b)},add:function(a,b){e.each(function(c){l(c,a,b,!0)})},remove:function(a,b){e.each(function(c){l(c,a,b,!1)})},live:function(a,b,c){r(document.documentElement,a,b,c)},delegate:function(a,b,c){e.each(function(d){r(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()}})})($_);