-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjstpl.v1.1.201811.html
347 lines (337 loc) · 12.2 KB
/
jstpl.v1.1.201811.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>新闻媒体 - eophy tpltitle:{$title}</title>
<meta name="keywords" content="悠菲中国, eophy, tplkeyword:{$keywords}"/>
<meta name="description" content="悠菲中国, 品味最纯生活" />
<!-- <link type="image/png" rel="icon" href="favicon.png" /> -->
<!--
<link rel="stylesheet" type="text/css" href="./common.css" />
<link rel="stylesheet" type="text/css" href="./layout.css" />
-->
<!--[if lt IE 9]>
<script type="text/javascript" src="js/PIE_IE678.js"></script>
<![endif]-->
</head>
<body>
<div id="container">
<div id="header">
<div class="h_box">
<div class="logo"><a href="index.html">a logo</a></div>
<div class="menu">
<ul>
<li><a href="index.html">首页</a></li>
<li><a href="about_us.html">关于我们</a>
<div class="submenu">
<ul>
<li class="title"><a href="about_us.html">公司介绍</a></li>
<li class="title"><a href="about_us_2.html">品牌介绍</a></li>
<li class="title"><a href="about_us_3.html">品牌VIDEO</a></li>
</ul>
</div>
</li>
<li><a href="products.html">产品中心</a></li>
<li><a href="news.html" class="active">新闻媒体</a></li>
<li><a href="active.html">品牌活动</a></li>
<li><a href="faq.html">营养咨询</a></li>
<li><a href="sale.html">售卖专柜</a></li>
<li><a href="shop.html">网络商城</a></li>
</ul>
</div>
</div>
<div class="clear"></div>
</div>
<!--#header-->
<div id="main">
<div class="homebk"> news logo</div>
<div class="mainbox2">
<div class="homelist">
<div class="box">
<div class="news">
<div class="title">最新新闻</div>
<div class="content">
<ul class="cont" tpldata="newslist::repeat::">
{for (var $k in $newslist)}
<li><a class="btn_show" href="{$newslist[$k]['href']}">> {$newslist[$k]['title']}
<a name="atag" tpldata="atag::updatevalue">{$newslist[$k]['title']}</a>
</a></li>
{/for}
<!--
<li><a class="btn_show" href="#1">> 更高生物利用度(更好更快被吸收)、高活性成分、不刺激肠胃。</a></li>
-->
</ul>
</div>
<div class="pages">
<ul>
<li><a href="javascript:;"> < </a></li>
<li class="active"><a href="#"> 1 </a></li>
<li><a href="#"> 2 </a></li>
<li><a href="#"> 3 </a></li>
<li><a href="#"> 4 </a></li>
<li><a href="#"> ... </a></li>
<li><a href="#"> 6 </a></li>
<li><a href="javascript:;"> > </a></li>
<li><a href="javascript:;" tpldata="newslist_nextpage::updateattribute::href" href="{$newslist_nextpage}"> 下一页 </a></li>
</ul>
</div>
</div>
<div class="news_cnt" style="display:block;" tpldata="newscontentlist::repeat::"> <!-- tpldata="newscontentlist::updatevalue::type=list::format=firstchild" -->
{for(var $k in $newscontentlist)}
<div id="promptBox">
<a href="javascript:;" class="btn_close">X</a>
<div class="title">{$newscontentlist[$k]['title']}</div>
<div class="content"><p>
{$newscontentlist[$k]['content']}
</p>
</div>
<div class="pages">
<ul>
<li><a href="javascript:;"> < </a></li>
<li class="active"><a href="#"> 1 </a></li>
<li><a href="#"> 2 </a></li>
<li><a href="javascript:;"> > </a></li>
<li><a href="javascript:;"> 下一页 </a></li>
</ul>
</div>
</div>
{/for}
<div id="promptBox2">
<a href="javascript:;" class="btn_close">X</a>
<div class="title">虾青素是目前为止最具创新、最具抗氧化能力的抗氧化剂#2</div>
<div class="content">
<p>
BoP S.L. 联合巴塞罗那大学健康医学实验室共同研发近百种天然健康营养品,我 们的研发人员有着二十多年营养与药剂开发经验,产品品牌在欧洲拥有极高的知 名度和美誉度。为了满足消费者“选择最佳天然营养品的健康需求”。</p>
</div>
<div class="pages">
<ul>
<li><a href="javascript:;"> < </a></li>
<li><a href="javascript:;"> > </a></li>
</ul>
</div>
</div>
</div>
<div class="news_cnt" style="display:block" tpldata="newslist2::repeat::">
{for(var $k in $newslist)}
<ul>
<li><a href="{$newslist[$k]['href']}">{$newslist[$k]['title']}</a></li>
</ul>
{/for}
</div>
<p>
<br/><br/>
</p>
<div class="news_cnt" tpldata="user.feedback::switch::">
{if ($user['feedback'] == 1)}
<div>Choice one{$user['iname']}</div>
{else if ($user['feedback'] == 2)}
<div tpldata="user.iname::updatevalue::">Choice two{$user['iname']}</div>
{else}
<div>
Choice three{$user['iname']}
</div>
{/if}
</div>
</div>
</div>
<div class="clear"></div>
<!-- mainbox -->
<script>
if(1==1){console.log("1==1."+(new Date()));}
else if(2==2)
{if(3==3){console.log("3==3"+(new Date()));};}
</script>
</div>
<!--#main-->
</div>
<div id="footer">
<script>
if(1==1){console.log("2nd 1==1."+(new Date()));}
else if(2==2)
{if(3==3){console.log("2nd 3==3"+(new Date()));};}
function aFunc(){if (1==1){console.log("this is in aFunc "+(new Date()));}}
</script>
<div class="f_box">
<div class="f_logo">
<a href="http://www.eophy.com/"> base code </a>
</div>
<div class="f_logo">
<a href="javascript:;"> wenxin logo</a>
</div>
<div class="allright"> footer bottom </div>
<div class="f_menu">
<ul>
<li><a href="contact.html">联系我们</a></li>
<li><a href="legal.html">法律声明</a></li>
<li class="last"><a href="http://www.miit.gov.cn/" target="_blank" >京ICP备1204600号 </a> © <span tpldata="copyright_year::updatevalue::">{$copyright_year}</span> Eophy. 保留所有权利.</li>
</ul>
</div>
<div class="allright_2" onclick="javascript:if(1==1){aFunc();}else{if(1==1){aFunc();}}">footer logo</div>
</div>
</div>
</div>
<div id="pagejsondata">
{
"pagetitle": "-吉娃, GWA2 JTMPL-",
"newslist": {
"0": {"title":"虾青素是目前为止最具创新、最具抗氧化能力的抗氧化剂", "href":"#11"},
"1": {"title":"所有产品都含有天然雨生红球藻(富含天然虾青素)", "href":"#10"},
"2": {"title":"更高生物利用度(更好更快被吸收)、高活性成分、不刺激肠胃", "href":"#9"},
"3": {"title":"真是极好的西红柿产品", "href":"#8"}
},
"copyright_year": 2017,
"keywords": "Wadelau, GWA2, gwa2",
"newslist_nextpage": "https://ufqi.com/#newlist_nextpage_value",
"newscontentlist":{
"0":{"title":"虾青素是目前为止最具创新、最具抗氧化能力的抗氧化剂1", "content":"111BoP S.L. 联合巴塞罗那大学健康医学实验室共同研发近百种天然健康营养品,我 们的研发人员有着二十多年营养与药剂开发经验,产品品牌在欧洲拥有极高的知 名度和美誉度。为了满足消费者“选择最佳天然营养品的健康需求”", "pages":3},
"1":{"title":"虾青素是目前为止最具创新、最具抗氧化能力的抗氧化剂2", "content":"222BoP S.L. 联合巴塞罗那大学健康医学实验室共同研发近百种天然健康营养品,我 们的研发人员有着二十多年营养与药剂开发经验,产品品牌在欧洲拥有极高的知 名度和美誉度。为了满足消费者“选择最佳天然营养品的健康需求”", "pages":3},
"2":{"title":"虾青素是目前为止最具创新、最具抗氧化能力的抗氧化剂3", "content":"333BoP S.L. 联合巴塞罗那大学健康医学实验室共同研发近百种天然健康营养品,我 们的研发人员有着二十多年营养与药剂开发经验,产品品牌在欧洲拥有极高的知 名度和美誉度。为了满足消费者“选择最佳天然营养品的健康需求”", "pages":2}
},
"user": {
"feedback": 2,
"iname": {"surname":"Wadelau", "familyname":"Lau"},
"age": "33"
},
"atag": "Xenxin\"s Tag",
"":""
}
</div>
</body>
<script type="text/javascript">
//- JSTPL
/*
* JavaScript-based HTML Template Engine , born with GWA2
* @Xenxin@ufqi.com, Wadelau@hotmail.com
* @Since Nov 11, 2018
*/
"use strict";
(function(window){ //- anonymous func bgn
const parseTag = ':JSTPL:'; const tplVarTag = '$';
//- server response in json
var timeCostBgn = (new Date()).getTime();
var pageJsonElement = document.getElementById('pagejsondata');
var tplData = {};
if(pageJsonElement){
var tplDataStr = pageJsonElement.innerText;
tplData = JSON.parse(tplDataStr);
if(!tplData['copyright_year']){ tplData['copyright_year'] = (new Date()).getYear(); }
//- parse json keys as global variables
for(var $k in tplData){
//console.log("k:"+$k+" v:"+tplData[$k]);
if($k != ''){
var $v = tplData[$k];
$k = tplVarTag + $k;
if(window){ window[$k] = $v; }else{ console.log('window undefined error.'); }
}
}
//- hide raw data
pageJsonElement.style.height = '0px';
pageJsonElement.style.visibility = 'hidden';
}
else{ console.log('pageJsonElement has error.'); }
//- parse all tag blocks
console.log("aft parse copyright_year:"+$copyright_year);
var renderElement = function(window, document, tplHTML){
//var re = /\{([^\}]+)\}/gm, match, tplRaw, tplObject;
var tplRe = /\{((for|if|else|switch|break|case|\$|\/)[^}]*)\}/gm, match, tplRaw, tplObject;
tplObject = document.body || document;
if(!tplHTML){
tplRaw = tplObject.innerHTML;
tplRaw = tplRaw.substring(0, tplRaw.indexOf('<div id="pagejsondata"')); // why this?
}
else{
tplRaw = tplHTML;
}
//- parse original scripts first
tplRaw = tplRaw.replace(/[\n|\r]/g, '');
var scriptRe = /<script[^>]*>(.*?)<\/script>/gm;
var hasScript = false; var tplSegment = [];
var lastpos = 0;
var staticStr, ipos, matchStr, exprStr;
while(match = scriptRe.exec(tplRaw)){
//console.log(match);
ipos = match.index;
staticStr = tplRaw.substring(lastpos, ipos);
if(true){
//staticStr = staticStr.replace(/"/g, '\\"');
tplSegment.push(parseTag + staticStr);
matchStr = match[0];
exprStr = match[1];
tplSegment.push(exprStr);
}
lastpos = ipos + matchStr.length;
hasScript = true;
}
if(hasScript){
staticStr = tplRaw.substring(lastpos);
tplSegment.push(parseTag + staticStr);
}
else{
console.log("no scripts:"+tplRaw);
tplSegment.push(parseTag + tplRaw);
}
//console.log(tplSegment);
var tpl2code = "var tpl2js = [];\n"; var segStr = '';
for(var segi in tplSegment){
segStr = tplSegment[segi];
if(segStr.indexOf(parseTag) == -1){
tpl2code += "\n" + segStr + "\n";
}
else{
segStr = segStr.replace(parseTag, '');
lastpos = 0;
//- parse tpl tags
while(match = tplRe.exec(segStr)){
ipos = match.index;
staticStr = segStr.substring(lastpos, ipos);
//console.log("bfr staticStr:"+staticStr);
if(true){
staticStr = staticStr.replace(/"/g, '\\"');
tpl2code += "\ttpl2js.push(\""+staticStr+"\");\n";
//console.log(match);
matchStr = match[0];
exprStr = match[1];
//console.log("aft exprStr:"+exprStr);
if(exprStr.indexOf('$') == 0){
tpl2code += "\ttpl2js.push("+exprStr+");\n";
}
else if(exprStr.match(/.*({|}).*/gm)){ // exceptions
tpl2code += "\ttpl2js.push(\""+matchStr+"\");\n";
console.log("illegal tpl sentence:["+matchStr+"] for containing { or }. 201812012201.");
}
else{
if(exprStr.match(/(^( )?(if|for|switch|case|break|{|}))(.*)?/g)){
exprStr += '{';
}
else if(exprStr.indexOf('else') == 0){
exprStr = '}\n' + exprStr + '{';
}
else if(exprStr.indexOf('/') == 0){
exprStr = '}';
}
tpl2code += "\n" + exprStr + "\n";
}
}
lastpos = ipos + matchStr.length;
}
//- last static part
staticStr = segStr.substring(lastpos);
staticStr = staticStr.replace(/"/g, '\\"');
tpl2code += "\ttpl2js.push(\""+staticStr+"\");\n";
}
} // end of segment loop
tpl2code += "return tpl2js.join('');\n";
console.log("tpl2code:"+tpl2code);
//- merge data
var tplParse = (function(){ return new Function(tpl2code).apply(window); }).apply();
//console.log("tplParse:"+tplParse);
tplObject.innerHTML = tplParse;
};
//- compile
renderElement(window, document, null);
//-
console.log("tpl parse time \
cost:"+((new Date()).getTime() - timeCostBgn));
})(window); //- anonymous func end
</script>
</html>