You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
159 lines
5.9 KiB
JavaScript
159 lines
5.9 KiB
JavaScript
/*
|
|
* Copyright 2021 Netsyms Technologies.
|
|
* 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/.
|
|
*/
|
|
|
|
|
|
var pdfjsLib = window['pdfjs-dist/build/pdf'];
|
|
pdfjsLib.GlobalWorkerOptions.workerSrc = 'node_modules/pdfjs-dist/build/pdf.worker.min.js';
|
|
|
|
var signaturePad;
|
|
|
|
function setupNotaryOptions(name, location, expires, idnumber, state) {
|
|
setStorage("notary_name", name);
|
|
setStorage("notary_location", location);
|
|
setStorage("notary_expires", expires);
|
|
setStorage("notary_idnumber", idnumber);
|
|
setStorage("notary_state", state);
|
|
}
|
|
|
|
function openSettingsModal() {
|
|
$("#settingsModal #notary_name").val(getStorage("notary_name"));
|
|
$("#settingsModal #notary_location").val(getStorage("notary_location"));
|
|
$("#settingsModal #notary_expires").val(getStorage("notary_expires"));
|
|
$("#settingsModal #notary_idnumber").val(getStorage("notary_idnumber"));
|
|
$("#settingsModal #notary_state").val(getStorage("notary_state"));
|
|
|
|
$("#settingsModal #color_theme").val(getStorage("color_theme"));
|
|
$("#settingsModal #button_size").val(getStorage("button_size"));
|
|
// show preview of stamp
|
|
if (inStorage("notary_state")) {
|
|
getStampSvg(function (svg) {
|
|
$("#settingsModal #stamp-preview").attr("src", "data:image/svg+xml;base64," + btoa(svg));
|
|
});
|
|
}
|
|
|
|
// show signature
|
|
if (inStorage("notary_signature")) {
|
|
$("#settingsModal #signature-preview").attr("src", "data:image/svg+xml;base64," + btoa(getStorage("notary_signature")));
|
|
}
|
|
|
|
new bootstrap.Modal(document.getElementById('settingsModal')).show();
|
|
}
|
|
|
|
function saveSettingsModal() {
|
|
setupNotaryOptions(
|
|
$("#settingsModal #notary_name").val(),
|
|
$("#settingsModal #notary_location").val(),
|
|
$("#settingsModal #notary_expires").val(),
|
|
$("#settingsModal #notary_idnumber").val(),
|
|
$("#settingsModal #notary_state option:selected").val());
|
|
// show preview of stamp
|
|
if (inStorage("notary_state")) {
|
|
getStampSvg(function (svg) {
|
|
$("#settingsModal #stamp-preview").attr("src", "data:image/svg+xml;base64," + btoa(svg));
|
|
});
|
|
}
|
|
// show signature
|
|
if (inStorage("notary_signature")) {
|
|
$("#settingsModal #signature-preview").attr("src", "data:image/svg+xml;base64," + btoa(getStorage("notary_signature")));
|
|
}
|
|
|
|
setStorage("color_theme", $("#appOptionsSettings #color_theme option:selected").val());
|
|
setAppTheme(getStorage("color_theme"));
|
|
setStorage("button_size", $("#appOptionsSettings #button_size option:selected").val());
|
|
setButtonSize(getStorage("button_size"));
|
|
}
|
|
|
|
function initSignaturePad() {
|
|
var canvas = document.getElementById("signaturecanvas");
|
|
signaturePad = new SignaturePad(canvas, {
|
|
backgroundColor: 'rgba(255, 255, 255, 0.5)',
|
|
onBegin: function () {
|
|
// stop page from jumping around if user starts drawing signature while a text box is focused
|
|
$("input").blur();
|
|
}
|
|
});
|
|
new bootstrap.Modal(document.getElementById('signatureModal')).show();
|
|
|
|
|
|
$("#signatureModal").on("shown.bs.modal", resizeSignaturePadCanvas);
|
|
}
|
|
|
|
function resizeSignaturePadCanvas() {
|
|
var canvas = document.getElementById("signaturecanvas");
|
|
var ratio = Math.max(window.devicePixelRatio || 1, 1);
|
|
canvas.width = canvas.offsetWidth * ratio;
|
|
canvas.height = canvas.offsetHeight * ratio;
|
|
canvas.getContext("2d").scale(ratio, ratio);
|
|
if (signaturePad != null) {
|
|
signaturePad.clear(); // otherwise isEmpty() might return incorrect value
|
|
}
|
|
}
|
|
|
|
function signaturePadUndo() {
|
|
var data = signaturePad.toData();
|
|
|
|
resizeSignaturePadCanvas();
|
|
|
|
if (data) {
|
|
data.pop(); // remove the last dot or line
|
|
signaturePad.fromData(data);
|
|
}
|
|
}
|
|
|
|
|
|
function activateNotarySignaturePad() {
|
|
initSignaturePad();
|
|
signaturePadCallback = function () {
|
|
var signature = signaturePad.toDataURL("image/svg+xml");
|
|
signature = signature.replace("data:image/svg+xml;base64,", "");
|
|
signature = atob(signature);
|
|
setStorage("notary_signature", trimAndShrinkSVG(signature));
|
|
$("#settingsModal #signature-preview").attr("src", "data:image/svg+xml;base64," + btoa(getStorage("notary_signature")));
|
|
};
|
|
}
|
|
|
|
function trimAndShrinkSVG(svgstring) {
|
|
var div = document.getElementById('svgtrimbox');
|
|
div.innerHTML = svgstring;
|
|
var svg = div.firstChild;
|
|
var bbox = svg.getBBox();
|
|
var viewBox = [bbox.x, bbox.y, bbox.width, bbox.height].join(" ");
|
|
svg.setAttribute("viewBox", viewBox);
|
|
svg.setAttribute("width", 100);
|
|
svg.setAttribute("height", 50);
|
|
//console.log(svg.outerHTML);
|
|
div.innerHTML = "";
|
|
return svg.outerHTML;
|
|
}
|
|
|
|
$("body").on("input change paste", "#notaryProfileSettings input,#notaryProfileSettings select", function () {
|
|
getStampSvgWithValues({
|
|
name: $("#settingsModal #notary_name").val(),
|
|
location: $("#settingsModal #notary_location").val(),
|
|
expires: $("#settingsModal #notary_expires").val(),
|
|
idnumber: $("#settingsModal #notary_idnumber").val(),
|
|
state: $("#settingsModal #notary_state option:selected").val()
|
|
}, function (svg) {
|
|
$("#settingsModal #stamp-preview").attr("src", "data:image/svg+xml;base64," + btoa(svg));
|
|
});
|
|
});
|
|
|
|
$("body").on("input change paste", "#appOptionsSettings select", function () {
|
|
setAppTheme($("#appOptionsSettings #color_theme option:selected").val());
|
|
setButtonSize($("#appOptionsSettings #button_size option:selected").val());
|
|
});
|
|
|
|
function setAppTheme(theme) {
|
|
$("body").removeClass().addClass("theme-" + theme);
|
|
}
|
|
|
|
function setButtonSize(size) {
|
|
$(".btn").removeClass(["btn-sm", "btn-lg", "btn-"]).addClass("btn-" + size);
|
|
}
|
|
|
|
setAppTheme(getStorage("color_theme"));
|
|
setButtonSize(getStorage("button_size")); |