kis-js/kis-min.js

25 lines
10 KiB
JavaScript
Executable File

(function(){if("undefined"!==typeof document.querySelector){var g,f,c,a;g=function(b){a="undefined"===typeof b?"undefined"!==typeof g.el?g.el:document.documentElement:"object"!==typeof b?f(b):b;g.prototype.el=a;var b=c(g),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};c=function(b){var a;if("undefined"!==typeof b){if("undefined"!==typeof Object.create)return Object.create(b);a=typeof b;if(!("object"!==a&&"function"!==a))return a=function(){},a.prototype=b,new a}};g.ext=function(b,d){d.el=a;g[b]=d};g.ext("each",function(b){if("undefined"!==typeof a.length&&a!==window){var d=a.length;if(0!==d)for(var e,c=0;c<d;c++)e=a.item(c)?a.item(c):a[c],b.call(e,e)}else b.call(a,a)});g.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()};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 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,"")},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,e){if(""===e)throw new b("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(e))throw new b("INVALID_CHARACTER_ERR",
"String contains an invalid character");return a.call(d,e)},e=function(b){for(var a=c.call(b.className),a=a?a.split(/\s+/):[],d=0,e=a.length;d<e;d++)this.push(a[d]);this._updateClassName=function(){b.className=this.toString()}},h=e.prototype=[],i=function(){return new e(this)};b.prototype=Error.prototype;h.item=function(b){return this[b]||null};h.contains=function(b){return-1!==d(this,b+"")};h.add=function(b){b+="";-1===d(this,b)&&(this.push(b),this._updateClassName())};h.remove=function(b){b=d(this,
b+"");-1!==b&&(this.splice(b,1),this._updateClassName())};h.toggle=function(b){b+="";-1===d(this,b)?this.add(b):this.remove(b)};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(a,b,d){var e,c;"undefined"!==typeof a.hasAttribute?(a.hasAttribute(b)&&(e=a.getAttribute(b)),c=!0):"undefined"!==typeof a[b]?(e=a[b],c=!1):"class"===b&&"undefined"!==typeof a.className&&(b="className",e=a.className,c=!1);if("undefined"===typeof e&&("undefined"===typeof d||null===d))return console.log(d),console.log(a),console.log("Element does not have the selected attribute"),null;if("undefined"===typeof d)return e;"undefined"!==typeof d&&null!==d?!0===c?a.setAttribute(b,d):
a[b]=d:null===d&&(!0===c?a.removeAttribute(b):delete a[b]);return"undefined"!==typeof d?d:e}function f(a){return a.replace(/(\-[a-z])/g,function(b){return b.toUpperCase().replace("-","")})}function c(a,b,d){var e,b=f(b);e={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if("undefined"===typeof d&&"undefined"!==a.style[b])return a.style[b];if("undefined"===typeof d&&"undefined"!==a.style[e[b]])return a.style[e[b]];if("undefined"!==typeof a.style[b])return a.style[b]=d,null;if(a.style[e[b]])return a.style[e[b]]=
d,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){"undefined"===typeof a&&(a="block");this.css("display",a)},attr:function(a,b){var d=this.el;if(1<d.length&&"undefined"===typeof b)console.log(d),console.log("Must be a singular element");else if(1<d.length&&"undefined"!==typeof b)$_.each(function(d){return g(d,
a,b)});else return g(d,a,b)},text:function(a){var b,d,c;c=this.el;d="undefined"!==typeof c.textContent?"textContent":"undefined"!==typeof c.innerText?"innerText":"innerHTML";b=c[d];return"undefined"!==typeof a?c[d]=a:b},css:function(a,b){if("undefined"===typeof b)return c(this.el,a);$_.each(function(d){c(d,a,b)})},append:function(a){"undefined"!==typeof document.insertAdjacentHTML?this.el.insertAdjacentHTML("beforeend",a):this.el.innerHTML+=a},prepend:function(a){"undefined"!==typeof document.insertAdjacentHTML?
this.el.insertAdjacentHTML("afterbegin",a):this.el.innerHTML=a+this.el.innerHTML},html:function(a){"undefined"!==typeof a&&(this.el.innerHTML=a);return this.el.innerHTML}})})();
(function(){if("undefined"!==typeof window.XMLHttpRequest){var g={_do:function(f,c,a,b){var d=new XMLHttpRequest;"undefined"===typeof a&&(a=function(){});b=b?"POST":"GET";f+="GET"===b?"?"+this._serialize(c):"";d.open(b,f);d.onreadystatechange=function(){4===d.readyState&&a(d.responseText)};"POST"===b?(d.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),d.send(this._serialize(c))):d.send(null)},_serialize:function(f){var c,a,b=[];for(c in f)f.hasOwnProperty(c)&&"function"!==typeof f[c]&&
(a=f[c].toString(),c=encodeURIComponent(c),a=encodeURIComponent(a),b.push(c+"="+a));return b.join("&")}};$_.ext("get",function(f,c,a){g._do(f,c,a,!1)});$_.ext("post",function(f,c,a){g._do(f,c,a,!0)});$_.ext("sse",function(f,c,a){"undefined"!==typeof EventSource?(f=new EventSource(f),f.onmessage=c):setInterval($_.get,a||3E4,f,{},c)})}})();
(function(){var g,f,c,a;"undefined"!==typeof document.addEventListener?(g=function(b,a,c){"undefined"!==typeof b.addEventListener&&b.addEventListener(a,c,!1)},f=function(b,a,c){"undefined"!==typeof b.removeEventListener&&b.removeEventListener(a,c,!1)}):"undefined"!==typeof document.attachEvent&&(g=function(b,a,c){function h(b){c.apply(b)}"undefined"!==typeof b.attachEvent?(f(a,c),b.attachEvent("on"+a,h),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:c,
_listener:h})):console.log("Failed to _attach event:"+a+" on "+b)},f=function(b,a,c){if("undefined"!==typeof b.detachEvent){var h=b.KIS_0_6_0;if(h&&h.listeners&&h.listeners[a])for(var f=h.listeners[a],g=f.length,k=0;k<g;k++)if(f[k].callback===c){b.detachEvent("on"+a,f[k]._listener);f.splice(k,1);0===f.length&&delete h.listeners[a];break}}});c=function(b,a,e,h){var i,j;if(typeof b==="undefined"){console.log(arguments);console.log(a);return false}if(a.match(/^([\w\-]+)$/))h===true?g(b,a,e):f(b,a,e);
else{a=a.split(" ");j=a.length;for(i=0;i<j;i++)c(b,a[i],e,h)}};a=function(b,a,e,f){c(b,e,function(c){var e,g,l,c=c||window.event;g=$_.$(a,b);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(b,a){$_.each(function(e){c(e,b,a,true)})},remove:function(a,d){$_.each(function(e){c(e,a,d,false)})},live:function(b,d,c){a(document.documentElement,b,d,c)},delegate:function(b,c,e){$_.each(function(f){a(f,b,c,e)})}})})();
(function(){var g=window.indexedDB||window.webkitIndexedDB||window.mozIndexedDB||window.msIndexedDB,f={};"undefined"!==typeof g&&(f={current_db:null,connect:function(c,a,b){var d={},d=g.open(c,a||1);"undefined"!==typeof b&&(d.onupgradeneeded=b);d.onerror=function(){console.log("IndexedDB disallowed.")};d.onsuccess=function(){f.current_db=d.result}},create_store:function(c,a,b){var d={};"undefined"!==typeof a&&(d.keyPath=a);"undefined"!==typeof b&&(d.autoIncrement=!!b);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,a){var b=a?f.getItem(c):g.getItem(c);return JSON.parse(b)},set:function(c,a,b){a=JSON.stringify(a);b?f.setItem(c,a):g.setItem(c,a)},remove:function(c,a){a?f.removeItem(c):g.removeItem(c)},getAll:function(c){var a,b={},d,e;e=c?g:f;a=e.length;for(c=0;c<a;c++)d=e.key(c),b[d]=e.getItem(d);return b},clear:function(c){c?f.clear():g.clear()}})})();
(function(){var g=function(c){var a=[],b=0,d={},e,a=f.object_keys(c);a.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});b=a.length;for(e=0;e<b;e++)d[a[e]]=c[a[e]];return d},f={object_keys:function(c){var a=[],b;for(b in c)c.hasOwnProperty(b)&&a.push(b);return a},object_values:function(c){var a=[],b;for(b in c)a.push(c[b]);return a},array_combine:function(c,a){var b={},d,e=0;"array"!==$_.type(c)&&(c=this.object_values(c));
"array"!==$_.type(a)&&(a=this.object_values(a));d=c.length;if(d!==a.length)return console.log("Object combine requires two arrays of the same size"),!1;for(e=0;e<d;e++)b[c[e]]=a[e];return b},object_merge:function(){var c=Array.prototype.slice.call(arguments),a=c.length,b={},d,e=0,f,g,j;d=!0;for(f=0;f<a;f++)if("array"!==$_.type(c[f])){d=!1;break}if(d){b=[];for(f=0;f<a;f++)b=b.contact(c[f]);return b}for(j=f=0;f<a;f++)if(d=c[f],"array"==$_.type(d)){g=0;for(e=d.length;g<e;g++)b[j++]=d[g]}else for(g in d)d.hasOwnProperty(g)&&
(parseInt(g,10)+""===g?b[j++]=d[g]:b[g]=d[g]);return b},str_trans:function(c,a,b){var d=[],e=[],f=!1,i=0,j=0,k="",l="",o="",m="",n;if("object"===typeof a){a=g(a);for(n in a)a.hasOwnProperty(n)&&(d.push(n),e.push(a[n]));a=d;b=e}j=c.length;i=a.length;k="string"===typeof b;l="string"===typeof a;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==a.charAt(e)){f=!0;break}}else for(e=0;e<i;e++)if(c.substr(d,a[e].length)==a[e]){f=!0;d=d+a[e].length-1;break}m=f?m+(k?
b.charAt(e):b[e]):m+c.charAt(d)}return m}};$_.ext("util",f)})();