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

18 lines
7.8 KiB
JavaScript
Executable File

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