File tree Expand file tree Collapse file tree 4 files changed +15
-19
lines changed Expand file tree Collapse file tree 4 files changed +15
-19
lines changed Original file line number Diff line number Diff line change @@ -8,8 +8,8 @@ const PAGE_TEMPLATE = `
8
8
<div class="canvasWrapper">
9
9
<canvas></canvas>
10
10
</div>
11
- <div class="` + config . textLayerName + `"></div>
12
11
<svg class="` + config . annotationLayerName + `"></svg>
12
+ <div class="` + config . textLayerName + `"></div>
13
13
</div>
14
14
` ;
15
15
Original file line number Diff line number Diff line change @@ -64,9 +64,6 @@ function saveToStorage(x, y) {
64
64
* @param {PointerEvent } e The DOM event to be handled
65
65
*/
66
66
function handleDocumentPointermove ( e ) {
67
- if ( ! e . srcElement . classList . contains ( 'annotationLayer' ) ) {
68
- return ;
69
- }
70
67
if ( _candraw ) {
71
68
savePoint ( e . clientX , e . clientY ) ;
72
69
}
Original file line number Diff line number Diff line change @@ -21,9 +21,7 @@ function handleDocumentMouseup(e) {
21
21
if ( input || ! findSVGAtPoint ( e . clientX , e . clientY ) ) {
22
22
return ;
23
23
}
24
- if ( ! e . srcElement . classList . contains ( 'annotationLayer' ) ) {
25
- return ;
26
- }
24
+
27
25
input = document . createElement ( 'input' ) ;
28
26
input . setAttribute ( 'id' , 'pdf-annotate-text-input' ) ;
29
27
input . setAttribute ( 'placeholder' , 'Enter text' ) ;
Original file line number Diff line number Diff line change @@ -66,24 +66,25 @@ export function findSVGAtPoint(x, y) {
66
66
/**
67
67
* Find an Element that represents an annotation at a given point.
68
68
*
69
- * IMPORTANT: Requires the annotation layer to be the top most element so
70
- * either use z-ordering or make it the leaf container.
71
- *
72
69
* @param {Number } x The x coordinate of the point
73
70
* @param {Number } y The y coordinate of the point
74
- * @return {Element } The annotation element or null if one can't be found
71
+ * @return {Element|null } The annotation element or null if one can't be found
75
72
*/
76
73
export function findAnnotationAtPoint ( x , y ) {
77
- let el = null ;
78
- let candidate = document . elementFromPoint ( x , y ) ;
79
- while ( ! el && candidate && candidate !== document ) {
80
- let type = candidate . getAttribute ( 'data-pdf-annotate-type' ) ;
81
- if ( type ) {
82
- el = candidate ;
74
+ let svg = findSVGAtPoint ( x , y ) ;
75
+
76
+ if ( ! svg ) {
77
+ return ;
78
+ }
79
+
80
+ let elements = svg . querySelectorAll ( '[data-pdf-annotate-type]' ) ;
81
+ for ( let element of elements ) {
82
+ if ( pointIntersectsRect ( x , y , element . getBoundingClientRect ( ) ) ) {
83
+ return element ;
83
84
}
84
- candidate = candidate . parentNode ;
85
85
}
86
- return el ;
86
+
87
+ return null ;
87
88
}
88
89
89
90
/**
You can’t perform that action at this time.
0 commit comments