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-06-24 13:13:20 +00:00
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
tooltipTimeout: -1,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {jQuery}
|
|
|
|
*/
|
|
|
|
currentTooltip: null,
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @param {number} revisionTickWidth
|
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
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-06-24 13:13:20 +00:00
|
|
|
self = this,
|
|
|
|
i, diffSize, tooltip, relativeChangeSize,
|
|
|
|
showTooltip = function () {
|
|
|
|
self.showTooltip( $( this ) );
|
|
|
|
$( this ).tipsy( 'show' );
|
|
|
|
},
|
|
|
|
hideTooltip = function () {
|
|
|
|
self.hideTooltip( $( this ) );
|
|
|
|
};
|
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-21 00:10:08 +00:00
|
|
|
.width( revisionTickWidth )
|
2016-05-10 12:42:05 +00:00
|
|
|
.tipsy( {
|
|
|
|
gravity: 's',
|
|
|
|
html: true,
|
2016-06-24 13:13:20 +00:00
|
|
|
trigger: 'manual',
|
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-06-24 13:13:20 +00:00
|
|
|
.mouseover( showTooltip )
|
|
|
|
.mouseout( 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-24 13:13:20 +00:00
|
|
|
/**
|
|
|
|
* Hides the current tooltip immediately
|
|
|
|
*/
|
|
|
|
hideCurrentTooltip: function () {
|
|
|
|
if ( this.tooltipTimeout !== -1 ) {
|
|
|
|
window.clearTimeout( this.tooltipTimeout );
|
|
|
|
this.currentTooltip.tipsy( 'hide' );
|
2016-06-30 09:52:57 +00:00
|
|
|
this.currentTooltip.removeClass( 'mw-revision-wrapper-hovered' );
|
2016-06-24 13:13:20 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the tooltip after 500ms
|
|
|
|
*
|
|
|
|
* @param {jQuery} $rev
|
|
|
|
*/
|
|
|
|
hideTooltip: function ( $rev ) {
|
|
|
|
this.tooltipTimeout = window.setTimeout( function () {
|
|
|
|
$rev.tipsy( 'hide' );
|
2016-06-30 09:52:57 +00:00
|
|
|
$rev.removeClass( 'mw-revision-wrapper-hovered' );
|
2016-06-24 13:13:20 +00:00
|
|
|
}, 500 );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the previous tooltip and shows the new one
|
|
|
|
*
|
|
|
|
* @param {jQuery} $rev
|
|
|
|
*/
|
|
|
|
showTooltip: function ( $rev ) {
|
|
|
|
this.hideCurrentTooltip();
|
|
|
|
$rev.tipsy( 'show' );
|
2016-06-30 09:52:57 +00:00
|
|
|
$rev.addClass( 'mw-revision-wrapper-hovered' );
|
2016-06-24 13:13:20 +00:00
|
|
|
this.currentTooltip = $rev;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets event handlers on tooltips so they do not disappear when hovering over them
|
|
|
|
*/
|
|
|
|
keepTooltipsOnHover: function () {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
$( document )
|
|
|
|
.on( 'mouseover', '.mw-revision-tooltip', function () {
|
|
|
|
window.clearTimeout( self.tooltipTimeout );
|
|
|
|
} )
|
|
|
|
.on( 'mouseout', '.mw-revision-tooltip', function () {
|
|
|
|
self.hideTooltip( self.currentTooltip );
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
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
|
|
|
|
* @return {string}
|
|
|
|
*/
|
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(
|
|
|
|
mw.message( 'revisionslider-label-date', rev.getFormattedDate() ).parseDom()
|
|
|
|
),
|
2016-05-31 13:06:38 +00:00
|
|
|
rev.getUser() ?
|
2016-06-15 11:56:10 +00:00
|
|
|
$( '<bdi>' ).append( $( '<p>' ).append(
|
2016-06-22 10:17:06 +00:00
|
|
|
mw.message( 'revisionslider-label-username', mw.html.escape( rev.getUser() ) ).parseDom()
|
2016-05-31 13:06:38 +00:00
|
|
|
) )
|
|
|
|
: '',
|
2016-05-30 12:36:48 +00:00
|
|
|
this.makeCommentLine( rev ),
|
2016-06-15 11:56:10 +00:00
|
|
|
$( '<p>' ).append(
|
|
|
|
mw.message( 'revisionslider-label-page-size', mw.language.convertNumber( rev.getSize() ), rev.getSize() ).parseDom()
|
2016-06-01 15:02:07 +00:00
|
|
|
),
|
2016-06-15 11:56:10 +00:00
|
|
|
this.makeChangeSizeLine( rev ),
|
2016-06-28 11:48:25 +00:00
|
|
|
rev.isMinor() ? $( '<p>' ).text( mw.message( 'revisionslider-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
|
|
|
},
|
|
|
|
|
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 '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $( '<bdi>' ).append(
|
|
|
|
$( '<p>' ).append(
|
2016-06-15 11:56:10 +00:00
|
|
|
$( '<strong>' ).text( mw.message( 'revisionslider-label-comment' ).text() ),
|
|
|
|
$( '<em>' ).append(
|
|
|
|
rev.getParsedComment()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
makeChangeSizeLine: function ( rev ) {
|
|
|
|
var changeSizeClass = 'mw-no-change',
|
|
|
|
leadingSign = '',
|
|
|
|
$changeNumber;
|
|
|
|
|
|
|
|
if ( rev.getRelativeSize() > 0 ) {
|
|
|
|
changeSizeClass = 'mw-positive-change';
|
|
|
|
leadingSign = '+';
|
|
|
|
} else if ( rev.getRelativeSize() < 0 ) {
|
|
|
|
changeSizeClass = 'mw-negative-change';
|
|
|
|
}
|
|
|
|
|
|
|
|
$changeNumber = $( '<span>' )
|
|
|
|
.addClass( changeSizeClass )
|
|
|
|
.text( leadingSign + mw.language.convertNumber( rev.getRelativeSize() ) );
|
|
|
|
|
|
|
|
return $( '<p>' ).append(
|
|
|
|
mw.message( 'revisionslider-label-change-size', $changeNumber, rev.getRelativeSize() ).parseDom()
|
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 ) );
|