From f2a3c7aebdfd249c6dc85ee5552673c631593bde Mon Sep 17 00:00:00 2001 From: Artem Sapegin Date: Wed, 21 Nov 2012 00:29:32 +0400 Subject: [PATCH] Some more refactoring of template function. --- src/social-likes.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/social-likes.js b/src/social-likes.js index 172b2b0..6d61600 100644 --- a/src/social-likes.js +++ b/src/social-likes.js @@ -511,10 +511,10 @@ function makeUrl(url, context) { } function template(tmpl, context, filter) { - for (var key in context) if (context.hasOwnProperty(key)) { - tmpl = tmpl.replace(new RegExp('{' + key + '}', 'g'), filter ? filter(context[key]) : context[key]); - } - return tmpl; + return tmpl.replace(/\{([^\}]+)\}/g, function(m, key) { + // If key don't exists in the context we should keep template tag as is + return key in context ? (filter ? filter(context[key]) : context[key]) : m; + }); } function getElementClassNames(elem, mod) {