Add number pad and currency calculator tools, close #16
родител
da2fee3222
ревизия
ce10e4af95
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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 = '<div class="modal fade" id="bsmoneypad">'
|
||||
+ ' <div class="modal-dialog">'
|
||||
+ ' <div class="modal-content">'
|
||||
+ ' <div class="modal-header">'
|
||||
+ ' <h5 class="modal-title" id="bsmoneypad-title"></h5>'
|
||||
+ ' <button type="button" class="close" data-dismiss="modal" aria-label="Close">'
|
||||
+ ' <span aria-hidden="true">×</span>'
|
||||
+ ' </button>'
|
||||
+ ' </div>'
|
||||
+ ' <div class="modal-body" id="bsmoneypad-body">'
|
||||
+ ' <div class="d-flex justify-content-between align-content-center m-2">'
|
||||
+ ' <div class="btn btn-outline-success" id="bsmoneypad-plusminus" data-direction="plus"><i class="fas fa-plus"></i></div>'
|
||||
+ ' <div class="h2" id="bsmoneypad-amount" data-amount="0">$0.00</div>'
|
||||
+ ' <div class="btn btn-outline-primary" id="bsmoneypad-reset"><i class="fas fa-eraser"></i></div>'
|
||||
+ ' </div>'
|
||||
+ ' <div id="bsmoneypad-pad" class="d-flex flex-wrap"></div>'
|
||||
+ ' </div>'
|
||||
+ ' <div class="modal-footer">'
|
||||
+ ' <button type="button" class="btn btn-secondary" data-dismiss="modal" id="bsmoneypad-cancel">Cancel</button>'
|
||||
+ ' <button type="button" class="btn btn-primary" id="bsmoneypad-ok">OK</button>'
|
||||
+ ' </div>'
|
||||
+ ' </div>'
|
||||
+ ' </div>'
|
||||
+ '</div>';
|
||||
$("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('<div class="btn btn-default moneypadbtn m-1" data-amount="' + val + '"><h5>' + label + '</h5></div>');
|
||||
}
|
||||
for (var i = 0; i < denominations.length; i++) {
|
||||
if (denominations[i] === null) {
|
||||
$("#bsmoneypad-pad").append('<div class="w-100 my-0 py-0"><hr /></div>');
|
||||
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('<i class="fas fa-minus"></i>');
|
||||
} else {
|
||||
$(this).data("direction", "plus");
|
||||
$(this).removeClass("btn-outline-danger");
|
||||
$(this).addClass("btn-outline-success");
|
||||
$(this).html('<i class="fas fa-plus"></i>');
|
||||
}
|
||||
});
|
||||
$("#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");
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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 bsnumpad(title, content, okbtn, cancelbtn, callback) {
|
||||
var html = '<div class="modal fade" id="bsnumpad">'
|
||||
+ ' <div class="modal-dialog">'
|
||||
+ ' <div class="modal-content">'
|
||||
+ ' <div class="modal-header">'
|
||||
+ ' <h5 class="modal-title" id="bsnumpad-title"></h5>'
|
||||
+ ' <button type="button" class="close" data-dismiss="modal" aria-label="Close">'
|
||||
+ ' <span aria-hidden="true">×</span>'
|
||||
+ ' </button>'
|
||||
+ ' </div>'
|
||||
+ ' <div class="modal-body" id="bsnumpad-body">'
|
||||
+ ' <div class="display-4 text-center"> <span id="bsnumpad-input"></span> </div>'
|
||||
+ ' <div id="bsnumpad-pad" class="row"></div>'
|
||||
+ ' </div>'
|
||||
+ ' <div class="modal-footer">'
|
||||
+ ' <button type="button" class="btn btn-secondary" data-dismiss="modal" id="bsnumpad-cancel">Cancel</button>'
|
||||
+ ' <button type="button" class="btn btn-primary" id="bsnumpad-ok">OK</button>'
|
||||
+ ' </div>'
|
||||
+ ' </div>'
|
||||
+ ' </div>'
|
||||
+ '</div>';
|
||||
$("body").append(html);
|
||||
function addButton(val, label) {
|
||||
$("#bsnumpad-pad").append('<div class="col-4 p-1"><div class="w-100 h-100 p-2 py-3 btn btn-default numpadbtn" data-key="' + val + '"><h5>' + label + '</h5></div></div>');
|
||||
}
|
||||
for (var i = 1; i <= 9; i++) {
|
||||
addButton(i, i);
|
||||
}
|
||||
addButton('0', '0');
|
||||
addButton('.', '.');
|
||||
addButton('clear', '<i class="fas fa-eraser"></i>');
|
||||
$("#bsnumpad-pad").on("click", ".numpadbtn", function () {
|
||||
var char = $(this).data('key');
|
||||
var val = $("#bsnumpad-input").text();
|
||||
if (char == "clear") {
|
||||
val = "";
|
||||
} else if (char == ".") {
|
||||
if (!val.includes('.')) {
|
||||
val += char;
|
||||
}
|
||||
} else {
|
||||
val += char;
|
||||
}
|
||||
$("#bsnumpad-input").text(val);
|
||||
});
|
||||
$("#bsnumpad-title").html(title);
|
||||
$("#bsnumpad-input").text(content);
|
||||
$("#bsnumpad-ok").html(okbtn);
|
||||
$("#bsnumpad-cancel").html(cancelbtn);
|
||||
$("#bsnumpad-ok").on("click", function () {
|
||||
callback($("#bsnumpad-input").text());
|
||||
$("#bsnumpad").modal("hide");
|
||||
});
|
||||
$("#bsnumpad").on("shown.bs.modal", function () {
|
||||
$("#bsnumpad-input").focus();
|
||||
});
|
||||
$("#bsnumpad").on("hidden.bs.modal", function () {
|
||||
$("#bsnumpad").remove();
|
||||
});
|
||||
$("#bsnumpad").modal("show");
|
||||
}
|
Зареждане…
Reference in New Issue