Skip to content

Commit f214cf9

Browse files
author
Victor Nazzaro
committed
Fixed eraser and better naming
1 parent 16255a4 commit f214cf9

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

src/UI/eraser.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,24 @@ import {
99
let _canerase = false;
1010
let userId = "user";
1111

12-
function handleDocumentMouseDown(e){
12+
function handleDocumentDown(e){
1313
_canerase = true;
1414
}
1515

16-
function handleDocumentMouseUp(e){
16+
function handleDocumentUp(e){
1717
_canerase = false;
1818
}
1919

20+
function handleDocumentTouchMove(e){
21+
erase(findAnnotationAtPoint(e.changedTouches[0].clientX, e.changedTouches[0].clientY));
22+
}
23+
2024
function handleDocumentMouseMove(e){
25+
erase(findAnnotationAtPoint(e.clientX, e.clientY));
26+
}
27+
28+
function erase(target){
2129
if(_canerase){
22-
let target = findAnnotationAtPoint(e.clientX, e.clientY);
2330
if(target && target.getAttribute('data-pdf-annotate-userId') == userId){
2431
let { documentId } = getMetadata(target.parentElement);
2532
let annotationId = target.getAttribute('data-pdf-annotate-id');
@@ -36,12 +43,18 @@ function handleDocumentMouseMove(e){
3643
export function enableEraser(){
3744
userId = PDFJSAnnotate.getStoreAdapter().userId;
3845
document.addEventListener('mousemove', handleDocumentMouseMove);
39-
document.addEventListener('mousedown', handleDocumentMouseDown);
40-
document.addEventListener('mouseup', handleDocumentMouseUp);
46+
document.addEventListener('mousedown', handleDocumentDown);
47+
document.addEventListener('mouseup', handleDocumentUp);
48+
document.addEventListener('touchstart', handleDocumentDown);
49+
document.addEventListener('touchmove', handleDocumentTouchMove);
50+
document.addEventListener('touchend', handleDocumentUp);
4151
}
4252

4353
export function disableEraser(){
4454
document.removeEventListener('mousemove', handleDocumentMouseMove);
45-
document.removeEventListener('mousedown', handleDocumentMouseDown);
46-
document.removeEventListener('mouseup', handleDocumentMouseUp);
55+
document.removeEventListener('mousedown', handleDocumentDown);
56+
document.removeEventListener('mouseup', handleDocumentUp);
57+
document.removeEventListener('touchstart', handleDocumentDown);
58+
document.removeEventListener('touchmove', handleDocumentTouchMove);
59+
document.removeEventListener('touchend', handleDocumentUp);
4760
}

src/UI/pen.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function handleDocumentPointerdown(e) {
3232
*
3333
* @param {Event} e The DOM event to be handled
3434
*/
35-
function handleDocumentKeyupChrome(e){
35+
function handleDocumentPointerupChrome(e){
3636
saveToStorage(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
3737
}
3838

@@ -159,7 +159,7 @@ export function enablePen() {
159159
if (!isFirefox){
160160
document.addEventListener('touchstart', handleDocumentPointerdown);
161161
document.addEventListener('touchmove', handleDocumentPointermoveChrome);
162-
document.addEventListener('touchend', handleDocumentKeyupChrome);
162+
document.addEventListener('touchend', handleDocumentPointerupChrome);
163163
document.addEventListener('mousedown', handleDocumentPointerdown);
164164
document.addEventListener('mousemove', handleDocumentPointermove);
165165
document.addEventListener('mouseup', handleDocumentPointerup);
@@ -182,7 +182,7 @@ export function disablePen() {
182182
if (!isFirefox){
183183
document.removeEventListener('touchstart', handleDocumentPointerdown);
184184
document.removeEventListener('touchmove', handleDocumentPointermoveChrome);
185-
document.removeEventListener('touchend', handleDocumentKeyupChrome);
185+
document.removeEventListener('touchend', handleDocumentPointerupChrome);
186186
document.removeEventListener('mousedown', handleDocumentPointerdown);
187187
document.removeEventListener('mousemove', handleDocumentPointermove);
188188
document.removeEventListener('mouseup', handleDocumentPointerup);

web/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ render();
208208
}
209209

210210
function setPen(size, color) {
211-
console.trace();
212211
let modified = false;
213212

214213
if (penSize !== size) {

0 commit comments

Comments
 (0)