-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathteepee.min.js
2 lines (2 loc) · 3.01 KB
/
teepee.min.js
1
2
// Teepee v1.2.2 MIT/GPL2 @rezitech
(function(a){function g(){function i(a,d){var e=arguments.callee,f="",g=-1,h;while(b(h=a[++g])){if(c(h)){var i=h.condition[0],j=h.condition[1],l=(new Function("return this."+j.split("||([^'\"[{])").join("||this.$1").split("&&").join("&&this."))).apply(d),m,n;if(i===k.printer){f+=String(l||"")}else if(i===k.iffer&&b(l)&&l!=false)f+=e(h.children,d);else if(i===k.notter&&(!b(l)||l==false))f+=e(h.children,d);else if(i===k.looper&&b(l)){m=-1;n={};while(b(n[j]=l[++m]))f+=e(h.children,n)}}else f+=h}return f}function h(a){var c=arguments.callee,d=[],f=[],g=-1,h;while(b(h=a[++g])){if(h.constructor===Array.prototype.constructor){if((new RegExp("^("+e(k.iffer)+"|"+e(k.notter)+"|"+e(k.looper)+")$")).test(h[0])){var i={},f=c(a.splice(++g,a.length-g));i.condition=h;i.children=f[0];d.push(i);a=a.concat(f[1]);--g}else if((new RegExp("^"+e(k.ender)+"$")).test(h[0])){f=a.splice(++g,a.length-1);--g}else d.push({condition:h})}else d.push(h)}return[d,f]}function g(a){var c=arguments.callee,d=a.match(new RegExp("^([\\W\\w]*?)"+e(k.opener)+"([\\W\\w]*?)"+e(k.closer)+"([\\W\\w]*?)$")),f=[];if(b(d))f=f.concat([d[1]],[[d[2].substr(0,1),d[2].substr(1)]],c(d[3]));else f.push(a);return f}var j=this,k={closer:"}}",ender:"/",iffer:"?",looper:"#",notter:"!",opener:"{{",printer:"=",tpl:"",use:{}};j.closer=function(a){if(!d(a))return k.closer;k.closer=a;return j};j.ender=function(a){if(!d(a))return k.ender;k.ender=a;return j};j.iffer=function(a){if(!d(a))return k.iffer;k.iffer=a;return j};j.looper=function(a){if(!d(a))return k.looper;k.looper=a;return j};j.notter=function(a){if(!d(a))return k.notter;k.notter=a;return j};j.opener=function(a){if(!d(a))return k.opener;k.opener=a;return j};j.printer=function(a){if(!d(a))return k.printer;k.printer=a;return j};j.tpl=function(a){if(!d(a))return k.tpl;k.tpl=a;return j};j.tplById=function(b,c){b=a.getElementById(b);if(b.src)j.tplByUrl(b.src,c);else k.tpl=b.innerHTML;return j};j.tplByUrl=function(a,c){c=!b(c)?true:c;var d=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");d.open("GET",a,c);d.send(null);if(c)d.onreadystatechange=function(){if(d.readyState===4)k.tpl=d.responseText};else k.tpl=d.responseText;return j};j.use=function(a){if(!c(a))return k.use;k.use=a;return j};j.andUse=function(a){if(c(a))k.use=f(k.use,a);return j};j.render=function(a,b){return i(h(g(a||k.tpl))[0],b||k.use)};j.write=function(b,c){a.write(j.render(b,c));return j};j.css=function(b,c){var d=a.createElement("div");d.innerHTML="<style>"+j.render(b,c)+"</style>";a.documentElement.firstChild.appendChild(d.firstChild);return j};return j}function f(){var a={},b=arguments,d=b.length,e=-1,f;while(++e<d)if(c(b[e]))for(f in b[e])a[f]=c(a[f])&&c(b[e][f])?b.callee(a[f],b[e][f]):b[e][f];return a}function e(a){return a.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}function d(a){return b(a)&&a.constructor===String.prototype.constructor}function c(a){return b(a)&&a.constructor===Object.prototype.constructor}function b(a){return a!==undefined&&a!==null}window.teepee=function(){return new g}})(document)