kis-js/kis-min.js

10 lines
3.8 KiB
JavaScript
Executable File

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