/**
* @type Array
*/
- requires: ['js/app.config.js', 'js/app.model.js', 'js/app.ui.js', 'js/app.ui.templateManager.js', 'js/app.helpers.js'],
+ requires: ['js/app.config.js', 'js/app.model.js', 'js/app.ui.js', 'js/app.ui.templateManager.js', 'js/app.ui.templateManager.modifiers.js', 'js/app.helpers.js'],
/**
* @type Model
-/*global tizen, $, app */
+/*global tizen, $, app, ModifierManager */
/**
* @class TemplateManager
*/
* UI module initialisation
*/
init: function init() {
+ this.modifiers = new ModifierManager().getAll();
},
/**
* @param {string} tplParams
*/
getCompleted: function TemplateManager_getCompleted(tplHtml, tplParams) {
- var tplParam, replaceRegExp;
+ var tplParam;
for (tplParam in tplParams) {
if (tplParams.hasOwnProperty(tplParam)) {
- replaceRegExp = new RegExp(['%', tplParam, '%'].join(''), 'g');
- tplHtml = tplHtml.replace(replaceRegExp, tplParams[tplParam]);
+ tplHtml = this.passThruModifiers(tplHtml, tplParam, tplParams[tplParam]);
}
}
return tplHtml;
+ },
+
+ passThruModifiers: function (tplHtml, tplParam, content) {
+ var regModOn = new RegExp('%' + tplParam + '\\|([a-zA-Z]){1,}%', 'g'),
+ regModOff = new RegExp(['%', tplParam, '%'].join(''), 'g'),
+ regModGet = new RegExp('%' + tplParam + '\\|(.+?)%'),
+ specRegExp = new RegExp('\\$','g'),
+ modifier;
+
+ if (content && (typeof content === 'string')) {
+ content = content.replace(specRegExp, '$$$$');
+ }
+
+ if (regModOn.test(tplHtml)) {
+ modifier = tplHtml.match(regModGet)[1];
+ try {
+ content = this.modifiers[modifier](content);
+ } catch (error) {
+ console.error('unknown modifier: ' + modifier);
+ }
+ tplHtml = tplHtml.replace(regModOn, content);
+ } else {
+ tplHtml = tplHtml.replace(regModOff, content);
+ }
+ return tplHtml;
}
};
--- /dev/null
+/*global $*/
+/**
+ * @class ModifierManager
+ */
+function ModifierManager() {
+ 'use strict';
+ this.init();
+}
+
+(function () {
+ 'use strict';
+ ModifierManager.prototype = {
+
+ /**
+ * UI module initialisation
+ */
+ init: function () {
+ },
+
+ /**
+ * @return modifiers object
+ */
+ getAll: function () {
+ return this.modifiers;
+ },
+
+ /**
+ * modifiers definitions
+ */
+ modifiers: {
+ escape: function escape(str) {
+ return $('<span>').text(str).html();
+ }
+ }
+ };
+}());
\ No newline at end of file
<li data-filtertext="%name%" class="%cssClasses%">
<div class="toRemove hidden"><input type="checkbox" /></div>
- <div class="numberOrName">%name%</div>
+ <div class="numberOrName">%name|escape%</div>
<div class="iconStatus"></div>
<div class="callTime">%callTime%</div>
</li>
\ No newline at end of file