Commit 1c32bd37 authored by Smari McCarthy's avatar Smari McCarthy
Browse files

Build symbol regex automatically (take 2)

parent f4b22cd8
......@@ -31,15 +31,14 @@ function Marka(target) {
Marka.prototype.match = function() {
// docs: https://github.com/padolsey/findAndReplaceDOMText
this.currencySymbols = "[€$¢¥₹₨]";
/* var opts = [];
var opts = [];
for (sym in currency_info) {
opts.push(currency_info[sym].symbol_native)
var sbl = currency_info[sym].symbol_native.replace("/", "\\/")
if (sbl == "$") { sbl = "\\$" }
opts.push(sbl)
}
this.currencySymbols = "(" + opts.join("|") + ")"
console.log(this.currencySymbols)
*/
var currencySymbols = this.currencySymbols;
var currencyWords = "(" + currencySymbols + "|kr|[Dd]ollars|[Cc]ents on the dollar|[Cc]ents|[Ee]uros|[Pp]ounds|[Rr]upees|[Zz]loty)";
var numbers = "[\\d,.]+";
......@@ -74,17 +73,16 @@ Marka.prototype.doConversions = function() {
$(value).replaceWith(text)
} else {
var node = $(value);
node.data("original_value", node.text());
var children = node.children()
self.getValueInSetCurrency(res.number, res.symbol, function(value, converted) {
if (converted) {
console.log(self.getCurrentCurrency())
node.text(value + " " + self.getCurrentCurrency());
node.text(value.toFixed(2) + " " + self.getCurrentCurrency());
} else {
node.text(node.data("original_value"))
}
node.append(children);
node.children(".marka-results").html("<span class=\"marka-result\">" + node.data("original_value") + "</span>")
})
}
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment