kis-js/kis-min.js

25 lines
11 KiB
JavaScript
Raw Normal View History

2011-11-15 12:03:12 -05:00
(function(){if(typeof document.querySelector!=="undefined"){var g,h,d,c;g=function(a){c=typeof a==="undefined"?typeof g.el!=="undefined"?g.el:document.documentElement:typeof a!=="object"?h(a):a;g.prototype.el=c;var a=d(g),b;for(b in a)if(typeof a[b]==="object")a[b].el=c;a.el=c;return a};h=function(a,b){var c;if(typeof a!="string"||typeof a==="undefined")return a;c=b!=null&&b.nodeType===1?b:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);else c=c.querySelectorAll(a);
return c.length===1?c[0]:c};d=function(a){var b;if(typeof a!=="undefined"){if(typeof Object.create!=="undefined")return Object.create(a);b=typeof a;if(!(b!=="object"&&b!=="function"))return b=function(){},b.prototype=a,new b}};g.ext=function(a,b){b.el=c;g[a]=b};g.ext("each",function(a){if(typeof c.length!=="undefined"&&c!==window){var b=c.length;if(b!==0)for(var e,f=0;f<b;f++)e=c.item(f)?c.item(f):c[f],a.call(e,e)}else a.call(c,c)});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.$=h}})();
(function(){if(typeof window.console==="undefined")window.console={log:function(){}};if(typeof String.prototype.trim==="undefined")String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")};typeof document!=="undefined"&&!("classList"in document.createElement("a"))&&function(g){var g=(g.HTMLElement||g.Element).prototype,h=Object,d=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},c=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},b=function(b,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 c.call(b,e)},e=function(a){for(var b=d.call(a.className),b=b?b.split(/\s+/):[],c=0,e=b.length;c<e;c++)this.push(b[c]);this._updateClassName=function(){a.className=this.toString()}},f=e.prototype=[],
k=function(){return new e(this)};a.prototype=Error.prototype;f.item=function(a){return this[a]||null};f.contains=function(a){a+="";return b(this,a)!==-1};f.add=function(a){a+="";b(this,a)===-1&&(this.push(a),this._updateClassName())};f.remove=function(a){a+="";a=b(this,a);a!==-1&&(this.splice(a,1),this._updateClassName())};f.toggle=function(a){a+="";b(this,a)===-1?this.add(a):this.remove(a)};f.toString=function(){return this.join(" ")};if(h.defineProperty){f={get:k,enumerable:true,configurable:true};
try{h.defineProperty(g,"classList",f)}catch(i){if(i.number===-2146823252)f.enumerable=false,h.defineProperty(g,"classList",f)}}else h.prototype.__defineGetter__&&g.__defineGetter__("classList",k)}(self);if(typeof Event.preventDefault==="undefined"&&typeof window.event!=="undefined")Event.prototype.preventDefault=function(){window.event.stop()},Event.prototype.stopPropagation=function(){window.event.returnValue=false}})();
(function(){function g(c,a,b){var e,f;if(typeof c.hasAttribute!=="undefined")c.hasAttribute(a)&&(e=c.getAttribute(a)),f=true;else if(typeof c[a]!=="undefined")e=c[a],f=false;else if(a==="class"&&typeof c.className!=="undefined")a="className",e=c.className,f=false;if(typeof e==="undefined"&&(typeof b==="undefined"||b===null))console.log(b),console.log(c),console.log("Element does not have the selected attribute");else{if(typeof b==="undefined")return e;typeof b!=="undefined"&&b!==null?f===true?c.setAttribute(a,
b):c[a]=b:b===null&&(f===true?c.removeAttribute(a):delete c[a]);return typeof b!=="undefined"?b:e}}function h(c){return c.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function d(c,a,b){var e,a=h(a);e={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if(typeof b==="undefined"&&c.style[a]!=="undefined")return c.style[a];else if(typeof b==="undefined"&&c.style[e[a]]!=="undefined")return c.style[e[a]];typeof c.style[a]!=="undefined"?c.style[a]=b:c.style[e[a]]?
c.style[e[a]]=b:console.log("Property "+a+" nor an equivalent seems to exist")}$_.ext("dom",{addClass:function(c){$_.each(function(a){a.classList.add(c)})},removeClass:function(c){$_.each(function(a){a.classList.remove(c)})},hide:function(){this.css("display","none")},show:function(c){typeof c==="undefined"&&(c="block");this.css("display",c)},attr:function(c,a){var b=this.el;if(b.length>1&&typeof a==="undefined")console.log(b),console.log("Must be a singular element");else if(b.length>1&&typeof a!==
"undefined")$_.each(function(b){return g(b,c,a)});else return g(b,c,a)},text:function(c){var a,b,e;e=this.el;b=typeof e.innerText!=="undefined"?"innerText":typeof e.textContent!=="undefined"?"textContent":"innerHTML";a=e[b];return typeof c!=="undefined"?e[b]=c:a},css:function(c,a){if(typeof a==="undefined")return d(this.el,c);$_.each(function(b){d(b,c,a)})},html:function(c){if(typeof c!=="undefined")this.el.innerHTML=c;return this.el.innerHTML}})})();
(function(){if(!(typeof localStorage==="undefined"||typeof JSON==="undefined")){var g=localStorage,h=sessionStorage;$_.ext("store",{get:function(d,c){var a=c?h.getItem(d):g.getItem(d);return JSON.parse(a)},set:function(d,c,a){c=JSON.stringify(c);a?h.setItem(d,c):g.setItem(d,c)},remove:function(d,c){c?h.removeItem(d):g.removeItem(d)},getAll:function(d){var c,a={},b,e;e=d?g:h;c=e.length;for(d=0;d<c;d++)b=e.key(d),a[b]=e.getItem(b);return a},clear:function(d){d?h.clear():g.clear()}})}})();
(function(){if(typeof window.XMLHttpRequest!=="undefined"){var g={_do:function(g,d,c,a){var b=new XMLHttpRequest;typeof c==="undefined"&&(c=function(){});a=a?"POST":"GET";g+=a==="GET"?"?"+this._serialize(d):"";b.open(a,g);b.onreadystatechange=function(){b.readyState===4&&c(b.responseText)};a==="POST"?(b.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),b.send(this._serialize(d))):b.send(null)},_serialize:function(g){var d,c,a=[];for(d in g)g.hasOwnProperty(d)&&typeof g[d]!=="function"&&
(c=g[d].toString(),d=encodeURIComponent(d),c=encodeURIComponent(c),a.push(d+"="+c));return a.join("&")}};$_.ext("get",function(h,d,c){g._do(h,d,c,false)});$_.ext("post",function(h,d,c){g._do(h,d,c,true)})}})();
(function(){var g=function(d){var c=[],a=0,b={},e,c=h.object_keys(d);c.sort(function(a,b){var c=parseFloat(b),e=parseFloat(a),d=c+""===b,g=e+""===a;if(d&&g)return c>e?1:c<e?-1:0;else if(d&&!g)return 1;else if(!d&&g)return-1;return b>a?1:b<a?-1:0});a=c.length;for(e=0;e<a;e++)b[c[e]]=d[c[e]];return b},h={object_keys:function(d){var c=[],a;for(a in d)d.hasOwnProperty(a)&&c.push(a);return c},object_values:function(d){var c=[],a;for(a in d)c.push(d[a]);return c},array_combine:function(d,c){var a={},b,
e=0;$_.type(d)!=="array"&&(d=this.object_values(d));$_.type(c)!=="array"&&(c=this.object_values(c));b=d.length;if(b!==c.length)return console.log("Object combine requires two arrays of the same size"),false;for(e=0;e<b;e++)a[d[e]]=c[e];return a},object_merge:function(){var d=Array.prototype.slice.call(arguments),c=d.length,a={},b,e=0,f,g,h;b=true;for(f=0;f<c;f++)if($_.type(d[f])!=="array"){b=false;break}if(b){a=[];for(f=0;f<c;f++)a=a.contact(d[f]);return a}for(f=0,h=0;f<c;f++)if(b=d[f],$_.type(b)==
"array")for(g=0,e=b.length;g<e;g++)a[h++]=b[g];else for(g in b)b.hasOwnProperty(g)&&(parseInt(g,10)+""===g?a[h++]=b[g]:a[g]=b[g]);return a},str_trans:function(d,c,a){var b=[],e=[],f=false,h=0,i=0,j="",m="",l="",o="",n;if(typeof c==="object"){c=g(c);for(n in c)c.hasOwnProperty(n)&&(b.push(n),e.push(c[n]));c=b;a=e}i=d.length;h=c.length;j=typeof a==="string";m=typeof c==="string";for(b=0;b<i;b++){f=false;if(m){d.charAt(b-1);l=d.charAt(b);d.charAt(b+1);for(e=0;e<h;e++)if(l==c.charAt(e)){f=true;break}}else for(e=
0;e<h;e++)if(d.substr(b,c[e].length)==c[e]){f=true;b=b+c[e].length-1;break}o+=f?j?a.charAt(e):a[e]:d.charAt(b)}return o}};$_.ext("util",h)})();
(function(){var g,h,d,c;typeof document.addEventListener!=="undefined"?(g=function(a,b,c){typeof a.addEventListener!=="undefined"&&a.addEventListener(b,c,false)},h=function(a,b,c){typeof a.removeEventListener!=="undefined"&&a.removeEventListener(b,c,false)}):typeof document.attachEvent!=="undefined"&&(g=function(a,b,c){var e;function d(a){c.apply(a)}typeof a.attachEvent!=="undefined"?(h(b,c),a.attachEvent("on"+b,d),e=a.KIS_0_5_0=a.KIS_0_5_0||{},a=e,a.listeners=a.listeners||{},a.listeners[b]=a.listeners[b]||
[],a.listeners[b].push({callback:c,_listener:d})):console.log("Failed to _attach event:"+b+" on "+a)},h=function(a,b,c){if(typeof a.detachEvent!=="undefined"){var d=a.KIS_0_5_0;if(d&&d.listeners&&d.listeners[b])for(var g=d.listeners[b],h=g.length,j=0;j<h;j++)if(g[j].callback===c){a.detachEvent("on"+b,g[j]._listener);g.splice(j,1);g.length===0&&delete d.listeners[b];break}}});d=function(a,b,c,f){var k,i;if(typeof a==="undefined")return console.log(arguments),console.log(b),false;if(b.match(/^([\w\-]+)$/))f===
true?g(a,b,c):h(a,b,c);else{b=b.split(" ");i=b.length;for(k=0;k<i;k++)d(a,b[k],c,f)}};c=function(a,b,c,f){d(a,c,function(a){var c,d,e,a=a||window.event;d=$_.$(b);for(c in d)e=a.target||a.srcElement,e==d[c]&&(f.call(d[c],a),a.stopPropagation())},true)};$_.ext("event",{add:function(a,b){$_.each(function(c){d(c,a,b,true)})},remove:function(a,b){$_.each(function(c){d(c,a,b,false)})},live:function(a,b,d){c(document.documentElement,a,b,d)},delegate:function(a,b,d){$_.each(function(f){c(f,a,b,d)})}})})();
(function(){if($_.ajax!=="undefined"){var g,h;g={};h={};$_.ext("template",{get:function(d){var c;c=this.el.innerHTML;if(c==="")console.log("Template is empty or cannot be found");else return g[d]=c},parse:function(d,c){var a=g[d],b=[],b=[],e=0,f=e=0,k=0,i="",j={},m="",l,a=String(a).replace(/\s+/gim," "),a=a.replace(/>\s+</gim,"><"),a=a.replace(/>\s+\{/gim,">{"),a=a.replace(/\}\s+</gim,"}<"),b=a.match(/\{([A-Z0-9_\-]+)\}(.*)\{\/\1\}/gim);if(b!=null){e=b.length;for(f=0;f<e;f++){a=a.replace(b[f],"{"+
f+"}");m="";i=String(b[f]).match(/^\{([A-Z0-9_\-]+)\}/i);j=c[i[1]];if(j.length>0){i=j.length;b[f]=b[f].replace(/\{([A-Z0-9_\-]+)\}(.*)\{\/\1\}/gim,"$2");for(k=0;k<i;k++)m+=b[f].replace(/\{([A-Z0-9 _\-]+)\}/gi,function(a,b){return j[k][b]?j[k][b]:""})}a=a.replace("{"+f+"}",m)}}b=a.match(/\{([A-Z0-9_\-]+)\}/gim);if(b!=null){e=b.length;for(f=0;f<e;f++)i=b[f].replace("{",""),i=i.replace("}",""),a=a.replace(b[f],c[i])}f=document.createDocumentFragment();f.appendChild(document.createElement("section"));
f=f.querySelectorAll("section")[0];f.innerHTML=a;f=f.querySelectorAll('[src=""], [href=""]');for(l in f)f[l].parentNode&&f[l].parentNode.removeChild(f[l]);return h[d]=a},apply:function(d,c,a){typeof c==="undefined"&&typeof a==="undefined"?this.el.innerHTML=typeof h[d]!=="undefined"?h[d]:d:$_.get(c,{},function(b){b===""?console.log("Template is empty or can not be found"):(g[d]=b,b=this.parse(d,a),h[d]=b,this.el.innerHTML=b)})}})}})();