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

Do actual conversion

parent e82f9807
......@@ -55,7 +55,16 @@ Marka.prototype.doConversions = function() {
if (res === false) {
$(value).replaceWith(text)
} else {
$(value).text($(value).text() + " -> " + res.number + " " + res.symbol + (res.certain?"":" (not sure)"));
var node = $(value);
node.data("original_value", node.text());
self.getValueInSetCurrency(res.number, res.symbol, function(value, converted) {
if (converted) {
console.log(self.getCurrentCurrency())
node.text(value + " " + self.getCurrentCurrency());
} else {
node.text(node.data("original_value"))
}
})
}
});
}
......@@ -133,12 +142,12 @@ Marka.prototype.getValueInSetCurrency = function(value, from_currency, callback)
Marka.prototype.getValueInCurrency = function(value, from_currency, to_currency, callback){
if(!to_currency){
callback(value);
callback(value, false);
}
this.retreiveExchangeRates(from_currency, to_currency, function(rate){
var converted_amount = value * rate;
callback(converted_amount);
callback(converted_amount, true);
});
}
......@@ -148,7 +157,7 @@ Marka.prototype.getCurrentCurrency = function(){
}
Marka.prototype.setCurrency = function(currency){
this.setCookie("currency", currency, 365);
this.setCookie("currency", currency.toUpperCase(), 365);
}
Marka.prototype.retreiveExchangeRates = function(currency_one, currency_two, callback) {
......@@ -194,7 +203,9 @@ Marka.prototype.getCookie = function (cname) {
}
return "";
}
$(function() { new Marka(document.getElementById('test')); });
var the_marka;
$(function() { the_marka = new Marka(document.getElementById('test')); });
Marka.prototype.setCookie = function (cname, cvalue, exdays) {
var d = new Date();
......
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