kis-js/kis-min.js

13 lines
6.0 KiB
JavaScript
Executable File

(function(e){var c,m,k;c=function(f){k=f===e?c.el!==e?c.el:document.documentElement:m(f);c.prototype.el=k;f=Object.create(c);for(var n in f)"object"===typeof f[n]&&(f[n].el=k);f.el=k;return f};m=function(c,k){var l;if("string"!=typeof c||c===e)return c;l=null!=k&&1===k.nodeType?k:document;if(c.match(/^#([\w\-]+$)/))return document.getElementById(c.split("#")[1]);l=l.querySelectorAll(c);return 1===l.length?l[0]:l};c.ext=function(f,e){e.el=k;c[f]=e};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.$=m})();"undefined"===typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")});"undefined"===typeof Array.isArray&&(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.apply(e)});
(function(e,c){function m(a,b,d){var g,h;a.hasAttribute!==c?(a.hasAttribute(b)&&(g=a.getAttribute(b)),h=!0):a[b]!==c?(g=a[b],h=!1):"class"===b&&a.className!==c&&(b="className",g=a.className,h=!1);if(g===c&&(d===c||null===d))return null;if(d===c)return g;d!==c&&null!==d?!0===h?a.setAttribute(b,d):a[b]=d:null===d&&(!0===h?a.removeAttribute(b):delete a[b]);return d!==c?d:g}function k(a){return a.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function f(a,b,d){var g;b=k(b);
g={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if(d===c&&a.style[b]!==c)return a.style[b];if(d===c&&a.style[g[b]]!==c)return a.style[g[b]];if(a.style[b]!==c)return a.style[b]=d,null;if(a.style[g[b]])return a.style[g[b]]=d,null}"undefined"===typeof document||"classList"in document.createElement("a")||function(a){if("HTMLElement"in a||"Element"in a){a=(a.HTMLElement||a.Element).prototype;var b=Object,d=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},c=Array.prototype.indexOf||
function(a){for(var b=0,d=this.length;b<d;b++)if(b in this&&this[b]===a)return b;return-1},h=function(a,b){this.name=a;this.code=DOMException[a];this.message=b},e=function(a,b){if(""===b)throw new h("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(b))throw new h("INVALID_CHARACTER_ERR","String contains an invalid character");return c.call(a,b)},k=function(a){for(var b=d.call(a.className),b=b?b.split(/\s+/):[],c=0,g=b.length;c<g;c++)this.push(b[c]);this._updateClassName=function(){a.className=
this.toString()}},f=k.prototype=[],l=function(){return new k(this)};h.prototype=Error.prototype;f.item=function(a){return this[a]||null};f.contains=function(a){return-1!==e(this,a+"")};f.add=function(){var a=arguments,b=0,d=a.length,c,g=!1;do c=a[b]+"",-1===e(this,c)&&(this.push(c),g=!0);while(++b<d);g&&this._updateClassName()};f.remove=function(){var a=arguments,b=0,d=a.length,c,g=!1;do c=a[b]+"",c=e(this,c),-1!==c&&(this.splice(c,1),g=!0);while(++b<d);g&&this._updateClassName()};f.toggle=function(a,
b){a+="";var d=this.contains(a),c=d?!0!==b&&"remove":!1!==b&&"add";if(c)this[c](a);return!d};f.toString=function(){return this.join(" ")};if(b.defineProperty){f={get:l,enumerable:!0,configurable:!0};try{b.defineProperty(a,"classList",f)}catch(m){-2146823252===m.number&&(f.enumerable=!1,b.defineProperty(a,"classList",f))}}else b.prototype.__defineGetter__&&a.__defineGetter__("classList",l)}}(self);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 m(d,a,b)});else return m(d,a,b)},text:function(a){var b,d,g;g=this.el;d=a!==c?!0:!1;b=g.textContent;return d?g.textContent=a:b},css:function(a,b){if(b===c)return f(this.el,a);e.each(function(d){f(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 n={_do:function(a,b,d,g,h){var e=new XMLHttpRequest;d===c&&(d=function(){});h=h?"POST":"GET";"GET"===h&&(a+=a.match(/\?/)?this._serialize(b):"?"+this._serialize(b));e.open(h,a);e.onreadystatechange=function(){4===e.readyState&&(200===e.status?d.call(e.responseText,e.responseText):g!==c&&g.call(e.status,e.status))};"POST"===h?(e.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),e.send(this._serialize(b))):
e.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){n._do(a,b,d,c,!1)});e.ext("post",function(a,b,c,e){n._do(a,b,c,e,!0)});var l,r;l=function(a,b,c,e){var h,f;if(b.match(/^([\w\-]+)$/))!0===e?a.addEventListener(b,c,!1):a.removeEventListener(b,c,!1);else for(b=b.split(" "),f=b.length,h=0;h<f;h++)l(a,b[h],c,e)};
r=function(a,b,c,g){l(a,c,function(c){var d,f;f=e.$(b,a);for(d in f)c.target==f[d]&&(g.call(f[d],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(e){r(e,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={},e,f;f=a?p:q;b=f.length;for(a=0;a<b;a++)e=f.key(a),c[e]=f.getItem(e);return c},clear:function(a){a?q.clear():p.clear()}})})($_);