Rename many methods to be much more meaningful

This is split from I4431882 to make that much easier to review.

Additional changes:
* Remove plural "s" from setRevisionPreviewHighlight
* Add "All" to removeAllRevisionPreviewHighlights
* Merge two methods into a single enableRevisionPreviewHighlights

Change-Id: I7088b23a330a46fadfc4ae296cf1d61f0be435f8
This commit is contained in:
thiemowmde 2024-02-20 08:43:15 +01:00
parent d41ff5d8cf
commit 9280f7f2e7
2 changed files with 27 additions and 26 deletions

View file

@ -38,7 +38,7 @@ $.extend( RevisionListView.prototype, {
/**
* @type {boolean}
*/
allowHover: true,
allowRevisionPreviewHighlights: true,
/**
* @type {string}
@ -113,12 +113,12 @@ $.extend( RevisionListView.prototype, {
)
)
.on( 'mouseenter', function ( event ) {
if ( self.allowHover ) {
self.setRevisionHoveredFromMouseEvent( $( this ), event );
if ( self.allowRevisionPreviewHighlights ) {
self.onRevisionHover( $( this ), event );
}
} )
.on( 'mouseleave', function () {
self.unsetAllHovered();
self.removeAllRevisionPreviewHighlights();
self.removeCurrentRevisionFocusWithDelay();
} )
);
@ -129,20 +129,21 @@ $.extend( RevisionListView.prototype, {
return this.$html;
},
enableHover: function () {
this.allowHover = true;
},
disableHover: function () {
this.allowHover = false;
this.unsetAllHovered();
/**
* @param {boolean} [enabled=true]
*/
enableRevisionPreviewHighlights: function ( enabled ) {
this.allowRevisionPreviewHighlights = enabled !== false;
if ( !this.allowRevisionPreviewHighlights ) {
this.removeAllRevisionPreviewHighlights();
}
},
/**
* @param {jQuery} $revisionWrapper
* @param {MouseEvent} event
*/
setRevisionHoveredFromMouseEvent: function ( $revisionWrapper, event ) {
onRevisionHover: function ( $revisionWrapper, event ) {
if ( !$revisionWrapper.length || $( event.target ).closest( '.mw-revslider-revision-tooltip' ).length ) {
return;
}
@ -165,14 +166,14 @@ $.extend( RevisionListView.prototype, {
}
if ( hasMovedTop ) {
this.setRevisionGhost( $revisionWrapper.find( '.mw-revslider-revision-wrapper-up' ) );
this.setRevisionPreviewHighlight( $revisionWrapper.find( '.mw-revslider-revision-wrapper-up' ) );
if ( isOlderTop ) {
this.setRevisionGhost( $neighborRevisionWrapper.find( '.mw-revslider-revision-wrapper-down' ) );
this.setRevisionPreviewHighlight( $neighborRevisionWrapper.find( '.mw-revslider-revision-wrapper-down' ) );
}
} else {
this.setRevisionGhost( $revisionWrapper.find( '.mw-revslider-revision-wrapper-down' ) );
this.setRevisionPreviewHighlight( $revisionWrapper.find( '.mw-revslider-revision-wrapper-down' ) );
if ( isNewerBottom ) {
this.setRevisionGhost( $neighborRevisionWrapper.find( '.mw-revslider-revision-wrapper-up' ) );
this.setRevisionPreviewHighlight( $neighborRevisionWrapper.find( '.mw-revslider-revision-wrapper-up' ) );
}
}
},
@ -181,11 +182,11 @@ $.extend( RevisionListView.prototype, {
* @private
* @param {jQuery} $revisionWrapper
*/
setRevisionGhost: function ( $revisionWrapper ) {
setRevisionPreviewHighlight: function ( $revisionWrapper ) {
$revisionWrapper.addClass( 'mw-revslider-revision-hovered' );
},
unsetAllHovered: function () {
removeAllRevisionPreviewHighlights: function () {
$( '.mw-revslider-revision-wrapper-up, .mw-revslider-revision-wrapper-down' )
.removeClass( 'mw-revslider-revision-hovered' );
},

View file

@ -162,12 +162,12 @@ $.extend( SliderView.prototype, {
.on( 'click', this.revisionsClickHandler.bind( this ) )
.on( 'mouseout', function () {
if ( !self.isDragged ) {
self.getRevisionListView().unsetAllHovered();
self.getRevisionListView().removeAllRevisionPreviewHighlights();
}
} )
.on( 'mouseover', function ( event ) {
if ( !self.isDragged ) {
lastMouseMoveRevisionPos = self.showTooltipsOnMouseMoveHandler(
lastMouseMoveRevisionPos = self.pointerContainerMouseMoveHandler(
event,
null
);
@ -175,7 +175,7 @@ $.extend( SliderView.prototype, {
} )
.on( 'mousemove', function ( event ) {
if ( !self.isDragged ) {
lastMouseMoveRevisionPos = self.showTooltipsOnMouseMoveHandler(
lastMouseMoveRevisionPos = self.pointerContainerMouseMoveHandler(
event,
lastMouseMoveRevisionPos
);
@ -293,7 +293,7 @@ $.extend( SliderView.prototype, {
* @param {number} lastValidPosition
* @return {number}
*/
showTooltipsOnMouseMoveHandler: function ( event, lastValidPosition ) {
pointerContainerMouseMoveHandler: function ( event, lastValidPosition ) {
const pos = this.getRevisionPositionFromLeftOffset( event.pageX );
if ( pos === lastValidPosition ) {
@ -301,8 +301,8 @@ $.extend( SliderView.prototype, {
}
const $hoveredRevisionWrapper = this.getRevElementAtPosition( this.getRevisionsElement(), pos ).parent();
this.getRevisionListView().unsetAllHovered();
this.getRevisionListView().setRevisionHoveredFromMouseEvent( $hoveredRevisionWrapper, event );
this.getRevisionListView().removeAllRevisionPreviewHighlights();
this.getRevisionListView().onRevisionHover( $hoveredRevisionWrapper, event );
return pos;
},
@ -497,7 +497,7 @@ $.extend( SliderView.prototype, {
return false;
}
self.isDragged = true;
self.getRevisionListView().disableHover();
self.getRevisionListView().enableRevisionPreviewHighlights( false );
self.setPointerDragCursor();
self.fadeOutPointerLines( true );
self.escapePressed = false;
@ -510,7 +510,7 @@ $.extend( SliderView.prototype, {
pointer = self.whichPointer( $p );
self.isDragged = false;
self.getRevisionListView().enableHover();
self.getRevisionListView().enableRevisionPreviewHighlights();
self.setPointerDragCursor( false );
if ( self.escapePressed ) {