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

18 lines
7.9 KiB
JavaScript
Executable File

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