' ).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;
if ( self.selectedUser === userName && event.type !== 'click' ) {
return;
}
self.removeRevisionHighlight();
switch ( event.type ) {
case 'mouseenter':
$userLine.addClass( 'mw-revslider-highlight' );
$userBubble.addClass( 'mw-revslider-highlite-bubble' );
self.highlightSameUserRevisions( userName );
break;
case 'mouseleave':
self.reApplySavedHighlighting( $userLine, $userBubble );
break;
case 'click':
oldUser = self.selectedUser;
self.resetRevisionHighlighting();
$userLine.addClass( 'mw-revslider-highlight' );
$userBubble.addClass( 'mw-revslider-highlite-bubble' );
if ( oldUser !== userName ) {
self.highlightSameUserRevisions( userName );
self.selectedUser = userName;
}
break;
}
},
/**
* 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 $( '
' ).append(
$( '' ).text( mw.msg( 'revisionslider-label-comment' ) + mw.msg( 'colon-separator' ) ),
$( '' ).append(
$( '' ).append(
rev.getParsedComment()
)
)
);
},
/**
* Generates the HTML for the tags label
*
* @param {Revision} rev
* @return {string|jQuery}
*/
makeTagsLine: function ( rev ) {
var self = this,
tags, $tagLines, i, $tagLine, $tagBubble;
if ( rev.hasNoTags() ) {
return '';
}
tags = rev.getTags();
$tagLines = $( '' );
for ( i = 0; i < tags.length; i++ ) {
$tagLine = $( '
' ).addClass( 'mw-revslider-highlightable-row mw-revslider-tag-row' ).append(
tags[ i ],
$tagBubble = $( '
' ).addClass( 'mw-revslider-bubble' )
.on( 'click mouseenter mouseleave', function ( event ) {
self.setTagFilterEvents( $( this ), event );
} ),
'
'
);
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 ) {
var self = this,
$tagLine = $tagBubble.parent(),
tagName = $tagLine.data( 'tag-name' ),
oldTag;
if ( self.selectedTag === tagName && event.type !== 'click' ) {
return;
}
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 ) {
self.highlightSameTagRevisions( tagName );
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' );
}
}
}
},
/**
* 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 ) {
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';
}
// Classes are documented above
// eslint-disable-next-line mediawiki/class-doc
$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;