Commit ce8e64e4 authored by Smari McCarthy's avatar Smari McCarthy
Browse files

Start matching symbols

parent 37af0df8
......@@ -7,8 +7,6 @@ function Marka(target) {
console.log("Exchanged to: " + value);
});
if (!target) {
this.target = $('body').get();
} else {
......@@ -21,7 +19,8 @@ function Marka(target) {
Marka.prototype.match = function() {
// docs: https://github.com/padolsey/findAndReplaceDOMText
var currencySymbols = "[€$¢¥₹₨]";
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,.]+";
var optSpace = "[\\s]*";
......@@ -35,7 +34,6 @@ Marka.prototype.match = function() {
var format3 = numbers + optSpace + magnitudes + optSpace + currencyWords;
var regex = new RegExp("(" + format1 + "|" + format2 + "|" + format3 + ")", "g")
findAndReplaceDOMText(this.target, {
find: regex,
wrap: this.wrapNode()
......@@ -46,20 +44,55 @@ Marka.prototype.doConversions = function() {
var self = this;
$(".marka").each(function(index, value) {
var text = $(value).text();
self.splitSymbols(text);
var res = self.splitSymbols(text);
if (!res) {
$(value).replaceWith(text)
}
});
}
Marka.prototype.splitSymbols = function(text) {
var numbers = /[\d,.]+/;
try {
var number = text.match(numbers)[0];
} catch (e) {
return false;
}
var residual = text.replace(numbers, "");
var symbol = this.findSymbol(residual);
return {number: number, symbol: symbol};
var result = this.findSymbol(residual);
return true;
}
Marka.prototype.findSymbol = function(text) {
var result = {certain: false, symbol: null}
text = $.trim(text);
console.log(">"+text+"<");
if (text.match(/[A-Z]{3}/)) {
for (code in currency_info) {
if (code == text) {
console.log("FOUND SYMBOL: " + code);
}
}
} else if (text.match(/[$€¥]/)) {
for (code in currency_info) {
if (currency_info[code].symbol == text) {
console.log("FOUND SYMBOL: " + code);
}
}
}
return text;
/*
"ILS": {
"symbol": "₪",
"name": "Israeli New Sheqel",
"symbol_native": "₪",
"decimal_digits": 2,
"rounding": 0,
"code": "ILS",
"name_plural": "Israeli new sheqels"
},
*/
}
Marka.prototype.wrapNode = function() {
......
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