add $.format

This commit is contained in:
Pratik Vyas 2014-04-14 12:36:40 +05:30
parent 6c79e85e8c
commit 80f1a3a071
3 changed files with 21 additions and 1 deletions

View file

@ -52,6 +52,7 @@
"public/js/lib/bootstrap.min.js",
"public/js/lib/nprogress.js",
"public/js/lib/beautify-html.js",
"public/js/frappe/format.js",
"public/js/frappe/provide.js",
"public/js/frappe/class.js",

View file

@ -0,0 +1,19 @@
function format (str, args) {
this.unkeyed_index = 0;
return str.replace(/\{(\w*)\}/g, function(match, key) {
if (key === '') {
key = this.unkeyed_index;
this.unkeyed_index++
}
if (key == +key) {
return args[key] !== undefined
? args[key]
: match;
}
}.bind(this));
}
if (jQuery) {
jQuery.format = format
}

View file

@ -247,4 +247,4 @@ frappe.utils = {
setTimeout(function() { callback(dataURL); }, 10 );
}
}
};
};