Skip to content

Commit cffc647

Browse files
committed
#4668 - Rejecting predictions using HTML (Apache Annotator)
- Try introducing a double-click detection - however, doesn't work properly at the moment
1 parent 7352b81 commit cffc647

File tree

1 file changed

+50
-4
lines changed

1 file changed

+50
-4
lines changed

inception/inception-html-apache-annotator-editor/src/main/ts/src/apache-annotator/ApacheAnnotatorSelector.ts

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export class ApacheAnnotatorSelector {
2727
private popupContent: HTMLElement | undefined
2828
private popupAnchor: HTMLElement | undefined
2929

30+
private clickCount = 0
31+
private clickTimer: number
32+
private CLICK_DELAY = 300
33+
3034
public constructor (element: Element, ajax: DiamAjax) {
3135
this.ajax = ajax
3236
this.root = element
@@ -63,6 +67,8 @@ export class ApacheAnnotatorSelector {
6367
}
6468

6569
public showSelector (event: Event): void {
70+
console.warn("showSelector")
71+
6672
const mouseEvent = event as MouseEvent
6773

6874
this.destroyPopup()
@@ -76,7 +82,7 @@ export class ApacheAnnotatorSelector {
7682
// inline label
7783
const vid = hls[0].getAttribute('data-iaa-id')
7884
if (!vid) return
79-
this.ajax.selectAnnotation(vid)
85+
this.onClick(mouseEvent, vid)
8086
return
8187
}
8288

@@ -106,7 +112,7 @@ export class ApacheAnnotatorSelector {
106112
labelArea.classList.add('iaa-label')
107113
labelArea.textContent = label !== NO_LABEL ? label : 'no label'
108114
labelArea.style.cursor = 'pointer'
109-
labelArea.addEventListener('click', e => this.onSelectAnnotation(e, vid))
115+
labelArea.addEventListener('mouseup', e => this.onClick(e, vid))
110116
menuItem.appendChild(labelArea)
111117

112118
const deleteButton = document.createElement('a')
@@ -122,13 +128,53 @@ export class ApacheAnnotatorSelector {
122128
this.popup = createPopper(this.popupAnchor, this.popupContent, { placement: 'top' })
123129
}
124130

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+
127141
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}`)
128168
this.destroyPopup()
129169
this.ajax.selectAnnotation(id)
130170
}
131171

172+
private onExtensionAction (id: VID) {
173+
console.warn(`Trigger extension action on annotation ${id}`)
174+
this.destroyPopup()
175+
this.ajax.triggerExtensionAction(id)
176+
}
177+
132178
private onDeleteAnnotation (event: Event, id: VID) {
133179
console.log(`Deleting annotation ${id}`)
134180
event.stopPropagation()

0 commit comments

Comments
 (0)