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

10 lines
3.9 KiB
JavaScript
Executable File

(function(e){var c,h,b;c=function(a){b=a===e?c.el!==e?c.el:document.documentElement:h(a);c.prototype.el=b;a=Object.create(c);for(var d in a)"object"===typeof a[d]&&(a[d].el=b);a.el=b;return a};h=function(a,d){var b;if("string"!=typeof a||a===e)return a;b=null!=d&&1===d.nodeType?d:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);b=b.querySelectorAll(a);return 1===b.length?b[0]:b};c.ext=function(a,d){d.el=b;c[a]=d};c.ext("each",function(a){b.length!==e&&b!==window?
[].forEach.call(b,a):a.call(b,b)});c.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()};c=window.$_=window.$_||c;c.$=h})();Promise.prototype.done||(Promise.prototype.done=function(e,c){this.then(e,c).then(null,function(e){setTimeout(function(){throw e;},0)})});
(function(e){var c={_do:function(c,b,a,d,g){var f=new XMLHttpRequest;a===e&&(a=function(){});g=g?"POST":"GET";"GET"===g&&(c+=c.match(/\?/)?this._serialize(b):"?"+this._serialize(b));f.open(g,c);f.onreadystatechange=function(){4===f.readyState&&(200===f.status?a.call(f.responseText,f.responseText):d!==e&&d.call(f.status,f.status))};"POST"===g?(f.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),f.send(this._serialize(b))):f.send(null)},_serialize:function(c){var b,a,d=[];for(b in c)c.hasOwnProperty(b)&&
"function"!==$_.type(c[b])&&(a=c[b].toString(),b=encodeURIComponent(b),a=encodeURIComponent(a),d.push(b+"="+a));return d.join("&")}};$_.ext("get",function(e,b,a,d){c._do(e,b,a,d,!1)});$_.ext("post",function(e,b,a,d){c._do(e,b,a,d,!0)})})();
(function(e){var c,h;c=function(b,a,d,g){var f,e;if(a.match(/^([\w\-]+)$/))!0===g?b.addEventListener(a,d,!1):b.removeEventListener(a,d,!1);else for(a=a.split(" "),e=a.length,f=0;f<e;f++)c(b,a[f],d,g)};h=function(b,a,d,g){c(b,d,function(d){var e,c;c=$_.$(a,b);for(e in c)d.target==c[e]&&(g.call(c[e],d),d.stopPropagation())},!0)};$_.ext("event",{create:function(b,a){if(/MSIE|Trident/i.test(navigator.userAgent)){var d=document.createEvent("CustomEvent");d.initCustomEvent(b,!0,!0,a);return d}return new CustomEvent(b,
a)},add:function(b,a){$_.each(function(d){c(d,b,a,!0)})},remove:function(b,a){$_.each(function(d){c(d,b,a,!1)})},live:function(b,a,d){h(document.documentElement,b,a,d)},delegate:function(b,a,d){$_.each(function(c){h(c,b,a,d)})},trigger:function(b){return this.el.dispatchEvent(b)}})})();
(function(e){function c(a,d,b){var c;a.hasAttribute(d)&&(c=a.getAttribute(d));if(c===e&&(b===e||null===b))return null;if(b===e)return c;b!==e&&null!==b?a.setAttribute(d,b):null===b&&a.removeAttribute(d);return b!==e?b:c}function h(a){return String(a).replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function b(a,d,b){var c;d=h(d);c={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if(b===e&&a.style[d]!==e)return a.style[d];if(b===e&&a.style[c[d]]!==e)return a.style[c[d]];
if(a.style[d]!==e)return a.style[d]=b,null;if(a.style[c[d]])return a.style[c[d]]=b,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===e&&(a="block");this.css("display",a)},attr:function(a,b){var g=this.el;if(1<g.length&&b===e)return null;if(1<g.length&&b!==e)$_.each(function(e){return c(e,a,b)});else return c(g,a,b)},text:function(a){var b,
c,f;f=this.el;c=a!==e?!0:!1;b=f.textContent;return c?f.textContent=a:b},css:function(a,d){var c=null;if("object"===$_.type(a))for(c in a)a.hasOwnProperty(c)&&$_.each(function(d){b(d,c,a[c])});else if(d===e&&"object"!==$_.type(a))return b(this.el,a);$_.each(function(c){b(c,a,d)})},append:function(a){this.el.insertAdjacentHTML("beforeend",a)},prepend:function(a){this.el.insertAdjacentHTML("afterbegin",a)},html:function(a){a!==e&&(this.el.innerHTML=a);return this.el.innerHTML}})})();