2016-05-10 12:42:05 +00:00
|
|
|
( function ( mw, $ ) {
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @param {RevisionList} revisionList
|
|
|
|
* @constructor
|
|
|
|
*/
|
2016-05-10 12:42:05 +00:00
|
|
|
var RevisionListView = function ( revisionList ) {
|
|
|
|
this.revisionList = revisionList;
|
|
|
|
};
|
|
|
|
|
|
|
|
$.extend( RevisionListView.prototype, {
|
|
|
|
/**
|
|
|
|
* @type {RevisionList}
|
|
|
|
*/
|
|
|
|
revisionList: null,
|
|
|
|
|
2016-08-03 12:08:05 +00:00
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
revisionWidth: 16,
|
|
|
|
|
2016-06-24 13:13:20 +00:00
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
tooltipTimeout: -1,
|
|
|
|
|
|
|
|
/**
|
2016-08-03 12:08:05 +00:00
|
|
|
* @type {OO.ui.PopupWidget}
|
2016-06-24 13:13:20 +00:00
|
|
|
*/
|
|
|
|
currentTooltip: null,
|
|
|
|
|
2016-08-03 12:08:05 +00:00
|
|
|
/**
|
|
|
|
* @type {jQuery}
|
|
|
|
*/
|
|
|
|
$highlightedRevisionWrapper: null,
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @param {number} revisionTickWidth
|
2016-06-27 14:00:13 +00:00
|
|
|
* @param {number} positionOffset
|
2016-06-17 13:06:12 +00:00
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
2016-06-27 14:00:13 +00:00
|
|
|
render: function ( revisionTickWidth, positionOffset ) {
|
2016-07-01 10:13:53 +00:00
|
|
|
var $html = $( '<div>' ).addClass( 'mw-revslider-revisions' ),
|
2016-05-10 12:42:05 +00:00
|
|
|
revs = this.revisionList.getRevisions(),
|
|
|
|
maxChangeSizeLogged = Math.log( this.revisionList.getBiggestChangeSize() ),
|
2016-06-24 13:13:20 +00:00
|
|
|
self = this,
|
2016-08-03 12:08:05 +00:00
|
|
|
i, diffSize, relativeChangeSize,
|
2016-06-24 13:13:20 +00:00
|
|
|
showTooltip = function () {
|
|
|
|
self.showTooltip( $( this ) );
|
|
|
|
},
|
|
|
|
hideTooltip = function () {
|
|
|
|
self.hideTooltip( $( this ) );
|
|
|
|
};
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2016-06-27 14:00:13 +00:00
|
|
|
positionOffset = positionOffset || 0;
|
2016-08-03 12:08:05 +00:00
|
|
|
this.revisionWidth = revisionTickWidth;
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2016-05-12 13:52:54 +00:00
|
|
|
for ( i = 0; i < revs.length; i++ ) {
|
|
|
|
diffSize = revs[ i ].getRelativeSize();
|
2016-05-13 15:54:53 +00:00
|
|
|
relativeChangeSize = diffSize !== 0 ? Math.ceil( 65.0 * Math.log( Math.abs( diffSize ) ) / maxChangeSizeLogged ) + 5 : 0;
|
2016-05-10 12:42:05 +00:00
|
|
|
|
|
|
|
$html
|
2016-05-30 10:06:44 +00:00
|
|
|
.append( $( '<div>' )
|
2016-07-01 10:13:53 +00:00
|
|
|
.addClass( 'mw-revslider-revision-wrapper' )
|
2016-08-03 12:08:05 +00:00
|
|
|
.width( this.revisionWidth )
|
2016-05-30 10:06:44 +00:00
|
|
|
.append( $( '<div>' )
|
2016-07-01 10:13:53 +00:00
|
|
|
.addClass( 'mw-revslider-revision' )
|
2016-05-30 10:06:44 +00:00
|
|
|
.attr( 'data-revid', revs[ i ].getId() )
|
2016-06-27 14:00:13 +00:00
|
|
|
.attr( 'data-pos', positionOffset + i + 1 )
|
2016-05-18 14:55:39 +00:00
|
|
|
.css( {
|
|
|
|
height: relativeChangeSize + 'px',
|
2016-08-03 12:08:05 +00:00
|
|
|
width: this.revisionWidth + 'px',
|
2016-05-18 14:55:39 +00:00
|
|
|
top: diffSize > 0 ? '-' + relativeChangeSize + 'px' : 0
|
|
|
|
} )
|
2016-07-01 10:13:53 +00:00
|
|
|
.addClass( diffSize > 0 ? 'mw-revslider-revision-up' : 'mw-revslider-revision-down' )
|
|
|
|
.append( $( '<div>' ).addClass( 'mw-revslider-revision-border-box' ) )
|
2016-05-18 14:55:39 +00:00
|
|
|
)
|
2016-08-31 13:42:23 +00:00
|
|
|
.mouseenter( showTooltip )
|
|
|
|
.mouseleave( hideTooltip )
|
2016-05-26 09:50:51 +00:00
|
|
|
);
|
2016-05-10 12:42:05 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 13:13:20 +00:00
|
|
|
this.keepTooltipsOnHover();
|
|
|
|
|
2016-05-10 12:42:05 +00:00
|
|
|
return $html;
|
|
|
|
},
|
|
|
|
|
2016-06-27 14:00:13 +00:00
|
|
|
/**
|
|
|
|
* @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 = diffSize !== 0 ? Math.ceil( 65.0 * Math.log( Math.abs( diffSize ) ) / maxChangeSizeLogged ) + 5 : 0;
|
|
|
|
$renderedList.find( '.mw-revslider-revision[data-pos="' + ( i + 1 ) + '"]' ).css( {
|
|
|
|
height: relativeChangeSize + 'px',
|
|
|
|
top: diffSize > 0 ? '-' + relativeChangeSize + 'px' : 0
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-06-24 13:13:20 +00:00
|
|
|
/**
|
|
|
|
* Hides the current tooltip immediately
|
|
|
|
*/
|
|
|
|
hideCurrentTooltip: function () {
|
2016-08-31 13:42:23 +00:00
|
|
|
if ( this.tooltipTimeout !== -1 ) {
|
2016-06-24 13:13:20 +00:00
|
|
|
window.clearTimeout( this.tooltipTimeout );
|
2016-08-31 13:42:23 +00:00
|
|
|
}
|
|
|
|
if ( this.$highlightedRevisionWrapper !== null ) {
|
2016-08-03 12:08:05 +00:00
|
|
|
this.$highlightedRevisionWrapper.removeClass( 'mw-revslider-revision-wrapper-hovered' );
|
2016-08-31 13:42:23 +00:00
|
|
|
}
|
|
|
|
if ( this.currentTooltip !== null ) {
|
2016-08-03 12:08:05 +00:00
|
|
|
this.currentTooltip.toggle( false );
|
|
|
|
this.currentTooltip.$element.remove();
|
2016-06-24 13:13:20 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the tooltip after 500ms
|
|
|
|
*
|
|
|
|
* @param {jQuery} $rev
|
|
|
|
*/
|
|
|
|
hideTooltip: function ( $rev ) {
|
2016-08-03 12:08:05 +00:00
|
|
|
var self = this;
|
2016-06-24 13:13:20 +00:00
|
|
|
this.tooltipTimeout = window.setTimeout( function () {
|
2016-08-03 12:08:05 +00:00
|
|
|
if ( $rev !== null ) {
|
|
|
|
$rev.removeClass( 'mw-revslider-revision-wrapper-hovered' );
|
|
|
|
}
|
2016-08-31 13:42:23 +00:00
|
|
|
if ( self.currentTooltip !== null ) {
|
2016-08-03 12:08:05 +00:00
|
|
|
self.currentTooltip.toggle( false );
|
|
|
|
self.currentTooltip.$element.remove();
|
|
|
|
}
|
2016-06-24 13:13:20 +00:00
|
|
|
}, 500 );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the previous tooltip and shows the new one
|
|
|
|
*
|
|
|
|
* @param {jQuery} $rev
|
|
|
|
*/
|
|
|
|
showTooltip: function ( $rev ) {
|
2016-08-03 12:08:05 +00:00
|
|
|
var pos = parseInt( $rev.find( '.mw-revslider-revision' ).attr( 'data-pos' ), 10 ),
|
|
|
|
revId = parseInt( $rev.find( '.mw-revslider-revision' ).attr( 'data-revid' ), 10 ),
|
|
|
|
revision = this.getRevisionWithId( revId ),
|
|
|
|
tooltip;
|
|
|
|
if ( revision === null ) {
|
|
|
|
return;
|
|
|
|
}
|
2016-08-31 13:42:23 +00:00
|
|
|
|
|
|
|
this.hideCurrentTooltip();
|
|
|
|
|
2016-08-03 12:08:05 +00:00
|
|
|
tooltip = this.makeTooltip( revision );
|
|
|
|
tooltip.$element.css( {
|
|
|
|
left: $rev.offset().left + this.revisionWidth / 2 + 'px',
|
|
|
|
top: $rev.offset().top + $rev.outerHeight() + 'px'
|
2016-07-02 20:14:00 +00:00
|
|
|
} ).addClass( 'mw-revslider-revision-tooltip-' + pos );
|
2016-08-03 12:08:05 +00:00
|
|
|
$( 'body' ).append( tooltip.$element );
|
|
|
|
tooltip.toggle( true );
|
|
|
|
|
2016-07-01 10:13:53 +00:00
|
|
|
$rev.addClass( 'mw-revslider-revision-wrapper-hovered' );
|
2016-08-03 12:08:05 +00:00
|
|
|
this.$highlightedRevisionWrapper = $rev;
|
|
|
|
this.currentTooltip = tooltip;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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;
|
2016-06-24 13:13:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets event handlers on tooltips so they do not disappear when hovering over them
|
|
|
|
*/
|
|
|
|
keepTooltipsOnHover: function () {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
$( document )
|
2016-08-31 13:42:23 +00:00
|
|
|
.on( 'mouseenter', '.mw-revslider-revision-tooltip', function () {
|
2016-06-24 13:13:20 +00:00
|
|
|
window.clearTimeout( self.tooltipTimeout );
|
|
|
|
} )
|
2016-08-31 13:42:23 +00:00
|
|
|
.on( 'mouseleave', '.mw-revslider-revision-tooltip', function () {
|
2016-08-03 12:08:05 +00:00
|
|
|
self.hideTooltip( self.$highlightedRevisionWrapper );
|
2016-06-24 13:13:20 +00:00
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* Generates the HTML for a tooltip that appears on hover above each revision on the slider
|
|
|
|
*
|
|
|
|
* @param {Revision} rev
|
2016-08-03 12:08:05 +00:00
|
|
|
* @return {OO.ui.PopupWidget}
|
2016-06-17 13:06:12 +00:00
|
|
|
*/
|
2016-05-12 11:31:08 +00:00
|
|
|
makeTooltip: function ( rev ) {
|
2016-05-30 10:06:44 +00:00
|
|
|
var $tooltip = $( '<div>' )
|
2016-05-26 13:21:42 +00:00
|
|
|
.append(
|
2016-06-15 11:56:10 +00:00
|
|
|
$( '<p>' ).append(
|
2016-07-26 17:02:31 +00:00
|
|
|
$( '<strong>' ).text( mw.msg( 'revisionslider-label-date' ) + mw.msg( 'colon-separator' ) ),
|
|
|
|
rev.getFormattedDate()
|
2016-06-15 11:56:10 +00:00
|
|
|
),
|
2016-07-25 13:35:41 +00:00
|
|
|
this.makeUserLine( rev.getUser(), rev.getUserGender() ),
|
2016-05-30 12:36:48 +00:00
|
|
|
this.makeCommentLine( rev ),
|
2016-06-29 10:43:46 +00:00
|
|
|
this.makePageSizeLine( rev.getSize() ),
|
|
|
|
this.makeChangeSizeLine( rev.getRelativeSize() ),
|
|
|
|
rev.isMinor() ? $( '<p>' ).text( mw.message( 'revisionslider-minoredit' ).text() ) : ''
|
|
|
|
);
|
2016-08-03 12:08:05 +00:00
|
|
|
return new OO.ui.PopupWidget( {
|
|
|
|
$content: $tooltip,
|
|
|
|
padded: true,
|
|
|
|
classes: [ 'mw-revslider-tooltip', 'mw-revslider-revision-tooltip' ]
|
|
|
|
} );
|
2016-05-30 12:36:48 +00:00
|
|
|
},
|
|
|
|
|
2016-06-30 12:27:16 +00:00
|
|
|
/**
|
|
|
|
* Generates a link to user page or to contributions page for IP addresses
|
|
|
|
*
|
|
|
|
* @param {string} user
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
getUserPage: function ( user ) {
|
2016-07-26 08:24:44 +00:00
|
|
|
return ( mw.util.isIPAddress( user, false ) ? 'Special:Contributions/' : 'User:' ) + this.stripInvalidCharacters( user );
|
2016-06-30 11:13:44 +00:00
|
|
|
},
|
|
|
|
|
2016-06-29 10:43:46 +00:00
|
|
|
/**
|
|
|
|
* Generates the HTML for the user label
|
|
|
|
*
|
|
|
|
* @param {string} userString
|
2016-07-25 13:35:41 +00:00
|
|
|
* @param {string} userGender
|
2016-06-29 10:43:46 +00:00
|
|
|
* @return {string|jQuery}
|
|
|
|
*/
|
2016-07-25 13:35:41 +00:00
|
|
|
makeUserLine: function ( userString, userGender ) {
|
2016-06-29 10:43:46 +00:00
|
|
|
if ( !userString ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2016-07-25 13:35:41 +00:00
|
|
|
if ( !userGender ) {
|
|
|
|
userGender = 'unknown';
|
|
|
|
}
|
2016-07-26 09:03:08 +00:00
|
|
|
return $( '<p>' ).append(
|
2016-07-26 17:02:31 +00:00
|
|
|
$( '<strong>' ).text( mw.msg( 'revisionslider-label-username', userGender ) + mw.msg( 'colon-separator' ) ),
|
2016-07-26 09:03:08 +00:00
|
|
|
$( '<bdi>' ).append(
|
|
|
|
$( '<a>' ).addClass( 'mw-userlink' ).attr( 'href', mw.util.getUrl( this.getUserPage( userString ) ) ).text( this.stripInvalidCharacters( userString ) )
|
|
|
|
)
|
|
|
|
);
|
2016-06-29 10:43:46 +00:00
|
|
|
},
|
|
|
|
|
2016-07-26 08:24:44 +00:00
|
|
|
/**
|
|
|
|
* @param {string} s
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
stripInvalidCharacters: function ( s ) {
|
|
|
|
return s.replace( /[<>&]/g, '' );
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* Generates the HTML for the comment label
|
|
|
|
*
|
|
|
|
* @param {Revision} rev
|
|
|
|
* @return {string|jQuery}
|
|
|
|
*/
|
2016-05-30 12:36:48 +00:00
|
|
|
makeCommentLine: function ( rev ) {
|
|
|
|
if ( rev.hasEmptyComment() ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2016-07-26 09:03:08 +00:00
|
|
|
return $( '<p>' ).append(
|
|
|
|
$( '<strong>' ).text( mw.msg( 'revisionslider-label-comment' ) + mw.msg( 'colon-separator' ) ),
|
|
|
|
$( '<em>' ).append(
|
|
|
|
$( '<bdi>' ).append(
|
2016-06-15 11:56:10 +00:00
|
|
|
rev.getParsedComment()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2016-06-29 10:43:46 +00:00
|
|
|
/**
|
|
|
|
* Generates the HTML for the page size label
|
|
|
|
*
|
2016-07-04 21:58:22 +00:00
|
|
|
* @param {number} size
|
2016-06-29 10:43:46 +00:00
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
|
|
|
makePageSizeLine: function ( size ) {
|
|
|
|
return $( '<p>' ).append(
|
2016-07-26 17:02:31 +00:00
|
|
|
$( '<strong>' ).text( mw.msg( 'revisionslider-label-page-size' ) + mw.msg( 'colon-separator' ) ),
|
2016-07-28 12:49:12 +00:00
|
|
|
mw.msg( 'revisionslider-page-size', mw.language.convertNumber( size ), size )
|
2016-06-29 10:43:46 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the HTML for the change size label
|
|
|
|
*
|
2016-07-04 21:58:22 +00:00
|
|
|
* @param {number} relativeSize
|
2016-06-29 10:43:46 +00:00
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
|
|
|
makeChangeSizeLine: function ( relativeSize ) {
|
2016-07-01 10:13:53 +00:00
|
|
|
var changeSizeClass = 'mw-revslider-change-none',
|
2016-06-15 11:56:10 +00:00
|
|
|
leadingSign = '',
|
|
|
|
$changeNumber;
|
|
|
|
|
2016-06-29 10:43:46 +00:00
|
|
|
if ( relativeSize > 0 ) {
|
2016-07-01 10:13:53 +00:00
|
|
|
changeSizeClass = 'mw-revslider-change-positive';
|
2016-06-15 11:56:10 +00:00
|
|
|
leadingSign = '+';
|
2016-06-29 10:43:46 +00:00
|
|
|
} else if ( relativeSize < 0 ) {
|
2016-07-01 10:13:53 +00:00
|
|
|
changeSizeClass = 'mw-revslider-change-negative';
|
2016-06-15 11:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$changeNumber = $( '<span>' )
|
|
|
|
.addClass( changeSizeClass )
|
2016-07-16 18:56:57 +00:00
|
|
|
.attr( {
|
|
|
|
dir: 'ltr' // Make sure that minus/plus is on the left
|
|
|
|
} )
|
2016-06-29 10:43:46 +00:00
|
|
|
.text( leadingSign + mw.language.convertNumber( relativeSize ) );
|
2016-06-15 11:56:10 +00:00
|
|
|
|
|
|
|
return $( '<p>' ).append(
|
2016-07-26 17:02:31 +00:00
|
|
|
$( '<strong>' ).text( mw.msg( 'revisionslider-label-change-size' ) + mw.msg( 'colon-separator' ) ),
|
2016-07-28 12:49:12 +00:00
|
|
|
mw.message( 'revisionslider-change-size', $changeNumber, relativeSize, Math.abs( relativeSize ) ).parse()
|
2016-05-30 12:36:48 +00:00
|
|
|
);
|
2016-05-10 12:42:05 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
mw.libs.revisionSlider = mw.libs.revisionSlider || {};
|
|
|
|
mw.libs.revisionSlider.RevisionListView = RevisionListView;
|
|
|
|
}( mediaWiki, jQuery ) );
|