2018-11-16 16:33:52 +00:00
|
|
|
( function () {
|
2016-10-20 14:35:13 +00:00
|
|
|
var settings = new mw.libs.revisionSlider.Settings(),
|
|
|
|
autoExpand = settings.shouldAutoExpand(),
|
2016-08-12 07:35:12 +00:00
|
|
|
expanded = autoExpand,
|
|
|
|
autoExpandButton,
|
2016-07-02 20:14:00 +00:00
|
|
|
toggleButton = OO.ui.ButtonWidget.static.infuse( $( '.mw-revslider-toggle-button' ) ),
|
2017-05-04 20:57:38 +00:00
|
|
|
initialize = function () {
|
2016-08-05 16:14:28 +00:00
|
|
|
var startTime = mw.now(),
|
2018-08-22 08:00:30 +00:00
|
|
|
api = new mw.libs.revisionSlider.Api( mw.util.wikiScript( 'api' ) ),
|
|
|
|
changeTags = [];
|
2016-07-25 13:35:41 +00:00
|
|
|
|
2017-05-19 16:04:00 +00:00
|
|
|
toggleButton.$element.children().attr( {
|
|
|
|
'aria-expanded': autoExpand,
|
|
|
|
'aria-controls': 'mw-revslider-slider-wrapper'
|
|
|
|
} );
|
|
|
|
|
2016-08-05 16:14:28 +00:00
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.event.init' );
|
2016-11-23 00:31:53 +00:00
|
|
|
mw.libs.revisionSlider.userOffset = mw.user.options.get( 'timecorrection' ) ? mw.user.options.get( 'timecorrection' ).split( '|' )[ 1 ] : mw.config.get( 'extRevisionSliderTimeOffset' );
|
2016-07-25 13:35:41 +00:00
|
|
|
|
2016-09-14 15:48:06 +00:00
|
|
|
mw.libs.revisionSlider.HelpDialog.init();
|
|
|
|
|
2018-08-22 08:00:30 +00:00
|
|
|
api.fetchAvailableChangeTags().then( function ( data ) {
|
|
|
|
if ( typeof data === 'object' &&
|
|
|
|
data.query &&
|
|
|
|
data.query.tags &&
|
|
|
|
data.query.tags.length > 0
|
|
|
|
) {
|
|
|
|
changeTags = data.query.tags;
|
|
|
|
}
|
|
|
|
api.fetchRevisionData( mw.config.get( 'wgPageName' ), {
|
|
|
|
startId: mw.config.get( 'wgDiffNewId' ),
|
|
|
|
limit: mw.libs.revisionSlider.calculateRevisionsPerWindow( 160, 16 ),
|
|
|
|
changeTags: changeTags
|
|
|
|
} ).then( function ( data ) {
|
|
|
|
var revs,
|
|
|
|
revisionList,
|
|
|
|
$container,
|
|
|
|
slider;
|
2016-04-19 12:45:09 +00:00
|
|
|
|
2018-08-22 08:00:30 +00:00
|
|
|
mw.track( 'timing.MediaWiki.RevisionSlider.timing.initFetchRevisionData', mw.now() - startTime );
|
2016-08-02 12:01:09 +00:00
|
|
|
|
2018-08-22 08:00:30 +00:00
|
|
|
try {
|
|
|
|
revs = data.revisions;
|
|
|
|
revs.reverse();
|
2017-03-03 13:55:42 +00:00
|
|
|
|
2018-08-22 08:00:30 +00:00
|
|
|
$container = $( '.mw-revslider-slider-wrapper' );
|
|
|
|
$container.attr( 'id', 'mw-revslider-slider-wrapper' );
|
2016-05-11 12:34:27 +00:00
|
|
|
|
2018-08-22 08:00:30 +00:00
|
|
|
revisionList = new mw.libs.revisionSlider.RevisionList( mw.libs.revisionSlider.makeRevisions( revs ) );
|
|
|
|
revisionList.getView().setDir( $container.css( 'direction' ) || 'ltr' );
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2018-08-22 08:00:30 +00:00
|
|
|
slider = new mw.libs.revisionSlider.Slider( revisionList );
|
2016-08-15 15:09:42 +00:00
|
|
|
slider.getView().render( $container );
|
|
|
|
|
2018-08-22 08:00:30 +00:00
|
|
|
$( window ).on( 'resize', OO.ui.throttle( function () {
|
|
|
|
slider.getView().render( $container );
|
|
|
|
}, 250 ) );
|
2016-08-05 16:14:28 +00:00
|
|
|
|
2018-08-22 08:00:30 +00:00
|
|
|
if ( !settings.shouldHideHelpDialogue() ) {
|
|
|
|
mw.libs.revisionSlider.HelpDialog.show();
|
|
|
|
settings.setHideHelpDialogue( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
$( '.mw-revslider-placeholder' ).remove();
|
|
|
|
mw.track( 'timing.MediaWiki.RevisionSlider.timing.init', mw.now() - startTime );
|
|
|
|
} catch ( err ) {
|
|
|
|
$( '.mw-revslider-placeholder' )
|
|
|
|
.text( mw.message( 'revisionslider-loading-failed' ).text() );
|
|
|
|
mw.log.error( err );
|
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.error.init' );
|
|
|
|
}
|
|
|
|
}, function ( err ) {
|
2016-07-02 20:14:00 +00:00
|
|
|
$( '.mw-revslider-placeholder' )
|
2016-08-05 16:14:28 +00:00
|
|
|
.text( mw.message( 'revisionslider-loading-failed' ).text() );
|
2016-11-16 09:00:27 +00:00
|
|
|
mw.log.error( err );
|
2016-08-05 16:14:28 +00:00
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.error.init' );
|
2018-08-22 08:00:30 +00:00
|
|
|
} );
|
2016-08-05 16:14:28 +00:00
|
|
|
} );
|
2016-09-13 13:14:00 +00:00
|
|
|
},
|
|
|
|
|
2016-11-23 18:43:31 +00:00
|
|
|
expand = function () {
|
2018-07-02 22:46:44 +00:00
|
|
|
toggleButton.setTitle( mw.message( 'revisionslider-toggle-title-collapse' ).text() );
|
2016-12-16 13:13:00 +00:00
|
|
|
$( '.mw-revslider-container' ).removeClass( 'mw-revslider-container-collapsed' )
|
|
|
|
.addClass( 'mw-revslider-container-expanded' );
|
2016-09-13 13:14:00 +00:00
|
|
|
$( '.mw-revslider-slider-wrapper' ).show();
|
2018-07-23 15:08:41 +00:00
|
|
|
$( '.mw-revslider-auto-expand-button' ).show();
|
2017-05-19 16:04:00 +00:00
|
|
|
toggleButton.$element.children().attr( 'aria-expanded', 'true' );
|
2016-09-13 13:14:00 +00:00
|
|
|
expanded = true;
|
2016-11-23 18:43:31 +00:00
|
|
|
},
|
2016-04-19 12:45:09 +00:00
|
|
|
|
2016-11-23 18:43:31 +00:00
|
|
|
collapse = function () {
|
2018-07-02 22:46:44 +00:00
|
|
|
toggleButton.setTitle( mw.message( 'revisionslider-toggle-title-expand' ).text() );
|
2016-12-16 13:13:00 +00:00
|
|
|
$( '.mw-revslider-container' ).removeClass( 'mw-revslider-container-expanded' )
|
|
|
|
.addClass( 'mw-revslider-container-collapsed' );
|
2016-11-23 18:43:31 +00:00
|
|
|
$( '.mw-revslider-slider-wrapper' ).hide();
|
2018-07-23 15:08:41 +00:00
|
|
|
$( '.mw-revslider-auto-expand-button' ).hide();
|
2017-05-19 16:04:00 +00:00
|
|
|
toggleButton.$element.children().attr( 'aria-expanded', 'false' );
|
2016-11-23 18:43:31 +00:00
|
|
|
};
|
2016-08-09 16:34:53 +00:00
|
|
|
|
2016-10-20 14:35:13 +00:00
|
|
|
autoExpandButton = new OO.ui.ToggleButtonWidget( {
|
2018-08-30 14:58:19 +00:00
|
|
|
icon: 'pushPin',
|
2016-10-20 14:35:13 +00:00
|
|
|
classes: [ 'mw-revslider-auto-expand-button' ],
|
2017-05-19 16:04:00 +00:00
|
|
|
title: mw.msg( autoExpand ?
|
2016-10-20 14:35:13 +00:00
|
|
|
'revisionslider-turn-off-auto-expand-title' :
|
|
|
|
'revisionslider-turn-on-auto-expand-title'
|
2017-05-19 16:04:00 +00:00
|
|
|
),
|
2016-10-20 14:35:13 +00:00
|
|
|
value: autoExpand
|
|
|
|
} );
|
2018-07-23 15:08:41 +00:00
|
|
|
|
2017-05-19 16:04:00 +00:00
|
|
|
autoExpandButton.$element.children().attr(
|
|
|
|
'aria-label',
|
|
|
|
mw.msg( autoExpand ?
|
2017-07-14 10:28:45 +00:00
|
|
|
'revisionslider-turn-off-auto-expand-title' :
|
|
|
|
'revisionslider-turn-on-auto-expand-title'
|
|
|
|
)
|
|
|
|
);
|
2016-10-20 14:35:13 +00:00
|
|
|
|
|
|
|
autoExpandButton.connect( this, {
|
|
|
|
click: function () {
|
|
|
|
autoExpand = !autoExpand;
|
|
|
|
settings.setAutoExpand( autoExpand );
|
|
|
|
if ( autoExpand ) {
|
2017-05-19 16:04:00 +00:00
|
|
|
autoExpandButton.setTitle( mw.msg( 'revisionslider-turn-off-auto-expand-title' ) );
|
|
|
|
autoExpandButton.$element.children().attr(
|
|
|
|
'aria-label', mw.msg( 'revisionslider-turn-off-auto-expand-title' )
|
|
|
|
);
|
2016-11-23 18:43:31 +00:00
|
|
|
expand();
|
2016-11-17 11:02:26 +00:00
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.event.autoexpand_on' );
|
2016-10-20 14:35:13 +00:00
|
|
|
} else {
|
2017-05-19 16:04:00 +00:00
|
|
|
autoExpandButton.setTitle( mw.msg( 'revisionslider-turn-on-auto-expand-title' ) );
|
|
|
|
autoExpandButton.$element.children().attr(
|
|
|
|
'aria-label', mw.msg( 'revisionslider-turn-on-auto-expand-title' )
|
|
|
|
);
|
2016-11-17 11:02:26 +00:00
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.event.autoexpand_off' );
|
2016-08-12 07:35:12 +00:00
|
|
|
}
|
2016-10-20 14:35:13 +00:00
|
|
|
}
|
|
|
|
} );
|
2016-08-12 07:35:12 +00:00
|
|
|
|
2016-10-20 14:35:13 +00:00
|
|
|
$( '.mw-revslider-container' ).append( autoExpandButton.$element );
|
2016-08-12 07:35:12 +00:00
|
|
|
|
2016-08-05 16:14:28 +00:00
|
|
|
toggleButton.connect( this, {
|
|
|
|
click: function () {
|
|
|
|
expanded = !expanded;
|
|
|
|
if ( expanded ) {
|
2016-11-23 18:43:31 +00:00
|
|
|
expand();
|
2016-08-05 16:14:28 +00:00
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.event.expand' );
|
2016-11-02 18:22:40 +00:00
|
|
|
mw.hook( 'revslider.expand' ).fire();
|
2016-08-05 16:14:28 +00:00
|
|
|
} else {
|
2016-11-23 18:43:31 +00:00
|
|
|
collapse();
|
2016-08-05 16:14:28 +00:00
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.event.collapse' );
|
2016-11-02 18:22:40 +00:00
|
|
|
mw.hook( 'revslider.collapse' ).fire();
|
2016-08-05 16:14:28 +00:00
|
|
|
}
|
2016-06-02 16:14:34 +00:00
|
|
|
}
|
|
|
|
} );
|
2016-11-23 18:43:31 +00:00
|
|
|
|
|
|
|
expand();
|
|
|
|
initialize();
|
|
|
|
|
2018-11-16 16:33:52 +00:00
|
|
|
}() );
|