mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RevisionSlider
synced 2024-12-18 09:50:49 +00:00
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:
parent
d41ff5d8cf
commit
9280f7f2e7
|
@ -38,7 +38,7 @@ $.extend( RevisionListView.prototype, {
|
||||||
/**
|
/**
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
allowHover: true,
|
allowRevisionPreviewHighlights: true,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {string}
|
* @type {string}
|
||||||
|
@ -113,12 +113,12 @@ $.extend( RevisionListView.prototype, {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.on( 'mouseenter', function ( event ) {
|
.on( 'mouseenter', function ( event ) {
|
||||||
if ( self.allowHover ) {
|
if ( self.allowRevisionPreviewHighlights ) {
|
||||||
self.setRevisionHoveredFromMouseEvent( $( this ), event );
|
self.onRevisionHover( $( this ), event );
|
||||||
}
|
}
|
||||||
} )
|
} )
|
||||||
.on( 'mouseleave', function () {
|
.on( 'mouseleave', function () {
|
||||||
self.unsetAllHovered();
|
self.removeAllRevisionPreviewHighlights();
|
||||||
self.removeCurrentRevisionFocusWithDelay();
|
self.removeCurrentRevisionFocusWithDelay();
|
||||||
} )
|
} )
|
||||||
);
|
);
|
||||||
|
@ -129,20 +129,21 @@ $.extend( RevisionListView.prototype, {
|
||||||
return this.$html;
|
return this.$html;
|
||||||
},
|
},
|
||||||
|
|
||||||
enableHover: function () {
|
/**
|
||||||
this.allowHover = true;
|
* @param {boolean} [enabled=true]
|
||||||
},
|
*/
|
||||||
|
enableRevisionPreviewHighlights: function ( enabled ) {
|
||||||
disableHover: function () {
|
this.allowRevisionPreviewHighlights = enabled !== false;
|
||||||
this.allowHover = false;
|
if ( !this.allowRevisionPreviewHighlights ) {
|
||||||
this.unsetAllHovered();
|
this.removeAllRevisionPreviewHighlights();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {jQuery} $revisionWrapper
|
* @param {jQuery} $revisionWrapper
|
||||||
* @param {MouseEvent} event
|
* @param {MouseEvent} event
|
||||||
*/
|
*/
|
||||||
setRevisionHoveredFromMouseEvent: function ( $revisionWrapper, event ) {
|
onRevisionHover: function ( $revisionWrapper, event ) {
|
||||||
if ( !$revisionWrapper.length || $( event.target ).closest( '.mw-revslider-revision-tooltip' ).length ) {
|
if ( !$revisionWrapper.length || $( event.target ).closest( '.mw-revslider-revision-tooltip' ).length ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -165,14 +166,14 @@ $.extend( RevisionListView.prototype, {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( hasMovedTop ) {
|
if ( hasMovedTop ) {
|
||||||
this.setRevisionGhost( $revisionWrapper.find( '.mw-revslider-revision-wrapper-up' ) );
|
this.setRevisionPreviewHighlight( $revisionWrapper.find( '.mw-revslider-revision-wrapper-up' ) );
|
||||||
if ( isOlderTop ) {
|
if ( isOlderTop ) {
|
||||||
this.setRevisionGhost( $neighborRevisionWrapper.find( '.mw-revslider-revision-wrapper-down' ) );
|
this.setRevisionPreviewHighlight( $neighborRevisionWrapper.find( '.mw-revslider-revision-wrapper-down' ) );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.setRevisionGhost( $revisionWrapper.find( '.mw-revslider-revision-wrapper-down' ) );
|
this.setRevisionPreviewHighlight( $revisionWrapper.find( '.mw-revslider-revision-wrapper-down' ) );
|
||||||
if ( isNewerBottom ) {
|
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
|
* @private
|
||||||
* @param {jQuery} $revisionWrapper
|
* @param {jQuery} $revisionWrapper
|
||||||
*/
|
*/
|
||||||
setRevisionGhost: function ( $revisionWrapper ) {
|
setRevisionPreviewHighlight: function ( $revisionWrapper ) {
|
||||||
$revisionWrapper.addClass( 'mw-revslider-revision-hovered' );
|
$revisionWrapper.addClass( 'mw-revslider-revision-hovered' );
|
||||||
},
|
},
|
||||||
|
|
||||||
unsetAllHovered: function () {
|
removeAllRevisionPreviewHighlights: function () {
|
||||||
$( '.mw-revslider-revision-wrapper-up, .mw-revslider-revision-wrapper-down' )
|
$( '.mw-revslider-revision-wrapper-up, .mw-revslider-revision-wrapper-down' )
|
||||||
.removeClass( 'mw-revslider-revision-hovered' );
|
.removeClass( 'mw-revslider-revision-hovered' );
|
||||||
},
|
},
|
||||||
|
|
|
@ -162,12 +162,12 @@ $.extend( SliderView.prototype, {
|
||||||
.on( 'click', this.revisionsClickHandler.bind( this ) )
|
.on( 'click', this.revisionsClickHandler.bind( this ) )
|
||||||
.on( 'mouseout', function () {
|
.on( 'mouseout', function () {
|
||||||
if ( !self.isDragged ) {
|
if ( !self.isDragged ) {
|
||||||
self.getRevisionListView().unsetAllHovered();
|
self.getRevisionListView().removeAllRevisionPreviewHighlights();
|
||||||
}
|
}
|
||||||
} )
|
} )
|
||||||
.on( 'mouseover', function ( event ) {
|
.on( 'mouseover', function ( event ) {
|
||||||
if ( !self.isDragged ) {
|
if ( !self.isDragged ) {
|
||||||
lastMouseMoveRevisionPos = self.showTooltipsOnMouseMoveHandler(
|
lastMouseMoveRevisionPos = self.pointerContainerMouseMoveHandler(
|
||||||
event,
|
event,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
@ -175,7 +175,7 @@ $.extend( SliderView.prototype, {
|
||||||
} )
|
} )
|
||||||
.on( 'mousemove', function ( event ) {
|
.on( 'mousemove', function ( event ) {
|
||||||
if ( !self.isDragged ) {
|
if ( !self.isDragged ) {
|
||||||
lastMouseMoveRevisionPos = self.showTooltipsOnMouseMoveHandler(
|
lastMouseMoveRevisionPos = self.pointerContainerMouseMoveHandler(
|
||||||
event,
|
event,
|
||||||
lastMouseMoveRevisionPos
|
lastMouseMoveRevisionPos
|
||||||
);
|
);
|
||||||
|
@ -293,7 +293,7 @@ $.extend( SliderView.prototype, {
|
||||||
* @param {number} lastValidPosition
|
* @param {number} lastValidPosition
|
||||||
* @return {number}
|
* @return {number}
|
||||||
*/
|
*/
|
||||||
showTooltipsOnMouseMoveHandler: function ( event, lastValidPosition ) {
|
pointerContainerMouseMoveHandler: function ( event, lastValidPosition ) {
|
||||||
const pos = this.getRevisionPositionFromLeftOffset( event.pageX );
|
const pos = this.getRevisionPositionFromLeftOffset( event.pageX );
|
||||||
|
|
||||||
if ( pos === lastValidPosition ) {
|
if ( pos === lastValidPosition ) {
|
||||||
|
@ -301,8 +301,8 @@ $.extend( SliderView.prototype, {
|
||||||
}
|
}
|
||||||
|
|
||||||
const $hoveredRevisionWrapper = this.getRevElementAtPosition( this.getRevisionsElement(), pos ).parent();
|
const $hoveredRevisionWrapper = this.getRevElementAtPosition( this.getRevisionsElement(), pos ).parent();
|
||||||
this.getRevisionListView().unsetAllHovered();
|
this.getRevisionListView().removeAllRevisionPreviewHighlights();
|
||||||
this.getRevisionListView().setRevisionHoveredFromMouseEvent( $hoveredRevisionWrapper, event );
|
this.getRevisionListView().onRevisionHover( $hoveredRevisionWrapper, event );
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
},
|
},
|
||||||
|
@ -497,7 +497,7 @@ $.extend( SliderView.prototype, {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
self.isDragged = true;
|
self.isDragged = true;
|
||||||
self.getRevisionListView().disableHover();
|
self.getRevisionListView().enableRevisionPreviewHighlights( false );
|
||||||
self.setPointerDragCursor();
|
self.setPointerDragCursor();
|
||||||
self.fadeOutPointerLines( true );
|
self.fadeOutPointerLines( true );
|
||||||
self.escapePressed = false;
|
self.escapePressed = false;
|
||||||
|
@ -510,7 +510,7 @@ $.extend( SliderView.prototype, {
|
||||||
pointer = self.whichPointer( $p );
|
pointer = self.whichPointer( $p );
|
||||||
|
|
||||||
self.isDragged = false;
|
self.isDragged = false;
|
||||||
self.getRevisionListView().enableHover();
|
self.getRevisionListView().enableRevisionPreviewHighlights();
|
||||||
self.setPointerDragCursor( false );
|
self.setPointerDragCursor( false );
|
||||||
|
|
||||||
if ( self.escapePressed ) {
|
if ( self.escapePressed ) {
|
||||||
|
|
Loading…
Reference in a new issue