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

19 lines
7.8 KiB
JavaScript
Executable File

(function(){if("undefined"!==typeof document.querySelector){var c,g,e,b;c=function(a){b="undefined"===typeof a?"undefined"!==typeof c.el?c.el:document.documentElement:"object"!==typeof a?g(a):a;c.prototype.el=b;var a=e(c),d;for(d in a)"object"===typeof a[d]&&(a[d].el=b);a.el=b;return a};g=function(a,d){var b;if("string"!=typeof a||"undefined"===typeof a)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};e=function(a){var d;if("undefined"!==typeof a){if("undefined"!==typeof Object.create)return Object.create(a);d=typeof a;if(!("object"!==d&&"function"!==d))return d=function(){},d.prototype=a,new d}};c.ext=function(a,d){d.el=b;c[a]=d};c.ext("each",function(a){if("undefined"!==typeof b.length&&b!==window)if("undefined"!==typeof Array.prototype.forEach)[].forEach.call(b,a);else{var d=b.length;if(0!==d)for(var h,f=0;f<d;f++)h=b.item(f)?b.item(f):b[f],a.call(h,h)}else 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.$=g}})();
(function(){"undefined"===typeof window.console&&(window.console={log:function(){}});"undefined"===typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")});"undefined"===typeof Event.preventDefault&&"undefined"!==typeof window.event&&(Event.prototype.preventDefault=function(){window.event.returnValue=false},Event.prototype.stopPropagation=function(){window.event.cancelBubble=true});"undefined"===typeof[].isArray&&(Array.isArray=function(c){return Object.prototype.toString.apply(c)===
"[object Array]"})})();
(function(){if("undefined"!==typeof window.XMLHttpRequest){var c={_do:function(g,c,b,a){var d=new XMLHttpRequest;"undefined"===typeof b&&(b=function(){});a=a?"POST":"GET";g+="GET"===a?"?"+this._serialize(c):"";d.open(a,g);d.onreadystatechange=function(){4===d.readyState&&b(d.responseText)};"POST"===a?(d.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),d.send(this._serialize(c))):d.send(null)},_serialize:function(c){var e,b,a=[];for(e in c)c.hasOwnProperty(e)&&"function"!==typeof c[e]&&
(b=c[e].toString(),e=encodeURIComponent(e),b=encodeURIComponent(b),a.push(e+"="+b));return a.join("&")}};$_.ext("get",function(g,e,b){c._do(g,e,b,!1)});$_.ext("post",function(g,e,b){c._do(g,e,b,!0)});$_.ext("sse",function(c,e,b){"undefined"!==typeof EventSource?(c=new EventSource(c),c.onmessage=function(a){e(a.data)}):setInterval($_.get,b||3E4,c,{},function(a){a.trim().replace(/data:/gim,"");a.replace(/^event|id|retry?:(.*)$/gim,"");e(a)})})}})();
(function(){var c,g,e,b;"undefined"!==typeof document.addEventListener?(c=function(a,d,b){"undefined"!==typeof a.addEventListener&&a.addEventListener(d,b,!1)},g=function(a,d,b){"undefined"!==typeof a.removeEventListener&&a.removeEventListener(d,b,!1)}):"undefined"!==typeof document.attachEvent&&(c=function(a,b,h){function c(a){h.apply(a)}"undefined"!==typeof a.attachEvent?(g(b,h),a.attachEvent("on"+b,c),a=a.KIS_0_6_0=a.KIS_0_6_0||{},a.listeners=a.listeners||{},a.listeners[b]=a.listeners[b]||[],a.listeners[b].push({callback:h,
_listener:c})):console.log("Failed to _attach event:"+b+" on "+a)},g=function(a,b,c){if("undefined"!==typeof a.detachEvent){var f=a.KIS_0_6_0;if(f&&f.listeners&&f.listeners[b])for(var e=f.listeners[b],g=e.length,i=0;i<g;i++)if(e[i].callback===c){a.detachEvent("on"+b,e[i]._listener);e.splice(i,1);0===e.length&&delete f.listeners[b];break}}});e=function(a,b,h,f){var j,k;if(typeof a==="undefined"){console.log(arguments);console.log(b);return false}if(b.match(/^([\w\-]+)$/))f===true?c(a,b,h):g(a,b,h);
else{b=b.split(" ");k=b.length;for(j=0;j<k;j++)e(a,b[j],h,f)}};b=function(a,b,c,f){e(a,c,function(c){var h,i,e,c=c||window.event;i=$_.$(b,a);for(h in i){e=c.target||c.srcElement;if(e==i[h]){f.call(i[h],c);c.stopPropagation()}}},true)};$_.ext("event",{add:function(a,b){$_.each(function(c){e(c,a,b,true)})},remove:function(a,b){$_.each(function(c){e(c,a,b,false)})},live:function(a,d,c){b(document.documentElement,a,d,c)},delegate:function(a,d,c){$_.each(function(e){b(e,a,d,c)})}})})();
"undefined"!==typeof document&&!("classList"in document.createElement("a"))&&function(c){var c=(c.HTMLElement||c.Element).prototype,g=Object,e=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},b=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},a=function(a,b){this.name=a;this.code=DOMException[a];this.message=b},d=function(d,c){if(""===c)throw new a("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(c))throw new a("INVALID_CHARACTER_ERR",
"String contains an invalid character");return b.call(d,c)},h=function(a){for(var b=e.call(a.className),b=b?b.split(/\s+/):[],d=0,c=b.length;d<c;d++)this.push(b[d]);this._updateClassName=function(){a.className=this.toString()}},f=h.prototype=[],j=function(){return new h(this)};a.prototype=Error.prototype;f.item=function(a){return this[a]||null};f.contains=function(a){return-1!==d(this,a+"")};f.add=function(a){a+="";-1===d(this,a)&&(this.push(a),this._updateClassName())};f.remove=function(a){a=d(this,
a+"");-1!==a&&(this.splice(a,1),this._updateClassName())};f.toggle=function(a){a+="";-1===d(this,a)?this.add(a):this.remove(a)};f.toString=function(){return this.join(" ")};if(g.defineProperty){f={get:j,enumerable:!0,configurable:!0};try{g.defineProperty(c,"classList",f)}catch(k){-2146823252===k.number&&(f.enumerable=!1,g.defineProperty(c,"classList",f))}}else g.prototype.__defineGetter__&&c.__defineGetter__("classList",j)}(self);
(function(){function c(b,a,d){var c,e;"undefined"!==typeof b.hasAttribute?(b.hasAttribute(a)&&(c=b.getAttribute(a)),e=!0):"undefined"!==typeof b[a]?(c=b[a],e=!1):"class"===a&&"undefined"!==typeof b.className&&(a="className",c=b.className,e=!1);if("undefined"===typeof c&&("undefined"===typeof d||null===d))return console.log(d),console.log(b),console.log("Element does not have the selected attribute"),null;if("undefined"===typeof d)return c;"undefined"!==typeof d&&null!==d?!0===e?b.setAttribute(a,d):
b[a]=d:null===d&&(!0===e?b.removeAttribute(a):delete b[a]);return"undefined"!==typeof d?d:c}function g(b){return b.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function e(b,a,c){var e,a=g(a);e={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if("undefined"===typeof c&&"undefined"!==b.style[a])return b.style[a];if("undefined"===typeof c&&"undefined"!==b.style[e[a]])return b.style[e[a]];if("undefined"!==typeof b.style[a])return b.style[a]=c,null;if(b.style[e[a]])return b.style[e[a]]=
c,null;console.log("Property "+a+" nor an equivalent seems to exist")}$_.ext("dom",{addClass:function(b){$_.each(function(a){a.classList.add(b)})},removeClass:function(b){$_.each(function(a){a.classList.remove(b)})},hide:function(){this.css("display","none")},show:function(b){"undefined"===typeof b&&(b="block");this.css("display",b)},attr:function(b,a){var d=this.el;if(1<d.length&&"undefined"===typeof a)console.log(d),console.log("Must be a singular element");else if(1<d.length&&"undefined"!==typeof a)$_.each(function(d){return c(d,
b,a)});else return c(d,b,a)},text:function(b){var a,c,e;e=this.el;c="undefined"!==typeof e.textContent?"textContent":"undefined"!==typeof e.innerText?"innerText":"innerHTML";a=e[c];return"undefined"!==typeof b?e[c]=b:a},css:function(b,a){if("undefined"===typeof a)return e(this.el,b);$_.each(function(c){e(c,b,a)})},append:function(b){"undefined"!==typeof document.insertAdjacentHTML?this.el.insertAdjacentHTML("beforeend",b):this.el.innerHTML+=b},prepend:function(b){"undefined"!==typeof document.insertAdjacentHTML?
this.el.insertAdjacentHTML("afterbegin",b):this.el.innerHTML=b+this.el.innerHTML},html:function(b){"undefined"!==typeof b&&(this.el.innerHTML=b);return this.el.innerHTML}})})();