mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
Refactor diffpage init
Avoid re-rendering the diff if it hasn't changed. Change-Id: Icbc8eb58625cf7c5485d0045e26993a170016309
This commit is contained in:
parent
05c0a88b5c
commit
007bb6fa09
|
@ -6,8 +6,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
( function () {
|
( function () {
|
||||||
var $visualDiff,
|
var reviewModeButtonSelect, diffElement, lastDiff, $wikitextDiff,
|
||||||
reviewModeButtonSelect,
|
$visualDiffContainer = $( '<div>' ),
|
||||||
|
$visualDiff = $( '<div>' ),
|
||||||
|
progress = new OO.ui.ProgressBarWidget( { classes: [ 've-init-mw-diffPage-loading' ] } ),
|
||||||
uri = new mw.Uri(),
|
uri = new mw.Uri(),
|
||||||
mode = uri.query.diffmode || 'source',
|
mode = uri.query.diffmode || 'source',
|
||||||
conf = mw.config.get( 'wgVisualEditorConfig' ),
|
conf = mw.config.get( 'wgVisualEditorConfig' ),
|
||||||
|
@ -18,10 +20,14 @@
|
||||||
mode = 'source';
|
mode = 'source';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$visualDiffContainer.append(
|
||||||
|
progress.$element.addClass( 'oo-ui-element-hidden' ),
|
||||||
|
$visualDiff
|
||||||
|
);
|
||||||
|
|
||||||
function onReviewModeButtonSelectSelect( item ) {
|
function onReviewModeButtonSelectSelect( item ) {
|
||||||
var modulePromise, progress, oldPageName, newPageName,
|
var modulePromise, oldPageName, newPageName, isVisual,
|
||||||
$revSlider = $( '.mw-revslider-container' ),
|
$revSlider = $( '.mw-revslider-container' ),
|
||||||
$wikitextDiff = $( 'table.diff[data-mw="interface"]' ),
|
|
||||||
oldId = mw.config.get( 'wgDiffOldId' ),
|
oldId = mw.config.get( 'wgDiffOldId' ),
|
||||||
newId = mw.config.get( 'wgDiffNewId' );
|
newId = mw.config.get( 'wgDiffNewId' );
|
||||||
|
|
||||||
|
@ -33,28 +39,34 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
mode = item.getData();
|
mode = item.getData();
|
||||||
|
isVisual = mode === 'visual';
|
||||||
|
|
||||||
if ( mode === 'visual' ) {
|
$visualDiffContainer.toggleClass( 'oo-ui-element-hidden', !isVisual );
|
||||||
progress = new OO.ui.ProgressBarWidget( { classes: [ 've-init-mw-diffPage-loading' ] } );
|
$wikitextDiff.toggleClass( 'oo-ui-element-hidden', isVisual );
|
||||||
$wikitextDiff.addClass( 'oo-ui-element-hidden' ).before( progress.$element );
|
$revSlider.toggleClass( 've-init-mw-diffPage-revSlider-visual', isVisual );
|
||||||
|
|
||||||
|
if ( isVisual && !(
|
||||||
|
lastDiff && lastDiff.oldId === oldId && lastDiff.newId === newId &&
|
||||||
|
lastDiff.oldPageName === oldPageName && lastDiff.newPageName === newPageName
|
||||||
|
) ) {
|
||||||
|
$visualDiff.empty();
|
||||||
|
progress.$element.removeClass( 'oo-ui-element-hidden' );
|
||||||
// TODO: Load a smaller subset of VE for computing the visual diff
|
// TODO: Load a smaller subset of VE for computing the visual diff
|
||||||
modulePromise = mw.loader.using( [ 'ext.visualEditor.desktopArticleTarget' ].concat( pluginModules ) );
|
modulePromise = mw.loader.using( [ 'ext.visualEditor.desktopArticleTarget' ].concat( pluginModules ) );
|
||||||
mw.libs.ve.diffLoader.getVisualDiffGeneratorPromise( oldId, newId, modulePromise, oldPageName, newPageName ).then( function ( visualDiffGenerator ) {
|
mw.libs.ve.diffLoader.getVisualDiffGeneratorPromise( oldId, newId, modulePromise, oldPageName, newPageName ).then( function ( visualDiffGenerator ) {
|
||||||
var diffElement = new ve.ui.DiffElement( visualDiffGenerator(), { classes: [ 've-init-mw-diffPage-diff' ] } );
|
diffElement = new ve.ui.DiffElement( visualDiffGenerator(), { classes: [ 've-init-mw-diffPage-diff' ] } );
|
||||||
|
|
||||||
progress.$element.remove();
|
progress.$element.addClass( 'oo-ui-element-hidden' );
|
||||||
$wikitextDiff.before( diffElement.$element );
|
$visualDiff.append( diffElement.$element );
|
||||||
$visualDiff = diffElement.$element;
|
lastDiff = {
|
||||||
$revSlider.addClass( 've-init-mw-diffPage-revSlider-visual' );
|
oldId: oldId,
|
||||||
|
newId: newId,
|
||||||
|
oldPageName: oldPageName,
|
||||||
|
newPageName: newPageName
|
||||||
|
};
|
||||||
|
|
||||||
diffElement.positionDescriptions();
|
diffElement.positionDescriptions();
|
||||||
} );
|
} );
|
||||||
} else {
|
|
||||||
if ( $visualDiff ) {
|
|
||||||
$visualDiff.addClass( 'oo-ui-element-hidden' );
|
|
||||||
}
|
|
||||||
$wikitextDiff.removeClass( 'oo-ui-element-hidden' );
|
|
||||||
$revSlider.removeClass( 've-init-mw-diffPage-revSlider-visual' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( history.replaceState ) {
|
if ( history.replaceState ) {
|
||||||
|
@ -65,6 +77,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
mw.hook( 'wikipage.diff' ).add( function () {
|
mw.hook( 'wikipage.diff' ).add( function () {
|
||||||
|
$wikitextDiff = $( 'table.diff[data-mw="interface"]' );
|
||||||
|
$wikitextDiff.before( $visualDiffContainer );
|
||||||
// The PHP widget was a ButtonGroupWidget, so replace with a
|
// The PHP widget was a ButtonGroupWidget, so replace with a
|
||||||
// ButtonSelectWidget instead of infusing.
|
// ButtonSelectWidget instead of infusing.
|
||||||
reviewModeButtonSelect = new OO.ui.ButtonSelectWidget( {
|
reviewModeButtonSelect = new OO.ui.ButtonSelectWidget( {
|
||||||
|
|
Loading…
Reference in a new issue