' ).addClass( 'mw-revslider-bubble' )
.on( 'click mouseenter mouseleave', function ( event ) {
self.setTagFilterEvents( $( this ), event );
} );
const $tagLine = $( '
' ).addClass( 'mw-revslider-filter-highlightable-row mw-revslider-tag-row' ).append(
tags[ i ],
$tagBubble,
'
'
);
if ( self.selectedTag === tags[ i ] ) {
self.selectedUser = '';
$tagLine.addClass( 'mw-revslider-filter-highlight' );
$tagLine.find( $tagBubble ).addClass( 'mw-revslider-filter-highlight-bubble' );
}
$tagLine.attr( 'data-tag-name', tags[ i ] );
$tagLines.append( $tagLine );
}
return $tagLines;
},
/**
* Set tag filter events for revisions
*
* @private
* @param {jQuery} $tagBubble
* @param {MouseEvent} event
*/
setTagFilterEvents: function ( $tagBubble, event ) {
const $tagLine = $tagBubble.parent(),
tagName = $tagLine.attr( 'data-tag-name' );
if ( this.selectedTag === tagName && event.type !== 'click' ) {
return;
}
this.removeRevisionFilterHighlighting();
let oldTag;
switch ( event.type ) {
case 'mouseenter':
$tagLine.addClass( 'mw-revslider-filter-highlight' );
$tagBubble.addClass( 'mw-revslider-filter-highlight-bubble' );
this.filterHighlightSameTagRevisions( tagName );
break;
case 'mouseleave':
this.reApplySavedFilterHighlighting( $tagLine, $tagBubble );
break;
case 'click':
oldTag = this.selectedTag;
this.resetRevisionFilterHighlighting();
$tagLine.addClass( 'mw-revslider-filter-highlight' );
$tagBubble.addClass( 'mw-revslider-filter-highlight-bubble' );
if ( oldTag !== tagName ) {
this.filterHighlightSameTagRevisions( tagName );
this.selectedTag = tagName;
}
break;
}
},
/**
* Highlight same tag revisions
*
* @private
* @param {string} tagName
*/
filterHighlightSameTagRevisions: function ( tagName ) {
const revs = this.revisionList.getRevisions();
for ( let i = 0; i < revs.length; i++ ) {
if ( revs[ i ].getTags().indexOf( tagName ) !== -1 ) {
$( '[data-revid="' + revs[ i ].id + '"]' ).parent()
.addClass( 'mw-revslider-revision-filter-highlight' );
}
}
},
/**
* Re-apply filter highlighting from saved state
*
* @private
* @param {jQuery} $line
* @param {jQuery} $bubble
*/
reApplySavedFilterHighlighting: function ( $line, $bubble ) {
$line.removeClass( 'mw-revslider-filter-highlight' );
$bubble.removeClass( 'mw-revslider-filter-highlight-bubble' );
if ( this.selectedTag ) {
this.filterHighlightSameTagRevisions( this.selectedTag );
}
if ( this.selectedUser ) {
this.filterHighlightSameUserRevisions( this.selectedUser );
}
},
/**
* Removes the filter highlighting from the revisions
*
* @private
*/
removeRevisionFilterHighlighting: function () {
$( '.mw-revslider-revision-wrapper' ).removeClass( 'mw-revslider-revision-filter-highlight' );
},
/**
* Resets filter highlighting from setting state
*
* @private
*/
resetRevisionFilterHighlighting: function () {
$( '.mw-revslider-filter-highlightable-row' ).removeClass( 'mw-revslider-filter-highlight' );
$( '.mw-revslider-bubble' ).removeClass( 'mw-revslider-filter-highlight-bubble' );
this.selectedTag = '';
this.selectedUser = '';
},
/**
* Generates the HTML for the page size label
*
* @private
* @param {number} size
* @return {jQuery}
*/
makePageSizeLine: function ( size ) {
return $( '
' )
.text( mw.msg( 'revisionslider-page-size', mw.language.convertNumber( size ), size ) )
.prepend( $( '' ).text( mw.msg( 'revisionslider-label-page-size' ) + mw.msg( 'colon-separator' ) ) );
},
/**
* Generates the HTML for the change size label
*
* @private
* @param {number} relativeSize
* @return {jQuery}
*/
makeChangeSizeLine: function ( relativeSize ) {
let changeSizeClass = 'mw-revslider-change-none',
leadingSign = '';
if ( relativeSize > 0 ) {
changeSizeClass = 'mw-revslider-change-positive';
leadingSign = '+';
} else if ( relativeSize < 0 ) {
changeSizeClass = 'mw-revslider-change-negative';
}
// Classes are documented above
// eslint-disable-next-line mediawiki/class-doc
const $changeNumber = $( '' )
.addClass( changeSizeClass )
.attr( {
dir: 'ltr' // Make sure that minus/plus is on the left
} )
.text( leadingSign + mw.language.convertNumber( relativeSize ) );
return $( '' ).append(
$( '' ).text( mw.msg( 'revisionslider-label-change-size' ) + mw.msg( 'colon-separator' ) ),
mw.message( 'revisionslider-change-size', $changeNumber, relativeSize, Math.abs( relativeSize ) ).parse()
);
},
/**
* @return {jQuery}
*/
getElement: function () {
return this.$html;
}
} );
module.exports = RevisionListView;