2016-05-10 18:53:31 +00:00
|
|
|
( function ( mw, $ ) {
|
|
|
|
var DiffPage = function () {
|
|
|
|
};
|
|
|
|
|
|
|
|
$.extend( DiffPage.prototype, {
|
2016-05-10 19:45:09 +00:00
|
|
|
refresh: function ( revId1, revId2 ) {
|
2016-05-30 10:06:44 +00:00
|
|
|
$( 'table.diff[data-mw="interface"]' )
|
|
|
|
.append( $( '<tr>' ) )
|
|
|
|
.append( $( '<td>' ) )
|
|
|
|
.append( $( '<div>' ).attr( 'id', 'mw-revision-slider-darkness' ) );
|
2016-05-10 18:53:31 +00:00
|
|
|
$.ajax( {
|
|
|
|
url: mw.util.wikiScript( 'index' ),
|
|
|
|
data: {
|
2016-05-10 19:45:09 +00:00
|
|
|
diff: Math.max( revId1, revId2 ),
|
|
|
|
oldid: Math.min( revId1, revId2 )
|
2016-05-10 18:53:31 +00:00
|
|
|
},
|
2016-05-12 08:42:43 +00:00
|
|
|
tryCount: 0,
|
|
|
|
retryLimit: 2,
|
2016-05-10 18:53:31 +00:00
|
|
|
success: function ( data ) {
|
2016-05-30 10:06:44 +00:00
|
|
|
var $container = $( '#mw-revision-slider-container' ),
|
|
|
|
scrollLeft = $container.find( '.mw-revisions-container' ).scrollLeft();
|
2016-05-19 12:52:36 +00:00
|
|
|
|
|
|
|
data = $( data );
|
2016-05-30 10:06:44 +00:00
|
|
|
data.find( '#mw-revision-slider-container' )
|
2016-05-19 12:52:36 +00:00
|
|
|
.replaceWith( $container );
|
|
|
|
$( '#mw-content-text' ).html( data.find( '#mw-content-text' ) )
|
2016-05-30 10:06:44 +00:00
|
|
|
.find( '.mw-revisions-container' ).scrollLeft( scrollLeft );
|
2016-05-12 08:42:43 +00:00
|
|
|
},
|
|
|
|
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?
|
2016-05-10 18:53:31 +00:00
|
|
|
}
|
|
|
|
} );
|
2016-05-11 10:01:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
pushState: function ( revId1, revId2, sliderView ) {
|
|
|
|
history.pushState(
|
2016-05-19 12:52:36 +00:00
|
|
|
{
|
|
|
|
revid1: revId1,
|
|
|
|
revid2: revId2,
|
|
|
|
leftPos: sliderView.pointerOne.getPosition(),
|
|
|
|
rightPos: sliderView.pointerTwo.getPosition(),
|
|
|
|
sliderPos: sliderView.slider.getFirstVisibleRevisionIndex()
|
|
|
|
},
|
2016-05-11 10:01:44 +00:00
|
|
|
$( 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' );
|
2016-05-13 10:29:05 +00:00
|
|
|
sliderView.pointerOne.setPosition( event.state.leftPos );
|
|
|
|
sliderView.pointerTwo.setPosition( event.state.rightPos );
|
2016-05-11 10:01:44 +00:00
|
|
|
sliderView.slider.setFirstVisibleRevisionIndex( event.state.sliderPos );
|
|
|
|
sliderView.slide( 0 );
|
2016-05-17 12:29:08 +00:00
|
|
|
sliderView.resetPointerStylesBasedOnPosition();
|
2016-05-19 16:39:58 +00:00
|
|
|
sliderView.resetRevisionStylesBasedOnPointerPosition(
|
|
|
|
sliderView.$element.find( 'div.revisions' )
|
|
|
|
);
|
2016-05-11 10:01:44 +00:00
|
|
|
self.refresh( event.state.revid1, event.state.revid2 );
|
|
|
|
} );
|
2016-05-10 18:53:31 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
mw.libs.revisionSlider = mw.libs.revisionSlider || {};
|
|
|
|
mw.libs.revisionSlider.DiffPage = DiffPage;
|
|
|
|
}( mediaWiki, jQuery ) );
|