I have a form that needs to be signed by three people. I initially set it up to be signed by one person, but found out I needed three. I can't get all three to work.
Canvas Containers:
<div class="rowElem">
<div id="container2">
</div>
</div>
<div class="rowElem">
<div id="container3">
</div>
</div>
<div class="rowElem">
<div id="container4">
</div>
</div>
Javascript:
<script>
(function (ns) {
"use strict";
ns.SignatureControl = function (options) {
var containerId = options && options.canvasId || "container2",
callback = options && options.callback || {},
label = options && options.label || "Teacher Signature",
cWidth = options && options.width || "300px",
cHeight = options && options.height || "300px",
btnClearId,
canvas,
ctx;
function initCotnrol() {
createControlElements();
wireButtonEvents();
canvas = _("signatureCanvas");
canvas.addEventListener("mousedown", pointerDown, false);
canvas.addEventListener("mouseup", pointerUp, false);
ctx = canvas.getContext("2d");
}
function createControlElements() {
var signatureArea = document.createElement("div"),
labelDiv = document.createElement("div"),
canvasDiv = document.createElement("div"),
canvasElement = document.createElement("canvas"),
buttonsContainer = document.createElement("div"),
buttonClear = document.createElement("button");
labelDiv.className = "signatureLabel";
labelDiv.textContent = label;
canvasElement.id = "signatureCanvas";
canvasElement.clientWidth = cWidth;
canvasElement.clientHeight = cHeight;
canvasElement.style.border = "solid 2px black";
canvasElement.style.background = "white";
buttonClear.id = "btnClear";
buttonClear.textContent = "Clear Signature Panel";
canvasDiv.appendChild(canvasElement);
buttonsContainer.appendChild(buttonClear);
signatureArea.className = "signatureArea";
signatureArea.appendChild(labelDiv);
signatureArea.appendChild(canvasDiv);
signatureArea.appendChild(buttonsContainer);
_(containerId).appendChild(signatureArea);
}
function pointerDown(evt) {
ctx.beginPath();
ctx.moveTo(evt.offsetX, evt.offsetY);
canvas.addEventListener("mousemove", paint, false);
}
function pointerUp(evt) {
canvas.removeEventListener("mousemove", paint);
paint(evt);
}
function paint(evt) {
ctx.lineTo(evt.offsetX, evt.offsetY);
ctx.stroke();
}
function wireButtonEvents() {
var btnClear = _("btnClear");
btnClear.addEventListener("click", function () {
ctx.clearRect(0, 0, canvas.width, canvas.height);
}, false);
}
function getSignatureImage() {
return ctx.getImageData(0, 0, canvas.width, canvas.height).data;
}
return {
init: initCotnrol,
getSignatureImage: getSignatureImage
};
}
})(this.ns = this.ns || {});
This is the initiator script:
function teacherSig() {
var signature = new ns.SignatureControl({ containerId: 'container2', callback: function () {
}
});
signature.init();
_('btnClear').className = "greyishBtn";
}
window.addEventListener('DOMContentLoaded', teacherSig, false);
</script>
The "_" are a variable set in another file for document.getElementById - I already know that works, I'm using it in all my js files.
I tried duplicating the initiator script and changing the function name/element names, but it did not do any good.
Any help would be greatly appreciated.
If anyone knows a better way to do this, I can try that as well. I'm running out of time on this project, and this was something the client added on in the end. If anyone knows another solution, a plugin or anything for multiple, I'm open to that as well.