@@ -27,6 +27,10 @@ export class ApacheAnnotatorSelector {
27
27
private popupContent : HTMLElement | undefined
28
28
private popupAnchor : HTMLElement | undefined
29
29
30
+ private clickCount = 0
31
+ private clickTimer : number
32
+ private CLICK_DELAY = 300
33
+
30
34
public constructor ( element : Element , ajax : DiamAjax ) {
31
35
this . ajax = ajax
32
36
this . root = element
@@ -63,6 +67,8 @@ export class ApacheAnnotatorSelector {
63
67
}
64
68
65
69
public showSelector ( event : Event ) : void {
70
+ console . warn ( "showSelector" )
71
+
66
72
const mouseEvent = event as MouseEvent
67
73
68
74
this . destroyPopup ( )
@@ -76,7 +82,7 @@ export class ApacheAnnotatorSelector {
76
82
// inline label
77
83
const vid = hls [ 0 ] . getAttribute ( 'data-iaa-id' )
78
84
if ( ! vid ) return
79
- this . ajax . selectAnnotation ( vid )
85
+ this . onClick ( mouseEvent , vid )
80
86
return
81
87
}
82
88
@@ -106,7 +112,7 @@ export class ApacheAnnotatorSelector {
106
112
labelArea . classList . add ( 'iaa-label' )
107
113
labelArea . textContent = label !== NO_LABEL ? label : 'no label'
108
114
labelArea . style . cursor = 'pointer'
109
- labelArea . addEventListener ( 'click ' , e => this . onSelectAnnotation ( e , vid ) )
115
+ labelArea . addEventListener ( 'mouseup ' , e => this . onClick ( e , vid ) )
110
116
menuItem . appendChild ( labelArea )
111
117
112
118
const deleteButton = document . createElement ( 'a' )
@@ -122,13 +128,53 @@ export class ApacheAnnotatorSelector {
122
128
this . popup = createPopper ( this . popupAnchor , this . popupContent , { placement : 'top' } )
123
129
}
124
130
125
- private onSelectAnnotation ( event : Event , id : VID ) {
126
- console . log ( `Selecting annotation ${ id } ` )
131
+ /**
132
+ * Distinguish between double clicks and single clicks . This is relevant when clicking on
133
+ * annotations. For clicking on text nodes, this is not really relevant.
134
+ */
135
+ private onClick ( event : MouseEvent , id : VID ) {
136
+ if ( event . button != 0 ) return
137
+
138
+ const singleClickAction = this . onSelectAnnotation . bind ( this )
139
+ const doubleClickAction = this . onExtensionAction . bind ( this )
140
+
127
141
event . stopPropagation ( )
142
+ event . preventDefault ( )
143
+
144
+ this . clickCount ++
145
+ console . warn ( this . clickCount , id )
146
+ if ( this . clickCount === 1 ) {
147
+ this . clickTimer = window . setTimeout ( ( ) => {
148
+ try {
149
+ singleClickAction ( id ) // perform single-click action
150
+ } finally {
151
+ this . clickCount = 0 // after action performed, reset counter
152
+ }
153
+ } , this . CLICK_DELAY )
154
+ } else {
155
+ if ( this . clickTimer !== null ) {
156
+ clearTimeout ( this . clickTimer ) // prevent single-click action
157
+ }
158
+ try {
159
+ doubleClickAction ( id ) // perform double-click action
160
+ } finally {
161
+ this . clickCount = 0 // after action performed, reset counter
162
+ }
163
+ }
164
+ }
165
+
166
+ private onSelectAnnotation ( id : VID ) {
167
+ console . warn ( `Selecting annotation ${ id } ` )
128
168
this . destroyPopup ( )
129
169
this . ajax . selectAnnotation ( id )
130
170
}
131
171
172
+ private onExtensionAction ( id : VID ) {
173
+ console . warn ( `Trigger extension action on annotation ${ id } ` )
174
+ this . destroyPopup ( )
175
+ this . ajax . triggerExtensionAction ( id )
176
+ }
177
+
132
178
private onDeleteAnnotation ( event : Event , id : VID ) {
133
179
console . log ( `Deleting annotation ${ id } ` )
134
180
event . stopPropagation ( )
0 commit comments