|
1 | 1 | /*
|
2 |
| - * JavaScript Templates 2.1.0 |
| 2 | + * JavaScript Templates 2.4.1 |
3 | 3 | * https://github.com/blueimp/JavaScript-Templates
|
4 | 4 | *
|
5 | 5 | * Copyright 2011, Sebastian Tschan
|
|
12 | 12 | * http://ejohn.org/blog/javascript-micro-templating/
|
13 | 13 | */
|
14 | 14 |
|
15 |
| -/*jslint evil: true, regexp: true */ |
| 15 | +/*jslint evil: true, regexp: true, unparam: true */ |
16 | 16 | /*global document, define */
|
17 | 17 |
|
18 | 18 | (function ($) {
|
|
34 | 34 | tmpl.load = function (id) {
|
35 | 35 | return document.getElementById(id).innerHTML;
|
36 | 36 | };
|
37 |
| - tmpl.regexp = /([\s'\\])(?![^%]*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g; |
| 37 | + tmpl.regexp = /([\s'\\])(?!(?:[^{]|\{(?!%))*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g; |
38 | 38 | tmpl.func = function (s, p1, p2, p3, p4, p5) {
|
39 |
| - if (p1) { // whitespace, quote and backspace in interpolation context |
| 39 | + if (p1) { // whitespace, quote and backspace in HTML context |
40 | 40 | return {
|
41 | 41 | "\n": "\\n",
|
42 | 42 | "\r": "\\r",
|
43 | 43 | "\t": "\\t",
|
44 | 44 | " " : " "
|
45 |
| - }[s] || "\\" + s; |
| 45 | + }[p1] || "\\" + p1; |
46 | 46 | }
|
47 | 47 | if (p2) { // interpolation: {%=prop%}, or unescaped: {%#prop%}
|
48 | 48 | if (p2 === "=") {
|
49 | 49 | return "'+_e(" + p3 + ")+'";
|
50 | 50 | }
|
51 |
| - return "'+(" + p3 + "||'')+'"; |
| 51 | + return "'+(" + p3 + "==null?'':" + p3 + ")+'"; |
52 | 52 | }
|
53 | 53 | if (p4) { // evaluation start tag: {%
|
54 | 54 | return "';";
|
|
66 | 66 | "'" : "'"
|
67 | 67 | };
|
68 | 68 | tmpl.encode = function (s) {
|
69 |
| - return String(s || "").replace( |
| 69 | + /*jshint eqnull:true */ |
| 70 | + return (s == null ? "" : "" + s).replace( |
70 | 71 | tmpl.encReg,
|
71 | 72 | function (c) {
|
72 | 73 | return tmpl.encMap[c] || "";
|
73 | 74 | }
|
74 | 75 | );
|
75 | 76 | };
|
76 | 77 | tmpl.arg = "o";
|
77 |
| - tmpl.helper = ",print=function(s,e){_s+=e&&(s||'')||_e(s);}" + |
| 78 | + tmpl.helper = ",print=function(s,e){_s+=e?(s==null?'':s):_e(s);}" + |
78 | 79 | ",include=function(s,d){_s+=tmpl(s,d);}";
|
79 | 80 | if (typeof define === "function" && define.amd) {
|
80 | 81 | define(function () {
|
|
0 commit comments