Merge pull request #7599 from opf/fix/30862/correct-registration-of-hover-sync

[30862] Correct registration and deregistration of hover sync
pull/7602/head
Henriette Dinger 5 years ago committed by GitHub
commit e1a829b638
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      frontend/src/app/components/wp-table/wp-table-hover-sync.ts

@ -32,24 +32,23 @@ export class WpTableHoverSync {
private lastHoveredElement:Element | null = null;
private $body = jQuery('body');
private lastAffectedElements:JQuery[] = [];
private eventListener = (evt:MouseEvent) => {
const target = evt.target as Element|null;
if (target && target !== this.lastHoveredElement) {
this.handleHover(target);
}
this.lastHoveredElement = target;
}
constructor(private tableAndTimeline:JQuery) {
}
activate() {
this.$body.on('mousemove.hoverSync', (event:JQuery.TriggeredEvent) => {
if (event.target !== this.lastHoveredElement) {
this.handleHover(event.target);
}
this.lastHoveredElement = event.target;
});
window.addEventListener('mousemove', this.eventListener, { passive: true });
}
deactivate() {
this.$body.off('.hoverSync');
window.removeEventListener('mousemove', this.eventListener);
this.removeAllHoverClasses();
}
@ -98,17 +97,12 @@ export class WpTableHoverSync {
this.removeAllHoverClasses();
timelineRow.addClass(cssClassRowHovered);
tableRow.addClass(cssClassRowHovered);
this.lastAffectedElements.push(tableRow);
this.lastAffectedElements.push(timelineRow);
});
}
private removeAllHoverClasses() {
this.lastAffectedElements.forEach(e => {
e.removeClass(cssClassRowHovered);
});
this.lastAffectedElements = [];
this.tableAndTimeline
.find(`.${cssClassRowHovered}`)
.removeClass(cssClassRowHovered);
}
}

Loading…
Cancel
Save