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-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,
|
|
|
|
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>' )
|
2016-07-01 10:13:53 +00:00
|
|
|
.addClass( 'mw-revslider-revision-wrapper' )
|
2016-05-30 10:06:44 +00:00
|
|
|
.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-07-04 16:26:13 +00:00
|
|
|
className: 'mw-revslider-revision-tooltip mw-revslider-revision-tooltip-' + ( i + 1 )
|
2016-05-18 14:55:39 +00:00
|
|
|
} )
|
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() )
|
|
|
|
.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-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-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-07-01 10:13:53 +00:00
|
|
|
this.currentTooltip.removeClass( 'mw-revslider-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-07-01 10:13:53 +00:00
|
|
|
$rev.removeClass( 'mw-revslider-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-07-01 10:13:53 +00:00
|
|
|
$rev.addClass( 'mw-revslider-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 )
|
2016-07-01 10:13:53 +00:00
|
|
|
.on( 'mouseover', '.mw-revslider-revision-tooltip', function () {
|
2016-06-24 13:13:20 +00:00
|
|
|
window.clearTimeout( self.tooltipTimeout );
|
|
|
|
} )
|
2016-07-01 10:13:53 +00:00
|
|
|
.on( 'mouseout', '.mw-revslider-revision-tooltip', function () {
|
2016-06-24 13:13:20 +00:00
|
|
|
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-06-29 10:43:46 +00:00
|
|
|
this.makeUserLine( rev.getUser() ),
|
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-05-18 10:45:06 +00:00
|
|
|
return $tooltip.html();
|
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
|
|
|
|
* @return {string|jQuery}
|
|
|
|
*/
|
|
|
|
makeUserLine: function ( userString ) {
|
|
|
|
if ( !userString ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $( '<bdi>' ).append( $( '<p>' ).append(
|
2016-07-26 08:24:44 +00:00
|
|
|
mw.message( 'revisionslider-label-username', this.stripInvalidCharacters( userString ), this.getUserPage( userString ) ).parseDom()
|
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 '';
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
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(
|
|
|
|
mw.message( 'revisionslider-label-page-size', mw.language.convertNumber( size ), size ).parseDom()
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-06-29 10:43:46 +00:00
|
|
|
mw.message( 'revisionslider-label-change-size', $changeNumber, relativeSize ).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 ) );
|