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

16 lines
6.0 KiB
JavaScript
Executable File

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