Skip to content

Commit 049474f

Browse files
committed
refactor(templating): moving to static calls
1 parent 0c032b1 commit 049474f

File tree

2 files changed

+54
-54
lines changed

2 files changed

+54
-54
lines changed

src/js/modules/infragistics.templating.advanced.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@
5050
temp = template.split(tokens[ 0 ]);
5151
if (temp[ 0 ] && temp[ 0 ].length > 0) {
5252
$.ig.args.push(temp[ 0 ]);
53-
tmpl += "result += args[" + this.i++ + "];";
53+
tmpl += "result += args[" + $.ig.i++ + "];";
5454
}
5555
}
56-
tmpl += this._handleCompleteBlock(tokens);
56+
tmpl += $.ig._handleCompleteBlock(tokens);
5757
if (temp && temp.length > 0 && temp[ 1 ].length > 0) {
5858
$.ig.args.push(temp[ 1 ]);
59-
tmpl += "result += args[" + this.i++ + "];";
59+
tmpl += "result += args[" + $.ig.i++ + "];";
6060
}
6161
tmpl += "return result;";
6262

@@ -85,15 +85,15 @@
8585
}
8686
blocks[ 0 ][ i ] = blocks[ 0 ][ i ].
8787
replace("{{" + tokens[ 1 ], $.ig._directives[ tokens[ 1 ] ].start);
88-
template += this._handleEach(blocks[ 0 ][ i ] + "{{/each}}", [
88+
template += $.ig._handleEach(blocks[ 0 ][ i ] + "{{/each}}", [
8989
blocks[ 0 ][ i ] + "{{/each}}",
9090
"each",
9191
blocks[ 1 ][ i ],
9292
"{{/each}}"
9393
]);
9494
}
9595
} else if (tokens[ 1 ] === "if") {
96-
template += this._handleIfElse(tmpl, tokens);
96+
template += $.ig._handleIfElse(tmpl, tokens);
9797
}
9898
return template;
9999
},
@@ -141,11 +141,11 @@
141141
// Check for a nested blocks and recursively handle them
142142
if ($.ig.regExp.block.test(tmpl)) {
143143
inner = $.ig.regExp.block.exec(tmpl);
144-
tmpl = tmpl.replace(inner[ 0 ], this._handleCompleteBlock(inner));
144+
tmpl = tmpl.replace(inner[ 0 ], $.ig._handleCompleteBlock(inner));
145145
}
146146

147147
// Parse the contents of the block
148-
htmlStrings = tokens[ 2 ].split(this.regExp.blockDirective);
148+
htmlStrings = tokens[ 2 ].split($.ig.regExp.blockDirective);
149149

150150
// We need to make sure that we"re not replacing a substitute inside the if condition with result +=...
151151
tmplArr.push(tmpl.slice(0, tmpl.indexOf(") {") + 3));

src/js/modules/infragistics.templating.js

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -53,71 +53,71 @@
5353
// K.D. May 28th, 2012 Bug #112490 Removing linebreaks in the template before rendering it.
5454
//D.U. February 28th 2014 Checking if tmpl is initialized
5555
if (tmpl) {
56-
tmpl = tmpl.replace(this.regExp.lineBreak, "");
56+
tmpl = tmpl.replace($.ig.regExp.lineBreak, "");
5757

5858
// Removing comments
59-
tmpl = tmpl.replace(this.regExp.comment, "");
59+
tmpl = tmpl.replace($.ig.regExp.comment, "");
6060
if (typeof data === "function") {
6161
if (args) {
6262
data = data.apply(this, args);
6363
} else {
6464
data = data.call();
6565
}
6666
}
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;
7373
} 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);
7878
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;
8383
if (typeof $.ig._tokenizeDirectives === "function") {
8484
tmpl = $.ig._tokenizeDirectives(tmpl);
8585
} else {
86-
console.warn(this._getLocaleString("noAdvancedTemplating"));
86+
console.warn($.ig._getLocaleString("noAdvancedTemplating"));
8787
}
8888
} else {
89-
this._hasBlock = false;
89+
$.ig._hasBlock = false;
9090
}
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;
9595
}
96-
if (!this.tokens.length) {
96+
if (!$.ig.tokens.length) {
9797

9898
// Nothing got tokenized
9999
return tmpl;// An exception can be thrown here
100100
}
101-
if (this._hasBlock) {
101+
if ($.ig._hasBlock) {
102102
if (typeof $.ig._compileTemplate === "function") {
103103
// K.D. August 27th, 2013 Bug #150299 Using the advanced templating engine
104104
tmpl = $.ig._compileTemplate(tmpl, data);
105105
} else {
106-
console.warn(this._getLocaleString("noAdvancedTemplating"));
106+
console.warn($.ig._getLocaleString("noAdvancedTemplating"));
107107
}
108108
} else {
109-
tmpl = this._populateTemplate(tmpl, data);
109+
tmpl = $.ig._populateTemplate(tmpl, data);
110110
}
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;
115115
}
116116
return tmpl;
117117
},
118118
clearTmplCache: function () {
119-
delete this._internalTmplCache;
120-
this._internalTmplCache = {};
119+
delete $.ig._internalTmplCache;
120+
$.ig._internalTmplCache = {};
121121
},
122122
/* type="RegExp" Used to tokenize the template string. */
123123
regExp: {
@@ -189,8 +189,8 @@
189189
_internalTmplCache: {},
190190
_tokenizeTemplate: function (template) {
191191
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);
194194
while (tempToken !== null) {
195195
splitName = tempToken[ 1 ].split(".");
196196

@@ -200,12 +200,12 @@
200200
tempToken[ 3 ] = new RegExp("\\$\\{" + tempToken[ 1 ] + "\\}", "g");
201201
tempToken[ 1 ] = splitName;
202202
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);
205205
}
206206
}
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);
209209
while (tempToken !== null) {
210210
splitName = tempToken[ 1 ].split(".");
211211

@@ -215,25 +215,25 @@
215215
tempToken[ 3 ] = new RegExp("\\{\\{html\\s+" + tempToken[ 1 ] + "\\}\\}", "g");
216216
tempToken[ 1 ] = splitName;
217217
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);
220220
}
221221
}
222222
},
223223
_populateTemplate: function (template, data) {
224224
var i, j, result = "", temp;
225225
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);
228228
}
229229
result = template;
230230
} else {
231231
for (j = 0; j < data.length; j++) {
232232
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);
235235
}
236-
temp = temp.replace(this.regExp.index, j);
236+
temp = temp.replace($.ig.regExp.index, j);
237237
result += temp;
238238
}
239239
}
@@ -259,13 +259,13 @@
259259
}
260260
}
261261
if (token[ 2 ] && typeof tempData === "string") {
262-
arg = this.encode(tempData);
262+
arg = $.ig.encode(tempData);
263263
} else {
264264
arg = tempData;
265265
}
266266
} else {
267267
if (token[ 2 ] && typeof data[ token[ 1 ] ] === "string") {
268-
arg = this.encode(data[ token[ 1 ] ]);
268+
arg = $.ig.encode(data[ token[ 1 ] ]);
269269
} else {
270270
arg = data[ token[ 1 ] ];
271271
}

0 commit comments

Comments
 (0)