2016-05-10 12:42:05 +00:00
|
|
|
( function ( mw, $ ) {
|
|
|
|
var RevisionListView = function ( revisionList ) {
|
|
|
|
this.revisionList = revisionList;
|
|
|
|
};
|
|
|
|
|
|
|
|
$.extend( RevisionListView.prototype, {
|
|
|
|
/**
|
|
|
|
* @type {RevisionList}
|
|
|
|
*/
|
|
|
|
revisionList: null,
|
|
|
|
|
2016-05-12 11:34:16 +00:00
|
|
|
render: function ( revisionTickWidth ) {
|
2016-05-30 10:06:44 +00:00
|
|
|
var $html = $( '<div>' ).addClass( 'mw-revisions' ),
|
2016-05-10 12:42:05 +00:00
|
|
|
revs = this.revisionList.getRevisions(),
|
|
|
|
maxChangeSizeLogged = Math.log( this.revisionList.getBiggestChangeSize() ),
|
2016-05-30 10:06:44 +00:00
|
|
|
i, diffSize, tooltip, relativeChangeSize;
|
2016-05-10 12:42:05 +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-30 10:06:44 +00:00
|
|
|
tooltip = this.makeTooltip( revs[ i ] );
|
2016-05-10 12:42:05 +00:00
|
|
|
|
|
|
|
$html
|
2016-05-30 10:06:44 +00:00
|
|
|
.append( $( '<div>' )
|
|
|
|
.addClass( 'mw-revision-wrapper' )
|
|
|
|
.attr( 'title', tooltip )
|
2016-05-10 12:42:05 +00:00
|
|
|
.css( {
|
2016-05-12 13:52:54 +00:00
|
|
|
left: revisionTickWidth * i + 'px',
|
2016-05-18 14:55:39 +00:00
|
|
|
width: revisionTickWidth + 'px'
|
2016-05-10 12:42:05 +00:00
|
|
|
} )
|
|
|
|
.tipsy( {
|
|
|
|
gravity: 's',
|
|
|
|
html: true,
|
2016-05-18 10:45:06 +00:00
|
|
|
fade: true,
|
2016-05-30 10:06:44 +00:00
|
|
|
className: 'mw-revision-tooltip'
|
2016-05-18 14:55:39 +00:00
|
|
|
} )
|
2016-05-30 10:06:44 +00:00
|
|
|
.append( $( '<div>' )
|
|
|
|
.addClass( 'mw-revision' )
|
|
|
|
.attr( 'data-revid', revs[ i ].getId() )
|
|
|
|
.attr( 'data-pos', i + 1 )
|
2016-05-18 14:55:39 +00:00
|
|
|
.css( {
|
|
|
|
height: relativeChangeSize + 'px',
|
|
|
|
width: revisionTickWidth + 'px',
|
|
|
|
top: diffSize > 0 ? '-' + relativeChangeSize + 'px' : 0
|
|
|
|
} )
|
2016-05-30 10:06:44 +00:00
|
|
|
.addClass( diffSize > 0 ? 'mw-revision-up' : 'mw-revision-down' )
|
|
|
|
.append( $( '<div>' ).addClass( 'mw-revision-border-box' ) )
|
2016-05-18 14:55:39 +00:00
|
|
|
)
|
2016-05-26 09:50:51 +00:00
|
|
|
);
|
2016-05-10 12:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
},
|
|
|
|
|
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-05-30 10:06:44 +00:00
|
|
|
$( '<p>' ).append( $( '<b>' ).text( rev.getFormattedDate() ) ),
|
2016-05-31 13:06:38 +00:00
|
|
|
rev.getUser() ?
|
|
|
|
$( '<bdi>' ).append( $( '<p>' ).text(
|
|
|
|
mw.msg( 'revisionslider-label-user', mw.html.escape( rev.getUser() ) )
|
|
|
|
) )
|
|
|
|
: '',
|
2016-05-30 12:36:48 +00:00
|
|
|
this.makeCommentLine( rev ),
|
2016-05-30 10:06:44 +00:00
|
|
|
$( '<p>' ).text(
|
|
|
|
mw.msg( 'revisionslider-label-article-size', mw.msg( 'revisionslider-revision-bytes', rev.getSize() ) )
|
|
|
|
),
|
2016-06-01 15:02:07 +00:00
|
|
|
$( '<p>' ).text(
|
|
|
|
mw.msg( 'revisionslider-label-change-size', mw.msg( 'revisionslider-revision-bytes', rev.getRelativeSize() ) )
|
|
|
|
),
|
2016-05-30 10:06:44 +00:00
|
|
|
rev.isMinor() ? $( '<p>' ).text( mw.message( 'minoredit' ).text() ) : '' );
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2016-05-18 10:45:06 +00:00
|
|
|
return $tooltip.html();
|
2016-05-30 12:36:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
makeCommentLine: function ( rev ) {
|
|
|
|
if ( rev.hasEmptyComment() ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $( '<bdi>' ).append(
|
|
|
|
$( '<p>' ).append(
|
|
|
|
$( '<i>' ).html(
|
|
|
|
mw.msg( 'revisionslider-label-comment', rev.getParsedComment() )
|
|
|
|
) )
|
|
|
|
);
|
2016-05-10 12:42:05 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
mw.libs.revisionSlider = mw.libs.revisionSlider || {};
|
|
|
|
mw.libs.revisionSlider.RevisionListView = RevisionListView;
|
|
|
|
}( mediaWiki, jQuery ) );
|