mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RevisionSlider
synced 2024-11-15 19:49:30 +00:00
980f2ca917
* threw out most of the things from init.js * turned Slider + View into respective modules * pointers should remember position (except on page load) and correctly slide back to their position/to the side Some things still need testing and refactoring. Addshore: - CS fixes and comment out current failing tests Bug: T134395 Change-Id: I78a7095e1d9902314163b1443448f47ef0484d4e
61 lines
1.9 KiB
JavaScript
61 lines
1.9 KiB
JavaScript
( function ( mw, $ ) {
|
|
var RevisionListView = function ( revisionList ) {
|
|
this.revisionList = revisionList;
|
|
};
|
|
|
|
$.extend( RevisionListView.prototype, {
|
|
/**
|
|
* @type {RevisionList}
|
|
*/
|
|
revisionList: null,
|
|
|
|
render: function ( revisionTickWidth ) {
|
|
var $html = $( '<div class="revisions"/>' ),
|
|
revs = this.revisionList.getRevisions(),
|
|
maxChangeSizeLogged = Math.log( this.revisionList.getBiggestChangeSize() ),
|
|
i, diffSize, $tooltip, relativeChangeSize;
|
|
|
|
for ( i = 1; i < revs.length; i++ ) {
|
|
diffSize = revs[ i ].getSize() - revs[ i - 1 ].getSize();
|
|
relativeChangeSize = Math.ceil( 65.0 * Math.log( Math.abs( diffSize ) ) / maxChangeSizeLogged ) + 5;
|
|
$tooltip = this.makeTooltip( revs[ i ], diffSize );
|
|
|
|
$html
|
|
.append( $( '<div class="revision" title="' + $tooltip + '"/>' )
|
|
.css( {
|
|
left: revisionTickWidth * ( i - 1 ) + 'px',
|
|
height: relativeChangeSize + 'px',
|
|
width: revisionTickWidth + 'px',
|
|
top: diffSize > 0 ? '-' + relativeChangeSize + 'px' : 0,
|
|
background: false || 'black' // TODO: put rainbow thingy here
|
|
} )
|
|
.tipsy( {
|
|
gravity: 's',
|
|
html: true,
|
|
fade: true
|
|
} ) )
|
|
.append( $( '<div class="stopper"/>' )
|
|
.css( {
|
|
left: revisionTickWidth * ( i - 1 ) + 'px',
|
|
width: revisionTickWidth + 'px'
|
|
} ) );
|
|
}
|
|
|
|
return $html;
|
|
},
|
|
|
|
makeTooltip: function ( rev, diffSize ) {
|
|
var $tooltip = $( '<center/>' ) // TODO: center is deprecated since 1995
|
|
.append( '<p><b>' + rev.getFormattedDate() + '</b></p>' )
|
|
.append( $( '<p/>' ).text( mw.html.escape( rev.getUser() ) ) )
|
|
.append( rev.getComment() ? '<p><i>' + rev.getComment() + '</i></p>' : '' )
|
|
.append( $( '<p/>' ).text( diffSize + ' byte' ) );
|
|
|
|
return $( '<div/>' ).append( $tooltip ).html();
|
|
}
|
|
} );
|
|
|
|
mw.libs.revisionSlider = mw.libs.revisionSlider || {};
|
|
mw.libs.revisionSlider.RevisionListView = RevisionListView;
|
|
}( mediaWiki, jQuery ) );
|