FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript-Templates/tmpl.js at master · lrc/JavaScript-Templates · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
lrc
/
JavaScript-Templates
Public
forked from
blueimp/JavaScript-Templates
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript-Templates
/
tmpl.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
86 lines (84 loc) · 2.51 KB
Breadcrumbs
JavaScript-Templates
/
tmpl.js
Copy path
File metadata and controls
86 lines (84 loc) · 2.51 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
* JavaScript Templates 2.1.0
* https://github.com/blueimp/JavaScript-Templates
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*
* Inspired by John Resig's JavaScript Micro-Templating:
* http://ejohn.org/blog/javascript-micro-templating/
*/
/*jslint evil: true, regexp: true */
/*global document, define */
(
function
(
$
)
{
"use strict"
;
var
tmpl
=
function
(
str
,
data
)
{
var
f
=
!
/
[
^
\w
\-
\.
:
]
/
.
test
(
str
)
?
tmpl
.
cache
[
str
]
=
tmpl
.
cache
[
str
]
||
tmpl
(
tmpl
.
load
(
str
)
)
:
new
Function
(
tmpl
.
arg
+
',tmpl'
,
"var _e=tmpl.encode"
+
tmpl
.
helper
+
",_s='"
+
str
.
replace
(
tmpl
.
regexp
,
tmpl
.
func
)
+
"';return _s;"
)
;
return
data
?
f
(
data
,
tmpl
)
:
function
(
data
)
{
return
f
(
data
,
tmpl
)
;
}
;
}
;
tmpl
.
cache
=
{
}
;
tmpl
.
load
=
function
(
id
)
{
return
document
.
getElementById
(
id
)
.
innerHTML
;
}
;
tmpl
.
regexp
=
/
(
[
\s
'
\\
]
)
(?
!
[
^
%
]
*
%
\}
)
|
(?:
\{
%
(
=
|
#
)
(
[
\s
\S
]
+
?
)
%
\}
)
|
(
\{
%
)
|
(
%
\}
)
/
g
;
tmpl
.
func
=
function
(
s
,
p1
,
p2
,
p3
,
p4
,
p5
)
{
if
(
p1
)
{
// whitespace, quote and backspace in interpolation context
return
{
"\n"
:
"\\n"
,
"\r"
:
"\\r"
,
"\t"
:
"\\t"
,
" "
:
" "
}
[
s
]
||
"\\"
+
s
;
}
if
(
p2
)
{
// interpolation: {%=prop%}, or unescaped: {%#prop%}
if
(
p2
===
"="
)
{
return
"'+_e("
+
p3
+
")+'"
;
}
return
"'+("
+
p3
+
"||'')+'"
;
}
if
(
p4
)
{
// evaluation start tag: {%
return
"';"
;
}
if
(
p5
)
{
// evaluation
end tag: %
}
return
"_s+='"
;
}
}
;
tmpl
.
encReg
=
/
[
<
>
&
"
'
\x00
]
/
g
;
tmpl
.
encMap
=
{
"<"
:
"<"
,
">"
:
">"
,
"&"
:
"&"
,
"\""
:
"""
,
"'"
:
"'"
}
;
tmpl
.
encode
=
function
(
s
)
{
return
String
(
s
||
""
)
.
replace
(
tmpl
.
encReg
,
function
(
c
)
{
return
tmpl
.
encMap
[
c
]
||
""
;
}
)
;
}
;
tmpl
.
arg
=
"o"
;
tmpl
.
helper
=
",print=function(s,e){_s+=e&&(s||'')||_e(s);}"
+
",include=function(s,d){_s+=tmpl(s,d);}"
;
if
(
typeof
define
===
"function"
&&
define
.
amd
)
{
define
(
function
(
)
{
return
tmpl
;
}
)
;
}
else
{
$
.
tmpl
=
tmpl
;
}
}
(
this
)
)
;
Back
|
FazBrowse Home
|
New Git URL