|
53 | 53 | // K.D. May 28th, 2012 Bug #112490 Removing linebreaks in the template before rendering it. |
54 | 54 | //D.U. February 28th 2014 Checking if tmpl is initialized |
55 | 55 | if (tmpl) { |
56 | | - tmpl = tmpl.replace(this.regExp.lineBreak, ""); |
| 56 | + tmpl = tmpl.replace($.ig.regExp.lineBreak, ""); |
57 | 57 |
|
58 | 58 | // Removing comments |
59 | | - tmpl = tmpl.replace(this.regExp.comment, ""); |
| 59 | + tmpl = tmpl.replace($.ig.regExp.comment, ""); |
60 | 60 | if (typeof data === "function") { |
61 | 61 | if (args) { |
62 | 62 | data = data.apply(this, args); |
63 | 63 | } else { |
64 | 64 | data = data.call(); |
65 | 65 | } |
66 | 66 | } |
67 | | - if (this._internalTmplCache && this._internalTmplCache.hasOwnProperty(tmpl)) { |
68 | | - this.tokens = this._internalTmplCache[ tmpl ].tokens; |
69 | | - this.args = this._internalTmplCache[ tmpl ].args; |
70 | | - this.i = this._internalTmplCache[ tmpl ].i; |
71 | | - this._hasBlock = this._internalTmplCache[ tmpl ]._hasBlock; |
72 | | - tmpl = this._internalTmplCache[ tmpl ].tmpl; |
| 67 | + if ($.ig._internalTmplCache && $.ig._internalTmplCache.hasOwnProperty(tmpl)) { |
| 68 | + $.ig.tokens = $.ig._internalTmplCache[ tmpl ].tokens; |
| 69 | + $.ig.args = $.ig._internalTmplCache[ tmpl ].args; |
| 70 | + $.ig.i = $.ig._internalTmplCache[ tmpl ].i; |
| 71 | + $.ig._hasBlock = $.ig._internalTmplCache[ tmpl ]._hasBlock; |
| 72 | + tmpl = $.ig._internalTmplCache[ tmpl ].tmpl; |
73 | 73 | } else { |
74 | | - this.tokens = [ ]; |
75 | | - this.args = [ ]; |
76 | | - this.i = 0; |
77 | | - this._tokenizeTemplate(tmpl); |
| 74 | + $.ig.tokens = [ ]; |
| 75 | + $.ig.args = [ ]; |
| 76 | + $.ig.i = 0; |
| 77 | + $.ig._tokenizeTemplate(tmpl); |
78 | 78 | cacheConst = tmpl; |
79 | | - this._internalTmplCache[ cacheConst ] = {}; |
80 | | - this._internalTmplCache[ cacheConst ].tokens = this.tokens; |
81 | | - if (this.regExp.block.test(tmpl)) { |
82 | | - this._hasBlock = true; |
| 79 | + $.ig._internalTmplCache[ cacheConst ] = {}; |
| 80 | + $.ig._internalTmplCache[ cacheConst ].tokens = $.ig.tokens; |
| 81 | + if ($.ig.regExp.block.test(tmpl)) { |
| 82 | + $.ig._hasBlock = true; |
83 | 83 | if (typeof $.ig._tokenizeDirectives === "function") { |
84 | 84 | tmpl = $.ig._tokenizeDirectives(tmpl); |
85 | 85 | } else { |
86 | | - console.warn(this._getLocaleString("noAdvancedTemplating")); |
| 86 | + console.warn($.ig._getLocaleString("noAdvancedTemplating")); |
87 | 87 | } |
88 | 88 | } else { |
89 | | - this._hasBlock = false; |
| 89 | + $.ig._hasBlock = false; |
90 | 90 | } |
91 | | - this._internalTmplCache[ cacheConst ].args = this.args; |
92 | | - this._internalTmplCache[ cacheConst ].i = this.i; |
93 | | - this._internalTmplCache[ cacheConst ]._hasBlock = this._hasBlock; |
94 | | - this._internalTmplCache[ cacheConst ].tmpl = tmpl; |
| 91 | + $.ig._internalTmplCache[ cacheConst ].args = $.ig.args; |
| 92 | + $.ig._internalTmplCache[ cacheConst ].i = $.ig.i; |
| 93 | + $.ig._internalTmplCache[ cacheConst ]._hasBlock = $.ig._hasBlock; |
| 94 | + $.ig._internalTmplCache[ cacheConst ].tmpl = tmpl; |
95 | 95 | } |
96 | | - if (!this.tokens.length) { |
| 96 | + if (!$.ig.tokens.length) { |
97 | 97 |
|
98 | 98 | // Nothing got tokenized |
99 | 99 | return tmpl;// An exception can be thrown here |
100 | 100 | } |
101 | | - if (this._hasBlock) { |
| 101 | + if ($.ig._hasBlock) { |
102 | 102 | if (typeof $.ig._compileTemplate === "function") { |
103 | 103 | // K.D. August 27th, 2013 Bug #150299 Using the advanced templating engine |
104 | 104 | tmpl = $.ig._compileTemplate(tmpl, data); |
105 | 105 | } else { |
106 | | - console.warn(this._getLocaleString("noAdvancedTemplating")); |
| 106 | + console.warn($.ig._getLocaleString("noAdvancedTemplating")); |
107 | 107 | } |
108 | 108 | } else { |
109 | | - tmpl = this._populateTemplate(tmpl, data); |
| 109 | + tmpl = $.ig._populateTemplate(tmpl, data); |
110 | 110 | } |
111 | | - delete this.args; |
112 | | - delete this.tokens; |
113 | | - delete this._hasBlock; |
114 | | - delete this.i; |
| 111 | + delete $.ig.args; |
| 112 | + delete $.ig.tokens; |
| 113 | + delete $.ig._hasBlock; |
| 114 | + delete $.ig.i; |
115 | 115 | } |
116 | 116 | return tmpl; |
117 | 117 | }, |
118 | 118 | clearTmplCache: function () { |
119 | | - delete this._internalTmplCache; |
120 | | - this._internalTmplCache = {}; |
| 119 | + delete $.ig._internalTmplCache; |
| 120 | + $.ig._internalTmplCache = {}; |
121 | 121 | }, |
122 | 122 | /* type="RegExp" Used to tokenize the template string. */ |
123 | 123 | regExp: { |
|
189 | 189 | _internalTmplCache: {}, |
190 | 190 | _tokenizeTemplate: function (template) { |
191 | 191 | var tempToken, splitName; |
192 | | - if (this.regExp.sub.test(template)) { |
193 | | - tempToken = this.regExp.sub.exec(template); |
| 192 | + if ($.ig.regExp.sub.test(template)) { |
| 193 | + tempToken = $.ig.regExp.sub.exec(template); |
194 | 194 | while (tempToken !== null) { |
195 | 195 | splitName = tempToken[ 1 ].split("."); |
196 | 196 |
|
|
200 | 200 | tempToken[ 3 ] = new RegExp("\\$\\{" + tempToken[ 1 ] + "\\}", "g"); |
201 | 201 | tempToken[ 1 ] = splitName; |
202 | 202 | tempToken[ 2 ] = true; |
203 | | - this.tokens.push(tempToken); |
204 | | - tempToken = this.regExp.sub.exec(template); |
| 203 | + $.ig.tokens.push(tempToken); |
| 204 | + tempToken = $.ig.regExp.sub.exec(template); |
205 | 205 | } |
206 | 206 | } |
207 | | - if (this.regExp.nonEncodeSub.test(template)) { |
208 | | - tempToken = this.regExp.nonEncodeSub.exec(template); |
| 207 | + if ($.ig.regExp.nonEncodeSub.test(template)) { |
| 208 | + tempToken = $.ig.regExp.nonEncodeSub.exec(template); |
209 | 209 | while (tempToken !== null) { |
210 | 210 | splitName = tempToken[ 1 ].split("."); |
211 | 211 |
|
|
215 | 215 | tempToken[ 3 ] = new RegExp("\\{\\{html\\s+" + tempToken[ 1 ] + "\\}\\}", "g"); |
216 | 216 | tempToken[ 1 ] = splitName; |
217 | 217 | tempToken[ 2 ] = false; |
218 | | - this.tokens.push(tempToken); |
219 | | - tempToken = this.regExp.nonEncodeSub.exec(template); |
| 218 | + $.ig.tokens.push(tempToken); |
| 219 | + tempToken = $.ig.regExp.nonEncodeSub.exec(template); |
220 | 220 | } |
221 | 221 | } |
222 | 222 | }, |
223 | 223 | _populateTemplate: function (template, data) { |
224 | 224 | var i, j, result = "", temp; |
225 | 225 | if ($.ig.util.getType(data) !== "array") { |
226 | | - for (i = 0; i < this.tokens.length; i++) { |
227 | | - template = this._populateArgumentValue(data, this.tokens[ i ], template); |
| 226 | + for (i = 0; i < $.ig.tokens.length; i++) { |
| 227 | + template = $.ig._populateArgumentValue(data, $.ig.tokens[ i ], template); |
228 | 228 | } |
229 | 229 | result = template; |
230 | 230 | } else { |
231 | 231 | for (j = 0; j < data.length; j++) { |
232 | 232 | temp = template; |
233 | | - for (i = 0; i < this.tokens.length; i++) { |
234 | | - temp = this._populateArgumentValue(data[ j ], this.tokens[ i ], temp); |
| 233 | + for (i = 0; i < $.ig.tokens.length; i++) { |
| 234 | + temp = $.ig._populateArgumentValue(data[ j ], $.ig.tokens[ i ], temp); |
235 | 235 | } |
236 | | - temp = temp.replace(this.regExp.index, j); |
| 236 | + temp = temp.replace($.ig.regExp.index, j); |
237 | 237 | result += temp; |
238 | 238 | } |
239 | 239 | } |
|
259 | 259 | } |
260 | 260 | } |
261 | 261 | if (token[ 2 ] && typeof tempData === "string") { |
262 | | - arg = this.encode(tempData); |
| 262 | + arg = $.ig.encode(tempData); |
263 | 263 | } else { |
264 | 264 | arg = tempData; |
265 | 265 | } |
266 | 266 | } else { |
267 | 267 | if (token[ 2 ] && typeof data[ token[ 1 ] ] === "string") { |
268 | | - arg = this.encode(data[ token[ 1 ] ]); |
| 268 | + arg = $.ig.encode(data[ token[ 1 ] ]); |
269 | 269 | } else { |
270 | 270 | arg = data[ token[ 1 ] ]; |
271 | 271 | } |
|
0 commit comments