/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ function bsmoneypad(title, amount, okbtn, cancelbtn, denominations, callback) { var html = ''; $("body").append(html); if (denominations == null) { denominations = [1.00, 2.00, 5.00, 10.00, 20.00, 50.00, 100.00, null, 0.01, 0.05, 0.10, 0.25, 0.50]; } function addButton(val, label) { $("#bsmoneypad-pad").append('
' + label + '
'); } for (var i = 0; i < denominations.length; i++) { if (denominations[i] === null) { $("#bsmoneypad-pad").append('

'); continue; } var lbl = ""; if (denominations[i] < 1) { lbl = denominations[i] * 100.0 + "ยข"; } else if (denominations[i] % 1 === 0) { lbl = "$" + denominations[i]; } else { lbl = "$" + denominations[i].toFixed(2); } addButton(denominations[i], lbl); } $("#bsmoneypad-title").html(title); $("#bsmoneypad-amount").text("$" + (amount * 1.0).toFixed(2)); $("#bsmoneypad-amount").data('amount', (amount * 1.0)); $("#bsmoneypad-ok").html(okbtn); $("#bsmoneypad-cancel").html(cancelbtn); $("#bsmoneypad-pad").on("click", ".moneypadbtn", function () { var total = $("#bsmoneypad-amount").data('amount') * 1.0; var amount = $(this).data('amount'); if ($("#bsmoneypad-plusminus").data("direction") == "plus") { total += amount; } else { total -= amount; } $("#bsmoneypad-amount").text("$" + (total * 1.0).toFixed(2)); $("#bsmoneypad-amount").data('amount', (total * 1.0)); }); $("#bsmoneypad-plusminus").on("click", function () { if ($(this).data("direction") == "plus") { $(this).data("direction", "minus"); $(this).removeClass("btn-outline-success"); $(this).addClass("btn-outline-danger"); $(this).html(''); } else { $(this).data("direction", "plus"); $(this).removeClass("btn-outline-danger"); $(this).addClass("btn-outline-success"); $(this).html(''); } }); $("#bsmoneypad-reset").on("click", function () { $("#bsmoneypad-amount").text("$0.00"); $("#bsmoneypad-amount").data('amount', 0.0); }); $("#bsmoneypad-ok").on("click", function () { callback($("#bsmoneypad-amount").data('amount').toFixed(2) * 1.0); $("#bsmoneypad").modal("hide"); }); $("#bsmoneypad").on("shown.bs.modal", function () { $("#bsmoneypad-input").focus(); }); $("#bsmoneypad").on("hidden.bs.modal", function () { $("#bsmoneypad").remove(); }); $("#bsmoneypad").modal("show"); }