2020-06-16 14:13:36 +00:00
|
|
|
/**
|
|
|
|
* @external Revision
|
|
|
|
* @external RevisionList
|
|
|
|
*/
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* @class RevisionListView
|
|
|
|
* @param {RevisionList} revisionList
|
|
|
|
* @param {string} [dir]
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function RevisionListView( revisionList, dir ) {
|
|
|
|
this.revisionList = revisionList;
|
|
|
|
this.dir = dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
$.extend( RevisionListView.prototype, {
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
2020-11-18 09:11:12 +00:00
|
|
|
* @type {RevisionList}
|
2016-06-17 13:06:12 +00:00
|
|
|
*/
|
2020-11-18 09:11:12 +00:00
|
|
|
revisionList: null,
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2020-01-24 16:21:23 +00:00
|
|
|
/**
|
2020-11-18 09:11:12 +00:00
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
revisionWidth: 16,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
minRevisionHeight: 5,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
maxRevisionHeight: 66,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
tooltipTimeout: -1,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
allowHover: true,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
dir: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
selectedUser: '',
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
selectedTag: '',
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {jQuery}
|
|
|
|
*/
|
|
|
|
html: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} revisionTickWidth
|
|
|
|
* @param {number} positionOffset
|
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
|
|
|
render: function ( revisionTickWidth, positionOffset ) {
|
|
|
|
var revs = this.revisionList.getRevisions(),
|
|
|
|
maxChangeSizeLogged = Math.log( this.revisionList.getBiggestChangeSize() ),
|
|
|
|
self = this,
|
|
|
|
i, diffSize, relativeChangeSize;
|
|
|
|
|
|
|
|
positionOffset = positionOffset || 0;
|
|
|
|
this.revisionWidth = revisionTickWidth;
|
|
|
|
|
|
|
|
this.$html = $( '<div>' ).addClass( 'mw-revslider-revisions' );
|
|
|
|
|
|
|
|
for ( i = 0; i < revs.length; i++ ) {
|
|
|
|
diffSize = revs[ i ].getRelativeSize();
|
|
|
|
relativeChangeSize = this.calcRelativeChangeSize( diffSize, maxChangeSizeLogged );
|
|
|
|
|
|
|
|
this.$html
|
|
|
|
.append( $( '<div>' )
|
|
|
|
.addClass( 'mw-revslider-revision-wrapper' )
|
|
|
|
.width( this.revisionWidth )
|
|
|
|
.append( $( '<div>' )
|
|
|
|
.addClass( 'mw-revslider-revision' )
|
|
|
|
.attr( 'data-revid', revs[ i ].getId() )
|
|
|
|
.attr( 'data-pos', positionOffset + i + 1 )
|
|
|
|
.attr( 'data-user', revs[ i ].getUser() )
|
|
|
|
.css( {
|
|
|
|
height: relativeChangeSize + 'px',
|
|
|
|
width: this.revisionWidth + 'px',
|
|
|
|
top: diffSize > 0 ? '-' + relativeChangeSize + 'px' : 0
|
|
|
|
} )
|
|
|
|
.addClass( diffSize > 0 ? 'mw-revslider-revision-up' : 'mw-revslider-revision-down' )
|
|
|
|
.append( $( '<div>' ).addClass( 'mw-revslider-revision-border-box' ) )
|
|
|
|
)
|
2016-05-30 10:06:44 +00:00
|
|
|
.append( $( '<div>' )
|
2020-11-18 09:11:12 +00:00
|
|
|
.addClass( 'mw-revslider-revision-wrapper-up' )
|
2016-08-03 12:08:05 +00:00
|
|
|
.width( this.revisionWidth )
|
2020-11-18 09:11:12 +00:00
|
|
|
.append(
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-revslider-pointer mw-revslider-pointer-ghost' )
|
2016-05-18 14:55:39 +00:00
|
|
|
)
|
2020-11-18 09:11:12 +00:00
|
|
|
)
|
|
|
|
.append( $( '<div>' )
|
|
|
|
.addClass( 'mw-revslider-revision-wrapper-down' )
|
|
|
|
.width( this.revisionWidth )
|
|
|
|
.append(
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-revslider-pointer mw-revslider-pointer-ghost' )
|
2017-08-17 14:08:49 +00:00
|
|
|
)
|
2020-11-18 09:11:12 +00:00
|
|
|
)
|
|
|
|
.on( 'mouseenter', function ( event ) {
|
|
|
|
if ( self.allowHover ) {
|
|
|
|
self.setRevisionHovered( $( this ), event );
|
|
|
|
}
|
|
|
|
} )
|
|
|
|
.on( 'mouseleave', function () {
|
|
|
|
self.unsetRevisionHovered( $( this ) );
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
}
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
this.keepTooltipsOnHover();
|
|
|
|
this.closeTooltipsOnClick();
|
2016-06-24 13:13:20 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
return this.$html;
|
|
|
|
},
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
enableHover: function () {
|
|
|
|
this.allowHover = true;
|
|
|
|
},
|
2017-08-17 14:08:49 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
disableHover: function () {
|
|
|
|
this.allowHover = false;
|
|
|
|
this.unsetAllHovered();
|
|
|
|
},
|
2017-08-17 14:08:49 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* @param {jQuery} $revisionWrapper
|
|
|
|
* @param {MouseEvent} event
|
|
|
|
*/
|
|
|
|
setRevisionHovered: function ( $revisionWrapper, event ) {
|
|
|
|
var hasMovedTop = event.pageY - $revisionWrapper.offset().top < $revisionWrapper.height() / 2,
|
|
|
|
isOlderTop = $revisionWrapper.hasClass( 'mw-revslider-revision-older' ) && hasMovedTop,
|
|
|
|
isNewerBottom = $revisionWrapper.hasClass( 'mw-revslider-revision-newer' ) && !hasMovedTop,
|
|
|
|
$neighborRevisionWrapper = $revisionWrapper;
|
|
|
|
|
|
|
|
this.showTooltip( $revisionWrapper );
|
|
|
|
|
|
|
|
if ( isOlderTop ) {
|
|
|
|
$neighborRevisionWrapper = $revisionWrapper.prev();
|
|
|
|
} else if ( isNewerBottom ) {
|
|
|
|
$neighborRevisionWrapper = $revisionWrapper.next();
|
|
|
|
}
|
2017-08-17 14:08:49 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( $neighborRevisionWrapper.length === 0 ) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-17 14:08:49 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( hasMovedTop ) {
|
|
|
|
this.setRevisionGhost( $revisionWrapper.find( '.mw-revslider-revision-wrapper-up' ) );
|
2017-08-17 14:08:49 +00:00
|
|
|
if ( isOlderTop ) {
|
2020-11-18 09:11:12 +00:00
|
|
|
this.setRevisionGhost( $neighborRevisionWrapper.find( '.mw-revslider-revision-wrapper-down' ) );
|
2017-08-17 14:08:49 +00:00
|
|
|
}
|
2020-11-18 09:11:12 +00:00
|
|
|
} else {
|
|
|
|
this.setRevisionGhost( $revisionWrapper.find( '.mw-revslider-revision-wrapper-down' ) );
|
|
|
|
if ( isNewerBottom ) {
|
|
|
|
this.setRevisionGhost( $neighborRevisionWrapper.find( '.mw-revslider-revision-wrapper-up' ) );
|
2017-08-17 14:08:49 +00:00
|
|
|
}
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
|
|
|
},
|
2017-08-17 14:08:49 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* @param {jQuery} $revisionWrapper
|
|
|
|
* @return {number}
|
|
|
|
*/
|
|
|
|
getRevisionWrapperPos: function ( $revisionWrapper ) {
|
|
|
|
return +$revisionWrapper.find( '.mw-revslider-revision' ).attr( 'data-pos' );
|
|
|
|
},
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* @param {jQuery} $revisionWrapper
|
|
|
|
*/
|
|
|
|
setRevisionGhost: function ( $revisionWrapper ) {
|
|
|
|
$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().removeClass( 'mw-revslider-revision-hovered' );
|
|
|
|
$revisionWrapper.prev().children().removeClass( 'mw-revslider-revision-hovered' );
|
|
|
|
$revisionWrapper.next().children().removeClass( 'mw-revslider-revision-hovered' );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {jQuery} $renderedList
|
|
|
|
*/
|
|
|
|
adjustRevisionSizes: function ( $renderedList ) {
|
|
|
|
var revs = this.revisionList.getRevisions(),
|
|
|
|
maxChangeSizeLogged = Math.log( this.revisionList.getBiggestChangeSize() ),
|
|
|
|
i, diffSize, relativeChangeSize;
|
|
|
|
|
|
|
|
for ( i = 0; i < revs.length; i++ ) {
|
|
|
|
diffSize = revs[ i ].getRelativeSize();
|
|
|
|
relativeChangeSize = this.calcRelativeChangeSize( diffSize, maxChangeSizeLogged );
|
|
|
|
|
|
|
|
$renderedList.find( '.mw-revslider-revision[data-pos="' + ( i + 1 ) + '"]' ).css( {
|
|
|
|
height: relativeChangeSize + 'px',
|
|
|
|
top: diffSize > 0 ? '-' + relativeChangeSize + 'px' : 0
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
calcRelativeChangeSize: function ( diffSize, maxChangeSizeLogged ) {
|
|
|
|
if ( diffSize === 0 ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return Math.ceil(
|
|
|
|
( this.maxRevisionHeight - this.minRevisionHeight ) *
|
|
|
|
Math.log( Math.abs( diffSize ) ) / maxChangeSizeLogged ) +
|
|
|
|
this.minRevisionHeight;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the current tooltip immediately
|
|
|
|
*/
|
|
|
|
hideCurrentTooltip: function () {
|
|
|
|
window.clearTimeout( this.tooltipTimeout );
|
|
|
|
$( '.mw-revslider-revision-wrapper-hovered' )
|
|
|
|
.removeClass( 'mw-revslider-revision-wrapper-hovered' );
|
|
|
|
$( '.mw-revslider-revision-tooltip' ).remove();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the tooltip after 500ms
|
|
|
|
*
|
|
|
|
* @param {jQuery} $revisionWrapper
|
|
|
|
*/
|
|
|
|
hideTooltip: function ( $revisionWrapper ) {
|
|
|
|
this.tooltipTimeout = window.setTimeout( function () {
|
|
|
|
$revisionWrapper.removeClass( 'mw-revslider-revision-wrapper-hovered' );
|
2019-01-14 08:37:23 +00:00
|
|
|
$( '.mw-revslider-revision-tooltip' ).remove();
|
2020-11-18 09:11:12 +00:00
|
|
|
}, 500 );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the previous tooltip and shows the new one
|
|
|
|
*
|
|
|
|
* @param {jQuery} $revisionWrapper
|
|
|
|
*/
|
|
|
|
showTooltip: function ( $revisionWrapper ) {
|
|
|
|
var pos = +$revisionWrapper.find( '.mw-revslider-revision' ).attr( 'data-pos' ),
|
|
|
|
revId = +$revisionWrapper.find( '.mw-revslider-revision' ).attr( 'data-revid' ),
|
|
|
|
revision = this.getRevisionWithId( revId ),
|
|
|
|
tooltip;
|
|
|
|
if ( revision === null ) {
|
|
|
|
return;
|
|
|
|
}
|
2016-08-31 13:42:23 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
this.hideCurrentTooltip();
|
2016-08-31 13:42:23 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
tooltip = this.makeTooltip( revision, $revisionWrapper );
|
|
|
|
// eslint-disable-next-line mediawiki/class-doc
|
|
|
|
tooltip.$element.addClass( 'mw-revslider-revision-tooltip-' + pos );
|
2017-03-03 13:55:42 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
$( 'body' ).append( tooltip.$element );
|
|
|
|
tooltip.toggle( true );
|
2016-08-03 12:08:05 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
$revisionWrapper.addClass( 'mw-revslider-revision-wrapper-hovered' );
|
|
|
|
},
|
2016-08-03 12:08:05 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* @param {number} revId
|
|
|
|
* @return {Revision|null}
|
|
|
|
*/
|
|
|
|
getRevisionWithId: function ( revId ) {
|
|
|
|
var matchedRevision = null;
|
|
|
|
this.revisionList.revisions.forEach( function ( revision ) {
|
|
|
|
if ( revision.getId() === revId ) {
|
|
|
|
matchedRevision = revision;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
return matchedRevision;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets event handlers on tooltips so they do not disappear when hovering over them
|
|
|
|
*/
|
|
|
|
keepTooltipsOnHover: function () {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
$( document )
|
|
|
|
.on( 'mouseenter', '.mw-revslider-revision-tooltip', function () {
|
|
|
|
window.clearTimeout( self.tooltipTimeout );
|
|
|
|
} )
|
|
|
|
.on( 'mouseleave', '.mw-revslider-revision-tooltip', function () {
|
|
|
|
self.hideTooltip( $( '.mw-revslider-revision-wrapper-hovered' ) );
|
2016-08-03 12:08:05 +00:00
|
|
|
} );
|
2020-11-18 09:11:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets an event handler to close tooltips when clicking somewhere outside
|
|
|
|
*/
|
|
|
|
closeTooltipsOnClick: function () {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
$( document )
|
|
|
|
.on( 'click', function ( event ) {
|
|
|
|
if ( $( event.target ).closest( '.mw-revslider-revision-tooltip' ).length === 0 &&
|
|
|
|
$( event.target ).closest( '.mw-revslider-revisions-container' ).length === 0 ) {
|
|
|
|
self.hideCurrentTooltip();
|
|
|
|
}
|
2016-08-03 12:08:05 +00:00
|
|
|
} );
|
2020-11-18 09:11:12 +00:00
|
|
|
},
|
2018-08-13 04:42:09 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* Generates the HTML for a tooltip that appears on hover above each revision on the slider
|
|
|
|
*
|
|
|
|
* @param {Revision} revision
|
|
|
|
* @param {jQuery} $revisionWrapper
|
|
|
|
* @return {OO.ui.PopupWidget}
|
|
|
|
*/
|
|
|
|
makeTooltip: function ( revision, $revisionWrapper ) {
|
|
|
|
var $tooltip = $( '<div>' )
|
|
|
|
.append(
|
|
|
|
$( '<p>' ).append(
|
|
|
|
$( '<strong>' ).text( mw.msg( 'revisionslider-label-date' ) + mw.msg( 'colon-separator' ) ),
|
|
|
|
$( '<a>' ).attr( 'href', mw.util.getUrl( null, { oldid: revision.id } ) )
|
|
|
|
.text( revision.getFormattedDate() )
|
2018-08-13 04:42:09 +00:00
|
|
|
),
|
2020-11-18 09:11:12 +00:00
|
|
|
this.makeUserLine( revision.getUser(), revision.getUserGender() ),
|
|
|
|
this.makeCommentLine( revision ),
|
|
|
|
this.makePageSizeLine( revision.getSize() ),
|
|
|
|
this.makeChangeSizeLine( revision.getRelativeSize() ),
|
|
|
|
revision.isMinor() ? $( '<p>' ).text( mw.message( 'revisionslider-minoredit' ).text() ) : '',
|
|
|
|
this.makeTagsLine( revision )
|
2016-07-26 09:03:08 +00:00
|
|
|
);
|
2020-11-18 09:11:12 +00:00
|
|
|
return new OO.ui.PopupWidget( {
|
|
|
|
$content: $tooltip,
|
|
|
|
$floatableContainer: $revisionWrapper,
|
|
|
|
padded: true,
|
|
|
|
classes: [ 'mw-revslider-tooltip', 'mw-revslider-revision-tooltip' ]
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a link to user page or to contributions page for IP addresses
|
|
|
|
*
|
|
|
|
* @param {string} user
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
getUserPage: function ( user ) {
|
|
|
|
return ( mw.util.isIPAddress( user, false ) ? 'Special:Contributions/' : 'User:' ) + this.stripInvalidCharacters( user );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the HTML for the user label
|
|
|
|
*
|
|
|
|
* @param {string} userString
|
|
|
|
* @param {string} userGender
|
|
|
|
* @return {string|jQuery}
|
|
|
|
*/
|
|
|
|
makeUserLine: function ( userString, userGender ) {
|
|
|
|
var self = this,
|
|
|
|
$userLine,
|
|
|
|
$userBubble;
|
|
|
|
|
|
|
|
if ( !userString ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
if ( !userGender ) {
|
|
|
|
userGender = 'unknown';
|
|
|
|
}
|
|
|
|
|
|
|
|
$userLine = $( '<p>' ).addClass( 'mw-revslider-highlightable-row mw-revslider-username-row' ).append(
|
|
|
|
$( '<strong>' ).text( mw.msg( 'revisionslider-label-username', userGender ) + mw.msg( 'colon-separator' ) ),
|
|
|
|
$( '<bdi>' ).append(
|
|
|
|
$( '<a>' ).addClass( 'mw-userlink' ).attr( 'href', mw.util.getUrl( this.getUserPage( userString ) ) ).text( this.stripInvalidCharacters( userString ) )
|
|
|
|
),
|
|
|
|
$userBubble = $( '<div>' ).addClass( 'mw-revslider-bubble' )
|
|
|
|
.on( 'click mouseenter mouseleave', function ( event ) {
|
|
|
|
self.setUserFilterEvents( $( this ), userString, event );
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( self.selectedUser === userString ) {
|
|
|
|
self.selectedTag = '';
|
|
|
|
$userLine.addClass( 'mw-revslider-highlight' );
|
|
|
|
$userBubble.addClass( 'mw-revslider-highlite-bubble' );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $userLine;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set user filter events for revisions
|
|
|
|
*
|
|
|
|
* @param {jQuery} $userBubble
|
|
|
|
* @param {string} userName
|
|
|
|
* @param {MouseEvent} event
|
|
|
|
*/
|
|
|
|
setUserFilterEvents: function ( $userBubble, userName, event ) {
|
|
|
|
var self = this,
|
|
|
|
$userLine = $userBubble.parent(),
|
|
|
|
oldUser;
|
2018-08-13 04:42:09 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( self.selectedUser === userName && event.type !== 'click' ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.removeRevisionHighlight();
|
|
|
|
|
|
|
|
switch ( event.type ) {
|
|
|
|
case 'mouseenter':
|
2019-03-25 16:30:47 +00:00
|
|
|
$userLine.addClass( 'mw-revslider-highlight' );
|
2018-08-13 04:42:09 +00:00
|
|
|
$userBubble.addClass( 'mw-revslider-highlite-bubble' );
|
2020-11-18 09:11:12 +00:00
|
|
|
self.highlightSameUserRevisions( userName );
|
|
|
|
break;
|
|
|
|
case 'mouseleave':
|
|
|
|
self.reApplySavedHighlighting( $userLine, $userBubble );
|
|
|
|
break;
|
|
|
|
case 'click':
|
|
|
|
oldUser = self.selectedUser;
|
|
|
|
self.resetRevisionHighlighting();
|
2018-08-13 04:42:09 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
$userLine.addClass( 'mw-revslider-highlight' );
|
|
|
|
$userBubble.addClass( 'mw-revslider-highlite-bubble' );
|
2019-04-01 14:42:00 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( oldUser !== userName ) {
|
2019-04-01 16:12:56 +00:00
|
|
|
self.highlightSameUserRevisions( userName );
|
2020-11-18 09:11:12 +00:00
|
|
|
self.selectedUser = userName;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
2016-05-30 12:36:48 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* Highlights revisions of the sameUser
|
|
|
|
*
|
|
|
|
* @param {string} userString
|
|
|
|
*/
|
|
|
|
highlightSameUserRevisions: function ( userString ) {
|
|
|
|
$( '[data-user="' + userString + '"]' ).parent()
|
|
|
|
.toggleClass( 'mw-revslider-revision-highlight' );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} s
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
stripInvalidCharacters: function ( s ) {
|
|
|
|
return s.replace( /[<>&]/g, '' );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the HTML for the comment label
|
|
|
|
*
|
|
|
|
* @param {Revision} rev
|
|
|
|
* @return {string|jQuery}
|
|
|
|
*/
|
|
|
|
makeCommentLine: function ( rev ) {
|
|
|
|
if ( rev.hasEmptyComment() ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $( '<p>' ).append(
|
|
|
|
$( '<strong>' ).text( mw.msg( 'revisionslider-label-comment' ) + mw.msg( 'colon-separator' ) ),
|
|
|
|
$( '<em>' ).append(
|
|
|
|
$( '<bdi>' ).append(
|
|
|
|
rev.getParsedComment()
|
2016-06-15 11:56:10 +00:00
|
|
|
)
|
2020-11-18 09:11:12 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
2018-10-24 09:07:34 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* Generates the HTML for the tags label
|
|
|
|
*
|
|
|
|
* @param {Revision} rev
|
|
|
|
* @return {string|jQuery}
|
|
|
|
*/
|
|
|
|
makeTagsLine: function ( rev ) {
|
|
|
|
var self = this,
|
|
|
|
tags, $tagLines, i, $tagLine, $tagBubble;
|
2018-10-24 09:07:34 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( rev.hasNoTags() ) {
|
|
|
|
return '';
|
|
|
|
}
|
2018-10-24 09:07:34 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
tags = rev.getTags();
|
|
|
|
$tagLines = $( '<div>' );
|
2018-10-24 09:07:34 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
for ( i = 0; i < tags.length; i++ ) {
|
|
|
|
$tagLine = $( '<div>' ).addClass( 'mw-revslider-highlightable-row mw-revslider-tag-row' ).append(
|
|
|
|
tags[ i ],
|
|
|
|
$tagBubble = $( '<div>' ).addClass( 'mw-revslider-bubble' )
|
|
|
|
.on( 'click mouseenter mouseleave', function ( event ) {
|
|
|
|
self.setTagFilterEvents( $( this ), event );
|
|
|
|
} ),
|
|
|
|
'<br>'
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( self.selectedTag === tags[ i ] ) {
|
|
|
|
self.selectedUser = '';
|
|
|
|
$tagLine.addClass( 'mw-revslider-highlight' );
|
|
|
|
$tagLine.find( $tagBubble ).addClass( 'mw-revslider-highlite-bubble' );
|
2019-04-01 14:42:00 +00:00
|
|
|
}
|
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
$tagLine.attr( 'data-tag-name', tags[ i ] );
|
|
|
|
$tagLines.append( $tagLine );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $tagLines;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set tag filter events for revisions
|
|
|
|
*
|
|
|
|
* @param {jQuery} $tagBubble
|
|
|
|
* @param {MouseEvent} event
|
|
|
|
*/
|
|
|
|
setTagFilterEvents: function ( $tagBubble, event ) {
|
|
|
|
var self = this,
|
|
|
|
$tagLine = $tagBubble.parent(),
|
|
|
|
tagName = $tagLine.data( 'tag-name' ),
|
|
|
|
oldTag;
|
|
|
|
|
|
|
|
if ( self.selectedTag === tagName && event.type !== 'click' ) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-01 14:42:00 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
self.removeRevisionHighlight();
|
|
|
|
|
|
|
|
switch ( event.type ) {
|
|
|
|
case 'mouseenter':
|
|
|
|
$tagLine.addClass( 'mw-revslider-highlight' );
|
|
|
|
$tagBubble.addClass( 'mw-revslider-highlite-bubble' );
|
|
|
|
self.highlightSameTagRevisions( tagName );
|
|
|
|
break;
|
|
|
|
case 'mouseleave':
|
|
|
|
self.reApplySavedHighlighting( $tagLine, $tagBubble );
|
|
|
|
break;
|
|
|
|
case 'click':
|
|
|
|
oldTag = self.selectedTag;
|
|
|
|
self.resetRevisionHighlighting();
|
|
|
|
|
|
|
|
$tagLine.addClass( 'mw-revslider-highlight' );
|
|
|
|
$tagBubble.addClass( 'mw-revslider-highlite-bubble' );
|
|
|
|
|
|
|
|
if ( oldTag !== tagName ) {
|
2019-04-01 16:12:56 +00:00
|
|
|
self.highlightSameTagRevisions( tagName );
|
2020-11-18 09:11:12 +00:00
|
|
|
self.selectedTag = tagName;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Highlights same tag revisions
|
|
|
|
*
|
|
|
|
* @param {string} tagName
|
|
|
|
*/
|
|
|
|
highlightSameTagRevisions: function ( tagName ) {
|
|
|
|
var i, j, revTags,
|
|
|
|
revs = this.revisionList.getRevisions();
|
|
|
|
|
|
|
|
for ( i = 0; i < revs.length; i++ ) {
|
|
|
|
revTags = revs[ i ].getTags();
|
|
|
|
for ( j = 0; j < revTags.length; j++ ) {
|
|
|
|
if ( tagName === revTags[ j ] ) {
|
|
|
|
$( '[data-revid="' + revs[ i ].id + '"]' ).parent()
|
|
|
|
.addClass( 'mw-revslider-revision-highlight' );
|
2018-10-24 09:07:34 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
|
|
|
},
|
2016-06-15 11:56:10 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* Re-apply highlighting from saved state
|
|
|
|
*
|
|
|
|
* @param {jQuery} $line
|
|
|
|
* @param {jQuery} $bubble
|
|
|
|
*/
|
|
|
|
reApplySavedHighlighting: function ( $line, $bubble ) {
|
|
|
|
$line.removeClass( 'mw-revslider-highlight' );
|
|
|
|
$bubble.removeClass( 'mw-revslider-highlite-bubble' );
|
|
|
|
if ( this.selectedTag ) {
|
|
|
|
this.highlightSameTagRevisions( this.selectedTag );
|
|
|
|
}
|
|
|
|
if ( this.selectedUser ) {
|
|
|
|
this.highlightSameUserRevisions( this.selectedUser );
|
|
|
|
}
|
|
|
|
},
|
2016-06-15 11:56:10 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* Removes the highlighting from the revisions
|
|
|
|
*/
|
|
|
|
removeRevisionHighlight: function () {
|
|
|
|
$( '.mw-revslider-revision-wrapper' ).removeClass( 'mw-revslider-revision-highlight' );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets highlighting setting state
|
|
|
|
*/
|
|
|
|
resetRevisionHighlighting: function () {
|
|
|
|
$( '.mw-revslider-highlightable-row' ).removeClass( 'mw-revslider-highlight' );
|
|
|
|
$( '.mw-revslider-bubble' ).removeClass( 'mw-revslider-highlite-bubble' );
|
|
|
|
this.selectedTag = '';
|
|
|
|
this.selectedUser = '';
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the HTML for the page size label
|
|
|
|
*
|
|
|
|
* @param {number} size
|
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
|
|
|
makePageSizeLine: function ( size ) {
|
|
|
|
return $( '<p>' ).append(
|
|
|
|
$( '<strong>' ).text( mw.msg( 'revisionslider-label-page-size' ) + mw.msg( 'colon-separator' ) ),
|
|
|
|
mw.msg( 'revisionslider-page-size', mw.language.convertNumber( size ), size )
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the HTML for the change size label
|
|
|
|
*
|
|
|
|
* @param {number} relativeSize
|
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
|
|
|
makeChangeSizeLine: function ( relativeSize ) {
|
|
|
|
var changeSizeClass = 'mw-revslider-change-none',
|
|
|
|
leadingSign = '',
|
|
|
|
$changeNumber;
|
|
|
|
|
|
|
|
if ( relativeSize > 0 ) {
|
|
|
|
changeSizeClass = 'mw-revslider-change-positive';
|
|
|
|
leadingSign = '+';
|
|
|
|
} else if ( relativeSize < 0 ) {
|
|
|
|
changeSizeClass = 'mw-revslider-change-negative';
|
2016-05-10 12:42:05 +00:00
|
|
|
}
|
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
// Classes are documented above
|
|
|
|
// eslint-disable-next-line mediawiki/class-doc
|
|
|
|
$changeNumber = $( '<span>' )
|
|
|
|
.addClass( changeSizeClass )
|
|
|
|
.attr( {
|
|
|
|
dir: 'ltr' // Make sure that minus/plus is on the left
|
|
|
|
} )
|
|
|
|
.text( leadingSign + mw.language.convertNumber( relativeSize ) );
|
|
|
|
|
|
|
|
return $( '<p>' ).append(
|
|
|
|
$( '<strong>' ).text( mw.msg( 'revisionslider-label-change-size' ) + mw.msg( 'colon-separator' ) ),
|
|
|
|
mw.message( 'revisionslider-change-size', $changeNumber, relativeSize, Math.abs( relativeSize ) ).parse()
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set direction for the view
|
|
|
|
*
|
|
|
|
* @param {string} dir
|
|
|
|
*/
|
|
|
|
setDir: function ( dir ) {
|
|
|
|
this.dir = dir;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
|
|
|
getElement: function () {
|
|
|
|
return this.$html;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2020-03-29 21:15:32 +00:00
|
|
|
module.exports = RevisionListView;
|