2018-11-16 16:33:52 +00:00
|
|
|
( function () {
|
2016-11-02 18:22:40 +00:00
|
|
|
/**
|
|
|
|
* Module containing presentation logic for the revision pointer lines
|
|
|
|
*
|
|
|
|
* @param {Pointer} pointer
|
|
|
|
* @param {string} name
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
var PointerLine = function ( pointer, name ) {
|
|
|
|
this.pointer = pointer;
|
|
|
|
this.name = name;
|
|
|
|
};
|
|
|
|
|
2020-01-24 16:21:23 +00:00
|
|
|
/**
|
|
|
|
* @class mw.libs.revisionSlider.PointerLine
|
|
|
|
*/
|
2016-11-02 18:22:40 +00:00
|
|
|
$.extend( PointerLine.prototype, {
|
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
name: '',
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {Pointer}
|
|
|
|
*/
|
|
|
|
pointer: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {jQuery}
|
|
|
|
*/
|
|
|
|
$html: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the offset method is available for the diff element
|
|
|
|
*
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
offsetNotAvailable: function () {
|
|
|
|
return typeof $( '.diff-ntitle' ).offset() === 'undefined';
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the relative distance in between the given pointer and column
|
|
|
|
*
|
|
|
|
* @param {jQuery} $sourcePointer
|
|
|
|
* @param {jQuery} $targetColumn
|
|
|
|
*
|
|
|
|
* @return {int} distance between the given elements
|
|
|
|
*/
|
|
|
|
calculateDistance: function ( $sourcePointer, $targetColumn ) {
|
|
|
|
return ( $targetColumn.offset().left + $targetColumn.width() / 2 ) -
|
2017-03-31 15:15:03 +00:00
|
|
|
( $sourcePointer.offset().left + ( $sourcePointer.width() ) / 2 );
|
2016-11-02 18:22:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate and set line's width and position with the given pointer and column
|
|
|
|
*
|
|
|
|
* @param {jQuery} $sourcePointer
|
|
|
|
* @param {jQuery} $targetColumn
|
|
|
|
*/
|
|
|
|
setCssProperties: function ( $sourcePointer, $targetColumn ) {
|
|
|
|
var distance, widthToSet, leftToSet;
|
|
|
|
|
|
|
|
distance = this.calculateDistance( $sourcePointer, $targetColumn );
|
|
|
|
|
|
|
|
widthToSet = Math.abs( distance );
|
|
|
|
leftToSet = ( $targetColumn.offset().left + $targetColumn.width() / 2 ) -
|
|
|
|
$( '.mw-revslider-revision-slider' ).offset().left;
|
|
|
|
|
2017-03-31 15:15:03 +00:00
|
|
|
if ( distance > 0 ) {
|
2016-11-02 18:22:40 +00:00
|
|
|
// targetColumn is right relative to sourcePointer
|
|
|
|
leftToSet -= widthToSet;
|
2017-03-31 15:15:03 +00:00
|
|
|
leftToSet -= 1;
|
|
|
|
} else {
|
|
|
|
// targetColumn is left relative to sourcePointer
|
|
|
|
leftToSet += 1;
|
2016-11-02 18:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.$html.css( {
|
|
|
|
width: widthToSet + 'px',
|
|
|
|
left: leftToSet + 'px'
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the target column is located right form the source pointer
|
|
|
|
*
|
|
|
|
* @param {jQuery} $sourcePointer
|
|
|
|
* @param {jQuery} $targetColumn
|
|
|
|
*
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
targetColumnIsRightFromPointer: function ( $sourcePointer, $targetColumn ) {
|
|
|
|
return this.calculateDistance( $sourcePointer, $targetColumn ) > 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws the line between pointer and column by setting borders, position and width of the line box
|
|
|
|
*
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
drawLine: function () {
|
|
|
|
var $upperLineDiv = this.$html.find( '.mw-revslider-pointer-line-upper' ),
|
|
|
|
$lowerLineDiv = this.$html.find( '.mw-revslider-pointer-line-lower' ),
|
2016-12-16 13:13:00 +00:00
|
|
|
$newerUnderLineDiv = this.$html.find( '.mw-revslider-pointer-line-underline' )
|
|
|
|
.filter( '.mw-revslider-pointer-newer' ),
|
|
|
|
$olderUnderLineDiv = this.$html.find( '.mw-revslider-pointer-line-underline' )
|
|
|
|
.filter( '.mw-revslider-pointer-older' ),
|
2016-11-02 18:22:40 +00:00
|
|
|
$sourcePointer = this.pointer.getView().getElement(),
|
2016-12-16 13:13:00 +00:00
|
|
|
$table = $( '.diff-otitle' ),
|
2016-11-02 18:22:40 +00:00
|
|
|
$targetColumn;
|
|
|
|
|
|
|
|
if ( this.offsetNotAvailable() ) {
|
|
|
|
// offset is not available in QUnit tests so skip calculation and drawing
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-11 08:17:24 +00:00
|
|
|
if ( this.pointer.getView().isNewerPointer() ) {
|
2016-11-02 18:22:40 +00:00
|
|
|
$lowerLineDiv.removeClass( 'mw-revslider-lower-color' ).addClass( 'mw-revslider-upper-color' );
|
|
|
|
$upperLineDiv.removeClass( 'mw-revslider-lower-color' ).addClass( 'mw-revslider-upper-color' );
|
2016-12-16 13:13:00 +00:00
|
|
|
$newerUnderLineDiv.removeClass( 'mw-revslider-lower-color' ).addClass( 'mw-revslider-upper-color' );
|
|
|
|
$olderUnderLineDiv.removeClass( 'mw-revslider-lower-color' ).addClass( 'mw-revslider-upper-color' );
|
2016-11-16 00:48:33 +00:00
|
|
|
$targetColumn = $( '.diff-ntitle' );
|
2016-11-02 18:22:40 +00:00
|
|
|
} else {
|
|
|
|
$lowerLineDiv.removeClass( 'mw-revslider-upper-color' ).addClass( 'mw-revslider-lower-color' );
|
|
|
|
$upperLineDiv.removeClass( 'mw-revslider-upper-color' ).addClass( 'mw-revslider-lower-color' );
|
2016-12-16 13:13:00 +00:00
|
|
|
$olderUnderLineDiv.removeClass( 'mw-revslider-upper-color' ).addClass( 'mw-revslider-lower-color' );
|
|
|
|
$newerUnderLineDiv.removeClass( 'mw-revslider-upper-color' ).addClass( 'mw-revslider-lower-color' );
|
2017-07-06 09:49:44 +00:00
|
|
|
$targetColumn = $table;
|
2016-11-02 18:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.setCssProperties( $sourcePointer, $targetColumn );
|
|
|
|
|
|
|
|
$upperLineDiv.addClass( 'mw-revslider-bottom-line' );
|
|
|
|
|
2016-11-16 00:48:33 +00:00
|
|
|
if ( this.targetColumnIsRightFromPointer( $sourcePointer, $targetColumn ) ) {
|
2016-11-02 18:22:40 +00:00
|
|
|
$upperLineDiv.addClass( 'mw-revslider-left-line' );
|
|
|
|
$lowerLineDiv.addClass( 'mw-revslider-right-line' );
|
2016-12-16 13:13:00 +00:00
|
|
|
|
|
|
|
$( $newerUnderLineDiv ).css( {
|
|
|
|
width: $table.width() + 'px',
|
|
|
|
'margin-right': -$table.width() / 2 + 'px',
|
|
|
|
'margin-left': 0,
|
2019-02-10 16:54:28 +00:00
|
|
|
float: 'right'
|
2016-12-16 13:13:00 +00:00
|
|
|
} );
|
|
|
|
$( $olderUnderLineDiv ).css( {
|
|
|
|
width: $table.width() + 'px',
|
|
|
|
'margin-right': -$table.width() / 2 + 'px',
|
|
|
|
'margin-left': 0,
|
2019-02-10 16:54:28 +00:00
|
|
|
float: 'right'
|
2016-12-16 13:13:00 +00:00
|
|
|
} );
|
2016-11-02 18:22:40 +00:00
|
|
|
} else {
|
|
|
|
$upperLineDiv.addClass( 'mw-revslider-right-line' );
|
|
|
|
$lowerLineDiv.addClass( 'mw-revslider-left-line' );
|
2016-12-16 13:13:00 +00:00
|
|
|
|
|
|
|
$( $newerUnderLineDiv ).css( {
|
|
|
|
width: $table.width() + 'px',
|
|
|
|
'margin-left': -$table.width() / 2 + 'px',
|
|
|
|
'margin-right': 0,
|
2019-02-10 16:54:28 +00:00
|
|
|
float: 'left'
|
2016-12-16 13:13:00 +00:00
|
|
|
} );
|
|
|
|
$( $olderUnderLineDiv ).css( {
|
|
|
|
width: $table.width() + 'px',
|
|
|
|
'margin-left': -$table.width() / 2 + 'px',
|
|
|
|
'margin-right': 0,
|
2019-02-10 16:54:28 +00:00
|
|
|
float: 'left'
|
2016-12-16 13:13:00 +00:00
|
|
|
} );
|
2016-11-02 18:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the DOM element with the line-box for drawing the lines
|
|
|
|
*/
|
|
|
|
initialize: function () {
|
|
|
|
this.$html = $( '<div>' )
|
|
|
|
.addClass( 'mw-revslider-pointer-line ' + this.name )
|
|
|
|
.append(
|
|
|
|
$( '<div>' ).addClass( 'mw-revslider-pointer-line-upper ' + this.name ),
|
2016-12-16 13:13:00 +00:00
|
|
|
$( '<div>' ).addClass( 'mw-revslider-pointer-line-lower ' + this.name ),
|
|
|
|
$( '<div>' ).addClass( 'mw-revslider-pointer-line-underline ' + this.name )
|
2016-11-02 18:22:40 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds colored top-borders for the diff columns fitting the line colors between pointers and columns
|
|
|
|
*/
|
|
|
|
addColoredColumnBorders: function () {
|
|
|
|
$( '#mw-diff-otitle1' ).addClass( 'mw-revslider-older-diff-column' );
|
|
|
|
$( '#mw-diff-ntitle1' ).addClass( 'mw-revslider-newer-diff-column' );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove colored top-borders for the diff columns fitting the line colors between pointers and columns
|
|
|
|
*/
|
|
|
|
removeColoredColumnBorders: function () {
|
|
|
|
$( '#mw-diff-otitle1' ).removeClass( 'mw-revslider-older-diff-column' );
|
|
|
|
$( '#mw-diff-ntitle1' ).removeClass( 'mw-revslider-newer-diff-column' );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the hooks to draw the column borders
|
|
|
|
*/
|
|
|
|
setColumnBorderHooks: function () {
|
|
|
|
mw.hook( 'wikipage.diff' ).add( this.addColoredColumnBorders );
|
|
|
|
mw.hook( 'revslider.expand' ).add( this.addColoredColumnBorders );
|
|
|
|
mw.hook( 'revslider.collapse' ).add( this.removeColoredColumnBorders );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
|
|
|
render: function () {
|
|
|
|
this.initialize();
|
|
|
|
this.setColumnBorderHooks();
|
|
|
|
return this.getElement();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
|
|
|
getElement: function () {
|
|
|
|
return this.$html;
|
|
|
|
}
|
2016-12-16 13:13:00 +00:00
|
|
|
|
2016-11-02 18:22:40 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
mw.libs.revisionSlider = mw.libs.revisionSlider || {};
|
|
|
|
mw.libs.revisionSlider.PointerLine = PointerLine;
|
2018-11-16 16:33:52 +00:00
|
|
|
}() );
|