Simplify tooltip and hover effect removal

There's no need and probably just minimal gain to use these methods
with a revision as input. We could always just cleanup all tooltips
or wrapper highlighting before we set a new one. Makes the code
much simpler.

Change-Id: I34594843ccafa83372c796ff8cca68c4d6b58e06
This commit is contained in:
WMDE-Fisch 2023-08-30 09:38:57 +02:00
parent 23b2f811a2
commit 3140576347
2 changed files with 7 additions and 38 deletions

View file

@ -118,7 +118,8 @@ $.extend( RevisionListView.prototype, {
}
} )
.on( 'mouseleave', function () {
self.unsetRevisionHovered( $( this ) );
self.unsetAllHovered();
self.hideCurrentTooltipWithDelay();
} )
);
}
@ -177,14 +178,6 @@ $.extend( RevisionListView.prototype, {
}
},
/**
* @param {jQuery} $revisionWrapper
* @return {number}
*/
getRevisionWrapperPos: function ( $revisionWrapper ) {
return +$revisionWrapper.find( '.mw-revslider-revision' ).attr( 'data-pos' );
},
/**
* @param {jQuery} $revisionWrapper
*/
@ -192,29 +185,11 @@ $.extend( RevisionListView.prototype, {
$revisionWrapper.addClass( 'mw-revslider-revision-hovered' );
},
/**
* @param {jQuery} $revisionWrapper
*/
unsetRevisionHovered: function ( $revisionWrapper ) {
this.unsetRevisionGhosts( $revisionWrapper );
this.hideTooltip( $revisionWrapper );
},
unsetAllHovered: function () {
$( '.mw-revslider-revision-wrapper-up, .mw-revslider-revision-wrapper-down' )
.removeClass( 'mw-revslider-revision-hovered' );
},
/**
* @param {jQuery} $revisionWrapper
*/
unsetRevisionGhosts: function ( $revisionWrapper ) {
$revisionWrapper.children()
.add( $revisionWrapper.prev().children() )
.add( $revisionWrapper.next().children() )
.removeClass( 'mw-revslider-revision-hovered' );
},
/**
* @param {jQuery} $renderedList
*/
@ -254,15 +229,10 @@ $.extend( RevisionListView.prototype, {
},
/**
* Hides the tooltip after 500ms
*
* @param {jQuery} $revisionWrapper
* Hides the current tooltip after 500ms
*/
hideTooltip: function ( $revisionWrapper ) {
this.tooltipTimeout = window.setTimeout( function () {
$revisionWrapper.removeClass( 'mw-revslider-revision-wrapper-hovered' );
$( '.mw-revslider-revision-tooltip' ).remove();
}, 500 );
hideCurrentTooltipWithDelay: function () {
this.tooltipTimeout = window.setTimeout( this.hideCurrentTooltip.bind( this ), 500 );
},
/**
@ -342,7 +312,7 @@ $.extend( RevisionListView.prototype, {
window.clearTimeout( self.tooltipTimeout );
} )
.on( 'mouseleave', '.mw-revslider-revision-tooltip', function () {
self.hideTooltip( $( '.mw-revslider-revision-wrapper-hovered' ) );
self.hideCurrentTooltipWithDelay();
} );
},

View file

@ -280,8 +280,7 @@ $.extend( SliderView.prototype, {
}
const $hoveredRevisionWrapper = this.getRevElementAtPosition( this.getRevisionsElement(), pos ).parent();
const $lastRevisionWrapper = this.getRevElementAtPosition( this.getRevisionsElement(), lastValidPosition ).parent();
this.getRevisionListView().unsetRevisionGhosts( $lastRevisionWrapper );
this.getRevisionListView().unsetAllHovered();
this.getRevisionListView().setRevisionHoveredFromMouseEvent( $hoveredRevisionWrapper, event );
return pos;