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

14 lines
5.7 KiB
JavaScript
Executable File

(function(d){var f,g,c;f=function(a){c=a===d?f.el!==d?f.el:document.documentElement:g(a);f.prototype.el=c;a=Object.create(f);for(var b in a)"object"===typeof a[b]&&(a[b].el=c);a.el=c;return a};g=function(a,b){var c;if("string"!=typeof a||a===d)return a;c=null!=b&&1===b.nodeType?b:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);c=c.querySelectorAll(a);return 1===c.length?c[0]:c};f.ext=function(a,b){b.el=c;f[a]=b};f.ext("each",function(a){c.length!==d&&c!==window?
[].forEach.call(c,a):a.call(c,c)});f.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()};f=window.$_=window.$_||f;f.$=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){var f={_do:function(f,c,a,b,h){var e=new XMLHttpRequest;a===d&&(a=function(){});h=h?"POST":"GET";"GET"===h&&(f+=f.match(/\?/)?this._serialize(c):"?"+this._serialize(c));e.open(h,f);e.onreadystatechange=function(){4===e.readyState&&(200===e.status?a.call(e.responseText,e.responseText):b!==d&&b.call(e.status,e.status))};"POST"===h?(e.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),e.send(this._serialize(c))):e.send(null)},_serialize:function(d){var c,a,b=[];for(c in d)d.hasOwnProperty(c)&&
"function"!==$_.type(d[c])&&(a=d[c].toString(),c=encodeURIComponent(c),a=encodeURIComponent(a),b.push(c+"="+a));return b.join("&")}};$_.ext("get",function(d,c,a,b){f._do(d,c,a,b,!1)});$_.ext("post",function(d,c,a,b){f._do(d,c,a,b,!0)})})();
(function(d){var f,g;f=function(c,a,b,d){var e,k;if(a.match(/^([\w\-]+)$/))!0===d?c.addEventListener(a,b,!1):c.removeEventListener(a,b,!1);else for(a=a.split(" "),k=a.length,e=0;e<k;e++)f(c,a[e],b,d)};g=function(c,a,b,d){f(c,b,function(b){var f,g;g=$_.$(a,c);for(f in g)b.target==g[f]&&(d.call(g[f],b),b.stopPropagation())},!0)};$_.ext("event",{create:function(c,a){if(/MSIE|Trident/i.test(navigator.userAgent)){var b=document.createEvent("CustomEvent");b.initCustomEvent(c,!0,!0,a);return b}return new CustomEvent(c,
a)},add:function(c,a){$_.each(function(b){f(b,c,a,!0)})},remove:function(c,a){$_.each(function(b){f(b,c,a,!1)})},live:function(c,a,b){g(document.documentElement,c,a,b)},delegate:function(c,a,b){$_.each(function(d){g(d,c,a,b)})},trigger:function(c){return this.el.dispatchEvent(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 f=Object,g=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},c=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},a=function(a,b){this.name=a;this.code=DOMException[a];this.message=b},b=function(b,d){if(""===d)throw new a("SYNTAX_ERR","An invalid or illegal string was specified");
if(/\s/.test(d))throw new a("INVALID_CHARACTER_ERR","String contains an invalid character");return c.call(b,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()}},e=h.prototype=[],k=function(){return new h(this)};a.prototype=Error.prototype;e.item=function(a){return this[a]||null};e.contains=function(a){return-1!==b(this,a+"")};e.add=function(){var a=arguments,c=0,d=a.length,e,f=!1;
do e=a[c]+"",-1===b(this,e)&&(this.push(e),f=!0);while(++c<d);f&&this._updateClassName()};e.remove=function(){var a=arguments,c=0,d=a.length,e,f=!1;do e=a[c]+"",e=b(this,e),-1!==e&&(this.splice(e,1),f=!0);while(++c<d);f&&this._updateClassName()};e.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};e.toString=function(){return this.join(" ")};if(f.defineProperty){e={get:k,enumerable:!0,configurable:!0};try{f.defineProperty(d,"classList",e)}catch(l){-2146823252===
l.number&&(e.enumerable=!1,f.defineProperty(d,"classList",e))}}else f.prototype.__defineGetter__&&d.__defineGetter__("classList",k)}}(self);
(function(d){function f(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){return a.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function c(a,b,c){var e;b=g(b);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(b){b.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 f(c,a,b)});else return f(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 c(this.el,a);$_.each(function(d){c(d,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}})})();