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

18 lines
7.5 KiB
JavaScript
Executable File

(function(){if("undefined"!==typeof document.querySelector){var g,e,f,b;g=function(a){b="undefined"===typeof a?"undefined"!==typeof g.el?g.el:document.documentElement:"object"!==typeof a?e(a):a;g.prototype.el=b;var a=f(g),c;for(c in a)"object"===typeof a[c]&&(a[c].el=b);a.el=b;return a};e=function(a,c){var b;if("string"!=typeof a||"undefined"===typeof a)return a;b=null!=c&&1===c.nodeType?c:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);b=b.querySelectorAll(a);
return 1===b.length?b[0]:b};f=function(a){var c;if("undefined"!==typeof a){if("undefined"!==typeof Object.create)return Object.create(a);c=typeof a;if(!("object"!==c&&"function"!==c))return c=function(){},c.prototype=a,new c}};g.ext=function(a,c){c.el=b;g[a]=c};g.ext("each",function(a){if("undefined"!==typeof b.length&&b!==window){var c=b.length;if(0!==c)for(var d,h=0;h<c;h++)d=b.item(h)?b.item(h):b[h],a.call(d,d)}else a.call(b,b)});g.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()};g=window.$_=window.$_||g;g.$=e}})();
(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})})();
(function(){if("undefined"!==typeof window.XMLHttpRequest){var g={_do:function(e,f,b,a){var c=new XMLHttpRequest;"undefined"===typeof b&&(b=function(){});a=a?"POST":"GET";e+="GET"===a?"?"+this._serialize(f):"";c.open(a,e);c.onreadystatechange=function(){4===c.readyState&&b(c.responseText)};"POST"===a?(c.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),c.send(this._serialize(f))):c.send(null)},_serialize:function(e){var f,b,a=[];for(f in e)e.hasOwnProperty(f)&&"function"!==typeof e[f]&&
(b=e[f].toString(),f=encodeURIComponent(f),b=encodeURIComponent(b),a.push(f+"="+b));return a.join("&")}};$_.ext("get",function(e,f,b){g._do(e,f,b,!1)});$_.ext("post",function(e,f,b){g._do(e,f,b,!0)});$_.ext("sse",function(e,f,b){"undefined"!==typeof EventSource?(e=new EventSource(e),e.onmessage=f):setInterval($_.get,b||3E4,e,{},f)})}})();
(function(){var g,e,f,b;"undefined"!==typeof document.addEventListener?(g=function(a,c,b){"undefined"!==typeof a.addEventListener&&a.addEventListener(c,b,!1)},e=function(a,c,b){"undefined"!==typeof a.removeEventListener&&a.removeEventListener(c,b,!1)}):"undefined"!==typeof document.attachEvent&&(g=function(a,c,b){function h(a){b.apply(a)}"undefined"!==typeof a.attachEvent?(e(c,b),a.attachEvent("on"+c,h),a=a.KIS_0_6_0=a.KIS_0_6_0||{},a.listeners=a.listeners||{},a.listeners[c]=a.listeners[c]||[],a.listeners[c].push({callback:b,
_listener:h})):console.log("Failed to _attach event:"+c+" on "+a)},e=function(a,b,d){if("undefined"!==typeof a.detachEvent){var h=a.KIS_0_6_0;if(h&&h.listeners&&h.listeners[b])for(var e=h.listeners[b],f=e.length,i=0;i<f;i++)if(e[i].callback===d){a.detachEvent("on"+b,e[i]._listener);e.splice(i,1);0===e.length&&delete h.listeners[b];break}}});f=function(a,b,d,h){var j,k;if(typeof a==="undefined"){console.log(arguments);console.log(b);return false}if(b.match(/^([\w\-]+)$/))h===true?g(a,b,d):e(a,b,d);
else{b=b.split(" ");k=b.length;for(j=0;j<k;j++)f(a,b[j],d,h)}};b=function(a,b,d,e){f(a,d,function(d){var f,i,g,d=d||window.event;i=$_.$(b,a);for(f in i){g=d.target||d.srcElement;if(g==i[f]){e.call(i[f],d);d.stopPropagation()}}},true)};$_.ext("event",{add:function(a,b){$_.each(function(d){f(d,a,b,true)})},remove:function(a,b){$_.each(function(d){f(d,a,b,false)})},live:function(a,c,d){b(document.documentElement,a,c,d)},delegate:function(a,c,d){$_.each(function(e){b(e,a,c,d)})}})})();
"undefined"!==typeof document&&!("classList"in document.createElement("a"))&&function(g){var g=(g.HTMLElement||g.Element).prototype,e=Object,f=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},b=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},c=function(c,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 b.call(c,d)},d=function(a){for(var b=f.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()}},h=d.prototype=[],j=function(){return new d(this)};a.prototype=Error.prototype;h.item=function(a){return this[a]||null};h.contains=function(a){return-1!==c(this,a+"")};h.add=function(a){a+="";-1===c(this,a)&&(this.push(a),this._updateClassName())};h.remove=function(a){a=c(this,
a+"");-1!==a&&(this.splice(a,1),this._updateClassName())};h.toggle=function(a){a+="";-1===c(this,a)?this.add(a):this.remove(a)};h.toString=function(){return this.join(" ")};if(e.defineProperty){h={get:j,enumerable:!0,configurable:!0};try{e.defineProperty(g,"classList",h)}catch(k){-2146823252===k.number&&(h.enumerable=!1,e.defineProperty(g,"classList",h))}}else e.prototype.__defineGetter__&&g.__defineGetter__("classList",j)}(self);
(function(){function g(b,a,c){var d,e;"undefined"!==typeof b.hasAttribute?(b.hasAttribute(a)&&(d=b.getAttribute(a)),e=!0):"undefined"!==typeof b[a]?(d=b[a],e=!1):"class"===a&&"undefined"!==typeof b.className&&(a="className",d=b.className,e=!1);if("undefined"===typeof d&&("undefined"===typeof c||null===c))return console.log(c),console.log(b),console.log("Element does not have the selected attribute"),null;if("undefined"===typeof c)return d;"undefined"!==typeof c&&null!==c?!0===e?b.setAttribute(a,c):
b[a]=c:null===c&&(!0===e?b.removeAttribute(a):delete b[a]);return"undefined"!==typeof c?c:d}function e(b){return b.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function f(b,a,c){var d,a=e(a);d={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[d[a]])return b.style[d[a]];if("undefined"!==typeof b.style[a])return b.style[a]=c,null;if(b.style[d[a]])return b.style[d[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 c=this.el;if(1<c.length&&"undefined"===typeof a)console.log(c),console.log("Must be a singular element");else if(1<c.length&&"undefined"!==typeof a)$_.each(function(c){return g(c,
b,a)});else return g(c,b,a)},text:function(b){var a,c,d;d=this.el;c="undefined"!==typeof d.textContent?"textContent":"undefined"!==typeof d.innerText?"innerText":"innerHTML";a=d[c];return"undefined"!==typeof b?d[c]=b:a},css:function(b,a){if("undefined"===typeof a)return f(this.el,b);$_.each(function(c){f(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}})})();