' ).addClass( 'mw-revslider-bubble' )
.on( 'click mouseenter mouseleave', function ( event ) {
self.setTagFilterEvents( $( this ), event );
} );
const $tagLine = $( '
' ).addClass( 'mw-revslider-highlightable-row mw-revslider-tag-row' ).append(
tags[ i ],
$tagBubble,
'
'
);
if ( self.selectedTag === tags[ i ] ) {
self.selectedUser = '';
$tagLine.addClass( 'mw-revslider-highlight' );
$tagLine.find( $tagBubble ).addClass( 'mw-revslider-highlite-bubble' );
}
$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 ) {
const self = this,
$tagLine = $tagBubble.parent(),
tagName = $tagLine.data( 'tag-name' );
if ( self.selectedTag === tagName && event.type !== 'click' ) {
return;
}
self.removeRevisionHighlight();
let oldTag;
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 ) {
self.highlightSameTagRevisions( tagName );
self.selectedTag = tagName;
}
break;
}
},
/**
* Highlights same tag revisions
*
* @param {string} tagName
*/
highlightSameTagRevisions: function ( tagName ) {
const revs = this.revisionList.getRevisions();
for ( let i = 0; i < revs.length; i++ ) {
const revTags = revs[ i ].getTags();
for ( let j = 0; j < revTags.length; j++ ) {
if ( tagName === revTags[ j ] ) {
$( '[data-revid="' + revs[ i ].id + '"]' ).parent()
.addClass( 'mw-revslider-revision-highlight' );
}
}
}
},
/**
* 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 );
}
},
/**
* 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 $( '
' ).append(
$( '' ).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 ) {
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()
);
},
/**
* Set direction for the view
*
* @param {string} dir
*/
setDir: function ( dir ) {
this.dir = dir;
},
/**
* @return {jQuery}
*/
getElement: function () {
return this.$html;
}
} );
module.exports = RevisionListView;