kis-js/kis-min.js

22 lines
10 KiB
JavaScript
Executable File

(function(){if("undefined"!==typeof document.querySelector){var e,k,p,f;e=function(h){f="undefined"===typeof h?"undefined"!==typeof e.el?e.el:document.documentElement:"object"!==typeof h?k(h):h;e.prototype.el=f;var h=p(e),i;for(i in h)"object"===typeof h[i]&&(h[i].el=f);h.el=f;return h};k=function(h,e){var f;if("string"!=typeof h||"undefined"===typeof h)return h;f=null!=e&&1===e.nodeType?e:document;if(h.match(/^#([\w\-]+$)/))return document.getElementById(h.split("#")[1]);f=f.querySelectorAll(h);
return 1===f.length?f[0]:f};p=function(e){var f;if("undefined"!==typeof e){if("undefined"!==typeof Object.create)return Object.create(e);f=typeof e;if(!("object"!==f&&"function"!==f))return f=function(){},f.prototype=e,new f}};e.ext=function(h,i){i.el=f;e[h]=i};e.ext("each",function(e){if("undefined"!==typeof f.length&&f!==window)if("undefined"!==typeof Array.prototype.forEach)[].forEach.call(f,e);else{var i=f.length;if(0!==i)for(var l,j=0;j<i;j++)l=f.item(j)?f.item(j):f[j],e.call(l,l)}else e.call(f,
f)});e.type=function(e){return function(){return e&&e!==this}.call(e)?(typeof e).toLowerCase():{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};e=window.$_=window.$_||e;e.$=k}})();"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(e){function k(a,b,c){var d,g;if(typeof a.hasAttribute!=="undefined"){a.hasAttribute(b)&&(d=a.getAttribute(b));g=true}else if(typeof a[b]!=="undefined"){d=a[b];g=false}else if(b==="class"&&typeof a.className!=="undefined"){b="className";d=a.className;g=false}if(typeof d==="undefined"&&(typeof c==="undefined"||c===null)){console.log(c);console.log(a);console.log("Element does not have the selected attribute");return null}if(typeof c==="undefined")return d;typeof c!=="undefined"&&c!==null?
g===true?a.setAttribute(b,c):a[b]=c:c===null&&(g===true?a.removeAttribute(b):delete a[b]);return typeof c!=="undefined"?c:d}function p(a){return a.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function f(a,b,c){var d,b=p(b);d={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if(typeof c==="undefined"&&a.style[b]!=="undefined")return a.style[b];if(typeof c==="undefined"&&a.style[d[b]]!=="undefined")return a.style[d[b]];if(typeof a.style[b]!=="undefined"){a.style[b]=
c;return null}if(a.style[d[b]]){a.style[d[b]]=c;return null}console.log("Property "+b+" nor an equivalent seems to exist")}typeof document!=="undefined"&&!("classList"in document.createElement("a"))&&function(a){var a=(a.HTMLElement||a.Element).prototype,b=Object,c=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},d=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},g=function(a,b){this.name=a;this.code=DOMException[a];
this.message=b},e=function(a,b){if(b==="")throw new g("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(b))throw new g("INVALID_CHARACTER_ERR","String contains an invalid character");return d.call(a,b)},n=function(a){for(var b=c.call(a.className),b=b?b.split(/\s+/):[],d=0,g=b.length;d<g;d++)this.push(b[d]);this._updateClassName=function(){a.className=this.toString()}},f=n.prototype=[],h=function(){return new n(this)};g.prototype=Error.prototype;f.item=function(a){return this[a]||
null};f.contains=function(a){return e(this,a+"")!==-1};f.add=function(a){a=a+"";if(e(this,a)===-1){this.push(a);this._updateClassName()}};f.remove=function(a){a=e(this,a+"");if(a!==-1){this.splice(a,1);this._updateClassName()}};f.toggle=function(a){a=a+"";e(this,a)===-1?this.add(a):this.remove(a)};f.toString=function(){return this.join(" ")};if(b.defineProperty){f={get:h,enumerable:true,configurable:true};try{b.defineProperty(a,"classList",f)}catch(i){if(i.number===-2146823252){f.enumerable=false;
b.defineProperty(a,"classList",f)}}}else b.prototype.__defineGetter__&&a.__defineGetter__("classList",h)}(self);e.ext("dom",{addClass:function(a){e.each(function(b){b.classList.add(a)})},removeClass:function(a){e.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 c=this.el;if(c.length>1&&typeof b==="undefined"){console.log(c);console.log("Must be a singular element")}else if(c.length>
1&&typeof b!=="undefined")e.each(function(c){return k(c,a,b)});else return k(c,a,b)},text:function(a){var b,c,d;d=this.el;c=typeof d.textContent!=="undefined"?"textContent":typeof d.innerText!=="undefined"?"innerText":"innerHTML";b=d[c];if(typeof a!=="undefined")return d[c]=a;return b},css:function(a,b){if(typeof b==="undefined")return f(this.el,a);e.each(function(c){f(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}});if(typeof window.XMLHttpRequest!=="undefined"){var h={_do:function(a,b,c,d){var g=new XMLHttpRequest;typeof c==="undefined"&&(c=function(){});d=d?"POST":"GET";a=a+(d==="GET"?"?"+this._serialize(b):"");g.open(d,a);g.onreadystatechange=function(){g.readyState===
4&&c(g.responseText)};if(d==="POST"){g.setRequestHeader("Content-Type","application/x-www-form-urlencoded");g.send(this._serialize(b))}else g.send(null)},_serialize:function(a){var b,c,d=[];for(b in a)if(a.hasOwnProperty(b)&&typeof a[b]!=="function"){c=a[b].toString();b=encodeURIComponent(b);c=encodeURIComponent(c);d.push(b+"="+c)}return d.join("&")}};e.ext("get",function(a,b,c){h._do(a,b,c,false)});e.ext("post",function(a,b,c){h._do(a,b,c,true)});e.ext("sse",function(a,b,c){if(typeof EventSource!==
"undefined"){a=new EventSource(a);a.onmessage=function(a){b(a.data)}}else setInterval(e.get,c||3E4,a,{},function(a){a.trim().replace(/data:/gim,"");a.replace(/^(event|id|retry)?\:(.*)$/gim,"");b.call(a,a)})});var i,l,j,q;if(typeof document.addEventListener!=="undefined"){i=function(a,b,c){typeof a.addEventListener!=="undefined"&&a.addEventListener(b,c,false)};l=function(a,b,c){typeof a.removeEventListener!=="undefined"&&a.removeEventListener(b,c,false)}}else if(typeof document.attachEvent!=="undefined"){i=
function(a,b,c){function d(a){c.apply(a)}if(typeof a.attachEvent!=="undefined"){l(b,c);a.attachEvent("on"+b,d);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:d})}else console.log("Failed to _attach event:"+b+" on "+a)};l=function(a,b,c){if(typeof a.detachEvent!=="undefined"){var d=a.KIS_0_6_0;if(d&&d.listeners&&d.listeners[b])for(var g=d.listeners[b],e=g.length,f=0;f<e;f++)if(g[f].callback===c){a.detachEvent("on"+
b,g[f]._listener);g.splice(f,1);g.length===0&&delete d.listeners[b];break}}}}j=function(a,b,c,d){var g,e;if(typeof a==="undefined"){console.log(arguments);console.log(b);return false}if(b.match(/^([\w\-]+)$/))d===true?i(a,b,c):l(a,b,c);else{b=b.split(" ");e=b.length;for(g=0;g<e;g++)j(a,b[g],c,d)}};q=function(a,b,c,d){j(a,c,function(c){var f,n,h,c=c||window.event;n=e.$(b,a);for(f in n){h=c.target||c.srcElement;if(h==n[f]){d.call(n[f],c);c.stopPropagation()}}},true)};e.ext("event",{add:function(a,b){e.each(function(c){j(c,
a,b,true)})},remove:function(a,b){e.each(function(c){j(c,a,b,false)})},live:function(a,b,c){q(document.documentElement,a,b,c)},delegate:function(a,b,c){e.each(function(d){q(d,a,b,c)})}});if(typeof localStorage==="undefined"||typeof JSON==="undefined")return null;var m=localStorage,o=sessionStorage;e.ext("store",{get:function(a,b){var c=b?o.getItem(a):m.getItem(a);return JSON.parse(c)},set:function(a,b,c){b=JSON.stringify(b);c?o.setItem(a,b):m.setItem(a,b)},remove:function(a,b){b?o.removeItem(a):m.removeItem(a)},
getAll:function(a){var b,c={},d,g;g=a?m:o;b=g.length;for(a=0;a<b;a++){d=g.key(a);c[d]=g.getItem(d)}return c},clear:function(a){a?o.clear():m.clear()}});var s=function(a){var b=[],c=0,d={},g,b=r.object_keys(a);b.sort(function(a,b){var c=parseFloat(b),d=parseFloat(a),g=c+""===b,e=d+""===a;return g&&e?c>d?1:c<d?-1:0:g&&!e?1:!g&&e?-1:b>a?1:b<a?-1:0});c=b.length;for(g=0;g<c;g++)d[b[g]]=a[b[g]];return d},r={object_keys:function(a){var b=[],c;for(c in a)a.hasOwnProperty(c)&&b.push(c);return b},object_values:function(a){var b=
[],c;for(c in a)b.push(a[c]);return b},array_combine:function(a,b){var c={},d,g=0;e.type(a)!=="array"&&(a=this.object_values(a));e.type(b)!=="array"&&(b=this.object_values(b));d=a.length;if(d!==b.length){console.log("Object combine requires two arrays of the same size");return false}for(g=0;g<d;g++)c[a[g]]=b[g];return c},object_merge:function(){var a=Array.prototype.slice.call(arguments),b=a.length,c={},d,g=0,f,h,i;d=true;for(f=0;f<b;f++)if(e.type(a[f])!=="array"){d=false;break}if(d){c=[];for(f=0;f<
b;f++)c=c.contact(a[f]);return c}for(i=f=0;f<b;f++){d=a[f];if(e.type(d)=="array"){h=0;for(g=d.length;h<g;h++)c[i++]=d[h]}else for(h in d)d.hasOwnProperty(h)&&(parseInt(h,10)+""===h?c[i++]=d[h]:c[h]=d[h])}return c},str_trans:function(a,b,c){var d=[],g=[],e=false,f=0,h=0,i="",j="",l="",k="",m;if(typeof b==="object"){b=s(b);for(m in b)if(b.hasOwnProperty(m)){d.push(m);g.push(b[m])}b=d;c=g}h=a.length;f=b.length;i=typeof c==="string";j=typeof b==="string";for(d=0;d<h;d++){e=false;if(j){a.charAt(d-1);l=
a.charAt(d);a.charAt(d+1);for(g=0;g<f;g++)if(l==b.charAt(g)){e=true;break}}else for(g=0;g<f;g++)if(a.substr(d,b[g].length)==b[g]){e=true;d=d+b[g].length-1;break}k=e?k+(i?c.charAt(g):c[g]):k+a.charAt(d)}return k}};e.ext("util",r)}})($_);