/* * 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 = ''; $("body").append(html); function addButton(val, label) { $("#bsnumpad-pad").append('
' + label + '
'); } for (var i = 1; i <= 9; i++) { addButton(i, i); } addButton('0', '0'); addButton('.', '.'); addButton('clear', ''); $("#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"); }