diff --git a/BTCPayServer/Views/Stores/PayButton.cshtml b/BTCPayServer/Views/Stores/PayButton.cshtml index 3442f393b..910c404db 100644 --- a/BTCPayServer/Views/Stores/PayButton.cshtml +++ b/BTCPayServer/Views/Stores/PayButton.cshtml @@ -232,7 +232,157 @@ } - + + diff --git a/BTCPayServer/wwwroot/paybutton/paybutton.js b/BTCPayServer/wwwroot/paybutton/paybutton.js index 28b3943f2..dc445186a 100644 --- a/BTCPayServer/wwwroot/paybutton/paybutton.js +++ b/BTCPayServer/wwwroot/paybutton/paybutton.js @@ -37,34 +37,34 @@ var dictionary = { }; VeeValidate.Validator.localize(dictionary); +function getStyles (styles) { + return document.getElementById(styles).innerHTML.trim().replace(/\s{2}/g, '') + '\n' +} + function inputChanges(event, buttonSize) { if (buttonSize !== null && buttonSize !== undefined) { srvModel.buttonSize = buttonSize; } + var isFixedAmount = srvModel.buttonType == 0 + var isCustomAmount = srvModel.buttonType == 1 + var isSlider = srvModel.buttonType == 2 + var width = "209px"; var widthInput = "3em"; if (srvModel.buttonSize === 0) { width = "146px"; widthInput = "2em"; - } else if (srvModel.buttonSize === 1 ) { + } else if (srvModel.buttonSize === 1) { width = "168px"; } else if (srvModel.buttonSize === 2) { width = "209px"; } + var html = - '\n' + + // Styles + getStyles('template-paybutton-styles') + (isSlider ? getStyles('template-slider-styles') : '') + + // Form '
\n' + addInput("storeId", srvModel.storeId); @@ -81,26 +81,22 @@ function inputChanges(event, buttonSize) { if (srvModel.checkoutQueryString) html += addInput("checkoutQueryString", srvModel.checkoutQueryString); // Fixed amount: Add price and currency as hidden inputs - if (srvModel.buttonType == 0) { + if (isFixedAmount) { html += addInput("price", srvModel.price); html += addInput("currency", srvModel.currency); } // Custom amount - else if (srvModel.buttonType == 1) { + else if (isCustomAmount) { html += '
\n
\n'; - - if (!srvModel.simpleInput) html += addPlusMinusButton("-"); - - html += ' ' + addInputPrice(srvModel.price, widthInput, "", srvModel.simpleInput? "number": null, srvModel.min, srvModel.max, srvModel.step); - - if (!srvModel.simpleInput) html += addPlusMinusButton("+"); - + html += srvModel.simpleInput ? '' : addPlusMinusButton("-"); + html += ' ' + addInputPrice(srvModel.price, widthInput, "", srvModel.simpleInput ? "number": null, srvModel.min, srvModel.max, srvModel.step); + html += srvModel.simpleInput ? '' : addPlusMinusButton("+"); html += '
\n'; html += addSelectCurrency(srvModel.currency); html += '
\n'; } // Slider - else if (srvModel.buttonType == 2) { + else if (isSlider) { html += '
\n'; html += addInputPrice(srvModel.price, width, 'onchange="document.querySelector(\'#btcpay-input-range\').value = document.querySelector(\'#btcpay-input-price\').value"'); html += addSelectCurrency(srvModel.currency); @@ -108,9 +104,8 @@ function inputChanges(event, buttonSize) { html += '
\n'; } - html += ' '; - - html += '\n
'; + html += ' \n'; + html += ''; $("#mainCode").text(html).html(); $("#preview").html(html); @@ -141,11 +136,5 @@ function addSelectCurrency(currency) { } function addSlider(price, min, max, step, width) { - var input = document.getElementById('template-input-slider').innerHTML.trim(); - input = input.replace("PRICE", price); - input = input.replace("MIN", min); - input = input.replace("MAX", max); - input = input.replace("STEP", step); - input = input.replace("WIDTH", width); - return ' ' + input + '\n'; + return ' \n'; }