mediawiki-extensions-Revisi.../modules/ext.RevisionSlider.init.js
addshore f9471bcfbc If the slider fails to load then fail nicely!
If something goes wrong with the initial api rquest the
slider would either load in a broken state or say that
it is loading forever.

Now a message will be displayed to the user as well
as the error logged to the console.

Change-Id: Id763f31432feb7bd0e9ecbbeb2dd40f7ca6acaaf
2016-05-12 09:46:39 +01:00

48 lines
1.3 KiB
JavaScript
Executable file

( function ( mw, $ ) {
mw.loader.using( [ 'jquery.ui.draggable', 'jquery.ui.tooltip', 'jquery.tipsy' ], function () {
$( function () {
mw.track( 'counter.MediaWiki.RevisionSlider.event.init' );
mw.libs.revisionSlider.fetchRevisions( {
pageName: mw.config.get( 'wgPageName' ),
startId: mw.config.get( 'wgCurRevisionId' ),
success: function ( data ) {
var revs,
revisionList,
$container,
slider;
try {
revs = data.query.pages[ 0 ].revisions;
if ( !revs ) {
return;
}
revs.reverse();
revisionList = new mw.libs.revisionSlider.RevisionList( revs );
$container = $( '#revision-slider-container' );
slider = new mw.libs.revisionSlider.Slider( revisionList );
slider.getView().render( $container );
$( '#revision-slider-placeholder' ).remove();
} catch ( err ) {
$( '#revision-slider-placeholder' )
.html( mw.message( 'revisionslider-loading-failed' ).text() );
console.log( err );
mw.track( 'counter.MediaWiki.RevisionSlider.error.init' );
}
},
error: function ( err ) {
$( '#revision-slider-placeholder' )
.html( mw.message( 'revisionslider-loading-failed' ).text() );
console.log( err );
mw.track( 'counter.MediaWiki.RevisionSlider.error.init' );
}
} );
} );
} );
}( mediaWiki, jQuery ) );