Skip to content
This repository has been archived by the owner on Oct 28, 2019. It is now read-only.

Commit

Permalink
UPDATE: add_custom_money_amount()
Browse files Browse the repository at this point in the history
This will now properly use the parse_currency() and currency_format_info
global functions so that the feature will work (in theory) with all
known currency types.

This should fix #1576.  Thanks to @Leopard1907 and @BryanChung for
pointing this out.
  • Loading branch information
jshackles committed Apr 23, 2018
1 parent d1a11b9 commit 684e0bc
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions enhancedsteam.js
Original file line number Diff line number Diff line change
Expand Up @@ -2190,8 +2190,8 @@ function replace_account_name() {
}

function add_custom_money_amount() {
function get_string_with_currency_symbol(string, symbol, space) {
if(symbol == "€" || symbol == "pуб") return string + (space ? " " : "") + symbol;
function get_string_with_currency_symbol(string, right, symbol, space) {
if(right) return string + (space ? " " : "") + symbol;
else return symbol + (space ? " " : "") + string;
}

Expand All @@ -2209,21 +2209,20 @@ function add_custom_money_amount() {
$(newel).find(".giftcard_style").html(localized_strings.wallet.custom_giftcard_amount.replace("__minamount__", price).replace("__input__", "<span id='es_custom_money_amount_wrapper'></span>"));
}

var currency_symbol = currency_symbol_from_string(price);
var minimum = +(price.replace(/(?:R\$|\$||¥|£|pуб)/, "").replace(/(.--|,--)/,""));
var inputel = $(newel).find((giftcard ? "#es_custom_money_amount_wrapper" : ".price"));
inputel.html(get_string_with_currency_symbol("<input type='number' id='es_custom_money_amount' class='es_text_input money' min='" + minimum + "' step='.01' value='" + minimum +"'>", currency_symbol, true));
var currency = parse_currency(price);
var currency_info = currency_format_info[currency.currency_type];
var inputel = $(newel).find((giftcard ? "#es_custom_money_amount_wrapper" : ".price"));
inputel.html(get_string_with_currency_symbol("<input type='number' id='es_custom_money_amount' class='es_text_input money' min='" + currency.value + "' step='.01' value='" + currency.value +"'>", currency_info.right, currency.currency_symbol, true));

$((giftcard ? ".giftcard_selection" : ".addfunds_area_purchase_game") + ":first").after(newel);
$("#es_custom_money_amount").on("input", function() {
var value = $("#es_custom_money_amount").val();
if(isNaN(value) || value == "") $("#es_custom_money_amount").val(minimum);

if(isNaN(value) || value == "") $("#es_custom_money_amount").val(currency.value);
if(giftcard) {
if(value > 10) priceel.addClass("small");
else priceel.removeClass("small");

priceel.text(get_string_with_currency_symbol(value, currency_symbol, false));
priceel.text(get_string_with_currency_symbol(value, currency_info.right, currency.currency_symbol, false));
}
var jsvalue = (+$("#es_custom_money_amount").val()).toFixed(2).replace(/[,.]/g, '');

Expand Down

1 comment on commit 684e0bc

@Leopard1907
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works. Thanks.

Please sign in to comment.