mediawiki-extensions-Revisi.../modules/ext.RevisionSlider.DiffPage.js
Leszek Manicki b86194eacb Fix updating revision bar styles when going back/forward in history
This left unchanged in I164538bbaf44d46a4c66659f56e07ec7225d7fa9

Change-Id: Ied950472458a61efbfae5850d070f7047a222879
2016-06-01 16:45:15 +02:00

80 lines
2.6 KiB
JavaScript

( function ( mw, $ ) {
var DiffPage = function () {
};
$.extend( DiffPage.prototype, {
refresh: function ( revId1, revId2 ) {
$( 'table.diff[data-mw="interface"]' )
.append( $( '<tr>' ) )
.append( $( '<td>' ) )
.append( $( '<div>' ).attr( 'id', 'mw-revision-slider-darkness' ) );
$.ajax( {
url: mw.util.wikiScript( 'index' ),
data: {
diff: Math.max( revId1, revId2 ),
oldid: Math.min( revId1, revId2 )
},
tryCount: 0,
retryLimit: 2,
success: function ( data ) {
var $container = $( '#mw-revision-slider-container' ),
scrollLeft = $container.find( '.mw-revisions-container' ).scrollLeft();
data = $( data );
data.find( '#mw-revision-slider-container' )
.replaceWith( $container );
$( '#mw-content-text' ).html( data.find( '#mw-content-text' ) )
.find( '.mw-revisions-container' ).scrollLeft( scrollLeft );
},
error: function ( err ) {
this.tryCount++;
console.log( err );
mw.track( 'counter.MediaWiki.RevisionSlider.error.refresh' );
if ( this.tryCount <= this.retryLimit ) {
console.log( 'Retrying request' );
$.ajax( this );
}
// TODO notify the user that we failed to update the diff?
// This could also attempt to reload the page with the correct diff loaded without ajax?
}
} );
},
pushState: function ( revId1, revId2, sliderView ) {
history.pushState(
{
revid1: revId1,
revid2: revId2,
leftPos: sliderView.pointerOne.getPosition(),
rightPos: sliderView.pointerTwo.getPosition(),
sliderPos: sliderView.slider.getFirstVisibleRevisionIndex()
},
$( document ).find( 'title' ).text(),
mw.util.wikiScript( 'index' ) + '?diff=' + Math.max( revId1, revId2 ) + '&oldid=' + Math.min( revId1, revId2 )
);
},
initOnPopState: function ( sliderView ) {
var self = this;
window.addEventListener( 'popstate', function ( event ) {
if ( event.state === null ) {
return;
}
mw.track( 'counter.MediaWiki.RevisionSlider.event.historyChange' );
sliderView.pointerOne.setPosition( event.state.leftPos );
sliderView.pointerTwo.setPosition( event.state.rightPos );
sliderView.slider.setFirstVisibleRevisionIndex( event.state.sliderPos );
sliderView.slide( 0 );
sliderView.resetPointerStylesBasedOnPosition();
sliderView.resetRevisionStylesBasedOnPointerPosition(
sliderView.$element.find( 'div.mw-revisions' )
);
self.refresh( event.state.revid1, event.state.revid2 );
} );
}
} );
mw.libs.revisionSlider = mw.libs.revisionSlider || {};
mw.libs.revisionSlider.DiffPage = DiffPage;
}( mediaWiki, jQuery ) );