2020-11-18 09:11:12 +00:00
|
|
|
var Settings = require( 'ext.RevisionSlider.Settings' ),
|
|
|
|
settings = new Settings(),
|
2020-03-29 20:36:10 +00:00
|
|
|
SliderModule = require( 'ext.RevisionSlider.Slider' ),
|
2020-11-20 09:27:07 +00:00
|
|
|
HelpDialog = SliderModule.HelpDialog,
|
2020-03-29 20:36:10 +00:00
|
|
|
RevisionSliderApi = SliderModule.Api,
|
|
|
|
Slider = SliderModule.Slider,
|
|
|
|
utils = SliderModule.utils,
|
2020-11-18 09:11:12 +00:00
|
|
|
autoExpand = settings.shouldAutoExpand(),
|
|
|
|
expanded = autoExpand,
|
|
|
|
toggleButton = OO.ui.ButtonWidget.static.infuse( $( '.mw-revslider-toggle-button' ) );
|
|
|
|
|
|
|
|
function initialize() {
|
|
|
|
var startTime = mw.now(),
|
2020-03-29 20:36:10 +00:00
|
|
|
api = new RevisionSliderApi( mw.util.wikiScript( 'api' ) ),
|
2020-11-18 09:11:12 +00:00
|
|
|
changeTags = [];
|
|
|
|
|
|
|
|
toggleButton.$element.children().attr( {
|
|
|
|
'aria-expanded': autoExpand,
|
|
|
|
'aria-controls': 'mw-revslider-slider-wrapper'
|
|
|
|
} );
|
2020-11-12 18:48:39 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.event.init' );
|
2020-11-20 10:31:12 +00:00
|
|
|
SliderModule.setUserOffset(
|
2020-03-29 21:15:32 +00:00
|
|
|
mw.user.options.get( 'timecorrection' ) ?
|
|
|
|
mw.user.options.get( 'timecorrection' ).split( '|' )[ 1 ] :
|
|
|
|
mw.config.get( 'extRevisionSliderTimeOffset' )
|
|
|
|
);
|
2020-11-12 18:48:39 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
HelpDialog.init();
|
2020-11-12 18:48:39 +00:00
|
|
|
|
2020-11-18 09:11:12 +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' ), {
|
2022-09-09 09:18:10 +00:00
|
|
|
startId: Math.max( mw.config.get( 'wgDiffOldId' ), mw.config.get( 'wgDiffNewId' ) ),
|
2020-03-29 20:36:10 +00:00
|
|
|
limit: utils.calculateRevisionsPerWindow( 160, 16 ),
|
2020-11-18 09:11:12 +00:00
|
|
|
changeTags: changeTags
|
|
|
|
} ).then( function ( data2 ) {
|
|
|
|
mw.track( 'timing.MediaWiki.RevisionSlider.timing.initFetchRevisionData', mw.now() - startTime );
|
|
|
|
|
|
|
|
try {
|
2021-10-07 13:55:44 +00:00
|
|
|
var revs = data2.revisions;
|
2020-11-18 09:11:12 +00:00
|
|
|
revs.reverse();
|
|
|
|
|
2021-10-07 13:55:44 +00:00
|
|
|
var $container = $( '.mw-revslider-slider-wrapper' );
|
2020-11-18 09:11:12 +00:00
|
|
|
$container.attr( 'id', 'mw-revslider-slider-wrapper' );
|
|
|
|
|
2020-11-20 10:31:12 +00:00
|
|
|
var revisionList = new SliderModule.RevisionList(
|
|
|
|
SliderModule.makeRevisions( revs ),
|
2020-11-18 09:11:12 +00:00
|
|
|
changeTags
|
|
|
|
);
|
|
|
|
revisionList.getView().setDir( $container.css( 'direction' ) || 'ltr' );
|
|
|
|
|
2021-10-07 13:55:44 +00:00
|
|
|
var slider = new Slider( revisionList );
|
2020-11-18 09:11:12 +00:00
|
|
|
slider.getView().render( $container );
|
|
|
|
|
|
|
|
$( window ).on( 'resize', OO.ui.throttle( function () {
|
2020-11-12 18:48:39 +00:00
|
|
|
slider.getView().render( $container );
|
2020-11-18 09:11:12 +00:00
|
|
|
}, 250 ) );
|
2020-11-12 18:48:39 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( !settings.shouldHideHelpDialogue() ) {
|
|
|
|
HelpDialog.show();
|
|
|
|
settings.setHideHelpDialogue( true );
|
2020-11-12 18:48:39 +00:00
|
|
|
}
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
$( '.mw-revslider-placeholder' ).remove();
|
|
|
|
mw.track( 'timing.MediaWiki.RevisionSlider.timing.init', mw.now() - startTime );
|
|
|
|
} catch ( err ) {
|
2020-11-12 18:48:39 +00:00
|
|
|
$( '.mw-revslider-placeholder' )
|
|
|
|
.text( mw.message( 'revisionslider-loading-failed' ).text() );
|
|
|
|
mw.log.error( err );
|
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.error.init' );
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
|
|
|
}, function ( err ) {
|
|
|
|
$( '.mw-revslider-placeholder' )
|
|
|
|
.text( mw.message( 'revisionslider-loading-failed' ).text() );
|
|
|
|
mw.log.error( err );
|
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.error.init' );
|
2020-11-12 18:48:39 +00:00
|
|
|
} );
|
2016-10-20 14:35:13 +00:00
|
|
|
} );
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function expand() {
|
|
|
|
toggleButton.setTitle( mw.message( 'revisionslider-toggle-title-collapse' ).text() );
|
|
|
|
$( '.mw-revslider-container' ).removeClass( 'mw-revslider-container-collapsed' )
|
|
|
|
.addClass( 'mw-revslider-container-expanded' );
|
|
|
|
$( '.mw-revslider-slider-wrapper' ).show();
|
|
|
|
$( '.mw-revslider-auto-expand-button' ).show();
|
|
|
|
toggleButton.$element.children().attr( 'aria-expanded', 'true' );
|
|
|
|
expanded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function collapse() {
|
|
|
|
toggleButton.setTitle( mw.message( 'revisionslider-toggle-title-expand' ).text() );
|
|
|
|
$( '.mw-revslider-container' ).removeClass( 'mw-revslider-container-expanded' )
|
|
|
|
.addClass( 'mw-revslider-container-collapsed' );
|
|
|
|
$( '.mw-revslider-slider-wrapper' ).hide();
|
|
|
|
$( '.mw-revslider-auto-expand-button' ).hide();
|
|
|
|
toggleButton.$element.children().attr( 'aria-expanded', 'false' );
|
|
|
|
}
|
|
|
|
|
2021-10-07 13:55:44 +00:00
|
|
|
var autoExpandButton = new OO.ui.ToggleButtonWidget( {
|
2020-11-18 09:11:12 +00:00
|
|
|
icon: 'pushPin',
|
|
|
|
classes: [ 'mw-revslider-auto-expand-button' ],
|
|
|
|
title: mw.msg( autoExpand ?
|
|
|
|
'revisionslider-turn-off-auto-expand-title' :
|
|
|
|
'revisionslider-turn-on-auto-expand-title'
|
|
|
|
),
|
|
|
|
value: autoExpand
|
|
|
|
} );
|
|
|
|
|
|
|
|
autoExpandButton.$element.children().attr(
|
|
|
|
'aria-label',
|
|
|
|
mw.msg( autoExpand ?
|
|
|
|
'revisionslider-turn-off-auto-expand-title' :
|
|
|
|
'revisionslider-turn-on-auto-expand-title'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
autoExpandButton.connect( this, {
|
|
|
|
click: function () {
|
|
|
|
autoExpand = !autoExpand;
|
|
|
|
settings.setAutoExpand( autoExpand );
|
|
|
|
if ( autoExpand ) {
|
|
|
|
autoExpandButton.setTitle( mw.msg( 'revisionslider-turn-off-auto-expand-title' ) );
|
|
|
|
autoExpandButton.$element.children().attr(
|
|
|
|
'aria-label', mw.msg( 'revisionslider-turn-off-auto-expand-title' )
|
|
|
|
);
|
|
|
|
expand();
|
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.event.autoexpand_on' );
|
|
|
|
} else {
|
|
|
|
autoExpandButton.setTitle( mw.msg( 'revisionslider-turn-on-auto-expand-title' ) );
|
|
|
|
autoExpandButton.$element.children().attr(
|
|
|
|
'aria-label', mw.msg( 'revisionslider-turn-on-auto-expand-title' )
|
|
|
|
);
|
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.event.autoexpand_off' );
|
2016-10-20 14:35:13 +00:00
|
|
|
}
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( '.mw-revslider-container' ).append( autoExpandButton.$element );
|
|
|
|
|
|
|
|
toggleButton.connect( this, {
|
|
|
|
click: function () {
|
|
|
|
expanded = !expanded;
|
|
|
|
if ( expanded ) {
|
|
|
|
expand();
|
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.event.expand' );
|
|
|
|
mw.hook( 'revslider.expand' ).fire();
|
|
|
|
} else {
|
|
|
|
collapse();
|
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.event.collapse' );
|
|
|
|
mw.hook( 'revslider.collapse' ).fire();
|
2016-06-02 16:14:34 +00:00
|
|
|
}
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
|
|
|
} );
|
2016-11-23 18:43:31 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
expand();
|
|
|
|
initialize();
|