mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RevisionSlider
synced 2024-11-15 19:49:30 +00:00
b1f6a1df56
This allows using browser back and forward buttons once users have started heading between revisions. This also updates the URL so that the page can be reloaded at any time and the same state will be held. (This also removes a commented out block of code that I think was left for updating the URL) Change-Id: I4cfe38f76eeb9e090f0a8a42e22e75cf84014d60
52 lines
1.7 KiB
JavaScript
52 lines
1.7 KiB
JavaScript
( function ( mw, $ ) {
|
|
var DiffPage = function () {
|
|
};
|
|
|
|
$.extend( DiffPage.prototype, {
|
|
refresh: function ( revId1, revId2 ) {
|
|
$( 'body' )
|
|
.find( 'table.diff[data-mw=\'interface\']' )
|
|
.append( '<div id="revision-slider-darkness"></div>' );
|
|
$.ajax( {
|
|
url: mw.util.wikiScript( 'index' ),
|
|
data: {
|
|
diff: Math.max( revId1, revId2 ),
|
|
oldid: Math.min( revId1, revId2 )
|
|
},
|
|
success: function ( data ) {
|
|
data = $( '<div/>' ).html( data ).contents();
|
|
$( 'body' )
|
|
.find( 'table.diff[data-mw=\'interface\']' )
|
|
.html( data.find( 'table.diff[data-mw=\'interface\']' ) );
|
|
}
|
|
} );
|
|
},
|
|
|
|
pushState: function ( revId1, revId2, sliderView ) {
|
|
history.pushState(
|
|
{ revid1: revId1, revid2: revId2, leftPos: sliderView.leftPointer.getPosition(), rightPos: sliderView.rightPointer.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.leftPointer.setPosition( event.state.leftPos );
|
|
sliderView.rightPointer.setPosition( event.state.rightPos );
|
|
sliderView.slider.setFirstVisibleRevisionIndex( event.state.sliderPos );
|
|
sliderView.slide( 0 );
|
|
self.refresh( event.state.revid1, event.state.revid2 );
|
|
} );
|
|
}
|
|
} );
|
|
|
|
mw.libs.revisionSlider = mw.libs.revisionSlider || {};
|
|
mw.libs.revisionSlider.DiffPage = DiffPage;
|
|
}( mediaWiki, jQuery ) );
|