Skip to content

Commit c0fe847

Browse files
author
Victor Nazzaro
committed
better firefox handling and made storing decimals better.
1 parent 5b58611 commit c0fe847

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/UI/pen.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ let _penColor;
1515
let path;
1616
let lines = [];
1717

18+
const isFirefox = /firefox/i.test(navigator.userAgent);
19+
1820
/**
1921
* Handle document.touchdown or document.pointerdown event
2022
*/
@@ -108,7 +110,8 @@ function savePoint(x, y) {
108110
x - rect.left,
109111
y - rect.top
110112
], svg);
111-
113+
point[0] = point[0].toFixed(2);
114+
point[1] = point[1].toFixed(2);
112115
lines.push(point);
113116

114117
if (lines.length <= 1) {
@@ -146,7 +149,7 @@ export function enablePen() {
146149

147150
_enabled = true;
148151
// Chrome and Firefox has different behaviors with how pen works, so we need different events.
149-
if (navigator.userAgent.indexOf("Chrome") !== -1){
152+
if (!isFirefox){
150153
document.addEventListener('touchstart', handleDocumentPointerdown);
151154
document.addEventListener('touchmove', handleDocumentPointermoveChrome);
152155
document.addEventListener('touchend', handleDocumentKeyupChrome);
@@ -169,7 +172,7 @@ export function disablePen() {
169172
if (!_enabled) { return; }
170173

171174
_enabled = false;
172-
if (navigator.userAgent.indexOf("Chrome") !== -1){
175+
if (!isFirefox){
173176
document.removeEventListener('touchstart', handleDocumentPointerdown);
174177
document.removeEventListener('touchmove', handleDocumentPointermoveChrome);
175178
document.removeEventListener('touchend', handleDocumentKeyupChrome);

0 commit comments

Comments
 (0)