2016-04-19 12:45:09 +00:00
|
|
|
( function ( mw, $ ) {
|
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,
|
2016-08-05 16:14:28 +00:00
|
|
|
initialized = false,
|
2016-08-12 07:35:12 +00:00
|
|
|
autoExpandButton,
|
2016-07-02 20:14:00 +00:00
|
|
|
toggleButton = OO.ui.ButtonWidget.static.infuse( $( '.mw-revslider-toggle-button' ) ),
|
2016-08-05 16:14:28 +00:00
|
|
|
initialize = function () {
|
|
|
|
var startTime = mw.now(),
|
|
|
|
api = new mw.libs.revisionSlider.Api( mw.util.wikiScript( 'api' ) );
|
2016-07-25 13:35:41 +00:00
|
|
|
|
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();
|
|
|
|
|
2016-08-05 16:14:28 +00:00
|
|
|
api.fetchRevisionData( mw.config.get( 'wgPageName' ), {
|
2016-11-23 00:31:53 +00:00
|
|
|
startId: mw.config.get( 'extRevisionSliderNewRev' ),
|
2016-08-15 18:15:30 +00:00
|
|
|
limit: mw.libs.revisionSlider.calculateRevisionsPerWindow( 160, 16 )
|
|
|
|
} ).then( function ( data ) {
|
|
|
|
var revs,
|
|
|
|
revisionList,
|
|
|
|
$container,
|
|
|
|
slider;
|
2016-04-19 12:45:09 +00:00
|
|
|
|
2016-08-15 18:15:30 +00:00
|
|
|
mw.track( 'timing.MediaWiki.RevisionSlider.timing.initFetchRevisionData', mw.now() - startTime );
|
2016-04-19 12:45:09 +00:00
|
|
|
|
2016-08-15 18:15:30 +00:00
|
|
|
try {
|
|
|
|
revs = data.revisions;
|
|
|
|
revs.reverse();
|
2016-08-02 12:01:09 +00:00
|
|
|
|
2016-08-15 18:15:30 +00:00
|
|
|
revisionList = new mw.libs.revisionSlider.RevisionList( mw.libs.revisionSlider.makeRevisions( revs ) );
|
2016-05-11 12:34:27 +00:00
|
|
|
|
2016-08-15 18:15:30 +00:00
|
|
|
$container = $( '.mw-revslider-slider-wrapper' );
|
|
|
|
slider = new mw.libs.revisionSlider.Slider( revisionList );
|
|
|
|
slider.getView().render( $container );
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2016-10-13 03:28:27 +00:00
|
|
|
$( window ).on( 'resize', OO.ui.throttle( function () {
|
2016-08-15 15:09:42 +00:00
|
|
|
slider.getView().render( $container );
|
2016-10-13 03:28:27 +00:00
|
|
|
}, 250 ) );
|
2016-08-15 15:09:42 +00:00
|
|
|
|
2016-10-20 14:35:13 +00:00
|
|
|
if ( !settings.shouldHideHelpDialogue() ) {
|
2016-08-15 18:15:30 +00:00
|
|
|
mw.libs.revisionSlider.HelpDialog.show();
|
2016-10-20 14:35:13 +00:00
|
|
|
settings.setHideHelpDialogue( true );
|
2016-08-05 16:14:28 +00:00
|
|
|
}
|
|
|
|
|
2016-08-15 18:15:30 +00:00
|
|
|
$( '.mw-revslider-placeholder' ).remove();
|
|
|
|
mw.track( 'timing.MediaWiki.RevisionSlider.timing.init', mw.now() - startTime );
|
|
|
|
} catch ( 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' );
|
2016-06-27 14:00:13 +00:00
|
|
|
}
|
2016-08-15 18:15:30 +00:00
|
|
|
|
|
|
|
initialized = true;
|
|
|
|
}, function ( err ) {
|
|
|
|
$( '.mw-revslider-placeholder' )
|
|
|
|
.text( mw.message( 'revisionslider-loading-failed' ).text() );
|
2016-11-16 09:00:27 +00:00
|
|
|
mw.log.error( err );
|
2016-08-15 18:15:30 +00:00
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.error.init' );
|
2016-08-05 16:14:28 +00:00
|
|
|
} );
|
2016-09-13 13:14:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
expandAndIntitialize = function () {
|
|
|
|
$( '.mw-revslider-slider-wrapper' ).show();
|
|
|
|
expanded = true;
|
|
|
|
if ( !initialized ) {
|
|
|
|
initialize();
|
|
|
|
}
|
2016-08-05 16:14:28 +00:00
|
|
|
};
|
2016-04-19 12:45:09 +00:00
|
|
|
|
2016-08-05 16:14:28 +00:00
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.event.load' );
|
2016-08-09 16:34:53 +00:00
|
|
|
|
2016-10-20 14:35:13 +00:00
|
|
|
autoExpandButton = new OO.ui.ToggleButtonWidget( {
|
|
|
|
icon: 'pin',
|
|
|
|
classes: [ 'mw-revslider-auto-expand-button' ],
|
|
|
|
title: mw.message( autoExpand ?
|
|
|
|
'revisionslider-turn-off-auto-expand-title' :
|
|
|
|
'revisionslider-turn-on-auto-expand-title'
|
|
|
|
).text(),
|
|
|
|
value: autoExpand
|
|
|
|
} );
|
|
|
|
|
|
|
|
autoExpandButton.connect( this, {
|
|
|
|
click: function () {
|
|
|
|
autoExpand = !autoExpand;
|
|
|
|
settings.setAutoExpand( autoExpand );
|
|
|
|
if ( autoExpand ) {
|
|
|
|
autoExpandButton.setTitle( mw.message( 'revisionslider-turn-off-auto-expand-title' ).text() );
|
|
|
|
expandAndIntitialize();
|
2016-11-17 10:59:40 +00:00
|
|
|
toggleButton.setIcon( 'collapse' ).setTitle( mw.message( 'revisionslider-toggle-title-collapse' ).text() );
|
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 {
|
|
|
|
autoExpandButton.setTitle( mw.message( 'revisionslider-turn-on-auto-expand-title' ).text() );
|
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
|
|
|
|
|
|
|
if ( autoExpand ) {
|
2016-09-13 13:14:00 +00:00
|
|
|
expandAndIntitialize();
|
2016-11-17 10:59:40 +00:00
|
|
|
toggleButton.setIcon( 'collapse' ).setTitle( mw.message( 'revisionslider-toggle-title-collapse' ).text() );
|
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-09-13 13:14:00 +00:00
|
|
|
expandAndIntitialize();
|
2016-08-05 16:14:28 +00:00
|
|
|
toggleButton.setIcon( 'collapse' ).setTitle( mw.message( 'revisionslider-toggle-title-collapse' ).text() );
|
|
|
|
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-09-13 13:14:00 +00:00
|
|
|
$( '.mw-revslider-slider-wrapper' ).hide();
|
2016-08-05 16:14:28 +00:00
|
|
|
toggleButton.setIcon( 'expand' ).setTitle( mw.message( 'revisionslider-toggle-title-expand' ).text() );
|
|
|
|
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-04-19 12:45:09 +00:00
|
|
|
}( mediaWiki, jQuery ) );
|