ThinkPHP/Extend/Tool/TPM/Tpl/Public/js/TPM.js

(开头部分) 25KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

//ThinkTemplate 用js实现了ThinkPHP的模板引擎。
//用户可以在手机客户端中用ThinkPHP的模板引擎。
//@author luofei614<http://weibo.com/luofei614>
//
var ThinkTemplate={
    tags:['Include','Volist','Foreach','For','Empty','Notempty','Present','Notpresent','Compare','If','Elseif','Else','Swith','Case','Default','Var','Range'],
	parse:function(tplContent,vars){
	var render=function(){
		tplContent='<% var key,mod=0;%>'+tplContent;//定义模板中循环需要使用的到变量	
        $.each(ThinkTemplate.tags,function(k,v){
            tplContent=ThinkTemplate['parse'+v](tplContent);
        });  
		return ThinkTemplate.template(tplContent,vars);
		};
		
		return render();
	},
	//解析 <% %> 标签
	template:function(text,vars){
		var source="";
		var index=0;
		var escapes = {
			"'":      "'",
			'\\':     '\\',
			'\r':     'r',
			'\n':     'n',
			'\t':     't',
			'\u2028': 'u2028',
			'\u2029': 'u2029'
		};
		var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g;
		text.replace(/<%=([\s\S]+?)%>|<%([\s\S]+?)%>/g,function(match,interpolate,evaluate,offset){
			var p=text.slice(index,offset).replace(escaper,function(match){
				return '\\'+escapes[match];
			});
			if(''!=$.trim(p)){
				source+="__p+='"+p+"';\n";	
			}

			if(evaluate){
				source+=evaluate+"\n";
			}	
			if(interpolate){
				source+="if( 'undefined'!=typeof("+interpolate+") && (__t=(" + interpolate + "))!=null) __p+=__t;\n";
			}
			index=offset+match.length;
			return match;
		});
		source+="__p+='"+text.slice(index).replace(escaper,function(match){ return '\\'+escapes[match]; })+"';\n";//拼接剩余的字符串

		source = "var __t,__p='',__j=Array.prototype.join," +
			"print=function(){__p+=__j.call(arguments,'');};\n" +
			"with(obj){\n"+
			source + 
			"}\n"+
			"return __p;\n";
		try {
			render = new Function('obj', source);

		} catch (e) {
后面还有 775 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。