forked from BorisMoore/jsrender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsrender.min.js
6 lines (6 loc) · 13.6 KB
/
jsrender.min.js
1
2
3
4
5
6
/*! JsRender v1.0.0-beta: http://github.com/BorisMoore/jsrender and http://jsviews.com/jsviews
informal pre V1.0 commit counter: 53 */
(function(n,t,i){"use strict";function kt(n){return n}function ki(n){return n}function dt(n){e._dbgMode=n;yt=n?"Unavailable (nested view): use #getIndex()":"";d("dbg",oi.dbg=lt.dbg=n?ki:kt)}function gt(n){return{getTgt:n,map:function(t){var i=this,r;i.src!==t&&(i.src&&i.unmap(),typeof t=="object"&&(r=n.apply(i,arguments),i.src=t,i.tgt=r))}}}function ft(n,t){t&&t.onError&&t.onError(n)===!1||(this.name=(u.link?"JsViews":"JsRender")+" Error",this.message=n||this.name)}function f(n,t){var i;n=n||{};for(i in t)n[i]=t[i];return n}function ni(n,t,i){return(!h.rTag||n)&&(p=n?n.charAt(0):p,w=n?n.charAt(1):w,o=t?t.charAt(0):o,a=t?t.charAt(1):a,g=i||g,n="\\"+p+"(\\"+g+")?\\"+w,t="\\"+o+"\\"+a,y="(?:(?:(\\w+(?=[\\/\\s\\"+o+"]))|(?:(\\w+)?(:)|(>)|!--((?:[^-]|-(?!-))*)--|(\\*)))\\s*((?:[^\\"+o+"]|\\"+o+"(?!\\"+a+"))*?)",h.rTag=y+")",y=new RegExp(n+y+"(\\/)?|(?:\\/(\\w+)))"+t,"g"),vt=new RegExp("<.*>|([^\\\\]|^)[{}]|"+n+".*"+t)),[p,w,o,a,g]}function di(n,t){t||(t=n,n=i);var e,f,o,u,r=this,s=!t||t==="root";if(n){if(u=r.type===t?r:i,!u)if(e=r.views,r._.useKey){for(f in e)if(u=e[f].get(n,t))break}else for(f=0,o=e.length;!u&&f<o;f++)u=e[f].get(n,t)}else if(s)while(r.parent.parent)u=r=r.parent;else while(r&&!u)u=r.type===t?r:i,r=r.parent;return u}function ti(){var n=this.get("item");return n?n.index:i}function ii(){return this.index}function gi(t){var u,e=this,o=e.linkCtx,r=(e.ctx||{})[t];return r===i&&o&&o.ctx&&(r=o.ctx[t]),r===i&&(r=oi[t]),r&&at(r)&&!r._wrp&&(u=function(){return r.apply(!this||this===n?e:this,arguments)},u._wrp=1,f(u,r)),u||r}function nr(n,t,u){var f,e,h,o=+u===u&&u,s=t.linkCtx;if(o&&(u=(o=t.tmpl.bnds[o-1])(t.data,t,r)),e=u.args[0],n||o){f=s&&s.tag||{_:{inline:!s,bnd:o},tagName:n+":",flow:!0,_is:"tag"};for(h in u.props)rt.test(h)&&(f[h]=u.props[h]);s&&(s.tag=f,f.linkCtx=f.linkCtx||s,u.ctx=l(u.ctx,s.view.ctx));f.tagCtx=u;u.view=t;f.ctx=u.ctx||{};delete u.ctx;t._.tag=f;e=et(f,f.convert||n!=="true"&&n)[0];e=e!=i?e:"";e=o&&t._.onRender?t._.onRender(e,t,o):e;t._.tag=i}return e}function et(n,t){var r=n.tagCtx,u=r.view,i=r.args;return t=t&&(""+t===t?u.getRsc("converters",t)||v("Unknown converter: '"+t+"'"):t),i=!i.length&&!r.index&&n.autoBind?[u.data]:t?i.slice():i,t&&(t.depends&&(n.depends=h.getDeps(n.depends,n,t.depends,t)),i[0]=t.apply(n,i)),i}function tr(n,t){for(var f,e,u=this;f===i&&u;)e=u.tmpl[n],f=e&&e[t],u=u.parent;return f||r[n][t]}function ir(n,t,u,e,o){var ct,h,wt,at,ut,a,vt,w,c,ft,tt,bt,k,yt,pt,nt,y,st,d,kt,g="",ht=+e===e&&e,p=t.linkCtx||0,it=t.ctx,dt=u||t.tmpl;for(n._is==="tag"&&(h=n,n=h.tagName),h=h||p.tag,ht&&(e=(bt=dt.bnds[ht-1])(t.data,t,r)),vt=e.length,a=0;a<vt;a++){if(c=e[a],d=c.props,tt=c.tmpl,tt=c.content=tt&&dt.tmpls[tt-1],u=c.props.tmpl,a||u&&h||(k=t.getRsc("tags",n)||v("Unknown tag: {{"+n+"}}")),u=u||(h?h:k).template||tt,u=""+u===u?t.getRsc("templates",u)||s(u):u,f(c,{tmpl:u,render:ot,index:a,view:t,ctx:l(c.ctx,it)}),!h){k._ctr?(h=new k._ctr,yt=!!h.init,h.attr=h.attr||k.attr||i):h={render:k.render};h._={inline:!p};p&&(p.attr=h.attr=p.attr||h.attr,p.tag=h,h.linkCtx=p);(h._.bnd=bt||p.fn)?h._.arrVws={}:h.dataBoundOnly&&v("{^{"+n+"}} tag must be data-bound");h.tagName=n;h.parent=ut=it&&it.tag;h._is="tag";h._def=k;for(st in d=c.props)rt.test(st)&&(h[st]=d[st])}c.tag=h;h.map&&h.tagCtxs&&(c.map=h.tagCtxs[a].map);h.flow||(ft=c.ctx=c.ctx||{},wt=h.parents=ft.parentTags=it&&l(ft.parentTags,it.parentTags)||{},ut&&(wt[ut.tagName]=ut),ft.tag=h)}for(h.tagCtxs=e,t._.tag=h,h.rendering={},a=0;a<vt;a++)c=h.tagCtx=e[a],d=c.props,y=et(h,h.convert),(pt=d.map||h).map&&(y.length||d.map)&&(nt=c.map=f(c.map||{unmap:pt.unmap},d),nt.src!==y[0]&&(nt.src&&nt.unmap(),pt.map.apply(nt,y)),y=[nt.tgt]),h.ctx=c.ctx,!a&&yt&&(kt=h.template,h.init(c,p,h.ctx),yt=i,h.template!==kt&&(h._.tmpl=h.template)),w=i,ct=h.render,(ct=h.render)&&(w=ct.apply(h,y)),y=y.length?y:[t],w=w!==i?w:c.render(y[0],!0)||(o?i:""),g=g?g+(w||""):w;return delete h.rendering,h.tagCtx=h.tagCtxs[0],h.ctx=h.tagCtx.ctx,h._.inline&&(at=h.attr)&&at!==b&&(g=at==="text"?lt.html(g):""),ht&&t._.onRender?t._.onRender(g,t,ht):g}function nt(n,t,i,r,u,f,e,o){var a,h,c,v=t==="array",l={key:0,useKey:v?0:1,id:""+bi++,onRender:o,bnds:{}},s={data:r,tmpl:u,content:e,views:v?[]:{},parent:i,type:t,get:di,getIndex:ii,getRsc:tr,hlp:gi,_:l,_is:"view"};return i?(a=i.views,h=i._,h.useKey?(a[l.key="_"+h.useKey++]=s,s.index=yt,s.getIndex=ti,c=h.tag,l.bnd=v&&(!c||!!c._.bnd&&c)):a.splice(l.key=s.index=f,0,s),s.ctx=n||i.ctx):s.ctx=n,s}function rr(n){var t,i,r,u,f;for(t in k)if(u=k[t],(f=u.compile)&&(i=n[t+"s"]))for(r in i)i[r]=f(r,i[r],n,t,u)}function ur(n,t,i){var u,r;return at(t)?t={depends:t.depends,render:t}:((r=t.template)&&(t.template=""+r===r?s[r]||s(r):r),t.init!==!1&&(u=t._ctr=function(){},(u.prototype=t).constructor=u)),i&&(t._parentTmpl=i),t}function ri(r,u,f,e,o,h){function v(i){if(""+i===i||i.nodeType>0){try{a=i.nodeType>0?i:!vt.test(i)&&t&&t(n.document).find(i)[0]}catch(u){}return a&&(i=a.getAttribute(bt),r=r||i,i=s[i],i||(r=r||"_"+wi++,a.setAttribute(bt,r),i=s[r]=ri(r,a.innerHTML,f,e,o,h)),a=null),i}}var c,a;return u=u||"",c=v(u),h=h||(u.markup?u:{}),h.tmplName=r,f&&(h._parentTmpl=f),!c&&u.markup&&(c=v(u.markup))&&c.fn&&(c.debug!==u.debug||c.allowCode!==u.allowCode)&&(c=c.markup),c!==i?(r&&!f&&(ut[r]=function(){return u.render.apply(u,arguments)}),c.fn||u.fn?c.fn&&(u=r&&r!==c.tmplName?l(h,c):c):(u=ui(c,h),st(c.replace(li,"\\$&"),u)),rr(h),u):void 0}function ui(n,t){var i,o=e.wrapMap||{},r=f({markup:n,tmpls:[],links:{},tags:{},bnds:[],_is:"template",render:ot},t);return t.htmlTag||(i=yi.exec(n),r.htmlTag=i?i[1].toLowerCase():""),i=o[r.htmlTag],i&&i!==o.div&&(r.markup=u.trim(r.markup)),r}function fr(n,t){function u(e,o,s){var a,c,v,l;if(e&&""+e!==e&&!e.nodeType&&!e.markup){for(v in e)u(v,e[v],o);return r}return o===i&&(o=e,e=i),e&&""+e!==e&&(s=o,o=e,e=i),l=s?s[f]=s[f]||{}:u,c=t.compile,(a=h.onBeforeStoreItem)&&(c=a(l,e,o,c)||c),e?o===null?delete l[e]:l[e]=c?o=c(e,o,s,n,t):o:o=c(i,o),c&&o&&(o._is=n),(a=h.onStoreItem)&&a(l,e,o,c),o}var f=n+"s";r[f]=u;k[n]=t}function ot(n,t,f,e,o,h){var w,et,tt,y,it,rt,ut,k,p,ft,d,ot,c,a=this,st=!a.attr||a.attr===b,g="";if(!!t===t&&(f=t,t=i),o===!0&&(ut=!0,o=0),a.tag?(k=a,a=a.tag,ft=a._,ot=a.tagName,c=ft.tmpl||k.tmpl,t=l(t,a.ctx),p=k.content,k.props.link===!1&&(t=t||{},t.link=!1),e=e||k.view,n=arguments.length?n:e):c=a.jquery&&(a[0]||v('Unknown template: "'+a.selector+'"'))||a,c&&(!e&&n&&n._is==="view"&&(e=n),e&&(p=p||e.content,h=h||e._.onRender,n===e&&(n=e.data),t=l(t,e.ctx)),e&&e.data!==i||((t=t||{}).root=n),c.fn||(c=s[c]||s(c)),c)){if(h=(t&&t.link)!==!1&&st&&h,d=h,h===!0&&(d=i,h=e._.onRender),t=c.helpers?l(c.helpers,t):t,u.isArray(n)&&!f)for(y=ut?e:o!==i&&e||nt(t,"array",e,n,c,o,p,h),w=0,et=n.length;w<et;w++)tt=n[w],it=nt(t,"item",y,tt,c,(o||0)+w,p,h),rt=c.fn(tt,it,r),g+=y._.onRender?y._.onRender(rt,it):rt;else y=ut?e:nt(t,ot||"data",e,n,c,o,p,h),ft&&!a.flow&&(y.tag=a),g+=c.fn(n,y,r);return d?d(g,y):g}return""}function v(n){throw new h.Err(n);}function c(n){v("Syntax error\n"+n)}function st(n,t,i,r){function v(t){t-=f;t&&s.push(n.substr(f,t).replace(it,"\\n"))}function h(t){t&&c('Unmatched or missing tag: "{{/'+t+'}}" in template:\n'+n)}function p(e,y,p,k,d,g,nt,tt,ut,ft,et,ot){g&&(d=":",k=b);ft=ft||i;var pt,lt,at=y&&[],ct="",st="",vt="",yt=!ft&&!d&&!nt;p=p||(ut=ut||"#data",d);v(ot);f=ot+e.length;tt?w&&s.push(["*","\n"+ut.replace(ci,"$1")+"\n"]):p?(p==="else"&&(vi.test(ut)&&c('for "{{else if expr}}" use "{{else expr}}"'),at=u[6],u[7]=n.substring(u[7],ot),u=o.pop(),s=u[3],yt=!0),ut&&(ut=ut.replace(it," "),ct=ht(ut,at,t).replace(ai,function(n,t,i){return t?vt+=i+",":st+=i+",",a=a||rt.test(i.split(":")[0]),""})),st=st.slice(0,-1),ct=ct.slice(0,-1),pt=st&&st.indexOf("noerror:true")+1&&st||"",l=[p,k||!!r||a||"",ct,yt&&[],'\n\tparams:"'+ut+'",\n\tprops:{'+st+"}"+(vt?",ctx:{"+vt.slice(0,-1)+"}":""),pt,at||0],s.push(l),yt&&(o.push(u),u=l,u[7]=f)):et&&(lt=u[0],h(et!==lt&<!=="else"&&et),u[7]=n.substring(u[7],ot),u=o.pop());h(!u&&et);s=u[3]}var l,a,w=t&&t.allowCode,e=[],f=0,o=[],s=e,u=[,,,e];return h(o[0]&&o[0][3].pop()[0]),n.replace(y,p),v(n.length),(f=e[e.length-1])&&h(""+f!==f&&+f[7]===f[7]&&f[0]),fi(e,i?n:t,i)}function fi(n,i,r){var a,f,o,l,v,p,ht,ct,lt,at,et,w,s,ot,y,tt,k,rt,vt,d,yt,pt,st,ut,g,h=0,u="",nt="",ft={},wt=n.length;for(""+i===i?(y=r?'data-link="'+i.replace(it," ").slice(1,-1)+'"':i,i=0):(y=i.tmplName||"unnamed",i.allowCode&&(ft.allowCode=!0),i.debug&&(ft.debug=!0),w=i.bnds,ot=i.tmpls),a=0;a<wt;a++)if(f=n[a],""+f===f)u+='\nret+="'+f+'";';else if(o=f[0],o==="*")u+=""+f[1];else{if(l=f[1],v=f[2],rt=f[3],p=f[4],nt=f[5],vt=f[7],(pt=o==="else")||(h=0,w&&(s=f[6])&&(h=w.push(s))),(st=o===":")?(l&&(o=l===b?">":l+o),nt&&(ut="prm"+a,nt="try{var "+ut+"=["+v+"][0];}catch(e){"+ut+'="";}\n',v=ut)):(rt&&(tt=ui(vt,ft),tt.tmplName=y+"/"+o,fi(rt,tt),ot.push(tt)),pt||(k=o,yt=u,u=""),d=n[a+1],d=d&&d[0]==="else"),p+=",\n\targs:["+v+"]}",st&&(s||l&&l!==b)){if(g=new Function("data,view,j,u"," // "+y+" "+h+" "+o+"\n"+nt+"return {"+p+";"),g.paths=s,g._ctxs=o,r)return g;et=1}if(u+=st?"\n"+(s?"":nt)+(r?"return ":"ret+=")+(et?(et=0,at=!0,'c("'+l+'",view,'+(s?(w[h-1]=g,h):"{"+p)+");"):o===">"?(ct=!0,"h("+v+");"):(lt=!0,"(v="+v+")!="+(r?"=":"")+'u?v:"";')):(ht=!0,"{view:view,tmpl:"+(rt?ot.length:"0")+","+p+","),k&&!d){if(u="["+u.slice(0,-1)+"]",(r||s)&&(u=new Function("data,view,j,u"," // "+y+" "+h+" "+k+"\nreturn "+u+";"),s&&((w[h-1]=u).paths=s),u._ctxs=o,r))return u;u=yt+'\nret+=t("'+k+'",view,this,'+(h||u)+");";s=0;k=0}}u="// "+y+"\nvar j=j||"+(t?"jQuery.":"js")+"views"+(lt?",v":"")+(ht?",t=j._tag":"")+(at?",c=j._cnvt":"")+(ct?",h=j.converters.html":"")+(r?";\n":',ret="";\n')+(e.tryCatch?"try{\n":"")+(ft.debug?"debugger;":"")+u+(r?"\n":"\nreturn ret;\n")+(e.tryCatch?"\n}catch(e){return j._err(e);}":"");try{u=new Function("data,view,j,u",u)}catch(bt){c("Compiled template code:\n\n"+u,bt)}return i&&(i.fn=u),u}function ht(n,t,i){function b(b,k,d,g,nt,tt,it,rt,ut,ft,et,ot,ct,lt,at,vt,yt,pt,wt,bt){function dt(n,i,r,f,e,o,c,l){if(r&&(t&&(u==="linkTo"&&(s=t._jsvto=t._jsvto||[],s.push(nt)),(!u||h)&&t.push(nt.slice(i.length))),r!==".")){var a=(f?'view.hlp("'+f+'")':e?"view":"data")+(l?(o?"."+o:f?"":e?"":"."+r)+(c||""):(l=f?"":e?o||"":r,""));return a=a+(l?"."+l:""),i+(a.slice(0,9)==="view.data"?a.slice(5):a)}return n}var kt;if(tt=tt||"",d=d||k||ot,nt=nt||ut,ft=ft||yt||"",!it||e||f)return t&&vt&&!e&&!f&&(!u||h||s)&&(kt=v[r],bt.length-1>wt-kt&&(kt=bt.slice(kt,wt+1),vt=w+":"+kt+o,vt=y[vt]=y[vt]||st(p+vt+a,i,!0),vt.paths||ht(kt,vt.paths=[],i),(s||t).push({_jsvOb:vt}))),e?(e=!ct,e?b:'"'):f?(f=!lt,f?b:'"'):(d?(r++,v[r]=wt++,d):"")+(pt?r?"":u?(u=h=s=!1,"\b"):",":rt?(r&&c(n),u=nt,h=g,"\b"+nt+":"):nt?nt.split("^").join(".").replace(si,dt)+(ft?(l[++r]=!0,nt.charAt(0)!=="."&&(v[r]=wt),ft):tt):tt?tt:at?(l[r--]=!1,at)+(ft?(l[++r]=!0,ft):""):et?(l[r]||c(n),","):k?"":(e=ct,f=lt,'"'));c(n)}var u,s,h,y=i.links,l={},v={0:-1},r=0,f=!1,e=!1;return(n+" ").replace(/\)\^/g,").").replace(hi,b)}function l(n,t){return n&&n!==t?t?f(f({},t),n):n:t&&f({},t)}function ei(n){return wt[n]||(wt[n]="&#"+n.charCodeAt(0)+";")}function er(n){var i,t,r=[];if(typeof n=="object")for(i in n)t=n[i],t&&t.toJSON&&!t.toJSON()||at(t)||r.push({key:i,prop:n[i]});return r}if((!t||!t.views)&&!n.jsviews){var u,tt,y,vt,yt,p="{",w="{",o="}",a="}",g="^",si=/^(!*?)(?:null|true|false|\d[\d.]*|([\w$]+|\.|~([\w$]+)|#(view|([\w$]+))?)([\w$.^]*?)(?:[.[^]([\w$]+)\]?)?)$/g,hi=/(\()(?=\s*\()|(?:([([])\s*)?(?:(\^?)(!*?[#~]?[\w$.^]+)?\s*((\+\+|--)|\+|-|&&|\|\||===|!==|==|!=|<=|>=|[<>%*:?\/]|(=))\s*|(!*?[#~]?[\w$.^]+)([([])?)|(,\s*)|(\(?)\\?(?:(')|("))|(?:\s*(([)\]])(?=\s*\.|\s*\^|\s*$)|[)\]])([([]?))|(\s+)/g,it=/[ \t]*(\r\n|\n|\r)/g,ci=/\\(['"])/g,li=/['"\\]/g,ai=/\x08(~)?([^\x08]+)\x08/g,vi=/^if\s/,yi=/<(\w+)[>\s]/,pt=/[\x00`><"'&]/g,rt=/^on[A-Z]|^convert(Back)?$/,pi=pt,wi=0,bi=0,wt={"&":"&","<":"<",">":">","\x00":"�","'":"'",'"':""","`":"`"},b="html",bt="data-jsv-tmpl",ut={},k={template:{compile:ri},tag:{compile:ur},helper:{},converter:{}},r={jsviews:"v1.0.0-beta",render:ut,settings:function(n){f(e,n);dt(e._dbgMode);e.jsv&&e.jsv()},sub:{View:nt,Err:ft,tmplFn:st,cvt:et,parse:ht,extend:f,err:v,syntaxErr:c,isFn:function(n){return typeof n=="function"},DataMap:gt},_cnvt:nr,_tag:ir,_err:function(n){return e._dbgMode?"Error: "+(n.message||n)+". ":""}};(ft.prototype=new Error).constructor=ft;ti.depends=function(){return[this.get("item"),"index"]};ii.depends=function(){return["index"]};for(tt in k)fr(tt,k[tt]);var ct,s=r.templates,lt=r.converters,oi=r.helpers,d=r.tags,h=r.sub,at=h.isFn,e=r.settings;t?(u=t,u.fn.render=ot,(ct=u.observable)&&(f(h,ct.sub),delete ct.sub)):(u=n.jsviews={},u.isArray=Array&&Array.isArray||function(n){return Object.prototype.toString.call(n)==="[object Array]"});u.render=ut;u.views=r;u.templates=s=r.templates;e({debugMode:dt,delimiters:ni,_dbgMode:!0,tryCatch:!0});d({"else":function(){},"if":{render:function(n){var t=this;return t.rendering.done||!n&&(arguments.length||!t.tagCtx.index)?"":(t.rendering.done=!0,t.selected=t.tagCtx.index,t.tagCtx.render(t.tagCtx.view,!0))},onUpdate:function(n,t,i){for(var r,f,u=0;(r=this.tagCtxs[u])&&r.args.length;u++)if(r=r.args[0],f=!r!=!i[u].args[0],!this.convert&&!!r||f)return f;return!1},flow:!0},"for":{render:function(n){var f,t=this,r=t.tagCtx,e="",o=0;return t.rendering.done||((f=!arguments.length)&&(n=r.view.data),n!==i&&(e+=r.render(n,f),o+=u.isArray(n)?n.length:1),(t.rendering.done=o)&&(t.selected=r.index)),e},flow:!0,autoBind:!0},include:{flow:!0,autoBind:!0},"*":{render:kt,flow:!0}});d({props:f(f({},d["for"]),gt(er))});d.props.autoBind=!0;lt({html:function(n){return n!=i?String(n).replace(pi,ei):""},attr:function(n){return n!=i?String(n).replace(pt,ei):n===null?n:""},url:function(n){return n!=i?encodeURI(String(n)):n===null?n:""}});ni()}})(this,this.jQuery);
/*
//# sourceMappingURL=jsrender.min.js.map
*/