Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow drawing outside canvas for a smoother signature #765

Merged
merged 11 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/css/signature-pad.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ body {
-ms-flex: 1;
flex: 1;
border: 1px solid #f4f4f4;
border-radius: 4px;
}

.signature-pad--body.empty {
background-color: #333;
}

.signature-pad--body canvas {
Expand Down
6 changes: 5 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</span>

<div id="signature-pad" class="signature-pad">
<div class="signature-pad--body">
<div id="canvas-wrapper" class="signature-pad--body">
<canvas></canvas>
</div>
<div class="signature-pad--footer">
Expand All @@ -59,6 +59,10 @@
background</button>
</div>
</div>

<div>
<button type="button" class="button" data-action="open-in-window">Open in Window</button>
</div>
</div>
</div>

Expand Down
19 changes: 19 additions & 0 deletions docs/js/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const wrapper = document.getElementById("signature-pad");
const canvasWrapper = document.getElementById("canvas-wrapper");
const clearButton = wrapper.querySelector("[data-action=clear]");
const changeBackgroundColorButton = wrapper.querySelector("[data-action=change-background-color]");
const changeColorButton = wrapper.querySelector("[data-action=change-color]");
Expand All @@ -9,6 +10,7 @@ const savePNGButton = wrapper.querySelector("[data-action=save-png]");
const saveJPGButton = wrapper.querySelector("[data-action=save-jpg]");
const saveSVGButton = wrapper.querySelector("[data-action=save-svg]");
const saveSVGWithBackgroundButton = wrapper.querySelector("[data-action=save-svg-with-background]");
const openInWindowButton = wrapper.querySelector("[data-action=open-in-window]");
let undoData = [];
const canvas = wrapper.querySelector("canvas");
const signaturePad = new SignaturePad(canvas, {
Expand Down Expand Up @@ -182,3 +184,20 @@ saveSVGWithBackgroundButton.addEventListener("click", () => {
download(dataURL, "signature.svg");
}
});

openInWindowButton.addEventListener("click", () => {
var externalWin = window.open('', '', `width=${canvas.width / window.devicePixelRatio},height=${canvas.height / window.devicePixelRatio}`);
canvas.style.width = "100%";
canvas.style.height = "100%";
externalWin.onresize = resizeCanvas;
externalWin.document.body.style.margin = '0';
externalWin.document.body.appendChild(canvas);
canvasWrapper.classList.add("empty");
externalWin.onbeforeunload = () => {
canvas.style.width = "";
canvas.style.height = "";
canvasWrapper.classList.remove("empty");
canvasWrapper.appendChild(canvas);
resizeCanvas();
};
})
2 changes: 1 addition & 1 deletion docs/js/signature_pad.umd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/js/signature_pad.umd.min.js.map

Large diffs are not rendered by default.

Loading
Loading