2023-06-22 09:41:37 +00:00
|
|
|
const Settings = require( 'ext.RevisionSlider.Settings' ),
|
2020-11-18 09:11:12 +00:00
|
|
|
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
|
|
|
toggleButton = OO.ui.ButtonWidget.static.infuse( $( '.mw-revslider-toggle-button' ) );
|
2023-06-22 09:41:37 +00:00
|
|
|
let autoExpand = settings.shouldAutoExpand();
|
|
|
|
let expanded = autoExpand;
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
function initialize() {
|
2023-06-22 09:41:37 +00:00
|
|
|
const startTime = mw.now();
|
|
|
|
const api = new RevisionSliderApi( mw.util.wikiScript( 'api' ) );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
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 ) {
|
2023-10-24 14:08:50 +00:00
|
|
|
const changeTags = data && data.query && data.query.tags || [];
|
2020-11-18 09:11:12 +00:00
|
|
|
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 {
|
2023-06-22 09:41:37 +00:00
|
|
|
const revs = data2.revisions;
|
2020-11-18 09:11:12 +00:00
|
|
|
revs.reverse();
|
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
const $container = $( '.mw-revslider-slider-wrapper' );
|
2020-11-18 09:11:12 +00:00
|
|
|
$container.attr( 'id', 'mw-revslider-slider-wrapper' );
|
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
const revisionList = new SliderModule.RevisionList(
|
2020-11-20 10:31:12 +00:00
|
|
|
SliderModule.makeRevisions( revs ),
|
2020-11-18 09:11:12 +00:00
|
|
|
changeTags
|
|
|
|
);
|
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
const 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' )
|
2023-04-21 06:35:27 +00:00
|
|
|
.text( mw.msg( 'revisionslider-loading-failed' ) );
|
2020-11-12 18:48:39 +00:00
|
|
|
mw.log.error( err );
|
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.error.init' );
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
|
|
|
}, function ( err ) {
|
|
|
|
$( '.mw-revslider-placeholder' )
|
2023-04-21 06:35:27 +00:00
|
|
|
.text( mw.msg( 'revisionslider-loading-failed' ) );
|
2020-11-18 09:11:12 +00:00
|
|
|
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() {
|
2023-04-21 06:35:27 +00:00
|
|
|
toggleButton.setTitle( mw.msg( 'revisionslider-toggle-title-collapse' ) );
|
2020-11-18 09:11:12 +00:00
|
|
|
$( '.mw-revslider-container' ).removeClass( 'mw-revslider-container-collapsed' )
|
|
|
|
.addClass( 'mw-revslider-container-expanded' );
|
2023-08-25 15:49:59 +00:00
|
|
|
$( '.mw-revslider-slider-wrapper, .mw-revslider-auto-expand-button' ).show();
|
2020-11-18 09:11:12 +00:00
|
|
|
toggleButton.$element.children().attr( 'aria-expanded', 'true' );
|
|
|
|
expanded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function collapse() {
|
2023-04-21 06:35:27 +00:00
|
|
|
toggleButton.setTitle( mw.msg( 'revisionslider-toggle-title-expand' ) );
|
2020-11-18 09:11:12 +00:00
|
|
|
$( '.mw-revslider-container' ).removeClass( 'mw-revslider-container-expanded' )
|
|
|
|
.addClass( 'mw-revslider-container-collapsed' );
|
2023-08-25 15:49:59 +00:00
|
|
|
$( '.mw-revslider-slider-wrapper, .mw-revslider-auto-expand-button' ).hide();
|
2020-11-18 09:11:12 +00:00
|
|
|
toggleButton.$element.children().attr( 'aria-expanded', 'false' );
|
|
|
|
}
|
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
const 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();
|