kis-js/kis-min.js

26 lines
10 KiB
JavaScript
Executable File

(function(){if("undefined"!==typeof document.querySelector){var g,f,c,b;g=function(a){b="undefined"===typeof a?"undefined"!==typeof g.el?g.el:document.documentElement:"object"!==typeof a?f(a):a;g.prototype.el=b;var a=c(g),d;for(d in a)"object"===typeof a[d]&&(a[d].el=b);a.el=b;return a};f=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};c=function(a){var b;if("undefined"!==typeof a){if("undefined"!==typeof Object.create)return Object.create(a);b=typeof a;if(!("object"!==b&&"function"!==b))return b=function(){},b.prototype=a,new b}};g.ext=function(a,d){d.el=b;g[a]=d};g.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 e,c=0;c<d;c++)e=b.item(c)?b.item(c):b[c],a.call(e,e)}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.$=f}})();
(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(g){return Object.prototype.toString.apply(g)===
"[object Array]"})})();
"undefined"!==typeof document&&!("classList"in document.createElement("a"))&&function(g){var g=(g.HTMLElement||g.Element).prototype,f=Object,c=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,e){if(""===e)throw new a("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(e))throw new a("INVALID_CHARACTER_ERR",
"String contains an invalid character");return b.call(d,e)},e=function(a){for(var b=c.call(a.className),b=b?b.split(/\s+/):[],d=0,e=b.length;d<e;d++)this.push(b[d]);this._updateClassName=function(){a.className=this.toString()}},h=e.prototype=[],i=function(){return new e(this)};a.prototype=Error.prototype;h.item=function(a){return this[a]||null};h.contains=function(a){return-1!==d(this,a+"")};h.add=function(a){a+="";-1===d(this,a)&&(this.push(a),this._updateClassName())};h.remove=function(a){a=d(this,
a+"");-1!==a&&(this.splice(a,1),this._updateClassName())};h.toggle=function(a){a+="";-1===d(this,a)?this.add(a):this.remove(a)};h.toString=function(){return this.join(" ")};if(f.defineProperty){h={get:i,enumerable:!0,configurable:!0};try{f.defineProperty(g,"classList",h)}catch(j){-2146823252===j.number&&(h.enumerable=!1,f.defineProperty(g,"classList",h))}}else f.prototype.__defineGetter__&&g.__defineGetter__("classList",i)}(self);
(function(){function g(b,a,d){var e,c;"undefined"!==typeof b.hasAttribute?(b.hasAttribute(a)&&(e=b.getAttribute(a)),c=!0):"undefined"!==typeof b[a]?(e=b[a],c=!1):"class"===a&&"undefined"!==typeof b.className&&(a="className",e=b.className,c=!1);if("undefined"===typeof e&&("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 e;"undefined"!==typeof d&&null!==d?!0===c?b.setAttribute(a,d):
b[a]=d:null===d&&(!0===c?b.removeAttribute(a):delete b[a]);return"undefined"!==typeof d?d:e}function f(b){return b.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function c(b,a,d){var e,a=f(a);e={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if("undefined"===typeof d&&"undefined"!==b.style[a])return b.style[a];if("undefined"===typeof d&&"undefined"!==b.style[e[a]])return b.style[e[a]];if("undefined"!==typeof b.style[a])return b.style[a]=d,null;if(b.style[e[a]])return b.style[e[a]]=
d,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 g(d,
b,a)});else return g(d,b,a)},text:function(b){var a,d,c;c=this.el;d="undefined"!==typeof c.textContent?"textContent":"undefined"!==typeof c.innerText?"innerText":"innerHTML";a=c[d];return"undefined"!==typeof b?c[d]=b:a},css:function(b,a){if("undefined"===typeof a)return c(this.el,b);$_.each(function(d){c(d,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}})})();
(function(){if("undefined"!==typeof window.XMLHttpRequest){var g={_do:function(f,c,b,a){var d=new XMLHttpRequest;"undefined"===typeof b&&(b=function(){});a=a?"POST":"GET";f+="GET"===a?"?"+this._serialize(c):"";d.open(a,f);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(f){var c,b,a=[];for(c in f)f.hasOwnProperty(c)&&"function"!==typeof f[c]&&
(b=f[c].toString(),c=encodeURIComponent(c),b=encodeURIComponent(b),a.push(c+"="+b));return a.join("&")}};$_.ext("get",function(f,c,b){g._do(f,c,b,!1)});$_.ext("post",function(f,c,b){g._do(f,c,b,!0)});$_.ext("sse",function(f,c,b){"undefined"!==typeof EventSource?(f=new EventSource(f),f.onmessage=function(a){c(a.data)}):setInterval($_.get,b||3E4,f,{},function(a){a.trim().replace(/data:/gim,"");a.replace(/^event|id|retry?:(.*)$/gim,"");c(a)})})}})();
(function(){var g,f,c,b;"undefined"!==typeof document.addEventListener?(g=function(a,b,c){"undefined"!==typeof a.addEventListener&&a.addEventListener(b,c,!1)},f=function(a,b,c){"undefined"!==typeof a.removeEventListener&&a.removeEventListener(b,c,!1)}):"undefined"!==typeof document.attachEvent&&(g=function(a,b,c){function h(a){c.apply(a)}"undefined"!==typeof a.attachEvent?(f(b,c),a.attachEvent("on"+b,h),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:h})):console.log("Failed to _attach event:"+b+" on "+a)},f=function(a,b,c){if("undefined"!==typeof a.detachEvent){var h=a.KIS_0_6_0;if(h&&h.listeners&&h.listeners[b])for(var f=h.listeners[b],g=f.length,k=0;k<g;k++)if(f[k].callback===c){a.detachEvent("on"+b,f[k]._listener);f.splice(k,1);0===f.length&&delete h.listeners[b];break}}});c=function(a,b,e,h){var i,j;if(typeof a==="undefined"){console.log(arguments);console.log(b);return false}if(b.match(/^([\w\-]+)$/))h===true?g(a,b,e):f(a,b,e);
else{b=b.split(" ");j=b.length;for(i=0;i<j;i++)c(a,b[i],e,h)}};b=function(a,b,e,f){c(a,e,function(c){var e,g,l,c=c||window.event;g=$_.$(b,a);for(e in g){l=c.target||c.srcElement;if(l==g[e]){f.call(g[e],c);c.stopPropagation()}}},true)};$_.ext("event",{add:function(a,b){$_.each(function(e){c(e,a,b,true)})},remove:function(a,b){$_.each(function(e){c(e,a,b,false)})},live:function(a,c,e){b(document.documentElement,a,c,e)},delegate:function(a,c,e){$_.each(function(f){b(f,a,c,e)})}})})();
(function(){var g=window.indexedDB||window.webkitIndexedDB||window.mozIndexedDB||window.msIndexedDB,f={};"undefined"!==typeof g&&(f={current_db:null,connect:function(c,b,a){var d={},d=g.open(c,b||1);"undefined"!==typeof a&&(d.onupgradeneeded=a);d.onerror=function(){console.log("IndexedDB disallowed.")};d.onsuccess=function(){f.current_db=d.result}},create_store:function(c,b,a){var d={};"undefined"!==typeof b&&(d.keyPath=b);"undefined"!==typeof a&&(d.autoIncrement=!!a);return g.createObjectStore(c,
d)},delete_store:function(){g.deleteObjectStore().onerror=g.onerror}},$_.ext("indexedDB",f))})();
(function(){if("undefined"===typeof localStorage||"undefined"===typeof JSON)return null;var g=localStorage,f=sessionStorage;$_.ext("store",{get:function(c,b){var a=b?f.getItem(c):g.getItem(c);return JSON.parse(a)},set:function(c,b,a){b=JSON.stringify(b);a?f.setItem(c,b):g.setItem(c,b)},remove:function(c,b){b?f.removeItem(c):g.removeItem(c)},getAll:function(c){var b,a={},d,e;e=c?g:f;b=e.length;for(c=0;c<b;c++)d=e.key(c),a[d]=e.getItem(d);return a},clear:function(c){c?f.clear():g.clear()}})})();
(function(){var g=function(c){var b=[],a=0,d={},e,b=f.object_keys(c);b.sort(function(a,b){var c=parseFloat(b),d=parseFloat(a),e=c+""===b,f=d+""===a;return e&&f?c>d?1:c<d?-1:0:e&&!f?1:!e&&f?-1:b>a?1:b<a?-1:0});a=b.length;for(e=0;e<a;e++)d[b[e]]=c[b[e]];return d},f={object_keys:function(c){var b=[],a;for(a in c)c.hasOwnProperty(a)&&b.push(a);return b},object_values:function(c){var b=[],a;for(a in c)b.push(c[a]);return b},array_combine:function(c,b){var a={},d,e=0;"array"!==$_.type(c)&&(c=this.object_values(c));
"array"!==$_.type(b)&&(b=this.object_values(b));d=c.length;if(d!==b.length)return console.log("Object combine requires two arrays of the same size"),!1;for(e=0;e<d;e++)a[c[e]]=b[e];return a},object_merge:function(){var c=Array.prototype.slice.call(arguments),b=c.length,a={},d,e=0,f,g,j;d=!0;for(f=0;f<b;f++)if("array"!==$_.type(c[f])){d=!1;break}if(d){a=[];for(f=0;f<b;f++)a=a.contact(c[f]);return a}for(j=f=0;f<b;f++)if(d=c[f],"array"==$_.type(d)){g=0;for(e=d.length;g<e;g++)a[j++]=d[g]}else for(g in d)d.hasOwnProperty(g)&&
(parseInt(g,10)+""===g?a[j++]=d[g]:a[g]=d[g]);return a},str_trans:function(c,b,a){var d=[],e=[],f=!1,i=0,j=0,k="",l="",o="",m="",n;if("object"===typeof b){b=g(b);for(n in b)b.hasOwnProperty(n)&&(d.push(n),e.push(b[n]));b=d;a=e}j=c.length;i=b.length;k="string"===typeof a;l="string"===typeof b;for(d=0;d<j;d++){f=!1;if(l){c.charAt(d-1);o=c.charAt(d);c.charAt(d+1);for(e=0;e<i;e++)if(o==b.charAt(e)){f=!0;break}}else for(e=0;e<i;e++)if(c.substr(d,b[e].length)==b[e]){f=!0;d=d+b[e].length-1;break}m=f?m+(k?
a.charAt(e):a[e]):m+c.charAt(d)}return m}};$_.ext("util",f)})();